Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for dictionaries #1330

Merged
merged 5 commits into from
Nov 25, 2022
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
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 @@ -804,3 +804,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)))
CarloLucibello marked this conversation as resolved.
Show resolved Hide resolved

# 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