33 namespace csparse_extension {
48 return e1.
_c < e2.
_c || (e1.
_c == e2.
_c && e1.
_r < e2.
_r);
56 int cs_cholsolsymb(
const cs *A,
double *b,
const css* S,
double* x,
int* work)
60 if (!CS_CSC (A) || !b || ! S || !x) {
74 cs_ipvec (S->pinv, b, x, n) ;
76 cs_ltsolve (N->L, x) ;
77 cs_pvec (S->pinv, x, b, n) ;
90 double d, lki, *Lx, *x, *Cx ;
91 int top, i, p, k, n, *Li, *Lp, *cp, *pinv, *s, *c, *parent, *Cp, *Ci ;
94 if (!CS_CSC (A) || !S || !S->cp || !S->parent)
return (NULL) ;
96 N = (csn*) cs_calloc (1,
sizeof (csn)) ;
99 cp = S->cp ; pinv = S->pinv ; parent = S->parent ;
100 C = pinv ? cs_symperm (A, pinv, 1) : ((cs *) A) ;
101 E = pinv ? C : NULL ;
102 if (!N || !c || !x || !C)
return (cs_ndone (N, E, NULL, NULL, 0)) ;
104 Cp = C->p ; Ci = C->i ; Cx = C->x ;
105 N->L = L = cs_spalloc (n, n, cp [n], 1, 0) ;
106 if (!L)
return (cs_ndone (N, E, NULL, NULL, 0)) ;
107 Lp = L->p ; Li = L->i ; Lx = L->x ;
108 for (k = 0 ; k < n ; k++) Lp [k] = c [k] = cp [k] ;
109 for (k = 0 ; k < n ; k++)
112 top = cs_ereach (C, k, parent, s, c) ;
114 for (p = Cp [k] ; p < Cp [k+1] ; p++)
116 if (Ci [p] <= k) x [Ci [p]] = Cx [p] ;
121 for ( ; top < n ; top++)
124 lki = x [i] / Lx [Lp [i]] ;
126 for (p = Lp [i] + 1 ; p < c [i] ; p++)
128 x [Li [p]] -= Lx [p] * lki ;
136 if (d <= 0)
return (cs_ndone (N, E, NULL, NULL, 0)) ;
142 return (cs_ndone (N, E, NULL, NULL, 1)) ;
150 string name = filename;
151 std::string::size_type lastDot = name.find_last_of(
'.');
152 if (lastDot != std::string::npos)
153 name = name.substr(0, lastDot);
155 vector<SparseMatrixEntry> entries;
157 const int* Ap = A->p;
158 const int* Ai = A->i;
159 const double* Ax = A->x;
160 for (
int i=0; i < cols; i++) {
161 const int& rbeg = Ap[i];
162 const int& rend = Ap[i+1];
163 for (
int j = rbeg; j < rend; j++) {
165 if (upperTriangular && Ai[j] != i)
170 entries.reserve(A->nz);
174 for (
int i = 0; i < A->nz; ++i) {
176 if (upperTriangular && Ai[i] != Aj[i])
182 std::ofstream fout(filename);
183 fout <<
"# name: " << name << std::endl;
184 fout <<
"# type: sparse matrix" << std::endl;
185 fout <<
"# nnz: " << entries.size() << std::endl;
186 fout <<
"# rows: " << rows << std::endl;
187 fout <<
"# columns: " << cols << std::endl;
189 fout << setprecision(9) << endl;
191 for (vector<SparseMatrixEntry>::const_iterator it = entries.begin(); it != entries.end(); ++it) {
193 fout << entry.
_r+1 <<
" " << entry.
_c+1 <<
" " << entry.
_x << std::endl;
#define __PRETTY_FUNCTION__
SparseMatrixEntry(int r=-1, int c=-1, double x=0.)
int cs_cholsolsymb(const cs *A, double *b, const css *S, double *x, int *work)
bool operator()(const SparseMatrixEntry &e1, const SparseMatrixEntry &e2) const
csn * cs_chol_workspace(const cs *A, const css *S, int *cin, double *xin)
bool writeCs2Octave(const char *filename, const cs *A, bool upperTriangular)