Skip to content

Commit b2304bd

Browse files
authored
Merge pull request #249 from JuliaArrays/combine_axes
axistype should create OneTo for better similar support
2 parents b2889ed + da610c6 commit b2304bd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "5.0.1"
3+
version = "5.0.2"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/ranges.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,19 @@ Returns valid indices for array `x` along each dimension specified in `dim`.
482482
_indices(x, dims::Tuple) = (indices(x, first(dims)), _indices(x, tail(dims))...)
483483
_indices(x, ::Tuple{}) = ()
484484

485+
function Base.Broadcast.axistype(r::OptionallyStaticUnitRange{StaticInt{1}}, _)
486+
Base.OneTo(last(r))
487+
end
488+
function Base.Broadcast.axistype(_, r::OptionallyStaticUnitRange{StaticInt{1}})
489+
Base.OneTo(last(r))
490+
end
491+
function Base.Broadcast.axistype(r::OptionallyStaticUnitRange{StaticInt{1}}, ::OptionallyStaticUnitRange{StaticInt{1}})
492+
Base.OneTo(last(r))
493+
end
494+
function Base.similar(::Type{<:Array{T}}, axes::Tuple{OptionallyStaticUnitRange{StaticInt{1}},Vararg{Union{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}}}}}) where {T}
495+
Array{T}(undef, map(last, axes))
496+
end
497+
function Base.similar(::Type{<:Array{T}}, axes::Tuple{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}},Vararg{Union{Base.OneTo,OptionallyStaticUnitRange{StaticInt{1}}}}}) where {T}
498+
Array{T}(undef, map(last, axes))
499+
end
500+

test/ranges.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@
118118
@test @inferred(eachindex(static(-7):static(7))) === static(1):static(15)
119119
@test @inferred((static(-7):static(7))[first(eachindex(static(-7):static(7)))]) == -7
120120

121-
@test @inferred(firstindex(128:static(-1):1)) == 1
121+
@test @inferred(firstindex(128:static(-1):1)) == 1
122+
123+
@test identity.(static(1):5) isa Vector{Int}
124+
@test (static(1):5) .+ (1:3)' isa Matrix{Int}
125+
@test similar(Array{Int}, (static(1):(4),)) isa Vector{Int}
126+
@test similar(Array{Int}, (static(1):(4), Base.OneTo(4))) isa Matrix{Int}
127+
@test similar(Array{Int}, (Base.OneTo(4), static(1):(4))) isa Matrix{Int}
122128
end
123129

0 commit comments

Comments
 (0)