Skip to content

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Jul 23, 2025

Aims to address #1581:

julia> using Zygote

julia> jacobian(vv -> prod(vv[1]), [[1,2,3.], [4,5,6.]])
(Any[0 0],)  # before
(nothing,)  # after

julia> gradient(vv -> prod(vv[1]), [[1,2,3.], [4,5,6.]])  # unchanged
(Union{Nothing, Vector{Float64}}[[6.0, 3.0, 2.0], nothing],)

Also change this failure case, of a function which returns an array of arrays:

julia> jacobian(x -> [x, x./2], [1,2,3.])
ERROR: MethodError: no method matching zero(::Type{Vector{Float64}})

julia> using StaticArrays

julia> jacobian(x -> [x, x./2], SA[1,2,3.])
ERROR: DimensionMismatch: No precise constructor for SVector{3, Float64} found. Length of input was 1.
Stacktrace:
...
  [9] _eyelike(y::Vector{SVector{3, Float64}})
    @ Zygote ~/.julia/packages/Zygote/55SqB/src/lib/grad.jl:204
 [10] withjacobian(f::Function, args::SVector{3, Float64})
    @ Zygote ~/.julia/packages/Zygote/55SqB/src/lib/grad.jl:188

... to have the more obvious error:

julia> jacobian(x -> [x, x./2], [1,2,3.])
ERROR: ArgumentError: jacobian expected a function which returns an array, or a scalar, got Vector{Vector{Float64}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant