GNU Octave  4.2.1
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
__luinc__.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2005-2017 David Bateman
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "defun.h"
28 #include "error.h"
29 #include "errwarn.h"
30 #include "ovl.h"
31 #include "utils.h"
32 #include "oct-map.h"
33 
34 #include "MatrixType.h"
35 #include "sparse-lu.h"
36 #include "ov-re-sparse.h"
37 #include "ov-cx-sparse.h"
38 
39 // FIXME: Deprecated in 4.0 and should be removed in 4.4.
40 DEFUN (__luinc__, args, nargout,
41  doc: /* -*- texinfo -*-
42 @deftypefn {} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} __luinc__ (@var{A}, '0')
43 @deftypefnx {} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} __luinc__ (@var{A}, @var{droptol})
44 @deftypefnx {} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} __luinc__ (@var{A}, @var{opts})
45 Internal implementation of @code{luinc}.
46 
47 See documentation for @code{luinc}.
48 @seealso{luinc}
49 @end deftypefn */)
50 {
51  int nargin = args.length ();
52 
53  if (nargin < 2 || nargin > 3)
54  print_usage ();
55 
56  if (! args(0).is_sparse_type ())
57  error ("luinc: matrix A must be sparse");
58 
59  bool zero_level = false;
60  bool milu = false;
61  bool udiag = false;
62  Matrix thresh;
63  double droptol = -1.0;
64  bool vecout = false;
65 
66  if (args(1).is_string ())
67  {
68  if (args(1).string_value () == "0")
69  zero_level = true;
70  else
71  error ("luinc: unrecognized string argument");
72  }
73  else if (args(1).is_map ())
74  {
76  = args(1).xscalar_map_value ("luinc: OPTS must be a scalar structure");
77 
79 
80  tmp = map.getfield ("droptol");
81  if (tmp.is_defined ())
82  droptol = tmp.double_value ();
83 
84  tmp = map.getfield ("milu");
85  if (tmp.is_defined ())
86  {
87  double val = tmp.double_value ();
88 
89  milu = (val == 0.0 ? false : true);
90  }
91 
92  tmp = map.getfield ("udiag");
93  if (tmp.is_defined ())
94  {
95  double val = tmp.double_value ();
96 
97  udiag = (val == 0.0 ? false : true);
98  }
99 
100  tmp = map.getfield ("thresh");
101  if (tmp.is_defined ())
102  {
103  thresh = tmp.matrix_value ();
104 
105  if (thresh.numel () == 1)
106  {
107  thresh.resize (1, 2);
108  thresh(1) = thresh(0);
109  }
110  else if (thresh.numel () != 2)
111  error ("luinc: THRESH must be a 1 or 2-element vector");
112  }
113  }
114  else
115  droptol = args(1).double_value ();
116 
117  if (nargin == 3)
118  {
119  std::string tmp = args(2).string_value ();
120 
121  if (tmp == "vector")
122  vecout = true;
123  else
124  error ("luinc: unrecognized string argument");
125  }
126 
127  // FIXME: Add code for zero-level factorization
128  if (zero_level)
129  error ("luinc: zero-level factorization not implemented");
130 
132 
133  if (args(0).is_real_type ())
134  {
135  SparseMatrix sm = args(0).sparse_matrix_value ();
136  octave_idx_type sm_nr = sm.rows ();
137  octave_idx_type sm_nc = sm.cols ();
138  ColumnVector Qinit (sm_nc);
139 
140  for (octave_idx_type i = 0; i < sm_nc; i++)
141  Qinit(i) = i;
142 
143  switch (nargout)
144  {
145  case 0:
146  case 1:
147  case 2:
148  {
150  (sm, Qinit, thresh, false, true, droptol, milu, udiag);
151 
152  SparseMatrix P = fact.Pr ();
153  SparseMatrix L = P.transpose () * fact.L ();
154 
155  retval(1)
157 
158  retval(0)
160  sm_nr, fact.row_perm ()));
161  }
162  break;
163 
164  case 3:
165  {
167  (sm, Qinit, thresh, false, true, droptol, milu, udiag);
168 
169  if (vecout)
170  retval(2) = fact.Pr_vec ();
171  else
172  retval(2) = fact.Pr_mat ();
173 
174  retval(1)
176 
177  retval(0)
179  }
180  break;
181 
182  case 4:
183  default:
184  {
186  (sm, Qinit, thresh, false, false, droptol, milu, udiag);
187 
188  if (vecout)
189  {
190  retval(3) = fact.Pc_vec ();
191  retval(2) = fact.Pr_vec ();
192  }
193  else
194  {
195  retval(3) = fact.Pc_mat ();
196  retval(2) = fact.Pr_mat ();
197  }
198 
199  retval(1)
201 
202  retval(0)
204  }
205  break;
206  }
207  }
208  else
209  {
210  SparseComplexMatrix sm = args(0).sparse_complex_matrix_value ();
211  octave_idx_type sm_nr = sm.rows ();
212  octave_idx_type sm_nc = sm.cols ();
213  ColumnVector Qinit (sm_nc);
214 
215  for (octave_idx_type i = 0; i < sm_nc; i++)
216  Qinit(i) = i;
217 
218  switch (nargout)
219  {
220  case 0:
221  case 1:
222  case 2:
223  {
225  (sm, Qinit, thresh, false, true, droptol, milu, udiag);
226 
227  SparseMatrix P = fact.Pr ();
228  SparseComplexMatrix L = P.transpose () * fact.L ();
229 
230  retval(1)
232 
233  retval(0)
235  sm_nr, fact.row_perm ()));
236  }
237  break;
238 
239  case 3:
240  {
242  (sm, Qinit, thresh, false, true, droptol, milu, udiag);
243 
244  if (vecout)
245  retval(2) = fact.Pr_vec ();
246  else
247  retval(2) = fact.Pr_mat ();
248 
249  retval(1)
251 
252  retval(0)
254  }
255  break;
256 
257  case 4:
258  default:
259  {
261  (sm, Qinit, thresh, false, false, droptol, milu, udiag);
262 
263  if (vecout)
264  {
265  retval(3) = fact.Pc_vec ();
266  retval(2) = fact.Pr_vec ();
267  }
268  else
269  {
270  retval(3) = fact.Pc_mat ();
271  retval(2) = fact.Pr_mat ();
272  }
273 
274  retval(1)
276 
277  retval(0)
279  }
280  break;
281  }
282  }
283 
284  return retval;
285 }
ColumnVector Pc_vec(void) const
Definition: sparse-lu.cc:938
octave_idx_type cols(void) const
Definition: Sparse.h:272
octave_idx_type rows(void) const
Definition: Sparse.h:271
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
Definition: dMatrix.h:145
SparseMatrix transpose(void) const
Definition: dSparse.h:141
ar P
Definition: __luinc__.cc:49
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
SparseMatrix Pr(void) const
Definition: sparse-lu.cc:877
PermMatrix Pr_mat(void) const
Definition: sparse-lu.cc:911
lu_type L(void) const
Definition: sparse-lu.h:82
bool is_defined(void) const
Definition: ov.h:536
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
ColumnVector Pr_vec(void) const
Definition: sparse-lu.cc:897
JNIEnv void * args
Definition: ov-java.cc:67
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
const octave_idx_type * row_perm(void) const
Definition: sparse-lu.h:102
int nargin
Definition: graphics.cc:10115
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
Definition: dMatrix.h:37
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:787
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_map map(dims)
PermMatrix Pc_mat(void) const
Definition: sparse-lu.cc:952
octave_value getfield(const std::string &key) const
Definition: oct-map.cc:171
double double_value(bool frc_str_conv=false) const
Definition: ov.h:775
lu_type U(void) const
Definition: sparse-lu.h:84
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))