26#if defined (HAVE_CONFIG_H)
106 elem (ia(i), i) = 1.0;
120 elem (i, j) =
static_cast<unsigned char> (a.
elem (i, j));
135 return !(*
this == a);
168 if (r < 0 || r >=
rows () || c < 0 || c + a_len >
cols ())
169 (*current_liboctave_error_handler) (
"range error for insert");
188 if (r < 0 || r + a_len >
rows () || c < 0 || c >=
cols ())
189 (*current_liboctave_error_handler) (
"range error for insert");
209 if (r < 0 || r + a_nr >
rows () || c < 0 || c + a_nc >
cols ())
210 (*current_liboctave_error_handler) (
"range error for insert");
212 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1);
233 if (nr > 0 && nc > 0)
252 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0
253 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc)
254 (*current_liboctave_error_handler) (
"range error for fill");
256 if (r1 > r2) { std::swap (r1, r2); }
257 if (c1 > c2) { std::swap (c1, c2); }
259 if (r2 >= r1 && c2 >= c1)
277 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
281 retval.
insert (*
this, 0, 0);
282 retval.
insert (a, 0, nc_insert);
292 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
296 retval.
insert (*
this, 0, 0);
297 retval.
insert (a, 0, nc_insert);
306 if (nr != a.
numel ())
307 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
311 retval.
insert (*
this, 0, 0);
312 retval.
insert (a, 0, nc_insert);
322 (*current_liboctave_error_handler) (
"row dimension mismatch for append");
326 retval.
insert (*
this, 0, 0);
327 retval.
insert (a, 0, nc_insert);
337 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
341 retval.
insert (*
this, 0, 0);
342 retval.
insert (a, nr_insert, 0);
351 if (nc != a.
numel ())
352 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
356 retval.
insert (*
this, 0, 0);
357 retval.
insert (a, nr_insert, 0);
367 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
371 retval.
insert (*
this, 0, 0);
372 retval.
insert (a, nr_insert, 0);
382 (*current_liboctave_error_handler) (
"column dimension mismatch for stack");
386 retval.
insert (*
this, 0, 0);
387 retval.
insert (a, nr_insert, 0);
407 if (r1 > r2) { std::swap (r1, r2); }
408 if (c1 > c2) { std::swap (c1, c2); }
410 return index (octave::idx_vector (r1, r2+1), octave::idx_vector (c1, c2+1));
417 return index (octave::idx_vector (r1, r1 + nr), octave::idx_vector (c1, c1 + nc));
425 return index (octave::idx_vector (i), octave::idx_vector::colon);
431 return index (octave::idx_vector::colon, octave::idx_vector (i));
444 float sum = colsum.
xelem (i);
445 if (octave::math::isinf (sum) || octave::math::isnan (sum))
451 anorm = std::max (anorm, sum);
460is_singular (
const float rcond)
462 return (std::abs (rcond) <= std::numeric_limits<float>::epsilon ());
471 return inverse (mattype, info, rcon,
false,
false);
479 return inverse (mattype, info, rcon,
false,
false);
484 bool force,
bool calc_cond)
const
487 return inverse (mattype, info, rcon, force, calc_cond);
495 return inverse (mattype, info, rcon,
false,
false);
502 return inverse (mattype, info, rcon,
false,
false);
507 bool force,
bool calc_cond)
const
514 if (nr != nc || nr == 0 || nc == 0)
515 (*current_liboctave_error_handler) (
"inverse requires square matrix");
517 int typ = mattype.
type ();
521 float *tmp_data = retval.
rwdata ();
525 F77_XFCN (strtri, STRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1),
526 F77_CONST_CHAR_ARG2 (&udiag, 1),
527 nr, tmp_data, nr, tmp_info
529 F77_CHAR_ARG_LEN (1)));
545 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&job, 1),
546 F77_CONST_CHAR_ARG2 (&uplo, 1),
547 F77_CONST_CHAR_ARG2 (&udiag, 1),
548 nr, tmp_data, nr, rcon,
549 work, iwork, dtrcon_info
552 F77_CHAR_ARG_LEN (1)));
554 if (dtrcon_info != 0)
558 if (info == -1 && ! force)
566 bool force,
bool calc_cond)
const
573 if (nr != nc || nr == 0 || nc == 0)
574 (*current_liboctave_error_handler) (
"inverse requires square matrix");
577 F77_INT *pipvt = ipvt.rwdata ();
580 float *tmp_data = retval.
rwdata ();
588 F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt,
589 z.rwdata (), lwork, tmp_info));
591 lwork =
static_cast<F77_INT> (z(0));
592 lwork = (lwork < 4 * nc ? 4 * nc : lwork);
594 float *pz = z.rwdata ();
602 anorm = norm1 (retval);
604 F77_XFCN (sgetrf, SGETRF, (nc, nc, tmp_data, nr, pipvt, tmp_info));
614 if (octave::math::isnan (anorm))
615 rcon = octave::numeric_limits<float>::NaN ();
624 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
625 nc, tmp_data, nr, anorm,
626 rcon, pz, piz, sgecon_info
627 F77_CHAR_ARG_LEN (1)));
629 if (sgecon_info != 0)
634 if (info == -1 && ! force)
640 F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt,
641 pz, lwork, dgetri_info));
643 if (dgetri_info != 0)
655 bool force,
bool calc_cond)
const
657 int typ = mattype.
type (
false);
661 typ = mattype.
type (*
this);
668 float scalar = this->
elem (0);
669 if (octave::math::isfinite (scalar) && scalar != 0)
671 else if (octave::math::isinf (scalar) || scalar == 0)
674 rcon = octave::numeric_limits<float>::NaN ();
678 ret = tinverse (mattype, info, rcon, force, calc_cond);
683 octave::math::chol<FloatMatrix>
chol (*
this, info,
true, calc_cond);
697 ret = finverse (mattype, info, rcon, force, calc_cond);
699 if ((calc_cond || mattype.
ishermitian ()) && rcon == 0.0)
701 octave::numeric_limits<float>::Inf ());
710 octave::math::svd<FloatMatrix> result (*
this,
711 octave::math::svd<FloatMatrix>::Type::economy);
725 tol = std::max (nr, nc) * sigma.
elem (0)
726 * std::numeric_limits<float>::epsilon ();
729 tol = std::numeric_limits<float>::min ();
732 while (r >= 0 && sigma.
elem (r) < tol)
746#if defined (HAVE_FFTW)
751 std::size_t nr =
rows ();
752 std::size_t nc =
cols ();
756 std::size_t npts, nsamples;
758 if (nr == 1 || nc == 1)
760 npts = (nr > nc ? nr : nc);
769 const float *in (
data ());
772 octave::fftw::fft (in, out, npts, nsamples);
780 std::size_t nr =
rows ();
781 std::size_t nc =
cols ();
785 std::size_t npts, nsamples;
787 if (nr == 1 || nc == 1)
789 npts = (nr > nc ? nr : nc);
802 octave::fftw::ifft (in, out, npts, nsamples);
812 const float *in =
data ();
814 octave::fftw::fftNd (in, retval.
rwdata (), 2, dv);
827 octave::fftw::ifftNd (out, out, 2, dv);
837 (*current_liboctave_error_handler)
838 (
"support for FFTW was unavailable or disabled when liboctave was built");
846 (*current_liboctave_error_handler)
847 (
"support for FFTW was unavailable or disabled when liboctave was built");
855 (*current_liboctave_error_handler)
856 (
"support for FFTW was unavailable or disabled when liboctave was built");
864 (*current_liboctave_error_handler)
865 (
"support for FFTW was unavailable or disabled when liboctave was built");
889 bool calc_cond)
const
892 return determinant (mattype, info, rcon, calc_cond);
898 bool calc_cond)
const
909 (*current_liboctave_error_handler) (
"matrix must be square");
911 int typ = mattype.
type ();
918 typ = mattype.
type (*
this);
924 for (
F77_INT i = 0; i < nc; i++)
925 retval *=
elem (i, i);
930 float *tmp_data = atmp.
rwdata ();
935 anorm = norm1 (*
this);
940 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
941 tmp_data, nr, tmp_info
942 F77_CHAR_ARG_LEN (1)));
961 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
962 nr, tmp_data, nr, anorm,
963 rcon, pz, piz, tmp_info
964 F77_CHAR_ARG_LEN (1)));
972 for (
F77_INT i = 0; i < nc; i++)
973 retval *= atmp(i, i);
975 retval = retval.
square ();
979 (*current_liboctave_error_handler) (
"det: invalid dense matrix type");
987 float *tmp_data = atmp.
rwdata ();
995 anorm = norm1 (*
this);
997 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info));
1019 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1020 nc, tmp_data, nr, anorm,
1021 rcon, pz, piz, tmp_info
1022 F77_CHAR_ARG_LEN (1)));
1034 for (
F77_INT i = 0; i < nc; i++)
1036 float c = atmp(i, i);
1037 retval *= (ipvt(i) != (i+1)) ? -c : c;
1050 return rcond (mattype);
1056 float rcon = octave::numeric_limits<float>::NaN ();
1061 (*current_liboctave_error_handler) (
"matrix must be square");
1063 if (nr == 0 || nc == 0)
1064 rcon = octave::numeric_limits<float>::Inf ();
1067 int typ = mattype.
type ();
1070 typ = mattype.
type (*
this);
1075 const float *tmp_data =
data ();
1086 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1087 F77_CONST_CHAR_ARG2 (&uplo, 1),
1088 F77_CONST_CHAR_ARG2 (&dia, 1),
1089 nr, tmp_data, nr, rcon,
1091 F77_CHAR_ARG_LEN (1)
1092 F77_CHAR_ARG_LEN (1)
1093 F77_CHAR_ARG_LEN (1)));
1099 (*current_liboctave_error_handler)
1100 (
"permuted triangular matrix not implemented");
1103 const float *tmp_data =
data ();
1114 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1115 F77_CONST_CHAR_ARG2 (&uplo, 1),
1116 F77_CONST_CHAR_ARG2 (&dia, 1),
1117 nr, tmp_data, nr, rcon,
1119 F77_CHAR_ARG_LEN (1)
1120 F77_CHAR_ARG_LEN (1)
1121 F77_CHAR_ARG_LEN (1)));
1127 (*current_liboctave_error_handler)
1128 (
"permuted triangular matrix not implemented");
1139 float *tmp_data = atmp.
rwdata ();
1141 anorm = norm1 (atmp);
1143 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
1145 F77_CHAR_ARG_LEN (1)));
1160 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
1161 nr, tmp_data, nr, anorm,
1163 F77_CHAR_ARG_LEN (1)));
1175 float *tmp_data = atmp.
rwdata ();
1181 anorm = norm1 (atmp);
1188 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, info));
1198 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1199 nc, tmp_data, nr, anorm,
1201 F77_CHAR_ARG_LEN (1)));
1218 float& rcon, solve_singularity_handler sing_handler,
1230 (*current_liboctave_error_handler)
1231 (
"matrix dimension mismatch solution of linear equations");
1233 if (nr == 0 || nc == 0 || b_nc == 0)
1237 int typ = mattype.
type ();
1245 (*current_liboctave_error_handler)
1246 (
"permuted triangular matrix not implemented");
1249 const float *tmp_data =
data ();
1252 float *result = retval.
rwdata ();
1260 F77_XFCN (strtrs, STRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
1261 F77_CONST_CHAR_ARG2 (&trans, 1),
1262 F77_CONST_CHAR_ARG2 (&dia, 1),
1263 nr, b_nc, tmp_data, nr,
1264 result, nr, tmp_info
1265 F77_CHAR_ARG_LEN (1)
1266 F77_CHAR_ARG_LEN (1)
1267 F77_CHAR_ARG_LEN (1)));
1278 float *pz = z.rwdata ();
1282 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1283 F77_CONST_CHAR_ARG2 (&uplo, 1),
1284 F77_CONST_CHAR_ARG2 (&dia, 1),
1285 nr, tmp_data, nr, rcon,
1287 F77_CHAR_ARG_LEN (1)
1288 F77_CHAR_ARG_LEN (1)
1289 F77_CHAR_ARG_LEN (1)));
1296 if (is_singular (rcon) || octave::math::isnan (rcon))
1301 sing_handler (rcon);
1303 octave::warn_singular_matrix (rcon);
1319 float& rcon, solve_singularity_handler sing_handler,
1331 (*current_liboctave_error_handler)
1332 (
"matrix dimension mismatch solution of linear equations");
1334 if (nr == 0 || nc == 0 || b_nc == 0)
1338 int typ = mattype.
type ();
1346 (*current_liboctave_error_handler)
1347 (
"permuted triangular matrix not implemented");
1350 const float *tmp_data =
data ();
1353 float *result = retval.
rwdata ();
1361 F77_XFCN (strtrs, STRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
1362 F77_CONST_CHAR_ARG2 (&trans, 1),
1363 F77_CONST_CHAR_ARG2 (&dia, 1),
1364 nr, b_nc, tmp_data, nr,
1365 result, nr, tmp_info
1366 F77_CHAR_ARG_LEN (1)
1367 F77_CHAR_ARG_LEN (1)
1368 F77_CHAR_ARG_LEN (1)));
1379 float *pz = z.rwdata ();
1383 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&
norm, 1),
1384 F77_CONST_CHAR_ARG2 (&uplo, 1),
1385 F77_CONST_CHAR_ARG2 (&dia, 1),
1386 nr, tmp_data, nr, rcon,
1388 F77_CHAR_ARG_LEN (1)
1389 F77_CHAR_ARG_LEN (1)
1390 F77_CHAR_ARG_LEN (1)));
1397 if (is_singular (rcon) || octave::math::isnan (rcon))
1402 sing_handler (rcon);
1404 octave::warn_singular_matrix (rcon);
1419 float& rcon, solve_singularity_handler sing_handler,
1420 bool calc_cond)
const
1430 if (nr != nc || nr != b_nr)
1431 (*current_liboctave_error_handler)
1432 (
"matrix dimension mismatch solution of linear equations");
1434 if (nr == 0 || b_nc == 0)
1438 int typ = mattype.
type ();
1449 float *tmp_data = atmp.
rwdata ();
1453 anorm = norm1 (atmp);
1457 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
1458 tmp_data, nr, tmp_info
1459 F77_CHAR_ARG_LEN (1)));
1477 float *pz = z.rwdata ();
1481 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
1482 nr, tmp_data, nr, anorm,
1483 rcon, pz, piz, tmp_info
1484 F77_CHAR_ARG_LEN (1)));
1491 if (is_singular (rcon) || octave::math::isnan (rcon))
1496 sing_handler (rcon);
1498 octave::warn_singular_matrix (rcon);
1505 float *result = retval.
rwdata ();
1507 F77_XFCN (spotrs, SPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1),
1508 nr, b_nc, tmp_data, nr,
1509 result, b_nr, tmp_info
1510 F77_CHAR_ARG_LEN (1)));
1527 F77_INT *pipvt = ipvt.rwdata ();
1530 float *tmp_data = atmp.
rwdata ();
1532 if (calc_cond && anorm < 0.0)
1533 anorm = norm1 (atmp);
1536 float *pz = z.rwdata ();
1542 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info));
1553 sing_handler (rcon);
1555 octave::warn_singular_matrix ();
1565 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
1566 nc, tmp_data, nr, anorm,
1567 rcon, pz, piz, tmp_info
1568 F77_CHAR_ARG_LEN (1)));
1575 if (is_singular (rcon) || octave::math::isnan (rcon))
1578 sing_handler (rcon);
1580 octave::warn_singular_matrix (rcon);
1587 float *result = retval.
rwdata ();
1590 F77_XFCN (sgetrs, SGETRS, (F77_CONST_CHAR_ARG2 (&job, 1),
1591 nr, b_nc, tmp_data, nr,
1592 pipvt, result, b_nr, tmp_info
1593 F77_CHAR_ARG_LEN (1)));
1602 (*current_liboctave_error_handler) (
"incorrect matrix type");
1613 return solve (mattype, b, info, rcon,
nullptr);
1621 return solve (mattype, b, info, rcon,
nullptr);
1628 return solve (mattype, b, info, rcon,
nullptr);
1634 float& rcon, solve_singularity_handler sing_handler,
1638 int typ = mattype.
type ();
1641 typ = mattype.
type (*
this);
1645 retval = utsolve (mattype, b, info, rcon, sing_handler,
true, transt);
1647 retval = ltsolve (mattype, b, info, rcon, sing_handler,
true, transt);
1652 retval = fsolve (mattype, b, info, rcon, sing_handler,
true);
1654 (*current_liboctave_error_handler) (
"unknown matrix type");
1660 retval =
lssolve (b, info, rank, rcon);
1671 return solve (mattype, b, info, rcon,
nullptr);
1679 return solve (mattype, b, info, rcon,
nullptr);
1687 return solve (mattype, b, info, rcon,
nullptr);
1698 float *rd = retval.
rwdata ();
1701 rd[i] = std::real (cmd[i]);
1702 rd[nel+i] = std::imag (cmd[i]);
1714 const float *smd = sm.
data ();
1724 float& rcon, solve_singularity_handler sing_handler,
1728 tmp =
solve (mattype, tmp, info, rcon, sing_handler, singular_fallback,
1730 return unstack_complex_matrix (tmp);
1738 return solve (mattype, b, info, rcon);
1746 return solve (mattype, b, info, rcon);
1754 return solve (mattype, b, info, rcon,
nullptr);
1760 float& rcon, solve_singularity_handler sing_handler,
1764 tmp =
solve (mattype, tmp, info, rcon, sing_handler,
true, transt);
1773 return tmp.
solve (mattype, b);
1781 return tmp.
solve (mattype, b, info);
1789 return tmp.
solve (mattype, b, info, rcon);
1795 solve_singularity_handler sing_handler,
1799 return tmp.
solve (mattype, b, info, rcon, sing_handler, transt);
1807 return solve (b, info, rcon,
nullptr);
1814 return solve (b, info, rcon,
nullptr);
1821 return solve (b, info, rcon,
nullptr);
1826 float& rcon, solve_singularity_handler sing_handler,
1830 return solve (mattype, b, info, rcon, sing_handler,
true, transt);
1837 return tmp.
solve (b);
1844 return tmp.
solve (b, info);
1852 return tmp.
solve (b, info, rcon);
1858 solve_singularity_handler sing_handler,
1862 return tmp.
solve (b, info, rcon, sing_handler, transt);
1869 return solve (b, info, rcon);
1876 return solve (b, info, rcon);
1883 return solve (b, info, rcon,
nullptr);
1888 float& rcon, solve_singularity_handler sing_handler,
1892 return solve (mattype, b, info, rcon, sing_handler, transt);
1899 return tmp.
solve (b);
1907 return tmp.
solve (b, info);
1915 return tmp.
solve (b, info, rcon);
1920 float& rcon, solve_singularity_handler sing_handler,
1924 return tmp.
solve (b, info, rcon, sing_handler, transt);
1933 return lssolve (b, info, rank, rcon);
1941 return lssolve (b, info, rank, rcon);
1949 return lssolve (b, info, rank, rcon);
1967 (*current_liboctave_error_handler)
1968 (
"matrix dimension mismatch solution of linear equations");
1970 if (m == 0 || n == 0 || b_nc == 0)
1974 F77_INT minmn = (m < n ? m : n);
1975 F77_INT maxmn = (m > n ? m : n);
1981 for (
F77_INT j = 0; j < nrhs; j++)
1982 for (
F77_INT i = 0; i < m; i++)
1983 retval.
elem (i, j) = b.
elem (i, j);
1989 float *tmp_data = atmp.
rwdata ();
1991 float *pretval = retval.
rwdata ();
2002 F77_CONST_CHAR_ARG2 (
" ", 1),
2004 F77_CHAR_ARG_LEN (6)
2005 F77_CHAR_ARG_LEN (1));
2009 F77_CONST_CHAR_ARG2 (
" ", 1),
2010 m, n, nrhs, -1, mnthr
2011 F77_CHAR_ARG_LEN (6)
2012 F77_CHAR_ARG_LEN (1));
2016 float dminmn =
static_cast<float> (minmn);
2017 float dsmlsizp1 =
static_cast<float> (smlsiz+1);
2018 float tmp = octave::math::log2 (dminmn / dsmlsizp1);
2024 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
2033 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
2034 ps, rcon, tmp_rank, work.
rwdata (),
2035 lwork, piwork, tmp_info));
2044 if (n > m && n >= mnthr)
2047 = 9*m + 2*m*smlsiz + 8*m*nlvl + m*nrhs + (smlsiz+1)*(smlsiz+1);
2060 if (wlalsd > addend)
2063 const F77_INT lworkaround = 4*m + m*m + addend;
2065 if (work(0) < lworkaround)
2066 work(0) = lworkaround;
2071 = 12*n + 2*n*smlsiz + 8*n*nlvl + n*nrhs + (smlsiz+1)*(smlsiz+1);
2073 if (work(0) < lworkaround)
2074 work(0) = lworkaround;
2077 lwork =
static_cast<F77_INT> (work(0));
2080 float anorm = norm1 (*
this);
2082 if (octave::math::isinf (anorm))
2087 else if (octave::math::isnan (anorm))
2089 rcon = octave::numeric_limits<float>::NaN ();
2091 octave::numeric_limits<float>::NaN ());
2095 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval,
2096 maxmn, ps, rcon, tmp_rank,
2103 if (s.
elem (0) == 0.0)
2106 rcon = s.
elem (minmn - 1) / s.
elem (0);
2122 return tmp.
lssolve (b, info, rank, rcon);
2131 return tmp.
lssolve (b, info, rank, rcon);
2140 return tmp.
lssolve (b, info, rank, rcon);
2148 return tmp.
lssolve (b, info, rank, rcon);
2157 return lssolve (b, info, rank, rcon);
2165 return lssolve (b, info, rank, rcon);
2173 return lssolve (b, info, rank, rcon);
2187 if (m != b.
numel ())
2188 (*current_liboctave_error_handler)
2189 (
"matrix dimension mismatch solution of linear equations");
2191 if (m == 0 || n == 0)
2195 F77_INT minmn = (m < n ? m : n);
2196 F77_INT maxmn = (m > n ? m : n);
2203 for (
F77_INT i = 0; i < m; i++)
2210 float *tmp_data = atmp.
rwdata ();
2212 float *pretval = retval.
rwdata ();
2223 F77_CONST_CHAR_ARG2 (
" ", 1),
2225 F77_CHAR_ARG_LEN (6)
2226 F77_CHAR_ARG_LEN (1));
2230 float dminmn =
static_cast<float> (minmn);
2231 float dsmlsizp1 =
static_cast<float> (smlsiz+1);
2232 float tmp = octave::math::log2 (dminmn / dsmlsizp1);
2238 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
2247 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
2248 ps, rcon, tmp_rank, work.
rwdata (),
2249 lwork, piwork, tmp_info));
2254 lwork =
static_cast<F77_INT> (work(0));
2257 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval,
2258 maxmn, ps, rcon, tmp_rank,
2267 if (s.
elem (0) == 0.0)
2270 rcon = s.
elem (minmn - 1) / s.
elem (0);
2286 return tmp.
lssolve (b, info, rank, rcon);
2296 return tmp.
lssolve (b, info, rank, rcon);
2305 return tmp.
lssolve (b, info, rank, rcon);
2313 return tmp.
lssolve (b, info, rank, rcon);
2325 if (nr != a_nr || nc != a_nc)
2326 octave::err_nonconformant (
"operator +=", nr, nc, a_nr, a_nc);
2343 if (nr != a_nr || nc != a_nc)
2344 octave::err_nonconformant (
"operator -=", nr, nc, a_nr, a_nc);
2366 float *c = retval.
rwdata ();
2368 F77_XFCN (sgemm, SGEMM, (F77_CONST_CHAR_ARG2 (
"N", 1),
2369 F77_CONST_CHAR_ARG2 (
"N", 1),
2372 F77_CHAR_ARG_LEN (1)
2373 F77_CHAR_ARG_LEN (1)));
2467 if (nr == 1 || nc == 1)
2490 if (nr > 0 && nc > 0)
2499 float tmp_min = octave::numeric_limits<float>::NaN ();
2501 for (idx_j = 0; idx_j < nc; idx_j++)
2503 tmp_min =
elem (i, idx_j);
2505 if (! octave::math::isnan (tmp_min))
2511 float tmp =
elem (i, j);
2513 if (octave::math::isnan (tmp))
2515 else if (tmp < tmp_min)
2522 result.
elem (i) = tmp_min;
2523 idx_arg.
elem (i) = (octave::math::isnan (tmp_min) ? 0 : idx_j);
2545 if (nr > 0 && nc > 0)
2554 float tmp_max = octave::numeric_limits<float>::NaN ();
2556 for (idx_j = 0; idx_j < nc; idx_j++)
2558 tmp_max =
elem (i, idx_j);
2560 if (! octave::math::isnan (tmp_max))
2566 float tmp =
elem (i, j);
2568 if (octave::math::isnan (tmp))
2570 else if (tmp > tmp_max)
2577 result.
elem (i) = tmp_max;
2578 idx_arg.
elem (i) = (octave::math::isnan (tmp_max) ? 0 : idx_j);
2600 if (nr > 0 && nc > 0)
2609 float tmp_min = octave::numeric_limits<float>::NaN ();
2611 for (idx_i = 0; idx_i < nr; idx_i++)
2613 tmp_min =
elem (idx_i, j);
2615 if (! octave::math::isnan (tmp_min))
2621 float tmp =
elem (i, j);
2623 if (octave::math::isnan (tmp))
2625 else if (tmp < tmp_min)
2632 result.
elem (j) = tmp_min;
2633 idx_arg.
elem (j) = (octave::math::isnan (tmp_min) ? 0 : idx_i);
2655 if (nr > 0 && nc > 0)
2664 float tmp_max = octave::numeric_limits<float>::NaN ();
2666 for (idx_i = 0; idx_i < nr; idx_i++)
2668 tmp_max =
elem (idx_i, j);
2670 if (! octave::math::isnan (tmp_max))
2676 float tmp =
elem (i, j);
2678 if (octave::math::isnan (tmp))
2680 else if (tmp > tmp_max)
2687 result.
elem (j) = tmp_max;
2688 idx_arg.
elem (j) = (octave::math::isnan (tmp_max) ? 0 : idx_i);
2703 octave::write_value<float> (os, a.
elem (i, j));
2716 if (nr > 0 && nc > 0)
2722 tmp = octave::read_value<float> (is);
2724 a.
elem (i, j) = tmp;
2736 float cc, s, temp_r;
2738 F77_FUNC (slartg, SLARTG) (
x, y, cc, s, temp_r);
2759 octave::math::schur<FloatMatrix> as (a,
"U");
2760 octave::math::schur<FloatMatrix> bs (b,
"U");
2781 float *pa = sch_a.
rwdata ();
2782 float *pb = sch_b.
rwdata ();
2783 float *px = cx.
rwdata ();
2785 F77_XFCN (strsyl, STRSYL, (F77_CONST_CHAR_ARG2 (
"N", 1),
2786 F77_CONST_CHAR_ARG2 (
"N", 1),
2787 1, a_nr, b_nr, pa, a_nr, pb,
2788 b_nr, px, a_nr,
scale, info
2789 F77_CHAR_ARG_LEN (1)
2790 F77_CHAR_ARG_LEN (1)));
2821get_blas_trans_arg (
bool trans)
2823 return trans ?
'T' :
'N';
2844 octave::err_nonconformant (
"operator *", a_nr, a_nc, b_nr, b_nc);
2846 if (a_nr == 0 || a_nc == 0 || b_nc == 0)
2848 else if (a.
data () == b.
data () && a_nr == b_nc && tra != trb)
2853 float *c = retval.
rwdata ();
2855 const char ctra = get_blas_trans_arg (tra);
2856 F77_XFCN (ssyrk, SSYRK, (F77_CONST_CHAR_ARG2 (
"U", 1),
2857 F77_CONST_CHAR_ARG2 (&ctra, 1),
2859 a.
data (), lda, 0.0, c, a_nr
2860 F77_CHAR_ARG_LEN (1)
2861 F77_CHAR_ARG_LEN (1)));
2862 for (
int j = 0; j < a_nr; j++)
2863 for (
int i = 0; i < j; i++)
2875 float *c = retval.
rwdata ();
2883 const char ctra = get_blas_trans_arg (tra);
2884 F77_XFCN (sgemv, SGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1),
2885 lda, tda, 1.0, a.
data (), lda,
2886 b.
data (), 1, 0.0, c, 1
2887 F77_CHAR_ARG_LEN (1)));
2892 const char crevtrb = get_blas_trans_arg (! trb);
2893 F77_XFCN (sgemv, SGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1),
2894 ldb, tdb, 1.0, b.
data (), ldb,
2895 a.
data (), 1, 0.0, c, 1
2896 F77_CHAR_ARG_LEN (1)));
2900 const char ctra = get_blas_trans_arg (tra);
2901 const char ctrb = get_blas_trans_arg (trb);
2902 F77_XFCN (sgemm, SGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1),
2903 F77_CONST_CHAR_ARG2 (&ctrb, 1),
2904 a_nr, b_nc, a_nc, 1.0, a.
data (),
2905 lda, b.
data (), ldb, 0.0, c, a_nr
2906 F77_CHAR_ARG_LEN (1)
2907 F77_CHAR_ARG_LEN (1)));
2917 return xgemm (a, b);
2922#define EMPTY_RETURN_CHECK(T) \
2923 if (nr == 0 || nc == 0) \
2929 const bool nanflag =
true;
2930 const bool realabs =
true;
2931 return min (
f, m, nanflag, realabs);
2937 const bool realabs =
true;
2938 return min (
f, m, nanflag, realabs);
2955 result(i, j) = octave::math::min (
f, m(i, j), nanflag, realabs);
2964 const bool nanflag =
true;
2965 const bool realabs =
true;
2966 return min (
f, m, nanflag, realabs);
2972 const bool realabs =
true;
2973 return min (
f, m, nanflag, realabs);
2990 result(i, j) = octave::math::min (m(i, j),
f, nanflag, realabs);
2999 const bool nanflag =
true;
3000 const bool realabs =
true;
3001 return min (a, b, nanflag, realabs);
3007 const bool realabs =
true;
3008 return min (a, b, nanflag, realabs);
3013 const bool nanflag,
const bool realabs)
3019 (*current_liboctave_error_handler)
3020 (
"two-arg min requires same size arguments");
3030 result(i, j) = octave::math::min (a(i, j), b(i, j), nanflag, realabs);
3039 const bool nanflag =
true;
3040 const bool realabs =
true;
3041 return max (
f, m, nanflag, realabs);
3047 const bool realabs =
true;
3048 return max (
f, m, nanflag, realabs);
3065 result(i, j) = octave::math::max (
f, m(i, j), nanflag, realabs);
3074 const bool nanflag =
true;
3075 const bool realabs =
true;
3076 return max (
f, m, nanflag, realabs);
3082 const bool realabs =
true;
3083 return max (
f, m, nanflag, realabs);
3100 result(i, j) = octave::math::max (m(i, j),
f, nanflag, realabs);
3109 const bool nanflag =
true;
3110 const bool realabs =
true;
3111 return max (a, b, nanflag, realabs);
3117 const bool realabs =
true;
3118 return max (a, b, nanflag, realabs);
3123 const bool nanflag,
const bool realabs)
3129 (*current_liboctave_error_handler)
3130 (
"two-arg max requires same size arguments");
3140 result(i, j) = octave::math::max (a(i, j), b(i, j), nanflag, realabs);
3154 if (x2.
numel () != m)
3155 (*current_liboctave_error_handler)
3156 (
"linspace: vectors must be of equal length");
3162 retval.
clear (m, 0);
3166 retval.clear (m, n);
3168 retval.insert (
linspace (x1(i), x2(i), n), i, 0);
base_det< float > FloatDET
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.
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
void resize(octave_idx_type n, const float &rfv=0)
FloatColumnVector extract(octave_idx_type r1, octave_idx_type r2) const
FloatComplexMatrix lssolve(const FloatMatrix &b) const
FloatComplexMatrix solve(MatrixType &mattype, const FloatMatrix &b) const
FloatDiagMatrix inverse() const
FloatColumnVector extract_diag(octave_idx_type k=0) const
boolMatrix any(int dim=-1) const
Matrix dsumsq(int dim=-1, bool nanflag=false) const
FloatMatrix cumprod(int dim=-1, bool nanflag=false) const
FloatMatrix cumsum(int dim=-1, bool nanflag=false) const
bool operator==(const FloatMatrix &a) const
void resize(octave_idx_type nr, octave_idx_type nc, float rfv=0)
FloatColumnVector row_max() const
FloatMatrix lssolve(const FloatMatrix &b) const
FloatComplexMatrix fourier2d() const
friend class FloatComplexMatrix
FloatMatrix & fill(float val)
Matrix dsum(int dim=-1, bool nanflag=false) const
FloatMatrix inverse() const
FloatMatrix & insert(const FloatMatrix &a, octave_idx_type r, octave_idx_type c)
FloatRowVector row(octave_idx_type i) const
FloatMatrix & operator-=(const FloatDiagMatrix &a)
FloatMatrix sumsq(int dim=-1, bool nanflag=false) const
FloatComplexMatrix ifourier2d() const
FloatMatrix & operator+=(const FloatDiagMatrix &a)
FloatComplexMatrix ifourier() const
FloatMatrix solve(MatrixType &mattype, const FloatMatrix &b) const
FloatComplexMatrix fourier() const
FloatRowVector column_min() const
FloatMatrix prod(int dim=-1, bool nanflag=false) const
FloatMatrix flip(int dim=-1) const
Matrix dprod(int dim=-1, bool nanflag=false) const
FloatMatrix append(const FloatMatrix &a) const
FloatRowVector column_max() const
FloatMatrix diag(octave_idx_type k=0) const
bool operator!=(const FloatMatrix &a) const
FloatColumnVector row_min() const
FloatMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
FloatMatrix extract_n(octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
FloatColumnVector column(octave_idx_type i) const
FloatDET determinant() const
FloatMatrix transpose() const
FloatMatrix stack(const FloatMatrix &a) const
FloatMatrix pseudo_inverse(float tol=0.0) const
boolMatrix all(int dim=-1) const
FloatMatrix sum(int dim=-1, bool nanflag=false) const
NDArray dsum(int dim=-1, bool nanflag=false) const
NDArray dprod(int dim=-1, bool nanflag=false) const
FloatNDArray cumsum(int dim=-1, bool nanflag=false) const
NDArray dsumsq(int dim=-1, bool nanflag=false) const
FloatNDArray sumsq(int dim=-1, bool nanflag=false) const
boolNDArray any(int dim=-1) const
boolNDArray all(int dim=-1) const
FloatNDArray & insert(const FloatNDArray &a, octave_idx_type r, octave_idx_type c)
FloatNDArray sum(int dim=-1, bool nanflag=false) const
FloatNDArray flip(int dim=-1) const
FloatNDArray cumprod(int dim=-1, bool nanflag=false) const
FloatNDArray diag(octave_idx_type k=0) const
FloatNDArray prod(int dim=-1, bool nanflag=false) const
void resize(octave_idx_type n, const float &rfv=0)
Template for two dimensional diagonal array with math operators.
void mark_as_unsymmetric()
int type(bool quiet=true)
void mark_as_rectangular()
octave_idx_type rows() const
const Array< octave_idx_type > & col_perm_vec() const
Vector representing the dimensions (size) of an Array.
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
FloatMatrix operator*(const FloatColumnVector &v, const FloatRowVector &a)
FloatMatrix max(float f, const FloatMatrix &m)
FloatMatrix linspace(const FloatColumnVector &x1, const FloatColumnVector &x2, octave_idx_type n)
#define EMPTY_RETURN_CHECK(T)
FloatMatrix real(const FloatComplexMatrix &a)
FloatMatrix imag(const FloatComplexMatrix &a)
std::ostream & operator<<(std::ostream &os, const FloatMatrix &a)
FloatMatrix min(float f, const FloatMatrix &m)
FloatMatrix Givens(float x, float y)
FloatMatrix Sylvester(const FloatMatrix &a, const FloatMatrix &b, const FloatMatrix &c)
FloatMatrix xgemm(const FloatMatrix &a, const FloatMatrix &b, blas_trans_type transa, blas_trans_type transb)
std::istream & operator>>(std::istream &is, FloatMatrix &a)
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
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
char get_blas_char(blas_trans_type transt)
bool mx_inline_equal(std::size_t n, const T1 *x, const T2 *y)
void mx_inline_real(std::size_t n, T *r, const std::complex< T > *x)
void mx_inline_imag(std::size_t n, T *r, const std::complex< T > *x)
#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< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
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 xsdot(n, dx, incx, dy, incy, retval)