use of org.apache.sysml.parser.BinaryExpression in project incubator-systemml by apache.
the class CommonSyntacticValidator method unaryExpressionHelper.
protected void unaryExpressionHelper(ParserRuleContext ctx, ExpressionInfo left, ExpressionInfo me, String op) {
if (left.expr != null) {
Token start = ctx.start;
String fileName = currentFile;
int line = start.getLine();
int col = start.getCharPositionInLine();
if (left.expr instanceof IntIdentifier) {
if (op.equals("-")) {
((IntIdentifier) left.expr).multiplyByMinusOne();
}
me.expr = left.expr;
} else if (left.expr instanceof DoubleIdentifier) {
if (op.equals("-")) {
((DoubleIdentifier) left.expr).multiplyByMinusOne();
}
me.expr = left.expr;
} else {
Expression right = new IntIdentifier(1, fileName, line, col, line, col);
if (op.equals("-")) {
right = new IntIdentifier(-1, fileName, line, col, line, col);
}
Expression.BinaryOp bop = Expression.getBinaryOp("*");
BinaryExpression be = new BinaryExpression(bop);
be.setLeft(left.expr);
be.setRight(right);
me.expr = be;
}
setFileLineColumn(me.expr, ctx);
}
}
use of org.apache.sysml.parser.BinaryExpression in project incubator-systemml by apache.
the class CommonSyntacticValidator method binaryExpressionHelper.
// --------------------------------------------------------------------
// HELPER METHODS FOR OVERRIDDEN VISITOR FUNCTIONS
// --------------------------------------------------------------------
protected void binaryExpressionHelper(ParserRuleContext ctx, ExpressionInfo left, ExpressionInfo right, ExpressionInfo me, String op) {
if (left.expr != null && right.expr != null) {
Expression.BinaryOp bop = Expression.getBinaryOp(op);
BinaryExpression be = new BinaryExpression(bop);
be = new BinaryExpression(bop);
be.setLeft(left.expr);
be.setRight(right.expr);
me.expr = be;
setFileLineColumn(me.expr, ctx);
}
}
use of org.apache.sysml.parser.BinaryExpression in project incubator-systemml by apache.
the class PydmlSyntacticValidator method incrementByOne.
/**
* Increment lower indices by 1 when translating from PyDML
* (0-based indexing) to DML (1-based indexing).
*
* @param expr expression
* @param ctx antlr rule context
* @return expression
*/
private Expression incrementByOne(Expression expr, ParserRuleContext ctx) {
// Addition and subtraction operator same as DML
Expression.BinaryOp bop = Expression.getBinaryOp("+");
Expression retVal = new BinaryExpression(bop);
((BinaryExpression) retVal).setLeft(expr);
int line = ctx.start.getLine();
int col = ctx.start.getCharPositionInLine();
((BinaryExpression) retVal).setRight(new DoubleIdentifier(1.0, currentFile, line, col, line, col));
setFileLineColumn(retVal, ctx);
return retVal;
}
use of org.apache.sysml.parser.BinaryExpression in project incubator-systemml by apache.
the class PydmlSyntacticValidator method handleLanguageSpecificFunction.
/**
* For Pydml, matrix multiply is invoked using dot (A, B). This is taken from numpy.dot
* For Dml, it is invoked using "%*%". The dot function call in pydml is converted to a
* {@link BinaryExpression} equivalent to what is done in
* DmlSyntacticValidator's exitMatrixMulExpression(MatrixMulExpressionContext).
*/
@Override
protected Expression handleLanguageSpecificFunction(ParserRuleContext ctx, String functionName, ArrayList<ParameterExpression> paramExpression) {
if (functionName.equals("dot") && paramExpression.size() == 2) {
Expression.BinaryOp bop = Expression.getBinaryOp("%*%");
Expression expr = new BinaryExpression(bop);
((BinaryExpression) expr).setLeft(paramExpression.get(0).getExpr());
((BinaryExpression) expr).setRight(paramExpression.get(1).getExpr());
return expr;
}
return null;
}
Aggregations