use of org.apache.sysml.runtime.matrix.MetaDataFormat in project incubator-systemml by apache.
the class PreparedScript method setMatrix.
/**
* Binds a matrix object to a registered input variable.
* If reuse requested, then the input is guaranteed to be
* preserved over multiple <code>executeScript</code> calls.
*
* @param varname input variable name
* @param matrix matrix represented as a MatrixBlock
* @param reuse if {@code true}, preserve value over multiple {@code executeScript} calls
*/
public void setMatrix(String varname, MatrixBlock matrix, boolean reuse) {
if (!_inVarnames.contains(varname))
throw new DMLException("Unspecified input variable: " + varname);
int blocksize = ConfigurationManager.getBlocksize();
// create new matrix object
MatrixCharacteristics mc = new MatrixCharacteristics(matrix.getNumRows(), matrix.getNumColumns(), blocksize, blocksize);
MetaDataFormat meta = new MetaDataFormat(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
MatrixObject mo = new MatrixObject(ValueType.DOUBLE, OptimizerUtils.getUniqueTempFileName(), meta);
mo.acquireModify(matrix);
mo.release();
// put create matrix wrapper into symbol table
_vars.put(varname, mo);
if (reuse) {
// prevent cleanup
mo.enableCleanup(false);
_inVarReuse.put(varname, mo);
}
}
use of org.apache.sysml.runtime.matrix.MetaDataFormat in project incubator-systemml by apache.
the class PreparedScript method setFrame.
/**
* Binds a frame object to a registered input variable.
* If reuse requested, then the input is guaranteed to be
* preserved over multiple <code>executeScript</code> calls.
*
* @param varname input variable name
* @param frame frame represented as a FrameBlock
* @param reuse if {@code true}, preserve value over multiple {@code executeScript} calls
*/
public void setFrame(String varname, FrameBlock frame, boolean reuse) {
if (!_inVarnames.contains(varname))
throw new DMLException("Unspecified input variable: " + varname);
// create new frame object
MatrixCharacteristics mc = new MatrixCharacteristics(frame.getNumRows(), frame.getNumColumns(), -1, -1);
MetaDataFormat meta = new MetaDataFormat(mc, OutputInfo.BinaryCellOutputInfo, InputInfo.BinaryCellInputInfo);
FrameObject fo = new FrameObject(OptimizerUtils.getUniqueTempFileName(), meta);
fo.acquireModify(frame);
fo.release();
// put create matrix wrapper into symbol table
_vars.put(varname, fo);
if (reuse) {
// prevent cleanup
fo.enableCleanup(false);
_inVarReuse.put(varname, fo);
}
}
use of org.apache.sysml.runtime.matrix.MetaDataFormat in project incubator-systemml by apache.
the class MLContextConversionUtil method frameBlockToFrameObject.
/**
* Convert a {@code FrameBlock} to a {@code FrameObject}.
*
* @param variableName
* name of the variable associated with the frame
* @param frameBlock
* frame as a FrameBlock
* @param frameMetadata
* the frame metadata
* @return the {@code FrameBlock} converted to a {@code FrameObject}
*/
public static FrameObject frameBlockToFrameObject(String variableName, FrameBlock frameBlock, FrameMetadata frameMetadata) {
try {
MatrixCharacteristics mc = (frameMetadata != null) ? frameMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
MetaDataFormat mtd = new MetaDataFormat(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
FrameObject frameObject = new FrameObject(OptimizerUtils.getUniqueTempFileName(), mtd, frameMetadata.getFrameSchema().getSchema().toArray(new ValueType[0]));
frameObject.acquireModify(frameBlock);
frameObject.release();
return frameObject;
} catch (DMLRuntimeException e) {
throw new MLContextException("Exception converting FrameBlock to FrameObject", e);
}
}
use of org.apache.sysml.runtime.matrix.MetaDataFormat in project incubator-systemml by apache.
the class MLContextConversionUtil method binaryBlocksToMatrixObject.
private static MatrixObject binaryBlocksToMatrixObject(JavaPairRDD<MatrixIndexes, MatrixBlock> binaryBlocks, MatrixMetadata matrixMetadata, boolean copy) {
MatrixCharacteristics mc = (matrixMetadata != null) ? matrixMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
JavaPairRDD<MatrixIndexes, MatrixBlock> javaPairRdd = SparkUtils.copyBinaryBlockMatrix(binaryBlocks, copy);
MatrixObject matrixObject = new MatrixObject(ValueType.DOUBLE, OptimizerUtils.getUniqueTempFileName(), new MetaDataFormat(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo));
matrixObject.setRDDHandle(new RDDObject(javaPairRdd));
return matrixObject;
}
use of org.apache.sysml.runtime.matrix.MetaDataFormat in project incubator-systemml by apache.
the class MLContextConversionUtil method javaRDDStringCSVToMatrixObject.
/**
* Convert a {@code JavaRDD<String>} in CSV format to a {@code MatrixObject}
*
* @param javaRDD
* the Java RDD of strings
* @param matrixMetadata
* matrix metadata
* @return the {@code JavaRDD<String>} converted to a {@code MatrixObject}
*/
public static MatrixObject javaRDDStringCSVToMatrixObject(JavaRDD<String> javaRDD, MatrixMetadata matrixMetadata) {
JavaPairRDD<LongWritable, Text> javaPairRDD = javaRDD.mapToPair(new ConvertStringToLongTextPair());
MatrixCharacteristics mc = (matrixMetadata != null) ? matrixMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
MatrixObject matrixObject = new MatrixObject(ValueType.DOUBLE, OptimizerUtils.getUniqueTempFileName(), new MetaDataFormat(mc, OutputInfo.CSVOutputInfo, InputInfo.CSVInputInfo));
JavaPairRDD<LongWritable, Text> javaPairRDD2 = javaPairRDD.mapToPair(new CopyTextInputFunction());
matrixObject.setRDDHandle(new RDDObject(javaPairRDD2));
return matrixObject;
}
Aggregations