-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Adds rand_distr::Distribution implementations for f16 & bf16 #83
Conversation
Happy to make any modifications you'd like to any names! |
I'll happily merge this with the following changes:
That's it, just minor things other than the rename. |
Oh also, it doesn't look like |
Perfect, will make those updates soon! Thanks for the response 🚀 |
Also for completeness, here's the errors you'll get if you run the tests without num-traits: error[E0277]: the trait bound `binary16::f16: Float` is not satisfied
--> src\rand_distr.rs:103:13
|
102 | let _: crate::f16 = rng.sample(
| ------ required by a bound introduced by this call
103 | rand_distr::Normal::new(crate::f16::from_f32(0.0), crate::f16::from_f32(1.0)).unwrap(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Float` is not implemented for `binary16::f16`
|
= help: the following other types implement trait `Float`:
f32
f64
= note: required for `rand_distr::Normal<binary16::f16>` to implement `Distribution<binary16::f16>`
note: required by a bound in `rand::Rng::sample`
--> C:\Users\clowm\.cargo\registry\src\github.com-1ecc6299db9ec823\rand-0.8.5\src\rng.rs:152:21
|
152 | fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T {
| ^^^^^^^^^^^^^^^ required by this bound in `rand::Rng::sample |
src/rand_distr.rs
Outdated
use rand::Rng; | ||
use rand_distr::{uniform::UniformFloat, Distribution}; | ||
|
||
macro_rules! impl_distribution_via_f32 { | ||
($Ty:ty, $Distr:ty) => { | ||
impl Distribution<$Ty> for $Distr { | ||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $Ty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rand::Rng
trait is used in this impl Distribution here. Unfortunately rand_distr doesn't re-export Rng, so thats the only use of it.
This would mean users would always have to use --features rand,rand_distr
together. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just kidding I think I figured out how to do this by adding an actual feature named rand_distr that requires both rand & rand_distr
Okay should be all good for re-review! |
@starkat99 anything else I need to update? |
Resolves #82
Tests need to be run with the
sample
andnum-traits
feature enabled