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 ()
60 sparse_chol_rep (
const chol_type& a,
bool natural,
bool force)
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);
79 OCTAVE_DISABLE_COPY_MOVE (sparse_chol_rep)
83 #if defined (HAVE_CHOLMOD)
91 #if defined (HAVE_CHOLMOD)
92 cholmod_sparse *
L ()
const
97 cholmod_common *cc ()
const
99 cholmod_common *ret =
const_cast<cholmod_common *
> (&m_common);
107 #if defined (HAVE_CHOLMOD)
108 return (m_minor_p ==
from_size_t (m_L->ncol) ? 0 : m_minor_p + 1);
120 double rcond ()
const {
return m_rcond; }
132 #if defined (HAVE_CHOLMOD)
135 cholmod_common m_common;
137 void drop_zeros (
const cholmod_sparse *S);
143 #if defined (HAVE_CHOLMOD)
148 template <
typename chol_type>
157 chol_elt *Sx =
static_cast<chol_elt *
> (S->x);
168 for (; p < pend; p++)
170 chol_elt sik = Sx[p];
172 if (CHOLMOD_IS_NONZERO (sik))
189 template <
typename T>
204 return CHOLMOD_COMPLEX;
209 template <
typename chol_type>
212 bool natural,
bool force)
216 #if defined (HAVE_CHOLMOD)
222 (*current_liboctave_error_handler)
223 (
"sparse_chol requires square matrix");
225 cholmod_common *cm = &m_common;
230 cm->prefer_zomplex =
false;
237 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
nullptr);
241 cm->print =
static_cast<int> (spu) + 2;
242 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function,
248 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide,
251 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
253 cm->final_asis =
false;
254 cm->final_super =
false;
256 cm->final_pack =
true;
257 cm->final_monotonic =
true;
258 cm->final_resymbol =
false;
261 cholmod_sparse *
ac = &
A;
269 ac->nzmax = a.nnz ();
273 #if defined (OCTAVE_ENABLE_64)
274 ac->itype = CHOLMOD_LONG;
276 ac->itype = CHOLMOD_INT;
278 ac->dtype = CHOLMOD_DOUBLE;
280 ac->xtype = get_xtype<chol_elt> ();
291 cm->method[0].ordering = CHOLMOD_NATURAL;
292 cm->postorder =
false;
298 m_is_pd = cm->status == CHOLMOD_OK;
299 info = (m_is_pd ? 0 : cm->status);
301 if (m_is_pd || force)
305 m_minor_p = Lfactor->minor;
309 if (m_minor_p > 0 && m_minor_p < a_nr)
311 std::size_t n1 = a_nr + 1;
320 m_L->ncol = m_minor_p;
327 m_perm.resize (a_nr);
334 static char blank_name[] =
" ";
343 octave_unused_parameter (a);
344 octave_unused_parameter (natural);
345 octave_unused_parameter (force);
347 (*current_liboctave_error_handler)
348 (
"support for CHOLMOD was unavailable or disabled when liboctave was built");
355 template <
typename chol_type>
359 #if defined (HAVE_CHOLMOD)
382 template <
typename chol_type>
384 : m_rep (new typename
sparse_chol<chol_type>::sparse_chol_rep ())
387 template <
typename chol_type>
390 : m_rep (new typename
391 sparse_chol<chol_type>::sparse_chol_rep (a, natural, force))
394 template <
typename chol_type>
397 bool natural,
bool force)
398 : m_rep (new typename
399 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, force))
402 template <
typename chol_type>
406 : m_rep (new typename
407 sparse_chol<chol_type>::sparse_chol_rep (a, info, natural, false))
410 template <
typename chol_type>
413 : m_rep (new typename
414 sparse_chol<chol_type>::sparse_chol_rep (a, info, false, false))
417 template <
typename chol_type>
421 #if defined (HAVE_CHOLMOD)
423 cholmod_sparse *
m = m_rep->L ();
429 chol_type ret (
m->nrow, nc, nnz);
437 ret.xdata (i) =
static_cast<chol_elt *
> (
m->x)[i];
449 template <
typename chol_type>
456 template <
typename chol_type>
460 return m_rep->perm ();
463 template <
typename chol_type>
470 template <
typename chol_type>
474 return m_rep->is_positive_definite ();
477 template <
typename chol_type>
481 return m_rep->rcond ();
484 template <
typename chol_type>
490 #if defined (HAVE_CHOLMOD)
492 cholmod_sparse *
m = m_rep->L ();
498 chol_type linv = L ().hermitian ().inverse (mattype, info, rcond2, 1, 0);
514 template <
typename chol_type>
523 (*current_liboctave_error_handler) (
"U must be a square matrix");
526 int typ = mattype.type (
false);
529 chol_type rtra, multip;
533 rtra =
r.transpose ();
538 rtra =
r.transpose ();
545 retval = multip.inverse (mattypenew, info, rcond,
true,
false);
574 OCTAVE_END_NAMESPACE(math)
575 OCTAVE_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
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
#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,...)