Skip to content

Commit 877375f

Browse files
authored
Multiplication between ScalMat and AbstractZeros (#403)
#401
1 parent a854a25 commit 877375f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: ext/FillArraysPDMatsExt.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ module FillArraysPDMatsExt
33
import FillArrays
44
import FillArrays.LinearAlgebra
55
import PDMats
6+
using FillArrays: mult_zeros, AbstractZeros
7+
using PDMats: ScalMat
68

79
function PDMats.AbstractPDMat(a::LinearAlgebra.Diagonal{T,<:FillArrays.AbstractFill{T,1}}) where {T<:Real}
810
dim = size(a, 1)
9-
return PDMats.ScalMat(dim, FillArrays.getindex_value(a.diag))
11+
return ScalMat(dim, FillArrays.getindex_value(a.diag))
1012
end
1113

14+
Base.:*(a::ScalMat, b::AbstractZeros{T, 1} where T) = mult_zeros(a, b)
15+
Base.:*(a::ScalMat, b::AbstractZeros{T, 2} where T) = mult_zeros(a, b)
16+
Base.:*(a::AbstractZeros{T, 2} where T, b::ScalMat) = mult_zeros(a, b) # This is implemented in case ScalMat implements right multiplication
17+
1218
end # module

Diff for: test/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,11 @@ end
29902990
@test a.dim == length(diag)
29912991
@test a.value == first(diag)
29922992
end
2993+
a = ScalMat(4, 1.)
2994+
for zero in (Zeros(4), Zeros(4,4))
2995+
@test a * zero === zero
2996+
end
2997+
@test Zeros(4,4) * a === Zeros(4,4)
29932998
end
29942999

29953000
@testset "isbanded/isdiag" begin

0 commit comments

Comments
 (0)