Mercurial > hg > octave-nkf
annotate liboctave/numeric/oct-spparms.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | a9574e3c6e9e |
children |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 2004-2015 David Bateman |
11523 | 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" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
32 #include "singleton-cleanup.h" |
5164 | 33 |
5893 | 34 octave_sparse_params *octave_sparse_params::instance = 0; |
35 | |
36 bool | |
37 octave_sparse_params::instance_ok (void) | |
38 { | |
39 bool retval = true; | |
40 | |
41 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
42 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
43 instance = new octave_sparse_params (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
44 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
45 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
46 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
47 } |
5893 | 48 |
49 if (! instance) | |
50 { | |
51 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
52 ("unable to create octave_sparse_params object!"); |
5893 | 53 |
54 retval = false; | |
55 } | |
56 | |
57 return retval; | |
58 } | |
59 | |
60 void | |
61 octave_sparse_params::defaults (void) | |
62 { | |
63 if (instance_ok ()) | |
64 instance->do_defaults (); | |
65 } | |
5164 | 66 |
67 void | |
5893 | 68 octave_sparse_params::tight (void) |
69 { | |
70 if (instance_ok ()) | |
71 instance->do_tight (); | |
72 } | |
73 | |
74 string_vector | |
75 octave_sparse_params::get_keys (void) | |
76 { | |
77 return instance_ok () ? instance->do_get_keys () : string_vector (); | |
78 } | |
79 | |
80 ColumnVector | |
81 octave_sparse_params::get_vals (void) | |
82 { | |
83 return instance_ok () ? instance->do_get_vals () : ColumnVector (); | |
84 } | |
85 | |
86 bool | |
87 octave_sparse_params::set_vals (const NDArray& vals) | |
5164 | 88 { |
5893 | 89 return instance_ok () ? instance->do_set_vals (vals) : false; |
90 } | |
91 | |
92 bool | |
93 octave_sparse_params::set_key (const std::string& key, const double& val) | |
94 { | |
95 return instance_ok () ? instance->do_set_key (key, val) : false; | |
96 } | |
97 | |
98 double | |
99 octave_sparse_params::get_key (const std::string& key) | |
100 { | |
101 return instance_ok () ? instance->do_get_key (key) : octave_NaN; | |
102 } | |
103 | |
6460 | 104 double |
105 octave_sparse_params::get_bandden (void) | |
106 { | |
107 return instance_ok () ? instance->do_get_bandden () : 0.0; | |
108 } | |
109 | |
5893 | 110 void |
111 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix) | |
112 { | |
113 if (instance_ok ()) | |
114 instance->do_print_info (os, prefix); | |
5164 | 115 } |
116 | |
117 void | |
5893 | 118 octave_sparse_params::do_defaults (void) |
5164 | 119 { |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 params(0) = 0; // spumoni |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 params(1) = 1; // ths_rel |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 params(2) = 1; // ths_abs |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 params(3) = 0; // exact_d |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 params(4) = 3; // supernd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 params(5) = 3; // rreduce |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 params(6) = 0.5; // wh_frac |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 params(7) = 1; // autommd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 params(8) = 1; // autoamd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 params(9) = 0.1; // piv_tol |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 params(10) = 0.5; // bandden |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 params(11) = 1; // umfpack |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
132 params(12) = 0.001; // sym_tol |
5893 | 133 } |
134 | |
135 void | |
136 octave_sparse_params::do_tight (void) | |
137 { | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 params(0) = 0; // spumoni |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 params(1) = 1; // ths_rel |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 params(2) = 0; // ths_abs |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 params(3) = 1; // exact_d |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 params(4) = 1; // supernd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 params(5) = 1; // rreduce |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 params(6) = 0.5; // wh_frac |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
145 params(7) = 1; // autommd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 params(8) = 1; // autoamd |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
147 params(9) = 0.1; // piv_tol |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 params(10) = 0.5; // bandden |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 params(11) = 1; // umfpack |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 params(12) = 0.001; // sym_tol |
5164 | 151 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
152 |
5164 | 153 void |
5893 | 154 octave_sparse_params::init_keys (void) |
5164 | 155 { |
5893 | 156 keys(0) = "spumoni"; |
157 keys(1) = "ths_rel"; | |
158 keys(2) = "ths_abs"; | |
159 keys(3) = "exact_d"; | |
160 keys(4) = "supernd"; | |
161 keys(5) = "rreduce"; | |
162 keys(6) = "wh_frac"; | |
163 keys(7) = "autommd"; | |
164 keys(8) = "autoamd"; | |
165 keys(9) = "piv_tol"; | |
166 keys(10) = "bandden"; | |
167 keys(11) = "umfpack"; | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
168 keys(12) = "sym_tol"; |
5164 | 169 } |
170 | |
6460 | 171 double |
172 octave_sparse_params::do_get_bandden (void) | |
173 { | |
174 return params(10); | |
175 } | |
176 | |
5164 | 177 bool |
5893 | 178 octave_sparse_params::do_set_vals (const NDArray& vals) |
179 { | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
180 octave_idx_type len = vals.numel (); |
5893 | 181 |
182 if (len > OCTAVE_SPARSE_CONTROLS_SIZE) | |
183 { | |
184 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
185 ("octave_sparse_params::do_set_vals: too many values"); |
5893 | 186 |
187 return false; | |
188 } | |
189 else | |
190 { | |
191 for (int i = 0; i < len; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
192 params(i) = vals(i); |
5893 | 193 |
194 return true; | |
195 } | |
196 } | |
197 | |
198 bool | |
199 octave_sparse_params::do_set_key (const std::string& key, const double& val) | |
5164 | 200 { |
201 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
5893 | 202 { |
203 if (keys (i) == key) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
204 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
205 params(i) = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
206 return true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
207 } |
5893 | 208 } |
209 | |
5164 | 210 return false; |
211 } | |
212 | |
213 double | |
5893 | 214 octave_sparse_params::do_get_key (const std::string& key) |
5164 | 215 { |
216 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
5893 | 217 { |
218 if (keys (i) == key) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
219 return params(i); |
5893 | 220 } |
5164 | 221 |
222 return octave_NaN; | |
223 } | |
224 | |
225 void | |
5893 | 226 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
|
227 const std::string& prefix) const |
5164 | 228 { |
229 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++) | |
230 os << prefix << keys(i) << ": " << params(i) << "\n"; | |
231 } |