Search in sources :

Example 46 with MatrixMetadata

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

the class MLContextTest method testInputTupleSeqWithMetadataPYDML.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInputTupleSeqWithMetadataPYDML() {
    System.out.println("MLContextTest - Tuple sequence with metadata PYDML");
    List<String> list1 = new ArrayList<String>();
    list1.add("1,2");
    list1.add("3,4");
    JavaRDD<String> javaRDD1 = sc.parallelize(list1);
    RDD<String> rdd1 = JavaRDD.toRDD(javaRDD1);
    List<String> list2 = new ArrayList<String>();
    list2.add("5,6");
    list2.add("7,8");
    JavaRDD<String> javaRDD2 = sc.parallelize(list2);
    RDD<String> rdd2 = JavaRDD.toRDD(javaRDD2);
    MatrixMetadata mm1 = new MatrixMetadata(2, 2);
    MatrixMetadata mm2 = new MatrixMetadata(2, 2);
    Tuple3 tuple1 = new Tuple3("m1", rdd1, mm1);
    Tuple3 tuple2 = new Tuple3("m2", rdd2, mm2);
    List tupleList = new ArrayList();
    tupleList.add(tuple1);
    tupleList.add(tuple2);
    Seq seq = JavaConversions.asScalaBuffer(tupleList).toSeq();
    Script script = pydml("print('sums: ' + sum(m1) + ' ' + sum(m2))").in(seq);
    setExpectedStdOut("sums: 10.0 26.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Tuple3(scala.Tuple3) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) Seq(scala.collection.Seq) Test(org.junit.Test)

Example 47 with MatrixMetadata

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

the class MLContextTest method testJavaRDDIJVSumDML.

@Test
public void testJavaRDDIJVSumDML() {
    System.out.println("MLContextTest - JavaRDD<String> IJV sum DML");
    List<String> list = new ArrayList<String>();
    list.add("1 1 5");
    list.add("2 2 5");
    list.add("3 3 5");
    JavaRDD<String> javaRDD = sc.parallelize(list);
    MatrixMetadata mm = new MatrixMetadata(MatrixFormat.IJV, 3, 3);
    Script script = dml("print('sum: ' + sum(M));").in("M", javaRDD, mm);
    setExpectedStdOut("sum: 15.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) ArrayList(java.util.ArrayList) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) Test(org.junit.Test)

Example 48 with MatrixMetadata

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

the class MLContextTest method testIJVMatrixFromURLSumPYDML.

@Test
public void testIJVMatrixFromURLSumPYDML() throws MalformedURLException {
    System.out.println("MLContextTest - IJV matrix from URL sum PYDML");
    String ijv = "https://raw.githubusercontent.com/apache/systemml/master/src/test/scripts/org/apache/sysml/api/mlcontext/1234.ijv";
    URL url = new URL(ijv);
    MatrixMetadata mm = new MatrixMetadata(MatrixFormat.IJV, 2, 2);
    Script script = pydml("print('sum: ' + sum(M))").in("M", url, mm);
    setExpectedStdOut("sum: 10.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) URL(java.net.URL) Test(org.junit.Test)

Example 49 with MatrixMetadata

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

the class MLContextTest method testJavaRDDIJVSumPYDML.

@Test
public void testJavaRDDIJVSumPYDML() {
    System.out.println("MLContextTest - JavaRDD<String> IJV sum PYDML");
    List<String> list = new ArrayList<String>();
    list.add("1 1 5");
    list.add("2 2 5");
    list.add("3 3 5");
    JavaRDD<String> javaRDD = sc.parallelize(list);
    MatrixMetadata mm = new MatrixMetadata(MatrixFormat.IJV, 3, 3);
    Script script = pydml("print('sum: ' + sum(M))").in("M", javaRDD, mm);
    setExpectedStdOut("sum: 15.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) ArrayList(java.util.ArrayList) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) Test(org.junit.Test)

Example 50 with MatrixMetadata

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

the class MLContextTest method testJavaRDDGoodMetadataPYDML.

@Test
public void testJavaRDDGoodMetadataPYDML() {
    System.out.println("MLContextTest - JavaRDD<String> good metadata PYDML");
    List<String> list = new ArrayList<String>();
    list.add("1,2,3");
    list.add("4,5,6");
    list.add("7,8,9");
    JavaRDD<String> javaRDD = sc.parallelize(list);
    MatrixMetadata mm = new MatrixMetadata(3, 3, 9);
    Script script = pydml("print('sum: ' + sum(M))").in("M", javaRDD, mm);
    setExpectedStdOut("sum: 45.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) ArrayList(java.util.ArrayList) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) Test(org.junit.Test)

Aggregations

MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)72 Script (org.apache.sysml.api.mlcontext.Script)68 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)60 Row (org.apache.spark.sql.Row)36 StructField (org.apache.spark.sql.types.StructField)34 StructType (org.apache.spark.sql.types.StructType)34 DenseVector (org.apache.spark.ml.linalg.DenseVector)16 Vector (org.apache.spark.ml.linalg.Vector)16 VectorUDT (org.apache.spark.ml.linalg.VectorUDT)16 MLResults (org.apache.sysml.api.mlcontext.MLResults)12 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)10 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)10 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)10 Matrix (org.apache.sysml.api.mlcontext.Matrix)8 Tuple2 (scala.Tuple2)8 URL (java.net.URL)4 List (java.util.List)4 Tuple3 (scala.Tuple3)4 Seq (scala.collection.Seq)4