use of org.apache.sysml.runtime.io.FrameWriter in project incubator-systemml by apache.
the class FrameMatrixCastingTest method writeMatrixOrFrameInput.
private static void writeMatrixOrFrameInput(String fname, double[][] A, int rows, int cols, DataType dt, ValueType vt) throws IOException {
int blksize = ConfigurationManager.getBlocksize();
// write input data
if (dt == DataType.FRAME) {
FrameBlock fb = DataConverter.convertToFrameBlock(DataConverter.convertToMatrixBlock(A), vt);
FrameWriter writer = FrameWriterFactory.createFrameWriter(OutputInfo.BinaryBlockOutputInfo);
writer.writeFrameToHDFS(fb, fname, rows, cols);
} else {
MatrixBlock mb = DataConverter.convertToMatrixBlock(A);
MatrixWriter writer = MatrixWriterFactory.createMatrixWriter(OutputInfo.BinaryBlockOutputInfo);
writer.writeMatrixToHDFS(mb, fname, (long) rows, (long) cols, blksize, blksize, -1);
}
// write meta data
MatrixCharacteristics mc = new MatrixCharacteristics(rows, cols, blksize, blksize);
MapReduceTool.writeMetaDataFile(fname + ".mtd", vt, null, dt, mc, OutputInfo.BinaryBlockOutputInfo);
}
use of org.apache.sysml.runtime.io.FrameWriter in project incubator-systemml by apache.
the class FrameMatrixReblockTest method writeFrameInput.
private static void writeFrameInput(String fname, String ofmt, double[][] frame, int rows, int cols) throws IOException {
MatrixBlock mb = DataConverter.convertToMatrixBlock(frame);
FrameBlock fb = DataConverter.convertToFrameBlock(mb);
// write input data
FrameWriter writer = FrameWriterFactory.createFrameWriter(InputInfo.getMatchingOutputInfo(InputInfo.stringExternalToInputInfo(ofmt)));
writer.writeFrameToHDFS(fb, fname, rows, cols);
}
use of org.apache.sysml.runtime.io.FrameWriter in project incubator-systemml by apache.
the class FrameReadWriteTest method writeAndVerifyData.
void writeAndVerifyData(OutputInfo oinfo, FrameBlock frame1, FrameBlock frame2, CSVFileFormatProperties fprop) throws IOException {
String fname1 = SCRIPT_DIR + TEST_DIR + "/frameData1";
String fname2 = SCRIPT_DIR + TEST_DIR + "/frameData2";
// Create reader/writer
FrameWriter writer = FrameWriterFactory.createFrameWriter(oinfo, fprop);
FrameReader reader = FrameReaderFactory.createFrameReader(OutputInfo.getMatchingInputInfo(oinfo), fprop);
// Write frame data to disk
writer.writeFrameToHDFS(frame1, fname1, frame1.getNumRows(), frame1.getNumColumns());
writer.writeFrameToHDFS(frame2, fname2, frame2.getNumRows(), frame2.getNumColumns());
// Read frame data from disk
FrameBlock frame1Read = reader.readFrameFromHDFS(fname1, frame1.getSchema(), frame1.getNumRows(), frame1.getNumColumns());
FrameBlock frame2Read = reader.readFrameFromHDFS(fname2, frame2.getSchema(), frame2.getNumRows(), frame2.getNumColumns());
// Verify that data read with original frames
verifyFrameData(frame1, frame1Read);
verifyFrameData(frame2, frame2Read);
MapReduceTool.deleteFileIfExistOnHDFS(fname1);
MapReduceTool.deleteFileIfExistOnHDFS(fname2);
}
use of org.apache.sysml.runtime.io.FrameWriter in project incubator-systemml by apache.
the class FrameObject method writeBlobToHDFS.
@Override
protected void writeBlobToHDFS(String fname, String ofmt, int rep, FileFormatProperties fprop) throws IOException, DMLRuntimeException {
OutputInfo oinfo = OutputInfo.stringToOutputInfo(ofmt);
FrameWriter writer = FrameWriterFactory.createFrameWriter(oinfo, fprop);
writer.writeFrameToHDFS(_data, fname, getNumRows(), getNumColumns());
}
use of org.apache.sysml.runtime.io.FrameWriter in project systemml by apache.
the class TransformEncodeDecodeTest method runTransformEncodeDecodeTest.
private void runTransformEncodeDecodeTest(ExecType et, boolean sparse, String fmt) {
RUNTIME_PLATFORM platformOld = rtplatform;
// only CP supported
rtplatform = RUNTIME_PLATFORM.HYBRID;
try {
getAndLoadTestConfiguration(TEST_NAME1);
// get input/output info
InputInfo iinfo = InputInfo.stringExternalToInputInfo(fmt);
OutputInfo oinfo = InputInfo.getMatchingOutputInfo(iinfo);
// generate and write input data
double[][] A = TestUtils.round(getRandomMatrix(rows, cols, 1, 15, sparse ? sparsity2 : sparsity1, 7));
FrameBlock FA = DataConverter.convertToFrameBlock(DataConverter.convertToMatrixBlock(A));
FrameWriter writer = FrameWriterFactory.createFrameWriter(oinfo);
writer.writeFrameToHDFS(FA, input("F"), rows, cols);
fullDMLScriptName = SCRIPT_DIR + TEST_DIR + TEST_NAME1 + ".dml";
programArgs = new String[] { "-explain", "-args", input("F"), fmt, String.valueOf(rows), String.valueOf(cols), SCRIPT_DIR + TEST_DIR + SPEC, output("FO") };
// run test
runTest(true, false, null, -1);
// compare matrices (values recoded to identical codes)
FrameReader reader = FrameReaderFactory.createFrameReader(iinfo);
FrameBlock FO = reader.readFrameFromHDFS(output("FO"), 16, 2);
HashMap<String, Long> cFA = getCounts(FA, 1);
Iterator<String[]> iterFO = FO.getStringRowIterator();
while (iterFO.hasNext()) {
String[] row = iterFO.next();
Double expected = (double) cFA.get(row[1]);
Double val = (row[0] != null) ? Double.valueOf(row[0]) : 0;
Assert.assertEquals("Output aggregates don't match: " + expected + " vs " + val, expected, val);
}
} catch (Exception ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
} finally {
rtplatform = platformOld;
}
}
Aggregations