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

Conversation

Projects
None yet
3 participants
@unnonouno
Contributor

unnonouno commented Jun 16, 2017

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 label Jun 16, 2017

@niboshi

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)

This comment has been minimized.

@niboshi

niboshi Jun 17, 2017

Member

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)

This comment has been minimized.

@niboshi

niboshi Jun 17, 2017

Member

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 enhancement label Jun 19, 2017

unnonouno added some commits Jun 19, 2017

@niboshi

This comment has been minimized.

Member

niboshi commented Jun 20, 2017

LGTM!

@niboshi niboshi merged commit 6ac0c25 into master Jun 20, 2017

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 84.983%
Details

@niboshi niboshi deleted the count_nonzero-array branch Jun 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment