Search in sources :

Example 11 with MatrixReader

use of org.apache.sysml.runtime.io.MatrixReader in project incubator-systemml by apache.

the class TransformFrameApplyTest method runTransformTest.

/**
	 * 
	 * @param rt
	 * @param ofmt
	 * @param dataset
	 */
private void runTransformTest(RUNTIME_PLATFORM rt, String ofmt, TransformType type) {
    //set runtime platform
    RUNTIME_PLATFORM rtold = rtplatform;
    boolean csvReblockOld = OptimizerUtils.ALLOW_FRAME_CSV_REBLOCK;
    rtplatform = rt;
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK || rtplatform == RUNTIME_PLATFORM.HYBRID_SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    //set transform specification
    String SPEC = null;
    String DATASET = null;
    switch(type) {
        case RECODE:
            SPEC = SPEC1;
            DATASET = DATASET1;
            break;
        case DUMMY:
            SPEC = SPEC2;
            DATASET = DATASET1;
            break;
        case BIN:
            SPEC = SPEC3;
            DATASET = DATASET1;
            break;
        case IMPUTE:
            SPEC = SPEC4;
            DATASET = DATASET2;
            break;
        case OMIT:
            SPEC = SPEC5;
            DATASET = DATASET2;
            break;
    }
    if (!ofmt.equals("csv"))
        throw new RuntimeException("Unsupported test output format");
    try {
        getAndLoadTestConfiguration(TEST_NAME1);
        /* This is for running the junit test the new way, i.e., construct the arguments directly */
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME1 + ".dml";
        programArgs = new String[] { "-nvargs", "DATA=" + HOME + "input/" + DATASET, "TFSPEC=" + HOME + "input/" + SPEC, "TFMTD=" + output("tfmtd"), "TFDATA=" + output("tfout"), "OFMT=" + ofmt };
        OptimizerUtils.ALLOW_FRAME_CSV_REBLOCK = csvReblockOld;
        runTest(true, false, null, -1);
        fullDMLScriptName = HOME + TEST_NAME2 + ".dml";
        programArgs = new String[] { "-explain", "-nvargs", "DATA=" + HOME + "input/" + DATASET, "TFSPEC=" + HOME + "input/" + SPEC, // generated above
        "APPLYMTD=" + output("tfmtd"), "TFDATA=" + output("test_tfout"), "OFMT=" + ofmt };
        OptimizerUtils.ALLOW_FRAME_CSV_REBLOCK = true;
        runTest(true, false, null, -1);
        //read both outputs and compare
        MatrixReader reader1 = MatrixReaderFactory.createMatrixReader(InputInfo.CSVInputInfo);
        MatrixBlock mb1 = reader1.readMatrixFromHDFS(output("tfout"), -1, -1, -1, -1, -1);
        MatrixReader reader2 = MatrixReaderFactory.createMatrixReader(InputInfo.CSVInputInfo);
        MatrixBlock mb2 = reader2.readMatrixFromHDFS(output("test_tfout"), -1, -1, -1, -1, -1);
        double[][] R1 = DataConverter.convertToDoubleMatrix(mb1);
        double[][] R2 = DataConverter.convertToDoubleMatrix(mb2);
        TestUtils.compareMatrices(R1, R2, R1.length, R1[0].length, 0);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        rtplatform = rtold;
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        OptimizerUtils.ALLOW_FRAME_CSV_REBLOCK = csvReblockOld;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixReader(org.apache.sysml.runtime.io.MatrixReader)

Aggregations

MatrixReader (org.apache.sysml.runtime.io.MatrixReader)11 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)11 IOException (java.io.IOException)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 FrameReader (org.apache.sysml.runtime.io.FrameReader)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)2 DMLException (org.apache.sysml.api.DMLException)1 RUNTIME_PLATFORM (org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM)1 ParseException (org.apache.sysml.parser.ParseException)1 FrameWriter (org.apache.sysml.runtime.io.FrameWriter)1 MatrixWriter (org.apache.sysml.runtime.io.MatrixWriter)1 InputInfo (org.apache.sysml.runtime.matrix.data.InputInfo)1 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)1 Test (org.junit.Test)1