Applies an inplace op on (x, i, v). op is one of gen_array_ops.alias_inplace_update, gen_array_ops.alias_inplace_add, or gen_array_ops.alias_inplace_sub. If i is None, x and v must be the same shape. Computes x op v; If i is a scalar, x has a rank 1 higher than v's. Computes x[i, :
(x, i, v, op)
| 28 | |
| 29 | |
| 30 | def _inplace_helper(x, i, v, op): |
| 31 | """Applies an inplace op on (x, i, v). |
| 32 | |
| 33 | op is one of gen_array_ops.alias_inplace_update, |
| 34 | gen_array_ops.alias_inplace_add, or gen_array_ops.alias_inplace_sub. |
| 35 | |
| 36 | If i is None, x and v must be the same shape. Computes |
| 37 | x op v; |
| 38 | If i is a scalar, x has a rank 1 higher than v's. Computes |
| 39 | x[i, :] op v; |
| 40 | Otherwise, x and v must have the same rank. Computes |
| 41 | x[i, :] op v; |
| 42 | |
| 43 | Args: |
| 44 | x: A Tensor. |
| 45 | i: None, a scalar or a vector. |
| 46 | v: A Tensor. |
| 47 | op: alias_inplace_update, alias_inplace_add, or alias_inplace_sub. |
| 48 | |
| 49 | Returns: |
| 50 | Returns x. |
| 51 | |
| 52 | """ |
| 53 | x = ops.convert_to_tensor(x) |
| 54 | v = ops.convert_to_tensor(v, x.dtype) |
| 55 | if i is None: |
| 56 | # Full tensor. |
| 57 | return array_ops.reshape( |
| 58 | op(array_ops.reshape(x, [1, -1]), [0], array_ops.reshape(v, [1, -1])), |
| 59 | array_ops.shape(x)) |
| 60 | i = math_ops.cast(i, dtypes.int32) |
| 61 | if i.get_shape().ndims == 0: |
| 62 | # Single 0-dim update. |
| 63 | return op(x, array_ops.reshape(i, [1]), array_ops.expand_dims(v, 0)) |
| 64 | return op(x, i, v) |
| 65 | |
| 66 | |
| 67 | @deprecation.deprecated( |
no test coverage detected