5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
7016
|
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
|
5 |
|
6 This file is part of Octave. |
5164
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
5164
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
5164
|
21 |
|
22 */ |
|
23 |
5893
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "lo-error.h" |
5164
|
29 #include "lo-ieee.h" |
|
30 |
|
31 #include "oct-spparms.h" |
|
32 |
5893
|
33 octave_sparse_params *octave_sparse_params::instance = 0; |
|
34 |
|
35 bool |
|
36 octave_sparse_params::instance_ok (void) |
|
37 { |
|
38 bool retval = true; |
|
39 |
|
40 if (! instance) |
|
41 instance = new octave_sparse_params (); |
|
42 |
|
43 if (! instance) |
|
44 { |
|
45 (*current_liboctave_error_handler) |
|
46 ("unable to create octave_sparse_params object!"); |
|
47 |
|
48 retval = false; |
|
49 } |
|
50 |
|
51 return retval; |
|
52 } |
|
53 |
|
54 void |
|
55 octave_sparse_params::defaults (void) |
|
56 { |
|
57 if (instance_ok ()) |
|
58 instance->do_defaults (); |
|
59 } |
5164
|
60 |
|
61 void |
5893
|
62 octave_sparse_params::tight (void) |
|
63 { |
|
64 if (instance_ok ()) |
|
65 instance->do_tight (); |
|
66 } |
|
67 |
|
68 string_vector |
|
69 octave_sparse_params::get_keys (void) |
|
70 { |
|
71 return instance_ok () ? instance->do_get_keys () : string_vector (); |
|
72 } |
|
73 |
|
74 ColumnVector |
|
75 octave_sparse_params::get_vals (void) |
|
76 { |
|
77 return instance_ok () ? instance->do_get_vals () : ColumnVector (); |
|
78 } |
|
79 |
|
80 bool |
|
81 octave_sparse_params::set_vals (const NDArray& vals) |
5164
|
82 { |
5893
|
83 return instance_ok () ? instance->do_set_vals (vals) : false; |
|
84 } |
|
85 |
|
86 bool |
|
87 octave_sparse_params::set_key (const std::string& key, const double& val) |
|
88 { |
|
89 return instance_ok () ? instance->do_set_key (key, val) : false; |
|
90 } |
|
91 |
|
92 double |
|
93 octave_sparse_params::get_key (const std::string& key) |
|
94 { |
|
95 return instance_ok () ? instance->do_get_key (key) : octave_NaN; |
|
96 } |
|
97 |
6460
|
98 double |
|
99 octave_sparse_params::get_bandden (void) |
|
100 { |
|
101 return instance_ok () ? instance->do_get_bandden () : 0.0; |
|
102 } |
|
103 |
5893
|
104 void |
|
105 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix) |
|
106 { |
|
107 if (instance_ok ()) |
|
108 instance->do_print_info (os, prefix); |
5164
|
109 } |
|
110 |
|
111 void |
5893
|
112 octave_sparse_params::do_defaults (void) |
5164
|
113 { |
5893
|
114 params(0) = 0; // spumoni |
|
115 params(1) = 1; // ths_rel |
|
116 params(2) = 1; // ths_abs |
|
117 params(3) = 0; // exact_d |
|
118 params(4) = 3; // supernd |
|
119 params(5) = 3; // rreduce |
|
120 params(6) = 0.5; // wh_frac |
|
121 params(7) = 1; // autommd |
|
122 params(8) = 1; // autoamd |
|
123 params(9) = 0.1; // piv_tol |
|
124 params(10) = 0.5; // bandden |
|
125 params(11) = 1; // umfpack |
|
126 } |
|
127 |
|
128 void |
|
129 octave_sparse_params::do_tight (void) |
|
130 { |
|
131 params(0) = 0; // spumoni |
|
132 params(1) = 1; // ths_rel |
|
133 params(2) = 0; // ths_abs |
|
134 params(3) = 1; // exact_d |
|
135 params(4) = 1; // supernd |
|
136 params(5) = 1; // rreduce |
|
137 params(6) = 0.5; // wh_frac |
|
138 params(7) = 1; // autommd |
|
139 params(8) = 1; // autoamd |
|
140 params(9) = 0.1; // piv_tol |
|
141 params(10) = 0.5; // bandden |
|
142 params(11) = 1; // umfpack |
5164
|
143 } |
|
144 |
|
145 void |
5893
|
146 octave_sparse_params::init_keys (void) |
5164
|
147 { |
5893
|
148 keys(0) = "spumoni"; |
|
149 keys(1) = "ths_rel"; |
|
150 keys(2) = "ths_abs"; |
|
151 keys(3) = "exact_d"; |
|
152 keys(4) = "supernd"; |
|
153 keys(5) = "rreduce"; |
|
154 keys(6) = "wh_frac"; |
|
155 keys(7) = "autommd"; |
|
156 keys(8) = "autoamd"; |
|
157 keys(9) = "piv_tol"; |
|
158 keys(10) = "bandden"; |
|
159 keys(11) = "umfpack"; |
5164
|
160 } |
|
161 |
6460
|
162 double |
|
163 octave_sparse_params::do_get_bandden (void) |
|
164 { |
|
165 return params(10); |
|
166 } |
|
167 |
5164
|
168 bool |
5893
|
169 octave_sparse_params::do_set_vals (const NDArray& vals) |
|
170 { |
|
171 octave_idx_type len = vals.length (); |
|
172 |
|
173 if (len > OCTAVE_SPARSE_CONTROLS_SIZE) |
|
174 { |
|
175 (*current_liboctave_error_handler) |
|
176 ("octave_sparse_params::do_set_vals: too many values"); |
|
177 |
|
178 return false; |
|
179 } |
|
180 else |
|
181 { |
|
182 for (int i = 0; i < len; i++) |
|
183 params(i) = vals(i); |
|
184 |
|
185 return true; |
|
186 } |
|
187 } |
|
188 |
|
189 bool |
|
190 octave_sparse_params::do_set_key (const std::string& key, const double& val) |
5164
|
191 { |
|
192 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
5893
|
193 { |
|
194 if (keys (i) == key) |
|
195 { |
|
196 params(i) = val; |
|
197 return true; |
|
198 } |
|
199 } |
|
200 |
5164
|
201 return false; |
|
202 } |
|
203 |
|
204 double |
5893
|
205 octave_sparse_params::do_get_key (const std::string& key) |
5164
|
206 { |
|
207 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
5893
|
208 { |
|
209 if (keys (i) == key) |
5164
|
210 return params(i); |
5893
|
211 } |
5164
|
212 |
|
213 return octave_NaN; |
|
214 } |
|
215 |
|
216 void |
5893
|
217 octave_sparse_params::do_print_info (std::ostream& os, |
|
218 const std::string& prefix) const |
5164
|
219 { |
|
220 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
|
221 os << prefix << keys(i) << ": " << params(i) << "\n"; |
|
222 } |
|
223 |
|
224 /* |
|
225 ;;; Local Variables: *** |
|
226 ;;; mode: C++ *** |
|
227 ;;; End: *** |
|
228 */ |