Search in sources :

Example 16 with Script

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));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) URL(java.net.URL) Test(org.junit.Test)

Example 17 with Script

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);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 18 with 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);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 19 with 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));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 20 with Script

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);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) StructType(org.apache.spark.sql.types.StructType) ArrayList(java.util.ArrayList) StructField(org.apache.spark.sql.types.StructField) Row(org.apache.spark.sql.Row) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) Test(org.junit.Test)

Aggregations

Script (org.apache.sysml.api.mlcontext.Script)410 Test (org.junit.Test)374 ArrayList (java.util.ArrayList)126 Row (org.apache.spark.sql.Row)104 MLResults (org.apache.sysml.api.mlcontext.MLResults)94 StructType (org.apache.spark.sql.types.StructType)70 MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)70 StructField (org.apache.spark.sql.types.StructField)68 DenseVector (org.apache.spark.ml.linalg.DenseVector)28 Vector (org.apache.spark.ml.linalg.Vector)28 VectorUDT (org.apache.spark.ml.linalg.VectorUDT)28 Matrix (org.apache.sysml.api.mlcontext.Matrix)26 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)26 MLContext (org.apache.sysml.api.mlcontext.MLContext)18 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)18 Tuple2 (scala.Tuple2)18 List (java.util.List)16 URL (java.net.URL)14 DMLScript (org.apache.sysml.api.DMLScript)14 Seq (scala.collection.Seq)14