use of org.apache.sysml.api.jmlc.Connection in project systemml by apache.
the class JMLCInputOutputTest method testScalarOutputScalarObject.
@Test
public void testScalarOutputScalarObject() throws DMLException {
Connection conn = new Connection();
String str = "outDouble = 1.23;\nwrite(outDouble, './tmp/outDouble');";
PreparedScript script = conn.prepareScript(str, new String[] {}, new String[] { "outDouble" }, false);
ScalarObject so = script.executeScript().getScalarObject("outDouble");
double result = so.getDoubleValue();
Assert.assertEquals(1.23, result, 0);
conn.close();
}
use of org.apache.sysml.api.jmlc.Connection in project systemml by apache.
the class FrameDecodeTest 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_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("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 systemml by apache.
the class ReuseModelVariablesTest method execDMLScriptviaJMLC.
private static ArrayList<double[][]> execDMLScriptviaJMLC(String testname, ArrayList<double[][]> X, boolean modelReuse) throws IOException {
Timing time = new Timing(true);
ArrayList<double[][]> ret = new ArrayList<double[][]>();
// establish connection to SystemML
Connection conn = new Connection();
try {
// For now, JMLC pipeline only allows dml
boolean parsePyDML = false;
// read and precompile script
String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
PreparedScript pstmt = conn.prepareScript(script, new String[] { "X", "W" }, new String[] { "predicted_y" }, parsePyDML);
// read model
String modelData = conn.readScript(SCRIPT_DIR + TEST_DIR + MODEL_FILE);
double[][] W = conn.convertToDoubleMatrix(modelData, rows, cols);
if (modelReuse)
pstmt.setMatrix("W", W, true);
// execute script multiple times
for (int i = 0; i < nRuns; i++) {
// bind input parameters
if (!modelReuse)
pstmt.setMatrix("W", W);
pstmt.setMatrix("X", X.get(i));
// execute script
ResultVariables rs = pstmt.executeScript();
// get output parameter
double[][] Y = rs.getMatrix("predicted_y");
// 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 systemml by apache.
the class APICodegenTest method runMLContextParforDatasetTest.
private void runMLContextParforDatasetTest(boolean jmlc) {
try {
double[][] X = getRandomMatrix(rows, cols, -10, 10, sparsity, 76543);
MatrixBlock mX = DataConverter.convertToMatrixBlock(X);
String s = "X = read(\"/tmp\");" + "R = colSums(X/rowSums(X));" + "write(R, \"tmp2\")";
// execute scripts
if (jmlc) {
DMLScript.STATISTICS = true;
Connection conn = new Connection(ConfigType.CODEGEN_ENABLED, ConfigType.ALLOW_DYN_RECOMPILATION);
PreparedScript pscript = conn.prepareScript(s, new String[] { "X" }, new String[] { "R" }, false);
pscript.setMatrix("X", mX, false);
pscript.executeScript();
conn.close();
System.out.println(Statistics.display());
} else {
SparkConf conf = SparkExecutionContext.createSystemMLSparkConf().setAppName("MLContextTest").setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
MLContext ml = new MLContext(sc);
ml.setConfigProperty(DMLConfig.CODEGEN, "true");
ml.setStatistics(true);
Script script = dml(s).in("X", mX).out("R");
ml.execute(script);
ml.resetConfig();
sc.stop();
ml.close();
}
// check for generated operator
Assert.assertTrue(heavyHittersContainsSubString("spoofRA"));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.sysml.api.jmlc.Connection in project incubator-systemml by apache.
the class SystemTMulticlassSVMScoreTest method execDMLScriptviaJMLC.
/**
*
* @param X
* @return
* @throws DMLException
* @throws IOException
*/
private ArrayList<double[][]> execDMLScriptviaJMLC(ArrayList<double[][]> X) throws IOException {
Timing time = new Timing(true);
ArrayList<double[][]> ret = new ArrayList<double[][]>();
//establish connection to SystemML
Connection conn = new Connection();
try {
// For now, JMLC pipeline only allows dml
boolean parsePyDML = false;
//read and precompile script
String script = conn.readScript(SCRIPT_DIR + TEST_DIR + TEST_NAME + ".dml");
PreparedScript pstmt = conn.prepareScript(script, new String[] { "X", "W" }, new String[] { "predicted_y" }, parsePyDML);
//read model
String modelData = conn.readScript(SCRIPT_DIR + TEST_DIR + MODEL_FILE);
double[][] W = conn.convertToDoubleMatrix(modelData, rows, cols);
//execute script multiple times
for (int i = 0; i < nRuns; i++) {
//bind input parameters
pstmt.setMatrix("W", W);
pstmt.setMatrix("X", X.get(i));
//execute script
ResultVariables rs = pstmt.executeScript();
//get output parameter
double[][] Y = rs.getMatrix("predicted_y");
//keep result for comparison
ret.add(Y);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException(ex);
} finally {
if (conn != null)
conn.close();
}
System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
return ret;
}
Aggregations