# Efficient representation and operations on symmetric zero-diagonal tensors

**URL:** <https://discourse.julialang.org/t/efficient-representation-and-operations-on-symmetric-zero-diagonal-tensors/39751>\
**Category:** Performance\
**Created:** [May 19, 2020, 1:17pm UTC](https://discourse.julialang.org/t/efficient-representation-and-operations-on-symmetric-zero-diagonal-tensors/39751 "2020-05-19T13:17:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hessammehr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hessammehr/32/3847_2.png) [@hessammehr](https://discourse.julialang.org/u/hessammehr)\
**Post date:** [May 19, 2020, 1:17pm UTC](https://discourse.julialang.org/t/efficient-representation-and-operations-on-symmetric-zero-diagonal-tensors/39751/1 "2020-05-19T13:17:56Z")

</div>

I am looking for an efficient way of representing symmetric tensors with all zero diagonals (any combination of two indices, that is). Since these tensors are going to be fairly small, a fair number of entries are going to be zero or duplicates (especially above rank 2), so I have been representing them as vectors of the unique non-zero items. However, manual indexing has become tedious and operations such as multiplication don’t play nicely with reverse mode AD.

I would like to avoid allocations as much as possible since these tensors are used in a tight loop. Just wondered if anyone else had faced a similar problem and whether you’d have any tips to share.
