Skip to content

Commit e6b1745

Browse files
committed
Return error from array_view for numpy scalars
Unless ND==0, in which case return success but don't clobber the m_shape and m_strides members.
1 parent 2706edb commit e6b1745

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/numpy_cpp.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,17 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
443443
m_data = NULL;
444444
m_shape = zeros;
445445
m_strides = zeros;
446-
} else if (PyArray_NDIM(tmp) != ND) {
447-
PyErr_Format(PyExc_ValueError,
448-
"Expected %d-dimensional array, got %d",
449-
ND,
450-
PyArray_NDIM(tmp));
451-
Py_DECREF(tmp);
452-
return 0;
446+
if (PyArray_NDIM(tmp) == 0 && ND == 0) {
447+
return 1;
448+
}
449+
}
450+
if (PyArray_NDIM(tmp) != ND) {
451+
PyErr_Format(PyExc_ValueError,
452+
"Expected %d-dimensional array, got %d",
453+
ND,
454+
PyArray_NDIM(tmp));
455+
Py_DECREF(tmp);
456+
return 0;
453457
}
454458

455459
/* Copy some of the data to the view object for faster access */

0 commit comments

Comments
 (0)