[SYSTEMML-1357] Fix value type promotion scalar-scalar operations This patch fixes various inconsistencies of value type promotion for scalar-scalar binary operations as shown up recently on sanity tests that were not included in our testsuite. Furthermore, this also includes a rework of all function and scalar objects to (1) force proper implementation of subclasses (e.g., comparison and index functions), (2) remove unnecessary redundancy (e.g., double-long execute, cloning, language-depending string handling), and (3) remove unnecessary exception handling. Finally, we now also include the problematic testcase in our testsuite by referencing the current data generation and algorithm scripts.
Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/693afd41 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/693afd41 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/693afd41 Branch: refs/heads/master Commit: 693afd414b69b3e550930b4d96d3ef09f932a768 Parents: 770c34b Author: Matthias Boehm <mboe...@gmail.com> Authored: Tue Feb 28 22:57:03 2017 -0800 Committer: Matthias Boehm <mboe...@gmail.com> Committed: Wed Mar 1 10:08:49 2017 -0800 ---------------------------------------------------------------------- .../sysml/runtime/functionobjects/And.java | 7 -- .../sysml/runtime/functionobjects/Builtin.java | 11 +- .../sysml/runtime/functionobjects/CM.java | 5 - .../sysml/runtime/functionobjects/COV.java | 9 +- .../sysml/runtime/functionobjects/CTable.java | 6 -- .../runtime/functionobjects/DiagIndex.java | 11 +- .../sysml/runtime/functionobjects/Divide.java | 17 ---- .../sysml/runtime/functionobjects/Equals.java | 25 +---- .../runtime/functionobjects/FileFunction.java | 3 +- .../runtime/functionobjects/FunctionObject.java | 94 ++++------------- .../runtime/functionobjects/GreaterThan.java | 22 ++-- .../functionobjects/GreaterThanEquals.java | 22 ++-- .../runtime/functionobjects/IndexFunction.java | 20 +++- .../runtime/functionobjects/IntegerDivide.java | 14 --- .../runtime/functionobjects/KahanPlus.java | 5 - .../runtime/functionobjects/KahanPlusSq.java | 5 - .../sysml/runtime/functionobjects/LessThan.java | 17 +--- .../runtime/functionobjects/LessThanEquals.java | 19 +--- .../sysml/runtime/functionobjects/Mean.java | 5 - .../sysml/runtime/functionobjects/Minus.java | 17 ---- .../runtime/functionobjects/Minus1Multiply.java | 16 --- .../runtime/functionobjects/MinusMultiply.java | 15 --- .../sysml/runtime/functionobjects/MinusNz.java | 14 +-- .../sysml/runtime/functionobjects/Modulus.java | 22 +--- .../sysml/runtime/functionobjects/Multiply.java | 16 --- .../runtime/functionobjects/Multiply2.java | 16 --- .../sysml/runtime/functionobjects/Not.java | 6 -- .../runtime/functionobjects/NotEquals.java | 19 +--- .../functionobjects/OffsetColumnIndex.java | 10 +- .../sysml/runtime/functionobjects/Or.java | 7 -- .../functionobjects/ParameterizedBuiltin.java | 5 - .../sysml/runtime/functionobjects/Plus.java | 19 +--- .../runtime/functionobjects/PlusMultiply.java | 15 --- .../sysml/runtime/functionobjects/Power.java | 15 --- .../sysml/runtime/functionobjects/Power2.java | 16 --- .../runtime/functionobjects/ReduceAll.java | 13 +-- .../runtime/functionobjects/ReduceCol.java | 10 +- .../runtime/functionobjects/ReduceDiag.java | 10 +- .../runtime/functionobjects/ReduceRow.java | 10 +- .../runtime/functionobjects/RemoveFile.java | 7 -- .../runtime/functionobjects/RenameFile.java | 6 -- .../sysml/runtime/functionobjects/RevIndex.java | 26 ++--- .../runtime/functionobjects/SortIndex.java | 30 ++++-- .../runtime/functionobjects/SwapIndex.java | 11 +- .../ValueComparisonFunction.java | 39 ++++++++ .../runtime/functionobjects/ValueFunction.java | 3 +- .../cp/ArithmeticBinaryCPInstruction.java | 71 ++----------- .../instructions/cp/BinaryCPInstruction.java | 9 ++ .../runtime/instructions/cp/BooleanObject.java | 22 +--- .../cp/BuiltinBinaryCPInstruction.java | 24 ++--- .../runtime/instructions/cp/DoubleObject.java | 6 -- .../runtime/instructions/cp/IntObject.java | 16 +-- .../cp/RelationalBinaryCPInstruction.java | 26 ++--- .../cp/ScalarBuiltinCPInstruction.java | 10 +- .../runtime/instructions/cp/ScalarObject.java | 16 ++- .../cp/ScalarScalarArithmeticCPInstruction.java | 81 ++++----------- .../cp/ScalarScalarBuiltinCPInstruction.java | 69 +++---------- .../cp/ScalarScalarRelationalCPInstruction.java | 54 +++------- .../runtime/instructions/cp/StringObject.java | 18 +--- .../misc/UnivariateStatsBasicTest.java | 100 +++++++++++++++++++ 60 files changed, 377 insertions(+), 855 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/And.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/And.java b/src/main/java/org/apache/sysml/runtime/functionobjects/And.java index 79f4782..2d183aa 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/And.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/And.java @@ -23,7 +23,6 @@ import java.io.Serializable; public class And extends ValueFunction implements Serializable { - private static final long serialVersionUID = 6523146102263905602L; private static And singleObj = null; @@ -37,15 +36,9 @@ public class And extends ValueFunction implements Serializable singleObj = new And(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public boolean execute(boolean in1, boolean in2) { return in1 && in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Builtin.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Builtin.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Builtin.java index 9673f47..41388a1 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Builtin.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Builtin.java @@ -270,12 +270,8 @@ public class Builtin extends ValueFunction return null; } } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } + @Override public double execute (double in) throws DMLRuntimeException { @@ -321,6 +317,7 @@ public class Builtin extends ValueFunction } } + @Override public double execute (long in) throws DMLRuntimeException { return execute((double)in); } @@ -328,6 +325,7 @@ public class Builtin extends ValueFunction /* * Builtin functions with two inputs */ + @Override public double execute (double in1, double in2) throws DMLRuntimeException { switch(bFunc) { @@ -424,6 +422,7 @@ public class Builtin extends ValueFunction } } + @Override public double execute (long in1, long in2) throws DMLRuntimeException { switch(bFunc) { @@ -456,7 +455,7 @@ public class Builtin extends ValueFunction } } - // currently, it is used only for PRINT, PRINTF and STOP + @Override public String execute (String in1) throws DMLRuntimeException { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/CM.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/CM.java b/src/main/java/org/apache/sysml/runtime/functionobjects/CM.java index 10b6e0d..a27e515 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/CM.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/CM.java @@ -74,11 +74,6 @@ public class CM extends ValueFunction //execution due to state in cm object (buff2, buff3) return new CM( type ); } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } public AggregateOperationTypes getAggOpType() { return _type; http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/COV.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/COV.java b/src/main/java/org/apache/sysml/runtime/functionobjects/COV.java index 5e8dac1..eb5148b 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/COV.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/COV.java @@ -35,7 +35,6 @@ import org.apache.sysml.runtime.instructions.cp.KahanObject; */ public class COV extends ValueFunction { - private static final long serialVersionUID = 1865050401811477181L; private static COV singleObj = null; @@ -48,16 +47,10 @@ public class COV extends ValueFunction return singleObj; } - private COV() - { + private COV() { _plus = KahanPlus.getKahanPlusFnObject(); } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /** * General case for arbitrary weights w2 * http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/CTable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/CTable.java b/src/main/java/org/apache/sysml/runtime/functionobjects/CTable.java index f46bff2..31cdce8 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/CTable.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/CTable.java @@ -28,7 +28,6 @@ import org.apache.sysml.runtime.util.UtilFunctions; public class CTable extends ValueFunction { - private static final long serialVersionUID = -5374880447194177236L; private static CTable singleObj = null; @@ -42,11 +41,6 @@ public class CTable extends ValueFunction singleObj = new CTable(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } public void execute(double v1, double v2, double w, boolean ignoreZeros, CTableMap resultMap) throws DMLRuntimeException http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/DiagIndex.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/DiagIndex.java b/src/main/java/org/apache/sysml/runtime/functionobjects/DiagIndex.java index 685a488..53f7bf8 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/DiagIndex.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/DiagIndex.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -42,11 +41,6 @@ public class DiagIndex extends IndexFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public void execute(MatrixIndexes in, MatrixIndexes out) { //only used for V2M @@ -68,13 +62,12 @@ public class DiagIndex extends IndexFunction return false; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { if( in.getCols() == 1 ) //diagV2M out.set(in.getRows(), in.getRows(), in.getRowsPerBlock(), in.getRowsPerBlock()); else //diagM2V out.set(in.getRows(), 1, in.getRowsPerBlock(), in.getRowsPerBlock()); return false; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Divide.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Divide.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Divide.java index 29412d5..4461ab6 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Divide.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Divide.java @@ -21,7 +21,6 @@ package org.apache.sysml.runtime.functionobjects; public class Divide extends ValueFunction { - private static final long serialVersionUID = -5377082529324612637L; private static Divide singleObj = null; @@ -35,11 +34,6 @@ public class Divide extends ValueFunction singleObj = new Divide(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public double execute(double in1, double in2) { @@ -47,18 +41,7 @@ public class Divide extends ValueFunction } @Override - public double execute(double in1, long in2) { - return in1 / (double)in2; - } - - @Override - public double execute(long in1, double in2) { - return (double)in1 / in2; - } - - @Override public double execute(long in1, long in2) { return (double)in1 / (double)in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Equals.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Equals.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Equals.java index 2802bb4..7ba4b21 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Equals.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Equals.java @@ -19,9 +19,9 @@ package org.apache.sysml.runtime.functionobjects; -public class Equals extends ValueFunction -{ +public class Equals extends ValueComparisonFunction +{ private static final long serialVersionUID = -8887713112454357802L; private static Equals singleObj = null; @@ -35,11 +35,6 @@ public class Equals extends ValueFunction singleObj = new Equals(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of @@ -47,7 +42,7 @@ public class Equals extends ValueFunction * NaN and -0.0 are handled. The behavior of methods in * <code>Double</code> class are designed mainly to make Java * collections work properly. For more details, see the help for - * <code>Double.equals()</code> and <code>Double.comapreTo()</code>. + * <code>Double.equals()</code> and <code>Double.compareTo()</code>. */ /** @@ -61,11 +56,6 @@ public class Equals extends ValueFunction } @Override - public boolean compare(boolean in1, boolean in2) { - return (in1 == in2); - } - - @Override public boolean compare(double in1, double in2) { return (in1 == in2); } @@ -74,18 +64,13 @@ public class Equals extends ValueFunction public boolean compare(long in1, long in2) { return (in1 == in2); } - + @Override - public boolean compare(double in1, long in2) { + public boolean compare(boolean in1, boolean in2) { return (in1 == in2); } @Override - public boolean compare(long in1, double in2) { - return (in1 == in2); - } - - @Override public boolean compare(String in1, String in2) { return ( in1!=null && in1.equals(in2) ); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/FileFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/FileFunction.java b/src/main/java/org/apache/sysml/runtime/functionobjects/FileFunction.java index de795ec..278e01d 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/FileFunction.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/FileFunction.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -public class FileFunction extends FunctionObject { +public abstract class FileFunction extends FunctionObject { - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/FunctionObject.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/FunctionObject.java b/src/main/java/org/apache/sysml/runtime/functionobjects/FunctionObject.java index c576a1b..d18e758 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/FunctionObject.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/FunctionObject.java @@ -23,29 +23,22 @@ import java.util.HashMap; import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.instructions.cp.Data; -import org.apache.sysml.runtime.matrix.MatrixCharacteristics; -import org.apache.sysml.runtime.matrix.data.MatrixIndexes; -import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; -public class FunctionObject +public abstract class FunctionObject { + @Override + public final Object clone() throws CloneNotSupportedException { + // cloning is not supported for singleton classes + throw new CloneNotSupportedException(); + } + + //basic execute methods for all function objects - /* - * execute() methods related to ValueFunctions - */ public double execute ( double in1, double in2 ) throws DMLRuntimeException { throw new DMLRuntimeException("FunctionObject.execute(double,double): should never get called in the base class"); } - public double execute ( double in1, long in2 ) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(double,int): should never get called in the base class"); - } - - public double execute ( long in1, double in2 ) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(int,double): should never get called in the base class"); - } - public double execute ( long in1, long in2 ) throws DMLRuntimeException { throw new DMLRuntimeException("FunctionObject.execute(int,int): should never get called in the base class"); } @@ -70,65 +63,6 @@ public class FunctionObject public double execute ( HashMap<String,String> params ) throws DMLRuntimeException { throw new DMLRuntimeException("FunctionObject.execute(HashMap<String,String> params): should never get called in the base class"); } - - - /* - * execute() methods related to IndexFunctions - */ - public void execute(MatrixIndexes in, MatrixIndexes out) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(MatrixIndexes,MatrixIndexes): should never get called in the base class"); - } - - public void execute(CellIndex in, CellIndex out) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(CellIndex,CellIndex): should never get called in the base class"); - } - - //return whether dimension has been reduced - public boolean computeDimension(int row, int col, CellIndex retDim) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(int,int,CellIndex): should never get called in the base class"); - } - - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException{ - throw new DMLRuntimeException("computeDimension(MatrixCharacteristics in, MatrixCharacteristics out): should never get called in the base class"); - } - - /* - * execute() methods related to FileFunctions (rm, mv) - */ - public String execute ( String in1 ) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(String): should never get called in the base class"); - } - - public String execute ( String in1, String in2 ) throws DMLRuntimeException { - throw new DMLRuntimeException("FunctionObject.execute(String,String): should never get called in the base class"); - } - - /* - * compare() methods related to ValueFunctions (relational operators) - */ - public boolean compare(double in1, double in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } - - public boolean compare(long in1, long in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } - - public boolean compare(double in1, long in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } - - public boolean compare(long in1, double in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } - - public boolean compare(boolean in1, boolean in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } - - public boolean compare(String in1, String in2) throws DMLRuntimeException { - throw new DMLRuntimeException("compare(): should not be invoked from base class."); - } ///////////////////////////////////////////////////////////////////////////////////// @@ -147,5 +81,17 @@ public class FunctionObject public Data execute(Data in1, Data in2) throws DMLRuntimeException { throw new DMLRuntimeException("execute(): should not be invoked from base class."); } + + ///////////////////////////////////////////////////////////////////////////////////// + /* + * For file functions and specific builtin functions + */ + public String execute ( String in1 ) throws DMLRuntimeException { + throw new DMLRuntimeException("FileFunction.execute(String): should never get called in the base class"); + } + + public String execute ( String in1, String in2 ) throws DMLRuntimeException { + throw new DMLRuntimeException("FileFunction.execute(String,String): should never get called in the base class"); + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThan.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThan.java b/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThan.java index 7401cd7..fe350d7 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThan.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThan.java @@ -19,9 +19,9 @@ package org.apache.sysml.runtime.functionobjects; -public class GreaterThan extends ValueFunction -{ +public class GreaterThan extends ValueComparisonFunction +{ private static final long serialVersionUID = 1408566061111937556L; private static GreaterThan singleObj = null; @@ -35,12 +35,7 @@ public class GreaterThan extends ValueFunction singleObj = new GreaterThan(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - + /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of * <code>Double.compare()</code> due to the inconsistencies in the way @@ -71,15 +66,10 @@ public class GreaterThan extends ValueFunction } @Override - public boolean compare(double in1, long in2) { - return (in1 > in2); + public boolean compare(boolean in1, boolean in2) { + return (in1 && !in2); } - - @Override - public boolean compare(long in1, double in2) { - return (in1 > in2); - } - + @Override public boolean compare(String in1, String in2) { return (in1!=null && in1.compareTo(in2)>0 ); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThanEquals.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThanEquals.java b/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThanEquals.java index cca6b46..b2809de 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThanEquals.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/GreaterThanEquals.java @@ -19,9 +19,9 @@ package org.apache.sysml.runtime.functionobjects; -public class GreaterThanEquals extends ValueFunction -{ +public class GreaterThanEquals extends ValueComparisonFunction +{ private static final long serialVersionUID = -5444900552418046584L; private static GreaterThanEquals singleObj = null; @@ -35,11 +35,6 @@ public class GreaterThanEquals extends ValueFunction singleObj = new GreaterThanEquals(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of @@ -69,15 +64,10 @@ public class GreaterThanEquals extends ValueFunction public boolean compare(long in1, long in2) { return (in1 >= in2); } - - @Override - public boolean compare(double in1, long in2) { - return (in1 >= in2); - } - - @Override - public boolean compare(long in1, double in2) { - return (in1 >= in2); + + @Override + public boolean compare(boolean in1, boolean in2) { + return (in1 && !in2) || (in1 == in2); } @Override http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/IndexFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/IndexFunction.java b/src/main/java/org/apache/sysml/runtime/functionobjects/IndexFunction.java index 28e245e..079f110 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/IndexFunction.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/IndexFunction.java @@ -21,9 +21,23 @@ package org.apache.sysml.runtime.functionobjects; import java.io.Serializable; -public class IndexFunction extends FunctionObject implements Serializable -{ +import org.apache.sysml.runtime.matrix.MatrixCharacteristics; +import org.apache.sysml.runtime.matrix.data.MatrixIndexes; +import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; - +public abstract class IndexFunction extends FunctionObject implements Serializable +{ private static final long serialVersionUID = -7672111359444767237L; + + //compute output indexes + + public abstract void execute(MatrixIndexes in, MatrixIndexes out); + + public abstract void execute(CellIndex in, CellIndex out); + + //determine of dimension has been reduced + public abstract boolean computeDimension(int row, int col, CellIndex retDim); + + //compute output dimensions + public abstract boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java b/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java index 732949b..e283667 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/IntegerDivide.java @@ -38,10 +38,6 @@ public class IntegerDivide extends ValueFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public double execute(double in1, double in2) { @@ -49,16 +45,6 @@ public class IntegerDivide extends ValueFunction } @Override - public double execute(double in1, long in2) { - return executeIntDiv( in1, (double)in2 ); - } - - @Override - public double execute(long in1, double in2) { - return executeIntDiv( (double)in1, in2 ); - } - - @Override public double execute(long in1, long in2) { return executeIntDiv( (double)in1, (double)in2 ); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlus.java b/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlus.java index 8cf57e7..14affa3 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlus.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlus.java @@ -43,11 +43,6 @@ public class KahanPlus extends KahanFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public Data execute(Data in1, double in2) throws DMLRuntimeException http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlusSq.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlusSq.java b/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlusSq.java index d7c188f..7a8c7c9 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlusSq.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/KahanPlusSq.java @@ -52,11 +52,6 @@ public class KahanPlusSq extends KahanFunction implements Serializable { return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /** * Square the given term, then add to the existing sum using * the Kahan summation algorithm. http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/LessThan.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/LessThan.java b/src/main/java/org/apache/sysml/runtime/functionobjects/LessThan.java index 5cce17e..00397d1 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/LessThan.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/LessThan.java @@ -19,9 +19,8 @@ package org.apache.sysml.runtime.functionobjects; -public class LessThan extends ValueFunction +public class LessThan extends ValueComparisonFunction { - private static final long serialVersionUID = -5598503447690597942L; private static LessThan singleObj = null; @@ -35,11 +34,6 @@ public class LessThan extends ValueFunction singleObj = new LessThan(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of @@ -71,13 +65,8 @@ public class LessThan extends ValueFunction } @Override - public boolean compare(double in1, long in2) { - return (in1 < in2); - } - - @Override - public boolean compare(long in1, double in2) { - return (in1 < in2); + public boolean compare(boolean in1, boolean in2) { + return (!in1 && in2); } @Override http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/LessThanEquals.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/LessThanEquals.java b/src/main/java/org/apache/sysml/runtime/functionobjects/LessThanEquals.java index 59cc051..8197eda 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/LessThanEquals.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/LessThanEquals.java @@ -19,9 +19,8 @@ package org.apache.sysml.runtime.functionobjects; -public class LessThanEquals extends ValueFunction +public class LessThanEquals extends ValueComparisonFunction { - private static final long serialVersionUID = -1211700634442163849L; private static LessThanEquals singleObj = null; @@ -35,11 +34,6 @@ public class LessThanEquals extends ValueFunction singleObj = new LessThanEquals(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of @@ -70,14 +64,9 @@ public class LessThanEquals extends ValueFunction return (in1 <= in2); } - @Override - public boolean compare(double in1, long in2) { - return (in1 <= in2); - } - - @Override - public boolean compare(long in1, double in2) { - return (in1 <= in2); + @Override + public boolean compare(boolean in1, boolean in2) { + return (!in1 && in2) || (in1 == in2); } @Override http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Mean.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Mean.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Mean.java index 27f1aa3..3647741 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Mean.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Mean.java @@ -43,11 +43,6 @@ public class Mean extends ValueFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - //overwride in1 public Data execute(Data in1, double in2, double count) throws DMLRuntimeException { KahanObject kahanObj=(KahanObject)in1; http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Minus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Minus.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Minus.java index d05a170..b6ef281 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Minus.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Minus.java @@ -23,7 +23,6 @@ import java.io.Serializable; public class Minus extends ValueFunction implements Serializable { - private static final long serialVersionUID = 8433928060333018056L; private static Minus singleObj = null; @@ -38,27 +37,12 @@ public class Minus extends ValueFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return in1 - in2; } @Override - public double execute(double in1, long in2) { - return in1 - in2; - } - - @Override - public double execute(long in1, double in2) { - return in1 - in2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 - in2); @@ -67,5 +51,4 @@ public class Minus extends ValueFunction implements Serializable return in1 - in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Minus1Multiply.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Minus1Multiply.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Minus1Multiply.java index 1d99f10..f7e3dc3 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Minus1Multiply.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Minus1Multiply.java @@ -37,27 +37,12 @@ public class Minus1Multiply extends ValueFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return 1 - in1 * in2; } @Override - public double execute(double in1, long in2) { - return 1 - in1 * in2; - } - - @Override - public double execute(long in1, double in2) { - return 1 - in1 * in2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 * in2); @@ -66,5 +51,4 @@ public class Minus1Multiply extends ValueFunction implements Serializable return 1 - in1 * in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/MinusMultiply.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/MinusMultiply.java b/src/main/java/org/apache/sysml/runtime/functionobjects/MinusMultiply.java index 1d90b44..9a98194 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/MinusMultiply.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/MinusMultiply.java @@ -35,27 +35,12 @@ public class MinusMultiply extends ValueFunctionWithConstant implements Serializ return new MinusMultiply(); } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return in1 - _constant * in2; } @Override - public double execute(double in1, long in2) { - return in1 - _constant * in2; - } - - @Override - public double execute(long in1, double in2) { - return in1 - _constant * in2; - } - - @Override public double execute(long in1, long in2) { return in1 - _constant * in2; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/MinusNz.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/MinusNz.java b/src/main/java/org/apache/sysml/runtime/functionobjects/MinusNz.java index 8b3d06f..6925b90 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/MinusNz.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/MinusNz.java @@ -38,23 +38,13 @@ public class MinusNz extends ValueFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return (in1 != 0) ? in1 - in2 : 0; } - - @Override - public double execute(double in1, long in2) { - return (in1 != 0) ? in1 - in2 : 0; - } - + @Override - public double execute(long in1, double in2) { + public double execute(long in1, long in2) { return (in1 != 0) ? in1 - in2 : 0; } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java index 2dc134a..3a82fd4 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Modulus.java @@ -44,11 +44,6 @@ public class Modulus extends ValueFunction singleObj = new Modulus(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public double execute(double in1, double in2) { @@ -58,24 +53,9 @@ public class Modulus extends ValueFunction } @Override - public double execute(double in1, long in2) { - if( in2==0 ) - return Double.NaN; - return in1 - _intdiv.execute(in1, in2)*in2; - } - - @Override - public double execute(long in1, double in2) { - if( in2==0.0 || in2==-0.0 ) - return Double.NaN; - return in1 - _intdiv.execute(in1, in2)*in2; - } - - @Override public double execute(long in1, long in2) { if( in2==0 ) return Double.NaN; return in1 - _intdiv.execute(in1, in2)*in2; - } - + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply.java index 093f6cf..e104baa 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply.java @@ -38,27 +38,12 @@ public class Multiply extends ValueFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return in1 * in2; } @Override - public double execute(double in1, long in2) { - return in1 * in2; - } - - @Override - public double execute(long in1, double in2) { - return in1 * in2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 * in2); @@ -67,5 +52,4 @@ public class Multiply extends ValueFunction implements Serializable return in1 * in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply2.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply2.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply2.java index 3b4be72..38368fc 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply2.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Multiply2.java @@ -21,7 +21,6 @@ package org.apache.sysml.runtime.functionobjects; public class Multiply2 extends ValueFunction { - private static final long serialVersionUID = -3762789087715600938L; private static Multiply2 singleObj = null; @@ -36,11 +35,6 @@ public class Multiply2 extends ValueFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1) { return in1 + in1; //ignore in2 because always 2; @@ -52,16 +46,6 @@ public class Multiply2 extends ValueFunction } @Override - public double execute(double in1, long in2) { - return in1 + in1; //ignore in2 because always 2; - } - - @Override - public double execute(long in1, double in2) { - return in1 + in1; //ignore in2 because always 2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 + in2); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java index 82849ed..bdd11f2 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java @@ -21,7 +21,6 @@ package org.apache.sysml.runtime.functionobjects; public class Not extends ValueFunction { - private static final long serialVersionUID = -3137270229584267263L; private static Not singleObj = null; @@ -35,11 +34,6 @@ public class Not extends ValueFunction singleObj = new Not(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public boolean execute(boolean in) { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/NotEquals.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/NotEquals.java b/src/main/java/org/apache/sysml/runtime/functionobjects/NotEquals.java index 5fd4ee9..1e1a338 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/NotEquals.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/NotEquals.java @@ -19,9 +19,8 @@ package org.apache.sysml.runtime.functionobjects; -public class NotEquals extends ValueFunction +public class NotEquals extends ValueComparisonFunction { - private static final long serialVersionUID = 2243676126579964278L; private static NotEquals singleObj = null; @@ -35,11 +34,6 @@ public class NotEquals extends ValueFunction singleObj = new NotEquals(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } /* * Arithmetic relational operators (==, !=, <=, >=) must be instead of @@ -61,10 +55,6 @@ public class NotEquals extends ValueFunction } @Override - public boolean compare(boolean in1, boolean in2) { - return (in1 != in2); - } - @Override public boolean compare(double in1, double in2) { return (in1 != in2); } @@ -75,12 +65,7 @@ public class NotEquals extends ValueFunction } @Override - public boolean compare(double in1, long in2) { - return (in1 != in2); - } - - @Override - public boolean compare(long in1, double in2) { + public boolean compare(boolean in1, boolean in2) { return (in1 != in2); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/OffsetColumnIndex.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/OffsetColumnIndex.java b/src/main/java/org/apache/sysml/runtime/functionobjects/OffsetColumnIndex.java index afd5483..8a85edc 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/OffsetColumnIndex.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/OffsetColumnIndex.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -27,7 +26,6 @@ import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; public class OffsetColumnIndex extends IndexFunction { - private static final long serialVersionUID = 1523769994005450946L; //private static OffsetColumnIndex singleObj = null; @@ -48,11 +46,6 @@ public class OffsetColumnIndex extends IndexFunction this.offset = offset; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public void execute(MatrixIndexes in, MatrixIndexes out) { out.setIndexes(in.getRowIndex(), in.getColumnIndex()+offset); @@ -70,8 +63,7 @@ public class OffsetColumnIndex extends IndexFunction return false; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(numRowsInOutput, numColumnsInOutput, in.getRowsPerBlock(), in.getColsPerBlock()); return false; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java index 0423d6e..9f29b53 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java @@ -23,7 +23,6 @@ import java.io.Serializable; public class Or extends ValueFunction implements Serializable { - private static final long serialVersionUID = -2847467729680510910L; private static Or singleObj = null; @@ -37,15 +36,9 @@ public class Or extends ValueFunction implements Serializable singleObj = new Or(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public boolean execute(boolean in1, boolean in2) { return in1 || in2; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ParameterizedBuiltin.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ParameterizedBuiltin.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ParameterizedBuiltin.java index e55f294..eb69068 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ParameterizedBuiltin.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ParameterizedBuiltin.java @@ -183,11 +183,6 @@ public class ParameterizedBuiltin extends ValueFunction } } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - public double execute(HashMap<String,String> params) throws DMLRuntimeException { switch(bFunc) { case CDF: http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Plus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Plus.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Plus.java index b197ddd..c25853d 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Plus.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Plus.java @@ -27,7 +27,6 @@ import org.apache.sysml.runtime.DMLRuntimeException; public class Plus extends ValueFunction implements Serializable { - private static final long serialVersionUID = -3573790367761963555L; private static Plus singleObj = null; @@ -42,27 +41,12 @@ public class Plus extends ValueFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return in1 + in2; } @Override - public double execute(double in1, long in2) { - return in1 + in2; - } - - @Override - public double execute(long in1, double in2) { - return in1 + in2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 + in2); @@ -74,6 +58,5 @@ public class Plus extends ValueFunction implements Serializable public String execute ( String in1, String in2 ) throws DMLRuntimeException { return in1 + in2; - } - + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/PlusMultiply.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/PlusMultiply.java b/src/main/java/org/apache/sysml/runtime/functionobjects/PlusMultiply.java index 9d1a746..5f9b6e7 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/PlusMultiply.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/PlusMultiply.java @@ -35,27 +35,12 @@ public class PlusMultiply extends ValueFunctionWithConstant implements Serializa return new PlusMultiply(); } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return in1 + _constant * in2; } @Override - public double execute(double in1, long in2) { - return in1 + _constant * in2; - } - - @Override - public double execute(long in1, double in2) { - return in1 + _constant * in2; - } - - @Override public double execute(long in1, long in2) { return in1 + _constant * in2; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Power.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Power.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Power.java index 848503b..1845e6b 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Power.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Power.java @@ -38,27 +38,12 @@ public class Power extends ValueFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1, double in2) { return Math.pow(in1, in2); } @Override - public double execute(double in1, long in2) { - return Math.pow(in1, (double)in2); - } - - @Override - public double execute(long in1, double in2) { - return Math.pow((double)in1, in2); - } - - @Override public double execute(long in1, long in2) { return Math.pow((double)in1, (double)in2); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/Power2.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Power2.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Power2.java index 9bec3bc..1d1c2e5 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Power2.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Power2.java @@ -23,7 +23,6 @@ package org.apache.sysml.runtime.functionobjects; public class Power2 extends ValueFunction { - private static final long serialVersionUID = -4370611388912121328L; private static Power2 singleObj = null; @@ -38,11 +37,6 @@ public class Power2 extends ValueFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public double execute(double in1) { return in1*in1; //ignore in2 because always 2; @@ -54,16 +48,6 @@ public class Power2 extends ValueFunction } @Override - public double execute(double in1, long in2) { - return in1*in1; //ignore in2 because always 2; - } - - @Override - public double execute(long in1, double in2) { - return in1*in1; //ignore in2 because always 2; - } - - @Override public double execute(long in1, long in2) { //for robustness regarding long overflows (only used for scalar instructions) double dval = ((double)in1 * in2); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceAll.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceAll.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceAll.java index 1f71f03..1496e48 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceAll.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceAll.java @@ -19,12 +19,10 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; - public class ReduceAll extends IndexFunction { @@ -42,11 +40,6 @@ public class ReduceAll extends IndexFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /* * NOTE: index starts from 1 for cells in a matrix, but index starts from 0 for cells inside a block */ @@ -66,9 +59,9 @@ public class ReduceAll extends IndexFunction retDim.set(1, 1); return true; } - - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(1, 1, in.getRowsPerBlock(), in.getColsPerBlock()); return true; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceCol.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceCol.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceCol.java index 66ff5ec..9bbd937 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceCol.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceCol.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -42,11 +41,6 @@ public class ReduceCol extends IndexFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /* * NOTE: index starts from 1 for cells in a matrix, but index starts from 0 for cells inside a block */ @@ -67,8 +61,8 @@ public class ReduceCol extends IndexFunction return true; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(in.getRows(), 1, in.getRowsPerBlock(), in.getColsPerBlock()); return true; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceDiag.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceDiag.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceDiag.java index f178be8..e38b7b8 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceDiag.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceDiag.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -42,11 +41,6 @@ public class ReduceDiag extends IndexFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /* * NOTE: index starts from 1 for cells in a matrix, but index starts from 0 for cells inside a block */ @@ -67,8 +61,8 @@ public class ReduceDiag extends IndexFunction return true; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(1, 1, 1, 1); return true; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceRow.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceRow.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceRow.java index a275297..2f5aade 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceRow.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ReduceRow.java @@ -19,7 +19,6 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -42,11 +41,6 @@ public class ReduceRow extends IndexFunction return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - /* * NOTE: index starts from 1 for cells in a matrix, but index starts from 0 for cells inside a block */ @@ -68,8 +62,8 @@ public class ReduceRow extends IndexFunction return true; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(1, in.getCols(), in.getRowsPerBlock(), in.getColsPerBlock()); return true; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/RemoveFile.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/RemoveFile.java b/src/main/java/org/apache/sysml/runtime/functionobjects/RemoveFile.java index 74c79ca..2412380 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/RemoveFile.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/RemoveFile.java @@ -27,7 +27,6 @@ import org.apache.sysml.runtime.util.MapReduceTool; public class RemoveFile extends FileFunction { - private static RemoveFile singleObj = null; private RemoveFile() { @@ -39,11 +38,6 @@ public class RemoveFile extends FileFunction singleObj = new RemoveFile(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public String execute (String fname) throws DMLRuntimeException { @@ -54,5 +48,4 @@ public class RemoveFile extends FileFunction } return null; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/RenameFile.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/RenameFile.java b/src/main/java/org/apache/sysml/runtime/functionobjects/RenameFile.java index 20edbf7..ef6f8a5 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/RenameFile.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/RenameFile.java @@ -39,11 +39,6 @@ public class RenameFile extends FileFunction singleObj = new RenameFile(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override public String execute (String origName, String newName) throws DMLRuntimeException { @@ -54,5 +49,4 @@ public class RenameFile extends FileFunction } return null; } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/RevIndex.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/RevIndex.java b/src/main/java/org/apache/sysml/runtime/functionobjects/RevIndex.java index 4308497..efdc232 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/RevIndex.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/RevIndex.java @@ -21,8 +21,9 @@ package org.apache.sysml.runtime.functionobjects; import java.io.Serializable; -import org.apache.sysml.runtime.DMLRuntimeException; +import org.apache.commons.lang.NotImplementedException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; +import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -41,25 +42,26 @@ public class RevIndex extends IndexFunction implements Serializable singleObj = new RevIndex(); return singleObj; } - - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } @Override // for cp block operations - public boolean computeDimension(int row, int col, CellIndex retDim) - throws DMLRuntimeException - { + public boolean computeDimension(int row, int col, CellIndex retDim) { retDim.set(row, col); return false; } @Override //for mr block operations - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) - throws DMLRuntimeException - { + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(in.getRows(), in.getCols(), in.getColsPerBlock(), in.getRowsPerBlock(), in.getNonZeros()); return false; } + + @Override + public void execute(MatrixIndexes in, MatrixIndexes out) { + throw new NotImplementedException(); + } + + @Override + public void execute(CellIndex in, CellIndex out) { + throw new NotImplementedException(); + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/SortIndex.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/SortIndex.java b/src/main/java/org/apache/sysml/runtime/functionobjects/SortIndex.java index 0bbb7bb..c72735a 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/SortIndex.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/SortIndex.java @@ -20,7 +20,9 @@ package org.apache.sysml.runtime.functionobjects; -import org.apache.sysml.runtime.DMLRuntimeException; +import org.apache.commons.lang.NotImplementedException; +import org.apache.sysml.runtime.matrix.MatrixCharacteristics; +import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; /** @@ -30,7 +32,6 @@ import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; */ public class SortIndex extends IndexFunction { - private static final long serialVersionUID = -8446389232078905200L; private int _col = -1; @@ -63,17 +64,24 @@ public class SortIndex extends IndexFunction return _ixreturn; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - - public boolean computeDimension(int row, int col, CellIndex retDim) - throws DMLRuntimeException - { + @Override + public boolean computeDimension(int row, int col, CellIndex retDim) { retDim.set(row, _ixreturn?1:col); return false; } - + @Override + public void execute(MatrixIndexes in, MatrixIndexes out) { + throw new NotImplementedException(); + } + + @Override + public void execute(CellIndex in, CellIndex out) { + throw new NotImplementedException(); + } + + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { + throw new NotImplementedException(); + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/SwapIndex.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/SwapIndex.java b/src/main/java/org/apache/sysml/runtime/functionobjects/SwapIndex.java index e256106..e5a4458 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/SwapIndex.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/SwapIndex.java @@ -21,7 +21,6 @@ package org.apache.sysml.runtime.functionobjects; import java.io.Serializable; -import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; @@ -29,7 +28,6 @@ import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; public class SwapIndex extends IndexFunction implements Serializable { - private static final long serialVersionUID = -8898087610410746689L; private static SwapIndex singleObj = null; @@ -44,11 +42,6 @@ public class SwapIndex extends IndexFunction implements Serializable return singleObj; } - public Object clone() throws CloneNotSupportedException { - // cloning is not supported for singleton classes - throw new CloneNotSupportedException(); - } - @Override public void execute(MatrixIndexes in, MatrixIndexes out) { out.setIndexes(in.getColumnIndex(), in.getRowIndex()); @@ -67,8 +60,8 @@ public class SwapIndex extends IndexFunction implements Serializable return false; } - public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) throws DMLRuntimeException - { + @Override + public boolean computeDimension(MatrixCharacteristics in, MatrixCharacteristics out) { out.set(in.getCols(), in.getRows(), in.getColsPerBlock(), in.getRowsPerBlock()); return false; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ValueComparisonFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ValueComparisonFunction.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ValueComparisonFunction.java new file mode 100644 index 0000000..8153ccf --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ValueComparisonFunction.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sysml.runtime.functionobjects; + +import java.io.Serializable; + +/** + * Abstraction for comparison (relational) operators in order to + * force a proper implementation by all relevant subclasses. + */ +public abstract class ValueComparisonFunction extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = 6021132561216734747L; + + public abstract boolean compare(double in1, double in2); + + public abstract boolean compare(long in1, long in2); + + public abstract boolean compare(boolean in1, boolean in2); + + public abstract boolean compare(String in1, String in2); +} http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/functionobjects/ValueFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/ValueFunction.java b/src/main/java/org/apache/sysml/runtime/functionobjects/ValueFunction.java index 2115938..0c233f7 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/ValueFunction.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/ValueFunction.java @@ -21,7 +21,8 @@ package org.apache.sysml.runtime.functionobjects; import java.io.Serializable; -public class ValueFunction extends FunctionObject implements Serializable +public abstract class ValueFunction extends FunctionObject implements Serializable { private static final long serialVersionUID = -4985988545393861058L; + } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ArithmeticBinaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/ArithmeticBinaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/ArithmeticBinaryCPInstruction.java index c9545ac..338daba 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/ArithmeticBinaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/ArithmeticBinaryCPInstruction.java @@ -27,15 +27,8 @@ import org.apache.sysml.runtime.matrix.operators.Operator; public abstract class ArithmeticBinaryCPInstruction extends BinaryCPInstruction -{ - - public ArithmeticBinaryCPInstruction(Operator op, - CPOperand in1, - CPOperand in2, - CPOperand out, - String opcode, - String istr ) - { +{ + public ArithmeticBinaryCPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) { super(op, in1, in2, out, opcode, istr); _cptype = CPINSTRUCTION_TYPE.ArithmeticBinary; } @@ -48,61 +41,17 @@ public abstract class ArithmeticBinaryCPInstruction extends BinaryCPInstruction CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); String opcode = parseBinaryInstruction(str, in1, in2, out); - // Arithmetic operations must be performed on DOUBLE or INT - ValueType vt1 = in1.getValueType(); - DataType dt1 = in1.getDataType(); - ValueType vt2 = in2.getValueType(); - DataType dt2 = in2.getDataType(); - ValueType vt3 = out.getValueType(); - DataType dt3 = out.getDataType(); - - //prithvi TODO - //make sure these checks belong here - //if either input is a matrix, then output - //has to be a matrix - if((dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) && dt3 != DataType.MATRIX) { - throw new DMLRuntimeException("Element-wise matrix operations between variables " + in1.getName() + - " and " + in2.getName() + " must produce a matrix, which " + out.getName() + "is not"); - } + checkOutputDataType(in1, in2, out); - Operator operator = (dt1 != dt2) ? - InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : + Operator operator = (in1.getDataType() != in2.getDataType()) ? + InstructionUtils.parseScalarBinaryOperator(opcode, (in1.getDataType() == DataType.SCALAR)) : InstructionUtils.parseBinaryOperator(opcode); - if ( opcode.equalsIgnoreCase("+") && dt1 == DataType.SCALAR && dt2 == DataType.SCALAR) - { + if( in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR ) return new ScalarScalarArithmeticCPInstruction(operator, in1, in2, out, opcode, str); - } - else if(dt1 == DataType.SCALAR && dt2 == DataType.SCALAR){ - if ( (vt1 != ValueType.DOUBLE && vt1 != ValueType.INT) - || (vt2 != ValueType.DOUBLE && vt2 != ValueType.INT) - || (vt3 != ValueType.DOUBLE && vt3 != ValueType.INT) ) - throw new DMLRuntimeException("Unexpected ValueType in ArithmeticInstruction."); - - //haven't we already checked for this above -- prithvi - if ( vt1 != ValueType.DOUBLE && vt1 != ValueType.INT ) { - throw new DMLRuntimeException("Unexpected ValueType (" + vt1 + ") in ArithmeticInstruction: " + str); - } - - return new ScalarScalarArithmeticCPInstruction(operator, in1, in2, out, opcode, str); - - } else if (dt1 == DataType.MATRIX || dt2 == DataType.MATRIX){ - if(vt1 == ValueType.STRING - || vt2 == ValueType.STRING - || vt3 == ValueType.STRING) - throw new DMLRuntimeException("We do not support element-wise string operations on matrices " - + in1.getName() - + ", " - + in2.getName() - + " and " - + out.getName()); - - if(dt1 == DataType.MATRIX && dt2 == DataType.MATRIX) - return new MatrixMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str); - else - return new ScalarMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str); - } - - return null; + else if( in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX ) + return new MatrixMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str); + else + return new ScalarMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str); } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/BinaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/BinaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/BinaryCPInstruction.java index 4994dad..0f160f3 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/BinaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/BinaryCPInstruction.java @@ -19,6 +19,7 @@ package org.apache.sysml.runtime.instructions.cp; +import org.apache.sysml.parser.Expression.DataType; import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.instructions.InstructionUtils; import org.apache.sysml.runtime.matrix.operators.Operator; @@ -66,4 +67,12 @@ public abstract class BinaryCPInstruction extends ComputationCPInstruction return opcode; } + protected static void checkOutputDataType(CPOperand in1, CPOperand in2, CPOperand out) + throws DMLRuntimeException + { + // check for valid data type of output + if((in1.getDataType() == DataType.MATRIX || in2.getDataType() == DataType.MATRIX) && out.getDataType() != DataType.MATRIX) + throw new DMLRuntimeException("Element-wise matrix operations between variables " + in1.getName() + + " and " + in2.getName() + " must produce a matrix, which " + out.getName() + " is not"); + } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanObject.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanObject.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanObject.java index 6c7d67d..dff1339 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanObject.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanObject.java @@ -27,7 +27,6 @@ import org.apache.sysml.parser.Expression.ValueType; public class BooleanObject extends ScalarObject { - private static final long serialVersionUID = -4506242165735516984L; private boolean _value; @@ -61,26 +60,15 @@ public class BooleanObject extends ScalarObject return Boolean.toString(_value).toUpperCase(); } - public String getLanguageSpecificBooleanStringValue() { - if (DMLScript.SCRIPT_TYPE == ScriptType.DML) { - return Boolean.toString(_value).toUpperCase(); - } else { - return StringUtils.capitalize(Boolean.toString(_value)); - } + @Override + public String getLanguageSpecificStringValue() { + return (DMLScript.SCRIPT_TYPE == ScriptType.DML) ? + Boolean.toString(_value).toUpperCase() : + StringUtils.capitalize(Boolean.toString(_value)); } @Override public Object getValue(){ return _value; } - - public String toString() { - return getStringValue(); - } - - @Override - public String getDebugName() { - return null; - } - } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/BuiltinBinaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/BuiltinBinaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/BuiltinBinaryCPInstruction.java index fd75d11..d4679f3 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/BuiltinBinaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/BuiltinBinaryCPInstruction.java @@ -31,18 +31,16 @@ import org.apache.sysml.runtime.matrix.operators.RightScalarOperator; public abstract class BuiltinBinaryCPInstruction extends BinaryCPInstruction { + private int _arity; - private int arity; - - public BuiltinBinaryCPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, int _arity, String opcode, String istr ) - { + public BuiltinBinaryCPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, int arity, String opcode, String istr) { super(op, in1, in2, out, opcode, istr); _cptype = CPINSTRUCTION_TYPE.BuiltinBinary; - arity = _arity; + _arity = arity; } public int getArity() { - return arity; + return _arity; } public static BuiltinBinaryCPInstruction parseInstruction ( String str ) @@ -51,17 +49,17 @@ public abstract class BuiltinBinaryCPInstruction extends BinaryCPInstruction CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); String opcode = parseBinaryInstruction(str, in1, in2, out); - - ValueFunction func = Builtin.getBuiltinFnObject(opcode); + + checkOutputDataType(in1, in2, out); // Determine appropriate Function Object based on opcode + ValueFunction func = Builtin.getBuiltinFnObject(opcode); - if ( in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR ) { + if ( in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR ) return new ScalarScalarBuiltinCPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str); - } else if (in1.getDataType() != in2.getDataType()) { - return new MatrixScalarBuiltinCPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str); - } else { // if ( in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX ) { + else if ( in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX ) return new MatrixMatrixBuiltinCPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str); - } + else + return new MatrixScalarBuiltinCPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str); } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/DoubleObject.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/DoubleObject.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/DoubleObject.java index 306e4c0..0bad105 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/DoubleObject.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/DoubleObject.java @@ -24,7 +24,6 @@ import org.apache.sysml.runtime.util.UtilFunctions; public class DoubleObject extends ScalarObject { - private static final long serialVersionUID = -8525290101679236360L; private double _value; @@ -62,11 +61,6 @@ public class DoubleObject extends ScalarObject public Object getValue(){ return _value; } - - - public String toString() { - return getStringValue(); - } @Override public String getDebugName() { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/IntObject.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/IntObject.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/IntObject.java index 5ec7c1d..06c31d9 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/IntObject.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/IntObject.java @@ -24,19 +24,16 @@ import org.apache.sysml.parser.Expression.ValueType; public class IntObject extends ScalarObject { - private static final long serialVersionUID = 353170585998999528L; //we use consistently to the compiler long in terms of integer (8 byte) private long _value; - public IntObject(long val) - { + public IntObject(long val) { this(null,val); } - public IntObject(String name, long val) - { + public IntObject(String name, long val) { super(name, ValueType.INT); _value = val; } @@ -65,13 +62,4 @@ public class IntObject extends ScalarObject public Object getValue(){ return _value; } - - public String toString() { - return getStringValue(); - } - - @Override - public String getDebugName() { - return null; - } }