-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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 keras.ops.searchsorted #19922
base: master
Are you sure you want to change the base?
Add keras.ops.searchsorted #19922
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19922 +/- ##
==========================================
- Coverage 79.02% 78.96% -0.06%
==========================================
Files 499 499
Lines 46436 46523 +87
Branches 8548 8561 +13
==========================================
+ Hits 36695 36738 +43
- Misses 8015 8052 +37
- Partials 1726 1733 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Converted to draft because I will add a test |
I opted to try to maximize support for N-D searchsorted (because this is my use-case). However, numpy does not support it. JAX supports it by vmapping, which I implemented. If you have better suggestions on how we can support N-D searchsorted, I would be happy to implement them. The tests also need to be updated, still, because Nevertheless, I am marking this as ready for review now, so that you can give feedback. Thank you. |
Thanks for the PR!
Since we support vmapping APIs, we could simply not implement N-D support for this op. We should try to stay as close to NumPy as possible in order to minimize user surprise. A TF test seems to be failing:
|
@fchollet Thank you for the review!
You make a good point. In that case, should we raise an error if the user passes an N-D If we raise an error: Should we do this in
We can drop the part that is failing if we only support 1-D. |
@@ -3966,6 +3966,13 @@ def test_round(self): | |||
self.assertAllClose(knp.round(x, decimals=-1), np.round(x, decimals=-1)) | |||
self.assertAllClose(knp.Round(decimals=-1)(x), np.round(x, decimals=-1)) | |||
|
|||
def test_searchsorted(self): |
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.
Please also add a test for static shape inference (on KerasTensors).
Better to do it in each backend function I think! |
This is commonly used for spline transformations.