Skip to content

Commit

Permalink
Add AllocationsTest.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Nov 17, 2020
1 parent b4cb1ac commit f303aea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Calculus", "DiffTests", "LinearAlgebra", "SparseArrays", "Test", "InteractiveUtils"]
test = ["Calculus", "DiffTests", "LinearAlgebra", "SparseArrays", "Test", "InteractiveUtils", "BenchmarkTools"]
2 changes: 1 addition & 1 deletion src/apiutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ function seed!(duals::AbstractArray{Dual{T,V,N}}, x, index,
offset = index - 1
seed_inds = 1:chunksize
dual_inds = seed_inds .+ offset
duals[dual_inds] .= Dual{T,V,N}.(view(x, dual_inds), seeds[seed_inds])
duals[dual_inds] .= Dual{T,V,N}.(view(x, dual_inds), getindex.(Ref(seeds), seed_inds))
return duals
end
27 changes: 27 additions & 0 deletions test/AllocationsTest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module AllocationsTest

using ForwardDiff
using BenchmarkTools

include(joinpath(dirname(@__FILE__), "utils.jl"))

@testset "Test seed! allocations" begin
x = rand(1000)
cfg = ForwardDiff.GradientConfig(nothing, x)

balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds))
@test balloc == 0

balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds[1]))
@test balloc == 0

index = 1
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $index, $(cfg.seeds))
@test balloc == 0

index = 1
balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $index, $(cfg.seeds[1]))
@test balloc == 0
end

end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ println("done (took $t seconds).")
println("Testing miscellaneous functionality...")
t = @elapsed include("MiscTest.jl")
println("done (took $t seconds).")

println("Testing allocations...")
t = @elapsed include("AllocationsTest.jl")
println("done (took $t seconds).")

0 comments on commit f303aea

Please sign in to comment.