Skip to content

Commit 5941fc9

Browse files
committed
BUG: object array np.conjugate, ndarray.conjugate inconsistent
fixes numpygh-4730
1 parent 88cf0e4 commit 5941fc9

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

numpy/core/src/multiarray/calculation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o
11821182
NPY_NO_EXPORT PyObject *
11831183
PyArray_Conjugate(PyArrayObject *self, PyArrayObject *out)
11841184
{
1185-
if (PyArray_ISCOMPLEX(self)) {
1185+
if (PyArray_ISCOMPLEX(self) || PyArray_ISOBJECT(self)) {
11861186
if (out == NULL) {
11871187
return PyArray_GenericUnaryFunction(self,
11881188
n_ops.conjugate);

numpy/core/tests/test_multiarray.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,43 @@ def test_ravel(self):
16751675
assert_equal(a.ravel(order='K'), [2, 3, 0, 1])
16761676
assert_(a.ravel(order='K').flags.owndata)
16771677

1678+
def test_conjugate(self):
1679+
a = np.array([1-1j, 1+1j, 23+23.0j])
1680+
ac = a.conj()
1681+
assert_equal(a.real, ac.real)
1682+
assert_equal(a.imag, -ac.imag)
1683+
assert_equal(ac, a.conjugate())
1684+
assert_equal(ac, np.conjugate(a))
1685+
1686+
a = np.array([1-1j, 1+1j, 23+23.0j], 'F')
1687+
ac = a.conj()
1688+
assert_equal(a.real, ac.real)
1689+
assert_equal(a.imag, -ac.imag)
1690+
assert_equal(ac, a.conjugate())
1691+
assert_equal(ac, np.conjugate(a))
1692+
1693+
a = np.array([1, 2, 3])
1694+
ac = a.conj()
1695+
assert_equal(a, ac)
1696+
assert_equal(ac, a.conjugate())
1697+
assert_equal(ac, np.conjugate(a))
1698+
1699+
a = np.array([1.0, 2.0, 3.0])
1700+
ac = a.conj()
1701+
assert_equal(a, ac)
1702+
assert_equal(ac, a.conjugate())
1703+
assert_equal(ac, np.conjugate(a))
1704+
1705+
a = np.array([1-1j, 1+1j, 1, 2.0], object)
1706+
ac = a.conj()
1707+
assert_equal(ac, [k.conjugate() for k in a])
1708+
assert_equal(ac, a.conjugate())
1709+
assert_equal(ac, np.conjugate(a))
1710+
1711+
a = np.array([1-1j, 1, 2.0, 'f'], object)
1712+
assert_raises(AttributeError, lambda: a.conj())
1713+
assert_raises(AttributeError, lambda: a.conjugate())
1714+
16781715

16791716
class TestBinop(object):
16801717
def test_ufunc_override_rop_precedence(self):

0 commit comments

Comments
 (0)