Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CartesianIndexs broadcast like scalars? #38432

Closed
Sleort opened this issue Nov 13, 2020 · 1 comment · Fixed by #47044
Closed

Make CartesianIndexs broadcast like scalars? #38432

Sleort opened this issue Nov 13, 2020 · 1 comment · Fixed by #47044
Labels
broadcast Applying a function over a collection

Comments

@Sleort
Copy link
Contributor

Sleort commented Nov 13, 2020

Following this Discourse discussion, I'd like to propose to make CartesianIndexs broadcast like scalars. That is, since

julia> 1 .+ (2, 3)
(3, 4)

works, so should

julia> CartesianIndex(1,1) .+ (CartesianIndex(2,2), CartesianIndex(3,3))

(which currently errors, but should, in my opinion, result in (CartesianIndex(3, 3), CartesianIndex(4, 4)))

@mbauman
Copy link
Member

mbauman commented Nov 13, 2020

Notably, this works if the collection being broadcast over a CartesianIndices (#29890) — so this is on the path towards greater consistency.

This is as simple as adding a definition like @mcabbott proposed and a few tests:

Broadcast.broadcastable(I::CartesianIndex) = Ref(I)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast Applying a function over a collection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants