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
3 changes: 0 additions & 3 deletions .github/workflows/Downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ jobs:
coverage: true
allow_reresolve: false
force_latest_compatible_version: false
env:
# `julia-downgrade-compat` promotes weakdeps to deps, so extensions always load
DOWNGRADE_TEST: "true"
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v7
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ jobs:
- uses: julia-actions/cache@v3
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v7
with:
Expand Down
4 changes: 0 additions & 4 deletions test/ChainRulesTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module ChainRulesTest

using LinearAlgebra
using ChainRulesCore
using DiffResults
Expand Down Expand Up @@ -283,5 +281,3 @@ module IsolatedModuleForTestingScoping

end # end of SubModule
end # end of IsolatedModuleForTestingScoping

end
4 changes: 0 additions & 4 deletions test/MacrosTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module MacrosTests

using ReverseDiff, ForwardDiff, Test, StaticArrays
using ForwardDiff: Dual, Partials, partials

Expand Down Expand Up @@ -344,5 +342,3 @@ using ReverseDiff: @grad, TrackedReal, TrackedVector, TrackedMatrix, TrackedArra
@test g1 == g2
@test custom_grad_called
end

end # module
4 changes: 0 additions & 4 deletions test/PrecisionTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module PrecisionTests

using ReverseDiff, Test, LinearAlgebra, Statistics

include("utils.jl")
Expand Down Expand Up @@ -53,5 +51,3 @@ for (n, d) in ((1.0e-200, 1.0e-200), (1.0e200, 1.0e200))
@test ReverseDiff.gradient(f, [d]) ≈ [∂] rtol = 8 * eps(Float64)
end
end

end # module
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Expand All @@ -27,6 +28,7 @@ IrrationalConstants = "0.2"
LinearAlgebra = "1"
LogExpFunctions = "1"
NaNMath = "1"
ParallelTestRunner = "2.0.1"
Random = "1"
SpecialFunctions = "2"
StaticArrays = "1.6.4"
Expand Down
4 changes: 0 additions & 4 deletions test/TapeTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module TapeTests

using ReverseDiff, Test
using ReverseDiff: SpecialInstruction, ScalarInstruction, NULL_TAPE

Expand Down Expand Up @@ -62,5 +60,3 @@ for Instr in (SpecialInstruction, ScalarInstruction)
@test length(NULL_TAPE) == 0
@test repr(MIME"text/plain"(), NULL_TAPE) == "0-element InstructionTape"
end

end # module
32 changes: 32 additions & 0 deletions test/ThreadsTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ReverseDiff, Test

# Run on a multithreaded worker, see `test_worker` in runtests.jl
@test Threads.nthreads() > 1

@testset "recording from multiple threads (#218)" begin
function g(x, i)
acc = zero(eltype(x))
for _ in 1:100
acc += (i * x[1] - x[2])^2
end
return acc + sum(abs2, i .* x)
end
function f(x)
s = Vector{Any}(undef, 64)
@sync for i in eachindex(s)
Threads.@spawn s[i] = g(x, i)
end
return sum(s)
end
f_serial(x) = sum(i -> g(x, i), 1:64)

x = [1.0, 2.0]
∇f = ReverseDiff.gradient(f_serial, x)
for _ in 1:20
@test ReverseDiff.gradient(f, x) ≈ ∇f
end

# tape replay
tape = ReverseDiff.compile(ReverseDiff.GradientTape(f, x))
@test ReverseDiff.gradient!(similar(x), tape, x) ≈ ∇f
end
5 changes: 1 addition & 4 deletions test/TrackedTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module TrackedTests

using ReverseDiff, Test
using ReverseDiff: TrackedReal, TrackedArray

Expand Down Expand Up @@ -652,6 +650,7 @@ instr = first(recorded)
@test instr.cache === nothing

for T in (UInt, Int)
local ta_sub, idx, recorded, instr
ta_sub = ta[:, T(1):T(2)]
idx = ReverseDiff.index_iterable(axes(ta), (:, T(1):T(2)))
@test collect(idx) == [(i, j) for i in 1:3, j in 1:2]
Expand Down Expand Up @@ -897,5 +896,3 @@ end
@test occursin(r"^TrackedReal<\w{3}>\(1\.0, 0\.0, ---, ---\)$", repr(TrackedReal(1.0, 0.0)))
ta = TrackedArray([1.0, 2.0], [0.0, 3.0], InstructionTape())
@test occursin(r"^TrackedReal<\w{3}>\(2\.0, 3\.0, \w{3}, 2, \w{3}\)$", repr(ta[2]))

