-
-
Notifications
You must be signed in to change notification settings - Fork 892
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
Make count_nonzero to return array #154
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.
Please check!
@@ -18,17 +18,15 @@ def func(xp): | |||
m = testing.shaped_random((2, 3), xp, xp.bool_) | |||
a = testing.shaped_random((2, 3), xp, dtype) * m | |||
c = xp.count_nonzero(a) | |||
self.assertIsInstance(c, int) | |||
return c | |||
return int(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.
Write some tests for c
, just like in matrix_rank
(#97).
self.assertEqual(func(numpy), func(cupy)) | ||
|
||
@testing.for_all_dtypes() | ||
def test_count_nonzero_zero_dim(self, dtype): | ||
def func(xp): | ||
a = xp.array(1.0, dtype=dtype) | ||
c = xp.count_nonzero(a) | ||
self.assertIsInstance(c, int) | ||
return c | ||
return int(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.
Ditto (tests for c
).
LGTM! |
I fixed
count_nonzero
to returnndarray
instead ofint
. It is faster because there is not synchronization between CPU and GPU.see also #95