Skip to content

Commit

Permalink
tests for dictionaries (#1330)
Browse files Browse the repository at this point in the history
* tests for issue 717

* test for issue 760

* fix tests

* add .vscode to gitignore

* cleanup
  • Loading branch information
CarloLucibello authored Nov 25, 2022
1 parent d82c0bc commit 81680a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ docs/build
docs/Manifest.toml
Manifest.toml
dev/
.vscode/
18 changes: 18 additions & 0 deletions test/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,21 @@ end
@test gradient(xs -> sum(map(x->x.im^2, xs)), [1+2im,3])[1] == [4im, 0]
@test gradient(xs -> mapreduce(x->x.im^2, +, xs), [1+2im,3])[1] == [4im, 0]
end

@testset "Dict" begin
# issue #717
@test gradient(x -> (() -> x[:y])(), Dict(:y => 0.4)) == (Dict(:y => 1.0),)

ntd = (; data = Dict("x" => rand(2)))
@test gradient(x -> sum(x.data["x"]), ntd)[1] == (; data = Dict("x" => ones(2)))

# issue #760
function f760(x)
d = Dict()
for i in 1:4
push!(d, i=>i^x)
end
sum(values(d))
end
@test gradient(f760, 3)[1] 123.93054835019153
end

0 comments on commit 81680a7

Please sign in to comment.