use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class HopRewriteUtils method createDataGenOpByVal.
public static Hop createDataGenOpByVal(Hop rowInput, Hop colInput, double value) {
Hop val = new LiteralOp(value);
HashMap<String, Hop> params = new HashMap<>();
params.put(DataExpression.RAND_ROWS, rowInput);
params.put(DataExpression.RAND_COLS, colInput);
params.put(DataExpression.RAND_MIN, val);
params.put(DataExpression.RAND_MAX, val);
params.put(DataExpression.RAND_PDF, new LiteralOp(DataExpression.RAND_PDF_UNIFORM));
params.put(DataExpression.RAND_LAMBDA, new LiteralOp(-1.0));
params.put(DataExpression.RAND_SPARSITY, new LiteralOp(1.0));
params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED));
// note internal refresh size information
Hop datagen = new DataGenOp(DataGenMethod.RAND, new DataIdentifier("tmp"), params);
datagen.setOutputBlocksizes(rowInput.getRowsInBlock(), colInput.getColsInBlock());
copyLineNumbers(rowInput, datagen);
if (value == 0)
datagen.setNnz(0);
return datagen;
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyFunctionProgramBlock.
/**
* This creates a deep copy of a function program block. The central reference to singletons of function program blocks
* poses the need for explicit copies in order to prevent conflicting writes of temporary variables (see ExternalFunctionProgramBlock.
*
* @param namespace function namespace
* @param oldName ?
* @param pid ?
* @param IDPrefix ?
* @param prog runtime program
* @param fnStack ?
* @param fnCreated ?
* @param plain ?
*/
public static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain) {
// fpb guaranteed to be non-null (checked inside getFunctionProgramBlock)
FunctionProgramBlock fpb = prog.getFunctionProgramBlock(namespace, oldName);
String fnameNew = (plain) ? oldName : (oldName + CP_CHILD_THREAD + pid);
String fnameNewKey = DMLProgram.constructFunctionKey(namespace, fnameNew);
if (prog.getFunctionProgramBlocks().containsKey(fnameNewKey))
// prevent redundant deep copy if already existent
return;
// create deep copy
FunctionProgramBlock copy = null;
ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
if (fpb.getInputParams() != null)
tmp1.addAll(fpb.getInputParams());
if (fpb.getOutputParams() != null)
tmp2.addAll(fpb.getOutputParams());
if (fpb instanceof ExternalFunctionProgramBlockCP) {
ExternalFunctionProgramBlockCP efpb = (ExternalFunctionProgramBlockCP) fpb;
HashMap<String, String> tmp3 = efpb.getOtherParams();
if (IDPrefix != -1)
copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
else
copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
} else if (fpb instanceof ExternalFunctionProgramBlock) {
ExternalFunctionProgramBlock efpb = (ExternalFunctionProgramBlock) fpb;
HashMap<String, String> tmp3 = efpb.getOtherParams();
if (IDPrefix != -1)
copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
else
copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
} else {
if (!fnStack.contains(fnameNewKey)) {
fnStack.add(fnameNewKey);
copy = new FunctionProgramBlock(prog, tmp1, tmp2);
copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, fpb.isRecompileOnce()));
copy.setRecompileOnce(fpb.isRecompileOnce());
copy.setThreadID(pid);
fnStack.remove(fnameNewKey);
} else
// stop deep copy for recursive function calls
copy = fpb;
}
// copy.setVariables( (LocalVariableMap) fpb.getVariables() ); //implicit cloning
// note: instructions not used by function program block
// put
prog.addFunctionProgramBlock(namespace, fnameNew, copy);
fnCreated.add(DMLProgram.constructFunctionKey(namespace, fnameNew));
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitParForStatement.
@Override
public void exitParForStatement(ParForStatementContext ctx) {
ParForStatement parForStmt = new ParForStatement();
DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
HashMap<String, String> parForParamValues = new HashMap<>();
if (ctx.parForParams != null && ctx.parForParams.size() > 0) {
for (StrictParameterizedExpressionContext parForParamCtx : ctx.parForParams) {
String paramVal = parForParamCtx.paramVal.getText();
if (argVals.containsKey(paramVal))
paramVal = argVals.get(paramVal);
parForParamValues.put(parForParamCtx.paramName.getText(), paramVal);
}
}
// 1/-1
Expression incrementExpr = null;
if (ctx.iterPred.info.increment != null) {
incrementExpr = ctx.iterPred.info.increment;
}
IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile);
parForStmt.setPredicate(predicate);
if (ctx.body.size() > 0) {
for (StatementContext stmtCtx : ctx.body) {
parForStmt.addStatementBlock(getStatementBlock(stmtCtx.info.stmt));
}
parForStmt.mergeStatementBlocks();
}
ctx.info.stmt = parForStmt;
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method getFunctionParameters.
private ArrayList<DataIdentifier> getFunctionParameters(List<TypedArgNoAssignContext> ctx) {
ArrayList<DataIdentifier> retVal = new ArrayList<>();
for (TypedArgNoAssignContext paramCtx : ctx) {
DataIdentifier dataId = new DataIdentifier(paramCtx.paramName.getText());
String dataType = null;
String valueType = null;
if (paramCtx.paramType == null || paramCtx.paramType.dataType() == null || paramCtx.paramType.dataType().getText() == null || paramCtx.paramType.dataType().getText().isEmpty()) {
dataType = "scalar";
} else {
dataType = paramCtx.paramType.dataType().getText();
}
// check and assign data type
checkValidDataType(dataType, paramCtx.start);
if (dataType.equalsIgnoreCase("matrix"))
dataId.setDataType(DataType.MATRIX);
else if (dataType.equalsIgnoreCase("frame"))
dataId.setDataType(DataType.FRAME);
else if (dataType.equalsIgnoreCase("scalar"))
dataId.setDataType(DataType.SCALAR);
valueType = paramCtx.paramType.valueType().getText();
if (valueType.equals("int") || valueType.equals("integer") || valueType.equals("Int") || valueType.equals("Integer")) {
dataId.setValueType(ValueType.INT);
} else if (valueType.equals("string") || valueType.equals("String")) {
dataId.setValueType(ValueType.STRING);
} else if (valueType.equals("boolean") || valueType.equals("Boolean")) {
dataId.setValueType(ValueType.BOOLEAN);
} else if (valueType.equals("double") || valueType.equals("Double")) {
dataId.setValueType(ValueType.DOUBLE);
} else if (valueType.equals("bool")) {
notifyErrorListeners("invalid valuetype " + valueType + " (Quickfix: use \'boolean\' instead)", paramCtx.start);
return null;
} else {
notifyErrorListeners("invalid valuetype " + valueType, paramCtx.start);
return null;
}
retVal.add(dataId);
}
return retVal;
}
use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitInternalFunctionDefExpression.
// -----------------------------------------------------------------
// Internal & External Functions Definitions
// -----------------------------------------------------------------
@Override
public void exitInternalFunctionDefExpression(InternalFunctionDefExpressionContext ctx) {
FunctionStatement functionStmt = new FunctionStatement();
ArrayList<DataIdentifier> functionInputs = getFunctionParameters(ctx.inputParams);
functionStmt.setInputParams(functionInputs);
// set function outputs
ArrayList<DataIdentifier> functionOutputs = getFunctionParameters(ctx.outputParams);
functionStmt.setOutputParams(functionOutputs);
// set function name
functionStmt.setName(ctx.name.getText());
if (ctx.body.size() > 0) {
// handle function body
// Create arraylist of one statement block
ArrayList<StatementBlock> body = new ArrayList<>();
for (StatementContext stmtCtx : ctx.body) {
body.add(getStatementBlock(stmtCtx.info.stmt));
}
functionStmt.setBody(body);
functionStmt.mergeStatementBlocks();
} else {
notifyErrorListeners("functions with no statements are not allowed", ctx.start);
return;
}
ctx.info.stmt = functionStmt;
setFileLineColumn(ctx.info.stmt, ctx);
ctx.info.functionName = ctx.name.getText();
}
Aggregations