summaryrefslogtreecommitdiff
path: root/candle-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'candle-core/src')
-rw-r--r--candle-core/src/tensor.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/candle-core/src/tensor.rs b/candle-core/src/tensor.rs
index e1cae41c..e6e7b415 100644
--- a/candle-core/src/tensor.rs
+++ b/candle-core/src/tensor.rs
@@ -361,6 +361,16 @@ impl Tensor {
Self::new_impl(array, shape, device, false)
}
+ /// Returns a new tensor with all the elements having the same specified value. Note that
+ /// the tensor is not contiguous so you would have to call `.contiguous()` on it if needed.
+ pub fn full<D: crate::WithDType, S: Into<Shape>>(
+ value: D,
+ shape: S,
+ device: &Device,
+ ) -> Result<Self> {
+ Self::from_vec_impl(vec![value], (), device, false)?.broadcast_as(shape)
+ }
+
/// Creates a new 1D tensor from an iterator.
pub fn from_iter<D: crate::WithDType>(
iter: impl IntoIterator<Item = D>,