`;return d[d.length-1]=" "+d[d.length-1]+"]"+(i?"":x),d}function ns(e){const t=[];for(let n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}class br{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=ee(e),n!=null){const r=n.length;f(r===this.size,()=>`Lengthofvalues'${r}'doesnotmatchthesizeinferredbytheshape'${this.size}'.`)}if(t==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||Ep(t,this.size),this.strides=Ut(e)}set(e,...t){t.length===0&&(t=[0]),f(t.length===this.rank,()=>`Thenumberofprovidedcoordinates(${t.length})mustmatchtherank(${this.rank})`);const n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(const r of e){if(r<0||r>=this.shape[t]){const o=`Requestedoutofrangeelementat${e}.Buffershape=${this.shape}`;throw new Error(o)}t++}let n=e[e.length-1];for(let r=0;r<e.length-1;++r)n+=this.strides[r]*e[r];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];const t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return Bt().makeTensor(this.values,this.shape,this.dtype)}}let Bt=null,wr=null,uw=null;function au(e){Bt=e}function cu(e){wr=e}function pu(e){uw=e}class te{constructor(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=ee(e),this.strides=Ut(e),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return wr.buffer(this.shape,this.dtype,e)}bufferSync(){return wr.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return kn(this.shape,e)}arraySync(){return kn(this.shape,this.dataSync())}async data(){this.throwIfDisposed();const e=Bt().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(n=>pa(n))}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return e}dataSync(){this.throwIfDisposed();const e=Bt().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>pa(t))}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();const e=await Bt().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){if(this.isDisposed)return;Bt().disposeTensor(this),this.isDisposedInternal=!0}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return wr.print(this,e)}clone(){return this.throwIfDisposed(),wr.clone(this)}toString(e=!1){const t=this.dataSync();return iu(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),wr.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),Bt().makeVariable(this,e,t,n)}}Object.defineProperty(te,Symbol.hasInstance,{value:e=>!!e&&e.data!=null&&e.dataSync!=null&&e.throwIfDisposed!=null});class $t extends te{constructor(e,t,n,r){super(e.shape,e.dtype,e.dataId,r);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error(`dtypeofthenewvalue(${e.dtype})andpreviousvalue(${this.dtype})mustmatch`);if(!Se(e.shape,this.shape))throw new Error(`shapeofthenewvalue(${e.shape})andpreviousvalue(${this.shape})mustmatch`);Bt().disposeTensor(this),this.dataId=e.dataId,Bt().incRef(this,null)}dispose(){Bt().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty($t,Symbol.hasInstance,{value:e=>e instanceof te&&e.assign!=null&&e.assign instanceof Function});var Wp;(function(e){e.R0="R0",e
ManifestJSONhasweightswithnames:${s.join(", ")}.`)}const c=o.reduce((g,x,w)=>(x&&g.push(w),g),[]),p=[];c.forEach(g=>{t[g].paths.forEach(x=>{const w=n+(n.endsWith("/")?"":"/")+x;p.push(w)})});const l=await e(p),h={};let d=0;return c.forEach(g=>{const x=t[g].paths.length;let w=0;for(let A=0;A<x;A++)w+=l[d+A].byteLength;const L=new ArrayBuffer(w),S=new Uint8Array(L);let I=0;for(let A=0;A<x;A++){const E=new Uint8Array(l[d+A]);S.set(E,I),I+=E.byteLength}const R=i[g];R.forEach(A=>{const E=L.slice(A.groupOffset,A.groupOffset+A.sizeBytes),F=Yp(E,[A.manifestEntry]);for(const M in F)h[M]=F[M]}),d+=x}),h}}const qw="application/octet-stream",zw="application/json";class Xp{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?(f(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=pe().platform.fetch,f(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&f(e.length===2,()=>`URLpathsforhttpmusthavealengthof2,(actuallengthis${e.length}).`),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");const t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;const n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],r={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:n};t.body.append("model.json",new Blob([JSON.stringify(r)],{type:zw}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:qw}),"model.weights.bin");const o=await this.fetch(this.path,t);if(o.ok)return{modelArtifactsInfo:as(e),responses:[o]};throw new Error(`BrowserHTTPRequest.save()failedduetoHTTPresponsestatus${o.status}.`)}async load(){const e=await this.fetch(this.path,this.requestInit);if(!e.ok)throw new Error(`Requestto${this.path}failedwithstatuscode${e.status}.PleaseverifythisURLpointstothemodelJSONofthemodeltoload.`);let t;try{t=await e.json()}catch(l){let h=`FailedtoparsemodelJSONofresponsefrom${this.path}.`;throw this.path.endsWith(".pb")?h+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":h+=" Please make sure the server is serving valid JSON for this request.",new Error(h)}const n=t.modelTopology,r=t.weightsManifest,o=t.generatedBy,i=t.convertedBy,a=t.format,s=t.userDefinedMetadata;if(n==null&&r==null)throw new Error(`TheJSONfromHTTPpath${this.path}containsneithermodeltopologyormanifestforweights.`);let c,p;if(r!=null){const l=await this.loadWeights(r);[c,p]=l}return{modelTopology:n,weightSpecs:c,weightData:p,userDefinedMetadata:s,generatedBy:o,convertedBy:i,format:a}}async loadWeights(e){const t=Array.isArray(this.path)?this.path[1]:this.path,[n,r]=Hw(t),o=this.weightPathPrefix||n,i=[];for(const p of e)i.push(...p.weights);const a=[],s=[];for(const p of e)for(const l of p.paths)this.weightUrlConverter!=null?s.push(this.weightUrlConverter(l)):a.push(o+l+r);this.weightUrlConverter&&a.push(...await Promise.all(s));const c=await Jp(a,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[i,ss(c)]}}Xp.URL_SCHEME_REGEX=/^https?:\/\//;function Hw(e){const t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),r=e.
Actual:${o}.
Expected:${i}.`);for(let a=0;a<i.length;++a){const s=o[a],c=i[a];if(!n(s,c))throw new Error(`Arraysdiffer:actual[${a}]=${s},expected[${a}]=${c}.
Actual:${o}.
Expected:${i}.`)}}function lx(e,t){e().then(()=>t.fail(),()=>t())}function hx(e,t){const n=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return Tt(e)||Tt(e[0])||Tt(t)||Tt(t[0])?cl(e,n,(r,o)=>r==o):cl(e,t,(r,o)=>pl(r,o,0))}function ux(e,t,n){if(n==null&&(n=al()),!pl(e,t,n))throw new Error(`Numbersdiffer:actual===${e},expected===${t}`)}function pl(e,t,n){return!isFinite(e)&&!isFinite(t)?!0:!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}function dx(e,t,n){for(let r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw new Error(`Valueoutofrange:${e[r]}low:${t},high:${n}`)}function mx(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}const xc="2.4.0";function fx(){pe().set("PROD",!0)}function gx(){pe().set("DEBUG",!0)}function bx(){pe().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function ye(e){pe().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}pu(ye);function wx(){b.disposeVariables()}function xx(){return b}function yx(){return b.memory()}function Lx(e){return b.profile(e)}function O(e,t){return b.tidy(e,t)}function Le(e){const t=rs(e);t.forEach(n=>n.dispose())}function ll(e){return b.keep(e)}function vx(e){return b.time(e)}function Sx(e){return b.setBackend(e)}function Ix(){return b.ready()}function wc(){return b.backendName}function Tx(e){b.removeBackend(e)}function Ax(e){return b.findBackend(e)}function Nx(e){return b.findBackendFactory(e)}function Rx(e,t,n=1){return b.registerBackend(e,t,n)}function _x(){return b.backend}function Cx(e,t){pe().setPlatform(e,t)}function Ex(e,t){let n=u(e,"a","add"),r=u(t,"b","add");[n,r]=Y(n,r);const o=(a,s)=>{const c=a.add(n,r);return s([n,r]),c},i={a:n,b:r};return b.runKernelFunc(o,i,null,Cn)}const N=m({add_:Ex});function Ox(e,t){let n=u(e,"a","floorDiv"),r=u(t,"b","floorDiv");[n,r]=Y(n,r);const o=(a,s)=>{const c=a.floorDiv(n,r);return s([n,r]),c},i={a:n,b:r};return b.runKernelFunc(o,i,null,zo)}const fa=m({floorDiv_:Ox});function kx(e,t){let n=u(e,"a","div"),r=u(t,"b","div");if([n,r]=Y(n,r),n.dtype==="int32"&&r.dtype==="int32")return fa(n,r);const o=(s,c)=>{const p=s.realDivide(n,r);return c([n,r]),p},i={a:n,b:r},a={};return b.runKernelFunc(o,i,null,Bo,a)}const D=m({div_:kx});function Dx(e,t){let n=u(e,"a","mul"),r=u(t,"b","mul");[n,r]=Y(n,r);const o=(a,s)=>{const c=a.multiply(n,r);return s([n,r]),c},i={a:n,b:r};return b.runKernelFunc(o,i,null,li)}const v=m({mul_:Dx});function Fx(e){const t=u(e,"x","abs"),n={x:t};return b.runKernelFunc((r,o)=>(o([t]),t.dtype==="complex64"?r.complexAbs(t):r.abs(t)),n,null,ho)}const Oe=m({abs_:Fx});function Mx(e){const t=u(e,"x","acos"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.acos(t);return o([t]),i},n,null,uo)}const ju=m({acos_:Mx});function Ux(e){const t=u(e,"x","acosh"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.acosh(t);return o([t]),i},n,null,mo)}const Gu=m({acosh_:Ux});function Wx(e){f(Array.isArray(e),()=>"The argument passed to tf.addN() must be a list of tensors"),f(e.length>=1,()=>`Mustpassatleastonetensortotf.addN(),butgot${e.length}`);const t=e.map((i,a)=>u(i,`tensors${a}`,"addN")),n=t[0];t.forEach(i=>{if(i.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(i=>{if(!Se(i.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});const r=(i,a)=>{const s=i.addN(t);return a(t),s},o=t;return b.runKernelFunc(r,o,null,fo)}const Pu=m({addN_:Wx});function hl(e,t){for(let n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function qu(e,t,n){const r=e.length+t.length,o=[];let i=0,a=0;for(let s=0;s<r;s++)n.indexOf(s)===-1?o.push(e[i++]):o.push(t[a++]);return o}function ul(e,t){const n=[],r=e.length;for(let i=0;i<r;i++)t.indexOf(i)===-1&&n.push(e[i]);const o=t.map(i=>e[i]);return[n,o]}function we(e,t){const n=t.map(r=>1);return qu(e,n,t)}function Bx(e,t,n){f(hl(t,n),()=>`${e}supportsonlyinner-mostaxesfornow.Gotaxes${t}andrank-${n}input.`)}func
withdtype${p.dtype}.`)});const r=H(t,n[0].shape)[0],o=gl(n.map(p=>p.shape),r);if(ee(o)===0)return Xe([],o);if(n=n.filter(p=>p.size>0),n.length===1)return n[0];const i=n.map(p=>p.shape);fl(i,r);const a=(p,l)=>{const h=p.concat(n,r);return l(n),h},s=n,c={axis:t};return b.runKernelFunc(a,s,null,Co,c)}const Z=m({concat_:ny});function ry(e){const t=u(e,"x","sigmoid"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.sigmoid(t);return o([i]),i},n,null,Oi)}const ft=m({sigmoid_:ry});function oy(e,t,n){const r=u(e,"x","slice");if(r.rank===0)throw new Error("Slicing scalar is not possible");const[o,i]=ls(r,t,n);rl(r,o,i);const a=(p,l)=>(l([r]),p.slice(r,o,i)),s={x:r},c={begin:t,size:n};return b.runKernelFunc(a,s,null,Ri,c)}const P=m({slice_:oy});function iy(e){const t=u(e,"x","tanh"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.tanh(t);return o([i]),i},n,null,Gi)}const hs=m({tanh_:iy});function sy(e,t,n,r,o,i){const a=u(e,"forgetBias","basicLSTMCell"),s=u(t,"lstmKernel","basicLSTMCell"),c=u(n,"lstmBias","basicLSTMCell"),p=u(r,"data","basicLSTMCell"),l=u(o,"c","basicLSTMCell"),h=u(i,"h","basicLSTMCell"),d=Z([p,h],1),g=V(d,s),x=N(g,c),w=x.shape[0],L=x.shape[1]/4,S=[w,L],I=P(x,[0,0],S),R=P(x,[0,L],S),A=P(x,[0,L*2],S),E=P(x,[0,L*3],S),F=N(v(ft(I),hs(R)),v(l,ft(N(a,A)))),M=v(hs(F),ft(E));return[F,M]}const td=m({basicLSTMCell_:sy});function ay(e,t,n){const r=u(e,"x","batchToSpaceND"),o=t.reduce((c,p)=>c*p);f(r.rank>=1+t.length,()=>`inputrankis${r.rank}butshouldbe>thanblockShape.length${t.length}`),f(n.length===t.length,()=>`crops.lengthis${n.length}butshouldbeequaltoblockShape.length${t.length}`),f(r.shape[0]%o===0,()=>`inputtensorbatchis${r.shape[0]}butisnotdivisiblebytheproductoftheelementsofblockShape${t.join(" * ")}===${o}`);const i=c=>c.batchToSpaceND(r,t,n),a={x:r},s={blockShape:t,crops:n};return b.runKernelFunc(i,a,null,Ao,s)}const Nr=m({batchToSpaceND_:ay});function nd(e){let t;return e.rank===0||e.rank===1?t=y(e,[1,1,1,e.size]):e.rank===2?t=y(e,[1,1,e.shape[0],e.shape[1]]):e.rank===3?t=y(e,[1,e.shape[0],e.shape[1],e.shape[2]]):t=e,t}function cy(e,t,n,r,o,i){i==null&&(i=.001);const a=u(e,"x","batchNorm"),s=u(t,"mean","batchNorm"),c=u(n,"variance","batchNorm");let p;o!=null&&(p=u(o,"scale","batchNorm"));let l;r!=null&&(l=u(r,"offset","batchNorm")),f(s.rank===c.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),f(l==null||s.rank===l.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),f(p==null||s.rank===p.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");const h=nd(a),d=(L,S)=>(S([h,s,c,p]),L.batchNorm(h,ba(s),ba(c),ba(l),ba(p),i)),g={x:h,scale:p,offset:l,mean:s,variance:c},x={varianceEpsilon:i},w=b.runKernelFunc(d,g,null,Ho,x);return y(w,a.shape)}function ba(e){return e==null?null:e.rank===0?y(e,[e.size]):e.rank===1?e:e.rank===2?y(e,[1,1,e.shape[0],e.shape[1]]):e.rank===3?y(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e}const jt=m({batchNorm_:cy});function py(e,t,n,r,o,i){const a=u(e,"x","batchNorm"),s=u(t,"mean","batchNorm"),c=u(n,"variance","batchNorm");let p;o!=null&&(p=u(o,"scale","batchNorm"));let l;return r!=null&&(l=u(r,"offset","batchNorm")),f(a.rank===2,()=>`ErrorinbatchNorm2D:xmustberank2butgotrank${a.rank}.`),f(s.rank===2||s.rank===1,()=>`ErrorinbatchNorm2D:meanmustberank2orrank1butgotrank${s.rank}.`),f(c.rank===2||c.rank===1,()=>`ErrorinbatchNorm2D:variancemustberank2orrank1butgotrank${c.rank}.`),p!=null&&f(p.rank===2||p.rank===1,()=>`ErrorinbatchNorm2D:scalemustberank2orrank1butgotrank${p.rank}.`),l!=null&&f(l.rank===2||l.rank===1,()=>`ErrorinbatchNorm2D:offsetmustberank2orrank1butgotrank${l.rank}.`),jt(a,s,c,l,p,i)}const rd=m({batchNorm2d_:py});function ly(e,t,n,r,o,i){const a=u(e,"x","batchNorm"),s=u(t,"mean","batchNorm"),c=u(n,"variance","batchNorm");let p;o!=null&&(p=u(o,"scale","batchNorm"));let l;return r!=null&&(l=u(r,"offset","batchNorm")),f(a.rank===3,()=>`ErrorinbatchNorm3D:xmust
rank${i.rank}.`),f(X(t),()=>`ErrorinlocalResponseNormalization:depthRadiusmustbeanintegerbutgotdepthRadius${t}.`);let a=i,s=!1;i.rank===3&&(s=!0,a=y(i,[1,i.shape[0],i.shape[1],i.shape[2]]));const c=(d,g)=>{const x=d.localResponseNormalization4D(a,t,n,r,o);return g([a,x]),x},p={x:a},l={depthRadius:t,bias:n,alpha:r,beta:o},h=b.runKernelFunc(c,p,null,ni,l);return s?y(h,[h.shape[1],h.shape[2],h.shape[3]]):h}const Rd=m({localResponseNormalization_:aL});function cL(e){const t=u(e,"x","log"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.log(t);return o([t]),i},n,null,Qo)}const Rt=m({log_:cL});function pL(e){const t=u(e,"x","log1p"),n={x:t};return b.runKernelFunc((r,o)=>{const i=r.log1p(t);return o([t]),i},n,null,ei)}const Ia=m({log1p_:pL});function lL(e){return f(Mt(e),()=>"The f passed in grad(f) must be a function"),(t,n)=>{const r=u(t,"x","tf.grad",null),o=n!=null?u(n,"dy","tf.grad"):null;return b.tidy(()=>{const{value:i,grads:a}=b.gradients(()=>e(r),[r],o);return o!=null&&G(i.shape,o.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Ta(a),a[0]})}}function hL(e){return f(Mt(e),()=>"The f passed in grads(f) must be a function"),(t,n)=>{f(Array.isArray(t),()=>"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");const r=Jt(t,"args","tf.grads",null),o=n!=null?u(n,"dy","tf.grads"):null;return b.tidy(()=>{const{value:i,grads:a}=b.gradients(()=>e(...r),r,o);return o!=null&&G(i.shape,o.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ta(a),a})}}function uL(e){return f(Mt(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,n)=>{f(t instanceof te,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),f(n==null||n instanceof te,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");const{grads:r,value:o}=b.gradients(()=>e(t),[t],n);return Ta(r),{grad:r[0],value:o}}}function dL(e){return f(Mt(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,n)=>{f(Array.isArray(t)&&t.every(o=>o instanceof te),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),f(n==null||n instanceof te,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");const r=b.gradients(()=>e(...t),t,n);return n!=null&&G(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Ta(r.grads),r}}function wl(e,t){f(Mt(e),()=>"The f passed in variableGrads(f) must be a function"),f(t==null||Array.isArray(t)&&t.every(p=>p instanceof $t),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");const n=t!=null;if(!n){t=[];for(const p in b.registeredVariables)t.push(b.registeredVariables[p])}const r=n?t.filter(p=>!p.trainable):null,o=t.length;t=t.filter(p=>p.trainable),f(t.length>0,()=>`variableGrads()expectsatleastoneoftheinputvariablestobetrainable,butnoneofthe${o}variablesistrainable.`);const i=!0,{value:a,grads:s}=b.gradients(e,t,null,i);f(s.some(p=>p!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),f(a.rank===0,()=>`ThefpassedinvariableGrads(f)mustreturnascalar,butitreturnedarank-${a.rank}tensor`);const c={};return t.forEach((p,l)=>{s[l]!=null&&(c[p.name]=s[l])}),r!=null&&r.forEach(p=>c[p.name]=null),{value:a,grads:c}}function ze(e){return b.customGrad(e)}function Ta(e){const t=e.filter(n=>n==null).length;if(t>0)throw new Error(`Cannotcomputegradientofy=f(x)withrespecttox.Makesurethat