Search in sources :

Example 11 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.

the class MLContextTest method testOutputListStringCSVDenseDML.

@Test
public void testOutputListStringCSVDenseDML() {
    System.out.println("MLContextTest - output List String CSV Dense DML");
    String s = "M = matrix('1 2 3 4', rows=2, cols=2); print(toString(M));";
    Script script = dml(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 12 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.

the class MLContextTest method testOutputJavaRDDStringIJVFromMatrixDML.

@Test
public void testOutputJavaRDDStringIJVFromMatrixDML() {
    System.out.println("MLContextTest - output Java RDD String IJV from matrix DML");
    String s = "M = matrix('1 2 3 4', rows=2, cols=2);";
    Script script = dml(s).out("M");
    MLResults results = ml.execute(script);
    JavaRDD<String> javaRDDStringIJV = results.getJavaRDDStringIJV("M");
    List<String> lines = javaRDDStringIJV.sortBy(row -> row, true, 1).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));
}
Also used : MatrixFormat(org.apache.sysml.api.mlcontext.MatrixFormat) Arrays(java.util.Arrays) URL(java.net.URL) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) Map(java.util.Map) DoubleType(org.apache.spark.sql.types.DoubleType) ScriptFactory.dml(org.apache.sysml.api.mlcontext.ScriptFactory.dml) ScriptFactory.pydmlFromUrl(org.apache.sysml.api.mlcontext.ScriptFactory.pydmlFromUrl) DataTypes(org.apache.spark.sql.types.DataTypes) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) Vector(org.apache.spark.ml.linalg.Vector) DenseVector(org.apache.spark.ml.linalg.DenseVector) MLContextConversionUtil(org.apache.sysml.api.mlcontext.MLContextConversionUtil) Seq(scala.collection.Seq) Tuple4(scala.Tuple4) ScriptFactory.dmlFromLocalFile(org.apache.sysml.api.mlcontext.ScriptFactory.dmlFromLocalFile) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) Tuple3(scala.Tuple3) Tuple1(scala.Tuple1) List(java.util.List) Stream(java.util.stream.Stream) ScriptFactory.pydmlFromFile(org.apache.sysml.api.mlcontext.ScriptFactory.pydmlFromFile) MLResults(org.apache.sysml.api.mlcontext.MLResults) Vectors(org.apache.spark.ml.linalg.Vectors) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) Function(org.apache.spark.api.java.function.Function) ScriptFactory.dmlFromFile(org.apache.sysml.api.mlcontext.ScriptFactory.dmlFromFile) RDD(org.apache.spark.rdd.RDD) ScriptFactory.dmlFromInputStream(org.apache.sysml.api.mlcontext.ScriptFactory.dmlFromInputStream) Dataset(org.apache.spark.sql.Dataset) MLContextException(org.apache.sysml.api.mlcontext.MLContextException) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) RDDConverterUtils(org.apache.sysml.runtime.instructions.spark.utils.RDDConverterUtils) MLContextUtil(org.apache.sysml.api.mlcontext.MLContextUtil) HashMap(java.util.HashMap) DataConverter(org.apache.sysml.runtime.util.DataConverter) ArrayList(java.util.ArrayList) Script(org.apache.sysml.api.mlcontext.Script) Statistics(org.apache.sysml.utils.Statistics) VectorUDT(org.apache.spark.ml.linalg.VectorUDT) ScriptFactory.pydmlFromLocalFile(org.apache.sysml.api.mlcontext.ScriptFactory.pydmlFromLocalFile) JavaRDD(org.apache.spark.api.java.JavaRDD) JavaConversions(scala.collection.JavaConversions) MalformedURLException(java.net.MalformedURLException) RowFactory(org.apache.spark.sql.RowFactory) Iterator(scala.collection.Iterator) Matrix(org.apache.sysml.api.mlcontext.Matrix) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Row(org.apache.spark.sql.Row) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) File(java.io.File) ScriptFactory.pydml(org.apache.sysml.api.mlcontext.ScriptFactory.pydml) ScriptFactory.pydmlFromInputStream(org.apache.sysml.api.mlcontext.ScriptFactory.pydmlFromInputStream) ScriptFactory.dmlFromUrl(org.apache.sysml.api.mlcontext.ScriptFactory.dmlFromUrl) ScriptExecutor(org.apache.sysml.api.mlcontext.ScriptExecutor) Assert(org.junit.Assert) InputStream(java.io.InputStream) Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 13 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.

the class MLContextTest method testOutputJavaRDDStringIJVDML.

@Test
public void testOutputJavaRDDStringIJVDML() {
    System.out.println("MLContextTest - output Java RDD String IJV DML");
    String s = "M = matrix('1 2 3 4', rows=2, cols=2);";
    Script script = dml(s).out("M");
    MLResults results = ml.execute(script);
    JavaRDD<String> javaRDDStringIJV = results.getJavaRDDStringIJV("M");
    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));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) Test(org.junit.Test)

Example 14 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.

the class MLContextTest method testOutputListStringIJVDensePYDML.

@Test
public void testOutputListStringIJVDensePYDML() {
    System.out.println("MLContextTest - output List String IJV 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);
    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));
}
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 15 with MLResults

use of org.apache.sysml.api.mlcontext.MLResults in project incubator-systemml by apache.

the class MLContextTest method testOutputScalaSeqPYDML.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testOutputScalaSeqPYDML() {
    System.out.println("MLContextTest - output specified as Scala Seq PYDML");
    List outputs = Arrays.asList("x", "y");
    Seq seq = JavaConversions.asScalaBuffer(outputs).toSeq();
    Script script = pydml("a=1\nx=a+1\ny=x+1").out(seq);
    MLResults results = ml.execute(script);
    Assert.assertEquals(2, results.getLong("x"));
    Assert.assertEquals(3, results.getLong("y"));
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MLResults(org.apache.sysml.api.mlcontext.MLResults) List(java.util.List) ArrayList(java.util.ArrayList) Seq(scala.collection.Seq) Test(org.junit.Test)

Aggregations

MLResults (org.apache.sysml.api.mlcontext.MLResults)51 Script (org.apache.sysml.api.mlcontext.Script)47 Test (org.junit.Test)44 Row (org.apache.spark.sql.Row)18 ArrayList (java.util.ArrayList)11 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 StructType (org.apache.spark.sql.types.StructType)7 MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)7 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)7 StructField (org.apache.spark.sql.types.StructField)6 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)6 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)6 FrameMetadata (org.apache.sysml.api.mlcontext.FrameMetadata)5 Matrix (org.apache.sysml.api.mlcontext.Matrix)5 List (java.util.List)4 CommaSeparatedValueStringToDoubleArrayRow (org.apache.sysml.test.integration.mlcontext.MLContextTest.CommaSeparatedValueStringToDoubleArrayRow)4 IOException (java.io.IOException)3 Seq (scala.collection.Seq)3 HashMap (java.util.HashMap)2 JavaRDD (org.apache.spark.api.java.JavaRDD)2