In tensorflow what is the difference between tf.add and operator ?

In tensorflow what is the difference between tf.add and operator ?

Asked on December 26, 2018 in Tensorflow.
Add Comment

  • 1 Answer(s)

        The a+b and tf.add(a, b) has no difference in precision. The a+b translates to a.__add__(b) this will mapped to tf.add.

    _OverrideBinaryOperatorHelper(gen_math_ops.add, "add")

        The Difference is that their node name in the hidden graph is add rather than Add. Just compare things by referring the hidden graph representation like the below code:

    dtype = tf.int32
    a = tf.placeholder(dtype)
    b = tf.placeholder(dtype)
    c = a+b

        Look this directly by examine the __add__ method.

    real_function = tf.Tensor.__add__.im_func.func_closure[0].cell_contents
    print(real_function.__module__ + "." + real_function.__name__)
    print(tf.add.__module__ + "." + tf.add.__name__)

        This shows output like this which means that they call same underlying function


        Below are some of the Python special methods which is potentially overloaded by suitable TensorFlow versions see it from tf.Tensor.OVERLOADABLE_OPERATORS.

    Answered on December 26, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.