MCPcopy Index your code
hub / github.com/tensorflow/tfjs / tidy

Method tidy

tfjs-core/src/engine.ts:441–475  ·  view source on GitHub ↗
(nameOrFn: string|ScopeFn<T>, fn?: ScopeFn<T>)

Source from the content-addressed store, hash-verified

439 }
440
441 tidy<T extends TensorContainer>(nameOrFn: string|ScopeFn<T>, fn?: ScopeFn<T>):
442 T {
443 let name: string = null;
444 if (fn == null) {
445 // Called with only 1 argument.
446 if (typeof nameOrFn !== 'function') {
447 throw new Error('Please provide a function to tidy()');
448 }
449 fn = nameOrFn;
450 } else {
451 // Called with 2 arguments.
452 if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) {
453 throw new Error(
454 'When calling with two arguments, the first argument ' +
455 'to tidy() must be a string');
456 }
457 if (typeof fn !== 'function') {
458 throw new Error(
459 'When calling with two arguments, the 2nd argument ' +
460 'to tidy() must be a function');
461 }
462 name = nameOrFn as string;
463 // TODO(nsthorat,smilkov): Do operation logging and performance
464 // profiling.
465 }
466 let result: T;
467 return this.scopedRun(
468 () => this.startScope(name), () => this.endScope(result), () => {
469 result = fn();
470 if (result instanceof Promise) {
471 console.error('Cannot return a Promise inside of tidy.');
472 }
473 return result;
474 });
475 }
476
477 private scopedRun<T>(start: () => void, end: () => void, f: () => T): T {
478 start();

Callers 15

runKernelFuncMethod · 0.95
gradientsMethod · 0.95
convertToRowMajorFunction · 0.80
showExamplesFunction · 0.80
cartoonizeFunction · 0.80
filterFunction · 0.80
mapFunction · 0.80
applyMethod · 0.80
predictLoopMethod · 0.80
testLoopMethod · 0.80
makeTestFunctionMethod · 0.80
fitLoopMethod · 0.80

Calls 3

scopedRunMethod · 0.95
startScopeMethod · 0.95
endScopeMethod · 0.95

Tested by

no test coverage detected