-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
ENH: Add the C99 remainder function, as np.remainder_ieee
#9963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good; just seems there are a few statements left in from testing.
I wish there was a way to change the meaning of the name, especially since we already have np.mod
which is just the same thing as the current np.remainder
. But the only way I can think of doing that is to add an argument to np.remainder
, which could warn upon the "wrong" setting; this seems non-trivial for a ufunc.
will be computed exactly, with no rounding error | ||
introduced. | ||
*/ | ||
assert(m == c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left-over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't hurt and might turn up potential problems. This comes from the Python implementation.
if (npy_isfinite(x)) { | ||
return NPY_NAN; | ||
} | ||
assert(npy_isfinite(y)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left-over from testing?
|
f35f198
to
3a5a475
Compare
I muddled isfinite and isinfinite there - fixed now. Is there a reason we have no EDIT: I am dumb, |
I'm not a big fan of the name, nor of many almost identical but separate functions. Have you considered any alternatives, like |
@rgommers Maybe |
I suppose the function could be put somewhere else with a |
An argument for the current name - it matches |
@charris - I wondered about turning |
I'd also like to see the argument for adding this in the first place. The differences with
Two differences; this implementation gives back floats rather than ints for int input, and the second one changes 3 to -1 in output. Unless I'm missing something major, that's a fairly marginal change. |
This is an omission and not a feature.
This is as marginal a change as So yes, there would be a good argument here for |
Doesn't mean that it would need to be public though.
Hmm... we want to choose nice functional names, not match other languages. And of those others, Java is very low on the recognition scale so not very relevant. |
However, we also don't want to mismatch other languages, which is the problem
It needs to be visible to I suppose we could move the functions to:
|
Not quite I think. |
Does that opinion also stand against I suppose this is similar to #9696, in that python adding things to |
Adding as an extra method inside |
Unfortunately adding the extra method is a lot of work without breaking compatibility of Would you be happier with |
Better, but doesn't make much of a difference to my opinion. If we're bikeshedding names, I don't think something like |
@rgommers I don't see the difficulty here. I think we need the function for completeness, both for Python compatibility and because is has greater precision on the near negative side of zero, which is where it is useful due to the distribution of floating point numbers. The main question is how to name it so that it does not collide with our long time EDIT: It would have been nice if the Python folks had been more cognizant of the NumPy tradition here, but it is too late to change that. |
Hmm, I suppose EDIT: Although there would still be a name collision, which might get worse if ufuncs and multiarray get combined somewhere down the line. |
@charris - I'd personally like turning In any case, I think we should have the specific ufunc and might then as well expose it. |
Another option is to let folks roll their own, |
I do think we should have this as a |
It sounds like |
Implementation stolen from cpython 3.7
3a5a475
to
3915399
Compare
It's simple math to me:
Completeness is in the eye of the beholder. This is nothing like rounding, where we clearly do need the two behaviors for rounding .5. |
np.remainder_ieee
@@ -1268,6 +1268,25 @@ def test_heaviside(self): | |||
assert_equal(h, expected1.astype(np.float32)) | |||
|
|||
|
|||
class TestIeeeRemainder(object): | |||
def test_remainder_ieee(self): | |||
# Testing is basic because implementation is copied from cpython, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to test the different float types, no?
@@ -1268,6 +1268,25 @@ def test_heaviside(self): | |||
assert_equal(h, expected1.astype(np.float32)) | |||
|
|||
|
|||
class TestIeeeRemainder(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rename?
I think we should support most C99 functions because if someone wants to generalize a C, or even a Python 3.7+ program, to use ndarrays, then they may need the function. I do think this needs more tests. |
Ideally we'd copy the python3 tests there, but to do so we need to implement #9969. |
@mhvk is there a way to remove your "review approval" from this PR? The idea seems still controversial |
On request of @mattip, since the idea itself still seemed controversial
@mattip - I dismissed my own review. |
Needs #13375 to port the tests too |
Now that C99 is a requirement, I'm inclined to remove the manual implementation, which also removes the need for detailed testing. |
Implementation stolen from cpython 3.7.
As suggested in a comment in #9702.