26 #if defined (HAVE_CONFIG_H)
48 template <
typename chol_type>
54 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
55 #if defined (HAVE_CHOLMOD)
56 , m_L (nullptr), m_common ()
61 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
62 #if defined (HAVE_CHOLMOD)
63 , m_L (nullptr), m_common ()
66 init (a, natural, force);
70 bool natural,
bool force)
71 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
72 #if defined (HAVE_CHOLMOD)
73 , m_L (nullptr), m_common ()
76 info = init (a, natural, force);
87 #if defined (HAVE_CHOLMOD)
95 #if defined (HAVE_CHOLMOD)
96 cholmod_sparse *
L (
void)
const
104 #if defined (HAVE_CHOLMOD)
118 double rcond (
void)
const {
return m_rcond; }
130 #if defined (HAVE_CHOLMOD)
135 void drop_zeros (
const cholmod_sparse *S);
141 #if defined (HAVE_CHOLMOD)
146 template <
typename chol_type>
166 for (; p < pend; p++)
170 if (CHOLMOD_IS_NONZERO (sik))
187 template <
typename T>
202 return CHOLMOD_COMPLEX;
207 template <
typename chol_type>
210 bool natural,
bool force)
214 #if defined (HAVE_CHOLMOD)
220 (*current_liboctave_error_handler)
221 (
"sparse_chol requires square matrix");
223 cholmod_common *cm = &m_common;
228 cm->prefer_zomplex =
false;
235 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
nullptr);
239 cm->print =
static_cast<int> (spu) + 2;
240 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
246 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide,
249 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
251 cm->final_asis =
false;
252 cm->final_super =
false;
254 cm->final_pack =
true;
255 cm->final_monotonic =
true;
256 cm->final_resymbol =
false;
259 cholmod_sparse *
ac = &
A;
267 ac->nzmax = a.nnz ();
271 #if defined (OCTAVE_ENABLE_64)
272 ac->itype = CHOLMOD_LONG;
274 ac->itype = CHOLMOD_INT;
276 ac->dtype = CHOLMOD_DOUBLE;
278 ac->xtype = get_xtype<chol_elt> ();
289 cm->method[0].ordering = CHOLMOD_NATURAL;
290 cm->postorder =
false;
296 m_is_pd = cm->status == CHOLMOD_OK;
297 info = (m_is_pd ? 0 : cm->status);
299 if (m_is_pd || force)
303 m_minor_p = Lfactor->minor;
307 if (m_minor_p > 0 && m_minor_p < a_nr)
309 std::size_t n1 = a_nr + 1;
318 m_L->ncol = m_minor_p;
325 m_perm.resize (a_nr);
332 static char blank_name[] =
" ";
341 octave_unused_parameter (a);
342 octave_unused_parameter (natural);
343 octave_unused_parameter (force);
345 (*current_liboctave_error_handler)
346 (
"support for CHOLMOD was unavailable or disabled when liboctave was built");
353 template <
typename chol_type>
357 #if defined (HAVE_CHOLMOD)
380 template <
typename chol_type>
385 template <
typename chol_type>
388 : m_rep (new typename
392 template <
typename chol_type>
395 bool natural,
bool force)
396 : m_rep (new typename
400 template <
typename chol_type>
404 : m_rep (new typename
408 template <
typename chol_type>
411 : m_rep (new typename
415 template <
typename chol_type>
419 #if defined (HAVE_CHOLMOD)
421 cholmod_sparse *
m = m_rep->L ();
426 chol_type ret (
m->nrow, nc, nnz);
434 ret.xdata (i) =
static_cast<chol_elt *
>(
m->x)[i];
446 template <
typename chol_type>
453 template <
typename chol_type>
457 return m_rep->perm ();
460 template <
typename chol_type>
467 template <
typename chol_type>
471 return m_rep->is_positive_definite ();
474 template <
typename chol_type>
478 return m_rep->rcond ();
481 template <
typename chol_type>
487 #if defined (HAVE_CHOLMOD)
489 cholmod_sparse *
m = m_rep->L ();
495 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0);
511 template <
typename chol_type>
520 (*current_liboctave_error_handler) (
"U must be a square matrix");
523 int typ = mattype.type (
false);
526 chol_type rtra, multip;
530 rtra =
r.transpose ();
535 rtra =
r.transpose ();
542 retval = multip.inverse (mattypenew, info, rcond,
true,
false);
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
SparseMatrix transpose(void) const
SparseMatrix hermitian(void) const
octave_idx_type * xcidx(void)
octave_idx_type * xridx(void)
octave_idx_type init(const chol_type &a, bool natural, bool force)
sparse_chol_rep(const chol_type &a, octave_idx_type &info, bool natural, bool force)
SparseMatrix Q(void) const
void drop_zeros(const cholmod_sparse *S)
octave_idx_type P(void) const
bool is_positive_definite(void) const
cholmod_sparse * L(void) const
octave_idx_type m_minor_p
sparse_chol_rep(const sparse_chol_rep &)=delete
RowVector perm(void) const
sparse_chol_rep(const chol_type &a, bool natural, bool force)
RowVector perm(void) const
sparse_chol< chol_type > & operator=(const sparse_chol< chol_type > &a)=default
SparseMatrix Q(void) const
std::shared_ptr< sparse_chol_rep > m_rep
bool is_positive_definite(void) const
chol_type inverse(void) const
chol_type::element_type chol_elt
octave_idx_type P(void) const
static double get_key(const std::string &key)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Q
F77_RET_T const F77_INT F77_CMPLX * A
class OCTAVE_API SparseMatrix
#define CHOLMOD_NAME(name)
template OCTAVE_API SparseMatrix chol2inv< SparseMatrix >(const SparseMatrix &r)
int get_xtype< Complex >(void)
int get_xtype< double >(void)
chol_type chol2inv(const chol_type &r)
template OCTAVE_API SparseComplexMatrix chol2inv< SparseComplexMatrix >(const SparseComplexMatrix &r)
void SparseCholError(int status, char *file, int line, char *message)
int SparseCholPrint(const char *fmt,...)