1 // =============================================================================
2 // === spqr_stranspose2 ========================================================
3 // =============================================================================
4 
5 // Construct the numerical values of S = A (p,q) in compressed-row form
6 
7 #include "spqr.hpp"
8 
spqr_stranspose2(cholmod_sparse * A,Long * Qfill,Long * Sp,Long * PLinv,Entry * Sx,Long * W)9 template <typename Entry> void spqr_stranspose2
10 (
11     // input, not modified
12     cholmod_sparse *A,  // m-by-n
13     Long *Qfill,        // size n, fill-reducing column permutation;
14                         // Qfill [k] = j
15                         // if the kth column of S is the jth column of A.
16                         // Identity permutation is used if Qfill is NULL.
17 
18     Long *Sp,           // size m+1, row pointers of S
19     Long *PLinv,        // size m, inverse row permutation, PLinv [i] = k
20 
21     // output, contents not defined on input
22     Entry *Sx,          // size nz, numerical values of S
23 
24     // workspace, not defined on input or output
25     Long *W             // size m
26 )
27 {
28     Long i, j, p, pend, row, col, s, m, n, *Ap, *Ai ;
29     Entry *Ax ;
30 
31     // -------------------------------------------------------------------------
32     // get inputs
33     // -------------------------------------------------------------------------
34 
35     m = A->nrow ;
36     n = A->ncol ;
37     Ap = (Long *) A->p ;
38     Ai = (Long *) A->i ;
39     Ax = (Entry *) A->x ;
40 
41     // -------------------------------------------------------------------------
42     // create S = A (p,q)', or S=A(p,q) if S is considered to be in row-form
43     // -------------------------------------------------------------------------
44 
45     for (row = 0 ; row < m ; row++)
46     {
47         W [row] = Sp [row] ;
48     }
49 
50     for (col = 0 ; col < n ; col++)     // for each column of A(:,Qfill)
51     {
52         j = Qfill ? Qfill [col] : col ; // col of S is column j of A
53         pend = Ap [j+1] ;
54         for (p = Ap [j] ; p < pend ; p++)
55         {
56             i = Ai [p] ;                // the entry A(i,j)
57             row = PLinv [i] ;           // row of S is row i of A
58             s = W [row]++ ;             // place S(row,col) in position
59             Sx [s] = Ax [p] ;
60         }
61     }
62 }
63 
64 
65 // =============================================================================
66 
67 template void spqr_stranspose2 <double>
68 (
69     // input, not modified
70     cholmod_sparse *A,  // m-by-n
71     Long *Qfill,        // size n, fill-reducing column permutation;
72                         // Qfill [k] = j
73                         // if the kth column of S is the jth column of A.
74                         // Identity permutation is used if Qfill is NULL.
75 
76     Long *Sp,           // size m+1, row pointers of S
77     Long *PLinv,        // size m, inverse row permutation, PLinv [i] = k
78 
79     // output, contents not defined on input
80     double *Sx,         // size nz, numerical values of S
81 
82     // workspace, not defined on input or output
83     Long *W             // size m
84 ) ;
85 
86 // =============================================================================
87 
88 template void spqr_stranspose2 <Complex>
89 (
90     // input, not modified
91     cholmod_sparse *A,  // m-by-n
92     Long *Qfill,        // size n, fill-reducing column permutation;
93                         // Qfill [k] = j
94                         // if the kth column of S is the jth column of A.
95                         // Identity permutation is used if Qfill is NULL.
96 
97     Long *Sp,           // size m+1, row pointers of S
98     Long *PLinv,        // size m, inverse row permutation, PLinv [i] = k
99 
100     // output, contents not defined on input
101     Complex *Sx,        // size nz, numerical values of S
102 
103     // workspace, not defined on input or output
104     Long *W             // size m
105 ) ;
106 
107