spparms.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 David Bateman
00004 Copyright (C) 1998-2004 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "defun-dld.h"
00029 #include "ov.h"
00030 #include "pager.h"
00031 #include "error.h"
00032 #include "gripes.h"
00033 
00034 #include "oct-spparms.h"
00035 
00036 DEFUN_DLD (spparms, args, nargout,
00037   "-*- texinfo -*-\n\
00038 @deftypefn  {Loadable Function} { } spparms ()\n\
00039 @deftypefnx {Loadable Function} {@var{vals} =} spparms ()\n\
00040 @deftypefnx {Loadable Function} {[@var{keys}, @var{vals}] =} spparms ()\n\
00041 @deftypefnx {Loadable Function} {@var{val} =} spparms (@var{key})\n\
00042 @deftypefnx {Loadable Function} { } spparms (@var{vals})\n\
00043 @deftypefnx {Loadable Function} { } spparms ('defaults')\n\
00044 @deftypefnx {Loadable Function} { } spparms ('tight')\n\
00045 @deftypefnx {Loadable Function} { } spparms (@var{key}, @var{val})\n\
00046 Query or set the parameters used by the sparse solvers and factorization\n\
00047 functions.  The first four calls above get information about the current\n\
00048 settings, while the others change the current settings.  The parameters are\n\
00049 stored as pairs of keys and values, where the values are all floats and the\n\
00050 keys are one of the following strings:\n\
00051 \n\
00052 @table @samp\n\
00053 @item spumoni\n\
00054 Printing level of debugging information of the solvers (default 0)\n\
00055 \n\
00056 @item ths_rel\n\
00057 Included for compatibility.  Not used.  (default 1)\n\
00058 \n\
00059 @item ths_abs\n\
00060 Included for compatibility.  Not used.  (default 1)\n\
00061 \n\
00062 @item exact_d\n\
00063 Included for compatibility.  Not used.  (default 0)\n\
00064 \n\
00065 @item supernd\n\
00066 Included for compatibility.  Not used.  (default 3)\n\
00067 \n\
00068 @item rreduce\n\
00069 Included for compatibility.  Not used.  (default 3)\n\
00070 \n\
00071 @item wh_frac\n\
00072 Included for compatibility.  Not used.  (default 0.5)\n\
00073 \n\
00074 @item autommd\n\
00075 Flag whether the LU/QR and the '\\' and '/' operators will automatically\n\
00076 use the sparsity preserving mmd functions (default 1)\n\
00077 \n\
00078 @item autoamd\n\
00079 Flag whether the LU and the '\\' and '/' operators will automatically\n\
00080 use the sparsity preserving amd functions (default 1)\n\
00081 \n\
00082 @item piv_tol\n\
00083 The pivot tolerance of the @sc{umfpack} solvers (default 0.1)\n\
00084 \n\
00085 @item sym_tol\n\
00086 The pivot tolerance of the @sc{umfpack} symmetric solvers (default 0.001)\n\
00087 \n\
00088 @item bandden\n\
00089 The density of non-zero elements in a banded matrix before it is treated\n\
00090 by the @sc{lapack} banded solvers (default 0.5)\n\
00091 \n\
00092 @item umfpack\n\
00093 Flag whether the @sc{umfpack} or mmd solvers are used for the LU, '\\' and\n\
00094 '/' operations (default 1)\n\
00095 @end table\n\
00096 \n\
00097 The value of individual keys can be set with\n\
00098 @code{spparms (@var{key}, @var{val})}.\n\
00099 The default values can be restored with the special keyword\n\
00100 'defaults'.  The special keyword 'tight' can be used to set the mmd solvers\n\
00101 to attempt a sparser solution at the potential cost of longer running\n\
00102 time.\n\
00103 @end deftypefn")
00104 {
00105   octave_value_list retval;
00106   int nargin = args.length ();
00107 
00108   if (nargin == 0)
00109     {
00110       if (nargout == 0)
00111         octave_sparse_params::print_info (octave_stdout, "");
00112       else if (nargout == 1)
00113         retval(0) =  octave_sparse_params::get_vals ();
00114       else if (nargout == 2)
00115         {
00116           retval (1) = octave_sparse_params::get_vals ();
00117           retval (0) = octave_sparse_params::get_keys ();
00118         }
00119       else
00120         error ("spparms: too many output arguments");
00121     }
00122   else if (nargin == 1)
00123     {
00124       if (args(0).is_string ())
00125         {
00126           std::string str = args(0).string_value ();
00127           int len = str.length ();
00128           for (int i = 0; i < len; i++)
00129             str [i] = tolower (str [i]);
00130 
00131           if (str == "defaults")
00132             octave_sparse_params::defaults ();
00133           else if (str == "tight")
00134             octave_sparse_params::tight ();
00135           else
00136             {
00137               double val = octave_sparse_params::get_key (str);
00138               if (xisnan (val))
00139                 error ("spparms: KEY not recognized");
00140               else
00141                 retval (0) = val;
00142             }
00143         }
00144       else
00145         {
00146           NDArray vals = args(0).array_value ();
00147 
00148           if (error_state)
00149             error ("spparms: input must be a string or a vector");
00150           else if (vals.numel () > OCTAVE_SPARSE_CONTROLS_SIZE)
00151             error ("spparms: too many elements in vector VALS");
00152           else
00153             octave_sparse_params::set_vals (vals);
00154         }
00155     }
00156   else if (nargin == 2)
00157     {
00158       if (args(0).is_string ())
00159         {
00160           std::string str = args(0).string_value ();
00161 
00162           double val = args(1).double_value ();
00163 
00164           if (error_state)
00165             error ("spparms: second argument must be a real scalar");
00166           else if (str == "umfpack")
00167             warning ("spparms: request to disable umfpack solvers ignored");
00168           else if (!octave_sparse_params::set_key (str, val))
00169             error ("spparms: KEY not found");
00170         }
00171       else
00172         error ("spparms: first argument must be a string");
00173     }
00174   else
00175     error ("spparms: too many input arguments");
00176 
00177   return retval;
00178 }
00179 
00180 /*
00181 
00182 %!test
00183 %! old_vals = spparms ();  # save state
00184 %! spparms ("defaults");
00185 %! vals = spparms ();
00186 %! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
00187 %! [keys, vals] = spparms ();
00188 %! assert (rows (keys), 13);
00189 %! assert (keys(2,:), "ths_rel");
00190 %! assert (vals, [0 1 1 0 3 3 0.5 1.0 1.0 0.1 0.5 1.0 0.001]');
00191 %! spparms ([3 2 1]);
00192 %! assert (spparms ()(1:3), [3, 2, 1]');
00193 %! assert (spparms ("ths_rel"), 2);
00194 %! spparms ("exact_d", 5);
00195 %! assert (spparms ("exact_d"), 5);
00196 %! spparms (old_vals);     # restore state
00197 
00198 %% Test input validation
00199 %!error (spparms (1, 2, 3))
00200 %!error ([x, y, z] = spparms ())
00201 %!error (spparms ("UNKNOWN_KEY"))
00202 %!error (spparms ({1, 2, 3}))
00203 %!error (spparms (ones (14, 1)))
00204 %!error (spparms (1, 1))
00205 %!error (spparms ("ths_rel", "hello"))
00206 %!error (spparms ("UNKNOWN_KEY", 1))
00207 
00208 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines