Skip to content

Commit 11955cd

Browse files
authored
WIP: Remove *(Diagonal, Woodbury) (#19)
* Remove diagonal * * Bump version. Bump PDMats * Add constructor test. Clear whitespace * Delete irrelevant tests
1 parent 5879fe4 commit 11955cd

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PDMatsExtras"
22
uuid = "2c7acb1b-7338-470f-b38f-951d2bcb9193"
33
authors = ["Invenia Technical Computing"]
4-
version = "2.5.0"
4+
version = "2.5.1"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -14,7 +14,7 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
1414
ChainRulesCore = "0.9.17, 0.10"
1515
Distributions = "0.23, 0.24"
1616
FiniteDifferences = "0.11, 0.12"
17-
PDMats = "0.9, 0.10"
17+
PDMats = "0.9, 0.10, 0.11"
1818
Zygote = "0.5.5"
1919
julia = "1"
2020

src/woodbury_pd_mat.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function WoodburyPDMat(
3838
return WoodburyPDMat(A, Diagonal(D), Diagonal(S))
3939
end
4040

41+
WoodburyPDMat{T, TA, TD, TS}(vals...) where {T, TA, TD, TS} = WoodburyPDMat(vals...)
42+
4143
PDMats.dim(W::WoodburyPDMat) = size(W.A, 1)
4244

4345
# Convesion method. Primarily useful for testing purposes.
@@ -88,14 +90,4 @@ end
8890
# NOTE: the parameterisation to scale up the Woodbury matrix is not unique. Here we
8991
# implement one way to scale it.
9092
*(a::WoodburyPDMat, c::Real) = WoodburyPDMat(a.A, a.D * c, a.S * c)
91-
*(c::Real, a::WoodburyPDMat) = a * c
92-
function *(a::WoodburyPDMat, c::Diagonal{T}) where {T<:Real}
93-
isposdef(c) || throw(ArgumentError("c must be positive definite"))
94-
WoodburyPDMat(sqrt(c) * a.A, a.D, a.S * c)
95-
end
96-
*(c::Diagonal{T}, a::WoodburyPDMat) where {T<:Real} = a * c
97-
function *(c1::Diagonal{T}, a::WoodburyPDMat, c2::Diagonal{T}) where {T<:Real}
98-
isposdef(c1) || throw(ArgumentError("c1 must be positive definite"))
99-
isposdef(c2) || throw(ArgumentError("c2 must be positive definite"))
100-
WoodburyPDMat(sqrt(c1) * sqrt(c2) * a.A, a.D, c1 * a.S * c2)
101-
end
93+
*(c::Real, a::WoodburyPDMat) = a * c

test/woodbury_pd_mat.jl

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
W = WoodburyPDMat(A, D, S)
88
W_dense = PDMat(Symmetric(Matrix(W)))
99

10+
@testset "Valid constructors" begin
11+
@test W == typeof(W)(W.A, W.D, W.S)
12+
end
13+
1014
@testset "invalid constructors error" begin
1115
@test_throws ArgumentError WoodburyPDMat(randn(5, 2), D, S)
1216
@test_throws ArgumentError WoodburyPDMat(randn(4, 3), D, S)
@@ -44,24 +48,6 @@
4448
@test c * W == W * c
4549
@test c * W_dense c * W atol=1e-6
4650
@test (c * W) isa WoodburyPDMat
47-
48-
c = Diagonal(2.0 * ones(4,))
49-
@test c * W == W * c
50-
@test c * W_dense c * W atol=1e-6
51-
@test (c * W) isa WoodburyPDMat
52-
53-
c1 = Diagonal(2.0 * ones(4,))
54-
c2 = Diagonal(3.0 * ones(4,))
55-
c_neg = Diagonal([1,2,-2,3])
56-
57-
@test c2 * W * c1 == c1 * W * c2
58-
@test c1 * W * c2 c1 * W_dense * c2
59-
@test (c1 * W * c2) isa WoodburyPDMat
60-
61-
@test_throws(ArgumentError, c_neg * W)
62-
@test_throws(ArgumentError, c_neg * W * c2)
63-
@test_throws(ArgumentError, c1 * W * c_neg)
64-
6551
end
6652

6753
@testset "MvNormal logpdf" begin

0 commit comments

Comments
 (0)