From e84f026630bc71990b35fec36550b49ee8bb368a Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Fri, 20 Mar 2015 10:26:11 +0000 Subject: [PATCH] Fix creation of operator ASTs --- pyop2/base.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pyop2/base.py b/pyop2/base.py index 8e17ebc6d..4acb9a34d 100644 --- a/pyop2/base.py +++ b/pyop2/base.py @@ -1990,10 +1990,10 @@ def _check_shape(self, other): self.dataset.dim, other.dataset.dim) def _op(self, other, op): - ops = {operator.add: '+', - operator.sub: '-', - operator.mul: '*', - operator.div: '/'} + ops = {operator.add: ast.Sum, + operator.sub: ast.Sub, + operator.mul: ast.Prod, + operator.div: ast.Div} ret = _make_object('Dat', self.dataset, None, self.dtype) name = "binop_%s" % op.__name__ if np.isscalar(other): @@ -2006,9 +2006,8 @@ def _op(self, other, op): ast.Decl(self.ctype, ast.Symbol("*ret"))], ast.c_for("n", self.cdim, ast.Assign(ast.Symbol("ret", ("n", )), - ast.BinExpr(ast.Symbol("self", ("n", )), - ast.Symbol("other", ("0", )), - op=ops[op])), + ops[op](ast.Symbol("self", ("n", )), + ast.Symbol("other", ("0", )))), pragma=None)) k = _make_object('Kernel', k, name) @@ -2022,9 +2021,8 @@ def _op(self, other, op): ast.Decl(self.ctype, ast.Symbol("*ret"))], ast.c_for("n", self.cdim, ast.Assign(ast.Symbol("ret", ("n", )), - ast.BinExpr(ast.Symbol("self", ("n", )), - ast.Symbol("other", ("n", )), - op=ops[op])), + ops[op](ast.Symbol("self", ("n", )), + ast.Symbol("other", ("n", )))), pragma=None)) k = _make_object('Kernel', k, name)