use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testOutputDataFramePYDMLDoublesNoIDColumn.
@Test
public void testOutputDataFramePYDMLDoublesNoIDColumn() {
System.out.println("MLContextTest - output DataFrame PYDML, doubles no 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.getDataFrameDoubleNoIDColumn("M");
List<Row> list = dataFrame.collectAsList();
Row row1 = list.get(0);
Assert.assertEquals(1.0, row1.getDouble(0), 0.0);
Assert.assertEquals(2.0, row1.getDouble(1), 0.0);
Row row2 = list.get(1);
Assert.assertEquals(3.0, row2.getDouble(0), 0.0);
Assert.assertEquals(4.0, row2.getDouble(1), 0.0);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testFunctionNoReturnValueForceFunctionCallDML.
@Test
public void testFunctionNoReturnValueForceFunctionCallDML() {
System.out.println("MLContextTest - function with no return value, force function call DML");
String s = "hello=function(){\nwhile(FALSE){};\nprint('no return value, force function call');\n}\nhello();";
Script script = dml(s);
setExpectedStdOut("no return value, force function call");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumDMLVectorWithNoIDColumnNoFormatSpecified.
@Test
public void testDataFrameSumDMLVectorWithNoIDColumnNoFormatSpecified() {
System.out.println("MLContextTest - DataFrame sum DML, vector with no ID column, no format specified");
List<Vector> list = new ArrayList<Vector>();
list.add(Vectors.dense(1.0, 2.0, 3.0));
list.add(Vectors.dense(4.0, 5.0, 6.0));
list.add(Vectors.dense(7.0, 8.0, 9.0));
JavaRDD<Vector> javaRddVector = sc.parallelize(list);
JavaRDD<Row> javaRddRow = javaRddVector.map(new VectorRow());
List<StructField> fields = new ArrayList<StructField>();
fields.add(DataTypes.createStructField("C1", new VectorUDT(), true));
StructType schema = DataTypes.createStructType(fields);
Dataset<Row> dataFrame = spark.createDataFrame(javaRddRow, schema);
Script script = dml("print('sum: ' + sum(M));").in("M", dataFrame);
setExpectedStdOut("sum: 45.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testCreatePYDMLScriptBasedOnFileAndExecute.
@Test
public void testCreatePYDMLScriptBasedOnFileAndExecute() {
System.out.println("MLContextTest - create PYDML script based on file and execute");
setExpectedStdOut("hello world");
Script script = pydmlFromFile(baseDirectory + File.separator + "hello-world.pydml");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testFunctionNoReturnValueDML.
@Test
public void testFunctionNoReturnValueDML() {
System.out.println("MLContextTest - function with no return value DML");
String s = "hello=function(){print('no return value')}\nhello();";
Script script = dml(s);
setExpectedStdOut("no return value");
ml.execute(script);
}
Aggregations