GNU Octave  8.1.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-2023 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 "Array.h"
33 #include "lo-error.h"
34 #include "lo-ieee.h"
35 #include "oct-spparms.h"
36 #include "singleton-cleanup.h"
37 
39 
41 
43 {
44  bool retval = true;
45 
46  if (! s_instance)
47  {
48  s_instance = new sparse_params ();
50  }
51 
52  return retval;
53 }
54 
56 {
57  if (instance_ok ())
59 }
60 
62 {
63  if (instance_ok ())
64  s_instance->do_tight ();
65 }
66 
68 {
69  return instance_ok () ? s_instance->do_get_keys () : string_vector ();
70 }
71 
73 {
74  return instance_ok () ? s_instance->do_get_vals () : ColumnVector ();
75 }
76 
78 {
79  return instance_ok () ? s_instance->do_set_vals (vals) : false;
80 }
81 
82 bool sparse_params::set_key (const std::string& key, const double& val)
83 {
84  return instance_ok () ? s_instance->do_set_key (key, val) : false;
85 }
86 
87 double sparse_params::get_key (const std::string& key)
88 {
89  return (instance_ok ()
91 }
92 
94 {
95  return instance_ok () ? s_instance->do_get_bandden () : 0.0;
96 }
97 
98 void sparse_params::print_info (std::ostream& os, const std::string& prefix)
99 {
100  if (instance_ok ())
101  s_instance->do_print_info (os, prefix);
102 }
103 
105 {
106  m_params(0) = 0; // spumoni
107  m_params(1) = 1; // ths_rel
108  m_params(2) = 1; // ths_abs
109  m_params(3) = 0; // exact_d
110  m_params(4) = 3; // supernd
111  m_params(5) = 3; // rreduce
112  m_params(6) = 0.5; // wh_frac
113  m_params(7) = 1; // autommd
114  m_params(8) = 1; // autoamd
115  m_params(9) = 0.1; // piv_tol
116  m_params(10) = 0.5; // bandden
117  m_params(11) = 1; // umfpack
118  m_params(12) = 0.001; // sym_tol
119 }
120 
122 {
123  m_params(0) = 0; // spumoni
124  m_params(1) = 1; // ths_rel
125  m_params(2) = 0; // ths_abs
126  m_params(3) = 1; // exact_d
127  m_params(4) = 1; // supernd
128  m_params(5) = 1; // rreduce
129  m_params(6) = 0.5; // wh_frac
130  m_params(7) = 1; // autommd
131  m_params(8) = 1; // autoamd
132  m_params(9) = 0.1; // piv_tol
133  m_params(10) = 0.5; // bandden
134  m_params(11) = 1; // umfpack
135  m_params(12) = 0.001; // sym_tol
136 }
137 
139 {
140  m_keys(0) = "spumoni";
141  m_keys(1) = "ths_rel";
142  m_keys(2) = "ths_abs";
143  m_keys(3) = "exact_d";
144  m_keys(4) = "supernd";
145  m_keys(5) = "rreduce";
146  m_keys(6) = "wh_frac";
147  m_keys(7) = "autommd";
148  m_keys(8) = "autoamd";
149  m_keys(9) = "piv_tol";
150  m_keys(10) = "bandden";
151  m_keys(11) = "umfpack";
152  m_keys(12) = "sym_tol";
153 }
154 
156 {
157  return m_params(10);
158 }
159 
161 {
162  octave_idx_type len = vals.numel ();
163 
165  (*current_liboctave_error_handler)
166  ("sparse_params::do_set_vals: too many values");
167 
168  for (int i = 0; i < len; i++)
169  m_params(i) = vals(i);
170 
171  return true;
172 }
173 
174 bool sparse_params::do_set_key (const std::string& key, const double& val)
175 {
176  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
177  {
178  if (m_keys (i) == key)
179  {
180  m_params(i) = val;
181  return true;
182  }
183  }
184 
185  return false;
186 }
187 
188 double sparse_params::do_get_key (const std::string& key)
189 {
190  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
191  {
192  if (m_keys (i) == key)
193  return m_params(i);
194  }
195 
196  return numeric_limits<double>::NaN ();
197 }
198 
199 void sparse_params::do_print_info (std::ostream& os,
200  const std::string& prefix) const
201 {
202  for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
203  os << prefix << m_keys(i) << ": " << m_params(i) << "\n";
204 }
205 
OCTAVE_END_NAMESPACE(octave)
#define NaN
Definition: Faddeeva.cc:261
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:414
static void add(fptr f)
ColumnVector m_params
Definition: oct-spparms.h:84
static double get_key(const std::string &key)
Definition: oct-spparms.cc:87
static void defaults(void)
Definition: oct-spparms.cc:55
ColumnVector do_get_vals(void) const
Definition: oct-spparms.h:102
static void tight(void)
Definition: oct-spparms.cc:61
static sparse_params * s_instance
Definition: oct-spparms.h:88
static double get_bandden(void)
Definition: oct-spparms.cc:93
static void print_info(std::ostream &os, const std::string &prefix)
Definition: oct-spparms.cc:98
static string_vector get_keys(void)
Definition: oct-spparms.cc:67
double do_get_key(const std::string &key)
Definition: oct-spparms.cc:188
string_vector m_keys
Definition: oct-spparms.h:86
void do_tight(void)
Definition: oct-spparms.cc:121
sparse_params(void)
Definition: oct-spparms.h:46
void do_print_info(std::ostream &os, const std::string &prefix) const
Definition: oct-spparms.cc:199
static bool set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:82
double do_get_bandden(void)
Definition: oct-spparms.cc:155
static void cleanup_instance(void)
Definition: oct-spparms.h:90
static bool set_vals(const Array< double > &vals)
Definition: oct-spparms.cc:77
void init_keys(void)
Definition: oct-spparms.cc:138
bool do_set_vals(const Array< double > &vals)
Definition: oct-spparms.cc:160
string_vector do_get_keys(void) const
Definition: oct-spparms.h:100
static bool instance_ok(void)
Definition: oct-spparms.cc:42
static ColumnVector get_vals(void)
Definition: oct-spparms.cc:72
bool do_set_key(const std::string &key, const double &val)
Definition: oct-spparms.cc:174
void do_defaults(void)
Definition: oct-spparms.cc:104
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
class OCTAVE_API ColumnVector
Definition: mx-fwd.h:45
#define OCTAVE_SPARSE_CONTROLS_SIZE
Definition: oct-spparms.h:38
F77_RET_T len
Definition: xerbla.cc:61