From 875959e9a173a6c16e8b3080c95e68738728198a Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Fri, 5 Dec 2025 13:55:38 +0000 Subject: [PATCH 1/3] Introduce resizedata!_layout and resizing for broadcast arrays --- src/cache.jl | 16 ++++++++++++++-- src/padded.jl | 11 ++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/cache.jl b/src/cache.jl index 9cac1810..3e3bcb06 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -226,7 +226,10 @@ end resizedata!(B::CachedArray, mn...) = resizedata!(MemoryLayout(B.data), MemoryLayout(B.array), B, mn...) resizedata!(B::AbstractCachedArray, mn...) = resizedata!(MemoryLayout(B.data), UnknownLayout(), B, mn...) -resizedata!(A, mn...) = A # don't do anything +resizedata!_layout(A, mn...) = A # don't do anything + + +resizedata!(A, mn...) = resizedata!_layout(MemoryLayout(A), A, mn...) function resizedata!(A::AdjOrTrans, m, n) resizedata!(parent(A), n, m) A @@ -615,4 +618,13 @@ CachedArray(data::AbstractMatrix, array::AbstractQ) = CachedArray(data, array, s CachedArray(data::AbstractMatrix{T}, array::AbstractQ{T}, datasize::NTuple{2,Int}) where T = CachedMatrix{T,typeof(data),typeof(array)}(data, array, datasize) -length(A::CachedMatrix{<:T,<:AbstractMatrix{T},<:AbstractQ{T}}) where T = prod(size(A.array)) \ No newline at end of file +length(A::CachedMatrix{<:T,<:AbstractMatrix{T},<:AbstractQ{T}}) where T = prod(size(A.array)) + + + +### +# resizedata! for types +### + + +resizedata!_layout(lay::BroadcastLayout, b, m...) = resizedata!.(arguments(lay, b), m...) diff --git a/src/padded.jl b/src/padded.jl index 5fbf5043..7cec0565 100644 --- a/src/padded.jl +++ b/src/padded.jl @@ -124,16 +124,12 @@ function rowsupport(lay::Union{PaddedColumns{Lay}, PaddedLayout{Lay}}, A, k) whe isempty(k̃) ? convert(typeof(rs), Base.OneTo(0)) : rs end -function _vcat_resizedata!(::Union{AbstractPaddedLayout, DualLayout{<:PaddedRows}}, B, m...) +function resizedata!_layout(::Union{AbstractPaddedLayout, DualLayout{<:PaddedRows}}, B, m...) any(iszero,m) || Base.checkbounds(paddeddata(B), m...) B end -function _vcat_resizedata!(::Union{DualLayout{<:PaddedRows}, AbstractPaddedLayout}, B::Vcat{<:Any, 1}, m) # ambiguity - iszero(m) || Base.checkbounds(paddeddata(B), m) - B -end -function _vcat_resizedata!(_, B::Vcat{<:Any, 1}, n) +function resizedata!_layout(::ApplyLayout{typeof(vcat)}, B::AbstractVector, n) m = n for arg in arguments(B) m ≤ 0 && break @@ -145,9 +141,6 @@ function _vcat_resizedata!(_, B::Vcat{<:Any, 1}, n) B end -_vcat_resizedata!(_, B, m...) = B # by default we can't resize - -resizedata!(B::Vcat, m...) = _vcat_resizedata!(MemoryLayout(B), B, m...) cacheddata(B::Vcat) = Vcat(map(maybe_cacheddata, arguments(B))...) From d71a24eb5732f322a0bcb01053189890bca7f1bd Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Fri, 5 Dec 2025 14:03:08 +0000 Subject: [PATCH 2/3] Update padded.jl --- src/padded.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/padded.jl b/src/padded.jl index 7cec0565..4b542daf 100644 --- a/src/padded.jl +++ b/src/padded.jl @@ -124,11 +124,7 @@ function rowsupport(lay::Union{PaddedColumns{Lay}, PaddedLayout{Lay}}, A, k) whe isempty(k̃) ? convert(typeof(rs), Base.OneTo(0)) : rs end -function resizedata!_layout(::Union{AbstractPaddedLayout, DualLayout{<:PaddedRows}}, B, m...) - any(iszero,m) || Base.checkbounds(paddeddata(B), m...) - B -end - +resizedata!_layout(::Union{AbstractPaddedLayout, DualLayout{<:PaddedRows}}, B, m...) = B function resizedata!_layout(::ApplyLayout{typeof(vcat)}, B::AbstractVector, n) m = n for arg in arguments(B) From 76c9ebf873737fa1dcd9c9abf04aba0d860bf6a7 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Fri, 5 Dec 2025 14:27:21 +0000 Subject: [PATCH 3/3] Update cache.jl --- src/cache.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.jl b/src/cache.jl index 3e3bcb06..ebd49c3c 100644 --- a/src/cache.jl +++ b/src/cache.jl @@ -226,7 +226,7 @@ end resizedata!(B::CachedArray, mn...) = resizedata!(MemoryLayout(B.data), MemoryLayout(B.array), B, mn...) resizedata!(B::AbstractCachedArray, mn...) = resizedata!(MemoryLayout(B.data), UnknownLayout(), B, mn...) -resizedata!_layout(A, mn...) = A # don't do anything +resizedata!_layout(_, A, mn...) = A # don't do anything resizedata!(A, mn...) = resizedata!_layout(MemoryLayout(A), A, mn...)