Mercurial > hg > octave-nkf
annotate liboctave/dMatrix.h @ 7788:45f5faba05a2
Add the rcond function
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 14 May 2008 18:09:56 +0200 |
parents | 36594d5bbe13 |
children | 82be108cc558 |
rev | line source |
---|---|
458 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, |
4 2004, 2005, 2006, 2007 John W. Eaton | |
458 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
458 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
458 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_Matrix_int_h) | |
25 #define octave_Matrix_int_h 1 | |
26 | |
1989 | 27 #include "MArray2.h" |
28 #include "MDiagArray2.h" | |
5785 | 29 #include "MatrixType.h" |
458 | 30 |
31 #include "mx-defs.h" | |
2870 | 32 #include "mx-op-defs.h" |
458 | 33 |
3585 | 34 class |
6108 | 35 OCTAVE_API |
3585 | 36 Matrix : public MArray2<double> |
458 | 37 { |
38 public: | |
39 | |
7788 | 40 typedef void (*solve_singularity_handler) (double rcon); |
3480 | 41 |
1214 | 42 Matrix (void) : MArray2<double> () { } |
3585 | 43 |
5275 | 44 Matrix (octave_idx_type r, octave_idx_type c) : MArray2<double> (r, c) { } |
3585 | 45 |
5275 | 46 Matrix (octave_idx_type r, octave_idx_type c, double val) : MArray2<double> (r, c, val) { } |
3585 | 47 |
6979 | 48 Matrix (const dim_vector& dv) : MArray2<double> (dv) { } |
49 | |
50 Matrix (const dim_vector& dv, double val) : MArray2<double> (dv, val) { } | |
51 | |
1214 | 52 Matrix (const Matrix& a) : MArray2<double> (a) { } |
3585 | 53 |
54 Matrix (const MArray2<double>& a) : MArray2<double> (a) { } | |
55 | |
56 explicit Matrix (const RowVector& rv); | |
458 | 57 |
3585 | 58 explicit Matrix (const ColumnVector& cv); |
59 | |
60 explicit Matrix (const DiagMatrix& a); | |
61 | |
62 explicit Matrix (const boolMatrix& a); | |
63 | |
64 explicit Matrix (const charMatrix& a); | |
1574 | 65 |
458 | 66 Matrix& operator = (const Matrix& a) |
67 { | |
1214 | 68 MArray2<double>::operator = (a); |
458 | 69 return *this; |
70 } | |
71 | |
2385 | 72 bool operator == (const Matrix& a) const; |
73 bool operator != (const Matrix& a) const; | |
458 | 74 |
3354 | 75 bool is_symmetric (void) const; |
76 | |
1359 | 77 // destructive insert/delete/reorder operations |
458 | 78 |
5275 | 79 Matrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
80 Matrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); | |
81 Matrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); | |
82 Matrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); | |
458 | 83 |
84 Matrix& fill (double val); | |
5275 | 85 Matrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
458 | 86 |
87 Matrix append (const Matrix& a) const; | |
88 Matrix append (const RowVector& a) const; | |
89 Matrix append (const ColumnVector& a) const; | |
90 Matrix append (const DiagMatrix& a) const; | |
91 | |
92 Matrix stack (const Matrix& a) const; | |
93 Matrix stack (const RowVector& a) const; | |
94 Matrix stack (const ColumnVector& a) const; | |
95 Matrix stack (const DiagMatrix& a) const; | |
96 | |
6108 | 97 friend OCTAVE_API Matrix real (const ComplexMatrix& a); |
98 friend OCTAVE_API Matrix imag (const ComplexMatrix& a); | |
1205 | 99 |
3225 | 100 Matrix transpose (void) const { return MArray2<double>::transpose (); } |
101 | |
1359 | 102 // resize is the destructive equivalent for this one |
458 | 103 |
5275 | 104 Matrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458 | 105 |
5275 | 106 Matrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316 | 107 |
1359 | 108 // extract row or column i. |
458 | 109 |
5275 | 110 RowVector row (octave_idx_type i) const; |
458 | 111 |
5275 | 112 ColumnVector column (octave_idx_type i) const; |
458 | 113 |
6207 | 114 private: |
7788 | 115 Matrix tinverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 116 int force, int calc_cond) const; |
117 | |
7788 | 118 Matrix finverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 119 int force, int calc_cond) const; |
120 | |
121 public: | |
458 | 122 Matrix inverse (void) const; |
6479 | 123 Matrix inverse (octave_idx_type& info) const; |
7788 | 124 Matrix inverse (octave_idx_type& info, double& rcon, int force = 0, |
6479 | 125 int calc_cond = 1) const; |
126 | |
6207 | 127 Matrix inverse (MatrixType &mattype) const; |
128 Matrix inverse (MatrixType &mattype, octave_idx_type& info) const; | |
7788 | 129 Matrix inverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 130 int force = 0, int calc_cond = 1) const; |
458 | 131 |
4384 | 132 Matrix pseudo_inverse (double tol = 0.0) const; |
740 | 133 |
458 | 134 ComplexMatrix fourier (void) const; |
135 ComplexMatrix ifourier (void) const; | |
136 | |
677 | 137 ComplexMatrix fourier2d (void) const; |
138 ComplexMatrix ifourier2d (void) const; | |
139 | |
458 | 140 DET determinant (void) const; |
5275 | 141 DET determinant (octave_idx_type& info) const; |
7788 | 142 DET determinant (octave_idx_type& info, double& rcon, int calc_cond = 1) const; |
143 | |
144 double rcond (void) const; | |
145 double rcond (MatrixType &mattype) const; | |
458 | 146 |
5785 | 147 private: |
148 // Upper triangular matrix solvers | |
149 Matrix utsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 150 double& rcon, solve_singularity_handler sing_handler, |
5785 | 151 bool calc_cond = false) const; |
152 | |
153 // Lower triangular matrix solvers | |
154 Matrix ltsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 155 double& rcon, solve_singularity_handler sing_handler, |
5785 | 156 bool calc_cond = false) const; |
157 | |
158 // Full matrix solvers (lu/cholesky) | |
159 Matrix fsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 160 double& rcon, solve_singularity_handler sing_handler, |
5785 | 161 bool calc_cond = false) const; |
162 | |
163 public: | |
164 // Generic interface to solver with no probing of type | |
165 Matrix solve (MatrixType &typ, const Matrix& b) const; | |
166 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info) const; | |
167 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 168 double& rcon) const; |
5785 | 169 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
7788 | 170 double& rcon, solve_singularity_handler sing_handler, |
5785 | 171 bool singular_fallback = true) const; |
172 | |
173 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; | |
174 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
175 octave_idx_type& info) const; | |
176 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
7788 | 177 octave_idx_type& info, double& rcon) const; |
5785 | 178 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
7788 | 179 octave_idx_type& info, double& rcon, |
5785 | 180 solve_singularity_handler sing_handler, |
181 bool singular_fallback = true) const; | |
182 | |
183 ColumnVector solve (MatrixType &typ, const ColumnVector& b) const; | |
184 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
185 octave_idx_type& info) const; | |
186 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
7788 | 187 octave_idx_type& info, double& rcon) const; |
5785 | 188 ColumnVector solve (MatrixType &typ, const ColumnVector& b, |
7788 | 189 octave_idx_type& info, double& rcon, |
5785 | 190 solve_singularity_handler sing_handler) const; |
191 | |
192 ComplexColumnVector solve (MatrixType &typ, | |
193 const ComplexColumnVector& b) const; | |
194 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
195 octave_idx_type& info) const; | |
196 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
7788 | 197 octave_idx_type& info, double& rcon) const; |
5785 | 198 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
7788 | 199 octave_idx_type& info, double& rcon, |
5785 | 200 solve_singularity_handler sing_handler) const; |
201 | |
202 // Generic interface to solver with probing of type | |
458 | 203 Matrix solve (const Matrix& b) const; |
5275 | 204 Matrix solve (const Matrix& b, octave_idx_type& info) const; |
7788 | 205 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon) const; |
206 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon, | |
3480 | 207 solve_singularity_handler sing_handler) const; |
458 | 208 |
209 ComplexMatrix solve (const ComplexMatrix& b) const; | |
5275 | 210 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
7788 | 211 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const; |
212 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon, | |
3480 | 213 solve_singularity_handler sing_handler) const; |
458 | 214 |
215 ColumnVector solve (const ColumnVector& b) const; | |
5275 | 216 ColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
7788 | 217 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const; |
218 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon, | |
3480 | 219 solve_singularity_handler sing_handler) const; |
458 | 220 |
221 ComplexColumnVector solve (const ComplexColumnVector& b) const; | |
5275 | 222 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
223 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, | |
7788 | 224 double& rcon) const; |
5275 | 225 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
7788 | 226 double& rcon, |
3480 | 227 solve_singularity_handler sing_handler) const; |
458 | 228 |
5785 | 229 // Singular solvers |
458 | 230 Matrix lssolve (const Matrix& b) const; |
5275 | 231 Matrix lssolve (const Matrix& b, octave_idx_type& info) const; |
7076 | 232 Matrix lssolve (const Matrix& b, octave_idx_type& info, |
233 octave_idx_type& rank) const; | |
234 Matrix lssolve (const Matrix& b, octave_idx_type& info, | |
7788 | 235 octave_idx_type& rank, double& rcon) const; |
458 | 236 |
237 ComplexMatrix lssolve (const ComplexMatrix& b) const; | |
5275 | 238 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
239 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, | |
240 octave_idx_type& rank) const; | |
7076 | 241 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
7788 | 242 octave_idx_type& rank, double &rcon) const; |
458 | 243 |
244 ColumnVector lssolve (const ColumnVector& b) const; | |
5275 | 245 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
7076 | 246 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
247 octave_idx_type& rank) const; | |
248 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, | |
7788 | 249 octave_idx_type& rank, double& rcon) const; |
458 | 250 |
251 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; | |
7076 | 252 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
253 octave_idx_type& info) const; | |
254 ComplexColumnVector lssolve (const ComplexColumnVector& b, | |
255 octave_idx_type& info, | |
5275 | 256 octave_idx_type& rank) const; |
7076 | 257 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
258 octave_idx_type& info, | |
7788 | 259 octave_idx_type& rank, double& rcon) const; |
458 | 260 |
1819 | 261 Matrix expm (void) const; |
262 | |
458 | 263 Matrix& operator += (const DiagMatrix& a); |
264 Matrix& operator -= (const DiagMatrix& a); | |
265 | |
1359 | 266 // unary operations |
458 | 267 |
2964 | 268 boolMatrix operator ! (void) const; |
458 | 269 |
1359 | 270 // other operations |
458 | 271 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
272 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
273 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
274 typedef bool (*bmapper) (double); |
2676 | 275 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
276 Matrix map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
277 ComplexMatrix map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
278 boolMatrix map (bmapper fcn) const; |
458 | 279 |
4431 | 280 bool any_element_is_negative (bool = false) const; |
2385 | 281 bool any_element_is_inf_or_nan (void) const; |
5943 | 282 bool any_element_not_one_or_zero (void) const; |
2385 | 283 bool all_elements_are_int_or_inf_or_nan (void) const; |
284 bool all_integers (double& max_val, double& min_val) const; | |
285 bool too_large_for_float (void) const; | |
1963 | 286 |
4017 | 287 boolMatrix all (int dim = -1) const; |
288 boolMatrix any (int dim = -1) const; | |
458 | 289 |
4017 | 290 Matrix cumprod (int dim = -1) const; |
291 Matrix cumsum (int dim = -1) const; | |
292 Matrix prod (int dim = -1) const; | |
293 Matrix sum (int dim = -1) const; | |
294 Matrix sumsq (int dim = -1) const; | |
2385 | 295 Matrix abs (void) const; |
458 | 296 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
297 Matrix diag (octave_idx_type k = 0) const; |
458 | 298 |
299 ColumnVector row_min (void) const; | |
2354 | 300 ColumnVector row_max (void) const; |
458 | 301 |
5275 | 302 ColumnVector row_min (Array<octave_idx_type>& index) const; |
303 ColumnVector row_max (Array<octave_idx_type>& index) const; | |
458 | 304 |
305 RowVector column_min (void) const; | |
2354 | 306 RowVector column_max (void) const; |
458 | 307 |
5275 | 308 RowVector column_min (Array<octave_idx_type>& index) const; |
309 RowVector column_max (Array<octave_idx_type>& index) const; | |
458 | 310 |
1359 | 311 // i/o |
458 | 312 |
6108 | 313 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Matrix& a); |
314 friend OCTAVE_API std::istream& operator >> (std::istream& is, Matrix& a); | |
458 | 315 |
3933 | 316 static double resize_fill_value (void) { return 0; } |
317 | |
458 | 318 private: |
319 | |
5275 | 320 Matrix (double *d, octave_idx_type r, octave_idx_type c) : MArray2<double> (d, r, c) { } |
458 | 321 }; |
322 | |
5508 | 323 // Publish externally used friend functions. |
324 | |
6108 | 325 extern OCTAVE_API Matrix real (const ComplexMatrix& a); |
326 extern OCTAVE_API Matrix imag (const ComplexMatrix& a); | |
5508 | 327 |
328 // column vector by row vector -> matrix operations | |
329 | |
6108 | 330 extern OCTAVE_API Matrix operator * (const ColumnVector& a, const RowVector& b); |
5508 | 331 |
332 // Other functions. | |
333 | |
6108 | 334 extern OCTAVE_API Matrix Givens (double, double); |
1819 | 335 |
6108 | 336 extern OCTAVE_API Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
1959 | 337 |
6108 | 338 extern OCTAVE_API Matrix operator * (const Matrix& a, const Matrix& b); |
2828 | 339 |
6108 | 340 extern OCTAVE_API Matrix min (double d, const Matrix& m); |
341 extern OCTAVE_API Matrix min (const Matrix& m, double d); | |
342 extern OCTAVE_API Matrix min (const Matrix& a, const Matrix& b); | |
4309 | 343 |
6108 | 344 extern OCTAVE_API Matrix max (double d, const Matrix& m); |
345 extern OCTAVE_API Matrix max (const Matrix& m, double d); | |
346 extern OCTAVE_API Matrix max (const Matrix& a, const Matrix& b); | |
4309 | 347 |
6708 | 348 MS_CMP_OP_DECLS (Matrix, double, OCTAVE_API) |
349 MS_BOOL_OP_DECLS (Matrix, double, OCTAVE_API) | |
2870 | 350 |
6708 | 351 SM_CMP_OP_DECLS (double, Matrix, OCTAVE_API) |
352 SM_BOOL_OP_DECLS (double, Matrix, OCTAVE_API) | |
2870 | 353 |
6708 | 354 MM_CMP_OP_DECLS (Matrix, Matrix, OCTAVE_API) |
355 MM_BOOL_OP_DECLS (Matrix, Matrix, OCTAVE_API) | |
2870 | 356 |
3573 | 357 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
358 | |
3689 | 359 template <class T> |
360 void read_int (std::istream& is, bool swap_bytes, T& val); | |
361 | |
458 | 362 #endif |
363 | |
364 /* | |
365 ;;; Local Variables: *** | |
366 ;;; mode: C++ *** | |
367 ;;; End: *** | |
368 */ |