CartesianIndices syntax

The key is that @Pier seems to be after peak performance — and reducing all allocations at all costs. Typically you wouldn’t need CartesianIndices or CartesianIndex at all. Just using regular old indexed assignment with a view would be enough.

dest[2:4, [2,5]] = @view src[2:4, [2,5]]

That will work and be reasonably fast… but it’ll allocate a small wrapper for the view and won’t be quite as fast as just writing out the loops manually.

Someone else just asked for this capability a day or two ago: Support CartesianIndices with Arrays and other iterables, not just ranges (alternative?) - #8 by mbauman. I suppose we could keep the specializations for the all-UnitRange case and just allow it to behave like map(CartesianIndex, Iterators.product(...)) in other cases.

1 Like