Mercurial > hg > octave-avbm
annotate liboctave/oct-spparms.cc @ 13889:aaefd6b28188
toeplitz.m: Update coding style
* toeplitz.m: Update coding style
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 18 Nov 2011 14:26:20 -0800 |
parents | 12df7854fa7c |
children | 7dd7cccf0757 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2004-2011 David Bateman |
4 Copyright (C) 1998-2004 Andy Adler | |
7016 | 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) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
46 ("unable to create octave_sparse_params object!"); |
5893 | 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 { |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 params(0) = 0; // spumoni |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 params(1) = 1; // ths_rel |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 params(2) = 1; // ths_abs |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 params(3) = 0; // exact_d |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 params(4) = 3; // supernd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
119 params(5) = 3; // rreduce |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 params(6) = 0.5; // wh_frac |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 params(7) = 1; // autommd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 params(8) = 1; // autoamd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 params(9) = 0.1; // piv_tol |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 params(10) = 0.5; // bandden |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 params(11) = 1; // umfpack |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 params(12) = 0.001; // sym_tol |
5893 | 127 } |
128 | |
129 void | |
130 octave_sparse_params::do_tight (void) | |
131 { | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
132 params(0) = 0; // spumoni |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 params(1) = 1; // ths_rel |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 params(2) = 0; // ths_abs |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 params(3) = 1; // exact_d |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 params(4) = 1; // supernd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 params(5) = 1; // rreduce |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 params(6) = 0.5; // wh_frac |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 params(7) = 1; // autommd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 params(8) = 1; // autoamd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 params(9) = 0.1; // piv_tol |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 params(10) = 0.5; // bandden |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 params(11) = 1; // umfpack |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 params(12) = 0.001; // sym_tol |
5164 | 145 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 |
5164 | 147 void |
5893 | 148 octave_sparse_params::init_keys (void) |
5164 | 149 { |
5893 | 150 keys(0) = "spumoni"; |
151 keys(1) = "ths_rel"; | |
152 keys(2) = "ths_abs"; | |
153 keys(3) = "exact_d"; | |
154 keys(4) = "supernd"; | |
155 keys(5) = "rreduce"; | |
156 keys(6) = "wh_frac"; | |
157 keys(7) = "autommd"; | |
158 keys(8) = "autoamd"; | |
159 keys(9) = "piv_tol"; | |
160 keys(10) = "bandden"; | |
161 keys(11) = "umfpack"; | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 keys(12) = "sym_tol"; |
5164 | 163 } |
164 | |
6460 | 165 double |
166 octave_sparse_params::do_get_bandden (void) | |
167 { | |
168 return params(10); | |
169 } | |
170 | |
5164 | 171 bool |
5893 | 172 octave_sparse_params::do_set_vals (const NDArray& vals) |
173 { | |
174 octave_idx_type len = vals.length (); | |
175 | |
176 if (len > OCTAVE_SPARSE_CONTROLS_SIZE) | |
177 { | |
178 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
179 ("octave_sparse_params::do_set_vals: too many values"); |
5893 | 180 |
181 return false; | |
182 } | |
183 else | |
184 { | |
185 for (int i = 0; i < len; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 params(i) = vals(i); |
5893 | 187 |
188 return true; | |
189 } | |
190 } | |
191 | |
192 bool | |
193 octave_sparse_params::do_set_key (const std::string& key, const double& val) | |
5164 | 194 { |
195 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
5893 | 196 { |
197 if (keys (i) == key) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
198 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
199 params(i) = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 return true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
201 } |
5893 | 202 } |
203 | |
5164 | 204 return false; |
205 } | |
206 | |
207 double | |
5893 | 208 octave_sparse_params::do_get_key (const std::string& key) |
5164 | 209 { |
210 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
5893 | 211 { |
212 if (keys (i) == key) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
213 return params(i); |
5893 | 214 } |
5164 | 215 |
216 return octave_NaN; | |
217 } | |
218 | |
219 void | |
5893 | 220 octave_sparse_params::do_print_info (std::ostream& os, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
221 const std::string& prefix) const |
5164 | 222 { |
223 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
224 os << prefix << keys(i) << ": " << params(i) << "\n"; | |
225 } |