Skip to content

Commit

Permalink
Simplify kron(::PDiagMat, ::PDiagMat) (#164)
Browse files Browse the repository at this point in the history
* Simplify `kron(::PDiagMat, ::PDiagMat)`

* Update Project.toml

* Add test with StaticArrays
  • Loading branch information
devmotion authored Jun 18, 2022
1 parent da9fe95 commit 8d88c15
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PDMats"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.12"
version = "0.11.13"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion src/pdiagmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function /(x::AbstractVecOrMat, a::PDiagMat)
# return matrix for 1-element vectors `x`, consistent with LinearAlgebra
return reshape(x, Val(2)) ./ permutedims(a.diag) # = (a' \ x')'
end
Base.kron(A::PDiagMat, B::PDiagMat) = PDiagMat( vcat([A.diag[i] * B.diag for i in 1:dim(A)]...) )
Base.kron(A::PDiagMat, B::PDiagMat) = PDiagMat(vec(permutedims(A.diag) .* B.diag))

### Algebra

Expand Down
2 changes: 1 addition & 1 deletion test/kron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Test
using LinearAlgebra: LinearAlgebra

function _pd_kron_compare(A::AbstractPDMat, B::AbstractPDMat)
PDAkB_kron = kron(A, B)
PDAkB_kron = @inferred kron(A, B)
PDAkB_dense = PDMat( kron( Matrix(A), Matrix(B) ) )
_pd_compare(PDAkB_kron, PDAkB_dense)
end
Expand Down
1 change: 1 addition & 0 deletions test/specialarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using StaticArrays
# Diagonal matrix
D = PDiagMat(@SVector(rand(4)))
@test D isa PDiagMat{Float64, <:SVector{4, Float64}}
@test @inferred(kron(D, D)) isa PDiagMat{Float64, <:SVector{16, Float64}}

x = @SVector rand(4)
X = @SMatrix rand(10, 4)
Expand Down

2 comments on commit 8d88c15

@devmotion
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/62601

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 v0.11.13 -m "<description of version>" 8d88c15f7c9931038ab4b741fea92f7fc990da4d
git push origin v0.11.13

Please sign in to comment.