MCPcopy
hub / github.com/tensorflow/tfjs / next

Method next

tfjs-data/src/iterators/lazy_iterator.ts:710–733  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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
736class ErrorHandlingLazyIterator<T> extends LazyIterator<T> {

Callers 15

maybeReadHeaderLineMethod · 0.45
toArrayFunction · 0.45
toArrayForTestFunction · 0.45
resolveFullyFunction · 0.45
resolveWhileFunction · 0.45
serialNextMethod · 0.45
serialNextMethod · 0.45
nextMethod · 0.45
serialNextMethod · 0.45
serialNextMethod · 0.45

Calls 1

disposeMethod · 0.45

Tested by

no test coverage detected