Mercurial > hg > octave-nkf
comparison liboctave/oct-spparms.cc @ 5893:d73ffe42f2c8
[project @ 2006-07-16 07:48:19 by jwe]
author | jwe |
---|---|
date | Sun, 16 Jul 2006 07:49:03 +0000 |
parents | 4c8a2e4e0717 |
children | fa6312d93730 |
comparison
equal
deleted
inserted
replaced
5892:13aa80fc7839 | 5893:d73ffe42f2c8 |
---|---|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 Boston, MA 02110-1301, USA. | 19 Boston, MA 02110-1301, USA. |
20 | 20 |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #ifdef HAVE_CONFIG_H |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "lo-error.h" | |
24 #include "lo-ieee.h" | 28 #include "lo-ieee.h" |
25 | 29 |
26 #include "oct-spparms.h" | 30 #include "oct-spparms.h" |
27 | 31 |
28 SparseParams Voctave_sparse_controls; | 32 octave_sparse_params *octave_sparse_params::instance = 0; |
29 | 33 |
30 void | 34 bool |
31 SparseParams::defaults (void) | 35 octave_sparse_params::instance_ok (void) |
32 { | 36 { |
33 Voctave_sparse_controls (0) = 0; // spumoni | 37 bool retval = true; |
34 Voctave_sparse_controls (1) = 1; // ths_rel | 38 |
35 Voctave_sparse_controls (2) = 1; // ths_abs | 39 if (! instance) |
36 Voctave_sparse_controls (3) = 0; // exact_d | 40 instance = new octave_sparse_params (); |
37 Voctave_sparse_controls (4) = 3; // supernd | 41 |
38 Voctave_sparse_controls (5) = 3; // rreduce | 42 if (! instance) |
39 Voctave_sparse_controls (6) = 0.5; // wh_frac | 43 { |
40 Voctave_sparse_controls (7) = 1; // autommd | 44 (*current_liboctave_error_handler) |
41 Voctave_sparse_controls (8) = 1; // autoamd | 45 ("unable to create octave_sparse_params object!"); |
42 Voctave_sparse_controls (9) = 0.1; // piv_tol | 46 |
43 Voctave_sparse_controls (10) = 0.5; // bandden | 47 retval = false; |
44 Voctave_sparse_controls (11) = 1; // umfpack | 48 } |
45 } | 49 |
46 | 50 return retval; |
47 void | 51 } |
48 SparseParams::tight (void) | 52 |
49 { | 53 void |
50 Voctave_sparse_controls (0) = 0; // spumoni | 54 octave_sparse_params::defaults (void) |
51 Voctave_sparse_controls (1) = 1; // ths_rel | 55 { |
52 Voctave_sparse_controls (2) = 0; // ths_abs | 56 if (instance_ok ()) |
53 Voctave_sparse_controls (3) = 1; // exact_d | 57 instance->do_defaults (); |
54 Voctave_sparse_controls (4) = 1; // supernd | 58 } |
55 Voctave_sparse_controls (5) = 1; // rreduce | 59 |
56 Voctave_sparse_controls (6) = 0.5; // wh_frac | 60 void |
57 Voctave_sparse_controls (7) = 1; // autommd | 61 octave_sparse_params::tight (void) |
58 Voctave_sparse_controls (8) = 1; // autoamd | 62 { |
59 Voctave_sparse_controls (9) = 0.1; // piv_tol | 63 if (instance_ok ()) |
60 Voctave_sparse_controls (10) = 0.5; // bandden | 64 instance->do_tight (); |
61 Voctave_sparse_controls (11) = 1; // umfpack | 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) | |
81 { | |
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); | |
102 } | |
103 | |
104 void | |
105 octave_sparse_params::do_defaults (void) | |
106 { | |
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 | |
62 } | 136 } |
63 | 137 |
64 void | 138 void |
65 SparseParams::init_keys (void) | 139 octave_sparse_params::init_keys (void) |
66 { | 140 { |
67 keys (0) = "spumoni"; | 141 keys(0) = "spumoni"; |
68 keys (1) = "ths_rel"; | 142 keys(1) = "ths_rel"; |
69 keys (2) = "ths_abs"; | 143 keys(2) = "ths_abs"; |
70 keys (3) = "exact_d"; | 144 keys(3) = "exact_d"; |
71 keys (4) = "supernd"; | 145 keys(4) = "supernd"; |
72 keys (5) = "rreduce"; | 146 keys(5) = "rreduce"; |
73 keys (6) = "wh_frac"; | 147 keys(6) = "wh_frac"; |
74 keys (7) = "autommd"; | 148 keys(7) = "autommd"; |
75 keys (8) = "autoamd"; | 149 keys(8) = "autoamd"; |
76 keys (9) = "piv_tol"; | 150 keys(9) = "piv_tol"; |
77 keys (10) = "bandden"; | 151 keys(10) = "bandden"; |
78 keys (11) = "umfpack"; | 152 keys(11) = "umfpack"; |
79 } | 153 } |
80 | 154 |
81 SparseParams& | 155 bool |
82 SparseParams::operator = (const SparseParams& a) | 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) | |
83 { | 178 { |
84 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | 179 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
85 params (i) = a.params (i); | 180 { |
86 | 181 if (keys (i) == key) |
87 return *this; | 182 { |
88 } | 183 params(i) = val; |
89 | 184 return true; |
90 bool | 185 } |
91 SparseParams::set_key (const std::string key, const double& val) | 186 } |
187 | |
188 return false; | |
189 } | |
190 | |
191 double | |
192 octave_sparse_params::do_get_key (const std::string& key) | |
92 { | 193 { |
93 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | 194 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
94 if (keys (i) == key) | 195 { |
95 { | 196 if (keys (i) == key) |
96 params(i) = val; | |
97 return true; | |
98 } | |
99 return false; | |
100 } | |
101 | |
102 double | |
103 SparseParams::get_key (const std::string key) | |
104 { | |
105 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
106 if (keys (i) == key) | |
107 return params(i); | 197 return params(i); |
198 } | |
108 | 199 |
109 return octave_NaN; | 200 return octave_NaN; |
110 } | 201 } |
111 | 202 |
112 void | 203 void |
113 SparseParams::print_info (std::ostream& os, const std::string& prefix) const | 204 octave_sparse_params::do_print_info (std::ostream& os, |
205 const std::string& prefix) const | |
114 { | 206 { |
115 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | 207 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) |
116 os << prefix << keys(i) << ": " << params(i) << "\n"; | 208 os << prefix << keys(i) << ": " << params(i) << "\n"; |
117 } | 209 } |
118 | 210 |