Commit a8c3de3b authored by Derek Murray's avatar Derek Murray Committed by TensorFlower Gardener
Browse files

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
parent c0e82340
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment