Skip to content

Commit 38414d7

Browse files
committed
style and doc fixes
1 parent 09e699d commit 38414d7

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

test/rulesets/Base/base.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@
8787

8888
x isa Real && test_scalar(cbrt, x)
8989
if (x isa Real && x >= 0) || x isa Complex
90-
# this check is needed because the imaginary part jumps from pi to -pi
91-
nr = imag(x) != 0 && real(x) < 0
92-
test_scalar(sqrt, x, test_wirtinger=nr)
93-
test_scalar(log, x, test_wirtinger=nr)
94-
test_scalar(log2, x, test_wirtinger=nr)
95-
test_scalar(log10, x, test_wirtinger=nr)
96-
test_scalar(log1p, x, test_wirtinger=nr)
90+
# this check is needed because these have discontinuities between
91+
# `-10 + im*eps()` and `-10 - im*eps()`
92+
should_test_wirtinger = imag(x) != 0 && real(x) < 0
93+
test_scalar(sqrt, x; test_wirtinger=should_test_wirtinger)
94+
test_scalar(log, x; test_wirtinger=should_test_wirtinger)
95+
test_scalar(log2, x; test_wirtinger=should_test_wirtinger)
96+
test_scalar(log10, x; test_wirtinger=should_test_wirtinger)
97+
test_scalar(log1p, x; test_wirtinger=should_test_wirtinger)
9798
end
9899
end
99100
end

test/test_util.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using ChainRules
55
const _fdm = central_fdm(5, 1)
66

77
"""
8-
test_scalar(f, x; rtol=1e-9, atol=1e-9, fdm=central_fdm(5, 1), kwargs...)
8+
test_scalar(f, x; rtol=1e-9, atol=1e-9, fdm=central_fdm(5, 1), test_wirtinger=x isa Complex, kwargs...)
99
1010
Given a function `f` with scalar input an scalar output, perform finite differencing checks,
1111
at input point `x` to confirm that there are correct ChainRules provided.
@@ -14,7 +14,9 @@ at input point `x` to confirm that there are correct ChainRules provided.
1414
- `f`: Function for which the `frule` and `rrule` should be tested.
1515
- `x`: input at which to evaluate `f` (should generally be set to an arbitary point in the domain).
1616
17-
All keyword arguments except for `fdm` are passed to `isapprox`.
17+
- `test_wirtinger`: test whether the wirtinger derivative is correct, too
18+
19+
All keyword arguments except for `fdm` and `test_wirtinger` are passed to `isapprox`.
1820
"""
1921
function test_scalar(f, x; rtol=1e-9, atol=1e-9, fdm=_fdm, test_wirtinger=x isa Complex, kwargs...)
2022
@testset "$f at $x, $(nameof(rule))" for rule in (rrule, frule)

0 commit comments

Comments
 (0)