Skip to content

Commit 92d9bdf

Browse files
authored
fix api doc in slice op, test=develop (#17804)
1 parent 473777a commit 92d9bdf

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

paddle/fluid/API.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ paddle.fluid.layers.gaussian_random (ArgSpec(args=['shape', 'mean', 'std', 'seed
197197
paddle.fluid.layers.sampling_id (ArgSpec(args=['x', 'min', 'max', 'seed', 'dtype'], varargs=None, keywords=None, defaults=(0.0, 1.0, 0, 'float32')), ('document', '35428949368cad5121dd37f8522ef8b0'))
198198
paddle.fluid.layers.gaussian_random_batch_size_like (ArgSpec(args=['input', 'shape', 'input_dim_idx', 'output_dim_idx', 'mean', 'std', 'seed', 'dtype'], varargs=None, keywords=None, defaults=(0, 0, 0.0, 1.0, 0, 'float32')), ('document', '9e520987168f8ddb7dd71ffd68aa352c'))
199199
paddle.fluid.layers.sum (ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None), ('document', 'a418e3ccb5e2ac21bd60f5cc221d5860'))
200-
paddle.fluid.layers.slice (ArgSpec(args=['input', 'axes', 'starts', 'ends'], varargs=None, keywords=None, defaults=None), ('document', 'bcb6380dbcf288058f8c1e14b82cbe0d'))
200+
paddle.fluid.layers.slice (ArgSpec(args=['input', 'axes', 'starts', 'ends'], varargs=None, keywords=None, defaults=None), ('document', '3ca6a761570d86e303e473afba99bb49'))
201201
paddle.fluid.layers.shape (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'bf61c8f79d795a8371bdb3b5468aa82b'))
202202
paddle.fluid.layers.rank (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', 'ee1386c42ecc8f424fe3fb21862fefc2'))
203203
paddle.fluid.layers.logical_and (ArgSpec(args=['x', 'y', 'out', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'cdcf20c494c92060d10feb9374532f42'))

paddle/fluid/operators/slice_op.cc

+19-19
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,27 @@ the start or end indices, it represents number of elements before the end
9797
of that dimension. If the value passed to start or end is larger than
9898
the n (the number of elements in this dimension), it represents n.
9999
For slicing to the end of a dimension with unknown size, it is recommended
100-
to pass in INT_MAX. If axes are omitted, they are set to [0, ..., ndim-1].
100+
to pass in INT_MAX. The size of axes must be equal to starts\' and ends\'.
101101
Following examples will explain how slice works:
102102
103-
.. code-block:: text
104-
105-
Cast1:
106-
Given:
107-
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
108-
axes = [0, 1]
109-
starts = [1, 0]
110-
ends = [2, 3]
111-
Then:
112-
result = [ [5, 6, 7], ]
113-
114-
Cast2:
115-
Given:
116-
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
117-
starts = [0, 1]
118-
ends = [-1, 1000]
119-
Then:
120-
result = [ [2, 3, 4], ]
103+
.. code-block:: text
104+
105+
Case1:
106+
Given:
107+
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
108+
axes = [0, 1]
109+
starts = [1, 0]
110+
ends = [2, 3]
111+
Then:
112+
result = [ [5, 6, 7], ]
113+
114+
Case2:
115+
Given:
116+
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
117+
starts = [0, 1]
118+
ends = [-1, 1000]
119+
Then:
120+
result = [ [2, 3, 4], ]
121121
)DOC");
122122
}
123123
};

python/paddle/fluid/layers/nn.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -9587,8 +9587,39 @@ def sum(x):
95879587
@templatedoc()
95889588
def slice(input, axes, starts, ends):
95899589
"""
9590-
${comment}
9590+
Slice Operator.
9591+
9592+
Produces a slice of the input tensor along multiple axes. Similar to numpy:
9593+
https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
9594+
Slice uses `axes`, `starts` and `ends` attributes to specify the start and
9595+
end dimension for each axis in the list of axes, it uses this information
9596+
to slice the input data tensor. If a negative value is passed for any of
9597+
the start or end indices, it represents number of elements before the end
9598+
of that dimension. If the value passed to start or end is larger than
9599+
the n (the number of elements in this dimension), it represents n.
9600+
For slicing to the end of a dimension with unknown size, it is recommended
9601+
to pass in INT_MAX. The size of axes must be equal to starts\' and ends\'.
9602+
Following examples will explain how slice works:
9603+
9604+
.. code-block:: text
95919605
9606+
Case1:
9607+
Given:
9608+
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
9609+
axes = [0, 1]
9610+
starts = [1, 0]
9611+
ends = [2, 3]
9612+
Then:
9613+
result = [ [5, 6, 7], ]
9614+
9615+
Case2:
9616+
Given:
9617+
data = [ [1, 2, 3, 4], [5, 6, 7, 8], ]
9618+
axes = [0, 1]
9619+
starts = [0, 1]
9620+
ends = [-1, 1000]
9621+
Then:
9622+
result = [ [2, 3, 4], ]
95929623
Args:
95939624
input (Variable): ${input_comment}.
95949625
axes (List): ${axes_comment}

0 commit comments

Comments
 (0)