[NumPy-Tickets] [NumPy] #2197: Division by zero when creating array from N-dimensional new-style-buffer with zero length and no strides
NumPy Trac
numpy-tickets@scipy....
Wed Aug 8 01:57:23 CDT 2012
#2197: Division by zero when creating array from N-dimensional new-style-buffer
with zero length and no strides
------------------------+---------------------------------------------------
Reporter: batavus | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version: devel
Keywords: |
------------------------+---------------------------------------------------
I believe there's a bug in function _array_from_buffer_3118 in file
numpy/numpy/core/src/multiarray/ctors.c
Consider the code which currently starts at line 1228
if (view->strides != NULL) {
for (k = 0; k < nd; ++k) {
strides[k] = view->strides[k];
}
}
else {
d = view->len;
for (k = 0; k < nd; ++k) {
d /= view->shape[k];
strides[k] = d;
}
}
if strides is NULL and shape is something containing at least on zero
(e.g. [0] or [1,0,2]) such that view->len is zero, there will be a
division 0 by 0 in "d /= view->shape[k];"
I suggest replacing the line
d /= view->shape[k];
by
if (view->shape[k]) d /= view->shape[k];
This should resolve the problem and be consistent with how strides is
defined in numpy for such cases. Also, it's probably a good idea to add a
test for this issue.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2197>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list