|
17 | 17 | from hypothesis import given, assume
|
18 | 18 | from hypothesis.strategies import composite, just
|
19 | 19 |
|
| 20 | +import math |
| 21 | + |
20 | 22 | from .hypothesis_helpers import (integer_dtype_objects,
|
21 | 23 | floating_dtype_objects,
|
22 | 24 | numeric_dtype_objects,
|
|
34 | 36 | assert_integral, less_equal, isintegral, isfinite,
|
35 | 37 | ndindex, promote_dtypes, is_integer_dtype,
|
36 | 38 | is_float_dtype, not_equal, float64, asarray,
|
37 |
| - dtype_ranges, full) |
| 39 | + dtype_ranges, full, true, false) |
38 | 40 | # We might as well use this implementation rather than requiring
|
39 | 41 | # mod.broadcast_shapes(). See test_equal() and others.
|
40 | 42 | from .test_broadcasting import broadcast_shapes
|
@@ -526,18 +528,49 @@ def test_greater_equal(args):
|
526 | 528 |
|
527 | 529 | @given(numeric_scalars)
|
528 | 530 | def test_isfinite(x):
|
529 |
| - # a = _array_module.isfinite(x) |
530 |
| - pass |
| 531 | + a = _array_module.isfinite(x) |
| 532 | + TRUE = true(x.shape) |
| 533 | + if is_integer_dtype(x.dtype): |
| 534 | + assert_exactly_equal(a, TRUE) |
| 535 | + # Test that isfinite, isinf, and isnan are self-consistent. |
| 536 | + inf = logical_or(_array_module.isinf(x), _array_module.isnan(x)) |
| 537 | + assert_exactly_equal(a, logical_not(inf)) |
| 538 | + |
| 539 | + # Test the exact value by comparing to the math version |
| 540 | + if is_float_dtype(x.dtype): |
| 541 | + for idx in ndindex(x.shape): |
| 542 | + s = float(x[idx]) |
| 543 | + assert bool(a[idx]) == math.isfinite(s) |
531 | 544 |
|
532 | 545 | @given(numeric_scalars)
|
533 | 546 | def test_isinf(x):
|
534 |
| - # a = _array_module.isinf(x) |
535 |
| - pass |
| 547 | + a = _array_module.isinf(x) |
| 548 | + FALSE = false(x.shape) |
| 549 | + if is_integer_dtype(x.dtype): |
| 550 | + assert_exactly_equal(a, FALSE) |
| 551 | + finite_or_nan = logical_or(_array_module.isfinite(x), _array_module.isnan(x)) |
| 552 | + assert_exactly_equal(a, logical_not(finite_or_nan)) |
| 553 | + |
| 554 | + # Test the exact value by comparing to the math version |
| 555 | + if is_float_dtype(x.dtype): |
| 556 | + for idx in ndindex(x.shape): |
| 557 | + s = float(x[idx]) |
| 558 | + assert bool(a[idx]) == math.isinf(s) |
536 | 559 |
|
537 | 560 | @given(numeric_scalars)
|
538 | 561 | def test_isnan(x):
|
539 |
| - # a = _array_module.isnan(x) |
540 |
| - pass |
| 562 | + a = _array_module.isnan(x) |
| 563 | + FALSE = false(x.shape) |
| 564 | + if is_integer_dtype(x.dtype): |
| 565 | + assert_exactly_equal(a, FALSE) |
| 566 | + finite_or_inf = logical_or(_array_module.isfinite(x), _array_module.isinf(x)) |
| 567 | + assert_exactly_equal(a, logical_not(finite_or_inf)) |
| 568 | + |
| 569 | + # Test the exact value by comparing to the math version |
| 570 | + if is_float_dtype(x.dtype): |
| 571 | + for idx in ndindex(x.shape): |
| 572 | + s = float(x[idx]) |
| 573 | + assert bool(a[idx]) == math.isnan(s) |
541 | 574 |
|
542 | 575 | @given(two_numeric_dtypes.flatmap(lambda i: two_array_scalars(*i)))
|
543 | 576 | def test_less(args):
|
|
0 commit comments