# ANN: TensorSlice.jl → TensorCast.jl

**URL:** <https://discourse.julialang.org/t/ann-tensorslice-jl-tensorcast-jl/19243>\
**Category:** Package Announcements\
**Tags:** package, announcement, broadcast, tensors\
**Created:** [January 3, 2019, 6:12pm UTC](https://discourse.julialang.org/t/ann-tensorslice-jl-tensorcast-jl/19243 "2019-01-03T18:12:36Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [January 24, 2019, 1:55pm UTC](https://discourse.julialang.org/t/ann-tensorslice-jl-tensorcast-jl/19243/5 "2019-01-24T13:55:18Z")

</div>

This package is now registered under the name [TensorCast.jl](https://github.com/mcabbott/TensorCast.jl), because it suffered further scope creep to include arbitrary broadcasting.

You can do things like this, the word `lazy` means it uses LazyArrays.jl to avoid materialising the whole 3-array RHS:

```julia
using Statistics
x = randn(100); m = rand(1:99, 100);

@reduce y[k] := mean(i,j) m[k] * exp(-(x[i]-x[j])^2) lazy

```

And alla [xiaodai’s question](https://discourse.julialang.org/t/most-efficient-way-to-stack-vectors-on-the-fourth-dimension/19867/4), here’s an efficient way to stack 60k matrices, broadcast an operation, and re-slice them into 60 batches of 1000:

```julia
using Flux
imgs = Flux.Data.MNIST.images(); # 60_000 matrixes each 28x28

@cast batches[b][i,j,n] |= 1 - float(imgs[n\b][i,j]) n:1000;

```

The stacking operation uses the optimised `reduce(hcat,...)`, plus appropriate reshaping. Using `|=` instead of `:=` means (by another abuse of notation) that the sliced batches are copied Arrays, not views.

---

_[View the full topic](https://discourse.julialang.org/t/ann-tensorslice-jl-tensorcast-jl/19243)._
