# HG changeset patch # User John W. Eaton # Date 1346360244 14400 # Node ID 94cdf82d4a0cba97b7b80ddfa532bcee21dde4e7 # Parent 2136343014d56ddd5d6f997a678ceffe76eb4bf1 don't overload meaning of info in Sparse Cholesky factorization functions * chol.cc (Fchol): New variable, force. Always pass natural and force to SparseCHOL and SparseComplexCHOL constructors. * SparsedbleCHOL.h, SparsedbleCHOL.cc (SparseCHOL::SparseCHOL): New arg, force. Pass it to sparse_base_chol constructor. * SparseCmplxCHOL.h, SparseCmplxCHOL.cc (SparseComplexCHOL::SparseComplexCHOL): Likewise. * sparse-base-chol.h (sparse_base_chol<>::sparse_base_chol_rep::init): * sparse-base-chol.h, sparse-base-chol.cc (sparse_base_chol<>::sparse_base_chol_rep::init): Replace nargout argument with force. Check force, not nargout > 1. * sparse-base-chol.h (sparse_base_chol::sparse_base_chol_rep::sparse_base_chol_rep): New arg, force. Pass it to init. (sparse_base_chol::sparse_base_chol): New arg force. Pass it to rep constructor. diff --git a/libinterp/dldfcn/chol.cc b/libinterp/dldfcn/chol.cc --- a/libinterp/dldfcn/chol.cc +++ b/libinterp/dldfcn/chol.cc @@ -180,7 +180,6 @@ octave_idx_type nr = arg.rows (); octave_idx_type nc = arg.columns (); - bool natural = (nargout != 3); int arg_is_empty = empty_arg ("chol", nr, nc); @@ -191,14 +190,18 @@ if (arg.is_sparse_type ()) { + octave_idx_type info; + bool natural = (nargout != 3); + bool force = nargout > 1; + if (arg.is_real_type ()) { SparseMatrix m = arg.sparse_matrix_value (); if (! error_state) { - octave_idx_type info = nargout; - SparseCHOL fact (m, info, natural); + SparseCHOL fact (m, info, natural, force); + if (nargout == 3) { if (vecout) @@ -225,8 +228,7 @@ if (! error_state) { - octave_idx_type info = nargout; - SparseComplexCHOL fact (m, info, natural); + SparseComplexCHOL fact (m, info, natural, force); if (nargout == 3) { @@ -405,14 +407,16 @@ { if (arg.is_sparse_type ()) { + octave_idx_type info; + if (arg.is_real_type ()) { SparseMatrix m = arg.sparse_matrix_value (); if (! error_state) { - octave_idx_type info; SparseCHOL chol (m, info); + if (info == 0) retval = chol.inverse (); else @@ -425,8 +429,8 @@ if (! error_state) { - octave_idx_type info; SparseComplexCHOL chol (m, info); + if (info == 0) retval = chol.inverse (); else diff --git a/liboctave/SparseCmplxCHOL.h b/liboctave/SparseCmplxCHOL.h --- a/liboctave/SparseCmplxCHOL.h +++ b/liboctave/SparseCmplxCHOL.h @@ -38,14 +38,13 @@ SparseComplexCHOL (void) : sparse_base_chol () { } - SparseComplexCHOL (const SparseComplexMatrix& a, bool natural = true) : - sparse_base_chol - (a, natural) { } + SparseComplexCHOL (const SparseComplexMatrix& a, bool natural = true, + bool force = false) : + sparse_base_chol (a, natural, force) { } SparseComplexCHOL (const SparseComplexMatrix& a, octave_idx_type& info, - bool natural = true) : - sparse_base_chol - (a, info, natural) { } + bool natural = true, bool force = false) : + sparse_base_chol (a, info, natural, force) { } SparseComplexCHOL (const SparseComplexCHOL& a) : sparse_base_chol (a) { } diff --git a/liboctave/SparsedbleCHOL.h b/liboctave/SparsedbleCHOL.h --- a/liboctave/SparsedbleCHOL.h +++ b/liboctave/SparsedbleCHOL.h @@ -35,12 +35,12 @@ SparseCHOL (void) : sparse_base_chol () { } - SparseCHOL (const SparseMatrix& a, bool natural = true) : - sparse_base_chol (a, natural) { } + SparseCHOL (const SparseMatrix& a, bool natural = true, bool force = false) : + sparse_base_chol (a, natural, force) { } SparseCHOL (const SparseMatrix& a, octave_idx_type& info, - bool natural = true) : - sparse_base_chol (a, info, natural) { } + bool natural = false, bool force = false) : + sparse_base_chol (a, info, natural, force) { } SparseCHOL (const SparseCHOL& a) : sparse_base_chol (a) { } diff --git a/liboctave/sparse-base-chol.cc b/liboctave/sparse-base-chol.cc --- a/liboctave/sparse-base-chol.cc +++ b/liboctave/sparse-base-chol.cc @@ -80,9 +80,10 @@ template octave_idx_type sparse_base_chol::sparse_base_chol_rep::init - (const chol_type& a, bool natural, octave_idx_type nargout) + (const chol_type& a, bool natural, bool force) { volatile octave_idx_type info = 0; + #ifdef HAVE_CHOLMOD octave_idx_type a_nr = a.rows (); octave_idx_type a_nc = a.cols (); @@ -170,7 +171,7 @@ is_pd = cm->status == CHOLMOD_OK; info = (is_pd ? 0 : cm->status); - if (is_pd || nargout > 1) + if (is_pd || force) { BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; cond = CHOLMOD_NAME(rcond) (Lfactor, cm); diff --git a/liboctave/sparse-base-chol.h b/liboctave/sparse-base-chol.h --- a/liboctave/sparse-base-chol.h +++ b/liboctave/sparse-base-chol.h @@ -41,19 +41,19 @@ perms (), cond (0) { } - sparse_base_chol_rep (const chol_type& a, const bool natural) + sparse_base_chol_rep (const chol_type& a, bool natural, bool force) : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0), perms (), cond (0) { - init (a, natural); + init (a, natural, force); } sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, - const bool natural) + bool natural, bool force) : count (1), Lsparse (0), Common (), is_pd (false), minor_p (0), perms (), cond (0) { - info = init (a, natural, info); + info = init (a, natural, force); } ~sparse_base_chol_rep (void) @@ -93,8 +93,7 @@ double cond; - octave_idx_type init (const chol_type& a, bool natural = true, - octave_idx_type nargout = 1); + octave_idx_type init (const chol_type& a, bool natural, bool force); void drop_zeros (const cholmod_sparse* S); @@ -111,18 +110,17 @@ sparse_base_chol_rep (void) : count (1), is_pd (false), minor_p (0), perms (), cond (0) { } - sparse_base_chol_rep (const chol_type& a, - const bool natural) + sparse_base_chol_rep (const chol_type& a, bool natural, bool force) : count (1), is_pd (false), minor_p (0), perms (), cond (0) { - init (a, natural); + init (a, natural, force); } sparse_base_chol_rep (const chol_type& a, octave_idx_type& info, - const bool natural) + bool natural, bool force) : count (1), is_pd (false), minor_p (0), perms (), cond (0) { - info = init (a, natural, info); + info = init (a, natural, force); } ~sparse_base_chol_rep (void) { } @@ -148,8 +146,7 @@ double cond; - octave_idx_type init (const chol_type& a, bool natural = true, - octave_idx_type nargout = 0); + octave_idx_type init (const chol_type& a, bool natural, bool force); // No copying! @@ -169,13 +166,14 @@ sparse_base_chol::sparse_base_chol_rep ()) { } - sparse_base_chol (const chol_type& a, const bool n) + sparse_base_chol (const chol_type& a, bool natural, bool force) : rep (new typename - sparse_base_chol::sparse_base_chol_rep (a, n)) + sparse_base_chol::sparse_base_chol_rep (a, natural, force)) { } - sparse_base_chol (const chol_type& a, octave_idx_type& info, const bool n) - : rep (new typename sparse_base_chol::sparse_base_chol_rep (a, info, n)) + sparse_base_chol (const chol_type& a, octave_idx_type& info, + bool natural, bool force) + : rep (new typename sparse_base_chol::sparse_base_chol_rep (a, info, natural, force)) { } sparse_base_chol (const sparse_base_chol& a)