Skip to content

Commit 7c862c0

Browse files
committed
Add elementwise tests for log, log1p, log2, and log10
1 parent a4d2689 commit 7c862c0

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

array_api_tests/test_elementwise_functions.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,23 +634,47 @@ def test_less_equal(args):
634634

635635
@given(floating_scalars)
636636
def test_log(x):
637-
# a = _array_module.log(x)
638-
pass
637+
a = _array_module.log(x)
638+
INFINITY = infinity(x.shape, x.dtype)
639+
ZERO = zero(x.shape, x.dtype)
640+
domain = inrange(x, ZERO, INFINITY)
641+
codomain = inrange(a, -INFINITY, INFINITY)
642+
# log maps [0, inf] to [-inf, inf]. Values outside this domain are
643+
# mapped to nan, which is already tested in the special cases.
644+
assert_exactly_equal(domain, codomain)
639645

640646
@given(floating_scalars)
641647
def test_log1p(x):
642-
# a = _array_module.log1p(x)
643-
pass
648+
a = _array_module.log1p(x)
649+
INFINITY = infinity(x.shape, x.dtype)
650+
NEGONE = -one(x.shape, x.dtype)
651+
codomain = inrange(x, NEGONE, INFINITY)
652+
domain = inrange(a, -INFINITY, INFINITY)
653+
# log1p maps [1, inf] to [-inf, inf]. Values outside this domain are
654+
# mapped to nan, which is already tested in the special cases.
655+
assert_exactly_equal(domain, codomain)
644656

645657
@given(floating_scalars)
646658
def test_log2(x):
647-
# a = _array_module.log2(x)
648-
pass
659+
a = _array_module.log2(x)
660+
INFINITY = infinity(x.shape, x.dtype)
661+
ZERO = zero(x.shape, x.dtype)
662+
domain = inrange(x, ZERO, INFINITY)
663+
codomain = inrange(a, -INFINITY, INFINITY)
664+
# log2 maps [0, inf] to [-inf, inf]. Values outside this domain are
665+
# mapped to nan, which is already tested in the special cases.
666+
assert_exactly_equal(domain, codomain)
649667

650668
@given(floating_scalars)
651669
def test_log10(x):
652-
# a = _array_module.log10(x)
653-
pass
670+
a = _array_module.log10(x)
671+
INFINITY = infinity(x.shape, x.dtype)
672+
ZERO = zero(x.shape, x.dtype)
673+
domain = inrange(x, ZERO, INFINITY)
674+
codomain = inrange(a, -INFINITY, INFINITY)
675+
# log10 maps [0, inf] to [-inf, inf]. Values outside this domain are
676+
# mapped to nan, which is already tested in the special cases.
677+
assert_exactly_equal(domain, codomain)
654678

655679
@given(two_floating_dtypes.flatmap(lambda i: two_array_scalars(*i)))
656680
def test_logaddexp(args):

0 commit comments

Comments
 (0)