Search in sources :

Example 11 with MatrixMetadata

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

the class MLContextTest method testDataFrameSumDMLDoublesWithIDColumnSortCheck.

@Test
public void testDataFrameSumDMLDoublesWithIDColumnSortCheck() {
    System.out.println("MLContextTest - DataFrame sum DML, doubles with ID column sort check");
    List<String> list = new ArrayList<String>();
    list.add("3,7,8,9");
    list.add("1,1,2,3");
    list.add("2,4,5,6");
    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('M[1,1]: ' + as.scalar(M[1,1]));").in("M", dataFrame, mm);
    setExpectedStdOut("M[1,1]: 1.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)

Example 12 with MatrixMetadata

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

the class MLContextTest method testIJVMatrixFromURLSumDML.

@Test
public void testIJVMatrixFromURLSumDML() throws MalformedURLException {
    System.out.println("MLContextTest - IJV matrix from URL sum DML");
    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 = dml("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 13 with MatrixMetadata

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

the class MLContextTest method testOutputBinaryBlocksPYDML.

@Test
public void testOutputBinaryBlocksPYDML() {
    System.out.println("MLContextTest - output binary blocks PYDML");
    String s = "M = full('1 2 3 4', rows=2, cols=2);";
    MLResults results = ml.execute(pydml(s).out("M"));
    Matrix m = results.getMatrix("M");
    JavaPairRDD<MatrixIndexes, MatrixBlock> binaryBlocks = m.toBinaryBlocks();
    MatrixMetadata mm = m.getMatrixMetadata();
    MatrixCharacteristics mc = mm.asMatrixCharacteristics();
    JavaRDD<String> javaRDDStringIJV = RDDConverterUtils.binaryBlockToTextCell(binaryBlocks, mc);
    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 : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) Matrix(org.apache.sysml.api.mlcontext.Matrix) MLResults(org.apache.sysml.api.mlcontext.MLResults) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) MatrixMetadata(org.apache.sysml.api.mlcontext.MatrixMetadata) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) Test(org.junit.Test)

Example 14 with MatrixMetadata

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

the class MLContextTest method testDataFrameGoodMetadataDML.

@Test
public void testDataFrameGoodMetadataDML() {
    System.out.println("MLContextTest - DataFrame good metadata DML");
    List<String> list = new ArrayList<String>();
    list.add("10,20,30");
    list.add("40,50,60");
    list.add("70,80,90");
    JavaRDD<String> javaRddString = sc.parallelize(list);
    JavaRDD<Row> javaRddRow = javaRddString.map(new CommaSeparatedValueStringToDoubleArrayRow());
    List<StructField> fields = new ArrayList<StructField>();
    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(3, 3, 9);
    Script script = dml("print('sum: ' + sum(M));").in("M", dataFrame, mm);
    setExpectedStdOut("sum: 450.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)

Example 15 with MatrixMetadata

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

the class MLContextTest method testDataFrameSumPYDMLVectorWithNoIDColumn.

@Test
public void testDataFrameSumPYDMLVectorWithNoIDColumn() {
    System.out.println("MLContextTest - DataFrame sum PYDML, vector with no ID column");
    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);
    MatrixMetadata mm = new MatrixMetadata(MatrixFormat.DF_VECTOR);
    Script script = pydml("print('sum: ' + sum(M))").in("M", dataFrame, mm);
    setExpectedStdOut("sum: 45.0");
    ml.execute(script);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) VectorUDT(org.apache.spark.ml.linalg.VectorUDT) 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) Vector(org.apache.spark.ml.linalg.Vector) DenseVector(org.apache.spark.ml.linalg.DenseVector) 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