mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 02:38:10 +00:00
Add rand-like/randn-like. (#333)
This commit is contained in:
@ -269,6 +269,10 @@ impl Tensor {
|
|||||||
Self::rand_impl(lo, up, s, device, false)
|
Self::rand_impl(lo, up, s, device, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rand_like(&self, lo: f64, up: f64) -> Result<Self> {
|
||||||
|
Tensor::rand_f64_impl(lo, up, self.shape(), self.dtype(), self.device(), false)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn randn_impl<S: Into<Shape>, T: crate::FloatDType>(
|
pub(crate) fn randn_impl<S: Into<Shape>, T: crate::FloatDType>(
|
||||||
mean: T,
|
mean: T,
|
||||||
std: T,
|
std: T,
|
||||||
@ -296,6 +300,17 @@ impl Tensor {
|
|||||||
Ok(from_storage(storage, s, none, is_variable))
|
Ok(from_storage(storage, s, none, is_variable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn randn_like(&self, mean: f64, stdev: f64) -> Result<Self> {
|
||||||
|
Tensor::randn_f64_impl(
|
||||||
|
mean,
|
||||||
|
stdev,
|
||||||
|
self.shape(),
|
||||||
|
self.dtype(),
|
||||||
|
self.device(),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new tensor initialized with values sampled from a normal distribution with the
|
/// Creates a new tensor initialized with values sampled from a normal distribution with the
|
||||||
/// specified `mean` and standard deviation `std`.
|
/// specified `mean` and standard deviation `std`.
|
||||||
pub fn randn<S: Into<Shape>, T: crate::FloatDType>(
|
pub fn randn<S: Into<Shape>, T: crate::FloatDType>(
|
||||||
|
Reference in New Issue
Block a user