Search in sources :

Example 6 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults 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 7 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults 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)

Example 8 with MLResults

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

the class MLContextTest method testOutputListDML.

@Test
public void testOutputListDML() {
    System.out.println("MLContextTest - output specified as List DML");
    List<String> outputs = Arrays.asList("x", "y");
    Script script = dml("a=1;x=a+1;y=x+1").out(outputs);
    MLResults results = ml.execute(script);
    Assert.assertEquals(2, results.getLong("x"));
    Assert.assertEquals(3, results.getLong("y"));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 9 with MLResults

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

the class MLContextTest method testOutputDataFrameDMLVectorWithIDColumn.

@Test
public void testOutputDataFrameDMLVectorWithIDColumn() {
    System.out.println("MLContextTest - output DataFrame DML, vector with ID column");
    String s = "M = matrix('1 2 3 4', rows=2, cols=2);";
    Script script = dml(s).out("M");
    MLResults results = ml.execute(script);
    Dataset<Row> dataFrame = results.getDataFrameVectorWithIDColumn("M");
    List<Row> list = dataFrame.collectAsList();
    Row row1 = list.get(0);
    Assert.assertEquals(1.0, row1.getDouble(0), 0.0);
    Assert.assertArrayEquals(new double[] { 1.0, 2.0 }, ((Vector) row1.get(1)).toArray(), 0.0);
    Row row2 = list.get(1);
    Assert.assertEquals(2.0, row2.getDouble(0), 0.0);
    Assert.assertArrayEquals(new double[] { 3.0, 4.0 }, ((Vector) row2.get(1)).toArray(), 0.0);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Row(org.apache.spark.sql.Row) Test(org.junit.Test)

Example 10 with MLResults

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

the class MLContextTest method testOutputListStringIJVSparseDML.

@Test
public void testOutputListStringIJVSparseDML() {
    System.out.println("MLContextTest - output List String IJV Sparse DML");
    String s = "M = matrix(0, rows=10, cols=10); M[1,1]=1; M[1,2]=2; M[2,1]=3; M[2,2]=4; print(toString(M));";
    Script script = dml(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)

Aggregations

MLResults (org.apache.sysml.api.mlcontext.MLResults)51 Script (org.apache.sysml.api.mlcontext.Script)47 Test (org.junit.Test)44 Row (org.apache.spark.sql.Row)18 ArrayList (java.util.ArrayList)11 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 StructType (org.apache.spark.sql.types.StructType)7 MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)7 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)7 StructField (org.apache.spark.sql.types.StructField)6 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)6 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)6 FrameMetadata (org.apache.sysml.api.mlcontext.FrameMetadata)5 Matrix (org.apache.sysml.api.mlcontext.Matrix)5 List (java.util.List)4 CommaSeparatedValueStringToDoubleArrayRow (org.apache.sysml.test.integration.mlcontext.MLContextTest.CommaSeparatedValueStringToDoubleArrayRow)4 IOException (java.io.IOException)3 Seq (scala.collection.Seq)3 HashMap (java.util.HashMap)2 JavaRDD (org.apache.spark.api.java.JavaRDD)2