use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testMultipleOutDML.
@Test
public void testMultipleOutDML() {
System.out.println("MLContextTest - multiple out DML");
String s = "M = matrix('1 2 3 4', rows=2, cols=2); N = sum(M)";
// alternative to .out("M").out("N")
MLResults results = ml.execute(dml(s).out("M", "N"));
double[][] matrix = results.getMatrixAs2DDoubleArray("M");
double sum = results.getDouble("N");
Assert.assertEquals(1.0, matrix[0][0], 0);
Assert.assertEquals(2.0, matrix[0][1], 0);
Assert.assertEquals(3.0, matrix[1][0], 0);
Assert.assertEquals(4.0, matrix[1][1], 0);
Assert.assertEquals(10.0, sum, 0);
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputListStringCSVDensePYDML.
@Test
public void testOutputListStringCSVDensePYDML() {
System.out.println("MLContextTest - output List String CSV Dense PYDML");
String s = "M = full('1 2 3 4', rows=2, cols=2)\nprint(toString(M))";
Script script = pydml(s).out("M");
MLResults results = ml.execute(script);
MatrixObject mo = results.getMatrixObject("M");
List<String> lines = MLContextConversionUtil.matrixObjectToListStringCSV(mo);
Assert.assertEquals("1.0,2.0", lines.get(0));
Assert.assertEquals("3.0,4.0", lines.get(1));
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputDataFramePYDMLDoublesWithIDColumn.
@Test
public void testOutputDataFramePYDMLDoublesWithIDColumn() {
System.out.println("MLContextTest - output DataFrame PYDML, doubles with ID column");
String s = "M = full('1 2 3 4', rows=2, cols=2)";
Script script = pydml(s).out("M");
MLResults results = ml.execute(script);
Dataset<Row> dataFrame = results.getDataFrameDoubleWithIDColumn("M");
List<Row> list = dataFrame.collectAsList();
Row row1 = list.get(0);
Assert.assertEquals(1.0, row1.getDouble(0), 0.0);
Assert.assertEquals(1.0, row1.getDouble(1), 0.0);
Assert.assertEquals(2.0, row1.getDouble(2), 0.0);
Row row2 = list.get(1);
Assert.assertEquals(2.0, row2.getDouble(0), 0.0);
Assert.assertEquals(3.0, row2.getDouble(1), 0.0);
Assert.assertEquals(4.0, row2.getDouble(2), 0.0);
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputJavaRDDStringCSVDenseDML.
@Test
public void testOutputJavaRDDStringCSVDenseDML() {
System.out.println("MLContextTest - output Java RDD String CSV Dense DML");
String s = "M = matrix('1 2 3 4', rows=2, cols=2); print(toString(M));";
Script script = dml(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));
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputJavaRDDStringIJVPYDML.
@Test
public void testOutputJavaRDDStringIJVPYDML() {
System.out.println("MLContextTest - output Java RDD String IJV PYDML");
String s = "M = full('1 2 3 4', rows=2, cols=2)";
Script script = pydml(s).out("M");
MLResults results = ml.execute(script);
JavaRDD<String> javaRDDStringIJV = results.getJavaRDDStringIJV("M");
List<String> lines = javaRDDStringIJV.collect();
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));
}
Aggregations