use of org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex in project incubator-systemml by apache.
the class MulticlassSVMScoreTest method runJMLCMulticlassTest.
private void runJMLCMulticlassTest(boolean sparse, boolean flags) throws IOException {
TestConfiguration config = getTestConfiguration(TEST_NAME);
loadTestConfiguration(config);
// generate inputs
ArrayList<double[][]> Xset = generateInputs(nRuns, rows, cols, sparse ? sparsity2 : sparsity1);
if (CHECK_IN_OUT)
checkSelfEquivalence(Xset, rows, cols);
// run DML via JMLC
ArrayList<double[][]> Yset = execDMLScriptviaJMLC(Xset, flags);
if (CHECK_IN_OUT)
checkSelfEquivalence(Yset, rows, 1);
// run R and compare results to DML result
String HOME = SCRIPT_DIR + TEST_DIR;
fullRScriptName = HOME + TEST_NAME + ".R";
rCmd = getRCmd(inputDir(), expectedDir());
// write model data once
MatrixBlock mb = DataConverter.readMatrixFromHDFS(SCRIPT_DIR + TEST_DIR + MODEL_FILE, InputInfo.TextCellInputInfo, rows, cols, 1000, 1000);
double[][] W = DataConverter.convertToDoubleMatrix(mb);
writeInputMatrix("W", W, true);
// for each input data set
int lnRuns = CHECK_IN_OUT ? 1 : nRuns;
for (int i = 0; i < lnRuns; i++) {
// write input data
writeInputMatrix("X", Xset.get(i), true);
// run the R script
runRScript(true);
// compare results
HashMap<CellIndex, Double> rfile = readRMatrixFromFS("predicted_y");
double[][] expected = TestUtils.convertHashMapToDoubleArray(rfile, rows, 1);
TestUtils.compareMatrices(expected, Yset.get(i), rows, 1, eps);
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex in project incubator-systemml by apache.
the class IPAFunctionInliningTest method runIPAFunInlineTest.
private void runIPAFunInlineTest(String testName, boolean IPA) {
boolean oldFlagIPA = OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS;
try {
TestConfiguration config = getTestConfiguration(testName);
loadTestConfiguration(config);
String HOME = SCRIPT_DIR + TEST_DIR;
fullDMLScriptName = HOME + testName + ".dml";
programArgs = new String[] { "-explain", "-stats", "-args", output("R") };
fullRScriptName = HOME + testName + ".R";
rCmd = getRCmd(expectedDir());
OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS = IPA;
// run script and compare output
runTest(true, false, null, -1);
// compare results
if (!testName.equals(TEST_NAME6)) {
double val = readDMLMatrixFromHDFS("R").get(new CellIndex(1, 1));
Assert.assertTrue("Wrong result: 7 vs " + val, Math.abs(val - 7) < Math.pow(10, -14));
}
// compare inlined functions
boolean inlined = (IPA && ArrayUtils.contains(new String[] { TEST_NAME1, TEST_NAME2, TEST_NAME3, TEST_NAME6 }, testName));
Assert.assertTrue("Unexpected function call: " + inlined, !heavyHittersContainsSubString("foo") == inlined);
// check for incorrect operation replication
if (testName.equals(TEST_NAME6))
Assert.assertTrue(Statistics.getCPHeavyHitterCount("print") == 1);
} finally {
OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS = oldFlagIPA;
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex in project incubator-systemml by apache.
the class IPAUnknownRecursionTest method runIPAUnknownRecursionTest.
/**
* @param condition
* @param branchRemoval
* @param IPA
*/
private void runIPAUnknownRecursionTest(boolean IPA) {
boolean oldFlagIPA = OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS;
try {
TestConfiguration config = getTestConfiguration(TEST_NAME);
loadTestConfiguration(config);
String HOME = SCRIPT_DIR + TEST_DIR;
fullDMLScriptName = HOME + TEST_NAME + ".dml";
programArgs = new String[] { "-args", Integer.toString(val), output("R") };
fullRScriptName = HOME + TEST_NAME + ".R";
rCmd = getRCmd(Integer.toString(val), expectedDir());
OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS = IPA;
runTest(true, false, null, -1);
runRScript(true);
// compare matrices
HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("R");
HashMap<CellIndex, Double> rfile = readRMatrixFromFS("R");
TestUtils.compareMatrices(dmlfile, rfile, 0, "Stat-DML", "Stat-R");
} finally {
OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS = oldFlagIPA;
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex in project incubator-systemml by apache.
the class NegativeLoopIncrementsTest method runNegativeLoopIncrementsTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runNegativeLoopIncrementsTest(String testname, boolean vect, boolean multiStep) {
String TEST_NAME = testname;
TestConfiguration config = getTestConfiguration(TEST_NAME);
loadTestConfiguration(config);
double[][] A = getRandomMatrix(rows, cols, -5, 5, 0.9, 7);
writeInputMatrixWithMTD("A", A, true);
String HOME = SCRIPT_DIR + TEST_DIR;
fullDMLScriptName = HOME + TEST_NAME + ".dml";
programArgs = new String[] { "-args", input("A"), String.valueOf(vect ? 0 : 1), String.valueOf(multiStep).toUpperCase(), output("R") };
fullRScriptName = HOME + TEST_NAME + ".R";
rCmd = getRCmd(inputDir(), String.valueOf(vect ? 0 : 1), String.valueOf(multiStep).toUpperCase(), expectedDir());
// run Tests
runTest(true, false, null, -1);
runRScript(true);
// compare matrices
HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("R");
HashMap<CellIndex, Double> rfile = readRMatrixFromFS("R");
TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
// check meta data
checkDMLMetaDataFile("R", new MatrixCharacteristics(1, 1, 1, 1));
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex in project incubator-systemml by apache.
the class OuterTableExpandTest method runOuterTableTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runOuterTableTest(String testname, boolean sparse, boolean left, ExecType instType) {
// rtplatform for MR
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;
break;
}
boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
if (rtplatform == RUNTIME_PLATFORM.SPARK)
DMLScript.USE_LOCAL_SPARK_CONFIG = true;
try {
String TEST_NAME = testname;
TestConfiguration config = getTestConfiguration(TEST_NAME);
loadTestConfiguration(config);
String HOME = SCRIPT_DIR + TEST_DIR;
fullDMLScriptName = HOME + TEST_NAME + ".dml";
programArgs = new String[] { "-explain", "-args", input("A"), String.valueOf(cols2), String.valueOf(left).toUpperCase(), output("C") };
fullRScriptName = HOME + TEST_NAME + ".R";
rCmd = getRCmd(inputDir(), Integer.toString(cols2), String.valueOf(left).toUpperCase(), expectedDir());
// generate actual datasets
double sparsity = sparse ? sparsity2 : sparsity1;
double[][] A = TestUtils.round(getRandomMatrix(rows, 1, 1, cols2, sparsity, 235));
writeInputMatrixWithMTD("A", A, true);
// run the testcase (expect exceptions for table w/ 0s)
boolean exceptionExpected = testname.equals(TEST_NAME2) && sparsity < 1.0;
runTest(true, exceptionExpected, DMLException.class, -1);
runRScript(true);
if (!exceptionExpected) {
// compare matrices
HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("C");
HashMap<CellIndex, Double> rfile = readRMatrixFromFS("C");
TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
// check meta data
checkDMLMetaDataFile("C", new MatrixCharacteristics(left ? rows : cols2, left ? cols2 : rows, 1, 1));
// check compiled/executed jobs
if (rtplatform == RUNTIME_PLATFORM.HADOOP) {
// reblock+gmr if rexpand; otherwise 3/5
int expectedNumCompiled = 2;
int expectedNumExecuted = expectedNumCompiled;
checkNumCompiledMRJobs(expectedNumCompiled);
checkNumExecutedMRJobs(expectedNumExecuted);
}
}
} finally {
rtplatform = platformOld;
DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
}
}
Aggregations