Skip to content

Commit

Permalink
Overload 3-arg * (#266)
Browse files Browse the repository at this point in the history
* Overload 3-arg *

* Update runtests.jl

* Remove `@views` for more reliable coverage
  • Loading branch information
dlfivefifty authored Jun 25, 2023
1 parent 39234a3 commit 655c089
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
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))"))
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)


function *(a::Transpose{T, <:AbstractVector{T}}, b::ZerosVector{T}) where T<:Real
la, lb = length(a), length(b)
if la lb
Expand Down
8 changes: 3 additions & 5 deletions src/oneelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ function _mulonel!(C, A, B::OneElementMatrix, alpha::Number, beta::Number)
if iszero(beta)
C .= zero(eltype(C))
else
@views begin
C[:, 1:B.ind[2]-1] .*= beta
C[:, B.ind[2]+1:end] .*= beta
end
view(C, :, 1:B.ind[2]-1) .*= beta
view(C, :, B.ind[2]+1:size(C,2)) .*= beta
end
y = @view C[:, B.ind[2]]
y = view(C, :, B.ind[2])
__mulonel!(y, A, B, alpha, beta)
C
end
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,21 @@ 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)*Zeros(5) ==
transpose(Zeros(5))*Diagonal(1:5)*(1:5)

@test_throws DimensionMismatch Zeros(6)'*Diagonal(1:5)*Zeros(5)
@test_throws DimensionMismatch Zeros(5)'*Diagonal(1:6)*Zeros(5)
@test_throws DimensionMismatch Zeros(5)'*Diagonal(1:5)*Zeros(6)
end
end

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

2 comments on commit 655c089

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

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 v1.2.1 -m "<description of version>" 655c089f622e3265e39865127fac383cddf96c83
git push origin v1.2.1

Please sign in to comment.