MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / stack

Function stack

NLP/EMNLP2019-MAL/src/reader.py:511–535  ·  view source on GitHub ↗

Data generator for multi-devices

(data_reader, count, clip_last=True)

Source from the content-addressed store, hash-verified

509 provider for py_reader
510 """
511 def stack(data_reader, count, clip_last=True):
512 """
513 Data generator for multi-devices
514 """
515 def __impl__():
516 res = []
517 for item in data_reader():
518 res.append(item)
519 if len(res) == count:
520 yield res
521 res = []
522 if len(res) == count:
523 yield res
524 elif not clip_last:
525 data = []
526 for item in res:
527 data += item
528 if len(data) > count:
529 inst_num_per_part = len(data) // count
530 yield [
531 data[inst_num_per_part * i:inst_num_per_part * (i + 1)]
532 for i in range(count)
533 ]
534
535 return __impl__
536
537 def split(data_reader, count):
538 """

Callers 1

prepare_data_generatorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected