buffered

paddle.fluid.io.buffered(reader, size)[source]

Creates a buffered data reader.

The buffered data reader will read and save data entries into a buffer. Reading from the buffered data reader will proceed as long as the buffer is not empty.

Parameters
  • reader (callable) – The data reader to read from.

  • size (int) – Max buffer size.

Returns

The buffered data reader.

Return type

Variable

Examples

import paddle.reader as reader
import time

def reader_creator_10(dur):
    def reader():
        for i in range(10):
            time.sleep(dur)
            yield i
    return reader

for size in range(20):
    b = reader.buffered(reader_creator_10(0), size)
    c = 0
    for i in b():
        assert i == c
        c += 1
    assert c == 10