diff options
author | warren <warren.weckesser@gmail.com> | 2021-09-17 12:11:56 -0400 |
---|---|---|
committer | warren <warren.weckesser@gmail.com> | 2021-09-17 12:11:56 -0400 |
commit | ee885f247cf866db439117c1160a3048274ea9a0 (patch) | |
tree | f9652a50a91fe71500cbf815dbcbc5cfbfb66073 /numpy/array_api/_manipulation_functions.py | |
parent | 5d75d4862fd3409b54a29a3523e60ac1d6e374ec (diff) | |
download | numpy-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