Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve _dist_params_numtype #433

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ DoubleFloats = "0.9, 1"
ElasticArrays = "1.2.3"
EmpiricalDistributions = "0.2, 0.3.1"
FFTW = "1"
FillArrays = "1.1.1"
FillArrays = "0.13, 1.1.1"
Folds = "0.2"
ForwardDiff = "0.10"
ForwardDiffPullbacks = "0.1.1, 0.2"
Expand Down
11 changes: 8 additions & 3 deletions src/transforms/distribution_transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@
end


_dist_params_numtype(d::Distribution) = promote_type(map(typeof, Distributions.params(d))...)
_dist_params_numtype(d::Distribution) = realnumtype(typeof(params(d)))

function ChainRulesCore.rrule(::typeof(_dist_params_numtype), d::Distribution)
_dist_params_numtype_pullback(ΔΩ) = (NoTangent(), NoTangent())
_dist_params_numtype(d), _dist_params_numtype_pullback

Check warning on line 326 in src/transforms/distribution_transform.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/distribution_transform.jl#L324-L326

Added lines #L324 - L326 were not covered by tests
end


@inline _trafo_cdf(d::Distribution{Univariate,Continuous}, x::Real) = _trafo_cdf_impl(_dist_params_numtype(d), d, x)
Expand Down Expand Up @@ -370,7 +375,7 @@


@inline function _eval_dist_trafo_func(f::typeof(_trafo_cdf), d::Distribution{Univariate,Continuous}, src_v::Real)
R_V = float(promote_type(typeof(src_v), eltype(params(d))))
R_V = float(promote_type(typeof(src_v), _dist_params_numtype(d)))
if insupport(d, src_v)
trg_v = f(d, src_v)
convert(R_V, trg_v)
Expand All @@ -380,7 +385,7 @@
end

@inline function _eval_dist_trafo_func(f::typeof(_trafo_quantile), d::Distribution{Univariate,Continuous}, src_v::Real)
R_V = float(promote_type(typeof(src_v), eltype(params(d))))
R_V = float(promote_type(typeof(src_v), _dist_params_numtype(d)))
if 0 <= src_v <= 1
trg_v = f(d, src_v)
convert(R_V, trg_v)
Expand Down
Loading