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