MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _setitem_for_tensor_array

Function _setitem_for_tensor_array

python/paddle/base/variable_index.py:138–163  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

136
137
138def _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
166def deal_advanced_index(

Callers 1

_setitem_staticFunction · 0.85

Calls 5

to_static_variableFunction · 0.90
array_writeFunction · 0.90
NotImplementedErrorClass · 0.85
typeFunction · 0.50
castMethod · 0.45

Tested by

no test coverage detected