JuliaDiff / JuliaDiff/ChainRules.jl

Need adjoint for reinterpret SVector

Open
#606 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

missing rule
Dominant language
Julia
Stars
475
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Minimum working example:

f(x) = sum(sum(reinterpret(SVector{size(x, 1), eltype(x)}, x)))
Zygote.gradient(f, rand(3, 10))
ERROR: Need an adjoint for constructor Base.ReinterpretArray{SVector{3, Float64}, 2, Float64, Matrix{Float64}, false}. Gradient is of type FillArrays.Fill{FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] (::Zygote.Jnew{Base.ReinterpretArray{SVector{3, Float64}, 2, Float64, Matrix{Float64}, false}, Nothing, false})(Δ::FillArrays.Fill{FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}})
   @ Zygote ~/.julia/packages/Zygote/ajuwN/src/lib/lib.jl:323
 [3] (::Zygote.var"#1811#back#235"{Zygote.Jnew{Base.ReinterpretArray{SVector{3, Float64}, 2, Float64, Matrix{Float64}, false}, Nothing, false}})(Δ::FillArrays.Fill{FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}})
   @ Zygote ~/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:67
 [4] Pullback
   @ ./reinterpretarray.jl:47 [inlined]
 [5] (::typeof(∂(reinterpret)))(Δ::FillArrays.Fill{FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}})
   @ Zygote ~/.julia/packages/Zygote/ajuwN/src/compiler/interface2.jl:0
 [6] Pullback
   @ ./REPL[95]:1 [inlined]
 [7] (::Zygote.var"#52#53"{typeof(∂(f))})(Δ::Float64)
   @ Zygote ~/.julia/packages/Zygote/ajuwN/src/compiler/interface.jl:41
 [8] gradient(::Function, ::Matrix{Float64}, ::Vararg{Any})
   @ Zygote ~/.julia/packages/Zygote/ajuwN/src/compiler/interface.jl:76
 [9] top-level scope
   @ REPL[98]:1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied minimum working example and the Base.ReinterpretArray constructor shown in the error. Investigate how reinterpret(SVector{size(x, 1), eltype(x)}, x) is handled during reverse-mode differentiation. Done means the example runs without the missing-adjoint error and produces a gradient for the input matrix.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.