inducer / pymbolic

A simple package to do symbolic math (focus on code gen and DSLs)
http://mathema.tician.de/software/pymbolic
Other
106 stars 24 forks source link

Pymbolic to SymEngine conversion error when using FloorDiv. #130

Closed Ravindu-Hirimuthugoda closed 1 year ago

Ravindu-Hirimuthugoda commented 1 year ago

There was an error encountered while attempting to convert a Pymbolic floor division expression to a SymEngine expression.

import pymbolic.interop.symengine as mapper
import pymbolic.primitives as pr

a = pr.FloorDiv(pr.Sum((pr.Variable('x'),63)),64)
map = mapper.PymbolicToSymEngineMapper()
res = map(a)
print("res: ",res)
print(type(res))

Error:

return self.rec(expr.numerator) // self.rec(expr.denominator)
TypeError: unsupported operand type(s) for //: 'Add' and 'Integer'
inducer commented 1 year ago

I'd say this is a symengine issue. Are you sure that Symengine supports floordiv? @isuruf might know this off the top of his head.

Ravindu-Hirimuthugoda commented 1 year ago

Yes floordiv can be used in Symengine.

By adding following code in the pymbolic/interop/common.py under PymbolicToSympyLikeMapper class might be a fix.

def map_floor_div(self, expr):
        return self.sym.floor(self.rec(expr.numerator) / self.rec(expr.denominator))
inducer commented 1 year ago

I'd be happy to look at a PR. Make sure to include a test.

Ravindu-Hirimuthugoda commented 1 year ago

Sure. I'll do

isuruf commented 1 year ago

https://github.com/symengine/symengine.py/pull/441 should fix the // operator for symengine

Ravindu-Hirimuthugoda commented 1 year ago

Thanks!