MCPcopy Create free account
hub / github.com/apache/tvm / strided_slice_python

Function strided_slice_python

python/tvm/topi/testing/strided_slice_python.py:20–89  ·  view source on GitHub ↗

Python version of strided slice operator. Parameters ---------- data : numpy.ndarray Input data begin : list Beginning of the slices. end : list End of the slices. strides : list The stride of each slice. slice_mode : str, optional

(data, begin, end, strides, slice_mode="end", axes=None)

Source from the content-addressed store, hash-verified

18
19
20def strided_slice_python(data, begin, end, strides, slice_mode="end", axes=None):
21 """Python version of strided slice operator.
22
23 Parameters
24 ----------
25 data : numpy.ndarray
26 Input data
27
28 begin : list
29 Beginning of the slices.
30
31 end : list
32 End of the slices.
33
34 strides : list
35 The stride of each slice.
36
37 slice_mode : str, optional
38 The slice mode [end, size].
39
40 - ``"end"``: The default slice mode, ending indices for the slice.
41 - ``"size"``: The input strides will be ignored, input end in this mode indicates
42 the size of a slice starting at the location specified by begin. If end[i] is -1,
43 all remaining elements in that dimension are included in the slice.
44
45 axes : list, optional
46 Axes along which slicing is applied
47
48 Returns
49 -------
50 result : numpy.ndarray
51 The sliced result.
52 """
53 strides = [] if strides is None else strides
54 if axes is not None:
55 rank = len(data.shape)
56 new_begin = [0] * rank
57 new_end = [data.shape[i] for i in range(rank)]
58 new_strides = [1] * rank
59
60 for i, axis in enumerate(axes):
61 new_begin[axis] = begin[i]
62 new_end[axis] = end[i]
63 if len(strides) > i:
64 new_strides[axis] = strides[i]
65
66 begin = new_begin
67 end = new_end
68 strides = new_strides
69
70 slices = []
71 for i in range(len(data.shape)):
72 new_stride = None
73 if slice_mode == "end" and i < len(strides):
74 new_stride = strides[i]
75
76 new_begin = begin[i] if i < len(begin) else None
77 if i >= len(end):

Callers 1

batch_to_space_nd_pythonFunction · 0.90

Calls 2

tupleFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…