# Array Contraction, LoopVectorization & AD

**URL:** https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721
**Category:** Performance
**Tags:** zygote, loopvectorization, autodiff
**Created:** [December 17, 2023, 12:12am UTC](https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721 "2023-12-17T00:12:34Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [December 17, 2023, 9:51am UTC](https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721/4 "2023-12-17T09:51:13Z")

</div>

The error might be avoided by `sum(abs2, ...)` instead of `sum`.

Zygote’s rule for `sum` uses FillArrays, which [this PR](https://github.com/FluxML/Zygote.jl/pull/1453) may remove. It’s an optimisation to save a little allocation which causes all kinds of issues (normally in toy problems like this). Here `@tensor` doesn’t understand this type of fake array, see e.g. [this question](https://discourse.julialang.org/t/take-the-automatic-differentiation-with-tensor-contraction/106995/2).

---

_[View the full topic](https://discourse.julialang.org/t/array-contraction-loopvectorization-ad/107721)._
