-
-
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
Indexing with an empty vector "regression" #12271
Comments
No strong preference. Ref https://groups.google.com/forum/?fromgroups=#!topic/julia-users/Z59s12-HEyk |
This enables the use of the multidimensional abstract array indexing fallbacks for all element types. In particular, this fixes #12271: `A[[]]`. It also allows indexing with `A[Any[1,2,3]]`. I think this is a good direction in general, since we simply index through the array and pass along the elements to a scalar indexing method. If the `AbstractArray` subtype doesn't support indexing with those elements, then it'll throw an error there. But I think this starts allowing fancier capabilities in packages, like indexing with an array of Dual numbers.
Similar weird (?) behaviour:
|
This enables the use of the multidimensional abstract array indexing fallbacks for all element types. In particular, this fixes #12271: `A[[]]`. It also allows indexing with `A[Any[1,2,3]]`. I think this is a good direction in general, since we simply index through the array and pass along the elements to a scalar indexing method. If the `AbstractArray` subtype doesn't support indexing with those elements, then it'll throw an error there. But I think this starts allowing fancier capabilities in packages, like indexing with an array of Dual numbers.
@malmaud Should the behaviour I mention above be a separate issue or is it expected? |
@hayd, that behavior is intentional. |
Thanks! |
I'm generally not super jazzed about how many different kinds of indexing we allow into multidimensional arrays. I would prefer it only linear and N-dimensional indexing were allowed. In fact, now that we have generated functions and |
It can be really powerful, but it's also an easy source of mistakes. I'd definitely be interested in trying it out. I think it could even be deprecated nicely, which makes experimenting with it much easier. |
Note that you could still express linear indexing using reshape if you really need it, but not allowing it by default would prevent mistaken usage as well as encourage writing code in a more generic style that will work for non-contiguous arrays. In fact, one could then imagine eliminating the contiguous vs non-contiguous distinction, which would make the array view business much simpler. Are non-contiguous strided arrays closed under slicing with scalars and ranges? |
Now that we have nice iterators I generally dislike linear indexing, but I have the impression that there are still cases where it may be more performant. We still have #9080 to deal with, for example. |
If you don't change dimensionality (i.e., use |
I think there's a lot to be said for only having one strided array type and having that be what is returned by all scalar/range slices, with no copying. We would probably need GC support for interior pointers, but I think we'll need that for strings too, so we may as well do it. For performance, we can always dynamically check whether linear indexing is applicable and do linear indexing if it is. I think the occasional complexity that would add to a few functions would be well worth it for the massive simplification we would get from collapsing arrays, strided arrays and array views into a single type. |
SubArrays pretty much do all that already, except the linear indexing check is done at construction time. |
What were you thinking of, for GC support for interior pointers? |
Prodding a bit more shows that this issue is due to
[]
now being a synonym forAny[]
rather thanNone[]
:@andreasnoack suggests one fix is to relax the typevar restriction in the definition of
Base._checkbounds
. Doing so leads toI'm not sure if this is fixable, or worth fixing even. Thoughts?
The text was updated successfully, but these errors were encountered: