()
| 503 | |
| 504 | |
| 505 | def test_external_source(): |
| 506 | class TestIterator: |
| 507 | def __init__(self, n): |
| 508 | self.n = n |
| 509 | |
| 510 | def __iter__(self): |
| 511 | self.i = 0 |
| 512 | return self |
| 513 | |
| 514 | def __next__(self): |
| 515 | batch_1 = [] |
| 516 | batch_2 = [] |
| 517 | if self.i < self.n: |
| 518 | batch_1.append(datapy.arange(0, 1, dtype=datapy.float32)) |
| 519 | batch_2.append(datapy.arange(0, 1, dtype=datapy.float32)) |
| 520 | self.i += 1 |
| 521 | return batch_1, batch_2 |
| 522 | else: |
| 523 | self.i = 0 |
| 524 | raise StopIteration |
| 525 | |
| 526 | next = __next__ |
| 527 | |
| 528 | class IterSetupPipeline(Pipeline): |
| 529 | def __init__(self, iterator, num_threads, device_id): |
| 530 | super().__init__(1, num_threads, device_id) |
| 531 | self.input_1 = ops.ExternalSource() |
| 532 | self.input_2 = ops.ExternalSource() |
| 533 | self.iterator = iterator |
| 534 | |
| 535 | def define_graph(self): |
| 536 | self.batch_1 = self.input_1() |
| 537 | self.batch_2 = self.input_2() |
| 538 | return [self.batch_1, self.batch_2] |
| 539 | |
| 540 | def iter_setup(self): |
| 541 | batch_1, batch_2 = next(self.iterator) |
| 542 | self.feed_input(self.batch_1, batch_1) |
| 543 | self.feed_input(self.batch_2, batch_2) |
| 544 | |
| 545 | iter_num = 5 |
| 546 | iterator = iter(TestIterator(iter_num)) |
| 547 | pipe = IterSetupPipeline(iterator, 3, 0) |
| 548 | |
| 549 | i = 0 |
| 550 | while True: |
| 551 | try: |
| 552 | pipe.run() |
| 553 | i += 1 |
| 554 | except StopIteration: |
| 555 | break |
| 556 | assert iter_num == i |
| 557 | |
| 558 | |
| 559 | def test_external_source_fail_missing_output(): |
nothing calls this directly
no test coverage detected