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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
BUG: Fix regression in arr.conj()
I'll make these helpers static-inline functions on main.
Unfortunately, this doesn't just cause wrong promotion for bool->uint8
in `arr.conj()`, but it also leads to all other non-complex types
returning unnecessary copies which seems like a pretty unfortunate
regression, even if it might not be very visible in practice.

I am suspecting we may need a 2.4.6 for this :(
  • Loading branch information
seberg committed May 17, 2026
commit bddaab7ace45f90148d8f2bb6e67daab2d45ec76
2 changes: 1 addition & 1 deletion numpy/_core/src/multiarray/calculation.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ NPY_NO_EXPORT PyObject *
PyArray_Conjugate(PyArrayObject *self, PyArrayObject *out)
{
if (PyArray_ISCOMPLEX(self) || PyArray_ISOBJECT(self) ||
PyArray_ISUSERDEF(self) || !NPY_DT_is_legacy(PyArray_DESCR(self))) {
PyArray_ISUSERDEF(self) || !NPY_DT_is_legacy(NPY_DTYPE(PyArray_DESCR(self)))) {
if (out == NULL) {
return PyArray_GenericUnaryFunction(self,
n_ops.conjugate);
Expand Down
11 changes: 11 additions & 0 deletions numpy/_core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,17 @@ def test_conjugate(self):
assert_raises(TypeError, a.conj)
assert_raises(TypeError, a.conjugate)

@pytest.mark.parametrize("dtype", ["?", "b", "h", "I"])
def test_conjugate_view(self, dtype):
a = np.ones(10, dtype=dtype)
assert a.conj() is a

@pytest.mark.parametrize("dtype", ["S", "U", "M8[ns]"])
def test_conjugate_error(self, dtype):
a = np.ones(10, dtype=dtype)
with pytest.raises(TypeError, match="cannot conjugate non-numeric dtype"):
a.conj()

def test_conjugate_out(self):
# Minimal test for the out argument being passed on correctly
# NOTE: The ability to pass `out` is currently undocumented!
Expand Down
Loading