summaryrefslogtreecommitdiff
path: root/candle-core/src/tensor.rs
diff options
context:
space:
mode:
authorLaurent Mazare <laurent.mazare@gmail.com>2023-08-06 22:51:08 +0200
committerGitHub <noreply@github.com>2023-08-06 21:51:08 +0100
commit2c9f6059760c2c6bb62c6ceac3fd283f52d39fe8 (patch)
treea920f12ad7d6073b168f5d9c92ec60bae7df7ee2 /candle-core/src/tensor.rs
parent141df4ad2b80f0691450f32b28bcc2314301050b (diff)
downloadcandle-2c9f6059760c2c6bb62c6ceac3fd283f52d39fe8.tar.gz
candle-2c9f6059760c2c6bb62c6ceac3fd283f52d39fe8.tar.bz2
candle-2c9f6059760c2c6bb62c6ceac3fd283f52d39fe8.zip
Add rand-like/randn-like. (#333)
Diffstat (limited to 'candle-core/src/tensor.rs')
-rw-r--r--candle-core/src/tensor.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/candle-core/src/tensor.rs b/candle-core/src/tensor.rs
index 170b3fda..ff381620 100644
--- a/candle-core/src/tensor.rs
+++ b/candle-core/src/tensor.rs
@@ -269,6 +269,10 @@ impl Tensor {
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>(
mean: T,
std: T,
@@ -296,6 +300,17 @@ impl Tensor {
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
/// specified `mean` and standard deviation `std`.
pub fn randn<S: Into<Shape>, T: crate::FloatDType>(