JuliaDiff / JuliaDiff/ReverseDiff.jl

Error when computing derivative of function involving a complex matrix

Open
#116 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
393
Forks
60
Avg merge
18h 24m
Merged PRs (30d)
8

Description

For example consider the following minimal program:

function f4(x)
abs( (Complex[1] * x)[1] )
end

tp = InstructionTape()
at = ReverseDiff.TrackedReal(0.41992711708322633, 0, tp)
ot = f4(at)
ReverseDiff.seed!(ot)
ReverseDiff.reverse_pass!(tp)
println(deriv(at))

TypeError: in TrackedReal, in V, expected V<:Real, got Type{Complex{Float64}}

Stacktrace:
[1] ReverseDiff.TrackedArray(::Array{Complex{Float64},1}, ::Array{Int64,1}, ::Array{ReverseDiff.AbstractInstruction,1}) at /Users/wmoses/.julia/packages/ReverseDiff/qmgw8/src/tracked.jl:86
[2] track(::Array{Complex{Float64},1}, ::Type{Int64}, ::Array{ReverseDiff.AbstractInstruction,1}) at /Users/wmoses/.julia/packages/ReverseDiff/qmgw8/src/tracked.jl:387
[3] broadcast_mul(::Array{Complex,1}, ::TrackedReal{Float64,Int64,Nothing}, ::Type{Int64}) at /Users/wmoses/.julia/packages/ReverseDiff/qmgw8/src/derivatives/elementwise.jl:421
[4] broadcast at /Users/wmoses/.julia/packages/ReverseDiff/qmgw8/src/derivatives/elementwise.jl:343 [inlined]
[5] * at ./arraymath.jl:55 [inlined]
[6] f4(::TrackedReal{Float64,Int64,Nothing}) at ./In[165]:2
[7] top-level scope at In[165]:7

On the other hand the following succeeds:

function f4(x)
abs( (Complex[x])[1] )
end

tp = InstructionTape()
at = ReverseDiff.TrackedReal(0.41992711708322633, 0, tp)
ot = f4(at)
ReverseDiff.seed!(ot)
ReverseDiff.reverse_pass!(tp)
println(deriv(at))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproducer in the issue and inspect the TrackedArray handling in src/tracked.jl, then follow the broadcast_mul path in src/derivatives/elementwise.jl. Compare the failing Complex[1] * x case with the working Complex[x] case; done means the failing example completes without the TypeError and reports its derivative.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.