[SYSTEMML-2151] Fix correctness of codegen row powAdd for sparse

This patch fixes the result correctness of the codegen powAdd vector
(primitive as used in codegen row operations) for sparse inputs.
 

Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/5837953e
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/5837953e
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/5837953e

Branch: refs/heads/master
Commit: 5837953e94cc427aaf8207d9c94cea36a50499cf
Parents: de8f2c7
Author: Matthias Boehm <[email protected]>
Authored: Fri Feb 16 00:09:03 2018 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Fri Feb 16 00:09:03 2018 -0800

----------------------------------------------------------------------
 .../apache/sysml/runtime/codegen/LibSpoofPrimitives.java    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/5837953e/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java 
b/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java
index fe34507..bcb2f4d 100644
--- a/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java
+++ b/src/main/java/org/apache/sysml/runtime/codegen/LibSpoofPrimitives.java
@@ -655,15 +655,16 @@ public class LibSpoofPrimitives
        }
 
        public static void vectPowAdd(double[] a, double bval, double[] c, 
int[] aix, int ai, int ci, int alen, int len) {
-               if( bval == 0 ) //handle 0^0=1
+               if( bval == 0 ) //handle 0^0=1 & a^0=1
                        for( int j=0; j<len; j++ )
                                c[ci + j] += 1;
-               for( int j = ai; j < ai+alen; j++ )
-                       c[ci + aix[j]] += Math.pow(a[j], bval) - 1;
+               else //handle 0^b=0 & a^b
+                       for( int j = ai; j < ai+alen; j++ )
+                               c[ci + aix[j]] += Math.pow(a[j], bval);
        }
        
        public static void vectPowAdd(double bval, double[] a, double[] c, 
int[] aix, int ai, int ci, int alen, int len) {
-               for( int j=0; j<len; j++ )
+               for( int j=0; j<len; j++ ) //handle 0^0=1 & b^0=1
                        c[ci + j] += 1;
                for( int j = ai; j < ai+alen; j++ )
                        c[ci + aix[j]] += Math.pow(bval, a[j]) - 1;

Reply via email to