26#if defined (HAVE_CONFIG_H)
67static const Complex Complex_NaN_result (octave::numeric_limits<double>::NaN (),
68 octave::numeric_limits<double>::NaN ());
145 elem (i, j) =
static_cast<unsigned char> (a.
elem (i, j));
152 (*current_liboctave_error_handler) (
"complex: internal error");
171 return !(*
this == a);
201 if (r < 0 || r + a_nr >
rows () || c < 0 || c + a_nc >
cols ())
202 (*current_liboctave_error_handler) (
"range error for insert");
204 if (a_nr >0 && a_nc > 0)
221 if (r < 0 || r >=
rows () || c < 0 || c + a_len >
cols ())
222 (*current_liboctave_error_handler) (
"range error for insert");
241 if (r < 0 || r + a_len >
rows () || c < 0 || c >=
cols ())
242 (*current_liboctave_error_handler) (
"range error for insert");
262 if (r < 0 || r + a_nr >
rows () || c < 0 || c + a_nc >
cols ())
263 (*current_liboctave_error_handler) (
"range error for insert");
265 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1);
293 if (r < 0 || r >=
rows () || c < 0 || c + a_len >
cols ())
294 (*current_liboctave_error_handler) (
"range error for insert");
308 if (r < 0 || r + a_len >
rows () || c < 0 || c >=
cols ())
309 (*current_liboctave_error_handler) (
"range error for insert");
329 if (r < 0 || r + a_nr >
rows () || c < 0 || c + a_nc >
cols ())
330 (*current_liboctave_error_handler) (
"range error for insert");
332 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1);
353 if (nr > 0 && nc > 0)
371 if (nr > 0 && nc > 0)
390 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0
391 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc)
392 (*current_liboctave_error_handler) (
"range error for fill");
394 if (r1 > r2) { std::swap (r1, r2); }
395 if (c1 > c2) { std::swap (c1, c2); }
397 if (r2 >= r1 && c2 >= c1)
416 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0
417 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc)
418 (*current_liboctave_error_handler) (
"range error for fill");
420 if (r1 > r2) { std::swap (r1, r2); }
421 if (c1 > c2) { std::swap (c1, c2); }
423 if (r2 >= r1 && c2 >=c1)
441 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
445 retval.
insert (*
this, 0, 0);
446 retval.
insert (a, 0, nc_insert);
456 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
460 retval.
insert (*
this, 0, 0);
461 retval.
insert (a, 0, nc_insert);
470 if (nr != a.
numel ())
471 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
475 retval.
insert (*
this, 0, 0);
476 retval.
insert (a, 0, nc_insert);
486 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
490 retval.
insert (*
this, 0, 0);
491 retval.
insert (a, 0, nc_insert);
501 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
505 retval.
insert (*
this, 0, 0);
506 retval.
insert (a, 0, nc_insert);
516 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
520 retval.
insert (*
this, 0, 0);
521 retval.
insert (a, 0, nc_insert);
530 if (nr != a.
numel ())
531 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
535 retval.
insert (*
this, 0, 0);
536 retval.
insert (a, 0, nc_insert);
546 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
550 retval.
insert (*
this, 0, 0);
551 retval.
insert (a, 0, nc_insert);
561 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
565 retval.
insert (*
this, 0, 0);
566 retval.
insert (a, nr_insert, 0);
575 if (nc != a.
numel ())
576 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
580 retval.
insert (*
this, 0, 0);
581 retval.
insert (a, nr_insert, 0);
591 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
595 retval.
insert (*
this, 0, 0);
596 retval.
insert (a, nr_insert, 0);
606 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
610 retval.
insert (*
this, 0, 0);
611 retval.
insert (a, nr_insert, 0);
621 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
625 retval.
insert (*
this, 0, 0);
626 retval.
insert (a, nr_insert, 0);
635 if (nc != a.
numel ())
636 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
640 retval.
insert (*
this, 0, 0);
641 retval.
insert (a, nr_insert, 0);
651 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
655 retval.
insert (*
this, 0, 0);
656 retval.
insert (a, nr_insert, 0);
666 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
670 retval.
insert (*
this, 0, 0);
671 retval.
insert (a, nr_insert, 0);
678 return do_mx_unary_map<Complex, Complex, std::conj<double>> (a);
687 if (r1 > r2) { std::swap (r1, r2); }
688 if (c1 > c2) { std::swap (c1, c2); }
690 return index (octave::idx_vector (r1, r2+1), octave::idx_vector (c1, c2+1));
697 return index (octave::idx_vector (r1, r1 + nr), octave::idx_vector (c1, c1 + nc));
705 return index (octave::idx_vector (i), octave::idx_vector::colon);
711 return index (octave::idx_vector::colon, octave::idx_vector (i));
724 double sum = colsum.
xelem (i);
725 if (octave::math::isinf (sum) || octave::math::isnan (sum))
731 anorm = std::max (anorm, sum);
740is_singular (
const double rcond)
742 return (std::abs (rcond) <= std::numeric_limits<double>::epsilon ());
751 return inverse (mattype, info, rcon,
false,
false);
759 return inverse (mattype, info, rcon,
false,
false);
764 bool calc_cond)
const
767 return inverse (mattype, info, rcon, force, calc_cond);
775 return inverse (mattype, info, rcon,
false,
false);
782 return inverse (mattype, info, rcon,
false,
false);
787 double& rcon,
bool force,
bool calc_cond)
const
794 if (nr != nc || nr == 0 || nc == 0)
795 (*current_liboctave_error_handler) (
"inverse requires square matrix");
797 int typ = mattype.
type ();
805 F77_XFCN (ztrtri, ZTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1),
806 F77_CONST_CHAR_ARG2 (&udiag, 1),
809 F77_CHAR_ARG_LEN (1)));
825 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&job, 1),
826 F77_CONST_CHAR_ARG2 (&uplo, 1),
827 F77_CONST_CHAR_ARG2 (&udiag, 1),
832 F77_CHAR_ARG_LEN (1)));
834 if (ztrcon_info != 0)
838 if (info == -1 && ! force)
846 double& rcon,
bool force,
bool calc_cond)
const
854 (*current_liboctave_error_handler) (
"inverse requires square matrix");
857 F77_INT *pipvt = ipvt.rwdata ();
873 lwork =
static_cast<F77_INT> (std::real (z(0)));
874 lwork = (lwork < 2 * nc ? 2 * nc : lwork);
882 double anorm = norm1 (retval);
886 if (octave::math::isnan (anorm) || octave::math::isinf (anorm))
902 if (octave::math::isnan (anorm))
903 rcon = octave::numeric_limits<double>::NaN ();
911 double *prz = rz.rwdata ();
912 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
915 zgecon_info F77_CHAR_ARG_LEN (1)));
917 if (zgecon_info != 0)
922 if ((info == -1 && ! force)
923 || octave::math::isnan (anorm) || octave::math::isinf (anorm))
932 if (zgetri_info != 0)
944 double& rcon,
bool force,
bool calc_cond)
const
946 int typ = mattype.
type (
false);
950 typ = mattype.
type (*
this);
955 double real = std::real (scalar);
956 double imag = std::imag (scalar);
960 Complex (octave::numeric_limits<double>::Inf (), 0.0));
962 ret =
Complex (1, 0) / (*this);
966 if (octave::math::isfinite (
real) && octave::math::isfinite (
imag)
969 else if (octave::math::isinf (
real) || octave::math::isinf (
imag)
973 rcon = octave::numeric_limits<double>::NaN ();
977 ret = tinverse (mattype, info, rcon, force, calc_cond);
982 octave::math::chol<ComplexMatrix>
chol (*
this, info,
true, calc_cond);
996 ret = finverse (mattype, info, rcon, force, calc_cond);
998 if ((calc_cond || mattype.
ishermitian ()) && rcon == 0.0)
1001 Complex (octave::numeric_limits<double>::Inf (), 0.0));
1013 octave::math::svd<ComplexMatrix> result (*
this,
1014 octave::math::svd<ComplexMatrix>::Type::economy);
1028 tol = std::max (nr, nc) * sigma.
elem (0)
1029 * std::numeric_limits<double>::epsilon ();
1032 tol = std::numeric_limits<double>::min ();
1035 while (r >= 0 && sigma.
elem (r) < tol)
1051#if defined (HAVE_FFTW)
1056 std::size_t nr =
rows ();
1057 std::size_t nc =
cols ();
1061 std::size_t npts, nsamples;
1063 if (nr == 1 || nc == 1)
1065 npts = (nr > nc ? nr : nc);
1077 octave::fftw::fft (in, out, npts, nsamples);
1085 std::size_t nr =
rows ();
1086 std::size_t nc =
cols ();
1090 std::size_t npts, nsamples;
1092 if (nr == 1 || nc == 1)
1094 npts = (nr > nc ? nr : nc);
1106 octave::fftw::ifft (in, out, npts, nsamples);
1120 octave::fftw::fftNd (in, out, 2, dv);
1134 octave::fftw::ifftNd (in, out, 2, dv);
1144 (*current_liboctave_error_handler)
1145 (
"support for FFTW was unavailable or disabled when liboctave was built");
1153 (*current_liboctave_error_handler)
1154 (
"support for FFTW was unavailable or disabled when liboctave was built");
1162 (*current_liboctave_error_handler)
1163 (
"support for FFTW was unavailable or disabled when liboctave was built");
1171 (*current_liboctave_error_handler)
1172 (
"support for FFTW was unavailable or disabled when liboctave was built");
1196 bool calc_cond)
const
1199 return determinant (mattype, info, rcon, calc_cond);
1205 bool calc_cond)
const
1216 (*current_liboctave_error_handler) (
"matrix must be square");
1218 int typ = mattype.
type ();
1225 typ = mattype.
type (*
this);
1231 for (
F77_INT i = 0; i < nc; i++)
1232 retval *=
elem (i, i);
1241 anorm = norm1 (*
this);
1246 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
1248 F77_CHAR_ARG_LEN (1)));
1265 double *prz = rz.
rwdata ();
1267 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
1270 F77_CHAR_ARG_LEN (1)));
1278 for (
F77_INT i = 0; i < nc; i++)
1279 retval *= atmp(i, i);
1281 retval = retval.
square ();
1285 (*current_liboctave_error_handler) (
"det: invalid dense matrix type");
1298 double anorm = norm1 (*
this);
1303 if (octave::math::isnan (anorm))
1329 double *prz = rz.
rwdata ();
1331 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1334 F77_CHAR_ARG_LEN (1)));
1346 for (
F77_INT i = 0; i < nc; i++)
1349 retval *= (ipvt(i) != (i+1)) ? -c : c;
1362 return rcond (mattype);
1368 double rcon = octave::numeric_limits<double>::NaN ();
1373 (*current_liboctave_error_handler) (
"matrix must be square");
1375 if (nr == 0 || nc == 0)
1376 rcon = octave::numeric_limits<double>::Inf ();
1379 int typ = mattype.
type ();
1382 typ = mattype.
type (*
this);
1396 double *prz = rz.
rwdata ();
1398 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1399 F77_CONST_CHAR_ARG2 (&uplo, 1),
1400 F77_CONST_CHAR_ARG2 (&dia, 1),
1403 F77_CHAR_ARG_LEN (1)
1404 F77_CHAR_ARG_LEN (1)
1405 F77_CHAR_ARG_LEN (1)));
1411 (*current_liboctave_error_handler)
1412 (
"permuted triangular matrix not implemented");
1424 double *prz = rz.
rwdata ();
1426 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1427 F77_CONST_CHAR_ARG2 (&uplo, 1),
1428 F77_CONST_CHAR_ARG2 (&dia, 1),
1431 F77_CHAR_ARG_LEN (1)
1432 F77_CHAR_ARG_LEN (1)
1433 F77_CHAR_ARG_LEN (1)));
1439 (*current_liboctave_error_handler)
1440 (
"permuted triangular matrix not implemented");
1443 double anorm = -1.0;
1453 anorm = norm1 (atmp);
1455 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
1457 F77_CHAR_ARG_LEN (1)));
1471 double *prz = rz.
rwdata ();
1473 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
1476 F77_CHAR_ARG_LEN (1)));
1494 anorm = norm1 (atmp);
1499 double *prz = rz.
rwdata ();
1502 if (octave::math::isnan (anorm))
1517 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1520 F77_CHAR_ARG_LEN (1)));
1537 solve_singularity_handler sing_handler,
1549 (*current_liboctave_error_handler)
1550 (
"matrix dimension mismatch solution of linear equations");
1552 if (nr == 0 || nc == 0 || b_nc == 0)
1556 int typ = mattype.
type ();
1559 (*current_liboctave_error_handler) (
"incorrect matrix type");
1565 (*current_liboctave_error_handler)
1566 (
"permuted triangular matrix not implemented");
1579 F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
1580 F77_CONST_CHAR_ARG2 (&trans, 1),
1581 F77_CONST_CHAR_ARG2 (&dia, 1),
1584 F77_CHAR_ARG_LEN (1)
1585 F77_CHAR_ARG_LEN (1)
1586 F77_CHAR_ARG_LEN (1)));
1599 double *prz = rz.rwdata ();
1601 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1602 F77_CONST_CHAR_ARG2 (&uplo, 1),
1603 F77_CONST_CHAR_ARG2 (&dia, 1),
1606 F77_CHAR_ARG_LEN (1)
1607 F77_CHAR_ARG_LEN (1)
1608 F77_CHAR_ARG_LEN (1)));
1615 if (is_singular (rcon) || octave::math::isnan (rcon))
1620 sing_handler (rcon);
1622 octave::warn_singular_matrix (rcon);
1633 solve_singularity_handler sing_handler,
1645 (*current_liboctave_error_handler)
1646 (
"matrix dimension mismatch solution of linear equations");
1648 if (nr == 0 || nc == 0 || b_nc == 0)
1652 int typ = mattype.
type ();
1655 (*current_liboctave_error_handler) (
"incorrect matrix type");
1661 (*current_liboctave_error_handler)
1662 (
"permuted triangular matrix not implemented");
1675 F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
1676 F77_CONST_CHAR_ARG2 (&trans, 1),
1677 F77_CONST_CHAR_ARG2 (&dia, 1),
1680 F77_CHAR_ARG_LEN (1)
1681 F77_CHAR_ARG_LEN (1)
1682 F77_CHAR_ARG_LEN (1)));
1695 double *prz = rz.rwdata ();
1697 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1698 F77_CONST_CHAR_ARG2 (&uplo, 1),
1699 F77_CONST_CHAR_ARG2 (&dia, 1),
1702 F77_CHAR_ARG_LEN (1)
1703 F77_CHAR_ARG_LEN (1)
1704 F77_CHAR_ARG_LEN (1)));
1711 if (is_singular (rcon) || octave::math::isnan (rcon))
1716 sing_handler (rcon);
1718 octave::warn_singular_matrix (rcon);
1729 solve_singularity_handler sing_handler,
1730 bool calc_cond)
const
1740 if (nr != nc || nr != b_nr)
1741 (*current_liboctave_error_handler)
1742 (
"matrix dimension mismatch solution of linear equations");
1744 if (nr == 0 || b_nc == 0)
1748 int typ = mattype.
type ();
1751 double anorm = -1.0;
1763 anorm = norm1 (atmp);
1767 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
1769 F77_CHAR_ARG_LEN (1)));
1789 double *prz = rz.rwdata ();
1791 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
1794 F77_CHAR_ARG_LEN (1)));
1801 if (is_singular (rcon) || octave::math::isnan (rcon))
1806 sing_handler (rcon);
1808 octave::warn_singular_matrix (rcon);
1817 F77_XFCN (zpotrs, ZPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1),
1820 F77_CHAR_ARG_LEN (1)));
1837 F77_INT *pipvt = ipvt.rwdata ();
1845 double *prz = rz.rwdata ();
1848 if (calc_cond && anorm < 0.0)
1849 anorm = norm1 (atmp);
1855 if (octave::math::isnan (anorm) || octave::math::isinf (anorm))
1860 nr, pipvt, tmp_info));
1872 sing_handler (rcon);
1874 octave::warn_singular_matrix ();
1884 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1887 F77_CHAR_ARG_LEN (1)));
1894 if (is_singular (rcon) || octave::math::isnan (rcon))
1897 sing_handler (rcon);
1899 octave::warn_singular_matrix (rcon);
1909 F77_XFCN (zgetrs, ZGETRS, (F77_CONST_CHAR_ARG2 (&job, 1),
1912 F77_CHAR_ARG_LEN (1)));
1921 if (octave::math::isinf (anorm))
1936 return solve (mattype, b, info, rcon,
nullptr);
1944 return solve (mattype, b, info, rcon,
nullptr);
1951 return solve (mattype, b, info, rcon,
nullptr);
1957 solve_singularity_handler sing_handler,
1961 return solve (mattype, tmp, info, rcon, sing_handler, singular_fallback,
1970 return solve (mattype, b, info, rcon,
nullptr);
1978 return solve (mattype, b, info, rcon,
nullptr);
1985 return solve (mattype, b, info, rcon,
nullptr);
1991 solve_singularity_handler sing_handler,
1995 int typ = mattype.
type ();
1998 typ = mattype.
type (*
this);
2002 retval = utsolve (mattype, b, info, rcon, sing_handler,
true, transt);
2004 retval = ltsolve (mattype, b, info, rcon, sing_handler,
true, transt);
2009 retval =
hermitian ().
solve (mattype, b, info, rcon, sing_handler,
2012 retval = fsolve (mattype, b, info, rcon, sing_handler,
true);
2014 (*current_liboctave_error_handler) (
"unknown matrix type");
2020 retval =
lssolve (b, info, rank, rcon);
2052 solve_singularity_handler sing_handler,
2064 return solve (mattype, b, info, rcon,
nullptr);
2072 return solve (mattype, b, info, rcon,
nullptr);
2079 return solve (mattype, b, info, rcon,
nullptr);
2085 solve_singularity_handler sing_handler,
2090 tmp =
solve (mattype, tmp, info, rcon, sing_handler,
true, transt);
2099 return solve (b, info, rcon,
nullptr);
2106 return solve (b, info, rcon,
nullptr);
2113 return solve (b, info, rcon,
nullptr);
2118 solve_singularity_handler sing_handler,
2122 return solve (tmp, info, rcon, sing_handler, transt);
2130 return solve (b, info, rcon,
nullptr);
2137 return solve (b, info, rcon,
nullptr);
2144 return solve (b, info, rcon,
nullptr);
2150 solve_singularity_handler sing_handler,
2154 return solve (mattype, b, info, rcon, sing_handler,
true, transt);
2182 solve_singularity_handler sing_handler,
2193 return solve (b, info, rcon,
nullptr);
2200 return solve (b, info, rcon,
nullptr);
2207 return solve (b, info, rcon,
nullptr);
2213 solve_singularity_handler sing_handler,
2217 return solve (mattype, b, info, rcon, sing_handler, transt);
2258 return lssolve (b, info, rank, rcon);
2266 return lssolve (b, info, rank, rcon);
2274 return lssolve (b, info, rank, rcon);
2291 (*current_liboctave_error_handler)
2292 (
"matrix dimension mismatch solution of linear equations");
2294 if (m == 0 || n == 0 || b_nc == 0)
2298 F77_INT minmn = (m < n ? m : n);
2299 F77_INT maxmn = (m > n ? m : n);
2306 for (
F77_INT j = 0; j < nrhs; j++)
2307 for (
F77_INT i = 0; i < m; i++)
2308 retval.
elem (i, j) = b.
elem (i, j);
2318 double *ps = s.
rwdata ();
2327 F77_CONST_CHAR_ARG2 (
" ", 1),
2329 F77_CHAR_ARG_LEN (6)
2330 F77_CHAR_ARG_LEN (1));
2334 F77_CONST_CHAR_ARG2 (
" ", 1),
2335 m, n, nrhs, -1, mnthr
2336 F77_CHAR_ARG_LEN (6)
2337 F77_CHAR_ARG_LEN (1));
2342 double dminmn =
static_cast<double> (minmn);
2343 double dsmlsizp1 =
static_cast<double> (smlsiz+1);
2344 double tmp = octave::math::log2 (dminmn / dsmlsizp1);
2350 F77_INT lrwork = minmn*(10 + 2*smlsiz + 8*nlvl)
2352 + std::max ((smlsiz+1)*(smlsiz+1),
2353 n*(1+nrhs) + 2*nrhs);
2357 double *prwork = rwork.
rwdata ();
2359 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
2371 lwork, prwork, piwork, tmp_info));
2380 if (n > m && n >= mnthr)
2393 const F77_INT lworkaround = 4*m + m*m + addend;
2395 if (std::real (work(0)) < lworkaround)
2396 work(0) = lworkaround;
2400 F77_INT lworkaround = 2*m + m*nrhs;
2402 if (std::real (work(0)) < lworkaround)
2403 work(0) = lworkaround;
2406 lwork =
static_cast<F77_INT> (std::real (work(0)));
2409 double anorm = norm1 (*
this);
2411 if (octave::math::isinf (anorm))
2416 else if (octave::math::isnan (anorm))
2418 rcon = octave::numeric_limits<double>::NaN ();
2420 octave::numeric_limits<double>::NaN ());
2426 maxmn, ps, rcon, tmp_rank,
2428 lwork, prwork, piwork, tmp_info));
2433 if (s.
elem (0) == 0.0)
2436 rcon = s.
elem (minmn - 1) / s.
elem (0);
2483 return lssolve (b, info, rank, rcon);
2492 return lssolve (b, info, rank, rcon);
2500 return lssolve (b, info, rank, rcon);
2518 (*current_liboctave_error_handler)
2519 (
"matrix dimension mismatch solution of linear equations");
2521 if (m == 0 || n == 0)
2525 F77_INT minmn = (m < n ? m : n);
2526 F77_INT maxmn = (m > n ? m : n);
2533 for (
F77_INT i = 0; i < m; i++)
2544 double *ps = s.
rwdata ();
2553 F77_CONST_CHAR_ARG2 (
" ", 1),
2555 F77_CHAR_ARG_LEN (6)
2556 F77_CHAR_ARG_LEN (1));
2561 double dminmn =
static_cast<double> (minmn);
2562 double dsmlsizp1 =
static_cast<double> (smlsiz+1);
2563 double tmp = octave::math::log2 (dminmn / dsmlsizp1);
2569 F77_INT lrwork = minmn*(10 + 2*smlsiz + 8*nlvl)
2570 + 3*smlsiz*nrhs + (smlsiz+1)*(smlsiz+1);
2574 double *prwork = rwork.
rwdata ();
2576 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
2588 lwork, prwork, piwork, tmp_info));
2593 lwork =
static_cast<F77_INT> (std::real (work(0)));
2600 maxmn, ps, rcon, tmp_rank,
2602 prwork, piwork, tmp_info));
2609 if (s.
elem (0) == 0.0)
2612 rcon = s.
elem (minmn - 1) / s.
elem (0);
2651 F77_XFCN (zgemm, ZGEMM, (F77_CONST_CHAR_ARG2 (
"N", 1),
2652 F77_CONST_CHAR_ARG2 (
"N", 1),
2655 F77_CHAR_ARG_LEN (1)
2656 F77_CHAR_ARG_LEN (1)));
2673 if (nr != a_nr || nc != a_nc)
2674 octave::err_nonconformant (
"operator +=", nr, nc, a_nr, a_nc);
2691 if (nr != a_nr || nc != a_nc)
2692 octave::err_nonconformant (
"operator -=", nr, nc, a_nr, a_nc);
2709 if (nr != a_nr || nc != a_nc)
2710 octave::err_nonconformant (
"operator +=", nr, nc, a_nr, a_nc);
2727 if (nr != a_nr || nc != a_nc)
2728 octave::err_nonconformant (
"operator -=", nr, nc, a_nr, a_nc);
2747 if (nr != a_nr || nc != a_nc)
2748 octave::err_nonconformant (
"operator +=", nr, nc, a_nr, a_nc);
2750 if (nr == 0 || nc == 0)
2768 if (nr != a_nr || nc != a_nc)
2769 octave::err_nonconformant (
"operator -=", nr, nc, a_nr, a_nc);
2771 if (nr == 0 || nc == 0)
2842 if (nr != 1 && nc != 1)
2843 (*current_liboctave_error_handler) (
"diag: expecting vector argument");
2857 if (std::imag (
elem (i, j)) != 0.0)
2876 if (std::imag (
elem (i, j)) != 0.0)
2901 if (nr > 0 && nc > 0)
2914 double abs_min = octave::numeric_limits<double>::NaN ();
2916 for (idx_j = 0; idx_j < nc; idx_j++)
2918 tmp_min =
elem (i, idx_j);
2920 if (! octave::math::isnan (tmp_min))
2922 abs_min = (real_only ? tmp_min.real ()
2923 : std::abs (tmp_min));
2932 if (octave::math::isnan (tmp))
2935 double abs_tmp = (real_only ? tmp.real () : std::abs (tmp));
2937 if (abs_tmp < abs_min)
2945 if (octave::math::isnan (tmp_min))
2947 result.
elem (i) = Complex_NaN_result;
2948 idx_arg.
elem (i) = 0;
2952 result.
elem (i) = tmp_min;
2953 idx_arg.
elem (i) = idx_j;
2976 if (nr > 0 && nc > 0)
2989 double abs_max = octave::numeric_limits<double>::NaN ();
2991 for (idx_j = 0; idx_j < nc; idx_j++)
2993 tmp_max =
elem (i, idx_j);
2995 if (! octave::math::isnan (tmp_max))
2997 abs_max = (real_only ? tmp_max.real ()
2998 : std::abs (tmp_max));
3007 if (octave::math::isnan (tmp))
3010 double abs_tmp = (real_only ? tmp.real () : std::abs (tmp));
3012 if (abs_tmp > abs_max)
3020 if (octave::math::isnan (tmp_max))
3022 result.
elem (i) = Complex_NaN_result;
3023 idx_arg.
elem (i) = 0;
3027 result.
elem (i) = tmp_max;
3028 idx_arg.
elem (i) = idx_j;
3051 if (nr > 0 && nc > 0)
3064 double abs_min = octave::numeric_limits<double>::NaN ();
3066 for (idx_i = 0; idx_i < nr; idx_i++)
3068 tmp_min =
elem (idx_i, j);
3070 if (! octave::math::isnan (tmp_min))
3072 abs_min = (real_only ? tmp_min.real ()
3073 : std::abs (tmp_min));
3082 if (octave::math::isnan (tmp))
3085 double abs_tmp = (real_only ? tmp.real () : std::abs (tmp));
3087 if (abs_tmp < abs_min)
3095 if (octave::math::isnan (tmp_min))
3097 result.
elem (j) = Complex_NaN_result;
3098 idx_arg.
elem (j) = 0;
3102 result.
elem (j) = tmp_min;
3103 idx_arg.
elem (j) = idx_i;
3126 if (nr > 0 && nc > 0)
3139 double abs_max = octave::numeric_limits<double>::NaN ();
3141 for (idx_i = 0; idx_i < nr; idx_i++)
3143 tmp_max =
elem (idx_i, j);
3145 if (! octave::math::isnan (tmp_max))
3147 abs_max = (real_only ? tmp_max.real ()
3148 : std::abs (tmp_max));
3157 if (octave::math::isnan (tmp))
3160 double abs_tmp = (real_only ? tmp.real () : std::abs (tmp));
3162 if (abs_tmp > abs_max)
3170 if (octave::math::isnan (tmp_max))
3172 result.
elem (j) = Complex_NaN_result;
3173 idx_arg.
elem (j) = 0;
3177 result.
elem (j) = tmp_max;
3178 idx_arg.
elem (j) = idx_i;
3196 octave::write_value<Complex> (os, a.
elem (i, j));
3209 if (nr > 0 && nc > 0)
3215 tmp = octave::read_value<Complex> (is);
3217 a.
elem (i, j) = tmp;
3258 octave::math::schur<ComplexMatrix> as (a,
"U");
3259 octave::math::schur<ComplexMatrix> bs (b,
"U");
3283 F77_XFCN (ztrsyl, ZTRSYL, (F77_CONST_CHAR_ARG2 (
"N", 1),
3284 F77_CONST_CHAR_ARG2 (
"N", 1),
3287 F77_CHAR_ARG_LEN (1)
3288 F77_CHAR_ARG_LEN (1)));
3339get_blas_trans_arg (
bool trans,
bool conj)
3341 return trans ? (
conj ?
'C' :
'T') :
'N';
3364 octave::err_nonconformant (
"operator *", a_nr, a_nc, b_nr, b_nc);
3366 if (a_nr == 0 || a_nc == 0 || b_nc == 0)
3368 else if (a.
data () == b.
data () && a_nr == b_nc && tra != trb)
3380 const char ctra = get_blas_trans_arg (tra, cja);
3383 F77_XFCN (zherk, ZHERK, (F77_CONST_CHAR_ARG2 (
"U", 1),
3384 F77_CONST_CHAR_ARG2 (&ctra, 1),
3387 F77_CHAR_ARG_LEN (1)
3388 F77_CHAR_ARG_LEN (1)));
3389 for (
F77_INT j = 0; j < a_nr; j++)
3390 for (
F77_INT i = 0; i < j; i++)
3391 retval.
xelem (j, i) = octave::math::conj (retval.
xelem (i, j));
3395 F77_XFCN (zsyrk, ZSYRK, (F77_CONST_CHAR_ARG2 (
"U", 1),
3396 F77_CONST_CHAR_ARG2 (&ctra, 1),
3399 F77_CHAR_ARG_LEN (1)
3400 F77_CHAR_ARG_LEN (1)));
3401 for (
F77_INT j = 0; j < a_nr; j++)
3402 for (
F77_INT i = 0; i < j; i++)
3418 if (b_nc == 1 && a_nr == 1)
3425 if (cja) *c = octave::math::conj (*c);
3436 else if (b_nc == 1 && ! cjb)
3438 const char ctra = get_blas_trans_arg (tra, cja);
3439 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1),
3442 F77_CHAR_ARG_LEN (1)));
3444 else if (a_nr == 1 && ! cja && ! cjb)
3446 const char crevtrb = get_blas_trans_arg (! trb, cjb);
3447 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1),
3450 F77_CHAR_ARG_LEN (1)));
3454 const char ctra = get_blas_trans_arg (tra, cja);
3455 const char ctrb = get_blas_trans_arg (trb, cjb);
3456 F77_XFCN (zgemm, ZGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1),
3457 F77_CONST_CHAR_ARG2 (&ctrb, 1),
3461 F77_CHAR_ARG_LEN (1)
3462 F77_CHAR_ARG_LEN (1)));
3472 return xgemm (a, b);
3477#define EMPTY_RETURN_CHECK(T) \
3478 if (nr == 0 || nc == 0) \
3495 result(i, j) = octave::math::min (c, m(i, j));
3514 (*current_liboctave_error_handler)
3515 (
"two-arg min requires same size arguments");
3523 bool columns_are_real_only =
true;
3527 if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0)
3529 columns_are_real_only =
false;
3534 if (columns_are_real_only)
3537 result(i, j) = octave::math::min (std::real (a(i, j)),
3538 std::real (b(i, j)));
3545 result(i, j) = octave::math::min (a(i, j), b(i, j));
3567 result(i, j) = octave::math::max (c, m(i, j));
3586 (*current_liboctave_error_handler)
3587 (
"two-arg max requires same size arguments");
3595 bool columns_are_real_only =
true;
3599 if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0)
3601 columns_are_real_only =
false;
3607 if (columns_are_real_only)
3612 result(i, j) = octave::math::max (std::real (a(i, j)),
3613 std::real (b(i, j)));
3621 result(i, j) = octave::math::max (a(i, j), b(i, j));
3636 if (x2.
numel () != m)
3637 (*current_liboctave_error_handler)
3638 (
"linspace: vectors must be of equal length");
3644 retval.
clear (m, 0);
3648 retval.clear (m, n);
3650 retval.insert (
linspace (x1(i), x2(i), n), i, 0);
std::ostream & operator<<(std::ostream &os, const ComplexMatrix &a)
ComplexMatrix max(const Complex &c, const ComplexMatrix &m)
ComplexMatrix Givens(const Complex &x, const Complex &y)
ComplexMatrix conj(const ComplexMatrix &a)
ComplexMatrix linspace(const ComplexColumnVector &x1, const ComplexColumnVector &x2, octave_idx_type n)
ComplexMatrix Sylvester(const ComplexMatrix &a, const ComplexMatrix &b, const ComplexMatrix &c)
ComplexMatrix min(const Complex &c, const ComplexMatrix &m)
#define EMPTY_RETURN_CHECK(T)
ComplexMatrix operator*(const ColumnVector &v, const ComplexRowVector &a)
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
std::istream & operator>>(std::istream &is, ComplexMatrix &a)
base_det< Complex > ComplexDET
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
Array< T, Alloc > index(const octave::idx_vector &i) const
Indexing without resizing.
bool issquare() const
Size of the specified dimension.
T & elem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type rows() const
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type columns() const
octave_idx_type cols() const
const T * data() const
Size of the specified dimension.
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
ColumnVector extract(octave_idx_type r1, octave_idx_type r2) const
void resize(octave_idx_type n, const Complex &rfv=Complex(0))
ComplexRowVector column_max() const
ComplexMatrix & operator+=(const DiagMatrix &a)
ComplexMatrix & operator-=(const DiagMatrix &a)
ComplexMatrix lssolve(const Matrix &b) const
ComplexMatrix ifourier2d() const
ComplexColumnVector row_max() const
ComplexMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
ComplexColumnVector row_min() const
ComplexMatrix fourier() const
friend ComplexMatrix conj(const ComplexMatrix &a)
boolMatrix all(int dim=-1) const
ComplexMatrix & fill(double val)
ComplexMatrix append(const Matrix &a) const
ComplexMatrix diag(octave_idx_type k=0) const
ComplexMatrix pseudo_inverse(double tol=0.0) const
bool operator==(const ComplexMatrix &a) const
ComplexMatrix fourier2d() const
ComplexRowVector row(octave_idx_type i) const
ComplexMatrix & insert(const Matrix &a, octave_idx_type r, octave_idx_type c)
ComplexMatrix solve(MatrixType &mattype, const Matrix &b) const
ComplexMatrix inverse() const
bool row_is_real_only(octave_idx_type) const
ComplexMatrix sumsq(int dim=-1) const
void resize(octave_idx_type nr, octave_idx_type nc, const Complex &rfv=Complex(0))
ComplexMatrix extract_n(octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
ComplexMatrix stack(const Matrix &a) const
ComplexMatrix cumprod(int dim=-1) const
ComplexMatrix transpose() const
ComplexMatrix prod(int dim=-1) const
ComplexDET determinant() const
ComplexMatrix cumsum(int dim=-1) const
ComplexMatrix ifourier() const
boolMatrix any(int dim=-1) const
ComplexRowVector column_min() const
bool operator!=(const ComplexMatrix &a) const
ComplexMatrix hermitian() const
bool column_is_real_only(octave_idx_type) const
ComplexMatrix sum(int dim=-1) const
ComplexColumnVector column(octave_idx_type i) const
boolNDArray any(int dim=-1) const
ComplexNDArray prod(int dim=-1) const
ComplexNDArray sumsq(int dim=-1) const
ComplexNDArray diag(octave_idx_type k=0) const
ComplexNDArray cumsum(int dim=-1) const
ComplexNDArray & insert(const NDArray &a, octave_idx_type r, octave_idx_type c)
ComplexNDArray cumprod(int dim=-1) const
boolNDArray all(int dim=-1) const
ComplexNDArray sum(int dim=-1) const
void resize(octave_idx_type n, const Complex &rfv=Complex(0))
octave_idx_type rows() const
octave_idx_type length() const
T elem(octave_idx_type r, octave_idx_type c) const
octave_idx_type cols() const
DiagMatrix inverse() const
ColumnVector extract_diag(octave_idx_type k=0) const
Template for two dimensional diagonal array with math operators.
void mark_as_unsymmetric()
int type(bool quiet=true)
void mark_as_rectangular()
Matrix sum(int dim=-1) const
RowVector row(octave_idx_type i) const
Vector representing the dimensions (size) of an Array.
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
#define F77_DBLE_CMPLX_ARG(x)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
#define F77_CONST_DBLE_CMPLX_ARG(x)
double norm(const ColumnVector &v)
void scale(Matrix &m, double x, double y, double z)
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_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
char get_blas_char(blas_trans_type transt)
void mx_inline_sub2(std::size_t n, R *r, const X *x)
void mx_inline_add2(std::size_t n, R *r, const X *x)
bool mx_inline_equal(std::size_t n, const T1 *x, const T2 *y)
#define MM_BOOL_OPS(M1, M2)
#define MM_CMP_OPS(M1, M2)
#define SM_BOOL_OPS(S, M)
#define MS_BOOL_OPS(M, S)
std::complex< double > Complex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg
subroutine xilaenv(ispec, name, opts, n1, n2, n3, n4, retval)
subroutine xzdotc(n, zx, incx, zy, incy, retval)
subroutine xzdotu(n, zx, incx, zy, incy, retval)