Search in sources :

Example 81 with TestConfiguration

use of org.apache.sysml.test.integration.TestConfiguration in project incubator-systemml by apache.

the class FrameReadMetaTest method runJMLCReadMetaTest.

private void runJMLCReadMetaTest(String testname, boolean modelReuse, boolean readFrame, boolean useSpec) throws IOException {
    String TEST_NAME = testname;
    TestConfiguration config = getTestConfiguration(TEST_NAME);
    loadTestConfiguration(config);
    // establish connection to SystemML
    Connection conn = new Connection();
    // read meta data frame
    String spec = MapReduceTool.readStringFromHDFSFile(SCRIPT_DIR + TEST_DIR + "tfmtd_example2/spec.json");
    FrameBlock M = readFrame ? DataConverter.convertToFrameBlock(conn.readStringFrame(SCRIPT_DIR + TEST_DIR + "tfmtd_frame_example/tfmtd_frame")) : conn.readTransformMetaDataFromFile(spec, SCRIPT_DIR + TEST_DIR + "tfmtd_example2/");
    try {
        // generate data based on recode maps
        HashMap<String, Long>[] RC = getRecodeMaps(spec, M);
        double[][] X = generateData(rows, cols, RC);
        String[][] F = null;
        // prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC", spec);
        // read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "X", "M" }, new String[] { "F" }, false);
        if (modelReuse)
            pstmt.setFrame("M", M, true);
        // execute script multiple times (2 runs)
        for (int i = 0; i < 2; i++) {
            // bind input parameters
            if (!modelReuse)
                pstmt.setFrame("M", M, false);
            pstmt.setMatrix("X", X);
            // execute script
            ResultVariables rs = pstmt.executeScript();
            // get output parameter
            F = rs.getFrame("F");
        }
        // for all generated data, probe recode maps and compare versus output
        for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) if (RC[j] != null) {
            Assert.assertEquals("Wrong result: " + F[i][j] + ".", Double.valueOf(X[i][j]), Double.valueOf(RC[j].get(F[i][j]).toString()));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock)

Example 82 with TestConfiguration

use of org.apache.sysml.test.integration.TestConfiguration in project incubator-systemml by apache.

the class FrameTransformTest method runJMLCReuseTest.

private void runJMLCReuseTest(String testname, boolean sparse, boolean modelReuse) throws IOException {
    String TEST_NAME = testname;
    TestConfiguration config = getTestConfiguration(TEST_NAME);
    loadTestConfiguration(config);
    // generate inputs
    double[][] Xd = TestUtils.round(getRandomMatrix(rows, cols, 0.51, 7.49, sparse ? sparsity2 : sparsity1, 1234));
    // create ragged meta frame
    setColumnValue(Xd, 2, 3);
    String[][] Xs = createFrameData(Xd);
    String[][] Ms = createRecodeMaps(Xs);
    // run DML via JMLC
    ArrayList<double[][]> Yset = execDMLScriptviaJMLC(TEST_NAME, Xs, Ms, modelReuse);
    // check correct result (nnz 7 + 0 -> 8 distinct vals)
    for (double[][] data : Yset) Assert.assertEquals("Wrong result: " + data[0][0] + ".", new Double(8), new Double(data[0][0]));
}
Also used : TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 83 with TestConfiguration

use of org.apache.sysml.test.integration.TestConfiguration 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 84 with TestConfiguration

use of org.apache.sysml.test.integration.TestConfiguration in project incubator-systemml by apache.

the class AssertExpressionTest method setUp.

@Override
public void setUp() {
    TestUtils.clearAssertionInformation();
    addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "R" }));
}
Also used : TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 85 with TestConfiguration

use of org.apache.sysml.test.integration.TestConfiguration in project incubator-systemml by apache.

the class AssertExpressionTest method runPrintExpressionTest.

/**
 * @param testname
 * @param rewrites
 */
private void runPrintExpressionTest(String testname, boolean rewrites) {
    String TEST_NAME = testname;
    TestConfiguration config = getTestConfiguration(TEST_NAME);
    loadTestConfiguration(config);
    // set rewrite configuration
    boolean oldRewriteFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
    OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
    try {
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME + ".dml";
        programArgs = new String[] { "-args", output("R") };
        fullRScriptName = HOME + TEST_NAME + ".R";
        rCmd = getRCmd(expectedDir());
        // run Tests
        runTest(true, false, null, -1);
    } finally {
        OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldRewriteFlag;
    }
}
Also used : TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Aggregations

TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)866 Test (org.junit.Test)299 CellIndex (org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex)201 RUNTIME_PLATFORM (org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM)171 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)50 IOException (java.io.IOException)18 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)14 Modulus (org.apache.sysml.runtime.functionobjects.Modulus)9 HashMap (java.util.HashMap)8 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)8 DMLException (org.apache.sysml.api.DMLException)6 Random (java.util.Random)5 ValueType (org.apache.sysml.parser.Expression.ValueType)5 Date (java.util.Date)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 Connection (org.apache.sysml.api.jmlc.Connection)2 DMLConfig (org.apache.sysml.conf.DMLConfig)2 DMLProgram (org.apache.sysml.parser.DMLProgram)2 DMLTranslator (org.apache.sysml.parser.DMLTranslator)2