From c61fb47be2e9b097f02ab3b2b7c88657b8d35b1b Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 30 Nov 2018 01:17:21 +0100 Subject: [PATCH] Compat annotation for #29890 (broadcasting CartesianIndices). --- base/multidimensional.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 3c353fa649cd75..854034cd9a5667 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -211,6 +211,28 @@ module IteratorsMD CartesianIndex(1, 2) ``` + ## Broadcasting + + `CartesianIndices` support broadcasting arithmetic (+ and -) with a `CartesianIndex`. + + !!! compat "Julia 1.1" + Broadcasting of CartesianIndices requires at least Julia 1.1. + + ```jldoctest + julia> CIs = CartesianIndices((2:3, 5:6)) + 2×2 CartesianIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}}: + CartesianIndex(2, 5) CartesianIndex(2, 6) + CartesianIndex(3, 5) CartesianIndex(3, 6) + + julia> CI = CartesianIndex(3, 4) + CartesianIndex(3, 4) + + julia> CIs .+ CI + 2×2 CartesianIndices{2,Tuple{UnitRange{Int64},UnitRange{Int64}}}: + CartesianIndex(5, 9) CartesianIndex(5, 10) + CartesianIndex(6, 9) CartesianIndex(6, 10) + ``` + For cartesian to linear index conversion, see [`LinearIndices`](@ref). """ struct CartesianIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{CartesianIndex{N},N}