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

Method endScope

tfjs-core/src/engine.ts:1071–1097  ·  view source on GitHub ↗

* End a scope. Use this with startScope() to achieve the same functionality * as scope() without the need for a function closure.

(result?: TensorContainer)

Source from the content-addressed store, hash-verified

1069 * as scope() without the need for a function closure.
1070 */
1071 endScope(result?: TensorContainer) {
1072 const tensorsToTrackInParent = getTensorsInContainer(result);
1073 const tensorsToTrackInParentSet =
1074 new Set(tensorsToTrackInParent.map(t => t.id));
1075
1076 // Dispose the arrays tracked in this scope.
1077 for (let i = 0; i < this.state.activeScope.track.length; i++) {
1078 const tensor = this.state.activeScope.track[i];
1079 if (!tensor.kept && !tensorsToTrackInParentSet.has(tensor.id)) {
1080 tensor.dispose();
1081 }
1082 }
1083
1084 const oldScope = this.state.scopeStack.pop();
1085 this.state.activeScope = this.state.scopeStack.length === 0 ?
1086 null :
1087 this.state.scopeStack[this.state.scopeStack.length - 1];
1088
1089 // Track the current result in the parent scope.
1090 tensorsToTrackInParent.forEach(tensor => {
1091 // Only track the tensor if was allocated in the inner scope and is not
1092 // globally kept.
1093 if (!tensor.kept && tensor.scopeId === oldScope.id) {
1094 this.track(tensor);
1095 }
1096 });
1097 }
1098
1099 /**
1100 * Returns gradients of `f` with respect to each of the `xs`. The gradients

Callers 5

tidyMethod · 0.95
executeTestsFunction · 0.80
engine_test.tsFile · 0.80
f2Function · 0.80
backends_test.tsFile · 0.80

Calls 5

trackMethod · 0.95
getTensorsInContainerFunction · 0.90
hasMethod · 0.80
disposeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected