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

Function test_addition_reduce_negative_zero

numpy/core/tests/test_ufunc.py:2834–2857  ·  view source on GitHub ↗
(dtype, use_initial)

Source from the content-addressed store, hash-verified

2832@pytest.mark.parametrize("dtype", np.typecodes["AllFloat"])
2833@pytest.mark.parametrize("use_initial", [True, False])
2834def test_addition_reduce_negative_zero(dtype, use_initial):
2835 dtype = np.dtype(dtype)
2836 if dtype.kind == "c":
2837 neg_zero = dtype.type(complex(-0.0, -0.0))
2838 else:
2839 neg_zero = dtype.type(-0.0)
2840
2841 kwargs = {}
2842 if use_initial:
2843 kwargs["initial"] = neg_zero
2844 else:
2845 pytest.xfail("-0. propagation in sum currently requires initial")
2846
2847 # Test various length, in case SIMD paths or chunking play a role.
2848 # 150 extends beyond the pairwise blocksize; probably not important.
2849 for i in range(0, 150):
2850 arr = np.array([neg_zero] * i, dtype=dtype)
2851 res = np.sum(arr, **kwargs)
2852 if i > 0 or use_initial:
2853 assert _check_neg_zero(res)
2854 else:
2855 # `sum([])` should probably be 0.0 and not -0.0 like `sum([-0.0])`
2856 assert not np.signbit(res.real)
2857 assert not np.signbit(res.imag)
2858
2859class TestLowlevelAPIAccess:
2860 def test_resolve_dtypes_basic(self):

Callers

nothing calls this directly

Calls 3

_check_neg_zeroFunction · 0.85
dtypeMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected