GNU Octave 11.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-2026 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
114 max (int dim = -1, bool nanflag = true, bool realabs = false) const;
116 max (Array<octave_idx_type>& index, int dim = -1,
117 bool nanflag = true, bool realabs = false) const;
119 min (int dim = -1, bool nanflag = true, bool realabs = false) const;
121 min (Array<octave_idx_type>& index, int dim = -1,
122 bool nanflag = true, bool realabs = false) const;
123
127 insert (const SparseMatrix& a, octave_idx_type r, octave_idx_type c);
129 insert (const SparseComplexMatrix& a, const Array<octave_idx_type>& indx);
131 insert (const SparseMatrix& a, const Array<octave_idx_type>& indx);
132
137
138 OCTAVE_API ComplexMatrix matrix_value () const;
139
140 OCTAVE_API SparseComplexMatrix hermitian () const; // complex conjugate transpose
143
145
146 // extract row or column i.
147
149
151
152private:
153 SparseComplexMatrix dinverse (MatrixType& mattype, octave_idx_type& info,
154 double& rcond, const bool force = false,
155 const bool calccond = true) const;
156
157 SparseComplexMatrix tinverse (MatrixType& mattype, octave_idx_type& info,
158 double& rcond, const bool force = false,
159 const bool calccond = true) const;
160
161public:
162 OCTAVE_API SparseComplexMatrix inverse () const;
163 OCTAVE_API SparseComplexMatrix inverse (MatrixType& mattype) const;
165 inverse (MatrixType& mattype, octave_idx_type& info) const;
167 inverse (MatrixType& mattype, octave_idx_type& info, double& rcond,
168 bool force = false, bool calc_cond = true) const;
169
170 OCTAVE_API ComplexDET determinant () const;
171 OCTAVE_API ComplexDET determinant (octave_idx_type& info) const;
173 determinant (octave_idx_type& info, double& rcond,
174 bool calc_cond = true) const;
175
176private:
177 // Diagonal matrix solvers
178 ComplexMatrix dsolve (MatrixType& mattype, const Matrix& b,
179 octave_idx_type& info, double& rcond,
180 solve_singularity_handler sing_handler,
181 bool calc_cond = false) const;
182
183 ComplexMatrix dsolve (MatrixType& mattype, const ComplexMatrix& b,
184 octave_idx_type& info, double& rcond,
185 solve_singularity_handler sing_handler,
186 bool calc_cond = false) const;
187
188 SparseComplexMatrix dsolve (MatrixType& mattype, const SparseMatrix& b,
189 octave_idx_type& info, double& rcond,
190 solve_singularity_handler sing_handler,
191 bool calc_cond = false) const;
192
193 SparseComplexMatrix dsolve (MatrixType& mattype, const SparseComplexMatrix& b,
194 octave_idx_type& info, double& rcond,
195 solve_singularity_handler sing_handler,
196 bool calc_cond = false) const;
197
198 // Upper triangular matrix solvers
199 ComplexMatrix utsolve (MatrixType& mattype, const Matrix& b,
200 octave_idx_type& info, double& rcond,
201 solve_singularity_handler sing_handler,
202 bool calc_cond = false) const;
203
204 ComplexMatrix utsolve (MatrixType& mattype, const ComplexMatrix& b,
205 octave_idx_type& info, double& rcond,
206 solve_singularity_handler sing_handler,
207 bool calc_cond = false) const;
208
209 SparseComplexMatrix utsolve (MatrixType& mattype, const SparseMatrix& b,
210 octave_idx_type& info, double& rcond,
211 solve_singularity_handler sing_handler,
212 bool calc_cond = false) const;
213
214 SparseComplexMatrix utsolve (MatrixType& mattype, const SparseComplexMatrix& b,
215 octave_idx_type& info, double& rcond,
216 solve_singularity_handler sing_handler,
217 bool calc_cond = false) const;
218
219 // Lower triangular matrix solvers
220 ComplexMatrix ltsolve (MatrixType& mattype, const Matrix& b,
221 octave_idx_type& info, double& rcond,
222 solve_singularity_handler sing_handler,
223 bool calc_cond = false) const;
224
225 ComplexMatrix ltsolve (MatrixType& mattype, const ComplexMatrix& b,
226 octave_idx_type& info, double& rcond,
227 solve_singularity_handler sing_handler,
228 bool calc_cond = false) const;
229
230 SparseComplexMatrix ltsolve (MatrixType& mattype, const SparseMatrix& b,
231 octave_idx_type& info, double& rcond,
232 solve_singularity_handler sing_handler,
233 bool calc_cond = false) const;
234
235 SparseComplexMatrix ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
236 octave_idx_type& info, double& rcond,
237 solve_singularity_handler sing_handler,
238 bool calc_cond = false) const;
239
240 // Tridiagonal matrix solvers
241 ComplexMatrix trisolve (MatrixType& mattype, const Matrix& b,
242 octave_idx_type& info, double& rcond,
243 solve_singularity_handler sing_handler,
244 bool calc_cond = false) const;
245
246 ComplexMatrix trisolve (MatrixType& mattype, const ComplexMatrix& b,
247 octave_idx_type& info, double& rcond,
248 solve_singularity_handler sing_handler,
249 bool calc_cond = false) const;
250
251 SparseComplexMatrix trisolve (MatrixType& mattype, const SparseMatrix& b,
252 octave_idx_type& info, double& rcond,
253 solve_singularity_handler sing_handler,
254 bool calc_cond = false) const;
255
256 SparseComplexMatrix trisolve (MatrixType& mattype, const SparseComplexMatrix& b,
257 octave_idx_type& info, double& rcond,
258 solve_singularity_handler sing_handler,
259 bool calc_cond = false) const;
260
261 // Banded matrix solvers (umfpack/cholesky)
262 ComplexMatrix bsolve (MatrixType& mattype, const Matrix& b,
263 octave_idx_type& info, double& rcond,
264 solve_singularity_handler sing_handler,
265 bool calc_cond = false) const;
266
267 ComplexMatrix bsolve (MatrixType& mattype, const ComplexMatrix& b,
268 octave_idx_type& info, double& rcond,
269 solve_singularity_handler sing_handler,
270 bool calc_cond = false) const;
271
272 SparseComplexMatrix bsolve (MatrixType& mattype, const SparseMatrix& b,
273 octave_idx_type& info, double& rcond,
274 solve_singularity_handler sing_handler,
275 bool calc_cond = false) const;
276
277 SparseComplexMatrix bsolve (MatrixType& mattype, const SparseComplexMatrix& b,
278 octave_idx_type& info, double& rcond,
279 solve_singularity_handler sing_handler,
280 bool calc_cond = false) const;
281
282 // Full matrix solvers (umfpack/cholesky)
283 void * factorize (octave_idx_type& err, double& rcond, Matrix& Control,
284 Matrix& Info, solve_singularity_handler sing_handler,
285 bool calc_cond) const;
286
287 ComplexMatrix fsolve (MatrixType& mattype, const Matrix& b,
288 octave_idx_type& info, double& rcond,
289 solve_singularity_handler sing_handler,
290 bool calc_cond = false) const;
291
292 ComplexMatrix fsolve (MatrixType& mattype, const ComplexMatrix& b,
293 octave_idx_type& info, double& rcond,
294 solve_singularity_handler sing_handler,
295 bool calc_cond = false) const;
296
297 SparseComplexMatrix fsolve (MatrixType& mattype, const SparseMatrix& b,
298 octave_idx_type& info, double& rcond,
299 solve_singularity_handler sing_handler,
300 bool calc_cond = false) const;
301
302 SparseComplexMatrix fsolve (MatrixType& mattype, const SparseComplexMatrix& b,
303 octave_idx_type& info, double& rcond,
304 solve_singularity_handler sing_handler,
305 bool calc_cond = false) const;
306
307public:
308 // Generic interface to solver with no probing of type
309 OCTAVE_API ComplexMatrix solve (MatrixType& mattype, const Matrix& b) const;
311 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info) const;
313 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info,
314 double& rcond) const;
316 solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info,
317 double& rcond, solve_singularity_handler sing_handler,
318 bool singular_fallback = true) const;
319
321 solve (MatrixType& mattype, const ComplexMatrix& b) const;
323 solve (MatrixType& mattype, const ComplexMatrix& b,
324 octave_idx_type& info) const;
326 solve (MatrixType& mattype, const ComplexMatrix& b,
327 octave_idx_type& info, double& rcond) const;
329 solve (MatrixType& mattype, const ComplexMatrix& b,
330 octave_idx_type& info, double& rcond,
331 solve_singularity_handler sing_handler,
332 bool singular_fallback = true) const;
333
335 solve (MatrixType& mattype, const SparseMatrix& b) const;
337 solve (MatrixType& mattype, const SparseMatrix& b,
338 octave_idx_type& info) const;
340 solve (MatrixType& mattype, const SparseMatrix& b, octave_idx_type& info,
341 double& rcond) const;
343 solve (MatrixType& mattype, const SparseMatrix& b, octave_idx_type& info,
344 double& rcond, solve_singularity_handler sing_handler,
345 bool singular_fallback = true) const;
346
348 solve (MatrixType& mattype, const SparseComplexMatrix& b) const;
350 solve (MatrixType& mattype, const SparseComplexMatrix& b,
351 octave_idx_type& info) const;
353 solve (MatrixType& mattype, const SparseComplexMatrix& b,
354 octave_idx_type& info, double& rcond) const;
356 solve (MatrixType& mattype, const SparseComplexMatrix& b,
357 octave_idx_type& info, double& rcond,
358 solve_singularity_handler sing_handler,
359 bool singular_fallback = true) const;
360
362 solve (MatrixType& mattype, const ColumnVector& b) const;
364 solve (MatrixType& mattype, const ColumnVector& b,
365 octave_idx_type& info) const;
367 solve (MatrixType& mattype, const ColumnVector& b,
368 octave_idx_type& info, double& rcond) const;
370 solve (MatrixType& mattype, const ColumnVector& b,
371 octave_idx_type& info, double& rcond,
372 solve_singularity_handler sing_handler) const;
373
375 solve (MatrixType& mattype, const ComplexColumnVector& b) const;
377 solve (MatrixType& mattype, const ComplexColumnVector& b,
378 octave_idx_type& info) const;
380 solve (MatrixType& mattype, const ComplexColumnVector& b,
381 octave_idx_type& info, double& rcond) const;
383 solve (MatrixType& mattype, const ComplexColumnVector& b,
384 octave_idx_type& info, double& rcond,
385 solve_singularity_handler sing_handler) const;
386
387 // Generic interface to solver with probing of type
388 OCTAVE_API ComplexMatrix solve (const Matrix& b) const;
390 solve (const Matrix& b, octave_idx_type& info) const;
392 solve (const Matrix& b, octave_idx_type& info, double& rcond) const;
394 solve (const Matrix& b, octave_idx_type& info, double& rcond,
395 solve_singularity_handler sing_handler) const;
396
399 solve (const ComplexMatrix& b, octave_idx_type& info) const;
401 solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const;
403 solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond,
404 solve_singularity_handler sing_handler) const;
405
406 OCTAVE_API SparseComplexMatrix solve (const SparseMatrix& b) const;
408 solve (const SparseMatrix& b, octave_idx_type& info) const;
410 solve (const SparseMatrix& b, octave_idx_type& info, double& rcond) const;
412 solve (const SparseMatrix& b, octave_idx_type& info, double& rcond,
413 solve_singularity_handler sing_handler) const;
414
417 solve (const SparseComplexMatrix& b, octave_idx_type& info) const;
419 solve (const SparseComplexMatrix& b, octave_idx_type& info,
420 double& rcond) const;
422 solve (const SparseComplexMatrix& b, octave_idx_type& info, double& rcond,
423 solve_singularity_handler sing_handler) const;
424
425 OCTAVE_API ComplexColumnVector solve (const ColumnVector& b) const;
427 solve (const ColumnVector& b, octave_idx_type& info) const;
429 solve (const ColumnVector& b, octave_idx_type& info, double& rcond) const;
431 solve (const ColumnVector& b, octave_idx_type& info, double& rcond,
432 solve_singularity_handler sing_handler) const;
433
436 solve (const ComplexColumnVector& b, octave_idx_type& info) const;
438 solve (const ComplexColumnVector& b, octave_idx_type& info,
439 double& rcond) const;
441 solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcond,
442 solve_singularity_handler sing_handler) const;
443
444 OCTAVE_API SparseComplexMatrix squeeze () const;
445
446 OCTAVE_API SparseComplexMatrix reshape (const dim_vector& new_dims) const;
447
449 permute (const Array<octave_idx_type>& vec, bool inv = false) const;
450
452 ipermute (const Array<octave_idx_type>& vec) const;
453
454 OCTAVE_API bool any_element_is_nan () const;
455 OCTAVE_API bool any_element_is_inf_or_nan () const;
456 OCTAVE_API bool all_elements_are_real () const;
457 OCTAVE_API bool all_integers (double& max_val, double& min_val) const;
458 OCTAVE_API bool too_large_for_float () const;
459
461
462 OCTAVE_API SparseBoolMatrix all (int dim = -1) const;
463 OCTAVE_API SparseBoolMatrix any (int dim = -1) const;
464
465 OCTAVE_API SparseComplexMatrix cumprod (int dim = -1, bool nanflag = false) const;
466 OCTAVE_API SparseComplexMatrix cumsum (int dim = -1, bool nanflag = false) const;
467 OCTAVE_API SparseComplexMatrix prod (int dim = -1, bool nanflag = false) const;
468 OCTAVE_API SparseComplexMatrix sum (int dim = -1, bool nanflag = false) const;
469 OCTAVE_API SparseComplexMatrix xsum (int dim = -1, bool nanflag = false) const;
470 OCTAVE_API SparseComplexMatrix sumsq (int dim = -1, bool nanflag = false) const;
471 OCTAVE_API SparseMatrix abs () const;
472
474
475 // i/o
476 friend OCTAVE_API std::ostream&
477 operator << (std::ostream& os, const SparseComplexMatrix& a);
478 friend OCTAVE_API std::istream&
479 operator >> (std::istream& is, SparseComplexMatrix& a);
480};
481
488
499
510
515
520
525
538
551
556
558min (const Complex& c, const SparseComplexMatrix& m);
560min (const Complex& c, const SparseComplexMatrix& m, const bool nanflag);
562min (const Complex& c, const SparseComplexMatrix& m, const bool nanflag,
563 const bool realabs);
565min (const SparseComplexMatrix& m, const Complex& c);
567min (const SparseComplexMatrix& m, const Complex& c, const bool nanflag);
569min (const SparseComplexMatrix& m, const Complex& c, const bool nanflag,
570 const bool realabs);
572min (const SparseComplexMatrix& a, const SparseComplexMatrix& b);
575 const bool nanflag);
578 const bool nanflag, const bool realabs);
579
581max (const Complex& c, const SparseComplexMatrix& m);
583max (const Complex& c, const SparseComplexMatrix& m, const bool nanflag);
585max (const Complex& c, const SparseComplexMatrix& m, const bool nanflag,
586 const bool realabs);
588max (const SparseComplexMatrix& m, const Complex& c);
590max (const SparseComplexMatrix& m, const Complex& c, const bool nanflag);
592max (const SparseComplexMatrix& m, const Complex& c, const bool nanflag,
593 const bool realabs);
595max (const SparseComplexMatrix& a, const SparseComplexMatrix& b);
598 const bool nanflag);
601 const bool nanflag, const bool realabs);
602
605
608
611
613
614#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:424
SparseComplexMatrix max(const Complex &c, const SparseComplexMatrix &m)
Definition CSparse.cc:8157
ComplexMatrix herm_mul(const SparseComplexMatrix &, const ComplexMatrix &)
Definition CSparse.cc:7842
SparseComplexMatrix operator+(const ComplexDiagMatrix &, const SparseMatrix &)
Definition CSparse.cc:7882
SparseComplexMatrix operator*(const SparseMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7776
ComplexMatrix mul_herm(const ComplexMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7812
ComplexMatrix mul_trans(const ComplexMatrix &, const SparseComplexMatrix &)
Definition CSparse.cc:7806
SparseComplexMatrix min(const Complex &c, const SparseComplexMatrix &m)
Definition CSparse.cc:7964
ComplexMatrix trans_mul(const SparseComplexMatrix &, const ComplexMatrix &)
Definition CSparse.cc:7836
SparseComplexMatrix operator-(const ComplexDiagMatrix &, const SparseMatrix &)
Definition CSparse.cc:7913
#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-base.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:141
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:92
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition dim-vector.h:573
bool operator==(const dim_vector &a, const dim_vector &b)
Definition dim-vector.h:557
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:1646
template int8_t abs(int8_t)