71 const octave_idx_type&,
const octave_idx_type&,
72 double*,
const octave_idx_type&,
73 octave_idx_type*, octave_idx_type&);
77 const octave_idx_type&,
const octave_idx_type&,
78 const octave_idx_type&,
const octave_idx_type&,
79 const double*,
const octave_idx_type&,
80 const octave_idx_type*,
double*,
81 const octave_idx_type&, octave_idx_type&
86 const octave_idx_type&,
const octave_idx_type&,
87 const octave_idx_type&,
double*,
88 const octave_idx_type&,
const octave_idx_type*,
89 const double&,
double&,
double*,
90 octave_idx_type*, octave_idx_type&
95 const octave_idx_type&,
const octave_idx_type&,
96 double*,
const octave_idx_type&, octave_idx_type&
101 const octave_idx_type&,
const octave_idx_type&,
102 const octave_idx_type&,
double*,
103 const octave_idx_type&,
double*,
104 const octave_idx_type&, octave_idx_type&
109 const octave_idx_type&,
const octave_idx_type&,
110 double*,
const octave_idx_type&,
111 const double&,
double&,
double*,
112 octave_idx_type*, octave_idx_type&
115 F77_FUNC (dptsv, DPTSV) (
const octave_idx_type&,
const octave_idx_type&,
116 double*,
double*,
double*,
const octave_idx_type&,
120 F77_FUNC (dgtsv, DGTSV) (
const octave_idx_type&,
const octave_idx_type&,
121 double*,
double*,
double*,
double*,
122 const octave_idx_type&, octave_idx_type&);
125 F77_FUNC (dgttrf, DGTTRF) (
const octave_idx_type&,
double*,
double*,
126 double*,
double*, octave_idx_type*,
131 const octave_idx_type&,
const octave_idx_type&,
132 const double*,
const double*,
const double*,
133 const double*,
const octave_idx_type*,
134 double *,
const octave_idx_type&, octave_idx_type&
138 F77_FUNC (zptsv, ZPTSV) (
const octave_idx_type&,
const octave_idx_type&,
139 double*,
Complex*, Complex*,
const octave_idx_type&,
143 F77_FUNC (zgtsv, ZGTSV) (
const octave_idx_type&,
const octave_idx_type&,
144 Complex*, Complex*, Complex*, Complex*,
145 const octave_idx_type&, octave_idx_type&);
193 if (nr != nr_a || nc != nc_a || nz != nz_a)
210 return !(*
this == a);
219 if (nr == nc && nr > 0)
272 return max (dummy_idx, dim);
296 if (nr == 0 || nc == 0 || dim >= dv.
length ())
306 if (
ridx (i) != idx_j)
317 double tmp =
data (i);
321 else if (
xisnan (tmp_max) || tmp > tmp_max)
329 idx_arg.
elem (j) =
xisnan (tmp_max) ? 0 : idx_j;
337 result.
xcidx (0) = 0;
340 double tmp =
elem (idx_arg(j), j);
343 result.
xdata (ii) = tmp;
344 result.
xridx (ii++) = 0;
346 result.
xcidx (j+1) = ii;
354 if (nr == 0 || nc == 0 || dim >= dv.
length ())
364 if (found[
ridx (i)] == -j)
365 found[
ridx (i)] = -j - 1;
368 if (found[i] > -nc && found[i] < 0)
369 idx_arg.
elem (i) = -found[i];
377 double tmp =
data (i);
381 else if (ix == -1 || tmp >
elem (ir, ix))
382 idx_arg.
elem (ir) = j;
388 if (idx_arg.
elem (j) == -1 ||
elem (j, idx_arg.
elem (j)) != 0.)
394 result.
xcidx (0) = 0;
395 result.
xcidx (1) = nel;
398 if (idx_arg(j) == -1)
402 result.
xridx (ii++) = j;
406 double tmp =
elem (j, idx_arg(j));
409 result.
xdata (ii) = tmp;
410 result.
xridx (ii++) = j;
423 return min (dummy_idx, dim);
447 if (nr == 0 || nc == 0 || dim >= dv.
length ())
457 if (
ridx (i) != idx_j)
468 double tmp =
data (i);
472 else if (
xisnan (tmp_min) || tmp < tmp_min)
480 idx_arg.
elem (j) =
xisnan (tmp_min) ? 0 : idx_j;
488 result.
xcidx (0) = 0;
491 double tmp =
elem (idx_arg(j), j);
494 result.
xdata (ii) = tmp;
495 result.
xridx (ii++) = 0;
497 result.
xcidx (j+1) = ii;
505 if (nr == 0 || nc == 0 || dim >= dv.
length ())
515 if (found[
ridx (i)] == -j)
516 found[
ridx (i)] = -j - 1;
519 if (found[i] > -nc && found[i] < 0)
520 idx_arg.
elem (i) = -found[i];
528 double tmp =
data (i);
532 else if (ix == -1 || tmp <
elem (ir, ix))
533 idx_arg.
elem (ir) = j;
539 if (idx_arg.
elem (j) == -1 ||
elem (j, idx_arg.
elem (j)) != 0.)
545 result.
xcidx (0) = 0;
546 result.
xcidx (1) = nel;
549 if (idx_arg(j) == -1)
553 result.
xridx (ii++) = j;
557 double tmp =
elem (j, idx_arg(j));
560 result.
xdata (ii) = tmp;
561 result.
xridx (ii++) = j;
596 retval(j) =
data (k);
621 if (rb.
rows () > 0 && rb.
cols () > 0)
622 insert (rb, ra_idx(0), ra_idx(1));
631 if (rb.
rows () > 0 && rb.
cols () > 0)
632 retval.
insert (rb, ra_idx(0), ra_idx(1));
717 retval.
xcidx (0) = 0;
725 retval.
xdata (ii) = tmp;
729 retval.
xcidx (i+1) = ii;
761 if (x_nr != y_nr || x_nc != y_nc)
773 bool ja_lt_max= ja < ja_max;
777 bool jb_lt_max = jb < jb_max;
779 while (ja_lt_max || jb_lt_max )
783 (ja_lt_max && (x.
ridx (ja) < y.
ridx (jb))))
789 ja_lt_max= ja < ja_max;
791 else if (( !ja_lt_max ) ||
792 (jb_lt_max && (y.
ridx (jb) < x.
ridx (ja)) ) )
795 jb_lt_max= jb < jb_max;
807 ja_lt_max= ja < ja_max;
809 jb_lt_max= jb < jb_max;
830 return inverse (mattype, info, rcond, 0, 0);
838 return inverse (mattype, info, rcond, 0, 0);
845 return inverse (mattype, info, rcond, 0, 0);
850 double& rcond,
const bool,
851 const bool calccond)
const
859 if (nr == 0 || nc == 0 || nr != nc)
860 (*current_liboctave_error_handler) (
"inverse requires square matrix");
864 int typ = mattyp.
type ();
876 double *v = retval.
data ();
883 double tmp = fabs (v[i]);
904 double& rcond,
const bool,
905 const bool calccond)
const
913 if (nr == 0 || nc == 0 || nr != nc)
914 (*current_liboctave_error_handler) (
"inverse requires square matrix");
918 int typ = mattyp.
type ();
925 double ainvnorm = 0.;
934 atmp += fabs (
data (i));
959 retval.
xcidx (i) = cx;
960 retval.
xridx (cx) = i;
961 retval.
xdata (cx) = 1.0;
975 (*current_liboctave_error_handler)
976 (
"division by zero");
977 goto inverse_singular;
983 rpX = retval.
xridx (colXp);
992 v -= retval.
xdata (colXp) *
data (colUp);
996 }
while ((rpX<j) && (rpU<j) &&
997 (colXp<cx) && (colUp<nz));
1001 colUp =
cidx (j+1) - 1;
1004 double pivot =
data (colUp);
1005 if (pivot == 0. ||
ridx (colUp) != j)
1007 (*current_liboctave_error_handler)
1008 (
"division by zero");
1009 goto inverse_singular;
1020 retval.
xridx (cx) = j;
1021 retval.
xdata (cx) = v / pivot;
1029 colUp =
cidx (i+1) - 1;
1032 double pivot =
data (colUp);
1033 if (pivot == 0. ||
ridx (colUp) != i)
1035 (*current_liboctave_error_handler) (
"division by zero");
1036 goto inverse_singular;
1041 retval.
xdata (j) /= pivot;
1043 retval.
xcidx (nr) = cx;
1088 k <
cidx (jidx+1); k++)
1097 pivot =
data (cidx (jidx+1) - 1);
1099 pivot =
data (cidx (jidx));
1102 (*current_liboctave_error_handler)
1103 (
"division by zero");
1104 goto inverse_singular;
1107 work[j] = v / pivot;
1113 colUp =
cidx (perm[iidx]+1) - 1;
1115 colUp =
cidx (perm[iidx]);
1117 double pivot =
data (colUp);
1120 (*current_liboctave_error_handler)
1121 (
"division by zero");
1122 goto inverse_singular;
1136 nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2);
1140 retval.
xcidx (i) = cx;
1144 retval.
xridx (cx) = j;
1145 retval.
xdata (cx++) = work[j];
1149 retval.
xcidx (nr) = cx;
1160 i < retval.
cidx (j+1); i++)
1161 atmp += fabs (retval.
data (i));
1162 if (atmp > ainvnorm)
1166 rcond = 1. / ainvnorm / anorm;
1181 double& rcond,
int,
int calc_cond)
const
1183 int typ = mattype.
type (
false);
1187 typ = mattype.
type (*
this);
1190 ret =
dinverse (mattype, info, rcond,
true, calc_cond);
1204 rcond = fact.
rcond ();
1210 info, rcond2,
true,
false);
1230 rcond = fact.
rcond ();
1233 info, rcond2,
true,
false);
1267 if (nr == 0 || nc == 0 || nr != nc)
1276 Matrix Control (UMFPACK_CONTROL, 1);
1282 Control (UMFPACK_PRL) = tmp;
1287 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
1288 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
1294 Control (UMFPACK_FIXQ) = tmp;
1297 Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE;
1303 const double *Ax =
data ();
1305 UMFPACK_DNAME (report_matrix) (nr, nc, Ap, Ai, Ax, 1, control);
1308 Matrix Info (1, UMFPACK_INFO);
1311 Ax, 0, &Symbolic, control, info);
1315 (*current_liboctave_error_handler)
1316 (
"SparseMatrix::determinant symbolic factorization failed");
1329 &Numeric, control, info);
1332 rcond = Info (UMFPACK_RCOND);
1336 (*current_liboctave_error_handler)
1337 (
"SparseMatrix::determinant numeric factorization failed");
1350 status =
UMFPACK_DNAME (get_determinant) (&c10, &e10, Numeric,
1355 (*current_liboctave_error_handler)
1356 (
"SparseMatrix::determinant error calculating determinant");
1362 retval =
DET (c10, e10, 10);
1369 (*current_liboctave_error_handler) (
"UMFPACK not installed");
1378 double& rcond, solve_singularity_handler,
1379 bool calc_cond)
const
1388 if (nr != b.
rows ())
1390 (
"matrix dimension mismatch solution of linear equations");
1391 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1396 int typ = mattype.
type ();
1406 retval(i,j) = b(i,j) /
data (i);
1411 retval(k,j) = b(
ridx (i),j) /
data (i);
1418 double tmp = fabs (
data (i));
1424 rcond = dmin / dmax;
1439 solve_singularity_handler,
bool calc_cond)
const
1448 if (nr != b.
rows ())
1450 (
"matrix dimension mismatch solution of linear equations");
1451 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1456 int typ = mattype.
type ();
1466 retval.
xcidx (0) = 0;
1473 if (b.
ridx (i) >= nm)
1478 retval.
xcidx (j+1) = ii;
1488 for (k = b.
cidx (j); k < b.
cidx (j+1); k++)
1496 retval.
xridx (ii) = l;
1500 retval.
xcidx (j+1) = ii;
1508 double tmp = fabs (
data (i));
1514 rcond = dmin / dmax;
1529 solve_singularity_handler,
bool calc_cond)
const
1538 if (nr != b.
rows ())
1540 (
"matrix dimension mismatch solution of linear equations");
1541 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1546 int typ = mattype.
type ();
1556 retval(i,j) = b(i,j) /
data (i);
1561 retval(k,j) = b(
ridx (i),j) /
data (i);
1568 double tmp = fabs (
data (i));
1574 rcond = dmin / dmax;
1589 solve_singularity_handler,
bool calc_cond)
const
1598 if (nr != b.
rows ())
1600 (
"matrix dimension mismatch solution of linear equations");
1601 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1606 int typ = mattype.
type ();
1616 retval.
xcidx (0) = 0;
1623 if (b.
ridx (i) >= nm)
1628 retval.
xcidx (j+1) = ii;
1638 for (k = b.
cidx (j); k < b.
cidx (j+1); k++)
1646 retval.
xridx (ii) = l;
1650 retval.
xcidx (j+1) = ii;
1658 double tmp = fabs (
data (i));
1664 rcond = dmin / dmax;
1679 solve_singularity_handler sing_handler,
1680 bool calc_cond)
const
1689 if (nr != b.
rows ())
1691 (
"matrix dimension mismatch solution of linear equations");
1692 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1697 int typ = mattype.
type ();
1704 double ainvnorm = 0.;
1715 atmp += fabs (
data (i));
1723 retval.
resize (nc, b_nc);
1744 goto triangular_error;
1747 double tmp = work[k] /
data (
cidx (kidx+1)-1);
1750 i <
cidx (kidx+1)-1; i++)
1753 work[iidx] = work[iidx] - tmp *
data (i);
1759 retval.
xelem (perm[i], j) = work[i];
1778 double tmp = work[k] /
data (
cidx (iidx+1)-1);
1781 i <
cidx (iidx+1)-1; i++)
1784 work[idx2] = work[idx2] - tmp *
data (i);
1791 atmp += fabs (work[i]);
1794 if (atmp > ainvnorm)
1797 rcond = 1. / ainvnorm / anorm;
1803 retval.
resize (nc, b_nc);
1820 goto triangular_error;
1823 double tmp = work[k] /
data (
cidx (k+1)-1);
1828 work[iidx] = work[iidx] - tmp *
data (i);
1834 retval.
xelem (i, j) = work[i];
1851 double tmp = work[k] /
data (
cidx (k+1)-1);
1856 work[iidx] = work[iidx] - tmp *
data (i);
1863 atmp += fabs (work[i]);
1866 if (atmp > ainvnorm)
1869 rcond = 1. / ainvnorm / anorm;
1878 sing_handler (rcond);
1883 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
1887 volatile double rcond_plus_one = rcond + 1.0;
1889 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
1895 sing_handler (rcond);
1900 (
"matrix singular to machine precision, rcond = %g",
1914 solve_singularity_handler sing_handler,
1915 bool calc_cond)
const
1924 if (nr != b.
rows ())
1926 (
"matrix dimension mismatch solution of linear equations");
1927 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1932 int typ = mattype.
type ();
1939 double ainvnorm = 0.;
1949 atmp += fabs (
data (i));
1958 retval.
xcidx (0) = 0;
1988 goto triangular_error;
1991 double tmp = work[k] /
data (
cidx (kidx+1)-1);
1994 i <
cidx (kidx+1)-1; i++)
1997 work[iidx] = work[iidx] - tmp *
data (i);
2009 if (ii + new_nnz > x_nz)
2018 if (work[rperm[i]] != 0.)
2020 retval.
xridx (ii) = i;
2021 retval.
xdata (ii++) = work[rperm[i]];
2023 retval.
xcidx (j+1) = ii;
2044 double tmp = work[k] /
data (
cidx (iidx+1)-1);
2047 i <
cidx (iidx+1)-1; i++)
2050 work[idx2] = work[idx2] - tmp *
data (i);
2057 atmp += fabs (work[i]);
2060 if (atmp > ainvnorm)
2063 rcond = 1. / ainvnorm / anorm;
2085 goto triangular_error;
2088 double tmp = work[k] /
data (
cidx (k+1)-1);
2093 work[iidx] = work[iidx] - tmp *
data (i);
2105 if (ii + new_nnz > x_nz)
2116 retval.
xridx (ii) = i;
2117 retval.
xdata (ii++) = work[i];
2119 retval.
xcidx (j+1) = ii;
2138 double tmp = work[k] /
data (
cidx (k+1)-1);
2141 i <
cidx (k+1)-1; i++)
2144 work[iidx] = work[iidx] - tmp *
data (i);
2151 atmp += fabs (work[i]);
2154 if (atmp > ainvnorm)
2157 rcond = 1. / ainvnorm / anorm;
2166 sing_handler (rcond);
2171 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
2175 volatile double rcond_plus_one = rcond + 1.0;
2177 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2183 sing_handler (rcond);
2188 (
"matrix singular to machine precision, rcond = %g",
2201 solve_singularity_handler sing_handler,
2202 bool calc_cond)
const
2211 if (nr != b.
rows ())
2213 (
"matrix dimension mismatch solution of linear equations");
2214 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2219 int typ = mattype.
type ();
2226 double ainvnorm = 0.;
2237 atmp += fabs (
data (i));
2245 retval.
resize (nc, b_nc);
2266 goto triangular_error;
2272 i <
cidx (kidx+1)-1; i++)
2275 cwork[iidx] = cwork[iidx] - tmp *
data (i);
2281 retval.
xelem (perm[i], j) = cwork[i];
2301 double tmp = work[k] /
data (
cidx (iidx+1)-1);
2304 i <
cidx (iidx+1)-1; i++)
2307 work[idx2] = work[idx2] - tmp *
data (i);
2314 atmp += fabs (work[i]);
2317 if (atmp > ainvnorm)
2320 rcond = 1. / ainvnorm / anorm;
2326 retval.
resize (nc, b_nc);
2343 goto triangular_error;
2351 cwork[iidx] = cwork[iidx] - tmp *
data (i);
2357 retval.
xelem (i, j) = cwork[i];
2375 double tmp = work[k] /
data (
cidx (k+1)-1);
2378 i <
cidx (k+1)-1; i++)
2381 work[iidx] = work[iidx] - tmp *
data (i);
2388 atmp += fabs (work[i]);
2391 if (atmp > ainvnorm)
2394 rcond = 1. / ainvnorm / anorm;
2403 sing_handler (rcond);
2408 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
2412 volatile double rcond_plus_one = rcond + 1.0;
2414 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2420 sing_handler (rcond);
2425 (
"matrix singular to machine precision, rcond = %g",
2439 solve_singularity_handler sing_handler,
2440 bool calc_cond)
const
2449 if (nr != b.
rows ())
2451 (
"matrix dimension mismatch solution of linear equations");
2452 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2457 int typ = mattype.
type ();
2464 double ainvnorm = 0.;
2474 atmp += fabs (
data (i));
2483 retval.
xcidx (0) = 0;
2513 goto triangular_error;
2519 i <
cidx (kidx+1)-1; i++)
2522 cwork[iidx] = cwork[iidx] - tmp *
data (i);
2534 if (ii + new_nnz > x_nz)
2543 if (cwork[rperm[i]] != 0.)
2545 retval.
xridx (ii) = i;
2546 retval.
xdata (ii++) = cwork[rperm[i]];
2548 retval.
xcidx (j+1) = ii;
2570 double tmp = work[k] /
data (
cidx (iidx+1)-1);
2573 i <
cidx (iidx+1)-1; i++)
2576 work[idx2] = work[idx2] - tmp *
data (i);
2583 atmp += fabs (work[i]);
2586 if (atmp > ainvnorm)
2589 rcond = 1. / ainvnorm / anorm;
2611 goto triangular_error;
2619 cwork[iidx] = cwork[iidx] - tmp *
data (i);
2631 if (ii + new_nnz > x_nz)
2642 retval.
xridx (ii) = i;
2643 retval.
xdata (ii++) = cwork[i];
2645 retval.
xcidx (j+1) = ii;
2665 double tmp = work[k] /
data (
cidx (k+1)-1);
2668 i <
cidx (k+1)-1; i++)
2671 work[iidx] = work[iidx] - tmp *
data (i);
2678 atmp += fabs (work[i]);
2681 if (atmp > ainvnorm)
2684 rcond = 1. / ainvnorm / anorm;
2693 sing_handler (rcond);
2698 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
2702 volatile double rcond_plus_one = rcond + 1.0;
2704 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2710 sing_handler (rcond);
2715 (
"matrix singular to machine precision, rcond = %g",
2729 solve_singularity_handler sing_handler,
2730 bool calc_cond)
const
2739 if (nr != b.
rows ())
2741 (
"matrix dimension mismatch solution of linear equations");
2742 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2747 int typ = mattype.
type ();
2754 double ainvnorm = 0.;
2765 atmp += fabs (
data (i));
2773 retval.
resize (nc, b_nc);
2783 work[perm[i]] = b(i,j);
2793 if (perm[
ridx (i)] < minr)
2795 minr = perm[
ridx (i)];
2799 if (minr != k ||
data (mini) == 0)
2802 goto triangular_error;
2805 double tmp = work[k] /
data (mini);
2813 work[iidx] = work[iidx] - tmp *
data (i);
2819 retval(i, j) = work[i];
2840 i <
cidx (k+1); i++)
2841 if (perm[
ridx (i)] < minr)
2843 minr = perm[
ridx (i)];
2847 double tmp = work[k] /
data (mini);
2850 i <
cidx (k+1); i++)
2856 work[iidx] = work[iidx] - tmp *
data (i);
2864 atmp += fabs (work[i]);
2867 if (atmp > ainvnorm)
2870 rcond = 1. / ainvnorm / anorm;
2876 retval.
resize (nc, b_nc, 0.);
2892 goto triangular_error;
2895 double tmp = work[k] /
data (
cidx (k));
2898 i <
cidx (k+1); i++)
2901 work[iidx] = work[iidx] - tmp *
data (i);
2907 retval.
xelem (i, j) = work[i];
2925 double tmp = work[k] /
data (
cidx (k));
2928 i <
cidx (k+1); i++)
2931 work[iidx] = work[iidx] - tmp *
data (i);
2938 atmp += fabs (work[i]);
2941 if (atmp > ainvnorm)
2944 rcond = 1. / ainvnorm / anorm;
2953 sing_handler (rcond);
2958 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
2962 volatile double rcond_plus_one = rcond + 1.0;
2964 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2970 sing_handler (rcond);
2975 (
"matrix singular to machine precision, rcond = %g",
2989 solve_singularity_handler sing_handler,
2990 bool calc_cond)
const
2999 if (nr != b.
rows ())
3001 (
"matrix dimension mismatch solution of linear equations");
3002 else if (nr == 0 || nc == 0 || b.
cols () == 0)
3007 int typ = mattype.
type ();
3014 double ainvnorm = 0.;
3024 atmp += fabs (
data (i));
3033 retval.
xcidx (0) = 0;
3047 work[perm[b.
ridx (i)]] = b.
data (i);
3057 if (perm[
ridx (i)] < minr)
3059 minr = perm[
ridx (i)];
3063 if (minr != k ||
data (mini) == 0)
3066 goto triangular_error;
3069 double tmp = work[k] /
data (mini);
3077 work[iidx] = work[iidx] - tmp *
data (i);
3089 if (ii + new_nnz > x_nz)
3100 retval.
xridx (ii) = i;
3101 retval.
xdata (ii++) = work[i];
3103 retval.
xcidx (j+1) = ii;
3126 i <
cidx (k+1); i++)
3127 if (perm[
ridx (i)] < minr)
3129 minr = perm[
ridx (i)];
3133 double tmp = work[k] /
data (mini);
3136 i <
cidx (k+1); i++)
3142 work[iidx] = work[iidx] - tmp *
data (i);
3150 atmp += fabs (work[i]);
3153 if (atmp > ainvnorm)
3156 rcond = 1. / ainvnorm / anorm;
3178 goto triangular_error;
3181 double tmp = work[k] /
data (
cidx (k));
3186 work[iidx] = work[iidx] - tmp *
data (i);
3198 if (ii + new_nnz > x_nz)
3209 retval.
xridx (ii) = i;
3210 retval.
xdata (ii++) = work[i];
3212 retval.
xcidx (j+1) = ii;
3232 double tmp = work[k] /
data (
cidx (k));
3235 i <
cidx (k+1); i++)
3238 work[iidx] = work[iidx] - tmp *
data (i);
3245 atmp += fabs (work[i]);
3248 if (atmp > ainvnorm)
3251 rcond = 1. / ainvnorm / anorm;
3260 sing_handler (rcond);
3265 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
3269 volatile double rcond_plus_one = rcond + 1.0;
3271 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3277 sing_handler (rcond);
3282 (
"matrix singular to machine precision, rcond = %g",
3296 solve_singularity_handler sing_handler,
3297 bool calc_cond)
const
3306 if (nr != b.
rows ())
3308 (
"matrix dimension mismatch solution of linear equations");
3309 else if (nr == 0 || nc == 0 || b.
cols () == 0)
3314 int typ = mattype.
type ();
3321 double ainvnorm = 0.;
3332 atmp += fabs (
data (i));
3340 retval.
resize (nc, b_nc);
3349 cwork[perm[i]] = b(i,j);
3359 if (perm[
ridx (i)] < minr)
3361 minr = perm[
ridx (i)];
3365 if (minr != k ||
data (mini) == 0)
3368 goto triangular_error;
3379 cwork[iidx] = cwork[iidx] - tmp *
data (i);
3385 retval(i, j) = cwork[i];
3407 i <
cidx (k+1); i++)
3408 if (perm[
ridx (i)] < minr)
3410 minr = perm[
ridx (i)];
3414 double tmp = work[k] /
data (mini);
3417 i <
cidx (k+1); i++)
3423 work[iidx] = work[iidx] - tmp *
data (i);
3431 atmp += fabs (work[i]);
3434 if (atmp > ainvnorm)
3437 rcond = 1. / ainvnorm / anorm;
3443 retval.
resize (nc, b_nc, 0.);
3460 goto triangular_error;
3468 cwork[iidx] = cwork[iidx] - tmp *
data (i);
3474 retval.
xelem (i, j) = cwork[i];
3493 double tmp = work[k] /
data (
cidx (k));
3496 i <
cidx (k+1); i++)
3499 work[iidx] = work[iidx] - tmp *
data (i);
3506 atmp += fabs (work[i]);
3509 if (atmp > ainvnorm)
3512 rcond = 1. / ainvnorm / anorm;
3521 sing_handler (rcond);
3526 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
3530 volatile double rcond_plus_one = rcond + 1.0;
3532 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3538 sing_handler (rcond);
3543 (
"matrix singular to machine precision, rcond = %g",
3557 solve_singularity_handler sing_handler,
3558 bool calc_cond)
const
3567 if (nr != b.
rows ())
3569 (
"matrix dimension mismatch solution of linear equations");
3570 else if (nr == 0 || nc == 0 || b.
cols () == 0)
3575 int typ = mattype.
type ();
3582 double ainvnorm = 0.;
3592 atmp += fabs (
data (i));
3601 retval.
xcidx (0) = 0;
3615 cwork[perm[b.
ridx (i)]] = b.
data (i);
3625 if (perm[
ridx (i)] < minr)
3627 minr = perm[
ridx (i)];
3631 if (minr != k ||
data (mini) == 0)
3634 goto triangular_error;
3645 cwork[iidx] = cwork[iidx] - tmp *
data (i);
3657 if (ii + new_nnz > x_nz)
3668 retval.
xridx (ii) = i;
3669 retval.
xdata (ii++) = cwork[i];
3671 retval.
xcidx (j+1) = ii;
3695 i <
cidx (k+1); i++)
3696 if (perm[
ridx (i)] < minr)
3698 minr = perm[
ridx (i)];
3702 double tmp = work[k] /
data (mini);
3705 i <
cidx (k+1); i++)
3711 work[iidx] = work[iidx] - tmp *
data (i);
3719 atmp += fabs (work[i]);
3722 if (atmp > ainvnorm)
3725 rcond = 1. / ainvnorm / anorm;
3747 goto triangular_error;
3755 cwork[iidx] = cwork[iidx] - tmp *
data (i);
3767 if (ii + new_nnz > x_nz)
3778 retval.
xridx (ii) = i;
3779 retval.
xdata (ii++) = cwork[i];
3781 retval.
xcidx (j+1) = ii;
3802 double tmp = work[k] /
data (
cidx (k));
3805 i <
cidx (k+1); i++)
3808 work[iidx] = work[iidx] - tmp *
data (i);
3815 atmp += fabs (work[i]);
3818 if (atmp > ainvnorm)
3821 rcond = 1. / ainvnorm / anorm;
3830 sing_handler (rcond);
3835 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
3839 volatile double rcond_plus_one = rcond + 1.0;
3841 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3847 sing_handler (rcond);
3852 (
"matrix singular to machine precision, rcond = %g",
3866 solve_singularity_handler sing_handler,
3867 bool calc_cond)
const
3875 if (nr != nc || nr != b.
rows ())
3877 (
"matrix dimension mismatch solution of linear equations");
3878 else if (nr == 0 || b.
cols () == 0)
3881 (*current_liboctave_error_handler)
3882 (
"calculation of condition number not implemented");
3886 volatile int typ = mattype.
type ();
3904 D[nc-1] =
data (ii);
3920 else if (
ridx (i) == j + 1)
3929 F77_XFCN (dptsv, DPTSV, (nr, b_nc, D, DL, result,
3955 DL[j] =
data (ii++);
3956 DU[j] =
data (ii++);
3958 D[nc-1] =
data (ii);
3975 else if (
ridx (i) == j + 1)
3977 else if (
ridx (i) == j - 1)
3986 F77_XFCN (dgtsv, DGTSV, (nr, b_nc, DL, D, DU, result,
3996 sing_handler (rcond);
4001 (
"matrix singular to machine precision");
4008 (*current_liboctave_error_handler) (
"incorrect matrix type");
4017 solve_singularity_handler sing_handler,
4018 bool calc_cond)
const
4026 if (nr != nc || nr != b.
rows ())
4028 (
"matrix dimension mismatch solution of linear equations");
4029 else if (nr == 0 || b.
cols () == 0)
4032 (*current_liboctave_error_handler)
4033 (
"calculation of condition number not implemented");
4037 int typ = mattype.
type ();
4058 DL[j] =
data (ii++);
4059 DU[j] =
data (ii++);
4061 D[nc-1] =
data (ii);
4078 else if (
ridx (i) == j + 1)
4080 else if (
ridx (i) == j - 1)
4085 F77_XFCN (dgttrf, DGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
4094 sing_handler (rcond);
4099 (
"matrix singular to machine precision");
4109 retval.
xcidx (0) = 0;
4123 nr, 1, DL, D, DU, DU2, pipvt,
4124 work, b.
rows (), err
4134 if (ii + new_nnz > x_nz)
4145 retval.
xridx (ii) = i;
4146 retval.
xdata (ii++) = work[i];
4148 retval.
xcidx (j+1) = ii;
4155 (*current_liboctave_error_handler) (
"incorrect matrix type");
4164 solve_singularity_handler sing_handler,
4165 bool calc_cond)
const
4173 if (nr != nc || nr != b.
rows ())
4175 (
"matrix dimension mismatch solution of linear equations");
4176 else if (nr == 0 || b.
cols () == 0)
4179 (*current_liboctave_error_handler)
4180 (
"calculation of condition number not implemented");
4184 volatile int typ = mattype.
type ();
4202 D[nc-1] =
data (ii);
4218 else if (
ridx (i) == j + 1)
4230 F77_XFCN (zptsv, ZPTSV, (nr, b_nc, D, DL, result,
4254 DL[j] =
data (ii++);
4255 DU[j] =
data (ii++);
4257 D[nc-1] =
data (ii);
4274 else if (
ridx (i) == j + 1)
4276 else if (
ridx (i) == j - 1)
4288 F77_XFCN (zgtsv, ZGTSV, (nr, b_nc, DL, D, DU, result,
4298 sing_handler (rcond);
4303 (
"matrix singular to machine precision");
4307 (*current_liboctave_error_handler) (
"incorrect matrix type");
4316 solve_singularity_handler sing_handler,
4317 bool calc_cond)
const
4325 if (nr != nc || nr != b.
rows ())
4327 (
"matrix dimension mismatch solution of linear equations");
4328 else if (nr == 0 || b.
cols () == 0)
4331 (*current_liboctave_error_handler)
4332 (
"calculation of condition number not implemented");
4336 int typ = mattype.
type ();
4357 DL[j] =
data (ii++);
4358 DU[j] =
data (ii++);
4360 D[nc-1] =
data (ii);
4377 else if (
ridx (i) == j + 1)
4379 else if (
ridx (i) == j - 1)
4384 F77_XFCN (dgttrf, DGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
4393 sing_handler (rcond);
4398 (
"matrix singular to machine precision");
4415 retval.
xcidx (0) = 0;
4428 nr, 1, DL, D, DU, DU2, pipvt,
4434 (*current_liboctave_error_handler)
4435 (
"SparseMatrix::solve solve failed");
4443 nr, 1, DL, D, DU, DU2, pipvt,
4449 (*current_liboctave_error_handler)
4450 (
"SparseMatrix::solve solve failed");
4460 if (Bx[i] != 0. || Bz[i] != 0.)
4463 if (ii + new_nnz > x_nz)
4472 if (Bx[i] != 0. || Bz[i] != 0.)
4474 retval.
xridx (ii) = i;
4475 retval.
xdata (ii++) =
4479 retval.
xcidx (j+1) = ii;
4486 (*current_liboctave_error_handler) (
"incorrect matrix type");
4495 solve_singularity_handler sing_handler,
4496 bool calc_cond)
const
4504 if (nr != nc || nr != b.
rows ())
4506 (
"matrix dimension mismatch solution of linear equations");
4507 else if (nr == 0 || b.
cols () == 0)
4512 volatile int typ = mattype.
type ();
4528 tmp_data[ii++] = 0.;
4536 m_band(ri - j, j) =
data (i);
4546 nr, n_lower, tmp_data, ldm, err
4569 nr, n_lower, tmp_data, ldm,
4570 anorm, rcond, pz, piz, err
4576 volatile double rcond_plus_one = rcond + 1.0;
4578 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4584 sing_handler (rcond);
4589 (
"matrix singular to machine precision, rcond = %g",
4605 nr, n_lower, b_nc, tmp_data,
4606 ldm, result, b.
rows (), err
4611 (*current_liboctave_error_handler)
4612 (
"SparseMatrix::solve solve failed");
4635 tmp_data[ii++] = 0.;
4640 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
4650 atmp += fabs (
data (i));
4659 F77_XFCN (dgbtrf, DGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
4671 sing_handler (rcond);
4676 (
"matrix singular to machine precision");
4691 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
4692 anorm, rcond, pz, piz, err
4698 volatile double rcond_plus_one = rcond + 1.0;
4700 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4706 sing_handler (rcond);
4711 (
"matrix singular to machine precision, rcond = %g",
4728 nr, n_lower, n_upper, b_nc, tmp_data,
4729 ldm, pipvt, result, b.
rows (), err
4735 (*current_liboctave_error_handler) (
"incorrect matrix type");
4744 solve_singularity_handler sing_handler,
4745 bool calc_cond)
const
4753 if (nr != nc || nr != b.
rows ())
4755 (
"matrix dimension mismatch solution of linear equations");
4756 else if (nr == 0 || b.
cols () == 0)
4761 volatile int typ = mattype.
type ();
4778 tmp_data[ii++] = 0.;
4786 m_band(ri - j, j) =
data (i);
4796 nr, n_lower, tmp_data, ldm, err
4817 nr, n_lower, tmp_data, ldm,
4818 anorm, rcond, pz, piz, err
4824 volatile double rcond_plus_one = rcond + 1.0;
4826 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4832 sing_handler (rcond);
4837 (
"matrix singular to machine precision, rcond = %g",
4856 retval.
xcidx (0) = 0;
4860 Bx[i] = b.
elem (i, j);
4864 nr, n_lower, 1, tmp_data,
4870 (*current_liboctave_error_handler)
4871 (
"SparseMatrix::solve solve failed");
4886 sz = (sz > 10 ? sz : 10) + x_nz;
4890 retval.
xdata (ii) = tmp;
4891 retval.
xridx (ii++) = i;
4894 retval.
xcidx (j+1) = ii;
4918 tmp_data[ii++] = 0.;
4923 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
4933 atmp += fabs (
data (i));
4942 F77_XFCN (dgbtrf, DGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
4952 sing_handler (rcond);
4957 (
"matrix singular to machine precision");
4972 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
4973 anorm, rcond, pz, piz, err
4979 volatile double rcond_plus_one = rcond + 1.0;
4981 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4987 sing_handler (rcond);
4992 (
"matrix singular to machine precision, rcond = %g",
5005 retval.
xcidx (0) = 0;
5015 i < b.
cidx (j+1); i++)
5020 nr, n_lower, n_upper, 1, tmp_data,
5021 ldm, pipvt, work, b.
rows (), err
5031 if (ii + new_nnz > x_nz)
5042 retval.
xridx (ii) = i;
5043 retval.
xdata (ii++) = work[i];
5045 retval.
xcidx (j+1) = ii;
5053 (*current_liboctave_error_handler) (
"incorrect matrix type");
5062 solve_singularity_handler sing_handler,
5063 bool calc_cond)
const
5071 if (nr != nc || nr != b.
rows ())
5073 (
"matrix dimension mismatch solution of linear equations");
5074 else if (nr == 0 || b.
cols () == 0)
5079 volatile int typ = mattype.
type ();
5096 tmp_data[ii++] = 0.;
5104 m_band(ri - j, j) =
data (i);
5114 nr, n_lower, tmp_data, ldm, err
5137 nr, n_lower, tmp_data, ldm,
5138 anorm, rcond, pz, piz, err
5144 volatile double rcond_plus_one = rcond + 1.0;
5146 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5152 sing_handler (rcond);
5157 (
"matrix singular to machine precision, rcond = %g",
5172 retval.
resize (b_nr, b_nc);
5185 nr, n_lower, 1, tmp_data,
5191 (*current_liboctave_error_handler)
5192 (
"SparseMatrix::solve solve failed");
5199 nr, n_lower, 1, tmp_data,
5200 ldm, Bz, b.
rows (), err
5205 (*current_liboctave_error_handler)
5206 (
"SparseMatrix::solve solve failed");
5212 retval(i, j) =
Complex (Bx[i], Bz[i]);
5234 tmp_data[ii++] = 0.;
5239 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
5249 atmp += fabs (
data (i));
5258 F77_XFCN (dgbtrf, DGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
5268 sing_handler (rcond);
5273 (
"matrix singular to machine precision");
5288 nr, n_lower, tmp_data, ldm,
5289 anorm, rcond, pz, piz, err
5295 volatile double rcond_plus_one = rcond + 1.0;
5297 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5303 sing_handler (rcond);
5308 (
"matrix singular to machine precision, rcond = %g",
5335 nr, n_lower, n_upper, 1, tmp_data,
5336 ldm, pipvt, Bx, b.
rows (), err
5341 nr, n_lower, n_upper, 1, tmp_data,
5342 ldm, pipvt, Bz, b.
rows (), err
5346 retval(i, j) =
Complex (Bx[i], Bz[i]);
5352 (*current_liboctave_error_handler) (
"incorrect matrix type");
5361 solve_singularity_handler sing_handler,
5362 bool calc_cond)
const
5370 if (nr != nc || nr != b.
rows ())
5372 (
"matrix dimension mismatch solution of linear equations");
5373 else if (nr == 0 || b.
cols () == 0)
5378 volatile int typ = mattype.
type ();
5395 tmp_data[ii++] = 0.;
5403 m_band(ri - j, j) =
data (i);
5413 nr, n_lower, tmp_data, ldm, err
5437 nr, n_lower, tmp_data, ldm,
5438 anorm, rcond, pz, piz, err
5444 volatile double rcond_plus_one = rcond + 1.0;
5446 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5452 sing_handler (rcond);
5457 (
"matrix singular to machine precision, rcond = %g",
5477 retval.
xcidx (0) = 0;
5490 nr, n_lower, 1, tmp_data,
5496 (*current_liboctave_error_handler)
5497 (
"SparseMatrix::solve solve failed");
5504 nr, n_lower, 1, tmp_data,
5510 (*current_liboctave_error_handler)
5511 (
"SparseMatrix::solve solve failed");
5521 if (Bx[i] != 0. || Bz[i] != 0.)
5524 if (ii + new_nnz > x_nz)
5533 if (Bx[i] != 0. || Bz[i] != 0.)
5535 retval.
xridx (ii) = i;
5536 retval.
xdata (ii++) =
5540 retval.
xcidx (j+1) = ii;
5564 tmp_data[ii++] = 0.;
5569 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
5579 atmp += fabs (
data (i));
5588 F77_XFCN (dgbtrf, DGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
5598 sing_handler (rcond);
5603 (
"matrix singular to machine precision");
5618 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
5619 anorm, rcond, pz, piz, err
5625 volatile double rcond_plus_one = rcond + 1.0;
5627 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5633 sing_handler (rcond);
5638 (
"matrix singular to machine precision, rcond = %g",
5651 retval.
xcidx (0) = 0;
5665 i < b.
cidx (j+1); i++)
5674 nr, n_lower, n_upper, 1, tmp_data,
5675 ldm, pipvt, Bx, b.
rows (), err
5680 nr, n_lower, n_upper, 1, tmp_data,
5681 ldm, pipvt, Bz, b.
rows (), err
5688 if (Bx[i] != 0. || Bz[i] != 0.)
5691 if (ii + new_nnz > x_nz)
5700 if (Bx[i] != 0. || Bz[i] != 0.)
5702 retval.
xridx (ii) = i;
5703 retval.
xdata (ii++) =
5706 retval.
xcidx (j+1) = ii;
5714 (*current_liboctave_error_handler) (
"incorrect matrix type");
5722 Matrix &Info, solve_singularity_handler sing_handler,
5723 bool calc_cond)
const
5731 Control =
Matrix (UMFPACK_CONTROL, 1);
5737 Control (UMFPACK_PRL) = tmp;
5741 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
5742 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
5748 Control (UMFPACK_FIXQ) = tmp;
5754 const double *Ax =
data ();
5758 UMFPACK_DNAME (report_matrix) (nr, nc, Ap, Ai, Ax, 1, control);
5761 Info =
Matrix (1, UMFPACK_INFO);
5763 int status =
UMFPACK_DNAME (qsymbolic) (nr, nc, Ap, Ai, Ax, 0,
5764 &Symbolic, control, info);
5768 (*current_liboctave_error_handler)
5769 (
"SparseMatrix::solve symbolic factorization failed");
5782 &Numeric, control, info);
5786 rcond = Info (UMFPACK_RCOND);
5789 volatile double rcond_plus_one = rcond + 1.0;
5791 if (status == UMFPACK_WARNING_singular_matrix ||
5792 rcond_plus_one == 1.0 ||
xisnan (rcond))
5799 sing_handler (rcond);
5802 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
5806 else if (status < 0)
5808 (*current_liboctave_error_handler)
5809 (
"SparseMatrix::solve numeric factorization failed");
5826 (*current_liboctave_error_handler) (
"UMFPACK not installed");
5835 solve_singularity_handler sing_handler,
5836 bool calc_cond)
const
5844 if (nr != nc || nr != b.
rows ())
5846 (
"matrix dimension mismatch solution of linear equations");
5847 else if (nr == 0 || b.
cols () == 0)
5852 volatile int typ = mattype.
type ();
5858 cholmod_common Common;
5859 cholmod_common *cm = &Common;
5862 CHOLMOD_NAME(start) (cm);
5863 cm->prefer_zomplex =
false;
5869 cm->print_function = 0;
5873 cm->print =
static_cast<int> (spu) + 2;
5878 cm->complex_divide = CHOLMOD_NAME(divcomplex);
5879 cm->hypotenuse = CHOLMOD_NAME(hypot);
5881 cm->final_ll =
true;
5883 cholmod_sparse Astore;
5884 cholmod_sparse *
A = &Astore;
5895 #ifdef USE_64_BIT_IDX_T
5896 A->itype = CHOLMOD_LONG;
5898 A->itype = CHOLMOD_INT;
5900 A->dtype = CHOLMOD_DOUBLE;
5902 A->xtype = CHOLMOD_REAL;
5909 cholmod_dense Bstore;
5910 cholmod_dense *
B = &Bstore;
5911 B->nrow = b.
rows ();
5912 B->ncol = b.
cols ();
5914 B->nzmax = B->nrow * B->ncol;
5915 B->dtype = CHOLMOD_DOUBLE;
5916 B->xtype = CHOLMOD_REAL;
5917 if (nc < 1 || b.
cols () < 1)
5925 L = CHOLMOD_NAME(analyze) (
A, cm);
5928 rcond = CHOLMOD_NAME(rcond)(L, cm);
5942 volatile double rcond_plus_one = rcond + 1.0;
5944 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5950 sing_handler (rcond);
5955 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
5963 X = CHOLMOD_NAME(
solve) (CHOLMOD_A, L,
B, cm);
5971 retval.
xelem (i,j) =
static_cast<double *
>(X->x)[jr + i];
5975 CHOLMOD_NAME(free_dense) (&X, cm);
5976 CHOLMOD_NAME(free_factor) (&L, cm);
5977 CHOLMOD_NAME(finish) (cm);
5978 static char tmp[] =
" ";
5979 CHOLMOD_NAME(print_common) (tmp, cm);
5983 (*current_liboctave_warning_handler)
5984 (
"CHOLMOD not installed");
5996 factorize (err, rcond, Control, Info, sing_handler, calc_cond);
6010 const double *Ax =
data ();
6015 Ai, Ax, &result[iidx],
6016 &Bx[iidx], Numeric, control,
6020 (*current_liboctave_error_handler)
6021 (
"SparseMatrix::solve solve failed");
6039 (*current_liboctave_error_handler) (
"UMFPACK not installed");
6043 (*current_liboctave_error_handler) (
"incorrect matrix type");
6052 solve_singularity_handler sing_handler,
6053 bool calc_cond)
const
6061 if (nr != nc || nr != b.
rows ())
6063 (
"matrix dimension mismatch solution of linear equations");
6064 else if (nr == 0 || b.
cols () == 0)
6069 volatile int typ = mattype.
type ();
6075 cholmod_common Common;
6076 cholmod_common *cm = &Common;
6079 CHOLMOD_NAME(start) (cm);
6080 cm->prefer_zomplex =
false;
6086 cm->print_function = 0;
6090 cm->print =
static_cast<int> (spu) + 2;
6095 cm->complex_divide = CHOLMOD_NAME(divcomplex);
6096 cm->hypotenuse = CHOLMOD_NAME(hypot);
6098 cm->final_ll =
true;
6100 cholmod_sparse Astore;
6101 cholmod_sparse *
A = &Astore;
6112 #ifdef USE_64_BIT_IDX_T
6113 A->itype = CHOLMOD_LONG;
6115 A->itype = CHOLMOD_INT;
6117 A->dtype = CHOLMOD_DOUBLE;
6119 A->xtype = CHOLMOD_REAL;
6126 cholmod_sparse Bstore;
6127 cholmod_sparse *
B = &Bstore;
6128 B->nrow = b.
rows ();
6129 B->ncol = b.
cols ();
6132 B->nzmax = b.
nnz ();
6136 #ifdef USE_64_BIT_IDX_T
6137 B->itype = CHOLMOD_LONG;
6139 B->itype = CHOLMOD_INT;
6141 B->dtype = CHOLMOD_DOUBLE;
6143 B->xtype = CHOLMOD_REAL;
6145 if (b.
rows () < 1 || b.
cols () < 1)
6152 L = CHOLMOD_NAME(analyze) (
A, cm);
6155 rcond = CHOLMOD_NAME(rcond)(L, cm);
6168 volatile double rcond_plus_one = rcond + 1.0;
6170 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
6176 sing_handler (rcond);
6181 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
6189 X = CHOLMOD_NAME(spsolve) (CHOLMOD_A, L,
B, cm);
6192 retval =
SparseMatrix (static_cast<octave_idx_type>(X->nrow),
6193 static_cast<octave_idx_type>(X->ncol),
6194 static_cast<octave_idx_type>(X->nzmax));
6196 j <= static_cast<octave_idx_type>(X->ncol); j++)
6199 j < static_cast<octave_idx_type>(X->nzmax); j++)
6202 retval.
xdata (j) =
static_cast<double *
>(X->x)[j];
6206 CHOLMOD_NAME(free_sparse) (&X, cm);
6207 CHOLMOD_NAME(free_factor) (&L, cm);
6208 CHOLMOD_NAME(finish) (cm);
6209 static char tmp[] =
" ";
6210 CHOLMOD_NAME(print_common) (tmp, cm);
6214 (*current_liboctave_warning_handler)
6215 (
"CHOLMOD not installed");
6226 void *Numeric =
factorize (err, rcond, Control, Info,
6227 sing_handler, calc_cond);
6238 const double *Ax =
data ();
6249 retval.
xcidx (0) = 0;
6254 Bx[i] = b.
elem (i, j);
6257 Ai, Ax, Xx, Bx, Numeric,
6261 (*current_liboctave_error_handler)
6262 (
"SparseMatrix::solve solve failed");
6280 sz = (sz > 10 ? sz : 10) + x_nz;
6284 retval.
xdata (ii) = tmp;
6285 retval.
xridx (ii++) = i;
6288 retval.
xcidx (j+1) = ii;
6301 (*current_liboctave_error_handler) (
"UMFPACK not installed");
6305 (*current_liboctave_error_handler) (
"incorrect matrix type");
6314 solve_singularity_handler sing_handler,
6315 bool calc_cond)
const
6323 if (nr != nc || nr != b.
rows ())
6325 (
"matrix dimension mismatch solution of linear equations");
6326 else if (nr == 0 || b.
cols () == 0)
6331 volatile int typ = mattype.
type ();
6337 cholmod_common Common;
6338 cholmod_common *cm = &Common;
6341 CHOLMOD_NAME(start) (cm);
6342 cm->prefer_zomplex =
false;
6348 cm->print_function = 0;
6352 cm->print =
static_cast<int> (spu) + 2;
6357 cm->complex_divide = CHOLMOD_NAME(divcomplex);
6358 cm->hypotenuse = CHOLMOD_NAME(hypot);
6360 cm->final_ll =
true;
6362 cholmod_sparse Astore;
6363 cholmod_sparse *
A = &Astore;
6374 #ifdef USE_64_BIT_IDX_T
6375 A->itype = CHOLMOD_LONG;
6377 A->itype = CHOLMOD_INT;
6379 A->dtype = CHOLMOD_DOUBLE;
6381 A->xtype = CHOLMOD_REAL;
6388 cholmod_dense Bstore;
6389 cholmod_dense *
B = &Bstore;
6390 B->nrow = b.
rows ();
6391 B->ncol = b.
cols ();
6393 B->nzmax = B->nrow * B->ncol;
6394 B->dtype = CHOLMOD_DOUBLE;
6395 B->xtype = CHOLMOD_COMPLEX;
6396 if (nc < 1 || b.
cols () < 1)
6404 L = CHOLMOD_NAME(analyze) (
A, cm);
6407 rcond = CHOLMOD_NAME(rcond)(L, cm);
6420 volatile double rcond_plus_one = rcond + 1.0;
6422 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
6428 sing_handler (rcond);
6433 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
6441 X = CHOLMOD_NAME(
solve) (CHOLMOD_A, L,
B, cm);
6449 retval.
xelem (i,j) =
static_cast<Complex *
>(X->x)[jr + i];
6453 CHOLMOD_NAME(free_dense) (&X, cm);
6454 CHOLMOD_NAME(free_factor) (&L, cm);
6455 CHOLMOD_NAME(finish) (cm);
6456 static char tmp[] =
" ";
6457 CHOLMOD_NAME(print_common) (tmp, cm);
6461 (*current_liboctave_warning_handler)
6462 (
"CHOLMOD not installed");
6473 void *Numeric =
factorize (err, rcond, Control, Info,
6474 sing_handler, calc_cond);
6485 const double *Ax =
data ();
6490 retval.
resize (b_nr, b_nc);
6505 Ai, Ax, Xx, Bx, Numeric,
6509 Numeric, control, info);
6511 if (status < 0 || status2 < 0)
6513 (*current_liboctave_error_handler)
6514 (
"SparseMatrix::solve solve failed");
6524 retval(i, j) =
Complex (Xx[i], Xz[i]);
6535 (*current_liboctave_error_handler) (
"UMFPACK not installed");
6539 (*current_liboctave_error_handler) (
"incorrect matrix type");
6548 solve_singularity_handler sing_handler,
6549 bool calc_cond)
const
6557 if (nr != nc || nr != b.
rows ())
6559 (
"matrix dimension mismatch solution of linear equations");
6560 else if (nr == 0 || b.
cols () == 0)
6565 volatile int typ = mattype.
type ();
6571 cholmod_common Common;
6572 cholmod_common *cm = &Common;
6575 CHOLMOD_NAME(start) (cm);
6576 cm->prefer_zomplex =
false;
6582 cm->print_function = 0;
6586 cm->print =
static_cast<int> (spu) + 2;
6591 cm->complex_divide = CHOLMOD_NAME(divcomplex);
6592 cm->hypotenuse = CHOLMOD_NAME(hypot);
6594 cm->final_ll =
true;
6596 cholmod_sparse Astore;
6597 cholmod_sparse *
A = &Astore;
6608 #ifdef USE_64_BIT_IDX_T
6609 A->itype = CHOLMOD_LONG;
6611 A->itype = CHOLMOD_INT;
6613 A->dtype = CHOLMOD_DOUBLE;
6615 A->xtype = CHOLMOD_REAL;
6622 cholmod_sparse Bstore;
6623 cholmod_sparse *
B = &Bstore;
6624 B->nrow = b.
rows ();
6625 B->ncol = b.
cols ();
6628 B->nzmax = b.
nnz ();
6632 #ifdef USE_64_BIT_IDX_T
6633 B->itype = CHOLMOD_LONG;
6635 B->itype = CHOLMOD_INT;
6637 B->dtype = CHOLMOD_DOUBLE;
6639 B->xtype = CHOLMOD_COMPLEX;
6641 if (b.
rows () < 1 || b.
cols () < 1)
6648 L = CHOLMOD_NAME(analyze) (
A, cm);
6651 rcond = CHOLMOD_NAME(rcond)(L, cm);
6664 volatile double rcond_plus_one = rcond + 1.0;
6666 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
6672 sing_handler (rcond);
6677 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
6685 X = CHOLMOD_NAME(spsolve) (CHOLMOD_A, L,
B, cm);
6689 (static_cast<octave_idx_type>(X->nrow),
6690 static_cast<octave_idx_type>(X->ncol),
6691 static_cast<octave_idx_type>(X->nzmax));
6693 j <= static_cast<octave_idx_type>(X->ncol); j++)
6696 j < static_cast<octave_idx_type>(X->nzmax); j++)
6703 CHOLMOD_NAME(free_sparse) (&X, cm);
6704 CHOLMOD_NAME(free_factor) (&L, cm);
6705 CHOLMOD_NAME(finish) (cm);
6706 static char tmp[] =
" ";
6707 CHOLMOD_NAME(print_common) (tmp, cm);
6711 (*current_liboctave_warning_handler)
6712 (
"CHOLMOD not installed");
6723 void *Numeric =
factorize (err, rcond, Control, Info,
6724 sing_handler, calc_cond);
6735 const double *Ax =
data ();
6749 retval.
xcidx (0) = 0;
6760 Ai, Ax, Xx, Bx, Numeric,
6764 Numeric, control, info);
6766 if (status < 0 || status2 < 0)
6768 (*current_liboctave_error_handler)
6769 (
"SparseMatrix::solve solve failed");
6787 sz = (sz > 10 ? sz : 10) + x_nz;
6791 retval.
xdata (ii) = tmp;
6792 retval.
xridx (ii++) = i;
6795 retval.
xcidx (j+1) = ii;
6807 (*current_liboctave_error_handler) (
"UMFPACK not installed");
6811 (*current_liboctave_error_handler) (
"incorrect matrix type");
6822 return solve (mattype, b, info, rcond, 0);
6830 return solve (mattype, b, info, rcond, 0);
6837 return solve (mattype, b, info, rcond, 0);
6842 double& rcond, solve_singularity_handler sing_handler,
6843 bool singular_fallback)
const
6846 int typ = mattype.
type (
false);
6849 typ = mattype.
type (*
this);
6853 retval =
dsolve (mattype, b, err, rcond, sing_handler,
false);
6855 retval =
utsolve (mattype, b, err, rcond, sing_handler,
false);
6857 retval =
ltsolve (mattype, b, err, rcond, sing_handler,
false);
6859 retval =
bsolve (mattype, b, err, rcond, sing_handler,
false);
6862 retval =
trisolve (mattype, b, err, rcond, sing_handler,
false);
6864 retval =
fsolve (mattype, b, err, rcond, sing_handler,
true);
6867 (*current_liboctave_error_handler) (
"unknown matrix type");
6876 retval =
qrsolve (*
this, b, err);
6878 retval = dmsolve<Matrix, SparseMatrix, Matrix> (*
this, b, err);
6890 return solve (mattype, b, info, rcond, 0);
6898 return solve (mattype, b, info, rcond, 0);
6905 return solve (mattype, b, info, rcond, 0);
6911 solve_singularity_handler sing_handler,
6912 bool singular_fallback)
const
6915 int typ = mattype.
type (
false);
6918 typ = mattype.
type (*
this);
6921 retval =
dsolve (mattype, b, err, rcond, sing_handler,
false);
6923 retval =
utsolve (mattype, b, err, rcond, sing_handler,
false);
6925 retval =
ltsolve (mattype, b, err, rcond, sing_handler,
false);
6927 retval =
bsolve (mattype, b, err, rcond, sing_handler,
false);
6930 retval =
trisolve (mattype, b, err, rcond, sing_handler,
false);
6932 retval =
fsolve (mattype, b, err, rcond, sing_handler,
true);
6935 (*current_liboctave_error_handler) (
"unknown matrix type");
6943 retval =
qrsolve (*
this, b, err);
6945 retval = dmsolve<SparseMatrix, SparseMatrix, SparseMatrix>
6958 return solve (mattype, b, info, rcond, 0);
6966 return solve (mattype, b, info, rcond, 0);
6973 return solve (mattype, b, info, rcond, 0);
6979 solve_singularity_handler sing_handler,
6980 bool singular_fallback)
const
6983 int typ = mattype.
type (
false);
6986 typ = mattype.
type (*
this);
6989 retval =
dsolve (mattype, b, err, rcond, sing_handler,
false);
6991 retval =
utsolve (mattype, b, err, rcond, sing_handler,
false);
6993 retval =
ltsolve (mattype, b, err, rcond, sing_handler,
false);
6995 retval =
bsolve (mattype, b, err, rcond, sing_handler,
false);
6998 retval =
trisolve (mattype, b, err, rcond, sing_handler,
false);
7000 retval =
fsolve (mattype, b, err, rcond, sing_handler,
true);
7003 (*current_liboctave_error_handler) (
"unknown matrix type");
7011 retval =
qrsolve (*
this, b, err);
7013 retval = dmsolve<ComplexMatrix, SparseMatrix, ComplexMatrix>
7026 return solve (mattype, b, info, rcond, 0);
7034 return solve (mattype, b, info, rcond, 0);
7041 return solve (mattype, b, info, rcond, 0);
7047 solve_singularity_handler sing_handler,
7048 bool singular_fallback)
const
7051 int typ = mattype.
type (
false);
7054 typ = mattype.
type (*
this);
7057 retval =
dsolve (mattype, b, err, rcond, sing_handler,
false);
7059 retval =
utsolve (mattype, b, err, rcond, sing_handler,
false);
7061 retval =
ltsolve (mattype, b, err, rcond, sing_handler,
false);
7063 retval =
bsolve (mattype, b, err, rcond, sing_handler,
false);
7066 retval =
trisolve (mattype, b, err, rcond, sing_handler,
false);
7068 retval =
fsolve (mattype, b, err, rcond, sing_handler,
true);
7071 (*current_liboctave_error_handler) (
"unknown matrix type");
7079 retval =
qrsolve (*
this, b, err);
7081 retval = dmsolve<SparseComplexMatrix, SparseMatrix, SparseComplexMatrix>
7093 return solve (mattype, b, info, rcond);
7101 return solve (mattype, b, info, rcond);
7108 return solve (mattype, b, info, rcond, 0);
7114 solve_singularity_handler sing_handler)
const
7117 return solve (mattype, tmp, info, rcond,
7118 sing_handler).
column (static_cast<octave_idx_type> (0));
7126 return solve (mattype, b, info, rcond, 0);
7134 return solve (mattype, b, info, rcond, 0);
7140 double& rcond)
const
7142 return solve (mattype, b, info, rcond, 0);
7148 solve_singularity_handler sing_handler)
const
7151 return solve (mattype, tmp, info, rcond,
7152 sing_handler).
column (static_cast<octave_idx_type> (0));
7160 return solve (b, info, rcond, 0);
7167 return solve (b, info, rcond, 0);
7172 double& rcond)
const
7174 return solve (b, info, rcond, 0);
7179 solve_singularity_handler sing_handler)
const
7182 return solve (mattype, b, err, rcond, sing_handler);
7190 return solve (b, info, rcond, 0);
7198 return solve (b, info, rcond, 0);
7205 return solve (b, info, rcond, 0);
7210 solve_singularity_handler sing_handler)
const
7213 return solve (mattype, b, err, rcond, sing_handler);
7220 return solve (b, info, rcond, 0);
7225 double& rcond)
const
7227 return solve (b, info, rcond, 0);
7233 solve_singularity_handler sing_handler)
const
7236 return solve (mattype, b, err, rcond, sing_handler);
7244 return solve (b, info, rcond, 0);
7251 return solve (b, info, rcond, 0);
7256 double& rcond)
const
7258 return solve (b, info, rcond, 0);
7264 solve_singularity_handler sing_handler)
const
7267 return solve (mattype, b, err, rcond, sing_handler);
7274 return solve (b, info, rcond);
7281 return solve (b, info, rcond);
7286 double& rcond)
const
7288 return solve (b, info, rcond, 0);
7294 solve_singularity_handler sing_handler)
const
7297 return solve (tmp, info, rcond,
7298 sing_handler).
column (static_cast<octave_idx_type> (0));
7306 return solve (b, info, rcond, 0);
7313 return solve (b, info, rcond, 0);
7318 double& rcond)
const
7320 return solve (b, info, rcond, 0);
7326 solve_singularity_handler sing_handler)
const
7329 return solve (tmp, info, rcond, sing_handler).
column (static_cast<octave_idx_type> (0));
7362 double val =
data (i);
7377 double val =
data (i);
7392 double val =
data (i);
7393 if (val != 0.0 && val != 1.0)
7419 double val =
data (i);
7445 double val =
data (i);
7486 if (jj <
cidx (i+1) &&
ridx (jj) == j)
7529 if ((
rows () == 1 && dim == -1) || dim == 1)
7534 (
cidx (j+1) -
cidx (j) < nr ? 0.0 : 1.0), 1.0);
7548 double d = data (i); \
7549 tmp[ridx (i)] += d * d
7552 double d = data (i); \
7570 retval.
data (i) = fabs (retval.
data (i));
7599 os << a.
ridx (i) + 1 <<
" " << j + 1 <<
" ";
7613 return read_sparse_matrix<elt_type> (is, a, octave_read_value<double>);
7677 return do_mul_dm_sm<SparseMatrix> (
d, a);
7683 return do_mul_sm_dm<SparseMatrix> (a,
d);
7689 return do_add_dm_sm<SparseMatrix> (
d, a);
7695 return do_sub_dm_sm<SparseMatrix> (
d, a);
7701 return do_add_sm_dm<SparseMatrix> (a,
d);
7707 return do_sub_sm_dm<SparseMatrix> (a,
d);
7726 #define EMPTY_RETURN_CHECK(T) \
7727 if (nr == 0 || nc == 0) \
7751 result.
xdata (idx) = tmp;
7767 result.
xcidx (0) = 0;
7776 result.
xdata (ii) = tmp;
7780 result.
xcidx (j+1) = ii;
7806 if (a_nr != b_nr || a_nc != b_nc)
7818 bool ja_lt_max= ja < ja_max;
7822 bool jb_lt_max = jb < jb_max;
7824 while (ja_lt_max || jb_lt_max )
7827 if ((! jb_lt_max) ||
7828 (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
7830 double tmp =
xmin (a.
data (ja), 0.);
7838 ja_lt_max= ja < ja_max;
7840 else if (( !ja_lt_max ) ||
7841 (jb_lt_max && (b.
ridx (jb) < a.
ridx (ja)) ) )
7843 double tmp =
xmin (0., b.
data (jb));
7851 jb_lt_max= jb < jb_max;
7863 ja_lt_max= ja < ja_max;
7865 jb_lt_max= jb < jb_max;
7902 result.
xdata (idx) = tmp;
7918 result.
xcidx (0) = 0;
7926 result.
xdata (ii) = tmp;
7930 result.
xcidx (j+1) = ii;
7956 if (a_nr != b_nr || a_nc != b_nc)
7968 bool ja_lt_max= ja < ja_max;
7972 bool jb_lt_max = jb < jb_max;
7974 while (ja_lt_max || jb_lt_max )
7977 if ((! jb_lt_max) ||
7978 (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
7980 double tmp =
xmax (a.
data (ja), 0.);
7988 ja_lt_max= ja < ja_max;
7990 else if (( !ja_lt_max ) ||
7991 (jb_lt_max && (b.
ridx (jb) < a.
ridx (ja)) ) )
7993 double tmp =
xmax (0., b.
data (jb));
8001 jb_lt_max= jb < jb_max;
8013 ja_lt_max= ja < ja_max;
8015 jb_lt_max= jb < jb_max;