Skip to content

Add SOneTo as AbstractUnitRange to represent axes(::StaticArray) #534

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

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

andyferris
Copy link
Member

@andyferris andyferris commented Oct 29, 2018

This has been on the to-do list for 2 years! 🎉

Now axes(::StaticArray) will return a tuple of "static unit ranges / slices". The SOneTo type lives under AbstractUnitRange so it can work properly with Base, and is therefore not a StaticArray subtype.

One interesting side-effect is what happens to collect:

julia> v = SVector(1,2,3)
3-element SArray{Tuple{3},Int64,1,3}:
 1
 2
 3

julia> [x for x in v]
3-element SizedArray{Tuple{3},Int64,1,1}:
 1
 2
 3

This matches the OffsetArrays package... basically if you want to mess with axes your behavior is automatically used by collect, and in particular for offsets (Slices) you kind of need to rely on this to work out properly. I guess we should roll with this for now. If we can get generator/comprehension syntax working fast (constructing SVectors with optimal code) that could be pretty neat.

I believe the benefits of this will eventually be far-reaching. In particular the axes and keys of an array can now be directly used as an indication of it's static-sizedness. This is more-or-less a trait that is already plumbed into many systems (like collect). Hopefully this will make dealing with "wrapped up" types like Diagonal with SVector more natural.

Closes #476

@andyferris andyferris changed the title Add SOneTo as AbstractUnitRange to represent axes(::StaticArray) Add SOneTo as AbstractUnitRange to represent axes(::StaticArray) Oct 29, 2018
@c42f c42f mentioned this pull request Oct 29, 2018
18 tasks
@andyferris
Copy link
Member Author

Ready or not, here it comes...

@andyferris andyferris merged commit db98a1a into master Oct 30, 2018
@c42f c42f added this to the 1.0 milestone Oct 31, 2018
@tkoolen tkoolen deleted the ajf/SOneTo branch November 10, 2018 16:53
@tkoolen tkoolen restored the ajf/SOneTo branch November 10, 2018 16:53
@andreasnoack andreasnoack deleted the ajf/SOneTo branch June 24, 2025 06:06
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