Tullio: overwrite existing matrix instead of creating a new matrix?

I can use Tullio to define a matrix multiplication function matmul(A, B) as such:

using Tullio

matmul(A, B) = @tullio C[i, k] := A[i, j] * B[j, k]

I’d like to also define a function matmul!(C, A, B) that stores the result by overwriting C instead of creating a new matrix.

Is this possible with Tullio?

Yes! You just need to replace := with = inside the @tullio macro.

3 Likes

That’s easy! So it would look like this, presumably?

using Tullio

matmul!(C, A, B) = @tullio C[i, k] = A[i, j] * B[j, k]

Yes, that should do the trick.

1 Like

Perfect, thank you!