You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The spec should be updated first. The test suite should be easy to update. We already have similar code for the bitwise shift operators, which only accept nonnegative values for the second argument.
I disagree with that. The spec should specify what range of inputs are required for a specific function. If this confused you, it will confuse other people too.
@asmeurer Not clear to me how you think the specification should be changed. Are you looking for a note that saying zero-division behavior is undefined (i.e., library-specific)?
Yes, just a note is what I'm expecting. For the test suite I am completely skipping testing zero inputs for x2 for floor_divide and remainder(). The spec says "Rounds the result of dividing each element x1_i of the input array x1 by the respective element x2_i of the input array x2 ..." which is meaningless if x2_i is 0 and x2 has an integer dtype.
So, I think we have a choice here in what behavior the specification requires. We can either opt for the more consistent behavior (namely, np.inf//1.0 gives inf, rather than nan in order to be consistent with xp.floor(xp.divide(inf, 1.0)), or side with prior art (i.e., NumPy).
I've opened #329 to add explicit guidance for floor_divide. Note that this guidance diverges from NumPy's behavior and aligns with TensorFlow's behavior as documented above.
Activity
rgommers commentedon Jun 12, 2021
The numpy code does give:
There's an issue about it here: numpy/numpy#5150
I don't think this should be specified in the array API spec, it falls under the warnings/exceptions behavior which is library-specific.
rgommers commentedon Jun 12, 2021
And for the record: there's something to say for either option, but I personally prefer the PyTorch behavior.
pmeier commentedon Jun 14, 2021
@asmeurer In that case, we need to exclude it as second input for these functions in the test suite.
asmeurer commentedon Jun 14, 2021
The spec should be updated first. The test suite should be easy to update. We already have similar code for the bitwise shift operators, which only accept nonnegative values for the second argument.
pmeier commentedon Jun 15, 2021
@asmeurer From #199 (comment)
Thus, I think we can go ahead and adapt the test suite.
asmeurer commentedon Jun 15, 2021
I disagree with that. The spec should specify what range of inputs are required for a specific function. If this confused you, it will confuse other people too.
kgryte commentedon Jun 15, 2021
@asmeurer Not clear to me how you think the specification should be changed. Are you looking for a note that saying zero-division behavior is undefined (i.e., library-specific)?
asmeurer commentedon Aug 31, 2021
Yes, just a note is what I'm expecting. For the test suite I am completely skipping testing zero inputs for x2 for floor_divide and remainder(). The spec says "Rounds the result of dividing each element
x1_iof the input arrayx1by the respective elementx2_iof the input arrayx2..." which is meaningless if x2_i is 0 and x2 has an integer dtype.asmeurer commentedon Aug 31, 2021
Perhaps this should be a separate issue, but I also noticed that floor(x) isn't properly specified for infinities.
asmeurer commentedon Aug 31, 2021
I guess floor_divide should also be specified when the result of x1/x2 is an infinity.
NumPy has this behavior on floats
Presumably it is supposed to work this way, although I find it a little surprising that floor_divide(x, y) != floor(divide(x, y)) in this case.
arogozhnikov commentedon Oct 2, 2021
I believe that same question can arise with log/arcsin/arccos, though it is more common to just return nan there
kgryte commentedon Nov 9, 2021
@asmeurer Re:
floor_divideand infinities. NumPy's behavior matches Python behavior:However, NumPy differs from Python in supporting rounding infinities...
So, I think we have a choice here in what behavior the specification requires. We can either opt for the more consistent behavior (namely,
np.inf//1.0givesinf, rather thannanin order to be consistent withxp.floor(xp.divide(inf, 1.0)), or side with prior art (i.e., NumPy).Perhaps you have additional thoughts?
kgryte commentedon Nov 9, 2021
FWIW, TensorFlow diverges from NumPy behavior here:
kgryte commentedon Nov 9, 2021
Further updates, NumPy's
floor_dividehas additional weird behavior:while TensorFlow does something more sane
kgryte commentedon Nov 9, 2021
I've opened #329 to add explicit guidance for
floor_divide. Note that this guidance diverges from NumPy's behavior and aligns with TensorFlow's behavior as documented above.