Skip to content

Commit

Permalink
Support broadcasting ones and test 3-arg diagonal Eye multiplication (#…
Browse files Browse the repository at this point in the history
…116)

* Support broadcasting ones and test 3-arg diagonal Eye multiplication

* v0.12.11

* Update infarrays.jl
  • Loading branch information
dlfivefifty authored Mar 15, 2023
1 parent 2310430 commit d8e3396
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.12.10"
version = "0.12.11"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
38 changes: 38 additions & 0 deletions src/infarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,50 @@ function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,1,
convert(AbstractArray{promote_type(T,V),N}, b)
end

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,2,Tuple{OneToInf{Int},OneTo{Int}}},AbstractArray{V,N}}}) where {N,T,V}
a,b = bc.args
@assert bc.axes == axes(b)
convert(AbstractArray{promote_type(T,V),N}, b)
end

function _onesbroadcast_ifinf(::NTuple{2,OneToInf{Int}}, bc)
a,b = bc.args
convert(AbstractArray{promote_type(eltype(a),eltype(b))}, b)
end
_onesbroadcast_ifinf(_, bc) = BroadcastArray(bc)

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,2,NTuple{2,OneToInf{Int}}},AbstractArray{V,N}}}) where {N,T,V}
a,b = bc.args
_onesbroadcast_ifinf(axes(b), bc)
end



copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,1,Tuple{OneToInf{Int}}},AbstractArray{V,N},Vararg{Any}}}) where {N,T,V} =
broadcast(*, first(bc.args), broadcast(*, tail(bc.args)...))
copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,2,Tuple{OneToInf{Int},OneTo{Int}}},AbstractArray{V,N},Vararg{Any}}}) where {N,T,V} =
broadcast(*, first(bc.args), broadcast(*, tail(bc.args)...))
copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,2,NTuple{2,OneToInf{Int}}},AbstractArray{V,N},Vararg{Any}}}) where {N,T,V} =
broadcast(*, first(bc.args), broadcast(*, tail(bc.args)...))

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{AbstractArray{T,N},Ones{V,1,Tuple{OneToInf{Int}}}}}) where {N,T,V}
a,b = bc.args
@assert bc.axes == axes(a)
convert(AbstractArray{promote_type(T,V),N}, a)
end

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{AbstractArray{T,N},Ones{V,2,Tuple{OneTo{Int},OneToInf{Int}}}}}) where {N,T,V}
a,b = bc.args
@assert bc.axes == axes(a)
convert(AbstractArray{promote_type(T,V),N}, a)
end

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{AbstractArray{T,N},Ones{V,2,Tuple{OneToInf{Int},OneToInf{Int}}}}}) where {N,T,V}
a,b = bc.args
@assert bc.axes == axes(a)
convert(AbstractArray{promote_type(T,V),N}, a)
end

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{AbstractFill{T,1,Tuple{OneToInf{Int}}},AbstractArray{V,N}}}) where {N,T<:Number,V}
a,b = bc.args
@assert bc.axes == axes(b)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1060,4 +1060,13 @@ end
@testset "UpperTriangular Inverse" begin
A = UpperTriangular(Ones(∞,∞))
@test ApplyArray(inv,A)[1:10,1:10] diagm(0 => ones(10), 1 => -ones(9))
end

@testset "3-mul (changed in Julia v1.9)" begin
@test *(Eye(∞),Diagonal(1:∞), Eye(∞)) == broadcast(*, Ones(∞), Diagonal(1:∞), Ones(1,∞)) ==
broadcast(*, Ones(∞), Diagonal(1:∞), Ones(∞,∞)) == broadcast(*, Ones(∞,1), Diagonal(1:∞), Ones(∞,∞)) ==
broadcast(*, Ones(∞,∞), Diagonal(1:∞), Ones(∞,∞)) == Diagonal(1:∞)

@test_throws DimensionMismatch broadcast(*, Ones(∞,2), Diagonal(1:∞))
@test_throws DimensionMismatch broadcast(*, Diagonal(1:∞), Ones(2,∞))
end

2 comments on commit d8e3396

@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/79625

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 v0.12.11 -m "<description of version>" d8e3396f61b932ee78a07df1ac673764815eed56
git push origin v0.12.11

Please sign in to comment.