JuliaDiff / JuliaDiff/ForwardDiff.jl
jacobian(f!, y, x) doesn't work if y is complex
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with JacobianConfig and review the dual_buffer_eltype helper described in PR #831, then inspect the extraction work referenced in #830. Done means jacobian(g!, complex_y, x) no longer raises the dual-over-ComplexF64 error and returns the expected derivative representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100