未验证 提交 c9d7a173 编写于 作者: C cc 提交者: GitHub

[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
上级 fc3e4626
.. _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)
......@@ -15,3 +15,20 @@ buffered
- **size** (int) – 最大buffer的大小
返回:缓存的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)
.. _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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册