Allow for uniform initialization in a single step. (#136)

This commit is contained in:
Laurent Mazare
2023-07-11 08:52:29 +01:00
committed by GitHub
parent b31a3bbdcb
commit ae79c00e48
5 changed files with 43 additions and 13 deletions

View File

@ -109,14 +109,20 @@ impl Device {
}
}
pub(crate) fn rand_uniform(&self, shape: &Shape, dtype: DType) -> Result<Storage> {
pub(crate) fn rand_uniform(
&self,
shape: &Shape,
dtype: DType,
lo: f64,
up: f64,
) -> Result<Storage> {
match self {
Device::Cpu => {
let storage = CpuStorage::rand_uniform(shape, dtype)?;
let storage = CpuStorage::rand_uniform(shape, dtype, lo, up)?;
Ok(Storage::Cpu(storage))
}
Device::Cuda(device) => {
let storage = device.rand_uniform(shape, dtype)?;
let storage = device.rand_uniform(shape, dtype, lo, up)?;
Ok(Storage::Cuda(storage))
}
}