Search in sources :

Example 6 with PreparedScript

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

the class InputToStringTest method testScalartoString.

@Test
public void testScalartoString() throws DMLException {
    try (Connection conn = new Connection()) {
        PreparedScript pscript = conn.prepareScript("s = read(\"tmp\", data_type=\"scalar\"); print(toString(s));", new String[] { "s" }, new String[] {});
        pscript.setScalar("s", 7);
        pscript.executeScript();
    }
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 7 with PreparedScript

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

the class InputToStringTest method testFrametoString.

@Test
public void testFrametoString() throws DMLException {
    try (Connection conn = new Connection()) {
        PreparedScript pscript = conn.prepareScript("f = read(\"tmp\", data_type=\"frame\"); print(toString(f));", new String[] { "f" }, new String[] {});
        pscript.setFrame("f", DataConverter.convertToFrameBlock(MatrixBlock.randOperations(7, 3, 1.0, 0, 1, "uniform", 7)), false);
        pscript.executeScript();
    }
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Example 8 with PreparedScript

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

the class JMLCClonedPreparedScriptTest method runJMLCClonedTest.

private void runJMLCClonedTest(String script, int num, boolean clone) throws IOException {
    int k = InfrastructureAnalyzer.getLocalParallelism();
    boolean failed = false;
    try (Connection conn = new Connection()) {
        DMLScript.STATISTICS = true;
        Statistics.reset();
        PreparedScript pscript = conn.prepareScript(script, new String[] {}, new String[] { "out" }, false);
        ExecutorService pool = Executors.newFixedThreadPool(k);
        ArrayList<JMLCTask> tasks = new ArrayList<>();
        for (int i = 0; i < num; i++) tasks.add(new JMLCTask(pscript, clone));
        List<Future<Double>> taskrets = pool.invokeAll(tasks);
        for (Future<Double> ret : taskrets) if (ret.get() != 700)
            throw new RuntimeException("wrong results: " + ret.get());
        pool.shutdown();
    } catch (Exception ex) {
        failed = true;
    }
    // check expected failure
    Assert.assertTrue(failed == !clone || k == 1);
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DMLException(org.apache.sysml.api.DMLException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Example 9 with PreparedScript

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

the class JMLCInputOutputTest method testScalarOutputBoolean.

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

Example 10 with PreparedScript

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

the class JMLCInputOutputTest method testScalarInputInt.

@Test
public void testScalarInputInt() 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);
    int inScalar1 = 2;
    int inScalar2 = 3;
    script.setScalar("inScalar1", inScalar1);
    script.setScalar("inScalar2", inScalar2);
    setExpectedStdOut("total:5");
    script.executeScript();
    conn.close();
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

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