Add a simple full method. (#1455)

* Add a simple implementation of the full method.

* Add the docstring.
This commit is contained in:
Laurent Mazare
2023-12-17 20:15:57 -05:00
committed by GitHub
parent 94817dac56
commit 96f1a28e39
2 changed files with 19 additions and 0 deletions

View File

@ -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>,