From 0bc16a6c9d879a9f13dcb6b075193ffefb16d1c1 Mon Sep 17 00:00:00 2001 From: songyouwei Date: Mon, 6 Jan 2020 14:27:14 +0800 Subject: [PATCH] add LayerList doc (#1690) test=develop --- doc/fluid/api_cn/dygraph_cn.rst | 1 + doc/fluid/api_cn/dygraph_cn/LayerList_cn.rst | 33 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 doc/fluid/api_cn/dygraph_cn/LayerList_cn.rst diff --git a/doc/fluid/api_cn/dygraph_cn.rst b/doc/fluid/api_cn/dygraph_cn.rst index ffb9dcb7d..23b6e1357 100644 --- a/doc/fluid/api_cn/dygraph_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn.rst @@ -24,6 +24,7 @@ fluid.dygraph dygraph_cn/guard_cn.rst dygraph_cn/InverseTimeDecay_cn.rst dygraph_cn/Layer_cn.rst + dygraph_cn/LayerList_cn.rst dygraph_cn/LayerNorm_cn.rst dygraph_cn/Linear_cn.rst dygraph_cn/load_dygraph_cn.rst diff --git a/doc/fluid/api_cn/dygraph_cn/LayerList_cn.rst b/doc/fluid/api_cn/dygraph_cn/LayerList_cn.rst new file mode 100644 index 000000000..7186e7df7 --- /dev/null +++ b/doc/fluid/api_cn/dygraph_cn/LayerList_cn.rst @@ -0,0 +1,33 @@ +.. _cn_api_fluid_dygraph_LayerList: + +LayerList +------------------------------- + +.. py:class:: paddle.fluid.dygraph.LayerList(sublayers=None) + +LayerList用于保存子层列表,它包含的子层将被正确地注册和添加。列表中的子层可以像常规python列表一样被索引。 + +参数: + - **sublayers** (iterable,可选) - 要保存的子层。 + +返回:无 + +**代码示例** + +.. code-block:: python + + import paddle.fluid as fluid + import numpy as np + + class MyLayer(fluid.Layer): + def __init__(self): + super(MyLayer, self).__init__() + self.linears = fluid.dygraph.LayerList( + [fluid.dygraph.Linear(10, 10) for i in range(10)]) + def forward(self, x): + # LayerList可以像iterable一样迭代,也可以使用int索引 + for i, l in enumerate(self.linears): + x = self.linears[i // 2](x) + l(x) + return x + + -- GitLab