Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.11"
version = "1.12.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
16 changes: 12 additions & 4 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ for MT in (:(AbstractMatrix{T}), :(Transpose{<:Any, <:AbstractMatrix{T}}), :(Adj
:(AbstractTriangular{T}))
@eval *(a::$MT, b::AbstractZerosVector) where {T} = mult_zeros(a, b)
end
*(a::Transpose{<:Any, <:AbstractVector}, b::AbstractZerosMatrix) = transpose(transpose(b) * parent(a))
*(a::Adjoint{<:Any, <:AbstractVector}, b::AbstractZerosMatrix) = adjoint(adjoint(b) * parent(a))
for T in (:AbstractZerosMatrix, :AbstractFillMatrix)
@eval begin
*(a::Transpose{<:Any, <:AbstractVector}, b::$T) = transpose(transpose(b) * parent(a))
*(a::Adjoint{<:Any, <:AbstractVector}, b::$T) = adjoint(adjoint(b) * parent(a))
end
end
*(a::AbstractZerosMatrix, b::AbstractVector) = mult_zeros(a, b)
function *(F::AbstractFillMatrix, v::AbstractVector)
check_matmul_sizes(F, v)
Fill(getindex_value(F) * sum(v), (axes(F,1),))
end

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

for MT in (:AbstractMatrix, :AbstractTriangular, :(Adjoint{<:Any,<:TransposeAbsVec}))
for MT in (:AbstractMatrix, :AbstractTriangular, :(Adjoint{<:Any,<:TransposeAbsVec}), :AbstractFillMatrix)
@eval *(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::$MT) = (b' * a')'
end
# ambiguity
Expand All @@ -332,7 +340,7 @@ function *(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::TransposeAbsVec{<:A
a * b2
end
*(a::AdjointAbsVec{<:Any,<:AbstractZerosVector}, b::AbstractZerosMatrix) = (b' * a')'
for MT in (:AbstractMatrix, :AbstractTriangular, :(Transpose{<:Any,<:AdjointAbsVec}))
for MT in (:AbstractMatrix, :AbstractTriangular, :(Transpose{<:Any,<:AdjointAbsVec}), :AbstractFillMatrix)
@eval *(a::TransposeAbsVec{<:Any,<:AbstractZerosVector}, b::$MT) = transpose(transpose(b) * transpose(a))
end
*(a::TransposeAbsVec{<:Any,<:AbstractZerosVector}, b::AbstractZerosMatrix) = transpose(transpose(b) * transpose(a))
Expand Down
25 changes: 19 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1640,14 +1640,16 @@ end

@test Fill(2,3)*A ≈ Vector(Fill(2,3))*A
@test Fill(2,0)*A ≈ Vector(Fill(2,0))*A
@test Fill(2,3,mA)*A ≈ Matrix(Fill(2,3,mA))*A
@test Fill(2,3,la)*a ≈ Matrix(Fill(2,3,la))*a
@test Fill(2,3,mA)*A ≈ mul!(similar(A, 3,nA), Fill(2,3,mA), A) ≈ Matrix(Fill(2,3,mA))*A
@test Fill(2,3,la)*a ≈ mul!(similar(a, 3), Fill(2,3,la), a) ≈ Matrix(Fill(2,3,la))*a
@test Fill(2,3,la)*a isa Fill
@test Ones(3)*A ≈ Vector(Ones(3))*A
@test Ones(3,mA)*A ≈ Matrix(Ones(3,mA))*A
@test Ones(3,la)*a ≈ Matrix(Ones(3,la))*a
@test Ones(3,mA)*A ≈ mul!(similar(A, 3, nA), Ones(3,mA), A) ≈ Matrix(Ones(3,mA))*A
@test Ones(3,la)*a ≈ mul!(similar(a, 3), Ones(3,la), a) ≈ Matrix(Ones(3,la))*a
@test Ones(3,la)*a isa Fill
@test Zeros(3)*A ≡ Zeros(3,nA)
@test Zeros(3,mA)*A == Zeros(3,nA)
@test Zeros(3,la)*a == Zeros(3)
@test Zeros(3,mA)*A == mul!(similar(A, 3, nA), Zeros(3,mA), A) == Zeros(3,nA)
@test Zeros(3,la)*a == mul!(similar(A, 3), Zeros(3,la), a) == Zeros(3)

@test A*Fill(2,nA) ≈ A*Vector(Fill(2,nA))
@test A*Fill(2,nA,1) ≈ A*Matrix(Fill(2,nA,1))
Expand All @@ -1669,6 +1671,17 @@ end

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

F = Fill(2, mA, 3)
@test transpose(A) * F ≈ transpose(Fill(2, 3, mA) * A)
F = Fill(2, la, 3)
FS = Fill(2, (Base.OneTo(la), SOneTo(3)))
@testset for (adjf, adjT) in ((transpose, Transpose), (adjoint, Adjoint))
@test adjf(a) * F ≈ adjf(Fill(2, 3, la) * a)
@test adjf(a) * F isa adjT{<:Any, <:Fill{<:Any,1}}
@test adjf(a) * FS ≈ adjf(Fill(2, 3, la) * a)
@test axes(adjf(a) * FS, 2) == SOneTo(3)
end

w = zeros(mA)
@test mul!(w, A, Fill(2,nA), true, false) ≈ A * fill(2,nA)
w .= 2
Expand Down