From 5cda4e782ae37127fba309654ca02b6ef2bfd1fd Mon Sep 17 00:00:00 2001 From: mohamed82008 Date: Sat, 23 Feb 2019 23:24:37 +1100 Subject: [PATCH 1/2] low hanging performance --- src/Bijectors.jl | 154 ++++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/src/Bijectors.jl b/src/Bijectors.jl index 98136b2f..83762eaf 100644 --- a/src/Bijectors.jl +++ b/src/Bijectors.jl @@ -16,8 +16,10 @@ export TransformDistribution, invlink, logpdf_with_trans -_eps(::Type{T}) where {T} = eps(T) -_eps(::Type{Real}) = eps(Float64) +const DEBUG = Bool(parse(Int, get(ENV, "DEBUG_BIJECTORS", "0"))) + +@inline _eps(::Type{T}) where {T} = eps(T) +@inline _eps(::Type{Real}) = eps(Float64) function __init__() @require ForwardDiff="f6369f11-7733-5829-9624-2563aa707210" @eval begin _eps(::Type{<:ForwardDiff.Dual{<:Any, Real}}) = _eps(Real) @@ -64,12 +66,12 @@ const TransformDistribution{T<:ContinuousUnivariateDistribution} = Union{T, Trun ϵ = eps(x) bounds = (minimum(dist)+ϵ, maximum(dist)-ϵ) clamped_x = clamp(x, bounds...) - @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x" + DEBUG && @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x" return clamped_x end -link(d::TransformDistribution, x::Real) = _link(d, _clamp(x, d)) -function _link(d::TransformDistribution, x::Real) +@inline link(d::TransformDistribution, x::Real) = _link(d, _clamp(x, d)) +@inline function _link(d::TransformDistribution, x::Real) a, b = minimum(d), maximum(d) lowerbounded, upperbounded = isfinite(a), isfinite(b) if lowerbounded && upperbounded @@ -83,8 +85,8 @@ function _link(d::TransformDistribution, x::Real) end end -invlink(d::TransformDistribution, y::Real) = _clamp(_invlink(d, y), d) -function _invlink(d::TransformDistribution, y::Real) +@inline invlink(d::TransformDistribution, y::Real) = _clamp(_invlink(d, y), d) +@inline function _invlink(d::TransformDistribution, y::Real) a, b = minimum(d), maximum(d) lowerbounded, upperbounded = isfinite(a), isfinite(b) if lowerbounded && upperbounded @@ -98,11 +100,11 @@ function _invlink(d::TransformDistribution, y::Real) end end -function logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) +@inline function logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) x = transform ? _clamp(x, d) : x return _logpdf_with_trans(d, x, transform) end -function _logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) +@inline function _logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) lp = logpdf(d, x) if transform a, b = minimum(d), maximum(d) @@ -127,9 +129,9 @@ const PositiveDistribution = Union{ InverseGaussian, Kolmogorov, LogNormal, NoncentralChisq, NoncentralF, Rayleigh, Weibull, } -_link(d::PositiveDistribution, x::Real) = log(x) -_invlink(d::PositiveDistribution, y::Real) = exp(y) -function _logpdf_with_trans(d::PositiveDistribution, x::Real, transform::Bool) +@inline _link(d::PositiveDistribution, x::Real) = log(x) +@inline _invlink(d::PositiveDistribution, y::Real) = exp(y) +@inline function _logpdf_with_trans(d::PositiveDistribution, x::Real, transform::Bool) return logpdf(d, x) + transform * log(x) end @@ -140,9 +142,9 @@ end const UnitDistribution = Union{Beta, KSOneSided, NoncentralBeta} -_link(d::UnitDistribution, x::Real) = StatsFuns.logit(x) -_invlink(d::UnitDistribution, y::Real) = StatsFuns.logistic(y) -function _logpdf_with_trans(d::UnitDistribution, x::Real, transform::Bool) +@inline _link(d::UnitDistribution, x::Real) = StatsFuns.logit(x) +@inline _invlink(d::UnitDistribution, y::Real) = StatsFuns.logistic(y) +@inline function _logpdf_with_trans(d::UnitDistribution, x::Real, transform::Bool) return logpdf(d, x) + transform * log(x * (one(x) - x)) end @@ -155,30 +157,30 @@ const SimplexDistribution = Union{Dirichlet} @inline function _clamp(x::T, dist::SimplexDistribution) where T bounds = (zero(T), one(T)) clamped_x = clamp(x, bounds...) - @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x" + DEBUG && @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x" return clamped_x end -function link( - d::SimplexDistribution, - x::AbstractVector{T}, +@inline function link( + d::SimplexDistribution, + x::AbstractVector{T}, ::Type{Val{proj}} = Val{true} ) where {T<:Real, proj} y, K = similar(x), length(x) ϵ = _eps(T) sum_tmp = zero(T) - z = x[1] * (one(T) - 2ϵ) + ϵ # z ∈ [ϵ, 1-ϵ] - y[1] = StatsFuns.logit(z) - log(one(T) / (K - 1)) - @inbounds for k in 2:(K - 1) + @inbounds z = x[1] * (one(T) - 2ϵ) + ϵ # z ∈ [ϵ, 1-ϵ] + @inbounds y[1] = StatsFuns.logit(z) - log(one(T) / (K - 1)) + @inbounds @simd for k in 2:(K - 1) sum_tmp += x[k - 1] # z ∈ [ϵ, 1-ϵ] # x[k] = 0 && sum_tmp = 1 -> z ≈ 1 z = (x[k] + ϵ)*(one(T) - 2ϵ)/(one(T) - sum_tmp + ϵ) y[k] = StatsFuns.logit(z) - log(one(T) / (K - k)) end - sum_tmp += x[K - 1] - if proj + @inbounds sum_tmp += x[K - 1] + @inbounds if proj y[K] = zero(T) else y[K] = one(T) - sum_tmp - x[K] @@ -188,15 +190,15 @@ function link( end # Vectorised implementation of the above. -function link( - d::SimplexDistribution, - X::AbstractMatrix{T}, +@inline function link( + d::SimplexDistribution, + X::AbstractMatrix{T}, ::Type{Val{proj}} = Val{true} ) where {T<:Real, proj} Y, K, N = similar(X), size(X, 1), size(X, 2) ϵ = _eps(T) - @inbounds for n in 1:size(X, 2) + @inbounds @simd for n in 1:size(X, 2) sum_tmp = zero(T) z = X[1, n] * (one(T) - 2ϵ) + ϵ Y[1, n] = StatsFuns.logit(z) - log(one(T) / (K - 1)) @@ -216,24 +218,24 @@ function link( return Y end -function invlink( - d::SimplexDistribution, - y::AbstractVector{T}, +@inline function invlink( + d::SimplexDistribution, + y::AbstractVector{T}, ::Type{Val{proj}} = Val{true} ) where {T<:Real, proj} x, K = similar(y), length(y) ϵ = _eps(T) - z = StatsFuns.logistic(y[1] + log(one(T) / (K - 1))) - x[1] = _clamp((z - ϵ) / (one(T) - 2ϵ), d) + @inbounds z = StatsFuns.logistic(y[1] + log(one(T) / (K - 1))) + @inbounds x[1] = _clamp((z - ϵ) / (one(T) - 2ϵ), d) sum_tmp = zero(T) - @inbounds for k = 2:(K - 1) + @inbounds @simd for k = 2:(K - 1) z = StatsFuns.logistic(y[k] + log(one(T) / (K - k))) sum_tmp += x[k-1] - x[k] = _clamp((one(T) - sum_tmp + ϵ) / (one(T) - 2ϵ) * z - ϵ, d) + x[k] = _clamp(((one(T) + ϵ) - sum_tmp) / (one(T) - 2ϵ) * z - ϵ, d) end - sum_tmp += x[K - 1] - if proj + @inbounds sum_tmp += x[K - 1] + @inbounds if proj x[K] = _clamp(one(T) - sum_tmp, d) else x[K] = _clamp(one(T) - sum_tmp - y[K], d) @@ -242,15 +244,15 @@ function invlink( end # Vectorised implementation of the above. -function invlink( - d::SimplexDistribution, - Y::AbstractMatrix{T}, +@inline function invlink( + d::SimplexDistribution, + Y::AbstractMatrix{T}, ::Type{Val{proj}} = Val{true} ) where {T<:Real, proj} X, K, N = similar(Y), size(Y, 1), size(Y, 2) ϵ = _eps(T) - @inbounds for n in 1:size(X, 2) + @inbounds @simd for n in 1:size(X, 2) sum_tmp, z = zero(T), StatsFuns.logistic(Y[1, n] + log(one(T) / (K - 1))) X[1, n] = _clamp((z - ϵ) / (one(T) - 2ϵ), d) for k in 2:(K - 1) @@ -269,7 +271,7 @@ function invlink( return X end -function logpdf_with_trans( +@inline function logpdf_with_trans( d::SimplexDistribution, x::AbstractVector{<:Real}, transform::Bool, @@ -281,9 +283,9 @@ function logpdf_with_trans( K = length(x) sum_tmp = zero(eltype(x)) - z = x[1] + @inbounds z = x[1] lp += log(z + ϵ) + log(one(T) - z + ϵ) - @inbounds for k in 2:(K - 1) + @inbounds @simd for k in 2:(K - 1) sum_tmp += x[k-1] z = x[k] / (one(T) - sum_tmp + ϵ) lp += log(z + ϵ) + log(one(T) - z + ϵ) + log(one(T) - sum_tmp + ϵ) @@ -293,7 +295,7 @@ function logpdf_with_trans( end # REVIEW: why do we put this piece of code here? -function logpdf_with_trans(d::Categorical, x::Int) +@inline function logpdf_with_trans(d::Categorical, x::Int) return d.p[x] > 0.0 && insupport(d, x) ? log(d.p[x]) : eltype(d.p)(-Inf) end @@ -304,9 +306,9 @@ end using Distributions: AbstractMvLogNormal -link(d::AbstractMvLogNormal, x::AbstractVector{<:Real}) = log.(x) -invlink(d::AbstractMvLogNormal, y::AbstractVector{<:Real}) = exp.(y) -function logpdf_with_trans( +@inline link(d::AbstractMvLogNormal, x::AbstractVector{<:Real}) = log.(x) +@inline invlink(d::AbstractMvLogNormal, y::AbstractVector{<:Real}) = exp.(y) +@inline function logpdf_with_trans( d::AbstractMvLogNormal, x::AbstractVector{<:Real}, transform::Bool, @@ -320,32 +322,32 @@ end const PDMatDistribution = Union{InverseWishart, Wishart} -function link(d::PDMatDistribution, X::AbstractMatrix{T}) where {T<:Real} +@inline function link(d::PDMatDistribution, X::AbstractMatrix{T}) where {T<:Real} Y = cholesky(X).L - for m in 1:size(Y, 1) + @inbounds @simd for m in 1:size(Y, 1) Y[m, m] = log(Y[m, m]) end return Matrix(Y) end -function invlink(d::PDMatDistribution, Y::AbstractMatrix{T}) where {T<:Real} +@inline function invlink(d::PDMatDistribution, Y::AbstractMatrix{T}) where {T<:Real} X, dim = copy(Y), size(Y) - for m in 1:size(X, 1) + @inbounds @simd for m in 1:size(X, 1) X[m, m] = exp(X[m, m]) end Z = similar(X) return mul!(Z, LowerTriangular(X), LowerTriangular(X)') end -function logpdf_with_trans( - d::PDMatDistribution, - X::AbstractMatrix{<:Real}, +@inline function logpdf_with_trans( + d::PDMatDistribution, + X::AbstractMatrix{<:Real}, transform::Bool ) lp = logpdf(d, X) if transform && isfinite(lp) U = cholesky(X).U - for i in 1:dim(d) + @inbounds @simd for i in 1:dim(d) lp += (dim(d) - i + 2) * log(U[i, i]) end lp += dim(d) * log(2.0) @@ -361,14 +363,14 @@ end # UnivariateDistributions using Distributions: UnivariateDistribution -link(d::UnivariateDistribution, x::Real) = x -link(d::UnivariateDistribution, x::AbstractVector{<:Real}) = link.(Ref(d), x) +@inline link(d::UnivariateDistribution, x::Real) = x +@inline link(d::UnivariateDistribution, x::AbstractVector{<:Real}) = link.(Ref(d), x) -invlink(d::UnivariateDistribution, y::Real) = y -invlink(d::UnivariateDistribution, y::AbstractVector{<:Real}) = invlink.(Ref(d), y) +@inline invlink(d::UnivariateDistribution, y::Real) = y +@inline invlink(d::UnivariateDistribution, y::AbstractVector{<:Real}) = invlink.(Ref(d), y) -logpdf_with_trans(d::UnivariateDistribution, x::Real, ::Bool) = logpdf(d, x) -function logpdf_with_trans( +@inline logpdf_with_trans(d::UnivariateDistribution, x::Real, ::Bool) = logpdf(d, x) +@inline function logpdf_with_trans( d::UnivariateDistribution, x::AbstractVector{<:Real}, transform::Bool, @@ -379,28 +381,28 @@ end # MultivariateDistributions using Distributions: MultivariateDistribution -link(d::MultivariateDistribution, x::AbstractVector{<:Real}) = copy(x) -function link(d::MultivariateDistribution, X::AbstractMatrix{<:Real}) +@inline link(d::MultivariateDistribution, x::AbstractVector{<:Real}) = copy(x) +@inline function link(d::MultivariateDistribution, X::AbstractMatrix{<:Real}) Y = similar(X) - for n in 1:size(X, 2) + @inbounds @simd for n in 1:size(X, 2) Y[:, n] = link(d, view(X, :, n)) end return Y end -invlink(d::MultivariateDistribution, y::AbstractVector{<:Real}) = copy(y) -function invlink(d::MultivariateDistribution, Y::AbstractMatrix{<:Real}) +@inline invlink(d::MultivariateDistribution, y::AbstractVector{<:Real}) = copy(y) +@inline function invlink(d::MultivariateDistribution, Y::AbstractMatrix{<:Real}) X = similar(Y) - for n in 1:size(Y, 2) + @inbounds @simd for n in 1:size(Y, 2) X[:, n] = invlink(d, view(Y, :, n)) end return X end -function logpdf_with_trans(d::MultivariateDistribution, x::AbstractVector{<:Real}, ::Bool) +@inline function logpdf_with_trans(d::MultivariateDistribution, x::AbstractVector{<:Real}, ::Bool) return logpdf(d, x) end -function logpdf_with_trans( +@inline function logpdf_with_trans( d::MultivariateDistribution, X::AbstractMatrix{<:Real}, transform::Bool, @@ -411,16 +413,16 @@ end # MatrixDistributions using Distributions: MatrixDistribution -link(d::MatrixDistribution, X::AbstractMatrix{<:Real}) = copy(X) -link(d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}) = link.(Ref(d), X) +@inline link(d::MatrixDistribution, X::AbstractMatrix{<:Real}) = copy(X) +@inline link(d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}) = link.(Ref(d), X) -invlink(d::MatrixDistribution, Y::AbstractMatrix{<:Real}) = copy(Y) -function invlink(d::MatrixDistribution, Y::AbstractVector{<:AbstractMatrix{<:Real}}) +@inline invlink(d::MatrixDistribution, Y::AbstractMatrix{<:Real}) = copy(Y) +@inline function invlink(d::MatrixDistribution, Y::AbstractVector{<:AbstractMatrix{<:Real}}) return invlink.(Ref(d), Y) end -logpdf_with_trans(d::MatrixDistribution, X::AbstractMatrix{<:Real}, ::Bool) = logpdf(d, X) -function logpdf_with_trans( +@inline logpdf_with_trans(d::MatrixDistribution, X::AbstractMatrix{<:Real}, ::Bool) = logpdf(d, X) +@inline function logpdf_with_trans( d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}, transform::Bool, From c3454de8e0102bdc19e7234853f04415f9f276d4 Mon Sep 17 00:00:00 2001 From: mohamed82008 Date: Sun, 24 Feb 2019 09:20:51 +1100 Subject: [PATCH 2/2] remove inlines --- src/Bijectors.jl | 92 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Bijectors.jl b/src/Bijectors.jl index 83762eaf..9317e466 100644 --- a/src/Bijectors.jl +++ b/src/Bijectors.jl @@ -18,8 +18,8 @@ export TransformDistribution, const DEBUG = Bool(parse(Int, get(ENV, "DEBUG_BIJECTORS", "0"))) -@inline _eps(::Type{T}) where {T} = eps(T) -@inline _eps(::Type{Real}) = eps(Float64) +_eps(::Type{T}) where {T} = eps(T) +_eps(::Type{Real}) = eps(Float64) function __init__() @require ForwardDiff="f6369f11-7733-5829-9624-2563aa707210" @eval begin _eps(::Type{<:ForwardDiff.Dual{<:Any, Real}}) = _eps(Real) @@ -62,7 +62,7 @@ end ############# const TransformDistribution{T<:ContinuousUnivariateDistribution} = Union{T, Truncated{T}} -@inline function _clamp(x::Real, dist::TransformDistribution) +function _clamp(x::Real, dist::TransformDistribution) ϵ = eps(x) bounds = (minimum(dist)+ϵ, maximum(dist)-ϵ) clamped_x = clamp(x, bounds...) @@ -70,8 +70,8 @@ const TransformDistribution{T<:ContinuousUnivariateDistribution} = Union{T, Trun return clamped_x end -@inline link(d::TransformDistribution, x::Real) = _link(d, _clamp(x, d)) -@inline function _link(d::TransformDistribution, x::Real) +link(d::TransformDistribution, x::Real) = _link(d, _clamp(x, d)) +function _link(d::TransformDistribution, x::Real) a, b = minimum(d), maximum(d) lowerbounded, upperbounded = isfinite(a), isfinite(b) if lowerbounded && upperbounded @@ -85,8 +85,8 @@ end end end -@inline invlink(d::TransformDistribution, y::Real) = _clamp(_invlink(d, y), d) -@inline function _invlink(d::TransformDistribution, y::Real) +invlink(d::TransformDistribution, y::Real) = _clamp(_invlink(d, y), d) +function _invlink(d::TransformDistribution, y::Real) a, b = minimum(d), maximum(d) lowerbounded, upperbounded = isfinite(a), isfinite(b) if lowerbounded && upperbounded @@ -100,11 +100,11 @@ end end end -@inline function logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) +function logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) x = transform ? _clamp(x, d) : x return _logpdf_with_trans(d, x, transform) end -@inline function _logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) +function _logpdf_with_trans(d::TransformDistribution, x::Real, transform::Bool) lp = logpdf(d, x) if transform a, b = minimum(d), maximum(d) @@ -129,9 +129,9 @@ const PositiveDistribution = Union{ InverseGaussian, Kolmogorov, LogNormal, NoncentralChisq, NoncentralF, Rayleigh, Weibull, } -@inline _link(d::PositiveDistribution, x::Real) = log(x) -@inline _invlink(d::PositiveDistribution, y::Real) = exp(y) -@inline function _logpdf_with_trans(d::PositiveDistribution, x::Real, transform::Bool) +_link(d::PositiveDistribution, x::Real) = log(x) +_invlink(d::PositiveDistribution, y::Real) = exp(y) +function _logpdf_with_trans(d::PositiveDistribution, x::Real, transform::Bool) return logpdf(d, x) + transform * log(x) end @@ -142,9 +142,9 @@ end const UnitDistribution = Union{Beta, KSOneSided, NoncentralBeta} -@inline _link(d::UnitDistribution, x::Real) = StatsFuns.logit(x) -@inline _invlink(d::UnitDistribution, y::Real) = StatsFuns.logistic(y) -@inline function _logpdf_with_trans(d::UnitDistribution, x::Real, transform::Bool) +_link(d::UnitDistribution, x::Real) = StatsFuns.logit(x) +_invlink(d::UnitDistribution, y::Real) = StatsFuns.logistic(y) +function _logpdf_with_trans(d::UnitDistribution, x::Real, transform::Bool) return logpdf(d, x) + transform * log(x * (one(x) - x)) end @@ -154,14 +154,14 @@ end ########### const SimplexDistribution = Union{Dirichlet} -@inline function _clamp(x::T, dist::SimplexDistribution) where T +function _clamp(x::T, dist::SimplexDistribution) where T bounds = (zero(T), one(T)) clamped_x = clamp(x, bounds...) DEBUG && @debug "x = $x, bounds = $bounds, clamped_x = $clamped_x" return clamped_x end -@inline function link( +function link( d::SimplexDistribution, x::AbstractVector{T}, ::Type{Val{proj}} = Val{true} @@ -190,7 +190,7 @@ end end # Vectorised implementation of the above. -@inline function link( +function link( d::SimplexDistribution, X::AbstractMatrix{T}, ::Type{Val{proj}} = Val{true} @@ -218,7 +218,7 @@ end return Y end -@inline function invlink( +function invlink( d::SimplexDistribution, y::AbstractVector{T}, ::Type{Val{proj}} = Val{true} @@ -244,7 +244,7 @@ end end # Vectorised implementation of the above. -@inline function invlink( +function invlink( d::SimplexDistribution, Y::AbstractMatrix{T}, ::Type{Val{proj}} = Val{true} @@ -271,7 +271,7 @@ end return X end -@inline function logpdf_with_trans( +function logpdf_with_trans( d::SimplexDistribution, x::AbstractVector{<:Real}, transform::Bool, @@ -295,7 +295,7 @@ end end # REVIEW: why do we put this piece of code here? -@inline function logpdf_with_trans(d::Categorical, x::Int) +function logpdf_with_trans(d::Categorical, x::Int) return d.p[x] > 0.0 && insupport(d, x) ? log(d.p[x]) : eltype(d.p)(-Inf) end @@ -306,9 +306,9 @@ end using Distributions: AbstractMvLogNormal -@inline link(d::AbstractMvLogNormal, x::AbstractVector{<:Real}) = log.(x) -@inline invlink(d::AbstractMvLogNormal, y::AbstractVector{<:Real}) = exp.(y) -@inline function logpdf_with_trans( +link(d::AbstractMvLogNormal, x::AbstractVector{<:Real}) = log.(x) +invlink(d::AbstractMvLogNormal, y::AbstractVector{<:Real}) = exp.(y) +function logpdf_with_trans( d::AbstractMvLogNormal, x::AbstractVector{<:Real}, transform::Bool, @@ -322,7 +322,7 @@ end const PDMatDistribution = Union{InverseWishart, Wishart} -@inline function link(d::PDMatDistribution, X::AbstractMatrix{T}) where {T<:Real} +function link(d::PDMatDistribution, X::AbstractMatrix{T}) where {T<:Real} Y = cholesky(X).L @inbounds @simd for m in 1:size(Y, 1) Y[m, m] = log(Y[m, m]) @@ -330,7 +330,7 @@ const PDMatDistribution = Union{InverseWishart, Wishart} return Matrix(Y) end -@inline function invlink(d::PDMatDistribution, Y::AbstractMatrix{T}) where {T<:Real} +function invlink(d::PDMatDistribution, Y::AbstractMatrix{T}) where {T<:Real} X, dim = copy(Y), size(Y) @inbounds @simd for m in 1:size(X, 1) X[m, m] = exp(X[m, m]) @@ -339,7 +339,7 @@ end return mul!(Z, LowerTriangular(X), LowerTriangular(X)') end -@inline function logpdf_with_trans( +function logpdf_with_trans( d::PDMatDistribution, X::AbstractMatrix{<:Real}, transform::Bool @@ -363,14 +363,14 @@ end # UnivariateDistributions using Distributions: UnivariateDistribution -@inline link(d::UnivariateDistribution, x::Real) = x -@inline link(d::UnivariateDistribution, x::AbstractVector{<:Real}) = link.(Ref(d), x) +link(d::UnivariateDistribution, x::Real) = x +link(d::UnivariateDistribution, x::AbstractVector{<:Real}) = link.(Ref(d), x) -@inline invlink(d::UnivariateDistribution, y::Real) = y -@inline invlink(d::UnivariateDistribution, y::AbstractVector{<:Real}) = invlink.(Ref(d), y) +invlink(d::UnivariateDistribution, y::Real) = y +invlink(d::UnivariateDistribution, y::AbstractVector{<:Real}) = invlink.(Ref(d), y) -@inline logpdf_with_trans(d::UnivariateDistribution, x::Real, ::Bool) = logpdf(d, x) -@inline function logpdf_with_trans( +logpdf_with_trans(d::UnivariateDistribution, x::Real, ::Bool) = logpdf(d, x) +function logpdf_with_trans( d::UnivariateDistribution, x::AbstractVector{<:Real}, transform::Bool, @@ -381,8 +381,8 @@ end # MultivariateDistributions using Distributions: MultivariateDistribution -@inline link(d::MultivariateDistribution, x::AbstractVector{<:Real}) = copy(x) -@inline function link(d::MultivariateDistribution, X::AbstractMatrix{<:Real}) +link(d::MultivariateDistribution, x::AbstractVector{<:Real}) = copy(x) +function link(d::MultivariateDistribution, X::AbstractMatrix{<:Real}) Y = similar(X) @inbounds @simd for n in 1:size(X, 2) Y[:, n] = link(d, view(X, :, n)) @@ -390,8 +390,8 @@ using Distributions: MultivariateDistribution return Y end -@inline invlink(d::MultivariateDistribution, y::AbstractVector{<:Real}) = copy(y) -@inline function invlink(d::MultivariateDistribution, Y::AbstractMatrix{<:Real}) +invlink(d::MultivariateDistribution, y::AbstractVector{<:Real}) = copy(y) +function invlink(d::MultivariateDistribution, Y::AbstractMatrix{<:Real}) X = similar(Y) @inbounds @simd for n in 1:size(Y, 2) X[:, n] = invlink(d, view(Y, :, n)) @@ -399,10 +399,10 @@ end return X end -@inline function logpdf_with_trans(d::MultivariateDistribution, x::AbstractVector{<:Real}, ::Bool) +function logpdf_with_trans(d::MultivariateDistribution, x::AbstractVector{<:Real}, ::Bool) return logpdf(d, x) end -@inline function logpdf_with_trans( +function logpdf_with_trans( d::MultivariateDistribution, X::AbstractMatrix{<:Real}, transform::Bool, @@ -413,16 +413,16 @@ end # MatrixDistributions using Distributions: MatrixDistribution -@inline link(d::MatrixDistribution, X::AbstractMatrix{<:Real}) = copy(X) -@inline link(d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}) = link.(Ref(d), X) +link(d::MatrixDistribution, X::AbstractMatrix{<:Real}) = copy(X) +link(d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}) = link.(Ref(d), X) -@inline invlink(d::MatrixDistribution, Y::AbstractMatrix{<:Real}) = copy(Y) -@inline function invlink(d::MatrixDistribution, Y::AbstractVector{<:AbstractMatrix{<:Real}}) +invlink(d::MatrixDistribution, Y::AbstractMatrix{<:Real}) = copy(Y) +function invlink(d::MatrixDistribution, Y::AbstractVector{<:AbstractMatrix{<:Real}}) return invlink.(Ref(d), Y) end -@inline logpdf_with_trans(d::MatrixDistribution, X::AbstractMatrix{<:Real}, ::Bool) = logpdf(d, X) -@inline function logpdf_with_trans( +logpdf_with_trans(d::MatrixDistribution, X::AbstractMatrix{<:Real}, ::Bool) = logpdf(d, X) +function logpdf_with_trans( d::MatrixDistribution, X::AbstractVector{<:AbstractMatrix{<:Real}}, transform::Bool,