branches for tensor array setitem operation. A item can be a: (1) int/Variable, which is a simple number/variable such as [1], [-2] (2) Slice, which is represented by bounds such as [2:-1] (3) Tuple, which includes the above two cases such as [2:-1, 1] If item is case (1), we per
(var, item, value)
| 136 | |
| 137 | |
| 138 | def _setitem_for_tensor_array(var, item, value): |
| 139 | """branches for tensor array setitem operation. |
| 140 | A item can be a: |
| 141 | (1) int/Variable, which is a simple number/variable such as [1], [-2] |
| 142 | (2) Slice, which is represented by bounds such as [2:-1] |
| 143 | (3) Tuple, which includes the above two cases such as [2:-1, 1] |
| 144 | If item is case (1), we perform paddle.tensor.array_write, |
| 145 | in other cases, we raise a NotImplementedError. |
| 146 | """ |
| 147 | |
| 148 | from .framework import Variable |
| 149 | |
| 150 | assert not paddle.in_dynamic_mode(), ( |
| 151 | "setitem for tensor_array must be called in static graph mode." |
| 152 | ) |
| 153 | if isinstance(item, (Variable, paddle.pir.Value, int)): |
| 154 | from paddle.jit.dy2static.convert_operators import to_static_variable |
| 155 | from paddle.tensor import array_write |
| 156 | |
| 157 | item = paddle.cast(to_static_variable(item), dtype='int64') |
| 158 | value = to_static_variable(value) |
| 159 | return array_write(x=value, i=item, array=var) |
| 160 | else: |
| 161 | raise NotImplementedError( |
| 162 | f"Only support __setitem__ by Int/Variable in tensor_array, but gets {type(item)}" |
| 163 | ) |
| 164 | |
| 165 | |
| 166 | def deal_advanced_index( |
no test coverage detected