GNU Octave  3.8.0
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
fMatrix.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
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 (octave_fMatrix_h)
24 #define octave_fMatrix_h 1
25 
26 #include "MArray.h"
27 #include "MDiagArray2.h"
28 #include "MatrixType.h"
29 
30 #include "mx-defs.h"
31 #include "mx-op-decl.h"
32 #include "DET.h"
33 
34 class
35 OCTAVE_API
37 {
38 public:
39 
42 
43  typedef void (*solve_singularity_handler) (float rcon);
44 
45  FloatMatrix (void) : MArray<float> () { }
46 
48  : MArray<float> (dim_vector (r, c)) { }
49 
51  : MArray<float> (dim_vector (r, c), val) { }
52 
53  FloatMatrix (const dim_vector& dv) : MArray<float> (dv.redim (2)) { }
54 
55  FloatMatrix (const dim_vector& dv, float val)
56  : MArray<float> (dv.redim (2), val) { }
57 
58  FloatMatrix (const FloatMatrix& a) : MArray<float> (a) { }
59 
60  template <class U>
61  FloatMatrix (const MArray<U>& a) : MArray<float> (a.as_matrix ()) { }
62 
63  template <class U>
64  FloatMatrix (const Array<U>& a) : MArray<float> (a.as_matrix ()) { }
65 
66  explicit FloatMatrix (const FloatRowVector& rv);
67 
68  explicit FloatMatrix (const FloatColumnVector& cv);
69 
70  explicit FloatMatrix (const FloatDiagMatrix& a);
71 
72  explicit FloatMatrix (const PermMatrix& a);
73 
74  explicit FloatMatrix (const boolMatrix& a);
75 
76  explicit FloatMatrix (const charMatrix& a);
77 
78 
80  {
82  return *this;
83  }
84 
85  bool operator == (const FloatMatrix& a) const;
86  bool operator != (const FloatMatrix& a) const;
87 
88  bool is_symmetric (void) const;
89 
90  // destructive insert/delete/reorder operations
91 
92  FloatMatrix& insert (const FloatMatrix& a,
94  FloatMatrix& insert (const FloatRowVector& a,
96  FloatMatrix& insert (const FloatColumnVector& a,
98  FloatMatrix& insert (const FloatDiagMatrix& a,
100 
101  FloatMatrix& fill (float val);
102  FloatMatrix& fill (float val, octave_idx_type r1, octave_idx_type c1,
104 
105  FloatMatrix append (const FloatMatrix& a) const;
106  FloatMatrix append (const FloatRowVector& a) const;
107  FloatMatrix append (const FloatColumnVector& a) const;
108  FloatMatrix append (const FloatDiagMatrix& a) const;
109 
110  FloatMatrix stack (const FloatMatrix& a) const;
111  FloatMatrix stack (const FloatRowVector& a) const;
112  FloatMatrix stack (const FloatColumnVector& a) const;
113  FloatMatrix stack (const FloatDiagMatrix& a) const;
114 
115  friend OCTAVE_API FloatMatrix real (const FloatComplexMatrix& a);
116  friend OCTAVE_API FloatMatrix imag (const FloatComplexMatrix& a);
117 
118  friend class FloatComplexMatrix;
119 
120  FloatMatrix transpose (void) const { return MArray<float>::transpose (); }
121 
122  // resize is the destructive equivalent for this one
123 
126 
128  octave_idx_type nr, octave_idx_type nc) const;
129 
130  // extract row or column i.
131 
133 
135 
136  void resize (octave_idx_type nr, octave_idx_type nc, float rfv = 0)
137  {
138  MArray<float>::resize (dim_vector (nr, nc), rfv);
139  }
140 
141 private:
143  float& rcon, int force, int calc_cond) const;
144 
146  float& rcon, int force, int calc_cond) const;
147 
148 public:
149  FloatMatrix inverse (void) const;
150  FloatMatrix inverse (octave_idx_type& info) const;
151  FloatMatrix inverse (octave_idx_type& info, float& rcon, int force = 0,
152  int calc_cond = 1) const;
153 
154  FloatMatrix inverse (MatrixType &mattype) const;
155  FloatMatrix inverse (MatrixType &mattype, octave_idx_type& info) const;
156  FloatMatrix inverse (MatrixType &mattype, octave_idx_type& info, float& rcon,
157  int force = 0, int calc_cond = 1) const;
158 
159  FloatMatrix pseudo_inverse (float tol = 0.0) const;
160 
161  FloatComplexMatrix fourier (void) const;
162  FloatComplexMatrix ifourier (void) const;
163 
164  FloatComplexMatrix fourier2d (void) const;
165  FloatComplexMatrix ifourier2d (void) const;
166 
167  FloatDET determinant (void) const;
168  FloatDET determinant (octave_idx_type& info) const;
169  FloatDET determinant (octave_idx_type& info, float& rcon,
170  int calc_cond = 1) const;
172  float& rcon, int calc_cond = 1) const;
173 
174  float rcond (void) const;
175  float rcond (MatrixType &mattype) const;
176 
177 private:
178  // Upper triangular matrix solvers
179  FloatMatrix utsolve (MatrixType &typ, const FloatMatrix& b,
180  octave_idx_type& info,
181  float& rcon, solve_singularity_handler sing_handler,
182  bool calc_cond = false,
183  blas_trans_type transt = blas_no_trans) const;
184 
185  // Lower triangular matrix solvers
186  FloatMatrix ltsolve (MatrixType &typ, const FloatMatrix& b,
187  octave_idx_type& info,
188  float& rcon, solve_singularity_handler sing_handler,
189  bool calc_cond = false,
190  blas_trans_type transt = blas_no_trans) const;
191 
192  // Full matrix solvers (lu/cholesky)
193  FloatMatrix fsolve (MatrixType &typ, const FloatMatrix& b,
194  octave_idx_type& info,
195  float& rcon, solve_singularity_handler sing_handler,
196  bool calc_cond = false) const;
197 
198 public:
199  // Generic interface to solver with no probing of type
200  FloatMatrix solve (MatrixType &typ, const FloatMatrix& b) const;
201  FloatMatrix solve (MatrixType &typ, const FloatMatrix& b,
202  octave_idx_type& info) const;
203  FloatMatrix solve (MatrixType &typ, const FloatMatrix& b,
204  octave_idx_type& info, float& rcon) const;
205  FloatMatrix solve (MatrixType &typ, const FloatMatrix& b,
206  octave_idx_type& info, float& rcon,
207  solve_singularity_handler sing_handler,
208  bool singular_fallback = true,
209  blas_trans_type transt = blas_no_trans) const;
210 
211  FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b) const;
213  octave_idx_type& info) const;
215  octave_idx_type& info, float& rcon) const;
217  octave_idx_type& info, float& rcon,
218  solve_singularity_handler sing_handler,
219  bool singular_fallback = true,
220  blas_trans_type transt = blas_no_trans) const;
221 
222  FloatColumnVector solve (MatrixType &typ, const FloatColumnVector& b) const;
224  octave_idx_type& info) const;
226  octave_idx_type& info, float& rcon) const;
228  octave_idx_type& info, float& rcon,
229  solve_singularity_handler sing_handler,
230  blas_trans_type transt = blas_no_trans) const;
231 
233  const FloatComplexColumnVector& b) const;
235  const FloatComplexColumnVector& b,
236  octave_idx_type& info) const;
238  const FloatComplexColumnVector& b,
239  octave_idx_type& info, float& rcon) const;
241  const FloatComplexColumnVector& b,
242  octave_idx_type& info, float& rcon,
243  solve_singularity_handler sing_handler,
244  blas_trans_type transt = blas_no_trans) const;
245 
246  // Generic interface to solver with probing of type
247  FloatMatrix solve (const FloatMatrix& b) const;
248  FloatMatrix solve (const FloatMatrix& b, octave_idx_type& info) const;
249  FloatMatrix solve (const FloatMatrix& b, octave_idx_type& info,
250  float& rcon) const;
251  FloatMatrix solve (const FloatMatrix& b, octave_idx_type& info, float& rcon,
252  solve_singularity_handler sing_handler,
253  blas_trans_type transt = blas_no_trans) const;
254 
257  octave_idx_type& info) const;
259  float& rcon) const;
261  float& rcon,
262  solve_singularity_handler sing_handler,
263  blas_trans_type transt = blas_no_trans) const;
264 
265  FloatColumnVector solve (const FloatColumnVector& b) const;
267  octave_idx_type& info) const;
269  float& rcon) const;
271  float& rcon,
272  solve_singularity_handler sing_handler,
273  blas_trans_type transt = blas_no_trans) const;
274 
277  octave_idx_type& info) const;
279  octave_idx_type& info,
280  float& rcon) const;
282  octave_idx_type& info,
283  float& rcon,
284  solve_singularity_handler sing_handler,
285  blas_trans_type transt = blas_no_trans) const;
286 
287  // Singular solvers
288  FloatMatrix lssolve (const FloatMatrix& b) const;
289  FloatMatrix lssolve (const FloatMatrix& b, octave_idx_type& info) const;
291  octave_idx_type& rank) const;
293  octave_idx_type& rank, float& rcon) const;
294 
297  octave_idx_type& info) const;
299  octave_idx_type& info,
300  octave_idx_type& rank) const;
302  octave_idx_type& info, octave_idx_type& rank,
303  float &rcon) const;
304 
307  octave_idx_type& info) const;
309  octave_idx_type& rank) const;
311  octave_idx_type& rank, float& rcon) const;
312 
315  octave_idx_type& info) const;
317  octave_idx_type& info,
318  octave_idx_type& rank) const;
320  octave_idx_type& info,
321  octave_idx_type& rank, float& rcon) const;
322 
325 
326  // unary operations
327 
328  boolMatrix operator ! (void) const;
329 
330  // other operations
331 
332  bool any_element_is_negative (bool = false) const;
333  bool any_element_is_positive (bool = false) const;
334  bool any_element_is_nan (void) const;
335  bool any_element_is_inf_or_nan (void) const;
336  bool any_element_not_one_or_zero (void) const;
337  bool all_elements_are_int_or_inf_or_nan (void) const;
338  bool all_integers (float& max_val, float& min_val) const;
339  bool too_large_for_float (void) const;
340 
341  boolMatrix all (int dim = -1) const;
342  boolMatrix any (int dim = -1) const;
343 
344  FloatMatrix cumprod (int dim = -1) const;
345  FloatMatrix cumsum (int dim = -1) const;
346  FloatMatrix prod (int dim = -1) const;
347  FloatMatrix sum (int dim = -1) const;
348  FloatMatrix sumsq (int dim = -1) const;
349  FloatMatrix abs (void) const;
350 
351  FloatMatrix diag (octave_idx_type k = 0) const;
352 
354 
355  FloatColumnVector row_min (void) const;
356  FloatColumnVector row_max (void) const;
357 
360 
361  FloatRowVector column_min (void) const;
362  FloatRowVector column_max (void) const;
363 
366 
367  // i/o
368 
369  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
370  const FloatMatrix& a);
371  friend OCTAVE_API std::istream& operator >> (std::istream& is,
372  FloatMatrix& a);
373 };
374 
375 // Publish externally used friend functions.
376 
377 extern OCTAVE_API FloatMatrix real (const FloatComplexMatrix& a);
378 extern OCTAVE_API FloatMatrix imag (const FloatComplexMatrix& a);
379 
380 // column vector by row vector -> matrix operations
381 
382 extern OCTAVE_API FloatMatrix operator * (const FloatColumnVector& a,
383  const FloatRowVector& b);
384 
385 // Other functions.
386 
387 extern OCTAVE_API FloatMatrix Givens (float, float);
388 
389 extern OCTAVE_API FloatMatrix Sylvester (const FloatMatrix&, const FloatMatrix&,
390  const FloatMatrix&);
391 
392 extern OCTAVE_API FloatMatrix xgemm (const FloatMatrix& a, const FloatMatrix& b,
394  blas_trans_type transb = blas_no_trans);
395 
396 extern OCTAVE_API FloatMatrix operator * (const FloatMatrix& a,
397  const FloatMatrix& b);
398 
399 extern OCTAVE_API FloatMatrix min (float d, const FloatMatrix& m);
400 extern OCTAVE_API FloatMatrix min (const FloatMatrix& m, float d);
401 extern OCTAVE_API FloatMatrix min (const FloatMatrix& a, const FloatMatrix& b);
402 
403 extern OCTAVE_API FloatMatrix max (float d, const FloatMatrix& m);
404 extern OCTAVE_API FloatMatrix max (const FloatMatrix& m, float d);
405 extern OCTAVE_API FloatMatrix max (const FloatMatrix& a, const FloatMatrix& b);
406 
407 extern OCTAVE_API FloatMatrix linspace (const FloatColumnVector& x1,
408  const FloatColumnVector& x2,
409  octave_idx_type n);
410 
411 
412 MS_CMP_OP_DECLS (FloatMatrix, float, OCTAVE_API)
413 MS_BOOL_OP_DECLS (FloatMatrix, float, OCTAVE_API)
414 
415 SM_CMP_OP_DECLS (float, FloatMatrix, OCTAVE_API)
416 SM_BOOL_OP_DECLS (float, FloatMatrix, OCTAVE_API)
417 
418 MM_CMP_OP_DECLS (FloatMatrix, FloatMatrix, OCTAVE_API)
419 MM_BOOL_OP_DECLS (FloatMatrix, FloatMatrix, OCTAVE_API)
420 
421 MARRAY_FORWARD_DEFS (MArray, FloatMatrix, float)
422 
423 template <class T>
424 void read_int (std::istream& is, bool swap_bytes, T& val);
425 
426 #endif