Skip to content

Commit

Permalink
Generalise last for broadcastVector (#359)
Browse files Browse the repository at this point in the history
* Generalise last for broadcastVector

* Update broadcasttests.jl

* v2.3.2
  • Loading branch information
dlfivefifty authored Jan 15, 2025
1 parent 97361a4 commit 5d7d524
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LazyArrays"
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
version = "2.3.1"
version = "2.3.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
5 changes: 4 additions & 1 deletion src/lazybroadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion test/broadcasttests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module BroadcastTests

using LazyArrays, ArrayLayouts, LinearAlgebra, FillArrays, StaticArrays, Tracker, Base64, Test
using LazyArrays, ArrayLayouts, LinearAlgebra, FillArrays, Base64, Test
using StaticArrays, Tracker
import LazyArrays: BroadcastLayout, arguments, LazyArrayStyle, sub_materialize
import Base: broadcasted

Expand Down Expand Up @@ -415,6 +416,11 @@ using Infinities
@test transpose(b)[1:5] == exp.((1:5) .+ im)
@test b'[1:5] == exp.((1:5) .- im)
end

@testset "BroadcastVector last" begin
a = BroadcastArray(Base.literal_pow, ^, 1:5, Val(2))
@test last(a) == 25
end
end

end #module

2 comments on commit 5d7d524

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123030

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.3.2 -m "<description of version>" 5d7d5248a9b1f5492dcea4755aa6a44efa8d0606
git push origin v2.3.2

Please sign in to comment.