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;
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations