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

Method test_cabs_inf_nan

numpy/core/tests/test_umath_complex.py:436–469  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

434 assert_array_equal(np.abs(x), np.real(x))
435
436 def test_cabs_inf_nan(self):
437 x, y = [], []
438
439 # cabs(+-nan + nani) returns nan
440 x.append(np.nan)
441 y.append(np.nan)
442 check_real_value(np.abs, np.nan, np.nan, np.nan)
443
444 x.append(np.nan)
445 y.append(-np.nan)
446 check_real_value(np.abs, -np.nan, np.nan, np.nan)
447
448 # According to C99 standard, if exactly one of the real/part is inf and
449 # the other nan, then cabs should return inf
450 x.append(np.inf)
451 y.append(np.nan)
452 check_real_value(np.abs, np.inf, np.nan, np.inf)
453
454 x.append(-np.inf)
455 y.append(np.nan)
456 check_real_value(np.abs, -np.inf, np.nan, np.inf)
457
458 # cabs(conj(z)) == conj(cabs(z)) (= cabs(z))
459 def f(a):
460 return np.abs(np.conj(a))
461
462 def g(a, b):
463 return np.abs(complex(a, b))
464
465 xa = np.array(x, dtype=complex)
466 assert len(xa) == len(x) == len(y)
467 for xi, yi in zip(x, y):
468 ref = g(xi, yi)
469 check_real_value(f, xi, yi, ref)
470
471class TestCarg:
472 def test_simple(self):

Callers

nothing calls this directly

Calls 1

check_real_valueFunction · 0.85

Tested by

no test coverage detected