MCPcopy Create free account
hub / github.com/numpy/numpy / test_sum_complex

Method test_sum_complex

numpy/core/tests/test_ufunc.py:740–763  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

738 assert_almost_equal(d, 2.)
739
740 def test_sum_complex(self):
741 for dt in (np.complex64, np.complex128, np.clongdouble):
742 for v in (0, 1, 2, 7, 8, 9, 15, 16, 19, 127,
743 128, 1024, 1235):
744 tgt = dt(v * (v + 1) / 2) - dt((v * (v + 1) / 2) * 1j)
745 d = np.empty(v, dtype=dt)
746 d.real = np.arange(1, v + 1)
747 d.imag = -np.arange(1, v + 1)
748 assert_almost_equal(np.sum(d), tgt)
749 assert_almost_equal(np.sum(d[::-1]), tgt)
750
751 d = np.ones(500, dtype=dt) + 1j
752 assert_almost_equal(np.sum(d[::2]), 250. + 250j)
753 assert_almost_equal(np.sum(d[1::2]), 250. + 250j)
754 assert_almost_equal(np.sum(d[::3]), 167. + 167j)
755 assert_almost_equal(np.sum(d[1::3]), 167. + 167j)
756 assert_almost_equal(np.sum(d[::-2]), 250. + 250j)
757 assert_almost_equal(np.sum(d[-1::-2]), 250. + 250j)
758 assert_almost_equal(np.sum(d[::-3]), 167. + 167j)
759 assert_almost_equal(np.sum(d[-1::-3]), 167. + 167j)
760 # sum with first reduction entry != 0
761 d = np.ones((1,), dtype=dt) + 1j
762 d += d
763 assert_almost_equal(d, 2. + 2j)
764
765 def test_sum_initial(self):
766 # Integer, single axis

Callers

nothing calls this directly

Calls 3

assert_almost_equalFunction · 0.90
dtClass · 0.70
sumMethod · 0.45

Tested by

no test coverage detected