GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
CSparse.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1998-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_CSparse_h)
27#define octave_CSparse_h 1
28
29#include "octave-config.h"
30
31#include "CColVector.h"
32#include "CMatrix.h"
33#include "CNDArray.h"
34#include "DET.h"
35#include "MSparse.h"
36#include "MatrixType.h"
37#include "Sparse-op-decls.h"
38#include "dColVector.h"
39#include "dMatrix.h"
40#include "dNDArray.h"
41#include "oct-cmplx.h"
42#include "mx-fwd.h"
43
44class OCTAVE_API SparseComplexMatrix : public MSparse<Complex>
45{
46public:
47
48 // Corresponding dense matrix type for this sparse matrix type.
50
51 typedef void (*solve_singularity_handler) (double rcond);
52
54
57
59 : MSparse<Complex> (dv, nz) { }
60
62 Complex val)
63 : MSparse<Complex> (r, c, val) { }
64
66 : MSparse<Complex> (r, c, Complex (val)) { }
67
70
72 : MSparse<Complex> (a, dv) { }
73
75
77
79 : MSparse<Complex> (a) { }
80
82 : MSparse<Complex> (a) { }
83
84 SparseComplexMatrix (const Array<Complex>& a, const octave::idx_vector& r,
85 const octave::idx_vector& c, octave_idx_type nr = -1,
86 octave_idx_type nc = -1, bool sum_terms = true,
87 octave_idx_type nzm = -1)
88 : MSparse<Complex> (a, r, c, nr, nc, sum_terms, nzm) { }
89
91
93
95
99
101 {
103 return *this;
104 }
105
107
108 OCTAVE_API bool operator == (const SparseComplexMatrix& a) const;
109 OCTAVE_API bool operator != (const SparseComplexMatrix& a) const;
110
111 OCTAVE_API bool ishermitian () const;
112
113 OCTAVE_API SparseComplexMatrix max (int dim = -1) const;
115 max (Array<octave_idx_type>& index, int dim = -1) const;
116 OCTAVE_API SparseComplexMatrix min (int dim = -1) const;
118 min (Array<octave_idx_type>& index, int dim = -1) const;
119
123 insert (const SparseMatrix& a, octave_idx_type r, octave_idx_type c);
125 insert (const SparseComplexMatrix& a, const Array<octave_idx_type>& indx);
127 insert (const SparseMatrix& a, const Array<octave_idx_type>& indx);
128
133
134 OCTAVE_API ComplexMatrix matrix_value () const;
135
136 OCTAVE_API SparseComplexMatrix hermitian () const; // complex conjugate transpose
139
141
142 // extract row or column i.
143
145
147
148private:
149 SparseComplexMatrix dinverse (MatrixType& mattype, octave_idx_type& info,
150 double& rcond, const bool force = false,
151 const bool calccond = true) const;
152
153 SparseComplexMatrix tinverse (MatrixType& mattype, octave_idx_type& info,
154 double& rcond, const bool force = false,
155 const bool calccond = true) const;
156
157public:
158 OCTAVE_API SparseComplexMatrix inverse () const;
159 OCTAVE_API SparseComplexMatrix inverse (MatrixType& mattype) const;
161 inverse (MatrixType& mattype, octave_idx_type& info) const;
163 inverse (MatrixType& mattype, octave_idx_type& info, double& rcond,
164 bool force = false, bool calc_cond = true) const;
165
166 OCTAVE_API ComplexDET determinant () const;
167 OCTAVE_API ComplexDET determinant (octave_idx_type& info) const;
169 determinant (octave_idx_type& info, double& rcond,
170 bool calc_cond = true) const;
171
172private:
173 // Diagonal matrix solvers
174 ComplexMatrix dsolve (MatrixType& mattype, const Matrix& b,
175 octave_idx_type& info, double& rcond,
176 solve_singularity_handler sing_handler,
177 bool calc_cond = false) const;
178
179 ComplexMatrix dsolve (MatrixType& mattype, const ComplexMatrix& b,
180 octave_idx_type& info, double& rcond,
181 solve_singularity_handler sing_handler,
182 bool calc_cond = false) const;
183
184 SparseComplexMatrix dsolve (MatrixType& mattype, const SparseMatrix& b,
185 octave_idx_type& info, double& rcond,
186 solve_singularity_handler sing_handler,
187 bool calc_cond = false) const;
188
189 SparseComplexMatrix dsolve (MatrixType& mattype, const SparseComplexMatrix& b,
190 octave_idx_type& info, double& rcond,
191 solve_singularity_handler sing_handler,
192 bool calc_cond = false) const;
193
194 // Upper triangular matrix solvers
195 ComplexMatrix utsolve (MatrixType& mattype, const Matrix& b,
196 octave_idx_type& info, double& rcond,
197 solve_singularity_handler sing_handler,
198 bool calc_cond = false) const;
199
200 ComplexMatrix utsolve (MatrixType& mattype, const ComplexMatrix& b,
201 octave_idx_type& info, double& rcond,
202 solve_singularity_handler sing_handler,
203 bool calc_cond = false) const;
204
205 SparseComplexMatrix utsolve (MatrixType& mattype, const SparseMatrix& b,
206 octave_idx_type& info, double& rcond,
207 solve_singularity_handler sing_handler,
208 bool calc_cond = false) const;
209
210 SparseComplexMatrix utsolve (MatrixType& mattype, const SparseComplexMatrix& b,
211 octave_idx_type& info, double& rcond,
212 solve_singularity_handler sing_handler,
213 bool calc_cond = false) const;
214
215 // Lower triangular matrix solvers
216 ComplexMatrix ltsolve (MatrixType& mattype, const Matrix& b,
217 octave_idx_type& info, double& rcond,
218 solve_singularity_handler sing_handler,
219 bool calc_cond = false) const;
220
221 ComplexMatrix ltsolve (MatrixType& mattype, const ComplexMatrix& b,
222 octave_idx_type& info, double& rcond,
223 solve_singularity_handler sing_handler,
224 bool calc_cond = false) const;
225
226 SparseComplexMatrix ltsolve (MatrixType& mattype, const SparseMatrix& b,
227 octave_idx_type& info, double& rcond,
228 solve_singularity_handler sing_handler,
229 bool calc_cond = false) const;
230
231 SparseComplexMatrix ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
232 octave_idx_type& info, double& rcond,
233 solve_singularity_handler sing_handler,
234 bool calc_cond = false) const;
235
236 // Tridiagonal matrix solvers
237 ComplexMatrix trisolve (MatrixType& mattype, const Matrix& b,
238 octave_idx_type& info, double& rcond,
239 solve_singularity_handler sing_handler,
240 bool calc_cond = false) const;
241
242 ComplexMatrix trisolve (MatrixType& mattype, const ComplexMatrix& b,
243 octave_idx_type& info, double& rcond,
244 solve_singularity_handler sing_handler,
245 bool calc_cond = false) const;
246
247 SparseComplexMatrix trisolve (MatrixType& mattype, const SparseMatrix& b,
248 octave_idx_type& info, double& rcond,
249 solve_singularity_handler sing_handler,
250 bool calc_cond = false) const;
251
252 SparseComplexMatrix trisolve (MatrixType& mattype, const SparseComplexMatrix& b,
253 octave_idx_type& info, double& rcond,
254 solve_singularity_handler sing_handler,
255 bool calc_cond = false) const;
256
257 // Banded matrix solvers (umfpack/cholesky)
258 ComplexMatrix bsolve (MatrixType& mattype, const Matrix& b,
259 octave_idx_type& info, double& rcond,
260 solve_singularity_handler sing_handler,
261 bool calc_cond = false) const;
262
263 ComplexMatrix bsolve (MatrixType& mattype, const ComplexMatrix& b,
264 octave_idx_type& info, double& rcond,
265 solve_singularity_handler sing_handler,
266 bool calc_cond = false) const;
267
268 SparseComplexMatrix bsolve (MatrixType& mattype, const SparseMatrix& b,
269 octave_idx_type& info, double& rcond,
270 solve_singularity_handler sing_handler,
271 bool calc_cond = false) const;
272
273 SparseComplexMatrix bsolve (MatrixType& mattype, const SparseComplexMatrix& b,
274 octave_idx_type& info, double& rcond,
275 solve_singularity_handler sing_handler,
276 bool calc_cond = false) const;
277
278 // Full matrix solvers (umfpack/cholesky)
279 void * factorize (octave_idx_type& err, double& rcond, Matrix& Control,
280 Matrix& Info, solve_singularity_handler sing_handler,
281 bool calc_cond) const;
282
283 ComplexMatrix fsolve (MatrixType& mattype, const Matrix& b,
284 octave_idx_type& info, double& rcond,
285 solve_singularity_handler sing_handler,
286 bool calc_cond = false) const;
287
288 ComplexMatrix fsolve (MatrixType& mattype, const ComplexMatrix& b,
289 octave_idx_type& info, double& rcond,
290 solve_singularity_handler sing_handler,
291 bool calc_cond = false) const;
292
293 SparseComplexMatrix fsolve (MatrixType& mattype, const SparseMatrix& b,
294 octave_idx_type& info, double& rcond,
295 solve_singularity_handler sing_handler,
296 bool calc_cond = false) const;
297
298 SparseComplexMatrix fsolve (MatrixType& mattype, const SparseComplexMatrix& b,
299 octave_idx_type& info, double& rcond,
300 solve_singularity_handler sing_handler,
301 bool calc_cond = false) const;
302
303public:
304 // Generic interface to solver with no probing of type
305 OCTAVE_API ComplexMatrix solve (MatrixType& mattype, const Matrix& b) const;
307 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info) const;
309 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info,
310 double& rcond) const;
312 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info,
313 double& rcond, solve_singularity_handler sing_handler,
314 bool singular_fallback = true) const;
315
317 solve (MatrixType& mattype, const ComplexMatrix& b) const;
319 solve (MatrixType& mattype, const ComplexMatrix& b,
320 octave_idx_type& info) const;
322 solve (MatrixType& mattype, const ComplexMatrix& b,
323 octave_idx_type& info, double& rcond) const;
325 solve (MatrixType& mattype, const ComplexMatrix& b,
326 octave_idx_type& info, double& rcond,
327 solve_singularity_handler sing_handler,
328 bool singular_fallback = true) const;
329
331 solve (MatrixType& mattype, const SparseMatrix& b) const;
333 solve (MatrixType& mattype, const SparseMatrix& b,
334 octave_idx_type& info) const;
336 solve (MatrixType& mattype, const SparseMatrix& b, octave_idx_type& info,
337 double& rcond) const;
339 solve (MatrixType& mattype, const SparseMatrix& b, octave_idx_type& info,
340 double& rcond, solve_singularity_handler sing_handler,
341 bool singular_fallback = true) const;
342
344 solve (MatrixType& mattype, const SparseComplexMatrix& b) const;
346 solve (MatrixType& mattype, const SparseComplexMatrix& b,
347 octave_idx_type& info) const;
349 solve (MatrixType& mattype, const SparseComplexMatrix& b,
350 octave_idx_type& info, double& rcond) const;
352 solve (MatrixType& mattype, const SparseComplexMatrix& b,
353 octave_idx_type& info, double& rcond,
354 solve_singularity_handler sing_handler,
355 bool singular_fallback = true) const;
356
358 solve (MatrixType& mattype, const ColumnVector& b) const;
360 solve (MatrixType& mattype, const ColumnVector& b,
361 octave_idx_type& info) const;
363 solve (MatrixType& mattype, const ColumnVector& b,
364 octave_idx_type& info, double& rcond) const;
366 solve (MatrixType& mattype, const ColumnVector& b,
367 octave_idx_type& info, double& rcond,
368 solve_singularity_handler sing_handler) const;
369
371 solve (MatrixType& mattype, const ComplexColumnVector& b) const;
373 solve (MatrixType& mattype, const ComplexColumnVector& b,
374 octave_idx_type& info) const;
376 solve (MatrixType& mattype, const ComplexColumnVector& b,
377 octave_idx_type& info, double& rcond) const;
379 solve (MatrixType& mattype, const ComplexColumnVector& b,
380 octave_idx_type& info, double& rcond,
381 solve_singularity_handler sing_handler) const;
382
383 // Generic interface to solver with probing of type
384 OCTAVE_API ComplexMatrix solve (const Matrix& b) const;
386 solve (const Matrix& b, octave_idx_type& info) const;
388 solve (const Matrix& b, octave_idx_type& info, double& rcond) const;
390 solve (const Matrix& b, octave_idx_type& info, double& rcond,
391 solve_singularity_handler sing_handler) const;
392
395 solve (const ComplexMatrix& b, octave_idx_type& info) const;
397 solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const;
399 solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond,
400 solve_singularity_handler sing_handler) const;
401
402 OCTAVE_API SparseComplexMatrix solve (const SparseMatrix& b) const;
404 solve (const SparseMatrix& b, octave_idx_type& info) const;
406 solve (const SparseMatrix& b, octave_idx_type& info, double& rcond) const;
408 solve (const SparseMatrix& b, octave_idx_type& info, double& rcond,
409 solve_singularity_handler sing_handler) const;
410
413 solve (const SparseComplexMatrix& b, octave_idx_type& info) const;
415 solve (const SparseComplexMatrix& b, octave_idx_type& info,
416 double& rcond) const;
418 solve (const SparseComplexMatrix& b, octave_idx_type& info, double& rcond,
419 solve_singularity_handler sing_handler) const;
420
421 OCTAVE_API ComplexColumnVector solve (const ColumnVector& b) const;
423 solve (const ColumnVector& b, octave_idx_type& info) const;
425 solve (const ColumnVector& b, octave_idx_type& info, double& rcond) const;
427 solve (const ColumnVector& b, octave_idx_type& info, double& rcond,
428 solve_singularity_handler sing_handler) const;
429
432 solve (const ComplexColumnVector& b, octave_idx_type& info) const;
434 solve (const ComplexColumnVector& b, octave_idx_type& info,
435 double& rcond) const;
437 solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcond,
438 solve_singularity_handler sing_handler) const;
439
440 OCTAVE_API SparseComplexMatrix squeeze () const;
441
442 OCTAVE_API SparseComplexMatrix reshape (const dim_vector& new_dims) const;
443
445 permute (const Array<octave_idx_type>& vec, bool inv = false) const;
446
448 ipermute (const Array<octave_idx_type>& vec) const;
449
450 OCTAVE_API bool any_element_is_nan () const;
451 OCTAVE_API bool any_element_is_inf_or_nan () const;
452 OCTAVE_API bool all_elements_are_real () const;
453 OCTAVE_API bool all_integers (double& max_val, double& min_val) const;
454 OCTAVE_API bool too_large_for_float () const;
455
457
458 OCTAVE_API SparseBoolMatrix all (int dim = -1) const;
459 OCTAVE_API SparseBoolMatrix any (int dim = -1) const;
460
461 OCTAVE_API SparseComplexMatrix cumprod (int dim = -1) const;
462 OCTAVE_API SparseComplexMatrix cumsum (int dim = -1) const;
463 OCTAVE_API SparseComplexMatrix prod (int dim = -1) const;
464 OCTAVE_API SparseComplexMatrix sum (int dim = -1) const;
465 OCTAVE_API SparseComplexMatrix sumsq (int dim = -1) const;
466 OCTAVE_API SparseMatrix abs () const;
467
469
470 // i/o
471 friend OCTAVE_API std::ostream&
472 operator << (std::ostream& os, const SparseComplexMatrix& a);
473 friend OCTAVE_API std::istream&
474 operator >> (std::istream& is, SparseComplexMatrix& a);
475};
476
483
494
505
510
515
520
533
546
551
553min (const Complex& c, const SparseComplexMatrix& m);
555min (const SparseComplexMatrix& m, const Complex& c);
557min (const SparseComplexMatrix& a, const SparseComplexMatrix& b);
558
560max (const Complex& c, const SparseComplexMatrix& m);
562max (const SparseComplexMatrix& m, const Complex& c);
564max (const SparseComplexMatrix& a, const SparseComplexMatrix& b);
565
568
571
574
576
577#endif
template std::ostream & operator<<(std::ostream &, const Array< bool > &)
ComplexColumnVector conj(const ComplexColumnVector &a)
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition CNDArray.cc:418
SparseComplexMatrix max(const Complex &c, const SparseComplexMatrix &m)
Definition CSparse.cc:7738
ComplexMatrix herm_mul(const SparseComplexMatrix &, const ComplexMatrix &)
Definition CSparse.cc:7499
SparseComplexMatrix operator+(const ComplexDiagMatrix &, const SparseMatrix &)
Definition CSparse.cc:7539
SparseComplexMatrix operator*(const SparseMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7433
ComplexMatrix mul_herm(const ComplexMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7469
ComplexMatrix mul_trans(const ComplexMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7463
SparseComplexMatrix min(const Complex &c, const SparseComplexMatrix &m)
Definition CSparse.cc:7621
ComplexMatrix trans_mul(const SparseComplexMatrix &, const ComplexMatrix &)
Definition CSparse.cc:7493
SparseComplexMatrix operator-(const ComplexDiagMatrix &, const SparseMatrix &)
Definition CSparse.cc:7570
#define SPARSE_FORWARD_DEFS(B, R, F, T)
Definition MSparse.h:192
#define SPARSE_SMSM_CMP_OP_DECLS(M1, M2, API)
#define SPARSE_SMSM_BOOL_OP_DECLS(M1, M2, API)
#define SPARSE_SSM_CMP_OP_DECLS(S, M, API)
#define SPARSE_SMS_BOOL_OP_DECLS(M, S, API)
#define SPARSE_SSM_BOOL_OP_DECLS(S, M, API)
#define SPARSE_SMS_CMP_OP_DECLS(M, S, API)
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
charNDArray max(char d, const charNDArray &m)
Definition chNDArray.cc:230
charNDArray min(char d, const charNDArray &m)
Definition chNDArray.cc:207
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
MSparse< T > transpose() const
Definition MSparse.h:96
MSparse< T > & operator=(const MSparse< T > &a)
Definition MSparse.h:78
SparseComplexMatrix(const ComplexNDArray &a)
Definition CSparse.h:81
SparseComplexMatrix(const ComplexMatrix &a)
Definition CSparse.h:78
SparseComplexMatrix(const Sparse< Complex > &a)
Definition CSparse.h:76
SparseComplexMatrix(octave_idx_type r, octave_idx_type c, double val)
Definition CSparse.h:65
SparseComplexMatrix(octave_idx_type r, octave_idx_type c)
Definition CSparse.h:55
SparseComplexMatrix(const SparseComplexMatrix &a)
Definition CSparse.h:68
SparseComplexMatrix(const dim_vector &dv, octave_idx_type nz=0)
Definition CSparse.h:58
SparseComplexMatrix(const MSparse< Complex > &a)
Definition CSparse.h:74
ComplexMatrix solve(const ComplexMatrix &b) const
ComplexMatrix dense_matrix_type
Definition CSparse.h:49
SparseComplexMatrix(octave_idx_type r, octave_idx_type c, Complex val)
Definition CSparse.h:61
~SparseComplexMatrix()=default
SparseComplexMatrix(octave_idx_type r, octave_idx_type c, octave_idx_type num_nz)
Definition CSparse.h:96
SparseComplexMatrix transpose() const
Definition CSparse.h:137
SparseComplexMatrix(const SparseComplexMatrix &a, const dim_vector &dv)
Definition CSparse.h:71
SparseComplexMatrix(const Array< Complex > &a, const octave::idx_vector &r, const octave::idx_vector &c, octave_idx_type nr=-1, octave_idx_type nc=-1, bool sum_terms=true, octave_idx_type nzm=-1)
Definition CSparse.h:84
Definition DET.h:38
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition dim-vector.h:532
bool operator==(const dim_vector &a, const dim_vector &b)
Definition dim-vector.h:516
bool too_large_for_float(double x)
Definition lo-utils.cc:56
#define OCTAVE_API
Definition main.in.cc:55
std::complex< double > Complex
Definition oct-cmplx.h:33
const octave_base_value const Array< octave_idx_type > & ra_idx
octave_value operator!(const octave_value &a)
Definition ov.h:1648
template int8_t abs(int8_t)