use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testCreatePYDMLScriptBasedOnURL.
@Test
public void testCreatePYDMLScriptBasedOnURL() throws MalformedURLException {
System.out.println("MLContextTest - create PYDML script based on URL");
String urlString = "https://raw.githubusercontent.com/apache/systemml/master/src/test/scripts/applications/hits/HITS.pydml";
URL url = new URL(urlString);
Script script = pydmlFromUrl(url);
String expectedContent = "Licensed to the Apache Software Foundation";
String s = script.getScriptString();
assertTrue("Script string doesn't contain expected content: " + expectedContent, s.contains(expectedContent));
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testExecutePYDMLScript.
@Test
public void testExecutePYDMLScript() {
System.out.println("MLContextTest - execute PYDML script");
String testString = "hello pydml world!";
setExpectedStdOut(testString);
Script script = new Script("print('" + testString + "')", org.apache.sysml.api.mlcontext.ScriptType.PYDML);
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testPrintFormattingMultipleExpressions.
@Test
public void testPrintFormattingMultipleExpressions() {
System.out.println("MLContextTest - print formatting multiple expressions");
Script script = dml("a='hello'; b='goodbye'; c=4; d=3; e=3.0; f=5.0; g=FALSE; print('%s %d %f %b', (a+b), (c-d), (e*f), !g);");
setExpectedStdOut("hellogoodbye 1 15.000000 true");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testOutputListStringCSVSparsePYDML.
@Test
public void testOutputListStringCSVSparsePYDML() {
System.out.println("MLContextTest - output List 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);
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.Script in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumDMLDoublesWithIDColumn.
@Test
public void testDataFrameSumDMLDoublesWithIDColumn() {
System.out.println("MLContextTest - DataFrame sum DML, doubles with ID column");
List<String> list = new ArrayList<String>();
list.add("1,1,2,3");
list.add("2,4,5,6");
list.add("3,7,8,9");
JavaRDD<String> javaRddString = sc.parallelize(list);
JavaRDD<Row> javaRddRow = javaRddString.map(new CommaSeparatedValueStringToDoubleArrayRow());
List<StructField> fields = new ArrayList<StructField>();
fields.add(DataTypes.createStructField(RDDConverterUtils.DF_ID_COLUMN, DataTypes.DoubleType, true));
fields.add(DataTypes.createStructField("C1", DataTypes.DoubleType, true));
fields.add(DataTypes.createStructField("C2", DataTypes.DoubleType, true));
fields.add(DataTypes.createStructField("C3", DataTypes.DoubleType, true));
StructType schema = DataTypes.createStructType(fields);
Dataset<Row> dataFrame = spark.createDataFrame(javaRddRow, schema);
MatrixMetadata mm = new MatrixMetadata(MatrixFormat.DF_DOUBLES_WITH_INDEX);
Script script = dml("print('sum: ' + sum(M));").in("M", dataFrame, mm);
setExpectedStdOut("sum: 45.0");
ml.execute(script);
}
Aggregations