Skip to content

Commit 0fad751

Browse files
authored
Add aliasing warning to docs (#204)
* Fix typo in docs * Add aliasing warning to docs
1 parent 68e0eda commit 0fad751

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

docs/src/man/indexnotation.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ detail on this page.
1111

1212
## The `@tensor` macro
1313

14-
The prefered way to specify (a sequence of) tensor operations is by using the `@tensor`
14+
The preferred way to specify (a sequence of) tensor operations is by using the `@tensor`
1515
macro, which accepts an
1616
[index notation](https://en.wikipedia.org/wiki/Abstract_index_notation) format, a.k.a.
1717
[Einstein notation](https://en.wikipedia.org/wiki/Einstein_notation) (and in particular,
@@ -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)