# HG changeset patch # User jwe # Date 1153036143 0 # Node ID d73ffe42f2c8192f8a472382c7bba101c9488e08 # Parent 13aa80fc78398dff9acc52227419f21b6b1ce8a2 [project @ 2006-07-16 07:48:19 by jwe] diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/CSparse.cc --- a/liboctave/CSparse.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/CSparse.cc Sun Jul 16 07:49:03 2006 +0000 @@ -1061,11 +1061,11 @@ double *control = Control.fortran_vec (); UMFPACK_ZNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -1073,7 +1073,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -5544,10 +5544,10 @@ double *control = Control.fortran_vec (); UMFPACK_ZNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -5555,7 +5555,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -5675,7 +5675,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -5932,7 +5932,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -6240,7 +6240,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -6479,7 +6479,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/ChangeLog --- a/liboctave/ChangeLog Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/ChangeLog Sun Jul 16 07:49:03 2006 +0000 @@ -1,3 +1,15 @@ +2006-07-16 John W. Eaton + + * oct-spparms.h, oct-spparms.cc (class octave_sparse_params): + Rename from SparseParams. Use same implementation method as other + singleton classes in Octave. Change all uses of + Voctave_sparse_controls to use static functions from + octave_sparse_params class instead. + + * oct-spparms.h, oct-spparms.cc (SparseParams::set_key, + SparseParams::get_key): Pass std::string arg by const reference, + not const value. + 2006-07-15 John W. Eaton * data-conv.cc: Instantiante swap_bytes templates here. diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/MatrixType.cc --- a/liboctave/MatrixType.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/MatrixType.cc Sun Jul 16 07:49:03 2006 +0000 @@ -37,7 +37,7 @@ MatrixType::MatrixType (void) : typ (MatrixType::Unknown), - sp_bandden (Voctave_sparse_controls.get_key ("bandden")), + sp_bandden (octave_sparse_params::get_key ("bandden")), bandden (0), upper_band (0), lower_band (0), dense (false), full (false), nperm (0), perm (0) { } @@ -184,11 +184,11 @@ octave_idx_type nm = (ncols < nrows ? ncols : nrows); octave_idx_type nnz = a.nzmax (); - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Calculating Sparse Matrix Type"); - sp_bandden = Voctave_sparse_controls.get_key ("bandden"); + sp_bandden = octave_sparse_params::get_key ("bandden"); bool maybe_hermitian = false; typ = MatrixType::Full; @@ -510,12 +510,12 @@ octave_idx_type nm = (ncols < nrows ? ncols : nrows); octave_idx_type nnz = a.nzmax (); - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) full = true; + if (octave_sparse_params::get_key ("spumoni") != 0.) full = true; (*current_liboctave_warning_handler) ("Calculating Sparse Matrix Type"); - sp_bandden = Voctave_sparse_controls.get_key ("bandden"); + sp_bandden = octave_sparse_params::get_key ("bandden"); bool maybe_hermitian = false; typ = MatrixType::Full; @@ -828,7 +828,7 @@ } MatrixType::MatrixType (const matrix_type t, bool _full) : typ (MatrixType::Unknown), - sp_bandden (Voctave_sparse_controls.get_key ("bandden")), + sp_bandden (octave_sparse_params::get_key ("bandden")), bandden (0), upper_band (0), lower_band (0), dense (false), full (_full), nperm (0), perm (0) { @@ -844,7 +844,7 @@ MatrixType::MatrixType (const matrix_type t, const octave_idx_type np, const octave_idx_type *p, bool _full) : typ (MatrixType::Unknown), - sp_bandden (Voctave_sparse_controls.get_key ("bandden")), + sp_bandden (octave_sparse_params::get_key ("bandden")), bandden (0), upper_band (0), lower_band (0), dense (false), full (_full), nperm (0), perm (0) { @@ -863,7 +863,7 @@ MatrixType::MatrixType (const matrix_type t, const octave_idx_type ku, const octave_idx_type kl, bool _full) : typ (MatrixType::Unknown), - sp_bandden (Voctave_sparse_controls.get_key ("bandden")), + sp_bandden (octave_sparse_params::get_key ("bandden")), bandden (0), upper_band (0), lower_band (0), dense (false), full (_full), nperm (0), perm (0) { @@ -914,10 +914,10 @@ MatrixType::type (bool quiet) { if (typ != MatrixType::Unknown && (full || - sp_bandden == Voctave_sparse_controls.get_key ("bandden"))) + sp_bandden == octave_sparse_params::get_key ("bandden"))) { if (!quiet && - Voctave_sparse_controls.get_key ("spumoni") != 0.) + octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Using Cached Matrix Type"); @@ -925,7 +925,7 @@ } if (typ != MatrixType::Unknown && - Voctave_sparse_controls.get_key ("spumoni") != 0.) + octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Invalidating Matrix Type"); @@ -938,9 +938,9 @@ MatrixType::type (const SparseMatrix &a) { if (typ != MatrixType::Unknown && (full || - sp_bandden == Voctave_sparse_controls.get_key ("bandden"))) + sp_bandden == octave_sparse_params::get_key ("bandden"))) { - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Using Cached Matrix Type"); @@ -971,9 +971,9 @@ MatrixType::type (const SparseComplexMatrix &a) { if (typ != MatrixType::Unknown && (full || - sp_bandden == Voctave_sparse_controls.get_key ("bandden"))) + sp_bandden == octave_sparse_params::get_key ("bandden"))) { - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Using Cached Matrix Type"); @@ -1004,7 +1004,7 @@ { if (typ != MatrixType::Unknown) { - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Using Cached Matrix Type"); @@ -1031,7 +1031,7 @@ { if (typ != MatrixType::Unknown) { - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) ("Using Cached Matrix Type"); @@ -1056,7 +1056,7 @@ void MatrixType::info () const { - if (Voctave_sparse_controls.get_key ("spumoni") != 0.) + if (octave_sparse_params::get_key ("spumoni") != 0.) { if (typ == MatrixType::Unknown) (*current_liboctave_warning_handler) diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/SparseCmplxLU.cc --- a/liboctave/SparseCmplxLU.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/SparseCmplxLU.cc Sun Jul 16 07:49:03 2006 +0000 @@ -52,7 +52,7 @@ double *control = Control.fortran_vec (); UMFPACK_ZNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; if (piv_thres >= 0.) @@ -63,7 +63,7 @@ } else { - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -72,7 +72,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -240,7 +240,7 @@ double *control = Control.fortran_vec (); UMFPACK_ZNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; if (piv_thres >= 0.) @@ -251,7 +251,7 @@ } else { - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -267,7 +267,7 @@ Control (UMFPACK_FIXQ) = 1.0; else { - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; } diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/SparsedbleLU.cc --- a/liboctave/SparsedbleLU.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/SparsedbleLU.cc Sun Jul 16 07:49:03 2006 +0000 @@ -51,7 +51,7 @@ double *control = Control.fortran_vec (); UMFPACK_DNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; @@ -63,7 +63,7 @@ } else { - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -72,7 +72,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -228,7 +228,7 @@ double *control = Control.fortran_vec (); UMFPACK_DNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; if (piv_thres >= 0.) @@ -239,7 +239,7 @@ } else { - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -256,7 +256,7 @@ Control (UMFPACK_FIXQ) = 1.0; else { - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; } diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/dSparse.cc --- a/liboctave/dSparse.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/dSparse.cc Sun Jul 16 07:49:03 2006 +0000 @@ -1137,11 +1137,11 @@ double *control = Control.fortran_vec (); UMFPACK_DNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -1149,7 +1149,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -5765,10 +5765,10 @@ double *control = Control.fortran_vec (); UMFPACK_DNAME (defaults) (control); - double tmp = Voctave_sparse_controls.get_key ("spumoni"); + double tmp = octave_sparse_params::get_key ("spumoni"); if (!xisnan (tmp)) Control (UMFPACK_PRL) = tmp; - tmp = Voctave_sparse_controls.get_key ("piv_tol"); + tmp = octave_sparse_params::get_key ("piv_tol"); if (!xisnan (tmp)) { Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; @@ -5776,7 +5776,7 @@ } // Set whether we are allowed to modify Q or not - tmp = Voctave_sparse_controls.get_key ("autoamd"); + tmp = octave_sparse_params::get_key ("autoamd"); if (!xisnan (tmp)) Control (UMFPACK_FIXQ) = tmp; @@ -5893,7 +5893,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -6124,7 +6124,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -6403,7 +6403,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; @@ -6654,7 +6654,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/oct-spparms.cc --- a/liboctave/oct-spparms.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/oct-spparms.cc Sun Jul 16 07:49:03 2006 +0000 @@ -20,97 +20,189 @@ */ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "lo-error.h" #include "lo-ieee.h" #include "oct-spparms.h" -SparseParams Voctave_sparse_controls; +octave_sparse_params *octave_sparse_params::instance = 0; + +bool +octave_sparse_params::instance_ok (void) +{ + bool retval = true; + + if (! instance) + instance = new octave_sparse_params (); + + if (! instance) + { + (*current_liboctave_error_handler) + ("unable to create octave_sparse_params object!"); + + retval = false; + } + + return retval; +} + +void +octave_sparse_params::defaults (void) +{ + if (instance_ok ()) + instance->do_defaults (); +} void -SparseParams::defaults (void) +octave_sparse_params::tight (void) +{ + if (instance_ok ()) + instance->do_tight (); +} + +string_vector +octave_sparse_params::get_keys (void) +{ + return instance_ok () ? instance->do_get_keys () : string_vector (); +} + +ColumnVector +octave_sparse_params::get_vals (void) +{ + return instance_ok () ? instance->do_get_vals () : ColumnVector (); +} + +bool +octave_sparse_params::set_vals (const NDArray& vals) { - Voctave_sparse_controls (0) = 0; // spumoni - Voctave_sparse_controls (1) = 1; // ths_rel - Voctave_sparse_controls (2) = 1; // ths_abs - Voctave_sparse_controls (3) = 0; // exact_d - Voctave_sparse_controls (4) = 3; // supernd - Voctave_sparse_controls (5) = 3; // rreduce - Voctave_sparse_controls (6) = 0.5; // wh_frac - Voctave_sparse_controls (7) = 1; // autommd - Voctave_sparse_controls (8) = 1; // autoamd - Voctave_sparse_controls (9) = 0.1; // piv_tol - Voctave_sparse_controls (10) = 0.5; // bandden - Voctave_sparse_controls (11) = 1; // umfpack + return instance_ok () ? instance->do_set_vals (vals) : false; +} + +bool +octave_sparse_params::set_key (const std::string& key, const double& val) +{ + return instance_ok () ? instance->do_set_key (key, val) : false; +} + +double +octave_sparse_params::get_key (const std::string& key) +{ + return instance_ok () ? instance->do_get_key (key) : octave_NaN; +} + +void +octave_sparse_params::print_info (std::ostream& os, const std::string& prefix) +{ + if (instance_ok ()) + instance->do_print_info (os, prefix); } void -SparseParams::tight (void) +octave_sparse_params::do_defaults (void) { - Voctave_sparse_controls (0) = 0; // spumoni - Voctave_sparse_controls (1) = 1; // ths_rel - Voctave_sparse_controls (2) = 0; // ths_abs - Voctave_sparse_controls (3) = 1; // exact_d - Voctave_sparse_controls (4) = 1; // supernd - Voctave_sparse_controls (5) = 1; // rreduce - Voctave_sparse_controls (6) = 0.5; // wh_frac - Voctave_sparse_controls (7) = 1; // autommd - Voctave_sparse_controls (8) = 1; // autoamd - Voctave_sparse_controls (9) = 0.1; // piv_tol - Voctave_sparse_controls (10) = 0.5; // bandden - Voctave_sparse_controls (11) = 1; // umfpack + params(0) = 0; // spumoni + params(1) = 1; // ths_rel + params(2) = 1; // ths_abs + params(3) = 0; // exact_d + params(4) = 3; // supernd + params(5) = 3; // rreduce + params(6) = 0.5; // wh_frac + params(7) = 1; // autommd + params(8) = 1; // autoamd + params(9) = 0.1; // piv_tol + params(10) = 0.5; // bandden + params(11) = 1; // umfpack +} + +void +octave_sparse_params::do_tight (void) +{ + params(0) = 0; // spumoni + params(1) = 1; // ths_rel + params(2) = 0; // ths_abs + params(3) = 1; // exact_d + params(4) = 1; // supernd + params(5) = 1; // rreduce + params(6) = 0.5; // wh_frac + params(7) = 1; // autommd + params(8) = 1; // autoamd + params(9) = 0.1; // piv_tol + params(10) = 0.5; // bandden + params(11) = 1; // umfpack } void -SparseParams::init_keys (void) +octave_sparse_params::init_keys (void) { - keys (0) = "spumoni"; - keys (1) = "ths_rel"; - keys (2) = "ths_abs"; - keys (3) = "exact_d"; - keys (4) = "supernd"; - keys (5) = "rreduce"; - keys (6) = "wh_frac"; - keys (7) = "autommd"; - keys (8) = "autoamd"; - keys (9) = "piv_tol"; - keys (10) = "bandden"; - keys (11) = "umfpack"; -} - -SparseParams& -SparseParams::operator = (const SparseParams& a) -{ - for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) - params (i) = a.params (i); - - return *this; + keys(0) = "spumoni"; + keys(1) = "ths_rel"; + keys(2) = "ths_abs"; + keys(3) = "exact_d"; + keys(4) = "supernd"; + keys(5) = "rreduce"; + keys(6) = "wh_frac"; + keys(7) = "autommd"; + keys(8) = "autoamd"; + keys(9) = "piv_tol"; + keys(10) = "bandden"; + keys(11) = "umfpack"; } bool -SparseParams::set_key (const std::string key, const double& val) +octave_sparse_params::do_set_vals (const NDArray& vals) +{ + octave_idx_type len = vals.length (); + + if (len > OCTAVE_SPARSE_CONTROLS_SIZE) + { + (*current_liboctave_error_handler) + ("octave_sparse_params::do_set_vals: too many values"); + + return false; + } + else + { + for (int i = 0; i < len; i++) + params(i) = vals(i); + + return true; + } +} + +bool +octave_sparse_params::do_set_key (const std::string& key, const double& val) { for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) - if (keys (i) == key) - { - params(i) = val; - return true; - } + { + if (keys (i) == key) + { + params(i) = val; + return true; + } + } + return false; } double -SparseParams::get_key (const std::string key) +octave_sparse_params::do_get_key (const std::string& key) { for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) - if (keys (i) == key) + { + if (keys (i) == key) return params(i); + } return octave_NaN; } void -SparseParams::print_info (std::ostream& os, const std::string& prefix) const +octave_sparse_params::do_print_info (std::ostream& os, + const std::string& prefix) const { for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) os << prefix << keys(i) << ": " << params(i) << "\n"; diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/oct-spparms.h --- a/liboctave/oct-spparms.h Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/oct-spparms.h Sun Jul 16 07:49:03 2006 +0000 @@ -30,45 +30,69 @@ #include "str-vec.h" #include "dColVector.h" +#include "dNDArray.h" #define OCTAVE_SPARSE_CONTROLS_SIZE 12 class -SparseParams +octave_sparse_params { - public: - SparseParams (void) : params (ColumnVector (OCTAVE_SPARSE_CONTROLS_SIZE)), - keys (string_vector (OCTAVE_SPARSE_CONTROLS_SIZE)) - { defaults (); init_keys (); } - - void defaults (void); +protected: - void tight (void); - - SparseParams& operator = (const SparseParams& a); + octave_sparse_params (void) + : params (OCTAVE_SPARSE_CONTROLS_SIZE), + keys (OCTAVE_SPARSE_CONTROLS_SIZE) + { + init_keys (); + do_defaults (); + } + +public: + + static bool instance_ok (void); + + static void defaults (void); + + static void tight (void); - double& operator () (int n) { return params (n); } - double operator () (int n) const { return params (n); } + static string_vector get_keys (void); - string_vector get_keys (void) const { return keys; } + static ColumnVector get_vals (void); - ColumnVector get_vals (void) const { return params; } + static bool set_vals (const NDArray& vals); - bool set_key (const std::string key, const double& val); + static bool set_key (const std::string& key, const double& val); - double get_key (const std::string key); + static double get_key (const std::string& key); - void print_info (std::ostream& os, const std::string& prefix) const; - - private: - void init_keys (void); + static void print_info (std::ostream& os, const std::string& prefix); + +private: ColumnVector params; string_vector keys; -}; + + static octave_sparse_params *instance; + + void do_defaults (void); + + void do_tight (void); + + string_vector do_get_keys (void) const { return keys; } + + ColumnVector do_get_vals (void) const { return params; } -extern SparseParams Voctave_sparse_controls; + bool do_set_vals (const NDArray& vals); + + bool do_set_key (const std::string& key, const double& val); + + double do_get_key (const std::string& key); + + void do_print_info (std::ostream& os, const std::string& prefix) const; + + void init_keys (void); +}; #endif diff -r 13aa80fc7839 -r d73ffe42f2c8 liboctave/sparse-base-chol.cc --- a/liboctave/sparse-base-chol.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/liboctave/sparse-base-chol.cc Sun Jul 16 07:49:03 2006 +0000 @@ -99,7 +99,7 @@ CHOLMOD_NAME(start) (cm); cm->prefer_zomplex = false; - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; diff -r 13aa80fc7839 -r d73ffe42f2c8 src/DLD-FUNCTIONS/spchol.cc --- a/src/DLD-FUNCTIONS/spchol.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/src/DLD-FUNCTIONS/spchol.cc Sun Jul 16 07:49:03 2006 +0000 @@ -398,7 +398,7 @@ cholmod_common *cm = &Common; CHOLMOD_NAME(start) (cm); - double spu = Voctave_sparse_controls.get_key ("spumoni"); + double spu = octave_sparse_params::get_key ("spumoni"); if (spu == 0.) { cm->print = -1; diff -r 13aa80fc7839 -r d73ffe42f2c8 src/DLD-FUNCTIONS/spparms.cc --- a/src/DLD-FUNCTIONS/spparms.cc Sat Jul 15 18:16:53 2006 +0000 +++ b/src/DLD-FUNCTIONS/spparms.cc Sun Jul 16 07:49:03 2006 +0000 @@ -91,13 +91,13 @@ if (nargin == 0) { if (nargout == 0) - Voctave_sparse_controls.print_info (octave_stdout, ""); + octave_sparse_params::print_info (octave_stdout, ""); else if (nargout == 1) - retval(0) = Voctave_sparse_controls.get_vals (); + retval(0) = octave_sparse_params::get_vals (); else if (nargout == 2) { - retval (0) = Voctave_sparse_controls.get_keys (); - retval (1) = Voctave_sparse_controls.get_vals (); + retval (0) = octave_sparse_params::get_keys (); + retval (1) = octave_sparse_params::get_vals (); } else error ("spparms: too many output arguments"); @@ -112,12 +112,12 @@ str [i] = tolower (str [i]); if (str == "defaults") - Voctave_sparse_controls.defaults (); + octave_sparse_params::defaults (); else if (str == "tight") - Voctave_sparse_controls.tight (); + octave_sparse_params::tight (); else { - double val = Voctave_sparse_controls.get_key (str); + double val = octave_sparse_params::get_key (str); if (xisnan (val)) error ("spparams: unrecognized key"); else @@ -133,8 +133,7 @@ else if (vals.numel () > OCTAVE_SPARSE_CONTROLS_SIZE) error ("spparams: too many elements in values vector"); else - for (int i = 0; i < vals.length (); i++) - Voctave_sparse_controls (i) = vals (i); + octave_sparse_params::set_vals (vals); } } else if (nargin == 2) @@ -149,7 +148,7 @@ error ("spparms: second argument must be a real scalar"); else if (str == "umfpack") warning ("spparms: request to disable umfpack solvers ignored"); - else if (!Voctave_sparse_controls.set_key (str, val)) + else if (!octave_sparse_params::set_key (str, val)) error ("spparms: key not found"); } else