Search in sources :

Example 1 with FrameBlock

use of org.apache.sysml.runtime.matrix.data.FrameBlock in project incubator-systemml by apache.

the class ResultVariables method getFrame.

/**
	 * Obtain the frame represented by the given output variable.
	 * 
	 * @param varname output variable name
	 * @return frame as a two-dimensional string array
	 * @throws DMLException if DMLException occurs
	 */
public String[][] getFrame(String varname) throws DMLException {
    if (!_out.containsKey(varname))
        throw new DMLException("Non-existent output variable: " + varname);
    Data dat = _out.get(varname);
    //basic checks for data type	
    if (!(dat instanceof FrameObject))
        throw new DMLException("Expected frame result '" + varname + "' not a frame.");
    //convert output matrix to double array	
    FrameObject fo = (FrameObject) dat;
    FrameBlock frame = fo.acquireRead();
    String[][] ret = DataConverter.convertToStringFrame(frame);
    fo.release();
    return ret;
}
Also used : DMLException(org.apache.sysml.api.DMLException) FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) Data(org.apache.sysml.runtime.instructions.cp.Data) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject)

Example 2 with FrameBlock

use of org.apache.sysml.runtime.matrix.data.FrameBlock in project incubator-systemml by apache.

the class MLContextConversionUtil method javaRDDStringCSVToFrameObject.

/**
	 * Convert a {@code JavaRDD<String>} in CSV format to a {@code FrameObject}
	 * 
	 * @param variableName
	 *            name of the variable associated with the frame
	 * @param javaRDD
	 *            the Java RDD of strings
	 * @param frameMetadata
	 *            frame metadata
	 * @return the {@code JavaRDD<String>} converted to a {@code FrameObject}
	 */
public static FrameObject javaRDDStringCSVToFrameObject(String variableName, JavaRDD<String> javaRDD, FrameMetadata frameMetadata) {
    JavaPairRDD<LongWritable, Text> javaPairRDD = javaRDD.mapToPair(new ConvertStringToLongTextPair());
    MatrixCharacteristics mc = (frameMetadata != null) ? frameMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
    JavaPairRDD<LongWritable, Text> javaPairRDDText = javaPairRDD.mapToPair(new CopyTextInputFunction());
    FrameObject frameObject = new FrameObject(OptimizerUtils.getUniqueTempFileName(), new MatrixFormatMetaData(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo), frameMetadata.getFrameSchema().getSchema().toArray(new ValueType[0]));
    JavaPairRDD<Long, FrameBlock> rdd;
    try {
        rdd = FrameRDDConverterUtils.csvToBinaryBlock(jsc(), javaPairRDDText, mc, frameObject.getSchema(), false, ",", false, -1);
    } catch (DMLRuntimeException e) {
        e.printStackTrace();
        return null;
    }
    frameObject.setRDDHandle(new RDDObject(rdd, variableName));
    return frameObject;
}
Also used : ValueType(org.apache.sysml.parser.Expression.ValueType) Text(org.apache.hadoop.io.Text) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CopyTextInputFunction(org.apache.sysml.runtime.instructions.spark.functions.CopyTextInputFunction) ConvertStringToLongTextPair(org.apache.sysml.runtime.instructions.spark.functions.ConvertStringToLongTextPair) FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) RDDObject(org.apache.sysml.runtime.instructions.spark.data.RDDObject) LongWritable(org.apache.hadoop.io.LongWritable)

Example 3 with FrameBlock

use of org.apache.sysml.runtime.matrix.data.FrameBlock in project incubator-systemml by apache.

the class MLContextConversionUtil method frameObjectToBinaryBlockFrame.

/**
	 * Convert a {@code FrameObject} to a {@code BinaryBlockFrame}.
	 * 
	 * @param frameObject
	 *            the {@code FrameObject}
	 * @param sparkExecutionContext
	 *            the Spark execution context
	 * @return the {@code FrameObject} converted to a {@code BinaryBlockFrame}
	 */
