oneflow.full_like¶
-
oneflow.
full_like
(input, fill_value, \*, dtype=None, device=None, placement=None, sbp=None, requires_grad=False) → Tensor¶ Returns a tensor with the same size as
input
filled withfill_value
.oneflow.full_like(input, fill_value)
is equivalent tooneflow.full(input.size(), fill_value, dtype=input.dtype, device=input.device)
.The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.full_like.html.
- Parameters
input (oneflow.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 >>> x = flow.randn(2, 3) >>> y = flow.full_like(x, 2.0) >>> y tensor([[2., 2., 2.], [2., 2., 2.]], dtype=oneflow.float32) >>> y = flow.full_like(x, 2, dtype=flow.int32) >>> y tensor([[2, 2, 2], [2, 2, 2]], dtype=oneflow.int32) >>> placement = flow.placement("cpu", ranks=[0]) >>> y = flow.full_like(x, 5.0, placement=placement, sbp=flow.sbp.broadcast) # construct global tensor >>> y.is_global True