GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-spparms.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <ostream>
29 
30 #include "dNDArray.h"
31 #include "lo-error.h"
32 #include "lo-ieee.h"
33 #include "oct-spparms.h"
34 #include "singleton-cleanup.h"
35 
37 
38 bool
40 {
41  bool retval = true;
42 
43  if (! instance)
44  {
46 
47  if (instance)
49  }
50 
51  if (! instance)
52  (*current_liboctave_error_handler)
53  ("unable to create octave_sparse_params object!");
54 
55  return retval;
56 }
57 
58 void
60 {
61  if (instance_ok ())
63 }
64 
65 void
67 {
68  if (instance_ok ())
69  instance->do_tight ();
70 }
71 
74 {
75  return instance_ok () ? instance->do_get_keys () : string_vector ();
76 }
77 
80 {
81  return instance_ok () ? instance->do_get_vals () : ColumnVector ();
82 }
83 
84 bool
86 {
87  return instance_ok () ? instance->do_set_vals (vals) : false;
88 }
89 
90 bool
91 octave_sparse_params::set_key (const std::string& key, const double& val)
92 {
93  return instance_ok () ? instance->do_set_key (key, val) : false;
94 }
95 
96 double
98 {
99  return instance_ok () ? instance->do_get_key (key)
101 }
102 
103 double
105 {
106  return instance_ok () ? instance->do_get_bandden () : 0.0;
107 }
108 
109 void
110 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix)
111 {
112  if (instance_ok ())
113  instance->do_print_info (os, prefix);
114 }
115 
116 void
118 {
119  params(0) = 0; // spumoni
120  params(1) = 1; // ths_rel
121  params(2) = 1; // ths_abs
122  params(3) = 0; // exact_d
123  params(4) = 3; // supernd
124  params(5) = 3; // rreduce
125  params(6) = 0.5; // wh_frac
126  params(7) = 1; // autommd
127  params(8) = 1; // autoamd
128  params(9) = 0.1; // piv_tol
129  params(10) = 0.5; // bandden
130  params(11) = 1; // umfpack
131  params(12) = 0.001; // sym_tol
132 }
133 
134 void
136 {
137  params(0) = 0; // spumoni
138  params(1) = 1; // ths_rel
139  params(2) = 0; // ths_abs
140  params(3) = 1; // exact_d
141  params(4) = 1; // supernd
142  params(5) = 1; // rreduce
143  params(6) = 0.5; // wh_frac
144  params(7) = 1; // autommd
145  params(8) = 1; // autoamd
146  params(9) = 0.1; // piv_tol
147  params(10) = 0.5; // bandden
148  params(11) = 1; // umfpack
149  params(12) = 0.001; // sym_tol
150 }
151 
152 void
154 {
155  keys(0) = "spumoni";
156  keys(1) = "ths_rel";
157  keys(2) = "ths_abs";
158  keys(3) = "exact_d";
159  keys(4) = "supernd";
160  keys(5) = "rreduce";
161  keys(6) = "wh_frac";
162  keys(7) = "autommd";
163  keys(8) = "autoamd";
164  keys(9) = "piv_tol";
165  keys(10) = "bandden";
166  keys(11) = "umfpack";
167  keys(12) = "sym_tol";
168 }
169 
170 double
172 {
173  return params(10);
174 }
175 
176 bool
178 {
179  octave_idx_type len = vals.numel ();
180 
181  if (len > OCTAVE_SPARSE_CONTROLS_SIZE)
182  (*current_liboctave_error_handler)
183  ("octave_sparse_params::do_set_vals: too many values");
184 
185  for (int i = 0; i < len; i++)
186  params(i) = vals(i);
187 
188  return true;
189 }
190 
191 bool
193 {
194  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
195  {
196  if (keys (i) == key)
197  {
198  params(i) = val;
199  return true;
200  }
201  }
202 
203  return false;
204 }
205 
206 double
208 {
209  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
210  {
211  if (keys (i) == key)
212  return params(i);
213  }
214 
216 }
217 
218 void
220  const std::string& prefix) const
221 {
222  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
223  os << prefix << keys(i) << ": " << params(i) << "\n";
224 }
static string_vector get_keys(void)
Definition: oct-spparms.cc:73
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
#define OCTAVE_SPARSE_CONTROLS_SIZE
Definition: oct-spparms.h:37
double do_get_key(const std::string &key)
Definition: oct-spparms.cc:207
static octave_sparse_params * instance
Definition: oct-spparms.h:97
static void print_info(std::ostream &os, const std::string &prefix)
Definition: oct-spparms.cc:110
static double get_key(const std::string &key)
Definition: oct-spparms.cc:97
ColumnVector do_get_vals(void) const
Definition: oct-spparms.h:107
static ColumnVector get_vals(void)
Definition: oct-spparms.cc:79
static void add(fptr f)
string_vector do_get_keys(void) const
Definition: oct-spparms.h:105
void do_defaults(void)
Definition: oct-spparms.cc:117
octave_value retval
Definition: data.cc:6246
ColumnVector params
Definition: oct-spparms.h:93
static void defaults(void)
Definition: oct-spparms.cc:59
string_vector keys
Definition: oct-spparms.h:95
double do_get_bandden(void)
Definition: oct-spparms.cc:171
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol NaN(Not a Number). NaN is the result of operations which do not produce a well defined 0 result. Common operations which produce a NaN are arithmetic with infinity ex($\infty - \infty$)
bool do_set_vals(const NDArray &vals)
Definition: oct-spparms.cc:177
for i
Definition: data.cc:5264
static bool set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:91
void do_print_info(std::ostream &os, const std::string &prefix) const
Definition: oct-spparms.cc:219
bool do_set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:192
static bool set_vals(const NDArray &vals)
Definition: oct-spparms.cc:85
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
static void cleanup_instance(void)
Definition: oct-spparms.h:99
static void tight(void)
Definition: oct-spparms.cc:66
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
static bool instance_ok(void)
Definition: oct-spparms.cc:39
octave::stream os
Definition: file-io.cc:627
static double get_bandden(void)
Definition: oct-spparms.cc:104