# Dispatch question with TrackedArray in Flux

**URL:** <https://discourse.julialang.org/t/dispatch-question-with-trackedarray-in-flux/14229>\
**Category:** General Usage\
**Created:** [August 29, 2018, 8:16am UTC](https://discourse.julialang.org/t/dispatch-question-with-trackedarray-in-flux/14229 "2018-08-29T08:16:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [August 29, 2018, 8:16am UTC](https://discourse.julialang.org/t/dispatch-question-with-trackedarray-in-flux/14229/1 "2018-08-29T08:16:54Z")

</div>

Hi,

I have a following problem. I need to define a function, say `f(a, b)`, where `a` and `b` are matrices. For this function, I want to define a gradient for Flux, therefore if one of those arguments are of type `TrackedArray`, they needs to be forwarded to Flux.Tracked.track(f, a, b).  
Since `TrackedArray` is subtype of `AbstractArray`, i do not know, how to achieve that if none of those arguments are of type `TrackedArray`, the function should be dispatched normally, which if at least one of the is of type `TrackedArray`, it is forwarded to `track`.

I have ended up defining all four functions (in a loop), but I wonder if there is a neat solution. At the moment, I can also thing about using generated function as well.

Thanks for opinions.
