GNU Octave  6.2.0
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) 1998-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <ostream>
31 
32 #include "dNDArray.h"
33 #include "lo-error.h"
34 #include "lo-ieee.h"
35 #include "oct-spparms.h"
36 #include "singleton-cleanup.h"
37 
39 
40 bool
42 {
43  bool retval = true;
44 
45  if (! instance)
46  {
49  }
50 
51  return retval;
52 }
53 
54 void
56 {
57  if (instance_ok ())
59 }
60 
61 void
63 {
64  if (instance_ok ())
65  instance->do_tight ();
66 }
67 
70 {
71  return instance_ok () ? instance->do_get_keys () : string_vector ();
72 }
73 
76 {
77  return instance_ok () ? instance->do_get_vals () : ColumnVector ();
78 }
79 
80 bool
82 {
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)
97 }
98 
99 double
101 {
102  return instance_ok () ? instance->do_get_bandden () : 0.0;
103 }
104 
105 void
106 octave_sparse_params::print_info (std::ostream& os, const std::string& prefix)
107 {
108  if (instance_ok ())
109  instance->do_print_info (os, prefix);
110 }
111 
112 void
114 {
115  params(0) = 0; // spumoni
116  params(1) = 1; // ths_rel
117  params(2) = 1; // ths_abs
118  params(3) = 0; // exact_d
119  params(4) = 3; // supernd
120  params(5) = 3; // rreduce
121  params(6) = 0.5; // wh_frac
122  params(7) = 1; // autommd
123  params(8) = 1; // autoamd
124  params(9) = 0.1; // piv_tol
125  params(10) = 0.5; // bandden
126  params(11) = 1; // umfpack
127  params(12) = 0.001; // sym_tol
128 }
129 
130 void
132 {
133  params(0) = 0; // spumoni
134  params(1) = 1; // ths_rel
135  params(2) = 0; // ths_abs
136  params(3) = 1; // exact_d
137  params(4) = 1; // supernd
138  params(5) = 1; // rreduce
139  params(6) = 0.5; // wh_frac
140  params(7) = 1; // autommd
141  params(8) = 1; // autoamd
142  params(9) = 0.1; // piv_tol
143  params(10) = 0.5; // bandden
144  params(11) = 1; // umfpack
145  params(12) = 0.001; // sym_tol
146 }
147 
148 void
150 {
151  keys(0) = "spumoni";
152  keys(1) = "ths_rel";
153  keys(2) = "ths_abs";
154  keys(3) = "exact_d";
155  keys(4) = "supernd";
156  keys(5) = "rreduce";
157  keys(6) = "wh_frac";
158  keys(7) = "autommd";
159  keys(8) = "autoamd";
160  keys(9) = "piv_tol";
161  keys(10) = "bandden";
162  keys(11) = "umfpack";
163  keys(12) = "sym_tol";
164 }
165 
166 double
168 {
169  return params(10);
170 }
171 
172 bool
174 {
175  octave_idx_type len = vals.numel ();
176 
178  (*current_liboctave_error_handler)
179  ("octave_sparse_params::do_set_vals: too many values");
180 
181  for (int i = 0; i < len; i++)
182  params(i) = vals(i);
183 
184  return true;
185 }
186 
187 bool
188 octave_sparse_params::do_set_key (const std::string& key, const double& val)
189 {
190  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
191  {
192  if (keys (i) == key)
193  {
194  params(i) = val;
195  return true;
196  }
197  }
198 
199  return false;
200 }
201 
202 double
203 octave_sparse_params::do_get_key (const std::string& key)
204 {
205  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
206  {
207  if (keys (i) == key)
208  return params(i);
209  }
210 
212 }
213 
214 void
216  const std::string& prefix) const
217 {
218  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
219  os << prefix << keys(i) << ": " << params(i) << "\n";
220 }
#define NaN
Definition: Faddeeva.cc:248
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:377
static string_vector get_keys(void)
Definition: oct-spparms.cc:69
static void print_info(std::ostream &os, const std::string &prefix)
Definition: oct-spparms.cc:106
static ColumnVector get_vals(void)
Definition: oct-spparms.cc:75
static bool set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:87
void do_defaults(void)
Definition: oct-spparms.cc:113
static double get_bandden(void)
Definition: oct-spparms.cc:100
static double get_key(const std::string &key)
Definition: oct-spparms.cc:93
bool do_set_vals(const NDArray &vals)
Definition: oct-spparms.cc:173
string_vector do_get_keys(void) const
Definition: oct-spparms.h:107
static bool instance_ok(void)
Definition: oct-spparms.cc:41
double do_get_key(const std::string &key)
Definition: oct-spparms.cc:203
bool do_set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:188
static octave_sparse_params * instance
Definition: oct-spparms.h:99
static void cleanup_instance(void)
Definition: oct-spparms.h:101
string_vector keys
Definition: oct-spparms.h:97
static bool set_vals(const NDArray &vals)
Definition: oct-spparms.cc:81
double do_get_bandden(void)
Definition: oct-spparms.cc:167
ColumnVector do_get_vals(void) const
Definition: oct-spparms.h:109
void do_print_info(std::ostream &os, const std::string &prefix) const
Definition: oct-spparms.cc:215
ColumnVector params
Definition: oct-spparms.h:95
static void tight(void)
Definition: oct-spparms.cc:62
static void defaults(void)
Definition: oct-spparms.cc:55
static void add(fptr f)
#define OCTAVE_SPARSE_CONTROLS_SIZE
Definition: oct-spparms.h:39
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
F77_RET_T len
Definition: xerbla.cc:61