From c9d7a1735f31d304006e49cfc7c852b0a0cb19d0 Mon Sep 17 00:00:00 2001 From: cc <52520497+juncaipeng@users.noreply.github.com> Date: Wed, 23 Sep 2020 10:37:37 +0800 Subject: [PATCH] [doc] Add example for buffered and cache, test=develop, test=document_fix (#2677) * Add example for buffered and cache, test=develop, test=document_fix * up, test=develop;test=document_fix --- doc/paddle/api/paddle/io/buffered_cn.rst | 23 ++++++++++++++++++++--- doc/paddle/api/paddle/io/cache_cn.rst | 23 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/doc/paddle/api/paddle/io/buffered_cn.rst b/doc/paddle/api/paddle/io/buffered_cn.rst index 027c6346f..626bda6f1 100644 --- a/doc/paddle/api/paddle/io/buffered_cn.rst +++ b/doc/paddle/api/paddle/io/buffered_cn.rst @@ -1,9 +1,9 @@ -.. _cn_api_fluid_io_buffered: +.. _cn_api_io_buffered: buffered ------------------------------- -.. py:function:: paddle.fluid.io.buffered(reader, size) +.. py:function:: paddle.io.buffered(reader, size) @@ -14,4 +14,21 @@ buffered - **reader** (callable) – 读取数据的reader - **size** (int) – 最大buffer的大小 -返回:缓存的reader(读取器) \ No newline at end of file +返回:缓存的reader(读取器) + +**代码示例** + +.. code-block:: python + + import paddle + + def reader(): + for i in range(3): + yield i + + # Create a buffered reader, and the buffer size is 2. + buffered_reader = paddle.io.buffered(reader, 2) + + # Output: 0 1 2 + for i in buffered_reader(): + print(i) diff --git a/doc/paddle/api/paddle/io/cache_cn.rst b/doc/paddle/api/paddle/io/cache_cn.rst index e93e4c85d..511bc9219 100644 --- a/doc/paddle/api/paddle/io/cache_cn.rst +++ b/doc/paddle/api/paddle/io/cache_cn.rst @@ -1,9 +1,9 @@ -.. _cn_api_fluid_io_cache: +.. _cn_api_io_cache: cache ------------------------------- -.. py:function:: paddle.fluid.io.cache(reader) +.. py:function:: paddle.io.cache(reader) @@ -15,4 +15,21 @@ cache 返回:每次都会从内存中yields数据的一个装饰reader。 -返回类型:生成器 \ No newline at end of file +返回类型:数据保存在内存的reader(读取器) + +**代码示例** + +.. code-block:: python + + import paddle + + def reader(): + for i in range(3): + yield i + + # All data is cached into memory + cached_reader = paddle.io.cache(reader) + + # Output: 0 1 2 + for i in cached_reader(): + print(i) -- GitLab