UNPKG

genuine-verify-sdk

Version:

Privacy-first human verification widget using React, Next.js, and TensorFlow.js

5 lines 1.61 MB
'use strict';var Bs=require('stream'),uE=require('http'),I6=require('url'),uie=require('https'),Ad=require('zlib'),De=require('react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Bs__default=/*#__PURE__*/_interopDefault(Bs);var uE__default=/*#__PURE__*/_interopDefault(uE);var I6__default=/*#__PURE__*/_interopDefault(I6);var uie__default=/*#__PURE__*/_interopDefault(uie);var Ad__default=/*#__PURE__*/_interopDefault(Ad);var De__default=/*#__PURE__*/_interopDefault(De);var rse=Object.create;var Q4=Object.defineProperty;var ose=Object.getOwnPropertyDescriptor;var nse=Object.getOwnPropertyNames;var sse=Object.getPrototypeOf,ase=Object.prototype.hasOwnProperty;var Wl=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var f=(r,e)=>()=>(r&&(e=r(r=0)),e);var Uo=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ye=(r,e)=>{for(var t in e)Q4(r,t,{get:e[t],enumerable:true});},TI=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of nse(e))!ase.call(r,n)&&n!==t&&Q4(r,n,{get:()=>e[n],enumerable:!(o=ose(e,n))||o.enumerable});return r};var sf=(r,e,t)=>(t=r!=null?rse(sse(r)):{},TI(e||!r||!r.__esModule?Q4(t,"default",{value:r,enumerable:true}):t,r)),ise=r=>TI(Q4({},"__esModule",{value:true}),r);function In(r){throw new Error(`'${r}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`)}var Hl,Ta,yy=f(()=>{Hl=class{constructor(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0;}get(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)}set(e,t){this.dataIdsCount++,this.data.set(e,t);}has(e){return this.data.has(e)}delete(e){return this.dataIdsCount--,this.data.delete(e)}numDataIds(){return this.dataIdsCount}},Ta=class{refCount(e){return In("refCount")}incRef(e){return In("incRef")}timerAvailable(){return true}time(e){return In("time")}read(e){return In("read")}readSync(e){return In("readSync")}readToGPU(e,t){return In("readToGPU")}numDataIds(){return In("numDataIds")}disposeData(e,t){return In("disposeData")}write(e,t,o){return In("write")}move(e,t,o,n,s){return In("move")}createTensorFromGPUData(e,t,o){return In("createTensorFromGPUData")}memory(){return In("memory")}floatPrecision(){return In("floatPrecision")}epsilon(){return this.floatPrecision()===32?1e-7:1e-4}dispose(){return In("dispose")}};});function kI(r){let e=r.length,t=0;for(;e>0;)t=Math.random()*e|0,e--,e6(r,e,t);}function pse(r,e){if(r.length!==e.length)throw new Error(`Array sizes must match to be shuffled together First array length was ${r.length}Second array length was ${e.length}`);let t=r.length,o=0;for(;t>0;)o=Math.random()*t|0,t--,e6(r,t,o),e6(e,t,o);}function af(r,e,t){return Math.max(r,Math.min(e,t))}function lse(r){return r%2===0?r:r+1}function e6(r,e,t){let o=r[e];r[e]=r[t],r[t]=o;}function use(r){let e=0;for(let t=0;t<r.length;t++)e+=r[t];return e}function cse(r,e){let t=Math.random();return e*t+(1-t)*r}function dse(r,e){let t=0;for(let o=0;o<r.length;o++){let n=Number(r[o])-Number(e[o]);t+=n*n;}return t}function D(r,e){if(!r)throw new Error(typeof e=="string"?e:e())}function jt(r,e,t=""){D(Yo(r,e),()=>t+` Shapes ${r} and ${e} must match`);}function Wn(r){D(r!=null,()=>"The input to the tensor constructor must be a non-null value.");}function et(r){if(r.length===0)return 1;let e=r[0];for(let t=1;t<r.length;t++)e*=r[t];return e}function mse(r){return r.length===0}function by(r,e){if(r===e)return true;if(r==null||e==null||r.length!==e.length)return false;for(let t=0;t<r.length;t++)if(r[t]!==null&&e[t]!==null&&r[t]!==e[t])return false;return true}function Yo(r,e){if(r===e)return true;if(r==null||e==null||r.length!==e.length)return false;for(let t=0;t<r.length;t++)if(r[t]!==e[t])return false;return true}function Zi(r){return r%1===0}function fse(r){if(Math.tanh!=null)return Math.tanh(r);if(r===1/0)return 1;if(r===-1/0)return -1;{let e=Math.exp(2*r);return (e-1)/(e+1)}}function hse(r){let e=Math.ceil(Math.sqrt(r));return [e,Math.ceil(r/e)]}function gse(r){let e=new Uint32Array(r);for(let t=0;t<r;++t)e[t]=t;return kI(e),e}function fc(r,e){return e<=r.length?r:r+" ".repeat(e-r.length)}function xse(r,e=n=>0,t,o){return new Promise((n,s)=>{let a=0,i=()=>{if(r()){n();return}a++;let p=e(a);if(t!=null&&a>=t){s();return}o!=null?o(i,p):setTimeout(i,p);};i();})}function yse(r,e){let t=1,o=-1;for(let s=0;s<r.length;++s)if(r[s]>=0)t*=r[s];else if(r[s]===-1){if(o!==-1)throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${o} and dim ${s}`);o=s;}else if(r[s]<0)throw Error(`Shapes can not be < 0. Found ${r[s]} at dim ${s}`);if(o===-1){if(e>0&&e!==t)throw Error(`Size(${e}) must match the product of shape ${r}`);return r}if(t===0)throw Error(`Cannot infer the missing size in [${r}] when there are 0 elements`);if(e%t!==0)throw Error(`The implicit shape can't be a fractional number. Got ${e} / ${t}`);let n=r.slice();return n[o]=e/t,n}function Lr(r,e){let t=e.length;return r=r==null?e.map((o,n)=>n):[].concat(r),D(r.every(o=>o>=-t&&o<t),()=>`All values in axis param must be in range [-${t}, ${t}) but got axis ${r}`),D(r.every(o=>Zi(o)),()=>`All values in axis param must be integers but got axis ${r}`),r.map(o=>o<0?t+o:o)}function vy(r,e){let t=[],o=[],n=e!=null&&Array.isArray(e)&&e.length===0,s=e==null||n?null:Lr(e,r).sort(),a=0;for(let i=0;i<r.length;++i){if(s!=null){if(s[a]===i&&r[i]!==1)throw new Error(`Can't squeeze axis ${i} since its dim '${r[i]}' is not 1`);(s[a]==null||s[a]>i)&&r[i]===1&&(t.push(r[i]),o.push(i)),s[a]<=i&&a++;}r[i]!==1&&(t.push(r[i]),o.push(i));}return {newShape:t,keptDims:o}}function wy(r,e){return t6(r,e)}function t6(r,e){let t=null;if(r==null||r==="float32")t=new Float32Array(e);else if(r==="int32")t=new Int32Array(e);else if(r==="bool")t=new Uint8Array(e);else if(r==="string")t=new Array(e);else throw new Error(`Unknown data type ${r}`);return t}function Sy(r,e){for(let t=0;t<r.length;t++){let o=r[t];if(isNaN(o)||!isFinite(o))throw Error(`A tensor of type ${e} being uploaded contains ${o}.`)}}function Ny(r){return r==="bool"||r==="complex64"||r==="float32"||r==="int32"||r==="string"}function bse(r,e){return !(e==="complex64"||e==="float32"&&r!=="complex64"||e==="int32"&&r!=="float32"&&r!=="complex64"||e==="bool"&&r==="bool")}function pf(r){if(r==="float32"||r==="int32")return 4;if(r==="complex64")return 8;if(r==="bool")return 1;throw new Error(`Unknown dtype ${r}`)}function Ty(r){if(r==null)return 0;let e=0;return r.forEach(t=>e+=t.length),e}function $s(r){return typeof r=="string"||r instanceof String}function EI(r){return typeof r=="boolean"}function AI(r){return typeof r=="number"}function ql(r){return Array.isArray(r)?ql(r[0]):r instanceof Float32Array?"float32":r instanceof Int32Array||r instanceof Uint8Array||r instanceof Uint8ClampedArray?"int32":AI(r)?"float32":$s(r)?"string":EI(r)?"bool":"float32"}function Ca(r){return !!(r&&r.constructor&&r.call&&r.apply)}function lf(r,e){for(let t=e;t<r;++t)if(r%t===0)return t;return r}function Ia(r){let e=r.length;if(e<2)return [];let t=new Array(e-1);t[e-2]=r[e-1];for(let o=e-3;o>=0;--o)t[o]=t[o+1]*r[o+1];return t}function DI(r,e,t,o=false){let n=new Array;if(e.length===1){let s=e[0]*(o?2:1);for(let a=0;a<s;a++)n[a]=t[r+a];}else {let s=e[0],a=e.slice(1),i=a.reduce((p,l)=>p*l)*(o?2:1);for(let p=0;p<s;p++)n[p]=DI(r+p*i,a,t,o);}return n}function mc(r,e,t=false){if(r.length===0)return e[0];let o=r.reduce((n,s)=>n*s)*(t?2:1);if(o===0)return [];if(o!==e.length)throw new Error(`[${r}] does not match the input size ${e.length}${t?" for a complex tensor":""}.`);return DI(0,r,e,t)}function vse(r,e){if(Array.isArray(r))return r;if(e==="float32")return r instanceof Float32Array?r:new Float32Array(r);if(e==="int32")return r instanceof Int32Array?r:new Int32Array(r);if(e==="bool"||e==="string")return Uint8Array.from(new Int32Array(r));throw new Error(`Unknown dtype ${e}`)}function $0(r,e){let t=uf(r,e);for(let o=0;o<t.length;o++)t[o]=1;return t}function uf(r,e){if(e==null||e==="float32"||e==="complex64")return new Float32Array(r);if(e==="int32")return new Int32Array(r);if(e==="bool")return new Uint8Array(r);throw new Error(`Unknown data type ${e}`)}function wse(r,e){let t=r.reduce((o,n)=>o*n,1);if(e==null||e==="float32")return mc(r,new Float32Array(t));if(e==="int32")return mc(r,new Int32Array(t));if(e==="bool")return mc(r,new Uint8Array(t));throw new Error(`Unknown data type ${e}`)}function tr(r){r.forEach(e=>{D(Number.isInteger(e)&&e>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${r}].`);});}function Sse(r,e,t){if(e===0)return 0;if(e===1)return r[0];let o=r[r.length-1];for(let n=0;n<r.length-1;++n)o+=t[n]*r[n];return o}function Nse(r,e,t){if(e===0)return [];if(e===1)return [r];let o=new Array(e);for(let n=0;n<o.length-1;++n)o[n]=Math.floor(r/t[n]),r-=o[n]*t[n];return o[o.length-1]=r,o}function hc(r){return r&&r.then&&typeof r.then=="function"}var Qr=f(()=>{});function Cse(r){let e={};return r.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(t,...o)=>(Ise(e,o[0],o[1]),o.join("="))),e}function Ise(r,e,t){r[decodeURIComponent(e)]=decodeURIComponent(t||"");}function kse(r,e){let t=e.toLowerCase();return t==="true"||t==="false"?t==="true":`${+t}`===t?+t:e}function M(){return r6}function _I(r){r6=r;}var $I,cf,r6,xo=f(()=>{Qr();$I="tfjsflags",cf=class{constructor(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=Cse,this.populateURLFlags();}setPlatform(e,t){this.platform!=null&&(M().getBool("IS_TEST")||M().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,o){if(this.flagRegistry[e]={evaluationFn:t,setHook:o},this.urlFlags[e]!=null){let n=this.urlFlags[e];M().getBool("IS_TEST")||M().getBool("PROD")||console.warn(`Setting feature override from URL ${e}: ${n}.`),this.set(e,n);}}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];let t=this.evaluateFlag(e);if(hc(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)}getString(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;let e=this.getQueryParams(this.global.location.search);$I in e&&e[$I].split(",").forEach(o=>{let[n,s]=o.split(":");this.urlFlags[n]=kse(n,s);});}};r6=null;});function Iy(){if(Cy==null){let r;if(typeof window<"u")r=window;else if(typeof global<"u")r=global;else if(typeof process<"u")r=process;else if(typeof self<"u")r=self;else throw new Error("Could not find a global object");Cy=r;}return Cy}function Ese(){let r=Iy();return r._tfGlobals==null&&(r._tfGlobals=new Map),r._tfGlobals}function _0(r,e){let t=Ese();if(t.has(r))return t.get(r);{let o=e();return t.set(r,o),t.get(r)}}var Cy,o6=f(()=>{});var Ji,ka,Ea,ns,Qi,gc,xc,ep,tp,Aa,Da,$a,_a,Ra,rp,yc,op,bc,np,sp,vc,Kl,ky,wc,_s,Fa,Oa,Sc,ap,ip,pp,Nc,lp,up,Tc,Cc,La,Pa,Ic,cp,kc,Ec,Ac,dp,Dc,$c,_c,mp,df,mf,ff,Va,Rc,za,Fc,Ma,jl,Ba,fp,Ga,Oc,Lc,Pc,Ua,Wa,hp,gp,Vc,Xl,Ha,Rs,zc,Mc,qa,Ka,ja,xp,Yl,Zl,Bc,Xa,Ya,Jl,Ql,eu,Ase,Ey,Dse,yp,Gc,$se,bp,Za,vp,Uc,wp,Wc,Hc,Sp,Np,Ja,Tp,Qa,qc,ei,Cp,tu,Kc,jc,Xc,Ip,kp,Ep,Ap,_se,ti,Dp,$p,Yc,Zc,Jc,Qc,ed,ri,oi,_p,Rp,td,Fp,rd,ni,Op,si,ai,od,nd,sd,Lp,ii,Pp,pi,li,ui,ci,di,mi,Vp,zp,Mp,Bp,ad,id,pd,ld,ud,fi,cd,ru,dd,md,fd,hd,hi,gi,xi,Fs,gd,xd,Os,yd,Gp,Up,Rse,Wp,yi,hf,bd,ou,nu,su,P=f(()=>{Ji="Abs",ka="Acos",Ea="Acosh",ns="Add",Qi="AddN",gc="All",xc="Any",ep="ArgMax",tp="ArgMin",Aa="Asin",Da="Asinh",$a="Atan",_a="Atanh",Ra="Atan2",rp="AvgPool",yc="AvgPoolGrad",op="AvgPool3D",bc="AvgPool3DGrad",np="BatchMatMul",sp="BatchToSpaceND",vc="Bincount",Kl="BitwiseAnd",ky="BroadcastTo",wc="BroadcastArgs",_s="Cast",Fa="Ceil",Oa="ClipByValue",Sc="Complex",ap="ComplexAbs",ip="Concat",pp="Conv2D",Nc="Conv2DBackpropFilter",lp="Conv2DBackpropInput",up="Conv3D",Tc="Conv3DBackpropFilterV2",Cc="Conv3DBackpropInputV2",La="Cos",Pa="Cosh",Ic="Cumprod",cp="Cumsum",kc="CropAndResize",Ec="DenseBincount",Ac="DepthToSpace",dp="DepthwiseConv2dNative",Dc="DepthwiseConv2dNativeBackpropFilter",$c="DepthwiseConv2dNativeBackpropInput",_c="Diag",mp="Dilation2D",df="Dilation2DBackpropInput",mf="Dilation2DBackpropFilter",ff="Draw",Va="RealDiv",Rc="Einsum",za="Elu",Fc="EluGrad",Ma="Erf",jl="Equal",Ba="Exp",fp="ExpandDims",Ga="Expm1",Oc="FFT",Lc="Fill",Pc="FlipLeftRight",Ua="Floor",Wa="FloorDiv",hp="FusedBatchNorm",gp="GatherV2",Vc="GatherNd",Xl="Greater",Ha="GreaterEqual",Rs="Identity",zc="IFFT",Mc="Imag",qa="IsFinite",Ka="IsInf",ja="IsNan",xp="LeakyRelu",Yl="Less",Zl="LessEqual",Bc="LinSpace",Xa="Log",Ya="Log1p",Jl="LogicalAnd",Ql="LogicalNot",eu="LogicalOr",Ase="LogicalXor",Ey="LogSoftmax",Dse="LowerBound",yp="LRN",Gc="LRNGrad",$se="MatrixBandPart",bp="Max",Za="Maximum",vp="MaxPool",Uc="MaxPoolGrad",wp="MaxPool3D",Wc="MaxPool3DGrad",Hc="MaxPoolWithArgmax",Sp="Mean",Np="Min",Ja="Minimum",Tp="MirrorPad",Qa="Mod",qc="Multinomial",ei="Multiply",Cp="Neg",tu="NotEqual",Kc="NonMaxSuppressionV3",jc="NonMaxSuppressionV4",Xc="NonMaxSuppressionV5",Ip="OnesLike",kp="OneHot",Ep="Pack",Ap="PadV2",_se="Pool",ti="Pow",Dp="Prelu",$p="Prod",Yc="RaggedGather",Zc="RaggedRange",Jc="RaggedTensorToTensor",Qc="Range",ed="Real",ri="Reciprocal",oi="Relu",_p="Reshape",Rp="ResizeNearestNeighbor",td="ResizeNearestNeighborGrad",Fp="ResizeBilinear",rd="ResizeBilinearGrad",ni="Relu6",Op="Reverse",si="Round",ai="Rsqrt",od="ScatterNd",nd="TensorScatterUpdate",sd="SearchSorted",Lp="Select",ii="Selu",Pp="Slice",pi="Sin",li="Sinh",ui="Sign",ci="Sigmoid",di="Softplus",mi="Sqrt",Vp="Sum",zp="SpaceToBatchND",Mp="SplitV",Bp="Softmax",ad="SparseFillEmptyRows",id="SparseReshape",pd="SparseSegmentMean",ld="SparseSegmentSum",ud="SparseToDense",fi="SquaredDifference",cd="Square",ru="StaticRegexReplace",dd="StridedSlice",md="StringNGrams",fd="StringSplit",hd="StringToHashBucketFast",hi="Sub",gi="Tan",xi="Tanh",Fs="Tile",gd="TopK",xd="Transform",Os="Transpose",yd="Unique",Gp="Unpack",Up="UnsortedSegmentSum",Rse="UpperBound",Wp="ZerosLike",yi="Step",hf="FromPixels",bd="RotateWithOffset",ou="_FusedMatMul",nu="FusedConv2D",su="FusedDepthwiseConv2D";});function bi(...r){M().getBool("IS_TEST")||M().getBool("PROD")||console.warn(...r);}function Fse(...r){M().getBool("IS_TEST")||M().getBool("PROD")||console.log(...r);}var n6=f(()=>{xo();});function vd(r,e){let t=Dy(r,e);return gf.get(t)}function s6(r){return R0.get(r)}function F0(r){let e=gf.entries(),t=[];for(;;){let{done:o,value:n}=e.next();if(o)break;let[s,a]=n,[i]=s.split("_");i===r&&t.push(a);}return t}function xf(r){let{kernelName:e,backendName:t}=r,o=Dy(e,t);gf.has(o)&&bi(`The kernel '${e}' for backend '${t}' is already registered`),gf.set(o,r);}function Ay(r){let{kernelName:e}=r;R0.has(e)&&M().getBool("DEBUG")&&bi(`Overriding the gradient for '${e}'`),R0.set(e,r);}function Ose(r,e){let t=Dy(r,e);if(!gf.has(t))throw new Error(`The kernel '${r}' for backend '${e}' is not registered`);gf.delete(t);}function Lse(r){if(!R0.has(r))throw new Error(`The gradient '${r}' for backend is not registered`);R0.delete(r);}function Pse(r,e){F0(r).forEach(o=>{let n=Object.assign({},o,{backendName:e});xf(n);});}function Dy(r,e){return `${e}_${r}`}var gf,R0,O0=f(()=>{xo();o6();n6();gf=_0("kernelRegistry",()=>new Map),R0=_0("gradRegistry",()=>new Map);});function a6(r){return r instanceof Float32Array||r instanceof Int32Array||r instanceof Uint8Array||r instanceof Uint8ClampedArray}var $y=f(()=>{});var WI=Uo((c7e,UI)=>{UI.exports=ur;var ss=null;try{ss=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 ur(r,e,t){this.low=r|0,this.high=e|0,this.unsigned=!!t;}ur.prototype.__isLong__;Object.defineProperty(ur.prototype,"__isLong__",{value:true});function En(r){return (r&&r.__isLong__)===true}ur.isLong=En;var FI={},OI={};function Sd(r,e){var t,o,n;return e?(r>>>=0,(n=0<=r&&r<256)&&(o=OI[r],o)?o:(t=cr(r,(r|0)<0?-1:0,true),n&&(OI[r]=t),t)):(r|=0,(n=-128<=r&&r<128)&&(o=FI[r],o)?o:(t=cr(r,r<0?-1:0,false),n&&(FI[r]=t),t))}ur.fromInt=Sd;function as(r,e){if(isNaN(r))return e?wd:is;if(e){if(r<0)return wd;if(r>=zI)return GI}else {if(r<=-PI)return kn;if(r+1>=PI)return BI}return r<0?as(-r,e).neg():cr(r%bf|0,r/bf|0,e)}ur.fromNumber=as;function cr(r,e,t){return new ur(r,e,t)}ur.fromBits=cr;var i6=Math.pow;function Ry(r,e,t){if(r.length===0)throw Error("empty string");if(r==="NaN"||r==="Infinity"||r==="+Infinity"||r==="-Infinity")return is;if(typeof e=="number"?(t=e,e=false):e=!!e,t=t||10,t<2||36<t)throw RangeError("radix");var o;if((o=r.indexOf("-"))>0)throw Error("interior hyphen");if(o===0)return Ry(r.substring(1),e,t).neg();for(var n=as(i6(t,8)),s=is,a=0;a<r.length;a+=8){var i=Math.min(8,r.length-a),p=parseInt(r.substring(a,a+i),t);if(i<8){var l=as(i6(t,i));s=s.mul(l).add(as(p));}else s=s.mul(n),s=s.add(as(p));}return s.unsigned=e,s}ur.fromString=Ry;function Ls(r,e){return typeof r=="number"?as(r,e):typeof r=="string"?Ry(r,e):cr(r.low,r.high,typeof e=="boolean"?e:r.unsigned)}ur.fromValue=Ls;var LI=65536,Vse=1<<24,bf=LI*LI,zI=bf*bf,PI=zI/2,VI=Sd(Vse),is=Sd(0);ur.ZERO=is;var wd=Sd(0,true);ur.UZERO=wd;var yf=Sd(1);ur.ONE=yf;var MI=Sd(1,true);ur.UONE=MI;var _y=Sd(-1);ur.NEG_ONE=_y;var BI=cr(-1,2147483647,false);ur.MAX_VALUE=BI;var GI=cr(-1,-1,true);ur.MAX_UNSIGNED_VALUE=GI;var kn=cr(0,-2147483648,false);ur.MIN_VALUE=kn;var ye=ur.prototype;ye.toInt=function(){return this.unsigned?this.low>>>0:this.low};ye.toNumber=function(){return this.unsigned?(this.high>>>0)*bf+(this.low>>>0):this.high*bf+(this.low>>>0)};ye.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(kn)){var t=as(e),o=this.div(t),n=o.mul(t).sub(this);return o.toString(e)+n.toInt().toString(e)}else return "-"+this.neg().toString(e);for(var s=as(i6(e,6),this.unsigned),a=this,i="";;){var p=a.div(s),l=a.sub(p.mul(s)).toInt()>>>0,u=l.toString(e);if(a=p,a.isZero())return u+i;for(;u.length<6;)u="0"+u;i=""+u+i;}};ye.getHighBits=function(){return this.high};ye.getHighBitsUnsigned=function(){return this.high>>>0};ye.getLowBits=function(){return this.low};ye.getLowBitsUnsigned=function(){return this.low>>>0};ye.getNumBitsAbs=function(){if(this.isNegative())return this.eq(kn)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,t=31;t>0&&(e&1<<t)==0;t--);return this.high!=0?t+33:t+1};ye.isZero=function(){return this.high===0&&this.low===0};ye.eqz=ye.isZero;ye.isNegative=function(){return !this.unsigned&&this.high<0};ye.isPositive=function(){return this.unsigned||this.high>=0};ye.isOdd=function(){return (this.low&1)===1};ye.isEven=function(){return (this.low&1)===0};ye.equals=function(e){return En(e)||(e=Ls(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?false:this.high===e.high&&this.low===e.low};ye.eq=ye.equals;ye.notEquals=function(e){return !this.eq(e)};ye.neq=ye.notEquals;ye.ne=ye.notEquals;ye.lessThan=function(e){return this.comp(e)<0};ye.lt=ye.lessThan;ye.lessThanOrEqual=function(e){return this.comp(e)<=0};ye.lte=ye.lessThanOrEqual;ye.le=ye.lessThanOrEqual;ye.greaterThan=function(e){return this.comp(e)>0};ye.gt=ye.greaterThan;ye.greaterThanOrEqual=function(e){return this.comp(e)>=0};ye.gte=ye.greaterThanOrEqual;ye.ge=ye.greaterThanOrEqual;ye.compare=function(e){if(En(e)||(e=Ls(e)),this.eq(e))return 0;var t=this.isNegative(),o=e.isNegative();return t&&!o?-1:!t&&o?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};ye.comp=ye.compare;ye.negate=function(){return !this.unsigned&&this.eq(kn)?kn:this.not().add(yf)};ye.neg=ye.negate;ye.add=function(e){En(e)||(e=Ls(e));var t=this.high>>>16,o=this.high&65535,n=this.low>>>16,s=this.low&65535,a=e.high>>>16,i=e.high&65535,p=e.low>>>16,l=e.low&65535,u=0,c=0,d=0,m=0;return m+=s+l,d+=m>>>16,m&=65535,d+=n+p,c+=d>>>16,d&=65535,c+=o+i,u+=c>>>16,c&=65535,u+=t+a,u&=65535,cr(d<<16|m,u<<16|c,this.unsigned)};ye.subtract=function(e){return En(e)||(e=Ls(e)),this.add(e.neg())};ye.sub=ye.subtract;ye.multiply=function(e){if(this.isZero())return is;if(En(e)||(e=Ls(e)),ss){var t=ss.mul(this.low,this.high,e.low,e.high);return cr(t,ss.get_high(),this.unsigned)}if(e.isZero())return is;if(this.eq(kn))return e.isOdd()?kn:is;if(e.eq(kn))return this.isOdd()?kn:is;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(VI)&&e.lt(VI))return as(this.toNumber()*e.toNumber(),this.unsigned);var o=this.high>>>16,n=this.high&65535,s=this.low>>>16,a=this.low&65535,i=e.high>>>16,p=e.high&65535,l=e.low>>>16,u=e.low&65535,c=0,d=0,m=0,h=0;return h+=a*u,m+=h>>>16,h&=65535,m+=s*u,d+=m>>>16,m&=65535,m+=a*l,d+=m>>>16,m&=65535,d+=n*u,c+=d>>>16,d&=65535,d+=s*l,c+=d>>>16,d&=65535,d+=a*p,c+=d>>>16,d&=65535,c+=o*u+n*l+s*p+a*i,c&=65535,cr(m<<16|h,c<<16|d,this.unsigned)};ye.mul=ye.multiply;ye.divide=function(e){if(En(e)||(e=Ls(e)),e.isZero())throw Error("division by zero");if(ss){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var t=(this.unsigned?ss.div_u:ss.div_s)(this.low,this.high,e.low,e.high);return cr(t,ss.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?wd:is;var o,n,s;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return wd;if(e.gt(this.shru(1)))return MI;s=wd;}else {if(this.eq(kn)){if(e.eq(yf)||e.eq(_y))return kn;if(e.eq(kn))return yf;var a=this.shr(1);return o=a.div(e).shl(1),o.eq(is)?e.isNegative()?yf:_y:(n=this.sub(e.mul(o)),s=o.add(n.div(e)),s)}else if(e.eq(kn))return this.unsigned?wd:is;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();s=is;}for(n=this;n.gte(e);){o=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var i=Math.ceil(Math.log(o)/Math.LN2),p=i<=48?1:i6(2,i-48),l=as(o),u=l.mul(e);u.isNegative()||u.gt(n);)o-=p,l=as(o,this.unsigned),u=l.mul(e);l.isZero()&&(l=yf),s=s.add(l),n=n.sub(u);}return s};ye.div=ye.divide;ye.modulo=function(e){if(En(e)||(e=Ls(e)),ss){var t=(this.unsigned?ss.rem_u:ss.rem_s)(this.low,this.high,e.low,e.high);return cr(t,ss.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};ye.mod=ye.modulo;ye.rem=ye.modulo;ye.not=function(){return cr(~this.low,~this.high,this.unsigned)};ye.and=function(e){return En(e)||(e=Ls(e)),cr(this.low&e.low,this.high&e.high,this.unsigned)};ye.or=function(e){return En(e)||(e=Ls(e)),cr(this.low|e.low,this.high|e.high,this.unsigned)};ye.xor=function(e){return En(e)||(e=Ls(e)),cr(this.low^e.low,this.high^e.high,this.unsigned)};ye.shiftLeft=function(e){return En(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?cr(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):cr(0,this.low<<e-32,this.unsigned)};ye.shl=ye.shiftLeft;ye.shiftRight=function(e){return En(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?cr(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):cr(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};ye.shr=ye.shiftRight;ye.shiftRightUnsigned=function(e){if(En(e)&&(e=e.toInt()),e&=63,e===0)return this;var t=this.high;if(e<32){var o=this.low;return cr(o>>>e|t<<32-e,t>>>e,this.unsigned)}else return e===32?cr(t,0,this.unsigned):cr(t>>>e-32,0,this.unsigned)};ye.shru=ye.shiftRightUnsigned;ye.shr_u=ye.shiftRightUnsigned;ye.toSigned=function(){return this.unsigned?cr(this.low,this.high,false):this};ye.toUnsigned=function(){return this.unsigned?this:cr(this.low,this.high,true)};ye.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};ye.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]};ye.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]};ur.fromBytes=function(e,t,o){return o?ur.fromBytesLE(e,t):ur.fromBytesBE(e,t)};ur.fromBytesLE=function(e,t){return new ur(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)};ur.fromBytesBE=function(e,t){return new ur(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};});function L0(r){return Td.fromString(r,true,16)}function Fy(r){return r.xor(r.shru(47))}function KI(r,e,t){let o=r.slice(e,e+t);return Td.fromBytes(Array.from(o),true,true)}function rr(r,e){return KI(r,e,8)}function HI(r,e){return KI(r,e,4)}function yo(r,e){return e===0?r:r.shru(e).or(r.shl(64-e))}function au(r,e,t=L0("9ddfea08eb382d69")){let o=r.xor(e).mul(t);o=o.xor(o.shru(47));let n=e.xor(o).mul(t);return n=n.xor(n.shru(47)),n=n.mul(t),n}function zse(r,e,t,o,n,s){n=n.add(r),s=yo(s.add(n).add(o),21);let a=n;return n=n.add(e),n=n.add(t),s=s.add(yo(n,44)),[n.add(o),s.add(a)]}function p6(r,e,t,o){return zse(rr(r,e),rr(r,e+8),rr(r,e+16),rr(r,e+24),t,o)}function Mse(r,e=r.length){if(e>=8){let t=Zo.add(e*2),o=rr(r,0).add(Zo),n=rr(r,e-8),s=yo(n,37).mul(t).add(o),a=yo(o,25).add(n).mul(t);return au(s,a,t)}if(e>=4){let t=Zo.add(e*2),o=HI(r,0);return au(o.shl(3).add(e),HI(r,e-4),t)}if(e>0){let t=r[0],o=r[e>>1],n=r[e-1],s=t+(o<<8),a=e+(n<<2);return Fy(Zo.mul(s).xor(qI.mul(a))).mul(Zo)}return Zo}function Bse(r,e=r.length){let t=Zo.add(e*2),o=rr(r,0).mul(Nd),n=rr(r,8),s=rr(r,e-8).mul(t),a=rr(r,e-16).mul(Zo);return au(yo(o.add(n),43).add(yo(s,30)).add(a),o.add(yo(n.add(Zo),18)).add(s),t)}function Gse(r,e=r.length){let t=Zo.add(e*2),o=rr(r,0).mul(Zo),n=rr(r,8),s=rr(r,e-8).mul(t),a=rr(r,e-16).mul(Zo),i=yo(o.add(n),43).add(yo(s,30)).add(a),p=au(i,o.add(yo(n.add(Zo),18)).add(s),t),l=rr(r,16).mul(t),u=rr(r,24),c=i.add(rr(r,e-32)).mul(t),d=p.add(rr(r,e-24)).mul(t);return au(yo(l.add(u),43).add(yo(c,30)).add(d),l.add(yo(u.add(o),18)).add(c),t)}function Use(r,e=r.length){let t=Td.fromNumber(81,true);if(e<=32)return e<=16?Mse(r,e):Bse(r,e);if(e<=64)return Gse(r,e);let o=t,n=t.mul(Nd).add(113),s=Fy(n.mul(Zo).add(113)).mul(Zo),a=[Td.UZERO,Td.UZERO],i=[Td.UZERO,Td.UZERO];o=o.mul(Zo).add(rr(r,0));let p=0,l=(e-1>>6)*64,u=l+(e-1&63)-63;do o=yo(o.add(n).add(a[0]).add(rr(r,p+8)),37).mul(Nd),n=yo(n.add(a[1]).add(rr(r,p+48)),42).mul(Nd),o=o.xor(i[1]),n=n.add(a[0]).add(rr(r,p+40)),s=yo(s.add(i[0]),33).mul(Nd),a=p6(r,p,a[1].mul(Nd),o.add(i[0])),i=p6(r,p+32,s.add(i[1]),n.add(rr(r,p+16))),[s,o]=[o,s],p+=64;while(p!==l);let c=Nd.add(s.and(255).shl(1));return p=u,i[0]=i[0].add(e-1&63),a[0]=a[0].add(i[0]),i[0]=i[0].add(a[0]),o=yo(o.add(n).add(a[0]).add(rr(r,p+8)),37).mul(c),n=yo(n.add(a[1]).add(rr(r,p+48)),42).mul(c),o=o.xor(i[1].mul(9)),n=n.add(a[0].mul(9).add(rr(r,p+40))),s=yo(s.add(i[0]),33).mul(c),a=p6(r,p,a[1].mul(c),o.add(i[0])),i=p6(r,p+32,s.add(i[1]),n.add(rr(r,p+16))),[s,o]=[o,s],au(au(a[0],i[0],c).add(Fy(n).mul(qI)).add(s),au(a[1],i[1],c).add(o),c)}var Oy,Td,qI,Nd,Zo,jI=f(()=>{Oy=sf(WI());Td=Oy.default||Oy;qI=L0("c3a5c85c97cb3127"),Nd=L0("b492b66fbe98f273"),Zo=L0("9ae16a3b2f90404f");});var v={};Ye(v,{arraysEqual:()=>Yo,arraysEqualWithNull:()=>by,assert:()=>D,assertNonNegativeIntegerDimensions:()=>tr,assertNonNull:()=>Wn,assertShapesMatch:()=>jt,bytesFromStringArray:()=>Ty,bytesPerElement:()=>pf,checkConversionForErrors:()=>Sy,clamp:()=>af,computeStrides:()=>Ia,convertBackendValuesAndArrayBuffer:()=>vse,createScalarValue:()=>Wse,createShuffledIndices:()=>gse,decodeString:()=>wf,distSquared:()=>dse,encodeString:()=>iu,fetch:()=>qse,fingerPrint64:()=>Use,flatten:()=>Ps,getArrayFromDType:()=>t6,getTypedArrayFromDType:()=>wy,hasEncodingLoss:()=>bse,hexToLong:()=>L0,indexToLoc:()=>Nse,inferDtype:()=>ql,inferFromImplicitShape:()=>yse,isBoolean:()=>EI,isFunction:()=>Ca,isInt:()=>Zi,isNumber:()=>AI,isPromise:()=>hc,isScalarShape:()=>mse,isString:()=>$s,isTypedArray:()=>Cr,isValidDtype:()=>Ny,locToIndex:()=>Sse,makeOnesTypedArray:()=>$0,makeZerosNestedTypedArray:()=>wse,makeZerosTypedArray:()=>uf,nearestDivisor:()=>lf,nearestLargerEven:()=>lse,now:()=>Cd,parseAxisParam:()=>Lr,randUniform:()=>cse,repeatedTry:()=>xse,rightPad:()=>fc,shuffle:()=>kI,shuffleCombo:()=>pse,sizeFromShape:()=>et,sizeToSquarishShape:()=>hse,squeezeShape:()=>vy,sum:()=>use,swap:()=>e6,tanh:()=>fse,toNestedArray:()=>mc,toTypedArray:()=>vf});function Wse(r,e){return e==="string"?iu(r):vf([r],e)}function Hse(r,e){return r instanceof Float32Array&&e==="float32"||r instanceof Int32Array&&e==="int32"||r instanceof Uint8Array&&e==="bool"}function vf(r,e){if(e==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(r)&&(r=Ps(r)),M().getBool("DEBUG")&&Sy(r,e),Hse(r,e))return r;if(e==null||e==="float32"||e==="complex64")return new Float32Array(r);if(e==="int32")return new Int32Array(r);if(e==="bool"){let t=new Uint8Array(r.length);for(let o=0;o<t.length;++o)Math.round(r[o])!==0&&(t[o]=1);return t}else throw new Error(`Unknown data type ${e}`)}function Cd(){return M().platform.now()}function qse(r,e){return M().platform.fetch(r,e)}function iu(r,e="utf-8"){return e=e||"utf-8",M().platform.encode(r,e)}function wf(r,e="utf-8"){return e=e||"utf-8",M().platform.decode(r,e)}function Cr(r){return M().platform.isTypedArray!=null?M().platform.isTypedArray(r):a6(r)}function Ps(r,e=[],t=false){if(e==null&&(e=[]),typeof r=="boolean"||typeof r=="number"||typeof r=="string"||hc(r)||r==null||Cr(r)&&t)e.push(r);else if(Array.isArray(r)||Cr(r))for(let o=0;o<r.length;++o)Ps(r[o],e,t);else {let o=-1;for(let n of Object.keys(r))/^([1-9]+[0-9]*|0)$/.test(n)&&(o=Math.max(o,Number(n)));for(let n=0;n<=o;n++)Ps(r[n],e,t);}return e}var J=f(()=>{xo();$y();Qr();Qr();jI();});function Kse(r,e,t){if(e!=="float32")return false;for(let o=0;o<r.length;o++){let n=r[o];if(isNaN(n)||!isFinite(n))return console.warn(`Found ${n} in the result of '${t}'`),true}return false}var l6,Ly,XI=f(()=>{xo();J();l6=class{constructor(e,t){this.backendTimer=e,this.logger=t,t==null&&(this.logger=new Ly);}profileKernel(e,t,o){let n,s=()=>{n=o();},a,i=Cd();if(this.backendTimer.timerAvailable())a=this.backendTimer.time(s);else {s();for(let l of n)l.dataSync();a=Promise.resolve({kernelMs:Cd()-i});}if(M().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(let l=0;l<n.length;l++){let u=n[l];u.data().then(c=>{Kse(c,u.dtype,e);});}return {kernelName:e,outputs:n,inputs:t,timeMs:a.then(l=>l.kernelMs),extraInfo:a.then(l=>l.getExtraProfileInfo!=null?l.getExtraProfileInfo():"")}}logKernelProfile(e){let{kernelName:t,outputs:o,timeMs:n,inputs:s,extraInfo:a}=e;o.forEach(i=>{Promise.all([i.data(),n,a]).then(p=>{this.logger.logKernelProfile(t,i,p[0],p[1],s,p[2]);});});}};Ly=class{logKernelProfile(e,t,o,n,s,a){let i=typeof n=="number"?fc(`${n}ms`,9):n.error,p=fc(e,25),l=t.rank,u=t.size,c=fc(t.shape.toString(),14),d="";for(let m in s){let h=s[m];if(h!=null){let g=h.shape||t.shape,x=g.length;d+=`${m}: ${x}D ${x>0?g:""} `;}}console.log(`%c${p} %c${i} %c${l}D ${c} %c${u} %c${d} %c${a}`,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue");}};});function YI(r,e,t){let o={},n={};for(let p=0;p<e.length;p++)o[e[p].id]=true;for(let p=0;p<r.length;p++){let l=r[p],u=l.inputs;for(let c in u){let d=u[c],m=false;for(let h=0;h<e.length;h++)if(o[d.id]){l.outputs.forEach(g=>o[g.id]=true),m=true,n[l.id]=true;break}if(m)break}}let s={};s[t.id]=true;let a={};for(let p=r.length-1;p>=0;p--){let l=r[p],u=l.inputs;for(let c=0;c<l.outputs.length;c++)if(s[l.outputs[c].id]){for(let d in u)s[u[d].id]=true,a[l.id]=true;break}}let i=[];for(let p=0;p<r.length;p++){let l=r[p];if(n[l.id]&&a[l.id]){let u={};for(let d in l.inputs){let m=l.inputs[d];o[m.id]&&(u[d]=m);}let c=Object.assign({},l);c.inputs=u,c.outputs=l.outputs,i.push(c);}}return i}function ZI(r,e,t,o){for(let n=e.length-1;n>=0;n--){let s=e[n],a=[];if(s.outputs.forEach(p=>{let l=r[p.id];l!=null?a.push(l):a.push(null);}),s.gradient==null)throw new Error(`Cannot compute gradient: gradient function not found for ${s.kernelName}.`);let i=s.gradient(a);for(let p in s.inputs){if(!(p in i))throw new Error(`Cannot backprop through input ${p}. Available gradients found: ${Object.keys(i)}.`);let l=t(()=>i[p]());if(l.dtype!=="float32")throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input ${p} must have 'float32' dtype, but has '${l.dtype}'`);let u=s.inputs[p];if(!Yo(l.shape,u.shape))throw new Error(`Error in gradient for op ${s.kernelName}. The gradient of input '${p}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`);if(r[u.id]==null)r[u.id]=l;else {let c=r[u.id];r[u.id]=o(c,l),c.dispose();}}}}var JI=f(()=>{J();});function ek(r,e,t,o){let n=Ia(e),s=jse(r,e,t,n),a=e.length,i=u6(r,e,t,n,s),p=["Tensor"];return o&&(p.push(` dtype: ${t}`),p.push(` rank: ${a}`),p.push(` shape: [${e}]`),p.push(" values:")),p.push(i.map(l=>" "+l).join(` `)),p.join(` `)}function jse(r,e,t,o){let n=et(e),s=o[o.length-1],a=new Array(s).fill(0),i=e.length,p=t==="complex64"?z0(r):r;if(i>1)for(let l=0;l<n/s;l++){let u=l*s;for(let c=0;c<s;c++)a[c]=Math.max(a[c],V0(p[u+c],0,t).length);}return a}function V0(r,e,t){let o;return Array.isArray(r)?o=`${parseFloat(r[0].toFixed(Py))} + ${parseFloat(r[1].toFixed(Py))}j`:$s(r)?o=`'${r}'`:t==="bool"?o=tk(r):o=parseFloat(r.toFixed(Py)).toString(),fc(o,e)}function tk(r){return r===0?"false":"true"}function u6(r,e,t,o,n,s=true){let a=t==="complex64"?2:1,i=e[0],p=e.length;if(p===0){if(t==="complex64"){let g=z0(r);return [V0(g[0],0,t)]}return t==="bool"?[tk(r[0])]:[r[0].toString()]}if(p===1){if(i>QI){let x=P0*a,y=Array.from(r.slice(0,x)),b=Array.from(r.slice((i-P0)*a,i*a));return t==="complex64"&&(y=z0(y),b=z0(b)),["["+y.map((S,w)=>V0(S,n[w],t)).join(", ")+", ..., "+b.map((S,w)=>V0(S,n[i-P0+w],t)).join(", ")+"]"]}return ["["+(t==="complex64"?z0(r):Array.from(r)).map((x,y)=>V0(x,n[y],t)).join(", ")+"]"]}let l=e.slice(1),u=o.slice(1),c=o[0]*a,d=[];if(i>QI){for(let g=0;g<P0;g++){let x=g*c,y=x+c;d.push(...u6(r.slice(x,y),l,t,u,n,false));}d.push("...");for(let g=i-P0;g<i;g++){let x=g*c,y=x+c;d.push(...u6(r.slice(x,y),l,t,u,n,g===i-1));}}else for(let g=0;g<i;g++){let x=g*c,y=x+c;d.push(...u6(r.slice(x,y),l,t,u,n,g===i-1));}let m=p===2?",":"";d[0]="["+(i>0?d[0]+m:"");for(let g=1;g<d.length-1;g++)d[g]=" "+d[g]+m;let h=`, `;for(let g=2;g<p;g++)h+=` `;return d[d.length-1]=" "+d[d.length-1]+"]"+(s?"":h),d}function z0(r){let e=[];for(let t=0;t<r.length;t+=2)e.push([r[t],r[t+1]]);return e}var QI,P0,Py,rk=f(()=>{J();QI=20,P0=3,Py=7;});function ok(r){Vs=r;}function nk(r){Sf=r;}function L(){return _0("Tensor",()=>Pe)}var lt,Vs,Sf,Pe,vi,Q=f(()=>{o6();rk();J();J();lt=class{constructor(e,t,o){if(this.dtype=t,this.shape=e.slice(),this.size=et(e),o!=null){let n=o.length;D(n===this.size,()=>`Length of values '${n}' does not match the size inferred by the shape '${this.size}'.`);}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=o||t6(t,this.size),this.strides=Ia(e);}set(e,...t){t.length===0&&(t=[0]),D(t.length===this.rank,()=>`The number of provided coordinates (${t.length}) must match the rank (${this.rank})`);let o=this.locToIndex(t);this.values[o]=e;}get(...e){e.length===0&&(e=[0]);let t=0;for(let n of e){if(n<0||n>=this.shape[t]){let s=`Requested out of range element at ${e}. Buffer shape=${this.shape}`;throw new Error(s)}t++;}let o=e[e.length-1];for(let n=0;n<e.length-1;++n)o+=this.strides[n]*e[n];return this.values[o]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let o=0;o<e.length-1;++o)t+=this.strides[o]*e[o];return t}indexToLoc(e){if(this.rank===0)return [];if(this.rank===1)return [e];let t=new Array(this.shape.length);for(let o=0;o<t.length-1;++o)t[o]=Math.floor(e/this.strides[o]),e-=t[o]*this.strides[o];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return Vs().makeTensor(this.values,this.shape,this.dtype)}},Vs=null,Sf=null;Pe=class{constructor(e,t,o,n){this.kept=false,this.isDisposedInternal=false,this.shape=e.slice(),this.dtype=t||"float32",this.size=et(e),this.strides=Ia(e),this.dataId=o,this.id=n,this.rankType=this.rank<5?this.rank.toString():"higher";}get rank(){return this.shape.length}async buffer(){let e=await this.data();return Sf.buffer(this.shape,this.dtype,e)}bufferSync(){return Sf.buffer(this.shape,this.dtype,this.dataSync())}async array(){let e=await this.data();return mc(this.shape,e,this.dtype==="complex64")}arraySync(){return mc(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();let e=Vs().read(this.dataId);if(this.dtype==="string"){let t=await e;try{return t.map(o=>wf(o))}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(),Vs().readToGPU(this.dataId,e)}dataSync(){this.throwIfDisposed();let e=Vs().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>wf(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();let e=await Vs().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(this.kerasMask&&this.kerasMask.dispose(),Vs().disposeTensor(this),this.isDisposedInternal=true);}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=false){return Sf.print(this,e)}clone(){return this.throwIfDisposed(),Sf.clone(this)}toString(e=false){let t=this.dataSync();return ek(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Sf.cast(this,e)}variable(e=true,t,o){return this.throwIfDisposed(),Vs().makeVariable(this,e,t,o)}};Object.defineProperty(Pe,Symbol.hasInstance,{value:r=>!!r&&r.data!=null&&r.dataSync!=null&&r.throwIfDisposed!=null});L();vi=class extends Pe{constructor(e,t,o,n){super(e.shape,e.dtype,e.dataId,n),this.trainable=t,this.name=o;}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);if(!Yo(e.shape,this.shape))throw new Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);Vs().disposeTensor(this),this.dataId=e.dataId,Vs().incRef(this,null);}dispose(){Vs().disposeVariable(this),this.isDisposedInternal=true;}};Object.defineProperty(vi,Symbol.hasInstance,{value:r=>r instanceof Pe&&r.assign!=null&&r.assign instanceof Function});});function Ir(r,e){if(r==="string"||e==="string"){if(r==="string"&&e==="string")return "string";throw new Error(`Can not upcast ${r} with ${e}`)}return Yse[r][e]}function pu(r){return Ir(r,"int32")}function d6(r){return r!=null&&typeof r=="object"&&"texture"in r&&r.texture instanceof WebGLTexture}function m6(r){return typeof GPUBuffer<"u"&&r!=null&&typeof r=="object"&&"buffer"in r&&r.buffer instanceof GPUBuffer}var c6,Vy,zy,My,By,Yse,Nf=f(()=>{(function(r){r.R0="R0",r.R1="R1",r.R2="R2",r.R3="R3",r.R4="R4",r.R5="R5",r.R6="R6";})(c6||(c6={}));(function(r){r.float32="float32",r.int32="int32",r.bool="int32",r.complex64="complex64";})(Vy||(Vy={}));(function(r){r.float32="float32",r.int32="int32",r.bool="bool",r.complex64="complex64";})(zy||(zy={}));(function(r){r.float32="float32",r.int32="float32",r.bool="float32",r.complex64="complex64";})(My||(My={}));(function(r){r.float32="complex64",r.int32="complex64",r.bool="complex64",r.complex64="complex64";})(By||(By={}));Yse={float32:My,int32:Vy,bool:zy,complex64:By};});var Hn={};Ye(Hn,{assertTypesMatch:()=>Gy,getTensorsInContainer:()=>M0,isTensorInList:()=>Zse,makeTypesMatch:()=>tt});function tt(r,e){if(r.dtype===e.dtype)return [r,e];let t=Ir(r.dtype,e.dtype);return [r.cast(t),e.cast(t)]}function Gy(r,e){D(r.dtype===e.dtype,()=>`The dtypes of the first(${r.dtype}) and second(${e.dtype}) input must match`);}function Zse(r,e){return e.some(t=>t.id===r.id)}function M0(r){let e=[];return ak(r,e,new Set),e}function ak(r,e,t){if(r==null)return;if(r instanceof Pe){e.push(r);return}if(!Jse(r))return;let o=r;for(let n in o){let s=o[n];t.has(s)||(t.add(s),ak(s,e,t));}}function Jse(r){return Array.isArray(r)||typeof r=="object"}var or=f(()=>{Q();Nf();J();});function Uy(r){return r.kernelName!=null}function Qse(r){let e=$0(et(r),"float32");return E.makeTensor(e,r,"float32")}function Wy(){let r=Iy();if(r._tfengine==null){let e=new cf(r);r._tfengine=new B0(e);}return _I(r._tfengine.ENV),ok(()=>r._tfengine),r._tfengine}function eae(r,e){let t={a:r,b:e};return E.runKernel(ns,t)}var f6,B0,E,q=f(()=>{yy();xo();o6();P();O0();n6();XI();JI();Q();or();J();J();f6=class{constructor(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=false,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null,get kernelNames(){return Array.from(new Set(this.kernels.map(e=>e.name)))}};}dispose(){for(let e in this.registeredVariables)this.registeredVariables[e].dispose();}},B0=class r{constructor(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new f6;}async ready(){if(this.pendingBackendInit!=null)return this.pendingBackendInit.then(()=>{});if(this.backendInstance!=null)return;let e=this.getSortedBackends();for(let t=0;t<e.length;t++){let o=e[t];if(await this.initializeBackend(o).success){await this.setBackend(o);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){let{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){let{asyncInit:t}=this.initializeBackend(e);if(t)return null}else return null;return this.registry[e]}findBackendFactory(e){return e in this.registryFactory?this.registryFactory[e].factory:null}registerBackend(e,t,o=1){return e in this.registryFactory?(bi(`${e} backend was already registered. Reusing existing backend factory.`),false):(this.registryFactory[e]={factory:t,priority:o},true)}async setBackend(e){if(this.registryFactory[e]==null)throw new Error(`Backend name '${e}' not found in registry`);if(this.backendName=e,this.registry[e]==null){this.backendInstance=null;let{success:t,asyncInit:o}=this.initializeBackend(e);if(!(o?await t:t))return false}return this.backendInstance=this.registry[e],this.setupRegisteredKernels(),this.profiler=new l6(this.backendInstance),true}setupRegisteredKernels(){F0(this.backendName).forEach(t=>{t.setupFunc!=null&&t.setupFunc(this.backendInstance);});}disposeRegisteredKernels(e){F0(e).forEach(o=>{o.disposeFunc!=null&&o.disposeFunc(this.registry[e]);});}initializeBackend(e){let t=this.registryFactory[e];if(t==null)throw new Error(`Cannot initialize backend ${e}, no registration found.`);try{let o=t.factory();if(o&&!(o instanceof Ta)&&typeof o.then=="function"){let n=++this.pendingBackendInitId,s=o.then(a=>n<this.pendingBackendInitId?!1:(this.registry[e]=a,this.pendingBackendInit=null,!0)).catch(a=>(n<this.pendingBackendInitId||(this.pendingBackendInit=null,bi(`Initialization of backend ${e} failed`),bi(a.stack||a.message)),!1));return this.pendingBackendInit=s,{success:s,asyncInit:!0}}else return this.registry[e]=o,{success:!0,asyncInit:!1}}catch(o){return bi(`Initialization of backend ${e} failed`),bi(o.stack||o.message),{success:false,asyncInit:false}}}removeBackend(e){if(!(e in this.registryFactory))throw new Error(`${e} backend not found in registry`);this.backendName===e&&this.pendingBackendInit!=null&&this.pendingBackendInitId++,e in this.registry&&(this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e]),delete this.registryFactory[e],this.backendName===e&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null);}getSortedBackends(){if(Object.keys(this.registryFactory).length===0)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort((e,t)=>this.registryFactory[t].priority-this.registryFactory[e].priority)}initializeBackendsAndReturnBest(){let e=this.getSortedBackends();for(let t=0;t<e.length;t++){let o=e[t],{success:n,asyncInit:s}=this.initializeBackend(o);if(s||n)return {name:o,asyncInit:s}}throw new Error("Could not initialize any backends, all backend initializations failed.")}moveData(e,t){let o=this.state.tensorInfo.get(t),n=o.backend,s=this.readSync(t),a=n.refCount(t);n.disposeData(t,true),o.backend=e,e.move(t,s,o.shape,o.dtype,a),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++;}tidy(e,t){let o=null;if(t==null){if(typeof e!="function")throw new Error("Please provide a function to tidy()");t=e;}else {if(typeof e!="string"&&!(e instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if(typeof t!="function")throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");o=e;}let n;return this.scopedRun(()=>this.startScope(o),()=>this.endScope(n),()=>(n=t(),n instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),n))}scopedRun(e,t,o){e();try{let n=o();return t(),n}catch(n){throw t(),n}}nextTensorId(){return r.nextTensorId++}nextVariableId(){return r.nextVariableId++}clone(e){let t=E.runKernel(Rs,{x:e}),o={x:e},n=a=>({x:()=>{let i="float32",p={x:a},l={dtype:i};return E.runKernel(_s,p,l)}}),s=[];return this.addTapeNode(this.state.activeScope.name,o,[t],n,s,{}),t}runKernel(e,t,o){if(this.backendName==null&&this.backend,!(vd(e,this.backendName)!=null))throw new Error(`Kernel '${e}' not registered for backend '${this.backendName}'`);return this.runKernelFunc({kernelName:e,inputs:t,attrs:o})}shouldCheckForMemLeaks(){return this.ENV.getBool("IS_TEST")}checkKernelForMemLeak(e,t,o){let n=this.backend.numDataIds(),s=0;o.forEach(p=>{s+=p.dtype==="complex64"?3:1;});let a=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],i=n-t-s-a;if(i>0)throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${e}'`)}runKernelFunc(e){let t,o=[],n=this.isTapeOn(),s=this.state.numBytes,a=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);let i;this.backendName==null&&this.backend;let p,l=Uy(e)?e.kernelName:this.state.activeScope!=null?this.state.activeScope.name:"";if(Uy(e)){let{kernelName:h,inputs:g,attrs:x}=e;this.backendName==null&&this.backend;let y=vd(h,this.backendName);D(y!=null,()=>`Cannot find registered kernel '${h}' for backend '${this.backendName}'`),i=()=>{let b=this.backend.numDataIds();p=y.kernelFunc({inputs:g,attrs:x,backend:this.backend});let S=Array.isArray(p)?p:[p];this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(h,b,S);let w=S.map(I=>I.rank!=null?I:this.makeTensorFromTensorInfo(I));if(n){let I=this.getTensorsForGradient(h,g,w);o=this.saveTensorsForBackwardMode(I);}return w};}else {let{forwardFunc:h}=e,g=x=>{n&&(o=x.map(y=>this.keep(this.clone(y))));};i=()=>{let x=this.backend.numDataIds();p=this.tidy(()=>h(this.backend,g));let y=Array.isArray(p)?p:[p];return this.shouldCheckForMemLeaks()&&this.checkKernelForMemLeak(l,x,y),y};}let{inputs:u,attrs:c}=e,d=Uy(e)?null:e.backwardsFunc,m;return this.scopedRun(()=>this.state.kernelDepth++,()=>this.state.kernelDepth--,()=>{!this.ENV.getBool("DEBUG")&&!this.state.profiling?t=i():(m=this.profiler.profileKernel(l,u,()=>i()),this.ENV.getBool("DEBUG")&&this.profiler.logKernelProfile(m),t=m.outputs);}),n&&this.addTapeNode(l,u,t,d,o,c),this.state.profiling&&this.state.activeProfile.kernels.push({name:l,bytesAdded:this.state.numBytes-s,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.nu