Skip to content

Commit f0e6ca6

Browse files
committed
Propagate CachedArrayStyle for ApplyArray
1 parent b34b2f6 commit f0e6ca6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/lazyapplying.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ end
331331

332332
applybroadcaststyle(::Type{<:AbstractArray{<:Any,N}}, _2) where N = DefaultArrayStyle{N}()
333333
applybroadcaststyle(::Type{<:AbstractArray{<:Any,N}}, ::AbstractLazyLayout) where N = LazyArrayStyle{N}()
334+
applybroadcaststyle(::Type{<:ApplyArray{<:Any,N,<:Any,Args}}, ::AbstractLazyLayout) where {N,Args<:Tuple} = result_style(LazyArrayStyle{N}(), tuple_type_broadcastlayout(Args))
335+
applybroadcaststyle(::Type{<:SubArray{<:Any,<:Any,P}}, lay::AbstractLazyLayout) where {P} = applybroadcaststyle(P, lay)
334336
BroadcastStyle(M::Type{<:ApplyArray}) = applybroadcaststyle(M, MemoryLayout(M))
335337
BroadcastStyle(M::Type{<:SubArray{<:Any,N,<:ApplyArray}}) where N = applybroadcaststyle(M, MemoryLayout(M))
336338

test/applytests.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module ApplyTests
22

3-
using LazyArrays, FillArrays, ArrayLayouts, Test
4-
import LazyArrays: materialize, broadcasted, DefaultApplyStyle, Applied, arguments,
5-
ApplyArray, ApplyMatrix, ApplyVector, LazyArrayApplyStyle, ApplyLayout, call
6-
import ArrayLayouts: StridedLayout
7-
using LinearAlgebra
3+
using LazyArrays, FillArrays, ArrayLayouts, Test
4+
import LazyArrays: materialize, broadcasted, DefaultApplyStyle, Applied, arguments,
5+
ApplyArray, ApplyMatrix, ApplyVector, LazyArrayApplyStyle, ApplyLayout, call,
6+
CachedArrayStyle, CachedArray, LazyArrayStyle
7+
import ArrayLayouts: StridedLayout
8+
import Base.Broadcast: BroadcastStyle
9+
using LinearAlgebra
810

911
@testset "Applying" begin
1012
@testset "Applied" begin
@@ -121,6 +123,13 @@ using LinearAlgebra
121123
end
122124
@test colsupport(M,1) == 1:5
123125
end
126+
127+
@testset "BroadcastStyle with a cached argument" begin
128+
A = ApplyArray(*, rand(10, 2), rand(2, 2))
129+
@test BroadcastStyle(typeof(A)) == BroadcastStyle(typeof(A')) == BroadcastStyle(typeof(view(A, 1:2, 1:2))) == LazyArrayStyle{2}()
130+
A = ApplyArray(*, CachedArray(rand(10, 2)), rand(2, 2))
131+
@test BroadcastStyle(typeof(A)) == BroadcastStyle(typeof(A')) == BroadcastStyle(typeof(view(A, 1:2, 1:2))) == CachedArrayStyle{2}()
132+
end
124133
end # testset
125134

126135
end # module

0 commit comments

Comments
 (0)