26#if defined (HAVE_CONFIG_H)
60 return (octave::math::is_integer (
x)
61 && ((
x >= 0 &&
x < std::numeric_limits<int>::max ())
62 || (x <= 0 && x > std::numeric_limits<int>::min ())));
70xpow_private (
const T& a,
double b)
77 if (nr == 0 || nc == 0)
82 error (
"for A^b, A must be a square matrix. Use .^ for elementwise power.");
85 error (
"use full(a) ^ full(b)");
87 int btmp =
static_cast<int> (b);
117 atmp = a.inverse (mattyp, info, rcond, 1);
120 warning (
"inverse: matrix singular to machine precision, rcond = %g", rcond);
125 if (atmp.nnz () == 0)
155 uint64_t sparsity = atmp.numel () / atmp.nnz ();
156 int threshold = (sparsity >= 1000) ? 40
157 : (sparsity >= 100) ? 20
160 if (btmp > threshold)
165 result = result * atmp;
175 for (
int i = 0; i < btmp; i++)
176 result = result * atmp;
188 return xpow_private<SparseMatrix> (a, b);
194 return xpow_private<SparseComplexMatrix> (a, b);
232template <
typename S,
typename SM>
294 result(i, j) = std::pow (atmp, b(i, j));
309 result(i, j) = std::pow (a, b(i, j));
334 result(i, j) = std::pow (atmp, b(i, j));
366 result(a.
ridx (i), j) = std::pow (a.
data (i), b);
373 Matrix result (nr, nc, (std::pow (0.0, b)));
379 result(a.
ridx (i), j) = std::pow (a.
data (i), b);
392 result.
data (i) = std::pow (a.
data (i), b);
406 result.
data (i) = std::pow (a.
data (i), b);
432 if (nr != b_nr || nc != b_nc)
433 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
435 int convert_to_complex = 0;
441 double btmp = b (a.
ridx (i), j);
444 convert_to_complex = 1;
457 if (convert_to_complex)
471 retval = complex_result;
534 if (nr != b_nr || nc != b_nc)
535 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
566 double btmp = b (i, j);
568 result (i, j) = std::pow (a,
static_cast<int> (btmp));
570 result (i, j) = std::pow (a, btmp);
589 result (i, j) = std::pow (a, b (i, j));
614 result (a.
ridx (i), j)
615 = std::pow (a.
data (i),
static_cast<int> (b));
624 result (a.
ridx (i), j) = std::pow (a.
data (i), b);
641 result.
data (i) = std::pow (a.
data (i),
static_cast<int> (b));
649 result.
data (i) = std::pow (a.
data (i), b);
674 if (nr != b_nr || nc != b_nc)
675 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
683 double btmp = b(a.
ridx (i), j);
687 static_cast<int> (btmp));
717 result.
data (i) = std::pow (a.
data (i), b);
741 if (nr != b_nr || nc != b_nc)
742 octave::err_nonconformant (
"operator .^", nr, nc, b_nr, b_nc);
760OCTAVE_END_NAMESPACE(octave)
bool all_integers(double &max_val, double &min_val) const
bool any_element_is_negative(bool=false) const
octave_idx_type cols() const
octave_idx_type numel() const
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
T & xelem(octave_idx_type n)
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
Matrix matrix_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
void error(const char *fmt,...)
std::complex< double > Complex
F77_RET_T const F77_DBLE * x
octave_value xpow(const SparseMatrix &a, double b)
octave_value elem_xpow(double a, const SparseMatrix &b)
octave_value scalar_xpow(const S &a, const SM &b)