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);
}
}
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]));
}
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);
}
}
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" }));
}
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;
}
}
Aggregations