JuliaDiff / JuliaDiff/ForwardDiff.jl
Reinterpret discards information and returns incorrect result
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
using ForwardDiff
E(x) = abs2(x[1])
xf = randn(ComplexF64, 2)
# WRONG
r2c(x) = reinterpret(ComplexF64, x)
c2r(x) = reinterpret(Float64, x)
# # OK
# r2c(x) = x[1:2] + im*x[3:4]
# c2r(x) = vcat(real(x), imag(x))
ForwardDiff.gradient(x -> E(r2c(x)), c2r(x))
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 by running the Julia reproducer in the issue and compare the gradients from reinterpret with the explicitly constructed r2c and c2r functions. Trace how ForwardDiff handles reinterpret and determine how to avoid losing information; done means the reinterpret-based path returns the same correct gradient as the explicit path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100