Search in sources :

Example 6 with Script

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;
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Matrix(org.apache.sysml.api.mlcontext.Matrix) MLContext(org.apache.sysml.api.mlcontext.MLContext)

Example 7 with Script

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;
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Matrix(org.apache.sysml.api.mlcontext.Matrix) MLContext(org.apache.sysml.api.mlcontext.MLContext)

Example 8 with Script

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);
}
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 9 with 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);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Example 10 with 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);
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) Test(org.junit.Test)

Aggregations

Script (org.apache.sysml.api.mlcontext.Script)410 Test (org.junit.Test)374 ArrayList (java.util.ArrayList)126 Row (org.apache.spark.sql.Row)104 MLResults (org.apache.sysml.api.mlcontext.MLResults)94 StructType (org.apache.spark.sql.types.StructType)70 MatrixMetadata (org.apache.sysml.api.mlcontext.MatrixMetadata)70 StructField (org.apache.spark.sql.types.StructField)68 DenseVector (org.apache.spark.ml.linalg.DenseVector)28 Vector (org.apache.spark.ml.linalg.Vector)28 VectorUDT (org.apache.spark.ml.linalg.VectorUDT)28 Matrix (org.apache.sysml.api.mlcontext.Matrix)26 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)26 MLContext (org.apache.sysml.api.mlcontext.MLContext)18 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)18 Tuple2 (scala.Tuple2)18 List (java.util.List)16 URL (java.net.URL)14 DMLScript (org.apache.sysml.api.DMLScript)14 Seq (scala.collection.Seq)14