Skip to content

Commit

Permalink
Overload 3-arg *
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Jun 25, 2023
1 parent 39234a3 commit 8a9c9fc
Show file tree
Hide file tree
Showing 3 changed files with 28 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 = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "1.2.0"
version = "1.2.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
17 changes: 17 additions & 0 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ end

*(a::Adjoint{T, <:AbstractMatrix{T}} where T, b::Zeros{<:Any, 1}) = mult_zeros(a, b)

*(a::AdjointAbsVec{<:Any,<:ZerosVector}, D::Diagonal) = (D*a')'
*(a::TransposeAbsVec{<:Any,<:ZerosVector}, D::Diagonal) = transpose(D*transpose(a))
function _triple_zeromul(x, D::Diagonal, y)
if !(length(x) == length(D.diag) == length(y))
throw(DimensionMismatch("x has length $(length(x)), D has size $(size(D)), and y has $(length(y))"))

Check warning on line 280 in src/fillalgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/fillalgebra.jl#L280

Added line #L280 was not covered by tests
end
zero(promote_type(eltype(x), eltype(D), eltype(y)))
end

*(x::AdjointAbsVec{<:Any,<:ZerosVector}, D::Diagonal, y::AbstractVector) = _triple_zeromul(x, D, y)
*(x::TransposeAbsVec{<:Any,<:ZerosVector}, D::Diagonal, y::AbstractVector) = _triple_zeromul(x, D, y)
*(x::AdjointAbsVec, D::Diagonal, y::ZerosVector) = _triple_zeromul(x, D, y)
*(x::TransposeAbsVec, D::Diagonal, y::ZerosVector) = _triple_zeromul(x, D, y)
*(x::AdjointAbsVec{<:Any,<:ZerosVector}, D::Diagonal, y::ZerosVector) = _triple_zeromul(x, D, y)
*(x::TransposeAbsVec{<:Any,<:ZerosVector}, D::Diagonal, y::ZerosVector) = _triple_zeromul(x, D, y)

Check warning on line 290 in src/fillalgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/fillalgebra.jl#L290

Added line #L290 was not covered by tests


function *(a::Transpose{T, <:AbstractVector{T}}, b::ZerosVector{T}) where T<:Real
la, lb = length(a), length(b)
if la lb
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ end

@test transpose([[1,2]]) * Zeros{SVector{2,Int}}(1) 0
@test_broken transpose([[1,2,3]]) * Zeros{SVector{2,Int}}(1)

@testset "Diagonal mul introduced in v1.9" begin
@test Zeros(5)'*Diagonal(1:5) Zeros(5)'
@test transpose(Zeros(5))*Diagonal(1:5) transpose(Zeros(5))
@test Zeros(5)'*Diagonal(1:5)*(1:5) ==
(1:5)'*Diagonal(1:5)*Zeros(5) ==
transpose(1:5)*Diagonal(1:5)*Zeros(5) ==
Zeros(5)'*Diagonal(1:5)*Zeros(5) ==
transpose(Zeros(5))*Diagonal(1:5)*(1:5)
end
end

z1, z2 = Zeros{Float64}(4), Zeros{Int}(4)
Expand Down

0 comments on commit 8a9c9fc

Please sign in to comment.