finch-tensor / finch-tensor-python

Sparse and Structured Tensor Programming in Python
MIT License
8 stars 3 forks source link

Discrepancy in `%` operator #52

Closed mtsokol closed 5 months ago

mtsokol commented 5 months ago

I think that we still could match Python behavior in terms of % operator and negative input. Array API standard describes several edge cases, and also says:

In the remaining cases, the result must match that of the Python % operator.

And I think negative input falls into that rule. Therefore we could take a look at these differences:

Python

In [113]: 2 % 10
Out[113]: 2

In [114]: -2 % 10
Out[114]: 8

In [115]: -2 % -10
Out[115]: -2

In [116]: 2 % -10
Out[116]: -8

Julia

julia> 2 % 10
2

julia> -2 % 10
-2

julia> -2 % -10
-2

julia> 2 % -10
2
willow-ahrens commented 5 months ago

did we just mix up mod and rem ?

julia> rem(-2, 10)
-2

julia> mod(-2, 10)
8

julia> mod(2, 10)
2

julia> rem(2, 10)
2

julia> mod(2, -10)
-8

julia> mod(-2, -10)
-2
willow-ahrens commented 5 months ago

I think we just need to add mod_nothrow

willow-ahrens commented 5 months ago

fixed in https://github.com/willow-ahrens/finch-tensor/pull/56