Set `__array_priority__` on Variable to make numpy operator overloading work.
This fixes a bug whereby using a `tf.Variable` as the right argument to an overloaded math operator (e.g. `__mul__`) when the left argument is an ndarray would produce an incorrect result (e.g. returning an `np.object` ndarray where each element is the corresponding element of the LHS, scalar multiplied by the variable). For example, before: ```python >>> arr = np.array([1, 2, 3], dtype=np.int32) >>> v = tf.Variable([1, 2, 3]) >>> result = arr * v >>> print result array([<tf.Tensor ...>, <tf.Tensor ...>, <tf.Tensor ...>], dtype=object) >>> print result.eval() AttributeError: ... ``` ...and after: ```python >>> ... >>> print result <tf.Tensor ...> >>> print result.eval() array([1, 4, 9], dtype=int32) ``` Fixes #2289. Change: 124985637
Loading
Please sign in to comment