Skip to content

jacobian(f!, y, x) doesn't work if y is complex #832

Description

@devmotion

The in-place jacobian counterpart of #818:

julia> g!(y, x) = (y .= cis(x[1]));

julia> ForwardDiff.jacobian(g!, Vector{ComplexF64}(undef, 2), [0.0])
ERROR: ArgumentError: Cannot create a dual over scalar type ComplexF64. If the type behaves as a scalar, define ForwardDiff.can_dual(::Type{ComplexF64}) = true.

JacobianConfig(f!, y, x) leaves the output eltype Y unconstrained and allocates similar(y, Dual{T,Y,N}), so for a complex y it tries to build a dual over ComplexF64. It should buffer as Complex{Dual{T,real(Y),N}}, which is how the package already represents a complex value carrying derivative information.

PR #831 adds a dual_buffer_eltype helper for exactly this, so the config side becomes a one-line change once that lands. The extraction side needs #830.

Activity

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

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