00001 /* ========================================================================== */ 00002 /* === umfpack_triplet_to_col =============================================== */ 00003 /* ========================================================================== */ 00004 00005 /* -------------------------------------------------------------------------- */ 00006 /* UMFPACK Version 4.3 (Jan. 16, 2004), Copyright (c) 2004 by Timothy A. */ 00007 /* Davis. All Rights Reserved. See ../README for License. */ 00008 /* email: davis@cise.ufl.edu CISE Department, Univ. of Florida. */ 00009 /* web: http://www.cise.ufl.edu/research/sparse/umfpack */ 00010 /* -------------------------------------------------------------------------- */ 00011 00012 int umfpack_di_triplet_to_col 00013 ( 00014 int n_row, 00015 int n_col, 00016 int nz, 00017 const int Ti [ ], 00018 const int Tj [ ], 00019 const double Tx [ ], 00020 int Ap [ ], 00021 int Ai [ ], 00022 double Ax [ ], 00023 int Map [ ] 00024 ) ; 00025 00026 long umfpack_dl_triplet_to_col 00027 ( 00028 long n_row, 00029 long n_col, 00030 long nz, 00031 const long Ti [ ], 00032 const long Tj [ ], 00033 const double Tx [ ], 00034 long Ap [ ], 00035 long Ai [ ], 00036 double Ax [ ], 00037 long Map [ ] 00038 ) ; 00039 00040 int umfpack_zi_triplet_to_col 00041 ( 00042 int n_row, 00043 int n_col, 00044 int nz, 00045 const int Ti [ ], 00046 const int Tj [ ], 00047 const double Tx [ ], const double Tz [ ], 00048 int Ap [ ], 00049 int Ai [ ], 00050 double Ax [ ], double Az [ ], 00051 int Map [ ] 00052 ) ; 00053 00054 long umfpack_zl_triplet_to_col 00055 ( 00056 long n_row, 00057 long n_col, 00058 long nz, 00059 const long Ti [ ], 00060 const long Tj [ ], 00061 const double Tx [ ], const double Tz [ ], 00062 long Ap [ ], 00063 long Ai [ ], 00064 double Ax [ ], double Az [ ], 00065 long Map [ ] 00066 ) ; 00067 00068 /* 00069 double int Syntax: 00070 00071 #include "umfpack.h" 00072 int n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ; 00073 double *Tx, *Ax ; 00074 status = umfpack_di_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, 00075 Ap, Ai, Ax, Map) ; 00076 00077 double long Syntax: 00078 00079 #include "umfpack.h" 00080 long n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ; 00081 double *Tx, *Ax ; 00082 status = umfpack_dl_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, 00083 Ap, Ai, Ax, Map) ; 00084 00085 complex int Syntax: 00086 00087 #include "umfpack.h" 00088 int n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ; 00089 double *Tx, *Tz, *Ax, *Az ; 00090 status = umfpack_zi_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, Tz, 00091 Ap, Ai, Ax, Az, Map) ; 00092 00093 long Syntax: 00094 00095 #include "umfpack.h" 00096 long n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ; 00097 double *Tx, *Tz, *Ax, *Az ; 00098 status = umfpack_zl_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, Tz, 00099 Ap, Ai, Ax, Az, Map) ; 00100 00101 Purpose: 00102 00103 Converts a sparse matrix from "triplet" form to compressed-column form. 00104 Analogous to A = spconvert (Ti, Tj, Tx + Tx*1i) in MATLAB, except that 00105 zero entries present in the triplet form are present in A. 00106 00107 The triplet form of a matrix is a very simple data structure for basic 00108 sparse matrix operations. For example, suppose you wish to factorize a 00109 matrix A coming from a finite element method, in which A is a sum of 00110 dense submatrices, A = E1 + E2 + E3 + ... . The entries in each element 00111 matrix Ei can be concatenated together in the three triplet arrays, and 00112 any overlap between the elements will be correctly summed by 00113 umfpack_*_triplet_to_col. 00114 00115 Transposing a matrix in triplet form is simple; just interchange the 00116 use of Ti and Tj. You can construct the complex conjugate transpose by 00117 negating Tz, for the complex versions. 00118 00119 Permuting a matrix in triplet form is also simple. If you want the matrix 00120 PAQ, or A (P,Q) in MATLAB notation, where P [k] = i means that row i of 00121 A is the kth row of PAQ and Q [k] = j means that column j of A is the kth 00122 column of PAQ, then do the following. First, create inverse permutations 00123 Pinv and Qinv such that Pinv [i] = k if P [k] = i and Qinv [j] = k if 00124 Q [k] = j. Next, for the mth triplet (Ti [m], Tj [m], Tx [m], Tz [m]), 00125 replace Ti [m] with Pinv [Ti [m]] and replace Tj [m] with Qinv [Tj [m]]. 00126 00127 If you have a column-form matrix with duplicate entries or unsorted 00128 columns, you can sort it and sum up the duplicates by first converting it 00129 to triplet form with umfpack_*_col_to_triplet, and then converting it back 00130 with umfpack_*_triplet_to_col. 00131 00132 Constructing a submatrix is also easy. Just scan the triplets and remove 00133 those entries outside the desired subset of 0...n_row-1 and 0...n_col-1, 00134 and renumber the indices according to their position in the subset. 00135 00136 You can do all these operations on a column-form matrix by first 00137 converting it to triplet form with umfpack_*_col_to_triplet, doing the 00138 operation on the triplet form, and then converting it back with 00139 umfpack_*_triplet_to_col. 00140 00141 The only operation not supported easily in the triplet form is the 00142 multiplication of two sparse matrices (UMFPACK does not provide this 00143 operation). 00144 00145 You can print the input triplet form with umfpack_*_report_triplet, and 00146 the output matrix with umfpack_*_report_matrix. 00147 00148 The matrix may be singular (nz can be zero, and empty rows and/or columns 00149 may exist). It may also be rectangular and/or complex. 00150 00151 Returns: 00152 00153 UMFPACK_OK if successful. 00154 UMFPACK_ERROR_argument_missing if Ap, Ai, Ti, and/or Tj are missing. 00155 UMFPACK_ERROR_n_nonpositive if n_row <= 0 or n_col <= 0. 00156 UMFPACK_ERROR_invalid_matrix if nz < 0, or if for any k, Ti [k] and/or 00157 Tj [k] are not in the range 0 to n_row-1 or 0 to n_col-1, respectively. 00158 UMFPACK_ERROR_out_of_memory if unable to allocate sufficient workspace. 00159 00160 Arguments: 00161 00162 Int n_row ; Input argument, not modified. 00163 Int n_col ; Input argument, not modified. 00164 00165 A is an n_row-by-n_col matrix. Restriction: n_row > 0 and n_col > 0. 00166 All row and column indices in the triplet form must be in the range 00167 0 to n_row-1 and 0 to n_col-1, respectively. 00168 00169 Int nz ; Input argument, not modified. 00170 00171 The number of entries in the triplet form of the matrix. Restriction: 00172 nz >= 0. 00173 00174 Int Ti [nz] ; Input argument, not modified. 00175 Int Tj [nz] ; Input argument, not modified. 00176 double Tx [nz] ; Input argument, not modified. 00177 double Tz [nz] ; Input argument, not modified, for complex versions. 00178 00179 Ti, Tj, Tx, and Tz hold the "triplet" form of a sparse matrix. The kth 00180 nonzero entry is in row i = Ti [k], column j = Tj [k], and the real part 00181 of a_ij is Tx [k]. The imaginary part of a_ij is Tz [k], for complex 00182 versions. The row and column indices i and j must be in the range 0 to 00183 n_row-1 and 0 to n_col-1, respectively. Duplicate entries may be 00184 present; they are summed in the output matrix. This is not an error 00185 condition. The "triplets" may be in any order. Tx, Tz, Ax, and Az 00186 are optional. For the real version, Ax is computed only if both Ax 00187 and Tx are present (not (double *) NULL). For the complex version, Ax 00188 and Az are computed only if Tx, Tz, Ax, and Az are all present. These 00189 are not error conditions; the routine can create just the pattern of 00190 the output matrix from the pattern of the triplets. 00191 00192 Future complex version: if Tx is present and Tz is NULL, then both real 00193 and imaginary parts will be contained in Tx[0..2*nz-1], with Tx[2*k] 00194 and Tx[2*k+1] being the real and imaginary part of the kth entry. 00195 00196 Int Ap [n_col+1] ; Output argument. 00197 00198 Ap is an integer array of size n_col+1 on input. On output, Ap holds 00199 the "pointers" for the column form of the sparse matrix A. Column j of 00200 the matrix A is held in Ai [(Ap [j]) ... (Ap [j+1]-1)]. The first 00201 entry, Ap [0], is zero, and Ap [j] <= Ap [j+1] holds for all j in the 00202 range 0 to n_col-1. The value nz2 = Ap [n_col] is thus the total 00203 number of entries in the pattern of the matrix A. Equivalently, the 00204 number of duplicate triplets is nz - Ap [n_col]. 00205 00206 Int Ai [nz] ; Output argument. 00207 00208 Ai is an integer array of size nz on input. Note that only the first 00209 Ap [n_col] entries are used. 00210 00211 The nonzero pattern (row indices) for column j is stored in 00212 Ai [(Ap [j]) ... (Ap [j+1]-1)]. The row indices in a given column j 00213 are in ascending order, and no duplicate row indices are present. 00214 Row indices are in the range 0 to n_col-1 (the matrix is 0-based). 00215 00216 double Ax [nz] ; Output argument. 00217 double Az [nz] ; Output argument for complex versions. 00218 00219 Ax and Az (for the complex versions) are double arrays of size nz on 00220 input. Note that only the first Ap [n_col] entries are used 00221 in both arrays. 00222 00223 Ax is optional; if Tx and/or Ax are not present (a (double *) NULL 00224 pointer), then Ax is not computed. Az is also optional; if Tz and/or 00225 Az are not present, then Az is not computed. If present, Ax holds the 00226 numerical values of the the real part of the sparse matrix A and Az 00227 holds the imaginary parts. The nonzero pattern (row indices) for 00228 column j is stored in Ai [(Ap [j]) ... (Ap [j+1]-1)], and the 00229 corresponding numerical values are stored in 00230 Ax [(Ap [j]) ... (Ap [j+1]-1)]. The imaginary parts are stored in 00231 Az [(Ap [j]) ... (Ap [j+1]-1)], for the complex versions. 00232 00233 Future complex version: if Ax is present and Az is NULL, then both real 00234 and imaginary parts will be returned in Ax[0..2*nz2-1], with Ax[2*k] 00235 and Ax[2*k+1] being the real and imaginary part of the kth entry. 00236 00237 int Map [nz] ; Optional output argument. 00238 00239 If Map is present (a non-NULL pointer to an Int array of size nz), then 00240 on output it holds the position of the triplets in the column-form 00241 matrix. That is, suppose p = Map [k], and the k-th triplet is i=Ti[k], 00242 j=Tj[k], and aij=Tx[k]. Then i=Ai[p], and aij will have been summed 00243 into Ax[p] (or simply aij=Ax[p] if there were no duplicate entries also 00244 in row i and column j). Also, Ap[j] <= p < Ap[j+1]. The Map array is 00245 not computed if it is (Int *) NULL. The Map array is useful for 00246 converting a subsequent triplet form matrix with the same pattern as the 00247 first one, without calling this routine. If Ti and Tj do not change, 00248 then Ap, and Ai can be reused from the prior call to 00249 umfpack_*_triplet_to_col. You only need to recompute Ax (and Az for the 00250 complex version). This code excerpt properly sums up all duplicate 00251 values (for the real version): 00252 00253 for (p = 0 ; p < Ap [n_col] ; p++) Ax [p] = 0 ; 00254 for (k = 0 ; k < nz ; k++) Ax [Map [k]] += Tx [k] ; 00255 00256 This feature is useful (along with the reuse of the Symbolic object) if 00257 you need to factorize a sequence of triplet matrices with identical 00258 nonzero pattern (the order of the triplets in the Ti,Tj,Tx arrays must 00259 also remain unchanged). It is faster than calling this routine for 00260 each matrix, and requires no workspace. 00261 */