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

Handle Real and Any better #96

Closed
wants to merge 1 commit into from
Closed

Handle Real and Any better #96

wants to merge 1 commit into from

Conversation

mohamed82008
Copy link
Member

This PR allows the handling of arrays of Any and Real better by relaxing some type constraints.

@mohamed82008
Copy link
Member Author

Tests are failing because of an issue with the latest ReverseDiff version which has a lot of the functionality in DistributionsAD. This created some conflict. Should be alright after #97 goes in though.

@@ -77,7 +77,7 @@ function Base.rand(rng::AbstractRNG, d::MvDiscreteNonParametric{T,P}) where {T,P
p = probs(d)
n, k = size(p)
map(1:k) do j
draw = rand(rng, P)
draw = rand(rng, (P === Real ? Float64 : P))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a quite crude heuristic. Ideally we would want P to be

mapreduce(promote_type, 1:n) do i
    typeof(p[i, j])
end

assuming that all provided probabilities can be promoted to a common non-abstract type in each column (but possibly not the same type for all columns) - I guess that should usually be satisfied?

BTW copying the logic from Distributions.DiscreteNonParametric here unfortunately introduces also the bugs present in the implementation in Distributions (see e.g. JuliaStats/Distributions.jl#1128), which might not be fixed when the upstream bugs are fixed if people don't keep track of Distributions closely.

@yebai yebai closed this Aug 18, 2021
@yebai yebai deleted the mt/RealAndAny branch October 3, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants