diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2014-03-16 13:50:53 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2014-03-16 13:50:53 -0600 |
commit | b80ef7539cc91f4c78a80f425b0906f497fc1f12 (patch) | |
tree | bd4aa7fefde65bc09ab773392217fc03c57b1642 | |
parent | ea639028632c5e7c2cd5ebc8f404c567b98c1dee (diff) | |
parent | a22bb0e4dd4265216128cfb4796730d1df2b5d94 (diff) | |
download | numpy-b80ef7539cc91f4c78a80f425b0906f497fc1f12.tar.gz |
Merge pull request #4483 from meltingwax/meltingwax/2469
BUG: Fix commutativity of {dot,multiply,inner}(scalar, matrix_of_objects)
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 17 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 7 |
3 files changed, 25 insertions, 1 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 233855460..767c68932 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -2429,7 +2429,7 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc, */ if (nin == 2 && nout == 1 && dtypes[1]->type_num == NPY_OBJECT) { PyObject *_obj = PyTuple_GET_ITEM(args, 1); - if (!PyArray_CheckExact(_obj)) { + if (!PyArray_Check(_obj)) { double self_prio, other_prio; self_prio = PyArray_GetPriority(PyTuple_GET_ITEM(args, 0), NPY_SCALAR_PRIORITY); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 655ac3748..b872a528d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3152,6 +3152,23 @@ class TestDot(TestCase): r = np.empty((1024, 32), dtype=int) assert_raises(ValueError, dot, f, v, r) + def test_dot_scalar_and_matrix_of_objects(self): + # Ticket #2469 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.dot(arr, 3), desired) + assert_equal(np.dot(3, arr), desired) + + +class TestInner(TestCase): + + def test_inner_scalar_and_matrix_of_objects(self): + # Ticket #4482 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.inner(arr, 3), desired) + assert_equal(np.inner(3, arr), desired) + class TestSummarization(TestCase): def test_1d(self): diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index f5a98431c..7ad75c85c 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -589,6 +589,13 @@ class TestUfunc(TestCase): assert_equal(np.max(a), True) assert_equal(np.min(a), False) + def test_object_scalar_multiply(self): + # Tickets #2469 and #4482 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.multiply(arr, 3), desired) + assert_equal(np.multiply(3, arr), desired) + def test_zerosize_reduction(self): # Test with default dtype and object dtype for a in [[], np.array([], dtype=object)]: |