Mercurial > octave-nkf
diff src/xpow.cc @ 10129:ab80681c44d9
optimize third powers
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 18 Jan 2010 14:14:08 +0100 |
parents | f39b98237d5c |
children | 829e69ec3110 |
line wrap: on
line diff
--- a/src/xpow.cc Mon Jan 18 13:48:13 2010 +0100 +++ b/src/xpow.cc Mon Jan 18 14:14:08 2010 +0100 @@ -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 {