comparison liboctave/fMatrix.h @ 7789:82be108cc558

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