Mercurial > hg > octave-lyh
annotate liboctave/dMatrix.h @ 8015:30629059b72d
Update the manual to reflect the changes in error output
author | sh@sh-laptop |
---|---|
date | Wed, 06 Aug 2008 22:23:54 +0200 |
parents | 935be827eaf8 |
children | 64cf956a109c |
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 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
54 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
55 Matrix (const MArray2<U>& a) : MArray2<double> (a) { } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
56 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
57 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
58 Matrix (const Array2<U>& a) : MArray2<double> (a) { } |
3585 | 59 |
60 explicit Matrix (const RowVector& rv); | |
458 | 61 |
3585 | 62 explicit Matrix (const ColumnVector& cv); |
63 | |
64 explicit Matrix (const DiagMatrix& a); | |
65 | |
66 explicit Matrix (const boolMatrix& a); | |
67 | |
68 explicit Matrix (const charMatrix& a); | |
1574 | 69 |
458 | 70 Matrix& operator = (const Matrix& a) |
71 { | |
1214 | 72 MArray2<double>::operator = (a); |
458 | 73 return *this; |
74 } | |
75 | |
2385 | 76 bool operator == (const Matrix& a) const; |
77 bool operator != (const Matrix& a) const; | |
458 | 78 |
3354 | 79 bool is_symmetric (void) const; |
80 | |
1359 | 81 // destructive insert/delete/reorder operations |
458 | 82 |
5275 | 83 Matrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
84 Matrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); | |
85 Matrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); | |
86 Matrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); | |
458 | 87 |
88 Matrix& fill (double val); | |
5275 | 89 Matrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
458 | 90 |
91 Matrix append (const Matrix& a) const; | |
92 Matrix append (const RowVector& a) const; | |
93 Matrix append (const ColumnVector& a) const; | |
94 Matrix append (const DiagMatrix& a) const; | |
95 | |
96 Matrix stack (const Matrix& a) const; | |
97 Matrix stack (const RowVector& a) const; | |
98 Matrix stack (const ColumnVector& a) const; | |
99 Matrix stack (const DiagMatrix& a) const; | |
100 | |
6108 | 101 friend OCTAVE_API Matrix real (const ComplexMatrix& a); |
102 friend OCTAVE_API Matrix imag (const ComplexMatrix& a); | |
1205 | 103 |
3225 | 104 Matrix transpose (void) const { return MArray2<double>::transpose (); } |
105 | |
1359 | 106 // resize is the destructive equivalent for this one |
458 | 107 |
5275 | 108 Matrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458 | 109 |
5275 | 110 Matrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316 | 111 |
1359 | 112 // extract row or column i. |
458 | 113 |
5275 | 114 RowVector row (octave_idx_type i) const; |
458 | 115 |
5275 | 116 ColumnVector column (octave_idx_type i) const; |
458 | 117 |
6207 | 118 private: |
7788 | 119 Matrix tinverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 120 int force, int calc_cond) const; |
121 | |
7788 | 122 Matrix finverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 123 int force, int calc_cond) const; |
124 | |
125 public: | |
458 | 126 Matrix inverse (void) const; |
6479 | 127 Matrix inverse (octave_idx_type& info) const; |
7788 | 128 Matrix inverse (octave_idx_type& info, double& rcon, int force = 0, |
6479 | 129 int calc_cond = 1) const; |
130 | |
6207 | 131 Matrix inverse (MatrixType &mattype) const; |
132 Matrix inverse (MatrixType &mattype, octave_idx_type& info) const; | |
7788 | 133 Matrix inverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
6207 | 134 int force = 0, int calc_cond = 1) const; |
458 | 135 |
4384 | 136 Matrix pseudo_inverse (double tol = 0.0) const; |
740 | 137 |
458 | 138 ComplexMatrix fourier (void) const; |
139 ComplexMatrix ifourier (void) const; | |
140 | |
677 | 141 ComplexMatrix fourier2d (void) const; |
142 ComplexMatrix ifourier2d (void) const; | |
143 | |
458 | 144 DET determinant (void) const; |
5275 | 145 DET determinant (octave_idx_type& info) const; |
7788 | 146 DET determinant (octave_idx_type& info, double& rcon, int calc_cond = 1) const; |
147 | |
148 double rcond (void) const; | |
149 double rcond (MatrixType &mattype) const; | |
458 | 150 |
5785 | 151 private: |
152 // Upper triangular matrix solvers | |
153 Matrix utsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 154 double& rcon, solve_singularity_handler sing_handler, |
5785 | 155 bool calc_cond = false) const; |
156 | |
157 // Lower triangular matrix solvers | |
158 Matrix ltsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 159 double& rcon, solve_singularity_handler sing_handler, |
5785 | 160 bool calc_cond = false) const; |
161 | |
162 // Full matrix solvers (lu/cholesky) | |
163 Matrix fsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 164 double& rcon, solve_singularity_handler sing_handler, |
5785 | 165 bool calc_cond = false) const; |
166 | |
167 public: | |
168 // Generic interface to solver with no probing of type | |
169 Matrix solve (MatrixType &typ, const Matrix& b) const; | |
170 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info) const; | |
171 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
7788 | 172 double& rcon) const; |
5785 | 173 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
7788 | 174 double& rcon, solve_singularity_handler sing_handler, |
5785 | 175 bool singular_fallback = true) const; |
176 | |
177 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; | |
178 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
179 octave_idx_type& info) const; | |
180 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
7788 | 181 octave_idx_type& info, double& rcon) const; |
5785 | 182 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
7788 | 183 octave_idx_type& info, double& rcon, |
5785 | 184 solve_singularity_handler sing_handler, |
185 bool singular_fallback = true) const; | |
186 | |
187 ColumnVector solve (MatrixType &typ, const ColumnVector& b) const; | |
188 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
189 octave_idx_type& info) const; | |
190 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
7788 | 191 octave_idx_type& info, double& rcon) const; |
5785 | 192 ColumnVector solve (MatrixType &typ, const ColumnVector& b, |
7788 | 193 octave_idx_type& info, double& rcon, |
5785 | 194 solve_singularity_handler sing_handler) const; |
195 | |
196 ComplexColumnVector solve (MatrixType &typ, | |
197 const ComplexColumnVector& b) const; | |
198 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
199 octave_idx_type& info) const; | |
200 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
7788 | 201 octave_idx_type& info, double& rcon) const; |
5785 | 202 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
7788 | 203 octave_idx_type& info, double& rcon, |
5785 | 204 solve_singularity_handler sing_handler) const; |
205 | |
206 // Generic interface to solver with probing of type | |
458 | 207 Matrix solve (const Matrix& b) const; |
5275 | 208 Matrix solve (const Matrix& b, octave_idx_type& info) const; |
7788 | 209 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon) const; |
210 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon, | |
3480 | 211 solve_singularity_handler sing_handler) const; |
458 | 212 |
213 ComplexMatrix solve (const ComplexMatrix& b) const; | |
5275 | 214 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
7788 | 215 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const; |
216 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon, | |
3480 | 217 solve_singularity_handler sing_handler) const; |
458 | 218 |
219 ColumnVector solve (const ColumnVector& b) const; | |
5275 | 220 ColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
7788 | 221 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const; |
222 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon, | |
3480 | 223 solve_singularity_handler sing_handler) const; |
458 | 224 |
225 ComplexColumnVector solve (const ComplexColumnVector& b) const; | |
5275 | 226 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
227 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, | |
7788 | 228 double& rcon) const; |
5275 | 229 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
7788 | 230 double& rcon, |
3480 | 231 solve_singularity_handler sing_handler) const; |
458 | 232 |
5785 | 233 // Singular solvers |
458 | 234 Matrix lssolve (const Matrix& b) const; |
5275 | 235 Matrix lssolve (const Matrix& b, octave_idx_type& info) const; |
7076 | 236 Matrix lssolve (const Matrix& b, octave_idx_type& info, |
237 octave_idx_type& rank) const; | |
238 Matrix lssolve (const Matrix& b, octave_idx_type& info, | |
7788 | 239 octave_idx_type& rank, double& rcon) const; |
458 | 240 |
241 ComplexMatrix lssolve (const ComplexMatrix& b) const; | |
5275 | 242 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
243 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, | |
244 octave_idx_type& rank) const; | |
7076 | 245 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
7788 | 246 octave_idx_type& rank, double &rcon) const; |
458 | 247 |
248 ColumnVector lssolve (const ColumnVector& b) const; | |
5275 | 249 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
7076 | 250 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
251 octave_idx_type& rank) const; | |
252 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, | |
7788 | 253 octave_idx_type& rank, double& rcon) const; |
458 | 254 |
255 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; | |
7076 | 256 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
257 octave_idx_type& info) const; | |
258 ComplexColumnVector lssolve (const ComplexColumnVector& b, | |
259 octave_idx_type& info, | |
5275 | 260 octave_idx_type& rank) const; |
7076 | 261 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
262 octave_idx_type& info, | |
7788 | 263 octave_idx_type& rank, double& rcon) const; |
458 | 264 |
1819 | 265 Matrix expm (void) const; |
266 | |
458 | 267 Matrix& operator += (const DiagMatrix& a); |
268 Matrix& operator -= (const DiagMatrix& a); | |
269 | |
1359 | 270 // unary operations |
458 | 271 |
2964 | 272 boolMatrix operator ! (void) const; |
458 | 273 |
1359 | 274 // other operations |
458 | 275 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
276 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
277 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
278 typedef bool (*bmapper) (double); |
2676 | 279 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
280 Matrix map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
281 ComplexMatrix map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
282 boolMatrix map (bmapper fcn) const; |
458 | 283 |
4431 | 284 bool any_element_is_negative (bool = false) const; |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7800
diff
changeset
|
285 bool any_element_is_nan (void) const; |
2385 | 286 bool any_element_is_inf_or_nan (void) const; |
5943 | 287 bool any_element_not_one_or_zero (void) const; |
2385 | 288 bool all_elements_are_int_or_inf_or_nan (void) const; |
289 bool all_integers (double& max_val, double& min_val) const; | |
290 bool too_large_for_float (void) const; | |
1963 | 291 |
4017 | 292 boolMatrix all (int dim = -1) const; |
293 boolMatrix any (int dim = -1) const; | |
458 | 294 |
4017 | 295 Matrix cumprod (int dim = -1) const; |
296 Matrix cumsum (int dim = -1) const; | |
297 Matrix prod (int dim = -1) const; | |
298 Matrix sum (int dim = -1) const; | |
299 Matrix sumsq (int dim = -1) const; | |
2385 | 300 Matrix abs (void) const; |
458 | 301 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
302 Matrix diag (octave_idx_type k = 0) const; |
458 | 303 |
304 ColumnVector row_min (void) const; | |
2354 | 305 ColumnVector row_max (void) const; |
458 | 306 |
5275 | 307 ColumnVector row_min (Array<octave_idx_type>& index) const; |
308 ColumnVector row_max (Array<octave_idx_type>& index) const; | |
458 | 309 |
310 RowVector column_min (void) const; | |
2354 | 311 RowVector column_max (void) const; |
458 | 312 |
5275 | 313 RowVector column_min (Array<octave_idx_type>& index) const; |
314 RowVector column_max (Array<octave_idx_type>& index) const; | |
458 | 315 |
1359 | 316 // i/o |
458 | 317 |
6108 | 318 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Matrix& a); |
319 friend OCTAVE_API std::istream& operator >> (std::istream& is, Matrix& a); | |
458 | 320 |
3933 | 321 static double resize_fill_value (void) { return 0; } |
322 | |
458 | 323 private: |
324 | |
5275 | 325 Matrix (double *d, octave_idx_type r, octave_idx_type c) : MArray2<double> (d, r, c) { } |
458 | 326 }; |
327 | |
5508 | 328 // Publish externally used friend functions. |
329 | |
6108 | 330 extern OCTAVE_API Matrix real (const ComplexMatrix& a); |
331 extern OCTAVE_API Matrix imag (const ComplexMatrix& a); | |
5508 | 332 |
333 // column vector by row vector -> matrix operations | |
334 | |
6108 | 335 extern OCTAVE_API Matrix operator * (const ColumnVector& a, const RowVector& b); |
5508 | 336 |
337 // Other functions. | |
338 | |
6108 | 339 extern OCTAVE_API Matrix Givens (double, double); |
1819 | 340 |
6108 | 341 extern OCTAVE_API Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
1959 | 342 |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
343 extern OCTAVE_API Matrix xgemm (bool transa, const Matrix& a, bool transb, const Matrix& b); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
344 |
6108 | 345 extern OCTAVE_API Matrix operator * (const Matrix& a, const Matrix& b); |
2828 | 346 |
6108 | 347 extern OCTAVE_API Matrix min (double d, const Matrix& m); |
348 extern OCTAVE_API Matrix min (const Matrix& m, double d); | |
349 extern OCTAVE_API Matrix min (const Matrix& a, const Matrix& b); | |
4309 | 350 |
6108 | 351 extern OCTAVE_API Matrix max (double d, const Matrix& m); |
352 extern OCTAVE_API Matrix max (const Matrix& m, double d); | |
353 extern OCTAVE_API Matrix max (const Matrix& a, const Matrix& b); | |
4309 | 354 |
6708 | 355 MS_CMP_OP_DECLS (Matrix, double, OCTAVE_API) |
356 MS_BOOL_OP_DECLS (Matrix, double, OCTAVE_API) | |
2870 | 357 |
6708 | 358 SM_CMP_OP_DECLS (double, Matrix, OCTAVE_API) |
359 SM_BOOL_OP_DECLS (double, Matrix, OCTAVE_API) | |
2870 | 360 |
6708 | 361 MM_CMP_OP_DECLS (Matrix, Matrix, OCTAVE_API) |
362 MM_BOOL_OP_DECLS (Matrix, Matrix, OCTAVE_API) | |
2870 | 363 |
3573 | 364 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
365 | |
3689 | 366 template <class T> |
367 void read_int (std::istream& is, bool swap_bytes, T& val); | |
368 | |
458 | 369 #endif |
370 | |
371 /* | |
372 ;;; Local Variables: *** | |
373 ;;; mode: C++ *** | |
374 ;;; End: *** | |
375 */ |