# Zygote / ReverseDiff not matching input types

**URL:** https://discourse.julialang.org/t/zygote-reversediff-not-matching-input-types/80838
**Category:** Machine Learning
**Tags:** zygote, reversediff, diffeqflux
**Created:** [May 10, 2022, 7:27pm UTC](https://discourse.julialang.org/t/zygote-reversediff-not-matching-input-types/80838 "2022-05-10T19:27:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![evolbio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evolbio/32/30793_2.png) [@evolbio](https://discourse.julialang.org/u/evolbio)
#### Post date: [May 10, 2022, 7:27pm UTC](https://discourse.julialang.org/t/zygote-reversediff-not-matching-input-types/80838/1 "2022-05-10T19:27:06Z")

</div>

In my code, the line (y ./ k).^h throws a Zygote / ReverseDiff error but works without problem with ForwardDiff. Here, k and h are views of a parameter vector and y is a subset of the variable vector that depends on the parameters, with y obtained by getindex() on the variable vector

* * *

ERROR: MethodError: (::ReverseDiff.ForwardOptimize{typeof(/)})  
(::ReverseDiff.TrackedReal{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ReverseDiff.TrackedArray{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEq.OrdinaryDiffEqTag, Float64}, Float64, 12}}}}, ::ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}}) is ambiguous. Candidates:  
(self::ReverseDiff.ForwardOptimize{F})(t::ReverseDiff.TrackedReal{V, D}, x::Real) where {F, V, D} in ReverseDiff at /opt/julia/packages/ReverseDiff/Z4pL0/src/macros.jl:121  
(self::ReverseDiff.ForwardOptimize{F})(x::Real, t::ReverseDiff.TrackedReal{V, D}) where {F, V, D} in ReverseDiff at /opt/julia/packages/ReverseDiff/Z4pL0/src/macros.jl:109  
Possible fix, define  
(::ReverseDiff.ForwardOptimize{F})(::ReverseDiff.TrackedReal{V, D}, ::ReverseDiff.TrackedReal{V, D}) where {F, V, D, V, D}

* * *

I can see in ReverseDiff/Z4pL0/src/macros.jl what candidate macros might look like but I am not sure how to fix the problem. Is it that TrackedReal has three parameters and so does not match the two-parameter types in the macro:  
(self::ForwardOptimize{F})(a::TrackedReal{V1,D}, b::TrackedReal{V2,D}) where {F,V1,V2,D}

I don’t have any experience extending Zygote/ForwardDiff although I vaguely get the idea. Not sure how to create a MWE for this particular problem. Thanks.
