Skip to content

Commit

Permalink
FillMatrix times vector returns FillVector (#369)
Browse files Browse the repository at this point in the history
* FillMatrix times vector returns FillVector

* Bump version to v1.12.0
  • Loading branch information
jishnub authored Aug 19, 2024
1 parent f0f7618 commit d0988b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 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.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 @@ -1643,14 +1643,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 @@ -1672,6 +1674,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

2 comments on commit d0988b6

@dlfivefifty
Copy link
Member

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/113392

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.12.0 -m "<description of version>" d0988b6e9c8d178f096fbdc8f27aa725c30f30f9
git push origin v1.12.0

Please sign in to comment.