Skip to content

Commit d0988b6

Browse files
authored
FillMatrix times vector returns FillVector (#369)
* FillMatrix times vector returns FillVector * Bump version to v1.12.0
1 parent f0f7618 commit d0988b6

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "1.11"
3+
version = "1.12.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/fillalgebra.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,17 @@ for MT in (:(AbstractMatrix{T}), :(Transpose{<:Any, <:AbstractMatrix{T}}), :(Adj
102102
:(AbstractTriangular{T}))
103103
@eval *(a::$MT, b::AbstractZerosVector) where {T} = mult_zeros(a, b)
104104
end
105-
*(a::Transpose{<:Any, <:AbstractVector}, b::AbstractZerosMatrix) = transpose(transpose(b) * parent(a))
106-
*(a::Adjoint{<:Any, <:AbstractVector}, b::AbstractZerosMatrix) = adjoint(adjoint(b) * parent(a))
105+
for T in (:AbstractZerosMatrix, :AbstractFillMatrix)
106+
@eval begin
107+
*(a::Transpose{<:Any, <:AbstractVector}, b::$T) = transpose(transpose(b) * parent(a))
108+
*(a::Adjoint{<:Any, <:AbstractVector}, b::$T) = adjoint(adjoint(b) * parent(a))
109+
end
110+
end
107111
*(a::AbstractZerosMatrix, b::AbstractVector) = mult_zeros(a, b)
112+
function *(F::AbstractFillMatrix, v::AbstractVector)
113+
check_matmul_sizes(F, v)
114+
Fill(getindex_value(F) * sum(v), (axes(F,1),))
115+
end
108116

109117
function lmul_diag(a::Diagonal, b)
110118
size(a,2) == size(b,1) || throw(DimensionMismatch("A has dimensions $(size(a)) but B has dimensions $(size(b))"))
@@ -322,7 +330,7 @@ function _adjvec_mul_zeros(a, b)
322330
return a1 * b[1]
323331
end
324332

325-
for MT in (:AbstractMatrix, :AbstractTriangular, :(Adjoint{<:Any,<:TransposeAbsVec}))
333+
for MT in (:AbstractMatrix, :AbstractTriangular, :(Adjoint{<:Any,<:TransposeAbsVec}), :AbstractFillMatrix)
326334
@eval *(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::$MT) = (b' * a')'
327335
end
328336
# ambiguity
@@ -332,7 +340,7 @@ function *(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::TransposeAbsVec{<:A
332340
a * b2
333341
end
334342
*(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::AbstractZerosMatrix) = (b' * a')'
335-
for MT in (:AbstractMatrix, :AbstractTriangular, :(Transpose{<:Any,<:AdjointAbsVec}))
343+
for MT in (:AbstractMatrix, :AbstractTriangular, :(Transpose{<:Any,<:AdjointAbsVec}), :AbstractFillMatrix)
336344
@eval *(a::TransposeAbsVec{<:Any,<:AbstractZerosVector}, b::$MT) = transpose(transpose(b) * transpose(a))
337345
end
338346
*(a::TransposeAbsVec{<:Any,<:AbstractZerosVector}, b::AbstractZerosMatrix) = transpose(transpose(b) * transpose(a))

test/runtests.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,14 +1643,16 @@ end
16431643

16441644
@test Fill(2,3)*A Vector(Fill(2,3))*A
16451645
@test Fill(2,0)*A Vector(Fill(2,0))*A
1646-
@test Fill(2,3,mA)*A Matrix(Fill(2,3,mA))*A
1647-
@test Fill(2,3,la)*a Matrix(Fill(2,3,la))*a
1646+
@test Fill(2,3,mA)*A mul!(similar(A, 3,nA), Fill(2,3,mA), A) Matrix(Fill(2,3,mA))*A
1647+
@test Fill(2,3,la)*a mul!(similar(a, 3), Fill(2,3,la), a) Matrix(Fill(2,3,la))*a
1648+
@test Fill(2,3,la)*a isa Fill
16481649
@test Ones(3)*A Vector(Ones(3))*A
1649-
@test Ones(3,mA)*A Matrix(Ones(3,mA))*A
1650-
@test Ones(3,la)*a Matrix(Ones(3,la))*a
1650+
@test Ones(3,mA)*A mul!(similar(A, 3, nA), Ones(3,mA), A) Matrix(Ones(3,mA))*A
1651+
@test Ones(3,la)*a mul!(similar(a, 3), Ones(3,la), a) Matrix(Ones(3,la))*a
1652+
@test Ones(3,la)*a isa Fill
16511653
@test Zeros(3)*A Zeros(3,nA)
1652-
@test Zeros(3,mA)*A == Zeros(3,nA)
1653-
@test Zeros(3,la)*a == Zeros(3)
1654+
@test Zeros(3,mA)*A == mul!(similar(A, 3, nA), Zeros(3,mA), A) == Zeros(3,nA)
1655+
@test Zeros(3,la)*a == mul!(similar(A, 3), Zeros(3,la), a) == Zeros(3)
16541656

16551657
@test A*Fill(2,nA) A*Vector(Fill(2,nA))
16561658
@test A*Fill(2,nA,1) A*Matrix(Fill(2,nA,1))
@@ -1672,6 +1674,17 @@ end
16721674

16731675
@test Zeros(la)' * Transpose(Adjoint(a)) == 0.0
16741676

1677+
F = Fill(2, mA, 3)
1678+
@test transpose(A) * F transpose(Fill(2, 3, mA) * A)
1679+
F = Fill(2, la, 3)
1680+
FS = Fill(2, (Base.OneTo(la), SOneTo(3)))
1681+
@testset for (adjf, adjT) in ((transpose, Transpose), (adjoint, Adjoint))
1682+
@test adjf(a) * F adjf(Fill(2, 3, la) * a)
1683+
@test adjf(a) * F isa adjT{<:Any, <:Fill{<:Any,1}}
1684+
@test adjf(a) * FS adjf(Fill(2, 3, la) * a)
1685+
@test axes(adjf(a) * FS, 2) == SOneTo(3)
1686+
end
1687+
16751688
w = zeros(mA)
16761689
@test mul!(w, A, Fill(2,nA), true, false) A * fill(2,nA)
16771690
w .= 2

0 commit comments

Comments
 (0)