oneflow.Tensor.type_as

Tensor.type_as()
Returns this tensor cast to the type of the given tensor.

This is a no-op if the tensor is already of the correct type.

Parameters
  • input (Tensor) – the input tensor.

  • target (Tensor) – the tensor which has the desired type.

For example:

>>> import oneflow as flow
>>> import numpy as np

>>> input = flow.tensor(np.random.randn(1, 2, 3), dtype=flow.float32)
>>> target = flow.tensor(np.random.randn(4, 5, 6), dtype = flow.int32)
>>> input = input.type_as(target)
>>> input.dtype
oneflow.int32