MCPcopy Index your code
hub / github.com/numpy/numpy / test_special_values

Method test_special_values

numpy/_core/tests/test_umath_complex.py:49–125  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

47
48 @platform_skip
49 def test_special_values(self):
50 # C99: Section G 6.3.1
51
52 check = check_complex_value
53 f = np.exp
54
55 # cexp(+-0 + 0i) is 1 + 0i
56 check(f, ncu.PZERO, 0, 1, 0, False)
57 check(f, ncu.NZERO, 0, 1, 0, False)
58
59 # cexp(x + infi) is nan + nani for finite x and raises 'invalid' FPU
60 # exception
61 check(f, 1, np.inf, np.nan, np.nan)
62 check(f, -1, np.inf, np.nan, np.nan)
63 check(f, 0, np.inf, np.nan, np.nan)
64
65 # cexp(inf + 0i) is inf + 0i
66 check(f, np.inf, 0, np.inf, 0)
67
68 # cexp(-inf + yi) is +0 * (cos(y) + i sin(y)) for finite y
69 check(f, -np.inf, 1, ncu.PZERO, ncu.PZERO)
70 check(f, -np.inf, 0.75 * np.pi, ncu.NZERO, ncu.PZERO)
71
72 # cexp(inf + yi) is +inf * (cos(y) + i sin(y)) for finite y
73 check(f, np.inf, 1, np.inf, np.inf)
74 check(f, np.inf, 0.75 * np.pi, -np.inf, np.inf)
75
76 # cexp(-inf + inf i) is +-0 +- 0i (signs unspecified)
77 def _check_ninf_inf(dummy):
78 msgform = "cexp(-inf, inf) is (%f, %f), expected (+-0, +-0)"
79 with np.errstate(invalid='ignore'):
80 z = f(np.array(complex(-np.inf, np.inf)))
81 if z.real != 0 or z.imag != 0:
82 raise AssertionError(msgform % (z.real, z.imag))
83
84 _check_ninf_inf(None)
85
86 # cexp(inf + inf i) is +-inf + NaNi and raised invalid FPU ex.
87 def _check_inf_inf(dummy):
88 msgform = "cexp(inf, inf) is (%f, %f), expected (+-inf, nan)"
89 with np.errstate(invalid='ignore'):
90 z = f(np.array(complex(np.inf, np.inf)))
91 if not np.isinf(z.real) or not np.isnan(z.imag):
92 raise AssertionError(msgform % (z.real, z.imag))
93
94 _check_inf_inf(None)
95
96 # cexp(-inf + nan i) is +-0 +- 0i
97 def _check_ninf_nan(dummy):
98 msgform = "cexp(-inf, nan) is (%f, %f), expected (+-0, +-0)"
99 with np.errstate(invalid='ignore'):
100 z = f(np.array(complex(-np.inf, np.nan)))
101 if z.real != 0 or z.imag != 0:
102 raise AssertionError(msgform % (z.real, z.imag))
103
104 _check_ninf_nan(None)
105
106 # cexp(inf + nan i) is +-inf + nan

Callers

nothing calls this directly

Calls 1

checkFunction · 0.85

Tested by

no test coverage detected