MCPcopy
hub / github.com/numpy/numpy / test_special_values

Method test_special_values

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

Source from the content-addressed store, hash-verified

144 @platform_skip
145 @pytest.mark.skipif(platform.machine() == "armv5tel", reason="See gh-413.")
146 def test_special_values(self):
147 xl = []
148 yl = []
149
150 # From C99 std (Sec 6.3.2)
151 # XXX: check exceptions raised
152 # --- raise for invalid fails.
153
154 # clog(-0 + i0) returns -inf + i pi and raises the 'divide-by-zero'
155 # floating-point exception.
156 with np.errstate(divide='raise'):
157 x = np.array([ncu.NZERO], dtype=complex)
158 y = complex(-np.inf, np.pi)
159 assert_raises(FloatingPointError, np.log, x)
160 with np.errstate(divide='ignore'):
161 assert_almost_equal(np.log(x), y)
162
163 xl.append(x)
164 yl.append(y)
165
166 # clog(+0 + i0) returns -inf + i0 and raises the 'divide-by-zero'
167 # floating-point exception.
168 with np.errstate(divide='raise'):
169 x = np.array([0], dtype=complex)
170 y = complex(-np.inf, 0)
171 assert_raises(FloatingPointError, np.log, x)
172 with np.errstate(divide='ignore'):
173 assert_almost_equal(np.log(x), y)
174
175 xl.append(x)
176 yl.append(y)
177
178 # clog(x + i inf returns +inf + i pi /2, for finite x.
179 x = np.array([complex(1, np.inf)], dtype=complex)
180 y = complex(np.inf, 0.5 * np.pi)
181 assert_almost_equal(np.log(x), y)
182 xl.append(x)
183 yl.append(y)
184
185 x = np.array([complex(-1, np.inf)], dtype=complex)
186 assert_almost_equal(np.log(x), y)
187 xl.append(x)
188 yl.append(y)
189
190 # clog(x + iNaN) returns NaN + iNaN and optionally raises the
191 # 'invalid' floating- point exception, for finite x.
192 with np.errstate(invalid='raise'):
193 x = np.array([complex(1., np.nan)], dtype=complex)
194 y = complex(np.nan, np.nan)
195 #assert_raises(FloatingPointError, np.log, x)
196 with np.errstate(invalid='ignore'):
197 assert_almost_equal(np.log(x), y)
198
199 xl.append(x)
200 yl.append(y)
201
202 with np.errstate(invalid='raise'):
203 x = np.array([np.inf + 1j * np.nan], dtype=complex)

Callers

nothing calls this directly

Calls 2

assert_raisesFunction · 0.90
assert_almost_equalFunction · 0.90

Tested by

no test coverage detected