[To Discuss] Python floor division and modulo lower to C semantics - #2537
[To Discuss] Python floor division and modulo lower to C semantics#2537ThrudPrimrose wants to merge 2 commits into
Conversation
Both rounded toward zero rather than toward negative infinity, so -32 // 7 gave -4 and -32 % 7 gave -4 where NumPy gives -5 and 3, and % on a float operand did not compile at all. int_floor_ni also reached for host-only std::div, which nvcc removes from device code along with the branch holding it.
|
Two points for the discussion, neither of them fixed here. Division by zero still diverges from NumPy. NumPy answers
The table in the new test is 64 operand pairs per dtype over |
The goldens still spell FloorDiv as ifloor(a / b), the form this branch replaced because integer division has already truncated by the time the floor runs. Same two expressions, now py_floor.
|
As per the discussion, let's add a few sympy functions:
have them lower to sympy.Mod in the cases that it can be evaluated at compile time Also, modify the docs so that in dace, tasklet code is translated to C Modulo semantics, memlets and symbolic expressions in maps/ISedges/... follow SymPy Modulo semantics, and each respective frontend adds their own (PyMod, etc.). |
//and%in a tasklet lowered to C's truncating division, so-32 // 7gave-4and-32 % 7gave-4where Python and NumPy give-5and3, and%on a float operand did not compile at all. Routing both topy_floor/py_modfixes that, andint_floor_nidropsstd::divin the same change because nvcc removes a host-only call -- and the guarded region containing it -- from device code.