Search in sources :

Example 36 with CellIndex

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);
    }
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 37 with CellIndex

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;
    }
}
Also used : CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 38 with CellIndex

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;
    }
}
Also used : CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 39 with CellIndex

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));
}
Also used : CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Example 40 with CellIndex

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;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Aggregations

CellIndex (org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex)257 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)201 RUNTIME_PLATFORM (org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM)173 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)37 Test (org.junit.Test)20 HashMap (java.util.HashMap)16 IOException (java.io.IOException)14 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)9 Random (java.util.Random)8 ArrayList (java.util.ArrayList)7 BufferedReader (java.io.BufferedReader)6 StringTokenizer (java.util.StringTokenizer)6 InputStreamReader (java.io.InputStreamReader)5 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 FileStatus (org.apache.hadoop.fs.FileStatus)4 FileReader (java.io.FileReader)2 DMLException (org.apache.sysml.api.DMLException)2 MMultMethod (org.apache.sysml.hops.AggBinaryOp.MMultMethod)2