|
9 | 9 | @inline size(a::StaticArray) = size(typeof(a))
|
10 | 10 | @inline size(a::StaticArray, d::Int) = size(typeof(a), d)
|
11 | 11 |
|
| 12 | +Base.axes(s::StaticArray) = _axes(Size(s)) |
| 13 | +@pure function _axes(::Size{sizes}) where {sizes} |
| 14 | + map(SOneTo, sizes) |
| 15 | +end |
| 16 | + |
| 17 | +function Base.summary(io::IO, a, inds::Tuple{SOneTo, Vararg{SOneTo}}) |
| 18 | + print(io, Base.dims2string(length.(inds)), " ") |
| 19 | + Base.showarg(io, a, true) |
| 20 | +end |
| 21 | + |
12 | 22 | # This seems to confuse Julia a bit in certain circumstances (specifically for trailing 1's)
|
13 | 23 | @inline function Base.isassigned(a::StaticArray, i::Int...)
|
14 | 24 | ii = LinearIndices(size(a))[i...]
|
@@ -51,6 +61,17 @@ similar_type(::Type{A},s::Size{S}) where {A<:AbstractArray,S} = similar_type(A,e
|
51 | 61 |
|
52 | 62 | similar_type(::A,::Type{T},s::Size{S}) where {A<:AbstractArray,T,S} = similar_type(A,T,s)
|
53 | 63 |
|
| 64 | +# We should be able to deal with SOneTo axes |
| 65 | +similar_type(s::SOneTo) = similar_type(typeof(s)) |
| 66 | +similar_type(::Type{SOneTo{n}}) where {n} = similar_type(SOneTo{n}, Int, Size(n)) |
| 67 | + |
| 68 | +similar_type(::A, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar_type(A, eltype(A), shape) |
| 69 | +similar_type(::Type{A}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar_type(A, eltype(A), shape) |
| 70 | + |
| 71 | +similar_type(::A,::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray,T} = similar_type(A, T, Size(last.(shape))) |
| 72 | +similar_type(::Type{A},::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray,T} = similar_type(A, T, Size(last.(shape))) |
| 73 | + |
| 74 | + |
54 | 75 | # Default types
|
55 | 76 | # Generally, use SArray
|
56 | 77 | similar_type(::Type{A},::Type{T},s::Size{S}) where {A<:AbstractArray,T,S} = default_similar_type(T,s,length_val(s))
|
@@ -98,6 +119,17 @@ similar(::Type{A},::Type{T},s::Size{S}) where {A<:AbstractArray,T,S} = mutable_s
|
98 | 119 | similar(::Type{SA},::Type{T},s::Size{S}) where {SA<:SizedArray,T,S} = sizedarray_similar_type(T,s,length_val(s))(undef)
|
99 | 120 | similar(::Type{A},::Type{T},s::Size{S}) where {A<:Array,T,S} = sizedarray_similar_type(T,s,length_val(s))(undef)
|
100 | 121 |
|
| 122 | +# We should be able to deal with SOneTo axes |
| 123 | +similar(::A, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar(A, eltype(A), shape) |
| 124 | +similar(::Type{A}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray} = similar(A, eltype(A), shape) |
| 125 | + |
| 126 | +similar(::A,::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray,T} = similar(A, T, Size(last.(shape))) |
| 127 | +similar(::Type{A},::Type{T}, shape::Tuple{SOneTo, Vararg{SOneTo}}) where {A<:AbstractArray,T} = similar(A, T, Size(last.(shape))) |
| 128 | + |
| 129 | +# Handle mixtures of SOneTo and other ranges (probably should make Base more robust here) |
| 130 | +similar(::Type{A}, shape::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}}) where {A<:AbstractArray} = similar(A, length.(shape)) # Jumps back to 2-argument form in Base |
| 131 | +similar(::Type{A},::Type{T}, shape::Tuple{AbstractUnitRange, Vararg{AbstractUnitRange}}) where {A<:AbstractArray,T} = similar(A, length.(shape)) |
| 132 | + |
101 | 133 |
|
102 | 134 | @inline reshape(a::StaticArray, s::Size) = similar_type(a, s)(Tuple(a))
|
103 | 135 | @inline reshape(a::AbstractArray, s::Size) = _reshape(a, IndexStyle(a), s)
|
|
0 commit comments