26 #if defined (HAVE_CONFIG_H)
46 #if defined (HAVE_CXSPARSE)
47 template <
typename SPARSE_T>
71 template <
typename SPARSE_T>
88 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
89 return (m_H && m_Htau && m_HPinv && m_R && m_E);
90 #elif defined (HAVE_CXSPARSE)
97 SPARSE_T
V (
void)
const;
105 SPARSE_T
R (
bool econ)
const;
107 typename SPARSE_T::dense_matrix_type
108 C (
const typename SPARSE_T::dense_matrix_type& b,
bool econ =
false);
110 typename SPARSE_T::dense_matrix_type
Q (
bool econ =
false);
115 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
117 template <
typename RHS_T,
typename RET_T>
122 #if defined (HAVE_CXSPARSE)
129 template <
typename RHS_T,
typename RET_T>
132 template <
typename RHS_T,
typename RET_T>
135 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
142 SuiteSparse_long *m_E;
144 cholmod_dense *m_Htau;
145 SuiteSparse_long *m_HPinv;
150 template <
typename SPARSE_T>
154 #if defined (HAVE_CXSPARSE)
159 ret.
xelem (i) =
S->pinv[i];
170 template <
typename SPARSE_T>
174 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
184 #elif defined (HAVE_CXSPARSE)
189 ret.
xelem (S->pinv[i]) = i;
200 template <
typename SPARSE_T>
204 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
224 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
228 static cholmod_sparse
238 A.itype = CHOLMOD_LONG;
243 A.xtype = CHOLMOD_REAL;
244 A.dtype = CHOLMOD_DOUBLE;
249 A.p =
reinterpret_cast<SuiteSparse_long *
> (a.
cidx ());
250 A.i =
reinterpret_cast<SuiteSparse_long *
> (a.
ridx ());
254 SuiteSparse_long *A_p;
255 A_p =
new SuiteSparse_long[ncols+1];
259 SuiteSparse_long *A_i;
260 A_i =
new SuiteSparse_long[nnz];
265 A.x =
const_cast<double *
> (a.
data ());
272 static cholmod_sparse
282 A.itype = CHOLMOD_LONG;
287 A.xtype = CHOLMOD_COMPLEX;
288 A.dtype = CHOLMOD_DOUBLE;
293 A.p =
reinterpret_cast<SuiteSparse_long *
> (a.
cidx ());
294 A.i =
reinterpret_cast<SuiteSparse_long *
> (a.
ridx ());
298 SuiteSparse_long *A_p;
299 A_p =
new SuiteSparse_long[ncols+1];
303 SuiteSparse_long *A_i;
304 A_i =
new SuiteSparse_long[nnz];
317 static cholmod_dense *
321 = cholmod_l_allocate_dense (a.
rows (), a.
cols (), a.
rows(),
322 CHOLMOD_COMPLEX, cc1);
324 const double *a_x = a.
data ();
328 A_x[j] =
Complex (a_x[j], 0.0);
343 A.xtype = CHOLMOD_REAL;
344 A.dtype = CHOLMOD_DOUBLE;
347 A.x =
const_cast<double *
> (a.
data ());
362 A.xtype = CHOLMOD_COMPLEX;
363 A.dtype = CHOLMOD_DOUBLE;
374 rcs2ros (
const cholmod_sparse *y)
381 SuiteSparse_long *y_p =
reinterpret_cast<SuiteSparse_long *
> (y->p);
385 SuiteSparse_long *y_i =
reinterpret_cast<SuiteSparse_long *
> (y->i);
386 double *y_x =
reinterpret_cast<double *
> (y->x);
390 ret.xdata (j) = y_x[j];
399 ccs2cos (
const cholmod_sparse *a)
406 SuiteSparse_long *a_p =
reinterpret_cast<SuiteSparse_long *
> (a->p);
410 SuiteSparse_long *a_i =
reinterpret_cast<SuiteSparse_long *
> (a->i);
415 ret.xdata(j) = a_x[j];
423 static cholmod_sparse *
427 = cholmod_l_allocate_sparse (a.
rows (), a.
cols (), a.
nnz (), 0, 1, 0,
428 CHOLMOD_COMPLEX, cc);
431 SuiteSparse_long *A_p =
reinterpret_cast<SuiteSparse_long *
> (
A->p);
435 const double *a_x = a.
data ();
437 SuiteSparse_long *A_i =
reinterpret_cast<SuiteSparse_long *
> (
A->i);
440 A_x[j] =
Complex (a_x[j], 0.0);
447 suitesparse_long_to_suitesparse_integer (SuiteSparse_long
x)
451 (*current_liboctave_error_handler)
452 (
"integer dimension or index out of range for SuiteSparse's indexing type");
458 spqr_error_handler (
const cholmod_common *cc)
465 case CHOLMOD_OUT_OF_MEMORY:
466 (*current_liboctave_error_handler)
467 (
"sparse_qr: sparse matrix QR factorization failed"
469 case CHOLMOD_TOO_LARGE:
470 (*current_liboctave_error_handler)
471 (
"sparse_qr: sparse matrix QR factorization failed"
472 " - integer overflow occurred");
474 (*current_liboctave_error_handler)
475 (
"sparse_qr: sparse matrix QR factorization failed"
476 " - error %d", cc->status);
504 : nrows (a.rows ()), ncols (a.columns ())
505 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
506 , m_cc (), m_R (nullptr), m_E (nullptr), m_H (nullptr), m_Htau (nullptr),
512 if (nr < 0 || nc < 0)
513 (*current_liboctave_error_handler)
514 (
"matrix dimension with negative size");
516 if (order < 0 || order > 9)
517 (*current_liboctave_error_handler)
518 (
"ordering %d is not supported by SPQR", order);
520 cholmod_l_start (&m_cc);
521 cholmod_sparse
A = ros2rcs (a);
523 SuiteSparseQR<double> (order,
static_cast<double> (SPQR_DEFAULT_TOL),
524 static_cast<SuiteSparse_long
> (
A.nrow),
525 &
A, &m_R, &m_E, &m_H, &m_HPinv, &m_Htau, &m_cc);
526 spqr_error_handler (&m_cc);
530 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
531 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
535 #elif defined (HAVE_CXSPARSE)
536 , S (
nullptr),
N (
nullptr)
549 A.
x = const_cast<
double *> (a.data ());
557 ("
sparse_qr: sparse matrix QR factorization filled");
564 octave_unused_parameter (order);
566 (*current_liboctave_error_handler)
567 (
"sparse_qr: support for SPQR or CXSparse was unavailable or disabled when liboctave was built");
575 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
577 cholmod_l_free_sparse (&m_R, &m_cc);
578 cholmod_l_free_sparse (&m_H, &m_cc);
579 cholmod_l_free_dense (&m_Htau, &m_cc);
582 cholmod_l_finish (&m_cc);
584 #elif defined (HAVE_CXSPARSE)
596 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
598 return rcs2ros (m_H);
600 #elif defined (HAVE_CXSPARSE)
616 ret.
xcidx (j) =
N->L->p[j];
620 ret.
xridx (j) =
N->L->i[j];
621 ret.
xdata (j) =
N->L->x[j];
637 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
644 SparseMatrix ret ((econ ? (nc > nr ? nr : nc) : nr), nc, nz);
645 SuiteSparse_long *Rp =
reinterpret_cast<SuiteSparse_long *
> (m_R->p);
646 SuiteSparse_long *Ri =
reinterpret_cast<SuiteSparse_long *
> (m_R->i);
654 ret.
xdata (j) = (
reinterpret_cast<double *
> (m_R->x))[j];
659 #elif defined (HAVE_CXSPARSE)
673 SparseMatrix ret ((econ ? (nc > nrows ? nrows : nc) : nrows), nc, nz);
676 ret.
xcidx (j) =
N->U->p[j];
680 ret.
xridx (j) =
N->U->i[j];
681 ret.
xdata (j) =
N->U->x[j];
688 octave_unused_parameter (econ);
699 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
701 ? (ncols > nrows ? nrows : ncols)
708 (*current_liboctave_error_handler)
709 (
"sparse_qr: matrix dimension mismatch");
710 else if (b_nc < 0 || b_nr < 0)
711 (*current_liboctave_error_handler)
712 (
"sparse_qr: matrix dimension with negative size");
715 cholmod_dense
B = rod2rcd (b);
717 QTB = SuiteSparseQR_qmult<double> (SPQR_QTX, m_H, m_Htau, m_HPinv, &
B,
719 spqr_error_handler (&m_cc);
722 double *QTB_x =
reinterpret_cast<double *
> (QTB->x);
723 double *ret_vec =
reinterpret_cast<double *
> (ret.
fortran_vec ());
726 ret_vec[j * nr + i] = QTB_x[j * b_nr + i];
728 cholmod_l_free_dense (&QTB, &m_cc);
732 #elif defined (HAVE_CXSPARSE)
735 (*current_liboctave_error_handler)
736 (
"sparse-qr: economy mode with CXSparse not supported");
744 const double *bvec = b.
data ();
749 if (nr < 0 || nc < 0 || nr != b_nr)
750 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
752 if (nr == 0 || nc == 0 || b_nc == 0)
753 ret =
Matrix (nc, b_nc, 0.0);
787 octave_unused_parameter (b);
788 octave_unused_parameter (econ);
799 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
802 ? (ncols > nrows ? nrows : ncols)
809 = cholmod_l_allocate_dense (nrows, nrows, nrows, CHOLMOD_REAL, &m_cc);
812 (
reinterpret_cast<double *
> (I->x))[i] = 0.0;
815 (
reinterpret_cast<double *
> (I->x))[i * nrows + i] = 1.0;
817 q = SuiteSparseQR_qmult<double> (SPQR_QX, m_H, m_Htau, m_HPinv, I, &m_cc);
818 spqr_error_handler (&m_cc);
820 double *q_x =
reinterpret_cast<double *
> (q->x);
821 double *ret_vec =
const_cast<double *
> (ret.
fortran_vec ());
824 ret_vec[j * nrows + i] = q_x[j * nrows + i];
826 cholmod_l_free_dense (&q, &m_cc);
827 cholmod_l_free_dense (&I, &m_cc);
831 #elif defined (HAVE_CXSPARSE)
834 (*current_liboctave_error_handler)
835 (
"sparse-qr: economy mode with CXSparse not supported");
842 if (nr < 0 || nc < 0)
843 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
845 if (nr == 0 || nc == 0)
846 ret =
Matrix (nc, nr, 0.0);
876 ret_vec[i+idx] = buf[i];
886 octave_unused_parameter (econ);
901 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD) && defined (HAVE_CXSPARSE))
907 if (nrows < 0 || ncols < 0 || b_nc < 0 || b_nr < 0)
908 (*current_liboctave_error_handler)
909 (
"matrix dimension with negative size");
911 if (nrows < 0 || ncols < 0 || nrows != b_nr)
912 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
915 cholmod_dense
B = rod2rcd (b);
919 QTB = SuiteSparseQR_qmult<double> (SPQR_QTX, m_H, m_Htau, m_HPinv, &
B,
922 spqr_error_handler (&m_cc);
928 R2.nzmax = m_R->nzmax;
929 R2.x =
reinterpret_cast<double *
> (m_R->x);
940 SuiteSparse_long *R_p =
reinterpret_cast<SuiteSparse_long *
> (m_R->p);
942 R2_p[i] = suitesparse_long_to_suitesparse_integer (R_p[i]);
946 SuiteSparse_long *R_i =
reinterpret_cast<SuiteSparse_long *
> (m_R->i);
948 R2_i[i] = suitesparse_long_to_suitesparse_integer (R_i[i]);
952 double *x_vec =
const_cast<double *
> (
x.fortran_vec ());
958 E[i] = suitesparse_long_to_suitesparse_integer (m_E[i]);
967 (&R2, &(
reinterpret_cast<double *
> (QTB->x)[j * b_nr]));
970 (
E, &(
reinterpret_cast<double *
> (QTB->x)[j * b_nr]),
971 &x_vec[j * ncols], ncols);
980 cholmod_l_free_dense (&QTB, &m_cc);
986 #elif defined (HAVE_CXSPARSE)
994 const double *bvec = b.data ();
997 double *vec =
x.fortran_vec ();
1002 i++, idx+=nc, bidx+=b_nr)
1028 octave_unused_parameter (b);
1042 #if defined (HAVE_CXSPARSE)
1053 const double *bvec = b.data ();
1056 double *vec =
x.fortran_vec ();
1063 i++, idx+=nc, bidx+=b_nr)
1088 octave_unused_parameter (b);
1103 #if defined (HAVE_CXSPARSE)
1125 Xx[j] = b.
xelem (j, i);
1152 sz = (sz > 10 ? sz : 10) + x_nz;
1153 x.change_capacity (sz);
1171 octave_unused_parameter (b);
1186 #if defined (HAVE_CXSPARSE)
1212 Xx[j] = b.
xelem (j, i);
1239 sz = (sz > 10 ? sz : 10) + x_nz;
1240 x.change_capacity (sz);
1254 x.maybe_compress ();
1260 octave_unused_parameter (b);
1275 #if defined (HAVE_CXSPARSE)
1332 vec[j+idx] =
Complex (Xx[j], Xz[j]);
1341 octave_unused_parameter (b);
1356 #if defined (HAVE_CXSPARSE)
1418 vec[j+idx] =
Complex (Xx[j], Xz[j]);
1427 octave_unused_parameter (b);
1439 : nrows (a.rows ()), ncols (a.columns ())
1440 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1441 , m_cc (), m_R (nullptr), m_E (nullptr), m_H (nullptr),
1442 m_Htau (nullptr), m_HPinv (nullptr)
1447 if (nr < 0 || nc < 0)
1448 (*current_liboctave_error_handler)
1449 (
"matrix dimension with negative size");
1451 if (order < 0 || order > 9)
1452 (*current_liboctave_error_handler)
1453 (
"ordering %d is not supported by SPQR", order);
1455 cholmod_l_start (&m_cc);
1456 cholmod_sparse
A = cos2ccs (a);
1458 SuiteSparseQR<Complex> (order,
static_cast<double> (SPQR_DEFAULT_TOL),
1459 static_cast<SuiteSparse_long
> (
A.nrow),
1460 &
A, &m_R, &m_E, &m_H,
1461 &m_HPinv, &m_Htau, &m_cc);
1462 spqr_error_handler (&m_cc);
1466 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
1467 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
1471 #elif defined (HAVE_CXSPARSE)
1472 , S (
nullptr),
N (
nullptr)
1485 A.
x = const_cast<cs_complex_t *>
1486 (reinterpret_cast<const cs_complex_t *> (a.data ()));
1494 ("
sparse_qr: sparse matrix QR factorization filled");
1501 octave_unused_parameter (order);
1503 (*current_liboctave_error_handler)
1504 (
"sparse_qr: support for CXSparse was unavailable or disabled when liboctave was built");
1512 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1514 cholmod_l_free_sparse (&m_R, &m_cc);
1515 cholmod_l_free_sparse (&m_H, &m_cc);
1516 cholmod_l_free_dense (&m_Htau, &m_cc);
1519 cholmod_l_finish (&m_cc);
1521 #elif defined (HAVE_CXSPARSE)
1533 #if defined (HAVE_CXSPARSE)
1548 ret.
xcidx (j) =
N->L->p[j];
1552 ret.
xridx (j) =
N->L->i[j];
1569 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1577 SuiteSparse_long *Rp =
reinterpret_cast<SuiteSparse_long *
> (m_R->p);
1578 SuiteSparse_long *Ri =
reinterpret_cast<SuiteSparse_long *
> (m_R->i);
1586 ret.
xdata (j) = (
reinterpret_cast<Complex *
> (m_R->x))[j];
1591 #elif defined (HAVE_CXSPARSE)
1609 ret.
xcidx (j) =
N->U->p[j];
1613 ret.
xridx (j) =
N->U->i[j];
1621 octave_unused_parameter (econ);
1633 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1637 ? (ncols > nrows ? nrows : ncols)
1644 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1646 if (b_nc < 0 || b_nr < 0)
1647 (*current_liboctave_error_handler)
1648 (
"matrix dimension with negative size");
1651 cholmod_dense
B = cod2ccd (b);
1653 QTB = SuiteSparseQR_qmult<Complex> (SPQR_QTX, m_H, m_Htau, m_HPinv, &
B,
1655 spqr_error_handler (&m_cc);
1662 ret_vec[j * nr + i] = QTB_x[j * b_nr + i];
1664 cholmod_l_free_dense (&QTB, &m_cc);
1668 #elif defined (HAVE_CXSPARSE)
1671 (*current_liboctave_error_handler)
1672 (
"sparse-qr: economy mode with CXSparse not supported");
1678 const cs_complex_t *bvec
1679 =
reinterpret_cast<const cs_complex_t *
> (b.
data ());
1683 if (nr < 0 || nc < 0 || nr != b_nr)
1684 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1686 if (nr == 0 || nc == 0 || b_nc == 0)
1701 reinterpret_cast<cs_complex_t *
> (buf),
1709 reinterpret_cast<cs_complex_t *
> (buf));
1713 vec[i+idx] = buf[i];
1721 octave_unused_parameter (b);
1722 octave_unused_parameter (econ);
1733 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1736 ? (ncols > nrows ? nrows : ncols)
1743 =
reinterpret_cast<cholmod_dense *
>
1744 (cholmod_l_allocate_dense (nrows, nrows, nrows, CHOLMOD_COMPLEX, &m_cc));
1747 (
reinterpret_cast<Complex *
> (I->x))[i] = 0.0;
1750 (
reinterpret_cast<Complex *
> (I->x))[i * nrows + i] = 1.0;
1752 q = SuiteSparseQR_qmult<Complex> (SPQR_QX, m_H, m_Htau, m_HPinv, I,
1754 spqr_error_handler (&m_cc);
1761 ret_vec[j * nrows + i] = q_x[j * nrows + i];
1763 cholmod_l_free_dense (&q, &m_cc);
1764 cholmod_l_free_dense (&I, &m_cc);
1768 #elif defined (HAVE_CXSPARSE)
1771 (*current_liboctave_error_handler)
1772 (
"sparse-qr: economy mode with CXSparse not supported");
1779 if (nr < 0 || nc < 0)
1780 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1782 if (nr == 0 || nc == 0)
1789 bvec[i] = cs_complex_t (0.0, 0.0);
1797 bvec[j] = cs_complex_t (1.0, 0.0);
1802 reinterpret_cast<cs_complex_t *
> (buf),
1810 reinterpret_cast<cs_complex_t *
> (buf));
1814 vec[i+idx] = buf[i];
1816 bvec[j] = cs_complex_t (0.0, 0.0);
1824 octave_unused_parameter (econ);
1840 #if defined (HAVE_CXSPARSE)
1909 sz = (sz > 10 ? sz : 10) + x_nz;
1910 x.change_capacity (sz);
1928 octave_unused_parameter (b);
1944 #if defined (HAVE_CXSPARSE)
2017 sz = (sz > 10 ? sz : 10) + x_nz;
2018 x.change_capacity (sz);
2032 x.maybe_compress ();
2038 octave_unused_parameter (b);
2054 #if defined (HAVE_CXSPARSE)
2063 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2073 Xx[j] = b.xelem (j, i);
2076 buf[j] = cs_complex_t (0.0, 0.0);
2079 reinterpret_cast<cs_complex_t *
>(Xx),
2099 octave_unused_parameter (b);
2115 #if defined (HAVE_CXSPARSE)
2127 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2143 Xx[j] = b.xelem (j, i);
2146 buf[j] = cs_complex_t (0.0, 0.0);
2148 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
> (Xx),
2168 octave_unused_parameter (b);
2184 #if defined (HAVE_CXSPARSE)
2206 Xx[j] = b.xelem (j, i);
2209 buf[j] = cs_complex_t (0.0, 0.0);
2212 reinterpret_cast<cs_complex_t *
> (Xx),
2224 reinterpret_cast<cs_complex_t *
> (Xx),
2237 sz = (sz > 10 ? sz : 10) + x_nz;
2238 x.change_capacity (sz);
2252 x.maybe_compress ();
2258 octave_unused_parameter (b);
2274 #if defined (HAVE_CXSPARSE)
2304 Xx[j] = b.xelem (j, i);
2307 buf[j] = cs_complex_t (0.0, 0.0);
2310 reinterpret_cast<cs_complex_t *
> (Xx),
2322 reinterpret_cast<cs_complex_t *
> (Xx),
2335 sz = (sz > 10 ? sz : 10) + x_nz;
2336 x.change_capacity (sz);
2350 x.maybe_compress ();
2356 octave_unused_parameter (b);
2372 #if defined (HAVE_CXSPARSE)
2380 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
2384 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
>
2390 i++, idx+=nc, bidx+=b_nr)
2395 buf[j] = cs_complex_t (0.0, 0.0);
2416 octave_unused_parameter (b);
2432 #if defined (HAVE_CXSPARSE)
2443 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
2447 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2458 i++, idx+=nc, bidx+=b_nr)
2463 buf[j] = cs_complex_t (0.0, 0.0);
2484 octave_unused_parameter (b);
2500 #if defined (HAVE_CXSPARSE)
2522 Xx[j] = b.xelem (j, i);
2525 buf[j] = cs_complex_t (0.0, 0.0);
2528 reinterpret_cast<cs_complex_t *
> (Xx),
2540 reinterpret_cast<cs_complex_t *
> (Xx),
2553 sz = (sz > 10 ? sz : 10) + x_nz;
2554 x.change_capacity (sz);
2568 x.maybe_compress ();
2574 octave_unused_parameter (b);
2590 #if defined (HAVE_CXSPARSE)
2620 Xx[j] = b.xelem (j, i);
2623 buf[j] = cs_complex_t (0.0, 0.0);
2625 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
>(Xx),
2637 reinterpret_cast<cs_complex_t *
>(Xx), nc);
2649 sz = (sz > 10 ? sz : 10) + x_nz;
2650 x.change_capacity (sz);
2664 x.maybe_compress ();
2670 octave_unused_parameter (b);
2677 template <
typename SPARSE_T>
2682 template <
typename SPARSE_T>
2687 template <
typename SPARSE_T>
2691 return m_rep->ok ();
2694 template <
typename SPARSE_T>
2701 template <
typename SPARSE_T>
2708 template <
typename SPARSE_T>
2715 template <
typename SPARSE_T>
2723 template <
typename SPARSE_T>
2731 ret(perm(i) - 1, i) = 1.0;
2736 template <
typename SPARSE_T>
2740 return m_rep->R (econ);
2743 template <
typename SPARSE_T>
2744 typename SPARSE_T::dense_matrix_type
2748 return m_rep->C (b, econ);
2751 template <
typename SPARSE_T>
2752 typename SPARSE_T::dense_matrix_type
2755 return m_rep->Q (econ);
2758 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
2773 cholmod_l_start (&cc);
2774 cholmod_sparse
A = ros2rcs (a);
2775 cholmod_dense
B = rod2rcd (b);
2778 X = SuiteSparseQR_min2norm<double> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2779 spqr_error_handler (&cc);
2781 double *vec =
x.fortran_vec ();
2783 vec[i] =
reinterpret_cast<double *
> (X->x)[i];
2788 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2789 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2791 cholmod_l_finish (&cc);
2808 cholmod_l_start (&cc);
2809 cholmod_sparse
A = ros2rcs (a);
2810 cholmod_sparse
B = ros2rcs (b);
2813 X = SuiteSparseQR_min2norm<double> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2814 spqr_error_handler (&cc);
2818 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2819 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2820 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
2821 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
2825 cholmod_l_finish (&cc);
2848 cholmod_l_start (&cc);
2850 cholmod_sparse *
A = ros2ccs (a, &cc);
2851 cholmod_dense
B = cod2ccd (b);
2854 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL,
A, &
B, &cc);
2855 spqr_error_handler (&cc);
2859 vec[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2861 cholmod_l_free_sparse (&
A, &cc);
2862 cholmod_l_finish (&cc);
2882 cholmod_l_start (&cc);
2884 cholmod_sparse *
A = ros2ccs (a, &cc);
2885 cholmod_sparse
B = cos2ccs (b);
2888 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL,
A, &
B, &cc);
2889 spqr_error_handler (&cc);
2891 cholmod_l_free_sparse (&
A, &cc);
2894 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
2895 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
2897 cholmod_l_finish (&cc);
2922 cholmod_l_start (&cc);
2924 cholmod_sparse
A = cos2ccs (a);
2925 cholmod_dense
B = cod2ccd (b);
2928 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2929 spqr_error_handler (&cc);
2933 vec[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2937 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2938 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2940 cholmod_l_finish (&cc);
2964 cholmod_l_start (&cc);
2966 cholmod_sparse
A = cos2ccs (a);
2967 cholmod_dense *
B = rod2ccd (b, &cc);
2970 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A,
B, &cc);
2971 spqr_error_handler (&cc);
2976 vec[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2980 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2981 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2983 cholmod_l_free_dense (&
B, &cc);
2984 cholmod_l_finish (&cc);
3004 cholmod_l_start (&cc);
3006 cholmod_sparse
A = cos2ccs (a);
3007 cholmod_sparse
B = cos2ccs (b);
3010 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
3011 spqr_error_handler (&cc);
3015 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
3016 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
3017 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
3018 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
3020 cholmod_l_finish (&cc);
3040 cholmod_l_start (&cc);
3042 cholmod_sparse
A = cos2ccs (a);
3043 cholmod_sparse *
B = ros2ccs (b, &cc);
3046 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A,
B, &cc);
3047 spqr_error_handler (&cc);
3053 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
3054 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
3056 cholmod_l_free_sparse (&
B, &cc);
3057 cholmod_l_finish (&cc);
3071 template <
typename SPARSE_T>
3076 enum { order = -1 };
3084 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3085 enum { order = SPQR_ORDERING_DEFAULT };
3086 #elif defined (HAVE_CXSPARSE)
3096 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3097 enum { order = SPQR_ORDERING_DEFAULT };
3098 #elif defined (HAVE_CXSPARSE)
3103 template <
typename SPARSE_T>
3104 template <
typename RHS_T,
typename RET_T>
3109 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3121 if (nr < 0 || nc < 0 || b_nc < 0 || b_nr < 0)
3122 (*current_liboctave_error_handler)
3123 (
"matrix dimension with negative size");
3126 (*current_liboctave_error_handler)
3127 (
"matrix dimension mismatch in solution of minimum norm problem");
3131 return min2norm_solve<RHS_T, RET_T> (a, b, info, order);
3133 #elif defined (HAVE_CXSPARSE)
3145 if (nr < 0 || nc < 0 || nr != b_nr)
3146 (*current_liboctave_error_handler)
3147 (
"matrix dimension mismatch in solution of minimum norm problem");
3149 if (nr == 0 || nc == 0 || b_nc == 0)
3153 return RET_T (nc, b_nc, 0.0);
3159 return q.
ok () ? q.
tall_solve<RHS_T, RET_T> (b, info) : RET_T ();
3165 return q.
ok () ? q.
wide_solve<RHS_T, RET_T> (b, info) : RET_T ();
3170 octave_unused_parameter (a);
3171 octave_unused_parameter (b);
3172 octave_unused_parameter (info);
3235 template <
typename SPARSE_T>
3236 template <
typename RHS_T,
typename RET_T>
3240 return m_rep->template tall_solve<RHS_T, RET_T> (b, info);
3243 template <
typename SPARSE_T>
3244 template <
typename RHS_T,
typename RET_T>
3248 return m_rep->template wide_solve<RHS_T, RET_T> (b, info);
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols(void) const
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
ComplexMatrix hermitian(void) const
Matrix transpose(void) const
octave_idx_type rows(void) const
octave_idx_type * cidx(void)
octave_idx_type * ridx(void)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
T & xelem(octave_idx_type n)
octave_idx_type cols(void) const
octave_idx_type * xcidx(void)
octave_idx_type * xridx(void)
ColumnVector E(void) const
ColumnVector P(void) const
RET_T tall_solve(const RHS_T &b, octave_idx_type &info)
cxsparse_types< SPARSE_T >::symbolic_type * S
SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b, bool econ=false)
sparse_qr_rep(const SPARSE_T &a, int order)
SPARSE_T R(bool econ) const
ColumnVector Pinv(void) const
RET_T wide_solve(const RHS_T &b, octave_idx_type &info) const
cxsparse_types< SPARSE_T >::numeric_type * N
sparse_qr_rep(const sparse_qr_rep &)=delete
SPARSE_T::dense_matrix_type Q(bool econ=false)
OCTAVE_API RET_T tall_solve(const RHS_T &b, octave_idx_type &info) const
OCTAVE_API SPARSE_T V(void) const
OCTAVE_API SPARSE_T::dense_matrix_type Q(bool econ=false) const
OCTAVE_API ColumnVector P(void) const
OCTAVE_API ColumnVector Pinv(void) const
static OCTAVE_API RET_T solve(const SPARSE_T &a, const RHS_T &b, octave_idx_type &info)
OCTAVE_API ColumnVector E(void) const
OCTAVE_API SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b, bool econ=false) const
sparse_qr & operator=(const sparse_qr &a)=default
OCTAVE_API SparseMatrix E_MAT() const
OCTAVE_API sparse_qr(void)
std::shared_ptr< sparse_qr_rep > m_rep
OCTAVE_API RET_T wide_solve(const RHS_T &b, octave_idx_type &info) const
OCTAVE_API bool ok(void) const
OCTAVE_API SPARSE_T R(bool econ=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
F77_RET_T const F77_INT F77_CMPLX * A
F77_RET_T const F77_INT & N
F77_RET_T const F77_DBLE * x
class OCTAVE_API ComplexMatrix
class OCTAVE_API SparseMatrix
class OCTAVE_API ColumnVector
class OCTAVE_API SparseComplexMatrix
for(octave_idx_type i=0;i< n;i++) ac+
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
suitesparse_integer * to_suitesparse_intptr(octave_idx_type *i)
#define CXSPARSE_DNAME(name)
#define CXSPARSE_ZNAME(name)
octave_idx_type from_suitesparse_long(SuiteSparse_long x)
octave_idx_type from_size_t(std::size_t x)
Matrix qrsolve(const SparseMatrix &a, const MArray< double > &b, octave_idx_type &info)