1
// =============================================================================
2
// === spqr_cpack ==============================================================
3
// =============================================================================
5
// spqr_cpack copies the C matrix from the frontal matrix F and
6
// stores it in packed form. F can be overwritten with C (the pack can occur
7
// in-place), but in that case, the R and H matrices are destroyed.
9
// In this example, m = 5, n = 6, npiv = 2, and rank = 2 (the number of good
10
// pivot columns found; equivalently, the number of rows in the R block). The
11
// number of columns in C is cn = n-npiv. The number of rows is
12
// cm = MIN (m-rank,cn). In this example, MIN (m-rank,cn) = 3.
16
// . . c c c c <- rank = 2
20
// In the next example below, m = 8 instead. Note that
21
// cm = MIN (m-rank,cn) = 4.
25
// . . c c c c <- rank = 2
34
template <typename Entry> Int spqr_cpack // returns # of rows in C
36
// input, not modified
37
Int m, // # of rows in F
38
Int n, // # of columns in F
39
Int npiv, // number of pivotal columns in F
40
Int rank, // the C block starts at F (rank,npiv)
42
// input, not modified unless the pack occurs in-place
43
Entry *F, // m-by-n frontal matrix in column-major order
45
// output, contents not defined on input
46
Entry *C // packed columns of C, of size cm-by-cn in upper
52
// -------------------------------------------------------------------------
54
// -------------------------------------------------------------------------
56
ASSERT (m >= 0 && n >= 0 && npiv >= 0 && npiv <= n) ;
58
ASSERT (rank >= 0 && rank <= MIN (m,npiv)) ;
59
cn = n - npiv ; // number of columns of C
60
cm = MIN (m-rank, cn) ; // number of rows of C
62
if (cm <= 0 || cn <= 0)
64
return (0) ; // nothing to do
67
ASSERT (C != NULL && F != NULL) ;
68
ASSERT (C <= F // C can be packed in-place, in F
69
|| C >= F + m*n) ; // or C must appear after F
71
F += INDEX (rank,npiv,m) ; // C starts at F (rank,npiv)
73
// -------------------------------------------------------------------------
74
// pack the upper triangular part of C
75
// -------------------------------------------------------------------------
77
for (k = 0 ; k < cm ; k++)
80
for (i = 0 ; i <= k ; i++)
84
F += m ; // advance to the next column of F
87
// -------------------------------------------------------------------------
88
// pack the rectangular part of C
89
// -------------------------------------------------------------------------
94
for (i = 0 ; i < cm ; i++)
98
F += m ; // advance to the next column of F
101
PR (("Cpack rank %ld cm %ld cn %ld\n", rank, cm, cn)) ;
102
return (cm) ; // return # of rows in C
106
// =============================================================================
108
template Int spqr_cpack <double> // returns # of rows in C
110
// input, not modified
111
Int m, // # of rows in F
112
Int n, // # of columns in F
113
Int npiv, // number of pivotal columns in F
114
Int rank, // the C block starts at F (rank,npiv)
116
// input, not modified unless the pack occurs in-place
117
double *F, // m-by-n frontal matrix in column-major order
119
// output, contents not defined on input
120
double *C // packed columns of C, of size cm-by-cn in upper
124
// =============================================================================
126
template Int spqr_cpack <Complex> // returns # of rows in C
128
// input, not modified
129
Int m, // # of rows in F
130
Int n, // # of columns in F
131
Int npiv, // number of pivotal columns in F
132
Int rank, // the C block starts at F (rank,npiv)
134
// input, not modified unless the pack occurs in-place
135
Complex *F, // m-by-n frontal matrix in column-major order
137
// output, contents not defined on input
138
Complex *C // packed columns of C, of size cm-by-cn in upper