00001 /* 00002 00003 Copyright (C) 2004-2012 David Bateman 00004 Copyright (C) 1998-2004 Andy Adler 00005 00006 This file is part of Octave. 00007 00008 Octave is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License as published by the 00010 Free Software Foundation; either version 3 of the License, or (at your 00011 option) any later version. 00012 00013 Octave is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Octave; see the file COPYING. If not, see 00020 <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include <config.h> 00026 #endif 00027 00028 #include "lo-error.h" 00029 #include "lo-ieee.h" 00030 00031 #include "oct-spparms.h" 00032 #include "singleton-cleanup.h" 00033 00034 octave_sparse_params *octave_sparse_params::instance = 0; 00035 00036 bool 00037 octave_sparse_params::instance_ok (void) 00038 { 00039 bool retval = true; 00040 00041 if (! instance) 00042 { 00043 instance = new octave_sparse_params (); 00044 00045 if (instance) 00046 singleton_cleanup_list::add (cleanup_instance); 00047 } 00048 00049 if (! instance) 00050 { 00051 (*current_liboctave_error_handler) 00052 ("unable to create octave_sparse_params object!"); 00053 00054 retval = false; 00055 } 00056 00057 return retval; 00058 } 00059 00060 void 00061 octave_sparse_params::defaults (void) 00062 { 00063 if (instance_ok ()) 00064 instance->do_defaults (); 00065 } 00066 00067 void 00068 octave_sparse_params::tight (void) 00069 { 00070 if (instance_ok ()) 00071 instance->do_tight (); 00072 } 00073 00074 string_vector 00075 octave_sparse_params::get_keys (void) 00076 { 00077 return instance_ok () ? instance->do_get_keys () : string_vector (); 00078 } 00079 00080 ColumnVector 00081 octave_sparse_params::get_vals (void) 00082 { 00083 return instance_ok () ? instance->do_get_vals () : ColumnVector (); 00084 } 00085 00086 bool 00087 octave_sparse_params::set_vals (const NDArray& vals) 00088 { 00089 return instance_ok () ? instance->do_set_vals (vals) : false; 00090 } 00091 00092 bool 00093 octave_sparse_params::set_key (const std::string& key, const double& val) 00094 { 00095 return instance_ok () ? instance->do_set_key (key, val) : false; 00096 } 00097 00098 double 00099 octave_sparse_params::get_key (const std::string& key) 00100 { 00101 return instance_ok () ? instance->do_get_key (key) : octave_NaN; 00102 } 00103 00104 double 00105 octave_sparse_params::get_bandden (void) 00106 { 00107 return instance_ok () ? instance->do_get_bandden () : 0.0; 00108 } 00109 00110 void 00111 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix) 00112 { 00113 if (instance_ok ()) 00114 instance->do_print_info (os, prefix); 00115 } 00116 00117 void 00118 octave_sparse_params::do_defaults (void) 00119 { 00120 params(0) = 0; // spumoni 00121 params(1) = 1; // ths_rel 00122 params(2) = 1; // ths_abs 00123 params(3) = 0; // exact_d 00124 params(4) = 3; // supernd 00125 params(5) = 3; // rreduce 00126 params(6) = 0.5; // wh_frac 00127 params(7) = 1; // autommd 00128 params(8) = 1; // autoamd 00129 params(9) = 0.1; // piv_tol 00130 params(10) = 0.5; // bandden 00131 params(11) = 1; // umfpack 00132 params(12) = 0.001; // sym_tol 00133 } 00134 00135 void 00136 octave_sparse_params::do_tight (void) 00137 { 00138 params(0) = 0; // spumoni 00139 params(1) = 1; // ths_rel 00140 params(2) = 0; // ths_abs 00141 params(3) = 1; // exact_d 00142 params(4) = 1; // supernd 00143 params(5) = 1; // rreduce 00144 params(6) = 0.5; // wh_frac 00145 params(7) = 1; // autommd 00146 params(8) = 1; // autoamd 00147 params(9) = 0.1; // piv_tol 00148 params(10) = 0.5; // bandden 00149 params(11) = 1; // umfpack 00150 params(12) = 0.001; // sym_tol 00151 } 00152 00153 void 00154 octave_sparse_params::init_keys (void) 00155 { 00156 keys(0) = "spumoni"; 00157 keys(1) = "ths_rel"; 00158 keys(2) = "ths_abs"; 00159 keys(3) = "exact_d"; 00160 keys(4) = "supernd"; 00161 keys(5) = "rreduce"; 00162 keys(6) = "wh_frac"; 00163 keys(7) = "autommd"; 00164 keys(8) = "autoamd"; 00165 keys(9) = "piv_tol"; 00166 keys(10) = "bandden"; 00167 keys(11) = "umfpack"; 00168 keys(12) = "sym_tol"; 00169 } 00170 00171 double 00172 octave_sparse_params::do_get_bandden (void) 00173 { 00174 return params(10); 00175 } 00176 00177 bool 00178 octave_sparse_params::do_set_vals (const NDArray& vals) 00179 { 00180 octave_idx_type len = vals.length (); 00181 00182 if (len > OCTAVE_SPARSE_CONTROLS_SIZE) 00183 { 00184 (*current_liboctave_error_handler) 00185 ("octave_sparse_params::do_set_vals: too many values"); 00186 00187 return false; 00188 } 00189 else 00190 { 00191 for (int i = 0; i < len; i++) 00192 params(i) = vals(i); 00193 00194 return true; 00195 } 00196 } 00197 00198 bool 00199 octave_sparse_params::do_set_key (const std::string& key, const double& val) 00200 { 00201 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) 00202 { 00203 if (keys (i) == key) 00204 { 00205 params(i) = val; 00206 return true; 00207 } 00208 } 00209 00210 return false; 00211 } 00212 00213 double 00214 octave_sparse_params::do_get_key (const std::string& key) 00215 { 00216 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) 00217 { 00218 if (keys (i) == key) 00219 return params(i); 00220 } 00221 00222 return octave_NaN; 00223 } 00224 00225 void 00226 octave_sparse_params::do_print_info (std::ostream& os, 00227 const std::string& prefix) const 00228 { 00229 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) 00230 os << prefix << keys(i) << ": " << params(i) << "\n"; 00231 }