Skip to content
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

Merged
merged 3 commits into from
Jun 20, 2017
Merged

Make count_nonzero to return array #154

merged 3 commits into from
Jun 20, 2017

Conversation

unnonouno
Copy link
Contributor

I fixed count_nonzero to return ndarray instead of int. It is faster because there is not synchronization between CPU and GPU.
see also #95

@unnonouno unnonouno added the no-compat Disrupts backward compatibility label Jun 16, 2017
Copy link
Member

@niboshi niboshi left a 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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto (tests for c).

@niboshi niboshi self-assigned this Jun 17, 2017
@okuta okuta added this to the v2.0.0a milestone Jun 19, 2017
@niboshi niboshi added the cat:enhancement Improvements to existing features label Jun 19, 2017
@niboshi
Copy link
Member

niboshi commented Jun 20, 2017

LGTM!

@niboshi niboshi merged commit 6ac0c25 into master Jun 20, 2017
@niboshi niboshi deleted the count_nonzero-array branch June 20, 2017 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement Improvements to existing features no-compat Disrupts backward compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants