>>0)/4294967296};return c.double=function(){do var l=p.next()>>>11,m=(p.next()>>>0)/4294967296,d=(l+m)/(1<<21);while(d===0);return d},c.int32=p.next,c.quick=c,u&&(typeof u==\"object\"&&n(u,p),c.state=function(){return n(p,{})}),c}e&&e.exports?e.exports=s:t&&t.amd?t(function(){return s}):this.tychei=s})(kk,typeof hC==\"object\"&&hC,typeof define==\"function\"&&define)});var Tk=Kt(()=>{});var $k=Kt((_k,yd)=>{(function(r,e,t){var o=256,n=6,s=52,a=\"random\",i=t.pow(o,n),p=t.pow(2,s),u=p*2,c=o-1,l;function m(C,w,k){var _=[];w=w==!0?{entropy:!0}:w||{};var E=g(h(w.entropy?[C,b(e)]:C==null?x():C,3),_),A=new d(_),R=function(){for(var D=A.g(n),P=i,M=0;D=u;)D/=2,P/=2,M>>>=1;return(D+M)/P};return R.int32=function(){return A.g(4)|0},R.quick=function(){return A.g(4)/4294967296},R.double=R,g(b(A.S),e),(w.pass||k||function(D,P,M,L){return L&&(L.S&&f(L,A),D.state=function(){return f(A,{})}),M?(t[a]=D,P):D})(R,E,\"global\"in w?w.global:this==t,w.state)}function d(C){var w,k=C.length,_=this,E=0,A=_.i=_.j=0,R=_.S=[];for(k||(C=[k++]);E{var P4=gk(),M4=yk(),L4=Ck(),B4=wk(),V4=vk(),z4=Nk(),lu=$k();lu.alea=P4;lu.xor128=M4;lu.xorwow=L4;lu.xorshift7=B4;lu.xor4096=V4;lu.tychei=z4;Ek.exports=lu});var oI=Kt(()=>{});var nI=Kt(()=>{});var x3=Kt(()=>{});var y3=Kt(()=>{});var b3=Kt(()=>{});var C3=Kt((wg,aI)=>{var sI=(()=>{var r=typeof document!=\"undefined\"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename!=\"undefined\"&&(r=r||__filename),function(e){e=e||{};function t(){return te.buffer!=ze&&Nt(te.buffer),ct}function o(){return te.buffer!=ze&&Nt(te.buffer),at}function n(){return te.buffer!=ze&&Nt(te.buffer),ft}function s(){return te.buffer!=ze&&Nt(te.buffer),Rr}function a(){return te.buffer!=ze&&Nt(te.buffer),Pt}function i(){return te.buffer!=ze&&Nt(te.buffer),qr}function p(){return te.buffer!=ze&&Nt(te.buffer),er}var u=typeof e!=\"undefined\"?e:{},c,l;u.ready=new Promise(function(F,B){c=F,l=B});var m;typeof process!=\"undefined\"&&process.listeners&&(m={uncaughtException:process.listeners(\"uncaughtException\"),unhandledRejection:process.listeners(\"unhandledRejection\")});var d=Object.assign({},u),f=[],h=\"./this.program\",g=(F,B)=>{throw B},x=typeof window==\"object\",b=typeof importScripts==\"function\",C=typeof process==\"object\"&&typeof process.versions==\"object\"&&typeof process.versions.node==\"string\",w=u.ENVIRONMENT_IS_PTHREAD||!1,k=\"\";function _(F){return u.locateFile?u.locateFile(F,k):k+F}var E,A,R,D;function P(F){if(F instanceof qi)return;K(\"exiting due to exception: \"+F)}if(C){var M=oI(),L=nI();b?k=L.dirname(k)+\"/\":k=__dirname+\"/\",E=(B,ue)=>(B=ep(B)?new URL(B):L.normalize(B),M.readFileSync(B,ue?void 0:\"utf8\")),R=B=>{var ue=E(B,!0);return ue.buffer||(ue=new Uint8Array(ue)),ue},A=(B,ue,_e)=>{B=ep(B)?new URL(B):L.normalize(B),M.readFile(B,function(Me,Pe){Me?_e(Me):ue(Pe.buffer)})},process.argv.length>1&&(h=process.argv[1].replace(/\\\\/g,\"/\")),f=process.argv.slice(2),process.on(\"uncaughtException\",function(B){if(!(B instanceof qi))throw B}),process.on(\"unhandledRejection\",function(B){throw B}),g=(B,ue)=>{if(Do())throw process.exitCode=B,ue;P(ue),process.exit(B)},u.inspect=function(){return\"[Emscripten Module object]\"};let F;try{F=x3()}catch(B){throw console.error('The \"worker_threads\" module is not supported in this node.js build - perhaps a newer version is needed?'),B}global.Worker=F.Worker}else(x||b)&&(b?k=self.location.href:typeof document!=\"undefined\"&&document.currentScript&&(k=document.currentScript.src),typeof r!=\"undefined\"&&r&&(k=r),k.indexOf(\"blob:\")!==0?k=k.substr(0,k.replace(/[?#].*/,\"\").lastIndexOf(\"/\")+1):k=\"\",C||(E=F=>{var B=new XMLHttpRequest;return B.open(\"GET\",F,!1),B.send(null),B.responseText},b&&(R=F=>{var B=new XMLHttpRequest;return B.open(\"GET\",F,!1),B.responseType=\"arraybuffer\",B.send(null),new Uint8Array(B.response)}),A=(F,B,ue)=>{var _e=new XMLHttpRequest;_e.open(\"GET\",F,!0),_e.responseType=\"arraybuffer\",_e.onload=()=>{if(_e.status==200||_e.status==0&&_e.response){B(_e.response);return}ue()},_e.onerror=ue,_e.send(null)}),D=F=>document.title=F);C&&typeof performance==\"undefined\"&&(global.performance=y3().performance);var V=console.log.bind(console),z=console.warn.bind(console);C&&(V=F=>M.writeSync(1,F+`\n`),z=F=>M.writeSync(2,F+`\n`));var U=u.print||V,K=u.printErr||z;Object.assign(u,d),d=null,u.arguments&&(f=u.arguments),u.thisProgram&&(h=u.thisProgram),u.quit&&(g=u.quit);var H=4,q=Atomics.load,Z=Atomics.store,ee=Atomics.compareExchange,oe;u.wasmBinary&&(oe=u.wasmBinary);var J=u.noExitRuntime||!0;typeof WebAssembly!=\"object\"&&Ki(\"no native wasm support detected\");var te,ie,ce=!1,ye;function Ne(F,B){F||Ki(B)}var Ie=typeof TextDecoder!=\"undefined\"?new TextDecoder(\"utf8\"):void 0;function Ae(F,B,ue){for(var _e=B+ue,Me=B;F[Me]&&!(Me>=_e);)++Me;if(Me-B>16&&F.buffer&&Ie)return Ie.decode(F.buffer instanceof SharedArrayBuffer?F.slice(B,Me):F.subarray(B,Me));for(var Pe=\"\";B>10,56320|Qr&1023)}}return Pe}function Re(F,B){return F?Ae(o(),F,B):\"\"}function ot(F,B,ue,_e){if(!(_e>0))return 0;for(var Me=ue,Pe=ue+_e-1,fe=0;fe=55296&&ve<=57343){var Ft=F.charCodeAt(++fe);ve=65536+((ve&1023)<<10)|Ft&1023}if(ve<=127){if(ue>=Pe)break;B[ue++]=ve}else if(ve<=2047){if(ue+1>=Pe)break;B[ue++]=192|ve>>6,B[ue++]=128|ve&63}else if(ve<=65535){if(ue+2>=Pe)break;B[ue++]=224|ve>>12,B[ue++]=128|ve>>6&63,B[ue++]=128|ve&63}else{if(ue+3>=Pe)break;B[ue++]=240|ve>>18,B[ue++]=128|ve>>12&63,B[ue++]=128|ve>>6&63,B[ue++]=128|ve&63}}return B[ue]=0,ue-Me}function pt(F,B,ue){return ot(F,o(),B,ue)}var ze,ct,at,ft,ht,Rr,Pt,qr,er;w&&(ze=u.buffer);function Nt(F){ze=F,u.HEAP8=ct=new Int8Array(F),u.HEAP16=ft=new Int16Array(F),u.HEAP32=Rr=new Int32Array(F),u.HEAPU8=at=new Uint8Array(F),u.HEAPU16=ht=new Uint16Array(F),u.HEAPU32=Pt=new Uint32Array(F),u.HEAPF32=qr=new Float32Array(F),u.HEAPF64=er=new Float64Array(F)}var tr=u.INITIAL_MEMORY||16777216;if(w)te=u.wasmMemory,ze=u.buffer;else if(u.wasmMemory)te=u.wasmMemory;else if(te=new WebAssembly.Memory({initial:tr/65536,maximum:32768,shared:!0}),!(te.buffer instanceof SharedArrayBuffer))throw K(\"requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag\"),C&&K(\"(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)\"),Error(\"bad memory\");te&&(ze=te.buffer),tr=ze.byteLength,Nt(ze);var rr,jr=[],Xr=[],cr=[],ea=!1;function Do(){return J}function hs(){if(u.preRun)for(typeof u.preRun==\"function\"&&(u.preRun=[u.preRun]);u.preRun.length;)Dc(u.preRun.shift());Pc(jr)}function qt(){ea=!0,!w&&Pc(Xr)}function ta(){if(!w){if(u.postRun)for(typeof u.postRun==\"function\"&&(u.postRun=[u.postRun]);u.postRun.length;)AI(u.postRun.shift());Pc(cr)}}function Dc(F){jr.unshift(F)}function Fc(F){Xr.unshift(F)}function AI(F){cr.unshift(F)}var Ya=0,Ju=null,ra=null;function Rx(F){Ya++,u.monitorRunDependencies&&u.monitorRunDependencies(Ya)}function Yl(F){if(Ya--,u.monitorRunDependencies&&u.monitorRunDependencies(Ya),Ya==0&&(Ju!==null&&(clearInterval(Ju),Ju=null),ra)){var B=ra;ra=null,B()}}function Ki(F){u.onAbort&&u.onAbort(F),F=\"Aborted(\"+F+\")\",K(F),ce=!0,ye=1,F+=\". Build with -sASSERTIONS for more info.\";var B=new WebAssembly.RuntimeError(F);throw l(B),B}var Dx=\"data:application/octet-stream;base64,\";function Ql(F){return F.startsWith(Dx)}function ep(F){return F.startsWith(\"file://\")}var lr;lr=\"tfjs-backend-wasm-threaded-simd.wasm\",Ql(lr)||(lr=_(lr));function Zl(F){try{if(F==lr&&oe)return new Uint8Array(oe);if(R)return R(F);throw\"both async and sync fetching of the wasm failed\"}catch(B){Ki(B)}}function Fx(){if(!oe&&(x||b)){if(typeof fetch==\"function\"&&!ep(lr))return fetch(lr,{credentials:\"same-origin\"}).then(function(F){if(!F.ok)throw\"failed to load wasm binary file at '\"+lr+\"'\";return F.arrayBuffer()}).catch(function(){return Zl(lr)});if(A)return new Promise(function(F,B){A(lr,function(ue){F(new Uint8Array(ue))},B)})}return Promise.resolve().then(function(){return Zl(lr)})}function Ox(){var F={env:lm,wasi_snapshot_preview1:lm};function B(fe,ve){var Ft=fe.exports;if(u.asm=Ft,Gx(u.asm._emscripten_tls_init),rr=u.asm.__indirect_function_table,Fc(u.asm.__wasm_call_ctors),ie=ve,!w){var Qr=Oe.unusedWorkers.length;Oe.unusedWorkers.forEach(function(na){Oe.loadWasmModuleToWorker(na,function(){--Qr||Yl(\"wasm-instantiate\")})})}}w||Rx(\"wasm-instantiate\");function ue(fe){B(fe.instance,fe.module)}function _e(fe){return Fx().then(function(ve){return WebAssembly.instantiate(ve,F)}).then(function(ve){return ve}).then(fe,function(ve){K(\"failed to asynchronously prepare wasm: \"+ve),Ki(ve)})}function Me(){return!oe&&typeof WebAssembly.instantiateStreaming==\"function\"&&!Ql(lr)&&!ep(lr)&&!C&&typeof fetch==\"function\"?fetch(lr,{credentials:\"same-origin\"}).then(function(fe){var ve=WebAssembly.instantiateStreaming(fe,F);return ve.then(ue,function(Ft){return K(\"wasm streaming compile failed: \"+Ft),K(\"falling back to ArrayBuffer instantiation\"),_e(ue)})}):_e(ue)}if(u.instantiateWasm)try{var Pe=u.instantiateWasm(F,B);return Pe}catch(fe){K(\"Module.instantiateWasm callback failed with error: \"+fe),l(fe)}return Me().catch(l),{}}var RI,DI,Jl={};function qi(F){this.name=\"ExitStatus\",this.message=\"Program terminated with exit(\"+F+\")\",this.status=F}function Px(F){var B=Oe.pthreads[F];delete Oe.pthreads[F],B.terminate(),hb(F),Oe.runningWorkers.splice(Oe.runningWorkers.indexOf(B),1),B.pthread_ptr=0}function Mx(F){var B=Oe.pthreads[F];B.postMessage({cmd:\"cancel\"})}function Oc(F){var B=Oe.pthreads[F];Ne(B),Oe.returnWorkerToPool(B)}function Lx(F){var B=Oe.getNewWorker();if(!B)return 6;Oe.runningWorkers.push(B),Oe.pthreads[F.pthread_ptr]=B,B.pthread_ptr=F.pthread_ptr;var ue={cmd:\"run\",start_routine:F.startRoutine,arg:F.arg,pthread_ptr:F.pthread_ptr};return B.runPthread=()=>{C&&B.ref(),B.postMessage(ue,F.transferList),delete B.runPthread},B.loaded&&B.runPthread(),0}var em={varargs:void 0,get:function(){em.varargs+=4;var F=s()[em.varargs-4>>2];return F},getStr:function(F){var B=Re(F);return B}};function tm(F){if(w)return Qa(1,1,F);ye=F,Do()||(Oe.terminateAllThreads(),u.onExit&&u.onExit(F),ce=!0),g(F,new qi(F))}function Bx(F,B){if(ye=F,!B&&w)throw om(F),\"unwind\";tm(F)}var rm=Bx;function Vx(F){if(F instanceof qi||F==\"unwind\")return ye;g(1,F)}var Oe={unusedWorkers:[],runningWorkers:[],tlsInitFunctions:[],pthreads:{},init:function(){w?Oe.initWorker():Oe.initMainThread()},initMainThread:function(){for(var F=8;F--;)Oe.allocateUnusedWorker()},initWorker:function(){J=!1},setExitStatus:function(F){ye=F},terminateAllThreads:function(){for(var F of Object.values(Oe.pthreads))Oe.returnWorkerToPool(F);for(var F of Oe.unusedWorkers)F.terminate();Oe.unusedWorkers=[]},returnWorkerToPool:function(F){var B=F.pthread_ptr;delete Oe.pthreads[B],Oe.unusedWorkers.push(F),Oe.runningWorkers.splice(Oe.runningWorkers.indexOf(F),1),F.pthread_ptr=0,C&&F.unref(),hb(B)},receiveObjectTransfer:function(F){},threadInitTLS:function(){Oe.tlsInitFunctions.forEach(F=>F())},loadWasmModuleToWorker:function(F,B){F.onmessage=Pe=>{var fe=Pe.data,ve=fe.cmd;if(F.pthread_ptr&&(Oe.currentProxiedOperationCallerThread=F.pthread_ptr),fe.targetThread&&fe.targetThread!=xm()){var Ft=Oe.pthreads[fe.targetThread];Ft?Ft.postMessage(fe,fe.transferList):K('Internal error! Worker sent a message \"'+ve+'\" to target pthread '+fe.targetThread+\", but that thread no longer exists!\"),Oe.currentProxiedOperationCallerThread=void 0;return}ve===\"processProxyingQueue\"?Mc(fe.queue):ve===\"spawnThread\"?Lx(fe):ve===\"cleanupThread\"?Oc(fe.thread):ve===\"killThread\"?Px(fe.thread):ve===\"cancelThread\"?Mx(fe.thread):ve===\"loaded\"?(F.loaded=!0,C&&F.unref(),B&&B(F),F.runPthread&&F.runPthread()):ve===\"print\"?U(\"Thread \"+fe.threadId+\": \"+fe.text):ve===\"printErr\"?K(\"Thread \"+fe.threadId+\": \"+fe.text):ve===\"alert\"?alert(\"Thread \"+fe.threadId+\": \"+fe.text):fe.target===\"setimmediate\"?F.postMessage(fe):ve===\"callHandler\"?u[fe.handler](...fe.args):ve&&K(\"worker sent an unknown command \"+ve),Oe.currentProxiedOperationCallerThread=void 0},F.onerror=Pe=>{var fe=\"worker sent an error!\";throw K(fe+\" \"+Pe.filename+\":\"+Pe.lineno+\": \"+Pe.message),Pe},C&&(F.on(\"message\",function(Pe){F.onmessage({data:Pe})}),F.on(\"error\",function(Pe){F.onerror(Pe)}),F.on(\"detachedExit\",function(){}));var ue=[],_e=[\"onExit\",\"onAbort\",\"print\",\"printErr\"];for(var Me of _e)u.hasOwnProperty(Me)&&ue.push(Me);F.postMessage({cmd:\"load\",handlers:ue,urlOrBlob:u.mainScriptUrlOrBlob||r,wasmMemory:te,wasmModule:ie})},allocateUnusedWorker:function(){var F,B=_(\"tfjs-backend-wasm-threaded-simd.worker.js\");F=new Worker(B),Oe.unusedWorkers.push(F)},getNewWorker:function(){return Oe.unusedWorkers.length==0&&(Oe.allocateUnusedWorker(),Oe.loadWasmModuleToWorker(Oe.unusedWorkers[0])),Oe.unusedWorkers.pop()}};u.PThread=Oe;function Pc(F){for(;F.length>0;)F.shift()(u)}function zx(){var F=xm(),B=s()[F+52>>2],ue=s()[F+56>>2],_e=B-ue;BI(B,_e),ym(B)}u.establishStackSpace=zx;function om(F){if(w)return Qa(2,0,F);try{rm(F)}catch(B){Vx(B)}}var tp=[];function Wx(F){var B=tp[F];return B||(F>=tp.length&&(tp.length=F+1),tp[F]=B=rr.get(F)),B}function Ux(F,B){var ue=Wx(F)(B);Do()?Oe.setExitStatus(ue):LI(ue)}u.invokeEntryPoint=Ux;function Gx(F){Oe.tlsInitFunctions.push(F)}function Hx(F){OI(F,!b,1,!x),Oe.threadInitTLS()}function Kx(F){w?postMessage({cmd:\"cleanupThread\",thread:F}):Oc(F)}function nm(F,B,ue,_e){return w?Qa(3,1,F,B,ue,_e):sm(F,B,ue,_e)}function sm(F,B,ue,_e){if(typeof SharedArrayBuffer==\"undefined\")return K(\"Current environment does not support SharedArrayBuffer, pthreads are not available!\"),6;var Me=[],Pe=0;if(w&&(Me.length===0||Pe))return nm(F,B,ue,_e);if(Pe)return Pe;var fe={startRoutine:ue,pthread_ptr:F,arg:_e,transferList:Me};return w?(fe.cmd=\"spawnThread\",postMessage(fe,Me),0):Lx(fe)}function qx(){return 65536}var jx=!0;function Xx(){return jx}function Mc(F){Atomics.store(s(),F>>2,1),xm()&&MI(F),Atomics.compareExchange(s(),F>>2,1,0)}u.executeNotifiedProxyingQueue=Mc;function Yx(F,B,ue,_e){if(F==B)setTimeout(()=>Mc(_e));else if(w)postMessage({targetThread:F,cmd:\"processProxyingQueue\",queue:_e});else{var Me=Oe.pthreads[F];if(!Me)return;Me.postMessage({cmd:\"processProxyingQueue\",queue:_e})}return 1}function Qx(F,B,ue){return-1}function Zx(){Ki(\"\")}function ji(F){ji.shown||(ji.shown={}),ji.shown[F]||(ji.shown[F]=1,C&&(F=\"warning: \"+F),K(F))}function Jx(){C||b||ji(\"Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread\")}function ey(){return Date.now()}function am(){return 2147483648}function ty(){return am()}var Lc;C?Lc=()=>{var F=process.hrtime();return F[0]*1e3+F[1]/1e6}:Lc=()=>performance.timeOrigin+performance.now();function ry(F,B,ue){o().copyWithin(F,B,B+ue)}function oy(){return C?b3().cpus().length:navigator.hardwareConcurrency}function ny(F){var B=gb(),ue=F();return ym(B),ue}function Qa(F,B){var ue=arguments.length-2,_e=arguments;return ny(()=>{for(var Me=ue,Pe=bm(Me*8),fe=Pe>>3,ve=0;ve>3,Me=0;Me>>16),Nt(te.buffer),1}catch(B){}}function iy(F){var B=o().length;if(F=F>>>0,F<=B)return!1;var ue=am();if(F>ue)return!1;let _e=(Ft,Qr)=>Ft+(Qr-Ft%Qr)%Qr;for(var Me=1;Me<=4;Me*=2){var Pe=B*(1+.2/Me);Pe=Math.min(Pe,F+100663296);var fe=Math.min(ue,_e(Math.max(F,Pe),65536)),ve=ay(fe);if(ve)return!0}return!1}function uy(){throw\"unwind\"}function im(F){return w?Qa(4,1,F):52}function um(F,B,ue,_e,Me){return w?Qa(5,1,F,B,ue,_e,Me):70}var py=[null,[],[]];function cy(F,B){var ue=py[F];B===0||B===10?((F===1?U:K)(Ae(ue,0)),ue.length=0):ue.push(B)}function pm(F,B,ue,_e){if(w)return Qa(6,1,F,B,ue,_e);for(var Me=0,Pe=0;Pe>2],ve=a()[B+4>>2];B+=8;for(var Ft=0;Ft>2]=Me,0}function cm(F){var B=u[\"_\"+F];return B}function ly(F,B){t().set(F,B)}function my(F,B,ue,_e,Me){var Pe={string:Dr=>{var sp=0;if(Dr!=null&&Dr!==0){var WI=(Dr.length<<2)+1;sp=bm(WI),pt(Dr,sp,WI)}return sp},array:Dr=>{var sp=bm(Dr.length);return ly(Dr,sp),sp}};function fe(Dr){return B===\"string\"?Re(Dr):B===\"boolean\"?Boolean(Dr):Dr}var ve=cm(F),Ft=[],Qr=0;if(_e)for(var na=0;na<_e.length;na++){var zI=Pe[ue[na]];zI?(Qr===0&&(Qr=gb()),Ft[na]=zI(_e[na])):Ft[na]=_e[na]}var xb=ve.apply(null,Ft);function OV(Dr){return Qr!==0&&ym(Qr),fe(Dr)}return xb=OV(xb),xb}function dy(F,B,ue,_e){ue=ue||[];var Me=ue.every(fe=>fe===\"number\"||fe===\"boolean\"),Pe=B!==\"string\";return Pe&&Me&&!_e?cm(F):function(){return my(F,B,ue,arguments,_e)}}Oe.init();var fy=[null,tm,om,nm,im,um,pm],lm={__emscripten_init_main_thread_js:Hx,__emscripten_thread_cleanup:Kx,__pthread_create_js:sm,_emscripten_default_pthread_stack_size:qx,_emscripten_get_now_is_monotonic:Xx,_emscripten_notify_task_queue:Yx,_emscripten_set_offscreencanvas_size:Qx,abort:Zx,emscripten_check_blocking_allowed:Jx,emscripten_date_now:ey,emscripten_get_heap_max:ty,emscripten_get_now:Lc,emscripten_memcpy_big:ry,emscripten_num_logical_cores:oy,emscripten_receive_on_main_thread_js:sy,emscripten_resize_heap:iy,emscripten_unwind_to_js_event_loop:uy,exit:rm,fd_close:im,fd_seek:um,fd_write:pm,memory:te||u.wasmMemory},FI=Ox(),hy=u.___wasm_call_ctors=function(){return(hy=u.___wasm_call_ctors=u.asm.__wasm_call_ctors).apply(null,arguments)},gy=u._init=function(){return(gy=u._init=u.asm.init).apply(null,arguments)},xy=u._init_with_threads_count=function(){return(xy=u._init_with_threads_count=u.asm.init_with_threads_count).apply(null,arguments)},yy=u._get_threads_count=function(){return(yy=u._get_threads_count=u.asm.get_threads_count).apply(null,arguments)},by=u._register_tensor=function(){return(by=u._register_tensor=u.asm.register_tensor).apply(null,arguments)},Cy=u._dispose_data=function(){return(Cy=u._dispose_data=u.asm.dispose_data).apply(null,arguments)},Sy=u._dispose=function(){return(Sy=u._dispose=u.asm.dispose).apply(null,arguments)},wy=u._Abs=function(){return(wy=u._Abs=u.asm.Abs).apply(null,arguments)},Iy=u._Add=function(){return(Iy=u._Add=u.asm.Add).apply(null,arguments)},vy=u._AddN=function(){return(vy=u._AddN=u.asm.AddN).apply(null,arguments)},ky=u._All=function(){return(ky=u._All=u.asm.All).apply(null,arguments)},Ny=u._Any=function(){return(Ny=u._Any=u.asm.Any).apply(null,arguments)},Ty=u._ArgMax=function(){return(Ty=u._ArgMax=u.asm.ArgMax).apply(null,arguments)},_y=u._AvgPool=function(){return(_y=u._AvgPool=u.asm.AvgPool).apply(null,arguments)},$y=u._BatchMatMul=function(){return($y=u._BatchMatMul=u.asm.BatchMatMul).apply(null,arguments)},Ey=u._Ceil=function(){return(Ey=u._Ceil=u.asm.Ceil).apply(null,arguments)},Ay=u._ClipByValue=function(){return(Ay=u._ClipByValue=u.asm.ClipByValue).apply(null,arguments)},Ry=u._Conv2D=function(){return(Ry=u._Conv2D=u.asm.Conv2D).apply(null,arguments)},Dy=u._Conv2DBackpropInput=function(){return(Dy=u._Conv2DBackpropInput=u.asm.Conv2DBackpropInput).apply(null,arguments)},Fy=u._Cos=function(){return(Fy=u._Cos=u.asm.Cos).apply(null,arguments)},Oy=u._Cosh=function(){return(Oy=u._Cosh=u.asm.Cosh).apply(null,arguments)},Py=u._CropAndResize=function(){return(Py=u._CropAndResize=u.asm.CropAndResize).apply(null,arguments)},My=u._Cumprod=function(){return(My=u._Cumprod=u.asm.Cumprod).apply(null,arguments)},Ly=u._Cumsum=function(){return(Ly=u._Cumsum=u.asm.Cumsum).apply(null,arguments)},By=u._DepthToSpace=function(){return(By=u._DepthToSpace=u.asm.DepthToSpace).apply(null,arguments)},Vy=u._DepthwiseConv2dNative=function(){return(Vy=u._DepthwiseConv2dNative=u.asm.DepthwiseConv2dNative).apply(null,arguments)},zy=u._Elu=function(){return(zy=u._Elu=u.asm.Elu).apply(null,arguments)},Wy=u._Equal=function(){return(Wy=u._Equal=u.asm.Equal).apply(null,arguments)},Uy=u._Exp=function(){return(Uy=u._Exp=u.asm.Exp).apply(null,arguments)},Gy=u._FlipLeftRight=function(){return(Gy=u._FlipLeftRight=u.asm.FlipLeftRight).apply(null,arguments)},Hy=u._Floor=function(){return(Hy=u._Floor=u.asm.Floor).apply(null,arguments)},Ky=u._FloorDiv=function(){return(Ky=u._FloorDiv=u.asm.FloorDiv).apply(null,arguments)},qy=u._FusedBatchNorm=function(){return(qy=u._FusedBatchNorm=u.asm.FusedBatchNorm).apply(null,arguments)},jy=u._FusedConv2D=function(){return(jy=u._FusedConv2D=u.asm.FusedConv2D).apply(null,arguments)},Xy=u._FusedDepthwiseConv2D=function(){return(Xy=u._FusedDepthwiseConv2D=u.asm.FusedDepthwiseConv2D).apply(null,arguments)},Yy=u._Gather=function(){return(Yy=u._Gather=u.asm.Gather).apply(null,arguments)},Qy=u._GatherNd=function(){return(Qy=u._GatherNd=u.asm.GatherNd).apply(null,arguments)},Zy=u._Greater=function(){return(Zy=u._Greater=u.asm.Greater).apply(null,arguments)},Jy=u._GreaterEqual=function(){return(Jy=u._GreaterEqual=u.asm.GreaterEqual).apply(null,arguments)},eb=u._IsNan=function(){return(eb=u._IsNan=u.asm.IsNan).apply(null,arguments)},tb=u._LeakyRelu=function(){return(tb=u._LeakyRelu=u.asm.LeakyRelu).apply(null,arguments)},rb=u._Less=function(){return(rb=u._Less=u.asm.Less).apply(null,arguments)},ob=u._LessEqual=function(){return(ob=u._LessEqual=u.asm.LessEqual).apply(null,arguments)},nb=u._Log=function(){return(nb=u._Log=u.asm.Log).apply(null,arguments)},sb=u._LogicalAnd=function(){return(sb=u._LogicalAnd=u.asm.LogicalAnd).apply(null,arguments)},ab=u._LogicalNot=function(){return(ab=u._LogicalNot=u.asm.LogicalNot).apply(null,arguments)},ib=u._LogicalOr=function(){return(ib=u._LogicalOr=u.asm.LogicalOr).apply(null,arguments)},ub=u._LogicalXor=function(){return(ub=u._LogicalXor=u.asm.LogicalXor).apply(null,arguments)},pb=u._Max=function(){return(pb=u._Max=u.asm.Max).apply(null,arguments)},cb=u._MaxPool=function(){return(cb=u._MaxPool=u.asm.MaxPool).apply(null,arguments)},mm=u._Maximum=function(){return(mm=u._Maximum=u.asm.Maximum).apply(null,arguments)},dm=u._Mean=function(){return(dm=u._Mean=u.asm.Mean).apply(null,arguments)},Vc=u._Min=function(){return(Vc=u._Min=u.asm.Min).apply(null,arguments)},lb=u._Minimum=function(){return(lb=u._Minimum=u.asm.Minimum).apply(null,arguments)},mb=u._MirrorPad=function(){return(mb=u._MirrorPad=u.asm.MirrorPad).apply(null,arguments)},rp=u._Multiply=function(){return(rp=u._Multiply=u.asm.Multiply).apply(null,arguments)},fm=u._Neg=function(){return(fm=u._Neg=u.asm.Neg).apply(null,arguments)},op=u._NonMaxSuppressionV3=function(){return(op=u._NonMaxSuppressionV3=u.asm.NonMaxSuppressionV3).apply(null,arguments)},np=u._NonMaxSuppressionV4=function(){return(np=u._NonMaxSuppressionV4=u.asm.NonMaxSuppressionV4).apply(null,arguments)},db=u._NonMaxSuppressionV5=function(){return(db=u._NonMaxSuppressionV5=u.asm.NonMaxSuppressionV5).apply(null,arguments)},G=u._NotEqual=function(){return(G=u._NotEqual=u.asm.NotEqual).apply(null,arguments)},se=u._OneHot=function(){return(se=u._OneHot=u.asm.OneHot).apply(null,arguments)},Te=u._PadV2=function(){return(Te=u._PadV2=u.asm.PadV2).apply(null,arguments)},nt=u._Pow=function(){return(nt=u._Pow=u.asm.Pow).apply(null,arguments)},Tt=u._Prelu=function(){return(Tt=u._Prelu=u.asm.Prelu).apply(null,arguments)},_t=u._Prod=function(){return(_t=u._Prod=u.asm.Prod).apply(null,arguments)},qe=u._RealDiv=function(){return(qe=u._RealDiv=u.asm.RealDiv).apply(null,arguments)},Ue=u._Reciprocal=function(){return(Ue=u._Reciprocal=u.asm.Reciprocal).apply(null,arguments)},Wt=u._Relu=function(){return(Wt=u._Relu=u.asm.Relu).apply(null,arguments)},Yr=u._Relu6=function(){return(Yr=u._Relu6=u.asm.Relu6).apply(null,arguments)},oa=u._ResizeBilinear=function(){return(oa=u._ResizeBilinear=u.asm.ResizeBilinear).apply(null,arguments)},hm=u._ResizeNearestNeighbor=function(){return(hm=u._ResizeNearestNeighbor=u.asm.ResizeNearestNeighbor).apply(null,arguments)},zc=u._Reverse=function(){return(zc=u._Reverse=u.asm.Reverse).apply(null,arguments)},fb=u._RotateWithOffset=function(){return(fb=u._RotateWithOffset=u.asm.RotateWithOffset).apply(null,arguments)},hr=u._Round=function(){return(hr=u._Round=u.asm.Round).apply(null,arguments)},Za=u._Rsqrt=function(){return(Za=u._Rsqrt=u.asm.Rsqrt).apply(null,arguments)},gm=u._ScatterNd=function(){return(gm=u._ScatterNd=u.asm.ScatterNd).apply(null,arguments)},oV=u._SelectV2=function(){return(oV=u._SelectV2=u.asm.SelectV2).apply(null,arguments)},nV=u._Sigmoid=function(){return(nV=u._Sigmoid=u.asm.Sigmoid).apply(null,arguments)},sV=u._Sin=function(){return(sV=u._Sin=u.asm.Sin).apply(null,arguments)},aV=u._Softmax=function(){return(aV=u._Softmax=u.asm.Softmax).apply(null,arguments)},iV=u._SparseFillEmptyRows=function(){return(iV=u._SparseFillEmptyRows=u.asm.SparseFillEmptyRows).apply(null,arguments)},uV=u._SparseReshape=function(){return(uV=u._SparseReshape=u.asm.SparseReshape).apply(null,arguments)},pV=u._SparseSegmentReduction=function(){return(pV=u._SparseSegmentReduction=u.asm.SparseSegmentReduction).apply(null,arguments)},cV=u._Sqrt=function(){return(cV=u._Sqrt=u.asm.Sqrt).apply(null,arguments)},lV=u._Square=function(){return(lV=u._Square=u.asm.Square).apply(null,arguments)},mV=u._SquaredDifference=function(){return(mV=u._SquaredDifference=u.asm.SquaredDifference).apply(null,arguments)},dV=u._Step=function(){return(dV=u._Step=u.asm.Step).apply(null,arguments)},fV=u._StridedSlice=function(){return(fV=u._StridedSlice=u.asm.StridedSlice).apply(null,arguments)},hV=u._Sub=function(){return(hV=u._Sub=u.asm.Sub).apply(null,arguments)},gV=u._Sum=function(){return(gV=u._Sum=u.asm.Sum).apply(null,arguments)},xV=u._Tan=function(){return(xV=u._Tan=u.asm.Tan).apply(null,arguments)},yV=u._Tanh=function(){return(yV=u._Tanh=u.asm.Tanh).apply(null,arguments)},bV=u._Tile=function(){return(bV=u._Tile=u.asm.Tile).apply(null,arguments)},CV=u._TopK=function(){return(CV=u._TopK=u.asm.TopK).apply(null,arguments)},SV=u._Transform=function(){return(SV=u._Transform=u.asm.Transform).apply(null,arguments)},wV=u._Transpose=function(){return(wV=u._Transpose=u.asm.Transpose).apply(null,arguments)},IV=u.__FusedMatMul=function(){return(IV=u.__FusedMatMul=u.asm._FusedMatMul).apply(null,arguments)},vV=u._malloc=function(){return(vV=u._malloc=u.asm.malloc).apply(null,arguments)},kV=u._free=function(){return(kV=u._free=u.asm.free).apply(null,arguments)},NV=u.__emscripten_tls_init=function(){return(NV=u.__emscripten_tls_init=u.asm._emscripten_tls_init).apply(null,arguments)},xm=u._pthread_self=function(){return(xm=u._pthread_self=u.asm.pthread_self).apply(null,arguments)},TV=u.___errno_location=function(){return(TV=u.___errno_location=u.asm.__errno_location).apply(null,arguments)},OI=u.__emscripten_thread_init=function(){return(OI=u.__emscripten_thread_init=u.asm._emscripten_thread_init).apply(null,arguments)},_V=u.__emscripten_thread_crashed=function(){return(_V=u.__emscripten_thread_crashed=u.asm._emscripten_thread_crashed).apply(null,arguments)},$V=u._emscripten_main_thread_process_queued_calls=function(){return($V=u._emscripten_main_thread_process_queued_calls=u.asm.emscripten_main_thread_process_queued_calls).apply(null,arguments)},EV=u._emscripten_main_browser_thread_id=function(){return(EV=u._emscripten_main_browser_thread_id=u.asm.emscripten_main_browser_thread_id).apply(null,arguments)},PI=u._emscripten_run_in_main_runtime_thread_js=function(){return(PI=u._emscripten_run_in_main_runtime_thread_js=u.asm.emscripten_run_in_main_runtime_thread_js).apply(null,arguments)},AV=u._emscripten_dispatch_to_thread_=function(){return(AV=u._emscripten_dispatch_to_thread_=u.asm.emscripten_dispatch_to_thread_).apply(null,arguments)},MI=u.__emscripten_proxy_execute_task_queue=function(){return(MI=u.__emscripten_proxy_execute_task_queue=u.asm._emscripten_proxy_execute_task_queue).apply(null,arguments)},hb=u.__emscripten_thread_free_data=function(){return(hb=u.__emscripten_thread_free_data=u.asm._emscripten_thread_free_data).apply(null,arguments)},LI=u.__emscripten_thread_exit=function(){return(LI=u.__emscripten_thread_exit=u.asm._emscripten_thread_exit).apply(null,arguments)},BI=u._emscripten_stack_set_limits=function(){return(BI=u._emscripten_stack_set_limits=u.asm.emscripten_stack_set_limits).apply(null,arguments)},gb=u.stackSave=function(){return(gb=u.stackSave=u.asm.stackSave).apply(null,arguments)},ym=u.stackRestore=function(){return(ym=u.stackRestore=u.asm.stackRestore).apply(null,arguments)},bm=u.stackAlloc=function(){return(bm=u.stackAlloc=u.asm.stackAlloc).apply(null,arguments)},RV=u.dynCall_iijjiiii=function(){return(RV=u.dynCall_iijjiiii=u.asm.dynCall_iijjiiii).apply(null,arguments)},DV=u.dynCall_jiji=function(){return(DV=u.dynCall_jiji=u.asm.dynCall_jiji).apply(null,arguments)};u.keepRuntimeAlive=Do,u.wasmMemory=te,u.cwrap=dy,u.ExitStatus=qi,u.PThread=Oe;var Cm;ra=function F(){Cm||VI(),Cm||(ra=F)};function VI(F){if(F=F||f,Ya>0)return;if(w){c(u),qt(),startWorker(u);return}if(hs(),Ya>0)return;function B(){Cm||(Cm=!0,u.calledRun=!0,!ce&&(qt(),c(u),u.onRuntimeInitialized&&u.onRuntimeInitialized(),ta()))}u.setStatus?(u.setStatus(\"Running...\"),setTimeout(function(){setTimeout(function(){u.setStatus(\"\")},1),B()},1)):B()}if(u.preInit)for(typeof u.preInit==\"function\"&&(u.preInit=[u.preInit]);u.preInit.length>0;)u.preInit.pop()();VI();var Sm;m&&(Sm={uncaughtException:process.listeners(\"uncaughtException\").filter(function(F){return!m.uncaughtException.indexOf(F)>-1}),unhandledRejection:process.listeners(\"unhandledRejection\").filter(function(F){return!m.unhandledRejection.indexOf(F)>-1})});var wm;if(typeof WasmBackendModule!=\"undefined\")wm=WasmBackendModule;else if(typeof e!=\"undefined\")wm=e;else throw new Error(\"Could not find wasm module in post.js\");if(Sm){var FV=wm._dispose;wm._dispose=function(){FV(),Sm.uncaughtException.forEach(function(F){process.removeListener(\"uncaughtException\",F)}),Sm.unhandledRejection.forEach(function(F){process.removeListener(\"unhandledRejection\",F)})}}return e.ready}})();typeof wg==\"object\"&&typeof aI==\"object\"?aI.exports=sI:typeof define==\"function\"&&define.amd?define([],function(){return sI}):typeof wg==\"object\"&&(wg.WasmBackendModuleThreadedSimd=sI)});var w3=Kt((a1t,S3)=>{S3.exports.wasmWorkerContents=`\"use strict\";var Module={};var ENVIRONMENT_IS_NODE=typeof process==\"object\"&&typeof process.versions==\"object\"&&typeof process.versions.node==\"string\";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require(\"worker_threads\");var parentPort=nodeWorkerThreads.parentPort;parentPort.on(\"message\",data=>onmessage({data:data}));var fs=require(\"fs\");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(fs.readFileSync(f,\"utf8\")+\"//# sourceURL=\"+f)},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;var pendingNotifiedProxyingQueues=[];function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(\" \");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+\"\n\");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(\" \");postMessage({cmd:\"alert\",text:text,threadId:Module[\"_pthread_self\"]()})}var err=threadPrintErr;self.alert=threadAlert;Module[\"instantiateWasm\"]=(info,receiveInstance)=>{var instance=new WebAssembly.Instance(Module[\"wasmModule\"],info);receiveInstance(instance);Module[\"wasmModule\"]=null;return instance.exports};self.onunhandledrejection=e=>{throw e.reason??e};self.startWorker=instance=>{Module=instance;postMessage({\"cmd\":\"loaded\"})};self.onmessage=e=>{try{if(e.data.cmd===\"load\"){Module[\"wasmModule\"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=function(){postMessage({cmd:\"callHandler\",handler:handler,args:[...arguments]})}}Module[\"wasmMemory\"]=e.data.wasmMemory;Module[\"buffer\"]=Module[\"wasmMemory\"].buffer;Module[\"ENVIRONMENT_IS_PTHREAD\"]=true;if(typeof e.data.urlOrBlob==\"string\"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}WasmBackendModuleThreadedSimd(Module)}else if(e.data.cmd===\"run\"){Module[\"__emscripten_thread_init\"](e.data.pthread_ptr,0,0,1);Module[\"establishStackSpace\"]();Module[\"PThread\"].receiveObjectTransfer(e.data);Module[\"PThread\"].threadInitTLS();if(!initializedJS){pendingNotifiedProxyingQueues.forEach(queue=>{Module[\"executeNotifiedProxyingQueue\"](queue)});pendingNotifiedProxyingQueues=[];initializedJS=true}try{Module[\"invokeEntryPoint\"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!=\"unwind\"){if(ex instanceof Module[\"ExitStatus\"]){if(Module[\"keepRuntimeAlive\"]()){}else{Module[\"__emscripten_thread_exit\"](ex.status)}}else{throw ex}}}}else if(e.data.cmd===\"cancel\"){if(Module[\"_pthread_self\"]()){Module[\"__emscripten_thread_exit\"](-1)}}else if(e.data.target===\"setimmediate\"){}else if(e.data.cmd===\"processProxyingQueue\"){if(initializedJS){Module[\"executeNotifiedProxyingQueue\"](e.data.queue)}else{pendingNotifiedProxyingQueues.push(e.data.queue)}}else if(e.data.cmd){err(\"worker.js received unknown command \"+e.data.cmd);err(e.data)}}catch(ex){if(Module[\"__emscripten_thread_crashed\"]){Module[\"__emscripten_thread_crashed\"]()}throw ex}};`});var I3=Kt((Ig,uI)=>{var iI=(()=>{var r=typeof document!=\"undefined\"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename!=\"undefined\"&&(r=r||__filename),function(e){e=e||{};var t=typeof e!=\"undefined\"?e:{},o,n;t.ready=new Promise(function(G,se){o=G,n=se});var s;typeof process!=\"undefined\"&&process.listeners&&(s={uncaughtException:process.listeners(\"uncaughtException\"),unhandledRejection:process.listeners(\"unhandledRejection\")});var a=Object.assign({},t),i=[],p=\"./this.program\",u=(G,se)=>{throw se},c=typeof window==\"object\",l=typeof importScripts==\"function\",m=typeof process==\"object\"&&typeof process.versions==\"object\"&&typeof process.versions.node==\"string\",d=\"\";function f(G){return t.locateFile?t.locateFile(G,d):d+G}var h,g,x,b;function C(G){if(G instanceof Ju)return;E(\"exiting due to exception: \"+G)}if(m){var w=oI(),k=nI();l?d=k.dirname(d)+\"/\":d=__dirname+\"/\",h=(G,se)=>(G=hs(G)?new URL(G):k.normalize(G),w.readFileSync(G,se?void 0:\"utf8\")),x=G=>{var se=h(G,!0);return se.buffer||(se=new Uint8Array(se)),se},g=(G,se,Te)=>{G=hs(G)?new URL(G):k.normalize(G),w.readFile(G,function(nt,Tt){nt?Te(nt):se(Tt.buffer)})},process.argv.length>1&&(p=process.argv[1].replace(/\\\\/g,\"/\")),i=process.argv.slice(2),process.on(\"uncaughtException\",function(G){if(!(G instanceof Ju))throw G}),process.on(\"unhandledRejection\",function(G){throw G}),u=(G,se)=>{if(at())throw process.exitCode=G,se;C(se),process.exit(G)},t.inspect=function(){return\"[Emscripten Module object]\"}}else(c||l)&&(l?d=self.location.href:typeof document!=\"undefined\"&&document.currentScript&&(d=document.currentScript.src),r&&(d=r),d.indexOf(\"blob:\")!==0?d=d.substr(0,d.replace(/[?#].*/,\"\").lastIndexOf(\"/\")+1):d=\"\",h=G=>{var se=new XMLHttpRequest;return se.open(\"GET\",G,!1),se.send(null),se.responseText},l&&(x=G=>{var se=new XMLHttpRequest;return se.open(\"GET\",G,!1),se.responseType=\"arraybuffer\",se.send(null),new Uint8Array(se.response)}),g=(G,se,Te)=>{var nt=new XMLHttpRequest;nt.open(\"GET\",G,!0),nt.responseType=\"arraybuffer\",nt.onload=()=>{if(nt.status==200||nt.status==0&&nt.response){se(nt.response);return}Te()},nt.onerror=Te,nt.send(null)},b=G=>document.title=G);var _=t.print||console.log.bind(console),E=t.printErr||console.warn.bind(console);Object.assign(t,a),a=null,t.arguments&&(i=t.arguments),t.thisProgram&&(p=t.thisProgram),t.quit&&(u=t.quit);var A=4,R;t.wasmBinary&&(R=t.wasmBinary);var D=t.noExitRuntime||!0;typeof WebAssembly!=\"object\"&&cr(\"no native wasm support detected\");var P,M=!1,L;function V(G,se){G||cr(se)}var z=typeof TextDecoder!=\"undefined\"?new TextDecoder(\"utf8\"):void 0;function U(G,se,Te){for(var nt=se+Te,Tt=se;G[Tt]&&!(Tt>=nt);)++Tt;if(Tt-se>16&&G.buffer&&z)return z.decode(G.subarray(se,Tt));for(var _t=\"\";se>10,56320|Yr&1023)}}return _t}function K(G,se){return G?U(oe,G,se):\"\"}function H(G,se,Te,nt){if(!(nt>0))return 0;for(var Tt=Te,_t=Te+nt-1,qe=0;qe=55296&&Ue<=57343){var Wt=G.charCodeAt(++qe);Ue=65536+((Ue&1023)<<10)|Wt&1023}if(Ue<=127){if(Te>=_t)break;se[Te++]=Ue}else if(Ue<=2047){if(Te+1>=_t)break;se[Te++]=192|Ue>>6,se[Te++]=128|Ue&63}else if(Ue<=65535){if(Te+2>=_t)break;se[Te++]=224|Ue>>12,se[Te++]=128|Ue>>6&63,se[Te++]=128|Ue&63}else{if(Te+3>=_t)break;se[Te++]=240|Ue>>18,se[Te++]=128|Ue>>12&63,se[Te++]=128|Ue>>6&63,se[Te++]=128|Ue&63}}return se[Te]=0,Te-Tt}function q(G,se,Te){return H(G,oe,se,Te)}var Z,ee,oe,J,te,ie,ce,ye,Ne;function Ie(G){Z=G,t.HEAP8=ee=new Int8Array(G),t.HEAP16=J=new Int16Array(G),t.HEAP32=ie=new Int32Array(G),t.HEAPU8=oe=new Uint8Array(G),t.HEAPU16=te=new Uint16Array(G),t.HEAPU32=ce=new Uint32Array(G),t.HEAPF32=ye=new Float32Array(G),t.HEAPF64=Ne=new Float64Array(G)}var Ae=t.INITIAL_MEMORY||16777216,Re,ot=[],pt=[],ze=[],ct=!1;function at(){return D}function ft(){if(t.preRun)for(typeof t.preRun==\"function\"&&(t.preRun=[t.preRun]);t.preRun.length;)Pt(t.preRun.shift());ra(ot)}function ht(){ct=!0,ra(pt)}function Rr(){if(t.postRun)for(typeof t.postRun==\"function\"&&(t.postRun=[t.postRun]);t.postRun.length;)er(t.postRun.shift());ra(ze)}function Pt(G){ot.unshift(G)}function qr(G){pt.unshift(G)}function er(G){ze.unshift(G)}var Nt=0,tr=null,rr=null;function jr(G){Nt++,t.monitorRunDependencies&&t.monitorRunDependencies(Nt)}function Xr(G){if(Nt--,t.monitorRunDependencies&&t.monitorRunDependencies(Nt),Nt==0&&(tr!==null&&(clearInterval(tr),tr=null),rr)){var se=rr;rr=null,se()}}function cr(G){t.onAbort&&t.onAbort(G),G=\"Aborted(\"+G+\")\",E(G),M=!0,L=1,G+=\". Build with -sASSERTIONS for more info.\";var se=new WebAssembly.RuntimeError(G);throw n(se),se}var ea=\"data:application/octet-stream;base64,\";function Do(G){return G.startsWith(ea)}function hs(G){return G.startsWith(\"file://\")}var qt;qt=\"tfjs-backend-wasm.wasm\",Do(qt)||(qt=f(qt));function ta(G){try{if(G==qt&&R)return new Uint8Array(R);if(x)return x(G);throw\"both async and sync fetching of the wasm failed\"}catch(se){cr(se)}}function Dc(){if(!R&&(c||l)){if(typeof fetch==\"function\"&&!hs(qt))return fetch(qt,{credentials:\"same-origin\"}).then(function(G){if(!G.ok)throw\"failed to load wasm binary file at '\"+qt+\"'\";return G.arrayBuffer()}).catch(function(){return ta(qt)});if(g)return new Promise(function(G,se){g(qt,function(Te){G(new Uint8Array(Te))},se)})}return Promise.resolve().then(function(){return ta(qt)})}function Fc(){var G={env:Oc,wasi_snapshot_preview1:Oc};function se(qe,Ue){var Wt=qe.exports;t.asm=Wt,P=t.asm.memory,Ie(P.buffer),Re=t.asm.__indirect_function_table,qr(t.asm.__wasm_call_ctors),Xr(\"wasm-instantiate\")}jr(\"wasm-instantiate\");function Te(qe){se(qe.instance)}function nt(qe){return Dc().then(function(Ue){return WebAssembly.instantiate(Ue,G)}).then(function(Ue){return Ue}).then(qe,function(Ue){E(\"failed to asynchronously prepare wasm: \"+Ue),cr(Ue)})}function Tt(){return!R&&typeof WebAssembly.instantiateStreaming==\"function\"&&!Do(qt)&&!hs(qt)&&!m&&typeof fetch==\"function\"?fetch(qt,{credentials:\"same-origin\"}).then(function(qe){var Ue=WebAssembly.instantiateStreaming(qe,G);return Ue.then(Te,function(Wt){return E(\"wasm streaming compile failed: \"+Wt),E(\"falling back to ArrayBuffer instantiation\"),nt(Te)})}):nt(Te)}if(t.instantiateWasm)try{var _t=t.instantiateWasm(G,se);return _t}catch(qe){E(\"Module.instantiateWasm callback failed with error: \"+qe),n(qe)}return Tt().catch(n),{}}var AI,Ya;function Ju(G){this.name=\"ExitStatus\",this.message=\"Program terminated with exit(\"+G+\")\",this.status=G}function ra(G){for(;G.length>0;)G.shift()(t)}function Rx(){cr(\"\")}function Yl(){return 2147483648}function Ki(){return Yl()}function Dx(G,se,Te){oe.copyWithin(G,se,se+Te)}function Ql(G){try{return P.grow(G-Z.byteLength+65535>>>16),Ie(P.buffer),1}catch(se){}}function ep(G){var se=oe.length;G=G>>>0;var Te=Yl();if(G>Te)return!1;let nt=(Wt,Yr)=>Wt+(Yr-Wt%Yr)%Yr;for(var Tt=1;Tt<=4;Tt*=2){var _t=se*(1+.2/Tt);_t=Math.min(_t,G+100663296);var qe=Math.min(Te,nt(Math.max(G,_t),65536)),Ue=Ql(qe);if(Ue)return!0}return!1}var lr={varargs:void 0,get:function(){lr.varargs+=4;var G=ie[lr.varargs-4>>2];return G},getStr:function(G){var se=K(G);return se}};function Zl(G){return 52}function Fx(G,se,Te,nt,Tt){return 70}var Ox=[null,[],[]];function RI(G,se){var Te=Ox[G];se===0||se===10?((G===1?_:E)(U(Te,0)),Te.length=0):Te.push(se)}function DI(G,se,Te,nt){for(var Tt=0,_t=0;_t>2],Ue=ce[se+4>>2];se+=8;for(var Wt=0;Wt>2]=Tt,0}function Jl(G){var se=t[\"_\"+G];return se}function qi(G,se){ee.set(G,se)}function Px(G,se,Te,nt,Tt){var _t={string:hr=>{var Za=0;if(hr!=null&&hr!==0){var gm=(hr.length<<2)+1;Za=Vc(gm),q(hr,Za,gm)}return Za},array:hr=>{var Za=Vc(hr.length);return qi(hr,Za),Za}};function qe(hr){return se===\"string\"?K(hr):se===\"boolean\"?Boolean(hr):hr}var Ue=Jl(G),Wt=[],Yr=0;if(nt)for(var oa=0;oaqe===\"number\"||qe===\"boolean\"),_t=se!==\"string\";return _t&&Tt&&!nt?Jl(G):function(){return Px(G,se,Te,arguments,nt)}}var Oc={abort:Rx,emscripten_get_heap_max:Ki,emscripten_memcpy_big:Dx,emscripten_resize_heap:ep,fd_close:Zl,fd_seek:Fx,fd_write:DI},Lx=Fc(),em=t.___wasm_call_ctors=function(){return(em=t.___wasm_call_ctors=t.asm.__wasm_call_ctors).apply(null,arguments)},tm=t._init=function(){return(tm=t._init=t.asm.init).apply(null,arguments)},Bx=t._init_with_threads_count=function(){return(Bx=t._init_with_threads_count=t.asm.init_with_threads_count).apply(null,arguments)},rm=t._get_threads_count=function(){return(rm=t._get_threads_count=t.asm.get_threads_count).apply(null,arguments)},Vx=t._register_tensor=function(){return(Vx=t._register_tensor=t.asm.register_tensor).apply(null,arguments)},Oe=t._dispose_data=function(){return(Oe=t._dispose_data=t.asm.dispose_data).apply(null,arguments)},Pc=t._dispose=function(){return(Pc=t._dispose=t.asm.dispose).apply(null,arguments)},zx=t._Abs=function(){return(zx=t._Abs=t.asm.Abs).apply(null,arguments)},om=t._Add=function(){return(om=t._Add=t.asm.Add).apply(null,arguments)},tp=t._AddN=function(){return(tp=t._AddN=t.asm.AddN).apply(null,arguments)},Wx=t._All=function(){return(Wx=t._All=t.asm.All).apply(null,arguments)},Ux=t._Any=function(){return(Ux=t._Any=t.asm.Any).apply(null,arguments)},Gx=t._ArgMax=function(){return(Gx=t._ArgMax=t.asm.ArgMax).apply(null,arguments)},Hx=t._AvgPool=function(){return(Hx=t._AvgPool=t.asm.AvgPool).apply(null,arguments)},Kx=t._BatchMatMul=function(){return(Kx=t._BatchMatMul=t.asm.BatchMatMul).apply(null,arguments)},nm=t._Ceil=function(){return(nm=t._Ceil=t.asm.Ceil).apply(null,arguments)},sm=t._ClipByValue=function(){return(sm=t._ClipByValue=t.asm.ClipByValue).apply(null,arguments)},qx=t._Conv2D=function(){return(qx=t._Conv2D=t.asm.Conv2D).apply(null,arguments)},jx=t._Conv2DBackpropInput=function(){return(jx=t._Conv2DBackpropInput=t.asm.Conv2DBackpropInput).apply(null,arguments)},Xx=t._Cos=function(){return(Xx=t._Cos=t.asm.Cos).apply(null,arguments)},Mc=t._Cosh=function(){return(Mc=t._Cosh=t.asm.Cosh).apply(null,arguments)},Yx=t._CropAndResize=function(){return(Yx=t._CropAndResize=t.asm.CropAndResize).apply(null,arguments)},Qx=t._Cumprod=function(){return(Qx=t._Cumprod=t.asm.Cumprod).apply(null,arguments)},Zx=t._Cumsum=function(){return(Zx=t._Cumsum=t.asm.Cumsum).apply(null,arguments)},ji=t._DepthToSpace=function(){return(ji=t._DepthToSpace=t.asm.DepthToSpace).apply(null,arguments)},Jx=t._DepthwiseConv2dNative=function(){return(Jx=t._DepthwiseConv2dNative=t.asm.DepthwiseConv2dNative).apply(null,arguments)},ey=t._Elu=function(){return(ey=t._Elu=t.asm.Elu).apply(null,arguments)},am=t._Equal=function(){return(am=t._Equal=t.asm.Equal).apply(null,arguments)},ty=t._Exp=function(){return(ty=t._Exp=t.asm.Exp).apply(null,arguments)},Lc=t._FlipLeftRight=function(){return(Lc=t._FlipLeftRight=t.asm.FlipLeftRight).apply(null,arguments)},ry=t._Floor=function(){return(ry=t._Floor=t.asm.Floor).apply(null,arguments)},oy=t._FloorDiv=function(){return(oy=t._FloorDiv=t.asm.FloorDiv).apply(null,arguments)},ny=t._FusedBatchNorm=function(){return(ny=t._FusedBatchNorm=t.asm.FusedBatchNorm).apply(null,arguments)},Qa=t._FusedConv2D=function(){return(Qa=t._FusedConv2D=t.asm.FusedConv2D).apply(null,arguments)},Bc=t._FusedDepthwiseConv2D=function(){return(Bc=t._FusedDepthwiseConv2D=t.asm.FusedDepthwiseConv2D).apply(null,arguments)},sy=t._Gather=function(){return(sy=t._Gather=t.asm.Gather).apply(null,arguments)},ay=t._GatherNd=function(){return(ay=t._GatherNd=t.asm.GatherNd).apply(null,arguments)},iy=t._Greater=function(){return(iy=t._Greater=t.asm.Greater).apply(null,arguments)},uy=t._GreaterEqual=function(){return(uy=t._GreaterEqual=t.asm.GreaterEqual).apply(null,arguments)},im=t._IsNan=function(){return(im=t._IsNan=t.asm.IsNan).apply(null,arguments)},um=t._LeakyRelu=function(){return(um=t._LeakyRelu=t.asm.LeakyRelu).apply(null,arguments)},py=t._Less=function(){return(py=t._Less=t.asm.Less).apply(null,arguments)},cy=t._LessEqual=function(){return(cy=t._LessEqual=t.asm.LessEqual).apply(null,arguments)},pm=t._Log=function(){return(pm=t._Log=t.asm.Log).apply(null,arguments)},cm=t._LogicalAnd=function(){return(cm=t._LogicalAnd=t.asm.LogicalAnd).apply(null,arguments)},ly=t._LogicalNot=function(){return(ly=t._LogicalNot=t.asm.LogicalNot).apply(null,arguments)},my=t._LogicalOr=function(){return(my=t._LogicalOr=t.asm.LogicalOr).apply(null,arguments)},dy=t._LogicalXor=function(){return(dy=t._LogicalXor=t.asm.LogicalXor).apply(null,arguments)},fy=t._Max=function(){return(fy=t._Max=t.asm.Max).apply(null,arguments)},lm=t._MaxPool=function(){return(lm=t._MaxPool=t.asm.MaxPool).apply(null,arguments)},FI=t._Maximum=function(){return(FI=t._Maximum=t.asm.Maximum).apply(null,arguments)},hy=t._Mean=function(){return(hy=t._Mean=t.asm.Mean).apply(null,arguments)},gy=t._Min=function(){return(gy=t._Min=t.asm.Min).apply(null,arguments)},xy=t._Minimum=function(){return(xy=t._Minimum=t.asm.Minimum).apply(null,arguments)},yy=t._MirrorPad=function(){return(yy=t._MirrorPad=t.asm.MirrorPad).apply(null,arguments)},by=t._Multiply=function(){return(by=t._Multiply=t.asm.Multiply).apply(null,arguments)},Cy=t._Neg=function(){return(Cy=t._Neg=t.asm.Neg).apply(null,arguments)},Sy=t._NonMaxSuppressionV3=function(){return(Sy=t._NonMaxSuppressionV3=t.asm.NonMaxSuppressionV3).apply(null,arguments)},wy=t._NonMaxSuppressionV4=function(){return(wy=t._NonMaxSuppressionV4=t.asm.NonMaxSuppressionV4).apply(null,arguments)},Iy=t._NonMaxSuppressionV5=function(){return(Iy=t._NonMaxSuppressionV5=t.asm.NonMaxSuppressionV5).apply(null,arguments)},vy=t._NotEqual=function(){return(vy=t._NotEqual=t.asm.NotEqual).apply(null,arguments)},ky=t._OneHot=function(){return(ky=t._OneHot=t.asm.OneHot).apply(null,arguments)},Ny=t._PadV2=function(){return(Ny=t._PadV2=t.asm.PadV2).apply(null,arguments)},Ty=t._Pow=function(){return(Ty=t._Pow=t.asm.Pow).apply(null,arguments)},_y=t._Prelu=function(){return(_y=t._Prelu=t.asm.Prelu).apply(null,arguments)},$y=t._Prod=function(){return($y=t._Prod=t.asm.Prod).apply(null,arguments)},Ey=t._RealDiv=function(){return(Ey=t._RealDiv=t.asm.RealDiv).apply(null,arguments)},Ay=t._Reciprocal=function(){return(Ay=t._Reciprocal=t.asm.Reciprocal).apply(null,arguments)},Ry=t._Relu=function(){return(Ry=t._Relu=t.asm.Relu).apply(null,arguments)},Dy=t._Relu6=function(){return(Dy=t._Relu6=t.asm.Relu6).apply(null,arguments)},Fy=t._ResizeBilinear=function(){return(Fy=t._ResizeBilinear=t.asm.ResizeBilinear).apply(null,arguments)},Oy=t._ResizeNearestNeighbor=function(){return(Oy=t._ResizeNearestNeighbor=t.asm.ResizeNearestNeighbor).apply(null,arguments)},Py=t._Reverse=function(){return(Py=t._Reverse=t.asm.Reverse).apply(null,arguments)},My=t._RotateWithOffset=function(){return(My=t._RotateWithOffset=t.asm.RotateWithOffset).apply(null,arguments)},Ly=t._Round=function(){return(Ly=t._Round=t.asm.Round).apply(null,arguments)},By=t._Rsqrt=function(){return(By=t._Rsqrt=t.asm.Rsqrt).apply(null,arguments)},Vy=t._ScatterNd=function(){return(Vy=t._ScatterNd=t.asm.ScatterNd).apply(null,arguments)},zy=t._SelectV2=function(){return(zy=t._SelectV2=t.asm.SelectV2).apply(null,arguments)},Wy=t._Sigmoid=function(){return(Wy=t._Sigmoid=t.asm.Sigmoid).apply(null,arguments)},Uy=t._Sin=function(){return(Uy=t._Sin=t.asm.Sin).apply(null,arguments)},Gy=t._Softmax=function(){return(Gy=t._Softmax=t.asm.Softmax).apply(null,arguments)},Hy=t._SparseFillEmptyRows=function(){return(Hy=t._SparseFillEmptyRows=t.asm.SparseFillEmptyRows).apply(null,arguments)},Ky=t._SparseReshape=function(){return(Ky=t._SparseReshape=t.asm.SparseReshape).apply(null,arguments)},qy=t._SparseSegmentReduction=function(){return(qy=t._SparseSegmentReduction=t.asm.SparseSegmentReduction).apply(null,arguments)},jy=t._Sqrt=function(){return(jy=t._Sqrt=t.asm.Sqrt).apply(null,arguments)},Xy=t._Square=function(){return(Xy=t._Square=t.asm.Square).apply(null,arguments)},Yy=t._SquaredDifference=function(){return(Yy=t._SquaredDifference=t.asm.SquaredDifference).apply(null,arguments)},Qy=t._Step=function(){return(Qy=t._Step=t.asm.Step).apply(null,arguments)},Zy=t._StridedSlice=function(){return(Zy=t._StridedSlice=t.asm.StridedSlice).apply(null,arguments)},Jy=t._Sub=function(){return(Jy=t._Sub=t.asm.Sub).apply(null,arguments)},eb=t._Sum=function(){return(eb=t._Sum=t.asm.Sum).apply(null,arguments)},tb=t._Tan=function(){return(tb=t._Tan=t.asm.Tan).apply(null,arguments)},rb=t._Tanh=function(){return(rb=t._Tanh=t.asm.Tanh).apply(null,arguments)},ob=t._Tile=function(){return(ob=t._Tile=t.asm.Tile).apply(null,arguments)},nb=t._TopK=function(){return(nb=t._TopK=t.asm.TopK).apply(null,arguments)},sb=t._Transform=function(){return(sb=t._Transform=t.asm.Transform).apply(null,arguments)},ab=t._Transpose=function(){return(ab=t._Transpose=t.asm.Transpose).apply(null,arguments)},ib=t.__FusedMatMul=function(){return(ib=t.__FusedMatMul=t.asm._FusedMatMul).apply(null,arguments)},ub=t._malloc=function(){return(ub=t._malloc=t.asm.malloc).apply(null,arguments)},pb=t._free=function(){return(pb=t._free=t.asm.free).apply(null,arguments)},cb=t.___errno_location=function(){return(cb=t.___errno_location=t.asm.__errno_location).apply(null,arguments)},mm=t.stackSave=function(){return(mm=t.stackSave=t.asm.stackSave).apply(null,arguments)},dm=t.stackRestore=function(){return(dm=t.stackRestore=t.asm.stackRestore).apply(null,arguments)},Vc=t.stackAlloc=function(){return(Vc=t.stackAlloc=t.asm.stackAlloc).apply(null,arguments)},lb=t.dynCall_iijjiiii=function(){return(lb=t.dynCall_iijjiiii=t.asm.dynCall_iijjiiii).apply(null,arguments)},mb=t.dynCall_jiji=function(){return(mb=t.dynCall_jiji=t.asm.dynCall_jiji).apply(null,arguments)};t.cwrap=Mx;var rp;rr=function G(){rp||fm(),rp||(rr=G)};function fm(G){if(G=G||i,Nt>0||(ft(),Nt>0))return;function se(){rp||(rp=!0,t.calledRun=!0,!M&&(ht(),o(t),t.onRuntimeInitialized&&t.onRuntimeInitialized(),Rr()))}t.setStatus?(t.setStatus(\"Running...\"),setTimeout(function(){setTimeout(function(){t.setStatus(\"\")},1),se()},1)):se()}if(t.preInit)for(typeof t.preInit==\"function\"&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();fm();var op;s&&(op={uncaughtException:process.listeners(\"uncaughtException\").filter(function(G){return!s.uncaughtException.indexOf(G)>-1}),unhandledRejection:process.listeners(\"unhandledRejection\").filter(function(G){return!s.unhandledRejection.indexOf(G)>-1})});var np;if(typeof e!=\"undefined\")np=e;else if(typeof WasmBackendModuleThreadedSimd!=\"undefined\")np=WasmBackendModuleThreadedSimd;else throw new Error(\"Could not find wasm module in post.js\");if(op){var db=np._dispose;np._dispose=function(){db(),op.uncaughtException.forEach(function(G){process.removeListener(\"uncaughtException\",G)}),op.unhandledRejection.forEach(function(G){process.removeListener(\"unhandledRejection\",G)})}}return e.ready}})();typeof Ig==\"object\"&&typeof uI==\"object\"?uI.exports=iI:typeof define==\"function\"&&define.amd?define([],function(){return iI}):typeof Ig==\"object\"&&(Ig.WasmBackendModule=iI)});var Fo=class{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}},Zr=class{refCount(e){return Fr(\"refCount\")}incRef(e){return Fr(\"incRef\")}timerAvailable(){return!0}time(e){return Fr(\"time\")}read(e){return Fr(\"read\")}readSync(e){return Fr(\"readSync\")}readToGPU(e,t){return Fr(\"readToGPU\")}numDataIds(){return Fr(\"numDataIds\")}disposeData(e,t){return Fr(\"disposeData\")}write(e,t,o){return Fr(\"write\")}move(e,t,o,n,s){return Fr(\"move\")}createTensorFromGPUData(e,t,o){return Fr(\"createTensorFromGPUData\")}memory(){return Fr(\"memory\")}floatPrecision(){return Fr(\"floatPrecision\")}epsilon(){return this.floatPrecision()===32?1e-7:1e-4}dispose(){return Fr(\"dispose\")}};function Fr(r){throw new Error(`'${r}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}function UI(r){let e=r.length,t=0;for(;e>0;)t=Math.random()*e|0,e--,Im(r,e,t)}function WV(r,e){if(r.length!==e.length)throw new Error(`Array sizes must match to be shuffled together First array length was ${r.length}Second array length was ${e.length}`);let t=r.length,o=0;for(;t>0;)o=Math.random()*t|0,t--,Im(r,t,o),Im(e,t,o)}function ip(r,e,t){return Math.max(r,Math.min(e,t))}function UV(r){return r%2===0?r:r+1}function Im(r,e,t){let o=r[e];r[e]=r[t],r[t]=o}function GV(r){let e=0;for(let t=0;tt+` Shapes ${r} and ${e} must match`)}function Jr(r){$(r!=null,()=>\"The input to the tensor constructor must be a non-null value.\")}function We(r){if(r.length===0)return 1;let e=r[0];for(let t=1;t0,t,o){return new Promise((n,s)=>{let a=0,i=()=>{if(r()){n();return}a++;let p=e(a);if(t!=null&&a>=t){s();return}o!=null?o(i,p):setTimeout(i,p)};i()})}function ZV(r,e){let t=1,o=-1;for(let s=0;s=0)t*=r[s];else if(r[s]===-1){if(o!==-1)throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${o} and dim ${s}`);o=s}else if(r[s]<0)throw Error(`Shapes can not be < 0. Found ${r[s]} at dim ${s}`);if(o===-1){if(e>0&&e!==t)throw Error(`Size(${e}) must match the product of shape ${r}`);return r}if(t===0)throw Error(`Cannot infer the missing size in [${r}] when there are 0 elements`);if(e%t!==0)throw Error(`The implicit shape can't be a fractional number. Got ${e} / ${t}`);let n=r.slice();return n[o]=e/t,n}function Ja(r,e){let t=e.length;return r=r==null?e.map((o,n)=>n):[].concat(r),$(r.every(o=>o>=-t&&o`All values in axis param must be in range [-${t}, ${t}) but got axis ${r}`),$(r.every(o=>sa(o)),()=>`All values in axis param must be integers but got axis ${r}`),r.map(o=>o<0?t+o:o)}function bb(r,e){let t=[],o=[],n=e!=null&&Array.isArray(e)&&e.length===0,s=e==null||n?null:Ja(e,r).sort(),a=0;for(let i=0;ii)&&r[i]===1&&(t.push(r[i]),o.push(i)),s[a]<=i&&a++}r[i]!==1&&(t.push(r[i]),o.push(i))}return{newShape:t,keptDims:o}}function Cb(r,e){let t=null;if(r==null||r===\"float32\")t=new Float32Array(e);else if(r===\"int32\")t=new Int32Array(e);else if(r===\"bool\")t=new Uint8Array(e);else throw new Error(`Unknown data type ${r}`);return t}function Sb(r,e){let t=null;if(r==null||r===\"float32\")t=new Float32Array(e);else if(r===\"int32\")t=new Int32Array(e);else if(r===\"bool\")t=new Uint8Array(e);else if(r===\"string\")t=new Array(e);else throw new Error(`Unknown data type ${r}`);return t}function wb(r,e){for(let t=0;te+=t.length),e}function Oo(r){return typeof r==\"string\"||r instanceof String}function GI(r){return typeof r==\"boolean\"}function HI(r){return typeof r==\"number\"}function pp(r){return Array.isArray(r)?pp(r[0]):r instanceof Float32Array?\"float32\":r instanceof Int32Array||r instanceof Uint8Array||r instanceof Uint8ClampedArray?\"int32\":HI(r)?\"float32\":Oo(r)?\"string\":GI(r)?\"bool\":\"float32\"}function gs(r){return!!(r&&r.constructor&&r.call&&r.apply)}function cp(r,e){for(let t=e;t=0;--o)t[o]=t[o+1]*r[o+1];return t}function KI(r,e,t,o=!1){let n=new Array;if(e.length===1){let s=e[0]*(o?2:1);for(let a=0;ap*u)*(o?2:1);for(let p=0;pn*s)*(t?2:1);if(o===0)return[];if(o!==e.length)throw new Error(`[${r}] does not match the input size ${e.length}${t?\" for a complex tensor\":\"\"}.`);return KI(0,r,e,t)}function ez(r,e){if(Array.isArray(r))return r;if(e===\"float32\")return r instanceof Float32Array?r:new Float32Array(r);if(e===\"int32\")return r instanceof Int32Array?r:new Int32Array(r);if(e===\"bool\"||e===\"string\")return Uint8Array.from(new Int32Array(r));throw new Error(`Unknown dtype ${e}`)}function Wc(r,e){let t=lp(r,e);for(let o=0;oo*n,1);if(e==null||e===\"float32\")return Xi(r,new Float32Array(t));if(e===\"int32\")return Xi(r,new Int32Array(t));if(e===\"bool\")return Xi(r,new Uint8Array(t));throw new Error(`Unknown data type ${e}`)}function bt(r){r.forEach(e=>{$(Number.isInteger(e)&&e>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${r}].`)})}function rz(r,e,t){if(e===0)return 0;if(e===1)return r[0];let o=r[r.length-1];for(let n=0;n{let[n,s]=o.split(\":\");this.urlFlags[n]=iz(n,s)})}};function sz(r){let e={};return r.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(t,...o)=>(az(e,o[0],o[1]),o.join(\"=\"))),e}function az(r,e,t){r[decodeURIComponent(e)]=decodeURIComponent(t||\"\")}function iz(r,e){if(e=e.toLowerCase(),e===\"true\"||e===\"false\")return e===\"true\";if(`${+e}`===e)return+e;throw new Error(`Could not parse value flag value ${e} for flag ${r}.`)}function O(){return kb}var kb=null;function jI(r){kb=r}var Nb;function Tb(){if(Nb==null){let r;if(typeof window!=\"undefined\")r=window;else if(typeof global!=\"undefined\")r=global;else if(typeof process!=\"undefined\")r=process;else if(typeof self!=\"undefined\")r=self;else throw new Error(\"Could not find a global object\");Nb=r}return Nb}function uz(){let r=Tb();return r._tfGlobals==null&&(r._tfGlobals=new Map),r._tfGlobals}function Gc(r,e){let t=uz();if(t.has(r))return t.get(r);{let o=e();return t.set(r,o),t.get(r)}}var ys=\"Abs\",aa=\"Acos\",ia=\"Acosh\",eo=\"Add\",Po=\"AddN\",Mo=\"All\",Lo=\"Any\",Bo=\"ArgMax\",ei=\"ArgMin\",ua=\"Asin\",pa=\"Asinh\",ca=\"Atan\",la=\"Atanh\",ma=\"Atan2\",Vo=\"AvgPool\",mp=\"AvgPoolGrad\",dp=\"AvgPool3D\",vm=\"AvgPool3DGrad\",zo=\"BatchMatMul\",bs=\"BatchToSpaceND\",ti=\"Bincount\",ise=\"BroadcastTo\",fp=\"BroadcastArgs\",co=\"Cast\",Wo=\"Ceil\",lo=\"ClipByValue\",ri=\"Complex\",hp=\"ComplexAbs\",Cs=\"Concat\",Uo=\"Conv2D\",oi=\"Conv2DBackpropFilter\",Go=\"Conv2DBackpropInput\",gp=\"Conv3D\",km=\"Conv3DBackpropFilterV2\",xp=\"Conv3DBackpropInputV2\",Ho=\"Cos\",Ko=\"Cosh\",qo=\"Cumprod\",jo=\"Cumsum\",Xo=\"CropAndResize\",ni=\"DenseBincount\",Yo=\"DepthToSpace\",Qo=\"DepthwiseConv2dNative\",yp=\"DepthwiseConv2dNativeBackpropFilter\",bp=\"DepthwiseConv2dNativeBackpropInput\",si=\"Diag\",ai=\"Dilation2D\",_b=\"Dilation2DBackpropInput\",$b=\"Dilation2DBackpropFilter\",Zo=\"RealDiv\",ii=\"Einsum\",Jo=\"Elu\",Nm=\"EluGrad\",da=\"Erf\",en=\"Equal\",tn=\"Exp\",Ss=\"ExpandDims\",fa=\"Expm1\",ui=\"FFT\",ws=\"Fill\",rn=\"FlipLeftRight\",on=\"Floor\",nn=\"FloorDiv\",sn=\"FusedBatchNorm\",Is=\"GatherV2\",an=\"GatherNd\",un=\"Greater\",pn=\"GreaterEqual\",mo=\"Identity\",pi=\"IFFT\",ci=\"Imag\",ha=\"IsFinite\",ga=\"IsInf\",cn=\"IsNan\",ln=\"LeakyRelu\",mn=\"Less\",dn=\"LessEqual\",li=\"LinSpace\",fn=\"Log\",xa=\"Log1p\",hn=\"LogicalAnd\",gn=\"LogicalNot\",xn=\"LogicalOr\",XI=\"LogicalXor\",use=\"LogSoftmax\",pse=\"LowerBound\",mi=\"LRN\",Tm=\"LRNGrad\",yn=\"Max\",bn=\"Maximum\",Cn=\"MaxPool\",_m=\"MaxPoolGrad\",Cp=\"MaxPool3D\",$m=\"MaxPool3DGrad\",Sp=\"MaxPoolWithArgmax\",Sn=\"Mean\",wn=\"Min\",In=\"Minimum\",vn=\"MirrorPad\",ya=\"Mod\",wp=\"Multinomial\",kn=\"Multiply\",vs=\"Neg\",Nn=\"NotEqual\",Tn=\"NonMaxSuppressionV3\",ba=\"NonMaxSuppressionV4\",_n=\"NonMaxSuppressionV5\",ks=\"OnesLike\",$n=\"OneHot\",Ns=\"Pack\",En=\"PadV2\",cse=\"Pool\",An=\"Pow\",Rn=\"Prelu\",Dn=\"Prod\",Ip=\"RaggedGather\",vp=\"RaggedRange\",kp=\"RaggedTensorToTensor\",Ts=\"Range\",di=\"Real\",Fn=\"Reciprocal\",On=\"Relu\",_s=\"Reshape\",Pn=\"ResizeNearestNeighbor\",Em=\"ResizeNearestNeighborGrad\",Mn=\"ResizeBilinear\",Am=\"ResizeBilinearGrad\",Ln=\"Relu6\",Bn=\"Reverse\",Vn=\"Round\",zn=\"Rsqrt\",Wn=\"ScatterNd\",fi=\"SearchSorted\",$s=\"Select\",Ca=\"Selu\",Es=\"Slice\",Un=\"Sin\",Sa=\"Sinh\",wa=\"Sign\",Gn=\"Sigmoid\",Ia=\"Softplus\",Hn=\"Sqrt\",Kn=\"Sum\",As=\"SpaceToBatchND\",Rs=\"SplitV\",qn=\"Softmax\",hi=\"SparseFillEmptyRows\",va=\"SparseReshape\",gi=\"SparseSegmentMean\",xi=\"SparseSegmentSum\",yi=\"SparseToDense\",jn=\"SquaredDifference\",bi=\"Square\",Xn=\"StridedSlice\",Ds=\"StringNGrams\",Ci=\"StringSplit\",Si=\"StringToHashBucketFast\",Yn=\"Sub\",Qn=\"Tan\",Zn=\"Tanh\",to=\"Tile\",Jn=\"TopK\",es=\"Transform\",ro=\"Transpose\",Np=\"Unique\",Fs=\"Unpack\",Tp=\"UnsortedSegmentSum\",lse=\"UpperBound\",Os=\"ZerosLike\",fo=\"Step\",Zi=\"FromPixels\",ts=\"RotateWithOffset\",ho=\"_FusedMatMul\",go=\"FusedConv2D\",xo=\"FusedDepthwiseConv2D\";function Ps(...r){O().getBool(\"IS_TEST\")||O().getBool(\"PROD\")||console.warn(...r)}function pz(...r){O().getBool(\"IS_TEST\")||O().getBool(\"PROD\")||console.log(...r)}var _p=Gc(\"kernelRegistry\",()=>new Map),Hc=Gc(\"gradRegistry\",()=>new Map);function Kc(r,e){let t=Ab(r,e);return _p.get(t)}function Eb(r){return Hc.get(r)}function Rm(r){let e=_p.entries(),t=[];for(;;){let{done:o,value:n}=e.next();if(o)break;let[s,a]=n,[i]=s.split(\"_\");i===r&&t.push(a)}return t}function ka(r){let{kernelName:e,backendName:t}=r,o=Ab(e,t);_p.has(o)&&Ps(`The kernel '${e}' for backend '${t}' is already registered`),_p.set(o,r)}function gse(r){let{kernelName:e}=r;Hc.has(e)&&O().getBool(\"DEBUG\")&&Ps(`Overriding the gradient for '${e}'`),Hc.set(e,r)}function xse(r,e){let t=Ab(r,e);if(!_p.has(t))throw new Error(`The kernel '${r}' for backend '${e}' is not registered`);_p.delete(t)}function yse(r){if(!Hc.has(r))throw new Error(`The gradient '${r}' for backend is not registered`);Hc.delete(r)}function bse(r,e){Rm(r).forEach(o=>{let n=Object.assign({},o,{backendName:e});ka(n)})}function Ab(r,e){return`${e}_${r}`}var y={};Ge(y,{arraysEqual:()=>Or,assert:()=>$,assertNonNegativeIntegerDimensions:()=>bt,assertNonNull:()=>Jr,assertShapesMatch:()=>gt,bytesFromStringArray:()=>vb,bytesPerElement:()=>up,checkConversionForErrors:()=>wb,clamp:()=>ip,computeStrides:()=>xs,convertBackendValuesAndArrayBuffer:()=>ez,createScalarValue:()=>gz,createShuffledIndices:()=>YV,decodeString:()=>Rp,distSquared:()=>KV,encodeString:()=>Ii,fetch:()=>yz,fingerPrint64:()=>hz,flatten:()=>os,getArrayFromDType:()=>Sb,getTypedArrayFromDType:()=>Cb,hasEncodingLoss:()=>JV,hexToLong:()=>qc,indexToLoc:()=>oz,inferDtype:()=>pp,inferFromImplicitShape:()=>ZV,isBoolean:()=>GI,isFunction:()=>gs,isInt:()=>sa,isNumber:()=>HI,isPromise:()=>Qi,isScalarShape:()=>qV,isString:()=>Oo,isTypedArray:()=>Bt,isValidDtype:()=>Ib,locToIndex:()=>rz,makeOnesTypedArray:()=>Wc,makeZerosNestedTypedArray:()=>tz,makeZerosTypedArray:()=>lp,nearestDivisor:()=>cp,nearestLargerEven:()=>UV,now:()=>ou,parseAxisParam:()=>Ja,randUniform:()=>HV,repeatedTry:()=>QV,rightPad:()=>Yi,shuffle:()=>UI,shuffleCombo:()=>WV,sizeFromShape:()=>We,sizeToSquarishShape:()=>XV,squeezeShape:()=>bb,sum:()=>GV,swap:()=>Im,tanh:()=>jV,toNestedArray:()=>Xi,toTypedArray:()=>Ap});var Ob=ap(i0());var ru=Ob.default||Ob;function qc(r){return ru.fromString(r,!0,16)}var p0=qc(\"c3a5c85c97cb3127\"),tu=qc(\"b492b66fbe98f273\"),gr=qc(\"9ae16a3b2f90404f\");function Fb(r){return r.xor(r.shru(47))}function c0(r,e,t){let o=r.slice(e,e+t);return ru.fromBytes(Array.from(o),!0,!0)}function Ct(r,e){return c0(r,e,8)}function u0(r,e){return c0(r,e,4)}function jt(r,e){return e===0?r:r.shru(e).or(r.shl(64-e))}function wi(r,e,t=qc(\"9ddfea08eb382d69\")){let o=r.xor(e).mul(t);o=o.xor(o.shru(47));let n=e.xor(o).mul(t);return n=n.xor(n.shru(47)),n=n.mul(t),n}function lz(r,e,t,o,n,s){n=n.add(r),s=jt(s.add(n).add(o),21);let a=n;return n=n.add(e),n=n.add(t),s=s.add(jt(n,44)),[n.add(o),s.add(a)]}function Fm(r,e,t,o){return lz(Ct(r,e),Ct(r,e+8),Ct(r,e+16),Ct(r,e+24),t,o)}function mz(r,e=r.length){if(e>=8){let t=gr.add(e*2),o=Ct(r,0).add(gr),n=Ct(r,e-8),s=jt(n,37).mul(t).add(o),a=jt(o,25).add(n).mul(t);return wi(s,a,t)}if(e>=4){let t=gr.add(e*2),o=u0(r,0);return wi(o.shl(3).add(e),u0(r,e-4),t)}if(e>0){let t=r[0],o=r[e>>1],n=r[e-1],s=t+(o<<8),a=e+(n<<2);return Fb(gr.mul(s).xor(p0.mul(a))).mul(gr)}return gr}function dz(r,e=r.length){let t=gr.add(e*2),o=Ct(r,0).mul(tu),n=Ct(r,8),s=Ct(r,e-8).mul(t),a=Ct(r,e-16).mul(gr);return wi(jt(o.add(n),43).add(jt(s,30)).add(a),o.add(jt(n.add(gr),18)).add(s),t)}function fz(r,e=r.length){let t=gr.add(e*2),o=Ct(r,0).mul(gr),n=Ct(r,8),s=Ct(r,e-8).mul(t),a=Ct(r,e-16).mul(gr),i=jt(o.add(n),43).add(jt(s,30)).add(a),p=wi(i,o.add(jt(n.add(gr),18)).add(s),t),u=Ct(r,16).mul(t),c=Ct(r,24),l=i.add(Ct(r,e-32)).mul(t),m=p.add(Ct(r,e-24)).mul(t);return wi(jt(u.add(c),43).add(jt(l,30)).add(m),u.add(jt(c.add(o),18)).add(l),t)}function hz(r,e=r.length){let t=ru.fromNumber(81,!0);if(e<=32)return e<=16?mz(r,e):dz(r,e);if(e<=64)return fz(r,e);let o=t,n=t.mul(tu).add(113),s=Fb(n.mul(gr).add(113)).mul(gr),a=[ru.UZERO,ru.UZERO],i=[ru.UZERO,ru.UZERO];o=o.mul(gr).add(Ct(r,0));let p=0,u=(e-1>>6)*64,c=u+(e-1&63)-63;do o=jt(o.add(n).add(a[0]).add(Ct(r,p+8)),37).mul(tu),n=jt(n.add(a[1]).add(Ct(r,p+48)),42).mul(tu),o=o.xor(i[1]),n=n.add(a[0]).add(Ct(r,p+40)),s=jt(s.add(i[0]),33).mul(tu),a=Fm(r,p,a[1].mul(tu),o.add(i[0])),i=Fm(r,p+32,s.add(i[1]),n.add(Ct(r,p+16))),[s,o]=[o,s],p+=64;while(p!==u);let l=tu.add(s.and(255).shl(1));return p=c,i[0]=i[0].add(e-1&63),a[0]=a[0].add(i[0]),i[0]=i[0].add(a[0]),o=jt(o.add(n).add(a[0]).add(Ct(r,p+8)),37).mul(l),n=jt(n.add(a[1]).add(Ct(r,p+48)),42).mul(l),o=o.xor(i[1].mul(9)),n=n.add(a[0].mul(9).add(Ct(r,p+40))),s=jt(s.add(i[0]),33).mul(l),a=Fm(r,p,a[1].mul(l),o.add(i[0])),i=Fm(r,p+32,s.add(i[1]),n.add(Ct(r,p+16))),[s,o]=[o,s],wi(wi(a[0],i[0],l).add(Fb(n).mul(p0)).add(s),wi(a[1],i[1],l).add(o),l)}function gz(r,e){return e===\"string\"?Ii(r):Ap([r],e)}function xz(r,e){return r instanceof Float32Array&&e===\"float32\"||r instanceof Int32Array&&e===\"int32\"||r instanceof Uint8Array&&e===\"bool\"}function Ap(r,e){if(e===\"string\")throw new Error(\"Cannot convert a string[] to a TypedArray\");if(Array.isArray(r)&&(r=os(r)),O().getBool(\"DEBUG\")&&wb(r,e),xz(r,e))return r;if(e==null||e===\"float32\"||e===\"complex64\")return new Float32Array(r);if(e===\"int32\")return new Int32Array(r);if(e===\"bool\"){let t=new Uint8Array(r.length);for(let o=0;o{n=o()},a,i=ou();if(this.backendTimer.timerAvailable())a=this.backendTimer.time(s);else{s();for(let u of n)u.dataSync();a=Promise.resolve({kernelMs:ou()-i})}if(O().getBool(\"CHECK_COMPUTATION_FOR_ERRORS\"))for(let u=0;u{bz(l,c.dtype,e)})}return{kernelName:e,outputs:n,inputs:t,timeMs:a.then(u=>u.kernelMs),extraInfo:a.then(u=>u.getExtraProfileInfo!=null?u.getExtraProfileInfo():\"\")}}logKernelProfile(e){let{kernelName:t,outputs:o,timeMs:n,inputs:s,extraInfo:a}=e;o.forEach(i=>{Promise.all([i.data(),n,a]).then(p=>{this.logger.logKernelProfile(t,i,p[0],p[1],s,p[2])})})}};function bz(r,e,t){if(e!==\"float32\")return!1;for(let o=0;o0?h:\"\"} `}}console.log(`%c${p}\t%c${i}\t%c${u}D ${l}\t%c${c}\t%c${m}\t%c${a}`,\"font-weight:bold\",\"color:red\",\"color:blue\",\"color: orange\",\"color: green\",\"color: steelblue\")}};function l0(r,e,t){let o={},n={};for(let p=0;po[h.id]=!0),d=!0,n[u.id]=!0;break}if(d)break}}let s={};s[t.id]=!0;let a={};for(let p=r.length-1;p>=0;p--){let u=r[p],c=u.inputs;for(let l=0;l=0;n--){let s=e[n],a=[];if(s.outputs.forEach(p=>{let u=r[p.id];u!=null?a.push(u):a.push(null)}),s.gradient==null)throw new Error(`Cannot compute gradient: gradient function not found for ${s.kernelName}.`);let i=s.gradient(a);for(let p in s.inputs){if(!(p in i))throw new Error(`Cannot backprop through input ${p}. Available gradients found: ${Object.keys(i)}.`);let u=t(()=>i[p]());if(u.dtype!==\"float32\")throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input ${p} must have 'float32' dtype, but has '${u.dtype}'`);let c=s.inputs[p];if(!Or(u.shape,c.shape))throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input '${p}' has shape '${u.shape}', which does not match the shape of the input '${c.shape}'`);if(r[c.id]==null)r[c.id]=u;else{let l=r[c.id];r[c.id]=o(l,u),l.dispose()}}}}var d0=20,jc=3,Mb=7;function f0(r,e,t,o){let n=xs(e),s=Cz(r,e,t,n),a=e.length,i=Pm(r,e,t,n,s),p=[\"Tensor\"];return o&&(p.push(` dtype: ${t}`),p.push(` rank: ${a}`),p.push(` shape: [${e}]`),p.push(\" values:\")),p.push(i.map(u=>\" \"+u).join(`\n`)),p.join(`\n`)}function Cz(r,e,t,o){let n=We(e),s=o[o.length-1],a=new Array(s).fill(0),i=e.length,p=t===\"complex64\"?Yc(r):r;if(i>1)for(let u=0;ud0){let g=jc*a,x=Array.from(r.slice(0,g)),b=Array.from(r.slice((i-jc)*a,i*a));return t===\"complex64\"&&(x=Yc(x),b=Yc(b)),[\"[\"+x.map((C,w)=>Xc(C,n[w],t)).join(\", \")+\", ..., \"+b.map((C,w)=>Xc(C,n[i-jc+w],t)).join(\", \")+\"]\"]}return[\"[\"+(t===\"complex64\"?Yc(r):Array.from(r)).map((g,x)=>Xc(g,n[x],t)).join(\", \")+\"]\"]}let u=e.slice(1),c=o.slice(1),l=o[0]*a,m=[];if(i>d0){for(let h=0;h0?m[0]+d:\"\");for(let h=1;h`Length of values '${n}' does not match the size inferred by the shape '${this.size}'.`)}if(t===\"complex64\")throw new Error(\"complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).\");this.values=o||Sb(t,this.size),this.strides=xs(e)}set(e,...t){t.length===0&&(t=[0]),$(t.length===this.rank,()=>`The number of provided coordinates (${t.length}) must match the rank (${this.rank})`);let o=this.locToIndex(t);this.values[o]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(let n of e){if(n<0||n>=this.shape[t]){let s=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(s)}t++}let o=e[e.length-1];for(let n=0;nRp(o))}catch(o){throw new Error(\"Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().\")}}return e}dataToGPU(e){return this.throwIfDisposed(),ns().readToGPU(this.dataId,e)}dataSync(){this.throwIfDisposed();let e=ns().readSync(this.dataId);if(this.dtype===\"string\")try{return e.map(t=>Rp(t))}catch(t){throw new Error(\"Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().\")}return e}async bytes(){this.throwIfDisposed();let e=await ns().read(this.dataId);return this.dtype===\"string\"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(ns().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error(\"Tensor is disposed.\")}print(e=!1){return Dp.print(this,e)}clone(){return this.throwIfDisposed(),Dp.clone(this)}toString(e=!1){let t=this.dataSync();return f0(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Dp.cast(this,e)}variable(e=!0,t,o){return this.throwIfDisposed(),ns().makeVariable(this,e,t,o)}};Object.defineProperty(it,Symbol.hasInstance,{value:r=>!!r&&r.data!=null&&r.dataSync!=null&&r.throwIfDisposed!=null});function wz(){return Gc(\"Tensor\",()=>it)}wz();var Na=class extends it{constructor(e,t,o,n){super(e.shape,e.dtype,e.dataId,n),this.trainable=t,this.name=o}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);if(!Or(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);ns().disposeTensor(this),this.dataId=e.dataId,ns().incRef(this,null)}dispose(){ns().disposeVariable(this),this.isDisposedInternal=!0}};Object.defineProperty(Na,Symbol.hasInstance,{value:r=>r instanceof it&&r.assign!=null&&r.assign instanceof Function});var C0={};Ge(C0,{assertTypesMatch:()=>Ub,getTensorsInContainer:()=>Qc,isTensorInList:()=>vz,makeTypesMatch:()=>De});var Lb;(function(r){r.R0=\"R0\",r.R1=\"R1\",r.R2=\"R2\",r.R3=\"R3\",r.R4=\"R4\",r.R5=\"R5\",r.R6=\"R6\"})(Lb||(Lb={}));var Bb;(function(r){r.float32=\"float32\",r.int32=\"int32\",r.bool=\"int32\",r.complex64=\"complex64\"})(Bb||(Bb={}));var Vb;(function(r){r.float32=\"float32\",r.int32=\"int32\",r.bool=\"bool\",r.complex64=\"complex64\"})(Vb||(Vb={}));var zb;(function(r){r.float32=\"float32\",r.int32=\"float32\",r.bool=\"float32\",r.complex64=\"complex64\"})(zb||(zb={}));var Wb;(function(r){r.float32=\"complex64\",r.int32=\"complex64\",r.bool=\"complex64\",r.complex64=\"complex64\"})(Wb||(Wb={}));var Iz={float32:zb,int32:Bb,bool:Vb,complex64:Wb};function dt(r,e){if(r===\"string\"||e===\"string\"){if(r===\"string\"&&e===\"string\")return\"string\";throw new Error(`Can not upcast ${r} with ${e}`)}return Iz[r][e]}function Ta(r){return dt(r,\"int32\")}function De(r,e){if(r.dtype===e.dtype)return[r,e];let t=dt(r.dtype,e.dtype);return[r.cast(t),e.cast(t)]}function Ub(r,e){$(r.dtype===e.dtype,()=>`The dtypes of the first(${r.dtype}) and second(${e.dtype}) input must match`)}function vz(r,e){return e.some(t=>t.id===r.id)}function Qc(r){let e=[];return b0(r,e,new Set),e}function b0(r,e,t){if(r==null)return;if(r instanceof it){e.push(r);return}if(!kz(r))return;let o=r;for(let n in o){let s=o[n];t.has(s)||(t.add(s),b0(s,e,t))}}function kz(r){return Array.isArray(r)||typeof r==\"object\"}function Gb(r){return r.kernelName!=null}var Mm=class{constructor(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null,get kernelNames(){return Array.from(new Set(this.kernels.map(e=>e.name)))}}}dispose(){for(let e in this.registeredVariables)this.registeredVariables[e].dispose()}},vi=class{constructor(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new Mm}async ready(){if(this.pendingBackendInit!=null)return this.pendingBackendInit.then(()=>{});if(this.backendInstance!=null)return;let e=this.getSortedBackends();for(let t=0;t{t.setupFunc!=null&&t.setupFunc(this.backendInstance)})}disposeRegisteredKernels(e){Rm(e).forEach(o=>{o.disposeFunc!=null&&o.disposeFunc(this.registry[e])})}initializeBackend(e){let t=this.registryFactory[e];if(t==null)throw new Error(`Cannot initialize backend ${e}, no registration found.`);try{let o=t.factory();if(o&&!(o instanceof Zr)&&typeof o.then==\"function\"){let n=++this.pendingBackendInitId,s=o.then(a=>n(nthis.registryFactory[t].priority-this.registryFactory[e].priority)}initializeBackendsAndReturnBest(){let e=this.getSortedBackends();for(let t=0;tthis.startScope(o),()=>this.endScope(n),()=>(n=t(),n instanceof Promise&&console.error(\"Cannot return a Promise inside of tidy.\"),n))}scopedRun(e,t,o){e();try{let n=o();return t(),n}catch(n){throw t(),n}}nextTensorId(){return vi.nextTensorId++}nextVariableId(){return vi.nextVariableId++}clone(e){let t=T.runKernel(mo,{x:e}),o={x:e},n=a=>({x:()=>{let i=\"float32\",p={x:a},u={dtype:i};return T.runKernel(co,p,u)}}),s=[];return this.addTapeNode(this.state.activeScope.name,o,[t],n,s,{}),t}runKernel(e,t,o){if(this.backendName==null&&this.backend,!(Kc(e,this.backendName)!=null))throw new Error(`Kernel '${e}' not registered for backend '${this.backendName}'`);return this.runKernelFunc({kernelName:e,inputs:t,attrs:o})}shouldCheckForMemLeaks(){return this.ENV.getBool(\"IS_TEST\")}checkKernelForMemLeak(e,t,o){let n=this.backend.numDataIds(),s=0;o.forEach(p=>{s+=p.dtype===\"complex64\"?3:1});let a=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],i=n-t-s-a;if(i>0)throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${e}'`)}runKernelFunc(e){let t,o=[],n=this.isTapeOn(),s=this.state.numBytes,a=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);let i;this.backendName==null&&this.backend;let p,u=Gb(e)?e.kernelName:this.state.activeScope!=null?this.state.activeScope.name:\"\";if(Gb(e)){let{kernelName:f,inputs:h,attrs:g}=e;this.backendName==null&&this.backend;let x=Kc(f,this.backendName);$(x!=null,()=>`Cannot find registered kernel '${f}' for backend '${this.backendName}'`),i=()=>{let b=this.backend.numDataIds();p=x.kernelFunc({inputs:h,attrs:g,backend:this.backend});let C=Array.isArray(p)?p:[p];this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(f,b,C);let w=C.map(k=>k.rank!=null?k:this.makeTensorFromTensorInfo(k));if(n){let k=this.getTensorsForGradient(f,h,w);o=this.saveTensorsForBackwardMode(k)}return w}}else{let{forwardFunc:f}=e,h=g=>{n&&(o=g.map(x=>this.keep(this.clone(x))))};i=()=>{let g=this.backend.numDataIds();p=this.tidy(()=>f(this.backend,h));let x=Array.isArray(p)?p:[p];return this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(u,g,x),x}}let{inputs:c,attrs:l}=e,m=Gb(e)?null:e.backwardsFunc,d;return this.scopedRun(()=>this.state.kernelDepth++,()=>this.state.kernelDepth--,()=>{!this.ENV.getBool(\"DEBUG\")&&!this.state.profiling?t=i():(d=this.profiler.profileKernel(u,c,()=>i()),this.ENV.getBool(\"DEBUG\")&&this.profiler.logKernelProfile(d),t=d.outputs)}),n&&this.addTapeNode(u,c,t,m,o,l),this.state.profiling&&this.state.activeProfile.kernels.push({name:u,bytesAdded:this.state.numBytes-s,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-a,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(c).map(f=>c[f]!=null?c[f].shape:null),outputShapes:t.map(f=>f.shape),kernelTimeMs:d.timeMs,extraInfo:d.extraInfo}),Array.isArray(p)?t:t[0]}saveTensorsForBackwardMode(e){return e.map(o=>this.keep(this.clone(o)))}getTensorsForGradient(e,t,o){let n=Eb(e);if(n!=null){let s=n.inputsToSave||[],a=n.outputsToSave||[],i;n.saveAllInputs?($(Array.isArray(t),()=>\"saveAllInputs is true, expected inputs to be an array.\"),i=Object.keys(t).map(u=>t[u])):i=s.map(u=>t[u]);let p=o.filter((u,c)=>a[c]);return i.concat(p)}return[]}makeTensor(e,t,o,n){if(e==null)throw new Error(\"Values passed to engine.makeTensor() are null\");o=o||\"float32\",n=n||this.backend;let s=e;o===\"string\"&&Oo(e[0])&&(s=e.map(p=>Ii(p)));let a=n.write(s,t,o),i=new it(t,o,a,this.nextTensorId());if(this.trackTensor(i,n),o===\"string\"){let p=this.state.tensorInfo.get(a),u=vb(s);this.state.numBytes+=u-p.bytes,p.bytes=u}return i}makeTensorFromDataId(e,t,o,n){o=o||\"float32\";let s={dataId:e,shape:t,dtype:o};return this.makeTensorFromTensorInfo(s,n)}makeTensorFromTensorInfo(e,t){let{dataId:o,shape:n,dtype:s}=e,a=new it(n,s,o,this.nextTensorId());return this.trackTensor(a,t),a}makeVariable(e,t=!0,o,n){o=o||this.nextVariableId().toString(),n!=null&&n!==e.dtype&&(e=e.cast(n));let s=new Na(e,t,o,this.nextTensorId());if(this.state.registeredVariables[s.name]!=null)throw new Error(`Variable with name ${s.name} was already registered`);return this.state.registeredVariables[s.name]=s,this.incRef(s,this.backend),s}trackTensor(e,t){this.state.numTensors++,e.dtype===\"string\"&&this.state.numStringTensors++;let o=0;e.dtype!==\"complex64\"&&e.dtype!==\"string\"&&(o=e.size*up(e.dtype)),this.state.numBytes+=o,this.state.tensorInfo.has(e.dataId)||(this.state.numDataBuffers++,this.state.tensorInfo.set(e.dataId,{backend:t||this.backend,dtype:e.dtype,shape:e.shape,bytes:o})),e instanceof Na||this.track(e)}incRef(e,t){this.trackTensor(e,t),this.backend.incRef(e.dataId)}removeDataId(e,t){this.state.tensorInfo.has(e)&&this.state.tensorInfo.get(e).backend===t&&(this.state.tensorInfo.delete(e),this.state.numDataBuffers--)}disposeTensor(e){if(!this.state.tensorInfo.has(e.dataId))return;let t=this.state.tensorInfo.get(e.dataId);if(this.state.numTensors--,e.dtype===\"string\"&&(this.state.numStringTensors--,this.state.numBytes-=t.bytes),e.dtype!==\"complex64\"&&e.dtype!==\"string\"){let o=e.size*up(e.dtype);this.state.numBytes-=o}t.backend.disposeData(e.dataId)&&this.removeDataId(e.dataId,t.backend)}disposeVariables(){for(let e in this.state.registeredVariables){let t=this.state.registeredVariables[e];this.disposeVariable(t)}}disposeVariable(e){this.disposeTensor(e),this.state.registeredVariables[e.name]!=null&&delete this.state.registeredVariables[e.name]}memory(){let e=this.backend.memory();return e.numTensors=this.state.numTensors,e.numDataBuffers=this.state.numDataBuffers,e.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(e.unreliable=!0,e.reasons==null&&(e.reasons=[]),e.reasons.push(\"Memory usage by string tensors is approximate (2 bytes per character)\")),e}async profile(e){this.state.profiling=!0;let t=this.state.numBytes,o=this.state.numTensors;this.state.activeProfile.kernels=[],this.state.activeProfile.result=await e(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max(...this.state.activeProfile.kernels.map(n=>n.totalBytesSnapshot)),this.state.activeProfile.newBytes=this.state.numBytes-t,this.state.activeProfile.newTensors=this.state.numTensors-o;for(let n of this.state.activeProfile.kernels)n.kernelTimeMs=await n.kernelTimeMs,n.extraInfo=await n.extraInfo;return this.state.activeProfile}isTapeOn(){return this.state.gradientDepth>0&&this.state.kernelDepth===0}addTapeNode(e,t,o,n,s,a){let i={id:this.state.nextTapeNodeId++,kernelName:e,inputs:t,outputs:o,saved:s},p=Eb(e);p!=null&&(n=p.gradFunc),n!=null&&(i.gradient=u=>(u=u.map((c,l)=>{if(c==null){let m=o[l],d=lp(m.size,m.dtype);return this.makeTensor(d,m.shape,m.dtype)}return c}),n(u.length>1?u:u[0],s,a))),this.state.activeTape.push(i)}keep(e){return e.kept=!0,e}startTape(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++}endTape(){this.state.gradientDepth--}startScope(e){let t={track:[],name:\"unnamed scope\",id:this.state.nextScopeId++};e&&(t.name=e),this.state.scopeStack.push(t),this.state.activeScope=t}endScope(e){let t=Qc(e),o=new Set(t.map(s=>s.id));for(let s=0;s{!s.kept&&s.scopeId===n.id&&this.track(s)})}gradients(e,t,o,n=!1){if($(t.length>0,()=>\"gradients() received an empty list of xs.\"),o!=null&&o.dtype!==\"float32\")throw new Error(`dy must have 'float32' dtype, but has '${o.dtype}'`);let s=this.scopedRun(()=>this.startTape(),()=>this.endTape(),()=>this.tidy(\"forward\",e));$(s instanceof it,()=>\"The result y returned by f() must be a tensor.\");let a=l0(this.state.activeTape,t,s);if(!n&&a.length===0&&t.length>0)throw new Error(\"Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.\");return this.tidy(\"backward\",()=>{let i={};i[s.id]=o==null?Nz(s.shape):o,m0(i,a,u=>this.tidy(u),Tz);let p=t.map(u=>i[u.id]);return this.state.gradientDepth===0&&(this.state.activeTape.forEach(u=>{for(let c of u.saved)c.dispose()}),this.state.activeTape=null),{value:s,grads:p}})}customGrad(e){return $(gs(e),()=>\"The f passed in customGrad(f) must be a function.\"),(...t)=>{$(t.every(i=>i instanceof it),()=>\"The args passed in customGrad(f)(x1, x2,...) must all be tensors\");let o,n={};t.forEach((i,p)=>{n[p]=i});let s=(i,p)=>(o=e(...t,p),$(o.value instanceof it,()=>\"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor\"),$(gs(o.gradFunc),()=>\"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function.\"),o.value),a=(i,p)=>{let u=o.gradFunc(i,p),c=Array.isArray(u)?u:[u];$(c.length===t.length,()=>\"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...).\"),$(c.every(m=>m instanceof it),()=>\"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.\");let l={};return c.forEach((m,d)=>{l[d]=()=>m}),l};return this.runKernelFunc({forwardFunc:s,backwardsFunc:a,inputs:n})}}readSync(e){return this.state.tensorInfo.get(e).backend.readSync(e)}read(e){return this.state.tensorInfo.get(e).backend.read(e)}readToGPU(e,t){return this.state.tensorInfo.get(e).backend.readToGPU(e,t)}async time(e){let t=ou(),o=await this.backend.time(e);return o.wallMs=ou()-t,o}track(e){return this.state.activeScope!=null&&(e.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(e)),e}get registeredVariables(){return this.state.registeredVariables}reset(){this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new Mm;for(let e in this.registry)this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null}};vi.nextTensorId=0;vi.nextVariableId=0;function Nz(r){let e=Wc(We(r),\"float32\");return T.makeTensor(e,r,\"float32\")}function Hb(){let r=Tb();if(r._tfengine==null){let e=new Uc(r);r._tfengine=new vi(e)}return jI(r._tfengine.ENV),g0(()=>r._tfengine),r._tfengine}var T=Hb();function Tz(r,e){let t={a:r,b:e};return T.runKernel(eo,t)}var ki={};Ge(ki,{isBrowser:()=>qb,isMobile:()=>Ez,mockIsMobile:()=>$z});function _z(){return typeof navigator!=\"undefined\"&&navigator!=null}var Kb;function $z(r){Kb=r}function Ez(r){if(Kb!==void 0)return Kb;if(r||_z()){if(r||(r=navigator),r.product===\"ReactNative\")return!0;let e=r.userAgent||r.vendor||(typeof window!=\"undefined\"?window.opera:\"\");if(!e){let t=r;return t.userAgentData&&t.userAgentData.mobile}return/(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(e.substr(0,4))}return!1}function qb(){return typeof window!=\"undefined\"&&window.document!=null||typeof WorkerGlobalScope!=\"undefined\"}var oo=O();oo.registerFlag(\"DEBUG\",()=>!1,r=>{r&&console.warn(\"Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.\")});oo.registerFlag(\"IS_BROWSER\",()=>qb());oo.registerFlag(\"IS_NODE\",()=>typeof process!=\"undefined\"&&typeof process.versions!=\"undefined\"&&typeof process.versions.node!=\"undefined\");oo.registerFlag(\"IS_CHROME\",()=>typeof navigator!=\"undefined\"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor));oo.registerFlag(\"PROD\",()=>!1);oo.registerFlag(\"TENSORLIKE_CHECK_SHAPE_CONSISTENCY\",()=>oo.getBool(\"DEBUG\"));oo.registerFlag(\"DEPRECATION_WARNINGS_ENABLED\",()=>!0);oo.registerFlag(\"IS_TEST\",()=>!1);oo.registerFlag(\"CHECK_COMPUTATION_FOR_ERRORS\",()=>!0);oo.registerFlag(\"WRAP_TO_IMAGEBITMAP\",()=>!1);oo.registerFlag(\"CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU\",()=>!1);oo.registerFlag(\"USE_SETTIMEOUTCUSTOM\",()=>!1);function or(r,e){let t=r;if(Bt(r))return e===\"string\"?[]:[r.length];if(typeof r==\"object\"){if(\"texture\"in r){let s=r.channels||\"RGBA\";return[r.height,r.width*s.length]}else if(\"buffer\"in r&&!(r.buffer instanceof ArrayBuffer))return[r.buffer.size/(e==null?4:up(e))]}if(!Array.isArray(r))return[];let n=[];for(;Array.isArray(t)||Bt(t)&&e!==\"string\";)n.push(t.length),t=t[0];return Array.isArray(r)&&O().getBool(\"TENSORLIKE_CHECK_SHAPE_CONSISTENCY\")&&w0(r,n,[]),n}function w0(r,e,t){if(t=t||[],!Array.isArray(r)&&!Bt(r)){$(e.length===0,()=>`Element arr[${t.join(\"][\")}] is a primitive, but should be an array/TypedArray of ${e[0]} elements`);return}$(e.length>0,()=>`Element arr[${t.join(\"][\")}] should be a primitive, but is an array of ${r.length} elements`),$(r.length===e[0],()=>`Element arr[${t.join(\"][\")}] should have ${e[0]} elements, but has ${r.length} elements`);let o=e.slice(1);for(let n=0;n=0&&(n=o),S0(o,n,e,t),r==null||!Bt(r)&&!Array.isArray(r)&&typeof r!=\"number\"&&typeof r!=\"boolean\"&&typeof r!=\"string\"){let p=r==null?\"null\":r.constructor.name;throw new Error(`Argument '${e}' passed to '${t}' must be a Tensor or TensorLike, but got '${p}'`)}let s=or(r,n);!Bt(r)&&!Array.isArray(r)&&(r=[r]);let i=n!==\"string\"?Ap(r,n):os(r,[],!0);return T.makeTensor(i,s,n)}function _a(r,e,t,o=\"numeric\"){if(!Array.isArray(r))throw new Error(`Argument ${e} passed to ${t} must be a \\`Tensor[]\\` or \\`TensorLike[]\\``);return r.map((s,a)=>v(s,`${e}[${a}]`,t,o))}var jb=\"__op\";function N(r){let e=Object.keys(r);if(e.length!==1)throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${e.length} keys.`);let t=e[0],o=r[t];t.endsWith(\"_\")&&(t=t.substring(0,t.length-1)),t=t+jb;let n=(...s)=>{T.startScope(t);try{let a=o(...s);return Qi(a)&&console.error(\"Cannot return a Promise inside of tidy.\"),T.endScope(a),a}catch(a){throw T.endScope(null),a}};return Object.defineProperty(n,\"name\",{value:t,configurable:!0}),n}function Az(r,e){let t=v(r,\"real\",\"complex\"),o=v(e,\"imag\",\"complex\");gt(t.shape,o.shape,`real and imag shapes, ${t.shape} and ${o.shape}, must match in call to tf.complex().`);let n={real:t,imag:o};return T.runKernel(ri,n)}var Tr=N({complex_:Az});function xr(r,e,t,o){if(o==null)o=pp(r);else if(o===\"complex64\")throw new Error(\"Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).\");if(typeof r==\"object\"&&(\"texture\"in r||\"buffer\"in r&&!(r.buffer instanceof ArrayBuffer))){if(o!==\"float32\"&&o!==\"int32\")throw new Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${o}.`);return T.backend.createTensorFromGPUData(r,e||t,o)}if(!Bt(r)&&!Array.isArray(r)&&typeof r!=\"number\"&&typeof r!=\"boolean\"&&typeof r!=\"string\")throw new Error(\"values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray\");if(e!=null){bt(e);let n=We(e),s=We(t);$(n===s,()=>`Based on the provided shape, [${e}], the tensor should have ${n} values but has ${s}`);for(let a=0;a`Error creating a new Tensor. Inferred shape (${t}) does not match the provided shape (${e}). `)}}return!Bt(r)&&!Array.isArray(r)&&(r=[r]),e=e||t,r=o!==\"string\"?Ap(r,o):os(r,[],!0),T.makeTensor(r,e,o)}function nr(r,e,t){let o=or(r,t);return xr(r,e,o,t)}var Zc={float32:4,float16:2,int32:4,uint16:2,uint8:1,bool:1,complex64:8};var Lm=4;async function v0(r,e){let t=[],o=[],n=Array.isArray(r)?r.map(a=>a.name):Object.keys(r);for(let a=0;a{let m=await p.bytes(),d=m.reduce((g,x)=>g+x.length,0)+Lm*m.length,f=new Uint8Array(d),h=0;for(let g=0;g{if(e+=s.byteLength,t.push(s.byteLength===s.buffer.byteLength?s:new s.constructor(s)),!(s instanceof Float32Array||s instanceof Int32Array||s instanceof Uint8Array))throw new Error(`Unsupported TypedArray subtype: ${s.constructor.name}`)});let o=new Uint8Array(e),n=0;return t.forEach(s=>{o.set(new Uint8Array(s.buffer),n),n+=s.byteLength}),o.buffer}var Xb=typeof Buffer!=\"undefined\"&&(typeof Blob==\"undefined\"||typeof atob==\"undefined\"||typeof btoa==\"undefined\");function I0(r){return Xb?Buffer.byteLength(r):new Blob([r]).size}function k0(r){if(Xb)return Buffer.from(r).toString(\"base64\");let e=new Uint8Array(r),t=\"\";for(let o=0,n=e.length;o{e+=n.byteLength});let t=new Uint8Array(e),o=0;return r.forEach(n=>{t.set(new Uint8Array(n),o),o+=n.byteLength}),t.buffer}function Yb(r){let e=\"/\";for(r=r.trim();r.endsWith(e);)r=r.slice(0,r.length-1);let t=r.split(e);return t[t.length-1]}function Vm(r,e){let t={modelTopology:r.modelTopology,format:r.format,generatedBy:r.generatedBy,convertedBy:r.convertedBy,weightsManifest:e};return r.signature!=null&&(t.signature=r.signature),r.userDefinedMetadata!=null&&(t.userDefinedMetadata=r.userDefinedMetadata),r.modelInitializer!=null&&(t.modelInitializer=r.modelInitializer),r.initializerSignature!=null&&(t.initializerSignature=r.initializerSignature),r.trainingConfig!=null&&(t.trainingConfig=r.trainingConfig),t}function Qb(r,e,t){let o={modelTopology:r.modelTopology,format:r.format,generatedBy:r.generatedBy,convertedBy:r.convertedBy};if(r.trainingConfig!=null&&(o.trainingConfig=r.trainingConfig),r.weightsManifest!=null){if(!e)throw new Error(\"modelJSON has weightsManifest but weightSpecs is null\");if(!t)throw new Error(\"modelJSON has weightsManifest but weightData is null\");o.weightSpecs=e,o.weightData=t}return r.signature!=null&&(o.signature=r.signature),r.userDefinedMetadata!=null&&(o.userDefinedMetadata=r.userDefinedMetadata),r.modelInitializer!=null&&(o.modelInitializer=r.modelInitializer),r.initializerSignature!=null&&(o.initializerSignature=r.initializerSignature),o}async function Op(r,e){let t,o;return r.weightsManifest!=null&&([t,o]=await e(r.weightsManifest)),Qb(r,t,o)}function Ms(r){if(r.modelTopology instanceof ArrayBuffer)throw new Error(\"Expected JSON model topology, received ArrayBuffer.\");return{dateSaved:new Date,modelTopologyType:\"JSON\",modelTopologyBytes:r.modelTopology==null?0:I0(JSON.stringify(r.modelTopology)),weightSpecsBytes:r.weightSpecs==null?0:I0(JSON.stringify(r.weightSpecs)),weightDataBytes:r.weightData==null?0:r.weightData.byteLength}}function zm(r){let e=[];for(let t of r)e.push(...t.weights);return e}function Dz(){let r=t=>{let o=t<<13,n=0;for(;!(o&8388608);)n-=8388608,o<<=1;return o&=-8388609,n+=947912704,o|n},e=new Uint32Array(2048);e[0]=0;for(let t=1;t<1024;t++)e[t]=r(t);for(let t=1024;t<2048;t++)e[t]=939524096+(t-1024<<13);return e}function Fz(){let r=new Uint32Array(64);r[0]=0,r[31]=1199570944,r[32]=2147483648,r[63]=3347054592;for(let e=1;e<31;e++)r[e]=e<<23;for(let e=33;e<63;e++)r[e]=2147483648+(e-32<<23);return r}function Oz(){let r=new Uint32Array(64);for(let e=0;e<64;e++)r[e]=1024;return r[0]=r[32]=0,r}function Pz(){let r=Dz(),e=Fz(),t=Oz();return o=>{let n=new ArrayBuffer(4*o.length),s=new Uint32Array(n);for(let a=0;a>10]+(i&1023)]+e[i>>10];s[a]=p}return new Float32Array(n)}}var mt=class{constructor(){this.saveRouters=[],this.loadRouters=[]}static getInstance(){return mt.instance==null&&(mt.instance=new mt),mt.instance}static registerSaveRouter(e){mt.getInstance().saveRouters.push(e)}static registerLoadRouter(e){mt.getInstance().loadRouters.push(e)}static getSaveHandlers(e){return mt.getHandlers(e,\"save\")}static getLoadHandlers(e,t){return mt.getHandlers(e,\"load\",t)}static getHandlers(e,t,o){let n=[];return(t===\"load\"?mt.getInstance().loadRouters:mt.getInstance().saveRouters).forEach(a=>{let i=a(e,o);i!==null&&n.push(i)}),n}},T0=r=>mt.registerSaveRouter(r),_0=r=>mt.registerLoadRouter(r),$0=r=>mt.getSaveHandlers(r),E0=(r,e)=>mt.getLoadHandlers(r,e);var Zb=\"tensorflowjs\",Jb=1,nu=\"models_store\",Ni=\"model_info_store\";function A0(){if(!O().getBool(\"IS_BROWSER\"))throw new Error(\"Failed to obtain IndexedDB factory because the current environmentis not a web browser.\");let r=typeof window==\"undefined\"?self:window,e=r.indexedDB||r.mozIndexedDB||r.webkitIndexedDB||r.msIndexedDB||r.shimIndexedDB;if(e==null)throw new Error(\"The current browser does not appear to support IndexedDB.\");return e}function eC(r){let e=r.result;e.createObjectStore(nu,{keyPath:\"modelPath\"}),e.createObjectStore(Ni,{keyPath:\"modelPath\"})}var Ls=class{constructor(e){if(this.indexedDB=A0(),e==null||!e)throw new Error(\"For IndexedDB, modelPath must not be null, undefined or empty.\");this.modelPath=e}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error(\"BrowserLocalStorage.save() does not support saving model topology in binary formats yet.\");return this.databaseAction(this.modelPath,e)}async load(){return this.databaseAction(this.modelPath)}databaseAction(e,t){return new Promise((o,n)=>{let s=this.indexedDB.open(Zb,Jb);s.onupgradeneeded=()=>eC(s),s.onsuccess=()=>{let a=s.result;if(t==null){let i=a.transaction(nu,\"readonly\"),u=i.objectStore(nu).get(this.modelPath);u.onsuccess=()=>{if(u.result==null)return a.close(),n(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));o(u.result.modelArtifacts)},u.onerror=c=>(a.close(),n(u.error)),i.oncomplete=()=>a.close()}else{let i=Ms(t),p=a.transaction(Ni,\"readwrite\"),u=p.objectStore(Ni),c=u.put({modelPath:this.modelPath,modelArtifactsInfo:i}),l;c.onsuccess=()=>{l=a.transaction(nu,\"readwrite\");let d=l.objectStore(nu).put({modelPath:this.modelPath,modelArtifacts:t,modelArtifactsInfo:i});d.onsuccess=()=>o({modelArtifactsInfo:i}),d.onerror=f=>{u=p.objectStore(Ni);let h=u.delete(this.modelPath);h.onsuccess=()=>(a.close(),n(d.error)),h.onerror=g=>(a.close(),n(d.error))}},c.onerror=m=>(a.close(),n(c.error)),p.oncomplete=()=>{l==null?a.close():l.oncomplete=()=>a.close()}}},s.onerror=a=>n(s.error)})}};Ls.URL_SCHEME=\"indexeddb://\";var R0=r=>O().getBool(\"IS_BROWSER\")&&!Array.isArray(r)&&r.startsWith(Ls.URL_SCHEME)?Mz(r.slice(Ls.URL_SCHEME.length)):null;mt.registerSaveRouter(R0);mt.registerLoadRouter(R0);function Mz(r){return new Ls(r)}function Lz(r){return r.startsWith(Ls.URL_SCHEME)?r.slice(Ls.URL_SCHEME.length):r}var Wm=class{constructor(){this.indexedDB=A0()}async listModels(){return new Promise((e,t)=>{let o=this.indexedDB.open(Zb,Jb);o.onupgradeneeded=()=>eC(o),o.onsuccess=()=>{let n=o.result,s=n.transaction(Ni,\"readonly\"),i=s.objectStore(Ni).getAll();i.onsuccess=()=>{let p={};for(let u of i.result)p[u.modelPath]=u.modelArtifactsInfo;e(p)},i.onerror=p=>(n.close(),t(i.error)),s.oncomplete=()=>n.close()},o.onerror=n=>t(o.error)})}async removeModel(e){return e=Lz(e),new Promise((t,o)=>{let n=this.indexedDB.open(Zb,Jb);n.onupgradeneeded=()=>eC(n),n.onsuccess=()=>{let s=n.result,a=s.transaction(Ni,\"readwrite\"),i=a.objectStore(Ni),p=i.get(e),u;p.onsuccess=()=>{if(p.result==null)return s.close(),o(new Error(`Cannot find model with path '${e}' in IndexedDB.`));{let c=i.delete(e),l=()=>{u=s.transaction(nu,\"readwrite\");let d=u.objectStore(nu).delete(e);d.onsuccess=()=>t(p.result.modelArtifactsInfo),d.onerror=f=>o(p.error)};c.onsuccess=l,c.onerror=m=>(l(),s.close(),o(p.error))}},p.onerror=c=>(s.close(),o(p.error)),a.oncomplete=()=>{u==null?s.close():u.oncomplete=()=>s.close()}},n.onerror=s=>o(n.error)})}};var $a=\"/\",Pp=\"tensorflowjs_models\",D0=\"info\",Bz=\"model_topology\",Vz=\"weight_specs\",zz=\"weight_data\",Wz=\"model_metadata\";function F0(r){return{info:[Pp,r,D0].join($a),topology:[Pp,r,Bz].join($a),weightSpecs:[Pp,r,Vz].join($a),weightData:[Pp,r,zz].join($a),modelMetadata:[Pp,r,Wz].join($a)}}function O0(r){for(let e of Object.values(r))window.localStorage.removeItem(e)}function Uz(r){let e=r.split($a);if(e.length<3)throw new Error(`Invalid key format: ${r}`);return e.slice(1,e.length-1).join($a)}function Gz(r){return r.startsWith(Bs.URL_SCHEME)?r.slice(Bs.URL_SCHEME.length):r}var Bs=class{constructor(e){if(!O().getBool(\"IS_BROWSER\")||typeof window==\"undefined\"||typeof window.localStorage==\"undefined\")throw new Error(\"The current environment does not support local storage.\");if(this.LS=window.localStorage,e==null||!e)throw new Error(\"For local storage, modelPath must not be null, undefined or empty.\");this.modelPath=e,this.keys=F0(this.modelPath)}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error(\"BrowserLocalStorage.save() does not support saving model topology in binary formats yet.\");{let t=JSON.stringify(e.modelTopology),o=JSON.stringify(e.weightSpecs),n=Ms(e);try{this.LS.setItem(this.keys.info,JSON.stringify(n)),this.LS.setItem(this.keys.topology,t),this.LS.setItem(this.keys.weightSpecs,o),this.LS.setItem(this.keys.weightData,k0(e.weightData));let s={format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,signature:e.signature!=null?e.signature:void 0,userDefinedMetadata:e.userDefinedMetadata!=null?e.userDefinedMetadata:void 0,modelInitializer:e.modelInitializer!=null?e.modelInitializer:void 0,initializerSignature:e.initializerSignature!=null?e.initializerSignature:void 0,trainingConfig:e.trainingConfig!=null?e.trainingConfig:void 0};return this.LS.setItem(this.keys.modelMetadata,JSON.stringify(s)),{modelArtifactsInfo:n}}catch(s){throw O0(this.keys),new Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${n.modelTopologyBytes}, weightSpecsBytes=${n.weightSpecsBytes}, weightDataBytes=${n.weightDataBytes}.`)}}}async load(){let e=JSON.parse(this.LS.getItem(this.keys.info));if(e==null)throw new Error(`In local storage, there is no model with name '${this.modelPath}'`);if(e.modelTopologyType!==\"JSON\")throw new Error(\"BrowserLocalStorage does not support loading non-JSON model topology yet.\");let t={},o=JSON.parse(this.LS.getItem(this.keys.topology));if(o==null)throw new Error(`In local storage, the topology of model '${this.modelPath}' is missing.`);t.modelTopology=o;let n=JSON.parse(this.LS.getItem(this.keys.weightSpecs));if(n==null)throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);t.weightSpecs=n;let s=this.LS.getItem(this.keys.modelMetadata);if(s!=null){let i=JSON.parse(s);t.format=i.format,t.generatedBy=i.generatedBy,t.convertedBy=i.convertedBy,i.signature!=null&&(t.signature=i.signature),i.userDefinedMetadata!=null&&(t.userDefinedMetadata=i.userDefinedMetadata),i.modelInitializer!=null&&(t.modelInitializer=i.modelInitializer),i.initializerSignature!=null&&(t.initializerSignature=i.initializerSignature),i.trainingConfig!=null&&(t.trainingConfig=i.trainingConfig)}let a=this.LS.getItem(this.keys.weightData);if(a==null)throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);return t.weightData=N0(a),t}};Bs.URL_SCHEME=\"localstorage://\";var P0=r=>O().getBool(\"IS_BROWSER\")&&!Array.isArray(r)&&r.startsWith(Bs.URL_SCHEME)?Hz(r.slice(Bs.URL_SCHEME.length)):null;mt.registerSaveRouter(P0);mt.registerLoadRouter(P0);function Hz(r){return new Bs(r)}var Um=class{constructor(){$(O().getBool(\"IS_BROWSER\"),()=>\"Current environment is not a web browser\"),$(typeof window==\"undefined\"||typeof window.localStorage!=\"undefined\",()=>\"Current browser does not appear to support localStorage\"),this.LS=window.localStorage}async listModels(){let e={},t=Pp+$a,o=$a+D0;for(let n=0;n\"scheme must not be undefined or null.\"),e.endsWith(Mp)&&(e=e.slice(0,e.indexOf(Mp))),$(e.length>0,()=>\"scheme must not be an empty string.\");let o=Xt.getInstance();$(o.managers[e]==null,()=>`A model store manager is already registered for scheme '${e}'.`),o.managers[e]=t}static getManager(e){let t=Xt.getInstance().managers[e];if(t==null)throw new Error(`Cannot find model manager for scheme '${e}'`);return t}static getSchemes(){return Object.keys(Xt.getInstance().managers)}};function Gm(r){if(r.indexOf(Mp)===-1)throw new Error(`The url string provided does not contain a scheme. Supported schemes are: ${Xt.getSchemes().join(\",\")}`);return{scheme:r.split(Mp)[0],path:r.split(Mp)[1]}}async function M0(r,e,t=!1){$(r!==e,()=>`Old path and new path are the same: '${r}'`);let o=mt.getLoadHandlers(r);$(o.length>0,()=>`Copying failed because no load handler is found for source URL ${r}.`),$(o.length<2,()=>`Copying failed because more than one (${o.length}) load handlers for source URL ${r}.`);let n=o[0],s=mt.getSaveHandlers(e);$(s.length>0,()=>`Copying failed because no save handler is found for destination URL ${e}.`),$(s.length<2,()=>`Copying failed because more than one (${o.length}) save handlers for destination URL ${e}.`);let a=s[0],i=Gm(r).scheme,p=Gm(r).path,u=i===Gm(r).scheme,c=await n.load();t&&u&&await Xt.getManager(i).removeModel(p);let l=await a.save(c);return t&&!u&&await Xt.getManager(i).removeModel(p),l.modelArtifactsInfo}async function L0(){let r=Xt.getSchemes(),e={};for(let t of r){let o=await Xt.getManager(t).listModels();for(let n in o){let s=t+Mp+n;e[s]=o[n]}}return e}async function B0(r){let e=Gm(r);return Xt.getManager(e.scheme).removeModel(e.path)}async function V0(r,e){return M0(r,e,!1)}async function z0(r,e){return M0(r,e,!0)}var tC=class{constructor(){this.messageName=\"setTimeoutCustom\",this.functionRefs=[],this.handledMessageCount=0,this.hasEventListener=!1}fetch(e,t){return fetch(e,t)}now(){return performance.now()}encode(e,t){if(t!==\"utf-8\"&&t!==\"utf8\")throw new Error(`Browser's encoder only supports utf-8, but got ${t}`);return this.textEncoder==null&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(e)}decode(e,t){return new TextDecoder(t).decode(e)}setTimeoutCustom(e,t){if(typeof window==\"undefined\"||!O().getBool(\"USE_SETTIMEOUTCUSTOM\")){setTimeout(e,t);return}this.functionRefs.push(e),setTimeout(()=>{window.postMessage({name:this.messageName,index:this.functionRefs.length-1},\"*\")},t),this.hasEventListener||(this.hasEventListener=!0,window.addEventListener(\"message\",o=>{if(o.source===window&&o.data.name===this.messageName){o.stopPropagation();let n=this.functionRefs[o.data.index];n(),this.handledMessageCount++,this.handledMessageCount===this.functionRefs.length&&(this.functionRefs=[],this.handledMessageCount=0)}},!0))}isTypedArray(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray}};if(O().get(\"IS_BROWSER\")){O().setPlatform(\"browser\",new tC);try{Xt.registerManager(Bs.URL_SCHEME,new Um)}catch(r){}try{Xt.registerManager(Ls.URL_SCHEME,new Wm)}catch(r){}}var Kz={importFetch:()=>W0()},rC;var oC=class{constructor(){this.util=U0(),this.textEncoder=new this.util.TextEncoder}fetch(e,t){return O().global.fetch!=null?O().global.fetch(e,t):(rC==null&&(rC=Kz.importFetch()),rC(e,t))}now(){let e=process.hrtime();return e[0]*1e3+e[1]/1e6}encode(e,t){if(t!==\"utf-8\"&&t!==\"utf8\")throw new Error(`Node built-in encoder only supports utf-8, but got ${t}`);return this.textEncoder.encode(e)}decode(e,t){return e.length===0?\"\":new this.util.TextDecoder(t).decode(e)}isTypedArray(e){return this.util.types.isFloat32Array(e)||this.util.types.isInt32Array(e)||this.util.types.isUint8Array(e)||this.util.types.isUint8ClampedArray(e)}};O().get(\"IS_NODE\")&&!O().get(\"IS_BROWSER\")&&O().setPlatform(\"node\",new oC);function le(r,e=\"float32\",t){return e=e||\"float32\",bt(r),new st(r,e,t)}function qz(r,e){let t=v(r,\"x\",\"cast\");if(!Ib(e))throw new Error(`Failed to cast to unknown dtype ${e}`);if(e===\"string\"&&t.dtype!==\"string\"||e!==\"string\"&&t.dtype===\"string\")throw new Error(\"Only strings can be casted to strings\");let o={x:t},n={dtype:e};return T.runKernel(co,o,n)}var je=N({cast_:qz});function jz(r){let t={x:v(r,\"x\",\"clone\",\"string_or_numeric\")};return T.runKernel(mo,t)}var Lr=N({clone_:jz});function Hm(r,e=!1){console.log(r.toString(e))}Hb();var Xz={buffer:le,cast:je,clone:Lr,print:Hm};x0(Xz);function Iie(){O().set(\"PROD\",!0)}function vie(){O().set(\"DEBUG\",!0)}function kie(){O().set(\"DEPRECATION_WARNINGS_ENABLED\",!1),console.warn(\"TensorFlow.js deprecation warnings have been disabled.\")}function nC(r){O().getBool(\"DEPRECATION_WARNINGS_ENABLED\")&&console.warn(r+\" You can disable deprecation warnings with tf.disableDeprecationWarnings().\")}y0(nC);function Nie(){T.disposeVariables()}function sr(){return T}function Tie(){return T.memory()}function _ie(r){return T.profile(r)}function Ee(r,e){return T.tidy(r,e)}function Ot(r){Qc(r).forEach(t=>t.dispose())}function _r(r){return T.keep(r)}function $ie(r){return T.time(r)}function Eie(r){return T.setBackend(r)}function Aie(){return T.ready()}function Rie(){return T.backendName}function Die(r){T.removeBackend(r)}function Fie(r){return T.findBackend(r)}function Oie(r){return T.findBackendFactory(r)}function Ti(r,e,t=1){return T.registerBackend(r,e,t)}function Pie(){return T.backend}function Mie(r,e){O().setPlatform(r,e)}function Yz(r,e){let t=v(r,\"a\",\"add\"),o=v(e,\"b\",\"add\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(eo,n)}var be=N({add_:Yz});function Qz(r,e){let t=v(r,\"a\",\"floorDiv\"),o=v(e,\"b\",\"floorDiv\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(nn,n)}var Km=N({floorDiv_:Qz});function Zz(r,e){let t=v(r,\"a\",\"div\"),o=v(e,\"b\",\"div\");if([t,o]=De(t,o),t.dtype===\"int32\"&&o.dtype===\"int32\")return Km(t,o);let n={a:t,b:o},s={};return T.runKernel(Zo,n,s)}var He=N({div_:Zz});function Jz(r,e){let t=v(r,\"a\",\"mul\"),o=v(e,\"b\",\"mul\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(kn,n)}var ne=N({mul_:Jz});function eW(r){let e=v(r,\"x\",\"abs\");if(e.dtype===\"complex64\"){let t={x:e};return T.runKernel(hp,t)}else{let t={x:e};return T.runKernel(ys,t)}}var Yt=N({abs_:eW});function tW(r){let t={x:v(r,\"x\",\"acos\")};return T.runKernel(aa,t)}var G0=N({acos_:tW});function rW(r){let t={x:v(r,\"x\",\"acosh\")};return T.runKernel(ia,t)}var H0=N({acosh_:rW});function oW(r){$(Array.isArray(r),()=>\"The argument passed to tf.addN() must be a list of tensors\"),$(r.length>=1,()=>`Must pass at least one tensor to tf.addN(), but got ${r.length}`);let e=r.map((n,s)=>v(n,`tensors${s}`,\"addN\")),t=e[0];e.forEach(n=>{if(n.dtype!==t.dtype)throw new Error(\"All tensors passed to tf.addN() must have the same dtype\")}),e.forEach(n=>{if(!Or(n.shape,t.shape))throw new Error(\"All tensors passed to tf.addN() must have the same shape\")});let o=e;return T.runKernel(Po,o)}var K0=N({addN_:oW});function nW(r,e=null,t=!1){let n={x:v(r,\"x\",\"all\",\"bool\")},s={axis:e,keepDims:t};return T.runKernel(Mo,n,s)}var q0=N({all_:nW});function sW(r,e=null,t=!1){let n={x:v(r,\"x\",\"any\",\"bool\")},s={axis:e,keepDims:t};return T.runKernel(Lo,n,s)}var j0=N({any_:sW});function aW(r,e=0){let o={x:v(r,\"x\",\"argMax\")},n={axis:e};return T.runKernel(Bo,o,n)}var X0=N({argMax_:aW});function iW(r,e=0){let o={x:v(r,\"x\",\"argMin\")},n={axis:e};return T.runKernel(ei,o,n)}var Y0=N({argMin_:iW});function uW(r){let t={x:v(r,\"x\",\"asin\")};return T.runKernel(ua,t)}var Q0=N({asin_:uW});function pW(r){let t={x:v(r,\"x\",\"asinh\")};return T.runKernel(pa,t)}var Z0=N({asinh_:pW});function cW(r){let t={x:v(r,\"x\",\"atan\")};return T.runKernel(ca,t)}var J0=N({atan_:cW});function lW(r,e){let t=v(r,\"a\",\"atan2\"),o=v(e,\"b\",\"atan2\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(ma,n)}var ev=N({atan2_:lW});function mW(r){let t={x:v(r,\"x\",\"atanh\")};return T.runKernel(la,t)}var tv=N({atanh_:mW});function dW(r,e,t,o,n=\"NHWC\",s){let a=r[3],i=[...e,a],p=ov(n);return au(r,i,t,s,o,null,null,p)}function aC(r,e,t,o,n,s,a=\"channelsLast\"){let[i,p]=Jc(e),u;if(a===\"channelsLast\")u=[i,p,r[3],r[3]];else if(a===\"channelsFirst\")u=[i,p,r[1],r[1]];else throw new Error(`Unknown dataFormat ${a}`);return au(r,u,t,o,n,s,!1,a)}function fW(r,e,t,o,n,s,a=\"NDHWC\"){let[i,p,u]=sC(e),c,l;if(a===\"NDHWC\")l=\"channelsLast\",c=[i,p,u,r[4],r[4]];else if(a===\"NCDHW\")l=\"channelsFirst\",c=[i,p,u,r[1],r[1]];else throw new Error(`Unknown dataFormat ${a}`);return rv(r,c,t,o,n,!1,l,s)}function au(r,e,t,o,n,s,a=!1,i=\"channelsLast\"){let[p,u,c,l]=[-1,-1,-1,-1];if(i===\"channelsLast\")[p,u,c,l]=r;else if(i===\"channelsFirst\")[p,l,u,c]=r;else throw new Error(`Unknown dataFormat ${i}`);let[m,d,,f]=e,[h,g]=Jc(t),[x,b]=Jc(o),C=Lp(m,x),w=Lp(d,b),{padInfo:k,outHeight:_,outWidth:E}=xW(n,u,c,h,g,C,w,s,i),A=a?f*l:f,R;return i===\"channelsFirst\"?R=[p,A,_,E]:i===\"channelsLast\"&&(R=[p,_,E,A]),{batchSize:p,dataFormat:i,inHeight:u,inWidth:c,inChannels:l,outHeight:_,outWidth:E,outChannels:A,padInfo:k,strideHeight:h,strideWidth:g,filterHeight:m,filterWidth:d,effectiveFilterHeight:C,effectiveFilterWidth:w,dilationHeight:x,dilationWidth:b,inShape:r,outShape:R,filterShape:e}}function rv(r,e,t,o,n,s=!1,a=\"channelsLast\",i){let[p,u,c,l,m]=[-1,-1,-1,-1,-1];if(a===\"channelsLast\")[p,u,c,l,m]=r;else if(a===\"channelsFirst\")[p,m,u,c,l]=r;else throw new Error(`Unknown dataFormat ${a}`);let[d,f,h,,g]=e,[x,b,C]=sC(t),[w,k,_]=sC(o),E=Lp(d,w),A=Lp(f,k),R=Lp(h,_),{padInfo:D,outDepth:P,outHeight:M,outWidth:L}=yW(n,u,c,l,x,b,C,E,A,R,i),V=s?g*m:g,z;return a===\"channelsFirst\"?z=[p,V,P,M,L]:a===\"channelsLast\"&&(z=[p,P,M,L,V]),{batchSize:p,dataFormat:a,inDepth:u,inHeight:c,inWidth:l,inChannels:m,outDepth:P,outHeight:M,outWidth:L,outChannels:V,padInfo:D,strideDepth:x,strideHeight:b,strideWidth:C,filterDepth:d,filterHeight:f,filterWidth:h,effectiveFilterDepth:E,effectiveFilterHeight:A,effectiveFilterWidth:R,dilationDepth:w,dilationHeight:k,dilationWidth:_,inShape:r,outShape:z,filterShape:e}}function hW(r,e,t,o,n){o==null&&(o=iC(r,e,t));let s=r[0],a=r[1],i=el((s-e+2*o)/t+1,n),p=el((a-e+2*o)/t+1,n);return[i,p]}function gW(r,e,t,o,n,s){n==null&&(n=iC(r,e[0],o[0]));let a=[0,0,0,t];for(let i=0;i<3;i++)r[i]+2*n>=e[i]&&(a[i]=el((r[i]-e[i]+2*n)/o[i]+1,s));return a}function iC(r,e,t,o=1){let n=Lp(e,o);return Math.floor((r[0]*(t-1)-t+n)/2)}function Jc(r){return typeof r==\"number\"?[r,r,r]:r.length===2?[r[0],r[1],1]:r}function sC(r){return typeof r==\"number\"?[r,r,r]:r}function Lp(r,e){return e<=1?r:r+(r-1)*(e-1)}function xW(r,e,t,o,n,s,a,i,p){let u,c,l;if(typeof r==\"number\"){u={top:r,bottom:r,left:r,right:r,type:r===0?\"VALID\":\"NUMBER\"};let d=hW([e,t],s,o,r,i);c=d[0],l=d[1]}else if(r===\"same\"){c=Math.ceil(e/o),l=Math.ceil(t/n);let m=Math.max(0,(c-1)*o+s-e),d=Math.max(0,(l-1)*n+a-t),f=Math.floor(m/2),h=m-f,g=Math.floor(d/2),x=d-g;u={top:f,bottom:h,left:g,right:x,type:\"SAME\"}}else if(r===\"valid\")u={top:0,bottom:0,left:0,right:0,type:\"VALID\"},c=Math.ceil((e-s+1)/o),l=Math.ceil((t-a+1)/n);else if(typeof r==\"object\"){let m=p===\"channelsLast\"?r[1][0]:r[2][0],d=p===\"channelsLast\"?r[1][1]:r[2][1],f=p===\"channelsLast\"?r[2][0]:r[3][0],h=p===\"channelsLast\"?r[2][1]:r[3][1];u={top:m,bottom:d,left:f,right:h,type:m===0&&d===0&&f===0&&h===0?\"VALID\":\"EXPLICIT\"},c=el((e-s+m+d)/o+1,i),l=el((t-a+f+h)/n+1,i)}else throw Error(`Unknown padding parameter: ${r}`);return{padInfo:u,outHeight:c,outWidth:l}}function yW(r,e,t,o,n,s,a,i,p,u,c){let l,m,d,f;if(r===\"valid\"&&(r=0),typeof r==\"number\"){l={top:r,bottom:r,left:r,right:r,front:r,back:r,type:r===0?\"VALID\":\"NUMBER\"};let g=gW([e,t,o,1],[i,p,u],1,[n,s,a],r,c);m=g[0],d=g[1],f=g[2]}else if(r===\"same\"){m=Math.ceil(e/n),d=Math.ceil(t/s),f=Math.ceil(o/a);let h=(m-1)*n+i-e,g=(d-1)*s+p-t,x=(f-1)*a+u-o,b=Math.floor(h/2),C=h-b,w=Math.floor(g/2),k=g-w,_=Math.floor(x/2),E=x-_;l={top:w,bottom:k,left:_,right:E,front:b,back:C,type:\"SAME\"}}else throw Error(`Unknown padding parameter: ${r}`);return{padInfo:l,outDepth:m,outHeight:d,outWidth:f}}function el(r,e){if(!e)return Math.trunc(r);switch(e){case\"round\":return Math.round(r);case\"ceil\":return Math.ceil(r);case\"floor\":return Math.floor(r);default:throw new Error(`Unknown roundingMode ${e}`)}}function su(r){let[e,t,o]=Jc(r);return e===1&&t===1&&o===1}function mr(r,e){return su(r)||su(e)}function Vs(r){return Jc(r).every(e=>e>0)}function ov(r){if(r===\"NHWC\")return\"channelsLast\";if(r===\"NCHW\")return\"channelsFirst\";throw new Error(`Unknown dataFormat ${r}`)}function Mt(r,e,t){if(t!=null){if(typeof e==\"string\")throw Error(`Error in ${r}: pad must be an integer when using dimRoundingMode ${t} but got pad ${e}.`);if(typeof e==\"number\")$(sa(e),()=>`Error in ${r}: pad must be an integer when using dimRoundingMode ${t} but got pad ${e}.`);else if(typeof e==\"object\")e.forEach(o=>{o.forEach(n=>{$(sa(n),()=>`Error in ${r}: pad must be an integer when using dimRoundingMode ${t} but got pad ${n}.`)})});else throw Error(`Error in ${r}: Unknown padding parameter: ${e}`)}}function bW(r,e){let o={x:v(r,\"x\",\"reshape\",\"string_or_numeric\")},n={shape:e};return T.runKernel(_s,o,n)}var W=N({reshape_:bW});function CW(r,e,t,o,n){let s=v(r,\"x\",\"avgPool\",\"float32\"),a=1;$(mr(t,a),()=>`Error in avgPool: Either strides or dilations must be 1. Got strides ${t} and dilations '${a}'`);let i=s,p=!1;s.rank===3&&(p=!0,i=W(s,[1,s.shape[0],s.shape[1],s.shape[2]])),$(i.rank===4,()=>`Error in avgPool: x must be rank 4 but got rank ${i.rank}.`),Mt(\"avgPool\",o,n);let u={x:i},c={filterSize:e,strides:t,pad:o,dimRoundingMode:n},l=T.runKernel(Vo,u,c);return l=je(l,s.dtype),p?W(l,[l.shape[1],l.shape[2],l.shape[3]]):l}var qm=N({avgPool_:CW});function SW(r,e,t,o,n,s=\"NDHWC\"){let a=v(r,\"x\",\"avgPool3d\",\"float32\"),i=a,p=!1;a.rank===4&&(p=!0,i=W(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]])),$(i.rank===5,()=>`Error in avgPool3d: x must be rank 5 but got rank ${i.rank}.`),$(s===\"NDHWC\",()=>`Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of ${s}`),$(typeof t==\"number\"&&t>0||Array.isArray(t)&&t[0]>0&&t[1]>0&&t[2]>0,()=>`Error in avgPool3d: Stride must be > 0, but got '${t}'`),Mt(\"avgPool3d\",o,n);let u={x:i},c={filterSize:e,strides:t,pad:o,dimRoundingMode:n,dataFormat:s},l=T.runKernel(dp,u,c);return l=je(l,i.dtype),p?W(l,[l.shape[1],l.shape[2],l.shape[3],l.shape[4]]):l}var nv=N({avgPool3d_:SW});function wW(r,e=0){$(r.length>=1,()=>\"Pass at least one tensor to concat\");let t=_a(r,\"tensors\",\"concat\",\"string_or_numeric\");if(t[0].dtype===\"complex64\"&&t.forEach(s=>{if(s.dtype!==\"complex64\")throw new Error(`Cannot concatenate complex64 tensors with a tensor\n with dtype ${s.dtype}. `)}),t.length===1)return Lr(t[0]);let o=t,n={axis:e};return T.runKernel(Cs,o,n)}var xt=N({concat_:wW});function IW(r,e,t=!1,o=!1){let n=v(r,\"a\",\"matMul\"),s=v(e,\"b\",\"matMul\");[n,s]=De(n,s);let a={a:n,b:s},i={transposeA:t,transposeB:o};return T.runKernel(zo,a,i)}var Xe=N({matMul_:IW});function vW(r){let t={x:v(r,\"x\",\"sigmoid\",\"float32\")};return T.runKernel(Gn,t)}var Ws=N({sigmoid_:vW});function kW(r,e,t){let o=v(r,\"x\",\"slice\",\"string_or_numeric\");if(o.rank===0)throw new Error(\"Slicing scalar is not possible\");let n={x:o},s={begin:e,size:t};return T.runKernel(Es,n,s)}var Ke=N({slice_:kW});function NW(r){let t={x:v(r,\"x\",\"tanh\",\"float32\")};return T.runKernel(Zn,t)}var tl=N({tanh_:NW});function TW(r,e,t,o,n,s){let a=v(r,\"forgetBias\",\"basicLSTMCell\"),i=v(e,\"lstmKernel\",\"basicLSTMCell\"),p=v(t,\"lstmBias\",\"basicLSTMCell\"),u=v(o,\"data\",\"basicLSTMCell\"),c=v(n,\"c\",\"basicLSTMCell\"),l=v(s,\"h\",\"basicLSTMCell\"),m=xt([u,l],1),d=Xe(m,i),f=be(d,p),h=f.shape[0],g=f.shape[1]/4,x=[h,g],b=Ke(f,[0,0],x),C=Ke(f,[0,g],x),w=Ke(f,[0,g*2],x),k=Ke(f,[0,g*3],x),_=be(ne(Ws(b),tl(C)),ne(c,Ws(be(a,w)))),E=ne(tl(_),Ws(k));return[_,E]}var sv=N({basicLSTMCell_:TW});function _W(r,e,t){let o=v(r,\"x\",\"batchToSpaceND\"),n=e.reduce((i,p)=>i*p);$(o.rank>=1+e.length,()=>`input rank is ${o.rank} but should be > than blockShape.length ${e.length}`),$(t.length===e.length,()=>`crops.length is ${t.length} but should be equal to blockShape.length ${e.length}`),$(o.shape[0]%n===0,()=>`input tensor batch is ${o.shape[0]} but is not divisible by the product of the elements of blockShape ${e.join(\" * \")} === ${n}`);let s={x:o},a={blockShape:e,crops:t};return T.runKernel(bs,s,a)}var jm=N({batchToSpaceND_:_W});function av(r){let e;return r.rank===0||r.rank===1?e=W(r,[1,1,1,r.size]):r.rank===2?e=W(r,[1,1,r.shape[0],r.shape[1]]):r.rank===3?e=W(r,[1,r.shape[0],r.shape[1],r.shape[2]]):e=r,e}function $W(r,e,t,o,n,s){s==null&&(s=.001);let a=v(r,\"x\",\"batchNorm\"),i=v(e,\"mean\",\"batchNorm\"),p=v(t,\"variance\",\"batchNorm\"),u;n!=null&&(u=v(n,\"scale\",\"batchNorm\"));let c;o!=null&&(c=v(o,\"offset\",\"batchNorm\")),$(i.rank===p.rank,()=>\"Batch normalization gradient requires mean and variance to have equal ranks.\"),$(c==null||i.rank===c.rank,()=>\"Batch normalization gradient requires mean and offset to have equal ranks.\"),$(u==null||i.rank===u.rank,()=>\"Batch normalization gradient requires mean and scale to have equal ranks.\");let m={x:av(a),scale:u,offset:c,mean:i,variance:p},d={varianceEpsilon:s},f=T.runKernel(sn,m,d);return W(f,a.shape)}var _i=N({batchNorm_:$W});function EW(r,e,t,o,n,s){let a=v(r,\"x\",\"batchNorm\"),i=v(e,\"mean\",\"batchNorm\"),p=v(t,\"variance\",\"batchNorm\"),u;n!=null&&(u=v(n,\"scale\",\"batchNorm\"));let c;return o!=null&&(c=v(o,\"offset\",\"batchNorm\")),$(a.rank===2,()=>`Error in batchNorm2D: x must be rank 2 but got rank ${a.rank}.`),$(i.rank===2||i.rank===1,()=>`Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank ${i.rank}.`),$(p.rank===2||p.rank===1,()=>`Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank ${p.rank}.`),u!=null&&$(u.rank===2||u.rank===1,()=>`Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank ${u.rank}.`),c!=null&&$(c.rank===2||c.rank===1,()=>`Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank ${c.rank}.`),_i(a,i,p,c,u,s)}var iv=N({batchNorm2d_:EW});function AW(r,e,t,o,n,s){let a=v(r,\"x\",\"batchNorm\"),i=v(e,\"mean\",\"batchNorm\"),p=v(t,\"variance\",\"batchNorm\"),u;n!=null&&(u=v(n,\"scale\",\"batchNorm\"));let c;return o!=null&&(c=v(o,\"offset\",\"batchNorm\")),$(a.rank===3,()=>`Error in batchNorm3D: x must be rank 3 but got rank ${a.rank}.`),$(i.rank===3||i.rank===1,()=>`Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank ${i.rank}.`),$(p.rank===3||p.rank===1,()=>`Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank ${p.rank}.`),u!=null&&$(u.rank===3||u.rank===1,()=>`Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank ${u.rank}.`),c!=null&&$(c.rank===3||c.rank===1,()=>`Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank ${c.rank}.`),_i(a,i,p,c,u,s)}var uv=N({batchNorm3d_:AW});function RW(r,e,t,o,n,s){let a=v(r,\"x\",\"batchNorm\"),i=v(e,\"mean\",\"batchNorm\"),p=v(t,\"variance\",\"batchNorm\"),u;n!=null&&(u=v(n,\"scale\",\"batchNorm\"));let c;return o!=null&&(c=v(o,\"offset\",\"batchNorm\")),$(a.rank===4,()=>`Error in batchNorm4D: x must be rank 4 but got rank ${a.rank}.`),$(i.rank===4||i.rank===1,()=>`Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank ${i.rank}.`),$(p.rank===4||p.rank===1,()=>`Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank ${p.rank}.`),u!=null&&$(u.rank===4||u.rank===1,()=>`Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank ${u.rank}.`),c!=null&&$(c.rank===4||c.rank===1,()=>`Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank ${c.rank}.`),_i(a,i,p,c,u,s)}var pv=N({batchNorm4d_:RW});function DW(r,e,t){let o=v(r,\"x\",\"bincount\"),n=v(e,\"weights\",\"bincount\");$(o.dtype===\"int32\",()=>`Error in bincount: input dtype must be int32, but got ${o.dtype}`),$(t>=0,()=>`size must be non-negative, but got ${t}.`),$(n.size===o.size||n.size===0,()=>`Error in bincount: weights must have the same size as input or0-length, but got input shape: ${o.shape}, weights shape: ${n.shape}.`);let s={x:o,weights:n},a={size:t};return T.runKernel(ti,s,a)}var Xm=N({bincount_:DW});function FW(r,e){let t=v(r,\"s0\",\"broadcastArgs\",\"int32\"),o=v(e,\"s1\",\"broadcastArgs\",\"int32\");if(t.rank!==1)throw new Error(`broadcastArgs(): first input must be a vector (rank=1). Has rank ${t.rank}`);if(o.rank!==1)throw new Error(`broadcastArgs(): second input must be a vector (rank=1). Has rank ${o.rank}`);let n={s0:t,s1:o};return T.runKernel(fp,n)}var cv=N({broadcastArgs_:FW});function OW(r,e){let t=v(r,\"broadcastTo\",\"x\"),o=t.shape;if(bt(e),e.lengtht.rank){let u=t.shape.slice();for(;u.length=0;u--)if(n[u]===e[u])s[u]=1;else if(t.shape[u]!==1)throw new Error(`broadcastTo(): [${o}] cannot be broadcast to [${e}].`);if(s.map((u,c)=>u>1?c:-1).filter(u=>u>=0).length===0)return Lr(t);let i={x:t},p={reps:s};return T.runKernel(to,i,p)}var $i=N({broadcastTo_:OW});function PW(r){let t={x:v(r,\"x\",\"ceil\",\"float32\")};return T.runKernel(Wo,t)}var lv=N({ceil_:PW});function Us(r,e,t){bt(r);let o={shape:r,value:e,dtype:t};return T.runKernel(ws,{},o)}function MW(r,e,t){let o=v(r,\"x\",\"clipByValue\");if($(e<=t,()=>`Error in clip: min (${e}) must be less than or equal to max (${t}).`),e===t)return Us(o.shape,e,o.dtype);let n={x:o},s={clipValueMin:e,clipValueMax:t};return T.runKernel(lo,n,s)}var mv=N({clipByValue_:MW});function LW(r){return xt(r,0)}var dv=N({concat1d_:LW});function BW(r,e){return xt(r,e)}var fv=N({concat2d_:BW});function VW(r,e){return xt(r,e)}var hv=N({concat3d_:VW});function zW(r,e){return xt(r,e)}var gv=N({concat4d_:zW});function WW(r,e,t,o,n=\"NHWC\",s=[1,1],a){let i=v(r,\"x\",\"conv2d\",\"float32\"),p=v(e,\"filter\",\"conv2d\",\"float32\"),u=i,c=!1;i.rank===3&&(c=!0,u=W(i,[1,i.shape[0],i.shape[1],i.shape[2]])),$(u.rank===4,()=>`Error in conv2d: input must be rank 4, but got rank ${u.rank}.`),$(p.rank===4,()=>`Error in conv2d: filter must be rank 4, but got rank ${p.rank}.`),Mt(\"conv2d\",o,a);let l=n===\"NHWC\"?u.shape[3]:u.shape[1];$(l===p.shape[2],()=>`Error in conv2d: depth of input (${l}) must match input depth for filter ${p.shape[2]}.`),$(mr(t,s),()=>`Error in conv2D: Either strides or dilations must be 1. Got strides ${t} and dilations '${s}'`),$(Vs(s),()=>\"Error in conv2D: Dilated rates should be larger than 0.\"),$(Vs(t),()=>\"Error in conv2D: Strides should be larger than 0.\");let m={x:u,filter:p},d={strides:t,pad:o,dataFormat:n,dilations:s,dimRoundingMode:a},f=T.runKernel(Uo,m,d);return c?W(f,[f.shape[1],f.shape[2],f.shape[3]]):f}var Ei=N({conv2d_:WW});function UW(r,e,t,o,n=\"NWC\",s=1,a){let i=v(r,\"x\",\"conv1d\"),p=v(e,\"filter\",\"conv1d\"),u=i,c=!1;i.rank===2&&(c=!0,u=W(i,[1,i.shape[0],i.shape[1]])),$(u.rank===3,()=>`Error in conv1d: input must be rank 3, but got rank ${u.rank}.`),$(p.rank===3,()=>`Error in conv1d: filter must be rank 3, but got rank ${p.rank}.`),Mt(\"conv1d\",o,a),$(u.shape[2]===p.shape[1],()=>`Error in conv1d: depth of input (${u.shape[2]}) must match input depth for filter ${p.shape[1]}.`),$(mr(t,s),()=>`Error in conv1D: Either stride or dilation must be 1. Got stride ${t} and dilation '${s}'`),$(Vs(s),()=>\"Error in conv1D: Dilated rates should be larger than 0.\"),$(Vs(t),()=>\"Error in conv1D: Stride should be larger than 0.\"),$(n===\"NWC\",()=>`Error in conv1d: got dataFormat of ${n} but only NWC is currently supported.`);let l=W(p,[1,p.shape[0],p.shape[1],p.shape[2]]),m=W(u,[u.shape[0],1,u.shape[1],u.shape[2]]),g=Ei(m,l,[1,t],o,\"NHWC\",[1,s],a);return c?W(g,[g.shape[2],g.shape[3]]):W(g,[g.shape[0],g.shape[2],g.shape[3]])}var xv=N({conv1d_:UW});function GW(r,e,t,o,n,s=\"NHWC\",a){$(r.length===e.rank,()=>`Length of inShape (${r.length}) and rank of dy (${e.rank}) must match`);let i=r,p=e,u=!1;e.rank===3&&(u=!0,p=W(e,[1,e.shape[0],e.shape[1],e.shape[2]]),i=[1,r[0],r[1],r[2]]),$(i.length===4,()=>`Error in conv2dDerInput: inShape must be length 4, but got length ${i.length}.`),$(p.rank===4,()=>`Error in conv2dDerInput: dy must be rank 4, but got rank ${p.rank}`),$(t.rank===4,()=>`Error in conv2dDerInput: filter must be rank 4, but got rank ${t.rank}`);let c=s===\"NHWC\"?i[3]:i[1],l=s===\"NHWC\"?p.shape[3]:p.shape[1];$(c===t.shape[2],()=>`Error in conv2dDerInput: depth of input (${c}) must match input depth for filter ${t.shape[2]}.`),$(l===t.shape[3],()=>`Error in conv2dDerInput: depth of output (${l}) must match output depth for filter ${t.shape[3]}.`),Mt(\"conv2dDerInput\",n,a);let m={dy:p,filter:t},d={strides:o,pad:n,dataFormat:s,dimRoundingMode:a,inputShape:i},f=T.runKernel(Go,m,d);return u?W(f,[f.shape[1],f.shape[2],f.shape[3]]):f}var Ym=N({conv2DBackpropInput_:GW});function HW(r,e,t,o,n,s){let a=v(r,\"x\",\"conv2dTranspose\"),i=v(e,\"filter\",\"conv2dTranspose\");return Ym(t,a,i,o,n,\"NHWC\",s)}var yv=N({conv2dTranspose_:HW});function KW(r,e,t,o,n=\"NDHWC\",s=[1,1,1]){let a=v(r,\"x\",\"conv3d\"),i=v(e,\"filter\",\"conv3d\"),p=a,u=!1;a.rank===4&&(u=!0,p=W(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]])),$(p.rank===5,()=>`Error in conv3d: input must be rank 5, but got rank ${p.rank}.`),$(i.rank===5,()=>`Error in conv3d: filter must be rank 5, but got rank ${i.rank}.`),$(p.shape[4]===i.shape[3],()=>`Error in conv3d: depth of input (${p.shape[4]}) must match input depth for filter ${i.shape[3]}.`),$(mr(t,s),()=>`Error in conv3D: Either strides or dilations must be 1. Got strides ${t} and dilations '${s}'`),$(n===\"NDHWC\",()=>`Error in conv3d: got dataFormat of ${n} but only NDHWC is currently supported.`),$(Vs(s),()=>\"Error in conv3D: Dilated rates should be larger than 0.\"),$(Vs(t),()=>\"Error in conv3D: Strides should be larger than 0.\");let c={x:p,filter:i},l={strides:t,pad:o,dataFormat:n,dilations:s},m=T.runKernel(gp,c,l);return u?W(m,[m.shape[1],m.shape[2],m.shape[3],m.shape[4]]):m}var bv=N({conv3d_:KW});function qW(r,e,t,o,n){$(r.length===e.rank,()=>`Length of inShape (${r.length}) and rank of dy (${e.rank}) must match`);let s=r,a=e,i=!1;e.rank===4&&(i=!0,a=W(e,[1,e.shape[0],e.shape[1],e.shape[2],e.shape[3]]),s=[1,r[0],r[1],r[2],r[3]]);let p=s[4],u=a.shape[4];$(s.length===5,()=>`Error in conv3dDerInput: inShape must be length 5, but got length ${s.length}.`),$(a.rank===5,()=>`Error in conv3dDerInput: dy must be rank 5, but got rank ${a.rank}`),$(t.rank===5,()=>`Error in conv3dDerInput: filter must be rank 5, but got rank ${t.rank}`),$(p===t.shape[3],()=>`Error in conv3dDerInput: depth of input (${p}) must match input depth for filter ${t.shape[3]}.`),$(u===t.shape[4],()=>`Error in conv3dDerInput: depth of output (${u}) must match output depth for filter ${t.shape[4]}.`);let c={dy:a,filter:t},l={pad:n,strides:o,inputShape:s},m=T.runKernel(xp,c,l);return i?W(m,[m.shape[1],m.shape[2],m.shape[3],m.shape[4]]):m}var Cv=N({conv3DBackpropInput_:qW});function jW(r,e,t,o,n){let s=v(r,\"x\",\"conv3dTranspose\"),a=v(e,\"filter\",\"conv3dTranspose\");return Cv(t,s,a,o,n)}var Sv=N({conv3dTranspose_:jW});function XW(r){let t={x:v(r,\"x\",\"cos\",\"float32\")};return T.runKernel(Ho,t)}var wv=N({cos_:XW});function YW(r){let t={x:v(r,\"x\",\"cosh\",\"float32\")};return T.runKernel(Ko,t)}var Iv=N({cosh_:YW});function QW(r,e=0,t=!1,o=!1){let s={x:v(r,\"x\",\"cumprod\")},a={axis:e,exclusive:t,reverse:o};return T.runKernel(qo,s,a)}var vv=N({cumprod_:QW});function ZW(r,e=0,t=!1,o=!1){let s={x:v(r,\"x\",\"cumsum\")},a={axis:e,exclusive:t,reverse:o};return T.runKernel(jo,s,a)}var kv=N({cumsum_:ZW});function JW(r,e,t,o=!1){let n=v(r,\"x\",\"denseBincount\"),s=v(e,\"weights\",\"denseBincount\");$(n.dtype===\"int32\",()=>`Error in denseBincount: input dtype must be int32, but got ${n.dtype}`),$(n.rank<=2,()=>`Error in denseBincount: input must be at most rank 2, but got rank ${n.rank}.`),$(t>=0,()=>`size must be non-negative, but got ${t}.`),$(s.size===n.size||s.size===0,()=>`Error in denseBincount: weights must have the same shape as x or 0-length, but got x shape: ${n.shape}, weights shape: ${s.shape}.`);let a={x:n,weights:s},i={size:t,binaryOutput:o};return T.runKernel(ni,a,i)}var Nv=N({denseBincount_:JW});function eU(r,e,t=\"NHWC\"){let o=v(r,\"x\",\"depthToSpace\",\"float32\"),n=t===\"NHWC\"?o.shape[1]:o.shape[2],s=t===\"NHWC\"?o.shape[2]:o.shape[3],a=t===\"NHWC\"?o.shape[3]:o.shape[1];$(e>1,()=>`blockSize should be > 1 for depthToSpace, but was: ${e}`),$(n*e>=0,()=>`Negative dimension size caused by overflow when multiplying\n ${n} and ${e} for depthToSpace with input shape\n ${o.shape}`),$(s*e>=0,()=>`Negative dimension size caused by overflow when multiplying\n ${s} and ${e} for depthToSpace with input shape\n ${o.shape}`),$(a%(e*e)===0,()=>`Dimension size must be evenly divisible by ${e*e} but is ${a} for depthToSpace with input shape ${o.shape}`);let i={x:o},p={blockSize:e,dataFormat:t};return T.runKernel(Yo,i,p)}var Tv=N({depthToSpace_:eU});function tU(r,e,t,o,n=\"NHWC\",s=[1,1],a){let i=v(r,\"x\",\"depthwiseConv2d\",\"float32\"),p=v(e,\"filter\",\"depthwiseConv2d\",\"float32\"),u=i,c=!1;i.rank===3&&(c=!0,u=W(i,[1,i.shape[0],i.shape[1],i.shape[2]])),$(u.rank===4,()=>`Error in depthwiseConv2d: input must be rank 4, but got rank ${u.rank}.`),$(p.rank===4,()=>`Error in depthwiseConv2d: filter must be rank 4, but got rank ${p.rank}.`);let l=n===\"NHWC\"?u.shape[3]:u.shape[1];$(l===p.shape[2],()=>`Error in depthwiseConv2d: number of input channels (${l}) must match the inChannels dimension in filter ${p.shape[2]}.`),Mt(\"depthwiseConv2d\",o,a);let m={x:u,filter:p},d={strides:t,pad:o,dataFormat:n,dilations:s,dimRoundingMode:a},f=T.runKernel(Qo,m,d);return c?W(f,[f.shape[1],f.shape[2],f.shape[3]]):f}var Bp=N({depthwiseConv2d_:tU});function rU(r){let t={x:v(r,\"x\",\"diag\")};return T.runKernel(si,t)}var _v=N({diag_:rU});function oU(r,e,t,o,n=[1,1],s=\"NHWC\"){let a=v(r,\"x\",\"dilation2d\"),i=v(e,\"filter\",\"dilation2d\");$(a.rank===3||a.rank===4,()=>`Error in dilation2d: input must be rank 3 or 4, but got rank ${a.rank}.`),$(i.rank===3,()=>`Error in dilation2d: filter must be rank 3, but got rank ${i.rank}.`),$(s===\"NHWC\",()=>`Error in dilation2d: Only NHWC is currently supported, but got dataFormat of ${s}`);let p=a,u=!1;a.rank===3&&(p=W(a,[1,a.shape[0],a.shape[1],a.shape[2]]),u=!0),$(p.shape[3]===i.shape[2],()=>`Error in dilation2d: input and filter must have the same depth: ${p.shape[3]} vs ${i.shape[2]}`);let c={x:p,filter:i},l={strides:t,pad:o,dilations:n},m=T.runKernel(ai,c,l);return u?W(m,[m.shape[1],m.shape[2],m.shape[3]]):m}var $v=N({dilation2d_:oU});var yr={};Ge(yr,{assertAndGetBroadcastShape:()=>Je,getBroadcastDims:()=>Ev,getReductionAxes:()=>Qm});function Ev(r,e){let t=r.length,o=[];for(let n=0;n1&&a===1&&o.unshift(s)}return o}function Qm(r,e){let t=[];for(let o=0;o1)&&t.unshift(s)}return t}function Je(r,e){let t=[],o=Math.max(r.length,e.length);for(let n=0;n`Error in dot: inputs must all be rank 1 or 2, but got ranks ${t.rank} and ${o.rank}.`);let n=t.rank===1?t.size:t.shape[1],s=o.rank===1?o.size:o.shape[0];if($(n===s,()=>`Error in dot: inner dimensions of inputs must match, but got ${n} and ${s}.`),t.rank===1&&o.rank===1){let a=W(t,[1,-1]),i=W(o,[-1,1]),p=Xe(a,i);return W(p,[])}else if(t.rank===1&&o.rank===2){let a=W(t,[1,-1]),i=W(o,[o.shape[0],o.shape[1]]),p=Xe(a,i);return W(p,[p.size])}else if(t.rank===2&&o.rank===1){let a=W(o,[-1,1]),i=Xe(t,a);return W(i,[i.size])}else{let a=W(o,[o.shape[0],o.shape[1]]);return Xe(t,a)}}var Rv=N({dot_:uU});function pU(r,...e){let t=e.map((n,s)=>v(n,`tensors${s}`,\"einsum\")),o={equation:r};return T.runKernel(ii,t,o)}var Dv=N({einsum_:pU});function cU(r){let t={x:v(r,\"x\",\"elu\",\"float32\")};return T.runKernel(Jo,t)}var Jm=N({elu_:cU});function lU(r){let e=v(r,\"x\",\"erf\");$(e.dtype===\"int32\"||e.dtype===\"float32\",()=>\"Input dtype must be `int32` or `float32`.\"),e.dtype===\"int32\"&&(e=je(e,\"float32\"));let t={x:e};return T.runKernel(da,t)}var Fv=N({erf_:lU});function uC(r,e){for(let t=0;tr[s]);return[t,n]}function Ea(r,e){let t=e.map(o=>1);return Ov(r,t,e)}function dU(r,e,t){$(uC(e,t),()=>`${r} supports only inner-most axes for now. Got axes ${e} and rank-${t} input.`)}function fU(r,e){if(uC(r,e))return null;let t=[];for(let o=0;ot.push(o)),t}function hU(r){return r.map((e,t)=>[t,e]).sort((e,t)=>e[1]-t[1]).map(e=>e[0])}function gU(r,e){let t=[];for(let o=e-r;o\"Axis must be <= rank of the tensor\");let o={input:t},n={dim:e};return T.runKernel(Ss,o,n)}var Ra=N({expandDims_:TU});function _U(r){let t={x:v(r,\"x\",\"expm1\")};return T.runKernel(fa,t)}var Lv=N({expm1_:_U});function $U(r,e){let t=v(r,\"x\",\"tile\",\"string_or_numeric\");$(t.rank===e.length,()=>`Error in transpose: rank of input ${t.rank} must match length of reps ${e}.`);let o={x:t},n={reps:e};return T.runKernel(to,o,n)}var Ai=N({tile_:$U});function EU(r,e,t,o=\"float32\"){e==null&&(e=r);let n=le([r,e],o),s=r<=e?r:e;for(let i=0;i`Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank ${s.rank}.`),$(sa(e),()=>`Error in localResponseNormalization: depthRadius must be an integer but got depthRadius ${e}.`);let a=s,i=!1;s.rank===3&&(i=!0,a=W(s,[1,s.shape[0],s.shape[1],s.shape[2]]));let p={x:a},u={depthRadius:e,bias:t,alpha:o,beta:n},c=T.runKernel(mi,p,u);return i?W(c,[c.shape[1],c.shape[2],c.shape[3]]):c}var Gv=N({localResponseNormalization_:WU});function UU(r){let t={x:v(r,\"x\",\"log\",\"float32\")};return T.runKernel(fn,t)}var Da=N({log_:UU});function GU(r){let t={x:v(r,\"x\",\"log1p\")};return T.runKernel(xa,t)}var sd=N({log1p_:GU});function HU(r){return $(gs(r),()=>\"The f passed in grad(f) must be a function\"),(e,t)=>{let o=v(e,\"x\",\"tf.grad\",\"string_or_numeric\"),n=t!=null?v(t,\"dy\",\"tf.grad\"):null;return T.tidy(()=>{let{value:s,grads:a}=T.gradients(()=>r(o),[o],n);return n!=null&>(s.shape,n.shape,\"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)\"),ad(a),a[0]})}}function KU(r){return $(gs(r),()=>\"The f passed in grads(f) must be a function\"),(e,t)=>{$(Array.isArray(e),()=>\"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s\");let o=_a(e,\"args\",\"tf.grads\",\"string_or_numeric\"),n=t!=null?v(t,\"dy\",\"tf.grads\"):null;return T.tidy(()=>{let{value:s,grads:a}=T.gradients(()=>r(...o),o,n);return n!=null&>(s.shape,n.shape,\"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])\"),ad(a),a})}}function qU(r){return $(gs(r),()=>\"The f passed in valueAndGrad(f) must be a function\"),(e,t)=>{$(e instanceof it,()=>\"The x passed in valueAndGrad(f)(x) must be a tensor\"),$(t==null||t instanceof it,()=>\"The dy passed in valueAndGrad(f)(x, dy) must be a tensor\");let{grads:o,value:n}=T.gradients(()=>r(e),[e],t);return ad(o),{grad:o[0],value:n}}}function jU(r){return $(gs(r),()=>\"The f passed in valueAndGrads(f) must be a function\"),(e,t)=>{$(Array.isArray(e)&&e.every(n=>n instanceof it),()=>\"The args passed in valueAndGrads(f)(args) must be array of tensors\"),$(t==null||t instanceof it,()=>\"The dy passed in valueAndGrads(f)(args, dy) must be a tensor\");let o=T.gradients(()=>r(...e),e,t);return t!=null&>(o.value.shape,t.shape,\"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])\"),ad(o.grads),o}}function pC(r,e){$(gs(r),()=>\"The f passed in variableGrads(f) must be a function\"),$(e==null||Array.isArray(e)&&e.every(u=>u instanceof Na),()=>\"The varList passed in variableGrads(f, varList) must be an array of variables\");let t=e!=null;if(!t){e=[];for(let u in T.registeredVariables)e.push(T.registeredVariables[u])}let o=t?e.filter(u=>!u.trainable):null,n=e.length;e=e.filter(u=>u.trainable),$(e.length>0,()=>`variableGrads() expects at least one of the input variables to be trainable, but none of the ${n} variables is trainable.`);let s=!0,{value:a,grads:i}=T.gradients(r,e,null,s);$(i.some(u=>u!=null),()=>\"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize().\"),$(a.rank===0,()=>`The f passed in variableGrads(f) must return a scalar, but it returned a rank-${a.rank} tensor`);let p={};return e.forEach((u,c)=>{i[c]!=null&&(p[u.name]=i[c])}),o!=null&&o.forEach(u=>p[u.name]=null),{value:a,grads:p}}function br(r){return T.customGrad(r)}function ad(r){if(r.filter(t=>t==null).length>0)throw new Error(`Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.`)}function XU(r){let t={x:v(r,\"x\",\"neg\")};return T.runKernel(vs,t)}var Cr=N({neg_:XU});function YU(r){let t={x:v(r,\"x\",\"softplus\")};return T.runKernel(Ia,t)}var id=N({softplus_:YU});function QU(r){let e=v(r,\"x\",\"logSigmoid\");return br(o=>({value:Cr(id(Cr(o))),gradFunc:a=>ne(a,Ws(Cr(o)))}))(e)}var Hv=N({logSigmoid_:QU});function ZU(r,e){let t=v(r,\"a\",\"sub\"),o=v(e,\"b\",\"sub\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(Yn,n)}var ke=N({sub_:ZU});function JU(r,e=-1){let t=v(r,\"logits\",\"logSoftmax\");if(e===-1&&(e=t.rank-1),e!==t.rank-1)throw Error(`Log Softmax along a non-last dimension is not yet supported. Logits was rank ${t.rank} and axis was ${e}`);return br((n,s)=>{let i=Gs(n,e,!0),p=ke(n,i),u=ke(je(p,\"float32\"),Da(et(So(p),e,!0)));return s([u]),{value:u,gradFunc:(l,m)=>{let[d]=m,f=!0,h=So(d);return ke(l,ne(et(l,e,f),h))}}})(t)}var Kv=N({logSoftmax_:JU});function e4(r,e=null,t=!1){let o=v(r,\"x\",\"logSumExp\"),n=Ja(e,o.shape),s=Gs(o,n,!0),a=ke(o,s),i=So(a),p=et(i,n),u=Da(p),c=be(W(s,u.shape),u);if(t){let l=Ea(c.shape,n);return W(c,l)}return c}var ud=N({logSumExp_:e4});function t4(r,e){let t=v(r,\"a\",\"logicalAnd\",\"bool\"),o=v(e,\"b\",\"logicalAnd\",\"bool\");Je(t.shape,o.shape);let n={a:t,b:o};return T.runKernel(hn,n)}var pu=N({logicalAnd_:t4});function r4(r){let t={x:v(r,\"x\",\"logicalNot\",\"bool\")};return T.runKernel(gn,t)}var pd=N({logicalNot_:r4});function o4(r,e){let t=v(r,\"a\",\"logicalOr\",\"bool\"),o=v(e,\"b\",\"logicalOr\",\"bool\");Je(t.shape,o.shape);let n={a:t,b:o};return T.runKernel(xn,n)}var cd=N({logicalOr_:o4});function n4(r,e){let t=v(r,\"a\",\"logicalXor\",\"bool\"),o=v(e,\"b\",\"logicalXor\",\"bool\");return Je(t.shape,o.shape),pu(cd(r,e),pd(pu(r,e)))}var qv=N({logicalXor_:n4});var ld=2147483648;function s4(r,e,t=\"left\"){let o=v(r,\"sortedSequence\",\"searchSorted\"),n=v(e,\"values\",\"searchSorted\"),s=o.shape[o.shape.length-1],a=n.shape[n.shape.length-1],i=W(o,[-1,s]),p=W(n,[-1,a]);if(i.rank<2)throw new Error(\"Sorted input argument must be at least 2-dimensional\");if(i.shape[0]!==p.shape[0])throw new Error(\"Leading dimension of 'sortedSequence' and 'values' must match.\");if(We(p.shape)>=ld)throw new Error(`values tensor size must less than ${ld}`);if(i.shape[1]>=ld)throw new Error(`trailing dim_size must less than ${ld} for int32 output type, was ${i.shape[1]}`);let u={sortedSequence:i,values:p},c={side:t};return T.runKernel(fi,u,c)}var ol=N({searchSorted_:s4});function jv(r,e){return ol(r,e,\"left\")}function a4(r,e,t,o,n){let s=v(r,\"x\",\"maxPool\"),a=1,i=s,p=!1;s.rank===3&&(p=!0,i=W(s,[1,s.shape[0],s.shape[1],s.shape[2]])),$(i.rank===4,()=>`Error in maxPool: input must be rank 4 but got rank ${i.rank}.`),$(mr(t,a),()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${t} and dilations '${a}'`),Mt(\"maxPool\",o,n);let u={x:i},c={filterSize:e,strides:t,pad:o,dimRoundingMode:n},l=T.runKernel(Cn,u,c);return p?W(l,[l.shape[1],l.shape[2],l.shape[3]]):l}var md=N({maxPool_:a4});function i4(r,e=[1,1,1],t,o,n,s=\"NDHWC\"){let a=v(r,\"x\",\"maxPool3d\"),i=a,p=!1;a.rank===4&&(p=!0,i=W(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]])),$(i.rank===5,()=>`Error in maxPool3d: x must be rank 5 but got rank ${i.rank}.`),$(s===\"NDHWC\",()=>`Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of ${s}`),Mt(\"maxPool3d\",o,n);let u={x:i},c={filterSize:e,strides:t,pad:o,dimRoundingMode:n,dataFormat:s},l=T.runKernel(Cp,u,c);return p?W(l,[l.shape[1],l.shape[2],l.shape[3],l.shape[4]]):l}var Xv=N({maxPool3d_:i4});function u4(r,e,t,o,n=!1){let a={x:v(r,\"x\",\"maxPoolWithArgmax\")},i={filterSize:e,strides:t,pad:o,includeBatchInIndex:n},p=T.runKernel(Sp,a,i);return{result:p[0],indexes:p[1]}}var Yv=N({maxPoolWithArgmax_:u4});function p4(r,e){let t=v(r,\"a\",\"maximum\"),o=v(e,\"b\",\"maximum\");[t,o]=De(t,o),t.dtype===\"bool\"&&(t=je(t,\"int32\"),o=je(o,\"int32\")),Je(t.shape,o.shape);let n={a:t,b:o};return T.runKernel(bn,n)}var dd=N({maximum_:p4});function c4(r,e=null,t=!1){let n={x:v(r,\"x\",\"mean\")},s={axis:e,keepDims:t};return T.runKernel(Sn,n,s)}var cu=N({mean_:c4});function Br(r,e=\"float32\"){if(bt(r),e===\"complex64\"){let o=Br(r,\"float32\"),n=Br(r,\"float32\");return Tr(o,n)}let t=lp(We(r),e);return T.makeTensor(t,r,e)}function Hs(r,e=\"float32\"){if(bt(r),e===\"complex64\"){let o=Hs(r,\"float32\"),n=Br(r,\"float32\");return Tr(o,n)}let t=Wc(We(r),e);return T.makeTensor(t,r,e)}function Qv(r,e,{indexing:t=\"xy\"}={}){if(t!==\"xy\"&&t!==\"ij\")throw new TypeError(`${t} is not a valid third argument to meshgrid`);if(r===void 0)return[];let o=v(r,\"x\",\"meshgrid\",r instanceof it?r.dtype:\"float32\");if(e===void 0)return[o];let n=v(e,\"y\",\"meshgrid\",e instanceof it?e.dtype:\"float32\"),s=We(o.shape),a=We(n.shape);return t===\"xy\"?(o=W(o,[1,-1]),n=W(n,[-1,1]),[Xe(Hs([a,1],o.dtype),o),Xe(n,Hs([1,s],n.dtype))]):(o=W(o,[-1,1]),n=W(n,[1,-1]),[Xe(o,Hs([1,a],o.dtype)),Xe(Hs([s,1],n.dtype),n)])}function l4(r,e){let t=v(r,\"a\",\"minimum\"),o=v(e,\"b\",\"minimum\");[t,o]=De(t,o),t.dtype===\"bool\"&&(t=je(t,\"int32\"),o=je(o,\"int32\")),Je(t.shape,o.shape);let n={a:t,b:o};return T.runKernel(In,n)}var fd=N({minimum_:l4});function m4(r,e,t){$(t===\"reflect\"||t===\"symmetric\",()=>`Invalid mode. Mode must be either reflect or symmetric. Got ${t}.`);let o=v(r,\"x\",\"mirrorPad\");if(o.rank===0)throw new Error(\"mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad\");$(e.length===o.rank,()=>`Padding doesn't match input. Must be ${o.rank}. Got ${e.length}.`);let n=t===\"reflect\"?1:0;for(let i=0;i\"Invalid number of paddings. Must be length of 2 each.\"),$(e[i][0]>=0&&e[i][0]<=o.shape[i]-n&&e[i][1]>=0&&e[i][1]<=o.shape[i]-n,()=>`Padding in dimension ${i} cannot be greater than or equal to ${o.shape[i]-n} or less than 0 for input of shape ${o.shape}`);let s={paddings:e,mode:t},a={x:o};return T.runKernel(vn,a,s)}var Zv=N({mirrorPad_:m4});function d4(r,e){let t=v(r,\"a\",\"mod\"),o=v(e,\"b\",\"mod\");[t,o]=De(t,o);let n={a:t,b:o};return T.runKernel(ya,n)}var Jv=N({mod_:d4});function f4(r,e=null,t=!1){r=v(r,\"x\",\"moments\");let o=Ja(e,r.shape),n=cu(r,o,t),s=n.shape;t||(s=Ea(n.shape,o));let a=Qt(ke(je(r,\"float32\"),W(n,s))),i=cu(a,o,t);return{mean:n,variance:i}}var ek=N({moments_:f4});function h4(r,e,t,o){let n=v(e,\"data\",\"multiRNNCell\"),s=_a(t,\"c\",\"multiRNNCell\"),a=_a(o,\"h\",\"multiRNNCell\"),i=n,p=[];for(let l=0;l2)throw new Error(`Rank of probabilities must be 1 or 2, but is ${a}`);t=t||Math.random();let p={logits:a===1?W(n,[1,-1]):n},u={numSamples:e,seed:t,normalized:o},c=T.runKernel(wp,p,u);return a===1?W(c,[c.size]):c}var rk=N({multinomial_:g4});function x4(r,e){let t=v(r,\"a\",\"notEqual\",\"string_or_numeric\"),o=v(e,\"b\",\"notEqual\",\"string_or_numeric\");[t,o]=De(t,o),Je(t.shape,o.shape);let n={a:t,b:o};return T.runKernel(Nn,n)}var hd=N({notEqual_:x4});function y4(r,e,t=1,o=0,n=\"int32\"){if(e<2)throw new Error(`Error in oneHot: depth must be >=2, but it is ${e}`);let a={indices:v(r,\"indices\",\"oneHot\",\"int32\")},i={dtype:n,depth:e,onValue:t,offValue:o};return T.runKernel($n,a,i)}var nl=N({oneHot_:y4});function b4(r){let t={x:v(r,\"x\",\"onesLike\")};return T.runKernel(ks,t)}var ok=N({onesLike_:b4});function C4(r,e){let t=v(r,\"v1\",\"outerProduct\"),o=v(e,\"v2\",\"outerProduct\");$(t.rank===1&&o.rank===1,()=>`Error in outerProduct: inputs must be rank 1, but got ranks ${t.rank} and ${o.rank}.`);let n=W(t,[-1,1]),s=W(o,[1,-1]);return Xe(n,s)}var nk=N({outerProduct_:C4});function S4(r,e,t=0){let o=v(r,\"x\",\"pad\");if(o.rank===0)throw new Error(\"pad(scalar) is not defined. Pass non-scalar to pad\");let n={paddings:e,constantValue:t},s={x:o};return T.runKernel(En,s,n)}var Ks=N({pad_:S4});function w4(r,e,t=0){return $(e.length===2,()=>\"Invalid number of paddings. Must be length of 2.\"),Ks(r,[e],t)}var sk=N({pad1d_:w4});function I4(r,e,t=0){return $(e.length===2&&e[0].length===2&&e[1].length===2,()=>\"Invalid number of paddings. Must be length of 2 each.\"),Ks(r,e,t)}var ak=N({pad2d_:I4});function v4(r,e,t=0){return $(e.length===3&&e[0].length===2&&e[1].length===2&&e[2].length===2,()=>\"Invalid number of paddings. Must be length of 2 each.\"),Ks(r,e,t)}var ik=N({pad3d_:v4});function k4(r,e,t=0){return $(e.length===4&&e[0].length===2&&e[1].length===2&&e[2].length===2&&e[3].length===2,()=>\"Invalid number of paddings. Must be length of 2 each.\"),Ks(r,e,t)}var uk=N({pad4d_:k4});function N4(r,e,t){let o=v(r,\"x\",\"spaceToBatchND\");$(o.rank>=1+e.length,()=>`input rank ${o.rank} should be > than [blockShape] ${e.length}`),$(t.length===e.length,()=>`paddings.shape[0] ${t.length} must be equal to [blockShape] ${e.length}`),$(o.shape.reduce((a,i,p)=>p>0&&p<=e.length?a&&(i+t[p-1][0]+t[p-1][1])%e[p-1]===0:a,!0),()=>`input spatial dimensions ${o.shape.slice(1)} with paddings ${t.toString()} must be divisible by blockShapes ${e.toString()}`);let n={x:o},s={blockShape:e,paddings:t};return T.runKernel(As,n,s)}var gd=N({spaceToBatchND_:N4});function T4(r,e,t,o,n,s,a){n==null&&(n=[1,1]),s==null&&(s=1),o===0&&(o=\"valid\");let i=v(r,\"x\",\"maxPool\"),p=i,u=!1;i.rank===3&&(u=!0,p=W(i,[1,i.shape[0],i.shape[1],i.shape[2]])),$(mr(s,n),()=>`Error in pool: Either strides or dilations must be 1. Got strides ${s} and dilations '${n}'`);let c=aC(p.shape,e,s,n,o),l=[c.dilationHeight,c.dilationWidth],m;o===\"same\"?m=$4([c.filterHeight,c.filterWidth],l):m=[[0,0],[0,0]];let d=l[0]===1&&l[1]===1,[f,h]=_4([c.inHeight,c.inWidth],l,m),g=d?o:\"valid\",x=d?p:gd(p,l,f),C=(t===\"avg\"?()=>qm(x,e,s,g,a):()=>md(x,e,s,g,a))(),w=d?C:jm(C,l,h);return u?W(w,[w.shape[1],w.shape[2],w.shape[3]]):w}function _4(r,e,t){let o=t.map(c=>c[0]),n=t.map(c=>c[1]),s=r.concat(o,n),a=e.map((c,l)=>(c-s[l]%c)%c),i=n.map((c,l)=>c+a[l]),p=e.map((c,l)=>[o[l],i[l]]),u=e.map((c,l)=>[0,a[l]]);return[p,u]}function $4(r,e){let o=r.map((a,i)=>a+(a-1)*(e[i]-1)).map(a=>a-1),n=o.map(a=>Math.floor(a/2)),s=o.map((a,i)=>a-n[i]);return o.map((a,i)=>[n[i],s[i]])}var pk=N({pool_:T4});function E4(r,e){let t=v(r,\"x\",\"prelu\"),o=v(e,\"alpha\",\"prelu\"),n={x:t,alpha:o};return T.runKernel(Rn,n)}var xd=N({prelu_:E4});function A4(r,e=null,t=!1){let o=v(r,\"x\",\"prod\");o.dtype===\"bool\"&&(o=je(o,\"int32\"));let n={x:o},s={axis:e,keepDims:t};return T.runKernel(Dn,n,s)}var ck=N({prod_:A4});function R4(r,e,t,o){let n=r.map((c,l)=>v(c,`tensors${l}`,\"raggedGather\",\"int32\")),s=v(e,\"paramsDenseValues\",\"raggedGather\"),a=v(t,\"indices\",\"raggedGather\",\"int32\"),i={paramsNestedSplits:n,paramsDenseValues:s,indices:a},p={outputRaggedRank:o},u=T.runKernel(Ip,i,p);return{outputNestedSplits:u.slice(0,u.length-1),outputDenseValues:u[u.length-1]}}var lk=N({raggedGather_:R4});function D4(r,e,t){let o=v(r,\"starts\",\"raggedRange\"),n=v(e,\"limits\",\"raggedRange\",o.dtype),s=v(t,\"deltas\",\"raggedRange\",o.dtype),a={starts:o,limits:n,deltas:s},i=T.runKernel(vp,a);return{rtNestedSplits:i[0],rtDenseValues:i[1]}}var mk=N({raggedRange_:D4});function F4(r,e,t,o,n){let s=v(r,\"shape\",\"raggedTensorToTensor\",\"int32\"),a=v(e,\"values\",\"raggedTensorToTensor\"),i=v(t,\"defaultValue\",\"raggedTensorToTensor\",a.dtype),p=o.map((l,m)=>v(l,`tensors${m}`,\"raggedTensorToTensor\",\"int32\")),u={shape:s,values:a,defaultValue:i,rowPartitionTensors:p},c={rowPartitionTypes:n};return T.runKernel(kp,u,c)}var dk=N({raggedTensorToTensor_:F4});function O4(r,e,t){bt(r);let o=We(r),n=null;if(t==null||t===\"float32\")n=new Float32Array(o);else if(t===\"int32\")n=new Int32Array(o);else if(t===\"bool\")n=new Uint8Array(o);else throw new Error(`Unknown data type ${t}`);for(let s=0;sAk,createVideoElement:()=>j4,encodeStrings:()=>Dk,expectArrayBuffersEqual:()=>q4,expectArraysClose:()=>U4,expectArraysEqual:()=>H4,expectNumbersClose:()=>Rk,expectPromiseToFail:()=>G4,expectValuesInRange:()=>K4,play:()=>X4,testEpsilon:()=>bd});var W4=.001,Ak=.1;function U4(r,e,t){return t==null&&(t=bd()),xC(r,e,(o,n)=>yC(o,n,t))}function bd(){return T.backend.floatPrecision()===32?W4:Ak}function xC(r,e,t){let o=!0;if((Bt(r)||Bt(e))&&(o=!1),Bt(r)&&Bt(e)&&(o=!0),o){let a=r.constructor.name,i=e.constructor.name;if(a!==i)throw new Error(`Arrays are of different type. Actual: ${a}. Expected: ${i}`)}if(Array.isArray(r)&&Array.isArray(e)){let a=or(r),i=or(e);if(!Or(a,i))throw new Error(`Arrays have different shapes. Actual: [${a}]. Expected: [${i}]`)}let n=Bt(r)?r:os(r),s=Bt(e)?e:os(e);if(n.length!==s.length)throw new Error(`Arrays have different lengths actual: ${n.length} vs expected: ${s.length}.\nActual: ${n}.\nExpected: ${s}.`);for(let a=0;ae.fail(),()=>e()),typeof expect!=\"undefined\"&&expect().nothing()}function H4(r,e){let t=typeof e==\"string\"||typeof e==\"number\"||typeof e==\"boolean\"?[e]:e;return Oo(r)||Oo(r[0])||Oo(e)||Oo(e[0])?xC(r,t,(o,n)=>o==n):xC(r,e,(o,n)=>yC(o,n,0))}function Rk(r,e,t){if(t==null&&(t=bd()),!yC(r,e,t))throw new Error(`Numbers differ: actual === ${r}, expected === ${e}`);typeof expect!=\"undefined\"&&expect().nothing()}function yC(r,e,t){return!isFinite(r)&&!isFinite(e)?!0:!(isNaN(r)||isNaN(e)||Math.abs(r-e)>t)}function K4(r,e,t){for(let o=0;ot)throw new Error(`Value out of range:${r[o]} low: ${e}, high: ${t}`)}function q4(r,e){let t=new Float32Array(r),o=new Float32Array(e);if(t.length!==o.length)throw new Error(`Expected ArrayBuffer to be of length ${o.length}, but it was ${t.length}`);for(let n=0;n{e.addEventListener(\"loadeddata\",o=>t(e)),e.load()})}async function X4(r){await r.play(),\"requestVideoFrameCallback\"in r&&await new Promise(e=>{r.requestVideoFrameCallback(e)})}var mu=class{constructor(e,t,o,n,s){this.mean=e,this.stdDev=t,this.dtype=o,this.nextVal=NaN,this.truncated=n,this.truncated&&(this.upper=this.mean+this.stdDev*2,this.lower=this.mean-this.stdDev*2);let a=s||Math.random();this.random=wd.alea(a.toString())}nextValue(){if(!isNaN(this.nextVal)){let n=this.nextVal;return this.nextVal=NaN,n}let e,t,o=!1;for(;!o;){let n,s,a;do n=2*this.random()-1,s=2*this.random()-1,a=n*n+s*s;while(a>=1||a===0);let i=Math.sqrt(-2*Math.log(a)/a);e=this.mean+this.stdDev*n*i,t=this.mean+this.stdDev*s*i,(!this.truncated||this.isValidTruncated(e))&&(o=!0)}return(!this.truncated||this.isValidTruncated(t))&&(this.nextVal=this.convertValue(t)),this.convertValue(e)}convertValue(e){return this.dtype==null||this.dtype===\"float32\"?e:Math.round(e)}isValidTruncated(e){return e<=this.upper&&e>=this.lower}},Cd=class{constructor(e,t,o,n){this.alpha=e,this.beta=1/t,this.dtype=o;let s=n||Math.random();this.randu=wd.alea(s.toString()),this.randn=new mu(0,1,o,!1,this.randu()),e<1?this.d=e+2/3:this.d=e-1/3,this.c=1/Math.sqrt(9*this.d)}nextValue(){let e,t,o,n,s,a;for(;;){do n=this.randn.nextValue(),a=1+this.c*n;while(a<=0);if(a*=a*a,e=n*n,t=1-.331*e*e,o=.5*e+this.d*(1-a+Math.log(a)),s=this.randu(),sthis.dtype==null||this.dtype===\"float32\",this.min=e,this.range=t-e,this.dtype=o,n==null&&(n=Math.random()),typeof n==\"number\"&&(n=n.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error(`The difference between ${e} - ${t} <= 1 and dtype is not float`);this.random=wd.alea(n)}convertValue(e){return this.canReturnFloat()?e:Math.round(e)}nextValue(){return this.convertValue(this.min+this.range*this.random())}};function Y4(r,e,t=1,o=\"float32\",n){if(bt(r),t==null&&(t=1),o==null&&(o=\"float32\"),o!==\"float32\"&&o!==\"int32\")throw new Error(`Unsupported data type ${o}`);let s=new Cd(e,t,o,n),a=le(r,o);for(let i=0;i`Error in reverse1D: x must be rank 1 but got rank ${e.rank}.`),no(e,0)}var Lk=N({reverse1d_:sG});function aG(r,e){let t=v(r,\"x\",\"reverse\");return $(t.rank===2,()=>`Error in reverse2D: x must be rank 2 but got rank ${t.rank}.`),no(t,e)}var Bk=N({reverse2d_:aG});function iG(r,e){let t=v(r,\"x\",\"reverse\");return $(t.rank===3,()=>`Error in reverse3D: x must be rank 3 but got rank ${t.rank}.`),no(t,e)}var Vk=N({reverse3d_:iG});function uG(r,e){let t=v(r,\"x\",\"reverse\");return $(t.rank===4,()=>`Error in reverse4D: x must be rank 4 but got rank ${t.rank}.`),no(t,e)}var zk=N({reverse4d_:uG});function pG(r){let t={x:v(r,\"x\",\"round\")};return T.runKernel(Vn,t)}var Nd=N({round_:pG});function cG(r){let t={x:v(r,\"x\",\"rsqrt\",\"float32\")};return T.runKernel(zn,t)}var Wk=N({rsqrt_:cG});function lG(r){let t={x:v(r,\"x\",\"selu\")};return T.runKernel(Ca,t)}var Uk=N({selu_:lG});function mG(r,e,t,o,n,s=[1,1],a=\"NHWC\"){let i=v(r,\"x\",\"separableConv2d\"),p=v(e,\"depthwiseFilter\",\"separableConv2d\"),u=v(t,\"pointwiseFilter\",\"separableConv2d\"),c=i,l=!1;if(i.rank===3&&(l=!0,c=W(i,[1,i.shape[0],i.shape[1],i.shape[2]])),a===\"NCHW\")throw new Error(\"separableConv2d currently does not support dataFormat NCHW; only NHWC is supported\");$(c.rank===4,()=>`Error in separableConv2d: input must be rank 4, but got rank ${c.rank}.`),$(p.rank===4,()=>`Error in separableConv2d: depthwise filter must be rank 4, but got rank ${p.rank}.`),$(u.rank===4,()=>`Error in separableConv2d: pointwise filter must be rank 4, but got rank ${p.rank}.`),$(u.shape[0]===1,()=>`Error in separableConv2d: the first dimension of pointwise filter must be 1, but got ${u.shape[0]}.`),$(u.shape[1]===1,()=>`Error in separableConv2d: the second dimension of pointwise filter must be 1, but got ${u.shape[1]}.`);let m=p.shape[2],d=p.shape[3];$(u.shape[2]===m*d,()=>`Error in separableConv2d: the third dimension of pointwise filter must be ${m*d}, but got ${u.shape[2]}.`);let f=Bp(c,p,o,n,a,s),g=Ei(f,u,1,\"valid\",a);return l?W(g,[g.shape[1],g.shape[2],g.shape[3]]):g}var Gk=N({separableConv2d_:mG});async function dG(r,e){let t=v(r,\"x\",\"setdiff1d\"),o=v(e,\"y\",\"setdiff1d\");$(t.dtype===o.dtype,()=>`x and y should have the same dtype, but got x (${t.dtype}) and y (${o.dtype}).`),$(t.rank===1,()=>`x should be 1D tensor, but got x (${t.shape}).`),$(o.rank===1,()=>`y should be 1D tensor, but got y (${o.shape}).`);let n=await t.data(),s=await o.data(),a=new Set(s),i=0;for(let c=0;c`slice1d expects a rank-1 tensor, but got a rank-${o.rank} tensor`),Ke(o,[e],[t])}var Xk=N({slice1d_:xG});function yG(r,e,t){let o=v(r,\"x\",\"slice2d\");return $(o.rank===2,()=>`slice2d expects a rank-2 tensor, but got a rank-${o.rank} tensor`),Ke(o,e,t)}var Yk=N({slice2d_:yG});function bG(r,e,t){let o=v(r,\"x\",\"slice3d\");return $(o.rank===3,()=>`slice3d expects a rank-3 tensor, but got a rank-${o.rank} tensor`),Ke(o,e,t)}var Qk=N({slice3d_:bG});function CG(r,e,t){let o=v(r,\"x\",\"slice4d\");return $(o.rank===4,()=>`slice4d expects a rank-4 tensor, but got a rank-${o.rank} tensor`),Ke(o,e,t)}var Zk=N({slice4d_:CG});function SG(r,e=-1){let t=v(r,\"logits\",\"softmax\",\"float32\");if(e===-1&&(e=t.rank-1),e!==t.rank-1)throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${t.rank} and dim was ${e}`);let o={logits:t},n={dim:e};return T.runKernel(qn,o,n)}var Jk=N({softmax_:SG});function wG(r){$(r.dtype===\"complex64\",()=>`The dtype for tf.spectral.fft() must be complex64 but got ${r.dtype}.`);let e={input:r};return T.runKernel(ui,e)}var zp=N({fft_:wG});function IG(r){$(r.dtype===\"complex64\",()=>`The dtype for tf.spectral.ifft() must be complex64 but got ${r.dtype}.`);let e={input:r};return T.runKernel(pi,e)}var du=N({ifft_:IG});function vG(r){let e=r.shape[r.shape.length-1],t=r.size/e,o;if(e<=2){let n=W(r,[t,e]);o=du(n)}else{let n=[t,2*(e-1)],s=W(Fa(r),[t,e]),a=W(Ri(r),[t,e]),i=no(Ke(s,[0,1],[t,e-2]),1),p=ne(no(Ke(a,[0,1],[t,e-2]),1),Ce(-1)),u=xt([s,i],1),c=xt([a,p],1),l=W(Tr(u,c),[n[0],n[1]]);o=du(l)}if(o=Fa(o),r.rank===3&&r.shape[0]!==0){let n=o,s=r.shape[0];o=W(o,[s,o.shape[0]/s,o.shape[1]]),n.dispose()}return o}var Td=N({irfft_:vG});function kG(r,e,t=0){let n={x:v(r,\"x\",\"split\")},s={numOrSizeSplits:e,axis:t};return T.runKernel(Rs,n,s)}var Oa=N({split_:kG});function NG(r,e){$(r.dtype===\"float32\",()=>`The dtype for rfft() must be real value but got ${r.dtype}`);let t=r.shape[r.shape.length-1],o=r.size/t,n;if(e!=null&&e0),h=r.shape.map(g=>g);h[r.shape.length-1]=e,n=Ke(r,f,h),t=e}else if(e!=null&&e>t){let f=r.shape.map(h=>h);f[r.shape.length-1]=e-t,n=xt([r,Br(f)],r.shape.length-1),t=e}else n=r;let s=Ut(n),a=W(Tr(n,s),[o,t]),i=zp(a),p=Math.floor(t/2)+1,u=Fa(i),c=Ri(i),l=Oa(u,[p,t-p],u.shape.length-1),m=Oa(c,[p,t-p],c.shape.length-1),d=n.shape.slice();return d[n.shape.length-1]=p,W(Tr(l[0],m[0]),d)}var Wp=N({rfft_:NG});function TG(r,e){let t=v(r,\"a\",\"squaredDifference\"),o=v(e,\"b\",\"squaredDifference\");[t,o]=De(t,o),Je(t.shape,o.shape);let n={a:t,b:o},s={};return T.runKernel(jn,n,s)}var _d=N({squaredDifference_:TG});function _G(r,e){let t=v(r,\"x\",\"squeeze\",\"string_or_numeric\");return W(t,bb(t.shape,e).newShape)}var Up=N({squeeze_:_G});function $G(r,e=0){let t=_a(r,\"tensors\",\"stack\",\"string_or_numeric\");$(t.length>=1,()=>\"Pass at least one tensor to tf.stack\"),t.length>0&&$(e<=t[0].rank,()=>\"Axis must be <= rank of the tensor\");let o=t,n={axis:e};return T.runKernel(Ns,o,n)}var Sr=N({stack_:$G});function EG(r,e=0){let o={x:v(r,\"x\",\"step\")},n={alpha:e};return T.runKernel(fo,o,n)}var $d=N({step_:EG});function AG(r,e,t,o,n=0,s=0,a=0,i=0,p=0){let c={x:v(r,\"x\",\"stridedSlice\",\"string_or_numeric\")},l={begin:e,end:t,strides:o,beginMask:n,endMask:s,ellipsisMask:a,newAxisMask:i,shrinkAxisMask:p};return T.runKernel(Xn,c,l)}var e1=N({stridedSlice_:AG});function RG(r){let t={x:v(r,\"x\",\"tan\",\"float32\")};return T.runKernel(Qn,t)}var t1=N({tan_:RG});function dr(r,e){Jr(r);let t=or(r,e);if(t.length!==1)throw new Error(\"tensor1d() requires values to be a flat/TypedArray\");return xr(r,null,t,e)}function Oi(r,e,t){if(Jr(r),e!=null&&e.length!==2)throw new Error(\"tensor2d() requires shape to have two numbers\");let o=or(r,t);if(o.length!==2&&o.length!==1)throw new Error(\"tensor2d() requires values to be number[][] or flat/TypedArray\");if(o.length===1&&e==null)throw new Error(\"tensor2d() requires shape to be provided when `values` are a flat/TypedArray\");return xr(r,e,o,t)}function Ed(r,e,t){if(Jr(r),e!=null&&e.length!==3)throw new Error(\"tensor3d() requires shape to have three numbers\");let o=or(r,t);if(o.length!==3&&o.length!==1)throw new Error(\"tensor3d() requires values to be number[][][] or flat/TypedArray\");if(o.length===1&&e==null)throw new Error(\"tensor3d() requires shape to be provided when `values` are a flat array\");return xr(r,e,o,t)}function r1(r,e,t){if(Jr(r),e!=null&&e.length!==4)throw new Error(\"tensor4d() requires shape to have four numbers\");let o=or(r,t);if(o.length!==4&&o.length!==1)throw new Error(\"tensor4d() requires values to be number[][][][] or flat/TypedArray\");if(o.length===1&&e==null)throw new Error(\"tensor4d() requires shape to be provided when `values` are a flat array\");return xr(r,e,o,t)}function o1(r,e,t){if(Jr(r),e!=null&&e.length!==5)throw new Error(\"tensor5d() requires shape to have five numbers\");let o=or(r,t);if(o.length!==5&&o.length!==1)throw new Error(\"tensor5d() requires values to be number[][][][][] or flat/TypedArray\");if(o.length===1&&e==null)throw new Error(\"tensor5d() requires shape to be provided when `values` are a flat array\");return xr(r,e,o,t)}function n1(r,e,t){if(Jr(r),e!=null&&e.length!==6)throw new Error(\"tensor6d() requires shape to have six numbers\");let o=or(r,t);if(o.length!==6&&o.length!==1)throw new Error(\"tensor6d() requires values to be number[][][][][][] or flat/TypedArray\");if(o.length===1&&e==null)throw new Error(\"tensor6d() requires shape to be provided when `values` are a flat array\");return e=e||o,xr(r,e,o,t)}function DG(r,e=1,t=!0){let o=v(r,\"x\",\"topk\");if(o.rank===0)throw new Error(\"topk() expects the input to be of rank 1 or higher\");let n=o.shape[o.shape.length-1];if(e<0)throw new Error(`'k' passed to topk() must be >= 0 but got ${e}`);if(e>n)throw new Error(`'k' passed to topk() must be <= the last dimension (${n}) but got ${e}`);let s={x:o},a={k:e,sorted:t},[i,p]=T.runKernel(Jn,s,a);return{values:i,indices:p}}var s1=N({topk_:DG});function FG(r,e=0,t=1,o,n){if(bt(r),o!=null&&o===\"bool\")throw new Error(\"Unsupported data type $ { dtype }\");let s=new mu(e,t,o,!0,n),a=le(r,o);for(let i=0;i0,()=>\"The input tensor must be at least 1D\");let o={x:t},n={axis:e},[s,a]=T.runKernel(Np,o,n);return{values:s,indices:a}}var i1=N({unique_:OG});function PG(r,e,t){let o=v(r,\"x\",\"unsortedSegmentSum\"),n=v(e,\"segmentIds\",\"unsortedSegmentSum\",\"int32\");$(sa(t),()=>\"numSegments must be of dtype int\");let s={x:o,segmentIds:n},a={numSegments:t};return T.runKernel(Tp,s,a)}var u1=N({unsortedSegmentSum_:PG});function MG(r,e=0){let t=v(r,\"x\",\"unstack\",\"string_or_numeric\");$(e>=-t.shape.length&&e`Axis = ${e} is not in [-${t.shape.length}, ${t.shape.length})`);let o={value:t},n={axis:e};return T.runKernel(Fs,o,n)}var so=N({unstack_:MG});function p1(r,e){return ol(r,e,\"right\")}function c1(r,e=!0,t,o){return T.makeVariable(r,e,t,o)}function Ad(r,e){let t=[];for(let s=0;s0,()=>\"mask cannot be scalar\"),gt(i.slice(s,s+a),n.shape,\"mask's shape must match the first K dimensions of tensor's shape,\");let p=1;for(let h=s;hi).reverse()),$(o.rank===e.length,()=>`Error in transpose: rank of input ${o.rank} must match length of perm ${e}.`),e.forEach(a=>{$(a>=0&&a`All entries in 'perm' must be between 0 and ${o.rank-1} but got ${e}`)}),o.rank<=1)return o.clone();let n={x:o},s={perm:e};return o.dtype===\"complex64\"?Ee(()=>{let a=Fa(o),i=Ri(o);return a=T.runKernel(ro,{x:a},s),i=T.runKernel(ro,{x:i},s),t&&(i=Cr(i)),Tr(a,i)}):T.runKernel(ro,n,s)}var Gp=N({transpose_:zG});function WG(r,e,t,o,n=!0){let s=v(r,\"v\",\"movingAverage\"),a=v(e,\"x\",\"movingAverage\"),i=v(t,\"decay\",\"movingAverage\");Ub(s,a),$(Or(s.shape,a.shape),()=>\"Shape mismatch in v and x\");let p=Ce(1),u=ke(p,i),c=ne(ke(a,s),u);if(n){$(o!=null,()=>\"When using zeroDebias: true, step is required.\");let l=v(o,\"step\",\"movingAverage\");c=He(c,ke(p,Aa(i,l)))}return be(s,c)}var UG=N({movingAverage_:WG});var sl={};Ge(sl,{calculateShapes:()=>l1,validateInput:()=>Dd,validateUpdateShape:()=>bC});function bC(r,e,t){let o=e.rank>1?e.shape[e.rank-1]:1,n=e.rank>1?e.rank-1:1,s=`Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: ${t.shape}, indices.shape: ${e.shape}, shape: ${r}, sliceDim: ${o}, and batchDim: ${n}.`;if(t.rank1?e.shape[o-1]:1,s=t.length,a=1;for(let l=n;l2)throw new Error(`sparseIndices should be a scalar, vector, or matrix, but got shape ${r.shape}.`);let n=r.rank>0?r.shape[0]:1,s=r.rank>1?r.shape[1]:1;if(t.length!==s)throw new Error(`outputShape has incorrect number of elements:, ${t.length}, should be: ${s}.`);let a=e.size;if(!(e.rank===0||e.rank===1&&a===n))throw new Error(`sparseValues has incorrect shape ${e.shape}, should be [] or [${n}]`);if(e.dtype!==o.dtype)throw new Error(\"sparseValues.dtype must match defaultValues.dtype\")}function qG(r,e,t,o=0){bt(t);let n=v(r,\"sparseIndices\",\"sparseToDense\",\"int32\"),s=v(e,\"sparseValues\",\"sparseToDense\",\"string_or_numeric\"),a=v(o,\"defaultValue\",\"sparseToDense\",s.dtype);m1(n,s,t,a);let i={sparseIndices:n,sparseValues:s,defaultValue:a},p={outputShape:t};return T.runKernel(yi,i,p)}var jG=N({sparseToDense_:qG});function XG(r,e){let t=v(e,\"indices\",\"gatherND\",\"int32\"),n={params:v(r,\"x\",\"gatherND\",\"string_or_numeric\"),indices:t};return T.runKernel(an,n)}var YG=N({gatherND_:XG});function d1(r,e){if(e==null)return r.shape.slice();if(Or(r.shape,e))return e;if(r.shape.length===e.length){let t=[];for(let o=0;o`x has to be a floating point tensor since it's going to be scaled, but got a ${n.dtype} tensor instead.`),$(e>=0&&e<1,()=>`rate must be a float in the range [0, 1), but got ${e}.`),e===0)return r instanceof it?n.clone():n;let s=d1(n,t),a=1-e,i=He(td(be(vd(s,0,1,\"float32\",o),a)),a);return ne(n,i)}var ZG=N({dropout_:QG});function CC(r){return Math.floor(Math.pow(2,Math.ceil(Math.log(r)/Math.log(2))))}function al(r,e,t){let o=1-r%2,n=new Float32Array(r);for(let s=0;s1,()=>`inTopK() expects the predictions to be of rank 2 or higher, but got ${o.rank}`),$(o.rank-1===n.rank,()=>`predictions rank should be 1 larger than targets rank, but got predictions rank ${o.rank} and targets rank ${n.rank}`),gt(o.shape.slice(0,o.shape.length-1),n.shape,\"predictions's shape should be align with the targets' shape, except the last dimension.\");let s=o.shape[o.shape.length-1];$(t>0&&t<=s,()=>`'k' passed to inTopK() must be > 0 && <= the predictions last dimension (${s}), but got ${t}`);let a=await o.data(),i=await n.data(),[p,u]=[a.length/s,s],c=Cb(\"bool\",p);for(let l=0;lg.value-h.value),c[l]=0;for(let h=0;hh1,depthwiseConv2d:()=>y1,matMul:()=>b1});function tH(r,e,t,o,n,s=\"NHWC\",a){let i=r;r.rank===3&&(i=W(r,[1,r.shape[0],r.shape[1],r.shape[2]]));let p=e;p.rank===3&&(p=W(e,[1,e.shape[0],e.shape[1],e.shape[2]])),$(i.rank===4,()=>`Error in conv2dDerFilter: input must be rank 4, but got shape ${i.shape}.`),$(p.rank===4,()=>`Error in conv2dDerFilter: dy must be rank 4, but got shape ${p.shape}.`),$(t.length===4,()=>`Error in conv2dDerFilter: filterShape must be length 4, but got ${t}.`);let u=s===\"NHWC\"?i.shape[3]:i.shape[1],c=s===\"NHWC\"?p.shape[3]:p.shape[1];$(u===t[2],()=>`Error in conv2dDerFilter: depth of input ${u}) must match input depth in filter (${t[2]}.`),$(c===t[3],()=>`Error in conv2dDerFilter: depth of dy (${c}) must match output depth for filter (${t[3]}).`),Mt(\"conv2dDerFilter\",n,a);let l={x:i,dy:p},m={strides:o,pad:n,dataFormat:s,dimRoundingMode:a,filterShape:t};return T.runKernel(oi,l,m)}var f1=N({conv2DBackpropFilter_:tH});function fu(r,e,t){if(t==null||t===\"linear\")return r;if(t===\"relu\")return ne(r,$d(e));throw new Error(`Cannot compute gradient for fused activation ${t}.`)}function hu(r,e){let t=e,o=Qm(r.shape,e.shape);return o.length>0&&(t=et(t,o)),W(t,r.shape)}function gu(r,e,t,o){if(e===\"linear\")return r;if(e===\"relu\")return Fi(r);if(e===\"elu\")return Jm(r);if(e===\"relu6\")return kd(r);if(e===\"prelu\")return xd(r,t);if(e===\"leakyrelu\")return nd(r,o);if(e===\"sigmoid\")return Ws(r);throw new Error(`Unknown fused activation ${e}.`)}var xu=(r,e)=>!(r>0)||e===\"linear\";function rH({x:r,filter:e,strides:t,pad:o,dataFormat:n=\"NHWC\",dilations:s=[1,1],dimRoundingMode:a,bias:i,activation:p=\"linear\",preluActivationWeights:u,leakyreluAlpha:c}){if(p=p||\"linear\",xu(T.state.gradientDepth,p)===!1){$(n===\"NHWC\",()=>`Error in fused conv2d: got dataFormat of ${n} but only NHWC is currently supported for the case of gradient depth is 0 and the activation is not linear.`);let _=Ei(r,e,t,o,n,s,a);return i!=null&&(_=be(_,i)),gu(_,p,u,c)}let l=v(r,\"x\",\"conv2d\",\"float32\"),m=v(e,\"filter\",\"conv2d\",\"float32\"),d=l,f=!1;l.rank===3&&(f=!0,d=W(l,[1,l.shape[0],l.shape[1],l.shape[2]])),$(d.rank===4,()=>`Error in fused conv2d: input must be rank 4, but got rank ${d.rank}.`),$(m.rank===4,()=>`Error in fused conv2d: filter must be rank 4, but got rank ${m.rank}.`),Mt(\"fused conv2d\",o,a);let h=n===\"NHWC\"?d.shape[3]:d.shape[1];$(m.shape[2]===h,()=>`Error in conv2d: depth of input (${h}) must match input depth for filter ${m.shape[2]}.`),$(mr(t,s),()=>`Error in conv2D: Either strides or dilations must be 1. Got strides ${t} and dilations '${s}'`);let g=au(d.shape,m.shape,t,s,o,a),x;i!=null&&(x=v(i,\"bias\",\"fused conv2d\"),[x]=De(x,l),n===\"NHWC\"?Je(g.outShape,x.shape):($(x.shape.length<=1,()=>`Error in fused conv2d: only supports scalar or 1-D Tensor bias for NCHW format but got the bias of rank-${x.shape.length}.`),$(x.shape.length===0||x.shape[0]===g.outChannels||x.shape[0]===1,()=>`Error in fused conv2d: bias shape (${x.shape}) is not compatible with the number of output channels (${g.outChannels})`)));let b;if(u!=null){let _=u.shape;if($(_.length<=1||_.length===3,()=>`Error in fused conv2d: only supports scalar, 1-D Tensor or 3-D Tensor PReLU activation weights but got a tensor of rank-${_.length}.`),_.length===1)$(_[0]===1||_[0]===g.outChannels,()=>`Error in fused conv2d: PReLU activation weights (${_}) is not compatible with the number of output channels (${g.outChannels}).`);else if(_.length===3)try{Je(_,g.outShape)}catch(E){let A=`Error in fused conv2d: PReLU activation weights (${_}) is not compatible with the output shape of the conv2d (${g.outShape}).`;throw Error(A)}b=v(u,\"prelu weights\",\"fused conv2d\")}let C=(_,E)=>{$(n===\"NHWC\",()=>`Error in gradient of fused conv2D: got dataFormat of ${n} but only NHWC is currently supported.`);let[A,R,D,P]=E,M=fu(_,D,p);$(su(s),()=>`Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '${s}'`);let L=Ym(R.shape,M,A,t,o),V=f1(R,M,A.shape,t,o),z=[L,V];if(P!=null){let U=hu(P,M);z.push(U)}return z},w={x:d,filter:m,bias:x,preluActivationWeights:b},k={strides:t,pad:o,dataFormat:n,dilations:s,dimRoundingMode:a,activation:p,leakyreluAlpha:c};return i==null?br((E,A,R)=>{let D=T.runKernel(go,w,k);return R([A,E,D]),f&&(D=W(D,[D.shape[1],D.shape[2],D.shape[3]])),{value:D,gradFunc:C}})(d,m):br((E,A,R,D)=>{let P=T.runKernel(go,w,k);return D([A,E,P,R]),f&&(P=W(P,[P.shape[1],P.shape[2],P.shape[3]])),{value:P,gradFunc:C}})(d,m,x)}var h1=N({fusedConv2d_:rH});function oH(r,e,t,o,n,s=[1,1],a){let i=r;r.rank===3&&(i=W(r,[1,r.shape[0],r.shape[1],r.shape[2]]));let p=e;p.rank===3&&(p=W(e,[1,e.shape[0],e.shape[1],e.shape[2]]));let u={x:i,dy:p},c={strides:o,pad:n,dimRoundingMode:a,dilations:s,filterShape:t};return T.runKernel(yp,u,c)}var g1=N({depthwiseConv2dNativeBackpropFilter_:oH});function nH(r,e,t,o,n,s=[1,1],a){let i=e,p=!1;e.rank===3&&(p=!0,i=W(e,[1,e.shape[0],e.shape[1],e.shape[2]]));let u={dy:i,filter:t},c={strides:o,pad:n,dimRoundingMode:a,dilations:s,inputShape:r},l=T.runKernel(bp,u,c);return p?W(l,[l.shape[1],l.shape[2],l.shape[3]]):l}var x1=N({depthwiseConv2dNativeBackpropInput_:nH});function sH({x:r,filter:e,strides:t,pad:o,dataFormat:n=\"NHWC\",dilations:s=[1,1],dimRoundingMode:a,bias:i,activation:p=\"linear\",preluActivationWeights:u,leakyreluAlpha:c}){if(xu(T.state.gradientDepth,p)===!1){let k=Bp(r,e,t,o,n,s,a);return i!=null&&(k=be(k,i)),gu(k,p,u,c)}let l=v(r,\"x\",\"depthwiseConv2d\",\"float32\"),m=v(e,\"filter\",\"depthwiseConv2d\",\"float32\"),d=l,f=!1;l.rank===3&&(f=!0,d=W(l,[1,l.shape[0],l.shape[1],l.shape[2]])),$(d.rank===4,()=>`Error in fused depthwiseConv2d: input must be rank 4, but got rank ${d.rank}.`),$(m.rank===4,()=>`Error in fused depthwiseConv2d: filter must be rank 4, but got rank ${m.rank}.`),$(d.shape[3]===m.shape[2],()=>`Error in fused depthwiseConv2d: number of input channels (${d.shape[3]}) must match the inChannels dimension in filter ${m.shape[2]}.`),s==null&&(s=[1,1]),$(mr(t,s),()=>`Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides ${t} and dilations '${s}'`),Mt(\"fused depthwiseConv2d\",o,a);let h=au(d.shape,m.shape,t,s,o,a,!0),g;i!=null&&(g=v(i,\"bias\",\"fused conv2d\"),[g]=De(g,l),Je(h.outShape,g.shape));let x;u!=null&&(x=v(u,\"prelu weights\",\"fused depthwiseConv2d\"));let b=(k,_)=>{$(su(s),()=>`Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '${s}'`);let[E,A,R,D]=_,P=fu(k,R,p),M=x1(A.shape,P,E,t,o,s,a),L=g1(A,P,E.shape,t,o,s,a);if(D!=null){let V=hu(g,P);return[M,L,V]}return[M,L]},C={x:d,filter:m,bias:g,preluActivationWeights:x},w={strides:t,pad:o,dataFormat:n,dilations:s,dimRoundingMode:a,activation:p,leakyreluAlpha:c};return i==null?br((_,E,A)=>{let R=T.runKernel(xo,C,w);return A([E,_,R]),f&&(R=W(R,[R.shape[1],R.shape[2],R.shape[3]])),{value:R,gradFunc:b}})(d,m):br((_,E,A,R)=>{let D=T.runKernel(xo,C,w);return R([E,_,D,A]),f&&(D=W(D,[D.shape[1],D.shape[2],D.shape[3]])),{value:D,gradFunc:b}})(d,m,g)}var y1=N({fusedDepthwiseConv2d_:sH});function aH({a:r,b:e,transposeA:t=!1,transposeB:o=!1,bias:n,activation:s=\"linear\",preluActivationWeights:a,leakyreluAlpha:i=.2}){if(xu(T.state.gradientDepth,s)===!1){let P=Xe(r,e,t,o);return n!=null&&(P=be(P,n)),gu(P,s,a,i)}let p=v(r,\"a\",\"fused matMul\"),u=v(e,\"b\",\"fused matMul\");[p,u]=De(p,u);let c=t?p.shape[p.rank-2]:p.shape[p.rank-1],l=o?u.shape[u.rank-1]:u.shape[u.rank-2],m=t?p.shape[p.rank-1]:p.shape[p.rank-2],d=o?u.shape[u.rank-2]:u.shape[u.rank-1],f=p.shape.slice(0,-2),h=u.shape.slice(0,-2),g=We(f),x=We(h);$(c===l,()=>`Error in fused matMul: inner shapes (${c}) and (${l}) of Tensors with shapes ${p.shape} and ${u.shape} and transposeA=${t} and transposeB=${o} must match.`);let C=Je(p.shape.slice(0,-2),u.shape.slice(0,-2)).concat([m,d]),w=t?W(p,[g,c,m]):W(p,[g,m,c]),k=o?W(u,[x,d,l]):W(u,[x,l,d]),_;n!=null&&(_=v(n,\"bias\",\"fused matMul\"),[_]=De(_,p),Je(C,_.shape));let E;a!=null&&(E=v(a,\"prelu weights\",\"fused matMul\"));let A=(P,M)=>{let[L,V,z,U]=M,K=fu(W(P,z.shape),z,s),H,q;if(!t&&!o?(H=Xe(K,V,!1,!0),q=Xe(L,K,!0,!1)):!t&&o?(H=Xe(K,V,!1,!1),q=Xe(K,L,!0,!1)):t&&!o?(H=Xe(V,K,!1,!0),q=Xe(L,K,!1,!1)):(H=Xe(V,K,!0,!0),q=Xe(K,L,!0,!0)),n!=null){let Z=hu(U,K);return[H,q,Z]}else return[H,q]},R={a:w,b:k,bias:_,preluActivationWeights:E},D={transposeA:t,transposeB:o,activation:s,leakyreluAlpha:i};return n==null?br((M,L,V)=>{let z=T.runKernel(ho,R,D);return V([M,L,z]),{value:W(z,C),gradFunc:A}})(w,k):br((M,L,V,z)=>{let U=T.runKernel(ho,R,D);return z([M,L,U,V]),{value:W(U,C),gradFunc:A}})(w,k,_)}var b1=N({fusedMatMul_:aH});function iH(r){return al(r,.54,.46)}var C1=N({hammingWindow_:iH});function uH(r){return al(r,.5,.5)}var Fd=N({hannWindow_:uH});function pH(r,e,t,o=!1,n=0){let s=0,a=[];for(;s+e<=r.size;)a.push(Ke(r,s,e)),s+=t;if(o)for(;s`Error in cropAndResize: image must be rank 4,but got rank ${a.rank}.`),$(i.rank===2&&i.shape[1]===4,()=>`Error in cropAndResize: boxes must be have size [${u},4] but had shape ${i.shape}.`),$(p.rank===1&&p.shape[0]===u,()=>`Error in cropAndResize: boxInd must be have size [${u}] but had shape ${i.shape}.`),$(o.length===2,()=>`Error in cropAndResize: cropSize must be of length 2, but got length ${o.length}.`),$(o[0]>=1&&o[1]>=1,()=>`cropSize must be atleast [1,1], but was ${o}`),$(n===\"bilinear\"||n===\"nearest\",()=>`method must be bilinear or nearest, but was ${n}`);let c={image:a,boxes:i,boxInd:p},l={method:n,extrapolationValue:s,cropSize:o};return T.runKernel(Xo,c,l)}var w1=N({cropAndResize_:lH});function mH(r){let e=v(r,\"image\",\"flipLeftRight\",\"float32\");$(e.rank===4,()=>`Error in flipLeftRight: image must be rank 4,but got rank ${e.rank}.`);let t={image:e};return T.runKernel(rn,t,{})}var I1=N({flipLeftRight_:mH});function dH(r){let e=v(r,\"image\",\"grayscaleToRGB\"),t=e.rank-1,o=e.shape[t];$(e.rank>=2,()=>`Error in grayscaleToRGB: images must be at least rank 2, but got rank ${e.rank}.`),$(o===1,()=>`Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${o}.`);let n=new Array(e.rank);return n.fill(1,0,t),n[t]=3,Ai(e,n)}var v1=N({grayscaleToRGB_:dH});function fH(r,e,t=0,o=.5){let n=v(r,\"image\",\"rotateWithOffset\",\"float32\");$(n.rank===4,()=>`Error in rotateWithOffset: image must be rank 4,but got rank ${n.rank}.`);let s={image:n},a={radians:e,fillValue:t,center:o};return T.runKernel(ts,s,a)}var k1=N({rotateWithOffset_:fH});function wo(r,e,t,o,n,s){o==null&&(o=.5),n==null&&(n=Number.NEGATIVE_INFINITY),s==null&&(s=0);let a=r.shape[0];return t=Math.min(t,a),$(0<=o&&o<=1,()=>`iouThreshold must be in [0, 1], but was '${o}'`),$(r.rank===2,()=>`boxes must be a 2D tensor, but was of rank '${r.rank}'`),$(r.shape[1]===4,()=>`boxes must have 4 columns, but 2nd dimension was ${r.shape[1]}`),$(e.rank===1,()=>\"scores must be a 1D tensor\"),$(e.shape[0]===a,()=>`scores has incompatible shape with boxes. Expected ${a}, but was ${e.shape[0]}`),$(0<=s&&s<=1,()=>`softNmsSigma must be in [0, 1], but was '${s}'`),{maxOutputSize:t,iouThreshold:o,scoreThreshold:n,softNmsSigma:s}}function hH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY){let s=v(r,\"boxes\",\"nonMaxSuppression\",\"float32\"),a=v(e,\"scores\",\"nonMaxSuppression\",\"float32\"),i=wo(s,a,t,o,n);t=i.maxOutputSize,o=i.iouThreshold,n=i.scoreThreshold;let p={maxOutputSize:t,iouThreshold:o,scoreThreshold:n};return T.runKernel(Tn,{boxes:s,scores:a},p)}var N1=N({nonMaxSuppression_:hH});function T1(r,e,t){let o=gH(r,e,t),n=o<0?-(o+1):o;r.splice(n,0,e)}function gH(r,e,t){return yH(r,e,t||xH)}function xH(r,e){return r>e?1:r>>1);let i=t(e,r[s]);i>0?o=s+1:(n=s,a=!i)}return a?o:-o-1}function Pd(r,e,t,o,n){return wC(r,e,t,o,n,0)}function Md(r,e,t,o,n,s){return wC(r,e,t,o,n,0,!1,s,!0)}function Ld(r,e,t,o,n,s){return wC(r,e,t,o,n,s,!0)}function wC(r,e,t,o,n,s,a=!1,i=!1,p=!1){let u=[];for(let g=0;gn&&u.push({score:e[g],boxIndex:g,suppressBeginIndex:0});u.sort(_1);let c=s>0?-.5/s:0,l=[],m=[];for(;l.length0;){let g=u.pop(),{score:x,boxIndex:b,suppressBeginIndex:C}=g;if(x=C;--k){let _=bH(r,b,l[k]);if(_>=o){w=!0;break}if(g.score=g.score*CH(o,c,_),g.score<=n)break}g.suppressBeginIndex=l.length,w||(g.score===x?(l.push(b),m.push(g.score)):g.score>n&&T1(u,g,_1))}let d=l.length,f=t-d;i&&f>0&&(l.push(...new Array(f).fill(0)),m.push(...new Array(f).fill(0)));let h={selectedIndices:l};return a&&(h.selectedScores=m),p&&(h.validOutputs=d),h}function bH(r,e,t){let o=r.subarray(e*4,e*4+4),n=r.subarray(t*4,t*4+4),s=Math.min(o[0],o[2]),a=Math.min(o[1],o[3]),i=Math.max(o[0],o[2]),p=Math.max(o[1],o[3]),u=Math.min(n[0],n[2]),c=Math.min(n[1],n[3]),l=Math.max(n[0],n[2]),m=Math.max(n[1],n[3]),d=(i-s)*(p-a),f=(l-u)*(m-c);if(d<=0||f<=0)return 0;let h=Math.max(s,u),g=Math.max(a,c),x=Math.min(i,l),b=Math.min(p,m),C=Math.max(x-h,0)*Math.max(b-g,0);return C/(d+f-C)}function CH(r,e,t){let o=Math.exp(e*t*t);return t<=r?o:0}function _1(r,e){return r.score-e.score||r.score===e.score&&e.boxIndex-r.boxIndex}async function SH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY){let s=v(r,\"boxes\",\"nonMaxSuppressionAsync\"),a=v(e,\"scores\",\"nonMaxSuppressionAsync\"),i=wo(s,a,t,o,n);t=i.maxOutputSize,o=i.iouThreshold,n=i.scoreThreshold;let p=await Promise.all([s.data(),a.data()]),u=p[0],c=p[1],{selectedIndices:l}=Pd(u,c,t,o,n);return s!==r&&s.dispose(),a!==e&&a.dispose(),dr(l,\"int32\")}var $1=SH;function wH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY,s=0){let a=v(r,\"boxes\",\"nonMaxSuppression\"),i=v(e,\"scores\",\"nonMaxSuppression\"),p=wo(a,i,t,o,n,s);t=p.maxOutputSize,o=p.iouThreshold,n=p.scoreThreshold,s=p.softNmsSigma;let u={boxes:a,scores:i},c={maxOutputSize:t,iouThreshold:o,scoreThreshold:n,softNmsSigma:s},l=T.runKernel(_n,u,c);return{selectedIndices:l[0],selectedScores:l[1]}}var E1=N({nonMaxSuppressionWithScore_:wH});async function IH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY,s=0){let a=v(r,\"boxes\",\"nonMaxSuppressionAsync\"),i=v(e,\"scores\",\"nonMaxSuppressionAsync\"),p=wo(a,i,t,o,n,s);t=p.maxOutputSize,o=p.iouThreshold,n=p.scoreThreshold,s=p.softNmsSigma;let u=await Promise.all([a.data(),i.data()]),c=u[0],l=u[1],{selectedIndices:m,selectedScores:d}=Ld(c,l,t,o,n,s);return a!==r&&a.dispose(),i!==e&&i.dispose(),{selectedIndices:dr(m,\"int32\"),selectedScores:dr(d)}}var A1=IH;function vH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY,s=!1){let a=v(r,\"boxes\",\"nonMaxSuppression\"),i=v(e,\"scores\",\"nonMaxSuppression\"),p=wo(a,i,t,o,n,null),u=p.maxOutputSize,c=p.iouThreshold,l=p.scoreThreshold,m={boxes:a,scores:i},d={maxOutputSize:u,iouThreshold:c,scoreThreshold:l,padToMaxOutputSize:s},f=T.runKernel(ba,m,d);return{selectedIndices:f[0],validOutputs:f[1]}}var R1=N({nonMaxSuppressionPadded_:vH});async function kH(r,e,t,o=.5,n=Number.NEGATIVE_INFINITY,s=!1){let a=v(r,\"boxes\",\"nonMaxSuppressionAsync\"),i=v(e,\"scores\",\"nonMaxSuppressionAsync\"),p=wo(a,i,t,o,n,null),u=p.maxOutputSize,c=p.iouThreshold,l=p.scoreThreshold,[m,d]=await Promise.all([a.data(),i.data()]),{selectedIndices:f,validOutputs:h}=Md(m,d,u,c,l,s);return a!==r&&a.dispose(),i!==e&&i.dispose(),{selectedIndices:dr(f,\"int32\"),validOutputs:Ce(h,\"int32\")}}var D1=kH;function NH(r,e,t=!1,o=!1){let n=v(r,\"images\",\"resizeBilinear\");$(n.rank===3||n.rank===4,()=>`Error in resizeBilinear: x must be rank 3 or 4, but got rank ${n.rank}.`),$(e.length===2,()=>`Error in resizeBilinear: new shape must 2D, but got shape ${e}.`),$(o===!1||t===!1,()=>\"Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.\");let s=n,a=!1;n.rank===3&&(a=!0,s=W(n,[1,n.shape[0],n.shape[1],n.shape[2]]));let[]=e,i={images:s},p={alignCorners:t,halfPixelCenters:o,size:e},u=T.runKernel(Mn,i,p);return a?W(u,[u.shape[1],u.shape[2],u.shape[3]]):u}var F1=N({resizeBilinear_:NH});function TH(r,e,t=!1,o=!1){let n=v(r,\"images\",\"resizeNearestNeighbor\");$(n.rank===3||n.rank===4,()=>`Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${n.rank}.`),$(e.length===2,()=>`Error in resizeNearestNeighbor: new shape must 2D, but got shape ${e}.`),$(n.dtype===\"float32\"||n.dtype===\"int32\",()=>\"`images` must have `int32` or `float32` as dtype\"),$(o===!1||t===!1,()=>\"Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.\");let s=n,a=!1;n.rank===3&&(a=!0,s=W(n,[1,n.shape[0],n.shape[1],n.shape[2]]));let[]=e,i={images:s},p={alignCorners:t,halfPixelCenters:o,size:e},u=T.runKernel(Pn,i,p);return a?W(u,[u.shape[1],u.shape[2],u.shape[3]]):u}var O1=N({resizeNearestNeighbor_:TH});function _H(r,e=\"binary\",t=!1,o=.5){let n=v(r,\"image\",\"threshold\"),s=.2989,a=.587,i=.114,p=n.shape[0]*n.shape[1],u=ne(dr([o]),255),c,l,m,d;if($(n.rank===3,()=>`Error in threshold: image must be rank 3,but got rank ${n.rank}.`),$(n.shape[2]===3||n.shape[2]===1,()=>`Error in threshold: image color channel must be equal to 3 or 1but got ${n.shape[2]}.`),$(n.dtype===\"int32\"||n.dtype===\"float32\",()=>`Error in dtype: image dtype must be int32 or float32,but got dtype ${n.dtype}.`),$(e===\"otsu\"||e===\"binary\",()=>`Method must be binary or otsu, but was ${e}`),n.shape[2]===3){[c,l,m]=Oa(n,[1,1,1],-1);let g=ne(c,s),x=ne(l,a),b=ne(m,i);d=be(be(g,x),b)}else d=r;if(e===\"otsu\"){let g=Xm(je(Nd(d),\"int32\"),nr([]),256);u=$H(g,p)}let f=t?Vp(d,u):uu(d,u);return je(ne(f,255),\"int32\")}function $H(r,e){let t=dr([-1]),o=dr([0]),n=dr([0]),s,a,i,p,u,c;for(let l=0;l`Error in transform: image must be rank 4,but got rank ${a.rank}.`),$(i.rank===2&&(i.shape[0]===a.shape[0]||i.shape[0]===1)&&i.shape[1]===8,()=>\"Error in transform: Input transform should be batch x 8 or 1 x 8\"),$(s==null||s.length===2,()=>`Error in transform: outputShape must be [height, width] or null, but got ${s}.`);let p={image:a,transforms:i},u={interpolation:t,fillMode:o,fillValue:n,outputShape:s};return T.runKernel(es,p,u)}var M1=N({transform_:EH});function AH(r,e,t){$(e%1===0,()=>`bandPart(): numLower must be an integer, got ${e}.`),$(t%1===0,()=>`bandPart(): numUpper must be an integer, got ${t}.`);let o=v(r,\"a\",\"bandPart\");$(o.rank>=2,()=>`bandPart(): Rank must be at least 2, got ${o.rank}.`);let n=o.shape,[s,a]=o.shape.slice(-2);if(!(e<=s))throw new Error(`bandPart(): numLower (${e}) must not be greater than the number of rows (${s}).`);if(!(t<=a))throw new Error(`bandPart(): numUpper (${t}) must not be greater than the number of columns (${a}).`);e<0&&(e=s),t<0&&(t=a);let i=W(Di(0,s,1,\"int32\"),[-1,1]),p=Di(0,a,1,\"int32\"),u=ke(i,p),c=pu(Vp(u,Ce(+e,\"int32\")),od(u,Ce(-t,\"int32\"))),l=Br([s,a],o.dtype);return W(Sr(so(W(o,[-1,s,a])).map(m=>ss(c,m,l))),n)}var L1=N({bandPart_:AH});function RH(r){let e;if(Array.isArray(r)){e=!1,$(r!=null&&r.length>0,()=>\"Gram-Schmidt process: input must not be null, undefined, or empty\");let n=r[0].shape[0];for(let s=1;s`Gram-Schmidt: Non-unique lengths found in the input vectors: (${r[s].shape[0]} vs. ${n})`)}else e=!0,r=Oa(r,r.shape[0],0).map(n=>Up(n,[0]));$(r.length<=r[0].shape[0],()=>`Gram-Schmidt: Number of vectors (${r.length}) exceeds number of dimensions (${r[0].shape[0]}).`);let t=[],o=r;for(let n=0;n{let s=o[n];if(n>0)for(let a=0;a=2,()=>`qr() requires input tensor to have a rank >= 2, but got rank ${r.rank}`),r.rank===2)return V1(r,e);{let t=r.shape.slice(0,r.shape.length-2).reduce((p,u)=>p*u),o=so(W(r,[t,r.shape[r.shape.length-2],r.shape[r.shape.length-1]]),0),n=[],s=[];o.forEach(p=>{let[u,c]=V1(p,e);n.push(u),s.push(c)});let a=W(Sr(n,0),r.shape),i=W(Sr(s,0),r.shape);return[a,i]}}function V1(r,e=!1){return T.tidy(()=>{$(r.shape.length===2,()=>`qr2d() requires a 2D Tensor, but got a ${r.shape.length}D Tensor.`);let t=r.shape[0],o=r.shape[1],n=ed(t),s=Lr(r),a=Oi([[1]],[1,1]),i=Lr(a),p=t>=o?o:t;for(let u=0;u{let d=Ke(s,[u,u],[t-u,1]),f=iu(d),h=Ke(s,[u,u],[1,1]),g=ss(uu(h,0),Oi([[-1]]),Oi([[1]])),x=ke(h,ne(g,f)),b=He(d,x);b.shape[0]===1?i=Lr(a):i=xt([a,Ke(b,[1,0],[b.shape[0]-1,b.shape[1]])],0);let C=Cr(He(Xe(g,x),f)),w=Ke(s,[u,0],[t-u,o]),k=ne(C,i),_=Gp(i);if(u===0)s=ke(w,Xe(k,Xe(_,w)));else{let R=ke(w,Xe(k,Xe(_,w)));s=xt([Ke(s,[0,0],[u,o]),R],0)}let E=Gp(k),A=Ke(n,[0,u],[t,n.shape[1]-u]);if(u===0)n=ke(A,Xe(Xe(A,i),E));else{let R=ke(A,Xe(Xe(A,i),E));n=xt([Ke(n,[0,0],[t,u]),R],1)}return[i,s,n]}),Ot([c,l,m])}return!e&&t>o&&(n=Ke(n,[0,0],[t,o]),s=Ke(s,[0,0],[o,o])),[n,s]})}var z1=N({qr_:DH});var $t;(function(r){r[r.NONE=0]=\"NONE\",r[r.MEAN=1]=\"MEAN\",r[r.SUM=2]=\"SUM\",r[r.SUM_BY_NONZERO_WEIGHTS=3]=\"SUM_BY_NONZERO_WEIGHTS\"})($t||($t={}));function FH(r,e,t=$t.SUM_BY_NONZERO_WEIGHTS){let o=v(r,\"losses\",\"computeWeightedLoss\"),n=null;e!=null&&(n=v(e,\"weights\",\"computeWeightedLoss\"));let s=n==null?o:ne(o,n);if(t===$t.NONE)return s;if(t===$t.SUM)return et(s);if(t===$t.MEAN){if(n==null)return cu(s);{let a=o.size/n.size,i=He(et(s),et(n));return a>1?He(i,Ce(a)):i}}if(t===$t.SUM_BY_NONZERO_WEIGHTS){if(n==null)return He(et(s),Ce(o.size));{let a=ne(n,Hs(o.shape)),i=je(et(hd(a,Ce(0))),\"float32\");return He(et(s),i)}}throw Error(`Unknown reduction: ${t}`)}var ar=N({computeWeightedLoss_:FH});function OH(r,e,t,o=$t.SUM_BY_NONZERO_WEIGHTS){let n=v(r,\"labels\",\"absoluteDifference\"),s=v(e,\"predictions\",\"absoluteDifference\"),a=null;t!=null&&(a=v(t,\"weights\",\"absoluteDifference\")),gt(n.shape,s.shape,\"Error in absoluteDifference: \");let i=Yt(ke(n,s));return ar(i,a,o)}var W1=N({absoluteDifference_:OH});function PH(r,e,t,o,n=$t.SUM_BY_NONZERO_WEIGHTS){let s=v(r,\"labels\",\"cosineDistance\"),a=v(e,\"predictions\",\"cosineDistance\"),i=null;o!=null&&(i=v(o,\"weights\",\"cosineDistance\")),gt(s.shape,a.shape,\"Error in cosineDistance: \");let p=Ce(1),u=ke(p,et(ne(s,a),t,!0));return ar(u,i,n)}var U1=N({cosineDistance_:PH});function MH(r,e,t,o=$t.SUM_BY_NONZERO_WEIGHTS){let n=v(r,\"labels\",\"hingeLoss\"),s=v(e,\"predictions\",\"hingeLoss\"),a=null;t!=null&&(a=v(t,\"weights\",\"hingeLoss\")),gt(n.shape,s.shape,\"Error in hingeLoss: \");let i=Ce(1);n=ke(ne(Ce(2),n),i);let p=Fi(ke(i,ne(n,s)));return ar(p,a,o)}var G1=N({hingeLoss_:MH});function LH(r,e,t,o=1,n=$t.SUM_BY_NONZERO_WEIGHTS){let s=v(r,\"labels\",\"huberLoss\"),a=v(e,\"predictions\",\"huberLoss\"),i=null;t!=null&&(i=v(t,\"weights\",\"huberLoss\")),gt(s.shape,a.shape,\"Error in huberLoss: \");let p=Ce(o),u=Yt(ke(a,s)),c=fd(u,p),l=ke(u,c),m=be(ne(Ce(.5),Qt(c)),ne(p,l));return ar(m,i,n)}var H1=N({huberLoss_:LH});function BH(r,e,t,o=1e-7,n=$t.SUM_BY_NONZERO_WEIGHTS){let s=v(r,\"labels\",\"logLoss\"),a=v(e,\"predictions\",\"logLoss\"),i=null;t!=null&&(i=v(t,\"weights\",\"logLoss\")),gt(s.shape,a.shape,\"Error in logLoss: \");let p=Ce(1),u=Ce(o),c=Cr(ne(s,Da(be(a,u)))),l=ne(ke(p,s),Da(be(ke(p,a),u))),m=ke(c,l);return ar(m,i,n)}var K1=N({logLoss_:BH});function VH(r,e,t,o=$t.SUM_BY_NONZERO_WEIGHTS){let n=v(r,\"labels\",\"meanSquaredError\"),s=v(e,\"predictions\",\"meanSquaredError\"),a=null;t!=null&&(a=v(t,\"weights\",\"meanSquaredError\")),gt(n.shape,s.shape,\"Error in meanSquaredError: \");let i=_d(n,s);return ar(i,a,o)}var q1=N({meanSquaredError_:VH});function zH(r,e){let t=v(r,\"labels\",\"sigmoidCrossEntropyWithLogits\"),o=v(e,\"logits\",\"sigmoidCrossEntropyWithLogits\");gt(t.shape,o.shape,\"Error in sigmoidCrossEntropyWithLogits: \");let n=Fi(o),s=ne(o,t),a=sd(So(Cr(Yt(o))));return be(ke(n,s),a)}function WH(r,e,t,o=0,n=$t.SUM_BY_NONZERO_WEIGHTS){let s=v(r,\"multiClassLabels\",\"sigmoidCrossEntropy\"),a=v(e,\"logits\",\"sigmoidCrossEntropy\"),i=null;if(t!=null&&(i=v(t,\"weights\",\"sigmoidCrossEntropy\")),gt(s.shape,a.shape,\"Error in sigmoidCrossEntropy: \"),o>0){let u=Ce(o),c=Ce(1),l=Ce(.5);s=be(ne(s,ke(c,u)),ne(l,u))}let p=zH(s,a);return ar(p,i,n)}var j1=N({sigmoidCrossEntropy_:WH});function UH(r,e,t=-1){if(t===-1&&(t=e.rank-1),t!==e.rank-1)throw Error(`Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank ${e.rank} and dim was ${t}`);return br((n,s,a)=>{let p=ud(s,[t],!0),u=ke(je(s,\"float32\"),p);a([n,u]);let c=Cr(ne(u,n));return{value:et(c,[t]),gradFunc:(d,f)=>{let[h,g]=f,x=Ea(d.shape,[t]);return[ne(W(d,x),ke(je(h,\"float32\"),So(g))),ne(W(d,x),ke(So(g),je(h,\"float32\")))]}}})(r,e)}function GH(r,e,t,o=0,n=$t.SUM_BY_NONZERO_WEIGHTS){let s=v(r,\"onehotLabels\",\"softmaxCrossEntropy\"),a=v(e,\"logits\",\"softmaxCrossEntropy\"),i=null;if(t!=null&&(i=v(t,\"weights\",\"softmaxCrossEntropy\")),gt(s.shape,a.shape,\"Error in softmaxCrossEntropy: \"),o>0){let u=Ce(o),c=Ce(1),l=Ce(s.shape[1]);s=be(ne(s,ke(c,u)),He(u,l))}let p=UH(s,a);return ar(p,i,n)}var X1=N({softmaxCrossEntropy_:GH});function HH(r,e,t,o){let n=v(r,\"indices\",\"sparseFillEmptyRows\",\"int32\"),s=v(e,\"values\",\"sparseFillEmptyRows\"),a=v(t,\"denseShape\",\"sparseFillEmptyRows\",\"int32\"),i=v(o,\"defaultValue\",\"sparseFillEmptyRows\",s.dtype);if(n.rank!==2)throw new Error(`Indices should be Tensor2D but received shape\n ${n.shape}`);if(s.rank!==1)throw new Error(`Values should be Tensor1D but received shape ${s.shape}`);if(a.rank!==1)throw new Error(`Dense shape should be Tensor1D but received shape ${a.shape}`);if(i.rank!==0)throw new Error(`Default value should be a scalar but received shape ${i.shape}`);let p={indices:n,values:s,denseShape:a,defaultValue:i},u=T.runKernel(hi,p);return{outputIndices:u[0],outputValues:u[1],emptyRowIndicator:u[2],reverseIndexMap:u[3]}}var Y1=N({sparseFillEmptyRows_:HH});function KH(r,e,t){let o=v(r,\"inputIndices\",\"sparseReshape\",\"int32\"),n=v(e,\"inputShape\",\"sparseReshape\",\"int32\"),s=v(t,\"newShape\",\"sparseReshape\",\"int32\");if(o.rank!==2)throw new Error(`Input indices should be Tensor2D but received shape\n ${o.shape}`);if(n.rank!==1)throw new Error(`Input shape should be Tensor1D but received shape ${n.shape}`);if(s.rank!==1)throw new Error(`New shape should be Tensor1D but received shape ${s.shape}`);let a={inputIndices:o,inputShape:n,newShape:s},i=T.runKernel(va,a);return{outputIndices:i[0],outputShape:i[1]}}var Q1=N({sparseReshape_:KH});function qH(r,e,t){let o=v(r,\"data\",\"sparseSegmentMean\"),n=v(e,\"indices\",\"sparseSegmentMean\",\"int32\"),s=v(t,\"segmentIds\",\"sparseSegmentMean\",\"int32\");if(o.rank<1)throw new Error(\"Data should be at least 1 dimensional but received scalar\");if(n.rank!==1)throw new Error(`Indices should be Tensor1D but received shape\n ${n.shape}`);if(s.rank!==1)throw new Error(`Segment ids should be Tensor1D but received shape\n ${s.shape}`);let a={data:o,indices:n,segmentIds:s};return T.runKernel(gi,a)}var Z1=N({sparseSegmentMean_:qH});function jH(r,e,t){let o=v(r,\"data\",\"sparseSegmentSum\"),n=v(e,\"indices\",\"sparseSegmentSum\",\"int32\"),s=v(t,\"segmentIds\",\"sparseSegmentSum\",\"int32\");if(o.rank<1)throw new Error(\"Data should be at least 1 dimensional but received scalar\");if(n.rank!==1)throw new Error(`Indices should be Tensor1D but received shape\n ${n.shape}`);if(s.rank!==1)throw new Error(`Segment ids should be Tensor1D but received shape\n ${s.shape}`);let a={data:o,indices:n,segmentIds:s};return T.runKernel(xi,a)}var J1=N({sparseSegmentSum_:jH});function XH(r,e,t,o,n,s,a,i){let p=v(r,\"data\",\"stringNGrams\",\"string\");if(p.dtype!==\"string\")throw new Error(\"Data must be of datatype string\");if(p.shape.length!==1)throw new Error(`Data must be a vector, saw: ${p.shape}`);let u=v(e,\"dataSplits\",\"stringNGrams\");if(u.dtype!==\"int32\")throw new Error(\"Data splits must be of datatype int32\");let c={separator:t,nGramWidths:o,leftPad:n,rightPad:s,padWidth:a,preserveShortSequences:i},l={data:p,dataSplits:u},m=T.runKernel(Ds,l,c);return{nGrams:m[0],nGramsSplits:m[1]}}var eN=N({stringNGrams_:XH});function YH(r,e,t=!0){let o=v(r,\"input\",\"stringSplit\",\"string\"),n=v(e,\"delimiter\",\"stringSplit\",\"string\");if(o.rank!==1)throw new Error(`Input should be Tensor1D but received shape ${o.shape}`);if(n.rank!==0)throw new Error(`Delimiter should be a scalar but received shape ${n.shape}`);let s={skipEmpty:t},a={input:o,delimiter:n},i=T.runKernel(Ci,a,s);return{indices:i[0],values:i[1],shape:i[2]}}var tN=N({stringSplit_:YH});function QH(r,e){let t=v(r,\"input\",\"stringToHashBucketFast\",\"string\"),o={numBuckets:e};if(e<=0)throw new Error(\"Number of buckets must be at least 1\");let n={input:t};return T.runKernel(Si,n,o)}var rN=N({stringToHashBucketFast_:QH});var ZH={fft:zp,ifft:du,rfft:Wp,irfft:Td},JH={hammingWindow:C1,hannWindow:Fd,frame:Od,stft:S1},eK={flipLeftRight:I1,grayscaleToRGB:v1,resizeNearestNeighbor:O1,resizeBilinear:F1,rotateWithOffset:k1,cropAndResize:w1,nonMaxSuppression:N1,nonMaxSuppressionAsync:$1,nonMaxSuppressionWithScore:E1,nonMaxSuppressionWithScoreAsync:A1,nonMaxSuppressionPadded:R1,nonMaxSuppressionPaddedAsync:D1,threshold:P1,transform:M1},tK={bandPart:L1,gramSchmidt:B1,qr:z1},rK={absoluteDifference:W1,computeWeightedLoss:ar,cosineDistance:U1,hingeLoss:G1,huberLoss:H1,logLoss:K1,meanSquaredError:q1,sigmoidCrossEntropy:j1,softmaxCrossEntropy:X1},oK={sparseFillEmptyRows:Y1,sparseReshape:Q1,sparseSegmentMean:Z1,sparseSegmentSum:J1},nK={stringNGrams:eN,stringSplit:tN,stringToHashBucketFast:rN};var oN={};Ge(oN,{Serializable:()=>il,SerializationMap:()=>qs,registerClass:()=>IC});var il=class{getClassName(){return this.constructor.className}static fromConfig(e,t){return new e(t)}},qs=class{constructor(){this.classNameMap={}}static getMap(){return qs.instance==null&&(qs.instance=new qs),qs.instance}static register(e){qs.getMap().classNameMap[e.className]=[e,e.fromConfig]}};function IC(r){$(r.className!=null,()=>\"Class being registered does not have the static className property defined.\"),$(typeof r.className==\"string\",()=>\"className is required to be a string, but got type \"+typeof r.className),$(r.className.length>0,()=>\"Class being registered has an empty-string as its className, which is disallowed.\"),qs.register(r)}var wr=class extends il{minimize(e,t=!1,o){let{value:n,grads:s}=this.computeGradients(e,o);if(o!=null){let a=o.map(i=>({name:i.name,tensor:s[i.name]}));this.applyGradients(a)}else this.applyGradients(s);return Ot(s),t?n:(n.dispose(),null)}get iterations(){return this.iterations_==null&&(this.iterations_=0),this.iterations_}incrementIterations(){this.iterations_=this.iterations+1}computeGradients(e,t){return pC(e,t)}dispose(){this.iterations_!=null&&Ot(this.iterations_)}async saveIterations(){return this.iterations_==null&&(this.iterations_=0),{name:\"iter\",tensor:Ce(this.iterations_,\"int32\")}}async getWeights(){throw new Error(\"getWeights() is not implemented for this optimizer yet.\")}async setWeights(e){throw new Error(`setWeights() is not implemented for this optimizer class ${this.getClassName()}`)}async extractIterations(e){return this.iterations_=(await e[0].tensor.data())[0],e.slice(1)}};Object.defineProperty(wr,Symbol.hasInstance,{value:r=>r.minimize!=null&&r.computeGradients!=null&&r.applyGradients!=null});var yu=class extends wr{constructor(e,t,o=null){super(),this.learningRate=e,this.rho=t,this.epsilon=o,this.accumulatedGrads=[],this.accumulatedUpdates=[],o==null&&(this.epsilon=T.backend.epsilon())}static get className(){return\"Adadelta\"}applyGradients(e){(Array.isArray(e)?e.map(o=>o.name):Object.keys(e)).forEach((o,n)=>{let s=T.registeredVariables[o],a=!1;this.accumulatedGrads[n]==null&&(this.accumulatedGrads[n]={originalName:`${o}/accum_grad`,variable:Ee(()=>Ut(s).variable(a))}),this.accumulatedUpdates[n]==null&&(this.accumulatedUpdates[n]={originalName:`${o}/accum_var`,variable:Ee(()=>Ut(s).variable(a))});let i=Array.isArray(e)?e[n].tensor:e[o];if(i==null)return;let p=this.accumulatedGrads[n].variable,u=this.accumulatedUpdates[n].variable;Ee(()=>{let c=be(ne(p,this.rho),ne(Qt(i),1-this.rho)),l=ne(He($r(be(u,this.epsilon)),$r(be(p,this.epsilon))),i),m=be(ne(u,this.rho),ne(Qt(l),1-this.rho));p.assign(c),u.assign(m);let d=be(ne(l,-this.learningRate),s);s.assign(d)})}),this.incrementIterations()}dispose(){this.accumulatedUpdates!=null&&(Ot(this.accumulatedGrads.map(e=>e.variable)),Ot(this.accumulatedUpdates.map(e=>e.variable)))}async getWeights(){let e=[...this.accumulatedGrads,...this.accumulatedUpdates];return[await this.saveIterations()].concat(e.map(t=>({name:t.originalName,tensor:t.variable})))}async setWeights(e){e=await this.extractIterations(e);let t=e.length/2,o=!1;this.accumulatedGrads=e.slice(0,t).map(n=>({originalName:n.name,variable:n.tensor.variable(o)})),this.accumulatedUpdates=e.slice(t,t*2).map(n=>({originalName:n.name,variable:n.tensor.variable(o)}))}getConfig(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}}static fromConfig(e,t){return new e(t.learningRate,t.rho,t.epsilon)}};var bu=class extends wr{constructor(e,t=.1){super(),this.learningRate=e,this.initialAccumulatorValue=t,this.accumulatedGrads=[]}static get className(){return\"Adagrad\"}applyGradients(e){(Array.isArray(e)?e.map(o=>o.name):Object.keys(e)).forEach((o,n)=>{let s=T.registeredVariables[o];this.accumulatedGrads[n]==null&&(this.accumulatedGrads[n]={originalName:`${o}/accumulator`,variable:Ee(()=>Us(s.shape,this.initialAccumulatorValue).variable(!1))});let a=Array.isArray(e)?e[n].tensor:e[o];if(a==null)return;let i=this.accumulatedGrads[n].variable;Ee(()=>{let p=be(i,Qt(a));i.assign(p);let u=be(ne(He(a,$r(be(p,T.backend.epsilon()))),-this.learningRate),s);s.assign(u)})}),this.incrementIterations()}dispose(){this.accumulatedGrads!=null&&Ot(this.accumulatedGrads.map(e=>e.variable))}async getWeights(){return[await this.saveIterations()].concat(this.accumulatedGrads.map(e=>({name:e.originalName,tensor:e.variable})))}async setWeights(e){e=await this.extractIterations(e);let t=!1;this.accumulatedGrads=e.map(o=>({originalName:o.name,variable:o.tensor.variable(t)}))}getConfig(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}}static fromConfig(e,t){return new e(t.learningRate,t.initialAccumulatorValue)}};var Cu=class extends wr{constructor(e,t,o,n=null){super(),this.learningRate=e,this.beta1=t,this.beta2=o,this.epsilon=n,this.accumulatedFirstMoment=[],this.accumulatedSecondMoment=[],Ee(()=>{this.accBeta1=Ce(t).variable(),this.accBeta2=Ce(o).variable()}),n==null&&(this.epsilon=T.backend.epsilon())}static get className(){return\"Adam\"}applyGradients(e){let t=Array.isArray(e)?e.map(o=>o.name):Object.keys(e);Ee(()=>{let o=ke(1,this.accBeta1),n=ke(1,this.accBeta2);t.forEach((s,a)=>{let i=T.registeredVariables[s],p=!1;this.accumulatedFirstMoment[a]==null&&(this.accumulatedFirstMoment[a]={originalName:`${s}/m`,variable:Ee(()=>Ut(i).variable(p))}),this.accumulatedSecondMoment[a]==null&&(this.accumulatedSecondMoment[a]={originalName:`${s}/v`,variable:Ee(()=>Ut(i).variable(p))});let u=Array.isArray(e)?e[a].tensor:e[s];if(u==null)return;let c=this.accumulatedFirstMoment[a].variable,l=this.accumulatedSecondMoment[a].variable,m=be(ne(c,this.beta1),ne(u,1-this.beta1)),d=be(ne(l,this.beta2),ne(Qt(u),1-this.beta2)),f=He(m,o),h=He(d,n);c.assign(m),l.assign(d);let g=be(ne(He(f,be($r(h),this.epsilon)),-this.learningRate),i);i.assign(g)}),this.accBeta1.assign(ne(this.accBeta1,this.beta1)),this.accBeta2.assign(ne(this.accBeta2,this.beta2))}),this.incrementIterations()}dispose(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&Ot(this.accumulatedFirstMoment.map(e=>e.variable)),this.accumulatedSecondMoment!=null&&Ot(this.accumulatedSecondMoment.map(e=>e.variable))}async getWeights(){let e=[...this.accumulatedFirstMoment,...this.accumulatedSecondMoment];return[await this.saveIterations()].concat(e.map(t=>({name:t.originalName,tensor:t.variable})))}async setWeights(e){e=await this.extractIterations(e),Ee(()=>{this.accBeta1.assign(Aa(this.beta1,this.iterations_+1)),this.accBeta2.assign(Aa(this.beta2,this.iterations_+1))});let t=e.length/2,o=!1;this.accumulatedFirstMoment=e.slice(0,t).map(n=>({originalName:n.name,variable:n.tensor.variable(o)})),this.accumulatedSecondMoment=e.slice(t,t*2).map(n=>({originalName:n.name,variable:n.tensor.variable(o)}))}getConfig(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}}static fromConfig(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)}};var Su=class extends wr{constructor(e,t,o,n=null,s=0){super(),this.learningRate=e,this.beta1=t,this.beta2=o,this.epsilon=n,this.decay=s,this.accumulatedFirstMoment=[],this.accumulatedWeightedInfNorm=[],Ee(()=>{this.iteration=Ce(0).variable(),this.accBeta1=Ce(t).variable()}),n==null&&(this.epsilon=T.backend.epsilon())}static get className(){return\"Adamax\"}applyGradients(e){let t=Array.isArray(e)?e.map(o=>o.name):Object.keys(e);Ee(()=>{let o=ke(1,this.accBeta1),n=He(-this.learningRate,be(ne(this.iteration,this.decay),1));t.forEach((s,a)=>{let i=T.registeredVariables[s],p=!1;this.accumulatedFirstMoment[a]==null&&(this.accumulatedFirstMoment[a]={originalName:`${s}/m`,variable:Ut(i).variable(p)}),this.accumulatedWeightedInfNorm[a]==null&&(this.accumulatedWeightedInfNorm[a]={originalName:`${s}/v`,variable:Ut(i).variable(p)});let u=Array.isArray(e)?e[a].tensor:e[s];if(u==null)return;let c=this.accumulatedFirstMoment[a].variable,l=this.accumulatedWeightedInfNorm[a].variable,m=be(ne(c,this.beta1),ne(u,1-this.beta1)),d=ne(l,this.beta2),f=Yt(u),h=dd(d,f);c.assign(m),l.assign(h);let g=be(ne(He(n,o),He(m,be(h,this.epsilon))),i);i.assign(g)}),this.iteration.assign(be(this.iteration,1)),this.accBeta1.assign(ne(this.accBeta1,this.beta1))}),this.incrementIterations()}dispose(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&Ot(this.accumulatedFirstMoment.map(e=>e.variable)),this.accumulatedWeightedInfNorm!=null&&Ot(this.accumulatedWeightedInfNorm.map(e=>e.variable))}async getWeights(){throw new Error(\"getWeights() is not implemented for Adamax yet.\")}async setWeights(e){throw new Error(\"setWeights() is not implemented for Adamax yet.\")}getConfig(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}}static fromConfig(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)}};var Pa=class extends wr{constructor(e){super(),this.learningRate=e,this.setLearningRate(e)}static get className(){return\"SGD\"}applyGradients(e){(Array.isArray(e)?e.map(o=>o.name):Object.keys(e)).forEach((o,n)=>{let s=Array.isArray(e)?e[n].tensor:e[o];if(s==null)return;let a=T.registeredVariables[o];Ee(()=>{let i=be(ne(this.c,s),a);a.assign(i)})}),this.incrementIterations()}setLearningRate(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=_r(Ce(-e))}dispose(){this.c.dispose()}async getWeights(){return[await this.saveIterations()]}async setWeights(e){if(e=await this.extractIterations(e),e.length!==0)throw new Error(\"SGD optimizer does not have settable weights.\")}getConfig(){return{learningRate:this.learningRate}}static fromConfig(e,t){return new e(t.learningRate)}};var wu=class extends Pa{constructor(e,t,o=!1){super(e),this.learningRate=e,this.momentum=t,this.useNesterov=o,this.accumulations=[],this.m=Ce(this.momentum)}static get className(){return\"Momentum\"}applyGradients(e){(Array.isArray(e)?e.map(o=>o.name):Object.keys(e)).forEach((o,n)=>{let s=T.registeredVariables[o];this.accumulations[n]==null&&(this.accumulations[n]={originalName:`${o}/momentum`,variable:Ee(()=>Ut(s).variable(!1))});let a=this.accumulations[n].variable,i=Array.isArray(e)?e[n].tensor:e[o];i!=null&&Ee(()=>{let p,u=be(ne(this.m,a),i);this.useNesterov?p=be(ne(this.c,be(i,ne(u,this.m))),s):p=be(ne(this.c,u),s),a.assign(u),s.assign(p)})}),this.incrementIterations()}dispose(){this.m.dispose(),this.accumulations!=null&&Ot(this.accumulations.map(e=>e.variable))}setMomentum(e){this.momentum=e}async getWeights(){return[await this.saveIterations()].concat(this.accumulations.map(e=>({name:e.originalName,tensor:e.variable})))}async setWeights(e){e=await this.extractIterations(e);let t=!1;this.accumulations=e.map(o=>({originalName:o.name,variable:o.tensor.variable(t)}))}getConfig(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}}static fromConfig(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)}};var Iu=class extends wr{constructor(e,t=.9,o=0,n=null,s=!1){if(super(),this.learningRate=e,this.decay=t,this.momentum=o,this.epsilon=n,this.accumulatedMeanSquares=[],this.accumulatedMoments=[],this.accumulatedMeanGrads=[],this.centered=s,n==null&&(this.epsilon=T.backend.epsilon()),e==null)throw new Error(\"learningRate for RMSPropOptimizer must be defined.\")}static get className(){return\"RMSProp\"}applyGradients(e){(Array.isArray(e)?e.map(o=>o.name):Object.keys(e)).forEach((o,n)=>{let s=T.registeredVariables[o],a=!1;this.accumulatedMeanSquares[n]==null&&(this.accumulatedMeanSquares[n]={originalName:`${o}/rms`,variable:Ee(()=>Ut(s).variable(a))}),this.accumulatedMoments[n]==null&&(this.accumulatedMoments[n]={originalName:`${o}/momentum`,variable:Ee(()=>Ut(s).variable(a))}),this.accumulatedMeanGrads[n]==null&&this.centered&&(this.accumulatedMeanGrads[n]={originalName:`${o}/mg`,variable:Ee(()=>Ut(s).variable(a))});let i=Array.isArray(e)?e[n].tensor:e[o];if(i==null)return;let p=this.accumulatedMeanSquares[n].variable,u=this.accumulatedMoments[n].variable;Ee(()=>{let c=be(ne(p,this.decay),ne(Qt(i),1-this.decay));if(this.centered){let l=this.accumulatedMeanGrads[n].variable,m=be(ne(l,this.decay),ne(i,1-this.decay)),d=He(ne(i,this.learningRate),$r(ke(c,be(Qt(m),this.epsilon)))),f=be(ne(u,this.momentum),d);p.assign(c),l.assign(m),u.assign(f);let h=ke(s,f);s.assign(h)}else{let l=be(ne(p,this.decay),ne(Qt(i),1-this.decay)),m=be(ne(u,this.momentum),He(ne(i,this.learningRate),$r(be(l,this.epsilon))));p.assign(l),u.assign(m);let d=ke(s,m);s.assign(d)}})}),this.incrementIterations()}dispose(){this.accumulatedMeanSquares!=null&&Ot(this.accumulatedMeanSquares.map(e=>e.variable)),this.accumulatedMeanGrads!=null&&this.centered&&Ot(this.accumulatedMeanGrads.map(e=>e.variable)),this.accumulatedMoments!=null&&Ot(this.accumulatedMoments.map(e=>e.variable))}async getWeights(){let e=[...this.accumulatedMeanSquares,...this.accumulatedMoments];return this.centered&&e.push(...this.accumulatedMeanGrads),[await this.saveIterations()].concat(e.map(t=>({name:t.originalName,tensor:t.variable})))}async setWeights(e){e=await this.extractIterations(e);let t=this.centered?e.length/3:e.length/2,o=!1;this.accumulatedMeanSquares=e.slice(0,t).map(n=>({originalName:n.name,variable:n.tensor.variable(o)})),this.accumulatedMoments=e.slice(t,t*2).map(n=>({originalName:n.name,variable:n.tensor.variable(o)})),this.centered&&(this.accumulatedMeanGrads=e.slice(t*2,t*3).map(n=>({originalName:n.name,variable:n.tensor.variable(o)})))}getConfig(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}}static fromConfig(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)}};var sK=[yu,bu,Cu,Su,wu,Iu,Pa];function nN(){for(let r of sK)IC(r)}var La={};Ge(La,{browserFiles:()=>aN,browserHTTPRequest:()=>pN,concatenateArrayBuffers:()=>Fp,copyModel:()=>V0,decodeWeights:()=>Bm,encodeWeights:()=>v0,fromMemory:()=>cN,fromMemorySync:()=>$C,getLoadHandlers:()=>E0,getModelArtifactsForJSON:()=>Op,getModelArtifactsForJSONSync:()=>Qb,getModelArtifactsInfoForJSON:()=>Ms,getSaveHandlers:()=>$0,getWeightSpecs:()=>zm,http:()=>Vd,isHTTPScheme:()=>Bd,listModels:()=>L0,loadWeights:()=>iN,moveModel:()=>z0,registerLoadRouter:()=>_0,registerSaveRouter:()=>T0,removeModel:()=>B0,weightsLoaderFactory:()=>TC,withSaveHandler:()=>lN,withSaveHandlerSync:()=>mN});var aK=\"model\",iK=\".json\",uK=\".weights.bin\";function sN(r){return new Promise(e=>setTimeout(e)).then(r)}var Ma=class{constructor(e){if(!O().getBool(\"IS_BROWSER\"))throw new Error(\"browserDownloads() cannot proceed because the current environment is not a browser.\");e.startsWith(Ma.URL_SCHEME)&&(e=e.slice(Ma.URL_SCHEME.length)),(e==null||e.length===0)&&(e=aK),this.modelJsonFileName=e+iK,this.weightDataFileName=e+uK}async save(e){if(typeof document==\"undefined\")throw new Error(\"Browser downloads are not supported in this environment since `document` is not present\");let t=window.URL.createObjectURL(new Blob([e.weightData],{type:\"application/octet-stream\"}));if(e.modelTopology instanceof ArrayBuffer)throw new Error(\"BrowserDownloads.save() does not support saving model topology in binary formats yet.\");{let o=[{paths:[\"./\"+this.weightDataFileName],weights:e.weightSpecs}],n=Vm(e,o),s=window.URL.createObjectURL(new Blob([JSON.stringify(n)],{type:\"application/json\"})),a=this.modelJsonAnchor==null?document.createElement(\"a\"):this.modelJsonAnchor;if(a.download=this.modelJsonFileName,a.href=s,await sN(()=>a.dispatchEvent(new MouseEvent(\"click\"))),e.weightData!=null){let i=this.weightDataAnchor==null?document.createElement(\"a\"):this.weightDataAnchor;i.download=this.weightDataFileName,i.href=t,await sN(()=>i.dispatchEvent(new MouseEvent(\"click\")))}return{modelArtifactsInfo:Ms(e)}}}};Ma.URL_SCHEME=\"downloads://\";var vC=class{constructor(e){if(e==null||e.length<1)throw new Error(`When calling browserFiles, at least 1 file is required, but received ${e}`);this.jsonFile=e[0],this.weightsFiles=e.slice(1)}async load(){return new Promise((e,t)=>{let o=new FileReader;o.onload=n=>{let s=JSON.parse(n.target.result),a=s.modelTopology;if(a==null){t(new Error(`modelTopology field is missing from file ${this.jsonFile.name}`));return}if(s.weightsManifest==null){t(new Error(`weightManifest field is missing from file ${this.jsonFile.name}`));return}if(this.weightsFiles.length===0){e({modelTopology:a});return}let p=Op(s,u=>this.loadWeights(u));e(p)},o.onerror=n=>t(`Failed to read model topology and weights manifest JSON from file '${this.jsonFile.name}'. BrowserFiles supports loading Keras-style tf.Model artifacts only.`),o.readAsText(this.jsonFile)})}loadWeights(e){let t=[],o=[];for(let a of e)t.push(...a.weights),o.push(...a.paths);let n=this.checkManifestAndWeightFiles(e),s=o.map(a=>this.loadWeightsFile(a,n[a]));return Promise.all(s).then(a=>[t,Fp(a)])}loadWeightsFile(e,t){return new Promise((o,n)=>{let s=new FileReader;s.onload=a=>{let i=a.target.result;o(i)},s.onerror=a=>n(`Failed to weights data from file of path '${e}'.`),s.readAsArrayBuffer(t)})}checkManifestAndWeightFiles(e){let t=[],o=this.weightsFiles.map(s=>Yb(s.name)),n={};for(let s of e)s.paths.forEach(a=>{let i=Yb(a);if(t.indexOf(i)!==-1)throw new Error(`Duplicate file basename found in weights manifest: '${i}'`);if(t.push(i),o.indexOf(i)===-1)throw new Error(`Weight file with basename '${i}' is not provided.`);n[a]=this.weightsFiles[o.indexOf(i)]});if(t.length!==this.weightsFiles.length)throw new Error(`Mismatch in the number of files in weights manifest (${t.length}) and the number of weight files provided (${this.weightsFiles.length}).`);return n}},pK=r=>O().getBool(\"IS_BROWSER\")&&!Array.isArray(r)&&r.startsWith(Ma.URL_SCHEME)?cK(r.slice(Ma.URL_SCHEME.length)):null;mt.registerSaveRouter(pK);function cK(r=\"model\"){return new Ma(r)}function aN(r){return new vC(r)}function kC(r,e,t,o){a(r),t=t==null?0:t,o=o==null?1:o,i(t,o);let n=0,s=p=>(p.then(u=>{let c=t+ ++n/r.length*(o-t);return e(c),u}),p);function a(p){$(p!=null&&Array.isArray(p)&&p.length>0,()=>\"promises must be a none empty array\")}function i(p,u){$(p>=0&&p<=1,()=>`Progress fraction must be in range [0, 1], but got startFraction ${p}`),$(u>=0&&u<=1,()=>`Progress fraction must be in range [0, 1], but got endFraction ${u}`),$(u>=p,()=>`startFraction must be no more than endFraction, but got startFraction ${p} and endFraction ${u}`)}return Promise.all(r.map(s))}async function NC(r,e){e==null&&(e={});let t=e.fetchFunc==null?O().platform.fetch:e.fetchFunc,o=r.map(l=>t(l,e.requestInit,{isBinary:!0})),n=0,s=.5,i=(e.onProgress==null?await Promise.all(o):await kC(o,e.onProgress,n,s)).map(l=>l.arrayBuffer()),p=.5,u=1;return e.onProgress==null?await Promise.all(i):await kC(i,e.onProgress,p,u)}async function iN(r,e=\"\",t,o){return TC(a=>NC(a,{requestInit:o}))(r,e,t)}function TC(r){return async(e,t=\"\",o)=>{let n=e.map(()=>!1),s={},a=o!=null?o.map(()=>!1):[],i=[];if(e.forEach((d,f)=>{let h=0;d.weights.forEach(g=>{let x=\"quantization\"in g?g.quantization.dtype:g.dtype,b=Zc[x]*We(g.shape),C=()=>{n[f]=!0,s[f]==null&&(s[f]=[]),s[f].push({manifestEntry:g,groupOffset:h,sizeBytes:b})};o!=null?o.forEach((w,k)=>{w===g.name&&(C(),a[k]=!0)}):C(),i.push(g.name),h+=b})}),!a.every(d=>d)){let d=o.filter((f,h)=>!a[h]);throw new Error(`Could not find weights in manifest with names: ${d.join(\", \")}. \nManifest JSON has weights with names: ${i.join(\", \")}.`)}let p=n.reduce((d,f,h)=>(f&&d.push(h),d),[]),u=[];p.forEach(d=>{e[d].paths.forEach(f=>{let h=t+(t.endsWith(\"/\")?\"\":\"/\")+f;u.push(h)})});let c=await r(u),l={},m=0;return p.forEach(d=>{let f=e[d].paths.length,h=0;for(let w=0;w{let k=g.slice(w.groupOffset,w.groupOffset+w.sizeBytes),_=Bm(k,[w.manifestEntry]);for(let E in _)l[E]=_[E]}),m+=f}),l}}var lK=\"application/octet-stream\",mK=\"application/json\",ul=class{constructor(e,t){if(this.DEFAULT_METHOD=\"POST\",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?($(typeof t.fetchFunc==\"function\",()=>\"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)\"),this.fetch=t.fetchFunc):this.fetch=O().platform.fetch,$(e!=null&&e.length>0,()=>\"URL path for http must not be null, undefined or empty.\"),Array.isArray(e)&&$(e.length===2,()=>`URL paths for http must have a length of 2, (actual length is ${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error(\"requestInit is expected to have no pre-existing body, but has one.\");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error(\"BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.\");let t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;let o=[{paths:[\"./model.weights.bin\"],weights:e.weightSpecs}],n=Vm(e,o);t.body.append(\"model.json\",new Blob([JSON.stringify(n)],{type:mK}),\"model.json\"),e.weightData!=null&&t.body.append(\"model.weights.bin\",new Blob([e.weightData],{type:lK}),\"model.weights.bin\");let s=await this.fetch(this.path,t);if(s.ok)return{modelArtifactsInfo:Ms(e),responses:[s]};throw new Error(`BrowserHTTPRequest.save() failed due to HTTP response status ${s.status}.`)}async load(){let e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Request to ${this.path} failed with status code ${e.status}. Please verify this URL points to the model JSON of the model to load.`);let t;try{t=await e.json()}catch(s){let a=`Failed to parse model JSON of response from ${this.path}.`;throw this.path.endsWith(\".pb\")?a+=\" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.\":a+=\" Please make sure the server is serving valid JSON for this request.\",new Error(a)}let o=t.modelTopology,n=t.weightsManifest;if(o==null&&n==null)throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);return Op(t,s=>this.loadWeights(s))}async loadWeights(e){let t=Array.isArray(this.path)?this.path[1]:this.path,[o,n]=dK(t),s=this.weightPathPrefix||o,a=zm(e),i=[],p=[];for(let c of e)for(let l of c.paths)this.weightUrlConverter!=null?p.push(this.weightUrlConverter(l)):i.push(s+l+n);this.weightUrlConverter&&i.push(...await Promise.all(p));let u=await NC(i,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[a,Fp(u)]}};ul.URL_SCHEME_REGEX=/^https?:\\/\\//;function dK(r){let e=r.lastIndexOf(\"/\"),t=r.lastIndexOf(\"?\"),o=r.substring(0,e),n=t>e?r.substring(t):\"\";return[o+\"/\",n]}function Bd(r){return r.match(ul.URL_SCHEME_REGEX)!=null}var uN=(r,e)=>{if(typeof fetch==\"undefined\"&&(e==null||e.fetchFunc==null))return null;{let t=!0;if(Array.isArray(r)?t=r.every(o=>Bd(o)):t=Bd(r),t)return Vd(r,e)}return null};mt.registerSaveRouter(uN);mt.registerLoadRouter(uN);function Vd(r,e){return new ul(r,e)}function pN(r,e){return Vd(r,e)}var pl=class{constructor(e){this.modelArtifacts=e}load(){return this.modelArtifacts}},zd=class{constructor(e){this.saveHandler=e}save(e){return this.saveHandler(e)}},_C=class{constructor(e){e.load&&(this.load=()=>Promise.resolve(e.load())),e.save&&(this.save=t=>Promise.resolve(e.save(t)))}};function cN(r,e,t,o){let n=arguments;return new _C($C(...n))}function $C(r,e,t,o){return arguments.length===1?r.modelTopology!=null||r.weightSpecs!=null?new pl(r):(console.warn(\"Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release.\"),new pl({modelTopology:r})):(console.warn(\"Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release.\"),new pl({modelTopology:r,weightSpecs:e,weightData:t,trainingConfig:o}))}function lN(r){return new zd(r)}function mN(r){return new zd(r)}var fN={};Ge(fN,{confusionMatrix:()=>dN});function fK(r,e,t){let o=v(r,\"labels\",\"confusionMatrix\"),n=v(e,\"predictions\",\"confusionMatrix\");$(t==null||t>0&&Number.isInteger(t),()=>`If provided, numClasses must be a positive integer, but got ${t}`),$(o.rank===1,()=>`Expected the rank of labels to be 1, but got ${o.rank}`),$(n.rank===1,()=>`Expected the rank of predictions to be 1, but got ${n.rank}`),$(o.shape[0]===n.shape[0],()=>`Mismatch in the number of examples: ${o.shape[0]} vs. ${n.shape[0]}. Labels and predictions should have the same number of elements.`),$(t>0&&Number.isInteger(t),()=>`numClasses is required to be a positive integer, but got ${t}`);let s=nl(je(o,\"int32\"),t),a=nl(je(n,\"int32\"),t),i=Gp(s),p=Xe(i,a);return je(p,\"int32\")}var dN=N({confusionMatrix_:fK});var gN={};Ge(gN,{fromPixels:()=>SK,fromPixelsAsync:()=>bK,toPixels:()=>CK});var vu;function hN(r,e=3){if(e>4)throw new Error(\"Cannot construct Tensor with more than 4 channels from pixels.\");if(r==null)throw new Error(\"pixels passed to tf.browser.fromPixels() can not be null\");let t=!1,o=!1,n=!1,s=!1,a=!1,i=!1;if(r.data instanceof Uint8Array)t=!0;else if(typeof ImageData!=\"undefined\"&&r instanceof ImageData)o=!0;else if(typeof HTMLVideoElement!=\"undefined\"&&r instanceof HTMLVideoElement)n=!0;else if(typeof HTMLImageElement!=\"undefined\"&&r instanceof HTMLImageElement)s=!0;else if(r.getContext!=null)a=!0;else if(typeof ImageBitmap!=\"undefined\"&&r instanceof ImageBitmap)i=!0;else throw new Error(`pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was ${r.constructor.name}`);if(Kc(Zi,T.backendName)!=null){let f={pixels:r},h={numChannels:e};return T.runKernel(Zi,f,h)}let[u,c]=n?[r.videoWidth,r.videoHeight]:[r.width,r.height],l;if(a)l=r.getContext(\"2d\").getImageData(0,0,u,c).data;else if(o||t)l=r.data;else if(s||n||i){if(vu==null)if(typeof document==\"undefined\")if(typeof OffscreenCanvas!=\"undefined\"&&typeof OffscreenCanvasRenderingContext2D!=\"undefined\")vu=new OffscreenCanvas(1,1).getContext(\"2d\");else throw new Error(\"Cannot parse input in current context. Reason: OffscreenCanvas Context2D rendering is not supported.\");else vu=document.createElement(\"canvas\").getContext(\"2d\",{willReadFrequently:!0});vu.canvas.width=u,vu.canvas.height=c,vu.drawImage(r,0,0,u,c),l=vu.getImageData(0,0,u,c).data}let m;if(e===4)m=new Int32Array(l);else{let f=u*c;m=new Int32Array(f*e);for(let h=0;h4||s===2)throw new Error(`toPixels only supports depth of size 1, 3 or 4 but got ${s}`);if(t.dtype!==\"float32\"&&t.dtype!==\"int32\")throw new Error(`Unsupported type for toPixels: ${t.dtype}. Please use float32 or int32 tensors.`);let a=await t.data(),i=t.dtype===\"float32\"?255:1,p=new Uint8ClampedArray(n*o*4);for(let u=0;u1)throw new Error(`Tensor values for a float32 Tensor must be in the range [0 - 1] but encountered ${d}.`)}else if(t.dtype===\"int32\"&&(d<0||d>255))throw new Error(`Tensor values for a int32 Tensor must be in the range [0 - 255] but encountered ${d}.`);s===1?(c[0]=d*i,c[1]=d*i,c[2]=d*i):c[m]=d*i}let l=u*4;p[l+0]=Math.round(c[0]),p[l+1]=Math.round(c[1]),p[l+2]=Math.round(c[2]),p[l+3]=Math.round(c[3])}if(e!=null){e.width=n,e.height=o;let u=e.getContext(\"2d\"),c=new ImageData(p,n,o);u.putImageData(c,0,0)}return t!==r&&t.dispose(),p}var SK=N({fromPixels_:hN});var Wd={};Ge(Wd,{prepareAndValidate:()=>xN});function xN(r,e){let t=r.shape.length,o=e.shape.length;if(t<1)throw new Error(`tf.gatherND() expects the input to be rank 1 or higher, but the rank was ${t}.`);if(o<1)throw new Error(`tf.gatherND() expects the indices to be rank 1 or higher, but the rank was ${o}.`);if(e.dtype!==\"int32\")throw new Error(`tf.gatherND() expects the indices to be int32 type, but the dtype was ${e.dtype}.`);if(e.shape[o-1]>t)throw new Error(`index innermost dimension length must be <= tensor rank; saw: ${e.shape[o-1]} vs. ${t}`);if(We(r.shape)===0)throw new Error(`Requested more than 0 entries, but input is empty. Input shape: ${r.shape}.`);let n=e.shape,s=n[n.length-1],a=1;for(let l=0;ll/u),1].slice(0,s);return[p,a,u,c]}var ut={};Ge(ut,{assertParamsValid:()=>IK,computeFlatOffset:()=>_K,computeOutShape:()=>kK,getNormalizedAxes:()=>NK,isSliceContinous:()=>TK,maskToAxes:()=>vK,parseSliceParams:()=>$K,sliceInfo:()=>EK,startForAxis:()=>kN,startIndicesWithElidedDims:()=>wN,stopForAxis:()=>NN,stopIndicesWithElidedDims:()=>IN,stridesForAxis:()=>vN,stridesWithElidedDims:()=>bN});var EC=-2,wK=-1;function IK(r,e,t){let o=r.shape.length;$(o===e.length,()=>`Error in slice${o}D: Length of begin ${e} must match the rank of the array (${o}).`),$(o===t.length,()=>`Error in slice${o}D: Length of size ${t} must match the rank of the array (${o}).`);for(let n=0;n`Error in slice${o}D: begin[${n}] + size[${n}] (${e[n]+t[n]}) would overflow input.shape[${n}] (${r.shape[n]})`)}function vK(r){let e=[],t=0;for(;r>0;)r&1&&e.push(t),r/=2,t++;return e}function kK(r,e,t){let o=[];for(let n=0;n0){let d=e[0],f=t+1;c=wN(a,d,f,o,r),l=IN(i,d,f,n,r),m=bN(s,d,f,r)}else for(let d=0;d-1)s[i]=0;else{let p=CN(e,t,i),u=o[p];r&1<-1)s[i]=Number.MAX_SAFE_INTEGER;else{let p=CN(e,t,i),u=o[p];r&1<
0?a=Number.MIN_SAFE_INTEGER:a=Number.MAX_SAFE_INTEGER);let p=o[n];return a<0&&(a+=p),a=ip(0,a,p-1),a}function NN(r,e,t,o,n,s){let a=e[n],i=t[n]||1;(r&1<0?a=Number.MAX_SAFE_INTEGER:a=Number.MIN_SAFE_INTEGER);let p=o[n];return a<0&&(a+=p),i>0?a=ip(0,a,p):a=ip(-1,a,p-1),a}function TK(r,e,t){let o=t.length;for(let n=0;n1){o=n;break}for(let n=o+1;n0||t[n]!==r[n])return!1;return!0}function _K(r,e){let t=r.length>0?r[r.length-1]:1;for(let o=0;o{$(a!==-1,()=>\"slice() does not support negative begin indexing.\")});let s;return t==null?s=new Array(n).fill(-1):typeof t==\"number\"?s=[t,...new Array(n-1).fill(-1)]:t.lengtha>=0?a:($(a===-1,()=>`Negative size values should be exactly -1 but got ${a} for the slice() size at index ${i}.`),r.shape[i]-o[i])),[o,s]}function EK(r,e,t,o,n,s,a,i,p){let u;if(o==null?(u=new Array(e.length),u.fill(1)):u=o,a!=null&&a&a-1)throw new Error(\"Multiple ellipses in slice is not allowed.\");let c=!1,l={dims:u.length,numAddAxisAfterEllipsis:0,begin:e.slice(),end:t.slice(),strides:u.slice(),beginMask:n,endMask:s,ellipsisMask:a,newAxisMask:i,shrinkAxisMask:p};for(let C=0;C0?0:-1,m.strides[C]>0?k:k-1];if(w&&m.strides[C]<=0)throw Error(\"only stride 1 allowed on non-range indexing.\");h=h&&m.strides[C]===1;let A=!!(m.beginMask&1<