20 #ifndef SELDON_FILE_CHOLMOD_CXX
22 #include "Cholmod.hxx"
27 MatrixCholmod::MatrixCholmod()
30 cholmod_start(¶m_chol);
36 MatrixCholmod::~MatrixCholmod()
41 cholmod_finish(¶m_chol);
45 void MatrixCholmod::HideMessages()
50 void MatrixCholmod::ShowMessages()
55 void MatrixCholmod::ShowFullHistory()
60 size_t MatrixCholmod::GetMemorySize()
const
62 size_t taille =
sizeof(*this);
66 taille += size_t(L->nzmax)*(
sizeof(double) +
sizeof(
int)) + (n+1)*
sizeof(int);
73 int MatrixCholmod::GetInfoFactorization()
const
79 bool MatrixCholmod::UseInteger8()
const
85 void MatrixCholmod::Clear()
90 cholmod_free_factor(&L, ¶m_chol);
95 template<
class Prop,
class Storage,
class Allocator>
97 FactorizeMatrix(Matrix<double, Prop, Storage, Allocator> & mat,
102 Matrix<double, Symmetric, RowSymSparse> Acsc;
112 FactorizeCSR(Matrix<double, Symmetric, RowSymSparse> & Acsc)
118 Vector<int> ptrA; Acsc.FillPtrInt(ptrA);
122 A.nzmax = Acsc.GetDataSize();
124 A.p = ptrA.GetData();
126 A.x = Acsc.GetData();
129 A.xtype = CHOLMOD_REAL;
130 A.dtype = CHOLMOD_DOUBLE;
133 L = cholmod_analyze(&A, ¶m_chol);
136 cholmod_factorize(&A, L, ¶m_chol);
140 cholmod_change_factor(CHOLMOD_REAL,
true,
false,
true,
141 true, L, ¶m_chol);
146 template<
class Allocator>
150 Solve(TransA, x.GetData(), 1);
160 b_rhs.nzmax = b_rhs.nrow;
161 b_rhs.d = b_rhs.nrow;
164 b_rhs.xtype = CHOLMOD_REAL;
165 b_rhs.dtype = CHOLMOD_DOUBLE;
167 cholmod_dense* x_sol, *y;
170 y = cholmod_solve(CHOLMOD_Lt, L, &b_rhs, ¶m_chol);
171 x_sol = cholmod_solve(CHOLMOD_Pt, L, y, ¶m_chol);
175 y = cholmod_solve(CHOLMOD_P, L, &b_rhs, ¶m_chol);
176 x_sol = cholmod_solve(CHOLMOD_L, L, y, ¶m_chol);
179 double* data =
reinterpret_cast<double*
>(x_sol->x);
180 for (
int i = 0; i < n*nrhs; i++)
183 cholmod_free_dense(&x_sol, ¶m_chol);
184 cholmod_free_dense(&y, ¶m_chol);
189 template<
class Allocator>
195 cholmod_dense Xchol,Ychol;
197 Xchol.nrow = X.GetM();
199 Xchol.nzmax = Xchol.nrow;
200 Xchol.d = Xchol.nrow;
201 Xchol.x = X.GetData();
203 Xchol.xtype = CHOLMOD_REAL;
204 Xchol.dtype = CHOLMOD_DOUBLE;
206 Ychol.nrow = X.GetM();
208 Ychol.nzmax = Ychol.nrow;
209 Ychol.d = Ychol.nrow;
210 Ychol.x = Y.GetData();
212 Ychol.xtype = CHOLMOD_REAL;
213 Ychol.dtype = CHOLMOD_DOUBLE;
216 int* pint =
reinterpret_cast<int*
>(L->p);
217 for (
int i = 0; i <= n; i++)
222 Lcsr.SetData(n, n, L->nzmax,
reinterpret_cast<double*
>(L->x),
224 reinterpret_cast<int*
>(L->i));
229 cholmod_dense* x_sol;
230 x_sol = cholmod_solve(CHOLMOD_P, L, &Xchol, ¶m_chol);
232 double* data =
reinterpret_cast<double*
>(x_sol->x);
233 for (
int i = 0; i < n; i++)
236 Seldon::Mlt(Lcsr, Y, X);
238 cholmod_free_dense(&x_sol, ¶m_chol);
243 Seldon::MltAdd(1.0, SeldonTrans, Lcsr, X, 0.0, Y);
245 cholmod_dense* x_sol;
246 x_sol = cholmod_solve(CHOLMOD_Pt, L, &Ychol, ¶m_chol);
248 double* data =
reinterpret_cast<double*
>(x_sol->x);
249 for (
int i = 0; i < X.GetM(); i++)
252 cholmod_free_dense(&x_sol, ¶m_chol);
259 template<
class T,
class Prop,
class Storage,
class Allocator>
263 mat_chol.FactorizeMatrix(A, keep_matrix);
267 template<
class T,
class Allocator>
269 SolveCholesky(
const SeldonTranspose& TransA,
270 MatrixCholmod& mat_chol, Vector<T, VectFull, Allocator>& x)
272 mat_chol.Solve(TransA, x);
276 template<
class T,
class Allocator>
278 MltCholesky(
const SeldonTranspose& TransA,
279 MatrixCholmod& mat_chol, Vector<T, VectFull, Allocator>& x)
281 mat_chol.Mlt(TransA, x);
286 #define SELDON_FILE_CHOLMOD_CXX