Search in sources :

Example 21 with Script

use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.

the class MLContextTest method testCreatePYDMLScriptBasedOnStringAndExecute.

@Test
public void testCreatePYDMLScriptBasedOnStringAndExecute() {
    System.out.println("MLContextTest - create PYDML script based on string and execute");
    String testString = "Create PYDML script based on string and execute";
    setExpectedStdOut(testString);
    Script script = pydml("print('" + testString + "')");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 22 with Script

use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.

the class MLContextTest method testOutputListStringIJVSparsePYDML.

@Test
public void testOutputListStringIJVSparsePYDML() {
    System.out.println("MLContextTest - output List String IJV Sparse PYDML");
    String s = "M = full(0, rows=10, cols=10)\nM[0,0]=1\nM[0,1]=2\nM[1,0]=3\nM[1,1]=4\nprint(toString(M))";
    Script script = pydml(s).out("M");
    MLResults results = ml.execute(script);
    MatrixObject mo = results.getMatrixObject("M");
    List<String> lines = MLContextConversionUtil.matrixObjectToListStringIJV(mo);
    Assert.assertEquals("1 1 1.0", lines.get(0));
    Assert.assertEquals("1 2 2.0", lines.get(1));
    Assert.assertEquals("2 1 3.0", lines.get(2));
    Assert.assertEquals("2 2 4.0", lines.get(3));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 23 with Script

use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.

the class MLContextTest method testCreateDMLScriptBasedOnURL.

@Test
public void testCreateDMLScriptBasedOnURL() throws MalformedURLException {
    System.out.println("MLContextTest - create DML script based on URL");
    String urlString = "https://raw.githubusercontent.com/apache/systemml/master/src/test/scripts/applications/hits/HITS.dml";
    URL url = new URL(urlString);
    Script script = dmlFromUrl(url);
    String expectedContent = "Licensed to the Apache Software Foundation";
    String s = script.getScriptString();
    assertTrue("Script string doesn't contain expected content: " + expectedContent, s.contains(expectedContent));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) URL(java.net.URL) Test(org.junit.Test)

Example 24 with Script

use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.

the class MLContextTest method testPrintFormattingBooleanSubstitution.

@Test
public void testPrintFormattingBooleanSubstitution() {
    System.out.println("MLContextTest - print formatting boolean substitution");
    Script script = dml("print('boolean %b', TRUE);");
    setExpectedStdOut("boolean true");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 25 with Script

use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.

the class MLContextTest method testOutputJavaRDDStringCSVSparsePYDML.

/**
 * Reading from dense and sparse matrices is handled differently, so we have
 * tests for both dense and sparse matrices.
 */
@Test
public void testOutputJavaRDDStringCSVSparsePYDML() {
    System.out.println("MLContextTest - output Java RDD String CSV Sparse PYDML");
    String s = "M = full(0, rows=10, cols=10)\nM[0,0]=1\nM[0,1]=2\nM[1,0]=3\nM[1,1]=4\nprint(toString(M))";
    Script script = pydml(s).out("M");
    MLResults results = ml.execute(script);
    JavaRDD<String> javaRDDStringCSV = results.getJavaRDDStringCSV("M");
    List<String> lines = javaRDDStringCSV.collect();
    Assert.assertEquals("1.0,2.0", lines.get(0));
    Assert.assertEquals("3.0,4.0", lines.get(1));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Aggregations

Script (org.apache.sysml.api.mlcontext.Script)410 Test (org.junit.Test)374 ArrayList (java.util.ArrayList)126 Row (org.apache.spark.sql.Row)104 MLResults (org.apache.sysml.api.mlcontext.MLResults)94 StructType (org.apache.spark.sql.types.StructType)70 MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)70 StructField (org.apache.spark.sql.types.StructField)68 DenseVector (org.apache.spark.ml.linalg.DenseVector)28 Vector (org.apache.spark.ml.linalg.Vector)28 VectorUDT (org.apache.spark.ml.linalg.VectorUDT)28 Matrix (org.apache.sysml.api.mlcontext.Matrix)26 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)26 MLContext (org.apache.sysml.api.mlcontext.MLContext)18 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)18 Tuple2 (scala.Tuple2)18 List (java.util.List)16 URL (java.net.URL)14 DMLScript (org.apache.sysml.api.DMLScript)14 Seq (scala.collection.Seq)14