Mercurial > hg > octave-lyh
changeset 10129:ab80681c44d9
optimize third powers
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 18 Jan 2010 14:14:08 +0100 |
parents | e68431e60e3d |
children | 0c3609dd34cf |
files | src/ChangeLog src/xpow.cc |
diffstat | 2 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-01-18 Jaroslav Hajek <highegg@gmail.com> + + * xpow.cc (xpow (const NDArray&, double), xpow (const FloatNDArray&, + float)): Optimize also the x.^3 case. + 2010-01-18 David Grundberg <davidg@cs.umu.se> * mex.cc (mexPrintf): Change signature.
--- a/src/xpow.cc +++ b/src/xpow.cc @@ -1200,18 +1200,23 @@ } else { - NDArray result (a.dims ()); + NoAlias<NDArray> result (a.dims ()); int ib = static_cast<int> (b); if (ib == 2) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = a(i) * a(i); + result(i) = a(i) * a(i); + } + else if (ib == 3) + { + for (octave_idx_type i = 0; i < a.length (); i++) + result(i) = a(i) * a(i) * a(i); } else if (ib == -1) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = 1.0 / a(i); + result(i) = 1.0 / a(i); } else { @@ -2515,18 +2520,23 @@ } else { - FloatNDArray result (a.dims ()); + NoAlias<FloatNDArray> result (a.dims ()); int ib = static_cast<int> (b); if (ib == 2) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = a(i) * a(i); + result(i) = a(i) * a(i); + } + else if (ib == 3) + { + for (octave_idx_type i = 0; i < a.length (); i++) + result(i) = a(i) * a(i) * a(i); } else if (ib == -1) { for (octave_idx_type i = 0; i < a.length (); i++) - result.xelem (i) = 1.0f / a(i); + result(i) = 1.0f / a(i); } else {