Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix version testing mishap #1142

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
Attempt to fix version testing mishap
wsmoses committed Nov 9, 2023
commit c36c812e186e8e25259f9d038d9110aa05f4d51e
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 11 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ using GPUCompiler
using Enzyme
using Test
using FiniteDifferences
using ForwardDiff
using Aqua
using Statistics
using LinearAlgebra
@@ -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)
@@ -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

@@ -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)
@@ -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)))
@@ -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)