|
31 | 31 | logical_or, logical_and, inrange, π, one, zero, |
32 | 32 | infinity, isnegative, all as array_all, any as |
33 | 33 | array_any, int_to_dtype, bool as bool_dtype, |
34 | | - assert_integral, less_equal, isintegral, |
35 | | - isfinite, ndindex, promote_dtypes, |
36 | | - is_integer_dtype, is_float_dtype) |
| 34 | + assert_integral, less_equal, isintegral, isfinite, |
| 35 | + ndindex, promote_dtypes, is_integer_dtype, |
| 36 | + is_float_dtype, not_equal, float64, asarray) |
37 | 37 | # We might as well use this implementation rather than requiring |
38 | 38 | # mod.broadcast_shapes(). See test_equal() and others. |
39 | 39 | from .test_broadcasting import broadcast_shapes |
@@ -437,7 +437,25 @@ def test_floor(x): |
437 | 437 | def test_floor_divide(args): |
438 | 438 | x1, x2 = args |
439 | 439 | sanity_check(x1, x2) |
440 | | - # a = _array_module.floor_divide(x1, x2) |
| 440 | + if is_integer_dtype(x1.dtype): |
| 441 | + # The spec does not specify the behavior for division by 0 for integer |
| 442 | + # dtypes. A library may choose to raise an exception in this case, so |
| 443 | + # we avoid passing it in entirely. |
| 444 | + nonzero = not_equal(x2, zero(x2.shape, x2.dtype)) |
| 445 | + div = _array_module.divide( |
| 446 | + asarray(x1[nonzero], dtype=float64), |
| 447 | + asarray(x2[nonzero], dtype=float64)) |
| 448 | + a = _array_module.floor_divide(x1[nonzero], x2[nonzero]) |
| 449 | + else: |
| 450 | + div = _array_module.divide(x1, x2) |
| 451 | + a = _array_module.floor_divide(x1, x2) |
| 452 | + |
| 453 | + # TODO: The spec doesn't clearly specify the behavior of floor_divide on |
| 454 | + # infinities. See https://github.com/data-apis/array-api/issues/199. |
| 455 | + finite = isfinite(div) |
| 456 | + assert_integral(a[finite]) |
| 457 | + |
| 458 | + # TODO: Test the exact output for floor_divide. |
441 | 459 |
|
442 | 460 | @given(two_numeric_dtypes.flatmap(lambda i: two_array_scalars(*i))) |
443 | 461 | def test_greater(args): |
|
0 commit comments