Cast input to specified data type. Parameters ---------- x : tvm.te.Tensor or Expr Input argument. dtype : str Data type. span : Optional[Span] The location of the cast in the source. Returns ------- y : tvm.te.Tensor The result.
(x, dtype, span=None)
| 740 | |
| 741 | |
| 742 | def cast(x, dtype, span=None): |
| 743 | """Cast input to specified data type. |
| 744 | |
| 745 | Parameters |
| 746 | ---------- |
| 747 | x : tvm.te.Tensor or Expr |
| 748 | Input argument. |
| 749 | |
| 750 | dtype : str |
| 751 | Data type. |
| 752 | |
| 753 | span : Optional[Span] |
| 754 | The location of the cast in the source. |
| 755 | |
| 756 | Returns |
| 757 | ------- |
| 758 | y : tvm.te.Tensor |
| 759 | The result. |
| 760 | """ |
| 761 | if isinstance(x, te.tensor.Tensor): |
| 762 | return te.compute(x.shape, lambda *i: x(*i).astype(dtype), tag=tag.ELEMWISE) |
| 763 | # pylint: disable=import-outside-toplevel |
| 764 | from tvm.tirx import _ffi_api |
| 765 | |
| 766 | return _ffi_api._cast(dtype, x, span) |
| 767 | |
| 768 | |
| 769 | def reinterpret(x, dtype): |
no test coverage detected
searching dependent graphs…