ReverseDiff.jl icon indicating copy to clipboard operation
ReverseDiff.jl copied to clipboard

Error when computing derivative of function involving a complex matrix

Open wsmoses opened this issue 5 years ago • 0 comments

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))

wsmoses avatar Jun 08 '19 01:06 wsmoses