This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 65d702afe0 [MINOR] Cleanup unnecessary indirections for matrix block 
operations
65d702afe0 is described below

commit 65d702afe0d38b9292a63c5baa1c305f20d1a929
Author: Matthias Boehm <mboe...@gmail.com>
AuthorDate: Fri May 3 19:35:41 2024 +0200

    [MINOR] Cleanup unnecessary indirections for matrix block operations
---
 .../instructions/spark/CtableSPInstruction.java    |  11 +-
 .../spark/MatrixAppendMSPInstruction.java          |   5 +-
 .../spark/UaggOuterChainSPInstruction.java         |   4 +-
 .../matrix/data/OperationsOnMatrixValues.java      | 156 +--------------------
 4 files changed, 9 insertions(+), 167 deletions(-)

diff --git 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/CtableSPInstruction.java
 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/CtableSPInstruction.java
index f79b86ac61..bfe80c80d7 100644
--- 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/CtableSPInstruction.java
+++ 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/CtableSPInstruction.java
@@ -38,7 +38,6 @@ import 
org.apache.sysds.runtime.instructions.spark.utils.SparkUtils;
 import org.apache.sysds.runtime.matrix.data.CTableMap;
 import org.apache.sysds.runtime.matrix.data.MatrixBlock;
 import org.apache.sysds.runtime.matrix.data.MatrixIndexes;
-import org.apache.sysds.runtime.matrix.data.OperationsOnMatrixValues;
 import org.apache.sysds.runtime.meta.DataCharacteristics;
 import org.apache.sysds.runtime.util.LongLongDoubleHashMap.ADoubleEntry;
 import scala.Tuple2;
