GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
sparse-qr.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2005-2023 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_sparse_qr_h)
27 #define octave_sparse_qr_h 1
28 
29 #include "octave-config.h"
30 
31 #include <memory>
32 
33 #include "oct-cmplx.h"
34 #include "MArray-fwd.h"
35 #include "mx-fwd.h"
36 
38 
40 
41 // If the sparse matrix classes become templated on the element type
42 // (i.e., sparse_matrix<double>), then it might be best to make the
43 // template parameter of this class also be the element type instead
44 // of the matrix type.
45 
46 template <typename SPARSE_T>
47 class
49 {
50 public:
51 
52  OCTAVE_API sparse_qr (void);
53 
54 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
55  // order = 7 selects SPQR default ordering
56  OCTAVE_API sparse_qr (const SPARSE_T& a, int order = 7);
57 #else
58  OCTAVE_API sparse_qr (const SPARSE_T& a, int order = 0);
59 #endif
60 
61  sparse_qr (const sparse_qr& a) = default;
62 
63  ~sparse_qr (void) = default;
64 
65  sparse_qr& operator = (const sparse_qr& a) = default;
66 
67  OCTAVE_API bool ok (void) const;
68 
69  OCTAVE_API ColumnVector E (void) const;
70 
71  // constructs permutation matrix from permutation vector rep -> E()
72  OCTAVE_API SparseMatrix E_MAT () const;
73 
74  OCTAVE_API SPARSE_T V (void) const;
75 
76  OCTAVE_API ColumnVector Pinv (void) const;
77 
78  OCTAVE_API ColumnVector P (void) const;
79 
80  OCTAVE_API SPARSE_T R (bool econ = false) const;
81 
82  OCTAVE_API typename SPARSE_T::dense_matrix_type
83  C (const typename SPARSE_T::dense_matrix_type& b, bool econ = false) const;
84 
85  OCTAVE_API typename SPARSE_T::dense_matrix_type
86  Q (bool econ = false) const;
87 
88  template <typename RHS_T, typename RET_T>
89  static OCTAVE_API RET_T
90  solve (const SPARSE_T& a, const RHS_T& b,
91  octave_idx_type& info);
92 
93 private:
94 
95  template <typename RHS_T, typename RET_T>
96  static OCTAVE_API RET_T
97  min2norm_solve (const SPARSE_T& a, const RHS_T& b,
98  octave_idx_type& info, int order);
99 
100  template <typename RHS_T, typename RET_T>
101  OCTAVE_API RET_T
102  tall_solve (const RHS_T& b, octave_idx_type& info) const;
103 
104  template <typename RHS_T, typename RET_T>
105  OCTAVE_API RET_T
106  wide_solve (const RHS_T& b, octave_idx_type& info) const;
107 
108  //--------
109  class sparse_qr_rep;
110 
111  std::shared_ptr<sparse_qr_rep> m_rep;
112 };
113 
114 // extern instantiations with set visibility/export/import attribute
115 
116 extern template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr<SparseMatrix>;
117 
118 extern template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr<SparseComplexMatrix>;
119 
120 // Provide qrsolve for backward compatibility.
121 
122 extern OCTAVE_API Matrix
123 qrsolve (const SparseMatrix& a, const MArray<double>& b,
124  octave_idx_type& info);
125 
127 qrsolve (const SparseMatrix& a, const SparseMatrix& b,
128  octave_idx_type& info);
129 
131 qrsolve (const SparseMatrix& a, const MArray<Complex>& b,
132  octave_idx_type& info);
133 
135 qrsolve (const SparseMatrix& a, const SparseComplexMatrix& b,
136  octave_idx_type& info);
137 
139 qrsolve (const SparseComplexMatrix& a, const MArray<double>& b,
140  octave_idx_type& info);
141 
143 qrsolve (const SparseComplexMatrix& a, const SparseMatrix& b,
144  octave_idx_type& info);
145 
147 qrsolve (const SparseComplexMatrix& a, const MArray<Complex>& b,
148  octave_idx_type& info);
149 
152  octave_idx_type& info);
153 
156 
159 
160 #endif
OCTAVE_END_NAMESPACE(octave)
#define C(a, b)
Definition: Faddeeva.cc:259
Definition: dMatrix.h:42
OCTAVE_API RET_T tall_solve(const RHS_T &b, octave_idx_type &info) const
static OCTAVE_API RET_T solve(const SPARSE_T &a, const RHS_T &b, octave_idx_type &info)
sparse_qr(const sparse_qr &a)=default
std::shared_ptr< sparse_qr_rep > m_rep
Definition: sparse-qr.h:109
OCTAVE_API RET_T wide_solve(const RHS_T &b, octave_idx_type &info) const
~sparse_qr(void)=default
static OCTAVE_API RET_T min2norm_solve(const SPARSE_T &a, const RHS_T &b, octave_idx_type &info, int order)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Q
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
#define OCTAVE_API
Definition: main.in.cc:55
sparse_qr< SparseComplexMatrix > SparseComplexQR
Definition: sparse-qr.h:155
sparse_qr< SparseMatrix > SparseQR
Definition: sparse-qr.h:154
OCTAVE_API Matrix qrsolve(const SparseMatrix &a, const MArray< double > &b, octave_idx_type &info)
Definition: sparse-qr.cc:3288