Skip to content

Commit 83f14be

Browse files
committed
Add aliasing warning to docs
1 parent 3fcbb2a commit 83f14be

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/src/man/indexnotation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ tensor expression in the right hand side in an existing tensor `D`, whereas the
3838
operator `:=` results in a new tensor `E` with the correct properties to be created.
3939
Nonetheless, the contents of `D` and `E` will be equal.
4040

41+
!!! warning "Aliasing"
42+
43+
Special care has to be taken when using the in-place `=`, combined with tensors that might
44+
alias or have overlapping memory regions. As `@tensor` assumes it is allowed to change the
45+
order of the operations within its scope, this may lead to unexpected or wrong results.
46+
For example, the result of the following expressions might be different and making use of
47+
this should be considered as undefined behavior:
48+
```julia
49+
@tensor B[:] := L[-1, 1] * A[1, -2, 2] * R[2, -3] + α * A[-1, -2, -3]
50+
@tensor A[:] = L[-1, 1] * A[1, -2, 2] * R[2, -3] + α * A[-1, -2, -3]
51+
```
52+
4153
Following Einstein's summation convention, that contents is computed in a number of steps
4254
involving the three primitive tensor operators. In this particular example, the first step
4355
involves tracing/contracting the 3rd and 5th index of array `A`, the result of which is

0 commit comments

Comments
 (0)