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

Method pump

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

Source from the content-addressed store, hash-verified

887 }
888
889 async pump(): Promise<boolean> {
890 const item = await this.upstream.next();
891 if (item.done) {
892 return false;
893 }
894 const inputTensors = tf.tensor_util.getTensorsInContainer(item.value as {});
895 // Careful: the transform may mutate the item in place.
896 // that's why we have to remember the input Tensors above, and then
897 // below dispose only those that were not passed through to the output.
898 // Note too that the transform function is responsible for tidying any
899 // intermediate Tensors. Here we are concerned only about the inputs.
900 const mappedArray = this.transform(item.value);
901 const outputTensors =
902 tf.tensor_util.getTensorsInContainer(mappedArray as {});
903 this.outputQueue.pushAll(mappedArray);
904
905 // TODO(soergel) faster intersection, and deduplicate outputTensors
906 // TODO(soergel) move to tf.disposeExcept(in, out)?
907 for (const t of inputTensors) {
908 if (!tf.tensor_util.isTensorInList(t, outputTensors)) {
909 t.dispose();
910 }
911 }
912
913 return true;
914 }
915}
916
917/**

Callers 1

serialNextFunction · 0.45

Calls 3

pushAllMethod · 0.80
nextMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected