summaryrefslogtreecommitdiff
path: root/numpy/array_api/_manipulation_functions.py
diff options
context:
space:
mode:
authorwarren <warren.weckesser@gmail.com>2021-09-17 12:11:56 -0400
committerwarren <warren.weckesser@gmail.com>2021-09-17 12:11:56 -0400
commitee885f247cf866db439117c1160a3048274ea9a0 (patch)
treef9652a50a91fe71500cbf815dbcbc5cfbfb66073 /numpy/array_api/_manipulation_functions.py
parent5d75d4862fd3409b54a29a3523e60ac1d6e374ec (diff)
downloadnumpy-ee885f247cf866db439117c1160a3048274ea9a0.tar.gz
BUG: core: Fix *_like strides for str and bytes dtype.
When a user passed a noncontiguous array to empty_like (or any other _like function) with dtype=str or dtype=bytes, the returned array would have strides that were all 0, even though the data type was 'U1' or 'S1'. The problem was in the C code in the function PyArray_NewLikeArrayWithShape. Because the default order is "keep", the branch with the comment /* KEEPORDER needs some analysis of the strides */ was taken. That branch uses the itemsize (i.e. dtype->elsize) of the requested dtype, but for str or bytes, that itemsize is 0, so the computed strides end up being 0. It is in the subsequent call to PyArray_NewFromDescr_int that the itemsize is updated to be nonzero. The fix is to use the same check for str or bytes that is used in PyArray_NewFromDescr_int in PyArray_NewLikeArrayWithShape to figure out the itemsize when computing the strides in the KEEPORDER branch. Closes gh-19860.
Diffstat (limited to 'numpy/array_api/_manipulation_functions.py')
0 files changed, 0 insertions, 0 deletions