UNPKG

mind-ar

Version:

web augmented reality framework

230 lines 1.77 MB
(function(){"use strict";function G1(n,t){for(var e=0;e<t.length;e++){const s=t[e];if(typeof s!="string"&&!Array.isArray(s)){for(const o in s)if(o!=="default"&&!(o in n)){const r=Object.getOwnPropertyDescriptor(s,o);r&&Object.defineProperty(n,o,r.get?r:{enumerable:!0,get:()=>s[o]})}}}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 L1=1e-7,E1=1e-4;class pf{constructor(t,e){this.backend=t,this.dataMover=e,this.data=new WeakMap,this.dataIdsCount=0}get(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)}set(t,e){this.dataIdsCount++,this.data.set(t,e)}has(t){return this.data.has(t)}delete(t){return this.dataIdsCount--,this.data.delete(t)}numDataIds(){return this.dataIdsCount}}class Ac{refCount(t){return un("refCount")}incRef(t){return un("incRef")}timerAvailable(){return!0}time(t){return un("time")}read(t){return un("read")}readSync(t){return un("readSync")}readToGPU(t,e){return un("readToGPU")}numDataIds(){return un("numDataIds")}disposeData(t,e){return un("disposeData")}write(t,e,s){return un("write")}move(t,e,s,o,r){return un("move")}memory(){return un("memory")}floatPrecision(){return un("floatPrecision")}epsilon(){return this.floatPrecision()===32?L1:E1}dispose(){return un("dispose")}}function un(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 W1(n){let t=n.length,e=0;for(;t>0;)e=Math.random()*t|0,t--,Pn(n,t,e)}function Ys(n,t,e){return Math.max(n,Math.min(t,e))}function Kc(n){return n%2===0?n:n+1}function Pn(n,t,e){const s=n[t];n[t]=n[e],n[e]=s}function M1(n){let t=0;for(let e=0;e<n.length;e++)t+=n[e];return t}function k(n,t){if(!n)throw new Error(typeof t=="string"?t:t())}function Zc(n,t,e=""){k(Xt(n,t),()=>e+` Shapes ${n} and ${t} must match`)}function Bc(n){k(n!=null,()=>"The input to the tensor constructor must be a non-null value.")}function Go(n,t=[],e=!1){if(t==null&&(t=[]),Array.isArray(n)||qn(n)&&!e)for(let s=0;s<n.length;++s)Go(n[s],t,e);else t.push(n);return t}function H(n){if(n.length===0)return 1;let t=n[0];for(let e=1;e<n.length;e++)t*=n[e];return t}function Xt(n,t){if(n===t)return!0;if(n==null||t==null||n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;return!0}function Lo(n){return n%1===0}function Hc(n){const t=Math.ceil(Math.sqrt(n));return[t,Math.ceil(n/t)]}function Eo(n,t){return t<=n.length?n:n+" ".repeat(t-n.length)}function ff(n,t=o=>0,e,s=setTimeout){return new Promise((o,r)=>{let i=0;const a=()=>{if(n()){o();return}i++;const l=t(i);if(e!=null&&i>=e){r();return}s(a,l)};a()})}function mf(n,t){let e=1,s=-1;for(let r=0;r<n.length;++r)if(n[r]>=0)e*=n[r];else if(n[r]===-1){if(s!==-1)throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${r}`);s=r}else if(n[r]<0)throw Error(`Shapes can not be < 0. Found ${n[r]} at dim ${r}`);if(s===-1){if(t>0&&t!==e)throw Error(`Size(${t}) must match the product of shape ${n}`);return n}if(e===0)throw Error(`Cannot infer the missing size in [${n}] when there are 0 elements`);if(t%e!==0)throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${e}`);const o=n.slice();return o[s]=t/e,o}function Wt(n,t){const e=t.length;return n=n==null?t.map((s,o)=>o):[].concat(n),k(n.every(s=>s>=-e&&s<e),()=>`All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`),k(n.every(s=>Lo(s)),()=>`All values in axis param must be integers but got axis ${n}`),n.map(s=>s<0?e+s:s)}function ks(n,t){const e=[],s=[],o=t!=null&&Array.isArray(t)&&t.length===0,r=t==null||o?null:Wt(t,n).sort();let i=0;for(let a=0;a<n.length;++a){if(r!=null){if(r[i]===a&&n[a]!==1)throw new Error(`Can't squeeze axis ${a} since its dim '${n[a]}' is not 1`);(r[i]==null||r[i]>a)&&n[a]===1&&(e.push(n[a]),s.push(a)),r[i]<=a&&i++}n[a]!==1&&(e.push(n[a]),s.push(a))}return{newShape:e,keptDims:s}}function ue(n,t){let e=null;if(n==null||n==="float32")e=new Float32Array(t);else if(n==="int32")e=new Int32Array(t);else if(n==="bool")e=new Uint8Array(t);else throw new Error(`Unknown data type ${n}`);return e}function Ot(n,t){let e=null;if(n==null||n==="float32")e=new Float32Array(t);else if(n==="int32")e=new Int32Array(t);else if(n==="bool")e=new Uint8Array(t);else if(n==="string")e=new Array(t);else throw new Error(`Unknown data type ${n}`);return e}function D1(n,t){for(let e=0;e<n.length;e++){const s=n[e];if(isNaN(s)||!isFinite(s))throw Error(`A tensor of type ${t} being uploaded contains ${s}.`)}}function F1(n){return n==="bool"||n==="complex64"||n==="float32"||n==="int32"||n==="string"}function gf(n,t){return!(t==="complex64"||t==="float32"&&n!=="complex64"||t==="int32"&&n!=="float32"&&n!=="complex64"||t==="bool"&&n==="bool")}function qn(n){return n instanceof Float32Array||n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray}function _c(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 V1(n){if(n==null)return 0;let t=0;return n.forEach(e=>t+=e.length),t}function wr(n){return typeof n=="string"||n instanceof String}function z1(n){return typeof n=="boolean"}function Uc(n){return typeof n=="number"}function Cr(n){return Array.isArray(n)?Cr(n[0]):n instanceof Float32Array?"float32":n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray?"int32":Uc(n)?"float32":wr(n)?"string":z1(n)?"bool":"float32"}function Yc(n){return!!(n&&n.constructor&&n.call&&n.apply)}function jc(n,t){for(let e=t;e<n;++e)if(n%e===0)return e;return n}function bt(n){const t=n.length;if(t<2)return[];const e=new Array(t-1);e[t-2]=n[t-1];for(let s=t-3;s>=0;--s)e[s]=e[s+1]*n[s+1];return e}function bf(n,t,e,s=!1){const o=new Array;if(t.length===1){const r=t[0]*(s?2:1);for(let i=0;i<r;i++)o[i]=e[n+i]}else{const r=t[0],i=t.slice(1),a=i.reduce((l,c)=>l*c)*(s?2:1);for(let l=0;l<r;l++)o[l]=bf(n+l*a,i,e,s)}return o}function Xn(n,t,e=!1){if(n.length===0)return t[0];const s=n.reduce((o,r)=>o*r)*(e?2:1);if(s===0)return[];if(s!==t.length)throw new Error(`[${n}] does not match the input size ${t.length}${e?" for a complex tensor":""}.`);return bf(0,n,t,e)}function Qc(n,t){const e=fe(n,t);for(let s=0;s<e.length;s++)e[s]=1;return e}function fe(n,t){if(t==null||t==="float32"||t==="complex64")return new Float32Array(n);if(t==="int32")return new Int32Array(n);if(t==="bool")return new Uint8Array(n);throw new Error(`Unknown data type ${t}`)}function xf(n,t){const e=n.reduce((s,o)=>s*o,1);if(t==null||t==="float32")return Xn(n,new Float32Array(e));if(t==="int32")return Xn(n,new Int32Array(e));if(t==="bool")return Xn(n,new Uint8Array(e));throw new Error(`Unknown data type ${t}`)}function yf(n){n.forEach(t=>{k(Number.isInteger(t)&&t>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${n}].`)})}function dn(n,t,e){if(t===0)return 0;if(t===1)return n[0];let s=n[n.length-1];for(let o=0;o<n.length-1;++o)s+=e[o]*n[o];return s}function hs(n,t,e){if(t===0)return[];if(t===1)return[n];const s=new Array(t);for(let o=0;o<s.length-1;++o)s[o]=Math.floor(n/e[o]),n-=s[o]*e[o];return s[s.length-1]=n,s}function If(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 wf="tfjsflags";class P1{constructor(t){this.global=t,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=X1,this.populateURLFlags()}setPlatform(t,e){this.platform!=null&&(_().getBool("IS_TEST")||_().getBool("PROD")||console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)),this.platformName=t,this.platform=e}registerFlag(t,e,s){if(this.flagRegistry[t]={evaluationFn:e,setHook:s},this.urlFlags[t]!=null){const o=this.urlFlags[t];_().getBool("IS_TEST")||_().getBool("PROD")||console.warn(`Setting feature override from URL ${t}: ${o}.`),this.set(t,o)}}async getAsync(t){return t in this.flags?this.flags[t]:(this.flags[t]=await this.evaluateFlag(t),this.flags[t])}get(t){if(t in this.flags)return this.flags[t];const e=this.evaluateFlag(t);if(If(e))throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`);return this.flags[t]=e,this.flags[t]}getNumber(t){return this.get(t)}getBool(t){return this.get(t)}getFlags(){return this.flags}get features(){return this.flags}set(t,e){if(this.flagRegistry[t]==null)throw new Error(`Cannot set flag ${t} as it has not been registered.`);this.flags[t]=e,this.flagRegistry[t].setHook!=null&&this.flagRegistry[t].setHook(e)}evaluateFlag(t){if(this.flagRegistry[t]==null)throw new Error(`Cannot evaluate flag '${t}': no evaluation function found.`);return this.flagRegistry[t].evaluationFn()}setFlags(t){this.flags=Object.assign({},t)}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 t=this.getQueryParams(this.global.location.search);wf in t&&t[wf].split(",").forEach(s=>{const[o,r]=s.split(":");this.urlFlags[o]=A1(o,r)})}}function X1(n){const t={};return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(e,...s)=>(O1(t,s[0],s[1]),s.join("="))),t}function O1(n,t,e){n[decodeURIComponent(t)]=decodeURIComponent(e||"")}function A1(n,t){if(t=t.toLowerCase(),t==="true"||t==="false")return t==="true";if(`${+t}`===t)return+t;throw new Error(`Could not parse value flag value ${t} for flag ${n}.`)}function _(){return Cf}let Cf=null;function K1(n){Cf=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 Jc;function vf(){if(Jc==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");Jc=n}return Jc}function Z1(){const n=vf();return n._tfGlobals==null&&(n._tfGlobals=new Map),n._tfGlobals}function qc(n,t){const e=Z1();if(e.has(n))return e.get(n);{const s=t();return e.set(n,s),e.get(n)}}const ma="Abs",vr="Acos",Sr="Acosh",Wo="Add",tu="AddN",eu="All",nu="Any",ga="ArgMax",ba="ArgMin",kr="Asin",Tr="Asinh",Nr="Atan",Rr="Atanh",$r="Atan2",xa="AvgPool",su="AvgPoolGrad",ya="AvgPool3D",ou="AvgPool3DGrad",Ia="BatchMatMul",wa="BatchToSpaceND",ru="Bincount",B1="BroadcastTo",Sf="BroadcastArgs",Gr="Cast",Lr="Ceil",Er="ClipByValue",iu="Complex",Ca="ComplexAbs",va="Concat",Sa="Conv2D",au="Conv2DBackpropFilter",ka="Conv2DBackpropInput",Ta="Conv3D",lu="Conv3DBackpropFilterV2",cu="Conv3DBackpropInputV2",Wr="Cos",Mr="Cosh",uu="Cumprod",Na="Cumsum",du="CropAndResize",kf="DenseBincount",hu="DepthToSpace",Ra="DepthwiseConv2dNative",pu="DepthwiseConv2dNativeBackpropFilter",fu="DepthwiseConv2dNativeBackpropInput",Tf="Diag",$a="Dilation2D",mu="Dilation2DBackpropInput",gu="Dilation2DBackpropFilter",Dr="RealDiv",Nf="Einsum",Fr="Elu",bu="EluGrad",Vr="Erf",Ga="Equal",zr="Exp",La="ExpandDims",Pr="Expm1",xu="FFT",yu="Fill",Iu="FlipLeftRight",Xr="Floor",Or="FloorDiv",Ea="FusedBatchNorm",Wa="GatherV2",Rf="GatherNd",Ma="Greater",Ar="GreaterEqual",Kr="Identity",wu="IFFT",Cu="Imag",Zr="IsFinite",Br="IsInf",Hr="IsNan",Da="LeakyRelu",Fa="Less",Va="LessEqual",$f="LinSpace",_r="Log",Ur="Log1p",za="LogicalAnd",Pa="LogicalNot",Xa="LogicalOr",H1="LogSoftmax",Oa="LRN",vu="LRNGrad",Aa="Max",Yr="Maximum",Ka="MaxPool",Su="MaxPoolGrad",Za="MaxPool3D",ku="MaxPool3DGrad",Gf="MaxPoolWithArgmax",Ba="Mean",Ha="Min",jr="Minimum",_a="MirrorPad",Qr="Mod",Lf="Multinomial",Jr="Multiply",Ua="Neg",Ya="NotEqual",Tu="NonMaxSuppressionV3",Nu="NonMaxSuppressionV4",Ru="NonMaxSuppressionV5",ja="OnesLike",Qa="OneHot",Ja="Pack",qa="PadV2",qr="Pow",tl="Prelu",el="Prod",Ef="RaggedGather",Wf="RaggedTensorToTensor",$u="Range",Gu="Real",ti="Reciprocal",ei="Relu",nl="Reshape",sl="ResizeNearestNeighbor",Lu="ResizeNearestNeighborGrad",ol="ResizeBilinear",Eu="ResizeBilinearGrad",ni="Relu6",rl="Reverse",si="Round",oi="Rsqrt",Mf="ScatterNd",Df="SearchSorted",il="Select",ri="Selu",al="Slice",ii="Sin",ai="Sinh",li="Sign",ci="Sigmoid",ui="Softplus",di="Sqrt",ll="Sum",cl="SpaceToBatchND",ul="SplitV",dl="Softmax",Ff="SparseFillEmptyRows",Vf="SparseReshape",zf="SparseSegmentMean",Pf="SparseSegmentSum",Xf="SparseToDense",hi="SquaredDifference",Wu="Square",Mu="StridedSlice",Of="StringNGrams",Af="StringSplit",Kf="StringToHashBucketFast",pi="Sub",fi="Tan",mi="Tanh",gi="Tile",Du="TopK",Fu="Transform",Mo="Transpose",Vu="Unique",hl="Unpack",pl="UnsortedSegmentSum",fl="ZerosLike",bi="Step",zu="FromPixels",Pu="RotateWithOffset",ml="_FusedMatMul",gl="FusedConv2D",Zf="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 hn(...n){_().getBool("IS_TEST")||_().getBool("PROD")||console.warn(...n)}function _1(...n){_().getBool("IS_TEST")||_().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 bl=qc("kernelRegistry",()=>new Map),Xu=qc("gradRegistry",()=>new Map);function Ou(n,t){const e=_f(n,t);return bl.get(e)}function Bf(n){return Xu.get(n)}function Hf(n){const t=bl.entries(),e=[];for(;;){const{done:s,value:o}=t.next();if(s)break;const[r,i]=o,[a]=r.split("_");a===n&&e.push(i)}return e}function pn(n){const{kernelName:t,backendName:e}=n,s=_f(t,e);bl.has(s)&&hn(`The kernel '${t}' for backend '${e}' is already registered`),bl.set(s,n)}function U1(n){const{kernelName:t}=n;Xu.has(t)&&_().getBool("DEBUG")&&hn(`Overriding the gradient for '${t}'`),Xu.set(t,n)}function _f(n,t){return`${t}_${n}`}var Ts=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Y1(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function s(){if(this instanceof s){var o=[null];o.push.apply(o,arguments);var r=Function.bind.apply(t,o);return new r}return t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(n).forEach(function(s){var o=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(e,s,o.get?o:{enumerable:!0,get:function(){return n[s]}})}),e}var Au=ne,wn=null;try{wn=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 ne(n,t,e){this.low=n|0,this.high=t|0,this.unsigned=!!e}ne.prototype.__isLong__,Object.defineProperty(ne.prototype,"__isLong__",{value:!0});function nn(n){return(n&&n.__isLong__)===!0}ne.isLong=nn;var Uf={},Yf={};function js(n,t){var e,s,o;return t?(n>>>=0,(o=0<=n&&n<256)&&(s=Yf[n],s)?s:(e=se(n,(n|0)<0?-1:0,!0),o&&(Yf[n]=e),e)):(n|=0,(o=-128<=n&&n<128)&&(s=Uf[n],s)?s:(e=se(n,n<0?-1:0,!1),o&&(Uf[n]=e),e))}ne.fromInt=js;function Cn(n,t){if(isNaN(n))return t?Qs:vn;if(t){if(n<0)return Qs;if(n>=Qf)return nm}else{if(n<=-Jf)return sn;if(n+1>=Jf)return em}return n<0?Cn(-n,t).neg():se(n%Do|0,n/Do|0,t)}ne.fromNumber=Cn;function se(n,t,e){return new ne(n,t,e)}ne.fromBits=se;var xl=Math.pow;function Ku(n,t,e){if(n.length===0)throw Error("empty string");if(n==="NaN"||n==="Infinity"||n==="+Infinity"||n==="-Infinity")return vn;if(typeof t=="number"?(e=t,t=!1):t=!!t,e=e||10,e<2||36<e)throw RangeError("radix");var s;if((s=n.indexOf("-"))>0)throw Error("interior hyphen");if(s===0)return Ku(n.substring(1),t,e).neg();for(var o=Cn(xl(e,8)),r=vn,i=0;i<n.length;i+=8){var a=Math.min(8,n.length-i),l=parseInt(n.substring(i,i+a),e);if(a<8){var c=Cn(xl(e,a));r=r.mul(c).add(Cn(l))}else r=r.mul(o),r=r.add(Cn(l))}return r.unsigned=t,r}ne.fromString=Ku;function On(n,t){return typeof n=="number"?Cn(n,t):typeof n=="string"?Ku(n,t):se(n.low,n.high,typeof t=="boolean"?t:n.unsigned)}ne.fromValue=On;var jf=1<<16,j1=1<<24,Do=jf*jf,Qf=Do*Do,Jf=Qf/2,qf=js(j1),vn=js(0);ne.ZERO=vn;var Qs=js(0,!0);ne.UZERO=Qs;var Fo=js(1);ne.ONE=Fo;var tm=js(1,!0);ne.UONE=tm;var Zu=js(-1);ne.NEG_ONE=Zu;var em=se(-1,2147483647,!1);ne.MAX_VALUE=em;var nm=se(-1,-1,!0);ne.MAX_UNSIGNED_VALUE=nm;var sn=se(0,-2147483648,!1);ne.MIN_VALUE=sn;var ut=ne.prototype;ut.toInt=function(){return this.unsigned?this.low>>>0:this.low},ut.toNumber=function(){return this.unsigned?(this.high>>>0)*Do+(this.low>>>0):this.high*Do+(this.low>>>0)},ut.toString=function(t){if(t=t||10,t<2||36<t)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(sn)){var e=Cn(t),s=this.div(e),o=s.mul(e).sub(this);return s.toString(t)+o.toInt().toString(t)}else return"-"+this.neg().toString(t);for(var r=Cn(xl(t,6),this.unsigned),i=this,a="";;){var l=i.div(r),c=i.sub(l.mul(r)).toInt()>>>0,u=c.toString(t);if(i=l,i.isZero())return u+a;for(;u.length<6;)u="0"+u;a=""+u+a}},ut.getHighBits=function(){return this.high},ut.getHighBitsUnsigned=function(){return this.high>>>0},ut.getLowBits=function(){return this.low},ut.getLowBitsUnsigned=function(){return this.low>>>0},ut.getNumBitsAbs=function(){if(this.isNegative())return this.eq(sn)?64:this.neg().getNumBitsAbs();for(var t=this.high!=0?this.high:this.low,e=31;e>0&&!(t&1<<e);e--);return this.high!=0?e+33:e+1},ut.isZero=function(){return this.high===0&&this.low===0},ut.eqz=ut.isZero,ut.isNegative=function(){return!this.unsigned&&this.high<0},ut.isPositive=function(){return this.unsigned||this.high>=0},ut.isOdd=function(){return(this.low&1)===1},ut.isEven=function(){return(this.low&1)===0},ut.equals=function(t){return nn(t)||(t=On(t)),this.unsigned!==t.unsigned&&this.high>>>31===1&&t.high>>>31===1?!1:this.high===t.high&&this.low===t.low},ut.eq=ut.equals,ut.notEquals=function(t){return!this.eq(t)},ut.neq=ut.notEquals,ut.ne=ut.notEquals,ut.lessThan=function(t){return this.comp(t)<0},ut.lt=ut.lessThan,ut.lessThanOrEqual=function(t){return this.comp(t)<=0},ut.lte=ut.lessThanOrEqual,ut.le=ut.lessThanOrEqual,ut.greaterThan=function(t){return this.comp(t)>0},ut.gt=ut.greaterThan,ut.greaterThanOrEqual=function(t){return this.comp(t)>=0},ut.gte=ut.greaterThanOrEqual,ut.ge=ut.greaterThanOrEqual,ut.compare=function(t){if(nn(t)||(t=On(t)),this.eq(t))return 0;var e=this.isNegative(),s=t.isNegative();return e&&!s?-1:!e&&s?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},ut.comp=ut.compare,ut.negate=function(){return!this.unsigned&&this.eq(sn)?sn:this.not().add(Fo)},ut.neg=ut.negate,ut.add=function(t){nn(t)||(t=On(t));var e=this.high>>>16,s=this.high&65535,o=this.low>>>16,r=this.low&65535,i=t.high>>>16,a=t.high&65535,l=t.low>>>16,c=t.low&65535,u=0,d=0,h=0,p=0;return p+=r+c,h+=p>>>16,p&=65535,h+=o+l,d+=h>>>16,h&=65535,d+=s+a,u+=d>>>16,d&=65535,u+=e+i,u&=65535,se(h<<16|p,u<<16|d,this.unsigned)},ut.subtract=function(t){return nn(t)||(t=On(t)),this.add(t.neg())},ut.sub=ut.subtract,ut.multiply=function(t){if(this.isZero())return vn;if(nn(t)||(t=On(t)),wn){var e=wn.mul(this.low,this.high,t.low,t.high);return se(e,wn.get_high(),this.unsigned)}if(t.isZero())return vn;if(this.eq(sn))return t.isOdd()?sn:vn;if(t.eq(sn))return this.isOdd()?sn:vn;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(qf)&&t.lt(qf))return Cn(this.toNumber()*t.toNumber(),this.unsigned);var s=this.high>>>16,o=this.high&65535,r=this.low>>>16,i=this.low&65535,a=t.high>>>16,l=t.high&65535,c=t.low>>>16,u=t.low&65535,d=0,h=0,p=0,f=0;return f+=i*u,p+=f>>>16,f&=65535,p+=r*u,h+=p>>>16,p&=65535,p+=i*c,h+=p>>>16,p&=65535,h+=o*u,d+=h>>>16,h&=65535,h+=r*c,d+=h>>>16,h&=65535,h+=i*l,d+=h>>>16,h&=65535,d+=s*u+o*c+r*l+i*a,d&=65535,se(p<<16|f,d<<16|h,this.unsigned)},ut.mul=ut.multiply,ut.divide=function(t){if(nn(t)||(t=On(t)),t.isZero())throw Error("division by zero");if(wn){if(!this.unsigned&&this.high===-2147483648&&t.low===-1&&t.high===-1)return this;var e=(this.unsigned?wn.div_u:wn.div_s)(this.low,this.high,t.low,t.high);return se(e,wn.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Qs:vn;var s,o,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return Qs;if(t.gt(this.shru(1)))return tm;r=Qs}else{if(this.eq(sn)){if(t.eq(Fo)||t.eq(Zu))return sn;if(t.eq(sn))return Fo;var i=this.shr(1);return s=i.div(t).shl(1),s.eq(vn)?t.isNegative()?Fo:Zu:(o=this.sub(t.mul(s)),r=s.add(o.div(t)),r)}else if(t.eq(sn))return this.unsigned?Qs:vn;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=vn}for(o=this;o.gte(t);){s=Math.max(1,Math.floor(o.toNumber()/t.toNumber()));for(var a=Math.ceil(Math.log(s)/Math.LN2),l=a<=48?1:xl(2,a-48),c=Cn(s),u=c.mul(t);u.isNegative()||u.gt(o);)s-=l,c=Cn(s,this.unsigned),u=c.mul(t);c.isZero()&&(c=Fo),r=r.add(c),o=o.sub(u)}return r},ut.div=ut.divide,ut.modulo=function(t){if(nn(t)||(t=On(t)),wn){var e=(this.unsigned?wn.rem_u:wn.rem_s)(this.low,this.high,t.low,t.high);return se(e,wn.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},ut.mod=ut.modulo,ut.rem=ut.modulo,ut.not=function(){return se(~this.low,~this.high,this.unsigned)},ut.and=function(t){return nn(t)||(t=On(t)),se(this.low&t.low,this.high&t.high,this.unsigned)},ut.or=function(t){return nn(t)||(t=On(t)),se(this.low|t.low,this.high|t.high,this.unsigned)},ut.xor=function(t){return nn(t)||(t=On(t)),se(this.low^t.low,this.high^t.high,this.unsigned)},ut.shiftLeft=function(t){return nn(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?se(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):se(0,this.low<<t-32,this.unsigned)},ut.shl=ut.shiftLeft,ut.shiftRight=function(t){return nn(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?se(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):se(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},ut.shr=ut.shiftRight,ut.shiftRightUnsigned=function(t){if(nn(t)&&(t=t.toInt()),t&=63,t===0)return this;var e=this.high;if(t<32){var s=this.low;return se(s>>>t|e<<32-t,e>>>t,this.unsigned)}else return t===32?se(e,0,this.unsigned):se(e>>>t-32,0,this.unsigned)},ut.shru=ut.shiftRightUnsigned,ut.shr_u=ut.shiftRightUnsigned,ut.toSigned=function(){return this.unsigned?se(this.low,this.high,!1):this},ut.toUnsigned=function(){return this.unsigned?this:se(this.low,this.high,!0)},ut.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},ut.toBytesLE=function(){var t=this.high,e=this.low;return[e&255,e>>>8&255,e>>>16&255,e>>>24,t&255,t>>>8&255,t>>>16&255,t>>>24]},ut.toBytesBE=function(){var t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,t&255,e>>>24,e>>>16&255,e>>>8&255,e&255]},ne.fromBytes=function(t,e,s){return s?ne.fromBytesLE(t,e):ne.fromBytesBE(t,e)},ne.fromBytesLE=function(t,e){return new ne(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)},ne.fromBytesBE=function(t,e){return new ne(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)};const Q1=G1({__proto__:null,default:Au},[Au]);/** * @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 Js=Au||Q1;function yl(n){return Js.fromString(n,!0,16)}const sm=yl("c3a5c85c97cb3127"),qs=yl("b492b66fbe98f273"),Oe=yl("9ae16a3b2f90404f");function Bu(n){return n.xor(n.shru(47))}function om(n,t,e){const s=n.slice(t,t+e);return Js.fromBytes(Array.from(s),!0,!0)}function Qt(n,t){return om(n,t,8)}function rm(n,t){return om(n,t,4)}function Ge(n,t){return t===0?n:n.shru(t).or(n.shl(64-t))}function Ns(n,t,e=yl("9ddfea08eb382d69")){let s=n.xor(t).mul(e);s=s.xor(s.shru(47));let o=t.xor(s).mul(e);return o=o.xor(o.shru(47)),o=o.mul(e),o}function J1(n,t,e,s,o,r){o=o.add(n),r=Ge(r.add(o).add(s),21);const i=o;return o=o.add(t),o=o.add(e),r=r.add(Ge(o,44)),[o.add(s),r.add(i)]}function Il(n,t,e,s){return J1(Qt(n,t),Qt(n,t+8),Qt(n,t+16),Qt(n,t+24),e,s)}function q1(n,t=n.length){if(t>=8){const e=Oe.add(t*2),s=Qt(n,0).add(Oe),o=Qt(n,t-8),r=Ge(o,37).mul(e).add(s),i=Ge(s,25).add(o).mul(e);return Ns(r,i,e)}if(t>=4){const e=Oe.add(t*2),s=rm(n,0);return Ns(s.shl(3).add(t),rm(n,t-4),e)}if(t>0){const e=n[0],s=n[t>>1],o=n[t-1],r=e+(s<<8),i=t+(o<<2);return Bu(Oe.mul(r).xor(sm.mul(i))).mul(Oe)}return Oe}function tI(n,t=n.length){const e=Oe.add(t*2),s=Qt(n,0).mul(qs),o=Qt(n,8),r=Qt(n,t-8).mul(e),i=Qt(n,t-16).mul(Oe);return Ns(Ge(s.add(o),43).add(Ge(r,30)).add(i),s.add(Ge(o.add(Oe),18)).add(r),e)}function eI(n,t=n.length){const e=Oe.add(t*2),s=Qt(n,0).mul(Oe),o=Qt(n,8),r=Qt(n,t-8).mul(e),i=Qt(n,t-16).mul(Oe),a=Ge(s.add(o),43).add(Ge(r,30)).add(i),l=Ns(a,s.add(Ge(o.add(Oe),18)).add(r),e),c=Qt(n,16).mul(e),u=Qt(n,24),d=a.add(Qt(n,t-32)).mul(e),h=l.add(Qt(n,t-24)).mul(e);return Ns(Ge(c.add(u),43).add(Ge(d,30)).add(h),c.add(Ge(u.add(s),18)).add(d),e)}function im(n,t=n.length){const e=Js.fromNumber(81,!0);if(t<=32)return t<=16?q1(n,t):tI(n,t);if(t<=64)return eI(n,t);let s=e,o=e.mul(qs).add(113),r=Bu(o.mul(Oe).add(113)).mul(Oe),i=[Js.UZERO,Js.UZERO],a=[Js.UZERO,Js.UZERO];s=s.mul(Oe).add(Qt(n,0));let l=0;const c=(t-1>>6)*64,u=c+(t-1&63)-63;do s=Ge(s.add(o).add(i[0]).add(Qt(n,l+8)),37).mul(qs),o=Ge(o.add(i[1]).add(Qt(n,l+48)),42).mul(qs),s=s.xor(a[1]),o=o.add(i[0]).add(Qt(n,l+40)),r=Ge(r.add(a[0]),33).mul(qs),i=Il(n,l,i[1].mul(qs),s.add(a[0])),a=Il(n,l+32,r.add(a[1]),o.add(Qt(n,l+16))),[r,s]=[s,r],l+=64;while(l!==c);const d=qs.add(r.and(255).shl(1));return l=u,a[0]=a[0].add(t-1&63),i[0]=i[0].add(a[0]),a[0]=a[0].add(i[0]),s=Ge(s.add(o).add(i[0]).add(Qt(n,l+8)),37).mul(d),o=Ge(o.add(i[1]).add(Qt(n,l+48)),42).mul(d),s=s.xor(a[1].mul(9)),o=o.add(i[0].mul(9).add(Qt(n,l+40))),r=Ge(r.add(a[0]),33).mul(d),i=Il(n,l,i[1].mul(d),s.add(a[0])),a=Il(n,l+32,r.add(a[1]),o.add(Qt(n,l+16))),[r,s]=[s,r],Ns(Ns(i[0],a[0],d).add(Bu(o).mul(sm)).add(r),Ns(i[1],a[1],d).add(s),d)}/** * @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 ps(n,t){return t==="string"?An(n):Rs([n],t)}function nI(n,t){return n instanceof Float32Array&&t==="float32"||n instanceof Int32Array&&t==="int32"||n instanceof Uint8Array&&t==="bool"}function Rs(n,t){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(n)&&(n=Go(n)),_().getBool("DEBUG")&&D1(n,t),nI(n,t))return n;if(t==null||t==="float32"||t==="complex64")return new Float32Array(n);if(t==="int32")return new Int32Array(n);if(t==="bool"){const e=new Uint8Array(n.length);for(let s=0;s<e.length;++s)Math.round(n[s])!==0&&(e[s]=1);return e}else throw new Error(`Unknown data type ${t}`)}function Ye(){return _().platform.now()}function An(n,t="utf-8"){return t=t||"utf-8",_().platform.encode(n,t)}function $s(n,t="utf-8"){return t=t||"utf-8",_().platform.decode(n,t)}/** * @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 sI{constructor(t,e){this.backendTimer=t,this.logger=e,e==null&&(this.logger=new rI)}profileKernel(t,e,s){let o;const r=()=>{o=s()};let i;const a=Ye();if(this.backendTimer.timerAvailable())i=this.backendTimer.time(r);else{r();for(const c of o)c.dataSync();i=Promise.resolve({kernelMs:Ye()-a})}if(_().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(let c=0;c<o.length;c++){const u=o[c];u.data().then(d=>{oI(d,u.dtype,t)})}return{kernelName:t,outputs:o,inputs:e,timeMs:i.then(c=>c.kernelMs),extraInfo:i.then(c=>c.getExtraProfileInfo!=null?c.getExtraProfileInfo():"")}}logKernelProfile(t){const{kernelName:e,outputs:s,timeMs:o,inputs:r,extraInfo:i}=t;s.forEach(a=>{Promise.all([a.data(),o,i]).then(l=>{this.logger.logKernelProfile(e,a,l[0],l[1],r,l[2])})})}}function oI(n,t,e){if(t!=="float32")return!1;for(let s=0;s<n.length;s++){const o=n[s];if(isNaN(o)||!isFinite(o))return console.warn(`Found ${o} in the result of '${e}'`),!0}return!1}class rI{logKernelProfile(t,e,s,o,r,i){const a=typeof o=="number"?Eo(`${o}ms`,9):o.error,l=Eo(t,25),c=e.rank,u=e.size,d=Eo(e.shape.toString(),14);let h="";for(const p in r){const f=r[p];if(f!=null){const g=f.shape||e.shape,m=g.length;h+=`${p}: ${m}D ${m>0?g:""} `}}console.log(`%c${l} %c${a} %c${c}D ${d} %c${u} %c${h} %c${i}`,"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 iI(n,t,e){const s={},o={};for(let l=0;l<t.length;l++)s[t[l].id]=!0;for(let l=0;l<n.length;l++){const c=n[l],u=c.inputs;for(const d in u){const h=u[d];let p=!1;for(let f=0;f<t.length;f++)if(s[h.id]){c.outputs.forEach(g=>s[g.id]=!0),p=!0,o[c.id]=!0;break}if(p)break}}const r={};r[e.id]=!0;const i={};for(let l=n.length-1;l>=0;l--){const c=n[l],u=c.inputs;for(let d=0;d<c.outputs.length;d++)if(r[c.outputs[d].id]){for(const h in u)r[u[h].id]=!0,i[c.id]=!0;break}}const a=[];for(let l=0;l<n.length;l++){const c=n[l];if(o[c.id]&&i[c.id]){const u={};for(const h in c.inputs){const p=c.inputs[h];s[p.id]&&(u[h]=p)}const d=Object.assign({},c);d.inputs=u,d.outputs=c.outputs,a.push(d)}}return a}function aI(n,t,e,s){for(let o=t.length-1;o>=0;o--){const r=t[o],i=[];if(r.outputs.forEach(l=>{const c=n[l.id];c!=null?i.push(c):i.push(null)}),r.gradient==null)throw new Error(`Cannot compute gradient: gradient function not found for ${r.kernelName}.`);const a=r.gradient(i);for(const l in r.inputs){if(!(l in a))throw new Error(`Cannot backprop through input ${l}. Available gradients found: ${Object.keys(a)}.`);const c=e(()=>a[l]());if(c.dtype!=="float32")throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input ${l} must have 'float32' dtype, but has '${c.dtype}'`);const u=r.inputs[l];if(!Xt(c.shape,u.shape))throw new Error(`Error in gradient for op ${r.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 d=n[u.id];n[u.id]=s(d,c),d.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 am=20,xi=3,Hu=7;function lI(n,t,e,s){const o=bt(t),r=cI(n,t,e,o),i=t.length,a=wl(n,t,e,o,r),l=["Tensor"];return s&&(l.push(` dtype: ${e}`),l.push(` rank: ${i}`),l.push(` shape: [${t}]`),l.push(" values:")),l.push(a.map(c=>" "+c).join(` `)),l.join(` `)}function cI(n,t,e,s){const o=H(t),r=s[s.length-1],i=new Array(r).fill(0),a=t.length,l=e==="complex64"?Ii(n):n;if(a>1)for(let c=0;c<o/r;c++){const u=c*r;for(let d=0;d<r;d++)i[d]=Math.max(i[d],yi(l[u+d],0,e).length)}return i}function yi(n,t,e){let s;return Array.isArray(n)?s=`${parseFloat(n[0].toFixed(Hu))} + ${parseFloat(n[1].toFixed(Hu))}j`:wr(n)?s=`'${n}'`:e==="bool"?s=lm(n):s=parseFloat(n.toFixed(Hu)).toString(),Eo(s,t)}function lm(n){return n===0?"false":"true"}function wl(n,t,e,s,o,r=!0){const i=e==="complex64"?2:1,a=t[0],l=t.length;if(l===0){if(e==="complex64"){const g=Ii(n);return[yi(g[0],0,e)]}return e==="bool"?[lm(n[0])]:[n[0].toString()]}if(l===1){if(a>am){const m=xi*i;let b=Array.from(n.slice(0,m)),x=Array.from(n.slice((a-xi)*i,a*i));return e==="complex64"&&(b=Ii(b),x=Ii(x)),["["+b.map((I,y)=>yi(I,o[y],e)).join(", ")+", ..., "+x.map((I,y)=>yi(I,o[a-xi+y],e)).join(", ")+"]"]}return["["+(e==="complex64"?Ii(n):Array.from(n)).map((m,b)=>yi(m,o[b],e)).join(", ")+"]"]}const c=t.slice(1),u=s.slice(1),d=s[0]*i,h=[];if(a>am){for(let g=0;g<xi;g++){const m=g*d,b=m+d;h.push(...wl(n.slice(m,b),c,e,u,o,!1))}h.push("...");for(let g=a-xi;g<a;g++){const m=g*d,b=m+d;h.push(...wl(n.slice(m,b),c,e,u,o,g===a-1))}}else for(let g=0;g<a;g++){const m=g*d,b=m+d;h.push(...wl(n.slice(m,b),c,e,u,o,g===a-1))}const p=l===2?",":"";h[0]="["+h[0]+p;for(let g=1;g<h.length-1;g++)h[g]=" "+h[g]+p;let f=`, `;for(let g=2;g<l;g++)f+=` `;return h[h.length-1]=" "+h[h.length-1]+"]"+(r?"":f),h}function Ii(n){const t=[];for(let e=0;e<n.length;e+=2)t.push([n[e],n[e+1]]);return t}/** * @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 Le{constructor(t,e,s){if(this.dtype=e,this.shape=t.slice(),this.size=H(t),s!=null){const o=s.length;k(o===this.size,()=>`Length of values '${o}' does not match the size inferred by the shape '${this.size}'.`)}if(e==="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||Ot(e,this.size),this.strides=bt(t)}set(t,...e){e.length===0&&(e=[0]),k(e.length===this.rank,()=>`The number of provided coordinates (${e.length}) must match the rank (${this.rank})`);const s=this.locToIndex(e);this.values[s]=t}get(...t){t.length===0&&(t=[0]);let e=0;for(const o of t){if(o<0||o>=this.shape[e]){const r=`Requested out of range element at ${t}. Buffer shape=${this.shape}`;throw new Error(r)}e++}let s=t[t.length-1];for(let o=0;o<t.length-1;++o)s+=this.strides[o]*t[o];return this.values[s]}locToIndex(t){if(this.rank===0)return 0;if(this.rank===1)return t[0];let e=t[t.length-1];for(let s=0;s<t.length-1;++s)e+=this.strides[s]*t[s];return e}indexToLoc(t){if(this.rank===0)return[];if(this.rank===1)return[t];const e=new Array(this.shape.length);for(let s=0;s<e.length-1;++s)e[s]=Math.floor(t/this.strides[s]),t-=e[s]*this.strides[s];return e[e.length-1]=t,e}get rank(){return this.shape.length}toTensor(){return Kn().makeTensor(this.values,this.shape,this.dtype)}}let Kn=null,Vo=null;function uI(n){Kn=n}function dI(n){Vo=n}class xe{constructor(t,e,s,o){this.kept=!1,this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=H(t),this.strides=bt(t),this.dataId=s,this.id=o,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const t=await this.data();return Vo.buffer(this.shape,this.dtype,t)}bufferSync(){return Vo.buffer(this.shape,this.dtype,this.dataSync())}async array(){const t=await this.data();return Xn(this.shape,t,this.dtype==="complex64")}arraySync(){return Xn(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();const t=Kn().read(this.dataId);if(this.dtype==="string"){const e=await t;try{return e.map(s=>$s(s))}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return t}dataToGPU(t){return this.throwIfDisposed(),Kn().readToGPU(this.dataId,t)}dataSync(){this.throwIfDisposed();const t=Kn().readSync(this.dataId);if(this.dtype==="string")try{return t.map(e=>$s(e))}catch{throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return t}async bytes(){this.throwIfDisposed();const t=await Kn().read(this.dataId);return this.dtype==="string"?t:new Uint8Array(t.buffer)}dispose(){this.isDisposed||(Kn().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(t=!1){return Vo.print(this,t)}clone(){return this.throwIfDisposed(),Vo.clone(this)}toString(t=!1){const e=this.dataSync();return lI(e,this.shape,this.dtype,t)}cast(t){return this.throwIfDisposed(),Vo.cast(this,t)}variable(t=!0,e,s){return this.throwIfDisposed(),Kn().makeVariable(this,t,e,s)}}Object.defineProperty(xe,Symbol.hasInstance,{value:n=>!!n&&n.data!=null&&n.dataSync!=null&&n.throwIfDisposed!=null});function Q(){return qc("Tensor",()=>xe)}Q();class Cl extends xe{constructor(t,e,s,o){super(t.shape,t.dtype,t.dataId,o),this.trainable=e,this.name=s}assign(t){if(t.dtype!==this.dtype)throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`);if(!Xt(t.shape,this.shape))throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`);Kn().disposeTensor(this),this.dataId=t.dataId,Kn().incRef(this,null)}dispose(){Kn().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(Cl,Symbol.hasInstance,{value:n=>n instanceof xe&&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 cm;(function(n){n.R0="R0",n.R1="R1",n.R2="R2",n.R3="R3",n.R4="R4",n.R5="R5",n.R6="R6"})(cm||(cm={}));var _u;(function(n){n.float32="float32",n.int32="int32",n.bool="int32",n.complex64="complex64"})(_u||(_u={}));var Uu;(function(n){n.float32="float32",n.int32="int32",n.bool="bool",n.complex64="complex64"})(Uu||(Uu={}));var Yu;(function(n){n.float32="float32",n.int32="float32",n.bool="float32",n.complex64="complex64"})(Yu||(Yu={}));var ju;(function(n){n.float32="complex64",n.int32="complex64",n.bool="complex64",n.complex64="complex64"})(ju||(ju={}));const hI={float32:Yu,int32:_u,bool:Uu,complex64:ju};function je(n,t){if(n==="string"||t==="string"){if(n==="string"&&t==="string")return"string";throw new Error(`Can not upcast ${n} with ${t}`)}return hI[n][t]}function Qu(n){return je(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 me(n,t){if(n.dtype===t.dtype)return[n,t];const e=je(n.dtype,t.dtype);return[n.cast(e),t.cast(e)]}function um(n){const t=[];return dm(n,t,new Set),t}function dm(n,t,e){if(n==null)return;if(n instanceof xe){t.push(n);return}if(!pI(n))return;const s=n;for(const o in s){const r=s[o];e.has(r)||(e.add(r),dm(r,t,e))}}function pI(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 Ju(n){return n.kernelName!=null}class hm{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(t=>t.name)))}}}dispose(){for(const t in this.registeredVariables)this.registeredVariables[t].dispose()}}class zo{constructor(t){this.ENV=t,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new hm}async ready(){if(this.pendingBackendInit!=null)return this.pendingBackendInit.then(()=>{});if(this.backendInstance!=null)return;const t=this.getSortedBackends();for(let e=0;e<t.length;e++){const s=t[e];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:t,asyncInit:e}=this.initializeBackendsAndReturnBest();if(e)throw new Error(`The highest priority backend '${t}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);this.setBackend(t)}return this.backendInstance}backendNames(){return Object.keys(this.registryFactory)}findBackend(t){if(!(t in this.registry))if(t in this.registryFactory){const{asyncInit:e}=this.initializeBackend(t);if(e)return null}else return null;return this.registry[t]}findBackendFactory(t){return t in this.registryFactory?this.registryFactory[t].factory:null}registerBackend(t,e,s=1){return t in this.registryFactory?(hn(`${t} backend was already registered. Reusing existing backend factory.`),!1):(this.registryFactory[t]={factory:e,priority:s},!0)}async setBackend(t){if(this.registryFactory[t]==null)throw new Error(`Backend name '${t}' not found in registry`);if(this.backendName=t,this.registry[t]==null){this.backendInstance=null;const{success:e,asyncInit:s}=this.initializeBackend(t);if(!(s?await e:e))return!1}return this.backendInstance=this.registry[t],this.setupRegisteredKernels(),this.profiler=new sI(this.backendInstance),!0}setupRegisteredKernels(){Hf(this.backendName).forEach(e=>{e.setupFunc!=null&&e.setupFunc(this.backendInstance)})}disposeRegisteredKernels(t){Hf(t).forEach(s=>{s.disposeFunc!