-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Shortcut for sub2ind indexing #6339
Comments
A more efficient way to do this would be |
Fair enough. One thing about array comprehensions is that only the most basic arguments will give an Array with the correct type. For the one above I get an Array{Any}. |
I assume you ran the code directly in the REPL prompt? Type inference is much harder there, with global variables; testing within a function normally gives better results (almost surely in this case).
|
It seems to me that this is a special case of broadcast_getindex. I.e. what you write as
I suggested in #2591 to add syntax for this as
but this seems to be the first time in a while that someone has asked for something like this :) |
Ah I forgot that type inference is harder in the REPL. Sorry! I think I will switch to broadcast_getindex. Thanks everyone for the help. |
I frequently find myself using the sub2ind function in my work, so I created a handy shortcut so that
That is the indices of x and y are matched in pairs. The code that allows this is
I think this (or some similar syntax) would be useful to many people, and perhaps could be included in base. Right now this definition raises warnings that it conflicts with SharedArray.
The text was updated successfully, but these errors were encountered: