phaniarnab commented on code in PR #1849:
URL: https://github.com/apache/systemds/pull/1849#discussion_r1242347444


##########
src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixBincell.java:
##########
@@ -1423,14 +1402,46 @@ else if( atype == BinaryAccessType.OUTER_VECTOR_VECTOR 
) { //VECTOR - VECTOR
                        }
                        //general case
                        else {
-                               for(int r=rl; r<ru; r++)
-                                       for(int c=0; c<clen; c++) {
-                                               double v1 = m1.quickGetValue(r, 
c);
-                                               double v2 = m2.quickGetValue(r, 
c);
-                                               double v = op.fn.execute( v1, 
v2 );
-                                               ret.appendValuePlain(r, c, v);
-                                               lnnz += (v!=0) ? 1 : 0;
+                               // if ValueFunction is comparison, return 
matrix is true boolean and boolean arithmetics are activated, use boolean 
arithmetics
+                               if (op.fn instanceof ValueComparisonFunction && 
ret.denseBlock != null && (ret.getDenseBlock() instanceof DenseBlockTrueBool || 
ret.getDenseBlock() instanceof DenseBlockBool) ){
+                                       //TODO: Optimize casting to boolean 
denseblock types :/
+                                       if(ret.getDenseBlock() instanceof 
DenseBlockTrueBool){
+                                               for(int r=rl; r<ru; r++)
+                                                       for(int c=0; c<clen; 
c++) {
+                                                               double v1 = 
m1.quickGetValue(r, c);
+                                                               double v2 = 
m2.quickGetValue(r, c);
+                                                               boolean vb = 
((ValueComparisonFunction) op.fn).compare( v1, v2 );
+
+                                                               //react what is 
happening in appendValuePlain()
+                                                               
ret.allocateDenseBlock(false);
+                                                               
((DenseBlockTrueBool) ret.getDenseBlock()).set(r,c,vb);
+                                                               lnnz += vb ? 1 
: 0;
+                                                       }
+                                       } else {
+                                               for(int r=rl; r<ru; r++)
+                                                       for(int c=0; c<clen; 
c++) {
+                                                               double v1 = 
m1.quickGetValue(r, c);
+                                                               double v2 = 
m2.quickGetValue(r, c);
+                                                               boolean vb = 
((ValueComparisonFunction) op.fn).compare( v1, v2 );
+
+                                                               //react what is 
happening in appendValuePlain()
+                                                               
ret.allocateDenseBlock(false);
+                                                               
((DenseBlockBool) ret.getDenseBlock()).set(r,c,vb);
+                                                               lnnz += vb ? 1 
: 0;
+                                                       }
                                        }
+
+                               } else {
+                                       for(int r=rl; r<ru; r++)
+                                               for(int c=0; c<clen; c++) {
+                                                       double v1 = 
m1.quickGetValue(r, c);
+                                                       double v2 = 
m2.quickGetValue(r, c);
+                                                       double v = 
op.fn.execute( v1, v2 );
+                                                       ret.appendValuePlain(r, 
c, v);
+                                                       lnnz += (v!=0) ? 1 : 0;
+                                               }
+                               }
+

Review Comment:
   Can you please take the new code out to a new method and call that method 
from unsafeBinary?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to