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

no method matching setindex!(::ChainRulesCore.NoTangent, ::Float64, ::Int64) #200

Open
fredrikekre opened this issue Jul 27, 2023 · 2 comments
Labels
bug Something isn't working forward-mode mutation

Comments

@fredrikekre
Copy link

fredrikekre commented Jul 27, 2023

Simple example of taking the jacobian of the identity function, but the identity function allocates a new vector and assigns by iteration:

function identity_loop(x)
    y = similar(x)
    for i in eachindex(x, y)
        y[i] = x[i]
    end
    return y
end
julia> AD.jacobian(Diffractor.DiffractorForwardBackend(), identity_loop, rand(2))
ERROR: MethodError: no method matching setindex!(::ChainRulesCore.NoTangent, ::Float64, ::Int64)
Stacktrace:
  [1] frule(::Tuple{…}, ::typeof(setindex!), x::Vector{…}, v::Float64, inds::Int64)
    @ ChainRules ~/.julia/packages/ChainRules/9sNmB/src/rulesets/Base/indexing.jl:215
  [2] (::Diffractor.∂☆internal{1})(::ZeroBundle{1, typeof(setindex!)}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/stage1/forward.jl:119
  [3] (::Diffractor.∂☆{1})(::ZeroBundle{1, typeof(setindex!)}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/stage1/forward.jl:160
  [4] identity_loop
    @ Diffractor ./REPL[11]:4 [inlined]
  [5] (::Diffractor.∂☆recurse{})(::ZeroBundle{…}, ::Diffractor.TangentBundle{…})
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/stage1/recurse_fwd.jl:0
  [6] (::Diffractor.∂☆internal{1})(::ZeroBundle{1, typeof(identity_loop)}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/stage1/forward.jl:121
  [7] (::Diffractor.∂☆{1})(::ZeroBundle{1, typeof(identity_loop)}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/stage1/forward.jl:160
  [8] (::Diffractor.var"#pushforward#359")(vs::Any)
    @ Diffractor ~/.julia/packages/Diffractor/QyO8B/src/AbstractDifferentiation.jl:13 [inlined]
  [9] (::Diffractor.var"#358#362")(cols::Any)
    @ Diffractor ~/.julia/packages/AbstractDifferentiation/eEkWP/src/AbstractDifferentiation.jl:526 [inlined]
 [10] mapslices(f::Diffractor.var"#358#362"{Diffractor.var"#pushforward#359"{}}, A::Matrix{Float64}; dims::Int64)
    @ Base ./abstractarray.jl:3179
 [11] jacobian(b::Diffractor.DiffractorForwardBackend, f::Function, args::Vector{Float64})
    @ Diffractor ~/.julia/packages/AbstractDifferentiation/eEkWP/src/AbstractDifferentiation.jl:524
@oxinabox
Copy link
Member

So what is going wrong is we should be creating the tangent for the array as a similar array, but we are instead creating it as a NoTangent.
So we need to fix that.

@oxinabox oxinabox added bug Something isn't working forward-mode mutation labels Jul 27, 2023
@bvdmitri
Copy link

Same error when

AD.hessian(Diffractor.DiffractorForwardBackend(), (x) -> dot(x, ones(2, 2), x), zeros(2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working forward-mode mutation
Projects
None yet
Development

No branches or pull requests

3 participants