use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class GPUTests method generateIntegerSequenceMatrix.
/**
* Generates an input matrix which is a sequence of integers
* @param spark valid instance of {@link SparkSession}
* @param m number of rows
* @param n number of columns
* @return a matrix with a sequence of integers
*/
protected Matrix generateIntegerSequenceMatrix(SparkSession spark, int m, int n) {
MLContext genMLC = new MLContext(spark);
String scriptStr;
scriptStr = "temp = seq(1, " + (m * n) + ")" + "in1 = matrix(temp, rows=" + m + ", cols=" + n + ")";
Script generateScript = ScriptFactory.dmlFromString(scriptStr).out("in1");
Matrix in1 = genMLC.execute(generateScript).getMatrix("in1");
genMLC.close();
return in1;
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class GPUTests method generateInputMatrix.
/**
* Generates a random input matrix with a given size and sparsity
*
* @param spark valid instance of {@link SparkSession}
* @param m number of rows
* @param n number of columns
* @param min min for RNG
* @param max max for RNG
* @param sparsity sparsity (1 = completely dense, 0 = completely sparse)
* @param performRounding performs rounding after generation of random matrix
* @return a random matrix with given size and sparsity
*/
protected Matrix generateInputMatrix(SparkSession spark, int m, int n, double min, double max, double sparsity, int seed, boolean performRounding) {
// Generate a random matrix of size m * n
MLContext genMLC = new MLContext(spark);
String scriptStr;
if (sparsity == 0.0) {
scriptStr = "in1 = matrix(0, rows=" + m + ", cols=" + n + ")";
} else {
scriptStr = "in1 = rand(rows=" + m + ", cols=" + n + ", sparsity = " + sparsity + ", seed= " + seed + ", min=" + min + ", max=" + max + ")";
if (performRounding)
scriptStr += "; in1 = round(in1)";
}
Script generateScript = ScriptFactory.dmlFromString(scriptStr).out("in1");
Matrix in1 = genMLC.execute(generateScript).getMatrix("in1");
genMLC.close();
return in1;
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testDataFrameSumDMLDoublesWithNoIDColumn.
@Test
public void testDataFrameSumDMLDoublesWithNoIDColumn() {
System.out.println("MLContextTest - DataFrame sum DML, doubles with no ID column");
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(MatrixFormat.DF_DOUBLES);
Script script = dml("print('sum: ' + sum(M));").in("M", dataFrame, mm);
setExpectedStdOut("sum: 450.0");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testInputFramePYDML.
@Test
public void testInputFramePYDML() {
System.out.println("MLContextTest - input frame PYDML");
String s = "M = load($Min, data_type='frame', format='csv')\nprint(toString(M))";
String csvFile = baseDirectory + File.separator + "one-two-three-four.csv";
Script script = pydml(s).in("$Min", csvFile);
setExpectedStdOut("one");
ml.execute(script);
}
use of org.apache.sysml.api.mlcontext.Script in project incubator-systemml by apache.
the class MLContextTest method testInputFrameDML.
@Test
public void testInputFrameDML() {
System.out.println("MLContextTest - input frame DML");
String s = "M = read($Min, data_type='frame', format='csv'); print(toString(M));";
String csvFile = baseDirectory + File.separator + "one-two-three-four.csv";
Script script = dml(s).in("$Min", csvFile);
setExpectedStdOut("one");
ml.execute(script);
}
Aggregations