26#if defined (HAVE_CONFIG_H)
47template <
typename chol_type>
53 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
54#if defined (HAVE_CHOLMOD)
55 , m_L (nullptr), m_common ()
59 sparse_chol_rep (
const chol_type& a,
bool natural,
bool force)
60 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
61#if defined (HAVE_CHOLMOD)
62 , m_L (nullptr), m_common ()
65 init (a, natural, force);
69 bool natural,
bool force)
70 : m_is_pd (false), m_minor_p (0), m_perm (), m_rcond (0)
71#if defined (HAVE_CHOLMOD)
72 , m_L (nullptr), m_common ()
75 info = init (a, natural, force);
78 OCTAVE_DISABLE_COPY_MOVE (sparse_chol_rep)
82#if defined (HAVE_CHOLMOD)
90#if defined (HAVE_CHOLMOD)
91 cholmod_sparse *
L ()
const
96 cholmod_common * cc ()
const
98 cholmod_common *ret =
const_cast<cholmod_common *
> (&m_common);
106#if defined (HAVE_CHOLMOD)
107 return (m_minor_p ==
from_size_t (m_L->ncol) ? 0 : m_minor_p + 1);
119 double rcond ()
const {
return m_rcond; }
131#if defined (HAVE_CHOLMOD)
134 cholmod_common m_common;
136 void drop_zeros (
const cholmod_sparse *S);
142#if defined (HAVE_CHOLMOD)
147template <
typename chol_type>
156 chol_elt *Sx =
static_cast<chol_elt *
> (S->x);
167 for (; p < pend; p++)
169 chol_elt sik = Sx[p];
171 if (CHOLMOD_IS_NONZERO (sik))
203 return CHOLMOD_COMPLEX;
208template <
typename chol_type>
211 bool natural,
bool force)
215#if defined (HAVE_CHOLMOD)
221 (*current_liboctave_error_handler)
222 (
"sparse_chol requires square matrix");
224 cholmod_common *cm = &m_common;
229 cm->prefer_zomplex =
false;
236 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
nullptr);
240 cm->print =
static_cast<int> (spu) + 2;
241 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
247 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide,
250 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
252 cm->final_asis =
false;
253 cm->final_super =
false;
255 cm->final_pack =
true;
256 cm->final_monotonic =
true;
257 cm->final_resymbol =
false;
260 cholmod_sparse *ac = &
A;
268 ac->nzmax = a.nnz ();
272#if defined (OCTAVE_ENABLE_64)
273 ac->itype = CHOLMOD_LONG;
275 ac->itype = CHOLMOD_INT;
277 ac->dtype = CHOLMOD_DOUBLE;
279 ac->xtype = get_xtype<chol_elt> ();
290 cm->method[0].ordering = CHOLMOD_NATURAL;
291 cm->postorder =
false;
294 cholmod_factor *Lfactor =
CHOLMOD_NAME(analyze) (ac, cm);
297 m_is_pd = cm->status == CHOLMOD_OK;
298 info = (m_is_pd ? 0 : cm->status);
300 if (m_is_pd || force)
304 m_minor_p = Lfactor->minor;
308 if (m_minor_p > 0 && m_minor_p < a_nr)
310 std::size_t n1 = a_nr + 1;
319 m_L->ncol = m_minor_p;
326 m_perm.resize (a_nr);
333 static char blank_name[] =
" ";
342 octave_unused_parameter (a);
343 octave_unused_parameter (natural);
344 octave_unused_parameter (force);
346 (*current_liboctave_error_handler)
347 (
"support for CHOLMOD was unavailable or disabled when liboctave was built");
354template <
typename chol_type>
358#if defined (HAVE_CHOLMOD)
381template <
typename chol_type>
383 : m_rep (new typename
sparse_chol<chol_type>::sparse_chol_rep ())
386template <
typename chol_type>
389 : m_rep (new typename
390 sparse_chol<chol_type>::sparse_chol_rep (a, natural, force))
393template <
typename chol_type>
396 bool natural,
bool force)
397 : m_rep (new typename
398 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, force))
401template <
typename chol_type>
405 : m_rep (new typename
406 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, false))
409template <
typename chol_type>
412 : m_rep (new typename
413 sparse_chol<chol_type>::sparse_chol_rep (a, info, false, false))
416template <
typename chol_type>
420#if defined (HAVE_CHOLMOD)
422 cholmod_sparse *m = m_rep->L ();
428 chol_type ret (m->nrow, nc, nnz);
436 ret.xdata (i) =
static_cast<chol_elt *
> (m->x)[i];
448template <
typename chol_type>
455template <
typename chol_type>
459 return m_rep->perm ();
462template <
typename chol_type>
469template <
typename chol_type>
473 return m_rep->is_positive_definite ();
476template <
typename chol_type>
480 return m_rep->rcond ();
483template <
typename chol_type>
489#if defined (HAVE_CHOLMOD)
491 cholmod_sparse *m = m_rep->L ();
497 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0);
499 if (m_perm.
numel () == n)
513template <
typename chol_type>
522 (*current_liboctave_error_handler) (
"U must be a square matrix");
525 int typ = mattype.type (
false);
528 chol_type rtra, multip;
532 rtra = r.transpose ();
537 rtra = r.transpose ();
544 retval = multip.inverse (mattypenew, info, rcond,
true,
false);
573OCTAVE_END_NAMESPACE(math)
574OCTAVE_END_NAMESPACE(octave)
octave_idx_type numel() const
Number of elements in the array.
SparseMatrix transpose() const
SparseMatrix hermitian() const
octave_idx_type P() const
bool is_positive_definite() const
chol_type inverse() const
chol_type::element_type chol_elt
static double get_key(const std::string &key)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
#define CHOLMOD_NAME(name)
octave_idx_type from_suitesparse_long(SuiteSparse_long x)
octave_idx_type from_size_t(std::size_t x)
int get_xtype< Complex >()
template SparseMatrix chol2inv< SparseMatrix >(const SparseMatrix &r)
int get_xtype< double >()
chol_type chol2inv(const chol_type &r)
template SparseComplexMatrix chol2inv< SparseComplexMatrix >(const SparseComplexMatrix &r)
void SparseCholError(int status, char *file, int line, char *message)
int SparseCholPrint(const char *fmt,...)