1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
This patch is based on a revert of upstream commit 67541fe44dd5e21681eb37453a3aaa3274ef3512
adapted for use in the Debian package by Peter Michael Green.
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -88,13 +88,11 @@
default-features = false
[dependencies.rand]
-version = "0.9.0"
-features = ["thread_rng"]
+version = "0.8.0"
optional = true
-default-features = false
[dependencies.rand_distr]
-version = "0.5.0"
+version = "0.4.0"
optional = true
default-features = false
@@ -127,7 +125,7 @@
version = "1.0"
[dev-dependencies.rand]
-version = "0.9.0"
+version = "0.8.0"
[target.'cfg(target_arch = "spirv")'.dependencies.crunchy]
version = "0.2.2"
--- a/src/rand_distr.rs
+++ b/src/rand_distr.rs
@@ -1,6 +1,6 @@
use crate::{bf16, f16};
-use rand::{distr::Distribution, Rng};
+use rand::{distributions::Distribution, Rng};
use rand_distr::uniform::UniformFloat;
macro_rules! impl_distribution_via_f32 {
@@ -13,13 +13,13 @@
};
}
-impl_distribution_via_f32!(f16, rand_distr::StandardUniform);
+impl_distribution_via_f32!(f16, rand_distr::Standard);
impl_distribution_via_f32!(f16, rand_distr::StandardNormal);
impl_distribution_via_f32!(f16, rand_distr::Exp1);
impl_distribution_via_f32!(f16, rand_distr::Open01);
impl_distribution_via_f32!(f16, rand_distr::OpenClosed01);
-impl_distribution_via_f32!(bf16, rand_distr::StandardUniform);
+impl_distribution_via_f32!(bf16, rand_distr::Standard);
impl_distribution_via_f32!(bf16, rand_distr::StandardNormal);
impl_distribution_via_f32!(bf16, rand_distr::Exp1);
impl_distribution_via_f32!(bf16, rand_distr::Open01);
@@ -34,25 +34,25 @@
impl rand_distr::uniform::UniformSampler for Float16Sampler {
type X = f16;
- fn new<B1, B2>(low: B1, high: B2) -> Result<Self, rand_distr::uniform::Error>
+ fn new<B1, B2>(low: B1, high: B2) -> Self
where
B1: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
B2: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
{
- Ok(Self(UniformFloat::new(
+ Self(UniformFloat::new(
low.borrow().to_f32(),
high.borrow().to_f32(),
- )?))
+ ))
}
- fn new_inclusive<B1, B2>(low: B1, high: B2) -> Result<Self, rand_distr::uniform::Error>
+ fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
where
B1: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
B2: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
{
- Ok(Self(UniformFloat::new_inclusive(
+ Self(UniformFloat::new_inclusive(
low.borrow().to_f32(),
high.borrow().to_f32(),
- )?))
+ ))
}
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
f16::from_f32(self.0.sample(rng))
@@ -68,25 +68,25 @@
impl rand_distr::uniform::UniformSampler for BFloat16Sampler {
type X = bf16;
- fn new<B1, B2>(low: B1, high: B2) -> Result<Self, rand_distr::uniform::Error>
+ fn new<B1, B2>(low: B1, high: B2) -> Self
where
B1: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
B2: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
{
- Ok(Self(UniformFloat::new(
+ Self(UniformFloat::new(
low.borrow().to_f32(),
high.borrow().to_f32(),
- )?))
+ ))
}
- fn new_inclusive<B1, B2>(low: B1, high: B2) -> Result<Self, rand_distr::uniform::Error>
+ fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
where
B1: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
B2: rand_distr::uniform::SampleBorrow<Self::X> + Sized,
{
- Ok(Self(UniformFloat::new_inclusive(
+ Self(UniformFloat::new_inclusive(
low.borrow().to_f32(),
high.borrow().to_f32(),
- )?))
+ ))
}
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
bf16::from_f32(self.0.sample(rng))
@@ -98,15 +98,15 @@
use super::*;
#[allow(unused_imports)]
- use rand::{rng, Rng};
- use rand_distr::{StandardNormal, StandardUniform, Uniform};
+ use rand::{thread_rng, Rng};
+ use rand_distr::{Standard, StandardNormal, Uniform};
#[test]
fn test_sample_f16() {
- let mut rng = rng();
- let _: f16 = rng.sample(StandardUniform);
+ let mut rng = thread_rng();
+ let _: f16 = rng.sample(Standard);
let _: f16 = rng.sample(StandardNormal);
- let _: f16 = rng.sample(Uniform::new(f16::from_f32(0.0), f16::from_f32(1.0)).unwrap());
+ let _: f16 = rng.sample(Uniform::new(f16::from_f32(0.0), f16::from_f32(1.0)));
#[cfg(feature = "num-traits")]
let _: f16 =
rng.sample(rand_distr::Normal::new(f16::from_f32(0.0), f16::from_f32(1.0)).unwrap());
@@ -114,10 +114,10 @@
#[test]
fn test_sample_bf16() {
- let mut rng = rng();
- let _: bf16 = rng.sample(StandardUniform);
+ let mut rng = thread_rng();
+ let _: bf16 = rng.sample(Standard);
let _: bf16 = rng.sample(StandardNormal);
- let _: bf16 = rng.sample(Uniform::new(bf16::from_f32(0.0), bf16::from_f32(1.0)).unwrap());
+ let _: bf16 = rng.sample(Uniform::new(bf16::from_f32(0.0), bf16::from_f32(1.0)));
#[cfg(feature = "num-traits")]
let _: bf16 =
rng.sample(rand_distr::Normal::new(bf16::from_f32(0.0), bf16::from_f32(1.0)).unwrap());
|