GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-spparms.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1998-2025 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
40sparse_params *sparse_params::s_instance = nullptr;
41
42bool
44{
45 bool retval = true;
46
47 if (! s_instance)
48 {
49 s_instance = new sparse_params ();
50 singleton_cleanup_list::add (cleanup_instance);
51 }
52
53 return retval;
54}
55
56void
58{
59 if (instance_ok ())
60 s_instance->do_defaults ();
61}
62
63void
65{
66 if (instance_ok ())
67 s_instance->do_tight ();
68}
69
72{
73 return instance_ok () ? s_instance->do_get_keys () : string_vector ();
74}
75
78{
79 return instance_ok () ? s_instance->do_get_vals () : ColumnVector ();
80}
81
82bool
84{
85 return instance_ok () ? s_instance->do_set_vals (vals) : false;
86}
87
88bool
89sparse_params::set_key (const std::string& key, const double& val)
90{
91 return instance_ok () ? s_instance->do_set_key (key, val) : false;
92}
93
94double
95sparse_params::get_key (const std::string& key)
96{
97 return (instance_ok ()
98 ? s_instance->do_get_key (key) : numeric_limits<double>::NaN ());
99}
100
101double
103{
104 return instance_ok () ? s_instance->do_get_bandden () : 0.0;
105}
106
107void
108sparse_params::print_info (std::ostream& os, const std::string& prefix)
109{
110 if (instance_ok ())
111 s_instance->do_print_info (os, prefix);
112}
113
114void
115sparse_params::do_defaults ()
116{
117 m_params(0) = 0; // spumoni
118 m_params(1) = 1; // ths_rel
119 m_params(2) = 1; // ths_abs
120 m_params(3) = 0; // exact_d
121 m_params(4) = 3; // supernd
122 m_params(5) = 3; // rreduce
123 m_params(6) = 0.5; // wh_frac
124 m_params(7) = 1; // autommd
125 m_params(8) = 1; // autoamd
126 m_params(9) = 0.1; // piv_tol
127 m_params(10) = 0.5; // bandden
128 m_params(11) = 1; // umfpack
129 m_params(12) = 0.001; // sym_tol
130}
131
132void
133sparse_params::do_tight ()
134{
135 m_params(0) = 0; // spumoni
136 m_params(1) = 1; // ths_rel
137 m_params(2) = 0; // ths_abs
138 m_params(3) = 1; // exact_d
139 m_params(4) = 1; // supernd
140 m_params(5) = 1; // rreduce
141 m_params(6) = 0.5; // wh_frac
142 m_params(7) = 1; // autommd
143 m_params(8) = 1; // autoamd
144 m_params(9) = 0.1; // piv_tol
145 m_params(10) = 0.5; // bandden
146 m_params(11) = 1; // umfpack
147 m_params(12) = 0.001; // sym_tol
148}
149
150void
151sparse_params::init_keys ()
152{
153 m_keys(0) = "spumoni";
154 m_keys(1) = "ths_rel";
155 m_keys(2) = "ths_abs";
156 m_keys(3) = "exact_d";
157 m_keys(4) = "supernd";
158 m_keys(5) = "rreduce";
159 m_keys(6) = "wh_frac";
160 m_keys(7) = "autommd";
161 m_keys(8) = "autoamd";
162 m_keys(9) = "piv_tol";
163 m_keys(10) = "bandden";
164 m_keys(11) = "umfpack";
165 m_keys(12) = "sym_tol";
166}
167
168double
169sparse_params::do_get_bandden ()
170{
171 return m_params(10);
172}
173
174bool
175sparse_params::do_set_vals (const Array<double>& vals)
176{
177 octave_idx_type len = vals.numel ();
178
180 (*current_liboctave_error_handler)
181 ("sparse_params::do_set_vals: too many values");
182
183 for (int i = 0; i < len; i++)
184 m_params(i) = vals(i);
185
186 return true;
187}
188
189bool
190sparse_params::do_set_key (const std::string& key, const double& val)
191{
192 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
193 {
194 if (m_keys (i) == key)
195 {
196 m_params(i) = val;
197 return true;
198 }
199 }
200
201 return false;
202}
203
204double
205sparse_params::do_get_key (const std::string& key)
206{
207 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
208 {
209 if (m_keys (i) == key)
210 return m_params(i);
211 }
212
213 return numeric_limits<double>::NaN ();
214}
215
216void
217sparse_params::do_print_info (std::ostream& os,
218 const std::string& prefix) const
219{
220 for (int i = 0; i < OCTAVE_SPARSE_CONTROLS_SIZE; i++)
221 os << prefix << m_keys(i) << ": " << m_params(i) << "\n";
222}
223
224OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
static void add(fptr f)
static double get_key(const std::string &key)
static void print_info(std::ostream &os, const std::string &prefix)
static bool set_key(const std::string &key, const double &val)
static bool instance_ok()
static bool set_vals(const Array< double > &vals)
static void defaults()
static string_vector get_keys()
static ColumnVector get_vals()
static double get_bandden()
static void tight()
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_SPARSE_CONTROLS_SIZE
Definition oct-spparms.h:38
F77_RET_T len
Definition xerbla.cc:61