-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
How to define random functions on your own types need to be better documented. #25605
Comments
This is a fine example of a general theme I've seen a few times. Sometimes people feel a MethodError is too "low level" and user-unfriendly, and that a more application-specific error message should be substituted for it. But I generally think that it's good to know how the system works, in which case a MethodError is actually quite informative and more useful than an ad-hoc message: the formatting is consistent so you get better at reading MethodErrors over time, and more effort has been put in to MethodErrors to make them include more information. |
MbedTLS fails with this error message now: https://travis-ci.org/JuliaWeb/GitHub.jl/jobs/330410030#L1289. Still no idea how to fix. Was this supposed to be just an optimization or an API change? If purely optimization, should be fixed to not break code, if API change, should have deprecation and NEWS: |
I agree with @KristofferC that the issue here is not
|
I will address the issue. |
The previous julia> Base.rand(::MersenneTwister, f::F) = rand()*f.v
julia> julia> rand(MersenneTwister(0), F(1.1))
0.7166581394375923
julia> julia> rand(F(2.0), 2, 2)
ERROR: MethodError: no method matching rand(::F, ::Int64, ::Int64)
Closest candidates are:
rand(::Integer...) at random.jl:280
rand(::Type, ::Integer, ::Integer...) at random.jl:282
rand(::AbstractArray, ::Integer...) at random.jl:297
... and you now have to define a loop yourself for array generation.
Yes, I fully agree the new system needs documentation and a better error message. In the PR introducing |
This is not what happened here, cf. #23964 (comment) |
Bump, what is the status on this? I would like to reiterate how awesome it would be if this could be made non-breaking. |
Bump; documentation for this is very much needed now that we start upgrading to v0. 7. |
Message received! |
I believe this is not possible while keeping the benefits of the new framework. I would like to reiterate how limited the previous API was; I know you are not a big fan of this change, but hope you will come to appreciate the new possibilities. |
It's still kind of difficult to find and understand the documentation for this. If I google "ERROR: ArgumentError: Sampler for this object is not defined", it brings me here. When I finally found the right part of the docs (https://docs.julialang.org/en/v1/stdlib/Random/#Generating-values-from-a-collection-1), I was very surprised to find that, instead of learning how to implement a |
and have better error messages.
On 0.6:
The error message says exactly what is happening, I define the function, everything works.
On 0.7:
Ok... what do I do... Looking at docs for
rand
, says nothing aboutSampler
. Looking at NEWS.md, nothing aboutSampler
. Looking at docs, nothing aboutSampler
. Looking at>help? Sampler
,No documentation found.
. Let's try the same as in 0.6:Woho, it works... or?
Gives up.
The text was updated successfully, but these errors were encountered: