use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testFunctionReturnValueDML.
@Test
public void testFunctionReturnValueDML() {
System.out.println("MLContextTest - function with return value DML");
String s = "hello=function()return(string s){s='return value'}\na=hello();\nprint(a);";
Script script = dml(s);
setExpectedStdOut("return value");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testDisplayBooleanPYDML.
@Test
public void testDisplayBooleanPYDML() {
System.out.println("MLContextTest - display boolean PYDML");
String s = "print(b)";
Script script = pydml(s).in("b", true);
setExpectedStdOut("True");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script 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));
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testRDDSumIJVDML.
@Test
public void testRDDSumIJVDML() {
System.out.println("MLContextTest - RDD<String> IJV sum DML");
List<String> list = new ArrayList<String>();
list.add("1 1 1");
list.add("2 1 2");
list.add("1 2 3");
list.add("3 3 4");
JavaRDD<String> javaRDD = sc.parallelize(list);
RDD<String> rdd = JavaRDD.toRDD(javaRDD);
MatrixMetadata mm = new MatrixMetadata(MatrixFormat.IJV, 3, 3);
Script script = dml("print('sum: ' + sum(M));").in("M", rdd, mm);
setExpectedStdOut("sum: 10.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testOutputDataFrameVectorsWithIDColumnFromMatrixDML.
@Test
public void testOutputDataFrameVectorsWithIDColumnFromMatrixDML() {
System.out.println("MLContextTest - output DataFrame of vectors with ID column from matrix DML");
String s = "M = matrix('1 2 3 4', rows=1, cols=4);";
Script script = dml(s).out("M");
Dataset<Row> df = ml.execute(script).getMatrix("M").toDFVectorWithIDColumn();
List<Row> list = df.collectAsList();
Row row = list.get(0);
Assert.assertEquals(1.0, row.getDouble(0), 0.0);
Assert.assertArrayEquals(new double[] { 1.0, 2.0, 3.0, 4.0 }, ((Vector) row.get(1)).toArray(), 0.0);
}
Aggregations