use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputDataFrameDMLVectorNoIDColumn.
@Test
public void testOutputDataFrameDMLVectorNoIDColumn() {
System.out.println("MLContextTest - output DataFrame DML, vector no 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.getDataFrameVectorNoIDColumn("M");
List<Row> list = dataFrame.collectAsList();
Row row1 = list.get(0);
Assert.assertArrayEquals(new double[] { 1.0, 2.0 }, ((Vector) row1.get(0)).toArray(), 0.0);
Row row2 = list.get(1);
Assert.assertArrayEquals(new double[] { 3.0, 4.0 }, ((Vector) row2.get(0)).toArray(), 0.0);
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputBinaryBlocksDML.
@Test
public void testOutputBinaryBlocksDML() {
System.out.println("MLContextTest - output binary blocks DML");
String s = "M = matrix('1 2 3 4', rows=2, cols=2);";
MLResults results = ml.execute(dml(s).out("M"));
Matrix m = results.getMatrix("M");
JavaPairRDD<MatrixIndexes, MatrixBlock> binaryBlocks = m.toBinaryBlocks();
MatrixMetadata mm = m.getMatrixMetadata();
MatrixCharacteristics mc = mm.asMatrixCharacteristics();
JavaRDD<String> javaRDDStringIJV = RDDConverterUtils.binaryBlockToTextCell(binaryBlocks, mc);
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));
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputJavaRDDStringCSVDensePYDML.
@Test
public void testOutputJavaRDDStringCSVDensePYDML() {
System.out.println("MLContextTest - output Java RDD 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);
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 testOutputScalaSeqDML.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testOutputScalaSeqDML() {
System.out.println("MLContextTest - output specified as Scala Seq DML");
List outputs = Arrays.asList("x", "y");
Seq seq = JavaConversions.asScalaBuffer(outputs).toSeq();
Script script = dml("a=1;x=a+1;y=x+1").out(seq);
MLResults results = ml.execute(script);
Assert.assertEquals(2, results.getLong("x"));
Assert.assertEquals(3, results.getLong("y"));
}
use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.
the class MLContextTest method testOutputRDDStringCSVSparseDML.
@Test
public void testOutputRDDStringCSVSparseDML() {
System.out.println("MLContextTest - output RDD String CSV 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);
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());
}
Aggregations