oneflow.full¶
-
oneflow.
full
(size: Union[int, Tuple[int, …], oneflow.Size], fill_value: Union[float, int, complex], dtype: Optional[oneflow._oneflow_internal.dtype] = None, device: Optional[Union[oneflow._oneflow_internal.device, str]] = None, placement: Optional[oneflow._oneflow_internal.placement] = None, sbp: Optional[Union[oneflow._oneflow_internal.sbp.sbp, List[oneflow._oneflow_internal.sbp.sbp]]] = None, requires_grad: bool = False)¶ Creates a tensor of size size filled with fill_value. The tensor’s dtype is inferred from value.
- Parameters
size (int...) – a list, tuple, or oneflow.Size of integers defining the shape of the output tensor.
fill_value (Scalar) – the value to fill the output tensor with.
dtype (oneflow.dtype, optional) – the desired data type of returned tensor.
device (oneflow.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type
placement (oneflow.placement, optional) – the desired placement of returned global tensor. Default: if None, the returned tensor is local one using the argument device.
sbp (oneflow.sbp.sbp or tuple of oneflow.sbp.sbp, optional) – the desired sbp descriptor of returned global tensor. Default: if None, the returned tensor is local one using the argument device.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
For example:
>>> import oneflow as flow >>> y = flow.full((5,),5) >>> y tensor([5, 5, 5, 5, 5], dtype=oneflow.int64) >>> y = flow.full((2,3),5.0) # construct local tensor >>> y tensor([[5., 5., 5.], [5., 5., 5.]], dtype=oneflow.float32) >>> placement = flow.placement("cpu", ranks=[0]) >>> y = flow.full((2,3), 5.0, placement=placement, sbp=flow.sbp.broadcast) # construct global tensor >>> y.is_global True