Repository: systemml Updated Branches: refs/heads/master d596d2214 -> ea77cb456
[SYSTEMML-1931] Generalize logical operators to matrices Closes #714. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/ea77cb45 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/ea77cb45 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/ea77cb45 Branch: refs/heads/master Commit: ea77cb456008c99276ebbae021ea8fe1246338ea Parents: d596d22 Author: Janardhan Pulivarthi <[email protected]> Authored: Thu Jan 4 00:46:03 2018 -0800 Committer: Matthias Boehm <[email protected]> Committed: Thu Jan 4 00:46:03 2018 -0800 ---------------------------------------------------------------------- .../java/org/apache/sysml/hops/BinaryOp.java | 3 +- src/main/java/org/apache/sysml/hops/Hop.java | 4 +- .../java/org/apache/sysml/hops/LiteralOp.java | 2 + .../apache/sysml/parser/BooleanExpression.java | 26 ++- .../org/apache/sysml/parser/DMLTranslator.java | 14 +- .../sysml/runtime/functionobjects/And.java | 5 + .../sysml/runtime/functionobjects/Not.java | 5 + .../sysml/runtime/functionobjects/Or.java | 5 + .../sysml/runtime/functionobjects/Xor.java | 5 + .../instructions/CPInstructionParser.java | 2 - .../runtime/instructions/InstructionUtils.java | 6 +- .../instructions/MRInstructionParser.java | 8 +- .../instructions/SPInstructionParser.java | 32 ++- .../cp/BooleanBinaryCPInstruction.java | 22 +- .../instructions/cp/UnaryCPInstruction.java | 11 +- .../spark/BuiltinBinarySPInstruction.java | 4 +- .../MatrixMatrixArithmeticSPInstruction.java | 8 - .../instructions/spark/SPInstruction.java | 3 +- .../runtime/matrix/data/LibMatrixBincell.java | 8 +- .../matrix/operators/BinaryOperator.java | 2 +- .../runtime/matrix/operators/UnaryOperator.java | 2 +- .../binary/matrix/ElementwiseLogicalTest.java | 229 +++++++++++++++++++ .../binary/matrix/ElementwiseAndTest.R | 34 +++ .../binary/matrix/ElementwiseAndTest.dml | 27 +++ .../binary/matrix/ElementwiseNotTest.R | 31 +++ .../binary/matrix/ElementwiseNotTest.dml | 26 +++ .../functions/binary/matrix/ElementwiseOrTest.R | 32 +++ .../binary/matrix/ElementwiseOrTest.dml | 27 +++ .../binary/matrix/ElementwiseXorTest.R | 32 +++ .../binary/matrix/ElementwiseXorTest.dml | 27 +++ .../functions/binary/matrix/ZPackageSuite.java | 1 + 31 files changed, 576 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/hops/BinaryOp.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/BinaryOp.java b/src/main/java/org/apache/sysml/hops/BinaryOp.java index d207cba..20e4dd3 100644 --- a/src/main/java/org/apache/sysml/hops/BinaryOp.java +++ b/src/main/java/org/apache/sysml/hops/BinaryOp.java @@ -1606,7 +1606,8 @@ public class BinaryOp extends Hop ||op==OpOp2.GREATER ||op==OpOp2.GREATEREQUAL ||op==OpOp2.EQUAL ||op==OpOp2.NOTEQUAL ||op==OpOp2.MIN ||op==OpOp2.MAX - ||op==OpOp2.AND ||op==OpOp2.OR + ||op==OpOp2.AND ||op==OpOp2.OR + ||op == OpOp2.XOR ||op==OpOp2.LOG ||op==OpOp2.POW ); } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/hops/Hop.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/Hop.java b/src/main/java/org/apache/sysml/hops/Hop.java index 5ce3f4a..0a3972b 100644 --- a/src/main/java/org/apache/sysml/hops/Hop.java +++ b/src/main/java/org/apache/sysml/hops/Hop.java @@ -1218,9 +1218,9 @@ public abstract class Hop implements ParseInfo HopsOpOp2LopsB.put(OpOp2.NOTEQUAL, Binary.OperationTypes.NOT_EQUALS); HopsOpOp2LopsB.put(OpOp2.MIN, Binary.OperationTypes.MIN); HopsOpOp2LopsB.put(OpOp2.MAX, Binary.OperationTypes.MAX); - HopsOpOp2LopsB.put(OpOp2.AND, Binary.OperationTypes.OR); + HopsOpOp2LopsB.put(OpOp2.AND, Binary.OperationTypes.AND); HopsOpOp2LopsB.put(OpOp2.XOR, Binary.OperationTypes.XOR); - HopsOpOp2LopsB.put(OpOp2.OR, Binary.OperationTypes.AND); + HopsOpOp2LopsB.put(OpOp2.OR, Binary.OperationTypes.OR); HopsOpOp2LopsB.put(OpOp2.SOLVE, Binary.OperationTypes.SOLVE); HopsOpOp2LopsB.put(OpOp2.POW, Binary.OperationTypes.POW); HopsOpOp2LopsB.put(OpOp2.LOG, Binary.OperationTypes.NOTSUPPORTED); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/hops/LiteralOp.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/LiteralOp.java b/src/main/java/org/apache/sysml/hops/LiteralOp.java index 16ebf1b..6199777 100644 --- a/src/main/java/org/apache/sysml/hops/LiteralOp.java +++ b/src/main/java/org/apache/sysml/hops/LiteralOp.java @@ -223,6 +223,8 @@ public class LiteralOp extends Hop return value_double; case STRING: return Double.parseDouble(value_string); + case BOOLEAN: + return value_boolean ? 1 : 0; default: throw new HopsException("Can not coerce an object of type " + getValueType() + " into Double."); } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/parser/BooleanExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/BooleanExpression.java b/src/main/java/org/apache/sysml/parser/BooleanExpression.java index c16e58d..31d7b1f 100644 --- a/src/main/java/org/apache/sysml/parser/BooleanExpression.java +++ b/src/main/java/org/apache/sysml/parser/BooleanExpression.java @@ -89,30 +89,36 @@ public class BooleanExpression extends Expression */ @Override public void validateExpression(HashMap<String,DataIdentifier> ids, HashMap<String, ConstIdentifier> constVars, boolean conditional) throws LanguageException{ - - this.getLeft().validateExpression(ids, constVars, conditional); - //recursive validate + getLeft().validateExpression(ids, constVars, conditional); if (_left instanceof FunctionCallIdentifier){ raiseValidateError("user-defined function calls not supported in boolean expressions", - false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION); + false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION); } - if (this.getRight() != null) { - if (_right instanceof FunctionCallIdentifier){ raiseValidateError("user-defined function calls not supported in boolean expressions", - false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION); + false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION); } - this.getRight().validateExpression(ids, constVars, conditional); } + String outputName = getTempName(); DataIdentifier output = new DataIdentifier(outputName); output.setParseInfo(this); - - output.setBooleanProperties(); + if( getLeft().getOutput().getDataType().isMatrix() + || (getRight()!=null && getRight().getOutput().getDataType().isMatrix()) ) { + output.setDataType((getRight()==null) ? DataType.MATRIX : + computeDataType(this.getLeft(), this.getRight(), true)); + //since SystemML only supports double matrices, the value type is forced to + //double; once we support boolean matrices this needs to change + output.setValueType(ValueType.DOUBLE); + } + else { + output.setBooleanProperties(); + } this.setOutput(output); + if ((_opcode == Expression.BooleanOp.CONDITIONALAND) || (_opcode == Expression.BooleanOp.CONDITIONALOR)) { // always unconditional (because unsupported operation) if (_opcode == Expression.BooleanOp.CONDITIONALAND) { http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/parser/DMLTranslator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/DMLTranslator.java b/src/main/java/org/apache/sysml/parser/DMLTranslator.java index 791db1c..94dd4e6 100644 --- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java +++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java @@ -1956,12 +1956,12 @@ public class DMLTranslator right = processExpression(source.getRight(), null, hops); } - //prepare target identifier and ensure that output type is boolean - //(type should not be determined by target (e.g., string for print) - if (target == null) { - target = createTarget(source); - } - target.setValueType(ValueType.BOOLEAN); + //prepare target identifier and ensure that output type is boolean + //(type should not be determined by target (e.g., string for print) + if (target == null) + target = createTarget(source); + if( target.getDataType().isScalar() ) + target.setValueType(ValueType.BOOLEAN); if (source.getRight() == null) { Hop currUop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), Hop.OpOp1.NOT, left); @@ -2664,7 +2664,7 @@ public class DMLTranslator case XOR: currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), - ValueType.BOOLEAN, Hop.OpOp2.XOR, expr, expr2); + target.getValueType(), Hop.OpOp2.XOR, expr, expr2); break; case ABS: http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/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 2d183aa..c6cff7f 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/And.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/And.java @@ -41,4 +41,9 @@ public class And extends ValueFunction implements Serializable public boolean execute(boolean in1, boolean in2) { return in1 && in2; } + + @Override + public double execute(double in1, double in2) { + return ((in1 != 0) && (in2 != 0)) ? 1 : 0; + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/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 bdd11f2..6a4b1ef 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Not.java @@ -39,4 +39,9 @@ public class Not extends ValueFunction public boolean execute(boolean in) { return !in; } + + @Override + public double execute(double in) { + return (in == 0) ? 1 : 0; + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/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 9f29b53..45069e8 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Or.java @@ -41,4 +41,9 @@ public class Or extends ValueFunction implements Serializable public boolean execute(boolean in1, boolean in2) { return in1 || in2; } + + @Override + public double execute(double in1, double in2) { + return ((in1 != 0) || (in2 != 0)) ? 1 : 0; + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/functionobjects/Xor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/Xor.java b/src/main/java/org/apache/sysml/runtime/functionobjects/Xor.java index 8fa666b..4a4b845 100644 --- a/src/main/java/org/apache/sysml/runtime/functionobjects/Xor.java +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/Xor.java @@ -41,4 +41,9 @@ public class Xor extends ValueFunction implements Serializable public boolean execute(boolean in1, boolean in2) { return in1 != in2; } + + @Override + public double execute(double in1, double in2) { + return ((in1 != 0) != (in2 != 0)) ? 1 : 0; + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java b/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java index e3deefa..7ad91db 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java @@ -128,13 +128,11 @@ public class CPInstructionParser extends InstructionParser String2CPInstructionType.put( "-nz" , CPType.ArithmeticBinary); //special - case String2CPInstructionType.put( "+*" , CPType.ArithmeticBinary); String2CPInstructionType.put( "-*" , CPType.ArithmeticBinary); - // Boolean Instruction Opcodes String2CPInstructionType.put( "&&" , CPType.BooleanBinary); String2CPInstructionType.put( "||" , CPType.BooleanBinary); String2CPInstructionType.put( "xor" , CPType.BooleanBinary); - String2CPInstructionType.put( "!" , CPType.BooleanUnary); // Relational Instruction Opcodes http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java b/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java index 2f81357..8752021 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java @@ -679,10 +679,12 @@ public class InstructionUtils return new BinaryOperator(LessThanEquals.getLessThanEqualsFnObject()); else if(opcode.equalsIgnoreCase(">=") || opcode.equalsIgnoreCase("map>=")) return new BinaryOperator(GreaterThanEquals.getGreaterThanEqualsFnObject()); - else if(opcode.equalsIgnoreCase("&&")) + else if(opcode.equalsIgnoreCase("&&") || opcode.equalsIgnoreCase("map&&")) return new BinaryOperator(And.getAndFnObject()); - else if(opcode.equalsIgnoreCase("||")) + else if(opcode.equalsIgnoreCase("||") || opcode.equalsIgnoreCase("map||")) return new BinaryOperator(Or.getOrFnObject()); + else if(opcode.equalsIgnoreCase("xor") || opcode.equalsIgnoreCase("mapxor")) + return new BinaryOperator(Xor.getXorFnObject()); else if(opcode.equalsIgnoreCase("+") || opcode.equalsIgnoreCase("map+")) return new BinaryOperator(Plus.getPlusFnObject()); else if(opcode.equalsIgnoreCase("-") || opcode.equalsIgnoreCase("map-")) http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java b/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java index 15785c0..b68bfe2 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java @@ -184,6 +184,9 @@ public class MRInstructionParser extends InstructionParser String2MRInstructionType.put( "^2" , MRINSTRUCTION_TYPE.ArithmeticBinary); //special ^ case String2MRInstructionType.put( "*2" , MRINSTRUCTION_TYPE.ArithmeticBinary); //special * case String2MRInstructionType.put( "-nz" , MRINSTRUCTION_TYPE.ArithmeticBinary); //special - case + String2MRInstructionType.put( "&&" , MRINSTRUCTION_TYPE.ArithmeticBinary); + String2MRInstructionType.put( "||" , MRINSTRUCTION_TYPE.ArithmeticBinary); + String2MRInstructionType.put( "xor" , MRINSTRUCTION_TYPE.ArithmeticBinary); String2MRInstructionType.put( "+*" , MRINSTRUCTION_TYPE.ArithmeticBinary2); String2MRInstructionType.put( "-*" , MRINSTRUCTION_TYPE.ArithmeticBinary2); @@ -203,7 +206,10 @@ public class MRInstructionParser extends InstructionParser String2MRInstructionType.put( "map<=" , MRINSTRUCTION_TYPE.ArithmeticBinary); String2MRInstructionType.put( "map==" , MRINSTRUCTION_TYPE.ArithmeticBinary); String2MRInstructionType.put( "map!=" , MRINSTRUCTION_TYPE.ArithmeticBinary); - + String2MRInstructionType.put( "map&&" , MRINSTRUCTION_TYPE.ArithmeticBinary); + String2MRInstructionType.put( "map||" , MRINSTRUCTION_TYPE.ArithmeticBinary); + String2MRInstructionType.put( "mapxor" , MRINSTRUCTION_TYPE.ArithmeticBinary); + String2MRInstructionType.put( "uaggouterchain", MRINSTRUCTION_TYPE.UaggOuterChain); // REORG Instruction Opcodes http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java b/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java index 1a5033e..a45c8a0 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java @@ -131,7 +131,6 @@ public class SPInstructionParser extends InstructionParser String2SPInstructionType.put( "zipmm" , SPINSTRUCTION_TYPE.ZIPMM); String2SPInstructionType.put( "pmapmm" , SPINSTRUCTION_TYPE.PMAPMM); - String2SPInstructionType.put( "uaggouterchain", SPINSTRUCTION_TYPE.UaggOuterChain); //ternary aggregate operators @@ -175,14 +174,8 @@ public class SPInstructionParser extends InstructionParser String2SPInstructionType.put( "map%/%" , SPINSTRUCTION_TYPE.ArithmeticBinary); String2SPInstructionType.put( "map1-*" , SPINSTRUCTION_TYPE.ArithmeticBinary); String2SPInstructionType.put( "map^" , SPINSTRUCTION_TYPE.ArithmeticBinary); - String2SPInstructionType.put( "map+*" , SPINSTRUCTION_TYPE.ArithmeticBinary); - String2SPInstructionType.put( "map-*" , SPINSTRUCTION_TYPE.ArithmeticBinary); - String2SPInstructionType.put( "map>" , SPINSTRUCTION_TYPE.RelationalBinary); - String2SPInstructionType.put( "map>=" , SPINSTRUCTION_TYPE.RelationalBinary); - String2SPInstructionType.put( "map<" , SPINSTRUCTION_TYPE.RelationalBinary); - String2SPInstructionType.put( "map<=" , SPINSTRUCTION_TYPE.RelationalBinary); - String2SPInstructionType.put( "map==" , SPINSTRUCTION_TYPE.RelationalBinary); - String2SPInstructionType.put( "map!=" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map+*" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "map-*" , SPINSTRUCTION_TYPE.ArithmeticBinary); // Relational Instruction Opcodes String2SPInstructionType.put( "==" , SPINSTRUCTION_TYPE.RelationalBinary); @@ -191,6 +184,22 @@ public class SPInstructionParser extends InstructionParser String2SPInstructionType.put( ">" , SPINSTRUCTION_TYPE.RelationalBinary); String2SPInstructionType.put( "<=" , SPINSTRUCTION_TYPE.RelationalBinary); String2SPInstructionType.put( ">=" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map>" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map>=" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map<" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map<=" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map==" , SPINSTRUCTION_TYPE.RelationalBinary); + String2SPInstructionType.put( "map!=" , SPINSTRUCTION_TYPE.RelationalBinary); + + // Boolean Instruction Opcodes + String2SPInstructionType.put( "&&" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "||" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "xor" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "!" , SPINSTRUCTION_TYPE.BuiltinUnary); + String2SPInstructionType.put( "map&&" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "map||" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "mapxor" , SPINSTRUCTION_TYPE.ArithmeticBinary); + String2SPInstructionType.put( "map!" , SPINSTRUCTION_TYPE.BuiltinUnary); // REBLOCK Instruction Opcodes String2SPInstructionType.put( "rblk" , SPINSTRUCTION_TYPE.Reblock); @@ -203,7 +212,8 @@ public class SPInstructionParser extends InstructionParser // Builtin Instruction Opcodes String2SPInstructionType.put( "log" , SPINSTRUCTION_TYPE.Builtin); String2SPInstructionType.put( "log_nz" , SPINSTRUCTION_TYPE.Builtin); - + + // Boolean Binary builtin String2SPInstructionType.put( "max" , SPINSTRUCTION_TYPE.BuiltinBinary); String2SPInstructionType.put( "min" , SPINSTRUCTION_TYPE.BuiltinBinary); String2SPInstructionType.put( "mapmax" , SPINSTRUCTION_TYPE.BuiltinBinary); @@ -366,7 +376,7 @@ public class SPInstructionParser extends InstructionParser case RelationalBinary: return RelationalBinarySPInstruction.parseInstruction(str); - + //ternary instructions case Ternary: return TernarySPInstruction.parseInstruction(str); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanBinaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanBinaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanBinaryCPInstruction.java index 9560470..53a62b6 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanBinaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/BooleanBinaryCPInstruction.java @@ -29,30 +29,26 @@ import org.apache.sysml.runtime.matrix.operators.Operator; public class BooleanBinaryCPInstruction extends BinaryCPInstruction { - private BooleanBinaryCPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, + protected BooleanBinaryCPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) { super(CPType.BooleanBinary, op, in1, in2, out, opcode, istr); } - public static BooleanBinaryCPInstruction parseInstruction (String str) + public static BinaryCPInstruction parseInstruction (String str) throws DMLRuntimeException { CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN); String opcode = parseBinaryInstruction(str, in1, in2, out); - - // Boolean operations must be performed on BOOLEAN - ValueType vt1 = in1.getValueType(); - ValueType vt2 = in2.getValueType(); - ValueType vt3 = out.getValueType(); - if ( vt1 != ValueType.BOOLEAN || vt3 != ValueType.BOOLEAN - || (vt2 != null && vt2 != ValueType.BOOLEAN) ) - throw new DMLRuntimeException("Unexpected ValueType in ArithmeticInstruction."); - - // Determine appropriate Function Object based on opcode BinaryOperator bop = InstructionUtils.parseBinaryOperator(opcode); - return new BooleanBinaryCPInstruction(bop, in1, in2, out, opcode, str); + + if ( in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR ) + return new BooleanBinaryCPInstruction(bop, in1, in2, out, opcode, str); + else if ( in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX ) + return new MatrixMatrixArithmeticCPInstruction(bop, in1, in2, out, opcode, str); + else + return new ScalarMatrixArithmeticCPInstruction(bop, in1, in2, out, opcode, str); } @Override http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/cp/UnaryCPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/UnaryCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/UnaryCPInstruction.java index f3f903a..a89f2bc 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/cp/UnaryCPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/UnaryCPInstruction.java @@ -24,6 +24,7 @@ import org.apache.sysml.runtime.functionobjects.Not; import org.apache.sysml.runtime.instructions.InstructionUtils; import org.apache.sysml.runtime.matrix.operators.Operator; import org.apache.sysml.runtime.matrix.operators.SimpleOperator; +import org.apache.sysml.runtime.matrix.operators.UnaryOperator; public abstract class UnaryCPInstruction extends ComputationCPInstruction { @@ -87,7 +88,7 @@ public abstract class UnaryCPInstruction extends ComputationCPInstruction { } return opcode; } - + static SimpleOperator getSimpleUnaryOperator(String opcode) throws DMLRuntimeException { if (opcode.equalsIgnoreCase("!")) @@ -95,4 +96,12 @@ public abstract class UnaryCPInstruction extends ComputationCPInstruction { throw new DMLRuntimeException("Unknown unary operator " + opcode); } + + static UnaryOperator getUnaryOperator(String opcode) + throws DMLRuntimeException { + if (opcode.equalsIgnoreCase("!")) + return new UnaryOperator(Not.getNotFnObject()); + + throw new DMLRuntimeException("Unknown unary operator " + opcode); + } } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java index 0bd28a1..d042ce6 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/BuiltinBinarySPInstruction.java @@ -66,7 +66,7 @@ public abstract class BuiltinBinarySPInstruction extends BinarySPInstruction { } else //default builtin function { - opcode = parseBinaryInstruction(str, in1, in2, out); + opcode = parseBinaryInstruction(str, in1, in2, out); func = Builtin.getBuiltinFnObject(opcode); } @@ -74,7 +74,7 @@ public abstract class BuiltinBinarySPInstruction extends BinarySPInstruction { if( func == null ) throw new DMLRuntimeException("Failed to create builtin value function for opcode: "+opcode); - // Determine appropriate Function Object based on opcode + // Determine appropriate Function Object based on opcode if (in1.getDataType() != in2.getDataType()) //MATRIX-SCALAR { return new MatrixScalarBuiltinSPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java index 945ab85..95a355d 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/MatrixMatrixArithmeticSPInstruction.java @@ -29,13 +29,6 @@ public class MatrixMatrixArithmeticSPInstruction extends ArithmeticBinarySPInstr protected MatrixMatrixArithmeticSPInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) throws DMLRuntimeException { super(op, in1, in2, out, opcode, istr); - - // sanity check opcodes - if (!(opcode.equalsIgnoreCase("+") || opcode.equalsIgnoreCase("-") || opcode.equalsIgnoreCase("*") - || opcode.equalsIgnoreCase("/") || opcode.equalsIgnoreCase("%%") || opcode.equalsIgnoreCase("%/%") - || opcode.equalsIgnoreCase("^") || opcode.equalsIgnoreCase("1-*"))) { - throw new DMLRuntimeException("Unknown opcode in MatrixMatrixArithmeticSPInstruction: " + toString()); - } } @Override @@ -45,5 +38,4 @@ public class MatrixMatrixArithmeticSPInstruction extends ArithmeticBinarySPInstr //common binary matrix-matrix process instruction super.processMatrixMatrixBinaryInstruction(ec); } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java index ae7da3d..ba28866 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/SPInstruction.java @@ -31,7 +31,8 @@ public abstract class SPInstruction extends Instruction { public enum SPINSTRUCTION_TYPE { MAPMM, MAPMMCHAIN, CPMM, RMM, TSMM, TSMM2, PMM, ZIPMM, PMAPMM, //matrix multiplication instructions - MatrixIndexing, Reorg, ArithmeticBinary, RelationalBinary, AggregateUnary, AggregateTernary, Reblock, CSVReblock, + MatrixIndexing, Reorg, ArithmeticBinary, RelationalBinary, + AggregateUnary, AggregateTernary, Reblock, CSVReblock, Builtin, BuiltinUnary, BuiltinBinary, BuiltinNary, MultiReturnBuiltin, Checkpoint, Compression, Cast, CentralMoment, Covariance, QSort, QPick, ParameterizedBuiltin, MAppend, RAppend, GAppend, GAlignedAppend, Rand, http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java index ea72767..16c8d2d 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java @@ -788,9 +788,9 @@ public class LibMatrixBincell * * This will do cell wise operation for <, <=, >, >=, == and != operators. * - * @param mbLeft left matrix - * @param mbRight right matrix - * @param mbOut output matrix + * @param m1 left matrix + * @param m2 right matrix + * @param ret output matrix * @param bOp binary operator * */ @@ -989,7 +989,7 @@ public class LibMatrixBincell * Since this operation is sparse-unsafe, ret should always be passed in dense representation. * * @param m1 input matrix - * @param m2 result matrix + * @param ret result matrix * @param op scalar operator * @throws DMLRuntimeException if DMLRuntimeException occurs */ http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/matrix/operators/BinaryOperator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/operators/BinaryOperator.java b/src/main/java/org/apache/sysml/runtime/matrix/operators/BinaryOperator.java index 60cae66..1c1b3c5 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/operators/BinaryOperator.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/operators/BinaryOperator.java @@ -55,7 +55,7 @@ public class BinaryOperator extends Operator implements Serializable public BinaryOperator(ValueFunction p) { //binaryop is sparse-safe iff (0 op 0) == 0 super (p instanceof Plus || p instanceof Multiply || p instanceof Minus - || p instanceof And || p instanceof Or + || p instanceof And || p instanceof Or || p instanceof Xor || p instanceof PlusMultiply || p instanceof MinusMultiply); fn = p; } http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/main/java/org/apache/sysml/runtime/matrix/operators/UnaryOperator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/operators/UnaryOperator.java b/src/main/java/org/apache/sysml/runtime/matrix/operators/UnaryOperator.java index a02c3d2..3b071e2 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/operators/UnaryOperator.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/operators/UnaryOperator.java @@ -35,7 +35,7 @@ public class UnaryOperator extends Operator } public UnaryOperator(ValueFunction p, int numThreads) { - super(p instanceof Builtin && + super(p instanceof Builtin && ((Builtin)p).bFunc==Builtin.BuiltinCode.SIN || ((Builtin)p).bFunc==Builtin.BuiltinCode.TAN // sinh and tanh are zero only at zero, else they are nnz || ((Builtin)p).bFunc==Builtin.BuiltinCode.SINH || ((Builtin)p).bFunc==Builtin.BuiltinCode.TANH http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseLogicalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseLogicalTest.java b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseLogicalTest.java new file mode 100644 index 0000000..0488a26 --- /dev/null +++ b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseLogicalTest.java @@ -0,0 +1,229 @@ +/* + * 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.test.integration.functions.binary.matrix; + + +import java.util.HashMap; + +import org.apache.sysml.api.DMLScript; +import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM; +import org.apache.sysml.lops.LopProperties.ExecType; +import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; +import org.apache.sysml.test.integration.AutomatedTestBase; +import org.apache.sysml.test.integration.TestConfiguration; +import org.apache.sysml.test.utils.TestUtils; +import org.junit.Test; + +/** + * This tests elementwise xor operations + * + * + */ +public class ElementwiseLogicalTest extends AutomatedTestBase{ + + private final static String TEST_NAME1 = "ElementwiseAndTest"; + private final static String TEST_NAME2 = "ElementwiseOrTest"; + private final static String TEST_NAME3 = "ElementwiseNotTest"; + private final static String TEST_NAME4 = "ElementwiseXorTest"; + + private final static String TEST_DIR = "functions/binary/matrix/"; + private static final String TEST_CLASS_DIR = TEST_DIR + ElementwiseLogicalTest.class.getSimpleName() + "/"; + + private final static int rows = 2100; + private final static int cols = 70; + private final static double sparsity1 = 0.9;//dense + private final static double sparsity2 = 0.1;//sparse + private final static double eps = 1e-10; + + @Override + public void setUp() { + addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "C" })); + addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[] { "C" })); + addTestConfiguration(TEST_NAME3, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME3, new String[] { "C" })); + addTestConfiguration(TEST_NAME4, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME4, new String[] { "C" })); + } + + @Test + public void testAndDenseCP() { + runLogical(TEST_NAME1, false, ExecType.CP); + } + + @Test + public void testAndSparseCP() { + runLogical(TEST_NAME1, true, ExecType.CP); + } + + @Test + public void testAndDenseSP() { + runLogical(TEST_NAME1, false, ExecType.SPARK); + } + + @Test + public void testAndSparseSP() { + runLogical(TEST_NAME1, true, ExecType.SPARK); + } + + @Test + public void testAndDenseMR() { + runLogical(TEST_NAME1, false, ExecType.MR); + } + + @Test + public void testAndSparseMR() { + runLogical(TEST_NAME1, true, ExecType.MR); + } + + @Test + public void testOrDenseCP() { + runLogical(TEST_NAME2, false, ExecType.CP); + } + + @Test + public void testOrSparseCP() { + runLogical(TEST_NAME2, true, ExecType.CP); + } + + @Test + public void testOrDenseSP() { + runLogical(TEST_NAME2, false, ExecType.SPARK); + } + + @Test + public void testOrSparseSP() { + runLogical(TEST_NAME2, true, ExecType.SPARK); + } + + @Test + public void testOrDenseMR() { + runLogical(TEST_NAME2, false, ExecType.MR); + } + + @Test + public void testOrSparseMR() { + runLogical(TEST_NAME2, true, ExecType.MR); + } + +//TODO support for unary not requires some more cleanups +// @Test +// public void testNotDenseCP() { +// runLogical(TEST_NAME3, false, ExecType.CP); +// } +// +// @Test +// public void testNotSparseCP() { +// runLogical(TEST_NAME3, true, ExecType.CP); +// } +// +// @Test +// public void testNotDenseSP() { +// runLogical(TEST_NAME3, false, ExecType.SPARK); +// } +// +// @Test +// public void testNotSparseSP() { +// runLogical(TEST_NAME3, true, ExecType.SPARK); +// } +// +// @Test +// public void testNotDenseMR() { +// runLogical(TEST_NAME3, false, ExecType.MR); +// } +// +// @Test +// public void testNotSparseMR() { +// runLogical(TEST_NAME3, true, ExecType.MR); +// } + + @Test + public void testXorDenseCP() { + runLogical(TEST_NAME4, false, ExecType.CP); + } + + @Test + public void testXorSparseCP() { + runLogical(TEST_NAME4, true, ExecType.CP); + } + + @Test + public void testXorDenseSP() { + runLogical(TEST_NAME4, false, ExecType.SPARK); + } + + @Test + public void testXorSparseSP() { + runLogical(TEST_NAME4, true, ExecType.SPARK); + } + + @Test + public void testXorDenseMR() { + runLogical(TEST_NAME4, false, ExecType.MR); + } + + @Test + public void testXorSparseMR() { + runLogical(TEST_NAME4, true, ExecType.MR); + } + + private void runLogical(String testname, boolean sparse, ExecType et) { + //rtplatform for MR + RUNTIME_PLATFORM platformOld = rtplatform; + switch( et ){ + case MR: rtplatform = RUNTIME_PLATFORM.HADOOP; break; + case SPARK: rtplatform = RUNTIME_PLATFORM.SPARK; break; + default: rtplatform = RUNTIME_PLATFORM.HYBRID_SPARK; break; + } + + boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG; + if( rtplatform == RUNTIME_PLATFORM.SPARK || rtplatform == RUNTIME_PLATFORM.HYBRID_SPARK ) + DMLScript.USE_LOCAL_SPARK_CONFIG = true; + + try { + String TEST_NAME = testname; + getAndLoadTestConfiguration(TEST_NAME); + + String HOME = SCRIPT_DIR + TEST_DIR; + fullDMLScriptName = HOME + TEST_NAME + ".dml"; + programArgs = new String[]{"-explain","-args", input("A"), input("B"), output("C")}; + + fullRScriptName = HOME + TEST_NAME + ".R"; + rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir() + " " + expectedDir(); + + //get a random matrix of values with (-0.5, 0, 1] + double[][] A = getRandomMatrix(rows, cols, -0.5, 1, sparse ? sparsity1 : sparsity2, 1234); + double[][] B = getRandomMatrix(rows, cols, -0.5, 1, sparse ? sparsity1 : sparsity2, 5678); + writeInputMatrixWithMTD("A", A, true); + writeInputMatrixWithMTD("B", B, true); + + //run tests + runTest(true, false, null, -1); + runRScript(true); + + //compare matrices + HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("C"); + HashMap<CellIndex, Double> rfile = readRMatrixFromFS("C"); + TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R"); + } + finally { + DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld; + rtplatform = platformOld; + } + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.R new file mode 100644 index 0000000..8bf870d --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.R @@ -0,0 +1,34 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +A <- readMM(paste(args[1], "A.mtx", sep="")) +B <- readMM(paste(args[1], "B.mtx", sep="")) + +C = A & B; + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); + + http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.dml new file mode 100644 index 0000000..dcb637d --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseAndTest.dml @@ -0,0 +1,27 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +A = read($1); +B = read($2); + +C = (A & B); + +write(C, $3); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.R new file mode 100644 index 0000000..25b38e3 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.R @@ -0,0 +1,31 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +A <- readMM(paste(args[1], "A.mtx", sep="")) + +C = !A; + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.dml new file mode 100644 index 0000000..e68d049 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseNotTest.dml @@ -0,0 +1,26 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +A = read($1); + +C = !A; + +write(C, $3); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.R new file mode 100644 index 0000000..3326c79 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.R @@ -0,0 +1,32 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +A <- readMM(paste(args[1], "A.mtx", sep="")) +B <- readMM(paste(args[1], "B.mtx", sep="")) + +C = A | B; + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.dml new file mode 100644 index 0000000..8a84694 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseOrTest.dml @@ -0,0 +1,27 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +A = read($1); +B = read($2); + +C = (A | B); + +write(C, $3); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.R new file mode 100644 index 0000000..ed50d45 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.R @@ -0,0 +1,32 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +A <- readMM(paste(args[1], "A.mtx", sep="")) +B <- readMM(paste(args[1], "B.mtx", sep="")) + +C = xor(A,B); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.dml new file mode 100644 index 0000000..1b4a4be --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseXorTest.dml @@ -0,0 +1,27 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +A = read($1); +B = read($2); + +C = xor(A, B); + +write(C, $3); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/ea77cb45/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix/ZPackageSuite.java ---------------------------------------------------------------------- diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix/ZPackageSuite.java index 8652300..4011fc8 100644 --- a/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix/ZPackageSuite.java +++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix/ZPackageSuite.java @@ -33,6 +33,7 @@ import org.junit.runners.Suite; ElementwiseAdditionMultiplicationTest.class, ElementwiseAdditionTest.class, ElementwiseDivisionTest.class, + ElementwiseLogicalTest.class, ElementwiseModulusTest.class, ElementwiseMultiplicationTest.class, ElementwiseSubtractionTest.class,
