# \#tullio

**URL:** https://discourse.julialang.org/tag/tullio/522.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Creating a macro to call @tullio with arbitrary dimensions](https://discourse.julialang.org/t/creating-a-macro-to-call-tullio-with-arbitrary-dimensions/135848)

<div class="topic-metadata">

**Author:** [@nicrummel](https://discourse.julialang.org/u/nicrummel)\
**Replies:** 2\
**Last updated:** [April 20, 2026, 11:21am UTC](https://discourse.julialang.org/t/creating-a-macro-to-call-tullio-with-arbitrary-dimensions/135848 "2026-04-20T11:21:27Z")

</div>

Hello everyone, Custom Macro I am hoping to be able to write a macro that can call @tullio to specify an arbitrary sized linear form. I think this should follow from some easy-ish fix similar to an old thread… but I am …

---

## [Make mutating function more AD-friendly](https://discourse.julialang.org/t/make-mutating-function-more-ad-friendly/133356)

<div class="topic-metadata">

**Author:** [@MrMR](https://discourse.julialang.org/u/MrMR)\
**Replies:** 10\
**Last updated:** [October 23, 2025, 9:52am UTC](https://discourse.julialang.org/t/make-mutating-function-more-ad-friendly/133356 "2025-10-23T09:52:03Z")

</div>

Dear all, since this is my first post, I want to thank you for the help I got in many years I used Julia (I always found the answer to my problems in previous posts!). Diving into the problem: what I need to do is to …

---

## [Understanding Tullio performances](https://discourse.julialang.org/t/understanding-tullio-performances/129760)

<div class="topic-metadata">

**Author:** [@mcp](https://discourse.julialang.org/u/mcp)\
**Replies:** 12\
**Last updated:** [June 10, 2025, 12:25pm UTC](https://discourse.julialang.org/t/understanding-tullio-performances/129760 "2025-06-10T12:25:57Z")

</div>

Hi everyone! I’m new to Julia and I’m trying to translate a JAX code in Julia using Tullio macro that makes the code simple and clean. However, I’m not able to get the same performances even with simple functions. Here…

---

## [Usage of Tullio.jl](https://discourse.julialang.org/t/usage-of-tullio-jl/126908)

<div class="topic-metadata">

**Author:** [@hssn15](https://discourse.julialang.org/u/hssn15)\
**Replies:** 1\
**Last updated:** [March 13, 2025, 3:37pm UTC](https://discourse.julialang.org/t/usage-of-tullio-jl/126908 "2025-03-13T15:37:49Z")

</div>

I have a really big code, that is separated into bunch of functions, modules, and files. I would like to implement Tullio.jl to optimize loops and array operations. Normally I’m using @tullio macro before the loop or ar…

---

## [Indexing array with a matrix and scalar](https://discourse.julialang.org/t/indexing-array-with-a-matrix-and-scalar/116848)

<div class="topic-metadata">

**Author:** [@baptnz](https://discourse.julialang.org/u/baptnz)\
**Replies:** 9\
**Last updated:** [July 10, 2024, 7:33pm UTC](https://discourse.julialang.org/t/indexing-array-with-a-matrix-and-scalar/116848 "2024-07-10T19:33:45Z")

</div>

A bit rusty after a while away from julia… How would I fill a 3D array with N values at positions given as follows: 1st index given as a scalar (from a for loop) the other two indices are provided as vectors I’m u…

---

## [Adding the result of a tensor contraction to a preallocated array](https://discourse.julialang.org/t/adding-the-result-of-a-tensor-contraction-to-a-preallocated-array/110789)

<div class="topic-metadata">

**Author:** [@paulp](https://discourse.julialang.org/u/paulp)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 4:19pm UTC](https://discourse.julialang.org/t/adding-the-result-of-a-tensor-contraction-to-a-preallocated-array/110789 "2024-02-26T16:19:40Z")

</div>

Hi all, I’d like to perform an arbitrary contraction between two tensors and add the result to an existing array, without allocating an additional array. Tullio has the operation that I want, here is a simple example: u…

---

## [Tullio & AxisKeys can dummy variables refer to named keys](https://discourse.julialang.org/t/tullio-axiskeys-can-dummy-variables-refer-to-named-keys/110233)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 0\
**Last updated:** [February 15, 2024, 4:31am UTC](https://discourse.julialang.org/t/tullio-axiskeys-can-dummy-variables-refer-to-named-keys/110233 "2024-02-15T04:31:57Z")

</div>

Is there a more succinct way to do this? ka = KeyedArray( ones(2,2), I=\[:a,:b\], J=\[:x,:y\] ) @tullio x\[i,j\] := ( ka\[i,j\], axiskeys(ka)\[1\]\[i\], axiskeys(ka)\[2\]\[j\]) Something like @tullio x\[i,j\] := ( ka(i,j), i, j ) T…

---

## [Compute pairwise distances (Distances.jl)](https://discourse.julialang.org/t/compute-pairwise-distances-distances-jl/54297)

<div class="topic-metadata">

**Author:** [@bhaveshshrimali](https://discourse.julialang.org/u/bhaveshshrimali)\
**Replies:** 9\
**Last updated:** [February 1, 2024, 2:38pm UTC](https://discourse.julialang.org/t/compute-pairwise-distances-distances-jl/54297 "2024-02-01T14:38:22Z")

</div>

While trying to port some of my code from Python (NumPy + Numba) to Julia, I noticed that the pairwise distance evaluation is at times slightly slower when using Distances.jl. It is a pretty trivial piece of code that I …

---

## [Tullio broadcasting issue](https://discourse.julialang.org/t/tullio-broadcasting-issue/107321)

<div class="topic-metadata">

**Author:** [@swanchristmas](https://discourse.julialang.org/u/swanchristmas)\
**Replies:** 4\
**Last updated:** [December 9, 2023, 11:46am UTC](https://discourse.julialang.org/t/tullio-broadcasting-issue/107321 "2023-12-09T11:46:28Z")

</div>

@tensor tmp1\[m,s,n,p\] := -λ\[l,m,s\]\*ω\[l,k\]\*λ\[k,n,p\] + λ\[l,m,s\]\*g\[l,n\]\*ones(2)\[p\]) @tullio tmp2\[m,s,n,p\] := -λ\[l,m,s\]\*ω\[l,k\]\*λ\[k,n,p\] + λ\[l,m,s\]\*g\[l,n\] tmp1 turns out to be different from tmp2. It seems that @tullio perfo…

---

## [Tullio for general dimensional tensors](https://discourse.julialang.org/t/tullio-for-general-dimensional-tensors/104787)

<div class="topic-metadata">

**Author:** [@J.J.sakurai](https://discourse.julialang.org/u/J.J.sakurai)\
**Replies:** 2\
**Last updated:** [October 10, 2023, 7:27am UTC](https://discourse.julialang.org/t/tullio-for-general-dimensional-tensors/104787 "2023-10-10T07:27:03Z")

</div>

Tullio.jl seems to be super faster. But how can I write tullio code for general dimensional tensors. For example, an outer product of vectors, do we need such a branch as follow? Is there any way to write the following …

---

## [Tullio - missing elements in vectors](https://discourse.julialang.org/t/tullio-missing-elements-in-vectors/104091)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 0\
**Last updated:** [September 21, 2023, 4:44am UTC](https://discourse.julialang.org/t/tullio-missing-elements-in-vectors/104091 "2023-09-21T04:44:03Z")

</div>

Is it possible to do X::Vector{Any}=zeros(2) @tullio X\[i\] = \[1,missing\]\[i\] in one line? something like @tullio X\[i\]::Vector{Any} := \[1,missing\]\[i\] Also, is it possible to apply a custom aggregation function? some…

---

## [Taking the gradient of an einsum](https://discourse.julialang.org/t/taking-the-gradient-of-an-einsum/103003)

<div class="topic-metadata">

**Author:** [@yuvalw](https://discourse.julialang.org/u/yuvalw)\
**Replies:** 4\
**Last updated:** [August 21, 2023, 8:55am UTC](https://discourse.julialang.org/t/taking-the-gradient-of-an-einsum/103003 "2023-08-21T08:55:21Z")

</div>

Hello, I would really appreciate some help optimizing my optimization. What I calculate makes the most sense (to me) as an einsum but I cannot seem to take its gradient properly. What I managed to do instead is iterate o…

---

## [Generate Input for Tullio](https://discourse.julialang.org/t/generate-input-for-tullio/102859)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 1\
**Last updated:** [August 16, 2023, 1:27pm UTC](https://discourse.julialang.org/t/generate-input-for-tullio/102859 "2023-08-16T13:27:48Z")

</div>

I’d like to benchmark my own code for working with N-dimensional arrays. As baseline, Tullio seems to be the fastest, significantly faster than sum. Given the setup using BenchmarkTools using Tullio const M = 3 const …

---

## [ERROR: LoadError: Scalar indexing is disallowed in tullio](https://discourse.julialang.org/t/error-loaderror-scalar-indexing-is-disallowed-in-tullio/101775)

<div class="topic-metadata">

**Author:** [@Nellatur](https://discourse.julialang.org/u/Nellatur)\
**Replies:** 4\
**Last updated:** [July 24, 2023, 3:45am UTC](https://discourse.julialang.org/t/error-loaderror-scalar-indexing-is-disallowed-in-tullio/101775 "2023-07-24T03:45:46Z")

</div>

For the following code using CUDA using Tullio using BenchmarkTools A = rand(500, 500) B = rand(500, 500) A\_d = CUDA.CuArray(A) B\_d = CUDA.CuArray(B) @btime @tullio C\_d\[i,k\] := A\_d\[i,j\] \* B\_d\[j,k\] C = Array(C\_d) I …

---

## [Tullio with pre-computed index broadcasting](https://discourse.julialang.org/t/tullio-with-pre-computed-index-broadcasting/97345)

<div class="topic-metadata">

**Author:** [@ovt](https://discourse.julialang.org/u/ovt)\
**Replies:** 2\
**Last updated:** [April 11, 2023, 1:58pm UTC](https://discourse.julialang.org/t/tullio-with-pre-computed-index-broadcasting/97345 "2023-04-11T13:58:12Z")

</div>

It’s my first time with Tullio, so my problem may look very basic. Here is a minimal example that provides the error "expected integers!" : using Tullio m,r = 5,5 rr = div(r\*(r-1),2) A = rand(m,rr) B = rand(m,r) C = si…

---

## [Matrix Multiplication of a Large Number of Small Matrices](https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531)

<div class="topic-metadata">

**Author:** [@andrewkhardy](https://discourse.julialang.org/u/andrewkhardy)\
**Replies:** 12\
**Last updated:** [February 8, 2023, 7:47pm UTC](https://discourse.julialang.org/t/matrix-multiplication-of-a-large-number-of-small-matrices/93531 "2023-02-08T19:47:04Z")

</div>

Im interested in computing the matrix multiplication of 2x2 matrices, but these are sampled at a very large number of points. Here is my current benchmark using Tullio,TensorCast, LinearAlgebra, StaticArrays function M…

---

## [Oddities with loop with dummy variable in Tullio](https://discourse.julialang.org/t/oddities-with-loop-with-dummy-variable-in-tullio/91484)

<div class="topic-metadata">

**Author:** [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Replies:** 2\
**Last updated:** [December 9, 2022, 6:10pm UTC](https://discourse.julialang.org/t/oddities-with-loop-with-dummy-variable-in-tullio/91484 "2022-12-09T18:10:05Z")

</div>

Hi there I spotred possibly a strange bug using Tullio on CPU. Here is my package status (Julia-1.8.2) \[bdcacae8\] LoopVectorization v0.12.141 \[bc48ee85\] Tullio v0.3.5 And my minimal non-wroking example using LoopVec…

---

## [Matrix product \`M \* transpose(M)\`](https://discourse.julialang.org/t/matrix-product-m-transpose-m/61212)

<div class="topic-metadata">

**Author:** [@stla](https://discourse.julialang.org/u/stla)\
**Replies:** 10\
**Last updated:** [December 8, 2022, 6:02pm UTC](https://discourse.julialang.org/t/matrix-product-m-transpose-m/61212 "2022-12-08T18:02:45Z")

</div>

Hello, Is there a function in Julia to efficiently compute the matrix product M \* transpose(M)? This matrix is symmetric, so there should be a more efficient way than doing M \* transpose(M). In R one can use the tcross…

---

## [Multiplication of vector of matrices and vector of vectors](https://discourse.julialang.org/t/multiplication-of-vector-of-matrices-and-vector-of-vectors/89874)

<div class="topic-metadata">

**Author:** [@dalbandea](https://discourse.julialang.org/u/dalbandea)\
**Replies:** 3\
**Last updated:** [November 7, 2022, 3:59pm UTC](https://discourse.julialang.org/t/multiplication-of-vector-of-matrices-and-vector-of-vectors/89874 "2022-11-07T15:59:50Z")

</div>

I’m trying to optimize a multiplication of a vector of Matrices A of size (L, L, L) and a vector of vectors x of size (L,L), which will result in a vector of vectors c of size (L, L). That is, each c\[i,:\] is the result …

---

## [Fast LogSumExp over 4th dimension](https://discourse.julialang.org/t/fast-logsumexp-over-4th-dimension/64182)

<div class="topic-metadata">

**Author:** [@jroon](https://discourse.julialang.org/u/jroon)\
**Replies:** 36\
**Last updated:** [October 21, 2022, 5:17pm UTC](https://discourse.julialang.org/t/fast-logsumexp-over-4th-dimension/64182 "2022-10-21T17:17:02Z")

</div>

Hi all, I’m rewriting a function from R to Julia that reduces an array across the 4th dimension via LogSumExp, and I’m currently trying to optimise the speed. I’ve made a bit of progress through the Tullio package, but …

---

## [Speeding up my logsumexp function](https://discourse.julialang.org/t/speeding-up-my-logsumexp-function/42380)

<div class="topic-metadata">

**Author:** [@vkv](https://discourse.julialang.org/u/vkv)\
**Replies:** 35\
**Last updated:** [October 21, 2022, 5:14pm UTC](https://discourse.julialang.org/t/speeding-up-my-logsumexp-function/42380 "2022-10-21T17:14:51Z")

</div>

I wrote a logsumexp function based on the code here, that takes matrix as input and applies logsumexp along a dimension in a numerically stable way. function lsexp\_mat(mat, zero1\_mat; dims=1) # To use the function zer…

---

## [GPU performance problem of locally connected layer with Tullio](https://discourse.julialang.org/t/gpu-performance-problem-of-locally-connected-layer-with-tullio/85469)

<div class="topic-metadata">

**Author:** [@Rasmus\_Hoier](https://discourse.julialang.org/u/Rasmus_Hoier)\
**Replies:** 3\
**Last updated:** [August 23, 2022, 8:01am UTC](https://discourse.julialang.org/t/gpu-performance-problem-of-locally-connected-layer-with-tullio/85469 "2022-08-23T08:01:34Z")

</div>

I am using Tullio.jl to implement a locally connected layer, which is like a convolutional layer except there isn’t any weight sharing. I found Tullio very useful for this task, but unfortunately there is a large gap in …

---

## [Symbolics Einstein notation](https://discourse.julialang.org/t/symbolics-einstein-notation/85866)

<div class="topic-metadata">

**Author:** [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Replies:** 1\
**Last updated:** [August 17, 2022, 9:19am UTC](https://discourse.julialang.org/t/symbolics-einstein-notation/85866 "2022-08-17T09:19:41Z")

</div>

How do I do this with the arrayop macro in Symbolics.jl? using Tullio, Symbolics @variables x₀ q = x₀\*rand(4, 4) t = x₀\*rand(4, 4, 4) @tullio r\[a, b, c\] := q\[a, i\]\*t\[i, b, c\] I tried this r = Symbolics.@arrayop (a, …

---

## [Speeding up a sum involving 3 matrices](https://discourse.julialang.org/t/speeding-up-a-sum-involving-3-matrices/85713)

<div class="topic-metadata">

**Author:** [@structural](https://discourse.julialang.org/u/structural)\
**Replies:** 4\
**Last updated:** [August 14, 2022, 10:41pm UTC](https://discourse.julialang.org/t/speeding-up-a-sum-involving-3-matrices/85713 "2022-08-14T22:41:18Z")

</div>

Thanks for your answers. It made a 20x improvement in my overall computation time. May I get your help with another related task? I need to compute a 10,000+ row vector in which the i^{th} row is \\sum\_{jk} x^{}\_{ij}z^{}…

---

## [Tullio without product](https://discourse.julialang.org/t/tullio-without-product/85708)

<div class="topic-metadata">

**Author:** [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Replies:** 1\
**Last updated:** [August 13, 2022, 5:13pm UTC](https://discourse.julialang.org/t/tullio-without-product/85708 "2022-08-13T17:13:26Z")

</div>

How can I replace the \* with a function? @tullio c := a\[i\]\*b\[i\] a is an array of symbolic differential and b is an array of symbolic functions. I would like to get: a\[1\](b\[1\])+a\[2\](b\[2\]) Thank you

---

## [Tullio Order of Operations](https://discourse.julialang.org/t/tullio-order-of-operations/85538)

<div class="topic-metadata">

**Author:** [@andrewkhardy](https://discourse.julialang.org/u/andrewkhardy)\
**Replies:** 5\
**Last updated:** [August 10, 2022, 1:38pm UTC](https://discourse.julialang.org/t/tullio-order-of-operations/85538 "2022-08-10T13:38:06Z")

</div>

I’m attempting to use Tullio to perform a sum over matrices and running into difficulty. I need to take the sum of inverses and instead am taking the inverse of sums. Is there a way to properly write order of operations,…

---

## [Related or linked structures](https://discourse.julialang.org/t/related-or-linked-structures/85463)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 0\
**Last updated:** [August 8, 2022, 7:45am UTC](https://discourse.julialang.org/t/related-or-linked-structures/85463 "2022-08-08T07:45:46Z")

</div>

Is it possible to connect data structures, similar to Primary-Key Foreign-Key connections in a relational database? One way could be to have a type similar to enum that would limit a field to a given set of values. Usi…

---

## [Is there any way to optimize array additions and multiplications with transposes?](https://discourse.julialang.org/t/is-there-any-way-to-optimize-array-additions-and-multiplications-with-transposes/80268)

<div class="topic-metadata">

**Author:** [@Geositta](https://discourse.julialang.org/u/Geositta)\
**Replies:** 27\
**Last updated:** [August 2, 2022, 8:06am UTC](https://discourse.julialang.org/t/is-there-any-way-to-optimize-array-additions-and-multiplications-with-transposes/80268 "2022-08-02T08:06:32Z")

</div>

The question is related to python - Optimizing array additions and multiplications with transposes - Stack Overflow Given A is an array, I want to evaluate sum += p(A) \* factor(p) where p is a permutation/transpose, fa…

---

## [TensorsOperations, lookups and functions](https://discourse.julialang.org/t/tensorsoperations-lookups-and-functions/85140)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 2\
**Last updated:** [August 2, 2022, 6:00am UTC](https://discourse.julialang.org/t/tensorsoperations-lookups-and-functions/85140 "2022-08-02T06:00:17Z")

</div>

is there functionality like TensorOperations that supports functions and named lookups? I have an array of deals. Each specifies a curve, and needs to be valued over many simulated iterations of the curve. I’d like to w…

---

## [Tullio seems two times slower than basic LoopVectorization](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298)

<div class="topic-metadata">

**Author:** [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Replies:** 3\
**Last updated:** [April 10, 2022, 5:44pm UTC](https://discourse.julialang.org/t/tullio-seems-two-times-slower-than-basic-loopvectorization/79298 "2022-04-10T17:44:01Z")

</div>

I wanted to use Tullio to get rid of lots of nested loops in my code and write Einstein notation instead. Code I’m trying to compute a simple sum: elbo\_tullio(G::AbstractMatrix, p::AbstractVector, mu::AbstractVector, v…

[Next page](https://discourse.julialang.org/tag/tullio/522.md?match_all_tags=true&page=1&tags%5B%5D=tullio)
