From 6eaf7d760f8e5a9eda31930250e92fbb68ac496f Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Sun, 12 Jan 2025 21:12:10 +0000 Subject: [PATCH] Generalise last for broadcastVector --- src/lazybroadcasting.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lazybroadcasting.jl b/src/lazybroadcasting.jl index 09b0ab61..afe6bc77 100644 --- a/src/lazybroadcasting.jl +++ b/src/lazybroadcasting.jl @@ -88,7 +88,10 @@ Broadcasted(A::SubArray{<:Any,N,<:BroadcastArray}) where N = broadcasted(A)::Bro axes(A::BroadcastArray) = axes(broadcasted(A)) size(A::BroadcastArray) = map(length, axes(A)) -last(A::BroadcastArray) = A.f(last.(A.args)...) +_broadcast_last(a) = a +_broadcast_last(a::AbstractArray) = last(a) +_broadcast_last(a::Ref) = a[] +last(A::BroadcastArray) = A.f(_broadcast_last.(A.args)...) @propagate_inbounds getindex(A::BroadcastArray{T,N}, kj::Vararg{Int,N}) where {T,N} = convert(T,broadcasted(A)[kj...])::T