mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 11:08:52 +00:00
Switch Tensor::full to return a contiguous tensor. (#2929)
This commit is contained in:
@ -382,8 +382,7 @@ impl Tensor {
|
|||||||
Self::new_impl(array, shape, device, false)
|
Self::new_impl(array, shape, device, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new tensor with all the elements having the same specified value. Note that
|
/// Returns a new tensor with all the elements having the same specified value.
|
||||||
/// the tensor is not contiguous so you would have to call `.contiguous()` on it if needed.
|
|
||||||
///```rust
|
///```rust
|
||||||
/// use candle_core::{Tensor, Device};
|
/// use candle_core::{Tensor, Device};
|
||||||
/// let a = Tensor::full(3.5, (2, 4), &Device::Cpu)?;
|
/// let a = Tensor::full(3.5, (2, 4), &Device::Cpu)?;
|
||||||
@ -398,7 +397,12 @@ impl Tensor {
|
|||||||
shape: S,
|
shape: S,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Self::from_vec_impl(vec![value], (), device, false)?.broadcast_as(shape)
|
let none = BackpropOp::none();
|
||||||
|
let shape = shape.into();
|
||||||
|
let mut storage = unsafe { device.alloc_uninit(&shape, D::DTYPE)? };
|
||||||
|
let layout = Layout::contiguous(shape.clone());
|
||||||
|
storage.const_set(value.to_scalar(), &layout)?;
|
||||||
|
Ok(from_storage(storage, shape, none, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new 1D tensor from an iterator.
|
/// Creates a new 1D tensor from an iterator.
|
||||||
|
Reference in New Issue
Block a user