Skip to content

vectorized_transpose

vectorized_transpose(n, d)

Given a flattened stack of n dxd matrices, computes the transpose operator

Parameters:

Name Type Description Default
n int

Number of matrices

required
d int

Dimension of matrices

required

Returns:

Name Type Description
T (n*d*d, n*d*d) scipy sparse matrix

Vectorized transpose operator

Source code in src\fast_cody\vectorized_transpose.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def vectorized_transpose(n, d):
    """
    Given a flattened stack of n  dxd matrices, computes the transpose operator

    Parameters
    ----------
    n : int
        Number of matrices
    d : int
        Dimension of matrices

    Returns
    -------
    T : (n*d*d, n*d*d) scipy sparse matrix
        Vectorized transpose operator
    """
    ii = np.arange(n*d*d)
    Mi = np.reshape(ii, (n*d, d))

    Mii = np.reshape(Mi, (n, d, d))
    Mii = Mii.transpose((0, 2, 1))
    Mii = np.reshape(Mii, (d*n, d))
    Mj = Mii.flatten()
    # transpose each block

    i = Mj;
    j = np.arange(n*d*d)
    v = np.ones(n*d*d)
    T = sp.sparse.csc_matrix((v, (i, j)), (n*d*d, n*d*d))
    return T