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

Method test_special_values

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

Source from the content-addressed store, hash-verified

300
301 @platform_skip
302 def test_special_values(self):
303 # C99: Sec G 6.4.2
304
305 check = check_complex_value
306 f = np.sqrt
307
308 # csqrt(+-0 + 0i) is 0 + 0i
309 check(f, np.PZERO, 0, 0, 0)
310 check(f, np.NZERO, 0, 0, 0)
311
312 # csqrt(x + infi) is inf + infi for any x (including NaN)
313 check(f, 1, np.inf, np.inf, np.inf)
314 check(f, -1, np.inf, np.inf, np.inf)
315
316 check(f, np.PZERO, np.inf, np.inf, np.inf)
317 check(f, np.NZERO, np.inf, np.inf, np.inf)
318 check(f, np.inf, np.inf, np.inf, np.inf)
319 check(f, -np.inf, np.inf, np.inf, np.inf)
320 check(f, -np.nan, np.inf, np.inf, np.inf)
321
322 # csqrt(x + nani) is nan + nani for any finite x
323 check(f, 1, np.nan, np.nan, np.nan)
324 check(f, -1, np.nan, np.nan, np.nan)
325 check(f, 0, np.nan, np.nan, np.nan)
326
327 # csqrt(-inf + yi) is +0 + infi for any finite y > 0
328 check(f, -np.inf, 1, np.PZERO, np.inf)
329
330 # csqrt(inf + yi) is +inf + 0i for any finite y > 0
331 check(f, np.inf, 1, np.inf, np.PZERO)
332
333 # csqrt(-inf + nani) is nan +- infi (both +i infi are valid)
334 def _check_ninf_nan(dummy):
335 msgform = "csqrt(-inf, nan) is (%f, %f), expected (nan, +-inf)"
336 z = np.sqrt(np.array(complex(-np.inf, np.nan)))
337 #Fixme: ugly workaround for isinf bug.
338 with np.errstate(invalid='ignore'):
339 if not (np.isnan(z.real) and np.isinf(z.imag)):
340 raise AssertionError(msgform % (z.real, z.imag))
341
342 _check_ninf_nan(None)
343
344 # csqrt(+inf + nani) is inf + nani
345 check(f, np.inf, np.nan, np.inf, np.nan)
346
347 # csqrt(nan + yi) is nan + nani for any finite y (infinite handled in x
348 # + nani)
349 check(f, np.nan, 0, np.nan, np.nan)
350 check(f, np.nan, 1, np.nan, np.nan)
351 check(f, np.nan, np.nan, np.nan, np.nan)
352
353 # XXX: check for conj(csqrt(z)) == csqrt(conj(z)) (need to fix branch
354 # cuts first)
355
356class TestCpow:
357 def setup_method(self):

Callers

nothing calls this directly

Calls 1

checkFunction · 0.85

Tested by

no test coverage detected