http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmKMeans.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmKMeans.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmKMeans.java
new file mode 100644
index 0000000..c131ea8
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmKMeans.java
@@ -0,0 +1,196 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmKMeans extends AutomatedTestBase 
+{      
+       private final static String TEST_NAME1 = "Algorithm_KMeans";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmKMeans.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       //private final static double eps = 1e-5;
+       
+       private final static int rows = 3972;
+       private final static int cols = 972;
+               
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "C" })); 
+       }
+
+       @Test
+       public void testKMeansDenseBinSingleRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, false, 2, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseBinSingleRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, true, 2, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseBinSingleCP() {
+               runKMeansTest(TEST_NAME1, false, false, 2, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseBinSingleCP() {
+               runKMeansTest(TEST_NAME1, false, true, 2, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseBinMultiRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, false, 2, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseBinMultiRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, true, 2, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseBinMultiCP() {
+               runKMeansTest(TEST_NAME1, false, false, 2, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseBinMultiCP() {
+               runKMeansTest(TEST_NAME1, false, true, 2, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseMulSingleRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, false, 20, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseMulSingleRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, true, 20, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseMulSingleCP() {
+               runKMeansTest(TEST_NAME1, false, false, 20, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseMulSingleCP() {
+               runKMeansTest(TEST_NAME1, false, true, 20, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseMulMultiRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, false, 20, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseMulMultiRewritesCP() {
+               runKMeansTest(TEST_NAME1, true, true, 20, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansDenseMulMultiCP() {
+               runKMeansTest(TEST_NAME1, false, false, 20, 10, ExecType.CP);
+       }
+       
+       @Test
+       public void testKMeansSparseMulMultiCP() {
+               runKMeansTest(TEST_NAME1, false, true, 20, 10, ExecType.CP);
+       }
+       
+       private void runKMeansTest( String testname, boolean rewrites, boolean 
sparse, int centroids, int runs, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = "scripts/algorithms/Kmeans.dml";
+                       programArgs = new String[]{ "-explain", "-stats",
+                               "-nvargs", "X="+input("X"), 
"k="+String.valueOf(centroids), "runs="+String.valueOf(runs), 
+                               "tol="+String.valueOf(epsilon), 
"maxi="+String.valueOf(maxiter), "C="+output("C")};
+
+                       //rCmd = getRCmd(inputDir(), 
String.valueOf(intercept),String.valueOf(epsilon),
+                       //      String.valueOf(maxiter), expectedDir());
+
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 714);
+                       writeInputMatrixWithMTD("X", X, true);
+                       
+                       runTest(true, false, null, -1); 
+                       
+                       
Assert.assertTrue(heavyHittersContainsSubString("spoof") || 
heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmL2SVM.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmL2SVM.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmL2SVM.java
new file mode 100644
index 0000000..7666d8f
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmL2SVM.java
@@ -0,0 +1,168 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmL2SVM extends AutomatedTestBase 
+{      
+       private final static String TEST_NAME1 = "Algorithm_L2SVM";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmL2SVM.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static double eps = 1e-5;
+       
+       private final static int rows = 3468;
+       private final static int cols1 = 1007;
+       private final static int cols2 = 987;
+       
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static int intercept = 0;
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testL2SVMDenseRewritesCP() {
+               runL2SVMTest(TEST_NAME1, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testL2SVMSparseRewritesCP() {
+               runL2SVMTest(TEST_NAME1, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testL2SVMDenseCP() {
+               runL2SVMTest(TEST_NAME1, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testL2SVMSparseCP() {
+               runL2SVMTest(TEST_NAME1, false, true, ExecType.CP);
+       }
+
+       @Test
+       public void testL2SVMDenseRewritesSP() {
+               runL2SVMTest(TEST_NAME1, true, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testL2SVMSparseRewritesSP() {
+               runL2SVMTest(TEST_NAME1, true, true, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testL2SVMDenseSP() {
+               runL2SVMTest(TEST_NAME1, false, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testL2SVMSparseSP() {
+               runL2SVMTest(TEST_NAME1, false, true, ExecType.SPARK);
+       }
+       
+       private void runL2SVMTest( String testname, boolean rewrites, boolean 
sparse, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = "scripts/algorithms/l2-svm.dml";
+                       programArgs = new String[]{ "-explain", "-stats", 
"-nvargs", "X="+input("X"), "Y="+input("Y"),
+                               "icpt="+String.valueOf(intercept), 
"tol="+String.valueOf(epsilon), "reg=0.001",
+                               "maxiter="+String.valueOf(maxiter), 
"model="+output("w"), "Log= "};
+
+                       rCmd = getRCmd(inputDir(), 
String.valueOf(intercept),String.valueOf(epsilon),
+                               String.valueOf(maxiter), expectedDir());
+
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       int cols = (instType==ExecType.SPARK) ? cols2 : cols1;
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 714);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 
0, 1, 1.0, 136));
+                       writeInputMatrixWithMTD("Y", y, true);
+                       
+                       runTest(true, false, null, -1); 
+                       runRScript(true); 
+                       
+                       //compare matrices 
+                       HashMap<CellIndex, Double> dmlfile = 
readDMLMatrixFromHDFS("w");
+                       HashMap<CellIndex, Double> rfile  = 
readRMatrixFromFS("w");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+                       
Assert.assertTrue(heavyHittersContainsSubString("spoof") || 
heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmLinregCG.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmLinregCG.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmLinregCG.java
new file mode 100644
index 0000000..3031df0
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmLinregCG.java
@@ -0,0 +1,246 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmLinregCG extends AutomatedTestBase 
+{      
+       private final static String TEST_NAME1 = "Algorithm_LinregCG";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmLinregCG.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static double eps = 1e-1;
+       
+       private final static int rows = 2468;
+       private final static int cols = 507;
+               
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testLinregCG0DenseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, false, 0, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG0SparseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, true, 0, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG0DenseCP() {
+               runLinregCGTest(TEST_NAME1, false, false, 0, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG0SparseCP() {
+               runLinregCGTest(TEST_NAME1, false, true, 0, ExecType.CP);
+       }
+
+       @Test
+       public void testLinregCG0DenseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, false, 0, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG0SparseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, true, 0, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG0DenseSP() {
+               runLinregCGTest(TEST_NAME1, false, false, 0, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG0SparseSP() {
+               runLinregCGTest(TEST_NAME1, false, true, 0, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG1DenseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, false, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG1SparseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, true, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG1DenseCP() {
+               runLinregCGTest(TEST_NAME1, false, false, 1, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG1SparseCP() {
+               runLinregCGTest(TEST_NAME1, false, true, 1, ExecType.CP);
+       }
+
+       @Test
+       public void testLinregCG1DenseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, false, 1, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG1SparseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, true, 1, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG1DenseSP() {
+               runLinregCGTest(TEST_NAME1, false, false, 1, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG1SparseSP() {
+               runLinregCGTest(TEST_NAME1, false, true, 1, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG2DenseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, false, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG2SparseRewritesCP() {
+               runLinregCGTest(TEST_NAME1, true, true, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG2DenseCP() {
+               runLinregCGTest(TEST_NAME1, false, false, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testLinregCG2SparseCP() {
+               runLinregCGTest(TEST_NAME1, false, true, 2, ExecType.CP);
+       }
+
+       @Test
+       public void testLinregCG2DenseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, false, 2, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG2SparseRewritesSP() {
+               runLinregCGTest(TEST_NAME1, true, true, 2, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG2DenseSP() {
+               runLinregCGTest(TEST_NAME1, false, false, 2, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testLinregCG2SparseSP() {
+               runLinregCGTest(TEST_NAME1, false, true, 2, ExecType.SPARK);
+       }
+       
+       private void runLinregCGTest( String testname, boolean rewrites, 
boolean sparse, int intercept, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = 
"scripts/algorithms/LinearRegCG.dml";
+                       programArgs = new String[]{ "-explain", "-stats", 
"-nvargs", "X="+input("X"), "Y="+input("y"),
+                               "icpt="+String.valueOf(intercept), 
"tol="+String.valueOf(epsilon),
+                               "maxi="+String.valueOf(maxiter), "reg=0.001", 
"B="+output("w")};
+
+                       rCmd = getRCmd(inputDir(), 
String.valueOf(intercept),String.valueOf(epsilon),
+                               String.valueOf(maxiter), "0.001", 
expectedDir());
+       
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 7);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] y = getRandomMatrix(rows, 1, 0, 10, 1.0, 3);
+                       writeInputMatrixWithMTD("y", y, true);
+                       
+                       runTest(true, false, null, -1); 
+                       runRScript(true); 
+                       
+                       //compare matrices 
+                       HashMap<CellIndex, Double> dmlfile = 
readDMLMatrixFromHDFS("w");
+                       HashMap<CellIndex, Double> rfile  = 
readRMatrixFromFS("w");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+                       
Assert.assertTrue(heavyHittersContainsSubString("spoofRA") 
+                                       || 
heavyHittersContainsSubString("sp_spoofRA"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMDABivar.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMDABivar.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMDABivar.java
new file mode 100644
index 0000000..19be842
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMDABivar.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.test.integration.functions.codegenalg;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.File;
+
+import org.apache.sysml.test.integration.applications.MDABivariateStatsTest;
+
+@RunWith(value = Parameterized.class)
+public class AlgorithmMDABivar extends MDABivariateStatsTest 
+{
+       private final static String LOCAL_TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
LOCAL_TEST_DIR, TEST_CONF);
+       
+       public AlgorithmMDABivar(int n, int m, int li, int lml) {
+               super(n, m, li, lml);
+               TEST_CLASS_DIR = TEST_DIR + 
AlgorithmMDABivar.class.getSimpleName() + "/";
+       }
+
+       @Test
+       public void testMDABivariateStatsDml() {
+               testMDABivariateStats(ScriptType.DML);
+       }
+       
+       @Override
+       protected File getConfigTemplateFile() {
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMLogreg.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMLogreg.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMLogreg.java
new file mode 100644
index 0000000..0e5e322
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMLogreg.java
@@ -0,0 +1,286 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmMLogreg extends AutomatedTestBase 
+{
+       private final static String TEST_NAME1 = "Algorithm_MLogreg";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmMLogreg.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static double eps = 1e-5;
+       
+       private final static int rows = 2468;
+       private final static int cols = 227;
+               
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testMlogregBin0DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 0, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin0SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 0, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin0DenseCP() {
+               runMlogregTest(TEST_NAME1, 2, 0, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin0SparseCP() {
+               runMlogregTest(TEST_NAME1, 2, 0, false, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul0DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 0, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul0SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 0, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul0DenseCP() {
+               runMlogregTest(TEST_NAME1, 5, 0, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul0SparseCP() {
+               runMlogregTest(TEST_NAME1, 5, 0, false, true, ExecType.CP);
+       }
+
+       @Test
+       public void testMlogregBin0DenseRewritesSP() {
+               runMlogregTest(TEST_NAME1, 2, 0, true, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregBin0SparseRewritesSP() {
+               runMlogregTest(TEST_NAME1, 2, 0, true, true, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregBin0DenseSP() {
+               runMlogregTest(TEST_NAME1, 2, 0, false, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregBin0SparseSP() {
+               runMlogregTest(TEST_NAME1, 2, 0, false, true, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregMul0DenseRewritesSP() {
+               runMlogregTest(TEST_NAME1, 5, 0, true, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregMul0SparseRewritesSP() {
+               runMlogregTest(TEST_NAME1, 5, 0, true, true, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregMul0DenseSP() {
+               runMlogregTest(TEST_NAME1, 5, 0, false, false, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregMul0SparseSP() {
+               runMlogregTest(TEST_NAME1, 5, 0, false, true, ExecType.SPARK);
+       }
+       
+       @Test
+       public void testMlogregBin1DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 1, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin1SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 1, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin1DenseCP() {
+               runMlogregTest(TEST_NAME1, 2, 1, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin1SparseCP() {
+               runMlogregTest(TEST_NAME1, 2, 1, false, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul1DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 1, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul1SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 1, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul1DenseCP() {
+               runMlogregTest(TEST_NAME1, 5, 1, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul1SparseCP() {
+               runMlogregTest(TEST_NAME1, 5, 1, false, true, ExecType.CP);
+       }
+
+       @Test
+       public void testMlogregBin2DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 2, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin2SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 2, 2, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin2DenseCP() {
+               runMlogregTest(TEST_NAME1, 2, 2, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregBin2SparseCP() {
+               runMlogregTest(TEST_NAME1, 2, 2, false, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul2DenseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 2, true, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul2SparseRewritesCP() {
+               runMlogregTest(TEST_NAME1, 5, 2, true, true, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul2DenseCP() {
+               runMlogregTest(TEST_NAME1, 5, 2, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testMlogregMul2SparseCP() {
+               runMlogregTest(TEST_NAME1, 5, 2, false, true, ExecType.CP);
+       }
+       
+       private void runMlogregTest( String testname, int classes, int 
intercept, boolean rewrites, boolean sparse, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = 
"scripts/algorithms/MultiLogReg.dml";
+                       programArgs = new String[]{ "-explain", "-stats", 
"-nvargs", "X="+input("X"), "Y="+input("Y"),
+                               "icpt="+String.valueOf(intercept), 
"tol="+String.valueOf(epsilon),
+                               "moi="+String.valueOf(maxiter), "reg=0.001", 
"B="+output("w")};
+
+                       rCmd = getRCmd(inputDir(), 
String.valueOf(intercept),String.valueOf(epsilon),
+                               String.valueOf(maxiter), expectedDir());
+
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 2384);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 
0.51, classes+0.49, 1.0, 9283));
+                       writeInputMatrixWithMTD("Y", y, true);
+                       
+                       runTest(true, false, null, -1); 
+                       runRScript(true); 
+                       
+                       //compare matrices 
+                       HashMap<CellIndex, Double> dmlfile = 
readDMLMatrixFromHDFS("w");
+                       HashMap<CellIndex, Double> rfile  = 
readRMatrixFromFS("w");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+                       Assert.assertTrue(heavyHittersContainsSubString("spoof")
+                               || heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMSVM.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMSVM.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMSVM.java
new file mode 100644
index 0000000..eef66c8
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmMSVM.java
@@ -0,0 +1,166 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmMSVM extends AutomatedTestBase 
+{      
+       private final static String TEST_NAME1 = "Algorithm_MSVM";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmMSVM.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static double eps = 1e-5;
+       
+       private final static int rows = 1468;
+       private final static int cols = 1007;
+               
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static int intercept = 0;
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testMSVMDenseBinRewritesCP() {
+               runMSVMTest(TEST_NAME1, true, false, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMSparseBinRewritesCP() {
+               runMSVMTest(TEST_NAME1, true, true, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMDenseBinCP() {
+               runMSVMTest(TEST_NAME1, false, false, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMSparseBinCP() {
+               runMSVMTest(TEST_NAME1, false, true, 2, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMDenseMulRewritesCP() {
+               runMSVMTest(TEST_NAME1, true, false, 4, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMSparseMulRewritesCP() {
+               runMSVMTest(TEST_NAME1, true, true, 4, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMDenseMulCP() {
+               runMSVMTest(TEST_NAME1, false, false, 4, ExecType.CP);
+       }
+       
+       @Test
+       public void testMSVMSparseMulCP() {
+               runMSVMTest(TEST_NAME1, false, true, 4, ExecType.CP);
+       }
+       
+       private void runMSVMTest( String testname, boolean rewrites, boolean 
sparse, int numClasses, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = "scripts/algorithms/m-svm.dml";
+                       programArgs = new String[]{ "-explain", "-stats", 
"-nvargs", "X="+input("X"), "Y="+input("Y"),
+                                       "icpt="+String.valueOf(intercept), 
"tol="+String.valueOf(epsilon), "reg=0.001",
+                                       "maxiter="+String.valueOf(maxiter), 
"model="+output("w"), "Log= "};
+
+                       rCmd = getRCmd(inputDir(), 
String.valueOf(intercept),String.valueOf(epsilon),
+                               String.valueOf(maxiter), expectedDir());
+
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 714);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 
1, numClasses, 1.0, 136));
+                       writeInputMatrixWithMTD("Y", y, true);
+                       
+                       runTest(true, false, null, -1); 
+                       runRScript(true); 
+                       
+                       //compare matrices 
+                       HashMap<CellIndex, Double> dmlfile = 
readDMLMatrixFromHDFS("w");
+                       HashMap<CellIndex, Double> rfile  = 
readRMatrixFromFS("w");
+                       TestUtils.compareMatrices(dmlfile, rfile, eps, 
"Stat-DML", "Stat-R");
+                       
Assert.assertTrue(heavyHittersContainsSubString("spoof") || 
heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmPNMF.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmPNMF.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmPNMF.java
new file mode 100644
index 0000000..eb47100
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmPNMF.java
@@ -0,0 +1,152 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmPNMF extends AutomatedTestBase 
+{      
+       private final static String TEST_NAME1 = "Algorithm_PNMF";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmPNMF.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static double eps = 1e-5;
+       
+       private final static int rows = 1468;
+       private final static int cols = 1207;
+       private final static int rank = 20;
+               
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static double epsilon = 0.000000001;
+       private final static double maxiter = 10;
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testPNMFDenseCP() {
+               runPNMFTest(TEST_NAME1, false, false, ExecType.CP);
+       }
+       
+       @Test
+       public void testPNMFSparseCP() {
+               runPNMFTest(TEST_NAME1, false, true, ExecType.CP);
+       }
+       
+       //TODO requires proper handling of blocksize constraints
+       //@Test
+       //public void testPNMFDenseSP() {
+       //      runPNMFTest(TEST_NAME1, false, false, ExecType.SPARK);
+       //}
+       
+       //@Test
+       //public void testPNMFSparseSP() {
+       //      runPNMFTest(TEST_NAME1, false, true, ExecType.SPARK);
+       //}
+
+       private void runPNMFTest( String testname, boolean rewrites, boolean 
sparse, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       fullDMLScriptName = "scripts/staging/PNMF.dml";
+                       programArgs = new String[]{ "-explain", "-stats", 
"-args", input("X"), 
+                               input("W"), input("H"), String.valueOf(rank), 
String.valueOf(epsilon), 
+                               String.valueOf(maxiter), output("W"), 
output("H")};
+
+                       rCmd = getRCmd(inputDir(), String.valueOf(rank), 
String.valueOf(epsilon), 
+                               String.valueOf(maxiter), expectedDir());
+
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 234);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] W = getRandomMatrix(rows, rank, 0, 0.025, 
1.0, 3);
+                       writeInputMatrixWithMTD("W", W, true);
+                       double[][] H = getRandomMatrix(rank, cols, 0, 0.025, 
1.0, 7);
+                       writeInputMatrixWithMTD("H", H, true);
+                       
+                       runTest(true, false, null, -1); 
+                       runRScript(true); 
+                       
+                       //compare matrices 
+                       HashMap<CellIndex, Double> dmlW = 
readDMLMatrixFromHDFS("W");
+                       HashMap<CellIndex, Double> dmlH = 
readDMLMatrixFromHDFS("H");
+                       HashMap<CellIndex, Double> rW = readRMatrixFromFS("W");
+                       HashMap<CellIndex, Double> rH = readRMatrixFromFS("H");
+                       TestUtils.compareMatrices(dmlW, rW, eps, "Stat-DML", 
"Stat-R");
+                       TestUtils.compareMatrices(dmlH, rH, eps, "Stat-DML", 
"Stat-R");
+                       
Assert.assertTrue(heavyHittersContainsSubString("spoof") || 
heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/98595c52/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmStepwiseRegression.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmStepwiseRegression.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmStepwiseRegression.java
new file mode 100644
index 0000000..012250a
--- /dev/null
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/codegenalg/AlgorithmStepwiseRegression.java
@@ -0,0 +1,208 @@
+/*
+ * 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.codegenalg;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.hops.OptimizerUtils;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class AlgorithmStepwiseRegression extends AutomatedTestBase 
+{
+       private final static String TEST_NAME1 = "Algorithm_Stepwise";
+       private final static String TEST_DIR = "functions/codegenalg/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
AlgorithmStepwiseRegression.class.getSimpleName() + "/";
+       private final static String TEST_CONF = "SystemML-config-codegen.xml";
+       private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + 
TEST_DIR, TEST_CONF);
+       
+       private final static int rows = 2468;
+       private final static int cols = 200;
+       
+       private final static double sparsity1 = 0.7; //dense
+       private final static double sparsity2 = 0.1; //sparse
+       
+       private final static int icpt = 0;
+       private final static double thr = 0.01;
+       
+       public enum StepwiseType {
+               GLM_PROBIT,
+               LINREG_DS,
+       }
+       
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "w" })); 
+       }
+
+       @Test
+       public void testStepwiseGLMDenseRewritesCP() {
+               runStepwiseTest(StepwiseType.GLM_PROBIT, false, true, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseGLMSparseRewritesCP() {
+               runStepwiseTest(StepwiseType.GLM_PROBIT, true, true, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseGLMDenseNoRewritesCP() {
+               runStepwiseTest(StepwiseType.GLM_PROBIT, false, false, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseGLMSparseNoRewritesCP() {
+               runStepwiseTest(StepwiseType.GLM_PROBIT, true, false, 
ExecType.CP);
+       }
+       
+//     @Test
+//     public void testStepwiseGLMDenseRewritesSP() {
+//             runStepwiseTest(StepwiseType.GLM_PROBIT, false, true, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseGLMSparseRewritesSP() {
+//             runStepwiseTest(StepwiseType.GLM_PROBIT, true, true, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseGLMDenseNoRewritesSP() {
+//             runStepwiseTest(StepwiseType.GLM_PROBIT, false, false, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseGLMSparseNoRewritesSP() {
+//             runStepwiseTest(StepwiseType.GLM_PROBIT, true, false, 
ExecType.SPARK);
+//     }
+       
+       @Test
+       public void testStepwiseLinregDSDenseRewritesCP() {
+               runStepwiseTest(StepwiseType.LINREG_DS, false, true, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseLinregDSSparseRewritesCP() {
+               runStepwiseTest(StepwiseType.LINREG_DS, true, true, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseLinregDSDenseNoRewritesCP() {
+               runStepwiseTest(StepwiseType.LINREG_DS, false, false, 
ExecType.CP);
+       }
+       
+       @Test
+       public void testStepwiseLinregDSSparseNoRewritesCP() {
+               runStepwiseTest(StepwiseType.LINREG_DS, true, false, 
ExecType.CP);
+       }
+       
+//     @Test
+//     public void testStepwiseLinregDSDenseRewritesSP() {
+//             runStepwiseTest(StepwiseType.LINREG_DS, false, true, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseLinregDSSparseRewritesSP() {
+//             runStepwiseTest(StepwiseType.LINREG_DS, true, true, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseLinregDSDenseNoRewritesSP() {
+//             runStepwiseTest(StepwiseType.LINREG_DS, false, false, 
ExecType.SPARK);
+//     }
+//     
+//     @Test
+//     public void testStepwiseLinregDSSparseNoRewritesSP() {
+//             runStepwiseTest(StepwiseType.LINREG_DS, true, false, 
ExecType.SPARK);
+//     }
+       
+       private void runStepwiseTest( StepwiseType type, boolean sparse, 
boolean rewrites, ExecType instType)
+       {
+               boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
+               RUNTIME_PLATFORM platformOld = rtplatform;
+               switch( instType ){
+                       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 = TEST_NAME1;
+                       TestConfiguration config = 
getTestConfiguration(TEST_NAME);
+                       loadTestConfiguration(config);
+                       
+                       if( type ==  StepwiseType.LINREG_DS) {
+                               fullDMLScriptName = 
"scripts/algorithms/StepLinearRegDS.dml";
+                               programArgs = new String[]{ "-explain", 
"-stats", "-nvargs",
+                                       "X="+input("X"), "Y="+input("Y"), 
"icpt="+String.valueOf(icpt),
+                                       "thr="+String.valueOf(thr), 
"B="+output("B"), "S="+output("S")};
+                       }
+                       else { //GLM binomial probit
+                               fullDMLScriptName = 
"scripts/algorithms/StepGLM.dml";
+                               programArgs = new String[]{ "-explain", 
"-stats", "-nvargs",
+                                       "X="+input("X"), "Y="+input("Y"), 
"icpt="+String.valueOf(icpt),
+                                       "thr="+String.valueOf(thr), "link=3", 
"yneg=0",
+                                       "moi=5", "mii=5", "B="+output("B"), 
"S="+output("S")};
+                       }
+                       
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = 
rewrites;
+                       
+                       //generate actual datasets
+                       double[][] X = getRandomMatrix(rows, cols, 0, 1, 
sparse?sparsity2:sparsity1, 714);
+                       writeInputMatrixWithMTD("X", X, true);
+                       double[][] y = TestUtils.round(getRandomMatrix(rows, 1, 
0, 1, 1.0, 136));
+                       writeInputMatrixWithMTD("Y", y, true);
+                       
+                       runTest(true, false, null, -1); 
+
+                       Assert.assertTrue(heavyHittersContainsSubString("spoof")
+                               || heavyHittersContainsSubString("sp_spoof"));
+               }
+               finally {
+                       rtplatform = platformOld;
+                       DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+                       OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag;
+                       OptimizerUtils.ALLOW_AUTO_VECTORIZATION = true;
+                       OptimizerUtils.ALLOW_OPERATOR_FUSION = true;
+               }
+       }
+
+       /**
+        * Override default configuration with custom test configuration to 
ensure
+        * scratch space and local temporary directory locations are also 
updated.
+        */
+       @Override
+       protected File getConfigTemplateFile() {
+               // Instrumentation in this test's output log to show custom 
configuration file used for template.
+               System.out.println("This test case overrides default 
configuration with " + TEST_CONF_FILE.getPath());
+               return TEST_CONF_FILE;
+       }
+}

Reply via email to