71 const octave_idx_type&,
const octave_idx_type&,
72 Complex*,
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 Complex*,
const octave_idx_type&,
80 const octave_idx_type*, Complex*,
81 const octave_idx_type&, octave_idx_type&
86 const octave_idx_type&,
const octave_idx_type&,
87 const octave_idx_type&, Complex*,
88 const octave_idx_type&,
const octave_idx_type*,
89 const double&,
double&, Complex*,
double*,
95 const octave_idx_type&,
const octave_idx_type&,
96 Complex*,
const octave_idx_type&, octave_idx_type&
101 const octave_idx_type&,
const octave_idx_type&,
102 const octave_idx_type&, Complex*,
103 const octave_idx_type&, Complex*,
104 const octave_idx_type&, octave_idx_type&
109 const octave_idx_type&,
const octave_idx_type&,
110 Complex*,
const octave_idx_type&,
const double&,
111 double&, Complex*,
double*, octave_idx_type&
115 F77_FUNC (zgttrf, ZGTTRF) (
const octave_idx_type&, Complex*, Complex*,
116 Complex*, Complex*, octave_idx_type*,
121 const octave_idx_type&,
const octave_idx_type&,
122 const Complex*,
const Complex*,
const Complex*,
123 const Complex*,
const octave_idx_type*,
124 Complex *,
const octave_idx_type&,
129 F77_FUNC (zptsv, ZPTSV) (
const octave_idx_type&,
const octave_idx_type&,
130 double*, Complex*, Complex*,
131 const octave_idx_type&, octave_idx_type&);
134 F77_FUNC (zgtsv, ZGTSV) (
const octave_idx_type&,
const octave_idx_type&,
135 Complex*, Complex*, Complex*, Complex*,
136 const octave_idx_type&, octave_idx_type&);
187 if (nr != nr_a || nc != nc_a || nz != nz_a)
204 return !(*
this == a);
213 if (nr == nc && nr > 0)
253 return max (dummy_idx, dim);
278 if (nr == 0 || nc == 0 || dim >= dv.
length ())
289 if (
ridx (i) != idx_j)
310 if (
xisnan (abs_max) || abs_tmp > abs_max)
318 idx_arg.
elem (j) =
xisnan (tmp_max) ? 0 : idx_j;
326 result.
xcidx (0) = 0;
332 result.
xdata (ii) = tmp;
333 result.
xridx (ii++) = 0;
335 result.
xcidx (j+1) = ii;
342 if (nr == 0 || nc == 0 || dim >= dv.
length ())
352 if (found[
ridx (i)] == -j)
353 found[
ridx (i)] = -j - 1;
356 if (found[i] > -nc && found[i] < 0)
357 idx_arg.
elem (i) = -found[i];
370 idx_arg.
elem (ir) = j;
376 if (idx_arg.
elem (j) == -1 ||
elem (j, idx_arg.
elem (j)) != 0.)
382 result.
xcidx (0) = 0;
383 result.
xcidx (1) = nel;
386 if (idx_arg(j) == -1)
390 result.
xridx (ii++) = j;
397 result.
xdata (ii) = tmp;
398 result.
xridx (ii++) = j;
411 return min (dummy_idx, dim);
435 if (nr == 0 || nc == 0 || dim >= dv.
length ())
446 if (
ridx (i) != idx_j)
467 if (
xisnan (abs_min) || abs_tmp < abs_min)
475 idx_arg.
elem (j) =
xisnan (tmp_min) ? 0 : idx_j;
483 result.
xcidx (0) = 0;
489 result.
xdata (ii) = tmp;
490 result.
xridx (ii++) = 0;
492 result.
xcidx (j+1) = ii;
499 if (nr == 0 || nc == 0 || dim >= dv.
length ())
509 if (found[
ridx (i)] == -j)
510 found[
ridx (i)] = -j - 1;
513 if (found[i] > -nc && found[i] < 0)
514 idx_arg.
elem (i) = -found[i];
527 idx_arg.
elem (ir) = j;
533 if (idx_arg.
elem (j) == -1 ||
elem (j, idx_arg.
elem (j)) != 0.)
539 result.
xcidx (0) = 0;
540 result.
xcidx (1) = nel;
543 if (idx_arg(j) == -1)
547 result.
xridx (ii++) = j;
554 result.
xdata (ii) = tmp;
555 result.
xridx (ii++) = j;
590 retval(j) =
data (k);
617 return insert (tmp , r, c);
633 return insert (tmp , indx);
649 if (rb.
rows () > 0 && rb.
cols () > 0)
650 insert (rb, ra_idx(0), ra_idx(1));
659 if (rb.
rows () > 0 && rb.
cols () > 0)
660 insert (tmp, ra_idx(0), ra_idx(1));
685 retval.
xcidx (i) = nz;
694 retval.
xridx (q) = j;
697 assert (
nnz () == retval.
xcidx (nr));
730 return inverse (mattype, info, rcond, 0, 0);
738 return inverse (mattype, info, rcond, 0, 0);
745 return inverse (mattype, info, rcond, 0, 0);
750 double& rcond,
const bool,
751 const bool calccond)
const
759 if (nr == 0 || nc == 0 || nr != nc)
760 (*current_liboctave_error_handler) (
"inverse requires square matrix");
764 int typ = mattyp.
type ();
804 double& rcond,
const bool,
805 const bool calccond)
const
813 if (nr == 0 || nc == 0 || nr != nc)
814 (*current_liboctave_error_handler) (
"inverse requires square matrix");
818 int typ = mattyp.
type ();
825 double ainvnorm = 0.;
859 retval.
xcidx (i) = cx;
860 retval.
xridx (cx) = i;
861 retval.
xdata (cx) = 1.0;
875 (*current_liboctave_error_handler)
876 (
"division by zero");
877 goto inverse_singular;
883 rpX = retval.
xridx (colXp);
892 v -= retval.
xdata (colXp) *
data (colUp);
896 }
while ((rpX<j) && (rpU<j) &&
897 (colXp<cx) && (colUp<nz));
902 colUp =
cidx (j+1) - 1;
906 if (pivot == 0. ||
ridx (colUp) != j)
908 (*current_liboctave_error_handler)
909 (
"division by zero");
910 goto inverse_singular;
921 retval.
xridx (cx) = j;
922 retval.
xdata (cx) = v / pivot;
930 colUp =
cidx (i+1) - 1;
934 if (pivot == 0. ||
ridx (colUp) != i)
936 (*current_liboctave_error_handler) (
"division by zero");
937 goto inverse_singular;
942 retval.
xdata (j) /= pivot;
944 retval.
xcidx (nr) = cx;
989 k <
cidx (jidx+1); k++)
998 pivot =
data (cidx (jidx+1) - 1);
1000 pivot =
data (cidx (jidx));
1003 (*current_liboctave_error_handler)
1004 (
"division by zero");
1005 goto inverse_singular;
1008 work[j] = v / pivot;
1014 colUp =
cidx (perm[iidx]+1) - 1;
1016 colUp =
cidx (perm[iidx]);
1021 (*current_liboctave_error_handler)
1022 (
"division by zero");
1023 goto inverse_singular;
1037 nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2);
1041 retval.
xcidx (i) = cx;
1045 retval.
xridx (cx) = j;
1046 retval.
xdata (cx++) = work[j];
1050 retval.
xcidx (nr) = cx;
1061 i < retval.
cidx (j+1); i++)
1063 if (atmp > ainvnorm)
1067 rcond = 1. / ainvnorm / anorm;
1082 double& rcond,
int,
int calc_cond)
const
1084 int typ = mattype.
type (
false);
1088 typ = mattype.
type (*
this);
1091 ret =
dinverse (mattype, info, rcond,
true, calc_cond);
1105 rcond = fact.
rcond ();
1132 rcond = fact.
rcond ();
1172 if (nr == 0 || nc == 0 || nr != nc)
1181 Matrix Control (UMFPACK_CONTROL, 1);
1187 Control (UMFPACK_PRL) = tmp;
1192 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
1193 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
1199 Control (UMFPACK_FIXQ) = tmp;
1202 Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE;
1211 reinterpret_cast<const double *
> (Ax),
1215 Matrix Info (1, UMFPACK_INFO);
1218 (nr, nc, Ap, Ai,
reinterpret_cast<const double *
> (Ax), 0,
1219 0, &Symbolic, control, info);
1223 (*current_liboctave_error_handler)
1224 (
"SparseComplexMatrix::determinant symbolic factorization failed");
1238 reinterpret_cast<const double *
> (Ax),
1239 0, Symbolic, &Numeric, control, info);
1242 rcond = Info (UMFPACK_RCOND);
1246 (*current_liboctave_error_handler)
1247 (
"SparseComplexMatrix::determinant numeric factorization failed");
1265 (*current_liboctave_error_handler)
1266 (
"SparseComplexMatrix::determinant error calculating determinant");
1279 (*current_liboctave_error_handler) (
"UMFPACK not installed");
1288 solve_singularity_handler,
bool calc_cond)
const
1297 if (nr != b.
rows ())
1299 (
"matrix dimension mismatch solution of linear equations");
1300 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1305 int typ = mattype.
type ();
1315 retval(i,j) = b(i,j) /
data (i);
1320 retval(k,j) = b(
ridx (i),j) /
data (i);
1333 rcond = dmin / dmax;
1348 solve_singularity_handler,
1349 bool calc_cond)
const
1358 if (nr != b.
rows ())
1360 (
"matrix dimension mismatch solution of linear equations");
1361 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1366 int typ = mattype.
type ();
1376 retval.
xcidx (0) = 0;
1383 if (b.
ridx (i) >= nm)
1388 retval.
xcidx (j+1) = ii;
1398 for (k = b.
cidx (j); k < b.
cidx (j+1); k++)
1406 retval.
xridx (ii) = l;
1410 retval.
xcidx (j+1) = ii;
1424 rcond = dmin / dmax;
1439 solve_singularity_handler,
1440 bool calc_cond)
const
1449 if (nr != b.
rows ())
1451 (
"matrix dimension mismatch solution of linear equations");
1452 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1457 int typ = mattype.
type ();
1467 retval(i,j) = b(i,j) /
data (i);
1472 retval(k,j) = b(
ridx (i),j) /
data (i);
1485 rcond = dmin / dmax;
1500 solve_singularity_handler,
1501 bool calc_cond)
const
1510 if (nr != b.
rows ())
1512 (
"matrix dimension mismatch solution of linear equations");
1513 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1518 int typ = mattype.
type ();
1528 retval.
xcidx (0) = 0;
1535 if (b.
ridx (i) >= nm)
1540 retval.
xcidx (j+1) = ii;
1550 for (k = b.
cidx (j); k < b.
cidx (j+1); k++)
1558 retval.
xridx (ii) = l;
1562 retval.
xcidx (j+1) = ii;
1576 rcond = dmin / dmax;
1591 solve_singularity_handler sing_handler,
1592 bool calc_cond)
const
1601 if (nr != b.
rows ())
1603 (
"matrix dimension mismatch solution of linear equations");
1604 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1609 int typ = mattype.
type ();
1616 double ainvnorm = 0.;
1635 retval.
resize (nc, b_nc);
1656 goto triangular_error;
1662 i <
cidx (kidx+1)-1; i++)
1665 work[iidx] = work[iidx] - tmp *
data (i);
1671 retval(perm[i], j) = work[i];
1693 i <
cidx (iidx+1)-1; i++)
1696 work[idx2] = work[idx2] - tmp *
data (i);
1706 if (atmp > ainvnorm)
1709 rcond = 1. / ainvnorm / anorm;
1715 retval.
resize (nc, b_nc);
1732 goto triangular_error;
1740 work[iidx] = work[iidx] - tmp *
data (i);
1746 retval.
xelem (i, j) = work[i];
1766 i <
cidx (k+1)-1; i++)
1769 work[iidx] = work[iidx] - tmp *
data (i);
1779 if (atmp > ainvnorm)
1782 rcond = 1. / ainvnorm / anorm;
1791 sing_handler (rcond);
1796 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
1800 volatile double rcond_plus_one = rcond + 1.0;
1802 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
1808 sing_handler (rcond);
1813 (
"matrix singular to machine precision, rcond = %g",
1827 solve_singularity_handler sing_handler,
1828 bool calc_cond)
const
1837 if (nr != b.
rows ())
1839 (
"matrix dimension mismatch solution of linear equations");
1840 else if (nr == 0 || nc == 0 || b.
cols () == 0)
1845 int typ = mattype.
type ();
1852 double ainvnorm = 0.;
1871 retval.
xcidx (0) = 0;
1901 goto triangular_error;
1907 i <
cidx (kidx+1)-1; i++)
1910 work[iidx] = work[iidx] - tmp *
data (i);
1922 if (ii + new_nnz > x_nz)
1931 if (work[rperm[i]] != 0.)
1933 retval.
xridx (ii) = i;
1934 retval.
xdata (ii++) = work[rperm[i]];
1936 retval.
xcidx (j+1) = ii;
1960 i <
cidx (iidx+1)-1; i++)
1963 work[idx2] = work[idx2] - tmp *
data (i);
1973 if (atmp > ainvnorm)
1976 rcond = 1. / ainvnorm / anorm;
1998 goto triangular_error;
2006 work[iidx] = work[iidx] - tmp *
data (i);
2018 if (ii + new_nnz > x_nz)
2029 retval.
xridx (ii) = i;
2030 retval.
xdata (ii++) = work[i];
2032 retval.
xcidx (j+1) = ii;
2054 i <
cidx (k+1)-1; i++)
2057 work[iidx] = work[iidx] - tmp *
data (i);
2067 if (atmp > ainvnorm)
2070 rcond = 1. / ainvnorm / anorm;
2079 sing_handler (rcond);
2084 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
2088 volatile double rcond_plus_one = rcond + 1.0;
2090 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2096 sing_handler (rcond);
2101 (
"matrix singular to machine precision, rcond = %g",
2114 solve_singularity_handler sing_handler,
2115 bool calc_cond)
const
2124 if (nr != b.
rows ())
2126 (
"matrix dimension mismatch solution of linear equations");
2127 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2132 int typ = mattype.
type ();
2139 double ainvnorm = 0.;
2158 retval.
resize (nc, b_nc);
2179 goto triangular_error;
2185 i <
cidx (kidx+1)-1; i++)
2188 work[iidx] = work[iidx] - tmp *
data (i);
2194 retval(perm[i], j) = work[i];
2216 i <
cidx (iidx+1)-1; i++)
2219 work[idx2] = work[idx2] - tmp *
data (i);
2229 if (atmp > ainvnorm)
2232 rcond = 1. / ainvnorm / anorm;
2238 retval.
resize (nc, b_nc);
2255 goto triangular_error;
2263 work[iidx] = work[iidx] - tmp *
data (i);
2269 retval.
xelem (i, j) = work[i];
2289 i <
cidx (k+1)-1; i++)
2292 work[iidx] = work[iidx] - tmp *
data (i);
2302 if (atmp > ainvnorm)
2305 rcond = 1. / ainvnorm / anorm;
2314 sing_handler (rcond);
2319 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
2323 volatile double rcond_plus_one = rcond + 1.0;
2325 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2331 sing_handler (rcond);
2336 (
"matrix singular to machine precision, rcond = %g",
2350 solve_singularity_handler sing_handler,
2351 bool calc_cond)
const
2360 if (nr != b.
rows ())
2362 (
"matrix dimension mismatch solution of linear equations");
2363 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2368 int typ = mattype.
type ();
2375 double ainvnorm = 0.;
2394 retval.
xcidx (0) = 0;
2424 goto triangular_error;
2430 i <
cidx (kidx+1)-1; i++)
2433 work[iidx] = work[iidx] - tmp *
data (i);
2445 if (ii + new_nnz > x_nz)
2454 if (work[rperm[i]] != 0.)
2456 retval.
xridx (ii) = i;
2457 retval.
xdata (ii++) = work[rperm[i]];
2459 retval.
xcidx (j+1) = ii;
2483 i <
cidx (iidx+1)-1; i++)
2486 work[idx2] = work[idx2] - tmp *
data (i);
2496 if (atmp > ainvnorm)
2499 rcond = 1. / ainvnorm / anorm;
2521 goto triangular_error;
2529 work[iidx] = work[iidx] - tmp *
data (i);
2541 if (ii + new_nnz > x_nz)
2552 retval.
xridx (ii) = i;
2553 retval.
xdata (ii++) = work[i];
2555 retval.
xcidx (j+1) = ii;
2577 i <
cidx (k+1)-1; i++)
2580 work[iidx] = work[iidx] - tmp *
data (i);
2590 if (atmp > ainvnorm)
2593 rcond = 1. / ainvnorm / anorm;
2602 sing_handler (rcond);
2607 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
2611 volatile double rcond_plus_one = rcond + 1.0;
2613 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2619 sing_handler (rcond);
2624 (
"matrix singular to machine precision, rcond = %g",
2638 solve_singularity_handler sing_handler,
2639 bool calc_cond)
const
2648 if (nr != b.
rows ())
2650 (
"matrix dimension mismatch solution of linear equations");
2651 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2656 int typ = mattype.
type ();
2663 double ainvnorm = 0.;
2682 retval.
resize (nc, b_nc);
2691 work[perm[i]] = b(i,j);
2701 if (perm[
ridx (i)] < minr)
2703 minr = perm[
ridx (i)];
2707 if (minr != k ||
data (mini) == 0.)
2710 goto triangular_error;
2721 work[iidx] = work[iidx] - tmp *
data (i);
2727 retval(i, j) = work[i];
2748 i <
cidx (k+1); i++)
2749 if (perm[
ridx (i)] < minr)
2751 minr = perm[
ridx (i)];
2758 i <
cidx (k+1); i++)
2764 work[iidx] = work[iidx] - tmp *
data (i);
2775 if (atmp > ainvnorm)
2778 rcond = 1. / ainvnorm / anorm;
2784 retval.
resize (nc, b_nc, 0.);
2800 goto triangular_error;
2808 work[iidx] = work[iidx] - tmp *
data (i);
2813 retval.
xelem (i, j) = work[i];
2834 i <
cidx (k+1); i++)
2837 work[iidx] = work[iidx] - tmp *
data (i);
2847 if (atmp > ainvnorm)
2850 rcond = 1. / ainvnorm / anorm;
2858 sing_handler (rcond);
2863 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
2867 volatile double rcond_plus_one = rcond + 1.0;
2869 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
2875 sing_handler (rcond);
2880 (
"matrix singular to machine precision, rcond = %g",
2894 solve_singularity_handler sing_handler,
2895 bool calc_cond)
const
2905 if (nr != b.
rows ())
2907 (
"matrix dimension mismatch solution of linear equations");
2908 else if (nr == 0 || nc == 0 || b.
cols () == 0)
2913 int typ = mattype.
type ();
2920 double ainvnorm = 0.;
2939 retval.
xcidx (0) = 0;
2953 work[perm[b.
ridx (i)]] = b.
data (i);
2963 if (perm[
ridx (i)] < minr)
2965 minr = perm[
ridx (i)];
2969 if (minr != k ||
data (mini) == 0.)
2972 goto triangular_error;
2983 work[iidx] = work[iidx] - tmp *
data (i);
2995 if (ii + new_nnz > x_nz)
3006 retval.
xridx (ii) = i;
3007 retval.
xdata (ii++) = work[i];
3009 retval.
xcidx (j+1) = ii;
3032 i <
cidx (k+1); i++)
3033 if (perm[
ridx (i)] < minr)
3035 minr = perm[
ridx (i)];
3042 i <
cidx (k+1); i++)
3048 work[iidx] = work[iidx] - tmp *
data (i);
3059 if (atmp > ainvnorm)
3062 rcond = 1. / ainvnorm / anorm;
3084 goto triangular_error;
3092 work[iidx] = work[iidx] - tmp *
data (i);
3104 if (ii + new_nnz > x_nz)
3115 retval.
xridx (ii) = i;
3116 retval.
xdata (ii++) = work[i];
3118 retval.
xcidx (j+1) = ii;
3141 i <
cidx (k+1); i++)
3144 work[iidx] = work[iidx] - tmp *
data (i);
3154 if (atmp > ainvnorm)
3157 rcond = 1. / ainvnorm / anorm;
3166 sing_handler (rcond);
3171 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
3175 volatile double rcond_plus_one = rcond + 1.0;
3177 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3183 sing_handler (rcond);
3188 (
"matrix singular to machine precision, rcond = %g",
3202 solve_singularity_handler sing_handler,
3203 bool calc_cond)
const
3212 if (nr != b.
rows ())
3214 (
"matrix dimension mismatch solution of linear equations");
3215 else if (nr == 0 || nc == 0 || b.
cols () == 0)
3220 int typ = mattype.
type ();
3227 double ainvnorm = 0.;
3246 retval.
resize (nc, b_nc);
3255 work[perm[i]] = b(i,j);
3265 if (perm[
ridx (i)] < minr)
3267 minr = perm[
ridx (i)];
3271 if (minr != k ||
data (mini) == 0.)
3274 goto triangular_error;
3285 work[iidx] = work[iidx] - tmp *
data (i);
3291 retval(i, j) = work[i];
3312 i <
cidx (k+1); i++)
3313 if (perm[
ridx (i)] < minr)
3315 minr = perm[
ridx (i)];
3322 i <
cidx (k+1); i++)
3328 work[iidx] = work[iidx] - tmp *
data (i);
3339 if (atmp > ainvnorm)
3342 rcond = 1. / ainvnorm / anorm;
3348 retval.
resize (nc, b_nc, 0.);
3366 goto triangular_error;
3374 work[iidx] = work[iidx] - tmp *
data (i);
3380 retval.
xelem (i, j) = work[i];
3401 i <
cidx (k+1); i++)
3404 work[iidx] = work[iidx] - tmp *
data (i);
3414 if (atmp > ainvnorm)
3417 rcond = 1. / ainvnorm / anorm;
3426 sing_handler (rcond);
3431 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
3435 volatile double rcond_plus_one = rcond + 1.0;
3437 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3443 sing_handler (rcond);
3448 (
"matrix singular to machine precision, rcond = %g",
3462 solve_singularity_handler sing_handler,
3463 bool calc_cond)
const
3472 if (nr != b.
rows ())
3474 (
"matrix dimension mismatch solution of linear equations");
3475 else if (nr == 0 || nc == 0 || b.
cols () == 0)
3480 int typ = mattype.
type ();
3487 double ainvnorm = 0.;
3506 retval.
xcidx (0) = 0;
3520 work[perm[b.
ridx (i)]] = b.
data (i);
3530 if (perm[
ridx (i)] < minr)
3532 minr = perm[
ridx (i)];
3536 if (minr != k ||
data (mini) == 0.)
3539 goto triangular_error;
3550 work[iidx] = work[iidx] - tmp *
data (i);
3562 if (ii + new_nnz > x_nz)
3573 retval.
xridx (ii) = i;
3574 retval.
xdata (ii++) = work[i];
3576 retval.
xcidx (j+1) = ii;
3599 i <
cidx (k+1); i++)
3600 if (perm[
ridx (i)] < minr)
3602 minr = perm[
ridx (i)];
3609 i <
cidx (k+1); i++)
3615 work[iidx] = work[iidx] - tmp *
data (i);
3626 if (atmp > ainvnorm)
3629 rcond = 1. / ainvnorm / anorm;
3651 goto triangular_error;
3659 work[iidx] = work[iidx] - tmp *
data (i);
3671 if (ii + new_nnz > x_nz)
3682 retval.
xridx (ii) = i;
3683 retval.
xdata (ii++) = work[i];
3685 retval.
xcidx (j+1) = ii;
3708 i <
cidx (k+1); i++)
3711 work[iidx] = work[iidx] - tmp *
data (i);
3721 if (atmp > ainvnorm)
3724 rcond = 1. / ainvnorm / anorm;
3733 sing_handler (rcond);
3738 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
3742 volatile double rcond_plus_one = rcond + 1.0;
3744 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
3750 sing_handler (rcond);
3755 (
"matrix singular to machine precision, rcond = %g",
3769 solve_singularity_handler sing_handler,
3770 bool calc_cond)
const
3778 if (nr != nc || nr != b.
rows ())
3780 (
"matrix dimension mismatch solution of linear equations");
3781 else if (nr == 0 || b.
cols () == 0)
3784 (*current_liboctave_error_handler)
3785 (
"calculation of condition number not implemented");
3789 volatile int typ = mattype.
type ();
3823 else if (
ridx (i) == j + 1)
3832 F77_XFCN (zptsv, ZPTSV, (nr, b_nc, D, DL, result,
3858 DL[j] =
data (ii++);
3859 DU[j] =
data (ii++);
3861 D[nc-1] =
data (ii);
3878 else if (
ridx (i) == j + 1)
3880 else if (
ridx (i) == j - 1)
3889 F77_XFCN (zgtsv, ZGTSV, (nr, b_nc, DL, D, DU, result,
3899 sing_handler (rcond);
3904 (
"matrix singular to machine precision");
3911 (*current_liboctave_error_handler) (
"incorrect matrix type");
3920 solve_singularity_handler sing_handler,
3921 bool calc_cond)
const
3929 if (nr != nc || nr != b.
rows ())
3931 (
"matrix dimension mismatch solution of linear equations");
3932 else if (nr == 0 || b.
cols () == 0)
3935 (*current_liboctave_error_handler)
3936 (
"calculation of condition number not implemented");
3940 int typ = mattype.
type ();
3961 DL[j] =
data (ii++);
3962 DU[j] =
data (ii++);
3964 D[nc-1] =
data (ii);
3981 else if (
ridx (i) == j + 1)
3983 else if (
ridx (i) == j - 1)
3988 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
3997 sing_handler (rcond);
4002 (
"matrix singular to machine precision");
4011 retval.
xcidx (0) = 0;
4026 nr, 1, DL, D, DU, DU2, pipvt,
4027 work, b.
rows (), err
4037 if (ii + new_nnz > x_nz)
4048 retval.
xridx (ii) = i;
4049 retval.
xdata (ii++) = work[i];
4051 retval.
xcidx (j+1) = ii;
4058 (*current_liboctave_error_handler) (
"incorrect matrix type");
4067 solve_singularity_handler sing_handler,
4068 bool calc_cond)
const
4076 if (nr != nc || nr != b.
rows ())
4078 (
"matrix dimension mismatch solution of linear equations");
4079 else if (nr == 0 || b.
cols () == 0)
4082 (*current_liboctave_error_handler)
4083 (
"calculation of condition number not implemented");
4087 volatile int typ = mattype.
type ();
4121 else if (
ridx (i) == j + 1)
4133 F77_XFCN (zptsv, ZPTSV, (nr, b_nc, D, DL, result,
4157 DL[j] =
data (ii++);
4158 DU[j] =
data (ii++);
4160 D[nc-1] =
data (ii);
4177 else if (
ridx (i) == j + 1)
4179 else if (
ridx (i) == j - 1)
4191 F77_XFCN (zgtsv, ZGTSV, (nr, b_nc, DL, D, DU, result,
4201 sing_handler (rcond);
4206 (
"matrix singular to machine precision");
4210 (*current_liboctave_error_handler) (
"incorrect matrix type");
4220 solve_singularity_handler sing_handler,
4221 bool calc_cond)
const
4229 if (nr != nc || nr != b.
rows ())
4231 (
"matrix dimension mismatch solution of linear equations");
4232 else if (nr == 0 || b.
cols () == 0)
4235 (*current_liboctave_error_handler)
4236 (
"calculation of condition number not implemented");
4240 int typ = mattype.
type ();
4261 DL[j] =
data (ii++);
4262 DU[j] =
data (ii++);
4264 D[nc-1] =
data (ii);
4281 else if (
ridx (i) == j + 1)
4283 else if (
ridx (i) == j - 1)
4288 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
4297 sing_handler (rcond);
4302 (
"matrix singular to machine precision");
4318 retval.
xcidx (0) = 0;
4327 nr, 1, DL, D, DU, DU2, pipvt,
4333 (*current_liboctave_error_handler)
4334 (
"SparseComplexMatrix::solve solve failed");
4347 if (ii + new_nnz > x_nz)
4358 retval.
xridx (ii) = i;
4359 retval.
xdata (ii++) = Bx[i];
4362 retval.
xcidx (j+1) = ii;
4369 (*current_liboctave_error_handler) (
"incorrect matrix type");
4378 solve_singularity_handler sing_handler,
4379 bool calc_cond)
const
4387 if (nr != nc || nr != b.
rows ())
4389 (
"matrix dimension mismatch solution of linear equations");
4390 else if (nr == 0 || b.
cols () == 0)
4395 volatile int typ = mattype.
type ();
4411 tmp_data[ii++] = 0.;
4419 m_band(ri - j, j) =
data (i);
4429 nr, n_lower, tmp_data, ldm, err
4452 nr, n_lower, tmp_data, ldm,
4453 anorm, rcond, pz, piz, err
4459 volatile double rcond_plus_one = rcond + 1.0;
4461 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4467 sing_handler (rcond);
4472 (
"matrix singular to machine precision, rcond = %g",
4488 nr, n_lower, b_nc, tmp_data,
4489 ldm, result, b.
rows (), err
4494 (*current_liboctave_error_handler)
4495 (
"SparseMatrix::solve solve failed");
4518 tmp_data[ii++] = 0.;
4523 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
4542 F77_XFCN (zgbtrf, ZGBTRF, (nr, nc, n_lower, n_upper, tmp_data,
4554 sing_handler (rcond);
4559 (
"matrix singular to machine precision");
4573 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
4574 anorm, rcond, pz, piz, err
4580 volatile double rcond_plus_one = rcond + 1.0;
4582 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4588 sing_handler (rcond);
4593 (
"matrix singular to machine precision, rcond = %g",
4610 nr, n_lower, n_upper, b_nc, tmp_data,
4611 ldm, pipvt, result, b.
rows (), err
4617 (*current_liboctave_error_handler) (
"incorrect matrix type");
4626 solve_singularity_handler sing_handler,
4627 bool calc_cond)
const
4635 if (nr != nc || nr != b.
rows ())
4637 (
"matrix dimension mismatch solution of linear equations");
4638 else if (nr == 0 || b.
cols () == 0)
4643 volatile int typ = mattype.
type ();
4660 tmp_data[ii++] = 0.;
4668 m_band(ri - j, j) =
data (i);
4678 nr, n_lower, tmp_data, ldm, err
4699 nr, n_lower, tmp_data, ldm,
4700 anorm, rcond, pz, piz, err
4706 volatile double rcond_plus_one = rcond + 1.0;
4708 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4714 sing_handler (rcond);
4719 (
"matrix singular to machine precision, rcond = %g",
4738 retval.
xcidx (0) = 0;
4742 Bx[i] = b.
elem (i, j);
4746 nr, n_lower, 1, tmp_data,
4752 (*current_liboctave_error_handler)
4753 (
"SparseComplexMatrix::solve solve failed");
4768 sz = (sz > 10 ? sz : 10) + x_nz;
4772 retval.
xdata (ii) = tmp;
4773 retval.
xridx (ii++) = i;
4776 retval.
xcidx (j+1) = ii;
4800 tmp_data[ii++] = 0.;
4805 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
4824 F77_XFCN (zgbtrf, ZGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
4834 sing_handler (rcond);
4839 (
"matrix singular to machine precision");
4854 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
4855 anorm, rcond, pz, piz, err
4861 volatile double rcond_plus_one = rcond + 1.0;
4863 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
4869 sing_handler (rcond);
4874 (
"matrix singular to machine precision, rcond = %g",
4887 retval.
xcidx (0) = 0;
4897 i < b.
cidx (j+1); i++)
4902 nr, n_lower, n_upper, 1, tmp_data,
4903 ldm, pipvt, work, b.
rows (), err
4913 if (ii + new_nnz > x_nz)
4924 retval.
xridx (ii) = i;
4925 retval.
xdata (ii++) = work[i];
4927 retval.
xcidx (j+1) = ii;
4935 (*current_liboctave_error_handler) (
"incorrect matrix type");
4944 solve_singularity_handler sing_handler,
4945 bool calc_cond)
const
4953 if (nr != nc || nr != b.
rows ())
4955 (
"matrix dimension mismatch solution of linear equations");
4956 else if (nr == 0 || b.
cols () == 0)
4961 volatile int typ = mattype.
type ();
4978 tmp_data[ii++] = 0.;
4986 m_band(ri - j, j) =
data (i);
4996 nr, n_lower, tmp_data, ldm, err
5019 nr, n_lower, tmp_data, ldm,
5020 anorm, rcond, pz, piz, err
5026 volatile double rcond_plus_one = rcond + 1.0;
5028 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5034 sing_handler (rcond);
5039 (
"matrix singular to machine precision, rcond = %g",
5055 nr, n_lower, b_nc, tmp_data,
5056 ldm, result, b_nr, err
5061 (*current_liboctave_error_handler)
5062 (
"SparseComplexMatrix::solve solve failed");
5085 tmp_data[ii++] = 0.;
5090 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
5109 F77_XFCN (zgbtrf, ZGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
5119 sing_handler (rcond);
5124 (
"matrix singular to machine precision");
5138 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
5139 anorm, rcond, pz, piz, err
5145 volatile double rcond_plus_one = rcond + 1.0;
5147 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5153 sing_handler (rcond);
5158 (
"matrix singular to machine precision, rcond = %g",
5174 nr, n_lower, n_upper, b_nc, tmp_data,
5175 ldm, pipvt, result, b.
rows (), err
5181 (*current_liboctave_error_handler) (
"incorrect matrix type");
5190 solve_singularity_handler sing_handler,
5191 bool calc_cond)
const
5199 if (nr != nc || nr != b.
rows ())
5201 (
"matrix dimension mismatch solution of linear equations");
5202 else if (nr == 0 || b.
cols () == 0)
5207 volatile int typ = mattype.
type ();
5224 tmp_data[ii++] = 0.;
5232 m_band(ri - j, j) =
data (i);
5242 nr, n_lower, tmp_data, ldm, err
5266 nr, n_lower, tmp_data, ldm,
5267 anorm, rcond, pz, piz, err
5273 volatile double rcond_plus_one = rcond + 1.0;
5275 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5281 sing_handler (rcond);
5286 (
"matrix singular to machine precision, rcond = %g",
5305 retval.
xcidx (0) = 0;
5314 nr, n_lower, 1, tmp_data,
5320 (*current_liboctave_error_handler)
5321 (
"SparseMatrix::solve solve failed");
5333 if (ii + new_nnz > x_nz)
5344 retval.
xridx (ii) = i;
5345 retval.
xdata (ii++) = Bx[i];
5348 retval.
xcidx (j+1) = ii;
5372 tmp_data[ii++] = 0.;
5377 m_band(
ridx (i) - j + n_lower + n_upper, j) =
data (i);
5396 F77_XFCN (zgbtrf, ZGBTRF, (nr, nr, n_lower, n_upper, tmp_data,
5406 sing_handler (rcond);
5411 (
"matrix singular to machine precision");
5426 nc, n_lower, n_upper, tmp_data, ldm, pipvt,
5427 anorm, rcond, pz, piz, err
5433 volatile double rcond_plus_one = rcond + 1.0;
5435 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5441 sing_handler (rcond);
5446 (
"matrix singular to machine precision, rcond = %g",
5459 retval.
xcidx (0) = 0;
5470 i < b.
cidx (j+1); i++)
5475 nr, n_lower, n_upper, 1, tmp_data,
5476 ldm, pipvt, Bx, b.
rows (), err
5486 if (ii + new_nnz > x_nz)
5497 retval.
xridx (ii) = i;
5498 retval.
xdata (ii++) = Bx[i];
5500 retval.
xcidx (j+1) = ii;
5508 (*current_liboctave_error_handler) (
"incorrect matrix type");
5517 solve_singularity_handler sing_handler,
5518 bool calc_cond)
const
5526 Control =
Matrix (UMFPACK_CONTROL, 1);
5532 Control (UMFPACK_PRL) = tmp;
5536 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
5537 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
5543 Control (UMFPACK_FIXQ) = tmp;
5554 reinterpret_cast<const double *
> (Ax),
5558 Info =
Matrix (1, UMFPACK_INFO);
5561 reinterpret_cast<const double *
> (Ax),
5562 0, 0, &Symbolic, control, info);
5566 (*current_liboctave_error_handler)
5567 (
"SparseComplexMatrix::solve symbolic factorization failed");
5580 reinterpret_cast<const double *
> (Ax),
5581 0, Symbolic, &Numeric, control, info);
5585 rcond = Info (UMFPACK_RCOND);
5588 volatile double rcond_plus_one = rcond + 1.0;
5590 if (status == UMFPACK_WARNING_singular_matrix ||
5591 rcond_plus_one == 1.0 ||
xisnan (rcond))
5598 sing_handler (rcond);
5601 (
"SparseComplexMatrix::solve matrix singular to machine precision, rcond = %g",
5605 else if (status < 0)
5607 (*current_liboctave_error_handler)
5608 (
"SparseComplexMatrix::solve numeric factorization failed");
5624 (*current_liboctave_error_handler) (
"UMFPACK not installed");
5633 solve_singularity_handler sing_handler,
5634 bool calc_cond)
const
5642 if (nr != nc || nr != b.
rows ())
5644 (
"matrix dimension mismatch solution of linear equations");
5645 else if (nr == 0 || b.
cols () == 0)
5650 volatile int typ = mattype.
type ();
5656 cholmod_common Common;
5657 cholmod_common *cm = &Common;
5660 CHOLMOD_NAME(start) (cm);
5661 cm->prefer_zomplex =
false;
5667 cm->print_function = 0;
5671 cm->print =
static_cast<int> (spu) + 2;
5676 cm->complex_divide = CHOLMOD_NAME(divcomplex);
5677 cm->hypotenuse = CHOLMOD_NAME(hypot);
5679 cm->final_ll =
true;
5681 cholmod_sparse Astore;
5682 cholmod_sparse *
A = &Astore;
5693 #ifdef USE_64_BIT_IDX_T
5694 A->itype = CHOLMOD_LONG;
5696 A->itype = CHOLMOD_INT;
5698 A->dtype = CHOLMOD_DOUBLE;
5700 A->xtype = CHOLMOD_COMPLEX;
5707 cholmod_dense Bstore;
5708 cholmod_dense *
B = &Bstore;
5709 B->nrow = b.
rows ();
5710 B->ncol = b.
cols ();
5712 B->nzmax = B->nrow * B->ncol;
5713 B->dtype = CHOLMOD_DOUBLE;
5714 B->xtype = CHOLMOD_REAL;
5715 if (nc < 1 || b.
cols () < 1)
5723 L = CHOLMOD_NAME(analyze) (
A, cm);
5726 rcond = CHOLMOD_NAME(rcond)(L, cm);
5739 volatile double rcond_plus_one = rcond + 1.0;
5741 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
5747 sing_handler (rcond);
5752 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
5760 X = CHOLMOD_NAME(
solve) (CHOLMOD_A, L,
B, cm);
5768 retval.
xelem (i,j) =
static_cast<Complex *
>(X->x)[jr + i];
5772 CHOLMOD_NAME(free_dense) (&X, cm);
5773 CHOLMOD_NAME(free_factor) (&L, cm);
5774 CHOLMOD_NAME(finish) (cm);
5775 static char tmp[] =
" ";
5776 CHOLMOD_NAME(print_common) (tmp, cm);
5780 (*current_liboctave_warning_handler)
5781 (
"CHOLMOD not installed");
5792 void *Numeric =
factorize (err, rcond, Control, Info,
5793 sing_handler, calc_cond);
5805 #ifdef UMFPACK_SEPARATE_SPLIT
5813 retval.
resize (b_nr, b_nc);
5818 #ifdef UMFPACK_SEPARATE_SPLIT
5821 reinterpret_cast<const double *
> (Ax),
5823 reinterpret_cast<double *> (&Xx[iidx]),
5825 &Bx[iidx], Bz, Numeric,
5829 Bz[i] = b.
elem (i, j);
5833 reinterpret_cast<const double *
> (Ax),
5835 reinterpret_cast<double *> (&Xx[iidx]),
5837 reinterpret_cast<const double *
> (Bz),
5844 (*current_liboctave_error_handler)
5845 (
"SparseComplexMatrix::solve solve failed");
5863 (*current_liboctave_error_handler) (
"UMFPACK not installed");
5867 (*current_liboctave_error_handler) (
"incorrect matrix type");
5876 solve_singularity_handler sing_handler,
5877 bool calc_cond)
const
5885 if (nr != nc || nr != b.
rows ())
5887 (
"matrix dimension mismatch solution of linear equations");
5888 else if (nr == 0 || b.
cols () == 0)
5893 volatile int typ = mattype.
type ();
5899 cholmod_common Common;
5900 cholmod_common *cm = &Common;
5903 CHOLMOD_NAME(start) (cm);
5904 cm->prefer_zomplex =
false;
5910 cm->print_function = 0;
5914 cm->print =
static_cast<int> (spu) + 2;
5919 cm->complex_divide = CHOLMOD_NAME(divcomplex);
5920 cm->hypotenuse = CHOLMOD_NAME(hypot);
5922 cm->final_ll =
true;
5924 cholmod_sparse Astore;
5925 cholmod_sparse *
A = &Astore;
5936 #ifdef USE_64_BIT_IDX_T
5937 A->itype = CHOLMOD_LONG;
5939 A->itype = CHOLMOD_INT;
5941 A->dtype = CHOLMOD_DOUBLE;
5943 A->xtype = CHOLMOD_COMPLEX;
5950 cholmod_sparse Bstore;
5951 cholmod_sparse *
B = &Bstore;
5952 B->nrow = b.
rows ();
5953 B->ncol = b.
cols ();
5956 B->nzmax = b.
nnz ();
5960 #ifdef USE_64_BIT_IDX_T
5961 B->itype = CHOLMOD_LONG;
5963 B->itype = CHOLMOD_INT;
5965 B->dtype = CHOLMOD_DOUBLE;
5967 B->xtype = CHOLMOD_REAL;
5969 if (b.
rows () < 1 || b.
cols () < 1)
5976 L = CHOLMOD_NAME(analyze) (
A, cm);
5979 rcond = CHOLMOD_NAME(rcond)(L, cm);
5992 volatile double rcond_plus_one = rcond + 1.0;
5994 if (rcond_plus_one == 1.0 ||
xisnan (rcond))
6000 sing_handler (rcond);
6005 (
"SparseMatrix::solve matrix singular to machine precision, rcond = %g",
6013 X = CHOLMOD_NAME(spsolve) (CHOLMOD_A, L,
B, cm);