def floordiv(x, y, name=None): """Divides `x / y` elementwise, rounding down for floating point. The same as `tf.div(x,y)` for integers, but uses `tf.floor(tf.div(x,y))` for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by `x // y` floor division in Python 3 and in Python 2.7 with `from __future__ import division`. Note that for efficiency, `floordiv` uses C semantics for negative numbers (unlike Python and Numpy). `x` and `y` must have the same type, and the result will have the same type as well. Args: x: `Tensor` numerator of real numeric type. y: `Tensor` denominator of real numeric type. name: A name for the operation (optional). Returns: `x / y` rounded down (except possibly towards zero for negative integers). Raises: TypeError: If the inputs are complex. """ with ops.op_scope([x, y], name, "floordiv") as name: x = ops.convert_to_tensor(x, name="x") dtype = x.dtype if dtype.is_floating: return gen_math_ops.floor(gen_math_ops.div(x, y), name=name) else: if not dtype.is_integer: raise TypeError("Expected floating point or integer, got %r" % dtype) return gen_math_ops.div(x, y, name=name)
def round(x, name=None): """Rounds the values of a tensor to the nearest integer, element-wise. For example: ```python # 'a' is [0.9, 2.5, 2.3, -4.4] tf.round(a) ==> [ 1.0, 3.0, 2.0, -4.0 ] ``` Args: x: A `Tensor` of type `float` or `double`. name: A name for the operation (optional). Returns: A `Tensor` of same shape and type as `x`. """ x = ops.convert_to_tensor(x, name="x") if x.dtype.is_integer: return x else: return gen_math_ops.floor(x + 0.5, name=name)