File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -382,8 +382,7 @@ impl Tensor {
382382 Self :: new_impl ( array, shape, device, false )
383383 }
384384
385- /// Returns a new tensor with all the elements having the same specified value. Note that
386- /// the tensor is not contiguous so you would have to call `.contiguous()` on it if needed.
385+ /// Returns a new tensor with all the elements having the same specified value.
387386 ///```rust
388387 /// use candle_core::{Tensor, Device};
389388 /// let a = Tensor::full(3.5, (2, 4), &Device::Cpu)?;
@@ -398,7 +397,12 @@ impl Tensor {
398397 shape : S ,
399398 device : & Device ,
400399 ) -> Result < Self > {
401- Self :: from_vec_impl ( vec ! [ value] , ( ) , device, false ) ?. broadcast_as ( shape)
400+ let none = BackpropOp :: none ( ) ;
401+ let shape = shape. into ( ) ;
402+ let mut storage = unsafe { device. alloc_uninit ( & shape, D :: DTYPE ) ? } ;
403+ let layout = Layout :: contiguous ( shape. clone ( ) ) ;
404+ storage. const_set ( value. to_scalar ( ) , & layout) ?;
405+ Ok ( from_storage ( storage, shape, none, false ) )
402406 }
403407
404408 /// Creates a new 1D tensor from an iterator.
You can’t perform that action at this time.
0 commit comments