Search in sources :

Example 11 with Script

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

the class MLContextTest method testPrintFormattingStringSubstitutionAlignment.

@Test
public void testPrintFormattingStringSubstitutionAlignment() {
    System.out.println("MLContextTest - print formatting string substitution alignment");
    Script script = dml("print(\"'%10s' '%-10s'\", \"hello\", \"world\");");
    setExpectedStdOut("'     hello' 'world     '");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 12 with Script

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

the class MLContextTest method testOutputRDDStringIJVDML.

@Test
public void testOutputRDDStringIJVDML() {
    System.out.println("MLContextTest - output RDD String IJV DML");
    String s = "M = matrix('1 2 3 4', rows=2, cols=2);";
    Script script = dml(s).out("M");
    MLResults results = ml.execute(script);
    RDD<String> rddStringIJV = results.getRDDStringIJV("M");
    Iterator<String> iterator = rddStringIJV.toLocalIterator();
    Assert.assertEquals("1 1 1.0", iterator.next());
    Assert.assertEquals("1 2 2.0", iterator.next());
    Assert.assertEquals("2 1 3.0", iterator.next());
    Assert.assertEquals("2 2 4.0", iterator.next());
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 13 with Script

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

the class MLContextTest method testOutputRDDStringCSVSparsePYDML.

@Test
public void testOutputRDDStringCSVSparsePYDML() {
    System.out.println("MLContextTest - output 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);
    RDD<String> rddStringCSV = results.getRDDStringCSV("M");
    Iterator<String> iterator = rddStringCSV.toLocalIterator();
    Assert.assertEquals("1.0,2.0", iterator.next());
    Assert.assertEquals("3.0,4.0", iterator.next());
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 14 with Script

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

the class MLContextTest method testInputVariablesAddFloatsDML.

@Test
public void testInputVariablesAddFloatsDML() {
    System.out.println("MLContextTest - input variables add floats DML");
    String s = "print('x + y = ' + (x + y));";
    Script script = dml(s).in("x", 3F).in("y", 4F);
    setExpectedStdOut("x + y = 7.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 15 with Script

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

the class MLContextTest method test2DDoubleSumPYDML.

@Test
public void test2DDoubleSumPYDML() {
    System.out.println("MLContextTest - two-dimensional double array sum PYDML");
    double[][] matrix = new double[][] { { 10.0, 20.0 }, { 30.0, 40.0 } };
    Script script = pydml("print('sum: ' + sum(M))").in("M", matrix);
    setExpectedStdOut("sum: 100.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) 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