Skip to content

Commit

Permalink
WIP: Remove *(Diagonal, Woodbury) (#19)
Browse files Browse the repository at this point in the history
* Remove diagonal *

* Bump version. Bump PDMats

* Add constructor test. Clear whitespace

* Delete irrelevant tests
  • Loading branch information
AlexRobson authored Jul 28, 2021
1 parent 5879fe4 commit 11955cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PDMatsExtras"
uuid = "2c7acb1b-7338-470f-b38f-951d2bcb9193"
authors = ["Invenia Technical Computing"]
version = "2.5.0"
version = "2.5.1"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -14,7 +14,7 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
ChainRulesCore = "0.9.17, 0.10"
Distributions = "0.23, 0.24"
FiniteDifferences = "0.11, 0.12"
PDMats = "0.9, 0.10"
PDMats = "0.9, 0.10, 0.11"
Zygote = "0.5.5"
julia = "1"

Expand Down
14 changes: 3 additions & 11 deletions src/woodbury_pd_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function WoodburyPDMat(
return WoodburyPDMat(A, Diagonal(D), Diagonal(S))
end

WoodburyPDMat{T, TA, TD, TS}(vals...) where {T, TA, TD, TS} = WoodburyPDMat(vals...)

PDMats.dim(W::WoodburyPDMat) = size(W.A, 1)

# Convesion method. Primarily useful for testing purposes.
Expand Down Expand Up @@ -88,14 +90,4 @@ end
# NOTE: the parameterisation to scale up the Woodbury matrix is not unique. Here we
# implement one way to scale it.
*(a::WoodburyPDMat, c::Real) = WoodburyPDMat(a.A, a.D * c, a.S * c)
*(c::Real, a::WoodburyPDMat) = a * c
function *(a::WoodburyPDMat, c::Diagonal{T}) where {T<:Real}
isposdef(c) || throw(ArgumentError("c must be positive definite"))
WoodburyPDMat(sqrt(c) * a.A, a.D, a.S * c)
end
*(c::Diagonal{T}, a::WoodburyPDMat) where {T<:Real} = a * c
function *(c1::Diagonal{T}, a::WoodburyPDMat, c2::Diagonal{T}) where {T<:Real}
isposdef(c1) || throw(ArgumentError("c1 must be positive definite"))
isposdef(c2) || throw(ArgumentError("c2 must be positive definite"))
WoodburyPDMat(sqrt(c1) * sqrt(c2) * a.A, a.D, c1 * a.S * c2)
end
*(c::Real, a::WoodburyPDMat) = a * c
22 changes: 4 additions & 18 deletions test/woodbury_pd_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
W = WoodburyPDMat(A, D, S)
W_dense = PDMat(Symmetric(Matrix(W)))

@testset "Valid constructors" begin
@test W == typeof(W)(W.A, W.D, W.S)
end

@testset "invalid constructors error" begin
@test_throws ArgumentError WoodburyPDMat(randn(5, 2), D, S)
@test_throws ArgumentError WoodburyPDMat(randn(4, 3), D, S)
Expand Down Expand Up @@ -44,24 +48,6 @@
@test c * W == W * c
@test c * W_dense c * W atol=1e-6
@test (c * W) isa WoodburyPDMat

c = Diagonal(2.0 * ones(4,))
@test c * W == W * c
@test c * W_dense c * W atol=1e-6
@test (c * W) isa WoodburyPDMat

c1 = Diagonal(2.0 * ones(4,))
c2 = Diagonal(3.0 * ones(4,))
c_neg = Diagonal([1,2,-2,3])

@test c2 * W * c1 == c1 * W * c2
@test c1 * W * c2 c1 * W_dense * c2
@test (c1 * W * c2) isa WoodburyPDMat

@test_throws(ArgumentError, c_neg * W)
@test_throws(ArgumentError, c_neg * W * c2)
@test_throws(ArgumentError, c1 * W * c_neg)

end

@testset "MvNormal logpdf" begin
Expand Down

2 comments on commit 11955cd

@mzgubic
Copy link
Contributor

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

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 v2.5.1 -m "<description of version>" 11955cd8c9f19b01e818aacc1dce0eff1259a179
git push origin v2.5.1

Please sign in to comment.