Skip to content

BUG: getindex(::Dict) #760

@jamblejoe

Description

@jamblejoe

The following code

function f(x)
        d = Dict()

        for i in 1:4
            push!(d, i=>i^x)
        end
        
        sum(values(d))
    end
    
    @show f(3)
    gradient(f, 3)

errors with

MethodError: no method matching getindex(::Dict{Any,Any})
Closest candidates are:
  getindex(::Dict{K,V}, !Matched::Any) where {K, V} at dict.jl:465
  getindex(::AbstractDict, !Matched::Any) at abstractdict.jl:489
  getindex(::AbstractDict, !Matched::Any, !Matched::Any, !Matched::Any...) at abstractdict.jl:499

Stacktrace:
 [1] (::Zygote.var"#back#187"{:vals,Zygote.Context,Dict{Any,Any},Array{Any,1}})(::Array{Union{Nothing, Int64},1}) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\lib\lib.jl:207
 [2] (::Zygote.var"#1743#back#188"{Zygote.var"#back#187"{:vals,Zygote.Context,Dict{Any,Any},Array{Any,1}}})(::Array{Union{Nothing, Int64},1}) at C:\Users\Goran\.julia\packages\ZygoteRules\6nssF\src\adjoint.jl:49
 [3] iterate at .\dict.jl:682 [inlined]
 [4] (::typeof(∂(iterate)))(::Tuple{Int64,Nothing}) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [5] _foldl_impl at .\reduce.jl:60 [inlined]
 [6] (::typeof(∂(_foldl_impl)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [7] foldl_impl at .\reduce.jl:48 [inlined]
 [8] (::typeof(∂(foldl_impl)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [9] mapfoldl_impl at .\reduce.jl:44 [inlined]
 [10] (::typeof(∂(mapfoldl_impl)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [11] #mapfoldl#204 at .\reduce.jl:160 [inlined]
 [12] (::typeof(∂(#mapfoldl#204)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [13] mapfoldl at .\reduce.jl:160 [inlined]
 [14] (::typeof(∂(mapfoldl)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [15] #mapreduce#208 at .\reduce.jl:287 [inlined]
 [16] (::typeof(∂(#mapreduce#208)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [17] mapreduce at .\reduce.jl:287 [inlined]
 [18] (::typeof(∂(mapreduce)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [19] sum at .\reduce.jl:494 [inlined]
 [20] sum at .\reduce.jl:511 [inlined]
 [21] (::typeof(∂(sum)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [22] f at .\In[88]:10 [inlined]
 [23] (::typeof(∂(f)))(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface2.jl:0
 [24] (::Zygote.var"#41#42"{typeof(∂(f))})(::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface.jl:45
 [25] gradient(::Function, ::Int64) at C:\Users\Goran\.julia\packages\Zygote\seGHk\src\compiler\interface.jl:54
 [26] top-level scope at In[88]:14
 [27] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

I assume that this is not intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions