Skip to content

Commit

Permalink
Attempt to fix version testing mishap (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Nov 10, 2023
1 parent 6cdb3e3 commit fb5b0ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Enzyme_jll = "7cc45869-7501-5eee-bdea-0790c847d4ef"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
InlineStrings = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48"
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
Expand Down
24 changes: 11 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using GPUCompiler
using Enzyme
using Test
using FiniteDifferences
using ForwardDiff
using Aqua
using Statistics
using LinearAlgebra
Expand Down Expand Up @@ -219,8 +218,8 @@ make3() = (1.0, 2.0, 3.0)
test_scalar(Base.atan, 0.9)

res = autodiff(Reverse, Base.atan, Active, Active(0.9), Active(3.4))[1]
@test res[1] ForwardDiff.derivative(x->Base.atan(x, 3.4), 0.9)
@test res[2] ForwardDiff.derivative(x->Base.atan(0.9, x), 3.4)
@test res[1] 3.4 / (0.9 * 0.9 + 3.4 * 3.4)
@test res[2] -0.9 / (0.9 * 0.9 + 3.4 * 3.4)

test_scalar(cbrt, 1.0)
test_scalar(cbrt, 1.0f0; rtol = 1.0e-5, atol = 1.0e-5)
Expand Down Expand Up @@ -506,23 +505,23 @@ end
end

let
function loadsin(xp)
function loadsin2(xp)
x = @inbounds xp[1]
@inbounds xp[1] = 0.0
sin(x)
end
global invsin
function invsin(xp)
global invsin2
function invsin2(xp)
xp = Base.invokelatest(convert, Vector{Float64}, xp)
loadsin(xp)
loadsin2(xp)
end
x = [2.0]
end

@testset "Struct return" begin
x = [2.0]
dx = [0.0]
@test Enzyme.autodiff(Reverse, invsin, Active, Duplicated(x, dx)) == ((nothing,),)
@test Enzyme.autodiff(Reverse, invsin2, Active, Duplicated(x, dx)) == ((nothing,),)
@test dx[1] == -0.4161468365471424
end

Expand Down Expand Up @@ -781,14 +780,14 @@ end
x = 3.0
fd = central_fdm(5, 1)(sin, x)

@test fd ForwardDiff.derivative(sin, x)
@test fd cos(x)
@test fd first(autodiff(Reverse, sin, Active, Active(x)))[1]
@test fd first(autodiff(Forward, sin, Duplicated(x, 1.0)))

x = 0.2 + sin(3.0)
fd = central_fdm(5, 1)(asin, x)

@test fd ForwardDiff.derivative(asin, x)
@test fd 1/sqrt(1-x*x)
@test fd first(autodiff(Reverse, asin, Active, Active(x)))[1]
@test fd first(autodiff(Forward, asin, Duplicated(x, 1.0)))
test_scalar(asin, x)
Expand All @@ -803,14 +802,14 @@ end
x = 3.0
fd = central_fdm(5, 1)(foo, x)

@test fd ForwardDiff.derivative(foo, x)
@test fd cos(x)/sqrt(1-(0.2+sin(x))*(0.2+sin(x)))
@test fd first(autodiff(Reverse, foo, Active, Active(x)))[1]
@test fd first(autodiff(Forward, foo, Duplicated(x, 1.0)))
test_scalar(foo, x)

# Input type shouldn't matter
x = 3
@test fd ForwardDiff.derivative(foo, x)
@test fd cos(x)/sqrt(1-(0.2+sin(x))*(0.2+sin(x)))
@test fd first(autodiff(Reverse, foo, Active, Active(x)))[1]
# They do matter for duplicated, which can't be auto promoted
# @test fd ≈ first(autodiff(Forward, foo, Duplicated(x, 1)))
Expand Down Expand Up @@ -2053,7 +2052,6 @@ end
12.0 0.0]

@test jac == Enzyme.jacobian(Forward, inout, [2.0, 3.0])
@test jac == ForwardDiff.jacobian(inout, [2.0, 3.0])

jac = Enzyme.jacobian(Reverse, inout, [2.0, 3.0], #=n_outs=# Val(3), Val(2))
@test size(jac) == (3, 2)
Expand Down

0 comments on commit fb5b0ec

Please sign in to comment.