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