458
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
458
|
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 2, or (at your option) any |
|
10 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, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_Matrix_int_h) |
|
24 #define octave_Matrix_int_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
27 #pragma interface |
|
28 #endif |
|
29 |
1989
|
30 #include "MArray2.h" |
|
31 #include "MDiagArray2.h" |
458
|
32 |
|
33 #include "mx-defs.h" |
2870
|
34 #include "mx-op-defs.h" |
458
|
35 |
3585
|
36 class |
|
37 Matrix : public MArray2<double> |
458
|
38 { |
|
39 public: |
|
40 |
3480
|
41 typedef void (*solve_singularity_handler) (double rcond); |
|
42 |
1214
|
43 Matrix (void) : MArray2<double> () { } |
3585
|
44 |
1214
|
45 Matrix (int r, int c) : MArray2<double> (r, c) { } |
3585
|
46 |
1214
|
47 Matrix (int r, int c, double val) : MArray2<double> (r, c, val) { } |
3585
|
48 |
1214
|
49 Matrix (const Matrix& a) : MArray2<double> (a) { } |
3585
|
50 |
|
51 Matrix (const MArray2<double>& a) : MArray2<double> (a) { } |
|
52 |
|
53 explicit Matrix (const RowVector& rv); |
458
|
54 |
3585
|
55 explicit Matrix (const ColumnVector& cv); |
|
56 |
|
57 explicit Matrix (const DiagMatrix& a); |
|
58 |
|
59 explicit Matrix (const boolMatrix& a); |
|
60 |
|
61 explicit Matrix (const charMatrix& a); |
1574
|
62 |
458
|
63 Matrix& operator = (const Matrix& a) |
|
64 { |
1214
|
65 MArray2<double>::operator = (a); |
458
|
66 return *this; |
|
67 } |
|
68 |
2385
|
69 bool operator == (const Matrix& a) const; |
|
70 bool operator != (const Matrix& a) const; |
458
|
71 |
3354
|
72 bool is_symmetric (void) const; |
|
73 |
1359
|
74 // destructive insert/delete/reorder operations |
458
|
75 |
|
76 Matrix& insert (const Matrix& a, int r, int c); |
|
77 Matrix& insert (const RowVector& a, int r, int c); |
|
78 Matrix& insert (const ColumnVector& a, int r, int c); |
|
79 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
80 |
|
81 Matrix& fill (double val); |
|
82 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
83 |
|
84 Matrix append (const Matrix& a) const; |
|
85 Matrix append (const RowVector& a) const; |
|
86 Matrix append (const ColumnVector& a) const; |
|
87 Matrix append (const DiagMatrix& a) const; |
|
88 |
|
89 Matrix stack (const Matrix& a) const; |
|
90 Matrix stack (const RowVector& a) const; |
|
91 Matrix stack (const ColumnVector& a) const; |
|
92 Matrix stack (const DiagMatrix& a) const; |
|
93 |
1205
|
94 friend Matrix real (const ComplexMatrix& a); |
|
95 friend Matrix imag (const ComplexMatrix& a); |
|
96 |
3225
|
97 Matrix transpose (void) const { return MArray2<double>::transpose (); } |
|
98 |
1359
|
99 // resize is the destructive equivalent for this one |
458
|
100 |
|
101 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
102 |
4316
|
103 Matrix extract_n (int r1, int c1, int nr, int nc) const; |
|
104 |
1359
|
105 // extract row or column i. |
458
|
106 |
|
107 RowVector row (int i) const; |
|
108 RowVector row (char *s) const; |
|
109 |
|
110 ColumnVector column (int i) const; |
|
111 ColumnVector column (char *s) const; |
|
112 |
|
113 Matrix inverse (void) const; |
|
114 Matrix inverse (int& info) const; |
4329
|
115 Matrix inverse (int& info, double& rcond, int force = 0, |
|
116 int calc_cond = 1) const; |
458
|
117 |
4384
|
118 Matrix pseudo_inverse (double tol = 0.0) const; |
740
|
119 |
458
|
120 ComplexMatrix fourier (void) const; |
|
121 ComplexMatrix ifourier (void) const; |
|
122 |
677
|
123 ComplexMatrix fourier2d (void) const; |
|
124 ComplexMatrix ifourier2d (void) const; |
|
125 |
458
|
126 DET determinant (void) const; |
|
127 DET determinant (int& info) const; |
4329
|
128 DET determinant (int& info, double& rcond, int calc_cond = 1) const; |
458
|
129 |
|
130 Matrix solve (const Matrix& b) const; |
|
131 Matrix solve (const Matrix& b, int& info) const; |
|
132 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
3480
|
133 Matrix solve (const Matrix& b, int& info, double& rcond, |
|
134 solve_singularity_handler sing_handler) const; |
458
|
135 |
|
136 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
137 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
138 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
3480
|
139 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond, |
|
140 solve_singularity_handler sing_handler) const; |
458
|
141 |
|
142 ColumnVector solve (const ColumnVector& b) const; |
|
143 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
144 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
3480
|
145 ColumnVector solve (const ColumnVector& b, int& info, double& rcond, |
|
146 solve_singularity_handler sing_handler) const; |
458
|
147 |
|
148 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
149 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
150 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
151 double& rcond) const; |
3480
|
152 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
153 double& rcond, |
|
154 solve_singularity_handler sing_handler) const; |
458
|
155 |
|
156 Matrix lssolve (const Matrix& b) const; |
|
157 Matrix lssolve (const Matrix& b, int& info) const; |
|
158 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
159 |
|
160 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
161 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
162 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
163 int& rank) const; |
|
164 |
|
165 ColumnVector lssolve (const ColumnVector& b) const; |
|
166 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
167 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
168 |
|
169 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
170 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
171 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
172 int& rank) const; |
|
173 |
1819
|
174 Matrix expm (void) const; |
|
175 |
458
|
176 Matrix& operator += (const DiagMatrix& a); |
|
177 Matrix& operator -= (const DiagMatrix& a); |
|
178 |
1359
|
179 // unary operations |
458
|
180 |
2964
|
181 boolMatrix operator ! (void) const; |
458
|
182 |
1359
|
183 // column vector by row vector -> matrix operations |
458
|
184 |
2385
|
185 friend Matrix operator * (const ColumnVector& a, const RowVector& b); |
458
|
186 |
1359
|
187 // other operations |
458
|
188 |
2676
|
189 Matrix map (d_d_Mapper f) const; |
3248
|
190 boolMatrix map (b_d_Mapper f) const; |
2676
|
191 |
|
192 Matrix& apply (d_d_Mapper f); |
458
|
193 |
4431
|
194 bool any_element_is_negative (bool = false) const; |
2385
|
195 bool any_element_is_inf_or_nan (void) const; |
|
196 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
197 bool all_integers (double& max_val, double& min_val) const; |
|
198 bool too_large_for_float (void) const; |
1963
|
199 |
4017
|
200 boolMatrix all (int dim = -1) const; |
|
201 boolMatrix any (int dim = -1) const; |
458
|
202 |
4017
|
203 Matrix cumprod (int dim = -1) const; |
|
204 Matrix cumsum (int dim = -1) const; |
|
205 Matrix prod (int dim = -1) const; |
|
206 Matrix sum (int dim = -1) const; |
|
207 Matrix sumsq (int dim = -1) const; |
2385
|
208 Matrix abs (void) const; |
458
|
209 |
|
210 ColumnVector diag (void) const; |
|
211 ColumnVector diag (int k) const; |
|
212 |
|
213 ColumnVector row_min (void) const; |
2354
|
214 ColumnVector row_max (void) const; |
458
|
215 |
2354
|
216 ColumnVector row_min (Array<int>& index) const; |
|
217 ColumnVector row_max (Array<int>& index) const; |
458
|
218 |
|
219 RowVector column_min (void) const; |
2354
|
220 RowVector column_max (void) const; |
458
|
221 |
2354
|
222 RowVector column_min (Array<int>& index) const; |
|
223 RowVector column_max (Array<int>& index) const; |
458
|
224 |
1359
|
225 // i/o |
458
|
226 |
3504
|
227 friend std::ostream& operator << (std::ostream& os, const Matrix& a); |
|
228 friend std::istream& operator >> (std::istream& is, Matrix& a); |
458
|
229 |
3933
|
230 static double resize_fill_value (void) { return 0; } |
|
231 |
458
|
232 private: |
|
233 |
1214
|
234 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
235 }; |
|
236 |
1959
|
237 extern Matrix Givens (double, double); |
1819
|
238 |
1959
|
239 extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
|
240 |
2828
|
241 extern Matrix operator * (const Matrix& a, const Matrix& b); |
|
242 |
4309
|
243 extern Matrix min (double d, const Matrix& m); |
|
244 extern Matrix min (const Matrix& m, double d); |
|
245 extern Matrix min (const Matrix& a, const Matrix& b); |
|
246 |
|
247 extern Matrix max (double d, const Matrix& m); |
|
248 extern Matrix max (const Matrix& m, double d); |
|
249 extern Matrix max (const Matrix& a, const Matrix& b); |
|
250 |
2870
|
251 MS_CMP_OP_DECLS (Matrix, double) |
|
252 MS_BOOL_OP_DECLS (Matrix, double) |
|
253 |
|
254 SM_CMP_OP_DECLS (double, Matrix) |
|
255 SM_BOOL_OP_DECLS (double, Matrix) |
|
256 |
|
257 MM_CMP_OP_DECLS (Matrix, Matrix) |
|
258 MM_BOOL_OP_DECLS (Matrix, Matrix) |
|
259 |
3573
|
260 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
|
261 |
3689
|
262 template <class T> |
|
263 void read_int (std::istream& is, bool swap_bytes, T& val); |
|
264 |
458
|
265 #endif |
|
266 |
|
267 /* |
|
268 ;;; Local Variables: *** |
|
269 ;;; mode: C++ *** |
|
270 ;;; End: *** |
|
271 */ |