UNPKG

mind-ar

Version:

web augmented reality framework

245 lines 1.76 MB
(function(){"use strict";function YI(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 QI=1e-7,JI=1e-4;class lf{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 Zl{refCount(t){return Ze("refCount")}incRef(t){return Ze("incRef")}timerAvailable(){return!0}time(t){return Ze("time")}read(t){return Ze("read")}readSync(t){return Ze("readSync")}readToGPU(t,e){return Ze("readToGPU")}numDataIds(){return Ze("numDataIds")}disposeData(t,e){return Ze("disposeData")}write(t,e,s){return Ze("write")}move(t,e,s,o,r){return Ze("move")}createTensorFromGPUData(t,e,s){return Ze("createTensorFromGPUData")}memory(){return Ze("memory")}floatPrecision(){return Ze("floatPrecision")}epsilon(){return this.floatPrecision()===32?QI:JI}dispose(){return Ze("dispose")}}function Ze(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 jI(n){let t=n.length,e=0;for(;t>0;)e=Math.random()*t|0,t--,Eo(n,t,e)}function Ks(n,t,e){return Math.max(n,Math.min(t,e))}function Bl(n){return n%2===0?n:n+1}function Eo(n,t,e){const s=n[t];n[t]=n[e],n[e]=s}function qI(n){let t=0;for(let e=0;e<n.length;e++)t+=n[e];return t}function v(n,t){if(!n)throw new Error(typeof t=="string"?t:t())}function Hl(n,t,e=""){v(Rt(n,t),()=>e+` Shapes ${n} and ${t} must match`)}function _l(n){v(n!=null,()=>"The input to the tensor constructor must be a non-null value.")}function Z(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 Rt(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 Do(n){return n%1===0}function Ul(n){const t=Math.ceil(Math.sqrt(n));return[t,Math.ceil(n/t)]}function Wo(n,t){return t<=n.length?n:n+" ".repeat(t-n.length)}function uf(n,t=o=>0,e,s){return new Promise((o,r)=>{let i=0;const a=()=>{if(n()){o();return}i++;const c=t(i);if(e!=null&&i>=e){r();return}s!=null?s(a,c):setTimeout(a,c)};a()})}function df(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 It(n,t){const e=t.length;return n=n==null?t.map((s,o)=>o):[].concat(n),v(n.every(s=>s>=-e&&s<e),()=>`All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`),v(n.every(s=>Do(s)),()=>`All values in axis param must be integers but got axis ${n}`),n.map(s=>s<0?e+s:s)}function fs(n,t){const e=[],s=[],o=t!=null&&Array.isArray(t)&&t.length===0,r=t==null||o?null:It(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 Se(n,t){return qt(n,t)}function qt(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 tw(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 ew(n){return n==="bool"||n==="complex64"||n==="float32"||n==="int32"||n==="string"}function hf(n,t){return!(t==="complex64"||t==="float32"&&n!=="complex64"||t==="int32"&&n!=="float32"&&n!=="complex64"||t==="bool"&&n==="bool")}function xa(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 nw(n){if(n==null)return 0;let t=0;return n.forEach(e=>t+=e.length),t}function Cr(n){return typeof n=="string"||n instanceof String}function sw(n){return typeof n=="boolean"}function Yl(n){return typeof n=="number"}function Mo(n){return Array.isArray(n)?Mo(n[0]):n instanceof Float32Array?"float32":n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray?"int32":Yl(n)?"float32":Cr(n)?"string":sw(n)?"bool":"float32"}function Ql(n){return!!(n&&n.constructor&&n.call&&n.apply)}function Jl(n,t){for(let e=t;e<n;++e)if(n%e===0)return e;return n}function ct(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 pf(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((c,l)=>c*l)*(s?2:1);for(let c=0;c<r;c++)o[c]=pf(n+c*a,i,e,s)}return o}function vn(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 pf(0,n,t,e)}function ow(n,t){if(Array.isArray(n))return n;if(t==="float32")return n instanceof Float32Array?n:new Float32Array(n);if(t==="int32")return n instanceof Int32Array?n:new Int32Array(n);if(t==="bool"||t==="string")return Uint8Array.from(new Int32Array(n));throw new Error(`Unknown dtype ${t}`)}function jl(n,t){const e=ke(n,t);for(let s=0;s<e.length;s++)e[s]=1;return e}function ke(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 ff(n,t){const e=n.reduce((s,o)=>s*o,1);if(t==null||t==="float32")return vn(n,new Float32Array(e));if(t==="int32")return vn(n,new Int32Array(e));if(t==="bool")return vn(n,new Uint8Array(e));throw new Error(`Unknown data type ${t}`)}function es(n){n.forEach(t=>{v(Number.isInteger(t)&&t>=0,()=>`Tensor must have a shape comprised of positive integers but got shape [${n}].`)})}function Fn(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 Vo(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 ql(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 mf="tfjsflags";class rw{constructor(t){this.global=t,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=iw,this.populateURLFlags()}setPlatform(t,e){this.platform!=null&&(z().getBool("IS_TEST")||z().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];z().getBool("IS_TEST")||z().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(ql(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)}getString(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);mf in t&&t[mf].split(",").forEach(s=>{const[o,r]=s.split(":");this.urlFlags[o]=cw(o,r)})}}function iw(n){const t={};return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(e,...s)=>(aw(t,s[0],s[1]),s.join("="))),t}function aw(n,t,e){n[decodeURIComponent(t)]=decodeURIComponent(e||"")}function cw(n,t){const e=t.toLowerCase();return e==="true"||e==="false"?e==="true":`${+e}`===e?+e:t}function z(){return gf}let gf=null;function lw(n){gf=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 tu;function bf(){if(tu==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");tu=n}return tu}function uw(){const n=bf();return n._tfGlobals==null&&(n._tfGlobals=new Map),n._tfGlobals}function eu(n,t){const e=uw();if(e.has(n))return e.get(n);{const s=t();return e.set(n,s),e.get(n)}}const ya="Abs",vr="Acos",Sr="Acosh",Fo="Add",nu="AddN",su="All",ou="Any",Ia="ArgMax",wa="ArgMin",kr="Asin",Tr="Asinh",Nr="Atan",Rr="Atanh",$r="Atan2",Ca="AvgPool",ru="AvgPoolGrad",va="AvgPool3D",iu="AvgPool3DGrad",Sa="BatchMatMul",ka="BatchToSpaceND",au="Bincount",cu="BitwiseAnd",dw="BroadcastTo",xf="BroadcastArgs",Gr="Cast",Lr="Ceil",Er="ClipByValue",lu="Complex",Ta="ComplexAbs",Na="Concat",Ra="Conv2D",uu="Conv2DBackpropFilter",$a="Conv2DBackpropInput",Ga="Conv3D",du="Conv3DBackpropFilterV2",hu="Conv3DBackpropInputV2",Dr="Cos",Wr="Cosh",pu="Cumprod",La="Cumsum",fu="CropAndResize",mu="DenseBincount",gu="DepthToSpace",Ea="DepthwiseConv2dNative",bu="DepthwiseConv2dNativeBackpropFilter",xu="DepthwiseConv2dNativeBackpropInput",yf="Diag",Da="Dilation2D",yu="Dilation2DBackpropInput",Iu="Dilation2DBackpropFilter",hw="Draw",Mr="RealDiv",wu="Einsum",Vr="Elu",Cu="EluGrad",Fr="Erf",Wa="Equal",zr="Exp",Ma="ExpandDims",Xr="Expm1",vu="FFT",Su="Fill",ku="FlipLeftRight",Ar="Floor",Pr="FloorDiv",Va="FusedBatchNorm",Fa="GatherV2",If="GatherNd",za="Greater",Or="GreaterEqual",Kr="Identity",Tu="IFFT",Nu="Imag",Zr="IsFinite",Br="IsInf",Hr="IsNan",Xa="LeakyRelu",Aa="Less",Pa="LessEqual",wf="LinSpace",_r="Log",Ur="Log1p",Oa="LogicalAnd",Ka="LogicalNot",Za="LogicalOr",pw="LogSoftmax",Ba="LRN",Ru="LRNGrad",Ha="Max",Yr="Maximum",_a="MaxPool",$u="MaxPoolGrad",Ua="MaxPool3D",Gu="MaxPool3DGrad",Cf="MaxPoolWithArgmax",Ya="Mean",Qa="Min",Qr="Minimum",Ja="MirrorPad",Jr="Mod",vf="Multinomial",jr="Multiply",ja="Neg",qa="NotEqual",Lu="NonMaxSuppressionV3",Eu="NonMaxSuppressionV4",Du="NonMaxSuppressionV5",tc="OnesLike",ec="OneHot",nc="Pack",sc="PadV2",qr="Pow",oc="Prelu",rc="Prod",Sf="RaggedGather",kf="RaggedRange",Tf="RaggedTensorToTensor",Wu="Range",Mu="Real",ti="Reciprocal",ei="Relu",ic="Reshape",ac="ResizeNearestNeighbor",Vu="ResizeNearestNeighborGrad",cc="ResizeBilinear",Fu="ResizeBilinearGrad",ni="Relu6",lc="Reverse",si="Round",oi="Rsqrt",Nf="ScatterNd",Rf="TensorScatterUpdate",$f="SearchSorted",uc="Select",ri="Selu",dc="Slice",ii="Sin",ai="Sinh",ci="Sign",li="Sigmoid",ui="Softplus",di="Sqrt",hc="Sum",pc="SpaceToBatchND",fc="SplitV",mc="Softmax",Gf="SparseFillEmptyRows",Lf="SparseReshape",Ef="SparseSegmentMean",Df="SparseSegmentSum",Wf="SparseToDense",hi="SquaredDifference",zu="Square",Xu="StaticRegexReplace",Au="StridedSlice",Mf="StringNGrams",Vf="StringSplit",Ff="StringToHashBucketFast",pi="Sub",fi="Tan",mi="Tanh",gi="Tile",Pu="TopK",Ou="Transform",zo="Transpose",Ku="Unique",gc="Unpack",bc="UnsortedSegmentSum",xc="ZerosLike",bi="Step",Zu="FromPixels",Bu="RotateWithOffset",yc="_FusedMatMul",Ic="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 je(...n){z().getBool("IS_TEST")||z().getBool("PROD")||console.warn(...n)}function fw(...n){z().getBool("IS_TEST")||z().getBool("PROD")||console.log(...n)}/** * @license * Copyright 2019 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */const wc=eu("kernelRegistry",()=>new Map),Hu=eu("gradRegistry",()=>new Map);function _u(n,t){const e=Pf(n,t);return wc.get(e)}function Xf(n){return Hu.get(n)}function Af(n){const t=wc.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 qe(n){const{kernelName:t,backendName:e}=n,s=Pf(t,e);wc.has(s)&&je(`The kernel '${t}' for backend '${e}' is already registered`),wc.set(s,n)}function mw(n){const{kernelName:t}=n;Hu.has(t)&&z().getBool("DEBUG")&&je(`Overriding the gradient for '${t}'`),Hu.set(t,n)}function Pf(n,t){return`${t}_${n}`}/** * @license * Copyright 2023 Google LLC. * 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 Of(n){return n instanceof Float32Array||n instanceof Int32Array||n instanceof Uint8Array||n instanceof Uint8ClampedArray}var Zs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function gw(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}function bw(n){if(n.__esModule)return n;var t=n.default;if(typeof t=="function"){var e=function s(){return this instanceof s?Reflect.construct(t,arguments,this.constructor):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 Kf=Kt,ln=null;try{ln=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 Kt(n,t,e){this.low=n|0,this.high=t|0,this.unsigned=!!e}Kt.prototype.__isLong__,Object.defineProperty(Kt.prototype,"__isLong__",{value:!0});function Be(n){return(n&&n.__isLong__)===!0}Kt.isLong=Be;var Zf={},Bf={};function Bs(n,t){var e,s,o;return t?(n>>>=0,(o=0<=n&&n<256)&&(s=Bf[n],s)?s:(e=Zt(n,(n|0)<0?-1:0,!0),o&&(Bf[n]=e),e)):(n|=0,(o=-128<=n&&n<128)&&(s=Zf[n],s)?s:(e=Zt(n,n<0?-1:0,!1),o&&(Zf[n]=e),e))}Kt.fromInt=Bs;function un(n,t){if(isNaN(n))return t?Hs:dn;if(t){if(n<0)return Hs;if(n>=_f)return jf}else{if(n<=-Uf)return He;if(n+1>=Uf)return Jf}return n<0?un(-n,t).neg():Zt(n%Xo|0,n/Xo|0,t)}Kt.fromNumber=un;function Zt(n,t,e){return new Kt(n,t,e)}Kt.fromBits=Zt;var Cc=Math.pow;function Uu(n,t,e){if(n.length===0)throw Error("empty string");if(n==="NaN"||n==="Infinity"||n==="+Infinity"||n==="-Infinity")return dn;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 Uu(n.substring(1),t,e).neg();for(var o=un(Cc(e,8)),r=dn,i=0;i<n.length;i+=8){var a=Math.min(8,n.length-i),c=parseInt(n.substring(i,i+a),e);if(a<8){var l=un(Cc(e,a));r=r.mul(l).add(un(c))}else r=r.mul(o),r=r.add(un(c))}return r.unsigned=t,r}Kt.fromString=Uu;function Sn(n,t){return typeof n=="number"?un(n,t):typeof n=="string"?Uu(n,t):Zt(n.low,n.high,typeof t=="boolean"?t:n.unsigned)}Kt.fromValue=Sn;var Hf=65536,xw=1<<24,Xo=Hf*Hf,_f=Xo*Xo,Uf=_f/2,Yf=Bs(xw),dn=Bs(0);Kt.ZERO=dn;var Hs=Bs(0,!0);Kt.UZERO=Hs;var Ao=Bs(1);Kt.ONE=Ao;var Qf=Bs(1,!0);Kt.UONE=Qf;var Yu=Bs(-1);Kt.NEG_ONE=Yu;var Jf=Zt(-1,2147483647,!1);Kt.MAX_VALUE=Jf;var jf=Zt(-1,-1,!0);Kt.MAX_UNSIGNED_VALUE=jf;var He=Zt(0,-2147483648,!1);Kt.MIN_VALUE=He;var et=Kt.prototype;et.toInt=function(){return this.unsigned?this.low>>>0:this.low},et.toNumber=function(){return this.unsigned?(this.high>>>0)*Xo+(this.low>>>0):this.high*Xo+(this.low>>>0)},et.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(He)){var e=un(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=un(Cc(t,6),this.unsigned),i=this,a="";;){var c=i.div(r),l=i.sub(c.mul(r)).toInt()>>>0,u=l.toString(t);if(i=c,i.isZero())return u+a;for(;u.length<6;)u="0"+u;a=""+u+a}},et.getHighBits=function(){return this.high},et.getHighBitsUnsigned=function(){return this.high>>>0},et.getLowBits=function(){return this.low},et.getLowBitsUnsigned=function(){return this.low>>>0},et.getNumBitsAbs=function(){if(this.isNegative())return this.eq(He)?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},et.isZero=function(){return this.high===0&&this.low===0},et.eqz=et.isZero,et.isNegative=function(){return!this.unsigned&&this.high<0},et.isPositive=function(){return this.unsigned||this.high>=0},et.isOdd=function(){return(this.low&1)===1},et.isEven=function(){return(this.low&1)===0},et.equals=function(t){return Be(t)||(t=Sn(t)),this.unsigned!==t.unsigned&&this.high>>>31===1&&t.high>>>31===1?!1:this.high===t.high&&this.low===t.low},et.eq=et.equals,et.notEquals=function(t){return!this.eq(t)},et.neq=et.notEquals,et.ne=et.notEquals,et.lessThan=function(t){return this.comp(t)<0},et.lt=et.lessThan,et.lessThanOrEqual=function(t){return this.comp(t)<=0},et.lte=et.lessThanOrEqual,et.le=et.lessThanOrEqual,et.greaterThan=function(t){return this.comp(t)>0},et.gt=et.greaterThan,et.greaterThanOrEqual=function(t){return this.comp(t)>=0},et.gte=et.greaterThanOrEqual,et.ge=et.greaterThanOrEqual,et.compare=function(t){if(Be(t)||(t=Sn(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},et.comp=et.compare,et.negate=function(){return!this.unsigned&&this.eq(He)?He:this.not().add(Ao)},et.neg=et.negate,et.add=function(t){Be(t)||(t=Sn(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,c=t.low>>>16,l=t.low&65535,u=0,d=0,h=0,p=0;return p+=r+l,h+=p>>>16,p&=65535,h+=o+c,d+=h>>>16,h&=65535,d+=s+a,u+=d>>>16,d&=65535,u+=e+i,u&=65535,Zt(h<<16|p,u<<16|d,this.unsigned)},et.subtract=function(t){return Be(t)||(t=Sn(t)),this.add(t.neg())},et.sub=et.subtract,et.multiply=function(t){if(this.isZero())return dn;if(Be(t)||(t=Sn(t)),ln){var e=ln.mul(this.low,this.high,t.low,t.high);return Zt(e,ln.get_high(),this.unsigned)}if(t.isZero())return dn;if(this.eq(He))return t.isOdd()?He:dn;if(t.eq(He))return this.isOdd()?He:dn;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(Yf)&&t.lt(Yf))return un(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,c=t.high&65535,l=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*l,h+=p>>>16,p&=65535,h+=o*u,d+=h>>>16,h&=65535,h+=r*l,d+=h>>>16,h&=65535,h+=i*c,d+=h>>>16,h&=65535,d+=s*u+o*l+r*c+i*a,d&=65535,Zt(p<<16|f,d<<16|h,this.unsigned)},et.mul=et.multiply,et.divide=function(t){if(Be(t)||(t=Sn(t)),t.isZero())throw Error("division by zero");if(ln){if(!this.unsigned&&this.high===-2147483648&&t.low===-1&&t.high===-1)return this;var e=(this.unsigned?ln.div_u:ln.div_s)(this.low,this.high,t.low,t.high);return Zt(e,ln.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Hs:dn;var s,o,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return Hs;if(t.gt(this.shru(1)))return Qf;r=Hs}else{if(this.eq(He)){if(t.eq(Ao)||t.eq(Yu))return He;if(t.eq(He))return Ao;var i=this.shr(1);return s=i.div(t).shl(1),s.eq(dn)?t.isNegative()?Ao:Yu:(o=this.sub(t.mul(s)),r=s.add(o.div(t)),r)}else if(t.eq(He))return this.unsigned?Hs:dn;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=dn}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),c=a<=48?1:Cc(2,a-48),l=un(s),u=l.mul(t);u.isNegative()||u.gt(o);)s-=c,l=un(s,this.unsigned),u=l.mul(t);l.isZero()&&(l=Ao),r=r.add(l),o=o.sub(u)}return r},et.div=et.divide,et.modulo=function(t){if(Be(t)||(t=Sn(t)),ln){var e=(this.unsigned?ln.rem_u:ln.rem_s)(this.low,this.high,t.low,t.high);return Zt(e,ln.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},et.mod=et.modulo,et.rem=et.modulo,et.not=function(){return Zt(~this.low,~this.high,this.unsigned)},et.and=function(t){return Be(t)||(t=Sn(t)),Zt(this.low&t.low,this.high&t.high,this.unsigned)},et.or=function(t){return Be(t)||(t=Sn(t)),Zt(this.low|t.low,this.high|t.high,this.unsigned)},et.xor=function(t){return Be(t)||(t=Sn(t)),Zt(this.low^t.low,this.high^t.high,this.unsigned)},et.shiftLeft=function(t){return Be(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?Zt(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):Zt(0,this.low<<t-32,this.unsigned)},et.shl=et.shiftLeft,et.shiftRight=function(t){return Be(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?Zt(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):Zt(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},et.shr=et.shiftRight,et.shiftRightUnsigned=function(t){if(Be(t)&&(t=t.toInt()),t&=63,t===0)return this;var e=this.high;if(t<32){var s=this.low;return Zt(s>>>t|e<<32-t,e>>>t,this.unsigned)}else return t===32?Zt(e,0,this.unsigned):Zt(e>>>t-32,0,this.unsigned)},et.shru=et.shiftRightUnsigned,et.shr_u=et.shiftRightUnsigned,et.toSigned=function(){return this.unsigned?Zt(this.low,this.high,!1):this},et.toUnsigned=function(){return this.unsigned?this:Zt(this.low,this.high,!0)},et.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},et.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]},et.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]},Kt.fromBytes=function(t,e,s){return s?Kt.fromBytesLE(t,e):Kt.fromBytesBE(t,e)},Kt.fromBytesLE=function(t,e){return new Kt(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)},Kt.fromBytesBE=function(t,e){return new Kt(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)};const qf=gw(Kf),yw=YI({__proto__:null,default:qf},[Kf]);/** * @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 _s=qf||yw;function vc(n){return _s.fromString(n,!0,16)}const tm=vc("c3a5c85c97cb3127"),Us=vc("b492b66fbe98f273"),Re=vc("9ae16a3b2f90404f");function Qu(n){return n.xor(n.shru(47))}function em(n,t,e){const s=n.slice(t,t+e);return _s.fromBytes(Array.from(s),!0,!0)}function Ft(n,t){return em(n,t,8)}function nm(n,t){return em(n,t,4)}function fe(n,t){return t===0?n:n.shru(t).or(n.shl(64-t))}function ms(n,t,e=vc("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 Iw(n,t,e,s,o,r){o=o.add(n),r=fe(r.add(o).add(s),21);const i=o;return o=o.add(t),o=o.add(e),r=r.add(fe(o,44)),[o.add(s),r.add(i)]}function Sc(n,t,e,s){return Iw(Ft(n,t),Ft(n,t+8),Ft(n,t+16),Ft(n,t+24),e,s)}function ww(n,t=n.length){if(t>=8){const e=Re.add(t*2),s=Ft(n,0).add(Re),o=Ft(n,t-8),r=fe(o,37).mul(e).add(s),i=fe(s,25).add(o).mul(e);return ms(r,i,e)}if(t>=4){const e=Re.add(t*2),s=nm(n,0);return ms(s.shl(3).add(t),nm(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 Qu(Re.mul(r).xor(tm.mul(i))).mul(Re)}return Re}function Cw(n,t=n.length){const e=Re.add(t*2),s=Ft(n,0).mul(Us),o=Ft(n,8),r=Ft(n,t-8).mul(e),i=Ft(n,t-16).mul(Re);return ms(fe(s.add(o),43).add(fe(r,30)).add(i),s.add(fe(o.add(Re),18)).add(r),e)}function vw(n,t=n.length){const e=Re.add(t*2),s=Ft(n,0).mul(Re),o=Ft(n,8),r=Ft(n,t-8).mul(e),i=Ft(n,t-16).mul(Re),a=fe(s.add(o),43).add(fe(r,30)).add(i),c=ms(a,s.add(fe(o.add(Re),18)).add(r),e),l=Ft(n,16).mul(e),u=Ft(n,24),d=a.add(Ft(n,t-32)).mul(e),h=c.add(Ft(n,t-24)).mul(e);return ms(fe(l.add(u),43).add(fe(d,30)).add(h),l.add(fe(u.add(s),18)).add(d),e)}function Sw(n,t=n.length){const e=_s.fromNumber(81,!0);if(t<=32)return t<=16?ww(n,t):Cw(n,t);if(t<=64)return vw(n,t);let s=e,o=e.mul(Us).add(113),r=Qu(o.mul(Re).add(113)).mul(Re),i=[_s.UZERO,_s.UZERO],a=[_s.UZERO,_s.UZERO];s=s.mul(Re).add(Ft(n,0));let c=0;const l=(t-1>>6)*64,u=l+(t-1&63)-63;do s=fe(s.add(o).add(i[0]).add(Ft(n,c+8)),37).mul(Us),o=fe(o.add(i[1]).add(Ft(n,c+48)),42).mul(Us),s=s.xor(a[1]),o=o.add(i[0]).add(Ft(n,c+40)),r=fe(r.add(a[0]),33).mul(Us),i=Sc(n,c,i[1].mul(Us),s.add(a[0])),a=Sc(n,c+32,r.add(a[1]),o.add(Ft(n,c+16))),[r,s]=[s,r],c+=64;while(c!==l);const d=Us.add(r.and(255).shl(1));return c=u,a[0]=a[0].add(t-1&63),i[0]=i[0].add(a[0]),a[0]=a[0].add(i[0]),s=fe(s.add(o).add(i[0]).add(Ft(n,c+8)),37).mul(d),o=fe(o.add(i[1]).add(Ft(n,c+48)),42).mul(d),s=s.xor(a[1].mul(9)),o=o.add(i[0].mul(9).add(Ft(n,c+40))),r=fe(r.add(a[0]),33).mul(d),i=Sc(n,c,i[1].mul(d),s.add(a[0])),a=Sc(n,c+32,r.add(a[1]),o.add(Ft(n,c+16))),[r,s]=[s,r],ms(ms(i[0],a[0],d).add(Qu(o).mul(tm)).add(r),ms(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 gs(n,t){return t==="string"?bs(n):Ys([n],t)}function kw(n,t){return n instanceof Float32Array&&t==="float32"||n instanceof Int32Array&&t==="int32"||n instanceof Uint8Array&&t==="bool"}function Ys(n,t){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(n)&&(n=Qs(n)),z().getBool("DEBUG")&&tw(n,t),kw(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 Ve(){return z().platform.now()}function bs(n,t="utf-8"){return t=t||"utf-8",z().platform.encode(n,t)}function xs(n,t="utf-8"){return t=t||"utf-8",z().platform.decode(n,t)}function hn(n){return z().platform.isTypedArray!=null?z().platform.isTypedArray(n):Of(n)}function Qs(n,t=[],e=!1){if(t==null&&(t=[]),typeof n=="boolean"||typeof n=="number"||typeof n=="string"||ql(n)||n==null||hn(n)&&e)t.push(n);else if(Array.isArray(n)||hn(n))for(let s=0;s<n.length;++s)Qs(n[s],t,e);else{let s=-1;for(const o of Object.keys(n))/^([1-9]+[0-9]*|0)$/.test(o)&&(s=Math.max(s,Number(o)));for(let o=0;o<=s;o++)Qs(n[o],t,e)}return 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 Tw{constructor(t,e){this.backendTimer=t,this.logger=e,e==null&&(this.logger=new Rw)}profileKernel(t,e,s){let o;const r=()=>{o=s()};let i;const a=Ve();if(this.backendTimer.timerAvailable())i=this.backendTimer.time(r);else{r();for(const l of o)l.dataSync();i=Promise.resolve({kernelMs:Ve()-a})}if(z().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(let l=0;l<o.length;l++){const u=o[l];u.data().then(d=>{Nw(d,u.dtype,t)})}return{kernelName:t,outputs:o,inputs:e,timeMs:i.then(l=>l.kernelMs),extraInfo:i.then(l=>l.getExtraProfileInfo!=null?l.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(c=>{this.logger.logKernelProfile(e,a,c[0],c[1],r,c[2])})})}}function Nw(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 Rw{logKernelProfile(t,e,s,o,r,i){const a=typeof o=="number"?Wo(`${o}ms`,9):o.error,c=Wo(t,25),l=e.rank,u=e.size,d=Wo(e.shape.toString(),14);let h="";for(const p in r){const f=r[p];if(f!=null){const m=f.shape||e.shape,g=m.length;h+=`${p}: ${g}D ${g>0?m:""} `}}console.log(`%c${c} %c${a} %c${l}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 $w(n,t,e){const s={},o={};for(let c=0;c<t.length;c++)s[t[c].id]=!0;for(let c=0;c<n.length;c++){const l=n[c],u=l.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]){l.outputs.forEach(m=>s[m.id]=!0),p=!0,o[l.id]=!0;break}if(p)break}}const r={};r[e.id]=!0;const i={};for(let c=n.length-1;c>=0;c--){const l=n[c],u=l.inputs;for(let d=0;d<l.outputs.length;d++)if(r[l.outputs[d].id]){for(const h in u)r[u[h].id]=!0,i[l.id]=!0;break}}const a=[];for(let c=0;c<n.length;c++){const l=n[c];if(o[l.id]&&i[l.id]){const u={};for(const h in l.inputs){const p=l.inputs[h];s[p.id]&&(u[h]=p)}const d=Object.assign({},l);d.inputs=u,d.outputs=l.outputs,a.push(d)}}return a}function Gw(n,t,e,s){for(let o=t.length-1;o>=0;o--){const r=t[o],i=[];if(r.outputs.forEach(c=>{const l=n[c.id];l!=null?i.push(l):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 c in r.inputs){if(!(c in a))throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(a)}.`);const l=e(()=>a[c]());if(l.dtype!=="float32")throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`);const u=r.inputs[c];if(!Rt(l.shape,u.shape))throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input '${c}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`);if(n[u.id]==null)n[u.id]=l;else{const d=n[u.id];n[u.id]=s(d,l),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 sm=20,xi=3,Ju=7;function Lw(n,t,e,s){const o=ct(t),r=Ew(n,t,e,o),i=t.length,a=kc(n,t,e,o,r),c=["Tensor"];return s&&(c.push(` dtype: ${e}`),c.push(` rank: ${i}`),c.push(` shape: [${t}]`),c.push(" values:")),c.push(a.map(l=>" "+l).join(` `)),c.join(` `)}function Ew(n,t,e,s){const o=Z(t),r=s[s.length-1],i=new Array(r).fill(0),a=t.length,c=e==="complex64"?Ii(n):n;if(a>1)for(let l=0;l<o/r;l++){const u=l*r;for(let d=0;d<r;d++)i[d]=Math.max(i[d],yi(c[u+d],0,e).length)}return i}function yi(n,t,e){let s;return Array.isArray(n)?s=`${parseFloat(n[0].toFixed(Ju))} + ${parseFloat(n[1].toFixed(Ju))}j`:Cr(n)?s=`'${n}'`:e==="bool"?s=om(n):s=parseFloat(n.toFixed(Ju)).toString(),Wo(s,t)}function om(n){return n===0?"false":"true"}function kc(n,t,e,s,o,r=!0){const i=e==="complex64"?2:1,a=t[0],c=t.length;if(c===0){if(e==="complex64"){const m=Ii(n);return[yi(m[0],0,e)]}return e==="bool"?[om(n[0])]:[n[0].toString()]}if(c===1){if(a>sm){const g=xi*i;let b=Array.from(n.slice(0,g)),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((g,b)=>yi(g,o[b],e)).join(", ")+"]"]}const l=t.slice(1),u=s.slice(1),d=s[0]*i,h=[];if(a>sm){for(let m=0;m<xi;m++){const g=m*d,b=g+d;h.push(...kc(n.slice(g,b),l,e,u,o,!1))}h.push("...");for(let m=a-xi;m<a;m++){const g=m*d,b=g+d;h.push(...kc(n.slice(g,b),l,e,u,o,m===a-1))}}else for(let m=0;m<a;m++){const g=m*d,b=g+d;h.push(...kc(n.slice(g,b),l,e,u,o,m===a-1))}const p=c===2?",":"";h[0]="["+(a>0?h[0]+p:"");for(let m=1;m<h.length-1;m++)h[m]=" "+h[m]+p;let f=`, `;for(let m=2;m<c;m++)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 xe{constructor(t,e,s){if(this.dtype=e,this.shape=t.slice(),this.size=Z(t),s!=null){const o=s.length;v(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||qt(e,this.size),this.strides=ct(t)}set(t,...e){e.length===0&&(e=[0]),v(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,Po=null;function Dw(n){kn=n}function Ww(n){Po=n}class ae{constructor(t,e,s,o){this.kept=!1,this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=Z(t),this.strides=ct(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 Po.buffer(this.shape,this.dtype,t)}bufferSync(){return Po.buffer(this.shape,this.dtype,this.dataSync())}async array(){const t=await this.data();return vn(this.shape,t,this.dtype==="complex64")}arraySync(){return vn(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=>xs(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=>xs(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||(this.kerasMask&&this.kerasMask.dispose(),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 Po.print(this,t)}clone(){return this.throwIfDisposed(),Po.clone(this)}toString(t=!1){const e=this.dataSync();return Lw(e,this.shape,this.dtype,t)}cast(t){return this.throwIfDisposed(),Po.cast(this,t)}variable(t=!0,e,s){return this.throwIfDisposed(),kn().makeVariable(this,t,e,s)}}Object.defineProperty(ae,Symbol.hasInstance,{value:n=>!!n&&n.data!=null&&n.dataSync!=null&&n.throwIfDisposed!=null});function O(){return eu("Tensor",()=>ae)}O();class Tc extends ae{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(!Rt(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(Tc,Symbol.hasInstance,{value:n=>n instanceof ae&&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 rm;(function(n){n.R0="R0",n.R1="R1",n.R2="R2",n.R3="R3",n.R4="R4",n.R5="R5",n.R6="R6"})(rm||(rm={}));var ju;(function(n){n.float32="float32",n.int32="int32",n.bool="int32",n.complex64="complex64"})(ju||(ju={}));var qu;(function(n){n.float32="float32",n.int32="int32",n.bool="bool",n.complex64="complex64"})(qu||(qu={}));var td;(function(n){n.float32="float32",n.int32="float32",n.bool="float32",n.complex64="complex64"})(td||(td={}));var ed;(function(n){n.float32="complex64",n.int32="complex64",n.bool="complex64",n.complex64="complex64"})(ed||(ed={}));const Mw={float32:td,int32:ju,bool:qu,complex64:ed};function _e(n,t){if(n==="string"||t==="string"){if(n==="string"&&t==="string")return"string";throw new Error(`Can not upcast ${n} with ${t}`)}return Mw[n][t]}function nd(n){return _e(n,"int32")}function im(n){return n!=null&&typeof n=="object"&&"texture"in n&&n.texture instanceof WebGLTexture}function am(n){return typeof GPUBuffer<"u"&&n!=null&&typeof n=="object"&&"buffer"in n&&n.buffer instanceof GPUBuffer}/** * @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 te(n,t){if(n.dtype===t.dtype)return[n,t];const e=_e(n.dtype,t.dtype);return[n.cast(e),t.cast(e)]}function cm(n){const t=[];return lm(n,t,new Set),t}function lm(n,t,e){if(n==null)return;if(n instanceof ae){t.push(n);return}if(!Vw(n))return;const s=n;for(const o in s){const r=s[o];e.has(r)||(e.add(r),lm(r,t,e))}}function Vw(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 sd(n){return n.kernelName!=null}class um{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 Oo{constructor(t){this.ENV=t,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new um}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.pendingBac