Search in sources :

Example 21 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript 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();
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 22 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript 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();
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 23 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class JMLCInputOutputTest method testScalarOutputString.

@Test
public void testScalarOutputString() throws DMLException {
    Connection conn = new Connection();
    String str = "outString = 'hello';\nwrite(outString, './tmp/outString');";
    PreparedScript script = conn.prepareScript(str, new String[] {}, new String[] { "outString" }, false);
    String result = script.executeScript().getString("outString");
    Assert.assertEquals("hello", result);
    conn.close();
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 24 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class JMLCInputOutputTest method testScalarInputStringExplicitValueType.

@Test
public void testScalarInputStringExplicitValueType() throws IOException, DMLException {
    Connection conn = new Connection();
    String str = conn.readScript(baseDirectory + File.separator + "scalar-input-string.dml");
    PreparedScript script = conn.prepareScript(str, new String[] { "inScalar1", "inScalar2" }, new String[] {}, false);
    String inScalar1 = "hello";
    String inScalar2 = "goodbye";
    script.setScalar("inScalar1", inScalar1);
    script.setScalar("inScalar2", inScalar2);
    setExpectedStdOut("result:hellogoodbye");
    script.executeScript();
    conn.close();
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 25 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class MulticlassSVMScoreTest method execDMLScriptviaJMLC.

private static ArrayList<double[][]> execDMLScriptviaJMLC(ArrayList<double[][]> X, boolean flags) throws IOException {
    Timing time = new Timing(true);
    ArrayList<double[][]> ret = new ArrayList<double[][]>();
    // establish connection to SystemML
    Connection conn = !flags ? new Connection() : new Connection(ConfigType.PARALLEL_CP_MATRIX_OPERATIONS, ConfigType.PARALLEL_LOCAL_OR_REMOTE_PARFOR, ConfigType.ALLOW_DYN_RECOMPILATION);
    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;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

Connection (org.apache.sysml.api.jmlc.Connection)37 PreparedScript (org.apache.sysml.api.jmlc.PreparedScript)37 ResultVariables (org.apache.sysml.api.jmlc.ResultVariables)14 Test (org.junit.Test)14 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)9 DMLException (org.apache.sysml.api.DMLException)2 File (java.io.File)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 SparkConf (org.apache.spark.SparkConf)1 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)1 DMLScript (org.apache.sysml.api.DMLScript)1 MLContext (org.apache.sysml.api.mlcontext.MLContext)1 Script (org.apache.sysml.api.mlcontext.Script)1 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)1 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)1 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)1