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

Method test_special_values

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

checkFunction · 0.85

Tested by

no test coverage detected