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
Changes from 2 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
16 changes: 16 additions & 0 deletions test/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,19 @@ 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),)
@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(f, 3)[1] ≈ 123.93054835019153
CarloLucibello marked this conversation as resolved.
Show resolved Hide resolved
end