UNPKG

@brandvc/webgazer2

Version:
235 lines 1.88 MB
/*! WebGazer.js: Democratizing Webcam Eye Tracking on the Browser Copyright (c) 2016, Brown WebGazer Team Licensed under GPLv3. Companies with a valuation of less than $1M can use WebGazer.js under LGPLv3. */ (function(De,Bn){typeof exports=="object"&&typeof module<"u"?Bn(exports):typeof define=="function"&&define.amd?define(["exports"],Bn):(De=typeof globalThis<"u"?globalThis:De||self,Bn(De.webgazer2={}))})(this,function(De){"use strict";var oK=Object.defineProperty;var aK=(De,Bn,ko)=>Bn in De?oK(De,Bn,{enumerable:!0,configurable:!0,writable:!0,value:ko}):De[Bn]=ko;var Fe=(De,Bn,ko)=>aK(De,typeof Bn!="symbol"?Bn+"":Bn,ko);function Bn(n,e){for(var t=0;t<e.length;t++){const s=e[t];if(typeof s!="string"&&!Array.isArray(s)){for(const r in s)if(r!=="default"&&!(r in n)){const o=Object.getOwnPropertyDescriptor(s,r);o&&Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:()=>s[r]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}/** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const ko=1e-7,f$=1e-4;class Yg{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t)}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}}class Wh{refCount(e){return Vn("refCount")}incRef(e){return Vn("incRef")}timerAvailable(){return!0}time(e){return Vn("time")}read(e){return Vn("read")}readSync(e){return Vn("readSync")}readToGPU(e,t){return Vn("readToGPU")}numDataIds(){return Vn("numDataIds")}disposeData(e,t){return Vn("disposeData")}write(e,t,s){return Vn("write")}move(e,t,s,r,o){return Vn("move")}memory(){return Vn("memory")}floatPrecision(){return Vn("floatPrecision")}epsilon(){return this.floatPrecision()===32?ko:f$}dispose(){return Vn("dispose")}}function Vn(n){throw new Error(`'${n}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}/** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function m$(n){let e=n.length,t=0;for(;e>0;)t=Math.random()*e|0,e--,To(n,e,t)}function Hr(n,e,t){return Math.max(n,Math.min(e,t))}function Uh(n){return n%2===0?n:n+1}function To(n,e,t){const s=n[e];n[e]=n[t],n[t]=s}function g$(n){let e=0;for(let t=0;t<n.length;t++)e+=n[t];return e}function N(n,e){if(!n)throw new Error(typeof e=="string"?e:e())}function Nn(n,e,t=""){N(Ge(n,e),()=>t+` Shapes ${n} and ${e} must match`)}function Eo(n){N(n!=null,()=>"The input to the tensor constructor must be a non-null value.")}function Do(n,e=[],t=!1){if(e==null&&(e=[]),Array.isArray(n)||Ls(n)&&!t)for(let s=0;s<n.length;++s)Do(n[s],e,t);else e.push(n);return e}function Y(n){if(n.length===0)return 1;let e=n[0];for(let t=1;t<n.length;t++)e*=n[t];return e}function Ge(n,e){if(n===e)return!0;if(n==null||e==null||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}function Ao(n){return n%1===0}function Gh(n){const e=Math.ceil(Math.sqrt(n));return[e,Math.ceil(n/e)]}function Ro(n,e){return e<=n.length?n:n+" ".repeat(e-n.length)}function Zg(n,e=r=>0,t,s=setTimeout){return new Promise((r,o)=>{let a=0;const i=()=>{if(n()){r();return}a++;const l=e(a);if(t!=null&&a>=t){o();return}s(i,l)};i()})}function Qg(n,e){let t=1,s=-1;for(let o=0;o<n.length;++o)if(n[o]>=0)t*=n[o];else if(n[o]===-1){if(s!==-1)throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${o}`);s=o}else if(n[o]<0)throw Error(`Shapes can not be < 0. Found ${n[o]} at dim ${o}`);if(s===-1){if(e>0&&e!==t)throw Error(`Size(${e}) must match the product of shape ${n}`);return n}if(t===0)throw Error(`Cannot infer the missing size in [${n}] when there are 0 elements`);if(e%t!==0)throw Error(`The implicit shape can't be a fractional number. Got ${e} / ${t}`);const r=n.slice();return r[s]=e/t,r}function Me(n,e){const t=e.length;return n=n==null?e.map((s,r)=>r):[].concat(n),N(n.every(s=>s>=-t&&s<t),()=>`All values in axis param must be in range [-${t}, ${t}) but got axis ${n}`),N(n.every(s=>Ao(s)),()=>`All values in axis param must be integers but got axis ${n}`),n.map(s=>s<0?t+s:s)}function fr(n,e){const t=[],s=[],r=e!=null&&Array.isArray(e)&&e.length===0,o=e==null||r?null:Me(e,n).sort();let a=0;for(let i=0;i<n.length;++i){if(o!=null){if(o[a]===i&&n[i]!==1)throw new Error(`Can't squeeze axis ${i} since its dim '${n[i]}' is not 1`);(o[a]==null||o[a]>i)&&n[i]===1&&(t.push(n[i]),s.push(i)),o[a]<=i&&a++}n[i]!==1&&(t.push(n[i]),s.push(i))}return{newShape:t,keptDims:s}}function Vt(n,e){let t=null;if(n==null||n==="float32")t=new Float32Array(e);else if(n==="int32")t=new Int32Array(e);else if(n==="bool")t=new Uint8Array(e);else throw new Error(`Unknown data type ${n}`);return t}function Wt(n,e){let t=null;if(n==null||n==="float32")t=new Float32Array(e);else if(n==="int32")t=new Int32Array(e);else if(n==="bool")t=new Uint8Array(e);else if(n==="string")t=new Array(e);else throw new Error(`Unknown data type ${n}`);return t}function y$(n,e){for(let t=0;t<n.length;t++){const s=n[t];if(isNaN(s)||!isFinite(s))throw Error(`A tensor of type ${e} being uploaded contains ${s}.`)}}function b$(n){return n==="bool"||n==="complex64"||n==="float32"||n==="int32"||n==="string"}function Jg(n,e){return!(e==="complex64"||e==="float32"&&n!=="complex64"||e==="int32"&&n!=="float32"&&n!=="complex64"||e==="bool"&&n==="bool")}function Ls(n){return n instanceof Float32Array||n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray}function Hh(n){if(n==="float32"||n==="int32")return 4;if(n==="complex64")return 8;if(n==="bool")return 1;throw new Error(`Unknown dtype ${n}`)}function x$(n){if(n==null)return 0;let e=0;return n.forEach(t=>e+=t.length),e}function Fa(n){return typeof n=="string"||n instanceof String}function w$(n){return typeof n=="boolean"}function jh(n){return typeof n=="number"}function _a(n){return Array.isArray(n)?_a(n[0]):n instanceof Float32Array?"float32":n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray?"int32":jh(n)?"float32":Fa(n)?"string":w$(n)?"bool":"float32"}function qh(n){return!!(n&&n.constructor&&n.call&&n.apply)}function Kh(n,e){for(let t=e;t<n;++t)if(n%t===0)return t;return n}function Ne(n){const e=n.length;if(e<2)return[];const t=new Array(e-1);t[e-2]=n[e-1];for(let s=e-3;s>=0;--s)t[s]=t[s+1]*n[s+1];return t}function e0(n,e,t,s=!1){const r=new Array;if(e.length===1){const o=e[0]*(s?2:1);for(let a=0;a<o;a++)r[a]=t[n+a]}else{const o=e[0],a=e.slice(1),i=a.reduce((l,c)=>l*c)*(s?2:1);for(let l=0;l<o;l++)r[l]=e0(n+l*i,a,t,s)}return r}function Zn(n,e,t=!1){if(n.length===0)return e[0];const s=n.reduce((r,o)=>r*o)*(t?2:1);if(s===0)return[];if(s!==e.length)throw new Error(`[${n}] does not match the input size ${e.length}${t?" for a complex tensor":""}.`);return e0(0,n,e,t)}function Xh(n,e){const t=sn(n,e);for(let s=0;s<t.length;s++)t[s]=1;return t}function sn(n,e){if(e==null||e==="float32"||e==="complex64")return new Float32Array(n);if(e==="int32")return new Int32Array(n);if(e==="bool")return new Uint8Array(n);throw new Error(`Unknown data type ${e}`)}function t0(n,e){const t=n.reduce((s,r)=>s*r,1);if(e==null||e==="float32")return Zn(n,new Float32Array(t));if(e==="int32")return Zn(n,new Int32Array(t));if(e==="bool")return Zn(n,new Uint8Array(t));throw new Error(`Unknown data type ${e}`)}function n0(n){n.forEach(e=>{N(Number.isInteger(e)&&e>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${n}].`)})}function Ps(n,e,t){if(e===0)return 0;if(e===1)return n[0];let s=n[n.length-1];for(let r=0;r<n.length-1;++r)s+=t[r]*n[r];return s}function Fo(n,e,t){if(e===0)return[];if(e===1)return[n];const s=new Array(e);for(let r=0;r<s.length-1;++r)s[r]=Math.floor(n/t[r]),n-=s[r]*t[r];return s[s.length-1]=n,s}function _o(n){return n&&n.then&&typeof n.then=="function"}/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const s0="tfjsflags";class v${constructor(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=I$,this.populateURLFlags()}setPlatform(e,t){this.platform!=null&&(K().getBool("IS_TEST")||K().getBool("PROD")||console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${e}.`)),this.platformName=e,this.platform=t}registerFlag(e,t,s){if(this.flagRegistry[e]={evaluationFn:t,setHook:s},this.urlFlags[e]!=null){const r=this.urlFlags[e];K().getBool("IS_TEST")||K().getBool("PROD")||console.warn(`Setting feature override from URL ${e}: ${r}.`),this.set(e,r)}}async getAsync(e){return e in this.flags?this.flags[e]:(this.flags[e]=await this.evaluateFlag(e),this.flags[e])}get(e){if(e in this.flags)return this.flags[e];const t=this.evaluateFlag(e);if(_o(t))throw new Error(`Flag ${e} cannot be synchronously evaluated. Please use getAsync() instead.`);return this.flags[e]=t,this.flags[e]}getNumber(e){return this.get(e)}getBool(e){return this.get(e)}getFlags(){return this.flags}get features(){return this.flags}set(e,t){if(this.flagRegistry[e]==null)throw new Error(`Cannot set flag ${e} as it has not been registered.`);this.flags[e]=t,this.flagRegistry[e].setHook!=null&&this.flagRegistry[e].setHook(t)}evaluateFlag(e){if(this.flagRegistry[e]==null)throw new Error(`Cannot evaluate flag '${e}': no evaluation function found.`);return this.flagRegistry[e].evaluationFn()}setFlags(e){this.flags=Object.assign({},e)}reset(){this.flags={},this.urlFlags={},this.populateURLFlags()}populateURLFlags(){if(typeof this.global>"u"||typeof this.global.location>"u"||typeof this.global.location.search>"u")return;const e=this.getQueryParams(this.global.location.search);s0 in e&&e[s0].split(",").forEach(s=>{const[r,o]=s.split(":");this.urlFlags[r]=C$(r,o)})}}function I$(n){const e={};return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(t,...s)=>($$(e,s[0],s[1]),s.join("="))),e}function $$(n,e,t){n[decodeURIComponent(e)]=decodeURIComponent(t||"")}function C$(n,e){if(e=e.toLowerCase(),e==="true"||e==="false")return e==="true";if(`${+e}`===e)return+e;throw new Error(`Could not parse value flag value ${e} for flag ${n}.`)}function K(){return r0}let r0=null;function S$(n){r0=n}/** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */let Yh;function o0(){if(Yh==null){let n;if(typeof window<"u")n=window;else if(typeof global<"u")n=global;else if(typeof process<"u")n=process;else if(typeof self<"u")n=self;else throw new Error("Could not find a global object");Yh=n}return Yh}function N$(){const n=o0();return n._tfGlobals==null&&(n._tfGlobals=new Map),n._tfGlobals}function Zh(n,e){const t=N$();if(t.has(n))return t.get(n);{const s=e();return t.set(n,s),t.get(n)}}const zl="Abs",Oa="Acos",La="Acosh",Oo="Add",Ml="AddN",Qh="All",Jh="Any",Bl="ArgMax",Vl="ArgMin",Pa="Asin",za="Asinh",Ma="Atan",Ba="Atanh",Va="Atan2",Wl="AvgPool",ed="AvgPoolGrad",Ul="AvgPool3D",td="AvgPool3DGrad",Gl="BatchMatMul",Hl="BatchToSpaceND",nd="Bincount",k$="BroadcastTo",sd="BroadcastArgs",Wa="Cast",Ua="Ceil",Ga="ClipByValue",rd="Complex",jl="ComplexAbs",ql="Concat",Kl="Conv2D",od="Conv2DBackpropFilter",Xl="Conv2DBackpropInput",Yl="Conv3D",ad="Conv3DBackpropFilterV2",id="Conv3DBackpropInputV2",Ha="Cos",ja="Cosh",ld="Cumprod",Zl="Cumsum",cd="CropAndResize",ud="DenseBincount",hd="DepthToSpace",Ql="DepthwiseConv2dNative",dd="DepthwiseConv2dNativeBackpropFilter",pd="DepthwiseConv2dNativeBackpropInput",fd="Diag",Jl="Dilation2D",md="Dilation2DBackpropInput",gd="Dilation2DBackpropFilter",qa="RealDiv",yd="Einsum",Ka="Elu",bd="EluGrad",Xa="Erf",ec="Equal",Ya="Exp",tc="ExpandDims",Za="Expm1",xd="FFT",wd="Fill",vd="FlipLeftRight",Qa="Floor",Ja="FloorDiv",nc="FusedBatchNorm",sc="GatherV2",Id="GatherNd",rc="Greater",ei="GreaterEqual",ti="Identity",$d="IFFT",Cd="Imag",ni="IsFinite",si="IsInf",ri="IsNan",oc="LeakyRelu",ac="Less",ic="LessEqual",Sd="LinSpace",oi="Log",ai="Log1p",lc="LogicalAnd",cc="LogicalNot",uc="LogicalOr",T$="LogSoftmax",hc="LRN",Nd="LRNGrad",dc="Max",ii="Maximum",pc="MaxPool",kd="MaxPoolGrad",fc="MaxPool3D",Td="MaxPool3DGrad",Ed="MaxPoolWithArgmax",mc="Mean",gc="Min",li="Minimum",yc="MirrorPad",ci="Mod",Dd="Multinomial",ui="Multiply",bc="Neg",xc="NotEqual",Ad="NonMaxSuppressionV3",Rd="NonMaxSuppressionV4",Fd="NonMaxSuppressionV5",wc="OnesLike",vc="OneHot",Ic="Pack",$c="PadV2",hi="Pow",Cc="Prelu",Sc="Prod",_d="RaggedGather",Od="RaggedTensorToTensor",Ld="Range",Pd="Real",di="Reciprocal",pi="Relu",Nc="Reshape",kc="ResizeNearestNeighbor",zd="ResizeNearestNeighborGrad",Tc="ResizeBilinear",Md="ResizeBilinearGrad",fi="Relu6",Ec="Reverse",mi="Round",gi="Rsqrt",Bd="ScatterNd",Vd="SearchSorted",Dc="Select",yi="Selu",Ac="Slice",bi="Sin",xi="Sinh",wi="Sign",vi="Sigmoid",Ii="Softplus",$i="Sqrt",Rc="Sum",Fc="SpaceToBatchND",_c="SplitV",Oc="Softmax",Wd="SparseFillEmptyRows",Ud="SparseReshape",Gd="SparseSegmentMean",Hd="SparseSegmentSum",jd="SparseToDense",Ci="SquaredDifference",qd="Square",Kd="StridedSlice",Xd="StringNGrams",Yd="StringSplit",Zd="StringToHashBucketFast",Si="Sub",Ni="Tan",ki="Tanh",Ti="Tile",Qd="TopK",Jd="Transform",Lo="Transpose",ep="Unique",Lc="Unpack",Pc="UnsortedSegmentSum",zc="ZerosLike",Ei="Step",tp="FromPixels",np="RotateWithOffset",Mc="_FusedMatMul",Bc="FusedConv2D",Vc="FusedDepthwiseConv2D";/** * @license * Copyright 2018 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function Wn(...n){K().getBool("IS_TEST")||K().getBool("PROD")||console.warn(...n)}function E$(...n){K().getBool("IS_TEST")||K().getBool("PROD")||console.log(...n)}/** * @license * Copyright 2019 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const Wc=Zh("kernelRegistry",()=>new Map),sp=Zh("gradRegistry",()=>new Map);function rp(n,e){const t=c0(n,e);return Wc.get(t)}function a0(n){return sp.get(n)}function i0(n){const e=Wc.entries(),t=[];for(;;){const{done:s,value:r}=e.next();if(s)break;const[o,a]=r,[i]=o.split("_");i===n&&t.push(a)}return t}function l0(n){const{kernelName:e,backendName:t}=n,s=c0(e,t);Wc.has(s)&&Wn(`The kernel '${e}' for backend '${t}' is already registered`),Wc.set(s,n)}function D$(n){const{kernelName:e}=n;sp.has(e)&&K().getBool("DEBUG")&&Wn(`Overriding the gradient for '${e}'`),sp.set(e,n)}function c0(n,e){return`${e}_${n}`}var Qn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function u0(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function A$(n){if(n.__esModule)return n;var e=n.default;if(typeof e=="function"){var t=function s(){return this instanceof s?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(n).forEach(function(s){var r=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return n[s]}})}),t}var h0=dt,Jn=null;try{Jn=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function dt(n,e,t){this.low=n|0,this.high=e|0,this.unsigned=!!t}dt.prototype.__isLong__,Object.defineProperty(dt.prototype,"__isLong__",{value:!0});function kn(n){return(n&&n.__isLong__)===!0}dt.isLong=kn;var d0={},p0={};function jr(n,e){var t,s,r;return e?(n>>>=0,(r=0<=n&&n<256)&&(s=p0[n],s)?s:(t=pt(n,(n|0)<0?-1:0,!0),r&&(p0[n]=t),t)):(n|=0,(r=-128<=n&&n<128)&&(s=d0[n],s)?s:(t=pt(n,n<0?-1:0,!1),r&&(d0[n]=t),t))}dt.fromInt=jr;function es(n,e){if(isNaN(n))return e?qr:ts;if(e){if(n<0)return qr;if(n>=m0)return w0}else{if(n<=-g0)return Tn;if(n+1>=g0)return x0}return n<0?es(-n,e).neg():pt(n%Po|0,n/Po|0,e)}dt.fromNumber=es;function pt(n,e,t){return new dt(n,e,t)}dt.fromBits=pt;var Uc=Math.pow;function op(n,e,t){if(n.length===0)throw Error("empty string");if(n==="NaN"||n==="Infinity"||n==="+Infinity"||n==="-Infinity")return ts;if(typeof e=="number"?(t=e,e=!1):e=!!e,t=t||10,t<2||36<t)throw RangeError("radix");var s;if((s=n.indexOf("-"))>0)throw Error("interior hyphen");if(s===0)return op(n.substring(1),e,t).neg();for(var r=es(Uc(t,8)),o=ts,a=0;a<n.length;a+=8){var i=Math.min(8,n.length-a),l=parseInt(n.substring(a,a+i),t);if(i<8){var c=es(Uc(t,i));o=o.mul(c).add(es(l))}else o=o.mul(r),o=o.add(es(l))}return o.unsigned=e,o}dt.fromString=op;function bs(n,e){return typeof n=="number"?es(n,e):typeof n=="string"?op(n,e):pt(n.low,n.high,typeof e=="boolean"?e:n.unsigned)}dt.fromValue=bs;var f0=65536,R$=1<<24,Po=f0*f0,m0=Po*Po,g0=m0/2,y0=jr(R$),ts=jr(0);dt.ZERO=ts;var qr=jr(0,!0);dt.UZERO=qr;var zo=jr(1);dt.ONE=zo;var b0=jr(1,!0);dt.UONE=b0;var ap=jr(-1);dt.NEG_ONE=ap;var x0=pt(-1,2147483647,!1);dt.MAX_VALUE=x0;var w0=pt(-1,-1,!0);dt.MAX_UNSIGNED_VALUE=w0;var Tn=pt(0,-2147483648,!1);dt.MIN_VALUE=Tn;var pe=dt.prototype;pe.toInt=function(){return this.unsigned?this.low>>>0:this.low},pe.toNumber=function(){return this.unsigned?(this.high>>>0)*Po+(this.low>>>0):this.high*Po+(this.low>>>0)},pe.toString=function(e){if(e=e||10,e<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(Tn)){var t=es(e),s=this.div(t),r=s.mul(t).sub(this);return s.toString(e)+r.toInt().toString(e)}else return"-"+this.neg().toString(e);for(var o=es(Uc(e,6),this.unsigned),a=this,i="";;){var l=a.div(o),c=a.sub(l.mul(o)).toInt()>>>0,u=c.toString(e);if(a=l,a.isZero())return u+i;for(;u.length<6;)u="0"+u;i=""+u+i}},pe.getHighBits=function(){return this.high},pe.getHighBitsUnsigned=function(){return this.high>>>0},pe.getLowBits=function(){return this.low},pe.getLowBitsUnsigned=function(){return this.low>>>0},pe.getNumBitsAbs=function(){if(this.isNegative())return this.eq(Tn)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,t=31;t>0&&!(e&1<<t);t--);return this.high!=0?t+33:t+1},pe.isZero=function(){return this.high===0&&this.low===0},pe.eqz=pe.isZero,pe.isNegative=function(){return!this.unsigned&&this.high<0},pe.isPositive=function(){return this.unsigned||this.high>=0},pe.isOdd=function(){return(this.low&1)===1},pe.isEven=function(){return(this.low&1)===0},pe.equals=function(e){return kn(e)||(e=bs(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low},pe.eq=pe.equals,pe.notEquals=function(e){return!this.eq(e)},pe.neq=pe.notEquals,pe.ne=pe.notEquals,pe.lessThan=function(e){return this.comp(e)<0},pe.lt=pe.lessThan,pe.lessThanOrEqual=function(e){return this.comp(e)<=0},pe.lte=pe.lessThanOrEqual,pe.le=pe.lessThanOrEqual,pe.greaterThan=function(e){return this.comp(e)>0},pe.gt=pe.greaterThan,pe.greaterThanOrEqual=function(e){return this.comp(e)>=0},pe.gte=pe.greaterThanOrEqual,pe.ge=pe.greaterThanOrEqual,pe.compare=function(e){if(kn(e)||(e=bs(e)),this.eq(e))return 0;var t=this.isNegative(),s=e.isNegative();return t&&!s?-1:!t&&s?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},pe.comp=pe.compare,pe.negate=function(){return!this.unsigned&&this.eq(Tn)?Tn:this.not().add(zo)},pe.neg=pe.negate,pe.add=function(e){kn(e)||(e=bs(e));var t=this.high>>>16,s=this.high&65535,r=this.low>>>16,o=this.low&65535,a=e.high>>>16,i=e.high&65535,l=e.low>>>16,c=e.low&65535,u=0,h=0,d=0,p=0;return p+=o+c,d+=p>>>16,p&=65535,d+=r+l,h+=d>>>16,d&=65535,h+=s+i,u+=h>>>16,h&=65535,u+=t+a,u&=65535,pt(d<<16|p,u<<16|h,this.unsigned)},pe.subtract=function(e){return kn(e)||(e=bs(e)),this.add(e.neg())},pe.sub=pe.subtract,pe.multiply=function(e){if(this.isZero())return ts;if(kn(e)||(e=bs(e)),Jn){var t=Jn.mul(this.low,this.high,e.low,e.high);return pt(t,Jn.get_high(),this.unsigned)}if(e.isZero())return ts;if(this.eq(Tn))return e.isOdd()?Tn:ts;if(e.eq(Tn))return this.isOdd()?Tn:ts;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(y0)&&e.lt(y0))return es(this.toNumber()*e.toNumber(),this.unsigned);var s=this.high>>>16,r=this.high&65535,o=this.low>>>16,a=this.low&65535,i=e.high>>>16,l=e.high&65535,c=e.low>>>16,u=e.low&65535,h=0,d=0,p=0,f=0;return f+=a*u,p+=f>>>16,f&=65535,p+=o*u,d+=p>>>16,p&=65535,p+=a*c,d+=p>>>16,p&=65535,d+=r*u,h+=d>>>16,d&=65535,d+=o*c,h+=d>>>16,d&=65535,d+=a*l,h+=d>>>16,d&=65535,h+=s*u+r*c+o*l+a*i,h&=65535,pt(p<<16|f,h<<16|d,this.unsigned)},pe.mul=pe.multiply,pe.divide=function(e){if(kn(e)||(e=bs(e)),e.isZero())throw Error("division by zero");if(Jn){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var t=(this.unsigned?Jn.div_u:Jn.div_s)(this.low,this.high,e.low,e.high);return pt(t,Jn.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?qr:ts;var s,r,o;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return qr;if(e.gt(this.shru(1)))return b0;o=qr}else{if(this.eq(Tn)){if(e.eq(zo)||e.eq(ap))return Tn;if(e.eq(Tn))return zo;var a=this.shr(1);return s=a.div(e).shl(1),s.eq(ts)?e.isNegative()?zo:ap:(r=this.sub(e.mul(s)),o=s.add(r.div(e)),o)}else if(e.eq(Tn))return this.unsigned?qr:ts;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();o=ts}for(r=this;r.gte(e);){s=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var i=Math.ceil(Math.log(s)/Math.LN2),l=i<=48?1:Uc(2,i-48),c=es(s),u=c.mul(e);u.isNegative()||u.gt(r);)s-=l,c=es(s,this.unsigned),u=c.mul(e);c.isZero()&&(c=zo),o=o.add(c),r=r.sub(u)}return o},pe.div=pe.divide,pe.modulo=function(e){if(kn(e)||(e=bs(e)),Jn){var t=(this.unsigned?Jn.rem_u:Jn.rem_s)(this.low,this.high,e.low,e.high);return pt(t,Jn.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))},pe.mod=pe.modulo,pe.rem=pe.modulo,pe.not=function(){return pt(~this.low,~this.high,this.unsigned)},pe.and=function(e){return kn(e)||(e=bs(e)),pt(this.low&e.low,this.high&e.high,this.unsigned)},pe.or=function(e){return kn(e)||(e=bs(e)),pt(this.low|e.low,this.high|e.high,this.unsigned)},pe.xor=function(e){return kn(e)||(e=bs(e)),pt(this.low^e.low,this.high^e.high,this.unsigned)},pe.shiftLeft=function(e){return kn(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?pt(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):pt(0,this.low<<e-32,this.unsigned)},pe.shl=pe.shiftLeft,pe.shiftRight=function(e){return kn(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?pt(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):pt(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},pe.shr=pe.shiftRight,pe.shiftRightUnsigned=function(e){if(kn(e)&&(e=e.toInt()),e&=63,e===0)return this;var t=this.high;if(e<32){var s=this.low;return pt(s>>>e|t<<32-e,t>>>e,this.unsigned)}else return e===32?pt(t,0,this.unsigned):pt(t>>>e-32,0,this.unsigned)},pe.shru=pe.shiftRightUnsigned,pe.shr_u=pe.shiftRightUnsigned,pe.toSigned=function(){return this.unsigned?pt(this.low,this.high,!1):this},pe.toUnsigned=function(){return this.unsigned?this:pt(this.low,this.high,!0)},pe.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},pe.toBytesLE=function(){var e=this.high,t=this.low;return[t&255,t>>>8&255,t>>>16&255,t>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]},pe.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,t>>>24,t>>>16&255,t>>>8&255,t&255]},dt.fromBytes=function(e,t,s){return s?dt.fromBytesLE(e,t):dt.fromBytesBE(e,t)},dt.fromBytesLE=function(e,t){return new dt(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},dt.fromBytesBE=function(e,t){return new dt(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};const v0=u0(h0),F$=Bn({__proto__:null,default:v0},[h0]);/** * @license * Copyright 2021 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const Kr=v0||F$;function Gc(n){return Kr.fromString(n,!0,16)}const I0=Gc("c3a5c85c97cb3127"),Xr=Gc("b492b66fbe98f273"),ln=Gc("9ae16a3b2f90404f");function ip(n){return n.xor(n.shru(47))}function $0(n,e,t){const s=n.slice(e,e+t);return Kr.fromBytes(Array.from(s),!0,!0)}function ct(n,e){return $0(n,e,8)}function C0(n,e){return $0(n,e,4)}function Ut(n,e){return e===0?n:n.shru(e).or(n.shl(64-e))}function mr(n,e,t=Gc("9ddfea08eb382d69")){let s=n.xor(e).mul(t);s=s.xor(s.shru(47));let r=e.xor(s).mul(t);return r=r.xor(r.shru(47)),r=r.mul(t),r}function _$(n,e,t,s,r,o){r=r.add(n),o=Ut(o.add(r).add(s),21);const a=r;return r=r.add(e),r=r.add(t),o=o.add(Ut(r,44)),[r.add(s),o.add(a)]}function Hc(n,e,t,s){return _$(ct(n,e),ct(n,e+8),ct(n,e+16),ct(n,e+24),t,s)}function O$(n,e=n.length){if(e>=8){const t=ln.add(e*2),s=ct(n,0).add(ln),r=ct(n,e-8),o=Ut(r,37).mul(t).add(s),a=Ut(s,25).add(r).mul(t);return mr(o,a,t)}if(e>=4){const t=ln.add(e*2),s=C0(n,0);return mr(s.shl(3).add(e),C0(n,e-4),t)}if(e>0){const t=n[0],s=n[e>>1],r=n[e-1],o=t+(s<<8),a=e+(r<<2);return ip(ln.mul(o).xor(I0.mul(a))).mul(ln)}return ln}function L$(n,e=n.length){const t=ln.add(e*2),s=ct(n,0).mul(Xr),r=ct(n,8),o=ct(n,e-8).mul(t),a=ct(n,e-16).mul(ln);return mr(Ut(s.add(r),43).add(Ut(o,30)).add(a),s.add(Ut(r.add(ln),18)).add(o),t)}function P$(n,e=n.length){const t=ln.add(e*2),s=ct(n,0).mul(ln),r=ct(n,8),o=ct(n,e-8).mul(t),a=ct(n,e-16).mul(ln),i=Ut(s.add(r),43).add(Ut(o,30)).add(a),l=mr(i,s.add(Ut(r.add(ln),18)).add(o),t),c=ct(n,16).mul(t),u=ct(n,24),h=i.add(ct(n,e-32)).mul(t),d=l.add(ct(n,e-24)).mul(t);return mr(Ut(c.add(u),43).add(Ut(h,30)).add(d),c.add(Ut(u.add(s),18)).add(h),t)}function z$(n,e=n.length){const t=Kr.fromNumber(81,!0);if(e<=32)return e<=16?O$(n,e):L$(n,e);if(e<=64)return P$(n,e);let s=t,r=t.mul(Xr).add(113),o=ip(r.mul(ln).add(113)).mul(ln),a=[Kr.UZERO,Kr.UZERO],i=[Kr.UZERO,Kr.UZERO];s=s.mul(ln).add(ct(n,0));let l=0;const c=(e-1>>6)*64,u=c+(e-1&63)-63;do s=Ut(s.add(r).add(a[0]).add(ct(n,l+8)),37).mul(Xr),r=Ut(r.add(a[1]).add(ct(n,l+48)),42).mul(Xr),s=s.xor(i[1]),r=r.add(a[0]).add(ct(n,l+40)),o=Ut(o.add(i[0]),33).mul(Xr),a=Hc(n,l,a[1].mul(Xr),s.add(i[0])),i=Hc(n,l+32,o.add(i[1]),r.add(ct(n,l+16))),[o,s]=[s,o],l+=64;while(l!==c);const h=Xr.add(o.and(255).shl(1));return l=u,i[0]=i[0].add(e-1&63),a[0]=a[0].add(i[0]),i[0]=i[0].add(a[0]),s=Ut(s.add(r).add(a[0]).add(ct(n,l+8)),37).mul(h),r=Ut(r.add(a[1]).add(ct(n,l+48)),42).mul(h),s=s.xor(i[1].mul(9)),r=r.add(a[0].mul(9).add(ct(n,l+40))),o=Ut(o.add(i[0]),33).mul(h),a=Hc(n,l,a[1].mul(h),s.add(i[0])),i=Hc(n,l+32,o.add(i[1]),r.add(ct(n,l+16))),[o,s]=[s,o],mr(mr(a[0],i[0],h).add(ip(r).mul(I0)).add(o),mr(a[1],i[1],h).add(s),h)}/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function gr(n,e){return e==="string"?yr(n):Yr([n],e)}function M$(n,e){return n instanceof Float32Array&&e==="float32"||n instanceof Int32Array&&e==="int32"||n instanceof Uint8Array&&e==="bool"}function Yr(n,e){if(e==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(n)&&(n=Do(n)),K().getBool("DEBUG")&&y$(n,e),M$(n,e))return n;if(e==null||e==="float32"||e==="complex64")return new Float32Array(n);if(e==="int32")return new Int32Array(n);if(e==="bool"){const t=new Uint8Array(n.length);for(let s=0;s<t.length;++s)Math.round(n[s])!==0&&(t[s]=1);return t}else throw new Error(`Unknown data type ${e}`)}function yn(){return K().platform.now()}function yr(n,e="utf-8"){return e=e||"utf-8",K().platform.encode(n,e)}function br(n,e="utf-8"){return e=e||"utf-8",K().platform.decode(n,e)}/** * @license * Copyright 2018 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */class B${constructor(e,t){this.backendTimer=e,this.logger=t,t==null&&(this.logger=new W$)}profileKernel(e,t,s){let r;const o=()=>{r=s()};let a;const i=yn();if(this.backendTimer.timerAvailable())a=this.backendTimer.time(o);else{o();for(const c of r)c.dataSync();a=Promise.resolve({kernelMs:yn()-i})}if(K().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(let c=0;c<r.length;c++){const u=r[c];u.data().then(h=>{V$(h,u.dtype,e)})}return{kernelName:e,outputs:r,inputs:t,timeMs:a.then(c=>c.kernelMs),extraInfo:a.then(c=>c.getExtraProfileInfo!=null?c.getExtraProfileInfo():"")}}logKernelProfile(e){const{kernelName:t,outputs:s,timeMs:r,inputs:o,extraInfo:a}=e;s.forEach(i=>{Promise.all([i.data(),r,a]).then(l=>{this.logger.logKernelProfile(t,i,l[0],l[1],o,l[2])})})}}function V$(n,e,t){if(e!=="float32")return!1;for(let s=0;s<n.length;s++){const r=n[s];if(isNaN(r)||!isFinite(r))return console.warn(`Found ${r} in the result of '${t}'`),!0}return!1}class W${logKernelProfile(e,t,s,r,o,a){const i=typeof r=="number"?Ro(`${r}ms`,9):r.error,l=Ro(e,25),c=t.rank,u=t.size,h=Ro(t.shape.toString(),14);let d="";for(const p in o){const f=o[p];if(f!=null){const m=f.shape||t.shape,g=m.length;d+=`${p}: ${g}D ${g>0?m:""} `}}console.log(`%c${l} %c${i} %c${c}D ${h} %c${u} %c${d} %c${a}`,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")}}/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function U$(n,e,t){const s={},r={};for(let l=0;l<e.length;l++)s[e[l].id]=!0;for(let l=0;l<n.length;l++){const c=n[l],u=c.inputs;for(const h in u){const d=u[h];let p=!1;for(let f=0;f<e.length;f++)if(s[d.id]){c.outputs.forEach(m=>s[m.id]=!0),p=!0,r[c.id]=!0;break}if(p)break}}const o={};o[t.id]=!0;const a={};for(let l=n.length-1;l>=0;l--){const c=n[l],u=c.inputs;for(let h=0;h<c.outputs.length;h++)if(o[c.outputs[h].id]){for(const d in u)o[u[d].id]=!0,a[c.id]=!0;break}}const i=[];for(let l=0;l<n.length;l++){const c=n[l];if(r[c.id]&&a[c.id]){const u={};for(const d in c.inputs){const p=c.inputs[d];s[p.id]&&(u[d]=p)}const h=Object.assign({},c);h.inputs=u,h.outputs=c.outputs,i.push(h)}}return i}function G$(n,e,t,s){for(let r=e.length-1;r>=0;r--){const o=e[r],a=[];if(o.outputs.forEach(l=>{const c=n[l.id];c!=null?a.push(c):a.push(null)}),o.gradient==null)throw new Error(`Cannot compute gradient: gradient function not found for ${o.kernelName}.`);const i=o.gradient(a);for(const l in o.inputs){if(!(l in i))throw new Error(`Cannot backprop through input ${l}. Available gradients found: ${Object.keys(i)}.`);const c=t(()=>i[l]());if(c.dtype!=="float32")throw new Error(`Error in gradient for op ${o.kernelName}. The gradient of input ${l} must have 'float32' dtype, but has '${c.dtype}'`);const u=o.inputs[l];if(!Ge(c.shape,u.shape))throw new Error(`Error in gradient for op ${o.kernelName}. The gradient of input '${l}' has shape '${c.shape}', which does not match the shape of the input '${u.shape}'`);if(n[u.id]==null)n[u.id]=c;else{const h=n[u.id];n[u.id]=s(h,c),h.dispose()}}}}/** * @license * Copyright 2018 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const S0=20,Di=3,lp=7;function H$(n,e,t,s){const r=Ne(e),o=j$(n,e,t,r),a=e.length,i=jc(n,e,t,r,o),l=["Tensor"];return s&&(l.push(` dtype: ${t}`),l.push(` rank: ${a}`),l.push(` shape: [${e}]`),l.push(" values:")),l.push(i.map(c=>" "+c).join(` `)),l.join(` `)}function j$(n,e,t,s){const r=Y(e),o=s[s.length-1],a=new Array(o).fill(0),i=e.length,l=t==="complex64"?Ri(n):n;if(i>1)for(let c=0;c<r/o;c++){const u=c*o;for(let h=0;h<o;h++)a[h]=Math.max(a[h],Ai(l[u+h],0,t).length)}return a}function Ai(n,e,t){let s;return Array.isArray(n)?s=`${parseFloat(n[0].toFixed(lp))} + ${parseFloat(n[1].toFixed(lp))}j`:Fa(n)?s=`'${n}'`:t==="bool"?s=N0(n):s=parseFloat(n.toFixed(lp)).toString(),Ro(s,e)}function N0(n){return n===0?"false":"true"}function jc(n,e,t,s,r,o=!0){const a=t==="complex64"?2:1,i=e[0],l=e.length;if(l===0){if(t==="complex64"){const m=Ri(n);return[Ai(m[0],0,t)]}return t==="bool"?[N0(n[0])]:[n[0].toString()]}if(l===1){if(i>S0){const g=Di*a;let y=Array.from(n.slice(0,g)),b=Array.from(n.slice((i-Di)*a,i*a));return t==="complex64"&&(y=Ri(y),b=Ri(b)),["["+y.map((w,x)=>Ai(w,r[x],t)).join(", ")+", ..., "+b.map((w,x)=>Ai(w,r[i-Di+x],t)).join(", ")+"]"]}return["["+(t==="complex64"?Ri(n):Array.from(n)).map((g,y)=>Ai(g,r[y],t)).join(", ")+"]"]}const c=e.slice(1),u=s.slice(1),h=s[0]*a,d=[];if(i>S0){for(let m=0;m<Di;m++){const g=m*h,y=g+h;d.push(...jc(n.slice(g,y),c,t,u,r,!1))}d.push("...");for(let m=i-Di;m<i;m++){const g=m*h,y=g+h;d.push(...jc(n.slice(g,y),c,t,u,r,m===i-1))}}else for(let m=0;m<i;m++){const g=m*h,y=g+h;d.push(...jc(n.slice(g,y),c,t,u,r,m===i-1))}const p=l===2?",":"";d[0]="["+d[0]+p;for(let m=1;m<d.length-1;m++)d[m]=" "+d[m]+p;let f=`, `;for(let m=2;m<l;m++)f+=` `;return d[d.length-1]=" "+d[d.length-1]+"]"+(o?"":f),d}function Ri(n){const e=[];for(let t=0;t<n.length;t+=2)e.push([n[t],n[t+1]]);return e}/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */class Gt{constructor(e,t,s){if(this.dtype=t,this.shape=e.slice(),this.size=Y(e),s!=null){const r=s.length;N(r===this.size,()=>`Length of values '${r}' does not match the size inferred by the shape '${this.size}'.`)}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=s||Wt(t,this.size),this.strides=Ne(e)}set(e,...t){t.length===0&&(t=[0]),N(t.length===this.rank,()=>`The number of provided coordinates (${t.length}) must match the rank (${this.rank})`);const s=this.locToIndex(t);this.values[s]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(const r of e){if(r<0||r>=this.shape[t]){const o=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(o)}t++}let s=e[e.length-1];for(let r=0;r<e.length-1;++r)s+=this.strides[r]*e[r];return this.values[s]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let s=0;s<e.length-1;++s)t+=this.strides[s]*e[s];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];const t=new Array(this.shape.length);for(let s=0;s<t.length-1;++s)t[s]=Math.floor(e/this.strides[s]),e-=t[s]*this.strides[s];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return xs().makeTensor(this.values,this.shape,this.dtype)}}let xs=null,Mo=null;function q$(n){xs=n}function K$(n){Mo=n}class Ye{constructor(e,t,s,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=Y(e),this.strides=Ne(e),this.dataId=s,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return Mo.buffer(this.shape,this.dtype,e)}bufferSync(){return Mo.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return Zn(this.shape,e,this.dtype==="complex64")}arraySync(){return Zn(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();const e=xs().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(s=>br(s))}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataToGPU(e){return this.throwIfDisposed(),xs().readToGPU(this.dataId,e)}dataSync(){this.throwIfDisposed();const e=xs().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>br(t))}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();const e=await xs().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(xs().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Mo.print(this,e)}clone(){return this.throwIfDisposed(),Mo.clone(this)}toString(e=!1){const t=this.dataSync();return H$(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Mo.cast(this,e)}variable(e=!0,t,s){return this.throwIfDisposed(),xs().makeVariable(this,e,t,s)}}Object.defineProperty(Ye,Symbol.hasInstance,{value:n=>!!n&&n.data!=null&&n.dataSync!=null&&n.throwIfDisposed!=null});function Q(){return Zh("Tensor",()=>Ye)}Q();class qc extends Ye{constructor(e,t,s,r){super(e.shape,e.dtype,e.dataId,r),this.trainable=t,this.name=s}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);if(!Ge(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);xs().disposeTensor(this),this.dataId=e.dataId,xs().incRef(this,null)}dispose(){xs().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(qc,Symbol.hasInstance,{value:n=>n instanceof Ye&&n.assign!=null&&n.assign instanceof Function});/** * @license * Copyright 2017 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var k0;(function(n){n.R0="R0",n.R1="R1",n.R2="R2",n.R3="R3",n.R4="R4",n.R5="R5",n.R6="R6"})(k0||(k0={}));var cp;(function(n){n.float32="float32",n.int32="int32",n.bool="int32",n.complex64="complex64"})(cp||(cp={}));var up;(function(n){n.float32="float32",n.int32="int32",n.bool="bool",n.complex64="complex64"})(up||(up={}));var hp;(function(n){n.float32="float32",n.int32="float32",n.bool="float32",n.complex64="complex64"})(hp||(hp={}));var dp;(function(n){n.float32="complex64",n.int32="complex64",n.bool="complex64",n.complex64="complex64"})(dp||(dp={}));const X$={float32:hp,int32:cp,bool:up,complex64:dp};function En(n,e){if(n==="string"||e==="string"){if(n==="string"&&e==="string")return"string";throw new Error(`Can not upcast ${n} with ${e}`)}return X$[n][e]}function pp(n){return En(n,"int32")}/** * @license * Copyright 2018 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function It(n,e){if(n.dtype===e.dtype)return[n,e];const t=En(n.dtype,e.dtype);return[n.cast(t),e.cast(t)]}function Y$(n,e){N(n.dtype===e.dtype,()=>`The dtypes of the first(${n.dtype}) and second(${e.dtype}) input must match`)}function T0(n){const e=[];return E0(n,e,new Set),e}function E0(n,e,t){if(n==null)return;if(n instanceof Ye){e.push(n);return}if(!Z$(n))return;const s=n;for(const r in s){const o=s[r];t.has(o)||(t.add(o),E0(o,e,t))}}function Z$(n){return Array.isArray(n)||typeof n=="object"}/** * @license * Copyright 2018 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function fp(n){return n.kernelName!=null}class D0{constructor(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null,get kernelNames(){return Array.from(new Set(this.kernels.map(e=>e.name)))}}}dispose(){for(const e in this.registeredVariables)this.registeredVariables[e].dispose()}}class Bo{constructor(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new D0}async ready(){if(this.pendingBackendInit!=null)return this.pendingBackendInit.then(()=>{});if(this.backendInstance!=null)return;const e=this.getSortedBackends();for(let t=0;t<e.length;t++){const s=e[t];if(await this.initializeBackend(s).success){await this.setBackend(s);return}}throw new Error("Could not initialize any backends, all backend initializations failed.")}get backend(){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){const{name:e,asyncInit:t}=this.initializeBackendsAndReturnBest();if(t)throw new Error(`The highest priority backend '${e}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);this.setBackend(e)}return this.backendInstance}backendNames(){return Object.keys(this.registryFactory)}findBackend(e){if(!(e in this.registry))if(e in this.registryFactory){const{asyncInit:t}=this.initializeBackend(e);if(t)return null}else return null;return this.registry[e]}findBackendFactory(e){return e in this.reg