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

Dot syntax involving CartesianIndex and Tuple #29597

Closed
juliohm opened this issue Oct 11, 2018 · 7 comments
Closed

Dot syntax involving CartesianIndex and Tuple #29597

juliohm opened this issue Oct 11, 2018 · 7 comments

Comments

@juliohm
Copy link
Contributor

juliohm commented Oct 11, 2018

I would like to understand how this operation should be done instead?

start = CartesianIndex(1,2,3)
offset = (1,2,3)
@. start + offset

ERROR: iteration is deliberately unsupported for CartesianIndex. Use I rather than I..., or use Tuple(I)...

It is often the case that we need to offset from a CartesianIndex with a Dims or Tuple object. I could convert the Tuple to a CartesianIndex and avoid the dot syntax, or I could do @. start.I + offset to get access to the underlying Tuple. It is not that elegant though to have to think about Tuple vs. CartesianIndex.

Should the syntax above be allowed?

@KristofferC
Copy link
Member

or I could do @. start.I + offset to get access to the underlying Tuple.

The error message says to use Tuple.

@juliohm
Copy link
Contributor Author

juliohm commented Oct 11, 2018

Thanks, I am fixing the code locally. I guess my question is more on the lines of how useful this restriction with CartesianIndex + Tuple is. I know it educates users, but it also blocks use cases like the one above which seem reasonable to me?

@nalimilan
Copy link
Member

AFAIK the error is there because it would be very slow anyway? Better throw than trap people.

Cc: @timholy

@timholy
Copy link
Member

timholy commented Oct 12, 2018

Not quite sure what to do here. #26227 has the most nuanced thinking I know of on this topic.

@timholy
Copy link
Member

timholy commented Oct 12, 2018

Looking at this again, I should have pointed out the obvious: why do you need to offset with a tuple? Just convert it to a CartesianIndex:

julia> i2 = CartesianIndex(3,5)
CartesianIndex(3, 5)

julia> i1 = CartesianIndex(1,1)
CartesianIndex(1, 1)

julia> i1+i2
CartesianIndex(4, 6)

The case of what we should do about scalar increments is harder to figure out.

@juliohm
Copy link
Contributor Author

juliohm commented Oct 12, 2018 via email

@timholy
Copy link
Member

timholy commented Oct 12, 2018

If you're worried about penalties, instead of asking others just try benchmarking yourself.

As far as methods to do conversions, CartesianIndex is conceptually a scalar and tuple is a container. That makes it unclear what to do: should you generate 3 CartesianIndexes, each with a broadcasted scalar-add? Or add them elementwise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants