Mercurial > octave
changeset 29827:004e63a7a501
xpow.cc: Simplify calculation by using std::pow template where one arg is Complex (bug #60786).
* xpow.cc: Stop checking whether imaginary portion of complex value is 0.0 and
using that information to decide which std::pow template to call. Use std::pow
call where one of the elements is complex and let C++ library figure out which
template to call internally.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 28 Jun 2021 09:34:49 -0700 |
parents | a48151f59b69 |
children | e4c65b8276a6 |
files | libinterp/corefcn/xpow.cc |
diffstat | 1 files changed, 20 insertions(+), 120 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/xpow.cc Mon Jun 28 10:36:25 2021 +0200 +++ b/libinterp/corefcn/xpow.cc Mon Jun 28 09:34:49 2021 -0700 @@ -132,29 +132,9 @@ ComplexColumnVector lambda (b_eig.eigenvalues ()); ComplexMatrix Q (b_eig.right_eigenvectors ()); - if (a < 0.0) - { - Complex acplx (a); - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (acplx, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (a, lambda(i)); + ComplexDiagMatrix D (lambda); ComplexMatrix C = Q * D * Q.inverse (); @@ -201,29 +181,9 @@ ComplexColumnVector lambda (b_eig.eigenvalues ()); ComplexMatrix Q (b_eig.right_eigenvectors ()); - if (a < 0.0) - { - Complex acplx (a); - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (acplx, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (a, lambda(i)); + ComplexDiagMatrix D (lambda); retval = ComplexMatrix (Q * D * Q.inverse ()); @@ -442,13 +402,8 @@ ComplexMatrix Q (b_eig.right_eigenvectors ()); for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } + lambda(i) = std::pow (a, lambda(i)); + ComplexDiagMatrix D (lambda); retval = ComplexMatrix (Q * D * Q.inverse ()); @@ -493,13 +448,8 @@ ComplexMatrix Q (b_eig.right_eigenvectors ()); for (octave_idx_type i = 0; i < nr; i++) - { - Complex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } + lambda(i) = std::pow (a, lambda(i)); + ComplexDiagMatrix D (lambda); retval = ComplexMatrix (Q * D * Q.inverse ()); @@ -1595,29 +1545,9 @@ FloatComplexColumnVector lambda (b_eig.eigenvalues ()); FloatComplexMatrix Q (b_eig.right_eigenvectors ()); - if (a < 0.0) - { - FloatComplex acplx (a); - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (acplx, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (a, lambda(i)); + FloatComplexDiagMatrix D (lambda); FloatComplexMatrix C = Q * D * Q.inverse (); @@ -1665,29 +1595,9 @@ FloatComplexColumnVector lambda (b_eig.eigenvalues ()); FloatComplexMatrix Q (b_eig.right_eigenvectors ()); - if (a < 0.0) - { - FloatComplex acplx (a); - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (acplx, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } - } + for (octave_idx_type i = 0; i < nr; i++) + lambda(i) = std::pow (a, lambda(i)); + FloatComplexDiagMatrix D (lambda); retval = FloatComplexMatrix (Q * D * Q.inverse ()); @@ -1896,13 +1806,8 @@ FloatComplexMatrix Q (b_eig.right_eigenvectors ()); for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } + lambda(i) = std::pow (a, lambda(i)); + FloatComplexDiagMatrix D (lambda); retval = FloatComplexMatrix (Q * D * Q.inverse ()); @@ -1947,13 +1852,8 @@ FloatComplexMatrix Q (b_eig.right_eigenvectors ()); for (octave_idx_type i = 0; i < nr; i++) - { - FloatComplex elt = lambda(i); - if (std::imag (elt) == 0.0) - lambda(i) = std::pow (a, std::real (elt)); - else - lambda(i) = std::pow (a, elt); - } + lambda(i) = std::pow (a, lambda(i)); + FloatComplexDiagMatrix D (lambda); retval = FloatComplexMatrix (Q * D * Q.inverse ());