26 #if defined (HAVE_CONFIG_H)
46 #if defined (HAVE_CXSPARSE)
47 template <
typename SPARSE_T>
54 cxsparse_types<SparseMatrix>
63 cxsparse_types<SparseComplexMatrix>
71 template <
typename SPARSE_T>
76 sparse_qr_rep (
const SPARSE_T& a,
int order);
78 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (sparse_qr_rep)
84 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
85 return (m_H && m_Htau && m_HPinv && m_R && m_E);
86 #elif defined (HAVE_CXSPARSE)
101 SPARSE_T
R (
bool econ)
const;
103 typename SPARSE_T::dense_matrix_type
104 C (
const typename SPARSE_T::dense_matrix_type& b,
bool econ =
false);
106 typename SPARSE_T::dense_matrix_type
Q (
bool econ =
false);
111 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
113 template <
typename RHS_T,
typename RET_T>
118 #if defined (HAVE_CXSPARSE)
120 typename cxsparse_types<SPARSE_T>::symbolic_type *S;
121 typename cxsparse_types<SPARSE_T>::numeric_type *
N;
125 template <
typename RHS_T,
typename RET_T>
128 template <
typename RHS_T,
typename RET_T>
131 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
138 SuiteSparse_long *m_E;
140 cholmod_dense *m_Htau;
141 SuiteSparse_long *m_HPinv;
146 template <
typename SPARSE_T>
150 #if defined (HAVE_CXSPARSE)
155 ret.xelem (i) = S->pinv[i];
166 template <
typename SPARSE_T>
170 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
180 #elif defined (HAVE_CXSPARSE)
185 ret.xelem (S->pinv[i]) = i;
196 template <
typename SPARSE_T>
200 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
220 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
224 static cholmod_sparse
234 A.itype = CHOLMOD_LONG;
239 A.xtype = CHOLMOD_REAL;
240 A.dtype = CHOLMOD_DOUBLE;
245 A.p =
reinterpret_cast<SuiteSparse_long *
> (a.
cidx ());
246 A.i =
reinterpret_cast<SuiteSparse_long *
> (a.
ridx ());
250 SuiteSparse_long *A_p;
251 A_p =
new SuiteSparse_long[ncols+1];
255 SuiteSparse_long *A_i;
256 A_i =
new SuiteSparse_long[nnz];
261 A.x =
const_cast<double *
> (a.
data ());
268 static cholmod_sparse
278 A.itype = CHOLMOD_LONG;
283 A.xtype = CHOLMOD_COMPLEX;
284 A.dtype = CHOLMOD_DOUBLE;
289 A.p =
reinterpret_cast<SuiteSparse_long *
> (a.
cidx ());
290 A.i =
reinterpret_cast<SuiteSparse_long *
> (a.
ridx ());
294 SuiteSparse_long *A_p;
295 A_p =
new SuiteSparse_long[ncols+1];
299 SuiteSparse_long *A_i;
300 A_i =
new SuiteSparse_long[nnz];
313 static cholmod_dense *
317 = cholmod_l_allocate_dense (a.
rows (), a.
cols (), a.
rows(),
318 CHOLMOD_COMPLEX, cc1);
320 const double *a_x = a.
data ();
324 A_x[j] =
Complex (a_x[j], 0.0);
339 A.xtype = CHOLMOD_REAL;
340 A.dtype = CHOLMOD_DOUBLE;
343 A.x =
const_cast<double *
> (a.
data ());
358 A.xtype = CHOLMOD_COMPLEX;
359 A.dtype = CHOLMOD_DOUBLE;
370 rcs2ros (cholmod_sparse *y,
const cholmod_common *cc1)
376 (cholmod_l_nnz (y,
const_cast<cholmod_common *
> (cc1)));
379 SuiteSparse_long *y_p =
reinterpret_cast<SuiteSparse_long *
> (y->p);
383 SuiteSparse_long *y_i =
reinterpret_cast<SuiteSparse_long *
> (y->i);
384 double *y_x =
reinterpret_cast<double *
> (y->x);
388 ret.xdata (j) = y_x[j];
397 ccs2cos (cholmod_sparse *a, cholmod_common *cc1)
404 SuiteSparse_long *a_p =
reinterpret_cast<SuiteSparse_long *
> (a->p);
408 SuiteSparse_long *a_i =
reinterpret_cast<SuiteSparse_long *
> (a->i);
413 ret.xdata(j) = a_x[j];
421 static cholmod_sparse *
425 = cholmod_l_allocate_sparse (a.
rows (), a.
cols (), a.
nnz (), 0, 1, 0,
426 CHOLMOD_COMPLEX, cc);
429 SuiteSparse_long *A_p =
reinterpret_cast<SuiteSparse_long *
> (
A->p);
433 const double *a_x = a.
data ();
435 SuiteSparse_long *A_i =
reinterpret_cast<SuiteSparse_long *
> (
A->i);
438 A_x[j] =
Complex (a_x[j], 0.0);
445 suitesparse_long_to_suitesparse_integer (SuiteSparse_long
x)
449 (*current_liboctave_error_handler)
450 (
"integer dimension or index out of range for SuiteSparse's indexing type");
456 spqr_error_handler (
const cholmod_common *cc)
463 case CHOLMOD_OUT_OF_MEMORY:
464 (*current_liboctave_error_handler)
465 (
"sparse_qr: sparse matrix QR factorization failed"
467 case CHOLMOD_TOO_LARGE:
468 (*current_liboctave_error_handler)
469 (
"sparse_qr: sparse matrix QR factorization failed"
470 " - integer overflow occurred");
472 (*current_liboctave_error_handler)
473 (
"sparse_qr: sparse matrix QR factorization failed"
474 " - error %d", cc->status);
502 : nrows (a.rows ()), ncols (a.columns ())
503 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
504 , m_cc (), m_R (nullptr), m_E (nullptr), m_H (nullptr), m_Htau (nullptr),
510 if (nr < 0 || nc < 0)
511 (*current_liboctave_error_handler)
512 (
"matrix dimension with negative size");
514 if (order < 0 || order > 9)
515 (*current_liboctave_error_handler)
516 (
"ordering %d is not supported by SPQR", order);
518 cholmod_l_start (&m_cc);
519 cholmod_sparse
A = ros2rcs (a);
521 SuiteSparseQR<double> (order,
static_cast<double> (SPQR_DEFAULT_TOL),
522 static_cast<SuiteSparse_long
> (
A.nrow),
523 &
A, &m_R, &m_E, &m_H, &m_HPinv, &m_Htau, &m_cc);
524 spqr_error_handler (&m_cc);
528 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
529 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
533 #elif defined (HAVE_CXSPARSE)
534 , S (
nullptr),
N (
nullptr)
547 A.
x = const_cast<
double *> (a.data ());
555 ("
sparse_qr: sparse matrix QR factorization filled");
562 octave_unused_parameter (order);
564 (*current_liboctave_error_handler)
565 (
"sparse_qr: support for SPQR or CXSparse was unavailable or disabled when liboctave was built");
573 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
575 cholmod_l_free_sparse (&m_R, &m_cc);
576 cholmod_l_free_sparse (&m_H, &m_cc);
577 cholmod_l_free_dense (&m_Htau, &m_cc);
580 cholmod_l_finish (&m_cc);
582 #elif defined (HAVE_CXSPARSE)
594 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
596 return rcs2ros (m_H, &m_cc);
598 #elif defined (HAVE_CXSPARSE)
614 ret.xcidx (j) =
N->L->p[j];
618 ret.xridx (j) =
N->L->i[j];
619 ret.xdata (j) =
N->L->x[j];
635 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
641 (cholmod_l_nnz (m_R,
const_cast<cholmod_common *
> (&m_cc)));
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 ();
747 double *vec = ret.fortran_vec ();
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_mat->x))[i] = 0.0;
815 (
reinterpret_cast<double *
> (I_mat->x))[i * nrows + i] = 1.0;
817 q = SuiteSparseQR_qmult<double> (SPQR_QX, m_H, m_Htau, m_HPinv, I_mat,
819 spqr_error_handler (&m_cc);
821 double *q_x =
reinterpret_cast<double *
> (q->x);
822 double *ret_vec =
const_cast<double *
> (ret.fortran_vec ());
825 ret_vec[j * nrows + i] = q_x[j * nrows + i];
827 cholmod_l_free_dense (&q, &m_cc);
828 cholmod_l_free_dense (&I_mat, &m_cc);
832 #elif defined (HAVE_CXSPARSE)
835 (*current_liboctave_error_handler)
836 (
"sparse-qr: economy mode with CXSparse not supported");
841 double *ret_vec = ret.fortran_vec ();
843 if (nr < 0 || nc < 0)
844 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
846 if (nr == 0 || nc == 0)
847 ret =
Matrix (nc, nr, 0.0);
877 ret_vec[i+idx] = buf[i];
883 return ret.transpose ();
887 octave_unused_parameter (econ);
902 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD) && defined (HAVE_CXSPARSE))
908 if (nrows < 0 || ncols < 0 || b_nc < 0 || b_nr < 0)
909 (*current_liboctave_error_handler)
910 (
"matrix dimension with negative size");
912 if (nrows < 0 || ncols < 0 || nrows != b_nr)
913 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
916 cholmod_dense
B = rod2rcd (b);
920 QTB = SuiteSparseQR_qmult<double> (SPQR_QTX, m_H, m_Htau, m_HPinv, &
B,
923 spqr_error_handler (&m_cc);
929 R2.nzmax = m_R->nzmax;
930 R2.x =
reinterpret_cast<double *
> (m_R->x);
941 SuiteSparse_long *R_p =
reinterpret_cast<SuiteSparse_long *
> (m_R->p);
943 R2_p[i] = suitesparse_long_to_suitesparse_integer (R_p[i]);
947 SuiteSparse_long *R_i =
reinterpret_cast<SuiteSparse_long *
> (m_R->i);
949 R2_i[i] = suitesparse_long_to_suitesparse_integer (R_i[i]);
953 double *x_vec =
const_cast<double *
> (
x.fortran_vec ());
959 E[i] = suitesparse_long_to_suitesparse_integer (m_E[i]);
968 (&R2, &(
reinterpret_cast<double *
> (QTB->x)[j * b_nr]));
971 (E, &(
reinterpret_cast<double *
> (QTB->x)[j * b_nr]),
972 &x_vec[j * ncols], ncols);
981 cholmod_l_free_dense (&QTB, &m_cc);
987 #elif defined (HAVE_CXSPARSE)
995 const double *bvec = b.data ();
998 double *vec =
x.fortran_vec ();
1003 i++, idx+=nc, bidx+=b_nr)
1029 octave_unused_parameter (b);
1043 #if defined (HAVE_CXSPARSE)
1054 const double *bvec = b.data ();
1057 double *vec =
x.fortran_vec ();
1064 i++, idx+=nc, bidx+=b_nr)
1089 octave_unused_parameter (b);
1104 #if defined (HAVE_CXSPARSE)
1126 Xx[j] = b.
xelem (j, i);
1153 sz = (sz > 10 ? sz : 10) + x_nz;
1154 x.change_capacity (sz);
1172 octave_unused_parameter (b);
1187 #if defined (HAVE_CXSPARSE)
1213 Xx[j] = b.
xelem (j, i);
1240 sz = (sz > 10 ? sz : 10) + x_nz;
1241 x.change_capacity (sz);
1255 x.maybe_compress ();
1261 octave_unused_parameter (b);
1276 #if defined (HAVE_CXSPARSE)
1333 vec[j+idx] =
Complex (Xx[j], Xz[j]);
1342 octave_unused_parameter (b);
1357 #if defined (HAVE_CXSPARSE)
1419 vec[j+idx] =
Complex (Xx[j], Xz[j]);
1428 octave_unused_parameter (b);
1440 : nrows (a.rows ()), ncols (a.columns ())
1441 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1442 , m_cc (), m_R (nullptr), m_E (nullptr), m_H (nullptr),
1443 m_Htau (nullptr), m_HPinv (nullptr)
1448 if (nr < 0 || nc < 0)
1449 (*current_liboctave_error_handler)
1450 (
"matrix dimension with negative size");
1452 if (order < 0 || order > 9)
1453 (*current_liboctave_error_handler)
1454 (
"ordering %d is not supported by SPQR", order);
1456 cholmod_l_start (&m_cc);
1457 cholmod_sparse
A = cos2ccs (a);
1459 SuiteSparseQR<Complex> (order,
static_cast<double> (SPQR_DEFAULT_TOL),
1460 static_cast<SuiteSparse_long
> (
A.nrow),
1461 &
A, &m_R, &m_E, &m_H,
1462 &m_HPinv, &m_Htau, &m_cc);
1463 spqr_error_handler (&m_cc);
1467 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
1468 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
1472 #elif defined (HAVE_CXSPARSE)
1473 , S (
nullptr),
N (
nullptr)
1486 A.
x = const_cast<cs_complex_t *>
1487 (reinterpret_cast<const cs_complex_t *> (a.data ()));
1495 ("
sparse_qr: sparse matrix QR factorization filled");
1502 octave_unused_parameter (order);
1504 (*current_liboctave_error_handler)
1505 (
"sparse_qr: support for CXSparse was unavailable or disabled when liboctave was built");
1513 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1515 cholmod_l_free_sparse (&m_R, &m_cc);
1516 cholmod_l_free_sparse (&m_H, &m_cc);
1517 cholmod_l_free_dense (&m_Htau, &m_cc);
1520 cholmod_l_finish (&m_cc);
1522 #elif defined (HAVE_CXSPARSE)
1534 #if defined (HAVE_CXSPARSE)
1549 ret.xcidx (j) =
N->L->p[j];
1553 ret.xridx (j) =
N->L->i[j];
1554 ret.xdata (j) =
reinterpret_cast<Complex *
> (
N->L->x)[j];
1570 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1576 (cholmod_l_nnz (m_R,
const_cast<cholmod_common *
> (&m_cc)));
1580 SuiteSparse_long *Rp =
reinterpret_cast<SuiteSparse_long *
> (m_R->p);
1581 SuiteSparse_long *Ri =
reinterpret_cast<SuiteSparse_long *
> (m_R->i);
1589 ret.xdata (j) = (
reinterpret_cast<Complex *
> (m_R->x))[j];
1594 #elif defined (HAVE_CXSPARSE)
1612 ret.xcidx (j) =
N->U->p[j];
1616 ret.xridx (j) =
N->U->i[j];
1617 ret.xdata (j) =
reinterpret_cast<Complex *
> (
N->U->x)[j];
1624 octave_unused_parameter (econ);
1636 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1640 ? (ncols > nrows ? nrows : ncols)
1647 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1649 if (b_nc < 0 || b_nr < 0)
1650 (*current_liboctave_error_handler)
1651 (
"matrix dimension with negative size");
1654 cholmod_dense
B = cod2ccd (b);
1656 QTB = SuiteSparseQR_qmult<Complex> (SPQR_QTX, m_H, m_Htau, m_HPinv, &
B,
1658 spqr_error_handler (&m_cc);
1662 Complex *ret_vec =
reinterpret_cast<Complex *
> (ret.fortran_vec ());
1665 ret_vec[j * nr + i] = QTB_x[j * b_nr + i];
1667 cholmod_l_free_dense (&QTB, &m_cc);
1671 #elif defined (HAVE_CXSPARSE)
1674 (*current_liboctave_error_handler)
1675 (
"sparse-qr: economy mode with CXSparse not supported");
1681 const cs_complex_t *bvec
1682 =
reinterpret_cast<const cs_complex_t *
> (b.
data ());
1684 Complex *vec = ret.fortran_vec ();
1686 if (nr < 0 || nc < 0 || nr != b_nr)
1687 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1689 if (nr == 0 || nc == 0 || b_nc == 0)
1704 reinterpret_cast<cs_complex_t *
> (buf),
1712 reinterpret_cast<cs_complex_t *
> (buf));
1716 vec[i+idx] = buf[i];
1724 octave_unused_parameter (b);
1725 octave_unused_parameter (econ);
1736 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
1739 ? (ncols > nrows ? nrows : ncols)
1745 cholmod_dense *I_mat
1746 =
reinterpret_cast<cholmod_dense *
>
1747 (cholmod_l_allocate_dense (nrows, nrows, nrows, CHOLMOD_COMPLEX, &m_cc));
1750 (
reinterpret_cast<Complex *
> (I_mat->x))[i] = 0.0;
1753 (
reinterpret_cast<Complex *
> (I_mat->x))[i * nrows + i] = 1.0;
1755 q = SuiteSparseQR_qmult<Complex> (SPQR_QX, m_H, m_Htau, m_HPinv, I_mat,
1757 spqr_error_handler (&m_cc);
1764 ret_vec[j * nrows + i] = q_x[j * nrows + i];
1766 cholmod_l_free_dense (&q, &m_cc);
1767 cholmod_l_free_dense (&I_mat, &m_cc);
1771 #elif defined (HAVE_CXSPARSE)
1774 (*current_liboctave_error_handler)
1775 (
"sparse-qr: economy mode with CXSparse not supported");
1780 Complex *vec = ret.fortran_vec ();
1782 if (nr < 0 || nc < 0)
1783 (*current_liboctave_error_handler) (
"matrix dimension mismatch");
1785 if (nr == 0 || nc == 0)
1805 reinterpret_cast<cs_complex_t *
> (buf),
1813 reinterpret_cast<cs_complex_t *
> (buf));
1817 vec[i+idx] = buf[i];
1823 return ret.hermitian ();
1827 octave_unused_parameter (econ);
1843 #if defined (HAVE_CXSPARSE)
1912 sz = (sz > 10 ? sz : 10) + x_nz;
1913 x.change_capacity (sz);
1931 octave_unused_parameter (b);
1947 #if defined (HAVE_CXSPARSE)
2020 sz = (sz > 10 ? sz : 10) + x_nz;
2021 x.change_capacity (sz);
2035 x.maybe_compress ();
2041 octave_unused_parameter (b);
2057 #if defined (HAVE_CXSPARSE)
2066 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2076 Xx[j] = b.xelem (j, i);
2082 reinterpret_cast<cs_complex_t *
> (Xx),
2102 octave_unused_parameter (b);
2118 #if defined (HAVE_CXSPARSE)
2130 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2146 Xx[j] = b.xelem (j, i);
2151 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
> (Xx),
2171 octave_unused_parameter (b);
2187 #if defined (HAVE_CXSPARSE)
2209 Xx[j] = b.xelem (j, i);
2215 reinterpret_cast<cs_complex_t *
> (Xx),
2227 reinterpret_cast<cs_complex_t *
> (Xx),
2240 sz = (sz > 10 ? sz : 10) + x_nz;
2241 x.change_capacity (sz);
2255 x.maybe_compress ();
2261 octave_unused_parameter (b);
2277 #if defined (HAVE_CXSPARSE)
2307 Xx[j] = b.xelem (j, i);
2313 reinterpret_cast<cs_complex_t *
> (Xx),
2325 reinterpret_cast<cs_complex_t *
> (Xx),
2338 sz = (sz > 10 ? sz : 10) + x_nz;
2339 x.change_capacity (sz);
2353 x.maybe_compress ();
2359 octave_unused_parameter (b);
2375 #if defined (HAVE_CXSPARSE)
2383 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
2387 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
>
2393 i++, idx+=nc, bidx+=b_nr)
2419 octave_unused_parameter (b);
2435 #if defined (HAVE_CXSPARSE)
2446 const cs_complex_t *bvec =
reinterpret_cast<const cs_complex_t *
>
2450 cs_complex_t *vec =
reinterpret_cast<cs_complex_t *
> (
x.fortran_vec ());
2461 i++, idx+=nc, bidx+=b_nr)
2487 octave_unused_parameter (b);
2503 #if defined (HAVE_CXSPARSE)
2525 Xx[j] = b.xelem (j, i);
2531 reinterpret_cast<cs_complex_t *
> (Xx),
2543 reinterpret_cast<cs_complex_t *
> (Xx),
2556 sz = (sz > 10 ? sz : 10) + x_nz;
2557 x.change_capacity (sz);
2571 x.maybe_compress ();
2577 octave_unused_parameter (b);
2593 #if defined (HAVE_CXSPARSE)
2623 Xx[j] = b.xelem (j, i);
2628 CXSPARSE_ZNAME (_pvec) (S->q,
reinterpret_cast<cs_complex_t *
> (Xx),
2640 reinterpret_cast<cs_complex_t *
> (Xx), nc);
2652 sz = (sz > 10 ? sz : 10) + x_nz;
2653 x.change_capacity (sz);
2667 x.maybe_compress ();
2673 octave_unused_parameter (b);
2680 template <
typename SPARSE_T>
2682 : m_rep (new sparse_qr_rep (SPARSE_T (), 0))
2685 template <
typename SPARSE_T>
2687 : m_rep (new sparse_qr_rep (a, order))
2690 template <
typename SPARSE_T>
2694 return m_rep->ok ();
2697 template <
typename SPARSE_T>
2704 template <
typename SPARSE_T>
2711 template <
typename SPARSE_T>
2718 template <
typename SPARSE_T>
2726 template <
typename SPARSE_T>
2734 ret(perm(i) - 1, i) = 1.0;
2739 template <
typename SPARSE_T>
2743 return m_rep->R (econ);
2746 template <
typename SPARSE_T>
2747 typename SPARSE_T::dense_matrix_type
2751 return m_rep->C (b, econ);
2754 template <
typename SPARSE_T>
2755 typename SPARSE_T::dense_matrix_type
2758 return m_rep->Q (econ);
2761 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
2776 cholmod_l_start (&cc);
2777 cholmod_sparse
A = ros2rcs (a);
2778 cholmod_dense
B = rod2rcd (b);
2781 X = SuiteSparseQR_min2norm<double> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2782 spqr_error_handler (&cc);
2784 double *xdata =
x.fortran_vec ();
2786 xdata[i] =
reinterpret_cast<double *
> (X->x)[i];
2791 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2792 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2794 cholmod_l_free_dense (&X, &cc);
2795 cholmod_l_finish (&cc);
2811 cholmod_l_start (&cc);
2812 cholmod_sparse
A = ros2rcs (a);
2813 cholmod_sparse
B = ros2rcs (b);
2816 X = SuiteSparseQR_min2norm<double> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2817 spqr_error_handler (&cc);
2819 x = rcs2ros (X, &cc);
2824 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2825 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2826 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
2827 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
2829 cholmod_l_free_sparse (&X, &cc);
2830 cholmod_l_finish (&cc);
2848 cholmod_l_start (&cc);
2849 cholmod_sparse *
A = ros2ccs (a, &cc);
2850 cholmod_dense
B = cod2ccd (b);
2853 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL,
A, &
B, &cc);
2854 spqr_error_handler (&cc);
2858 xdata[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2861 cholmod_l_free_sparse (&
A, &cc);
2862 cholmod_l_free_dense (&X, &cc);
2863 cholmod_l_finish (&cc);
2878 cholmod_l_start (&cc);
2879 cholmod_sparse *
A = ros2ccs (a, &cc);
2880 cholmod_sparse
B = cos2ccs (b);
2883 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL,
A, &
B, &cc);
2884 spqr_error_handler (&cc);
2891 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
2892 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
2894 cholmod_l_free_sparse (&
A, &cc);
2895 cholmod_l_free_sparse (&X, &cc);
2896 cholmod_l_finish (&cc);
2914 cholmod_l_start (&cc);
2915 cholmod_sparse
A = cos2ccs (a);
2916 cholmod_dense
B = cod2ccd (b);
2919 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2920 spqr_error_handler (&cc);
2924 xdata[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2929 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2930 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2932 cholmod_l_free_dense (&X, &cc);
2933 cholmod_l_finish (&cc);
2953 cholmod_l_start (&cc);
2954 cholmod_sparse
A = cos2ccs (a);
2955 cholmod_dense *
B = rod2ccd (b, &cc);
2958 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A,
B, &cc);
2959 spqr_error_handler (&cc);
2963 xdata[i] =
reinterpret_cast<Complex *
> (X->x)[i];
2968 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
2969 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
2971 cholmod_l_free_dense (&
B, &cc);
2972 cholmod_l_free_dense (&X, &cc);
2973 cholmod_l_finish (&cc);
2988 cholmod_l_start (&cc);
2989 cholmod_sparse
A = cos2ccs (a);
2990 cholmod_sparse
B = cos2ccs (b);
2993 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A, &
B, &cc);
2994 spqr_error_handler (&cc);
3001 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
3002 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
3003 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.p);
3004 delete []
reinterpret_cast<SuiteSparse_long *
> (
B.i);
3006 cholmod_l_free_sparse (&X, &cc);
3007 cholmod_l_finish (&cc);
3024 cholmod_l_start (&cc);
3025 cholmod_sparse
A = cos2ccs (a);
3026 cholmod_sparse *
B = ros2ccs (b, &cc);
3029 X = SuiteSparseQR_min2norm<Complex> (order, SPQR_DEFAULT_TOL, &
A,
B, &cc);
3030 spqr_error_handler (&cc);
3037 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.p);
3038 delete []
reinterpret_cast<SuiteSparse_long *
> (
A.i);
3040 cholmod_l_free_sparse (&
B, &cc);
3041 cholmod_l_free_sparse (&X, &cc);
3042 cholmod_l_finish (&cc);
3053 template <
typename SPARSE_T>
3058 enum { order = -1 };
3063 cxsparse_defaults<SparseMatrix>
3066 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3067 enum { order = SPQR_ORDERING_DEFAULT };
3068 #elif defined (HAVE_CXSPARSE)
3075 cxsparse_defaults<SparseComplexMatrix>
3078 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3079 enum { order = SPQR_ORDERING_DEFAULT };
3080 #elif defined (HAVE_CXSPARSE)
3085 template <
typename SPARSE_T>
3086 template <
typename RHS_T,
typename RET_T>
3091 #if (defined (HAVE_SPQR) && defined (HAVE_CHOLMOD))
3101 int order = cxsparse_defaults<SPARSE_T>::order;
3103 if (nr < 0 || nc < 0 || b_nc < 0 || b_nr < 0)
3104 (*current_liboctave_error_handler)
3105 (
"matrix dimension with negative size");
3108 (*current_liboctave_error_handler)
3109 (
"matrix dimension mismatch in solution of minimum norm problem");
3113 return min2norm_solve<RHS_T, RET_T> (a, b, info, order);
3115 #elif defined (HAVE_CXSPARSE)
3125 int order = cxsparse_defaults<SPARSE_T>::order;
3127 if (nr < 0 || nc < 0 || nr != b_nr)
3128 (*current_liboctave_error_handler)
3129 (
"matrix dimension mismatch in solution of minimum norm problem");
3131 if (nr == 0 || nc == 0 || b_nc == 0)
3135 return RET_T (nc, b_nc, 0.0);
3141 return q.
ok () ? q.tall_solve<RHS_T, RET_T> (b, info) : RET_T ();
3147 return q.
ok () ? q.wide_solve<RHS_T, RET_T> (b, info) : RET_T ();
3152 octave_unused_parameter (a);
3153 octave_unused_parameter (b);
3154 octave_unused_parameter (info);
3217 template <
typename SPARSE_T>
3218 template <
typename RHS_T,
typename RET_T>
3222 return m_rep->template tall_solve<RHS_T, RET_T> (b, info);
3225 template <
typename SPARSE_T>
3226 template <
typename RHS_T,
typename RET_T>
3230 return m_rep->template wide_solve<RHS_T, RET_T> (b, info);
3335 OCTAVE_END_NAMESPACE(math)
3336 OCTAVE_END_NAMESPACE(
octave)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
octave_idx_type rows() const
const T * data() const
Size of the specified dimension.
octave_idx_type cols() const
octave_idx_type cols() const
T & xelem(octave_idx_type n)
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
SPARSE_T R(bool econ=false) const
SparseMatrix E_MAT() const
SPARSE_T::dense_matrix_type Q(bool econ=false) const
SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b, bool econ=false) const
static RET_T solve(const SPARSE_T &a, const RHS_T &b, octave_idx_type &info)
ColumnVector Pinv() 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 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
F77_RET_T const F77_INT F77_CMPLX * A
F77_RET_T const F77_INT & N
F77_RET_T const F77_DBLE * x
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)