Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
ChainRulesCore = "0.9.16"
ChainRulesTestUtils = "0.5"
Compat = "3"
FiniteDifferences = "0.11.4"
FiniteDifferences = "0.11"
Reexport = "0.2"
Requires = "0.5.2, 1"
julia = "1"
Expand Down
11 changes: 7 additions & 4 deletions test/rulesets/Base/fastmath_able.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ end
# Do not add any tests here for functions that do not have varients in Base.FastMath
# e.g. do not add `foo` unless `Base.FastMath.foo_fast` exists.
const FASTABLE_AST = quote
is_fastmath_mode = sin === Base.FastMath.sin_fast

@testset "Trig" begin
@testset "Basics" for x = (Float64(π)-0.01, Complex(π, π/2))
test_scalar(sin, x)
Expand Down Expand Up @@ -104,7 +106,7 @@ const FASTABLE_AST = quote
complex_jacobian_test(angle, z)
end
@test frule((Zero(), randn()), angle, randn())[2] === Zero()
@test rrule(angle, randn())[2](randn())[2] === Zero()
@test rrule(angle, randn())[2](randn())[2] === Zero()

# test that real primal with complex tangent gives complex tangent
ΔΩ = randn(ComplexF64)
Expand All @@ -120,7 +122,7 @@ const FASTABLE_AST = quote
for x in (-4.1, 6.4, 0.0, 0.0 + 0.0im, 0.5 + 0.25im)
test_scalar(+, x)
test_scalar(-, x)
test_scalar(atan, x)
test_scalar(atan, x; rtol=(is_fastmath_mode ? 1e-7 : 1e-9))
end
end

Expand All @@ -139,8 +141,9 @@ const FASTABLE_AST = quote
y, Δy, ȳ = rand(T, 3)
Δz = randn(typeof(f(x, y)))

frule_test(f, (x, Δx), (y, Δy))
rrule_test(f, Δz, (x, x̄), (y, ȳ))
# some tests struggle in fast_math mode to get accurasy so we relax it some.
frule_test(f, (x, Δx), (y, Δy); rtol=(is_fastmath_mode ? 1e-5 : 1e-7))
rrule_test(f, Δz, (x, x̄), (y, ȳ); rtol=(is_fastmath_mode ? 1e-5 : 1e-7))
end

@testset "$f(x::$T, y::$T) type check" for f in (/, +, -,\, hypot, ^), T in (Float32, Float64)
Expand Down
2 changes: 1 addition & 1 deletion test/rulesets/LinearAlgebra/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
n = 10
x, ẋ, x̄ = randn(T, n), randn(T, n), randn(T, n)
frule_test(BLAS.nrm2, (x, ẋ))
rrule_test(BLAS.nrm2, randn(), (x, x̄))
rrule_test(BLAS.nrm2, randn(), (x, x̄); rtol=1e-7)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ using ChainRules: level2partition, level3partition, chol_blocked_rev, chol_unblo
ΔF = unthunk(dF)
_, dX = dX_pullback(ΔF)
X̄_ad = dot(unthunk(dX), V)
X̄_fd = _fdm(0.0) do ε
X̄_fd = central_fdm(5, 1)(0.000_001) do ε
dot(Ȳ, getproperty(cholesky(X .+ ε .* V), p))
end
@test X̄_ad ≈ X̄_fd rtol=1e-6 atol=1e-6
@test X̄_ad ≈ X̄_fd rtol=1e-4
end
end
@testset "helper functions" begin
Expand Down