use of org.apache.sysml.parser.Expression.DataType in project systemml by apache.
the class GenerateClassesForMLContext method getParamTypeAsString.
/**
* Obtain a string representation of a parameter type, where a Matrix or
* Frame is represented by its full class name.
*
* @param param
* the function parameter
* @return string representation of a parameter type
*/
public static String getParamTypeAsString(DataIdentifier param) {
DataType dt = param.getDataType();
ValueType vt = param.getValueType();
if ((dt == DataType.SCALAR) && (vt == ValueType.INT)) {
return "long";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.DOUBLE)) {
return "double";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.BOOLEAN)) {
return "boolean";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.STRING)) {
return "String";
} else if (dt == DataType.MATRIX) {
return "org.apache.sysml.api.mlcontext.Matrix";
} else if (dt == DataType.FRAME) {
return "org.apache.sysml.api.mlcontext.Frame";
}
return null;
}
use of org.apache.sysml.parser.Expression.DataType in project systemml by apache.
the class Recompiler method tryReadMetaDataFileMatrixCharacteristics.
private static void tryReadMetaDataFileMatrixCharacteristics(DataOp dop) {
try {
// get meta data filename
String mtdname = DataExpression.getMTDFileName(dop.getFileName());
Path path = new Path(mtdname);
FileSystem fs = IOUtilFunctions.getFileSystem(mtdname);
if (fs.exists(path)) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(fs.open(path)));
JSONObject mtd = JSONHelper.parse(br);
DataType dt = DataType.valueOf(String.valueOf(mtd.get(DataExpression.DATATYPEPARAM)).toUpperCase());
dop.setDataType(dt);
if (dt != DataType.FRAME)
dop.setValueType(ValueType.valueOf(String.valueOf(mtd.get(DataExpression.VALUETYPEPARAM)).toUpperCase()));
dop.setDim1((dt == DataType.MATRIX || dt == DataType.FRAME) ? Long.parseLong(mtd.get(DataExpression.READROWPARAM).toString()) : 0);
dop.setDim2((dt == DataType.MATRIX || dt == DataType.FRAME) ? Long.parseLong(mtd.get(DataExpression.READCOLPARAM).toString()) : 0);
} finally {
IOUtilFunctions.closeSilently(br);
}
}
} catch (Exception ex) {
throw new DMLRuntimeException(ex);
}
}
use of org.apache.sysml.parser.Expression.DataType in project systemml by apache.
the class HopRewriteUtils method createUnary.
public static UnaryOp createUnary(Hop input, OpOp1 type) {
DataType dt = (type == OpOp1.CAST_AS_SCALAR) ? DataType.SCALAR : (type == OpOp1.CAST_AS_MATRIX) ? DataType.MATRIX : input.getDataType();
ValueType vt = (type == OpOp1.CAST_AS_MATRIX) ? ValueType.DOUBLE : input.getValueType();
UnaryOp unary = new UnaryOp(input.getName(), dt, vt, type, input);
unary.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
if (type == OpOp1.CAST_AS_SCALAR || type == OpOp1.CAST_AS_MATRIX) {
int dim = (type == OpOp1.CAST_AS_SCALAR) ? 0 : 1;
int blksz = (type == OpOp1.CAST_AS_SCALAR) ? 0 : ConfigurationManager.getBlocksize();
setOutputParameters(unary, dim, dim, blksz, blksz, -1);
}
copyLineNumbers(input, unary);
unary.refreshSizeInformation();
return unary;
}
use of org.apache.sysml.parser.Expression.DataType in project systemml by apache.
the class InterProceduralAnalysis method extractFunctionCallReturnStatistics.
/**
* Extract return variable statistics from this function into the
* calling program.
*
* @param fstmt The function statement.
* @param fop The function op.
* @param tmpVars Function's map of variables eligible for
* extraction.
* @param callVars Calling program's map of variables.
* @param overwrite Whether or not to overwrite variables in the
* calling program's variable map.
*/
private static void extractFunctionCallReturnStatistics(FunctionStatement fstmt, FunctionOp fop, LocalVariableMap tmpVars, LocalVariableMap callVars, boolean overwrite) {
ArrayList<DataIdentifier> foutputOps = fstmt.getOutputParams();
String[] outputVars = fop.getOutputVariableNames();
String fkey = fop.getFunctionKey();
try {
for (int i = 0; i < foutputOps.size(); i++) {
DataIdentifier di = foutputOps.get(i);
// name in function signature
String fvarname = di.getName();
// name in calling program
String pvarname = outputVars[i];
// output, remove that variable from the calling program's variable map.
if (callVars.keySet().contains(pvarname)) {
DataType fdataType = di.getDataType();
DataType pdataType = callVars.get(pvarname).getDataType();
if (fdataType != pdataType) {
// datatype has changed, and the calling program is reassigning the
// the variable, so remove it from the calling variable map
callVars.remove(pvarname);
}
}
// Update or add to the calling program's variable map.
if (di.getDataType() == DataType.MATRIX && tmpVars.keySet().contains(fvarname)) {
MatrixObject moIn = (MatrixObject) tmpVars.get(fvarname);
if (// not existing so far
!callVars.keySet().contains(pvarname) || overwrite) {
MatrixObject moOut = createOutputMatrix(moIn.getNumRows(), moIn.getNumColumns(), moIn.getNnz());
callVars.put(pvarname, moOut);
} else // already existing: take largest
{
Data dat = callVars.get(pvarname);
if (dat instanceof MatrixObject) {
MatrixObject moOut = (MatrixObject) dat;
MatrixCharacteristics mc = moOut.getMatrixCharacteristics();
if (OptimizerUtils.estimateSizeExactSparsity(mc.getRows(), mc.getCols(), (mc.getNonZeros() > 0) ? OptimizerUtils.getSparsity(mc) : 1.0) < OptimizerUtils.estimateSize(moIn.getNumRows(), moIn.getNumColumns())) {
// update statistics if necessary
mc.setDimension(moIn.getNumRows(), moIn.getNumColumns());
mc.setNonZeros(moIn.getNnz());
}
}
}
}
}
} catch (Exception ex) {
throw new HopsException("Failed to extract output statistics of function " + fkey + ".", ex);
}
}
use of org.apache.sysml.parser.Expression.DataType in project systemml by apache.
the class ProgramConverter method parseDataObject.
/**
* NOTE: MRJobConfiguration cannot be used for the general case because program blocks and
* related symbol tables can be hierarchically structured.
*
* @param in data object as string
* @return array of objects
*/
public static Object[] parseDataObject(String in) {
Object[] ret = new Object[2];
StringTokenizer st = new StringTokenizer(in, DATA_FIELD_DELIM);
String name = st.nextToken();
DataType datatype = DataType.valueOf(st.nextToken());
ValueType valuetype = ValueType.valueOf(st.nextToken());
String valString = st.hasMoreTokens() ? st.nextToken() : "";
Data dat = null;
switch(datatype) {
case SCALAR:
{
switch(valuetype) {
case INT:
dat = new IntObject(Long.parseLong(valString));
break;
case DOUBLE:
dat = new DoubleObject(Double.parseDouble(valString));
break;
case BOOLEAN:
dat = new BooleanObject(Boolean.parseBoolean(valString));
break;
case STRING:
dat = new StringObject(valString);
break;
default:
throw new DMLRuntimeException("Unable to parse valuetype " + valuetype);
}
break;
}
case MATRIX:
{
MatrixObject mo = new MatrixObject(valuetype, valString);
long rows = Long.parseLong(st.nextToken());
long cols = Long.parseLong(st.nextToken());
int brows = Integer.parseInt(st.nextToken());
int bcols = Integer.parseInt(st.nextToken());
long nnz = Long.parseLong(st.nextToken());
InputInfo iin = InputInfo.stringToInputInfo(st.nextToken());
OutputInfo oin = OutputInfo.stringToOutputInfo(st.nextToken());
PartitionFormat partFormat = PartitionFormat.valueOf(st.nextToken());
UpdateType inplace = UpdateType.valueOf(st.nextToken());
MatrixCharacteristics mc = new MatrixCharacteristics(rows, cols, brows, bcols, nnz);
MetaDataFormat md = new MetaDataFormat(mc, oin, iin);
mo.setMetaData(md);
if (partFormat._dpf != PDataPartitionFormat.NONE)
mo.setPartitioned(partFormat._dpf, partFormat._N);
mo.setUpdateType(inplace);
dat = mo;
break;
}
default:
throw new DMLRuntimeException("Unable to parse datatype " + datatype);
}
ret[0] = name;
ret[1] = dat;
return ret;
}
Aggregations