Skip to content

Vector adjoint within list comprehension not supported #1587

@lf28

Description

@lf28

Minimal Workable Example:

x = [1.0,2,3]
gradient(x) do x
    sum([y for y in x'])
end

I would expect a returned gradient of [1.,1.,1.] but the following error returns ERROR: MethodError: no method matching adjoint(::Tuple{Float64, Zygote.ZBack{ChainRules.var"#identity_pullback#313"}}) The function adjoint exists, but no method is defined for this combination of argument types.

Complete stacktrace is listed below

ERROR: MethodError: no method matching adjoint(::Tuple{Float64, Zygote.ZBack{ChainRules.var"#identity_pullback#313"}})
The function adjoint exists, but no method is defined for this combination of argument types.

Closest candidates are:
adjoint(::IRTools.Inner.CFG)
@ IRTools ~/.julia/packages/IRTools/v0mn8/src/passes/passes.jl:29
adjoint(::Missing)
@ Base missing.jl:101
adjoint(::ChainRulesCore.NotImplemented)
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/Vsbj9/src/tangent_types/notimplemented.jl:65
...

Stacktrace:
[1] (::LinearAlgebra.var"#1#2"{Zygote.var"#676#680"{Zygote.Context{false}, typeof(identity)}})(xs::Float64)
@ LinearAlgebra ~/.julia/juliaup/julia-1.11.7+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/LinearAlgebra/src/adjtrans.jl:401
[2] iterate
@ ./generator.jl:48 [inlined]
[3] _collect
@ ./array.jl:811 [inlined]
[4] collect_similar
@ ./array.jl:720 [inlined]
[5] map
@ ./abstractarray.jl:3371 [inlined]
[6] map
@ ~/.julia/juliaup/julia-1.11.7+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/LinearAlgebra/src/adjtrans.jl:401 [inlined]
[7] ∇map
@ ~/.julia/packages/Zygote/55SqB/src/lib/array.jl:188 [inlined]
[8] _pullback
@ ~/.julia/packages/Zygote/55SqB/src/lib/array.jl:231 [inlined]
[9] #5
@ ./REPL[7]:2 [inlined]
[10] _pullback(ctx::Zygote.Context{false}, f::var"#5#6", args::Vector{Float64})
@ Zygote ~/.julia/packages/Zygote/55SqB/src/compiler/interface2.jl:0
[11] pullback(f::Function, cx::Zygote.Context{false}, args::Vector{Float64})
@ Zygote ~/.julia/packages/Zygote/55SqB/src/compiler/interface.jl:96
[12] pullback
@ ~/.julia/packages/Zygote/55SqB/src/compiler/interface.jl:94 [inlined]
[13] gradient(f::Function, args::Vector{Float64})
@ Zygote ~/.julia/packages/Zygote/55SqB/src/compiler/interface.jl:153
[14] top-level scope
@ REPL[7]:1

I am using the latest version
Julia version: 1.11.7
Zygote version: 0.7.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions