use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class FrameEncodeTest method execDMLScriptviaJMLC.
private static ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, boolean modelReuse) throws IOException {
Timing time = new Timing(true);
ArrayList<String[][]> ret = new ArrayList<String[][]>();
// establish connection to SystemML
Connection conn = new Connection();
try {
// prepare input arguments
HashMap<String, String> args = new HashMap<String, String>();
args.put("$TRANSFORM_SPEC", "{ \"ids\": true ,\"recode\": [ 1, 2, 3] }");
// read and precompile script
String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
if (modelReuse)
pstmt.setFrame("F1", F1, true);
// execute script multiple times
for (int i = 0; i < nRuns; i++) {
// bind input parameters
if (!modelReuse)
pstmt.setFrame("F1", F1);
// execute script
ResultVariables rs = pstmt.executeScript();
// get output parameter
String[][] Y = rs.getFrame("F2");
// keep result for comparison
ret.add(Y);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException(ex);
} finally {
IOUtilFunctions.closeSilently(conn);
}
System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
return ret;
}
use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class FrameLeftIndexingTest method execDMLScriptviaJMLC.
private static ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, String[][] M, boolean modelReuse) throws IOException {
Timing time = new Timing(true);
ArrayList<String[][]> ret = new ArrayList<String[][]>();
// establish connection to SystemML
Connection conn = new Connection();
try {
// prepare input arguments
HashMap<String, String> args = new HashMap<String, String>();
args.put("$TRANSFORM_SPEC1", "{ \"ids\": true ,\"recode\": [ 1, 2] }");
args.put("$TRANSFORM_SPEC2", "{ \"ids\": true ,\"recode\": [ 1] }");
// read and precompile script
String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
if (modelReuse)
pstmt.setFrame("M", M, true);
// execute script multiple times
for (int i = 0; i < nRuns; i++) {
// bind input parameters
if (!modelReuse)
pstmt.setFrame("M", M);
pstmt.setFrame("F1", F1);
// execute script
ResultVariables rs = pstmt.executeScript();
// get output parameter
String[][] Y = rs.getFrame("F2");
// keep result for comparison
ret.add(Y);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException(ex);
} finally {
IOUtilFunctions.closeSilently(conn);
}
System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
return ret;
}
use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class InputToStringTest method testMatrixtoString.
@Test
public void testMatrixtoString() throws DMLException {
try (Connection conn = new Connection()) {
PreparedScript pscript = conn.prepareScript("m = read(\"tmp\", data_type=\"matrix\"); print(toString(m));", new String[] { "m" }, new String[] {});
pscript.setMatrix("m", MatrixBlock.randOperations(7, 3, 1.0, 0, 1, "uniform", 7), false);
pscript.executeScript();
}
}
use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class JMLCInputOutputTest method testScalarInputBoolean.
@Test
public void testScalarInputBoolean() throws IOException, DMLException {
Connection conn = new Connection();
String str = conn.readScript(baseDirectory + File.separator + "scalar-input.dml");
PreparedScript script = conn.prepareScript(str, new String[] { "inScalar1", "inScalar2" }, new String[] {}, false);
boolean inScalar1 = true;
boolean inScalar2 = true;
script.setScalar("inScalar1", inScalar1);
script.setScalar("inScalar2", inScalar2);
setExpectedStdOut("total:2.0");
script.executeScript();
conn.close();
}
use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class JMLCInputOutputTest method testScalarOutputLong.
@Test
public void testScalarOutputLong() throws DMLException {
Connection conn = new Connection();
String str = "outInteger = 5;\nwrite(outInteger, './tmp/outInteger');";
PreparedScript script = conn.prepareScript(str, new String[] {}, new String[] { "outInteger" }, false);
long result = script.executeScript().getLong("outInteger");
Assert.assertEquals(5, result);
conn.close();
}
Aggregations