Uh oh!
There was an error while loading. Please reload this page.
Make distributions generic / impl for f32 - #785
Conversation
dhardy
commented
Apr 27, 2019
Note that initial attempts to make |
dhardy
commented
May 3, 2019
@vks would you be able to review? |
vks
commented
May 3, 2019
I wonder whether it would make sense to make the parameter an associated type of |
| let x: f64 = self.sample(rng); | ||
| x as f32 | ||
| } | ||
| } |
There was a problem hiding this comment.
What is the motivation of this? To exercise the type change and optimize later? As of now, it does not seem worth to add this, when dist.sample(&mut rng) as f32 is equivalent.
There was a problem hiding this comment.
Yes, an optimised impl can follow later. Even like this though it helps with some generic coding.
dhardy
commented
May 3, 2019
Remember, the (unparameterised) |
vks
commented
May 10, 2019
That is a good point, it would make using unparametrized distributions much more cumbersome, so the current approach is probably best for now. |
vks
left a comment
There was a problem hiding this comment.
Looks good! I think this is the way we want the interface to look like.
Implement #100: impl for
f32and make distributions generic over the parameter type.Status: partial type changes only. I haven't started on optimising the algorithms, but have found a few resources of interest.
So far I am liking the way this is going. A few extra type annotations are needed but not many due to the language's preference to resolve floats as
f64(example).This adds a dependency on the
num-traitscrate, but only forrand_distr; I think this is acceptable.Slight annoyance:
NumCast::fromreturns anOption, thus requires.unwrap()(less concise and compiler cannot prove there is no panic). We could instead usestd::comvert::From, but this would require an extra bound:N: From<f32>.