-
-
Notifications
You must be signed in to change notification settings - Fork 776
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 apply_over_axes
API
#8177
base: main
Are you sure you want to change the base?
add apply_over_axes
API
#8177
Conversation
@@ -106,3 +106,11 @@ def test_apply_along_axis_invalid_axis(): | |||
for axis in [-3, 2]: | |||
with pytest.raises(numpy.AxisError): | |||
xp.apply_along_axis(xp.sum, axis, a) | |||
|
|||
|
|||
class TestApplyOverAxes(unittest.TestCase): |
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.
Could you add another test for axes.ndim == 0
for coverage?
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.
add test_apply_over_axis_invalid_0darr
Co-authored-by: Akifumi Imanishi <akifumi.imanishi@gmail.com>
for axis in axes: | ||
axis = internal._normalize_axis_index(axis, N) | ||
res = func(val, axis) | ||
if res.ndim == val.ndim: |
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.
Could you add another test for res.ndim == val.ndim
?
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.
Could you add this test?
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.
Yes, I'm working on it.
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.
add test_apply_over_axis_shape_preserve_func
Co-authored-by: Akifumi Imanishi <akifumi.imanishi@gmail.com>
Co-authored-by: Akifumi Imanishi <akifumi.imanishi@gmail.com>
for xp in [numpy, cupy]: | ||
a = xp.array(42) | ||
with pytest.raises(AttributeError): | ||
xp.apply_over_axes(xp.sum, a, 0) |
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 line should not raise AttributeError
.
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.
I've Changed it into numpy.AxisError
I found that cupy behaves different from numpy in 0-demension array. cupy will throw an AxisError:
But numpy will not throw an error:
The key difference is that cupy uses:
but numpy uses
I will make the behavior the same with numpy. But also add a comment on there. |
Merge branch 'main' of https://github.com/cupy/cupy
HI, I have fixed all the problems. Would you like to take a look? |
@syheliel Could you fix for CI failures? |
This pull request is now in conflicts. Could you fix it @syheliel? 🙏 |
got it, I will fix it later |
CIs are still failing. We can provide assistance if needed. 😃 |
@asi1024 thanks! I have located where is the problem and I'm trying to fix/test it on my local machine |
I've fixed the flake8 problem. But I can't find a way to fix this in doc:
Would you like take a look? |
@@ -14,5 +14,6 @@ Functional programming | |||
:toctree: generated/ | |||
|
|||
apply_along_axis | |||
apply_over_axis |
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.
apply_over_axis | |
apply_over_axes |
Hello, the community! This PR is to contribute a little step forward #6078. It's my first time to get involved in
cupy
:)implement Code is from: https://github.com/numpy/numpy/blob/8f7e4c57931569760a036599ade6955ecc387c84/numpy/lib/_shape_base_impl.py#L413
Test code is from: https://github.com/numpy/numpy/blob/8f7e4c57931569760a036599ade6955ecc387c84/numpy/lib/tests/test_shape_base.py#L274