Skip to content

Commit f303aea

Browse files
Add AllocationsTest.jl
1 parent b4cb1ac commit f303aea

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d"
2828
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2929
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3030
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
31+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3132
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3233

3334
[targets]
34-
test = ["Calculus", "DiffTests", "LinearAlgebra", "SparseArrays", "Test", "InteractiveUtils"]
35+
test = ["Calculus", "DiffTests", "LinearAlgebra", "SparseArrays", "Test", "InteractiveUtils", "BenchmarkTools"]

src/apiutils.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ function seed!(duals::AbstractArray{Dual{T,V,N}}, x, index,
7979
offset = index - 1
8080
seed_inds = 1:chunksize
8181
dual_inds = seed_inds .+ offset
82-
duals[dual_inds] .= Dual{T,V,N}.(view(x, dual_inds), seeds[seed_inds])
82+
duals[dual_inds] .= Dual{T,V,N}.(view(x, dual_inds), getindex.(Ref(seeds), seed_inds))
8383
return duals
8484
end

test/AllocationsTest.jl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module AllocationsTest
2+
3+
using ForwardDiff
4+
using BenchmarkTools
5+
6+
include(joinpath(dirname(@__FILE__), "utils.jl"))
7+
8+
@testset "Test seed! allocations" begin
9+
x = rand(1000)
10+
cfg = ForwardDiff.GradientConfig(nothing, x)
11+
12+
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds))
13+
@test balloc == 0
14+
15+
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds[1]))
16+
@test balloc == 0
17+
18+
index = 1
19+
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $index, $(cfg.seeds))
20+
@test balloc == 0
21+
22+
index = 1
23+
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $index, $(cfg.seeds[1]))
24+
@test balloc == 0
25+
end
26+
27+
end

test/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ println("done (took $t seconds).")
3131
println("Testing miscellaneous functionality...")
3232
t = @elapsed include("MiscTest.jl")
3333
println("done (took $t seconds).")
34+
35+
println("Testing allocations...")
36+
t = @elapsed include("AllocationsTest.jl")
37+
println("done (took $t seconds).")

0 commit comments

Comments
 (0)