-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StringifyMapper: Incorrect result for side-by-side product nodes #68
Comments
Pymbolic flattens those, assuming that multiplication is associative. ( |
The AST is correct (i.e. unflattened) but I think the >>> a * (b * c)
Product((Variable('a'), Product((Variable('b'), Variable('c')))))
No, no concrete use case. |
Well given floating point arithmetic is not associative we can always buggy behavior associated with this in a generated code ;). |
Grr, you're right. We should probably turn off auto-flattening. #69 For the |
I think its unsafe to stringify to incorrect schedules and should be avoided.
Yep, but the default should prefer correctness. |
OK, I can live with that. |
I think it is not just StringifyMapper that is wrong, even the parser implements left-to-right associativity incorrectly: >>> parse("a*b*c")
Product((Variable('a'), Product((Variable('b'), Variable('c')))))
>>> from pymbolic.mapper.evaluator import evaluate
>>> a_np = np.float64(1/3)
>>> b_np = np.finfo("float64").max
>>> c_np = np.float64(2)
>>> a_np * b_np * c_np
1.1984620899082103e+308
>>> evaluate(parse("a*b*c"), {"a": a_np, "b": b_np, "c": c_np})
/home/line/.local/lib/python3.10/site-packages/pytools/__init__.py:1103: RuntimeWarning: overflow encountered in double_scalars
return reduce(mul, iterable, 1)
inf
|
The text was updated successfully, but these errors were encountered: