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

Function _getitem_static

python/paddle/base/variable_index.py:842–916  ·  view source on GitHub ↗

Args: x(Tensor): Tensor to be indexing. indices(int|slice|None|Tensor|List|Tuple...): Indices, used to indicate the position of the element to be fetched.

(x, indices)

Source from the content-addressed store, hash-verified

840
841
842def _getitem_static(x, indices):
843 """
844 Args:
845 x(Tensor): Tensor to be indexing.
846 indices(int|slice|None|Tensor|List|Tuple...): Indices, used to indicate the position of the element to be fetched.
847 """
848 # step1: parsing the index and recording them
849 (
850 starts,
851 ends,
852 steps,
853 axes,
854 none_axes,
855 decrease_axes,
856 advanced_index,
857 has_advanced_index,
858 use_strided_slice,
859 ) = parse_index(x, indices)
860
861 # step2: Dealing with basic indexing
862 out, _ = get_tensor_with_basic_indexing(
863 x,
864 axes,
865 starts,
866 ends,
867 steps,
868 decrease_axes,
869 none_axes,
870 use_strided_slice,
871 )
872
873 # step3: Dealing with advanced indexing
874 if has_advanced_index:
875 (
876 transed_tensor,
877 adjusted_advanced_index,
878 _,
879 pos_of_new_dim,
880 rank_of_new_dim,
881 _,
882 _,
883 ) = deal_advanced_index(out, advanced_index, False, None)
884
885 # TODO(zooooo0820): Replacing gather_nd to another advanced OP for handling of mixed indexes more efficiently
886 if len(adjusted_advanced_index) == 1 and adjusted_advanced_index[
887 0
888 ].dtype in (paddle.bool, paddle.base.libpaddle.BOOL):
889 # Note: now slice not support 0-size Tensor, so only one bool tensor can return empty 0-size.
890 out = get_value_for_bool_tensor(
891 transed_tensor, adjusted_advanced_index[0]
892 )
893 else:
894 adjusted_advanced_index = parse_bool_and_broadcast_indices(
895 adjusted_advanced_index
896 )
897
898 if len(adjusted_advanced_index) > 1:
899 advanced_index_tensor = paddle.stack(

Callers 15

test_combined_index_1Method · 0.90
test_combined_index_2Method · 0.90
test_combined_index_3Method · 0.90
test_combined_index_4Method · 0.90
test_combined_index_5Method · 0.90
test_combined_index_6Method · 0.90
test_combined_index_7Method · 0.90
test_combined_index_8Method · 0.90
test_combined_index_9Method · 0.90

Calls 10

parse_indexFunction · 0.85
deal_advanced_indexFunction · 0.85
listFunction · 0.85
rangeFunction · 0.85
unsqueezeMethod · 0.80
stackMethod · 0.45
transposeMethod · 0.45

Tested by 15

test_combined_index_1Method · 0.72
test_combined_index_2Method · 0.72
test_combined_index_3Method · 0.72
test_combined_index_4Method · 0.72
test_combined_index_5Method · 0.72
test_combined_index_6Method · 0.72
test_combined_index_7Method · 0.72
test_combined_index_8Method · 0.72
test_combined_index_9Method · 0.72