GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-spparms.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2015 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
5 
6 This file is part of Octave.
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "lo-error.h"
29 #include "lo-ieee.h"
30 
31 #include "oct-spparms.h"
32 #include "singleton-cleanup.h"
33 
35 
36 bool
38 {
39  bool retval = true;
40 
41  if (! instance)
42  {
44 
45  if (instance)
47  }
48 
49  if (! instance)
50  {
51  (*current_liboctave_error_handler)
52  ("unable to create octave_sparse_params object!");
53 
54  retval = false;
55  }
56 
57  return retval;
58 }
59 
60 void
62 {
63  if (instance_ok ())
65 }
66 
67 void
69 {
70  if (instance_ok ())
71  instance->do_tight ();
72 }
73 
76 {
77  return instance_ok () ? instance->do_get_keys () : string_vector ();
78 }
79 
82 {
83  return instance_ok () ? instance->do_get_vals () : ColumnVector ();
84 }
85 
86 bool
88 {
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 
104 double
106 {
107  return instance_ok () ? instance->do_get_bandden () : 0.0;
108 }
109 
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);
115 }
116 
117 void
119 {
120  params(0) = 0; // spumoni
121  params(1) = 1; // ths_rel
122  params(2) = 1; // ths_abs
123  params(3) = 0; // exact_d
124  params(4) = 3; // supernd
125  params(5) = 3; // rreduce
126  params(6) = 0.5; // wh_frac
127  params(7) = 1; // autommd
128  params(8) = 1; // autoamd
129  params(9) = 0.1; // piv_tol
130  params(10) = 0.5; // bandden
131  params(11) = 1; // umfpack
132  params(12) = 0.001; // sym_tol
133 }
134 
135 void
137 {
138  params(0) = 0; // spumoni
139  params(1) = 1; // ths_rel
140  params(2) = 0; // ths_abs
141  params(3) = 1; // exact_d
142  params(4) = 1; // supernd
143  params(5) = 1; // rreduce
144  params(6) = 0.5; // wh_frac
145  params(7) = 1; // autommd
146  params(8) = 1; // autoamd
147  params(9) = 0.1; // piv_tol
148  params(10) = 0.5; // bandden
149  params(11) = 1; // umfpack
150  params(12) = 0.001; // sym_tol
151 }
152 
153 void
155 {
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";
168  keys(12) = "sym_tol";
169 }
170 
171 double
173 {
174  return params(10);
175 }
176 
177 bool
179 {
180  octave_idx_type len = vals.length ();
181 
182  if (len > OCTAVE_SPARSE_CONTROLS_SIZE)
183  {
184  (*current_liboctave_error_handler)
185  ("octave_sparse_params::do_set_vals: too many values");
186 
187  return false;
188  }
189  else
190  {
191  for (int i = 0; i < len; i++)
192  params(i) = vals(i);
193 
194  return true;
195  }
196 }
197 
198 bool
199 octave_sparse_params::do_set_key (const std::string& key, const double& val)
200 {
201  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
202  {
203  if (keys (i) == key)
204  {
205  params(i) = val;
206  return true;
207  }
208  }
209 
210  return false;
211 }
212 
213 double
214 octave_sparse_params::do_get_key (const std::string& key)
215 {
216  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
217  {
218  if (keys (i) == key)
219  return params(i);
220  }
221 
222  return octave_NaN;
223 }
224 
225 void
227  const std::string& prefix) const
228 {
229  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
230  os << prefix << keys(i) << ": " << params(i) << "\n";
231 }
void do_print_info(std::ostream &os, const std::string &prefix) const
Definition: oct-spparms.cc:226
static string_vector get_keys(void)
Definition: oct-spparms.cc:75
#define OCTAVE_SPARSE_CONTROLS_SIZE
Definition: oct-spparms.h:36
double do_get_key(const std::string &key)
Definition: oct-spparms.cc:214
static octave_sparse_params * instance
Definition: oct-spparms.h:96
static void print_info(std::ostream &os, const std::string &prefix)
Definition: oct-spparms.cc:111
ColumnVector do_get_vals(void) const
Definition: oct-spparms.h:106
static double get_key(const std::string &key)
Definition: oct-spparms.cc:99
static ColumnVector get_vals(void)
Definition: oct-spparms.cc:81
static void add(fptr f)
void do_defaults(void)
Definition: oct-spparms.cc:118
ColumnVector params
Definition: oct-spparms.h:92
static void defaults(void)
Definition: oct-spparms.cc:61
string_vector keys
Definition: oct-spparms.h:94
double do_get_bandden(void)
Definition: oct-spparms.cc:172
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
#define octave_NaN
Definition: lo-ieee.h:37
bool do_set_vals(const NDArray &vals)
Definition: oct-spparms.cc:178
static bool set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:93
bool do_set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:199
static bool set_vals(const NDArray &vals)
Definition: oct-spparms.cc:87
static void cleanup_instance(void)
Definition: oct-spparms.h:98
static void tight(void)
Definition: oct-spparms.cc:68
string_vector do_get_keys(void) const
Definition: oct-spparms.h:104
static bool instance_ok(void)
Definition: oct-spparms.cc:37
static double get_bandden(void)
Definition: oct-spparms.cc:105