Skip to content

Commit c61fb47

Browse files
committed
Compat annotation for #29890 (broadcasting CartesianIndices).
1 parent 9a8def2 commit c61fb47

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

base/multidimensional.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,28 @@ module IteratorsMD
211211
CartesianIndex(1, 2)
212212
```
213213
214+
## Broadcasting
215+
216+
`CartesianIndices` support broadcasting arithmetic (+ and -) with a `CartesianIndex`.
217+
218+
!!! compat "Julia 1.1"
219+
Broadcasting of CartesianIndices requires at least Julia 1.1.
220+
221+
```jldoctest
222+
julia> CIs = CartesianIndices((2:3, 5:6))
223+
2×2 CartesianIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}}:
224+
CartesianIndex(2, 5) CartesianIndex(2, 6)
225+
CartesianIndex(3, 5) CartesianIndex(3, 6)
226+
227+
julia> CI = CartesianIndex(3, 4)
228+
CartesianIndex(3, 4)
229+
230+
julia> CIs .+ CI
231+
2×2 CartesianIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}}:
232+
CartesianIndex(5, 9) CartesianIndex(5, 10)
233+
CartesianIndex(6, 9) CartesianIndex(6, 10)
234+
```
235+
214236
For cartesian to linear index conversion, see [`LinearIndices`](@ref).
215237
"""
216238
struct CartesianIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{CartesianIndex{N},N}

0 commit comments

Comments
 (0)