Search in sources :

Example 1 with BinaryExpression

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);
    }
}
Also used : DoubleIdentifier(org.apache.sysml.parser.DoubleIdentifier) BinaryExpression(org.apache.sysml.parser.BinaryExpression) IntIdentifier(org.apache.sysml.parser.IntIdentifier) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression) Token(org.antlr.v4.runtime.Token)

Example 2 with BinaryExpression

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);
    }
}
Also used : BinaryExpression(org.apache.sysml.parser.BinaryExpression) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression)

Example 3 with BinaryExpression

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;
}
Also used : BinaryExpression(org.apache.sysml.parser.BinaryExpression) DoubleIdentifier(org.apache.sysml.parser.DoubleIdentifier) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression)

Example 4 with BinaryExpression

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;
}
Also used : BinaryExpression(org.apache.sysml.parser.BinaryExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression)

Aggregations

BinaryExpression (org.apache.sysml.parser.BinaryExpression)4 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)4 Expression (org.apache.sysml.parser.Expression)4 ParameterExpression (org.apache.sysml.parser.ParameterExpression)4 BooleanExpression (org.apache.sysml.parser.BooleanExpression)2 DataExpression (org.apache.sysml.parser.DataExpression)2 DoubleIdentifier (org.apache.sysml.parser.DoubleIdentifier)2 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)2 RelationalExpression (org.apache.sysml.parser.RelationalExpression)2 Token (org.antlr.v4.runtime.Token)1 IntIdentifier (org.apache.sysml.parser.IntIdentifier)1