summaryrefslogtreecommitdiff
path: root/candle-core/src/cpu_backend.rs
diff options
context:
space:
mode:
authorLaurent Mazare <laurent.mazare@gmail.com>2023-07-11 08:52:29 +0100
committerGitHub <noreply@github.com>2023-07-11 08:52:29 +0100
commitae79c00e48089d889f900b4c05f90a1201e610c6 (patch)
treea42bc3334791a79b203397c581d4ed03998e4e3d /candle-core/src/cpu_backend.rs
parentb31a3bbdcbf1a75bbb18cdc2aa0fbff2ab931351 (diff)
downloadcandle-ae79c00e48089d889f900b4c05f90a1201e610c6.tar.gz
candle-ae79c00e48089d889f900b4c05f90a1201e610c6.tar.bz2
candle-ae79c00e48089d889f900b4c05f90a1201e610c6.zip
Allow for uniform initialization in a single step. (#136)
Diffstat (limited to 'candle-core/src/cpu_backend.rs')
-rw-r--r--candle-core/src/cpu_backend.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/candle-core/src/cpu_backend.rs b/candle-core/src/cpu_backend.rs
index 1af694d7..de32b549 100644
--- a/candle-core/src/cpu_backend.rs
+++ b/candle-core/src/cpu_backend.rs
@@ -895,7 +895,7 @@ impl CpuStorage {
MatMul(bmnk).map(self, lhs_l, rhs, rhs_l)
}
- pub(crate) fn rand_uniform(shape: &Shape, dtype: DType) -> Result<Self> {
+ pub(crate) fn rand_uniform(shape: &Shape, dtype: DType, min: f64, max: f64) -> Result<Self> {
use rand::prelude::*;
let elem_count = shape.elem_count();
@@ -907,7 +907,7 @@ impl CpuStorage {
DType::F32 => {
let mut data = Vec::new();
data.reserve(elem_count);
- let uniform = rand::distributions::Uniform::new(0f32, 1f32);
+ let uniform = rand::distributions::Uniform::new(min as f32, max as f32);
for _i in 0..elem_count {
data.push(rng.sample::<f32, _>(uniform))
}
@@ -916,7 +916,7 @@ impl CpuStorage {
DType::F64 => {
let mut data = Vec::new();
data.reserve(elem_count);
- let uniform = rand::distributions::Uniform::new(0f64, 1f64);
+ let uniform = rand::distributions::Uniform::new(min, max);
for _i in 0..elem_count {
data.push(rng.sample::<f64, _>(uniform))
}