Uh oh!
There was an error while loading. Please reload this page.
rand_distr: Use Result instead of panics - #770
Conversation
This also fixes a few bugs about invalid parameters in the documentation and the code. Refs rust-random#581.
vks
commented
Apr 9, 2019
What is the plan for the distributions in |
dhardy
commented
Apr 9, 2019
Thanks for getting this started. Do you think #100 has any effect on this? I haven't looked into it recently but some method for supporting lower precision / other types would be nice to have. |
vks
commented
Apr 9, 2019
I think #100 is orthogonal. |
dhardy
left a comment
There was a problem hiding this comment.
These guards don't catch NaN values, which do sometimes occur in numerical applications. So better I think to replace k <= 0.0 with !(k > 0.0) etc.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
newpavlov
commented
Apr 10, 2019
dhardy
commented
Apr 10, 2019
That way you need two checks. Infinite values are often acceptable, in which case a single check like |
vks
commented
Apr 10, 2019
Maybe there should be an error variant for NaN in arguments? |
dhardy
commented
Apr 10, 2019
That's one option, but needs a second round of testing. Is it worthwhile? |
vks
commented
Apr 10, 2019
@dhardy I just changed the checks as you suggested. |
vks
commented
Apr 15, 2019
Note that the error variants here are not yet public, so we could worry about the details later. Or I can still make them public for this PR. |
Uh oh!
There was an error while loading. Please reload this page.
dhardy
commented
Apr 15, 2019
Interesting point about the error types not being public — why isn't this a compile error (private type in public API)? Also note that #775 might remove the need for the current error in |
The type is public, but its variants are not (similar to a public struct with private members). You can still match on it with
This is fine, if we keep the variants private for now we can revisit this later without breakage. |
Am I reading something wrong? In I also don't see anything making the Edit: I suggest making these variants public anyway. Most users won't have a reason to depend on the variants, and tricks like |
vks
commented
Apr 15, 2019
You are right, the errors are all private. I expected that the modules for the distributions are public, but they are all private.
Will do! |
dhardy
commented
Apr 15, 2019
What do you think, are maximally-specific error types like this more useful than a single generic Another point is that with the export renames, the API doc shows e.g. Having a single BTW does this have any overlap with #771? Possibly not since we really don't need this to implement |
I'm not a fan of mixing all variants in a huge enum, but I think as single On the other hand, I like how the error types currently serve as documentation for the possible failures.
I could rename the errors or make the modules public and not re-export them. |
dhardy
commented
Apr 15, 2019
Is there some reason or just style? It does avoid the question of whether to add a hidden variant.
So long as the internals are private (allowing us to add a code later), this serves our needs sufficiently. |
It means that the error types are no longer self-documenting, because some variants are unused by a specific distribution, so we have to move the documentation into the distribution's constructor. Also, we have the same problem with the hidden variant, because we still might want to add new variants. However, it is actually quite similar to
Yes, the internals would be private and it would just be used to print the error messages. Otherwise it would behave like |
dhardy
commented
Apr 17, 2019
Agreed. I don't think there's much reason to match on error variants so lets switch to |
dhardy
commented
Apr 20, 2019
Lets take this as-is for now, but revisit the error types soon (at least add some |
rand_distr: Use `Result` instead of panics
rand_distr: Use `Result` instead of panics
This also fixes a few bugs about invalid parameters in the documentation
and the code.
The distributions in
randare untouched. In particular,Uniformand similar still panic.Refs #581.