Repository: systemml Updated Branches: refs/heads/master 9dc354ac2 -> 7dbbaaa76
[SYSTEMML-2057] New builtin functions for bitwise binary operators Closes #716. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/7dbbaaa7 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/7dbbaaa7 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/7dbbaaa7 Branch: refs/heads/master Commit: 7dbbaaa76f79061d8918cca389a51ac955001ffa Parents: 9dc354a Author: Janardhan Pulivarthi <[email protected]> Authored: Thu Jan 11 15:56:51 2018 -0800 Committer: Matthias Boehm <[email protected]> Committed: Thu Jan 11 15:58:24 2018 -0800 ---------------------------------------------------------------------- .../java/org/apache/sysml/hops/BinaryOp.java | 29 +-- src/main/java/org/apache/sysml/hops/Hop.java | 46 +++- src/main/java/org/apache/sysml/lops/Binary.java | 14 +- .../org/apache/sysml/lops/BinaryScalar.java | 16 +- src/main/java/org/apache/sysml/lops/Unary.java | 20 +- .../sysml/parser/BuiltinFunctionExpression.java | 20 ++ .../org/apache/sysml/parser/DMLTranslator.java | 21 ++ .../org/apache/sysml/parser/Expression.java | 7 +- .../sysml/runtime/functionobjects/BitwAnd.java | 52 ++++ .../sysml/runtime/functionobjects/BitwOr.java | 51 ++++ .../runtime/functionobjects/BitwShiftL.java | 56 ++++ .../runtime/functionobjects/BitwShiftR.java | 51 ++++ .../sysml/runtime/functionobjects/BitwXor.java | 51 ++++ .../instructions/CPInstructionParser.java | 5 + .../runtime/instructions/InstructionUtils.java | 70 ++++- .../instructions/MRInstructionParser.java | 10 + .../instructions/SPInstructionParser.java | 10 + .../matrix/operators/BinaryOperator.java | 16 +- .../matrix/ElementwiseBitwLogicalTest.java | 255 +++++++++++++++++++ .../binary/matrix/ElementwiseBitwAndTest.R | 34 +++ .../binary/matrix/ElementwiseBitwAndTest.dml | 29 +++ .../binary/matrix/ElementwiseBitwOrTest.R | 33 +++ .../binary/matrix/ElementwiseBitwOrTest.dml | 29 +++ .../binary/matrix/ElementwiseBitwShiftLTest.R | 34 +++ .../binary/matrix/ElementwiseBitwShiftLTest.dml | 29 +++ .../binary/matrix/ElementwiseBitwShiftRTest.R | 34 +++ .../binary/matrix/ElementwiseBitwShiftRTest.dml | 29 +++ .../binary/matrix/ElementwiseBitwXorTest.R | 34 +++ .../binary/matrix/ElementwiseBitwXorTest.dml | 29 +++ .../functions/binary/matrix/ZPackageSuite.java | 1 + 30 files changed, 1075 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 20e4dd3..1553b7a 100644 --- a/src/main/java/org/apache/sysml/hops/BinaryOp.java +++ b/src/main/java/org/apache/sysml/hops/BinaryOp.java @@ -222,7 +222,7 @@ public class BinaryOp extends Hop break; } default: - constructLopsBinaryDefault(); + constructLopsBinaryDefault(); } //add reblock/checkpoint lops if necessary @@ -627,12 +627,11 @@ public class BinaryOp extends Hop ot = HopsOpOp2LopsU.get(op); Unary unary1 = new Unary(getInput().get(0).constructLops(), - getInput().get(1).constructLops(), ot, getDataType(), getValueType(), et); + getInput().get(1).constructLops(), ot, getDataType(), getValueType(), et); setOutputDimensions(unary1); setLineNumbers(unary1); setLops(unary1); - } else { @@ -1597,18 +1596,18 @@ public class BinaryOp extends Hop && getInput().get(1) == that2.getInput().get(1)); } - public boolean supportsMatrixScalarOperations() - { - return ( op==OpOp2.PLUS ||op==OpOp2.MINUS - ||op==OpOp2.MULT ||op==OpOp2.DIV - ||op==OpOp2.MODULUS ||op==OpOp2.INTDIV - ||op==OpOp2.LESS ||op==OpOp2.LESSEQUAL - ||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.XOR - ||op==OpOp2.LOG ||op==OpOp2.POW ); + public boolean supportsMatrixScalarOperations() { + return ( op==OpOp2.PLUS ||op==OpOp2.MINUS + ||op==OpOp2.MULT ||op==OpOp2.DIV + ||op==OpOp2.MODULUS ||op==OpOp2.INTDIV + ||op==OpOp2.LESS ||op==OpOp2.LESSEQUAL + ||op==OpOp2.GREATER ||op==OpOp2.GREATEREQUAL + ||op==OpOp2.EQUAL ||op==OpOp2.NOTEQUAL + ||op==OpOp2.MIN ||op==OpOp2.MAX + ||op==OpOp2.LOG ||op==OpOp2.POW + ||op==OpOp2.AND ||op==OpOp2.OR ||op==OpOp2.XOR + ||op==OpOp2.BW_AND ||op==OpOp2.BW_OR ||op==OpOp2.BW_XOR + ||op==OpOp2.BW_SHIFTL ||op==OpOp2.BW_SHIFTR); } public boolean isPPredOperation() http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 667cd09..948394b 100644 --- a/src/main/java/org/apache/sysml/hops/Hop.java +++ b/src/main/java/org/apache/sysml/hops/Hop.java @@ -40,6 +40,7 @@ import org.apache.sysml.lops.LopProperties.ExecType; import org.apache.sysml.lops.LopsException; import org.apache.sysml.lops.Nary; import org.apache.sysml.lops.ReBlock; +import org.apache.sysml.lops.Unary; import org.apache.sysml.lops.UnaryCP; import org.apache.sysml.parser.Expression.DataType; import org.apache.sysml.parser.Expression.ValueType; @@ -311,12 +312,12 @@ public abstract class Hop implements ParseInfo && ((DataOp)this).getInputFormatType() == FileFormatTypes.CSV ) { reblock = new CSVReBlock( input, getRowsInBlock(), getColsInBlock(), - getDataType(), getValueType(), et); + getDataType(), getValueType(), et); } - else //TEXT / MM / BINARYBLOCK / BINARYCELL + else //TEXT / MM / BINARYBLOCK / BINARYCELL { reblock = new ReBlock( input, getRowsInBlock(), getColsInBlock(), - getDataType(), getValueType(), _outputEmptyBlocks, et); + getDataType(), getValueType(), _outputEmptyBlocks, et); } } catch( LopsException ex ) { @@ -373,10 +374,10 @@ public abstract class Hop implements ParseInfo } //construct checkpoint w/ right storage level - Lop input = getLops(); + Lop input = getLops(); Lop chkpoint = new Checkpoint(input, getDataType(), getValueType(), serializedStorage ? Checkpoint.getSerializeStorageLevelString() : - Checkpoint.getDefaultStorageLevelString() ); + Checkpoint.getDefaultStorageLevelString() ); setOutputDimensions( chkpoint ); setLineNumbers( chkpoint ); @@ -415,7 +416,7 @@ public abstract class Hop implements ParseInfo { try { - Lop compress = new Compression(getLops(), getDataType(), getValueType(), et); + Lop compress = new Compression(getLops(), getDataType(), getValueType(), et); setOutputDimensions( compress ); setLineNumbers( compress ); setLops( compress ); @@ -1067,6 +1068,7 @@ public abstract class Hop implements ParseInfo MINUS_NZ, //sparse-safe minus: X-(mean*ppred(X,0,!=)) LOG_NZ, //sparse-safe log; ppred(X,0,"!=")*log(X,0.5) MINUS1_MULT, //1-X*Y + BW_AND, BW_OR, BW_XOR, BW_SHIFTL, BW_SHIFTR, //bitwise operations } // Operations that require 3 operands @@ -1208,6 +1210,11 @@ public abstract class Hop implements ParseInfo HopsOpOp2LopsB.put(OpOp2.SOLVE, Binary.OperationTypes.SOLVE); HopsOpOp2LopsB.put(OpOp2.POW, Binary.OperationTypes.POW); HopsOpOp2LopsB.put(OpOp2.LOG, Binary.OperationTypes.NOTSUPPORTED); + HopsOpOp2LopsB.put(OpOp2.BW_AND, Binary.OperationTypes.BW_AND); + HopsOpOp2LopsB.put(OpOp2.BW_OR, Binary.OperationTypes.BW_OR); + HopsOpOp2LopsB.put(OpOp2.BW_XOR, Binary.OperationTypes.BW_XOR); + HopsOpOp2LopsB.put(OpOp2.BW_SHIFTL, Binary.OperationTypes.BW_SHIFTL); + HopsOpOp2LopsB.put(OpOp2.BW_SHIFTR, Binary.OperationTypes.BW_SHIFTR); } protected static final HashMap<Hop.OpOp2, BinaryScalar.OperationTypes> HopsOpOp2LopsBS; @@ -1233,6 +1240,11 @@ public abstract class Hop implements ParseInfo HopsOpOp2LopsBS.put(OpOp2.LOG, BinaryScalar.OperationTypes.LOG); HopsOpOp2LopsBS.put(OpOp2.POW, BinaryScalar.OperationTypes.POW); HopsOpOp2LopsBS.put(OpOp2.PRINT, BinaryScalar.OperationTypes.PRINT); + HopsOpOp2LopsBS.put(OpOp2.BW_AND, BinaryScalar.OperationTypes.BW_AND); + HopsOpOp2LopsBS.put(OpOp2.BW_OR, BinaryScalar.OperationTypes.BW_OR); + HopsOpOp2LopsBS.put(OpOp2.BW_XOR, BinaryScalar.OperationTypes.BW_XOR); + HopsOpOp2LopsBS.put(OpOp2.BW_SHIFTL, BinaryScalar.OperationTypes.BW_SHIFTL); + HopsOpOp2LopsBS.put(OpOp2.BW_SHIFTR, BinaryScalar.OperationTypes.BW_SHIFTR); } protected static final HashMap<Hop.OpOp2, org.apache.sysml.lops.Unary.OperationTypes> HopsOpOp2LopsU; @@ -1251,14 +1263,20 @@ public abstract class Hop implements ParseInfo HopsOpOp2LopsU.put(OpOp2.GREATER, org.apache.sysml.lops.Unary.OperationTypes.GREATER_THAN); HopsOpOp2LopsU.put(OpOp2.EQUAL, org.apache.sysml.lops.Unary.OperationTypes.EQUALS); HopsOpOp2LopsU.put(OpOp2.NOTEQUAL, org.apache.sysml.lops.Unary.OperationTypes.NOT_EQUALS); - HopsOpOp2LopsU.put(OpOp2.AND, org.apache.sysml.lops.Unary.OperationTypes.NOTSUPPORTED); - HopsOpOp2LopsU.put(OpOp2.OR, org.apache.sysml.lops.Unary.OperationTypes.NOTSUPPORTED); + HopsOpOp2LopsU.put(OpOp2.AND, org.apache.sysml.lops.Unary.OperationTypes.AND); + HopsOpOp2LopsU.put(OpOp2.OR, org.apache.sysml.lops.Unary.OperationTypes.OR); + HopsOpOp2LopsU.put(OpOp2.XOR, org.apache.sysml.lops.Unary.OperationTypes.XOR); HopsOpOp2LopsU.put(OpOp2.MAX, org.apache.sysml.lops.Unary.OperationTypes.MAX); HopsOpOp2LopsU.put(OpOp2.MIN, org.apache.sysml.lops.Unary.OperationTypes.MIN); HopsOpOp2LopsU.put(OpOp2.LOG, org.apache.sysml.lops.Unary.OperationTypes.LOG); HopsOpOp2LopsU.put(OpOp2.POW, org.apache.sysml.lops.Unary.OperationTypes.POW); HopsOpOp2LopsU.put(OpOp2.MINUS_NZ, org.apache.sysml.lops.Unary.OperationTypes.SUBTRACT_NZ); HopsOpOp2LopsU.put(OpOp2.LOG_NZ, org.apache.sysml.lops.Unary.OperationTypes.LOG_NZ); + HopsOpOp2LopsU.put(OpOp2.BW_AND, Unary.OperationTypes.BW_AND); + HopsOpOp2LopsU.put(OpOp2.BW_OR, Unary.OperationTypes.BW_OR); + HopsOpOp2LopsU.put(OpOp2.BW_XOR, Unary.OperationTypes.BW_XOR); + HopsOpOp2LopsU.put(OpOp2.BW_SHIFTL, Unary.OperationTypes.BW_SHIFTL); + HopsOpOp2LopsU.put(OpOp2.BW_SHIFTR, Unary.OperationTypes.BW_SHIFTR); } protected static final HashMap<Hop.OpOp1, org.apache.sysml.lops.Unary.OperationTypes> HopsOpOp1LopsU; @@ -1429,6 +1447,11 @@ public abstract class Hop implements ParseInfo HopsOpOp2String.put(OpOp2.RBIND, "rbind"); HopsOpOp2String.put(OpOp2.SOLVE, "solve"); HopsOpOp2String.put(OpOp2.XOR, "xor"); + HopsOpOp2String.put(OpOp2.BW_AND, "bitwAnd"); + HopsOpOp2String.put(OpOp2.BW_OR, "bitwOr"); + HopsOpOp2String.put(OpOp2.BW_XOR, "bitwXor"); + HopsOpOp2String.put(OpOp2.BW_SHIFTL, "bitwShiftL"); + HopsOpOp2String.put(OpOp2.BW_SHIFTR, "bitwShiftR"); } public static String getBinaryOpCode(OpOp2 op) { @@ -1519,8 +1542,13 @@ public abstract class Hop implements ParseInfo else if( "&".equals(op) ) return OpOp2.AND; else if( "log".equals(op) ) return OpOp2.LOG; else if( "^".equals(op) ) return OpOp2.POW; + else if("bitwAnd".equals(op) ) return OpOp2.BW_AND; + else if("bitwOr".equals(op) ) return OpOp2.BW_OR; + else if("bitwXor".equals(op) ) return OpOp2.BW_XOR; + else if("bitwShiftL".equals(op) ) return OpOp2.BW_SHIFTL; + else if("bitwShiftR".equals(op) ) return OpOp2.BW_SHIFTR; - return null; + return null; } ///////////////////////////////////// http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/lops/Binary.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/lops/Binary.java b/src/main/java/org/apache/sysml/lops/Binary.java index 8cf6e4b..d393ea2 100644 --- a/src/main/java/org/apache/sysml/lops/Binary.java +++ b/src/main/java/org/apache/sysml/lops/Binary.java @@ -36,7 +36,8 @@ public class Binary extends Lop ADD, SUBTRACT, MULTIPLY, DIVIDE, MINUS1_MULTIPLY, MODULUS, INTDIV, MATMULT, LESS_THAN, LESS_THAN_OR_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUALS, EQUALS, NOT_EQUALS, AND, OR, XOR, - MAX, MIN, POW, SOLVE, NOTSUPPORTED + MAX, MIN, POW, SOLVE, NOTSUPPORTED, + BW_AND, BW_OR, BW_XOR, BW_SHIFTL, BW_SHIFTR, //Bitwise operations } private OperationTypes operation; @@ -160,7 +161,16 @@ public class Binary extends Lop /* Binary Builtin Function */ case XOR: return "xor"; - + case BW_AND: + return "bitwAnd"; + case BW_OR: + return "bitwOr"; + case BW_XOR: + return "bitwXor"; + case BW_SHIFTL: + return "bitwShiftL"; + case BW_SHIFTR: + return "bitwShiftR"; /* Builtin Functions */ case MIN: http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/lops/BinaryScalar.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/lops/BinaryScalar.java b/src/main/java/org/apache/sysml/lops/BinaryScalar.java index 6b7903b..f581a9a 100644 --- a/src/main/java/org/apache/sysml/lops/BinaryScalar.java +++ b/src/main/java/org/apache/sysml/lops/BinaryScalar.java @@ -36,8 +36,8 @@ public class BinaryScalar extends Lop ADD, SUBTRACT, MULTIPLY, DIVIDE, MODULUS, INTDIV, LESS_THAN, LESS_THAN_OR_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUALS, EQUALS, NOT_EQUALS, AND, OR, XOR, - LOG,POW,MAX,MIN,PRINT, - IQSIZE, + LOG,POW,MAX,MIN,PRINT,IQSIZE, + BW_AND, BW_OR, BW_XOR, BW_SHIFTL, BW_SHIFTR, //Bitwise operations } private final OperationTypes operation; @@ -149,7 +149,17 @@ public class BinaryScalar extends Lop /* Boolean built in binary function */ case XOR: return "xor"; - + case BW_AND: + return "bitwAnd"; + case BW_OR: + return "bitwOr"; + case BW_XOR: + return "bitwXor"; + case BW_SHIFTL: + return "bitwShiftL"; + case BW_SHIFTR: + return "bitwShiftR"; + /* Builtin Functions */ case LOG: return "log"; http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/lops/Unary.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/lops/Unary.java b/src/main/java/org/apache/sysml/lops/Unary.java index d82819c..03096c2 100644 --- a/src/main/java/org/apache/sysml/lops/Unary.java +++ b/src/main/java/org/apache/sysml/lops/Unary.java @@ -39,7 +39,8 @@ public class Unary extends Lop public enum OperationTypes { ADD, SUBTRACT, SUBTRACTRIGHT, MULTIPLY, MULTIPLY2, DIVIDE, MODULUS, INTDIV, MINUS1_MULTIPLY, POW, POW2, LOG, MAX, MIN, NOT, ABS, SIN, COS, TAN, ASIN, ACOS, ATAN, SINH, COSH, TANH, SIGN, SQRT, EXP, Over, - LESS_THAN, LESS_THAN_OR_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUALS, EQUALS, NOT_EQUALS, + LESS_THAN, LESS_THAN_OR_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUALS, EQUALS, NOT_EQUALS, + AND, OR, XOR, BW_AND, BW_OR, BW_XOR, BW_SHIFTL, BW_SHIFTR, ROUND, CEIL, FLOOR, MR_IQM, INVERSE, CHOLESKY, CUMSUM, CUMPROD, CUMMIN, CUMMAX, SPROP, SIGMOID, SELP, SUBTRACT_NZ, LOG_NZ, @@ -224,7 +225,7 @@ public class Unary extends Lop case SUBTRACT_NZ: return "-nz"; - + case SUBTRACTRIGHT: return "s-r"; @@ -244,7 +245,7 @@ public class Unary extends Lop return "%%"; case INTDIV: - return "%/%"; + return "%/%"; case Over: return "so"; @@ -253,7 +254,7 @@ public class Unary extends Lop return "^"; case POW2: - return "^2"; + return "^2"; case GREATER_THAN: return ">"; @@ -320,7 +321,16 @@ public class Unary extends Lop case CAST_AS_FRAME: return UnaryCP.CAST_AS_FRAME_OPCODE; - + + case AND: return "&&"; + case OR: return "||"; + case XOR: return "xor"; + case BW_AND: return "bitwAnd"; + case BW_OR: return "bitwOr"; + case BW_XOR: return "bitwXor"; + case BW_SHIFTL: return "bitwShiftL"; + case BW_SHIFTR: return "bitwShiftR"; + default: throw new LopsException( "Instruction not defined for Unary operation: " + op); http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java index 07a27c7..e0f4e86 100644 --- a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java +++ b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java @@ -447,6 +447,11 @@ public class BuiltinFunctionExpression extends DataIdentifier break; case XOR: + case BITWISE_AND: + case BITWISE_OR: + case BITWISE_XOR: + case BITWISE_SHIFTL: + case BITWISE_SHIFTR: case MIN: case MAX: //min(X), min(X,s), min(s,X), min(s,r), min(X,Y) @@ -1344,6 +1349,11 @@ public class BuiltinFunctionExpression extends DataIdentifier case FLOOR: case MEDIAN: case XOR: + case BITWISE_AND: + case BITWISE_OR: + case BITWISE_XOR: + case BITWISE_SHIFTL: + case BITWISE_SHIFTR: return true; default: return false; @@ -1737,6 +1747,16 @@ public class BuiltinFunctionExpression extends DataIdentifier bifop = Expression.BuiltinFunctionOp.OUTER; else if ( functionName.equals("xor") ) bifop = Expression.BuiltinFunctionOp.XOR; + else if ( functionName.equals("bitwAnd") ) + bifop = Expression.BuiltinFunctionOp.BITWISE_AND; + else if ( functionName.equals("bitwOr") ) + bifop = Expression.BuiltinFunctionOp.BITWISE_OR; + else if ( functionName.equals("bitwXor") ) + bifop = Expression.BuiltinFunctionOp.BITWISE_XOR; + else if ( functionName.equals("bitwShiftL") ) + bifop = Expression.BuiltinFunctionOp.BITWISE_SHIFTL; + else if ( functionName.equals("bitwShiftR") ) + bifop = Expression.BuiltinFunctionOp.BITWISE_SHIFTR; else return null; http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 94dd4e6..9d88ff7 100644 --- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java +++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java @@ -2662,10 +2662,31 @@ public class DMLTranslator currBuiltinOp = new UnaryOp(target.getName(), target.getDataType(), ValueType.BOOLEAN, Hop.OpOp1.CAST_AS_BOOLEAN, expr); break; + // Boolean binary case XOR: currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), target.getValueType(), Hop.OpOp2.XOR, expr, expr2); break; + case BITWISE_AND: + currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), + target.getValueType(), OpOp2.BW_AND, expr, expr2); + break; + case BITWISE_OR: + currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), + target.getValueType(), OpOp2.BW_OR, expr, expr2); + break; + case BITWISE_XOR: + currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), + target.getValueType(), OpOp2.BW_XOR, expr, expr2); + break; + case BITWISE_SHIFTL: + currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), + target.getValueType(), OpOp2.BW_SHIFTL, expr, expr2); + break; + case BITWISE_SHIFTR: + currBuiltinOp = new BinaryOp(target.getName(), target.getDataType(), + target.getValueType(), OpOp2.BW_SHIFTR, expr, expr2); + break; case ABS: case SIN: http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/parser/Expression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/Expression.java b/src/main/java/org/apache/sysml/parser/Expression.java index ddefd88..19d4d3e 100644 --- a/src/main/java/org/apache/sysml/parser/Expression.java +++ b/src/main/java/org/apache/sysml/parser/Expression.java @@ -136,7 +136,12 @@ public abstract class Expression implements ParseInfo TRACE, TRANS, VAR, - XOR + XOR, + BITWISE_AND, + BITWISE_OR, + BITWISE_XOR, + BITWISE_SHIFTL, + BITWISE_SHIFTR, } /** http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/runtime/functionobjects/BitwAnd.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/BitwAnd.java b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwAnd.java new file mode 100644 index 0000000..63b9642 --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwAnd.java @@ -0,0 +1,52 @@ +/* + * 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 org.apache.sysml.runtime.util.UtilFunctions; + +import java.io.Serializable; + + +public class BitwAnd extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = 6523146102263905602L; + + private static BitwAnd singleObj = null; + + private BitwAnd() { + // nothing to do here + } + + public static BitwAnd getBitwAndFnObject() { + if ( singleObj == null ) + singleObj = new BitwAnd(); + return singleObj; + } + + @Override + public double execute(long in1, long in2) { + return (int)in1 & (int)in2; + } + + @Override + public double execute(double in1, double in2) { + return UtilFunctions.toInt(in1) & UtilFunctions.toInt(in2); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/runtime/functionobjects/BitwOr.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/BitwOr.java b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwOr.java new file mode 100644 index 0000000..acb7308 --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwOr.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.sysml.runtime.util.UtilFunctions; + +import java.io.Serializable; + +public class BitwOr extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = -9172774392245257468L; + + private static BitwOr singleObj = null; + + private BitwOr() { + // nothing to do here + } + + public static BitwOr getBitwOrFnObject() { + if ( singleObj == null ) + singleObj = new BitwOr(); + return singleObj; + } + + @Override + public double execute(long in1, long in2) { + return (int)in1 | (int)in2; + } + + @Override + public double execute(double in1, double in2) { + return UtilFunctions.toInt(in1) | UtilFunctions.toInt(in2); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftL.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftL.java b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftL.java new file mode 100644 index 0000000..921b3cf --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftL.java @@ -0,0 +1,56 @@ +/* + * 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 org.apache.sysml.runtime.util.UtilFunctions; + +import java.io.Serializable; + +public class BitwShiftL extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = -6874923721694361623L; + + private static BitwShiftL singleObj = null; + + private BitwShiftL() { + // nothing to do here + } + + public static BitwShiftL getBitwShiftLFnObject() { + if ( singleObj == null ) + singleObj = new BitwShiftL(); + return singleObj; + } + + @Override + public double execute(long in1, long in2) { + int ret = (int)in1 << (int)in2; + return (ret == Integer.MIN_VALUE) ? Double.NaN : ret; + } + + @Override + public double execute(double in1, double in2) { + //note: we need to account for integer overflows, as R returns 0 in these cases + int v1 = UtilFunctions.toInt(in1); + int v2 = UtilFunctions.toInt(in2); + int ret = v1 << v2; + return (ret == Integer.MIN_VALUE) ? Double.NaN : ret; + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftR.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftR.java b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftR.java new file mode 100644 index 0000000..a39a78a --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwShiftR.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.sysml.runtime.util.UtilFunctions; + +import java.io.Serializable; + +public class BitwShiftR extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = -6746241833459058280L; + + private static BitwShiftR singleObj = null; + + private BitwShiftR() { + // nothing to do here + } + + public static BitwShiftR getBitwShiftRFnObject() { + if ( singleObj == null ) + singleObj = new BitwShiftR(); + return singleObj; + } + + @Override + public double execute(long in1, long in2) { + return in1 >> in2; + } + + @Override + public double execute(double in1, double in2) { + return UtilFunctions.toInt(in1) >> UtilFunctions.toInt(in2); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/main/java/org/apache/sysml/runtime/functionobjects/BitwXor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/functionobjects/BitwXor.java b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwXor.java new file mode 100644 index 0000000..d5c5c26 --- /dev/null +++ b/src/main/java/org/apache/sysml/runtime/functionobjects/BitwXor.java @@ -0,0 +1,51 @@ +/* + * 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 org.apache.sysml.runtime.util.UtilFunctions; + +import java.io.Serializable; + +public class BitwXor extends ValueFunction implements Serializable +{ + private static final long serialVersionUID = -7231003441114081755L; + + private static BitwXor singleObj = null; + + private BitwXor() { + // nothing to do here + } + + public static BitwXor getBitwXorFnObject() { + if ( singleObj == null ) + singleObj = new BitwXor(); + return singleObj; + } + + @Override + public double execute(long in1, long in2) { + return (int)in1 ^ (int)in2; + } + + @Override + public double execute(double in1, double in2) { + return UtilFunctions.toInt(in1) ^ UtilFunctions.toInt(in2); + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 772b487..a7b9d6b 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java @@ -129,6 +129,11 @@ public class CPInstructionParser extends InstructionParser String2CPInstructionType.put( "&&" , CPType.Binary); String2CPInstructionType.put( "||" , CPType.Binary); String2CPInstructionType.put( "xor" , CPType.Binary); + String2CPInstructionType.put( "bitwAnd", CPType.Binary); + String2CPInstructionType.put( "bitwOr", CPType.Binary); + String2CPInstructionType.put( "bitwXor", CPType.Binary); + String2CPInstructionType.put( "bitwShiftL", CPType.Binary); + String2CPInstructionType.put( "bitwShiftR", CPType.Binary); String2CPInstructionType.put( "!" , CPType.Unary); // Relational Instruction Opcodes http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 c75a20b..91a4546 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/InstructionUtils.java @@ -42,6 +42,11 @@ import org.apache.sysml.lops.WeightedUnaryMM; import org.apache.sysml.lops.WeightedUnaryMMR; import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.functionobjects.And; +import org.apache.sysml.runtime.functionobjects.BitwAnd; +import org.apache.sysml.runtime.functionobjects.BitwOr; +import org.apache.sysml.runtime.functionobjects.BitwShiftL; +import org.apache.sysml.runtime.functionobjects.BitwShiftR; +import org.apache.sysml.runtime.functionobjects.BitwXor; import org.apache.sysml.runtime.functionobjects.Builtin; import org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode; import org.apache.sysml.runtime.functionobjects.CM; @@ -85,11 +90,11 @@ import org.apache.sysml.runtime.matrix.operators.AggregateOperator; import org.apache.sysml.runtime.matrix.operators.AggregateTernaryOperator; import org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator; import org.apache.sysml.runtime.matrix.operators.BinaryOperator; +import org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes; import org.apache.sysml.runtime.matrix.operators.LeftScalarOperator; import org.apache.sysml.runtime.matrix.operators.Operator; import org.apache.sysml.runtime.matrix.operators.RightScalarOperator; import org.apache.sysml.runtime.matrix.operators.ScalarOperator; -import org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes; import org.apache.sysml.runtime.matrix.operators.UnaryOperator; @@ -397,7 +402,7 @@ public class InstructionUtils CorrectionLocationType.LASTCOLUMN : CorrectionLocationType.LASTROW; AggregateOperator agg = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, corr); IndexFunction ixfun = opcode.equalsIgnoreCase("tak+*") ? - ReduceAll.getReduceAllFnObject() : ReduceRow.getReduceRowFnObject(); + ReduceAll.getReduceAllFnObject() : ReduceRow.getReduceRowFnObject(); return new AggregateTernaryOperator(Multiply.getMultiplyFnObject(), agg, ixfun, numThreads); } @@ -541,6 +546,16 @@ public class InstructionUtils return new BinaryOperator(Or.getOrFnObject()); else if(opcode.equalsIgnoreCase("xor")) return new BinaryOperator(Xor.getXorFnObject()); + else if(opcode.equalsIgnoreCase("bitwAnd")) + return new BinaryOperator(BitwAnd.getBitwAndFnObject()); + else if(opcode.equalsIgnoreCase("bitwOr")) + return new BinaryOperator(BitwOr.getBitwOrFnObject()); + else if(opcode.equalsIgnoreCase("bitwXor")) + return new BinaryOperator(BitwXor.getBitwXorFnObject()); + else if(opcode.equalsIgnoreCase("bitwShiftL")) + return new BinaryOperator(BitwShiftL.getBitwShiftLFnObject()); + else if(opcode.equalsIgnoreCase("bitwShiftR")) + return new BinaryOperator(BitwShiftR.getBitwShiftRFnObject()); else if(opcode.equalsIgnoreCase("+")) return new BinaryOperator(Plus.getPlusFnObject()); else if(opcode.equalsIgnoreCase("-")) @@ -680,7 +695,46 @@ public class InstructionUtils return new LeftScalarOperator(NotEquals.getNotEqualsFnObject(), constant); return new RightScalarOperator(NotEquals.getNotEqualsFnObject(), constant); } - + else if ( opcode.equalsIgnoreCase("&&") ) { + return arg1IsScalar ? + new LeftScalarOperator(And.getAndFnObject(), constant) : + new RightScalarOperator(And.getAndFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("||") ) { + return arg1IsScalar ? + new LeftScalarOperator(Or.getOrFnObject(), constant) : + new RightScalarOperator(Or.getOrFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("xor") ) { + return arg1IsScalar ? + new LeftScalarOperator(Xor.getXorFnObject(), constant) : + new RightScalarOperator(Xor.getXorFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("bitwAnd") ) { + return arg1IsScalar ? + new LeftScalarOperator(BitwAnd.getBitwAndFnObject(), constant) : + new RightScalarOperator(BitwAnd.getBitwAndFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("bitwOr") ) { + return arg1IsScalar ? + new LeftScalarOperator(BitwOr.getBitwOrFnObject(), constant) : + new RightScalarOperator(BitwOr.getBitwOrFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("bitwXor") ) { + return arg1IsScalar ? + new LeftScalarOperator(BitwXor.getBitwXorFnObject(), constant) : + new RightScalarOperator(BitwXor.getBitwXorFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("bitwShiftL") ) { + return arg1IsScalar ? + new LeftScalarOperator(BitwShiftL.getBitwShiftLFnObject(), constant) : + new RightScalarOperator(BitwShiftL.getBitwShiftLFnObject(), constant); + } + else if ( opcode.equalsIgnoreCase("bitwShiftR") ) { + return arg1IsScalar ? + new LeftScalarOperator(BitwShiftR.getBitwShiftRFnObject(), constant) : + new RightScalarOperator(BitwShiftR.getBitwShiftRFnObject(), constant); + } //operations that only exist for performance purposes (all unary or commutative operators) else if ( opcode.equalsIgnoreCase("*2") ) { return new RightScalarOperator(Multiply2.getMultiply2FnObject(), constant); @@ -724,6 +778,16 @@ public class InstructionUtils return new BinaryOperator(Or.getOrFnObject()); else if(opcode.equalsIgnoreCase("xor") || opcode.equalsIgnoreCase("mapxor")) return new BinaryOperator(Xor.getXorFnObject()); + else if(opcode.equalsIgnoreCase("bitwAnd") || opcode.equalsIgnoreCase("mapbitwAnd")) + return new BinaryOperator(BitwAnd.getBitwAndFnObject()); + else if(opcode.equalsIgnoreCase("bitwOr") || opcode.equalsIgnoreCase("mapbitwOr")) + return new BinaryOperator(BitwOr.getBitwOrFnObject()); + else if(opcode.equalsIgnoreCase("bitwXor") || opcode.equalsIgnoreCase("mapbitwXor")) + return new BinaryOperator(BitwXor.getBitwXorFnObject()); + else if(opcode.equalsIgnoreCase("bitwShiftL") || opcode.equalsIgnoreCase("mapbitwShiftL")) + return new BinaryOperator(BitwShiftL.getBitwShiftLFnObject()); + else if(opcode.equalsIgnoreCase("bitwShiftR") || opcode.equalsIgnoreCase("mapbitwShiftR")) + return new BinaryOperator(BitwShiftR.getBitwShiftRFnObject()); 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/7dbbaaa7/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 f42e10e..0e25d83 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/MRInstructionParser.java @@ -188,6 +188,11 @@ public class MRInstructionParser extends InstructionParser String2MRInstructionType.put( "&&" , MRType.Binary); String2MRInstructionType.put( "||" , MRType.Binary); String2MRInstructionType.put( "xor" , MRType.Binary); + String2MRInstructionType.put( "bitwAnd", MRType.Binary); + String2MRInstructionType.put( "bitwOr", MRType.Binary); + String2MRInstructionType.put( "bitwXor", MRType.Binary); + String2MRInstructionType.put( "bitwShiftL", MRType.Binary); + String2MRInstructionType.put( "bitwShiftR", MRType.Binary); String2MRInstructionType.put( "+*" , MRType.Binary2); String2MRInstructionType.put( "-*" , MRType.Binary2); @@ -210,6 +215,11 @@ public class MRInstructionParser extends InstructionParser String2MRInstructionType.put( "map&&" , MRType.Binary); String2MRInstructionType.put( "map||" , MRType.Binary); String2MRInstructionType.put( "mapxor" , MRType.Binary); + String2MRInstructionType.put( "mapbitwAnd", MRType.Binary); + String2MRInstructionType.put( "mapbitwOr", MRType.Binary); + String2MRInstructionType.put( "mapbitwXor", MRType.Binary); + String2MRInstructionType.put( "mapbitwShiftL", MRType.Binary); + String2MRInstructionType.put( "mapbitwShiftR", MRType.Binary); String2MRInstructionType.put( "uaggouterchain", MRType.UaggOuterChain); http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 268d37b..d625853 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/SPInstructionParser.java @@ -193,10 +193,20 @@ public class SPInstructionParser extends InstructionParser String2SPInstructionType.put( "&&" , SPType.Binary); String2SPInstructionType.put( "||" , SPType.Binary); String2SPInstructionType.put( "xor" , SPType.Binary); + String2SPInstructionType.put( "bitwAnd", SPType.Binary); + String2SPInstructionType.put( "bitwOr", SPType.Binary); + String2SPInstructionType.put( "bitwXor", SPType.Binary); + String2SPInstructionType.put( "bitwShiftL", SPType.Binary); + String2SPInstructionType.put( "bitwShiftR", SPType.Binary); String2SPInstructionType.put( "!" , SPType.Unary); String2SPInstructionType.put( "map&&" , SPType.Binary); String2SPInstructionType.put( "map||" , SPType.Binary); String2SPInstructionType.put( "mapxor" , SPType.Binary); + String2SPInstructionType.put( "mapbitwAnd", SPType.Binary); + String2SPInstructionType.put( "mapbitwOr", SPType.Binary); + String2SPInstructionType.put( "mapbitwXor", SPType.Binary); + String2SPInstructionType.put( "mapbitwShiftL", SPType.Binary); + String2SPInstructionType.put( "mapbitwShiftR", SPType.Binary); // Builtin Instruction Opcodes String2SPInstructionType.put( "max" , SPType.Binary); http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 1c1b3c5..48af5e1 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 @@ -24,7 +24,13 @@ import java.io.Serializable; import org.apache.sysml.hops.Hop.OpOp2; import org.apache.sysml.runtime.functionobjects.And; +import org.apache.sysml.runtime.functionobjects.BitwAnd; +import org.apache.sysml.runtime.functionobjects.BitwOr; +import org.apache.sysml.runtime.functionobjects.BitwShiftL; +import org.apache.sysml.runtime.functionobjects.BitwShiftR; +import org.apache.sysml.runtime.functionobjects.BitwXor; import org.apache.sysml.runtime.functionobjects.Builtin; +import org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode; import org.apache.sysml.runtime.functionobjects.Divide; import org.apache.sysml.runtime.functionobjects.Equals; import org.apache.sysml.runtime.functionobjects.GreaterThan; @@ -44,7 +50,6 @@ import org.apache.sysml.runtime.functionobjects.PlusMultiply; import org.apache.sysml.runtime.functionobjects.Power; import org.apache.sysml.runtime.functionobjects.ValueFunction; import org.apache.sysml.runtime.functionobjects.Xor; -import org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode; public class BinaryOperator extends Operator implements Serializable { @@ -56,7 +61,9 @@ public class BinaryOperator extends Operator implements Serializable //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 Xor - || p instanceof PlusMultiply || p instanceof MinusMultiply); + || p instanceof PlusMultiply || p instanceof MinusMultiply + || p instanceof BitwAnd || p instanceof BitwOr || p instanceof BitwXor + || p instanceof BitwShiftL || p instanceof BitwShiftR); fn = p; } @@ -84,6 +91,11 @@ public class BinaryOperator extends Operator implements Serializable else if( fn instanceof And ) return OpOp2.AND; else if( fn instanceof Or ) return OpOp2.OR; else if( fn instanceof Xor ) return OpOp2.XOR; + else if( fn instanceof BitwAnd ) return OpOp2.BW_AND; + else if( fn instanceof BitwOr ) return OpOp2.BW_OR; + else if( fn instanceof BitwXor ) return OpOp2.BW_XOR; + else if( fn instanceof BitwShiftL ) return OpOp2.BW_SHIFTL; + else if( fn instanceof BitwShiftR ) return OpOp2.BW_SHIFTR; else if( fn instanceof Power ) return OpOp2.POW; else if( fn instanceof MinusNz ) return OpOp2.MINUS_NZ; else if( fn instanceof Builtin ) { http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseBitwLogicalTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseBitwLogicalTest.java b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseBitwLogicalTest.java new file mode 100644 index 0000000..a1255ca --- /dev/null +++ b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix/ElementwiseBitwLogicalTest.java @@ -0,0 +1,255 @@ +/* + * 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 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; +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; + +import java.util.HashMap; + +public class ElementwiseBitwLogicalTest extends AutomatedTestBase{ + + private final static String TEST_NAME1 = "ElementwiseBitwAndTest"; + private final static String TEST_NAME2 = "ElementwiseBitwOrTest"; + private final static String TEST_NAME3 = "ElementwiseBitwXorTest"; + private final static String TEST_NAME4 = "ElementwiseBitwShiftLTest"; + private final static String TEST_NAME5 = "ElementwiseBitwShiftRTest"; + + private final static String TEST_DIR = "functions/binary/matrix/"; + private static final String TEST_CLASS_DIR = TEST_DIR + ElementwiseBitwLogicalTest.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" })); + addTestConfiguration(TEST_NAME5, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME5, new String[] { "C" })); + } + + @Test + public void testBitwAndDenseCP() { + runBitwLogic(TEST_NAME1, false, ExecType.CP); + } + + @Test + public void testBitwAndDenseSP() { + runBitwLogic(TEST_NAME1, false, ExecType.SPARK); + } + + @Test + public void testBitwAndDenseMR() { + runBitwLogic(TEST_NAME1, false, ExecType.MR); + } + + @Test + public void testBitwAndSparseCP() { + runBitwLogic(TEST_NAME1, true, ExecType.CP); + } + + @Test + public void testBitwAndSparseSP() { + runBitwLogic(TEST_NAME1, true, ExecType.SPARK); + } + + @Test + public void testBitwAndSparseMR() { + runBitwLogic(TEST_NAME1, true, ExecType.MR); + } + + @Test + public void testBitwOrDenseCP() { + runBitwLogic(TEST_NAME2, false, ExecType.CP); + } + + @Test + public void testBitwOrDenseSP() { + runBitwLogic(TEST_NAME2, false, ExecType.SPARK); + } + + @Test + public void testBitwOrDenseMR() { + runBitwLogic(TEST_NAME2, false, ExecType.MR); + } + + @Test + public void testBitwOrSparseCP() { + runBitwLogic(TEST_NAME2, true, ExecType.CP); + } + + @Test + public void testBitwOrSparseSP() { + runBitwLogic(TEST_NAME2, true, ExecType.SPARK); + } + + @Test + public void testBitwOrSparseMR() { + runBitwLogic(TEST_NAME2, true, ExecType.MR); + } + + @Test + public void testBitwXorDenseCP() { + runBitwLogic(TEST_NAME3, false, ExecType.CP); + } + + @Test + public void testBitwXorDenseSP() { + runBitwLogic(TEST_NAME3, false, ExecType.SPARK); + } + + @Test + public void testBitwXorDenseMR() { + runBitwLogic(TEST_NAME3, false, ExecType.MR); + } + + @Test + public void testBitwXorSparseCP() { + runBitwLogic(TEST_NAME3, true, ExecType.CP); + } + + @Test + public void testBitwXorSparseSP() { + runBitwLogic(TEST_NAME3, true, ExecType.SPARK); + } + + @Test + public void testBitwXorSparseMR() { + runBitwLogic(TEST_NAME3, true, ExecType.MR); + } + + @Test + public void testBitwShiftLDenseCP() { + runBitwLogic(TEST_NAME4, false, ExecType.CP); + } + + @Test + public void testBitwShiftLDenseSP() { + runBitwLogic(TEST_NAME4, false, ExecType.SPARK); + } + + @Test + public void testBitwShiftLDenseMR() { + runBitwLogic(TEST_NAME4, false, ExecType.MR); + } + + @Test + public void testBitwShiftLSparseCP() { + runBitwLogic(TEST_NAME4, true, ExecType.CP); + } + + @Test + public void testBitwShiftLSparseSP() { + runBitwLogic(TEST_NAME4, true, ExecType.SPARK); + } + + @Test + public void testBitwShiftLSparseMR() { + runBitwLogic(TEST_NAME4, true, ExecType.MR); + } + + @Test + public void testBitwShiftRDenseCP() { + runBitwLogic(TEST_NAME5, false, ExecType.CP); + } + + @Test + public void testBitwShiftRDenseSP() { + runBitwLogic(TEST_NAME5, false, ExecType.SPARK); + } + + @Test + public void testBitwShiftRDenseMR() { + runBitwLogic(TEST_NAME5, false, ExecType.MR); + } + + @Test + public void testBitwShiftRSparseCP() { + runBitwLogic(TEST_NAME5, true, ExecType.CP); + } + + @Test + public void testBitwShiftRSparseSP() { + runBitwLogic(TEST_NAME5, true, ExecType.SPARK); + } + + @Test + public void testBitwShiftRSparseMR() { + runBitwLogic(TEST_NAME5, true, ExecType.MR); + } + + private void runBitwLogic(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 + double[][] A = getRandomMatrix(rows, cols, 1, 31, sparse ? sparsity1 : sparsity2, 1234); + double[][] B = getRandomMatrix(rows, cols, 1, 31, sparse ? sparsity1 : sparsity2, 5678); + writeInputMatrixWithMTD("A", A, true); + writeInputMatrixWithMTD("B", B, true); + + //run tests + runTest(true, false, null, -1); + runRScript(true); + + //compare matrices + HashMap<MatrixValue.CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("C"); + HashMap<MatrixValue.CellIndex, Double> rfile = readRMatrixFromFS("C"); + TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R", true); + } + finally { + DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld; + rtplatform = platformOld; + } + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.R new file mode 100644 index 0000000..f2ea2d9 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.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 = bitwAnd(as.vector(A), as.vector(B)); +C = matrix(C, nrow(A), ncol(A)); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.dml new file mode 100644 index 0000000..6a3661b --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwAndTest.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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); + +print(sum(bitwAnd(A,7))+bitwAnd(7,7)); +C = bitwAnd(A, B); + +write(C, $3); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.R new file mode 100644 index 0000000..1c295dc --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.R @@ -0,0 +1,33 @@ +#------------------------------------------------------------- +# +# 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 = bitwOr(as.vector(A), as.vector(B)); +C = matrix(C, nrow(A), ncol(A)); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.dml new file mode 100644 index 0000000..be8d25c --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwOrTest.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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); + +print(sum(bitwOr(A,7))+bitwOr(7,7)); +C = bitwOr(A, B); + +write(C, $3); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.R new file mode 100644 index 0000000..5bb6f00 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.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 = bitwShiftL(as.vector(A), as.vector(B)); +C = matrix(C, nrow(A), ncol(A)); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.dml new file mode 100644 index 0000000..e0620fb --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftLTest.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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); + +print(sum(bitwShiftL(A,7))+bitwShiftL(7,7)); +C = bitwShiftL(A, B); + +write(C, $3); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.R new file mode 100644 index 0000000..4019fd8 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.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 = bitwShiftR(as.vector(A), as.vector(B)); +C = matrix(C, nrow(A), ncol(A)); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.dml new file mode 100644 index 0000000..bd8c0fe --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwShiftRTest.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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); + +print(sum(bitwShiftR(A,7))+bitwShiftR(7,7)); +C = bitwShiftR(A, B); + +write(C, $3); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.R b/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.R new file mode 100644 index 0000000..f0f1969 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.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 = bitwXor(as.vector(A), as.vector(B)); +C = matrix(C, nrow(A), ncol(A)); + +writeMM(as(C, "CsparseMatrix"), paste(args[2], "C", sep="")); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.dml b/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.dml new file mode 100644 index 0000000..7d7e2d2 --- /dev/null +++ b/src/test/scripts/functions/binary/matrix/ElementwiseBitwXorTest.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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); + +print(sum(bitwXor(A,7))+bitwXor(7,7)); +C = bitwXor(A, B); + +write(C, $3); + http://git-wip-us.apache.org/repos/asf/systemml/blob/7dbbaaa7/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 4011fc8..1dd85fd 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 @@ -34,6 +34,7 @@ import org.junit.runners.Suite; ElementwiseAdditionTest.class, ElementwiseDivisionTest.class, ElementwiseLogicalTest.class, + ElementwiseBitwLogicalTest.class, ElementwiseModulusTest.class, ElementwiseMultiplicationTest.class, ElementwiseSubtractionTest.class,
