Search in sources :

Example 6 with Connection

use of org.apache.sysml.api.jmlc.Connection 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 Connection

use of org.apache.sysml.api.jmlc.Connection 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 Connection

use of org.apache.sysml.api.jmlc.Connection 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 Connection

use of org.apache.sysml.api.jmlc.Connection 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 Connection

use of org.apache.sysml.api.jmlc.Connection 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)75 PreparedScript (org.apache.sysml.api.jmlc.PreparedScript)73 Test (org.junit.Test)28 ResultVariables (org.apache.sysml.api.jmlc.ResultVariables)27 IOException (java.io.IOException)25 HashMap (java.util.HashMap)22 ArrayList (java.util.ArrayList)19 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)17 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)4 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)4 DMLException (org.apache.sysml.api.DMLException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 SparkConf (org.apache.spark.SparkConf)2 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)2 DMLScript (org.apache.sysml.api.DMLScript)2 MLContext (org.apache.sysml.api.mlcontext.MLContext)2