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	Mon Jan 18 13:48:13 2010 +0100
+++ b/src/ChangeLog	Mon Jan 18 14:14:08 2010 +0100
@@ -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	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
         {