diff options
| author | Matti Picus <matti.picus@gmail.com> | 2022-03-02 23:59:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-02 23:59:18 -0700 |
| commit | b7529e6bac6e7b8a785aa0e1612aa54927adac41 (patch) | |
| tree | e88b36ee6150bf858115a0f0fd3d88817ee5e4fa | |
| parent | 13e8ace9f1f87d1cc8fcca0124571454b06fae1e (diff) | |
| parent | 7532ab6e52bb345cf97b32ec05d3f254966c06bf (diff) | |
| download | numpy-b7529e6bac6e7b8a785aa0e1612aa54927adac41.tar.gz | |
Merge pull request #21132 from tirthasheshpatel/fix-gh20336
BUG,ENH: np._from_dlpack: export arrays with any-strided size-1 dimen…
| -rw-r--r-- | numpy/core/src/multiarray/dlpack.c | 2 | ||||
| -rw-r--r-- | numpy/core/tests/test_dlpack.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/dlpack.c b/numpy/core/src/multiarray/dlpack.c index 980b85395..e4886cf4b 100644 --- a/numpy/core/src/multiarray/dlpack.c +++ b/numpy/core/src/multiarray/dlpack.c @@ -137,7 +137,7 @@ array_dlpack(PyArrayObject *self, if (!PyArray_IS_C_CONTIGUOUS(self) && PyArray_SIZE(self) != 1) { for (int i = 0; i < ndim; ++i) { - if (strides[i] % itemsize != 0) { + if (shape[i] != 1 && strides[i] % itemsize != 0) { PyErr_SetString(PyExc_RuntimeError, "DLPack only supports strides which are a multiple of " "itemsize."); diff --git a/numpy/core/tests/test_dlpack.py b/numpy/core/tests/test_dlpack.py index 203cf02c0..43a663f66 100644 --- a/numpy/core/tests/test_dlpack.py +++ b/numpy/core/tests/test_dlpack.py @@ -115,3 +115,9 @@ class TestDLPack: x = np.array(1.0) y = np._from_dlpack(x) assert_array_equal(x, y) + + def test_size1dims_arrays(self): + x = np.ndarray(dtype='f8', shape=(10, 5, 1), strides=(8, 80, 4), + buffer=np.ones(1000, dtype=np.uint8), order='F') + y = np._from_dlpack(x) + assert_array_equal(x, y) |
