Skip to content

Commit ff55d4c

Browse files
committed
Polish documents
* less_than * cumsum * multiplex * open_recordio_file
1 parent 2955ff5 commit ff55d4c

File tree

8 files changed

+93
-95
lines changed

8 files changed

+93
-95
lines changed

paddle/fluid/operators/compare_op.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,22 @@ class CompareOpProtoMaker : public framework::OpProtoAndCheckerMaker {
2323
public:
2424
void Make() override {
2525
OpComment comment;
26-
AddInput("X",
27-
string::Sprintf("(LoDTensor) the left hand operand of %s operator",
28-
comment.type));
29-
AddInput("Y", string::Sprintf(
30-
"(LoDTensor) the right hand operand of %s operator",
31-
comment.type));
26+
AddInput("X", string::Sprintf("the left hand operand of %s operator",
27+
comment.type));
28+
AddInput("Y", string::Sprintf("the right hand operand of %s operator",
29+
comment.type));
3230
AddAttr<bool>("force_cpu",
33-
"(bool, default false) Force fill output variable to cpu "
31+
"Force fill output variable to cpu "
3432
"memory. Otherwise, fill output variable to the running "
35-
"device")
36-
.SetDefault(false);
37-
AddOutput("Out", string::Sprintf(
38-
"(LoDTensor) n-dim bool tensor. Each element is %s",
39-
comment.equation));
33+
"device [default true].")
34+
.SetDefault(true);
35+
AddOutput("Out", string::Sprintf("n-dim bool tensor. Each element is %s",
36+
comment.equation));
4037
AddComment(string::Sprintf(R"DOC(%s Operator
4138
4239
It operates element-wise on X and Y, and returns the Out. Each of them is a
4340
N-dim tensor. X and Y could be any type. The each element of the Out tensor is
44-
calculated by %s
41+
calculated by $%s$
4542
)DOC",
4643
comment.type, comment.equation));
4744
AddAttr<int>("axis",

paddle/fluid/operators/cumsum_op.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ class CumsumOpMaker : public framework::OpProtoAndCheckerMaker {
3333
AddInput("X", "Input of Cumsum operator");
3434
AddOutput("Out", "Output of Cumsum operator");
3535
AddAttr<int>("axis",
36-
"(int, default -1). The dimenstion to accumulate along. "
37-
"-1 means the last dimenstion")
36+
"The dimenstion to accumulate along. -1 means the last "
37+
"dimenstion [default -1].")
3838
.SetDefault(-1)
3939
.EqualGreaterThan(-1);
4040
AddAttr<bool>("exclusive",
41-
"bool, default false). Whether to perform exclusive cumsum")
41+
"Whether to perform exclusive cumsum. [default false].")
4242
.SetDefault(false);
4343
AddAttr<bool>("reverse",
44-
"bool, default false). If true, the cumsum is performed in "
45-
"the reversed direction")
44+
"If true, the cumsum is performed in the reversed direction. "
45+
"[default false].")
4646
.SetDefault(false);
4747
AddComment(R"DOC(
4848
The cumulative sum of the elements along a given axis.

paddle/fluid/operators/multiplex_op.cc

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,44 @@ class MultiplexOp : public framework::OperatorWithKernel {
6262
class MultiplexOpMaker : public framework::OpProtoAndCheckerMaker {
6363
public:
6464
void Make() override {
65-
AddInput("Ids", "The index tensor of multiplex operator.");
66-
AddInput("X", "The candidate tensors of multiplex operator.")
65+
AddInput("Ids",
66+
"Tensor<int32>, index variable which is a 2-D tensor with shape "
67+
"[M, 1] where M is the batch size.");
68+
AddInput("X",
69+
"A list of variables to gather from. All variables have the same "
70+
"shape and the rank is at least 2.")
6771
.AsDuplicable();
6872
AddOutput("Out", "The output tensor of multiplex operator.");
6973
AddComment(R"DOC(
70-
Multiplex Operator.
71-
72-
Multiplex multiple tensors according to the index provided by the index tensor.
73-
74-
Ids: the index tensor.
75-
X[0 : N - 1]: the candidate tensors for output (N >= 2).
76-
For each index i from 0 to batchSize - 1, the output is the i-th row of the
74+
Referring to the given index variable, this layer selects rows from the
75+
input variables to construct a multiplex variable. Assuming that there are
76+
:math:`m` input variables and :math:`I_i` represents the i-th input
77+
variable and :math:`i` is in [0, :math:`m`). All input variables are
78+
tensors with same shape [:math:`d_0`, :math:`d_1`, ..., :math:`d_R`].
79+
Please note that rank of the input tensor should be at least 2. Each input
80+
variable will be treated as a 2-D matrix with shape [:math:`M`, :math:`N`]
81+
where :math:`M` for :math:`d_0` and :math:`N` for :math:`d_1` * :math:`d_2`
82+
* ... * :math:`d_R`. Let :math:`I_i[j]` be the j-th row of the i-th input
83+
variable. The given index variable should be a 2-D tensor with shape
84+
[:math:`M`, 1]. Let `ID[i]` be the i-th index value of the index variable.
85+
Then the output variable will be a tensor with shape [:math:`d_0`,
86+
:math:`d_1`, ..., :math:`d_R`]. If we treat the output tensor as a 2-D
87+
matrix with shape [:math:`M`, :math:`N`] and let :math:`O[i]` be the i-th
88+
row of the matrix, then `O[i]` is equal to :math:`I_{ID[i]}[i]`.
89+
90+
* Ids: the index tensor.
91+
92+
* X[0 : N - 1]: the candidate tensors for output (N >= 2).
93+
94+
* For each index i from 0 to batchSize - 1, the output is the i-th row of the
7795
the (Ids[i])-th tensor.
7896
7997
For i-th row of the output tensor:
8098
81-
$$y[i] = x_{k}[i]$$
99+
$ y[i] = x_{k}[i] $
82100
83-
where `y` is the output tensor, `x_{k}` is the k-th input tensor,
84-
and `k = Ids[i]`.
101+
where $y$ is the output tensor, $x_{k}$ is the k-th input tensor,
102+
and $k = Ids[i]$.
85103
86104
)DOC");
87105
}

paddle/fluid/operators/reader/create_recordio_file_reader_op.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ class CreateRecordIOReaderOp : public framework::OperatorBase {
7878
class CreateRecordIOReaderOpMaker : public FileReaderMakerBase {
7979
protected:
8080
void Apply() override {
81-
AddAttr<std::string>("filename", "The filename of record io reader");
81+
AddAttr<std::string>(
82+
"filename",
83+
"The filename of record file. This file will given to reader.");
8284
AddComment(R"DOC(
83-
CreateRecordIOReader Operator
85+
Open a recordio file and return the reader object. The returned reader object
86+
is thread-safe.
8487
85-
Create a reader from a record io file
88+
NOTE: This is a very low-level API. It is used for debugging data file or
89+
training. Please use `open_files` instead of this API for production usage.
8690
)DOC");
8791
}
8892
};

paddle/fluid/operators/reader/reader_op_registry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::unique_ptr<framework::ReaderBase> CreateReaderByFileName(
5454
}
5555

5656
void FileReaderMakerBase::Make() {
57-
AddOutput("Out", "(ReaderHolder) The created random reader.").AsDuplicable();
57+
AddOutput("Out", "(ReaderHolder): The created random reader.").AsDuplicable();
5858
AddAttr<std::vector<int>>("shape_concat", "The concat of all data's shapes.");
5959
AddAttr<std::vector<int>>(
6060
"ranks",

python/paddle/fluid/layers/control_flow.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -909,37 +909,40 @@ def create_array(dtype):
909909
dtype=dtype)
910910

911911

912-
def less_than(x, y, force_cpu=True, cond=None, **ignored):
912+
@templatedoc()
913+
def less_than(x, y, force_cpu=None, cond=None, **ignored):
913914
"""
914-
**Less than**
915+
${comment}
915916
916-
This layer returns the truth value of :math:`x < y` elementwise.
917+
>>> import paddle.fluid as fluid
918+
>>> less = fluid.layers.less_than(x=label, y=limit)
917919
918920
Args:
919-
x(Variable): First operand of *less_than*
920-
y(Variable): Second operand of *less_than*
921-
force_cpu(Bool|True): The output data will be on CPU if set true.
921+
x(${x_type}): ${x_comment}.
922+
y(${y_type}): ${y_comment}.
923+
force_cpu(${force_cpu_type}): ${force_cpu_comment}.
922924
cond(Variable|None): Optional output variable to store the result of *less_than*
923925
924926
Returns:
925-
Variable: The tensor variable storing the output of *less_than*.
926-
927-
Examples:
928-
.. code-block:: python
929-
930-
less = fluid.layers.less_than(x=label, y=limit)
927+
${out_comment}.
931928
"""
932929
helper = LayerHelper("less_than", **locals())
933930
if cond is None:
934931
cond = helper.create_tmp_variable(dtype='bool')
935932
cond.stop_gradient = True
936933

934+
attrs = dict()
935+
if force_cpu is not None:
936+
attrs['force_cpu'] = force_cpu
937+
elif force_init_on_cpu():
938+
attrs['force_cpu'] = force_init_on_cpu()
939+
937940
helper.append_op(
938941
type='less_than',
939942
inputs={'X': [x],
940943
'Y': [y]},
941944
outputs={'Out': [cond]},
942-
attrs={'force_cpu': force_cpu or force_init_on_cpu()})
945+
attrs=attrs)
943946
return cond
944947

945948

python/paddle/fluid/layers/io.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,41 +292,36 @@ def _copy_reader_create_op_(block, op):
292292
return new_op
293293

294294

295+
@templatedoc(op_type='create_recordio_file_reader')
295296
def open_recordio_file(filename,
296297
shapes,
297298
lod_levels,
298299
dtypes,
299300
pass_num=1,
300301
for_parallel=True):
301302
"""
302-
Open a RecordIO file
303+
${comment}
303304
304-
This layer takes a RecordIO file to read from and returns a Reader Variable.
305-
Via the Reader Variable, we can get data from the given RecordIO file.
305+
>>> import paddle.fluid as fluid
306+
>>> reader = fluid.layers.io.open_recordio_file(
307+
>>> filename='./data.recordio',
308+
>>> shapes=[(3,224,224), (1)],
309+
>>> lod_levels=[0, 0],
310+
>>> dtypes=['float32', 'int64'])
311+
>>> # Via the reader, we can use 'read_file' layer to get data:
312+
>>> image, label = fluid.layers.io.read_file(reader)
306313
307314
Args:
308-
filename(str): The RecordIO file's name.
315+
filename(${filename_type}): ${filename_comment}.
309316
shapes(list): List of tuples which declaring data shapes.
310-
lod_levels(list): List of ints which declaring data lod_level.
317+
lod_levels(${lod_levels_type}): ${lod_levels_comment}.
311318
dtypes(list): List of strs which declaring data type.
312319
pass_num(int): Number of passes to run.
313320
for_parallel(Bool): Set it as True if you are going to run
314321
subsequent operators in parallel.
315322
316323
Returns:
317-
Variable: A Reader Variable via which we can get RecordIO file data.
318-
319-
Examples:
320-
.. code-block:: python
321-
322-
reader = fluid.layers.io.open_recordio_file(
323-
filename='./data.recordio',
324-
shapes=[(3,224,224), (1)],
325-
lod_levels=[0, 0],
326-
dtypes=['float32', 'int64'])
327-
328-
# Via the reader, we can use 'read_file' layer to get data:
329-
image, label = fluid.layers.io.read_file(reader)
324+
${out_comment}.
330325
"""
331326
dtypes = [convert_np_dtype_to_dtype_(dt) for dt in dtypes]
332327
shape_concat = []

python/paddle/fluid/layers/nn.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,42 +3210,23 @@ def row_conv(input, future_context_size, param_attr=None, act=None):
32103210
return helper.append_activation(out)
32113211

32123212

3213+
@templatedoc()
32133214
def multiplex(inputs, index):
32143215
"""
3215-
**Multiplex Layer**
3216-
3217-
Referring to the given index variable, this layer selects rows from the
3218-
input variables to construct a multiplex variable. Assuming that there are
3219-
:math:`m` input variables and :math:`I_i` represents the i-th input
3220-
variable and :math:`i` is in [0, :math:`m`). All input variables are
3221-
tensors with same shape [:math:`d_0`, :math:`d_1`, ..., :math:`d_R`].
3222-
Please note that rank of the input tensor should be at least 2. Each input
3223-
variable will be treated as a 2-D matrix with shape [:math:`M`, :math:`N`]
3224-
where :math:`M` for :math:`d_0` and :math:`N` for :math:`d_1` * :math:`d_2`
3225-
* ... * :math:`d_R`. Let :math:`I_i[j]` be the j-th row of the i-th input
3226-
variable. The given index variable should be a 2-D tensor with shape
3227-
[:math:`M`, 1]. Let `ID[i]` be the i-th index value of the index variable.
3228-
Then the output variable will be a tensor with shape [:math:`d_0`,
3229-
:math:`d_1`, ..., :math:`d_R`]. If we treat the output tensor as a 2-D
3230-
matrix with shape [:math:`M`, :math:`N`] and let :math:`O[i]` be the i-th
3231-
row of the matrix, then `O[i]` is equal to :math:`I_{ID[i]}[i]`.
3216+
${comment}
3217+
3218+
>>> import paddle.fluid as fluid
3219+
>>> x1 = fluid.layers.data(name='x1', shape=[4], dtype='float32')
3220+
>>> x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32')
3221+
>>> index = fluid.layers.data(name='index', shape=[1], dtype='int32')
3222+
>>> out = fluid.layers.multiplex(inputs=[x1, x2], index=index)
32323223
32333224
Args:
3234-
inputs (list): A list of variables to gather from. All variables have the
3235-
same shape and the rank is at least 2.
3236-
index (Variable): Tensor<int32>, index variable which is a 2-D tensor
3237-
with shape [M, 1] where M is the batch size.
3225+
inputs (list): ${x_comment}.
3226+
index (${ids_type}): ${ids_comment}.
32383227
32393228
Returns:
3240-
Variable: Multiplex variable gathered from input variables.
3241-
3242-
Examples:
3243-
.. code-block:: python
3244-
3245-
x1 = fluid.layers.data(name='x1', shape=[4], dtype='float32')
3246-
x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32')
3247-
index = fluid.layers.data(name='index', shape=[1], dtype='int32')
3248-
out = fluid.layers.multiplex(inputs=[x1, x2], index=index)
3229+
${out_comment}.
32493230
"""
32503231
helper = LayerHelper('multiplex', **locals())
32513232

0 commit comments

Comments
 (0)