26#if defined (HAVE_CONFIG_H)
45#include "mx-fcm-fcdm.h"
60err_failed_diagonalization ()
62 error (
"Failed to diagonalize matrix while calculating matrix exponential");
66err_nonsquare_matrix ()
68 error (
"for x^y, only square matrix arguments are permitted and one " \
69 "argument must be scalar. Use .^ for elementwise power.");
76 return (octave::math::x_nint (
x) ==
x
77 &&
x <= std::numeric_limits<int>::max ()
78 &&
x >= std::numeric_limits<int>::min ());
84 static constexpr float out_of_range_top
85 =
static_cast<float> (std::numeric_limits<int>::max ()) + 1.0;
87 return (octave::math::x_nint (
x) ==
x
88 &&
x < out_of_range_top
89 &&
x >= std::numeric_limits<int>::min ());
111 if (a < 0.0 && ! xisint (b))
115 return std::pow (acplx, b);
118 retval = std::pow (a, b);
132 if (nr == 0 || nc == 0)
136 err_nonsquare_matrix ();
146 lambda(i) = std::pow (a, lambda(i));
156 catch (
const octave::execution_exception&)
158 err_failed_diagonalization ();
168 Complex result = std::pow (a, b);
181 if (nr == 0 || nc == 0)
185 err_nonsquare_matrix ();
195 lambda(i) = std::pow (a, lambda(i));
201 catch (
const octave::execution_exception&)
203 err_failed_diagonalization ();
218 if (nr == 0 || nc == 0)
222 err_nonsquare_matrix ();
226 int bint =
static_cast<int> (b);
245 atmp = a.
inverse (mattype, info, rcond, 1);
248 warning (
"inverse: matrix singular to machine precision, rcond = %g", rcond);
262 result = atmp * result;
283 lambda(i) = std::pow (lambda(i), b);
289 catch (
const octave::execution_exception&)
291 err_failed_diagonalization ();
307 if (nr == 0 || nc == 0)
311 err_nonsquare_matrix ();
315 int bint =
static_cast<int> (b);
337 return a.
power (
static_cast<int> (b));
351 if (nr == 0 || nc == 0)
355 err_nonsquare_matrix ();
365 lambda(i) = std::pow (lambda(i), b);
371 catch (
const octave::execution_exception&)
373 err_failed_diagonalization ();
386 result = std::pow (a,
static_cast<int> (b));
388 result = std::pow (a, b);
402 if (nr == 0 || nc == 0)
406 err_nonsquare_matrix ();
416 lambda(i) = std::pow (a, lambda(i));
422 catch (
const octave::execution_exception&)
424 err_failed_diagonalization ();
435 result = std::pow (a, b);
448 if (nr == 0 || nc == 0)
452 err_nonsquare_matrix ();
462 lambda(i) = std::pow (a, lambda(i));
468 catch (
const octave::execution_exception&)
470 err_failed_diagonalization ();
485 if (nr == 0 || nc == 0)
489 err_nonsquare_matrix ();
493 int bint =
static_cast<int> (b);
512 atmp = a.
inverse (mattype, info, rcond, 1);
515 warning (
"inverse: matrix singular to machine precision, rcond = %g", rcond);
529 result = atmp * result;
550 lambda(i) = std::pow (lambda(i), b);
556 catch (
const octave::execution_exception&)
558 err_failed_diagonalization ();
574 if (nr == 0 || nc == 0)
578 err_nonsquare_matrix ();
588 lambda(i) = std::pow (lambda(i), b);
594 catch (
const octave::execution_exception&)
596 err_failed_diagonalization ();
611 if (nr == 0 || nc == 0)
615 err_nonsquare_matrix ();
686 result(i, j) = std::pow (acplx, b(i, j));
699 result(i, j) = std::pow (a, b(i, j));
722 result(i, j) = std::pow (acplx, b(i, j));
729same_sign (
double a,
double b)
731 return (a >= 0 && b >= 0) || (a <= 0 && b <= 0);
741 if (r.numel () > 1 && r.all_elements_are_ints ()
742 && same_sign (r.base (), r.limit ()))
746 if (same_sign (r.base (), r.increment ()))
748 double base = std::pow (a, r.base ());
749 double inc = std::pow (a, r.increment ());
752 result(i) = (base *= inc);
756 double limit = std::pow (a, r.final_value ());
757 double inc = std::pow (a, -r.increment ());
760 result(i) = (limit *= inc);
767 Matrix tmp = r.array_value ();
794 result(i, j) = std::pow (acplx, b);
807 result(i, j) = std::pow (a(i, j), b);
828 if (nr != b_nr || nc != b_nc)
829 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
831 bool convert_to_complex =
false;
836 double atmp = a(i, j);
837 double btmp = b(i, j);
838 if (atmp < 0.0 && ! xisint (btmp))
840 convert_to_complex =
true;
847 if (convert_to_complex)
857 complex_result(i, j) = std::pow (acplx, bcplx);
860 retval = complex_result;
870 result(i, j) = std::pow (a(i, j), b(i, j));
892 result(i, j) = std::pow (
Complex (a(i, j)), b);
908 if (nr != b_nr || nc != b_nc)
909 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
917 result(i, j) = std::pow (
Complex (a(i, j)), b(i, j));
936 double btmp = b(i, j);
938 result(i, j) = std::pow (a,
static_cast<int> (btmp));
940 result(i, j) = std::pow (a, btmp);
959 result(i, j) = std::pow (a, b(i, j));
972 if (r.numel () > 1 && r.all_elements_are_ints ()
973 && same_sign (r.base (), r.limit ()))
978 if (same_sign (r.base (), r.increment ()))
980 Complex base = std::pow (a, r.base ());
981 Complex inc = std::pow (a, r.increment ());
984 result(i) = (base *= inc);
988 Complex limit = std::pow (a, r.final_value ());
989 Complex inc = std::pow (a, -r.increment ());
992 result(i) = (limit *= inc);
999 Matrix tmp = r.array_value ();
1017 int bint =
static_cast<int> (b);
1022 result(i, j) = std::pow (a(i, j), bint);
1031 result(i, j) = std::pow (a(i, j), b);
1048 if (nr != b_nr || nc != b_nc)
1049 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
1057 double btmp = b(i, j);
1059 result(i, j) = std::pow (a(i, j),
static_cast<int> (btmp));
1061 result(i, j) = std::pow (a(i, j), btmp);
1080 result(i, j) = std::pow (a(i, j), b);
1096 if (nr != b_nr || nc != b_nc)
1097 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
1105 result(i, j) = std::pow (a(i, j), b(i, j));
1152 result(i) = std::pow (acplx, b(i));
1163 result(i) = std::pow (a, b(i));
1181 result(i) = std::pow (a, b(i));
1197 int bint =
static_cast<int> (b);
1201 result.
xelem (i) = a(i) * a(i);
1206 result.
xelem (i) = a(i) * a(i) * a(i);
1208 else if (bint == -1)
1211 result.
xelem (i) = 1.0 / a(i);
1218 result.
xelem (i) = std::pow (a(i), bint);
1234 result(i) = std::pow (acplx, b);
1245 result(i) = std::pow (a(i), b);
1264 if (a_dims != b_dims)
1267 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
1280 bool convert_to_complex =
false;
1287 if (atmp < 0.0 && ! xisint (btmp))
1289 convert_to_complex =
true;
1296 if (convert_to_complex)
1304 complex_result(i) = std::pow (acplx, b(i));
1307 retval = complex_result;
1316 result(i) = std::pow (a(i), b(i));
1334 result(i) = std::pow (a(i), b);
1347 if (a_dims != b_dims)
1350 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
1360 result(i) = std::pow (a(i), b(i));
1377 result(i) = std::pow (a,
static_cast<int> (btmp));
1379 result(i) = std::pow (a, btmp);
1394 result(i) = std::pow (a, b(i));
1408 int bint =
static_cast<int> (b);
1412 result.
xelem (i) = 1.0 / a(i);
1419 result(i) = std::pow (a(i), bint);
1428 result(i) = std::pow (a(i), b);
1442 if (a_dims != b_dims)
1445 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
1457 result(i) = std::pow (a(i),
static_cast<int> (btmp));
1459 result(i) = std::pow (a(i), btmp);
1474 result(i) = std::pow (a(i), b);
1487 if (a_dims != b_dims)
1490 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
1500 result(i) = std::pow (a(i), b(i));
1525 if (a < 0.0 && ! xisint (b))
1529 return std::pow (acplx, b);
1532 retval = std::pow (a, b);
1546 if (nr == 0 || nc == 0)
1550 err_nonsquare_matrix ();
1560 lambda(i) = std::pow (a, lambda(i));
1571 catch (
const octave::execution_exception&)
1573 err_failed_diagonalization ();
1596 if (nr == 0 || nc == 0)
1600 err_nonsquare_matrix ();
1610 lambda(i) = std::pow (a, lambda(i));
1616 catch (
const octave::execution_exception&)
1618 err_failed_diagonalization ();
1633 if (nr == 0 || nc == 0)
1637 err_nonsquare_matrix ();
1641 int bint =
static_cast<int> (b);
1660 atmp = a.
inverse (mattype, info, rcond, 1);
1663 warning (
"inverse: matrix singular to machine precision, rcond = %g", rcond);
1677 result = atmp * result;
1698 lambda(i) = std::pow (lambda(i), b);
1704 catch (
const octave::execution_exception&)
1706 err_failed_diagonalization ();
1722 if (nr == 0 || nc == 0)
1726 err_nonsquare_matrix ();
1730 int bint =
static_cast<int> (b);
1756 if (nr == 0 || nc == 0)
1760 err_nonsquare_matrix ();
1770 lambda(i) = std::pow (lambda(i), b);
1776 catch (
const octave::execution_exception&)
1778 err_failed_diagonalization ();
1791 result = std::pow (a,
static_cast<int> (b));
1793 result = std::pow (a, b);
1807 if (nr == 0 || nc == 0)
1811 err_nonsquare_matrix ();
1821 lambda(i) = std::pow (a, lambda(i));
1827 catch (
const octave::execution_exception&)
1829 err_failed_diagonalization ();
1840 result = std::pow (a, b);
1853 if (nr == 0 || nc == 0)
1857 err_nonsquare_matrix ();
1867 lambda(i) = std::pow (a, lambda(i));
1873 catch (
const octave::execution_exception&)
1875 err_failed_diagonalization ();
1890 if (nr == 0 || nc == 0)
1894 err_nonsquare_matrix ();
1898 int bint =
static_cast<int> (b);
1917 atmp = a.
inverse (mattype, info, rcond, 1);
1920 warning (
"inverse: matrix singular to machine precision, rcond = %g", rcond);
1934 result = atmp * result;
1955 lambda(i) = std::pow (lambda(i), b);
1961 catch (
const octave::execution_exception&)
1963 err_failed_diagonalization ();
1979 if (nr == 0 || nc == 0)
1983 err_nonsquare_matrix ();
1993 lambda(i) = std::pow (lambda(i), b);
1999 catch (
const octave::execution_exception&)
2001 err_failed_diagonalization ();
2016 if (nr == 0 || nc == 0)
2020 err_nonsquare_matrix ();
2091 result(i, j) = std::pow (acplx, b(i, j));
2104 result(i, j) = std::pow (a, b(i, j));
2127 result(i, j) = std::pow (acplx, b(i, j));
2153 result(i, j) = std::pow (acplx, b);
2166 result(i, j) = std::pow (a(i, j), b);
2187 if (nr != b_nr || nc != b_nc)
2188 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
2190 bool convert_to_complex =
false;
2195 float atmp = a(i, j);
2196 float btmp = b(i, j);
2197 if (atmp < 0.0 && ! xisint (btmp))
2199 convert_to_complex =
true;
2206 if (convert_to_complex)
2216 complex_result(i, j) = std::pow (acplx, bcplx);
2219 retval = complex_result;
2229 result(i, j) = std::pow (a(i, j), b(i, j));
2267 if (nr != b_nr || nc != b_nc)
2268 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
2276 result(i, j) = std::pow (
FloatComplex (a(i, j)), b(i, j));
2295 float btmp = b(i, j);
2297 result(i, j) = std::pow (a,
static_cast<int> (btmp));
2299 result(i, j) = std::pow (a, btmp);
2318 result(i, j) = std::pow (a, b(i, j));
2335 int bint =
static_cast<int> (b);
2340 result(i, j) = std::pow (a(i, j), bint);
2349 result(i, j) = std::pow (a(i, j), b);
2366 if (nr != b_nr || nc != b_nc)
2367 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
2375 float btmp = b(i, j);
2377 result(i, j) = std::pow (a(i, j),
static_cast<int> (btmp));
2379 result(i, j) = std::pow (a(i, j), btmp);
2398 result(i, j) = std::pow (a(i, j), b);
2414 if (nr != b_nr || nc != b_nc)
2415 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
2423 result(i, j) = std::pow (a(i, j), b(i, j));
2470 result(i) = std::pow (acplx, b(i));
2481 result(i) = std::pow (a, b(i));
2499 result(i) = std::pow (a, b(i));
2515 int bint =
static_cast<int> (b);
2519 result.
xelem (i) = a(i) * a(i);
2524 result.
xelem (i) = a(i) * a(i) * a(i);
2526 else if (bint == -1)
2529 result.
xelem (i) = 1.0f / a(i);
2536 result.
xelem (i) = std::pow (a(i), bint);
2554 result(i) = std::pow (acplx, b);
2565 result(i) = std::pow (a(i), b);
2584 if (a_dims != b_dims)
2587 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
2600 bool convert_to_complex =
false;
2607 if (atmp < 0.0 && ! xisint (btmp))
2609 convert_to_complex =
true;
2616 if (convert_to_complex)
2624 complex_result(i) = std::pow (acplx, b(i));
2627 retval = complex_result;
2636 result(i) = std::pow (a(i), b(i));
2654 result(i) = std::pow (a(i), b);
2667 if (a_dims != b_dims)
2670 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
2680 result(i) = std::pow (a(i), b(i));
2697 result(i) = std::pow (a,
static_cast<int> (btmp));
2699 result(i) = std::pow (a, btmp);
2714 result(i) = std::pow (a, b(i));
2728 int bint =
static_cast<int> (b);
2732 result.
xelem (i) = 1.0f / a(i);
2739 result(i) = std::pow (a(i), bint);
2748 result(i) = std::pow (a(i), b);
2762 if (a_dims != b_dims)
2765 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
2777 result(i) = std::pow (a(i),
static_cast<int> (btmp));
2779 result(i) = std::pow (a(i), btmp);
2794 result(i) = std::pow (a(i), b);
2807 if (a_dims != b_dims)
2810 octave::err_nonconformant (
"operator .^", a_dims, b_dims);
2820 result(i) = std::pow (a(i), b(i));
2826OCTAVE_END_NAMESPACE(octave)
ComplexNDArray bsxfun_pow(const ComplexNDArray &x, const ComplexNDArray &y)
bool is_valid_bsxfun(const std::string &name, const dim_vector &xdv, const dim_vector &ydv)
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type rows() const
octave_idx_type cols() const
octave_idx_type numel() const
Number of elements in the array.
ComplexDiagMatrix inverse(octave_idx_type &info) const
ComplexMatrix inverse() const
octave_idx_type rows() const
octave_idx_type cols() const
T & dgxelem(octave_idx_type i)
ComplexColumnVector eigenvalues() const
ComplexMatrix right_eigenvectors() const
FloatComplexDiagMatrix inverse(octave_idx_type &info) const
FloatComplexMatrix inverse() const
FloatComplexMatrix right_eigenvectors() const
FloatComplexColumnVector eigenvalues() const
FloatMatrix inverse() const
bool any_element_is_negative(bool=false) const
bool all_integers(float &max_val, float &min_val) const
bool all_integers(double &max_val, double &min_val) const
bool any_element_is_negative(bool=false) const
PermMatrix power(octave_idx_type n) const
Vector representing the dimensions (size) of an Array.
ColumnVector real(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
void error(const char *fmt,...)
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Q
F77_RET_T const F77_DBLE * x
std::complex< double > Complex
std::complex< float > FloatComplex
NDArray octave_value_extract< NDArray >(const octave_value &v)
FloatNDArray octave_value_extract< FloatNDArray >(const octave_value &v)
octave_value elem_xpow(double a, const Matrix &b)
octave_value xpow(double a, double b)