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

Clean up indexing and dispatch #571

Merged
merged 3 commits into from
Dec 21, 2018
Merged

Clean up indexing and dispatch #571

merged 3 commits into from
Dec 21, 2018

Conversation

timholy
Copy link
Member

@timholy timholy commented Dec 19, 2018

Several aspects of indexing were not ideal:

  • getindex(a::StaticArray, inds::Int...) violates the AbstractArray interface
  • non-scalar static indexing of AbstractArrays only worked up to 4 dimensions
  • there were a lot of getindex and setindex! ambiguities

The first commit here fixes all of these problems while also reducing detect_ambiguities(Base, StaticArrays) from 35 pairs to 9. Serious progress on #18 🎆 .

The second is boring but addresses JuliaLang/julia#6383 (comment). A sed script to fix this is

sed -i "s/StaticArray{<:Any/StaticArray{<:Tuple/g" *.jl

if this ever creeps back in.

This should support non-scalar static indexing for any dimensionality
(not just dimensions 1-4). By having fewer `getindex` and `setindex!`
methods it should also substantially reduce the likelihood of
ambiguities with other packages.
@timholy
Copy link
Member Author

timholy commented Dec 19, 2018

CC @mbauman, if he has time to consult about whether my corruption of to_indices is just too evil to be tolerated.

@coveralls
Copy link

coveralls commented Dec 19, 2018

Coverage Status

Coverage decreased (-0.2%) to 66.068% when pulling b3b1eeb on teh/getindex into da4a1ed on master.

@timholy
Copy link
Member Author

timholy commented Dec 19, 2018

Hmm, looks like we never tested v[1,1] when v is an SVector, and the above broke that. Given the vector methods, it seems easiest to go back to the old getindex(a, i::Int...). Bummer. The 3rd commit implements this "reversion" and also tests the problematic case.

Also, it looks like the 2nd commit got rid of a couple more ambiguities, so now we're down to 7. The third commit fortunately did not introduce new ambiguities.

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

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

A net negative number of lines and less ambiguities? What's not to like!

I say we go with it, though I can't comment on the evilness (or lack thereof) of what you've done with to_indices :-)

@c42f c42f mentioned this pull request Dec 21, 2018
@c42f
Copy link
Member

c42f commented Dec 21, 2018

I've rerun CI to check whether this interacts with #569. Looks like it's going to be fine across the board, so I'm inclined just to merge this and get the release out.

@timholy
Copy link
Member Author

timholy commented Dec 21, 2018

TBH I fear the indexing tests are a bit on the thin side, so messing with the indexing rules is a bit scarier than I initially realized. Especially since there are close to 150 packages in JuliaRegistries/General that depend on this one.

So, I locally merged this and #572. I'm running tests on all my installed packages that depend on StaticArrays (only 14 packages, though). I'll let you know how it goes.

@timholy
Copy link
Member Author

timholy commented Dec 21, 2018

OK, I think this is fine.

@timholy timholy merged commit 4adc061 into master Dec 21, 2018
@timholy timholy deleted the teh/getindex branch December 21, 2018 13:35
@c42f
Copy link
Member

c42f commented Dec 21, 2018

Great, I think I'll tag and release then.

@c42f
Copy link
Member

c42f commented Dec 21, 2018

Ok, I see you've already done so, thanks!

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