use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class MLContextConversionUtil method matrixObjectToDataFrame.
/**
* Convert a {@code MatrixObject} to a {@code DataFrame}.
*
* @param matrixObject
* the {@code MatrixObject}
* @param sparkExecutionContext
* the Spark execution context
* @param isVectorDF
* is the DataFrame a vector DataFrame?
* @return the {@code MatrixObject} converted to a {@code DataFrame}
*/
public static Dataset<Row> matrixObjectToDataFrame(MatrixObject matrixObject, SparkExecutionContext sparkExecutionContext, boolean isVectorDF) {
try {
@SuppressWarnings("unchecked") JavaPairRDD<MatrixIndexes, MatrixBlock> binaryBlocks = (JavaPairRDD<MatrixIndexes, MatrixBlock>) sparkExecutionContext.getRDDHandleForMatrixObject(matrixObject, InputInfo.BinaryBlockInputInfo);
MatrixCharacteristics mc = matrixObject.getMatrixCharacteristics();
return RDDConverterUtils.binaryBlockToDataFrame(spark(), binaryBlocks, mc, isVectorDF);
} catch (DMLRuntimeException e) {
throw new MLContextException("DMLRuntimeException while converting matrix object to DataFrame", e);
}
}
use of org.apache.sysml.runtime.DMLRuntimeException 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.DMLRuntimeException in project incubator-systemml by apache.
the class MLContextConversionUtil method javaRDDStringCSVToFrameObject.
/**
* Convert a {@code JavaRDD<String>} in CSV format to a {@code FrameObject}
*
* @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(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 MetaDataFormat(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));
return frameObject;
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class ScriptExecutor method liveVariableAnalysis.
/**
* Liveness analysis is performed on the program, obtaining sets of live-in
* and live-out variables by forward and backward passes over the program.
*/
protected void liveVariableAnalysis() {
try {
dmlTranslator = new DMLTranslator(dmlProgram);
dmlTranslator.liveVariableAnalysis(dmlProgram);
} catch (DMLRuntimeException e) {
throw new MLContextException("Exception occurred during live variable analysis", e);
} catch (LanguageException e) {
throw new MLContextException("Exception occurred during live variable analysis", e);
}
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class DMLConfig method parseDMLConfig.
public static DMLConfig parseDMLConfig(String content) {
DMLConfig ret = null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document domTree = null;
domTree = builder.parse(new ByteArrayInputStream(content.getBytes("utf-8")));
Element root = domTree.getDocumentElement();
ret = new DMLConfig(root);
} catch (Exception ex) {
throw new DMLRuntimeException("Unable to parse DML config.", ex);
}
return ret;
}
Aggregations