Skip to content

Commit ceadfc9

Browse files
committed
Support promotion against Base AbstractUnitRanges
It's hard to support all `AbstractUnitRange` types unless one decides the types here should "lose" to all other types. But we can support the two most commonly used types.
1 parent aea5f34 commit ceadfc9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/blockaxis.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Base.convert(::Type{BlockedUnitRange{CS}}, axis::AbstractUnitRange{Int}) where C
8989

9090
Base.unitrange(b::BlockedUnitRange) = first(b):last(b)
9191

92-
92+
Base.promote_rule(::Type{BlockedUnitRange{CS}}, ::Type{UnitRange{Int}}) where CS = UnitRange{Int}
93+
Base.promote_rule(::Type{BlockedUnitRange{CS}}, ::Type{Base.OneTo{Int}}) where CS = UnitRange{Int}
9394

9495
"""
9596
blockaxes(A)

test/test_blockviews.jl

+11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
128128
V = view(A, Block.(2:3))
129129
@test V == 2:6
130130
@test view(V, Block(2)[1:2]) == [4,5]
131+
132+
A3 = mortar(reshape([rand(5, 4, 1), rand(5, 4, 1), rand(5, 4, 1)], 1, 1, 3))
133+
Aodd = A3[:,:,1:2:end]
134+
axs = axes(Aodd)
135+
axsp = promote(axs...)
136+
@test !all(ax -> typeof(ax) === typeof(axs[1]), axs)
137+
@test all(ax -> typeof(ax) === typeof(axsp[1]), axsp)
138+
axs = (axs[1], 1:5)
139+
axsp = promote(axs...)
140+
@test !all(ax -> typeof(ax) === typeof(axs[1]), axs)
141+
@test all(ax -> typeof(ax) === typeof(axsp[1]), axsp)
131142
end
132143

133144
@testset "subarray implements block interface" begin

0 commit comments

Comments
 (0)