public static BinaryBlockFrame frameObjectToBinaryBlockFrame(FrameObject frameObject, SparkExecutionContext sparkExecutionContext) {
    try {
        @SuppressWarnings("unchecked") JavaPairRDD<Long, FrameBlock> binaryBlock = (JavaPairRDD<Long, FrameBlock>) sparkExecutionContext.getRDDHandleForFrameObject(frameObject, InputInfo.BinaryBlockInputInfo);
        MatrixCharacteristics matrixCharacteristics = frameObject.getMatrixCharacteristics();
        FrameSchema fs = new FrameSchema(Arrays.asList(frameObject.getSchema()));
        FrameMetadata fm = new FrameMetadata(fs, matrixCharacteristics);
        return new BinaryBlockFrame(binaryBlock, fm);
    } catch (DMLRuntimeException e) {
        throw new MLContextException("DMLRuntimeException while converting frame object to BinaryBlockFrame", e);
    }
}
Also used : FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with FrameBlock

use of org.apache.sysml.runtime.matrix.data.FrameBlock in project incubator-systemml by apache.

the class Connection method readStringFrame.

/**
 * Reads an input frame in arbitrary format from HDFS into a dense string array.
 * NOTE: this call currently only supports default configurations for CSV.
 *
 * @param fname the filename of the input frame
 * @param iinfo InputInfo object
 * @param rows number of rows in the frame
 * @param cols number of columns in the frame
 * @return frame as a two-dimensional string array
 * @throws IOException if IOException occurs
 */
public String[][] readStringFrame(String fname, InputInfo iinfo, long rows, long cols) throws IOException {
    setLocalConfigs();
    try {
        FrameReader reader = FrameReaderFactory.createFrameReader(iinfo);
        FrameBlock mb = reader.readFrameFromHDFS(fname, rows, cols);
        return DataConverter.convertToStringFrame(mb);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}
Also used : FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) FrameReader(org.apache.sysml.runtime.io.FrameReader) IOException(java.io.IOException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLException(org.apache.sysml.api.DMLException) LanguageException(org.apache.sysml.parser.LanguageException) IOException(java.io.IOException) ParseException(org.apache.sysml.parser.ParseException)

Example 5 with FrameBlock

use of org.apache.sysml.runtime.matrix.data.FrameBlock in project incubator-systemml by apache.

the class ResultVariables method getFrameBlock.

/**
 * Obtain the frame represented by the given output variable.
 * Calling this method avoids unnecessary output conversions.
 *
 * @param varname output variable name
 * @return frame as a frame block
 */
public FrameBlock getFrameBlock(String varname) {
    Data dat = _out.get(varname);
    if (dat == null)
        throw new DMLException("Non-existent output variable: " + varname);
    // basic checks for data type
    if (!(dat instanceof FrameObject))
        throw new DMLException("Expected frame result '" + varname + "' not a frame.");
    // convert output matrix to double array
    FrameObject fo = (FrameObject) dat;
    FrameBlock fb = fo.acquireRead();
    fo.release();
    return fb;
}
Also used : DMLException(org.apache.sysml.api.DMLException) FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) Data(org.apache.sysml.runtime.instructions.cp.Data) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject)

Aggregations

FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)174 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)51 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)48 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)45 ValueType (org.apache.sysml.parser.Expression.ValueType)43 FrameReader (org.apache.sysml.runtime.io.FrameReader)35 IOException (java.io.IOException)31 RUNTIME_PLATFORM (org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM)31 FrameObject (org.apache.sysml.runtime.controlprogram.caching.FrameObject)27 LongWritable (org.apache.hadoop.io.LongWritable)22 JavaPairRDD (org.apache.spark.api.java.JavaPairRDD)21 CSVFileFormatProperties (org.apache.sysml.runtime.matrix.data.CSVFileFormatProperties)21 FrameWriter (org.apache.sysml.runtime.io.FrameWriter)18 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)16 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)14 Text (org.apache.hadoop.io.Text)12 RDDObject (org.apache.sysml.runtime.instructions.spark.data.RDDObject)12 ArrayList (java.util.ArrayList)10 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)10 ConvertStringToLongTextPair (org.apache.sysml.runtime.instructions.spark.functions.ConvertStringToLongTextPair)9