summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnnyOu <junyan.ou189@gmail.com>2022-05-06 02:36:26 -0500
committerGitHub <noreply@github.com>2022-05-06 09:36:26 +0200
commitba54f569cecf17812695f17812d238af2bb91000 (patch)
treef059f2afff12d3bb54c416413d12ba56f78e8897
parent2cc34c46943a92c8a5e97a1af0bffa3f2712b634 (diff)
downloadnumpy-ba54f569cecf17812695f17812d238af2bb91000.tar.gz
BUG: Fix segmentation fault (#21436)
* Fixed #21301 * Fixed #21436, better error message, organized test cases as requested * Update numpy/core/src/umath/ufunc_object.c Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
-rw-r--r--numpy/core/src/umath/ufunc_object.c7
-rw-r--r--numpy/core/tests/test_ufunc.py16
2 files changed, 22 insertions, 1 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 7b0db9e04..007f1bc53 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -5888,6 +5888,13 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
NPY_BEGIN_THREADS_DEF;
+ if (ufunc->core_enabled) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.at does not support ufunc with non-trivial signature: %s has signature %s.",
+ ufunc->name, ufunc->name, ufunc->core_signature);
+ return NULL;
+ }
+
if (ufunc->nin > 2) {
PyErr_SetString(PyExc_ValueError,
"Only unary and binary ufuncs supported at this time");
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index cb0f7bcbd..43306d7cf 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -389,7 +389,7 @@ class TestUfunc:
assert_equal(ixs, (0, 0, 0, 1, 2))
assert_equal(flags, (self.can_ignore, self.size_inferred, 0))
assert_equal(sizes, (3, -1, 9))
-
+
def test_signature9(self):
enabled, num_dims, ixs, flags, sizes = umt.test_signature(
1, 1, "( 3) -> ( )")
@@ -2002,6 +2002,20 @@ class TestUfunc:
# Test multiple output ufuncs raise error, gh-5665
assert_raises(ValueError, np.modf.at, np.arange(10), [1])
+ # Test maximum
+ a = np.array([1, 2, 3])
+ np.maximum.at(a, [0], 0)
+ assert_equal(np.array([1, 2, 3]), a)
+
+ def test_at_not_none_signature(self):
+ # Test ufuncs with non-trivial signature raise a TypeError
+ a = np.ones((2, 2, 2))
+ b = np.ones((1, 2, 2))
+ assert_raises(TypeError, np.matmul.at, a, [0], b)
+
+ a = np.array([[[1, 2], [3, 4]]])
+ assert_raises(TypeError, np.linalg._umath_linalg.det.at, a, [0])
+
def test_reduce_arguments(self):
f = np.add.reduce
d = np.ones((5,2), dtype=int)