@@ -245,13 +244,11 @@ public class CtableSPInstruction extends 
ComputationSPInstruction {
                        //local aggregation of entire partition
                        while( arg0.hasNext() ) {
                                Tuple2<MatrixIndexes,MatrixBlock[]> tmp = 
arg0.next();
-                               MatrixIndexes ix = tmp._1();
                                MatrixBlock[] mb = tmp._2();
                                
                                switch( _ctableOp ) {
                                        case CTABLE_TRANSFORM: {
-                                               
OperationsOnMatrixValues.performCtable(ix, mb[0], ix,
-                                                       mb[1], ix, mb[2], map, 
block, null);
+                                               mb[0].ctableOperations(null, 
mb[1], mb[2], map, block);
                                                break;
                                        }
                                        case CTABLE_EXPAND_SCALAR_WEIGHT:
@@ -261,14 +258,12 @@ public class CtableSPInstruction extends 
ComputationSPInstruction {
                                                break;
                                        }
                                        case CTABLE_TRANSFORM_HISTOGRAM: {
-                                               
OperationsOnMatrixValues.performCtable(ix, mb[0],
-                                                       _scalar_input2, 
_scalar_input3, map, block, null);
+                                               mb[0].ctableOperations(null, 
_scalar_input2, _scalar_input3, map, block);
                                                break;
                                        }
                                        case 
CTABLE_TRANSFORM_WEIGHTED_HISTOGRAM: {
                                                // 2nd and 3rd inputs are 
scalars
-                                               
OperationsOnMatrixValues.performCtable(ix, mb[0],
-                                                       _scalar_input2, ix, 
mb[1], map, block, null);
+                                               mb[0].ctableOperations(null, 
_scalar_input2, mb[1], map, block);
                                                break;
                                        }
                                        default:
diff --git 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/MatrixAppendMSPInstruction.java
 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/MatrixAppendMSPInstruction.java
index bdc98f28fb..68de8c3376 100644
--- 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/MatrixAppendMSPInstruction.java
+++ 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/MatrixAppendMSPInstruction.java
@@ -30,7 +30,6 @@ import 
org.apache.sysds.runtime.instructions.spark.data.PartitionedBroadcast;
 import org.apache.sysds.runtime.instructions.spark.utils.SparkUtils;
 import org.apache.sysds.runtime.matrix.data.MatrixBlock;
 import org.apache.sysds.runtime.matrix.data.MatrixIndexes;
-import org.apache.sysds.runtime.matrix.data.OperationsOnMatrixValues;
 import org.apache.sysds.runtime.matrix.operators.Operator;
 import org.apache.sysds.runtime.meta.DataCharacteristics;
 import scala.Tuple2;
@@ -165,8 +164,8 @@ public class MatrixAppendMSPInstruction extends 
AppendMSPInstruction {
                                                outlist.add(second);
                                        }
                                }
-       
-                               
OperationsOnMatrixValues.performAppend(in1.getValue(), value_in2, outlist, 
_blen, _cbind, true, 0);     
+                               
+                               in1.getValue().append(value_in2, outlist, 
_blen, _cbind, true, 0);
                                
ret.addAll(SparkUtils.fromIndexedMatrixBlock(outlist));
                        }
                        
diff --git 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/UaggOuterChainSPInstruction.java
 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/UaggOuterChainSPInstruction.java
index 9d8f2aa022..766d80158b 100644
--- 
a/src/main/java/org/apache/sysds/runtime/instructions/spark/UaggOuterChainSPInstruction.java
+++ 
b/src/main/java/org/apache/sysds/runtime/instructions/spark/UaggOuterChainSPInstruction.java
@@ -331,8 +331,8 @@ public class UaggOuterChainSPInstruction extends 
BinarySPInstruction {
                                        MatrixValue in2Val = _pbc.getBlock(1, 
bidx);
                                        
                                        //outer block operation
-                                       
OperationsOnMatrixValues.performBinaryIgnoreIndexes(in1Val, in2Val, _tmpVal1, 
_bOp);
-                                               
+                                       in1Val.binaryOperations(_bOp, in2Val, 
_tmpVal1);
+                                       
                                        //unary aggregate operation
                                        
OperationsOnMatrixValues.performAggregateUnary( in1Ix, _tmpVal1, outIx, 
_tmpVal2, _uaggOp, _blen);
                                        
diff --git 
a/src/main/java/org/apache/sysds/runtime/matrix/data/OperationsOnMatrixValues.java
 
b/src/main/java/org/apache/sysds/runtime/matrix/data/OperationsOnMatrixValues.java
index 0134f9fec0..66f7e6317d 100644
--- 
a/src/main/java/org/apache/sysds/runtime/matrix/data/OperationsOnMatrixValues.java
+++ 
b/src/main/java/org/apache/sysds/runtime/matrix/data/OperationsOnMatrixValues.java
@@ -31,175 +31,23 @@ import 
org.apache.sysds.runtime.compress.CompressedMatrixBlock;
 import org.apache.sysds.runtime.controlprogram.caching.CacheBlock;
 import org.apache.sysds.runtime.controlprogram.caching.MatrixObject.UpdateType;
 import org.apache.sysds.runtime.frame.data.FrameBlock;
-import org.apache.sysds.runtime.functionobjects.Builtin;
 import org.apache.sysds.runtime.instructions.spark.data.IndexedMatrixValue;
 import org.apache.sysds.runtime.instructions.spark.utils.SparkUtils;
 import org.apache.sysds.runtime.matrix.operators.AggregateBinaryOperator;
 import org.apache.sysds.runtime.matrix.operators.AggregateOperator;
 import org.apache.sysds.runtime.matrix.operators.AggregateUnaryOperator;
-import org.apache.sysds.runtime.matrix.operators.BinaryOperator;
 import org.apache.sysds.runtime.matrix.operators.Operator;
-import org.apache.sysds.runtime.matrix.operators.ReorgOperator;
 import org.apache.sysds.runtime.util.IndexRange;
 import org.apache.sysds.runtime.util.UtilFunctions;
 
 
 public class OperationsOnMatrixValues 
 {
-       public static void performReorg(MatrixIndexes indexesIn, MatrixValue 
valueIn, MatrixIndexes indexesOut, 
-                       MatrixValue valueOut, ReorgOperator op, int startRow, 
int startColumn, int length) {
-               //operate on the value indexes first
-               op.fn.execute(indexesIn, indexesOut);
-               
-               //operation on the cells inside the value
-               valueIn.reorgOperations(op, valueOut, startRow, startColumn, 
length);
-       }
-
-       public static void performAppend(MatrixValue valueIn1, MatrixValue 
valueIn2,
-                       ArrayList<IndexedMatrixValue> outlist, int blen, 
boolean cbind, boolean m2IsLast, int nextNCol) {
-               valueIn1.append(valueIn2, outlist, blen, cbind, m2IsLast, 
nextNCol);
-       }
-       
-       public static void performZeroOut(MatrixIndexes indexesIn, MatrixValue 
valueIn, 
-                       MatrixIndexes indexesOut, MatrixValue valueOut, 
IndexRange range, boolean complementary) {
-               valueIn.zeroOutOperations(valueOut, range, complementary);
-               indexesOut.setIndexes(indexesIn);
-       }
-       
-       // ------------- Ternary Operations -------------
-       public static void performCtable(MatrixIndexes indexesIn1, MatrixValue 
valueIn1, MatrixIndexes indexesIn2, MatrixValue valueIn2, 
-                       MatrixIndexes indexesIn3, MatrixValue valueIn3, 
CTableMap resultMap, MatrixBlock resultBlock, Operator op ) {
-               //operation on the cells inside the value
-               valueIn1.ctableOperations(op, valueIn2, valueIn3, resultMap, 
resultBlock);
-       }
-       
-       public static void performCtable(MatrixIndexes indexesIn1, MatrixValue 
valueIn1, MatrixIndexes indexesIn2, MatrixValue valueIn2, 
-                       double scalarIn3, CTableMap resultMap, MatrixBlock 
resultBlock, Operator op) {
-               //operation on the cells inside the value
-               valueIn1.ctableOperations(op, valueIn2, scalarIn3, false, 
resultMap, resultBlock);
-       }
-       
-       public static void performCtable(MatrixIndexes indexesIn1, MatrixValue 
valueIn1, double scalarIn2, 
-                       double scalarIn3, CTableMap resultMap, MatrixBlock 
resultBlock, Operator op ) {
-               //operation on the cells inside the value
-               valueIn1.ctableOperations(op, scalarIn2, scalarIn3, resultMap, 
resultBlock);
-       }
-       
-       public static void performCtable(MatrixIndexes indexesIn1, MatrixValue 
valueIn1, double scalarIn2, boolean left,
-                       int blen, CTableMap resultMap, MatrixBlock resultBlock, 
Operator op ) {
-               //operation on the cells inside the value
-               valueIn1.ctableOperations(op, indexesIn1, scalarIn2, left, 
blen, resultMap, resultBlock);
-       }
-       
-       public static void performCtable(MatrixIndexes indexesIn1, MatrixValue 
valueIn1, double scalarIn2, 
-                       MatrixIndexes indexesIn3, MatrixValue valueIn3, 
CTableMap resultMap, MatrixBlock resultBlock, Operator op ) {
-               //operation on the cells inside the value
-               valueIn1.ctableOperations(op, scalarIn2, valueIn3, resultMap, 
resultBlock);
-       }
-       // -----------------------------------------------------
-       
-       //binary operations are those that the indexes of both cells have to be 
matched
-       public static void performBinaryIgnoreIndexes(MatrixValue value1, 
MatrixValue value2, 
-                       MatrixValue valueOut, BinaryOperator op) {
-               value1.binaryOperations(op, value2, valueOut);
-       }
-
-       public static void startAggregation(MatrixValue valueOut, MatrixValue 
correction, AggregateOperator op, 
-                       int rlen, int clen, boolean sparseHint, boolean 
embeddedCorrection) {
-               int outRow=0, outCol=0, corRow=0, corCol=0;
-               if(!embeddedCorrection || op.existsCorrection())
-               {
-                       if( !embeddedCorrection ) {
-                               switch(op.correction)
-                               {
-                               case NONE:
-                                       outRow=rlen;
-                                       outCol=clen;
-                                       corRow=rlen;
-                                       corCol=clen;
-                                       break;
-                               case LASTROW:
-                                       outRow=rlen-1;
-                                       outCol=clen;
-                                       corRow=1;
-                                       corCol=clen;
-                                       break;
-                               case LASTCOLUMN:
-                                       if(op.increOp.fn instanceof Builtin 
-                                          && ( 
((Builtin)(op.increOp.fn)).bFunc == Builtin.BuiltinCode.MAXINDEX 
-                                               || 
((Builtin)(op.increOp.fn)).bFunc == Builtin.BuiltinCode.MININDEX) )
-                                       {
-                                               outRow = rlen;
-                                               outCol = 1;
-                                               corRow = rlen;
-                                               corCol = 1;
-                                       }
-                                       else{
-                                               outRow=rlen;
-                                               outCol=clen-1;
-                                               corRow=rlen;
-                                               corCol=1;
-                                       }
-                                       break;
-                               case LASTTWOROWS:
-                                       outRow=rlen-2;
-                                       outCol=clen;
-                                       corRow=2;
-                                       corCol=clen;
-                                       break;
-                               case LASTTWOCOLUMNS:
-                                       outRow=rlen;
-                                       outCol=clen-2;
-                                       corRow=rlen;
-                                       corCol=2;
-                                       break;
-                               case LASTFOURROWS:
-                                       outRow=rlen-4;
-                                       outCol=clen;
-                                       corRow=4;
-                                       corCol=clen;
-                                       break;
-                               case LASTFOURCOLUMNS:
-                                       outRow=rlen;
-                                       outCol=clen-4;
-                                       corRow=rlen;
-                                       corCol=4;
-                                       break;
-                               default:
-                                               throw new 
DMLRuntimeException("unrecognized correctionLocation: "+op.correction);
-                               }
-                       }else
-                       {
-                               outRow=rlen;
-                               outCol=clen;
-                               corRow=rlen;
-                               corCol=clen;
-                       }
-                       
-                       //set initial values according to operator
-                       if(op.initialValue==0) {
-                               valueOut.reset(Math.max(outRow,0), 
Math.max(outCol,0), sparseHint);
-                               correction.reset(Math.max(corRow,0), 
Math.max(corCol,0), false);
-                       }
-                       else {
-                               valueOut.reset(Math.max(outRow, 0), 
Math.max(outCol,0), op.initialValue);
-                               correction.reset(Math.max(corRow,0), 
Math.max(corCol,0), op.initialValue);
-                       }
-               }
-               else {
-                       if(op.initialValue==0)
-                               valueOut.reset(rlen, clen, sparseHint);
-                       else
-                               valueOut.reset(rlen, clen, op.initialValue);
-               }
-       }
-       
        public static void incrementalAggregation(MatrixValue valueAgg, 
MatrixValue correction, MatrixValue valueAdd, 
                        AggregateOperator op, boolean embeddedCorrection) {
                incrementalAggregation(valueAgg, correction, valueAdd, op, 
embeddedCorrection, true);
        }
        
-       
        public static void incrementalAggregation(MatrixValue valueAgg, 
MatrixValue correction, MatrixValue valueAdd, 
                        AggregateOperator op, boolean embeddedCorrection, 
boolean deep)
        {
@@ -264,7 +112,7 @@ public class OperationsOnMatrixValues
         * @return A List containing pairs of MatrixIndices and CacheBlocks 
either containing MatrixBlock or FrameBlocks
         */
        @SuppressWarnings("rawtypes")
-       public static List performSlice(IndexRange ixrange, int blen, int iix, 
int jix, CacheBlock in) {
+       public static List performSlice(IndexRange ixrange, int blen, int iix, 
int jix, CacheBlock<?> in) {
                if( in instanceof MatrixBlock )
                        return performSlice(ixrange, blen, iix, jix, 
(MatrixBlock)in);
                else if( in instanceof FrameBlock )
@@ -275,7 +123,7 @@ public class OperationsOnMatrixValues
        @SuppressWarnings("rawtypes")
        public static List performSlice(IndexRange ixrange, int blen, int iix, 
int jix, MatrixBlock in) {
                IndexedMatrixValue imv = new IndexedMatrixValue(new 
MatrixIndexes(iix, jix), in);
-               ArrayList<IndexedMatrixValue> outlist = performSlice(imv, 
ixrange, blen);
+               List<IndexedMatrixValue> outlist = performSlice(imv, ixrange, 
blen);
                return SparkUtils.fromIndexedMatrixBlockToPair(outlist);
        }
 

Reply via email to