use of org.apache.sysml.parser.common.ExpressionInfo in project incubator-systemml by apache.
the class PydmlSyntacticValidator method exitBuiltinFunctionExpression.
@Override
public void exitBuiltinFunctionExpression(BuiltinFunctionExpressionContext ctx) {
// Double verification: verify passed function name is a (non-parameterized) built-in function.
String[] names = getQualifiedNames(ctx.name.getText());
if (names == null) {
notifyErrorListeners("incorrect function name (only namespace " + namespaceResolutionOp() + " functionName allowed. Hint: If you are trying to use builtin functions, you can skip the namespace)", ctx.name);
return;
}
String namespace = names[0];
String functionName = names[1];
ArrayList<ParameterExpression> paramExpression = getParameterExpressionList(ctx.paramExprs);
castAsScalarDeprecationCheck(functionName, ctx);
ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, ctx.name);
if (convertedSyntax == null) {
return;
} else {
functionName = convertedSyntax.functionName;
paramExpression = convertedSyntax.paramExpression;
}
final ExpressionInfo info = ctx.info;
Action f = new Action() {
@Override
public void execute(Expression e) {
info.expr = e;
}
};
boolean validBIF = buildForBuiltInFunction(ctx, functionName, paramExpression, f);
if (validBIF)
return;
notifyErrorListeners("only builtin functions allowed as part of expression", ctx.start);
}
use of org.apache.sysml.parser.common.ExpressionInfo in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitIndexedExpression.
/**
* DML uses 1-based indexing.;
*
* @param ctx the parse tree
*/
@Override
public void exitIndexedExpression(IndexedExpressionContext ctx) {
boolean isRowLower = (ctx.rowLower != null && !ctx.rowLower.isEmpty() && (ctx.rowLower.info.expr != null));
boolean isRowUpper = (ctx.rowUpper != null && !ctx.rowUpper.isEmpty() && (ctx.rowUpper.info.expr != null));
boolean isColLower = (ctx.colLower != null && !ctx.colLower.isEmpty() && (ctx.colLower.info.expr != null));
boolean isColUpper = (ctx.colUpper != null && !ctx.colUpper.isEmpty() && (ctx.colUpper.info.expr != null));
ExpressionInfo rowLower = isRowLower ? ctx.rowLower.info : null;
ExpressionInfo rowUpper = isRowUpper ? ctx.rowUpper.info : null;
ExpressionInfo colLower = isColLower ? ctx.colLower.info : null;
ExpressionInfo colUpper = isColUpper ? ctx.colUpper.info : null;
ctx.dataInfo.expr = new IndexedIdentifier(ctx.name.getText(), false, false);
setFileLineColumn(ctx.dataInfo.expr, ctx);
try {
ArrayList<ArrayList<Expression>> exprList = new ArrayList<>();
ArrayList<Expression> rowIndices = new ArrayList<>();
ArrayList<Expression> colIndices = new ArrayList<>();
if (!isRowLower && !isRowUpper) {
// both not set
rowIndices.add(null);
rowIndices.add(null);
} else if (isRowLower && isRowUpper) {
// both set
rowIndices.add(rowLower.expr);
rowIndices.add(rowUpper.expr);
} else if (isRowLower && !isRowUpper) {
// only row set
rowIndices.add(rowLower.expr);
} else {
notifyErrorListeners("incorrect index expression for row", ctx.start);
return;
}
if (!isColLower && !isColUpper) {
// both not set
colIndices.add(null);
colIndices.add(null);
} else if (isColLower && isColUpper) {
colIndices.add(colLower.expr);
colIndices.add(colUpper.expr);
} else if (isColLower && !isColUpper) {
colIndices.add(colLower.expr);
} else {
notifyErrorListeners("incorrect index expression for column", ctx.start);
return;
}
exprList.add(rowIndices);
exprList.add(colIndices);
((IndexedIdentifier) ctx.dataInfo.expr).setIndices(exprList);
} catch (Exception e) {
notifyErrorListeners("cannot set the indices", ctx.start);
return;
}
}
use of org.apache.sysml.parser.common.ExpressionInfo in project systemml by apache.
the class DmlSyntacticValidator method exitIndexedExpression.
/**
* DML uses 1-based indexing.;
*
* @param ctx the parse tree
*/
@Override
public void exitIndexedExpression(IndexedExpressionContext ctx) {
boolean isRowLower = (ctx.rowLower != null && !ctx.rowLower.isEmpty() && (ctx.rowLower.info.expr != null));
boolean isRowUpper = (ctx.rowUpper != null && !ctx.rowUpper.isEmpty() && (ctx.rowUpper.info.expr != null));
boolean isColLower = (ctx.colLower != null && !ctx.colLower.isEmpty() && (ctx.colLower.info.expr != null));
boolean isColUpper = (ctx.colUpper != null && !ctx.colUpper.isEmpty() && (ctx.colUpper.info.expr != null));
ExpressionInfo rowLower = isRowLower ? ctx.rowLower.info : null;
ExpressionInfo rowUpper = isRowUpper ? ctx.rowUpper.info : null;
ExpressionInfo colLower = isColLower ? ctx.colLower.info : null;
ExpressionInfo colUpper = isColUpper ? ctx.colUpper.info : null;
ctx.dataInfo.expr = new IndexedIdentifier(ctx.name.getText(), false, false);
setFileLineColumn(ctx.dataInfo.expr, ctx);
try {
ArrayList<ArrayList<Expression>> exprList = new ArrayList<>();
ArrayList<Expression> rowIndices = new ArrayList<>();
ArrayList<Expression> colIndices = new ArrayList<>();
if (!isRowLower && !isRowUpper) {
// both not set
rowIndices.add(null);
rowIndices.add(null);
} else if (isRowLower && isRowUpper) {
// both set
rowIndices.add(rowLower.expr);
rowIndices.add(rowUpper.expr);
} else if (isRowLower && !isRowUpper) {
// only row set
rowIndices.add(rowLower.expr);
} else {
notifyErrorListeners("incorrect index expression for row", ctx.start);
return;
}
if (!isColLower && !isColUpper) {
// both not set
colIndices.add(null);
colIndices.add(null);
} else if (isColLower && isColUpper) {
colIndices.add(colLower.expr);
colIndices.add(colUpper.expr);
} else if (isColLower && !isColUpper) {
colIndices.add(colLower.expr);
} else {
notifyErrorListeners("incorrect index expression for column", ctx.start);
return;
}
exprList.add(rowIndices);
exprList.add(colIndices);
((IndexedIdentifier) ctx.dataInfo.expr).setIndices(exprList);
} catch (Exception e) {
notifyErrorListeners("cannot set the indices", ctx.start);
return;
}
}
use of org.apache.sysml.parser.common.ExpressionInfo in project incubator-systemml by apache.
the class DmlSyntacticValidator method exitBuiltinFunctionExpression.
@Override
public void exitBuiltinFunctionExpression(BuiltinFunctionExpressionContext ctx) {
// Double verification: verify passed function name is a (non-parameterized) built-in function.
String[] names = getQualifiedNames(ctx.name.getText());
if (names == null) {
notifyErrorListeners("incorrect function name (only namespace " + namespaceResolutionOp() + " functionName allowed. Hint: If you are trying to use builtin functions, you can skip the namespace)", ctx.name);
return;
}
String namespace = names[0];
String functionName = names[1];
ArrayList<ParameterExpression> paramExpression = getParameterExpressionList(ctx.paramExprs);
castAsScalarDeprecationCheck(functionName, ctx);
ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, ctx.name);
if (convertedSyntax == null) {
return;
} else {
functionName = convertedSyntax.functionName;
paramExpression = convertedSyntax.paramExpression;
}
final ExpressionInfo info = ctx.info;
Action f = new Action() {
@Override
public void execute(Expression e) {
info.expr = e;
}
};
boolean validBIF = buildForBuiltInFunction(ctx, functionName, paramExpression, f);
if (validBIF)
return;
notifyErrorListeners("only builtin functions allowed as part of expression", ctx.start);
}
use of org.apache.sysml.parser.common.ExpressionInfo in project incubator-systemml by apache.
the class PydmlSyntacticValidator method exitIndexedExpression.
/**
* PyDML uses 0-based indexing, so we increment lower indices by 1
* when translating to DML.
*
* @param ctx the parse tree
*/
@Override
public void exitIndexedExpression(IndexedExpressionContext ctx) {
boolean isRowLower = (ctx.rowLower != null && !ctx.rowLower.isEmpty() && (ctx.rowLower.info.expr != null));
boolean isRowUpper = (ctx.rowUpper != null && !ctx.rowUpper.isEmpty() && (ctx.rowUpper.info.expr != null));
boolean isColLower = (ctx.colLower != null && !ctx.colLower.isEmpty() && (ctx.colLower.info.expr != null));
boolean isColUpper = (ctx.colUpper != null && !ctx.colUpper.isEmpty() && (ctx.colUpper.info.expr != null));
boolean isRowSliceImplicit = ctx.rowImplicitSlice != null;
boolean isColSliceImplicit = ctx.colImplicitSlice != null;
ExpressionInfo rowLower = isRowLower ? ctx.rowLower.info : null;
ExpressionInfo rowUpper = isRowUpper ? ctx.rowUpper.info : null;
ExpressionInfo colLower = isColLower ? ctx.colLower.info : null;
ExpressionInfo colUpper = isColUpper ? ctx.colUpper.info : null;
ctx.dataInfo.expr = new IndexedIdentifier(ctx.name.getText(), false, false);
setFileLineColumn(ctx.dataInfo.expr, ctx);
try {
ArrayList<ArrayList<Expression>> exprList = new ArrayList<>();
ArrayList<Expression> rowIndices = new ArrayList<>();
ArrayList<Expression> colIndices = new ArrayList<>();
if (!isRowLower && !isRowUpper) {
// both not set
rowIndices.add(null);
rowIndices.add(null);
} else if (isRowLower && isRowUpper) {
// both set
rowIndices.add(incrementByOne(rowLower.expr, ctx));
rowIndices.add(rowUpper.expr);
} else if (isRowLower && !isRowUpper) {
// Add given lower bound
rowIndices.add(incrementByOne(rowLower.expr, ctx));
if (isRowSliceImplicit) {
// Add expression for nrow(X) for implicit upper bound
Expression.BuiltinFunctionOp bop = Expression.BuiltinFunctionOp.NROW;
DataIdentifier x = new DataIdentifier(ctx.name.getText());
Expression expr = new BuiltinFunctionExpression(ctx, bop, new Expression[] { x }, currentFile);
rowIndices.add(expr);
}
} else if (!isRowLower && isRowUpper && isRowSliceImplicit) {
// Add expression for `1` for implicit lower bound
// Note: We go ahead and increment by 1 to convert from 0-based to 1-based indexing
IntIdentifier one = new IntIdentifier(ctx, 1, currentFile);
rowIndices.add(one);
// Add given upper bound
rowIndices.add(rowUpper.expr);
} else {
notifyErrorListeners("incorrect index expression for row", ctx.start);
return;
}
if (!isColLower && !isColUpper) {
// both not set
colIndices.add(null);
colIndices.add(null);
} else if (isColLower && isColUpper) {
colIndices.add(incrementByOne(colLower.expr, ctx));
colIndices.add(colUpper.expr);
} else if (isColLower && !isColUpper) {
// Add given lower bound
colIndices.add(incrementByOne(colLower.expr, ctx));
if (isColSliceImplicit) {
// Add expression for ncol(X) for implicit upper bound
Expression.BuiltinFunctionOp bop = Expression.BuiltinFunctionOp.NCOL;
DataIdentifier x = new DataIdentifier(ctx.name.getText());
Expression expr = new BuiltinFunctionExpression(ctx, bop, new Expression[] { x }, currentFile);
colIndices.add(expr);
}
} else if (!isColLower && isColUpper && isColSliceImplicit) {
// Add expression for `1` for implicit lower bound
// Note: We go ahead and increment by 1 to convert from 0-based to 1-based indexing
IntIdentifier one = new IntIdentifier(ctx, 1, currentFile);
colIndices.add(one);
// Add given upper bound
colIndices.add(colUpper.expr);
} else {
notifyErrorListeners("incorrect index expression for column", ctx.start);
return;
}
exprList.add(rowIndices);
exprList.add(colIndices);
((IndexedIdentifier) ctx.dataInfo.expr).setIndices(exprList);
} catch (Exception e) {
notifyErrorListeners("cannot set the indices", ctx.start);
return;
}
}
Aggregations