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 |
|
97 void |
|
98 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix) |
|
99 { |
|
100 if (instance_ok ()) |
|
101 instance->do_print_info (os, prefix); |
5164
|
102 } |
|
103 |
|
104 void |
5893
|
105 octave_sparse_params::do_defaults (void) |
5164
|
106 { |
5893
|
107 params(0) = 0; // spumoni |
|
108 params(1) = 1; // ths_rel |
|
109 params(2) = 1; // ths_abs |
|
110 params(3) = 0; // exact_d |
|
111 params(4) = 3; // supernd |
|
112 params(5) = 3; // rreduce |
|
113 params(6) = 0.5; // wh_frac |
|
114 params(7) = 1; // autommd |
|
115 params(8) = 1; // autoamd |
|
116 params(9) = 0.1; // piv_tol |
|
117 params(10) = 0.5; // bandden |
|
118 params(11) = 1; // umfpack |
|
119 } |
|
120 |
|
121 void |
|
122 octave_sparse_params::do_tight (void) |
|
123 { |
|
124 params(0) = 0; // spumoni |
|
125 params(1) = 1; // ths_rel |
|
126 params(2) = 0; // ths_abs |
|
127 params(3) = 1; // exact_d |
|
128 params(4) = 1; // supernd |
|
129 params(5) = 1; // rreduce |
|
130 params(6) = 0.5; // wh_frac |
|
131 params(7) = 1; // autommd |
|
132 params(8) = 1; // autoamd |
|
133 params(9) = 0.1; // piv_tol |
|
134 params(10) = 0.5; // bandden |
|
135 params(11) = 1; // umfpack |
5164
|
136 } |
|
137 |
|
138 void |
5893
|
139 octave_sparse_params::init_keys (void) |
5164
|
140 { |
5893
|
141 keys(0) = "spumoni"; |
|
142 keys(1) = "ths_rel"; |
|
143 keys(2) = "ths_abs"; |
|
144 keys(3) = "exact_d"; |
|
145 keys(4) = "supernd"; |
|
146 keys(5) = "rreduce"; |
|
147 keys(6) = "wh_frac"; |
|
148 keys(7) = "autommd"; |
|
149 keys(8) = "autoamd"; |
|
150 keys(9) = "piv_tol"; |
|
151 keys(10) = "bandden"; |
|
152 keys(11) = "umfpack"; |
5164
|
153 } |
|
154 |
|
155 bool |
5893
|
156 octave_sparse_params::do_set_vals (const NDArray& vals) |
|
157 { |
|
158 octave_idx_type len = vals.length (); |
|
159 |
|
160 if (len > OCTAVE_SPARSE_CONTROLS_SIZE) |
|
161 { |
|
162 (*current_liboctave_error_handler) |
|
163 ("octave_sparse_params::do_set_vals: too many values"); |
|
164 |
|
165 return false; |
|
166 } |
|
167 else |
|
168 { |
|
169 for (int i = 0; i < len; i++) |
|
170 params(i) = vals(i); |
|
171 |
|
172 return true; |
|
173 } |
|
174 } |
|
175 |
|
176 bool |
|
177 octave_sparse_params::do_set_key (const std::string& key, const double& val) |
5164
|
178 { |
|
179 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
5893
|
180 { |
|
181 if (keys (i) == key) |
|
182 { |
|
183 params(i) = val; |
|
184 return true; |
|
185 } |
|
186 } |
|
187 |
5164
|
188 return false; |
|
189 } |
|
190 |
|
191 double |
5893
|
192 octave_sparse_params::do_get_key (const std::string& key) |
5164
|
193 { |
|
194 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
5893
|
195 { |
|
196 if (keys (i) == key) |
5164
|
197 return params(i); |
5893
|
198 } |
5164
|
199 |
|
200 return octave_NaN; |
|
201 } |
|
202 |
|
203 void |
5893
|
204 octave_sparse_params::do_print_info (std::ostream& os, |
|
205 const std::string& prefix) const |
5164
|
206 { |
|
207 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
|
208 os << prefix << keys(i) << ": " << params(i) << "\n"; |
|
209 } |
|
210 |
|
211 /* |
|
212 ;;; Local Variables: *** |
|
213 ;;; mode: C++ *** |
|
214 ;;; End: *** |
|
215 */ |