Skip to content

Conversation

takagi
Copy link
Contributor

@takagi takagi commented Jun 29, 2021

Fix #4354.

The result of astype from a ndarray whose dtype is boolean to another dtype is expected to be zero or one. However, its underlying representation is not necessarily zero or one (i.g. a view). And in such a case, astype returns a ndarray with values other than zero or one. This PR fixes astype from boolean ndarray to return the proper value.

@takagi takagi added cat:bug Bugs prio:high to-be-backported Pull-requests to be backported to stable branch labels Jun 29, 2021
@toslunar
Copy link
Member

Does the change also fix automatic conversion from boolean?

>>> for xp in (numpy, cupy): xp.arange(3, dtype=xp.int8).view(bool) + 4.5
...
array([4.5, 5.5, 5.5])
array([4.5, 5.5, 6.5])

@takagi
Copy link
Contributor Author

takagi commented Jun 30, 2021

I got the same result with this change, so it seems to be another issue.

Copy link
Member

@toslunar toslunar left a comment

Choose a reason for hiding this comment

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

LGTM because fixing the astype issue can have higher priority than other type conversions.

@toslunar
Copy link
Member

toslunar commented Jul 8, 2021

Jenkins, test this please.

@chainer-ci
Copy link
Member

Jenkins CI test (for commit c576e99, target branch master) succeeded!

@kmaehashi kmaehashi added this to the v10.0.0b1 milestone Jul 13, 2021
@kmaehashi kmaehashi enabled auto-merge July 13, 2021 12:54
@kmaehashi kmaehashi disabled auto-merge July 13, 2021 12:55
@kmaehashi kmaehashi merged commit 899445c into cupy:master Jul 13, 2021
chainer-ci pushed a commit to chainer-ci/cupy that referenced this pull request Jul 13, 2021
@takagi takagi deleted the bool-astype branch July 14, 2021 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:bug Bugs prio:high to-be-backported Pull-requests to be backported to stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

suprising behavior of cupy.array on numpy views with base array of a different dtype
4 participants