26 #if defined (HAVE_CONFIG_H)
47 template <
typename SPARSE_T>
58 #if defined (HAVE_CXSPARSE)
72 #if defined (HAVE_CXSPARSE)
81 template <
typename SPARSE_T>
98 #if defined (HAVE_CXSPARSE)
105 SPARSE_T
V (
void)
const;
111 SPARSE_T
R (
bool econ)
const;
113 typename SPARSE_T::dense_matrix_type
114 C (
const typename SPARSE_T::dense_matrix_type& b)
const;
116 typename SPARSE_T::dense_matrix_type
127 template <
typename RHS_T,
typename RET_T>
131 template <
typename RHS_T,
typename RET_T>
136 template <
typename SPARSE_T>
140 #if defined (HAVE_CXSPARSE)
145 ret.
xelem (i) =
S->pinv[i];
156 template <
typename SPARSE_T>
160 #if defined (HAVE_CXSPARSE)
165 ret.
xelem (S->pinv[i]) = i;
183 : count (1), nrows (a.rows ()), ncols (a.columns ())
184 #if defined (HAVE_CXSPARSE)
185 , S (nullptr),
N (nullptr)
188 #if defined (HAVE_CXSPARSE)
201 A.x =
const_cast<double *
> (a.
data ());
210 (*current_liboctave_error_handler)
211 (
"sparse_qr: sparse matrix QR factorization filled");
215 octave_unused_parameter (order);
217 (*current_liboctave_error_handler)
218 (
"sparse_qr: support for CXSparse was unavailable or disabled when liboctave was built");
226 #if defined (HAVE_CXSPARSE)
236 #if defined (HAVE_CXSPARSE)
254 ret.
xcidx (j) =
N->L->p[j];
258 ret.
xridx (j) =
N->L->i[j];
259 ret.
xdata (j) =
N->L->x[j];
275 #if defined (HAVE_CXSPARSE)
291 SparseMatrix ret ((econ ? (nc > nrows ? nrows : nc) : nrows), nc, nz);
294 ret.
xcidx (j) =
N->U->p[j];
298 ret.
xridx (j) =
N->U->i[j];
299 ret.
xdata (j) =
N->U->x[j];
306 octave_unused_parameter (econ);
317 #if defined (HAVE_CXSPARSE)
330 if (nr < 0 || nc < 0 || nr != b_nr)
331 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
333 if (nr == 0 || nc == 0 || b_nc == 0)
334 ret =
Matrix (nc, b_nc, 0.0);
372 octave_unused_parameter (b);
383 #if defined (HAVE_CXSPARSE)
389 if (nr < 0 || nc < 0)
390 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
392 if (nr == 0 || nc == 0)
393 ret =
Matrix (nc, nr, 0.0);
450 #if defined (HAVE_CXSPARSE)
458 const double *bvec = b.data ();
461 double *vec =
x.fortran_vec ();
466 i++, idx+=nc, bidx+=b_nr)
498 octave_unused_parameter (b);
513 #if defined (HAVE_CXSPARSE)
524 const double *bvec = b.data ();
527 double *vec =
x.fortran_vec ();
534 i++, idx+=nc, bidx+=b_nr)
566 octave_unused_parameter (b);
581 #if defined (HAVE_CXSPARSE)
603 Xx[j] = b.
xelem (j,i);
636 sz = (sz > 10 ? sz : 10) + x_nz;
637 x.change_capacity (sz);
655 octave_unused_parameter (b);
670 #if defined (HAVE_CXSPARSE)
696 Xx[j] = b.
xelem (j,i);
729 sz = (sz > 10 ? sz : 10) + x_nz;
730 x.change_capacity (sz);
750 octave_unused_parameter (b);
765 #if defined (HAVE_CXSPARSE)
832 vec[j+idx] =
Complex (Xx[j], Xz[j]);
841 octave_unused_parameter (b);
856 #if defined (HAVE_CXSPARSE)
930 vec[j+idx] =
Complex (Xx[j], Xz[j]);
939 octave_unused_parameter (b);
951 : count (1), nrows (a.rows ()), ncols (a.columns ())
952 #if defined (HAVE_CXSPARSE)
953 , S (nullptr),
N (nullptr)
956 #if defined (HAVE_CXSPARSE)
969 A.x =
const_cast<cs_complex_t *
>
970 (
reinterpret_cast<const cs_complex_t *
> (a.
data ()));
979 (*current_liboctave_error_handler)
980 (
"sparse_qr: sparse matrix QR factorization filled");
984 octave_unused_parameter (order);
986 (*current_liboctave_error_handler)
987 (
"sparse_qr: support for CXSparse was unavailable or disabled when liboctave was built");
995 #if defined (HAVE_CXSPARSE)
1005 #if defined (HAVE_CXSPARSE)
1022 ret.
xcidx (j) =
N->L->p[j];
1026 ret.
xridx (j) =
N->L->i[j];
1043 #if defined (HAVE_CXSPARSE)
1062 ret.
xcidx (j) =
N->U->p[j];
1066 ret.
xridx (j) =
N->U->i[j];
1074 octave_unused_parameter (econ);
1085 #if defined (HAVE_CXSPARSE)
1090 const cs_complex_t *bvec
1091 =
reinterpret_cast<const cs_complex_t *
> (b.
fortran_vec ());
1095 if (nr < 0 || nc < 0 || nr != b_nr)
1096 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1098 if (nr == 0 || nc == 0 || b_nc == 0)
1114 reinterpret_cast<cs_complex_t *
> (buf),
1124 reinterpret_cast<cs_complex_t *
> (buf));
1129 vec[i+idx] = buf[i];
1137 octave_unused_parameter (b);
1148 #if defined (HAVE_CXSPARSE)
1154 if (nr < 0 || nc < 0)
1155 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1157 if (nr == 0 || nc == 0)
1164 bvec[i] = cs_complex_t (0.0, 0.0);
1172 bvec[j] = cs_complex_t (1.0, 0.0);
1178 reinterpret_cast<cs_complex_t *
> (buf),
1188 reinterpret_cast<cs_complex_t *
> (buf));
1193 vec[i+idx] = buf[i];
1195 bvec[j] = cs_complex_t (0.0, 0.0);
1217 #if defined (HAVE_CXSPARSE)
1298 sz = (sz > 10 ? sz : 10) + x_nz;
1299 x.change_capacity (sz);
1317 octave_unused_parameter (b);
1333 #if defined (HAVE_CXSPARSE)
1418 sz = (sz > 10 ? sz : 10) + x_nz;
1419 x.change_capacity (sz);
1433 x.maybe_compress ();
1439 octave_unused_parameter (b);
1455 #if defined (HAVE_CXSPARSE)
1464 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
1474 Xx[j] = b.xelem (j,i);
1477 buf[j] = cs_complex_t (0.0, 0.0);
1481 reinterpret_cast<cs_complex_t *
>(Xx),
1506 octave_unused_parameter (b);
1522 #if defined (HAVE_CXSPARSE)
1534 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
1550 Xx[j] = b.xelem (j,i);
1553 buf[j] = cs_complex_t (0.0, 0.0);
1556 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
>(Xx),
1581 octave_unused_parameter (b);
1597 #if defined (HAVE_CXSPARSE)
1619 Xx[j] = b.xelem (j,i);
1622 buf[j] = cs_complex_t (0.0, 0.0);
1626 reinterpret_cast<cs_complex_t *
>(Xx),
1642 reinterpret_cast<cs_complex_t *
> (Xx),
1656 sz = (sz > 10 ? sz : 10) + x_nz;
1657 x.change_capacity (sz);
1671 x.maybe_compress ();
1677 octave_unused_parameter (b);
1693 #if defined (HAVE_CXSPARSE)
1723 Xx[j] = b.xelem (j,i);
1726 buf[j] = cs_complex_t (0.0, 0.0);
1730 reinterpret_cast<cs_complex_t *
>(Xx),
1746 reinterpret_cast<cs_complex_t *
> (Xx),
1760 sz = (sz > 10 ? sz : 10) + x_nz;
1761 x.change_capacity (sz);
1775 x.maybe_compress ();
1781 octave_unused_parameter (b);
1797 #if defined (HAVE_CXSPARSE)
1805 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
1809 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
>
1815 i++, idx+=nc, bidx+=b_nr)
1820 buf[j] = cs_complex_t (0.0, 0.0);
1847 octave_unused_parameter (b);
1863 #if defined (HAVE_CXSPARSE)
1874 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
1878 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
1889 i++, idx+=nc, bidx+=b_nr)
1894 buf[j] = cs_complex_t (0.0, 0.0);
1921 octave_unused_parameter (b);
1936 #if defined (HAVE_CXSPARSE)
1958 Xx[j] = b.
xelem (j,i);
1961 buf[j] = cs_complex_t (0.0, 0.0);
1965 reinterpret_cast<cs_complex_t *
>(Xx),
1981 reinterpret_cast<cs_complex_t *
> (Xx),
1995 sz = (sz > 10 ? sz : 10) + x_nz;
1996 x.change_capacity (sz);
2010 x.maybe_compress ();
2016 octave_unused_parameter (b);
2031 #if defined (HAVE_CXSPARSE)
2061 Xx[j] = b.
xelem (j,i);
2064 buf[j] = cs_complex_t (0.0, 0.0);
2067 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
>(Xx),
2083 reinterpret_cast<cs_complex_t *
>(Xx), nc);
2096 sz = (sz > 10 ? sz : 10) + x_nz;
2097 x.change_capacity (sz);
2111 x.maybe_compress ();
2117 octave_unused_parameter (b);
2124 template <
typename SPARSE_T>
2129 template <
typename SPARSE_T>
2134 template <
typename SPARSE_T>
2141 template <
typename SPARSE_T>
2144 if (--rep->count == 0)
2148 template <
typename SPARSE_T>
2154 if (--rep->count == 0)
2164 template <
typename SPARSE_T>
2171 template <
typename SPARSE_T>
2178 template <
typename SPARSE_T>
2185 template <
typename SPARSE_T>
2192 template <
typename SPARSE_T>
2196 return rep->R (econ);
2199 template <
typename SPARSE_T>
2200 typename SPARSE_T::dense_matrix_type
2206 template <
typename SPARSE_T>
2207 typename SPARSE_T::dense_matrix_type
2218 template <
typename SPARSE_T>
2223 enum { order = -1 };
2242 template <
typename SPARSE_T>
2243 template <
typename RHS_T,
typename RET_T>
2258 if (nr < 0 || nc < 0 || nr != b_nr)
2259 (*current_liboctave_error_handler)
2260 (
"matrix dimension mismatch in solution of minimum norm problem");
2262 if (nr == 0 || nc == 0 || b_nc == 0)
2266 return RET_T (nc, b_nc, 0.0);
2272 return q.
ok () ? q.
tall_solve<RHS_T, RET_T> (b, info) : RET_T ();
2278 return q.
ok () ? q.
wide_solve<RHS_T, RET_T> (b, info) : RET_T ();
2282 template <
typename SPARSE_T>
2283 template <
typename RHS_T,
typename RET_T>
2287 return rep->template tall_solve<RHS_T, RET_T> (b, info);
2290 template <
typename SPARSE_T>
2291 template <
typename RHS_T,
typename RET_T>
2295 return rep->template wide_solve<RHS_T, RET_T> (b, info);
2366 template class sparse_qr<SparseMatrix>;
2368 template class sparse_qr<SparseComplexMatrix>;
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type cols(void) const
octave_idx_type rows(void) const
const T * fortran_vec(void) const
Size of the specified dimension.
ComplexMatrix hermitian(void) const
Matrix transpose(void) const
octave_idx_type cols(void) const
octave_idx_type * xridx(void)
T & xelem(octave_idx_type n)
octave_idx_type * cidx(void)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
octave_idx_type rows(void) const
octave_idx_type * xcidx(void)
octave_idx_type * ridx(void)
SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b) const
SPARSE_T R(bool econ) const
cxsparse_types< SPARSE_T >::numeric_type * N
refcount< octave_idx_type > count
sparse_qr_rep(const SPARSE_T &a, int order)
RET_T wide_solve(const RHS_T &b, octave_idx_type &info) const
ColumnVector P(void) const
sparse_qr_rep(const sparse_qr_rep &)=delete
SPARSE_T::dense_matrix_type Q(void) const
RET_T tall_solve(const RHS_T &b, octave_idx_type &info) const
ColumnVector Pinv(void) const
cxsparse_types< SPARSE_T >::symbolic_type * S
RET_T tall_solve(const RHS_T &b, octave_idx_type &info) const
static RET_T solve(const SPARSE_T &a, const RHS_T &b, octave_idx_type &info)
SPARSE_T R(bool econ=false) const
ColumnVector Pinv(void) const
RET_T wide_solve(const RHS_T &b, octave_idx_type &info) const
sparse_qr & operator=(const sparse_qr &a)
ColumnVector P(void) const
SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b) const
SPARSE_T::dense_matrix_type Q(void) const
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
F77_RET_T const F77_INT & N
F77_RET_T const F77_INT F77_CMPLX * A
F77_RET_T const F77_DBLE * x
for(octave_idx_type i=0;i< n;i++) ac+
Matrix qrsolve(const SparseMatrix &a, const MArray< double > &b, octave_idx_type &info)
suitesparse_integer * to_suitesparse_intptr(octave_idx_type *i)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define CXSPARSE_DNAME(name)
#define CXSPARSE_ZNAME(name)
#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
#define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE