Mercurial > hg > octave-lojdl
changeset 10144:1b883ce66707
avoid redundant real->complex conversions in xpow
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 20 Jan 2010 12:05:43 +0100 |
parents | f3c34b518422 |
children | fa01c1670b3e |
files | src/ChangeLog src/xpow.cc |
diffstat | 2 files changed, 17 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-01-20 Jaroslav Hajek <highegg@gmail.com> + + * xpow.cc (xpow, elem_xpow): Don't do redundant real->complex + conversions. + 2010-01-20 Jaroslav Hajek <highegg@gmail.com> * data.cc: Substitute OCTAVE_QUIT -> octave_quit ().
--- a/src/xpow.cc +++ b/src/xpow.cc @@ -135,9 +135,7 @@ octave_value xpow (double a, const Complex& b) { - Complex result; - Complex atmp (a); - result = std::pow (atmp, b); + Complex result = std::pow (a, b); return result; } @@ -1152,12 +1150,11 @@ elem_xpow (double a, const ComplexNDArray& b) { ComplexNDArray result (b.dims ()); - Complex atmp (a); for (octave_idx_type i = 0; i < b.length (); i++) { octave_quit (); - result(i) = std::pow (atmp, b(i)); + result(i) = std::pow (a, b(i)); } return result; @@ -1274,8 +1271,7 @@ { octave_quit (); Complex atmp (a(i)); - Complex btmp (b(i)); - complex_result(i) = std::pow (atmp, btmp); + complex_result(i) = std::pow (atmp, b(i)); } retval = complex_result; @@ -1305,7 +1301,7 @@ for (octave_idx_type i = 0; i < a.length (); i++) { octave_quit (); - result(i) = std::pow (Complex (a(i)), b); + result(i) = std::pow (a(i), b); } return result; @@ -1329,7 +1325,7 @@ for (octave_idx_type i = 0; i < a.length (); i++) { octave_quit (); - result(i) = std::pow (Complex (a(i)), b(i)); + result(i) = std::pow (a(i), b(i)); } return result; @@ -1380,7 +1376,7 @@ if (b == -1) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = std::conj (a(i)) / std::norm (a(i)); + result.xelem (i) = 1.0 / a(i); } else { @@ -1552,9 +1548,7 @@ octave_value xpow (float a, const FloatComplex& b) { - FloatComplex result; - FloatComplex atmp (a); - result = std::pow (atmp, b); + FloatComplex result = std::pow (a, b); return result; } @@ -2472,12 +2466,11 @@ elem_xpow (float a, const FloatComplexNDArray& b) { FloatComplexNDArray result (b.dims ()); - FloatComplex atmp (a); for (octave_idx_type i = 0; i < b.length (); i++) { octave_quit (); - result(i) = std::pow (atmp, b(i)); + result(i) = std::pow (a, b(i)); } return result; @@ -2594,8 +2587,7 @@ { octave_quit (); FloatComplex atmp (a(i)); - FloatComplex btmp (b(i)); - complex_result(i) = std::pow (atmp, btmp); + complex_result(i) = std::pow (atmp, b(i)); } retval = complex_result; @@ -2625,7 +2617,7 @@ for (octave_idx_type i = 0; i < a.length (); i++) { octave_quit (); - result(i) = std::pow (FloatComplex (a(i)), b); + result(i) = std::pow (a(i), b); } return result; @@ -2649,7 +2641,7 @@ for (octave_idx_type i = 0; i < a.length (); i++) { octave_quit (); - result(i) = std::pow (FloatComplex (a(i)), b(i)); + result(i) = std::pow (a(i), b(i)); } return result; @@ -2700,7 +2692,7 @@ if (b == -1) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = std::conj (a(i)) / std::norm (a(i)); + result.xelem (i) = 1.0f / a(i); } else {