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 |
1296
|
26 #if defined (__GNUG__) |
|
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 |
2317
|
36 #include "data-conv.h" |
|
37 #include "mach-info.h" |
|
38 |
3585
|
39 class |
|
40 Matrix : public MArray2<double> |
458
|
41 { |
|
42 public: |
|
43 |
3480
|
44 typedef void (*solve_singularity_handler) (double rcond); |
|
45 |
1214
|
46 Matrix (void) : MArray2<double> () { } |
3585
|
47 |
1214
|
48 Matrix (int r, int c) : MArray2<double> (r, c) { } |
3585
|
49 |
1214
|
50 Matrix (int r, int c, double val) : MArray2<double> (r, c, val) { } |
3585
|
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 |
|
79 Matrix& insert (const Matrix& a, int r, int c); |
|
80 Matrix& insert (const RowVector& a, int r, int c); |
|
81 Matrix& insert (const ColumnVector& a, int r, int c); |
|
82 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
83 |
|
84 Matrix& fill (double val); |
|
85 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
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 |
1205
|
97 friend Matrix real (const ComplexMatrix& a); |
|
98 friend Matrix imag (const ComplexMatrix& a); |
|
99 |
3225
|
100 Matrix transpose (void) const { return MArray2<double>::transpose (); } |
|
101 |
1359
|
102 // resize is the destructive equivalent for this one |
458
|
103 |
|
104 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
105 |
1359
|
106 // extract row or column i. |
458
|
107 |
|
108 RowVector row (int i) const; |
|
109 RowVector row (char *s) const; |
|
110 |
|
111 ColumnVector column (int i) const; |
|
112 ColumnVector column (char *s) const; |
|
113 |
|
114 Matrix inverse (void) const; |
|
115 Matrix inverse (int& info) const; |
1656
|
116 Matrix inverse (int& info, double& rcond, int force = 0) const; |
458
|
117 |
740
|
118 Matrix pseudo_inverse (double tol = 0.0); |
|
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; |
|
128 DET determinant (int& info, double& rcond) const; |
|
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 |
2385
|
194 bool any_element_is_negative (void) const; |
|
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 |
4015
|
200 boolMatrix all (int dim = 0) const; |
|
201 boolMatrix any (int dim = 0) const; |
458
|
202 |
3723
|
203 Matrix cumprod (int dim = 0) const; //optional dimension argument |
|
204 Matrix cumsum (int dim = 0) const; |
|
205 Matrix prod (int dim = 0) const; |
|
206 Matrix sum (int dim = 0) const; |
|
207 Matrix sumsq (int dim = 0) 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 |
3504
|
230 int read (std::istream& is, int nr, int nc, oct_data_conv::data_type dt, |
2317
|
231 int skip, oct_mach_info::float_format flt_fmt); |
|
232 |
3504
|
233 int write (std::ostream& os, oct_data_conv::data_type dt, int skip, |
2317
|
234 oct_mach_info::float_format flt_fmt); |
458
|
235 |
3933
|
236 static double resize_fill_value (void) { return 0; } |
|
237 |
458
|
238 private: |
|
239 |
1214
|
240 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
241 }; |
|
242 |
1959
|
243 extern Matrix Givens (double, double); |
1819
|
244 |
1959
|
245 extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
|
246 |
2828
|
247 extern Matrix operator * (const Matrix& a, const Matrix& b); |
|
248 |
2870
|
249 MS_CMP_OP_DECLS (Matrix, double) |
|
250 MS_BOOL_OP_DECLS (Matrix, double) |
|
251 |
|
252 SM_CMP_OP_DECLS (double, Matrix) |
|
253 SM_BOOL_OP_DECLS (double, Matrix) |
|
254 |
|
255 MM_CMP_OP_DECLS (Matrix, Matrix) |
|
256 MM_BOOL_OP_DECLS (Matrix, Matrix) |
|
257 |
3573
|
258 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
|
259 |
3689
|
260 template <class T> |
|
261 void read_int (std::istream& is, bool swap_bytes, T& val); |
|
262 |
458
|
263 #endif |
|
264 |
|
265 /* |
|
266 ;;; Local Variables: *** |
|
267 ;;; mode: C++ *** |
|
268 ;;; End: *** |
|
269 */ |