Mercurial > hg > octave-lyh
comparison liboctave/CSparse.h @ 5164:57077d0ddc8e
[project @ 2005-02-25 19:55:24 by jwe]
author | jwe |
---|---|
date | Fri, 25 Feb 2005 19:55:28 +0000 |
parents | |
children | 23b37da9fd5b |
comparison
equal
deleted
inserted
replaced
5163:9f3299378193 | 5164:57077d0ddc8e |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2004 David Bateman | |
4 Copyright (C) 1998-2004 Andy Adler | |
5 | |
6 Octave is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) any | |
9 later version. | |
10 | |
11 Octave is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; see the file COPYING. If not, write to the Free | |
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | |
20 */ | |
21 | |
22 #if !defined (octave_CSparse_h) | |
23 #define octave_CSparse_h 1 | |
24 | |
25 #include "dMatrix.h" | |
26 #include "dNDArray.h" | |
27 #include "CNDArray.h" | |
28 #include "dColVector.h" | |
29 #include "CColVector.h" | |
30 #include "oct-cmplx.h" | |
31 | |
32 #include "CmplxDET.h" | |
33 #include "MSparse.h" | |
34 #include "MSparse-defs.h" | |
35 #include "Sparse-op-defs.h" | |
36 #include "SparseType.h" | |
37 | |
38 class SparseMatrix; | |
39 class SparseBoolMatrix; | |
40 | |
41 class | |
42 SparseComplexMatrix : public MSparse<Complex> | |
43 { | |
44 public: | |
45 | |
46 typedef void (*solve_singularity_handler) (double rcond); | |
47 | |
48 SparseComplexMatrix (void) : MSparse<Complex> () { } | |
49 | |
50 SparseComplexMatrix (int r, int c) : MSparse<Complex> (r, c) { } | |
51 | |
52 explicit SparseComplexMatrix (int r, int c, Complex val) | |
53 : MSparse<Complex> (r, c, val) { } | |
54 | |
55 SparseComplexMatrix (int r, int c, double val) | |
56 : MSparse<Complex> (r, c, Complex (val)) { } | |
57 | |
58 SparseComplexMatrix (const SparseComplexMatrix& a) | |
59 : MSparse<Complex> (a) { } | |
60 | |
61 SparseComplexMatrix (const SparseComplexMatrix& a, const dim_vector& dv) | |
62 : MSparse<Complex> (a, dv) { } | |
63 | |
64 SparseComplexMatrix (const MSparse<Complex>& a) : MSparse<Complex> (a) { } | |
65 | |
66 explicit SparseComplexMatrix (const ComplexMatrix& a) | |
67 : MSparse<Complex> (a) { } | |
68 | |
69 explicit SparseComplexMatrix (const ComplexNDArray& a) | |
70 : MSparse<Complex> (a) { } | |
71 | |
72 explicit SparseComplexMatrix (const Array<Complex> a, const Array<int>& r, | |
73 const Array<int>& c, int nr = -1, | |
74 int nc = -1, bool sum_terms = true) | |
75 : MSparse<Complex> (a, r, c, nr, nc, sum_terms) { } | |
76 | |
77 explicit SparseComplexMatrix (const Array<Complex> a, | |
78 const Array<double>& r, | |
79 const Array<double>& c, int nr = -1, | |
80 int nc = -1, bool sum_terms = true) | |
81 : MSparse<Complex> (a, r, c, nr, nc, sum_terms) { } | |
82 | |
83 explicit SparseComplexMatrix (const SparseMatrix& a); | |
84 | |
85 explicit SparseComplexMatrix (const SparseBoolMatrix& a); | |
86 | |
87 SparseComplexMatrix (int r, int c, int num_nz) | |
88 : MSparse<Complex> (r, c, num_nz) { } | |
89 | |
90 SparseComplexMatrix& operator = (const SparseComplexMatrix& a) | |
91 { | |
92 MSparse<Complex>::operator = (a); | |
93 return *this; | |
94 } | |
95 | |
96 bool operator == (const SparseComplexMatrix& a) const; | |
97 bool operator != (const SparseComplexMatrix& a) const; | |
98 | |
99 bool is_hermitian (void) const; | |
100 | |
101 SparseComplexMatrix max (int dim = 0) const; | |
102 SparseComplexMatrix max (Array2<int>& index, int dim = 0) const; | |
103 SparseComplexMatrix min (int dim = 0) const; | |
104 SparseComplexMatrix min (Array2<int>& index, int dim = 0) const; | |
105 | |
106 SparseComplexMatrix& insert (const SparseComplexMatrix& a, int r, int c); | |
107 SparseComplexMatrix& insert (const SparseMatrix& a, int r, int c); | |
108 | |
109 SparseComplexMatrix concat (const SparseComplexMatrix& rb, | |
110 const Array<int>& ra_idx); | |
111 SparseComplexMatrix concat (const SparseMatrix& rb, | |
112 const Array<int>& ra_idx); | |
113 | |
114 ComplexMatrix matrix_value (void) const; | |
115 | |
116 SparseComplexMatrix hermitian (void) const; // complex conjugate transpose | |
117 SparseComplexMatrix transpose (void) const | |
118 { return MSparse<Complex>::transpose (); } | |
119 | |
120 friend SparseComplexMatrix conj (const SparseComplexMatrix& a); | |
121 | |
122 SparseComplexMatrix inverse (void) const; | |
123 SparseComplexMatrix inverse (int& info) const; | |
124 SparseComplexMatrix inverse (int& info, double& rcond, int force = 0, | |
125 int calc_cond = 1) const; | |
126 | |
127 ComplexDET determinant (void) const; | |
128 ComplexDET determinant (int& info) const; | |
129 ComplexDET determinant (int& info, double& rcond, | |
130 int calc_cond = 1) const; | |
131 | |
132 private: | |
133 // Diagonal matrix solvers | |
134 ComplexMatrix dsolve (SparseType &typ, const Matrix& b, int& info, | |
135 double& rcond, solve_singularity_handler sing_handler) const; | |
136 | |
137 ComplexMatrix dsolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
138 double& rcond, solve_singularity_handler sing_handler) const; | |
139 | |
140 SparseComplexMatrix dsolve (SparseType &typ, const SparseMatrix& b, int& info, | |
141 double& rcond, solve_singularity_handler sing_handler) const; | |
142 | |
143 SparseComplexMatrix dsolve (SparseType &typ, const SparseComplexMatrix& b, | |
144 int& info, double& rcond, | |
145 solve_singularity_handler sing_handler) const; | |
146 | |
147 // Upper triangular matrix solvers | |
148 ComplexMatrix utsolve (SparseType &typ, const Matrix& b, int& info, | |
149 double& rcond, solve_singularity_handler sing_handler) const; | |
150 | |
151 ComplexMatrix utsolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
152 double& rcond, solve_singularity_handler sing_handler) const; | |
153 | |
154 SparseComplexMatrix utsolve (SparseType &typ, const SparseMatrix& b, int& info, | |
155 double& rcond, solve_singularity_handler sing_handler) const; | |
156 | |
157 SparseComplexMatrix utsolve (SparseType &typ, const SparseComplexMatrix& b, | |
158 int& info, double& rcond, | |
159 solve_singularity_handler sing_handler) const; | |
160 | |
161 // Lower triangular matrix solvers | |
162 ComplexMatrix ltsolve (SparseType &typ, const Matrix& b, int& info, | |
163 double& rcond, solve_singularity_handler sing_handler) const; | |
164 | |
165 ComplexMatrix ltsolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
166 double& rcond, solve_singularity_handler sing_handler) const; | |
167 | |
168 SparseComplexMatrix ltsolve (SparseType &typ, const SparseMatrix& b, int& info, | |
169 double& rcond, solve_singularity_handler sing_handler) const; | |
170 | |
171 SparseComplexMatrix ltsolve (SparseType &typ, const SparseComplexMatrix& b, | |
172 int& info, double& rcond, | |
173 solve_singularity_handler sing_handler) const; | |
174 | |
175 // Tridiagonal matrix solvers | |
176 ComplexMatrix trisolve (SparseType &typ, const Matrix& b, int& info, | |
177 double& rcond, solve_singularity_handler sing_handler) const; | |
178 | |
179 ComplexMatrix trisolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
180 double& rcond, solve_singularity_handler sing_handler) const; | |
181 | |
182 SparseComplexMatrix trisolve (SparseType &typ, const SparseMatrix& b, int& info, | |
183 double& rcond, solve_singularity_handler sing_handler) const; | |
184 | |
185 SparseComplexMatrix trisolve (SparseType &typ, const SparseComplexMatrix& b, | |
186 int& info, double& rcond, | |
187 solve_singularity_handler sing_handler) const; | |
188 | |
189 // Banded matrix solvers (umfpack/cholesky) | |
190 ComplexMatrix bsolve (SparseType &typ, const Matrix& b, int& info, | |
191 double& rcond, solve_singularity_handler sing_handler) const; | |
192 | |
193 ComplexMatrix bsolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
194 double& rcond, solve_singularity_handler sing_handler) const; | |
195 | |
196 SparseComplexMatrix bsolve (SparseType &typ, const SparseMatrix& b, int& info, | |
197 double& rcond, solve_singularity_handler sing_handler) const; | |
198 | |
199 SparseComplexMatrix bsolve (SparseType &typ, const SparseComplexMatrix& b, | |
200 int& info, double& rcond, | |
201 solve_singularity_handler sing_handler) const; | |
202 | |
203 // Full matrix solvers (umfpack/cholesky) | |
204 void * factorize (int& err, double &rcond, Matrix &Control, Matrix &Info, | |
205 solve_singularity_handler sing_handler) const; | |
206 | |
207 ComplexMatrix fsolve (SparseType &typ, const Matrix& b, int& info, | |
208 double& rcond, solve_singularity_handler sing_handler) const; | |
209 | |
210 ComplexMatrix fsolve (SparseType &typ, const ComplexMatrix& b, int& info, | |
211 double& rcond, solve_singularity_handler sing_handler) const; | |
212 | |
213 SparseComplexMatrix fsolve (SparseType &typ, const SparseMatrix& b, int& info, | |
214 double& rcond, solve_singularity_handler sing_handler) const; | |
215 | |
216 SparseComplexMatrix fsolve (SparseType &typ, const SparseComplexMatrix& b, | |
217 int& info, double& rcond, | |
218 solve_singularity_handler sing_handler) const; | |
219 | |
220 public: | |
221 // Generic interface to solver with no probing of type | |
222 ComplexMatrix solve (SparseType &typ, const Matrix& b) const; | |
223 ComplexMatrix solve (SparseType &typ, const Matrix& b, int& info) const; | |
224 ComplexMatrix solve (SparseType &typ, const Matrix& b, int& info, | |
225 double& rcond) const; | |
226 ComplexMatrix solve (SparseType &typ, const Matrix& b, int& info, | |
227 double& rcond, solve_singularity_handler sing_handler) const; | |
228 | |
229 ComplexMatrix solve (SparseType &typ, const ComplexMatrix& b) const; | |
230 ComplexMatrix solve (SparseType &typ, const ComplexMatrix& b, | |
231 int& info) const; | |
232 ComplexMatrix solve (SparseType &typ, const ComplexMatrix& b, int& info, | |
233 double& rcond) const; | |
234 ComplexMatrix solve (SparseType &typ, const ComplexMatrix& b, int& info, | |
235 double& rcond, solve_singularity_handler sing_handler) const; | |
236 | |
237 SparseComplexMatrix solve (SparseType &typ, const SparseMatrix& b) const; | |
238 SparseComplexMatrix solve (SparseType &typ, const SparseMatrix& b, | |
239 int& info) const; | |
240 SparseComplexMatrix solve (SparseType &typ, const SparseMatrix& b, int& info, | |
241 double& rcond) const; | |
242 SparseComplexMatrix solve (SparseType &typ, const SparseMatrix& b, int& info, | |
243 double& rcond, solve_singularity_handler sing_handler) const; | |
244 | |
245 SparseComplexMatrix solve (SparseType &typ, | |
246 const SparseComplexMatrix& b) const; | |
247 SparseComplexMatrix solve (SparseType &typ, const SparseComplexMatrix& b, | |
248 int& info) const; | |
249 SparseComplexMatrix solve (SparseType &typ, const SparseComplexMatrix& b, | |
250 int& info, double& rcond) const; | |
251 SparseComplexMatrix solve (SparseType &typ, const SparseComplexMatrix& b, int& info, | |
252 double& rcond, solve_singularity_handler sing_handler) const; | |
253 | |
254 ComplexColumnVector solve (SparseType &typ, const ColumnVector& b) const; | |
255 ComplexColumnVector solve (SparseType &typ, const ColumnVector& b, | |
256 int& info) const; | |
257 ComplexColumnVector solve (SparseType &typ, const ColumnVector& b, | |
258 int& info, double& rcond) const; | |
259 ComplexColumnVector solve (SparseType &typ, const ColumnVector& b, int& info, | |
260 double& rcond, solve_singularity_handler sing_handler) const; | |
261 | |
262 ComplexColumnVector solve (SparseType &typ, | |
263 const ComplexColumnVector& b) const; | |
264 ComplexColumnVector solve (SparseType &typ, | |
265 const ComplexColumnVector& b, int& info) const; | |
266 ComplexColumnVector solve (SparseType &typ, const ComplexColumnVector& b, | |
267 int& info, double& rcond) const; | |
268 ComplexColumnVector solve (SparseType &typ, const ComplexColumnVector& b, | |
269 int& info, double& rcond, | |
270 solve_singularity_handler sing_handler) const; | |
271 | |
272 // Generic interface to solver with probing of type | |
273 ComplexMatrix solve (const Matrix& b) const; | |
274 ComplexMatrix solve (const Matrix& b, int& info) const; | |
275 ComplexMatrix solve (const Matrix& b, int& info, double& rcond) const; | |
276 ComplexMatrix solve (const Matrix& b, int& info, double& rcond, | |
277 solve_singularity_handler sing_handler) const; | |
278 | |
279 ComplexMatrix solve (const ComplexMatrix& b) const; | |
280 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; | |
281 ComplexMatrix solve (const ComplexMatrix& b, int& info, | |
282 double& rcond) const; | |
283 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond, | |
284 solve_singularity_handler sing_handler) const; | |
285 | |
286 SparseComplexMatrix solve (const SparseMatrix& b) const; | |
287 SparseComplexMatrix solve (const SparseMatrix& b, int& info) const; | |
288 SparseComplexMatrix solve (const SparseMatrix& b, int& info, | |
289 double& rcond) const; | |
290 SparseComplexMatrix solve (const SparseMatrix& b, int& info, | |
291 double& rcond, | |
292 solve_singularity_handler sing_handler) const; | |
293 | |
294 SparseComplexMatrix solve (const SparseComplexMatrix& b) const; | |
295 SparseComplexMatrix solve (const SparseComplexMatrix& b, int& info) const; | |
296 SparseComplexMatrix solve (const SparseComplexMatrix& b, int& info, | |
297 double& rcond) const; | |
298 SparseComplexMatrix solve (const SparseComplexMatrix& b, int& info, | |
299 double& rcond, | |
300 solve_singularity_handler sing_handler) const; | |
301 | |
302 ComplexColumnVector solve (const ColumnVector& b) const; | |
303 ComplexColumnVector solve (const ColumnVector& b, int& info) const; | |
304 ComplexColumnVector solve (const ColumnVector& b, int& info, | |
305 double& rcond) const; | |
306 ComplexColumnVector solve (const ColumnVector& b, int& info, double& rcond, | |
307 solve_singularity_handler sing_handler) const; | |
308 | |
309 ComplexColumnVector solve (const ComplexColumnVector& b) const; | |
310 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; | |
311 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, | |
312 double& rcond) const; | |
313 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, | |
314 double& rcond, | |
315 solve_singularity_handler sing_handler) const; | |
316 | |
317 ComplexMatrix lssolve (const Matrix& b) const; | |
318 ComplexMatrix lssolve (const Matrix& b, int& info) const; | |
319 ComplexMatrix lssolve (const Matrix& b, int& info, int& rank) const; | |
320 | |
321 ComplexMatrix lssolve (const ComplexMatrix& b) const; | |
322 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; | |
323 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, | |
324 int& rank) const; | |
325 | |
326 SparseComplexMatrix lssolve (const SparseMatrix& b) const; | |
327 SparseComplexMatrix lssolve (const SparseMatrix& b, int& info) const; | |
328 SparseComplexMatrix lssolve (const SparseMatrix& b, int& info, | |
329 int& rank) const; | |
330 | |
331 SparseComplexMatrix lssolve (const SparseComplexMatrix& b) const; | |
332 SparseComplexMatrix lssolve (const SparseComplexMatrix& b, | |
333 int& info) const; | |
334 SparseComplexMatrix lssolve (const SparseComplexMatrix& b, int& info, | |
335 int& rank) const; | |
336 | |
337 ComplexColumnVector lssolve (const ColumnVector& b) const; | |
338 ComplexColumnVector lssolve (const ColumnVector& b, int& info) const; | |
339 ComplexColumnVector lssolve (const ColumnVector& b, int& info, | |
340 int& rank) const; | |
341 | |
342 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; | |
343 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; | |
344 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, | |
345 int& rank) const; | |
346 | |
347 SparseComplexMatrix squeeze (void) const; | |
348 | |
349 SparseComplexMatrix index (idx_vector& i, int resize_ok) const; | |
350 | |
351 SparseComplexMatrix index (idx_vector& i, idx_vector& j, int resize_ok) const; | |
352 | |
353 SparseComplexMatrix index (Array<idx_vector>& ra_idx, int resize_ok) const; | |
354 | |
355 SparseComplexMatrix reshape (const dim_vector& new_dims) const; | |
356 | |
357 SparseComplexMatrix permute (const Array<int>& vec, bool inv = false) const; | |
358 | |
359 SparseComplexMatrix ipermute (const Array<int>& vec) const; | |
360 | |
361 SparseComplexMatrix map (c_c_Mapper f) const; | |
362 SparseMatrix map (d_c_Mapper f) const; | |
363 SparseBoolMatrix map (b_c_Mapper f) const; | |
364 | |
365 SparseComplexMatrix& apply (c_c_Mapper f); | |
366 | |
367 bool any_element_is_inf_or_nan (void) const; | |
368 bool all_elements_are_real (void) const; | |
369 bool all_integers (double& max_val, double& min_val) const; | |
370 bool too_large_for_float (void) const; | |
371 | |
372 SparseBoolMatrix operator ! (void) const; | |
373 | |
374 SparseBoolMatrix all (int dim = -1) const; | |
375 SparseBoolMatrix any (int dim = -1) const; | |
376 | |
377 SparseComplexMatrix cumprod (int dim = -1) const; | |
378 SparseComplexMatrix cumsum (int dim = -1) const; | |
379 SparseComplexMatrix prod (int dim = -1) const; | |
380 SparseComplexMatrix sum (int dim = -1) const; | |
381 SparseComplexMatrix sumsq (int dim = -1) const; | |
382 SparseMatrix abs (void) const; | |
383 | |
384 SparseComplexMatrix diag (int k = 0) const; | |
385 | |
386 // i/o | |
387 friend std::ostream& operator << (std::ostream& os, | |
388 const SparseComplexMatrix& a); | |
389 friend std::istream& operator >> (std::istream& is, | |
390 SparseComplexMatrix& a); | |
391 }; | |
392 | |
393 extern SparseComplexMatrix operator * (const SparseMatrix&, | |
394 const SparseComplexMatrix&); | |
395 extern SparseComplexMatrix operator * (const SparseComplexMatrix&, | |
396 const SparseMatrix&); | |
397 extern SparseComplexMatrix operator * (const SparseComplexMatrix&, | |
398 const SparseComplexMatrix&); | |
399 | |
400 extern SparseComplexMatrix min (const Complex& c, | |
401 const SparseComplexMatrix& m); | |
402 extern SparseComplexMatrix min (const SparseComplexMatrix& m, | |
403 const Complex& c); | |
404 extern SparseComplexMatrix min (const SparseComplexMatrix& a, | |
405 const SparseComplexMatrix& b); | |
406 | |
407 extern SparseComplexMatrix max (const Complex& c, | |
408 const SparseComplexMatrix& m); | |
409 extern SparseComplexMatrix max (const SparseComplexMatrix& m, | |
410 const Complex& c); | |
411 extern SparseComplexMatrix max (const SparseComplexMatrix& a, | |
412 const SparseComplexMatrix& b); | |
413 | |
414 SPARSE_SMS_CMP_OP_DECLS (SparseComplexMatrix, Complex) | |
415 SPARSE_SMS_BOOL_OP_DECLS (SparseComplexMatrix, Complex) | |
416 | |
417 SPARSE_SSM_CMP_OP_DECLS (Complex, SparseComplexMatrix) | |
418 SPARSE_SSM_BOOL_OP_DECLS (Complex, SparseComplexMatrix) | |
419 | |
420 SPARSE_SMSM_CMP_OP_DECLS (SparseComplexMatrix, SparseComplexMatrix) | |
421 SPARSE_SMSM_BOOL_OP_DECLS (SparseComplexMatrix, SparseComplexMatrix) | |
422 | |
423 SPARSE_FORWARD_DEFS (MSparse, SparseComplexMatrix, ComplexMatrix, Complex) | |
424 | |
425 #endif | |
426 | |
427 /* | |
428 ;;; Local Variables: *** | |
429 ;;; mode: C++ *** | |
430 ;;; End: *** | |
431 */ |