Rev 1820 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
/* ========================================================================== *//* === umfpack_triplet_to_col =============================================== *//* ========================================================================== *//* -------------------------------------------------------------------------- *//* UMFPACK Version 4.5, Copyright (c) 2005 by Timothy A. Davis. CISE Dept, *//* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. *//* web: http://www.cise.ufl.edu/research/sparse/umfpack *//* -------------------------------------------------------------------------- */int umfpack_di_triplet_to_col(int n_row,int n_col,int nz,const int Ti [ ],const int Tj [ ],const double Tx [ ],int Ap [ ],int Ai [ ],double Ax [ ],int Map [ ]) ;long umfpack_dl_triplet_to_col(long n_row,long n_col,long nz,const long Ti [ ],const long Tj [ ],const double Tx [ ],long Ap [ ],long Ai [ ],double Ax [ ],long Map [ ]) ;int umfpack_zi_triplet_to_col(int n_row,int n_col,int nz,const int Ti [ ],const int Tj [ ],const double Tx [ ], const double Tz [ ],int Ap [ ],int Ai [ ],double Ax [ ], double Az [ ],int Map [ ]) ;long umfpack_zl_triplet_to_col(long n_row,long n_col,long nz,const long Ti [ ],const long Tj [ ],const double Tx [ ], const double Tz [ ],long Ap [ ],long Ai [ ],double Ax [ ], double Az [ ],long Map [ ]) ;/*double int Syntax:#include "umfpack.h"int n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ;double *Tx, *Ax ;status = umfpack_di_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx,Ap, Ai, Ax, Map) ;double long Syntax:#include "umfpack.h"long n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ;double *Tx, *Ax ;status = umfpack_dl_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx,Ap, Ai, Ax, Map) ;complex int Syntax:#include "umfpack.h"int n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ;double *Tx, *Tz, *Ax, *Az ;status = umfpack_zi_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, Tz,Ap, Ai, Ax, Az, Map) ;long Syntax:#include "umfpack.h"long n_row, n_col, nz, *Ti, *Tj, *Ap, *Ai, status, *Map ;double *Tx, *Tz, *Ax, *Az ;status = umfpack_zl_triplet_to_col (n_row, n_col, nz, Ti, Tj, Tx, Tz,Ap, Ai, Ax, Az, Map) ;packed complex Syntax:Same as above, except Tz and Az are NULL.Purpose:Converts a sparse matrix from "triplet" form to compressed-column form.Analogous to A = spconvert (Ti, Tj, Tx + Tz*1i) in MATLAB, except thatzero entries present in the triplet form are present in A.The triplet form of a matrix is a very simple data structure for basicsparse matrix operations. For example, suppose you wish to factorize amatrix A coming from a finite element method, in which A is a sum ofdense submatrices, A = E1 + E2 + E3 + ... . The entries in each elementmatrix Ei can be concatenated together in the three triplet arrays, andany overlap between the elements will be correctly summed byumfpack_*_triplet_to_col.Transposing a matrix in triplet form is simple; just interchange theuse of Ti and Tj. You can construct the complex conjugate transpose bynegating Tz, for the complex versions.Permuting a matrix in triplet form is also simple. If you want the matrixPAQ, or A (P,Q) in MATLAB notation, where P [k] = i means that row i ofA is the kth row of PAQ and Q [k] = j means that column j of A is the kthcolumn of PAQ, then do the following. First, create inverse permutationsPinv and Qinv such that Pinv [i] = k if P [k] = i and Qinv [j] = k ifQ [k] = j. Next, for the mth triplet (Ti [m], Tj [m], Tx [m], Tz [m]),replace Ti [m] with Pinv [Ti [m]] and replace Tj [m] with Qinv [Tj [m]].If you have a column-form matrix with duplicate entries or unsortedcolumns, you can sort it and sum up the duplicates by first converting itto triplet form with umfpack_*_col_to_triplet, and then converting it backwith umfpack_*_triplet_to_col.Constructing a submatrix is also easy. Just scan the triplets and removethose entries outside the desired subset of 0...n_row-1 and 0...n_col-1,and renumber the indices according to their position in the subset.You can do all these operations on a column-form matrix by firstconverting it to triplet form with umfpack_*_col_to_triplet, doing theoperation on the triplet form, and then converting it back withumfpack_*_triplet_to_col.The only operation not supported easily in the triplet form is themultiplication of two sparse matrices (UMFPACK does not provide thisoperation).You can print the input triplet form with umfpack_*_report_triplet, andthe output matrix with umfpack_*_report_matrix.The matrix may be singular (nz can be zero, and empty rows and/or columnsmay exist). It may also be rectangular and/or complex.Returns:UMFPACK_OK if successful.UMFPACK_ERROR_argument_missing if Ap, Ai, Ti, and/or Tj are missing.UMFPACK_ERROR_n_nonpositive if n_row <= 0 or n_col <= 0.UMFPACK_ERROR_invalid_matrix if nz < 0, or if for any k, Ti [k] and/orTj [k] are not in the range 0 to n_row-1 or 0 to n_col-1, respectively.UMFPACK_ERROR_out_of_memory if unable to allocate sufficient workspace.Arguments:Int n_row ; Input argument, not modified.Int n_col ; Input argument, not modified.A is an n_row-by-n_col matrix. Restriction: n_row > 0 and n_col > 0.All row and column indices in the triplet form must be in the range0 to n_row-1 and 0 to n_col-1, respectively.Int nz ; Input argument, not modified.The number of entries in the triplet form of the matrix. Restriction:nz >= 0.Int Ti [nz] ; Input argument, not modified.Int Tj [nz] ; Input argument, not modified.double Tx [nz] ; Input argument, not modified.Size 2*nz if Tz or Az are NULL.double Tz [nz] ; Input argument, not modified, for complex versions.Ti, Tj, Tx, and Tz hold the "triplet" form of a sparse matrix. The kthnonzero entry is in row i = Ti [k], column j = Tj [k], and the real partof a_ij is Tx [k]. The imaginary part of a_ij is Tz [k], for complexversions. The row and column indices i and j must be in the range 0 ton_row-1 and 0 to n_col-1, respectively. Duplicate entries may bepresent; they are summed in the output matrix. This is not an errorcondition. The "triplets" may be in any order. Tx, Tz, Ax, and Azare optional. Ax is computed only if both Ax and Tx are present(not (double *) NULL). This is not error condition; the routine cancreate just the pattern of the output matrix from the pattern of thetriplets.If Az or Tz are NULL, then both realand imaginary parts are contained in Tx[0..2*nz-1], with Tx[2*k]and Tx[2*k+1] being the real and imaginary part of the kth entry.Int Ap [n_col+1] ; Output argument.Ap is an integer array of size n_col+1 on input. On output, Ap holdsthe "pointers" for the column form of the sparse matrix A. Column j ofthe matrix A is held in Ai [(Ap [j]) ... (Ap [j+1]-1)]. The firstentry, Ap [0], is zero, and Ap [j] <= Ap [j+1] holds for all j in therange 0 to n_col-1. The value nz2 = Ap [n_col] is thus the totalnumber of entries in the pattern of the matrix A. Equivalently, thenumber of duplicate triplets is nz - Ap [n_col].Int Ai [nz] ; Output argument.Ai is an integer array of size nz on input. Note that only the firstAp [n_col] entries are used.The nonzero pattern (row indices) for column j is stored inAi [(Ap [j]) ... (Ap [j+1]-1)]. The row indices in a given column jare in ascending order, and no duplicate row indices are present.Row indices are in the range 0 to n_col-1 (the matrix is 0-based).double Ax [nz] ; Output argument. Size 2*nz if Tz or Az are NULL.double Az [nz] ; Output argument for complex versions.Ax and Az (for the complex versions) are double arrays of size nz oninput. Note that only the first Ap [n_col] entries are usedin both arrays.Ax is optional; if Tx and/or Ax are not present (a (double *) NULLpointer), then Ax is not computed. If present, Ax holds thenumerical values of the the real part of the sparse matrix A and Azholds the imaginary parts. The nonzero pattern (row indices) forcolumn j is stored in Ai [(Ap [j]) ... (Ap [j+1]-1)], and thecorresponding numerical values are stored inAx [(Ap [j]) ... (Ap [j+1]-1)]. The imaginary parts are stored inAz [(Ap [j]) ... (Ap [j+1]-1)], for the complex versions.If Az or Tz are NULL, then both realand imaginary parts are returned in Ax[0..2*nz2-1], with Ax[2*k]and Ax[2*k+1] being the real and imaginary part of the kth entry.int Map [nz] ; Optional output argument.If Map is present (a non-NULL pointer to an Int array of size nz), thenon output it holds the position of the triplets in the column-formmatrix. That is, suppose p = Map [k], and the k-th triplet is i=Ti[k],j=Tj[k], and aij=Tx[k]. Then i=Ai[p], and aij will have been summedinto Ax[p] (or simply aij=Ax[p] if there were no duplicate entries alsoin row i and column j). Also, Ap[j] <= p < Ap[j+1]. The Map array isnot computed if it is (Int *) NULL. The Map array is useful forconverting a subsequent triplet form matrix with the same pattern as thefirst one, without calling this routine. If Ti and Tj do not change,then Ap, and Ai can be reused from the prior call toumfpack_*_triplet_to_col. You only need to recompute Ax (and Az for thesplit complex version). This code excerpt properly sums up allduplicate values (for the real version):for (p = 0 ; p < Ap [n_col] ; p++) Ax [p] = 0 ;for (k = 0 ; k < nz ; k++) Ax [Map [k]] += Tx [k] ;This feature is useful (along with the reuse of the Symbolic object) ifyou need to factorize a sequence of triplet matrices with identicalnonzero pattern (the order of the triplets in the Ti,Tj,Tx arrays mustalso remain unchanged). It is faster than calling this routine foreach matrix, and requires no workspace.*/