Skip to content

Commit 5f7fd20

Browse files
committed
fixes and add more tests
1 parent 1d56eaa commit 5f7fd20

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ranges.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ end
187187
end
188188
end
189189

190-
Base.Broadcast.axistype(r::OptionallyStaticUnitRange{StaticInt{1}}) = Base.OneTo(last(r))
191-
192190
"""
193191
SUnitRange(start::Int, stop::Int)
194192
@@ -484,3 +482,15 @@ Returns valid indices for array `x` along each dimension specified in `dim`.
484482
_indices(x, dims::Tuple) = (indices(x, first(dims)), _indices(x, tail(dims))...)
485483
_indices(x, ::Tuple{}) = ()
486484

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

test/ranges.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120

121121
@test @inferred(firstindex(128:static(-1):1)) == 1
122122

123-
@test similar(Matrix{Int}(undef, 2, 3), (static(1):4, Base.OneTo(5))) isa Matrix{Int}
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), Base.OneTo(4))) isa Matrix{Int}
126+
@test similar(Array{Int}, (static(1):(4),)) isa Vector{Int}
124127
end
125128

0 commit comments

Comments
 (0)