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

[doc] Add example for cache and buffered (#26819)

* Add example for cache and buffered, test=develop, test=document_fix
上级 906e7f92
......@@ -62,6 +62,22 @@ def cache(reader):
Returns:
generator: a decorated reader object which yields data from cached memory.
Examples:
.. 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)
"""
all_data = tuple(reader())
......@@ -296,12 +312,28 @@ def buffered(reader, size):
buffer. Reading from the buffered data reader will proceed as long
as the buffer is not empty.
:param reader: the data reader to read from.
:type reader: callable
:param size: max buffer size.
:type size: int
Args:
reader(generator): the data reader to read from.
size(int): max buffer size.
Returns:
generator: the buffered data reader.
Examples:
.. code-block:: python
:returns: the buffered data reader.
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)
"""
class EndSignal():
......
......@@ -105,8 +105,6 @@
"convert_dist_to_sparse_program",
"load_persistables_for_increment",
"load_persistables_for_inference",
"cache",
"buffered",
"xmap_readers",
"Metric.reset",
"Metric.update",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册