shared-ritm 1.2.78 → 1.2.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(g){return g instanceof this?g:new this(g)}static concat(g,...B){const Q=new this(g);return B.forEach(w=>Q.set(w)),Q}static accessor(g){const Q=(this[cM]=this[cM]={accessors:{}}).accessors,w=this.prototype;function C(E){const e=lC(E);Q[e]||(Sl(w,E),Q[e]=!0)}return q.isArray(g)?g.forEach(C):C(g),this}};Yg.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),q.reduceDescriptors(Yg.prototype,({value:A},g)=>{let B=g[0].toUpperCase()+g.slice(1);return{get:()=>A,set(Q){this[B]=Q}}}),q.freezeMethods(Yg);function Do(A,g){const B=this||hC,Q=g||B,w=Yg.from(Q.headers);let C=Q.data;return q.forEach(A,function(e){C=e.call(B,C,w.normalize(),g?g.status:void 0)}),w.normalize(),C}function DM(A){return!!(A&&A.__CANCEL__)}function vw(A,g,B){LA.call(this,A??"canceled",LA.ERR_CANCELED,g,B),this.name="CanceledError"}q.inherits(vw,LA,{__CANCEL__:!0});function rM(A,g,B){const Q=B.config.validateStatus;!B.status||!Q||Q(B.status)?A(B):g(new LA("Request failed with status code "+B.status,[LA.ERR_BAD_REQUEST,LA.ERR_BAD_RESPONSE][Math.floor(B.status/100)-4],B.config,B.request,B))}function Ll(A){const g=/^([-+\w]{1,25})(:?\/\/|:)/.exec(A);return g&&g[1]||""}function bl(A,g){A=A||10;const B=new Array(A),Q=new Array(A);let w=0,C=0,E;return g=g!==void 0?g:1e3,function(I){const o=Date.now(),n=Q[C];E||(E=o),B[w]=I,Q[w]=o;let i=C,Y=0;for(;i!==w;)Y+=B[i++],i=i%A;if(w=(w+1)%A,w===C&&(C=(C+1)%A),o-E<g)return;const M=n&&o-n;return M?Math.round(Y*1e3/M):void 0}}function Kl(A,g){let B=0,Q=1e3/g,w,C;const E=(o,n=Date.now())=>{B=n,w=null,C&&(clearTimeout(C),C=null),A.apply(null,o)};return[(...o)=>{const n=Date.now(),i=n-B;i>=Q?E(o,n):(w=o,C||(C=setTimeout(()=>{C=null,E(w)},Q-i)))},()=>w&&E(w)]}const WE=(A,g,B=3)=>{let Q=0;const w=bl(50,250);return Kl(C=>{const E=C.loaded,e=C.lengthComputable?C.total:void 0,I=E-Q,o=w(I),n=E<=e;Q=E;const i={loaded:E,total:e,progress:e?E/e:void 0,bytes:I,rate:o||void 0,estimated:o&&e&&n?(e-E)/o:void 0,event:C,lengthComputable:e!=null,[g?"download":"upload"]:!0};A(i)},B)},FM=(A,g)=>{const B=A!=null;return[Q=>g[0]({lengthComputable:B,total:A,loaded:Q}),g[1]]},aM=A=>(...g)=>q.asap(()=>A(...g)),Vl=Bg.hasStandardBrowserEnv?((A,g)=>B=>(B=new URL(B,Bg.origin),A.protocol===B.protocol&&A.host===B.host&&(g||A.port===B.port)))(new URL(Bg.origin),Bg.navigator&&/(msie|trident)/i.test(Bg.navigator.userAgent)):()=>!0,xl=Bg.hasStandardBrowserEnv?{write(A,g,B,Q,w,C){const E=[A+"="+encodeURIComponent(g)];q.isNumber(B)&&E.push("expires="+new Date(B).toGMTString()),q.isString(Q)&&E.push("path="+Q),q.isString(w)&&E.push("domain="+w),C===!0&&E.push("secure"),document.cookie=E.join("; ")},read(A){const g=document.cookie.match(new RegExp("(^|;\\s*)("+A+")=([^;]*)"));return g?decodeURIComponent(g[3]):null},remove(A){this.write(A,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Xl(A){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(A)}function Ol(A,g){return g?A.replace(/\/?\/$/,"")+"/"+g.replace(/^\/+/,""):A}function sM(A,g,B){let Q=!Xl(g);return A&&(Q||B==!1)?Ol(A,g):g}const uM=A=>A instanceof Yg?{...A}:A;function _Q(A,g){g=g||{};const B={};function Q(o,n,i,Y){return q.isPlainObject(o)&&q.isPlainObject(n)?q.merge.call({caseless:Y},o,n):q.isPlainObject(n)?q.merge({},n):q.isArray(n)?n.slice():n}function w(o,n,i,Y){if(q.isUndefined(n)){if(!q.isUndefined(o))return Q(void 0,o,i,Y)}else return Q(o,n,i,Y)}function C(o,n){if(!q.isUndefined(n))return Q(void 0,n)}function E(o,n){if(q.isUndefined(n)){if(!q.isUndefined(o))return Q(void 0,o)}else return Q(void 0,n)}function e(o,n,i){if(i in g)return Q(o,n);if(i in A)return Q(void 0,o)}const I={url:C,method:C,data:C,baseURL:E,transformRequest:E,transformResponse:E,paramsSerializer:E,timeout:E,timeoutMessage:E,withCredentials:E,withXSRFToken:E,adapter:E,responseType:E,xsrfCookieName:E,xsrfHeaderName:E,onUploadProgress:E,onDownloadProgress:E,decompress:E,maxContentLength:E,maxBodyLength:E,beforeRedirect:E,transport:E,httpAgent:E,httpsAgent:E,cancelToken:E,socketPath:E,responseEncoding:E,validateStatus:e,headers:(o,n,i)=>w(uM(o),uM(n),i,!0)};return q.forEach(Object.keys(Object.assign({},A,g)),function(n){const i=I[n]||w,Y=i(A[n],g[n],n);q.isUndefined(Y)&&i!==e||(B[n]=Y)}),B}const UM=A=>{const g=_Q({},A);let{data:B,withXSRFToken:Q,xsrfHeaderName:w,xsrfCookieName:C,headers:E,auth:e}=g;g.headers=E=Yg.from(E),g.url=nM(sM(g.baseURL,g.url,g.allowAbsoluteUrls),A.params,A.paramsSerializer),e&&E.set("Authorization","Basic "+btoa((e.username||"")+":"+(e.password?unescape(encodeURIComponent(e.password)):"")));let I;if(q.isFormData(B)){if(Bg.hasStandardBrowserEnv||Bg.hasStandardBrowserWebWorkerEnv)E.setContentType(void 0);else if((I=E.getContentType())!==!1){const[o,...n]=I?I.split(";").map(i=>i.trim()).filter(Boolean):[];E.setContentType([o||"multipart/form-data",...n].join("; "))}}if(Bg.hasStandardBrowserEnv&&(Q&&q.isFunction(Q)&&(Q=Q(g)),Q||Q!==!1&&Vl(g.url))){const o=w&&C&&xl.read(C);o&&E.set(w,o)}return g},Zl=typeof XMLHttpRequest<"u"&&function(A){return new Promise(function(B,Q){const w=UM(A);let C=w.data;const E=Yg.from(w.headers).normalize();let{responseType:e,onUploadProgress:I,onDownloadProgress:o}=w,n,i,Y,M,c;function D(){M&&M(),c&&c(),w.cancelToken&&w.cancelToken.unsubscribe(n),w.signal&&w.signal.removeEventListener("abort",n)}let r=new XMLHttpRequest;r.open(w.method.toUpperCase(),w.url,!0),r.timeout=w.timeout;function F(){if(!r)return;const u=Yg.from("getAllResponseHeaders"in r&&r.getAllResponseHeaders()),U={data:!e||e==="text"||e==="json"?r.responseText:r.response,status:r.status,statusText:r.statusText,headers:u,config:A,request:r};rM(function(d){B(d),D()},function(d){Q(d),D()},U),r=null}"onloadend"in r?r.onloadend=F:r.onreadystatechange=function(){!r||r.readyState!==4||r.status===0&&!(r.responseURL&&r.responseURL.indexOf("file:")===0)||setTimeout(F)},r.onabort=function(){r&&(Q(new LA("Request aborted",LA.ECONNABORTED,A,r)),r=null)},r.onerror=function(){Q(new LA("Network Error",LA.ERR_NETWORK,A,r)),r=null},r.ontimeout=function(){let a=w.timeout?"timeout of "+w.timeout+"ms exceeded":"timeout exceeded";const U=w.transitional||YM;w.timeoutErrorMessage&&(a=w.timeoutErrorMessage),Q(new LA(a,U.clarifyTimeoutError?LA.ETIMEDOUT:LA.ECONNABORTED,A,r)),r=null},C===void 0&&E.setContentType(null),"setRequestHeader"in r&&q.forEach(E.toJSON(),function(a,U){r.setRequestHeader(U,a)}),q.isUndefined(w.withCredentials)||(r.withCredentials=!!w.withCredentials),e&&e!=="json"&&(r.responseType=w.responseType),o&&([Y,c]=WE(o,!0),r.addEventListener("progress",Y)),I&&r.upload&&([i,M]=WE(I),r.upload.addEventListener("progress",i),r.upload.addEventListener("loadend",M)),(w.cancelToken||w.signal)&&(n=u=>{r&&(Q(!u||u.type?new vw(null,A,r):u),r.abort(),r=null)},w.cancelToken&&w.cancelToken.subscribe(n),w.signal&&(w.signal.aborted?n():w.signal.addEventListener("abort",n)));const s=Ll(w.url);if(s&&Bg.protocols.indexOf(s)===-1){Q(new LA("Unsupported protocol "+s+":",LA.ERR_BAD_REQUEST,A));return}r.send(C||null)})},ql=(A,g)=>{const{length:B}=A=A?A.filter(Boolean):[];if(g||B){let Q=new AbortController,w;const C=function(o){if(!w){w=!0,e();const n=o instanceof Error?o:this.reason;Q.abort(n instanceof LA?n:new vw(n instanceof Error?n.message:n))}};let E=g&&setTimeout(()=>{E=null,C(new LA(`timeout ${g} of ms exceeded`,LA.ETIMEDOUT))},g);const e=()=>{A&&(E&&clearTimeout(E),E=null,A.forEach(o=>{o.unsubscribe?o.unsubscribe(C):o.removeEventListener("abort",C)}),A=null)};A.forEach(o=>o.addEventListener("abort",C));const{signal:I}=Q;return I.unsubscribe=()=>q.asap(e),I}},_l=function*(A,g){let B=A.byteLength;if(B<g){yield A;return}let Q=0,w;for(;Q<B;)w=Q+g,yield A.slice(Q,w),Q=w},$l=async function*(A,g){for await(const B of Ad(A))yield*_l(B,g)},Ad=async function*(A){if(A[Symbol.asyncIterator]){yield*A;return}const g=A.getReader();try{for(;;){const{done:B,value:Q}=await g.read();if(B)break;yield Q}}finally{await g.cancel()}},GM=(A,g,B,Q)=>{const w=$l(A,g);let C=0,E,e=I=>{E||(E=!0,Q&&Q(I))};return new ReadableStream({async pull(I){try{const{done:o,value:n}=await w.next();if(o){e(),I.close();return}let i=n.byteLength;if(B){let Y=C+=i;B(Y)}I.enqueue(new Uint8Array(n))}catch(o){throw e(o),o}},cancel(I){return e(I),w.return()}},{highWaterMark:2})},SE=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",hM=SE&&typeof ReadableStream=="function",Bd=SE&&(typeof TextEncoder=="function"?(A=>g=>A.encode(g))(new TextEncoder):async A=>new Uint8Array(await new Response(A).arrayBuffer())),lM=(A,...g)=>{try{return!!A(...g)}catch{return!1}},gd=hM&&lM(()=>{let A=!1;const g=new Request(Bg.origin,{body:new ReadableStream,method:"POST",get duplex(){return A=!0,"half"}}).headers.has("Content-Type");return A&&!g}),dM=64*1024,ro=hM&&lM(()=>q.isReadableStream(new Response("").body)),LE={stream:ro&&(A=>A.body)};SE&&(A=>{["text","arrayBuffer","blob","formData","stream"].forEach(g=>{!LE[g]&&(LE[g]=q.isFunction(A[g])?B=>B[g]():(B,Q)=>{throw new LA(`Response type '${g}' is not supported`,LA.ERR_NOT_SUPPORT,Q)})})})(new Response);const Qd=async A=>{if(A==null)return 0;if(q.isBlob(A))return A.size;if(q.isSpecCompliantForm(A))return(await new Request(Bg.origin,{method:"POST",body:A}).arrayBuffer()).byteLength;if(q.isArrayBufferView(A)||q.isArrayBuffer(A))return A.byteLength;if(q.isURLSearchParams(A)&&(A=A+""),q.isString(A))return(await Bd(A)).byteLength},wd=async(A,g)=>{const B=q.toFiniteNumber(A.getContentLength());return B??Qd(g)},Fo={http:ll,xhr:Zl,fetch:SE&&(async A=>{let{url:g,method:B,data:Q,signal:w,cancelToken:C,timeout:E,onDownloadProgress:e,onUploadProgress:I,responseType:o,headers:n,withCredentials:i="same-origin",fetchOptions:Y}=UM(A);o=o?(o+"").toLowerCase():"text";let M=ql([w,C&&C.toAbortSignal()],E),c;const D=M&&M.unsubscribe&&(()=>{M.unsubscribe()});let r;try{if(I&&gd&&B!=="get"&&B!=="head"&&(r=await wd(n,Q))!==0){let U=new Request(g,{method:"POST",body:Q,duplex:"half"}),G;if(q.isFormData(Q)&&(G=U.headers.get("content-type"))&&n.setContentType(G),U.body){const[d,H]=FM(r,WE(aM(I)));Q=GM(U.body,dM,d,H)}}q.isString(i)||(i=i?"include":"omit");const F="credentials"in Request.prototype;c=new Request(g,{...Y,signal:M,method:B.toUpperCase(),headers:n.normalize().toJSON(),body:Q,duplex:"half",credentials:F?i:void 0});let s=await fetch(c);const u=ro&&(o==="stream"||o==="response");if(ro&&(e||u&&D)){const U={};["status","statusText","headers"].forEach(h=>{U[h]=s[h]});const G=q.toFiniteNumber(s.headers.get("content-length")),[d,H]=e&&FM(G,WE(aM(e),!0))||[];s=new Response(GM(s.body,dM,d,()=>{H&&H(),D&&D()}),U)}o=o||"text";let a=await LE[q.findKey(LE,o)||"text"](s,A);return!u&&D&&D(),await new Promise((U,G)=>{rM(U,G,{data:a,headers:Yg.from(s.headers),status:s.status,statusText:s.statusText,config:A,request:c})})}catch(F){throw D&&D(),F&&F.name==="TypeError"&&/Load failed|fetch/i.test(F.message)?Object.assign(new LA("Network Error",LA.ERR_NETWORK,A,c),{cause:F.cause||F}):LA.from(F,F&&F.code,A,c)}})};q.forEach(Fo,(A,g)=>{if(A){try{Object.defineProperty(A,"name",{value:g})}catch{}Object.defineProperty(A,"adapterName",{value:g})}});const HM=A=>`- ${A}`,Cd=A=>q.isFunction(A)||A===null||A===!1,fM={getAdapter:A=>{A=q.isArray(A)?A:[A];const{length:g}=A;let B,Q;const w={};for(let C=0;C<g;C++){B=A[C];let E;if(Q=B,!Cd(B)&&(Q=Fo[(E=String(B)).toLowerCase()],Q===void 0))throw new LA(`Unknown adapter '${E}'`);if(Q)break;w[E||"#"+C]=Q}if(!Q){const C=Object.entries(w).map(([e,I])=>`adapter ${e} `+(I===!1?"is not supported by the environment":"is not available in the build"));let E=g?C.length>1?`since :
5
5
  `+C.map(HM).join(`
6
6
  `):" "+HM(C[0]):"as no adapter specified";throw new LA("There is no suitable adapter to dispatch the request "+E,"ERR_NOT_SUPPORT")}return Q},adapters:Fo};function ao(A){if(A.cancelToken&&A.cancelToken.throwIfRequested(),A.signal&&A.signal.aborted)throw new vw(null,A)}function JM(A){return ao(A),A.headers=Yg.from(A.headers),A.data=Do.call(A,A.transformRequest),["post","put","patch"].indexOf(A.method)!==-1&&A.headers.setContentType("application/x-www-form-urlencoded",!1),fM.getAdapter(A.adapter||hC.adapter)(A).then(function(Q){return ao(A),Q.data=Do.call(A,A.transformResponse,Q),Q.headers=Yg.from(Q.headers),Q},function(Q){return DM(Q)||(ao(A),Q&&Q.response&&(Q.response.data=Do.call(A,A.transformResponse,Q.response),Q.response.headers=Yg.from(Q.response.headers))),Promise.reject(Q)})}const NM="1.9.0",bE={};["object","boolean","number","function","string","symbol"].forEach((A,g)=>{bE[A]=function(Q){return typeof Q===A||"a"+(g<1?"n ":" ")+A}});const mM={};bE.transitional=function(g,B,Q){function w(C,E){return"[Axios v"+NM+"] Transitional option '"+C+"'"+E+(Q?". "+Q:"")}return(C,E,e)=>{if(g===!1)throw new LA(w(E," has been removed"+(B?" in "+B:"")),LA.ERR_DEPRECATED);return B&&!mM[E]&&(mM[E]=!0,console.warn(w(E," has been deprecated since v"+B+" and will be removed in the near future"))),g?g(C,E,e):!0}},bE.spelling=function(g){return(B,Q)=>(console.warn(`${Q} is likely a misspelling of ${g}`),!0)};function Ed(A,g,B){if(typeof A!="object")throw new LA("options must be an object",LA.ERR_BAD_OPTION_VALUE);const Q=Object.keys(A);let w=Q.length;for(;w-- >0;){const C=Q[w],E=g[C];if(E){const e=A[C],I=e===void 0||E(e,C,A);if(I!==!0)throw new LA("option "+C+" must be "+I,LA.ERR_BAD_OPTION_VALUE);continue}if(B!==!0)throw new LA("Unknown option "+C,LA.ERR_BAD_OPTION)}}const KE={assertOptions:Ed,validators:bE},xg=KE.validators;let $Q=class{constructor(g){this.defaults=g||{},this.interceptors={request:new iM,response:new iM}}async request(g,B){try{return await this._request(g,B)}catch(Q){if(Q instanceof Error){let w={};Error.captureStackTrace?Error.captureStackTrace(w):w=new Error;const C=w.stack?w.stack.replace(/^.+\n/,""):"";try{Q.stack?C&&!String(Q.stack).endsWith(C.replace(/^.+\n.+\n/,""))&&(Q.stack+=`
7
- `+C):Q.stack=C}catch{}}throw Q}}_request(g,B){typeof g=="string"?(B=B||{},B.url=g):B=g||{},B=_Q(this.defaults,B);const{transitional:Q,paramsSerializer:w,headers:C}=B;Q!==void 0&&KE.assertOptions(Q,{silentJSONParsing:xg.transitional(xg.boolean),forcedJSONParsing:xg.transitional(xg.boolean),clarifyTimeoutError:xg.transitional(xg.boolean)},!1),w!=null&&(q.isFunction(w)?B.paramsSerializer={serialize:w}:KE.assertOptions(w,{encode:xg.function,serialize:xg.function},!0)),B.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?B.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:B.allowAbsoluteUrls=!0),KE.assertOptions(B,{baseUrl:xg.spelling("baseURL"),withXsrfToken:xg.spelling("withXSRFToken")},!0),B.method=(B.method||this.defaults.method||"get").toLowerCase();let E=C&&q.merge(C.common,C[B.method]);C&&q.forEach(["delete","get","head","post","put","patch","common"],c=>{delete C[c]}),B.headers=Yg.concat(E,C);const e=[];let I=!0;this.interceptors.request.forEach(function(D){typeof D.runWhen=="function"&&D.runWhen(B)===!1||(I=I&&D.synchronous,e.unshift(D.fulfilled,D.rejected))});const o=[];this.interceptors.response.forEach(function(D){o.push(D.fulfilled,D.rejected)});let n,i=0,Y;if(!I){const c=[JM.bind(this),void 0];for(c.unshift.apply(c,e),c.push.apply(c,o),Y=c.length,n=Promise.resolve(B);i<Y;)n=n.then(c[i++],c[i++]);return n}Y=e.length;let M=B;for(i=0;i<Y;){const c=e[i++],D=e[i++];try{M=c(M)}catch(r){D.call(this,r);break}}try{n=JM.call(this,M)}catch(c){return Promise.reject(c)}for(i=0,Y=o.length;i<Y;)n=n.then(o[i++],o[i++]);return n}getUri(g){g=_Q(this.defaults,g);const B=sM(g.baseURL,g.url,g.allowAbsoluteUrls);return nM(B,g.params,g.paramsSerializer)}};q.forEach(["delete","get","head","options"],function(g){$Q.prototype[g]=function(B,Q){return this.request(_Q(Q||{},{method:g,url:B,data:(Q||{}).data}))}}),q.forEach(["post","put","patch"],function(g){function B(Q){return function(C,E,e){return this.request(_Q(e||{},{method:g,headers:Q?{"Content-Type":"multipart/form-data"}:{},url:C,data:E}))}}$Q.prototype[g]=B(),$Q.prototype[g+"Form"]=B(!0)});let ed=class wF{constructor(g){if(typeof g!="function")throw new TypeError("executor must be a function.");let B;this.promise=new Promise(function(C){B=C});const Q=this;this.promise.then(w=>{if(!Q._listeners)return;let C=Q._listeners.length;for(;C-- >0;)Q._listeners[C](w);Q._listeners=null}),this.promise.then=w=>{let C;const E=new Promise(e=>{Q.subscribe(e),C=e}).then(w);return E.cancel=function(){Q.unsubscribe(C)},E},g(function(C,E,e){Q.reason||(Q.reason=new vw(C,E,e),B(Q.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(g){if(this.reason){g(this.reason);return}this._listeners?this._listeners.push(g):this._listeners=[g]}unsubscribe(g){if(!this._listeners)return;const B=this._listeners.indexOf(g);B!==-1&&this._listeners.splice(B,1)}toAbortSignal(){const g=new AbortController,B=Q=>{g.abort(Q)};return this.subscribe(B),g.signal.unsubscribe=()=>this.unsubscribe(B),g.signal}static source(){let g;return{token:new wF(function(w){g=w}),cancel:g}}};function Id(A){return function(B){return A.apply(null,B)}}function od(A){return q.isObject(A)&&A.isAxiosError===!0}const so={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(so).forEach(([A,g])=>{so[g]=A});function RM(A){const g=new $Q(A),B=ZY($Q.prototype.request,g);return q.extend(B,$Q.prototype,g,{allOwnKeys:!0}),q.extend(B,g,null,{allOwnKeys:!0}),B.create=function(w){return RM(_Q(A,w))},B}const fB=RM(hC);fB.Axios=$Q,fB.CanceledError=vw,fB.CancelToken=ed,fB.isCancel=DM,fB.VERSION=NM,fB.toFormData=yE,fB.AxiosError=LA,fB.Cancel=fB.CanceledError,fB.all=function(g){return Promise.all(g)},fB.spread=Id,fB.isAxiosError=od,fB.mergeConfig=_Q,fB.AxiosHeaders=Yg,fB.formToJSON=A=>MM(q.isHTMLForm(A)?new FormData(A):A),fB.getAdapter=fM.getAdapter,fB.HttpStatusCode=so,fB.default=fB;const{Axios:T4,AxiosError:j4,CanceledError:p4,isCancel:y4,CancelToken:z4,VERSION:W4,all:S4,Cancel:L4,isAxiosError:b4,spread:K4,toFormData:V4,AxiosHeaders:x4,HttpStatusCode:X4,formToJSON:O4,getAdapter:Z4,mergeConfig:q4}=fB;class Gg{constructor(){QF(this,"axiosInstance");this.axiosInstance=fB.create({baseURL:process.env.VUE_APP_BACKEND,headers:{"Content-Type":"application/json",Accept:"application/json"}}),this.axiosInstance.interceptors.request.use(g=>{const B=this.getToken();return B&&g.headers&&(g.headers.Authorization=`Bearer ${B}`),g},g=>Promise.reject(g)),this.axiosInstance.interceptors.response.use(g=>g.data,g=>{var B,Q;return(((B=g.response)==null?void 0:B.status)===401||((Q=g.response)==null?void 0:Q.status)===403)&&this.logout(),Promise.reject(g)})}getToken(){return localStorage.getItem("token")}removeToken(){localStorage.removeItem("token")}logout(){this.removeToken(),window.location.href="/sign-in"}handleError(g){g.response?console.error("API Error:",g.response.status,g.response.data):g.request?console.error("No response received:",g.request):console.error("Error during request setup:",g.message)}async get(g,B){try{const Q=await this.axiosInstance.get(g,B);return(Q==null?void 0:Q.data)===!1?!1:(Q==null?void 0:Q.data)??Q}catch(Q){const w=Q;throw this.handleError(w),Q}}async delete(g,B){try{return await this.axiosInstance.delete(g,B)}catch(Q){const w=Q;throw this.handleError(w),Q}}async post(g,B,Q){try{const w=await this.axiosInstance.post(g,B,Q);return(w==null?void 0:w.data)===!1?!1:(w==null?void 0:w.data)||w}catch(w){const C=w;throw this.handleError(C),w}}async put(g,B,Q){try{return(await this.axiosInstance.put(g,B,Q)).data}catch(w){const C=w;throw this.handleError(C),w}}}class td extends Gg{async fetchCriticalPathTasks(g){return await this.get(`gantt/get_list_task_on_critical_path?${g}`)}async fetchGanttList(g){return await this.get(`/list/tasks/search?${g}&gantt=1`)}}let uo;function nd(){return uo||(uo=new td),uo}class id extends Gg{async fetchPieProjects(g){return await this.get("repairs/pie/projects?"+g)}async fetchPieTasks(g){return await this.get("repairs/pie/tasks?"+g)}async fetchPiePersonnel(g){return await this.get("repairs/metrics/get_list_position?"+g)}async fetchPersonnelData(g){return await this.get("repairs/metrics/list_position_intersection_group_by_status?"+g)}async fetchPersonnelInfo(g){return await this.get(`repairs/metrics/list_position_intersection_details?${g}`)}async fetchPiePersonnelInfo(g){return await this.get(`repairs/metrics/get_list_user_by_position?${g}`)}async fetchPieCriticalPath(g){return await this.get("repairs/metrics/get_critical_path_group_by_status?"+g)}async fetchPieCriticalPathInfo(g){return await this.get(`repairs/metrics/get_list_task_critical_path_by_status?${g}`)}async fetchPieTmc(g){return await this.get("repairs/metrics/get_list_instrument_type?"+g)}async fetchPieTmcInfo(g){return await this.get(`repairs/metrics/get_list_warehouse_by_instrument_type?${g}`)}async fetchPieUntimelyClosedTask(g){return await this.get("repairs/metrics/get_list_comment_type?"+g)}async fetchPieUntimelyClosedTaskInfo(g){return await this.get(`repairs/metrics/get_list_task_by_comment_type?${g}`)}async fetchPieAdditionalTasks(g){return await this.get("repairs/metrics/get_list_task_after_plan_fixate_group_by_status?"+g)}async fetchPieAdditionalTasksInfo(g){return await this.get(`repairs/metrics/get_list_task_after_plan_fixate_by_status?${g}`)}async fetchPersonnel(g){return await this.get("repairs/statistic/personnel?"+g)}async fetchPieExpired(g){return await this.get("repairs/metrics/get_list_task_expired_group_by_status?"+g)}async fetchPieExpiredInfo(g){return await this.get(`repairs/metrics/get_list_task_expired?${g}`)}async fetchEconomicsPerformance(g){return await this.get(`repairs/metrics/get_economic_performance?${g}`)}async fetchEconomicsInfo(g){return await this.get(`repairs/metrics/get_list_task_economic_performance?${g}`)}async fetchQualityMetrics(g){return await this.get(`repairs/metrics/get_quality_metrics?${g}`)}async fetchQualityInfo(g){return await this.get(`repairs/metrics/get_list_task_by_quality?${g}`)}async fetchPieWorkZone(g){return await this.get("repairs/metrics/get_list_work_zone_instrument?"+g)}async fetchWorkZoneInfo(g){return await this.get("repairs/metrics/get_list_work_zone_instrument_by_status?"+g)}async fetchPieAllTasks(g){return await this.get("repairs/metrics/get_list_task_group_by_status?"+g)}async fetchPieAllTasksInfo(g){return await this.get("repairs/metrics/get_list_task_by_status?"+g)}}let Uo;function Yd(){return Uo||(Uo=new id),Uo}class Md extends Gg{async fetchProjectById(g){return this.get(`/projects/${g}`)}createProject(g){return this.post("/projects",g)}editProject(g,B){return this.put(`/projects/${g}`,B)}fetchProjects(g){return this.get("/search/projects",{params:g})}cloneProject(g){return this.post(`projects/${g.id}/clone`,g)}archiveProject(g,B){return this.put(`/projects/${g}`,B)}unArchiveProject(g,B){return this.put(`/projects/${g}`,B)}moveAprProject(g){return this.post("repairs/move_plan_to_real",{repairs:[g]})}restoreProject(g){return this.post("/restore_project",{projects_ids:[g]})}importTasks(g){return this.post("tasks/import",g)}importKtd(g){return this.post("/parse_ktd",g,{headers:{"Content-Type":"multipart/form-data"}})}fetchProjectTeamList(g){return this.put(`/projects/${g}`,null)}deleteProject(g){return this.delete(`/projects/${g}`)}}let Go;function cd(){return Go||(Go=new Md),Go}class Dd extends Gg{fetchFilters(g){return this.get(`get_list_repair?smart=1&${g}`)}fetchRepairs(g,B,Q,w,C){return this.get("get_list_repair"+(g?`${B}&per_page=100000${C?"&"+C:""}&${Q?"":w}`:`?per_page=100000${C?"&"+C:""}&${w}`))}fetchRepairTemplates({equipmentId:g,categoryCode:B}){return this.get(`repairs/get_repair_template_list?per_page=100000&categoryCodeList[0]=${B}&equipmentIdList[0]=${g}`)}fetchEquipment(){return this.get("repairs/equipment/list?per_page=100000")}createRepair(g){return this.post("/repairs/equipments",g)}createRepairFromTemplate(g){return this.post("/repairs/create_repair_from_repair_template",g)}startRepair(g){return this.post(`/repairs/${g}/start`,null)}finishRepair(g){return this.post("/repairs/complete_repair_list",{repairIdList:[g]})}finishPreparationProject(g){return this.post(`/repairs/${g}/finish_preparation`,null)}moveRepairToCurrent(g){return this.post("/repairs/transfer_repair_plan_to_current",{repairs:[g]})}moveArchiveToCurrent(g){return this.post("/repairs/transfer_repair_archive_to_current",{repairs_ids:[g]})}moveRepairToApr(g){return this.post("/repairs/transfer_repair_current_to_plan",{repairs:[g]})}moveRepairToArchive(g){return this.post("/repairs/transfer_repair_current_to_archive",{repairs_ids:[g]})}restoreRepair(g){return this.post("/restore_repair",{repairs_ids:[g]})}updateRepair(g,B){return this.put(`/repairs/${B}`,g)}copyRepair(g){return this.post(`/repairs/${g}/clone`,null)}deleteRepair(g){return this.delete(`/repairs/${g}`)}}let ho;function rd(){return ho||(ho=new Dd),ho}class Fd extends Gg{login(g,B){return this.post("/login",{email:g,password:B})}loginPhoto(g){return this.post("/login/from_photo",{photo:g})}logout(){return this.post("/logout",null)}userInfo(){return this.get("/users/auth")}configs(){return this.get("/configs")}changePassword(g,B,Q){return this.put(`/users/${g}/password`,{password:B,password_confirmation:Q})}}let lo;function ad(){return lo||(lo=new Fd),lo}class sd extends Gg{uploadFile(g){return this.post("/upload-file",g,{headers:{"Content-Type":"multipart/form-data"}})}}let Ho;function ud(){return Ho||(Ho=new sd),Ho}class Ud extends Gg{async startVideoAnalytics(){return await this.post("/statanly/start",null)}}let fo;function Gd(){return fo||(fo=new Ud),fo}class hd extends Gg{async editUser({id:g,model:B}){return await this.put(`/admin/users/${g}`,B)}async getUser(g){return await this.get(`/admin/users/${g}`)}}let Jo;function ld(){return Jo||(Jo=new hd),Jo}/**
7
+ `+C):Q.stack=C}catch{}}throw Q}}_request(g,B){typeof g=="string"?(B=B||{},B.url=g):B=g||{},B=_Q(this.defaults,B);const{transitional:Q,paramsSerializer:w,headers:C}=B;Q!==void 0&&KE.assertOptions(Q,{silentJSONParsing:xg.transitional(xg.boolean),forcedJSONParsing:xg.transitional(xg.boolean),clarifyTimeoutError:xg.transitional(xg.boolean)},!1),w!=null&&(q.isFunction(w)?B.paramsSerializer={serialize:w}:KE.assertOptions(w,{encode:xg.function,serialize:xg.function},!0)),B.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?B.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:B.allowAbsoluteUrls=!0),KE.assertOptions(B,{baseUrl:xg.spelling("baseURL"),withXsrfToken:xg.spelling("withXSRFToken")},!0),B.method=(B.method||this.defaults.method||"get").toLowerCase();let E=C&&q.merge(C.common,C[B.method]);C&&q.forEach(["delete","get","head","post","put","patch","common"],c=>{delete C[c]}),B.headers=Yg.concat(E,C);const e=[];let I=!0;this.interceptors.request.forEach(function(D){typeof D.runWhen=="function"&&D.runWhen(B)===!1||(I=I&&D.synchronous,e.unshift(D.fulfilled,D.rejected))});const o=[];this.interceptors.response.forEach(function(D){o.push(D.fulfilled,D.rejected)});let n,i=0,Y;if(!I){const c=[JM.bind(this),void 0];for(c.unshift.apply(c,e),c.push.apply(c,o),Y=c.length,n=Promise.resolve(B);i<Y;)n=n.then(c[i++],c[i++]);return n}Y=e.length;let M=B;for(i=0;i<Y;){const c=e[i++],D=e[i++];try{M=c(M)}catch(r){D.call(this,r);break}}try{n=JM.call(this,M)}catch(c){return Promise.reject(c)}for(i=0,Y=o.length;i<Y;)n=n.then(o[i++],o[i++]);return n}getUri(g){g=_Q(this.defaults,g);const B=sM(g.baseURL,g.url,g.allowAbsoluteUrls);return nM(B,g.params,g.paramsSerializer)}};q.forEach(["delete","get","head","options"],function(g){$Q.prototype[g]=function(B,Q){return this.request(_Q(Q||{},{method:g,url:B,data:(Q||{}).data}))}}),q.forEach(["post","put","patch"],function(g){function B(Q){return function(C,E,e){return this.request(_Q(e||{},{method:g,headers:Q?{"Content-Type":"multipart/form-data"}:{},url:C,data:E}))}}$Q.prototype[g]=B(),$Q.prototype[g+"Form"]=B(!0)});let ed=class wF{constructor(g){if(typeof g!="function")throw new TypeError("executor must be a function.");let B;this.promise=new Promise(function(C){B=C});const Q=this;this.promise.then(w=>{if(!Q._listeners)return;let C=Q._listeners.length;for(;C-- >0;)Q._listeners[C](w);Q._listeners=null}),this.promise.then=w=>{let C;const E=new Promise(e=>{Q.subscribe(e),C=e}).then(w);return E.cancel=function(){Q.unsubscribe(C)},E},g(function(C,E,e){Q.reason||(Q.reason=new vw(C,E,e),B(Q.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(g){if(this.reason){g(this.reason);return}this._listeners?this._listeners.push(g):this._listeners=[g]}unsubscribe(g){if(!this._listeners)return;const B=this._listeners.indexOf(g);B!==-1&&this._listeners.splice(B,1)}toAbortSignal(){const g=new AbortController,B=Q=>{g.abort(Q)};return this.subscribe(B),g.signal.unsubscribe=()=>this.unsubscribe(B),g.signal}static source(){let g;return{token:new wF(function(w){g=w}),cancel:g}}};function Id(A){return function(B){return A.apply(null,B)}}function od(A){return q.isObject(A)&&A.isAxiosError===!0}const so={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(so).forEach(([A,g])=>{so[g]=A});function RM(A){const g=new $Q(A),B=ZY($Q.prototype.request,g);return q.extend(B,$Q.prototype,g,{allOwnKeys:!0}),q.extend(B,g,null,{allOwnKeys:!0}),B.create=function(w){return RM(_Q(A,w))},B}const fB=RM(hC);fB.Axios=$Q,fB.CanceledError=vw,fB.CancelToken=ed,fB.isCancel=DM,fB.VERSION=NM,fB.toFormData=yE,fB.AxiosError=LA,fB.Cancel=fB.CanceledError,fB.all=function(g){return Promise.all(g)},fB.spread=Id,fB.isAxiosError=od,fB.mergeConfig=_Q,fB.AxiosHeaders=Yg,fB.formToJSON=A=>MM(q.isHTMLForm(A)?new FormData(A):A),fB.getAdapter=fM.getAdapter,fB.HttpStatusCode=so,fB.default=fB;const{Axios:T4,AxiosError:j4,CanceledError:p4,isCancel:y4,CancelToken:z4,VERSION:W4,all:S4,Cancel:L4,isAxiosError:b4,spread:K4,toFormData:V4,AxiosHeaders:x4,HttpStatusCode:X4,formToJSON:O4,getAdapter:Z4,mergeConfig:q4}=fB;class Gg{constructor(){QF(this,"axiosInstance");this.axiosInstance=fB.create({baseURL:process.env.VUE_APP_BACKEND,headers:{"Content-Type":"application/json",Accept:"application/json"}}),this.axiosInstance.interceptors.request.use(g=>{const B=this.getToken();return B&&g.headers&&(g.headers.Authorization=`Bearer ${B}`),g},g=>Promise.reject(g)),this.axiosInstance.interceptors.response.use(g=>g.data,g=>{var B,Q;return(((B=g.response)==null?void 0:B.status)===401||((Q=g.response)==null?void 0:Q.status)===403)&&this.logout(),Promise.reject(g)})}getToken(){return localStorage.getItem("token")}removeToken(){localStorage.removeItem("token")}logout(){this.removeToken(),window.location.href="/sign-in"}handleError(g){g.response?console.error("API Error:",g.response.status,g.response.data):g.request?console.error("No response received:",g.request):console.error("Error during request setup:",g.message)}async get(g,B){try{const Q=await this.axiosInstance.get(g,B);return(Q==null?void 0:Q.data)===!1?!1:(Q==null?void 0:Q.data)??Q}catch(Q){const w=Q;throw this.handleError(w),Q}}async delete(g,B){try{return await this.axiosInstance.delete(g,B)}catch(Q){const w=Q;throw this.handleError(w),Q}}async post(g,B,Q){try{const w=await this.axiosInstance.post(g,B,Q);return(w==null?void 0:w.data)===!1?!1:(w==null?void 0:w.data)||w}catch(w){const C=w;throw this.handleError(C),w}}async put(g,B,Q){try{return(await this.axiosInstance.put(g,B,Q)).data}catch(w){const C=w;throw this.handleError(C),w}}}class td extends Gg{async fetchCriticalPathTasks(g){return await this.get(`gantt/get_list_task_on_critical_path?${g}`)}async fetchGanttList(g){return await this.get(`/list/tasks/search?${g}&gantt=1`)}}let uo;function nd(){return uo||(uo=new td),uo}class id extends Gg{async fetchPieProjects(g){return await this.get("repairs/pie/projects?"+g)}async fetchPieTasks(g){return await this.get("repairs/pie/tasks?"+g)}async fetchPiePersonnel(g){return await this.get("repairs/metrics/get_list_position?"+g)}async fetchPersonnelData(g){return await this.get("repairs/metrics/list_position_intersection_group_by_status?"+g)}async fetchPersonnelInfo(g){return await this.get(`repairs/metrics/list_position_intersection_details?${g}`)}async fetchPiePersonnelInfo(g){return await this.get(`repairs/metrics/get_list_user_by_position?${g}`)}async fetchPieCriticalPath(g){return await this.get("repairs/metrics/get_critical_path_group_by_status?"+g)}async fetchPieCriticalPathInfo(g){return await this.get(`repairs/metrics/get_list_task_critical_path_by_status?${g}`)}async fetchPieTmc(g){return await this.get("repairs/metrics/get_list_instrument_type?"+g)}async fetchPieTmcInfo(g){return await this.get(`repairs/metrics/get_list_warehouse_by_instrument_type?${g}`)}async fetchPieUntimelyClosedTask(g){return await this.get("repairs/metrics/get_list_comment_type?"+g)}async fetchPieUntimelyClosedTaskInfo(g){return await this.get(`repairs/metrics/get_list_task_by_comment_type?${g}`)}async fetchPieAdditionalTasks(g){return await this.get("repairs/metrics/get_list_task_after_plan_fixate_group_by_status?"+g)}async fetchPieAdditionalTasksInfo(g){return await this.get(`repairs/metrics/get_list_task_after_plan_fixate_by_status?${g}`)}async fetchPersonnel(g){return await this.get("repairs/statistic/personnel?"+g)}async fetchPieExpired(g){return await this.get("repairs/metrics/get_list_task_expired_group_by_status?"+g)}async fetchPieExpiredInfo(g){return await this.get(`repairs/metrics/get_list_task_expired?${g}`)}async fetchEconomicsPerformance(g){return await this.get(`repairs/metrics/get_economic_performance?${g}`)}async fetchEconomicsInfo(g){return await this.get(`repairs/metrics/get_list_task_economic_performance?${g}`)}async fetchQualityMetrics(g){return await this.get(`repairs/metrics/get_quality_metrics?${g}`)}async fetchQualityInfo(g){return await this.get(`repairs/metrics/get_list_task_by_quality?${g}`)}async fetchPieWorkZone(g){return await this.get("repairs/metrics/get_list_work_zone_instrument?"+g)}async fetchWorkZoneInfo(g){return await this.get("repairs/metrics/get_list_work_zone_instrument_by_status?"+g)}async fetchPieAllTasks(g){return await this.get("repairs/metrics/get_list_task_group_by_status?"+g)}async fetchPieAllTasksInfo(g){return await this.get("repairs/metrics/get_list_task_by_status?"+g)}}let Uo;function Yd(){return Uo||(Uo=new id),Uo}class Md extends Gg{async fetchProjectById(g){return this.get(`/projects/${g}`)}createProject(g){return this.post("/projects",g)}editProject(g,B){return this.put(`/projects/${g}`,B)}fetchProjects(g){return this.get("/search/projects",{params:g})}cloneProject(g){return this.post(`projects/${g.id}/clone`,g)}archiveProject(g,B){return this.put(`/projects/${g}`,B)}unArchiveProject(g,B){return this.put(`/projects/${g}`,B)}moveAprProject(g){return this.post("repairs/move_plan_to_real",{repairs:[g]})}restoreProject(g){return this.post("/restore_project",{projects_ids:[g]})}importTasks(g){return this.post("tasks/import",g)}importKtd(g){return this.post("/parse_ktd",g,{headers:{"Content-Type":"multipart/form-data"}})}fetchProjectTeamList(g){return this.put(`/projects/${g}`,null)}deleteProject(g){return this.delete(`/projects/${g}`)}}let Go;function cd(){return Go||(Go=new Md),Go}class Dd extends Gg{fetchFilters(g){return this.get(`get_list_repair?smart=1&${g}`)}fetchRepairs(g,B,Q,w,C){return this.get("get_list_repair"+(g?`${B}&per_page=100000${C?"&"+C:""}&${Q?"":w}`:`?per_page=100000${C?"&"+C:""}&${w}`))}fetchRepairTemplates({equipmentId:g,categoryCode:B}){return this.get(`repairs/get_repair_template_list?per_page=100000&categoryCodeList[0]=${B}&equipmentIdList[0]=${g}`)}fetchEquipment(){return this.get("repairs/equipment/list?per_page=100000")}createRepair(g){return this.post("/repairs/equipments",g)}createRepairFromTemplate(g){return this.post("/repairs/create_repair_from_repair_template",g)}startRepair(g){return this.post(`/repairs/${g}/start`,null)}finishRepair(g){return this.post("/repairs/complete_repair_list",{repairIdList:[g]})}finishPreparationProject(g){return this.post(`/repairs/${g}/finish_preparation`,null)}moveRepairToCurrent(g){return this.post("/repairs/transfer_repair_plan_to_current",{repairs:[g]})}moveArchiveToCurrent(g){return this.post("/repairs/transfer_repair_archive_to_current",{repairs_ids:[g]})}moveRepairToApr(g){return this.post("/repairs/transfer_repair_current_to_plan",{repairs:[g]})}moveRepairToArchive(g){return this.post("/repairs/transfer_repair_current_to_archive",{repairs_ids:[g]})}restoreRepair(g){return this.post("/restore_repair",{repairs_ids:[g]})}updateRepair(g,B){return this.put(`/repairs/${B}`,g)}copyRepair(g){return this.post(`/repairs/${g}/clone`,null)}deleteRepair(g){return this.delete(`/repairs/${g}`)}}let ho;function rd(){return ho||(ho=new Dd),ho}class Fd extends Gg{async fetchTaskById(g){return await this.get(`/tasks/${g}`)}async fetchTasksList(g){return await this.get("/list/tasks/search",{params:g})}async fetchSubtasksList(g){return await this.get(`/task/${g}/subtasks/list`)}async fetchTaskBranch(g){return await this.get(`/get_list_task_branch?task_id=${g}`)}async fetchInstrumentsList(g){return await this.get("admin/instruments",{params:g})}async fetchInstrumentTypeListWithPreparedWarehouse(g){return await this.get("/instrument_type/get_instrument_type_list_with_prepared_warehouse",{params:g})}async fetchInstrumentsEquivalentList(g){return await this.get("tasks/instrument/list",{params:g})}async fetchDiffInstruments(g){return await this.get(`tasks/${g.taskId}/fill/module`,{params:g})}async replaceInstruments(g){return await this.post("/instruments/equivalent/attach",g)}async fetchTaskUsagePersonal(g){return await this.get(`tasks/${g.taskId}/usage/users`,{params:g})}async fetchTaskUsageInstrument(g){return await this.get(`tasks/${g.taskId}/usage/instruments`,{params:g})}fetchEquipment(g){return this.get("repairs/equipment/list",{params:g})}fetchTaskVideoSources(g){return this.get("work_zone/get_list_video_source",{params:g})}fetchTaskVideoSourcesStream(g){return this.get("horizon/video-source",{params:g})}createWorkZone(g){return this.post("admin/work-zones",g)}async createTask(g){return await this.post("tasks",g)}async editTask(g){return await this.put(`tasks/${g.taskId}`,g.data)}async mergeTask(g){return await this.post("tasks/merge",g)}async deleteTask(g){return await this.delete(`tasks/${g}`)}async changeStatus(g){const{taskId:B,data:Q}=g;return await this.put(`task/${B}/change-status`,Q)}async uploadComment(g){return await this.post("comments",g)}async deleteComment(g){return await this.delete(`comments/${g}`)}async editComment(g){const{commentId:B,data:Q}=g;return await this.put(`comments/${B}`,Q)}async saveMetrics(g){return await this.put("/update_quality_metrics",g)}async checkReasonForStatus(g){return await this.post("/tasks/check_reason_for_task",g)}async verifyTaskStatus(g){const{task_id:B,data:Q}=g;return await this.get(`/task/${B}/change-status/verification`,{params:Q})}async checkBranchBeforeCloseTask(g){return await this.post("/check_branch_before_close_task",g)}}let lo;function ad(){return lo||(lo=new Fd),lo}class sd extends Gg{login(g,B){return this.post("/login",{email:g,password:B})}loginPhoto(g){return this.post("/login/from_photo",{photo:g})}logout(){return this.post("/logout",null)}userInfo(){return this.get("/users/auth")}configs(){return this.get("/configs")}changePassword(g,B,Q){return this.put(`/users/${g}/password`,{password:B,password_confirmation:Q})}}let Ho;function ud(){return Ho||(Ho=new sd),Ho}class Ud extends Gg{uploadFile(g){return this.post("/upload-file",g,{headers:{"Content-Type":"multipart/form-data"}})}}let fo;function Gd(){return fo||(fo=new Ud),fo}class hd extends Gg{async startVideoAnalytics(){return await this.post("/statanly/start",null)}}let Jo;function ld(){return Jo||(Jo=new hd),Jo}class dd extends Gg{async editUser({id:g,model:B}){return await this.put(`/admin/users/${g}`,B)}async getUser(g){return await this.get(`/admin/users/${g}`)}}let No;function Hd(){return No||(No=new dd),No}/**
8
8
  * @license
9
9
  * Copyright 2020 Google LLC. All Rights Reserved.
10
10
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,20 +19,20 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  * =============================================================================
22
- */var PM=function(A,g){return(PM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(B,Q){B.__proto__=Q}||function(B,Q){for(var w in Q)Q.hasOwnProperty(w)&&(B[w]=Q[w])})(A,g)};function Wg(A,g){function B(){this.constructor=A}PM(A,g),A.prototype=g===null?Object.create(g):(B.prototype=g.prototype,new B)}function uA(A,g,B,Q){return new(B||(B=Promise))(function(w,C){function E(o){try{I(Q.next(o))}catch(n){C(n)}}function e(o){try{I(Q.throw(o))}catch(n){C(n)}}function I(o){o.done?w(o.value):new B(function(n){n(o.value)}).then(E,e)}I((Q=Q.apply(A,[])).next())})}function UA(A,g){var B,Q,w,C,E={label:0,sent:function(){if(1&w[0])throw w[1];return w[1]},trys:[],ops:[]};return C={next:e(0),throw:e(1),return:e(2)},typeof Symbol=="function"&&(C[Symbol.iterator]=function(){return this}),C;function e(I){return function(o){return function(n){if(B)throw new TypeError("Generator is already executing.");for(;E;)try{if(B=1,Q&&(w=2&n[0]?Q.return:n[0]?Q.throw||((w=Q.return)&&w.call(Q),0):Q.next)&&!(w=w.call(Q,n[1])).done)return w;switch(Q=0,w&&(n=[2&n[0],w.value]),n[0]){case 0:case 1:w=n;break;case 4:return E.label++,{value:n[1],done:!1};case 5:E.label++,Q=n[1],n=[0];continue;case 7:n=E.ops.pop(),E.trys.pop();continue;default:if(!(w=(w=E.trys).length>0&&w[w.length-1])&&(n[0]===6||n[0]===2)){E=0;continue}if(n[0]===3&&(!w||n[1]>w[0]&&n[1]<w[3])){E.label=n[1];break}if(n[0]===6&&E.label<w[1]){E.label=w[1],w=n;break}if(w&&E.label<w[2]){E.label=w[2],E.ops.push(n);break}w[2]&&E.ops.pop(),E.trys.pop();continue}n=g.call(A,E)}catch(i){n=[6,i],Q=0}finally{B=w=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([I,o])}}}var dd=function(){function A(g){this.global=g,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}return A.prototype.setPlatform=function(g,B){this.platform!=null&&console.warn("Platform "+this.platformName+" has already been set. Overwriting the platform with "+B+"."),this.platformName=g,this.platform=B},A.prototype.registerFlag=function(g,B,Q){if(this.flagRegistry[g]={evaluationFn:B,setHook:Q},this.urlFlags[g]!=null){var w=this.urlFlags[g];console.warn("Setting feature override from URL "+g+": "+w+"."),this.set(g,w)}},A.prototype.get=function(g){return g in this.flags?this.flags[g]:(this.flags[g]=this.evaluateFlag(g),this.flags[g])},A.prototype.getNumber=function(g){return this.get(g)},A.prototype.getBool=function(g){return this.get(g)},A.prototype.getFlags=function(){return this.flags},Object.defineProperty(A.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),A.prototype.set=function(g,B){if(this.flagRegistry[g]==null)throw new Error("Cannot set flag "+g+" as it has not been registered.");this.flags[g]=B,this.flagRegistry[g].setHook!=null&&this.flagRegistry[g].setHook(B)},A.prototype.evaluateFlag=function(g){if(this.flagRegistry[g]==null)throw new Error("Cannot evaluate flag '"+g+"': no evaluation function found.");return this.flagRegistry[g].evaluationFn()},A.prototype.setFlags=function(g){this.flags=Object.assign({},g)},A.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},A.prototype.populateURLFlags=function(){var g=this;if(this.global!==void 0&&this.global.location!==void 0&&this.global.location.search!==void 0){var B,Q,w=(B=this.global.location.search,Q={},B.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(C){for(var E=[],e=1;e<arguments.length;e++)E[e-1]=arguments[e];return Hd(Q,E[0],E[1]),E.join("=")}),Q);"tfjsflags"in w&&w.tfjsflags.split(",").forEach(function(C){var E=C.split(":"),e=E[0],I=E[1];g.urlFlags[e]=function(o,n){if((n=n.toLowerCase())==="true"||n==="false")return n==="true";if(""+ +n===n)return+n;throw new Error("Could not parse value flag value "+n+" for flag "+o+".")}(e,I)})}},A}();function Hd(A,g,B){A[decodeURIComponent(g)]=decodeURIComponent(B||"")}function BA(){return vM}var vM=null,VE=new Map,No=new Map;function kM(A,g){var B=pM(A,g);return VE.get(B)}function fd(A){return No.get(A)}function TM(A){for(var g=VE.entries(),B=[];;){var Q=g.next(),w=Q.done,C=Q.value;if(w)break;var E=C[0],e=C[1];E.split("_")[0]===A&&B.push(e)}return B}function jM(A){var g=A.kernelName,B=A.backendName,Q=pM(g,B);if(VE.has(Q))throw new Error("The kernel '"+g+"' for backend '"+B+"' is already registered");VE.set(Q,A)}function Jd(A){var g=A.kernelName;No.has(g)&&console.warn("Overriding the gradient for '"+g+"'"),No.set(g,A)}function pM(A,g){return g+"_"+A}function mo(A,g,B){return Math.max(A,Math.min(g,B))}function yM(A){return A%2==0?A:A+1}function Nd(A){for(var g=0,B=0;B<A.length;B++)g+=A[B];return g}function R(A,g){if(!A)throw new Error(typeof g=="string"?g:g())}function eB(A,g,B){B===void 0&&(B=""),R(KB(A,g),function(){return B+" Shapes "+A+" and "+g+" must match"})}function kw(A){R(A!=null,function(){return"The input to the tensor constructor must be a non-null value."})}function Tw(A,g,B){if(g===void 0&&(g=[]),B===void 0&&(B=!1),g==null&&(g=[]),Array.isArray(A)||Xg(A)&&!B)for(var Q=0;Q<A.length;++Q)Tw(A[Q],g,B);else g.push(A);return g}function hA(A){if(A.length===0)return 1;for(var g=A[0],B=1;B<A.length;B++)g*=A[B];return g}function KB(A,g){if(A===g)return!0;if(A==null||g==null||A.length!==g.length)return!1;for(var B=0;B<A.length;B++)if(A[B]!==g[B])return!1;return!0}function JB(A){return A%1==0}function md(A){if(Math.tanh!=null)return Math.tanh(A);if(A===1/0)return 1;if(A===-1/0)return-1;var g=Math.exp(2*A);return(g-1)/(g+1)}function Ro(A){var g=Math.ceil(Math.sqrt(A));return[g,Math.ceil(A/g)]}function jw(A,g){return g<=A.length?A:A+" ".repeat(g-A.length)}function zM(A,g,B){return g===void 0&&(g=function(Q){return 0}),new Promise(function(Q,w){var C=0,E=function(){if(A())Q();else{C++;var e=g(C);B!=null&&C>=B?w():setTimeout(E,e)}};E()})}function Rd(A,g){for(var B=1,Q=-1,w=0;w<A.length;++w)if(A[w]>=0)B*=A[w];else if(A[w]===-1){if(Q!==-1)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+Q+" and dim "+w);Q=w}else if(A[w]<0)throw Error("Shapes can not be < 0. Found "+A[w]+" at dim "+w);if(Q===-1){if(g>0&&g!==B)throw Error("Size("+g+") must match the product of shape "+A);return A}if(B===0)throw Error("Cannot infer the missing size in ["+A+"] when there are 0 elements");if(g%B!=0)throw Error("The implicit shape can't be a fractional number. Got "+g+" / "+B);var C=A.slice();return C[Q]=g/B,C}function TB(A,g){var B=g.length;return R((A=A==null?g.map(function(Q,w){return w}):[].concat(A)).every(function(Q){return Q>=-B&&Q<B}),function(){return"All values in axis param must be in range [-"+B+", "+B+") but got axis "+A}),R(A.every(function(Q){return JB(Q)}),function(){return"All values in axis param must be integers but got axis "+A}),A.map(function(Q){return Q<0?B+Q:Q})}function Aw(A,g){for(var B=[],Q=[],w=g!=null&&Array.isArray(g)&&g.length===0,C=g==null||w?null:TB(g,A).sort(),E=0,e=0;e<A.length;++e){if(C!=null){if(C[E]===e&&A[e]!==1)throw new Error("Can't squeeze axis "+e+" since its dim '"+A[e]+"' is not 1");(C[E]==null||C[E]>e)&&A[e]===1&&(B.push(A[e]),Q.push(e)),C[E]<=e&&E++}A[e]!==1&&(B.push(A[e]),Q.push(e))}return{newShape:B,keptDims:Q}}function dC(A,g){var B=null;if(A==null||A==="float32")B=new Float32Array(g);else if(A==="int32")B=new Int32Array(g);else{if(A!=="bool")throw new Error("Unknown data type "+A);B=new Uint8Array(g)}return B}function xE(A,g){var B=null;if(A==null||A==="float32")B=new Float32Array(g);else if(A==="int32")B=new Int32Array(g);else if(A==="bool")B=new Uint8Array(g);else{if(A!=="string")throw new Error("Unknown data type "+A);B=new Array(g)}return B}function Pd(A,g){for(var B=0;B<A.length;B++){var Q=A[B];if(isNaN(Q)||!isFinite(Q))throw Error("A tensor of type "+g+" being uploaded contains "+Q+".")}}function vd(A){return A==="bool"||A==="complex64"||A==="float32"||A==="int32"||A==="string"}function kd(A,g){return g!=="complex64"&&(g!=="float32"||A==="complex64")&&(g!=="int32"||A==="float32"||A==="complex64")&&(g!=="bool"||A!=="bool")}function Xg(A){return A instanceof Float32Array||A instanceof Int32Array||A instanceof Uint8Array}function WM(A){if(A==="float32"||A==="int32")return 4;if(A==="complex64")return 8;if(A==="bool")return 1;throw new Error("Unknown dtype "+A)}function Td(A){if(A==null)return 0;var g=0;return A.forEach(function(B){return g+=B.length}),g}function Po(A){return typeof A=="string"||A instanceof String}function jd(A){return typeof A=="boolean"}function pd(A){return typeof A=="number"}function HC(A){return Array.isArray(A)?HC(A[0]):A instanceof Float32Array?"float32":A instanceof Int32Array||A instanceof Uint8Array?"int32":pd(A)?"float32":Po(A)?"string":jd(A)?"bool":"float32"}function vo(A){return!!(A&&A.constructor&&A.call&&A.apply)}function ko(A,g){for(var B=g;B<A;++B)if(A%B==0)return B;return A}function Og(A){var g=A.length;if(g<2)return[];var B=new Array(g-1);B[g-2]=A[g-1];for(var Q=g-3;Q>=0;--Q)B[Q]=B[Q+1]*A[Q+1];return B}function SM(A,g,B){if(g==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(A)&&(A=Tw(A)),B&&Pd(A,g),function(C,E){return C instanceof Float32Array&&E==="float32"||C instanceof Int32Array&&E==="int32"||C instanceof Uint8Array&&E==="bool"}(A,g))return A;if(g==null||g==="float32"||g==="complex64")return new Float32Array(A);if(g==="int32")return new Int32Array(A);if(g==="bool"){for(var Q=new Uint8Array(A.length),w=0;w<Q.length;++w)Math.round(A[w])!==0&&(Q[w]=1);return Q}throw new Error("Unknown data type "+g)}function LM(A,g){if(A.length===0)return g[0];var B=A.reduce(function(Q,w){return Q*w});if(B===0)return[];if(B!==g.length)throw new Error("["+A+"] does not match the input size.");return function Q(w,C,E){var e=new Array;if(C.length===1)for(var I=C[0],o=0;o<I;o++)e[o]=E[w+o];else{I=C[0];var n=C.slice(1),i=n.reduce(function(Y,M){return Y*M});for(o=0;o<I;o++)e[o]=Q(w+o*i,n,E)}return e}(0,A,g)}function bM(A,g){for(var B=fC(A,g),Q=0;Q<B.length;Q++)B[Q]=1;return B}function fC(A,g){if(g==null||g==="float32"||g==="complex64")return new Float32Array(A);if(g==="int32")return new Int32Array(A);if(g==="bool")return new Uint8Array(A);throw new Error("Unknown data type "+g)}function Zg(){return BA().platform.now()}function KM(A){A.forEach(function(g){R(Number.isInteger(g)&&g>=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+A+"]."})})}function yd(A,g){return g===void 0&&(g="utf-8"),g=g||"utf-8",BA().platform.encode(A,g)}function XE(A,g){return g===void 0&&(g="utf-8"),g=g||"utf-8",BA().platform.decode(A,g)}function VM(A,g,B){if(g===0)return 0;if(g===1)return A[0];for(var Q=A[A.length-1],w=0;w<A.length-1;++w)Q+=B[w]*A[w];return Q}function zd(A,g,B){if(g===0)return[];if(g===1)return[A];for(var Q=new Array(g),w=0;w<Q.length-1;++w)Q[w]=Math.floor(A/B[w]),A-=Q[w]*B[w];return Q[Q.length-1]=A,Q}var Wd=function(){function A(g,B){this.backendTimer=g,this.logger=B,B==null&&(this.logger=new Sd)}return A.prototype.profileKernel=function(g,B,Q){var w,C=this,E=this.backendTimer.time(function(){w=Q()});return w.forEach(function(e){e.data().then(function(I){(function(o,n,i){if(n!=="float32")return!1;for(var Y=0;Y<o.length;Y++){var M=o[Y];if(isNaN(M)||!isFinite(M))return console.warn("Found "+M+" in the result of '"+i+"'"),!0}})(I,e.dtype,g),E.then(function(o){var n="";o.getExtraProfileInfo!=null&&(n=o.getExtraProfileInfo()),C.logger.logKernelProfile(g,e,I,o.kernelMs,B,n)})})}),w},A}(),Sd=function(){function A(){}return A.prototype.logKernelProfile=function(g,B,Q,w,C,E){var e=typeof w=="number"?jw(w+"ms",9):w.error,I=jw(g,25),o=B.rank,n=B.size,i=jw(B.shape.toString(),14),Y="";for(var M in C){var c=C[M].shape||B.shape,D=c.length;Y+=M+": "+D+"D "+(D>0?c:"")+" "}console.log("%c"+I+" %c"+e+" %c"+o+"D "+i+" %c"+n+" %c"+Y+" %c"+E,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},A}(),xM=20,JC=3,To=7;function Ld(A,g,B,Q){var w=Og(g),C=function(o,n,i,Y){var M=hA(n),c=Y[Y.length-1],D=new Array(c).fill(0),r=n.length,F=i==="complex64"?mC(o):o;if(r>1)for(var s=0;s<M/c;s++)for(var u=s*c,a=0;a<c;a++)D[a]=Math.max(D[a],NC(F[u+a],0,i).length);return D}(A,g,B,w),E=g.length,e=function o(n,i,Y,M,c,D){D===void 0&&(D=!0);var r=Y==="complex64"?2:1,F=i[0],s=i.length;if(s===0)return Y==="complex64"?[NC(mC(n)[0],0,Y)]:Y==="bool"?[XM(n[0])]:[n[0].toString()];if(s===1){if(F>xM){var u=JC*r,a=Array.from(n.slice(0,u)),U=Array.from(n.slice((F-JC)*r,F*r));return Y==="complex64"&&(a=mC(a),U=mC(U)),["["+a.map(function(v,y){return NC(v,c[y],Y)}).join(", ")+", ..., "+U.map(function(v,y){return NC(v,c[F-JC+y],Y)}).join(", ")+"]"]}return["["+(Y==="complex64"?mC(n):Array.from(n)).map(function(v,y){return NC(v,c[y],Y)}).join(", ")+"]"]}var G=i.slice(1),d=M.slice(1),H=M[0]*r,h=[];if(F>xM){for(var l=0;l<JC;l++){var m=(f=l*H)+H;h.push.apply(h,o(n.slice(f,m),G,Y,d,c,!1))}for(h.push("..."),l=F-JC;l<F;l++)m=(f=l*H)+H,h.push.apply(h,o(n.slice(f,m),G,Y,d,c,l===F-1))}else for(l=0;l<F;l++){var f;m=(f=l*H)+H,h.push.apply(h,o(n.slice(f,m),G,Y,d,c,l===F-1))}var W=s===2?",":"";for(h[0]="["+h[0]+W,l=1;l<h.length-1;l++)h[l]=" "+h[l]+W;var N=`,
22
+ */var PM=function(A,g){return(PM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(B,Q){B.__proto__=Q}||function(B,Q){for(var w in Q)Q.hasOwnProperty(w)&&(B[w]=Q[w])})(A,g)};function Wg(A,g){function B(){this.constructor=A}PM(A,g),A.prototype=g===null?Object.create(g):(B.prototype=g.prototype,new B)}function uA(A,g,B,Q){return new(B||(B=Promise))(function(w,C){function E(o){try{I(Q.next(o))}catch(n){C(n)}}function e(o){try{I(Q.throw(o))}catch(n){C(n)}}function I(o){o.done?w(o.value):new B(function(n){n(o.value)}).then(E,e)}I((Q=Q.apply(A,[])).next())})}function UA(A,g){var B,Q,w,C,E={label:0,sent:function(){if(1&w[0])throw w[1];return w[1]},trys:[],ops:[]};return C={next:e(0),throw:e(1),return:e(2)},typeof Symbol=="function"&&(C[Symbol.iterator]=function(){return this}),C;function e(I){return function(o){return function(n){if(B)throw new TypeError("Generator is already executing.");for(;E;)try{if(B=1,Q&&(w=2&n[0]?Q.return:n[0]?Q.throw||((w=Q.return)&&w.call(Q),0):Q.next)&&!(w=w.call(Q,n[1])).done)return w;switch(Q=0,w&&(n=[2&n[0],w.value]),n[0]){case 0:case 1:w=n;break;case 4:return E.label++,{value:n[1],done:!1};case 5:E.label++,Q=n[1],n=[0];continue;case 7:n=E.ops.pop(),E.trys.pop();continue;default:if(!(w=(w=E.trys).length>0&&w[w.length-1])&&(n[0]===6||n[0]===2)){E=0;continue}if(n[0]===3&&(!w||n[1]>w[0]&&n[1]<w[3])){E.label=n[1];break}if(n[0]===6&&E.label<w[1]){E.label=w[1],w=n;break}if(w&&E.label<w[2]){E.label=w[2],E.ops.push(n);break}w[2]&&E.ops.pop(),E.trys.pop();continue}n=g.call(A,E)}catch(i){n=[6,i],Q=0}finally{B=w=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([I,o])}}}var fd=function(){function A(g){this.global=g,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}return A.prototype.setPlatform=function(g,B){this.platform!=null&&console.warn("Platform "+this.platformName+" has already been set. Overwriting the platform with "+B+"."),this.platformName=g,this.platform=B},A.prototype.registerFlag=function(g,B,Q){if(this.flagRegistry[g]={evaluationFn:B,setHook:Q},this.urlFlags[g]!=null){var w=this.urlFlags[g];console.warn("Setting feature override from URL "+g+": "+w+"."),this.set(g,w)}},A.prototype.get=function(g){return g in this.flags?this.flags[g]:(this.flags[g]=this.evaluateFlag(g),this.flags[g])},A.prototype.getNumber=function(g){return this.get(g)},A.prototype.getBool=function(g){return this.get(g)},A.prototype.getFlags=function(){return this.flags},Object.defineProperty(A.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),A.prototype.set=function(g,B){if(this.flagRegistry[g]==null)throw new Error("Cannot set flag "+g+" as it has not been registered.");this.flags[g]=B,this.flagRegistry[g].setHook!=null&&this.flagRegistry[g].setHook(B)},A.prototype.evaluateFlag=function(g){if(this.flagRegistry[g]==null)throw new Error("Cannot evaluate flag '"+g+"': no evaluation function found.");return this.flagRegistry[g].evaluationFn()},A.prototype.setFlags=function(g){this.flags=Object.assign({},g)},A.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},A.prototype.populateURLFlags=function(){var g=this;if(this.global!==void 0&&this.global.location!==void 0&&this.global.location.search!==void 0){var B,Q,w=(B=this.global.location.search,Q={},B.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(C){for(var E=[],e=1;e<arguments.length;e++)E[e-1]=arguments[e];return Jd(Q,E[0],E[1]),E.join("=")}),Q);"tfjsflags"in w&&w.tfjsflags.split(",").forEach(function(C){var E=C.split(":"),e=E[0],I=E[1];g.urlFlags[e]=function(o,n){if((n=n.toLowerCase())==="true"||n==="false")return n==="true";if(""+ +n===n)return+n;throw new Error("Could not parse value flag value "+n+" for flag "+o+".")}(e,I)})}},A}();function Jd(A,g,B){A[decodeURIComponent(g)]=decodeURIComponent(B||"")}function BA(){return vM}var vM=null,VE=new Map,mo=new Map;function kM(A,g){var B=pM(A,g);return VE.get(B)}function Nd(A){return mo.get(A)}function TM(A){for(var g=VE.entries(),B=[];;){var Q=g.next(),w=Q.done,C=Q.value;if(w)break;var E=C[0],e=C[1];E.split("_")[0]===A&&B.push(e)}return B}function jM(A){var g=A.kernelName,B=A.backendName,Q=pM(g,B);if(VE.has(Q))throw new Error("The kernel '"+g+"' for backend '"+B+"' is already registered");VE.set(Q,A)}function md(A){var g=A.kernelName;mo.has(g)&&console.warn("Overriding the gradient for '"+g+"'"),mo.set(g,A)}function pM(A,g){return g+"_"+A}function Ro(A,g,B){return Math.max(A,Math.min(g,B))}function yM(A){return A%2==0?A:A+1}function Rd(A){for(var g=0,B=0;B<A.length;B++)g+=A[B];return g}function R(A,g){if(!A)throw new Error(typeof g=="string"?g:g())}function eB(A,g,B){B===void 0&&(B=""),R(KB(A,g),function(){return B+" Shapes "+A+" and "+g+" must match"})}function kw(A){R(A!=null,function(){return"The input to the tensor constructor must be a non-null value."})}function Tw(A,g,B){if(g===void 0&&(g=[]),B===void 0&&(B=!1),g==null&&(g=[]),Array.isArray(A)||Xg(A)&&!B)for(var Q=0;Q<A.length;++Q)Tw(A[Q],g,B);else g.push(A);return g}function hA(A){if(A.length===0)return 1;for(var g=A[0],B=1;B<A.length;B++)g*=A[B];return g}function KB(A,g){if(A===g)return!0;if(A==null||g==null||A.length!==g.length)return!1;for(var B=0;B<A.length;B++)if(A[B]!==g[B])return!1;return!0}function JB(A){return A%1==0}function Pd(A){if(Math.tanh!=null)return Math.tanh(A);if(A===1/0)return 1;if(A===-1/0)return-1;var g=Math.exp(2*A);return(g-1)/(g+1)}function Po(A){var g=Math.ceil(Math.sqrt(A));return[g,Math.ceil(A/g)]}function jw(A,g){return g<=A.length?A:A+" ".repeat(g-A.length)}function zM(A,g,B){return g===void 0&&(g=function(Q){return 0}),new Promise(function(Q,w){var C=0,E=function(){if(A())Q();else{C++;var e=g(C);B!=null&&C>=B?w():setTimeout(E,e)}};E()})}function vd(A,g){for(var B=1,Q=-1,w=0;w<A.length;++w)if(A[w]>=0)B*=A[w];else if(A[w]===-1){if(Q!==-1)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+Q+" and dim "+w);Q=w}else if(A[w]<0)throw Error("Shapes can not be < 0. Found "+A[w]+" at dim "+w);if(Q===-1){if(g>0&&g!==B)throw Error("Size("+g+") must match the product of shape "+A);return A}if(B===0)throw Error("Cannot infer the missing size in ["+A+"] when there are 0 elements");if(g%B!=0)throw Error("The implicit shape can't be a fractional number. Got "+g+" / "+B);var C=A.slice();return C[Q]=g/B,C}function TB(A,g){var B=g.length;return R((A=A==null?g.map(function(Q,w){return w}):[].concat(A)).every(function(Q){return Q>=-B&&Q<B}),function(){return"All values in axis param must be in range [-"+B+", "+B+") but got axis "+A}),R(A.every(function(Q){return JB(Q)}),function(){return"All values in axis param must be integers but got axis "+A}),A.map(function(Q){return Q<0?B+Q:Q})}function Aw(A,g){for(var B=[],Q=[],w=g!=null&&Array.isArray(g)&&g.length===0,C=g==null||w?null:TB(g,A).sort(),E=0,e=0;e<A.length;++e){if(C!=null){if(C[E]===e&&A[e]!==1)throw new Error("Can't squeeze axis "+e+" since its dim '"+A[e]+"' is not 1");(C[E]==null||C[E]>e)&&A[e]===1&&(B.push(A[e]),Q.push(e)),C[E]<=e&&E++}A[e]!==1&&(B.push(A[e]),Q.push(e))}return{newShape:B,keptDims:Q}}function dC(A,g){var B=null;if(A==null||A==="float32")B=new Float32Array(g);else if(A==="int32")B=new Int32Array(g);else{if(A!=="bool")throw new Error("Unknown data type "+A);B=new Uint8Array(g)}return B}function xE(A,g){var B=null;if(A==null||A==="float32")B=new Float32Array(g);else if(A==="int32")B=new Int32Array(g);else if(A==="bool")B=new Uint8Array(g);else{if(A!=="string")throw new Error("Unknown data type "+A);B=new Array(g)}return B}function kd(A,g){for(var B=0;B<A.length;B++){var Q=A[B];if(isNaN(Q)||!isFinite(Q))throw Error("A tensor of type "+g+" being uploaded contains "+Q+".")}}function Td(A){return A==="bool"||A==="complex64"||A==="float32"||A==="int32"||A==="string"}function jd(A,g){return g!=="complex64"&&(g!=="float32"||A==="complex64")&&(g!=="int32"||A==="float32"||A==="complex64")&&(g!=="bool"||A!=="bool")}function Xg(A){return A instanceof Float32Array||A instanceof Int32Array||A instanceof Uint8Array}function WM(A){if(A==="float32"||A==="int32")return 4;if(A==="complex64")return 8;if(A==="bool")return 1;throw new Error("Unknown dtype "+A)}function pd(A){if(A==null)return 0;var g=0;return A.forEach(function(B){return g+=B.length}),g}function vo(A){return typeof A=="string"||A instanceof String}function yd(A){return typeof A=="boolean"}function zd(A){return typeof A=="number"}function HC(A){return Array.isArray(A)?HC(A[0]):A instanceof Float32Array?"float32":A instanceof Int32Array||A instanceof Uint8Array?"int32":zd(A)?"float32":vo(A)?"string":yd(A)?"bool":"float32"}function ko(A){return!!(A&&A.constructor&&A.call&&A.apply)}function To(A,g){for(var B=g;B<A;++B)if(A%B==0)return B;return A}function Og(A){var g=A.length;if(g<2)return[];var B=new Array(g-1);B[g-2]=A[g-1];for(var Q=g-3;Q>=0;--Q)B[Q]=B[Q+1]*A[Q+1];return B}function SM(A,g,B){if(g==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(A)&&(A=Tw(A)),B&&kd(A,g),function(C,E){return C instanceof Float32Array&&E==="float32"||C instanceof Int32Array&&E==="int32"||C instanceof Uint8Array&&E==="bool"}(A,g))return A;if(g==null||g==="float32"||g==="complex64")return new Float32Array(A);if(g==="int32")return new Int32Array(A);if(g==="bool"){for(var Q=new Uint8Array(A.length),w=0;w<Q.length;++w)Math.round(A[w])!==0&&(Q[w]=1);return Q}throw new Error("Unknown data type "+g)}function LM(A,g){if(A.length===0)return g[0];var B=A.reduce(function(Q,w){return Q*w});if(B===0)return[];if(B!==g.length)throw new Error("["+A+"] does not match the input size.");return function Q(w,C,E){var e=new Array;if(C.length===1)for(var I=C[0],o=0;o<I;o++)e[o]=E[w+o];else{I=C[0];var n=C.slice(1),i=n.reduce(function(Y,M){return Y*M});for(o=0;o<I;o++)e[o]=Q(w+o*i,n,E)}return e}(0,A,g)}function bM(A,g){for(var B=fC(A,g),Q=0;Q<B.length;Q++)B[Q]=1;return B}function fC(A,g){if(g==null||g==="float32"||g==="complex64")return new Float32Array(A);if(g==="int32")return new Int32Array(A);if(g==="bool")return new Uint8Array(A);throw new Error("Unknown data type "+g)}function Zg(){return BA().platform.now()}function KM(A){A.forEach(function(g){R(Number.isInteger(g)&&g>=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+A+"]."})})}function Wd(A,g){return g===void 0&&(g="utf-8"),g=g||"utf-8",BA().platform.encode(A,g)}function XE(A,g){return g===void 0&&(g="utf-8"),g=g||"utf-8",BA().platform.decode(A,g)}function VM(A,g,B){if(g===0)return 0;if(g===1)return A[0];for(var Q=A[A.length-1],w=0;w<A.length-1;++w)Q+=B[w]*A[w];return Q}function Sd(A,g,B){if(g===0)return[];if(g===1)return[A];for(var Q=new Array(g),w=0;w<Q.length-1;++w)Q[w]=Math.floor(A/B[w]),A-=Q[w]*B[w];return Q[Q.length-1]=A,Q}var Ld=function(){function A(g,B){this.backendTimer=g,this.logger=B,B==null&&(this.logger=new bd)}return A.prototype.profileKernel=function(g,B,Q){var w,C=this,E=this.backendTimer.time(function(){w=Q()});return w.forEach(function(e){e.data().then(function(I){(function(o,n,i){if(n!=="float32")return!1;for(var Y=0;Y<o.length;Y++){var M=o[Y];if(isNaN(M)||!isFinite(M))return console.warn("Found "+M+" in the result of '"+i+"'"),!0}})(I,e.dtype,g),E.then(function(o){var n="";o.getExtraProfileInfo!=null&&(n=o.getExtraProfileInfo()),C.logger.logKernelProfile(g,e,I,o.kernelMs,B,n)})})}),w},A}(),bd=function(){function A(){}return A.prototype.logKernelProfile=function(g,B,Q,w,C,E){var e=typeof w=="number"?jw(w+"ms",9):w.error,I=jw(g,25),o=B.rank,n=B.size,i=jw(B.shape.toString(),14),Y="";for(var M in C){var c=C[M].shape||B.shape,D=c.length;Y+=M+": "+D+"D "+(D>0?c:"")+" "}console.log("%c"+I+" %c"+e+" %c"+o+"D "+i+" %c"+n+" %c"+Y+" %c"+E,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},A}(),xM=20,JC=3,jo=7;function Kd(A,g,B,Q){var w=Og(g),C=function(o,n,i,Y){var M=hA(n),c=Y[Y.length-1],D=new Array(c).fill(0),r=n.length,F=i==="complex64"?mC(o):o;if(r>1)for(var s=0;s<M/c;s++)for(var u=s*c,a=0;a<c;a++)D[a]=Math.max(D[a],NC(F[u+a],0,i).length);return D}(A,g,B,w),E=g.length,e=function o(n,i,Y,M,c,D){D===void 0&&(D=!0);var r=Y==="complex64"?2:1,F=i[0],s=i.length;if(s===0)return Y==="complex64"?[NC(mC(n)[0],0,Y)]:Y==="bool"?[XM(n[0])]:[n[0].toString()];if(s===1){if(F>xM){var u=JC*r,a=Array.from(n.slice(0,u)),U=Array.from(n.slice((F-JC)*r,F*r));return Y==="complex64"&&(a=mC(a),U=mC(U)),["["+a.map(function(v,y){return NC(v,c[y],Y)}).join(", ")+", ..., "+U.map(function(v,y){return NC(v,c[F-JC+y],Y)}).join(", ")+"]"]}return["["+(Y==="complex64"?mC(n):Array.from(n)).map(function(v,y){return NC(v,c[y],Y)}).join(", ")+"]"]}var G=i.slice(1),d=M.slice(1),H=M[0]*r,h=[];if(F>xM){for(var l=0;l<JC;l++){var m=(f=l*H)+H;h.push.apply(h,o(n.slice(f,m),G,Y,d,c,!1))}for(h.push("..."),l=F-JC;l<F;l++)m=(f=l*H)+H,h.push.apply(h,o(n.slice(f,m),G,Y,d,c,l===F-1))}else for(l=0;l<F;l++){var f;m=(f=l*H)+H,h.push.apply(h,o(n.slice(f,m),G,Y,d,c,l===F-1))}var W=s===2?",":"";for(h[0]="["+h[0]+W,l=1;l<h.length-1;l++)h[l]=" "+h[l]+W;var N=`,
23
23
  `;for(l=2;l<s;l++)N+=`
24
24
  `;return h[h.length-1]=" "+h[h.length-1]+"]"+(D?"":N),h}(A,g,B,w,C),I=["Tensor"];return Q&&(I.push(" dtype: "+B),I.push(" rank: "+E),I.push(" shape: ["+g+"]"),I.push(" values:")),I.push(e.map(function(o){return" "+o}).join(`
25
25
  `)),I.join(`
26
- `)}function NC(A,g,B){return jw(Array.isArray(A)?parseFloat(A[0].toFixed(To))+" + "+parseFloat(A[1].toFixed(To))+"j":Po(A)?"'"+A+"'":B==="bool"?XM(A):parseFloat(A.toFixed(To)).toString(),g)}function XM(A){return A===0?"false":"true"}function mC(A){for(var g=[],B=0;B<A.length;B+=2)g.push([A[B],A[B+1]]);return g}var RC=function(){function A(g,B,Q){var w=this;if(this.dtype=B,this.shape=g.slice(),this.size=hA(g),Q!=null){var C=Q.length;R(C===this.size,function(){return"Length of values '"+C+"' does not match the size inferred by the shape '"+w.size+"'."})}if(B==="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=Q||xE(B,this.size),this.strides=Og(g)}return A.prototype.set=function(g){for(var B=this,Q=[],w=1;w<arguments.length;w++)Q[w-1]=arguments[w];Q.length===0&&(Q=[0]),R(Q.length===this.rank,function(){return"The number of provided coordinates ("+Q.length+") must match the rank ("+B.rank+")"});var C=this.locToIndex(Q);this.values[C]=g},A.prototype.get=function(){for(var g=[],B=0;B<arguments.length;B++)g[B]=arguments[B];g.length===0&&(g=[0]);for(var Q=0,w=0,C=g;w<C.length;w++){var E=C[w];if(E<0||E>=this.shape[Q]){var e="Requested out of range element at "+g+". Buffer shape="+this.shape;throw new Error(e)}Q++}for(var I=g[g.length-1],o=0;o<g.length-1;++o)I+=this.strides[o]*g[o];return this.values[I]},A.prototype.locToIndex=function(g){if(this.rank===0)return 0;if(this.rank===1)return g[0];for(var B=g[g.length-1],Q=0;Q<g.length-1;++Q)B+=this.strides[Q]*g[Q];return B},A.prototype.indexToLoc=function(g){if(this.rank===0)return[];if(this.rank===1)return[g];for(var B=new Array(this.shape.length),Q=0;Q<B.length-1;++Q)B[Q]=Math.floor(g/this.strides[Q]),g-=B[Q]*this.strides[Q];return B[B.length-1]=g,B},Object.defineProperty(A.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),A.prototype.toTensor=function(){return qg().makeTensor(this.values,this.shape,this.dtype)},A}(),qg=null,O=null,OM=null,uB=function(){function A(g,B,Q,w){this.kept=!1,this.isDisposedInternal=!1,this.shape=g.slice(),this.dtype=B||"float32",this.size=hA(g),this.strides=Og(g),this.dataId=Q,this.id=w,this.rankType=this.rank<5?this.rank.toString():"higher"}return A.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D()},A.prototype.asScalar=function(){return this.throwIfDisposed(),R(this.size===1,function(){return"The array must have only 1 element."}),this.reshape([])},A.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size])},A.prototype.as2D=function(g,B){return this.throwIfDisposed(),this.reshape([g,B])},A.prototype.as3D=function(g,B,Q){return this.throwIfDisposed(),this.reshape([g,B,Q])},A.prototype.as4D=function(g,B,Q,w){return this.throwIfDisposed(),this.reshape([g,B,Q,w])},A.prototype.as5D=function(g,B,Q,w,C){return this.throwIfDisposed(),this.reshape([g,B,Q,w,C])},A.prototype.asType=function(g){return this.throwIfDisposed(),O.cast(this,g)},Object.defineProperty(A.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),A.prototype.buffer=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return[4,this.data()];case 1:return g=B.sent(),[2,O.buffer(this.shape,this.dtype,g)]}})})},A.prototype.bufferSync=function(){return O.buffer(this.shape,this.dtype,this.dataSync())},A.prototype.array=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return[4,this.data()];case 1:return g=B.sent(),[2,LM(this.shape,g)]}})})},A.prototype.arraySync=function(){return LM(this.shape,this.dataSync())},A.prototype.data=function(){return uA(this,void 0,void 0,function(){var g,B;return UA(this,function(Q){switch(Q.label){case 0:return this.throwIfDisposed(),g=qg().read(this.dataId),this.dtype!=="string"?[3,2]:[4,g];case 1:B=Q.sent();try{return[2,B.map(function(w){return XE(w)})]}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}Q.label=2;case 2:return[2,g]}})})},A.prototype.dataSync=function(){this.throwIfDisposed();var g=qg().readSync(this.dataId);if(this.dtype==="string")try{return g.map(function(B){return XE(B)})}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return g},A.prototype.bytes=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return this.throwIfDisposed(),[4,qg().read(this.dataId)];case 1:return g=B.sent(),this.dtype==="string"?[2,g]:[2,new Uint8Array(g.buffer)]}})})},A.prototype.dispose=function(){this.isDisposed||(qg().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(A.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),A.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},A.prototype.toFloat=function(){return this.asType("float32")},A.prototype.toInt=function(){return this.asType("int32")},A.prototype.toBool=function(){return this.asType("bool")},A.prototype.print=function(g){return g===void 0&&(g=!1),O.print(this,g)},A.prototype.reshape=function(g){return this.throwIfDisposed(),O.reshape(this,g)},A.prototype.reshapeAs=function(g){return this.throwIfDisposed(),this.reshape(g.shape)},A.prototype.expandDims=function(g){return g===void 0&&(g=0),O.expandDims(this,g)},A.prototype.cumsum=function(g,B,Q){return g===void 0&&(g=0),B===void 0&&(B=!1),Q===void 0&&(Q=!1),O.cumsum(this,g,B,Q)},A.prototype.squeeze=function(g){return this.throwIfDisposed(),O.squeeze(this,g)},A.prototype.clone=function(){return this.throwIfDisposed(),O.clone(this)},A.prototype.oneHot=function(g,B,Q){return this.throwIfDisposed(),O.oneHot(this,g,B,Q)},A.prototype.toString=function(g){return g===void 0&&(g=!1),Ld(this.dataSync(),this.shape,this.dtype,g)},A.prototype.tile=function(g){return this.throwIfDisposed(),O.tile(this,g)},A.prototype.gather=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),O.gather(this,g,B)},A.prototype.matMul=function(g,B,Q){return B===void 0&&(B=!1),Q===void 0&&(Q=!1),this.throwIfDisposed(),O.matMul(this,g,B,Q)},A.prototype.dot=function(g){return this.throwIfDisposed(),O.dot(this,g)},A.prototype.norm=function(g,B,Q){return g===void 0&&(g="euclidean"),B===void 0&&(B=null),Q===void 0&&(Q=!1),this.throwIfDisposed(),O.norm(this,g,B,Q)},A.prototype.slice=function(g,B){return this.throwIfDisposed(),O.slice(this,g,B)},A.prototype.reverse=function(g){return this.throwIfDisposed(),O.reverse(this,g)},A.prototype.concat=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),g instanceof A&&(g=[g]),O.concat([this].concat(g),B)},A.prototype.split=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),O.split(this,g,B)},A.prototype.stack=function(g,B){return B===void 0&&(B=0),O.stack([this,g],B)},A.prototype.unstack=function(g){return g===void 0&&(g=0),O.unstack(this,g)},A.prototype.pad=function(g,B){return B===void 0&&(B=0),O.pad(this,g,B)},A.prototype.batchNormalization=function(g,B,Q,w,C){return Q===void 0&&(Q=.001),OM("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(g,B,C,w,Q)},A.prototype.batchNorm=function(g,B,Q,w,C){return C===void 0&&(C=.001),this.throwIfDisposed(),O.batchNorm(this,g,B,Q,w,C)},A.prototype.all=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.all(this,g,B)},A.prototype.any=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.any(this,g,B)},A.prototype.logSumExp=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.logSumExp(this,g,B)},A.prototype.sum=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.sum(this,g,B)},A.prototype.prod=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.prod(this,g,B)},A.prototype.mean=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.mean(this,g,B)},A.prototype.min=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.min(this,g,B)},A.prototype.max=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.max(this,g,B)},A.prototype.argMin=function(g){return g===void 0&&(g=null),this.throwIfDisposed(),O.argMin(this,g)},A.prototype.argMax=function(g){return g===void 0&&(g=null),this.throwIfDisposed(),O.argMax(this,g)},A.prototype.cast=function(g){return this.throwIfDisposed(),O.cast(this,g)},A.prototype.add=function(g){return this.throwIfDisposed(),O.add(this,g)},A.prototype.addStrict=function(g){return this.throwIfDisposed(),O.addStrict(this,g)},A.prototype.atan2=function(g){return this.throwIfDisposed(),O.atan2(this,g)},A.prototype.sub=function(g){return this.throwIfDisposed(),O.sub(this,g)},A.prototype.subStrict=function(g){return this.throwIfDisposed(),O.subStrict(this,g)},A.prototype.pow=function(g){return this.throwIfDisposed(),O.pow(this,g)},A.prototype.powStrict=function(g){return this.throwIfDisposed(),O.powStrict(this,g)},A.prototype.mul=function(g){return this.throwIfDisposed(),O.mul(this,g)},A.prototype.mulStrict=function(g){return this.throwIfDisposed(),O.mulStrict(this,g)},A.prototype.div=function(g){return this.throwIfDisposed(),O.div(this,g)},A.prototype.divNoNan=function(g){return this.throwIfDisposed(),O.divNoNan(this,g)},A.prototype.floorDiv=function(g){return this.throwIfDisposed(),O.floorDiv(this,g)},A.prototype.divStrict=function(g){return this.throwIfDisposed(),O.divStrict(this,g)},A.prototype.minimum=function(g){return this.throwIfDisposed(),O.minimum(this,g)},A.prototype.minimumStrict=function(g){return this.throwIfDisposed(),O.minimumStrict(this,g)},A.prototype.maximum=function(g){return this.throwIfDisposed(),O.maximum(this,g)},A.prototype.maximumStrict=function(g){return this.throwIfDisposed(),O.maximumStrict(this,g)},A.prototype.mod=function(g){return this.throwIfDisposed(),O.mod(this,g)},A.prototype.modStrict=function(g){return this.throwIfDisposed(),O.modStrict(this,g)},A.prototype.squaredDifferenceStrict=function(g){return this.throwIfDisposed(),O.squaredDifferenceStrict(this,g)},A.prototype.transpose=function(g){return this.throwIfDisposed(),O.transpose(this,g)},A.prototype.notEqual=function(g){return this.throwIfDisposed(),O.notEqual(this,g)},A.prototype.notEqualStrict=function(g){return this.throwIfDisposed(),O.notEqualStrict(this,g)},A.prototype.less=function(g){return this.throwIfDisposed(),O.less(this,g)},A.prototype.lessStrict=function(g){return this.throwIfDisposed(),O.lessStrict(this,g)},A.prototype.equal=function(g){return this.throwIfDisposed(),O.equal(this,g)},A.prototype.equalStrict=function(g){return this.throwIfDisposed(),O.equalStrict(this,g)},A.prototype.lessEqual=function(g){return this.throwIfDisposed(),O.lessEqual(this,g)},A.prototype.lessEqualStrict=function(g){return this.throwIfDisposed(),O.lessEqualStrict(this,g)},A.prototype.greater=function(g){return this.throwIfDisposed(),O.greater(this,g)},A.prototype.greaterStrict=function(g){return this.throwIfDisposed(),O.greaterStrict(this,g)},A.prototype.greaterEqual=function(g){return this.throwIfDisposed(),O.greaterEqual(this,g)},A.prototype.greaterEqualStrict=function(g){return this.throwIfDisposed(),O.greaterEqualStrict(this,g)},A.prototype.logicalAnd=function(g){return this.throwIfDisposed(),O.logicalAnd(this,g)},A.prototype.logicalOr=function(g){return this.throwIfDisposed(),O.logicalOr(this,g)},A.prototype.logicalNot=function(){return this.throwIfDisposed(),O.logicalNot(this)},A.prototype.logicalXor=function(g){return this.throwIfDisposed(),O.logicalXor(this,g)},A.prototype.where=function(g,B){return this.throwIfDisposed(),O.where(g,this,B)},A.prototype.neg=function(){return this.throwIfDisposed(),O.neg(this)},A.prototype.ceil=function(){return this.throwIfDisposed(),O.ceil(this)},A.prototype.floor=function(){return this.throwIfDisposed(),O.floor(this)},A.prototype.sign=function(){return this.throwIfDisposed(),O.sign(this)},A.prototype.isNaN=function(){return this.throwIfDisposed(),O.isNaN(this)},A.prototype.isInf=function(){return this.throwIfDisposed(),O.isInf(this)},A.prototype.isFinite=function(){return this.throwIfDisposed(),O.isFinite(this)},A.prototype.exp=function(){return this.throwIfDisposed(),O.exp(this)},A.prototype.expm1=function(){return this.throwIfDisposed(),O.expm1(this)},A.prototype.log=function(){return this.throwIfDisposed(),O.log(this)},A.prototype.log1p=function(){return this.throwIfDisposed(),O.log1p(this)},A.prototype.sqrt=function(){return this.throwIfDisposed(),O.sqrt(this)},A.prototype.rsqrt=function(){return this.throwIfDisposed(),O.rsqrt(this)},A.prototype.square=function(){return this.throwIfDisposed(),O.square(this)},A.prototype.reciprocal=function(){return this.throwIfDisposed(),O.reciprocal(this)},A.prototype.abs=function(){return this.throwIfDisposed(),O.abs(this)},A.prototype.clipByValue=function(g,B){return this.throwIfDisposed(),O.clipByValue(this,g,B)},A.prototype.relu=function(){return this.throwIfDisposed(),O.relu(this)},A.prototype.relu6=function(){return this.throwIfDisposed(),O.relu6(this)},A.prototype.elu=function(){return this.throwIfDisposed(),O.elu(this)},A.prototype.selu=function(){return this.throwIfDisposed(),O.selu(this)},A.prototype.leakyRelu=function(g){return g===void 0&&(g=.2),this.throwIfDisposed(),O.leakyRelu(this,g)},A.prototype.prelu=function(g){return this.throwIfDisposed(),O.prelu(this,g)},A.prototype.sigmoid=function(){return this.throwIfDisposed(),O.sigmoid(this)},A.prototype.logSigmoid=function(){return this.throwIfDisposed(),O.logSigmoid(this)},A.prototype.softplus=function(){return this.throwIfDisposed(),O.softplus(this)},A.prototype.zerosLike=function(){return this.throwIfDisposed(),O.zerosLike(this)},A.prototype.onesLike=function(){return this.throwIfDisposed(),O.onesLike(this)},A.prototype.sin=function(){return this.throwIfDisposed(),O.sin(this)},A.prototype.cos=function(){return this.throwIfDisposed(),O.cos(this)},A.prototype.tan=function(){return this.throwIfDisposed(),O.tan(this)},A.prototype.asin=function(){return this.throwIfDisposed(),O.asin(this)},A.prototype.acos=function(){return this.throwIfDisposed(),O.acos(this)},A.prototype.atan=function(){return this.throwIfDisposed(),O.atan(this)},A.prototype.sinh=function(){return this.throwIfDisposed(),O.sinh(this)},A.prototype.cosh=function(){return this.throwIfDisposed(),O.cosh(this)},A.prototype.tanh=function(){return this.throwIfDisposed(),O.tanh(this)},A.prototype.asinh=function(){return this.throwIfDisposed(),O.asinh(this)},A.prototype.acosh=function(){return this.throwIfDisposed(),O.acosh(this)},A.prototype.atanh=function(){return this.throwIfDisposed(),O.atanh(this)},A.prototype.erf=function(){return this.throwIfDisposed(),O.erf(this)},A.prototype.round=function(){return this.throwIfDisposed(),O.round(this)},A.prototype.step=function(g){return g===void 0&&(g=0),this.throwIfDisposed(),O.step(this,g)},A.prototype.softmax=function(g){return g===void 0&&(g=-1),this.throwIfDisposed(),O.softmax(this,g)},A.prototype.logSoftmax=function(g){return g===void 0&&(g=-1),this.throwIfDisposed(),O.logSoftmax(this,g)},A.prototype.resizeBilinear=function(g,B){return B===void 0&&(B=!1),this.throwIfDisposed(),O.image.resizeBilinear(this,g,B)},A.prototype.resizeNearestNeighbor=function(g,B){return B===void 0&&(B=!1),this.throwIfDisposed(),O.image.resizeNearestNeighbor(this,g,B)},A.prototype.conv1d=function(g,B,Q,w,C,E){return w===void 0&&(w="NWC"),C===void 0&&(C=1),this.throwIfDisposed(),O.conv1d(this,g,B,Q,w,C,E)},A.prototype.conv2d=function(g,B,Q,w,C,E){return w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]),this.throwIfDisposed(),O.conv2d(this,g,B,Q,w,C,E)},A.prototype.conv2dTranspose=function(g,B,Q,w,C){return this.throwIfDisposed(),O.conv2dTranspose(this,g,B,Q,w,C)},A.prototype.depthwiseConv2D=function(g,B,Q,w,C,E){return w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]),this.throwIfDisposed(),O.depthwiseConv2d(this,g,B,Q,w,C,E)},A.prototype.separableConv2d=function(g,B,Q,w,C,E){return C===void 0&&(C=[1,1]),E===void 0&&(E="NHWC"),this.throwIfDisposed(),O.separableConv2d(this,g,B,Q,w,C,E)},A.prototype.avgPool=function(g,B,Q,w){return this.throwIfDisposed(),O.avgPool(this,g,B,Q,w)},A.prototype.maxPool=function(g,B,Q,w){return this.throwIfDisposed(),O.maxPool(this,g,B,Q,w)},A.prototype.localResponseNormalization=function(g,B,Q,w){return g===void 0&&(g=5),B===void 0&&(B=1),Q===void 0&&(Q=1),w===void 0&&(w=.5),O.localResponseNormalization(this,g,B,Q,w)},A.prototype.pool=function(g,B,Q,w,C){return this.throwIfDisposed(),O.pool(this,g,B,Q,w,C)},A.prototype.variable=function(g,B,Q){return g===void 0&&(g=!0),this.throwIfDisposed(),qg().makeVariable(this,g,B,Q)},A.prototype.unsortedSegmentSum=function(g,B){return this.throwIfDisposed(),O.unsortedSegmentSum(this,g,B)},A.prototype.batchToSpaceND=function(g,B){return this.throwIfDisposed(),O.batchToSpaceND(this,g,B)},A.prototype.spaceToBatchND=function(g,B){return this.throwIfDisposed(),O.spaceToBatchND(this,g,B)},A.prototype.topk=function(g,B){return g===void 0&&(g=1),B===void 0&&(B=!0),this.throwIfDisposed(),O.topk(this,g,B)},A.prototype.stridedSlice=function(g,B,Q,w,C,E,e,I){return w===void 0&&(w=0),C===void 0&&(C=0),E===void 0&&(E=0),e===void 0&&(e=0),I===void 0&&(I=0),this.throwIfDisposed(),O.stridedSlice(this,g,B,Q,w,C,E,e,I)},A.prototype.depthToSpace=function(g,B){return this.throwIfDisposed(),O.depthToSpace(this,g,B)},A.prototype.fft=function(){return this.throwIfDisposed(),O.spectral.fft(this)},A.prototype.ifft=function(){return this.throwIfDisposed(),O.spectral.ifft(this)},A.prototype.rfft=function(){return this.throwIfDisposed(),O.spectral.rfft(this)},A.prototype.irfft=function(){return this.throwIfDisposed(),O.spectral.irfft(this)},A}();Object.defineProperty(uB,Symbol.hasInstance,{value:function(A){return!!A&&A.dataId!=null&&A.shape!=null&&A.dtype!=null}});var ZM,jo,po,yo,zo,pw=function(A){function g(B,Q,w,C){var E=A.call(this,B.shape,B.dtype,B.dataId,C)||this;return E.trainable=Q,E.name=w,E}return Wg(g,A),g.prototype.assign=function(B){if(B.dtype!==this.dtype)throw new Error("dtype of the new value ("+B.dtype+") and previous value ("+this.dtype+") must match");if(!KB(B.shape,this.shape))throw new Error("shape of the new value ("+B.shape+") and previous value ("+this.shape+") must match");qg().disposeTensor(this),this.dataId=B.dataId,qg().incRef(this,null)},g.prototype.dispose=function(){qg().disposeVariable(this),this.isDisposedInternal=!0},g}(uB);Object.defineProperty(pw,Symbol.hasInstance,{value:function(A){return A instanceof uB&&A.assign!=null&&A.assign instanceof Function}}),function(A){A.R0="R0",A.R1="R1",A.R2="R2",A.R3="R3",A.R4="R4",A.R5="R5",A.R6="R6"}(ZM||(ZM={})),function(A){A.float32="float32",A.int32="int32",A.bool="int32",A.complex64="complex64"}(jo||(jo={})),function(A){A.float32="float32",A.int32="int32",A.bool="bool",A.complex64="complex64"}(po||(po={})),function(A){A.float32="float32",A.int32="float32",A.bool="float32",A.complex64="complex64"}(yo||(yo={})),function(A){A.float32="complex64",A.int32="complex64",A.bool="complex64",A.complex64="complex64"}(zo||(zo={}));var bd={float32:yo,int32:jo,bool:po,complex64:zo};function _B(A,g){if(A==="string"||g==="string"){if(A==="string"&&g==="string")return"string";throw new Error("Can not upcast "+A+" with "+g)}return bd[A][g]}function Wo(A){return _B(A,"int32")}function UB(A,g){if(A.dtype===g.dtype)return[A,g];var B=_B(A.dtype,g.dtype);return[A.cast(B),g.cast(B)]}function Kd(A,g){R(A.dtype===g.dtype,function(){return"The dtypes of the first("+A.dtype+") and second("+g.dtype+") input must match"})}function qM(A){var g=[];return function B(Q,w,C){if(Q!=null){if(Q instanceof uB)return void w.push(Q);if(E=Q,!(!Array.isArray(E)&&typeof E!="object")){var E,e=Q;for(var I in e){var o=e[I];C.has(o)||(C.add(o),B(o,w,C))}}}}(A,g,new Set),g}var So,_M=function(){function A(){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}}return A.prototype.dispose=function(){for(var g in this.registeredVariables)this.registeredVariables[g].dispose()},A}(),Vd=function(){function A(g){this.ENV=g,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new _M}return A.prototype.ready=function(){return uA(this,void 0,void 0,function(){var g,B,Q;return UA(this,function(w){switch(w.label){case 0:if(this.pendingBackendInit!=null)return[2,this.pendingBackendInit.then(function(){})];if(this.backendInstance!=null)return[2];g=this.getSortedBackends(),B=0,w.label=1;case 1:return B<g.length?(Q=g[B],[4,this.initializeBackend(Q).success]):[3,5];case 2:return w.sent()?[4,this.setBackend(Q)]:[3,4];case 3:return w.sent(),[2];case 4:return B++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}})})},Object.defineProperty(A.prototype,"backend",{get:function(){if(this.pendingBackendInit!=null)throw new Error("Backend '"+this.backendName+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");if(this.backendInstance==null){var g=this.initializeBackendsAndReturnBest(),B=g.name;if(g.asyncInit)throw new Error("The highest priority backend '"+B+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");this.setBackend(B)}return this.backendInstance},enumerable:!0,configurable:!0}),A.prototype.backendNames=function(){return Object.keys(this.registryFactory)},A.prototype.findBackend=function(g){return!(g in this.registry)&&(!(g in this.registryFactory)||this.initializeBackend(g).asyncInit)?null:this.registry[g]},A.prototype.findBackendFactory=function(g){return g in this.registryFactory?this.registryFactory[g].factory:null},A.prototype.registerBackend=function(g,B,Q){return Q===void 0&&(Q=1),g in this.registryFactory?(console.warn(g+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[g]={factory:B,priority:Q},!0)},A.prototype.setBackend=function(g){return uA(this,void 0,void 0,function(){var B,Q,w;return UA(this,function(C){switch(C.label){case 0:if(this.registryFactory[g]==null)throw new Error("Backend name '"+g+"' not found in registry");return this.backendName=g,this.registry[g]!=null?[3,4]:(this.backendInstance=null,B=this.initializeBackend(g),Q=B.success,B.asyncInit?[4,Q]:[3,2]);case 1:return w=C.sent(),[3,3];case 2:w=Q,C.label=3;case 3:if(!w)return[2,!1];C.label=4;case 4:return this.backendInstance=this.registry[g],this.setupRegisteredKernels(),this.profiler=new Wd(this.backendInstance),[2,!0]}})})},A.prototype.setupRegisteredKernels=function(){var g=this;TM(this.backendName).forEach(function(B){B.setupFunc!=null&&B.setupFunc(g.backendInstance)})},A.prototype.disposeRegisteredKernels=function(g){var B=this;TM(g).forEach(function(Q){Q.disposeFunc!=null&&Q.disposeFunc(B.registry[g])})},A.prototype.initializeBackend=function(g){var B=this,Q=this.registryFactory[g];if(Q==null)throw new Error("Cannot initialize backend "+g+", no registration found.");try{var w=Q.factory();if(Promise.resolve(w)===w){var C=++this.pendingBackendInitId,E=w.then(function(e){return!(C<B.pendingBackendInitId)&&(B.registry[g]=e,B.pendingBackendInit=null,!0)}).catch(function(e){return!(C<B.pendingBackendInitId)&&(B.pendingBackendInit=null,console.warn("Initialization of backend "+g+" failed"),console.warn(e.stack||e.message),!1)});return this.pendingBackendInit=E,{success:E,asyncInit:!0}}return this.registry[g]=w,{success:!0,asyncInit:!1}}catch(e){return console.warn("Initialization of backend "+g+" failed"),console.warn(e.stack||e.message),{success:!1,asyncInit:!1}}},A.prototype.removeBackend=function(g){if(!(g in this.registryFactory))throw new Error(g+" backend not found in registry");this.backendName===g&&this.pendingBackendInit!=null&&this.pendingBackendInitId++,g in this.registry&&(this.disposeRegisteredKernels(g),this.registry[g].dispose(),delete this.registry[g]),delete this.registryFactory[g],this.backendName===g&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},A.prototype.getSortedBackends=function(){var g=this;if(Object.keys(this.registryFactory).length===0)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(function(B,Q){return g.registryFactory[Q].priority-g.registryFactory[B].priority})},A.prototype.initializeBackendsAndReturnBest=function(){for(var g=this.getSortedBackends(),B=0;B<g.length;B++){var Q=g[B],w=this.initializeBackend(Q),C=w.success,E=w.asyncInit;if(E||C)return{name:Q,asyncInit:E}}throw new Error("Could not initialize any backends, all backend initializations failed.")},A.prototype.moveData=function(g,B){var Q=this.state.tensorInfo.get(B),w=Q.backend,C=this.readSync(B);w.disposeData(B),Q.backend=g,g.move(B,C,Q.shape,Q.dtype),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},A.prototype.tidy=function(g,B){var Q,w=this,C=null;if(B==null){if(typeof g!="function")throw new Error("Please provide a function to tidy()");B=g}else{if(typeof g!="string"&&!(g instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if(typeof B!="function")throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");C=g}return this.scopedRun(function(){return w.startScope(C)},function(){return w.endScope(Q)},function(){return(Q=B())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),Q})},A.prototype.scopedRun=function(g,B,Q){g();try{var w=Q();return B(),w}catch(C){throw B(),C}},A.prototype.nextTensorId=function(){return A.nextTensorId++},A.prototype.nextVariableId=function(){return A.nextVariableId++},A.prototype.clone=function(g){var B=this.makeTensorFromDataId(g.dataId,g.shape,g.dtype),Q={x:g};return this.addTapeNode(this.state.activeScope.name,Q,[B],function(w){return{x:function(){return w.toFloat()}}},[]),B},A.prototype.runKernel=function(g,B,Q,w,C){return this.runKernelFunc(null,B,null,g,Q,w,C)},A.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},A.prototype.checkKernelForMemLeak=function(g,B,Q){var w=this.backend.numDataIds(),C=0;Q.forEach(function(I){C+=I.dtype==="complex64"?3:1});var E=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],e=w-B-C-E;if(e>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+e+" data ids) after running '"+g+"'")},A.prototype.runKernelFunc=function(g,B,Q,w,C,E,e){var I,o=this;E===void 0&&(E=[]),e===void 0&&(e=[]);var n=[],i=this.isTapeOn();w==null&&(w=this.state.activeScope!=null?this.state.activeScope.name:"");var Y,M=function(s){i&&(n=s.map(function(u){return o.keep(o.clone(u))}))},c=this.state.numBytes,D=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var r,F=kM(w,this.backendName);return Y=F!=null?function(){var s=o.backend.numDataIds();r=F.kernelFunc({inputs:B,attrs:C,backend:o.backend});var u=Array.isArray(r)?r:[r];o.shouldCheckForMemLeaks()&&o.checkKernelForMemLeak(w,s,u);var a=u.map(function(G){var d=G.dataId,H=G.shape,h=G.dtype;return o.makeTensorFromDataId(d,H,h)}),U=a.filter(function(G,d){return e[d]});return M((E||[]).slice().concat(U)),a}:function(){var s=o.backend.numDataIds();r=o.tidy(function(){return g(o.backend,M)});var u=Array.isArray(r)?r:[r];return o.shouldCheckForMemLeaks()&&o.checkKernelForMemLeak(w,s,u),u},this.scopedRun(function(){return o.state.kernelDepth++},function(){return o.state.kernelDepth--},function(){I=o.ENV.getBool("DEBUG")?o.profiler.profileKernel(w,B,function(){return Y()}):Y()}),i&&this.addTapeNode(w,B,I,Q,n),this.state.profiling&&this.state.activeProfile.kernels.push({name:w,bytesAdded:this.state.numBytes-c,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-D,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(B).map(function(s){return B[s].shape}),outputShapes:I.map(function(s){return s.shape})}),Array.isArray(r)?I:I[0]},A.prototype.makeTensor=function(g,B,Q,w){if(g==null)throw new Error("Values passed to engine.makeTensor() are null");Q=Q||"float32",w=w||this.backend;var C=g;Q==="string"&&Po(g[0])&&(C=g.map(function(n){return yd(n)}));var E=w.write(C,B,Q),e=new uB(B,Q,E,this.nextTensorId());if(this.incRef(e,w),Q==="string"){var I=this.state.tensorInfo.get(E),o=Td(C);this.state.numBytes+=o-I.bytes,I.bytes=o}return e},A.prototype.makeTensorFromDataId=function(g,B,Q,w){var C=new uB(B,Q=Q||"float32",g,this.nextTensorId());return this.incRef(C,w),C},A.prototype.makeVariable=function(g,B,Q,w){B===void 0&&(B=!0),Q=Q||this.nextVariableId().toString(),w!=null&&w!==g.dtype&&(g=g.asType(w));var C=new pw(g,B,Q,this.nextTensorId());if(this.state.registeredVariables[C.name]!=null)throw new Error("Variable with name "+C.name+" was already registered");return this.state.registeredVariables[C.name]=C,this.incRef(C,this.backend),C},A.prototype.incRef=function(g,B){var Q=this.state.tensorInfo.has(g.dataId)?this.state.tensorInfo.get(g.dataId).refCount:0;if(this.state.numTensors++,g.dtype==="string"&&this.state.numStringTensors++,Q===0){this.state.numDataBuffers++;var w=0;g.dtype!=="complex64"&&g.dtype!=="string"&&(w=g.size*WM(g.dtype)),this.state.tensorInfo.set(g.dataId,{backend:B||this.backend,dtype:g.dtype,shape:g.shape,bytes:w,refCount:0}),this.state.numBytes+=w}this.state.tensorInfo.get(g.dataId).refCount++,g instanceof pw||this.track(g)},A.prototype.disposeTensor=function(g){if(this.state.tensorInfo.has(g.dataId)){this.state.numTensors--,g.dtype==="string"&&this.state.numStringTensors--;var B=this.state.tensorInfo.get(g.dataId);B.refCount<=1?(g.dtype!=="complex64"&&(this.state.numBytes-=B.bytes),this.state.numDataBuffers--,B.backend.disposeData(g.dataId),this.state.tensorInfo.delete(g.dataId)):this.state.tensorInfo.get(g.dataId).refCount--}},A.prototype.disposeVariables=function(){for(var g in this.state.registeredVariables){var B=this.state.registeredVariables[g];this.disposeVariable(B)}},A.prototype.disposeVariable=function(g){this.disposeTensor(g),this.state.registeredVariables[g.name]!=null&&delete this.state.registeredVariables[g.name]},A.prototype.memory=function(){var g=this.backend.memory();return g.numTensors=this.state.numTensors,g.numDataBuffers=this.state.numDataBuffers,g.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(g.unreliable=!0,g.reasons==null&&(g.reasons=[]),g.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),g},A.prototype.profile=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){return this.state.profiling=!0,B=this.state.numBytes,Q=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=g(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(C){return C.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-B,this.state.activeProfile.newTensors=this.state.numTensors-Q,[2,this.state.activeProfile]})})},A.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&this.state.kernelDepth===0},A.prototype.addTapeNode=function(g,B,Q,w,C){var E=this,e={id:this.state.nextTapeNodeId++,kernelName:g,inputs:B,outputs:Q,saved:C},I=fd(g);I!=null&&(w=I.gradFunc),w!=null&&(e.gradient=function(o){return o=o.map(function(n,i){if(n==null){var Y=Q[i],M=fC(Y.size,Y.dtype);return E.makeTensor(M,Y.shape,Y.dtype)}return n}),w(o.length>1?o:o[0],C)}),this.state.activeTape.push(e)},A.prototype.keep=function(g){return g.kept=!0,g},A.prototype.startTape=function(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++},A.prototype.endTape=function(){this.state.gradientDepth--},A.prototype.startScope=function(g){var B={track:[],name:"unnamed scope",id:this.state.nextScopeId++};g&&(B.name=g),this.state.scopeStack.push(B),this.state.activeScope=B},A.prototype.endScope=function(g){for(var B=this,Q=qM(g),w=new Set(Q.map(function(I){return I.id})),C=0;C<this.state.activeScope.track.length;C++){var E=this.state.activeScope.track[C];E.kept||w.has(E.id)||E.dispose()}var e=this.state.scopeStack.pop();this.state.activeScope=this.state.scopeStack.length===0?null:this.state.scopeStack[this.state.scopeStack.length-1],Q.forEach(function(I){I.kept||I.scopeId!==e.id||B.track(I)})},A.prototype.gradients=function(g,B,Q,w){var C=this;if(w===void 0&&(w=!1),R(B.length>0,function(){return"gradients() received an empty list of xs."}),Q!=null&&Q.dtype!=="float32")throw new Error("dy must have 'float32' dtype, but has '"+Q.dtype+"'");var E=this.scopedRun(function(){return C.startTape()},function(){return C.endTape()},function(){return C.tidy("forward",g)});R(E instanceof uB,function(){return"The result y returned by f() must be a tensor."});var e=function(I,o,n){for(var i={},Y={},M=0;M<o.length;M++)i[o[M].id]=!0;for(M=0;M<I.length;M++){var c=(G=I[M]).inputs;for(var D in c){for(var r=c[D],F=!1,s=0;s<o.length;s++)if(i[r.id]){G.outputs.forEach(function(l){return i[l.id]=!0}),F=!0,Y[G.id]=!0;break}if(F)break}}var u={};u[n.id]=!0;var a={};for(M=I.length-1;M>=0;M--)for(c=(G=I[M]).inputs,s=0;s<G.outputs.length;s++)if(u[G.outputs[s].id]){for(var D in c)u[c[D].id]=!0,a[G.id]=!0;break}var U=[];for(M=0;M<I.length;M++){var G;if(Y[(G=I[M]).id]&&a[G.id]){var d={};for(var D in G.inputs){var H=G.inputs[D];i[H.id]&&(d[D]=H)}var h=Object.assign({},G);h.inputs=d,h.outputs=G.outputs,U.push(h)}}return U}(this.state.activeTape,B,E);if(!w&&e.length===0&&B.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",function(){var I,o,n={};n[E.id]=Q??(I=E.shape,o=bM(hA(I),"float32"),b.makeTensor(o,I,"float32")),function(Y,M,c){for(var D=function(F){var s=M[F],u=[];if(s.outputs.forEach(function(d){var H=Y[d.id];H!=null?u.push(H):u.push(null)}),s.gradient==null)throw new Error("Cannot compute gradient: gradient function not found for "+s.kernelName+".");var a=s.gradient(u),U=function(d){if(!(d in a))throw new Error("Cannot backprop through input "+d+". Available gradients found: "+Object.keys(a)+".");var H=c(function(){return a[d]()});if(H.dtype!=="float32")throw new Error("Error in gradient for op "+s.kernelName+". The gradient of input "+d+" must have 'float32' dtype, but has '"+H.dtype+"'");var h=s.inputs[d];if(!KB(H.shape,h.shape))throw new Error("Error in gradient for op "+s.kernelName+". The gradient of input '"+d+"' has shape '"+H.shape+"', which does not match the shape of the input '"+h.shape+"'");if(Y[h.id]==null)Y[h.id]=H;else{var l=Y[h.id];Y[h.id]=l.add(H),l.dispose()}};for(var G in s.inputs)U(G)},r=M.length-1;r>=0;r--)D(r)}(n,e,function(Y){return C.tidy(Y)});var i=B.map(function(Y){return n[Y.id]});return C.state.gradientDepth===0&&(C.state.activeTape.forEach(function(Y){for(var M=0,c=Y.saved;M<c.length;M++)c[M].dispose()}),C.state.activeTape=null),{value:E,grads:i}})},A.prototype.customGrad=function(g){var B=this;return R(vo(g),function(){return"The f passed in customGrad(f) must be a function."}),function(){for(var Q,w=[],C=0;C<arguments.length;C++)w[C]=arguments[C];R(w.every(function(e){return e instanceof uB}),function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"});var E={};return w.forEach(function(e,I){E[I]=e}),B.runKernelFunc(function(e,I){return R((Q=g.apply(void 0,w.concat([I]))).value instanceof uB,function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"}),R(vo(Q.gradFunc),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."}),Q.value},E,function(e,I){var o=Q.gradFunc(e,I),n=Array.isArray(o)?o:[o];R(n.length===w.length,function(){return"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(...)."}),R(n.every(function(Y){return Y instanceof uB}),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."});var i={};return n.forEach(function(Y,M){i[M]=function(){return Y}}),i})}},A.prototype.readSync=function(g){return this.state.tensorInfo.get(g).backend.readSync(g)},A.prototype.read=function(g){return this.state.tensorInfo.get(g).backend.read(g)},A.prototype.time=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){switch(w.label){case 0:return B=Zg(),[4,this.backend.time(g)];case 1:return(Q=w.sent()).wallMs=Zg()-B,[2,Q]}})})},A.prototype.track=function(g){return this.state.activeScope!=null&&(g.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(g)),g},Object.defineProperty(A.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),A.prototype.reset=function(){for(var g in this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new _M,this.registry)this.disposeRegisteredKernels(g),this.registry[g].dispose(),delete this.registry[g];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},A.nextTensorId=0,A.nextVariableId=0,A}(),b=function(){var A=function(){if(So==null){var B=void 0;if(typeof window<"u")B=window;else if(typeof global<"u")B=global;else if(typeof process<"u")B=process;else{if(typeof self>"u")throw new Error("Could not find a global object");B=self}So=B}return So}();if(A._tfengine==null){var g=new dd(A);A._tfengine=new Vd(g)}return function(B){vM=B}(A._tfengine.ENV),qg=function(){return A._tfengine},A._tfengine}();function $M(){return typeof window<"u"&&window.document!=null||typeof WorkerGlobalScope<"u"}var cQ=BA();cQ.registerFlag("DEBUG",function(){return!1},function(A){A&&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.")}),cQ.registerFlag("IS_BROWSER",function(){return $M()}),cQ.registerFlag("IS_NODE",function(){return typeof process<"u"&&process.versions!==void 0&&process.versions.node!==void 0}),cQ.registerFlag("IS_CHROME",function(){return typeof navigator<"u"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),cQ.registerFlag("PROD",function(){return!1}),cQ.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return cQ.getBool("DEBUG")}),cQ.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),cQ.registerFlag("IS_TEST",function(){return!1});var PC,hg,lg,Bw={},Lo={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function xd(A,g){Bw[A]=g}function _g(A){A in Bw||(Bw[A]=function(B){if(B!==1&&B!==2)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var Q=function(w){if(typeof OffscreenCanvas<"u"&&w===2)return new OffscreenCanvas(300,150);if(typeof document<"u")return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(B);return Q.addEventListener("webglcontextlost",function(w){w.preventDefault(),delete Bw[B]},!1),B===1?Q.getContext("webgl",Lo)||Q.getContext("experimental-webgl",Lo):Q.getContext("webgl2",Lo)}(A));var g=Bw[A];return g.isContextLost()?(delete Bw[A],_g(A)):(g.disable(g.DEPTH_TEST),g.disable(g.STENCIL_TEST),g.disable(g.BLEND),g.disable(g.DITHER),g.disable(g.POLYGON_OFFSET_FILL),g.disable(g.SAMPLE_COVERAGE),g.enable(g.SCISSOR_TEST),g.enable(g.CULL_FACE),g.cullFace(g.BACK),Bw[A])}function OE(A,g){return[g,A]}function vC(A){var g=hA(A);return Ro(Math.ceil(g/4))}function kC(A,g){return[Math.max(1,Math.ceil(g/2)),Math.max(1,Math.ceil(A/2))]}function bo(A,g){var B,Q,w,C,E,e,I,o,n,i=A;return BA().getNumber("WEBGL_VERSION")===2?(B=i.R32F,Q=i.R16F,w=i.RGBA16F,C=i.RGBA32F,E=i.RED,e=4,I=1,o=i.HALF_FLOAT,n=i.FLOAT):(B=A.RGBA,Q=A.RGBA,w=A.RGBA,C=i.RGBA,E=A.RGBA,e=4,I=4,o=g!=null?g.HALF_FLOAT_OES:null,n=A.FLOAT),{internalFormatFloat:B,internalFormatHalfFloat:Q,internalFormatPackedHalfFloat:w,internalFormatPackedFloat:C,textureFormatFloat:E,downloadTextureFormat:A.RGBA,downloadUnpackNumChannels:e,defaultNumChannels:I,textureTypeHalfFloat:o,textureTypeFloat:n}}function lA(A,g,B){var Q=B();return g&&function(w){var C=w.getError();if(C!==w.NO_ERROR)throw new Error("WebGL Error: "+qd(w,C))}(A),Q}(function(A){A[A.DENSE=0]="DENSE",A[A.SHARED_BATCH=1]="SHARED_BATCH"})(PC||(PC={})),function(A){A[A.RENDER=0]="RENDER",A[A.UPLOAD=1]="UPLOAD",A[A.PIXELS=2]="PIXELS",A[A.DOWNLOAD=3]="DOWNLOAD"}(hg||(hg={})),function(A){A[A.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",A[A.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",A[A.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",A[A.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",A[A.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}(lg||(lg={}));var Xd=596e-10,Od=65504;function Zd(A){return!!(BA().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||A===0||Xd<Math.abs(A)&&Math.abs(A)<Od)}function qd(A,g){switch(g){case A.NO_ERROR:return"NO_ERROR";case A.INVALID_ENUM:return"INVALID_ENUM";case A.INVALID_VALUE:return"INVALID_VALUE";case A.INVALID_OPERATION:return"INVALID_OPERATION";case A.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case A.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case A.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+g}}function ZE(A,g,B){return DQ(A,g,function(){return A.getExtension(B)},'Extension "'+B+'" not supported on this browser.')}function _d(A,g,B){var Q=DQ(A,g,function(){return A.createShader(A.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(lA(A,g,function(){return A.shaderSource(Q,B)}),lA(A,g,function(){return A.compileShader(Q)}),A.getShaderParameter(Q,A.COMPILE_STATUS)===!1)throw console.log(A.getShaderInfoLog(Q)),new Error("Failed to compile vertex shader.");return Q}function $d(A,g,B){var Q=DQ(A,g,function(){return A.createShader(A.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(lA(A,g,function(){return A.shaderSource(Q,B)}),lA(A,g,function(){return A.compileShader(Q)}),A.getShaderParameter(Q,A.COMPILE_STATUS)===!1)throw function(w,C){var E=AH.exec(C);if(E==null)return console.log("Couldn't parse line number in error: "+C),void console.log(w);for(var e=+E[1],I=w.split(`
26
+ `)}function NC(A,g,B){return jw(Array.isArray(A)?parseFloat(A[0].toFixed(jo))+" + "+parseFloat(A[1].toFixed(jo))+"j":vo(A)?"'"+A+"'":B==="bool"?XM(A):parseFloat(A.toFixed(jo)).toString(),g)}function XM(A){return A===0?"false":"true"}function mC(A){for(var g=[],B=0;B<A.length;B+=2)g.push([A[B],A[B+1]]);return g}var RC=function(){function A(g,B,Q){var w=this;if(this.dtype=B,this.shape=g.slice(),this.size=hA(g),Q!=null){var C=Q.length;R(C===this.size,function(){return"Length of values '"+C+"' does not match the size inferred by the shape '"+w.size+"'."})}if(B==="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=Q||xE(B,this.size),this.strides=Og(g)}return A.prototype.set=function(g){for(var B=this,Q=[],w=1;w<arguments.length;w++)Q[w-1]=arguments[w];Q.length===0&&(Q=[0]),R(Q.length===this.rank,function(){return"The number of provided coordinates ("+Q.length+") must match the rank ("+B.rank+")"});var C=this.locToIndex(Q);this.values[C]=g},A.prototype.get=function(){for(var g=[],B=0;B<arguments.length;B++)g[B]=arguments[B];g.length===0&&(g=[0]);for(var Q=0,w=0,C=g;w<C.length;w++){var E=C[w];if(E<0||E>=this.shape[Q]){var e="Requested out of range element at "+g+". Buffer shape="+this.shape;throw new Error(e)}Q++}for(var I=g[g.length-1],o=0;o<g.length-1;++o)I+=this.strides[o]*g[o];return this.values[I]},A.prototype.locToIndex=function(g){if(this.rank===0)return 0;if(this.rank===1)return g[0];for(var B=g[g.length-1],Q=0;Q<g.length-1;++Q)B+=this.strides[Q]*g[Q];return B},A.prototype.indexToLoc=function(g){if(this.rank===0)return[];if(this.rank===1)return[g];for(var B=new Array(this.shape.length),Q=0;Q<B.length-1;++Q)B[Q]=Math.floor(g/this.strides[Q]),g-=B[Q]*this.strides[Q];return B[B.length-1]=g,B},Object.defineProperty(A.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),A.prototype.toTensor=function(){return qg().makeTensor(this.values,this.shape,this.dtype)},A}(),qg=null,O=null,OM=null,uB=function(){function A(g,B,Q,w){this.kept=!1,this.isDisposedInternal=!1,this.shape=g.slice(),this.dtype=B||"float32",this.size=hA(g),this.strides=Og(g),this.dataId=Q,this.id=w,this.rankType=this.rank<5?this.rank.toString():"higher"}return A.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D()},A.prototype.asScalar=function(){return this.throwIfDisposed(),R(this.size===1,function(){return"The array must have only 1 element."}),this.reshape([])},A.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size])},A.prototype.as2D=function(g,B){return this.throwIfDisposed(),this.reshape([g,B])},A.prototype.as3D=function(g,B,Q){return this.throwIfDisposed(),this.reshape([g,B,Q])},A.prototype.as4D=function(g,B,Q,w){return this.throwIfDisposed(),this.reshape([g,B,Q,w])},A.prototype.as5D=function(g,B,Q,w,C){return this.throwIfDisposed(),this.reshape([g,B,Q,w,C])},A.prototype.asType=function(g){return this.throwIfDisposed(),O.cast(this,g)},Object.defineProperty(A.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),A.prototype.buffer=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return[4,this.data()];case 1:return g=B.sent(),[2,O.buffer(this.shape,this.dtype,g)]}})})},A.prototype.bufferSync=function(){return O.buffer(this.shape,this.dtype,this.dataSync())},A.prototype.array=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return[4,this.data()];case 1:return g=B.sent(),[2,LM(this.shape,g)]}})})},A.prototype.arraySync=function(){return LM(this.shape,this.dataSync())},A.prototype.data=function(){return uA(this,void 0,void 0,function(){var g,B;return UA(this,function(Q){switch(Q.label){case 0:return this.throwIfDisposed(),g=qg().read(this.dataId),this.dtype!=="string"?[3,2]:[4,g];case 1:B=Q.sent();try{return[2,B.map(function(w){return XE(w)})]}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}Q.label=2;case 2:return[2,g]}})})},A.prototype.dataSync=function(){this.throwIfDisposed();var g=qg().readSync(this.dataId);if(this.dtype==="string")try{return g.map(function(B){return XE(B)})}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return g},A.prototype.bytes=function(){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){switch(B.label){case 0:return this.throwIfDisposed(),[4,qg().read(this.dataId)];case 1:return g=B.sent(),this.dtype==="string"?[2,g]:[2,new Uint8Array(g.buffer)]}})})},A.prototype.dispose=function(){this.isDisposed||(qg().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(A.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),A.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},A.prototype.toFloat=function(){return this.asType("float32")},A.prototype.toInt=function(){return this.asType("int32")},A.prototype.toBool=function(){return this.asType("bool")},A.prototype.print=function(g){return g===void 0&&(g=!1),O.print(this,g)},A.prototype.reshape=function(g){return this.throwIfDisposed(),O.reshape(this,g)},A.prototype.reshapeAs=function(g){return this.throwIfDisposed(),this.reshape(g.shape)},A.prototype.expandDims=function(g){return g===void 0&&(g=0),O.expandDims(this,g)},A.prototype.cumsum=function(g,B,Q){return g===void 0&&(g=0),B===void 0&&(B=!1),Q===void 0&&(Q=!1),O.cumsum(this,g,B,Q)},A.prototype.squeeze=function(g){return this.throwIfDisposed(),O.squeeze(this,g)},A.prototype.clone=function(){return this.throwIfDisposed(),O.clone(this)},A.prototype.oneHot=function(g,B,Q){return this.throwIfDisposed(),O.oneHot(this,g,B,Q)},A.prototype.toString=function(g){return g===void 0&&(g=!1),Kd(this.dataSync(),this.shape,this.dtype,g)},A.prototype.tile=function(g){return this.throwIfDisposed(),O.tile(this,g)},A.prototype.gather=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),O.gather(this,g,B)},A.prototype.matMul=function(g,B,Q){return B===void 0&&(B=!1),Q===void 0&&(Q=!1),this.throwIfDisposed(),O.matMul(this,g,B,Q)},A.prototype.dot=function(g){return this.throwIfDisposed(),O.dot(this,g)},A.prototype.norm=function(g,B,Q){return g===void 0&&(g="euclidean"),B===void 0&&(B=null),Q===void 0&&(Q=!1),this.throwIfDisposed(),O.norm(this,g,B,Q)},A.prototype.slice=function(g,B){return this.throwIfDisposed(),O.slice(this,g,B)},A.prototype.reverse=function(g){return this.throwIfDisposed(),O.reverse(this,g)},A.prototype.concat=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),g instanceof A&&(g=[g]),O.concat([this].concat(g),B)},A.prototype.split=function(g,B){return B===void 0&&(B=0),this.throwIfDisposed(),O.split(this,g,B)},A.prototype.stack=function(g,B){return B===void 0&&(B=0),O.stack([this,g],B)},A.prototype.unstack=function(g){return g===void 0&&(g=0),O.unstack(this,g)},A.prototype.pad=function(g,B){return B===void 0&&(B=0),O.pad(this,g,B)},A.prototype.batchNormalization=function(g,B,Q,w,C){return Q===void 0&&(Q=.001),OM("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(g,B,C,w,Q)},A.prototype.batchNorm=function(g,B,Q,w,C){return C===void 0&&(C=.001),this.throwIfDisposed(),O.batchNorm(this,g,B,Q,w,C)},A.prototype.all=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.all(this,g,B)},A.prototype.any=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.any(this,g,B)},A.prototype.logSumExp=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.logSumExp(this,g,B)},A.prototype.sum=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.sum(this,g,B)},A.prototype.prod=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.prod(this,g,B)},A.prototype.mean=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.mean(this,g,B)},A.prototype.min=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.min(this,g,B)},A.prototype.max=function(g,B){return g===void 0&&(g=null),B===void 0&&(B=!1),this.throwIfDisposed(),O.max(this,g,B)},A.prototype.argMin=function(g){return g===void 0&&(g=null),this.throwIfDisposed(),O.argMin(this,g)},A.prototype.argMax=function(g){return g===void 0&&(g=null),this.throwIfDisposed(),O.argMax(this,g)},A.prototype.cast=function(g){return this.throwIfDisposed(),O.cast(this,g)},A.prototype.add=function(g){return this.throwIfDisposed(),O.add(this,g)},A.prototype.addStrict=function(g){return this.throwIfDisposed(),O.addStrict(this,g)},A.prototype.atan2=function(g){return this.throwIfDisposed(),O.atan2(this,g)},A.prototype.sub=function(g){return this.throwIfDisposed(),O.sub(this,g)},A.prototype.subStrict=function(g){return this.throwIfDisposed(),O.subStrict(this,g)},A.prototype.pow=function(g){return this.throwIfDisposed(),O.pow(this,g)},A.prototype.powStrict=function(g){return this.throwIfDisposed(),O.powStrict(this,g)},A.prototype.mul=function(g){return this.throwIfDisposed(),O.mul(this,g)},A.prototype.mulStrict=function(g){return this.throwIfDisposed(),O.mulStrict(this,g)},A.prototype.div=function(g){return this.throwIfDisposed(),O.div(this,g)},A.prototype.divNoNan=function(g){return this.throwIfDisposed(),O.divNoNan(this,g)},A.prototype.floorDiv=function(g){return this.throwIfDisposed(),O.floorDiv(this,g)},A.prototype.divStrict=function(g){return this.throwIfDisposed(),O.divStrict(this,g)},A.prototype.minimum=function(g){return this.throwIfDisposed(),O.minimum(this,g)},A.prototype.minimumStrict=function(g){return this.throwIfDisposed(),O.minimumStrict(this,g)},A.prototype.maximum=function(g){return this.throwIfDisposed(),O.maximum(this,g)},A.prototype.maximumStrict=function(g){return this.throwIfDisposed(),O.maximumStrict(this,g)},A.prototype.mod=function(g){return this.throwIfDisposed(),O.mod(this,g)},A.prototype.modStrict=function(g){return this.throwIfDisposed(),O.modStrict(this,g)},A.prototype.squaredDifferenceStrict=function(g){return this.throwIfDisposed(),O.squaredDifferenceStrict(this,g)},A.prototype.transpose=function(g){return this.throwIfDisposed(),O.transpose(this,g)},A.prototype.notEqual=function(g){return this.throwIfDisposed(),O.notEqual(this,g)},A.prototype.notEqualStrict=function(g){return this.throwIfDisposed(),O.notEqualStrict(this,g)},A.prototype.less=function(g){return this.throwIfDisposed(),O.less(this,g)},A.prototype.lessStrict=function(g){return this.throwIfDisposed(),O.lessStrict(this,g)},A.prototype.equal=function(g){return this.throwIfDisposed(),O.equal(this,g)},A.prototype.equalStrict=function(g){return this.throwIfDisposed(),O.equalStrict(this,g)},A.prototype.lessEqual=function(g){return this.throwIfDisposed(),O.lessEqual(this,g)},A.prototype.lessEqualStrict=function(g){return this.throwIfDisposed(),O.lessEqualStrict(this,g)},A.prototype.greater=function(g){return this.throwIfDisposed(),O.greater(this,g)},A.prototype.greaterStrict=function(g){return this.throwIfDisposed(),O.greaterStrict(this,g)},A.prototype.greaterEqual=function(g){return this.throwIfDisposed(),O.greaterEqual(this,g)},A.prototype.greaterEqualStrict=function(g){return this.throwIfDisposed(),O.greaterEqualStrict(this,g)},A.prototype.logicalAnd=function(g){return this.throwIfDisposed(),O.logicalAnd(this,g)},A.prototype.logicalOr=function(g){return this.throwIfDisposed(),O.logicalOr(this,g)},A.prototype.logicalNot=function(){return this.throwIfDisposed(),O.logicalNot(this)},A.prototype.logicalXor=function(g){return this.throwIfDisposed(),O.logicalXor(this,g)},A.prototype.where=function(g,B){return this.throwIfDisposed(),O.where(g,this,B)},A.prototype.neg=function(){return this.throwIfDisposed(),O.neg(this)},A.prototype.ceil=function(){return this.throwIfDisposed(),O.ceil(this)},A.prototype.floor=function(){return this.throwIfDisposed(),O.floor(this)},A.prototype.sign=function(){return this.throwIfDisposed(),O.sign(this)},A.prototype.isNaN=function(){return this.throwIfDisposed(),O.isNaN(this)},A.prototype.isInf=function(){return this.throwIfDisposed(),O.isInf(this)},A.prototype.isFinite=function(){return this.throwIfDisposed(),O.isFinite(this)},A.prototype.exp=function(){return this.throwIfDisposed(),O.exp(this)},A.prototype.expm1=function(){return this.throwIfDisposed(),O.expm1(this)},A.prototype.log=function(){return this.throwIfDisposed(),O.log(this)},A.prototype.log1p=function(){return this.throwIfDisposed(),O.log1p(this)},A.prototype.sqrt=function(){return this.throwIfDisposed(),O.sqrt(this)},A.prototype.rsqrt=function(){return this.throwIfDisposed(),O.rsqrt(this)},A.prototype.square=function(){return this.throwIfDisposed(),O.square(this)},A.prototype.reciprocal=function(){return this.throwIfDisposed(),O.reciprocal(this)},A.prototype.abs=function(){return this.throwIfDisposed(),O.abs(this)},A.prototype.clipByValue=function(g,B){return this.throwIfDisposed(),O.clipByValue(this,g,B)},A.prototype.relu=function(){return this.throwIfDisposed(),O.relu(this)},A.prototype.relu6=function(){return this.throwIfDisposed(),O.relu6(this)},A.prototype.elu=function(){return this.throwIfDisposed(),O.elu(this)},A.prototype.selu=function(){return this.throwIfDisposed(),O.selu(this)},A.prototype.leakyRelu=function(g){return g===void 0&&(g=.2),this.throwIfDisposed(),O.leakyRelu(this,g)},A.prototype.prelu=function(g){return this.throwIfDisposed(),O.prelu(this,g)},A.prototype.sigmoid=function(){return this.throwIfDisposed(),O.sigmoid(this)},A.prototype.logSigmoid=function(){return this.throwIfDisposed(),O.logSigmoid(this)},A.prototype.softplus=function(){return this.throwIfDisposed(),O.softplus(this)},A.prototype.zerosLike=function(){return this.throwIfDisposed(),O.zerosLike(this)},A.prototype.onesLike=function(){return this.throwIfDisposed(),O.onesLike(this)},A.prototype.sin=function(){return this.throwIfDisposed(),O.sin(this)},A.prototype.cos=function(){return this.throwIfDisposed(),O.cos(this)},A.prototype.tan=function(){return this.throwIfDisposed(),O.tan(this)},A.prototype.asin=function(){return this.throwIfDisposed(),O.asin(this)},A.prototype.acos=function(){return this.throwIfDisposed(),O.acos(this)},A.prototype.atan=function(){return this.throwIfDisposed(),O.atan(this)},A.prototype.sinh=function(){return this.throwIfDisposed(),O.sinh(this)},A.prototype.cosh=function(){return this.throwIfDisposed(),O.cosh(this)},A.prototype.tanh=function(){return this.throwIfDisposed(),O.tanh(this)},A.prototype.asinh=function(){return this.throwIfDisposed(),O.asinh(this)},A.prototype.acosh=function(){return this.throwIfDisposed(),O.acosh(this)},A.prototype.atanh=function(){return this.throwIfDisposed(),O.atanh(this)},A.prototype.erf=function(){return this.throwIfDisposed(),O.erf(this)},A.prototype.round=function(){return this.throwIfDisposed(),O.round(this)},A.prototype.step=function(g){return g===void 0&&(g=0),this.throwIfDisposed(),O.step(this,g)},A.prototype.softmax=function(g){return g===void 0&&(g=-1),this.throwIfDisposed(),O.softmax(this,g)},A.prototype.logSoftmax=function(g){return g===void 0&&(g=-1),this.throwIfDisposed(),O.logSoftmax(this,g)},A.prototype.resizeBilinear=function(g,B){return B===void 0&&(B=!1),this.throwIfDisposed(),O.image.resizeBilinear(this,g,B)},A.prototype.resizeNearestNeighbor=function(g,B){return B===void 0&&(B=!1),this.throwIfDisposed(),O.image.resizeNearestNeighbor(this,g,B)},A.prototype.conv1d=function(g,B,Q,w,C,E){return w===void 0&&(w="NWC"),C===void 0&&(C=1),this.throwIfDisposed(),O.conv1d(this,g,B,Q,w,C,E)},A.prototype.conv2d=function(g,B,Q,w,C,E){return w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]),this.throwIfDisposed(),O.conv2d(this,g,B,Q,w,C,E)},A.prototype.conv2dTranspose=function(g,B,Q,w,C){return this.throwIfDisposed(),O.conv2dTranspose(this,g,B,Q,w,C)},A.prototype.depthwiseConv2D=function(g,B,Q,w,C,E){return w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]),this.throwIfDisposed(),O.depthwiseConv2d(this,g,B,Q,w,C,E)},A.prototype.separableConv2d=function(g,B,Q,w,C,E){return C===void 0&&(C=[1,1]),E===void 0&&(E="NHWC"),this.throwIfDisposed(),O.separableConv2d(this,g,B,Q,w,C,E)},A.prototype.avgPool=function(g,B,Q,w){return this.throwIfDisposed(),O.avgPool(this,g,B,Q,w)},A.prototype.maxPool=function(g,B,Q,w){return this.throwIfDisposed(),O.maxPool(this,g,B,Q,w)},A.prototype.localResponseNormalization=function(g,B,Q,w){return g===void 0&&(g=5),B===void 0&&(B=1),Q===void 0&&(Q=1),w===void 0&&(w=.5),O.localResponseNormalization(this,g,B,Q,w)},A.prototype.pool=function(g,B,Q,w,C){return this.throwIfDisposed(),O.pool(this,g,B,Q,w,C)},A.prototype.variable=function(g,B,Q){return g===void 0&&(g=!0),this.throwIfDisposed(),qg().makeVariable(this,g,B,Q)},A.prototype.unsortedSegmentSum=function(g,B){return this.throwIfDisposed(),O.unsortedSegmentSum(this,g,B)},A.prototype.batchToSpaceND=function(g,B){return this.throwIfDisposed(),O.batchToSpaceND(this,g,B)},A.prototype.spaceToBatchND=function(g,B){return this.throwIfDisposed(),O.spaceToBatchND(this,g,B)},A.prototype.topk=function(g,B){return g===void 0&&(g=1),B===void 0&&(B=!0),this.throwIfDisposed(),O.topk(this,g,B)},A.prototype.stridedSlice=function(g,B,Q,w,C,E,e,I){return w===void 0&&(w=0),C===void 0&&(C=0),E===void 0&&(E=0),e===void 0&&(e=0),I===void 0&&(I=0),this.throwIfDisposed(),O.stridedSlice(this,g,B,Q,w,C,E,e,I)},A.prototype.depthToSpace=function(g,B){return this.throwIfDisposed(),O.depthToSpace(this,g,B)},A.prototype.fft=function(){return this.throwIfDisposed(),O.spectral.fft(this)},A.prototype.ifft=function(){return this.throwIfDisposed(),O.spectral.ifft(this)},A.prototype.rfft=function(){return this.throwIfDisposed(),O.spectral.rfft(this)},A.prototype.irfft=function(){return this.throwIfDisposed(),O.spectral.irfft(this)},A}();Object.defineProperty(uB,Symbol.hasInstance,{value:function(A){return!!A&&A.dataId!=null&&A.shape!=null&&A.dtype!=null}});var ZM,po,yo,zo,Wo,pw=function(A){function g(B,Q,w,C){var E=A.call(this,B.shape,B.dtype,B.dataId,C)||this;return E.trainable=Q,E.name=w,E}return Wg(g,A),g.prototype.assign=function(B){if(B.dtype!==this.dtype)throw new Error("dtype of the new value ("+B.dtype+") and previous value ("+this.dtype+") must match");if(!KB(B.shape,this.shape))throw new Error("shape of the new value ("+B.shape+") and previous value ("+this.shape+") must match");qg().disposeTensor(this),this.dataId=B.dataId,qg().incRef(this,null)},g.prototype.dispose=function(){qg().disposeVariable(this),this.isDisposedInternal=!0},g}(uB);Object.defineProperty(pw,Symbol.hasInstance,{value:function(A){return A instanceof uB&&A.assign!=null&&A.assign instanceof Function}}),function(A){A.R0="R0",A.R1="R1",A.R2="R2",A.R3="R3",A.R4="R4",A.R5="R5",A.R6="R6"}(ZM||(ZM={})),function(A){A.float32="float32",A.int32="int32",A.bool="int32",A.complex64="complex64"}(po||(po={})),function(A){A.float32="float32",A.int32="int32",A.bool="bool",A.complex64="complex64"}(yo||(yo={})),function(A){A.float32="float32",A.int32="float32",A.bool="float32",A.complex64="complex64"}(zo||(zo={})),function(A){A.float32="complex64",A.int32="complex64",A.bool="complex64",A.complex64="complex64"}(Wo||(Wo={}));var Vd={float32:zo,int32:po,bool:yo,complex64:Wo};function _B(A,g){if(A==="string"||g==="string"){if(A==="string"&&g==="string")return"string";throw new Error("Can not upcast "+A+" with "+g)}return Vd[A][g]}function So(A){return _B(A,"int32")}function UB(A,g){if(A.dtype===g.dtype)return[A,g];var B=_B(A.dtype,g.dtype);return[A.cast(B),g.cast(B)]}function xd(A,g){R(A.dtype===g.dtype,function(){return"The dtypes of the first("+A.dtype+") and second("+g.dtype+") input must match"})}function qM(A){var g=[];return function B(Q,w,C){if(Q!=null){if(Q instanceof uB)return void w.push(Q);if(E=Q,!(!Array.isArray(E)&&typeof E!="object")){var E,e=Q;for(var I in e){var o=e[I];C.has(o)||(C.add(o),B(o,w,C))}}}}(A,g,new Set),g}var Lo,_M=function(){function A(){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}}return A.prototype.dispose=function(){for(var g in this.registeredVariables)this.registeredVariables[g].dispose()},A}(),Xd=function(){function A(g){this.ENV=g,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new _M}return A.prototype.ready=function(){return uA(this,void 0,void 0,function(){var g,B,Q;return UA(this,function(w){switch(w.label){case 0:if(this.pendingBackendInit!=null)return[2,this.pendingBackendInit.then(function(){})];if(this.backendInstance!=null)return[2];g=this.getSortedBackends(),B=0,w.label=1;case 1:return B<g.length?(Q=g[B],[4,this.initializeBackend(Q).success]):[3,5];case 2:return w.sent()?[4,this.setBackend(Q)]:[3,4];case 3:return w.sent(),[2];case 4:return B++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}})})},Object.defineProperty(A.prototype,"backend",{get:function(){if(this.pendingBackendInit!=null)throw new Error("Backend '"+this.backendName+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");if(this.backendInstance==null){var g=this.initializeBackendsAndReturnBest(),B=g.name;if(g.asyncInit)throw new Error("The highest priority backend '"+B+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");this.setBackend(B)}return this.backendInstance},enumerable:!0,configurable:!0}),A.prototype.backendNames=function(){return Object.keys(this.registryFactory)},A.prototype.findBackend=function(g){return!(g in this.registry)&&(!(g in this.registryFactory)||this.initializeBackend(g).asyncInit)?null:this.registry[g]},A.prototype.findBackendFactory=function(g){return g in this.registryFactory?this.registryFactory[g].factory:null},A.prototype.registerBackend=function(g,B,Q){return Q===void 0&&(Q=1),g in this.registryFactory?(console.warn(g+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[g]={factory:B,priority:Q},!0)},A.prototype.setBackend=function(g){return uA(this,void 0,void 0,function(){var B,Q,w;return UA(this,function(C){switch(C.label){case 0:if(this.registryFactory[g]==null)throw new Error("Backend name '"+g+"' not found in registry");return this.backendName=g,this.registry[g]!=null?[3,4]:(this.backendInstance=null,B=this.initializeBackend(g),Q=B.success,B.asyncInit?[4,Q]:[3,2]);case 1:return w=C.sent(),[3,3];case 2:w=Q,C.label=3;case 3:if(!w)return[2,!1];C.label=4;case 4:return this.backendInstance=this.registry[g],this.setupRegisteredKernels(),this.profiler=new Ld(this.backendInstance),[2,!0]}})})},A.prototype.setupRegisteredKernels=function(){var g=this;TM(this.backendName).forEach(function(B){B.setupFunc!=null&&B.setupFunc(g.backendInstance)})},A.prototype.disposeRegisteredKernels=function(g){var B=this;TM(g).forEach(function(Q){Q.disposeFunc!=null&&Q.disposeFunc(B.registry[g])})},A.prototype.initializeBackend=function(g){var B=this,Q=this.registryFactory[g];if(Q==null)throw new Error("Cannot initialize backend "+g+", no registration found.");try{var w=Q.factory();if(Promise.resolve(w)===w){var C=++this.pendingBackendInitId,E=w.then(function(e){return!(C<B.pendingBackendInitId)&&(B.registry[g]=e,B.pendingBackendInit=null,!0)}).catch(function(e){return!(C<B.pendingBackendInitId)&&(B.pendingBackendInit=null,console.warn("Initialization of backend "+g+" failed"),console.warn(e.stack||e.message),!1)});return this.pendingBackendInit=E,{success:E,asyncInit:!0}}return this.registry[g]=w,{success:!0,asyncInit:!1}}catch(e){return console.warn("Initialization of backend "+g+" failed"),console.warn(e.stack||e.message),{success:!1,asyncInit:!1}}},A.prototype.removeBackend=function(g){if(!(g in this.registryFactory))throw new Error(g+" backend not found in registry");this.backendName===g&&this.pendingBackendInit!=null&&this.pendingBackendInitId++,g in this.registry&&(this.disposeRegisteredKernels(g),this.registry[g].dispose(),delete this.registry[g]),delete this.registryFactory[g],this.backendName===g&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},A.prototype.getSortedBackends=function(){var g=this;if(Object.keys(this.registryFactory).length===0)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(function(B,Q){return g.registryFactory[Q].priority-g.registryFactory[B].priority})},A.prototype.initializeBackendsAndReturnBest=function(){for(var g=this.getSortedBackends(),B=0;B<g.length;B++){var Q=g[B],w=this.initializeBackend(Q),C=w.success,E=w.asyncInit;if(E||C)return{name:Q,asyncInit:E}}throw new Error("Could not initialize any backends, all backend initializations failed.")},A.prototype.moveData=function(g,B){var Q=this.state.tensorInfo.get(B),w=Q.backend,C=this.readSync(B);w.disposeData(B),Q.backend=g,g.move(B,C,Q.shape,Q.dtype),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},A.prototype.tidy=function(g,B){var Q,w=this,C=null;if(B==null){if(typeof g!="function")throw new Error("Please provide a function to tidy()");B=g}else{if(typeof g!="string"&&!(g instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if(typeof B!="function")throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");C=g}return this.scopedRun(function(){return w.startScope(C)},function(){return w.endScope(Q)},function(){return(Q=B())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),Q})},A.prototype.scopedRun=function(g,B,Q){g();try{var w=Q();return B(),w}catch(C){throw B(),C}},A.prototype.nextTensorId=function(){return A.nextTensorId++},A.prototype.nextVariableId=function(){return A.nextVariableId++},A.prototype.clone=function(g){var B=this.makeTensorFromDataId(g.dataId,g.shape,g.dtype),Q={x:g};return this.addTapeNode(this.state.activeScope.name,Q,[B],function(w){return{x:function(){return w.toFloat()}}},[]),B},A.prototype.runKernel=function(g,B,Q,w,C){return this.runKernelFunc(null,B,null,g,Q,w,C)},A.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},A.prototype.checkKernelForMemLeak=function(g,B,Q){var w=this.backend.numDataIds(),C=0;Q.forEach(function(I){C+=I.dtype==="complex64"?3:1});var E=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],e=w-B-C-E;if(e>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+e+" data ids) after running '"+g+"'")},A.prototype.runKernelFunc=function(g,B,Q,w,C,E,e){var I,o=this;E===void 0&&(E=[]),e===void 0&&(e=[]);var n=[],i=this.isTapeOn();w==null&&(w=this.state.activeScope!=null?this.state.activeScope.name:"");var Y,M=function(s){i&&(n=s.map(function(u){return o.keep(o.clone(u))}))},c=this.state.numBytes,D=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var r,F=kM(w,this.backendName);return Y=F!=null?function(){var s=o.backend.numDataIds();r=F.kernelFunc({inputs:B,attrs:C,backend:o.backend});var u=Array.isArray(r)?r:[r];o.shouldCheckForMemLeaks()&&o.checkKernelForMemLeak(w,s,u);var a=u.map(function(G){var d=G.dataId,H=G.shape,h=G.dtype;return o.makeTensorFromDataId(d,H,h)}),U=a.filter(function(G,d){return e[d]});return M((E||[]).slice().concat(U)),a}:function(){var s=o.backend.numDataIds();r=o.tidy(function(){return g(o.backend,M)});var u=Array.isArray(r)?r:[r];return o.shouldCheckForMemLeaks()&&o.checkKernelForMemLeak(w,s,u),u},this.scopedRun(function(){return o.state.kernelDepth++},function(){return o.state.kernelDepth--},function(){I=o.ENV.getBool("DEBUG")?o.profiler.profileKernel(w,B,function(){return Y()}):Y()}),i&&this.addTapeNode(w,B,I,Q,n),this.state.profiling&&this.state.activeProfile.kernels.push({name:w,bytesAdded:this.state.numBytes-c,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-D,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(B).map(function(s){return B[s].shape}),outputShapes:I.map(function(s){return s.shape})}),Array.isArray(r)?I:I[0]},A.prototype.makeTensor=function(g,B,Q,w){if(g==null)throw new Error("Values passed to engine.makeTensor() are null");Q=Q||"float32",w=w||this.backend;var C=g;Q==="string"&&vo(g[0])&&(C=g.map(function(n){return Wd(n)}));var E=w.write(C,B,Q),e=new uB(B,Q,E,this.nextTensorId());if(this.incRef(e,w),Q==="string"){var I=this.state.tensorInfo.get(E),o=pd(C);this.state.numBytes+=o-I.bytes,I.bytes=o}return e},A.prototype.makeTensorFromDataId=function(g,B,Q,w){var C=new uB(B,Q=Q||"float32",g,this.nextTensorId());return this.incRef(C,w),C},A.prototype.makeVariable=function(g,B,Q,w){B===void 0&&(B=!0),Q=Q||this.nextVariableId().toString(),w!=null&&w!==g.dtype&&(g=g.asType(w));var C=new pw(g,B,Q,this.nextTensorId());if(this.state.registeredVariables[C.name]!=null)throw new Error("Variable with name "+C.name+" was already registered");return this.state.registeredVariables[C.name]=C,this.incRef(C,this.backend),C},A.prototype.incRef=function(g,B){var Q=this.state.tensorInfo.has(g.dataId)?this.state.tensorInfo.get(g.dataId).refCount:0;if(this.state.numTensors++,g.dtype==="string"&&this.state.numStringTensors++,Q===0){this.state.numDataBuffers++;var w=0;g.dtype!=="complex64"&&g.dtype!=="string"&&(w=g.size*WM(g.dtype)),this.state.tensorInfo.set(g.dataId,{backend:B||this.backend,dtype:g.dtype,shape:g.shape,bytes:w,refCount:0}),this.state.numBytes+=w}this.state.tensorInfo.get(g.dataId).refCount++,g instanceof pw||this.track(g)},A.prototype.disposeTensor=function(g){if(this.state.tensorInfo.has(g.dataId)){this.state.numTensors--,g.dtype==="string"&&this.state.numStringTensors--;var B=this.state.tensorInfo.get(g.dataId);B.refCount<=1?(g.dtype!=="complex64"&&(this.state.numBytes-=B.bytes),this.state.numDataBuffers--,B.backend.disposeData(g.dataId),this.state.tensorInfo.delete(g.dataId)):this.state.tensorInfo.get(g.dataId).refCount--}},A.prototype.disposeVariables=function(){for(var g in this.state.registeredVariables){var B=this.state.registeredVariables[g];this.disposeVariable(B)}},A.prototype.disposeVariable=function(g){this.disposeTensor(g),this.state.registeredVariables[g.name]!=null&&delete this.state.registeredVariables[g.name]},A.prototype.memory=function(){var g=this.backend.memory();return g.numTensors=this.state.numTensors,g.numDataBuffers=this.state.numDataBuffers,g.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(g.unreliable=!0,g.reasons==null&&(g.reasons=[]),g.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),g},A.prototype.profile=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){return this.state.profiling=!0,B=this.state.numBytes,Q=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=g(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(C){return C.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-B,this.state.activeProfile.newTensors=this.state.numTensors-Q,[2,this.state.activeProfile]})})},A.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&this.state.kernelDepth===0},A.prototype.addTapeNode=function(g,B,Q,w,C){var E=this,e={id:this.state.nextTapeNodeId++,kernelName:g,inputs:B,outputs:Q,saved:C},I=Nd(g);I!=null&&(w=I.gradFunc),w!=null&&(e.gradient=function(o){return o=o.map(function(n,i){if(n==null){var Y=Q[i],M=fC(Y.size,Y.dtype);return E.makeTensor(M,Y.shape,Y.dtype)}return n}),w(o.length>1?o:o[0],C)}),this.state.activeTape.push(e)},A.prototype.keep=function(g){return g.kept=!0,g},A.prototype.startTape=function(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++},A.prototype.endTape=function(){this.state.gradientDepth--},A.prototype.startScope=function(g){var B={track:[],name:"unnamed scope",id:this.state.nextScopeId++};g&&(B.name=g),this.state.scopeStack.push(B),this.state.activeScope=B},A.prototype.endScope=function(g){for(var B=this,Q=qM(g),w=new Set(Q.map(function(I){return I.id})),C=0;C<this.state.activeScope.track.length;C++){var E=this.state.activeScope.track[C];E.kept||w.has(E.id)||E.dispose()}var e=this.state.scopeStack.pop();this.state.activeScope=this.state.scopeStack.length===0?null:this.state.scopeStack[this.state.scopeStack.length-1],Q.forEach(function(I){I.kept||I.scopeId!==e.id||B.track(I)})},A.prototype.gradients=function(g,B,Q,w){var C=this;if(w===void 0&&(w=!1),R(B.length>0,function(){return"gradients() received an empty list of xs."}),Q!=null&&Q.dtype!=="float32")throw new Error("dy must have 'float32' dtype, but has '"+Q.dtype+"'");var E=this.scopedRun(function(){return C.startTape()},function(){return C.endTape()},function(){return C.tidy("forward",g)});R(E instanceof uB,function(){return"The result y returned by f() must be a tensor."});var e=function(I,o,n){for(var i={},Y={},M=0;M<o.length;M++)i[o[M].id]=!0;for(M=0;M<I.length;M++){var c=(G=I[M]).inputs;for(var D in c){for(var r=c[D],F=!1,s=0;s<o.length;s++)if(i[r.id]){G.outputs.forEach(function(l){return i[l.id]=!0}),F=!0,Y[G.id]=!0;break}if(F)break}}var u={};u[n.id]=!0;var a={};for(M=I.length-1;M>=0;M--)for(c=(G=I[M]).inputs,s=0;s<G.outputs.length;s++)if(u[G.outputs[s].id]){for(var D in c)u[c[D].id]=!0,a[G.id]=!0;break}var U=[];for(M=0;M<I.length;M++){var G;if(Y[(G=I[M]).id]&&a[G.id]){var d={};for(var D in G.inputs){var H=G.inputs[D];i[H.id]&&(d[D]=H)}var h=Object.assign({},G);h.inputs=d,h.outputs=G.outputs,U.push(h)}}return U}(this.state.activeTape,B,E);if(!w&&e.length===0&&B.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",function(){var I,o,n={};n[E.id]=Q??(I=E.shape,o=bM(hA(I),"float32"),b.makeTensor(o,I,"float32")),function(Y,M,c){for(var D=function(F){var s=M[F],u=[];if(s.outputs.forEach(function(d){var H=Y[d.id];H!=null?u.push(H):u.push(null)}),s.gradient==null)throw new Error("Cannot compute gradient: gradient function not found for "+s.kernelName+".");var a=s.gradient(u),U=function(d){if(!(d in a))throw new Error("Cannot backprop through input "+d+". Available gradients found: "+Object.keys(a)+".");var H=c(function(){return a[d]()});if(H.dtype!=="float32")throw new Error("Error in gradient for op "+s.kernelName+". The gradient of input "+d+" must have 'float32' dtype, but has '"+H.dtype+"'");var h=s.inputs[d];if(!KB(H.shape,h.shape))throw new Error("Error in gradient for op "+s.kernelName+". The gradient of input '"+d+"' has shape '"+H.shape+"', which does not match the shape of the input '"+h.shape+"'");if(Y[h.id]==null)Y[h.id]=H;else{var l=Y[h.id];Y[h.id]=l.add(H),l.dispose()}};for(var G in s.inputs)U(G)},r=M.length-1;r>=0;r--)D(r)}(n,e,function(Y){return C.tidy(Y)});var i=B.map(function(Y){return n[Y.id]});return C.state.gradientDepth===0&&(C.state.activeTape.forEach(function(Y){for(var M=0,c=Y.saved;M<c.length;M++)c[M].dispose()}),C.state.activeTape=null),{value:E,grads:i}})},A.prototype.customGrad=function(g){var B=this;return R(ko(g),function(){return"The f passed in customGrad(f) must be a function."}),function(){for(var Q,w=[],C=0;C<arguments.length;C++)w[C]=arguments[C];R(w.every(function(e){return e instanceof uB}),function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"});var E={};return w.forEach(function(e,I){E[I]=e}),B.runKernelFunc(function(e,I){return R((Q=g.apply(void 0,w.concat([I]))).value instanceof uB,function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"}),R(ko(Q.gradFunc),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."}),Q.value},E,function(e,I){var o=Q.gradFunc(e,I),n=Array.isArray(o)?o:[o];R(n.length===w.length,function(){return"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(...)."}),R(n.every(function(Y){return Y instanceof uB}),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."});var i={};return n.forEach(function(Y,M){i[M]=function(){return Y}}),i})}},A.prototype.readSync=function(g){return this.state.tensorInfo.get(g).backend.readSync(g)},A.prototype.read=function(g){return this.state.tensorInfo.get(g).backend.read(g)},A.prototype.time=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){switch(w.label){case 0:return B=Zg(),[4,this.backend.time(g)];case 1:return(Q=w.sent()).wallMs=Zg()-B,[2,Q]}})})},A.prototype.track=function(g){return this.state.activeScope!=null&&(g.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(g)),g},Object.defineProperty(A.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),A.prototype.reset=function(){for(var g in this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new _M,this.registry)this.disposeRegisteredKernels(g),this.registry[g].dispose(),delete this.registry[g];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},A.nextTensorId=0,A.nextVariableId=0,A}(),b=function(){var A=function(){if(Lo==null){var B=void 0;if(typeof window<"u")B=window;else if(typeof global<"u")B=global;else if(typeof process<"u")B=process;else{if(typeof self>"u")throw new Error("Could not find a global object");B=self}Lo=B}return Lo}();if(A._tfengine==null){var g=new fd(A);A._tfengine=new Xd(g)}return function(B){vM=B}(A._tfengine.ENV),qg=function(){return A._tfengine},A._tfengine}();function $M(){return typeof window<"u"&&window.document!=null||typeof WorkerGlobalScope<"u"}var cQ=BA();cQ.registerFlag("DEBUG",function(){return!1},function(A){A&&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.")}),cQ.registerFlag("IS_BROWSER",function(){return $M()}),cQ.registerFlag("IS_NODE",function(){return typeof process<"u"&&process.versions!==void 0&&process.versions.node!==void 0}),cQ.registerFlag("IS_CHROME",function(){return typeof navigator<"u"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),cQ.registerFlag("PROD",function(){return!1}),cQ.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return cQ.getBool("DEBUG")}),cQ.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),cQ.registerFlag("IS_TEST",function(){return!1});var PC,hg,lg,Bw={},bo={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function Od(A,g){Bw[A]=g}function _g(A){A in Bw||(Bw[A]=function(B){if(B!==1&&B!==2)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var Q=function(w){if(typeof OffscreenCanvas<"u"&&w===2)return new OffscreenCanvas(300,150);if(typeof document<"u")return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(B);return Q.addEventListener("webglcontextlost",function(w){w.preventDefault(),delete Bw[B]},!1),B===1?Q.getContext("webgl",bo)||Q.getContext("experimental-webgl",bo):Q.getContext("webgl2",bo)}(A));var g=Bw[A];return g.isContextLost()?(delete Bw[A],_g(A)):(g.disable(g.DEPTH_TEST),g.disable(g.STENCIL_TEST),g.disable(g.BLEND),g.disable(g.DITHER),g.disable(g.POLYGON_OFFSET_FILL),g.disable(g.SAMPLE_COVERAGE),g.enable(g.SCISSOR_TEST),g.enable(g.CULL_FACE),g.cullFace(g.BACK),Bw[A])}function OE(A,g){return[g,A]}function vC(A){var g=hA(A);return Po(Math.ceil(g/4))}function kC(A,g){return[Math.max(1,Math.ceil(g/2)),Math.max(1,Math.ceil(A/2))]}function Ko(A,g){var B,Q,w,C,E,e,I,o,n,i=A;return BA().getNumber("WEBGL_VERSION")===2?(B=i.R32F,Q=i.R16F,w=i.RGBA16F,C=i.RGBA32F,E=i.RED,e=4,I=1,o=i.HALF_FLOAT,n=i.FLOAT):(B=A.RGBA,Q=A.RGBA,w=A.RGBA,C=i.RGBA,E=A.RGBA,e=4,I=4,o=g!=null?g.HALF_FLOAT_OES:null,n=A.FLOAT),{internalFormatFloat:B,internalFormatHalfFloat:Q,internalFormatPackedHalfFloat:w,internalFormatPackedFloat:C,textureFormatFloat:E,downloadTextureFormat:A.RGBA,downloadUnpackNumChannels:e,defaultNumChannels:I,textureTypeHalfFloat:o,textureTypeFloat:n}}function lA(A,g,B){var Q=B();return g&&function(w){var C=w.getError();if(C!==w.NO_ERROR)throw new Error("WebGL Error: "+$d(w,C))}(A),Q}(function(A){A[A.DENSE=0]="DENSE",A[A.SHARED_BATCH=1]="SHARED_BATCH"})(PC||(PC={})),function(A){A[A.RENDER=0]="RENDER",A[A.UPLOAD=1]="UPLOAD",A[A.PIXELS=2]="PIXELS",A[A.DOWNLOAD=3]="DOWNLOAD"}(hg||(hg={})),function(A){A[A.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",A[A.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",A[A.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",A[A.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",A[A.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}(lg||(lg={}));var Zd=596e-10,qd=65504;function _d(A){return!!(BA().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||A===0||Zd<Math.abs(A)&&Math.abs(A)<qd)}function $d(A,g){switch(g){case A.NO_ERROR:return"NO_ERROR";case A.INVALID_ENUM:return"INVALID_ENUM";case A.INVALID_VALUE:return"INVALID_VALUE";case A.INVALID_OPERATION:return"INVALID_OPERATION";case A.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case A.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case A.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+g}}function ZE(A,g,B){return DQ(A,g,function(){return A.getExtension(B)},'Extension "'+B+'" not supported on this browser.')}function AH(A,g,B){var Q=DQ(A,g,function(){return A.createShader(A.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(lA(A,g,function(){return A.shaderSource(Q,B)}),lA(A,g,function(){return A.compileShader(Q)}),A.getShaderParameter(Q,A.COMPILE_STATUS)===!1)throw console.log(A.getShaderInfoLog(Q)),new Error("Failed to compile vertex shader.");return Q}function BH(A,g,B){var Q=DQ(A,g,function(){return A.createShader(A.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(lA(A,g,function(){return A.shaderSource(Q,B)}),lA(A,g,function(){return A.compileShader(Q)}),A.getShaderParameter(Q,A.COMPILE_STATUS)===!1)throw function(w,C){var E=gH.exec(C);if(E==null)return console.log("Couldn't parse line number in error: "+C),void console.log(w);for(var e=+E[1],I=w.split(`
27
27
  `),o=I.length.toString().length+2,n=I.map(function(r,F){return jw((F+1).toString(),o)+r}),i=0,Y=0;Y<n.length;Y++)i=Math.max(n[Y].length,i);var M=n.slice(0,e-1),c=n.slice(e-1,e),D=n.slice(e);console.log(M.join(`
28
28
  `)),console.log(C.split(`
29
29
  `)[0]),console.log("%c "+jw(c[0],i),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(D.join(`
30
- `))}(B,A.getShaderInfoLog(Q)),new Error("Failed to compile fragment shader.");return Q}var Ko,Vo,AH=/ERROR: [0-9]+:([0-9]+):/g;function BH(A,g){return DQ(A,g,function(){return A.createProgram()},"Unable to create WebGLProgram.")}function gH(A,g,B){if(lA(A,g,function(){return A.linkProgram(B)}),A.getProgramParameter(B,A.LINK_STATUS)===!1)throw console.log(A.getProgramInfoLog(B)),new Error("Failed to link vertex and fragment shaders.")}function xo(A,g,B){if(lA(A,g,function(){return A.validateProgram(B)}),A.getProgramParameter(B,A.VALIDATE_STATUS)===!1)throw console.log(A.getProgramInfoLog(B)),new Error("Shader program validation failed.")}function QH(A,g,B){var Q=DQ(A,g,function(){return A.createBuffer()},"Unable to create WebGLBuffer");return lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,Q)}),lA(A,g,function(){return A.bufferData(A.ARRAY_BUFFER,B,A.STATIC_DRAW)}),Q}function wH(A,g,B){var Q=DQ(A,g,function(){return A.createBuffer()},"Unable to create WebGLBuffer");return lA(A,g,function(){return A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,Q)}),lA(A,g,function(){return A.bufferData(A.ELEMENT_ARRAY_BUFFER,B,A.STATIC_DRAW)}),Q}function CH(A,g){return DQ(A,g,function(){return A.createTexture()},"Unable to create WebGLTexture.")}function EH(A,g){var B=BA().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(A<=0||g<=0){var Q="["+A+"x"+g+"]";throw new Error("Requested texture size "+Q+" is invalid.")}if(A>B||g>B)throw Q="["+A+"x"+g+"]",new Error("Requested texture size "+Q+" greater than WebGL maximum on this browser / GPU "+("["+B+"x"+B+"]")+".")}function eH(A,g){return DQ(A,g,function(){return A.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function Ac(A,g,B,Q,w,C,E,e){var I=A.getAttribLocation(B,Q);return I!==-1&&(lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,w)}),lA(A,g,function(){return A.vertexAttribPointer(I,C,A.FLOAT,!1,E,e)}),lA(A,g,function(){return A.enableVertexAttribArray(I)}),!0)}function IH(A,g,B,Q){YH(A,Q),lA(A,g,function(){return A.activeTexture(A.TEXTURE0+Q)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)})}function oH(A,g,B,Q){return DQ(A,g,function(){return A.getUniformLocation(B,Q)},'uniform "'+Q+'" not present in program.')}function tH(A,g,B){return A.getUniformLocation(g,B)}function nH(A,g,B,Q,w,C){lA(A,g,function(){return IH(A,g,Q,C)}),lA(A,g,function(){return A.uniform1i(w,C)})}function Xo(A,g,B,Q){lA(A,g,function(){return A.bindFramebuffer(A.FRAMEBUFFER,Q)}),lA(A,g,function(){return A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,B,0)})}function Bc(A,g,B){lA(A,g,function(){return A.bindFramebuffer(A.FRAMEBUFFER,B)}),lA(A,g,function(){return A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,null,0)})}function qE(A){var g=A.checkFramebufferStatus(A.FRAMEBUFFER);if(g!==A.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+iH(A,g))}function iH(A,g){switch(g){case A.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case A.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case A.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case A.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+g}}function DQ(A,g,B,Q){var w=lA(A,g,function(){return B()});if(w==null)throw new Error(Q);return w}function YH(A,g){var B=A.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,Q=g+A.TEXTURE0;if(Q<A.TEXTURE0||Q>B)throw new Error("textureUnit must be in "+("[gl.TEXTURE0, gl.TEXTURE"+B+"]")+".")}function _E(A,g){return g===void 0&&(g=2),hA(A.slice(0,A.length-g))}function $E(A){if(A.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[A.length>1?A[A.length-2]:1,A[A.length-1]]}function Oo(A){var g=[1,1,1];return A.length===0||A.length===1&&A[0]===1||(g=[_E(A)].concat($E(A))),g}function MH(A,g){var B;g===void 0&&(g=!1);var Q=BA().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(g&&(Q*=2,(A=A.map(function(o,n){return n>=A.length-2?yM(A[n]):A[n]})).length===1&&(A=[2,A[0]])),A.length!==2){var w=Aw(A);A=w.newShape}var C=hA(A);if(A.length<=1&&C<=Q)return[1,C];if(A.length===2&&A[0]<=Q&&A[1]<=Q)return A;if(A.length===3&&A[0]*A[1]<=Q&&A[2]<=Q)return[A[0]*A[1],A[2]];if(A.length===3&&A[0]<=Q&&A[1]*A[2]<=Q)return[A[0],A[1]*A[2]];if(A.length===4&&A[0]*A[1]*A[2]<=Q&&A[3]<=Q)return[A[0]*A[1]*A[2],A[3]];if(A.length===4&&A[0]<=Q&&A[1]*A[2]*A[3]<=Q)return[A[0],A[1]*A[2]*A[3]];if(g){var E=_E(A),e=2,I=2;return A.length&&(e=(B=$E(A))[0],I=B[1]),Ro(C=E*(e/2)*(I/2)).map(function(o){return 2*o})}return Ro(C)}function Ae(A){return A%2==0}function Be(A,g){if(KB(A=A.slice(-2),g=g.slice(-2))||!A.length||!g.length||A[0]===0||A[1]===0||g[0]===0||g[1]===0)return!0;if(A.length!==g.length){var B=A.slice(-1)[0],Q=g.slice(-1)[0];if(B===Q||Ae(B)&&Ae(Q)&&(A[0]===1||g[0]===1))return!0}return A[1]===g[1]&&Ae(A[0])&&Ae(g[0])}function cH(A){if(Ko==null){var g=_g(A);Ko=g.getParameter(g.MAX_TEXTURE_SIZE)}return Ko}function DH(A){if(Vo==null){var g=_g(A);Vo=g.getParameter(g.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,Vo)}function rH(A){if(A===0)return 0;var g=_g(A);return vg(g,"EXT_disjoint_timer_query_webgl2")&&A===2?2:vg(g,"EXT_disjoint_timer_query")?1:0}function vg(A,g){return A.getExtension(g)!=null}function gc(A){try{if(_g(A)!=null)return!0}catch{return!1}return!1}function FH(A){if(A===0)return!1;var g=_g(A);if(A===1){if(!vg(g,"OES_texture_float"))return!1}else if(!vg(g,"EXT_color_buffer_float"))return!1;return Zo(g)}function aH(A){if(A===0)return!1;var g=_g(A);if(A!==1){if(vg(g,"EXT_color_buffer_float"))return Zo(g);if(vg(g,"EXT_color_buffer_half_float")){var B=g.getExtension("EXT_color_buffer_half_float");return function(Q,w){var C=bo(Q,w),E=Q.createTexture();Q.bindTexture(Q.TEXTURE_2D,E),Q.texImage2D(Q.TEXTURE_2D,0,C.internalFormatHalfFloat,1,1,0,C.textureFormatFloat,C.textureTypeHalfFloat,null);var e=Q.createFramebuffer();Q.bindFramebuffer(Q.FRAMEBUFFER,e),Q.framebufferTexture2D(Q.FRAMEBUFFER,Q.COLOR_ATTACHMENT0,Q.TEXTURE_2D,E,0);var I=Q.checkFramebufferStatus(Q.FRAMEBUFFER)===Q.FRAMEBUFFER_COMPLETE;return Q.bindTexture(Q.TEXTURE_2D,null),Q.bindFramebuffer(Q.FRAMEBUFFER,null),Q.deleteTexture(E),Q.deleteFramebuffer(e),I}(g,B)}return!1}return!!vg(g,"OES_texture_float")&&!!vg(g,"WEBGL_color_buffer_float")&&Zo(g)}function Zo(A){var g=bo(A),B=A.createTexture();A.bindTexture(A.TEXTURE_2D,B),A.texImage2D(A.TEXTURE_2D,0,g.internalFormatFloat,1,1,0,g.textureFormatFloat,g.textureTypeFloat,null);var Q=A.createFramebuffer();A.bindFramebuffer(A.FRAMEBUFFER,Q),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,B,0);var w=A.checkFramebufferStatus(A.FRAMEBUFFER)===A.FRAMEBUFFER_COMPLETE;return A.bindTexture(A.TEXTURE_2D,null),A.bindFramebuffer(A.FRAMEBUFFER,null),A.deleteTexture(B),A.deleteFramebuffer(Q),w}function sH(A){return A===2&&_g(A).fenceSync!=null}var kA=BA();function Qc(A){BA().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(A+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function DA(A,g){return b.tidy(A,g)}function Mg(A){qM(A).forEach(function(g){return g.dispose()})}function uH(A){return b.keep(A)}function ge(){for(var A=[],g=0;g<arguments.length;g++)A[g]=arguments[g];BA().getBool("IS_TEST")||console.warn.apply(console,A)}function NQ(A,g){var B=A;if(Xg(A))return g==="string"?[]:[A.length];if(!Array.isArray(A))return[];for(var Q=[];Array.isArray(B)||Xg(B)&&g!=="string";)Q.push(B.length),B=B[0];return Array.isArray(A)&&BA().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function w(C,E,e){if(e=e||[],!Array.isArray(C)&&!Xg(C))return void R(E.length===0,function(){return"Element arr["+e.join("][")+"] is a primitive, but should be an array/TypedArray of "+E[0]+" elements"});R(E.length>0,function(){return"Element arr["+e.join("][")+"] should be a primitive, but is an array of "+C.length+" elements"}),R(C.length===E[0],function(){return"Element arr["+e.join("][")+"] should have "+E[0]+" elements, but has "+C.length+" elements"});for(var I=E.slice(1),o=0;o<C.length;++o)w(C[o],I,e.concat(o))}(A,Q,[]),Q}function wc(A,g,B,Q){if(A!=null&&(A!=="numeric"&&A!==g||A==="numeric"&&g==="string"))throw new Error("Argument '"+B+"' passed to '"+Q+"' must be "+A+" tensor, but got "+g+" tensor")}function J(A,g,B,Q){if(Q===void 0&&(Q="numeric"),A instanceof uB)return wc(Q,A.dtype,g,B),A;var w=HC(A);if(w!=="string"&&["bool","int32","float32"].indexOf(Q)>=0&&(w=Q),wc(Q,w,g,B),A==null||!Xg(A)&&!Array.isArray(A)&&typeof A!="number"&&typeof A!="boolean"&&typeof A!="string"){var C=A==null?"null":A.constructor.name;throw new Error("Argument '"+g+"' passed to '"+B+"' must be a Tensor or TensorLike, but got '"+C+"'")}var E=NQ(A,w);Xg(A)||Array.isArray(A)||(A=[A]);var e=w!=="string"?SM(A,w,BA().getBool("DEBUG")):Tw(A,[],!0);return b.makeTensor(e,E,w)}function Qe(A,g,B,Q){if(Q===void 0&&(Q="numeric"),!Array.isArray(A))throw new Error("Argument "+g+" passed to "+B+" must be a `Tensor[]` or `TensorLike[]`");return A.map(function(w,C){return J(w,g+"["+C+"]",B)},Q)}function Cc(A,g){for(var B=0;B<A.length;++B)if(A[A.length-B-1]!==g-1-B)return!1;return!0}function UH(A,g,B){for(var Q=A.length+g.length,w=[],C=0,E=0,e=0;e<Q;e++)B.indexOf(e)===-1?w.push(A[C++]):w.push(g[E++]);return w}function gg(A,g){for(var B=[],Q=A.length,w=0;w<Q;w++)g.indexOf(w)===-1&&B.push(A[w]);return[B,g.map(function(C){return A[C]})]}function cg(A,g){return UH(A,g.map(function(B){return 1}),g)}function dg(A,g,B){R(Cc(g,B),function(){return A+" supports only inner-most axes for now. Got axes "+g+" and rank-"+B+" input."})}function $g(A,g){if(Cc(A,g))return null;for(var B=[],Q=0;Q<g;++Q)A.indexOf(Q)===-1&&B.push(Q);return A.forEach(function(w){return B.push(w)}),B}function qo(A){return A.map(function(g,B){return[B,g]}).sort(function(g,B){return g[1]-B[1]}).map(function(g){return g[0]})}function AQ(A,g){for(var B=[],Q=g-A;Q<g;++Q)B.push(Q);return B}function GH(A,g){var B=A[0].length;A.forEach(function(w,C){R(w.length===B,function(){return"Error in concat"+B+"D: rank of tensors["+C+"] must be the same as the rank of the rest ("+B+")"})}),R(g>=0&&g<B,function(){return"Error in concat"+B+"D: axis must be between 0 and "+(B-1)+"."});var Q=A[0];A.forEach(function(w,C){for(var E=0;E<B;E++)R(E===g||w[E]===Q[E],function(){return"Error in concat"+B+"D: Shape of tensors["+C+"] ("+w+") does not match the shape of the rest ("+Q+") along the non-concatenated axis "+C+"."})})}function yw(A,g){for(var B=A[0].slice(),Q=1;Q<A.length;Q++)B[g]+=A[Q][g];return B}function z(A){var g=Object.keys(A);if(g.length!==1)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+g.length+" keys.");var B=g[0],Q=A[B];B.endsWith("_")&&(B=B.substring(0,B.length-1));var w=function(){for(var C=[],E=0;E<arguments.length;E++)C[E]=arguments[E];b.startScope(B);try{var e=Q.apply(void 0,C);return e instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),b.endScope(e),e}catch(I){throw b.endScope(null),I}};return Object.defineProperty(w,"name",{value:B,configurable:!0}),w}kA.registerFlag("HAS_WEBGL",function(){return kA.getNumber("WEBGL_VERSION")>0}),kA.registerFlag("WEBGL_VERSION",function(){return gc(2)?2:gc(1)?1:0}),kA.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return kA.get("WEBGL_VERSION")===2}),kA.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),kA.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),kA.registerFlag("WEBGL_PACK",function(){return kA.getBool("HAS_WEBGL")}),kA.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_CLIP",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),kA.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_REDUCE",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_LAZILY_UNPACK",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_CONV_IM2COL",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return cH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return DH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var A=kA.getNumber("WEBGL_VERSION");return A===0?0:rH(A)}),kA.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return kA.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(A=navigator.userAgent||navigator.vendor||window.opera,!(/(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(A)||/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(A.substr(0,4))));var A}),kA.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return FH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!kA.getBool("WEBGL_FORCE_F16_TEXTURES")&&kA.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),kA.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return aH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return sH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return kA.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),OM=Qc;var $B=z({complex_:function(A,g){var B=J(A,"real","complex"),Q=J(g,"imag","complex");return eB(B.shape,Q.shape,"real and imag shapes, "+B.shape+" and "+Q.shape+", must match in call to tf.complex()."),b.runKernelFunc(function(w){return w.complex(B,Q)},{$real:B,$imag:Q})}}),kg=z({real_:function(A){var g=J(A,"input","real");return b.runKernelFunc(function(B){return B.real(g)},{$input:g})}}),BQ=z({imag_:function(A){var g=J(A,"input","imag");return b.runKernelFunc(function(B){return B.imag(g)},{$input:g})}});function Ag(A,g,B){return mQ(A,g,NQ(A,B),B)}function mQ(A,g,B,Q){if(Q==null&&(Q=HC(A)),Q==="complex64")throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!Xg(A)&&!Array.isArray(A)&&typeof A!="number"&&typeof A!="boolean"&&typeof A!="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(g!=null){KM(g);var w=hA(g),C=hA(B);R(w===C,function(){return"Based on the provided shape, ["+g+"], the tensor should have "+w+" values but has "+C});for(var E=0;E<B.length;++E){var e=B[E],I=E!==B.length-1||e!==hA(g.slice(E));R(B[E]===g[E]||!I,function(){return"Error creating a new Tensor. Inferred shape ("+B+") does not match the provided shape ("+g+"). "})}}return Xg(A)||Array.isArray(A)||(A=[A]),g=g||B,A=Q!=="string"?SM(A,Q,BA().getBool("DEBUG")):Tw(A,[],!0),b.makeTensor(A,g,Q)}function nA(A,g){if((Xg(A)&&g!=="string"||Array.isArray(A))&&g!=="complex64")throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if(g==="string"&&Xg(A)&&!(A instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return mQ(A,[],[],g)}function PB(A,g){kw(A);var B=NQ(A,g);if(B.length!==1)throw new Error("tensor1d() requires values to be a flat/TypedArray");return mQ(A,null,B,g)}function RQ(A,g,B){if(kw(A),g!=null&&g.length!==2)throw new Error("tensor2d() requires shape to have two numbers");var Q=NQ(A,B);if(Q.length!==2&&Q.length!==1)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return mQ(A,g,Q,B)}function _o(A,g,B){if(kw(A),g!=null&&g.length!==3)throw new Error("tensor3d() requires shape to have three numbers");var Q=NQ(A,B);if(Q.length!==3&&Q.length!==1)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function Dg(A,g,B){if(kw(A),g!=null&&g.length!==4)throw new Error("tensor4d() requires shape to have four numbers");var Q=NQ(A,B);if(Q.length!==4&&Q.length!==1)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function hH(A,g,B){if(kw(A),g!=null&&g.length!==5)throw new Error("tensor5d() requires shape to have five numbers");var Q=NQ(A,B);if(Q.length!==5&&Q.length!==1)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function lH(A,g,B){if(kw(A),g!=null&&g.length!==6)throw new Error("tensor6d() requires shape to have six numbers");var Q=NQ(A,B);if(Q.length!==6&&Q.length!==1)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return mQ(A,g=g||Q,Q,B)}function dH(A,g,B,Q){return g===void 0&&(g=!0),b.makeVariable(A,g,B,Q)}function zw(A,g){if(g===void 0&&(g="float32"),g==="complex64"){var B=zw(A,"float32"),Q=DB(A,"float32");return $B(B,Q)}var w=bM(hA(A),g);return b.makeTensor(w,A,g)}function DB(A,g){if(g===void 0&&(g="float32"),g==="complex64"){var B=DB(A,"float32"),Q=DB(A,"float32");return $B(B,Q)}var w=fC(hA(A),g);return b.makeTensor(w,A,g)}function gQ(A,g,B){return b.runKernelFunc(function(Q){return Q.fill(A,g,B)},{})}function HH(A,g,B){if(B<=0)throw new Error("The number of values should be positive.");return b.runKernelFunc(function(Q){return Q.linspace(A,g,B)},{})}function we(A,g,B,Q){if(B===void 0&&(B=1),Q===void 0&&(Q="float32"),B===0)throw new Error("Cannot have a step of zero");if(A===g||A<g&&B<0||g<A&&B>1)return DB([0],Q);var w=fC(Math.abs(Math.ceil((g-A)/B)),Q);g<A&&B===1&&(B=-1),w[0]=A;for(var C=1;C<w.length;C++)w[C]=w[C-1]+B;return PB(w,Q)}var Ec=z({onesLike_:function(A){var g=J(A,"x","onesLike");if(g.dtype==="complex64"){var B=Ec(kg(g)),Q=$A(BQ(g));return $B(B,Q)}return b.runKernelFunc(function(w){return w.onesLike(g)},{$x:g},function(w,C){return{$x:function(){return $A(w)}}})}}),$A=z({zerosLike_:function(A){var g=J(A,"x","zerosLike");return b.runKernelFunc(function(B){return B.zerosLike(g)},{$x:g},function(B,Q){return{$x:function(){return $A(B)}}})}}),jB=z({concat_:function(A,g){g===void 0&&(g=0),R(A.length>=1,function(){return"Pass at least one tensor to concat"});var B=Qe(A,"tensors","concat");B[0].dtype==="complex64"&&B.forEach(function(e){if(e.dtype!=="complex64")throw new Error(`Cannot concatenate complex64 tensors with a tensor
31
- with dtype `+e.dtype+". ")}),g=TB(g,B[0].shape)[0];var Q=yw(B.map(function(e){return e.shape}),g);if(hA(Q)===0)return Ag([],Q);if((B=B.filter(function(e){return e.size>0})).length===1)return B[0];var w=B.map(function(e){return e.shape});GH(w,g);var C=B,E={axis:g};return b.runKernelFunc(function(e){return e.concat(B,g)},C,function(e){var I=w.map(function(o){return o[g]});return $o(e,I,g).map(function(o){return function(){return o}})},"Concat",E)}}),fH=z({concat1d_:function(A){return jB(A,0)}}),JH=z({concat2d_:function(A,g){return jB(A,g)}}),NH=z({concat3d_:function(A,g){return jB(A,g)}}),mH=z({concat4d_:function(A,g){return jB(A,g)}}),$o=z({split_:function(A,g,B){B===void 0&&(B=0);var Q,w=J(A,"x","split");return B=TB(B,w.shape)[0],typeof g=="number"?(R(w.shape[B]%g==0,function(){return"Number of splits must evenly divide the axis."}),Q=new Array(g).fill(w.shape[B]/g)):(R(w.shape[B]===g.reduce(function(C,E){return C+E}),function(){return"The sum of sizes must match the size of the axis dimension."}),Q=g),b.runKernelFunc(function(C){return C.split(w,Q,B)},{$x:w},function(C){return{$x:function(){return jB(C,B)}}})}});function gw(A,g){return A(g={exports:{}},g.exports),g.exports}var RH=gw(function(A){(function(g,B,Q){function w(e){var I,o=this,n=(I=4022871197,function(i){i=i.toString();for(var Y=0;Y<i.length;Y++){var M=.02519603282416938*(I+=i.charCodeAt(Y));M-=I=M>>>0,I=(M*=I)>>>0,I+=4294967296*(M-=I)}return 23283064365386963e-26*(I>>>0)});o.next=function(){var i=2091639*o.s0+23283064365386963e-26*o.c;return o.s0=o.s1,o.s1=o.s2,o.s2=i-(o.c=0|i)},o.c=1,o.s0=n(" "),o.s1=n(" "),o.s2=n(" "),o.s0-=n(e),o.s0<0&&(o.s0+=1),o.s1-=n(e),o.s1<0&&(o.s1+=1),o.s2-=n(e),o.s2<0&&(o.s2+=1),n=null}function C(e,I){return I.c=e.c,I.s0=e.s0,I.s1=e.s1,I.s2=e.s2,I}function E(e,I){var o=new w(e),n=I&&I.state,i=o.next;return i.int32=function(){return 4294967296*o.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.alea=E})(0,A)}),PH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.x=0,I.y=0,I.z=0,I.w=0,I.next=function(){var i=I.x^I.x<<11;return I.x=I.y,I.y=I.z,I.z=I.w,I.w^=I.w>>>19^i^i>>>8},e===(0|e)?I.x=e:o+=e;for(var n=0;n<o.length+64;n++)I.x^=0|o.charCodeAt(n),I.next()}function C(e,I){return I.x=e.x,I.y=e.y,I.z=e.z,I.w=e.w,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xor128=E})(0,A)}),vH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.next=function(){var i=I.x^I.x>>>2;return I.x=I.y,I.y=I.z,I.z=I.w,I.w=I.v,(I.d=I.d+362437|0)+(I.v=I.v^I.v<<4^i^i<<1)|0},I.x=0,I.y=0,I.z=0,I.w=0,I.v=0,e===(0|e)?I.x=e:o+=e;for(var n=0;n<o.length+64;n++)I.x^=0|o.charCodeAt(n),n==o.length&&(I.d=I.x<<10^I.x>>>4),I.next()}function C(e,I){return I.x=e.x,I.y=e.y,I.z=e.z,I.w=e.w,I.v=e.v,I.d=e.d,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xorwow=E})(0,A)}),kH=gw(function(A){(function(g,B,Q){function w(e){var I=this;I.next=function(){var o,n,i=I.x,Y=I.i;return o=i[Y],n=(o^=o>>>7)^o<<24,n^=(o=i[Y+1&7])^o>>>10,n^=(o=i[Y+3&7])^o>>>3,n^=(o=i[Y+4&7])^o<<7,o=i[Y+7&7],n^=(o^=o<<13)^o<<9,i[Y]=n,I.i=Y+1&7,n},function(o,n){var i,Y=[];if(n===(0|n))Y[0]=n;else for(n=""+n,i=0;i<n.length;++i)Y[7&i]=Y[7&i]<<15^n.charCodeAt(i)+Y[i+1&7]<<13;for(;Y.length<8;)Y.push(0);for(i=0;i<8&&Y[i]===0;++i);for(i==8?Y[7]=-1:Y[i],o.x=Y,o.i=0,i=256;i>0;--i)o.next()}(I,e)}function C(e,I){return I.x=e.x.slice(),I.i=e.i,I}function E(e,I){e==null&&(e=+new Date);var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(n.x&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xorshift7=E})(0,A)}),TH=gw(function(A){(function(g,B,Q){function w(e){var I=this;I.next=function(){var o,n,i=I.w,Y=I.X,M=I.i;return I.w=i=i+1640531527|0,n=Y[M+34&127],o=Y[M=M+1&127],n^=n<<13,o^=o<<17,n^=n>>>15,o^=o>>>12,n=Y[M]=n^o,I.i=M,n+(i^i>>>16)|0},function(o,n){var i,Y,M,c,D,r=[],F=128;for(n===(0|n)?(Y=n,n=null):(n+="\0",Y=0,F=Math.max(F,n.length)),M=0,c=-32;c<F;++c)n&&(Y^=n.charCodeAt((c+32)%n.length)),c===0&&(D=Y),Y^=Y<<10,Y^=Y>>>15,Y^=Y<<4,Y^=Y>>>13,c>=0&&(D=D+1640531527|0,M=(i=r[127&c]^=Y+D)==0?M+1:0);for(M>=128&&(r[127&(n&&n.length||0)]=-1),M=127,c=512;c>0;--c)Y=r[M+34&127],i=r[M=M+1&127],Y^=Y<<13,i^=i<<17,Y^=Y>>>15,i^=i>>>12,r[M]=Y^i;o.w=D,o.X=r,o.i=M}(I,e)}function C(e,I){return I.i=e.i,I.w=e.w,I.X=e.X.slice(),I}function E(e,I){e==null&&(e=+new Date);var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(n.X&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xor4096=E})(0,A)}),jH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.next=function(){var i=I.b,Y=I.c,M=I.d,c=I.a;return i=i<<25^i>>>7^Y,Y=Y-M|0,M=M<<24^M>>>8^c,c=c-i|0,I.b=i=i<<20^i>>>12^Y,I.c=Y=Y-M|0,I.d=M<<16^Y>>>16^c,I.a=c-i|0},I.a=0,I.b=0,I.c=-1640531527,I.d=1367130551,e===Math.floor(e)?(I.a=e/4294967296|0,I.b=0|e):o+=e;for(var n=0;n<o.length+20;n++)I.b^=0|o.charCodeAt(n),I.next()}function C(e,I){return I.a=e.a,I.b=e.b,I.c=e.c,I.d=e.d,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.tychei=E})(0,A)}),Qw=gw(function(A){(function(g,B){var Q,w=this,C=256,E=6,e="random",I=B.pow(C,E),o=B.pow(2,52),n=2*o,i=C-1;function Y(F,s,u){var a=[],U=D(function H(h,l){var m,f=[],W=typeof h;if(l&&W=="object")for(m in h)try{f.push(H(h[m],l-1))}catch{}return f.length?f:W=="string"?h:h+"\0"}((s=s==1?{entropy:!0}:s||{}).entropy?[F,r(g)]:F??function(){try{var H;return Q&&(H=Q.randomBytes)?H=H(C):(H=new Uint8Array(C),(w.crypto||w.msCrypto).getRandomValues(H)),r(H)}catch{var h=w.navigator,l=h&&h.plugins;return[+new Date,w,l,w.screen,r(g)]}}(),3),a),G=new M(a),d=function(){for(var H=G.g(E),h=I,l=0;H<o;)H=(H+l)*C,h*=C,l=G.g(1);for(;H>=n;)H/=2,h/=2,l>>>=1;return(H+l)/h};return d.int32=function(){return 0|G.g(4)},d.quick=function(){return G.g(4)/4294967296},d.double=d,D(r(G.S),g),(s.pass||u||function(H,h,l,m){return m&&(m.S&&c(m,G),H.state=function(){return c(G,{})}),l?(B[e]=H,h):H})(d,U,"global"in s?s.global:this==B,s.state)}function M(F){var s,u=F.length,a=this,U=0,G=a.i=a.j=0,d=a.S=[];for(u||(F=[u++]);U<C;)d[U]=U++;for(U=0;U<C;U++)d[U]=d[G=i&G+F[U%u]+(s=d[U])],d[G]=s;(a.g=function(H){for(var h,l=0,m=a.i,f=a.j,W=a.S;H--;)h=W[m=i&m+1],l=l*C+W[i&(W[m]=W[f=i&f+h])+(W[f]=h)];return a.i=m,a.j=f,l})(C)}function c(F,s){return s.i=F.i,s.j=F.j,s.S=F.S.slice(),s}function D(F,s){for(var u,a=F+"",U=0;U<a.length;)s[i&U]=i&(u^=19*s[i&U])+a.charCodeAt(U++);return r(s)}function r(F){return String.fromCharCode.apply(0,F)}if(B["seed"+e]=Y,D(B.random(),g),A.exports){A.exports=Y;try{Q=require("crypto")}catch{}}})([],Math)});Qw.alea=RH,Qw.xor128=PH,Qw.xorwow=vH,Qw.xorshift7=kH,Qw.xor4096=TH,Qw.tychei=jH;var Ce=Qw.alea,At=function(){function A(g,B,Q,w,C){this.mean=g,this.stdDev=B,this.dtype=Q,this.nextVal=NaN,this.truncated=w,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var E=C||Math.random();this.random=Ce(E.toString())}return A.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var g=this.nextVal;return this.nextVal=NaN,g}for(var B,Q,w=!1;!w;){var C=void 0,E=void 0,e=void 0;do e=(C=2*this.random()-1)*C+(E=2*this.random()-1)*E;while(e>=1||e===0);var I=Math.sqrt(-2*Math.log(e)/e);B=this.mean+this.stdDev*C*I,Q=this.mean+this.stdDev*E*I,this.truncated&&!this.isValidTruncated(B)||(w=!0)}return this.truncated&&!this.isValidTruncated(Q)||(this.nextVal=this.convertValue(Q)),this.convertValue(B)},A.prototype.convertValue=function(g){return this.dtype==null||this.dtype==="float32"?g:Math.round(g)},A.prototype.isValidTruncated=function(g){return g<=this.upper&&g>=this.lower},A}(),pH=function(){function A(g,B,Q,w){this.alpha=g,this.beta=1/B,this.dtype=Q;var C=w||Math.random();this.randu=Ce(C.toString()),this.randn=new At(0,1,Q,!1,this.randu()),this.d=g<1?g+2/3:g-1/3,this.c=1/Math.sqrt(9*this.d)}return A.prototype.nextValue=function(){for(var g,B,Q,w,C,E;;){do w=this.randn.nextValue(),E=1+this.c*w;while(E<=0);if(E*=E*E,B=1-.331*(g=w*w)*g,Q=.5*g+this.d*(1-E+Math.log(E)),(C=this.randu())<B||Math.log(C)<Q)break}return E=1/this.beta*this.d*E,this.alpha<1&&(E*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(E)},A.prototype.convertValue=function(g){return this.dtype==="float32"?g:Math.round(g)},A}(),yH=function(){function A(g,B,Q,w){var C=this;if(g===void 0&&(g=0),B===void 0&&(B=1),this.canReturnFloat=function(){return C.dtype==null||C.dtype==="float32"},this.min=g,this.range=B-g,this.dtype=Q,w==null&&(w=Math.random()),typeof w=="number"&&(w=w.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+g+" - "+B+" <= 1 and dtype is not float");this.random=Ce(w)}return A.prototype.convertValue=function(g){return this.canReturnFloat()?g:Math.round(g)},A.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},A}();function zA(A,g,B){return g===void 0&&(g="float32"),g=g||"float32",KM(A),new RC(A,g,B)}function zH(A,g){g===void 0&&(g=!1),console.log(A.toString(g))}var ec=z({batchToSpaceND_:function(A,g,B){var Q=J(A,"x","batchToSpaceND"),w=g.reduce(function(C,E){return C*E});return R(Q.rank>=1+g.length,function(){return"input rank is "+Q.rank+" but should be > than blockShape.length "+g.length}),R(B.length===g.length,function(){return"crops.length is "+B.length+" but should be equal to blockShape.length "+g.length}),R(Q.shape[0]%w==0,function(){return"input tensor batch is "+Q.shape[0]+" but is not divisible by the product of the elements of blockShape "+g.join(" * ")+" === "+w}),b.runKernelFunc(function(C){return C.batchToSpaceND(Q,g,B)},{$x:Q},function(C){return{$x:function(){return C.spaceToBatchND(g,B)}}})}}),WH=z({broadcastTo_:function(A,g){var B=J(A,"broadcastTo","x"),Q=B.shape;if(g.some(function(I){return!(I>0)||I%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+g+"].");if(g.length<B.rank)throw new Error("broadcastTo(): shape.length="+g.length+" < input.rank="+B.rank+".");if(g.length>B.rank){for(var w=B.shape.slice();w.length<g.length;)w.unshift(1);B=B.reshape(w)}for(var C=Array.from(g),E=g.length-1;E>=0;E--)if(B.shape[E]===g[E])C[E]=1;else if(B.shape[E]!==1)throw new Error("broadcastTo(): ["+Q+"] cannot be broadcast to ["+g+"].");var e=C.map(function(I,o){return I>1?o:-1}).filter(function(I){return I>=0});return e.length===0?B.clone():b.runKernelFunc(function(I){return I.tile(B,C)},{input:B},function(I){return{input:function(){return I.sum(e,!0)}}})}}),SH=z({cast_:function(A,g){var B=J(A,"x","cast");if(!vd(g))throw new Error("Failed to cast to unknown dtype "+g);if(g==="string"&&B.dtype!=="string"||g!=="string"&&B.dtype==="string")throw new Error("Only strings can be casted to strings");var Q={dtype:g};return b.runKernelFunc(function(w){return w.cast(B,g)},{x:B},function(w){return{x:function(){return w.clone()}}},"Cast",Q)}}),LH=z({clone_:function(A){var g=J(A,"x","clone",null);return b.runKernelFunc(function(){return b.makeTensorFromDataId(g.dataId,g.shape,g.dtype)},{$x:g},function(B){return{$x:function(){return B.toFloat()}}})}}),bH=z({cumsum_:function(A,g,B,Q){g===void 0&&(g=0),B===void 0&&(B=!1),Q===void 0&&(Q=!1);var w=J(A,"x","cumsum"),C=$g([g|=0],w.rank),E=w;C!=null&&(E=w.transpose(C));var e=AQ(1,w.rank)[0],I=b.runKernelFunc(function(o){return o.cumsum(E,e,B,Q)},{permutedX:E},function(o){return{permutedX:function(){return o.cumsum(g,B,!Q)}}});return C!=null&&(I=I.transpose(C)),I}}),KH=z({depthToSpace_:function(A,g,B){B===void 0&&(B="NHWC");var Q=J(A,"x","depthToSpace"),w=B==="NHWC"?Q.shape[1]:Q.shape[2],C=B==="NHWC"?Q.shape[2]:Q.shape[3],E=B==="NHWC"?Q.shape[3]:Q.shape[1];return R(w*g>=0,function(){return`Negative dimension size caused by overflow when multiplying
30
+ `))}(B,A.getShaderInfoLog(Q)),new Error("Failed to compile fragment shader.");return Q}var Vo,xo,gH=/ERROR: [0-9]+:([0-9]+):/g;function QH(A,g){return DQ(A,g,function(){return A.createProgram()},"Unable to create WebGLProgram.")}function wH(A,g,B){if(lA(A,g,function(){return A.linkProgram(B)}),A.getProgramParameter(B,A.LINK_STATUS)===!1)throw console.log(A.getProgramInfoLog(B)),new Error("Failed to link vertex and fragment shaders.")}function Xo(A,g,B){if(lA(A,g,function(){return A.validateProgram(B)}),A.getProgramParameter(B,A.VALIDATE_STATUS)===!1)throw console.log(A.getProgramInfoLog(B)),new Error("Shader program validation failed.")}function CH(A,g,B){var Q=DQ(A,g,function(){return A.createBuffer()},"Unable to create WebGLBuffer");return lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,Q)}),lA(A,g,function(){return A.bufferData(A.ARRAY_BUFFER,B,A.STATIC_DRAW)}),Q}function EH(A,g,B){var Q=DQ(A,g,function(){return A.createBuffer()},"Unable to create WebGLBuffer");return lA(A,g,function(){return A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,Q)}),lA(A,g,function(){return A.bufferData(A.ELEMENT_ARRAY_BUFFER,B,A.STATIC_DRAW)}),Q}function eH(A,g){return DQ(A,g,function(){return A.createTexture()},"Unable to create WebGLTexture.")}function IH(A,g){var B=BA().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(A<=0||g<=0){var Q="["+A+"x"+g+"]";throw new Error("Requested texture size "+Q+" is invalid.")}if(A>B||g>B)throw Q="["+A+"x"+g+"]",new Error("Requested texture size "+Q+" greater than WebGL maximum on this browser / GPU "+("["+B+"x"+B+"]")+".")}function oH(A,g){return DQ(A,g,function(){return A.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function Ac(A,g,B,Q,w,C,E,e){var I=A.getAttribLocation(B,Q);return I!==-1&&(lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,w)}),lA(A,g,function(){return A.vertexAttribPointer(I,C,A.FLOAT,!1,E,e)}),lA(A,g,function(){return A.enableVertexAttribArray(I)}),!0)}function tH(A,g,B,Q){cH(A,Q),lA(A,g,function(){return A.activeTexture(A.TEXTURE0+Q)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)})}function nH(A,g,B,Q){return DQ(A,g,function(){return A.getUniformLocation(B,Q)},'uniform "'+Q+'" not present in program.')}function iH(A,g,B){return A.getUniformLocation(g,B)}function YH(A,g,B,Q,w,C){lA(A,g,function(){return tH(A,g,Q,C)}),lA(A,g,function(){return A.uniform1i(w,C)})}function Oo(A,g,B,Q){lA(A,g,function(){return A.bindFramebuffer(A.FRAMEBUFFER,Q)}),lA(A,g,function(){return A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,B,0)})}function Bc(A,g,B){lA(A,g,function(){return A.bindFramebuffer(A.FRAMEBUFFER,B)}),lA(A,g,function(){return A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,null,0)})}function qE(A){var g=A.checkFramebufferStatus(A.FRAMEBUFFER);if(g!==A.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+MH(A,g))}function MH(A,g){switch(g){case A.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case A.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case A.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case A.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+g}}function DQ(A,g,B,Q){var w=lA(A,g,function(){return B()});if(w==null)throw new Error(Q);return w}function cH(A,g){var B=A.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,Q=g+A.TEXTURE0;if(Q<A.TEXTURE0||Q>B)throw new Error("textureUnit must be in "+("[gl.TEXTURE0, gl.TEXTURE"+B+"]")+".")}function _E(A,g){return g===void 0&&(g=2),hA(A.slice(0,A.length-g))}function $E(A){if(A.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[A.length>1?A[A.length-2]:1,A[A.length-1]]}function Zo(A){var g=[1,1,1];return A.length===0||A.length===1&&A[0]===1||(g=[_E(A)].concat($E(A))),g}function DH(A,g){var B;g===void 0&&(g=!1);var Q=BA().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(g&&(Q*=2,(A=A.map(function(o,n){return n>=A.length-2?yM(A[n]):A[n]})).length===1&&(A=[2,A[0]])),A.length!==2){var w=Aw(A);A=w.newShape}var C=hA(A);if(A.length<=1&&C<=Q)return[1,C];if(A.length===2&&A[0]<=Q&&A[1]<=Q)return A;if(A.length===3&&A[0]*A[1]<=Q&&A[2]<=Q)return[A[0]*A[1],A[2]];if(A.length===3&&A[0]<=Q&&A[1]*A[2]<=Q)return[A[0],A[1]*A[2]];if(A.length===4&&A[0]*A[1]*A[2]<=Q&&A[3]<=Q)return[A[0]*A[1]*A[2],A[3]];if(A.length===4&&A[0]<=Q&&A[1]*A[2]*A[3]<=Q)return[A[0],A[1]*A[2]*A[3]];if(g){var E=_E(A),e=2,I=2;return A.length&&(e=(B=$E(A))[0],I=B[1]),Po(C=E*(e/2)*(I/2)).map(function(o){return 2*o})}return Po(C)}function Ae(A){return A%2==0}function Be(A,g){if(KB(A=A.slice(-2),g=g.slice(-2))||!A.length||!g.length||A[0]===0||A[1]===0||g[0]===0||g[1]===0)return!0;if(A.length!==g.length){var B=A.slice(-1)[0],Q=g.slice(-1)[0];if(B===Q||Ae(B)&&Ae(Q)&&(A[0]===1||g[0]===1))return!0}return A[1]===g[1]&&Ae(A[0])&&Ae(g[0])}function rH(A){if(Vo==null){var g=_g(A);Vo=g.getParameter(g.MAX_TEXTURE_SIZE)}return Vo}function FH(A){if(xo==null){var g=_g(A);xo=g.getParameter(g.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,xo)}function aH(A){if(A===0)return 0;var g=_g(A);return vg(g,"EXT_disjoint_timer_query_webgl2")&&A===2?2:vg(g,"EXT_disjoint_timer_query")?1:0}function vg(A,g){return A.getExtension(g)!=null}function gc(A){try{if(_g(A)!=null)return!0}catch{return!1}return!1}function sH(A){if(A===0)return!1;var g=_g(A);if(A===1){if(!vg(g,"OES_texture_float"))return!1}else if(!vg(g,"EXT_color_buffer_float"))return!1;return qo(g)}function uH(A){if(A===0)return!1;var g=_g(A);if(A!==1){if(vg(g,"EXT_color_buffer_float"))return qo(g);if(vg(g,"EXT_color_buffer_half_float")){var B=g.getExtension("EXT_color_buffer_half_float");return function(Q,w){var C=Ko(Q,w),E=Q.createTexture();Q.bindTexture(Q.TEXTURE_2D,E),Q.texImage2D(Q.TEXTURE_2D,0,C.internalFormatHalfFloat,1,1,0,C.textureFormatFloat,C.textureTypeHalfFloat,null);var e=Q.createFramebuffer();Q.bindFramebuffer(Q.FRAMEBUFFER,e),Q.framebufferTexture2D(Q.FRAMEBUFFER,Q.COLOR_ATTACHMENT0,Q.TEXTURE_2D,E,0);var I=Q.checkFramebufferStatus(Q.FRAMEBUFFER)===Q.FRAMEBUFFER_COMPLETE;return Q.bindTexture(Q.TEXTURE_2D,null),Q.bindFramebuffer(Q.FRAMEBUFFER,null),Q.deleteTexture(E),Q.deleteFramebuffer(e),I}(g,B)}return!1}return!!vg(g,"OES_texture_float")&&!!vg(g,"WEBGL_color_buffer_float")&&qo(g)}function qo(A){var g=Ko(A),B=A.createTexture();A.bindTexture(A.TEXTURE_2D,B),A.texImage2D(A.TEXTURE_2D,0,g.internalFormatFloat,1,1,0,g.textureFormatFloat,g.textureTypeFloat,null);var Q=A.createFramebuffer();A.bindFramebuffer(A.FRAMEBUFFER,Q),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,B,0);var w=A.checkFramebufferStatus(A.FRAMEBUFFER)===A.FRAMEBUFFER_COMPLETE;return A.bindTexture(A.TEXTURE_2D,null),A.bindFramebuffer(A.FRAMEBUFFER,null),A.deleteTexture(B),A.deleteFramebuffer(Q),w}function UH(A){return A===2&&_g(A).fenceSync!=null}var kA=BA();function Qc(A){BA().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(A+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function DA(A,g){return b.tidy(A,g)}function Mg(A){qM(A).forEach(function(g){return g.dispose()})}function GH(A){return b.keep(A)}function ge(){for(var A=[],g=0;g<arguments.length;g++)A[g]=arguments[g];BA().getBool("IS_TEST")||console.warn.apply(console,A)}function NQ(A,g){var B=A;if(Xg(A))return g==="string"?[]:[A.length];if(!Array.isArray(A))return[];for(var Q=[];Array.isArray(B)||Xg(B)&&g!=="string";)Q.push(B.length),B=B[0];return Array.isArray(A)&&BA().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function w(C,E,e){if(e=e||[],!Array.isArray(C)&&!Xg(C))return void R(E.length===0,function(){return"Element arr["+e.join("][")+"] is a primitive, but should be an array/TypedArray of "+E[0]+" elements"});R(E.length>0,function(){return"Element arr["+e.join("][")+"] should be a primitive, but is an array of "+C.length+" elements"}),R(C.length===E[0],function(){return"Element arr["+e.join("][")+"] should have "+E[0]+" elements, but has "+C.length+" elements"});for(var I=E.slice(1),o=0;o<C.length;++o)w(C[o],I,e.concat(o))}(A,Q,[]),Q}function wc(A,g,B,Q){if(A!=null&&(A!=="numeric"&&A!==g||A==="numeric"&&g==="string"))throw new Error("Argument '"+B+"' passed to '"+Q+"' must be "+A+" tensor, but got "+g+" tensor")}function J(A,g,B,Q){if(Q===void 0&&(Q="numeric"),A instanceof uB)return wc(Q,A.dtype,g,B),A;var w=HC(A);if(w!=="string"&&["bool","int32","float32"].indexOf(Q)>=0&&(w=Q),wc(Q,w,g,B),A==null||!Xg(A)&&!Array.isArray(A)&&typeof A!="number"&&typeof A!="boolean"&&typeof A!="string"){var C=A==null?"null":A.constructor.name;throw new Error("Argument '"+g+"' passed to '"+B+"' must be a Tensor or TensorLike, but got '"+C+"'")}var E=NQ(A,w);Xg(A)||Array.isArray(A)||(A=[A]);var e=w!=="string"?SM(A,w,BA().getBool("DEBUG")):Tw(A,[],!0);return b.makeTensor(e,E,w)}function Qe(A,g,B,Q){if(Q===void 0&&(Q="numeric"),!Array.isArray(A))throw new Error("Argument "+g+" passed to "+B+" must be a `Tensor[]` or `TensorLike[]`");return A.map(function(w,C){return J(w,g+"["+C+"]",B)},Q)}function Cc(A,g){for(var B=0;B<A.length;++B)if(A[A.length-B-1]!==g-1-B)return!1;return!0}function hH(A,g,B){for(var Q=A.length+g.length,w=[],C=0,E=0,e=0;e<Q;e++)B.indexOf(e)===-1?w.push(A[C++]):w.push(g[E++]);return w}function gg(A,g){for(var B=[],Q=A.length,w=0;w<Q;w++)g.indexOf(w)===-1&&B.push(A[w]);return[B,g.map(function(C){return A[C]})]}function cg(A,g){return hH(A,g.map(function(B){return 1}),g)}function dg(A,g,B){R(Cc(g,B),function(){return A+" supports only inner-most axes for now. Got axes "+g+" and rank-"+B+" input."})}function $g(A,g){if(Cc(A,g))return null;for(var B=[],Q=0;Q<g;++Q)A.indexOf(Q)===-1&&B.push(Q);return A.forEach(function(w){return B.push(w)}),B}function _o(A){return A.map(function(g,B){return[B,g]}).sort(function(g,B){return g[1]-B[1]}).map(function(g){return g[0]})}function AQ(A,g){for(var B=[],Q=g-A;Q<g;++Q)B.push(Q);return B}function lH(A,g){var B=A[0].length;A.forEach(function(w,C){R(w.length===B,function(){return"Error in concat"+B+"D: rank of tensors["+C+"] must be the same as the rank of the rest ("+B+")"})}),R(g>=0&&g<B,function(){return"Error in concat"+B+"D: axis must be between 0 and "+(B-1)+"."});var Q=A[0];A.forEach(function(w,C){for(var E=0;E<B;E++)R(E===g||w[E]===Q[E],function(){return"Error in concat"+B+"D: Shape of tensors["+C+"] ("+w+") does not match the shape of the rest ("+Q+") along the non-concatenated axis "+C+"."})})}function yw(A,g){for(var B=A[0].slice(),Q=1;Q<A.length;Q++)B[g]+=A[Q][g];return B}function z(A){var g=Object.keys(A);if(g.length!==1)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+g.length+" keys.");var B=g[0],Q=A[B];B.endsWith("_")&&(B=B.substring(0,B.length-1));var w=function(){for(var C=[],E=0;E<arguments.length;E++)C[E]=arguments[E];b.startScope(B);try{var e=Q.apply(void 0,C);return e instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),b.endScope(e),e}catch(I){throw b.endScope(null),I}};return Object.defineProperty(w,"name",{value:B,configurable:!0}),w}kA.registerFlag("HAS_WEBGL",function(){return kA.getNumber("WEBGL_VERSION")>0}),kA.registerFlag("WEBGL_VERSION",function(){return gc(2)?2:gc(1)?1:0}),kA.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return kA.get("WEBGL_VERSION")===2}),kA.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),kA.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),kA.registerFlag("WEBGL_PACK",function(){return kA.getBool("HAS_WEBGL")}),kA.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_CLIP",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),kA.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_PACK_REDUCE",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_LAZILY_UNPACK",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_CONV_IM2COL",function(){return kA.getBool("WEBGL_PACK")}),kA.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return rH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return FH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var A=kA.getNumber("WEBGL_VERSION");return A===0?0:aH(A)}),kA.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return kA.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(A=navigator.userAgent||navigator.vendor||window.opera,!(/(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(A)||/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(A.substr(0,4))));var A}),kA.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return sH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!kA.getBool("WEBGL_FORCE_F16_TEXTURES")&&kA.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),kA.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return uH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return UH(kA.getNumber("WEBGL_VERSION"))}),kA.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return kA.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),OM=Qc;var $B=z({complex_:function(A,g){var B=J(A,"real","complex"),Q=J(g,"imag","complex");return eB(B.shape,Q.shape,"real and imag shapes, "+B.shape+" and "+Q.shape+", must match in call to tf.complex()."),b.runKernelFunc(function(w){return w.complex(B,Q)},{$real:B,$imag:Q})}}),kg=z({real_:function(A){var g=J(A,"input","real");return b.runKernelFunc(function(B){return B.real(g)},{$input:g})}}),BQ=z({imag_:function(A){var g=J(A,"input","imag");return b.runKernelFunc(function(B){return B.imag(g)},{$input:g})}});function Ag(A,g,B){return mQ(A,g,NQ(A,B),B)}function mQ(A,g,B,Q){if(Q==null&&(Q=HC(A)),Q==="complex64")throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!Xg(A)&&!Array.isArray(A)&&typeof A!="number"&&typeof A!="boolean"&&typeof A!="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(g!=null){KM(g);var w=hA(g),C=hA(B);R(w===C,function(){return"Based on the provided shape, ["+g+"], the tensor should have "+w+" values but has "+C});for(var E=0;E<B.length;++E){var e=B[E],I=E!==B.length-1||e!==hA(g.slice(E));R(B[E]===g[E]||!I,function(){return"Error creating a new Tensor. Inferred shape ("+B+") does not match the provided shape ("+g+"). "})}}return Xg(A)||Array.isArray(A)||(A=[A]),g=g||B,A=Q!=="string"?SM(A,Q,BA().getBool("DEBUG")):Tw(A,[],!0),b.makeTensor(A,g,Q)}function nA(A,g){if((Xg(A)&&g!=="string"||Array.isArray(A))&&g!=="complex64")throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if(g==="string"&&Xg(A)&&!(A instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return mQ(A,[],[],g)}function PB(A,g){kw(A);var B=NQ(A,g);if(B.length!==1)throw new Error("tensor1d() requires values to be a flat/TypedArray");return mQ(A,null,B,g)}function RQ(A,g,B){if(kw(A),g!=null&&g.length!==2)throw new Error("tensor2d() requires shape to have two numbers");var Q=NQ(A,B);if(Q.length!==2&&Q.length!==1)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return mQ(A,g,Q,B)}function $o(A,g,B){if(kw(A),g!=null&&g.length!==3)throw new Error("tensor3d() requires shape to have three numbers");var Q=NQ(A,B);if(Q.length!==3&&Q.length!==1)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function Dg(A,g,B){if(kw(A),g!=null&&g.length!==4)throw new Error("tensor4d() requires shape to have four numbers");var Q=NQ(A,B);if(Q.length!==4&&Q.length!==1)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function dH(A,g,B){if(kw(A),g!=null&&g.length!==5)throw new Error("tensor5d() requires shape to have five numbers");var Q=NQ(A,B);if(Q.length!==5&&Q.length!==1)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return mQ(A,g,Q,B)}function HH(A,g,B){if(kw(A),g!=null&&g.length!==6)throw new Error("tensor6d() requires shape to have six numbers");var Q=NQ(A,B);if(Q.length!==6&&Q.length!==1)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(Q.length===1&&g==null)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return mQ(A,g=g||Q,Q,B)}function fH(A,g,B,Q){return g===void 0&&(g=!0),b.makeVariable(A,g,B,Q)}function zw(A,g){if(g===void 0&&(g="float32"),g==="complex64"){var B=zw(A,"float32"),Q=DB(A,"float32");return $B(B,Q)}var w=bM(hA(A),g);return b.makeTensor(w,A,g)}function DB(A,g){if(g===void 0&&(g="float32"),g==="complex64"){var B=DB(A,"float32"),Q=DB(A,"float32");return $B(B,Q)}var w=fC(hA(A),g);return b.makeTensor(w,A,g)}function gQ(A,g,B){return b.runKernelFunc(function(Q){return Q.fill(A,g,B)},{})}function JH(A,g,B){if(B<=0)throw new Error("The number of values should be positive.");return b.runKernelFunc(function(Q){return Q.linspace(A,g,B)},{})}function we(A,g,B,Q){if(B===void 0&&(B=1),Q===void 0&&(Q="float32"),B===0)throw new Error("Cannot have a step of zero");if(A===g||A<g&&B<0||g<A&&B>1)return DB([0],Q);var w=fC(Math.abs(Math.ceil((g-A)/B)),Q);g<A&&B===1&&(B=-1),w[0]=A;for(var C=1;C<w.length;C++)w[C]=w[C-1]+B;return PB(w,Q)}var Ec=z({onesLike_:function(A){var g=J(A,"x","onesLike");if(g.dtype==="complex64"){var B=Ec(kg(g)),Q=$A(BQ(g));return $B(B,Q)}return b.runKernelFunc(function(w){return w.onesLike(g)},{$x:g},function(w,C){return{$x:function(){return $A(w)}}})}}),$A=z({zerosLike_:function(A){var g=J(A,"x","zerosLike");return b.runKernelFunc(function(B){return B.zerosLike(g)},{$x:g},function(B,Q){return{$x:function(){return $A(B)}}})}}),jB=z({concat_:function(A,g){g===void 0&&(g=0),R(A.length>=1,function(){return"Pass at least one tensor to concat"});var B=Qe(A,"tensors","concat");B[0].dtype==="complex64"&&B.forEach(function(e){if(e.dtype!=="complex64")throw new Error(`Cannot concatenate complex64 tensors with a tensor
31
+ with dtype `+e.dtype+". ")}),g=TB(g,B[0].shape)[0];var Q=yw(B.map(function(e){return e.shape}),g);if(hA(Q)===0)return Ag([],Q);if((B=B.filter(function(e){return e.size>0})).length===1)return B[0];var w=B.map(function(e){return e.shape});lH(w,g);var C=B,E={axis:g};return b.runKernelFunc(function(e){return e.concat(B,g)},C,function(e){var I=w.map(function(o){return o[g]});return At(e,I,g).map(function(o){return function(){return o}})},"Concat",E)}}),NH=z({concat1d_:function(A){return jB(A,0)}}),mH=z({concat2d_:function(A,g){return jB(A,g)}}),RH=z({concat3d_:function(A,g){return jB(A,g)}}),PH=z({concat4d_:function(A,g){return jB(A,g)}}),At=z({split_:function(A,g,B){B===void 0&&(B=0);var Q,w=J(A,"x","split");return B=TB(B,w.shape)[0],typeof g=="number"?(R(w.shape[B]%g==0,function(){return"Number of splits must evenly divide the axis."}),Q=new Array(g).fill(w.shape[B]/g)):(R(w.shape[B]===g.reduce(function(C,E){return C+E}),function(){return"The sum of sizes must match the size of the axis dimension."}),Q=g),b.runKernelFunc(function(C){return C.split(w,Q,B)},{$x:w},function(C){return{$x:function(){return jB(C,B)}}})}});function gw(A,g){return A(g={exports:{}},g.exports),g.exports}var vH=gw(function(A){(function(g,B,Q){function w(e){var I,o=this,n=(I=4022871197,function(i){i=i.toString();for(var Y=0;Y<i.length;Y++){var M=.02519603282416938*(I+=i.charCodeAt(Y));M-=I=M>>>0,I=(M*=I)>>>0,I+=4294967296*(M-=I)}return 23283064365386963e-26*(I>>>0)});o.next=function(){var i=2091639*o.s0+23283064365386963e-26*o.c;return o.s0=o.s1,o.s1=o.s2,o.s2=i-(o.c=0|i)},o.c=1,o.s0=n(" "),o.s1=n(" "),o.s2=n(" "),o.s0-=n(e),o.s0<0&&(o.s0+=1),o.s1-=n(e),o.s1<0&&(o.s1+=1),o.s2-=n(e),o.s2<0&&(o.s2+=1),n=null}function C(e,I){return I.c=e.c,I.s0=e.s0,I.s1=e.s1,I.s2=e.s2,I}function E(e,I){var o=new w(e),n=I&&I.state,i=o.next;return i.int32=function(){return 4294967296*o.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.alea=E})(0,A)}),kH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.x=0,I.y=0,I.z=0,I.w=0,I.next=function(){var i=I.x^I.x<<11;return I.x=I.y,I.y=I.z,I.z=I.w,I.w^=I.w>>>19^i^i>>>8},e===(0|e)?I.x=e:o+=e;for(var n=0;n<o.length+64;n++)I.x^=0|o.charCodeAt(n),I.next()}function C(e,I){return I.x=e.x,I.y=e.y,I.z=e.z,I.w=e.w,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xor128=E})(0,A)}),TH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.next=function(){var i=I.x^I.x>>>2;return I.x=I.y,I.y=I.z,I.z=I.w,I.w=I.v,(I.d=I.d+362437|0)+(I.v=I.v^I.v<<4^i^i<<1)|0},I.x=0,I.y=0,I.z=0,I.w=0,I.v=0,e===(0|e)?I.x=e:o+=e;for(var n=0;n<o.length+64;n++)I.x^=0|o.charCodeAt(n),n==o.length&&(I.d=I.x<<10^I.x>>>4),I.next()}function C(e,I){return I.x=e.x,I.y=e.y,I.z=e.z,I.w=e.w,I.v=e.v,I.d=e.d,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xorwow=E})(0,A)}),jH=gw(function(A){(function(g,B,Q){function w(e){var I=this;I.next=function(){var o,n,i=I.x,Y=I.i;return o=i[Y],n=(o^=o>>>7)^o<<24,n^=(o=i[Y+1&7])^o>>>10,n^=(o=i[Y+3&7])^o>>>3,n^=(o=i[Y+4&7])^o<<7,o=i[Y+7&7],n^=(o^=o<<13)^o<<9,i[Y]=n,I.i=Y+1&7,n},function(o,n){var i,Y=[];if(n===(0|n))Y[0]=n;else for(n=""+n,i=0;i<n.length;++i)Y[7&i]=Y[7&i]<<15^n.charCodeAt(i)+Y[i+1&7]<<13;for(;Y.length<8;)Y.push(0);for(i=0;i<8&&Y[i]===0;++i);for(i==8?Y[7]=-1:Y[i],o.x=Y,o.i=0,i=256;i>0;--i)o.next()}(I,e)}function C(e,I){return I.x=e.x.slice(),I.i=e.i,I}function E(e,I){e==null&&(e=+new Date);var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(n.x&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xorshift7=E})(0,A)}),pH=gw(function(A){(function(g,B,Q){function w(e){var I=this;I.next=function(){var o,n,i=I.w,Y=I.X,M=I.i;return I.w=i=i+1640531527|0,n=Y[M+34&127],o=Y[M=M+1&127],n^=n<<13,o^=o<<17,n^=n>>>15,o^=o>>>12,n=Y[M]=n^o,I.i=M,n+(i^i>>>16)|0},function(o,n){var i,Y,M,c,D,r=[],F=128;for(n===(0|n)?(Y=n,n=null):(n+="\0",Y=0,F=Math.max(F,n.length)),M=0,c=-32;c<F;++c)n&&(Y^=n.charCodeAt((c+32)%n.length)),c===0&&(D=Y),Y^=Y<<10,Y^=Y>>>15,Y^=Y<<4,Y^=Y>>>13,c>=0&&(D=D+1640531527|0,M=(i=r[127&c]^=Y+D)==0?M+1:0);for(M>=128&&(r[127&(n&&n.length||0)]=-1),M=127,c=512;c>0;--c)Y=r[M+34&127],i=r[M=M+1&127],Y^=Y<<13,i^=i<<17,Y^=Y>>>15,i^=i>>>12,r[M]=Y^i;o.w=D,o.X=r,o.i=M}(I,e)}function C(e,I){return I.i=e.i,I.w=e.w,I.X=e.X.slice(),I}function E(e,I){e==null&&(e=+new Date);var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(n.X&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.xor4096=E})(0,A)}),yH=gw(function(A){(function(g,B,Q){function w(e){var I=this,o="";I.next=function(){var i=I.b,Y=I.c,M=I.d,c=I.a;return i=i<<25^i>>>7^Y,Y=Y-M|0,M=M<<24^M>>>8^c,c=c-i|0,I.b=i=i<<20^i>>>12^Y,I.c=Y=Y-M|0,I.d=M<<16^Y>>>16^c,I.a=c-i|0},I.a=0,I.b=0,I.c=-1640531527,I.d=1367130551,e===Math.floor(e)?(I.a=e/4294967296|0,I.b=0|e):o+=e;for(var n=0;n<o.length+20;n++)I.b^=0|o.charCodeAt(n),I.next()}function C(e,I){return I.a=e.a,I.b=e.b,I.c=e.c,I.d=e.d,I}function E(e,I){var o=new w(e),n=I&&I.state,i=function(){return(o.next()>>>0)/4294967296};return i.double=function(){do var Y=((o.next()>>>11)+(o.next()>>>0)/4294967296)/2097152;while(Y===0);return Y},i.int32=o.next,i.quick=i,n&&(typeof n=="object"&&C(n,o),i.state=function(){return C(o,{})}),i}B&&B.exports?B.exports=E:this.tychei=E})(0,A)}),Qw=gw(function(A){(function(g,B){var Q,w=this,C=256,E=6,e="random",I=B.pow(C,E),o=B.pow(2,52),n=2*o,i=C-1;function Y(F,s,u){var a=[],U=D(function H(h,l){var m,f=[],W=typeof h;if(l&&W=="object")for(m in h)try{f.push(H(h[m],l-1))}catch{}return f.length?f:W=="string"?h:h+"\0"}((s=s==1?{entropy:!0}:s||{}).entropy?[F,r(g)]:F??function(){try{var H;return Q&&(H=Q.randomBytes)?H=H(C):(H=new Uint8Array(C),(w.crypto||w.msCrypto).getRandomValues(H)),r(H)}catch{var h=w.navigator,l=h&&h.plugins;return[+new Date,w,l,w.screen,r(g)]}}(),3),a),G=new M(a),d=function(){for(var H=G.g(E),h=I,l=0;H<o;)H=(H+l)*C,h*=C,l=G.g(1);for(;H>=n;)H/=2,h/=2,l>>>=1;return(H+l)/h};return d.int32=function(){return 0|G.g(4)},d.quick=function(){return G.g(4)/4294967296},d.double=d,D(r(G.S),g),(s.pass||u||function(H,h,l,m){return m&&(m.S&&c(m,G),H.state=function(){return c(G,{})}),l?(B[e]=H,h):H})(d,U,"global"in s?s.global:this==B,s.state)}function M(F){var s,u=F.length,a=this,U=0,G=a.i=a.j=0,d=a.S=[];for(u||(F=[u++]);U<C;)d[U]=U++;for(U=0;U<C;U++)d[U]=d[G=i&G+F[U%u]+(s=d[U])],d[G]=s;(a.g=function(H){for(var h,l=0,m=a.i,f=a.j,W=a.S;H--;)h=W[m=i&m+1],l=l*C+W[i&(W[m]=W[f=i&f+h])+(W[f]=h)];return a.i=m,a.j=f,l})(C)}function c(F,s){return s.i=F.i,s.j=F.j,s.S=F.S.slice(),s}function D(F,s){for(var u,a=F+"",U=0;U<a.length;)s[i&U]=i&(u^=19*s[i&U])+a.charCodeAt(U++);return r(s)}function r(F){return String.fromCharCode.apply(0,F)}if(B["seed"+e]=Y,D(B.random(),g),A.exports){A.exports=Y;try{Q=require("crypto")}catch{}}})([],Math)});Qw.alea=vH,Qw.xor128=kH,Qw.xorwow=TH,Qw.xorshift7=jH,Qw.xor4096=pH,Qw.tychei=yH;var Ce=Qw.alea,Bt=function(){function A(g,B,Q,w,C){this.mean=g,this.stdDev=B,this.dtype=Q,this.nextVal=NaN,this.truncated=w,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var E=C||Math.random();this.random=Ce(E.toString())}return A.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var g=this.nextVal;return this.nextVal=NaN,g}for(var B,Q,w=!1;!w;){var C=void 0,E=void 0,e=void 0;do e=(C=2*this.random()-1)*C+(E=2*this.random()-1)*E;while(e>=1||e===0);var I=Math.sqrt(-2*Math.log(e)/e);B=this.mean+this.stdDev*C*I,Q=this.mean+this.stdDev*E*I,this.truncated&&!this.isValidTruncated(B)||(w=!0)}return this.truncated&&!this.isValidTruncated(Q)||(this.nextVal=this.convertValue(Q)),this.convertValue(B)},A.prototype.convertValue=function(g){return this.dtype==null||this.dtype==="float32"?g:Math.round(g)},A.prototype.isValidTruncated=function(g){return g<=this.upper&&g>=this.lower},A}(),zH=function(){function A(g,B,Q,w){this.alpha=g,this.beta=1/B,this.dtype=Q;var C=w||Math.random();this.randu=Ce(C.toString()),this.randn=new Bt(0,1,Q,!1,this.randu()),this.d=g<1?g+2/3:g-1/3,this.c=1/Math.sqrt(9*this.d)}return A.prototype.nextValue=function(){for(var g,B,Q,w,C,E;;){do w=this.randn.nextValue(),E=1+this.c*w;while(E<=0);if(E*=E*E,B=1-.331*(g=w*w)*g,Q=.5*g+this.d*(1-E+Math.log(E)),(C=this.randu())<B||Math.log(C)<Q)break}return E=1/this.beta*this.d*E,this.alpha<1&&(E*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(E)},A.prototype.convertValue=function(g){return this.dtype==="float32"?g:Math.round(g)},A}(),WH=function(){function A(g,B,Q,w){var C=this;if(g===void 0&&(g=0),B===void 0&&(B=1),this.canReturnFloat=function(){return C.dtype==null||C.dtype==="float32"},this.min=g,this.range=B-g,this.dtype=Q,w==null&&(w=Math.random()),typeof w=="number"&&(w=w.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+g+" - "+B+" <= 1 and dtype is not float");this.random=Ce(w)}return A.prototype.convertValue=function(g){return this.canReturnFloat()?g:Math.round(g)},A.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},A}();function zA(A,g,B){return g===void 0&&(g="float32"),g=g||"float32",KM(A),new RC(A,g,B)}function SH(A,g){g===void 0&&(g=!1),console.log(A.toString(g))}var ec=z({batchToSpaceND_:function(A,g,B){var Q=J(A,"x","batchToSpaceND"),w=g.reduce(function(C,E){return C*E});return R(Q.rank>=1+g.length,function(){return"input rank is "+Q.rank+" but should be > than blockShape.length "+g.length}),R(B.length===g.length,function(){return"crops.length is "+B.length+" but should be equal to blockShape.length "+g.length}),R(Q.shape[0]%w==0,function(){return"input tensor batch is "+Q.shape[0]+" but is not divisible by the product of the elements of blockShape "+g.join(" * ")+" === "+w}),b.runKernelFunc(function(C){return C.batchToSpaceND(Q,g,B)},{$x:Q},function(C){return{$x:function(){return C.spaceToBatchND(g,B)}}})}}),LH=z({broadcastTo_:function(A,g){var B=J(A,"broadcastTo","x"),Q=B.shape;if(g.some(function(I){return!(I>0)||I%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+g+"].");if(g.length<B.rank)throw new Error("broadcastTo(): shape.length="+g.length+" < input.rank="+B.rank+".");if(g.length>B.rank){for(var w=B.shape.slice();w.length<g.length;)w.unshift(1);B=B.reshape(w)}for(var C=Array.from(g),E=g.length-1;E>=0;E--)if(B.shape[E]===g[E])C[E]=1;else if(B.shape[E]!==1)throw new Error("broadcastTo(): ["+Q+"] cannot be broadcast to ["+g+"].");var e=C.map(function(I,o){return I>1?o:-1}).filter(function(I){return I>=0});return e.length===0?B.clone():b.runKernelFunc(function(I){return I.tile(B,C)},{input:B},function(I){return{input:function(){return I.sum(e,!0)}}})}}),bH=z({cast_:function(A,g){var B=J(A,"x","cast");if(!Td(g))throw new Error("Failed to cast to unknown dtype "+g);if(g==="string"&&B.dtype!=="string"||g!=="string"&&B.dtype==="string")throw new Error("Only strings can be casted to strings");var Q={dtype:g};return b.runKernelFunc(function(w){return w.cast(B,g)},{x:B},function(w){return{x:function(){return w.clone()}}},"Cast",Q)}}),KH=z({clone_:function(A){var g=J(A,"x","clone",null);return b.runKernelFunc(function(){return b.makeTensorFromDataId(g.dataId,g.shape,g.dtype)},{$x:g},function(B){return{$x:function(){return B.toFloat()}}})}}),VH=z({cumsum_:function(A,g,B,Q){g===void 0&&(g=0),B===void 0&&(B=!1),Q===void 0&&(Q=!1);var w=J(A,"x","cumsum"),C=$g([g|=0],w.rank),E=w;C!=null&&(E=w.transpose(C));var e=AQ(1,w.rank)[0],I=b.runKernelFunc(function(o){return o.cumsum(E,e,B,Q)},{permutedX:E},function(o){return{permutedX:function(){return o.cumsum(g,B,!Q)}}});return C!=null&&(I=I.transpose(C)),I}}),xH=z({depthToSpace_:function(A,g,B){B===void 0&&(B="NHWC");var Q=J(A,"x","depthToSpace"),w=B==="NHWC"?Q.shape[1]:Q.shape[2],C=B==="NHWC"?Q.shape[2]:Q.shape[3],E=B==="NHWC"?Q.shape[3]:Q.shape[1];return R(w*g>=0,function(){return`Negative dimension size caused by overflow when multiplying
32
32
  `+w+" and "+g+` for depthToSpace with input shape
33
33
  `+Q.shape}),R(C*g>=0,function(){return`Negative dimension size caused by overflow when multiplying
34
34
  `+C+" and "+g+` for depthToSpace with input shape
35
- `+Q.shape}),R(E%(g*g)==0,function(){return"Dimension size must be evenly divisible by "+g*g+" but is "+E+" for depthToSpace with input shape "+Q.shape}),b.runKernelFunc(function(e){return e.depthToSpace(Q,g,B)},{$x:Q})}}),Tg=z({expandDims_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","expandDims",null);R(g<=B.rank,function(){return"Axis must be <= rank of the tensor"});var Q=B.shape.slice();return g<0&&(R(-(B.rank+1)<=g,function(){return"Axis must be in the interval ["+-(B.rank+1)+", "+B.rank+"]"}),g=B.rank+g+1),Q.splice(g,0,1),Sg(B,Q)}}),Ic=z({eye_:function(A,g,B,Q){Q===void 0&&(Q="float32"),g==null&&(g=A);for(var w=zA([A,g],Q),C=A<=g?A:g,E=0;E<C;++E)w.set(1,E,E);var e=w.toTensor().as2D(A,g);if(B==null)return e;if(B.length===1)return Ww(Tg(e,0),[B[0],1,1]);if(B.length===2)return Ww(Tg(Tg(e,0),0),[B[0],B[1],1,1]);if(B.length===3)return Ww(Tg(Tg(Tg(e,0),0),0),[B[0],B[1],B[2],1,1]);throw new Error("eye() currently supports only 1D and 2D batchShapes, but received "+B.length+"D.")}}),VH=z({multinomial_:function(A,g,B,Q){Q===void 0&&(Q=!1);var w=J(A,"logits","multinomial"),C=w.size,E=w.rank;if(C<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+C+".");if(E>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+E);B=B||Math.random();var e=E===1?w.as2D(1,-1):w,I=b.runKernelFunc(function(o){return o.multinomial(e,Q,g,B)},{logits2D:e});return E===1?I.as1D():I}}),Bt=z({oneHot_:function(A,g,B,Q){if(B===void 0&&(B=1),Q===void 0&&(Q=0),g<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+g);var w=J(A,"indices","oneHot","int32"),C=w.shape.concat([g]);return w=w.flatten(),b.runKernelFunc(function(E){return E.oneHot(w,g,B,Q)},{$indices:w},function(E){return{$indices:function(){return DB(w.shape,"float32")}}}).reshape(C)}}),ww=z({pad_:function(A,g,B){B===void 0&&(B=0);var Q=J(A,"x","pad");if(Q.rank===0)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var w={paddings:g,constantValue:B};return b.runKernelFunc(function(C){return C.pad(Q,g,B)},{x:Q},function(C){var E=g.map(function(e){return e[0]});return{x:function(){return C.slice(E,Q.shape)}}},"PadV2",w)}}),xH=z({pad1d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===2,function(){return"Invalid number of paddings. Must be length of 2."}),ww(A,[g],B)}}),XH=z({pad2d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===2&&g[0].length===2&&g[1].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),OH=z({pad3d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===3&&g[0].length===2&&g[1].length===2&&g[2].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),ZH=z({pad4d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===4&&g[0].length===2&&g[1].length===2&&g[2].length===2&&g[3].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),qH=z({rand_:function(A,g,B){var Q=hA(A),w=null;if(B==null||B==="float32")w=new Float32Array(Q);else if(B==="int32")w=new Int32Array(Q);else{if(B!=="bool")throw new Error("Unknown data type "+B);w=new Uint8Array(Q)}for(var C=0;C<Q;C++)w[C]=g();return b.makeTensor(w,A,B)}}),_H=z({randomNormal_:function(A,g,B,Q,w){if(g===void 0&&(g=0),B===void 0&&(B=1),Q!=null&&Q==="bool")throw new Error("Unsupported data type "+Q);for(var C=new At(g,B,Q,!1,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),$H=z({randomGamma_:function(A,g,B,Q,w){if(B===void 0&&(B=1),Q===void 0&&(Q="float32"),B==null&&(B=1),Q==null&&(Q="float32"),Q!=="float32"&&Q!=="int32")throw new Error("Unsupported data type "+Q);for(var C=new pH(g,B,Q,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),oc=z({randomUniform_:function(A,g,B,Q,w){g===void 0&&(g=0),B===void 0&&(B=1),Q===void 0&&(Q="float32");for(var C=zA(A,Q),E=new yH(g,B,null,w),e=0;e<C.values.length;e++)C.values[e]=E.nextValue();return C.toTensor()}}),Sg=z({reshape_:function(A,g){var B=J(A,"x","reshape",null);g=Rd(g,B.size),R(B.size===hA(g),function(){return"new shape and old shape must have the same number of elements."});var Q={shape:g};return b.runKernelFunc(function(w){return w.reshape(B,g)},{x:B},function(w){return{x:function(){return w.reshape(B.shape)}}},"Reshape",Q)}}),tc=z({spaceToBatchND_:function(A,g,B){var Q=J(A,"x","spaceToBatchND");return R(Q.rank>=1+g.length,function(){return"input rank "+Q.rank+" should be > than [blockShape] "+g.length}),R(B.length===g.length,function(){return"paddings.shape[0] "+B.length+" must be equal to [blockShape] "+g.length}),R(Q.shape.reduce(function(w,C,E){return E>0&&E<=g.length?w&&(C+B[E-1][0]+B[E-1][1])%g[E-1]==0:w},!0),function(){return"input spatial dimensions "+Q.shape.slice(1)+" with paddings "+B.toString()+" must be divisible by blockShapes "+g.toString()}),b.runKernelFunc(function(w){return w.spaceToBatchND(Q,g,B)},{$x:Q},function(w){return{$x:function(){return w.batchToSpaceND(g,B)}}})}}),nc=z({squeeze_:function(A,g){var B=J(A,"x","squeeze");return Sg(B,Aw(B.shape,g).newShape)}}),Hg=z({stack_:function(A,g){g===void 0&&(g=0);var B=Qe(A,"tensors","stack");if(R(B.length>=1,function(){return"Pass at least one tensor to tf.stack"}),B.length===1)return B[0].expandDims(g);var Q=B[0].rank,w=B[0].shape,C=B[0].dtype;R(g<=Q,function(){return"Axis must be <= rank of the tensor"}),B.forEach(function(e){eB(w,e.shape,"All tensors passed to stack must have matching shapes")}),B.forEach(function(e){R(C===e.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var E=B.map(function(e){return e.expandDims(g)});return jB(E,g)}}),Ww=z({tile_:function(A,g){var B=J(A,"x","tile",null);R(B.rank===g.length,function(){return"Error in transpose: rank of input "+B.rank+" must match length of reps "+g+"."});var Q=[B],w={reps:g};return b.runKernelFunc(function(C,E){var e=C.tile(B,g);return E([B]),e},{x:B},function(C,E){var e=E[0];return{x:function(){var I=$A(e);if(e.rank===1)for(var o=0;o<g[0];++o)I=I.add(C.slice([o*e.shape[0]],[e.shape[0]]));else if(e.rank===2)for(o=0;o<g[0];++o)for(var n=0;n<g[1];++n)I=I.add(C.slice([o*e.shape[0],n*e.shape[1]],[e.shape[0],e.shape[1]]));else if(e.rank===3)for(o=0;o<g[0];++o)for(n=0;n<g[1];++n)for(var i=0;i<g[2];++i)I=I.add(C.slice([o*e.shape[0],n*e.shape[1],i*e.shape[2]],[e.shape[0],e.shape[1],e.shape[2]]));else{if(e.rank!==4)throw new Error("Gradient for tile operation is not implemented for rank-"+e.rank+" tensors yet.");for(o=0;o<g[0];++o)for(n=0;n<g[1];++n)for(i=0;i<g[2];++i)for(var Y=0;Y<g[3];++Y)I=I.add(C.slice([o*e.shape[0],n*e.shape[1],i*e.shape[2],Y*e.shape[3]],[e.shape[0],e.shape[1],e.shape[2],e.shape[3]]))}return I}}},"Tile",w,Q)}}),Af=z({truncatedNormal_:function(A,g,B,Q,w){if(g===void 0&&(g=0),B===void 0&&(B=1),Q!=null&&Q==="bool")throw new Error("Unsupported data type "+Q);for(var C=new At(g,B,Q,!0,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),pB=z({unstack_:function(A,g){g===void 0&&(g=0),g=g||0;var B=J(A,"x","unstack");R(g>=-B.shape.length&&g<B.shape.length,function(){return"Axis = "+g+" is not in [-"+B.shape.length+", "+B.shape.length+")"}),g<0&&(g+=B.shape.length);var Q={axis:g};return b.runKernelFunc(function(w){return w.unstack(B,g)},{x:B},function(w){return{x:function(){return Hg(w,g)}}},"Unpack",Q)}}),Bf=function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return B=J(A,"x","setdiff1d"),Q=J(g,"y","setdiff1d"),R(B.dtype===Q.dtype,function(){return"x and y should have the same dtype, but got x ("+B.dtype+") and y ("+Q.dtype+")."}),R(B.rank===1,function(){return"x should be 1D tensor, but got x ("+B.shape+")."}),R(Q.rank===1,function(){return"y should be 1D tensor, but got y ("+Q.shape+")."}),[4,B.data()];case 1:return w=Y.sent(),[4,Q.data()];case 2:for(C=Y.sent(),E=new Set(C),e=0,n=0;n<w.length;n++)E.has(w[n])||e++;for(I=new RC([e],B.dtype),o=new RC([e],"int32"),n=0,i=0;n<w.length;n++)E.has(w[n])||(I.values[i]=w[n],o.values[i]=n,i++);return[2,[I.toTensor(),o.toTensor()]]}})})};function Ee(A,g,B,Q){Q===void 0&&(Q=!0);var w=[];if(Q)(w=w.concat(g.slice(0))).push(A[0]/B),w=w.concat(A.slice(1));else{w=w.concat(A[0]);for(var C=g.length,E=0;E<C;++E)w=w.concat([A[E+1]/g[E],g[E]]);w=w.concat(A.slice(C+1))}return w}function ee(A,g,B){B===void 0&&(B=!0);var Q=[];if(B){Q.push(g);for(var w=g+1;w<A;++w)w<=2*g?(Q.push(w),Q.push(w-(g+1))):Q.push(w)}else{var C=[],E=[];for(w=1;w<A;++w)w>=2*g+1||w%2==1?E.push(w):C.push(w);Q.push.apply(Q,C),Q.push(0),Q.push.apply(Q,E)}return Q}function Ie(A,g,B,Q){Q===void 0&&(Q=!0);var w=[];Q?w.push(A[0]/B):w.push(A[0]*B);for(var C=1;C<A.length;++C)C<=g.length?Q?w.push(g[C-1]*A[C]):w.push(A[C]/g[C-1]):w.push(A[C]);return w}function ic(A,g){for(var B=[0],Q=0;Q<g;++Q)B.push(A[Q][0]);return B}function Yc(A,g,B){for(var Q=A.slice(0,1),w=0;w<B;++w)Q.push(A[w+1]-g[w][0]-g[w][1]);return Q}function Mc(A,g){if(A.rank<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was "+A.rank+".");if(g.rank<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was "+g.rank+".");if(g.dtype!=="int32")throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was "+g.dtype+".");if(g.shape[g.rank-1]>A.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+g.shape[g.rank-1]+" vs. "+A.rank);if(A.size===0)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+A.shape+".");for(var B=g.shape,Q=B[B.length-1],w=1,C=0;C<B.length-1;++C)w*=B[C];var E=A.shape,e=B.slice();e.pop();var I=1;for(C=Q;C<A.rank;++C)I*=E[C],e.push(E[C]);var o=Og(A.shape).map(function(n){return n/I}).concat([1]).slice(0,Q);return[e,w,I,o]}var cc=30;function gt(A){return A<=cc?A:ko(A,Math.floor(Math.sqrt(A)))}function gf(A,g,B){var Q=g.rank>1?g.shape[g.rank-1]:1,w=g.rank>1?g.rank-1:1,C="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+B.shape+", indices.shape: "+g.shape+", shape: "+A+", sliceDim: "+Q+", and batchDim: "+w+".";if(B.rank<w)throw new Error(C+" update.rank < "+w+". ");if(A.length<Q+(B.rank-w))throw new Error(C+" Output shape length < "+(Q+(B.rank-w)));if(B.rank!==w+A.length-Q)throw new Error(C+" update.rank != "+(w+A.length-Q));for(var E=0;E<w;++E)if(B.shape[E]!==g.shape[E])throw new Error(C+" updates.shape["+E+"] ("+B.shape[E]+") != indices.shape["+E+"] ("+g.shape[E]+").");for(E=0;E<B.rank-w;++E)if(B.shape[E+w]!==A[E+Q])throw new Error(C+" updates.shape["+(E+w)+"] ("+B.shape[E+w]+") != shape["+(E+w)+"] ("+A[E+w]+")")}function Qf(A,g,B){if(g.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was "+g.rank+".");if(A.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was "+A.rank+".");if(g.dtype!=="int32")throw new Error("The dtype of 'indices' should be int32, but got dtype: "+g.dtype);if(B.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+B);if(B.length===0){if(g.size===0)throw new Error("Indices specified for empty output. indices shape: "+g.shape);if(A.size===0)throw new Error("Updates specified for empty output. updates shape: "+A.shape)}gf(B,g,A)}function oe(A,g,B){for(var Q=g.shape.length,w=Q>1?g.shape[Q-1]:1,C=B.length,E=1,e=w;e<C;++e)E*=B[e];var I=w<1?1:w;return{sliceRank:w,numUpdates:hA(g.shape)/I,sliceSize:E,strides:Og(B.slice(0,w)).concat([1]),outputSize:hA(B)}}function wf(A,g,B){R(A.rank===g.length,function(){return"Error in slice"+A.rank+"D: Length of begin "+g+" must match the rank of the array ("+A.rank+")."}),R(A.rank===B.length,function(){return"Error in slice"+A.rank+"D: Length of size "+B+" must match the rank of the array ("+A.rank+")."});for(var Q=function(C){R(g[C]+B[C]<=A.shape[C],function(){return"Error in slice"+A.rank+"D: begin["+C+"] + size["+C+"] ("+(g[C]+B[C])+") would overflow input.shape["+C+"] ("+A.shape[C]+")"})},w=0;w<A.rank;++w)Q(w)}function Dc(A){for(var g=[],B=0;A>0;)1&A&&g.push(B),A/=2,B++;return g}function Qt(A,g,B){for(var Q=[],w=0;w<A.length;w++)Q[w]=Math.ceil((g[w]-A[w])/B[w]);return Q}function Cf(A,g,B,Q,w){var C=g[w],E=B[w]||1;(A&1<<w||C==null)&&(C=E>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var e=Q[w];return C<0&&(C+=e),C=mo(0,C,e-1)}function Ef(A,g,B,Q,w){var C=g[w],E=B[w]||1;(A&1<<w||C==null)&&(C=E>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var e=Q[w];return C<0&&(C+=e),C=E>0?mo(0,C,e):mo(-1,C,e-1)}function rc(A,g,B){for(var Q=B.length,w=0;w<B.length;w++)if(B[w]>1){Q=w;break}for(w=Q+1;w<B.length;w++)if(g[w]>0||B[w]!==A[w])return!1;return!0}function Fc(A,g){for(var B=A.length>0?A[A.length-1]:1,Q=0;Q<A.length-1;Q++)B+=A[Q]*g[Q];return B}function ef(A,g){R(vo(A),function(){return"The f passed in variableGrads(f) must be a function"}),R(g==null||Array.isArray(g)&&g.every(function(n){return n instanceof pw}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var B=g!=null;if(!B)for(var Q in g=[],b.registeredVariables)g.push(b.registeredVariables[Q]);var w=B?g.filter(function(n){return!n.trainable}):null,C=g.length;R((g=g.filter(function(n){return n.trainable})).length>0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+C+" variables is trainable."});var E=b.gradients(A,g,null,!0),e=E.value,I=E.grads;R(I.some(function(n){return n!=null}),function(){return"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()."}),R(e.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+e.rank+" tensor"});var o={};return g.forEach(function(n,i){I[i]!=null&&(o[n.name]=I[i])}),w!=null&&w.forEach(function(n){return o[n.name]=null}),{value:e,grads:o}}function te(A){return b.customGrad(A)}var rQ=z({softmax_:function(A,g){g===void 0&&(g=-1);var B=J(A,"logits","softmax","float32");if(g===-1&&(g=B.rank-1),g!==B.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+B.rank+" and dim was "+g);return b.runKernelFunc(function(Q,w){var C=Q.softmax(B,g);return w([C]),C},{logits:B},function(Q,w){var C=w[0],E=Q.mul(C);return{logits:function(){return E.sub(E.sum([g],!0).mul(C))}}},"Softmax",{dim:g},[],[!0])}}),If=z({logSoftmax_:function(A,g){g===void 0&&(g=-1);var B=J(A,"logits","logSoftmax");if(g===-1&&(g=B.rank-1),g!==B.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+B.rank+" and axis was "+g);return te(function(Q,w){var C=Q.max(g,!0),E=Q.sub(C),e=E.toFloat().sub(E.exp().sum(g,!0).log());return w([e]),{value:e,gradFunc:function(I,o){var n=o[0].exp();return I.sub(I.sum(g,!0).mul(n))}}})(B)}}),ac=function(){function A(g,B){this.backend=g,this.dataMover=B,this.data=new WeakMap,this.dataIdsCount=0}return A.prototype.get=function(g){return this.data.has(g)||this.dataMover.moveData(this.backend,g),this.data.get(g)},A.prototype.set=function(g,B){this.dataIdsCount++,this.data.set(g,B)},A.prototype.has=function(g){return this.data.has(g)},A.prototype.delete=function(g){return this.dataIdsCount--,this.data.delete(g)},A.prototype.numDataIds=function(){return this.dataIdsCount},A}(),sc=function(){function A(){}return A.prototype.time=function(g){return x("time")},A.prototype.read=function(g){return x("read")},A.prototype.readSync=function(g){return x("readSync")},A.prototype.numDataIds=function(){return x("numDataIds")},A.prototype.disposeData=function(g){return x("disposeData")},A.prototype.write=function(g,B,Q){return x("write")},A.prototype.move=function(g,B,Q,w){return x("move")},A.prototype.memory=function(){return x("memory")},A.prototype.floatPrecision=function(){return x("floatPrecision")},A.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},A.prototype.batchMatMul=function(g,B,Q,w){return x("batchMatMul")},A.prototype.fusedBatchMatMul=function(g){return g.a,g.b,g.transposeA,g.transposeB,g.bias,g.activation,g.preluActivationWeights,x("fusedBatchMatMul")},A.prototype.slice=function(g,B,Q){return x("slice")},A.prototype.stridedSlice=function(g,B,Q,w){return x("stridedSlice")},A.prototype.unstack=function(g,B){return x("unstack")},A.prototype.reverse=function(g,B){return x("reverse")},A.prototype.concat=function(g,B){return x("concat")},A.prototype.neg=function(g){return x("neg")},A.prototype.add=function(g,B){return x("add")},A.prototype.addN=function(g){return x("addN")},A.prototype.subtract=function(g,B){return x("subtract")},A.prototype.multiply=function(g,B){return x("multiply")},A.prototype.realDivide=function(g,B){return x("realDivide")},A.prototype.floorDiv=function(g,B){return x("floorDiv")},A.prototype.sum=function(g,B){return x("sum")},A.prototype.prod=function(g,B){return x("prod")},A.prototype.unsortedSegmentSum=function(g,B,Q){return x("unsortedSegmentSum")},A.prototype.argMin=function(g,B){return x("argMin")},A.prototype.argMax=function(g,B){return x("argMax")},A.prototype.equal=function(g,B){return x("equal")},A.prototype.notEqual=function(g,B){return x("notEqual")},A.prototype.less=function(g,B){return x("less")},A.prototype.lessEqual=function(g,B){return x("lessEqual")},A.prototype.greater=function(g,B){return x("greater")},A.prototype.greaterEqual=function(g,B){return x("greaterEqual")},A.prototype.logicalNot=function(g){return x("logicalNot")},A.prototype.logicalAnd=function(g,B){return x("logicalAnd")},A.prototype.logicalOr=function(g,B){return x("logicalOr")},A.prototype.where=function(g){return x("where")},A.prototype.select=function(g,B,Q){return x("select")},A.prototype.topk=function(g,B,Q){return x("topk")},A.prototype.min=function(g,B){return x("min")},A.prototype.minimum=function(g,B){return x("minimum")},A.prototype.mod=function(g,B){return x("mod")},A.prototype.max=function(g,B){return x("max")},A.prototype.maximum=function(g,B){return x("maximum")},A.prototype.all=function(g,B){return x("all")},A.prototype.any=function(g,B){return x("any")},A.prototype.squaredDifference=function(g,B){return x("squaredDifference")},A.prototype.ceil=function(g){return x("ceil")},A.prototype.floor=function(g){return x("floor")},A.prototype.round=function(g){return x("round")},A.prototype.sign=function(g){return x("sign")},A.prototype.isNaN=function(g){return x("isNaN")},A.prototype.isInf=function(g){return x("isInf")},A.prototype.isFinite=function(g){return x("isFinite")},A.prototype.pow=function(g,B){return x("pow")},A.prototype.exp=function(g){return x("exp")},A.prototype.expm1=function(g){return x("expm1")},A.prototype.softmax=function(g,B){return x("softmax")},A.prototype.log=function(g){return x("log")},A.prototype.log1p=function(g){return x("log1p")},A.prototype.sqrt=function(g){return x("sqrt")},A.prototype.rsqrt=function(g){return x("rsqrt")},A.prototype.square=function(g){return x("square")},A.prototype.reciprocal=function(g){return x("reciprocal")},A.prototype.relu=function(g){return x("relu")},A.prototype.relu6=function(g){return x("relu6")},A.prototype.prelu=function(g,B){return x("prelu")},A.prototype.elu=function(g){return x("elu")},A.prototype.eluDer=function(g,B){return x("eluDer")},A.prototype.selu=function(g){return x("selu")},A.prototype.int=function(g){return x("int")},A.prototype.clip=function(g,B,Q){return x("clip")},A.prototype.abs=function(g){return x("abs")},A.prototype.complexAbs=function(g){return x("complexAbs")},A.prototype.sigmoid=function(g){return x("sigmoid")},A.prototype.softplus=function(g){return x("softplus")},A.prototype.sin=function(g){return x("sin")},A.prototype.cos=function(g){return x("cos")},A.prototype.tan=function(g){return x("tan")},A.prototype.asin=function(g){return x("asin")},A.prototype.acos=function(g){return x("acos")},A.prototype.atan=function(g){return x("atan")},A.prototype.atan2=function(g,B){return x("atan2")},A.prototype.sinh=function(g){return x("sinh")},A.prototype.cosh=function(g){return x("cosh")},A.prototype.tanh=function(g){return x("tanh")},A.prototype.asinh=function(g){return x("asinh")},A.prototype.acosh=function(g){return x("acosh")},A.prototype.atanh=function(g){return x("atanh")},A.prototype.erf=function(g){return x("erf")},A.prototype.step=function(g,B){return x("step")},A.prototype.fusedConv2d=function(g){return g.input,g.filter,g.convInfo,g.bias,g.activation,g.preluActivationWeights,x("fusedConv2d")},A.prototype.conv2d=function(g,B,Q){return x("conv2d")},A.prototype.conv2dDerInput=function(g,B,Q){return x("conv2dDerInput")},A.prototype.conv2dDerFilter=function(g,B,Q){return x("conv2dDerFilter")},A.prototype.fusedDepthwiseConv2D=function(g){return g.input,g.filter,g.convInfo,g.bias,g.activation,g.preluActivationWeights,x("fusedDepthwiseConv2D")},A.prototype.depthwiseConv2D=function(g,B,Q){return x("depthwiseConv2D")},A.prototype.depthwiseConv2DDerInput=function(g,B,Q){return x("depthwiseConv2DDerInput")},A.prototype.depthwiseConv2DDerFilter=function(g,B,Q){return x("depthwiseConv2DDerFilter")},A.prototype.conv3d=function(g,B,Q){return x("conv3d")},A.prototype.conv3dDerInput=function(g,B,Q){return x("conv3dDerInput")},A.prototype.conv3dDerFilter=function(g,B,Q){return x("conv3dDerFilter")},A.prototype.maxPool=function(g,B){return x("maxPool")},A.prototype.maxPoolBackprop=function(g,B,Q,w){return x("maxPoolBackprop")},A.prototype.avgPool=function(g,B){return x("avgPool")},A.prototype.avgPoolBackprop=function(g,B,Q){return x("avgPoolBackprop")},A.prototype.avgPool3d=function(g,B){return x("avgPool3d")},A.prototype.avgPool3dBackprop=function(g,B,Q){return x("avgPool3dBackprop")},A.prototype.maxPool3d=function(g,B){return x("maxPool3d")},A.prototype.maxPool3dBackprop=function(g,B,Q,w){return x("maxPool3dBackprop")},A.prototype.reshape=function(g,B){return x("reshape")},A.prototype.cast=function(g,B){return x("cast")},A.prototype.tile=function(g,B){return x("tile")},A.prototype.pad=function(g,B,Q){return x("pad")},A.prototype.transpose=function(g,B){return x("transpose")},A.prototype.gather=function(g,B,Q){return x("gather")},A.prototype.gatherND=function(g,B){return x("gatherND")},A.prototype.scatterND=function(g,B,Q){return x("scatterND")},A.prototype.batchToSpaceND=function(g,B,Q){return x("batchToSpaceND")},A.prototype.spaceToBatchND=function(g,B,Q){return x("spaceToBatchND")},A.prototype.resizeBilinear=function(g,B,Q,w){return x("resizeBilinear")},A.prototype.resizeBilinearBackprop=function(g,B,Q){return x("resizeBilinearBackprop")},A.prototype.resizeNearestNeighbor=function(g,B,Q,w){return x("resizeNearestNeighbor")},A.prototype.resizeNearestNeighborBackprop=function(g,B,Q){return x("resizeNearestNeighborBackprop")},A.prototype.batchNormalization=function(g,B,Q,w,C,E){return x("batchNormalization")},A.prototype.localResponseNormalization4D=function(g,B,Q,w,C){return x("localResponseNormalization4D")},A.prototype.LRNGrad=function(g,B,Q,w,C,E,e){return x("LRNGrad")},A.prototype.multinomial=function(g,B,Q,w){return x("multinomial")},A.prototype.oneHot=function(g,B,Q,w){return x("oneHot")},A.prototype.cumsum=function(g,B,Q,w){return x("cumsum")},A.prototype.nonMaxSuppression=function(g,B,Q,w,C){return x("nonMaxSuppression")},A.prototype.fft=function(g){return x("fft")},A.prototype.ifft=function(g){return x("ifft")},A.prototype.complex=function(g,B){return x("complex")},A.prototype.real=function(g){return x("real")},A.prototype.imag=function(g){return x("imag")},A.prototype.cropAndResize=function(g,B,Q,w,C,E){return x("cropAndResize")},A.prototype.depthToSpace=function(g,B,Q){return x("depthToSpace")},A.prototype.split=function(g,B,Q){return x("split")},A.prototype.sparseToDense=function(g,B,Q,w){return x("sparseToDense")},A.prototype.diag=function(g){return x("diag")},A.prototype.fill=function(g,B,Q){return x("fill")},A.prototype.onesLike=function(g){return x("onesLike")},A.prototype.zerosLike=function(g){return x("zerosLike")},A.prototype.linspace=function(g,B,Q){return x("linspace")},A.prototype.dispose=function(){return x("dispose")},A}();function x(A){throw new Error("'"+A+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function PQ(A,g){for(var B=A.length,Q=[],w=0;w<B;w++){var C=B-1-w,E=A[C]||1;(g[g.length-1-w]||1)>1&&E===1&&Q.unshift(C)}return Q}function yB(A,g){for(var B=[],Q=0;Q<g.length;Q++){var w=A[A.length-Q-1],C=g.length-Q-1,E=g[C];(w==null||w===1&&E>1)&&B.unshift(C)}return B}function qA(A,g){for(var B=[],Q=Math.max(A.length,g.length),w=0;w<Q;w++){var C=A[A.length-w-1];C==null&&(C=1);var E=g[g.length-w-1];if(E==null&&(E=1),C===1)B.unshift(E);else if(E===1)B.unshift(C);else{if(C!==E)throw Error("Operands could not be broadcast together with shapes "+A+" and "+g+".");B.unshift(C)}}return B}function TC(A,g,B,Q,w,C,E){E===void 0&&(E="channelsLast");var e,I=Ye(g),o=I[0],n=I[1];if(E==="channelsLast")e=[o,n,A[3],A[3]];else{if(E!=="channelsFirst")throw new Error("Unknown dataFormat "+E);e=[o,n,A[1],A[1]]}return Cw(A,e,B,Q,w,C,!1,E)}function ne(A,g,B,Q,w,C,E){E===void 0&&(E="NDHWC");var e,I,o=wt(g),n=o[0],i=o[1],Y=o[2];if(E==="NDHWC")I="channelsLast",e=[n,i,Y,A[4],A[4]];else{if(E!=="NCDHW")throw new Error("Unknown dataFormat "+E);I="channelsFirst",e=[n,i,Y,A[1],A[1]]}return ie(A,e,B,Q,w,!1,I,C)}function Cw(A,g,B,Q,w,C,E,e){E===void 0&&(E=!1),e===void 0&&(e="channelsLast");var I=[-1,-1,-1,-1],o=I[0],n=I[1],i=I[2],Y=I[3];if(e==="channelsLast")o=A[0],n=A[1],i=A[2],Y=A[3];else{if(e!=="channelsFirst")throw new Error("Unknown dataFormat "+e);o=A[0],Y=A[1],n=A[2],i=A[3]}var M,c=g[0],D=g[1],r=g[3],F=Ye(B),s=F[0],u=F[1],a=Ye(Q),U=a[0],G=a[1],d=Sw(c,U),H=Sw(D,G),h=function(N,v,y,k,p,K,V,T){var j,X,gA;if(typeof N=="number"){j={top:N,bottom:N,left:N,right:N,type:N===0?"VALID":"NUMBER"};var CA=function(oA,aA,JA,VA,bA){VA==null&&(VA=uc(oA,aA,JA));var pA=oA[0],ZA=oA[1],CB=jC((pA-aA+2*VA)/JA+1,bA);R(JB(CB),function(){return"The output # of rows ("+CB+") must be an integer. Change the stride and/or zero pad parameters"});var rB=jC((ZA-aA+2*VA)/JA+1,bA);return R(JB(rB),function(){return"The output # of columns ("+rB+") must be an integer. Change the stride and/or zero pad parameters"}),[CB,rB]}([v,y],K,k,N,T);X=CA[0],gA=CA[1]}else if(N==="same"){X=Math.ceil(v/k),gA=Math.ceil(y/p);var wA=Math.max(0,(X-1)*k+K-v),eA=Math.max(0,(gA-1)*p+V-y),YA=Math.floor(wA/2),$=wA-YA,RA=Math.floor(eA/2);j={top:YA,bottom:$,left:RA,right:eA-RA,type:"SAME"}}else{if(N!=="valid")throw Error("Unknown padding parameter: "+N);j={top:0,bottom:0,left:0,right:0,type:"VALID"},X=Math.ceil((v-K+1)/k),gA=Math.ceil((y-V+1)/p)}return{padInfo:j,outHeight:X,outWidth:gA}}(w,n,i,s,u,d,H,C),l=h.padInfo,m=h.outHeight,f=h.outWidth,W=E?r*Y:r;return e==="channelsFirst"?M=[o,W,m,f]:e==="channelsLast"&&(M=[o,m,f,W]),{batchSize:o,dataFormat:e,inHeight:n,inWidth:i,inChannels:Y,outHeight:m,outWidth:f,outChannels:W,padInfo:l,strideHeight:s,strideWidth:u,filterHeight:c,filterWidth:D,effectiveFilterHeight:d,effectiveFilterWidth:H,dilationHeight:U,dilationWidth:G,inShape:A,outShape:M,filterShape:g}}function ie(A,g,B,Q,w,C,E,e){C===void 0&&(C=!1),E===void 0&&(E="channelsLast");var I=[-1,-1,-1,-1,-1],o=I[0],n=I[1],i=I[2],Y=I[3],M=I[4];if(E==="channelsLast")o=A[0],n=A[1],i=A[2],Y=A[3],M=A[4];else{if(E!=="channelsFirst")throw new Error("Unknown dataFormat "+E);o=A[0],M=A[1],n=A[2],i=A[3],Y=A[4]}var c,D=g[0],r=g[1],F=g[2],s=g[4],u=wt(B),a=u[0],U=u[1],G=u[2],d=wt(Q),H=d[0],h=d[1],l=d[2],m=Sw(D,H),f=Sw(r,h),W=Sw(F,l),N=function(V,T,j,X,gA,CA,wA,eA,YA,$,RA){var oA,aA,JA,VA;if(typeof V=="number"){oA={top:V,bottom:V,left:V,right:V,front:V,back:V,type:V===0?"VALID":"NUMBER"};var bA=function(aB,vB,ag,hB,kB,mg){kB==null&&(kB=uc(aB,vB,hB));var SB=aB[0],AA=aB[1],IA=aB[2],NA=jC((SB-vB+2*kB)/hB+1,mg);R(JB(NA),function(){return"The output # of depths ("+NA+") must be an integer. Change the stride and/or zero pad parameters"});var TA=jC((AA-vB+2*kB)/hB+1,mg);R(JB(TA),function(){return"The output # of rows ("+TA+") must be an integer. Change the stride and/or zero pad parameters"});var AB=jC((IA-vB+2*kB)/hB+1,mg);return R(JB(AB),function(){return"The output # of columns ("+AB+") must be an integer. Change the stride and/or zero pad parameters"}),[NA,TA,AB,ag]}([T,j,X,1],eA,1,gA,V,RA);aA=bA[0],JA=bA[1],VA=bA[2]}else if(V==="same"){aA=Math.ceil(T/gA),JA=Math.ceil(j/CA),VA=Math.ceil(X/wA);var pA=(aA-1)*gA+eA-T,ZA=(JA-1)*CA+YA-j,CB=(VA-1)*wA+$-X,rB=Math.floor(pA/2),FB=pA-rB,QA=Math.floor(ZA/2),rA=ZA-QA,xA=Math.floor(CB/2);oA={top:QA,bottom:rA,left:xA,right:CB-xA,front:rB,back:FB,type:"SAME"}}else{if(V!=="valid")throw Error("Unknown padding parameter: "+V);oA={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},aA=Math.ceil((T-eA+1)/gA),JA=Math.ceil((j-YA+1)/CA),VA=Math.ceil((X-$+1)/wA)}return{padInfo:oA,outDepth:aA,outHeight:JA,outWidth:VA}}(w,n,i,Y,a,U,G,m,f,W,e),v=N.padInfo,y=N.outDepth,k=N.outHeight,p=N.outWidth,K=C?s*M:s;return E==="channelsFirst"?c=[o,K,y,k,p]:E==="channelsLast"&&(c=[o,y,k,p,K]),{batchSize:o,dataFormat:E,inDepth:n,inHeight:i,inWidth:Y,inChannels:M,outDepth:y,outHeight:k,outWidth:p,outChannels:K,padInfo:v,strideDepth:a,strideHeight:U,strideWidth:G,filterDepth:D,filterHeight:r,filterWidth:F,effectiveFilterDepth:m,effectiveFilterHeight:f,effectiveFilterWidth:W,dilationDepth:H,dilationHeight:h,dilationWidth:l,inShape:A,outShape:c,filterShape:g}}function uc(A,g,B,Q){Q===void 0&&(Q=1);var w=Sw(g,Q);return Math.floor((A[0]*(B-1)-B+w)/2)}function Ye(A){return typeof A=="number"?[A,A,A]:A.length===2?[A[0],A[1],1]:A}function wt(A){return typeof A=="number"?[A,A,A]:A}function Sw(A,g){return g<=1?A:A+(A-1)*(g-1)}function jC(A,g){if(!g)return A;switch(g){case"round":return Math.round(A);case"ceil":return Math.ceil(A);case"floor":return Math.floor(A);default:throw new Error("Unknown roundingMode "+g)}}function Lw(A){var g=Ye(A),B=g[0],Q=g[1],w=g[2];return B===1&&Q===1&&w===1}function rg(A,g){return Lw(A)||Lw(g)}function Ct(A){if(A==="NHWC")return"channelsLast";if(A==="NCHW")return"channelsFirst";throw new Error("Unknown dataFormat "+A)}function Uc(A,g,B){if(g==="complex64"){if(A.dtype==="complex64")return A.clone();var Q=DB(A.shape),w=A.toFloat(),C=B.complex(w,Q);return Q.dispose(),w.dispose(),C}if(!kd(A.dtype,g))return b.makeTensorFromDataId(A.dataId,A.shape,g);if(A.dtype==="complex64"){var E=B.real(A);return C=E.cast(g),E.dispose(),C}if(g==="int32")return B.int(A);if(g==="bool"){var e=nA(0,A.dtype);return C=B.notEqual(A,e),e.dispose(),C}throw new Error("Error in Cast: failed to cast "+A.dtype+" to "+g)}function Et(A,g){return b.makeTensorFromDataId(A.dataId,g,A.dtype)}function Gc(A,g,B){var Q=(g-A)/(B-1),w=fC(B,"float32");w[0]=A;for(var C=1;C<w.length;C++)w[C]=w[C-1]+Q;return PB(w,"float32")}function et(A,g){if(A.length!==g.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+A.length+", imag: "+g.length+".");for(var B=new Float32Array(2*A.length),Q=0;Q<B.length;Q+=2)B[Q]=A[Q/2],B[Q+1]=g[Q/2];return B}function hc(A,g){return{real:A[2*g],imag:A[2*g+1]}}function of(A,g,B,Q){A[2*Q]=g,A[2*Q+1]=B}function tf(A,g,B){var Q=(B?2:-2)*Math.PI*(A/g);return{real:Math.cos(Q),imag:Math.sin(Q)}}function nf(A,g,B){var Q=function(C,E,e){return function(I,o,n){for(var i=0,Y=I.length,M=0,c=!1;i<Y;){var D=n(o,I[M=i+(Y-i>>>1)]);D>0?i=M+1:(Y=M,c=!D)}return c?i:-i-1}(C,E,e||Yf)}(A,g,B),w=Q<0?-(Q+1):Q;A.splice(w,0,g)}function Yf(A,g){return A>g?1:A<g?-1:0}function It(A,g,B,Q,w){return lc(A,g,B,Q,w,0).selectedIndices}function ot(A,g,B,Q,w,C){var E=lc(A,g,B,Q,w,C);return E.numValidOutputs.dispose(),{selectedIndices:E.selectedIndices,selectedScores:E.selectedScores}}function lc(A,g,B,Q,w,C,E,e){e===void 0&&(e=!1);for(var I=Array.from(g).map(function(a,U){return{score:a,boxIndex:U,suppressBeginIndex:0}}).filter(function(a){return a.score>w}).sort(dc),o=C>0?-.5/C:0,n=[],i=[];n.length<B&&I.length>0;){var Y=I.pop(),M=Y.score,c=Y.boxIndex,D=Y.suppressBeginIndex;if(M<w)break;for(var r=!1,F=n.length-1;F>=D;--F){var s=Mf(A,c,n[F]);if(s>=Q){r=!0;break}if(Y.score=Y.score*cf(Q,o,s),Y.score<=w)break}Y.suppressBeginIndex=n.length,r||(Y.score===M?(n.push(c),i.push(Y.score)):Y.score>w&&nf(I,Y,dc))}var u=n.length;return e&&(n.fill(0,u),i.fill(0,u)),{selectedIndices:PB(n,"int32"),selectedScores:PB(i,"float32"),numValidOutputs:nA(u,"int32")}}function Mf(A,g,B){var Q=A.subarray(4*g,4*g+4),w=A.subarray(4*B,4*B+4),C=Math.min(Q[0],Q[2]),E=Math.min(Q[1],Q[3]),e=Math.max(Q[0],Q[2]),I=Math.max(Q[1],Q[3]),o=Math.min(w[0],w[2]),n=Math.min(w[1],w[3]),i=Math.max(w[0],w[2]),Y=Math.max(w[1],w[3]),M=(e-C)*(I-E),c=(i-o)*(Y-n);if(M<=0||c<=0)return 0;var D=Math.max(C,o),r=Math.max(E,n),F=Math.min(e,i),s=Math.min(I,Y),u=Math.max(F-D,0)*Math.max(s-r,0);return u/(M+c-u)}function cf(A,g,B){var Q=Math.exp(g*B*B);return B<=A?Q:0}function dc(A,g){return A.score-g.score||A.score===g.score&&g.boxIndex-A.boxIndex}function Hc(A,g,B){var Q=new Array(A.rank).fill(0),w=A.shape.slice();return g.map(function(C){w[B]=C;var E=A.slice(Q,w);return Q[B]+=C,E})}function fc(A,g){for(var B=new Array(A.rank),Q=0;Q<B.length;Q++)B[Q]=A.shape[Q]*g[Q];var w=zA(B,A.dtype);for(Q=0;Q<w.values.length;++Q){for(var C=w.indexToLoc(Q),E=new Array(A.rank),e=0;e<E.length;e++)E[e]=C[e]%A.shape[e];var I=A.locToIndex(E);w.values[Q]=A.values[I]}return w.toTensor()}function Jc(A,g,B,Q,w){for(var C=g[g.length-1],E=[A.length/C,C],e=E[0],I=E[1],o=dC(B,e*Q),n=dC("int32",e*Q),i=0;i<e;i++){for(var Y=i*I,M=A.subarray(Y,Y+I),c=[],D=0;D<M.length;D++)c.push({value:M[D],index:D});c.sort(function(a,U){return U.value-a.value});var r=i*Q,F=o.subarray(r,r+Q),s=n.subarray(r,r+Q);for(D=0;D<Q;D++)F[D]=c[D].value,s[D]=c[D].index}var u=g.slice();return u[u.length-1]=Q,[Ag(o,u,B),Ag(n,u,"int32")]}function tt(A,g){for(var B=[],Q=0;Q<g.length;Q++)g[Q]&&B.push(Q);var w=zA(A,"int32"),C=zA([B.length,A.length],"int32");for(Q=0;Q<B.length;Q++){var E=w.indexToLoc(B[Q]),e=Q*A.length;C.values.set(E,e)}return C.toTensor()}var Df=function(A,g){this.outputShape=[],this.outputShape=A,this.variableNames=g.map(function(w,C){return"T"+C});var B=[];this.variableNames.forEach(function(w){B.push("float v"+w+" = get"+w+"AtOutCoords();")});var Q=this.variableNames.map(function(w){return"v"+w}).join(" + ");this.userCode=`
35
+ `+Q.shape}),R(E%(g*g)==0,function(){return"Dimension size must be evenly divisible by "+g*g+" but is "+E+" for depthToSpace with input shape "+Q.shape}),b.runKernelFunc(function(e){return e.depthToSpace(Q,g,B)},{$x:Q})}}),Tg=z({expandDims_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","expandDims",null);R(g<=B.rank,function(){return"Axis must be <= rank of the tensor"});var Q=B.shape.slice();return g<0&&(R(-(B.rank+1)<=g,function(){return"Axis must be in the interval ["+-(B.rank+1)+", "+B.rank+"]"}),g=B.rank+g+1),Q.splice(g,0,1),Sg(B,Q)}}),Ic=z({eye_:function(A,g,B,Q){Q===void 0&&(Q="float32"),g==null&&(g=A);for(var w=zA([A,g],Q),C=A<=g?A:g,E=0;E<C;++E)w.set(1,E,E);var e=w.toTensor().as2D(A,g);if(B==null)return e;if(B.length===1)return Ww(Tg(e,0),[B[0],1,1]);if(B.length===2)return Ww(Tg(Tg(e,0),0),[B[0],B[1],1,1]);if(B.length===3)return Ww(Tg(Tg(Tg(e,0),0),0),[B[0],B[1],B[2],1,1]);throw new Error("eye() currently supports only 1D and 2D batchShapes, but received "+B.length+"D.")}}),XH=z({multinomial_:function(A,g,B,Q){Q===void 0&&(Q=!1);var w=J(A,"logits","multinomial"),C=w.size,E=w.rank;if(C<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+C+".");if(E>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+E);B=B||Math.random();var e=E===1?w.as2D(1,-1):w,I=b.runKernelFunc(function(o){return o.multinomial(e,Q,g,B)},{logits2D:e});return E===1?I.as1D():I}}),gt=z({oneHot_:function(A,g,B,Q){if(B===void 0&&(B=1),Q===void 0&&(Q=0),g<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+g);var w=J(A,"indices","oneHot","int32"),C=w.shape.concat([g]);return w=w.flatten(),b.runKernelFunc(function(E){return E.oneHot(w,g,B,Q)},{$indices:w},function(E){return{$indices:function(){return DB(w.shape,"float32")}}}).reshape(C)}}),ww=z({pad_:function(A,g,B){B===void 0&&(B=0);var Q=J(A,"x","pad");if(Q.rank===0)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var w={paddings:g,constantValue:B};return b.runKernelFunc(function(C){return C.pad(Q,g,B)},{x:Q},function(C){var E=g.map(function(e){return e[0]});return{x:function(){return C.slice(E,Q.shape)}}},"PadV2",w)}}),OH=z({pad1d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===2,function(){return"Invalid number of paddings. Must be length of 2."}),ww(A,[g],B)}}),ZH=z({pad2d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===2&&g[0].length===2&&g[1].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),qH=z({pad3d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===3&&g[0].length===2&&g[1].length===2&&g[2].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),_H=z({pad4d_:function(A,g,B){return B===void 0&&(B=0),R(g.length===4&&g[0].length===2&&g[1].length===2&&g[2].length===2&&g[3].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),ww(A,g,B)}}),$H=z({rand_:function(A,g,B){var Q=hA(A),w=null;if(B==null||B==="float32")w=new Float32Array(Q);else if(B==="int32")w=new Int32Array(Q);else{if(B!=="bool")throw new Error("Unknown data type "+B);w=new Uint8Array(Q)}for(var C=0;C<Q;C++)w[C]=g();return b.makeTensor(w,A,B)}}),Af=z({randomNormal_:function(A,g,B,Q,w){if(g===void 0&&(g=0),B===void 0&&(B=1),Q!=null&&Q==="bool")throw new Error("Unsupported data type "+Q);for(var C=new Bt(g,B,Q,!1,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),Bf=z({randomGamma_:function(A,g,B,Q,w){if(B===void 0&&(B=1),Q===void 0&&(Q="float32"),B==null&&(B=1),Q==null&&(Q="float32"),Q!=="float32"&&Q!=="int32")throw new Error("Unsupported data type "+Q);for(var C=new zH(g,B,Q,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),oc=z({randomUniform_:function(A,g,B,Q,w){g===void 0&&(g=0),B===void 0&&(B=1),Q===void 0&&(Q="float32");for(var C=zA(A,Q),E=new WH(g,B,null,w),e=0;e<C.values.length;e++)C.values[e]=E.nextValue();return C.toTensor()}}),Sg=z({reshape_:function(A,g){var B=J(A,"x","reshape",null);g=vd(g,B.size),R(B.size===hA(g),function(){return"new shape and old shape must have the same number of elements."});var Q={shape:g};return b.runKernelFunc(function(w){return w.reshape(B,g)},{x:B},function(w){return{x:function(){return w.reshape(B.shape)}}},"Reshape",Q)}}),tc=z({spaceToBatchND_:function(A,g,B){var Q=J(A,"x","spaceToBatchND");return R(Q.rank>=1+g.length,function(){return"input rank "+Q.rank+" should be > than [blockShape] "+g.length}),R(B.length===g.length,function(){return"paddings.shape[0] "+B.length+" must be equal to [blockShape] "+g.length}),R(Q.shape.reduce(function(w,C,E){return E>0&&E<=g.length?w&&(C+B[E-1][0]+B[E-1][1])%g[E-1]==0:w},!0),function(){return"input spatial dimensions "+Q.shape.slice(1)+" with paddings "+B.toString()+" must be divisible by blockShapes "+g.toString()}),b.runKernelFunc(function(w){return w.spaceToBatchND(Q,g,B)},{$x:Q},function(w){return{$x:function(){return w.batchToSpaceND(g,B)}}})}}),nc=z({squeeze_:function(A,g){var B=J(A,"x","squeeze");return Sg(B,Aw(B.shape,g).newShape)}}),Hg=z({stack_:function(A,g){g===void 0&&(g=0);var B=Qe(A,"tensors","stack");if(R(B.length>=1,function(){return"Pass at least one tensor to tf.stack"}),B.length===1)return B[0].expandDims(g);var Q=B[0].rank,w=B[0].shape,C=B[0].dtype;R(g<=Q,function(){return"Axis must be <= rank of the tensor"}),B.forEach(function(e){eB(w,e.shape,"All tensors passed to stack must have matching shapes")}),B.forEach(function(e){R(C===e.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var E=B.map(function(e){return e.expandDims(g)});return jB(E,g)}}),Ww=z({tile_:function(A,g){var B=J(A,"x","tile",null);R(B.rank===g.length,function(){return"Error in transpose: rank of input "+B.rank+" must match length of reps "+g+"."});var Q=[B],w={reps:g};return b.runKernelFunc(function(C,E){var e=C.tile(B,g);return E([B]),e},{x:B},function(C,E){var e=E[0];return{x:function(){var I=$A(e);if(e.rank===1)for(var o=0;o<g[0];++o)I=I.add(C.slice([o*e.shape[0]],[e.shape[0]]));else if(e.rank===2)for(o=0;o<g[0];++o)for(var n=0;n<g[1];++n)I=I.add(C.slice([o*e.shape[0],n*e.shape[1]],[e.shape[0],e.shape[1]]));else if(e.rank===3)for(o=0;o<g[0];++o)for(n=0;n<g[1];++n)for(var i=0;i<g[2];++i)I=I.add(C.slice([o*e.shape[0],n*e.shape[1],i*e.shape[2]],[e.shape[0],e.shape[1],e.shape[2]]));else{if(e.rank!==4)throw new Error("Gradient for tile operation is not implemented for rank-"+e.rank+" tensors yet.");for(o=0;o<g[0];++o)for(n=0;n<g[1];++n)for(i=0;i<g[2];++i)for(var Y=0;Y<g[3];++Y)I=I.add(C.slice([o*e.shape[0],n*e.shape[1],i*e.shape[2],Y*e.shape[3]],[e.shape[0],e.shape[1],e.shape[2],e.shape[3]]))}return I}}},"Tile",w,Q)}}),gf=z({truncatedNormal_:function(A,g,B,Q,w){if(g===void 0&&(g=0),B===void 0&&(B=1),Q!=null&&Q==="bool")throw new Error("Unsupported data type "+Q);for(var C=new Bt(g,B,Q,!0,w),E=zA(A,Q),e=0;e<E.values.length;e++)E.values[e]=C.nextValue();return E.toTensor()}}),pB=z({unstack_:function(A,g){g===void 0&&(g=0),g=g||0;var B=J(A,"x","unstack");R(g>=-B.shape.length&&g<B.shape.length,function(){return"Axis = "+g+" is not in [-"+B.shape.length+", "+B.shape.length+")"}),g<0&&(g+=B.shape.length);var Q={axis:g};return b.runKernelFunc(function(w){return w.unstack(B,g)},{x:B},function(w){return{x:function(){return Hg(w,g)}}},"Unpack",Q)}}),Qf=function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return B=J(A,"x","setdiff1d"),Q=J(g,"y","setdiff1d"),R(B.dtype===Q.dtype,function(){return"x and y should have the same dtype, but got x ("+B.dtype+") and y ("+Q.dtype+")."}),R(B.rank===1,function(){return"x should be 1D tensor, but got x ("+B.shape+")."}),R(Q.rank===1,function(){return"y should be 1D tensor, but got y ("+Q.shape+")."}),[4,B.data()];case 1:return w=Y.sent(),[4,Q.data()];case 2:for(C=Y.sent(),E=new Set(C),e=0,n=0;n<w.length;n++)E.has(w[n])||e++;for(I=new RC([e],B.dtype),o=new RC([e],"int32"),n=0,i=0;n<w.length;n++)E.has(w[n])||(I.values[i]=w[n],o.values[i]=n,i++);return[2,[I.toTensor(),o.toTensor()]]}})})};function Ee(A,g,B,Q){Q===void 0&&(Q=!0);var w=[];if(Q)(w=w.concat(g.slice(0))).push(A[0]/B),w=w.concat(A.slice(1));else{w=w.concat(A[0]);for(var C=g.length,E=0;E<C;++E)w=w.concat([A[E+1]/g[E],g[E]]);w=w.concat(A.slice(C+1))}return w}function ee(A,g,B){B===void 0&&(B=!0);var Q=[];if(B){Q.push(g);for(var w=g+1;w<A;++w)w<=2*g?(Q.push(w),Q.push(w-(g+1))):Q.push(w)}else{var C=[],E=[];for(w=1;w<A;++w)w>=2*g+1||w%2==1?E.push(w):C.push(w);Q.push.apply(Q,C),Q.push(0),Q.push.apply(Q,E)}return Q}function Ie(A,g,B,Q){Q===void 0&&(Q=!0);var w=[];Q?w.push(A[0]/B):w.push(A[0]*B);for(var C=1;C<A.length;++C)C<=g.length?Q?w.push(g[C-1]*A[C]):w.push(A[C]/g[C-1]):w.push(A[C]);return w}function ic(A,g){for(var B=[0],Q=0;Q<g;++Q)B.push(A[Q][0]);return B}function Yc(A,g,B){for(var Q=A.slice(0,1),w=0;w<B;++w)Q.push(A[w+1]-g[w][0]-g[w][1]);return Q}function Mc(A,g){if(A.rank<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was "+A.rank+".");if(g.rank<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was "+g.rank+".");if(g.dtype!=="int32")throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was "+g.dtype+".");if(g.shape[g.rank-1]>A.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+g.shape[g.rank-1]+" vs. "+A.rank);if(A.size===0)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+A.shape+".");for(var B=g.shape,Q=B[B.length-1],w=1,C=0;C<B.length-1;++C)w*=B[C];var E=A.shape,e=B.slice();e.pop();var I=1;for(C=Q;C<A.rank;++C)I*=E[C],e.push(E[C]);var o=Og(A.shape).map(function(n){return n/I}).concat([1]).slice(0,Q);return[e,w,I,o]}var cc=30;function Qt(A){return A<=cc?A:To(A,Math.floor(Math.sqrt(A)))}function wf(A,g,B){var Q=g.rank>1?g.shape[g.rank-1]:1,w=g.rank>1?g.rank-1:1,C="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+B.shape+", indices.shape: "+g.shape+", shape: "+A+", sliceDim: "+Q+", and batchDim: "+w+".";if(B.rank<w)throw new Error(C+" update.rank < "+w+". ");if(A.length<Q+(B.rank-w))throw new Error(C+" Output shape length < "+(Q+(B.rank-w)));if(B.rank!==w+A.length-Q)throw new Error(C+" update.rank != "+(w+A.length-Q));for(var E=0;E<w;++E)if(B.shape[E]!==g.shape[E])throw new Error(C+" updates.shape["+E+"] ("+B.shape[E]+") != indices.shape["+E+"] ("+g.shape[E]+").");for(E=0;E<B.rank-w;++E)if(B.shape[E+w]!==A[E+Q])throw new Error(C+" updates.shape["+(E+w)+"] ("+B.shape[E+w]+") != shape["+(E+w)+"] ("+A[E+w]+")")}function Cf(A,g,B){if(g.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was "+g.rank+".");if(A.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was "+A.rank+".");if(g.dtype!=="int32")throw new Error("The dtype of 'indices' should be int32, but got dtype: "+g.dtype);if(B.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+B);if(B.length===0){if(g.size===0)throw new Error("Indices specified for empty output. indices shape: "+g.shape);if(A.size===0)throw new Error("Updates specified for empty output. updates shape: "+A.shape)}wf(B,g,A)}function oe(A,g,B){for(var Q=g.shape.length,w=Q>1?g.shape[Q-1]:1,C=B.length,E=1,e=w;e<C;++e)E*=B[e];var I=w<1?1:w;return{sliceRank:w,numUpdates:hA(g.shape)/I,sliceSize:E,strides:Og(B.slice(0,w)).concat([1]),outputSize:hA(B)}}function Ef(A,g,B){R(A.rank===g.length,function(){return"Error in slice"+A.rank+"D: Length of begin "+g+" must match the rank of the array ("+A.rank+")."}),R(A.rank===B.length,function(){return"Error in slice"+A.rank+"D: Length of size "+B+" must match the rank of the array ("+A.rank+")."});for(var Q=function(C){R(g[C]+B[C]<=A.shape[C],function(){return"Error in slice"+A.rank+"D: begin["+C+"] + size["+C+"] ("+(g[C]+B[C])+") would overflow input.shape["+C+"] ("+A.shape[C]+")"})},w=0;w<A.rank;++w)Q(w)}function Dc(A){for(var g=[],B=0;A>0;)1&A&&g.push(B),A/=2,B++;return g}function wt(A,g,B){for(var Q=[],w=0;w<A.length;w++)Q[w]=Math.ceil((g[w]-A[w])/B[w]);return Q}function ef(A,g,B,Q,w){var C=g[w],E=B[w]||1;(A&1<<w||C==null)&&(C=E>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var e=Q[w];return C<0&&(C+=e),C=Ro(0,C,e-1)}function If(A,g,B,Q,w){var C=g[w],E=B[w]||1;(A&1<<w||C==null)&&(C=E>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var e=Q[w];return C<0&&(C+=e),C=E>0?Ro(0,C,e):Ro(-1,C,e-1)}function rc(A,g,B){for(var Q=B.length,w=0;w<B.length;w++)if(B[w]>1){Q=w;break}for(w=Q+1;w<B.length;w++)if(g[w]>0||B[w]!==A[w])return!1;return!0}function Fc(A,g){for(var B=A.length>0?A[A.length-1]:1,Q=0;Q<A.length-1;Q++)B+=A[Q]*g[Q];return B}function of(A,g){R(ko(A),function(){return"The f passed in variableGrads(f) must be a function"}),R(g==null||Array.isArray(g)&&g.every(function(n){return n instanceof pw}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var B=g!=null;if(!B)for(var Q in g=[],b.registeredVariables)g.push(b.registeredVariables[Q]);var w=B?g.filter(function(n){return!n.trainable}):null,C=g.length;R((g=g.filter(function(n){return n.trainable})).length>0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+C+" variables is trainable."});var E=b.gradients(A,g,null,!0),e=E.value,I=E.grads;R(I.some(function(n){return n!=null}),function(){return"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()."}),R(e.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+e.rank+" tensor"});var o={};return g.forEach(function(n,i){I[i]!=null&&(o[n.name]=I[i])}),w!=null&&w.forEach(function(n){return o[n.name]=null}),{value:e,grads:o}}function te(A){return b.customGrad(A)}var rQ=z({softmax_:function(A,g){g===void 0&&(g=-1);var B=J(A,"logits","softmax","float32");if(g===-1&&(g=B.rank-1),g!==B.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+B.rank+" and dim was "+g);return b.runKernelFunc(function(Q,w){var C=Q.softmax(B,g);return w([C]),C},{logits:B},function(Q,w){var C=w[0],E=Q.mul(C);return{logits:function(){return E.sub(E.sum([g],!0).mul(C))}}},"Softmax",{dim:g},[],[!0])}}),tf=z({logSoftmax_:function(A,g){g===void 0&&(g=-1);var B=J(A,"logits","logSoftmax");if(g===-1&&(g=B.rank-1),g!==B.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+B.rank+" and axis was "+g);return te(function(Q,w){var C=Q.max(g,!0),E=Q.sub(C),e=E.toFloat().sub(E.exp().sum(g,!0).log());return w([e]),{value:e,gradFunc:function(I,o){var n=o[0].exp();return I.sub(I.sum(g,!0).mul(n))}}})(B)}}),ac=function(){function A(g,B){this.backend=g,this.dataMover=B,this.data=new WeakMap,this.dataIdsCount=0}return A.prototype.get=function(g){return this.data.has(g)||this.dataMover.moveData(this.backend,g),this.data.get(g)},A.prototype.set=function(g,B){this.dataIdsCount++,this.data.set(g,B)},A.prototype.has=function(g){return this.data.has(g)},A.prototype.delete=function(g){return this.dataIdsCount--,this.data.delete(g)},A.prototype.numDataIds=function(){return this.dataIdsCount},A}(),sc=function(){function A(){}return A.prototype.time=function(g){return x("time")},A.prototype.read=function(g){return x("read")},A.prototype.readSync=function(g){return x("readSync")},A.prototype.numDataIds=function(){return x("numDataIds")},A.prototype.disposeData=function(g){return x("disposeData")},A.prototype.write=function(g,B,Q){return x("write")},A.prototype.move=function(g,B,Q,w){return x("move")},A.prototype.memory=function(){return x("memory")},A.prototype.floatPrecision=function(){return x("floatPrecision")},A.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},A.prototype.batchMatMul=function(g,B,Q,w){return x("batchMatMul")},A.prototype.fusedBatchMatMul=function(g){return g.a,g.b,g.transposeA,g.transposeB,g.bias,g.activation,g.preluActivationWeights,x("fusedBatchMatMul")},A.prototype.slice=function(g,B,Q){return x("slice")},A.prototype.stridedSlice=function(g,B,Q,w){return x("stridedSlice")},A.prototype.unstack=function(g,B){return x("unstack")},A.prototype.reverse=function(g,B){return x("reverse")},A.prototype.concat=function(g,B){return x("concat")},A.prototype.neg=function(g){return x("neg")},A.prototype.add=function(g,B){return x("add")},A.prototype.addN=function(g){return x("addN")},A.prototype.subtract=function(g,B){return x("subtract")},A.prototype.multiply=function(g,B){return x("multiply")},A.prototype.realDivide=function(g,B){return x("realDivide")},A.prototype.floorDiv=function(g,B){return x("floorDiv")},A.prototype.sum=function(g,B){return x("sum")},A.prototype.prod=function(g,B){return x("prod")},A.prototype.unsortedSegmentSum=function(g,B,Q){return x("unsortedSegmentSum")},A.prototype.argMin=function(g,B){return x("argMin")},A.prototype.argMax=function(g,B){return x("argMax")},A.prototype.equal=function(g,B){return x("equal")},A.prototype.notEqual=function(g,B){return x("notEqual")},A.prototype.less=function(g,B){return x("less")},A.prototype.lessEqual=function(g,B){return x("lessEqual")},A.prototype.greater=function(g,B){return x("greater")},A.prototype.greaterEqual=function(g,B){return x("greaterEqual")},A.prototype.logicalNot=function(g){return x("logicalNot")},A.prototype.logicalAnd=function(g,B){return x("logicalAnd")},A.prototype.logicalOr=function(g,B){return x("logicalOr")},A.prototype.where=function(g){return x("where")},A.prototype.select=function(g,B,Q){return x("select")},A.prototype.topk=function(g,B,Q){return x("topk")},A.prototype.min=function(g,B){return x("min")},A.prototype.minimum=function(g,B){return x("minimum")},A.prototype.mod=function(g,B){return x("mod")},A.prototype.max=function(g,B){return x("max")},A.prototype.maximum=function(g,B){return x("maximum")},A.prototype.all=function(g,B){return x("all")},A.prototype.any=function(g,B){return x("any")},A.prototype.squaredDifference=function(g,B){return x("squaredDifference")},A.prototype.ceil=function(g){return x("ceil")},A.prototype.floor=function(g){return x("floor")},A.prototype.round=function(g){return x("round")},A.prototype.sign=function(g){return x("sign")},A.prototype.isNaN=function(g){return x("isNaN")},A.prototype.isInf=function(g){return x("isInf")},A.prototype.isFinite=function(g){return x("isFinite")},A.prototype.pow=function(g,B){return x("pow")},A.prototype.exp=function(g){return x("exp")},A.prototype.expm1=function(g){return x("expm1")},A.prototype.softmax=function(g,B){return x("softmax")},A.prototype.log=function(g){return x("log")},A.prototype.log1p=function(g){return x("log1p")},A.prototype.sqrt=function(g){return x("sqrt")},A.prototype.rsqrt=function(g){return x("rsqrt")},A.prototype.square=function(g){return x("square")},A.prototype.reciprocal=function(g){return x("reciprocal")},A.prototype.relu=function(g){return x("relu")},A.prototype.relu6=function(g){return x("relu6")},A.prototype.prelu=function(g,B){return x("prelu")},A.prototype.elu=function(g){return x("elu")},A.prototype.eluDer=function(g,B){return x("eluDer")},A.prototype.selu=function(g){return x("selu")},A.prototype.int=function(g){return x("int")},A.prototype.clip=function(g,B,Q){return x("clip")},A.prototype.abs=function(g){return x("abs")},A.prototype.complexAbs=function(g){return x("complexAbs")},A.prototype.sigmoid=function(g){return x("sigmoid")},A.prototype.softplus=function(g){return x("softplus")},A.prototype.sin=function(g){return x("sin")},A.prototype.cos=function(g){return x("cos")},A.prototype.tan=function(g){return x("tan")},A.prototype.asin=function(g){return x("asin")},A.prototype.acos=function(g){return x("acos")},A.prototype.atan=function(g){return x("atan")},A.prototype.atan2=function(g,B){return x("atan2")},A.prototype.sinh=function(g){return x("sinh")},A.prototype.cosh=function(g){return x("cosh")},A.prototype.tanh=function(g){return x("tanh")},A.prototype.asinh=function(g){return x("asinh")},A.prototype.acosh=function(g){return x("acosh")},A.prototype.atanh=function(g){return x("atanh")},A.prototype.erf=function(g){return x("erf")},A.prototype.step=function(g,B){return x("step")},A.prototype.fusedConv2d=function(g){return g.input,g.filter,g.convInfo,g.bias,g.activation,g.preluActivationWeights,x("fusedConv2d")},A.prototype.conv2d=function(g,B,Q){return x("conv2d")},A.prototype.conv2dDerInput=function(g,B,Q){return x("conv2dDerInput")},A.prototype.conv2dDerFilter=function(g,B,Q){return x("conv2dDerFilter")},A.prototype.fusedDepthwiseConv2D=function(g){return g.input,g.filter,g.convInfo,g.bias,g.activation,g.preluActivationWeights,x("fusedDepthwiseConv2D")},A.prototype.depthwiseConv2D=function(g,B,Q){return x("depthwiseConv2D")},A.prototype.depthwiseConv2DDerInput=function(g,B,Q){return x("depthwiseConv2DDerInput")},A.prototype.depthwiseConv2DDerFilter=function(g,B,Q){return x("depthwiseConv2DDerFilter")},A.prototype.conv3d=function(g,B,Q){return x("conv3d")},A.prototype.conv3dDerInput=function(g,B,Q){return x("conv3dDerInput")},A.prototype.conv3dDerFilter=function(g,B,Q){return x("conv3dDerFilter")},A.prototype.maxPool=function(g,B){return x("maxPool")},A.prototype.maxPoolBackprop=function(g,B,Q,w){return x("maxPoolBackprop")},A.prototype.avgPool=function(g,B){return x("avgPool")},A.prototype.avgPoolBackprop=function(g,B,Q){return x("avgPoolBackprop")},A.prototype.avgPool3d=function(g,B){return x("avgPool3d")},A.prototype.avgPool3dBackprop=function(g,B,Q){return x("avgPool3dBackprop")},A.prototype.maxPool3d=function(g,B){return x("maxPool3d")},A.prototype.maxPool3dBackprop=function(g,B,Q,w){return x("maxPool3dBackprop")},A.prototype.reshape=function(g,B){return x("reshape")},A.prototype.cast=function(g,B){return x("cast")},A.prototype.tile=function(g,B){return x("tile")},A.prototype.pad=function(g,B,Q){return x("pad")},A.prototype.transpose=function(g,B){return x("transpose")},A.prototype.gather=function(g,B,Q){return x("gather")},A.prototype.gatherND=function(g,B){return x("gatherND")},A.prototype.scatterND=function(g,B,Q){return x("scatterND")},A.prototype.batchToSpaceND=function(g,B,Q){return x("batchToSpaceND")},A.prototype.spaceToBatchND=function(g,B,Q){return x("spaceToBatchND")},A.prototype.resizeBilinear=function(g,B,Q,w){return x("resizeBilinear")},A.prototype.resizeBilinearBackprop=function(g,B,Q){return x("resizeBilinearBackprop")},A.prototype.resizeNearestNeighbor=function(g,B,Q,w){return x("resizeNearestNeighbor")},A.prototype.resizeNearestNeighborBackprop=function(g,B,Q){return x("resizeNearestNeighborBackprop")},A.prototype.batchNormalization=function(g,B,Q,w,C,E){return x("batchNormalization")},A.prototype.localResponseNormalization4D=function(g,B,Q,w,C){return x("localResponseNormalization4D")},A.prototype.LRNGrad=function(g,B,Q,w,C,E,e){return x("LRNGrad")},A.prototype.multinomial=function(g,B,Q,w){return x("multinomial")},A.prototype.oneHot=function(g,B,Q,w){return x("oneHot")},A.prototype.cumsum=function(g,B,Q,w){return x("cumsum")},A.prototype.nonMaxSuppression=function(g,B,Q,w,C){return x("nonMaxSuppression")},A.prototype.fft=function(g){return x("fft")},A.prototype.ifft=function(g){return x("ifft")},A.prototype.complex=function(g,B){return x("complex")},A.prototype.real=function(g){return x("real")},A.prototype.imag=function(g){return x("imag")},A.prototype.cropAndResize=function(g,B,Q,w,C,E){return x("cropAndResize")},A.prototype.depthToSpace=function(g,B,Q){return x("depthToSpace")},A.prototype.split=function(g,B,Q){return x("split")},A.prototype.sparseToDense=function(g,B,Q,w){return x("sparseToDense")},A.prototype.diag=function(g){return x("diag")},A.prototype.fill=function(g,B,Q){return x("fill")},A.prototype.onesLike=function(g){return x("onesLike")},A.prototype.zerosLike=function(g){return x("zerosLike")},A.prototype.linspace=function(g,B,Q){return x("linspace")},A.prototype.dispose=function(){return x("dispose")},A}();function x(A){throw new Error("'"+A+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function PQ(A,g){for(var B=A.length,Q=[],w=0;w<B;w++){var C=B-1-w,E=A[C]||1;(g[g.length-1-w]||1)>1&&E===1&&Q.unshift(C)}return Q}function yB(A,g){for(var B=[],Q=0;Q<g.length;Q++){var w=A[A.length-Q-1],C=g.length-Q-1,E=g[C];(w==null||w===1&&E>1)&&B.unshift(C)}return B}function qA(A,g){for(var B=[],Q=Math.max(A.length,g.length),w=0;w<Q;w++){var C=A[A.length-w-1];C==null&&(C=1);var E=g[g.length-w-1];if(E==null&&(E=1),C===1)B.unshift(E);else if(E===1)B.unshift(C);else{if(C!==E)throw Error("Operands could not be broadcast together with shapes "+A+" and "+g+".");B.unshift(C)}}return B}function TC(A,g,B,Q,w,C,E){E===void 0&&(E="channelsLast");var e,I=Ye(g),o=I[0],n=I[1];if(E==="channelsLast")e=[o,n,A[3],A[3]];else{if(E!=="channelsFirst")throw new Error("Unknown dataFormat "+E);e=[o,n,A[1],A[1]]}return Cw(A,e,B,Q,w,C,!1,E)}function ne(A,g,B,Q,w,C,E){E===void 0&&(E="NDHWC");var e,I,o=Ct(g),n=o[0],i=o[1],Y=o[2];if(E==="NDHWC")I="channelsLast",e=[n,i,Y,A[4],A[4]];else{if(E!=="NCDHW")throw new Error("Unknown dataFormat "+E);I="channelsFirst",e=[n,i,Y,A[1],A[1]]}return ie(A,e,B,Q,w,!1,I,C)}function Cw(A,g,B,Q,w,C,E,e){E===void 0&&(E=!1),e===void 0&&(e="channelsLast");var I=[-1,-1,-1,-1],o=I[0],n=I[1],i=I[2],Y=I[3];if(e==="channelsLast")o=A[0],n=A[1],i=A[2],Y=A[3];else{if(e!=="channelsFirst")throw new Error("Unknown dataFormat "+e);o=A[0],Y=A[1],n=A[2],i=A[3]}var M,c=g[0],D=g[1],r=g[3],F=Ye(B),s=F[0],u=F[1],a=Ye(Q),U=a[0],G=a[1],d=Sw(c,U),H=Sw(D,G),h=function(N,v,y,k,p,K,V,T){var j,X,gA;if(typeof N=="number"){j={top:N,bottom:N,left:N,right:N,type:N===0?"VALID":"NUMBER"};var CA=function(oA,aA,JA,VA,bA){VA==null&&(VA=uc(oA,aA,JA));var pA=oA[0],ZA=oA[1],CB=jC((pA-aA+2*VA)/JA+1,bA);R(JB(CB),function(){return"The output # of rows ("+CB+") must be an integer. Change the stride and/or zero pad parameters"});var rB=jC((ZA-aA+2*VA)/JA+1,bA);return R(JB(rB),function(){return"The output # of columns ("+rB+") must be an integer. Change the stride and/or zero pad parameters"}),[CB,rB]}([v,y],K,k,N,T);X=CA[0],gA=CA[1]}else if(N==="same"){X=Math.ceil(v/k),gA=Math.ceil(y/p);var wA=Math.max(0,(X-1)*k+K-v),eA=Math.max(0,(gA-1)*p+V-y),YA=Math.floor(wA/2),$=wA-YA,RA=Math.floor(eA/2);j={top:YA,bottom:$,left:RA,right:eA-RA,type:"SAME"}}else{if(N!=="valid")throw Error("Unknown padding parameter: "+N);j={top:0,bottom:0,left:0,right:0,type:"VALID"},X=Math.ceil((v-K+1)/k),gA=Math.ceil((y-V+1)/p)}return{padInfo:j,outHeight:X,outWidth:gA}}(w,n,i,s,u,d,H,C),l=h.padInfo,m=h.outHeight,f=h.outWidth,W=E?r*Y:r;return e==="channelsFirst"?M=[o,W,m,f]:e==="channelsLast"&&(M=[o,m,f,W]),{batchSize:o,dataFormat:e,inHeight:n,inWidth:i,inChannels:Y,outHeight:m,outWidth:f,outChannels:W,padInfo:l,strideHeight:s,strideWidth:u,filterHeight:c,filterWidth:D,effectiveFilterHeight:d,effectiveFilterWidth:H,dilationHeight:U,dilationWidth:G,inShape:A,outShape:M,filterShape:g}}function ie(A,g,B,Q,w,C,E,e){C===void 0&&(C=!1),E===void 0&&(E="channelsLast");var I=[-1,-1,-1,-1,-1],o=I[0],n=I[1],i=I[2],Y=I[3],M=I[4];if(E==="channelsLast")o=A[0],n=A[1],i=A[2],Y=A[3],M=A[4];else{if(E!=="channelsFirst")throw new Error("Unknown dataFormat "+E);o=A[0],M=A[1],n=A[2],i=A[3],Y=A[4]}var c,D=g[0],r=g[1],F=g[2],s=g[4],u=Ct(B),a=u[0],U=u[1],G=u[2],d=Ct(Q),H=d[0],h=d[1],l=d[2],m=Sw(D,H),f=Sw(r,h),W=Sw(F,l),N=function(V,T,j,X,gA,CA,wA,eA,YA,$,RA){var oA,aA,JA,VA;if(typeof V=="number"){oA={top:V,bottom:V,left:V,right:V,front:V,back:V,type:V===0?"VALID":"NUMBER"};var bA=function(aB,vB,ag,hB,kB,mg){kB==null&&(kB=uc(aB,vB,hB));var SB=aB[0],AA=aB[1],IA=aB[2],NA=jC((SB-vB+2*kB)/hB+1,mg);R(JB(NA),function(){return"The output # of depths ("+NA+") must be an integer. Change the stride and/or zero pad parameters"});var TA=jC((AA-vB+2*kB)/hB+1,mg);R(JB(TA),function(){return"The output # of rows ("+TA+") must be an integer. Change the stride and/or zero pad parameters"});var AB=jC((IA-vB+2*kB)/hB+1,mg);return R(JB(AB),function(){return"The output # of columns ("+AB+") must be an integer. Change the stride and/or zero pad parameters"}),[NA,TA,AB,ag]}([T,j,X,1],eA,1,gA,V,RA);aA=bA[0],JA=bA[1],VA=bA[2]}else if(V==="same"){aA=Math.ceil(T/gA),JA=Math.ceil(j/CA),VA=Math.ceil(X/wA);var pA=(aA-1)*gA+eA-T,ZA=(JA-1)*CA+YA-j,CB=(VA-1)*wA+$-X,rB=Math.floor(pA/2),FB=pA-rB,QA=Math.floor(ZA/2),rA=ZA-QA,xA=Math.floor(CB/2);oA={top:QA,bottom:rA,left:xA,right:CB-xA,front:rB,back:FB,type:"SAME"}}else{if(V!=="valid")throw Error("Unknown padding parameter: "+V);oA={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},aA=Math.ceil((T-eA+1)/gA),JA=Math.ceil((j-YA+1)/CA),VA=Math.ceil((X-$+1)/wA)}return{padInfo:oA,outDepth:aA,outHeight:JA,outWidth:VA}}(w,n,i,Y,a,U,G,m,f,W,e),v=N.padInfo,y=N.outDepth,k=N.outHeight,p=N.outWidth,K=C?s*M:s;return E==="channelsFirst"?c=[o,K,y,k,p]:E==="channelsLast"&&(c=[o,y,k,p,K]),{batchSize:o,dataFormat:E,inDepth:n,inHeight:i,inWidth:Y,inChannels:M,outDepth:y,outHeight:k,outWidth:p,outChannels:K,padInfo:v,strideDepth:a,strideHeight:U,strideWidth:G,filterDepth:D,filterHeight:r,filterWidth:F,effectiveFilterDepth:m,effectiveFilterHeight:f,effectiveFilterWidth:W,dilationDepth:H,dilationHeight:h,dilationWidth:l,inShape:A,outShape:c,filterShape:g}}function uc(A,g,B,Q){Q===void 0&&(Q=1);var w=Sw(g,Q);return Math.floor((A[0]*(B-1)-B+w)/2)}function Ye(A){return typeof A=="number"?[A,A,A]:A.length===2?[A[0],A[1],1]:A}function Ct(A){return typeof A=="number"?[A,A,A]:A}function Sw(A,g){return g<=1?A:A+(A-1)*(g-1)}function jC(A,g){if(!g)return A;switch(g){case"round":return Math.round(A);case"ceil":return Math.ceil(A);case"floor":return Math.floor(A);default:throw new Error("Unknown roundingMode "+g)}}function Lw(A){var g=Ye(A),B=g[0],Q=g[1],w=g[2];return B===1&&Q===1&&w===1}function rg(A,g){return Lw(A)||Lw(g)}function Et(A){if(A==="NHWC")return"channelsLast";if(A==="NCHW")return"channelsFirst";throw new Error("Unknown dataFormat "+A)}function Uc(A,g,B){if(g==="complex64"){if(A.dtype==="complex64")return A.clone();var Q=DB(A.shape),w=A.toFloat(),C=B.complex(w,Q);return Q.dispose(),w.dispose(),C}if(!jd(A.dtype,g))return b.makeTensorFromDataId(A.dataId,A.shape,g);if(A.dtype==="complex64"){var E=B.real(A);return C=E.cast(g),E.dispose(),C}if(g==="int32")return B.int(A);if(g==="bool"){var e=nA(0,A.dtype);return C=B.notEqual(A,e),e.dispose(),C}throw new Error("Error in Cast: failed to cast "+A.dtype+" to "+g)}function et(A,g){return b.makeTensorFromDataId(A.dataId,g,A.dtype)}function Gc(A,g,B){var Q=(g-A)/(B-1),w=fC(B,"float32");w[0]=A;for(var C=1;C<w.length;C++)w[C]=w[C-1]+Q;return PB(w,"float32")}function It(A,g){if(A.length!==g.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+A.length+", imag: "+g.length+".");for(var B=new Float32Array(2*A.length),Q=0;Q<B.length;Q+=2)B[Q]=A[Q/2],B[Q+1]=g[Q/2];return B}function hc(A,g){return{real:A[2*g],imag:A[2*g+1]}}function nf(A,g,B,Q){A[2*Q]=g,A[2*Q+1]=B}function Yf(A,g,B){var Q=(B?2:-2)*Math.PI*(A/g);return{real:Math.cos(Q),imag:Math.sin(Q)}}function Mf(A,g,B){var Q=function(C,E,e){return function(I,o,n){for(var i=0,Y=I.length,M=0,c=!1;i<Y;){var D=n(o,I[M=i+(Y-i>>>1)]);D>0?i=M+1:(Y=M,c=!D)}return c?i:-i-1}(C,E,e||cf)}(A,g,B),w=Q<0?-(Q+1):Q;A.splice(w,0,g)}function cf(A,g){return A>g?1:A<g?-1:0}function ot(A,g,B,Q,w){return lc(A,g,B,Q,w,0).selectedIndices}function tt(A,g,B,Q,w,C){var E=lc(A,g,B,Q,w,C);return E.numValidOutputs.dispose(),{selectedIndices:E.selectedIndices,selectedScores:E.selectedScores}}function lc(A,g,B,Q,w,C,E,e){e===void 0&&(e=!1);for(var I=Array.from(g).map(function(a,U){return{score:a,boxIndex:U,suppressBeginIndex:0}}).filter(function(a){return a.score>w}).sort(dc),o=C>0?-.5/C:0,n=[],i=[];n.length<B&&I.length>0;){var Y=I.pop(),M=Y.score,c=Y.boxIndex,D=Y.suppressBeginIndex;if(M<w)break;for(var r=!1,F=n.length-1;F>=D;--F){var s=Df(A,c,n[F]);if(s>=Q){r=!0;break}if(Y.score=Y.score*rf(Q,o,s),Y.score<=w)break}Y.suppressBeginIndex=n.length,r||(Y.score===M?(n.push(c),i.push(Y.score)):Y.score>w&&Mf(I,Y,dc))}var u=n.length;return e&&(n.fill(0,u),i.fill(0,u)),{selectedIndices:PB(n,"int32"),selectedScores:PB(i,"float32"),numValidOutputs:nA(u,"int32")}}function Df(A,g,B){var Q=A.subarray(4*g,4*g+4),w=A.subarray(4*B,4*B+4),C=Math.min(Q[0],Q[2]),E=Math.min(Q[1],Q[3]),e=Math.max(Q[0],Q[2]),I=Math.max(Q[1],Q[3]),o=Math.min(w[0],w[2]),n=Math.min(w[1],w[3]),i=Math.max(w[0],w[2]),Y=Math.max(w[1],w[3]),M=(e-C)*(I-E),c=(i-o)*(Y-n);if(M<=0||c<=0)return 0;var D=Math.max(C,o),r=Math.max(E,n),F=Math.min(e,i),s=Math.min(I,Y),u=Math.max(F-D,0)*Math.max(s-r,0);return u/(M+c-u)}function rf(A,g,B){var Q=Math.exp(g*B*B);return B<=A?Q:0}function dc(A,g){return A.score-g.score||A.score===g.score&&g.boxIndex-A.boxIndex}function Hc(A,g,B){var Q=new Array(A.rank).fill(0),w=A.shape.slice();return g.map(function(C){w[B]=C;var E=A.slice(Q,w);return Q[B]+=C,E})}function fc(A,g){for(var B=new Array(A.rank),Q=0;Q<B.length;Q++)B[Q]=A.shape[Q]*g[Q];var w=zA(B,A.dtype);for(Q=0;Q<w.values.length;++Q){for(var C=w.indexToLoc(Q),E=new Array(A.rank),e=0;e<E.length;e++)E[e]=C[e]%A.shape[e];var I=A.locToIndex(E);w.values[Q]=A.values[I]}return w.toTensor()}function Jc(A,g,B,Q,w){for(var C=g[g.length-1],E=[A.length/C,C],e=E[0],I=E[1],o=dC(B,e*Q),n=dC("int32",e*Q),i=0;i<e;i++){for(var Y=i*I,M=A.subarray(Y,Y+I),c=[],D=0;D<M.length;D++)c.push({value:M[D],index:D});c.sort(function(a,U){return U.value-a.value});var r=i*Q,F=o.subarray(r,r+Q),s=n.subarray(r,r+Q);for(D=0;D<Q;D++)F[D]=c[D].value,s[D]=c[D].index}var u=g.slice();return u[u.length-1]=Q,[Ag(o,u,B),Ag(n,u,"int32")]}function nt(A,g){for(var B=[],Q=0;Q<g.length;Q++)g[Q]&&B.push(Q);var w=zA(A,"int32"),C=zA([B.length,A.length],"int32");for(Q=0;Q<B.length;Q++){var E=w.indexToLoc(B[Q]),e=Q*A.length;C.values.set(E,e)}return C.toTensor()}var Ff=function(A,g){this.outputShape=[],this.outputShape=A,this.variableNames=g.map(function(w,C){return"T"+C});var B=[];this.variableNames.forEach(function(w){B.push("float v"+w+" = get"+w+"AtOutCoords();")});var Q=this.variableNames.map(function(w){return"v"+w}).join(" + ");this.userCode=`
36
36
  void main() {
37
37
  `+B.join(`
38
38
  `)+`
@@ -40,7 +40,7 @@
40
40
  float result = `+Q+`;
41
41
  setOutput(result);
42
42
  }
43
- `},rf=function(A,g){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A,this.variableNames=g.map(function(w,C){return"T"+C});var B=[];this.variableNames.forEach(function(w){B.push("vec4 v"+w+" = get"+w+"AtOutCoords();")});var Q=this.variableNames.map(function(w){return"v"+w}).join(" + ");this.userCode=`
43
+ `},af=function(A,g){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A,this.variableNames=g.map(function(w,C){return"T"+C});var B=[];this.variableNames.forEach(function(w){B.push("vec4 v"+w+" = get"+w+"AtOutCoords();")});var Q=this.variableNames.map(function(w){return"v"+w}).join(" + ");this.userCode=`
44
44
  void main() {
45
45
  `+B.join(`
46
46
  `)+`
@@ -48,7 +48,7 @@
48
48
  vec4 result = `+Q+`;
49
49
  setOutput(result);
50
50
  }
51
- `},Ff=function(A,g,B){this.variableNames=["A"];var Q=A.windowSize,w=A.batchSize,C=A.inSize,E=Math.ceil(C/Q);B||this.variableNames.push("bestIndicesA"),this.outputShape=[w,E];var e=g==="max"?">":"<",I=B?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=`
51
+ `},sf=function(A,g,B){this.variableNames=["A"];var Q=A.windowSize,w=A.batchSize,C=A.inSize,E=Math.ceil(C/Q);B||this.variableNames.push("bestIndicesA"),this.outputShape=[w,E];var e=g==="max"?">":"<",I=B?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=`
52
52
  void main() {
53
53
  ivec2 coords = getOutputCoords();
54
54
  int batch = coords[0];
@@ -113,7 +113,7 @@
113
113
  ivec4 round(vec4 value) {
114
114
  return ivec4(floor(value + vec4(0.5)));
115
115
  }
116
- `),{version:A,attribute:g,varyingVs:B,varyingFs:Q,texture2D:w,output:C,defineOutput:E,defineSpecialNaN:e,defineSpecialInf:I,defineRound:o}}function Ew(A,g,B){B===void 0&&(B="index");var Q=Og(g);return Q.map(function(w,C){return"int "+A[C]+" = "+B+" / "+w+"; "+(C===Q.length-1?"int "+A[C+1]+" = "+B+" - "+A[C]+" * "+w:"index -= "+A[C]+" * "+w)+";"}).join("")}function nt(A){var g=Og(A).map(function(B){return B.toString()});return`
116
+ `),{version:A,attribute:g,varyingVs:B,varyingFs:Q,texture2D:w,output:C,defineOutput:E,defineSpecialNaN:e,defineSpecialInf:I,defineRound:o}}function Ew(A,g,B){B===void 0&&(B="index");var Q=Og(g);return Q.map(function(w,C){return"int "+A[C]+" = "+B+" / "+w+"; "+(C===Q.length-1?"int "+A[C+1]+" = "+B+" - "+A[C]+" * "+w:"index -= "+A[C]+" * "+w)+";"}).join("")}function it(A){var g=Og(A).map(function(B){return B.toString()});return`
117
117
  int getFlatIndex(ivec3 coords) {
118
118
  return coords.x * `+g[0]+" + coords.y * "+g[1]+` + coords.z;
119
119
  }
@@ -156,7 +156,7 @@
156
156
 
157
157
  return c / 255.0;
158
158
  }
159
- `;function af(A,g,B,Q){var w=[];A.forEach(function(M){var c=hA(M.shapeInfo.logicalShape);M.shapeInfo.isUniform?w.push("uniform float "+M.name+(c>1?"["+c+"]":"")+";"):(w.push("uniform sampler2D "+M.name+";"),w.push("uniform int offset"+M.name+";"))});var C,E,e=w.join(`
159
+ `;function uf(A,g,B,Q){var w=[];A.forEach(function(M){var c=hA(M.shapeInfo.logicalShape);M.shapeInfo.isUniform?w.push("uniform float "+M.name+(c>1?"["+c+"]":"")+";"):(w.push("uniform sampler2D "+M.name+";"),w.push("uniform int offset"+M.name+";"))});var C,E,e=w.join(`
160
160
  `),I=A.map(function(M){return function(c,D,r){r===void 0&&(r=!1);var F="";F+=r?Rc(c):bw(c);var s=c.shapeInfo.logicalShape,u=D.logicalShape;return s.length<=u.length&&(F+=r?function(a,U){var G,d=a.name,H=d.charAt(0).toUpperCase()+d.slice(1),h="get"+H+"AtOutCoords",l=a.shapeInfo.logicalShape.length,m=U.logicalShape.length,f=PQ(a.shapeInfo.logicalShape,U.logicalShape),W=nB(m),N=m-l,v=["x","y","z","w","u","v"];G=l===0?"":m<2&&f.length>=1?"coords = 0;":f.map(function(j){return"coords."+v[j+N]+" = 0;"}).join(`
161
161
  `);var y="";y=m<2&&l>0?"coords":a.shapeInfo.logicalShape.map(function(j,X){return"coords."+v[X+N]}).join(", ");var k="return outputValue;",p=hA(a.shapeInfo.logicalShape)===1,K=hA(U.logicalShape)===1;if(l!==1||p||K){if(p&&!K)k=m===1?`
162
162
  return vec4(outputValue.x, outputValue.x, 0., 0.);
@@ -242,9 +242,9 @@
242
242
  return fract((p3.x + p3.y) * p3.z);
243
243
  }
244
244
 
245
- `+sf+`
246
- `+uf+`
247
245
  `+Uf+`
246
+ `+Gf+`
247
+ `+hf+`
248
248
  `}(n);return g.isPacked?(C=function(M,c){switch(M.length){case 0:return`
249
249
  int getOutputCoords() {
250
250
  return 0;
@@ -403,7 +403,7 @@
403
403
  void setOutput(float val) {
404
404
  `+M.output+` = vec4(val, 0, 0, 0);
405
405
  }
406
- `}(n)),Q&&(Y+=Gf),[Y,i,E,e,C,I,B].join(`
406
+ `}(n)),Q&&(Y+=lf),[Y,i,E,e,C,I,B].join(`
407
407
  `)}function bw(A){var g=A.shapeInfo.logicalShape;switch(g.length){case 0:return function(B){var Q=B.name,w="get"+Q.charAt(0).toUpperCase()+Q.slice(1);if(B.shapeInfo.isUniform)return"float "+w+"() {return "+Q+";}";var C=B.shapeInfo.texShape,E=C[0],e=C[1];if(E===1&&e===1)return`
408
408
  float `+w+`() {
409
409
  return sampleTexture(`+Q+`, halfCR);
@@ -672,7 +672,7 @@
672
672
  vec2 uv = (vec2(texC, texR) + halfCR) / vec2(`+Y+", "+i+`);
673
673
  return `+s.texture2D+"("+e+`, uv);
674
674
  }
675
- `}(A)}}var sf=`
675
+ `}(A)}}var Uf=`
676
676
  vec2 uvFromFlat(int texNumR, int texNumC, int index) {
677
677
  int texR = index / texNumC;
678
678
  int texC = index - texR * texNumC;
@@ -684,7 +684,7 @@ vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
684
684
  int texC = texelIndex - texR * texNumC;
685
685
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
686
686
  }
687
- `,uf=`
687
+ `,Gf=`
688
688
  vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
689
689
  int texNumC, int row, int col) {
690
690
  int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
@@ -692,7 +692,7 @@ vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
692
692
  int texC = texelIndex - texR * texNumC;
693
693
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
694
694
  }
695
- `,Uf=`
695
+ `,hf=`
696
696
  vec2 packedUVfrom3D(int texNumR, int texNumC,
697
697
  int texelsInBatch, int texelsInLogicalRow, int b,
698
698
  int row, int col) {
@@ -701,7 +701,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
701
701
  int texC = index - texR * texNumC;
702
702
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
703
703
  }
704
- `,Gf=`
704
+ `,lf=`
705
705
  float getChannel(vec4 frag, vec2 innerDims) {
706
706
  vec2 modCoord = mod(innerDims, 2.);
707
707
  return modCoord.x == 0. ?
@@ -718,7 +718,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
718
718
  return `+g+`[i];
719
719
  }
720
720
  }
721
- `}function nB(A){if(A<=1)return"int";if(A===2)return"ivec2";if(A===3)return"ivec3";if(A===4)return"ivec4";if(A===5)return"ivec5";if(A===6)return"ivec6";throw Error("GPU for rank "+A+" is not yet supported")}function Vw(A,g){var B=JSON.parse(JSON.stringify(A));return B.shapeInfo.logicalShape=g,B}function xw(A,g){return g.map(function(B){return A[B]}).join(", ")}var hf=function(A,g,B,Q){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,R(A.length>2,function(){return"Packed arg"+(B.charAt(0).toUpperCase()+B.slice(1))+" supports only inputs with rank above 2."});var w=A[A.length-1],C=Math.ceil(w/g);this.outputShape=A.slice(0,-1),C>1&&this.outputShape.push(C),Q||this.variableNames.push("bestIndicesA");var E,e,I=this.outputShape,o=I.length,n=nB(o),i=Fg("coords",o);if(C===1){var Y=nB(e=o+1);E=`
721
+ `}function nB(A){if(A<=1)return"int";if(A===2)return"ivec2";if(A===3)return"ivec3";if(A===4)return"ivec4";if(A===5)return"ivec5";if(A===6)return"ivec6";throw Error("GPU for rank "+A+" is not yet supported")}function Vw(A,g){var B=JSON.parse(JSON.stringify(A));return B.shapeInfo.logicalShape=g,B}function xw(A,g){return g.map(function(B){return A[B]}).join(", ")}var df=function(A,g,B,Q){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,R(A.length>2,function(){return"Packed arg"+(B.charAt(0).toUpperCase()+B.slice(1))+" supports only inputs with rank above 2."});var w=A[A.length-1],C=Math.ceil(w/g);this.outputShape=A.slice(0,-1),C>1&&this.outputShape.push(C),Q||this.variableNames.push("bestIndicesA");var E,e,I=this.outputShape,o=I.length,n=nB(o),i=Fg("coords",o);if(C===1){var Y=nB(e=o+1);E=`
722
722
  `+Y+" sourceLocR = "+Y+"("+i.join()+`, 0);
723
723
  ++`+i[o-1]+`;
724
724
  `+Y+" sourceLocG = "+Y+"("+i.join()+`, 0);
@@ -780,7 +780,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
780
780
  }
781
781
  setOutput(bestIndex);
782
782
  }
783
- `},lf=function(A){this.variableNames=["dy"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=A.dilationHeight,E=A.dilationWidth,e=A.effectiveFilterHeight,I=A.effectiveFilterWidth,o=e-1-A.padInfo.top,n=I-1-A.padInfo.left,i=1/(g*B);this.userCode=`
783
+ `},Hf=function(A){this.variableNames=["dy"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=A.dilationHeight,E=A.dilationWidth,e=A.effectiveFilterHeight,I=A.effectiveFilterWidth,o=e-1-A.padInfo.top,n=I-1-A.padInfo.left,i=1/(g*B);this.userCode=`
784
784
  const ivec2 pads = ivec2(`+o+", "+n+`);
785
785
  const float avgMultiplier = float(`+i+`);
786
786
 
@@ -822,7 +822,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
822
822
  }
823
823
  setOutput(dotProd);
824
824
  }
825
- `},df=function(A){this.variableNames=["dy"],this.outputShape=A.inShape;var g=A.filterDepth,B=A.filterHeight,Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.effectiveFilterDepth,i=A.effectiveFilterHeight,Y=A.effectiveFilterWidth,M=n-1-A.padInfo.front,c=i-1-A.padInfo.top,D=Y-1-A.padInfo.left,r=1/(g*B*Q);this.userCode=`
825
+ `},ff=function(A){this.variableNames=["dy"],this.outputShape=A.inShape;var g=A.filterDepth,B=A.filterHeight,Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.effectiveFilterDepth,i=A.effectiveFilterHeight,Y=A.effectiveFilterWidth,M=n-1-A.padInfo.front,c=i-1-A.padInfo.top,D=Y-1-A.padInfo.left,r=1/(g*B*Q);this.userCode=`
826
826
  const ivec3 pads = ivec3(`+M+", "+c+", "+D+`);
827
827
  const float avgMultiplier = float(`+r+`);
828
828
 
@@ -878,7 +878,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
878
878
  }
879
879
  setOutput(dotProd);
880
880
  }
881
- `},Hf=function(A,g,B,Q,w,C){this.outputShape=[],this.variableNames=["x","mean","variance"],qA(A,g),qA(A,B);var E="0.0";Q!=null&&(qA(A,Q),this.variableNames.push("offset"),E="getOffsetAtOutCoords()");var e="1.0";w!=null&&(qA(A,w),this.variableNames.push("scale"),e="getScaleAtOutCoords()"),this.outputShape=A,this.userCode=`
881
+ `},Jf=function(A,g,B,Q,w,C){this.outputShape=[],this.variableNames=["x","mean","variance"],qA(A,g),qA(A,B);var E="0.0";Q!=null&&(qA(A,Q),this.variableNames.push("offset"),E="getOffsetAtOutCoords()");var e="1.0";w!=null&&(qA(A,w),this.variableNames.push("scale"),e="getScaleAtOutCoords()"),this.outputShape=A,this.userCode=`
882
882
  void main() {
883
883
  float x = getXAtOutCoords();
884
884
  float mean = getMeanAtOutCoords();
@@ -888,7 +888,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
888
888
  float inv = scale * inversesqrt(variance + float(`+C+`));
889
889
  setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));
890
890
  }
891
- `},ff=function(A,g,B,Q,w,C){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],qA(A,g),qA(A,B);var E="vec4(0.0)";Q!=null&&(qA(A,Q),this.variableNames.push("offset"),E="getOffsetAtOutCoords()");var e="vec4(1.0)";w!=null&&(qA(A,w),this.variableNames.push("scale"),e="getScaleAtOutCoords()"),this.outputShape=A,this.userCode=`
891
+ `},Nf=function(A,g,B,Q,w,C){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],qA(A,g),qA(A,B);var E="vec4(0.0)";Q!=null&&(qA(A,Q),this.variableNames.push("offset"),E="getOffsetAtOutCoords()");var e="vec4(1.0)";w!=null&&(qA(A,w),this.variableNames.push("scale"),e="getScaleAtOutCoords()"),this.outputShape=A,this.userCode=`
892
892
  void main() {
893
893
  vec4 offset = `+E+`;
894
894
  vec4 scale = `+e+`;
@@ -901,7 +901,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
901
901
 
902
902
  setOutput((x - mean) * inv + offset);
903
903
  }
904
- `},Jf="return areal * breal - aimag * bimag;",Nf="return areal * bimag + aimag * breal;",Pc=function(A,g,B){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=qA(g,B),this.userCode=`
904
+ `},mf="return areal * breal - aimag * bimag;",Rf="return areal * bimag + aimag * breal;",Pc=function(A,g,B){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=qA(g,B),this.userCode=`
905
905
  float binaryOpComplex(
906
906
  float areal, float aimag, float breal, float bimag) {
907
907
  `+A+`
@@ -914,7 +914,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
914
914
  float bimag = getBImagAtOutCoords();
915
915
  setOutput(binaryOpComplex(areal, aimag, breal, bimag));
916
916
  }
917
- `},it="return a + b;",Yt="return a - b;",vc="return a * b;",kc="return (a < 0.) ? b * a : a;",lB=function(A,g,B){this.variableNames=["A","B"],this.outputShape=qA(g,B),this.userCode=`
917
+ `},Yt="return a + b;",Mt="return a - b;",vc="return a * b;",kc="return (a < 0.) ? b * a : a;",lB=function(A,g,B){this.variableNames=["A","B"],this.outputShape=qA(g,B),this.userCode=`
918
918
  float binaryOperation(float a, float b) {
919
919
  `+A+`
920
920
  }
@@ -959,7 +959,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
959
959
 
960
960
  setOutput(result);
961
961
  }
962
- `},mf=function(){function A(g){this.variableNames=["A"],this.outputShape=g,this.userCode=`
962
+ `},Pf=function(){function A(g){this.variableNames=["A"],this.outputShape=g,this.userCode=`
963
963
  uniform float minVal;
964
964
  uniform float maxVal;
965
965
 
@@ -972,7 +972,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
972
972
 
973
973
  setOutput(clamp(value, minVal, maxVal));
974
974
  }
975
- `}return A.prototype.getCustomSetupFunc=function(g,B){var Q=this;return function(w,C){Q.minLoc==null&&(Q.minLoc=w.getUniformLocationNoThrow(C,"minVal"),Q.maxLoc=w.getUniformLocationNoThrow(C,"maxVal")),w.gl.uniform1f(Q.minLoc,g),w.gl.uniform1f(Q.maxLoc,B)}},A}(),Rf=function(){function A(g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g,this.userCode=`
975
+ `}return A.prototype.getCustomSetupFunc=function(g,B){var Q=this;return function(w,C){Q.minLoc==null&&(Q.minLoc=w.getUniformLocationNoThrow(C,"minVal"),Q.maxLoc=w.getUniformLocationNoThrow(C,"maxVal")),w.gl.uniform1f(Q.minLoc,g),w.gl.uniform1f(Q.maxLoc,B)}},A}(),vf=function(){function A(g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g,this.userCode=`
976
976
  uniform float minVal;
977
977
  uniform float maxVal;
978
978
 
@@ -986,7 +986,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
986
986
 
987
987
  setOutput(clamp(value, vec4(minVal), vec4(maxVal)));
988
988
  }
989
- `}return A.prototype.getCustomSetupFunc=function(g,B){var Q=this;return function(w,C){Q.minLoc==null&&(Q.minLoc=w.getUniformLocationNoThrow(C,"minVal"),Q.maxLoc=w.getUniformLocationNoThrow(C,"maxVal")),w.gl.uniform1f(Q.minLoc,g),w.gl.uniform1f(Q.maxLoc,B)}},A}(),Pf=function(A){this.variableNames=["real","imag"],this.outputShape=A,this.userCode=`
989
+ `}return A.prototype.getCustomSetupFunc=function(g,B){var Q=this;return function(w,C){Q.minLoc==null&&(Q.minLoc=w.getUniformLocationNoThrow(C,"minVal"),Q.maxLoc=w.getUniformLocationNoThrow(C,"maxVal")),w.gl.uniform1f(Q.minLoc,g),w.gl.uniform1f(Q.maxLoc,B)}},A}(),kf=function(A){this.variableNames=["real","imag"],this.outputShape=A,this.userCode=`
990
990
  void main() {
991
991
  float re = abs(getRealAtOutCoords());
992
992
  float im = abs(getImagAtOutCoords());
@@ -999,7 +999,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
999
999
  mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))
1000
1000
  );
1001
1001
  }
1002
- `},vf=function(A){this.outputShape=[],this.outputShape=yw(A,1),this.variableNames=A.map(function(e,I){return"T"+I});var g=new Array(A.length-1);g[0]=A[0][1];for(var B=1;B<g.length;B++)g[B]=g[B-1]+A[B][1];var Q=["if (yC < "+g[0]+") setOutput(getT0(yR, yC));"];for(B=1;B<g.length;B++){var w=g[B-1];Q.push("else if (yC < "+g[B]+") setOutput(getT"+B+"(yR, yC-"+w+"));")}var C=g.length,E=g[g.length-1];Q.push("else setOutput(getT"+C+"(yR, yC-"+E+"));"),this.userCode=`
1002
+ `},Tf=function(A){this.outputShape=[],this.outputShape=yw(A,1),this.variableNames=A.map(function(e,I){return"T"+I});var g=new Array(A.length-1);g[0]=A[0][1];for(var B=1;B<g.length;B++)g[B]=g[B-1]+A[B][1];var Q=["if (yC < "+g[0]+") setOutput(getT0(yR, yC));"];for(B=1;B<g.length;B++){var w=g[B-1];Q.push("else if (yC < "+g[B]+") setOutput(getT"+B+"(yR, yC-"+w+"));")}var C=g.length,E=g[g.length-1];Q.push("else setOutput(getT"+C+"(yR, yC-"+E+"));"),this.userCode=`
1003
1003
  void main() {
1004
1004
  ivec2 coords = getOutputCoords();
1005
1005
  int yR = coords.x;
@@ -1008,7 +1008,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1008
1008
  `+Q.join(`
1009
1009
  `)+`
1010
1010
  }
1011
- `},kf=function(A,g){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=yw(A,g);var B=this.outputShape,Q=B.length,w=nB(Q),C=Fg("coords",Q),E=["x","y","z","w","u","v"].slice(0,Q);this.variableNames=A.map(function(r,F){return"T"+F});var e=new Array(A.length-1);e[0]=A[0][g];for(var I=1;I<e.length;I++)e[I]=e[I-1]+A[I][g];var o=E[g],n=E.slice(-2),i=E.join(),Y="if ("+o+" < "+e[0]+`) {
1011
+ `},jf=function(A,g){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=yw(A,g);var B=this.outputShape,Q=B.length,w=nB(Q),C=Fg("coords",Q),E=["x","y","z","w","u","v"].slice(0,Q);this.variableNames=A.map(function(r,F){return"T"+F});var e=new Array(A.length-1);e[0]=A[0][g];for(var I=1;I<e.length;I++)e[I]=e[I-1]+A[I][g];var o=E[g],n=E.slice(-2),i=E.join(),Y="if ("+o+" < "+e[0]+`) {
1012
1012
  return getChannel(
1013
1013
  getT0(`+i+"), vec2("+n.join()+`));
1014
1014
  }`;for(I=1;I<e.length;I++){var M=e[I-1];Y+=`
@@ -1045,7 +1045,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1045
1045
  }
1046
1046
  setOutput(result);
1047
1047
  }
1048
- `};function Me(A,g,B){var Q=A.indexOf(g);return A.map(function(w,C){return C===Q?w+" - "+B:w}).join()}var Tf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideHeight,B=A.strideWidth,Q=A.padInfo.top,w=A.padInfo.left,C=A.dataFormat==="channelsLast";this.userCode=`
1048
+ `};function Me(A,g,B){var Q=A.indexOf(g);return A.map(function(w,C){return C===Q?w+" - "+B:w}).join()}var pf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideHeight,B=A.strideWidth,Q=A.padInfo.top,w=A.padInfo.left,C=A.dataFormat==="channelsLast";this.userCode=`
1049
1049
  void main() {
1050
1050
  ivec4 coords = getOutputCoords();
1051
1051
  int wR = coords.x;
@@ -1087,7 +1087,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1087
1087
  }
1088
1088
  setOutput(dotProd);
1089
1089
  }
1090
- `},jf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=A.dataFormat==="channelsLast",E=g-1-A.padInfo.top,e=B-1-A.padInfo.left,I=C?1:2,o=C?2:3,n=C?3:1;this.userCode=`
1090
+ `},yf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=A.dataFormat==="channelsLast",E=g-1-A.padInfo.top,e=B-1-A.padInfo.left,I=C?1:2,o=C?2:3,n=C?3:1;this.userCode=`
1091
1091
  const ivec2 pads = ivec2(`+E+", "+e+`);
1092
1092
 
1093
1093
  void main() {
@@ -1140,7 +1140,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1140
1140
  }
1141
1141
  setOutput(dotProd);
1142
1142
  }
1143
- `},pf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideDepth,B=A.strideHeight,Q=A.strideWidth,w=A.padInfo.front,C=A.padInfo.top,E=A.padInfo.left;this.userCode=`
1143
+ `},zf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideDepth,B=A.strideHeight,Q=A.strideWidth,w=A.padInfo.front,C=A.padInfo.top,E=A.padInfo.left;this.userCode=`
1144
1144
  void main() {
1145
1145
  ivec5 coords = getOutputCoords();
1146
1146
  int wF = coords.x;
@@ -1182,7 +1182,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1182
1182
  }
1183
1183
  setOutput(dotProd);
1184
1184
  }
1185
- `},yf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterDepth,B=A.filterHeight,Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=g-1-A.padInfo.front,I=B-1-A.padInfo.top,o=Q-1-A.padInfo.left;this.userCode=`
1185
+ `},Wf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterDepth,B=A.filterHeight,Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=g-1-A.padInfo.front,I=B-1-A.padInfo.top,o=Q-1-A.padInfo.left;this.userCode=`
1186
1186
  const ivec3 pads = ivec3(`+e+", "+I+", "+o+`);
1187
1187
 
1188
1188
  void main() {
@@ -1239,7 +1239,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1239
1239
  }
1240
1240
  setOutput(dotProd);
1241
1241
  }
1242
- `},zf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideHeight,B=A.strideWidth,Q=A.padInfo.top,w=A.padInfo.left,C=A.outChannels/A.inChannels;this.userCode=`
1242
+ `},Sf=function(A){this.variableNames=["x","dy"],this.outputShape=A.filterShape;var g=A.strideHeight,B=A.strideWidth,Q=A.padInfo.top,w=A.padInfo.left,C=A.outChannels/A.inChannels;this.userCode=`
1243
1243
  void main() {
1244
1244
  ivec4 coords = getOutputCoords();
1245
1245
  int wR = coords.x;
@@ -1274,7 +1274,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1274
1274
  }
1275
1275
  setOutput(dotProd);
1276
1276
  }
1277
- `},Wf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=g-1-A.padInfo.top,E=B-1-A.padInfo.left,e=A.outChannels/A.inChannels;this.userCode=`
1277
+ `},Lf=function(A){this.variableNames=["dy","W"],this.outputShape=A.inShape;var g=A.filterHeight,B=A.filterWidth,Q=A.strideHeight,w=A.strideWidth,C=g-1-A.padInfo.top,E=B-1-A.padInfo.left,e=A.outChannels/A.inChannels;this.userCode=`
1278
1278
  const ivec2 pads = ivec2(`+C+", "+E+`);
1279
1279
 
1280
1280
  void main() {
@@ -1450,7 +1450,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1450
1450
  `+u+`
1451
1451
  setOutput(result);
1452
1452
  }
1453
- `},Sf=function(A){this.variableNames=["x","W"],this.outputShape=A.outShape;var g=A.padInfo.front,B=A.padInfo.top,Q=A.padInfo.left,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.filterDepth,i=A.filterHeight,Y=A.filterWidth,M=4*Math.floor(A.inChannels/4),c=A.inChannels%4;this.userCode=`
1453
+ `},bf=function(A){this.variableNames=["x","W"],this.outputShape=A.outShape;var g=A.padInfo.front,B=A.padInfo.top,Q=A.padInfo.left,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.filterDepth,i=A.filterHeight,Y=A.filterWidth,M=4*Math.floor(A.inChannels/4),c=A.inChannels%4;this.userCode=`
1454
1454
  const ivec3 strides = ivec3(`+w+", "+C+", "+E+`);
1455
1455
  const ivec3 pads = ivec3(`+g+", "+B+", "+Q+`);
1456
1456
 
@@ -1741,7 +1741,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1741
1741
  `+U+`
1742
1742
  setOutput(result);
1743
1743
  }
1744
- `},Lf=function(A,g,B,Q,w){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var C=A[0],E=A[1],e=A[2],I=A[3],o=g[0],n=B[0],i=B[1];this.outputShape=[o,n,i,I];var Y=Q==="bilinear"?1:0,M=[E-1+".0",e-1+".0"],c=M[0],D=M[1],r=n>1?[""+(E-1)/(n-1),"(y2-y1) * height_ratio","y1*"+c+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+c],F=r[0],s=r[1],u=r[2],a=i>1?[""+(e-1)/(i-1),"(x2-x1) * width_ratio","x1*"+D+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+D],U=a[0],G=a[1],d=a[2];this.userCode=`
1744
+ `},Kf=function(A,g,B,Q,w){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var C=A[0],E=A[1],e=A[2],I=A[3],o=g[0],n=B[0],i=B[1];this.outputShape=[o,n,i,I];var Y=Q==="bilinear"?1:0,M=[E-1+".0",e-1+".0"],c=M[0],D=M[1],r=n>1?[""+(E-1)/(n-1),"(y2-y1) * height_ratio","y1*"+c+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+c],F=r[0],s=r[1],u=r[2],a=i>1?[""+(e-1)/(i-1),"(x2-x1) * width_ratio","x1*"+D+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+D],U=a[0],G=a[1],d=a[2];this.userCode=`
1745
1745
  const float height_ratio = float(`+F+`);
1746
1746
  const float width_ratio = float(`+U+`);
1747
1747
  void main() {
@@ -1802,7 +1802,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1802
1802
  setOutput(newValue);
1803
1803
  }
1804
1804
  }
1805
- `},bf=function(A,g,B){this.variableNames=["x"],this.outputShape=A;var Q=A.length,w=A[A.length-1],C=B?"<":">";this.userCode=`
1805
+ `},Vf=function(A,g,B){this.variableNames=["x"],this.outputShape=A;var Q=A.length,w=A[A.length-1],C=B?"<":">";this.userCode=`
1806
1806
  int getIndex(int i) {
1807
1807
  `+(B?"return "+w+" -i - 1;":"return i;")+`
1808
1808
  }
@@ -1824,7 +1824,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1824
1824
  }
1825
1825
  setOutput(val);
1826
1826
  }
1827
- `};function zc(A,g){if(A===1)return""+g;if(A===2)return g+".y";if(A===3)return g+".z";if(A===4)return g+".w";throw Error("Cumulative sum for rank "+A+" is not yet supported")}var Kf=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=PC.DENSE;var g=vC(A),B=Qg();this.outputShape=A,this.userCode=`
1827
+ `};function zc(A,g){if(A===1)return""+g;if(A===2)return g+".y";if(A===3)return g+".z";if(A===4)return g+".w";throw Error("Cumulative sum for rank "+A+" is not yet supported")}var xf=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=PC.DENSE;var g=vC(A),B=Qg();this.outputShape=A,this.userCode=`
1828
1828
  ivec3 outCoordsFromFlatIndex(int index) {
1829
1829
  `+Ew(["r","c","d"],A)+`
1830
1830
  return ivec3(r, c, d);
@@ -1845,7 +1845,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1845
1845
 
1846
1846
  `+B.output+` = result;
1847
1847
  }
1848
- `},Vf=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=PC.DENSE;var g=vC(A),B=Qg();this.outputShape=A,this.userCode=`
1848
+ `},Xf=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=PC.DENSE;var g=vC(A),B=Qg();this.outputShape=A,this.userCode=`
1849
1849
  ivec3 outCoordsFromFlatIndex(int index) {
1850
1850
  `+Ew(["r","c","d"],A)+`
1851
1851
  return ivec3(r, c, d);
@@ -1866,7 +1866,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1866
1866
 
1867
1867
  `+B.output+` = result;
1868
1868
  }
1869
- `},xf=function(){function A(g,B,Q){this.variableNames=["x"],this.outputShape=[],this.outputShape=g,this.blockSize=B,this.dataFormat=Q,this.userCode=`
1869
+ `},Of=function(){function A(g,B,Q){this.variableNames=["x"],this.outputShape=[],this.outputShape=g,this.blockSize=B,this.dataFormat=Q,this.userCode=`
1870
1870
  void main() {
1871
1871
  ivec4 coords = getOutputCoords();
1872
1872
  int b = coords[0];
@@ -1885,20 +1885,20 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1885
1885
  float result = `+this.getInputSamplingString()+`;
1886
1886
  setOutput(result);
1887
1887
  }
1888
- `}return A.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},A.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},A.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},A.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},A.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},A}(),Xf=function(A){this.variableNames=["X"],this.outputShape=[A,A],this.userCode=`
1888
+ `}return A.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},A.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},A.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},A.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},A.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},A}(),Zf=function(A){this.variableNames=["X"],this.outputShape=[A,A],this.userCode=`
1889
1889
  void main() {
1890
1890
  ivec2 coords = getOutputCoords();
1891
1891
  float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;
1892
1892
  setOutput(val);
1893
1893
  }
1894
- `},Of=function(A){this.variableNames=["A"],this.outTexUsage=hg.DOWNLOAD;var g=Qg();this.outputShape=A,this.userCode=`
1894
+ `},qf=function(A){this.variableNames=["A"],this.outTexUsage=hg.DOWNLOAD;var g=Qg();this.outputShape=A,this.userCode=`
1895
1895
  `+mc+`
1896
1896
 
1897
1897
  void main() {
1898
1898
  float x = getAAtOutCoords();
1899
1899
  `+g.output+` = encode_float(x);
1900
1900
  }
1901
- `},Zf=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=hg.DOWNLOAD;var g=Qg();this.outputShape=A,this.userCode=`
1901
+ `},_f=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=hg.DOWNLOAD;var g=Qg();this.outputShape=A,this.userCode=`
1902
1902
  `+mc+`
1903
1903
 
1904
1904
  void main() {
@@ -1906,8 +1906,8 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1906
1906
  float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));
1907
1907
  `+g.output+` = encode_float(x);
1908
1908
  }
1909
- `},qf=function(A,g,B){B===void 0&&(B=!1),this.variableNames=["A"];var Q=Qg(),w=g[0],C=g[1];this.outputShape=A;var E="result";B&&(E="floor(result * 255. + 0.5)"),this.userCode=`
1910
- `+nt(A)+`
1909
+ `},$f=function(A,g,B){B===void 0&&(B=!1),this.variableNames=["A"];var Q=Qg(),w=g[0],C=g[1];this.outputShape=A;var E="result";B&&(E="floor(result * 255. + 0.5)"),this.userCode=`
1910
+ `+it(A)+`
1911
1911
 
1912
1912
  void main() {
1913
1913
  ivec3 coords = getOutputCoords();
@@ -1936,7 +1936,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1936
1936
 
1937
1937
  `+Q.output+" = vec4("+E+`, 0., 0., 0.);
1938
1938
  }
1939
- `},_f=function(A,g,B){B===void 0&&(B=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var Q=Qg(),w=g[0],C=g[1];this.outputShape=A;var E="",e="result";B&&(e="floor(result * 255. + 0.5)");for(var I=0;I<=1;I++)for(var o=0;o<=1;o++){var n=2*I+o;E+=`
1939
+ `},AJ=function(A,g,B){B===void 0&&(B=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var Q=Qg(),w=g[0],C=g[1];this.outputShape=A;var E="",e="result";B&&(e="floor(result * 255. + 0.5)");for(var I=0;I<=1;I++)for(var o=0;o<=1;o++){var n=2*I+o;E+=`
1940
1940
  localCoords = coords;
1941
1941
  if(localCoords[2] + `+o+" < "+A[2]+`) {
1942
1942
  localCoords[2] += `+o+`;
@@ -1965,7 +1965,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1965
1965
  }
1966
1966
  }
1967
1967
  `}this.userCode=`
1968
- `+nt(A)+`
1968
+ `+it(A)+`
1969
1969
 
1970
1970
  void main() {
1971
1971
  ivec3 coords = getOutputCoords();
@@ -1980,7 +1980,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
1980
1980
 
1981
1981
  `+Q.output+" = "+e+`;
1982
1982
  }
1983
- `},$f="return real * expR - imag * expI;",AJ="return real * expI + imag * expR;",Wc=function(A,g,B){this.variableNames=["real","imag"];var Q=g[1];this.outputShape=g;var w=B?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,C=B?Q+".0":"1.0";this.userCode=`
1983
+ `},BJ="return real * expR - imag * expI;",gJ="return real * expI + imag * expR;",Wc=function(A,g,B){this.variableNames=["real","imag"];var Q=g[1];this.outputShape=g;var w=B?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,C=B?Q+".0":"1.0";this.userCode=`
1984
1984
  const float exponentMultiplier = `+w+`;
1985
1985
 
1986
1986
  float unaryOpComplex(float real, float expR, float imag, float expI) {
@@ -2013,18 +2013,18 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2013
2013
  ivec2 coords = getOutputCoords();
2014
2014
  setOutput(mulMatDFT(coords[0], coords[1]));
2015
2015
  }
2016
- `},BJ=function(){function A(g,B){this.outputShape=[],this.variableNames=["x"],this.outputShape=g,this.userCode=`
2016
+ `},QJ=function(){function A(g,B){this.outputShape=[],this.variableNames=["x"],this.outputShape=g,this.userCode=`
2017
2017
  uniform float value;
2018
2018
  void main() {
2019
2019
  // Input can be obtained from uniform value.
2020
2020
  setOutput(value);
2021
2021
  }
2022
- `}return A.prototype.getCustomSetupFunc=function(g){var B=this;return function(Q,w){B.valueLoc==null&&(B.valueLoc=Q.getUniformLocationNoThrow(w,"value")),Q.gl.uniform1f(B.valueLoc,g)}},A}(),gJ=function(A,g,B){this.variableNames=["A","indices"];var Q=A.slice();Q[B]=g,this.outputShape=Q,this.rank=Q.length;var w=nB(this.rank),C=function(E,e){var I=E.length;if(I>4)throw Error("Gather for rank "+I+" is not yet supported");if(I===1)return"int(getIndices(resRC))";for(var o=["resRC.x","resRC.y","resRC.z","resRC.w"],n=[],i=0;i<E.length;i++)i===e?n.push("int(getIndices("+o[i]+"))"):n.push(""+o[i]);return n.join()}(A,B);this.userCode=`
2022
+ `}return A.prototype.getCustomSetupFunc=function(g){var B=this;return function(Q,w){B.valueLoc==null&&(B.valueLoc=Q.getUniformLocationNoThrow(w,"value")),Q.gl.uniform1f(B.valueLoc,g)}},A}(),wJ=function(A,g,B){this.variableNames=["A","indices"];var Q=A.slice();Q[B]=g,this.outputShape=Q,this.rank=Q.length;var w=nB(this.rank),C=function(E,e){var I=E.length;if(I>4)throw Error("Gather for rank "+I+" is not yet supported");if(I===1)return"int(getIndices(resRC))";for(var o=["resRC.x","resRC.y","resRC.z","resRC.w"],n=[],i=0;i<E.length;i++)i===e?n.push("int(getIndices("+o[i]+"))"):n.push(""+o[i]);return n.join()}(A,B);this.userCode=`
2023
2023
  void main() {
2024
2024
  `+w+` resRC = getOutputCoords();
2025
2025
  setOutput(getA(`+C+`));
2026
2026
  }
2027
- `},QJ=function(A,g,B){this.sliceDim=A,this.strides=g,this.variableNames=["x","indices"],this.outputShape=B;var Q=nB(g.length),w=nB(B.length),C=this.sliceDim>1?"strides[j]":"strides";this.userCode=`
2027
+ `},CJ=function(A,g,B){this.sliceDim=A,this.strides=g,this.variableNames=["x","indices"],this.outputShape=B;var Q=nB(g.length),w=nB(B.length),C=this.sliceDim>1?"strides[j]":"strides";this.userCode=`
2028
2028
  `+Q+" strides = "+Q+"("+this.strides+`);
2029
2029
  void main() {
2030
2030
  `+w+` coords = getOutputCoords();
@@ -2035,7 +2035,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2035
2035
  }
2036
2036
  setOutput(getX(flattenIndex, coords[1]));
2037
2037
  }
2038
- `};function wJ(A,g){var B=Qg();return _d(A,g,B.version+`
2038
+ `};function EJ(A,g){var B=Qg();return AH(A,g,B.version+`
2039
2039
  precision highp float;
2040
2040
  `+B.attribute+` vec3 clipSpacePos;
2041
2041
  `+B.attribute+` vec2 uv;
@@ -2044,7 +2044,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2044
2044
  void main() {
2045
2045
  gl_Position = vec4(clipSpacePos, 1);
2046
2046
  resultUV = uv;
2047
- }`)}function CJ(A,g){return QH(A,g,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function EJ(A,g){return wH(A,g,new Uint16Array([0,1,2,2,1,3]))}function pC(A,g,B,Q,w,C,E){EH(B,Q);var e=CH(A,g),I=A.TEXTURE_2D;return lA(A,g,function(){return A.bindTexture(I,e)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_MIN_FILTER,A.NEAREST)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_MAG_FILTER,A.NEAREST)}),lA(A,g,function(){return A.texImage2D(I,0,w,B,Q,0,C,E,null)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)}),e}function eJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],w.internalFormatFloat,w.textureFormatFloat,A.FLOAT)}function IJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],w.internalFormatHalfFloat,w.textureFormatFloat,w.textureTypeHalfFloat)}function oJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],A.RGBA,A.RGBA,A.UNSIGNED_BYTE)}function tJ(A,g,B,Q,w){var C=kC(B,Q);return pC(A,g,C[0],C[1],w.internalFormatPackedFloat,A.RGBA,A.FLOAT)}function nJ(A,g,B,Q,w){var C=kC(B,Q);return pC(A,g,C[0],C[1],w.internalFormatPackedHalfFloat,A.RGBA,w.textureTypeHalfFloat)}function iJ(A,g,B,Q){return lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,Q)}),Ac(A,g,B,"clipSpacePos",Q,3,20,0)&&Ac(A,g,B,"uv",Q,2,20,12)}function YJ(A,g,B,Q,w,C,E){var e,I,o;lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)}),C instanceof Uint8Array?(e=new Uint8Array(Q*w*4),I=A.UNSIGNED_BYTE,o=A.RGBA):(e=new Float32Array(Q*w*4),I=A.FLOAT,o=E.internalFormatPackedFloat),e.set(C),lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,o,Q,w,0,A.RGBA,I,e)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)})}function MJ(A,g,B,Q){lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)}),Q.data instanceof Uint8Array?lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,A.RGBA,Q.width,Q.height,0,A.RGBA,A.UNSIGNED_BYTE,Q.data)}):lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,A.RGBA,A.RGBA,A.UNSIGNED_BYTE,Q)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)})}function cJ(A,g,B,Q,w){var C=A.createBuffer();lA(A,g,function(){return A.bindBuffer(A.PIXEL_PACK_BUFFER,C)});var E=16*B*Q;return lA(A,g,function(){return A.bufferData(A.PIXEL_PACK_BUFFER,E,A.STREAM_READ)}),lA(A,g,function(){return A.readPixels(0,0,Q,B,A.RGBA,A.FLOAT,0)}),lA(A,g,function(){return A.bindBuffer(A.PIXEL_PACK_BUFFER,null)}),C}function DJ(A,g,B){var Q=A,w=new Float32Array(B);return Q.bindBuffer(Q.PIXEL_PACK_BUFFER,g),Q.getBufferSubData(Q.PIXEL_PACK_BUFFER,0,w),Q.bindBuffer(Q.PIXEL_PACK_BUFFER,null),w}function rJ(A,g,B,Q,w){var C=OE(B,Q),E=C[0],e=C[1],I=new Uint8Array(B*Q*4);return lA(A,g,function(){return A.readPixels(0,0,E,e,w.downloadTextureFormat,A.UNSIGNED_BYTE,I)}),new Float32Array(I.buffer)}function FJ(A,g,B,Q,w,C,E,e){var I=A,o=new Float32Array(function(n,i){var Y=kC(n,i);return Y[0]*Y[1]*4}(C,E));return I.bindBuffer(I.PIXEL_PACK_BUFFER,g),I.getBufferSubData(I.PIXEL_PACK_BUFFER,0,o),I.bindBuffer(I.PIXEL_PACK_BUFFER,null),o}function aJ(A,g,B,Q){var w=new Float32Array(B*Q*4);return lA(A,g,function(){return A.readPixels(0,0,Q,B,A.RGBA,A.FLOAT,w)}),w}var sJ=function(){function A(g){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var B=BA().getNumber("WEBGL_VERSION");g!=null?(this.gl=g,xd(B,g)):this.gl=_g(B);var Q="WEBGL_color_buffer_float";if(BA().getNumber("WEBGL_VERSION")===1){if(this.textureFloatExtension=ZE(this.gl,this.debug,"OES_texture_float"),vg(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=ZE(this.gl,this.debug,"OES_texture_half_float");else if(BA().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(Q),vg(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=ZE(this.gl,this.debug,"EXT_color_buffer_half_float");else if(BA().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(Q="EXT_color_buffer_float",vg(this.gl,Q))this.colorBufferFloatExtension=this.gl.getExtension(Q);else{if(!vg(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=CJ(this.gl,this.debug),this.indexBuffer=EJ(this.gl,this.debug),this.framebuffer=eH(this.gl,this.debug),this.textureConfig=bo(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(A.prototype,"debug",{get:function(){return BA().getBool("DEBUG")},enumerable:!0,configurable:!0}),A.prototype.dispose=function(){var g=this;if(!this.disposed){this.program!=null&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),this.outputTexture!=null&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var B=this.gl;lA(B,this.debug,function(){return B.finish()}),lA(B,this.debug,function(){return B.bindFramebuffer(B.FRAMEBUFFER,null)}),lA(B,this.debug,function(){return B.deleteFramebuffer(g.framebuffer)}),lA(B,this.debug,function(){return B.bindBuffer(B.ARRAY_BUFFER,null)}),lA(B,this.debug,function(){return B.bindBuffer(B.ELEMENT_ARRAY_BUFFER,null)}),lA(B,this.debug,function(){return B.deleteBuffer(g.indexBuffer)}),this.disposed=!0}},A.prototype.createFloat32MatrixTexture=function(g,B){return this.throwIfDisposed(),eJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createFloat16MatrixTexture=function(g,B){return this.throwIfDisposed(),IJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createUnsignedBytesMatrixTexture=function(g,B){return this.throwIfDisposed(),oJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.uploadPixelDataToTexture=function(g,B){this.throwIfDisposed(),MJ(this.gl,this.debug,g,B)},A.prototype.uploadDenseMatrixToTexture=function(g,B,Q,w){this.throwIfDisposed(),YJ(this.gl,this.debug,g,B,Q,w,this.textureConfig)},A.prototype.createFloat16PackedMatrixTexture=function(g,B){return this.throwIfDisposed(),nJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createPackedMatrixTexture=function(g,B){return this.throwIfDisposed(),tJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.deleteMatrixTexture=function(g){var B=this;this.throwIfDisposed(),this.outputTexture===g&&(Bc(this.gl,this.debug,this.framebuffer),this.outputTexture=null),lA(this.gl,this.debug,function(){return B.gl.deleteTexture(g)})},A.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(g,B,Q){var w=this;return this.downloadMatrixDriver(g,function(){return rJ(w.gl,w.debug,B,Q,w.textureConfig)})},A.prototype.downloadPackedMatrixFromBuffer=function(g,B,Q,w,C,E){return FJ(this.gl,g,0,0,0,C,E,this.textureConfig)},A.prototype.downloadFloat32MatrixFromBuffer=function(g,B){return DJ(this.gl,g,B)},A.prototype.createBufferFromTexture=function(g,B,Q){this.bindTextureToFrameBuffer(g);var w=cJ(this.gl,this.debug,B,Q,this.textureConfig);return this.unbindTextureToFrameBuffer(),w},A.prototype.createAndWaitForFence=function(){var g=this.createFence(this.gl);return this.pollFence(g)},A.prototype.createFence=function(g){var B,Q,w=this;if(BA().getBool("WEBGL_FENCE_API_ENABLED")){var C=g,E=C.fenceSync(C.SYNC_GPU_COMMANDS_COMPLETE,0);g.flush(),Q=function(){var e=C.clientWaitSync(E,0,0);return e===C.ALREADY_SIGNALED||e===C.CONDITION_SATISFIED},B=E}else BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(B=this.beginQuery(),this.endQuery(),Q=function(){return w.isQueryAvailable(B,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):Q=function(){return!0};return{query:B,isFencePassed:Q}},A.prototype.downloadMatrixFromPackedTexture=function(g,B,Q){var w=this;return this.downloadMatrixDriver(g,function(){return aJ(w.gl,w.debug,B,Q)})},A.prototype.createProgram=function(g){this.throwIfDisposed();var B=this.gl,Q=$d(B,this.debug,g),w=wJ(B,this.debug),C=BH(B,this.debug);return lA(B,this.debug,function(){return B.attachShader(C,w)}),lA(B,this.debug,function(){return B.attachShader(C,Q)}),gH(B,this.debug,C),this.debug&&xo(B,this.debug,C),this.vertexAttrsAreBound||(this.setProgram(C),this.vertexAttrsAreBound=iJ(B,this.debug,this.program,this.vertexBuffer)),C},A.prototype.deleteProgram=function(g){var B=this;this.throwIfDisposed(),g===this.program&&(this.program=null),g!=null&&lA(this.gl,this.debug,function(){return B.gl.deleteProgram(g)})},A.prototype.setProgram=function(g){var B=this;this.throwIfDisposed(),this.program=g,this.program!=null&&this.debug&&xo(this.gl,this.debug,this.program),lA(this.gl,this.debug,function(){return B.gl.useProgram(g)})},A.prototype.getUniformLocation=function(g,B,Q){return Q===void 0&&(Q=!0),this.throwIfDisposed(),Q?oH(this.gl,this.debug,g,B):tH(this.gl,g,B)},A.prototype.getAttributeLocation=function(g,B){var Q=this;return this.throwIfDisposed(),lA(this.gl,this.debug,function(){return Q.gl.getAttribLocation(g,B)})},A.prototype.getUniformLocationNoThrow=function(g,B){return this.throwIfDisposed(),this.gl.getUniformLocation(g,B)},A.prototype.setInputMatrixTexture=function(g,B,Q){this.throwIfDisposed(),this.throwIfNoProgram(),nH(this.gl,this.debug,this.program,g,B,Q)},A.prototype.setOutputMatrixTexture=function(g,B,Q){this.setOutputMatrixTextureDriver(g,Q,B)},A.prototype.setOutputPackedMatrixTexture=function(g,B,Q){this.throwIfDisposed();var w=kC(B,Q),C=w[0],E=w[1];this.setOutputMatrixTextureDriver(g,C,E)},A.prototype.setOutputMatrixWriteRegion=function(g,B,Q,w){this.setOutputMatrixWriteRegionDriver(Q,g,w,B)},A.prototype.setOutputPackedMatrixWriteRegion=function(g,B,Q,w){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},A.prototype.debugValidate=function(){this.program!=null&&xo(this.gl,this.debug,this.program),qE(this.gl)},A.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var g=this.gl;this.debug&&this.debugValidate(),lA(g,this.debug,function(){return g.drawElements(g.TRIANGLES,6,g.UNSIGNED_SHORT,0)})},A.prototype.blockUntilAllProgramsCompleted=function(){var g=this;this.throwIfDisposed(),lA(this.gl,this.debug,function(){return g.gl.finish()})},A.prototype.getQueryTimerExtension=function(){return this.disjointQueryTimerExtension==null&&(this.disjointQueryTimerExtension=ZE(this.gl,this.debug,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},A.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},A.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},A.prototype.beginQuery=function(){if(BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var g=this.gl,B=this.getQueryTimerExtensionWebGL2(),Q=g.createQuery();return g.beginQuery(B.TIME_ELAPSED_EXT,Q),Q}var w=this.getQueryTimerExtensionWebGL1(),C=w.createQueryEXT();return w.beginQueryEXT(w.TIME_ELAPSED_EXT,C),C},A.prototype.endQuery=function(){if(BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")!==2){var g=this.getQueryTimerExtensionWebGL1();g.endQueryEXT(g.TIME_ELAPSED_EXT)}else{var B=this.gl,Q=this.getQueryTimerExtensionWebGL2();B.endQuery(Q.TIME_ELAPSED_EXT)}},A.prototype.waitForQueryAndGetTime=function(g){return uA(this,void 0,void 0,function(){var B=this;return UA(this,function(Q){switch(Q.label){case 0:return[4,zM(function(){return B.disposed||B.isQueryAvailable(g,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return Q.sent(),[2,this.getQueryTime(g,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},A.prototype.getQueryTime=function(g,B){if(B===0)return null;if(B===2){var Q=this.gl;return Q.getQueryParameter(g,Q.QUERY_RESULT)/1e6}var w=this.getQueryTimerExtensionWebGL1();return w.getQueryObjectEXT(g,w.QUERY_RESULT_EXT)/1e6},A.prototype.isQueryAvailable=function(g,B){if(B===0)return!0;if(B===2){var Q=this.gl,w=this.getQueryTimerExtensionWebGL2(),C=Q.getQueryParameter(g,Q.QUERY_RESULT_AVAILABLE);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(w.GPU_DISJOINT_EXT)),C&&!this.disjoint}return C=(w=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(g,w.QUERY_RESULT_AVAILABLE_EXT),this.disjoint==null&&(this.disjoint=this.gl.getParameter(w.GPU_DISJOINT_EXT)),C&&!this.disjoint},A.prototype.pollFence=function(g){var B=this;return new Promise(function(Q){B.addItemToPoll(function(){return g.isFencePassed()},function(){return Q()})})},A.prototype.pollItems=function(){for(var g=function(Q){for(var w=0;w<Q.length&&Q[w]();++w);return w-1}(this.itemsToPoll.map(function(Q){return Q.isDoneFn})),B=0;B<=g;++B)(0,this.itemsToPoll[B].resolveFn)();this.itemsToPoll=this.itemsToPoll.slice(g+1)},A.prototype.addItemToPoll=function(g,B){var Q=this;this.itemsToPoll.push({isDoneFn:g,resolveFn:B}),this.itemsToPoll.length>1||zM(function(){return Q.pollItems(),Q.itemsToPoll.length===0})},A.prototype.bindTextureToFrameBuffer=function(g){this.throwIfDisposed(),Xo(this.gl,this.debug,g,this.framebuffer),this.debug&&qE(this.gl)},A.prototype.unbindTextureToFrameBuffer=function(){this.outputTexture!=null?(Xo(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&qE(this.gl)):Bc(this.gl,this.debug,this.framebuffer)},A.prototype.downloadMatrixDriver=function(g,B){this.bindTextureToFrameBuffer(g);var Q=B();return this.unbindTextureToFrameBuffer(),Q},A.prototype.setOutputMatrixTextureDriver=function(g,B,Q){this.throwIfDisposed();var w=this.gl;Xo(w,this.debug,g,this.framebuffer),this.debug&&qE(w),this.outputTexture=g,lA(w,this.debug,function(){return w.viewport(0,0,B,Q)}),lA(w,this.debug,function(){return w.scissor(0,0,B,Q)})},A.prototype.setOutputMatrixWriteRegionDriver=function(g,B,Q,w){var C=this;this.throwIfDisposed(),lA(this.gl,this.debug,function(){return C.gl.scissor(g,B,Q,w)})},A.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},A.prototype.throwIfNoProgram=function(){if(this.program==null)throw new Error("No GPU program is currently set.")},A}();function Sc(A,g){if(A.length!==g.length)throw Error("Binary was compiled with "+A.length+" inputs, but was executed with "+g.length+" inputs");A.forEach(function(B,Q){var w=B.logicalShape,C=g[Q],E=C.shape;if(!KB(w,E))throw Error("Binary was compiled with different shapes than the current args. Shapes "+w+" and "+E+" must match");if(!B.isUniform||!C.isUniform){var e=B.texShape,I=C.isUniform?null:C.texData.texShape;if(!KB(e,I))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+e+" and "+I+" must match")}})}var uJ=function(A,g,B){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A;for(var Q=B.filterWidth,w=B.inChannels,C=B.strideWidth,E=B.strideHeight,e=B.padInfo,I=B.outWidth,o=B.dilationWidth,n=B.dilationHeight,i=B.dataFormat,Y=e.left,M=e.top,c=w*Q,D=Qg(),r=i==="channelsLast",F=r?0:1,s=r?1:2,u="",a=0;a<=1;a++)for(var U=0;U<=1;U++)u+=`
2047
+ }`)}function eJ(A,g){return CH(A,g,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function IJ(A,g){return EH(A,g,new Uint16Array([0,1,2,2,1,3]))}function pC(A,g,B,Q,w,C,E){IH(B,Q);var e=eH(A,g),I=A.TEXTURE_2D;return lA(A,g,function(){return A.bindTexture(I,e)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_MIN_FILTER,A.NEAREST)}),lA(A,g,function(){return A.texParameteri(I,A.TEXTURE_MAG_FILTER,A.NEAREST)}),lA(A,g,function(){return A.texImage2D(I,0,w,B,Q,0,C,E,null)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)}),e}function oJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],w.internalFormatFloat,w.textureFormatFloat,A.FLOAT)}function tJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],w.internalFormatHalfFloat,w.textureFormatFloat,w.textureTypeHalfFloat)}function nJ(A,g,B,Q,w){var C=OE(B,Q);return pC(A,g,C[0],C[1],A.RGBA,A.RGBA,A.UNSIGNED_BYTE)}function iJ(A,g,B,Q,w){var C=kC(B,Q);return pC(A,g,C[0],C[1],w.internalFormatPackedFloat,A.RGBA,A.FLOAT)}function YJ(A,g,B,Q,w){var C=kC(B,Q);return pC(A,g,C[0],C[1],w.internalFormatPackedHalfFloat,A.RGBA,w.textureTypeHalfFloat)}function MJ(A,g,B,Q){return lA(A,g,function(){return A.bindBuffer(A.ARRAY_BUFFER,Q)}),Ac(A,g,B,"clipSpacePos",Q,3,20,0)&&Ac(A,g,B,"uv",Q,2,20,12)}function cJ(A,g,B,Q,w,C,E){var e,I,o;lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)}),C instanceof Uint8Array?(e=new Uint8Array(Q*w*4),I=A.UNSIGNED_BYTE,o=A.RGBA):(e=new Float32Array(Q*w*4),I=A.FLOAT,o=E.internalFormatPackedFloat),e.set(C),lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,o,Q,w,0,A.RGBA,I,e)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)})}function DJ(A,g,B,Q){lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,B)}),Q.data instanceof Uint8Array?lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,A.RGBA,Q.width,Q.height,0,A.RGBA,A.UNSIGNED_BYTE,Q.data)}):lA(A,g,function(){return A.texImage2D(A.TEXTURE_2D,0,A.RGBA,A.RGBA,A.UNSIGNED_BYTE,Q)}),lA(A,g,function(){return A.bindTexture(A.TEXTURE_2D,null)})}function rJ(A,g,B,Q,w){var C=A.createBuffer();lA(A,g,function(){return A.bindBuffer(A.PIXEL_PACK_BUFFER,C)});var E=16*B*Q;return lA(A,g,function(){return A.bufferData(A.PIXEL_PACK_BUFFER,E,A.STREAM_READ)}),lA(A,g,function(){return A.readPixels(0,0,Q,B,A.RGBA,A.FLOAT,0)}),lA(A,g,function(){return A.bindBuffer(A.PIXEL_PACK_BUFFER,null)}),C}function FJ(A,g,B){var Q=A,w=new Float32Array(B);return Q.bindBuffer(Q.PIXEL_PACK_BUFFER,g),Q.getBufferSubData(Q.PIXEL_PACK_BUFFER,0,w),Q.bindBuffer(Q.PIXEL_PACK_BUFFER,null),w}function aJ(A,g,B,Q,w){var C=OE(B,Q),E=C[0],e=C[1],I=new Uint8Array(B*Q*4);return lA(A,g,function(){return A.readPixels(0,0,E,e,w.downloadTextureFormat,A.UNSIGNED_BYTE,I)}),new Float32Array(I.buffer)}function sJ(A,g,B,Q,w,C,E,e){var I=A,o=new Float32Array(function(n,i){var Y=kC(n,i);return Y[0]*Y[1]*4}(C,E));return I.bindBuffer(I.PIXEL_PACK_BUFFER,g),I.getBufferSubData(I.PIXEL_PACK_BUFFER,0,o),I.bindBuffer(I.PIXEL_PACK_BUFFER,null),o}function uJ(A,g,B,Q){var w=new Float32Array(B*Q*4);return lA(A,g,function(){return A.readPixels(0,0,Q,B,A.RGBA,A.FLOAT,w)}),w}var UJ=function(){function A(g){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var B=BA().getNumber("WEBGL_VERSION");g!=null?(this.gl=g,Od(B,g)):this.gl=_g(B);var Q="WEBGL_color_buffer_float";if(BA().getNumber("WEBGL_VERSION")===1){if(this.textureFloatExtension=ZE(this.gl,this.debug,"OES_texture_float"),vg(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=ZE(this.gl,this.debug,"OES_texture_half_float");else if(BA().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(Q),vg(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=ZE(this.gl,this.debug,"EXT_color_buffer_half_float");else if(BA().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(Q="EXT_color_buffer_float",vg(this.gl,Q))this.colorBufferFloatExtension=this.gl.getExtension(Q);else{if(!vg(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=eJ(this.gl,this.debug),this.indexBuffer=IJ(this.gl,this.debug),this.framebuffer=oH(this.gl,this.debug),this.textureConfig=Ko(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(A.prototype,"debug",{get:function(){return BA().getBool("DEBUG")},enumerable:!0,configurable:!0}),A.prototype.dispose=function(){var g=this;if(!this.disposed){this.program!=null&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),this.outputTexture!=null&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var B=this.gl;lA(B,this.debug,function(){return B.finish()}),lA(B,this.debug,function(){return B.bindFramebuffer(B.FRAMEBUFFER,null)}),lA(B,this.debug,function(){return B.deleteFramebuffer(g.framebuffer)}),lA(B,this.debug,function(){return B.bindBuffer(B.ARRAY_BUFFER,null)}),lA(B,this.debug,function(){return B.bindBuffer(B.ELEMENT_ARRAY_BUFFER,null)}),lA(B,this.debug,function(){return B.deleteBuffer(g.indexBuffer)}),this.disposed=!0}},A.prototype.createFloat32MatrixTexture=function(g,B){return this.throwIfDisposed(),oJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createFloat16MatrixTexture=function(g,B){return this.throwIfDisposed(),tJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createUnsignedBytesMatrixTexture=function(g,B){return this.throwIfDisposed(),nJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.uploadPixelDataToTexture=function(g,B){this.throwIfDisposed(),DJ(this.gl,this.debug,g,B)},A.prototype.uploadDenseMatrixToTexture=function(g,B,Q,w){this.throwIfDisposed(),cJ(this.gl,this.debug,g,B,Q,w,this.textureConfig)},A.prototype.createFloat16PackedMatrixTexture=function(g,B){return this.throwIfDisposed(),YJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.createPackedMatrixTexture=function(g,B){return this.throwIfDisposed(),iJ(this.gl,this.debug,g,B,this.textureConfig)},A.prototype.deleteMatrixTexture=function(g){var B=this;this.throwIfDisposed(),this.outputTexture===g&&(Bc(this.gl,this.debug,this.framebuffer),this.outputTexture=null),lA(this.gl,this.debug,function(){return B.gl.deleteTexture(g)})},A.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(g,B,Q){var w=this;return this.downloadMatrixDriver(g,function(){return aJ(w.gl,w.debug,B,Q,w.textureConfig)})},A.prototype.downloadPackedMatrixFromBuffer=function(g,B,Q,w,C,E){return sJ(this.gl,g,0,0,0,C,E,this.textureConfig)},A.prototype.downloadFloat32MatrixFromBuffer=function(g,B){return FJ(this.gl,g,B)},A.prototype.createBufferFromTexture=function(g,B,Q){this.bindTextureToFrameBuffer(g);var w=rJ(this.gl,this.debug,B,Q,this.textureConfig);return this.unbindTextureToFrameBuffer(),w},A.prototype.createAndWaitForFence=function(){var g=this.createFence(this.gl);return this.pollFence(g)},A.prototype.createFence=function(g){var B,Q,w=this;if(BA().getBool("WEBGL_FENCE_API_ENABLED")){var C=g,E=C.fenceSync(C.SYNC_GPU_COMMANDS_COMPLETE,0);g.flush(),Q=function(){var e=C.clientWaitSync(E,0,0);return e===C.ALREADY_SIGNALED||e===C.CONDITION_SATISFIED},B=E}else BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(B=this.beginQuery(),this.endQuery(),Q=function(){return w.isQueryAvailable(B,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):Q=function(){return!0};return{query:B,isFencePassed:Q}},A.prototype.downloadMatrixFromPackedTexture=function(g,B,Q){var w=this;return this.downloadMatrixDriver(g,function(){return uJ(w.gl,w.debug,B,Q)})},A.prototype.createProgram=function(g){this.throwIfDisposed();var B=this.gl,Q=BH(B,this.debug,g),w=EJ(B,this.debug),C=QH(B,this.debug);return lA(B,this.debug,function(){return B.attachShader(C,w)}),lA(B,this.debug,function(){return B.attachShader(C,Q)}),wH(B,this.debug,C),this.debug&&Xo(B,this.debug,C),this.vertexAttrsAreBound||(this.setProgram(C),this.vertexAttrsAreBound=MJ(B,this.debug,this.program,this.vertexBuffer)),C},A.prototype.deleteProgram=function(g){var B=this;this.throwIfDisposed(),g===this.program&&(this.program=null),g!=null&&lA(this.gl,this.debug,function(){return B.gl.deleteProgram(g)})},A.prototype.setProgram=function(g){var B=this;this.throwIfDisposed(),this.program=g,this.program!=null&&this.debug&&Xo(this.gl,this.debug,this.program),lA(this.gl,this.debug,function(){return B.gl.useProgram(g)})},A.prototype.getUniformLocation=function(g,B,Q){return Q===void 0&&(Q=!0),this.throwIfDisposed(),Q?nH(this.gl,this.debug,g,B):iH(this.gl,g,B)},A.prototype.getAttributeLocation=function(g,B){var Q=this;return this.throwIfDisposed(),lA(this.gl,this.debug,function(){return Q.gl.getAttribLocation(g,B)})},A.prototype.getUniformLocationNoThrow=function(g,B){return this.throwIfDisposed(),this.gl.getUniformLocation(g,B)},A.prototype.setInputMatrixTexture=function(g,B,Q){this.throwIfDisposed(),this.throwIfNoProgram(),YH(this.gl,this.debug,this.program,g,B,Q)},A.prototype.setOutputMatrixTexture=function(g,B,Q){this.setOutputMatrixTextureDriver(g,Q,B)},A.prototype.setOutputPackedMatrixTexture=function(g,B,Q){this.throwIfDisposed();var w=kC(B,Q),C=w[0],E=w[1];this.setOutputMatrixTextureDriver(g,C,E)},A.prototype.setOutputMatrixWriteRegion=function(g,B,Q,w){this.setOutputMatrixWriteRegionDriver(Q,g,w,B)},A.prototype.setOutputPackedMatrixWriteRegion=function(g,B,Q,w){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},A.prototype.debugValidate=function(){this.program!=null&&Xo(this.gl,this.debug,this.program),qE(this.gl)},A.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var g=this.gl;this.debug&&this.debugValidate(),lA(g,this.debug,function(){return g.drawElements(g.TRIANGLES,6,g.UNSIGNED_SHORT,0)})},A.prototype.blockUntilAllProgramsCompleted=function(){var g=this;this.throwIfDisposed(),lA(this.gl,this.debug,function(){return g.gl.finish()})},A.prototype.getQueryTimerExtension=function(){return this.disjointQueryTimerExtension==null&&(this.disjointQueryTimerExtension=ZE(this.gl,this.debug,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},A.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},A.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},A.prototype.beginQuery=function(){if(BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var g=this.gl,B=this.getQueryTimerExtensionWebGL2(),Q=g.createQuery();return g.beginQuery(B.TIME_ELAPSED_EXT,Q),Q}var w=this.getQueryTimerExtensionWebGL1(),C=w.createQueryEXT();return w.beginQueryEXT(w.TIME_ELAPSED_EXT,C),C},A.prototype.endQuery=function(){if(BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")!==2){var g=this.getQueryTimerExtensionWebGL1();g.endQueryEXT(g.TIME_ELAPSED_EXT)}else{var B=this.gl,Q=this.getQueryTimerExtensionWebGL2();B.endQuery(Q.TIME_ELAPSED_EXT)}},A.prototype.waitForQueryAndGetTime=function(g){return uA(this,void 0,void 0,function(){var B=this;return UA(this,function(Q){switch(Q.label){case 0:return[4,zM(function(){return B.disposed||B.isQueryAvailable(g,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return Q.sent(),[2,this.getQueryTime(g,BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},A.prototype.getQueryTime=function(g,B){if(B===0)return null;if(B===2){var Q=this.gl;return Q.getQueryParameter(g,Q.QUERY_RESULT)/1e6}var w=this.getQueryTimerExtensionWebGL1();return w.getQueryObjectEXT(g,w.QUERY_RESULT_EXT)/1e6},A.prototype.isQueryAvailable=function(g,B){if(B===0)return!0;if(B===2){var Q=this.gl,w=this.getQueryTimerExtensionWebGL2(),C=Q.getQueryParameter(g,Q.QUERY_RESULT_AVAILABLE);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(w.GPU_DISJOINT_EXT)),C&&!this.disjoint}return C=(w=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(g,w.QUERY_RESULT_AVAILABLE_EXT),this.disjoint==null&&(this.disjoint=this.gl.getParameter(w.GPU_DISJOINT_EXT)),C&&!this.disjoint},A.prototype.pollFence=function(g){var B=this;return new Promise(function(Q){B.addItemToPoll(function(){return g.isFencePassed()},function(){return Q()})})},A.prototype.pollItems=function(){for(var g=function(Q){for(var w=0;w<Q.length&&Q[w]();++w);return w-1}(this.itemsToPoll.map(function(Q){return Q.isDoneFn})),B=0;B<=g;++B)(0,this.itemsToPoll[B].resolveFn)();this.itemsToPoll=this.itemsToPoll.slice(g+1)},A.prototype.addItemToPoll=function(g,B){var Q=this;this.itemsToPoll.push({isDoneFn:g,resolveFn:B}),this.itemsToPoll.length>1||zM(function(){return Q.pollItems(),Q.itemsToPoll.length===0})},A.prototype.bindTextureToFrameBuffer=function(g){this.throwIfDisposed(),Oo(this.gl,this.debug,g,this.framebuffer),this.debug&&qE(this.gl)},A.prototype.unbindTextureToFrameBuffer=function(){this.outputTexture!=null?(Oo(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&qE(this.gl)):Bc(this.gl,this.debug,this.framebuffer)},A.prototype.downloadMatrixDriver=function(g,B){this.bindTextureToFrameBuffer(g);var Q=B();return this.unbindTextureToFrameBuffer(),Q},A.prototype.setOutputMatrixTextureDriver=function(g,B,Q){this.throwIfDisposed();var w=this.gl;Oo(w,this.debug,g,this.framebuffer),this.debug&&qE(w),this.outputTexture=g,lA(w,this.debug,function(){return w.viewport(0,0,B,Q)}),lA(w,this.debug,function(){return w.scissor(0,0,B,Q)})},A.prototype.setOutputMatrixWriteRegionDriver=function(g,B,Q,w){var C=this;this.throwIfDisposed(),lA(this.gl,this.debug,function(){return C.gl.scissor(g,B,Q,w)})},A.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},A.prototype.throwIfNoProgram=function(){if(this.program==null)throw new Error("No GPU program is currently set.")},A}();function Sc(A,g){if(A.length!==g.length)throw Error("Binary was compiled with "+A.length+" inputs, but was executed with "+g.length+" inputs");A.forEach(function(B,Q){var w=B.logicalShape,C=g[Q],E=C.shape;if(!KB(w,E))throw Error("Binary was compiled with different shapes than the current args. Shapes "+w+" and "+E+" must match");if(!B.isUniform||!C.isUniform){var e=B.texShape,I=C.isUniform?null:C.texData.texShape;if(!KB(e,I))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+e+" and "+I+" must match")}})}var GJ=function(A,g,B){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A;for(var Q=B.filterWidth,w=B.inChannels,C=B.strideWidth,E=B.strideHeight,e=B.padInfo,I=B.outWidth,o=B.dilationWidth,n=B.dilationHeight,i=B.dataFormat,Y=e.left,M=e.top,c=w*Q,D=Qg(),r=i==="channelsLast",F=r?0:1,s=r?1:2,u="",a=0;a<=1;a++)for(var U=0;U<=1;U++)u+=`
2048
2048
  blockIndex = rc.y + `+U+`;
2049
2049
  pos = rc.x + `+a+`;
2050
2050
 
@@ -2088,7 +2088,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2088
2088
 
2089
2089
  `+D.output+` = result;
2090
2090
  }
2091
- `},UJ=function(A,g,B,Q,w){this.variableNames=["x"],this.outputShape=[];var C,E=g,e=A[3]-1;this.outputShape=A;var I="float("+B+") + float("+Q+") * sum";C=w===.5?"inversesqrt("+I+")":w===1?"1.0/("+I+")":"exp(log("+I+") * float(-"+w+"));",this.userCode=`
2091
+ `},hJ=function(A,g,B,Q,w){this.variableNames=["x"],this.outputShape=[];var C,E=g,e=A[3]-1;this.outputShape=A;var I="float("+B+") + float("+Q+") * sum";C=w===.5?"inversesqrt("+I+")":w===1?"1.0/("+I+")":"exp(log("+I+") * float(-"+w+"));",this.userCode=`
2092
2092
  void main() {
2093
2093
  ivec4 coords = getOutputCoords();
2094
2094
  int b = coords[0];
@@ -2107,7 +2107,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2107
2107
  float val = x * `+C+`;
2108
2108
  setOutput(val);
2109
2109
  }
2110
- `},GJ=function(A,g,B,Q,w){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=A,this.depth=A[3],this.depthRadius=g,this.bias=B,this.alpha=Q,this.beta=w,this.userCode=`
2110
+ `},lJ=function(A,g,B,Q,w){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=A,this.depth=A[3],this.depthRadius=g,this.bias=B,this.alpha=Q,this.beta=w,this.userCode=`
2111
2111
  void main() {
2112
2112
  ivec4 coords = getOutputCoords();
2113
2113
  int b = coords[0];
@@ -2162,7 +2162,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2162
2162
  }
2163
2163
  setOutput(result);
2164
2164
  }
2165
- `},hJ=function(A,g,B,Q,w){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var C,E=g,e=A[3]-1;this.outputShape=A;var I="float("+B+") + float("+Q+") * sum";C=w===.5?"inversesqrt("+I+")":w===1?"1.0/("+I+")":"exp(log("+I+") * float(-"+w+"));",this.userCode=`
2165
+ `},dJ=function(A,g,B,Q,w){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var C,E=g,e=A[3]-1;this.outputShape=A;var I="float("+B+") + float("+Q+") * sum";C=w===.5?"inversesqrt("+I+")":w===1?"1.0/("+I+")":"exp(log("+I+") * float(-"+w+"));",this.userCode=`
2166
2166
  void main() {
2167
2167
  ivec4 coords = getOutputCoords();
2168
2168
  int b = coords.x;
@@ -2224,7 +2224,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2224
2224
  vec4 result = xAtOutputCoords * `+C+`;
2225
2225
  setOutput(result);
2226
2226
  }
2227
- `},lJ=function(A){this.variableNames=["dy","maxPos"],this.outputShape=A.inShape;var g=A.strideHeight,B=A.strideWidth,Q=A.dilationHeight,w=A.effectiveFilterHeight,C=A.effectiveFilterWidth,E=w-1-A.padInfo.top,e=C-1-A.padInfo.left,I=w*C-1;this.userCode=`
2227
+ `},HJ=function(A){this.variableNames=["dy","maxPos"],this.outputShape=A.inShape;var g=A.strideHeight,B=A.strideWidth,Q=A.dilationHeight,w=A.effectiveFilterHeight,C=A.effectiveFilterWidth,E=w-1-A.padInfo.top,e=C-1-A.padInfo.left,I=w*C-1;this.userCode=`
2228
2228
  const ivec2 pads = ivec2(`+E+", "+e+`);
2229
2229
 
2230
2230
  void main() {
@@ -2270,7 +2270,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2270
2270
  }
2271
2271
  setOutput(dotProd);
2272
2272
  }
2273
- `},dJ=function(A){this.variableNames=["dy","maxPos"],this.outputShape=A.inShape;var g=A.strideDepth,B=A.strideHeight,Q=A.strideWidth,w=A.dilationDepth,C=A.dilationHeight,E=A.dilationWidth,e=A.effectiveFilterDepth,I=A.effectiveFilterHeight,o=A.effectiveFilterWidth,n=e-1-A.padInfo.front,i=I-1-A.padInfo.top,Y=o-1-A.padInfo.left,M=e*I*o-1;this.userCode=`
2273
+ `},fJ=function(A){this.variableNames=["dy","maxPos"],this.outputShape=A.inShape;var g=A.strideDepth,B=A.strideHeight,Q=A.strideWidth,w=A.dilationDepth,C=A.dilationHeight,E=A.dilationWidth,e=A.effectiveFilterDepth,I=A.effectiveFilterHeight,o=A.effectiveFilterWidth,n=e-1-A.padInfo.front,i=I-1-A.padInfo.top,Y=o-1-A.padInfo.left,M=e*I*o-1;this.userCode=`
2274
2274
  const ivec3 pads = ivec3(`+n+", "+i+", "+Y+`);
2275
2275
 
2276
2276
  void main() {
@@ -2334,7 +2334,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2334
2334
  }
2335
2335
  setOutput(dotProd);
2336
2336
  }
2337
- `},Mt=function(A,g,B,Q,w,C,E){B===void 0&&(B=!1),Q===void 0&&(Q=!1),w===void 0&&(w=!1),C===void 0&&(C=null),E===void 0&&(E=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g;var e=B?A[1]:A[2],I=Math.ceil(e/2),o=B?"i * 2, rc.y":"rc.y, i * 2",n=Q?"rc.z, i * 2":"i * 2, rc.z",i=B?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],Y=Q?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],M="",c="";C&&(M=E?`vec4 activation(vec4 a) {
2337
+ `},ct=function(A,g,B,Q,w,C,E){B===void 0&&(B=!1),Q===void 0&&(Q=!1),w===void 0&&(w=!1),C===void 0&&(C=null),E===void 0&&(E=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g;var e=B?A[1]:A[2],I=Math.ceil(e/2),o=B?"i * 2, rc.y":"rc.y, i * 2",n=Q?"rc.z, i * 2":"i * 2, rc.z",i=B?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],Y=Q?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],M="",c="";C&&(M=E?`vec4 activation(vec4 a) {
2338
2338
  vec4 b = getPreluActivationWeightsAtOutCoords();
2339
2339
  `+C+`
2340
2340
  }`:`vec4 activation(vec4 x) {
@@ -2368,7 +2368,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2368
2368
 
2369
2369
  setOutput(result);
2370
2370
  }
2371
- `},HJ=function(){function A(g,B,Q){this.variableNames=["probs"],this.outputShape=[g,Q],this.userCode=`
2371
+ `},JJ=function(){function A(g,B,Q){this.variableNames=["probs"],this.outputShape=[g,Q],this.userCode=`
2372
2372
  uniform float seed;
2373
2373
 
2374
2374
  void main() {
@@ -2390,14 +2390,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2390
2390
  // If no other event happened, last event happened.
2391
2391
  setOutput(float(`+(B-1)+`));
2392
2392
  }
2393
- `}return A.prototype.getCustomSetupFunc=function(g){var B=this;return function(Q,w){B.seedLoc==null&&(B.seedLoc=Q.getUniformLocation(w,"seed")),Q.gl.uniform1f(B.seedLoc,g)}},A}(),fJ=function(A,g,B,Q){this.variableNames=["indices"],this.outputShape=[A,g],this.userCode=`
2393
+ `}return A.prototype.getCustomSetupFunc=function(g){var B=this;return function(Q,w){B.seedLoc==null&&(B.seedLoc=Q.getUniformLocation(w,"seed")),Q.gl.uniform1f(B.seedLoc,g)}},A}(),NJ=function(A,g,B,Q){this.variableNames=["indices"],this.outputShape=[A,g],this.userCode=`
2394
2394
  void main() {
2395
2395
  ivec2 coords = getOutputCoords();
2396
2396
  int index = round(getIndices(coords.x));
2397
2397
  setOutput(mix(float(`+Q+"), float("+B+`),
2398
2398
  float(index == coords.y)));
2399
2399
  }
2400
- `},JJ=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=A;var g=A.length;if(g===0)this.userCode=`
2400
+ `},mJ=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=A;var g=A.length;if(g===0)this.userCode=`
2401
2401
  void main() {
2402
2402
  setOutput(vec4(getA(), 0., 0., 0.));
2403
2403
  }
@@ -2426,7 +2426,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2426
2426
  setOutput(vec4(`+E+`));
2427
2427
  }
2428
2428
  }
2429
- `}},NJ=function(A,g,B){this.variableNames=["x"],this.outputShape=g.map(function(I,o){return I[0]+A[o]+I[1]});var Q=A.length,w=nB(Q),C=g.map(function(I){return I[0]}).join(","),E=g.map(function(I,o){return I[0]+A[o]}).join(","),e=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,Q);this.userCode=Q!==1?`
2429
+ `}},RJ=function(A,g,B){this.variableNames=["x"],this.outputShape=g.map(function(I,o){return I[0]+A[o]+I[1]});var Q=A.length,w=nB(Q),C=g.map(function(I){return I[0]}).join(","),E=g.map(function(I,o){return I[0]+A[o]}).join(","),e=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,Q);this.userCode=Q!==1?`
2430
2430
  `+w+" start = "+w+"("+C+`);
2431
2431
  `+w+" end = "+w+"("+E+`);
2432
2432
 
@@ -2451,7 +2451,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2451
2451
  setOutput(getX(outC - start));
2452
2452
  }
2453
2453
  }
2454
- `},mJ=function(A,g,B){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g.map(function(r,F){return r[0]+A[F]+r[1]});for(var Q=A.length,w=nB(Q),C=g.map(function(r){return r[0]}).join(","),E=g.map(function(r,F){return r[0]+A[F]}).join(","),e=Fg("rc",Q),I=Fg("source",Q),o=e[Q-1]+" < "+this.outputShape[Q-1],n=Q===1?"source":"vec2("+I.slice(-2).join()+")",i=[w+" rc = outputLoc;",e[Q-1]+` += 1;
2454
+ `},PJ=function(A,g,B){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g.map(function(r,F){return r[0]+A[F]+r[1]});for(var Q=A.length,w=nB(Q),C=g.map(function(r){return r[0]}).join(","),E=g.map(function(r,F){return r[0]+A[F]}).join(","),e=Fg("rc",Q),I=Fg("source",Q),o=e[Q-1]+" < "+this.outputShape[Q-1],n=Q===1?"source":"vec2("+I.slice(-2).join()+")",i=[w+" rc = outputLoc;",e[Q-1]+` += 1;
2455
2455
  if(`+o+`) {
2456
2456
  `,Q===1?"":`}
2457
2457
  rc = outputLoc;
@@ -2475,7 +2475,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2475
2475
  `+M+`
2476
2476
  setOutput(result);
2477
2477
  }
2478
- `},ct=function(A,g,B){if(this.variableNames=["x"],g==="avg"&&B)throw new Error("Cannot compute positions for average pool.");var Q=A.filterWidth,w=A.strideHeight,C=A.strideWidth,E=A.dilationHeight,e=A.dilationWidth,I=A.effectiveFilterHeight,o=A.effectiveFilterWidth,n=A.padInfo.top,i=A.padInfo.left;this.outputShape=A.outShape;var Y=g==="avg",M="0.0";if(Y||(M="-1.0 / 1e-20"),B)this.userCode=`
2478
+ `},Dt=function(A,g,B){if(this.variableNames=["x"],g==="avg"&&B)throw new Error("Cannot compute positions for average pool.");var Q=A.filterWidth,w=A.strideHeight,C=A.strideWidth,E=A.dilationHeight,e=A.dilationWidth,I=A.effectiveFilterHeight,o=A.effectiveFilterWidth,n=A.padInfo.top,i=A.padInfo.left;this.outputShape=A.outShape;var Y=g==="avg",M="0.0";if(Y||(M="-1.0 / 1e-20"),B)this.userCode=`
2479
2479
  const ivec2 strides = ivec2(`+w+", "+C+`);
2480
2480
  const ivec2 pads = ivec2(`+n+", "+i+`);
2481
2481
 
@@ -2616,7 +2616,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2616
2616
  }
2617
2617
  setOutput(`+c+`);
2618
2618
  }
2619
- `}},Dt=function(A,g,B){if(this.variableNames=["x"],g==="avg"&&B)throw new Error("Cannot compute positions for average pool.");var Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.effectiveFilterDepth,i=A.effectiveFilterHeight,Y=A.effectiveFilterWidth,M=A.padInfo.front,c=A.padInfo.top,D=A.padInfo.left;this.outputShape=A.outShape;var r=g==="avg",F="0.0";if(r||(F="-1.0 / 1e-20"),B)this.userCode=`
2619
+ `}},rt=function(A,g,B){if(this.variableNames=["x"],g==="avg"&&B)throw new Error("Cannot compute positions for average pool.");var Q=A.filterWidth,w=A.strideDepth,C=A.strideHeight,E=A.strideWidth,e=A.dilationDepth,I=A.dilationHeight,o=A.dilationWidth,n=A.effectiveFilterDepth,i=A.effectiveFilterHeight,Y=A.effectiveFilterWidth,M=A.padInfo.front,c=A.padInfo.top,D=A.padInfo.left;this.outputShape=A.outShape;var r=g==="avg",F="0.0";if(r||(F="-1.0 / 1e-20"),B)this.userCode=`
2620
2620
  const ivec3 strides =
2621
2621
  ivec3(`+w+", "+C+", "+E+`);
2622
2622
  const ivec3 pads = ivec3(`+M+", "+c+", "+D+`);
@@ -2780,7 +2780,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2780
2780
  setOutput(`+s+`);
2781
2781
  }
2782
2782
  }
2783
- `}},RJ=function(A,g){this.variableNames=["x"];var B=A.windowSize,Q=A.batchSize,w=A.inSize,C=Math.ceil(w/B);this.outputShape=[Q,C];var E="0.0",e="";g==="prod"?E="1.0":g==="min"?(E="1.0 / 1e-20",e="min"):g==="max"&&(E="-1.0 / 1e-20",e="max");var I=g+"("+g+"("+g+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";g==="sum"?I="sumValue":g==="prod"?I="prodValue":g==="all"?I="allValue":g==="any"&&(I="anyValue");var o=4*Math.floor(B/4),n=B%4,i=`
2783
+ `}},vJ=function(A,g){this.variableNames=["x"];var B=A.windowSize,Q=A.batchSize,w=A.inSize,C=Math.ceil(w/B);this.outputShape=[Q,C];var E="0.0",e="";g==="prod"?E="1.0":g==="min"?(E="1.0 / 1e-20",e="min"):g==="max"&&(E="-1.0 / 1e-20",e="max");var I=g+"("+g+"("+g+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";g==="sum"?I="sumValue":g==="prod"?I="prodValue":g==="all"?I="allValue":g==="any"&&(I="anyValue");var o=4*Math.floor(B/4),n=B%4,i=`
2784
2784
  if (`+(g==="sum")+`) {
2785
2785
  sumValue += dot(values, ones);
2786
2786
  } else if (`+(g==="prod")+`) {
@@ -2865,7 +2865,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2865
2865
  }
2866
2866
  setOutput(`+I+`);
2867
2867
  }
2868
- `},PJ=function(A,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A;for(var B="",Q=0;Q<4;Q++){var w="thisRC = rc;";Q%2==1&&(w+="thisRC.z += 1;"),Q>1&&(w+="thisRC.y += 1;"),B+=`
2868
+ `},kJ=function(A,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=A;for(var B="",Q=0;Q<4;Q++){var w="thisRC = rc;";Q%2==1&&(w+="thisRC.z += 1;"),Q>1&&(w+="thisRC.y += 1;"),B+=`
2869
2869
  `+w+`
2870
2870
  `+(Q>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+`
2871
2871
  int flatIndex = getFlatIndex(thisRC);
@@ -2883,7 +2883,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2883
2883
  return ivec3(r, c, d);
2884
2884
  }
2885
2885
 
2886
- `+nt(A)+`
2886
+ `+it(A)+`
2887
2887
 
2888
2888
  void main() {
2889
2889
  ivec3 rc = getOutputCoords();
@@ -2898,7 +2898,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2898
2898
 
2899
2899
  setOutput(result);
2900
2900
  }
2901
- `},vJ=function(A,g,B){this.variableNames=["dy"],this.outputShape=[],this.outputShape=g.shape;var Q=g.shape,w=Q[1],C=Q[2],E=A.shape,e=E[1],I=E[2],o=[B&&e>1?w-1:w,B&&I>1?C-1:C],n=[B&&e>1?e-1:e,B&&I>1?I-1:I],i=o[0]/n[0],Y=o[1]/n[1],M=1/i,c=1/Y,D=2*Math.ceil(M)+2,r=2*Math.ceil(c)+2;this.userCode=`
2901
+ `},TJ=function(A,g,B){this.variableNames=["dy"],this.outputShape=[],this.outputShape=g.shape;var Q=g.shape,w=Q[1],C=Q[2],E=A.shape,e=E[1],I=E[2],o=[B&&e>1?w-1:w,B&&I>1?C-1:C],n=[B&&e>1?e-1:e,B&&I>1?I-1:I],i=o[0]/n[0],Y=o[1]/n[1],M=1/i,c=1/Y,D=2*Math.ceil(M)+2,r=2*Math.ceil(c)+2;this.userCode=`
2902
2902
  void main() {
2903
2903
  ivec4 coords = getOutputCoords();
2904
2904
  int b = coords[0];
@@ -2979,7 +2979,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
2979
2979
 
2980
2980
  setOutput(accumulator);
2981
2981
  }
2982
- `},kJ=function(A,g,B,Q){this.variableNames=["A"],this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B];this.userCode=`
2982
+ `},jJ=function(A,g,B,Q){this.variableNames=["A"],this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B];this.userCode=`
2983
2983
  const vec2 effectiveInputOverOutputRatioRC = vec2(
2984
2984
  `+I[0]/o[0]+`,
2985
2985
  `+I[1]/o[1]+`);
@@ -3012,7 +3012,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3012
3012
 
3013
3013
  setOutput(newValue);
3014
3014
  }
3015
- `},TJ=function(A,g,B,Q){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B];this.userCode=`
3015
+ `},pJ=function(A,g,B,Q){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B];this.userCode=`
3016
3016
  const vec3 effectiveInputOverOutputRatioRC = vec3(
3017
3017
  `+I[0]/o[0]+`,
3018
3018
  `+I[1]/o[1]+`,
@@ -3089,7 +3089,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3089
3089
 
3090
3090
  setOutput(newValue);
3091
3091
  }
3092
- `},jJ=function(A,g,B){this.variableNames=["dy"],this.outputShape=[],this.outputShape=g.shape;var Q=g.shape,w=Q[1],C=Q[2],E=A.shape,e=E[1],I=E[2],o=[B&&e>1?w-1:w,B&&I>1?C-1:C],n=[B&&e>1?e-1:e,B&&I>1?I-1:I],i=o[0]/n[0],Y=o[1]/n[1],M=1/i,c=1/Y,D=2*Math.ceil(M)+2,r=2*Math.ceil(c)+2;this.userCode=`
3092
+ `},yJ=function(A,g,B){this.variableNames=["dy"],this.outputShape=[],this.outputShape=g.shape;var Q=g.shape,w=Q[1],C=Q[2],E=A.shape,e=E[1],I=E[2],o=[B&&e>1?w-1:w,B&&I>1?C-1:C],n=[B&&e>1?e-1:e,B&&I>1?I-1:I],i=o[0]/n[0],Y=o[1]/n[1],M=1/i,c=1/Y,D=2*Math.ceil(M)+2,r=2*Math.ceil(c)+2;this.userCode=`
3093
3093
  void main() {
3094
3094
  ivec4 coords = getOutputCoords();
3095
3095
  int b = coords[0];
@@ -3159,7 +3159,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3159
3159
 
3160
3160
  setOutput(accumulator);
3161
3161
  }
3162
- `},pJ=function(A,g,B,Q){this.variableNames=["A"],this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B],n=Q?"0.5":"0.0";this.userCode=`
3162
+ `},zJ=function(A,g,B,Q){this.variableNames=["A"],this.outputShape=[];var w=A[0],C=A[1],E=A[2],e=A[3];this.outputShape=[w,g,B,e];var I=[Q&&g>1?C-1:C,Q&&B>1?E-1:E],o=[Q&&g>1?g-1:g,Q&&B>1?B-1:B],n=Q?"0.5":"0.0";this.userCode=`
3163
3163
  const vec2 effectiveInputOverOutputRatioRC = vec2(
3164
3164
  `+I[0]/o[0]+`,
3165
3165
  `+I[1]/o[1]+`);
@@ -3182,7 +3182,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3182
3182
 
3183
3183
  setOutput(newValue);
3184
3184
  }
3185
- `},yJ=function(A,g){this.variableNames=["x"];var B=A.length;if(B>4)throw new Error("WebGL backend: Reverse of rank-"+B+" tensor is not yet supported");if(this.outputShape=A,B!==1){var Q=A.map(function(C,E){return function(e){return g.indexOf(e)!==-1&&A[e]!==1?A[e]+" - coords["+e+"] - 1":"coords["+e+"]"}(E)}).join(","),w=nB(B);this.userCode=`
3185
+ `},WJ=function(A,g){this.variableNames=["x"];var B=A.length;if(B>4)throw new Error("WebGL backend: Reverse of rank-"+B+" tensor is not yet supported");if(this.outputShape=A,B!==1){var Q=A.map(function(C,E){return function(e){return g.indexOf(e)!==-1&&A[e]!==1?A[e]+" - coords["+e+"] - 1":"coords["+e+"]"}(E)}).join(","),w=nB(B);this.userCode=`
3186
3186
  void main() {
3187
3187
  `+w+` coords = getOutputCoords();
3188
3188
  setOutput(getX(`+Q+`));
@@ -3192,7 +3192,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3192
3192
  int coord = getOutputCoords();
3193
3193
  setOutput(getX(`+A[0]+` - coord - 1));
3194
3194
  }
3195
- `},zJ=function(A,g){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var B=A.length;if(B>4)throw new Error("WebGL backend: Reverse of rank-"+B+" tensor is not yet supported");this.outputShape=A;var Q=Fg("rc",B),w=Q[B-1]+" + 1 < "+this.outputShape[B-1],C=Q[B-2]+" + 1 < "+this.outputShape[B-2],E=nB(B);function e(I){var o=A.map(function(n,i){return function(Y,M){return g.indexOf(Y)!==-1&&A[Y]!==1?A[Y]+" - "+M[Y]+" - 1":""+M[Y]}(i,I)});return"getChannel(getX("+o.join(",")+"), vec2("+o.slice(-2).join(",")+"))"}this.userCode=B===1?`
3195
+ `},SJ=function(A,g){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var B=A.length;if(B>4)throw new Error("WebGL backend: Reverse of rank-"+B+" tensor is not yet supported");this.outputShape=A;var Q=Fg("rc",B),w=Q[B-1]+" + 1 < "+this.outputShape[B-1],C=Q[B-2]+" + 1 < "+this.outputShape[B-2],E=nB(B);function e(I){var o=A.map(function(n,i){return function(Y,M){return g.indexOf(Y)!==-1&&A[Y]!==1?A[Y]+" - "+M[Y]+" - 1":""+M[Y]}(i,I)});return"getChannel(getX("+o.join(",")+"), vec2("+o.slice(-2).join(",")+"))"}this.userCode=B===1?`
3196
3196
  void main(){
3197
3197
  int rc = getOutputCoords();
3198
3198
  vec4 result = vec4(0.);
@@ -3240,7 +3240,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3240
3240
  }
3241
3241
  setOutput(mix(getDefaultValue(), sum, float(found)));
3242
3242
  }
3243
- `},WJ=function(A,g){this.variableNames=["x","segmentIds"];var B=A.windowSize,Q=A.batchSize,w=A.inSize,C=A.numSegments,E=C*Math.ceil(w/B);this.outputShape=[Q,E];var e=4*Math.floor(B/4),I=B%4,o=`
3243
+ `},LJ=function(A,g){this.variableNames=["x","segmentIds"];var B=A.windowSize,Q=A.batchSize,w=A.inSize,C=A.numSegments,E=C*Math.ceil(w/B);this.outputShape=[Q,E];var e=4*Math.floor(B/4),I=B%4,o=`
3244
3244
  sumValue += dot(values, segFilter);
3245
3245
  `,n="";w%B>0&&(n=`
3246
3246
  if (inIdx < 0 || inIdx >= `+w+`) {
@@ -3346,7 +3346,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3346
3346
  }
3347
3347
  setOutput(sumValue);
3348
3348
  }
3349
- `},SJ=function(A,g,B){var Q,w;if(this.variableNames=["c","a","b"],this.outputShape=g,B>4)throw Error("Where for rank "+B+" is not yet supported");if(B===1)w="resRC",Q="resRC";else{for(var C=["resRC.x","resRC.y","resRC.z","resRC.w"],E=[],e=[],I=0;I<g.length;I++)e.push(""+C[I]),I<A&&E.push(""+C[I]);Q=E.join(),w=e.join()}var o=nB(B);this.userCode=`
3349
+ `},bJ=function(A,g,B){var Q,w;if(this.variableNames=["c","a","b"],this.outputShape=g,B>4)throw Error("Where for rank "+B+" is not yet supported");if(B===1)w="resRC",Q="resRC";else{for(var C=["resRC.x","resRC.y","resRC.z","resRC.w"],E=[],e=[],I=0;I<g.length;I++)e.push(""+C[I]),I<A&&E.push(""+C[I]);Q=E.join(),w=e.join()}var o=nB(B);this.userCode=`
3350
3350
  void main() {
3351
3351
  `+o+` resRC = getOutputCoords();
3352
3352
  float cVal = getC(`+Q+`);
@@ -3356,10 +3356,10 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3356
3356
  setOutput(getB(`+w+`));
3357
3357
  }
3358
3358
  }
3359
- `},LJ=function(){function A(g){this.variableNames=["source"],this.outputShape=g,this.rank=g.length;var B,Q=nB(this.rank),w="uniform int start["+this.rank+"];",C=function(E){if(E===1)return"sourceLoc";if(E<=6)return rt.slice(0,E).map(function(e){return"sourceLoc."+e}).join(",");throw Error("Slicing for rank "+E+" is not yet supported")}(this.rank);B=`
3359
+ `},KJ=function(){function A(g){this.variableNames=["source"],this.outputShape=g,this.rank=g.length;var B,Q=nB(this.rank),w="uniform int start["+this.rank+"];",C=function(E){if(E===1)return"sourceLoc";if(E<=6)return Ft.slice(0,E).map(function(e){return"sourceLoc."+e}).join(",");throw Error("Slicing for rank "+E+" is not yet supported")}(this.rank);B=`
3360
3360
  `+Q+` sourceLoc;
3361
3361
  `+Q+` coords = getOutputCoords();
3362
- `+g.map(function(E,e){return"sourceLoc."+rt[e]+" = start["+e+"] + coords."+rt[e]+";"}).join(`
3362
+ `+g.map(function(E,e){return"sourceLoc."+Ft[e]+" = start["+e+"] + coords."+Ft[e]+";"}).join(`
3363
3363
  `)+`
3364
3364
  `,this.userCode=`
3365
3365
  `+w+`
@@ -3367,7 +3367,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3367
3367
  `+B+`
3368
3368
  setOutput(getSource(`+C+`));
3369
3369
  }
3370
- `}return A.prototype.getCustomSetupFunc=function(g){var B=this;if(g.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+g.length+")");return function(Q,w){B.startLoc==null&&(B.startLoc=Q.getUniformLocationNoThrow(w,"start"),B.startLoc==null)||Q.gl.uniform1iv(B.startLoc,g)}},A}(),rt=["x","y","z","w","u","v"],bJ=function(){function A(g){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g,this.rank=g.length;var B=nB(this.rank),Q=Fg("coords",this.rank),w=Fg("sourceLoc",this.rank),C=this.rank===1?"sourceLoc":"vec2("+w.slice(-2).join()+")",E="getChannel(getSource("+w.join()+"), "+C+")",e=`
3370
+ `}return A.prototype.getCustomSetupFunc=function(g){var B=this;if(g.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+g.length+")");return function(Q,w){B.startLoc==null&&(B.startLoc=Q.getUniformLocationNoThrow(w,"start"),B.startLoc==null)||Q.gl.uniform1iv(B.startLoc,g)}},A}(),Ft=["x","y","z","w","u","v"],VJ=function(){function A(g){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=g,this.rank=g.length;var B=nB(this.rank),Q=Fg("coords",this.rank),w=Fg("sourceLoc",this.rank),C=this.rank===1?"sourceLoc":"vec2("+w.slice(-2).join()+")",E="getChannel(getSource("+w.join()+"), "+C+")",e=`
3371
3371
  result.x = `+E+`;
3372
3372
  if (++`+Q[this.rank-1]+" < "+g[this.rank-1]+`) {
3373
3373
  ++`+w[this.rank-1]+`;
@@ -3397,7 +3397,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3397
3397
  `+I+`
3398
3398
  setOutput(result);
3399
3399
  }
3400
- `}return A.prototype.getCustomSetupFunc=function(g){var B=this;if(g.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+g.length+")");return function(Q,w){B.startLoc==null&&(B.startLoc=Q.getUniformLocationNoThrow(w,"start"),B.startLoc==null)||Q.gl.uniform1iv(B.startLoc,g)}},A}(),KJ=function(A,g,B){this.variableNames=["x"],this.outputShape=B;var Q=B.length,w=nB(B.length),C=nB(B.length),E="";if(Q===1)E="coords * strides + begin";else{var e=0;E=B.map(function(I,o){return e++,B.length===1?"coords * strides["+o+"] + begin["+o+"]":"coords["+(e-1)+"] * strides["+o+"] + begin["+o+"]"}).join(",")}this.userCode=`
3400
+ `}return A.prototype.getCustomSetupFunc=function(g){var B=this;if(g.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+g.length+")");return function(Q,w){B.startLoc==null&&(B.startLoc=Q.getUniformLocationNoThrow(w,"start"),B.startLoc==null)||Q.gl.uniform1iv(B.startLoc,g)}},A}(),xJ=function(A,g,B){this.variableNames=["x"],this.outputShape=B;var Q=B.length,w=nB(B.length),C=nB(B.length),E="";if(Q===1)E="coords * strides + begin";else{var e=0;E=B.map(function(I,o){return e++,B.length===1?"coords * strides["+o+"] + begin["+o+"]":"coords["+(e-1)+"] * strides["+o+"] + begin["+o+"]"}).join(",")}this.userCode=`
3401
3401
  `+w+" begin = "+w+"("+A+`);
3402
3402
  `+w+" strides = "+w+"("+g+`);
3403
3403
 
@@ -3405,17 +3405,17 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3405
3405
  `+C+` coords = getOutputCoords();
3406
3406
  setOutput(getX(`+E+`));
3407
3407
  }
3408
- `},VJ=function(){function A(g){this.gpgpu=g,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return A.prototype.acquireTexture=function(g,B,Q){var w,C=bc(B,Q),E=Kc(g,C,Q);if(E in this.freeTextures||(this.freeTextures[E]=[]),E in this.usedTextures||(this.usedTextures[E]=[]),this.freeTextures[E].length>0){this.numFreeTextures--,this.numUsedTextures++,this.log();var e=this.freeTextures[E].shift();return this.usedTextures[E].push(e),e}return this.numUsedTextures++,this.log(),C===lg.PACKED_2X2_FLOAT32?w=this.gpgpu.createPackedMatrixTexture(g[0],g[1]):C===lg.PACKED_2X2_FLOAT16?w=this.gpgpu.createFloat16PackedMatrixTexture(g[0],g[1]):C===lg.UNPACKED_FLOAT32?w=this.gpgpu.createFloat32MatrixTexture(g[0],g[1]):C===lg.UNPACKED_FLOAT16?w=this.gpgpu.createFloat16MatrixTexture(g[0],g[1]):C===lg.PACKED_4X1_UNSIGNED_BYTE&&(w=this.gpgpu.createUnsignedBytesMatrixTexture(g[0],g[1])),this.usedTextures[E].push(w),w},A.prototype.releaseTexture=function(g,B,Q,w){if(this.freeTextures!=null){var C=Kc(B,bc(Q,w),w);C in this.freeTextures||(this.freeTextures[C]=[]),this.freeTextures[C].push(g),this.numFreeTextures++,this.numUsedTextures--;var E=this.usedTextures[C],e=E.indexOf(g);if(e<0)throw new Error("Cannot release a texture that was never provided by this texture manager");E.splice(e,1),this.log()}},A.prototype.log=function(){if(this.logEnabled){var g=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+g+")")}},A.prototype.getNumUsedTextures=function(){return this.numUsedTextures},A.prototype.getNumFreeTextures=function(){return this.numFreeTextures},A.prototype.dispose=function(){var g=this;if(this.freeTextures!=null){for(var B in this.freeTextures)this.freeTextures[B].forEach(function(Q){g.gpgpu.deleteMatrixTexture(Q)});for(var B in this.usedTextures)this.usedTextures[B].forEach(function(w){g.gpgpu.deleteMatrixTexture(w)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},A}();function bc(A,g){if(A===hg.UPLOAD)return lg.PACKED_2X2_FLOAT32;if(A===hg.RENDER||A==null)return function(B){return BA().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?B?lg.PACKED_2X2_FLOAT32:lg.UNPACKED_FLOAT32:B?lg.PACKED_2X2_FLOAT16:lg.UNPACKED_FLOAT16}(g);if(A===hg.DOWNLOAD||A===hg.PIXELS)return lg.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+A)}function Kc(A,g,B){return A[0]+"_"+A[1]+"_"+g+"_"+B}var xJ=function(A,g){this.variableNames=["A"];for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[Q]*g[Q];this.outputShape=B,this.rank=B.length;var w=nB(this.rank),C=function(E){var e=E.length;if(e>5)throw Error("Tile for rank "+e+" is not yet supported");if(e===1)return"imod(resRC, "+E[0]+")";for(var I=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],o=[],n=0;n<E.length;n++)o.push("imod("+I[n]+", "+E[n]+")");return o.join()}(A);this.userCode=`
3408
+ `},XJ=function(){function A(g){this.gpgpu=g,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return A.prototype.acquireTexture=function(g,B,Q){var w,C=bc(B,Q),E=Kc(g,C,Q);if(E in this.freeTextures||(this.freeTextures[E]=[]),E in this.usedTextures||(this.usedTextures[E]=[]),this.freeTextures[E].length>0){this.numFreeTextures--,this.numUsedTextures++,this.log();var e=this.freeTextures[E].shift();return this.usedTextures[E].push(e),e}return this.numUsedTextures++,this.log(),C===lg.PACKED_2X2_FLOAT32?w=this.gpgpu.createPackedMatrixTexture(g[0],g[1]):C===lg.PACKED_2X2_FLOAT16?w=this.gpgpu.createFloat16PackedMatrixTexture(g[0],g[1]):C===lg.UNPACKED_FLOAT32?w=this.gpgpu.createFloat32MatrixTexture(g[0],g[1]):C===lg.UNPACKED_FLOAT16?w=this.gpgpu.createFloat16MatrixTexture(g[0],g[1]):C===lg.PACKED_4X1_UNSIGNED_BYTE&&(w=this.gpgpu.createUnsignedBytesMatrixTexture(g[0],g[1])),this.usedTextures[E].push(w),w},A.prototype.releaseTexture=function(g,B,Q,w){if(this.freeTextures!=null){var C=Kc(B,bc(Q,w),w);C in this.freeTextures||(this.freeTextures[C]=[]),this.freeTextures[C].push(g),this.numFreeTextures++,this.numUsedTextures--;var E=this.usedTextures[C],e=E.indexOf(g);if(e<0)throw new Error("Cannot release a texture that was never provided by this texture manager");E.splice(e,1),this.log()}},A.prototype.log=function(){if(this.logEnabled){var g=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+g+")")}},A.prototype.getNumUsedTextures=function(){return this.numUsedTextures},A.prototype.getNumFreeTextures=function(){return this.numFreeTextures},A.prototype.dispose=function(){var g=this;if(this.freeTextures!=null){for(var B in this.freeTextures)this.freeTextures[B].forEach(function(Q){g.gpgpu.deleteMatrixTexture(Q)});for(var B in this.usedTextures)this.usedTextures[B].forEach(function(w){g.gpgpu.deleteMatrixTexture(w)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},A}();function bc(A,g){if(A===hg.UPLOAD)return lg.PACKED_2X2_FLOAT32;if(A===hg.RENDER||A==null)return function(B){return BA().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?B?lg.PACKED_2X2_FLOAT32:lg.UNPACKED_FLOAT32:B?lg.PACKED_2X2_FLOAT16:lg.UNPACKED_FLOAT16}(g);if(A===hg.DOWNLOAD||A===hg.PIXELS)return lg.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+A)}function Kc(A,g,B){return A[0]+"_"+A[1]+"_"+g+"_"+B}var OJ=function(A,g){this.variableNames=["A"];for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[Q]*g[Q];this.outputShape=B,this.rank=B.length;var w=nB(this.rank),C=function(E){var e=E.length;if(e>5)throw Error("Tile for rank "+e+" is not yet supported");if(e===1)return"imod(resRC, "+E[0]+")";for(var I=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],o=[],n=0;n<E.length;n++)o.push("imod("+I[n]+", "+E[n]+")");return o.join()}(A);this.userCode=`
3409
3409
  void main() {
3410
3410
  `+w+` resRC = getOutputCoords();
3411
3411
  setOutput(getA(`+C+`));
3412
3412
  }
3413
- `},XJ=function(A,g){this.variableNames=["A"];for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[g[Q]];this.outputShape=B,this.rank=B.length;var w=nB(this.rank),C=function(E){var e=E.length;if(e>6)throw Error("Transpose for rank "+e+" is not yet supported");for(var I=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],o=new Array(e),n=0;n<E.length;n++)o[E[n]]=I[n];return o.join()}(g);this.userCode=`
3413
+ `},ZJ=function(A,g){this.variableNames=["A"];for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[g[Q]];this.outputShape=B,this.rank=B.length;var w=nB(this.rank),C=function(E){var e=E.length;if(e>6)throw Error("Transpose for rank "+e+" is not yet supported");for(var I=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],o=new Array(e),n=0;n<E.length;n++)o[E[n]]=I[n];return o.join()}(g);this.userCode=`
3414
3414
  void main() {
3415
3415
  `+w+` resRC = getOutputCoords();
3416
3416
  setOutput(getA(`+C+`));
3417
3417
  }
3418
- `},OJ=function(A,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[g[Q]];if(this.outputShape=B,this.rank=B.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var w=nB(this.rank),C=Nc("rc",this.rank),E=new Array(this.rank);for(Q=0;Q<g.length;Q++)E[g[Q]]=C[Q];var e="vec2("+E.slice(-2).join()+")",I="++"+C[this.rank-1]+" < "+B[this.rank-1],o="getChannel(getA("+E.join()+"), "+e+")";this.userCode=`
3418
+ `},qJ=function(A,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var B=new Array(A.length),Q=0;Q<B.length;Q++)B[Q]=A[g[Q]];if(this.outputShape=B,this.rank=B.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var w=nB(this.rank),C=Nc("rc",this.rank),E=new Array(this.rank);for(Q=0;Q<g.length;Q++)E[g[Q]]=C[Q];var e="vec2("+E.slice(-2).join()+")",I="++"+C[this.rank-1]+" < "+B[this.rank-1],o="getChannel(getA("+E.join()+"), "+e+")";this.userCode=`
3419
3419
  void main() {
3420
3420
  `+w+` rc = getOutputCoords();
3421
3421
  vec4 result = vec4(0.);
@@ -3432,7 +3432,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3432
3432
  }
3433
3433
  setOutput(result);
3434
3434
  }
3435
- `},Ft=1.7580993408473768,at=1.0507009873554805,KA=function(A,g){this.variableNames=["A"],this.outputShape=A,this.userCode=`
3435
+ `},at=1.7580993408473768,st=1.0507009873554805,KA=function(A,g){this.variableNames=["A"],this.outputShape=A,this.userCode=`
3436
3436
  float unaryOperation(float x) {
3437
3437
  `+g+`
3438
3438
  }
@@ -3443,37 +3443,37 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3443
3443
 
3444
3444
  setOutput(y);
3445
3445
  }
3446
- `},Lg="if (isnan(x)) return x;",ZJ="return x;",Vc="return abs(x);",xc=Lg+`
3446
+ `},Lg="if (isnan(x)) return x;",_J="return x;",Vc="return abs(x);",xc=Lg+`
3447
3447
  return (x < 0.0) ? 0.0 : x;
3448
3448
  `,Xc=Lg+`
3449
3449
  return (x < 0.0) ? 0.0 : min(6.0, x);
3450
- `,Oc="return (x >= 0.0) ? x : (exp(x) - 1.0);",qJ=`
3450
+ `,Oc="return (x >= 0.0) ? x : (exp(x) - 1.0);",$J=`
3451
3451
  // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
3452
3452
  // see: https://arxiv.org/abs/1706.02515
3453
- float scaleAlpha = `+Ft+`;
3454
- float scale = `+at+`;
3453
+ float scaleAlpha = `+at+`;
3454
+ float scale = `+st+`;
3455
3455
  return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);
3456
- `,Zc="return -x;",qc="return ceil(x);",_c="return floor(x);",$c="return exp(x);",AD="return exp(x) - 1.0;",_J=Lg+`
3456
+ `,Zc="return -x;",qc="return ceil(x);",_c="return floor(x);",$c="return exp(x);",AD="return exp(x) - 1.0;",AN=Lg+`
3457
3457
  return sin(x);
3458
- `,$J=Lg+`
3458
+ `,BN=Lg+`
3459
3459
  return cos(x);
3460
- `,AN=Lg+`
3460
+ `,gN=Lg+`
3461
3461
  if (abs(x) > 1.) {
3462
3462
  return NAN;
3463
3463
  }
3464
3464
  return asin(x);
3465
- `,BN=Lg+`
3465
+ `,QN=Lg+`
3466
3466
  if (abs(x) > 1.) {
3467
3467
  return NAN;
3468
3468
  }
3469
3469
  return acos(x);
3470
- `,gN=Lg+`
3470
+ `,wN=Lg+`
3471
3471
  return atan(x);
3472
- `,QN=Lg+"return log(x + sqrt(x * x + 1.0));",wN=Lg+`
3472
+ `,CN=Lg+"return log(x + sqrt(x * x + 1.0));",EN=Lg+`
3473
3473
  if (x < 1.0) return NAN;
3474
- return log(x + sqrt(x * x - 1.0));`,CN=Lg+`
3474
+ return log(x + sqrt(x * x - 1.0));`,eN=Lg+`
3475
3475
  if ((x < -1.0) || (x > 1.0)) return NAN;
3476
- return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,ce="return x;",EN="return x;",BD=`
3476
+ return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,ce="return x;",IN="return x;",BD=`
3477
3477
  vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
3478
3478
  bvec4 isNaN = isnan(x);
3479
3479
 
@@ -3513,14 +3513,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3513
3513
 
3514
3514
  setOutput(y);
3515
3515
  }
3516
- `},eN=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=A;var g=A.length,B=Fg("rc",g),Q=nB(g),w=function(e,I){if(e===1)return"rc";for(var o="",n=0;n<e;n++)o+=I[n],n<e-1&&(o+=",");return o}(g,B),C=B.slice(-2),E=g<=1?"rc":"vec2("+C.join(",")+")";this.userCode=`
3516
+ `},oN=function(A){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=A;var g=A.length,B=Fg("rc",g),Q=nB(g),w=function(e,I){if(e===1)return"rc";for(var o="",n=0;n<e;n++)o+=I[n],n<e-1&&(o+=",");return o}(g,B),C=B.slice(-2),E=g<=1?"rc":"vec2("+C.join(",")+")";this.userCode=`
3517
3517
  void main() {
3518
3518
  `+Q+` rc = getOutputCoords();
3519
3519
  vec4 packedInput = getA(`+w+`);
3520
3520
 
3521
3521
  setOutput(getChannel(packedInput, `+E+`));
3522
3522
  }
3523
- `},De={};function re(A,g){if(g===void 0&&(g=!1),A==="linear")return g?EN:ZJ;if(A==="relu")return g?BD:xc;if(A==="elu")return g?QD:Oc;if(A==="relu6")return g?gD:Xc;if(A==="prelu")return g?Tc:kc;throw new Error("Activation "+A+" has not been implemented for the WebGL backend.")}var IN=600,oN=function(A){function g(B){var Q,w=A.call(this)||this;if(w.pendingRead=new WeakMap,w.pendingDisposal=new WeakSet,w.dataRefCount=new WeakMap,w.numBytesInGPU=0,w.uploadWaitMs=0,w.downloadWaitMs=0,w.warnedAboutMemory=!1,w.pendingDeletes=0,w.disposed=!1,!BA().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(B==null){var C=_g(BA().getNumber("WEBGL_VERSION"));w.binaryCache=((Q=BA().getNumber("WEBGL_VERSION"))in De||(De[Q]={}),De[Q]),w.gpgpu=new sJ(C),w.canvas=C.canvas,w.gpgpuCreatedLocally=!0}else w.gpgpu=B,w.binaryCache={},w.gpgpuCreatedLocally=!1,w.canvas=B.gl.canvas;return w.textureManager=new VJ(w.gpgpu),w.numMBBeforeWarning=BA().global.screen==null?1024:BA().global.screen.height*BA().global.screen.width*window.devicePixelRatio*IN/1024/1024,w.texData=new ac(w,b),w}return Wg(g,A),g.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},g.prototype.write=function(B,Q,w){if(BA().getBool("DEBUG")&&this.checkNumericalProblems(B),w==="complex64"&&B!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var C={};return this.texData.set(C,{shape:Q,dtype:w,values:B,usage:hg.UPLOAD}),C},g.prototype.move=function(B,Q,w,C){if(BA().getBool("DEBUG")&&this.checkNumericalProblems(Q),C==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(B,{shape:w,dtype:C,values:Q,usage:hg.UPLOAD})},g.prototype.readSync=function(B){var Q=this.texData.get(B),w=Q.values,C=Q.dtype,E=Q.complexTensors,e=Q.slice,I=Q.shape,o=Q.isPacked;if(e!=null){var n=void 0;n=o?new yC(I,ce):new KA(I,ce);var i=this.runWebGLProgram(n,[{dataId:B,shape:I,dtype:C}],C),Y=this.readSync(i.dataId);return this.disposeData(i.dataId),Y}if(w!=null)return this.convertAndCacheOnCPU(B);if(C==="string")return w;var M,c,D=this.activeTimers!=null;return D&&(M=Zg()),C==="complex64"?c=et(E.real.dataSync(),E.imag.dataSync()):c=this.getValuesFromTexture(B),D&&(this.downloadWaitMs+=Zg()-M),this.convertAndCacheOnCPU(B,c)},g.prototype.read=function(B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return UA(this,function(h){switch(h.label){case 0:if(this.pendingRead.has(B))return Q=this.pendingRead.get(B),[2,new Promise(function(l){return Q.push(l)})];if(w=this.texData.get(B),C=w.values,E=w.shape,e=w.slice,I=w.dtype,o=w.complexTensors,n=w.isPacked,e!=null)return i=void 0,i=n?new yC(E,ce):new KA(E,ce),Y=this.runWebGLProgram(i,[{dataId:B,shape:E,dtype:I}],I),M=this.read(Y.dataId),this.disposeData(Y.dataId),[2,M];if(C!=null)return[2,this.convertAndCacheOnCPU(B)];if(!BA().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&BA().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return c=null,I!=="complex64"&&BA().get("WEBGL_BUFFER_SUPPORTED")&&(D=this.decode(B),r=this.texData.get(D.dataId),c=(H=this.gpgpu).createBufferFromTexture.apply(H,[r.texture].concat(vC(E)))),this.pendingRead.set(B,[]),I==="complex64"?[3,2]:[4,this.gpgpu.createAndWaitForFence()];case 1:h.sent(),h.label=2;case 2:return I!=="complex64"?[3,4]:[4,Promise.all([o.real.data(),o.imag.data()])];case 3:return s=h.sent(),u=s[0],a=s[1],F=et(u,a),[3,5];case 4:c==null?F=this.getValuesFromTexture(B):(U=hA(E),F=this.gpgpu.downloadFloat32MatrixFromBuffer(c,U)),h.label=5;case 5:return D!=null&&this.disposeData(D.dataId),G=this.convertAndCacheOnCPU(B,F),d=this.pendingRead.get(B),this.pendingRead.delete(B),d.forEach(function(l){return l(G)}),this.pendingDisposal.has(B)&&(this.pendingDisposal.delete(B),this.disposeData(B),this.pendingDeletes--),[2,G]}})})},g.prototype.checkNumericalProblems=function(B){if(B!=null)for(var Q=0;Q<B.length;Q++){var w=B[Q];if(!Zd(w))throw BA().getBool("WEBGL_RENDER_FLOAT32_CAPABLE")?Error("The value "+w+" cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'"):Error("The value "+w+" cannot be represented on this device.")}},g.prototype.getValuesFromTexture=function(B){var Q,w=this.texData.get(B),C=w.shape,E=w.dtype,e=w.isPacked,I=hA(C);if(BA().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")){var o=this.decode(B),n=this.texData.get(o.dataId),i=(Q=this.gpgpu).downloadMatrixFromPackedTexture.apply(Q,[n.texture].concat(vC(C))).subarray(0,I);return this.disposeData(o.dataId),i}var Y=BA().getBool("WEBGL_PACK")&&e===!0,M=Y?Oo(C):C,c=Y?new Zf(M):new Of(M),D=this.runWebGLProgram(c,[{shape:M,dtype:E,dataId:B}],"float32"),r=this.texData.get(D.dataId),F=this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(r.texture,r.texShape[0],r.texShape[1]).subarray(0,I);return this.disposeData(D.dataId),F},g.prototype.time=function(B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o;return UA(this,function(n){switch(n.label){case 0:return Q=this.activeTimers,w=[],C=!1,this.programTimersStack==null?(this.programTimersStack=w,C=!0):this.activeTimers.push(w),this.activeTimers=w,B(),E=Tw(this.activeTimers.map(function(i){return i.query})).filter(function(i){return i!=null}),e=Tw(this.activeTimers.map(function(i){return i.name})).filter(function(i){return i!=null}),this.activeTimers=Q,C&&(this.programTimersStack=null),I={uploadWaitMs:this.uploadWaitMs,downloadWaitMs:this.downloadWaitMs,kernelMs:null,wallMs:null},BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[4,Promise.all(E)]:[3,2];case 1:return o=n.sent(),I.kernelMs=Nd(o),I.getExtraProfileInfo=function(){return o.map(function(i,Y){return{name:e[Y],ms:i}}).map(function(i){return i.name+": "+i.ms}).join(", ")},[3,3];case 2:I.kernelMs={error:"WebGL query timers are not supported in this environment."},n.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,I]}})})},g.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},g.prototype.startTimer=function(){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:Zg(),endMs:null}},g.prototype.endTimer=function(B){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),B):(B.endMs=Zg(),B)},g.prototype.getQueryTime=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(B)]:[2,(Q=B).endMs-Q.startMs]})})},g.prototype.disposeData=function(B){if(!this.pendingDisposal.has(B)){if(this.pendingRead.has(B))return this.pendingDisposal.add(B),void this.pendingDeletes++;if(this.texData.has(B)){this.releaseGPUData(B);var Q=this.texData.get(B).complexTensors;Q!=null&&(Q.real.dispose(),Q.imag.dispose()),this.texData.delete(B)}}},g.prototype.releaseGPUData=function(B){var Q=this.texData.get(B),w=Q.texture,C=Q.dtype,E=Q.texShape,e=Q.usage,I=Q.isPacked,o=Q.slice,n=o&&o.origDataId||B,i=this.dataRefCount.get(n);i>1?this.dataRefCount.set(n,i-1):(this.dataRefCount.delete(n),w!=null&&(this.numBytesInGPU-=this.computeBytes(E,C),this.textureManager.releaseTexture(w,E,e,I)));var Y=this.texData.get(B);Y.texture=null,Y.texShape=null,Y.isPacked=!1,Y.slice=null},g.prototype.getTexture=function(B){return this.uploadToGPU(B),this.texData.get(B).texture},g.prototype.getDataInfo=function(B){return this.texData.get(B)},g.prototype.getCPUBackend=function(){return BA().getBool("WEBGL_CPU_FORWARD")?(this.cpuBackend==null&&(this.cpuBackend=b.findBackend("cpu")),this.cpuBackend):null},g.prototype.shouldExecuteOnCPU=function(B,Q){var w=this;return Q===void 0&&(Q=128),this.getCPUBackend()!=null&&B.every(function(C){return w.texData.get(C.dataId).texture==null&&C.size<Q})},g.prototype.getGPGPUContext=function(){return this.gpgpu},g.prototype.complex=function(B,Q){var w=this.makeOutput(B.shape,"complex64");return this.texData.get(w.dataId).complexTensors={real:b.keep(B.clone()),imag:b.keep(Q.clone())},w},g.prototype.real=function(B){return this.texData.get(B.dataId).complexTensors.real.clone()},g.prototype.imag=function(B){return this.texData.get(B.dataId).complexTensors.imag.clone()},g.prototype.slice=function(B,Q,w){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.slice(B,Q,w);if(hA(w)===0)return Ag([],w,B.dtype);var C=this.texData.get(B.dataId).isPacked,E=rc(B.shape,Q,w);if(C||!E){var e=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new bJ(w):new LJ(w),I=e.getCustomSetupFunc(Q);return this.compileAndRun(e,[B],null,I)}return this.uploadToGPU(B.dataId),this.shallowSlice(B,Q,w)},g.prototype.shallowSlice=function(B,Q,w){var C=this.texData.get(B.dataId),E=this.makeOutput(w,B.dtype),e=this.texData.get(E.dataId);Object.assign(e,C),e.shape=w,e.dtype=B.dtype;var I=Fc(Q,B.strides);C.slice&&(I+=C.slice.flatOffset),e.slice={flatOffset:I,origDataId:C.slice&&C.slice.origDataId||B.dataId};var o=this.dataRefCount.get(e.slice.origDataId)||1;return this.dataRefCount.set(e.slice.origDataId,o+1),E},g.prototype.stridedSlice=function(B,Q,w,C){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.stridedSlice(B,Q,w,C);var E=Qt(Q,w,C);if(E.some(function(I){return I===0}))return Ag([],E);var e=new KJ(Q,C,E);return this.compileAndRun(e,[B])},g.prototype.reverse=function(B,Q){var w=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new zJ(B.shape,Q):new yJ(B.shape,Q);return this.compileAndRun(w,[B])},g.prototype.concat=function(B,Q){if(B[0].dtype==="complex64"){var w=B.map(function(M){return kg(M)}),C=B.map(function(M){return BQ(M)});return $B(this.concat(w,Q),this.concat(C,Q))}if(this.shouldExecuteOnCPU(B))return this.cpuBackend.concat(B,Q);if(B.length===1)return B[0];if(B.length>BA().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var E=Math.floor(B.length/2),e=this.concat(B.slice(0,E),Q),I=this.concat(B.slice(E),Q);return this.concat([e,I],Q)}if(BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&B[0].rank>1){var o=new kf(B.map(function(M){return M.shape}),Q);return this.compileAndRun(o,B)}var n=yw(B.map(function(M){return M.shape}),Q),i=B.map(function(M){return M.as2D(-1,hA(M.shape.slice(Q)))}),Y=new vf(i.map(function(M){return M.shape}));return this.compileAndRun(Y,i).reshape(n)},g.prototype.neg=function(B){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.neg(B);if(BA().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(B,Zc,B.dtype);var Q=new KA(B.shape,Zc);return this.compileAndRun(Q,[B])},g.prototype.batchMatMul=function(B,Q,w,C){var E=w?B.shape[2]:B.shape[1],e=C?Q.shape[1]:Q.shape[2],I=w?B.shape[1]:B.shape[2],o=B.shape[0];if((E===1||e===1)&&I>1e3){w&&(B=B.transpose([0,2,1])),C&&(Q=Q.transpose([0,2,1]));var n=e===1?B:B.as3D(o,I,1),i=e===1?2:1,Y=e===1?Q.as3D(o,1,I):Q;return this.multiply(n,Y).sum(i,!0)}var M=_B(B.dtype,Q.dtype),c=new Mt(B.shape,[o,E,e],w,C);return this.compileAndRun(c,[B,Q],M)},g.prototype.fusedBatchMatMul=function(B){var Q=B.a,w=B.b,C=B.transposeA,E=B.transposeB,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=C?Q.shape[2]:Q.shape[1],i=E?w.shape[1]:w.shape[2],Y=Q.shape[0],M=_B(Q.dtype,w.dtype),c=e!=null,D=o!=null,r=I?re(I,!0):null,F=new Mt(Q.shape,[Y,n,i],C,E,c,r,D),s=[Q,w];return e&&s.push(e),o&&s.push(o),this.compileAndRun(F,s,M)},g.prototype.multiply=function(B,Q){if(B.dtype==="complex64"){var w=this.texData.get(B.dataId),C=this.texData.get(Q.dataId),E=new Pc(Jf,B.shape,Q.shape),e=new Pc(Nf,B.shape,Q.shape),I=[this.makeComplexComponentTensorInfo(B,w.complexTensors.real),this.makeComplexComponentTensorInfo(B,w.complexTensors.imag),this.makeComplexComponentTensorInfo(Q,C.complexTensors.real),this.makeComplexComponentTensorInfo(Q,C.complexTensors.imag)],o=this.compileAndRun(E,I),n=this.compileAndRun(e,I),i=this.complex(o,n);return o.dispose(),n.dispose(),i}if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.multiply(B,Q);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,vc,B.dtype);var Y=new lB(vc,B.shape,Q.shape);return this.compileAndRun(Y,[B,Q],B.dtype)},g.prototype.batchNormalization=function(B,Q,w,C,E,e){var I=[B,Q,w],o=null;e!=null&&(o=e.shape,I.push(e));var n=null;if(E!=null&&(n=E.shape,I.push(E)),BA().getBool("WEBGL_PACK_NORMALIZATION")){var i=new ff(B.shape,Q.shape,w.shape,o,n,C);return this.compileAndRun(i,I)}var Y=new Hf(B.shape,Q.shape,w.shape,o,n,C);return this.compileAndRun(Y,I)},g.prototype.localResponseNormalization4D=function(B,Q,w,C,E){var e=BA().getBool("WEBGL_PACK_NORMALIZATION")?new hJ(B.shape,Q,w,C,E):new UJ(B.shape,Q,w,C,E);return this.compileAndRun(e,[B])},g.prototype.LRNGrad=function(B,Q,w,C,E,e,I){var o=new GJ(Q.shape,C,E,e,I);return this.compileAndRun(o,[Q,w,B])},g.prototype.tile=function(B,Q){if(B.dtype==="string"){var w=this.readSync(B.dataId).map(function(E){return XE(E)});return fc(zA(B.shape,B.dtype,w),Q)}var C=new xJ(B.shape,Q);return this.compileAndRun(C,[B])},g.prototype.pad=function(B,Q,w){var C=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new mJ(B.shape,Q,w):new NJ(B.shape,Q,w);return this.compileAndRun(C,[B])},g.prototype.transpose=function(B,Q){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.transpose(B,Q);var w=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new OJ(B.shape,Q):new XJ(B.shape,Q);return this.compileAndRun(w,[B])},g.prototype.gather=function(B,Q,w){if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.gather(B,Q,w);var C=new gJ(B.shape,Q.size,w);return this.compileAndRun(C,[B,Q])},g.prototype.batchToSpaceND=function(B,Q,w){R(B.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var C=Q.reduce(function(i,Y){return i*Y}),E=Ee(B.shape,Q,C),e=ee(E.length,Q.length),I=Ie(B.shape,Q,C),o=ic(w,Q.length),n=Yc(I,w,Q.length);return B.reshape(E).transpose(e).reshape(I).slice(o,n)},g.prototype.spaceToBatchND=function(B,Q,w){R(B.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var C=Q.reduce(function(Y,M){return Y*M}),E=[[0,0]];E.push.apply(E,w);for(var e=1+Q.length;e<B.shape.length;++e)E.push([0,0]);var I=B.pad(E),o=Ee(I.shape,Q,C,!1),n=ee(o.length,Q.length,!1),i=Ie(I.shape,Q,C,!1);return I.reshape(o).transpose(n).reshape(i)},g.prototype.reduce=function(B,Q,w){var C=B.shape[0],E=B.shape[1],e=gt(E),I=new RJ({windowSize:e,inSize:E,batchSize:C},Q),o=this.compileAndRun(I,[B],w);return o.shape[1]===1?o:this.reduce(o,Q,w)},g.prototype.argReduce=function(B,Q,w){w===void 0&&(w=null);var C=B.shape[0],E=B.shape[1];w!=null&&(C=w.shape[0],E=w.shape[1]);var e=gt(E),I=new Ff({windowSize:e,inSize:E,batchSize:C},Q,w==null),o=[B];w!=null&&o.push(w);var n=this.compileAndRun(I,o,"int32");return n.shape[1]===1?n:this.argReduce(B,Q,n)},g.prototype.argReducePacked=function(B,Q,w){w===void 0&&(w=null);var C=w!=null?w.shape:B.shape,E=gt(C[C.length-1]),e=new hf(C,E,Q,w==null),I=w==null?[B]:[B,w],o=this.compileAndRun(e,I,"int32");return o.rank===B.rank?this.argReducePacked(B,Q,o):o},g.prototype.sum=function(B,Q){dg("sum",Q,B.rank);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E),I=Wo(B.dtype);return this.reduce(e,"sum",I).reshape(C)},g.prototype.prod=function(B,Q){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.prod(B,Q);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E),I=Wo(B.dtype);return this.reduce(e,"prod",I).reshape(C)},g.prototype.unsortedSegmentSum=function(B,Q,w){var C=0,E=$g([C],B.rank),e=B;E!=null&&(e=B.transpose(E),C=AQ(1,B.rank)[0]);var I=function(M,c,D){for(var r=[],F=M.length,s=0;s<F;s++)s!==c?r.push(M[s]):r.push(D);return r}(e.shape,C,w),o=hA([e.shape[C]]),n=e.as2D(-1,o),i=Wo(B.dtype),Y=this.segOpCompute(n,"unsortedSegmentSum",Q,i,w).reshape(I);return E!=null&&(Y=Y.transpose(qo(E))),Y},g.prototype.segOpCompute=function(B,Q,w,C,E){var e=B.shape[0],I=B.shape[1],o=function(Y,M){var c,D=!1;for(Y<=cc?(c=Y,D=!0):c=ko(Y,Math.floor(Math.sqrt(Y)));!D;)c>M||c===Y?D=!0:c=ko(Y,c+1);return c}(I,E),n=new WJ({windowSize:o,inSize:I,batchSize:e,numSegments:E}),i=this.compileAndRun(n,[B,w],C);return i.shape[1]===E?i:(w=we(0,E).tile([I/o]),this.segOpCompute(i,Q,w,C,E))},g.prototype.argMinMaxReduce=function(B,Q,w){var C=[Q];if(dg("arg"+w.charAt(0).toUpperCase()+w.slice(1),C,B.rank),!BA().getBool("WEBGL_PACK_REDUCE")||B.rank<=2){var E=gg(B.shape,C),e=E[0],I=hA(E[1]),o=B.as2D(-1,I);return this.argReduce(o,w).reshape(e)}return this.argReducePacked(B,w)},g.prototype.argMin=function(B,Q){return this.argMinMaxReduce(B,Q,"min")},g.prototype.argMax=function(B,Q){return this.argMinMaxReduce(B,Q,"max")},g.prototype.cumsum=function(B,Q,w,C){if(Q!==B.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(B.rank-1)+" but got axis="+Q);var E=new bf(B.shape,w,C);return this.compileAndRun(E,[B])},g.prototype.equal=function(B,Q){if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,`
3523
+ `},De={};function re(A,g){if(g===void 0&&(g=!1),A==="linear")return g?IN:_J;if(A==="relu")return g?BD:xc;if(A==="elu")return g?QD:Oc;if(A==="relu6")return g?gD:Xc;if(A==="prelu")return g?Tc:kc;throw new Error("Activation "+A+" has not been implemented for the WebGL backend.")}var tN=600,nN=function(A){function g(B){var Q,w=A.call(this)||this;if(w.pendingRead=new WeakMap,w.pendingDisposal=new WeakSet,w.dataRefCount=new WeakMap,w.numBytesInGPU=0,w.uploadWaitMs=0,w.downloadWaitMs=0,w.warnedAboutMemory=!1,w.pendingDeletes=0,w.disposed=!1,!BA().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(B==null){var C=_g(BA().getNumber("WEBGL_VERSION"));w.binaryCache=((Q=BA().getNumber("WEBGL_VERSION"))in De||(De[Q]={}),De[Q]),w.gpgpu=new UJ(C),w.canvas=C.canvas,w.gpgpuCreatedLocally=!0}else w.gpgpu=B,w.binaryCache={},w.gpgpuCreatedLocally=!1,w.canvas=B.gl.canvas;return w.textureManager=new XJ(w.gpgpu),w.numMBBeforeWarning=BA().global.screen==null?1024:BA().global.screen.height*BA().global.screen.width*window.devicePixelRatio*tN/1024/1024,w.texData=new ac(w,b),w}return Wg(g,A),g.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},g.prototype.write=function(B,Q,w){if(BA().getBool("DEBUG")&&this.checkNumericalProblems(B),w==="complex64"&&B!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var C={};return this.texData.set(C,{shape:Q,dtype:w,values:B,usage:hg.UPLOAD}),C},g.prototype.move=function(B,Q,w,C){if(BA().getBool("DEBUG")&&this.checkNumericalProblems(Q),C==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(B,{shape:w,dtype:C,values:Q,usage:hg.UPLOAD})},g.prototype.readSync=function(B){var Q=this.texData.get(B),w=Q.values,C=Q.dtype,E=Q.complexTensors,e=Q.slice,I=Q.shape,o=Q.isPacked;if(e!=null){var n=void 0;n=o?new yC(I,ce):new KA(I,ce);var i=this.runWebGLProgram(n,[{dataId:B,shape:I,dtype:C}],C),Y=this.readSync(i.dataId);return this.disposeData(i.dataId),Y}if(w!=null)return this.convertAndCacheOnCPU(B);if(C==="string")return w;var M,c,D=this.activeTimers!=null;return D&&(M=Zg()),C==="complex64"?c=It(E.real.dataSync(),E.imag.dataSync()):c=this.getValuesFromTexture(B),D&&(this.downloadWaitMs+=Zg()-M),this.convertAndCacheOnCPU(B,c)},g.prototype.read=function(B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return UA(this,function(h){switch(h.label){case 0:if(this.pendingRead.has(B))return Q=this.pendingRead.get(B),[2,new Promise(function(l){return Q.push(l)})];if(w=this.texData.get(B),C=w.values,E=w.shape,e=w.slice,I=w.dtype,o=w.complexTensors,n=w.isPacked,e!=null)return i=void 0,i=n?new yC(E,ce):new KA(E,ce),Y=this.runWebGLProgram(i,[{dataId:B,shape:E,dtype:I}],I),M=this.read(Y.dataId),this.disposeData(Y.dataId),[2,M];if(C!=null)return[2,this.convertAndCacheOnCPU(B)];if(!BA().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&BA().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return c=null,I!=="complex64"&&BA().get("WEBGL_BUFFER_SUPPORTED")&&(D=this.decode(B),r=this.texData.get(D.dataId),c=(H=this.gpgpu).createBufferFromTexture.apply(H,[r.texture].concat(vC(E)))),this.pendingRead.set(B,[]),I==="complex64"?[3,2]:[4,this.gpgpu.createAndWaitForFence()];case 1:h.sent(),h.label=2;case 2:return I!=="complex64"?[3,4]:[4,Promise.all([o.real.data(),o.imag.data()])];case 3:return s=h.sent(),u=s[0],a=s[1],F=It(u,a),[3,5];case 4:c==null?F=this.getValuesFromTexture(B):(U=hA(E),F=this.gpgpu.downloadFloat32MatrixFromBuffer(c,U)),h.label=5;case 5:return D!=null&&this.disposeData(D.dataId),G=this.convertAndCacheOnCPU(B,F),d=this.pendingRead.get(B),this.pendingRead.delete(B),d.forEach(function(l){return l(G)}),this.pendingDisposal.has(B)&&(this.pendingDisposal.delete(B),this.disposeData(B),this.pendingDeletes--),[2,G]}})})},g.prototype.checkNumericalProblems=function(B){if(B!=null)for(var Q=0;Q<B.length;Q++){var w=B[Q];if(!_d(w))throw BA().getBool("WEBGL_RENDER_FLOAT32_CAPABLE")?Error("The value "+w+" cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'"):Error("The value "+w+" cannot be represented on this device.")}},g.prototype.getValuesFromTexture=function(B){var Q,w=this.texData.get(B),C=w.shape,E=w.dtype,e=w.isPacked,I=hA(C);if(BA().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")){var o=this.decode(B),n=this.texData.get(o.dataId),i=(Q=this.gpgpu).downloadMatrixFromPackedTexture.apply(Q,[n.texture].concat(vC(C))).subarray(0,I);return this.disposeData(o.dataId),i}var Y=BA().getBool("WEBGL_PACK")&&e===!0,M=Y?Zo(C):C,c=Y?new _f(M):new qf(M),D=this.runWebGLProgram(c,[{shape:M,dtype:E,dataId:B}],"float32"),r=this.texData.get(D.dataId),F=this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(r.texture,r.texShape[0],r.texShape[1]).subarray(0,I);return this.disposeData(D.dataId),F},g.prototype.time=function(B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o;return UA(this,function(n){switch(n.label){case 0:return Q=this.activeTimers,w=[],C=!1,this.programTimersStack==null?(this.programTimersStack=w,C=!0):this.activeTimers.push(w),this.activeTimers=w,B(),E=Tw(this.activeTimers.map(function(i){return i.query})).filter(function(i){return i!=null}),e=Tw(this.activeTimers.map(function(i){return i.name})).filter(function(i){return i!=null}),this.activeTimers=Q,C&&(this.programTimersStack=null),I={uploadWaitMs:this.uploadWaitMs,downloadWaitMs:this.downloadWaitMs,kernelMs:null,wallMs:null},BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[4,Promise.all(E)]:[3,2];case 1:return o=n.sent(),I.kernelMs=Rd(o),I.getExtraProfileInfo=function(){return o.map(function(i,Y){return{name:e[Y],ms:i}}).map(function(i){return i.name+": "+i.ms}).join(", ")},[3,3];case 2:I.kernelMs={error:"WebGL query timers are not supported in this environment."},n.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,I]}})})},g.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},g.prototype.startTimer=function(){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:Zg(),endMs:null}},g.prototype.endTimer=function(B){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),B):(B.endMs=Zg(),B)},g.prototype.getQueryTime=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){return BA().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(B)]:[2,(Q=B).endMs-Q.startMs]})})},g.prototype.disposeData=function(B){if(!this.pendingDisposal.has(B)){if(this.pendingRead.has(B))return this.pendingDisposal.add(B),void this.pendingDeletes++;if(this.texData.has(B)){this.releaseGPUData(B);var Q=this.texData.get(B).complexTensors;Q!=null&&(Q.real.dispose(),Q.imag.dispose()),this.texData.delete(B)}}},g.prototype.releaseGPUData=function(B){var Q=this.texData.get(B),w=Q.texture,C=Q.dtype,E=Q.texShape,e=Q.usage,I=Q.isPacked,o=Q.slice,n=o&&o.origDataId||B,i=this.dataRefCount.get(n);i>1?this.dataRefCount.set(n,i-1):(this.dataRefCount.delete(n),w!=null&&(this.numBytesInGPU-=this.computeBytes(E,C),this.textureManager.releaseTexture(w,E,e,I)));var Y=this.texData.get(B);Y.texture=null,Y.texShape=null,Y.isPacked=!1,Y.slice=null},g.prototype.getTexture=function(B){return this.uploadToGPU(B),this.texData.get(B).texture},g.prototype.getDataInfo=function(B){return this.texData.get(B)},g.prototype.getCPUBackend=function(){return BA().getBool("WEBGL_CPU_FORWARD")?(this.cpuBackend==null&&(this.cpuBackend=b.findBackend("cpu")),this.cpuBackend):null},g.prototype.shouldExecuteOnCPU=function(B,Q){var w=this;return Q===void 0&&(Q=128),this.getCPUBackend()!=null&&B.every(function(C){return w.texData.get(C.dataId).texture==null&&C.size<Q})},g.prototype.getGPGPUContext=function(){return this.gpgpu},g.prototype.complex=function(B,Q){var w=this.makeOutput(B.shape,"complex64");return this.texData.get(w.dataId).complexTensors={real:b.keep(B.clone()),imag:b.keep(Q.clone())},w},g.prototype.real=function(B){return this.texData.get(B.dataId).complexTensors.real.clone()},g.prototype.imag=function(B){return this.texData.get(B.dataId).complexTensors.imag.clone()},g.prototype.slice=function(B,Q,w){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.slice(B,Q,w);if(hA(w)===0)return Ag([],w,B.dtype);var C=this.texData.get(B.dataId).isPacked,E=rc(B.shape,Q,w);if(C||!E){var e=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new VJ(w):new KJ(w),I=e.getCustomSetupFunc(Q);return this.compileAndRun(e,[B],null,I)}return this.uploadToGPU(B.dataId),this.shallowSlice(B,Q,w)},g.prototype.shallowSlice=function(B,Q,w){var C=this.texData.get(B.dataId),E=this.makeOutput(w,B.dtype),e=this.texData.get(E.dataId);Object.assign(e,C),e.shape=w,e.dtype=B.dtype;var I=Fc(Q,B.strides);C.slice&&(I+=C.slice.flatOffset),e.slice={flatOffset:I,origDataId:C.slice&&C.slice.origDataId||B.dataId};var o=this.dataRefCount.get(e.slice.origDataId)||1;return this.dataRefCount.set(e.slice.origDataId,o+1),E},g.prototype.stridedSlice=function(B,Q,w,C){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.stridedSlice(B,Q,w,C);var E=wt(Q,w,C);if(E.some(function(I){return I===0}))return Ag([],E);var e=new xJ(Q,C,E);return this.compileAndRun(e,[B])},g.prototype.reverse=function(B,Q){var w=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new SJ(B.shape,Q):new WJ(B.shape,Q);return this.compileAndRun(w,[B])},g.prototype.concat=function(B,Q){if(B[0].dtype==="complex64"){var w=B.map(function(M){return kg(M)}),C=B.map(function(M){return BQ(M)});return $B(this.concat(w,Q),this.concat(C,Q))}if(this.shouldExecuteOnCPU(B))return this.cpuBackend.concat(B,Q);if(B.length===1)return B[0];if(B.length>BA().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var E=Math.floor(B.length/2),e=this.concat(B.slice(0,E),Q),I=this.concat(B.slice(E),Q);return this.concat([e,I],Q)}if(BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&B[0].rank>1){var o=new jf(B.map(function(M){return M.shape}),Q);return this.compileAndRun(o,B)}var n=yw(B.map(function(M){return M.shape}),Q),i=B.map(function(M){return M.as2D(-1,hA(M.shape.slice(Q)))}),Y=new Tf(i.map(function(M){return M.shape}));return this.compileAndRun(Y,i).reshape(n)},g.prototype.neg=function(B){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.neg(B);if(BA().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(B,Zc,B.dtype);var Q=new KA(B.shape,Zc);return this.compileAndRun(Q,[B])},g.prototype.batchMatMul=function(B,Q,w,C){var E=w?B.shape[2]:B.shape[1],e=C?Q.shape[1]:Q.shape[2],I=w?B.shape[1]:B.shape[2],o=B.shape[0];if((E===1||e===1)&&I>1e3){w&&(B=B.transpose([0,2,1])),C&&(Q=Q.transpose([0,2,1]));var n=e===1?B:B.as3D(o,I,1),i=e===1?2:1,Y=e===1?Q.as3D(o,1,I):Q;return this.multiply(n,Y).sum(i,!0)}var M=_B(B.dtype,Q.dtype),c=new ct(B.shape,[o,E,e],w,C);return this.compileAndRun(c,[B,Q],M)},g.prototype.fusedBatchMatMul=function(B){var Q=B.a,w=B.b,C=B.transposeA,E=B.transposeB,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=C?Q.shape[2]:Q.shape[1],i=E?w.shape[1]:w.shape[2],Y=Q.shape[0],M=_B(Q.dtype,w.dtype),c=e!=null,D=o!=null,r=I?re(I,!0):null,F=new ct(Q.shape,[Y,n,i],C,E,c,r,D),s=[Q,w];return e&&s.push(e),o&&s.push(o),this.compileAndRun(F,s,M)},g.prototype.multiply=function(B,Q){if(B.dtype==="complex64"){var w=this.texData.get(B.dataId),C=this.texData.get(Q.dataId),E=new Pc(mf,B.shape,Q.shape),e=new Pc(Rf,B.shape,Q.shape),I=[this.makeComplexComponentTensorInfo(B,w.complexTensors.real),this.makeComplexComponentTensorInfo(B,w.complexTensors.imag),this.makeComplexComponentTensorInfo(Q,C.complexTensors.real),this.makeComplexComponentTensorInfo(Q,C.complexTensors.imag)],o=this.compileAndRun(E,I),n=this.compileAndRun(e,I),i=this.complex(o,n);return o.dispose(),n.dispose(),i}if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.multiply(B,Q);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,vc,B.dtype);var Y=new lB(vc,B.shape,Q.shape);return this.compileAndRun(Y,[B,Q],B.dtype)},g.prototype.batchNormalization=function(B,Q,w,C,E,e){var I=[B,Q,w],o=null;e!=null&&(o=e.shape,I.push(e));var n=null;if(E!=null&&(n=E.shape,I.push(E)),BA().getBool("WEBGL_PACK_NORMALIZATION")){var i=new Nf(B.shape,Q.shape,w.shape,o,n,C);return this.compileAndRun(i,I)}var Y=new Jf(B.shape,Q.shape,w.shape,o,n,C);return this.compileAndRun(Y,I)},g.prototype.localResponseNormalization4D=function(B,Q,w,C,E){var e=BA().getBool("WEBGL_PACK_NORMALIZATION")?new dJ(B.shape,Q,w,C,E):new hJ(B.shape,Q,w,C,E);return this.compileAndRun(e,[B])},g.prototype.LRNGrad=function(B,Q,w,C,E,e,I){var o=new lJ(Q.shape,C,E,e,I);return this.compileAndRun(o,[Q,w,B])},g.prototype.tile=function(B,Q){if(B.dtype==="string"){var w=this.readSync(B.dataId).map(function(E){return XE(E)});return fc(zA(B.shape,B.dtype,w),Q)}var C=new OJ(B.shape,Q);return this.compileAndRun(C,[B])},g.prototype.pad=function(B,Q,w){var C=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new PJ(B.shape,Q,w):new RJ(B.shape,Q,w);return this.compileAndRun(C,[B])},g.prototype.transpose=function(B,Q){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.transpose(B,Q);var w=BA().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new qJ(B.shape,Q):new ZJ(B.shape,Q);return this.compileAndRun(w,[B])},g.prototype.gather=function(B,Q,w){if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.gather(B,Q,w);var C=new wJ(B.shape,Q.size,w);return this.compileAndRun(C,[B,Q])},g.prototype.batchToSpaceND=function(B,Q,w){R(B.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var C=Q.reduce(function(i,Y){return i*Y}),E=Ee(B.shape,Q,C),e=ee(E.length,Q.length),I=Ie(B.shape,Q,C),o=ic(w,Q.length),n=Yc(I,w,Q.length);return B.reshape(E).transpose(e).reshape(I).slice(o,n)},g.prototype.spaceToBatchND=function(B,Q,w){R(B.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var C=Q.reduce(function(Y,M){return Y*M}),E=[[0,0]];E.push.apply(E,w);for(var e=1+Q.length;e<B.shape.length;++e)E.push([0,0]);var I=B.pad(E),o=Ee(I.shape,Q,C,!1),n=ee(o.length,Q.length,!1),i=Ie(I.shape,Q,C,!1);return I.reshape(o).transpose(n).reshape(i)},g.prototype.reduce=function(B,Q,w){var C=B.shape[0],E=B.shape[1],e=Qt(E),I=new vJ({windowSize:e,inSize:E,batchSize:C},Q),o=this.compileAndRun(I,[B],w);return o.shape[1]===1?o:this.reduce(o,Q,w)},g.prototype.argReduce=function(B,Q,w){w===void 0&&(w=null);var C=B.shape[0],E=B.shape[1];w!=null&&(C=w.shape[0],E=w.shape[1]);var e=Qt(E),I=new sf({windowSize:e,inSize:E,batchSize:C},Q,w==null),o=[B];w!=null&&o.push(w);var n=this.compileAndRun(I,o,"int32");return n.shape[1]===1?n:this.argReduce(B,Q,n)},g.prototype.argReducePacked=function(B,Q,w){w===void 0&&(w=null);var C=w!=null?w.shape:B.shape,E=Qt(C[C.length-1]),e=new df(C,E,Q,w==null),I=w==null?[B]:[B,w],o=this.compileAndRun(e,I,"int32");return o.rank===B.rank?this.argReducePacked(B,Q,o):o},g.prototype.sum=function(B,Q){dg("sum",Q,B.rank);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E),I=So(B.dtype);return this.reduce(e,"sum",I).reshape(C)},g.prototype.prod=function(B,Q){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.prod(B,Q);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E),I=So(B.dtype);return this.reduce(e,"prod",I).reshape(C)},g.prototype.unsortedSegmentSum=function(B,Q,w){var C=0,E=$g([C],B.rank),e=B;E!=null&&(e=B.transpose(E),C=AQ(1,B.rank)[0]);var I=function(M,c,D){for(var r=[],F=M.length,s=0;s<F;s++)s!==c?r.push(M[s]):r.push(D);return r}(e.shape,C,w),o=hA([e.shape[C]]),n=e.as2D(-1,o),i=So(B.dtype),Y=this.segOpCompute(n,"unsortedSegmentSum",Q,i,w).reshape(I);return E!=null&&(Y=Y.transpose(_o(E))),Y},g.prototype.segOpCompute=function(B,Q,w,C,E){var e=B.shape[0],I=B.shape[1],o=function(Y,M){var c,D=!1;for(Y<=cc?(c=Y,D=!0):c=To(Y,Math.floor(Math.sqrt(Y)));!D;)c>M||c===Y?D=!0:c=To(Y,c+1);return c}(I,E),n=new LJ({windowSize:o,inSize:I,batchSize:e,numSegments:E}),i=this.compileAndRun(n,[B,w],C);return i.shape[1]===E?i:(w=we(0,E).tile([I/o]),this.segOpCompute(i,Q,w,C,E))},g.prototype.argMinMaxReduce=function(B,Q,w){var C=[Q];if(dg("arg"+w.charAt(0).toUpperCase()+w.slice(1),C,B.rank),!BA().getBool("WEBGL_PACK_REDUCE")||B.rank<=2){var E=gg(B.shape,C),e=E[0],I=hA(E[1]),o=B.as2D(-1,I);return this.argReduce(o,w).reshape(e)}return this.argReducePacked(B,w)},g.prototype.argMin=function(B,Q){return this.argMinMaxReduce(B,Q,"min")},g.prototype.argMax=function(B,Q){return this.argMinMaxReduce(B,Q,"max")},g.prototype.cumsum=function(B,Q,w,C){if(Q!==B.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(B.rank-1)+" but got axis="+Q);var E=new Vf(B.shape,w,C);return this.compileAndRun(E,[B])},g.prototype.equal=function(B,Q){if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,`
3524
3524
  return vec4(equal(a, b));
3525
3525
  `,"bool");var w=new lB("return float(a == b);",B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"bool")},g.prototype.notEqual=function(B,Q){if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,`
3526
3526
  return vec4(notEqual(a, b));
@@ -3541,7 +3541,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
3541
3541
  vec4(greaterThanEqual(a, vec4(1.0))) +
3542
3542
  vec4(greaterThanEqual(b, vec4(1.0))),
3543
3543
  vec4(1.0));
3544
- `,"bool");var w=new lB("return float(a >= 1.0 || b >= 1.0);",B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"bool")},g.prototype.select=function(B,Q,w){var C=new SJ(B.rank,Q.shape,Q.rank);return this.compileAndRun(C,[B,Q,w],_B(Q.dtype,w.dtype))},g.prototype.where=function(B){ge("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var Q=B.dataSync();return tt(B.shape,Q)},g.prototype.topk=function(B,Q,w){return Jc(B.dataSync(),B.shape,B.dtype,Q)},g.prototype.min=function(B,Q){dg("min",Q,B.rank);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E);return this.reduce(e,"min",e.dtype).reshape(C)},g.prototype.minimum=function(B,Q){if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.minimum(B,Q);var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3544
+ `,"bool");var w=new lB("return float(a >= 1.0 || b >= 1.0);",B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"bool")},g.prototype.select=function(B,Q,w){var C=new bJ(B.rank,Q.shape,Q.rank);return this.compileAndRun(C,[B,Q,w],_B(Q.dtype,w.dtype))},g.prototype.where=function(B){ge("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var Q=B.dataSync();return nt(B.shape,Q)},g.prototype.topk=function(B,Q,w){return Jc(B.dataSync(),B.shape,B.dtype,Q)},g.prototype.min=function(B,Q){dg("min",Q,B.rank);var w=gg(B.shape,Q),C=w[0],E=hA(w[1]),e=B.as2D(-1,E);return this.reduce(e,"min",e.dtype).reshape(C)},g.prototype.minimum=function(B,Q){if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.minimum(B,Q);var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3545
3545
  vec4 result = vec4(min(a, b));
3546
3546
  vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
3547
3547
 
@@ -3635,7 +3635,7 @@ return a / b;`,B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"float32")},g.
3635
3635
  } else {
3636
3636
  return NAN;
3637
3637
  }
3638
- `,B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"int32")},g.prototype.add=function(B,Q){if(B.dtype==="complex64"&&Q.dtype==="complex64")return this.complexSeparableBinaryOp(B,Q,it);if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.add(B,Q);var w=_B(B.dtype,Q.dtype);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,it,w);var C=new lB(it,B.shape,Q.shape);return this.compileAndRun(C,[B,Q],w)},g.prototype.packedUnaryOp=function(B,Q,w){var C=new yC(B.shape,Q);return this.compileAndRun(C,[B],w)},g.prototype.packedBinaryOp=function(B,Q,w,C,E){E===void 0&&(E=!1);var e=new FQ(w,B.shape,Q.shape,E);return this.compileAndRun(e,[B,Q],C)},g.prototype.complexSeparableBinaryOp=function(B,Q,w){var C=this,E=this.texData.get(B.dataId),e=this.texData.get(Q.dataId),I=[[E.complexTensors.real,e.complexTensors.real],[E.complexTensors.imag,e.complexTensors.imag]].map(function(Y){var M=Y[0],c=Y[1],D=C.makeComplexComponentTensorInfo(B,M),r=C.makeComplexComponentTensorInfo(Q,c),F=new lB(w,B.shape,Q.shape);return C.compileAndRun(F,[D,r],_B(M.dtype,c.dtype))}),o=I[0],n=I[1],i=this.complex(o,n);return o.dispose(),n.dispose(),i},g.prototype.makeComplexComponentTensorInfo=function(B,Q){return{dataId:Q.dataId,dtype:Q.dtype,shape:B.shape}},g.prototype.addN=function(B){if(B.length===1)return B[0];if(B.length>BA().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var Q=Math.floor(B.length/2),w=this.addN(B.slice(0,Q)),C=this.addN(B.slice(Q));return this.addN([w,C])}var E=B.map(function(o){return o.dtype}).reduce(function(o,n){return _B(o,n)}),e=B.map(function(o){return o.shape}),I=BA().getBool("WEBGL_PACK")?new rf(B[0].shape,e):new Df(B[0].shape,e);return this.compileAndRun(I,B,E)},g.prototype.subtract=function(B,Q){if(B.dtype==="complex64"&&Q.dtype==="complex64")return this.complexSeparableBinaryOp(B,Q,Yt);if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.subtract(B,Q);var w=_B(B.dtype,Q.dtype);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,Yt,B.dtype);var C=new lB(Yt,B.shape,Q.shape);return this.compileAndRun(C,[B,Q],w)},g.prototype.pow=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3638
+ `,B.shape,Q.shape);return this.compileAndRun(w,[B,Q],"int32")},g.prototype.add=function(B,Q){if(B.dtype==="complex64"&&Q.dtype==="complex64")return this.complexSeparableBinaryOp(B,Q,Yt);if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.add(B,Q);var w=_B(B.dtype,Q.dtype);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,Yt,w);var C=new lB(Yt,B.shape,Q.shape);return this.compileAndRun(C,[B,Q],w)},g.prototype.packedUnaryOp=function(B,Q,w){var C=new yC(B.shape,Q);return this.compileAndRun(C,[B],w)},g.prototype.packedBinaryOp=function(B,Q,w,C,E){E===void 0&&(E=!1);var e=new FQ(w,B.shape,Q.shape,E);return this.compileAndRun(e,[B,Q],C)},g.prototype.complexSeparableBinaryOp=function(B,Q,w){var C=this,E=this.texData.get(B.dataId),e=this.texData.get(Q.dataId),I=[[E.complexTensors.real,e.complexTensors.real],[E.complexTensors.imag,e.complexTensors.imag]].map(function(Y){var M=Y[0],c=Y[1],D=C.makeComplexComponentTensorInfo(B,M),r=C.makeComplexComponentTensorInfo(Q,c),F=new lB(w,B.shape,Q.shape);return C.compileAndRun(F,[D,r],_B(M.dtype,c.dtype))}),o=I[0],n=I[1],i=this.complex(o,n);return o.dispose(),n.dispose(),i},g.prototype.makeComplexComponentTensorInfo=function(B,Q){return{dataId:Q.dataId,dtype:Q.dtype,shape:B.shape}},g.prototype.addN=function(B){if(B.length===1)return B[0];if(B.length>BA().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var Q=Math.floor(B.length/2),w=this.addN(B.slice(0,Q)),C=this.addN(B.slice(Q));return this.addN([w,C])}var E=B.map(function(o){return o.dtype}).reduce(function(o,n){return _B(o,n)}),e=B.map(function(o){return o.shape}),I=BA().getBool("WEBGL_PACK")?new af(B[0].shape,e):new Ff(B[0].shape,e);return this.compileAndRun(I,B,E)},g.prototype.subtract=function(B,Q){if(B.dtype==="complex64"&&Q.dtype==="complex64")return this.complexSeparableBinaryOp(B,Q,Mt);if(this.shouldExecuteOnCPU([B,Q]))return this.cpuBackend.subtract(B,Q);var w=_B(B.dtype,Q.dtype);if(BA().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(B,Q,Mt,B.dtype);var C=new lB(Mt,B.shape,Q.shape);return this.compileAndRun(C,[B,Q],w)},g.prototype.pow=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3639
3639
  // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
3640
3640
  vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));
3641
3641
  vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);
@@ -3696,7 +3696,7 @@ return (round(mod(b, 2.0)) != 1) ?
3696
3696
  return log(x);`);return this.compileAndRun(Q,[B])},g.prototype.log1p=function(B){var Q=new KA(B.shape,"return log(1.0 + x);");return this.compileAndRun(Q,[B])},g.prototype.sqrt=function(B){var Q=new KA(B.shape,"return sqrt(x);");return this.compileAndRun(Q,[B])},g.prototype.rsqrt=function(B){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.rsqrt(B);var Q=new KA(B.shape,"return inversesqrt(x);");return this.compileAndRun(Q,[B])},g.prototype.reciprocal=function(B){var Q=new KA(B.shape,"return 1.0 / x;");return this.compileAndRun(Q,[B])},g.prototype.relu=function(B){var Q;return Q=BA().getBool("WEBGL_PACK")?new yC(B.shape,BD):new KA(B.shape,xc),this.compileAndRun(Q,[B])},g.prototype.relu6=function(B){var Q;return Q=BA().getBool("WEBGL_PACK")?new yC(B.shape,gD):new KA(B.shape,Xc),this.compileAndRun(Q,[B])},g.prototype.prelu=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(Tc,B.shape,Q.shape):new lB(kc,B.shape,Q.shape);return this.compileAndRun(w,[B,Q])},g.prototype.elu=function(B){if(BA().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(B,QD,B.dtype);var Q=new KA(B.shape,Oc);return this.compileAndRun(Q,[B])},g.prototype.eluDer=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3697
3697
  vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
3698
3698
  return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
3699
- `,B.shape,Q.shape):new lB("return (b >= 1.0) ? a : a * (b + 1.0);",B.shape,Q.shape);return this.compileAndRun(w,[B,Q])},g.prototype.selu=function(B){var Q=new KA(B.shape,qJ);return this.compileAndRun(Q,[B])},g.prototype.int=function(B){var Q=new KA(B.shape,"return float(int(x));");return this.compileAndRun(Q,[B],"int32")},g.prototype.clip=function(B,Q,w){var C,E=(C=BA().getBool("WEBGL_PACK_CLIP")?new Rf(B.shape):new mf(B.shape)).getCustomSetupFunc(Q,w);return this.compileAndRun(C,[B],null,E)},g.prototype.abs=function(B){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.abs(B);if(BA().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(B,Vc,B.dtype);var Q=new KA(B.shape,Vc);return this.compileAndRun(Q,[B])},g.prototype.complexAbs=function(B){var Q=this.texData.get(B.dataId),w=new Pf(B.shape),C=[this.makeComplexComponentTensorInfo(B,Q.complexTensors.real),this.makeComplexComponentTensorInfo(B,Q.complexTensors.imag)];return this.compileAndRun(w,C)},g.prototype.sigmoid=function(B){var Q=new KA(B.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(Q,[B])},g.prototype.softplus=function(B){var Q=new KA(B.shape,`
3699
+ `,B.shape,Q.shape):new lB("return (b >= 1.0) ? a : a * (b + 1.0);",B.shape,Q.shape);return this.compileAndRun(w,[B,Q])},g.prototype.selu=function(B){var Q=new KA(B.shape,$J);return this.compileAndRun(Q,[B])},g.prototype.int=function(B){var Q=new KA(B.shape,"return float(int(x));");return this.compileAndRun(Q,[B],"int32")},g.prototype.clip=function(B,Q,w){var C,E=(C=BA().getBool("WEBGL_PACK_CLIP")?new vf(B.shape):new Pf(B.shape)).getCustomSetupFunc(Q,w);return this.compileAndRun(C,[B],null,E)},g.prototype.abs=function(B){if(this.shouldExecuteOnCPU([B]))return this.cpuBackend.abs(B);if(BA().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(B,Vc,B.dtype);var Q=new KA(B.shape,Vc);return this.compileAndRun(Q,[B])},g.prototype.complexAbs=function(B){var Q=this.texData.get(B.dataId),w=new kf(B.shape),C=[this.makeComplexComponentTensorInfo(B,Q.complexTensors.real),this.makeComplexComponentTensorInfo(B,Q.complexTensors.imag)];return this.compileAndRun(w,C)},g.prototype.sigmoid=function(B){var Q=new KA(B.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(Q,[B])},g.prototype.softplus=function(B){var Q=new KA(B.shape,`
3700
3700
  float epsilon = 1.1920928955078125e-7;
3701
3701
  float threshold = log(epsilon) + 2.0;
3702
3702
 
@@ -3716,7 +3716,7 @@ return (round(mod(b, 2.0)) != 1) ?
3716
3716
  result = log(exp_x + 1.0);
3717
3717
  }
3718
3718
  return result;
3719
- `);return this.compileAndRun(Q,[B])},g.prototype.sin=function(B){var Q=new KA(B.shape,_J);return this.compileAndRun(Q,[B])},g.prototype.cos=function(B){var Q=new KA(B.shape,$J);return this.compileAndRun(Q,[B])},g.prototype.tan=function(B){var Q=new KA(B.shape,"return tan(x);");return this.compileAndRun(Q,[B])},g.prototype.asin=function(B){var Q=new KA(B.shape,AN);return this.compileAndRun(Q,[B])},g.prototype.acos=function(B){var Q=new KA(B.shape,BN);return this.compileAndRun(Q,[B])},g.prototype.atan=function(B){var Q=new KA(B.shape,gN);return this.compileAndRun(Q,[B])},g.prototype.atan2=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3719
+ `);return this.compileAndRun(Q,[B])},g.prototype.sin=function(B){var Q=new KA(B.shape,AN);return this.compileAndRun(Q,[B])},g.prototype.cos=function(B){var Q=new KA(B.shape,BN);return this.compileAndRun(Q,[B])},g.prototype.tan=function(B){var Q=new KA(B.shape,"return tan(x);");return this.compileAndRun(Q,[B])},g.prototype.asin=function(B){var Q=new KA(B.shape,gN);return this.compileAndRun(Q,[B])},g.prototype.acos=function(B){var Q=new KA(B.shape,QN);return this.compileAndRun(Q,[B])},g.prototype.atan=function(B){var Q=new KA(B.shape,wN);return this.compileAndRun(Q,[B])},g.prototype.atan2=function(B,Q){var w=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ(`
3720
3720
  vec4 result = atan(a, b);
3721
3721
  vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
3722
3722
 
@@ -3740,7 +3740,7 @@ return (round(mod(b, 2.0)) != 1) ?
3740
3740
  `);return this.compileAndRun(Q,[B])},g.prototype.tanh=function(B){var Q=new KA(B.shape,`
3741
3741
  float e2x = exp(-2.0 * abs(x));
3742
3742
  return sign(x) * (1.0 - e2x) / (1.0 + e2x);
3743
- `);return this.compileAndRun(Q,[B])},g.prototype.asinh=function(B){var Q=new KA(B.shape,QN);return this.compileAndRun(Q,[B])},g.prototype.acosh=function(B){var Q=new KA(B.shape,wN);return this.compileAndRun(Q,[B])},g.prototype.atanh=function(B){var Q=new KA(B.shape,CN);return this.compileAndRun(Q,[B])},g.prototype.erf=function(B){var Q=new KA(B.shape,`
3743
+ `);return this.compileAndRun(Q,[B])},g.prototype.asinh=function(B){var Q=new KA(B.shape,CN);return this.compileAndRun(Q,[B])},g.prototype.acosh=function(B){var Q=new KA(B.shape,EN);return this.compileAndRun(Q,[B])},g.prototype.atanh=function(B){var Q=new KA(B.shape,eN);return this.compileAndRun(Q,[B])},g.prototype.erf=function(B){var Q=new KA(B.shape,`
3744
3744
  // Error function is calculated approximately with elementary function.
3745
3745
  // See "Handbook of Mathematical Functions with Formulas,
3746
3746
  // Graphs, and Mathematical Tables", Abramowitz and Stegun.
@@ -3757,11 +3757,11 @@ return (round(mod(b, 2.0)) != 1) ?
3757
3757
  return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
3758
3758
  `);return this.compileAndRun(Q,[B])},g.prototype.step=function(B,Q){var w=new KA(B.shape,function(C){return C===void 0&&(C=0),Lg+`
3759
3759
  return x > 0.0 ? 1.0 : float(`+C+`);
3760
- `}(Q));return this.compileAndRun(w,[B])},g.prototype.conv2dByMatMul=function(B,Q,w,C,E,e){var I=B.shape,o=this.texData.get(B.dataId),n=w.inChannels,i=I[0]*I[1]*I[2],Y=w.outChannels,M=w.dataFormat==="channelsLast",c=(i===1||Y===1)&&n>1e3,D=I[2]%2!=0&&!!o.isPacked;if(c||!BA().getBool("WEBGL_LAZILY_UNPACK")||!BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!D){var r=M?I[0]*I[1]*I[2]:I[0]*I[2]*I[3],F=this.reshape(B,[1,r,w.inChannels]),s=this.reshape(Q,[1,w.inChannels,w.outChannels]);return this.reshape(this.fusedBatchMatMul({a:F,b:s,transposeA:!1,transposeB:!1,bias:C,activation:E,preluActivationWeights:e}),w.outShape)}var u=M?I[0]*I[1]*(I[2]+1):I[0]*I[2]*(I[3]+1),a={dataId:B.dataId,shape:[1,u,w.inChannels],dtype:B.dtype},U=o.shape;o.shape=o.shape.slice(),o.shape[o.shape.length-2]++,R(Be(o.shape,a.shape),function(){return"packed reshape "+o.shape+" to "+a.shape+" isn't free"});var G=this.reshape(Q,[1,w.inChannels,w.outChannels]),d=this.fusedBatchMatMul({a,b:G,transposeA:!1,transposeB:!1,bias:C,activation:E,preluActivationWeights:e}),H=this.texData.get(d.dataId);return R(H.isPacked,function(){return"batchMatMul result is expected to be packed"}),o.shape=U,H.shape=w.outShape,b.makeTensorFromDataId(d.dataId,w.outShape,d.dtype)},g.prototype.conv2dWithIm2Row=function(B,Q,w,C,E,e){var I=w.filterWidth,o=w.filterHeight,n=w.inChannels,i=w.outWidth,Y=w.outHeight,M=w.dataFormat==="channelsLast",c=I*o*n,D=Y*i,r=[c,D],F=B.squeeze([0]),s=Q.reshape([1,c,-1]),u=new uJ(r,F.shape,w),a=this.compileAndRun(u,[F]).reshape([1,r[0],r[1]]),U=C!=null,G=e!=null,d=E?re(E,!0):null,H=new Mt(a.shape,[1,D,w.outChannels],!0,!1,U,d,G),h=[a,s];C&&h.push(C),G&&h.push(e);var l=this.compileAndRun(H,h);return M?l.reshape([1,Y,i,w.outChannels]):l.reshape([1,w.outChannels,Y,i])},g.prototype.fusedConv2d=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights;if(C.filterHeight===1&&C.filterWidth===1&&C.dilationHeight===1&&C.dilationWidth===1&&C.strideHeight===1&&C.strideWidth===1&&(C.padInfo.type==="SAME"||C.padInfo.type==="VALID"))return this.conv2dByMatMul(Q,w,C,E,e,I);if(BA().getBool("WEBGL_CONV_IM2COL")&&Q.shape[0]===1)return this.conv2dWithIm2Row(Q,w,C,E,e,I);var o=E!=null,n=I!=null,i=e?re(e,!1):null,Y=new jc(C,o,i,n),M=[Q,w];return E&&M.push(E),I&&M.push(I),this.compileAndRun(Y,M)},g.prototype.conv2d=function(B,Q,w){if(w.filterHeight===1&&w.filterWidth===1&&w.dilationHeight===1&&w.dilationWidth===1&&w.strideHeight===1&&w.strideWidth===1&&(w.padInfo.type==="SAME"||w.padInfo.type==="VALID"))return this.conv2dByMatMul(B,Q,w);if(BA().getBool("WEBGL_CONV_IM2COL")&&B.shape[0]===1)return this.conv2dWithIm2Row(B,Q,w);var C=new jc(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv2dDerInput=function(B,Q,w){var C=new jf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv2dDerFilter=function(B,Q,w){var C=new Tf(w);return this.compileAndRun(C,[B,Q])},g.prototype.fusedDepthwiseConv2D=function(B){var Q,w=B.input,C=B.filter,E=B.convInfo,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=BA().getBool("WEBGL_PACK_DEPTHWISECONV")&&E.strideWidth<=2&&E.outChannels/E.inChannels==1,i=I?re(I,n):null,Y=[w,C],M=e!=null,c=o!=null;return M&&Y.push(e),c&&Y.push(o),n?(Q=new yc(E,M,i,c),this.compileAndRun(Q,Y)):(Q=new pc(E,M,i,c),this.compileAndRun(Q,Y))},g.prototype.depthwiseConv2D=function(B,Q,w){var C;return BA().getBool("WEBGL_PACK_DEPTHWISECONV")&&w.strideWidth<=2&&w.outChannels/w.inChannels==1?(C=new yc(w),this.compileAndRun(C,[B,Q])):(C=new pc(w),this.compileAndRun(C,[B,Q]))},g.prototype.depthwiseConv2DDerInput=function(B,Q,w){var C=new Wf(w);return this.compileAndRun(C,[B,Q])},g.prototype.depthwiseConv2DDerFilter=function(B,Q,w){var C=new zf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3d=function(B,Q,w){var C=new Sf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3dDerInput=function(B,Q,w){var C=new yf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3dDerFilter=function(B,Q,w){var C=new pf(w);return this.compileAndRun(C,[B,Q])},g.prototype.maxPool=function(B,Q){var w=new ct(Q,"max",!1);return this.compileAndRun(w,[B])},g.prototype.avgPool=function(B,Q){var w=new ct(Q,"avg",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.maxPoolBackprop=function(B,Q,w,C){var E=new ct(C,"max",!0),e=this.compileAndRun(E,[Q]),I=new lJ(C),o=this.compileAndRun(I,[B,e],Q.dtype);return e.dispose(),o},g.prototype.avgPoolBackprop=function(B,Q,w){var C=new lf(w);return this.compileAndRun(C,[B],Q.dtype)},g.prototype.cast=function(B,Q){return Uc(B,Q,this)},g.prototype.unstack=function(B,Q){for(var w=B.shape[Q],C=new Array(B.rank-1),E=0,e=0;e<B.rank;e++)e!==Q&&(C[E++]=B.shape[e]);var I=new Array(B.rank).fill(0),o=B.shape.slice();o[Q]=1;var n=new Array(w);for(e=0;e<n.length;e++)I[Q]=e,n[e]=this.slice(B,I,o).reshape(C);return n},g.prototype.avgPool3d=function(B,Q){var w=new Dt(Q,"avg",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.avgPool3dBackprop=function(B,Q,w){var C=new df(w);return this.compileAndRun(C,[B],Q.dtype)},g.prototype.maxPool3d=function(B,Q){var w=new Dt(Q,"max",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.maxPool3dBackprop=function(B,Q,w,C){var E=new Dt(C,"max",!0),e=this.compileAndRun(E,[Q]),I=new dJ(C),o=this.compileAndRun(I,[B,e],Q.dtype);return e.dispose(),o},g.prototype.reshape=function(B,Q){var w=this.texData.get(B.dataId);if(w.isPacked&&!Be(B.shape,Q)&&(w.texture===null||!Be(w.shape,Q))){var C=this.packedReshape(B,Q);return b.makeTensorFromDataId(C.dataId,C.shape,C.dtype)}return Et(B,Q)},g.prototype.resizeBilinear=function(B,Q,w,C){var E=BA().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new TJ(B.shape,Q,w,C):new kJ(B.shape,Q,w,C);return this.compileAndRun(E,[B],"float32")},g.prototype.resizeBilinearBackprop=function(B,Q,w){var C=new vJ(B,Q,w);return this.compileAndRun(C,[B])},g.prototype.resizeNearestNeighbor=function(B,Q,w,C){var E=new pJ(B.shape,Q,w,C);return this.compileAndRun(E,[B])},g.prototype.resizeNearestNeighborBackprop=function(B,Q,w){var C=new jJ(B,Q,w);return this.compileAndRun(C,[B])},g.prototype.multinomial=function(B,Q,w,C){var E=Q?B:rQ(B),e=E.shape[0],I=E.shape[1],o=new HJ(e,I,w),n=o.getCustomSetupFunc(C);return this.compileAndRun(o,[E],"int32",n)},g.prototype.oneHot=function(B,Q,w,C){var E=new fJ(B.size,Q,w,C);return this.compileAndRun(E,[B])},g.prototype.diag=function(B){var Q=new Xf(B.size);return this.compileAndRun(Q,[B])},g.prototype.nonMaxSuppression=function(B,Q,w,C,E){return ge("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"),It(B.dataSync(),Q.dataSync(),w,C,E)},g.prototype.cropAndResize=function(B,Q,w,C,E,e){var I=new Lf(B.shape,Q.shape,C,E,e);return this.compileAndRun(I,[B,Q,w],"float32")},g.prototype.depthToSpace=function(B,Q,w){R(Q>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+Q});var C=B.shape[0],E=w==="NHWC"?B.shape[1]:B.shape[2],e=w==="NHWC"?B.shape[2]:B.shape[3],I=w==="NHWC"?B.shape[3]:B.shape[1],o=E*Q,n=e*Q,i=I/(Q*Q),Y=new xf(w==="NHWC"?[C,o,n,i]:[C,i,o,n],Q,w);return this.compileAndRun(Y,[B])},g.prototype.split=function(B,Q,w){return Hc(B,Q,w)},g.prototype.scatterND=function(B,Q,w){var C=oe(0,B,w),E=C.sliceRank,e=C.numUpdates,I=C.sliceSize,o=C.strides,n=C.outputSize,i=[n/I,I],Y=B.reshape([e,E]),M=Q.reshape([e,I]);if(n===0)return Et(Ag([]),w);var c=nA(0),D=new Lc(e,E,Y.rank,M.rank,o,i);return this.compileAndRun(D,[M,Y,c]).reshape(w)},g.prototype.sparseToDense=function(B,Q,w,C){var E=oe(0,B,w),e=E.sliceRank,I=E.numUpdates,o=E.strides,n=E.outputSize,i=new Lc(I,e,B.rank,Q.rank,o,[n,1]);return this.compileAndRun(i,[Q,B,C]).reshape(w)},g.prototype.fft=function(B){return this.fftImpl(B,!1)},g.prototype.ifft=function(B){return this.fftImpl(B,!0)},g.prototype.fftImpl=function(B,Q){var w=this.texData.get(B.dataId),C=new Wc($f,B.shape,Q),E=new Wc(AJ,B.shape,Q),e=[this.makeComplexComponentTensorInfo(B,w.complexTensors.real),this.makeComplexComponentTensorInfo(B,w.complexTensors.imag)],I=this.compileAndRun(C,e),o=this.compileAndRun(E,e),n=this.complex(I,o).as2D(B.shape[0],B.shape[1]);return I.dispose(),o.dispose(),n},g.prototype.gatherND=function(B,Q){var w=Q.shape,C=w[w.length-1],E=Mc(B,Q),e=E[0],I=E[1],o=E[2],n=E[3],i=Q.reshape([I,C]),Y=B.reshape([B.size/o,o]),M=new QJ(C,n,[I,o]);return this.compileAndRun(M,[Y,i]).reshape(e)},g.prototype.fill=function(B,Q,w){if((w=w||HC(Q))==="string"){var C=xE(w,hA(B));return C.fill(Q),b.makeTensor(C,B,w,this)}var E=new BJ(B,Q),e=E.getCustomSetupFunc(Q);return this.compileAndRun(E,[],w,e)},g.prototype.onesLike=function(B){if(B.dtype==="string")throw new Error("onesLike is not supported under string dtype");return this.fill(B.shape,1,B.dtype)},g.prototype.zerosLike=function(B){return this.fill(B.shape,B.dtype==="string"?"":0,B.dtype)},g.prototype.linspace=function(B,Q,w){return Gc(B,Q,w)},g.prototype.makeTensorInfo=function(B,Q){var w=this.write(null,B,Q);return this.texData.get(w).usage=null,{dataId:w,shape:B,dtype:Q}},g.prototype.makeOutput=function(B,Q){var w=this.makeTensorInfo(B,Q).dataId;return b.makeTensorFromDataId(w,B,Q,this)},g.prototype.unpackTensor=function(B){var Q=new eN(B.shape);return this.runWebGLProgram(Q,[B],B.dtype)},g.prototype.packTensor=function(B){var Q=new JJ(B.shape);return this.runWebGLProgram(Q,[B],B.dtype,null,!0)},g.prototype.packedReshape=function(B,Q){var w=[_E(B.shape)].concat($E(B.shape)),C={dtype:B.dtype,shape:w,dataId:B.dataId},E=[_E(Q)].concat($E(Q)),e=new PJ(E,w),I=this.runWebGLProgram(e,[C],B.dtype,null,!0);return{dataId:I.dataId,shape:Q,dtype:I.dtype}},g.prototype.decode=function(B){var Q,w=this.texData.get(B),C=w.isPacked,E=w.shape,e=w.dtype,I=Oo(E);return Q=C?new Vf(I):new Kf(I),{dtype:e,shape:E,dataId:this.runWebGLProgram(Q,[{shape:I,dtype:e,dataId:B}],e,null,!0).dataId}},g.prototype.runWebGLProgram=function(B,Q,w,C,E){var e=this;E===void 0&&(E=!1);var I=this.makeTensorInfo(B.outputShape,w),o=this.texData.get(I.dataId);if(B.packedOutput&&(o.isPacked=!0),B.outPackingScheme===PC.DENSE){var n=vC(B.outputShape);o.texShape=n.map(function(u){return 2*u})}if(B.outTexUsage!=null&&(o.usage=B.outTexUsage),hA(I.shape)===0)return o.values=dC(I.dtype,0),I;var i=[],Y=Q.map(function(u){if(u.dtype==="complex64")throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var a=e.texData.get(u.dataId);if(a.texture==null){if(!B.packedInputs&&hA(u.shape)<=BA().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:u.shape,texData:null,isUniform:!0,uniformValues:a.values};B.packedInputs&&(a.isPacked=!0,a.shape=u.shape)}else if(!!a.isPacked!=!!B.packedInputs)u=a.isPacked?e.unpackTensor(u):e.packTensor(u),i.push(u),a=e.texData.get(u.dataId);else if(a.isPacked&&!Be(a.shape,u.shape)){var U=u,G=u.shape;u.shape=a.shape,u=e.packedReshape(u,G),i.push(u),a=e.texData.get(u.dataId),U.shape=G}return e.uploadToGPU(u.dataId),{shape:u.shape,texData:a,isUniform:!1}});this.uploadToGPU(I.dataId);var M,c={shape:I.shape,texData:o,isUniform:!1},D=function(u,a,U){var G="";a.concat(U).forEach(function(h){var l=h.texData!=null&&h.texData.slice!=null&&h.texData.slice.flatOffset>0,m=h.isUniform?"uniform":h.texData.texShape;G+=h.shape+"_"+m+"_"+l});var d=u.userCode,H=u.constructor.name;return H+="_"+G+"_"+d}(B,Y,c),r=this.getAndSaveBinary(D,function(){return function(u,a,U,G){var d=a.userCode,H=U.map(function(p,K){var V={logicalShape:p.shape,texShape:p.isUniform?null:p.texData.texShape,isUniform:p.isUniform,isPacked:!p.isUniform&&p.texData.isPacked,flatOffset:null};return p.texData!=null&&p.texData.slice!=null&&p.texData.slice.flatOffset>0&&(V.flatOffset=p.texData.slice.flatOffset),{name:a.variableNames[K],shapeInfo:V}}),h=H.map(function(p){return p.shapeInfo}),l={logicalShape:G.shape,texShape:G.texData.texShape,isUniform:!1,isPacked:G.texData.isPacked,flatOffset:null},m=af(H,l,d,a.packedInputs),f=u.createProgram(m),W=null,N=u.getUniformLocation(f,"NAN",!1);BA().getNumber("WEBGL_VERSION")===1&&(W=u.getUniformLocation(f,"INFINITY",!1));for(var v={},y=0;y<a.variableNames.length;y++){var k=a.variableNames[y];v[k]=u.getUniformLocation(f,k,!1),v["offset"+k]=u.getUniformLocation(f,"offset"+k,!1)}return{program:a,source:m,webGLProgram:f,uniformLocations:v,inShapeInfos:h,outShapeInfo:l,infLoc:W,nanLoc:N}}(e.gpgpu,B,Y,c)}),F=this.activeTimers!=null;if(F&&(M=this.startTimer()),function(u,a,U,G,d){Sc(a.inShapeInfos,U),Sc([a.outShapeInfo],[G]);var H=G.texData.texture,h=G.texData.texShape;G.texData.isPacked?u.setOutputPackedMatrixTexture(H,h[0],h[1]):u.setOutputMatrixTexture(H,h[0],h[1]),u.setProgram(a.webGLProgram),BA().getNumber("WEBGL_VERSION")===1&&a.infLoc!==null&&u.gl.uniform1f(a.infLoc,1/0),a.nanLoc!==null&&u.gl.uniform1f(a.nanLoc,NaN),U.forEach(function(l,m){var f=a.program.variableNames[m],W=a.uniformLocations[f],N=a.uniformLocations["offset"+f];if(W!=null)if(l.isUniform)if(hA(l.shape)<2)u.gl.uniform1f(W,l.uniformValues[0]);else{var v=l.uniformValues;v instanceof Float32Array||(v=new Float32Array(v)),u.gl.uniform1fv(W,v)}else l.texData.slice!=null&&N!=null&&u.gl.uniform1i(N,l.texData.slice.flatOffset),u.setInputMatrixTexture(l.texData.texture,W,m)}),d!=null&&d(u,a.webGLProgram),u.executeProgram()}(this.gpgpu,r,Y,c,C),i.forEach(function(u){return e.disposeData(u.dataId)}),F&&(M=this.endTimer(M),this.activeTimers.push({name:B.constructor.name,query:this.getQueryTime(M)})),!BA().getBool("WEBGL_LAZILY_UNPACK")&&o.isPacked&&E===!1){var s=this.unpackTensor(I);return this.disposeData(I.dataId),s}return I},g.prototype.compileAndRun=function(B,Q,w,C,E){E===void 0&&(E=!1),w=w||Q[0].dtype;var e=this.runWebGLProgram(B,Q,w,C,E);return b.makeTensorFromDataId(e.dataId,e.shape,e.dtype)},g.prototype.getAndSaveBinary=function(B,Q){return B in this.binaryCache||(this.binaryCache[B]=Q()),this.binaryCache[B]},g.prototype.getTextureManager=function(){return this.textureManager},g.prototype.dispose=function(){var B=this;this.disposed||(BA().getBool("IS_TEST")||Object.keys(this.binaryCache).forEach(function(Q){B.gpgpu.deleteProgram(B.binaryCache[Q].webGLProgram),delete B.binaryCache[Q]}),this.textureManager.dispose(),this.canvas!=null&&typeof HTMLCanvasElement<"u"&&this.canvas instanceof HTMLCanvasElement?this.canvas.remove():this.canvas=null,this.gpgpuCreatedLocally&&(this.gpgpu.program=null,this.gpgpu.dispose()),this.disposed=!0)},g.prototype.floatPrecision=function(){var B=this;return this.floatPrecisionValue==null&&(this.floatPrecisionValue=DA(function(){if(!BA().get("WEBGL_RENDER_FLOAT32_ENABLED")){var Q=BA().getBool("DEBUG");BA().set("DEBUG",!1);var w=B.abs(nA(1e-8)).dataSync()[0];if(BA().set("DEBUG",Q),w>0)return 32}return 16})),this.floatPrecisionValue},g.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},g.prototype.uploadToGPU=function(B){var Q,w=this.texData.get(B),C=w.shape,E=w.dtype,e=w.values,I=w.texture,o=w.usage,n=w.isPacked;if(I==null){var i,Y=this.activeTimers!=null;Y&&(i=Zg());var M=w.texShape;if(M==null&&(M=MH(C,n),w.texShape=M),e!=null){var c=Oo(C),D=void 0,r=M[1],F=M[0],s=e instanceof Uint8Array;n?(r=(Q=kC(M[0],M[1]))[0],F=Q[1],D=new _f(c,[F,r],s)):D=new qf(c,[F,r],s);var u=this.makeTensorInfo([F,r],E);this.texData.get(u.dataId).usage=s?hg.PIXELS:hg.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(u.dataId),r,F,e);var a=this.runWebGLProgram(D,[u],E,null,!0),U=this.texData.get(a.dataId);w.texture=U.texture,w.texShape=U.texShape,w.isPacked=U.isPacked,w.usage=U.usage,this.disposeData(u.dataId),this.texData.delete(a.dataId),w.values=null,Y&&(this.uploadWaitMs+=Zg()-i)}else{var G=this.acquireTexture(M,o,E,n);w.texture=G}}},g.prototype.convertAndCacheOnCPU=function(B,Q){var w=this.texData.get(B),C=w.dtype;return this.releaseGPUData(B),Q!=null&&(w.values=function(E,e){if(e==="float32"||e==="complex64")return E;if(e==="int32"||e==="bool"){for(var I=e==="int32"?new Int32Array(E.length):new Uint8Array(E.length),o=0;o<I.length;++o)I[o]=Math.round(E[o]);return I}throw new Error("Unknown dtype "+e)}(Q,C)),w.values},g.prototype.acquireTexture=function(B,Q,w,C){if(this.numBytesInGPU+=this.computeBytes(B,w),!this.warnedAboutMemory&&this.numBytesInGPU>1024*this.numMBBeforeWarning*1024){var E=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+E+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(B,Q,C)},g.prototype.computeBytes=function(B,Q){return B[0]*B[1]*WM(Q)},g}(sc);$M()&&b.registerBackend("webgl",function(){return new oN},2);var tN=z({square_:function(A){var g=J(A,"x","square"),B=[g];return b.runKernelFunc(function(Q,w){return w([g]),Q.square(g)},{x:g},null,"Square",{},B,[])}}),zC="SquaredDifference",wD=z({squaredDifference_:function(A,g){var B,Q=J(A,"a","squaredDifference"),w=J(g,"b","squaredDifference");B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape);var C={a:Q,b:w},E=[Q,w];return b.runKernelFunc(function(e,I){var o=e.squaredDifference(Q,w);return I([Q,w]),o},C,function(e,I){var o=I[0],n=I[1],i=nA(2);return{a:function(){return e.mul(o.sub(n).mul(i))},b:function(){return e.mul(n.sub(o).mul(i))}}},zC,{},E,[])}}),nN=z({abs_:function(A){var g=J(A,"x","abs");return g.dtype==="complex64"?b.runKernelFunc(function(B){return B.complexAbs(g)},{$x:g}):b.runKernelFunc(function(B,Q){var w=B.abs(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mul(w.toFloat().step(-1))}}},"Abs")}}),iN=z({acos_:function(A){var g=J(A,"x","acos");return b.runKernelFunc(function(B,Q){var w=B.acos(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).sub(w.toFloat().square()).sqrt()).neg()}}})}}),YN=z({acosh_:function(A){var g=J(A,"x","acosh");return b.runKernelFunc(function(B,Q){var w=B.acosh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(w.toFloat().square().sub(1).sqrt())}}})}}),MN=z({asin_:function(A){var g=J(A,"x","asin");return b.runKernelFunc(function(B,Q){var w=B.asin(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).sub(w.toFloat().square()).sqrt())}}})}}),cN=z({asinh_:function(A){var g=J(A,"x","asinh");return b.runKernelFunc(function(B,Q){var w=B.asinh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).add(w.toFloat().square()).sqrt())}}})}}),DN=z({atan_:function(A){var g=J(A,"x","atan");return b.runKernelFunc(function(B,Q){var w=B.atan(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.toFloat().square().add(1))}}})}}),rN=z({atanh_:function(A){var g=J(A,"x","atanh");return b.runKernelFunc(function(B,Q){var w=B.atanh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(nA(1).sub(w.toFloat().square()))}}})}}),FN=z({ceil_:function(A){var g=J(A,"x","ceil");return b.runKernelFunc(function(B){return B.ceil(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),st=z({clipByValue_:function(A,g,B){var Q=J(A,"x","clipByValue");R(g<=B,function(){return"Error in clip: min ("+g+") must be less than or equal to max ("+B+")."});var w=[Q],C={min:g,max:B};return b.runKernelFunc(function(E,e){var I=E.clip(Q,g,B);return e([Q]),I},{x:Q},function(E,e){var I=e[0];return{x:function(){return E.where(I.greaterEqual(g).logicalAnd(I.lessEqual(B)),$A(E))}}},"ClipByValue",C,w)}}),aN=z({cos_:function(A){var g=J(A,"x","cos"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.cos(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return C.toFloat().sin().neg().mul(Q)}}},"Cos",{},B)}}),sN=z({cosh_:function(A){var g=J(A,"x","cosh");return b.runKernelFunc(function(B,Q){var w=B.cosh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return w.toFloat().sinh().mulStrict(B)}}})}}),uN=z({erf_:function(A){var g=J(A,"x","erf");return R(g.dtype==="int32"||g.dtype==="float32",function(){return"Input dtype must be `int32` or `float32`."}),g.dtype==="int32"&&(g=g.toFloat()),b.runKernelFunc(function(B,Q){var w=B.erf(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),ut=z({exp_:function(A){var g=J(A,"x","exp");return b.runKernelFunc(function(B,Q){var w=B.exp(g);return Q([w]),w},{x:g},function(B,Q){return{x:function(){return B.mulStrict(Q[0])}}},"Exp",{},[],[!0])}}),UN=z({expm1_:function(A){var g=J(A,"x","expm1");return b.runKernelFunc(function(B,Q){var w=B.expm1(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.exp())}}})}}),GN=z({floor_:function(A){var g=J(A,"x","floor");return b.runKernelFunc(function(B){return B.floor(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),hN=z({log_:function(A){var g=J(A,"x","log"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.log(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return Q.div(C.toFloat())}}},"Log",{},B)}}),lN=z({log1p_:function(A){var g=J(A,"x","log1p");return b.runKernelFunc(function(B,Q){var w=B.log1p(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.add(1))}}})}}),dN=z({logSigmoid_:function(A){var g=J(A,"x","logSigmoid");return b.runKernelFunc(function(B,Q){var w=B.softplus(g.neg()).neg();return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.neg().sigmoid())}}})}}),Fe=z({neg_:function(A){var g=J(A,"x","neg"),B=[g];return b.runKernelFunc(function(Q){return Q.neg(g)},{x:g},function(Q){return{x:function(){return Q.neg()}}},"Neg",{},B)}}),HN=z({reciprocal_:function(A){var g=J(A,"x","reciprocal");return b.runKernelFunc(function(B,Q){var w=B.reciprocal(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.square().neg())}}})}}),fN=z({round_:function(A){var g=J(A,"x","round");return b.runKernelFunc(function(B){return B.round(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),CD=z({rsqrt_:function(A){var g=J(A,"x","rsqrt"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.rsqrt(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return Q.div(C.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},B)}}),ED=z({sigmoid_:function(A){var g=J(A,"x","sigmoid");return b.runKernelFunc(function(B,Q){var w=B.sigmoid(g);return Q([w]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mul(w.mul(nA(1).sub(w)))}}},"Sigmoid")}}),JN=z({sign_:function(A){var g=J(A,"x","sign");return b.runKernelFunc(function(B){return B.sign(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),NN=z({isNaN_:function(A){var g=J(A,"x","isNaN");return b.runKernelFunc(function(B){return B.isNaN(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),mN=z({isInf_:function(A){var g=J(A,"x","isInf");return b.runKernelFunc(function(B){return B.isInf(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),RN=z({isFinite_:function(A){var g=J(A,"x","isFinite");return b.runKernelFunc(function(B){return B.isFinite(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),PN=z({sin_:function(A){var g=J(A,"x","sin"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.sin(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return C.toFloat().cos().mul(Q)}}},"Sin",{},B)}}),vN=z({sinh_:function(A){var g=J(A,"x","sinh");return b.runKernelFunc(function(B,Q){var w=B.sinh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return w.toFloat().cosh().mulStrict(B)}}})}}),kN=z({softplus_:function(A){var g=J(A,"x","softplus");return b.runKernelFunc(function(B,Q){var w=B.softplus(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.sigmoid())}}})}}),TN=z({sqrt_:function(A){var g=J(A,"x","sqrt");return b.runKernelFunc(function(B,Q){var w=B.sqrt(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.toFloat().sqrt().mul(2))}}})}}),jN=z({step_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","step");return b.runKernelFunc(function(Q){return Q.step(B,g)},{$x:B},function(Q){return{$x:function(){return $A(Q)}}})}}),pN=z({tan_:function(A){var g=J(A,"x","tan");return b.runKernelFunc(function(B,Q){var w=B.tan(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.cos().square())}}})}}),yN=z({tanh_:function(A){var g=J(A,"x","tanh");return b.runKernelFunc(function(B,Q){var w=B.tanh(g);return Q([w]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return nA(1).sub(w.square()).mulStrict(B)}}},"Tanh",{},null,[!0])}});function eD(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===2,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+I.rank+"."}),R(o.rank===2||o.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+o.rank+"."}),R(n.rank===2||n.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===2||E.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===2||e.rank===1,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function ID(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===3,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+I.rank+"."}),R(o.rank===3||o.rank===1,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+o.rank+"."}),R(n.rank===3||n.rank===1,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===3||E.rank===1,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===3||e.rank===1,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function oD(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===4,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+I.rank+"."}),R(o.rank===4||o.rank===1,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+o.rank+"."}),R(n.rank===4||n.rank===1,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===4||E.rank===1,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===4||e.rank===1,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function WC(A,g,B,Q,w,C){C==null&&(C=.001);var E,e,I,o=J(A,"x","batchNorm"),n=J(g,"mean","batchNorm"),i=J(B,"variance","batchNorm");w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(n.rank===i.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),R(e==null||n.rank===e.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),R(E==null||n.rank===E.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),I=o.rank===0||o.rank===1?o.as4D(1,1,1,o.size):o.rank===2?o.as4D(1,1,o.shape[0],o.shape[1]):o.rank===3?o.as4D(1,o.shape[0],o.shape[1],o.shape[2]):o;var Y=[o,n,i,E];return b.runKernelFunc(function(M,c){var D=M.batchNormalization(I,ae(n),ae(i),C,ae(E),ae(e));return c([o,n,i,E]),D},{x:o,mean:n,variance:i,scale:E,offset:e},function(M,c){var D=c,r=D[0],F=D[1],s=D[2],u=D[3],a=u??nA(1),U=yB(F.shape,I.shape),G=[];if(F.rank===1){for(var d=0;d<I.shape.length-1;++d)G.push(I.shape[d]);G.push(1)}var H=r.sub(F),h=M.mul(a),l=CD(s.add(nA(C))),m=l.mul(l).mul(l).mul(nA(-.5));return{x:function(){return F.rank===1?M.mul(Ww(l.as4D(1,1,1,F.shape[0]),G)).mul(a).reshape(r.shape):M.mul(l).mul(a).reshape(r.shape)},mean:function(){var f=l.mul(nA(-1)).mul(h);return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)},variance:function(){var f=m.mul(H).mul(h);return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)},scale:function(){var f=H.mul(l),W=M.mul(f);return F.rank===1&&(W=W.sum(U)),W.reshape(F.shape)},offset:function(){var f=M;return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)}}},"BatchNormalization",{varianceEpsilon:C},Y).reshape(o.shape)}function ae(A){return A==null?null:A.rank===0?A.as1D():A.rank===1?A:A.rank===2?A.as4D(1,1,A.shape[0],A.shape[1]):A.rank===3?A.as4D(1,A.shape[0],A.shape[1],A.shape[2]):A}function se(){Qc("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon")}var zN=z({batchNormalization2d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),eD(A,g,B,C,w,Q)}}),WN=z({batchNormalization3d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),ID(A,g,B,C,w,Q)}}),SN=z({batchNormalization4d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),oD(A,g,B,C,w,Q)}}),LN=z({batchNormalization_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),WC(A,g,B,C,w,Q)}}),tD=z({batchNorm_:WC}),bN=z({batchNorm2d_:eD}),KN=z({batchNorm3d_:ID}),VN=z({batchNorm4d_:oD}),ue=z({logicalAnd_:function(A,g){var B=J(A,"a","logicalAnd","bool"),Q=J(g,"b","logicalAnd","bool");return qA(B.shape,Q.shape),b.runKernelFunc(function(w){return w.logicalAnd(B,Q)},{a:B,b:Q},null,"LogicalAnd")}}),xN=z({logicalNot_:function(A){var g=J(A,"x","logicalNot","bool");return b.runKernelFunc(function(B){return B.logicalNot(g)},{$x:g})}}),nD=z({logicalOr_:function(A,g){var B=J(A,"a","logicalOr","bool"),Q=J(g,"b","logicalOr","bool");return qA(B.shape,Q.shape),b.runKernelFunc(function(w){return w.logicalOr(B,Q)},{$a:B,$b:Q})}}),XN=z({logicalXor_:function(A,g){var B=J(A,"a","logicalXor","bool"),Q=J(g,"b","logicalXor","bool");return qA(B.shape,Q.shape),nD(A,g).logicalAnd(ue(A,g).logicalNot())}}),Iw=z({where_:function(A,g,B){var Q=J(g,"a","where"),w=J(B,"b","where"),C=J(A,"condition","where","bool");return eB(Q.shape,w.shape,"Error in where: "),C.rank===1?R(C.shape[0]===Q.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}):eB(C.shape,w.shape,"Error in where: "),b.runKernelFunc(function(E,e){var I=E.select(C,Q,w);return e([C]),I},{$condition:C,$a:Q,$b:w},function(E,e){var I=e[0];return{$condition:function(){return $A(I).toFloat()},$a:function(){return E.mul(I.cast(E.dtype))},$b:function(){return E.mul(I.logicalNot().cast(E.dtype))}}})}}),iD=function(A){return uA(this,void 0,void 0,function(){var g,B,Q;return UA(this,function(w){switch(w.label){case 0:return[4,(g=J(A,"condition","whereAsync","bool")).data()];case 1:return B=w.sent(),Q=tt(g.shape,B),A!==g&&g.dispose(),[2,Q]}})})},OA=z({add_:function(A,g){var B,Q=J(A,"a","add"),w=J(g,"b","add");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E){return E.add(Q,w)},{a:Q,b:w},function(E){return{a:function(){var e=E,I=yB(Q.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(Q.shape)},b:function(){var e=E,I=yB(w.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(w.shape)}}},"Add")}}),ON=z({addN_:function(A){R(Array.isArray(A),function(){return"The argument passed to tf.addN() must be a list of tensors"}),R(A.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+A.length});var g=A.map(function(w,C){return J(w,"tensors"+C,"addN")}),B=g[0];g.forEach(function(w){if(w.dtype!==B.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),g.forEach(function(w){if(!KB(w.shape,B.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var Q=g;return b.runKernelFunc(function(w){return w.addN(g)},Q,function(w){var C={};return g.forEach(function(E,e){C[e]=function(){return w.clone()}}),C},"AddN")}}),ZN=z({addStrict_:function(A,g){var B=J(A,"a","addStrict"),Q=J(g,"b","addStrict");return eB(B.shape,Q.shape,"Error in addStrict: "),B.add(Q)}}),qN=z({atan2_:function(A,g){var B,Q=J(A,"a","atan2"),w=J(g,"b","atan2");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.atan2(Q,w);return e([Q,w]),I},{$a:Q,$b:w},function(E,e){var I=e[0],o=e[1];return{$a:function(){var n=OA(I.square(),o.square()),i=E.mul(o.div(n)),Y=yB(I.shape,C);return Y.length>0&&(i=i.sum(Y)),i.reshape(I.shape)},$b:function(){var n=OA(I.square(),o.square()),i=Fe(E.mul(I.div(n))),Y=yB(o.shape,C);return Y.length>0&&(i=i.sum(Y)),i.reshape(o.shape)}}})}}),bg=z({div_:function(A,g){var B,Q=J(A,"a","div"),w=J(g,"b","div");if(B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="int32"&&w.dtype==="int32")return YD(Q,w);var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.realDivide(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.div(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);i.length>0&&(n=n.sum(i).reshape(o.shape));var Y=o.square();return n.div(Y.toFloat()).neg()}}},"Div")}}),_N=z({divNoNan_:function(A,g){var B,Q=J(A,"a","div"),w=J(g,"b","div");Q=(B=UB(Q,w))[0],w=B[1];var C=bg(Q,w),E=$A(C),e=w.equal(E);return Iw(e,E,C)}}),$N=z({divStrict_:function(A,g){var B=J(A,"a","div"),Q=J(g,"b","div");return eB(B.shape,Q.shape,"Error in divideStrict: "),B.div(Q)}}),YD=z({floorDiv_:function(A,g){var B,Q=J(A,"a","floorDiv"),w=J(g,"b","floorDiv");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.floorDiv(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.div(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);i.length>0&&(n=n.sum(i).reshape(o.shape));var Y=o.square();return n.div(Y.toFloat()).neg()}}},"FloorDiv")}}),Ut=z({maximum_:function(A,g){var B,Q=J(A,"a","maximum"),w=J(g,"b","maximum");return B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="bool"&&(Q=Q.toInt(),w=w.toInt()),qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.maximum(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return C.mul(e.greaterEqual(I).toFloat())},b:function(){return C.mul(e.less(I).toFloat())}}},"Maximum")}}),Am=z({maximumStrict_:function(A,g){var B=J(A,"a","maximumStrict"),Q=J(g,"b","maximumStrict");return eB(B.shape,Q.shape,"Error in maximumStrict: "),B.maximum(Q)}}),MD=z({minimum_:function(A,g){var B,Q=J(A,"a","minimum"),w=J(g,"b","minimum");return B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="bool"&&(Q=Q.toInt(),w=w.toInt()),qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.minimum(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return C.mul(e.lessEqual(I).toFloat())},b:function(){return C.mul(e.greater(I).toFloat())}}},"Minimum")}}),Bm=z({minimumStrict_:function(A,g){var B=J(A,"a","minimumStrict"),Q=J(g,"b","minimumStrict");return eB(B.shape,Q.shape,"Error in minimumStrict: "),B.minimum(Q)}}),gm=z({mod_:function(A,g){var B,Q=J(A,"a","mod"),w=J(g,"b","mod");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.mod(Q,w);return e([Q,w]),I},{$a:Q,$b:w},function(E,e){var I=e[0],o=e[1];return{$a:function(){var n=yB(I.shape,C);return n.length>0?E.sum(n).reshape(I.shape):E},$b:function(){var n=E.mul(I.div(o).floor().neg()),i=yB(o.shape,C);return i.length>0?n.sum(i).reshape(o.shape):n}}})}}),Qm=z({modStrict_:function(A,g){var B=J(A,"a","modStrict"),Q=J(g,"b","modStrict");return eB(B.shape,Q.shape,"Error in modStrict: "),B.mod(Q)}}),wg=z({mul_:function(A,g){var B,Q=J(A,"a","mul"),w=J(g,"b","mul");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.multiply(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.mul(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);return i.length>0?n.sum(i).reshape(o.shape):n}}},"Mul")}}),wm=z({mulStrict_:function(A,g){var B=J(A,"a","mul"),Q=J(g,"b","mul");return eB(B.shape,Q.shape,"Error in multiplyStrict: "),B.mul(Q)}}),Ue=z({pow_:function(A,g){var B,Q=J(A,"base","pow"),w=J(g,"exp","pow");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape),E=[Q,w];return b.runKernelFunc(function(e,I){var o=e.pow(Q,w);return I([Q,w,o]),o},{a:Q,b:w},function(e,I){var o=I[0],n=I[1],i=I[2];return{a:function(){var Y=n.toFloat(),M=e.mul(Y.mul(o.pow(Y.sub(nA(1))))),c=yB(o.shape,C);return c.length>0&&(M=M.sum(c)),M.reshape(o.shape)},b:function(){var Y=o.greater(0),M=o.log().where(Y,$A(o)),c=e.mul(i.mul(M)),D=yB(n.shape,C);return D.length>0&&(c=c.sum(D)),c.reshape(n.shape)}}},"Pow",{},E,[!0])}}),Cm=z({powStrict_:function(A,g){return eB(A.shape,g.shape,"Error in powStrict: "),A.pow(g)}}),Em=z({squaredDifferenceStrict_:function(A,g){var B=J(A,"a","squaredDifferenceStrict"),Q=J(g,"b","squaredDifferenceStrict");return eB(B.shape,Q.shape,"Error in squaredDifferenceStrict: "),B.squaredDifference(Q)}}),zB=z({sub_:function(A,g){var B,Q=J(A,"a","sub"),w=J(g,"b","sub");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E){return E.subtract(Q,w)},{a:Q,b:w},function(E){return{a:function(){var e=E,I=yB(Q.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(Q.shape)},b:function(){var e=E,I=yB(w.shape,C);return I.length>0&&(e=e.sum(I)),e.neg().reshape(w.shape)}}},"Sub")}}),em=z({subStrict_:function(A,g){var B=J(A,"a","subStrict"),Q=J(g,"b","subStrict");return eB(B.shape,Q.shape,"Error in subStrict: "),B.sub(Q)}}),cD=z({equal_:function(A,g){var B,Q=J(A,"a","equal"),w=J(g,"b","equal");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.equal(Q,w)},{$a:Q,$b:w})}}),Im=z({equalStrict_:function(A,g){var B=J(A,"a","equalStrict"),Q=J(g,"b","equalStrict");return eB(B.shape,Q.shape,"Error in equalStrict: "),B.equal(Q)}}),om=z({greater_:function(A,g){var B,Q=J(A,"a","greater"),w=J(g,"b","greater");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.greater(Q,w)},{a:Q,b:w},null,"Greater")}}),DD=z({greaterEqual_:function(A,g){var B,Q=J(A,"a","greaterEqual"),w=J(g,"b","greaterEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.greaterEqual(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return $A(e)},b:function(){return $A(I)}}},"GreaterEqual")}}),tm=z({greaterEqualStrict_:function(A,g){var B=J(A,"a","greaterEqualStrict"),Q=J(g,"b","greaterEqualStrict");return eB(B.shape,Q.shape,"Error in greaterEqualStrict: "),B.greaterEqual(Q)}}),nm=z({greaterStrict_:function(A,g){var B=J(A,"a","greaterStrict"),Q=J(g,"b","greaterStrict");return eB(B.shape,Q.shape,"Error in greaterStrict: "),B.greater(Q)}}),im=z({less_:function(A,g){var B,Q=J(A,"a","less"),w=J(g,"b","less");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.less(Q,w)},{a:Q,b:w},null,"Less")}}),Ym=z({lessEqual_:function(A,g){var B,Q=J(A,"a","lessEqual"),w=J(g,"b","lessEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.lessEqual(Q,w);return E([Q,w]),e},{a:Q,b:w},null,"LessEqual")}}),Mm=z({lessEqualStrict_:function(A,g){var B=J(A,"a","lessEqualStrict"),Q=J(g,"b","lessEqualStrict");return eB(B.shape,Q.shape,"Error in lessEqualStrict: "),B.lessEqual(Q)}}),cm=z({lessStrict_:function(A,g){var B=J(A,"a","lessStrict"),Q=J(g,"b","lessStrict");return eB(B.shape,Q.shape,"Error in lessStrict: "),B.less(Q)}}),Dm=z({notEqual_:function(A,g){var B,Q=J(A,"a","notEqual"),w=J(g,"b","notEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.notEqual(Q,w)},{a:Q,b:w},null,"NotEqual")}}),rm=z({notEqualStrict_:function(A,g){var B=J(A,"a","notEqualStrict"),Q=J(g,"b","notEqualStrict");return eB(B.shape,Q.shape,"Error in notEqualStrict: "),B.notEqual(Q)}});function rD(A,g){for(var B=[],Q=A;Q<g;++Q)B.push(Q);return B}function FD(A){for(var g=[],B=0;B<A.length;++B)for(var Q=0;Q<A[B].length;++Q)g.push(A[B][Q]);return g}var Gt=z({gather_:function(A,g,B){B===void 0&&(B=0);var Q=J(A,"x","gather"),w=J(g,"indices","gather","int32");B=TB(B,Q.shape)[0];var C=function(E,e,I){for(var o=E.shape[I],n=[],i=1,Y=1,M=0;M<I;M++)n.push(E.shape[M]),i*=E.shape[M];for(M=0;M<e.rank;M++)n.push(e.shape[M]);for(M=I+1;M<E.rank;M++)n.push(E.shape[M]),Y*=E.shape[M];return{batchSize:i,sliceSize:Y,dimSize:o,outputShape:n}}(Q,w,B);return b.runKernelFunc(function(E,e){var I=E.gather(Q,w.flatten(),B);return e([w]),I},{x:Q,indices:w},function(E,e){var I=e[0];return{x:function(){var o=Q.shape,n=I.size,i=o.slice(0,B),Y=i.length,M=o.slice(B,o.length).slice(1),c=M.length,D=rD(0,Y),r=rD(Y+1,Y+1+c),F=FD([i,[n],M]),s=E.reshape(F),u=I.reshape([n]),a=FD([[Y],D,r]),U=s.transpose(a),G=aD(U,u,Q.shape[B]),d=qo(a);return G=G.transpose(d)},indices:function(){return I}}},"Gather",{axis:B}).reshape(C.outputShape)}}),aD=z({unsortedSegmentSum_:function(A,g,B){var Q=J(A,"x","unsortedSegmentSum"),w=J(g,"segmentIds","unsortedSegmentSum","int32");return R(JB(B),function(){return"numSegments must be of dtype int"}),b.runKernelFunc(function(C,E){var e=C.unsortedSegmentSum(Q,w,B);return E([w]),e},{$x:Q},function(C,E){var e=E[0];return{$x:function(){return function(I,o){for(var n=Ut(o,$A(o)),i=Gt(I,n),Y=DD(o,nA(0,"int32")),M=i.rank-Y.rank,c=0;c<M;++c)Y=Tg(Y,c+1);Y=ue(Y,zw(i.shape,"bool"));var D=$A(i);return Iw(Y,i,D)}(C,e)}}})}}),Fm=function(A,g,B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D;return UA(this,function(r){switch(r.label){case 0:for(Q=J(A,"tensor","boolMask"),w=J(g,"mask","boolMask","bool"),C=B??0,E=w.rank,e=Q.shape,R(E>0,function(){return"mask cannot be scalar"}),eB(e.slice(C,C+E),w.shape,"mask's shape must match the first K dimensions of tensor's shape,"),I=1,o=C;o<C+E;o++)I*=e[o];return n=e.slice(0,C).concat([I],e.slice(C+E)),i=Q.reshape(n),Y=w.reshape([-1]),[4,iD(Y)];case 1:return M=r.sent(),c=M.squeeze([1]),D=Gt(i,c,C),A!==Q&&Q.dispose(),g!==w&&w.dispose(),c.dispose(),i.dispose(),Y.dispose(),M.dispose(),[2,D]}})})};function sD(A,g,B,Q,w,C,E){C===void 0&&(C="NHWC"),R(A.length===g.rank,function(){return"Length of inShape ("+A.length+") and rank of dy ("+g.rank+") must match"});var e=A,I=g,o=!1;g.rank===3&&(o=!0,I=g.as4D(1,g.shape[0],g.shape[1],g.shape[2]),e=[1,A[0],A[1],A[2]]),R(e.length===4,function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+e.length+"."}),R(I.rank===4,function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+I.rank}),R(B.rank===4,function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+B.rank});var n=C==="NHWC"?e[3]:e[1],i=C==="NHWC"?I.shape[3]:I.shape[1];R(n===B.shape[2],function(){return"Error in conv2dDerInput: depth of input ("+n+") must match input depth for filter "+B.shape[2]+"."}),R(i===B.shape[3],function(){return"Error in conv2dDerInput: depth of output ("+i+") must match output depth for filter "+B.shape[3]+"."}),E!=null&&R(JB(w),function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+w+"."});var Y=Ct(C),M=Cw(e,B.shape,Q,1,w,E,!1,Y),c=b.runKernelFunc(function(D,r){var F=D.conv2dDerInput(I,B,M);return r([B,I]),F},{dy4D:I,filter:B},function(D,r){var F=r[0],s=r[1];return{dy4D:function(){return jg(D,F,Q,w,C,1,E)},filter:function(){return lt(D,s,F.shape,Q,w,C,E)}}});return o?c.as3D(c.shape[1],c.shape[2],c.shape[3]):c}function ht(A){var g=function(C){return typeof C=="number"?[C,C,C]:C.length===2?[C[0],C[1],1]:C}(A),B=g[0],Q=g[1],w=g[2];return B===1&&Q===1&&w===1}function uD(A,g,B,Q,w){R(A.length===g.rank,function(){return"Length of inShape ("+A.length+") and rank of dy ("+g.rank+") must match"});var C=A,E=g,e=!1;g.rank===4&&(e=!0,E=g.as5D(1,g.shape[0],g.shape[1],g.shape[2],g.shape[3]),C=[1,A[0],A[1],A[2],A[3]]);var I=C[4],o=E.shape[4];R(C.length===5,function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+C.length+"."}),R(E.rank===5,function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+E.rank}),R(B.rank===5,function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+B.rank}),R(I===B.shape[3],function(){return"Error in conv3dDerInput: depth of input ("+I+") must match input depth for filter "+B.shape[3]+"."}),R(o===B.shape[4],function(){return"Error in conv3dDerInput: depth of output ("+o+") must match output depth for filter "+B.shape[4]+"."});var n=ie(C,B.shape,Q,1,w),i=b.runKernelFunc(function(Y){return Y.conv3dDerInput(E,B,n)},{dy5D:E});return e?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}var am=z({conv1d_:function(A,g,B,Q,w,C,E){w===void 0&&(w="NWC"),C===void 0&&(C=1);var e=J(A,"x","conv1d"),I=J(g,"filter","conv1d"),o=e,n=!1;e.rank===2&&(n=!0,o=e.as3D(1,e.shape[0],e.shape[1])),R(o.rank===3,function(){return"Error in conv1d: input must be rank 3, but got rank "+o.rank+"."}),R(I.rank===3,function(){return"Error in conv1d: filter must be rank 3, but got rank "+I.rank+"."}),E!=null&&R(JB(Q),function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."}),R(o.shape[2]===I.shape[1],function(){return"Error in conv1d: depth of input ("+o.shape[2]+") must match input depth for filter "+I.shape[1]+"."}),R(rg(B,C),function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+B+" and dilation '"+C+"'"}),R(w==="NWC",function(){return"Error in conv1d: got dataFormat of "+w+" but only NWC is currently supported."});var i=I.as4D(1,I.shape[0],I.shape[1],I.shape[2]),Y=o.as4D(o.shape[0],1,o.shape[1],o.shape[2]),M=jg(Y,i,[1,B],Q,"NHWC",[1,C],E);return n?M.as2D(M.shape[2],M.shape[3]):M.as3D(M.shape[0],M.shape[2],M.shape[3])}}),jg=z({conv2d_:function(A,g,B,Q,w,C,E){w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]);var e=J(A,"x","conv2d"),I=J(g,"filter","conv2d"),o=e,n=!1;e.rank===3&&(n=!0,o=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),R(o.rank===4,function(){return"Error in conv2d: input must be rank 4, but got rank "+o.rank+"."}),R(I.rank===4,function(){return"Error in conv2d: filter must be rank 4, but got rank "+I.rank+"."}),E!=null&&R(JB(Q),function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."});var i=w==="NHWC"?o.shape[3]:o.shape[1];R(i===I.shape[2],function(){return"Error in conv2d: depth of input ("+i+") must match input depth for filter "+I.shape[2]+"."}),R(rg(B,C),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"});var Y=Ct(w),M=Cw(o.shape,I.shape,B,C,Q,E,!1,Y),c=[I,o],D=b.runKernelFunc(function(r,F){var s=r.conv2d(o,I,M);return F([I,o]),s},{x:o,filter:I},function(r,F){var s=F,u=s[0],a=s[1];return R(Lw(C),function(){return"Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+C+"'"}),{x:function(){return UD(a.shape,r,u,B,Q,w)},filter:function(){return lt(a,r,u.shape,B,Q,w)}}},"Conv2D",M,c);return n?D.as3D(D.shape[1],D.shape[2],D.shape[3]):D}}),sm=z({conv3d_:function(A,g,B,Q,w,C){w===void 0&&(w="NDHWC"),C===void 0&&(C=[1,1,1]);var E=J(A,"x","conv3d"),e=J(g,"filter","conv3d"),I=E,o=!1;E.rank===4&&(o=!0,I=E.as5D(1,E.shape[0],E.shape[1],E.shape[2],E.shape[3])),R(I.rank===5,function(){return"Error in conv3d: input must be rank 5, but got rank "+I.rank+"."}),R(e.rank===5,function(){return"Error in conv3d: filter must be rank 5, but got rank "+e.rank+"."}),R(I.shape[4]===e.shape[3],function(){return"Error in conv3d: depth of input ("+I.shape[4]+") must match input depth for filter "+e.shape[3]+"."}),R(function(Y,M){return ht(Y)||ht(M)}(B,C),function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"}),R(w==="NDHWC",function(){return"Error in conv3d: got dataFormat of "+w+" but only NDHWC is currently supported."});var n=ie(I.shape,e.shape,B,C,Q),i=b.runKernelFunc(function(Y,M){var c=Y.conv3d(I,e,n);return M([I,e]),c},{x:I,$filter:e},function(Y,M){R(ht(C),function(){return"Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+C+"'"});var c=M[0],D=M[1];return{x:function(){return uD(c.shape,Y,D,B,Q)},$filter:function(){return function(r,F,s,u,a){var U=r;r.rank===4&&(U=r.as5D(1,r.shape[0],r.shape[1],r.shape[2],r.shape[3]));var G=F;G.rank===4&&(G=F.as5D(1,F.shape[0],F.shape[1],F.shape[2],F.shape[3])),R(U.rank===5,function(){return"Error in conv3dDerFilter: input must be rank 5, but got shape "+U.shape+"."}),R(G.rank===5,function(){return"Error in conv3dDerFilter: dy must be rank 5, but got shape "+G.shape+"."}),R(s.length===5,function(){return"Error in conv3dDerFilter: filterShape must be length 5, but got "+s+"."}),R(U.shape[4]===s[3],function(){return"Error in conv3dDerFilter: depth of input "+U.shape[4]+") must match input depth in filter ("+s[3]+"."}),R(G.shape[4]===s[4],function(){return"Error in conv3dDerFilter: depth of dy ("+G.shape[4]+") must match output depth for filter ("+s[4]+")."});var d=ie(U.shape,s,u,1,a);return b.runKernelFunc(function(H){return H.conv3dDerFilter(U,G,d)},{x5D:U,dy5D:G})}(c,Y,D.shape,B,Q)}}});return o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),lt=z({conv2dDerFilter_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NHWC");var e=A;A.rank===3&&(e=A.as4D(1,A.shape[0],A.shape[1],A.shape[2]));var I=g;I.rank===3&&(I=g.as4D(1,g.shape[0],g.shape[1],g.shape[2])),R(e.rank===4,function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+e.shape+"."}),R(I.rank===4,function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+I.shape+"."}),R(B.length===4,function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+B+"."});var o=C==="NHWC"?e.shape[3]:e.shape[1],n=C==="NHWC"?I.shape[3]:I.shape[1];R(o===B[2],function(){return"Error in conv2dDerFilter: depth of input "+o+") must match input depth in filter ("+B[2]+"."}),R(n===B[3],function(){return"Error in conv2dDerFilter: depth of dy ("+n+") must match output depth for filter ("+B[3]+")."}),E!=null&&R(JB(w),function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+w+"."});var i=Ct(C),Y=Cw(e.shape,B,Q,1,w,E,!1,i);return b.runKernelFunc(function(M){return M.conv2dDerFilter(e,I,Y)},{x4D:e,dy4D:I})}}),UD=z({conv2dDerInput_:sD}),Ge=z({depthwiseConv2d_:function(A,g,B,Q,w,C,E){C===void 0&&(C=[1,1]);var e=J(A,"x","depthwiseConv2d"),I=J(g,"filter","depthwiseConv2d"),o=e,n=!1;e.rank===3&&(n=!0,o=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),R(o.rank===4,function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+o.rank+"."}),R(I.rank===4,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+I.rank+"."}),R(o.shape[3]===I.shape[2],function(){return"Error in depthwiseConv2d: number of input channels ("+o.shape[3]+") must match the inChannels dimension in filter "+I.shape[2]+"."}),C==null&&(C=[1,1]),R(rg(B,C),function(){return"Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"}),E!=null&&R(JB(Q),function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."});var i=Cw(o.shape,I.shape,B,C,Q,E,!0),Y=[o,I],M=b.runKernelFunc(function(c,D){var r=c.depthwiseConv2D(o,I,i);return D([o,I]),r},{x:o,filter:I},function(c,D){R(Lw(C),function(){return"Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+C+"'"});var r=D[0],F=D[1];return{x:function(){return GD(r.shape,c,F,i)},filter:function(){return hD(r,c,F.shape,i)}}},"DepthwiseConv2dNative",i,Y);return n?M.as3D(M.shape[1],M.shape[2],M.shape[3]):M}}),GD=z({depthwiseConv2dDerInput_:function(A,g,B,Q){var w=g,C=!1;g.rank===3&&(C=!0,w=g.as4D(1,g.shape[0],g.shape[1],g.shape[2]));var E=b.runKernelFunc(function(e){return e.depthwiseConv2DDerInput(w,B,Q)},{dy4D:w});return C?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),hD=z({depthwiseConv2dDerFilter_:function(A,g,B,Q){var w=A;A.rank===3&&(w=A.as4D(1,A.shape[0],A.shape[1],A.shape[2]));var C=g;return C.rank===3&&(C=g.as4D(1,g.shape[0],g.shape[1],g.shape[2])),b.runKernelFunc(function(E){return E.depthwiseConv2DDerFilter(w,C,Q)},{x4D:w,dy4D:C})}}),dt=z({separableConv2d_:function(A,g,B,Q,w,C,E){C===void 0&&(C=[1,1]),E===void 0&&(E="NHWC");var e=J(A,"x","separableConv2d"),I=J(g,"depthwiseFilter","separableConv2d"),o=J(B,"pointwiseFilter","separableConv2d"),n=e,i=!1;if(e.rank===3&&(i=!0,n=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),E==="NCHW")throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");R(n.rank===4,function(){return"Error in separableConv2d: input must be rank 4, but got rank "+n.rank+"."}),R(I.rank===4,function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+I.rank+"."}),R(o.rank===4,function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+I.rank+"."}),R(o.shape[0]===1,function(){return"Error in separableConv2d: the first dimension of pointwise filter must be 1, but got "+o.shape[0]+"."}),R(o.shape[1]===1,function(){return"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+o.shape[1]+"."});var Y=I.shape[2],M=I.shape[3];R(o.shape[2]===Y*M,function(){return"Error in separableConv2d: the third dimension of pointwise filter must be "+Y*M+", but got "+o.shape[2]+"."});var c=Ge(n,I,Q,w,E,C),D=jg(c,o,1,"valid",E);return i?D.as3D(D.shape[1],D.shape[2],D.shape[3]):D}}),um=z({conv2dTranspose_:function(A,g,B,Q,w,C){return sD(B,J(A,"x","conv2dTranspose"),J(g,"filter","conv2dTranspose"),Q,w,"NHWC",C)}}),Um=z({conv3dTranspose_:function(A,g,B,Q,w){return uD(B,J(A,"x","conv3dTranspose"),J(g,"filter","conv3dTranspose"),Q,w)}}),he=z({matMul_:function(A,g,B,Q){var w;B===void 0&&(B=!1),Q===void 0&&(Q=!1);var C=J(A,"a","matMul"),E=J(g,"b","matMul");w=UB(C,E),C=w[0],E=w[1];var e=B?C.shape[C.rank-2]:C.shape[C.rank-1],I=Q?E.shape[E.rank-1]:E.shape[E.rank-2],o=B?C.shape[C.rank-1]:C.shape[C.rank-2],n=Q?E.shape[E.rank-2]:E.shape[E.rank-1],i=C.shape.slice(0,-2),Y=E.shape.slice(0,-2),M=hA(i),c=hA(Y);R(C.rank>=2&&E.rank>=2&&C.rank===E.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+C.rank+" and "+E.rank+"."}),R(KB(i,Y),function(){return"Error in matMul: outer dimensions ("+i+") and ("+Y+") of Tensors with shapes "+C.shape+" and "+E.shape+" must match."}),R(e===I,function(){return"Error in matMul: inner shapes ("+e+") and ("+I+") of Tensors with shapes "+C.shape+" and "+E.shape+" and transposeA="+B+" and transposeB="+Q+" must match."});var D=C.shape.slice(0,-2).concat([o,n]),r=B?C.as3D(M,e,o):C.as3D(M,o,e),F=Q?E.as3D(c,n,I):E.as3D(c,I,n),s={transposeA:B,transposeB:Q};return b.runKernelFunc(function(u,a){var U=u.batchMatMul(r,F,B,Q);return a([r,F]),U},{a:r,b:F},function(u,a){var U=a,G=U[0],d=U[1];return B||Q?!B&&Q?{a:function(){return u.matMul(d,!1,!1)},b:function(){return u.matMul(G,!0,!1)}}:B&&!Q?{a:function(){return d.matMul(u,!1,!0)},b:function(){return G.matMul(u,!1,!1)}}:{a:function(){return d.matMul(u,!0,!0)},b:function(){return u.matMul(G,!0,!0)}}:{a:function(){return u.matMul(d,!1,!0)},b:function(){return G.matMul(u,!0,!1)}}},"BatchMatMul",s).reshape(D)}}),Gm=z({dot_:function(A,g){var B=J(A,"t1","dot"),Q=J(g,"t2","dot");R(!(B.rank!==1&&B.rank!==2||Q.rank!==1&&Q.rank!==2),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+B.rank+" and "+Q.rank+"."});var w=B.rank===1?B.size:B.shape[1],C=Q.rank===1?Q.size:Q.shape[0];return R(w===C,function(){return"Error in dot: inner dimensions of inputs must match, but got "+w+" and "+C+"."}),B.rank===1&&Q.rank===1?B.as2D(1,-1).matMul(Q.as2D(-1,1)).asScalar():B.rank===1&&Q.rank===2?B.as2D(1,-1).matMul(Q.as2D(Q.shape[0],Q.shape[1])).as1D():B.rank===2&&Q.rank===1?B.matMul(Q.as2D(-1,1)).as1D():B.matMul(Q.as2D(Q.shape[0],Q.shape[1]))}}),hm=z({outerProduct_:function(A,g){var B=J(A,"v1","outerProduct"),Q=J(g,"v2","outerProduct");return R(B.rank===1&&Q.rank===1,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+B.rank+" and "+Q.rank+"."}),B.as2D(-1,1).matMul(Q.as2D(1,-1))}}),SC=z({reverse_:function(A,g){var B=J(A,"x","reverse");if(B.rank===0)return B.clone();var Q=TB(g,B.shape);return b.runKernelFunc(function(w){return w.reverse(B,Q)},{$x:B},function(w){return{$x:function(){return w.reverse(Q)}}}).reshapeAs(B)}}),lm=z({reverse1d_:function(A){var g=J(A,"x","reverse");return R(g.rank===1,function(){return"Error in reverse1D: x must be rank 1 but got rank "+g.rank+"."}),SC(g,0)}}),dm=z({reverse2d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===2,function(){return"Error in reverse2D: x must be rank 2 but got rank "+B.rank+"."}),SC(B,g)}}),Hm=z({reverse3d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===3,function(){return"Error in reverse3D: x must be rank 3 but got rank "+B.rank+"."}),SC(B,g)}}),fm=z({reverse4d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===4,function(){return"Error in reverse4D: x must be rank 4 but got rank "+B.rank+"."}),SC(B,g)}});function lD(A,g,B,Q,w,C){var E=J(A,"x","maxPool"),e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(e.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+e.rank+"."}),R(rg(B,Q),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+Q+"'"}),C!=null&&R(JB(w),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+C+" but got pad "+w+"."});var o=TC(e.shape,g,B,Q,w,C);if(o.filterWidth===1&&o.filterHeight===1&&KB(o.inShape,o.outShape))return E.clone();var n=[e],i=b.runKernelFunc(function(Y,M){var c=Y.maxPool(e,o);return M([e,c]),c},{x:e},function(Y,M){var c=M[0],D=M[1];return{x:function(){return function(r,F,s,u,a,U,G,d){var H=J(r,"dy","maxPoolBackprop"),h=J(F,"input","maxPoolBackprop"),l=J(s,"output","maxPoolBackprop");R(h.rank===H.rank,function(){return"Rank of input ("+h.rank+") does not match rank of dy ("+H.rank+")"}),R(rg(a,U),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+U+"'"}),R(H.rank===4,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+H.rank+"."}),R(h.rank===4,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+h.rank+"."});var m=TC(h.shape,u,a,U,G,d);return b.runKernelFunc(function(f){return f.maxPoolBackprop(H,h,l,m)},{$dy:H,$input:h})}(Y,c,D,g,B,Q,w)}}},"MaxPool",o,n);return I?i.as3D(i.shape[1],i.shape[2],i.shape[3]):i}function dD(A,g,B,Q,w,C){var E=J(A,"x","avgPool","float32");R(rg(B,Q),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+Q+"'"});var e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(e.rank===4,function(){return"Error in avgPool: x must be rank 4 but got rank "+e.rank+"."}),C!=null&&R(JB(w),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+C+" but got pad "+w+"."});var o=TC(e.shape,g,B,Q,w,C);if(o.filterWidth===1&&o.filterHeight===1&&KB(o.inShape,o.outShape))return E.clone();var n=b.runKernelFunc(function(i){return i.avgPool(e,o)},{x:e},function(i){return{x:function(){return function(Y,M,c,D,r,F){var s=J(Y,"dy","avgPoolBackprop"),u=J(M,"input","avgPoolBackprop");R(u.rank===s.rank,function(){return"Rank of input ("+u.rank+") does not match rank of dy ("+s.rank+")"}),R(rg(D,r),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+D+" and dilations '"+r+"'"});var a=u,U=s,G=!1;u.rank===3&&(G=!0,a=u.as4D(1,u.shape[0],u.shape[1],u.shape[2]),U=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),R(U.rank===4,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+U.rank+"."}),R(a.rank===4,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+a.rank+"."});var d=TC(a.shape,c,D,r,F),H=b.runKernelFunc(function(h){return h.avgPoolBackprop(U,a,d)},{dy4D:U,input4D:a});return G?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}(i,e,g,B,Q,w)}}},"AvgPool",o);return n=n.cast(E.dtype),I?n.as3D(n.shape[1],n.shape[2],n.shape[3]):n}var VB=z({maxPool_:function(A,g,B,Q,w){return lD(A,g,B,1,Q,w)}}),LC=z({avgPool_:function(A,g,B,Q,w){return dD(A,g,B,1,Q,w)}}),Jm=z({pool_:function(A,g,B,Q,w,C){w==null&&(w=[1,1]),C==null&&(C=1),Q===0&&(Q="valid");var E=J(A,"x","maxPool"),e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(rg(C,w),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+C+" and dilations '"+w+"'"});var o,n=TC(e.shape,g,C,w,Q),i=[n.dilationHeight,n.dilationWidth];o=Q==="same"?function(a,U){var G=a.map(function(h,l){return h+(h-1)*(U[l]-1)}).map(function(h){return h-1}),d=G.map(function(h){return Math.floor(h/2)}),H=G.map(function(h,l){return h-d[l]});return G.map(function(h,l){return[d[l],H[l]]})}([n.filterHeight,n.filterWidth],i):[[0,0],[0,0]];var Y=i[0]===1&&i[1]===1,M=function(a,U,G){var d=G.map(function(N){return N[0]}),H=G.map(function(N){return N[1]}),h=a.concat(d,H),l=U.map(function(N,v){return(N-h[v]%N)%N}),m=H.map(function(N,v){return N+l[v]}),f=U.map(function(N,v){return[d[v],m[v]]}),W=U.map(function(N,v){return[0,l[v]]});return[f,W]}([n.inHeight,n.inWidth],i,o),c=M[0],D=M[1],r=Y?Q:"valid",F=Y?e:tc(e,i,c),s=(B==="avg"?function(){return dD(F,g,C,1,r)}:function(){return lD(F,g,C,1,r)})(),u=Y?s:ec(s,i,D);return I?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Nm=z({maxPool3d_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NDHWC");var e=J(A,"x","maxPool3d"),I=e,o=!1;e.rank===4&&(o=!0,I=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),E==null&&(E=[1,1,1]),R(I.rank===5,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+I.rank+"."}),R(C==="NDHWC",function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+C}),R(rg(B,E),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+E+"'"}),w!=null&&R(JB(Q),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+w+" but got pad "+Q+"."});var n=ne(I.shape,g,B,E,Q,w,C),i=b.runKernelFunc(function(Y,M){var c=Y.maxPool3d(I,n);return M([I,c]),c},{x:I},function(Y,M){var c=M[0],D=M[1];return{x:function(){return function(r,F,s,u,a,U,G,d){var H=J(r,"dy","maxPool3dBackprop"),h=J(F,"input","maxPool3dBackprop"),l=J(s,"output","maxPool3dBackprop"),m=H,f=h,W=l,N=!1;h.rank===4&&(N=!0,m=H.as5D(1,H.shape[0],H.shape[1],H.shape[2],H.shape[3]),f=h.as5D(1,h.shape[0],h.shape[1],h.shape[2],h.shape[3]),W=l.as5D(1,l.shape[0],l.shape[1],l.shape[2],l.shape[3])),R(m.rank===5,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+m.rank+"."}),R(f.rank===5,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+f.rank+"."}),R(W.rank===5,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+W.rank+"."}),U==null&&(U=[1,1,1]),R(rg(a,U),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+U+"'"}),d!=null&&R(JB(G),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+d+" but got pad "+G+"."});var v=ne(f.shape,u,a,U,G,d),y=b.runKernelFunc(function(k){return k.maxPool3dBackprop(m,f,W,v)},{dy5D:m,input5D:f});return N?y.as4D(y.shape[1],y.shape[2],y.shape[3],y.shape[4]):y}(Y,c,D,g,B,E,Q,w)}}});return o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),mm=z({avgPool3d_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NDHWC");var e=J(A,"x","avgPool3d","float32"),I=e,o=!1;e.rank===4&&(o=!0,I=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),E==null&&(E=[1,1,1]),R(I.rank===5,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+I.rank+"."}),R(C==="NDHWC",function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+C}),R(rg(B,E),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+E+"'"}),w!=null&&R(JB(Q),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+w+" but got pad "+Q+"."});var n=ne(I.shape,g,B,E,Q,w,C),i=b.runKernelFunc(function(Y){return Y.avgPool3d(I,n)},{x:I},function(Y){return{x:function(){return function(M,c,D,r,F,s,u){var a=J(M,"dy","avgPool3dBackprop"),U=J(c,"input","avgPool3dBackprop"),G=a,d=U,H=!1;U.rank===4&&(H=!0,G=a.as5D(1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]),d=U.as5D(1,U.shape[0],U.shape[1],U.shape[2],U.shape[3])),R(G.rank===5,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+G.rank+"."}),R(d.rank===5,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+d.rank+"."}),F==null&&(F=[1,1,1]),R(rg(r,F),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+F+"'"}),u!=null&&R(JB(s),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+s+"."});var h=ne(d.shape,D,r,F,s,u),l=b.runKernelFunc(function(m){return m.avgPool3dBackprop(G,d,h)},{dy5D:G,input5D:d});return H?l.as4D(l.shape[1],l.shape[2],l.shape[3],l.shape[4]):l}(Y,I,g,B,E,Q,w)}}});return i=i.cast(I.dtype),o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),QQ=z({slice_:function(A,g,B){var Q,w,C=J(A,"x","slice");if(C.rank===0)throw new Error("Slicing scalar is not possible");(Q=typeof g=="number"?[g].concat(new Array(C.rank-1).fill(0)):g.length<C.rank?g.concat(new Array(C.rank-g.length).fill(0)):g.slice()).forEach(function(I){R(I!==-1,function(){return"slice() does not support negative begin indexing."})}),w=(w=B==null?new Array(C.rank).fill(-1):typeof B=="number"?[B].concat(new Array(C.rank-1).fill(-1)):B.length<C.rank?B.concat(new Array(C.rank-B.length).fill(-1)):B).map(function(I,o){return I>=0?I:(R(I===-1,function(){return"Negative size values should be exactly -1 but got "+I+" for the slice() size at index "+o+"."}),C.shape[o]-Q[o])}),wf(C,Q,w);var E=C.shape,e={begin:Q,size:w};return b.runKernelFunc(function(I){return I.slice(C,Q,w)},{x:C},function(I){for(var o=[],n=0;n<I.rank;n++)o.push([Q[n],E[n]-Q[n]-w[n]]);return{x:function(){return I.pad(o)}}},"Slice",e)}}),Rm=z({slice1d_:function(A,g,B){var Q=J(A,"x","slice1d");return R(Q.rank===1,function(){return"slice1d expects a rank-1 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,[g],[B])}}),Pm=z({slice2d_:function(A,g,B){var Q=J(A,"x","slice2d");return R(Q.rank===2,function(){return"slice2d expects a rank-2 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}}),HD=z({slice3d_:function(A,g,B){var Q=J(A,"x","slice3d");return R(Q.rank===3,function(){return"slice3d expects a rank-3 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}}),vm=z({slice4d_:function(A,g,B){var Q=J(A,"x","slice4d");return R(Q.rank===4,function(){return"slice4d expects a rank-4 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}});function fD(A,g,B,Q,w){return g.rank<B.rank&&(g=g.reshape(cg(g.shape,Q))),A.rank<B.rank&&(A=A.reshape(cg(A.shape,Q))),{x:function(){var C=A.mul(B.equal(g).cast(A.dtype));return w==null?C:C.transpose(w)}}}var km=z({all_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","all","bool"),w=TB(g,Q.shape),C=w,E=$g(C,Q.rank);E!=null&&(Q=Q.transpose(E),C=AQ(C.length,Q.rank));var e=b.runKernelFunc(function(o){return o.all(Q,C)},{$x:Q});if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),Tm=z({any_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","any","bool"),w=TB(g,Q.shape),C=w,E=$g(C,Q.rank);E!=null&&(Q=Q.transpose(E),C=AQ(C.length,Q.rank));var e=b.runKernelFunc(function(o){return o.any(Q,C)},{$x:Q});if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),jm=z({argMax_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","argMax");g==null&&(g=0);var Q=TB(g,B.shape),w=$g(Q,B.rank);w!=null&&(B=B.transpose(w),Q=AQ(Q.length,B.rank));var C={axis:Q[0]},E=[B];return b.runKernelFunc(function(e,I){var o=e.argMax(B,Q[0]);return I([B]),o},{x:B},function(e,I){var o=I[0];return{x:function(){return $A(o)}}},"ArgMax",C,E)}}),pm=z({argMin_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","argMin");g==null&&(g=0);var Q=TB(g,B.shape),w=$g(Q,B.rank);return w!=null&&(B=B.transpose(w),Q=AQ(Q.length,B.rank)),b.runKernelFunc(function(C,E){var e=C.argMin(B,Q[0]);return E([B]),e},{$x:B},function(C,E){var e=E[0];return{$x:function(){return $A(e)}}})}}),ym=z({logSumExp_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","logSumExp"),w=TB(g,Q.shape),C=Q.max(w,!0),E=Q.sub(C).exp().sum(w).log(),e=C.reshape(E.shape).add(E);if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),le=z({max_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","max"),w=Q,C=TB(g,Q.shape),E=C,e=$g(E,Q.rank);e!=null&&(Q=Q.transpose(e),E=AQ(E.length,Q.rank));var I=[Q],o=b.runKernelFunc(function(i,Y){var M=i.max(Q,E);return Y([w,M]),M},{x:Q},function(i,Y){return fD(i,Y[1],Y[0],C,e)},"Max",{axes:E},I,[!0]);if(B){var n=cg(o.shape,C);o=o.reshape(n)}return o}}),zm=z({mean_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","mean"),w=TB(g,Q.shape),C=hA(gg(Q.shape,w)[1]);return te(function(E){var e=nA(C);return{value:(e.dtype===E.dtype?E:E.cast(e.dtype)).div(e).sum(g,B),gradFunc:function(I){var o=E.shape.slice();return w.forEach(function(n){o[n]=1}),I.reshape(o).mul(zw(E.shape,"float32")).div(C)}}})(Q)}}),Wm=z({min_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","min"),w=Q,C=TB(g,Q.shape),E=C,e=$g(E,Q.rank);e!=null&&(Q=Q.transpose(e),E=AQ(E.length,Q.rank));var I=[Q],o=b.runKernelFunc(function(i,Y){var M=i.min(Q,E);return Y([w,M]),M},{x:Q},function(i,Y){return fD(i,Y[1],Y[0],C,e)},"Min",{axes:E},I,[!0]);if(B){var n=cg(o.shape,C);o=o.reshape(n)}return o}}),Sm=z({moments_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=TB(g,(A=J(A,"x","moments")).shape),w=A.mean(Q,B),C=w.shape;B||(C=cg(w.shape,Q));var E=A.toFloat().sub(w.reshape(C)).square();return{mean:w,variance:E.mean(Q,B)}}}),JD=z({sum_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","sum");Q.dtype==="bool"&&(Q=Q.toInt());var w=TB(g,Q.shape);return te(function(C){var E=$g(w,C.rank),e=w,I=C;E!=null&&(I=C.transpose(E),e=AQ(e.length,C.rank));var o=function(M){var c=C.shape.slice();return w.forEach(function(D){c[D]=1}),M.reshape(c).mul(zw(C.shape,"float32"))},n={axes:e},i=b.runKernelFunc(function(M){return M.sum(I,e)},{x:I},function(M){return{x:function(){return o(M)}}},"Sum",n);if(B){var Y=cg(i.shape,w);i=i.reshape(Y)}return{value:i,gradFunc:o}})(Q)}}),Lm=z({prod_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","prod");Q.dtype==="bool"&&(Q=Q.toInt());var w=TB(g,Q.shape),C=$g(w,Q.rank),E=w,e=Q;C!=null&&(e=Q.transpose(C),E=AQ(E.length,Q.rank));var I=b.runKernelFunc(function(n){return n.prod(e,E)},{permutedX:e});if(B){var o=cg(I.shape,w);I=I.reshape(o)}return I}}),ND=z({elu_:function(A){var g=J(A,"x","elu");return b.runKernelFunc(function(B,Q){var w=B.elu(g);return Q([w]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return b.runKernelFunc(function(C){return C.eluDer(B,w)},{dy:B,y:w})}}})}}),bm=z({leakyRelu_:function(A,g){g===void 0&&(g=.2);var B=J(A,"x","leakyRelu");return Ut(nA(g).mul(B),B)}}),mD=z({prelu_:function(A,g){var B=J(A,"x","prelu"),Q=J(g,"alpha","prelu");return b.runKernelFunc(function(w,C){var E=w.prelu(B,Q);return C([B,Q]),E},{x:B,alpha:Q},function(w,C){var E=C[0],e=C[1],I=E.greater(0);return{x:function(){return Iw(I,w,w.mul(e))},alpha:function(){var o=Iw(I,$A(w),w.mul(E)),n=yB(e.shape,w.shape);return n.length>0&&(o=o.sum(n)),o.reshape(e.shape)}}},"Prelu")}}),GB=z({relu_:function(A){var g=J(A,"x","relu");return g.dtype==="bool"?g.toInt():b.runKernelFunc(function(B,Q){var w=B.relu(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mulStrict(w.step().toFloat())}}},"Relu")}}),RD=z({relu6_:function(A){var g=J(A,"x","relu6");return g.dtype==="bool"?g.toInt():b.runKernelFunc(function(B,Q){var w=B.relu6(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0],C=w.lessEqual(6).mul(w.step());return{x:function(){return B.mulStrict(C.toFloat())}}},"Relu6")}}),Km=z({selu_:function(A){var g=J(A,"x","selu");return b.runKernelFunc(function(B,Q){var w=B.selu(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){var C=w.greater(nA(0)),E=nA(Ft),e=nA(at),I=B.mul(e),o=B.mul(E).mul(w.toFloat().exp());return Iw(C,I,o)}}})}}),vQ=z({transpose_:function(A,g){var B=J(A,"x","transpose");if(g==null&&(g=B.shape.map(function(w,C){return C}).reverse()),R(B.rank===g.length,function(){return"Error in transpose: rank of input "+B.rank+" must match length of perm "+g+"."}),g.forEach(function(w){R(w>=0&&w<B.rank,function(){return"All entries in 'perm' must be between 0 and "+(B.rank-1)+" but got "+g})}),B.rank<=1)return B.clone();var Q={perm:g};return b.runKernelFunc(function(w){return w.transpose(B,g)},{x:B},function(w){var C=qo(g);return{x:function(){return w.transpose(C)}}},"Transpose",Q)}}),Vm=z({localResponseNormalization_:function(A,g,B,Q,w){g===void 0&&(g=5),B===void 0&&(B=1),Q===void 0&&(Q=1),w===void 0&&(w=.5);var C=J(A,"x","localResponseNormalization");R(C.rank===4||C.rank===3,function(){return`Error in localResponseNormalization: x must be rank 3 or 4 but got
3761
- rank `+C.rank+"."}),R(JB(g),function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+g+"."});var E=C,e=!1;C.rank===3&&(e=!0,E=C.as4D(1,C.shape[0],C.shape[1],C.shape[2]));var I=b.runKernelFunc(function(o,n){var i=o.localResponseNormalization4D(E,g,B,Q,w);return n([E,i]),i},{x4D:E},function(o,n){var i=n[0],Y=n[1];return{x4D:function(){return b.runKernelFunc(function(M){return M.LRNGrad(o,i,Y,g,B,Q,w)},{})}}});return e?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),PD=z({norm_:function(A,g,B,Q){g===void 0&&(g="euclidean"),B===void 0&&(B=null),Q===void 0&&(Q=!1);var w=function e(I,o,n){if(n===void 0&&(n=null),I.rank===0)return I.abs();if(I.rank!==1&&n===null)return e(I.reshape([-1]),o,n);if(I.rank===1||typeof n=="number"||Array.isArray(n)&&n.length===1){if(o===1)return I.abs().sum(n);if(o===1/0)return I.abs().max(n);if(o===-1/0)return I.abs().min(n);if(o==="euclidean"||o===2)return I.abs().pow(nA(2,"int32")).sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+o)}if(Array.isArray(n)&&n.length===2){if(o===1)return I.abs().sum(n[0]).max(n[1]-1);if(o===1/0)return I.abs().sum(n[1]).max(n[0]);if(o===-1/0)return I.abs().sum(n[1]).min(n[0]);if(o==="fro"||o==="euclidean")return I.square().sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+o)}throw new Error("Error in norm: invalid axis: "+n)}(A=J(A,"x","norm"),g,B),C=w.shape;if(Q){var E=TB(B,A.shape);C=cg(w.shape,E)}return w.reshape(C)}}),xm=z({basicLSTMCell_:function(A,g,B,Q,w,C){var E=J(A,"forgetBias","basicLSTMCell"),e=J(g,"lstmKernel","basicLSTMCell"),I=J(B,"lstmBias","basicLSTMCell"),o=J(Q,"data","basicLSTMCell"),n=J(w,"c","basicLSTMCell"),i=J(C,"h","basicLSTMCell"),Y=o.concat(i,1).matMul(e).add(I),M=Y.shape[0],c=Y.shape[1]/4,D=[M,c],r=Y.slice([0,0],D),F=Y.slice([0,c],D),s=Y.slice([0,2*c],D),u=Y.slice([0,3*c],D),a=r.sigmoid().mulStrict(F.tanh()).addStrict(n.mulStrict(E.add(s).sigmoid())),U=a.tanh().mulStrict(u.sigmoid());return[a,U]}}),Xm=z({multiRNNCell_:function(A,g,B,Q){for(var w=J(g,"data","multiRNNCell"),C=Qe(B,"c","multiRNNCell"),E=Qe(Q,"h","multiRNNCell"),e=w,I=[],o=0;o<A.length;o++){var n=A[o](e,C[o],E[o]);I.push(n[0]),I.push(n[1]),e=n[1]}var i=[],Y=[];for(o=0;o<I.length;o+=2)i.push(I[o]),Y.push(I[o+1]);return[i,Y]}}),Om=z({movingAverage_:function(A,g,B,Q,w){w===void 0&&(w=!0);var C=J(A,"v","movingAverage"),E=J(g,"x","movingAverage"),e=J(B,"decay","movingAverage");Kd(C,E),R(KB(C.shape,E.shape),function(){return"Shape mismatch in v and x"});var I=nA(1),o=I.sub(e),n=E.sub(C).mul(o);if(w){R(Q!=null,function(){return"When using zeroDebias: true, step is required."});var i=J(Q,"step","movingAverage");n=n.div(I.sub(Ue(e,i)))}return C.add(n)}}),Zm=z({stridedSlice_:function(A,g,B,Q,w,C,E,e,I){if(w===void 0&&(w=0),C===void 0&&(C=0),E===void 0&&(E=0),e===void 0&&(e=0),I===void 0&&(I=0),Q==null&&(Q=new Array(g.length)),E!==0)throw new Error("ellipsis mask is not yet supported");var o=J(A,"x","stridedSlice"),n=Dc(e),i=o.shape.slice();n.forEach(function(r){g[r]=0,B[r]=1,i.splice(r,0,1)}),o=o.reshape(i);for(var Y=0;Y<o.rank;Y++)g[Y]=Cf(w,g,Q,o.shape,Y),B[Y]=Ef(C,B,Q,o.shape,Y),Q[Y]=Q[Y]||1;var M=Dc(I);M.forEach(function(r){B[r]=g[r]+1,Q[r]=1});var c=Qt(g,B,Q),D=c.filter(function(r,F){return M.indexOf(F)===-1});return Q.every(function(r){return r===1})?QQ(o,g,c).reshape(D):b.runKernelFunc(function(r){return r.stridedSlice(o,g,B,Q)},{$x:o}).reshape(D)}}),qm=z({topk_:function(A,g,B){g===void 0&&(g=1),B===void 0&&(B=!0);var Q=J(A,"x","topk");if(Q.rank===0)throw new Error("topk() expects the input to be of rank 1 or higher");var w=Q.shape[Q.shape.length-1];if(g>w)throw new Error("'k' passed to topk() must be <= the last dimension ("+w+") but got "+g);var C=b.runKernelFunc(function(E){return E.topk(Q,g,B)},{$x:Q});return{values:C[0],indices:C[1]}}}),_m=z({scatterND_:function(A,g,B){var Q=J(A,"indices","scatterND","int32"),w=J(g,"updates","scatterND");return Qf(w,Q,B),b.runKernelFunc(function(C){return C.scatterND(Q,w,B)},{indices:Q,updates:w},null,"ScatterNd",{shape:B})}}),Ht=z({fft_:function(A){R(A.dtype==="complex64",function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+A.dtype+"."});var g=A.shape[A.shape.length-1],B=A.size/g,Q=A.as2D(B,g);return b.runKernelFunc(function(w){return w.fft(Q)},{input:A}).reshape(A.shape)}}),de=z({ifft_:function(A){R(A.dtype==="complex64",function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+A.dtype+"."});var g=A.shape[A.shape.length-1],B=A.size/g,Q=A.as2D(B,g);return b.runKernelFunc(function(w){return w.ifft(Q)},{input:A}).reshape(A.shape)}}),ft=z({rfft_:function(A,g){R(A.dtype==="float32",function(){return"The dtype for rfft() must be real value but got "+A.dtype});var B,Q=A.shape[A.shape.length-1],w=A.size/Q;if(g!=null&&g<Q){var C=A.shape.map(function(F){return 0}),E=A.shape.map(function(F){return F});E[A.shape.length-1]=g,B=A.slice(C,E),Q=g}else if(g!=null&&g>Q){var e=A.shape.map(function(F){return F});e[A.shape.length-1]=g-Q,B=A.concat(DB(e),A.shape.length-1),Q=g}else B=A;var I=B.zerosLike(),o=$B(B,I).as2D(w,Q),n=Ht(o),i=Math.floor(Q/2)+1,Y=kg(n),M=BQ(n),c=Y.split([i,Q-i],Y.shape.length-1),D=M.split([i,Q-i],M.shape.length-1),r=B.shape.slice();return r[B.shape.length-1]=i,$B(c[0],D[0]).reshape(r)}}),vD=z({irfft_:function(A){var g=A.shape[A.shape.length-1],B=A.size/g;if(g<=2){var Q=A.as2D(B,g),w=de(Q);return kg(w)}var C=[B,2*(g-1)],E=kg(A).as2D(B,g),e=BQ(A).as2D(B,g),I=E.slice([0,1],[B,g-2]).reverse(1),o=e.slice([0,1],[B,g-2]).reverse(1).mul(nA(-1)),n=E.concat(I,1),i=e.concat(o,1);return Q=$B(n,i).as2D(C[0],C[1]),w=de(Q),kg(w)}}),$m=Object.freeze({fft:Ht,ifft:de,rfft:ft,irfft:vD}),A0=z({sparseToDense_:function(A,g,B,Q){Q===void 0&&(Q=0);var w=J(A,"sparseIndices","sparseToDense","int32"),C=J(g,"sparseValues","sparseToDense"),E=J(Q,"defaultValue","sparseToDense",C.dtype);return function(e,I,o,n){if(e.dtype!=="int32")throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+e.dtype+".");if(e.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+e.shape+".");var i=e.rank>0?e.shape[0]:1,Y=e.rank>1?e.shape[1]:1;if(o.length!==Y)throw new Error("outputShape has incorrect number of elements:, "+o.length+", should be: "+Y+".");var M=I.size;if(I.rank!==0&&(I.rank!==1||M!==i))throw new Error("sparseValues has incorrect shape "+I.shape+", should be [] or ["+i+"]");if(I.dtype!==n.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(w,C,B,E),b.runKernelFunc(function(e){return e.sparseToDense(w,C,B,E)},{$sparseIndices:w,$sparseValues:C,$defaultValue:E})}}),B0=z({gatherND_:function(A,g){var B=J(g,"indices","gatherND","int32"),Q=J(A,"x","gatherND");return b.runKernelFunc(function(w){return w.gatherND(Q,B)},{x:Q,indices:B},null,"GatherNd")}}),g0=z({diag_:function(A){var g=J(A,"x","diag").flatten(),B=A.shape.concat(A.shape);return b.runKernelFunc(function(Q){return Q.diag(g)},{$x:g}).reshape(B)}}),Q0=z({dropout_:function(A,g,B,Q){var w=J(A,"x","dropout");if(R(w.dtype==="float32",function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+w.dtype+" tensor instead."}),R(g>=0&&g<1,function(){return"rate must be a float in the range [0, 1), but got "+g+"."}),g===0)return A instanceof uB?w.clone():w;var C=function(I,o){if(o==null)return I.shape.slice();if(KB(I.shape,o))return o;if(I.shape.length===o.length){for(var n=[],i=0;i<I.shape.length;i++)o[i]==null&&I.shape[i]!=null?n.push(I.shape[i]):n.push(o[i]);return n}return o}(w,B),E=1-g,e=oc(C,0,1,"float32",Q).add(E).floor().div(E);return w.mul(e)}});function kD(A,g,B){for(var Q=1-A%2,w=new Float32Array(A),C=0;C<A;++C){var E=2*Math.PI*C/(A+Q-1);w[C]=g-B*Math.cos(E)}return PB(w,"float32")}var Jt=z({hannWindow_:function(A){return kD(A,.5,.5)}}),TD=z({hammingWindow_:function(A){return kD(A,.54,.46)}}),Nt=z({frame_:function(A,g,B,Q,w){Q===void 0&&(Q=!1),w===void 0&&(w=0);for(var C=0,E=[];C+g<=A.size;)E.push(QQ(A,C,g)),C+=B;if(Q)for(;C<A.size;){var e=C+g-A.size,I=jB([QQ(A,C,g-e),gQ([e],w)]);E.push(I),C+=B}return E.length===0?RQ([],[0,g]):jB(E).as2D(E.length,g)}}),jD=z({stft_:function(A,g,B,Q,w){var C;w===void 0&&(w=Jt),Q==null&&(C=g,Q=Math.floor(Math.pow(2,Math.ceil(Math.log(C)/Math.log(2)))));for(var E=Nt(A,g,B),e=wg(E,w(g)),I=[],o=0;o<E.shape[0];o++)I.push(ft(e.slice([o,0],[1,g]),Q));return jB(I)}}),w0=Object.freeze({hannWindow:Jt,hammingWindow:TD,frame:Nt,stft:jD}),Cg,C0=function(A,g,B){return B===void 0&&(B=1),uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D,r;return UA(this,function(F){switch(F.label){case 0:return Q=J(A,"predictions","inTopK"),w=J(g,"targets","inTopK"),R(Q.rank>1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+Q.rank}),R(Q.rank-1===w.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+Q.rank+" and targets rank "+w.rank}),eB(Q.shape.slice(0,Q.shape.length-1),w.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),C=Q.shape[Q.shape.length-1],R(B>0&&B<=C,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+C+"), but got "+B}),[4,Q.data()];case 1:return E=F.sent(),[4,w.data()];case 2:for(e=F.sent(),I=[E.length/C,C],n=I[1],i=dC("bool",o=I[0]),Y=0;Y<o;Y++){for(M=Y*n,c=E.subarray(M,M+n),D=[],r=0;r<c.length;r++)D.push({value:c[r],index:r});for(D.sort(function(s,u){return u.value-s.value}),i[Y]=0,r=0;r<B;r++)if(D[r].index===e[Y]){i[Y]=1;break}}return A!==Q&&Q.dispose(),g!==w&&w.dispose(),[2,Ag(i,w.shape,"bool")]}})})};(function(A){A[A.NONE=0]="NONE",A[A.MEAN=1]="MEAN",A[A.SUM=2]="SUM",A[A.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"})(Cg||(Cg={}));var E0=z({absoluteDifference_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","absoluteDifference"),C=J(g,"predictions","absoluteDifference"),E=null;B!=null&&(E=J(B,"weights","absoluteDifference")),eB(w.shape,C.shape,"Error in absoluteDifference: ");var e=w.sub(C).abs();return aQ(e,E,Q)}}),aQ=z({computeWeightedLoss_:function(A,g,B){B===void 0&&(B=Cg.SUM_BY_NONZERO_WEIGHTS);var Q=J(A,"losses","computeWeightedLoss"),w=null;g!=null&&(w=J(g,"weights","computeWeightedLoss"));var C=w==null?Q:Q.mul(w);if(B===Cg.NONE)return C;if(B===Cg.SUM)return C.sum();if(B===Cg.MEAN){if(w==null)return C.mean();var E=Q.size/w.size,e=C.sum().div(w.sum());return E>1?e.div(nA(E)):e}if(B===Cg.SUM_BY_NONZERO_WEIGHTS){if(w==null)return C.sum().div(nA(Q.size));var I=w.mul(zw(Q.shape)).notEqual(nA(0)).sum().toFloat();return C.sum().div(I)}throw Error("Unknown reduction: "+B)}}),e0=z({cosineDistance_:function(A,g,B,Q,w){w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","cosineDistance"),E=J(g,"predictions","cosineDistance"),e=null;Q!=null&&(e=J(Q,"weights","cosineDistance")),eB(C.shape,E.shape,"Error in cosineDistance: ");var I=nA(1).sub(C.mul(E).sum(B,!0));return aQ(I,e,w)}}),I0=z({hingeLoss_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","hingeLoss"),C=J(g,"predictions","hingeLoss"),E=null;B!=null&&(E=J(B,"weights","hingeLoss")),eB(w.shape,C.shape,"Error in hingeLoss: ");var e=nA(1);w=nA(2).mul(w).sub(e);var I=e.sub(w.mul(C)).relu();return aQ(I,E,Q)}}),o0=z({huberLoss_:function(A,g,B,Q,w){Q===void 0&&(Q=1),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","huberLoss"),E=J(g,"predictions","huberLoss"),e=null;B!=null&&(e=J(B,"weights","huberLoss")),eB(C.shape,E.shape,"Error in huberLoss: ");var I=nA(Q),o=E.sub(C).abs(),n=MD(o,I),i=o.sub(n),Y=nA(.5).mul(n.square()).add(I.mul(i));return aQ(Y,e,w)}}),t0=z({logLoss_:function(A,g,B,Q,w){Q===void 0&&(Q=1e-7),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","logLoss"),E=J(g,"predictions","logLoss"),e=null;B!=null&&(e=J(B,"weights","logLoss")),eB(C.shape,E.shape,"Error in logLoss: ");var I=nA(1),o=nA(Q),n=C.mul(E.add(o).log()).neg().sub(I.sub(C).mul(I.sub(E).add(o).log()));return aQ(n,e,w)}}),n0=z({meanSquaredError_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","meanSquaredError"),C=J(g,"predictions","meanSquaredError"),E=null;B!=null&&(E=J(B,"weights","meanSquaredError")),eB(w.shape,C.shape,"Error in meanSquaredError: ");var e=w.squaredDifference(C);return aQ(e,E,Q)}}),i0=z({sigmoidCrossEntropy_:function(A,g,B,Q,w){Q===void 0&&(Q=0),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"multiClassLabels","sigmoidCrossEntropy"),E=J(g,"logits","sigmoidCrossEntropy"),e=null;if(B!=null&&(e=J(B,"weights","sigmoidCrossEntropy")),eB(C.shape,E.shape,"Error in sigmoidCrossEntropy: "),Q>0){var I=nA(Q),o=nA(1),n=nA(.5);C=C.mul(o.sub(I)).add(n.mul(I))}var i=function(Y,M){var c=J(Y,"labels","sigmoidCrossEntropyWithLogits"),D=J(M,"logits","sigmoidCrossEntropyWithLogits");eB(c.shape,D.shape,"Error in sigmoidCrossEntropyWithLogits: ");var r=D.relu(),F=D.mul(c),s=D.abs().neg().exp().log1p();return r.sub(F).add(s)}(C,E);return aQ(i,e,w)}}),Y0=z({softmaxCrossEntropy_:function(A,g,B,Q,w){Q===void 0&&(Q=0),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"onehotLabels","softmaxCrossEntropy"),E=J(g,"logits","softmaxCrossEntropy"),e=null;if(B!=null&&(e=J(B,"weights","softmaxCrossEntropy")),eB(C.shape,E.shape,"Error in softmaxCrossEntropy: "),Q>0){var I=nA(Q),o=nA(1),n=nA(C.shape[1]);C=C.mul(o.sub(I)).add(I.div(n))}var i=function(Y,M,c){if(c===void 0&&(c=-1),c===-1&&(c=M.rank-1),c!==M.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+M.rank+" and dim was "+c);return te(function(D,r,F){var s=r.logSumExp([c],!0),u=r.toFloat().sub(s);return F([D,u]),{value:u.mul(D).neg().sum([c]),gradFunc:function(a,U){var G=U[0],d=U[1],H=cg(a.shape,[c]);return[a.reshape(H).mul(G.toFloat().sub(d.exp())),a.reshape(H).mul(d.exp().sub(G.toFloat()))]}}})(Y,M)}(C,E);return aQ(i,e,w)}}),M0=Object.freeze({get Reduction(){return Cg},absoluteDifference:E0,computeWeightedLoss:aQ,cosineDistance:e0,hingeLoss:I0,huberLoss:o0,logLoss:t0,meanSquaredError:n0,sigmoidCrossEntropy:i0,softmaxCrossEntropy:Y0});function pD(A,g){return g===void 0&&(g=!1),b.tidy(function(){if(A.shape.length!==2)throw new Error("qr2d() requires a 2D Tensor, but got a "+A.shape.length+"D Tensor.");for(var B=A.shape[0],Q=A.shape[1],w=Ic(B),C=A.clone(),E=RQ([[1]],[1,1]),e=E.clone(),I=B>=Q?Q:B,o=function(i){var Y,M=C,c=e,D=w;Y=b.tidy(function(){var r=C.slice([i,i],[B-i,1]),F=r.norm(),s=C.slice([i,i],[1,1]),u=RQ([[-1]]).where(s.greater(0),RQ([[1]])),a=s.sub(u.mul(F)),U=r.div(a);e=U.shape[0]===1?E.clone():E.concat(U.slice([1,0],[U.shape[0]-1,U.shape[1]]),0);var G=u.matMul(a).div(F).neg(),d=C.slice([i,0],[B-i,Q]),H=G.mul(e);if(i===0)C=d.sub(H.matMul(e.transpose().matMul(d)));else{var h=d.sub(H.matMul(e.transpose().matMul(d)));C=C.slice([0,0],[i,Q]).concat(h,0)}var l=w.slice([0,i],[B,w.shape[1]-i]);if(i===0)w=l.sub(l.matMul(e).matMul(H.transpose()));else{var m=l.sub(l.matMul(e).matMul(H.transpose()));w=w.slice([0,0],[B,i]).concat(m,1)}return[e,C,w]}),e=Y[0],C=Y[1],w=Y[2],Mg([M,c,D])},n=0;n<I;++n)o(n);return!g&&B>Q&&(w=w.slice([0,0],[B,Q]),C=C.slice([0,0],[Q,Q])),[w,C]})}var c0=z({bandPart_:function(A,g,B){if(g%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+g+".");if(B%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+B+".");var Q=J(A,"a","bandPart");if(Q.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+Q.rank+".");var w=Q.shape,C=Q.shape.slice(-2),E=C[0],e=C[1];if(!(g<=E))throw new Error("bandPart(): numLower ("+g+") must not be greater than the number of rows ("+E+").");if(!(B<=e))throw new Error("bandPart(): numUpper ("+B+") must not be greater than the number of columns ("+e+").");g<0&&(g=E),B<0&&(B=e);var I=we(0,E,1,"int32").reshape([-1,1]),o=we(0,e,1,"int32"),n=zB(I,o),i=ue(n.lessEqual(nA(+g,"int32")),n.greaterEqual(nA(-B,"int32"))),Y=DB([E,e],Q.dtype);return Hg(pB(Q.reshape([-1,E,e])).map(function(M){return Iw(i,M,Y)})).reshape(w)}}),D0=z({gramSchmidt_:function(A){var g;if(Array.isArray(A)){g=!1,R(A!=null&&A.length>0,function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"});for(var B=A[0].shape[0],Q=function(I){R(A[I].shape[0]===B,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+A[I].shape[0]+" vs. "+B+")"})},w=1;w<A.length;++w)Q(w)}else g=!0,A=$o(A,A.shape[0],0).map(function(I){return nc(I,[0])});R(A.length<=A[0].shape[0],function(){return"Gram-Schmidt: Number of vectors ("+A.length+") exceeds number of dimensions ("+A[0].shape[0]+")."});var C=[],E=A,e=function(I){C.push(b.tidy(function(){var o=E[I];if(I>0)for(var n=0;n<I;++n){var i=JD(C[n].mulStrict(o)).mul(C[n]);o=o.sub(i)}return o.div(PD(o,"euclidean"))}))};for(w=0;w<A.length;++w)e(w);return g?Hg(C,0):C}}),r0=z({qr_:function(A,g){if(g===void 0&&(g=!1),A.rank<2)throw new Error("qr() requires input tensor to have a rank >= 2, but got rank "+A.rank);if(A.rank===2)return pD(A,g);var B=A.shape.slice(0,A.shape.length-2).reduce(function(E,e){return E*e}),Q=pB(A.reshape([B,A.shape[A.shape.length-2],A.shape[A.shape.length-1]]),0),w=[],C=[];return Q.forEach(function(E){var e=pD(E,g),I=e[0],o=e[1];w.push(I),C.push(o)}),[Hg(w,0).reshape(A.shape),Hg(C,0).reshape(A.shape)]}}),F0=Object.freeze({bandPart:c0,gramSchmidt:D0,qr:r0});function He(A,g,B,Q,w,C){Q==null&&(Q=.5),w==null&&(w=Number.NEGATIVE_INFINITY),C==null&&(C=0);var E=A.shape[0];return B=Math.min(B,E),R(0<=Q&&Q<=1,function(){return"iouThreshold must be in [0, 1], but was '"+Q+"'"}),R(A.rank===2,function(){return"boxes must be a 2D tensor, but was of rank '"+A.rank+"'"}),R(A.shape[1]===4,function(){return"boxes must have 4 columns, but 2nd dimension was "+A.shape[1]}),R(g.rank===1,function(){return"scores must be a 1D tensor"}),R(g.shape[0]===E,function(){return"scores has incompatible shape with boxes. Expected "+E+", but was "+g.shape[0]}),R(0<=C&&C<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+C+"'"}),{maxOutputSize:B,iouThreshold:Q,scoreThreshold:w,softNmsSigma:C}}var a0=z({resizeBilinear_:function(A,g,B){B===void 0&&(B=!1);var Q=J(A,"images","resizeBilinear");R(Q.rank===3||Q.rank===4,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+Q.rank+"."}),R(g.length===2,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+g+"."});var w=Q,C=!1;Q.rank===3&&(C=!0,w=Q.as4D(1,Q.shape[0],Q.shape[1],Q.shape[2]));var E=g[0],e=g[1],I=b.runKernelFunc(function(o,n){return n([w]),o.resizeBilinear(w,E,e,B)},{x:w},function(o,n){return{x:function(){return b.runKernelFunc(function(i){return i.resizeBilinearBackprop(o,n[0],B)},{})}}},"ResizeBilinear",{alignCorners:B,newHeight:E,newWidth:e});return C?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),s0=z({resizeNearestNeighbor_:function(A,g,B){B===void 0&&(B=!1);var Q=J(A,"images","resizeNearestNeighbor");R(Q.rank===3||Q.rank===4,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+Q.rank+"."}),R(g.length===2,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+g+"."}),R(Q.dtype==="float32"||Q.dtype==="int32",function(){return"`images` must have `int32` or `float32` as dtype"});var w=Q,C=!1;Q.rank===3&&(C=!0,w=Q.as4D(1,Q.shape[0],Q.shape[1],Q.shape[2]));var E=g[0],e=g[1],I=b.runKernelFunc(function(o,n){return n([w]),o.resizeNearestNeighbor(w,E,e,B)},{batchImages:w},function(o,n){return{batchImages:function(){return b.runKernelFunc(function(i){return i.resizeNearestNeighborBackprop(o,n[0],B)},{})}}});return C?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),u0=z({nonMaxSuppression_:function(A,g,B,Q,w){Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY);var C=J(A,"boxes","nonMaxSuppression"),E=J(g,"scores","nonMaxSuppression"),e=He(C,E,B,Q,w);B=e.maxOutputSize,Q=e.iouThreshold,w=e.scoreThreshold;var I={maxOutputSize:B,iouThreshold:Q,scoreThreshold:w};return b.runKernelFunc(function(o){return o.nonMaxSuppression(C,E,B,Q,w)},{boxes:C,scores:E},null,"NonMaxSuppressionV3",I)}}),U0=function(A,g,B,Q,w){return Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),uA(this,void 0,void 0,function(){var C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return C=J(A,"boxes","nonMaxSuppressionAsync"),E=J(g,"scores","nonMaxSuppressionAsync"),e=He(C,E,B,Q,w),B=e.maxOutputSize,Q=e.iouThreshold,w=e.scoreThreshold,[4,Promise.all([C.data(),E.data()])];case 1:return I=Y.sent(),o=I[0],n=I[1],i=It(o,n,B,Q,w),C!==A&&C.dispose(),E!==g&&E.dispose(),[2,i]}})})},G0=z({nonMaxSuppressionWithScore_:function(A,g,B,Q,w,C){Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),C===void 0&&(C=0);var E=J(A,"boxes","nonMaxSuppression"),e=J(g,"scores","nonMaxSuppression"),I=He(E,e,B,Q,w,C),o={maxOutputSize:B=I.maxOutputSize,iouThreshold:Q=I.iouThreshold,scoreThreshold:w=I.scoreThreshold,softNmsSigma:C=I.softNmsSigma},n=b.runKernel("NonMaxSuppressionV5",{boxes:E,scores:e},o);return{selectedIndices:n[0],selectedScores:n[1]}}}),h0=function(A,g,B,Q,w,C){return Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),C===void 0&&(C=0),uA(this,void 0,void 0,function(){var E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:return E=J(A,"boxes","nonMaxSuppressionAsync"),e=J(g,"scores","nonMaxSuppressionAsync"),I=He(E,e,B,Q,w,C),B=I.maxOutputSize,Q=I.iouThreshold,w=I.scoreThreshold,C=I.softNmsSigma,[4,Promise.all([E.data(),e.data()])];case 1:return o=M.sent(),n=o[0],i=o[1],Y=ot(n,i,B,Q,w,C),E!==A&&E.dispose(),e!==g&&e.dispose(),[2,Y]}})})},l0=z({cropAndResize_:function(A,g,B,Q,w,C){var E=J(A,"image","cropAndResize"),e=J(g,"boxes","cropAndResize","float32"),I=J(B,"boxInd","cropAndResize","int32");w=w||"bilinear",C=C||0;var o=e.shape[0];return R(E.rank===4,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+E.rank+"."}),R(e.rank===2&&e.shape[1]===4,function(){return"Error in cropAndResize: boxes must be have size ["+o+",4] but had shape "+e.shape+"."}),R(I.rank===1&&I.shape[0]===o,function(){return"Error in cropAndResize: boxInd must be have size ["+o+"] but had shape "+e.shape+"."}),R(Q.length===2,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+Q.length+"."}),R(Q[0]>=1&&Q[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+Q}),R(w==="bilinear"||w==="nearest",function(){return"method must be bilinear or nearest, but was "+w}),b.runKernelFunc(function(n,i){return n.cropAndResize(E,e,I,Q,w,C)},{images:E,boxes:e,boxInd:I},null,"CropAndResize",{method:w,extrapolationValue:C,cropSize:Q})}}),mt=Object.freeze({resizeBilinear:a0,resizeNearestNeighbor:s0,nonMaxSuppression:u0,nonMaxSuppressionAsync:U0,nonMaxSuppressionWithScore:G0,nonMaxSuppressionWithScoreAsync:h0,cropAndResize:l0}),Rt=function(A,g){return!(A>0)||g==="linear"},Pt=function(A,g,B){if(B==null||B==="linear")return A;if(B==="relu")return A.mul(g.step());throw new Error("Gradient for activation "+B+" has not been implemented yet.")},vt=function(A,g){var B=g,Q=yB(A.shape,g.shape);return Q.length>0&&(B=B.sum(Q)),B.reshape(A.shape)},kt=function(A,g,B){if(g==="linear")return A;if(g==="relu")return GB(A);if(g==="elu")return ND(A);if(g==="relu6")return RD(A);if(g==="prelu")return mD(A,B);throw new Error("Unknown fused activation "+g+".")},d0=z({fusedMatMul_:function(A){var g,B=A.a,Q=A.b,w=A.transposeA,C=w!==void 0&&w,E=A.transposeB,e=E!==void 0&&E,I=A.bias,o=A.activation,n=o===void 0?"linear":o,i=A.preluActivationWeights;if(Rt(b.state.gradientDepth,n)===!1){var Y=he(B,Q,C,e);return I!=null&&(Y=OA(Y,I)),kt(Y,n,i)}var M=J(B,"a","fused matMul"),c=J(Q,"b","fused matMul");g=UB(M,c),M=g[0],c=g[1];var D=C?M.shape[M.rank-2]:M.shape[M.rank-1],r=e?c.shape[c.rank-1]:c.shape[c.rank-2],F=C?M.shape[M.rank-1]:M.shape[M.rank-2],s=e?c.shape[c.rank-2]:c.shape[c.rank-1],u=M.shape.slice(0,-2),a=c.shape.slice(0,-2),U=hA(u),G=hA(a);R(M.rank>=2&&c.rank>=2&&M.rank===c.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+M.rank+" and "+c.rank+"."}),R(KB(u,a),function(){return"Error in fused matMul: outer dimensions ("+u+") and ("+a+") of Tensors with shapes "+M.shape+" and "+c.shape+" must match."}),R(D===r,function(){return"Error in fused matMul: inner shapes ("+D+") and ("+r+") of Tensors with shapes "+M.shape+" and "+c.shape+" and transposeA="+C+" and transposeB="+e+" must match."});var d,H,h=M.shape.slice(0,-2).concat([F,s]),l=C?M.as3D(U,D,F):M.as3D(U,F,D),m=e?c.as3D(G,s,r):c.as3D(G,r,s);I!=null&&qA(h,(d=UB(d=J(I,"bias","fused matMul"),M)[0]).shape),i!=null&&(H=J(i,"prelu weights","fused matMul"));var f={a:l,b:m};I!=null&&(f.bias=d),i!=null&&(f.preluActivationWeights=H);var W=[l,m];return b.runKernelFunc(function(N,v){var y=N.fusedBatchMatMul({a:l,b:m,transposeA:C,transposeB:e,bias:d,activation:n,preluActivationWeights:H});return v([l,m,y]),y},f,function(N,v){var y=v[0],k=v[1],p=v[2],K=Pt(N,p,n),V={};return I!=null&&(V={bias:function(){return vt(d,K)}}),Object.assign(C||e?!C&&e?{a:function(){return K.matMul(k,!1,!1)},b:function(){return K.matMul(y,!0,!1)}}:C&&!e?{a:function(){return k.matMul(K,!1,!0)},b:function(){return y.matMul(K,!1,!1)}}:{a:function(){return k.matMul(K,!0,!0)},b:function(){return K.matMul(y,!0,!0)}}:{a:function(){return K.matMul(k,!1,!0)},b:function(){return y.matMul(K,!0,!1)}},V)},"_FusedMatMul",{transposeA:C,transposeB:e,activation:n},W,[!0]).reshape(h)}}),H0=z({fusedConv2d_:function(A){var g=A.x,B=A.filter,Q=A.strides,w=A.pad,C=A.dataFormat,E=C===void 0?"NHWC":C,e=A.dilations,I=e===void 0?[1,1]:e,o=A.dimRoundingMode,n=A.bias,i=A.activation,Y=i===void 0?"linear":i,M=A.preluActivationWeights;if(Y=Y||"linear",Rt(b.state.gradientDepth,Y)===!1){var c=jg(g,B,Q,w,E,I,o);return n!=null&&(c=OA(c,n)),kt(c,Y,M)}var D=J(g,"x","conv2d"),r=J(B,"filter","conv2d"),F=D,s=!1;D.rank===3&&(s=!0,F=D.as4D(1,D.shape[0],D.shape[1],D.shape[2])),R(F.rank===4,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+F.rank+"."}),R(r.rank===4,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+r.rank+"."}),o!=null&&R(JB(w),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+w+"."}),R(F.shape[3]===r.shape[2],function(){return"Error in conv2d: depth of input ("+F.shape[3]+") must match input depth for filter "+r.shape[2]+"."}),R(rg(Q,I),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+Q+" and dilations '"+I+"'"}),R(E==="NHWC",function(){return"Error in conv2d: got dataFormat of "+E+" but only NHWC is currently supported."});var u,a,U=Cw(F.shape,r.shape,Q,I,w,o);n!=null&&(u=UB(u=J(n,"bias","fused conv2d"),D)[0],qA(U.outShape,u.shape)),M!=null&&(a=J(M,"prelu weights","fused conv2d"));var G={x:F,filter:r};n!=null&&(G.bias=u),M!=null&&(G.preluActivationWeights=a);var d=[r,F],H=b.runKernelFunc(function(h,l){var m=h.fusedConv2d({input:F,filter:r,convInfo:U,bias:u,activation:Y,preluActivationWeights:a});return l([r,F,m]),m},G,function(h,l){var m=l,f=m[0],W=m[1],N=m[2],v=Pt(h,N,Y);R(Lw(I),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+I+"'"});var y={};return n!=null&&(y={bias:function(){return vt(u,v)}}),Object.assign({x:function(){return UD(W.shape,v,f,Q,w)},filter:function(){return lt(W,v,f.shape,Q,w)}},y)},"FusedConv2D",{convInfo:U,activation:Y},d,[!0]);return s?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}}),f0=z({fusedDepthwiseConv2d_:function(A){var g=A.x,B=A.filter,Q=A.strides,w=A.pad,C=A.dataFormat,E=C===void 0?"NHWC":C,e=A.dilations,I=e===void 0?[1,1]:e,o=A.dimRoundingMode,n=A.bias,i=A.activation,Y=i===void 0?"linear":i,M=A.preluActivationWeights;if(Rt(b.state.gradientDepth,Y)===!1){var c=Ge(g,B,Q,w,E,I,o);return n!=null&&(c=OA(c,n)),kt(c,Y,M)}var D=J(g,"x","depthwiseConv2d"),r=J(B,"filter","depthwiseConv2d"),F=D,s=!1;D.rank===3&&(s=!0,F=D.as4D(1,D.shape[0],D.shape[1],D.shape[2])),R(F.rank===4,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+F.rank+"."}),R(r.rank===4,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+r.rank+"."}),R(F.shape[3]===r.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+F.shape[3]+") must match the inChannels dimension in filter "+r.shape[2]+"."}),I==null&&(I=[1,1]),R(rg(Q,I),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+Q+" and dilations '"+I+"'"}),o!=null&&R(JB(w),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+o+" but got pad "+w+"."});var u,a,U=Cw(F.shape,r.shape,Q,I,w,o,!0);n!=null&&(u=UB(u=J(n,"bias","fused conv2d"),D)[0],qA(U.outShape,u.shape)),M!=null&&(a=J(M,"prelu weights","fused depthwiseConv2d"));var G={x:F,filter:r};n!=null&&(G.bias=u),M!=null&&(G.preluActivationWeights=a);var d=[r,F],H=b.runKernelFunc(function(h,l){var m=h.fusedDepthwiseConv2D({input:F,filter:r,convInfo:U,bias:u,activation:Y,preluActivationWeights:a});return l([r,F,m]),m},G,function(h,l){R(Lw(I),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+I+"'"});var m=l[0],f=l[1],W=l[2],N=Pt(h,W,Y),v={};return n!=null&&(v={bias:function(){return vt(u,N)}}),Object.assign({x:function(){return GD(f.shape,N,m,U)},filter:function(){return hD(f,N,m.shape,U)}},v)},"FusedDepthwiseConv2D",{convInfo:U,activation:Y},d,[!0]);return s?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}}),J0=Object.freeze({matMul:d0,conv2d:H0,depthwiseConv2d:f0}),N0=Object.freeze({image:mt,linalg:F0,losses:M0,spectral:$m,fused:J0,signal:w0,square:tN,squaredDifference:wD,conv1d:am,conv2d:jg,conv3d:sm,depthwiseConv2d:Ge,separableConv2d:dt,conv2dTranspose:um,conv3dTranspose:Um,op:z,batchNormalization2d:zN,batchNormalization3d:WN,batchNormalization4d:SN,batchNormalization:LN,batchNorm:tD,batchNorm2d:bN,batchNorm3d:KN,batchNorm4d:VN,booleanMaskAsync:Fm,complex:$B,real:kg,imag:BQ,concat:jB,concat1d:fH,concat2d:JH,concat3d:NH,concat4d:mH,split:$o,matMul:he,dot:Gm,outerProduct:hm,reverse:SC,reverse1d:lm,reverse2d:dm,reverse3d:Hm,reverse4d:fm,maxPool:VB,avgPool:LC,pool:Jm,maxPool3d:Nm,avgPool3d:mm,slice:QQ,slice1d:Rm,slice2d:Pm,slice3d:HD,slice4d:vm,abs:nN,acos:iN,acosh:YN,asin:MN,asinh:cN,atan:DN,atanh:rN,ceil:FN,clipByValue:st,cos:aN,cosh:sN,erf:uN,exp:ut,expm1:UN,floor:GN,log:hN,log1p:lN,logSigmoid:dN,neg:Fe,reciprocal:HN,round:fN,rsqrt:CD,sigmoid:ED,sign:JN,isNaN:NN,isInf:mN,isFinite:RN,sin:PN,sinh:vN,softplus:kN,sqrt:TN,step:jN,tan:pN,tanh:yN,all:km,any:Tm,argMax:jm,argMin:pm,logSumExp:ym,max:le,mean:zm,min:Wm,moments:Sm,sum:JD,prod:Lm,equal:cD,equalStrict:Im,greater:om,greaterEqual:DD,greaterEqualStrict:tm,greaterStrict:nm,less:im,lessEqual:Ym,lessEqualStrict:Mm,lessStrict:cm,notEqual:Dm,notEqualStrict:rm,add:OA,addN:ON,addStrict:ZN,atan2:qN,div:bg,divNoNan:_N,divStrict:$N,floorDiv:YD,maximum:Ut,maximumStrict:Am,minimum:MD,minimumStrict:Bm,mod:gm,modStrict:Qm,mul:wg,mulStrict:wm,pow:Ue,powStrict:Cm,squaredDifferenceStrict:Em,sub:zB,subStrict:em,elu:ND,leakyRelu:bm,prelu:mD,relu:GB,relu6:RD,selu:Km,logicalAnd:ue,logicalNot:xN,logicalOr:nD,logicalXor:XN,where:Iw,whereAsync:iD,buffer:zA,print:zH,batchToSpaceND:ec,broadcastTo:WH,cast:SH,clone:LH,cumsum:bH,depthToSpace:KH,expandDims:Tg,eye:Ic,multinomial:VH,oneHot:Bt,pad:ww,pad1d:xH,pad2d:XH,pad3d:OH,pad4d:ZH,rand:qH,randomNormal:_H,randomGamma:$H,randomUniform:oc,reshape:Sg,spaceToBatchND:tc,squeeze:nc,stack:Hg,tile:Ww,truncatedNormal:Af,unstack:pB,setdiff1dAsync:Bf,fill:gQ,linspace:HH,ones:zw,range:we,scalar:nA,tensor:Ag,tensor1d:PB,tensor2d:RQ,tensor3d:_o,tensor4d:Dg,tensor5d:hH,tensor6d:lH,variable:dH,zeros:DB,onesLike:Ec,zerosLike:$A,transpose:vQ,softmax:rQ,logSoftmax:If,localResponseNormalization:Vm,norm:PD,gather:Gt,unsortedSegmentSum:aD,basicLSTMCell:xm,multiRNNCell:Xm,movingAverage:Om,stridedSlice:Zm,topk:qm,scatterND:_m,fft:Ht,ifft:de,rfft:ft,irfft:vD,sparseToDense:A0,gatherND:B0,diag:g0,dropout:Q0,hannWindow:Jt,hammingWindow:TD,frame:Nt,stft:jD,inTopKAsync:C0});function EA(A,g){Array.isArray(A)||(A=[A]),A.forEach(function(B){B!=null&&R(B.dtype!=="complex64",function(){return g+" does not support complex64 tensors."})})}function Tt(A,g,B,Q){if(B==="linear")return A.linear(g);if(B==="relu")return A.relu(g);if(B==="elu")return A.elu(g);if(B==="relu6")return A.relu6(g);if(B==="prelu")return A.prelu(g,Q);throw new Error("Activation "+B+" has not been implemented for the CPU backend.")}var m0=function(A){function g(){var B=A.call(this)||this;return B.blockSize=48,B.firstUse=!0,B.data=new ac(B,b),B}return Wg(g,A),g.prototype.write=function(B,Q,w){this.firstUse&&(this.firstUse=!1,BA().get("IS_NODE")&&ge(`
3760
+ `}(Q));return this.compileAndRun(w,[B])},g.prototype.conv2dByMatMul=function(B,Q,w,C,E,e){var I=B.shape,o=this.texData.get(B.dataId),n=w.inChannels,i=I[0]*I[1]*I[2],Y=w.outChannels,M=w.dataFormat==="channelsLast",c=(i===1||Y===1)&&n>1e3,D=I[2]%2!=0&&!!o.isPacked;if(c||!BA().getBool("WEBGL_LAZILY_UNPACK")||!BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!D){var r=M?I[0]*I[1]*I[2]:I[0]*I[2]*I[3],F=this.reshape(B,[1,r,w.inChannels]),s=this.reshape(Q,[1,w.inChannels,w.outChannels]);return this.reshape(this.fusedBatchMatMul({a:F,b:s,transposeA:!1,transposeB:!1,bias:C,activation:E,preluActivationWeights:e}),w.outShape)}var u=M?I[0]*I[1]*(I[2]+1):I[0]*I[2]*(I[3]+1),a={dataId:B.dataId,shape:[1,u,w.inChannels],dtype:B.dtype},U=o.shape;o.shape=o.shape.slice(),o.shape[o.shape.length-2]++,R(Be(o.shape,a.shape),function(){return"packed reshape "+o.shape+" to "+a.shape+" isn't free"});var G=this.reshape(Q,[1,w.inChannels,w.outChannels]),d=this.fusedBatchMatMul({a,b:G,transposeA:!1,transposeB:!1,bias:C,activation:E,preluActivationWeights:e}),H=this.texData.get(d.dataId);return R(H.isPacked,function(){return"batchMatMul result is expected to be packed"}),o.shape=U,H.shape=w.outShape,b.makeTensorFromDataId(d.dataId,w.outShape,d.dtype)},g.prototype.conv2dWithIm2Row=function(B,Q,w,C,E,e){var I=w.filterWidth,o=w.filterHeight,n=w.inChannels,i=w.outWidth,Y=w.outHeight,M=w.dataFormat==="channelsLast",c=I*o*n,D=Y*i,r=[c,D],F=B.squeeze([0]),s=Q.reshape([1,c,-1]),u=new GJ(r,F.shape,w),a=this.compileAndRun(u,[F]).reshape([1,r[0],r[1]]),U=C!=null,G=e!=null,d=E?re(E,!0):null,H=new ct(a.shape,[1,D,w.outChannels],!0,!1,U,d,G),h=[a,s];C&&h.push(C),G&&h.push(e);var l=this.compileAndRun(H,h);return M?l.reshape([1,Y,i,w.outChannels]):l.reshape([1,w.outChannels,Y,i])},g.prototype.fusedConv2d=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights;if(C.filterHeight===1&&C.filterWidth===1&&C.dilationHeight===1&&C.dilationWidth===1&&C.strideHeight===1&&C.strideWidth===1&&(C.padInfo.type==="SAME"||C.padInfo.type==="VALID"))return this.conv2dByMatMul(Q,w,C,E,e,I);if(BA().getBool("WEBGL_CONV_IM2COL")&&Q.shape[0]===1)return this.conv2dWithIm2Row(Q,w,C,E,e,I);var o=E!=null,n=I!=null,i=e?re(e,!1):null,Y=new jc(C,o,i,n),M=[Q,w];return E&&M.push(E),I&&M.push(I),this.compileAndRun(Y,M)},g.prototype.conv2d=function(B,Q,w){if(w.filterHeight===1&&w.filterWidth===1&&w.dilationHeight===1&&w.dilationWidth===1&&w.strideHeight===1&&w.strideWidth===1&&(w.padInfo.type==="SAME"||w.padInfo.type==="VALID"))return this.conv2dByMatMul(B,Q,w);if(BA().getBool("WEBGL_CONV_IM2COL")&&B.shape[0]===1)return this.conv2dWithIm2Row(B,Q,w);var C=new jc(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv2dDerInput=function(B,Q,w){var C=new yf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv2dDerFilter=function(B,Q,w){var C=new pf(w);return this.compileAndRun(C,[B,Q])},g.prototype.fusedDepthwiseConv2D=function(B){var Q,w=B.input,C=B.filter,E=B.convInfo,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=BA().getBool("WEBGL_PACK_DEPTHWISECONV")&&E.strideWidth<=2&&E.outChannels/E.inChannels==1,i=I?re(I,n):null,Y=[w,C],M=e!=null,c=o!=null;return M&&Y.push(e),c&&Y.push(o),n?(Q=new yc(E,M,i,c),this.compileAndRun(Q,Y)):(Q=new pc(E,M,i,c),this.compileAndRun(Q,Y))},g.prototype.depthwiseConv2D=function(B,Q,w){var C;return BA().getBool("WEBGL_PACK_DEPTHWISECONV")&&w.strideWidth<=2&&w.outChannels/w.inChannels==1?(C=new yc(w),this.compileAndRun(C,[B,Q])):(C=new pc(w),this.compileAndRun(C,[B,Q]))},g.prototype.depthwiseConv2DDerInput=function(B,Q,w){var C=new Lf(w);return this.compileAndRun(C,[B,Q])},g.prototype.depthwiseConv2DDerFilter=function(B,Q,w){var C=new Sf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3d=function(B,Q,w){var C=new bf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3dDerInput=function(B,Q,w){var C=new Wf(w);return this.compileAndRun(C,[B,Q])},g.prototype.conv3dDerFilter=function(B,Q,w){var C=new zf(w);return this.compileAndRun(C,[B,Q])},g.prototype.maxPool=function(B,Q){var w=new Dt(Q,"max",!1);return this.compileAndRun(w,[B])},g.prototype.avgPool=function(B,Q){var w=new Dt(Q,"avg",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.maxPoolBackprop=function(B,Q,w,C){var E=new Dt(C,"max",!0),e=this.compileAndRun(E,[Q]),I=new HJ(C),o=this.compileAndRun(I,[B,e],Q.dtype);return e.dispose(),o},g.prototype.avgPoolBackprop=function(B,Q,w){var C=new Hf(w);return this.compileAndRun(C,[B],Q.dtype)},g.prototype.cast=function(B,Q){return Uc(B,Q,this)},g.prototype.unstack=function(B,Q){for(var w=B.shape[Q],C=new Array(B.rank-1),E=0,e=0;e<B.rank;e++)e!==Q&&(C[E++]=B.shape[e]);var I=new Array(B.rank).fill(0),o=B.shape.slice();o[Q]=1;var n=new Array(w);for(e=0;e<n.length;e++)I[Q]=e,n[e]=this.slice(B,I,o).reshape(C);return n},g.prototype.avgPool3d=function(B,Q){var w=new rt(Q,"avg",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.avgPool3dBackprop=function(B,Q,w){var C=new ff(w);return this.compileAndRun(C,[B],Q.dtype)},g.prototype.maxPool3d=function(B,Q){var w=new rt(Q,"max",!1);return this.compileAndRun(w,[B],"float32")},g.prototype.maxPool3dBackprop=function(B,Q,w,C){var E=new rt(C,"max",!0),e=this.compileAndRun(E,[Q]),I=new fJ(C),o=this.compileAndRun(I,[B,e],Q.dtype);return e.dispose(),o},g.prototype.reshape=function(B,Q){var w=this.texData.get(B.dataId);if(w.isPacked&&!Be(B.shape,Q)&&(w.texture===null||!Be(w.shape,Q))){var C=this.packedReshape(B,Q);return b.makeTensorFromDataId(C.dataId,C.shape,C.dtype)}return et(B,Q)},g.prototype.resizeBilinear=function(B,Q,w,C){var E=BA().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new pJ(B.shape,Q,w,C):new jJ(B.shape,Q,w,C);return this.compileAndRun(E,[B],"float32")},g.prototype.resizeBilinearBackprop=function(B,Q,w){var C=new TJ(B,Q,w);return this.compileAndRun(C,[B])},g.prototype.resizeNearestNeighbor=function(B,Q,w,C){var E=new zJ(B.shape,Q,w,C);return this.compileAndRun(E,[B])},g.prototype.resizeNearestNeighborBackprop=function(B,Q,w){var C=new yJ(B,Q,w);return this.compileAndRun(C,[B])},g.prototype.multinomial=function(B,Q,w,C){var E=Q?B:rQ(B),e=E.shape[0],I=E.shape[1],o=new JJ(e,I,w),n=o.getCustomSetupFunc(C);return this.compileAndRun(o,[E],"int32",n)},g.prototype.oneHot=function(B,Q,w,C){var E=new NJ(B.size,Q,w,C);return this.compileAndRun(E,[B])},g.prototype.diag=function(B){var Q=new Zf(B.size);return this.compileAndRun(Q,[B])},g.prototype.nonMaxSuppression=function(B,Q,w,C,E){return ge("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"),ot(B.dataSync(),Q.dataSync(),w,C,E)},g.prototype.cropAndResize=function(B,Q,w,C,E,e){var I=new Kf(B.shape,Q.shape,C,E,e);return this.compileAndRun(I,[B,Q,w],"float32")},g.prototype.depthToSpace=function(B,Q,w){R(Q>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+Q});var C=B.shape[0],E=w==="NHWC"?B.shape[1]:B.shape[2],e=w==="NHWC"?B.shape[2]:B.shape[3],I=w==="NHWC"?B.shape[3]:B.shape[1],o=E*Q,n=e*Q,i=I/(Q*Q),Y=new Of(w==="NHWC"?[C,o,n,i]:[C,i,o,n],Q,w);return this.compileAndRun(Y,[B])},g.prototype.split=function(B,Q,w){return Hc(B,Q,w)},g.prototype.scatterND=function(B,Q,w){var C=oe(0,B,w),E=C.sliceRank,e=C.numUpdates,I=C.sliceSize,o=C.strides,n=C.outputSize,i=[n/I,I],Y=B.reshape([e,E]),M=Q.reshape([e,I]);if(n===0)return et(Ag([]),w);var c=nA(0),D=new Lc(e,E,Y.rank,M.rank,o,i);return this.compileAndRun(D,[M,Y,c]).reshape(w)},g.prototype.sparseToDense=function(B,Q,w,C){var E=oe(0,B,w),e=E.sliceRank,I=E.numUpdates,o=E.strides,n=E.outputSize,i=new Lc(I,e,B.rank,Q.rank,o,[n,1]);return this.compileAndRun(i,[Q,B,C]).reshape(w)},g.prototype.fft=function(B){return this.fftImpl(B,!1)},g.prototype.ifft=function(B){return this.fftImpl(B,!0)},g.prototype.fftImpl=function(B,Q){var w=this.texData.get(B.dataId),C=new Wc(BJ,B.shape,Q),E=new Wc(gJ,B.shape,Q),e=[this.makeComplexComponentTensorInfo(B,w.complexTensors.real),this.makeComplexComponentTensorInfo(B,w.complexTensors.imag)],I=this.compileAndRun(C,e),o=this.compileAndRun(E,e),n=this.complex(I,o).as2D(B.shape[0],B.shape[1]);return I.dispose(),o.dispose(),n},g.prototype.gatherND=function(B,Q){var w=Q.shape,C=w[w.length-1],E=Mc(B,Q),e=E[0],I=E[1],o=E[2],n=E[3],i=Q.reshape([I,C]),Y=B.reshape([B.size/o,o]),M=new CJ(C,n,[I,o]);return this.compileAndRun(M,[Y,i]).reshape(e)},g.prototype.fill=function(B,Q,w){if((w=w||HC(Q))==="string"){var C=xE(w,hA(B));return C.fill(Q),b.makeTensor(C,B,w,this)}var E=new QJ(B,Q),e=E.getCustomSetupFunc(Q);return this.compileAndRun(E,[],w,e)},g.prototype.onesLike=function(B){if(B.dtype==="string")throw new Error("onesLike is not supported under string dtype");return this.fill(B.shape,1,B.dtype)},g.prototype.zerosLike=function(B){return this.fill(B.shape,B.dtype==="string"?"":0,B.dtype)},g.prototype.linspace=function(B,Q,w){return Gc(B,Q,w)},g.prototype.makeTensorInfo=function(B,Q){var w=this.write(null,B,Q);return this.texData.get(w).usage=null,{dataId:w,shape:B,dtype:Q}},g.prototype.makeOutput=function(B,Q){var w=this.makeTensorInfo(B,Q).dataId;return b.makeTensorFromDataId(w,B,Q,this)},g.prototype.unpackTensor=function(B){var Q=new oN(B.shape);return this.runWebGLProgram(Q,[B],B.dtype)},g.prototype.packTensor=function(B){var Q=new mJ(B.shape);return this.runWebGLProgram(Q,[B],B.dtype,null,!0)},g.prototype.packedReshape=function(B,Q){var w=[_E(B.shape)].concat($E(B.shape)),C={dtype:B.dtype,shape:w,dataId:B.dataId},E=[_E(Q)].concat($E(Q)),e=new kJ(E,w),I=this.runWebGLProgram(e,[C],B.dtype,null,!0);return{dataId:I.dataId,shape:Q,dtype:I.dtype}},g.prototype.decode=function(B){var Q,w=this.texData.get(B),C=w.isPacked,E=w.shape,e=w.dtype,I=Zo(E);return Q=C?new Xf(I):new xf(I),{dtype:e,shape:E,dataId:this.runWebGLProgram(Q,[{shape:I,dtype:e,dataId:B}],e,null,!0).dataId}},g.prototype.runWebGLProgram=function(B,Q,w,C,E){var e=this;E===void 0&&(E=!1);var I=this.makeTensorInfo(B.outputShape,w),o=this.texData.get(I.dataId);if(B.packedOutput&&(o.isPacked=!0),B.outPackingScheme===PC.DENSE){var n=vC(B.outputShape);o.texShape=n.map(function(u){return 2*u})}if(B.outTexUsage!=null&&(o.usage=B.outTexUsage),hA(I.shape)===0)return o.values=dC(I.dtype,0),I;var i=[],Y=Q.map(function(u){if(u.dtype==="complex64")throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var a=e.texData.get(u.dataId);if(a.texture==null){if(!B.packedInputs&&hA(u.shape)<=BA().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:u.shape,texData:null,isUniform:!0,uniformValues:a.values};B.packedInputs&&(a.isPacked=!0,a.shape=u.shape)}else if(!!a.isPacked!=!!B.packedInputs)u=a.isPacked?e.unpackTensor(u):e.packTensor(u),i.push(u),a=e.texData.get(u.dataId);else if(a.isPacked&&!Be(a.shape,u.shape)){var U=u,G=u.shape;u.shape=a.shape,u=e.packedReshape(u,G),i.push(u),a=e.texData.get(u.dataId),U.shape=G}return e.uploadToGPU(u.dataId),{shape:u.shape,texData:a,isUniform:!1}});this.uploadToGPU(I.dataId);var M,c={shape:I.shape,texData:o,isUniform:!1},D=function(u,a,U){var G="";a.concat(U).forEach(function(h){var l=h.texData!=null&&h.texData.slice!=null&&h.texData.slice.flatOffset>0,m=h.isUniform?"uniform":h.texData.texShape;G+=h.shape+"_"+m+"_"+l});var d=u.userCode,H=u.constructor.name;return H+="_"+G+"_"+d}(B,Y,c),r=this.getAndSaveBinary(D,function(){return function(u,a,U,G){var d=a.userCode,H=U.map(function(p,K){var V={logicalShape:p.shape,texShape:p.isUniform?null:p.texData.texShape,isUniform:p.isUniform,isPacked:!p.isUniform&&p.texData.isPacked,flatOffset:null};return p.texData!=null&&p.texData.slice!=null&&p.texData.slice.flatOffset>0&&(V.flatOffset=p.texData.slice.flatOffset),{name:a.variableNames[K],shapeInfo:V}}),h=H.map(function(p){return p.shapeInfo}),l={logicalShape:G.shape,texShape:G.texData.texShape,isUniform:!1,isPacked:G.texData.isPacked,flatOffset:null},m=uf(H,l,d,a.packedInputs),f=u.createProgram(m),W=null,N=u.getUniformLocation(f,"NAN",!1);BA().getNumber("WEBGL_VERSION")===1&&(W=u.getUniformLocation(f,"INFINITY",!1));for(var v={},y=0;y<a.variableNames.length;y++){var k=a.variableNames[y];v[k]=u.getUniformLocation(f,k,!1),v["offset"+k]=u.getUniformLocation(f,"offset"+k,!1)}return{program:a,source:m,webGLProgram:f,uniformLocations:v,inShapeInfos:h,outShapeInfo:l,infLoc:W,nanLoc:N}}(e.gpgpu,B,Y,c)}),F=this.activeTimers!=null;if(F&&(M=this.startTimer()),function(u,a,U,G,d){Sc(a.inShapeInfos,U),Sc([a.outShapeInfo],[G]);var H=G.texData.texture,h=G.texData.texShape;G.texData.isPacked?u.setOutputPackedMatrixTexture(H,h[0],h[1]):u.setOutputMatrixTexture(H,h[0],h[1]),u.setProgram(a.webGLProgram),BA().getNumber("WEBGL_VERSION")===1&&a.infLoc!==null&&u.gl.uniform1f(a.infLoc,1/0),a.nanLoc!==null&&u.gl.uniform1f(a.nanLoc,NaN),U.forEach(function(l,m){var f=a.program.variableNames[m],W=a.uniformLocations[f],N=a.uniformLocations["offset"+f];if(W!=null)if(l.isUniform)if(hA(l.shape)<2)u.gl.uniform1f(W,l.uniformValues[0]);else{var v=l.uniformValues;v instanceof Float32Array||(v=new Float32Array(v)),u.gl.uniform1fv(W,v)}else l.texData.slice!=null&&N!=null&&u.gl.uniform1i(N,l.texData.slice.flatOffset),u.setInputMatrixTexture(l.texData.texture,W,m)}),d!=null&&d(u,a.webGLProgram),u.executeProgram()}(this.gpgpu,r,Y,c,C),i.forEach(function(u){return e.disposeData(u.dataId)}),F&&(M=this.endTimer(M),this.activeTimers.push({name:B.constructor.name,query:this.getQueryTime(M)})),!BA().getBool("WEBGL_LAZILY_UNPACK")&&o.isPacked&&E===!1){var s=this.unpackTensor(I);return this.disposeData(I.dataId),s}return I},g.prototype.compileAndRun=function(B,Q,w,C,E){E===void 0&&(E=!1),w=w||Q[0].dtype;var e=this.runWebGLProgram(B,Q,w,C,E);return b.makeTensorFromDataId(e.dataId,e.shape,e.dtype)},g.prototype.getAndSaveBinary=function(B,Q){return B in this.binaryCache||(this.binaryCache[B]=Q()),this.binaryCache[B]},g.prototype.getTextureManager=function(){return this.textureManager},g.prototype.dispose=function(){var B=this;this.disposed||(BA().getBool("IS_TEST")||Object.keys(this.binaryCache).forEach(function(Q){B.gpgpu.deleteProgram(B.binaryCache[Q].webGLProgram),delete B.binaryCache[Q]}),this.textureManager.dispose(),this.canvas!=null&&typeof HTMLCanvasElement<"u"&&this.canvas instanceof HTMLCanvasElement?this.canvas.remove():this.canvas=null,this.gpgpuCreatedLocally&&(this.gpgpu.program=null,this.gpgpu.dispose()),this.disposed=!0)},g.prototype.floatPrecision=function(){var B=this;return this.floatPrecisionValue==null&&(this.floatPrecisionValue=DA(function(){if(!BA().get("WEBGL_RENDER_FLOAT32_ENABLED")){var Q=BA().getBool("DEBUG");BA().set("DEBUG",!1);var w=B.abs(nA(1e-8)).dataSync()[0];if(BA().set("DEBUG",Q),w>0)return 32}return 16})),this.floatPrecisionValue},g.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},g.prototype.uploadToGPU=function(B){var Q,w=this.texData.get(B),C=w.shape,E=w.dtype,e=w.values,I=w.texture,o=w.usage,n=w.isPacked;if(I==null){var i,Y=this.activeTimers!=null;Y&&(i=Zg());var M=w.texShape;if(M==null&&(M=DH(C,n),w.texShape=M),e!=null){var c=Zo(C),D=void 0,r=M[1],F=M[0],s=e instanceof Uint8Array;n?(r=(Q=kC(M[0],M[1]))[0],F=Q[1],D=new AJ(c,[F,r],s)):D=new $f(c,[F,r],s);var u=this.makeTensorInfo([F,r],E);this.texData.get(u.dataId).usage=s?hg.PIXELS:hg.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(u.dataId),r,F,e);var a=this.runWebGLProgram(D,[u],E,null,!0),U=this.texData.get(a.dataId);w.texture=U.texture,w.texShape=U.texShape,w.isPacked=U.isPacked,w.usage=U.usage,this.disposeData(u.dataId),this.texData.delete(a.dataId),w.values=null,Y&&(this.uploadWaitMs+=Zg()-i)}else{var G=this.acquireTexture(M,o,E,n);w.texture=G}}},g.prototype.convertAndCacheOnCPU=function(B,Q){var w=this.texData.get(B),C=w.dtype;return this.releaseGPUData(B),Q!=null&&(w.values=function(E,e){if(e==="float32"||e==="complex64")return E;if(e==="int32"||e==="bool"){for(var I=e==="int32"?new Int32Array(E.length):new Uint8Array(E.length),o=0;o<I.length;++o)I[o]=Math.round(E[o]);return I}throw new Error("Unknown dtype "+e)}(Q,C)),w.values},g.prototype.acquireTexture=function(B,Q,w,C){if(this.numBytesInGPU+=this.computeBytes(B,w),!this.warnedAboutMemory&&this.numBytesInGPU>1024*this.numMBBeforeWarning*1024){var E=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+E+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(B,Q,C)},g.prototype.computeBytes=function(B,Q){return B[0]*B[1]*WM(Q)},g}(sc);$M()&&b.registerBackend("webgl",function(){return new nN},2);var iN=z({square_:function(A){var g=J(A,"x","square"),B=[g];return b.runKernelFunc(function(Q,w){return w([g]),Q.square(g)},{x:g},null,"Square",{},B,[])}}),zC="SquaredDifference",wD=z({squaredDifference_:function(A,g){var B,Q=J(A,"a","squaredDifference"),w=J(g,"b","squaredDifference");B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape);var C={a:Q,b:w},E=[Q,w];return b.runKernelFunc(function(e,I){var o=e.squaredDifference(Q,w);return I([Q,w]),o},C,function(e,I){var o=I[0],n=I[1],i=nA(2);return{a:function(){return e.mul(o.sub(n).mul(i))},b:function(){return e.mul(n.sub(o).mul(i))}}},zC,{},E,[])}}),YN=z({abs_:function(A){var g=J(A,"x","abs");return g.dtype==="complex64"?b.runKernelFunc(function(B){return B.complexAbs(g)},{$x:g}):b.runKernelFunc(function(B,Q){var w=B.abs(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mul(w.toFloat().step(-1))}}},"Abs")}}),MN=z({acos_:function(A){var g=J(A,"x","acos");return b.runKernelFunc(function(B,Q){var w=B.acos(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).sub(w.toFloat().square()).sqrt()).neg()}}})}}),cN=z({acosh_:function(A){var g=J(A,"x","acosh");return b.runKernelFunc(function(B,Q){var w=B.acosh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(w.toFloat().square().sub(1).sqrt())}}})}}),DN=z({asin_:function(A){var g=J(A,"x","asin");return b.runKernelFunc(function(B,Q){var w=B.asin(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).sub(w.toFloat().square()).sqrt())}}})}}),rN=z({asinh_:function(A){var g=J(A,"x","asinh");return b.runKernelFunc(function(B,Q){var w=B.asinh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.divStrict(nA(1).add(w.toFloat().square()).sqrt())}}})}}),FN=z({atan_:function(A){var g=J(A,"x","atan");return b.runKernelFunc(function(B,Q){var w=B.atan(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.toFloat().square().add(1))}}})}}),aN=z({atanh_:function(A){var g=J(A,"x","atanh");return b.runKernelFunc(function(B,Q){var w=B.atanh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(nA(1).sub(w.toFloat().square()))}}})}}),sN=z({ceil_:function(A){var g=J(A,"x","ceil");return b.runKernelFunc(function(B){return B.ceil(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),ut=z({clipByValue_:function(A,g,B){var Q=J(A,"x","clipByValue");R(g<=B,function(){return"Error in clip: min ("+g+") must be less than or equal to max ("+B+")."});var w=[Q],C={min:g,max:B};return b.runKernelFunc(function(E,e){var I=E.clip(Q,g,B);return e([Q]),I},{x:Q},function(E,e){var I=e[0];return{x:function(){return E.where(I.greaterEqual(g).logicalAnd(I.lessEqual(B)),$A(E))}}},"ClipByValue",C,w)}}),uN=z({cos_:function(A){var g=J(A,"x","cos"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.cos(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return C.toFloat().sin().neg().mul(Q)}}},"Cos",{},B)}}),UN=z({cosh_:function(A){var g=J(A,"x","cosh");return b.runKernelFunc(function(B,Q){var w=B.cosh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return w.toFloat().sinh().mulStrict(B)}}})}}),GN=z({erf_:function(A){var g=J(A,"x","erf");return R(g.dtype==="int32"||g.dtype==="float32",function(){return"Input dtype must be `int32` or `float32`."}),g.dtype==="int32"&&(g=g.toFloat()),b.runKernelFunc(function(B,Q){var w=B.erf(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),Ut=z({exp_:function(A){var g=J(A,"x","exp");return b.runKernelFunc(function(B,Q){var w=B.exp(g);return Q([w]),w},{x:g},function(B,Q){return{x:function(){return B.mulStrict(Q[0])}}},"Exp",{},[],[!0])}}),hN=z({expm1_:function(A){var g=J(A,"x","expm1");return b.runKernelFunc(function(B,Q){var w=B.expm1(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.exp())}}})}}),lN=z({floor_:function(A){var g=J(A,"x","floor");return b.runKernelFunc(function(B){return B.floor(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),dN=z({log_:function(A){var g=J(A,"x","log"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.log(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return Q.div(C.toFloat())}}},"Log",{},B)}}),HN=z({log1p_:function(A){var g=J(A,"x","log1p");return b.runKernelFunc(function(B,Q){var w=B.log1p(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.add(1))}}})}}),fN=z({logSigmoid_:function(A){var g=J(A,"x","logSigmoid");return b.runKernelFunc(function(B,Q){var w=B.softplus(g.neg()).neg();return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.neg().sigmoid())}}})}}),Fe=z({neg_:function(A){var g=J(A,"x","neg"),B=[g];return b.runKernelFunc(function(Q){return Q.neg(g)},{x:g},function(Q){return{x:function(){return Q.neg()}}},"Neg",{},B)}}),JN=z({reciprocal_:function(A){var g=J(A,"x","reciprocal");return b.runKernelFunc(function(B,Q){var w=B.reciprocal(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.square().neg())}}})}}),NN=z({round_:function(A){var g=J(A,"x","round");return b.runKernelFunc(function(B){return B.round(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),CD=z({rsqrt_:function(A){var g=J(A,"x","rsqrt"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.rsqrt(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return Q.div(C.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},B)}}),ED=z({sigmoid_:function(A){var g=J(A,"x","sigmoid");return b.runKernelFunc(function(B,Q){var w=B.sigmoid(g);return Q([w]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mul(w.mul(nA(1).sub(w)))}}},"Sigmoid")}}),mN=z({sign_:function(A){var g=J(A,"x","sign");return b.runKernelFunc(function(B){return B.sign(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),RN=z({isNaN_:function(A){var g=J(A,"x","isNaN");return b.runKernelFunc(function(B){return B.isNaN(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),PN=z({isInf_:function(A){var g=J(A,"x","isInf");return b.runKernelFunc(function(B){return B.isInf(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),vN=z({isFinite_:function(A){var g=J(A,"x","isFinite");return b.runKernelFunc(function(B){return B.isFinite(g)},{$x:g},function(B){return{$x:function(){return $A(B)}}})}}),kN=z({sin_:function(A){var g=J(A,"x","sin"),B=[g];return b.runKernelFunc(function(Q,w){var C=Q.sin(g);return w([g]),C},{x:g},function(Q,w){var C=w[0];return{x:function(){return C.toFloat().cos().mul(Q)}}},"Sin",{},B)}}),TN=z({sinh_:function(A){var g=J(A,"x","sinh");return b.runKernelFunc(function(B,Q){var w=B.sinh(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return w.toFloat().cosh().mulStrict(B)}}})}}),jN=z({softplus_:function(A){var g=J(A,"x","softplus");return b.runKernelFunc(function(B,Q){var w=B.softplus(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.mul(w.sigmoid())}}})}}),pN=z({sqrt_:function(A){var g=J(A,"x","sqrt");return b.runKernelFunc(function(B,Q){var w=B.sqrt(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.toFloat().sqrt().mul(2))}}})}}),yN=z({step_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","step");return b.runKernelFunc(function(Q){return Q.step(B,g)},{$x:B},function(Q){return{$x:function(){return $A(Q)}}})}}),zN=z({tan_:function(A){var g=J(A,"x","tan");return b.runKernelFunc(function(B,Q){var w=B.tan(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return B.div(w.cos().square())}}})}}),WN=z({tanh_:function(A){var g=J(A,"x","tanh");return b.runKernelFunc(function(B,Q){var w=B.tanh(g);return Q([w]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return nA(1).sub(w.square()).mulStrict(B)}}},"Tanh",{},null,[!0])}});function eD(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===2,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+I.rank+"."}),R(o.rank===2||o.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+o.rank+"."}),R(n.rank===2||n.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===2||E.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===2||e.rank===1,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function ID(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===3,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+I.rank+"."}),R(o.rank===3||o.rank===1,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+o.rank+"."}),R(n.rank===3||n.rank===1,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===3||E.rank===1,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===3||e.rank===1,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function oD(A,g,B,Q,w,C){var E,e,I=J(A,"x","batchNorm"),o=J(g,"mean","batchNorm"),n=J(B,"variance","batchNorm");return w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(I.rank===4,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+I.rank+"."}),R(o.rank===4||o.rank===1,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+o.rank+"."}),R(n.rank===4||n.rank===1,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+n.rank+"."}),E!=null&&R(E.rank===4||E.rank===1,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+E.rank+"."}),e!=null&&R(e.rank===4||e.rank===1,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+e.rank+"."}),WC(I,o,n,e,E,C)}function WC(A,g,B,Q,w,C){C==null&&(C=.001);var E,e,I,o=J(A,"x","batchNorm"),n=J(g,"mean","batchNorm"),i=J(B,"variance","batchNorm");w!=null&&(E=J(w,"scale","batchNorm")),Q!=null&&(e=J(Q,"offset","batchNorm")),R(n.rank===i.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),R(e==null||n.rank===e.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),R(E==null||n.rank===E.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),I=o.rank===0||o.rank===1?o.as4D(1,1,1,o.size):o.rank===2?o.as4D(1,1,o.shape[0],o.shape[1]):o.rank===3?o.as4D(1,o.shape[0],o.shape[1],o.shape[2]):o;var Y=[o,n,i,E];return b.runKernelFunc(function(M,c){var D=M.batchNormalization(I,ae(n),ae(i),C,ae(E),ae(e));return c([o,n,i,E]),D},{x:o,mean:n,variance:i,scale:E,offset:e},function(M,c){var D=c,r=D[0],F=D[1],s=D[2],u=D[3],a=u??nA(1),U=yB(F.shape,I.shape),G=[];if(F.rank===1){for(var d=0;d<I.shape.length-1;++d)G.push(I.shape[d]);G.push(1)}var H=r.sub(F),h=M.mul(a),l=CD(s.add(nA(C))),m=l.mul(l).mul(l).mul(nA(-.5));return{x:function(){return F.rank===1?M.mul(Ww(l.as4D(1,1,1,F.shape[0]),G)).mul(a).reshape(r.shape):M.mul(l).mul(a).reshape(r.shape)},mean:function(){var f=l.mul(nA(-1)).mul(h);return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)},variance:function(){var f=m.mul(H).mul(h);return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)},scale:function(){var f=H.mul(l),W=M.mul(f);return F.rank===1&&(W=W.sum(U)),W.reshape(F.shape)},offset:function(){var f=M;return F.rank===1&&(f=f.sum(U)),f.reshape(F.shape)}}},"BatchNormalization",{varianceEpsilon:C},Y).reshape(o.shape)}function ae(A){return A==null?null:A.rank===0?A.as1D():A.rank===1?A:A.rank===2?A.as4D(1,1,A.shape[0],A.shape[1]):A.rank===3?A.as4D(1,A.shape[0],A.shape[1],A.shape[2]):A}function se(){Qc("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon")}var SN=z({batchNormalization2d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),eD(A,g,B,C,w,Q)}}),LN=z({batchNormalization3d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),ID(A,g,B,C,w,Q)}}),bN=z({batchNormalization4d_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),oD(A,g,B,C,w,Q)}}),KN=z({batchNormalization_:function(A,g,B,Q,w,C){return Q===void 0&&(Q=.001),se(),WC(A,g,B,C,w,Q)}}),tD=z({batchNorm_:WC}),VN=z({batchNorm2d_:eD}),xN=z({batchNorm3d_:ID}),XN=z({batchNorm4d_:oD}),ue=z({logicalAnd_:function(A,g){var B=J(A,"a","logicalAnd","bool"),Q=J(g,"b","logicalAnd","bool");return qA(B.shape,Q.shape),b.runKernelFunc(function(w){return w.logicalAnd(B,Q)},{a:B,b:Q},null,"LogicalAnd")}}),ON=z({logicalNot_:function(A){var g=J(A,"x","logicalNot","bool");return b.runKernelFunc(function(B){return B.logicalNot(g)},{$x:g})}}),nD=z({logicalOr_:function(A,g){var B=J(A,"a","logicalOr","bool"),Q=J(g,"b","logicalOr","bool");return qA(B.shape,Q.shape),b.runKernelFunc(function(w){return w.logicalOr(B,Q)},{$a:B,$b:Q})}}),ZN=z({logicalXor_:function(A,g){var B=J(A,"a","logicalXor","bool"),Q=J(g,"b","logicalXor","bool");return qA(B.shape,Q.shape),nD(A,g).logicalAnd(ue(A,g).logicalNot())}}),Iw=z({where_:function(A,g,B){var Q=J(g,"a","where"),w=J(B,"b","where"),C=J(A,"condition","where","bool");return eB(Q.shape,w.shape,"Error in where: "),C.rank===1?R(C.shape[0]===Q.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}):eB(C.shape,w.shape,"Error in where: "),b.runKernelFunc(function(E,e){var I=E.select(C,Q,w);return e([C]),I},{$condition:C,$a:Q,$b:w},function(E,e){var I=e[0];return{$condition:function(){return $A(I).toFloat()},$a:function(){return E.mul(I.cast(E.dtype))},$b:function(){return E.mul(I.logicalNot().cast(E.dtype))}}})}}),iD=function(A){return uA(this,void 0,void 0,function(){var g,B,Q;return UA(this,function(w){switch(w.label){case 0:return[4,(g=J(A,"condition","whereAsync","bool")).data()];case 1:return B=w.sent(),Q=nt(g.shape,B),A!==g&&g.dispose(),[2,Q]}})})},OA=z({add_:function(A,g){var B,Q=J(A,"a","add"),w=J(g,"b","add");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E){return E.add(Q,w)},{a:Q,b:w},function(E){return{a:function(){var e=E,I=yB(Q.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(Q.shape)},b:function(){var e=E,I=yB(w.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(w.shape)}}},"Add")}}),qN=z({addN_:function(A){R(Array.isArray(A),function(){return"The argument passed to tf.addN() must be a list of tensors"}),R(A.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+A.length});var g=A.map(function(w,C){return J(w,"tensors"+C,"addN")}),B=g[0];g.forEach(function(w){if(w.dtype!==B.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),g.forEach(function(w){if(!KB(w.shape,B.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var Q=g;return b.runKernelFunc(function(w){return w.addN(g)},Q,function(w){var C={};return g.forEach(function(E,e){C[e]=function(){return w.clone()}}),C},"AddN")}}),_N=z({addStrict_:function(A,g){var B=J(A,"a","addStrict"),Q=J(g,"b","addStrict");return eB(B.shape,Q.shape,"Error in addStrict: "),B.add(Q)}}),$N=z({atan2_:function(A,g){var B,Q=J(A,"a","atan2"),w=J(g,"b","atan2");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.atan2(Q,w);return e([Q,w]),I},{$a:Q,$b:w},function(E,e){var I=e[0],o=e[1];return{$a:function(){var n=OA(I.square(),o.square()),i=E.mul(o.div(n)),Y=yB(I.shape,C);return Y.length>0&&(i=i.sum(Y)),i.reshape(I.shape)},$b:function(){var n=OA(I.square(),o.square()),i=Fe(E.mul(I.div(n))),Y=yB(o.shape,C);return Y.length>0&&(i=i.sum(Y)),i.reshape(o.shape)}}})}}),bg=z({div_:function(A,g){var B,Q=J(A,"a","div"),w=J(g,"b","div");if(B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="int32"&&w.dtype==="int32")return YD(Q,w);var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.realDivide(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.div(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);i.length>0&&(n=n.sum(i).reshape(o.shape));var Y=o.square();return n.div(Y.toFloat()).neg()}}},"Div")}}),Am=z({divNoNan_:function(A,g){var B,Q=J(A,"a","div"),w=J(g,"b","div");Q=(B=UB(Q,w))[0],w=B[1];var C=bg(Q,w),E=$A(C),e=w.equal(E);return Iw(e,E,C)}}),Bm=z({divStrict_:function(A,g){var B=J(A,"a","div"),Q=J(g,"b","div");return eB(B.shape,Q.shape,"Error in divideStrict: "),B.div(Q)}}),YD=z({floorDiv_:function(A,g){var B,Q=J(A,"a","floorDiv"),w=J(g,"b","floorDiv");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.floorDiv(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.div(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);i.length>0&&(n=n.sum(i).reshape(o.shape));var Y=o.square();return n.div(Y.toFloat()).neg()}}},"FloorDiv")}}),Gt=z({maximum_:function(A,g){var B,Q=J(A,"a","maximum"),w=J(g,"b","maximum");return B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="bool"&&(Q=Q.toInt(),w=w.toInt()),qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.maximum(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return C.mul(e.greaterEqual(I).toFloat())},b:function(){return C.mul(e.less(I).toFloat())}}},"Maximum")}}),gm=z({maximumStrict_:function(A,g){var B=J(A,"a","maximumStrict"),Q=J(g,"b","maximumStrict");return eB(B.shape,Q.shape,"Error in maximumStrict: "),B.maximum(Q)}}),MD=z({minimum_:function(A,g){var B,Q=J(A,"a","minimum"),w=J(g,"b","minimum");return B=UB(Q,w),Q=B[0],w=B[1],Q.dtype==="bool"&&(Q=Q.toInt(),w=w.toInt()),qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.minimum(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return C.mul(e.lessEqual(I).toFloat())},b:function(){return C.mul(e.greater(I).toFloat())}}},"Minimum")}}),Qm=z({minimumStrict_:function(A,g){var B=J(A,"a","minimumStrict"),Q=J(g,"b","minimumStrict");return eB(B.shape,Q.shape,"Error in minimumStrict: "),B.minimum(Q)}}),wm=z({mod_:function(A,g){var B,Q=J(A,"a","mod"),w=J(g,"b","mod");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.mod(Q,w);return e([Q,w]),I},{$a:Q,$b:w},function(E,e){var I=e[0],o=e[1];return{$a:function(){var n=yB(I.shape,C);return n.length>0?E.sum(n).reshape(I.shape):E},$b:function(){var n=E.mul(I.div(o).floor().neg()),i=yB(o.shape,C);return i.length>0?n.sum(i).reshape(o.shape):n}}})}}),Cm=z({modStrict_:function(A,g){var B=J(A,"a","modStrict"),Q=J(g,"b","modStrict");return eB(B.shape,Q.shape,"Error in modStrict: "),B.mod(Q)}}),wg=z({mul_:function(A,g){var B,Q=J(A,"a","mul"),w=J(g,"b","mul");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E,e){var I=E.multiply(Q,w);return e([Q,w]),I},{a:Q,b:w},function(E,e){var I=e[0],o=e[1];return{a:function(){var n=E.mul(o.toFloat()),i=yB(I.shape,C);return i.length>0?n.sum(i).reshape(I.shape):n},b:function(){var n=E.mul(I.toFloat()),i=yB(o.shape,C);return i.length>0?n.sum(i).reshape(o.shape):n}}},"Mul")}}),Em=z({mulStrict_:function(A,g){var B=J(A,"a","mul"),Q=J(g,"b","mul");return eB(B.shape,Q.shape,"Error in multiplyStrict: "),B.mul(Q)}}),Ue=z({pow_:function(A,g){var B,Q=J(A,"base","pow"),w=J(g,"exp","pow");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape),E=[Q,w];return b.runKernelFunc(function(e,I){var o=e.pow(Q,w);return I([Q,w,o]),o},{a:Q,b:w},function(e,I){var o=I[0],n=I[1],i=I[2];return{a:function(){var Y=n.toFloat(),M=e.mul(Y.mul(o.pow(Y.sub(nA(1))))),c=yB(o.shape,C);return c.length>0&&(M=M.sum(c)),M.reshape(o.shape)},b:function(){var Y=o.greater(0),M=o.log().where(Y,$A(o)),c=e.mul(i.mul(M)),D=yB(n.shape,C);return D.length>0&&(c=c.sum(D)),c.reshape(n.shape)}}},"Pow",{},E,[!0])}}),em=z({powStrict_:function(A,g){return eB(A.shape,g.shape,"Error in powStrict: "),A.pow(g)}}),Im=z({squaredDifferenceStrict_:function(A,g){var B=J(A,"a","squaredDifferenceStrict"),Q=J(g,"b","squaredDifferenceStrict");return eB(B.shape,Q.shape,"Error in squaredDifferenceStrict: "),B.squaredDifference(Q)}}),zB=z({sub_:function(A,g){var B,Q=J(A,"a","sub"),w=J(g,"b","sub");B=UB(Q,w),Q=B[0],w=B[1];var C=qA(Q.shape,w.shape);return b.runKernelFunc(function(E){return E.subtract(Q,w)},{a:Q,b:w},function(E){return{a:function(){var e=E,I=yB(Q.shape,C);return I.length>0&&(e=e.sum(I)),e.reshape(Q.shape)},b:function(){var e=E,I=yB(w.shape,C);return I.length>0&&(e=e.sum(I)),e.neg().reshape(w.shape)}}},"Sub")}}),om=z({subStrict_:function(A,g){var B=J(A,"a","subStrict"),Q=J(g,"b","subStrict");return eB(B.shape,Q.shape,"Error in subStrict: "),B.sub(Q)}}),cD=z({equal_:function(A,g){var B,Q=J(A,"a","equal"),w=J(g,"b","equal");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.equal(Q,w)},{$a:Q,$b:w})}}),tm=z({equalStrict_:function(A,g){var B=J(A,"a","equalStrict"),Q=J(g,"b","equalStrict");return eB(B.shape,Q.shape,"Error in equalStrict: "),B.equal(Q)}}),nm=z({greater_:function(A,g){var B,Q=J(A,"a","greater"),w=J(g,"b","greater");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.greater(Q,w)},{a:Q,b:w},null,"Greater")}}),DD=z({greaterEqual_:function(A,g){var B,Q=J(A,"a","greaterEqual"),w=J(g,"b","greaterEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.greaterEqual(Q,w);return E([Q,w]),e},{a:Q,b:w},function(C,E){var e=E[0],I=E[1];return{a:function(){return $A(e)},b:function(){return $A(I)}}},"GreaterEqual")}}),im=z({greaterEqualStrict_:function(A,g){var B=J(A,"a","greaterEqualStrict"),Q=J(g,"b","greaterEqualStrict");return eB(B.shape,Q.shape,"Error in greaterEqualStrict: "),B.greaterEqual(Q)}}),Ym=z({greaterStrict_:function(A,g){var B=J(A,"a","greaterStrict"),Q=J(g,"b","greaterStrict");return eB(B.shape,Q.shape,"Error in greaterStrict: "),B.greater(Q)}}),Mm=z({less_:function(A,g){var B,Q=J(A,"a","less"),w=J(g,"b","less");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.less(Q,w)},{a:Q,b:w},null,"Less")}}),cm=z({lessEqual_:function(A,g){var B,Q=J(A,"a","lessEqual"),w=J(g,"b","lessEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C,E){var e=C.lessEqual(Q,w);return E([Q,w]),e},{a:Q,b:w},null,"LessEqual")}}),Dm=z({lessEqualStrict_:function(A,g){var B=J(A,"a","lessEqualStrict"),Q=J(g,"b","lessEqualStrict");return eB(B.shape,Q.shape,"Error in lessEqualStrict: "),B.lessEqual(Q)}}),rm=z({lessStrict_:function(A,g){var B=J(A,"a","lessStrict"),Q=J(g,"b","lessStrict");return eB(B.shape,Q.shape,"Error in lessStrict: "),B.less(Q)}}),Fm=z({notEqual_:function(A,g){var B,Q=J(A,"a","notEqual"),w=J(g,"b","notEqual");return B=UB(Q,w),Q=B[0],w=B[1],qA(Q.shape,w.shape),b.runKernelFunc(function(C){return C.notEqual(Q,w)},{a:Q,b:w},null,"NotEqual")}}),am=z({notEqualStrict_:function(A,g){var B=J(A,"a","notEqualStrict"),Q=J(g,"b","notEqualStrict");return eB(B.shape,Q.shape,"Error in notEqualStrict: "),B.notEqual(Q)}});function rD(A,g){for(var B=[],Q=A;Q<g;++Q)B.push(Q);return B}function FD(A){for(var g=[],B=0;B<A.length;++B)for(var Q=0;Q<A[B].length;++Q)g.push(A[B][Q]);return g}var ht=z({gather_:function(A,g,B){B===void 0&&(B=0);var Q=J(A,"x","gather"),w=J(g,"indices","gather","int32");B=TB(B,Q.shape)[0];var C=function(E,e,I){for(var o=E.shape[I],n=[],i=1,Y=1,M=0;M<I;M++)n.push(E.shape[M]),i*=E.shape[M];for(M=0;M<e.rank;M++)n.push(e.shape[M]);for(M=I+1;M<E.rank;M++)n.push(E.shape[M]),Y*=E.shape[M];return{batchSize:i,sliceSize:Y,dimSize:o,outputShape:n}}(Q,w,B);return b.runKernelFunc(function(E,e){var I=E.gather(Q,w.flatten(),B);return e([w]),I},{x:Q,indices:w},function(E,e){var I=e[0];return{x:function(){var o=Q.shape,n=I.size,i=o.slice(0,B),Y=i.length,M=o.slice(B,o.length).slice(1),c=M.length,D=rD(0,Y),r=rD(Y+1,Y+1+c),F=FD([i,[n],M]),s=E.reshape(F),u=I.reshape([n]),a=FD([[Y],D,r]),U=s.transpose(a),G=aD(U,u,Q.shape[B]),d=_o(a);return G=G.transpose(d)},indices:function(){return I}}},"Gather",{axis:B}).reshape(C.outputShape)}}),aD=z({unsortedSegmentSum_:function(A,g,B){var Q=J(A,"x","unsortedSegmentSum"),w=J(g,"segmentIds","unsortedSegmentSum","int32");return R(JB(B),function(){return"numSegments must be of dtype int"}),b.runKernelFunc(function(C,E){var e=C.unsortedSegmentSum(Q,w,B);return E([w]),e},{$x:Q},function(C,E){var e=E[0];return{$x:function(){return function(I,o){for(var n=Gt(o,$A(o)),i=ht(I,n),Y=DD(o,nA(0,"int32")),M=i.rank-Y.rank,c=0;c<M;++c)Y=Tg(Y,c+1);Y=ue(Y,zw(i.shape,"bool"));var D=$A(i);return Iw(Y,i,D)}(C,e)}}})}}),sm=function(A,g,B){return uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D;return UA(this,function(r){switch(r.label){case 0:for(Q=J(A,"tensor","boolMask"),w=J(g,"mask","boolMask","bool"),C=B??0,E=w.rank,e=Q.shape,R(E>0,function(){return"mask cannot be scalar"}),eB(e.slice(C,C+E),w.shape,"mask's shape must match the first K dimensions of tensor's shape,"),I=1,o=C;o<C+E;o++)I*=e[o];return n=e.slice(0,C).concat([I],e.slice(C+E)),i=Q.reshape(n),Y=w.reshape([-1]),[4,iD(Y)];case 1:return M=r.sent(),c=M.squeeze([1]),D=ht(i,c,C),A!==Q&&Q.dispose(),g!==w&&w.dispose(),c.dispose(),i.dispose(),Y.dispose(),M.dispose(),[2,D]}})})};function sD(A,g,B,Q,w,C,E){C===void 0&&(C="NHWC"),R(A.length===g.rank,function(){return"Length of inShape ("+A.length+") and rank of dy ("+g.rank+") must match"});var e=A,I=g,o=!1;g.rank===3&&(o=!0,I=g.as4D(1,g.shape[0],g.shape[1],g.shape[2]),e=[1,A[0],A[1],A[2]]),R(e.length===4,function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+e.length+"."}),R(I.rank===4,function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+I.rank}),R(B.rank===4,function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+B.rank});var n=C==="NHWC"?e[3]:e[1],i=C==="NHWC"?I.shape[3]:I.shape[1];R(n===B.shape[2],function(){return"Error in conv2dDerInput: depth of input ("+n+") must match input depth for filter "+B.shape[2]+"."}),R(i===B.shape[3],function(){return"Error in conv2dDerInput: depth of output ("+i+") must match output depth for filter "+B.shape[3]+"."}),E!=null&&R(JB(w),function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+w+"."});var Y=Et(C),M=Cw(e,B.shape,Q,1,w,E,!1,Y),c=b.runKernelFunc(function(D,r){var F=D.conv2dDerInput(I,B,M);return r([B,I]),F},{dy4D:I,filter:B},function(D,r){var F=r[0],s=r[1];return{dy4D:function(){return jg(D,F,Q,w,C,1,E)},filter:function(){return dt(D,s,F.shape,Q,w,C,E)}}});return o?c.as3D(c.shape[1],c.shape[2],c.shape[3]):c}function lt(A){var g=function(C){return typeof C=="number"?[C,C,C]:C.length===2?[C[0],C[1],1]:C}(A),B=g[0],Q=g[1],w=g[2];return B===1&&Q===1&&w===1}function uD(A,g,B,Q,w){R(A.length===g.rank,function(){return"Length of inShape ("+A.length+") and rank of dy ("+g.rank+") must match"});var C=A,E=g,e=!1;g.rank===4&&(e=!0,E=g.as5D(1,g.shape[0],g.shape[1],g.shape[2],g.shape[3]),C=[1,A[0],A[1],A[2],A[3]]);var I=C[4],o=E.shape[4];R(C.length===5,function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+C.length+"."}),R(E.rank===5,function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+E.rank}),R(B.rank===5,function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+B.rank}),R(I===B.shape[3],function(){return"Error in conv3dDerInput: depth of input ("+I+") must match input depth for filter "+B.shape[3]+"."}),R(o===B.shape[4],function(){return"Error in conv3dDerInput: depth of output ("+o+") must match output depth for filter "+B.shape[4]+"."});var n=ie(C,B.shape,Q,1,w),i=b.runKernelFunc(function(Y){return Y.conv3dDerInput(E,B,n)},{dy5D:E});return e?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}var um=z({conv1d_:function(A,g,B,Q,w,C,E){w===void 0&&(w="NWC"),C===void 0&&(C=1);var e=J(A,"x","conv1d"),I=J(g,"filter","conv1d"),o=e,n=!1;e.rank===2&&(n=!0,o=e.as3D(1,e.shape[0],e.shape[1])),R(o.rank===3,function(){return"Error in conv1d: input must be rank 3, but got rank "+o.rank+"."}),R(I.rank===3,function(){return"Error in conv1d: filter must be rank 3, but got rank "+I.rank+"."}),E!=null&&R(JB(Q),function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."}),R(o.shape[2]===I.shape[1],function(){return"Error in conv1d: depth of input ("+o.shape[2]+") must match input depth for filter "+I.shape[1]+"."}),R(rg(B,C),function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+B+" and dilation '"+C+"'"}),R(w==="NWC",function(){return"Error in conv1d: got dataFormat of "+w+" but only NWC is currently supported."});var i=I.as4D(1,I.shape[0],I.shape[1],I.shape[2]),Y=o.as4D(o.shape[0],1,o.shape[1],o.shape[2]),M=jg(Y,i,[1,B],Q,"NHWC",[1,C],E);return n?M.as2D(M.shape[2],M.shape[3]):M.as3D(M.shape[0],M.shape[2],M.shape[3])}}),jg=z({conv2d_:function(A,g,B,Q,w,C,E){w===void 0&&(w="NHWC"),C===void 0&&(C=[1,1]);var e=J(A,"x","conv2d"),I=J(g,"filter","conv2d"),o=e,n=!1;e.rank===3&&(n=!0,o=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),R(o.rank===4,function(){return"Error in conv2d: input must be rank 4, but got rank "+o.rank+"."}),R(I.rank===4,function(){return"Error in conv2d: filter must be rank 4, but got rank "+I.rank+"."}),E!=null&&R(JB(Q),function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."});var i=w==="NHWC"?o.shape[3]:o.shape[1];R(i===I.shape[2],function(){return"Error in conv2d: depth of input ("+i+") must match input depth for filter "+I.shape[2]+"."}),R(rg(B,C),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"});var Y=Et(w),M=Cw(o.shape,I.shape,B,C,Q,E,!1,Y),c=[I,o],D=b.runKernelFunc(function(r,F){var s=r.conv2d(o,I,M);return F([I,o]),s},{x:o,filter:I},function(r,F){var s=F,u=s[0],a=s[1];return R(Lw(C),function(){return"Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+C+"'"}),{x:function(){return UD(a.shape,r,u,B,Q,w)},filter:function(){return dt(a,r,u.shape,B,Q,w)}}},"Conv2D",M,c);return n?D.as3D(D.shape[1],D.shape[2],D.shape[3]):D}}),Um=z({conv3d_:function(A,g,B,Q,w,C){w===void 0&&(w="NDHWC"),C===void 0&&(C=[1,1,1]);var E=J(A,"x","conv3d"),e=J(g,"filter","conv3d"),I=E,o=!1;E.rank===4&&(o=!0,I=E.as5D(1,E.shape[0],E.shape[1],E.shape[2],E.shape[3])),R(I.rank===5,function(){return"Error in conv3d: input must be rank 5, but got rank "+I.rank+"."}),R(e.rank===5,function(){return"Error in conv3d: filter must be rank 5, but got rank "+e.rank+"."}),R(I.shape[4]===e.shape[3],function(){return"Error in conv3d: depth of input ("+I.shape[4]+") must match input depth for filter "+e.shape[3]+"."}),R(function(Y,M){return lt(Y)||lt(M)}(B,C),function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"}),R(w==="NDHWC",function(){return"Error in conv3d: got dataFormat of "+w+" but only NDHWC is currently supported."});var n=ie(I.shape,e.shape,B,C,Q),i=b.runKernelFunc(function(Y,M){var c=Y.conv3d(I,e,n);return M([I,e]),c},{x:I,$filter:e},function(Y,M){R(lt(C),function(){return"Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+C+"'"});var c=M[0],D=M[1];return{x:function(){return uD(c.shape,Y,D,B,Q)},$filter:function(){return function(r,F,s,u,a){var U=r;r.rank===4&&(U=r.as5D(1,r.shape[0],r.shape[1],r.shape[2],r.shape[3]));var G=F;G.rank===4&&(G=F.as5D(1,F.shape[0],F.shape[1],F.shape[2],F.shape[3])),R(U.rank===5,function(){return"Error in conv3dDerFilter: input must be rank 5, but got shape "+U.shape+"."}),R(G.rank===5,function(){return"Error in conv3dDerFilter: dy must be rank 5, but got shape "+G.shape+"."}),R(s.length===5,function(){return"Error in conv3dDerFilter: filterShape must be length 5, but got "+s+"."}),R(U.shape[4]===s[3],function(){return"Error in conv3dDerFilter: depth of input "+U.shape[4]+") must match input depth in filter ("+s[3]+"."}),R(G.shape[4]===s[4],function(){return"Error in conv3dDerFilter: depth of dy ("+G.shape[4]+") must match output depth for filter ("+s[4]+")."});var d=ie(U.shape,s,u,1,a);return b.runKernelFunc(function(H){return H.conv3dDerFilter(U,G,d)},{x5D:U,dy5D:G})}(c,Y,D.shape,B,Q)}}});return o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),dt=z({conv2dDerFilter_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NHWC");var e=A;A.rank===3&&(e=A.as4D(1,A.shape[0],A.shape[1],A.shape[2]));var I=g;I.rank===3&&(I=g.as4D(1,g.shape[0],g.shape[1],g.shape[2])),R(e.rank===4,function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+e.shape+"."}),R(I.rank===4,function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+I.shape+"."}),R(B.length===4,function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+B+"."});var o=C==="NHWC"?e.shape[3]:e.shape[1],n=C==="NHWC"?I.shape[3]:I.shape[1];R(o===B[2],function(){return"Error in conv2dDerFilter: depth of input "+o+") must match input depth in filter ("+B[2]+"."}),R(n===B[3],function(){return"Error in conv2dDerFilter: depth of dy ("+n+") must match output depth for filter ("+B[3]+")."}),E!=null&&R(JB(w),function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+w+"."});var i=Et(C),Y=Cw(e.shape,B,Q,1,w,E,!1,i);return b.runKernelFunc(function(M){return M.conv2dDerFilter(e,I,Y)},{x4D:e,dy4D:I})}}),UD=z({conv2dDerInput_:sD}),Ge=z({depthwiseConv2d_:function(A,g,B,Q,w,C,E){C===void 0&&(C=[1,1]);var e=J(A,"x","depthwiseConv2d"),I=J(g,"filter","depthwiseConv2d"),o=e,n=!1;e.rank===3&&(n=!0,o=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),R(o.rank===4,function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+o.rank+"."}),R(I.rank===4,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+I.rank+"."}),R(o.shape[3]===I.shape[2],function(){return"Error in depthwiseConv2d: number of input channels ("+o.shape[3]+") must match the inChannels dimension in filter "+I.shape[2]+"."}),C==null&&(C=[1,1]),R(rg(B,C),function(){return"Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+C+"'"}),E!=null&&R(JB(Q),function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+E+" but got pad "+Q+"."});var i=Cw(o.shape,I.shape,B,C,Q,E,!0),Y=[o,I],M=b.runKernelFunc(function(c,D){var r=c.depthwiseConv2D(o,I,i);return D([o,I]),r},{x:o,filter:I},function(c,D){R(Lw(C),function(){return"Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+C+"'"});var r=D[0],F=D[1];return{x:function(){return GD(r.shape,c,F,i)},filter:function(){return hD(r,c,F.shape,i)}}},"DepthwiseConv2dNative",i,Y);return n?M.as3D(M.shape[1],M.shape[2],M.shape[3]):M}}),GD=z({depthwiseConv2dDerInput_:function(A,g,B,Q){var w=g,C=!1;g.rank===3&&(C=!0,w=g.as4D(1,g.shape[0],g.shape[1],g.shape[2]));var E=b.runKernelFunc(function(e){return e.depthwiseConv2DDerInput(w,B,Q)},{dy4D:w});return C?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),hD=z({depthwiseConv2dDerFilter_:function(A,g,B,Q){var w=A;A.rank===3&&(w=A.as4D(1,A.shape[0],A.shape[1],A.shape[2]));var C=g;return C.rank===3&&(C=g.as4D(1,g.shape[0],g.shape[1],g.shape[2])),b.runKernelFunc(function(E){return E.depthwiseConv2DDerFilter(w,C,Q)},{x4D:w,dy4D:C})}}),Ht=z({separableConv2d_:function(A,g,B,Q,w,C,E){C===void 0&&(C=[1,1]),E===void 0&&(E="NHWC");var e=J(A,"x","separableConv2d"),I=J(g,"depthwiseFilter","separableConv2d"),o=J(B,"pointwiseFilter","separableConv2d"),n=e,i=!1;if(e.rank===3&&(i=!0,n=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),E==="NCHW")throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");R(n.rank===4,function(){return"Error in separableConv2d: input must be rank 4, but got rank "+n.rank+"."}),R(I.rank===4,function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+I.rank+"."}),R(o.rank===4,function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+I.rank+"."}),R(o.shape[0]===1,function(){return"Error in separableConv2d: the first dimension of pointwise filter must be 1, but got "+o.shape[0]+"."}),R(o.shape[1]===1,function(){return"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+o.shape[1]+"."});var Y=I.shape[2],M=I.shape[3];R(o.shape[2]===Y*M,function(){return"Error in separableConv2d: the third dimension of pointwise filter must be "+Y*M+", but got "+o.shape[2]+"."});var c=Ge(n,I,Q,w,E,C),D=jg(c,o,1,"valid",E);return i?D.as3D(D.shape[1],D.shape[2],D.shape[3]):D}}),Gm=z({conv2dTranspose_:function(A,g,B,Q,w,C){return sD(B,J(A,"x","conv2dTranspose"),J(g,"filter","conv2dTranspose"),Q,w,"NHWC",C)}}),hm=z({conv3dTranspose_:function(A,g,B,Q,w){return uD(B,J(A,"x","conv3dTranspose"),J(g,"filter","conv3dTranspose"),Q,w)}}),he=z({matMul_:function(A,g,B,Q){var w;B===void 0&&(B=!1),Q===void 0&&(Q=!1);var C=J(A,"a","matMul"),E=J(g,"b","matMul");w=UB(C,E),C=w[0],E=w[1];var e=B?C.shape[C.rank-2]:C.shape[C.rank-1],I=Q?E.shape[E.rank-1]:E.shape[E.rank-2],o=B?C.shape[C.rank-1]:C.shape[C.rank-2],n=Q?E.shape[E.rank-2]:E.shape[E.rank-1],i=C.shape.slice(0,-2),Y=E.shape.slice(0,-2),M=hA(i),c=hA(Y);R(C.rank>=2&&E.rank>=2&&C.rank===E.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+C.rank+" and "+E.rank+"."}),R(KB(i,Y),function(){return"Error in matMul: outer dimensions ("+i+") and ("+Y+") of Tensors with shapes "+C.shape+" and "+E.shape+" must match."}),R(e===I,function(){return"Error in matMul: inner shapes ("+e+") and ("+I+") of Tensors with shapes "+C.shape+" and "+E.shape+" and transposeA="+B+" and transposeB="+Q+" must match."});var D=C.shape.slice(0,-2).concat([o,n]),r=B?C.as3D(M,e,o):C.as3D(M,o,e),F=Q?E.as3D(c,n,I):E.as3D(c,I,n),s={transposeA:B,transposeB:Q};return b.runKernelFunc(function(u,a){var U=u.batchMatMul(r,F,B,Q);return a([r,F]),U},{a:r,b:F},function(u,a){var U=a,G=U[0],d=U[1];return B||Q?!B&&Q?{a:function(){return u.matMul(d,!1,!1)},b:function(){return u.matMul(G,!0,!1)}}:B&&!Q?{a:function(){return d.matMul(u,!1,!0)},b:function(){return G.matMul(u,!1,!1)}}:{a:function(){return d.matMul(u,!0,!0)},b:function(){return u.matMul(G,!0,!0)}}:{a:function(){return u.matMul(d,!1,!0)},b:function(){return G.matMul(u,!0,!1)}}},"BatchMatMul",s).reshape(D)}}),lm=z({dot_:function(A,g){var B=J(A,"t1","dot"),Q=J(g,"t2","dot");R(!(B.rank!==1&&B.rank!==2||Q.rank!==1&&Q.rank!==2),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+B.rank+" and "+Q.rank+"."});var w=B.rank===1?B.size:B.shape[1],C=Q.rank===1?Q.size:Q.shape[0];return R(w===C,function(){return"Error in dot: inner dimensions of inputs must match, but got "+w+" and "+C+"."}),B.rank===1&&Q.rank===1?B.as2D(1,-1).matMul(Q.as2D(-1,1)).asScalar():B.rank===1&&Q.rank===2?B.as2D(1,-1).matMul(Q.as2D(Q.shape[0],Q.shape[1])).as1D():B.rank===2&&Q.rank===1?B.matMul(Q.as2D(-1,1)).as1D():B.matMul(Q.as2D(Q.shape[0],Q.shape[1]))}}),dm=z({outerProduct_:function(A,g){var B=J(A,"v1","outerProduct"),Q=J(g,"v2","outerProduct");return R(B.rank===1&&Q.rank===1,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+B.rank+" and "+Q.rank+"."}),B.as2D(-1,1).matMul(Q.as2D(1,-1))}}),SC=z({reverse_:function(A,g){var B=J(A,"x","reverse");if(B.rank===0)return B.clone();var Q=TB(g,B.shape);return b.runKernelFunc(function(w){return w.reverse(B,Q)},{$x:B},function(w){return{$x:function(){return w.reverse(Q)}}}).reshapeAs(B)}}),Hm=z({reverse1d_:function(A){var g=J(A,"x","reverse");return R(g.rank===1,function(){return"Error in reverse1D: x must be rank 1 but got rank "+g.rank+"."}),SC(g,0)}}),fm=z({reverse2d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===2,function(){return"Error in reverse2D: x must be rank 2 but got rank "+B.rank+"."}),SC(B,g)}}),Jm=z({reverse3d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===3,function(){return"Error in reverse3D: x must be rank 3 but got rank "+B.rank+"."}),SC(B,g)}}),Nm=z({reverse4d_:function(A,g){var B=J(A,"x","reverse");return R(B.rank===4,function(){return"Error in reverse4D: x must be rank 4 but got rank "+B.rank+"."}),SC(B,g)}});function lD(A,g,B,Q,w,C){var E=J(A,"x","maxPool"),e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(e.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+e.rank+"."}),R(rg(B,Q),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+Q+"'"}),C!=null&&R(JB(w),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+C+" but got pad "+w+"."});var o=TC(e.shape,g,B,Q,w,C);if(o.filterWidth===1&&o.filterHeight===1&&KB(o.inShape,o.outShape))return E.clone();var n=[e],i=b.runKernelFunc(function(Y,M){var c=Y.maxPool(e,o);return M([e,c]),c},{x:e},function(Y,M){var c=M[0],D=M[1];return{x:function(){return function(r,F,s,u,a,U,G,d){var H=J(r,"dy","maxPoolBackprop"),h=J(F,"input","maxPoolBackprop"),l=J(s,"output","maxPoolBackprop");R(h.rank===H.rank,function(){return"Rank of input ("+h.rank+") does not match rank of dy ("+H.rank+")"}),R(rg(a,U),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+U+"'"}),R(H.rank===4,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+H.rank+"."}),R(h.rank===4,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+h.rank+"."});var m=TC(h.shape,u,a,U,G,d);return b.runKernelFunc(function(f){return f.maxPoolBackprop(H,h,l,m)},{$dy:H,$input:h})}(Y,c,D,g,B,Q,w)}}},"MaxPool",o,n);return I?i.as3D(i.shape[1],i.shape[2],i.shape[3]):i}function dD(A,g,B,Q,w,C){var E=J(A,"x","avgPool","float32");R(rg(B,Q),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+Q+"'"});var e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(e.rank===4,function(){return"Error in avgPool: x must be rank 4 but got rank "+e.rank+"."}),C!=null&&R(JB(w),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+C+" but got pad "+w+"."});var o=TC(e.shape,g,B,Q,w,C);if(o.filterWidth===1&&o.filterHeight===1&&KB(o.inShape,o.outShape))return E.clone();var n=b.runKernelFunc(function(i){return i.avgPool(e,o)},{x:e},function(i){return{x:function(){return function(Y,M,c,D,r,F){var s=J(Y,"dy","avgPoolBackprop"),u=J(M,"input","avgPoolBackprop");R(u.rank===s.rank,function(){return"Rank of input ("+u.rank+") does not match rank of dy ("+s.rank+")"}),R(rg(D,r),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+D+" and dilations '"+r+"'"});var a=u,U=s,G=!1;u.rank===3&&(G=!0,a=u.as4D(1,u.shape[0],u.shape[1],u.shape[2]),U=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),R(U.rank===4,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+U.rank+"."}),R(a.rank===4,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+a.rank+"."});var d=TC(a.shape,c,D,r,F),H=b.runKernelFunc(function(h){return h.avgPoolBackprop(U,a,d)},{dy4D:U,input4D:a});return G?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}(i,e,g,B,Q,w)}}},"AvgPool",o);return n=n.cast(E.dtype),I?n.as3D(n.shape[1],n.shape[2],n.shape[3]):n}var VB=z({maxPool_:function(A,g,B,Q,w){return lD(A,g,B,1,Q,w)}}),LC=z({avgPool_:function(A,g,B,Q,w){return dD(A,g,B,1,Q,w)}}),mm=z({pool_:function(A,g,B,Q,w,C){w==null&&(w=[1,1]),C==null&&(C=1),Q===0&&(Q="valid");var E=J(A,"x","maxPool"),e=E,I=!1;E.rank===3&&(I=!0,e=E.as4D(1,E.shape[0],E.shape[1],E.shape[2])),R(rg(C,w),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+C+" and dilations '"+w+"'"});var o,n=TC(e.shape,g,C,w,Q),i=[n.dilationHeight,n.dilationWidth];o=Q==="same"?function(a,U){var G=a.map(function(h,l){return h+(h-1)*(U[l]-1)}).map(function(h){return h-1}),d=G.map(function(h){return Math.floor(h/2)}),H=G.map(function(h,l){return h-d[l]});return G.map(function(h,l){return[d[l],H[l]]})}([n.filterHeight,n.filterWidth],i):[[0,0],[0,0]];var Y=i[0]===1&&i[1]===1,M=function(a,U,G){var d=G.map(function(N){return N[0]}),H=G.map(function(N){return N[1]}),h=a.concat(d,H),l=U.map(function(N,v){return(N-h[v]%N)%N}),m=H.map(function(N,v){return N+l[v]}),f=U.map(function(N,v){return[d[v],m[v]]}),W=U.map(function(N,v){return[0,l[v]]});return[f,W]}([n.inHeight,n.inWidth],i,o),c=M[0],D=M[1],r=Y?Q:"valid",F=Y?e:tc(e,i,c),s=(B==="avg"?function(){return dD(F,g,C,1,r)}:function(){return lD(F,g,C,1,r)})(),u=Y?s:ec(s,i,D);return I?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Rm=z({maxPool3d_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NDHWC");var e=J(A,"x","maxPool3d"),I=e,o=!1;e.rank===4&&(o=!0,I=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),E==null&&(E=[1,1,1]),R(I.rank===5,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+I.rank+"."}),R(C==="NDHWC",function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+C}),R(rg(B,E),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+E+"'"}),w!=null&&R(JB(Q),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+w+" but got pad "+Q+"."});var n=ne(I.shape,g,B,E,Q,w,C),i=b.runKernelFunc(function(Y,M){var c=Y.maxPool3d(I,n);return M([I,c]),c},{x:I},function(Y,M){var c=M[0],D=M[1];return{x:function(){return function(r,F,s,u,a,U,G,d){var H=J(r,"dy","maxPool3dBackprop"),h=J(F,"input","maxPool3dBackprop"),l=J(s,"output","maxPool3dBackprop"),m=H,f=h,W=l,N=!1;h.rank===4&&(N=!0,m=H.as5D(1,H.shape[0],H.shape[1],H.shape[2],H.shape[3]),f=h.as5D(1,h.shape[0],h.shape[1],h.shape[2],h.shape[3]),W=l.as5D(1,l.shape[0],l.shape[1],l.shape[2],l.shape[3])),R(m.rank===5,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+m.rank+"."}),R(f.rank===5,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+f.rank+"."}),R(W.rank===5,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+W.rank+"."}),U==null&&(U=[1,1,1]),R(rg(a,U),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+U+"'"}),d!=null&&R(JB(G),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+d+" but got pad "+G+"."});var v=ne(f.shape,u,a,U,G,d),y=b.runKernelFunc(function(k){return k.maxPool3dBackprop(m,f,W,v)},{dy5D:m,input5D:f});return N?y.as4D(y.shape[1],y.shape[2],y.shape[3],y.shape[4]):y}(Y,c,D,g,B,E,Q,w)}}});return o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),Pm=z({avgPool3d_:function(A,g,B,Q,w,C,E){C===void 0&&(C="NDHWC");var e=J(A,"x","avgPool3d","float32"),I=e,o=!1;e.rank===4&&(o=!0,I=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),E==null&&(E=[1,1,1]),R(I.rank===5,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+I.rank+"."}),R(C==="NDHWC",function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+C}),R(rg(B,E),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+B+" and dilations '"+E+"'"}),w!=null&&R(JB(Q),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+w+" but got pad "+Q+"."});var n=ne(I.shape,g,B,E,Q,w,C),i=b.runKernelFunc(function(Y){return Y.avgPool3d(I,n)},{x:I},function(Y){return{x:function(){return function(M,c,D,r,F,s,u){var a=J(M,"dy","avgPool3dBackprop"),U=J(c,"input","avgPool3dBackprop"),G=a,d=U,H=!1;U.rank===4&&(H=!0,G=a.as5D(1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]),d=U.as5D(1,U.shape[0],U.shape[1],U.shape[2],U.shape[3])),R(G.rank===5,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+G.rank+"."}),R(d.rank===5,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+d.rank+"."}),F==null&&(F=[1,1,1]),R(rg(r,F),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+F+"'"}),u!=null&&R(JB(s),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+s+"."});var h=ne(d.shape,D,r,F,s,u),l=b.runKernelFunc(function(m){return m.avgPool3dBackprop(G,d,h)},{dy5D:G,input5D:d});return H?l.as4D(l.shape[1],l.shape[2],l.shape[3],l.shape[4]):l}(Y,I,g,B,E,Q,w)}}});return i=i.cast(I.dtype),o?i.as4D(i.shape[1],i.shape[2],i.shape[3],i.shape[4]):i}}),QQ=z({slice_:function(A,g,B){var Q,w,C=J(A,"x","slice");if(C.rank===0)throw new Error("Slicing scalar is not possible");(Q=typeof g=="number"?[g].concat(new Array(C.rank-1).fill(0)):g.length<C.rank?g.concat(new Array(C.rank-g.length).fill(0)):g.slice()).forEach(function(I){R(I!==-1,function(){return"slice() does not support negative begin indexing."})}),w=(w=B==null?new Array(C.rank).fill(-1):typeof B=="number"?[B].concat(new Array(C.rank-1).fill(-1)):B.length<C.rank?B.concat(new Array(C.rank-B.length).fill(-1)):B).map(function(I,o){return I>=0?I:(R(I===-1,function(){return"Negative size values should be exactly -1 but got "+I+" for the slice() size at index "+o+"."}),C.shape[o]-Q[o])}),Ef(C,Q,w);var E=C.shape,e={begin:Q,size:w};return b.runKernelFunc(function(I){return I.slice(C,Q,w)},{x:C},function(I){for(var o=[],n=0;n<I.rank;n++)o.push([Q[n],E[n]-Q[n]-w[n]]);return{x:function(){return I.pad(o)}}},"Slice",e)}}),vm=z({slice1d_:function(A,g,B){var Q=J(A,"x","slice1d");return R(Q.rank===1,function(){return"slice1d expects a rank-1 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,[g],[B])}}),km=z({slice2d_:function(A,g,B){var Q=J(A,"x","slice2d");return R(Q.rank===2,function(){return"slice2d expects a rank-2 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}}),HD=z({slice3d_:function(A,g,B){var Q=J(A,"x","slice3d");return R(Q.rank===3,function(){return"slice3d expects a rank-3 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}}),Tm=z({slice4d_:function(A,g,B){var Q=J(A,"x","slice4d");return R(Q.rank===4,function(){return"slice4d expects a rank-4 tensor, but got a rank-"+Q.rank+" tensor"}),QQ(Q,g,B)}});function fD(A,g,B,Q,w){return g.rank<B.rank&&(g=g.reshape(cg(g.shape,Q))),A.rank<B.rank&&(A=A.reshape(cg(A.shape,Q))),{x:function(){var C=A.mul(B.equal(g).cast(A.dtype));return w==null?C:C.transpose(w)}}}var jm=z({all_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","all","bool"),w=TB(g,Q.shape),C=w,E=$g(C,Q.rank);E!=null&&(Q=Q.transpose(E),C=AQ(C.length,Q.rank));var e=b.runKernelFunc(function(o){return o.all(Q,C)},{$x:Q});if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),pm=z({any_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","any","bool"),w=TB(g,Q.shape),C=w,E=$g(C,Q.rank);E!=null&&(Q=Q.transpose(E),C=AQ(C.length,Q.rank));var e=b.runKernelFunc(function(o){return o.any(Q,C)},{$x:Q});if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),ym=z({argMax_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","argMax");g==null&&(g=0);var Q=TB(g,B.shape),w=$g(Q,B.rank);w!=null&&(B=B.transpose(w),Q=AQ(Q.length,B.rank));var C={axis:Q[0]},E=[B];return b.runKernelFunc(function(e,I){var o=e.argMax(B,Q[0]);return I([B]),o},{x:B},function(e,I){var o=I[0];return{x:function(){return $A(o)}}},"ArgMax",C,E)}}),zm=z({argMin_:function(A,g){g===void 0&&(g=0);var B=J(A,"x","argMin");g==null&&(g=0);var Q=TB(g,B.shape),w=$g(Q,B.rank);return w!=null&&(B=B.transpose(w),Q=AQ(Q.length,B.rank)),b.runKernelFunc(function(C,E){var e=C.argMin(B,Q[0]);return E([B]),e},{$x:B},function(C,E){var e=E[0];return{$x:function(){return $A(e)}}})}}),Wm=z({logSumExp_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","logSumExp"),w=TB(g,Q.shape),C=Q.max(w,!0),E=Q.sub(C).exp().sum(w).log(),e=C.reshape(E.shape).add(E);if(B){var I=cg(e.shape,w);return e.reshape(I)}return e}}),le=z({max_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","max"),w=Q,C=TB(g,Q.shape),E=C,e=$g(E,Q.rank);e!=null&&(Q=Q.transpose(e),E=AQ(E.length,Q.rank));var I=[Q],o=b.runKernelFunc(function(i,Y){var M=i.max(Q,E);return Y([w,M]),M},{x:Q},function(i,Y){return fD(i,Y[1],Y[0],C,e)},"Max",{axes:E},I,[!0]);if(B){var n=cg(o.shape,C);o=o.reshape(n)}return o}}),Sm=z({mean_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","mean"),w=TB(g,Q.shape),C=hA(gg(Q.shape,w)[1]);return te(function(E){var e=nA(C);return{value:(e.dtype===E.dtype?E:E.cast(e.dtype)).div(e).sum(g,B),gradFunc:function(I){var o=E.shape.slice();return w.forEach(function(n){o[n]=1}),I.reshape(o).mul(zw(E.shape,"float32")).div(C)}}})(Q)}}),Lm=z({min_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","min"),w=Q,C=TB(g,Q.shape),E=C,e=$g(E,Q.rank);e!=null&&(Q=Q.transpose(e),E=AQ(E.length,Q.rank));var I=[Q],o=b.runKernelFunc(function(i,Y){var M=i.min(Q,E);return Y([w,M]),M},{x:Q},function(i,Y){return fD(i,Y[1],Y[0],C,e)},"Min",{axes:E},I,[!0]);if(B){var n=cg(o.shape,C);o=o.reshape(n)}return o}}),bm=z({moments_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=TB(g,(A=J(A,"x","moments")).shape),w=A.mean(Q,B),C=w.shape;B||(C=cg(w.shape,Q));var E=A.toFloat().sub(w.reshape(C)).square();return{mean:w,variance:E.mean(Q,B)}}}),JD=z({sum_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","sum");Q.dtype==="bool"&&(Q=Q.toInt());var w=TB(g,Q.shape);return te(function(C){var E=$g(w,C.rank),e=w,I=C;E!=null&&(I=C.transpose(E),e=AQ(e.length,C.rank));var o=function(M){var c=C.shape.slice();return w.forEach(function(D){c[D]=1}),M.reshape(c).mul(zw(C.shape,"float32"))},n={axes:e},i=b.runKernelFunc(function(M){return M.sum(I,e)},{x:I},function(M){return{x:function(){return o(M)}}},"Sum",n);if(B){var Y=cg(i.shape,w);i=i.reshape(Y)}return{value:i,gradFunc:o}})(Q)}}),Km=z({prod_:function(A,g,B){g===void 0&&(g=null),B===void 0&&(B=!1);var Q=J(A,"x","prod");Q.dtype==="bool"&&(Q=Q.toInt());var w=TB(g,Q.shape),C=$g(w,Q.rank),E=w,e=Q;C!=null&&(e=Q.transpose(C),E=AQ(E.length,Q.rank));var I=b.runKernelFunc(function(n){return n.prod(e,E)},{permutedX:e});if(B){var o=cg(I.shape,w);I=I.reshape(o)}return I}}),ND=z({elu_:function(A){var g=J(A,"x","elu");return b.runKernelFunc(function(B,Q){var w=B.elu(g);return Q([w]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){return b.runKernelFunc(function(C){return C.eluDer(B,w)},{dy:B,y:w})}}})}}),Vm=z({leakyRelu_:function(A,g){g===void 0&&(g=.2);var B=J(A,"x","leakyRelu");return Gt(nA(g).mul(B),B)}}),mD=z({prelu_:function(A,g){var B=J(A,"x","prelu"),Q=J(g,"alpha","prelu");return b.runKernelFunc(function(w,C){var E=w.prelu(B,Q);return C([B,Q]),E},{x:B,alpha:Q},function(w,C){var E=C[0],e=C[1],I=E.greater(0);return{x:function(){return Iw(I,w,w.mul(e))},alpha:function(){var o=Iw(I,$A(w),w.mul(E)),n=yB(e.shape,w.shape);return n.length>0&&(o=o.sum(n)),o.reshape(e.shape)}}},"Prelu")}}),GB=z({relu_:function(A){var g=J(A,"x","relu");return g.dtype==="bool"?g.toInt():b.runKernelFunc(function(B,Q){var w=B.relu(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0];return{x:function(){return B.mulStrict(w.step().toFloat())}}},"Relu")}}),RD=z({relu6_:function(A){var g=J(A,"x","relu6");return g.dtype==="bool"?g.toInt():b.runKernelFunc(function(B,Q){var w=B.relu6(g);return Q([g]),w},{x:g},function(B,Q){var w=Q[0],C=w.lessEqual(6).mul(w.step());return{x:function(){return B.mulStrict(C.toFloat())}}},"Relu6")}}),xm=z({selu_:function(A){var g=J(A,"x","selu");return b.runKernelFunc(function(B,Q){var w=B.selu(g);return Q([g]),w},{$x:g},function(B,Q){var w=Q[0];return{$x:function(){var C=w.greater(nA(0)),E=nA(at),e=nA(st),I=B.mul(e),o=B.mul(E).mul(w.toFloat().exp());return Iw(C,I,o)}}})}}),vQ=z({transpose_:function(A,g){var B=J(A,"x","transpose");if(g==null&&(g=B.shape.map(function(w,C){return C}).reverse()),R(B.rank===g.length,function(){return"Error in transpose: rank of input "+B.rank+" must match length of perm "+g+"."}),g.forEach(function(w){R(w>=0&&w<B.rank,function(){return"All entries in 'perm' must be between 0 and "+(B.rank-1)+" but got "+g})}),B.rank<=1)return B.clone();var Q={perm:g};return b.runKernelFunc(function(w){return w.transpose(B,g)},{x:B},function(w){var C=_o(g);return{x:function(){return w.transpose(C)}}},"Transpose",Q)}}),Xm=z({localResponseNormalization_:function(A,g,B,Q,w){g===void 0&&(g=5),B===void 0&&(B=1),Q===void 0&&(Q=1),w===void 0&&(w=.5);var C=J(A,"x","localResponseNormalization");R(C.rank===4||C.rank===3,function(){return`Error in localResponseNormalization: x must be rank 3 or 4 but got
3761
+ rank `+C.rank+"."}),R(JB(g),function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+g+"."});var E=C,e=!1;C.rank===3&&(e=!0,E=C.as4D(1,C.shape[0],C.shape[1],C.shape[2]));var I=b.runKernelFunc(function(o,n){var i=o.localResponseNormalization4D(E,g,B,Q,w);return n([E,i]),i},{x4D:E},function(o,n){var i=n[0],Y=n[1];return{x4D:function(){return b.runKernelFunc(function(M){return M.LRNGrad(o,i,Y,g,B,Q,w)},{})}}});return e?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),PD=z({norm_:function(A,g,B,Q){g===void 0&&(g="euclidean"),B===void 0&&(B=null),Q===void 0&&(Q=!1);var w=function e(I,o,n){if(n===void 0&&(n=null),I.rank===0)return I.abs();if(I.rank!==1&&n===null)return e(I.reshape([-1]),o,n);if(I.rank===1||typeof n=="number"||Array.isArray(n)&&n.length===1){if(o===1)return I.abs().sum(n);if(o===1/0)return I.abs().max(n);if(o===-1/0)return I.abs().min(n);if(o==="euclidean"||o===2)return I.abs().pow(nA(2,"int32")).sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+o)}if(Array.isArray(n)&&n.length===2){if(o===1)return I.abs().sum(n[0]).max(n[1]-1);if(o===1/0)return I.abs().sum(n[1]).max(n[0]);if(o===-1/0)return I.abs().sum(n[1]).min(n[0]);if(o==="fro"||o==="euclidean")return I.square().sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+o)}throw new Error("Error in norm: invalid axis: "+n)}(A=J(A,"x","norm"),g,B),C=w.shape;if(Q){var E=TB(B,A.shape);C=cg(w.shape,E)}return w.reshape(C)}}),Om=z({basicLSTMCell_:function(A,g,B,Q,w,C){var E=J(A,"forgetBias","basicLSTMCell"),e=J(g,"lstmKernel","basicLSTMCell"),I=J(B,"lstmBias","basicLSTMCell"),o=J(Q,"data","basicLSTMCell"),n=J(w,"c","basicLSTMCell"),i=J(C,"h","basicLSTMCell"),Y=o.concat(i,1).matMul(e).add(I),M=Y.shape[0],c=Y.shape[1]/4,D=[M,c],r=Y.slice([0,0],D),F=Y.slice([0,c],D),s=Y.slice([0,2*c],D),u=Y.slice([0,3*c],D),a=r.sigmoid().mulStrict(F.tanh()).addStrict(n.mulStrict(E.add(s).sigmoid())),U=a.tanh().mulStrict(u.sigmoid());return[a,U]}}),Zm=z({multiRNNCell_:function(A,g,B,Q){for(var w=J(g,"data","multiRNNCell"),C=Qe(B,"c","multiRNNCell"),E=Qe(Q,"h","multiRNNCell"),e=w,I=[],o=0;o<A.length;o++){var n=A[o](e,C[o],E[o]);I.push(n[0]),I.push(n[1]),e=n[1]}var i=[],Y=[];for(o=0;o<I.length;o+=2)i.push(I[o]),Y.push(I[o+1]);return[i,Y]}}),qm=z({movingAverage_:function(A,g,B,Q,w){w===void 0&&(w=!0);var C=J(A,"v","movingAverage"),E=J(g,"x","movingAverage"),e=J(B,"decay","movingAverage");xd(C,E),R(KB(C.shape,E.shape),function(){return"Shape mismatch in v and x"});var I=nA(1),o=I.sub(e),n=E.sub(C).mul(o);if(w){R(Q!=null,function(){return"When using zeroDebias: true, step is required."});var i=J(Q,"step","movingAverage");n=n.div(I.sub(Ue(e,i)))}return C.add(n)}}),_m=z({stridedSlice_:function(A,g,B,Q,w,C,E,e,I){if(w===void 0&&(w=0),C===void 0&&(C=0),E===void 0&&(E=0),e===void 0&&(e=0),I===void 0&&(I=0),Q==null&&(Q=new Array(g.length)),E!==0)throw new Error("ellipsis mask is not yet supported");var o=J(A,"x","stridedSlice"),n=Dc(e),i=o.shape.slice();n.forEach(function(r){g[r]=0,B[r]=1,i.splice(r,0,1)}),o=o.reshape(i);for(var Y=0;Y<o.rank;Y++)g[Y]=ef(w,g,Q,o.shape,Y),B[Y]=If(C,B,Q,o.shape,Y),Q[Y]=Q[Y]||1;var M=Dc(I);M.forEach(function(r){B[r]=g[r]+1,Q[r]=1});var c=wt(g,B,Q),D=c.filter(function(r,F){return M.indexOf(F)===-1});return Q.every(function(r){return r===1})?QQ(o,g,c).reshape(D):b.runKernelFunc(function(r){return r.stridedSlice(o,g,B,Q)},{$x:o}).reshape(D)}}),$m=z({topk_:function(A,g,B){g===void 0&&(g=1),B===void 0&&(B=!0);var Q=J(A,"x","topk");if(Q.rank===0)throw new Error("topk() expects the input to be of rank 1 or higher");var w=Q.shape[Q.shape.length-1];if(g>w)throw new Error("'k' passed to topk() must be <= the last dimension ("+w+") but got "+g);var C=b.runKernelFunc(function(E){return E.topk(Q,g,B)},{$x:Q});return{values:C[0],indices:C[1]}}}),A0=z({scatterND_:function(A,g,B){var Q=J(A,"indices","scatterND","int32"),w=J(g,"updates","scatterND");return Cf(w,Q,B),b.runKernelFunc(function(C){return C.scatterND(Q,w,B)},{indices:Q,updates:w},null,"ScatterNd",{shape:B})}}),ft=z({fft_:function(A){R(A.dtype==="complex64",function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+A.dtype+"."});var g=A.shape[A.shape.length-1],B=A.size/g,Q=A.as2D(B,g);return b.runKernelFunc(function(w){return w.fft(Q)},{input:A}).reshape(A.shape)}}),de=z({ifft_:function(A){R(A.dtype==="complex64",function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+A.dtype+"."});var g=A.shape[A.shape.length-1],B=A.size/g,Q=A.as2D(B,g);return b.runKernelFunc(function(w){return w.ifft(Q)},{input:A}).reshape(A.shape)}}),Jt=z({rfft_:function(A,g){R(A.dtype==="float32",function(){return"The dtype for rfft() must be real value but got "+A.dtype});var B,Q=A.shape[A.shape.length-1],w=A.size/Q;if(g!=null&&g<Q){var C=A.shape.map(function(F){return 0}),E=A.shape.map(function(F){return F});E[A.shape.length-1]=g,B=A.slice(C,E),Q=g}else if(g!=null&&g>Q){var e=A.shape.map(function(F){return F});e[A.shape.length-1]=g-Q,B=A.concat(DB(e),A.shape.length-1),Q=g}else B=A;var I=B.zerosLike(),o=$B(B,I).as2D(w,Q),n=ft(o),i=Math.floor(Q/2)+1,Y=kg(n),M=BQ(n),c=Y.split([i,Q-i],Y.shape.length-1),D=M.split([i,Q-i],M.shape.length-1),r=B.shape.slice();return r[B.shape.length-1]=i,$B(c[0],D[0]).reshape(r)}}),vD=z({irfft_:function(A){var g=A.shape[A.shape.length-1],B=A.size/g;if(g<=2){var Q=A.as2D(B,g),w=de(Q);return kg(w)}var C=[B,2*(g-1)],E=kg(A).as2D(B,g),e=BQ(A).as2D(B,g),I=E.slice([0,1],[B,g-2]).reverse(1),o=e.slice([0,1],[B,g-2]).reverse(1).mul(nA(-1)),n=E.concat(I,1),i=e.concat(o,1);return Q=$B(n,i).as2D(C[0],C[1]),w=de(Q),kg(w)}}),B0=Object.freeze({fft:ft,ifft:de,rfft:Jt,irfft:vD}),g0=z({sparseToDense_:function(A,g,B,Q){Q===void 0&&(Q=0);var w=J(A,"sparseIndices","sparseToDense","int32"),C=J(g,"sparseValues","sparseToDense"),E=J(Q,"defaultValue","sparseToDense",C.dtype);return function(e,I,o,n){if(e.dtype!=="int32")throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+e.dtype+".");if(e.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+e.shape+".");var i=e.rank>0?e.shape[0]:1,Y=e.rank>1?e.shape[1]:1;if(o.length!==Y)throw new Error("outputShape has incorrect number of elements:, "+o.length+", should be: "+Y+".");var M=I.size;if(I.rank!==0&&(I.rank!==1||M!==i))throw new Error("sparseValues has incorrect shape "+I.shape+", should be [] or ["+i+"]");if(I.dtype!==n.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(w,C,B,E),b.runKernelFunc(function(e){return e.sparseToDense(w,C,B,E)},{$sparseIndices:w,$sparseValues:C,$defaultValue:E})}}),Q0=z({gatherND_:function(A,g){var B=J(g,"indices","gatherND","int32"),Q=J(A,"x","gatherND");return b.runKernelFunc(function(w){return w.gatherND(Q,B)},{x:Q,indices:B},null,"GatherNd")}}),w0=z({diag_:function(A){var g=J(A,"x","diag").flatten(),B=A.shape.concat(A.shape);return b.runKernelFunc(function(Q){return Q.diag(g)},{$x:g}).reshape(B)}}),C0=z({dropout_:function(A,g,B,Q){var w=J(A,"x","dropout");if(R(w.dtype==="float32",function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+w.dtype+" tensor instead."}),R(g>=0&&g<1,function(){return"rate must be a float in the range [0, 1), but got "+g+"."}),g===0)return A instanceof uB?w.clone():w;var C=function(I,o){if(o==null)return I.shape.slice();if(KB(I.shape,o))return o;if(I.shape.length===o.length){for(var n=[],i=0;i<I.shape.length;i++)o[i]==null&&I.shape[i]!=null?n.push(I.shape[i]):n.push(o[i]);return n}return o}(w,B),E=1-g,e=oc(C,0,1,"float32",Q).add(E).floor().div(E);return w.mul(e)}});function kD(A,g,B){for(var Q=1-A%2,w=new Float32Array(A),C=0;C<A;++C){var E=2*Math.PI*C/(A+Q-1);w[C]=g-B*Math.cos(E)}return PB(w,"float32")}var Nt=z({hannWindow_:function(A){return kD(A,.5,.5)}}),TD=z({hammingWindow_:function(A){return kD(A,.54,.46)}}),mt=z({frame_:function(A,g,B,Q,w){Q===void 0&&(Q=!1),w===void 0&&(w=0);for(var C=0,E=[];C+g<=A.size;)E.push(QQ(A,C,g)),C+=B;if(Q)for(;C<A.size;){var e=C+g-A.size,I=jB([QQ(A,C,g-e),gQ([e],w)]);E.push(I),C+=B}return E.length===0?RQ([],[0,g]):jB(E).as2D(E.length,g)}}),jD=z({stft_:function(A,g,B,Q,w){var C;w===void 0&&(w=Nt),Q==null&&(C=g,Q=Math.floor(Math.pow(2,Math.ceil(Math.log(C)/Math.log(2)))));for(var E=mt(A,g,B),e=wg(E,w(g)),I=[],o=0;o<E.shape[0];o++)I.push(Jt(e.slice([o,0],[1,g]),Q));return jB(I)}}),E0=Object.freeze({hannWindow:Nt,hammingWindow:TD,frame:mt,stft:jD}),Cg,e0=function(A,g,B){return B===void 0&&(B=1),uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i,Y,M,c,D,r;return UA(this,function(F){switch(F.label){case 0:return Q=J(A,"predictions","inTopK"),w=J(g,"targets","inTopK"),R(Q.rank>1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+Q.rank}),R(Q.rank-1===w.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+Q.rank+" and targets rank "+w.rank}),eB(Q.shape.slice(0,Q.shape.length-1),w.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),C=Q.shape[Q.shape.length-1],R(B>0&&B<=C,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+C+"), but got "+B}),[4,Q.data()];case 1:return E=F.sent(),[4,w.data()];case 2:for(e=F.sent(),I=[E.length/C,C],n=I[1],i=dC("bool",o=I[0]),Y=0;Y<o;Y++){for(M=Y*n,c=E.subarray(M,M+n),D=[],r=0;r<c.length;r++)D.push({value:c[r],index:r});for(D.sort(function(s,u){return u.value-s.value}),i[Y]=0,r=0;r<B;r++)if(D[r].index===e[Y]){i[Y]=1;break}}return A!==Q&&Q.dispose(),g!==w&&w.dispose(),[2,Ag(i,w.shape,"bool")]}})})};(function(A){A[A.NONE=0]="NONE",A[A.MEAN=1]="MEAN",A[A.SUM=2]="SUM",A[A.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"})(Cg||(Cg={}));var I0=z({absoluteDifference_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","absoluteDifference"),C=J(g,"predictions","absoluteDifference"),E=null;B!=null&&(E=J(B,"weights","absoluteDifference")),eB(w.shape,C.shape,"Error in absoluteDifference: ");var e=w.sub(C).abs();return aQ(e,E,Q)}}),aQ=z({computeWeightedLoss_:function(A,g,B){B===void 0&&(B=Cg.SUM_BY_NONZERO_WEIGHTS);var Q=J(A,"losses","computeWeightedLoss"),w=null;g!=null&&(w=J(g,"weights","computeWeightedLoss"));var C=w==null?Q:Q.mul(w);if(B===Cg.NONE)return C;if(B===Cg.SUM)return C.sum();if(B===Cg.MEAN){if(w==null)return C.mean();var E=Q.size/w.size,e=C.sum().div(w.sum());return E>1?e.div(nA(E)):e}if(B===Cg.SUM_BY_NONZERO_WEIGHTS){if(w==null)return C.sum().div(nA(Q.size));var I=w.mul(zw(Q.shape)).notEqual(nA(0)).sum().toFloat();return C.sum().div(I)}throw Error("Unknown reduction: "+B)}}),o0=z({cosineDistance_:function(A,g,B,Q,w){w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","cosineDistance"),E=J(g,"predictions","cosineDistance"),e=null;Q!=null&&(e=J(Q,"weights","cosineDistance")),eB(C.shape,E.shape,"Error in cosineDistance: ");var I=nA(1).sub(C.mul(E).sum(B,!0));return aQ(I,e,w)}}),t0=z({hingeLoss_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","hingeLoss"),C=J(g,"predictions","hingeLoss"),E=null;B!=null&&(E=J(B,"weights","hingeLoss")),eB(w.shape,C.shape,"Error in hingeLoss: ");var e=nA(1);w=nA(2).mul(w).sub(e);var I=e.sub(w.mul(C)).relu();return aQ(I,E,Q)}}),n0=z({huberLoss_:function(A,g,B,Q,w){Q===void 0&&(Q=1),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","huberLoss"),E=J(g,"predictions","huberLoss"),e=null;B!=null&&(e=J(B,"weights","huberLoss")),eB(C.shape,E.shape,"Error in huberLoss: ");var I=nA(Q),o=E.sub(C).abs(),n=MD(o,I),i=o.sub(n),Y=nA(.5).mul(n.square()).add(I.mul(i));return aQ(Y,e,w)}}),i0=z({logLoss_:function(A,g,B,Q,w){Q===void 0&&(Q=1e-7),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"labels","logLoss"),E=J(g,"predictions","logLoss"),e=null;B!=null&&(e=J(B,"weights","logLoss")),eB(C.shape,E.shape,"Error in logLoss: ");var I=nA(1),o=nA(Q),n=C.mul(E.add(o).log()).neg().sub(I.sub(C).mul(I.sub(E).add(o).log()));return aQ(n,e,w)}}),Y0=z({meanSquaredError_:function(A,g,B,Q){Q===void 0&&(Q=Cg.SUM_BY_NONZERO_WEIGHTS);var w=J(A,"labels","meanSquaredError"),C=J(g,"predictions","meanSquaredError"),E=null;B!=null&&(E=J(B,"weights","meanSquaredError")),eB(w.shape,C.shape,"Error in meanSquaredError: ");var e=w.squaredDifference(C);return aQ(e,E,Q)}}),M0=z({sigmoidCrossEntropy_:function(A,g,B,Q,w){Q===void 0&&(Q=0),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"multiClassLabels","sigmoidCrossEntropy"),E=J(g,"logits","sigmoidCrossEntropy"),e=null;if(B!=null&&(e=J(B,"weights","sigmoidCrossEntropy")),eB(C.shape,E.shape,"Error in sigmoidCrossEntropy: "),Q>0){var I=nA(Q),o=nA(1),n=nA(.5);C=C.mul(o.sub(I)).add(n.mul(I))}var i=function(Y,M){var c=J(Y,"labels","sigmoidCrossEntropyWithLogits"),D=J(M,"logits","sigmoidCrossEntropyWithLogits");eB(c.shape,D.shape,"Error in sigmoidCrossEntropyWithLogits: ");var r=D.relu(),F=D.mul(c),s=D.abs().neg().exp().log1p();return r.sub(F).add(s)}(C,E);return aQ(i,e,w)}}),c0=z({softmaxCrossEntropy_:function(A,g,B,Q,w){Q===void 0&&(Q=0),w===void 0&&(w=Cg.SUM_BY_NONZERO_WEIGHTS);var C=J(A,"onehotLabels","softmaxCrossEntropy"),E=J(g,"logits","softmaxCrossEntropy"),e=null;if(B!=null&&(e=J(B,"weights","softmaxCrossEntropy")),eB(C.shape,E.shape,"Error in softmaxCrossEntropy: "),Q>0){var I=nA(Q),o=nA(1),n=nA(C.shape[1]);C=C.mul(o.sub(I)).add(I.div(n))}var i=function(Y,M,c){if(c===void 0&&(c=-1),c===-1&&(c=M.rank-1),c!==M.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+M.rank+" and dim was "+c);return te(function(D,r,F){var s=r.logSumExp([c],!0),u=r.toFloat().sub(s);return F([D,u]),{value:u.mul(D).neg().sum([c]),gradFunc:function(a,U){var G=U[0],d=U[1],H=cg(a.shape,[c]);return[a.reshape(H).mul(G.toFloat().sub(d.exp())),a.reshape(H).mul(d.exp().sub(G.toFloat()))]}}})(Y,M)}(C,E);return aQ(i,e,w)}}),D0=Object.freeze({get Reduction(){return Cg},absoluteDifference:I0,computeWeightedLoss:aQ,cosineDistance:o0,hingeLoss:t0,huberLoss:n0,logLoss:i0,meanSquaredError:Y0,sigmoidCrossEntropy:M0,softmaxCrossEntropy:c0});function pD(A,g){return g===void 0&&(g=!1),b.tidy(function(){if(A.shape.length!==2)throw new Error("qr2d() requires a 2D Tensor, but got a "+A.shape.length+"D Tensor.");for(var B=A.shape[0],Q=A.shape[1],w=Ic(B),C=A.clone(),E=RQ([[1]],[1,1]),e=E.clone(),I=B>=Q?Q:B,o=function(i){var Y,M=C,c=e,D=w;Y=b.tidy(function(){var r=C.slice([i,i],[B-i,1]),F=r.norm(),s=C.slice([i,i],[1,1]),u=RQ([[-1]]).where(s.greater(0),RQ([[1]])),a=s.sub(u.mul(F)),U=r.div(a);e=U.shape[0]===1?E.clone():E.concat(U.slice([1,0],[U.shape[0]-1,U.shape[1]]),0);var G=u.matMul(a).div(F).neg(),d=C.slice([i,0],[B-i,Q]),H=G.mul(e);if(i===0)C=d.sub(H.matMul(e.transpose().matMul(d)));else{var h=d.sub(H.matMul(e.transpose().matMul(d)));C=C.slice([0,0],[i,Q]).concat(h,0)}var l=w.slice([0,i],[B,w.shape[1]-i]);if(i===0)w=l.sub(l.matMul(e).matMul(H.transpose()));else{var m=l.sub(l.matMul(e).matMul(H.transpose()));w=w.slice([0,0],[B,i]).concat(m,1)}return[e,C,w]}),e=Y[0],C=Y[1],w=Y[2],Mg([M,c,D])},n=0;n<I;++n)o(n);return!g&&B>Q&&(w=w.slice([0,0],[B,Q]),C=C.slice([0,0],[Q,Q])),[w,C]})}var r0=z({bandPart_:function(A,g,B){if(g%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+g+".");if(B%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+B+".");var Q=J(A,"a","bandPart");if(Q.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+Q.rank+".");var w=Q.shape,C=Q.shape.slice(-2),E=C[0],e=C[1];if(!(g<=E))throw new Error("bandPart(): numLower ("+g+") must not be greater than the number of rows ("+E+").");if(!(B<=e))throw new Error("bandPart(): numUpper ("+B+") must not be greater than the number of columns ("+e+").");g<0&&(g=E),B<0&&(B=e);var I=we(0,E,1,"int32").reshape([-1,1]),o=we(0,e,1,"int32"),n=zB(I,o),i=ue(n.lessEqual(nA(+g,"int32")),n.greaterEqual(nA(-B,"int32"))),Y=DB([E,e],Q.dtype);return Hg(pB(Q.reshape([-1,E,e])).map(function(M){return Iw(i,M,Y)})).reshape(w)}}),F0=z({gramSchmidt_:function(A){var g;if(Array.isArray(A)){g=!1,R(A!=null&&A.length>0,function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"});for(var B=A[0].shape[0],Q=function(I){R(A[I].shape[0]===B,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+A[I].shape[0]+" vs. "+B+")"})},w=1;w<A.length;++w)Q(w)}else g=!0,A=At(A,A.shape[0],0).map(function(I){return nc(I,[0])});R(A.length<=A[0].shape[0],function(){return"Gram-Schmidt: Number of vectors ("+A.length+") exceeds number of dimensions ("+A[0].shape[0]+")."});var C=[],E=A,e=function(I){C.push(b.tidy(function(){var o=E[I];if(I>0)for(var n=0;n<I;++n){var i=JD(C[n].mulStrict(o)).mul(C[n]);o=o.sub(i)}return o.div(PD(o,"euclidean"))}))};for(w=0;w<A.length;++w)e(w);return g?Hg(C,0):C}}),a0=z({qr_:function(A,g){if(g===void 0&&(g=!1),A.rank<2)throw new Error("qr() requires input tensor to have a rank >= 2, but got rank "+A.rank);if(A.rank===2)return pD(A,g);var B=A.shape.slice(0,A.shape.length-2).reduce(function(E,e){return E*e}),Q=pB(A.reshape([B,A.shape[A.shape.length-2],A.shape[A.shape.length-1]]),0),w=[],C=[];return Q.forEach(function(E){var e=pD(E,g),I=e[0],o=e[1];w.push(I),C.push(o)}),[Hg(w,0).reshape(A.shape),Hg(C,0).reshape(A.shape)]}}),s0=Object.freeze({bandPart:r0,gramSchmidt:F0,qr:a0});function He(A,g,B,Q,w,C){Q==null&&(Q=.5),w==null&&(w=Number.NEGATIVE_INFINITY),C==null&&(C=0);var E=A.shape[0];return B=Math.min(B,E),R(0<=Q&&Q<=1,function(){return"iouThreshold must be in [0, 1], but was '"+Q+"'"}),R(A.rank===2,function(){return"boxes must be a 2D tensor, but was of rank '"+A.rank+"'"}),R(A.shape[1]===4,function(){return"boxes must have 4 columns, but 2nd dimension was "+A.shape[1]}),R(g.rank===1,function(){return"scores must be a 1D tensor"}),R(g.shape[0]===E,function(){return"scores has incompatible shape with boxes. Expected "+E+", but was "+g.shape[0]}),R(0<=C&&C<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+C+"'"}),{maxOutputSize:B,iouThreshold:Q,scoreThreshold:w,softNmsSigma:C}}var u0=z({resizeBilinear_:function(A,g,B){B===void 0&&(B=!1);var Q=J(A,"images","resizeBilinear");R(Q.rank===3||Q.rank===4,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+Q.rank+"."}),R(g.length===2,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+g+"."});var w=Q,C=!1;Q.rank===3&&(C=!0,w=Q.as4D(1,Q.shape[0],Q.shape[1],Q.shape[2]));var E=g[0],e=g[1],I=b.runKernelFunc(function(o,n){return n([w]),o.resizeBilinear(w,E,e,B)},{x:w},function(o,n){return{x:function(){return b.runKernelFunc(function(i){return i.resizeBilinearBackprop(o,n[0],B)},{})}}},"ResizeBilinear",{alignCorners:B,newHeight:E,newWidth:e});return C?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),U0=z({resizeNearestNeighbor_:function(A,g,B){B===void 0&&(B=!1);var Q=J(A,"images","resizeNearestNeighbor");R(Q.rank===3||Q.rank===4,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+Q.rank+"."}),R(g.length===2,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+g+"."}),R(Q.dtype==="float32"||Q.dtype==="int32",function(){return"`images` must have `int32` or `float32` as dtype"});var w=Q,C=!1;Q.rank===3&&(C=!0,w=Q.as4D(1,Q.shape[0],Q.shape[1],Q.shape[2]));var E=g[0],e=g[1],I=b.runKernelFunc(function(o,n){return n([w]),o.resizeNearestNeighbor(w,E,e,B)},{batchImages:w},function(o,n){return{batchImages:function(){return b.runKernelFunc(function(i){return i.resizeNearestNeighborBackprop(o,n[0],B)},{})}}});return C?I.as3D(I.shape[1],I.shape[2],I.shape[3]):I}}),G0=z({nonMaxSuppression_:function(A,g,B,Q,w){Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY);var C=J(A,"boxes","nonMaxSuppression"),E=J(g,"scores","nonMaxSuppression"),e=He(C,E,B,Q,w);B=e.maxOutputSize,Q=e.iouThreshold,w=e.scoreThreshold;var I={maxOutputSize:B,iouThreshold:Q,scoreThreshold:w};return b.runKernelFunc(function(o){return o.nonMaxSuppression(C,E,B,Q,w)},{boxes:C,scores:E},null,"NonMaxSuppressionV3",I)}}),h0=function(A,g,B,Q,w){return Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),uA(this,void 0,void 0,function(){var C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return C=J(A,"boxes","nonMaxSuppressionAsync"),E=J(g,"scores","nonMaxSuppressionAsync"),e=He(C,E,B,Q,w),B=e.maxOutputSize,Q=e.iouThreshold,w=e.scoreThreshold,[4,Promise.all([C.data(),E.data()])];case 1:return I=Y.sent(),o=I[0],n=I[1],i=ot(o,n,B,Q,w),C!==A&&C.dispose(),E!==g&&E.dispose(),[2,i]}})})},l0=z({nonMaxSuppressionWithScore_:function(A,g,B,Q,w,C){Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),C===void 0&&(C=0);var E=J(A,"boxes","nonMaxSuppression"),e=J(g,"scores","nonMaxSuppression"),I=He(E,e,B,Q,w,C),o={maxOutputSize:B=I.maxOutputSize,iouThreshold:Q=I.iouThreshold,scoreThreshold:w=I.scoreThreshold,softNmsSigma:C=I.softNmsSigma},n=b.runKernel("NonMaxSuppressionV5",{boxes:E,scores:e},o);return{selectedIndices:n[0],selectedScores:n[1]}}}),d0=function(A,g,B,Q,w,C){return Q===void 0&&(Q=.5),w===void 0&&(w=Number.NEGATIVE_INFINITY),C===void 0&&(C=0),uA(this,void 0,void 0,function(){var E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:return E=J(A,"boxes","nonMaxSuppressionAsync"),e=J(g,"scores","nonMaxSuppressionAsync"),I=He(E,e,B,Q,w,C),B=I.maxOutputSize,Q=I.iouThreshold,w=I.scoreThreshold,C=I.softNmsSigma,[4,Promise.all([E.data(),e.data()])];case 1:return o=M.sent(),n=o[0],i=o[1],Y=tt(n,i,B,Q,w,C),E!==A&&E.dispose(),e!==g&&e.dispose(),[2,Y]}})})},H0=z({cropAndResize_:function(A,g,B,Q,w,C){var E=J(A,"image","cropAndResize"),e=J(g,"boxes","cropAndResize","float32"),I=J(B,"boxInd","cropAndResize","int32");w=w||"bilinear",C=C||0;var o=e.shape[0];return R(E.rank===4,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+E.rank+"."}),R(e.rank===2&&e.shape[1]===4,function(){return"Error in cropAndResize: boxes must be have size ["+o+",4] but had shape "+e.shape+"."}),R(I.rank===1&&I.shape[0]===o,function(){return"Error in cropAndResize: boxInd must be have size ["+o+"] but had shape "+e.shape+"."}),R(Q.length===2,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+Q.length+"."}),R(Q[0]>=1&&Q[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+Q}),R(w==="bilinear"||w==="nearest",function(){return"method must be bilinear or nearest, but was "+w}),b.runKernelFunc(function(n,i){return n.cropAndResize(E,e,I,Q,w,C)},{images:E,boxes:e,boxInd:I},null,"CropAndResize",{method:w,extrapolationValue:C,cropSize:Q})}}),Rt=Object.freeze({resizeBilinear:u0,resizeNearestNeighbor:U0,nonMaxSuppression:G0,nonMaxSuppressionAsync:h0,nonMaxSuppressionWithScore:l0,nonMaxSuppressionWithScoreAsync:d0,cropAndResize:H0}),Pt=function(A,g){return!(A>0)||g==="linear"},vt=function(A,g,B){if(B==null||B==="linear")return A;if(B==="relu")return A.mul(g.step());throw new Error("Gradient for activation "+B+" has not been implemented yet.")},kt=function(A,g){var B=g,Q=yB(A.shape,g.shape);return Q.length>0&&(B=B.sum(Q)),B.reshape(A.shape)},Tt=function(A,g,B){if(g==="linear")return A;if(g==="relu")return GB(A);if(g==="elu")return ND(A);if(g==="relu6")return RD(A);if(g==="prelu")return mD(A,B);throw new Error("Unknown fused activation "+g+".")},f0=z({fusedMatMul_:function(A){var g,B=A.a,Q=A.b,w=A.transposeA,C=w!==void 0&&w,E=A.transposeB,e=E!==void 0&&E,I=A.bias,o=A.activation,n=o===void 0?"linear":o,i=A.preluActivationWeights;if(Pt(b.state.gradientDepth,n)===!1){var Y=he(B,Q,C,e);return I!=null&&(Y=OA(Y,I)),Tt(Y,n,i)}var M=J(B,"a","fused matMul"),c=J(Q,"b","fused matMul");g=UB(M,c),M=g[0],c=g[1];var D=C?M.shape[M.rank-2]:M.shape[M.rank-1],r=e?c.shape[c.rank-1]:c.shape[c.rank-2],F=C?M.shape[M.rank-1]:M.shape[M.rank-2],s=e?c.shape[c.rank-2]:c.shape[c.rank-1],u=M.shape.slice(0,-2),a=c.shape.slice(0,-2),U=hA(u),G=hA(a);R(M.rank>=2&&c.rank>=2&&M.rank===c.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+M.rank+" and "+c.rank+"."}),R(KB(u,a),function(){return"Error in fused matMul: outer dimensions ("+u+") and ("+a+") of Tensors with shapes "+M.shape+" and "+c.shape+" must match."}),R(D===r,function(){return"Error in fused matMul: inner shapes ("+D+") and ("+r+") of Tensors with shapes "+M.shape+" and "+c.shape+" and transposeA="+C+" and transposeB="+e+" must match."});var d,H,h=M.shape.slice(0,-2).concat([F,s]),l=C?M.as3D(U,D,F):M.as3D(U,F,D),m=e?c.as3D(G,s,r):c.as3D(G,r,s);I!=null&&qA(h,(d=UB(d=J(I,"bias","fused matMul"),M)[0]).shape),i!=null&&(H=J(i,"prelu weights","fused matMul"));var f={a:l,b:m};I!=null&&(f.bias=d),i!=null&&(f.preluActivationWeights=H);var W=[l,m];return b.runKernelFunc(function(N,v){var y=N.fusedBatchMatMul({a:l,b:m,transposeA:C,transposeB:e,bias:d,activation:n,preluActivationWeights:H});return v([l,m,y]),y},f,function(N,v){var y=v[0],k=v[1],p=v[2],K=vt(N,p,n),V={};return I!=null&&(V={bias:function(){return kt(d,K)}}),Object.assign(C||e?!C&&e?{a:function(){return K.matMul(k,!1,!1)},b:function(){return K.matMul(y,!0,!1)}}:C&&!e?{a:function(){return k.matMul(K,!1,!0)},b:function(){return y.matMul(K,!1,!1)}}:{a:function(){return k.matMul(K,!0,!0)},b:function(){return K.matMul(y,!0,!0)}}:{a:function(){return K.matMul(k,!1,!0)},b:function(){return y.matMul(K,!0,!1)}},V)},"_FusedMatMul",{transposeA:C,transposeB:e,activation:n},W,[!0]).reshape(h)}}),J0=z({fusedConv2d_:function(A){var g=A.x,B=A.filter,Q=A.strides,w=A.pad,C=A.dataFormat,E=C===void 0?"NHWC":C,e=A.dilations,I=e===void 0?[1,1]:e,o=A.dimRoundingMode,n=A.bias,i=A.activation,Y=i===void 0?"linear":i,M=A.preluActivationWeights;if(Y=Y||"linear",Pt(b.state.gradientDepth,Y)===!1){var c=jg(g,B,Q,w,E,I,o);return n!=null&&(c=OA(c,n)),Tt(c,Y,M)}var D=J(g,"x","conv2d"),r=J(B,"filter","conv2d"),F=D,s=!1;D.rank===3&&(s=!0,F=D.as4D(1,D.shape[0],D.shape[1],D.shape[2])),R(F.rank===4,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+F.rank+"."}),R(r.rank===4,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+r.rank+"."}),o!=null&&R(JB(w),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+w+"."}),R(F.shape[3]===r.shape[2],function(){return"Error in conv2d: depth of input ("+F.shape[3]+") must match input depth for filter "+r.shape[2]+"."}),R(rg(Q,I),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+Q+" and dilations '"+I+"'"}),R(E==="NHWC",function(){return"Error in conv2d: got dataFormat of "+E+" but only NHWC is currently supported."});var u,a,U=Cw(F.shape,r.shape,Q,I,w,o);n!=null&&(u=UB(u=J(n,"bias","fused conv2d"),D)[0],qA(U.outShape,u.shape)),M!=null&&(a=J(M,"prelu weights","fused conv2d"));var G={x:F,filter:r};n!=null&&(G.bias=u),M!=null&&(G.preluActivationWeights=a);var d=[r,F],H=b.runKernelFunc(function(h,l){var m=h.fusedConv2d({input:F,filter:r,convInfo:U,bias:u,activation:Y,preluActivationWeights:a});return l([r,F,m]),m},G,function(h,l){var m=l,f=m[0],W=m[1],N=m[2],v=vt(h,N,Y);R(Lw(I),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+I+"'"});var y={};return n!=null&&(y={bias:function(){return kt(u,v)}}),Object.assign({x:function(){return UD(W.shape,v,f,Q,w)},filter:function(){return dt(W,v,f.shape,Q,w)}},y)},"FusedConv2D",{convInfo:U,activation:Y},d,[!0]);return s?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}}),N0=z({fusedDepthwiseConv2d_:function(A){var g=A.x,B=A.filter,Q=A.strides,w=A.pad,C=A.dataFormat,E=C===void 0?"NHWC":C,e=A.dilations,I=e===void 0?[1,1]:e,o=A.dimRoundingMode,n=A.bias,i=A.activation,Y=i===void 0?"linear":i,M=A.preluActivationWeights;if(Pt(b.state.gradientDepth,Y)===!1){var c=Ge(g,B,Q,w,E,I,o);return n!=null&&(c=OA(c,n)),Tt(c,Y,M)}var D=J(g,"x","depthwiseConv2d"),r=J(B,"filter","depthwiseConv2d"),F=D,s=!1;D.rank===3&&(s=!0,F=D.as4D(1,D.shape[0],D.shape[1],D.shape[2])),R(F.rank===4,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+F.rank+"."}),R(r.rank===4,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+r.rank+"."}),R(F.shape[3]===r.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+F.shape[3]+") must match the inChannels dimension in filter "+r.shape[2]+"."}),I==null&&(I=[1,1]),R(rg(Q,I),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+Q+" and dilations '"+I+"'"}),o!=null&&R(JB(w),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+o+" but got pad "+w+"."});var u,a,U=Cw(F.shape,r.shape,Q,I,w,o,!0);n!=null&&(u=UB(u=J(n,"bias","fused conv2d"),D)[0],qA(U.outShape,u.shape)),M!=null&&(a=J(M,"prelu weights","fused depthwiseConv2d"));var G={x:F,filter:r};n!=null&&(G.bias=u),M!=null&&(G.preluActivationWeights=a);var d=[r,F],H=b.runKernelFunc(function(h,l){var m=h.fusedDepthwiseConv2D({input:F,filter:r,convInfo:U,bias:u,activation:Y,preluActivationWeights:a});return l([r,F,m]),m},G,function(h,l){R(Lw(I),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+I+"'"});var m=l[0],f=l[1],W=l[2],N=vt(h,W,Y),v={};return n!=null&&(v={bias:function(){return kt(u,N)}}),Object.assign({x:function(){return GD(f.shape,N,m,U)},filter:function(){return hD(f,N,m.shape,U)}},v)},"FusedDepthwiseConv2D",{convInfo:U,activation:Y},d,[!0]);return s?H.as3D(H.shape[1],H.shape[2],H.shape[3]):H}}),m0=Object.freeze({matMul:f0,conv2d:J0,depthwiseConv2d:N0}),R0=Object.freeze({image:Rt,linalg:s0,losses:D0,spectral:B0,fused:m0,signal:E0,square:iN,squaredDifference:wD,conv1d:um,conv2d:jg,conv3d:Um,depthwiseConv2d:Ge,separableConv2d:Ht,conv2dTranspose:Gm,conv3dTranspose:hm,op:z,batchNormalization2d:SN,batchNormalization3d:LN,batchNormalization4d:bN,batchNormalization:KN,batchNorm:tD,batchNorm2d:VN,batchNorm3d:xN,batchNorm4d:XN,booleanMaskAsync:sm,complex:$B,real:kg,imag:BQ,concat:jB,concat1d:NH,concat2d:mH,concat3d:RH,concat4d:PH,split:At,matMul:he,dot:lm,outerProduct:dm,reverse:SC,reverse1d:Hm,reverse2d:fm,reverse3d:Jm,reverse4d:Nm,maxPool:VB,avgPool:LC,pool:mm,maxPool3d:Rm,avgPool3d:Pm,slice:QQ,slice1d:vm,slice2d:km,slice3d:HD,slice4d:Tm,abs:YN,acos:MN,acosh:cN,asin:DN,asinh:rN,atan:FN,atanh:aN,ceil:sN,clipByValue:ut,cos:uN,cosh:UN,erf:GN,exp:Ut,expm1:hN,floor:lN,log:dN,log1p:HN,logSigmoid:fN,neg:Fe,reciprocal:JN,round:NN,rsqrt:CD,sigmoid:ED,sign:mN,isNaN:RN,isInf:PN,isFinite:vN,sin:kN,sinh:TN,softplus:jN,sqrt:pN,step:yN,tan:zN,tanh:WN,all:jm,any:pm,argMax:ym,argMin:zm,logSumExp:Wm,max:le,mean:Sm,min:Lm,moments:bm,sum:JD,prod:Km,equal:cD,equalStrict:tm,greater:nm,greaterEqual:DD,greaterEqualStrict:im,greaterStrict:Ym,less:Mm,lessEqual:cm,lessEqualStrict:Dm,lessStrict:rm,notEqual:Fm,notEqualStrict:am,add:OA,addN:qN,addStrict:_N,atan2:$N,div:bg,divNoNan:Am,divStrict:Bm,floorDiv:YD,maximum:Gt,maximumStrict:gm,minimum:MD,minimumStrict:Qm,mod:wm,modStrict:Cm,mul:wg,mulStrict:Em,pow:Ue,powStrict:em,squaredDifferenceStrict:Im,sub:zB,subStrict:om,elu:ND,leakyRelu:Vm,prelu:mD,relu:GB,relu6:RD,selu:xm,logicalAnd:ue,logicalNot:ON,logicalOr:nD,logicalXor:ZN,where:Iw,whereAsync:iD,buffer:zA,print:SH,batchToSpaceND:ec,broadcastTo:LH,cast:bH,clone:KH,cumsum:VH,depthToSpace:xH,expandDims:Tg,eye:Ic,multinomial:XH,oneHot:gt,pad:ww,pad1d:OH,pad2d:ZH,pad3d:qH,pad4d:_H,rand:$H,randomNormal:Af,randomGamma:Bf,randomUniform:oc,reshape:Sg,spaceToBatchND:tc,squeeze:nc,stack:Hg,tile:Ww,truncatedNormal:gf,unstack:pB,setdiff1dAsync:Qf,fill:gQ,linspace:JH,ones:zw,range:we,scalar:nA,tensor:Ag,tensor1d:PB,tensor2d:RQ,tensor3d:$o,tensor4d:Dg,tensor5d:dH,tensor6d:HH,variable:fH,zeros:DB,onesLike:Ec,zerosLike:$A,transpose:vQ,softmax:rQ,logSoftmax:tf,localResponseNormalization:Xm,norm:PD,gather:ht,unsortedSegmentSum:aD,basicLSTMCell:Om,multiRNNCell:Zm,movingAverage:qm,stridedSlice:_m,topk:$m,scatterND:A0,fft:ft,ifft:de,rfft:Jt,irfft:vD,sparseToDense:g0,gatherND:Q0,diag:w0,dropout:C0,hannWindow:Nt,hammingWindow:TD,frame:mt,stft:jD,inTopKAsync:e0});function EA(A,g){Array.isArray(A)||(A=[A]),A.forEach(function(B){B!=null&&R(B.dtype!=="complex64",function(){return g+" does not support complex64 tensors."})})}function jt(A,g,B,Q){if(B==="linear")return A.linear(g);if(B==="relu")return A.relu(g);if(B==="elu")return A.elu(g);if(B==="relu6")return A.relu6(g);if(B==="prelu")return A.prelu(g,Q);throw new Error("Activation "+B+" has not been implemented for the CPU backend.")}var P0=function(A){function g(){var B=A.call(this)||this;return B.blockSize=48,B.firstUse=!0,B.data=new ac(B,b),B}return Wg(g,A),g.prototype.write=function(B,Q,w){this.firstUse&&(this.firstUse=!1,BA().get("IS_NODE")&&ge(`
3762
3762
  ============================
3763
3763
  Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
3764
- ============================`));var C={};return this.data.set(C,{values:B,dtype:w}),C},g.prototype.move=function(B,Q,w,C){this.data.set(B,{values:Q,dtype:C})},g.prototype.numDataIds=function(){return this.data.numDataIds()},g.prototype.read=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){return[2,this.readSync(B)]})})},g.prototype.readSync=function(B){var Q=this.data.get(B),w=Q.dtype,C=Q.complexTensors;return w==="complex64"?et(this.readSync(C.real.dataId),this.readSync(C.imag.dataId)):this.data.get(B).values},g.prototype.bufferSync=function(B){var Q=this.readSync(B.dataId),w=Q;if(B.dtype==="string")try{w=Q.map(function(C){return XE(C)})}catch{throw new Error("Failed to decode encoded string bytes into utf-8")}return zA(B.shape,B.dtype,w)},g.prototype.makeOutput=function(B,Q,w){var C=this.write(B,Q,w);return b.makeTensorFromDataId(C,Q,w,this)},g.prototype.disposeData=function(B){if(this.data.has(B)){var Q=this.data.get(B).complexTensors;Q!=null&&(Q.real.dispose(),Q.imag.dispose()),this.data.delete(B)}},g.prototype.time=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){return Q=Zg(),B(),[2,{kernelMs:Zg()-Q}]})})},g.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},g.prototype.complex=function(B,Q){var w=this.makeOutput(null,B.shape,"complex64");return this.data.get(w.dataId).complexTensors={real:b.keep(B.clone()),imag:b.keep(Q.clone())},w},g.prototype.real=function(B){return this.data.get(B.dataId).complexTensors.real.clone()},g.prototype.imag=function(B){return this.data.get(B.dataId).complexTensors.imag.clone()},g.prototype.slice=function(B,Q,w){if(EA(B,"slice"),rc(B.shape,Q,w)){var C=Fc(Q,B.strides),E=hA(w);return Ag(this.readSync(B.dataId).subarray(C,C+E),w,B.dtype)}for(var e=zA(w,B.dtype),I=this.bufferSync(B),o=0;o<e.size;++o){var n=e.indexToLoc(o).map(function(i,Y){return i+Q[Y]});e.values[o]=I.get.apply(I,n)}return e.toTensor()},g.prototype.stridedSlice=function(B,Q,w,C){EA(B,"stridedSlice");var E=Qt(Q,w,C);if(E.some(function(M){return M===0}))return Ag([],E);for(var e=zA(E,B.dtype),I=this.bufferSync(B),o=0;o<e.size;o++){for(var n=e.indexToLoc(o),i=new Array(n.length),Y=0;Y<i.length;Y++)i[Y]=n[Y]*C[Y]+Q[Y];e.set.apply(e,[I.get.apply(I,i)].concat(n))}return e.toTensor()},g.prototype.diag=function(B){for(var Q=this.readSync(B.dataId),w=zA([B.size,B.size],B.dtype),C=w.values,E=0;E<Q.length;E++)C[E*B.size+E]=Q[E];return w.toTensor()},g.prototype.unstack=function(B,Q){for(var w=B.shape[Q],C=new Array(B.rank-1),E=0,e=0;e<B.rank;e++)e!==Q&&(C[E++]=B.shape[e]);var I=new Array(B.rank).fill(0),o=B.shape.slice();o[Q]=1;var n=new Array(w);for(e=0;e<n.length;e++)I[Q]=e,n[e]=this.slice(B,I,o).reshape(C);return n},g.prototype.reverse=function(B,Q){EA(B,"reverse");for(var w=zA(B.shape,B.dtype),C=this.bufferSync(B),E=function(I){var o=w.indexToLoc(I),n=o.slice();Q.forEach(function(i){return n[i]=B.shape[i]-1-n[i]}),w.set.apply(w,[C.get.apply(C,n)].concat(o))},e=0;e<w.size;e++)E(e);return w.toTensor()},g.prototype.concat=function(B,Q){var w=this;if(B[0].dtype==="complex64"){var C=B.map(function(M){return kg(M)}),E=B.map(function(M){return BQ(M)});return $B(this.concat(C,Q),this.concat(E,Q))}var e=B.map(function(M){var c=hA(M.shape.slice(Q));return M.as2D(-1,c)}),I=yw(e.map(function(M){return M.shape}),1),o=zA(I,B[0].dtype).values;if(e[0].shape[0]===1){var n=0;e.forEach(function(M){o.set(w.readSync(M.dataId),n),n+=M.size})}else{var i=0;e.forEach(function(M){for(var c=w.readSync(M.dataId),D=0,r=0;r<M.shape[0];++r)for(var F=r*I[1]+i,s=0;s<M.shape[1];++s)o[F+s]=c[D++];i+=M.shape[1]})}var Y=yw(B.map(function(M){return M.shape}),Q);return Ag(o,Y,B[0].dtype)},g.prototype.neg=function(B){return EA(B,"neg"),this.multiply(nA(-1),B)},g.prototype.add=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w+E,imag:C+e}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w+C})},g.prototype.addN=function(B){var Q=this;EA(B,"addN");for(var w=B.map(function(n){return Q.readSync(n.dataId)}),C=zA(B[0].shape,B[0].dtype),E=C.values,e=0;e<B.length;e++)for(var I=w[e],o=0;o<E.length;o++)E[o]+=I[o];return C.toTensor()},g.prototype.softmax=function(B,Q){var w=TB([Q],B.shape),C=this.max(B,w),E=cg(C.shape,w),e=this.subtract(B,C.reshape(E)),I=this.exp(e),o=this.sum(I,w).reshape(E);return this.realDivide(I,o)},g.prototype.subtract=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w-E,imag:C-e}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w-C})},g.prototype.pow=function(B,Q){return EA([B,Q],"pow"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.pow(w,C)})},g.prototype.batchMatMul=function(B,Q,w,C){EA([B,Q],"matMul");for(var E=w?B.shape[1]:B.shape[2],e=w?B.shape[2]:B.shape[1],I=C?Q.shape[1]:Q.shape[2],o=B.shape[0],n=this.readSync(B.dataId),i=this.readSync(Q.dataId),Y=w?[B.strides[0],1,B.strides[1]]:[B.strides[0],B.strides[1],1],M=Y[0],c=Y[1],D=Y[2],r=C?[1,Q.strides[1],Q.strides[0]]:[Q.strides[1],1,Q.strides[0]],F=r[0],s=r[1],u=r[2],a=e*I,U=zA([o,e,I],B.dtype),G=U.values,d=this.blockSize,H=0;H<o;H++)for(var h=0;h<e;h+=d)for(var l=0;l<I;l+=d)for(var m=0;m<E;m+=d)for(var f=Math.min(h+d,e),W=Math.min(l+d,I),N=Math.min(m+d,E),v=h;v<f;v++)for(var y=l;y<W;y++){for(var k=0,p=m;p<N;p++)k+=n[H*M+v*c+p*D]*i[p*F+y*s+H*u];G[H*a+(v*I+y)]+=k}return U.toTensor()},g.prototype.fusedBatchMatMul=function(B){var Q=B.a,w=B.b,C=B.transposeA,E=B.transposeB,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=this.batchMatMul(Q,w,C,E);return e&&(n=this.add(n,e)),I&&(n=Tt(this,n,I,o)),n},g.prototype.multiply=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w*E-C*e,imag:w*e+C*E}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w*C})},g.prototype.realDivide=function(B,Q){return EA([B,Q],"realDivide"),this.broadcastedBinaryOp(B,Q,"float32",function(w,C){return w/C})},g.prototype.floorDiv=function(B,Q){return EA([B,Q],"floorDiv"),this.broadcastedBinaryOp(B,Q,"int32",function(w,C){return Math.floor(w/C)})},g.prototype.sum=function(B,Q){EA(B,"sum"),dg("sum",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,_B(B.dtype,"int32")),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=0,c=0;c<I;++c)M+=n[Y+c];o[i]=M}return e},g.prototype.prod=function(B,Q){EA(B,"sum");for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,_B(B.dtype,"int32")),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=1,c=0;c<I;++c)M*=n[Y+c];o[i]=M}return e},g.prototype.unsortedSegmentSum=function(B,Q,w){EA(B,"unsortedSegmentSum");for(var C=[],E=B.rank-Q.rank,e=0;e<E;++e)Q=Q.expandDims(e+1);for(e=0;e<w;++e){var I=nA(e,"int32"),o=cD(I,Q).asType("float32").mul(B).sum(0);C.push(o)}return Hg(C)},g.prototype.argMin=function(B,Q){EA(B,"argMin");var w=[Q];dg("argMin",w,B.rank);for(var C=gg(B.shape,w),E=C[0],e=C[1],I=DB(E,"int32"),o=hA(e),n=this.readSync(I.dataId),i=this.readSync(B.dataId),Y=0;Y<n.length;++Y){for(var M=Y*o,c=i[M],D=0,r=0;r<o;++r){var F=i[M+r];F<c&&(c=F,D=r)}n[Y]=D}return I},g.prototype.argMax=function(B,Q){EA(B,"argMax");var w=[Q];dg("argMax",w,B.rank);for(var C=gg(B.shape,w),E=C[0],e=C[1],I=DB(E,"int32"),o=hA(e),n=this.readSync(I.dataId),i=this.readSync(B.dataId),Y=0;Y<n.length;++Y){for(var M=Y*o,c=i[M],D=0,r=0;r<o;++r){var F=i[M+r];F>c&&(c=F,D=r)}n[Y]=D}return I},g.prototype.cumsum=function(B,Q,w,C){if(EA(B,"cumsum"),Q!==B.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(B.rank-1)+" but got axis="+Q);for(var E=_B(B.dtype,"int32"),e=DB(B.shape,E),I=this.readSync(e.dataId),o=this.readSync(B.dataId),n=B.shape[B.rank-1],i=C?function(r,F){return r+n-F-1}:function(r,F){return r+F},Y=0;Y<o.length;Y+=n)for(var M=0;M<n;M++){var c=i(Y,M);if(M===0)I[c]=w?0:o[c];else{var D=i(Y,M-1);I[c]=w?o[D]+I[D]:o[c]+I[D]}}return e},g.prototype.equal=function(B,Q){return EA([B,Q],"equal"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w===C?1:0})},g.prototype.notEqual=function(B,Q){return EA([B,Q],"notEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w!==C?1:0})},g.prototype.less=function(B,Q){return EA([B,Q],"less"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w<C?1:0})},g.prototype.lessEqual=function(B,Q){return EA([B,Q],"lessEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w<=C?1:0})},g.prototype.greater=function(B,Q){return EA([B,Q],"greater"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w>C?1:0})},g.prototype.greaterEqual=function(B,Q){return EA([B,Q],"greaterEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w>=C?1:0})},g.prototype.logicalNot=function(B){EA(B,"logicalNot");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)w[C]=Q[C]?0:1;return this.makeOutput(w,B.shape,"bool")},g.prototype.logicalAnd=function(B,Q){return EA([B,Q],"logicalAnd"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w&&C})},g.prototype.logicalOr=function(B,Q){return EA([B,Q],"logicalOr"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w||C})},g.prototype.select=function(B,Q,w){EA([B,Q,w],"select");for(var C=this.readSync(B.dataId),E=this.readSync(Q.dataId),e=this.readSync(w.dataId),I=DB(Q.shape,_B(Q.dtype,w.dtype)),o=this.readSync(I.dataId),n=0,i=B.rank===0||B.rank>1||Q.rank===1?1:hA(Q.shape.slice(1)),Y=0;Y<C.length;Y++)for(var M=0;M<i;M++)C[Y]===1?o[n++]=E[Y]:o[n++]=e[Y];return I},g.prototype.where=function(B){EA([B],"where");var Q=this.readSync(B.dataId);return tt(B.shape,Q)},g.prototype.topk=function(B,Q,w){return EA(B,"topk"),Jc(this.readSync(B.dataId),B.shape,B.dtype,Q)},g.prototype.min=function(B,Q){EA(B,"min"),dg("min",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];D<M&&(M=D)}o[i]=M}return e},g.prototype.minimum=function(B,Q){return EA([B,Q],"minimum"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.min(w,C)})},g.prototype.mod=function(B,Q){return EA([B,Q],"mod"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){var E=w%C;return w<0&&C<0||w>=0&&C>=0?E:(E+C)%C})},g.prototype.max=function(B,Q){EA(B,"max"),dg("max",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];D>M&&(M=D)}o[i]=M}return e},g.prototype.maximum=function(B,Q){return EA([B,Q],"maximum"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.max(w,C)})},g.prototype.all=function(B,Q){EA(B,"all"),dg("all",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];M=M&&D}o[i]=M}return e},g.prototype.any=function(B,Q){EA(B,"any"),dg("any",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];M=M||D}o[i]=M}return e},g.prototype.squaredDifference=function(B,Q){return EA([B,Q],"squaredDifference"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){var E=w-C;return E*E})},g.prototype.ceil=function(B){EA(B,"ceil");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.ceil(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.floor=function(B){EA(B,"floor");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.floor(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.sign=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)Q[C]<0?w[C]=-1:Q[C]>0?w[C]=1:w[C]=0;return this.makeOutput(w,B.shape,"float32")},g.prototype.isNaN=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Number.isNaN(Q[C])&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.isInf=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Math.abs(Q[C])===1/0&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.isFinite=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Number.isFinite(Q[C])&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.round=function(B){EA(B,"round");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Math.floor(Q[C]);Q[C]-E<.5?w[C]=Math.floor(Q[C]):Q[C]-E>.5?w[C]=Math.ceil(Q[C]):w[C]=E%2==0?E:E+1}return this.makeOutput(w,B.shape,"float32")},g.prototype.exp=function(B){EA(B,"exp");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.exp(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.expm1=function(B){EA(B,"expm1");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.expm1(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.log=function(B){EA(B,"log");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.log(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.log1p=function(B){EA(B,"log1p");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.log1p(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.sqrt=function(B){EA(B,"sqrt");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.sqrt(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.rsqrt=function(B){EA(B,"rsqrt");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=1/Math.sqrt(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.reciprocal=function(B){EA(B,"reciprocal");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=1/Q[C];return this.makeOutput(w,B.shape,"float32")},g.prototype.linear=function(B){return B},g.prototype.relu=function(B){EA(B,"relu");for(var Q=DB(B.shape,B.dtype),w=this.readSync(Q.dataId),C=this.readSync(B.dataId),E=0;E<C.length;++E)w[E]=Math.max(0,C[E]);return Q},g.prototype.relu6=function(B){EA(B,"relu");for(var Q=DB(B.shape,B.dtype),w=this.readSync(Q.dataId),C=this.readSync(B.dataId),E=0;E<C.length;++E)w[E]=Math.min(Math.max(0,C[E]),6);return Q},g.prototype.prelu=function(B,Q){return EA([B,Q],"prelu"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return w<0?C*w:w})},g.prototype.elu=function(B){EA(B,"elu");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C){var E=w[C];Q[C]=E>=0?E:Math.exp(E)-1}return this.makeOutput(Q,B.shape,"float32")},g.prototype.eluDer=function(B,Q){EA([B,Q],"eluDer");for(var w=new Float32Array(Q.size),C=this.readSync(Q.dataId),E=this.readSync(B.dataId),e=0;e<C.length;++e){var I=C[e];w[e]=I>=1?E[e]:E[e]*(I+1)}return this.makeOutput(w,Q.shape,"float32")},g.prototype.selu=function(B){EA(B,"selu");for(var Q=Ft,w=at,C=new Float32Array(B.size),E=this.readSync(B.dataId),e=0;e<E.length;++e){var I=E[e];C[e]=I>=0?w*I:Q*(Math.exp(I)-1)}return this.makeOutput(C,B.shape,"float32")},g.prototype.clip=function(B,Q,w){EA(B,"clip");for(var C=new Float32Array(B.size),E=this.readSync(B.dataId),e=0;e<E.length;++e){var I=E[e];C[e]=I>w?w:I<Q?Q:I}return this.makeOutput(C,B.shape,"float32")},g.prototype.abs=function(B){for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.abs(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.complexAbs=function(B){for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<B.size;++C){var E=w[2*C],e=w[2*C+1];Q[C]=Math.hypot(E,e)}return this.makeOutput(Q,B.shape,"float32")},g.prototype.int=function(B){EA(B,"int");for(var Q=new Int32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=w[C];return this.makeOutput(Q,B.shape,"int32")},g.prototype.sigmoid=function(B){EA(B,"sigmoid");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=1/(1+Math.exp(-w[C]));return this.makeOutput(Q,B.shape,"float32")},g.prototype.softplus=function(B){EA(B,"softplus");for(var Q=Math.log(11920928955078125e-23)+2,w=new Float32Array(B.size),C=this.readSync(B.dataId),E=0;E<C.length;++E){var e=C[E]>-Q,I=C[E]<Q,o=Math.exp(C[E]),n=void 0;n=I?o:e?C[E]:Math.log(1+o),w[E]=n}return this.makeOutput(w,B.shape,"float32")},g.prototype.sin=function(B){EA(B,"sin");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.sin(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.cos=function(B){EA(B,"cos");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.cos(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.tan=function(B){EA(B,"tan");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.tan(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.asin=function(B){EA(B,"asin");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.asin(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.acos=function(B){EA(B,"acos");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.acos(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atan=function(B){EA(B,"atan");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.atan(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atan2=function(B,Q){return EA([B,Q],"atan2"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.atan2(w,C)})},g.prototype.sinh=function(B){EA(B,"sinh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.sinh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.cosh=function(B){EA(B,"cosh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.cosh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.tanh=function(B){EA(B,"tanh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=md(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.asinh=function(B){EA(B,"asinh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.asinh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.acosh=function(B){EA(B,"acosh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.acosh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atanh=function(B){EA(B,"atanh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.atanh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.erf=function(B){EA(B,"erf");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C){var E=Math.sign(w[C]),e=Math.abs(w[C]),I=1/(1+.3275911*e);Q[C]=E*(1-((((1.061405429*I-1.453152027)*I+1.421413741)*I-.284496736)*I+.254829592)*I*Math.exp(-e*e))}return this.makeOutput(Q,B.shape,"float32")},g.prototype.step=function(B,Q){Q===void 0&&(Q=0),EA(B,"step");for(var w=new Float32Array(B.size),C=this.readSync(B.dataId),E=0;E<C.length;++E){var e=C[E];isNaN(e)?w[E]=NaN:w[E]=e>0?1:Q}return this.makeOutput(w,B.shape,"float32")},g.prototype.fusedConv2d=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights,o=this.conv2d(Q,w,C);return E&&(o=this.add(o,E)),e&&(o=Tt(this,o,e,I)),o},g.prototype.conv2d=function(B,Q,w){EA([B,Q],"conv2d");for(var C=w.filterHeight,E=w.filterWidth,e=w.dilationHeight,I=w.dilationWidth,o=w.padInfo.left,n=w.padInfo.top,i=w.dataFormat==="channelsLast",Y=zA(w.outShape,B.dtype),M=B.strides[0],c=i?B.strides[1]:B.strides[2],D=i?B.strides[2]:1,r=i?1:B.strides[1],F=Y.strides[0],s=i?Y.strides[1]:Y.strides[2],u=i?Y.strides[2]:1,a=i?1:Y.strides[1],U=this.readSync(B.dataId),G=this.readSync(Q.dataId),d=Y.values,H=0;H<w.batchSize;++H)for(var h=H*M,l=H*F,m=0;m<w.outHeight;++m)for(var f=l+m*s,W=m*w.strideHeight-n,N=0;N<C;N++){var v=W+N*e;if(!(v<0||v>=w.inHeight))for(var y=N*Q.strides[0],k=h+v*c,p=0;p<w.outWidth;++p)for(var K=f+p*u,V=p*w.strideWidth-o,T=0;T<E;T++){var j=V+T*I;if(!(j<0||j>=w.inWidth))for(var X=k+j*D,gA=y+T*Q.strides[1],CA=0;CA<w.inChannels;++CA){for(var wA=U[X+CA*r],eA=0;eA<w.outChannels;++eA)d[K+eA*a]+=wA*G[gA+eA];gA+=w.outChannels}}}return Y.toTensor()},g.prototype.conv3d=function(B,Q,w){for(var C=w.filterDepth,E=w.filterHeight,e=w.filterWidth,I=w.dilationDepth,o=w.dilationHeight,n=w.dilationWidth,i=w.padInfo.front,Y=w.padInfo.left,M=w.padInfo.top,c=zA(w.outShape,B.dtype),D=this.readSync(B.dataId),r=this.readSync(Q.dataId),F=c.values,s=0;s<w.batchSize;++s)for(var u=s*B.strides[0],a=s*c.strides[0],U=0;U<w.outDepth;++U)for(var G=a+U*c.strides[1],d=U*w.strideDepth-i,H=0;H<C;H++){var h=d+H*I;if(!(h<0||h>=w.inDepth))for(var l=H*Q.strides[0],m=u+h*B.strides[1],f=0;f<w.outHeight;++f)for(var W=G+f*c.strides[2],N=f*w.strideHeight-M,v=0;v<E;v++){var y=N+v*o;if(!(y<0||y>=w.inHeight))for(var k=l+v*Q.strides[1],p=m+y*B.strides[2],K=0;K<w.outWidth;++K)for(var V=W+K*w.outChannels,T=K*w.strideWidth-Y,j=0;j<e;j++){var X=T+j*n;if(!(X<0||X>=w.inWidth))for(var gA=k+j*Q.strides[2],CA=p+X*w.inChannels,wA=gA,eA=0;eA<w.inChannels;++eA){for(var YA=D[CA+eA],$=0;$<w.outChannels;++$)F[V+$]+=YA*r[wA+$];wA+=w.outChannels}}}}return c.toTensor()},g.prototype.conv2dDerInput=function(B,Q,w){EA([B,Q],"conv2dDerInput");for(var C=zA(w.inShape,"float32"),E=C.values,e=this.readSync(B.dataId),I=this.readSync(Q.dataId),o=Q.strides,n=o[0],i=o[1],Y=o[2],M=w.batchSize,c=w.filterHeight,D=w.filterWidth,r=w.inChannels,F=w.inHeight,s=w.inWidth,u=w.outChannels,a=w.outHeight,U=w.outWidth,G=w.strideHeight,d=w.strideWidth,H=w.dataFormat,h=c-1-w.padInfo.top,l=D-1-w.padInfo.left,m=H==="channelsLast",f=C.strides[0],W=m?C.strides[1]:C.strides[2],N=m?C.strides[2]:1,v=m?1:C.strides[1],y=B.strides[0],k=m?B.strides[1]:B.strides[2],p=m?B.strides[2]:1,K=m?1:B.strides[1],V=0;V<M;++V)for(var T=0;T<r;++T)for(var j=0;j<F;++j)for(var X=j-h,gA=Math.max(0,Math.ceil(X/G)),CA=Math.min(a,(c+X)/G),wA=0;wA<s;++wA){for(var eA=wA-l,YA=Math.max(0,Math.ceil(eA/d)),$=Math.min(U,(D+eA)/d),RA=0,oA=gA;oA<CA;++oA)for(var aA=oA*G-X,JA=YA;JA<$;++JA)for(var VA=y*V+k*oA+p*JA,bA=n*(c-1-aA)+i*(D-1-(JA*d-eA))+Y*T,pA=0;pA<u;++pA)RA+=e[VA+K*pA]*I[bA+pA];E[f*V+W*j+N*wA+v*T]=RA}return C.toTensor()},g.prototype.conv3dDerInput=function(B,Q,w){for(var C=zA(w.inShape,"float32"),E=C.values,e=C.strides,I=e[0],o=e[1],n=e[2],i=e[3],Y=this.readSync(B.dataId),M=B.strides,c=M[0],D=M[1],r=M[2],F=M[3],s=this.readSync(Q.dataId),u=Q.strides,a=u[0],U=u[1],G=u[2],d=u[3],H=w.batchSize,h=w.filterDepth,l=w.filterHeight,m=w.filterWidth,f=w.inChannels,W=w.inDepth,N=w.inHeight,v=w.inWidth,y=w.outChannels,k=w.outDepth,p=w.outHeight,K=w.outWidth,V=w.strideDepth,T=w.strideHeight,j=w.strideWidth,X=h-1-w.padInfo.front,gA=l-1-w.padInfo.top,CA=m-1-w.padInfo.left,wA=0;wA<H;++wA)for(var eA=0;eA<f;++eA)for(var YA=0;YA<W;++YA)for(var $=YA-X,RA=Math.max(0,Math.ceil($/V)),oA=Math.min(k,(h+$)/V),aA=0;aA<N;++aA)for(var JA=aA-gA,VA=Math.max(0,Math.ceil(JA/T)),bA=Math.min(p,(l+JA)/T),pA=0;pA<v;++pA){for(var ZA=pA-CA,CB=Math.max(0,Math.ceil(ZA/j)),rB=Math.min(K,(m+ZA)/j),FB=0,QA=RA;QA<oA;++QA)for(var rA=QA*V-$,xA=VA;xA<bA;++xA)for(var aB=xA*T-JA,vB=CB;vB<rB;++vB)for(var ag=c*wA+D*QA+r*xA+F*vB,hB=a*(h-1-rA)+U*(l-1-aB)+G*(m-1-(vB*j-ZA))+d*eA,kB=0;kB<y;++kB)FB+=Y[ag+kB]*s[hB+kB];E[I*wA+o*YA+n*aA+i*pA+eA]=FB}return C.toTensor()},g.prototype.conv2dDerFilter=function(B,Q,w){EA([B,Q],"conv2dDerFilter");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=w.dataFormat==="channelsLast",n=zA(w.filterShape,"float32"),i=w.padInfo.left,Y=w.padInfo.top,M=this.bufferSync(B),c=this.bufferSync(Q),D=0;D<e;++D)for(var r=Math.max(0,Math.ceil((Y-D)/C)),F=Math.min(w.outHeight,(w.inHeight+Y-D)/C),s=0;s<I;++s)for(var u=Math.max(0,Math.ceil((i-s)/E)),a=Math.min(w.outWidth,(w.inWidth+i-s)/E),U=0;U<w.inChannels;++U)for(var G=0;G<w.outChannels;++G){for(var d=0,H=0;H<w.batchSize;++H)for(var h=r;h<F;++h)for(var l=D+h*C-Y,m=u;m<a;++m){var f=s+m*E-i;d+=o?M.get(H,l,f,U)*c.get(H,h,m,G):M.get(H,U,l,f)*c.get(H,G,h,m)}n.set(d,D,s,U,G)}return n.toTensor()},g.prototype.conv3dDerFilter=function(B,Q,w){for(var C=w.strideDepth,E=w.strideHeight,e=w.strideWidth,I=w.filterDepth,o=w.filterHeight,n=w.filterWidth,i=zA(w.filterShape,"float32"),Y=i.values,M=i.strides,c=M[0],D=M[1],r=M[2],F=M[3],s=this.readSync(Q.dataId),u=Q.strides,a=u[0],U=u[1],G=u[2],d=u[3],H=this.readSync(B.dataId),h=B.strides,l=h[0],m=h[1],f=h[2],W=h[3],N=w.padInfo.front,v=w.padInfo.left,y=w.padInfo.top,k=0;k<I;++k)for(var p=Math.max(0,Math.ceil((N-k)/C)),K=Math.min(w.outDepth,(w.inDepth+N-k)/C),V=k*c,T=0;T<o;++T)for(var j=Math.max(0,Math.ceil((y-T)/E)),X=Math.min(w.outHeight,(w.inHeight+y-T)/E),gA=T*D+V,CA=0;CA<n;++CA)for(var wA=Math.max(0,Math.ceil((v-CA)/e)),eA=Math.min(w.outWidth,(w.inWidth+v-CA)/e),YA=CA*r+gA,$=0;$<w.inChannels;++$)for(var RA=$*F+YA,oA=0;oA<w.outChannels;++oA){for(var aA=0,JA=0;JA<w.batchSize;++JA)for(var VA=JA*l,bA=JA*a,pA=p;pA<K;++pA)for(var ZA=(k+pA*C-N)*m+VA,CB=pA*U+bA,rB=j;rB<X;++rB)for(var FB=(T+rB*E-y)*f+ZA,QA=rB*G+CB,rA=wA;rA<eA;++rA){var xA=rA*d+QA;aA+=H[(CA+rA*e-v)*W+FB+$]*s[xA+oA]}Y[RA+oA]=aA}return i.toTensor()},g.prototype.fusedDepthwiseConv2D=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights,o=this.depthwiseConv2D(Q,w,C);return E&&(o=this.add(o,E)),e&&(o=Tt(this,o,e,I)),o},g.prototype.depthwiseConv2D=function(B,Q,w){EA([B,Q],"depthwiseConv2D");for(var C=w.filterHeight,E=w.filterWidth,e=w.dilationHeight,I=w.dilationWidth,o=w.padInfo.left,n=w.padInfo.top,i=w.outChannels/w.inChannels,Y=zA(w.outShape,B.dtype),M=this.readSync(B.dataId),c=this.readSync(Q.dataId),D=Y.values,r=0;r<w.batchSize;++r)for(var F=r*B.strides[0],s=r*Y.strides[0],u=0;u<w.outHeight;++u)for(var a=s+u*Y.strides[1],U=u*w.strideHeight-o,G=0;G<C;++G){var d=U+G*e;if(!(d<0||d>=w.inHeight))for(var H=G*Q.strides[0],h=F+d*B.strides[1],l=0;l<w.outWidth;++l)for(var m=a+l*Y.strides[2],f=l*w.strideWidth-n,W=0;W<E;++W){var N=f+W*I;if(!(N<0||N>=w.inWidth))for(var v=H+W*Q.strides[1],y=h+N*w.inChannels,k=m,p=v,K=0;K<w.inChannels;++K){for(var V=M[y+K],T=0;T<i;++T)D[k+T]+=V*c[p+T];k+=i,p+=i}}}return Y.toTensor()},g.prototype.depthwiseConv2DDerInput=function(B,Q,w){EA([B,Q],"depthwiseConv2DDerInput");for(var C=zA(w.inShape,"float32"),E=C.values,e=C.strides,I=e[0],o=e[1],n=e[2],i=this.readSync(B.dataId),Y=B.strides,M=Y[0],c=Y[1],D=Y[2],r=this.readSync(Q.dataId),F=Q.strides,s=F[0],u=F[1],a=F[2],U=w.batchSize,G=w.filterHeight,d=w.filterWidth,H=w.inChannels,h=w.inHeight,l=w.inWidth,m=w.outChannels,f=w.outHeight,W=w.outWidth,N=w.strideHeight,v=w.strideWidth,y=G-1-w.padInfo.top,k=d-1-w.padInfo.left,p=m/H,K=0;K<U;++K)for(var V=0;V<H;++V)for(var T=0;T<h;++T)for(var j=T-y,X=Math.max(0,Math.ceil(j/N)),gA=Math.min(f,(G+j)/N),CA=0;CA<l;++CA){for(var wA=CA-k,eA=Math.max(0,Math.ceil(wA/v)),YA=Math.min(W,(d+wA)/v),$=0,RA=X;RA<gA;++RA)for(var oA=RA*N-j,aA=eA;aA<YA;++aA)for(var JA=M*K+c*RA+D*aA,VA=s*(G-1-oA)+u*(d-1-(aA*v-wA))+a*V,bA=0;bA<p;++bA)$+=i[JA+(V*p+bA)]*r[VA+bA];E[I*K+o*T+n*CA+V]=$}return C.toTensor()},g.prototype.depthwiseConv2DDerFilter=function(B,Q,w){EA([B,Q],"depthwiseConv2DDerFilter");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=zA(w.filterShape,"float32"),n=w.padInfo.left,i=w.padInfo.top,Y=w.outChannels/w.inChannels,M=this.bufferSync(B),c=this.bufferSync(Q),D=0;D<e;++D)for(var r=Math.max(0,Math.ceil((i-D)/C)),F=Math.min(w.outHeight,(w.inHeight+i-D)/C),s=0;s<I;++s)for(var u=Math.max(0,Math.ceil((n-s)/E)),a=Math.min(w.outWidth,(w.inWidth+n-s)/E),U=0;U<w.outChannels;++U){for(var G=Math.trunc(U/Y),d=U%Y,H=0,h=0;h<w.batchSize;++h)for(var l=r;l<F;++l)for(var m=D+l*C-i,f=u;f<a;++f){var W=s+f*E-n;H+=M.get(h,m,W,G)*c.get(h,l,f,U)}o.set(H,D,s,G,d)}return o.toTensor()},g.prototype.tile=function(B,Q){return EA(B,"tile"),fc(this.bufferSync(B),Q)},g.prototype.pad=function(B,Q,w){EA(B,"pad");var C=Q.map(function(Y,M){return Y[0]+B.shape[M]+Y[1]}),E=Q.map(function(Y){return Y[0]}),e=this.bufferSync(B),I=zA(C,B.dtype);w!==0&&I.values.fill(w);for(var o=0;o<B.size;o++){var n=e.indexToLoc(o),i=n.map(function(Y,M){return Y+E[M]});I.set.apply(I,[e.get.apply(e,n)].concat(i))}return I.toTensor()},g.prototype.transpose=function(B,Q){EA(B,"transpose");for(var w=new Array(B.rank),C=0;C<w.length;C++)w[C]=B.shape[Q[C]];var E=this.readSync(B.dataId),e=zA(w,B.dtype),I=this.bufferSync(B);for(C=0;C<B.size;++C){for(var o=I.indexToLoc(C),n=new Array(o.length),i=0;i<n.length;i++)n[i]=o[Q[i]];var Y=e.locToIndex(n);e.values[Y]=E[C]}return e.toTensor()},g.prototype.gather=function(B,Q,w){EA([B,Q],"gather");var C=B.shape.slice(),E=this.readSync(Q.dataId);C[w]=E.length;for(var e=zA(C,B.dtype),I=this.bufferSync(B),o=0;o<e.size;++o){var n=e.indexToLoc(o),i=n.slice();i[w]=E[n[w]];var Y=I.locToIndex(i);e.values[o]=I.values[Y]}return e.toTensor()},g.prototype.batchToSpaceND=function(B,Q,w){EA([B],"batchToSpaceND");var C=Q.reduce(function(i,Y){return i*Y}),E=Ee(B.shape,Q,C),e=ee(E.length,Q.length),I=Ie(B.shape,Q,C),o=ic(w,Q.length),n=Yc(I,w,Q.length);return B.reshape(E).transpose(e).reshape(I).slice(o,n)},g.prototype.spaceToBatchND=function(B,Q,w){EA([B],"spaceToBatchND");var C=Q.reduce(function(Y,M){return Y*M}),E=[[0,0]];E.push.apply(E,w);for(var e=1+Q.length;e<B.shape.length;++e)E.push([0,0]);var I=B.pad(E),o=Ee(I.shape,Q,C,!1),n=ee(o.length,Q.length,!1),i=Ie(I.shape,Q,C,!1);return I.reshape(o).transpose(n).reshape(i)},g.prototype.pool=function(B,Q,w){EA(B,"pool");for(var C=Q.strideHeight,E=Q.strideWidth,e=Q.dilationHeight,I=Q.dilationWidth,o=Q.effectiveFilterHeight,n=Q.effectiveFilterWidth,i=Q.padInfo.top,Y=Q.padInfo.left,M=w==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,c=this.readSync(B.dataId),D=zA(Q.outShape,B.dtype),r=D.values,F=Q.outShape[1]*Q.outShape[2]*Q.outShape[3],s=Q.outShape[2]*Q.outShape[3],u=Q.outShape[3],a=0;a<Q.batchSize;++a)for(var U=a*F,G=a*B.strides[0],d=0;d<Q.inChannels;++d)for(var H=0;H<Q.outHeight;++H)for(var h=H*C-i,l=Math.max(0,h),m=Math.min(Q.inHeight,o+h),f=U+H*s,W=0;W<Q.outWidth;++W){for(var N=W*E-Y,v=Math.max(0,N),y=Math.min(Q.inWidth,n+N),k=M,p=0,K=0,V=l;V<m;V+=e){for(var T=G+V*B.strides[1],j=v;j<y;j+=I){var X=c[T+j*B.strides[2]+d];w==="max"&&X>k?k=X:w==="avg"&&(p+=X,K++)}if(isNaN(k))break}r[f+W*u+d]=w==="avg"?p/K:k}return D.toTensor()},g.prototype.maxPool=function(B,Q){return this.pool(B,Q,"max")},g.prototype.maxPoolPositions=function(B,Q){for(var w=zA(Q.outShape,"int32"),C=Q.strideHeight,E=Q.strideWidth,e=Q.dilationHeight,I=Q.dilationWidth,o=Q.effectiveFilterHeight,n=Q.effectiveFilterWidth,i=Q.padInfo.top,Y=Q.padInfo.left,M=this.bufferSync(B),c=0;c<Q.batchSize;++c)for(var D=0;D<Q.inChannels;++D)for(var r=0;r<Q.outHeight;++r){for(var F=r*C-i,s=F;s<0;)s+=e;for(var u=Math.min(Q.inHeight,o+F),a=0;a<Q.outWidth;++a){for(var U=a*E-Y,G=U;G<0;)G+=I;for(var d=Math.min(Q.inWidth,n+U),H=Number.NEGATIVE_INFINITY,h=-1,l=s;l<u;l+=e)for(var m=l-F,f=G;f<d;f+=I){var W=f-U,N=M.get(c,l,f,D);N>H&&(H=N,h=m*n+W)}w.set(h,c,r,a,D)}}return w.toTensor()},g.prototype.maxPoolBackprop=function(B,Q,w,C){EA([Q,w],"maxPoolBackprop");for(var E=this.maxPoolPositions(Q,C),e=C.strideHeight,I=C.strideWidth,o=C.dilationHeight,n=C.dilationWidth,i=C.effectiveFilterHeight,Y=C.effectiveFilterWidth,M=Y-1-C.padInfo.left,c=i-1-C.padInfo.top,D=zA(Q.shape,"float32"),r=this.bufferSync(E),F=this.bufferSync(B),s=0;s<C.batchSize;++s)for(var u=0;u<C.inChannels;++u)for(var a=0;a<C.inHeight;++a)for(var U=0;U<C.inWidth;++U){for(var G=a-c,d=U-M,H=0,h=0;h<i;h+=o){var l=(G+h)/e;if(!(l<0||l>=C.outHeight||Math.floor(l)!==l))for(var m=0;m<Y;m+=n){var f=(d+m)/I;if(!(f<0||f>=C.outWidth||Math.floor(f)!==f)){var W=i*Y-1-r.get(s,l,f,u)===h*Y+m?1:0;W!==0&&(H+=F.get(s,l,f,u)*W)}}}D.set(H,s,a,U,u)}return D.toTensor()},g.prototype.avgPoolBackprop=function(B,Q,w){EA([B,Q],"avgPoolBackprop");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=w.dilationHeight,n=w.dilationWidth,i=w.effectiveFilterHeight,Y=w.effectiveFilterWidth,M=Y-1-w.padInfo.left,c=i-1-w.padInfo.top,D=zA(Q.shape,"float32"),r=1/(e*I),F=this.bufferSync(B),s=0;s<w.batchSize;++s)for(var u=0;u<w.inChannels;++u)for(var a=0;a<w.inHeight;++a)for(var U=0;U<w.inWidth;++U){for(var G=a-c,d=U-M,H=0,h=0;h<i;h+=o){var l=(G+h)/C;if(!(l<0||l>=w.outHeight||Math.floor(l)!==l))for(var m=0;m<Y;m+=n){var f=(d+m)/E;f<0||f>=w.outWidth||Math.floor(f)!==f||(H+=F.get(s,l,f,u))}}D.set(H*r,s,a,U,u)}return D.toTensor()},g.prototype.pool3d=function(B,Q,w){EA(B,"pool3d");for(var C=Q.strideDepth,E=Q.strideHeight,e=Q.strideWidth,I=Q.dilationDepth,o=Q.dilationHeight,n=Q.dilationWidth,i=Q.effectiveFilterDepth,Y=Q.effectiveFilterHeight,M=Q.effectiveFilterWidth,c=Q.padInfo.front,D=Q.padInfo.top,r=Q.padInfo.left,F=w==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,s=this.readSync(B.dataId),u=zA(Q.outShape,B.dtype),a=u.values,U=Q.outShape[1]*Q.outShape[2]*Q.outShape[3]*Q.outShape[4],G=Q.outShape[2]*Q.outShape[3]*Q.outShape[4],d=Q.outShape[3]*Q.outShape[4],H=Q.outShape[4],h=0;h<Q.batchSize;++h)for(var l=h*U,m=h*B.strides[0],f=0;f<Q.inChannels;++f)for(var W=0;W<Q.outDepth;++W){for(var N=W*C-c,v=N;v<0;)v+=I;for(var y=Math.min(Q.inDepth,i+N),k=l+W*G,p=0;p<Q.outHeight;++p){for(var K=p*E-D,V=K;V<0;)V+=o;for(var T=Math.min(Q.inHeight,Y+K),j=k+p*d,X=0;X<Q.outWidth;++X){for(var gA=X*e-r,CA=gA;CA<0;)CA+=n;for(var wA=Math.min(Q.inWidth,M+gA),eA=j+X*H,YA=F,$=0,RA=0,oA=v;oA<y;oA+=I){for(var aA=m+oA*B.strides[1],JA=V;JA<T;JA+=o){for(var VA=aA+JA*B.strides[2],bA=CA;bA<wA;bA+=n){var pA=s[VA+bA*B.strides[3]+f];if(w==="max"&&pA>YA?YA=pA:w==="avg"&&($+=pA,RA++),isNaN(YA))break}if(isNaN(YA))break}if(isNaN(YA))break}a[eA+f]=w==="avg"?$/RA:YA}}}return u.toTensor()},g.prototype.avgPool3d=function(B,Q){return EA(B,"avgPool3d"),this.pool3d(B,Q,"avg").toFloat()},g.prototype.avgPool3dBackprop=function(B,Q,w){EA([B,Q],"avgPool3dBackprop");for(var C=w.strideDepth,E=w.strideHeight,e=w.strideWidth,I=w.filterDepth,o=w.filterHeight,n=w.filterWidth,i=w.dilationDepth,Y=w.dilationHeight,M=w.dilationWidth,c=w.effectiveFilterDepth,D=w.effectiveFilterHeight,r=w.effectiveFilterWidth,F=c-1-w.padInfo.front,s=r-1-w.padInfo.left,u=D-1-w.padInfo.top,a=zA(Q.shape,"float32"),U=1/(I*o*n),G=this.bufferSync(B),d=0;d<w.batchSize;++d)for(var H=0;H<w.inChannels;++H)for(var h=0;h<w.inDepth;++h)for(var l=0;l<w.inHeight;++l)for(var m=0;m<w.inWidth;++m){for(var f=h-F,W=l-u,N=m-s,v=0,y=0;y<c;y+=i){var k=(f+y)/C;if(!(k<0||k>=w.outDepth||Math.floor(k)!==k))for(var p=0;p<D;p+=Y){var K=(W+p)/E;if(!(K<0||K>=w.outHeight||Math.floor(K)!==K))for(var V=0;V<r;V+=M){var T=(N+V)/e;T<0||T>=w.outWidth||Math.floor(T)!==T||(v+=G.get(d,k,K,T,H))}}}a.set(v*U,d,h,l,m,H)}return a.toTensor()},g.prototype.maxPool3d=function(B,Q){return EA(B,"maxPool3d"),this.pool3d(B,Q,"max").toFloat()},g.prototype.maxPool3dPositions=function(B,Q){for(var w=zA(Q.outShape,"int32"),C=Q.strideDepth,E=Q.strideHeight,e=Q.strideWidth,I=Q.dilationDepth,o=Q.dilationHeight,n=Q.dilationWidth,i=Q.effectiveFilterDepth,Y=Q.effectiveFilterHeight,M=Q.effectiveFilterWidth,c=Q.padInfo.front,D=Q.padInfo.top,r=Q.padInfo.left,F=this.bufferSync(B),s=0;s<Q.batchSize;++s)for(var u=0;u<Q.inChannels;++u)for(var a=0;a<Q.outDepth;++a){for(var U=a*C-c,G=U;G<0;)G+=I;for(var d=Math.min(Q.inDepth,i+U),H=0;H<Q.outHeight;++H){for(var h=H*E-D,l=h;l<0;)l+=o;for(var m=Math.min(Q.inHeight,Y+h),f=0;f<Q.outWidth;++f){for(var W=f*e-r,N=W;N<0;)N+=n;for(var v=Math.min(Q.inWidth,M+W),y=Number.NEGATIVE_INFINITY,k=-1,p=G;p<d;p+=I)for(var K=p-U,V=l;V<m;V+=o)for(var T=V-h,j=N;j<v;j+=n){var X=j-W,gA=F.get(s,p,V,j,u);gA>=y&&(y=gA,k=K*Y*M+T*Y+X)}w.set(k,s,a,H,f,u)}}}return w.toTensor()},g.prototype.maxPool3dBackprop=function(B,Q,w,C){EA([Q,w],"maxPool3dBackprop");for(var E=this.maxPool3dPositions(Q,C),e=C.strideDepth,I=C.strideHeight,o=C.strideWidth,n=C.dilationDepth,i=C.dilationHeight,Y=C.dilationWidth,M=C.effectiveFilterDepth,c=C.effectiveFilterHeight,D=C.effectiveFilterWidth,r=M-1-C.padInfo.front,F=D-1-C.padInfo.left,s=c-1-C.padInfo.top,u=zA(Q.shape,"float32"),a=this.bufferSync(E),U=this.bufferSync(B),G=0;G<C.batchSize;++G)for(var d=0;d<C.inChannels;++d)for(var H=0;H<C.inDepth;++H)for(var h=0;h<C.inHeight;++h)for(var l=0;l<C.inWidth;++l){for(var m=H-r,f=h-s,W=l-F,N=0,v=0;v<M;v+=n){var y=(m+v)/e;if(!(y<0||y>=C.outDepth||Math.floor(y)!==y))for(var k=0;k<c;k+=i){var p=(f+k)/I;if(!(p<0||p>=C.outHeight||Math.floor(p)!==p))for(var K=0;K<D;K+=Y){var V=(W+K)/o;if(!(V<0||V>=C.outWidth||Math.floor(V)!==V)){var T=M*c*D-1-a.get(G,y,p,V,d)===v*c*D+k*D+K?1:0;T!==0&&(N+=U.get(G,y,p,V,d)*T)}}}}u.set(N,G,H,h,l,d)}return u.toTensor()},g.prototype.cast=function(B,Q){return Uc(B,Q,this)},g.prototype.reshape=function(B,Q){return Et(B,Q)},g.prototype.avgPool=function(B,Q){return EA(B,"avgPool"),this.pool(B,Q,"avg").toFloat()},g.prototype.resizeBilinear=function(B,Q,w,C){EA(B,"resizeBilinear");for(var E=B.shape,e=E[0],I=E[1],o=E[2],n=E[3],i=this.readSync(B.dataId),Y=new Float32Array(hA([e,Q,w,n])),M=[C&&Q>1?I-1:I,C&&w>1?o-1:o],c=[C&&Q>1?Q-1:Q,C&&w>1?w-1:w],D=0,r=M[0]/c[0],F=M[1]/c[1],s=0;s<e;s++)for(var u=0;u<Q;u++)for(var a=r*u,U=Math.floor(a),G=a-U,d=Math.min(I-1,Math.ceil(a)),H=s*B.strides[0]+U*B.strides[1],h=s*B.strides[0]+d*B.strides[1],l=0;l<w;l++)for(var m=F*l,f=Math.floor(m),W=m-f,N=Math.min(o-1,Math.ceil(m)),v=H+f*B.strides[2],y=h+f*B.strides[2],k=H+N*B.strides[2],p=h+N*B.strides[2],K=0;K<n;K++){var V=i[v+K],T=i[y+K],j=V+(i[k+K]-V)*W,X=j+(T+(i[p+K]-T)*W-j)*G;Y[D++]=X}return Ag(Y,[e,Q,w,n])},g.prototype.resizeBilinearBackprop=function(B,Q,w){EA([B,Q],"resizeBilinearBackprop");for(var C=Q.shape,E=C[0],e=C[1],I=C[2],o=C[3],n=B.shape,i=n[1],Y=n[2],M=new Float32Array(E*e*I*o),c=[w&&i>1?e-1:e,w&&Y>1?I-1:I],D=[w&&i>1?i-1:i,w&&Y>1?Y-1:Y],r=c[0]/D[0],F=c[1]/D[1],s=this.readSync(B.dataId),u=0,a=0;a<E;a++)for(var U=a*Q.strides[0],G=0;G<i;G++)for(var d=G*r,H=Math.floor(d),h=Math.min(Math.ceil(d),e-1),l=U+H*Q.strides[1],m=U+h*Q.strides[1],f=d-H,W=1-f,N=0;N<Y;N++)for(var v=N*F,y=Math.floor(v),k=Math.min(Math.ceil(v),I-1),p=v-y,K=1-p,V=l+y*Q.strides[2],T=l+k*Q.strides[2],j=m+y*Q.strides[2],X=m+k*Q.strides[2],gA=W*K,CA=W*p,wA=f*K,eA=f*p,YA=0;YA<o;YA++){var $=s[u++];M[V+YA]+=$*gA,M[T+YA]+=$*CA,M[j+YA]+=$*wA,M[X+YA]+=$*eA}return Dg(M,[E,I,e,o],Q.dtype)},g.prototype.resizeNearestNeighbor=function(B,Q,w,C){EA(B,"resizeNearestNeighbor");for(var E=B.shape,e=E[0],I=E[1],o=E[2],n=E[3],i=this.readSync(B.dataId),Y=new Float32Array(e*Q*w*n),M=[C&&Q>1?I-1:I,C&&w>1?o-1:o],c=[C&&Q>1?Q-1:Q,C&&w>1?w-1:w],D=M[0]/c[0],r=M[1]/c[1],F=0,s=0;s<e;s++)for(var u=s*B.strides[0],a=0;a<Q;a++)for(var U=D*a,G=u+Math.min(I-1,C?Math.round(U):Math.floor(U))*B.strides[1],d=0;d<w;d++)for(var H=r*d,h=G+Math.min(o-1,C?Math.round(H):Math.floor(H))*B.strides[2],l=0;l<n;l++){var m=i[h+l];Y[F++]=m}return Ag(Y,[e,Q,w,n],B.dtype)},g.prototype.resizeNearestNeighborBackprop=function(B,Q,w){EA([B,Q],"resizeNearestNeighborBackprop");for(var C=Q.shape,E=C[0],e=C[1],I=C[2],o=C[3],n=B.shape,i=n[1],Y=n[2],M=new Float32Array(E*e*I*o),c=this.readSync(B.dataId),D=[w&&i>1?e-1:e,w&&Y>1?I-1:I],r=[w&&i>1?i-1:i,w&&Y>1?Y-1:Y],F=D[0]/r[0],s=D[1]/r[1],u=1/F,a=1/s,U=2*Math.ceil(u)+2,G=2*Math.ceil(a)+2,d=0;d<E;d++)for(var H=d*Q.strides[0],h=0;h<e;h++)for(var l=H+h*Q.strides[1],m=Math.floor(h*u),f=Math.floor(m-U/2),W=0;W<I;W++)for(var N=l+W*Q.strides[2],v=Math.floor(W*a),y=Math.floor(v-G/2),k=0;k<o;k++){for(var p=0,K=0;K<U;K++){var V=K+f;if(!(V<0||V>=i)){var T=H+V*B.strides[1],j=V*F;if(h===Math.min(e-1,w?Math.round(j):Math.floor(j)))for(var X=0;X<G;X++){var gA=X+y;if(!(gA<0||gA>=Y)){var CA=T+gA*B.strides[2],wA=gA*s;W===Math.min(I-1,w?Math.round(wA):Math.floor(wA))&&(p+=c[CA+k])}}}}M[N+k]=p}return Dg(M,Q.shape,Q.dtype)},g.prototype.batchNormalization=function(B,Q,w,C,E,e){EA([B,Q,w,E,e],"batchNorm");for(var I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=this.readSync(w.dataId),i=E?this.readSync(E.dataId):new Float32Array([1]),Y=e?this.readSync(e.dataId):new Float32Array([0]),M=new Float32Array(I.length),c=Y.length,D=i.length,r=n.length,F=o.length,s=0,u=0,a=0,U=0,G=0;G<I.length;++G)M[G]=Y[s++]+(I[G]-o[u++])*i[a++]/Math.sqrt(n[U++]+C),s>=c&&(s=0),u>=F&&(u=0),a>=D&&(a=0),U>=r&&(U=0);return Dg(M,B.shape)},g.prototype.localResponseNormalization4D=function(B,Q,w,C,E){EA(B,"localResponseNormalization4D");var e=B.shape[3],I=e-1,o=this.readSync(B.dataId),n=B.size,i=new Float32Array(n);function Y(r){for(var F=r%e,s=r-F+Math.max(0,F-Q),u=r-F+Math.min(F+Q,I),a=0;s<=u;s++){var U=o[s];a+=U*U}return a}for(var M=0;M<n;M++){var c=Y(M),D=o[M]*Math.pow(w+C*c,-E);i[M]=D}return Dg(i,B.shape)},g.prototype.LRNGrad=function(B,Q,w,C,E,e,I){EA(B,"LRNGrad");for(var o=B.shape[3],n=this.readSync(B.dataId),i=this.readSync(Q.dataId),Y=this.readSync(w.dataId),M=new Float32Array(B.size),c=B.size,D=0;D<c;D++){for(var r=D%o,F=D-r+Math.max(0,r-C),s=D-r+Math.min(o,r+C+1),u=0,a=F;a<s;a++)u+=Math.pow(i[a],2);for(u=e*u+E,a=F;a<s;a++){var U=-2*e*I*i[a]*Y[D]/u;D===a&&(U+=Math.pow(u,-I)),U*=n[D],M[a]+=U}}return Dg(M,B.shape)},g.prototype.multinomial=function(B,Q,w,C){EA(B,"multinomial");for(var E=Q?B:rQ(B),e=E.shape[0],I=E.shape[1],o=DB([e,w],"int32"),n=this.readSync(o.dataId),i=this.readSync(E.dataId),Y=0;Y<e;++Y){var M=Y*I,c=new Float32Array(I-1);c[0]=i[M];for(var D=1;D<c.length;++D)c[D]=c[D-1]+i[M+D];for(var r=Ce(C.toString()),F=Y*w,s=0;s<w;++s){var u=r();n[F+s]=c.length;for(var a=0;a<c.length;a++)if(u<c[a]){n[F+s]=a;break}}}return o},g.prototype.oneHot=function(B,Q,w,C){EA(B,"oneHot");var E=new Float32Array(B.size*Q);E.fill(C);for(var e=this.readSync(B.dataId),I=0;I<B.size;++I)e[I]>=0&&e[I]<Q&&(E[I*Q+e[I]]=w);return RQ(E,[B.size,Q],"int32")},g.prototype.nonMaxSuppression=function(B,Q,w,C,E){return EA(B,"nonMaxSuppression"),It(this.readSync(B.dataId),this.readSync(Q.dataId),w,C,E)},g.prototype.fft=function(B){return this.fftBatch(B,!1)},g.prototype.ifft=function(B){return this.fftBatch(B,!0)},g.prototype.fftBatch=function(B,Q){for(var w=B.shape[0],C=B.shape[1],E=zA(B.shape,"float32"),e=zA(B.shape,"float32"),I=kg(B).as2D(w,C),o=BQ(B).as2D(w,C),n=0;n<w;n++)for(var i=I.slice([n,0],[1,C]),Y=o.slice([n,0],[1,C]),M=$B(i,Y),c=this.readSync(this.fftImpl(M,Q).dataId),D=0;D<C;D++){var r=hc(c,D);E.values[n*C+D]=r.real,e.values[n*C+D]=r.imag}return $B(E.toTensor(),e.toTensor()).as2D(w,C)},g.prototype.fftImpl=function(B,Q){var w=B.as1D(),C=w.size;if(this.isExponentOf2(C)){var E=this.fftRadix2(w,C,Q).as2D(B.shape[0],B.shape[1]);return Q&&(E=$B(kg(E).div(nA(C)),BQ(E).div(nA(C)))),E}var e=this.readSync(B.dataId),I=function(o){for(var n=new Float32Array(o.length/2),i=new Float32Array(o.length/2),Y=0;Y<o.length;Y+=2)n[Y/2]=o[Y],i[Y/2]=o[Y+1];return{real:n,imag:i}}(this.fourierTransformByMatmul(e,C,Q));return $B(I.real,I.imag).as2D(B.shape[0],B.shape[1])},g.prototype.isExponentOf2=function(B){return(B&B-1)==0},g.prototype.fftRadix2=function(B,Q,w){if(Q===1)return B;var C=this.readSync(B.dataId),E=Q/2,e=function(F){for(var s=Math.ceil(F.length/4),u=new Float32Array(s),a=new Float32Array(s),U=0;U<F.length;U+=4)u[Math.floor(U/4)]=F[U],a[Math.floor(U/4)]=F[U+1];return{real:u,imag:a}}(C),I=$B(e.real,e.imag).as1D(),o=function(F){for(var s=Math.floor(F.length/4),u=new Float32Array(s),a=new Float32Array(s),U=2;U<F.length;U+=4)u[Math.floor(U/4)]=F[U],a[Math.floor(U/4)]=F[U+1];return{real:u,imag:a}}(C),n=$B(o.real,o.imag).as1D();I=this.fftRadix2(I,E,w),n=this.fftRadix2(n,E,w);var i=function(F,s){for(var u=new Float32Array(F/2),a=new Float32Array(F/2),U=0;U<Math.ceil(F/2);U++){var G=(s?2:-2)*Math.PI*(U/F);u[U]=Math.cos(G),a[U]=Math.sin(G)}return{real:u,imag:a}}(Q,w),Y=$B(i.real,i.imag).mul(n),M=I.add(Y),c=I.sub(Y),D=kg(M).concat(kg(c)),r=BQ(M).concat(BQ(c));return $B(D,r).as1D()},g.prototype.fourierTransformByMatmul=function(B,Q,w){for(var C=new Float32Array(2*Q),E=0;E<Q;E++){for(var e=0,I=0,o=0;o<Q;o++){var n=tf(E*o,Q,w),i=hc(B,o);e+=i.real*n.real-i.imag*n.imag,I+=i.real*n.imag+i.imag*n.real}w&&(e/=Q,I/=Q),of(C,e,I,E)}return C},g.prototype.depthToSpace=function(B,Q,w){R(w==="NHWC",function(){return"Only NHWC dataFormat supported on CPU for depthToSpace. Got "+w}),R(Q>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+Q});for(var C=B.shape[0],E=B.shape[1],e=B.shape[2],I=B.shape[3],o=E*Q,n=e*Q,i=I/(Q*Q),Y=this.readSync(B.dataId),M=new Float32Array(C*o*n*i),c=0,D=0;D<C;++D)for(var r=0;r<o;++r)for(var F=Math.floor(r/Q),s=r%Q,u=0;u<n;++u)for(var a=Math.floor(u/Q),U=(s*Q+u%Q)*i,G=0;G<i;++G){var d=G+U+I*(a+e*(F+E*D));M[c++]=Y[d]}return Dg(M,[C,o,n,i])},g.prototype.broadcastedBinaryOp=function(B,Q,w,C){var E=qA(B.shape,Q.shape),e=zA(E,w),I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=PQ(B.shape,E),i=PQ(Q.shape,E),Y=e.values;if(n.length+i.length===0)for(var M=0;M<Y.length;++M)Y[M]=C(I[M%I.length],o[M%o.length]);else{var c=this.bufferSync(B),D=this.bufferSync(Q),r=function(F){var s=e.indexToLoc(F),u=s.slice(-B.rank);n.forEach(function(d){return u[d]=0});var a=c.locToIndex(u),U=s.slice(-Q.rank);i.forEach(function(d){return U[d]=0});var G=D.locToIndex(U);Y[F]=C(I[a],o[G])};for(M=0;M<Y.length;++M)r(M)}return e.toTensor()},g.prototype.broadcastedBinaryComplexOp=function(B,Q,w){var C=qA(B.shape,Q.shape),E=zA(C,"float32"),e=zA(C,"float32"),I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=PQ(B.shape,C),i=PQ(Q.shape,C),Y=E.values,M=e.values;if(n.length+i.length===0)for(var c=0;c<Y.length;c++){var D=c%I.length,r=c%o.length,F=w(I[2*D],I[2*D+1],o[2*r],o[2*r+1]);Y[c]=F.real,M[c]=F.imag}else{var s=this.bufferSync(this.data.get(B.dataId).complexTensors.real),u=this.bufferSync(this.data.get(Q.dataId).complexTensors.real),a=function(U){var G=E.indexToLoc(U),d=G.slice(-B.rank);n.forEach(function(f){return d[f]=0});var H=s.locToIndex(d),h=G.slice(-Q.rank);i.forEach(function(f){return h[f]=0});var l=u.locToIndex(h),m=w(I[2*H],I[2*H+1],o[2*l],o[2*l+1]);Y[U]=m.real,M[U]=m.imag};for(c=0;c<Y.length;c++)a(c)}return this.complex(E.toTensor(),e.toTensor())},g.prototype.split=function(B,Q,w){return Hc(B,Q,w)},g.prototype.dispose=function(){},g.prototype.floatPrecision=function(){return 32},g.prototype.epsilon=function(){return 1e-7},g.prototype.cropAndResize=function(B,Q,w,C,E,e){for(var I=B.shape,o=I[0],n=I[1],i=I[2],Y=I[3],M=Q.shape[0],c=C[0],D=C[1],r=zA([M,c,D,Y],"float32"),F=this.readSync(Q.dataId),s=this.readSync(w.dataId),u=this.readSync(B.dataId),a=B.strides,U=r.strides,G=0;G<M;G++){var d=4*G,H=F[d],h=F[d+1],l=F[d+2],m=F[d+3],f=s[G];if(!(f>=o))for(var W=c>1?(l-H)*(n-1)/(c-1):0,N=D>1?(m-h)*(i-1)/(D-1):0,v=0;v<c;v++){var y=c>1?H*(n-1)+v*W:.5*(H+l)*(n-1);if(y<0||y>n-1)for(var k=0;k<D;k++)for(var p=0;p<Y;p++){var K=p+k*U[2]+v*U[1]+G*U[0];r.values[K]=e}else if(E==="bilinear"){var V=Math.floor(y),T=Math.ceil(y),j=y-V;for(k=0;k<D;k++)if((oA=D>1?h*(i-1)+k*N:.5*(h+m)*(i-1))<0||oA>i-1)for(p=0;p<Y;p++)K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=e;else{var X=Math.floor(oA),gA=Math.ceil(oA),CA=oA-X;for(p=0;p<Y;p++){var wA=u[K=p+X*a[2]+V*a[1]+f*a[0]],eA=u[K=p+gA*a[2]+V*a[1]+f*a[0]],YA=u[K=p+X*a[2]+T*a[1]+f*a[0]],$=wA+(eA-wA)*CA,RA=YA+(u[K=p+gA*a[2]+T*a[1]+f*a[0]]-YA)*CA;K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=$+(RA-$)*j}}}else for(k=0;k<D;++k){var oA;if((oA=D>1?h*(i-1)+k*N:.5*(h+m)*(i-1))<0||oA>i-1)for(p=0;p<Y;p++)K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=e;else{var aA=Math.round(oA),JA=Math.round(y);for(p=0;p<Y;p++){var VA=p+aA*a[2]+JA*a[1]+f*a[0],bA=p+k*U[2]+v*U[1]+G*U[0];r.values[bA]=u[VA]}}}}}return r.toTensor()},g.prototype.sparseToDense=function(B,Q,w,C){var E=oe(0,B,w),e=E.sliceRank,I=E.numUpdates,o=E.sliceSize,n=E.strides,i=E.outputSize;return this.scatter(B,Q,w,i,o,I,e,n,C,!1)},g.prototype.gatherND=function(B,Q){var w=Q.shape,C=w[w.length-1],E=Mc(B,Q),e=E[0],I=E[1],o=E[2],n=E[3];if(I===0)return Ag([],e,B.dtype);for(var i=new RC([I,o],B.dtype),Y=this.readSync(Q.dataId),M=this.readSync(B.dataId),c=0;c<I;c++){for(var D=[],r=0,F=0;F<C;F++){var s=Y[c*C+F];r+=s*n[F],D.push(s)}if(r<0||r>=B.size/o)throw new Error("Invalid indices: "+D+" does not index into "+B.shape);for(var u=0;u<o;u++)i.values[c*o+u]=M[r*o+u]}return i.toTensor().reshape(e)},g.prototype.scatterND=function(B,Q,w){var C=oe(0,B,w),E=C.sliceRank,e=C.numUpdates,I=C.sliceSize,o=C.strides,n=C.outputSize,i=nA(0);return this.scatter(B,Q,w,n,I,e,E,o,i,!0)},g.prototype.fill=function(B,Q,w){var C=xE(w=w||HC(Q),hA(B));return C.fill(Q),b.makeTensor(C,B,w,this)},g.prototype.onesLike=function(B){if(B.dtype==="string")throw new Error("onesLike is not supported for string tensors");return this.fill(B.shape,1,B.dtype)},g.prototype.zerosLike=function(B){var Q=xE(B.dtype,hA(B.shape));return this.makeOutput(Q,B.shape,B.dtype)},g.prototype.linspace=function(B,Q,w){return Gc(B,Q,w)},g.prototype.scatter=function(B,Q,w,C,E,e,I,o,n,i){var Y=[C/E,E],M=this.readSync(B.dataId),c=this.readSync(Q.dataId);if(C===0)return Ag([],w,Q.dtype);var D=new RC(Y,Q.dtype);D.values.fill(this.readSync(n.dataId)[0]);for(var r=0;r<e;r++){for(var F=[],s=0,u=0;u<I;u++){var a=M[r*I+u];F.push(a),s+=a*o[u]}if(s<0||s>=C/E)throw new Error("Invalid indices: "+F+" does not index into "+w);for(var U=0;U<E;U++)i?D.values[s*E+U]+=c[r*E+U]:D.values[s*E+U]=Q.rank===0?c[0]:c[r*E+U]}return D.toTensor().reshape(w)},g}(sc);b.registerBackend("cpu",function(){return new m0},1);for(var jt=0,yD=[{kernelName:"NonMaxSuppressionV5",backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs,w=g,C=w.boxes,E=w.scores,e=Q,I=e.maxOutputSize,o=e.iouThreshold,n=e.scoreThreshold,i=e.softNmsSigma,Y=B;EA(C,"NonMaxSuppressionWithScore");var M=ot(Y.data.get(C.dataId).values,Y.data.get(E.dataId).values,I,o,n,i);return[M.selectedIndices,M.selectedScores]}},{kernelName:"Square",backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g.x,w=B;EA(Q,"square");for(var C=w.data.get(Q.dataId).values,E=new Float32Array(C.length),e=0;e<C.length;++e){var I=C[e];E[e]=I*I}return{dataId:w.write(E,Q.shape,Q.dtype),shape:Q.shape,dtype:Q.dtype}}},{kernelName:zC,backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g,w=Q.a,C=Q.b,E=B;EA([w,C],zC);var e=E.data.get(w.dataId).values,I=E.data.get(C.dataId).values,o=function(Y,M,c,D,r,F){var s=qA(Y,M),u=s.length,a=Og(s),U=dC(r,hA(s)),G=Y.length,d=M.length,H=Og(Y),h=Og(M),l=PQ(Y,s),m=PQ(M,s);if(l.length+m.length===0)for(var f=0;f<U.length;++f)U[f]=F(c[f%c.length],D[f%D.length]);else{var W=function(N){var v=zd(N,u,a),y=v.slice(-G);l.forEach(function(V){return y[V]=0});var k=VM(y,G,H),p=v.slice(-d);m.forEach(function(V){return p[V]=0});var K=VM(p,d,h);U[N]=F(c[k],D[K])};for(f=0;f<U.length;++f)W(f)}return[U,s]}(w.shape,C.shape,e,I,w.dtype,function(Y,M){var c=Y-M;return c*c}),n=o[0],i=o[1];return{dataId:E.write(n,i,w.dtype),shape:i,dtype:w.dtype}}}];jt<yD.length;jt++)jM(yD[jt]);for(var Xw,R0=function(A){this.variableNames=["A"];var g=Qg(),B=A[0],Q=A[1];this.outputShape=A,this.userCode=`
3764
+ ============================`));var C={};return this.data.set(C,{values:B,dtype:w}),C},g.prototype.move=function(B,Q,w,C){this.data.set(B,{values:Q,dtype:C})},g.prototype.numDataIds=function(){return this.data.numDataIds()},g.prototype.read=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){return[2,this.readSync(B)]})})},g.prototype.readSync=function(B){var Q=this.data.get(B),w=Q.dtype,C=Q.complexTensors;return w==="complex64"?It(this.readSync(C.real.dataId),this.readSync(C.imag.dataId)):this.data.get(B).values},g.prototype.bufferSync=function(B){var Q=this.readSync(B.dataId),w=Q;if(B.dtype==="string")try{w=Q.map(function(C){return XE(C)})}catch{throw new Error("Failed to decode encoded string bytes into utf-8")}return zA(B.shape,B.dtype,w)},g.prototype.makeOutput=function(B,Q,w){var C=this.write(B,Q,w);return b.makeTensorFromDataId(C,Q,w,this)},g.prototype.disposeData=function(B){if(this.data.has(B)){var Q=this.data.get(B).complexTensors;Q!=null&&(Q.real.dispose(),Q.imag.dispose()),this.data.delete(B)}},g.prototype.time=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){return Q=Zg(),B(),[2,{kernelMs:Zg()-Q}]})})},g.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},g.prototype.complex=function(B,Q){var w=this.makeOutput(null,B.shape,"complex64");return this.data.get(w.dataId).complexTensors={real:b.keep(B.clone()),imag:b.keep(Q.clone())},w},g.prototype.real=function(B){return this.data.get(B.dataId).complexTensors.real.clone()},g.prototype.imag=function(B){return this.data.get(B.dataId).complexTensors.imag.clone()},g.prototype.slice=function(B,Q,w){if(EA(B,"slice"),rc(B.shape,Q,w)){var C=Fc(Q,B.strides),E=hA(w);return Ag(this.readSync(B.dataId).subarray(C,C+E),w,B.dtype)}for(var e=zA(w,B.dtype),I=this.bufferSync(B),o=0;o<e.size;++o){var n=e.indexToLoc(o).map(function(i,Y){return i+Q[Y]});e.values[o]=I.get.apply(I,n)}return e.toTensor()},g.prototype.stridedSlice=function(B,Q,w,C){EA(B,"stridedSlice");var E=wt(Q,w,C);if(E.some(function(M){return M===0}))return Ag([],E);for(var e=zA(E,B.dtype),I=this.bufferSync(B),o=0;o<e.size;o++){for(var n=e.indexToLoc(o),i=new Array(n.length),Y=0;Y<i.length;Y++)i[Y]=n[Y]*C[Y]+Q[Y];e.set.apply(e,[I.get.apply(I,i)].concat(n))}return e.toTensor()},g.prototype.diag=function(B){for(var Q=this.readSync(B.dataId),w=zA([B.size,B.size],B.dtype),C=w.values,E=0;E<Q.length;E++)C[E*B.size+E]=Q[E];return w.toTensor()},g.prototype.unstack=function(B,Q){for(var w=B.shape[Q],C=new Array(B.rank-1),E=0,e=0;e<B.rank;e++)e!==Q&&(C[E++]=B.shape[e]);var I=new Array(B.rank).fill(0),o=B.shape.slice();o[Q]=1;var n=new Array(w);for(e=0;e<n.length;e++)I[Q]=e,n[e]=this.slice(B,I,o).reshape(C);return n},g.prototype.reverse=function(B,Q){EA(B,"reverse");for(var w=zA(B.shape,B.dtype),C=this.bufferSync(B),E=function(I){var o=w.indexToLoc(I),n=o.slice();Q.forEach(function(i){return n[i]=B.shape[i]-1-n[i]}),w.set.apply(w,[C.get.apply(C,n)].concat(o))},e=0;e<w.size;e++)E(e);return w.toTensor()},g.prototype.concat=function(B,Q){var w=this;if(B[0].dtype==="complex64"){var C=B.map(function(M){return kg(M)}),E=B.map(function(M){return BQ(M)});return $B(this.concat(C,Q),this.concat(E,Q))}var e=B.map(function(M){var c=hA(M.shape.slice(Q));return M.as2D(-1,c)}),I=yw(e.map(function(M){return M.shape}),1),o=zA(I,B[0].dtype).values;if(e[0].shape[0]===1){var n=0;e.forEach(function(M){o.set(w.readSync(M.dataId),n),n+=M.size})}else{var i=0;e.forEach(function(M){for(var c=w.readSync(M.dataId),D=0,r=0;r<M.shape[0];++r)for(var F=r*I[1]+i,s=0;s<M.shape[1];++s)o[F+s]=c[D++];i+=M.shape[1]})}var Y=yw(B.map(function(M){return M.shape}),Q);return Ag(o,Y,B[0].dtype)},g.prototype.neg=function(B){return EA(B,"neg"),this.multiply(nA(-1),B)},g.prototype.add=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w+E,imag:C+e}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w+C})},g.prototype.addN=function(B){var Q=this;EA(B,"addN");for(var w=B.map(function(n){return Q.readSync(n.dataId)}),C=zA(B[0].shape,B[0].dtype),E=C.values,e=0;e<B.length;e++)for(var I=w[e],o=0;o<E.length;o++)E[o]+=I[o];return C.toTensor()},g.prototype.softmax=function(B,Q){var w=TB([Q],B.shape),C=this.max(B,w),E=cg(C.shape,w),e=this.subtract(B,C.reshape(E)),I=this.exp(e),o=this.sum(I,w).reshape(E);return this.realDivide(I,o)},g.prototype.subtract=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w-E,imag:C-e}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w-C})},g.prototype.pow=function(B,Q){return EA([B,Q],"pow"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.pow(w,C)})},g.prototype.batchMatMul=function(B,Q,w,C){EA([B,Q],"matMul");for(var E=w?B.shape[1]:B.shape[2],e=w?B.shape[2]:B.shape[1],I=C?Q.shape[1]:Q.shape[2],o=B.shape[0],n=this.readSync(B.dataId),i=this.readSync(Q.dataId),Y=w?[B.strides[0],1,B.strides[1]]:[B.strides[0],B.strides[1],1],M=Y[0],c=Y[1],D=Y[2],r=C?[1,Q.strides[1],Q.strides[0]]:[Q.strides[1],1,Q.strides[0]],F=r[0],s=r[1],u=r[2],a=e*I,U=zA([o,e,I],B.dtype),G=U.values,d=this.blockSize,H=0;H<o;H++)for(var h=0;h<e;h+=d)for(var l=0;l<I;l+=d)for(var m=0;m<E;m+=d)for(var f=Math.min(h+d,e),W=Math.min(l+d,I),N=Math.min(m+d,E),v=h;v<f;v++)for(var y=l;y<W;y++){for(var k=0,p=m;p<N;p++)k+=n[H*M+v*c+p*D]*i[p*F+y*s+H*u];G[H*a+(v*I+y)]+=k}return U.toTensor()},g.prototype.fusedBatchMatMul=function(B){var Q=B.a,w=B.b,C=B.transposeA,E=B.transposeB,e=B.bias,I=B.activation,o=B.preluActivationWeights,n=this.batchMatMul(Q,w,C,E);return e&&(n=this.add(n,e)),I&&(n=jt(this,n,I,o)),n},g.prototype.multiply=function(B,Q){return B.dtype==="complex64"||Q.dtype==="complex64"?this.broadcastedBinaryComplexOp(B.cast("complex64"),Q.cast("complex64"),function(w,C,E,e){return{real:w*E-C*e,imag:w*e+C*E}}):this.broadcastedBinaryOp(B,Q,_B(B.dtype,Q.dtype),function(w,C){return w*C})},g.prototype.realDivide=function(B,Q){return EA([B,Q],"realDivide"),this.broadcastedBinaryOp(B,Q,"float32",function(w,C){return w/C})},g.prototype.floorDiv=function(B,Q){return EA([B,Q],"floorDiv"),this.broadcastedBinaryOp(B,Q,"int32",function(w,C){return Math.floor(w/C)})},g.prototype.sum=function(B,Q){EA(B,"sum"),dg("sum",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,_B(B.dtype,"int32")),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=0,c=0;c<I;++c)M+=n[Y+c];o[i]=M}return e},g.prototype.prod=function(B,Q){EA(B,"sum");for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,_B(B.dtype,"int32")),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=1,c=0;c<I;++c)M*=n[Y+c];o[i]=M}return e},g.prototype.unsortedSegmentSum=function(B,Q,w){EA(B,"unsortedSegmentSum");for(var C=[],E=B.rank-Q.rank,e=0;e<E;++e)Q=Q.expandDims(e+1);for(e=0;e<w;++e){var I=nA(e,"int32"),o=cD(I,Q).asType("float32").mul(B).sum(0);C.push(o)}return Hg(C)},g.prototype.argMin=function(B,Q){EA(B,"argMin");var w=[Q];dg("argMin",w,B.rank);for(var C=gg(B.shape,w),E=C[0],e=C[1],I=DB(E,"int32"),o=hA(e),n=this.readSync(I.dataId),i=this.readSync(B.dataId),Y=0;Y<n.length;++Y){for(var M=Y*o,c=i[M],D=0,r=0;r<o;++r){var F=i[M+r];F<c&&(c=F,D=r)}n[Y]=D}return I},g.prototype.argMax=function(B,Q){EA(B,"argMax");var w=[Q];dg("argMax",w,B.rank);for(var C=gg(B.shape,w),E=C[0],e=C[1],I=DB(E,"int32"),o=hA(e),n=this.readSync(I.dataId),i=this.readSync(B.dataId),Y=0;Y<n.length;++Y){for(var M=Y*o,c=i[M],D=0,r=0;r<o;++r){var F=i[M+r];F>c&&(c=F,D=r)}n[Y]=D}return I},g.prototype.cumsum=function(B,Q,w,C){if(EA(B,"cumsum"),Q!==B.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(B.rank-1)+" but got axis="+Q);for(var E=_B(B.dtype,"int32"),e=DB(B.shape,E),I=this.readSync(e.dataId),o=this.readSync(B.dataId),n=B.shape[B.rank-1],i=C?function(r,F){return r+n-F-1}:function(r,F){return r+F},Y=0;Y<o.length;Y+=n)for(var M=0;M<n;M++){var c=i(Y,M);if(M===0)I[c]=w?0:o[c];else{var D=i(Y,M-1);I[c]=w?o[D]+I[D]:o[c]+I[D]}}return e},g.prototype.equal=function(B,Q){return EA([B,Q],"equal"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w===C?1:0})},g.prototype.notEqual=function(B,Q){return EA([B,Q],"notEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w!==C?1:0})},g.prototype.less=function(B,Q){return EA([B,Q],"less"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w<C?1:0})},g.prototype.lessEqual=function(B,Q){return EA([B,Q],"lessEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w<=C?1:0})},g.prototype.greater=function(B,Q){return EA([B,Q],"greater"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w>C?1:0})},g.prototype.greaterEqual=function(B,Q){return EA([B,Q],"greaterEqual"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w>=C?1:0})},g.prototype.logicalNot=function(B){EA(B,"logicalNot");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)w[C]=Q[C]?0:1;return this.makeOutput(w,B.shape,"bool")},g.prototype.logicalAnd=function(B,Q){return EA([B,Q],"logicalAnd"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w&&C})},g.prototype.logicalOr=function(B,Q){return EA([B,Q],"logicalOr"),this.broadcastedBinaryOp(B,Q,"bool",function(w,C){return w||C})},g.prototype.select=function(B,Q,w){EA([B,Q,w],"select");for(var C=this.readSync(B.dataId),E=this.readSync(Q.dataId),e=this.readSync(w.dataId),I=DB(Q.shape,_B(Q.dtype,w.dtype)),o=this.readSync(I.dataId),n=0,i=B.rank===0||B.rank>1||Q.rank===1?1:hA(Q.shape.slice(1)),Y=0;Y<C.length;Y++)for(var M=0;M<i;M++)C[Y]===1?o[n++]=E[Y]:o[n++]=e[Y];return I},g.prototype.where=function(B){EA([B],"where");var Q=this.readSync(B.dataId);return nt(B.shape,Q)},g.prototype.topk=function(B,Q,w){return EA(B,"topk"),Jc(this.readSync(B.dataId),B.shape,B.dtype,Q)},g.prototype.min=function(B,Q){EA(B,"min"),dg("min",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];D<M&&(M=D)}o[i]=M}return e},g.prototype.minimum=function(B,Q){return EA([B,Q],"minimum"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.min(w,C)})},g.prototype.mod=function(B,Q){return EA([B,Q],"mod"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){var E=w%C;return w<0&&C<0||w>=0&&C>=0?E:(E+C)%C})},g.prototype.max=function(B,Q){EA(B,"max"),dg("max",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];D>M&&(M=D)}o[i]=M}return e},g.prototype.maximum=function(B,Q){return EA([B,Q],"maximum"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.max(w,C)})},g.prototype.all=function(B,Q){EA(B,"all"),dg("all",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];M=M&&D}o[i]=M}return e},g.prototype.any=function(B,Q){EA(B,"any"),dg("any",Q,B.rank);for(var w=gg(B.shape,Q),C=w[0],E=w[1],e=DB(C,B.dtype),I=hA(E),o=this.readSync(e.dataId),n=this.readSync(B.dataId),i=0;i<o.length;++i){for(var Y=i*I,M=n[Y],c=0;c<I;++c){var D=n[Y+c];M=M||D}o[i]=M}return e},g.prototype.squaredDifference=function(B,Q){return EA([B,Q],"squaredDifference"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){var E=w-C;return E*E})},g.prototype.ceil=function(B){EA(B,"ceil");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.ceil(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.floor=function(B){EA(B,"floor");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.floor(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.sign=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)Q[C]<0?w[C]=-1:Q[C]>0?w[C]=1:w[C]=0;return this.makeOutput(w,B.shape,"float32")},g.prototype.isNaN=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Number.isNaN(Q[C])&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.isInf=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Math.abs(Q[C])===1/0&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.isFinite=function(B){EA(B,"x");for(var Q=this.readSync(B.dataId),w=new Uint8Array(Q.length),C=0;C<Q.length;++C)Number.isFinite(Q[C])&&(w[C]=1);return this.makeOutput(w,B.shape,"bool")},g.prototype.round=function(B){EA(B,"round");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Math.floor(Q[C]);Q[C]-E<.5?w[C]=Math.floor(Q[C]):Q[C]-E>.5?w[C]=Math.ceil(Q[C]):w[C]=E%2==0?E:E+1}return this.makeOutput(w,B.shape,"float32")},g.prototype.exp=function(B){EA(B,"exp");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.exp(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.expm1=function(B){EA(B,"expm1");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=Math.expm1(Q[C]);return this.makeOutput(w,B.shape,"float32")},g.prototype.log=function(B){EA(B,"log");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.log(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.log1p=function(B){EA(B,"log1p");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.log1p(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.sqrt=function(B){EA(B,"sqrt");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=Math.sqrt(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.rsqrt=function(B){EA(B,"rsqrt");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C){var E=Q[C];w[C]=1/Math.sqrt(E)}return this.makeOutput(w,B.shape,"float32")},g.prototype.reciprocal=function(B){EA(B,"reciprocal");for(var Q=this.readSync(B.dataId),w=new Float32Array(Q.length),C=0;C<Q.length;++C)w[C]=1/Q[C];return this.makeOutput(w,B.shape,"float32")},g.prototype.linear=function(B){return B},g.prototype.relu=function(B){EA(B,"relu");for(var Q=DB(B.shape,B.dtype),w=this.readSync(Q.dataId),C=this.readSync(B.dataId),E=0;E<C.length;++E)w[E]=Math.max(0,C[E]);return Q},g.prototype.relu6=function(B){EA(B,"relu");for(var Q=DB(B.shape,B.dtype),w=this.readSync(Q.dataId),C=this.readSync(B.dataId),E=0;E<C.length;++E)w[E]=Math.min(Math.max(0,C[E]),6);return Q},g.prototype.prelu=function(B,Q){return EA([B,Q],"prelu"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return w<0?C*w:w})},g.prototype.elu=function(B){EA(B,"elu");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C){var E=w[C];Q[C]=E>=0?E:Math.exp(E)-1}return this.makeOutput(Q,B.shape,"float32")},g.prototype.eluDer=function(B,Q){EA([B,Q],"eluDer");for(var w=new Float32Array(Q.size),C=this.readSync(Q.dataId),E=this.readSync(B.dataId),e=0;e<C.length;++e){var I=C[e];w[e]=I>=1?E[e]:E[e]*(I+1)}return this.makeOutput(w,Q.shape,"float32")},g.prototype.selu=function(B){EA(B,"selu");for(var Q=at,w=st,C=new Float32Array(B.size),E=this.readSync(B.dataId),e=0;e<E.length;++e){var I=E[e];C[e]=I>=0?w*I:Q*(Math.exp(I)-1)}return this.makeOutput(C,B.shape,"float32")},g.prototype.clip=function(B,Q,w){EA(B,"clip");for(var C=new Float32Array(B.size),E=this.readSync(B.dataId),e=0;e<E.length;++e){var I=E[e];C[e]=I>w?w:I<Q?Q:I}return this.makeOutput(C,B.shape,"float32")},g.prototype.abs=function(B){for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.abs(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.complexAbs=function(B){for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<B.size;++C){var E=w[2*C],e=w[2*C+1];Q[C]=Math.hypot(E,e)}return this.makeOutput(Q,B.shape,"float32")},g.prototype.int=function(B){EA(B,"int");for(var Q=new Int32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=w[C];return this.makeOutput(Q,B.shape,"int32")},g.prototype.sigmoid=function(B){EA(B,"sigmoid");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=1/(1+Math.exp(-w[C]));return this.makeOutput(Q,B.shape,"float32")},g.prototype.softplus=function(B){EA(B,"softplus");for(var Q=Math.log(11920928955078125e-23)+2,w=new Float32Array(B.size),C=this.readSync(B.dataId),E=0;E<C.length;++E){var e=C[E]>-Q,I=C[E]<Q,o=Math.exp(C[E]),n=void 0;n=I?o:e?C[E]:Math.log(1+o),w[E]=n}return this.makeOutput(w,B.shape,"float32")},g.prototype.sin=function(B){EA(B,"sin");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.sin(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.cos=function(B){EA(B,"cos");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.cos(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.tan=function(B){EA(B,"tan");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.tan(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.asin=function(B){EA(B,"asin");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.asin(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.acos=function(B){EA(B,"acos");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.acos(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atan=function(B){EA(B,"atan");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.atan(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atan2=function(B,Q){return EA([B,Q],"atan2"),this.broadcastedBinaryOp(B,Q,B.dtype,function(w,C){return Math.atan2(w,C)})},g.prototype.sinh=function(B){EA(B,"sinh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.sinh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.cosh=function(B){EA(B,"cosh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.cosh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.tanh=function(B){EA(B,"tanh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Pd(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.asinh=function(B){EA(B,"asinh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.asinh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.acosh=function(B){EA(B,"acosh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.acosh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.atanh=function(B){EA(B,"atanh");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C)Q[C]=Math.atanh(w[C]);return this.makeOutput(Q,B.shape,"float32")},g.prototype.erf=function(B){EA(B,"erf");for(var Q=new Float32Array(B.size),w=this.readSync(B.dataId),C=0;C<w.length;++C){var E=Math.sign(w[C]),e=Math.abs(w[C]),I=1/(1+.3275911*e);Q[C]=E*(1-((((1.061405429*I-1.453152027)*I+1.421413741)*I-.284496736)*I+.254829592)*I*Math.exp(-e*e))}return this.makeOutput(Q,B.shape,"float32")},g.prototype.step=function(B,Q){Q===void 0&&(Q=0),EA(B,"step");for(var w=new Float32Array(B.size),C=this.readSync(B.dataId),E=0;E<C.length;++E){var e=C[E];isNaN(e)?w[E]=NaN:w[E]=e>0?1:Q}return this.makeOutput(w,B.shape,"float32")},g.prototype.fusedConv2d=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights,o=this.conv2d(Q,w,C);return E&&(o=this.add(o,E)),e&&(o=jt(this,o,e,I)),o},g.prototype.conv2d=function(B,Q,w){EA([B,Q],"conv2d");for(var C=w.filterHeight,E=w.filterWidth,e=w.dilationHeight,I=w.dilationWidth,o=w.padInfo.left,n=w.padInfo.top,i=w.dataFormat==="channelsLast",Y=zA(w.outShape,B.dtype),M=B.strides[0],c=i?B.strides[1]:B.strides[2],D=i?B.strides[2]:1,r=i?1:B.strides[1],F=Y.strides[0],s=i?Y.strides[1]:Y.strides[2],u=i?Y.strides[2]:1,a=i?1:Y.strides[1],U=this.readSync(B.dataId),G=this.readSync(Q.dataId),d=Y.values,H=0;H<w.batchSize;++H)for(var h=H*M,l=H*F,m=0;m<w.outHeight;++m)for(var f=l+m*s,W=m*w.strideHeight-n,N=0;N<C;N++){var v=W+N*e;if(!(v<0||v>=w.inHeight))for(var y=N*Q.strides[0],k=h+v*c,p=0;p<w.outWidth;++p)for(var K=f+p*u,V=p*w.strideWidth-o,T=0;T<E;T++){var j=V+T*I;if(!(j<0||j>=w.inWidth))for(var X=k+j*D,gA=y+T*Q.strides[1],CA=0;CA<w.inChannels;++CA){for(var wA=U[X+CA*r],eA=0;eA<w.outChannels;++eA)d[K+eA*a]+=wA*G[gA+eA];gA+=w.outChannels}}}return Y.toTensor()},g.prototype.conv3d=function(B,Q,w){for(var C=w.filterDepth,E=w.filterHeight,e=w.filterWidth,I=w.dilationDepth,o=w.dilationHeight,n=w.dilationWidth,i=w.padInfo.front,Y=w.padInfo.left,M=w.padInfo.top,c=zA(w.outShape,B.dtype),D=this.readSync(B.dataId),r=this.readSync(Q.dataId),F=c.values,s=0;s<w.batchSize;++s)for(var u=s*B.strides[0],a=s*c.strides[0],U=0;U<w.outDepth;++U)for(var G=a+U*c.strides[1],d=U*w.strideDepth-i,H=0;H<C;H++){var h=d+H*I;if(!(h<0||h>=w.inDepth))for(var l=H*Q.strides[0],m=u+h*B.strides[1],f=0;f<w.outHeight;++f)for(var W=G+f*c.strides[2],N=f*w.strideHeight-M,v=0;v<E;v++){var y=N+v*o;if(!(y<0||y>=w.inHeight))for(var k=l+v*Q.strides[1],p=m+y*B.strides[2],K=0;K<w.outWidth;++K)for(var V=W+K*w.outChannels,T=K*w.strideWidth-Y,j=0;j<e;j++){var X=T+j*n;if(!(X<0||X>=w.inWidth))for(var gA=k+j*Q.strides[2],CA=p+X*w.inChannels,wA=gA,eA=0;eA<w.inChannels;++eA){for(var YA=D[CA+eA],$=0;$<w.outChannels;++$)F[V+$]+=YA*r[wA+$];wA+=w.outChannels}}}}return c.toTensor()},g.prototype.conv2dDerInput=function(B,Q,w){EA([B,Q],"conv2dDerInput");for(var C=zA(w.inShape,"float32"),E=C.values,e=this.readSync(B.dataId),I=this.readSync(Q.dataId),o=Q.strides,n=o[0],i=o[1],Y=o[2],M=w.batchSize,c=w.filterHeight,D=w.filterWidth,r=w.inChannels,F=w.inHeight,s=w.inWidth,u=w.outChannels,a=w.outHeight,U=w.outWidth,G=w.strideHeight,d=w.strideWidth,H=w.dataFormat,h=c-1-w.padInfo.top,l=D-1-w.padInfo.left,m=H==="channelsLast",f=C.strides[0],W=m?C.strides[1]:C.strides[2],N=m?C.strides[2]:1,v=m?1:C.strides[1],y=B.strides[0],k=m?B.strides[1]:B.strides[2],p=m?B.strides[2]:1,K=m?1:B.strides[1],V=0;V<M;++V)for(var T=0;T<r;++T)for(var j=0;j<F;++j)for(var X=j-h,gA=Math.max(0,Math.ceil(X/G)),CA=Math.min(a,(c+X)/G),wA=0;wA<s;++wA){for(var eA=wA-l,YA=Math.max(0,Math.ceil(eA/d)),$=Math.min(U,(D+eA)/d),RA=0,oA=gA;oA<CA;++oA)for(var aA=oA*G-X,JA=YA;JA<$;++JA)for(var VA=y*V+k*oA+p*JA,bA=n*(c-1-aA)+i*(D-1-(JA*d-eA))+Y*T,pA=0;pA<u;++pA)RA+=e[VA+K*pA]*I[bA+pA];E[f*V+W*j+N*wA+v*T]=RA}return C.toTensor()},g.prototype.conv3dDerInput=function(B,Q,w){for(var C=zA(w.inShape,"float32"),E=C.values,e=C.strides,I=e[0],o=e[1],n=e[2],i=e[3],Y=this.readSync(B.dataId),M=B.strides,c=M[0],D=M[1],r=M[2],F=M[3],s=this.readSync(Q.dataId),u=Q.strides,a=u[0],U=u[1],G=u[2],d=u[3],H=w.batchSize,h=w.filterDepth,l=w.filterHeight,m=w.filterWidth,f=w.inChannels,W=w.inDepth,N=w.inHeight,v=w.inWidth,y=w.outChannels,k=w.outDepth,p=w.outHeight,K=w.outWidth,V=w.strideDepth,T=w.strideHeight,j=w.strideWidth,X=h-1-w.padInfo.front,gA=l-1-w.padInfo.top,CA=m-1-w.padInfo.left,wA=0;wA<H;++wA)for(var eA=0;eA<f;++eA)for(var YA=0;YA<W;++YA)for(var $=YA-X,RA=Math.max(0,Math.ceil($/V)),oA=Math.min(k,(h+$)/V),aA=0;aA<N;++aA)for(var JA=aA-gA,VA=Math.max(0,Math.ceil(JA/T)),bA=Math.min(p,(l+JA)/T),pA=0;pA<v;++pA){for(var ZA=pA-CA,CB=Math.max(0,Math.ceil(ZA/j)),rB=Math.min(K,(m+ZA)/j),FB=0,QA=RA;QA<oA;++QA)for(var rA=QA*V-$,xA=VA;xA<bA;++xA)for(var aB=xA*T-JA,vB=CB;vB<rB;++vB)for(var ag=c*wA+D*QA+r*xA+F*vB,hB=a*(h-1-rA)+U*(l-1-aB)+G*(m-1-(vB*j-ZA))+d*eA,kB=0;kB<y;++kB)FB+=Y[ag+kB]*s[hB+kB];E[I*wA+o*YA+n*aA+i*pA+eA]=FB}return C.toTensor()},g.prototype.conv2dDerFilter=function(B,Q,w){EA([B,Q],"conv2dDerFilter");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=w.dataFormat==="channelsLast",n=zA(w.filterShape,"float32"),i=w.padInfo.left,Y=w.padInfo.top,M=this.bufferSync(B),c=this.bufferSync(Q),D=0;D<e;++D)for(var r=Math.max(0,Math.ceil((Y-D)/C)),F=Math.min(w.outHeight,(w.inHeight+Y-D)/C),s=0;s<I;++s)for(var u=Math.max(0,Math.ceil((i-s)/E)),a=Math.min(w.outWidth,(w.inWidth+i-s)/E),U=0;U<w.inChannels;++U)for(var G=0;G<w.outChannels;++G){for(var d=0,H=0;H<w.batchSize;++H)for(var h=r;h<F;++h)for(var l=D+h*C-Y,m=u;m<a;++m){var f=s+m*E-i;d+=o?M.get(H,l,f,U)*c.get(H,h,m,G):M.get(H,U,l,f)*c.get(H,G,h,m)}n.set(d,D,s,U,G)}return n.toTensor()},g.prototype.conv3dDerFilter=function(B,Q,w){for(var C=w.strideDepth,E=w.strideHeight,e=w.strideWidth,I=w.filterDepth,o=w.filterHeight,n=w.filterWidth,i=zA(w.filterShape,"float32"),Y=i.values,M=i.strides,c=M[0],D=M[1],r=M[2],F=M[3],s=this.readSync(Q.dataId),u=Q.strides,a=u[0],U=u[1],G=u[2],d=u[3],H=this.readSync(B.dataId),h=B.strides,l=h[0],m=h[1],f=h[2],W=h[3],N=w.padInfo.front,v=w.padInfo.left,y=w.padInfo.top,k=0;k<I;++k)for(var p=Math.max(0,Math.ceil((N-k)/C)),K=Math.min(w.outDepth,(w.inDepth+N-k)/C),V=k*c,T=0;T<o;++T)for(var j=Math.max(0,Math.ceil((y-T)/E)),X=Math.min(w.outHeight,(w.inHeight+y-T)/E),gA=T*D+V,CA=0;CA<n;++CA)for(var wA=Math.max(0,Math.ceil((v-CA)/e)),eA=Math.min(w.outWidth,(w.inWidth+v-CA)/e),YA=CA*r+gA,$=0;$<w.inChannels;++$)for(var RA=$*F+YA,oA=0;oA<w.outChannels;++oA){for(var aA=0,JA=0;JA<w.batchSize;++JA)for(var VA=JA*l,bA=JA*a,pA=p;pA<K;++pA)for(var ZA=(k+pA*C-N)*m+VA,CB=pA*U+bA,rB=j;rB<X;++rB)for(var FB=(T+rB*E-y)*f+ZA,QA=rB*G+CB,rA=wA;rA<eA;++rA){var xA=rA*d+QA;aA+=H[(CA+rA*e-v)*W+FB+$]*s[xA+oA]}Y[RA+oA]=aA}return i.toTensor()},g.prototype.fusedDepthwiseConv2D=function(B){var Q=B.input,w=B.filter,C=B.convInfo,E=B.bias,e=B.activation,I=B.preluActivationWeights,o=this.depthwiseConv2D(Q,w,C);return E&&(o=this.add(o,E)),e&&(o=jt(this,o,e,I)),o},g.prototype.depthwiseConv2D=function(B,Q,w){EA([B,Q],"depthwiseConv2D");for(var C=w.filterHeight,E=w.filterWidth,e=w.dilationHeight,I=w.dilationWidth,o=w.padInfo.left,n=w.padInfo.top,i=w.outChannels/w.inChannels,Y=zA(w.outShape,B.dtype),M=this.readSync(B.dataId),c=this.readSync(Q.dataId),D=Y.values,r=0;r<w.batchSize;++r)for(var F=r*B.strides[0],s=r*Y.strides[0],u=0;u<w.outHeight;++u)for(var a=s+u*Y.strides[1],U=u*w.strideHeight-o,G=0;G<C;++G){var d=U+G*e;if(!(d<0||d>=w.inHeight))for(var H=G*Q.strides[0],h=F+d*B.strides[1],l=0;l<w.outWidth;++l)for(var m=a+l*Y.strides[2],f=l*w.strideWidth-n,W=0;W<E;++W){var N=f+W*I;if(!(N<0||N>=w.inWidth))for(var v=H+W*Q.strides[1],y=h+N*w.inChannels,k=m,p=v,K=0;K<w.inChannels;++K){for(var V=M[y+K],T=0;T<i;++T)D[k+T]+=V*c[p+T];k+=i,p+=i}}}return Y.toTensor()},g.prototype.depthwiseConv2DDerInput=function(B,Q,w){EA([B,Q],"depthwiseConv2DDerInput");for(var C=zA(w.inShape,"float32"),E=C.values,e=C.strides,I=e[0],o=e[1],n=e[2],i=this.readSync(B.dataId),Y=B.strides,M=Y[0],c=Y[1],D=Y[2],r=this.readSync(Q.dataId),F=Q.strides,s=F[0],u=F[1],a=F[2],U=w.batchSize,G=w.filterHeight,d=w.filterWidth,H=w.inChannels,h=w.inHeight,l=w.inWidth,m=w.outChannels,f=w.outHeight,W=w.outWidth,N=w.strideHeight,v=w.strideWidth,y=G-1-w.padInfo.top,k=d-1-w.padInfo.left,p=m/H,K=0;K<U;++K)for(var V=0;V<H;++V)for(var T=0;T<h;++T)for(var j=T-y,X=Math.max(0,Math.ceil(j/N)),gA=Math.min(f,(G+j)/N),CA=0;CA<l;++CA){for(var wA=CA-k,eA=Math.max(0,Math.ceil(wA/v)),YA=Math.min(W,(d+wA)/v),$=0,RA=X;RA<gA;++RA)for(var oA=RA*N-j,aA=eA;aA<YA;++aA)for(var JA=M*K+c*RA+D*aA,VA=s*(G-1-oA)+u*(d-1-(aA*v-wA))+a*V,bA=0;bA<p;++bA)$+=i[JA+(V*p+bA)]*r[VA+bA];E[I*K+o*T+n*CA+V]=$}return C.toTensor()},g.prototype.depthwiseConv2DDerFilter=function(B,Q,w){EA([B,Q],"depthwiseConv2DDerFilter");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=zA(w.filterShape,"float32"),n=w.padInfo.left,i=w.padInfo.top,Y=w.outChannels/w.inChannels,M=this.bufferSync(B),c=this.bufferSync(Q),D=0;D<e;++D)for(var r=Math.max(0,Math.ceil((i-D)/C)),F=Math.min(w.outHeight,(w.inHeight+i-D)/C),s=0;s<I;++s)for(var u=Math.max(0,Math.ceil((n-s)/E)),a=Math.min(w.outWidth,(w.inWidth+n-s)/E),U=0;U<w.outChannels;++U){for(var G=Math.trunc(U/Y),d=U%Y,H=0,h=0;h<w.batchSize;++h)for(var l=r;l<F;++l)for(var m=D+l*C-i,f=u;f<a;++f){var W=s+f*E-n;H+=M.get(h,m,W,G)*c.get(h,l,f,U)}o.set(H,D,s,G,d)}return o.toTensor()},g.prototype.tile=function(B,Q){return EA(B,"tile"),fc(this.bufferSync(B),Q)},g.prototype.pad=function(B,Q,w){EA(B,"pad");var C=Q.map(function(Y,M){return Y[0]+B.shape[M]+Y[1]}),E=Q.map(function(Y){return Y[0]}),e=this.bufferSync(B),I=zA(C,B.dtype);w!==0&&I.values.fill(w);for(var o=0;o<B.size;o++){var n=e.indexToLoc(o),i=n.map(function(Y,M){return Y+E[M]});I.set.apply(I,[e.get.apply(e,n)].concat(i))}return I.toTensor()},g.prototype.transpose=function(B,Q){EA(B,"transpose");for(var w=new Array(B.rank),C=0;C<w.length;C++)w[C]=B.shape[Q[C]];var E=this.readSync(B.dataId),e=zA(w,B.dtype),I=this.bufferSync(B);for(C=0;C<B.size;++C){for(var o=I.indexToLoc(C),n=new Array(o.length),i=0;i<n.length;i++)n[i]=o[Q[i]];var Y=e.locToIndex(n);e.values[Y]=E[C]}return e.toTensor()},g.prototype.gather=function(B,Q,w){EA([B,Q],"gather");var C=B.shape.slice(),E=this.readSync(Q.dataId);C[w]=E.length;for(var e=zA(C,B.dtype),I=this.bufferSync(B),o=0;o<e.size;++o){var n=e.indexToLoc(o),i=n.slice();i[w]=E[n[w]];var Y=I.locToIndex(i);e.values[o]=I.values[Y]}return e.toTensor()},g.prototype.batchToSpaceND=function(B,Q,w){EA([B],"batchToSpaceND");var C=Q.reduce(function(i,Y){return i*Y}),E=Ee(B.shape,Q,C),e=ee(E.length,Q.length),I=Ie(B.shape,Q,C),o=ic(w,Q.length),n=Yc(I,w,Q.length);return B.reshape(E).transpose(e).reshape(I).slice(o,n)},g.prototype.spaceToBatchND=function(B,Q,w){EA([B],"spaceToBatchND");var C=Q.reduce(function(Y,M){return Y*M}),E=[[0,0]];E.push.apply(E,w);for(var e=1+Q.length;e<B.shape.length;++e)E.push([0,0]);var I=B.pad(E),o=Ee(I.shape,Q,C,!1),n=ee(o.length,Q.length,!1),i=Ie(I.shape,Q,C,!1);return I.reshape(o).transpose(n).reshape(i)},g.prototype.pool=function(B,Q,w){EA(B,"pool");for(var C=Q.strideHeight,E=Q.strideWidth,e=Q.dilationHeight,I=Q.dilationWidth,o=Q.effectiveFilterHeight,n=Q.effectiveFilterWidth,i=Q.padInfo.top,Y=Q.padInfo.left,M=w==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,c=this.readSync(B.dataId),D=zA(Q.outShape,B.dtype),r=D.values,F=Q.outShape[1]*Q.outShape[2]*Q.outShape[3],s=Q.outShape[2]*Q.outShape[3],u=Q.outShape[3],a=0;a<Q.batchSize;++a)for(var U=a*F,G=a*B.strides[0],d=0;d<Q.inChannels;++d)for(var H=0;H<Q.outHeight;++H)for(var h=H*C-i,l=Math.max(0,h),m=Math.min(Q.inHeight,o+h),f=U+H*s,W=0;W<Q.outWidth;++W){for(var N=W*E-Y,v=Math.max(0,N),y=Math.min(Q.inWidth,n+N),k=M,p=0,K=0,V=l;V<m;V+=e){for(var T=G+V*B.strides[1],j=v;j<y;j+=I){var X=c[T+j*B.strides[2]+d];w==="max"&&X>k?k=X:w==="avg"&&(p+=X,K++)}if(isNaN(k))break}r[f+W*u+d]=w==="avg"?p/K:k}return D.toTensor()},g.prototype.maxPool=function(B,Q){return this.pool(B,Q,"max")},g.prototype.maxPoolPositions=function(B,Q){for(var w=zA(Q.outShape,"int32"),C=Q.strideHeight,E=Q.strideWidth,e=Q.dilationHeight,I=Q.dilationWidth,o=Q.effectiveFilterHeight,n=Q.effectiveFilterWidth,i=Q.padInfo.top,Y=Q.padInfo.left,M=this.bufferSync(B),c=0;c<Q.batchSize;++c)for(var D=0;D<Q.inChannels;++D)for(var r=0;r<Q.outHeight;++r){for(var F=r*C-i,s=F;s<0;)s+=e;for(var u=Math.min(Q.inHeight,o+F),a=0;a<Q.outWidth;++a){for(var U=a*E-Y,G=U;G<0;)G+=I;for(var d=Math.min(Q.inWidth,n+U),H=Number.NEGATIVE_INFINITY,h=-1,l=s;l<u;l+=e)for(var m=l-F,f=G;f<d;f+=I){var W=f-U,N=M.get(c,l,f,D);N>H&&(H=N,h=m*n+W)}w.set(h,c,r,a,D)}}return w.toTensor()},g.prototype.maxPoolBackprop=function(B,Q,w,C){EA([Q,w],"maxPoolBackprop");for(var E=this.maxPoolPositions(Q,C),e=C.strideHeight,I=C.strideWidth,o=C.dilationHeight,n=C.dilationWidth,i=C.effectiveFilterHeight,Y=C.effectiveFilterWidth,M=Y-1-C.padInfo.left,c=i-1-C.padInfo.top,D=zA(Q.shape,"float32"),r=this.bufferSync(E),F=this.bufferSync(B),s=0;s<C.batchSize;++s)for(var u=0;u<C.inChannels;++u)for(var a=0;a<C.inHeight;++a)for(var U=0;U<C.inWidth;++U){for(var G=a-c,d=U-M,H=0,h=0;h<i;h+=o){var l=(G+h)/e;if(!(l<0||l>=C.outHeight||Math.floor(l)!==l))for(var m=0;m<Y;m+=n){var f=(d+m)/I;if(!(f<0||f>=C.outWidth||Math.floor(f)!==f)){var W=i*Y-1-r.get(s,l,f,u)===h*Y+m?1:0;W!==0&&(H+=F.get(s,l,f,u)*W)}}}D.set(H,s,a,U,u)}return D.toTensor()},g.prototype.avgPoolBackprop=function(B,Q,w){EA([B,Q],"avgPoolBackprop");for(var C=w.strideHeight,E=w.strideWidth,e=w.filterHeight,I=w.filterWidth,o=w.dilationHeight,n=w.dilationWidth,i=w.effectiveFilterHeight,Y=w.effectiveFilterWidth,M=Y-1-w.padInfo.left,c=i-1-w.padInfo.top,D=zA(Q.shape,"float32"),r=1/(e*I),F=this.bufferSync(B),s=0;s<w.batchSize;++s)for(var u=0;u<w.inChannels;++u)for(var a=0;a<w.inHeight;++a)for(var U=0;U<w.inWidth;++U){for(var G=a-c,d=U-M,H=0,h=0;h<i;h+=o){var l=(G+h)/C;if(!(l<0||l>=w.outHeight||Math.floor(l)!==l))for(var m=0;m<Y;m+=n){var f=(d+m)/E;f<0||f>=w.outWidth||Math.floor(f)!==f||(H+=F.get(s,l,f,u))}}D.set(H*r,s,a,U,u)}return D.toTensor()},g.prototype.pool3d=function(B,Q,w){EA(B,"pool3d");for(var C=Q.strideDepth,E=Q.strideHeight,e=Q.strideWidth,I=Q.dilationDepth,o=Q.dilationHeight,n=Q.dilationWidth,i=Q.effectiveFilterDepth,Y=Q.effectiveFilterHeight,M=Q.effectiveFilterWidth,c=Q.padInfo.front,D=Q.padInfo.top,r=Q.padInfo.left,F=w==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,s=this.readSync(B.dataId),u=zA(Q.outShape,B.dtype),a=u.values,U=Q.outShape[1]*Q.outShape[2]*Q.outShape[3]*Q.outShape[4],G=Q.outShape[2]*Q.outShape[3]*Q.outShape[4],d=Q.outShape[3]*Q.outShape[4],H=Q.outShape[4],h=0;h<Q.batchSize;++h)for(var l=h*U,m=h*B.strides[0],f=0;f<Q.inChannels;++f)for(var W=0;W<Q.outDepth;++W){for(var N=W*C-c,v=N;v<0;)v+=I;for(var y=Math.min(Q.inDepth,i+N),k=l+W*G,p=0;p<Q.outHeight;++p){for(var K=p*E-D,V=K;V<0;)V+=o;for(var T=Math.min(Q.inHeight,Y+K),j=k+p*d,X=0;X<Q.outWidth;++X){for(var gA=X*e-r,CA=gA;CA<0;)CA+=n;for(var wA=Math.min(Q.inWidth,M+gA),eA=j+X*H,YA=F,$=0,RA=0,oA=v;oA<y;oA+=I){for(var aA=m+oA*B.strides[1],JA=V;JA<T;JA+=o){for(var VA=aA+JA*B.strides[2],bA=CA;bA<wA;bA+=n){var pA=s[VA+bA*B.strides[3]+f];if(w==="max"&&pA>YA?YA=pA:w==="avg"&&($+=pA,RA++),isNaN(YA))break}if(isNaN(YA))break}if(isNaN(YA))break}a[eA+f]=w==="avg"?$/RA:YA}}}return u.toTensor()},g.prototype.avgPool3d=function(B,Q){return EA(B,"avgPool3d"),this.pool3d(B,Q,"avg").toFloat()},g.prototype.avgPool3dBackprop=function(B,Q,w){EA([B,Q],"avgPool3dBackprop");for(var C=w.strideDepth,E=w.strideHeight,e=w.strideWidth,I=w.filterDepth,o=w.filterHeight,n=w.filterWidth,i=w.dilationDepth,Y=w.dilationHeight,M=w.dilationWidth,c=w.effectiveFilterDepth,D=w.effectiveFilterHeight,r=w.effectiveFilterWidth,F=c-1-w.padInfo.front,s=r-1-w.padInfo.left,u=D-1-w.padInfo.top,a=zA(Q.shape,"float32"),U=1/(I*o*n),G=this.bufferSync(B),d=0;d<w.batchSize;++d)for(var H=0;H<w.inChannels;++H)for(var h=0;h<w.inDepth;++h)for(var l=0;l<w.inHeight;++l)for(var m=0;m<w.inWidth;++m){for(var f=h-F,W=l-u,N=m-s,v=0,y=0;y<c;y+=i){var k=(f+y)/C;if(!(k<0||k>=w.outDepth||Math.floor(k)!==k))for(var p=0;p<D;p+=Y){var K=(W+p)/E;if(!(K<0||K>=w.outHeight||Math.floor(K)!==K))for(var V=0;V<r;V+=M){var T=(N+V)/e;T<0||T>=w.outWidth||Math.floor(T)!==T||(v+=G.get(d,k,K,T,H))}}}a.set(v*U,d,h,l,m,H)}return a.toTensor()},g.prototype.maxPool3d=function(B,Q){return EA(B,"maxPool3d"),this.pool3d(B,Q,"max").toFloat()},g.prototype.maxPool3dPositions=function(B,Q){for(var w=zA(Q.outShape,"int32"),C=Q.strideDepth,E=Q.strideHeight,e=Q.strideWidth,I=Q.dilationDepth,o=Q.dilationHeight,n=Q.dilationWidth,i=Q.effectiveFilterDepth,Y=Q.effectiveFilterHeight,M=Q.effectiveFilterWidth,c=Q.padInfo.front,D=Q.padInfo.top,r=Q.padInfo.left,F=this.bufferSync(B),s=0;s<Q.batchSize;++s)for(var u=0;u<Q.inChannels;++u)for(var a=0;a<Q.outDepth;++a){for(var U=a*C-c,G=U;G<0;)G+=I;for(var d=Math.min(Q.inDepth,i+U),H=0;H<Q.outHeight;++H){for(var h=H*E-D,l=h;l<0;)l+=o;for(var m=Math.min(Q.inHeight,Y+h),f=0;f<Q.outWidth;++f){for(var W=f*e-r,N=W;N<0;)N+=n;for(var v=Math.min(Q.inWidth,M+W),y=Number.NEGATIVE_INFINITY,k=-1,p=G;p<d;p+=I)for(var K=p-U,V=l;V<m;V+=o)for(var T=V-h,j=N;j<v;j+=n){var X=j-W,gA=F.get(s,p,V,j,u);gA>=y&&(y=gA,k=K*Y*M+T*Y+X)}w.set(k,s,a,H,f,u)}}}return w.toTensor()},g.prototype.maxPool3dBackprop=function(B,Q,w,C){EA([Q,w],"maxPool3dBackprop");for(var E=this.maxPool3dPositions(Q,C),e=C.strideDepth,I=C.strideHeight,o=C.strideWidth,n=C.dilationDepth,i=C.dilationHeight,Y=C.dilationWidth,M=C.effectiveFilterDepth,c=C.effectiveFilterHeight,D=C.effectiveFilterWidth,r=M-1-C.padInfo.front,F=D-1-C.padInfo.left,s=c-1-C.padInfo.top,u=zA(Q.shape,"float32"),a=this.bufferSync(E),U=this.bufferSync(B),G=0;G<C.batchSize;++G)for(var d=0;d<C.inChannels;++d)for(var H=0;H<C.inDepth;++H)for(var h=0;h<C.inHeight;++h)for(var l=0;l<C.inWidth;++l){for(var m=H-r,f=h-s,W=l-F,N=0,v=0;v<M;v+=n){var y=(m+v)/e;if(!(y<0||y>=C.outDepth||Math.floor(y)!==y))for(var k=0;k<c;k+=i){var p=(f+k)/I;if(!(p<0||p>=C.outHeight||Math.floor(p)!==p))for(var K=0;K<D;K+=Y){var V=(W+K)/o;if(!(V<0||V>=C.outWidth||Math.floor(V)!==V)){var T=M*c*D-1-a.get(G,y,p,V,d)===v*c*D+k*D+K?1:0;T!==0&&(N+=U.get(G,y,p,V,d)*T)}}}}u.set(N,G,H,h,l,d)}return u.toTensor()},g.prototype.cast=function(B,Q){return Uc(B,Q,this)},g.prototype.reshape=function(B,Q){return et(B,Q)},g.prototype.avgPool=function(B,Q){return EA(B,"avgPool"),this.pool(B,Q,"avg").toFloat()},g.prototype.resizeBilinear=function(B,Q,w,C){EA(B,"resizeBilinear");for(var E=B.shape,e=E[0],I=E[1],o=E[2],n=E[3],i=this.readSync(B.dataId),Y=new Float32Array(hA([e,Q,w,n])),M=[C&&Q>1?I-1:I,C&&w>1?o-1:o],c=[C&&Q>1?Q-1:Q,C&&w>1?w-1:w],D=0,r=M[0]/c[0],F=M[1]/c[1],s=0;s<e;s++)for(var u=0;u<Q;u++)for(var a=r*u,U=Math.floor(a),G=a-U,d=Math.min(I-1,Math.ceil(a)),H=s*B.strides[0]+U*B.strides[1],h=s*B.strides[0]+d*B.strides[1],l=0;l<w;l++)for(var m=F*l,f=Math.floor(m),W=m-f,N=Math.min(o-1,Math.ceil(m)),v=H+f*B.strides[2],y=h+f*B.strides[2],k=H+N*B.strides[2],p=h+N*B.strides[2],K=0;K<n;K++){var V=i[v+K],T=i[y+K],j=V+(i[k+K]-V)*W,X=j+(T+(i[p+K]-T)*W-j)*G;Y[D++]=X}return Ag(Y,[e,Q,w,n])},g.prototype.resizeBilinearBackprop=function(B,Q,w){EA([B,Q],"resizeBilinearBackprop");for(var C=Q.shape,E=C[0],e=C[1],I=C[2],o=C[3],n=B.shape,i=n[1],Y=n[2],M=new Float32Array(E*e*I*o),c=[w&&i>1?e-1:e,w&&Y>1?I-1:I],D=[w&&i>1?i-1:i,w&&Y>1?Y-1:Y],r=c[0]/D[0],F=c[1]/D[1],s=this.readSync(B.dataId),u=0,a=0;a<E;a++)for(var U=a*Q.strides[0],G=0;G<i;G++)for(var d=G*r,H=Math.floor(d),h=Math.min(Math.ceil(d),e-1),l=U+H*Q.strides[1],m=U+h*Q.strides[1],f=d-H,W=1-f,N=0;N<Y;N++)for(var v=N*F,y=Math.floor(v),k=Math.min(Math.ceil(v),I-1),p=v-y,K=1-p,V=l+y*Q.strides[2],T=l+k*Q.strides[2],j=m+y*Q.strides[2],X=m+k*Q.strides[2],gA=W*K,CA=W*p,wA=f*K,eA=f*p,YA=0;YA<o;YA++){var $=s[u++];M[V+YA]+=$*gA,M[T+YA]+=$*CA,M[j+YA]+=$*wA,M[X+YA]+=$*eA}return Dg(M,[E,I,e,o],Q.dtype)},g.prototype.resizeNearestNeighbor=function(B,Q,w,C){EA(B,"resizeNearestNeighbor");for(var E=B.shape,e=E[0],I=E[1],o=E[2],n=E[3],i=this.readSync(B.dataId),Y=new Float32Array(e*Q*w*n),M=[C&&Q>1?I-1:I,C&&w>1?o-1:o],c=[C&&Q>1?Q-1:Q,C&&w>1?w-1:w],D=M[0]/c[0],r=M[1]/c[1],F=0,s=0;s<e;s++)for(var u=s*B.strides[0],a=0;a<Q;a++)for(var U=D*a,G=u+Math.min(I-1,C?Math.round(U):Math.floor(U))*B.strides[1],d=0;d<w;d++)for(var H=r*d,h=G+Math.min(o-1,C?Math.round(H):Math.floor(H))*B.strides[2],l=0;l<n;l++){var m=i[h+l];Y[F++]=m}return Ag(Y,[e,Q,w,n],B.dtype)},g.prototype.resizeNearestNeighborBackprop=function(B,Q,w){EA([B,Q],"resizeNearestNeighborBackprop");for(var C=Q.shape,E=C[0],e=C[1],I=C[2],o=C[3],n=B.shape,i=n[1],Y=n[2],M=new Float32Array(E*e*I*o),c=this.readSync(B.dataId),D=[w&&i>1?e-1:e,w&&Y>1?I-1:I],r=[w&&i>1?i-1:i,w&&Y>1?Y-1:Y],F=D[0]/r[0],s=D[1]/r[1],u=1/F,a=1/s,U=2*Math.ceil(u)+2,G=2*Math.ceil(a)+2,d=0;d<E;d++)for(var H=d*Q.strides[0],h=0;h<e;h++)for(var l=H+h*Q.strides[1],m=Math.floor(h*u),f=Math.floor(m-U/2),W=0;W<I;W++)for(var N=l+W*Q.strides[2],v=Math.floor(W*a),y=Math.floor(v-G/2),k=0;k<o;k++){for(var p=0,K=0;K<U;K++){var V=K+f;if(!(V<0||V>=i)){var T=H+V*B.strides[1],j=V*F;if(h===Math.min(e-1,w?Math.round(j):Math.floor(j)))for(var X=0;X<G;X++){var gA=X+y;if(!(gA<0||gA>=Y)){var CA=T+gA*B.strides[2],wA=gA*s;W===Math.min(I-1,w?Math.round(wA):Math.floor(wA))&&(p+=c[CA+k])}}}}M[N+k]=p}return Dg(M,Q.shape,Q.dtype)},g.prototype.batchNormalization=function(B,Q,w,C,E,e){EA([B,Q,w,E,e],"batchNorm");for(var I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=this.readSync(w.dataId),i=E?this.readSync(E.dataId):new Float32Array([1]),Y=e?this.readSync(e.dataId):new Float32Array([0]),M=new Float32Array(I.length),c=Y.length,D=i.length,r=n.length,F=o.length,s=0,u=0,a=0,U=0,G=0;G<I.length;++G)M[G]=Y[s++]+(I[G]-o[u++])*i[a++]/Math.sqrt(n[U++]+C),s>=c&&(s=0),u>=F&&(u=0),a>=D&&(a=0),U>=r&&(U=0);return Dg(M,B.shape)},g.prototype.localResponseNormalization4D=function(B,Q,w,C,E){EA(B,"localResponseNormalization4D");var e=B.shape[3],I=e-1,o=this.readSync(B.dataId),n=B.size,i=new Float32Array(n);function Y(r){for(var F=r%e,s=r-F+Math.max(0,F-Q),u=r-F+Math.min(F+Q,I),a=0;s<=u;s++){var U=o[s];a+=U*U}return a}for(var M=0;M<n;M++){var c=Y(M),D=o[M]*Math.pow(w+C*c,-E);i[M]=D}return Dg(i,B.shape)},g.prototype.LRNGrad=function(B,Q,w,C,E,e,I){EA(B,"LRNGrad");for(var o=B.shape[3],n=this.readSync(B.dataId),i=this.readSync(Q.dataId),Y=this.readSync(w.dataId),M=new Float32Array(B.size),c=B.size,D=0;D<c;D++){for(var r=D%o,F=D-r+Math.max(0,r-C),s=D-r+Math.min(o,r+C+1),u=0,a=F;a<s;a++)u+=Math.pow(i[a],2);for(u=e*u+E,a=F;a<s;a++){var U=-2*e*I*i[a]*Y[D]/u;D===a&&(U+=Math.pow(u,-I)),U*=n[D],M[a]+=U}}return Dg(M,B.shape)},g.prototype.multinomial=function(B,Q,w,C){EA(B,"multinomial");for(var E=Q?B:rQ(B),e=E.shape[0],I=E.shape[1],o=DB([e,w],"int32"),n=this.readSync(o.dataId),i=this.readSync(E.dataId),Y=0;Y<e;++Y){var M=Y*I,c=new Float32Array(I-1);c[0]=i[M];for(var D=1;D<c.length;++D)c[D]=c[D-1]+i[M+D];for(var r=Ce(C.toString()),F=Y*w,s=0;s<w;++s){var u=r();n[F+s]=c.length;for(var a=0;a<c.length;a++)if(u<c[a]){n[F+s]=a;break}}}return o},g.prototype.oneHot=function(B,Q,w,C){EA(B,"oneHot");var E=new Float32Array(B.size*Q);E.fill(C);for(var e=this.readSync(B.dataId),I=0;I<B.size;++I)e[I]>=0&&e[I]<Q&&(E[I*Q+e[I]]=w);return RQ(E,[B.size,Q],"int32")},g.prototype.nonMaxSuppression=function(B,Q,w,C,E){return EA(B,"nonMaxSuppression"),ot(this.readSync(B.dataId),this.readSync(Q.dataId),w,C,E)},g.prototype.fft=function(B){return this.fftBatch(B,!1)},g.prototype.ifft=function(B){return this.fftBatch(B,!0)},g.prototype.fftBatch=function(B,Q){for(var w=B.shape[0],C=B.shape[1],E=zA(B.shape,"float32"),e=zA(B.shape,"float32"),I=kg(B).as2D(w,C),o=BQ(B).as2D(w,C),n=0;n<w;n++)for(var i=I.slice([n,0],[1,C]),Y=o.slice([n,0],[1,C]),M=$B(i,Y),c=this.readSync(this.fftImpl(M,Q).dataId),D=0;D<C;D++){var r=hc(c,D);E.values[n*C+D]=r.real,e.values[n*C+D]=r.imag}return $B(E.toTensor(),e.toTensor()).as2D(w,C)},g.prototype.fftImpl=function(B,Q){var w=B.as1D(),C=w.size;if(this.isExponentOf2(C)){var E=this.fftRadix2(w,C,Q).as2D(B.shape[0],B.shape[1]);return Q&&(E=$B(kg(E).div(nA(C)),BQ(E).div(nA(C)))),E}var e=this.readSync(B.dataId),I=function(o){for(var n=new Float32Array(o.length/2),i=new Float32Array(o.length/2),Y=0;Y<o.length;Y+=2)n[Y/2]=o[Y],i[Y/2]=o[Y+1];return{real:n,imag:i}}(this.fourierTransformByMatmul(e,C,Q));return $B(I.real,I.imag).as2D(B.shape[0],B.shape[1])},g.prototype.isExponentOf2=function(B){return(B&B-1)==0},g.prototype.fftRadix2=function(B,Q,w){if(Q===1)return B;var C=this.readSync(B.dataId),E=Q/2,e=function(F){for(var s=Math.ceil(F.length/4),u=new Float32Array(s),a=new Float32Array(s),U=0;U<F.length;U+=4)u[Math.floor(U/4)]=F[U],a[Math.floor(U/4)]=F[U+1];return{real:u,imag:a}}(C),I=$B(e.real,e.imag).as1D(),o=function(F){for(var s=Math.floor(F.length/4),u=new Float32Array(s),a=new Float32Array(s),U=2;U<F.length;U+=4)u[Math.floor(U/4)]=F[U],a[Math.floor(U/4)]=F[U+1];return{real:u,imag:a}}(C),n=$B(o.real,o.imag).as1D();I=this.fftRadix2(I,E,w),n=this.fftRadix2(n,E,w);var i=function(F,s){for(var u=new Float32Array(F/2),a=new Float32Array(F/2),U=0;U<Math.ceil(F/2);U++){var G=(s?2:-2)*Math.PI*(U/F);u[U]=Math.cos(G),a[U]=Math.sin(G)}return{real:u,imag:a}}(Q,w),Y=$B(i.real,i.imag).mul(n),M=I.add(Y),c=I.sub(Y),D=kg(M).concat(kg(c)),r=BQ(M).concat(BQ(c));return $B(D,r).as1D()},g.prototype.fourierTransformByMatmul=function(B,Q,w){for(var C=new Float32Array(2*Q),E=0;E<Q;E++){for(var e=0,I=0,o=0;o<Q;o++){var n=Yf(E*o,Q,w),i=hc(B,o);e+=i.real*n.real-i.imag*n.imag,I+=i.real*n.imag+i.imag*n.real}w&&(e/=Q,I/=Q),nf(C,e,I,E)}return C},g.prototype.depthToSpace=function(B,Q,w){R(w==="NHWC",function(){return"Only NHWC dataFormat supported on CPU for depthToSpace. Got "+w}),R(Q>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+Q});for(var C=B.shape[0],E=B.shape[1],e=B.shape[2],I=B.shape[3],o=E*Q,n=e*Q,i=I/(Q*Q),Y=this.readSync(B.dataId),M=new Float32Array(C*o*n*i),c=0,D=0;D<C;++D)for(var r=0;r<o;++r)for(var F=Math.floor(r/Q),s=r%Q,u=0;u<n;++u)for(var a=Math.floor(u/Q),U=(s*Q+u%Q)*i,G=0;G<i;++G){var d=G+U+I*(a+e*(F+E*D));M[c++]=Y[d]}return Dg(M,[C,o,n,i])},g.prototype.broadcastedBinaryOp=function(B,Q,w,C){var E=qA(B.shape,Q.shape),e=zA(E,w),I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=PQ(B.shape,E),i=PQ(Q.shape,E),Y=e.values;if(n.length+i.length===0)for(var M=0;M<Y.length;++M)Y[M]=C(I[M%I.length],o[M%o.length]);else{var c=this.bufferSync(B),D=this.bufferSync(Q),r=function(F){var s=e.indexToLoc(F),u=s.slice(-B.rank);n.forEach(function(d){return u[d]=0});var a=c.locToIndex(u),U=s.slice(-Q.rank);i.forEach(function(d){return U[d]=0});var G=D.locToIndex(U);Y[F]=C(I[a],o[G])};for(M=0;M<Y.length;++M)r(M)}return e.toTensor()},g.prototype.broadcastedBinaryComplexOp=function(B,Q,w){var C=qA(B.shape,Q.shape),E=zA(C,"float32"),e=zA(C,"float32"),I=this.readSync(B.dataId),o=this.readSync(Q.dataId),n=PQ(B.shape,C),i=PQ(Q.shape,C),Y=E.values,M=e.values;if(n.length+i.length===0)for(var c=0;c<Y.length;c++){var D=c%I.length,r=c%o.length,F=w(I[2*D],I[2*D+1],o[2*r],o[2*r+1]);Y[c]=F.real,M[c]=F.imag}else{var s=this.bufferSync(this.data.get(B.dataId).complexTensors.real),u=this.bufferSync(this.data.get(Q.dataId).complexTensors.real),a=function(U){var G=E.indexToLoc(U),d=G.slice(-B.rank);n.forEach(function(f){return d[f]=0});var H=s.locToIndex(d),h=G.slice(-Q.rank);i.forEach(function(f){return h[f]=0});var l=u.locToIndex(h),m=w(I[2*H],I[2*H+1],o[2*l],o[2*l+1]);Y[U]=m.real,M[U]=m.imag};for(c=0;c<Y.length;c++)a(c)}return this.complex(E.toTensor(),e.toTensor())},g.prototype.split=function(B,Q,w){return Hc(B,Q,w)},g.prototype.dispose=function(){},g.prototype.floatPrecision=function(){return 32},g.prototype.epsilon=function(){return 1e-7},g.prototype.cropAndResize=function(B,Q,w,C,E,e){for(var I=B.shape,o=I[0],n=I[1],i=I[2],Y=I[3],M=Q.shape[0],c=C[0],D=C[1],r=zA([M,c,D,Y],"float32"),F=this.readSync(Q.dataId),s=this.readSync(w.dataId),u=this.readSync(B.dataId),a=B.strides,U=r.strides,G=0;G<M;G++){var d=4*G,H=F[d],h=F[d+1],l=F[d+2],m=F[d+3],f=s[G];if(!(f>=o))for(var W=c>1?(l-H)*(n-1)/(c-1):0,N=D>1?(m-h)*(i-1)/(D-1):0,v=0;v<c;v++){var y=c>1?H*(n-1)+v*W:.5*(H+l)*(n-1);if(y<0||y>n-1)for(var k=0;k<D;k++)for(var p=0;p<Y;p++){var K=p+k*U[2]+v*U[1]+G*U[0];r.values[K]=e}else if(E==="bilinear"){var V=Math.floor(y),T=Math.ceil(y),j=y-V;for(k=0;k<D;k++)if((oA=D>1?h*(i-1)+k*N:.5*(h+m)*(i-1))<0||oA>i-1)for(p=0;p<Y;p++)K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=e;else{var X=Math.floor(oA),gA=Math.ceil(oA),CA=oA-X;for(p=0;p<Y;p++){var wA=u[K=p+X*a[2]+V*a[1]+f*a[0]],eA=u[K=p+gA*a[2]+V*a[1]+f*a[0]],YA=u[K=p+X*a[2]+T*a[1]+f*a[0]],$=wA+(eA-wA)*CA,RA=YA+(u[K=p+gA*a[2]+T*a[1]+f*a[0]]-YA)*CA;K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=$+(RA-$)*j}}}else for(k=0;k<D;++k){var oA;if((oA=D>1?h*(i-1)+k*N:.5*(h+m)*(i-1))<0||oA>i-1)for(p=0;p<Y;p++)K=p+k*U[2]+v*U[1]+G*U[0],r.values[K]=e;else{var aA=Math.round(oA),JA=Math.round(y);for(p=0;p<Y;p++){var VA=p+aA*a[2]+JA*a[1]+f*a[0],bA=p+k*U[2]+v*U[1]+G*U[0];r.values[bA]=u[VA]}}}}}return r.toTensor()},g.prototype.sparseToDense=function(B,Q,w,C){var E=oe(0,B,w),e=E.sliceRank,I=E.numUpdates,o=E.sliceSize,n=E.strides,i=E.outputSize;return this.scatter(B,Q,w,i,o,I,e,n,C,!1)},g.prototype.gatherND=function(B,Q){var w=Q.shape,C=w[w.length-1],E=Mc(B,Q),e=E[0],I=E[1],o=E[2],n=E[3];if(I===0)return Ag([],e,B.dtype);for(var i=new RC([I,o],B.dtype),Y=this.readSync(Q.dataId),M=this.readSync(B.dataId),c=0;c<I;c++){for(var D=[],r=0,F=0;F<C;F++){var s=Y[c*C+F];r+=s*n[F],D.push(s)}if(r<0||r>=B.size/o)throw new Error("Invalid indices: "+D+" does not index into "+B.shape);for(var u=0;u<o;u++)i.values[c*o+u]=M[r*o+u]}return i.toTensor().reshape(e)},g.prototype.scatterND=function(B,Q,w){var C=oe(0,B,w),E=C.sliceRank,e=C.numUpdates,I=C.sliceSize,o=C.strides,n=C.outputSize,i=nA(0);return this.scatter(B,Q,w,n,I,e,E,o,i,!0)},g.prototype.fill=function(B,Q,w){var C=xE(w=w||HC(Q),hA(B));return C.fill(Q),b.makeTensor(C,B,w,this)},g.prototype.onesLike=function(B){if(B.dtype==="string")throw new Error("onesLike is not supported for string tensors");return this.fill(B.shape,1,B.dtype)},g.prototype.zerosLike=function(B){var Q=xE(B.dtype,hA(B.shape));return this.makeOutput(Q,B.shape,B.dtype)},g.prototype.linspace=function(B,Q,w){return Gc(B,Q,w)},g.prototype.scatter=function(B,Q,w,C,E,e,I,o,n,i){var Y=[C/E,E],M=this.readSync(B.dataId),c=this.readSync(Q.dataId);if(C===0)return Ag([],w,Q.dtype);var D=new RC(Y,Q.dtype);D.values.fill(this.readSync(n.dataId)[0]);for(var r=0;r<e;r++){for(var F=[],s=0,u=0;u<I;u++){var a=M[r*I+u];F.push(a),s+=a*o[u]}if(s<0||s>=C/E)throw new Error("Invalid indices: "+F+" does not index into "+w);for(var U=0;U<E;U++)i?D.values[s*E+U]+=c[r*E+U]:D.values[s*E+U]=Q.rank===0?c[0]:c[r*E+U]}return D.toTensor().reshape(w)},g}(sc);b.registerBackend("cpu",function(){return new P0},1);for(var pt=0,yD=[{kernelName:"NonMaxSuppressionV5",backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs,w=g,C=w.boxes,E=w.scores,e=Q,I=e.maxOutputSize,o=e.iouThreshold,n=e.scoreThreshold,i=e.softNmsSigma,Y=B;EA(C,"NonMaxSuppressionWithScore");var M=tt(Y.data.get(C.dataId).values,Y.data.get(E.dataId).values,I,o,n,i);return[M.selectedIndices,M.selectedScores]}},{kernelName:"Square",backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g.x,w=B;EA(Q,"square");for(var C=w.data.get(Q.dataId).values,E=new Float32Array(C.length),e=0;e<C.length;++e){var I=C[e];E[e]=I*I}return{dataId:w.write(E,Q.shape,Q.dtype),shape:Q.shape,dtype:Q.dtype}}},{kernelName:zC,backendName:"cpu",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g,w=Q.a,C=Q.b,E=B;EA([w,C],zC);var e=E.data.get(w.dataId).values,I=E.data.get(C.dataId).values,o=function(Y,M,c,D,r,F){var s=qA(Y,M),u=s.length,a=Og(s),U=dC(r,hA(s)),G=Y.length,d=M.length,H=Og(Y),h=Og(M),l=PQ(Y,s),m=PQ(M,s);if(l.length+m.length===0)for(var f=0;f<U.length;++f)U[f]=F(c[f%c.length],D[f%D.length]);else{var W=function(N){var v=Sd(N,u,a),y=v.slice(-G);l.forEach(function(V){return y[V]=0});var k=VM(y,G,H),p=v.slice(-d);m.forEach(function(V){return p[V]=0});var K=VM(p,d,h);U[N]=F(c[k],D[K])};for(f=0;f<U.length;++f)W(f)}return[U,s]}(w.shape,C.shape,e,I,w.dtype,function(Y,M){var c=Y-M;return c*c}),n=o[0],i=o[1];return{dataId:E.write(n,i,w.dtype),shape:i,dtype:w.dtype}}}];pt<yD.length;pt++)jM(yD[pt]);for(var Xw,v0=function(A){this.variableNames=["A"];var g=Qg(),B=A[0],Q=A[1];this.outputShape=A,this.userCode=`
3765
3765
  void main() {
3766
3766
  ivec3 coords = getOutputCoords();
3767
3767
  int texR = coords[0];
@@ -3783,7 +3783,7 @@ Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed thi
3783
3783
 
3784
3784
  setOutput(floor(value * 255.0 + 0.5));
3785
3785
  }
3786
- `},P0=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var g=Qg(),B=A[0],Q=A[1];this.outputShape=A,this.userCode=`
3786
+ `},k0=function(A){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var g=Qg(),B=A[0],Q=A[1];this.outputShape=A,this.userCode=`
3787
3787
  void main() {
3788
3788
  ivec3 coords = getOutputCoords();
3789
3789
  int texR = coords[0];
@@ -3817,8 +3817,8 @@ Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed thi
3817
3817
 
3818
3818
  `+g.output+` = result;
3819
3819
  }
3820
- `},pt=0,zD=[{kernelName:"FromPixels",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs,w=g.pixels,C=Q.numChannels,E=typeof HTMLVideoElement<"u"&&w instanceof HTMLVideoElement,e=typeof HTMLImageElement<"u"&&w instanceof HTMLImageElement,I=E?[w.videoWidth,w.videoHeight]:[w.width,w.height],o=I[0],n=I[1],i=[n,o],Y=[n,o,C];(e||E)&&(Xw==null&&(Xw=document.createElement("canvas").getContext("2d")),Xw.canvas.width=o,Xw.canvas.height=n,Xw.drawImage(w,0,0,o,n),w=Xw.canvas);var M=B.makeTensorInfo(i,"int32");B.texData.get(M.dataId).usage=hg.PIXELS,B.gpgpu.uploadPixelDataToTexture(B.getTexture(M.dataId),w);var c=BA().getBool("WEBGL_PACK")?new P0(Y):new R0(Y),D=B.runWebGLProgram(c,[M],"int32");return B.disposeData(M.dataId),D}},{kernelName:"NonMaxSuppressionV5",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs;ge("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var w=g,C=w.boxes,E=w.scores,e=Q,I=e.maxOutputSize,o=e.iouThreshold,n=e.scoreThreshold,i=e.softNmsSigma,Y=B,M=ot(Y.readSync(C.dataId),Y.readSync(E.dataId),I,o,n,i);return[M.selectedIndices,M.selectedScores]}},{kernelName:"Square",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g.x,w=B,C=new KA(Q.shape,"return x * x;");return w.runWebGLProgram(C,[Q],Q.dtype)}},{kernelName:zC,backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g,w=Q.a,C=Q.b,E=B,e=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ("return (a - b) * (a - b);",w.shape,C.shape):new lB("return (a - b) * (a - b);",w.shape,C.shape);return E.compileAndRun(e,[w,C])}}];pt<zD.length;pt++)jM(zD[pt]);for(var yt=0,WD=[{kernelName:"Square",gradFunc:function(A,g){var B=g[0];return{x:function(){return A.mul(B.toFloat().mul(2))}}}},{kernelName:zC,gradFunc:function(A,g){var B=g[0],Q=g[1],w=nA(2);return{a:function(){return wg(A,wg(w,zB(B,Q)))},b:function(){return wg(A,wg(w,zB(Q,B)))}}}}];yt<WD.length;yt++)Jd(WD[yt]);var v0=function(){function A(){}return A.prototype.fetch=function(g,B){return fetch(g,B)},A.prototype.now=function(){return performance.now()},A.prototype.encode=function(g,B){if(B!=="utf-8"&&B!=="utf8")throw new Error("Browser's encoder only supports utf-8, but got "+B);return this.textEncoder==null&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(g)},A.prototype.decode=function(g,B){return new TextDecoder(B).decode(g)},A}();BA().get("IS_BROWSER")&&BA().setPlatform("browser",new v0);var zt,k0=function(){return require("node-fetch")},T0=function(){function A(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return A.prototype.fetch=function(g,B){return BA().global.fetch!=null?BA().global.fetch(g,B):(zt==null&&(zt=k0()),zt(g,B))},A.prototype.now=function(){var g=process.hrtime();return 1e3*g[0]+g[1]/1e6},A.prototype.encode=function(g,B){if(B!=="utf-8"&&B!=="utf8")throw new Error("Node built-in encoder only supports utf-8, but got "+B);return this.textEncoder.encode(g)},A.prototype.decode=function(g,B){return g.length===0?"":new this.util.TextDecoder(B).decode(g)},A}();BA().get("IS_NODE")&&BA().setPlatform("node",new T0);var Wt={float32:4,int32:4,uint16:2,uint8:1,bool:1},fe=4;function SD(A,g){for(var B={},Q=0,w=function(e){var I=e.name,o=e.dtype,n=e.shape,i=hA(n),Y=void 0;if("quantization"in e){var M=e.quantization;if(M.dtype!=="uint8"&&M.dtype!=="uint16")throw new Error("Weight "+e.name+" has unknown quantization dtype "+M.dtype+". Supported quantization dtypes are: 'uint8' and 'uint16'.");var c=Wt[M.dtype],D=A.slice(Q,Q+i*c),r=M.dtype==="uint8"?new Uint8Array(D):new Uint16Array(D);if(o==="float32")Y=Float32Array.from(r,function(G){return G*M.scale+M.min});else{if(o!=="int32")throw new Error("Unsupported dtype in weight '"+I+"': "+o);Y=Int32Array.from(r,function(G){return Math.round(G*M.scale+M.min)})}Q+=i*c}else if(o==="string"){var F=hA(e.shape);Y=[];for(var s=0;s<F;s++){var u=new Uint32Array(A.slice(Q,Q+fe))[0];Q+=fe;var a=new Uint8Array(A.slice(Q,Q+u));Y.push(a),Q+=u}}else{var U=Wt[o];if(D=A.slice(Q,Q+i*U),o==="float32")Y=new Float32Array(D);else if(o==="int32")Y=new Int32Array(D);else{if(o!=="bool")throw new Error("Unsupported dtype in weight '"+I+"': "+o);Y=new Uint8Array(D)}Q+=i*U}B[I]=Ag(Y,n,o)},C=0,E=g;C<E.length;C++)w(E[C]);return B}function j0(A){if(A===null)throw new Error("Invalid input value: "+JSON.stringify(A));var g=0,B=[];A.forEach(function(C){if(g+=C.byteLength,B.push(C.byteLength===C.buffer.byteLength?C:new C.constructor(C)),!(C instanceof Float32Array||C instanceof Int32Array||C instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+C.constructor.name)});var Q=new Uint8Array(g),w=0;return B.forEach(function(C){Q.set(new Uint8Array(C.buffer),w),w+=C.byteLength}),Q.buffer}var St=typeof Buffer<"u"&&(typeof Blob>"u"||typeof atob>"u"||typeof btoa>"u");function LD(A){return St?Buffer.byteLength(A):new Blob([A]).size}function Lt(A){var g=0;A.forEach(function(w){g+=w.byteLength});var B=new Uint8Array(g),Q=0;return A.forEach(function(w){B.set(new Uint8Array(w),Q),Q+=w.byteLength}),B.buffer}function bD(A){for(A=A.trim();A.endsWith("/");)A=A.slice(0,A.length-1);var g=A.split("/");return g[g.length-1]}function bC(A){if(A.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:A.modelTopology==null?0:LD(JSON.stringify(A.modelTopology)),weightSpecsBytes:A.weightSpecs==null?0:LD(JSON.stringify(A.weightSpecs)),weightDataBytes:A.weightData==null?0:A.weightData.byteLength}}var fg=function(){function A(){this.saveRouters=[],this.loadRouters=[]}return A.getInstance=function(){return A.instance==null&&(A.instance=new A),A.instance},A.registerSaveRouter=function(g){A.getInstance().saveRouters.push(g)},A.registerLoadRouter=function(g){A.getInstance().loadRouters.push(g)},A.getSaveHandlers=function(g){return A.getHandlers(g,"save")},A.getLoadHandlers=function(g,B){return A.getHandlers(g,"load",B)},A.getHandlers=function(g,B,Q){var w=[];return(B==="load"?A.getInstance().loadRouters:A.getInstance().saveRouters).forEach(function(C){var E=C(g,Q);E!==null&&w.push(E)}),w},A}(),Ow="://",kQ=function(){function A(){this.managers={}}return A.getInstance=function(){return A.instance==null&&(A.instance=new A),A.instance},A.registerManager=function(g,B){R(g!=null,function(){return"scheme must not be undefined or null."}),g.endsWith(Ow)&&(g=g.slice(0,g.indexOf(Ow))),R(g.length>0,function(){return"scheme must not be an empty string."});var Q=A.getInstance();R(Q.managers[g]==null,function(){return"A model store manager is already registered for scheme '"+g+"'."}),Q.managers[g]=B},A.getManager=function(g){var B=this.getInstance().managers[g];if(B==null)throw new Error("Cannot find model manager for scheme '"+g+"'");return B},A.getSchemes=function(){return Object.keys(this.getInstance().managers)},A}();function Je(A){if(A.indexOf(Ow)===-1)throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+kQ.getSchemes().join(","));return{scheme:A.split(Ow)[0],path:A.split(Ow)[1]}}function KD(A,g,B){return B===void 0&&(B=!1),uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return R(A!==g,function(){return"Old path and new path are the same: '"+A+"'"}),R((Q=fg.getLoadHandlers(A)).length>0,function(){return"Copying failed because no load handler is found for source URL "+A+"."}),R(Q.length<2,function(){return"Copying failed because more than one ("+Q.length+") load handlers for source URL "+A+"."}),w=Q[0],R((C=fg.getSaveHandlers(g)).length>0,function(){return"Copying failed because no save handler is found for destination URL "+g+"."}),R(C.length<2,function(){return"Copying failed because more than one ("+Q.length+") save handlers for destination URL "+g+"."}),E=C[0],e=Je(A).scheme,I=Je(A).path,o=e===Je(A).scheme,[4,w.load()];case 1:return n=Y.sent(),B&&o?[4,kQ.getManager(e).removeModel(I)]:[3,3];case 2:Y.sent(),Y.label=3;case 3:return[4,E.save(n)];case 4:return i=Y.sent(),!B||o?[3,6]:[4,kQ.getManager(e).removeModel(I)];case 5:Y.sent(),Y.label=6;case 6:return[2,i.modelArtifactsInfo]}})})}var ow="models_store",TQ="model_info_store";function VD(){if(!BA().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var A=window||self,g=A.indexedDB||A.mozIndexedDB||A.webkitIndexedDB||A.msIndexedDB||A.shimIndexedDB;if(g==null)throw new Error("The current browser does not appear to support IndexedDB.");return g}function bt(A){var g=A.result;g.createObjectStore(ow,{keyPath:"modelPath"}),g.createObjectStore(TQ,{keyPath:"modelPath"})}var Zw=function(){function A(g){if(this.indexedDB=VD(),g==null||!g)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=g}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){return UA(this,function(B){if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,g)]})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){return UA(this,function(g){return[2,this.databaseAction(this.modelPath)]})})},A.prototype.databaseAction=function(g,B){var Q=this;return new Promise(function(w,C){var E=Q.indexedDB.open("tensorflowjs",1);E.onupgradeneeded=function(){return bt(E)},E.onsuccess=function(){var e=E.result;if(B==null){var I=e.transaction(ow,"readonly"),o=I.objectStore(ow).get(Q.modelPath);o.onsuccess=function(){if(o.result==null)return e.close(),C(new Error("Cannot find model with path '"+Q.modelPath+"' in IndexedDB."));w(o.result.modelArtifacts)},o.onerror=function(D){return e.close(),C(o.error)},I.oncomplete=function(){return e.close()}}else{var n,i=bC(B),Y=e.transaction(TQ,"readwrite"),M=Y.objectStore(TQ),c=M.put({modelPath:Q.modelPath,modelArtifactsInfo:i});c.onsuccess=function(){var D=(n=e.transaction(ow,"readwrite")).objectStore(ow).put({modelPath:Q.modelPath,modelArtifacts:B,modelArtifactsInfo:i});D.onsuccess=function(){return w({modelArtifactsInfo:i})},D.onerror=function(r){var F=(M=Y.objectStore(TQ)).delete(Q.modelPath);F.onsuccess=function(){return e.close(),C(D.error)},F.onerror=function(s){return e.close(),C(D.error)}}},c.onerror=function(D){return e.close(),C(c.error)},Y.oncomplete=function(){n==null?e.close():n.oncomplete=function(){return e.close()}}}},E.onerror=function(e){return C(E.error)}})},A.URL_SCHEME="indexeddb://",A}(),xD=function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(Zw.URL_SCHEME)?(g=A.slice(Zw.URL_SCHEME.length),new Zw(g)):null;var g};fg.registerSaveRouter(xD),fg.registerLoadRouter(xD);var p0=function(){function A(){this.indexedDB=VD()}return A.prototype.listModels=function(){return uA(this,void 0,void 0,function(){var g=this;return UA(this,function(B){return[2,new Promise(function(Q,w){var C=g.indexedDB.open("tensorflowjs",1);C.onupgradeneeded=function(){return bt(C)},C.onsuccess=function(){var E=C.result,e=E.transaction(TQ,"readonly"),I=e.objectStore(TQ).getAll();I.onsuccess=function(){for(var o={},n=0,i=I.result;n<i.length;n++){var Y=i[n];o[Y.modelPath]=Y.modelArtifactsInfo}Q(o)},I.onerror=function(o){return E.close(),w(I.error)},e.oncomplete=function(){return E.close()}},C.onerror=function(E){return w(C.error)}})]})})},A.prototype.removeModel=function(g){return uA(this,void 0,void 0,function(){var B=this;return UA(this,function(Q){var w;return g=(w=g).startsWith(Zw.URL_SCHEME)?w.slice(Zw.URL_SCHEME.length):w,[2,new Promise(function(C,E){var e=B.indexedDB.open("tensorflowjs",1);e.onupgradeneeded=function(){return bt(e)},e.onsuccess=function(){var I,o=e.result,n=o.transaction(TQ,"readwrite"),i=n.objectStore(TQ),Y=i.get(g);Y.onsuccess=function(){if(Y.result==null)return o.close(),E(new Error("Cannot find model with path '"+g+"' in IndexedDB."));var M=i.delete(g),c=function(){var D=(I=o.transaction(ow,"readwrite")).objectStore(ow).delete(g);D.onsuccess=function(){return C(Y.result.modelArtifactsInfo)},D.onerror=function(r){return E(Y.error)}};M.onsuccess=c,M.onerror=function(D){return c(),o.close(),E(Y.error)}},Y.onerror=function(M){return o.close(),E(Y.error)},n.oncomplete=function(){I==null?o.close():I.oncomplete=function(){return o.close()}}},e.onerror=function(I){return E(e.error)}})]})})},A}();if(BA().getBool("IS_BROWSER"))try{kQ.registerManager(Zw.URL_SCHEME,new p0)}catch{}var sQ="/",qw="tensorflowjs_models",XD="info",y0="model_topology",z0="weight_specs",W0="weight_data",S0="model_metadata";function OD(A){return{info:[qw,A,XD].join(sQ),topology:[qw,A,y0].join(sQ),weightSpecs:[qw,A,z0].join(sQ),weightData:[qw,A,W0].join(sQ),modelMetadata:[qw,A,S0].join(sQ)}}function L0(A){var g=A.split(sQ);if(g.length<3)throw new Error("Invalid key format: "+A);return g.slice(1,g.length-1).join(sQ)}var _w=function(){function A(g){if(!BA().getBool("IS_BROWSER")||typeof window>"u"||window.localStorage===void 0)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,g==null||!g)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=g,this.keys=OD(this.modelPath)}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w;return UA(this,function(C){if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");B=JSON.stringify(g.modelTopology),Q=JSON.stringify(g.weightSpecs),w=bC(g);try{return this.LS.setItem(this.keys.info,JSON.stringify(w)),this.LS.setItem(this.keys.topology,B),this.LS.setItem(this.keys.weightSpecs,Q),this.LS.setItem(this.keys.weightData,function(E){if(St)return Buffer.from(E).toString("base64");for(var e=new Uint8Array(E),I="",o=0,n=e.length;o<n;o++)I+=String.fromCharCode(e[o]);return btoa(I)}(g.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,userDefinedMetadata:g.userDefinedMetadata})),[2,{modelArtifactsInfo:w}]}catch{throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes="+w.modelTopologyBytes+", weightSpecsBytes="+w.weightSpecsBytes+", weightDataBytes="+w.weightDataBytes+".")}return[2]})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E,e;return UA(this,function(I){if((g=JSON.parse(this.LS.getItem(this.keys.info)))==null)throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if(g.modelTopologyType!=="JSON")throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(B={},(Q=JSON.parse(this.LS.getItem(this.keys.topology)))==null)throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(B.modelTopology=Q,(w=JSON.parse(this.LS.getItem(this.keys.weightSpecs)))==null)throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(B.weightSpecs=w,(C=this.LS.getItem(this.keys.modelMetadata))!=null&&(E=JSON.parse(C),B.format=E.format,B.generatedBy=E.generatedBy,B.convertedBy=E.convertedBy,B.userDefinedMetadata=E.userDefinedMetadata),(e=this.LS.getItem(this.keys.weightData))==null)throw new Error("In local storage, the binary weight values of model '"+this.modelPath+"' are missing.");return B.weightData=function(o){if(St){var n=Buffer.from(o,"base64");return n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)}for(var i=atob(o),Y=new Uint8Array(i.length),M=0;M<i.length;++M)Y.set([i.charCodeAt(M)],M);return Y.buffer}(e),[2,B]})})},A.URL_SCHEME="localstorage://",A}(),ZD=function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(_w.URL_SCHEME)?(g=A.slice(_w.URL_SCHEME.length),new _w(g)):null;var g};fg.registerSaveRouter(ZD),fg.registerLoadRouter(ZD);var b0=function(){function A(){R(BA().getBool("IS_BROWSER"),function(){return"Current environment is not a web browser"}),R(typeof window>"u"||window.localStorage!==void 0,function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return A.prototype.listModels=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E;return UA(this,function(e){for(g={},B=qw+sQ,Q=sQ+XD,w=0;w<this.LS.length;++w)(C=this.LS.key(w)).startsWith(B)&&C.endsWith(Q)&&(E=L0(C),g[E]=JSON.parse(this.LS.getItem(C)));return[2,g]})})},A.prototype.removeModel=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){var C;if(g=(C=g).startsWith(_w.URL_SCHEME)?C.slice(_w.URL_SCHEME.length):C,B=OD(g),this.LS.getItem(B.info)==null)throw new Error("Cannot find model at path '"+g+"'");return Q=JSON.parse(this.LS.getItem(B.info)),this.LS.removeItem(B.info),this.LS.removeItem(B.topology),this.LS.removeItem(B.weightSpecs),this.LS.removeItem(B.weightData),[2,Q]})})},A}();if(BA().getBool("IS_BROWSER"))try{kQ.registerManager(_w.URL_SCHEME,new b0)}catch{}var K0="model",V0=".json",x0=".weights.bin";function qD(A){return new Promise(function(g){return setTimeout(g)}).then(A)}var Kt=function(){function A(g){if(!BA().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");g.startsWith(A.URL_SCHEME)&&(g=g.slice(A.URL_SCHEME.length)),g!=null&&g.length!==0||(g=K0),this.modelTopologyFileName=g+V0,this.weightDataFileName=g+x0}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e;return UA(this,function(I){switch(I.label){case 0:if(typeof document>"u")throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(B=window.URL.createObjectURL(new Blob([g.weightData],{type:"application/octet-stream"})),!(g.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return Q=[{paths:["./"+this.weightDataFileName],weights:g.weightSpecs}],w={modelTopology:g.modelTopology,format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,weightsManifest:Q},C=window.URL.createObjectURL(new Blob([JSON.stringify(w)],{type:"application/json"})),(E=this.jsonAnchor==null?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,E.href=C,[4,qD(function(){return E.dispatchEvent(new MouseEvent("click"))})];case 2:return I.sent(),g.weightData==null?[3,4]:((e=this.weightDataAnchor==null?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,e.href=B,[4,qD(function(){return e.dispatchEvent(new MouseEvent("click"))})]);case 3:I.sent(),I.label=4;case 4:return[2,{modelArtifactsInfo:bC(g)}]}})})},A.URL_SCHEME="downloads://",A}(),X0=function(){function A(g){if(g==null||g.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+g);this.files=g}return A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q=this;return UA(this,function(w){return g=this.files[0],B=this.files.slice(1),[2,new Promise(function(C,E){var e=new FileReader;e.onload=function(I){var o=JSON.parse(I.target.result),n=o.modelTopology;if(n!=null){B.length===0&&C({modelTopology:n});var i=o.weightsManifest;if(i!=null){var Y;try{Y=Q.checkManifestAndWeightFiles(i,B)}catch(r){return void E(r)}var M=[],c=[],D=[];i.forEach(function(r){r.paths.forEach(function(F){c.push(F),D.push(null)}),M.push.apply(M,r.weights)}),i.forEach(function(r){r.paths.forEach(function(F){var s=new FileReader;s.onload=function(u){var a=u.target.result,U=c.indexOf(F);D[U]=a,D.indexOf(null)===-1&&C({modelTopology:n,weightSpecs:M,weightData:Lt(D),format:o.format,generatedBy:o.generatedBy,convertedBy:o.convertedBy,userDefinedMetadata:o.userDefinedMetadata})},s.onerror=function(u){return E("Failed to weights data from file of path '"+F+"'.")},s.readAsArrayBuffer(Y[F])})})}else E(new Error("weightManifest field is missing from file "+g.name))}else E(new Error("modelTopology field is missing from file "+g.name))},e.onerror=function(I){return E("Failed to read model topology and weights manifest JSON from file '"+g.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},e.readAsText(g)})]})})},A.prototype.checkManifestAndWeightFiles=function(g,B){for(var Q=[],w=B.map(function(I){return bD(I.name)}),C={},E=0,e=g;E<e.length;E++)e[E].paths.forEach(function(I){var o=bD(I);if(Q.indexOf(o)!==-1)throw new Error("Duplicate file basename found in weights manifest: '"+o+"'");if(Q.push(o),w.indexOf(o)===-1)throw new Error("Weight file with basename '"+o+"' is not provided.");C[I]=B[w.indexOf(o)]});if(Q.length!==B.length)throw new Error("Mismatch in the number of files in weights manifest ("+Q.length+") and the number of weight files provided ("+B.length+").");return C},A}();function _D(A,g,B,Q){(function(C){R(C!=null&&Array.isArray(C)&&C.length>0,function(){return"promises must be a none empty array"})})(A),function(C,E){R(C>=0&&C<=1,function(){return"Progress fraction must be in range [0, 1], but got startFraction "+C}),R(E>=0&&E<=1,function(){return"Progress fraction must be in range [0, 1], but got endFraction "+E}),R(E>=C,function(){return"startFraction must be no more than endFraction, but got startFraction "+C+" and endFraction "+E})}(B=B??0,Q=Q??1);var w=0;return Promise.all(A.map(function(C){return C.then(function(E){var e=B+ ++w/A.length*(Q-B);return g(e),E}),C}))}function $D(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n;return UA(this,function(i){switch(i.label){case 0:return g==null&&(g={}),B=g.fetchFunc==null?BA().platform.fetch:g.fetchFunc,Q=A.map(function(Y){return B(Y,g.requestInit,{isBinary:!0})}),w=0,C=.5,g.onProgress!=null?[3,2]:[4,Promise.all(Q)];case 1:return E=i.sent(),[3,4];case 2:return[4,_D(Q,g.onProgress,w,C)];case 3:E=i.sent(),i.label=4;case 4:return e=E.map(function(Y){return Y.arrayBuffer()}),I=.5,o=1,g.onProgress!=null?[3,6]:[4,Promise.all(e)];case 5:return n=i.sent(),[3,8];case 6:return[4,_D(e,g.onProgress,I,o)];case 7:n=i.sent(),i.label=8;case 8:return[2,n]}})})}function Ar(A){var g=this;return function(B,Q,w){return Q===void 0&&(Q=""),uA(g,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c;return UA(this,function(D){switch(D.label){case 0:if(C=B.map(function(){return!1}),E={},e=w!=null?w.map(function(){return!1}):[],I=[],B.forEach(function(r,F){var s=0;r.weights.forEach(function(u){var a="quantization"in u?u.quantization.dtype:u.dtype,U=Wt[a]*hA(u.shape),G=function(){C[F]=!0,E[F]==null&&(E[F]=[]),E[F].push({manifestEntry:u,groupOffset:s,sizeBytes:U})};w!=null?w.forEach(function(d,H){d===u.name&&(G(),e[H]=!0)}):G(),I.push(u.name),s+=U})}),!e.every(function(r){return r}))throw o=w.filter(function(r,F){return!e[F]}),new Error("Could not find weights in manifest with names: "+o.join(", ")+`.
3821
- Manifest JSON has weights with names: `+I.join(", ")+".");return n=C.reduce(function(r,F,s){return F&&r.push(s),r},[]),i=[],n.forEach(function(r){B[r].paths.forEach(function(F){var s=Q+(Q.endsWith("/")?"":"/")+F;i.push(s)})}),[4,A(i)];case 1:return Y=D.sent(),M={},c=0,n.forEach(function(r){for(var F=B[r].paths.length,s=0,u=0;u<F;u++)s+=Y[c+u].byteLength;for(var a=new ArrayBuffer(s),U=new Uint8Array(a),G=0,d=0;d<F;d++){var H=new Uint8Array(Y[c+d]);U.set(H,G),G+=H.byteLength}E[r].forEach(function(h){var l=SD(a.slice(h.groupOffset,h.groupOffset+h.sizeBytes),[h.manifestEntry]);for(var m in l)M[m]=l[m]}),c+=F}),[2,M]}})})}}fg.registerSaveRouter(function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(Kt.URL_SCHEME)?function(g){return g===void 0&&(g="model"),new Kt(g)}(A.slice(Kt.URL_SCHEME.length)):null});var Br=function(){function A(g,B){if(this.DEFAULT_METHOD="POST",B==null&&(B={}),this.weightPathPrefix=B.weightPathPrefix,this.onProgress=B.onProgress,B.fetchFunc!=null?(R(typeof B.fetchFunc=="function",function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=B.fetchFunc):this.fetch=BA().platform.fetch,R(g!=null&&g.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(g)&&R(g.length===2,function(){return"URL paths for http must have a length of 2, (actual length is "+g.length+")."}),this.path=g,B.requestInit!=null&&B.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=B.requestInit||{}}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C;return UA(this,function(E){switch(E.label){case 0:if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(B=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,Q=[{paths:["./model.weights.bin"],weights:g.weightSpecs}],w={modelTopology:g.modelTopology,format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,userDefinedMetadata:g.userDefinedMetadata,weightsManifest:Q},B.body.append("model.json",new Blob([JSON.stringify(w)],{type:"application/json"}),"model.json"),g.weightData!=null&&B.body.append("model.weights.bin",new Blob([g.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,B)];case 1:if((C=E.sent()).ok)return[2,{modelArtifactsInfo:bC(g),responses:[C]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+C.status+".")}})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(g=M.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+g.status+". Please verify this URL points to the model JSON of the model to load.");M.label=2;case 2:return M.trys.push([2,4,,5]),[4,g.json()];case 3:return B=M.sent(),[3,5];case 4:throw M.sent(),Q="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?Q+=" 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.":Q+=" Please make sure the server is serving valid JSON for this request.",new Error(Q);case 5:if(w=B.modelTopology,C=B.weightsManifest,E=B.generatedBy,e=B.convertedBy,I=B.format,o=B.userDefinedMetadata,w==null&&C==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return C==null?[3,7]:[4,this.loadWeights(C)];case 6:Y=M.sent(),n=Y[0],i=Y[1],M.label=7;case 7:return[2,{modelTopology:w,weightSpecs:n,weightData:i,userDefinedMetadata:o,generatedBy:E,convertedBy:e,format:I}]}})})},A.prototype.loadWeights=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:for(B=Array.isArray(this.path)?this.path[1]:this.path,Q=function(c){var D=c.lastIndexOf("/"),r=c.lastIndexOf("?"),F=c.substring(0,D),s=r>D?c.substring(r):"";return[F+"/",s]}(B),w=Q[0],C=Q[1],E=this.weightPathPrefix||w,e=[],I=0,o=g;I<o.length;I++)n=o[I],e.push.apply(e,n.weights);return i=[],g.forEach(function(c){c.paths.forEach(function(D){i.push(E+D+C)})}),[4,$D(i,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 1:return Y=M.sent(),[2,[e,Lt(Y)]]}})})},A.URL_SCHEME_REGEX=/^https?:\/\//,A}();function Vt(A){return A.match(Br.URL_SCHEME_REGEX)!=null}var gr=function(A,g){return typeof fetch>"u"?null:(Array.isArray(A)?A.every(function(B){return Vt(B)}):Vt(A))?xt(A,{onProgress:g}):null};function xt(A,g){return new Br(A,g)}fg.registerSaveRouter(gr),fg.registerLoadRouter(gr);var Xt=function(){function A(g){this.modelArtifacts=g}return A.prototype.load=function(){return uA(this,void 0,void 0,function(){return UA(this,function(g){return[2,this.modelArtifacts]})})},A}(),O0=function(){function A(g){this.saveHandler=g}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,this.saveHandler(g)]})})},A}(),Qr=Object.freeze({browserFiles:function(A){return new X0(A)},browserHTTPRequest:function(A,g){return xt(A,g)},concatenateArrayBuffers:Lt,decodeWeights:SD,encodeWeights:function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e=this;return UA(this,function(I){switch(I.label){case 0:for(B=[],Q=[],w=Array.isArray(A)?A.map(function(o){return o.name}):Object.keys(A),C=function(o){var n=w[o],i=Array.isArray(A)?A[o].tensor:A[n];if(i.dtype!=="float32"&&i.dtype!=="int32"&&i.dtype!=="bool"&&i.dtype!=="string")throw new Error("Unsupported dtype in weight '"+n+"': "+i.dtype);var Y={name:n,shape:i.shape,dtype:i.dtype};if(i.dtype==="string"){var M=new Promise(function(c){return uA(e,void 0,void 0,function(){var D,r,F,s,u,a,U;return UA(this,function(G){switch(G.label){case 0:return[4,i.bytes()];case 1:for(D=G.sent(),r=D.reduce(function(d,H){return d+H.length},0)+fe*D.length,F=new Uint8Array(r),s=0,u=0;u<D.length;u++)a=D[u],U=new Uint8Array(new Uint32Array([a.length]).buffer),F.set(U,s),s+=fe,F.set(a,s),s+=a.length;return c(F),[2]}})})});Q.push(M)}else Q.push(i.data());g!=null&&(Y.group=g),B.push(Y)},E=0;E<w.length;++E)C(E);return[4,Promise.all(Q)];case 1:return[2,{data:j0(I.sent()),specs:B}]}})})},fromMemory:function(A,g,B,Q){return arguments.length===1?A.modelTopology!=null||A.weightSpecs!=null?new Xt(A):(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 Xt({modelTopology:A})):(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 Xt({modelTopology:A,weightSpecs:g,weightData:B,trainingConfig:Q}))},getLoadHandlers:function(A,g){return fg.getLoadHandlers(A,g)},getModelArtifactsInfoForJSON:bC,getSaveHandlers:function(A){return fg.getSaveHandlers(A)},http:xt,isHTTPScheme:Vt,loadWeights:function(A,g,B,Q){return g===void 0&&(g=""),uA(this,void 0,void 0,function(){return UA(this,function(w){return[2,Ar(function(C){return $D(C,{requestInit:Q})})(A,g,B)]})})},registerLoadRouter:function(A){return fg.registerLoadRouter(A)},registerSaveRouter:function(A){return fg.registerSaveRouter(A)},weightsLoaderFactory:Ar,withSaveHandler:function(A){return new O0(A)},copyModel:function(A,g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,KD(A,g,!1)]})})},listModels:function(){return uA(this,void 0,void 0,function(){var A,g,B,Q,w,C,E;return UA(this,function(e){switch(e.label){case 0:A=kQ.getSchemes(),g={},B=0,Q=A,e.label=1;case 1:return B<Q.length?(w=Q[B],[4,kQ.getManager(w).listModels()]):[3,4];case 2:for(E in C=e.sent())g[w+Ow+E]=C[E];e.label=3;case 3:return B++,[3,1];case 4:return[2,g]}})})},moveModel:function(A,g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,KD(A,g,!0)]})})},removeModel:function(A){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){return g=Je(A),[2,kQ.getManager(g.scheme).removeModel(g.path)]})})}}),$w;z({confusionMatrix_:function(A,g,B){var Q=J(A,"labels","confusionMatrix"),w=J(g,"predictions","confusionMatrix");R(B==null||B>0&&Number.isInteger(B),function(){return"If provided, numClasses must be a positive integer, but got "+B}),R(Q.rank===1,function(){return"Expected the rank of labels to be 1, but got "+Q.rank}),R(w.rank===1,function(){return"Expected the rank of predictions to be 1, but got "+w.rank}),R(Q.shape[0]===w.shape[0],function(){return"Mismatch in the number of examples: "+Q.shape[0]+" vs. "+w.shape[0]+". Labels and predictions should have the same number of elements."}),R(B>0&&Number.isInteger(B),function(){return"numClasses is required to be a positive integer, but got "+B});var C=Bt(Q.asType("int32"),B),E=Bt(w.asType("int32"),B);return C.transpose().matMul(E).asType("int32")}});var Z0=z({fromPixels_:function(A,g){if(g===void 0&&(g=3),g>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(A==null)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var B=!1,Q=!1,w=!1,C=!1,E=!1;if(A.data instanceof Uint8Array)B=!0;else if(typeof ImageData<"u"&&A instanceof ImageData)Q=!0;else if(typeof HTMLVideoElement<"u"&&A instanceof HTMLVideoElement)w=!0;else if(typeof HTMLImageElement<"u"&&A instanceof HTMLImageElement)C=!0;else{if(A.getContext==null)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 "+A.constructor.name);E=!0}if(w&&w&&A.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");if(kM("FromPixels",b.backendName)!=null)return b.runKernel("FromPixels",{pixels:A},{numChannels:g});var e,I,o=w?[A.videoWidth,A.videoHeight]:[A.width,A.height],n=o[0],i=o[1];if(E?e=A.getContext("2d").getImageData(0,0,n,i).data:Q||B?e=A.data:(C||w)&&($w==null&&($w=document.createElement("canvas").getContext("2d")),$w.canvas.width=n,$w.canvas.height=i,$w.drawImage(A,0,0,n,i),e=$w.getImageData(0,0,n,i).data),g===4)I=new Int32Array(e);else{var Y=n*i;I=new Int32Array(Y*g);for(var M=0;M<Y;M++)for(var c=0;c<g;++c)I[M*g+c]=e[4*M+c]}return _o(I,[i,n,g],"int32")}}),Ot=Object.freeze({toPixels:function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return UA(this,function(h){switch(h.label){case 0:if(B=J(A,"img","toPixels"),A instanceof uB||(B=B.toInt()),B.rank!==2&&B.rank!==3)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+B.rank+".");if(Q=B.shape.slice(0,2),w=Q[0],C=Q[1],(E=B.rank===2?1:B.shape[2])>4||E===2)throw new Error("toPixels only supports depth of size 1, 3 or 4 but got "+E);return[4,B.data()];case 1:return e=h.sent(),I=B.min(),o=B.max(),[4,Promise.all([I.data(),o.data()])];case 2:if(n=h.sent(),i=n[0],Y=n[1],M=i[0],c=Y[0],I.dispose(),o.dispose(),B.dtype==="float32"){if(M<0||c>1)throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range ["+M+" - "+c+"].")}else{if(B.dtype!=="int32")throw new Error("Unsupported type for toPixels: "+B.dtype+". Please use float32 or int32 tensors.");if(M<0||c>255)throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range ["+M+" - "+c+"].")}for(D=B.dtype==="float32"?255:1,r=new Uint8ClampedArray(C*w*4),F=0;F<w*C;++F)s=void 0,u=void 0,a=void 0,U=void 0,E===1?(s=e[F]*D,u=e[F]*D,a=e[F]*D,U=255):E===3?(s=e[3*F]*D,u=e[3*F+1]*D,a=e[3*F+2]*D,U=255):E===4&&(s=e[4*F]*D,u=e[4*F+1]*D,a=e[4*F+2]*D,U=e[4*F+3]*D),r[(G=4*F)+0]=Math.round(s),r[G+1]=Math.round(u),r[G+2]=Math.round(a),r[G+3]=Math.round(U);return g!=null&&(g.width=C,g.height=w,d=g.getContext("2d"),H=new ImageData(r,C,w),d.putImageData(H,0,0)),B!==A&&B.dispose(),[2,r]}})})},fromPixels:Z0}),q0=function(){function A(){}return A.prototype.getClassName=function(){return this.constructor.className},A.fromConfig=function(g,B){return new g(B)},A}(),_0=function(){function A(){this.classNameMap={}}return A.getMap=function(){return A.instance==null&&(A.instance=new A),A.instance},A.register=function(g){A.getMap().classNameMap[g.className]=[g,g.fromConfig]},A}();function tw(A){R(A.className!=null,function(){return"Class being registered does not have the static className property defined."}),R(typeof A.className=="string",function(){return"className is required to be a string, but got type "+typeof A.className}),R(A.className.length>0,function(){return"Class being registered has an empty-string as its className, which is disallowed."}),_0.register(A)}var nw=function(A){function g(){return A!==null&&A.apply(this,arguments)||this}return Wg(g,A),g.prototype.minimize=function(B,Q,w){Q===void 0&&(Q=!1);var C=this.computeGradients(B,w),E=C.value,e=C.grads;if(w!=null){var I=w.map(function(o){return{name:o.name,tensor:e[o.name]}});this.applyGradients(I)}else this.applyGradients(e);return Mg(e),Q?E:(E.dispose(),null)},Object.defineProperty(g.prototype,"iterations",{get:function(){return this.iterations_==null&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),g.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},g.prototype.computeGradients=function(B,Q){return ef(B,Q)},g.prototype.dispose=function(){this.iterations_!=null&&Mg(this.iterations_)},g.prototype.saveIterations=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){return this.iterations_==null&&(this.iterations_=0),[2,{name:"iter",tensor:nA(this.iterations_,"int32")}]})})},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){throw new Error("getWeights() is not implemented for this optimizer yet.")})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){throw new Error("setWeights() is not implemented for this optimizer class "+this.getClassName())})})},g.prototype.extractIterations=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return Q=this,[4,B[0].tensor.data()];case 1:return Q.iterations_=w.sent()[0],[2,B.slice(1)]}})})},g}(q0);Object.defineProperty(nw,Symbol.hasInstance,{value:function(A){return A.minimize!=null&&A.computeGradients!=null&&A.applyGradients!=null}});var $0=function(A){function g(B,Q,w){w===void 0&&(w=null);var C=A.call(this)||this;return C.learningRate=B,C.rho=Q,C.epsilon=w,C.accumulatedGrads=[],C.accumulatedUpdates=[],w==null&&(C.epsilon=b.backend.epsilon()),C}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedGrads[C]==null&&(Q.accumulatedGrads[C]={originalName:w+"/accum_grad",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedUpdates[C]==null&&(Q.accumulatedUpdates[C]={originalName:w+"/accum_var",variable:DA(function(){return $A(E).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedGrads[C].variable,o=Q.accumulatedUpdates[C].variable;DA(function(){var n=I.mul(Q.rho).add(e.square().mul(1-Q.rho)),i=o.add(Q.epsilon).sqrt().div(I.add(Q.epsilon).sqrt()).mul(e),Y=o.mul(Q.rho).add(i.square().mul(1-Q.rho));I.assign(n),o.assign(Y);var M=i.mul(-Q.learningRate).add(E);E.assign(M)})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedUpdates!=null&&(Mg(this.accumulatedGrads.map(function(B){return B.variable})),Mg(this.accumulatedUpdates.map(function(B){return B.variable})))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return[4,this.extractIterations(B)];case 1:return B=w.sent(),Q=B.length/2,this.accumulatedGrads=B.slice(0,Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.accumulatedUpdates=B.slice(Q,2*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.rho,Q.epsilon)},g.className="Adadelta",g}(nw);tw($0);var AR=function(A){function g(B,Q){Q===void 0&&(Q=.1);var w=A.call(this)||this;return w.learningRate=B,w.initialAccumulatorValue=Q,w.accumulatedGrads=[],w}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedGrads[C]==null&&(Q.accumulatedGrads[C]={originalName:w+"/accumulator",variable:DA(function(){return gQ(E.shape,Q.initialAccumulatorValue).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedGrads[C].variable;DA(function(){var o=I.add(e.square());I.assign(o);var n=e.div(o.add(b.backend.epsilon()).sqrt()).mul(-Q.learningRate).add(E);E.assign(n)})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedGrads!=null&&Mg(this.accumulatedGrads.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()].concat(this.accumulatedGrads.map(function(Q){return{name:Q.originalName,tensor:Q.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:return B=Q.sent(),this.accumulatedGrads=B.map(function(w){return{originalName:w.name,variable:w.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.initialAccumulatorValue)},g.className="Adagrad",g}(nw);tw(AR);var BR=function(A){function g(B,Q,w,C){C===void 0&&(C=null);var E=A.call(this)||this;return E.learningRate=B,E.beta1=Q,E.beta2=w,E.epsilon=C,E.accumulatedFirstMoment=[],E.accumulatedSecondMoment=[],DA(function(){E.accBeta1=nA(Q).variable(),E.accBeta2=nA(w).variable()}),C==null&&(E.epsilon=b.backend.epsilon()),E}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this,w=Array.isArray(B)?B.map(function(C){return C.name}):Object.keys(B);DA(function(){var C=zB(1,Q.accBeta1),E=zB(1,Q.accBeta2);w.forEach(function(e,I){var o=b.registeredVariables[e];Q.accumulatedFirstMoment[I]==null&&(Q.accumulatedFirstMoment[I]={originalName:e+"/m",variable:DA(function(){return $A(o).variable(!1)})}),Q.accumulatedSecondMoment[I]==null&&(Q.accumulatedSecondMoment[I]={originalName:e+"/v",variable:DA(function(){return $A(o).variable(!1)})});var n=Array.isArray(B)?B[I].tensor:B[e];if(n!=null){var i=Q.accumulatedFirstMoment[I].variable,Y=Q.accumulatedSecondMoment[I].variable,M=i.mul(Q.beta1).add(n.mul(1-Q.beta1)),c=Y.mul(Q.beta2).add(n.square().mul(1-Q.beta2)),D=M.div(C),r=c.div(E);i.assign(M),Y.assign(c);var F=D.div(r.sqrt().add(Q.epsilon)).mul(-Q.learningRate).add(o);o.assign(F)}}),Q.accBeta1.assign(Q.accBeta1.mul(Q.beta1)),Q.accBeta2.assign(Q.accBeta2.mul(Q.beta2))}),this.incrementIterations()},g.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&Mg(this.accumulatedFirstMoment.map(function(B){return B.variable})),this.accumulatedSecondMoment!=null&&Mg(this.accumulatedSecondMoment.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q,w=this;return UA(this,function(C){switch(C.label){case 0:return[4,this.extractIterations(B)];case 1:return B=C.sent(),DA(function(){w.accBeta1.assign(Ue(w.beta1,w.iterations_+1)),w.accBeta2.assign(Ue(w.beta2,w.iterations_+1))}),Q=B.length/2,this.accumulatedFirstMoment=B.slice(0,Q).map(function(E){return{originalName:E.name,variable:E.tensor.variable(!1)}}),this.accumulatedSecondMoment=B.slice(Q,2*Q).map(function(E){return{originalName:E.name,variable:E.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.beta1,Q.beta2,Q.epsilon)},g.className="Adam",g}(nw);tw(BR);var gR=function(A){function g(B,Q,w,C,E){C===void 0&&(C=null),E===void 0&&(E=0);var e=A.call(this)||this;return e.learningRate=B,e.beta1=Q,e.beta2=w,e.epsilon=C,e.decay=E,e.accumulatedFirstMoment=[],e.accumulatedWeightedInfNorm=[],DA(function(){e.iteration=nA(0).variable(),e.accBeta1=nA(Q).variable()}),C==null&&(e.epsilon=b.backend.epsilon()),e}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this,w=Array.isArray(B)?B.map(function(C){return C.name}):Object.keys(B);DA(function(){var C=zB(1,Q.accBeta1),E=bg(-Q.learningRate,Q.iteration.mul(Q.decay).add(1));w.forEach(function(e,I){var o=b.registeredVariables[e];Q.accumulatedFirstMoment[I]==null&&(Q.accumulatedFirstMoment[I]={originalName:e+"/m",variable:$A(o).variable(!1)}),Q.accumulatedWeightedInfNorm[I]==null&&(Q.accumulatedWeightedInfNorm[I]={originalName:e+"/v",variable:$A(o).variable(!1)});var n=Array.isArray(B)?B[I].tensor:B[e];if(n!=null){var i=Q.accumulatedFirstMoment[I].variable,Y=Q.accumulatedWeightedInfNorm[I].variable,M=i.mul(Q.beta1).add(n.mul(1-Q.beta1)),c=Y.mul(Q.beta2),D=n.abs(),r=c.maximum(D);i.assign(M),Y.assign(r);var F=E.div(C).mul(M.div(r.add(Q.epsilon))).add(o);o.assign(F)}}),Q.iteration.assign(Q.iteration.add(1)),Q.accBeta1.assign(Q.accBeta1.mul(Q.beta1))}),this.incrementIterations()},g.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&Mg(this.accumulatedFirstMoment.map(function(B){return B.variable})),this.accumulatedWeightedInfNorm!=null&&Mg(this.accumulatedWeightedInfNorm.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){throw new Error("getWeights() is not implemented for Adamax yet.")})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){throw new Error("setWeights() is not implemented for Adamax yet.")})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.beta1,Q.beta2,Q.epsilon,Q.decay)},g.className="Adamax",g}(nw);tw(gR);var wr=function(A){function g(B){var Q=A.call(this)||this;return Q.learningRate=B,Q.setLearningRate(B),Q}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=Array.isArray(B)?B[C].tensor:B[w];if(E!=null){var e=b.registeredVariables[w];DA(function(){var I=Q.c.mul(E).add(e);e.assign(I)})}}),this.incrementIterations()},g.prototype.setLearningRate=function(B){this.learningRate=B,this.c!=null&&this.c.dispose(),this.c=uH(nA(-B))},g.prototype.dispose=function(){this.c.dispose()},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()]]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:if((B=Q.sent()).length!==0)throw new Error("SGD optimizer does not have settable weights.");return[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate}},g.fromConfig=function(B,Q){return new B(Q.learningRate)},g.className="SGD",g}(nw);tw(wr);var QR=function(A){function g(B,Q,w){w===void 0&&(w=!1);var C=A.call(this,B)||this;return C.learningRate=B,C.momentum=Q,C.useNesterov=w,C.accumulations=[],C.m=nA(C.momentum),C}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulations[C]==null&&(Q.accumulations[C]={originalName:w+"/momentum",variable:DA(function(){return $A(E).variable(!1)})});var e=Q.accumulations[C].variable,I=Array.isArray(B)?B[C].tensor:B[w];I!=null&&DA(function(){var o,n=Q.m.mul(e).add(I);o=Q.useNesterov?Q.c.mul(I.add(n.mul(Q.m))).add(E):Q.c.mul(n).add(E),e.assign(n),E.assign(o)})}),this.incrementIterations()},g.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&Mg(this.accumulations.map(function(B){return B.variable}))},g.prototype.setMomentum=function(B){this.momentum=B},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()].concat(this.accumulations.map(function(Q){return{name:Q.originalName,tensor:Q.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:return B=Q.sent(),this.accumulations=B.map(function(w){return{originalName:w.name,variable:w.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.momentum,Q.useNesterov)},g.className="Momentum",g}(wr);tw(QR);var wR=function(A){function g(B,Q,w,C,E){Q===void 0&&(Q=.9),w===void 0&&(w=0),C===void 0&&(C=null),E===void 0&&(E=!1);var e=A.call(this)||this;if(e.learningRate=B,e.decay=Q,e.momentum=w,e.epsilon=C,e.accumulatedMeanSquares=[],e.accumulatedMoments=[],e.accumulatedMeanGrads=[],e.centered=E,C==null&&(e.epsilon=b.backend.epsilon()),B==null)throw new Error("learningRate for RMSPropOptimizer must be defined.");return e}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedMeanSquares[C]==null&&(Q.accumulatedMeanSquares[C]={originalName:w+"/rms",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedMoments[C]==null&&(Q.accumulatedMoments[C]={originalName:w+"/momentum",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedMeanGrads[C]==null&&Q.centered&&(Q.accumulatedMeanGrads[C]={originalName:w+"/mg",variable:DA(function(){return $A(E).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedMeanSquares[C].variable,o=Q.accumulatedMoments[C].variable;DA(function(){var n=I.mul(Q.decay).add(e.square().mul(1-Q.decay));if(Q.centered){var i=Q.accumulatedMeanGrads[C].variable,Y=i.mul(Q.decay).add(e.mul(1-Q.decay)),M=o.mul(Q.momentum).add(e.mul(Q.learningRate).div(n.sub(Y.square().add(Q.epsilon)).sqrt()));I.assign(n),i.assign(Y),o.assign(M);var c=E.sub(M);E.assign(c)}else{var D=I.mul(Q.decay).add(e.square().mul(1-Q.decay));M=o.mul(Q.momentum).add(e.mul(Q.learningRate).div(D.add(Q.epsilon).sqrt())),I.assign(D),o.assign(M),c=E.sub(M),E.assign(c)}})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&Mg(this.accumulatedMeanSquares.map(function(B){return B.variable})),this.accumulatedMeanGrads!=null&&this.centered&&Mg(this.accumulatedMeanGrads.map(function(B){return B.variable})),this.accumulatedMoments!=null&&Mg(this.accumulatedMoments.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&B.push.apply(B,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return[4,this.extractIterations(B)];case 1:return B=w.sent(),Q=this.centered?B.length/3:B.length/2,this.accumulatedMeanSquares=B.slice(0,Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.accumulatedMoments=B.slice(Q,2*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.centered&&(this.accumulatedMeanGrads=B.slice(2*Q,3*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}})),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.decay,Q.momentum,Q.epsilon,Q.centered)},g.className="RMSProp",g}(nw);tw(wR),typeof requestAnimationFrame<"u"||typeof setImmediate<"u"&&setImmediate,uB.prototype.squaredDifference=function(A){return wD(this,A)},O=N0;function iw(A,g,B){if(B===void 0&&(B=!1),A.beginPath(),g.slice(1).forEach(function(C,E){var e=C.x,I=C.y,o=g[E];A.moveTo(o.x,o.y),A.lineTo(e,I)}),B){var Q=g[g.length-1],w=g[0];if(!Q||!w)return;A.moveTo(Q.x,Q.y),A.lineTo(w.x,w.y)}A.stroke()}/*! *****************************************************************************
3820
+ `},yt=0,zD=[{kernelName:"FromPixels",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs,w=g.pixels,C=Q.numChannels,E=typeof HTMLVideoElement<"u"&&w instanceof HTMLVideoElement,e=typeof HTMLImageElement<"u"&&w instanceof HTMLImageElement,I=E?[w.videoWidth,w.videoHeight]:[w.width,w.height],o=I[0],n=I[1],i=[n,o],Y=[n,o,C];(e||E)&&(Xw==null&&(Xw=document.createElement("canvas").getContext("2d")),Xw.canvas.width=o,Xw.canvas.height=n,Xw.drawImage(w,0,0,o,n),w=Xw.canvas);var M=B.makeTensorInfo(i,"int32");B.texData.get(M.dataId).usage=hg.PIXELS,B.gpgpu.uploadPixelDataToTexture(B.getTexture(M.dataId),w);var c=BA().getBool("WEBGL_PACK")?new k0(Y):new v0(Y),D=B.runWebGLProgram(c,[M],"int32");return B.disposeData(M.dataId),D}},{kernelName:"NonMaxSuppressionV5",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=A.attrs;ge("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var w=g,C=w.boxes,E=w.scores,e=Q,I=e.maxOutputSize,o=e.iouThreshold,n=e.scoreThreshold,i=e.softNmsSigma,Y=B,M=tt(Y.readSync(C.dataId),Y.readSync(E.dataId),I,o,n,i);return[M.selectedIndices,M.selectedScores]}},{kernelName:"Square",backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g.x,w=B,C=new KA(Q.shape,"return x * x;");return w.runWebGLProgram(C,[Q],Q.dtype)}},{kernelName:zC,backendName:"webgl",kernelFunc:function(A){var g=A.inputs,B=A.backend,Q=g,w=Q.a,C=Q.b,E=B,e=BA().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new FQ("return (a - b) * (a - b);",w.shape,C.shape):new lB("return (a - b) * (a - b);",w.shape,C.shape);return E.compileAndRun(e,[w,C])}}];yt<zD.length;yt++)jM(zD[yt]);for(var zt=0,WD=[{kernelName:"Square",gradFunc:function(A,g){var B=g[0];return{x:function(){return A.mul(B.toFloat().mul(2))}}}},{kernelName:zC,gradFunc:function(A,g){var B=g[0],Q=g[1],w=nA(2);return{a:function(){return wg(A,wg(w,zB(B,Q)))},b:function(){return wg(A,wg(w,zB(Q,B)))}}}}];zt<WD.length;zt++)md(WD[zt]);var T0=function(){function A(){}return A.prototype.fetch=function(g,B){return fetch(g,B)},A.prototype.now=function(){return performance.now()},A.prototype.encode=function(g,B){if(B!=="utf-8"&&B!=="utf8")throw new Error("Browser's encoder only supports utf-8, but got "+B);return this.textEncoder==null&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(g)},A.prototype.decode=function(g,B){return new TextDecoder(B).decode(g)},A}();BA().get("IS_BROWSER")&&BA().setPlatform("browser",new T0);var Wt,j0=function(){return require("node-fetch")},p0=function(){function A(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return A.prototype.fetch=function(g,B){return BA().global.fetch!=null?BA().global.fetch(g,B):(Wt==null&&(Wt=j0()),Wt(g,B))},A.prototype.now=function(){var g=process.hrtime();return 1e3*g[0]+g[1]/1e6},A.prototype.encode=function(g,B){if(B!=="utf-8"&&B!=="utf8")throw new Error("Node built-in encoder only supports utf-8, but got "+B);return this.textEncoder.encode(g)},A.prototype.decode=function(g,B){return g.length===0?"":new this.util.TextDecoder(B).decode(g)},A}();BA().get("IS_NODE")&&BA().setPlatform("node",new p0);var St={float32:4,int32:4,uint16:2,uint8:1,bool:1},fe=4;function SD(A,g){for(var B={},Q=0,w=function(e){var I=e.name,o=e.dtype,n=e.shape,i=hA(n),Y=void 0;if("quantization"in e){var M=e.quantization;if(M.dtype!=="uint8"&&M.dtype!=="uint16")throw new Error("Weight "+e.name+" has unknown quantization dtype "+M.dtype+". Supported quantization dtypes are: 'uint8' and 'uint16'.");var c=St[M.dtype],D=A.slice(Q,Q+i*c),r=M.dtype==="uint8"?new Uint8Array(D):new Uint16Array(D);if(o==="float32")Y=Float32Array.from(r,function(G){return G*M.scale+M.min});else{if(o!=="int32")throw new Error("Unsupported dtype in weight '"+I+"': "+o);Y=Int32Array.from(r,function(G){return Math.round(G*M.scale+M.min)})}Q+=i*c}else if(o==="string"){var F=hA(e.shape);Y=[];for(var s=0;s<F;s++){var u=new Uint32Array(A.slice(Q,Q+fe))[0];Q+=fe;var a=new Uint8Array(A.slice(Q,Q+u));Y.push(a),Q+=u}}else{var U=St[o];if(D=A.slice(Q,Q+i*U),o==="float32")Y=new Float32Array(D);else if(o==="int32")Y=new Int32Array(D);else{if(o!=="bool")throw new Error("Unsupported dtype in weight '"+I+"': "+o);Y=new Uint8Array(D)}Q+=i*U}B[I]=Ag(Y,n,o)},C=0,E=g;C<E.length;C++)w(E[C]);return B}function y0(A){if(A===null)throw new Error("Invalid input value: "+JSON.stringify(A));var g=0,B=[];A.forEach(function(C){if(g+=C.byteLength,B.push(C.byteLength===C.buffer.byteLength?C:new C.constructor(C)),!(C instanceof Float32Array||C instanceof Int32Array||C instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+C.constructor.name)});var Q=new Uint8Array(g),w=0;return B.forEach(function(C){Q.set(new Uint8Array(C.buffer),w),w+=C.byteLength}),Q.buffer}var Lt=typeof Buffer<"u"&&(typeof Blob>"u"||typeof atob>"u"||typeof btoa>"u");function LD(A){return Lt?Buffer.byteLength(A):new Blob([A]).size}function bt(A){var g=0;A.forEach(function(w){g+=w.byteLength});var B=new Uint8Array(g),Q=0;return A.forEach(function(w){B.set(new Uint8Array(w),Q),Q+=w.byteLength}),B.buffer}function bD(A){for(A=A.trim();A.endsWith("/");)A=A.slice(0,A.length-1);var g=A.split("/");return g[g.length-1]}function bC(A){if(A.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:A.modelTopology==null?0:LD(JSON.stringify(A.modelTopology)),weightSpecsBytes:A.weightSpecs==null?0:LD(JSON.stringify(A.weightSpecs)),weightDataBytes:A.weightData==null?0:A.weightData.byteLength}}var fg=function(){function A(){this.saveRouters=[],this.loadRouters=[]}return A.getInstance=function(){return A.instance==null&&(A.instance=new A),A.instance},A.registerSaveRouter=function(g){A.getInstance().saveRouters.push(g)},A.registerLoadRouter=function(g){A.getInstance().loadRouters.push(g)},A.getSaveHandlers=function(g){return A.getHandlers(g,"save")},A.getLoadHandlers=function(g,B){return A.getHandlers(g,"load",B)},A.getHandlers=function(g,B,Q){var w=[];return(B==="load"?A.getInstance().loadRouters:A.getInstance().saveRouters).forEach(function(C){var E=C(g,Q);E!==null&&w.push(E)}),w},A}(),Ow="://",kQ=function(){function A(){this.managers={}}return A.getInstance=function(){return A.instance==null&&(A.instance=new A),A.instance},A.registerManager=function(g,B){R(g!=null,function(){return"scheme must not be undefined or null."}),g.endsWith(Ow)&&(g=g.slice(0,g.indexOf(Ow))),R(g.length>0,function(){return"scheme must not be an empty string."});var Q=A.getInstance();R(Q.managers[g]==null,function(){return"A model store manager is already registered for scheme '"+g+"'."}),Q.managers[g]=B},A.getManager=function(g){var B=this.getInstance().managers[g];if(B==null)throw new Error("Cannot find model manager for scheme '"+g+"'");return B},A.getSchemes=function(){return Object.keys(this.getInstance().managers)},A}();function Je(A){if(A.indexOf(Ow)===-1)throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+kQ.getSchemes().join(","));return{scheme:A.split(Ow)[0],path:A.split(Ow)[1]}}function KD(A,g,B){return B===void 0&&(B=!1),uA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o,n,i;return UA(this,function(Y){switch(Y.label){case 0:return R(A!==g,function(){return"Old path and new path are the same: '"+A+"'"}),R((Q=fg.getLoadHandlers(A)).length>0,function(){return"Copying failed because no load handler is found for source URL "+A+"."}),R(Q.length<2,function(){return"Copying failed because more than one ("+Q.length+") load handlers for source URL "+A+"."}),w=Q[0],R((C=fg.getSaveHandlers(g)).length>0,function(){return"Copying failed because no save handler is found for destination URL "+g+"."}),R(C.length<2,function(){return"Copying failed because more than one ("+Q.length+") save handlers for destination URL "+g+"."}),E=C[0],e=Je(A).scheme,I=Je(A).path,o=e===Je(A).scheme,[4,w.load()];case 1:return n=Y.sent(),B&&o?[4,kQ.getManager(e).removeModel(I)]:[3,3];case 2:Y.sent(),Y.label=3;case 3:return[4,E.save(n)];case 4:return i=Y.sent(),!B||o?[3,6]:[4,kQ.getManager(e).removeModel(I)];case 5:Y.sent(),Y.label=6;case 6:return[2,i.modelArtifactsInfo]}})})}var ow="models_store",TQ="model_info_store";function VD(){if(!BA().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var A=window||self,g=A.indexedDB||A.mozIndexedDB||A.webkitIndexedDB||A.msIndexedDB||A.shimIndexedDB;if(g==null)throw new Error("The current browser does not appear to support IndexedDB.");return g}function Kt(A){var g=A.result;g.createObjectStore(ow,{keyPath:"modelPath"}),g.createObjectStore(TQ,{keyPath:"modelPath"})}var Zw=function(){function A(g){if(this.indexedDB=VD(),g==null||!g)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=g}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){return UA(this,function(B){if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,g)]})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){return UA(this,function(g){return[2,this.databaseAction(this.modelPath)]})})},A.prototype.databaseAction=function(g,B){var Q=this;return new Promise(function(w,C){var E=Q.indexedDB.open("tensorflowjs",1);E.onupgradeneeded=function(){return Kt(E)},E.onsuccess=function(){var e=E.result;if(B==null){var I=e.transaction(ow,"readonly"),o=I.objectStore(ow).get(Q.modelPath);o.onsuccess=function(){if(o.result==null)return e.close(),C(new Error("Cannot find model with path '"+Q.modelPath+"' in IndexedDB."));w(o.result.modelArtifacts)},o.onerror=function(D){return e.close(),C(o.error)},I.oncomplete=function(){return e.close()}}else{var n,i=bC(B),Y=e.transaction(TQ,"readwrite"),M=Y.objectStore(TQ),c=M.put({modelPath:Q.modelPath,modelArtifactsInfo:i});c.onsuccess=function(){var D=(n=e.transaction(ow,"readwrite")).objectStore(ow).put({modelPath:Q.modelPath,modelArtifacts:B,modelArtifactsInfo:i});D.onsuccess=function(){return w({modelArtifactsInfo:i})},D.onerror=function(r){var F=(M=Y.objectStore(TQ)).delete(Q.modelPath);F.onsuccess=function(){return e.close(),C(D.error)},F.onerror=function(s){return e.close(),C(D.error)}}},c.onerror=function(D){return e.close(),C(c.error)},Y.oncomplete=function(){n==null?e.close():n.oncomplete=function(){return e.close()}}}},E.onerror=function(e){return C(E.error)}})},A.URL_SCHEME="indexeddb://",A}(),xD=function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(Zw.URL_SCHEME)?(g=A.slice(Zw.URL_SCHEME.length),new Zw(g)):null;var g};fg.registerSaveRouter(xD),fg.registerLoadRouter(xD);var z0=function(){function A(){this.indexedDB=VD()}return A.prototype.listModels=function(){return uA(this,void 0,void 0,function(){var g=this;return UA(this,function(B){return[2,new Promise(function(Q,w){var C=g.indexedDB.open("tensorflowjs",1);C.onupgradeneeded=function(){return Kt(C)},C.onsuccess=function(){var E=C.result,e=E.transaction(TQ,"readonly"),I=e.objectStore(TQ).getAll();I.onsuccess=function(){for(var o={},n=0,i=I.result;n<i.length;n++){var Y=i[n];o[Y.modelPath]=Y.modelArtifactsInfo}Q(o)},I.onerror=function(o){return E.close(),w(I.error)},e.oncomplete=function(){return E.close()}},C.onerror=function(E){return w(C.error)}})]})})},A.prototype.removeModel=function(g){return uA(this,void 0,void 0,function(){var B=this;return UA(this,function(Q){var w;return g=(w=g).startsWith(Zw.URL_SCHEME)?w.slice(Zw.URL_SCHEME.length):w,[2,new Promise(function(C,E){var e=B.indexedDB.open("tensorflowjs",1);e.onupgradeneeded=function(){return Kt(e)},e.onsuccess=function(){var I,o=e.result,n=o.transaction(TQ,"readwrite"),i=n.objectStore(TQ),Y=i.get(g);Y.onsuccess=function(){if(Y.result==null)return o.close(),E(new Error("Cannot find model with path '"+g+"' in IndexedDB."));var M=i.delete(g),c=function(){var D=(I=o.transaction(ow,"readwrite")).objectStore(ow).delete(g);D.onsuccess=function(){return C(Y.result.modelArtifactsInfo)},D.onerror=function(r){return E(Y.error)}};M.onsuccess=c,M.onerror=function(D){return c(),o.close(),E(Y.error)}},Y.onerror=function(M){return o.close(),E(Y.error)},n.oncomplete=function(){I==null?o.close():I.oncomplete=function(){return o.close()}}},e.onerror=function(I){return E(e.error)}})]})})},A}();if(BA().getBool("IS_BROWSER"))try{kQ.registerManager(Zw.URL_SCHEME,new z0)}catch{}var sQ="/",qw="tensorflowjs_models",XD="info",W0="model_topology",S0="weight_specs",L0="weight_data",b0="model_metadata";function OD(A){return{info:[qw,A,XD].join(sQ),topology:[qw,A,W0].join(sQ),weightSpecs:[qw,A,S0].join(sQ),weightData:[qw,A,L0].join(sQ),modelMetadata:[qw,A,b0].join(sQ)}}function K0(A){var g=A.split(sQ);if(g.length<3)throw new Error("Invalid key format: "+A);return g.slice(1,g.length-1).join(sQ)}var _w=function(){function A(g){if(!BA().getBool("IS_BROWSER")||typeof window>"u"||window.localStorage===void 0)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,g==null||!g)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=g,this.keys=OD(this.modelPath)}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w;return UA(this,function(C){if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");B=JSON.stringify(g.modelTopology),Q=JSON.stringify(g.weightSpecs),w=bC(g);try{return this.LS.setItem(this.keys.info,JSON.stringify(w)),this.LS.setItem(this.keys.topology,B),this.LS.setItem(this.keys.weightSpecs,Q),this.LS.setItem(this.keys.weightData,function(E){if(Lt)return Buffer.from(E).toString("base64");for(var e=new Uint8Array(E),I="",o=0,n=e.length;o<n;o++)I+=String.fromCharCode(e[o]);return btoa(I)}(g.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,userDefinedMetadata:g.userDefinedMetadata})),[2,{modelArtifactsInfo:w}]}catch{throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes="+w.modelTopologyBytes+", weightSpecsBytes="+w.weightSpecsBytes+", weightDataBytes="+w.weightDataBytes+".")}return[2]})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E,e;return UA(this,function(I){if((g=JSON.parse(this.LS.getItem(this.keys.info)))==null)throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if(g.modelTopologyType!=="JSON")throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(B={},(Q=JSON.parse(this.LS.getItem(this.keys.topology)))==null)throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(B.modelTopology=Q,(w=JSON.parse(this.LS.getItem(this.keys.weightSpecs)))==null)throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(B.weightSpecs=w,(C=this.LS.getItem(this.keys.modelMetadata))!=null&&(E=JSON.parse(C),B.format=E.format,B.generatedBy=E.generatedBy,B.convertedBy=E.convertedBy,B.userDefinedMetadata=E.userDefinedMetadata),(e=this.LS.getItem(this.keys.weightData))==null)throw new Error("In local storage, the binary weight values of model '"+this.modelPath+"' are missing.");return B.weightData=function(o){if(Lt){var n=Buffer.from(o,"base64");return n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)}for(var i=atob(o),Y=new Uint8Array(i.length),M=0;M<i.length;++M)Y.set([i.charCodeAt(M)],M);return Y.buffer}(e),[2,B]})})},A.URL_SCHEME="localstorage://",A}(),ZD=function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(_w.URL_SCHEME)?(g=A.slice(_w.URL_SCHEME.length),new _w(g)):null;var g};fg.registerSaveRouter(ZD),fg.registerLoadRouter(ZD);var V0=function(){function A(){R(BA().getBool("IS_BROWSER"),function(){return"Current environment is not a web browser"}),R(typeof window>"u"||window.localStorage!==void 0,function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return A.prototype.listModels=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E;return UA(this,function(e){for(g={},B=qw+sQ,Q=sQ+XD,w=0;w<this.LS.length;++w)(C=this.LS.key(w)).startsWith(B)&&C.endsWith(Q)&&(E=K0(C),g[E]=JSON.parse(this.LS.getItem(C)));return[2,g]})})},A.prototype.removeModel=function(g){return uA(this,void 0,void 0,function(){var B,Q;return UA(this,function(w){var C;if(g=(C=g).startsWith(_w.URL_SCHEME)?C.slice(_w.URL_SCHEME.length):C,B=OD(g),this.LS.getItem(B.info)==null)throw new Error("Cannot find model at path '"+g+"'");return Q=JSON.parse(this.LS.getItem(B.info)),this.LS.removeItem(B.info),this.LS.removeItem(B.topology),this.LS.removeItem(B.weightSpecs),this.LS.removeItem(B.weightData),[2,Q]})})},A}();if(BA().getBool("IS_BROWSER"))try{kQ.registerManager(_w.URL_SCHEME,new V0)}catch{}var x0="model",X0=".json",O0=".weights.bin";function qD(A){return new Promise(function(g){return setTimeout(g)}).then(A)}var Vt=function(){function A(g){if(!BA().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");g.startsWith(A.URL_SCHEME)&&(g=g.slice(A.URL_SCHEME.length)),g!=null&&g.length!==0||(g=x0),this.modelTopologyFileName=g+X0,this.weightDataFileName=g+O0}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e;return UA(this,function(I){switch(I.label){case 0:if(typeof document>"u")throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(B=window.URL.createObjectURL(new Blob([g.weightData],{type:"application/octet-stream"})),!(g.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return Q=[{paths:["./"+this.weightDataFileName],weights:g.weightSpecs}],w={modelTopology:g.modelTopology,format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,weightsManifest:Q},C=window.URL.createObjectURL(new Blob([JSON.stringify(w)],{type:"application/json"})),(E=this.jsonAnchor==null?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,E.href=C,[4,qD(function(){return E.dispatchEvent(new MouseEvent("click"))})];case 2:return I.sent(),g.weightData==null?[3,4]:((e=this.weightDataAnchor==null?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,e.href=B,[4,qD(function(){return e.dispatchEvent(new MouseEvent("click"))})]);case 3:I.sent(),I.label=4;case 4:return[2,{modelArtifactsInfo:bC(g)}]}})})},A.URL_SCHEME="downloads://",A}(),Z0=function(){function A(g){if(g==null||g.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+g);this.files=g}return A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q=this;return UA(this,function(w){return g=this.files[0],B=this.files.slice(1),[2,new Promise(function(C,E){var e=new FileReader;e.onload=function(I){var o=JSON.parse(I.target.result),n=o.modelTopology;if(n!=null){B.length===0&&C({modelTopology:n});var i=o.weightsManifest;if(i!=null){var Y;try{Y=Q.checkManifestAndWeightFiles(i,B)}catch(r){return void E(r)}var M=[],c=[],D=[];i.forEach(function(r){r.paths.forEach(function(F){c.push(F),D.push(null)}),M.push.apply(M,r.weights)}),i.forEach(function(r){r.paths.forEach(function(F){var s=new FileReader;s.onload=function(u){var a=u.target.result,U=c.indexOf(F);D[U]=a,D.indexOf(null)===-1&&C({modelTopology:n,weightSpecs:M,weightData:bt(D),format:o.format,generatedBy:o.generatedBy,convertedBy:o.convertedBy,userDefinedMetadata:o.userDefinedMetadata})},s.onerror=function(u){return E("Failed to weights data from file of path '"+F+"'.")},s.readAsArrayBuffer(Y[F])})})}else E(new Error("weightManifest field is missing from file "+g.name))}else E(new Error("modelTopology field is missing from file "+g.name))},e.onerror=function(I){return E("Failed to read model topology and weights manifest JSON from file '"+g.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},e.readAsText(g)})]})})},A.prototype.checkManifestAndWeightFiles=function(g,B){for(var Q=[],w=B.map(function(I){return bD(I.name)}),C={},E=0,e=g;E<e.length;E++)e[E].paths.forEach(function(I){var o=bD(I);if(Q.indexOf(o)!==-1)throw new Error("Duplicate file basename found in weights manifest: '"+o+"'");if(Q.push(o),w.indexOf(o)===-1)throw new Error("Weight file with basename '"+o+"' is not provided.");C[I]=B[w.indexOf(o)]});if(Q.length!==B.length)throw new Error("Mismatch in the number of files in weights manifest ("+Q.length+") and the number of weight files provided ("+B.length+").");return C},A}();function _D(A,g,B,Q){(function(C){R(C!=null&&Array.isArray(C)&&C.length>0,function(){return"promises must be a none empty array"})})(A),function(C,E){R(C>=0&&C<=1,function(){return"Progress fraction must be in range [0, 1], but got startFraction "+C}),R(E>=0&&E<=1,function(){return"Progress fraction must be in range [0, 1], but got endFraction "+E}),R(E>=C,function(){return"startFraction must be no more than endFraction, but got startFraction "+C+" and endFraction "+E})}(B=B??0,Q=Q??1);var w=0;return Promise.all(A.map(function(C){return C.then(function(E){var e=B+ ++w/A.length*(Q-B);return g(e),E}),C}))}function $D(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n;return UA(this,function(i){switch(i.label){case 0:return g==null&&(g={}),B=g.fetchFunc==null?BA().platform.fetch:g.fetchFunc,Q=A.map(function(Y){return B(Y,g.requestInit,{isBinary:!0})}),w=0,C=.5,g.onProgress!=null?[3,2]:[4,Promise.all(Q)];case 1:return E=i.sent(),[3,4];case 2:return[4,_D(Q,g.onProgress,w,C)];case 3:E=i.sent(),i.label=4;case 4:return e=E.map(function(Y){return Y.arrayBuffer()}),I=.5,o=1,g.onProgress!=null?[3,6]:[4,Promise.all(e)];case 5:return n=i.sent(),[3,8];case 6:return[4,_D(e,g.onProgress,I,o)];case 7:n=i.sent(),i.label=8;case 8:return[2,n]}})})}function Ar(A){var g=this;return function(B,Q,w){return Q===void 0&&(Q=""),uA(g,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c;return UA(this,function(D){switch(D.label){case 0:if(C=B.map(function(){return!1}),E={},e=w!=null?w.map(function(){return!1}):[],I=[],B.forEach(function(r,F){var s=0;r.weights.forEach(function(u){var a="quantization"in u?u.quantization.dtype:u.dtype,U=St[a]*hA(u.shape),G=function(){C[F]=!0,E[F]==null&&(E[F]=[]),E[F].push({manifestEntry:u,groupOffset:s,sizeBytes:U})};w!=null?w.forEach(function(d,H){d===u.name&&(G(),e[H]=!0)}):G(),I.push(u.name),s+=U})}),!e.every(function(r){return r}))throw o=w.filter(function(r,F){return!e[F]}),new Error("Could not find weights in manifest with names: "+o.join(", ")+`.
3821
+ Manifest JSON has weights with names: `+I.join(", ")+".");return n=C.reduce(function(r,F,s){return F&&r.push(s),r},[]),i=[],n.forEach(function(r){B[r].paths.forEach(function(F){var s=Q+(Q.endsWith("/")?"":"/")+F;i.push(s)})}),[4,A(i)];case 1:return Y=D.sent(),M={},c=0,n.forEach(function(r){for(var F=B[r].paths.length,s=0,u=0;u<F;u++)s+=Y[c+u].byteLength;for(var a=new ArrayBuffer(s),U=new Uint8Array(a),G=0,d=0;d<F;d++){var H=new Uint8Array(Y[c+d]);U.set(H,G),G+=H.byteLength}E[r].forEach(function(h){var l=SD(a.slice(h.groupOffset,h.groupOffset+h.sizeBytes),[h.manifestEntry]);for(var m in l)M[m]=l[m]}),c+=F}),[2,M]}})})}}fg.registerSaveRouter(function(A){return BA().getBool("IS_BROWSER")&&!Array.isArray(A)&&A.startsWith(Vt.URL_SCHEME)?function(g){return g===void 0&&(g="model"),new Vt(g)}(A.slice(Vt.URL_SCHEME.length)):null});var Br=function(){function A(g,B){if(this.DEFAULT_METHOD="POST",B==null&&(B={}),this.weightPathPrefix=B.weightPathPrefix,this.onProgress=B.onProgress,B.fetchFunc!=null?(R(typeof B.fetchFunc=="function",function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=B.fetchFunc):this.fetch=BA().platform.fetch,R(g!=null&&g.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(g)&&R(g.length===2,function(){return"URL paths for http must have a length of 2, (actual length is "+g.length+")."}),this.path=g,B.requestInit!=null&&B.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=B.requestInit||{}}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C;return UA(this,function(E){switch(E.label){case 0:if(g.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(B=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,Q=[{paths:["./model.weights.bin"],weights:g.weightSpecs}],w={modelTopology:g.modelTopology,format:g.format,generatedBy:g.generatedBy,convertedBy:g.convertedBy,userDefinedMetadata:g.userDefinedMetadata,weightsManifest:Q},B.body.append("model.json",new Blob([JSON.stringify(w)],{type:"application/json"}),"model.json"),g.weightData!=null&&B.body.append("model.weights.bin",new Blob([g.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,B)];case 1:if((C=E.sent()).ok)return[2,{modelArtifactsInfo:bC(g),responses:[C]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+C.status+".")}})})},A.prototype.load=function(){return uA(this,void 0,void 0,function(){var g,B,Q,w,C,E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(g=M.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+g.status+". Please verify this URL points to the model JSON of the model to load.");M.label=2;case 2:return M.trys.push([2,4,,5]),[4,g.json()];case 3:return B=M.sent(),[3,5];case 4:throw M.sent(),Q="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?Q+=" 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.":Q+=" Please make sure the server is serving valid JSON for this request.",new Error(Q);case 5:if(w=B.modelTopology,C=B.weightsManifest,E=B.generatedBy,e=B.convertedBy,I=B.format,o=B.userDefinedMetadata,w==null&&C==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return C==null?[3,7]:[4,this.loadWeights(C)];case 6:Y=M.sent(),n=Y[0],i=Y[1],M.label=7;case 7:return[2,{modelTopology:w,weightSpecs:n,weightData:i,userDefinedMetadata:o,generatedBy:E,convertedBy:e,format:I}]}})})},A.prototype.loadWeights=function(g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i,Y;return UA(this,function(M){switch(M.label){case 0:for(B=Array.isArray(this.path)?this.path[1]:this.path,Q=function(c){var D=c.lastIndexOf("/"),r=c.lastIndexOf("?"),F=c.substring(0,D),s=r>D?c.substring(r):"";return[F+"/",s]}(B),w=Q[0],C=Q[1],E=this.weightPathPrefix||w,e=[],I=0,o=g;I<o.length;I++)n=o[I],e.push.apply(e,n.weights);return i=[],g.forEach(function(c){c.paths.forEach(function(D){i.push(E+D+C)})}),[4,$D(i,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 1:return Y=M.sent(),[2,[e,bt(Y)]]}})})},A.URL_SCHEME_REGEX=/^https?:\/\//,A}();function xt(A){return A.match(Br.URL_SCHEME_REGEX)!=null}var gr=function(A,g){return typeof fetch>"u"?null:(Array.isArray(A)?A.every(function(B){return xt(B)}):xt(A))?Xt(A,{onProgress:g}):null};function Xt(A,g){return new Br(A,g)}fg.registerSaveRouter(gr),fg.registerLoadRouter(gr);var Ot=function(){function A(g){this.modelArtifacts=g}return A.prototype.load=function(){return uA(this,void 0,void 0,function(){return UA(this,function(g){return[2,this.modelArtifacts]})})},A}(),q0=function(){function A(g){this.saveHandler=g}return A.prototype.save=function(g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,this.saveHandler(g)]})})},A}(),Qr=Object.freeze({browserFiles:function(A){return new Z0(A)},browserHTTPRequest:function(A,g){return Xt(A,g)},concatenateArrayBuffers:bt,decodeWeights:SD,encodeWeights:function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e=this;return UA(this,function(I){switch(I.label){case 0:for(B=[],Q=[],w=Array.isArray(A)?A.map(function(o){return o.name}):Object.keys(A),C=function(o){var n=w[o],i=Array.isArray(A)?A[o].tensor:A[n];if(i.dtype!=="float32"&&i.dtype!=="int32"&&i.dtype!=="bool"&&i.dtype!=="string")throw new Error("Unsupported dtype in weight '"+n+"': "+i.dtype);var Y={name:n,shape:i.shape,dtype:i.dtype};if(i.dtype==="string"){var M=new Promise(function(c){return uA(e,void 0,void 0,function(){var D,r,F,s,u,a,U;return UA(this,function(G){switch(G.label){case 0:return[4,i.bytes()];case 1:for(D=G.sent(),r=D.reduce(function(d,H){return d+H.length},0)+fe*D.length,F=new Uint8Array(r),s=0,u=0;u<D.length;u++)a=D[u],U=new Uint8Array(new Uint32Array([a.length]).buffer),F.set(U,s),s+=fe,F.set(a,s),s+=a.length;return c(F),[2]}})})});Q.push(M)}else Q.push(i.data());g!=null&&(Y.group=g),B.push(Y)},E=0;E<w.length;++E)C(E);return[4,Promise.all(Q)];case 1:return[2,{data:y0(I.sent()),specs:B}]}})})},fromMemory:function(A,g,B,Q){return arguments.length===1?A.modelTopology!=null||A.weightSpecs!=null?new Ot(A):(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 Ot({modelTopology:A})):(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 Ot({modelTopology:A,weightSpecs:g,weightData:B,trainingConfig:Q}))},getLoadHandlers:function(A,g){return fg.getLoadHandlers(A,g)},getModelArtifactsInfoForJSON:bC,getSaveHandlers:function(A){return fg.getSaveHandlers(A)},http:Xt,isHTTPScheme:xt,loadWeights:function(A,g,B,Q){return g===void 0&&(g=""),uA(this,void 0,void 0,function(){return UA(this,function(w){return[2,Ar(function(C){return $D(C,{requestInit:Q})})(A,g,B)]})})},registerLoadRouter:function(A){return fg.registerLoadRouter(A)},registerSaveRouter:function(A){return fg.registerSaveRouter(A)},weightsLoaderFactory:Ar,withSaveHandler:function(A){return new q0(A)},copyModel:function(A,g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,KD(A,g,!1)]})})},listModels:function(){return uA(this,void 0,void 0,function(){var A,g,B,Q,w,C,E;return UA(this,function(e){switch(e.label){case 0:A=kQ.getSchemes(),g={},B=0,Q=A,e.label=1;case 1:return B<Q.length?(w=Q[B],[4,kQ.getManager(w).listModels()]):[3,4];case 2:for(E in C=e.sent())g[w+Ow+E]=C[E];e.label=3;case 3:return B++,[3,1];case 4:return[2,g]}})})},moveModel:function(A,g){return uA(this,void 0,void 0,function(){return UA(this,function(B){return[2,KD(A,g,!0)]})})},removeModel:function(A){return uA(this,void 0,void 0,function(){var g;return UA(this,function(B){return g=Je(A),[2,kQ.getManager(g.scheme).removeModel(g.path)]})})}}),$w;z({confusionMatrix_:function(A,g,B){var Q=J(A,"labels","confusionMatrix"),w=J(g,"predictions","confusionMatrix");R(B==null||B>0&&Number.isInteger(B),function(){return"If provided, numClasses must be a positive integer, but got "+B}),R(Q.rank===1,function(){return"Expected the rank of labels to be 1, but got "+Q.rank}),R(w.rank===1,function(){return"Expected the rank of predictions to be 1, but got "+w.rank}),R(Q.shape[0]===w.shape[0],function(){return"Mismatch in the number of examples: "+Q.shape[0]+" vs. "+w.shape[0]+". Labels and predictions should have the same number of elements."}),R(B>0&&Number.isInteger(B),function(){return"numClasses is required to be a positive integer, but got "+B});var C=gt(Q.asType("int32"),B),E=gt(w.asType("int32"),B);return C.transpose().matMul(E).asType("int32")}});var _0=z({fromPixels_:function(A,g){if(g===void 0&&(g=3),g>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(A==null)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var B=!1,Q=!1,w=!1,C=!1,E=!1;if(A.data instanceof Uint8Array)B=!0;else if(typeof ImageData<"u"&&A instanceof ImageData)Q=!0;else if(typeof HTMLVideoElement<"u"&&A instanceof HTMLVideoElement)w=!0;else if(typeof HTMLImageElement<"u"&&A instanceof HTMLImageElement)C=!0;else{if(A.getContext==null)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 "+A.constructor.name);E=!0}if(w&&w&&A.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");if(kM("FromPixels",b.backendName)!=null)return b.runKernel("FromPixels",{pixels:A},{numChannels:g});var e,I,o=w?[A.videoWidth,A.videoHeight]:[A.width,A.height],n=o[0],i=o[1];if(E?e=A.getContext("2d").getImageData(0,0,n,i).data:Q||B?e=A.data:(C||w)&&($w==null&&($w=document.createElement("canvas").getContext("2d")),$w.canvas.width=n,$w.canvas.height=i,$w.drawImage(A,0,0,n,i),e=$w.getImageData(0,0,n,i).data),g===4)I=new Int32Array(e);else{var Y=n*i;I=new Int32Array(Y*g);for(var M=0;M<Y;M++)for(var c=0;c<g;++c)I[M*g+c]=e[4*M+c]}return $o(I,[i,n,g],"int32")}}),Zt=Object.freeze({toPixels:function(A,g){return uA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return UA(this,function(h){switch(h.label){case 0:if(B=J(A,"img","toPixels"),A instanceof uB||(B=B.toInt()),B.rank!==2&&B.rank!==3)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+B.rank+".");if(Q=B.shape.slice(0,2),w=Q[0],C=Q[1],(E=B.rank===2?1:B.shape[2])>4||E===2)throw new Error("toPixels only supports depth of size 1, 3 or 4 but got "+E);return[4,B.data()];case 1:return e=h.sent(),I=B.min(),o=B.max(),[4,Promise.all([I.data(),o.data()])];case 2:if(n=h.sent(),i=n[0],Y=n[1],M=i[0],c=Y[0],I.dispose(),o.dispose(),B.dtype==="float32"){if(M<0||c>1)throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range ["+M+" - "+c+"].")}else{if(B.dtype!=="int32")throw new Error("Unsupported type for toPixels: "+B.dtype+". Please use float32 or int32 tensors.");if(M<0||c>255)throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range ["+M+" - "+c+"].")}for(D=B.dtype==="float32"?255:1,r=new Uint8ClampedArray(C*w*4),F=0;F<w*C;++F)s=void 0,u=void 0,a=void 0,U=void 0,E===1?(s=e[F]*D,u=e[F]*D,a=e[F]*D,U=255):E===3?(s=e[3*F]*D,u=e[3*F+1]*D,a=e[3*F+2]*D,U=255):E===4&&(s=e[4*F]*D,u=e[4*F+1]*D,a=e[4*F+2]*D,U=e[4*F+3]*D),r[(G=4*F)+0]=Math.round(s),r[G+1]=Math.round(u),r[G+2]=Math.round(a),r[G+3]=Math.round(U);return g!=null&&(g.width=C,g.height=w,d=g.getContext("2d"),H=new ImageData(r,C,w),d.putImageData(H,0,0)),B!==A&&B.dispose(),[2,r]}})})},fromPixels:_0}),$0=function(){function A(){}return A.prototype.getClassName=function(){return this.constructor.className},A.fromConfig=function(g,B){return new g(B)},A}(),AR=function(){function A(){this.classNameMap={}}return A.getMap=function(){return A.instance==null&&(A.instance=new A),A.instance},A.register=function(g){A.getMap().classNameMap[g.className]=[g,g.fromConfig]},A}();function tw(A){R(A.className!=null,function(){return"Class being registered does not have the static className property defined."}),R(typeof A.className=="string",function(){return"className is required to be a string, but got type "+typeof A.className}),R(A.className.length>0,function(){return"Class being registered has an empty-string as its className, which is disallowed."}),AR.register(A)}var nw=function(A){function g(){return A!==null&&A.apply(this,arguments)||this}return Wg(g,A),g.prototype.minimize=function(B,Q,w){Q===void 0&&(Q=!1);var C=this.computeGradients(B,w),E=C.value,e=C.grads;if(w!=null){var I=w.map(function(o){return{name:o.name,tensor:e[o.name]}});this.applyGradients(I)}else this.applyGradients(e);return Mg(e),Q?E:(E.dispose(),null)},Object.defineProperty(g.prototype,"iterations",{get:function(){return this.iterations_==null&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),g.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},g.prototype.computeGradients=function(B,Q){return of(B,Q)},g.prototype.dispose=function(){this.iterations_!=null&&Mg(this.iterations_)},g.prototype.saveIterations=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){return this.iterations_==null&&(this.iterations_=0),[2,{name:"iter",tensor:nA(this.iterations_,"int32")}]})})},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){throw new Error("getWeights() is not implemented for this optimizer yet.")})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){throw new Error("setWeights() is not implemented for this optimizer class "+this.getClassName())})})},g.prototype.extractIterations=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return Q=this,[4,B[0].tensor.data()];case 1:return Q.iterations_=w.sent()[0],[2,B.slice(1)]}})})},g}($0);Object.defineProperty(nw,Symbol.hasInstance,{value:function(A){return A.minimize!=null&&A.computeGradients!=null&&A.applyGradients!=null}});var BR=function(A){function g(B,Q,w){w===void 0&&(w=null);var C=A.call(this)||this;return C.learningRate=B,C.rho=Q,C.epsilon=w,C.accumulatedGrads=[],C.accumulatedUpdates=[],w==null&&(C.epsilon=b.backend.epsilon()),C}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedGrads[C]==null&&(Q.accumulatedGrads[C]={originalName:w+"/accum_grad",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedUpdates[C]==null&&(Q.accumulatedUpdates[C]={originalName:w+"/accum_var",variable:DA(function(){return $A(E).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedGrads[C].variable,o=Q.accumulatedUpdates[C].variable;DA(function(){var n=I.mul(Q.rho).add(e.square().mul(1-Q.rho)),i=o.add(Q.epsilon).sqrt().div(I.add(Q.epsilon).sqrt()).mul(e),Y=o.mul(Q.rho).add(i.square().mul(1-Q.rho));I.assign(n),o.assign(Y);var M=i.mul(-Q.learningRate).add(E);E.assign(M)})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedUpdates!=null&&(Mg(this.accumulatedGrads.map(function(B){return B.variable})),Mg(this.accumulatedUpdates.map(function(B){return B.variable})))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return[4,this.extractIterations(B)];case 1:return B=w.sent(),Q=B.length/2,this.accumulatedGrads=B.slice(0,Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.accumulatedUpdates=B.slice(Q,2*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.rho,Q.epsilon)},g.className="Adadelta",g}(nw);tw(BR);var gR=function(A){function g(B,Q){Q===void 0&&(Q=.1);var w=A.call(this)||this;return w.learningRate=B,w.initialAccumulatorValue=Q,w.accumulatedGrads=[],w}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedGrads[C]==null&&(Q.accumulatedGrads[C]={originalName:w+"/accumulator",variable:DA(function(){return gQ(E.shape,Q.initialAccumulatorValue).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedGrads[C].variable;DA(function(){var o=I.add(e.square());I.assign(o);var n=e.div(o.add(b.backend.epsilon()).sqrt()).mul(-Q.learningRate).add(E);E.assign(n)})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedGrads!=null&&Mg(this.accumulatedGrads.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()].concat(this.accumulatedGrads.map(function(Q){return{name:Q.originalName,tensor:Q.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:return B=Q.sent(),this.accumulatedGrads=B.map(function(w){return{originalName:w.name,variable:w.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.initialAccumulatorValue)},g.className="Adagrad",g}(nw);tw(gR);var QR=function(A){function g(B,Q,w,C){C===void 0&&(C=null);var E=A.call(this)||this;return E.learningRate=B,E.beta1=Q,E.beta2=w,E.epsilon=C,E.accumulatedFirstMoment=[],E.accumulatedSecondMoment=[],DA(function(){E.accBeta1=nA(Q).variable(),E.accBeta2=nA(w).variable()}),C==null&&(E.epsilon=b.backend.epsilon()),E}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this,w=Array.isArray(B)?B.map(function(C){return C.name}):Object.keys(B);DA(function(){var C=zB(1,Q.accBeta1),E=zB(1,Q.accBeta2);w.forEach(function(e,I){var o=b.registeredVariables[e];Q.accumulatedFirstMoment[I]==null&&(Q.accumulatedFirstMoment[I]={originalName:e+"/m",variable:DA(function(){return $A(o).variable(!1)})}),Q.accumulatedSecondMoment[I]==null&&(Q.accumulatedSecondMoment[I]={originalName:e+"/v",variable:DA(function(){return $A(o).variable(!1)})});var n=Array.isArray(B)?B[I].tensor:B[e];if(n!=null){var i=Q.accumulatedFirstMoment[I].variable,Y=Q.accumulatedSecondMoment[I].variable,M=i.mul(Q.beta1).add(n.mul(1-Q.beta1)),c=Y.mul(Q.beta2).add(n.square().mul(1-Q.beta2)),D=M.div(C),r=c.div(E);i.assign(M),Y.assign(c);var F=D.div(r.sqrt().add(Q.epsilon)).mul(-Q.learningRate).add(o);o.assign(F)}}),Q.accBeta1.assign(Q.accBeta1.mul(Q.beta1)),Q.accBeta2.assign(Q.accBeta2.mul(Q.beta2))}),this.incrementIterations()},g.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&Mg(this.accumulatedFirstMoment.map(function(B){return B.variable})),this.accumulatedSecondMoment!=null&&Mg(this.accumulatedSecondMoment.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q,w=this;return UA(this,function(C){switch(C.label){case 0:return[4,this.extractIterations(B)];case 1:return B=C.sent(),DA(function(){w.accBeta1.assign(Ue(w.beta1,w.iterations_+1)),w.accBeta2.assign(Ue(w.beta2,w.iterations_+1))}),Q=B.length/2,this.accumulatedFirstMoment=B.slice(0,Q).map(function(E){return{originalName:E.name,variable:E.tensor.variable(!1)}}),this.accumulatedSecondMoment=B.slice(Q,2*Q).map(function(E){return{originalName:E.name,variable:E.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.beta1,Q.beta2,Q.epsilon)},g.className="Adam",g}(nw);tw(QR);var wR=function(A){function g(B,Q,w,C,E){C===void 0&&(C=null),E===void 0&&(E=0);var e=A.call(this)||this;return e.learningRate=B,e.beta1=Q,e.beta2=w,e.epsilon=C,e.decay=E,e.accumulatedFirstMoment=[],e.accumulatedWeightedInfNorm=[],DA(function(){e.iteration=nA(0).variable(),e.accBeta1=nA(Q).variable()}),C==null&&(e.epsilon=b.backend.epsilon()),e}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this,w=Array.isArray(B)?B.map(function(C){return C.name}):Object.keys(B);DA(function(){var C=zB(1,Q.accBeta1),E=bg(-Q.learningRate,Q.iteration.mul(Q.decay).add(1));w.forEach(function(e,I){var o=b.registeredVariables[e];Q.accumulatedFirstMoment[I]==null&&(Q.accumulatedFirstMoment[I]={originalName:e+"/m",variable:$A(o).variable(!1)}),Q.accumulatedWeightedInfNorm[I]==null&&(Q.accumulatedWeightedInfNorm[I]={originalName:e+"/v",variable:$A(o).variable(!1)});var n=Array.isArray(B)?B[I].tensor:B[e];if(n!=null){var i=Q.accumulatedFirstMoment[I].variable,Y=Q.accumulatedWeightedInfNorm[I].variable,M=i.mul(Q.beta1).add(n.mul(1-Q.beta1)),c=Y.mul(Q.beta2),D=n.abs(),r=c.maximum(D);i.assign(M),Y.assign(r);var F=E.div(C).mul(M.div(r.add(Q.epsilon))).add(o);o.assign(F)}}),Q.iteration.assign(Q.iteration.add(1)),Q.accBeta1.assign(Q.accBeta1.mul(Q.beta1))}),this.incrementIterations()},g.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&Mg(this.accumulatedFirstMoment.map(function(B){return B.variable})),this.accumulatedWeightedInfNorm!=null&&Mg(this.accumulatedWeightedInfNorm.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){throw new Error("getWeights() is not implemented for Adamax yet.")})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){throw new Error("setWeights() is not implemented for Adamax yet.")})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.beta1,Q.beta2,Q.epsilon,Q.decay)},g.className="Adamax",g}(nw);tw(wR);var wr=function(A){function g(B){var Q=A.call(this)||this;return Q.learningRate=B,Q.setLearningRate(B),Q}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=Array.isArray(B)?B[C].tensor:B[w];if(E!=null){var e=b.registeredVariables[w];DA(function(){var I=Q.c.mul(E).add(e);e.assign(I)})}}),this.incrementIterations()},g.prototype.setLearningRate=function(B){this.learningRate=B,this.c!=null&&this.c.dispose(),this.c=GH(nA(-B))},g.prototype.dispose=function(){this.c.dispose()},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()]]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:if((B=Q.sent()).length!==0)throw new Error("SGD optimizer does not have settable weights.");return[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate}},g.fromConfig=function(B,Q){return new B(Q.learningRate)},g.className="SGD",g}(nw);tw(wr);var CR=function(A){function g(B,Q,w){w===void 0&&(w=!1);var C=A.call(this,B)||this;return C.learningRate=B,C.momentum=Q,C.useNesterov=w,C.accumulations=[],C.m=nA(C.momentum),C}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulations[C]==null&&(Q.accumulations[C]={originalName:w+"/momentum",variable:DA(function(){return $A(E).variable(!1)})});var e=Q.accumulations[C].variable,I=Array.isArray(B)?B[C].tensor:B[w];I!=null&&DA(function(){var o,n=Q.m.mul(e).add(I);o=Q.useNesterov?Q.c.mul(I.add(n.mul(Q.m))).add(E):Q.c.mul(n).add(E),e.assign(n),E.assign(o)})}),this.incrementIterations()},g.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&Mg(this.accumulations.map(function(B){return B.variable}))},g.prototype.setMomentum=function(B){this.momentum=B},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){return UA(this,function(B){switch(B.label){case 0:return[4,this.saveIterations()];case 1:return[2,[B.sent()].concat(this.accumulations.map(function(Q){return{name:Q.originalName,tensor:Q.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){return UA(this,function(Q){switch(Q.label){case 0:return[4,this.extractIterations(B)];case 1:return B=Q.sent(),this.accumulations=B.map(function(w){return{originalName:w.name,variable:w.tensor.variable(!1)}}),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.momentum,Q.useNesterov)},g.className="Momentum",g}(wr);tw(CR);var ER=function(A){function g(B,Q,w,C,E){Q===void 0&&(Q=.9),w===void 0&&(w=0),C===void 0&&(C=null),E===void 0&&(E=!1);var e=A.call(this)||this;if(e.learningRate=B,e.decay=Q,e.momentum=w,e.epsilon=C,e.accumulatedMeanSquares=[],e.accumulatedMoments=[],e.accumulatedMeanGrads=[],e.centered=E,C==null&&(e.epsilon=b.backend.epsilon()),B==null)throw new Error("learningRate for RMSPropOptimizer must be defined.");return e}return Wg(g,A),g.prototype.applyGradients=function(B){var Q=this;(Array.isArray(B)?B.map(function(w){return w.name}):Object.keys(B)).forEach(function(w,C){var E=b.registeredVariables[w];Q.accumulatedMeanSquares[C]==null&&(Q.accumulatedMeanSquares[C]={originalName:w+"/rms",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedMoments[C]==null&&(Q.accumulatedMoments[C]={originalName:w+"/momentum",variable:DA(function(){return $A(E).variable(!1)})}),Q.accumulatedMeanGrads[C]==null&&Q.centered&&(Q.accumulatedMeanGrads[C]={originalName:w+"/mg",variable:DA(function(){return $A(E).variable(!1)})});var e=Array.isArray(B)?B[C].tensor:B[w];if(e!=null){var I=Q.accumulatedMeanSquares[C].variable,o=Q.accumulatedMoments[C].variable;DA(function(){var n=I.mul(Q.decay).add(e.square().mul(1-Q.decay));if(Q.centered){var i=Q.accumulatedMeanGrads[C].variable,Y=i.mul(Q.decay).add(e.mul(1-Q.decay)),M=o.mul(Q.momentum).add(e.mul(Q.learningRate).div(n.sub(Y.square().add(Q.epsilon)).sqrt()));I.assign(n),i.assign(Y),o.assign(M);var c=E.sub(M);E.assign(c)}else{var D=I.mul(Q.decay).add(e.square().mul(1-Q.decay));M=o.mul(Q.momentum).add(e.mul(Q.learningRate).div(D.add(Q.epsilon).sqrt())),I.assign(D),o.assign(M),c=E.sub(M),E.assign(c)}})}}),this.incrementIterations()},g.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&Mg(this.accumulatedMeanSquares.map(function(B){return B.variable})),this.accumulatedMeanGrads!=null&&this.centered&&Mg(this.accumulatedMeanGrads.map(function(B){return B.variable})),this.accumulatedMoments!=null&&Mg(this.accumulatedMoments.map(function(B){return B.variable}))},g.prototype.getWeights=function(){return uA(this,void 0,void 0,function(){var B;return UA(this,function(Q){switch(Q.label){case 0:return B=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&B.push.apply(B,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[Q.sent()].concat(B.map(function(w){return{name:w.originalName,tensor:w.variable}}))]}})})},g.prototype.setWeights=function(B){return uA(this,void 0,void 0,function(){var Q;return UA(this,function(w){switch(w.label){case 0:return[4,this.extractIterations(B)];case 1:return B=w.sent(),Q=this.centered?B.length/3:B.length/2,this.accumulatedMeanSquares=B.slice(0,Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.accumulatedMoments=B.slice(Q,2*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}}),this.centered&&(this.accumulatedMeanGrads=B.slice(2*Q,3*Q).map(function(C){return{originalName:C.name,variable:C.tensor.variable(!1)}})),[2]}})})},g.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},g.fromConfig=function(B,Q){return new B(Q.learningRate,Q.decay,Q.momentum,Q.epsilon,Q.centered)},g.className="RMSProp",g}(nw);tw(ER),typeof requestAnimationFrame<"u"||typeof setImmediate<"u"&&setImmediate,uB.prototype.squaredDifference=function(A){return wD(this,A)},O=R0;function iw(A,g,B){if(B===void 0&&(B=!1),A.beginPath(),g.slice(1).forEach(function(C,E){var e=C.x,I=C.y,o=g[E];A.moveTo(o.x,o.y),A.lineTo(e,I)}),B){var Q=g[g.length-1],w=g[0];if(!Q||!w)return;A.moveTo(Q.x,Q.y),A.lineTo(w.x,w.y)}A.stroke()}/*! *****************************************************************************
3822
3822
  Copyright (c) Microsoft Corporation.
3823
3823
 
3824
3824
  Permission to use, copy, modify, and/or distribute this software for any
@@ -3831,4 +3831,4 @@ Manifest JSON has weights with names: `+I.join(", ")+".");return n=C.reduce(func
3831
3831
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3832
3832
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3833
3833
  PERFORMANCE OF THIS SOFTWARE.
3834
- ***************************************************************************** */var Zt=function(A,g){return Zt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(B,Q){B.__proto__=Q}||function(B,Q){for(var w in Q)Q.hasOwnProperty(w)&&(B[w]=Q[w])},Zt(A,g)};function yA(A,g){Zt(A,g);function B(){this.constructor=A}A.prototype=g===null?Object.create(g):(B.prototype=g.prototype,new B)}var Eg=function(){return Eg=Object.assign||function(g){for(var B,Q=1,w=arguments.length;Q<w;Q++){B=arguments[Q];for(var C in B)Object.prototype.hasOwnProperty.call(B,C)&&(g[C]=B[C])}return g},Eg.apply(this,arguments)};function dA(A,g,B,Q){function w(C){return C instanceof B?C:new B(function(E){E(C)})}return new(B||(B=Promise))(function(C,E){function e(n){try{o(Q.next(n))}catch(i){E(i)}}function I(n){try{o(Q.throw(n))}catch(i){E(i)}}function o(n){n.done?C(n.value):w(n.value).then(e,I)}o((Q=Q.apply(A,[])).next())})}function HA(A,g){var B={label:0,sent:function(){if(C[0]&1)throw C[1];return C[1]},trys:[],ops:[]},Q,w,C,E;return E={next:e(0),throw:e(1),return:e(2)},typeof Symbol=="function"&&(E[Symbol.iterator]=function(){return this}),E;function e(o){return function(n){return I([o,n])}}function I(o){if(Q)throw new TypeError("Generator is already executing.");for(;B;)try{if(Q=1,w&&(C=o[0]&2?w.return:o[0]?w.throw||((C=w.return)&&C.call(w),0):w.next)&&!(C=C.call(w,o[1])).done)return C;switch(w=0,C&&(o=[o[0]&2,C.value]),o[0]){case 0:case 1:C=o;break;case 4:return B.label++,{value:o[1],done:!1};case 5:B.label++,w=o[1],o=[0];continue;case 7:o=B.ops.pop(),B.trys.pop();continue;default:if(C=B.trys,!(C=C.length>0&&C[C.length-1])&&(o[0]===6||o[0]===2)){B=0;continue}if(o[0]===3&&(!C||o[1]>C[0]&&o[1]<C[3])){B.label=o[1];break}if(o[0]===6&&B.label<C[1]){B.label=C[1],C=o;break}if(C&&B.label<C[2]){B.label=C[2],B.ops.push(o);break}C[2]&&B.ops.pop(),B.trys.pop();continue}o=g.call(A,B)}catch(n){o=[6,n],w=0}finally{Q=C=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function KC(){for(var A=0,g=0,B=arguments.length;g<B;g++)A+=arguments[g].length;for(var Q=Array(A),w=0,g=0;g<B;g++)for(var C=arguments[g],E=0,e=C.length;E<e;E++,w++)Q[w]=C[E];return Q}var Yw=function(){function A(g,B){if(!Mw(g)||!Mw(B))throw new Error("Dimensions.constructor - expected width and height to be valid numbers, instead have "+JSON.stringify({width:g,height:B}));this._width=g,this._height=B}return Object.defineProperty(A.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),A.prototype.reverse=function(){return new A(1/this.width,1/this.height)},A}();function Ne(A,g){return A instanceof uB&&A.shape.length===g}function CR(A){return Ne(A,2)}function me(A){return Ne(A,3)}function jQ(A){return Ne(A,4)}function ER(A){return A%1!==0}function Cr(A){return A%2===0}function qt(A,g){g===void 0&&(g=2);var B=Math.pow(10,g);return Math.floor(A*B)/B}function Er(A){return A&&A.width&&A.height}function eR(A,g){var B=A.width,Q=A.height,w=g/Math.max(Q,B);return new Yw(Math.round(B*w),Math.round(Q*w))}function _t(A){return A.reduce(function(g,B){return g.add(B)},new QB(0,0)).div(new QB(A.length,A.length))}function VC(A,g,B){return Array(A).fill(0).map(function(Q,w){return g+w*B})}function Mw(A){return!!A&&A!==1/0&&A!==-1/0&&!isNaN(A)||A===0}function er(A){return Mw(A)&&0<=A&&A<=1}var QB=function(){function A(g,B){this._x=g,this._y=B}return Object.defineProperty(A.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),A.prototype.add=function(g){return new A(this.x+g.x,this.y+g.y)},A.prototype.sub=function(g){return new A(this.x-g.x,this.y-g.y)},A.prototype.mul=function(g){return new A(this.x*g.x,this.y*g.y)},A.prototype.div=function(g){return new A(this.x/g.x,this.y/g.y)},A.prototype.abs=function(){return new A(Math.abs(this.x),Math.abs(this.y))},A.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},A.prototype.floor=function(){return new A(Math.floor(this.x),Math.floor(this.y))},A}(),wQ=function(){function A(g,B){B===void 0&&(B=!0);var Q=g||{},w=[Q.left,Q.top,Q.right,Q.bottom].every(Mw),C=[Q.x,Q.y,Q.width,Q.height].every(Mw);if(!C&&!w)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(Q));var E=C?[Q.x,Q.y,Q.width,Q.height]:[Q.left,Q.top,Q.right-Q.left,Q.bottom-Q.top],e=E[0],I=E[1],o=E[2],n=E[3];A.assertIsValidBox({x:e,y:I,width:o,height:n},"Box.constructor",B),this._x=e,this._y=I,this._width=o,this._height=n}return A.isRect=function(g){return!!g&&[g.x,g.y,g.width,g.height].every(Mw)},A.assertIsValidBox=function(g,B,Q){if(Q===void 0&&(Q=!1),!A.isRect(g))throw new Error(B+" - invalid box: "+JSON.stringify(g)+", expected object with properties x, y, width, height");if(!Q&&(g.width<0||g.height<0))throw new Error(B+" - width ("+g.width+") and height ("+g.height+") must be positive numbers")},Object.defineProperty(A.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"topLeft",{get:function(){return new QB(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"topRight",{get:function(){return new QB(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottomLeft",{get:function(){return new QB(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottomRight",{get:function(){return new QB(this.right,this.bottom)},enumerable:!0,configurable:!0}),A.prototype.round=function(){var g=[this.x,this.y,this.width,this.height].map(function(E){return Math.round(E)}),B=g[0],Q=g[1],w=g[2],C=g[3];return new A({x:B,y:Q,width:w,height:C})},A.prototype.floor=function(){var g=[this.x,this.y,this.width,this.height].map(function(E){return Math.floor(E)}),B=g[0],Q=g[1],w=g[2],C=g[3];return new A({x:B,y:Q,width:w,height:C})},A.prototype.toSquare=function(){var g=this,B=g.x,Q=g.y,w=g.width,C=g.height,E=Math.abs(w-C);return w<C&&(B-=E/2,w+=E),C<w&&(Q-=E/2,C+=E),new A({x:B,y:Q,width:w,height:C})},A.prototype.rescale=function(g){var B=Er(g)?g.width:g,Q=Er(g)?g.height:g;return new A({x:this.x*B,y:this.y*Q,width:this.width*B,height:this.height*Q})},A.prototype.pad=function(g,B){var Q=[this.x-g/2,this.y-B/2,this.width+g,this.height+B],w=Q[0],C=Q[1],E=Q[2],e=Q[3];return new A({x:w,y:C,width:E,height:e})},A.prototype.clipAtImageBorders=function(g,B){var Q=this,w=Q.x,C=Q.y,E=Q.right,e=Q.bottom,I=Math.max(w,0),o=Math.max(C,0),n=E-I,i=e-o,Y=Math.min(n,g-I),M=Math.min(i,B-o);return new A({x:I,y:o,width:Y,height:M}).floor()},A.prototype.shift=function(g,B){var Q=this,w=Q.width,C=Q.height,E=this.x+g,e=this.y+B;return new A({x:E,y:e,width:w,height:C})},A.prototype.padAtBorders=function(g,B){var Q=this.width+1,w=this.height+1,C=1,E=1,e=Q,I=w,o=this.left,n=this.top,i=this.right,Y=this.bottom;return i>B&&(e=-i+B+Q,i=B),Y>g&&(I=-Y+g+w,Y=g),o<1&&(I=2-o,o=1),n<1&&(I=2-n,n=1),{dy:E,edy:I,dx:C,edx:e,y:n,ey:Y,x:o,ex:i,w:Q,h:w}},A.prototype.calibrate=function(g){return new A({left:this.left+g.left*this.width,top:this.top+g.top*this.height,right:this.right+g.right*this.width,bottom:this.bottom+g.bottom*this.height}).toSquare().round()},A}(),Re=function(A){yA(g,A);function g(B,Q,w,C,E){return E===void 0&&(E=!1),A.call(this,{left:B,top:Q,right:w,bottom:C},E)||this}return g}(wQ),Ir=function(){function A(g,B,Q,w,C){this._imageDims=new Yw(C.width,C.height),this._score=g,this._classScore=B,this._className=Q,this._box=new wQ(w).rescale(this._imageDims)}return Object.defineProperty(A.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"relativeBox",{get:function(){return new wQ(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),A.prototype.forSize=function(g,B){return new A(this.score,this.classScore,this.className,this.relativeBox,{width:g,height:B})},A}(),Jg=function(A){yA(g,A);function g(B,Q,w){return A.call(this,B,B,"",Q,w)||this}return g.prototype.forSize=function(B,Q){var w=A.prototype.forSize.call(this,B,Q),C=w.score,E=w.relativeBox,e=w.imageDims;return new g(C,E,e)},g}(Ir);function IR(A,g,B){B===void 0&&(B=!0);var Q=Math.max(0,Math.min(A.right,g.right)-Math.max(A.left,g.left)),w=Math.max(0,Math.min(A.bottom,g.bottom)-Math.max(A.top,g.top)),C=Q*w;return B?C/(A.area+g.area-C):C/Math.min(A.area,g.area)}function oR(A){var g=A.map(function(e){return e.x}),B=A.map(function(e){return e.y}),Q=g.reduce(function(e,I){return I<e?I:e},1/0),w=B.reduce(function(e,I){return I<e?I:e},1/0),C=g.reduce(function(e,I){return e<I?I:e},0),E=B.reduce(function(e,I){return e<I?I:e},0);return new Re(Q,w,C,E)}function xC(A,g,B,Q){Q===void 0&&(Q=!0);for(var w=g.map(function(e,I){return{score:e,boxIndex:I}}).sort(function(e,I){return e.score-I.score}).map(function(e){return e.boxIndex}),C=[],E=function(){var e=w.pop();C.push(e);for(var I=w,o=[],n=0;n<I.length;n++){var i=I[n],Y=A[e],M=A[i];o.push(IR(Y,M,Q))}w=w.filter(function(c,D){return o[D]<=B})};w.length>0;)E();return C}function XC(A,g){return DA(function(){var B=g[0],Q=g[1],w=g[2],C=gQ(KC(A.shape.slice(0,3),[1]),B),E=gQ(KC(A.shape.slice(0,3),[1]),Q),e=gQ(KC(A.shape.slice(0,3),[1]),w),I=jB([C,E,e],3);return zB(A,I)})}function tR(A,g){return g===void 0&&(g=!1),DA(function(){var B=A.shape.slice(1),Q=B[0],w=B[1];if(Q===w)return A;var C=Math.abs(Q-w),E=Math.round(C*(g?.5:1)),e=Q>w?2:1,I=function(M){var c=A.shape.slice();return c[e]=M,gQ(c,0)},o=I(E),n=C-o.shape[e],i=g&&n?I(n):null,Y=[i,A,o].filter(function(M){return!!M}).map(function(M){return M.toFloat()});return jB(Y,e)})}function $t(A){return 1/(1+Math.exp(-A))}var Pe=function(A){yA(g,A);function g(B,Q,w,C,E){return E===void 0&&(E=!1),A.call(this,{x:B,y:Q,width:w,height:C},E)||this}return g}(wQ),nR=.5,iR=.43,YR=.45,AC=function(){function A(g,B,Q){Q===void 0&&(Q=new QB(0,0));var w=B.width,C=B.height;this._imgDims=new Yw(w,C),this._shift=Q,this._positions=g.map(function(E){return E.mul(new QB(w,C)).add(Q)})}return Object.defineProperty(A.prototype,"shift",{get:function(){return new QB(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"relativePositions",{get:function(){var g=this;return this._positions.map(function(B){return B.sub(g._shift).div(new QB(g.imageWidth,g.imageHeight))})},enumerable:!0,configurable:!0}),A.prototype.forSize=function(g,B){return new this.constructor(this.relativePositions,{width:g,height:B})},A.prototype.shiftBy=function(g,B){return new this.constructor(this.relativePositions,this._imgDims,new QB(g,B))},A.prototype.shiftByPoint=function(g){return this.shiftBy(g.x,g.y)},A.prototype.align=function(g,B){if(B===void 0&&(B={}),g){var Q=g instanceof Jg?g.box.floor():new wQ(g);return this.shiftBy(Q.x,Q.y).align(null,B)}var w=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},B),C=w.useDlibAlignment,E=w.minBoxPadding;return C?this.alignDlib():this.alignMinBbox(E)},A.prototype.alignDlib=function(){var g=this.getRefPointsForAlignment(),B=g[0],Q=g[1],w=g[2],C=function(i){return w.sub(i).magnitude()},E=(C(B)+C(Q))/2,e=Math.floor(E/YR),I=_t(g),o=Math.floor(Math.max(0,I.x-nR*e)),n=Math.floor(Math.max(0,I.y-iR*e));return new Pe(o,n,Math.min(e,this.imageWidth+o),Math.min(e,this.imageHeight+n))},A.prototype.alignMinBbox=function(g){var B=oR(this.positions);return B.pad(B.width*g,B.height*g)},A.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},A}(),MR=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.getRefPointsForAlignment=function(){var B=this.positions;return[B[0],B[1],_t([B[3],B[4]])]},g}(AC),or=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.getJawOutline=function(){return this.positions.slice(0,17)},g.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},g.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},g.prototype.getNose=function(){return this.positions.slice(27,36)},g.prototype.getLeftEye=function(){return this.positions.slice(36,42)},g.prototype.getRightEye=function(){return this.positions.slice(42,48)},g.prototype.getMouth=function(){return this.positions.slice(48,68)},g.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(_t)},g}(AC),tr=function(){function A(g,B){this._label=g,this._distance=B}return Object.defineProperty(A.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),A.prototype.toString=function(g){return g===void 0&&(g=!0),""+this.label+(g?" ("+qt(this.distance)+")":"")},A}(),nr=function(A){yA(g,A);function g(B,Q){var w=A.call(this,B)||this;return w._label=Q,w}return g.assertIsValidLabeledBox=function(B,Q){if(wQ.assertIsValidBox(B,Q),!Mw(B.label))throw new Error(Q+" - expected property label ("+B.label+") to be a number")},Object.defineProperty(g.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),g}(wQ),ve=function(){function A(g,B){if(typeof g!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(B)||B.some(function(Q){return!(Q instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=g,this._descriptors=B}return Object.defineProperty(A.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),A.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(g){return Array.from(g)})}},A.fromJSON=function(g){var B=g.descriptors.map(function(Q){return new Float32Array(Q)});return new A(g.label,B)},A}();(function(A){yA(g,A);function g(B,Q,w,C){var E=A.call(this,B,Q)||this;return E._score=w,E._classScore=C,E}return g.assertIsValidPredictedBox=function(B,Q){if(nr.assertIsValidLabeledBox(B,Q),!er(B.score)||!er(B.classScore))throw new Error(Q+" - expected properties score ("+B.score+") and ("+B.classScore+") to be a number between [0, 1]")},Object.defineProperty(g.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),g})(nr);function OC(A){return A.detection instanceof Jg}function ZC(A,g){var B={detection:g};return Object.assign({},A,B)}function ir(){var A=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},g=function(){throw new Error("readFile - filesystem not available for browser environment")};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement("canvas")},createImageElement:function(){return document.createElement("img")},fetch:A,readFile:g}}function Yr(A){var g="";if(!A)try{A=require("fs")}catch(Q){g=Q.toString()}var B=A?function(Q){return new Promise(function(w,C){A.readFile(Q,function(E,e){return E?C(E):w(e)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+g)};return{readFile:B}}function Mr(){var A=global.Canvas||global.HTMLCanvasElement,g=global.Image||global.HTMLImageElement,B=function(){if(A)return new A;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},Q=function(){if(g)return new g;throw new Error("createImageElement - missing Image implementation for nodejs environment")},w=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},C=Yr();return Eg({Canvas:A||function(){function E(){}return E}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function E(){}return E}(),Image:g||function(){function E(){}return E}(),ImageData:global.ImageData||function(){function E(){}return E}(),Video:global.HTMLVideoElement||function(){function E(){}return E}(),createCanvasElement:B,createImageElement:Q,fetch:w},C)}function cr(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function Dr(){return typeof global=="object"&&typeof require=="function"&&typeof module<"u"&&typeof process<"u"&&!!process.version}var WB;function cR(){if(!WB)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return WB}function An(A){WB=A}function Bn(){cr()&&An(ir()),Dr()&&An(Mr())}function DR(A){if(WB||Bn(),!WB)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var g=A.Canvas,B=g===void 0?WB.Canvas:g,Q=A.Image,w=Q===void 0?WB.Image:Q;WB.Canvas=B,WB.Image=w,WB.createCanvasElement=A.createCanvasElement||function(){return new B},WB.createImageElement=A.createImageElement||function(){return new w},WB.ImageData=A.ImageData||WB.ImageData,WB.Video=A.Video||WB.Video,WB.fetch=A.fetch||WB.fetch,WB.readFile=A.readFile||WB.readFile}var eg={getEnv:cR,setEnv:An,initialize:Bn,createBrowserEnv:ir,createFileSystem:Yr,createNodejsEnv:Mr,monkeyPatch:DR,isBrowser:cr,isNodejs:Dr};Bn();function gn(A){return!eg.isNodejs()&&typeof A=="string"?document.getElementById(A):A}function CQ(A){var g=eg.getEnv(),B=g.Canvas,Q=g.CanvasRenderingContext2D;if(A instanceof Q)return A;var w=gn(A);if(!(w instanceof B))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var C=w.getContext("2d");if(!C)throw new Error("resolveContext2d - canvas 2d context is null");return C}var pQ;(function(A){A.TOP_LEFT="TOP_LEFT",A.TOP_RIGHT="TOP_RIGHT",A.BOTTOM_LEFT="BOTTOM_LEFT",A.BOTTOM_RIGHT="BOTTOM_RIGHT"})(pQ||(pQ={}));var rr=function(){function A(g){g===void 0&&(g={});var B=g.anchorPosition,Q=g.backgroundColor,w=g.fontColor,C=g.fontSize,E=g.fontStyle,e=g.padding;this.anchorPosition=B||pQ.TOP_LEFT,this.backgroundColor=Q||"rgba(0, 0, 0, 0.5)",this.fontColor=w||"rgba(255, 255, 255, 1)",this.fontSize=C||14,this.fontStyle=E||"Georgia",this.padding=e||4}return A}(),Fr=function(){function A(g,B,Q){Q===void 0&&(Q={}),this.text=typeof g=="string"?[g]:g instanceof A?g.text:g,this.anchor=B,this.options=new rr(Q)}return A.prototype.measureWidth=function(g){var B=this.options.padding;return this.text.map(function(Q){return g.measureText(Q).width}).reduce(function(Q,w){return Q<w?w:Q},0)+2*B},A.prototype.measureHeight=function(){var g=this.options,B=g.fontSize,Q=g.padding;return this.text.length*B+2*Q},A.prototype.getUpperLeft=function(g,B){var Q=this.options.anchorPosition,w=Q===pQ.BOTTOM_RIGHT||Q===pQ.TOP_RIGHT,C=Q===pQ.BOTTOM_LEFT||Q===pQ.BOTTOM_RIGHT,E=this.measureWidth(g),e=this.measureHeight(),I=w?this.anchor.x-E:this.anchor.x,o=C?this.anchor.y-e:this.anchor.y;if(B){var n=B.width,i=B.height,Y=Math.max(Math.min(I,n-E),0),M=Math.max(Math.min(o,i-e),0);return{x:Y,y:M}}return{x:I,y:o}},A.prototype.draw=function(g){var B=gn(g),Q=CQ(B),w=this.options,C=w.backgroundColor,E=w.fontColor,e=w.fontSize,I=w.fontStyle,o=w.padding;Q.font=e+"px "+I;var n=this.measureWidth(Q),i=this.measureHeight();Q.fillStyle=C;var Y=this.getUpperLeft(Q,B);Q.fillRect(Y.x,Y.y,n,i),Q.fillStyle=E,this.text.forEach(function(M,c){var D=o+Y.x,r=o+Y.y+(c+1)*e;Q.fillText(M,D,r)})},A}(),rR=function(){function A(g){g===void 0&&(g={});var B=g.boxColor,Q=g.lineWidth,w=g.label,C=g.drawLabelOptions;this.boxColor=B||"rgba(0, 0, 255, 1)",this.lineWidth=Q||2,this.label=w;var E={anchorPosition:pQ.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new rr(Object.assign({},E,C))}return A}(),FR=function(){function A(g,B){B===void 0&&(B={}),this.box=new wQ(g),this.options=new rR(B)}return A.prototype.draw=function(g){var B=CQ(g),Q=this.options,w=Q.boxColor,C=Q.lineWidth,E=this.box,e=E.x,I=E.y,o=E.width,n=E.height;B.strokeStyle=w,B.lineWidth=C,B.strokeRect(e,I,o,n);var i=this.options.label;i&&new Fr([i],{x:e-C/2,y:I},this.options.drawLabelOptions).draw(g)},A}();function aR(A,g){var B=Array.isArray(g)?g:[g];B.forEach(function(Q){var w=Q instanceof Jg?Q.score:OC(Q)?Q.detection.score:void 0,C=Q instanceof Jg?Q.box:OC(Q)?Q.detection.box:new wQ(Q),E=w?""+qt(w):void 0;new FR(C,{label:E}).draw(A)})}function ar(A){var g=eg.getEnv(),B=g.Image,Q=g.Video;return A instanceof B&&A.complete||A instanceof Q&&A.readyState>=3}function sR(A){return new Promise(function(g,B){if(A instanceof eg.getEnv().Canvas||ar(A))return g();function Q(C){C.currentTarget&&(C.currentTarget.removeEventListener("load",Q),C.currentTarget.removeEventListener("error",w),g(C))}function w(C){C.currentTarget&&(C.currentTarget.removeEventListener("load",Q),C.currentTarget.removeEventListener("error",w),B(C))}A.addEventListener("load",Q),A.addEventListener("error",w)})}function Qn(A){var g=eg.getEnv(),B=g.Image,Q=g.Video;return A instanceof B?new Yw(A.naturalWidth,A.naturalHeight):A instanceof Q?new Yw(A.videoWidth,A.videoHeight):new Yw(A.width,A.height)}function ke(A){var g=A.width,B=A.height,Q=eg.getEnv().createCanvasElement,w=Q();return w.width=g,w.height=B,w}function Te(A,g){var B=eg.getEnv().ImageData;if(!(A instanceof B)&&!ar(A))throw new Error("createCanvasFromMedia - media has not finished loading yet");var Q=Qn(A),w=Q.width,C=Q.height,E=ke({width:w,height:C});return A instanceof B?CQ(E).putImageData(A,0,0):CQ(E).drawImage(A,0,0,w,C),E}function uR(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e;return HA(this,function(I){switch(I.label){case 0:return B=eg.getEnv().createCanvasElement(),Q=A.shape.slice(jQ(A)?1:0),w=Q[0],C=Q[1],E=Q[2],e=DA(function(){return A.as3D(w,C,E).toInt()}),[4,Ot.toPixels(e,B)];case 1:return I.sent(),e.dispose(),[2,B]}})})}function sr(A){var g=eg.getEnv(),B=g.Image,Q=g.Canvas,w=g.Video;return A instanceof B||A instanceof Q||A instanceof w}function UR(A,g,B){B===void 0&&(B=!1);var Q=eg.getEnv(),w=Q.Image,C=Q.Canvas;if(!(A instanceof w||A instanceof C))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var E=Qn(A),e=g/Math.max(E.height,E.width),I=e*E.width,o=e*E.height,n=ke({width:g,height:g}),i=A instanceof C?A:Te(A),Y=Math.abs(I-o)/2,M=B&&I<o?Y:0,c=B&&o<I?Y:0;return CQ(n).drawImage(i,M,c,I,o),n}var je=function(){function A(g,B){var Q=this;if(B===void 0&&(B=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(g))throw new Error("NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have "+g);this._treatAsBatchInput=B,this._batchSize=g.length,g.forEach(function(w,C){if(me(w)){Q._imageTensors[C]=w,Q._inputDimensions[C]=w.shape;return}if(jQ(w)){var E=w.shape[0];if(E!==1)throw new Error("NetInput - tf.Tensor4D with batchSize "+E+" passed, but not supported in input array");Q._imageTensors[C]=w,Q._inputDimensions[C]=w.shape.slice(1);return}var e=w instanceof eg.getEnv().Canvas?w:Te(w);Q._canvases[C]=e,Q._inputDimensions[C]=[e.height,e.width,3]})}return Object.defineProperty(A.prototype,"imageTensors",{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"canvases",{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"isBatchInput",{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"reshapedInputDimensions",{get:function(){var g=this;return VC(this.batchSize,0,1).map(function(B,Q){return g.getReshapedInputDimensions(Q)})},enumerable:!0,configurable:!0}),A.prototype.getInput=function(g){return this.canvases[g]||this.imageTensors[g]},A.prototype.getInputDimensions=function(g){return this._inputDimensions[g]},A.prototype.getInputHeight=function(g){return this._inputDimensions[g][0]},A.prototype.getInputWidth=function(g){return this._inputDimensions[g][1]},A.prototype.getReshapedInputDimensions=function(g){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var B=this.getInputWidth(g),Q=this.getInputHeight(g);return eR({width:B,height:Q},this.inputSize)},A.prototype.toBatchTensor=function(g,B){var Q=this;return B===void 0&&(B=!0),this._inputSize=g,DA(function(){var w=VC(Q.batchSize,0,1).map(function(E){var e=Q.getInput(E);if(e instanceof uB){var I=jQ(e)?e:e.expandDims();return I=tR(I,B),(I.shape[1]!==g||I.shape[2]!==g)&&(I=mt.resizeBilinear(I,[g,g])),I.as3D(g,g,3)}if(e instanceof eg.getEnv().Canvas)return Ot.fromPixels(UR(e,g,B));throw new Error("toBatchTensor - at batchIdx "+E+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+e)}),C=Hg(w.map(function(E){return E.toFloat()})).as4D(Q.batchSize,g,g,3);return C})},A}();function xB(A){return dA(this,void 0,void 0,function(){var g,B,Q;return HA(this,function(w){switch(w.label){case 0:if(A instanceof je)return[2,A];if(g=Array.isArray(A)?A:[A],!g.length)throw new Error("toNetInput - empty array passed as input");return B=function(C){return Array.isArray(A)?" at input index "+C+":":""},Q=g.map(gn),Q.forEach(function(C,E){if(!sr(C)&&!me(C)&&!jQ(C))throw typeof g[E]=="string"?new Error("toNetInput -"+B(E)+" string passed, but could not resolve HTMLElement for element id "+g[E]):new Error("toNetInput -"+B(E)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(jQ(C)){var e=C.shape[0];if(e!==1)throw new Error("toNetInput -"+B(E)+" tf.Tensor4D with batchSize "+e+" passed, but not supported in input array")}}),[4,Promise.all(Q.map(function(C){return sr(C)&&sR(C)}))];case 1:return w.sent(),[2,new je(Q,Array.isArray(A))]}})})}function pe(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I;return HA(this,function(o){switch(o.label){case 0:return B=eg.getEnv().Canvas,Q=A,A instanceof B?[3,5]:[4,xB(A)];case 1:if(w=o.sent(),w.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return C=w.getInput(0),C instanceof B?(E=C,[3,4]):[3,2];case 2:return[4,uR(C)];case 3:E=o.sent(),o.label=4;case 4:Q=E,o.label=5;case 5:return e=CQ(Q),I=g.map(function(n){return n instanceof Jg?n.forSize(Q.width,Q.height).box.floor():n}).map(function(n){return n.clipAtImageBorders(Q.width,Q.height)}),[2,I.map(function(n){var i=n.x,Y=n.y,M=n.width,c=n.height,D=ke({width:M,height:c});return CQ(D).putImageData(e.getImageData(i,Y,M,c),0,0),D})]}})})}function wn(A,g){return dA(this,void 0,void 0,function(){return HA(this,function(B){if(!me(A)&&!jQ(A))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(jQ(A)&&A.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,DA(function(){var Q=A.shape.slice(jQ(A)?1:0),w=Q[0],C=Q[1],E=Q[2],e=g.map(function(o){return o instanceof Jg?o.forSize(C,w).box:o}).map(function(o){return o.clipAtImageBorders(C,w)}),I=e.map(function(o){var n=o.x,i=o.y,Y=o.width,M=o.height;return HD(A.as3D(w,C,E),[i,n,0],[M,Y,E])});return I})]})})}function GR(A,g){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return B=eg.getEnv().fetch,[4,B(A,g)];case 1:if(Q=w.sent(),!(Q.status<400))throw new Error("failed to fetch: ("+Q.status+") "+Q.statusText+", from url: "+Q.url);return[2,Q]}})})}function hR(A){return dA(this,void 0,void 0,function(){return HA(this,function(g){switch(g.label){case 0:return[4,GR(A)];case 1:return[2,g.sent().json()]}})})}function ur(A,g){var B=g+"-weights_manifest.json";if(!A)return{modelBaseUri:"",manifestUri:B};if(A==="/")return{modelBaseUri:"/",manifestUri:"/"+B};var Q=A.startsWith("http://")?"http://":A.startsWith("https://")?"https://":"";A=A.replace(Q,"");var w=A.split("/").filter(function(e){return e}),C=A.endsWith(".json")?w[w.length-1]:B,E=Q+(A.endsWith(".json")?w.slice(0,w.length-1):w).join("/");return E=A.startsWith("/")?"/"+E:E,{modelBaseUri:E,manifestUri:E==="/"?"/"+C:E+"/"+C}}function lR(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C;return HA(this,function(E){switch(E.label){case 0:return B=ur(A,g),Q=B.manifestUri,w=B.modelBaseUri,[4,hR(Q)];case 1:return C=E.sent(),[2,Qr.loadWeights(C,w)]}})})}function dR(A,g,B){B===void 0&&(B=!1);var Q=B?Qn(g):g,w=Q.width,C=Q.height;return A.width=w,A.height=C,{width:w,height:C}}var uQ=function(){function A(g){this._name=g,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(A.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),A.prototype.getParamFromPath=function(g){var B=this.traversePropertyPath(g),Q=B.obj,w=B.objProp;return Q[w]},A.prototype.reassignParamFromPath=function(g,B){var Q=this.traversePropertyPath(g),w=Q.obj,C=Q.objProp;w[C].dispose(),w[C]=B},A.prototype.getParamList=function(){var g=this;return this._paramMappings.map(function(B){var Q=B.paramPath;return{path:Q,tensor:g.getParamFromPath(Q)}})},A.prototype.getTrainableParams=function(){return this.getParamList().filter(function(g){return g.tensor instanceof pw})},A.prototype.getFrozenParams=function(){return this.getParamList().filter(function(g){return!(g.tensor instanceof pw)})},A.prototype.variable=function(){var g=this;this.getFrozenParams().forEach(function(B){var Q=B.path,w=B.tensor;g.reassignParamFromPath(Q,w.variable())})},A.prototype.freeze=function(){var g=this;this.getTrainableParams().forEach(function(B){var Q=B.path,w=B.tensor,C=Ag(w.dataSync());w.dispose(),g.reassignParamFromPath(Q,C)})},A.prototype.dispose=function(g){g===void 0&&(g=!0),this.getParamList().forEach(function(B){if(g&&B.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+B.path);B.tensor.dispose()}),this._params=void 0},A.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(g){var B=g.tensor;return Array.from(B.dataSync())}).reduce(function(g,B){return g.concat(B)}))},A.prototype.load=function(g){return dA(this,void 0,void 0,function(){return HA(this,function(B){switch(B.label){case 0:return g instanceof Float32Array?(this.extractWeights(g),[2]):[4,this.loadFromUri(g)];case 1:return B.sent(),[2]}})})},A.prototype.loadFromUri=function(g){return dA(this,void 0,void 0,function(){var B;return HA(this,function(Q){switch(Q.label){case 0:if(g&&typeof g!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,lR(g,this.getDefaultModelName())];case 1:return B=Q.sent(),this.loadFromWeightMap(B),[2]}})})},A.prototype.loadFromDisk=function(g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i;return HA(this,function(Y){switch(Y.label){case 0:if(g&&typeof g!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return B=eg.getEnv().readFile,Q=ur(g,this.getDefaultModelName()),w=Q.manifestUri,C=Q.modelBaseUri,E=function(M){return Promise.all(M.map(function(c){return B(c).then(function(D){return D.buffer})}))},e=Qr.weightsLoaderFactory(E),n=(o=JSON).parse,[4,B(w)];case 1:return I=n.apply(o,[Y.sent().toString()]),[4,e(I,C)];case 2:return i=Y.sent(),this.loadFromWeightMap(i),[2]}})})},A.prototype.loadFromWeightMap=function(g){var B=this.extractParamsFromWeigthMap(g),Q=B.paramMappings,w=B.params;this._paramMappings=Q,this._params=w},A.prototype.extractWeights=function(g){var B=this.extractParams(g),Q=B.paramMappings,w=B.params;this._paramMappings=Q,this._params=w},A.prototype.traversePropertyPath=function(g){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var B=g.split("/").reduce(function(C,E){if(!C.nextObj.hasOwnProperty(E))throw new Error("traversePropertyPath - object does not have property "+E+", for path "+g);return{obj:C.nextObj,objProp:E,nextObj:C.nextObj[E]}},{nextObj:this.params}),Q=B.obj,w=B.objProp;if(!Q||!w||!(Q[w]instanceof uB))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+g);return{obj:Q,objProp:w}},A}();function Ng(A,g,B){return DA(function(){var Q=dt(A,g.depthwise_filter,g.pointwise_filter,B,"same");return Q=OA(Q,g.bias),Q})}function Cn(A,g,B){return B===void 0&&(B=!1),DA(function(){var Q=GB(B?OA(jg(A,g.conv0.filters,[2,2],"same"),g.conv0.bias):Ng(A,g.conv0,[2,2])),w=Ng(Q,g.conv1,[1,1]),C=GB(OA(Q,w)),E=Ng(C,g.conv2,[1,1]);return GB(OA(Q,OA(w,E)))})}function ye(A,g,B,Q){return B===void 0&&(B=!1),Q===void 0&&(Q=!0),DA(function(){var w=GB(B?OA(jg(A,g.conv0.filters,Q?[2,2]:[1,1],"same"),g.conv0.bias):Ng(A,g.conv0,Q?[2,2]:[1,1])),C=Ng(w,g.conv1,[1,1]),E=GB(OA(w,C)),e=Ng(E,g.conv2,[1,1]),I=GB(OA(w,OA(C,e))),o=Ng(I,g.conv3,[1,1]);return GB(OA(w,OA(C,OA(e,o))))})}function Kg(A,g,B,Q){return B===void 0&&(B="same"),Q===void 0&&(Q=!1),DA(function(){var w=OA(jg(A,g.filters,[1,1],B),g.bias);return Q?GB(w):w})}function UQ(A,g){Object.keys(A).forEach(function(B){g.some(function(Q){return Q.originalPath===B})||A[B].dispose()})}function ze(A,g){return function(B,Q,w,C){var E=Dg(A(B*Q*w*w),[w,w,B,Q]),e=PB(A(Q));return g.push({paramPath:C+"/filters"},{paramPath:C+"/bias"}),{filters:E,bias:e}}}function En(A,g){return function(B,Q,w){var C=RQ(A(B*Q),[B,Q]),E=PB(A(Q));return g.push({paramPath:w+"/weights"},{paramPath:w+"/bias"}),{weights:C,bias:E}}}var Ur=function(){function A(g,B,Q){this.depthwise_filter=g,this.pointwise_filter=B,this.bias=Q}return A}();function en(A,g){return function(B,Q,w){var C=Dg(A(9*B),[3,3,B,1]),E=Dg(A(B*Q),[1,1,B,Q]),e=PB(A(Q));return g.push({paramPath:w+"/depthwise_filter"},{paramPath:w+"/pointwise_filter"},{paramPath:w+"/bias"}),new Ur(C,E,e)}}function In(A){return function(g){var B=A(g+"/depthwise_filter",4),Q=A(g+"/pointwise_filter",4),w=A(g+"/bias",1);return new Ur(B,Q,w)}}function yQ(A,g){return function(B,Q,w){var C=A[B];if(!Ne(C,Q))throw new Error("expected weightMap["+B+"] to be a Tensor"+Q+"D, instead have "+C);return g.push({originalPath:B,paramPath:w||B}),C}}function GQ(A){var g=A;function B(w){var C=g.slice(0,w);return g=g.slice(w),C}function Q(){return g}return{extractWeights:B,getRemainingWeights:Q}}function Gr(A,g){var B=ze(A,g),Q=en(A,g);function w(E,e,I,o){o===void 0&&(o=!1);var n=o?B(E,e,3,I+"/conv0"):Q(E,e,I+"/conv0"),i=Q(e,e,I+"/conv1"),Y=Q(e,e,I+"/conv2");return{conv0:n,conv1:i,conv2:Y}}function C(E,e,I,o){o===void 0&&(o=!1);var n=w(E,e,I,o),i=n.conv0,Y=n.conv1,M=n.conv2,c=Q(e,e,I+"/conv3");return{conv0:i,conv1:Y,conv2:M,conv3:c}}return{extractDenseBlock3Params:w,extractDenseBlock4Params:C}}function HR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=Gr(Q,g).extractDenseBlock4Params,E=C(3,32,"dense0",!0),e=C(32,64,"dense1"),I=C(64,128,"dense2"),o=C(128,256,"dense3");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{dense0:E,dense1:e,dense2:I,dense3:o}}}function hr(A){return function(g){var B=A(g+"/filters",4),Q=A(g+"/bias",1);return{filters:B,bias:Q}}}function lr(A,g){var B=yQ(A,g),Q=hr(B),w=In(B);function C(e,I){I===void 0&&(I=!1);var o=I?Q(e+"/conv0"):w(e+"/conv0"),n=w(e+"/conv1"),i=w(e+"/conv2");return{conv0:o,conv1:n,conv2:i}}function E(e,I){I===void 0&&(I=!1);var o=I?Q(e+"/conv0"):w(e+"/conv0"),n=w(e+"/conv1"),i=w(e+"/conv2"),Y=w(e+"/conv3");return{conv0:o,conv1:n,conv2:i,conv3:Y}}return{extractDenseBlock3Params:C,extractDenseBlock4Params:E}}function fR(A){var g=[],B=lr(A,g).extractDenseBlock4Params,Q={dense0:B("dense0",!0),dense1:B("dense1"),dense2:B("dense2"),dense3:B("dense3")};return UQ(A,g),{params:Q,paramMappings:g}}var dr=function(A){yA(g,A);function g(){return A.call(this,"FaceFeatureExtractor")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("FaceFeatureExtractor - load model before inference");return DA(function(){var w=B.toBatchTensor(112,!0),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(255)),e=ye(E,Q.dense0,!0);return e=ye(e,Q.dense1),e=ye(e,Q.dense2),e=ye(e,Q.dense3),e=LC(e,[7,7],[2,2],"valid"),e})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},g.prototype.extractParamsFromWeigthMap=function(B){return fR(B)},g.prototype.extractParams=function(B){return HR(B)},g}(uQ);function EQ(A,g){return DA(function(){return OA(he(A,g.weights),g.bias)})}function JR(A,g,B){var Q=[],w=GQ(A),C=w.extractWeights,E=w.getRemainingWeights,e=En(C,Q),I=e(g,B,"fc");if(E().length!==0)throw new Error("weights remaing after extract: "+E().length);return{paramMappings:Q,params:{fc:I}}}function NR(A){var g=[],B=yQ(A,g);function Q(C){var E=B(C+"/weights",2),e=B(C+"/bias",1);return{weights:E,bias:e}}var w={fc:Q("fc")};return UQ(A,g),{params:w,paramMappings:g}}function Hr(A){var g={},B={};return Object.keys(A).forEach(function(Q){var w=Q.startsWith("fc")?B:g;w[Q]=A[Q]}),{featureExtractorMap:g,classifierMap:B}}var fr=function(A){yA(g,A);function g(B,Q){var w=A.call(this,B)||this;return w._faceFeatureExtractor=Q,w}return Object.defineProperty(g.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),g.prototype.runNet=function(B){var Q=this,w=this.params;if(!w)throw new Error(this._name+" - load model before inference");return DA(function(){var C=B instanceof je?Q.faceFeatureExtractor.forwardInput(B):B;return EQ(C.as2D(C.shape[0],-1),w.fc)})},g.prototype.dispose=function(B){B===void 0&&(B=!0),this.faceFeatureExtractor.dispose(B),A.prototype.dispose.call(this,B)},g.prototype.loadClassifierParams=function(B){var Q=this.extractClassifierParams(B),w=Q.params,C=Q.paramMappings;this._params=w,this._paramMappings=C},g.prototype.extractClassifierParams=function(B){return JR(B,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},g.prototype.extractParamsFromWeigthMap=function(B){var Q=Hr(B),w=Q.featureExtractorMap,C=Q.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(w),NR(C)},g.prototype.extractParams=function(B){var Q=this.getClassifierChannelsIn(),w=this.getClassifierChannelsOut(),C=w*Q+w,E=B.slice(0,B.length-C),e=B.slice(B.length-C);return this.faceFeatureExtractor.extractWeights(E),this.extractClassifierParams(e)},g}(uQ),Jr=["neutral","happy","sad","angry","fearful","disgusted","surprised"],on=function(){function A(g){var B=this;if(g.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+g.length);Jr.forEach(function(Q,w){B[Q]=g[w]})}return A.prototype.asSortedArray=function(){var g=this;return Jr.map(function(B){return{expression:B,probability:g[B]}}).sort(function(B,Q){return Q.probability-B.probability})},A}(),mR=function(A){yA(g,A);function g(B){return B===void 0&&(B=new dr),A.call(this,"FaceExpressionNet",B)||this}return g.prototype.forwardInput=function(B){var Q=this;return DA(function(){return rQ(Q.runNet(B))})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.predictExpressions=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E,e=this;return HA(this,function(I){switch(I.label){case 0:return[4,xB(B)];case 1:return Q=I.sent(),[4,this.forwardInput(Q)];case 2:return w=I.sent(),[4,Promise.all(pB(w).map(function(o){return dA(e,void 0,void 0,function(){var n;return HA(this,function(i){switch(i.label){case 0:return[4,o.data()];case 1:return n=i.sent(),o.dispose(),[2,n]}})})}))];case 3:return C=I.sent(),w.dispose(),E=C.map(function(o){return new on(o)}),[2,Q.isBatchInput?E:E[0]]}})})},g.prototype.getDefaultModelName=function(){return"face_expression_model"},g.prototype.getClassifierChannelsIn=function(){return 256},g.prototype.getClassifierChannelsOut=function(){return 7},g}(fr);function RR(A){return A.expressions instanceof on}function Nr(A,g){var B={expressions:g};return Object.assign({},A,B)}function PR(A,g,B,Q){B===void 0&&(B=.1);var w=Array.isArray(g)?g:[g];w.forEach(function(C){var E=C instanceof on?C:RR(C)?C.expressions:void 0;if(!E)throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");var e=E.asSortedArray(),I=e.filter(function(i){return i.probability>B}),o=OC(C)?C.detection.box.bottomLeft:new QB(0,0),n=new Fr(I.map(function(i){return i.expression+" ("+qt(i.probability)+")"}),o);n.draw(A)})}function tn(A){return OC(A)&&A.landmarks instanceof AC&&A.unshiftedLandmarks instanceof AC&&A.alignedRect instanceof Jg}function We(A,g){var B=A.detection.box,Q=g.shiftBy(B.x,B.y),w=Q.align(),C=A.detection.imageDims,E=new Jg(A.detection.score,w.rescale(C.reverse()),C),e={landmarks:Q,unshiftedLandmarks:g,alignedRect:E};return Object.assign({},A,e)}var vR=function(){function A(g){g===void 0&&(g={});var B=g.drawLines,Q=B===void 0?!0:B,w=g.drawPoints,C=w===void 0?!0:w,E=g.lineWidth,e=g.lineColor,I=g.pointSize,o=g.pointColor;this.drawLines=Q,this.drawPoints=C,this.lineWidth=E||1,this.pointSize=I||2,this.lineColor=e||"rgba(0, 255, 255, 1)",this.pointColor=o||"rgba(255, 0, 255, 1)"}return A}(),kR=function(){function A(g,B){B===void 0&&(B={}),this.faceLandmarks=g,this.options=new vR(B)}return A.prototype.draw=function(g){var B=CQ(g),Q=this.options,w=Q.drawLines,C=Q.drawPoints,E=Q.lineWidth,e=Q.lineColor,I=Q.pointSize,o=Q.pointColor;if(w&&this.faceLandmarks instanceof or&&(B.strokeStyle=e,B.lineWidth=E,iw(B,this.faceLandmarks.getJawOutline()),iw(B,this.faceLandmarks.getLeftEyeBrow()),iw(B,this.faceLandmarks.getRightEyeBrow()),iw(B,this.faceLandmarks.getNose()),iw(B,this.faceLandmarks.getLeftEye(),!0),iw(B,this.faceLandmarks.getRightEye(),!0),iw(B,this.faceLandmarks.getMouth(),!0)),C){B.strokeStyle=o,B.fillStyle=o;var n=function(i){B.beginPath(),B.arc(i.x,i.y,I,0,2*Math.PI),B.fill()};this.faceLandmarks.positions.forEach(n)}},A}();function TR(A,g){var B=Array.isArray(g)?g:[g];B.forEach(function(Q){var w=Q instanceof AC?Q:tn(Q)?Q.landmarks:void 0;if(!w)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks<WithFaceDetection<{}>> or array thereof");new kR(w).draw(A)})}function jR(A,g){var B=ze(A,g),Q=en(A,g);function w(E,e,I){var o=Q(E,e,I+"/separable_conv0"),n=Q(e,e,I+"/separable_conv1"),i=B(E,e,1,I+"/expansion_conv");return{separable_conv0:o,separable_conv1:n,expansion_conv:i}}function C(E,e){var I=Q(E,E,e+"/separable_conv0"),o=Q(E,E,e+"/separable_conv1"),n=Q(E,E,e+"/separable_conv2");return{separable_conv0:I,separable_conv1:o,separable_conv2:n}}return{extractConvParams:B,extractSeparableConvParams:Q,extractReductionBlockParams:w,extractMainBlockParams:C}}function pR(A,g){var B=[],Q=GQ(A),w=Q.extractWeights,C=Q.getRemainingWeights,E=jR(w,B),e=E.extractConvParams,I=E.extractSeparableConvParams,o=E.extractReductionBlockParams,n=E.extractMainBlockParams,i=e(3,32,3,"entry_flow/conv_in"),Y=o(32,64,"entry_flow/reduction_block_0"),M=o(64,128,"entry_flow/reduction_block_1"),c={conv_in:i,reduction_block_0:Y,reduction_block_1:M},D={};VC(g,0,1).forEach(function(u){D["main_block_"+u]=n(128,"middle_flow/main_block_"+u)});var r=o(128,256,"exit_flow/reduction_block"),F=I(256,512,"exit_flow/separable_conv"),s={reduction_block:r,separable_conv:F};if(C().length!==0)throw new Error("weights remaing after extract: "+C().length);return{paramMappings:B,params:{entry_flow:c,middle_flow:D,exit_flow:s}}}function yR(A,g){var B=yQ(A,g),Q=hr(B),w=In(B);function C(e){var I=w(e+"/separable_conv0"),o=w(e+"/separable_conv1"),n=Q(e+"/expansion_conv");return{separable_conv0:I,separable_conv1:o,expansion_conv:n}}function E(e){var I=w(e+"/separable_conv0"),o=w(e+"/separable_conv1"),n=w(e+"/separable_conv2");return{separable_conv0:I,separable_conv1:o,separable_conv2:n}}return{extractConvParams:Q,extractSeparableConvParams:w,extractReductionBlockParams:C,extractMainBlockParams:E}}function zR(A,g){var B=[],Q=yR(A,B),w=Q.extractConvParams,C=Q.extractSeparableConvParams,E=Q.extractReductionBlockParams,e=Q.extractMainBlockParams,I=w("entry_flow/conv_in"),o=E("entry_flow/reduction_block_0"),n=E("entry_flow/reduction_block_1"),i={conv_in:I,reduction_block_0:o,reduction_block_1:n},Y={};VC(g,0,1).forEach(function(r){Y["main_block_"+r]=e("middle_flow/main_block_"+r)});var M=E("exit_flow/reduction_block"),c=C("exit_flow/separable_conv"),D={reduction_block:M,separable_conv:c};return UQ(A,B),{params:{entry_flow:i,middle_flow:Y,exit_flow:D},paramMappings:B}}function mr(A,g,B){return OA(jg(A,g.filters,B,"same"),g.bias)}function nn(A,g,B){B===void 0&&(B=!0);var Q=B?GB(A):A;return Q=Ng(Q,g.separable_conv0,[1,1]),Q=Ng(GB(Q),g.separable_conv1,[1,1]),Q=VB(Q,[3,3],[2,2],"same"),Q=OA(Q,mr(A,g.expansion_conv,[2,2])),Q}function WR(A,g){var B=Ng(GB(A),g.separable_conv0,[1,1]);return B=Ng(GB(B),g.separable_conv1,[1,1]),B=Ng(GB(B),g.separable_conv2,[1,1]),B=OA(B,A),B}var SR=function(A){yA(g,A);function g(B){var Q=A.call(this,"TinyXception")||this;return Q._numMainBlocks=B,Q}return g.prototype.forwardInput=function(B){var Q=this,w=this.params;if(!w)throw new Error("TinyXception - load model before inference");return DA(function(){var C=B.toBatchTensor(112,!0),E=[122.782,117.001,104.298],e=XC(C,E).div(nA(256)),I=GB(mr(e,w.entry_flow.conv_in,[2,2]));return I=nn(I,w.entry_flow.reduction_block_0,!1),I=nn(I,w.entry_flow.reduction_block_1),VC(Q._numMainBlocks,0,1).forEach(function(o){I=WR(I,w.middle_flow["main_block_"+o])}),I=nn(I,w.exit_flow.reduction_block),I=GB(Ng(I,w.exit_flow.separable_conv,[1,1])),I})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"tiny_xception_model"},g.prototype.extractParamsFromWeigthMap=function(B){return zR(B,this._numMainBlocks)},g.prototype.extractParams=function(B){return pR(B,this._numMainBlocks)},g}(uQ);function LR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=En(Q,g),E=C(512,1,"fc/age"),e=C(512,2,"fc/gender");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{fc:{age:E,gender:e}}}}function bR(A){var g=[],B=yQ(A,g);function Q(C){var E=B(C+"/weights",2),e=B(C+"/bias",1);return{weights:E,bias:e}}var w={fc:{age:Q("fc/age"),gender:Q("fc/gender")}};return UQ(A,g),{params:w,paramMappings:g}}var Se;(function(A){A.FEMALE="female",A.MALE="male"})(Se||(Se={}));var KR=function(A){yA(g,A);function g(B){B===void 0&&(B=new SR(2));var Q=A.call(this,"AgeGenderNet")||this;return Q._faceFeatureExtractor=B,Q}return Object.defineProperty(g.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),g.prototype.runNet=function(B){var Q=this,w=this.params;if(!w)throw new Error(this._name+" - load model before inference");return DA(function(){var C=B instanceof je?Q.faceFeatureExtractor.forwardInput(B):B,E=LC(C,[7,7],[2,2],"valid").as2D(C.shape[0],-1),e=EQ(E,w.fc.age).as1D(),I=EQ(E,w.fc.gender);return{age:e,gender:I}})},g.prototype.forwardInput=function(B){var Q=this;return DA(function(){var w=Q.runNet(B),C=w.age,E=w.gender;return{age:C,gender:rQ(E)}})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.predictAgeAndGender=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o=this;return HA(this,function(n){switch(n.label){case 0:return[4,xB(B)];case 1:return Q=n.sent(),[4,this.forwardInput(Q)];case 2:return w=n.sent(),C=pB(w.age),E=pB(w.gender),e=C.map(function(i,Y){return{ageTensor:i,genderTensor:E[Y]}}),[4,Promise.all(e.map(function(i){var Y=i.ageTensor,M=i.genderTensor;return dA(o,void 0,void 0,function(){var c,D,r,F,s;return HA(this,function(u){switch(u.label){case 0:return[4,Y.data()];case 1:return c=u.sent()[0],[4,M.data()];case 2:return D=u.sent()[0],r=D>.5,F=r?Se.MALE:Se.FEMALE,s=r?D:1-D,Y.dispose(),M.dispose(),[2,{age:c,gender:F,genderProbability:s}]}})})}))];case 3:return I=n.sent(),w.age.dispose(),w.gender.dispose(),[2,Q.isBatchInput?I:I[0]]}})})},g.prototype.getDefaultModelName=function(){return"age_gender_model"},g.prototype.dispose=function(B){B===void 0&&(B=!0),this.faceFeatureExtractor.dispose(B),A.prototype.dispose.call(this,B)},g.prototype.loadClassifierParams=function(B){var Q=this.extractClassifierParams(B),w=Q.params,C=Q.paramMappings;this._params=w,this._paramMappings=C},g.prototype.extractClassifierParams=function(B){return LR(B)},g.prototype.extractParamsFromWeigthMap=function(B){var Q=Hr(B),w=Q.featureExtractorMap,C=Q.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(w),bR(C)},g.prototype.extractParams=function(B){var Q=1539,w=B.slice(0,B.length-Q),C=B.slice(B.length-Q);return this.faceFeatureExtractor.extractWeights(w),this.extractClassifierParams(C)},g}(uQ),Rr=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.postProcess=function(B,Q,w){var C=w.map(function(e){var I=e.width,o=e.height,n=Q/Math.max(o,I);return{width:I*n,height:o*n}}),E=C.length;return DA(function(){var e=function(Y,M){return Hg([gQ([68],Y),gQ([68],M)],1).as2D(1,136).as1D()},I=function(Y,M){var c=C[Y],D=c.width,r=c.height;return M(D,r)?Math.abs(D-r)/2:0},o=function(Y){return I(Y,function(M,c){return M<c})},n=function(Y){return I(Y,function(M,c){return c<M})},i=B.mul(gQ([E,136],Q)).sub(Hg(Array.from(Array(E),function(Y,M){return e(o(M),n(M))}))).div(Hg(Array.from(Array(E),function(Y,M){return e(C[M].width,C[M].height)})));return i})},g.prototype.forwardInput=function(B){var Q=this;return DA(function(){var w=Q.runNet(B);return Q.postProcess(w,B.inputSize,B.inputDimensions.map(function(C){var E=C[0],e=C[1];return{height:E,width:e}}))})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.detectLandmarks=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E=this;return HA(this,function(e){switch(e.label){case 0:return[4,xB(B)];case 1:return Q=e.sent(),w=DA(function(){return pB(E.forwardInput(Q))}),[4,Promise.all(w.map(function(I,o){return dA(E,void 0,void 0,function(){var n,i,Y,M,c;return HA(this,function(D){switch(D.label){case 0:return Y=(i=Array).from,[4,I.data()];case 1:return n=Y.apply(i,[D.sent()]),M=n.filter(function(r,F){return Cr(F)}),c=n.filter(function(r,F){return!Cr(F)}),[2,new or(Array(68).fill(0).map(function(r,F){return new QB(M[F],c[F])}),{height:Q.getInputHeight(o),width:Q.getInputWidth(o)})]}})})}))];case 2:return C=e.sent(),w.forEach(function(I){return I.dispose()}),[2,Q.isBatchInput?C:C[0]]}})})},g.prototype.getClassifierChannelsOut=function(){return 136},g}(fr),Pr=function(A){yA(g,A);function g(B){return B===void 0&&(B=new dr),A.call(this,"FaceLandmark68Net",B)||this}return g.prototype.getDefaultModelName=function(){return"face_landmark_68_model"},g.prototype.getClassifierChannelsIn=function(){return 256},g}(Rr);function VR(A){var g=[],B=lr(A,g).extractDenseBlock3Params,Q={dense0:B("dense0",!0),dense1:B("dense1"),dense2:B("dense2")};return UQ(A,g),{params:Q,paramMappings:g}}function xR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=Gr(Q,g).extractDenseBlock3Params,E=C(3,32,"dense0",!0),e=C(32,64,"dense1"),I=C(64,128,"dense2");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{dense0:E,dense1:e,dense2:I}}}var XR=function(A){yA(g,A);function g(){return A.call(this,"TinyFaceFeatureExtractor")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("TinyFaceFeatureExtractor - load model before inference");return DA(function(){var w=B.toBatchTensor(112,!0),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(255)),e=Cn(E,Q.dense0,!0);return e=Cn(e,Q.dense1),e=Cn(e,Q.dense2),e=LC(e,[14,14],[2,2],"valid"),e})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"face_feature_extractor_tiny_model"},g.prototype.extractParamsFromWeigthMap=function(B){return VR(B)},g.prototype.extractParams=function(B){return xR(B)},g}(uQ),OR=function(A){yA(g,A);function g(B){return B===void 0&&(B=new XR),A.call(this,"FaceLandmark68TinyNet",B)||this}return g.prototype.getDefaultModelName=function(){return"face_landmark_68_tiny_model"},g.prototype.getClassifierChannelsIn=function(){return 128},g}(Rr);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g})(Pr);function ZR(A,g){return OA(wg(A,g.weights),g.biases)}function Yn(A,g,B,Q,w){w===void 0&&(w="same");var C=g.conv,E=C.filters,e=C.bias,I=jg(A,E,B,w);return I=OA(I,e),I=ZR(I,g.scale),Q?GB(I):I}function qR(A,g){return Yn(A,g,[1,1],!0)}function vr(A,g){return Yn(A,g,[1,1],!1)}function kr(A,g){return Yn(A,g,[2,2],!0,"valid")}function _R(A,g){function B(e,I,o){var n=A(e),i=n.length/(I*o*o);if(ER(i))throw new Error("depth has to be an integer: "+i+", weights.length: "+n.length+", numFilters: "+I+", filterSize: "+o);return DA(function(){return vQ(Dg(n,[I,i,o,o]),[2,3,1,0])})}function Q(e,I,o,n){var i=B(e,I,o),Y=PB(A(I));return g.push({paramPath:n+"/filters"},{paramPath:n+"/bias"}),{filters:i,bias:Y}}function w(e,I){var o=PB(A(e)),n=PB(A(e));return g.push({paramPath:I+"/weights"},{paramPath:I+"/biases"}),{weights:o,biases:n}}function C(e,I,o,n){var i=Q(e,I,o,n+"/conv"),Y=w(I,n+"/scale");return{conv:i,scale:Y}}function E(e,I,o,n,i){i===void 0&&(i=!1);var Y=C((i?.5:1)*e,I,o,n+"/conv1"),M=C(e,I,o,n+"/conv2");return{conv1:Y,conv2:M}}return{extractConvLayerParams:C,extractResidualLayerParams:E}}function $R(A){var g=GQ(A),B=g.extractWeights,Q=g.getRemainingWeights,w=[],C=_R(B,w),E=C.extractConvLayerParams,e=C.extractResidualLayerParams,I=E(4704,32,7,"conv32_down"),o=e(9216,32,3,"conv32_1"),n=e(9216,32,3,"conv32_2"),i=e(9216,32,3,"conv32_3"),Y=e(36864,64,3,"conv64_down",!0),M=e(36864,64,3,"conv64_1"),c=e(36864,64,3,"conv64_2"),D=e(36864,64,3,"conv64_3"),r=e(147456,128,3,"conv128_down",!0),F=e(147456,128,3,"conv128_1"),s=e(147456,128,3,"conv128_2"),u=e(589824,256,3,"conv256_down",!0),a=e(589824,256,3,"conv256_1"),U=e(589824,256,3,"conv256_2"),G=e(589824,256,3,"conv256_down_out"),d=DA(function(){return vQ(RQ(B(256*128),[128,256]),[1,0])});if(w.push({paramPath:"fc"}),Q().length!==0)throw new Error("weights remaing after extract: "+Q().length);var H={conv32_down:I,conv32_1:o,conv32_2:n,conv32_3:i,conv64_down:Y,conv64_1:M,conv64_2:c,conv64_3:D,conv128_down:r,conv128_1:F,conv128_2:s,conv256_down:u,conv256_1:a,conv256_2:U,conv256_down_out:G,fc:d};return{params:H,paramMappings:w}}function AP(A,g){var B=yQ(A,g);function Q(E){var e=B(E+"/scale/weights",1),I=B(E+"/scale/biases",1);return{weights:e,biases:I}}function w(E){var e=B(E+"/conv/filters",4),I=B(E+"/conv/bias",1),o=Q(E);return{conv:{filters:e,bias:I},scale:o}}function C(E){return{conv1:w(E+"/conv1"),conv2:w(E+"/conv2")}}return{extractConvLayerParams:w,extractResidualLayerParams:C}}function BP(A){var g=[],B=AP(A,g),Q=B.extractConvLayerParams,w=B.extractResidualLayerParams,C=Q("conv32_down"),E=w("conv32_1"),e=w("conv32_2"),I=w("conv32_3"),o=w("conv64_down"),n=w("conv64_1"),i=w("conv64_2"),Y=w("conv64_3"),M=w("conv128_down"),c=w("conv128_1"),D=w("conv128_2"),r=w("conv256_down"),F=w("conv256_1"),s=w("conv256_2"),u=w("conv256_down_out"),a=A.fc;if(g.push({originalPath:"fc",paramPath:"fc"}),!CR(a))throw new Error("expected weightMap[fc] to be a Tensor2D, instead have "+a);var U={conv32_down:C,conv32_1:E,conv32_2:e,conv32_3:I,conv64_down:o,conv64_1:n,conv64_2:i,conv64_3:Y,conv128_down:M,conv128_1:c,conv128_2:D,conv256_down:r,conv256_1:F,conv256_2:s,conv256_down_out:u,fc:a};return UQ(A,g),{params:U,paramMappings:g}}function eQ(A,g){var B=qR(A,g.conv1);return B=vr(B,g.conv2),B=OA(B,A),B=GB(B),B}function Le(A,g){var B=kr(A,g.conv1);B=vr(B,g.conv2);var Q=LC(A,2,2,"valid"),w=DB(Q.shape),C=Q.shape[3]!==B.shape[3],E=Q.shape[1]!==B.shape[1]||Q.shape[2]!==B.shape[2];if(E){var e=KC(B.shape);e[1]=1;var I=DB(e);B=jB([B,I],1);var o=KC(B.shape);o[2]=1;var n=DB(o);B=jB([B,n],2)}return Q=C?jB([Q,w],3):Q,B=OA(Q,B),B=GB(B),B}var gP=function(A){yA(g,A);function g(){return A.call(this,"FaceRecognitionNet")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("FaceRecognitionNet - load model before inference");return DA(function(){var w=B.toBatchTensor(150,!0).toFloat(),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(256)),e=kr(E,Q.conv32_down);e=VB(e,3,2,"valid"),e=eQ(e,Q.conv32_1),e=eQ(e,Q.conv32_2),e=eQ(e,Q.conv32_3),e=Le(e,Q.conv64_down),e=eQ(e,Q.conv64_1),e=eQ(e,Q.conv64_2),e=eQ(e,Q.conv64_3),e=Le(e,Q.conv128_down),e=eQ(e,Q.conv128_1),e=eQ(e,Q.conv128_2),e=Le(e,Q.conv256_down),e=eQ(e,Q.conv256_1),e=eQ(e,Q.conv256_2),e=Le(e,Q.conv256_down_out);var I=e.mean([1,2]),o=he(I,Q.fc);return o})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.computeFaceDescriptor=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E=this;return HA(this,function(e){switch(e.label){case 0:return[4,xB(B)];case 1:return Q=e.sent(),w=DA(function(){return pB(E.forwardInput(Q))}),[4,Promise.all(w.map(function(I){return I.data()}))];case 2:return C=e.sent(),w.forEach(function(I){return I.dispose()}),[2,Q.isBatchInput?C:C[0]]}})})},g.prototype.getDefaultModelName=function(){return"face_recognition_model"},g.prototype.extractParamsFromWeigthMap=function(B){return BP(B)},g.prototype.extractParams=function(B){return $R(B)},g}(uQ);function Tr(A,g){var B={descriptor:g};return Object.assign({},A,B)}function jr(A,g){var B={age:g};return Object.assign({},A,B)}function pr(A,g,B){var Q={gender:g,genderProbability:B};return Object.assign({},A,Q)}var yr=function(){function A(g){var B=g===void 0?{}:g,Q=B.minFaceSize,w=B.scaleFactor,C=B.maxNumScales,E=B.scoreThresholds,e=B.scaleSteps;if(this._name="MtcnnOptions",this._minFaceSize=Q||20,this._scaleFactor=w||.709,this._maxNumScales=C||10,this._scoreThresholds=E||[.6,.7,.7],this._scaleSteps=e,typeof this._minFaceSize!="number"||this._minFaceSize<0)throw new Error(this._name+" - expected minFaceSize to be a number > 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(I){return typeof I!="number"}))throw new Error(this._name+" - expected scoreThresholds to be an array of numbers of length 3");if(this._scaleSteps&&(!Array.isArray(this._scaleSteps)||this._scaleSteps.some(function(I){return typeof I!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(A.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),A}();function QP(A,g){function B(I,o){var n=Dg(A(9*I),[3,3,I,1]),i=PB(A(I)),Y=PB(A(I)),M=PB(A(I)),c=PB(A(I));return g.push({paramPath:o+"/filters"},{paramPath:o+"/batch_norm_scale"},{paramPath:o+"/batch_norm_offset"},{paramPath:o+"/batch_norm_mean"},{paramPath:o+"/batch_norm_variance"}),{filters:n,batch_norm_scale:i,batch_norm_offset:Y,batch_norm_mean:M,batch_norm_variance:c}}function Q(I,o,n,i,Y){var M=Dg(A(I*o*n*n),[n,n,I,o]),c=PB(A(o));return g.push({paramPath:i+"/filters"},{paramPath:i+"/"+(Y?"batch_norm_offset":"bias")}),{filters:M,bias:c}}function w(I,o,n,i){var Y=Q(I,o,n,i,!0),M=Y.filters,c=Y.bias;return{filters:M,batch_norm_offset:c}}function C(I,o,n){var i=B(I,n+"/depthwise_conv"),Y=w(I,o,1,n+"/pointwise_conv");return{depthwise_conv:i,pointwise_conv:Y}}function E(){var I=w(3,32,3,"mobilenetv1/conv_0"),o=C(32,64,"mobilenetv1/conv_1"),n=C(64,128,"mobilenetv1/conv_2"),i=C(128,128,"mobilenetv1/conv_3"),Y=C(128,256,"mobilenetv1/conv_4"),M=C(256,256,"mobilenetv1/conv_5"),c=C(256,512,"mobilenetv1/conv_6"),D=C(512,512,"mobilenetv1/conv_7"),r=C(512,512,"mobilenetv1/conv_8"),F=C(512,512,"mobilenetv1/conv_9"),s=C(512,512,"mobilenetv1/conv_10"),u=C(512,512,"mobilenetv1/conv_11"),a=C(512,1024,"mobilenetv1/conv_12"),U=C(1024,1024,"mobilenetv1/conv_13");return{conv_0:I,conv_1:o,conv_2:n,conv_3:i,conv_4:Y,conv_5:M,conv_6:c,conv_7:D,conv_8:r,conv_9:F,conv_10:s,conv_11:u,conv_12:a,conv_13:U}}function e(){var I=w(1024,256,1,"prediction_layer/conv_0"),o=w(256,512,3,"prediction_layer/conv_1"),n=w(512,128,1,"prediction_layer/conv_2"),i=w(128,256,3,"prediction_layer/conv_3"),Y=w(256,128,1,"prediction_layer/conv_4"),M=w(128,256,3,"prediction_layer/conv_5"),c=w(256,64,1,"prediction_layer/conv_6"),D=w(64,128,3,"prediction_layer/conv_7"),r=Q(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),F=Q(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),s=Q(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),u=Q(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),a=Q(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),U=Q(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),G=Q(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),d=Q(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),H=Q(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),h=Q(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),l=Q(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),m=Q(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),f={box_encoding_predictor:r,class_predictor:F},W={box_encoding_predictor:s,class_predictor:u},N={box_encoding_predictor:a,class_predictor:U},v={box_encoding_predictor:G,class_predictor:d},y={box_encoding_predictor:H,class_predictor:h},k={box_encoding_predictor:l,class_predictor:m};return{conv_0:I,conv_1:o,conv_2:n,conv_3:i,conv_4:Y,conv_5:M,conv_6:c,conv_7:D,box_predictor_0:f,box_predictor_1:W,box_predictor_2:N,box_predictor_3:v,box_predictor_4:y,box_predictor_5:k}}return{extractMobilenetV1Params:E,extractPredictionLayerParams:e}}function wP(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=QP(Q,g),E=C.extractMobilenetV1Params,e=C.extractPredictionLayerParams,I=E(),o=e(),n=_o(Q(5118*4),[1,5118,4]),i={extra_dim:n};if(g.push({paramPath:"output_layer/extra_dim"}),w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{params:{mobilenetv1:I,prediction_layer:o,output_layer:i},paramMappings:g}}function CP(A,g){var B=yQ(A,g);function Q(o,n,i){var Y=B(o+"/Conv2d_"+n+"_pointwise/weights",4,i+"/filters"),M=B(o+"/Conv2d_"+n+"_pointwise/convolution_bn_offset",1,i+"/batch_norm_offset");return{filters:Y,batch_norm_offset:M}}function w(o){var n="mobilenetv1/conv_"+o,i="MobilenetV1/Conv2d_"+o+"_depthwise",Y=n+"/depthwise_conv",M=n+"/pointwise_conv",c=B(i+"/depthwise_weights",4,Y+"/filters"),D=B(i+"/BatchNorm/gamma",1,Y+"/batch_norm_scale"),r=B(i+"/BatchNorm/beta",1,Y+"/batch_norm_offset"),F=B(i+"/BatchNorm/moving_mean",1,Y+"/batch_norm_mean"),s=B(i+"/BatchNorm/moving_variance",1,Y+"/batch_norm_variance");return{depthwise_conv:{filters:c,batch_norm_scale:D,batch_norm_offset:r,batch_norm_mean:F,batch_norm_variance:s},pointwise_conv:Q("MobilenetV1",o,M)}}function C(){return{conv_0:Q("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:w(1),conv_2:w(2),conv_3:w(3),conv_4:w(4),conv_5:w(5),conv_6:w(6),conv_7:w(7),conv_8:w(8),conv_9:w(9),conv_10:w(10),conv_11:w(11),conv_12:w(12),conv_13:w(13)}}function E(o,n){var i=B(o+"/weights",4,n+"/filters"),Y=B(o+"/biases",1,n+"/bias");return{filters:i,bias:Y}}function e(o){var n=E("Prediction/BoxPredictor_"+o+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+o+"/box_encoding_predictor"),i=E("Prediction/BoxPredictor_"+o+"/ClassPredictor","prediction_layer/box_predictor_"+o+"/class_predictor");return{box_encoding_predictor:n,class_predictor:i}}function I(){return{conv_0:Q("Prediction",0,"prediction_layer/conv_0"),conv_1:Q("Prediction",1,"prediction_layer/conv_1"),conv_2:Q("Prediction",2,"prediction_layer/conv_2"),conv_3:Q("Prediction",3,"prediction_layer/conv_3"),conv_4:Q("Prediction",4,"prediction_layer/conv_4"),conv_5:Q("Prediction",5,"prediction_layer/conv_5"),conv_6:Q("Prediction",6,"prediction_layer/conv_6"),conv_7:Q("Prediction",7,"prediction_layer/conv_7"),box_predictor_0:e(0),box_predictor_1:e(1),box_predictor_2:e(2),box_predictor_3:e(3),box_predictor_4:e(4),box_predictor_5:e(5)}}return{extractMobilenetV1Params:C,extractPredictionLayerParams:I}}function EP(A){var g=[],B=CP(A,g),Q=B.extractMobilenetV1Params,w=B.extractPredictionLayerParams,C=A["Output/extra_dim"];if(g.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!me(C))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+C);var E={mobilenetv1:Q(),prediction_layer:w(),output_layer:{extra_dim:C}};return UQ(A,g),{params:E,paramMappings:g}}function IQ(A,g,B){return DA(function(){var Q=jg(A,g.filters,B,"same");return Q=OA(Q,g.batch_norm_offset),st(Q,0,6)})}var eP=.0010000000474974513;function IP(A,g,B){return DA(function(){var Q=Ge(A,g.filters,B,"same");return Q=tD(Q,g.batch_norm_mean,g.batch_norm_variance,g.batch_norm_offset,g.batch_norm_scale,eP),st(Q,0,6)})}function oP(A){return[2,4,6,12].some(function(g){return g===A})?[2,2]:[1,1]}function tP(A,g){return DA(function(){var B=null,Q=IQ(A,g.conv_0,[2,2]),w=[g.conv_1,g.conv_2,g.conv_3,g.conv_4,g.conv_5,g.conv_6,g.conv_7,g.conv_8,g.conv_9,g.conv_10,g.conv_11,g.conv_12,g.conv_13];if(w.forEach(function(C,E){var e=E+1,I=oP(e);Q=IP(Q,C.depthwise_conv,I),Q=IQ(Q,C.pointwise_conv,[1,1]),e===11&&(B=Q)}),B===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:Q,conv11:B}})}function nP(A,g,B,Q,w){var C=A.shape[0],E=Math.min(B,C),e=g.map(function(n,i){return{score:n,boxIndex:i}}).filter(function(n){return n.score>w}).sort(function(n,i){return i.score-n.score}),I=function(n){return n<=Q?1:0},o=[];return e.forEach(function(n){if(!(o.length>=E)){for(var i=n.score,Y=o.length-1;Y>=0;--Y){var M=iP(A,n.boxIndex,o[Y]);if(M!==0&&(n.score*=I(M),n.score<=w))break}i===n.score&&o.push(n.boxIndex)}}),o}function iP(A,g,B){var Q=A.arraySync(),w=Math.min(Q[g][0],Q[g][2]),C=Math.min(Q[g][1],Q[g][3]),E=Math.max(Q[g][0],Q[g][2]),e=Math.max(Q[g][1],Q[g][3]),I=Math.min(Q[B][0],Q[B][2]),o=Math.min(Q[B][1],Q[B][3]),n=Math.max(Q[B][0],Q[B][2]),i=Math.max(Q[B][1],Q[B][3]),Y=(E-w)*(e-C),M=(n-I)*(i-o);if(Y<=0||M<=0)return 0;var c=Math.max(w,I),D=Math.max(C,o),r=Math.min(E,n),F=Math.min(e,i),s=Math.max(r-c,0)*Math.max(F-D,0);return s/(Y+M-s)}function YP(A){var g=pB(vQ(A,[1,0])),B=[zB(g[2],g[0]),zB(g[3],g[1])],Q=[OA(g[0],bg(B[0],nA(2))),OA(g[1],bg(B[1],nA(2)))];return{sizes:B,centers:Q}}function MP(A,g){var B=YP(A),Q=B.sizes,w=B.centers,C=pB(vQ(g,[1,0])),E=bg(wg(ut(bg(C[2],nA(5))),Q[0]),nA(2)),e=OA(wg(bg(C[0],nA(10)),Q[0]),w[0]),I=bg(wg(ut(bg(C[3],nA(5))),Q[1]),nA(2)),o=OA(wg(bg(C[1],nA(10)),Q[1]),w[1]);return vQ(Hg([zB(e,E),zB(o,I),OA(e,E),OA(o,I)]),[1,0])}function cP(A,g,B){return DA(function(){var Q=A.shape[0],w=MP(Sg(Ww(B.extra_dim,[Q,1,1]),[-1,4]),Sg(A,[-1,4]));w=Sg(w,[Q,w.shape[0]/Q,4]);var C=ED(QQ(g,[0,0,1],[-1,-1,-1])),E=QQ(C,[0,0,0],[-1,-1,1]);E=Sg(E,[Q,E.shape[1]]);var e=pB(w),I=pB(E);return{boxes:e,scores:I}})}function BC(A,g){return DA(function(){var B=A.shape[0],Q=Sg(Kg(A,g.box_encoding_predictor),[B,-1,1,4]),w=Sg(Kg(A,g.class_predictor),[B,-1,3]);return{boxPredictionEncoding:Q,classPrediction:w}})}function DP(A,g,B){return DA(function(){var Q=IQ(A,B.conv_0,[1,1]),w=IQ(Q,B.conv_1,[2,2]),C=IQ(w,B.conv_2,[1,1]),E=IQ(C,B.conv_3,[2,2]),e=IQ(E,B.conv_4,[1,1]),I=IQ(e,B.conv_5,[2,2]),o=IQ(I,B.conv_6,[1,1]),n=IQ(o,B.conv_7,[2,2]),i=BC(g,B.box_predictor_0),Y=BC(A,B.box_predictor_1),M=BC(w,B.box_predictor_2),c=BC(E,B.box_predictor_3),D=BC(I,B.box_predictor_4),r=BC(n,B.box_predictor_5),F=jB([i.boxPredictionEncoding,Y.boxPredictionEncoding,M.boxPredictionEncoding,c.boxPredictionEncoding,D.boxPredictionEncoding,r.boxPredictionEncoding],1),s=jB([i.classPrediction,Y.classPrediction,M.classPrediction,c.classPrediction,D.classPrediction,r.classPrediction],1);return{boxPredictions:F,classPredictions:s}})}var be=function(){function A(g){var B=g===void 0?{}:g,Q=B.minConfidence,w=B.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=Q||.5,this._maxResults=w||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(A.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),A}(),zr=function(A){yA(g,A);function g(){return A.call(this,"SsdMobilenetv1")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("SsdMobilenetv1 - load model before inference");return DA(function(){var w=B.toBatchTensor(512,!1).toFloat(),C=zB(wg(w,nA(.007843137718737125)),nA(1)),E=tP(C,Q.mobilenetv1),e=DP(E.out,E.conv11,Q.prediction_layer),I=e.boxPredictions,o=e.classPredictions;return cP(I,o,Q.output_layer)})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.locateFaces=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return HA(this,function(h){switch(h.label){case 0:return w=new be(Q),C=w.maxResults,E=w.minConfidence,[4,xB(B)];case 1:for(e=h.sent(),I=this.forwardInput(e),o=I.boxes,n=I.scores,i=o[0],Y=n[0],M=1;M<o.length;M++)o[M].dispose(),n[M].dispose();return r=(D=Array).from,[4,Y.data()];case 2:return c=r.apply(D,[h.sent()]),F=.5,s=nP(i,c,C,F,E),u=e.getReshapedInputDimensions(0),a=e.inputSize,U=a/u.width,G=a/u.height,d=i.arraySync(),H=s.map(function(l){var m=[Math.max(0,d[l][0]),Math.min(1,d[l][2])].map(function(k){return k*G}),f=m[0],W=m[1],N=[Math.max(0,d[l][1]),Math.min(1,d[l][3])].map(function(k){return k*U}),v=N[0],y=N[1];return new Jg(c[l],new Pe(v,f,y-v,W-f),{height:e.getInputHeight(0),width:e.getInputWidth(0)})}),i.dispose(),Y.dispose(),[2,H]}})})},g.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},g.prototype.extractParamsFromWeigthMap=function(B){return EP(B)},g.prototype.extractParams=function(B){return wP(B)},g}(uQ);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g})(zr);var rP=.4,FP=[new QB(.738768,.874946),new QB(2.42204,2.65704),new QB(4.30971,7.04493),new QB(10.246,4.59428),new QB(12.6868,11.8741)],aP=[new QB(1.603231,2.094468),new QB(6.041143,7.080126),new QB(2.882459,3.518061),new QB(4.266906,5.178857),new QB(9.041765,10.66308)],sP=[117.001,114.697,97.404],uP="tiny_yolov2_model",UP="tiny_yolov2_separable_conv_model",Ke=function(A){return typeof A=="number"};function GP(A){if(!A)throw new Error("invalid config: "+A);if(typeof A.withSeparableConvs!="boolean")throw new Error("config.withSeparableConvs has to be a boolean, have: "+A.withSeparableConvs);if(!Ke(A.iouThreshold)||A.iouThreshold<0||A.iouThreshold>1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+A.iouThreshold);if(!Array.isArray(A.classes)||!A.classes.length||!A.classes.every(function(g){return typeof g=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(A.classes));if(!Array.isArray(A.anchors)||!A.anchors.length||!A.anchors.map(function(g){return g||{}}).every(function(g){return Ke(g.x)&&Ke(g.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(A.anchors));if(A.meanRgb&&(!Array.isArray(A.meanRgb)||A.meanRgb.length!==3||!A.meanRgb.every(Ke)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(A.meanRgb))}function Mn(A){return DA(function(){var g=wg(A,nA(.10000000149011612));return OA(GB(zB(A,g)),g)})}function zQ(A,g){return DA(function(){var B=ww(A,[[0,0],[1,1],[1,1],[0,0]]);return B=jg(B,g.conv.filters,[1,1],"valid"),B=zB(B,g.bn.sub),B=wg(B,g.bn.truediv),B=OA(B,g.conv.bias),Mn(B)})}function WQ(A,g){return DA(function(){var B=ww(A,[[0,0],[1,1],[1,1],[0,0]]);return B=dt(B,g.depthwise_filter,g.pointwise_filter,[1,1],"valid"),B=OA(B,g.bias),Mn(B)})}function hP(A,g){var B=ze(A,g);function Q(E,e){var I=PB(A(E)),o=PB(A(E));return g.push({paramPath:e+"/sub"},{paramPath:e+"/truediv"}),{sub:I,truediv:o}}function w(E,e,I){var o=B(E,e,3,I+"/conv"),n=Q(e,I+"/bn");return{conv:o,bn:n}}var C=en(A,g);return{extractConvParams:B,extractConvWithBatchNormParams:w,extractSeparableConvParams:C}}function lP(A,g,B,Q){var w=GQ(A),C=w.extractWeights,E=w.getRemainingWeights,e=[],I=hP(C,e),o=I.extractConvParams,n=I.extractConvWithBatchNormParams,i=I.extractSeparableConvParams,Y;if(g.withSeparableConvs){var M=Q[0],c=Q[1],D=Q[2],r=Q[3],F=Q[4],s=Q[5],u=Q[6],a=Q[7],U=Q[8],G=g.isFirstLayerConv2d?o(M,c,3,"conv0"):i(M,c,"conv0"),d=i(c,D,"conv1"),H=i(D,r,"conv2"),h=i(r,F,"conv3"),l=i(F,s,"conv4"),m=i(s,u,"conv5"),f=a?i(u,a,"conv6"):void 0,W=U?i(a,U,"conv7"):void 0,N=o(U||a||u,5*B,1,"conv8");Y={conv0:G,conv1:d,conv2:H,conv3:h,conv4:l,conv5:m,conv6:f,conv7:W,conv8:N}}else{var M=Q[0],c=Q[1],D=Q[2],r=Q[3],F=Q[4],s=Q[5],u=Q[6],a=Q[7],U=Q[8],G=n(M,c,"conv0"),d=n(c,D,"conv1"),H=n(D,r,"conv2"),h=n(r,F,"conv3"),l=n(F,s,"conv4"),m=n(s,u,"conv5"),f=n(u,a,"conv6"),W=n(a,U,"conv7"),N=o(U,5*B,1,"conv8");Y={conv0:G,conv1:d,conv2:H,conv3:h,conv4:l,conv5:m,conv6:f,conv7:W,conv8:N}}if(E().length!==0)throw new Error("weights remaing after extract: "+E().length);return{params:Y,paramMappings:e}}function dP(A,g){var B=yQ(A,g);function Q(e){var I=B(e+"/sub",1),o=B(e+"/truediv",1);return{sub:I,truediv:o}}function w(e){var I=B(e+"/filters",4),o=B(e+"/bias",1);return{filters:I,bias:o}}function C(e){var I=w(e+"/conv"),o=Q(e+"/bn");return{conv:I,bn:o}}var E=In(B);return{extractConvParams:w,extractConvWithBatchNormParams:C,extractSeparableConvParams:E}}function HP(A,g){var B=[],Q=dP(A,B),w=Q.extractConvParams,C=Q.extractConvWithBatchNormParams,E=Q.extractSeparableConvParams,e;if(g.withSeparableConvs){var I=g.filterSizes&&g.filterSizes.length||9;e={conv0:g.isFirstLayerConv2d?w("conv0"):E("conv0"),conv1:E("conv1"),conv2:E("conv2"),conv3:E("conv3"),conv4:E("conv4"),conv5:E("conv5"),conv6:I>7?E("conv6"):void 0,conv7:I>8?E("conv7"):void 0,conv8:w("conv8")}}else e={conv0:C("conv0"),conv1:C("conv1"),conv2:C("conv2"),conv3:C("conv3"),conv4:C("conv4"),conv5:C("conv5"),conv6:C("conv6"),conv7:C("conv7"),conv8:w("conv8")};return UQ(A,B),{params:e,paramMappings:B}}var Wr;(function(A){A[A.XS=224]="XS",A[A.SM=320]="SM",A[A.MD=416]="MD",A[A.LG=608]="LG"})(Wr||(Wr={}));var cn=function(){function A(g){var B=g===void 0?{}:g,Q=B.inputSize,w=B.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=Q||416,this._scoreThreshold=w||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(A.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),A}(),Sr=function(A){yA(g,A);function g(B){var Q=A.call(this,"TinyYolov2")||this;return GP(B),Q._config=B,Q}return Object.defineProperty(g.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"withClassScores",{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"boxEncodingSize",{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),g.prototype.runTinyYolov2=function(B,Q){var w=zQ(B,Q.conv0);return w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv1),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv2),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv3),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv4),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv5),w=VB(w,[2,2],[1,1],"same"),w=zQ(w,Q.conv6),w=zQ(w,Q.conv7),Kg(w,Q.conv8,"valid",!1)},g.prototype.runMobilenet=function(B,Q){var w=this.config.isFirstLayerConv2d?Mn(Kg(B,Q.conv0,"valid",!1)):WQ(B,Q.conv0);return w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv1),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv2),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv3),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv4),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv5),w=VB(w,[2,2],[1,1],"same"),w=Q.conv6?WQ(w,Q.conv6):w,w=Q.conv7?WQ(w,Q.conv7):w,Kg(w,Q.conv8,"valid",!1)},g.prototype.forwardInput=function(B,Q){var w=this,C=this.params;if(!C)throw new Error("TinyYolov2 - load model before inference");return DA(function(){var E=B.toBatchTensor(Q,!1).toFloat();return E=w.config.meanRgb?XC(E,w.config.meanRgb):E,E=E.div(nA(256)),w.config.withSeparableConvs?w.runMobilenet(E,C):w.runTinyYolov2(E,C)})},g.prototype.forward=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[4,w.apply(this,[C.sent(),Q])];case 2:return[2,C.sent()]}})})},g.prototype.detect=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s=this;return HA(this,function(u){switch(u.label){case 0:return w=new cn(Q),C=w.inputSize,E=w.scoreThreshold,[4,xB(B)];case 1:return e=u.sent(),[4,this.forwardInput(e,C)];case 2:return I=u.sent(),o=DA(function(){return pB(I)[0].expandDims()}),n={width:e.getInputWidth(0),height:e.getInputHeight(0)},[4,this.extractBoxes(o,e.getReshapedInputDimensions(0),E)];case 3:return i=u.sent(),I.dispose(),o.dispose(),Y=i.map(function(a){return a.box}),M=i.map(function(a){return a.score}),c=i.map(function(a){return a.classScore}),D=i.map(function(a){return s.config.classes[a.label]}),r=xC(Y.map(function(a){return a.rescale(C)}),M,this.config.iouThreshold,!0),F=r.map(function(a){return new Ir(M[a],c[a],D[a],Y[a],n)}),[2,F]}})})},g.prototype.getDefaultModelName=function(){return""},g.prototype.extractParamsFromWeigthMap=function(B){return HP(B,this.config)},g.prototype.extractParams=function(B){var Q=this.config.filterSizes||g.DEFAULT_FILTER_SIZES,w=Q?Q.length:void 0;if(w!==7&&w!==8&&w!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+w+" filterSizes in config");return lP(B,this.config,this.boxEncodingSize,Q)},g.prototype.extractBoxes=function(B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H,h,l,m,f,W,N,v,y,k,p=this;return HA(this,function(K){switch(K.label){case 0:return C=Q.width,E=Q.height,e=Math.max(C,E),I=e/C,o=e/E,n=B.shape[1],i=this.config.anchors.length,Y=DA(function(){var V=B.reshape([n,n,i,p.boxEncodingSize]),T=V.slice([0,0,0,0],[n,n,i,4]),j=V.slice([0,0,0,4],[n,n,i,1]),X=p.withClassScores?rQ(V.slice([0,0,0,5],[n,n,i,p.config.classes.length]),3):nA(0);return[T,j,X]}),M=Y[0],c=Y[1],D=Y[2],r=[],[4,c.array()];case 1:return F=K.sent(),[4,M.array()];case 2:s=K.sent(),u=0,K.label=3;case 3:if(!(u<n))return[3,12];a=0,K.label=4;case 4:if(!(a<n))return[3,11];U=0,K.label=5;case 5:return U<i?(G=$t(F[u][a][U][0]),!w||G>w?(d=(a+$t(s[u][a][U][0]))/n*I,H=(u+$t(s[u][a][U][1]))/n*o,h=Math.exp(s[u][a][U][2])*this.config.anchors[U].x/n*I,l=Math.exp(s[u][a][U][3])*this.config.anchors[U].y/n*o,m=d-h/2,f=H-l/2,W={row:u,col:a,anchor:U},this.withClassScores?[4,this.extractPredictedClass(D,W)]:[3,7]):[3,9]):[3,10];case 6:return k=K.sent(),[3,8];case 7:k={classScore:1,label:0},K.label=8;case 8:N=k,v=N.classScore,y=N.label,r.push(Eg({box:new Re(m,f,m+h,f+l),score:G,classScore:G*v,label:y},W)),K.label=9;case 9:return U++,[3,5];case 10:return a++,[3,4];case 11:return u++,[3,3];case 12:return M.dispose(),c.dispose(),D.dispose(),[2,r]}})})},g.prototype.extractPredictedClass=function(B,Q){return dA(this,void 0,void 0,function(){var w,C,E,e;return HA(this,function(I){switch(I.label){case 0:return w=Q.row,C=Q.col,E=Q.anchor,[4,B.array()];case 1:return e=I.sent(),[2,Array(this.config.classes.length).fill(0).map(function(o,n){return e[w][C][E][n]}).map(function(o,n){return{classScore:o,label:n}}).reduce(function(o,n){return o.classScore>n.classScore?o:n})]}})})},g.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],g}(uQ),fP=function(A){yA(g,A);function g(B){B===void 0&&(B=!0);var Q=this,w=Object.assign({},{withSeparableConvs:B,iouThreshold:rP,classes:["face"]},B?{anchors:aP,meanRgb:sP}:{anchors:FP,withClassScores:!0});return Q=A.call(this,w)||this,Q}return Object.defineProperty(g.prototype,"withSeparableConvs",{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),g.prototype.locateFaces=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.detect(B,Q)];case 1:return w=C.sent(),[2,w.map(function(E){return new Jg(E.score,E.relativeBox,{width:E.imageWidth,height:E.imageHeight})})]}})})},g.prototype.getDefaultModelName=function(){return this.withSeparableConvs?UP:uP},g.prototype.extractParamsFromWeigthMap=function(B){return A.prototype.extractParamsFromWeigthMap.call(this,B)},g}(Sr),Lr=function(A){yA(g,A);function g(){var B=A!==null&&A.apply(this,arguments)||this;return B._name="TinyFaceDetectorOptions",B}return g}(cn),qC=function(){function A(){}return A.prototype.then=function(g){return dA(this,void 0,void 0,function(){var B;return HA(this,function(Q){switch(Q.label){case 0:return B=g,[4,this.run()];case 1:return[2,B.apply(void 0,[Q.sent()])]}})})},A.prototype.run=function(){return dA(this,void 0,void 0,function(){return HA(this,function(g){throw new Error("ComposableTask - run is not implemented")})})},A}();function Ve(A,g,B,Q,w){return w===void 0&&(w=function(C){var E=C.alignedRect;return E}),dA(this,void 0,void 0,function(){var C,E,e,I,o;return HA(this,function(n){switch(n.label){case 0:return C=A.map(function(i){return tn(i)?w(i):i.detection}),e=Q,e?[3,5]:g instanceof uB?[4,wn(g,C)]:[3,2];case 1:return I=n.sent(),[3,4];case 2:return[4,pe(g,C)];case 3:I=n.sent(),n.label=4;case 4:e=I,n.label=5;case 5:return E=e,[4,B(E)];case 6:return o=n.sent(),E.forEach(function(i){return i instanceof uB&&i.dispose()}),[2,o]}})})}function Dn(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C=this;return HA(this,function(E){return[2,Ve([A],g,function(e){return dA(C,void 0,void 0,function(){return HA(this,function(I){return[2,B(e[0])]})})},Q,w)]})})}function JP(A){return DA(function(){return Hg(pB(A,3).reverse(),3)})}var xe=2,Xe=12;function NP(A,g){var B=ze(A,g),Q=En(A,g);function w(o,n){var i=PB(A(o));return g.push({paramPath:n}),i}function C(o,n,i){i===void 0&&(i=!1);var Y=B(o[0],o[1],3,n+"/conv1"),M=w(o[1],n+"/prelu1_alpha"),c=B(o[1],o[2],3,n+"/conv2"),D=w(o[2],n+"/prelu2_alpha"),r=B(o[2],o[3],i?2:3,n+"/conv3"),F=w(o[3],n+"/prelu3_alpha");return{conv1:Y,prelu1_alpha:M,conv2:c,prelu2_alpha:D,conv3:r,prelu3_alpha:F}}function E(){var o=C([3,10,16,32],"pnet"),n=B(32,2,1,"pnet/conv4_1"),i=B(32,4,1,"pnet/conv4_2");return Eg(Eg({},o),{conv4_1:n,conv4_2:i})}function e(){var o=C([3,28,48,64],"rnet",!0),n=Q(576,128,"rnet/fc1"),i=w(128,"rnet/prelu4_alpha"),Y=Q(128,2,"rnet/fc2_1"),M=Q(128,4,"rnet/fc2_2");return Eg(Eg({},o),{fc1:n,prelu4_alpha:i,fc2_1:Y,fc2_2:M})}function I(){var o=C([3,32,64,64],"onet"),n=B(64,128,2,"onet/conv4"),i=w(128,"onet/prelu4_alpha"),Y=Q(1152,256,"onet/fc1"),M=w(256,"onet/prelu5_alpha"),c=Q(256,2,"onet/fc2_1"),D=Q(256,4,"onet/fc2_2"),r=Q(256,10,"onet/fc2_3");return Eg(Eg({},o),{conv4:n,prelu4_alpha:i,fc1:Y,prelu5_alpha:M,fc2_1:c,fc2_2:D,fc2_3:r})}return{extractPNetParams:E,extractRNetParams:e,extractONetParams:I}}function mP(A){var g=GQ(A),B=g.extractWeights,Q=g.getRemainingWeights,w=[],C=NP(B,w),E=C.extractPNetParams,e=C.extractRNetParams,I=C.extractONetParams,o=E(),n=e(),i=I();if(Q().length!==0)throw new Error("weights remaing after extract: "+Q().length);return{params:{pnet:o,rnet:n,onet:i},paramMappings:w}}function RP(A,g){var B=yQ(A,g);function Q(n){var i=B(n+"/weights",4,n+"/filters"),Y=B(n+"/bias",1);return{filters:i,bias:Y}}function w(n){var i=B(n+"/weights",2),Y=B(n+"/bias",1);return{weights:i,bias:Y}}function C(n){return B(n,1)}function E(n){var i=Q(n+"/conv1"),Y=C(n+"/prelu1_alpha"),M=Q(n+"/conv2"),c=C(n+"/prelu2_alpha"),D=Q(n+"/conv3"),r=C(n+"/prelu3_alpha");return{conv1:i,prelu1_alpha:Y,conv2:M,prelu2_alpha:c,conv3:D,prelu3_alpha:r}}function e(){var n=E("pnet"),i=Q("pnet/conv4_1"),Y=Q("pnet/conv4_2");return Eg(Eg({},n),{conv4_1:i,conv4_2:Y})}function I(){var n=E("rnet"),i=w("rnet/fc1"),Y=C("rnet/prelu4_alpha"),M=w("rnet/fc2_1"),c=w("rnet/fc2_2");return Eg(Eg({},n),{fc1:i,prelu4_alpha:Y,fc2_1:M,fc2_2:c})}function o(){var n=E("onet"),i=Q("onet/conv4"),Y=C("onet/prelu4_alpha"),M=w("onet/fc1"),c=C("onet/prelu5_alpha"),D=w("onet/fc2_1"),r=w("onet/fc2_2"),F=w("onet/fc2_3");return Eg(Eg({},n),{conv4:i,prelu4_alpha:Y,fc1:M,prelu5_alpha:c,fc2_1:D,fc2_2:r,fc2_3:F})}return{extractPNetParams:e,extractRNetParams:I,extractONetParams:o}}function PP(A){var g=[],B=RP(A,g),Q=B.extractPNetParams,w=B.extractRNetParams,C=B.extractONetParams,E=Q(),e=w(),I=C();return UQ(A,g),{params:{pnet:E,rnet:e,onet:I},paramMappings:g}}function rn(A,g){var B=g[0],Q=g[1];return{height:Math.floor(B*A),width:Math.floor(Q*A)}}function vP(A,g,B){for(var Q=B[0],w=B[1],C=Xe/A,E=[],e=Math.min(Q,w)*C,I=0;e>=12;)E.push(C*Math.pow(g,I)),e=e*g,I+=1;return E}var Fn=function(A){yA(g,A);function g(B,Q,w,C){return A.call(this,{left:B,top:Q,right:w,bottom:C},!0)||this}return g}(wQ);function br(A){return DA(function(){return wg(zB(A,nA(127.5)),nA(.0078125))})}function gC(A,g){return DA(function(){return OA(GB(A),wg(g,Fe(GB(Fe(A)))))})}function an(A,g,B){return B===void 0&&(B=!1),DA(function(){var Q=Kg(A,g.conv1,"valid");return Q=gC(Q,g.prelu1_alpha),Q=VB(Q,B?[2,2]:[3,3],[2,2],"same"),Q=Kg(Q,g.conv2,"valid"),Q=gC(Q,g.prelu2_alpha),Q=B?Q:VB(Q,[3,3],[2,2],"valid"),Q=Kg(Q,g.conv3,"valid"),Q=gC(Q,g.prelu3_alpha),Q})}function kP(A,g){return DA(function(){var B=an(A,g,!0),Q=Kg(B,g.conv4_1,"valid"),w=Tg(le(Q,3),3),C=rQ(zB(Q,w),3),E=Kg(B,g.conv4_2,"valid");return{prob:C,regions:E}})}function TP(A,g){return DA(function(){var B=rn(g,A.shape.slice(1)),Q=B.height,w=B.width,C=mt.resizeBilinear(A,[Q,w]),E=br(C);return vQ(E,[0,2,1,3])})}function jP(A,g,B,Q){for(var w=[],C=A.arraySync(),E=0;E<A.shape[0];E++)for(var e=0;e<A.shape[1];e++)C[E][e]>=Q&&w.push(new QB(e,E));var I=w.map(function(o){var n=new Re(Math.round((o.y*xe+1)/B),Math.round((o.x*xe+1)/B),Math.round((o.y*xe+Xe)/B),Math.round((o.x*xe+Xe)/B)),i=C[o.y][o.x],Y=g.arraySync(),M=new Fn(Y[o.y][o.x][0],Y[o.y][o.x][1],Y[o.y][o.x][2],Y[o.y][o.x][3]);return{cell:n,score:i,region:M}});return I}function pP(A,g,B,Q,w){w.stage1=[];var C=g.map(function(Y){return DA(function(){var M={scale:Y},c=TP(A,Y),D=Date.now(),r=kP(c,Q),F=r.prob,s=r.regions;M.pnet=Date.now()-D;var u=pB(pB(F,3)[1])[0],a=pB(s)[0];return{scoresTensor:u,regionsTensor:a,scale:Y,statsForScale:M}})}),E=C.map(function(Y){var M=Y.scoresTensor,c=Y.regionsTensor,D=Y.scale,r=Y.statsForScale,F=jP(M,c,D,B);if(M.dispose(),c.dispose(),!F.length)return w.stage1.push(r),[];var s=Date.now(),u=xC(F.map(function(a){return a.cell}),F.map(function(a){return a.score}),.5);return r.nms=Date.now()-s,r.numBoxes=u.length,w.stage1.push(r),u.map(function(a){return F[a]})}),e=E.reduce(function(Y,M){return Y.concat(M)},[]),I=[],o=[];if(e.length>0){var n=Date.now(),i=xC(e.map(function(Y){return Y.cell}),e.map(function(Y){return Y.score}),.7);w.stage1_nms=Date.now()-n,o=i.map(function(Y){return e[Y].score}),I=i.map(function(Y){return e[Y]}).map(function(Y){var M=Y.cell,c=Y.region;return new Re(M.left+c.left*M.width,M.top+c.top*M.height,M.right+c.right*M.width,M.bottom+c.bottom*M.height).toSquare().round()})}return{boxes:I,scores:o}}function Kr(A,g,B){var Q=B.width,w=B.height;return dA(this,void 0,void 0,function(){var C,E,e,I=this;return HA(this,function(o){switch(o.label){case 0:return C=CQ(A),[4,Promise.all(g.map(function(n){return dA(I,void 0,void 0,function(){var i,Y,M,c,D,r,F,s;return HA(this,function(u){return i=n.padAtBorders(A.height,A.width),Y=i.y,M=i.ey,c=i.x,D=i.ex,r=c-1,F=Y-1,s=C.getImageData(r,F,D-r,M-F),[2,eg.isNodejs()?Te(s):createImageBitmap(s)]})})}))];case 1:return E=o.sent(),e=[],E.forEach(function(n){var i=ke({width:Q,height:w}),Y=CQ(i);Y.drawImage(n,0,0,Q,w);for(var M=Y.getImageData(0,0,Q,w).data,c=[],D=0;D<M.length;D+=4)c.push(M[D+2]),c.push(M[D+1]),c.push(M[D]);e.push(c)}),[2,e.map(function(n){var i=DA(function(){var Y=vQ(Dg(n,[1,Q,w,3]),[0,2,1,3]).toFloat();return br(Y)});return i})]}})})}function yP(A,g){return DA(function(){var B=an(A,g),Q=Sg(B,[B.shape[0],g.fc1.weights.shape[0]]),w=EQ(Q,g.fc1),C=gC(w,g.prelu4_alpha),E=EQ(C,g.fc2_1),e=Tg(le(E,1),1),I=rQ(zB(E,e),1),o=EQ(C,g.fc2_2),n=pB(I,1)[1];return{scores:n,regions:o}})}function zP(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s;return HA(this,function(u){switch(u.label){case 0:return C=Date.now(),[4,Kr(A,g,{width:24,height:24})];case 1:return E=u.sent(),w.stage2_extractImagePatches=Date.now()-C,C=Date.now(),e=E.map(function(a){var U=yP(a,Q);return a.dispose(),U}),w.stage2_rnet=Date.now()-C,I=e.length>1?jB(e.map(function(a){return a.scores})):e[0].scores,i=(n=Array).from,[4,I.data()];case 2:return o=i.apply(n,[u.sent()]),I.dispose(),Y=o.map(function(a,U){return{score:a,idx:U}}).filter(function(a){return a.score>B}).map(function(a){var U=a.idx;return U}),M=Y.map(function(a){return g[a]}),c=Y.map(function(a){return o[a]}),D=[],r=[],M.length>0&&(C=Date.now(),F=xC(M,c,.7),w.stage2_nms=Date.now()-C,s=F.map(function(a){var U=e[Y[a]].regions.arraySync();return new Fn(U[0][0],U[0][1],U[0][2],U[0][3])}),r=F.map(function(a){return c[a]}),D=F.map(function(a,U){return M[a].calibrate(s[U])})),e.forEach(function(a){a.regions.dispose(),a.scores.dispose()}),[2,{boxes:D,scores:r}]}})})}function WP(A,g){return DA(function(){var B=an(A,g);B=VB(B,[2,2],[2,2],"same"),B=Kg(B,g.conv4,"valid"),B=gC(B,g.prelu4_alpha);var Q=Sg(B,[B.shape[0],g.fc1.weights.shape[0]]),w=EQ(Q,g.fc1),C=gC(w,g.prelu5_alpha),E=EQ(C,g.fc2_1),e=Tg(le(E,1),1),I=rQ(zB(E,e),1),o=EQ(C,g.fc2_2),n=EQ(C,g.fc2_3),i=pB(I,1)[1];return{scores:i,regions:o,points:n}})}function SP(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u;return HA(this,function(a){switch(a.label){case 0:return C=Date.now(),[4,Kr(A,g,{width:48,height:48})];case 1:return E=a.sent(),w.stage3_extractImagePatches=Date.now()-C,C=Date.now(),e=E.map(function(U){var G=WP(U,Q);return U.dispose(),G}),w.stage3_onet=Date.now()-C,I=e.length>1?jB(e.map(function(U){return U.scores})):e[0].scores,i=(n=Array).from,[4,I.data()];case 2:return o=i.apply(n,[a.sent()]),I.dispose(),Y=o.map(function(U,G){return{score:U,idx:G}}).filter(function(U){return U.score>B}).map(function(U){var G=U.idx;return G}),M=Y.map(function(U){var G=e[U].regions.arraySync();return new Fn(G[0][0],G[0][1],G[0][2],G[0][3])}),c=Y.map(function(U,G){return g[U].calibrate(M[G])}),D=Y.map(function(U){return o[U]}),r=[],F=[],s=[],c.length>0&&(C=Date.now(),u=xC(c,D,.7,!1),w.stage3_nms=Date.now()-C,r=u.map(function(U){return c[U]}),F=u.map(function(U){return D[U]}),s=u.map(function(U,G){return Array(5).fill(0).map(function(d,H){var h=e[U].points.arraySync();return new QB(h[0][H]*(r[G].width+1)+r[G].left,h[0][H+5]*(r[G].height+1)+r[G].top)})})),e.forEach(function(U){U.regions.dispose(),U.scores.dispose(),U.points.dispose()}),[2,{boxes:r,scores:F,points:s}]}})})}var LP=function(A){yA(g,A);function g(){return A.call(this,"Mtcnn")||this}return g.prototype.load=function(B){return dA(this,void 0,void 0,function(){return HA(this,function(Q){return console.warn("mtcnn is deprecated and will be removed soon"),[2,A.prototype.load.call(this,B)]})})},g.prototype.loadFromDisk=function(B){return dA(this,void 0,void 0,function(){return HA(this,function(Q){return console.warn("mtcnn is deprecated and will be removed soon"),[2,A.prototype.loadFromDisk.call(this,B)]})})},g.prototype.forwardInput=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return HA(this,function(h){switch(h.label){case 0:if(w=this.params,!w)throw new Error("Mtcnn - load model before inference");if(C=B.canvases[0],!C)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return E={},e=Date.now(),I=DA(function(){return JP(Tg(Ot.fromPixels(C)).toFloat())}),o=function(l){return I.dispose(),E.total=Date.now()-e,l},n=I.shape.slice(1),i=n[0],Y=n[1],M=new yr(Q),c=M.minFaceSize,D=M.scaleFactor,r=M.maxNumScales,F=M.scoreThresholds,s=M.scaleSteps,u=(s||vP(c,D,[i,Y])).filter(function(l){var m=rn(l,[i,Y]);return Math.min(m.width,m.height)>Xe}).slice(0,r),E.scales=u,E.pyramid=u.map(function(l){return rn(l,[i,Y])}),a=Date.now(),[4,pP(I,u,F[0],w.pnet,E)];case 1:return U=h.sent(),E.total_stage1=Date.now()-a,U.boxes.length?(E.stage2_numInputBoxes=U.boxes.length,a=Date.now(),[4,zP(C,U.boxes,F[1],w.rnet,E)]):[2,o({results:[],stats:E})];case 2:return G=h.sent(),E.total_stage2=Date.now()-a,G.boxes.length?(E.stage3_numInputBoxes=G.boxes.length,a=Date.now(),[4,SP(C,G.boxes,F[2],w.onet,E)]):[2,o({results:[],stats:E})];case 3:return d=h.sent(),E.total_stage3=Date.now()-a,H=d.boxes.map(function(l,m){return We(ZC({},new Jg(d.scores[m],new Pe(l.left/Y,l.top/i,l.width/Y,l.height/i),{height:i,width:Y})),new MR(d.points[m].map(function(f){return f.sub(new QB(l.left,l.top)).div(new QB(l.width,l.height))}),{width:l.width,height:l.height}))}),[2,o({results:H,stats:E})]}})})},g.prototype.forward=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[4,w.apply(this,[C.sent(),Q])];case 2:return[2,C.sent().results]}})})},g.prototype.forwardWithStats=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[2,w.apply(this,[C.sent(),Q])]}})})},g.prototype.getDefaultModelName=function(){return"mtcnn_model"},g.prototype.extractParamsFromWeigthMap=function(B){return PP(B)},g.prototype.extractParams=function(B){return mP(B)},g}(uQ),bP=.4,KP=[new QB(1.603231,2.094468),new QB(6.041143,7.080126),new QB(2.882459,3.518061),new QB(4.266906,5.178857),new QB(9.041765,10.66308)],VP=[117.001,114.697,97.404],xP=function(A){yA(g,A);function g(){var B=this,Q={withSeparableConvs:!0,iouThreshold:bP,classes:["face"],anchors:KP,meanRgb:VP,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return B=A.call(this,Q)||this,B}return Object.defineProperty(g.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),g.prototype.locateFaces=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.detect(B,Q)];case 1:return w=C.sent(),[2,w.map(function(E){return new Jg(E.score,E.relativeBox,{width:E.imageWidth,height:E.imageHeight})})]}})})},g.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},g.prototype.extractParamsFromWeigthMap=function(B){return A.prototype.extractParamsFromWeigthMap.call(this,B)},g}(Sr),Ig={ssdMobilenetv1:new zr,tinyFaceDetector:new xP,tinyYolov2:new fP,mtcnn:new LP,faceLandmark68Net:new Pr,faceLandmark68TinyNet:new OR,faceRecognitionNet:new gP,faceExpressionNet:new mR,ageGenderNet:new KR},Vr=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.extractedFaces=w,C}return g}(qC),sn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w=this;return HA(this,function(C){switch(C.label){case 0:return[4,this.parentTask];case 1:return B=C.sent(),[4,Ve(B,this.input,function(E){return dA(w,void 0,void 0,function(){return HA(this,function(e){switch(e.label){case 0:return[4,Promise.all(E.map(function(I){return Ig.faceExpressionNet.predictExpressions(I)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return Q=C.sent(),[2,B.map(function(E,e){return Nr(E,Q[e])})]}})})},g.prototype.withAgeAndGender=function(){return new hn(this,this.input)},g}(Vr),un=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),B?[4,Dn(B,this.input,function(C){return Ig.faceExpressionNet.predictExpressions(C)},this.extractedFaces)]:[2];case 2:return Q=w.sent(),[2,Nr(B,Q)]}})})},g.prototype.withAgeAndGender=function(){return new ln(this,this.input)},g}(Vr),Un=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withAgeAndGender=function(){return new dn(this,this.input)},g.prototype.withFaceDescriptors=function(){return new fn(this,this.input)},g}(sn),Gn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Jn(this,this.input)},g}(un),xr=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.extractedFaces=w,C}return g}(qC),hn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w=this;return HA(this,function(C){switch(C.label){case 0:return[4,this.parentTask];case 1:return B=C.sent(),[4,Ve(B,this.input,function(E){return dA(w,void 0,void 0,function(){return HA(this,function(e){switch(e.label){case 0:return[4,Promise.all(E.map(function(I){return Ig.ageGenderNet.predictAgeAndGender(I)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return Q=C.sent(),[2,B.map(function(E,e){var I=Q[e],o=I.age,n=I.gender,i=I.genderProbability;return jr(pr(E,n,i),o)})]}})})},g.prototype.withFaceExpressions=function(){return new sn(this,this.input)},g}(xr),ln=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E;return HA(this,function(e){switch(e.label){case 0:return[4,this.parentTask];case 1:return B=e.sent(),B?[4,Dn(B,this.input,function(I){return Ig.ageGenderNet.predictAgeAndGender(I)},this.extractedFaces)]:[2];case 2:return Q=e.sent(),w=Q.age,C=Q.gender,E=Q.genderProbability,[2,jr(pr(B,C,E),w)]}})})},g.prototype.withFaceExpressions=function(){return new un(this,this.input)},g}(xr),dn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withFaceExpressions=function(){return new Un(this,this.input)},g.prototype.withFaceDescriptors=function(){return new fn(this,this.input)},g}(hn),Hn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Jn(this,this.input)},g}(ln),Xr=function(A){yA(g,A);function g(B,Q){var w=A.call(this)||this;return w.parentTask=B,w.input=Q,w}return g}(qC),fn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),[4,Ve(B,this.input,function(C){return Promise.all(C.map(function(E){return Ig.faceRecognitionNet.computeFaceDescriptor(E)}))},null,function(C){return C.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return Q=w.sent(),[2,Q.map(function(C,E){return Tr(B[E],C)})]}})})},g.prototype.withFaceExpressions=function(){return new Un(this,this.input)},g.prototype.withAgeAndGender=function(){return new dn(this,this.input)},g}(Xr),Jn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),B?[4,Dn(B,this.input,function(C){return Ig.faceRecognitionNet.computeFaceDescriptor(C)},null,function(C){return C.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return Q=w.sent(),[2,Tr(B,Q)]}})})},g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g}(Xr),Or=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.useTinyLandmarkNet=w,C}return Object.defineProperty(g.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?Ig.faceLandmark68TinyNet:Ig.faceLandmark68Net},enumerable:!0,configurable:!0}),g}(qC),XP=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e=this;return HA(this,function(I){switch(I.label){case 0:return[4,this.parentTask];case 1:return B=I.sent(),Q=B.map(function(o){return o.detection}),this.input instanceof uB?[4,wn(this.input,Q)]:[3,3];case 2:return C=I.sent(),[3,5];case 3:return[4,pe(this.input,Q)];case 4:C=I.sent(),I.label=5;case 5:return w=C,[4,Promise.all(w.map(function(o){return e.landmarkNet.detectLandmarks(o)}))];case 6:return E=I.sent(),w.forEach(function(o){return o instanceof uB&&o.dispose()}),[2,B.map(function(o,n){return We(o,E[n])})]}})})},g.prototype.withFaceExpressions=function(){return new Un(this,this.input)},g.prototype.withAgeAndGender=function(){return new dn(this,this.input)},g.prototype.withFaceDescriptors=function(){return new fn(this,this.input)},g}(Or),OP=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E;return HA(this,function(e){switch(e.label){case 0:return[4,this.parentTask];case 1:return B=e.sent(),B?(Q=B.detection,this.input instanceof uB?[4,wn(this.input,[Q])]:[3,3]):[2];case 2:return C=e.sent(),[3,5];case 3:return[4,pe(this.input,[Q])];case 4:C=e.sent(),e.label=5;case 5:return w=C,[4,this.landmarkNet.detectLandmarks(w[0])];case 6:return E=e.sent(),w.forEach(function(I){return I instanceof uB&&I.dispose()}),[2,We(B,E)]}})})},g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Jn(this,this.input)},g}(Or),Zr=function(A){yA(g,A);function g(B,Q){Q===void 0&&(Q=new be);var w=A.call(this)||this;return w.input=B,w.options=Q,w}return g}(qC),qr=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C;return HA(this,function(E){switch(E.label){case 0:return B=this,Q=B.input,w=B.options,w instanceof yr?[4,Ig.mtcnn.forward(Q,w)]:[3,2];case 1:return[2,E.sent().map(function(e){return e.detection})];case 2:if(C=w instanceof Lr?function(e){return Ig.tinyFaceDetector.locateFaces(e,w)}:w instanceof be?function(e){return Ig.ssdMobilenetv1.locateFaces(e,w)}:w instanceof cn?function(e){return Ig.tinyYolov2.locateFaces(e,w)}:null,!C)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,C(Q)]}})})},g.prototype.runAndExtendWithFaceDetections=function(){var B=this;return new Promise(function(Q){return dA(B,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.run()];case 1:return w=C.sent(),[2,Q(w.map(function(E){return ZC({},E)}))]}})})})},g.prototype.withFaceLandmarks=function(B){return B===void 0&&(B=!1),new XP(this.runAndExtendWithFaceDetections(),this.input,B)},g.prototype.withFaceExpressions=function(){return new sn(this.runAndExtendWithFaceDetections(),this.input)},g.prototype.withAgeAndGender=function(){return new hn(this.runAndExtendWithFaceDetections(),this.input)},g}(Zr);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,new qr(this.input,this.options)];case 1:return B=w.sent(),Q=B[0],B.forEach(function(C){C.score>Q.score&&(Q=C)}),[2,Q]}})})},g.prototype.runAndExtendWithFaceDetection=function(){var B=this;return new Promise(function(Q){return dA(B,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.run()];case 1:return w=C.sent(),[2,Q(w?ZC({},w):void 0)]}})})})},g.prototype.withFaceLandmarks=function(B){return B===void 0&&(B=!1),new OP(this.runAndExtendWithFaceDetection(),this.input,B)},g.prototype.withFaceExpressions=function(){return new un(this.runAndExtendWithFaceDetection(),this.input)},g.prototype.withAgeAndGender=function(){return new ln(this.runAndExtendWithFaceDetection(),this.input)},g})(Zr);function ZP(A,g){return g===void 0&&(g=new be),new qr(A,g)}function qP(A,g){if(A.length!==g.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var B=Array.from(A),Q=Array.from(g);return Math.sqrt(B.map(function(w,C){return w-Q[C]}).reduce(function(w,C){return w+Math.pow(C,2)},0))}(function(){function A(g,B){B===void 0&&(B=.6),this._distanceThreshold=B;var Q=Array.isArray(g)?g:[g];if(!Q.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var w=1,C=function(){return"person "+w++};this._labeledDescriptors=Q.map(function(E){if(E instanceof ve)return E;if(E instanceof Float32Array)return new ve(C(),[E]);if(E.descriptor&&E.descriptor instanceof Float32Array)return new ve(C(),[E.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>")})}return Object.defineProperty(A.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),A.prototype.computeMeanDistance=function(g,B){return B.map(function(Q){return qP(Q,g)}).reduce(function(Q,w){return Q+w},0)/(B.length||1)},A.prototype.matchDescriptor=function(g){var B=this;return this.labeledDescriptors.map(function(Q){var w=Q.descriptors,C=Q.label;return new tr(C,B.computeMeanDistance(g,w))}).reduce(function(Q,w){return Q.distance<w.distance?Q:w})},A.prototype.findBestMatch=function(g){var B=this.matchDescriptor(g);return B.distance<this.distanceThreshold?B:new tr("unknown",B.distance)},A.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(g){return g.toJSON()})}},A.fromJSON=function(g){var B=g.labeledDescriptors.map(function(Q){return ve.fromJSON(Q)});return new A(B,g.distanceThreshold)},A})();function _r(A,g){var B=new Yw(g.width,g.height),Q=B.width,w=B.height;if(Q<=0||w<=0)throw new Error("resizeResults - invalid dimensions: "+JSON.stringify({width:Q,height:w}));if(Array.isArray(A))return A.map(function(e){return _r(e,{width:Q,height:w})});if(tn(A)){var C=A.detection.forSize(Q,w),E=A.unshiftedLandmarks.forSize(C.box.width,C.box.height);return We(ZC(A,C),E)}return OC(A)?ZC(A,A.detection.forSize(Q,w)):A instanceof AC||A instanceof Jg?A.forSize(Q,w):A}class _P{getVideoStreamConfig(g,B){return{audio:!1,video:{width:{min:g,ideal:g},height:{min:B,ideal:B},facingMode:"environment"}}}getContourCoordinate(g,B){return{x:g*.25,y:B*.05,width:g*.5,height:B*.9}}getBoxData(g){return g?{x:g.x,y:g.y,width:g.width,height:g.height}:null}setStylesForCanvas(g){g.width="100%",g.height="100%",g.style.position="absolute",g.style.top="0",g.style.left="0"}checkFaceInclusion(g,B){if(!g||!B||B.width>g.width||B.height>g.height)return!1;const Q=B.x,w=B.x+B.width,C=B.y,E=B.y+B.height,e=g.x,I=g.x+g.width,o=g.y,n=g.y+g.height;return Q>=e&&w<=I&&C>=o&&E<=n}async getFaceDetections(g){return g?ZP(g,new Lr).withFaceLandmarks().withFaceExpressions():[]}getCanvas(g){return Te(g)}getResizedAndDetection(g,B,Q,w,C){dR(g,{width:w,height:C});const E=_r(B,{width:w,height:C});Q.clearRect(0,0,w,C),aR(g,E),TR(g,E),PR(g,E)}async getFaceSnapshot(g,B){const Q=[new Pe(B.x,B.y,B.width,B.height)],w=await pe(g,Q);return w.length?w[0].toDataURL("image/jpeg").replace(/^data:image\/\w+;base64,/,""):null}async initModels(){let g=new Date;console.log(g);try{await Promise.all([Ig.tinyFaceDetector.loadFromUri("/models"),Ig.faceLandmark68Net.loadFromUri("/models"),Ig.faceRecognitionNet.loadFromUri("/models"),Ig.faceExpressionNet.loadFromUri("/models")])}catch(B){console.error(B)}g=new Date,console.log(g)}}let Nn;function $P(){return Nn||(Nn=new _P),Nn}class Av extends Gg{async fetchUserInstrumentsHistory(g,B){const Q={status:"issued",page:B,desc:"desc",column:"updated_at"};return await this.get(`users/${g}/instruments`,{params:Q})}}let mn;function Bv(){return mn||(mn=new Av),mn}class gv extends Gg{fetchControlZones(g){return this.get("/frame/list",{params:g})}async fetchControlZone(g){return this.get(`/frame/${g}`)}createControlZone(g){return this.post("/frame",g)}editControlZone(g,B){return this.put(`/frame/${g}`,B)}deleteControlZone(g){return this.delete(`/frame/${g}`)}fetchControlLogs(g){return this.get("/exposed_equipment_zones/list",{params:g})}fetchControllers(g){return this.get("/frame/controllers/list",{params:g})}fetchUsersWithPasses(){return this.get("inspector/users-with-passes")}fetchWarehousesList(){return this.get("tasks/warehouse/list?only_outside_exposed_equipment_zone=1")}manualEntry(g){return this.post("exposed_equipment_zones/hand/enter",g)}manualExit(g){return this.post("exposed_equipment_zones/hand/exit",g)}deleteControlLogs(g){return this.delete("exposed_equipment_zones",g)}fetchInstrumentTypeList(g){return this.get("search/instrument_types",{params:g})}}let Rn;function Qv(){return Rn||(Rn=new gv),Rn}class wv extends Gg{fetchSearchUsers(g){return this.get("search/users",{params:g})}}let Pn;function Cv(){return Pn||(Pn=new wv),Pn}class Ev extends Gg{async fetchTaskById(g){return await this.get(`/tasks/${g}`)}async fetchTasksList(g){return await this.get("/list/tasks/search",{params:g})}async fetchSubtasksList(g){return await this.get(`/task/${g}/subtasks/list`)}async fetchTaskBranch(g){return await this.get(`/get_list_task_branch?task_id=${g}`)}async fetchInstrumentsList(g){return await this.get("admin/instruments",{params:g})}async fetchInstrumentTypeListWithPreparedWarehouse(g){return await this.get("/instrument_type/get_instrument_type_list_with_prepared_warehouse",{params:g})}async fetchInstrumentsEquivalentList(g){return await this.get("tasks/instrument/list",{params:g})}async fetchDiffInstruments(g){return await this.get(`tasks/${g.taskId}/fill/module`,{params:g})}async replaceInstruments(g){return await this.post("/instruments/equivalent/attach",g)}async fetchTaskUsagePersonal(g){return await this.get(`tasks/${g.taskId}/usage/users`,{params:g})}async fetchTaskUsageInstrument(g){return await this.get(`tasks/${g.taskId}/usage/instruments`,{params:g})}fetchEquipment(g){return this.get("repairs/equipment/list",{params:g})}fetchTaskVideoSources(g){return this.get("work_zone/get_list_video_source",{params:g})}fetchTaskVideoSourcesStream(g){return this.get("horizon/video-source",{params:g})}createWorkZone(g){return this.post("admin/work-zones",g)}async createTask(g){return await this.post("tasks",g)}async editTask(g){return await this.put(`tasks/${g.taskId}`,g.data)}async mergeTask(g){return await this.post("tasks/merge",g)}async deleteTask(g){return await this.delete(`tasks/${g}`)}async changeStatus(g){const{taskId:B,data:Q}=g;return await this.put(`task/${B}/change-status`,Q)}async uploadComment(g){return await this.post("comments",g)}async deleteComment(g){return await this.delete(`comments/${g}`)}async editComment(g){const{commentId:B,data:Q}=g;return await this.put(`comments/${B}`,Q)}async saveMetrics(g){return await this.put("/update_quality_metrics",g)}async checkReasonForStatus(g){return await this.post("/tasks/check_reason_for_task",g)}async verifyTaskStatus(g){const{task_id:B,data:Q}=g;return await this.get(`/task/${B}/change-status/verification`,{params:Q})}async checkBranchBeforeCloseTask(g){return await this.post("/check_branch_before_close_task",g)}}let vn;function ev(){return vn||(vn=new Ev),vn}function Iv(A){const g=t.ref(""),B=t.ref(1),Q=async(E="",e=1)=>{await A.initialize({search:E,page:e})},w=async E=>{g.value=E,B.value=1,await Q(E,B.value)},C=async E=>{B.value=E,await Q(g.value,E)};return t.watch(()=>A.columnFilters.value,()=>Q(g.value,B.value),{deep:!0}),t.onMounted(()=>Q(g.value,B.value)),{search:g,currentPage:B,loading:A.loading,handleSearch:w,handlePageChange:C,loadTable:Q}}const ov=A=>{const g=t.ref({}),B=t.ref({});A.columns.forEach(({name:I,filterType:o})=>{o&&(g.value[I]=o==="multi"?[]:void 0,B.value[I]=!1)});const Q=t.computed(()=>Array.isArray(A.rows)?A.rows:A.rows.value),w=(I,o)=>{const n=A.columns.find(i=>i.name===I);if((n==null?void 0:n.filterType)==="multi"){const i=g.value[I],Y=i.indexOf(o);Y>-1?i.splice(Y,1):i.push(o),g.value[I]=[...i]}else g.value[I]=o,B.value[I]=!1},C=t.computed(()=>{var o;const I={};for(const n of A.columns){const i=g.value[n.name],Y=((o=A.filtersOptions)==null?void 0:o.value[n.name])||[];i&&(I[n.name]=Array.isArray(i)?Y.filter(M=>i.includes(M.name)).map(M=>M.id):Y.filter(M=>M.name===i).map(M=>M.id))}return I}),E=I=>{const o=A.columns.find(n=>n.name===I);g.value[I]=(o==null?void 0:o.filterType)==="multi"?[]:void 0},e=(I,o)=>{B.value[I]=o};return{rows:Q,columns:t.computed(()=>A.columns),columnFilters:g,filterMenus:B,toggleFilterValue:w,clearFilter:E,openFilterMenu:e,selectedFilters:C}};function tv(A,g=[]){const B=t.ref([...new Set([...g,...A.map(C=>C.name)])]),Q=t.computed(()=>A.filter(C=>B.value.includes(C.name)));function w(C){C.dialog({title:"Выберите колонки",options:{type:"checkbox",model:[...B.value],items:A.map(E=>({label:E.label,value:E.name,disable:g.includes(E.name)}))},cancel:!0,persistent:!0}).onOk(E=>{B.value=Array.from(new Set([...E,...g]))})}return{selectedColumnNames:B,visibleColumns:Q,openColumnSelectorDialog:w}}fA.ApiService=Gg,fA.AppButton=ME,fA.AppCheckbox=$F,fA.AppConfirmDialog=lG,fA.AppDatePicker=ua,fA.AppDatepicker=Oa,fA.AppDropdown=NG,fA.AppInput=Za,fA.AppInputNew=DY,fA.AppInputSearch=qa,fA.AppLayout=gs,fA.AppLayoutHeader=pU,fA.AppLayoutPage=WU,fA.AppLoader=uY,fA.AppModalSelect=pY,fA.AppSelect=XU,fA.AppSheet=gG,fA.AppSidebar=oG,fA.AppTable=OY,fA.AppTableLayout=zh,fA.AppTableModal=VG,fA.AppTablePagination=TY,fA.AppTableSearch=jY,fA.AppToggle=tG,fA.AppWrapper=MG,fA.base64ToBlob=ba,fA.isEqual=fE,fA.normalizeValue=Nw,fA.notificationSettings=VI,fA.useAuthService=ad,fA.useBaseTable=Iv,fA.useColumnSelector=tv,fA.useControlsService=Qv,fA.useFileService=ud,fA.useGanttService=nd,fA.useInstrumentsService=Bv,fA.useMetricsService=Yd,fA.usePhotoService=$P,fA.useProjectsService=cd,fA.useRepairsService=rd,fA.useSearchService=Cv,fA.useTableModel=ov,fA.useTasksService=ev,fA.useUserService=ld,fA.useVideoService=Gd,fA.uuidv4=KI,Object.defineProperty(fA,Symbol.toStringTag,{value:"Module"})});
3834
+ ***************************************************************************** */var qt=function(A,g){return qt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(B,Q){B.__proto__=Q}||function(B,Q){for(var w in Q)Q.hasOwnProperty(w)&&(B[w]=Q[w])},qt(A,g)};function yA(A,g){qt(A,g);function B(){this.constructor=A}A.prototype=g===null?Object.create(g):(B.prototype=g.prototype,new B)}var Eg=function(){return Eg=Object.assign||function(g){for(var B,Q=1,w=arguments.length;Q<w;Q++){B=arguments[Q];for(var C in B)Object.prototype.hasOwnProperty.call(B,C)&&(g[C]=B[C])}return g},Eg.apply(this,arguments)};function dA(A,g,B,Q){function w(C){return C instanceof B?C:new B(function(E){E(C)})}return new(B||(B=Promise))(function(C,E){function e(n){try{o(Q.next(n))}catch(i){E(i)}}function I(n){try{o(Q.throw(n))}catch(i){E(i)}}function o(n){n.done?C(n.value):w(n.value).then(e,I)}o((Q=Q.apply(A,[])).next())})}function HA(A,g){var B={label:0,sent:function(){if(C[0]&1)throw C[1];return C[1]},trys:[],ops:[]},Q,w,C,E;return E={next:e(0),throw:e(1),return:e(2)},typeof Symbol=="function"&&(E[Symbol.iterator]=function(){return this}),E;function e(o){return function(n){return I([o,n])}}function I(o){if(Q)throw new TypeError("Generator is already executing.");for(;B;)try{if(Q=1,w&&(C=o[0]&2?w.return:o[0]?w.throw||((C=w.return)&&C.call(w),0):w.next)&&!(C=C.call(w,o[1])).done)return C;switch(w=0,C&&(o=[o[0]&2,C.value]),o[0]){case 0:case 1:C=o;break;case 4:return B.label++,{value:o[1],done:!1};case 5:B.label++,w=o[1],o=[0];continue;case 7:o=B.ops.pop(),B.trys.pop();continue;default:if(C=B.trys,!(C=C.length>0&&C[C.length-1])&&(o[0]===6||o[0]===2)){B=0;continue}if(o[0]===3&&(!C||o[1]>C[0]&&o[1]<C[3])){B.label=o[1];break}if(o[0]===6&&B.label<C[1]){B.label=C[1],C=o;break}if(C&&B.label<C[2]){B.label=C[2],B.ops.push(o);break}C[2]&&B.ops.pop(),B.trys.pop();continue}o=g.call(A,B)}catch(n){o=[6,n],w=0}finally{Q=C=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function KC(){for(var A=0,g=0,B=arguments.length;g<B;g++)A+=arguments[g].length;for(var Q=Array(A),w=0,g=0;g<B;g++)for(var C=arguments[g],E=0,e=C.length;E<e;E++,w++)Q[w]=C[E];return Q}var Yw=function(){function A(g,B){if(!Mw(g)||!Mw(B))throw new Error("Dimensions.constructor - expected width and height to be valid numbers, instead have "+JSON.stringify({width:g,height:B}));this._width=g,this._height=B}return Object.defineProperty(A.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),A.prototype.reverse=function(){return new A(1/this.width,1/this.height)},A}();function Ne(A,g){return A instanceof uB&&A.shape.length===g}function eR(A){return Ne(A,2)}function me(A){return Ne(A,3)}function jQ(A){return Ne(A,4)}function IR(A){return A%1!==0}function Cr(A){return A%2===0}function _t(A,g){g===void 0&&(g=2);var B=Math.pow(10,g);return Math.floor(A*B)/B}function Er(A){return A&&A.width&&A.height}function oR(A,g){var B=A.width,Q=A.height,w=g/Math.max(Q,B);return new Yw(Math.round(B*w),Math.round(Q*w))}function $t(A){return A.reduce(function(g,B){return g.add(B)},new QB(0,0)).div(new QB(A.length,A.length))}function VC(A,g,B){return Array(A).fill(0).map(function(Q,w){return g+w*B})}function Mw(A){return!!A&&A!==1/0&&A!==-1/0&&!isNaN(A)||A===0}function er(A){return Mw(A)&&0<=A&&A<=1}var QB=function(){function A(g,B){this._x=g,this._y=B}return Object.defineProperty(A.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),A.prototype.add=function(g){return new A(this.x+g.x,this.y+g.y)},A.prototype.sub=function(g){return new A(this.x-g.x,this.y-g.y)},A.prototype.mul=function(g){return new A(this.x*g.x,this.y*g.y)},A.prototype.div=function(g){return new A(this.x/g.x,this.y/g.y)},A.prototype.abs=function(){return new A(Math.abs(this.x),Math.abs(this.y))},A.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},A.prototype.floor=function(){return new A(Math.floor(this.x),Math.floor(this.y))},A}(),wQ=function(){function A(g,B){B===void 0&&(B=!0);var Q=g||{},w=[Q.left,Q.top,Q.right,Q.bottom].every(Mw),C=[Q.x,Q.y,Q.width,Q.height].every(Mw);if(!C&&!w)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(Q));var E=C?[Q.x,Q.y,Q.width,Q.height]:[Q.left,Q.top,Q.right-Q.left,Q.bottom-Q.top],e=E[0],I=E[1],o=E[2],n=E[3];A.assertIsValidBox({x:e,y:I,width:o,height:n},"Box.constructor",B),this._x=e,this._y=I,this._width=o,this._height=n}return A.isRect=function(g){return!!g&&[g.x,g.y,g.width,g.height].every(Mw)},A.assertIsValidBox=function(g,B,Q){if(Q===void 0&&(Q=!1),!A.isRect(g))throw new Error(B+" - invalid box: "+JSON.stringify(g)+", expected object with properties x, y, width, height");if(!Q&&(g.width<0||g.height<0))throw new Error(B+" - width ("+g.width+") and height ("+g.height+") must be positive numbers")},Object.defineProperty(A.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"topLeft",{get:function(){return new QB(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"topRight",{get:function(){return new QB(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottomLeft",{get:function(){return new QB(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"bottomRight",{get:function(){return new QB(this.right,this.bottom)},enumerable:!0,configurable:!0}),A.prototype.round=function(){var g=[this.x,this.y,this.width,this.height].map(function(E){return Math.round(E)}),B=g[0],Q=g[1],w=g[2],C=g[3];return new A({x:B,y:Q,width:w,height:C})},A.prototype.floor=function(){var g=[this.x,this.y,this.width,this.height].map(function(E){return Math.floor(E)}),B=g[0],Q=g[1],w=g[2],C=g[3];return new A({x:B,y:Q,width:w,height:C})},A.prototype.toSquare=function(){var g=this,B=g.x,Q=g.y,w=g.width,C=g.height,E=Math.abs(w-C);return w<C&&(B-=E/2,w+=E),C<w&&(Q-=E/2,C+=E),new A({x:B,y:Q,width:w,height:C})},A.prototype.rescale=function(g){var B=Er(g)?g.width:g,Q=Er(g)?g.height:g;return new A({x:this.x*B,y:this.y*Q,width:this.width*B,height:this.height*Q})},A.prototype.pad=function(g,B){var Q=[this.x-g/2,this.y-B/2,this.width+g,this.height+B],w=Q[0],C=Q[1],E=Q[2],e=Q[3];return new A({x:w,y:C,width:E,height:e})},A.prototype.clipAtImageBorders=function(g,B){var Q=this,w=Q.x,C=Q.y,E=Q.right,e=Q.bottom,I=Math.max(w,0),o=Math.max(C,0),n=E-I,i=e-o,Y=Math.min(n,g-I),M=Math.min(i,B-o);return new A({x:I,y:o,width:Y,height:M}).floor()},A.prototype.shift=function(g,B){var Q=this,w=Q.width,C=Q.height,E=this.x+g,e=this.y+B;return new A({x:E,y:e,width:w,height:C})},A.prototype.padAtBorders=function(g,B){var Q=this.width+1,w=this.height+1,C=1,E=1,e=Q,I=w,o=this.left,n=this.top,i=this.right,Y=this.bottom;return i>B&&(e=-i+B+Q,i=B),Y>g&&(I=-Y+g+w,Y=g),o<1&&(I=2-o,o=1),n<1&&(I=2-n,n=1),{dy:E,edy:I,dx:C,edx:e,y:n,ey:Y,x:o,ex:i,w:Q,h:w}},A.prototype.calibrate=function(g){return new A({left:this.left+g.left*this.width,top:this.top+g.top*this.height,right:this.right+g.right*this.width,bottom:this.bottom+g.bottom*this.height}).toSquare().round()},A}(),Re=function(A){yA(g,A);function g(B,Q,w,C,E){return E===void 0&&(E=!1),A.call(this,{left:B,top:Q,right:w,bottom:C},E)||this}return g}(wQ),Ir=function(){function A(g,B,Q,w,C){this._imageDims=new Yw(C.width,C.height),this._score=g,this._classScore=B,this._className=Q,this._box=new wQ(w).rescale(this._imageDims)}return Object.defineProperty(A.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"relativeBox",{get:function(){return new wQ(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),A.prototype.forSize=function(g,B){return new A(this.score,this.classScore,this.className,this.relativeBox,{width:g,height:B})},A}(),Jg=function(A){yA(g,A);function g(B,Q,w){return A.call(this,B,B,"",Q,w)||this}return g.prototype.forSize=function(B,Q){var w=A.prototype.forSize.call(this,B,Q),C=w.score,E=w.relativeBox,e=w.imageDims;return new g(C,E,e)},g}(Ir);function tR(A,g,B){B===void 0&&(B=!0);var Q=Math.max(0,Math.min(A.right,g.right)-Math.max(A.left,g.left)),w=Math.max(0,Math.min(A.bottom,g.bottom)-Math.max(A.top,g.top)),C=Q*w;return B?C/(A.area+g.area-C):C/Math.min(A.area,g.area)}function nR(A){var g=A.map(function(e){return e.x}),B=A.map(function(e){return e.y}),Q=g.reduce(function(e,I){return I<e?I:e},1/0),w=B.reduce(function(e,I){return I<e?I:e},1/0),C=g.reduce(function(e,I){return e<I?I:e},0),E=B.reduce(function(e,I){return e<I?I:e},0);return new Re(Q,w,C,E)}function xC(A,g,B,Q){Q===void 0&&(Q=!0);for(var w=g.map(function(e,I){return{score:e,boxIndex:I}}).sort(function(e,I){return e.score-I.score}).map(function(e){return e.boxIndex}),C=[],E=function(){var e=w.pop();C.push(e);for(var I=w,o=[],n=0;n<I.length;n++){var i=I[n],Y=A[e],M=A[i];o.push(tR(Y,M,Q))}w=w.filter(function(c,D){return o[D]<=B})};w.length>0;)E();return C}function XC(A,g){return DA(function(){var B=g[0],Q=g[1],w=g[2],C=gQ(KC(A.shape.slice(0,3),[1]),B),E=gQ(KC(A.shape.slice(0,3),[1]),Q),e=gQ(KC(A.shape.slice(0,3),[1]),w),I=jB([C,E,e],3);return zB(A,I)})}function iR(A,g){return g===void 0&&(g=!1),DA(function(){var B=A.shape.slice(1),Q=B[0],w=B[1];if(Q===w)return A;var C=Math.abs(Q-w),E=Math.round(C*(g?.5:1)),e=Q>w?2:1,I=function(M){var c=A.shape.slice();return c[e]=M,gQ(c,0)},o=I(E),n=C-o.shape[e],i=g&&n?I(n):null,Y=[i,A,o].filter(function(M){return!!M}).map(function(M){return M.toFloat()});return jB(Y,e)})}function An(A){return 1/(1+Math.exp(-A))}var Pe=function(A){yA(g,A);function g(B,Q,w,C,E){return E===void 0&&(E=!1),A.call(this,{x:B,y:Q,width:w,height:C},E)||this}return g}(wQ),YR=.5,MR=.43,cR=.45,AC=function(){function A(g,B,Q){Q===void 0&&(Q=new QB(0,0));var w=B.width,C=B.height;this._imgDims=new Yw(w,C),this._shift=Q,this._positions=g.map(function(E){return E.mul(new QB(w,C)).add(Q)})}return Object.defineProperty(A.prototype,"shift",{get:function(){return new QB(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"relativePositions",{get:function(){var g=this;return this._positions.map(function(B){return B.sub(g._shift).div(new QB(g.imageWidth,g.imageHeight))})},enumerable:!0,configurable:!0}),A.prototype.forSize=function(g,B){return new this.constructor(this.relativePositions,{width:g,height:B})},A.prototype.shiftBy=function(g,B){return new this.constructor(this.relativePositions,this._imgDims,new QB(g,B))},A.prototype.shiftByPoint=function(g){return this.shiftBy(g.x,g.y)},A.prototype.align=function(g,B){if(B===void 0&&(B={}),g){var Q=g instanceof Jg?g.box.floor():new wQ(g);return this.shiftBy(Q.x,Q.y).align(null,B)}var w=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},B),C=w.useDlibAlignment,E=w.minBoxPadding;return C?this.alignDlib():this.alignMinBbox(E)},A.prototype.alignDlib=function(){var g=this.getRefPointsForAlignment(),B=g[0],Q=g[1],w=g[2],C=function(i){return w.sub(i).magnitude()},E=(C(B)+C(Q))/2,e=Math.floor(E/cR),I=$t(g),o=Math.floor(Math.max(0,I.x-YR*e)),n=Math.floor(Math.max(0,I.y-MR*e));return new Pe(o,n,Math.min(e,this.imageWidth+o),Math.min(e,this.imageHeight+n))},A.prototype.alignMinBbox=function(g){var B=nR(this.positions);return B.pad(B.width*g,B.height*g)},A.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},A}(),DR=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.getRefPointsForAlignment=function(){var B=this.positions;return[B[0],B[1],$t([B[3],B[4]])]},g}(AC),or=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.getJawOutline=function(){return this.positions.slice(0,17)},g.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},g.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},g.prototype.getNose=function(){return this.positions.slice(27,36)},g.prototype.getLeftEye=function(){return this.positions.slice(36,42)},g.prototype.getRightEye=function(){return this.positions.slice(42,48)},g.prototype.getMouth=function(){return this.positions.slice(48,68)},g.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map($t)},g}(AC),tr=function(){function A(g,B){this._label=g,this._distance=B}return Object.defineProperty(A.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),A.prototype.toString=function(g){return g===void 0&&(g=!0),""+this.label+(g?" ("+_t(this.distance)+")":"")},A}(),nr=function(A){yA(g,A);function g(B,Q){var w=A.call(this,B)||this;return w._label=Q,w}return g.assertIsValidLabeledBox=function(B,Q){if(wQ.assertIsValidBox(B,Q),!Mw(B.label))throw new Error(Q+" - expected property label ("+B.label+") to be a number")},Object.defineProperty(g.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),g}(wQ),ve=function(){function A(g,B){if(typeof g!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(B)||B.some(function(Q){return!(Q instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=g,this._descriptors=B}return Object.defineProperty(A.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),A.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(g){return Array.from(g)})}},A.fromJSON=function(g){var B=g.descriptors.map(function(Q){return new Float32Array(Q)});return new A(g.label,B)},A}();(function(A){yA(g,A);function g(B,Q,w,C){var E=A.call(this,B,Q)||this;return E._score=w,E._classScore=C,E}return g.assertIsValidPredictedBox=function(B,Q){if(nr.assertIsValidLabeledBox(B,Q),!er(B.score)||!er(B.classScore))throw new Error(Q+" - expected properties score ("+B.score+") and ("+B.classScore+") to be a number between [0, 1]")},Object.defineProperty(g.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),g})(nr);function OC(A){return A.detection instanceof Jg}function ZC(A,g){var B={detection:g};return Object.assign({},A,B)}function ir(){var A=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},g=function(){throw new Error("readFile - filesystem not available for browser environment")};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement("canvas")},createImageElement:function(){return document.createElement("img")},fetch:A,readFile:g}}function Yr(A){var g="";if(!A)try{A=require("fs")}catch(Q){g=Q.toString()}var B=A?function(Q){return new Promise(function(w,C){A.readFile(Q,function(E,e){return E?C(E):w(e)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+g)};return{readFile:B}}function Mr(){var A=global.Canvas||global.HTMLCanvasElement,g=global.Image||global.HTMLImageElement,B=function(){if(A)return new A;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},Q=function(){if(g)return new g;throw new Error("createImageElement - missing Image implementation for nodejs environment")},w=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},C=Yr();return Eg({Canvas:A||function(){function E(){}return E}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function E(){}return E}(),Image:g||function(){function E(){}return E}(),ImageData:global.ImageData||function(){function E(){}return E}(),Video:global.HTMLVideoElement||function(){function E(){}return E}(),createCanvasElement:B,createImageElement:Q,fetch:w},C)}function cr(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function Dr(){return typeof global=="object"&&typeof require=="function"&&typeof module<"u"&&typeof process<"u"&&!!process.version}var WB;function rR(){if(!WB)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return WB}function Bn(A){WB=A}function gn(){cr()&&Bn(ir()),Dr()&&Bn(Mr())}function FR(A){if(WB||gn(),!WB)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var g=A.Canvas,B=g===void 0?WB.Canvas:g,Q=A.Image,w=Q===void 0?WB.Image:Q;WB.Canvas=B,WB.Image=w,WB.createCanvasElement=A.createCanvasElement||function(){return new B},WB.createImageElement=A.createImageElement||function(){return new w},WB.ImageData=A.ImageData||WB.ImageData,WB.Video=A.Video||WB.Video,WB.fetch=A.fetch||WB.fetch,WB.readFile=A.readFile||WB.readFile}var eg={getEnv:rR,setEnv:Bn,initialize:gn,createBrowserEnv:ir,createFileSystem:Yr,createNodejsEnv:Mr,monkeyPatch:FR,isBrowser:cr,isNodejs:Dr};gn();function Qn(A){return!eg.isNodejs()&&typeof A=="string"?document.getElementById(A):A}function CQ(A){var g=eg.getEnv(),B=g.Canvas,Q=g.CanvasRenderingContext2D;if(A instanceof Q)return A;var w=Qn(A);if(!(w instanceof B))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var C=w.getContext("2d");if(!C)throw new Error("resolveContext2d - canvas 2d context is null");return C}var pQ;(function(A){A.TOP_LEFT="TOP_LEFT",A.TOP_RIGHT="TOP_RIGHT",A.BOTTOM_LEFT="BOTTOM_LEFT",A.BOTTOM_RIGHT="BOTTOM_RIGHT"})(pQ||(pQ={}));var rr=function(){function A(g){g===void 0&&(g={});var B=g.anchorPosition,Q=g.backgroundColor,w=g.fontColor,C=g.fontSize,E=g.fontStyle,e=g.padding;this.anchorPosition=B||pQ.TOP_LEFT,this.backgroundColor=Q||"rgba(0, 0, 0, 0.5)",this.fontColor=w||"rgba(255, 255, 255, 1)",this.fontSize=C||14,this.fontStyle=E||"Georgia",this.padding=e||4}return A}(),Fr=function(){function A(g,B,Q){Q===void 0&&(Q={}),this.text=typeof g=="string"?[g]:g instanceof A?g.text:g,this.anchor=B,this.options=new rr(Q)}return A.prototype.measureWidth=function(g){var B=this.options.padding;return this.text.map(function(Q){return g.measureText(Q).width}).reduce(function(Q,w){return Q<w?w:Q},0)+2*B},A.prototype.measureHeight=function(){var g=this.options,B=g.fontSize,Q=g.padding;return this.text.length*B+2*Q},A.prototype.getUpperLeft=function(g,B){var Q=this.options.anchorPosition,w=Q===pQ.BOTTOM_RIGHT||Q===pQ.TOP_RIGHT,C=Q===pQ.BOTTOM_LEFT||Q===pQ.BOTTOM_RIGHT,E=this.measureWidth(g),e=this.measureHeight(),I=w?this.anchor.x-E:this.anchor.x,o=C?this.anchor.y-e:this.anchor.y;if(B){var n=B.width,i=B.height,Y=Math.max(Math.min(I,n-E),0),M=Math.max(Math.min(o,i-e),0);return{x:Y,y:M}}return{x:I,y:o}},A.prototype.draw=function(g){var B=Qn(g),Q=CQ(B),w=this.options,C=w.backgroundColor,E=w.fontColor,e=w.fontSize,I=w.fontStyle,o=w.padding;Q.font=e+"px "+I;var n=this.measureWidth(Q),i=this.measureHeight();Q.fillStyle=C;var Y=this.getUpperLeft(Q,B);Q.fillRect(Y.x,Y.y,n,i),Q.fillStyle=E,this.text.forEach(function(M,c){var D=o+Y.x,r=o+Y.y+(c+1)*e;Q.fillText(M,D,r)})},A}(),aR=function(){function A(g){g===void 0&&(g={});var B=g.boxColor,Q=g.lineWidth,w=g.label,C=g.drawLabelOptions;this.boxColor=B||"rgba(0, 0, 255, 1)",this.lineWidth=Q||2,this.label=w;var E={anchorPosition:pQ.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new rr(Object.assign({},E,C))}return A}(),sR=function(){function A(g,B){B===void 0&&(B={}),this.box=new wQ(g),this.options=new aR(B)}return A.prototype.draw=function(g){var B=CQ(g),Q=this.options,w=Q.boxColor,C=Q.lineWidth,E=this.box,e=E.x,I=E.y,o=E.width,n=E.height;B.strokeStyle=w,B.lineWidth=C,B.strokeRect(e,I,o,n);var i=this.options.label;i&&new Fr([i],{x:e-C/2,y:I},this.options.drawLabelOptions).draw(g)},A}();function uR(A,g){var B=Array.isArray(g)?g:[g];B.forEach(function(Q){var w=Q instanceof Jg?Q.score:OC(Q)?Q.detection.score:void 0,C=Q instanceof Jg?Q.box:OC(Q)?Q.detection.box:new wQ(Q),E=w?""+_t(w):void 0;new sR(C,{label:E}).draw(A)})}function ar(A){var g=eg.getEnv(),B=g.Image,Q=g.Video;return A instanceof B&&A.complete||A instanceof Q&&A.readyState>=3}function UR(A){return new Promise(function(g,B){if(A instanceof eg.getEnv().Canvas||ar(A))return g();function Q(C){C.currentTarget&&(C.currentTarget.removeEventListener("load",Q),C.currentTarget.removeEventListener("error",w),g(C))}function w(C){C.currentTarget&&(C.currentTarget.removeEventListener("load",Q),C.currentTarget.removeEventListener("error",w),B(C))}A.addEventListener("load",Q),A.addEventListener("error",w)})}function wn(A){var g=eg.getEnv(),B=g.Image,Q=g.Video;return A instanceof B?new Yw(A.naturalWidth,A.naturalHeight):A instanceof Q?new Yw(A.videoWidth,A.videoHeight):new Yw(A.width,A.height)}function ke(A){var g=A.width,B=A.height,Q=eg.getEnv().createCanvasElement,w=Q();return w.width=g,w.height=B,w}function Te(A,g){var B=eg.getEnv().ImageData;if(!(A instanceof B)&&!ar(A))throw new Error("createCanvasFromMedia - media has not finished loading yet");var Q=wn(A),w=Q.width,C=Q.height,E=ke({width:w,height:C});return A instanceof B?CQ(E).putImageData(A,0,0):CQ(E).drawImage(A,0,0,w,C),E}function GR(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e;return HA(this,function(I){switch(I.label){case 0:return B=eg.getEnv().createCanvasElement(),Q=A.shape.slice(jQ(A)?1:0),w=Q[0],C=Q[1],E=Q[2],e=DA(function(){return A.as3D(w,C,E).toInt()}),[4,Zt.toPixels(e,B)];case 1:return I.sent(),e.dispose(),[2,B]}})})}function sr(A){var g=eg.getEnv(),B=g.Image,Q=g.Canvas,w=g.Video;return A instanceof B||A instanceof Q||A instanceof w}function hR(A,g,B){B===void 0&&(B=!1);var Q=eg.getEnv(),w=Q.Image,C=Q.Canvas;if(!(A instanceof w||A instanceof C))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var E=wn(A),e=g/Math.max(E.height,E.width),I=e*E.width,o=e*E.height,n=ke({width:g,height:g}),i=A instanceof C?A:Te(A),Y=Math.abs(I-o)/2,M=B&&I<o?Y:0,c=B&&o<I?Y:0;return CQ(n).drawImage(i,M,c,I,o),n}var je=function(){function A(g,B){var Q=this;if(B===void 0&&(B=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(g))throw new Error("NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have "+g);this._treatAsBatchInput=B,this._batchSize=g.length,g.forEach(function(w,C){if(me(w)){Q._imageTensors[C]=w,Q._inputDimensions[C]=w.shape;return}if(jQ(w)){var E=w.shape[0];if(E!==1)throw new Error("NetInput - tf.Tensor4D with batchSize "+E+" passed, but not supported in input array");Q._imageTensors[C]=w,Q._inputDimensions[C]=w.shape.slice(1);return}var e=w instanceof eg.getEnv().Canvas?w:Te(w);Q._canvases[C]=e,Q._inputDimensions[C]=[e.height,e.width,3]})}return Object.defineProperty(A.prototype,"imageTensors",{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"canvases",{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"isBatchInput",{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"reshapedInputDimensions",{get:function(){var g=this;return VC(this.batchSize,0,1).map(function(B,Q){return g.getReshapedInputDimensions(Q)})},enumerable:!0,configurable:!0}),A.prototype.getInput=function(g){return this.canvases[g]||this.imageTensors[g]},A.prototype.getInputDimensions=function(g){return this._inputDimensions[g]},A.prototype.getInputHeight=function(g){return this._inputDimensions[g][0]},A.prototype.getInputWidth=function(g){return this._inputDimensions[g][1]},A.prototype.getReshapedInputDimensions=function(g){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var B=this.getInputWidth(g),Q=this.getInputHeight(g);return oR({width:B,height:Q},this.inputSize)},A.prototype.toBatchTensor=function(g,B){var Q=this;return B===void 0&&(B=!0),this._inputSize=g,DA(function(){var w=VC(Q.batchSize,0,1).map(function(E){var e=Q.getInput(E);if(e instanceof uB){var I=jQ(e)?e:e.expandDims();return I=iR(I,B),(I.shape[1]!==g||I.shape[2]!==g)&&(I=Rt.resizeBilinear(I,[g,g])),I.as3D(g,g,3)}if(e instanceof eg.getEnv().Canvas)return Zt.fromPixels(hR(e,g,B));throw new Error("toBatchTensor - at batchIdx "+E+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+e)}),C=Hg(w.map(function(E){return E.toFloat()})).as4D(Q.batchSize,g,g,3);return C})},A}();function xB(A){return dA(this,void 0,void 0,function(){var g,B,Q;return HA(this,function(w){switch(w.label){case 0:if(A instanceof je)return[2,A];if(g=Array.isArray(A)?A:[A],!g.length)throw new Error("toNetInput - empty array passed as input");return B=function(C){return Array.isArray(A)?" at input index "+C+":":""},Q=g.map(Qn),Q.forEach(function(C,E){if(!sr(C)&&!me(C)&&!jQ(C))throw typeof g[E]=="string"?new Error("toNetInput -"+B(E)+" string passed, but could not resolve HTMLElement for element id "+g[E]):new Error("toNetInput -"+B(E)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(jQ(C)){var e=C.shape[0];if(e!==1)throw new Error("toNetInput -"+B(E)+" tf.Tensor4D with batchSize "+e+" passed, but not supported in input array")}}),[4,Promise.all(Q.map(function(C){return sr(C)&&UR(C)}))];case 1:return w.sent(),[2,new je(Q,Array.isArray(A))]}})})}function pe(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I;return HA(this,function(o){switch(o.label){case 0:return B=eg.getEnv().Canvas,Q=A,A instanceof B?[3,5]:[4,xB(A)];case 1:if(w=o.sent(),w.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return C=w.getInput(0),C instanceof B?(E=C,[3,4]):[3,2];case 2:return[4,GR(C)];case 3:E=o.sent(),o.label=4;case 4:Q=E,o.label=5;case 5:return e=CQ(Q),I=g.map(function(n){return n instanceof Jg?n.forSize(Q.width,Q.height).box.floor():n}).map(function(n){return n.clipAtImageBorders(Q.width,Q.height)}),[2,I.map(function(n){var i=n.x,Y=n.y,M=n.width,c=n.height,D=ke({width:M,height:c});return CQ(D).putImageData(e.getImageData(i,Y,M,c),0,0),D})]}})})}function Cn(A,g){return dA(this,void 0,void 0,function(){return HA(this,function(B){if(!me(A)&&!jQ(A))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(jQ(A)&&A.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,DA(function(){var Q=A.shape.slice(jQ(A)?1:0),w=Q[0],C=Q[1],E=Q[2],e=g.map(function(o){return o instanceof Jg?o.forSize(C,w).box:o}).map(function(o){return o.clipAtImageBorders(C,w)}),I=e.map(function(o){var n=o.x,i=o.y,Y=o.width,M=o.height;return HD(A.as3D(w,C,E),[i,n,0],[M,Y,E])});return I})]})})}function lR(A,g){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return B=eg.getEnv().fetch,[4,B(A,g)];case 1:if(Q=w.sent(),!(Q.status<400))throw new Error("failed to fetch: ("+Q.status+") "+Q.statusText+", from url: "+Q.url);return[2,Q]}})})}function dR(A){return dA(this,void 0,void 0,function(){return HA(this,function(g){switch(g.label){case 0:return[4,lR(A)];case 1:return[2,g.sent().json()]}})})}function ur(A,g){var B=g+"-weights_manifest.json";if(!A)return{modelBaseUri:"",manifestUri:B};if(A==="/")return{modelBaseUri:"/",manifestUri:"/"+B};var Q=A.startsWith("http://")?"http://":A.startsWith("https://")?"https://":"";A=A.replace(Q,"");var w=A.split("/").filter(function(e){return e}),C=A.endsWith(".json")?w[w.length-1]:B,E=Q+(A.endsWith(".json")?w.slice(0,w.length-1):w).join("/");return E=A.startsWith("/")?"/"+E:E,{modelBaseUri:E,manifestUri:E==="/"?"/"+C:E+"/"+C}}function HR(A,g){return dA(this,void 0,void 0,function(){var B,Q,w,C;return HA(this,function(E){switch(E.label){case 0:return B=ur(A,g),Q=B.manifestUri,w=B.modelBaseUri,[4,dR(Q)];case 1:return C=E.sent(),[2,Qr.loadWeights(C,w)]}})})}function fR(A,g,B){B===void 0&&(B=!1);var Q=B?wn(g):g,w=Q.width,C=Q.height;return A.width=w,A.height=C,{width:w,height:C}}var uQ=function(){function A(g){this._name=g,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(A.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),A.prototype.getParamFromPath=function(g){var B=this.traversePropertyPath(g),Q=B.obj,w=B.objProp;return Q[w]},A.prototype.reassignParamFromPath=function(g,B){var Q=this.traversePropertyPath(g),w=Q.obj,C=Q.objProp;w[C].dispose(),w[C]=B},A.prototype.getParamList=function(){var g=this;return this._paramMappings.map(function(B){var Q=B.paramPath;return{path:Q,tensor:g.getParamFromPath(Q)}})},A.prototype.getTrainableParams=function(){return this.getParamList().filter(function(g){return g.tensor instanceof pw})},A.prototype.getFrozenParams=function(){return this.getParamList().filter(function(g){return!(g.tensor instanceof pw)})},A.prototype.variable=function(){var g=this;this.getFrozenParams().forEach(function(B){var Q=B.path,w=B.tensor;g.reassignParamFromPath(Q,w.variable())})},A.prototype.freeze=function(){var g=this;this.getTrainableParams().forEach(function(B){var Q=B.path,w=B.tensor,C=Ag(w.dataSync());w.dispose(),g.reassignParamFromPath(Q,C)})},A.prototype.dispose=function(g){g===void 0&&(g=!0),this.getParamList().forEach(function(B){if(g&&B.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+B.path);B.tensor.dispose()}),this._params=void 0},A.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(g){var B=g.tensor;return Array.from(B.dataSync())}).reduce(function(g,B){return g.concat(B)}))},A.prototype.load=function(g){return dA(this,void 0,void 0,function(){return HA(this,function(B){switch(B.label){case 0:return g instanceof Float32Array?(this.extractWeights(g),[2]):[4,this.loadFromUri(g)];case 1:return B.sent(),[2]}})})},A.prototype.loadFromUri=function(g){return dA(this,void 0,void 0,function(){var B;return HA(this,function(Q){switch(Q.label){case 0:if(g&&typeof g!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,HR(g,this.getDefaultModelName())];case 1:return B=Q.sent(),this.loadFromWeightMap(B),[2]}})})},A.prototype.loadFromDisk=function(g){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e,I,o,n,i;return HA(this,function(Y){switch(Y.label){case 0:if(g&&typeof g!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return B=eg.getEnv().readFile,Q=ur(g,this.getDefaultModelName()),w=Q.manifestUri,C=Q.modelBaseUri,E=function(M){return Promise.all(M.map(function(c){return B(c).then(function(D){return D.buffer})}))},e=Qr.weightsLoaderFactory(E),n=(o=JSON).parse,[4,B(w)];case 1:return I=n.apply(o,[Y.sent().toString()]),[4,e(I,C)];case 2:return i=Y.sent(),this.loadFromWeightMap(i),[2]}})})},A.prototype.loadFromWeightMap=function(g){var B=this.extractParamsFromWeigthMap(g),Q=B.paramMappings,w=B.params;this._paramMappings=Q,this._params=w},A.prototype.extractWeights=function(g){var B=this.extractParams(g),Q=B.paramMappings,w=B.params;this._paramMappings=Q,this._params=w},A.prototype.traversePropertyPath=function(g){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var B=g.split("/").reduce(function(C,E){if(!C.nextObj.hasOwnProperty(E))throw new Error("traversePropertyPath - object does not have property "+E+", for path "+g);return{obj:C.nextObj,objProp:E,nextObj:C.nextObj[E]}},{nextObj:this.params}),Q=B.obj,w=B.objProp;if(!Q||!w||!(Q[w]instanceof uB))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+g);return{obj:Q,objProp:w}},A}();function Ng(A,g,B){return DA(function(){var Q=Ht(A,g.depthwise_filter,g.pointwise_filter,B,"same");return Q=OA(Q,g.bias),Q})}function En(A,g,B){return B===void 0&&(B=!1),DA(function(){var Q=GB(B?OA(jg(A,g.conv0.filters,[2,2],"same"),g.conv0.bias):Ng(A,g.conv0,[2,2])),w=Ng(Q,g.conv1,[1,1]),C=GB(OA(Q,w)),E=Ng(C,g.conv2,[1,1]);return GB(OA(Q,OA(w,E)))})}function ye(A,g,B,Q){return B===void 0&&(B=!1),Q===void 0&&(Q=!0),DA(function(){var w=GB(B?OA(jg(A,g.conv0.filters,Q?[2,2]:[1,1],"same"),g.conv0.bias):Ng(A,g.conv0,Q?[2,2]:[1,1])),C=Ng(w,g.conv1,[1,1]),E=GB(OA(w,C)),e=Ng(E,g.conv2,[1,1]),I=GB(OA(w,OA(C,e))),o=Ng(I,g.conv3,[1,1]);return GB(OA(w,OA(C,OA(e,o))))})}function Kg(A,g,B,Q){return B===void 0&&(B="same"),Q===void 0&&(Q=!1),DA(function(){var w=OA(jg(A,g.filters,[1,1],B),g.bias);return Q?GB(w):w})}function UQ(A,g){Object.keys(A).forEach(function(B){g.some(function(Q){return Q.originalPath===B})||A[B].dispose()})}function ze(A,g){return function(B,Q,w,C){var E=Dg(A(B*Q*w*w),[w,w,B,Q]),e=PB(A(Q));return g.push({paramPath:C+"/filters"},{paramPath:C+"/bias"}),{filters:E,bias:e}}}function en(A,g){return function(B,Q,w){var C=RQ(A(B*Q),[B,Q]),E=PB(A(Q));return g.push({paramPath:w+"/weights"},{paramPath:w+"/bias"}),{weights:C,bias:E}}}var Ur=function(){function A(g,B,Q){this.depthwise_filter=g,this.pointwise_filter=B,this.bias=Q}return A}();function In(A,g){return function(B,Q,w){var C=Dg(A(9*B),[3,3,B,1]),E=Dg(A(B*Q),[1,1,B,Q]),e=PB(A(Q));return g.push({paramPath:w+"/depthwise_filter"},{paramPath:w+"/pointwise_filter"},{paramPath:w+"/bias"}),new Ur(C,E,e)}}function on(A){return function(g){var B=A(g+"/depthwise_filter",4),Q=A(g+"/pointwise_filter",4),w=A(g+"/bias",1);return new Ur(B,Q,w)}}function yQ(A,g){return function(B,Q,w){var C=A[B];if(!Ne(C,Q))throw new Error("expected weightMap["+B+"] to be a Tensor"+Q+"D, instead have "+C);return g.push({originalPath:B,paramPath:w||B}),C}}function GQ(A){var g=A;function B(w){var C=g.slice(0,w);return g=g.slice(w),C}function Q(){return g}return{extractWeights:B,getRemainingWeights:Q}}function Gr(A,g){var B=ze(A,g),Q=In(A,g);function w(E,e,I,o){o===void 0&&(o=!1);var n=o?B(E,e,3,I+"/conv0"):Q(E,e,I+"/conv0"),i=Q(e,e,I+"/conv1"),Y=Q(e,e,I+"/conv2");return{conv0:n,conv1:i,conv2:Y}}function C(E,e,I,o){o===void 0&&(o=!1);var n=w(E,e,I,o),i=n.conv0,Y=n.conv1,M=n.conv2,c=Q(e,e,I+"/conv3");return{conv0:i,conv1:Y,conv2:M,conv3:c}}return{extractDenseBlock3Params:w,extractDenseBlock4Params:C}}function JR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=Gr(Q,g).extractDenseBlock4Params,E=C(3,32,"dense0",!0),e=C(32,64,"dense1"),I=C(64,128,"dense2"),o=C(128,256,"dense3");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{dense0:E,dense1:e,dense2:I,dense3:o}}}function hr(A){return function(g){var B=A(g+"/filters",4),Q=A(g+"/bias",1);return{filters:B,bias:Q}}}function lr(A,g){var B=yQ(A,g),Q=hr(B),w=on(B);function C(e,I){I===void 0&&(I=!1);var o=I?Q(e+"/conv0"):w(e+"/conv0"),n=w(e+"/conv1"),i=w(e+"/conv2");return{conv0:o,conv1:n,conv2:i}}function E(e,I){I===void 0&&(I=!1);var o=I?Q(e+"/conv0"):w(e+"/conv0"),n=w(e+"/conv1"),i=w(e+"/conv2"),Y=w(e+"/conv3");return{conv0:o,conv1:n,conv2:i,conv3:Y}}return{extractDenseBlock3Params:C,extractDenseBlock4Params:E}}function NR(A){var g=[],B=lr(A,g).extractDenseBlock4Params,Q={dense0:B("dense0",!0),dense1:B("dense1"),dense2:B("dense2"),dense3:B("dense3")};return UQ(A,g),{params:Q,paramMappings:g}}var dr=function(A){yA(g,A);function g(){return A.call(this,"FaceFeatureExtractor")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("FaceFeatureExtractor - load model before inference");return DA(function(){var w=B.toBatchTensor(112,!0),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(255)),e=ye(E,Q.dense0,!0);return e=ye(e,Q.dense1),e=ye(e,Q.dense2),e=ye(e,Q.dense3),e=LC(e,[7,7],[2,2],"valid"),e})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},g.prototype.extractParamsFromWeigthMap=function(B){return NR(B)},g.prototype.extractParams=function(B){return JR(B)},g}(uQ);function EQ(A,g){return DA(function(){return OA(he(A,g.weights),g.bias)})}function mR(A,g,B){var Q=[],w=GQ(A),C=w.extractWeights,E=w.getRemainingWeights,e=en(C,Q),I=e(g,B,"fc");if(E().length!==0)throw new Error("weights remaing after extract: "+E().length);return{paramMappings:Q,params:{fc:I}}}function RR(A){var g=[],B=yQ(A,g);function Q(C){var E=B(C+"/weights",2),e=B(C+"/bias",1);return{weights:E,bias:e}}var w={fc:Q("fc")};return UQ(A,g),{params:w,paramMappings:g}}function Hr(A){var g={},B={};return Object.keys(A).forEach(function(Q){var w=Q.startsWith("fc")?B:g;w[Q]=A[Q]}),{featureExtractorMap:g,classifierMap:B}}var fr=function(A){yA(g,A);function g(B,Q){var w=A.call(this,B)||this;return w._faceFeatureExtractor=Q,w}return Object.defineProperty(g.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),g.prototype.runNet=function(B){var Q=this,w=this.params;if(!w)throw new Error(this._name+" - load model before inference");return DA(function(){var C=B instanceof je?Q.faceFeatureExtractor.forwardInput(B):B;return EQ(C.as2D(C.shape[0],-1),w.fc)})},g.prototype.dispose=function(B){B===void 0&&(B=!0),this.faceFeatureExtractor.dispose(B),A.prototype.dispose.call(this,B)},g.prototype.loadClassifierParams=function(B){var Q=this.extractClassifierParams(B),w=Q.params,C=Q.paramMappings;this._params=w,this._paramMappings=C},g.prototype.extractClassifierParams=function(B){return mR(B,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},g.prototype.extractParamsFromWeigthMap=function(B){var Q=Hr(B),w=Q.featureExtractorMap,C=Q.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(w),RR(C)},g.prototype.extractParams=function(B){var Q=this.getClassifierChannelsIn(),w=this.getClassifierChannelsOut(),C=w*Q+w,E=B.slice(0,B.length-C),e=B.slice(B.length-C);return this.faceFeatureExtractor.extractWeights(E),this.extractClassifierParams(e)},g}(uQ),Jr=["neutral","happy","sad","angry","fearful","disgusted","surprised"],tn=function(){function A(g){var B=this;if(g.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+g.length);Jr.forEach(function(Q,w){B[Q]=g[w]})}return A.prototype.asSortedArray=function(){var g=this;return Jr.map(function(B){return{expression:B,probability:g[B]}}).sort(function(B,Q){return Q.probability-B.probability})},A}(),PR=function(A){yA(g,A);function g(B){return B===void 0&&(B=new dr),A.call(this,"FaceExpressionNet",B)||this}return g.prototype.forwardInput=function(B){var Q=this;return DA(function(){return rQ(Q.runNet(B))})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.predictExpressions=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E,e=this;return HA(this,function(I){switch(I.label){case 0:return[4,xB(B)];case 1:return Q=I.sent(),[4,this.forwardInput(Q)];case 2:return w=I.sent(),[4,Promise.all(pB(w).map(function(o){return dA(e,void 0,void 0,function(){var n;return HA(this,function(i){switch(i.label){case 0:return[4,o.data()];case 1:return n=i.sent(),o.dispose(),[2,n]}})})}))];case 3:return C=I.sent(),w.dispose(),E=C.map(function(o){return new tn(o)}),[2,Q.isBatchInput?E:E[0]]}})})},g.prototype.getDefaultModelName=function(){return"face_expression_model"},g.prototype.getClassifierChannelsIn=function(){return 256},g.prototype.getClassifierChannelsOut=function(){return 7},g}(fr);function vR(A){return A.expressions instanceof tn}function Nr(A,g){var B={expressions:g};return Object.assign({},A,B)}function kR(A,g,B,Q){B===void 0&&(B=.1);var w=Array.isArray(g)?g:[g];w.forEach(function(C){var E=C instanceof tn?C:vR(C)?C.expressions:void 0;if(!E)throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");var e=E.asSortedArray(),I=e.filter(function(i){return i.probability>B}),o=OC(C)?C.detection.box.bottomLeft:new QB(0,0),n=new Fr(I.map(function(i){return i.expression+" ("+_t(i.probability)+")"}),o);n.draw(A)})}function nn(A){return OC(A)&&A.landmarks instanceof AC&&A.unshiftedLandmarks instanceof AC&&A.alignedRect instanceof Jg}function We(A,g){var B=A.detection.box,Q=g.shiftBy(B.x,B.y),w=Q.align(),C=A.detection.imageDims,E=new Jg(A.detection.score,w.rescale(C.reverse()),C),e={landmarks:Q,unshiftedLandmarks:g,alignedRect:E};return Object.assign({},A,e)}var TR=function(){function A(g){g===void 0&&(g={});var B=g.drawLines,Q=B===void 0?!0:B,w=g.drawPoints,C=w===void 0?!0:w,E=g.lineWidth,e=g.lineColor,I=g.pointSize,o=g.pointColor;this.drawLines=Q,this.drawPoints=C,this.lineWidth=E||1,this.pointSize=I||2,this.lineColor=e||"rgba(0, 255, 255, 1)",this.pointColor=o||"rgba(255, 0, 255, 1)"}return A}(),jR=function(){function A(g,B){B===void 0&&(B={}),this.faceLandmarks=g,this.options=new TR(B)}return A.prototype.draw=function(g){var B=CQ(g),Q=this.options,w=Q.drawLines,C=Q.drawPoints,E=Q.lineWidth,e=Q.lineColor,I=Q.pointSize,o=Q.pointColor;if(w&&this.faceLandmarks instanceof or&&(B.strokeStyle=e,B.lineWidth=E,iw(B,this.faceLandmarks.getJawOutline()),iw(B,this.faceLandmarks.getLeftEyeBrow()),iw(B,this.faceLandmarks.getRightEyeBrow()),iw(B,this.faceLandmarks.getNose()),iw(B,this.faceLandmarks.getLeftEye(),!0),iw(B,this.faceLandmarks.getRightEye(),!0),iw(B,this.faceLandmarks.getMouth(),!0)),C){B.strokeStyle=o,B.fillStyle=o;var n=function(i){B.beginPath(),B.arc(i.x,i.y,I,0,2*Math.PI),B.fill()};this.faceLandmarks.positions.forEach(n)}},A}();function pR(A,g){var B=Array.isArray(g)?g:[g];B.forEach(function(Q){var w=Q instanceof AC?Q:nn(Q)?Q.landmarks:void 0;if(!w)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks<WithFaceDetection<{}>> or array thereof");new jR(w).draw(A)})}function yR(A,g){var B=ze(A,g),Q=In(A,g);function w(E,e,I){var o=Q(E,e,I+"/separable_conv0"),n=Q(e,e,I+"/separable_conv1"),i=B(E,e,1,I+"/expansion_conv");return{separable_conv0:o,separable_conv1:n,expansion_conv:i}}function C(E,e){var I=Q(E,E,e+"/separable_conv0"),o=Q(E,E,e+"/separable_conv1"),n=Q(E,E,e+"/separable_conv2");return{separable_conv0:I,separable_conv1:o,separable_conv2:n}}return{extractConvParams:B,extractSeparableConvParams:Q,extractReductionBlockParams:w,extractMainBlockParams:C}}function zR(A,g){var B=[],Q=GQ(A),w=Q.extractWeights,C=Q.getRemainingWeights,E=yR(w,B),e=E.extractConvParams,I=E.extractSeparableConvParams,o=E.extractReductionBlockParams,n=E.extractMainBlockParams,i=e(3,32,3,"entry_flow/conv_in"),Y=o(32,64,"entry_flow/reduction_block_0"),M=o(64,128,"entry_flow/reduction_block_1"),c={conv_in:i,reduction_block_0:Y,reduction_block_1:M},D={};VC(g,0,1).forEach(function(u){D["main_block_"+u]=n(128,"middle_flow/main_block_"+u)});var r=o(128,256,"exit_flow/reduction_block"),F=I(256,512,"exit_flow/separable_conv"),s={reduction_block:r,separable_conv:F};if(C().length!==0)throw new Error("weights remaing after extract: "+C().length);return{paramMappings:B,params:{entry_flow:c,middle_flow:D,exit_flow:s}}}function WR(A,g){var B=yQ(A,g),Q=hr(B),w=on(B);function C(e){var I=w(e+"/separable_conv0"),o=w(e+"/separable_conv1"),n=Q(e+"/expansion_conv");return{separable_conv0:I,separable_conv1:o,expansion_conv:n}}function E(e){var I=w(e+"/separable_conv0"),o=w(e+"/separable_conv1"),n=w(e+"/separable_conv2");return{separable_conv0:I,separable_conv1:o,separable_conv2:n}}return{extractConvParams:Q,extractSeparableConvParams:w,extractReductionBlockParams:C,extractMainBlockParams:E}}function SR(A,g){var B=[],Q=WR(A,B),w=Q.extractConvParams,C=Q.extractSeparableConvParams,E=Q.extractReductionBlockParams,e=Q.extractMainBlockParams,I=w("entry_flow/conv_in"),o=E("entry_flow/reduction_block_0"),n=E("entry_flow/reduction_block_1"),i={conv_in:I,reduction_block_0:o,reduction_block_1:n},Y={};VC(g,0,1).forEach(function(r){Y["main_block_"+r]=e("middle_flow/main_block_"+r)});var M=E("exit_flow/reduction_block"),c=C("exit_flow/separable_conv"),D={reduction_block:M,separable_conv:c};return UQ(A,B),{params:{entry_flow:i,middle_flow:Y,exit_flow:D},paramMappings:B}}function mr(A,g,B){return OA(jg(A,g.filters,B,"same"),g.bias)}function Yn(A,g,B){B===void 0&&(B=!0);var Q=B?GB(A):A;return Q=Ng(Q,g.separable_conv0,[1,1]),Q=Ng(GB(Q),g.separable_conv1,[1,1]),Q=VB(Q,[3,3],[2,2],"same"),Q=OA(Q,mr(A,g.expansion_conv,[2,2])),Q}function LR(A,g){var B=Ng(GB(A),g.separable_conv0,[1,1]);return B=Ng(GB(B),g.separable_conv1,[1,1]),B=Ng(GB(B),g.separable_conv2,[1,1]),B=OA(B,A),B}var bR=function(A){yA(g,A);function g(B){var Q=A.call(this,"TinyXception")||this;return Q._numMainBlocks=B,Q}return g.prototype.forwardInput=function(B){var Q=this,w=this.params;if(!w)throw new Error("TinyXception - load model before inference");return DA(function(){var C=B.toBatchTensor(112,!0),E=[122.782,117.001,104.298],e=XC(C,E).div(nA(256)),I=GB(mr(e,w.entry_flow.conv_in,[2,2]));return I=Yn(I,w.entry_flow.reduction_block_0,!1),I=Yn(I,w.entry_flow.reduction_block_1),VC(Q._numMainBlocks,0,1).forEach(function(o){I=LR(I,w.middle_flow["main_block_"+o])}),I=Yn(I,w.exit_flow.reduction_block),I=GB(Ng(I,w.exit_flow.separable_conv,[1,1])),I})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"tiny_xception_model"},g.prototype.extractParamsFromWeigthMap=function(B){return SR(B,this._numMainBlocks)},g.prototype.extractParams=function(B){return zR(B,this._numMainBlocks)},g}(uQ);function KR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=en(Q,g),E=C(512,1,"fc/age"),e=C(512,2,"fc/gender");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{fc:{age:E,gender:e}}}}function VR(A){var g=[],B=yQ(A,g);function Q(C){var E=B(C+"/weights",2),e=B(C+"/bias",1);return{weights:E,bias:e}}var w={fc:{age:Q("fc/age"),gender:Q("fc/gender")}};return UQ(A,g),{params:w,paramMappings:g}}var Se;(function(A){A.FEMALE="female",A.MALE="male"})(Se||(Se={}));var xR=function(A){yA(g,A);function g(B){B===void 0&&(B=new bR(2));var Q=A.call(this,"AgeGenderNet")||this;return Q._faceFeatureExtractor=B,Q}return Object.defineProperty(g.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),g.prototype.runNet=function(B){var Q=this,w=this.params;if(!w)throw new Error(this._name+" - load model before inference");return DA(function(){var C=B instanceof je?Q.faceFeatureExtractor.forwardInput(B):B,E=LC(C,[7,7],[2,2],"valid").as2D(C.shape[0],-1),e=EQ(E,w.fc.age).as1D(),I=EQ(E,w.fc.gender);return{age:e,gender:I}})},g.prototype.forwardInput=function(B){var Q=this;return DA(function(){var w=Q.runNet(B),C=w.age,E=w.gender;return{age:C,gender:rQ(E)}})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.predictAgeAndGender=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E,e,I,o=this;return HA(this,function(n){switch(n.label){case 0:return[4,xB(B)];case 1:return Q=n.sent(),[4,this.forwardInput(Q)];case 2:return w=n.sent(),C=pB(w.age),E=pB(w.gender),e=C.map(function(i,Y){return{ageTensor:i,genderTensor:E[Y]}}),[4,Promise.all(e.map(function(i){var Y=i.ageTensor,M=i.genderTensor;return dA(o,void 0,void 0,function(){var c,D,r,F,s;return HA(this,function(u){switch(u.label){case 0:return[4,Y.data()];case 1:return c=u.sent()[0],[4,M.data()];case 2:return D=u.sent()[0],r=D>.5,F=r?Se.MALE:Se.FEMALE,s=r?D:1-D,Y.dispose(),M.dispose(),[2,{age:c,gender:F,genderProbability:s}]}})})}))];case 3:return I=n.sent(),w.age.dispose(),w.gender.dispose(),[2,Q.isBatchInput?I:I[0]]}})})},g.prototype.getDefaultModelName=function(){return"age_gender_model"},g.prototype.dispose=function(B){B===void 0&&(B=!0),this.faceFeatureExtractor.dispose(B),A.prototype.dispose.call(this,B)},g.prototype.loadClassifierParams=function(B){var Q=this.extractClassifierParams(B),w=Q.params,C=Q.paramMappings;this._params=w,this._paramMappings=C},g.prototype.extractClassifierParams=function(B){return KR(B)},g.prototype.extractParamsFromWeigthMap=function(B){var Q=Hr(B),w=Q.featureExtractorMap,C=Q.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(w),VR(C)},g.prototype.extractParams=function(B){var Q=1539,w=B.slice(0,B.length-Q),C=B.slice(B.length-Q);return this.faceFeatureExtractor.extractWeights(w),this.extractClassifierParams(C)},g}(uQ),Rr=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.postProcess=function(B,Q,w){var C=w.map(function(e){var I=e.width,o=e.height,n=Q/Math.max(o,I);return{width:I*n,height:o*n}}),E=C.length;return DA(function(){var e=function(Y,M){return Hg([gQ([68],Y),gQ([68],M)],1).as2D(1,136).as1D()},I=function(Y,M){var c=C[Y],D=c.width,r=c.height;return M(D,r)?Math.abs(D-r)/2:0},o=function(Y){return I(Y,function(M,c){return M<c})},n=function(Y){return I(Y,function(M,c){return c<M})},i=B.mul(gQ([E,136],Q)).sub(Hg(Array.from(Array(E),function(Y,M){return e(o(M),n(M))}))).div(Hg(Array.from(Array(E),function(Y,M){return e(C[M].width,C[M].height)})));return i})},g.prototype.forwardInput=function(B){var Q=this;return DA(function(){var w=Q.runNet(B);return Q.postProcess(w,B.inputSize,B.inputDimensions.map(function(C){var E=C[0],e=C[1];return{height:E,width:e}}))})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.detectLandmarks=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E=this;return HA(this,function(e){switch(e.label){case 0:return[4,xB(B)];case 1:return Q=e.sent(),w=DA(function(){return pB(E.forwardInput(Q))}),[4,Promise.all(w.map(function(I,o){return dA(E,void 0,void 0,function(){var n,i,Y,M,c;return HA(this,function(D){switch(D.label){case 0:return Y=(i=Array).from,[4,I.data()];case 1:return n=Y.apply(i,[D.sent()]),M=n.filter(function(r,F){return Cr(F)}),c=n.filter(function(r,F){return!Cr(F)}),[2,new or(Array(68).fill(0).map(function(r,F){return new QB(M[F],c[F])}),{height:Q.getInputHeight(o),width:Q.getInputWidth(o)})]}})})}))];case 2:return C=e.sent(),w.forEach(function(I){return I.dispose()}),[2,Q.isBatchInput?C:C[0]]}})})},g.prototype.getClassifierChannelsOut=function(){return 136},g}(fr),Pr=function(A){yA(g,A);function g(B){return B===void 0&&(B=new dr),A.call(this,"FaceLandmark68Net",B)||this}return g.prototype.getDefaultModelName=function(){return"face_landmark_68_model"},g.prototype.getClassifierChannelsIn=function(){return 256},g}(Rr);function XR(A){var g=[],B=lr(A,g).extractDenseBlock3Params,Q={dense0:B("dense0",!0),dense1:B("dense1"),dense2:B("dense2")};return UQ(A,g),{params:Q,paramMappings:g}}function OR(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=Gr(Q,g).extractDenseBlock3Params,E=C(3,32,"dense0",!0),e=C(32,64,"dense1"),I=C(64,128,"dense2");if(w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{paramMappings:g,params:{dense0:E,dense1:e,dense2:I}}}var ZR=function(A){yA(g,A);function g(){return A.call(this,"TinyFaceFeatureExtractor")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("TinyFaceFeatureExtractor - load model before inference");return DA(function(){var w=B.toBatchTensor(112,!0),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(255)),e=En(E,Q.dense0,!0);return e=En(e,Q.dense1),e=En(e,Q.dense2),e=LC(e,[14,14],[2,2],"valid"),e})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.getDefaultModelName=function(){return"face_feature_extractor_tiny_model"},g.prototype.extractParamsFromWeigthMap=function(B){return XR(B)},g.prototype.extractParams=function(B){return OR(B)},g}(uQ),qR=function(A){yA(g,A);function g(B){return B===void 0&&(B=new ZR),A.call(this,"FaceLandmark68TinyNet",B)||this}return g.prototype.getDefaultModelName=function(){return"face_landmark_68_tiny_model"},g.prototype.getClassifierChannelsIn=function(){return 128},g}(Rr);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g})(Pr);function _R(A,g){return OA(wg(A,g.weights),g.biases)}function Mn(A,g,B,Q,w){w===void 0&&(w="same");var C=g.conv,E=C.filters,e=C.bias,I=jg(A,E,B,w);return I=OA(I,e),I=_R(I,g.scale),Q?GB(I):I}function $R(A,g){return Mn(A,g,[1,1],!0)}function vr(A,g){return Mn(A,g,[1,1],!1)}function kr(A,g){return Mn(A,g,[2,2],!0,"valid")}function AP(A,g){function B(e,I,o){var n=A(e),i=n.length/(I*o*o);if(IR(i))throw new Error("depth has to be an integer: "+i+", weights.length: "+n.length+", numFilters: "+I+", filterSize: "+o);return DA(function(){return vQ(Dg(n,[I,i,o,o]),[2,3,1,0])})}function Q(e,I,o,n){var i=B(e,I,o),Y=PB(A(I));return g.push({paramPath:n+"/filters"},{paramPath:n+"/bias"}),{filters:i,bias:Y}}function w(e,I){var o=PB(A(e)),n=PB(A(e));return g.push({paramPath:I+"/weights"},{paramPath:I+"/biases"}),{weights:o,biases:n}}function C(e,I,o,n){var i=Q(e,I,o,n+"/conv"),Y=w(I,n+"/scale");return{conv:i,scale:Y}}function E(e,I,o,n,i){i===void 0&&(i=!1);var Y=C((i?.5:1)*e,I,o,n+"/conv1"),M=C(e,I,o,n+"/conv2");return{conv1:Y,conv2:M}}return{extractConvLayerParams:C,extractResidualLayerParams:E}}function BP(A){var g=GQ(A),B=g.extractWeights,Q=g.getRemainingWeights,w=[],C=AP(B,w),E=C.extractConvLayerParams,e=C.extractResidualLayerParams,I=E(4704,32,7,"conv32_down"),o=e(9216,32,3,"conv32_1"),n=e(9216,32,3,"conv32_2"),i=e(9216,32,3,"conv32_3"),Y=e(36864,64,3,"conv64_down",!0),M=e(36864,64,3,"conv64_1"),c=e(36864,64,3,"conv64_2"),D=e(36864,64,3,"conv64_3"),r=e(147456,128,3,"conv128_down",!0),F=e(147456,128,3,"conv128_1"),s=e(147456,128,3,"conv128_2"),u=e(589824,256,3,"conv256_down",!0),a=e(589824,256,3,"conv256_1"),U=e(589824,256,3,"conv256_2"),G=e(589824,256,3,"conv256_down_out"),d=DA(function(){return vQ(RQ(B(256*128),[128,256]),[1,0])});if(w.push({paramPath:"fc"}),Q().length!==0)throw new Error("weights remaing after extract: "+Q().length);var H={conv32_down:I,conv32_1:o,conv32_2:n,conv32_3:i,conv64_down:Y,conv64_1:M,conv64_2:c,conv64_3:D,conv128_down:r,conv128_1:F,conv128_2:s,conv256_down:u,conv256_1:a,conv256_2:U,conv256_down_out:G,fc:d};return{params:H,paramMappings:w}}function gP(A,g){var B=yQ(A,g);function Q(E){var e=B(E+"/scale/weights",1),I=B(E+"/scale/biases",1);return{weights:e,biases:I}}function w(E){var e=B(E+"/conv/filters",4),I=B(E+"/conv/bias",1),o=Q(E);return{conv:{filters:e,bias:I},scale:o}}function C(E){return{conv1:w(E+"/conv1"),conv2:w(E+"/conv2")}}return{extractConvLayerParams:w,extractResidualLayerParams:C}}function QP(A){var g=[],B=gP(A,g),Q=B.extractConvLayerParams,w=B.extractResidualLayerParams,C=Q("conv32_down"),E=w("conv32_1"),e=w("conv32_2"),I=w("conv32_3"),o=w("conv64_down"),n=w("conv64_1"),i=w("conv64_2"),Y=w("conv64_3"),M=w("conv128_down"),c=w("conv128_1"),D=w("conv128_2"),r=w("conv256_down"),F=w("conv256_1"),s=w("conv256_2"),u=w("conv256_down_out"),a=A.fc;if(g.push({originalPath:"fc",paramPath:"fc"}),!eR(a))throw new Error("expected weightMap[fc] to be a Tensor2D, instead have "+a);var U={conv32_down:C,conv32_1:E,conv32_2:e,conv32_3:I,conv64_down:o,conv64_1:n,conv64_2:i,conv64_3:Y,conv128_down:M,conv128_1:c,conv128_2:D,conv256_down:r,conv256_1:F,conv256_2:s,conv256_down_out:u,fc:a};return UQ(A,g),{params:U,paramMappings:g}}function eQ(A,g){var B=$R(A,g.conv1);return B=vr(B,g.conv2),B=OA(B,A),B=GB(B),B}function Le(A,g){var B=kr(A,g.conv1);B=vr(B,g.conv2);var Q=LC(A,2,2,"valid"),w=DB(Q.shape),C=Q.shape[3]!==B.shape[3],E=Q.shape[1]!==B.shape[1]||Q.shape[2]!==B.shape[2];if(E){var e=KC(B.shape);e[1]=1;var I=DB(e);B=jB([B,I],1);var o=KC(B.shape);o[2]=1;var n=DB(o);B=jB([B,n],2)}return Q=C?jB([Q,w],3):Q,B=OA(Q,B),B=GB(B),B}var wP=function(A){yA(g,A);function g(){return A.call(this,"FaceRecognitionNet")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("FaceRecognitionNet - load model before inference");return DA(function(){var w=B.toBatchTensor(150,!0).toFloat(),C=[122.782,117.001,104.298],E=XC(w,C).div(nA(256)),e=kr(E,Q.conv32_down);e=VB(e,3,2,"valid"),e=eQ(e,Q.conv32_1),e=eQ(e,Q.conv32_2),e=eQ(e,Q.conv32_3),e=Le(e,Q.conv64_down),e=eQ(e,Q.conv64_1),e=eQ(e,Q.conv64_2),e=eQ(e,Q.conv64_3),e=Le(e,Q.conv128_down),e=eQ(e,Q.conv128_1),e=eQ(e,Q.conv128_2),e=Le(e,Q.conv256_down),e=eQ(e,Q.conv256_1),e=eQ(e,Q.conv256_2),e=Le(e,Q.conv256_down_out);var I=e.mean([1,2]),o=he(I,Q.fc);return o})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.computeFaceDescriptor=function(B){return dA(this,void 0,void 0,function(){var Q,w,C,E=this;return HA(this,function(e){switch(e.label){case 0:return[4,xB(B)];case 1:return Q=e.sent(),w=DA(function(){return pB(E.forwardInput(Q))}),[4,Promise.all(w.map(function(I){return I.data()}))];case 2:return C=e.sent(),w.forEach(function(I){return I.dispose()}),[2,Q.isBatchInput?C:C[0]]}})})},g.prototype.getDefaultModelName=function(){return"face_recognition_model"},g.prototype.extractParamsFromWeigthMap=function(B){return QP(B)},g.prototype.extractParams=function(B){return BP(B)},g}(uQ);function Tr(A,g){var B={descriptor:g};return Object.assign({},A,B)}function jr(A,g){var B={age:g};return Object.assign({},A,B)}function pr(A,g,B){var Q={gender:g,genderProbability:B};return Object.assign({},A,Q)}var yr=function(){function A(g){var B=g===void 0?{}:g,Q=B.minFaceSize,w=B.scaleFactor,C=B.maxNumScales,E=B.scoreThresholds,e=B.scaleSteps;if(this._name="MtcnnOptions",this._minFaceSize=Q||20,this._scaleFactor=w||.709,this._maxNumScales=C||10,this._scoreThresholds=E||[.6,.7,.7],this._scaleSteps=e,typeof this._minFaceSize!="number"||this._minFaceSize<0)throw new Error(this._name+" - expected minFaceSize to be a number > 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(I){return typeof I!="number"}))throw new Error(this._name+" - expected scoreThresholds to be an array of numbers of length 3");if(this._scaleSteps&&(!Array.isArray(this._scaleSteps)||this._scaleSteps.some(function(I){return typeof I!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(A.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),A}();function CP(A,g){function B(I,o){var n=Dg(A(9*I),[3,3,I,1]),i=PB(A(I)),Y=PB(A(I)),M=PB(A(I)),c=PB(A(I));return g.push({paramPath:o+"/filters"},{paramPath:o+"/batch_norm_scale"},{paramPath:o+"/batch_norm_offset"},{paramPath:o+"/batch_norm_mean"},{paramPath:o+"/batch_norm_variance"}),{filters:n,batch_norm_scale:i,batch_norm_offset:Y,batch_norm_mean:M,batch_norm_variance:c}}function Q(I,o,n,i,Y){var M=Dg(A(I*o*n*n),[n,n,I,o]),c=PB(A(o));return g.push({paramPath:i+"/filters"},{paramPath:i+"/"+(Y?"batch_norm_offset":"bias")}),{filters:M,bias:c}}function w(I,o,n,i){var Y=Q(I,o,n,i,!0),M=Y.filters,c=Y.bias;return{filters:M,batch_norm_offset:c}}function C(I,o,n){var i=B(I,n+"/depthwise_conv"),Y=w(I,o,1,n+"/pointwise_conv");return{depthwise_conv:i,pointwise_conv:Y}}function E(){var I=w(3,32,3,"mobilenetv1/conv_0"),o=C(32,64,"mobilenetv1/conv_1"),n=C(64,128,"mobilenetv1/conv_2"),i=C(128,128,"mobilenetv1/conv_3"),Y=C(128,256,"mobilenetv1/conv_4"),M=C(256,256,"mobilenetv1/conv_5"),c=C(256,512,"mobilenetv1/conv_6"),D=C(512,512,"mobilenetv1/conv_7"),r=C(512,512,"mobilenetv1/conv_8"),F=C(512,512,"mobilenetv1/conv_9"),s=C(512,512,"mobilenetv1/conv_10"),u=C(512,512,"mobilenetv1/conv_11"),a=C(512,1024,"mobilenetv1/conv_12"),U=C(1024,1024,"mobilenetv1/conv_13");return{conv_0:I,conv_1:o,conv_2:n,conv_3:i,conv_4:Y,conv_5:M,conv_6:c,conv_7:D,conv_8:r,conv_9:F,conv_10:s,conv_11:u,conv_12:a,conv_13:U}}function e(){var I=w(1024,256,1,"prediction_layer/conv_0"),o=w(256,512,3,"prediction_layer/conv_1"),n=w(512,128,1,"prediction_layer/conv_2"),i=w(128,256,3,"prediction_layer/conv_3"),Y=w(256,128,1,"prediction_layer/conv_4"),M=w(128,256,3,"prediction_layer/conv_5"),c=w(256,64,1,"prediction_layer/conv_6"),D=w(64,128,3,"prediction_layer/conv_7"),r=Q(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),F=Q(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),s=Q(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),u=Q(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),a=Q(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),U=Q(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),G=Q(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),d=Q(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),H=Q(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),h=Q(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),l=Q(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),m=Q(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),f={box_encoding_predictor:r,class_predictor:F},W={box_encoding_predictor:s,class_predictor:u},N={box_encoding_predictor:a,class_predictor:U},v={box_encoding_predictor:G,class_predictor:d},y={box_encoding_predictor:H,class_predictor:h},k={box_encoding_predictor:l,class_predictor:m};return{conv_0:I,conv_1:o,conv_2:n,conv_3:i,conv_4:Y,conv_5:M,conv_6:c,conv_7:D,box_predictor_0:f,box_predictor_1:W,box_predictor_2:N,box_predictor_3:v,box_predictor_4:y,box_predictor_5:k}}return{extractMobilenetV1Params:E,extractPredictionLayerParams:e}}function EP(A){var g=[],B=GQ(A),Q=B.extractWeights,w=B.getRemainingWeights,C=CP(Q,g),E=C.extractMobilenetV1Params,e=C.extractPredictionLayerParams,I=E(),o=e(),n=$o(Q(5118*4),[1,5118,4]),i={extra_dim:n};if(g.push({paramPath:"output_layer/extra_dim"}),w().length!==0)throw new Error("weights remaing after extract: "+w().length);return{params:{mobilenetv1:I,prediction_layer:o,output_layer:i},paramMappings:g}}function eP(A,g){var B=yQ(A,g);function Q(o,n,i){var Y=B(o+"/Conv2d_"+n+"_pointwise/weights",4,i+"/filters"),M=B(o+"/Conv2d_"+n+"_pointwise/convolution_bn_offset",1,i+"/batch_norm_offset");return{filters:Y,batch_norm_offset:M}}function w(o){var n="mobilenetv1/conv_"+o,i="MobilenetV1/Conv2d_"+o+"_depthwise",Y=n+"/depthwise_conv",M=n+"/pointwise_conv",c=B(i+"/depthwise_weights",4,Y+"/filters"),D=B(i+"/BatchNorm/gamma",1,Y+"/batch_norm_scale"),r=B(i+"/BatchNorm/beta",1,Y+"/batch_norm_offset"),F=B(i+"/BatchNorm/moving_mean",1,Y+"/batch_norm_mean"),s=B(i+"/BatchNorm/moving_variance",1,Y+"/batch_norm_variance");return{depthwise_conv:{filters:c,batch_norm_scale:D,batch_norm_offset:r,batch_norm_mean:F,batch_norm_variance:s},pointwise_conv:Q("MobilenetV1",o,M)}}function C(){return{conv_0:Q("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:w(1),conv_2:w(2),conv_3:w(3),conv_4:w(4),conv_5:w(5),conv_6:w(6),conv_7:w(7),conv_8:w(8),conv_9:w(9),conv_10:w(10),conv_11:w(11),conv_12:w(12),conv_13:w(13)}}function E(o,n){var i=B(o+"/weights",4,n+"/filters"),Y=B(o+"/biases",1,n+"/bias");return{filters:i,bias:Y}}function e(o){var n=E("Prediction/BoxPredictor_"+o+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+o+"/box_encoding_predictor"),i=E("Prediction/BoxPredictor_"+o+"/ClassPredictor","prediction_layer/box_predictor_"+o+"/class_predictor");return{box_encoding_predictor:n,class_predictor:i}}function I(){return{conv_0:Q("Prediction",0,"prediction_layer/conv_0"),conv_1:Q("Prediction",1,"prediction_layer/conv_1"),conv_2:Q("Prediction",2,"prediction_layer/conv_2"),conv_3:Q("Prediction",3,"prediction_layer/conv_3"),conv_4:Q("Prediction",4,"prediction_layer/conv_4"),conv_5:Q("Prediction",5,"prediction_layer/conv_5"),conv_6:Q("Prediction",6,"prediction_layer/conv_6"),conv_7:Q("Prediction",7,"prediction_layer/conv_7"),box_predictor_0:e(0),box_predictor_1:e(1),box_predictor_2:e(2),box_predictor_3:e(3),box_predictor_4:e(4),box_predictor_5:e(5)}}return{extractMobilenetV1Params:C,extractPredictionLayerParams:I}}function IP(A){var g=[],B=eP(A,g),Q=B.extractMobilenetV1Params,w=B.extractPredictionLayerParams,C=A["Output/extra_dim"];if(g.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!me(C))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+C);var E={mobilenetv1:Q(),prediction_layer:w(),output_layer:{extra_dim:C}};return UQ(A,g),{params:E,paramMappings:g}}function IQ(A,g,B){return DA(function(){var Q=jg(A,g.filters,B,"same");return Q=OA(Q,g.batch_norm_offset),ut(Q,0,6)})}var oP=.0010000000474974513;function tP(A,g,B){return DA(function(){var Q=Ge(A,g.filters,B,"same");return Q=tD(Q,g.batch_norm_mean,g.batch_norm_variance,g.batch_norm_offset,g.batch_norm_scale,oP),ut(Q,0,6)})}function nP(A){return[2,4,6,12].some(function(g){return g===A})?[2,2]:[1,1]}function iP(A,g){return DA(function(){var B=null,Q=IQ(A,g.conv_0,[2,2]),w=[g.conv_1,g.conv_2,g.conv_3,g.conv_4,g.conv_5,g.conv_6,g.conv_7,g.conv_8,g.conv_9,g.conv_10,g.conv_11,g.conv_12,g.conv_13];if(w.forEach(function(C,E){var e=E+1,I=nP(e);Q=tP(Q,C.depthwise_conv,I),Q=IQ(Q,C.pointwise_conv,[1,1]),e===11&&(B=Q)}),B===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:Q,conv11:B}})}function YP(A,g,B,Q,w){var C=A.shape[0],E=Math.min(B,C),e=g.map(function(n,i){return{score:n,boxIndex:i}}).filter(function(n){return n.score>w}).sort(function(n,i){return i.score-n.score}),I=function(n){return n<=Q?1:0},o=[];return e.forEach(function(n){if(!(o.length>=E)){for(var i=n.score,Y=o.length-1;Y>=0;--Y){var M=MP(A,n.boxIndex,o[Y]);if(M!==0&&(n.score*=I(M),n.score<=w))break}i===n.score&&o.push(n.boxIndex)}}),o}function MP(A,g,B){var Q=A.arraySync(),w=Math.min(Q[g][0],Q[g][2]),C=Math.min(Q[g][1],Q[g][3]),E=Math.max(Q[g][0],Q[g][2]),e=Math.max(Q[g][1],Q[g][3]),I=Math.min(Q[B][0],Q[B][2]),o=Math.min(Q[B][1],Q[B][3]),n=Math.max(Q[B][0],Q[B][2]),i=Math.max(Q[B][1],Q[B][3]),Y=(E-w)*(e-C),M=(n-I)*(i-o);if(Y<=0||M<=0)return 0;var c=Math.max(w,I),D=Math.max(C,o),r=Math.min(E,n),F=Math.min(e,i),s=Math.max(r-c,0)*Math.max(F-D,0);return s/(Y+M-s)}function cP(A){var g=pB(vQ(A,[1,0])),B=[zB(g[2],g[0]),zB(g[3],g[1])],Q=[OA(g[0],bg(B[0],nA(2))),OA(g[1],bg(B[1],nA(2)))];return{sizes:B,centers:Q}}function DP(A,g){var B=cP(A),Q=B.sizes,w=B.centers,C=pB(vQ(g,[1,0])),E=bg(wg(Ut(bg(C[2],nA(5))),Q[0]),nA(2)),e=OA(wg(bg(C[0],nA(10)),Q[0]),w[0]),I=bg(wg(Ut(bg(C[3],nA(5))),Q[1]),nA(2)),o=OA(wg(bg(C[1],nA(10)),Q[1]),w[1]);return vQ(Hg([zB(e,E),zB(o,I),OA(e,E),OA(o,I)]),[1,0])}function rP(A,g,B){return DA(function(){var Q=A.shape[0],w=DP(Sg(Ww(B.extra_dim,[Q,1,1]),[-1,4]),Sg(A,[-1,4]));w=Sg(w,[Q,w.shape[0]/Q,4]);var C=ED(QQ(g,[0,0,1],[-1,-1,-1])),E=QQ(C,[0,0,0],[-1,-1,1]);E=Sg(E,[Q,E.shape[1]]);var e=pB(w),I=pB(E);return{boxes:e,scores:I}})}function BC(A,g){return DA(function(){var B=A.shape[0],Q=Sg(Kg(A,g.box_encoding_predictor),[B,-1,1,4]),w=Sg(Kg(A,g.class_predictor),[B,-1,3]);return{boxPredictionEncoding:Q,classPrediction:w}})}function FP(A,g,B){return DA(function(){var Q=IQ(A,B.conv_0,[1,1]),w=IQ(Q,B.conv_1,[2,2]),C=IQ(w,B.conv_2,[1,1]),E=IQ(C,B.conv_3,[2,2]),e=IQ(E,B.conv_4,[1,1]),I=IQ(e,B.conv_5,[2,2]),o=IQ(I,B.conv_6,[1,1]),n=IQ(o,B.conv_7,[2,2]),i=BC(g,B.box_predictor_0),Y=BC(A,B.box_predictor_1),M=BC(w,B.box_predictor_2),c=BC(E,B.box_predictor_3),D=BC(I,B.box_predictor_4),r=BC(n,B.box_predictor_5),F=jB([i.boxPredictionEncoding,Y.boxPredictionEncoding,M.boxPredictionEncoding,c.boxPredictionEncoding,D.boxPredictionEncoding,r.boxPredictionEncoding],1),s=jB([i.classPrediction,Y.classPrediction,M.classPrediction,c.classPrediction,D.classPrediction,r.classPrediction],1);return{boxPredictions:F,classPredictions:s}})}var be=function(){function A(g){var B=g===void 0?{}:g,Q=B.minConfidence,w=B.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=Q||.5,this._maxResults=w||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(A.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),A}(),zr=function(A){yA(g,A);function g(){return A.call(this,"SsdMobilenetv1")||this}return g.prototype.forwardInput=function(B){var Q=this.params;if(!Q)throw new Error("SsdMobilenetv1 - load model before inference");return DA(function(){var w=B.toBatchTensor(512,!1).toFloat(),C=zB(wg(w,nA(.007843137718737125)),nA(1)),E=iP(C,Q.mobilenetv1),e=FP(E.out,E.conv11,Q.prediction_layer),I=e.boxPredictions,o=e.classPredictions;return rP(I,o,Q.output_layer)})},g.prototype.forward=function(B){return dA(this,void 0,void 0,function(){var Q;return HA(this,function(w){switch(w.label){case 0:return Q=this.forwardInput,[4,xB(B)];case 1:return[2,Q.apply(this,[w.sent()])]}})})},g.prototype.locateFaces=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return HA(this,function(h){switch(h.label){case 0:return w=new be(Q),C=w.maxResults,E=w.minConfidence,[4,xB(B)];case 1:for(e=h.sent(),I=this.forwardInput(e),o=I.boxes,n=I.scores,i=o[0],Y=n[0],M=1;M<o.length;M++)o[M].dispose(),n[M].dispose();return r=(D=Array).from,[4,Y.data()];case 2:return c=r.apply(D,[h.sent()]),F=.5,s=YP(i,c,C,F,E),u=e.getReshapedInputDimensions(0),a=e.inputSize,U=a/u.width,G=a/u.height,d=i.arraySync(),H=s.map(function(l){var m=[Math.max(0,d[l][0]),Math.min(1,d[l][2])].map(function(k){return k*G}),f=m[0],W=m[1],N=[Math.max(0,d[l][1]),Math.min(1,d[l][3])].map(function(k){return k*U}),v=N[0],y=N[1];return new Jg(c[l],new Pe(v,f,y-v,W-f),{height:e.getInputHeight(0),width:e.getInputWidth(0)})}),i.dispose(),Y.dispose(),[2,H]}})})},g.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},g.prototype.extractParamsFromWeigthMap=function(B){return IP(B)},g.prototype.extractParams=function(B){return EP(B)},g}(uQ);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g})(zr);var aP=.4,sP=[new QB(.738768,.874946),new QB(2.42204,2.65704),new QB(4.30971,7.04493),new QB(10.246,4.59428),new QB(12.6868,11.8741)],uP=[new QB(1.603231,2.094468),new QB(6.041143,7.080126),new QB(2.882459,3.518061),new QB(4.266906,5.178857),new QB(9.041765,10.66308)],UP=[117.001,114.697,97.404],GP="tiny_yolov2_model",hP="tiny_yolov2_separable_conv_model",Ke=function(A){return typeof A=="number"};function lP(A){if(!A)throw new Error("invalid config: "+A);if(typeof A.withSeparableConvs!="boolean")throw new Error("config.withSeparableConvs has to be a boolean, have: "+A.withSeparableConvs);if(!Ke(A.iouThreshold)||A.iouThreshold<0||A.iouThreshold>1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+A.iouThreshold);if(!Array.isArray(A.classes)||!A.classes.length||!A.classes.every(function(g){return typeof g=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(A.classes));if(!Array.isArray(A.anchors)||!A.anchors.length||!A.anchors.map(function(g){return g||{}}).every(function(g){return Ke(g.x)&&Ke(g.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(A.anchors));if(A.meanRgb&&(!Array.isArray(A.meanRgb)||A.meanRgb.length!==3||!A.meanRgb.every(Ke)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(A.meanRgb))}function cn(A){return DA(function(){var g=wg(A,nA(.10000000149011612));return OA(GB(zB(A,g)),g)})}function zQ(A,g){return DA(function(){var B=ww(A,[[0,0],[1,1],[1,1],[0,0]]);return B=jg(B,g.conv.filters,[1,1],"valid"),B=zB(B,g.bn.sub),B=wg(B,g.bn.truediv),B=OA(B,g.conv.bias),cn(B)})}function WQ(A,g){return DA(function(){var B=ww(A,[[0,0],[1,1],[1,1],[0,0]]);return B=Ht(B,g.depthwise_filter,g.pointwise_filter,[1,1],"valid"),B=OA(B,g.bias),cn(B)})}function dP(A,g){var B=ze(A,g);function Q(E,e){var I=PB(A(E)),o=PB(A(E));return g.push({paramPath:e+"/sub"},{paramPath:e+"/truediv"}),{sub:I,truediv:o}}function w(E,e,I){var o=B(E,e,3,I+"/conv"),n=Q(e,I+"/bn");return{conv:o,bn:n}}var C=In(A,g);return{extractConvParams:B,extractConvWithBatchNormParams:w,extractSeparableConvParams:C}}function HP(A,g,B,Q){var w=GQ(A),C=w.extractWeights,E=w.getRemainingWeights,e=[],I=dP(C,e),o=I.extractConvParams,n=I.extractConvWithBatchNormParams,i=I.extractSeparableConvParams,Y;if(g.withSeparableConvs){var M=Q[0],c=Q[1],D=Q[2],r=Q[3],F=Q[4],s=Q[5],u=Q[6],a=Q[7],U=Q[8],G=g.isFirstLayerConv2d?o(M,c,3,"conv0"):i(M,c,"conv0"),d=i(c,D,"conv1"),H=i(D,r,"conv2"),h=i(r,F,"conv3"),l=i(F,s,"conv4"),m=i(s,u,"conv5"),f=a?i(u,a,"conv6"):void 0,W=U?i(a,U,"conv7"):void 0,N=o(U||a||u,5*B,1,"conv8");Y={conv0:G,conv1:d,conv2:H,conv3:h,conv4:l,conv5:m,conv6:f,conv7:W,conv8:N}}else{var M=Q[0],c=Q[1],D=Q[2],r=Q[3],F=Q[4],s=Q[5],u=Q[6],a=Q[7],U=Q[8],G=n(M,c,"conv0"),d=n(c,D,"conv1"),H=n(D,r,"conv2"),h=n(r,F,"conv3"),l=n(F,s,"conv4"),m=n(s,u,"conv5"),f=n(u,a,"conv6"),W=n(a,U,"conv7"),N=o(U,5*B,1,"conv8");Y={conv0:G,conv1:d,conv2:H,conv3:h,conv4:l,conv5:m,conv6:f,conv7:W,conv8:N}}if(E().length!==0)throw new Error("weights remaing after extract: "+E().length);return{params:Y,paramMappings:e}}function fP(A,g){var B=yQ(A,g);function Q(e){var I=B(e+"/sub",1),o=B(e+"/truediv",1);return{sub:I,truediv:o}}function w(e){var I=B(e+"/filters",4),o=B(e+"/bias",1);return{filters:I,bias:o}}function C(e){var I=w(e+"/conv"),o=Q(e+"/bn");return{conv:I,bn:o}}var E=on(B);return{extractConvParams:w,extractConvWithBatchNormParams:C,extractSeparableConvParams:E}}function JP(A,g){var B=[],Q=fP(A,B),w=Q.extractConvParams,C=Q.extractConvWithBatchNormParams,E=Q.extractSeparableConvParams,e;if(g.withSeparableConvs){var I=g.filterSizes&&g.filterSizes.length||9;e={conv0:g.isFirstLayerConv2d?w("conv0"):E("conv0"),conv1:E("conv1"),conv2:E("conv2"),conv3:E("conv3"),conv4:E("conv4"),conv5:E("conv5"),conv6:I>7?E("conv6"):void 0,conv7:I>8?E("conv7"):void 0,conv8:w("conv8")}}else e={conv0:C("conv0"),conv1:C("conv1"),conv2:C("conv2"),conv3:C("conv3"),conv4:C("conv4"),conv5:C("conv5"),conv6:C("conv6"),conv7:C("conv7"),conv8:w("conv8")};return UQ(A,B),{params:e,paramMappings:B}}var Wr;(function(A){A[A.XS=224]="XS",A[A.SM=320]="SM",A[A.MD=416]="MD",A[A.LG=608]="LG"})(Wr||(Wr={}));var Dn=function(){function A(g){var B=g===void 0?{}:g,Q=B.inputSize,w=B.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=Q||416,this._scoreThreshold=w||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(A.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),A}(),Sr=function(A){yA(g,A);function g(B){var Q=A.call(this,"TinyYolov2")||this;return lP(B),Q._config=B,Q}return Object.defineProperty(g.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"withClassScores",{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"boxEncodingSize",{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),g.prototype.runTinyYolov2=function(B,Q){var w=zQ(B,Q.conv0);return w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv1),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv2),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv3),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv4),w=VB(w,[2,2],[2,2],"same"),w=zQ(w,Q.conv5),w=VB(w,[2,2],[1,1],"same"),w=zQ(w,Q.conv6),w=zQ(w,Q.conv7),Kg(w,Q.conv8,"valid",!1)},g.prototype.runMobilenet=function(B,Q){var w=this.config.isFirstLayerConv2d?cn(Kg(B,Q.conv0,"valid",!1)):WQ(B,Q.conv0);return w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv1),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv2),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv3),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv4),w=VB(w,[2,2],[2,2],"same"),w=WQ(w,Q.conv5),w=VB(w,[2,2],[1,1],"same"),w=Q.conv6?WQ(w,Q.conv6):w,w=Q.conv7?WQ(w,Q.conv7):w,Kg(w,Q.conv8,"valid",!1)},g.prototype.forwardInput=function(B,Q){var w=this,C=this.params;if(!C)throw new Error("TinyYolov2 - load model before inference");return DA(function(){var E=B.toBatchTensor(Q,!1).toFloat();return E=w.config.meanRgb?XC(E,w.config.meanRgb):E,E=E.div(nA(256)),w.config.withSeparableConvs?w.runMobilenet(E,C):w.runTinyYolov2(E,C)})},g.prototype.forward=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[4,w.apply(this,[C.sent(),Q])];case 2:return[2,C.sent()]}})})},g.prototype.detect=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s=this;return HA(this,function(u){switch(u.label){case 0:return w=new Dn(Q),C=w.inputSize,E=w.scoreThreshold,[4,xB(B)];case 1:return e=u.sent(),[4,this.forwardInput(e,C)];case 2:return I=u.sent(),o=DA(function(){return pB(I)[0].expandDims()}),n={width:e.getInputWidth(0),height:e.getInputHeight(0)},[4,this.extractBoxes(o,e.getReshapedInputDimensions(0),E)];case 3:return i=u.sent(),I.dispose(),o.dispose(),Y=i.map(function(a){return a.box}),M=i.map(function(a){return a.score}),c=i.map(function(a){return a.classScore}),D=i.map(function(a){return s.config.classes[a.label]}),r=xC(Y.map(function(a){return a.rescale(C)}),M,this.config.iouThreshold,!0),F=r.map(function(a){return new Ir(M[a],c[a],D[a],Y[a],n)}),[2,F]}})})},g.prototype.getDefaultModelName=function(){return""},g.prototype.extractParamsFromWeigthMap=function(B){return JP(B,this.config)},g.prototype.extractParams=function(B){var Q=this.config.filterSizes||g.DEFAULT_FILTER_SIZES,w=Q?Q.length:void 0;if(w!==7&&w!==8&&w!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+w+" filterSizes in config");return HP(B,this.config,this.boxEncodingSize,Q)},g.prototype.extractBoxes=function(B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H,h,l,m,f,W,N,v,y,k,p=this;return HA(this,function(K){switch(K.label){case 0:return C=Q.width,E=Q.height,e=Math.max(C,E),I=e/C,o=e/E,n=B.shape[1],i=this.config.anchors.length,Y=DA(function(){var V=B.reshape([n,n,i,p.boxEncodingSize]),T=V.slice([0,0,0,0],[n,n,i,4]),j=V.slice([0,0,0,4],[n,n,i,1]),X=p.withClassScores?rQ(V.slice([0,0,0,5],[n,n,i,p.config.classes.length]),3):nA(0);return[T,j,X]}),M=Y[0],c=Y[1],D=Y[2],r=[],[4,c.array()];case 1:return F=K.sent(),[4,M.array()];case 2:s=K.sent(),u=0,K.label=3;case 3:if(!(u<n))return[3,12];a=0,K.label=4;case 4:if(!(a<n))return[3,11];U=0,K.label=5;case 5:return U<i?(G=An(F[u][a][U][0]),!w||G>w?(d=(a+An(s[u][a][U][0]))/n*I,H=(u+An(s[u][a][U][1]))/n*o,h=Math.exp(s[u][a][U][2])*this.config.anchors[U].x/n*I,l=Math.exp(s[u][a][U][3])*this.config.anchors[U].y/n*o,m=d-h/2,f=H-l/2,W={row:u,col:a,anchor:U},this.withClassScores?[4,this.extractPredictedClass(D,W)]:[3,7]):[3,9]):[3,10];case 6:return k=K.sent(),[3,8];case 7:k={classScore:1,label:0},K.label=8;case 8:N=k,v=N.classScore,y=N.label,r.push(Eg({box:new Re(m,f,m+h,f+l),score:G,classScore:G*v,label:y},W)),K.label=9;case 9:return U++,[3,5];case 10:return a++,[3,4];case 11:return u++,[3,3];case 12:return M.dispose(),c.dispose(),D.dispose(),[2,r]}})})},g.prototype.extractPredictedClass=function(B,Q){return dA(this,void 0,void 0,function(){var w,C,E,e;return HA(this,function(I){switch(I.label){case 0:return w=Q.row,C=Q.col,E=Q.anchor,[4,B.array()];case 1:return e=I.sent(),[2,Array(this.config.classes.length).fill(0).map(function(o,n){return e[w][C][E][n]}).map(function(o,n){return{classScore:o,label:n}}).reduce(function(o,n){return o.classScore>n.classScore?o:n})]}})})},g.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],g}(uQ),NP=function(A){yA(g,A);function g(B){B===void 0&&(B=!0);var Q=this,w=Object.assign({},{withSeparableConvs:B,iouThreshold:aP,classes:["face"]},B?{anchors:uP,meanRgb:UP}:{anchors:sP,withClassScores:!0});return Q=A.call(this,w)||this,Q}return Object.defineProperty(g.prototype,"withSeparableConvs",{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(g.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),g.prototype.locateFaces=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.detect(B,Q)];case 1:return w=C.sent(),[2,w.map(function(E){return new Jg(E.score,E.relativeBox,{width:E.imageWidth,height:E.imageHeight})})]}})})},g.prototype.getDefaultModelName=function(){return this.withSeparableConvs?hP:GP},g.prototype.extractParamsFromWeigthMap=function(B){return A.prototype.extractParamsFromWeigthMap.call(this,B)},g}(Sr),Lr=function(A){yA(g,A);function g(){var B=A!==null&&A.apply(this,arguments)||this;return B._name="TinyFaceDetectorOptions",B}return g}(Dn),qC=function(){function A(){}return A.prototype.then=function(g){return dA(this,void 0,void 0,function(){var B;return HA(this,function(Q){switch(Q.label){case 0:return B=g,[4,this.run()];case 1:return[2,B.apply(void 0,[Q.sent()])]}})})},A.prototype.run=function(){return dA(this,void 0,void 0,function(){return HA(this,function(g){throw new Error("ComposableTask - run is not implemented")})})},A}();function Ve(A,g,B,Q,w){return w===void 0&&(w=function(C){var E=C.alignedRect;return E}),dA(this,void 0,void 0,function(){var C,E,e,I,o;return HA(this,function(n){switch(n.label){case 0:return C=A.map(function(i){return nn(i)?w(i):i.detection}),e=Q,e?[3,5]:g instanceof uB?[4,Cn(g,C)]:[3,2];case 1:return I=n.sent(),[3,4];case 2:return[4,pe(g,C)];case 3:I=n.sent(),n.label=4;case 4:e=I,n.label=5;case 5:return E=e,[4,B(E)];case 6:return o=n.sent(),E.forEach(function(i){return i instanceof uB&&i.dispose()}),[2,o]}})})}function rn(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C=this;return HA(this,function(E){return[2,Ve([A],g,function(e){return dA(C,void 0,void 0,function(){return HA(this,function(I){return[2,B(e[0])]})})},Q,w)]})})}function mP(A){return DA(function(){return Hg(pB(A,3).reverse(),3)})}var xe=2,Xe=12;function RP(A,g){var B=ze(A,g),Q=en(A,g);function w(o,n){var i=PB(A(o));return g.push({paramPath:n}),i}function C(o,n,i){i===void 0&&(i=!1);var Y=B(o[0],o[1],3,n+"/conv1"),M=w(o[1],n+"/prelu1_alpha"),c=B(o[1],o[2],3,n+"/conv2"),D=w(o[2],n+"/prelu2_alpha"),r=B(o[2],o[3],i?2:3,n+"/conv3"),F=w(o[3],n+"/prelu3_alpha");return{conv1:Y,prelu1_alpha:M,conv2:c,prelu2_alpha:D,conv3:r,prelu3_alpha:F}}function E(){var o=C([3,10,16,32],"pnet"),n=B(32,2,1,"pnet/conv4_1"),i=B(32,4,1,"pnet/conv4_2");return Eg(Eg({},o),{conv4_1:n,conv4_2:i})}function e(){var o=C([3,28,48,64],"rnet",!0),n=Q(576,128,"rnet/fc1"),i=w(128,"rnet/prelu4_alpha"),Y=Q(128,2,"rnet/fc2_1"),M=Q(128,4,"rnet/fc2_2");return Eg(Eg({},o),{fc1:n,prelu4_alpha:i,fc2_1:Y,fc2_2:M})}function I(){var o=C([3,32,64,64],"onet"),n=B(64,128,2,"onet/conv4"),i=w(128,"onet/prelu4_alpha"),Y=Q(1152,256,"onet/fc1"),M=w(256,"onet/prelu5_alpha"),c=Q(256,2,"onet/fc2_1"),D=Q(256,4,"onet/fc2_2"),r=Q(256,10,"onet/fc2_3");return Eg(Eg({},o),{conv4:n,prelu4_alpha:i,fc1:Y,prelu5_alpha:M,fc2_1:c,fc2_2:D,fc2_3:r})}return{extractPNetParams:E,extractRNetParams:e,extractONetParams:I}}function PP(A){var g=GQ(A),B=g.extractWeights,Q=g.getRemainingWeights,w=[],C=RP(B,w),E=C.extractPNetParams,e=C.extractRNetParams,I=C.extractONetParams,o=E(),n=e(),i=I();if(Q().length!==0)throw new Error("weights remaing after extract: "+Q().length);return{params:{pnet:o,rnet:n,onet:i},paramMappings:w}}function vP(A,g){var B=yQ(A,g);function Q(n){var i=B(n+"/weights",4,n+"/filters"),Y=B(n+"/bias",1);return{filters:i,bias:Y}}function w(n){var i=B(n+"/weights",2),Y=B(n+"/bias",1);return{weights:i,bias:Y}}function C(n){return B(n,1)}function E(n){var i=Q(n+"/conv1"),Y=C(n+"/prelu1_alpha"),M=Q(n+"/conv2"),c=C(n+"/prelu2_alpha"),D=Q(n+"/conv3"),r=C(n+"/prelu3_alpha");return{conv1:i,prelu1_alpha:Y,conv2:M,prelu2_alpha:c,conv3:D,prelu3_alpha:r}}function e(){var n=E("pnet"),i=Q("pnet/conv4_1"),Y=Q("pnet/conv4_2");return Eg(Eg({},n),{conv4_1:i,conv4_2:Y})}function I(){var n=E("rnet"),i=w("rnet/fc1"),Y=C("rnet/prelu4_alpha"),M=w("rnet/fc2_1"),c=w("rnet/fc2_2");return Eg(Eg({},n),{fc1:i,prelu4_alpha:Y,fc2_1:M,fc2_2:c})}function o(){var n=E("onet"),i=Q("onet/conv4"),Y=C("onet/prelu4_alpha"),M=w("onet/fc1"),c=C("onet/prelu5_alpha"),D=w("onet/fc2_1"),r=w("onet/fc2_2"),F=w("onet/fc2_3");return Eg(Eg({},n),{conv4:i,prelu4_alpha:Y,fc1:M,prelu5_alpha:c,fc2_1:D,fc2_2:r,fc2_3:F})}return{extractPNetParams:e,extractRNetParams:I,extractONetParams:o}}function kP(A){var g=[],B=vP(A,g),Q=B.extractPNetParams,w=B.extractRNetParams,C=B.extractONetParams,E=Q(),e=w(),I=C();return UQ(A,g),{params:{pnet:E,rnet:e,onet:I},paramMappings:g}}function Fn(A,g){var B=g[0],Q=g[1];return{height:Math.floor(B*A),width:Math.floor(Q*A)}}function TP(A,g,B){for(var Q=B[0],w=B[1],C=Xe/A,E=[],e=Math.min(Q,w)*C,I=0;e>=12;)E.push(C*Math.pow(g,I)),e=e*g,I+=1;return E}var an=function(A){yA(g,A);function g(B,Q,w,C){return A.call(this,{left:B,top:Q,right:w,bottom:C},!0)||this}return g}(wQ);function br(A){return DA(function(){return wg(zB(A,nA(127.5)),nA(.0078125))})}function gC(A,g){return DA(function(){return OA(GB(A),wg(g,Fe(GB(Fe(A)))))})}function sn(A,g,B){return B===void 0&&(B=!1),DA(function(){var Q=Kg(A,g.conv1,"valid");return Q=gC(Q,g.prelu1_alpha),Q=VB(Q,B?[2,2]:[3,3],[2,2],"same"),Q=Kg(Q,g.conv2,"valid"),Q=gC(Q,g.prelu2_alpha),Q=B?Q:VB(Q,[3,3],[2,2],"valid"),Q=Kg(Q,g.conv3,"valid"),Q=gC(Q,g.prelu3_alpha),Q})}function jP(A,g){return DA(function(){var B=sn(A,g,!0),Q=Kg(B,g.conv4_1,"valid"),w=Tg(le(Q,3),3),C=rQ(zB(Q,w),3),E=Kg(B,g.conv4_2,"valid");return{prob:C,regions:E}})}function pP(A,g){return DA(function(){var B=Fn(g,A.shape.slice(1)),Q=B.height,w=B.width,C=Rt.resizeBilinear(A,[Q,w]),E=br(C);return vQ(E,[0,2,1,3])})}function yP(A,g,B,Q){for(var w=[],C=A.arraySync(),E=0;E<A.shape[0];E++)for(var e=0;e<A.shape[1];e++)C[E][e]>=Q&&w.push(new QB(e,E));var I=w.map(function(o){var n=new Re(Math.round((o.y*xe+1)/B),Math.round((o.x*xe+1)/B),Math.round((o.y*xe+Xe)/B),Math.round((o.x*xe+Xe)/B)),i=C[o.y][o.x],Y=g.arraySync(),M=new an(Y[o.y][o.x][0],Y[o.y][o.x][1],Y[o.y][o.x][2],Y[o.y][o.x][3]);return{cell:n,score:i,region:M}});return I}function zP(A,g,B,Q,w){w.stage1=[];var C=g.map(function(Y){return DA(function(){var M={scale:Y},c=pP(A,Y),D=Date.now(),r=jP(c,Q),F=r.prob,s=r.regions;M.pnet=Date.now()-D;var u=pB(pB(F,3)[1])[0],a=pB(s)[0];return{scoresTensor:u,regionsTensor:a,scale:Y,statsForScale:M}})}),E=C.map(function(Y){var M=Y.scoresTensor,c=Y.regionsTensor,D=Y.scale,r=Y.statsForScale,F=yP(M,c,D,B);if(M.dispose(),c.dispose(),!F.length)return w.stage1.push(r),[];var s=Date.now(),u=xC(F.map(function(a){return a.cell}),F.map(function(a){return a.score}),.5);return r.nms=Date.now()-s,r.numBoxes=u.length,w.stage1.push(r),u.map(function(a){return F[a]})}),e=E.reduce(function(Y,M){return Y.concat(M)},[]),I=[],o=[];if(e.length>0){var n=Date.now(),i=xC(e.map(function(Y){return Y.cell}),e.map(function(Y){return Y.score}),.7);w.stage1_nms=Date.now()-n,o=i.map(function(Y){return e[Y].score}),I=i.map(function(Y){return e[Y]}).map(function(Y){var M=Y.cell,c=Y.region;return new Re(M.left+c.left*M.width,M.top+c.top*M.height,M.right+c.right*M.width,M.bottom+c.bottom*M.height).toSquare().round()})}return{boxes:I,scores:o}}function Kr(A,g,B){var Q=B.width,w=B.height;return dA(this,void 0,void 0,function(){var C,E,e,I=this;return HA(this,function(o){switch(o.label){case 0:return C=CQ(A),[4,Promise.all(g.map(function(n){return dA(I,void 0,void 0,function(){var i,Y,M,c,D,r,F,s;return HA(this,function(u){return i=n.padAtBorders(A.height,A.width),Y=i.y,M=i.ey,c=i.x,D=i.ex,r=c-1,F=Y-1,s=C.getImageData(r,F,D-r,M-F),[2,eg.isNodejs()?Te(s):createImageBitmap(s)]})})}))];case 1:return E=o.sent(),e=[],E.forEach(function(n){var i=ke({width:Q,height:w}),Y=CQ(i);Y.drawImage(n,0,0,Q,w);for(var M=Y.getImageData(0,0,Q,w).data,c=[],D=0;D<M.length;D+=4)c.push(M[D+2]),c.push(M[D+1]),c.push(M[D]);e.push(c)}),[2,e.map(function(n){var i=DA(function(){var Y=vQ(Dg(n,[1,Q,w,3]),[0,2,1,3]).toFloat();return br(Y)});return i})]}})})}function WP(A,g){return DA(function(){var B=sn(A,g),Q=Sg(B,[B.shape[0],g.fc1.weights.shape[0]]),w=EQ(Q,g.fc1),C=gC(w,g.prelu4_alpha),E=EQ(C,g.fc2_1),e=Tg(le(E,1),1),I=rQ(zB(E,e),1),o=EQ(C,g.fc2_2),n=pB(I,1)[1];return{scores:n,regions:o}})}function SP(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s;return HA(this,function(u){switch(u.label){case 0:return C=Date.now(),[4,Kr(A,g,{width:24,height:24})];case 1:return E=u.sent(),w.stage2_extractImagePatches=Date.now()-C,C=Date.now(),e=E.map(function(a){var U=WP(a,Q);return a.dispose(),U}),w.stage2_rnet=Date.now()-C,I=e.length>1?jB(e.map(function(a){return a.scores})):e[0].scores,i=(n=Array).from,[4,I.data()];case 2:return o=i.apply(n,[u.sent()]),I.dispose(),Y=o.map(function(a,U){return{score:a,idx:U}}).filter(function(a){return a.score>B}).map(function(a){var U=a.idx;return U}),M=Y.map(function(a){return g[a]}),c=Y.map(function(a){return o[a]}),D=[],r=[],M.length>0&&(C=Date.now(),F=xC(M,c,.7),w.stage2_nms=Date.now()-C,s=F.map(function(a){var U=e[Y[a]].regions.arraySync();return new an(U[0][0],U[0][1],U[0][2],U[0][3])}),r=F.map(function(a){return c[a]}),D=F.map(function(a,U){return M[a].calibrate(s[U])})),e.forEach(function(a){a.regions.dispose(),a.scores.dispose()}),[2,{boxes:D,scores:r}]}})})}function LP(A,g){return DA(function(){var B=sn(A,g);B=VB(B,[2,2],[2,2],"same"),B=Kg(B,g.conv4,"valid"),B=gC(B,g.prelu4_alpha);var Q=Sg(B,[B.shape[0],g.fc1.weights.shape[0]]),w=EQ(Q,g.fc1),C=gC(w,g.prelu5_alpha),E=EQ(C,g.fc2_1),e=Tg(le(E,1),1),I=rQ(zB(E,e),1),o=EQ(C,g.fc2_2),n=EQ(C,g.fc2_3),i=pB(I,1)[1];return{scores:i,regions:o,points:n}})}function bP(A,g,B,Q,w){return dA(this,void 0,void 0,function(){var C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u;return HA(this,function(a){switch(a.label){case 0:return C=Date.now(),[4,Kr(A,g,{width:48,height:48})];case 1:return E=a.sent(),w.stage3_extractImagePatches=Date.now()-C,C=Date.now(),e=E.map(function(U){var G=LP(U,Q);return U.dispose(),G}),w.stage3_onet=Date.now()-C,I=e.length>1?jB(e.map(function(U){return U.scores})):e[0].scores,i=(n=Array).from,[4,I.data()];case 2:return o=i.apply(n,[a.sent()]),I.dispose(),Y=o.map(function(U,G){return{score:U,idx:G}}).filter(function(U){return U.score>B}).map(function(U){var G=U.idx;return G}),M=Y.map(function(U){var G=e[U].regions.arraySync();return new an(G[0][0],G[0][1],G[0][2],G[0][3])}),c=Y.map(function(U,G){return g[U].calibrate(M[G])}),D=Y.map(function(U){return o[U]}),r=[],F=[],s=[],c.length>0&&(C=Date.now(),u=xC(c,D,.7,!1),w.stage3_nms=Date.now()-C,r=u.map(function(U){return c[U]}),F=u.map(function(U){return D[U]}),s=u.map(function(U,G){return Array(5).fill(0).map(function(d,H){var h=e[U].points.arraySync();return new QB(h[0][H]*(r[G].width+1)+r[G].left,h[0][H+5]*(r[G].height+1)+r[G].top)})})),e.forEach(function(U){U.regions.dispose(),U.scores.dispose(),U.points.dispose()}),[2,{boxes:r,scores:F,points:s}]}})})}var KP=function(A){yA(g,A);function g(){return A.call(this,"Mtcnn")||this}return g.prototype.load=function(B){return dA(this,void 0,void 0,function(){return HA(this,function(Q){return console.warn("mtcnn is deprecated and will be removed soon"),[2,A.prototype.load.call(this,B)]})})},g.prototype.loadFromDisk=function(B){return dA(this,void 0,void 0,function(){return HA(this,function(Q){return console.warn("mtcnn is deprecated and will be removed soon"),[2,A.prototype.loadFromDisk.call(this,B)]})})},g.prototype.forwardInput=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w,C,E,e,I,o,n,i,Y,M,c,D,r,F,s,u,a,U,G,d,H;return HA(this,function(h){switch(h.label){case 0:if(w=this.params,!w)throw new Error("Mtcnn - load model before inference");if(C=B.canvases[0],!C)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return E={},e=Date.now(),I=DA(function(){return mP(Tg(Zt.fromPixels(C)).toFloat())}),o=function(l){return I.dispose(),E.total=Date.now()-e,l},n=I.shape.slice(1),i=n[0],Y=n[1],M=new yr(Q),c=M.minFaceSize,D=M.scaleFactor,r=M.maxNumScales,F=M.scoreThresholds,s=M.scaleSteps,u=(s||TP(c,D,[i,Y])).filter(function(l){var m=Fn(l,[i,Y]);return Math.min(m.width,m.height)>Xe}).slice(0,r),E.scales=u,E.pyramid=u.map(function(l){return Fn(l,[i,Y])}),a=Date.now(),[4,zP(I,u,F[0],w.pnet,E)];case 1:return U=h.sent(),E.total_stage1=Date.now()-a,U.boxes.length?(E.stage2_numInputBoxes=U.boxes.length,a=Date.now(),[4,SP(C,U.boxes,F[1],w.rnet,E)]):[2,o({results:[],stats:E})];case 2:return G=h.sent(),E.total_stage2=Date.now()-a,G.boxes.length?(E.stage3_numInputBoxes=G.boxes.length,a=Date.now(),[4,bP(C,G.boxes,F[2],w.onet,E)]):[2,o({results:[],stats:E})];case 3:return d=h.sent(),E.total_stage3=Date.now()-a,H=d.boxes.map(function(l,m){return We(ZC({},new Jg(d.scores[m],new Pe(l.left/Y,l.top/i,l.width/Y,l.height/i),{height:i,width:Y})),new DR(d.points[m].map(function(f){return f.sub(new QB(l.left,l.top)).div(new QB(l.width,l.height))}),{width:l.width,height:l.height}))}),[2,o({results:H,stats:E})]}})})},g.prototype.forward=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[4,w.apply(this,[C.sent(),Q])];case 2:return[2,C.sent().results]}})})},g.prototype.forwardWithStats=function(B,Q){return Q===void 0&&(Q={}),dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return w=this.forwardInput,[4,xB(B)];case 1:return[2,w.apply(this,[C.sent(),Q])]}})})},g.prototype.getDefaultModelName=function(){return"mtcnn_model"},g.prototype.extractParamsFromWeigthMap=function(B){return kP(B)},g.prototype.extractParams=function(B){return PP(B)},g}(uQ),VP=.4,xP=[new QB(1.603231,2.094468),new QB(6.041143,7.080126),new QB(2.882459,3.518061),new QB(4.266906,5.178857),new QB(9.041765,10.66308)],XP=[117.001,114.697,97.404],OP=function(A){yA(g,A);function g(){var B=this,Q={withSeparableConvs:!0,iouThreshold:VP,classes:["face"],anchors:xP,meanRgb:XP,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return B=A.call(this,Q)||this,B}return Object.defineProperty(g.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),g.prototype.locateFaces=function(B,Q){return dA(this,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.detect(B,Q)];case 1:return w=C.sent(),[2,w.map(function(E){return new Jg(E.score,E.relativeBox,{width:E.imageWidth,height:E.imageHeight})})]}})})},g.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},g.prototype.extractParamsFromWeigthMap=function(B){return A.prototype.extractParamsFromWeigthMap.call(this,B)},g}(Sr),Ig={ssdMobilenetv1:new zr,tinyFaceDetector:new OP,tinyYolov2:new NP,mtcnn:new KP,faceLandmark68Net:new Pr,faceLandmark68TinyNet:new qR,faceRecognitionNet:new wP,faceExpressionNet:new PR,ageGenderNet:new xR},Vr=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.extractedFaces=w,C}return g}(qC),un=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w=this;return HA(this,function(C){switch(C.label){case 0:return[4,this.parentTask];case 1:return B=C.sent(),[4,Ve(B,this.input,function(E){return dA(w,void 0,void 0,function(){return HA(this,function(e){switch(e.label){case 0:return[4,Promise.all(E.map(function(I){return Ig.faceExpressionNet.predictExpressions(I)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return Q=C.sent(),[2,B.map(function(E,e){return Nr(E,Q[e])})]}})})},g.prototype.withAgeAndGender=function(){return new ln(this,this.input)},g}(Vr),Un=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),B?[4,rn(B,this.input,function(C){return Ig.faceExpressionNet.predictExpressions(C)},this.extractedFaces)]:[2];case 2:return Q=w.sent(),[2,Nr(B,Q)]}})})},g.prototype.withAgeAndGender=function(){return new dn(this,this.input)},g}(Vr),Gn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g.prototype.withFaceDescriptors=function(){return new Jn(this,this.input)},g}(un),hn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withAgeAndGender=function(){return new fn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Nn(this,this.input)},g}(Un),xr=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.extractedFaces=w,C}return g}(qC),ln=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w=this;return HA(this,function(C){switch(C.label){case 0:return[4,this.parentTask];case 1:return B=C.sent(),[4,Ve(B,this.input,function(E){return dA(w,void 0,void 0,function(){return HA(this,function(e){switch(e.label){case 0:return[4,Promise.all(E.map(function(I){return Ig.ageGenderNet.predictAgeAndGender(I)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return Q=C.sent(),[2,B.map(function(E,e){var I=Q[e],o=I.age,n=I.gender,i=I.genderProbability;return jr(pr(E,n,i),o)})]}})})},g.prototype.withFaceExpressions=function(){return new un(this,this.input)},g}(xr),dn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E;return HA(this,function(e){switch(e.label){case 0:return[4,this.parentTask];case 1:return B=e.sent(),B?[4,rn(B,this.input,function(I){return Ig.ageGenderNet.predictAgeAndGender(I)},this.extractedFaces)]:[2];case 2:return Q=e.sent(),w=Q.age,C=Q.gender,E=Q.genderProbability,[2,jr(pr(B,C,E),w)]}})})},g.prototype.withFaceExpressions=function(){return new Un(this,this.input)},g}(xr),Hn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withFaceDescriptors=function(){return new Jn(this,this.input)},g}(ln),fn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.withFaceExpressions=function(){return new hn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Nn(this,this.input)},g}(dn),Xr=function(A){yA(g,A);function g(B,Q){var w=A.call(this)||this;return w.parentTask=B,w.input=Q,w}return g}(qC),Jn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),[4,Ve(B,this.input,function(C){return Promise.all(C.map(function(E){return Ig.faceRecognitionNet.computeFaceDescriptor(E)}))},null,function(C){return C.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return Q=w.sent(),[2,Q.map(function(C,E){return Tr(B[E],C)})]}})})},g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g}(Xr),Nn=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,this.parentTask];case 1:return B=w.sent(),B?[4,rn(B,this.input,function(C){return Ig.faceRecognitionNet.computeFaceDescriptor(C)},null,function(C){return C.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return Q=w.sent(),[2,Tr(B,Q)]}})})},g.prototype.withFaceExpressions=function(){return new hn(this,this.input)},g.prototype.withAgeAndGender=function(){return new fn(this,this.input)},g}(Xr),Or=function(A){yA(g,A);function g(B,Q,w){var C=A.call(this)||this;return C.parentTask=B,C.input=Q,C.useTinyLandmarkNet=w,C}return Object.defineProperty(g.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?Ig.faceLandmark68TinyNet:Ig.faceLandmark68Net},enumerable:!0,configurable:!0}),g}(qC),ZP=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E,e=this;return HA(this,function(I){switch(I.label){case 0:return[4,this.parentTask];case 1:return B=I.sent(),Q=B.map(function(o){return o.detection}),this.input instanceof uB?[4,Cn(this.input,Q)]:[3,3];case 2:return C=I.sent(),[3,5];case 3:return[4,pe(this.input,Q)];case 4:C=I.sent(),I.label=5;case 5:return w=C,[4,Promise.all(w.map(function(o){return e.landmarkNet.detectLandmarks(o)}))];case 6:return E=I.sent(),w.forEach(function(o){return o instanceof uB&&o.dispose()}),[2,B.map(function(o,n){return We(o,E[n])})]}})})},g.prototype.withFaceExpressions=function(){return new Gn(this,this.input)},g.prototype.withAgeAndGender=function(){return new Hn(this,this.input)},g.prototype.withFaceDescriptors=function(){return new Jn(this,this.input)},g}(Or),qP=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C,E;return HA(this,function(e){switch(e.label){case 0:return[4,this.parentTask];case 1:return B=e.sent(),B?(Q=B.detection,this.input instanceof uB?[4,Cn(this.input,[Q])]:[3,3]):[2];case 2:return C=e.sent(),[3,5];case 3:return[4,pe(this.input,[Q])];case 4:C=e.sent(),e.label=5;case 5:return w=C,[4,this.landmarkNet.detectLandmarks(w[0])];case 6:return E=e.sent(),w.forEach(function(I){return I instanceof uB&&I.dispose()}),[2,We(B,E)]}})})},g.prototype.withFaceExpressions=function(){return new hn(this,this.input)},g.prototype.withAgeAndGender=function(){return new fn(this,this.input)},g.prototype.withFaceDescriptor=function(){return new Nn(this,this.input)},g}(Or),Zr=function(A){yA(g,A);function g(B,Q){Q===void 0&&(Q=new be);var w=A.call(this)||this;return w.input=B,w.options=Q,w}return g}(qC),qr=function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q,w,C;return HA(this,function(E){switch(E.label){case 0:return B=this,Q=B.input,w=B.options,w instanceof yr?[4,Ig.mtcnn.forward(Q,w)]:[3,2];case 1:return[2,E.sent().map(function(e){return e.detection})];case 2:if(C=w instanceof Lr?function(e){return Ig.tinyFaceDetector.locateFaces(e,w)}:w instanceof be?function(e){return Ig.ssdMobilenetv1.locateFaces(e,w)}:w instanceof Dn?function(e){return Ig.tinyYolov2.locateFaces(e,w)}:null,!C)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,C(Q)]}})})},g.prototype.runAndExtendWithFaceDetections=function(){var B=this;return new Promise(function(Q){return dA(B,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.run()];case 1:return w=C.sent(),[2,Q(w.map(function(E){return ZC({},E)}))]}})})})},g.prototype.withFaceLandmarks=function(B){return B===void 0&&(B=!1),new ZP(this.runAndExtendWithFaceDetections(),this.input,B)},g.prototype.withFaceExpressions=function(){return new un(this.runAndExtendWithFaceDetections(),this.input)},g.prototype.withAgeAndGender=function(){return new ln(this.runAndExtendWithFaceDetections(),this.input)},g}(Zr);(function(A){yA(g,A);function g(){return A!==null&&A.apply(this,arguments)||this}return g.prototype.run=function(){return dA(this,void 0,void 0,function(){var B,Q;return HA(this,function(w){switch(w.label){case 0:return[4,new qr(this.input,this.options)];case 1:return B=w.sent(),Q=B[0],B.forEach(function(C){C.score>Q.score&&(Q=C)}),[2,Q]}})})},g.prototype.runAndExtendWithFaceDetection=function(){var B=this;return new Promise(function(Q){return dA(B,void 0,void 0,function(){var w;return HA(this,function(C){switch(C.label){case 0:return[4,this.run()];case 1:return w=C.sent(),[2,Q(w?ZC({},w):void 0)]}})})})},g.prototype.withFaceLandmarks=function(B){return B===void 0&&(B=!1),new qP(this.runAndExtendWithFaceDetection(),this.input,B)},g.prototype.withFaceExpressions=function(){return new Un(this.runAndExtendWithFaceDetection(),this.input)},g.prototype.withAgeAndGender=function(){return new dn(this.runAndExtendWithFaceDetection(),this.input)},g})(Zr);function _P(A,g){return g===void 0&&(g=new be),new qr(A,g)}function $P(A,g){if(A.length!==g.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var B=Array.from(A),Q=Array.from(g);return Math.sqrt(B.map(function(w,C){return w-Q[C]}).reduce(function(w,C){return w+Math.pow(C,2)},0))}(function(){function A(g,B){B===void 0&&(B=.6),this._distanceThreshold=B;var Q=Array.isArray(g)?g:[g];if(!Q.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var w=1,C=function(){return"person "+w++};this._labeledDescriptors=Q.map(function(E){if(E instanceof ve)return E;if(E instanceof Float32Array)return new ve(C(),[E]);if(E.descriptor&&E.descriptor instanceof Float32Array)return new ve(C(),[E.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>")})}return Object.defineProperty(A.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(A.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),A.prototype.computeMeanDistance=function(g,B){return B.map(function(Q){return $P(Q,g)}).reduce(function(Q,w){return Q+w},0)/(B.length||1)},A.prototype.matchDescriptor=function(g){var B=this;return this.labeledDescriptors.map(function(Q){var w=Q.descriptors,C=Q.label;return new tr(C,B.computeMeanDistance(g,w))}).reduce(function(Q,w){return Q.distance<w.distance?Q:w})},A.prototype.findBestMatch=function(g){var B=this.matchDescriptor(g);return B.distance<this.distanceThreshold?B:new tr("unknown",B.distance)},A.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(g){return g.toJSON()})}},A.fromJSON=function(g){var B=g.labeledDescriptors.map(function(Q){return ve.fromJSON(Q)});return new A(B,g.distanceThreshold)},A})();function _r(A,g){var B=new Yw(g.width,g.height),Q=B.width,w=B.height;if(Q<=0||w<=0)throw new Error("resizeResults - invalid dimensions: "+JSON.stringify({width:Q,height:w}));if(Array.isArray(A))return A.map(function(e){return _r(e,{width:Q,height:w})});if(nn(A)){var C=A.detection.forSize(Q,w),E=A.unshiftedLandmarks.forSize(C.box.width,C.box.height);return We(ZC(A,C),E)}return OC(A)?ZC(A,A.detection.forSize(Q,w)):A instanceof AC||A instanceof Jg?A.forSize(Q,w):A}class Av{getVideoStreamConfig(g,B){return{audio:!1,video:{width:{min:g,ideal:g},height:{min:B,ideal:B},facingMode:"environment"}}}getContourCoordinate(g,B){return{x:g*.25,y:B*.05,width:g*.5,height:B*.9}}getBoxData(g){return g?{x:g.x,y:g.y,width:g.width,height:g.height}:null}setStylesForCanvas(g){g.width="100%",g.height="100%",g.style.position="absolute",g.style.top="0",g.style.left="0"}checkFaceInclusion(g,B){if(!g||!B||B.width>g.width||B.height>g.height)return!1;const Q=B.x,w=B.x+B.width,C=B.y,E=B.y+B.height,e=g.x,I=g.x+g.width,o=g.y,n=g.y+g.height;return Q>=e&&w<=I&&C>=o&&E<=n}async getFaceDetections(g){return g?_P(g,new Lr).withFaceLandmarks().withFaceExpressions():[]}getCanvas(g){return Te(g)}getResizedAndDetection(g,B,Q,w,C){fR(g,{width:w,height:C});const E=_r(B,{width:w,height:C});Q.clearRect(0,0,w,C),uR(g,E),pR(g,E),kR(g,E)}async getFaceSnapshot(g,B){const Q=[new Pe(B.x,B.y,B.width,B.height)],w=await pe(g,Q);return w.length?w[0].toDataURL("image/jpeg").replace(/^data:image\/\w+;base64,/,""):null}async initModels(){let g=new Date;console.log(g);try{await Promise.all([Ig.tinyFaceDetector.loadFromUri("/models"),Ig.faceLandmark68Net.loadFromUri("/models"),Ig.faceRecognitionNet.loadFromUri("/models"),Ig.faceExpressionNet.loadFromUri("/models")])}catch(B){console.error(B)}g=new Date,console.log(g)}}let mn;function Bv(){return mn||(mn=new Av),mn}class gv extends Gg{async fetchUserInstrumentsHistory(g,B){const Q={status:"issued",page:B,desc:"desc",column:"updated_at"};return await this.get(`users/${g}/instruments`,{params:Q})}}let Rn;function Qv(){return Rn||(Rn=new gv),Rn}class wv extends Gg{fetchControlZones(g){return this.get("/frame/list",{params:g})}async fetchControlZone(g){return this.get(`/frame/${g}`)}createControlZone(g){return this.post("/frame",g)}editControlZone(g,B){return this.put(`/frame/${g}`,B)}deleteControlZone(g){return this.delete(`/frame/${g}`)}fetchControlLogs(g){return this.get("/exposed_equipment_zones/list",{params:g})}fetchControllers(g){return this.get("/frame/controllers/list",{params:g})}fetchUsersWithPasses(){return this.get("inspector/users-with-passes")}fetchWarehousesList(){return this.get("tasks/warehouse/list?only_outside_exposed_equipment_zone=1")}manualEntry(g){return this.post("exposed_equipment_zones/hand/enter",g)}manualExit(g){return this.post("exposed_equipment_zones/hand/exit",g)}deleteControlLogs(g){return this.delete("exposed_equipment_zones",g)}fetchInstrumentTypeList(g){return this.get("search/instrument_types",{params:g})}}let Pn;function Cv(){return Pn||(Pn=new wv),Pn}class Ev extends Gg{fetchSearchUsers(g){return this.get("search/users",{params:g})}}let vn;function ev(){return vn||(vn=new Ev),vn}function Iv(A){const g=t.ref(""),B=t.ref(1),Q=async(E="",e=1)=>{await A.initialize({search:E,page:e})},w=async E=>{g.value=E,B.value=1,await Q(E,B.value)},C=async E=>{B.value=E,await Q(g.value,E)};return t.watch(()=>A.columnFilters.value,()=>Q(g.value,B.value),{deep:!0}),t.onMounted(()=>Q(g.value,B.value)),{search:g,currentPage:B,loading:A.loading,handleSearch:w,handlePageChange:C,loadTable:Q}}const ov=A=>{const g=t.ref({}),B=t.ref({});A.columns.forEach(({name:I,filterType:o})=>{o&&(g.value[I]=o==="multi"?[]:void 0,B.value[I]=!1)});const Q=t.computed(()=>Array.isArray(A.rows)?A.rows:A.rows.value),w=(I,o)=>{const n=A.columns.find(i=>i.name===I);if((n==null?void 0:n.filterType)==="multi"){const i=g.value[I],Y=i.indexOf(o);Y>-1?i.splice(Y,1):i.push(o),g.value[I]=[...i]}else g.value[I]=o,B.value[I]=!1},C=t.computed(()=>{var o;const I={};for(const n of A.columns){const i=g.value[n.name],Y=((o=A.filtersOptions)==null?void 0:o.value[n.name])||[];i&&(I[n.name]=Array.isArray(i)?Y.filter(M=>i.includes(M.name)).map(M=>M.id):Y.filter(M=>M.name===i).map(M=>M.id))}return I}),E=I=>{const o=A.columns.find(n=>n.name===I);g.value[I]=(o==null?void 0:o.filterType)==="multi"?[]:void 0},e=(I,o)=>{B.value[I]=o};return{rows:Q,columns:t.computed(()=>A.columns),columnFilters:g,filterMenus:B,toggleFilterValue:w,clearFilter:E,openFilterMenu:e,selectedFilters:C}};function tv(A,g=[]){const B=t.ref([...new Set([...g,...A.map(C=>C.name)])]),Q=t.computed(()=>A.filter(C=>B.value.includes(C.name)));function w(C){C.dialog({title:"Выберите колонки",options:{type:"checkbox",model:[...B.value],items:A.map(E=>({label:E.label,value:E.name,disable:g.includes(E.name)}))},cancel:!0,persistent:!0}).onOk(E=>{B.value=Array.from(new Set([...E,...g]))})}return{selectedColumnNames:B,visibleColumns:Q,openColumnSelectorDialog:w}}fA.ApiService=Gg,fA.AppButton=ME,fA.AppCheckbox=$F,fA.AppConfirmDialog=lG,fA.AppDatePicker=ua,fA.AppDatepicker=Oa,fA.AppDropdown=NG,fA.AppInput=Za,fA.AppInputNew=DY,fA.AppInputSearch=qa,fA.AppLayout=gs,fA.AppLayoutHeader=pU,fA.AppLayoutPage=WU,fA.AppLoader=uY,fA.AppModalSelect=pY,fA.AppSelect=XU,fA.AppSheet=gG,fA.AppSidebar=oG,fA.AppTable=OY,fA.AppTableLayout=zh,fA.AppTableModal=VG,fA.AppTablePagination=TY,fA.AppTableSearch=jY,fA.AppToggle=tG,fA.AppWrapper=MG,fA.base64ToBlob=ba,fA.isEqual=fE,fA.normalizeValue=Nw,fA.notificationSettings=VI,fA.useAuthService=ud,fA.useBaseTable=Iv,fA.useColumnSelector=tv,fA.useControlsService=Cv,fA.useFileService=Gd,fA.useGanttService=nd,fA.useInstrumentsService=Qv,fA.useMetricsService=Yd,fA.usePhotoService=Bv,fA.useProjectsService=cd,fA.useRepairsService=rd,fA.useSearchService=ev,fA.useTableModel=ov,fA.useTasksService=ad,fA.useUserService=Hd,fA.useVideoService=ld,fA.uuidv4=KI,Object.defineProperty(fA,Symbol.toStringTag,{value:"Module"})});