Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: array_view construction for empty arrays #5106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 2, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
jkseppan committed Sep 21, 2015
commit e6b1745f33ae2e5da977327bd72637d034d94d27
18 changes: 11 additions & 7 deletions src/numpy_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,17 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
m_data = NULL;
m_shape = zeros;
m_strides = zeros;
} else if (PyArray_NDIM(tmp) != ND) {
PyErr_Format(PyExc_ValueError,
"Expected %d-dimensional array, got %d",
ND,
PyArray_NDIM(tmp));
Py_DECREF(tmp);
return 0;
if (PyArray_NDIM(tmp) == 0 && ND == 0) {
return 1;
}
}
if (PyArray_NDIM(tmp) != ND) {
PyErr_Format(PyExc_ValueError,
"Expected %d-dimensional array, got %d",
ND,
PyArray_NDIM(tmp));
Py_DECREF(tmp);
return 0;
}

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