Skip to content

Commit 0f0d0d9

Browse files
committed
test gradient allocations
1 parent 92a8aea commit 0f0d0d9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

test/AllocationsTest.jl

+10
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F
3737

3838
end
3939

40+
@testset "Test gradient allocations" begin
41+
@testset "size = $(size(x))" for x in (rand(1), rand(DEFAULT_CHUNK_THRESHOLD+1))
42+
y = similar(x)
43+
cfg = ForwardDiff.GradientConfig(nothing, x)
44+
alloc = @allocated ForwardDiff.gradient!(y, prod, x, cfg)
45+
alloc = @allocated ForwardDiff.gradient!(y, prod, x, cfg)
46+
@test alloc == 0
47+
end
48+
end
49+
4050
end

test/GradientTest.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ end
158158

159159
println(" ...testing GPUArray compatibility (via JLArrays)")
160160

161-
@testset "size = $(size(x))" for x in JLArray.([rand(3), rand(13), rand(3,3), rand(13,13), rand(10,10,10)])
161+
@testset "size = $(size(x))" for x in JLArray.([
162+
rand(1),
163+
rand(DEFAULT_CHUNK_THRESHOLD+1),
164+
rand(1,1),
165+
rand(DEFAULT_CHUNK_THRESHOLD+1,DEFAULT_CHUNK_THRESHOLD+1),
166+
rand(1,1,1)
167+
])
162168

163169
@test ForwardDiff.gradient(prod, x) isa typeof(x)
164170

0 commit comments

Comments
 (0)