Repository: incubator-systemml
Updated Branches:
  refs/heads/master 770c34bc4 -> 693afd414


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/RelationalBinaryCPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/RelationalBinaryCPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/RelationalBinaryCPInstruction.java
index dedfe56..8046de9 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/RelationalBinaryCPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/RelationalBinaryCPInstruction.java
@@ -28,7 +28,7 @@ import org.apache.sysml.runtime.matrix.operators.Operator;
 
 public abstract class RelationalBinaryCPInstruction extends 
BinaryCPInstruction 
 {
-       public RelationalBinaryCPInstruction(Operator op, CPOperand in1, 
CPOperand in2, CPOperand out, String opcode, String istr ) {
+       public RelationalBinaryCPInstruction(Operator op, CPOperand in1, 
CPOperand in2, CPOperand out, String opcode, String istr) {
                super(op, in1, in2, out, opcode, istr);
                _cptype = CPINSTRUCTION_TYPE.RelationalBinary;
        }
@@ -40,29 +40,15 @@ public abstract class RelationalBinaryCPInstruction extends 
BinaryCPInstruction
                CPOperand out = new CPOperand("", ValueType.UNKNOWN, 
DataType.UNKNOWN);
                String opcode = parseBinaryInstruction(str, in1, in2, out);
                
-               ValueType vt1 = in1.getValueType();
-               DataType dt1 = in1.getDataType();
-               DataType dt2 = in2.getDataType();
-               DataType dt3 = out.getDataType();
+               checkOutputDataType(in1, in2, out);
                
-               if( vt1 == ValueType.BOOLEAN && !opcode.equalsIgnoreCase("==") 
&& !opcode.equalsIgnoreCase("!=") ) 
-                       throw new DMLRuntimeException("Operation " + opcode + " 
can not be applied on boolean values "
-                                                                               
  + "(Instruction = " + str + ").");
-               
-               // check for valid data type of output
-               if((dt1 == DataType.MATRIX || dt2 == DataType.MATRIX) && dt3 != 
DataType.MATRIX)
-                       throw new DMLRuntimeException("Element-wise matrix 
operations between variables " + in1.getName() + 
-                                       " and " + in2.getName() + " must 
produce a matrix, which " + out.getName() + " is not");
-               
-               Operator operator = (dt1 != dt2) ?
-                                       
InstructionUtils.parseScalarBinaryOperator(opcode, (dt1 == DataType.SCALAR)) : 
+               Operator operator = (in1.getDataType() != in2.getDataType()) ?
+                                       
InstructionUtils.parseScalarBinaryOperator(opcode, (in1.getDataType() == 
DataType.SCALAR)) : 
                                        
InstructionUtils.parseBinaryOperator(opcode);
                
-               //for scalar relational operations we only allow boolean 
operands
-               //or when both operands are numeric (int or double)
-               if(dt1 == DataType.SCALAR && dt2 == DataType.SCALAR)
+               if ( in1.getDataType() == DataType.SCALAR && in2.getDataType() 
== DataType.SCALAR )
                        return new 
ScalarScalarRelationalCPInstruction(operator, in1, in2, out, opcode, str);
-               else if(dt1 == DataType.MATRIX && dt2 == DataType.MATRIX)
+               else if ( in1.getDataType() == DataType.MATRIX && 
in2.getDataType() == DataType.MATRIX )
                        return new 
MatrixMatrixRelationalCPInstruction(operator, in1, in2, out, opcode, str);
                else
                        return new 
ScalarMatrixRelationalCPInstruction(operator, in1, in2, out, opcode, str);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarBuiltinCPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarBuiltinCPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarBuiltinCPInstruction.java
index 5738f4a..3b903c8 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarBuiltinCPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarBuiltinCPInstruction.java
@@ -50,12 +50,7 @@ public class ScalarBuiltinCPInstruction extends 
BuiltinUnaryCPInstruction
                        
                //core execution
                if ( opcode.equalsIgnoreCase("print") ) {
-                       String outString = null;
-                       if (so instanceof BooleanObject) {
-                               outString = ((BooleanObject) 
so).getLanguageSpecificBooleanStringValue();
-                       } else {
-                               outString = so.getStringValue();
-                       }
+                       String outString = so.getLanguageSpecificStringValue();
                        
                        // print to stdout only when suppress flag in DMLScript 
is not set.
                        // The flag will be set, for example, when SystemML is 
invoked in fenced mode from Jaql.
@@ -66,8 +61,7 @@ public class ScalarBuiltinCPInstruction extends 
BuiltinUnaryCPInstruction
                        sores = new StringObject(outString);
                }
                else if ( opcode.equalsIgnoreCase("stop") ) {
-                       String msg = so.getStringValue();
-                       throw new DMLScriptException(msg);
+                       throw new DMLScriptException(so.getStringValue());
                }
                else {
                        //Inputs for all builtins other than PRINT are treated 
as DOUBLE.

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarObject.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarObject.java 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarObject.java
index b3f2066..1529dc1 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarObject.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarObject.java
@@ -24,7 +24,6 @@ import org.apache.sysml.parser.Expression.ValueType;
 
 public abstract class ScalarObject extends Data
 {
-
        private static final long serialVersionUID = 6994413375932824892L;
 
        private String _name;
@@ -46,6 +45,19 @@ public abstract class ScalarObject extends Data
 
        public abstract String getStringValue();
        
-       public abstract Object getValue();
+       public String getLanguageSpecificStringValue() {
+               return getStringValue();
+       }
+       
+       public abstract Object getValue();      
        
+       @Override
+       public String toString() { 
+               return getStringValue();
+       }
+       
+       @Override
+       public String getDebugName() {
+               return getStringValue();
+       }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarArithmeticCPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarArithmeticCPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarArithmeticCPInstruction.java
index 1e7a44c..2d6c7fc 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarArithmeticCPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarArithmeticCPInstruction.java
@@ -22,84 +22,45 @@ package org.apache.sysml.runtime.instructions.cp;
 import org.apache.sysml.parser.Expression.ValueType;
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.controlprogram.context.ExecutionContext;
-import org.apache.sysml.runtime.functionobjects.Divide;
-import org.apache.sysml.runtime.functionobjects.Power;
 import org.apache.sysml.runtime.matrix.operators.BinaryOperator;
 import org.apache.sysml.runtime.matrix.operators.Operator;
 
 
 public class ScalarScalarArithmeticCPInstruction extends 
ArithmeticBinaryCPInstruction
-{
-       
-       public ScalarScalarArithmeticCPInstruction(Operator op, 
-                                                                  CPOperand 
in1, 
-                                                                  CPOperand 
in2,
-                                                                  CPOperand 
out, 
-                                                                  String 
opcode,
-                                                                  String istr){
+{      
+       public ScalarScalarArithmeticCPInstruction(Operator op, CPOperand in1, 
CPOperand in2, CPOperand out, String opcode, String istr){
                super(op, in1, in2, out, opcode, istr);
        }
        
        @Override
        public void processInstruction(ExecutionContext ec) throws 
DMLRuntimeException{
-               // 1) Obtain data objects associated with inputs 
                ScalarObject so1 = ec.getScalarInput(input1.getName(), 
input1.getValueType(), input1.isLiteral());
                ScalarObject so2 = ec.getScalarInput(input2.getName(), 
input2.getValueType(), input2.isLiteral() );
-               ScalarObject sores = null;
                
-               
-               // 2) Compute the result value & make an appropriate data 
object 
                BinaryOperator dop = (BinaryOperator) _optr;
-               
-               if( input1.getValueType() == ValueType.STRING 
-                        || input2.getValueType() == ValueType.STRING ) 
-               {
-                       String val1 = null;
-                       if (so1 instanceof BooleanObject) {
-                               val1 = ((BooleanObject) 
so1).getLanguageSpecificBooleanStringValue();
-                       } else {
-                               val1 = so1.getStringValue();
-                       }
-                       String val2 = null;
-                       if (so2 instanceof BooleanObject) {
-                               val2 = ((BooleanObject) 
so2).getLanguageSpecificBooleanStringValue();
-                       } else {
-                               val2 = so2.getStringValue();
-                       }
-                       //pre-check (for robustness regarding too long strings)
-                       // This line was commented out because of the addition 
of 
-                       // the built-in function toString.
-                       // The toString function adds its own memory estimation
-                       // and does not need a hard check on the limit of the 
size of the string.
-                       // StringObject.checkMaxStringLength(val1.length() + 
val2.length());
-                       
-                       String rval = dop.fn.execute(val1, val2);
-                       sores = new StringObject(rval);
+               ScalarObject sores = null;
+
+               //compute output value, incl implicit type promotion if 
necessary
+               if( so1 instanceof StringObject || so2 instanceof StringObject 
) {
+                       if( !getOpcode().equals("+") ) //not string 
concatenation
+                               throw new DMLRuntimeException("Arithmetic 
'"+getOpcode()+"' not supported over string inputs.");
+                       sores = new StringObject( dop.fn.execute(
+                               so1.getLanguageSpecificStringValue(), 
so2.getLanguageSpecificStringValue()) );
+               }
+               else if( so1 instanceof DoubleObject || so2 instanceof 
DoubleObject || output.getValueType()==ValueType.DOUBLE ) {
+                       sores = new DoubleObject( 
dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue()) );
                }
-               else if ( so1 instanceof IntObject && so2 instanceof IntObject 
) {
-                       if ( dop.fn instanceof Divide || dop.fn instanceof 
Power ) {
-                               // If both inputs are of type INT then output 
must be an INT if operation is not divide or power
-                               double rval = dop.fn.execute( 
so1.getLongValue(), so2.getLongValue() );
-                               sores = new DoubleObject(rval);
-                       }
-                       else {
-                               // If both inputs are of type INT then output 
must be an INT if operation is not divide or power
-                               double tmpVal = dop.fn.execute( 
so1.getLongValue(), so2.getLongValue() );
-                               //cast to long if no overflow, otherwise 
controlled exception
-                               if( tmpVal > Long.MAX_VALUE )
-                                       throw new DMLRuntimeException("Integer 
operation created numerical result overflow ("+tmpVal+" > 
"+Long.MAX_VALUE+").");
-                               sores = new IntObject((long) tmpVal);
-                       }
+               else if( so1 instanceof IntObject || so2 instanceof IntObject ) 
{
+                       double tmp = dop.fn.execute(so1.getLongValue(), 
so2.getLongValue());
+                       if( tmp > Long.MAX_VALUE ) //cast to long if no 
overflow, otherwise controlled exception
+                               throw new DMLRuntimeException("Integer 
operation created numerical result overflow ("+tmp+" > "+Long.MAX_VALUE+").");
+                       sores = new IntObject((long) tmp);
                }
-               //NOTE: boolean-boolean arithmetic covered by general case 
below in order
-               //to maintain consistency with R
-               else {
-                       // If either of the input is of type DOUBLE then output 
is a DOUBLE
-                       double rval = dop.fn.execute ( so1.getDoubleValue(), 
so2.getDoubleValue() );
-                       sores = new DoubleObject(rval); 
+               else { //all boolean
+                       //NOTE: boolean-boolean arithmetic treated as double 
for consistency with R
+                       sores = new DoubleObject( 
dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue()) );
                }
                
-               // 3) Put the result value into ProgramBlock
                ec.setScalarOutput(output.getName(), sores);
        }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarBuiltinCPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarBuiltinCPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarBuiltinCPInstruction.java
index c831741..3126e86 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarBuiltinCPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarBuiltinCPInstruction.java
@@ -19,7 +19,6 @@
 
 package org.apache.sysml.runtime.instructions.cp;
 
-import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.parser.Expression.ValueType;
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.controlprogram.context.ExecutionContext;
@@ -29,66 +28,30 @@ import org.apache.sysml.runtime.matrix.operators.Operator;
 
 public class ScalarScalarBuiltinCPInstruction extends 
BuiltinBinaryCPInstruction
 {
-       
-       public ScalarScalarBuiltinCPInstruction(Operator op,
-                                                                               
        CPOperand in1,
-                                                                               
        CPOperand in2,
-                                                                               
        CPOperand out,
-                                                                               
        String opcode,
-                                                                               
        String instr){
+       public ScalarScalarBuiltinCPInstruction(Operator op, CPOperand in1, 
CPOperand in2, CPOperand out, String opcode, String instr){
                super(op, in1, in2, out, 2, opcode, instr);
        }
 
        @Override 
-       public void processInstruction(ExecutionContext ec) throws 
DMLRuntimeException {
-               
-               String opcode = getOpcode();
-               ScalarObject sores = null;
-               
+       public void processInstruction(ExecutionContext ec) 
+               throws DMLRuntimeException 
+       {
                ScalarObject so1 = ec.getScalarInput( input1.getName(), 
input1.getValueType(), input1.isLiteral() );
                ScalarObject so2 = ec.getScalarInput(input2.getName(), 
input2.getValueType(), input2.isLiteral() );
                
-               if ( opcode.equalsIgnoreCase("print") ) {
-                       String buffer = "";
-                       if (input2.getValueType() != ValueType.STRING)
-                               throw new DMLRuntimeException("wrong value type 
in print");
-                       buffer = so2.getStringValue() + " ";
-                       
-                       if ( !DMLScript.suppressPrint2Stdout()) {
-                               switch (input1.getValueType()) {
-                                       case INT:
-                                               System.out.println(buffer + 
so1.getLongValue());
-                                               break;
-                                       case DOUBLE:
-                                               System.out.println(buffer + 
so1.getDoubleValue());
-                                               break;
-                                       case BOOLEAN:
-                                               System.out.println(buffer + 
((BooleanObject) so1).getLanguageSpecificBooleanStringValue());
-                                               break;
-                                       case STRING:
-                                               System.out.println(buffer + 
so1.getStringValue());
-                                               break;
-                                       default:
-                                               //do nothing
-                               }
-                       }
-               }
-               else {
-                       BinaryOperator dop = (BinaryOperator) _optr;
-                       
-                       if ( so1 instanceof IntObject 
-                                       && so2 instanceof IntObject 
-                                       && output.getValueType() == 
ValueType.INT) {
-                               long rval = (long) 
dop.fn.execute(so1.getLongValue(), so2.getLongValue());
-                               sores = (ScalarObject) new IntObject(rval);
-                       }
-                       else {
-                               double rval = 
dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue());
-                               sores = (ScalarObject) new DoubleObject(rval);
-                       }
-               }
+               BinaryOperator dop = (BinaryOperator) _optr;
+               ScalarObject sores = null;
+               
+               //compute output value, incl implicit type promotion if 
necessary
+               if( so1 instanceof StringObject || so2 instanceof StringObject )
+                       throw new DMLRuntimeException("Binary builtin 
'"+getOpcode()+"' not supported over string inputs.");
+               else if( so1 instanceof DoubleObject || so2 instanceof 
DoubleObject || output.getValueType()==ValueType.DOUBLE )
+                       sores = new DoubleObject(dop.fn.execute( 
so1.getDoubleValue(), so2.getDoubleValue() ));
+               else if( so1 instanceof IntObject || so2 instanceof IntObject )
+                       sores = new IntObject((long)dop.fn.execute( 
so1.getLongValue(), so2.getLongValue() ));
+               else //all boolean
+                       throw new DMLRuntimeException("Binary builtin 
'"+getOpcode()+"' not supported over boolean inputs.");
                
-               // 3) Put the result value into ProgramBlock
                ec.setScalarOutput(output.getName(), sores);
        }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarRelationalCPInstruction.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarRelationalCPInstruction.java
 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarRelationalCPInstruction.java
index ca2b12e..be2f493 100644
--- 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarRelationalCPInstruction.java
+++ 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/ScalarScalarRelationalCPInstruction.java
@@ -21,19 +21,14 @@ package org.apache.sysml.runtime.instructions.cp;
 
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.controlprogram.context.ExecutionContext;
+import org.apache.sysml.runtime.functionobjects.ValueComparisonFunction;
 import org.apache.sysml.runtime.matrix.operators.BinaryOperator;
 import org.apache.sysml.runtime.matrix.operators.Operator;
 
 
 public class ScalarScalarRelationalCPInstruction extends 
RelationalBinaryCPInstruction
-{
-       
-       public ScalarScalarRelationalCPInstruction(Operator op, 
-                                                                               
           CPOperand in1, 
-                                                                               
           CPOperand in2,
-                                                                               
           CPOperand out, 
-                                                                               
           String opcode,
-                                                                               
           String istr){
+{      
+       public ScalarScalarRelationalCPInstruction(Operator op, CPOperand in1, 
CPOperand in2, CPOperand out, String opcode, String istr) {
                super(op, in1, in2, out, opcode, istr);
        }
        
@@ -43,38 +38,21 @@ public class ScalarScalarRelationalCPInstruction extends 
RelationalBinaryCPInstr
        {
                ScalarObject so1 = ec.getScalarInput(input1.getName(), 
input1.getValueType(), input1.isLiteral());
                ScalarObject so2 = ec.getScalarInput(input2.getName(), 
input2.getValueType(), input2.isLiteral() );
-               ScalarObject sores = null;
                
-               BinaryOperator dop = (BinaryOperator) _optr;
+               ValueComparisonFunction vcomp = 
((ValueComparisonFunction)((BinaryOperator)_optr).fn);
+               boolean rval = false;
                
-               if ( (so1 instanceof IntObject || so1 instanceof BooleanObject) 
-                               && (so2 instanceof IntObject || so2 instanceof 
BooleanObject)  ) {
-                       boolean rval = dop.fn.compare ( so1.getLongValue(), 
so2.getLongValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else if ( so1 instanceof DoubleObject && so2 instanceof 
DoubleObject ) {
-                       boolean rval = dop.fn.compare ( so1.getDoubleValue(), 
so2.getDoubleValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else if ( so1 instanceof BooleanObject && so2 instanceof 
BooleanObject ) {
-                       boolean rval = dop.fn.compare ( so1.getBooleanValue(), 
so2.getBooleanValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else if ( so1 instanceof StringObject && so2 instanceof 
StringObject ) {
-                       boolean rval = dop.fn.compare ( so1.getStringValue(), 
so2.getStringValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else if ( so1 instanceof IntObject && so2 instanceof 
DoubleObject) {
-                       boolean rval = dop.fn.compare ( so1.getLongValue(), 
so2.getDoubleValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else if ( so1 instanceof DoubleObject && so2 instanceof 
IntObject ) {
-                       boolean rval = dop.fn.compare ( so1.getDoubleValue(), 
so2.getLongValue() );
-                       sores = (ScalarObject) new BooleanObject(rval); 
-               }
-               else throw new DMLRuntimeException("compare(): Invalid 
combination of value types "
-                               + "(" + so1.getValueType() + ", " + 
so2.getValueType() + ").");
+               //compute output value, incl implicit type promotion if 
necessary
+               if( so1 instanceof StringObject || so2 instanceof StringObject )
+                       rval = vcomp.compare ( so1.getStringValue(), 
so2.getStringValue() );
+               else if( so1 instanceof DoubleObject || so2 instanceof 
DoubleObject )
+                       rval = vcomp.compare( so1.getDoubleValue(), 
so2.getDoubleValue() );
+               else if( so1 instanceof IntObject || so2 instanceof IntObject )
+                       rval = vcomp.compare( so1.getLongValue(), 
so2.getLongValue() );
+               else //all boolean
+                       rval = vcomp.compare( so1.getBooleanValue(), 
so2.getBooleanValue() );
                
-               ec.setScalarOutput(output.getName(), sores);
+               //set boolean output value
+               ec.setScalarOutput(output.getName(), new BooleanObject(rval));
        }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/main/java/org/apache/sysml/runtime/instructions/cp/StringObject.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/instructions/cp/StringObject.java 
b/src/main/java/org/apache/sysml/runtime/instructions/cp/StringObject.java
index e953f89..22fdbcd 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/cp/StringObject.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/StringObject.java
@@ -24,7 +24,6 @@ import org.apache.sysml.runtime.DMLRuntimeException;
 
 public class StringObject extends ScalarObject 
 {      
-
        private static final long serialVersionUID = 2464839775369002455L;
 
        private static final int MAX_STRING_SIZE = 1*1024*1024; //1MB
@@ -64,24 +63,13 @@ public class StringObject extends ScalarObject
        public Object getValue(){
                return _value;
        }
-       
-       public String toString() { 
-               return getStringValue();
-       }
-
-       @Override
-       public String getDebugName() {
-               return _value;
-       }
 
        public static void checkMaxStringLength( long len ) 
                throws DMLRuntimeException
        {
-               if( len > MAX_STRING_SIZE )
-               {
-                       throw new DMLRuntimeException(
-                                       "Output string length exceeds maximum 
scalar string length " +
-                                       "("+len+" > "+MAX_STRING_SIZE+").");
+               if( len > MAX_STRING_SIZE ) {
+                       throw new DMLRuntimeException("Output string length 
exceeds maximum "
+                               + "scalar string length ("+len+" > 
"+MAX_STRING_SIZE+").");
                }
        }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/693afd41/src/test/java/org/apache/sysml/test/integration/functions/misc/UnivariateStatsBasicTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/misc/UnivariateStatsBasicTest.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/misc/UnivariateStatsBasicTest.java
new file mode 100644
index 0000000..849b293
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/misc/UnivariateStatsBasicTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.misc;
+
+import org.junit.Test;
+
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.runtime.io.MatrixWriterFactory;
+import org.apache.sysml.runtime.matrix.data.OutputInfo;
+import org.apache.sysml.runtime.util.MapReduceTool;
+import org.apache.sysml.runtime.matrix.MatrixCharacteristics;
+import org.apache.sysml.runtime.matrix.data.MatrixBlock;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+/**
+ * Regression test for sanity test with univariate statistics.
+ * 
+ */
+public class UnivariateStatsBasicTest extends AutomatedTestBase 
+{
+       private static final String TEST_NAME = "Univar-Stats";
+       private static final String TEST_NAME_DATAGEN = 
"genRandData4Univariate";
+
+       private static final String TEST_DIR = "functions/misc/";
+       private static final String TEST_CLASS_DIR = TEST_DIR + 
UnivariateStatsBasicTest.class.getSimpleName() + "/";
+
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration( TEST_NAME, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "R" }) );
+       }
+       
+       @Test
+       public void testUnivariateStatsSingleColumn()  {
+               testUnivariateStats( false );
+       }
+       
+       @Test
+       public void testUnivariateStatsSingleColumnRewrites()  {
+               testUnivariateStats( true );
+       }
+       
+       private void testUnivariateStats( boolean rewrites )
+       {       
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               
+               try
+               {
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       //run univariate stats data generator
+                       fullDMLScriptName = 
"./scripts/datagen/"+TEST_NAME_DATAGEN+".dml";
+                       programArgs = new String[]{ "-args", "100000", "100", 
"10", "1", "2", "3", "4", input("uni.mtx") };
+                       runTest(true, false, null, -1);                         
                        
+                       
+                       //write input types
+                       MatrixBlock mb = new MatrixBlock(1,1,false);
+                       mb.quickSetValue(0, 0, 1);
+                       
MatrixWriterFactory.createMatrixWriter(OutputInfo.CSVOutputInfo)
+                               .writeMatrixToHDFS(mb, input("uni-types.csv"), 
1, 1, 1, 1, 1);
+                       
MapReduceTool.writeMetaDataFile(input("uni-types.csv.mtd"), ValueType.DOUBLE, 
+                                       new MatrixCharacteristics(1,1,1,1,1), 
OutputInfo.CSVOutputInfo);
+                       
+                       //run univariate stats 
+                       fullDMLScriptName = 
"./scripts/algorithms/"+TEST_NAME+".dml";
+                       programArgs = new String[]{ "-explain", "-nvargs", 
"X="+input("uni.mtx"), 
+                               "TYPES="+input("uni-types.csv"), 
"STATS="+output("uni-stats.txt"), "CONSOLE_OUTPUT=TRUE" };
+                       runTest(true, false, null, -1);                         
                        
+               }
+               catch (Exception e) {
+                       throw new RuntimeException(e);
+               }
+               finally {
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+               }       
+       }       
+}
\ No newline at end of file

Reply via email to