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

Function _setitem_static

python/paddle/base/variable_index.py:430–714  ·  view source on GitHub ↗

In dynamic mode, this function will modify the value at input tensor, returning same Tensor as input. But it will return a new Tensor with assigned value in static mode. Args: x(Tensor): Tensor to be set value. indices(int|slice|None|Tensor|List|Tuple...): Indices, used

(x, indices, values)

Source from the content-addressed store, hash-verified

428
429
430def _setitem_static(x, indices, values):
431 """
432 In dynamic mode, this function will modify the value at input tensor, returning same Tensor as input.
433 But it will return a new Tensor with assigned value in static mode.
434
435 Args:
436 x(Tensor): Tensor to be set value.
437 indices(int|slice|None|Tensor|List|Tuple...): Indices, used to indicate the position of the element to be fetched.
438 values(Tensor|Number|Ndarray): values to be assigned to the x.
439 """
440 from . import in_dynamic_or_pir_mode
441 from .framework import Variable, in_pir_mode
442
443 is_tensor_array = is_tensor_array_type(x)
444
445 if is_tensor_array:
446 return _setitem_for_tensor_array(x, indices, values)
447
448 # step1: parsing the index and recording them
449 (
450 starts,
451 ends,
452 steps,
453 axes,
454 none_axes,
455 decrease_axes,
456 advanced_index,
457 has_advanced_index,
458 use_strided_slice,
459 ) = parse_index(x, indices)
460
461 inputs = {'Input': x}
462 attrs = {
463 'axes': axes,
464 'starts': starts,
465 'ends': ends,
466 'steps': steps,
467 'decrease_axes': decrease_axes,
468 'none_axes': none_axes,
469 }
470
471 value_tensor = None
472 StartsTensorList = None
473 EndsTensorList = None
474 StepsTensorList = None
475 shape = None
476
477 if paddle.utils._contain_var(starts):
478 StartsTensorList = paddle.utils._convert_to_tensor_list(starts)
479 inputs['StartsTensorList'] = StartsTensorList
480 del attrs['starts']
481
482 if paddle.utils._contain_var(ends):
483 EndsTensorList = paddle.utils._convert_to_tensor_list(ends)
484 inputs['EndsTensorList'] = EndsTensorList
485 del attrs['ends']
486 if paddle.utils._contain_var(steps):
487 StepsTensorList = paddle.utils._convert_to_tensor_list(steps)

Calls 15

is_tensor_array_typeFunction · 0.85
parse_indexFunction · 0.85
listFunction · 0.85
TypeErrorClass · 0.85
in_dynamic_or_pir_modeFunction · 0.85
in_pir_modeFunction · 0.85
deal_advanced_indexFunction · 0.85
astypeMethod · 0.80
tolistMethod · 0.80