00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_Matrix_int_h)
00025 #define octave_Matrix_int_h 1
00026
00027 #include "MArray2.h"
00028 #include "MDiagArray2.h"
00029 #include "MatrixType.h"
00030
00031 #include "mx-defs.h"
00032 #include "mx-op-decl.h"
00033 #include "DET.h"
00034
00035 class
00036 OCTAVE_API
00037 Matrix : public MArray2<double>
00038 {
00039 public:
00040
00041 typedef ColumnVector column_vector_type;
00042 typedef RowVector row_vector_type;
00043
00044 typedef void (*solve_singularity_handler) (double rcon);
00045
00046 Matrix (void) : MArray2<double> () { }
00047
00048 Matrix (octave_idx_type r, octave_idx_type c) : MArray2<double> (r, c) { }
00049
00050 Matrix (octave_idx_type r, octave_idx_type c, double val) : MArray2<double> (r, c, val) { }
00051
00052 Matrix (const dim_vector& dv) : MArray2<double> (dv) { }
00053
00054 Matrix (const dim_vector& dv, double val) : MArray2<double> (dv, val) { }
00055
00056 Matrix (const Matrix& a) : MArray2<double> (a) { }
00057
00058 template <class U>
00059 Matrix (const MArray2<U>& a) : MArray2<double> (a) { }
00060
00061 template <class U>
00062 Matrix (const Array2<U>& a) : MArray2<double> (a) { }
00063
00064 explicit Matrix (const RowVector& rv);
00065
00066 explicit Matrix (const ColumnVector& cv);
00067
00068 explicit Matrix (const DiagMatrix& a);
00069
00070 explicit Matrix (const PermMatrix& a);
00071
00072 explicit Matrix (const boolMatrix& a);
00073
00074 explicit Matrix (const charMatrix& a);
00075
00076 Matrix& operator = (const Matrix& a)
00077 {
00078 MArray2<double>::operator = (a);
00079 return *this;
00080 }
00081
00082 bool operator == (const Matrix& a) const;
00083 bool operator != (const Matrix& a) const;
00084
00085 bool is_symmetric (void) const;
00086
00087
00088
00089 Matrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c);
00090 Matrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c);
00091 Matrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c);
00092 Matrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c);
00093
00094 Matrix& fill (double val);
00095 Matrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2);
00096
00097 Matrix append (const Matrix& a) const;
00098 Matrix append (const RowVector& a) const;
00099 Matrix append (const ColumnVector& a) const;
00100 Matrix append (const DiagMatrix& a) const;
00101
00102 Matrix stack (const Matrix& a) const;
00103 Matrix stack (const RowVector& a) const;
00104 Matrix stack (const ColumnVector& a) const;
00105 Matrix stack (const DiagMatrix& a) const;
00106
00107 friend OCTAVE_API Matrix real (const ComplexMatrix& a);
00108 friend OCTAVE_API Matrix imag (const ComplexMatrix& a);
00109
00110 friend class ComplexMatrix;
00111
00112 Matrix transpose (void) const { return MArray2<double>::transpose (); }
00113
00114
00115
00116 Matrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const;
00117
00118 Matrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const;
00119
00120
00121
00122 RowVector row (octave_idx_type i) const;
00123
00124 ColumnVector column (octave_idx_type i) const;
00125
00126 private:
00127 Matrix tinverse (MatrixType &mattype, octave_idx_type& info, double& rcon,
00128 int force, int calc_cond) const;
00129
00130 Matrix finverse (MatrixType &mattype, octave_idx_type& info, double& rcon,
00131 int force, int calc_cond) const;
00132
00133 public:
00134 Matrix inverse (void) const;
00135 Matrix inverse (octave_idx_type& info) const;
00136 Matrix inverse (octave_idx_type& info, double& rcon, int force = 0,
00137 int calc_cond = 1) const;
00138
00139 Matrix inverse (MatrixType &mattype) const;
00140 Matrix inverse (MatrixType &mattype, octave_idx_type& info) const;
00141 Matrix inverse (MatrixType &mattype, octave_idx_type& info, double& rcon,
00142 int force = 0, int calc_cond = 1) const;
00143
00144 Matrix pseudo_inverse (double tol = 0.0) const;
00145
00146 ComplexMatrix fourier (void) const;
00147 ComplexMatrix ifourier (void) const;
00148
00149 ComplexMatrix fourier2d (void) const;
00150 ComplexMatrix ifourier2d (void) const;
00151
00152 DET determinant (void) const;
00153 DET determinant (octave_idx_type& info) const;
00154 DET determinant (octave_idx_type& info, double& rcon, int calc_cond = 1) const;
00155 DET determinant (MatrixType &mattype, octave_idx_type& info,
00156 double& rcon, int calc_cond = 1) const;
00157
00158 double rcond (void) const;
00159 double rcond (MatrixType &mattype) const;
00160
00161 private:
00162
00163 Matrix utsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00164 double& rcon, solve_singularity_handler sing_handler,
00165 bool calc_cond = false, blas_trans_type transt = blas_no_trans) const;
00166
00167
00168 Matrix ltsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00169 double& rcon, solve_singularity_handler sing_handler,
00170 bool calc_cond = false, blas_trans_type transt = blas_no_trans) const;
00171
00172
00173 Matrix fsolve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00174 double& rcon, solve_singularity_handler sing_handler,
00175 bool calc_cond = false) const;
00176
00177 public:
00178
00179 Matrix solve (MatrixType &typ, const Matrix& b) const;
00180 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info) const;
00181 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00182 double& rcon) const;
00183 Matrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00184 double& rcon, solve_singularity_handler sing_handler,
00185 bool singular_fallback = true, blas_trans_type transt = blas_no_trans) const;
00186
00187 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const;
00188 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00189 octave_idx_type& info) const;
00190 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00191 octave_idx_type& info, double& rcon) const;
00192 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00193 octave_idx_type& info, double& rcon,
00194 solve_singularity_handler sing_handler,
00195 bool singular_fallback = true,
00196 blas_trans_type transt = blas_no_trans) const;
00197
00198 ColumnVector solve (MatrixType &typ, const ColumnVector& b) const;
00199 ColumnVector solve (MatrixType &typ, const ColumnVector& b,
00200 octave_idx_type& info) const;
00201 ColumnVector solve (MatrixType &typ, const ColumnVector& b,
00202 octave_idx_type& info, double& rcon) const;
00203 ColumnVector solve (MatrixType &typ, const ColumnVector& b,
00204 octave_idx_type& info, double& rcon,
00205 solve_singularity_handler sing_handler,
00206 blas_trans_type transt = blas_no_trans) const;
00207
00208 ComplexColumnVector solve (MatrixType &typ,
00209 const ComplexColumnVector& b) const;
00210 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00211 octave_idx_type& info) const;
00212 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00213 octave_idx_type& info, double& rcon) const;
00214 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00215 octave_idx_type& info, double& rcon,
00216 solve_singularity_handler sing_handler,
00217 blas_trans_type transt = blas_no_trans) const;
00218
00219
00220 Matrix solve (const Matrix& b) const;
00221 Matrix solve (const Matrix& b, octave_idx_type& info) const;
00222 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon) const;
00223 Matrix solve (const Matrix& b, octave_idx_type& info, double& rcon,
00224 solve_singularity_handler sing_handler,
00225 blas_trans_type transt = blas_no_trans) const;
00226
00227 ComplexMatrix solve (const ComplexMatrix& b) const;
00228 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const;
00229 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const;
00230 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon,
00231 solve_singularity_handler sing_handler,
00232 blas_trans_type transt = blas_no_trans) const;
00233
00234 ColumnVector solve (const ColumnVector& b) const;
00235 ColumnVector solve (const ColumnVector& b, octave_idx_type& info) const;
00236 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const;
00237 ColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon,
00238 solve_singularity_handler sing_handler,
00239 blas_trans_type transt = blas_no_trans) const;
00240
00241 ComplexColumnVector solve (const ComplexColumnVector& b) const;
00242 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const;
00243 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info,
00244 double& rcon) const;
00245 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info,
00246 double& rcon, solve_singularity_handler sing_handler,
00247 blas_trans_type transt = blas_no_trans) const;
00248
00249
00250 Matrix lssolve (const Matrix& b) const;
00251 Matrix lssolve (const Matrix& b, octave_idx_type& info) const;
00252 Matrix lssolve (const Matrix& b, octave_idx_type& info,
00253 octave_idx_type& rank) const;
00254 Matrix lssolve (const Matrix& b, octave_idx_type& info,
00255 octave_idx_type& rank, double& rcon) const;
00256
00257 ComplexMatrix lssolve (const ComplexMatrix& b) const;
00258 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const;
00259 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info,
00260 octave_idx_type& rank) const;
00261 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info,
00262 octave_idx_type& rank, double &rcon) const;
00263
00264 ColumnVector lssolve (const ColumnVector& b) const;
00265 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const;
00266 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info,
00267 octave_idx_type& rank) const;
00268 ColumnVector lssolve (const ColumnVector& b, octave_idx_type& info,
00269 octave_idx_type& rank, double& rcon) const;
00270
00271 ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
00272 ComplexColumnVector lssolve (const ComplexColumnVector& b,
00273 octave_idx_type& info) const;
00274 ComplexColumnVector lssolve (const ComplexColumnVector& b,
00275 octave_idx_type& info,
00276 octave_idx_type& rank) const;
00277 ComplexColumnVector lssolve (const ComplexColumnVector& b,
00278 octave_idx_type& info,
00279 octave_idx_type& rank, double& rcon) const;
00280
00281 Matrix& operator += (const DiagMatrix& a);
00282 Matrix& operator -= (const DiagMatrix& a);
00283
00284
00285
00286 boolMatrix operator ! (void) const;
00287
00288
00289
00290 typedef double (*dmapper) (double);
00291 typedef Complex (*cmapper) (const Complex&);
00292 typedef bool (*bmapper) (double);
00293
00294 Matrix map (dmapper fcn) const;
00295 ComplexMatrix map (cmapper fcn) const;
00296 boolMatrix map (bmapper fcn) const;
00297
00298 bool any_element_is_negative (bool = false) const;
00299 bool any_element_is_nan (void) const;
00300 bool any_element_is_inf_or_nan (void) const;
00301 bool any_element_not_one_or_zero (void) const;
00302 bool all_elements_are_int_or_inf_or_nan (void) const;
00303 bool all_integers (double& max_val, double& min_val) const;
00304 bool too_large_for_float (void) const;
00305
00306 boolMatrix all (int dim = -1) const;
00307 boolMatrix any (int dim = -1) const;
00308
00309 Matrix cumprod (int dim = -1) const;
00310 Matrix cumsum (int dim = -1) const;
00311 Matrix prod (int dim = -1) const;
00312 Matrix sum (int dim = -1) const;
00313 Matrix sumsq (int dim = -1) const;
00314 Matrix abs (void) const;
00315
00316 Matrix diag (octave_idx_type k = 0) const;
00317
00318 ColumnVector row_min (void) const;
00319 ColumnVector row_max (void) const;
00320
00321 ColumnVector row_min (Array<octave_idx_type>& index) const;
00322 ColumnVector row_max (Array<octave_idx_type>& index) const;
00323
00324 RowVector column_min (void) const;
00325 RowVector column_max (void) const;
00326
00327 RowVector column_min (Array<octave_idx_type>& index) const;
00328 RowVector column_max (Array<octave_idx_type>& index) const;
00329
00330
00331
00332 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Matrix& a);
00333 friend OCTAVE_API std::istream& operator >> (std::istream& is, Matrix& a);
00334
00335 static double resize_fill_value (void) { return 0; }
00336
00337 private:
00338
00339 Matrix (double *d, octave_idx_type r, octave_idx_type c) : MArray2<double> (d, r, c) { }
00340 };
00341
00342
00343
00344 extern OCTAVE_API Matrix real (const ComplexMatrix& a);
00345 extern OCTAVE_API Matrix imag (const ComplexMatrix& a);
00346
00347
00348
00349 extern OCTAVE_API Matrix operator * (const ColumnVector& a, const RowVector& b);
00350
00351
00352
00353 extern OCTAVE_API Matrix Givens (double, double);
00354
00355 extern OCTAVE_API Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&);
00356
00357 extern OCTAVE_API Matrix xgemm (const Matrix& a, const Matrix& b,
00358 blas_trans_type transa = blas_no_trans,
00359 blas_trans_type transb = blas_no_trans);
00360
00361 extern OCTAVE_API Matrix operator * (const Matrix& a, const Matrix& b);
00362
00363 extern OCTAVE_API Matrix min (double d, const Matrix& m);
00364 extern OCTAVE_API Matrix min (const Matrix& m, double d);
00365 extern OCTAVE_API Matrix min (const Matrix& a, const Matrix& b);
00366
00367 extern OCTAVE_API Matrix max (double d, const Matrix& m);
00368 extern OCTAVE_API Matrix max (const Matrix& m, double d);
00369 extern OCTAVE_API Matrix max (const Matrix& a, const Matrix& b);
00370
00371 extern OCTAVE_API Matrix linspace (const ColumnVector& x1,
00372 const ColumnVector& x2,
00373 octave_idx_type n);
00374
00375 MS_CMP_OP_DECLS (Matrix, double, OCTAVE_API)
00376 MS_BOOL_OP_DECLS (Matrix, double, OCTAVE_API)
00377
00378 SM_CMP_OP_DECLS (double, Matrix, OCTAVE_API)
00379 SM_BOOL_OP_DECLS (double, Matrix, OCTAVE_API)
00380
00381 MM_CMP_OP_DECLS (Matrix, Matrix, OCTAVE_API)
00382 MM_BOOL_OP_DECLS (Matrix, Matrix, OCTAVE_API)
00383
00384 MARRAY_FORWARD_DEFS (MArray2, Matrix, double)
00385
00386 template <class T>
00387 void read_int (std::istream& is, bool swap_bytes, T& val);
00388
00389 #endif
00390
00391
00392
00393
00394
00395