|
77 | 77 | """
|
78 | 78 | @view A[inds...]
|
79 | 79 |
|
80 |
| -Creates a `SubArray` from an indexing expression. This can only be applied directly to a |
81 |
| -reference expression (e.g. `@view A[1,2:end]`), and should *not* be used as the target of |
82 |
| -an assignment (e.g. `@view(A[1,2:end]) = ...`). See also [`@views`](@ref) |
83 |
| -to switch an entire block of code to use views for slicing. |
| 80 | +Transform the indexing expression `A[inds...]` into the equivalent [`view`](@ref) call. |
| 81 | +
|
| 82 | +This can only be applied directly to a single indexing expression and is particularly |
| 83 | +helpful for expressions that include the special `begin` or `end` indexing syntaxes |
| 84 | +like `A[begin, 2:end-1]` (as those are not supported by the normal [`view`](@ref) |
| 85 | +function). |
| 86 | +
|
| 87 | +Note that `@view` cannot be used as the target of a regular assignment (e.g., |
| 88 | +`@view(A[1, 2:end]) = ...`), nor would the un-decorated |
| 89 | +[indexed assignment](@ref man-indexed-assignment) (`A[1, 2:end] = ...`) |
| 90 | +or broadcasted indexed assignment (`A[1, 2:end] .= ...`) make a copy. It can be useful, |
| 91 | +however, for _updating_ broadcasted assignments like `@view(A[1, 2:end]) .+= 1` |
| 92 | +because this is a simple syntax for `@view(A[1, 2:end]) .= @view(A[1, 2:end]) + 1`, |
| 93 | +and the indexing expression on the right-hand side would otherwise make a |
| 94 | +copy without the `@view`. |
| 95 | +
|
| 96 | +See also [`@views`](@ref) to switch an entire block of code to use views for non-scalar indexing. |
84 | 97 |
|
85 | 98 | !!! compat "Julia 1.5"
|
86 | 99 | Using `begin` in an indexing expression to refer to the first index requires at least
|
|
0 commit comments