GNU Octave  3.8.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
spparms.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2013 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 "defun.h"
29 #include "ov.h"
30 #include "pager.h"
31 #include "error.h"
32 #include "gripes.h"
33 
34 #include "oct-spparms.h"
35 
36 DEFUN (spparms, args, nargout,
37  "-*- texinfo -*-\n\
38 @deftypefn {Built-in Function} { } spparms ()\n\
39 @deftypefnx {Built-in Function} {@var{vals} =} spparms ()\n\
40 @deftypefnx {Built-in Function} {[@var{keys}, @var{vals}] =} spparms ()\n\
41 @deftypefnx {Built-in Function} {@var{val} =} spparms (@var{key})\n\
42 @deftypefnx {Built-in Function} { } spparms (@var{vals})\n\
43 @deftypefnx {Built-in Function} { } spparms (\"defaults\")\n\
44 @deftypefnx {Built-in Function} { } spparms (\"tight\")\n\
45 @deftypefnx {Built-in Function} { } spparms (@var{key}, @var{val})\n\
46 Query or set the parameters used by the sparse solvers and factorization\n\
47 functions. The first four calls above get information about the current\n\
48 settings, while the others change the current settings. The parameters are\n\
49 stored as pairs of keys and values, where the values are all floats and the\n\
50 keys are one of the following strings:\n\
51 \n\
52 @table @samp\n\
53 @item spumoni\n\
54 Printing level of debugging information of the solvers (default 0)\n\
55 \n\
56 @item ths_rel\n\
57 Included for compatibility. Not used. (default 1)\n\
58 \n\
59 @item ths_abs\n\
60 Included for compatibility. Not used. (default 1)\n\
61 \n\
62 @item exact_d\n\
63 Included for compatibility. Not used. (default 0)\n\
64 \n\
65 @item supernd\n\
66 Included for compatibility. Not used. (default 3)\n\
67 \n\
68 @item rreduce\n\
69 Included for compatibility. Not used. (default 3)\n\
70 \n\
71 @item wh_frac\n\
72 Included for compatibility. Not used. (default 0.5)\n\
73 \n\
74 @item autommd\n\
75 Flag whether the LU/QR and the '\\' and '/' operators will automatically\n\
76 use the sparsity preserving mmd functions (default 1)\n\
77 \n\
78 @item autoamd\n\
79 Flag whether the LU and the '\\' and '/' operators will automatically\n\
80 use the sparsity preserving amd functions (default 1)\n\
81 \n\
82 @item piv_tol\n\
83 The pivot tolerance of the @sc{umfpack} solvers (default 0.1)\n\
84 \n\
85 @item sym_tol\n\
86 The pivot tolerance of the @sc{umfpack} symmetric solvers (default 0.001)\n\
87 \n\
88 @item bandden\n\
89 The density of non-zero elements in a banded matrix before it is treated\n\
90 by the @sc{lapack} banded solvers (default 0.5)\n\
91 \n\
92 @item umfpack\n\
93 Flag whether the @sc{umfpack} or mmd solvers are used for the LU, '\\' and\n\
94 '/' operations (default 1)\n\
95 @end table\n\
96 \n\
97 The value of individual keys can be set with\n\
98 @code{spparms (@var{key}, @var{val})}.\n\
99 The default values can be restored with the special keyword\n\
100 @qcode{\"defaults\"}. The special keyword @qcode{\"tight\"} can be used to\n\
101 set the mmd solvers to attempt a sparser solution at the potential cost of\n\
102 longer running time.\n\
103 @end deftypefn")
104 {
105  octave_value_list retval;
106  int nargin = args.length ();
107 
108  if (nargin == 0)
109  {
110  if (nargout == 0)
112  else if (nargout == 1)
113  retval(0) = octave_sparse_params::get_vals ();
114  else if (nargout == 2)
115  {
116  retval(1) = octave_sparse_params::get_vals ();
117  retval(0) = octave_sparse_params::get_keys ();
118  }
119  else
120  error ("spparms: too many output arguments");
121  }
122  else if (nargin == 1)
123  {
124  if (args(0).is_string ())
125  {
126  std::string str = args(0).string_value ();
127  int len = str.length ();
128  for (int i = 0; i < len; i++)
129  str[i] = tolower (str[i]);
130 
131  if (str == "defaults")
133  else if (str == "tight")
135  else
136  {
137  double val = octave_sparse_params::get_key (str);
138  if (xisnan (val))
139  error ("spparms: KEY not recognized");
140  else
141  retval(0) = val;
142  }
143  }
144  else
145  {
146  NDArray vals = args(0).array_value ();
147 
148  if (error_state)
149  error ("spparms: input must be a string or a vector");
150  else if (vals.numel () > OCTAVE_SPARSE_CONTROLS_SIZE)
151  error ("spparms: too many elements in vector VALS");
152  else
154  }
155  }
156  else if (nargin == 2)
157  {
158  if (args(0).is_string ())
159  {
160  std::string str = args(0).string_value ();
161 
162  double val = args(1).double_value ();
163 
164  if (error_state)
165  error ("spparms: second argument must be a real scalar");
166  else if (str == "umfpack")
167  warning ("spparms: request to disable umfpack solvers ignored");
168  else if (!octave_sparse_params::set_key (str, val))
169  error ("spparms: KEY not found");
170  }
171  else
172  error ("spparms: first argument must be a string");
173  }
174  else
175  error ("spparms: too many input arguments");
176 
177  return retval;
178 }
179 
180 /*
181 %!test
182 %! old_vals = spparms (); # save state
183 %! spparms ("defaults");
184 %! vals = spparms ();
185 %! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
186 %! [keys, vals] = spparms ();
187 %! assert (rows (keys), 13);
188 %! assert (keys(2,:), "ths_rel");
189 %! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
190 %! spparms ([3 2 1]);
191 %! assert (spparms ()(1:3), [3, 2, 1]');
192 %! assert (spparms ("ths_rel"), 2);
193 %! spparms ("exact_d", 5);
194 %! assert (spparms ("exact_d"), 5);
195 %! spparms (old_vals); # restore state
196 
197 %% Test input validation
198 %!error <too many input arguments> spparms (1, 2, 3)
199 %!error <too many output arguments> [x, y, z] = spparms ()
200 %!error <KEY not recognized> spparms ("UNKNOWN_KEY")
201 %!#error <input must be a string> spparms ({1, 2, 3})
202 %!error spparms ({1, 2, 3})
203 %!error <too many elements in vector VALS> spparms (ones (14, 1))
204 %!error <first argument must be a string> spparms (1, 1)
205 %!#error <second argument must be a real scalar> spparms ("ths_rel", "hello")
206 %!error spparms ("ths_rel", "hello")
207 %!error <KEY not found> spparms ("UNKNOWN_KEY", 1)
208 */