Skip to content

Commit d54e5a0

Browse files
committed
Avoid piracy changing empty args case
1 parent c1eb10b commit d54e5a0

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

ext/LazyArraysBandedMatricesExt.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ isbanded(::AbstractPaddedLayout, A) = true # always treat as banded
428428
const HcatBandedMatrix{T,N} = Hcat{T,NTuple{N,BandedMatrix{T,Matrix{T},OneTo{Int}}}}
429429
const VcatBandedMatrix{T,N} = Vcat{T,2,NTuple{N,BandedMatrix{T,Matrix{T},OneTo{Int}}}}
430430

431+
BroadcastStyle(::Type{HcatBandedMatrix{T,0}}) where {T} = LazyArrayStyle{2}() # This method is needed for e.g. Hcat(), which would otherwise get recognised as a BandedStyle, giving different behaviour before-and-after loading BandedMatrices
431432
BroadcastStyle(::Type{HcatBandedMatrix{T,N}}) where {T,N} = BandedStyle()
432433
BroadcastStyle(::Type{VcatBandedMatrix{T,N}}) where {T,N} = BandedStyle()
433434

test/concattests.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,23 @@ import Base.Broadcast: BroadcastStyle
712712
args = LazyArrays._vcat_sub_arguments(MemoryLayout(V), V, (), 0, 1:3)
713713
@test args == ()
714714
end
715-
end
716715

717-
@testset "BroadcastStyle" begin
718-
args = (1:10, Accumulate(*, 1:10), BroadcastVector(exp, 1:10), BroadcastMatrix(exp, rand(10, 2)), Vcat(Accumulate(*, 1:10)', (1:10)')', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
719-
for i in 1:6
720-
@test @inferred(LazyArrays.tuple_type_broadcastlayout(typeof(args[1:i]))) == Base.Broadcast.combine_styles(args[1:i]...)
716+
@testset "BroadcastStyle" begin
717+
args = (1:10, Accumulate(*, 1:10), BroadcastVector(exp, 1:10), BroadcastMatrix(exp, rand(10, 2)), Vcat(Accumulate(*, 1:10)', (1:10)')', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
718+
for i in 1:6
719+
@test @inferred(LazyArrays.tuple_type_broadcastlayout(typeof(args[1:i]))) == Base.Broadcast.combine_styles(args[1:i]...)
720+
end
721+
@test @inferred(LazyArrays.tuple_type_broadcastlayout(typeof(args))) == Base.Broadcast.combine_styles(args...) == CachedArrayStyle{2}()
722+
@test @inferred(LazyArrays.tuple_type_broadcastlayout(Tuple{})) == Base.Broadcast.Unknown()
723+
@test BroadcastStyle(typeof(Vcat(adjoint.(args)...))) == BroadcastStyle(typeof(Vcat(transpose.(args)...))) == CachedArrayStyle{2}()
724+
@test BroadcastStyle(typeof(Hcat(args...))) == CachedArrayStyle{2}()
725+
726+
@test BroadcastStyle(typeof(Vcat((1:10)'))) == LazyArrayStyle{2}() # make sure we preserve Lazy even without lazy args
727+
@test BroadcastStyle(typeof(Hcat((1:10)'))) == LazyArrayStyle{2}()
728+
729+
@test BroadcastStyle(typeof(Vcat())) == LazyArrayStyle{1}()
730+
@test BroadcastStyle(typeof(Hcat())) == LazyArrayStyle{2}()
721731
end
722-
@test @inferred(LazyArrays.tuple_type_broadcastlayout(typeof(args))) == Base.Broadcast.combine_styles(args...) == CachedArrayStyle{2}()
723-
@test @inferred(LazyArrays.tuple_type_broadcastlayout(Tuple{})) == Base.Broadcast.Unknown()
724-
@test BroadcastStyle(typeof(Vcat(adjoint.(args)...))) == BroadcastStyle(typeof(Vcat(transpose.(args)...))) == CachedArrayStyle{2}()
725-
@test BroadcastStyle(typeof(Hcat(args...))) == CachedArrayStyle{2}()
726-
727-
@test BroadcastStyle(typeof(Vcat((1:10)'))) == LazyArrayStyle{2}() # make sure we preserve Lazy even without lazy args
728-
@test BroadcastStyle(typeof(Hcat((1:10)'))) == LazyArrayStyle{2}()
729-
730-
@test BroadcastStyle(typeof(Vcat())) == LazyArrayStyle{1}()
731-
@test BroadcastStyle(typeof(Hcat())) == LazyArrayStyle{2}()
732732
end
733733

734734
end # module

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ end
1515
# we include this at the top-level, so that other sub-modules may reuse the module instead of having to include the file
1616
include("infinitearrays.jl")
1717

18+
@testset "Avoiding unwanted behaviour from BandedMatrices extension" begin
19+
# This test needs to be included before BandedMatrices is loaded
20+
@test Base.Broadcast.BroadcastStyle(typeof(Hcat())) == LazyArrayStyle{2}()
21+
using BandedMatrices
22+
@test Base.Broadcast.BroadcastStyle(typeof(Hcat())) == LazyArrayStyle{2}()
23+
end
24+
1825
@testset "Lazy MemoryLayout" begin
1926
@testset "ApplyArray" begin
2027
A = [1.0 2; 3 4]

0 commit comments

Comments
 (0)