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

Add size(::LinearIndices) method #25541

Merged
merged 1 commit into from
Jan 13, 2018
Merged

Add size(::LinearIndices) method #25541

merged 1 commit into from
Jan 13, 2018

Conversation

nalimilan
Copy link
Member

@nalimilan nalimilan commented Jan 13, 2018

Fixes indexing LinearIndices with an array. This is useful in particular to convert cartesian indices that find now returns to linear indices.

Fixes indexing LinearIndices with an array. This is useful in particular
to convert cartesian indices that find() now returns to linear indices.
@@ -418,6 +418,7 @@ module IteratorsMD
# AbstractArray implementation
Base.IndexStyle(::Type{LinearIndices{N,R}}) where {N,R} = IndexCartesian()
Base.axes(iter::LinearIndices{N,R}) where {N,R} = iter.indices
Base.size(iter::LinearIndices{N,R}) where {N,R} = length.(iter.indices)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present we have the recommendation to not implement size for arrays that use non-1 indexing, and so perhaps you should restrict this to OneTo indices. But as part of #24899 (which I will tackle once we stop making breaking changes) that restriction will go away, and I for one do not object if you just keep this the way it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. As you want, you're the expert.

@nalimilan nalimilan merged commit f27f4b8 into master Jan 13, 2018
@nalimilan nalimilan deleted the nl/linearindices branch January 13, 2018 18:09
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

Successfully merging this pull request may close these issues.

2 participants