Repository: systemml
Updated Branches:
  refs/heads/master a044ab21d -> f5d97c551


[MINOR] Simplify spark key-value list handling via streams

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

Branch: refs/heads/master
Commit: 25feb997978e990eb5dc11eaaa2dc6ef7af03c61
Parents: a044ab2
Author: Matthias Boehm <mboe...@gmail.com>
Authored: Mon Apr 16 19:31:47 2018 -0700
Committer: Matthias Boehm <mboe...@gmail.com>
Committed: Mon Apr 16 19:31:47 2018 -0700

----------------------------------------------------------------------
 .../instructions/spark/utils/SparkUtils.java    | 28 ++++++--------------
 .../matrix/data/OperationsOnMatrixValues.java   |  7 +++--
 2 files changed, 11 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/25feb997/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/SparkUtils.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/SparkUtils.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/SparkUtils.java
index cdd64f0..49232da 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/SparkUtils.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/SparkUtils.java
@@ -70,40 +70,28 @@ public class SparkUtils
                return new Tuple2<>(in.getIndexes(), 
(MatrixBlock)in.getValue());
        }
 
-       public static ArrayList<Tuple2<MatrixIndexes,MatrixBlock>> 
fromIndexedMatrixBlock( ArrayList<IndexedMatrixValue> in ) {
-               ArrayList<Tuple2<MatrixIndexes,MatrixBlock>> ret = new 
ArrayList<>();
-               for( IndexedMatrixValue imv : in )
-                       ret.add(fromIndexedMatrixBlock(imv));
-               return ret;
+       public static List<Tuple2<MatrixIndexes,MatrixBlock>> 
fromIndexedMatrixBlock( List<IndexedMatrixValue> in ) {
+               return in.stream().map(imv -> 
fromIndexedMatrixBlock(imv)).collect(Collectors.toList());
        }
 
        public static Pair<MatrixIndexes,MatrixBlock> 
fromIndexedMatrixBlockToPair( IndexedMatrixValue in ){
                return new Pair<>(in.getIndexes(), (MatrixBlock)in.getValue());
        }
 
-       public static ArrayList<Pair<MatrixIndexes,MatrixBlock>> 
fromIndexedMatrixBlockToPair( ArrayList<IndexedMatrixValue> in ) {
-               ArrayList<Pair<MatrixIndexes,MatrixBlock>> ret = new 
ArrayList<>();
-               for( IndexedMatrixValue imv : in )
-                       ret.add(fromIndexedMatrixBlockToPair(imv));
-               return ret;
+       public static List<Pair<MatrixIndexes,MatrixBlock>> 
fromIndexedMatrixBlockToPair( List<IndexedMatrixValue> in ) {
+               return in.stream().map(imv -> 
fromIndexedMatrixBlockToPair(imv)).collect(Collectors.toList());
        }
 
        public static Tuple2<Long,FrameBlock> fromIndexedFrameBlock( Pair<Long, 
FrameBlock> in ){
                return new Tuple2<>(in.getKey(), in.getValue());
        }
 
-       public static ArrayList<Tuple2<Long,FrameBlock>> fromIndexedFrameBlock( 
ArrayList<Pair<Long, FrameBlock>> in ) {
-               ArrayList<Tuple2<Long, FrameBlock>> ret = new ArrayList<>();
-               for( Pair<Long, FrameBlock> ifv : in )
-                       ret.add(fromIndexedFrameBlock(ifv));
-               return ret;
+       public static List<Tuple2<Long,FrameBlock>> 
fromIndexedFrameBlock(List<Pair<Long, FrameBlock>> in) {
+               return in.stream().map(ifv -> 
fromIndexedFrameBlock(ifv)).collect(Collectors.toList());
        }
 
-       public static ArrayList<Pair<Long,Long>> toIndexedLong( 
List<Tuple2<Long, Long>> in ) {
-               ArrayList<Pair<Long, Long>> ret = new ArrayList<>();
-               for( Tuple2<Long, Long> e : in )
-                       ret.add(new Pair<>(e._1(), e._2()));
-               return ret;
+       public static List<Pair<Long,Long>> toIndexedLong( List<Tuple2<Long, 
Long>> in ) {
+               return in.stream().map(e -> new Pair<>(e._1(), 
e._2())).collect(Collectors.toList());
        }
 
        public static Pair<Long,FrameBlock> toIndexedFrameBlock( 
Tuple2<Long,FrameBlock> in ) {

http://git-wip-us.apache.org/repos/asf/systemml/blob/25feb997/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java
 
b/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java
index a698e46..1e1c003 100644
--- 
a/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java
+++ 
b/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java
@@ -22,6 +22,7 @@ package org.apache.sysml.runtime.matrix.data;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.sysml.parser.Expression.ValueType;
 import org.apache.sysml.runtime.DMLRuntimeException;
@@ -238,7 +239,7 @@ public class OperationsOnMatrixValues
        }
 
        @SuppressWarnings("rawtypes")
-       public static ArrayList performSlice(IndexRange ixrange, int brlen, int 
bclen, int iix, int jix, CacheBlock in) {
+       public static List performSlice(IndexRange ixrange, int brlen, int 
bclen, int iix, int jix, CacheBlock in) {
                if( in instanceof MatrixBlock )
                        return performSlice(ixrange, brlen, bclen, iix, jix, 
(MatrixBlock)in);
                else if( in instanceof FrameBlock )
@@ -246,13 +247,11 @@ public class OperationsOnMatrixValues
                throw new DMLRuntimeException("Unsupported cache block type: 
"+in.getClass().getName());
        }
        
-       
        @SuppressWarnings("rawtypes")
-       public static ArrayList performSlice(IndexRange ixrange, int brlen, int 
bclen, int iix, int jix, MatrixBlock in) {
+       public static List performSlice(IndexRange ixrange, int brlen, int 
bclen, int iix, int jix, MatrixBlock in) {
                IndexedMatrixValue imv = new IndexedMatrixValue(new 
MatrixIndexes(iix, jix), (MatrixBlock)in);
                ArrayList<IndexedMatrixValue> outlist = new ArrayList<>();
                performSlice(imv, ixrange, brlen, bclen, outlist);
-       
                return SparkUtils.fromIndexedMatrixBlockToPair(outlist);
        }
 

Reply via email to