Skip to content

Commit

Permalink
Remove deprecated dim (#225)
Browse files Browse the repository at this point in the history
* Remove deprecated `dim`

* Use `factors` instead of `UL` to avoid wrapper
  • Loading branch information
devmotion authored Jun 30, 2022
1 parent 7a270e3 commit c5625fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Bijectors"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.10.2"
version = "0.10.3"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
13 changes: 6 additions & 7 deletions src/Bijectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,23 @@ function pd_logpdf_with_trans(d, X::AbstractMatrix{<:Real}, transform::Bool)
end
lp = getlogp(d, Xcf, X)
if transform && isfinite(lp)
U = Xcf.U
d = dim(d)
lp += sum((d .- (1:d) .+ 2) .* log.(diag(U)))
lp += d * log(T(2))
n = size(d, 1)
lp += sum(((n + 2) .- (1:n)) .* log.(diag(Xcf.factors)))
lp += n * oftype(lp, IrrationalConstants.logtwo)
end
return lp
end
function getlogp(d::MatrixBeta, Xcf, X)
n1, n2 = params(d)
p = dim(d)
p = size(d, 1)
return ((n1 - p - 1) / 2) * logdet(Xcf) + ((n2 - p - 1) / 2) * logdet(I - X) + d.logc0
end
function getlogp(d::Wishart, Xcf, X)
return 0.5 * ((d.df - (dim(d) + 1)) * logdet(Xcf) - tr(d.S \ X)) + d.logc0
return ((d.df - (size(d, 1) + 1)) * logdet(Xcf) - tr(d.S \ X)) / 2 + d.logc0
end
function getlogp(d::InverseWishart, Xcf, X)
Ψ = Matrix(d.Ψ)
return -0.5 * ((d.df + dim(d) + 1) * logdet(Xcf) + tr(Xcf \ Ψ)) + d.logc0
return -((d.df + size(d, 1) + 1) * logdet(Xcf) + tr(Xcf \ Ψ)) / 2 + d.logc0
end

include("utils.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/compat/distributionsad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ end
ispd(::TuringWishart) = true
ispd(::TuringInverseWishart) = true
function getlogp(d::TuringWishart, Xcf, X)
return 0.5 * ((d.df - (dim(d) + 1)) * logdet(Xcf) - tr(d.chol \ X)) + d.logc0
return ((d.df - (size(d, 1) + 1)) * logdet(Xcf) - tr(d.chol \ X)) / 2 + d.logc0
end
function getlogp(d::TuringInverseWishart, Xcf, X)
Ψ = d.S
return -0.5 * ((d.df + dim(d) + 1) * logdet(Xcf) + tr(Xcf \ Ψ)) + d.logc0
return -((d.df + size(d, 1) + 1) * logdet(Xcf) + tr(Xcf \ Ψ)) / 2 + d.logc0
end
11 changes: 7 additions & 4 deletions src/compat/zygote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ function pd_logpdf_with_trans_zygote(
end
lp = getlogp(d, Xcf, X)
if transform && isfinite(lp)
U = Xcf.U
@inbounds for i in 1:dim(d)
lp += (dim(d) - i + 2) * log(U[i, i])
factors = Xcf.factors
n = size(d, 1)
k = n + 2
@inbounds for i in diagind(factors)
k -= 1
lp += k * log(factors[i])
end
lp += dim(d) * log(T(2))
lp += n * oftype(lp, IrrationalConstants.logtwo)
end
return lp
end
Expand Down

2 comments on commit c5625fc

@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/63435

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.10.3 -m "<description of version>" c5625fc78182a6374be9bfaa0a4527c254b505b5
git push origin v0.10.3

Please sign in to comment.