Search in sources :

Example 1 with WriterMatrixMarket

use of org.apache.sysml.runtime.io.WriterMatrixMarket in project incubator-systemml by apache.

the class VariableCPInstruction method writeMMFile.

/**
	 * Helper function to write MM files to HDFS.
	 * 
	 * @param ec execution context
	 * @param fname file name
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
private void writeMMFile(ExecutionContext ec, String fname) throws DMLRuntimeException {
    MatrixObject mo = ec.getMatrixObject(input1.getName());
    String outFmt = "matrixmarket";
    if (mo.isDirty()) {
        // there exist data computed in CP that is not backed up on HDFS
        // i.e., it is either in-memory or in evicted space
        mo.exportData(fname, outFmt);
    } else {
        OutputInfo oi = ((MatrixFormatMetaData) mo.getMetaData()).getOutputInfo();
        MatrixCharacteristics mc = mo.getMatrixCharacteristics();
        if (oi == OutputInfo.TextCellOutputInfo) {
            try {
                WriterMatrixMarket writer = new WriterMatrixMarket();
                writer.mergeTextcellToMatrixMarket(mo.getFileName(), fname, mc.getRows(), mc.getCols(), mc.getNonZeros());
            } catch (IOException e) {
                throw new DMLRuntimeException(e);
            }
        } else if (oi == OutputInfo.BinaryBlockOutputInfo) {
            mo.exportData(fname, outFmt);
        } else {
            throw new DMLRuntimeException("Unexpected data format (" + OutputInfo.outputInfoToString(oi) + "): can not export into MatrixMarket format.");
        }
    }
}
Also used : OutputInfo(org.apache.sysml.runtime.matrix.data.OutputInfo) WriterMatrixMarket(org.apache.sysml.runtime.io.WriterMatrixMarket) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IOException(java.io.IOException) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

IOException (java.io.IOException)1 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 WriterMatrixMarket (org.apache.sysml.runtime.io.WriterMatrixMarket)1 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)1 MatrixFormatMetaData (org.apache.sysml.runtime.matrix.MatrixFormatMetaData)1 OutputInfo (org.apache.sysml.runtime.matrix.data.OutputInfo)1