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

Array indexing should not allow less than the correct number of indexes #13015

Closed
315234 opened this issue Sep 8, 2015 · 1 comment
Closed

Comments

@315234
Copy link
Contributor

315234 commented Sep 8, 2015

I am working with 4/5/6D arrays and I have found so many bugs caused by supplying 4 indexes to a 5D array, which just silently returns an (essentially random) element.

I think this should be considered a bug as it is very easy to do by mistake and leads to data corruption.

Is this regarded as a feature? What is the reasoning behind it, rather than requiring colons to fill out the missing indexes?

@mbauman
Copy link
Member

mbauman commented Sep 8, 2015

Yes, it is a feature, albeit one that was inherited from other languages, and one whose utility in Julia is decreasing as time goes on. When you omit dimensions, the last index given is considered a linear index over the trailing size of the array. This is generally called linear indexing.

It's an extension of the ability to write for i=1:length(A) and index with i, regardless of the dimensionality of A. But Julia has recently gained more iteration and indexing tools that allow things like for i in eachindex(A) (which can supply very fast indices that index at the full dimensionality) and for i in CartesianRange(size(A)[3:end]) (which explicitly allows for the partial linear indexing behavior you've been accidentally running into). So, yes, there's been talk of removing at least the partial linear indexing behavior that you've been running into — I'm going to close this as a duplicate of #5396.

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

2 participants