end
4 changes: 0 additions & 4 deletions test/api/ConfigTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module ConfigTests

using ReverseDiff, Test

include(joinpath(dirname(@__FILE__), "../utils.jl"))
Expand Down Expand Up @@ -75,5 +73,3 @@ cfg = HessianConfig(DiffResults.HessianResult(y), x, gtp, jtp)
# These two act weird: work locally but fail in test mode
#@test issimilar(cfg.gradient_config, GradientConfig(track(x, Int), gtp))
#@test issimilar(cfg.jacobian_config, JacobianConfig(y, x, jtp))

end # module
32 changes: 0 additions & 32 deletions test/api/GradientTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module GradientTests

using DiffTests, ForwardDiff, ReverseDiff, StaticArrays, Test, LinearAlgebra

include(joinpath(dirname(@__FILE__), "../utils.jl"))
Expand Down Expand Up @@ -489,33 +487,3 @@ end
# a `Float64` buffer throws instead of zeroing the gradient
@test_throws ArgumentError ReverseDiff.gradient(W -> loss(zeros(3, 5), W, H), W)
end

@testset "recording from multiple threads (#218)" begin
function g(x, i)
acc = zero(eltype(x))
for _ in 1:100
acc += (i * x[1] - x[2])^2
end
return acc + sum(abs2, i .* x)
end
function f(x)
s = Vector{Any}(undef, 64)
@sync for i in eachindex(s)
Threads.@spawn s[i] = g(x, i)
end
return sum(s)
end
f_serial(x) = sum(i -> g(x, i), 1:64)

x = [1.0, 2.0]
∇f = ReverseDiff.gradient(f_serial, x)
for _ in 1:20
@test ReverseDiff.gradient(f, x) ≈ ∇f
end

# tape replay
tape = ReverseDiff.compile(ReverseDiff.GradientTape(f, x))
@test ReverseDiff.gradient!(similar(x), tape, x) ≈ ∇f
end

end # module
4 changes: 0 additions & 4 deletions test/api/HessianTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module HessianTests

using DiffTests, ForwardDiff, ReverseDiff, StaticArrays, Test

include(joinpath(dirname(@__FILE__), "../utils.jl"))
Expand Down Expand Up @@ -130,5 +128,3 @@ f251(x) = sum(abs2, x)
@test DiffResults.hessian(result) == hess
end
end

end # module
55 changes: 0 additions & 55 deletions test/api/JacobianTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module JacobianTests

using DiffTests, ForwardDiff, ReverseDiff, StaticArrays, Test

include(joinpath(dirname(@__FILE__), "../utils.jl"))
Expand Down Expand Up @@ -269,57 +267,6 @@ for f in DiffTests.BINARY_MATRIX_TO_MATRIX_FUNCS
test_binary_jacobian(f, rand(5, 5), rand(5, 5))
end

for f in (DiffTests.ARRAY_TO_ARRAY_FUNCS..., DiffTests.MATRIX_TO_MATRIX_FUNCS...)
test_println("ARRAY_TO_ARRAY_FUNCS + MATRIX_TO_MATRIX_FUNCS", f)

x = rand(5, 5)
test = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(f, y), x)

# without JacobianTape

J = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(f, y), x)
test_approx(J, test)

# with JacobianTape

tp = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(f, y), rand(eltype(x), size(x)))
J = ReverseDiff.jacobian!(tp, x)
test_approx(J, test)
end

for f in DiffTests.BINARY_MATRIX_TO_MATRIX_FUNCS
test_println("BINARY_MATRIX_TO_MATRIX_FUNCS", f)

a, b = rand(5, 5), rand(5, 5)

test_val = f(a, b)
test_a = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(x -> f(x, b), y), a)
test_b = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(x -> f(a, x), y), b)

# without JacobianTape

Ja = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(x -> f(x, b), y), a)
Jb = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(x -> f(a, x), y), b)
test_approx(Ja, test_a)
test_approx(Jb, test_b)

# with JacobianTape

ra = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(x -> f(x, b), y), rand(eltype(a), size(a)))
rb = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(x -> f(a, x), y), rand(eltype(b), size(b)))
Ja = ReverseDiff.jacobian!(ra, a)
Jb = ReverseDiff.jacobian!(rb, b)
test_approx(Ja, test_a)
test_approx(Jb, test_b)

# The below will fail until support for the Jacobian of
# functions with multiple output arrays is implemented

# Ja, Jb = ReverseDiff.jacobian((x, y) -> ReverseDiff.jacobian(f, (x, y)), (a, b))
# test_approx(Ja test_a)
# test_approx(Jb test_b)
end

############################################################################################

f251(x) = x .^ 2
Expand Down Expand Up @@ -348,5 +295,3 @@ end
# an element that is not a number has no single derivative to seed
@test_throws ArgumentError ReverseDiff.jacobian(x -> [x, x], [1.0, 2.0])
end

end # module
54 changes: 54 additions & 0 deletions test/api/NestedJacobianTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using DiffTests, ForwardDiff, ReverseDiff, Test

include("../utils.jl")

for f in (DiffTests.ARRAY_TO_ARRAY_FUNCS..., DiffTests.MATRIX_TO_MATRIX_FUNCS...)
test_println("ARRAY_TO_ARRAY_FUNCS + MATRIX_TO_MATRIX_FUNCS", f)

x = rand(5, 5)
test = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(f, y), x)

# without JacobianTape

J = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(f, y), x)
test_approx(J, test)

# with JacobianTape

tp = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(f, y), rand(eltype(x), size(x)))
J = ReverseDiff.jacobian!(tp, x)
test_approx(J, test)
end

for f in DiffTests.BINARY_MATRIX_TO_MATRIX_FUNCS
test_println("BINARY_MATRIX_TO_MATRIX_FUNCS", f)

a, b = rand(5, 5), rand(5, 5)

test_val = f(a, b)
test_a = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(x -> f(x, b), y), a)
test_b = ForwardDiff.jacobian(y -> ForwardDiff.jacobian(x -> f(a, x), y), b)

# without JacobianTape

Ja = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(x -> f(x, b), y), a)
Jb = ReverseDiff.jacobian(y -> ReverseDiff.jacobian(x -> f(a, x), y), b)
test_approx(Ja, test_a)
test_approx(Jb, test_b)

# with JacobianTape

ra = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(x -> f(x, b), y), rand(eltype(a), size(a)))
rb = ReverseDiff.JacobianTape(y -> ReverseDiff.jacobian(x -> f(a, x), y), rand(eltype(b), size(b)))
Ja = ReverseDiff.jacobian!(ra, a)
Jb = ReverseDiff.jacobian!(rb, b)
test_approx(Ja, test_a)
test_approx(Jb, test_b)

# The below will fail until support for the Jacobian of
# functions with multiple output arrays is implemented

# Ja, Jb = ReverseDiff.jacobian((x, y) -> ReverseDiff.jacobian(f, (x, y)), (a, b))
# test_approx(Ja test_a)
# test_approx(Jb test_b)
end
4 changes: 0 additions & 4 deletions test/compat/CompatTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module CompatTests

using FillArrays, ReverseDiff, Test

@test ReverseDiff.gradient(fill(2.0, 3)) do x
Expand All @@ -9,5 +7,3 @@ end == fill(4.0, 3)
@test ReverseDiff.gradient(fill(2.0, 3)) do x
sum(abs2.(x .- (1:3)))
end == [2, 0, -2]

end
4 changes: 0 additions & 4 deletions test/derivatives/BroadcastTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module BroadcastTests

using ReverseDiff

using ForwardDiff
Expand Down Expand Up @@ -686,5 +684,3 @@ end
@test ReverseDiff.gradient!(tape3, x) == 2 .* x
@test ReverseDiff.gradient!(ReverseDiff.compile(tape3), x) == 2 .* x
end

end # module
5 changes: 5 additions & 0 deletions test/derivatives/ElementwiseBinaryTests1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include("elementwise_utils.jl")

for (M, fsym) in binary_diffrules()[1:2:end]
test_binary(M, fsym)
end
5 changes: 5 additions & 0 deletions test/derivatives/ElementwiseBinaryTests2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include("elementwise_utils.jl")

for (M, fsym) in binary_diffrules()[2:2:end]
test_binary(M, fsym)
end
Loading
Loading