Take data points from another DataFlow and produce them until it's exhausted for certain amount of times. i.e.: dp1, dp2, .... dpn, dp1, dp2, ....dpn
| 359 | |
| 360 | |
| 361 | class RepeatedData(ProxyDataFlow): |
| 362 | """ Take data points from another DataFlow and produce them until |
| 363 | it's exhausted for certain amount of times. i.e.: |
| 364 | dp1, dp2, .... dpn, dp1, dp2, ....dpn |
| 365 | """ |
| 366 | |
| 367 | def __init__(self, ds, num): |
| 368 | """ |
| 369 | Args: |
| 370 | ds (DataFlow): input DataFlow |
| 371 | num (int): number of times to repeat ds. |
| 372 | Set to -1 to repeat ``ds`` infinite times. |
| 373 | """ |
| 374 | self.num = num |
| 375 | super(RepeatedData, self).__init__(ds) |
| 376 | |
| 377 | def __len__(self): |
| 378 | """ |
| 379 | Raises: |
| 380 | :class:`ValueError` when num == -1. |
| 381 | """ |
| 382 | if self.num == -1: |
| 383 | raise NotImplementedError("__len__() is unavailable for infinite dataflow") |
| 384 | return len(self.ds) * self.num |
| 385 | |
| 386 | def __iter__(self): |
| 387 | if self.num == -1: |
| 388 | while True: |
| 389 | yield from self.ds |
| 390 | else: |
| 391 | for _ in range(self.num): |
| 392 | yield from self.ds |
| 393 | |
| 394 | |
| 395 | class RepeatedDataPoint(ProxyDataFlow): |