Rounds the values of a tensor to the nearest integer, element-wise. Rounds half to even. Also known as bankers rounding. If you want to round according to the current system rounding mode use tf::cint. For example: ```python x = tf.constant([0.9, 2.5, 2.3, 1.5, -4.5]) tf.round(x) # [
(x, name=None)
| 618 | @tf_export("math.round", "round") |
| 619 | @dispatch.add_dispatch_support |
| 620 | def round(x, name=None): # pylint: disable=redefined-builtin |
| 621 | """Rounds the values of a tensor to the nearest integer, element-wise. |
| 622 | |
| 623 | Rounds half to even. Also known as bankers rounding. If you want to round |
| 624 | according to the current system rounding mode use tf::cint. |
| 625 | For example: |
| 626 | |
| 627 | ```python |
| 628 | x = tf.constant([0.9, 2.5, 2.3, 1.5, -4.5]) |
| 629 | tf.round(x) # [ 1.0, 2.0, 2.0, 2.0, -4.0 ] |
| 630 | ``` |
| 631 | |
| 632 | Args: |
| 633 | x: A `Tensor` of type `float16`, `float32`, `float64`, `int32`, or `int64`. |
| 634 | name: A name for the operation (optional). |
| 635 | |
| 636 | Returns: |
| 637 | A `Tensor` of same shape and type as `x`. |
| 638 | """ |
| 639 | x = ops.convert_to_tensor(x, name="x") |
| 640 | if x.dtype.is_integer: |
| 641 | return x |
| 642 | else: |
| 643 | return gen_math_ops.round(x, name=name) |
| 644 | |
| 645 | |
| 646 | @tf_export("cast", "dtypes.cast") |
no outgoing calls