-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Fix dot and inner type/value exception failures #6988
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
Changes from all commits
b491cc8
67592d3
bab118d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1926,14 +1926,34 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) | |
/* Raise an error if the casting rule isn't followed */ | ||
if (!PyArray_CanCastArrayTo(arr, newtype, casting)) { | ||
PyObject *errmsg; | ||
PyArray_Descr *arr_descr = NULL; | ||
PyObject *arr_descr_repr = NULL; | ||
PyObject *newtype_repr = NULL; | ||
|
||
PyErr_Clear(); | ||
errmsg = PyUString_FromString("Cannot cast array data from "); | ||
PyUString_ConcatAndDel(&errmsg, | ||
PyObject_Repr((PyObject *)PyArray_DESCR(arr))); | ||
arr_descr = PyArray_DESCR(arr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think calling |
||
if (arr_descr == NULL) { | ||
Py_DECREF(newtype); | ||
Py_DECREF(errmsg); | ||
return NULL; | ||
} | ||
arr_descr_repr = PyObject_Repr((PyObject *)arr_descr); | ||
if (arr_descr_repr == NULL) { | ||
Py_DECREF(newtype); | ||
Py_DECREF(errmsg); | ||
return NULL; | ||
} | ||
PyUString_ConcatAndDel(&errmsg, arr_descr_repr); | ||
PyUString_ConcatAndDel(&errmsg, | ||
PyUString_FromString(" to ")); | ||
PyUString_ConcatAndDel(&errmsg, | ||
PyObject_Repr((PyObject *)newtype)); | ||
newtype_repr = PyObject_Repr((PyObject *)newtype); | ||
if (newtype_repr == NULL) { | ||
Py_DECREF(newtype); | ||
Py_DECREF(errmsg); | ||
return NULL; | ||
} | ||
PyUString_ConcatAndDel(&errmsg, newtype_repr); | ||
PyUString_ConcatAndDel(&errmsg, | ||
PyUString_FromFormat(" according to the rule %s", | ||
npy_casting_to_string(casting))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2041,6 +2041,13 @@ def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs): | |
assert_raises(TypeError, np.dot, b, c) | ||
assert_raises(TypeError, c.dot, b) | ||
|
||
def test_dot_type_mismatch(self): | ||
c = 1. | ||
A = np.array((1,1), dtype='i,i') | ||
|
||
assert_raises(ValueError, np.dot, c, A) | ||
assert_raises(TypeError, np.dot, A, c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I managed to get this built so I can debug with |
||
|
||
def test_diagonal(self): | ||
a = np.arange(12).reshape((3, 4)) | ||
assert_equal(a.diagonal(), [0, 5, 10]) | ||
|
@@ -4825,6 +4832,13 @@ def test_matmul_inplace(): | |
|
||
class TestInner(TestCase): | ||
|
||
def test_inner_type_mismatch(self): | ||
c = 1. | ||
A = np.array((1,1), dtype='i,i') | ||
|
||
assert_raises(TypeError, np.inner, c, A) | ||
assert_raises(TypeError, np.inner, A, c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same story as above. This line will cause the exception, as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to add that this error occurs with python 3.5 debug also. |
||
|
||
def test_inner_scalar_and_vector(self): | ||
for dt in np.typecodes['AllInteger'] + np.typecodes['AllFloat'] + '?': | ||
sca = np.array(3, dtype=dt)[()] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some more debugging with
gdb
apparently the segmentation fault is occurring at this line. The real line responsible is inPyArray_EquivTypes
. SomehowPyArray_EquivTypes
is gettingNULL
for its first type, which is the cause of the problem.