-
Notifications
You must be signed in to change notification settings - Fork 421
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
Strange eltype
behavior
#1402
Comments
This has been the topic of multiple issues and PRs. The short version is: you can't expect I'll close this issue since it is a duplicate of eg #1071. |
Thanks for the link! Looks like this has been quite a saga. This design decision for |
It would be nice to have a way to get the default variate type for a distribution, though (which should then match the type that comes out of |
The main issue here is that it is not always possible to compute the type of |
You mean it would be difficult to "synchronize" the behavior of |
Yes. I assume, if you want to include the type of |
Yeah, you know there is a parallel infrastructure where the type of |
Sure but unfortunately it is only a heuristic and requires e.g. Distributions.jl/src/univariates.jl Line 140 in 27fb31c
|
I actually often wished for something that gives me the type of the variate/ But couldn't we have a function It would of course go hand-in-hand with |
I think the only reliable way that always works is to call |
Well, however implements |
I disagree in general here 🙂 Even if you implement |
We know how to deal with that, we have exactly the same behaviour, the same issues for iterators and we introduced traits |
On Zulip, @ExpandingMan pointed out that the law satisfied seems to be eltype(d::Distribution) == eltype(rand(d)) It's reasonable to have a way to compute that, it's just not the thing I'm usually interested in. For MeasureTheory, I think it was @phipsgabler who suggested a Thinking some more about this lately, I'm thinking the default implementation could be sampletype(m::M) where {M<:AbstractMeasure}= Core.Compiler.return_type(rand, Tuple{M}) In some cases, this might break or give us something too wide, which we can narrow with added methods if we need to. I'd think Distributions could have something similar. For the issue of RNG inputs, @devmotion I think your suggestion of another argument to |
As said before, this is also not a general property enforced or a design currently, usually julia> using Distributions
julia> eltype(Normal{Int}(0, 1))
Int64
julia> eltype(rand(Normal{Int}(0, 1)))
Float64
julia> eltype(Dirichlet(5, 1))
Int64
julia> eltype(rand(Dirichlet(5, 1)))
Float64 I really think it is not a good idea to use |
Is there discussion somewhere explaining how this is a good thing?
Why not? Seems like a great use of the abstract interpretation in the compiler (I assume that's how it works). Hopefully the abstract interpretation will itself be user-facing at some point, but until then this I'd think this is a reasonable workaround. |
Yes, as mentioned multiple times this discussion here is completely redundant and just a duplicate of many older issues and PRs 😄 Here
Because it will break in all kinds of ways (e.g. JuliaLang/julia#41442 and JuliaLang/julia#35910) and is always allowed to return |
Ok, I saw discussion that it was that way, but didn't see anything about why it was that way. The details you give are helpful for this, and it looks like we just expect entirely different use cases for the function. I think of eltype as answering "what type of values does this container hold?" (distributions are a kind of container). In some cases, It seems you expect it to be more like, "What primitive type should be used to instantiate arrays constructed using this?". That a fine question, just very different than I expected. From the many issues and PRs, it seems pretty common for people to be surprised by this usage. |
I'm not sure if that's a good way to view distributions in all use cases, at least not as a container of variates. In retrospect, maybe defining That's why I thought we should maybe have a Apart from that, though - what should |
As I alluded to in #882 (comment), there is |
One more of our original sins. |
So we'd define |
This looks great! And for non-distributional things it seems to act like julia> Random.gentype([randn(3) for j in 1:4])
Vector{Float64} (alias for Array{Float64, 1}) So maybe we drop |
I'd love to have some official way to provide sample type information. I'm currently expanding the concept of |
This seems problematic:
I found this very surprising, as I'd guess many others have/will. In general, it seems reasonable to expect a law that for any
d::Distribution
,My biggest concern here is that I'd like to implement
eltype
in MeasureTheory.jl, and I don't know if people might expect it to behave as it does in Distributions.Could there be a path to changing this?
The text was updated successfully, but these errors were encountered: