Skip to content

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.
# 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.

3 participants