Skip to content

Commit 5d7d524

Browse files
authored
Generalise last for broadcastVector (#359)
* Generalise last for broadcastVector * Update broadcasttests.jl * v2.3.2
1 parent 97361a4 commit 5d7d524

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "2.3.1"
3+
version = "2.3.2"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/lazybroadcasting.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ Broadcasted(A::SubArray{<:Any,N,<:BroadcastArray}) where N = broadcasted(A)::Bro
8888
axes(A::BroadcastArray) = axes(broadcasted(A))
8989
size(A::BroadcastArray) = map(length, axes(A))
9090

91-
last(A::BroadcastArray) = A.f(last.(A.args)...)
91+
_broadcast_last(a) = a
92+
_broadcast_last(a::AbstractArray) = last(a)
93+
_broadcast_last(a::Ref) = a[]
94+
last(A::BroadcastArray) = A.f(_broadcast_last.(A.args)...)
9295

9396
@propagate_inbounds getindex(A::BroadcastArray{T,N}, kj::Vararg{Int,N}) where {T,N} = convert(T,broadcasted(A)[kj...])::T
9497

test/broadcasttests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module BroadcastTests
22

3-
using LazyArrays, ArrayLayouts, LinearAlgebra, FillArrays, StaticArrays, Tracker, Base64, Test
3+
using LazyArrays, ArrayLayouts, LinearAlgebra, FillArrays, Base64, Test
4+
using StaticArrays, Tracker
45
import LazyArrays: BroadcastLayout, arguments, LazyArrayStyle, sub_materialize
56
import Base: broadcasted
67

@@ -415,6 +416,11 @@ using Infinities
415416
@test transpose(b)[1:5] == exp.((1:5) .+ im)
416417
@test b'[1:5] == exp.((1:5) .- im)
417418
end
419+
420+
@testset "BroadcastVector last" begin
421+
a = BroadcastArray(Base.literal_pow, ^, 1:5, Val(2))
422+
@test last(a) == 25
423+
end
418424
end
419425

420426
end #module

0 commit comments

Comments
 (0)