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
Add support for np.asarray_chkfinite [WIP] [need help] #6279
Add support for np.asarray_chkfinite [WIP] [need help] #6279
Conversation
@rishabhvarshney14 thanks for submitting this and thank you for your efforts to help to improve Numba! Before we begin to review the code, there are a few flake8 related issues that need to be addressed, as indicated by the failing coverage test on Azure pipelines:
Additionally, it seems like you accidentally committed a file called |
@rishabhvarshney14 thanks for updating this. It is looking. much better already, but there are still a number of flake8 issues as reported by Azure pipelines.
|
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.
Thank you again for your submission! It looks quite good now. I left a few suggestions about algorithmic efficiency and Numpy behavioral coherence that will need to be addressed.
So, I wrote the following benchmark script:
And then I benchmarked them like so:
And
And
So, in conclusion:
From what I can tell, these observations match your findings too, right @rishabhvarshney14 ? |
Yes. I have changed the |
@rishabhvarshney14 excellent, thank you very much. And thank you for being persistent and willing to measure what the best implementation is. I think this PR is now in great shape. The only item left on my list that needs to be attended to is the Beyond that, since I was involved in suggesting some code for this, I would like to request that either @sklam, @stuartarchibald or @gmarkall take a look at this too and sign it off, thanks! |
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.
Since only the first two arguments are supported for np.asarray
(https://numba.readthedocs.io/en/stable/reference/numpysupported.html#other-functions) I think it only makes sense to support the first two arguments of asarray_chkfinite
- so instead of adding tests for changing the order, I think it'd instead be better to remove the order='C'
kwarg from the implementation and tests.
Other than that, this is looking good!
@@ -338,6 +338,7 @@ The following top-level functions are supported: | |||
* :func:`numpy.array` (only the 2 first arguments) | |||
* :func:`numpy.array_equal` | |||
* :func:`numpy.asarray` (only the 2 first arguments) | |||
* :func:`numpy.asarray_chkfinite` (only the first first arguments) |
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.
* :func:`numpy.asarray_chkfinite` (only the first first arguments) | |
* :func:`numpy.asarray_chkfinite` (only the 2 first arguments) |
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.
Yeah, either that or only the first two arguments
, but I guess that would be inconsistent with the rest of the doc?
@rishabhvarshney14 excellent, thanks very much for fixing this up! |
@gmarkall happy with this? If yes, please do change the label to "Ready To Merge" (RTM), thx! |
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.
Looks good to me!
Yes - I saw this earlier but forgot to approve (must have got distracted). Thanks for the ping! |
@gmarkall excellent, thank you! @rishabhvarshney14 thanks for working on this so persistently, this PR is now in the RTM stage and will merged during the next merge window (probably later on today or tomorrow). 👌 |
Thank you for helping me and making my first PR really amazing. |
numba/np/arraymath.py
Outdated
else: | ||
dt = dtype.dtype |
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.
@esc Should this check that the dtype
variable as actually a Numba dtype type instance? e.g. if a user passes in a string like 'float32' they are going to get an attribute error.
numba/tests/test_np_functions.py
Outdated
#test for both inf and NaNs | ||
with self.assertRaises(ValueError) as e: | ||
cfunc(np.array([np.inf, np.nan])) | ||
self.assertIn("array must not contain infs or NaNs", str(e.exception)) | ||
|
||
#test for NaNs | ||
with self.assertRaises(ValueError) as e: | ||
cfunc(np.array([np.nan, np.nan, np.nan])) | ||
self.assertIn("array must not contain infs or NaNs", str(e.exception)) |
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.
@esc I'm not sure what these tests gain on the previous two given the alg present?
@stuartarchibald thanks for reviewing this too, more eyes is always less bugs! I'll move it back to 'waiting on author' as we address the items you mentioned. @rishabhvarshney14 can you take a look at the comments? Probably, simply adding a check the |
@esc @stuartarchibald I have changed |
@rishabhvarshney14 I believe what @stuartarchibald is referring to here are Numpy calls like the following:
Support for this type of construct (supplying a dtype as a string) was recently added in: #6262 -- perhaps you could adopt something similar in this case? I.e. to make |
In the interests of this PR making 0.52. I recommend just rejecting anything which isn't a |
@rishabhvarshney14 I would concur with @stuartarchibald to simply reject anything that isn't an instance of a dtype. |
I am having some issues with this. I tried two methods which may not be a good way for this.
This will give the required error instead of the attribute error
|
@rishabhvarshney14 I think the first option might be fine, actually. @stuartarchibald what do you say? Also, you may have some conflicts with master (as several PRs have been merged now) that must now be resolved. Your best bet is to merge the current |
@rishabhvarshney14 thanks for updates, it looks good now! One last nitpick, the git history now has a strange commit |
@rishabhvarshney14 so, after discussing with some of the other Numba devs, we agreed that it will be easiest, if I fixup this PR and re-submit a git-cleaned version. I'll try to preserve as much history as possible. |
New PR available here: #6341 |
Pull request to add support for np.asarray_chkfinite from issue #4074
Following numpy's documentation for asarray_chkfinite asarray_chkfinite takes three args: first one is array and other two are optional which are dtype and order.
When I use order with np.asarray in the impl function:
it gives the following error
The implementation of np.asarray in arraymath.py does not accept order argument.