use of org.apache.sysml.api.mlcontext.MatrixMetadata in project incubator-systemml by apache.
the class MLContextTest method testRDDSumIJVDML.
@Test
public void testRDDSumIJVDML() {
System.out.println("MLContextTest - RDD<String> IJV sum DML");
List<String> list = new ArrayList<String>();
list.add("1 1 1");
list.add("2 1 2");
list.add("1 2 3");
list.add("3 3 4");
JavaRDD<String> javaRDD = sc.parallelize(list);
RDD<String> rdd = JavaRDD.toRDD(javaRDD);
MatrixMetadata mm = new MatrixMetadata(MatrixFormat.IJV, 3, 3);
Script script = dml("print('sum: ' + sum(M));").in("M", rdd, mm);
setExpectedStdOut("sum: 10.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.MatrixMetadata in project incubator-systemml by apache.
the class MLContextTest method testInputTupleSeqWithMetadataDML.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInputTupleSeqWithMetadataDML() {
System.out.println("MLContextTest - Tuple sequence with metadata DML");
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 = dml("print('sums: ' + sum(m1) + ' ' + sum(m2));").in(seq);
setExpectedStdOut("sums: 10.0 26.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.MatrixMetadata in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumPYDMLVectorWithIDColumn.
@Test
public void testDataFrameSumPYDMLVectorWithIDColumn() {
System.out.println("MLContextTest - DataFrame sum PYDML, vector with ID column");
List<Tuple2<Double, Vector>> list = new ArrayList<Tuple2<Double, Vector>>();
list.add(new Tuple2<Double, Vector>(1.0, Vectors.dense(1.0, 2.0, 3.0)));
list.add(new Tuple2<Double, Vector>(2.0, Vectors.dense(4.0, 5.0, 6.0)));
list.add(new Tuple2<Double, Vector>(3.0, Vectors.dense(7.0, 8.0, 9.0)));
JavaRDD<Tuple2<Double, Vector>> javaRddTuple = sc.parallelize(list);
JavaRDD<Row> javaRddRow = javaRddTuple.map(new DoubleVectorRow());
List<StructField> fields = new ArrayList<StructField>();
fields.add(DataTypes.createStructField(RDDConverterUtils.DF_ID_COLUMN, DataTypes.DoubleType, true));
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_WITH_INDEX);
Script script = pydml("print('sum: ' + sum(M))").in("M", dataFrame, mm);
setExpectedStdOut("sum: 45.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.MatrixMetadata in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumDMLMllibVectorWithNoIDColumn.
@Test
public void testDataFrameSumDMLMllibVectorWithNoIDColumn() {
System.out.println("MLContextTest - DataFrame sum DML, mllib vector with no ID column");
List<org.apache.spark.mllib.linalg.Vector> list = new ArrayList<org.apache.spark.mllib.linalg.Vector>();
list.add(org.apache.spark.mllib.linalg.Vectors.dense(1.0, 2.0, 3.0));
list.add(org.apache.spark.mllib.linalg.Vectors.dense(4.0, 5.0, 6.0));
list.add(org.apache.spark.mllib.linalg.Vectors.dense(7.0, 8.0, 9.0));
JavaRDD<org.apache.spark.mllib.linalg.Vector> javaRddVector = sc.parallelize(list);
JavaRDD<Row> javaRddRow = javaRddVector.map(new MllibVectorRow());
List<StructField> fields = new ArrayList<StructField>();
fields.add(DataTypes.createStructField("C1", new org.apache.spark.mllib.linalg.VectorUDT(), true));
StructType schema = DataTypes.createStructType(fields);
Dataset<Row> dataFrame = spark.createDataFrame(javaRddRow, schema);
MatrixMetadata mm = new MatrixMetadata(MatrixFormat.DF_VECTOR);
Script script = dml("print('sum: ' + sum(M));").in("M", dataFrame, mm);
setExpectedStdOut("sum: 45.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.MatrixMetadata in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumPYDMLDoublesWithIDColumn.
@Test
public void testDataFrameSumPYDMLDoublesWithIDColumn() {
System.out.println("MLContextTest - DataFrame sum PYDML, 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 = pydml("print('sum: ' + sum(M))").in("M", dataFrame, mm);
setExpectedStdOut("sum: 45.0");
ml.execute(script);
}
Aggregations