Mercurial > hg > octave-lyh
annotate liboctave/dMatrix.h @ 7503:8c32f95c2639
convert mapper functions to new format
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 20 Feb 2008 04:22:50 -0500 |
parents | 0bade2dc44a1 |
children | 36594d5bbe13 |
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 | |
3480 | 40 typedef void (*solve_singularity_handler) (double rcond); |
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: |
115 Matrix tinverse (MatrixType &mattype, octave_idx_type& info, double& rcond, | |
116 int force, int calc_cond) const; | |
117 | |
118 Matrix finverse (MatrixType &mattype, octave_idx_type& info, double& rcond, | |
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; |
124 Matrix inverse (octave_idx_type& info, double& rcond, int force = 0, | |
125 int calc_cond = 1) const; | |
126 | |
6207 | 127 Matrix inverse (MatrixType &mattype) const; |
128 Matrix inverse (MatrixType &mattype, octave_idx_type& info) const; | |
129 Matrix inverse (MatrixType &mattype, octave_idx_type& info, double& rcond, | |
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; |
142 DET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; | |
458 | 143 |
5785 | 144 private: |
145 // Upper triangular matrix solvers | |
146 Matrix utsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
147 double& rcond, solve_singularity_handler sing_handler, | |
148 bool calc_cond = false) const; | |
149 | |
150 // Lower triangular matrix solvers | |
151 Matrix ltsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
152 double& rcond, solve_singularity_handler sing_handler, | |
153 bool calc_cond = false) const; | |
154 | |
155 // Full matrix solvers (lu/cholesky) | |
156 Matrix fsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
157 double& rcond, solve_singularity_handler sing_handler, | |
158 bool calc_cond = false) const; | |
159 | |
160 public: | |
161 // Generic interface to solver with no probing of type | |
162 Matrix solve (MatrixType &typ, const Matrix& b) const; | |
163 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info) const; | |
164 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
165 double& rcond) const; | |
166 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
167 double& rcond, solve_singularity_handler sing_handler, | |
168 bool singular_fallback = true) const; | |
169 | |
170 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; | |
171 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
172 octave_idx_type& info) const; | |
173 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
174 octave_idx_type& info, double& rcond) const; | |
175 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
176 octave_idx_type& info, double& rcond, | |
177 solve_singularity_handler sing_handler, | |
178 bool singular_fallback = true) const; | |
179 | |
180 ColumnVector solve (MatrixType &typ, const ColumnVector& b) const; | |
181 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
182 octave_idx_type& info) const; | |
183 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
184 octave_idx_type& info, double& rcond) const; | |
185 ColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
186 octave_idx_type& info, double& rcond, | |
187 solve_singularity_handler sing_handler) const; | |
188 | |
189 ComplexColumnVector solve (MatrixType &typ, | |
190 const ComplexColumnVector& b) const; | |
191 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
192 octave_idx_type& info) const; | |
193 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
194 octave_idx_type& info, double& rcond) const; | |
195 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
196 octave_idx_type& info, double& rcond, | |
197 solve_singularity_handler sing_handler) const; | |
198 | |
199 // Generic interface to solver with probing of type | |
458 | 200 Matrix solve (const Matrix& b) const; |
5275 | 201 Matrix solve (const Matrix& b, octave_idx_type& info) const; |
202 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; | |
203 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcond, | |
3480 | 204 solve_singularity_handler sing_handler) const; |
458 | 205 |
206 ComplexMatrix solve (const ComplexMatrix& b) const; | |
5275 | 207 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
208 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; | |
209 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, | |
3480 | 210 solve_singularity_handler sing_handler) const; |
458 | 211 |
212 ColumnVector solve (const ColumnVector& b) const; | |
5275 | 213 ColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
214 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond) const; | |
215 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, | |
3480 | 216 solve_singularity_handler sing_handler) const; |
458 | 217 |
218 ComplexColumnVector solve (const ComplexColumnVector& b) const; | |
5275 | 219 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
220 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, | |
458 | 221 double& rcond) const; |
5275 | 222 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480 | 223 double& rcond, |
224 solve_singularity_handler sing_handler) const; | |
458 | 225 |
5785 | 226 // Singular solvers |
458 | 227 Matrix lssolve (const Matrix& b) const; |
5275 | 228 Matrix lssolve (const Matrix& b, octave_idx_type& info) const; |
7076 | 229 Matrix lssolve (const Matrix& b, octave_idx_type& info, |
230 octave_idx_type& rank) const; | |
231 Matrix lssolve (const Matrix& b, octave_idx_type& info, | |
232 octave_idx_type& rank, double& rcond) const; | |
458 | 233 |
234 ComplexMatrix lssolve (const ComplexMatrix& b) const; | |
5275 | 235 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
236 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, | |
237 octave_idx_type& rank) const; | |
7076 | 238 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
239 octave_idx_type& rank, double &rcond) const; | |
458 | 240 |
241 ColumnVector lssolve (const ColumnVector& b) const; | |
5275 | 242 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
7076 | 243 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
244 octave_idx_type& rank) const; | |
245 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, | |
246 octave_idx_type& rank, double& rcond) const; | |
458 | 247 |
248 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; | |
7076 | 249 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
250 octave_idx_type& info) const; | |
251 ComplexColumnVector lssolve (const ComplexColumnVector& b, | |
252 octave_idx_type& info, | |
5275 | 253 octave_idx_type& rank) const; |
7076 | 254 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
255 octave_idx_type& info, | |
256 octave_idx_type& rank, double& rcond) const; | |
458 | 257 |
1819 | 258 Matrix expm (void) const; |
259 | |
458 | 260 Matrix& operator += (const DiagMatrix& a); |
261 Matrix& operator -= (const DiagMatrix& a); | |
262 | |
1359 | 263 // unary operations |
458 | 264 |
2964 | 265 boolMatrix operator ! (void) const; |
458 | 266 |
1359 | 267 // other operations |
458 | 268 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
269 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
270 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
271 typedef bool (*bmapper) (double); |
2676 | 272 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
273 Matrix map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
274 ComplexMatrix map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
275 boolMatrix map (bmapper fcn) const; |
458 | 276 |
4431 | 277 bool any_element_is_negative (bool = false) const; |
2385 | 278 bool any_element_is_inf_or_nan (void) const; |
5943 | 279 bool any_element_not_one_or_zero (void) const; |
2385 | 280 bool all_elements_are_int_or_inf_or_nan (void) const; |
281 bool all_integers (double& max_val, double& min_val) const; | |
282 bool too_large_for_float (void) const; | |
1963 | 283 |
4017 | 284 boolMatrix all (int dim = -1) const; |
285 boolMatrix any (int dim = -1) const; | |
458 | 286 |
4017 | 287 Matrix cumprod (int dim = -1) const; |
288 Matrix cumsum (int dim = -1) const; | |
289 Matrix prod (int dim = -1) const; | |
290 Matrix sum (int dim = -1) const; | |
291 Matrix sumsq (int dim = -1) const; | |
2385 | 292 Matrix abs (void) const; |
458 | 293 |
294 ColumnVector diag (void) const; | |
5275 | 295 ColumnVector diag (octave_idx_type k) const; |
458 | 296 |
297 ColumnVector row_min (void) const; | |
2354 | 298 ColumnVector row_max (void) const; |
458 | 299 |
5275 | 300 ColumnVector row_min (Array<octave_idx_type>& index) const; |
301 ColumnVector row_max (Array<octave_idx_type>& index) const; | |
458 | 302 |
303 RowVector column_min (void) const; | |
2354 | 304 RowVector column_max (void) const; |
458 | 305 |
5275 | 306 RowVector column_min (Array<octave_idx_type>& index) const; |
307 RowVector column_max (Array<octave_idx_type>& index) const; | |
458 | 308 |
1359 | 309 // i/o |
458 | 310 |
6108 | 311 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Matrix& a); |
312 friend OCTAVE_API std::istream& operator >> (std::istream& is, Matrix& a); | |
458 | 313 |
3933 | 314 static double resize_fill_value (void) { return 0; } |
315 | |
458 | 316 private: |
317 | |
5275 | 318 Matrix (double *d, octave_idx_type r, octave_idx_type c) : MArray2<double> (d, r, c) { } |
458 | 319 }; |
320 | |
5508 | 321 // Publish externally used friend functions. |
322 | |
6108 | 323 extern OCTAVE_API Matrix real (const ComplexMatrix& a); |
324 extern OCTAVE_API Matrix imag (const ComplexMatrix& a); | |
5508 | 325 |
326 // column vector by row vector -> matrix operations | |
327 | |
6108 | 328 extern OCTAVE_API Matrix operator * (const ColumnVector& a, const RowVector& b); |
5508 | 329 |
330 // Other functions. | |
331 | |
6108 | 332 extern OCTAVE_API Matrix Givens (double, double); |
1819 | 333 |
6108 | 334 extern OCTAVE_API Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
1959 | 335 |
6108 | 336 extern OCTAVE_API Matrix operator * (const Matrix& a, const Matrix& b); |
2828 | 337 |
6108 | 338 extern OCTAVE_API Matrix min (double d, const Matrix& m); |
339 extern OCTAVE_API Matrix min (const Matrix& m, double d); | |
340 extern OCTAVE_API Matrix min (const Matrix& a, const Matrix& b); | |
4309 | 341 |
6108 | 342 extern OCTAVE_API Matrix max (double d, const Matrix& m); |
343 extern OCTAVE_API Matrix max (const Matrix& m, double d); | |
344 extern OCTAVE_API Matrix max (const Matrix& a, const Matrix& b); | |
4309 | 345 |
6708 | 346 MS_CMP_OP_DECLS (Matrix, double, OCTAVE_API) |
347 MS_BOOL_OP_DECLS (Matrix, double, OCTAVE_API) | |
2870 | 348 |
6708 | 349 SM_CMP_OP_DECLS (double, Matrix, OCTAVE_API) |
350 SM_BOOL_OP_DECLS (double, Matrix, OCTAVE_API) | |
2870 | 351 |
6708 | 352 MM_CMP_OP_DECLS (Matrix, Matrix, OCTAVE_API) |
353 MM_BOOL_OP_DECLS (Matrix, Matrix, OCTAVE_API) | |
2870 | 354 |
3573 | 355 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
356 | |
3689 | 357 template <class T> |
358 void read_int (std::istream& is, bool swap_bytes, T& val); | |
359 | |
458 | 360 #endif |
361 | |
362 /* | |
363 ;;; Local Variables: *** | |
364 ;;; mode: C++ *** | |
365 ;;; End: *** | |
366 */ |