8000 Merge pull request #4887 from ewmoore/conj_obj · numpy/numpy@8198235 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8198235

Browse files
committed
Merge pull request #4887 from ewmoore/conj_obj
BUG: object array np.conjugate, ndarray.conjugate inconsistent
2 parents f94151d + 5941fc9 commit 8198235

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
@@ -1697,6 +1697,43 @@ def test_ravel(self):
16971697
assert_equal(a.ravel(order='K'), [2, 3, 0, 1])
16981698
assert_(a.ravel(order='K').flags.owndata)
16991699

1700+
def test_conjugate(self):
1701+
a = np.array([1-1j, 1+1j, 23+23.0j])
1702+
ac = a.conj()
1703+
assert_equal(a.real, ac.real)
1704+
assert_equal(a.imag, -ac.imag)
1705+
assert_equal(ac, a.conjugate())
1706+
assert_equal(ac, np.conjugate(a))
1707+
1708+
a = np.array([1-1j, 1+1j, 23+23.0j], 'F')
1709+
ac = a.conj()
1710+
assert_equal(a.real, ac.real)
1711+
assert_equal(a.imag, -ac.imag)
1712+
assert_equal(ac, a.conjugate())
1713+
assert_equal(ac, np.conjugate(a))
1714+
1715+
a = np.array([1, 2, 3])
1716+
ac = a.conj()
1717+
assert_equal(a, ac)
1718+
assert_equal(ac, a.conjugate())
1719+
assert_equal(ac, np.conjugate(a))
1720+
1721+
a = np.array([1.0, 2.0, 3.0])
1722+
ac = a.conj()
1723+
assert_equal(a, ac)
1724+
assert_equal(ac, a.conjugate())
1725+
assert_equal(ac, np.conjugate(a))
1726+
1727+
a = np.array([1-1j, 1+1j, 1, 2.0], object)
1728+
ac = a.conj()
1729+
assert_equal(ac, [k.conjugate() for k in a])
1730+
assert_equal(ac, a.conjugate())
1731+
assert_equal(ac, np.conjugate(a))
1732+
1733+
a = np.array([1-1j, 1, 2.0, 'f'], object)
1734+
assert_raises(AttributeError, lambda: a.conj())
1735+
assert_raises(AttributeError, lambda: a.conjugate())
1736+
17001737

17011738
class TestBinop(object):
17021739
def test_ufunc_override_rop_precedence(self):

0 commit comments

Comments
 (0)
0