<!DOCTYPE html><htmlclass="default"lang="en"><head><metacharset="utf-8"/><metahttp-equiv="x-ua-compatible"content="IE=edge"/><title>tidy | @vladmandic/face-api - v1.7.14</title><metaname="description"content="Documentation for @vladmandic/face-api"/><metaname="viewport"content="width=device-width, initial-scale=1"/><linkrel="stylesheet"href="../assets/style.css"/><linkrel="stylesheet"href="../assets/highlight.css"/><scriptdefersrc="../assets/main.js"></script><scriptasyncsrc="../assets/icons.js"id="tsd-icons-script"></script><scriptasyncsrc="../assets/search.js"id="tsd-search-script"></script><scriptasyncsrc="../assets/navigation.js"id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme=localStorage.getItem("tsd-theme")||"os";document.body.style.display="none";setTimeout(()=>app?app.showPage():document.body.style.removeProperty("display"),500)</script><headerclass="tsd-page-toolbar"><divclass="tsd-toolbar-contents container"><divclass="table-cell"id="tsd-search"data-base=".."><divclass="field"><labelfor="tsd-search-field"class="tsd-widget tsd-toolbar-icon search no-caption"><svgwidth="16"height="16"viewBox="0 0 16 16"fill="none"><usehref="../assets/icons.svg#icon-search"></use></svg></label><inputtype="text"id="tsd-search-field"aria-label="Search"/></div><divclass="field"><divid="tsd-toolbar-links"></div></div><ulclass="results"><liclass="state loading">Preparing search index...</li><liclass="state failure">The search index is not available</li></ul><ahref="../index.html"class="title">@vladmandic/face-api - v1.7.14</a></div><divclass="table-cell"id="tsd-widgets"><ahref="#"class="tsd-widget tsd-toolbar-icon menu no-caption"data-toggle="menu"aria-label="Menu"><svgwidth="16"height="16"viewBox="0 0 16 16"fill="none"><usehref="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><divclass="container container-main"><divclass="col-content"><divclass="tsd-page-title"><ulclass="tsd-breadcrumb"><li><ahref="../index.html">@vladmandic/face-api</a></li><li><ahref="../modules/tf.html">tf</a></li><li><ahref="tf.tidy.html">tidy</a></li></ul><h1>Function tidy</h1></div><sectionclass="tsd-panel"><ulclass="tsd-signatures"><liclass="tsd-signature tsd-anchor-link"><aid="tidy"class="tsd-anchor"></a><spanclass="tsd-kind-call-signature">tidy</span><spanclass="tsd-signature-symbol"><</span><aclass="tsd-signature-type tsd-kind-type-parameter"href="tf.tidy.html#tidy.T">T</a><spanclass="tsd-signature-symbol">></span><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-kind-parameter">nameOrFn</span>, <spanclass="tsd-kind-parameter">fn</span><spanclass="tsd-signature-symbol">?</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><aclass="tsd-signature-type tsd-kind-type-parameter"href="tf.tidy.html#tidy.T">T</a><ahref="#tidy"aria-label="Permalink"class="tsd-anchor-icon"><svgviewBox="0 0 24 24"><usehref="../assets/icons.svg#icon-anchor"></use></svg></a></li><liclass="tsd-description"><divclass="tsd-comment tsd-typography"><p>Executes the provided function <code>fn</code> and after it is executed, cleans up all
<pre><codeclass="js"><spanclass="hl-7">// y = 2 ^ 2 + 1</span><br/><spanclass="hl-0">const</span><spanclass="hl-1"></span><spanclass="hl-2">y</span><spanclass="hl-1"> = </span><spanclass="hl-5">tf</span><spanclass="hl-1">.</span><spanclass="hl-3">tidy</span><spanclass="hl-1">(() </span><spanclass="hl-0">=></span><spanclass="hl-1"> {</span><br/><spanclass="hl-1"></span><spanclass="hl-7">// a, b, and one will be cleaned up when the tidy ends.</span><br/><spanclass="hl-1"></span><spanclass="hl-0">const</span><spanclass="hl-1"></span><spanclass="hl-2">one</span><spanclass="hl-1"> = </span><spanclass="hl-5">tf</span><spanclass="hl-1">.</span><spanclass="hl-3">scalar</span><spanclass="hl-1">(</span><spanclass="hl-4">1</span><spanclass="hl-1">);</span><br/><spanclass="hl-1"></span><spanclass="hl-0">const</span><spanclass="hl-1"></span><spanclass="hl-2">a</span><spanclass="hl-1"> = </span><spanclass="hl-5">tf</span><spanclass="hl-1">.</span><spanclass="hl-3">scalar</span><spanclass="hl-1">(</span><spanclass="hl-4">2</span><spanclass="hl-1">);</span><br/><spanclass="hl-1"></span><spanclass="hl-0">const</span><spanclass="hl-1"></span><spanclass="hl-2">b</span><spanclass="hl-1"> = </span><spanclass="hl-5">a</span><spanclass="hl-1">.</span><spanclass="hl-3">square</span><spanclass="hl-1">();</span><br/><br/><spanclass="hl-1"></span><spanclass="hl-5">console</span><spanclass="hl-1">.</span><spanclass="hl-3">log</span><spanclass="hl-1">(</span><spanclass="hl-8">'numTensors (in tidy): '</span><spanclass="hl-1"> + </span><spanclass="hl-5">tf</span><spanclass="hl-1">.</span><spanclass="hl-3">memory</span><spanclass="hl-1">().</span><spanclass="hl-5">numTensors</span><spanclass="hl-1">);</span><br/><br/><spanclass="hl-1"></span><spanclass="hl-7">// The value returned inside the tidy function will return</span><br/><spanclass="hl-1"></span><spanclass="hl-7">// through the tidy, in this case to the variable y.</span><br/><spanclass="hl-1"></span><spanclass="hl-6">return</span><spanclass="hl-1"></span><spanclass="hl-5">b</span><spanclass="hl-1">.</span><spanclass="hl-3">add</span><spanclass="hl-1">(</span><spanclass="hl-5">one</span><spanclass="hl-1">);</span><br/><spanclass="hl-1">});</span><br/><br/><spanclass="hl-5">console</span><spanclass="hl-1">.</span><spanclass="hl-3">log</span><spanclass="hl-1">(</span><spanclass="hl-8">'numTensors (outside tidy): '</span><spanclass="hl-1"> + </span><spanclass="hl-5">tf</span><spanclass="hl-1">.</span><spanclass="hl-3">memory</span><spanclass="hl-1">().</span><spanclass="hl-5">numTensors</span><spanclass="hl-1">);</span><br/><spanclass="hl-5">y</span><spanclass="hl-1">.</span><spanclass="hl-3">print</span><spanclass="hl-1">();</span>
</code><buttontype="button">Copy</button></pre>
</div><sectionclass="tsd-panel"><h4>Type Parameters</h4><ulclass="tsd-type-parameter-list"><li><span><aid="tidy.T"class="tsd-anchor"></a><spanclass="tsd-kind-type-parameter">T</span><spanclass="tsd-signature-keyword"> extends </span><spanclass="tsd-signature-type">TensorContainer</span></span></li></ul></section><divclass="tsd-parameters"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameter-list"><li><span><spanclass="tsd-kind-parameter">nameOrFn</span>: <spanclass="tsd-signature-type">string</span><spanclass="tsd-signature-symbol"> | </span><spanclass="tsd-signature-type">ScopeFn</span><spanclass="tsd-signature-symbol"><</span><aclass="tsd-signature-type tsd-kind-type-parameter"href="tf.tidy.html#tidy.T">T</a><spanclass="tsd-signature-symbol">></span></span><divclass="tsd-comment tsd-typography"><p>The name of the closure, or the function to execute.
If a name is provided, the 2nd argument should be the function.
If debug mode is on, the timing and the memory usage of the function
will be tracked and displayed on the console using the provided name.</p>
</div><divclass="tsd-comment tsd-typography"></div></li><li><span><codeclass="tsd-tag">Optional</code><spanclass="tsd-kind-parameter">fn</span>: <spanclass="tsd-signature-type">ScopeFn</span><spanclass="tsd-signature-symbol"><</span><aclass="tsd-signature-type tsd-kind-type-parameter"href="tf.tidy.html#tidy.T">T</a><spanclass="tsd-signature-symbol">></span></span><divclass="tsd-comment tsd-typography"><p>The function to execute.</p>