()
| 708 | } |
| 709 | |
| 710 | async next(): Promise<IteratorResult<O>> { |
| 711 | const item = await this.upstream.next(); |
| 712 | if (item.done) { |
| 713 | return {value: null, done: true}; |
| 714 | } |
| 715 | const inputTensors = tf.tensor_util.getTensorsInContainer(item.value as {}); |
| 716 | // Careful: the transform may mutate the item in place. |
| 717 | // That's why we have to remember the input Tensors above, and then |
| 718 | // below dispose only those that were not passed through to the output. |
| 719 | // Note too that the transform function is responsible for tidying |
| 720 | // any intermediate Tensors. Here we are concerned only about the |
| 721 | // inputs. |
| 722 | const mapped = this.transform(item.value); |
| 723 | const outputTensors = tf.tensor_util.getTensorsInContainer(mapped as {}); |
| 724 | |
| 725 | // TODO(soergel) faster intersection |
| 726 | // TODO(soergel) move to tf.disposeExcept(in, out)? |
| 727 | for (const t of inputTensors) { |
| 728 | if (!tf.tensor_util.isTensorInList(t, outputTensors)) { |
| 729 | t.dispose(); |
| 730 | } |
| 731 | } |
| 732 | return {value: mapped, done: false}; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | class ErrorHandlingLazyIterator<T> extends LazyIterator<T> { |
no test coverage detected