# How to support \`view\` in Flux.Tracker?

**URL:** <https://discourse.julialang.org/t/how-to-support-view-in-flux-tracker/16711>\
**Category:** General Usage\
**Tags:** flux\
**Created:** [October 23, 2018, 11:02pm UTC](https://discourse.julialang.org/t/how-to-support-view-in-flux-tracker/16711 "2018-10-23T23:02:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [October 23, 2018, 11:02pm UTC](https://discourse.julialang.org/t/how-to-support-view-in-flux-tracker/16711/1 "2018-10-23T23:02:26Z")

</div>

I have a batched gemm and batched tr: [https://github.com/Roger-luo/Batched.jl/blob/master/src/gemm.jl](https://github.com/Roger-luo/Batched.jl/blob/master/src/gemm.jl)

Now I want to implement the gradient as:

```julia
using Flux.Tracker
using Flux.Tracker: TrackedArray, track, @grad, data
using LinearAlgebra
import Batched

Batched.bgemm(A::TrackedArray, B::TrackedArray) = track(Batched.bgemm, A, B)

@grad Batched.bgemm(A, B) = Batched.bgemm(data(A), data(B)), grad -> (Batched.bgemm(data(grad), transpose(data(B))), Batched.bgemm(transpose(data(B)), data(grad)))

Batched.btr(A::TrackedArray) = track(Batched.btr, A)
@grad Batched.btr(X) = Batched.btr(data(X)), grad->(Batched.ScalarIdentity{size(A, 3), size(A, 1)}(grad), )

```

And it works fine for `TrackedArray`, but when I use `view` on a `TrackedArray`, I get a `SubArray` of this `TrackedArray` rather than a `SubArray` of `Array`, and then I can’t use `BLAS.gemm!`

Any idea how can I fix this?

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [October 23, 2018, 11:04pm UTC](https://discourse.julialang.org/t/how-to-support-view-in-flux-tracker/16711/2 "2018-10-23T23:04:12Z")

</div>

Well, one possible solution might be:

define a `gemm!` function which converts those `SubArray` of `TrackedArray` to `SubArray` of `Array`, but is there any more elegant approach?
