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

@ -153,7 +153,13 @@ impl CudaDevice {
})
}
pub(crate) fn rand_uniform(&self, shape: &Shape, dtype: DType) -> Result<CudaStorage> {
pub(crate) fn rand_uniform(
&self,
shape: &Shape,
dtype: DType,
lo: f64,
up: f64,
) -> Result<CudaStorage> {
let elem_count = shape.elem_count();
let curand = self.curand.lock().unwrap();
let slice = match dtype {
@ -174,6 +180,10 @@ impl CudaDevice {
CudaStorageSlice::F64(data)
}
};
if lo != 0.0 || up != 1.0 {
let layout = Layout::contiguous(shape);
Affine(up - lo, lo).map(&slice, self, &layout)?;
}
Ok(CudaStorage {
slice,
device: self.clone(),