adMany(t){return t.map(t=>this.read(t))}write(t,r){if(this.closed_)throw Error(`TensorArray ${this.name} has already been closed.`);if(t<0||!this.dynamicSize&&t>=this.maxSize)throw Error(`Tried to write to index ${t}, but array is not resizeable and size is: ${this.maxSize}`);let a=this.tensors[t]||{};if(r.dtype!==this.dtype)throw Error(`TensorArray ${this.name}: Could not write to TensorArray index ${t},
          because the value dtype is ${r.dtype}, but TensorArray dtype is ${this.dtype}.`);if(0===this.size()&&(null==this.elementShape||0===this.elementShape.length)&&(this.elementShape=r.shape),assertShapesMatchAllowUndefinedSize(this.elementShape,r.shape,`TensorArray ${this.name}: Could not write to TensorArray index ${t}.`),a.read)throw Error(`TensorArray ${this.name}: Could not write to TensorArray index ${t}, because it has already been read.`);if(a.written)throw Error(`TensorArray ${this.name}: Could not write to TensorArray index ${t}, because it has already been written.`);a.tensor=r,keep(r),a.written=!0,this.tensors[t]=a}writeMany(t,r){if(t.length!==r.length)throw Error(`TensorArray ${this.name}: could not write multiple tensors,because the index size: ${t.length} is not the same as tensors size: ${r.length}.`);t.forEach((t,a)=>this.write(t,r[a]))}gather(t,r){if(r&&r!==this.dtype)throw Error(`TensorArray dtype is ${this.dtype} but gather requested dtype ${r}`);if(t)t=t.slice(0,this.size());else{t=[];for(let r=0;r<this.size();r++)t.push(r)}if(0===t.length)return tensor([],[0].concat(this.elementShape));let a=this.readMany(t);return assertShapesMatchAllowUndefinedSize(this.elementShape,a[0].shape,"TensorArray shape mismatch: "),ig(a,0)}concat(t){if(t&&t!==this.dtype)throw Error(`TensorArray dtype is ${this.dtype} but concat requested dtype ${t}`);if(0===this.size())return tensor([],[0].concat(this.elementShape));let r=[];for(let t=0;t<this.size();t++)r.push(t);let a=this.readMany(r);return assertShapesMatchAllowUndefinedSize(this.elementShape,a[0].shape,`TensorArray shape mismatch: tensor array shape (${this.elementShape}) vs first tensor shape (${a[0].shape})`),a7(a,0)}scatter(t,r){if(r.dtype!==this.dtype)throw Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${r.dtype}`);if(t.length!==r.shape[0])throw Error(`Expected len(indices) == tensor.shape[0], but saw: ${t.length} vs. ${r.shape[0]}`);let a=Math.max(...t);if(!this.dynamicSize&&a>=this.maxSize)throw Error(`Max index must be < array size (${a}  vs. ${this.maxSize})`);this.writeMany(t,iw(r,0))}split(t,r){if(r.dtype!==this.dtype)throw Error(`TensorArray dtype is ${this.dtype} but tensor has dtype ${r.dtype}`);let a=0,n=t.map(t=>a+=t);if(a!==r.shape[0])throw Error(`Expected sum of lengths to be equal to
          tensor.shape[0], but sum of lengths is
        ${a}, and tensor's shape is: ${r.shape}`);if(!this.dynamicSize&&t.length!==this.maxSize)throw Error(`TensorArray's size is not equal to the size of lengths (${this.maxSize} vs. ${t.length}), and the TensorArray is not marked as dynamically resizeable`);let s=0===a?0:r.size/a,i=[];globals_tidy(()=>{r=a6(r,[1,a,s]);for(let a=0;a<t.length;++a){let o=[0,0===a?0:n[a-1],0],l=[1,t[a],s];i[a]=a6(nt(r,o,l),this.elementShape)}return i});let o=[];for(let r=0;r<t.length;r++)o[r]=r;this.writeMany(o,i)}};let TensorList=class TensorList{get id(){return this.idTensor.id}constructor(t,r,a,n=-1){this.tensors=t,this.elementShape=r,this.elementDtype=a,null!=t&&t.forEach(t=>{if(a!==t.dtype)throw Error(`Invalid data types; op elements ${a}, but list elements ${t.dtype}`);assertShapesMatchAllowUndefinedSize(r,t.shape,"TensorList shape mismatch: "),keep(t)}),this.idTensor=scalar_scalar(0),this.maxNumElements=n,keep(this.idTensor)}copy(){return new TensorList([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(t){this.tensors.forEach(r=>{null!=t&&t.has(r.id)||r.dispose()}),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(t,r,a=-1){if(r!==this.elementDtype)throw Error(`Invalid data types; op elements ${r}, but list elements ${this.elementDtype}`);if(-1!==a&&this.tensors.length!==a)throw Error(`Operation expected a list with ${a} elements but got a list with ${this.tensors.length} elements.`);assertShapesMatchAllowUndefinedSize(t,this.elementShape,"TensorList shape mismatch: ");let n=inferElementShape(this.elementShape,this.tensors,t);return globals_tidy(()=>ig(this.tensors.map(t=>a6(t,n)),0))}popBack(t,r){if(r!==this.elementDtype)throw Error(`Invalid data types; op elements ${r}, but list elements ${this.elementDtype}`);if(0===this.size())throw Error("Trying to pop from an empty list.");let a=inferElementShape(this.elementShape,this.tensors,t),n=this.tensors.pop();return n.kept=!1,assertShapesMatchAllowUndefinedSize(n.shape,t,"TensorList shape mismatch: "),a6(n,a)}pushBack(t){if(t.dtype!==this.elementDtype)throw Error(`Invalid data types; op elements ${t.dtype}, but list elements ${this.elementDtype}`);if(assertShapesMatchAllowUndefinedSize(t.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw Error("Trying to push element into a full list.");keep(t),this.tensors.push(t)}resize(t){if(t<0)throw Error(`TensorListResize expects size to be non-negative. Got: ${t}`);if(-1!==this.maxNumElements&&t>this.maxNumElements)throw Error(`TensorListResize input size ${t} is greater maxNumElement ${this.maxNumElements}.`);let r=new TensorList([],this.elementShape,this.elementDtype,this.maxNumElements);r.tensors.length=t;for(let a=0;a<Math.min(this.tensors.length,t);++a)r.tensors[a]=this.tensors[a];return r}getItem(t,r,a){if(a!==this.elementDtype)throw Error(`Invalid data types; op elements ${a}, but list elements ${this.elementDtype}`);if(t<0||t>this.tensors.length)throw Error(`Trying to access element ${t} in a list with ${this.tensors.length} elements.`);if(null==this.tensors[t])throw Error(`element at index ${t} is null.`);assertShapesMatchAllowUndefinedSize(this.tensors[t].shape,r,"TensorList shape mismatch: ");let n=inferElementShape(this.elementShape,this.tensors,r);return a6(this.tensors[t],n)}setItem(t,r){if(r.dtype!==this.elementDtype)throw Error(`Invalid data types; op elements ${r.dtype}, but list elements ${this.elementDtype}`);if(t<0||-1!==this.maxNumElements&&t>=this.maxNumElements)throw Error(`Trying to set element ${t} in a list with max ${this.maxNumElements} elements.`);assertShapesMatchAllowUndefinedSize(this.elementShape,r.shape,"TensorList shape mismatch: "),keep(r),null!=this.tensors[t]&&(this.tensors[t].kept=!1),this.tensors[t]=r}gather(t,r,a){if(r!==this.elementDtype)throw Error(`Invalid data types; op elements ${r}, but list elements ${this.elementDtype}`);assertShapesMatchAllowUndefinedSize(this.elementShape,a,"TensorList shape mismatch: "),t=t.slice(0,this.size());let n=inferElementShape(this.elementShape,this.tensors,a);return 0===t.length?tensor([],[0].concat(n)):globals_tidy(()=>ig(t.map(t=>a6(this.tensors[t],n)),0))}concat(t,r){if(t&&t!==this.elementDtype)throw Error(`TensorList dtype is ${this.elementDtype} but concat requested dtype ${t}`);assertShapesMatchAllowUndefinedSize(this.elementShape,r,"TensorList shape mismatch: ");let a=inferElementShape(this.elementShape,this.tensors,r);return 0===this.size()?tensor([],[0].concat(a)):globals_tidy(()=>a7(this.tensors.map(t=>a6(t,a)),0))}};function fromTensor(t,r,a){let n=t.dtype;if(t.shape.length<1)throw Error(`Tensor must be at least a vector, but saw shape: ${t.shape}`);if(t.dtype!==a)throw Error(`Invalid data types; op elements ${t.dtype}, but list elements ${a}`);return assertShapesMatchAllowUndefinedSize(t.shape.slice(1),r,"TensorList shape mismatch: "),new TensorList(iw(t),r,n)}function reserve(t,r,a,n){return new TensorList([],t,r,n)}function scatter(t,r,a,n){if(r.length!==t.shape[0])throw Error(`Expected len(indices) == tensor.shape[0], but saw: ${r.length} vs. ${t.shape[0]}`);let s=Math.max(...r);if(null!=n&&-1!==n&&s>=n)throw Error(`Max index must be < array size (${s}  vs. ${n})`);let i=new TensorList([],a,t.dtype,n),o=iw(t,0);return r.forEach((t,r)=>{i.setItem(t,o[r])}),i}function tensor_list_split(t,r,a){let n=0,s=r.map(t=>n+=t);if(n!==t.shape[0])throw Error(`Expected sum of lengths to be equal to
          tensor.shape[0], but sum of lengths is
        ${n}, and tensor's shape is: ${t.shape}`);let i=mergeElementShape(t.shape.slice(1),a),o=0===n?0:t.size/n,l=globals_tidy(()=>{let a=[];t=a6(t,[1,n,o]);for(let n=0;n<r.length;++n){let l=[0,0===n?0:s[n-1],0],u=[1,r[n],o];a[n]=a6(nt(t,l,u),i)}return t.dispose(),a}),u=new TensorList([],a,t.dtype,r.length);for(let t=0;t<l.length;t++)u.setItem(t,l[t]);return u}let control_executor_executeOp=async(t,r,a)=>{switch(t.op){case"If":case"StatelessIf":{let n=getParamValue("thenBranch",t,r,a),s=getParamValue("elseBranch",t,r,a),i=getParamValue("cond",t,r,a),o=getParamValue("args",t,r,a);if((await i.data())[0])return a.functionMap[n].executeFunctionAsync(o,a.tensorArrayMap,a.tensorListMap);return a.functionMap[s].executeFunctionAsync(o,a.tensorArrayMap,a.tensorListMap)}case"While":case"StatelessWhile":{let n=getParamValue("body",t,r,a),s=getParamValue("cond",t,r,a),i=getParamValue("args",t,r,a),o=await a.functionMap[s].executeFunctionAsync(i,a.tensorArrayMap,a.tensorListMap),l=i.map(t=>t.id),u=await o[0].data();o.forEach(t=>{t.kept||-1!==l.indexOf(t.id)||t.dispose()});let p=i;for(;u[0];){let t=p,r=(p=await a.functionMap[n].executeFunctionAsync(p,a.tensorArrayMap,a.tensorListMap)).map(t=>t.id);t.forEach(t=>{t.kept||-1!==l.indexOf(t.id)||-1!==r.indexOf(t.id)||t.dispose()});let i=await a.functionMap[s].executeFunctionAsync(p,a.tensorArrayMap,a.tensorListMap);u=await i[0].data(),i.forEach(t=>{t.kept||-1!==l.indexOf(t.id)||-1!==r.indexOf(t.id)||t.dispose()})}return p}case"LoopCond":return[cloneTensor(getParamValue("pred",t,r,a))];case"Switch":{let n=getParamValue("pred",t,r,a),s=getParamValue("data",t,r,a);return s.kept||(s=cloneTensor(s)),(await n.data())[0]?[void 0,s]:[s,void 0]}case"Merge":{let n=t.inputNames.find(t=>void 0!==getTensor(t,r,a));if(n)return[cloneTensor(getTensor(n,r,a))];return}case"Enter":{let n=getParamValue("frameName",t,r,a),s=getParamValue("tensor",t,r,a);return a.enterFrame(n),[cloneTensor(s)]}case"Exit":{let n=getParamValue("tensor",t,r,a);return a.exitFrame(),[cloneTensor(n)]}case"NextIteration":{let n=getParamValue("tensor",t,r,a);return a.nextIteration(),[cloneTensor(n)]}case"TensorArrayV3":{let n=getParamValue("size",t,r,a),s=getParamValue("dtype",t,r,a),i=getParamValue("elementShape",t,r,a),o=getParamValue("dynamicSize",t,r,a),l=getParamValue("clearAfterRead",t,r,a),u=getParamValue("identicalElementShapes",t,r,a),p=new TensorArray(getParamValue("name",t,r,a),s,n,i,u,o,l);return a.addTensorArray(p),[p.idTensor,scalar_scalar(1)]}case"TensorArrayWriteV3":{let n=getParamValue("tensorArrayId",t,r,a),s=getParamValue("index",t,r,a),i=getParamValue("tensor",t,r,a),o=a.getTensorArray(n.id);return o.write(s,i),[o.idTensor]}case"TensorArrayReadV3":{let n=getParamValue("tensorArrayId",t,r,a),s=getParamValue("index",t,r,a);return[a.getTensorArray(n.id).read(s)]}case"TensorArrayGatherV3":{let n=getParamValue("tensorArrayId",t,r,a),s=getParamValue("indices",t,r,a),i=getParamValue("dtype",t,r,a);return[a.getTensorArray(n.id).gather(s,i)]}case"TensorArrayScatterV3":{let n=getParamValue("tensorArrayId",t,r,a),s=getParamValue("indices",t,r,a),i=getParamValue("tensor",t,r,a),o=a.getTensorArray(n.id);return o.scatter(s,i),[o.idTensor]}case"TensorArrayConcatV3":{let n=getParamValue("tensorArrayId",t,r,a),s=a.getTensorArray(n.id),i=getParamValue("dtype",t,r,a);return[s.concat(i)]}case"TensorArraySplitV3":{let n=getParamValue("tensorArrayId",t,r,a),s=getParamValue("tensor",t,r,a),i=getParamValue("lengths",t,r,a),o=a.getTensorArray(n.id);return o.split(i,s),[o.idTensor]}case"TensorArraySizeV3":{let n=getParamValue("tensorArrayId",t,r,a);return[scalar_scalar(a.getTensorArray(n.id).size(),"int32")]}case"TensorArrayCloseV3":{let n=getParamValue("tensorArrayId",t,r,a),s=a.getTensorArray(n.id);return s.clearAndClose(),[s.idTensor]}case"TensorListSetItem":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("index",t,r,a),i=getParamValue("tensor",t,r,a),o=a.getTensorList(n.id);return o.setItem(s,i),[o.idTensor]}case"TensorListGetItem":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("index",t,r,a),i=getParamValue("elementShape",t,r,a),o=getParamValue("elementDType",t,r,a);return[a.getTensorList(n.id).getItem(s,i,o)]}case"TensorListScatterV2":case"TensorListScatter":{let n=getParamValue("indices",t,r,a),s=scatter(getParamValue("tensor",t,r,a),n,getParamValue("elementShape",t,r,a),getParamValue("numElements",t,r,a));return a.addTensorList(s),[s.idTensor]}case"TensorListReserve":case"EmptyTensorList":{let n=getParamValue("elementShape",t,r,a),s=getParamValue("elementDType",t,r,a),i=getParamValue("TensorListReserve"===t.op?"numElements":"maxNumElements",t,r,a),o="TensorListReserve"===t.op?-1:i,l=reserve(n,s,i,o);return a.addTensorList(l),[l.idTensor]}case"TensorListGather":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("indices",t,r,a),i=getParamValue("elementShape",t,r,a),o=getParamValue("elementDType",t,r,a);return[a.getTensorList(n.id).gather(s,o,i)]}case"TensorListStack":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("elementShape",t,r,a),i=getParamValue("elementDType",t,r,a),o=getParamValue("numElements",t,r,a);return[a.getTensorList(n.id).stack(s,i,o)]}case"TensorListFromTensor":{let n=fromTensor(getParamValue("tensor",t,r,a),getParamValue("elementShape",t,r,a),getParamValue("elementDType",t,r,a));return a.addTensorList(n),[n.idTensor]}case"TensorListConcat":case"TensorListConcatV2":{let n=getParamValue("tensorListId",t,r,a),s=a.getTensorList(n.id),i=getParamValue("dtype",t,r,a),o=getParamValue("elementShape",t,r,a);return[s.concat(i,o)]}case"TensorListPushBack":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("tensor",t,r,a),i=a.getTensorList(n.id);return i.pushBack(s),[i.idTensor]}case"TensorListPopBack":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("elementShape",t,r,a),i=getParamValue("elementDType",t,r,a);return[a.getTensorList(n.id).popBack(s,i)]}case"TensorListSplit":{let n=getParamValue("tensor",t,r,a),s=getParamValue("elementShape",t,r,a),i=tensor_list_split(n,getParamValue("lengths",t,r,a),s);return a.addTensorList(i),[i.idTensor]}case"TensorListLength":{let n=getParamValue("tensorListId",t,r,a);return[scalar_scalar(a.getTensorList(n.id).size(),"int32")]}case"TensorListResize":{let n=getParamValue("tensorListId",t,r,a),s=getParamValue("size",t,r,a),i=a.getTensorList(n.id).resize(s);return a.addTensorList(i),[i.idTensor]}default:throw TypeError(`Node type ${t.op} is not implemented`)}};function fusedConvAndDepthWiseParams(t,r,a){let[n,s]=getParamValue("fusedOps",t,r,a),i="biasadd"===n,o="prelu"===s,l=getParamValue("numArgs",t,r,a);if(i){if(o&&2!==l)throw Error("FusedConv2d and DepthwiseConv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&i&&1!==l)throw Error("FusedConv2d and DepthwiseConv2d with BiasAdd must have one extra argument: bias.")}if("fusedbatchnorm"===n)throw Error("FusedConv2d and DepthwiseConv2d with FusedBatchNorm is not supported");let u=getParamValue("strides",t,r,a),p=getPadding(t,r,a),m=getParamValue("dataFormat",t,r,a).toUpperCase(),y=getParamValue("dilations",t,r,a),[_,w]=getParamValue("args",t,r,a);return i||(w=_,_=void 0),{stride:u,pad:p,dataFormat:m,dilations:y,biasArg:_,preluArg:w,activationFunc:s,leakyreluAlpha:getParamValue("leakyreluAlpha",t,r,a)}}function nmsParams(t,r,a){let n=getParamValue("boxes",t,r,a),s=getParamValue("scores",t,r,a),i=getParamValue("maxOutputSize",t,r,a),o=getParamValue("iouThreshold",t,r,a);return{boxes:n,scores:s,maxOutputSize:i,iouThreshold:o,scoreThreshold:getParamValue("scoreThreshold",t,r,a),softNmsSigma:getParamValue("softNmsSigma",t,r,a)}}let dynamic_executor_executeOp=async(t,r,a,n,s=eM)=>{switch(t.op){case"NonMaxSuppressionV5":{let{boxes:n,scores:i,maxOutputSize:o,iouThreshold:l,scoreThreshold:u,softNmsSigma:p}=nmsParams(t,r,a),m=await s.image.nonMaxSuppressionWithScoreAsync(n,i,o,l,u,p);return[m.selectedIndices,m.selectedScores]}case"NonMaxSuppressionV4":{let{boxes:n,scores:i,maxOutputSize:o,iouThreshold:l,scoreThreshold:u}=nmsParams(t,r,a),p=getParamValue("padToMaxOutputSize",t,r,a),m=await s.image.nonMaxSuppressionPaddedAsync(n,i,o,l,u,p);return[m.selectedIndices,m.validOutputs]}case"NonMaxSuppressionV3":case"NonMaxSuppressionV2":{let{boxes:n,scores:i,maxOutputSize:o,iouThreshold:l,scoreThreshold:u}=nmsParams(t,r,a);return[await s.image.nonMaxSuppressionAsync(n,i,o,l,u)]}case"Where":{let n=s.cast(getParamValue("condition",t,r,a),"bool"),i=[await s.whereAsync(n)];return n.dispose(),i}case"ListDiff":return s.setdiff1dAsync(getParamValue("x",t,r,a),getParamValue("y",t,r,a));default:throw TypeError(`Node type ${t.op} is not implemented`)}};let HashTable=class HashTable{get id(){return this.handle.id}constructor(t,r){this.keyDType=t,this.valueDType=r,this.handle=scalar_scalar(0),this.tensorMap=new Map,keep(this.handle)}clearAndClose(){this.tensorMap.forEach(t=>t.dispose()),this.tensorMap.clear(),this.handle.dispose()}size(){return this.tensorMap.size}tensorSize(){return scalar_scalar(this.size(),"int32")}async import(t,r){this.checkKeyAndValueTensor(t,r);let a=await t.data();return this.tensorMap.forEach(t=>t.dispose()),this.tensorMap.clear(),globals_tidy(()=>{let t=iw(r),n=a.length,s=t.length;assert(n===s,()=>`The number of elements doesn't match, keys has ${n} elements, the values has ${s} elements.`);for(let r=0;r<n;r++){let n=a[r],s=t[r];keep(s),this.tensorMap.set(n,s)}return this.handle})}async find(t,r){this.checkKeyAndValueTensor(t,r);let a=await t.data();return globals_tidy(()=>{let t=[];for(let n=0;n<a.length;n++){let s=a[n],i=this.findWithDefault(s,r);t.push(i)}return ig(t)})}findWithDefault(t,r){let a=this.tensorMap.get(t);return null!=a?a:r}checkKeyAndValueTensor(t,r){if(t.dtype!==this.keyDType)throw Error(`Expect key dtype ${this.keyDType}, but got ${t.dtype}`);if(r.dtype!==this.valueDType)throw Error(`Expect value dtype ${this.valueDType}, but got ${r.dtype}`)}};let hash_table_executor_executeOp=async(t,r,a,n)=>{switch(t.op){case"HashTable":case"HashTableV2":{let s=n.getHashTableHandleByName(t.name);if(null!=s)return[s];{let s=new HashTable(getParamValue("keyDType",t,r,a),getParamValue("valueDType",t,r,a));return n.addHashTable(t.name,s),[s.handle]}}case"InitializeTable":case"InitializeTableV2":case"LookupTableImport":case"LookupTableImportV2":{let s=getParamValue("tableHandle",t,r,a,n),i=getParamValue("keys",t,r,a),o=getParamValue("values",t,r,a),l=n.getHashTableById(s.id);return[await l.import(i,o)]}case"LookupTableFind":case"LookupTableFindV2":{let s=getParamValue("tableHandle",t,r,a,n),i=getParamValue("keys",t,r,a),o=getParamValue("defaultValue",t,r,a),l=n.getHashTableById(s.id);return[await l.find(i,o)]}case"LookupTableSize":case"LookupTableSizeV2":{let s=getParamValue("tableHandle",t,r,a,n);return[n.getHashTableById(s.id).tensorSize()]}default:throw TypeError(`Node type ${t.op} is not implemented`)}};function operation_executor_executeOp(t,r,a,n,s=globals_tidy){let i=((t,r,a)=>{switch(t.category){case"arithmetic":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"BiasAdd":case"AddV2":case"Add":return[n.add(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"AddN":return[n.addN(getParamValue("tensors",t,r,a))];case"FloorMod":case"Mod":return[n.mod(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Mul":return[n.mul(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"RealDiv":case"Div":return[n.div(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"DivNoNan":return[n.divNoNan(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"FloorDiv":return[n.floorDiv(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Sub":return[n.sub(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Minimum":return[n.minimum(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Maximum":return[n.maximum(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Pow":return[n.pow(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"SquaredDifference":return[n.squaredDifference(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"basic_math":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Abs":case"ComplexAbs":return[n.abs(getParamValue("x",t,r,a))];case"Acos":return[n.acos(getParamValue("x",t,r,a))];case"Acosh":return[n.acosh(getParamValue("x",t,r,a))];case"Asin":return[n.asin(getParamValue("x",t,r,a))];case"Asinh":return[n.asinh(getParamValue("x",t,r,a))];case"Atan":return[n.atan(getParamValue("x",t,r,a))];case"Atan2":return[n.atan2(getParamValue("x",t,r,a),getParamValue("y",t,r,a))];case"Atanh":return[n.atanh(getParamValue("x",t,r,a))];case"Ceil":return[n.ceil(getParamValue("x",t,r,a))];case"Complex":return[n.complex(getParamValue("real",t,r,a),getParamValue("imag",t,r,a))];case"Cos":return[n.cos(getParamValue("x",t,r,a))];case"Cosh":return[n.cosh(getParamValue("x",t,r,a))];case"Elu":return[n.elu(getParamValue("x",t,r,a))];case"Erf":return[n.erf(getParamValue("x",t,r,a))];case"Exp":return[n.exp(getParamValue("x",t,r,a))];case"Expm1":return[n.expm1(getParamValue("x",t,r,a))];case"Floor":return[n.floor(getParamValue("x",t,r,a))];case"Log":return[n.log(getParamValue("x",t,r,a))];case"Log1p":return[n.log1p(getParamValue("x",t,r,a))];case"Imag":return[n.imag(getParamValue("x",t,r,a))];case"Neg":return[n.neg(getParamValue("x",t,r,a))];case"Reciprocal":return[n.reciprocal(getParamValue("x",t,r,a))];case"Real":return[n.real(getParamValue("x",t,r,a))];case"Relu":return[n.relu(getParamValue("x",t,r,a))];case"Round":return[n.round(getParamValue("x",t,r,a))];case"Selu":return[n.selu(getParamValue("x",t,r,a))];case"Sigmoid":return[n.sigmoid(getParamValue("x",t,r,a))];case"Sin":return[n.sin(getParamValue("x",t,r,a))];case"Sign":return[n.sign(getParamValue("x",t,r,a))];case"Sinh":return[n.sinh(getParamValue("x",t,r,a))];case"Softplus":return[n.softplus(getParamValue("x",t,r,a))];case"Sqrt":return[n.sqrt(getParamValue("x",t,r,a))];case"Square":return[n.square(getParamValue("x",t,r,a))];case"Tanh":return[n.tanh(getParamValue("x",t,r,a))];case"Tan":return[n.tan(getParamValue("x",t,r,a))];case"ClipByValue":return[n.clipByValue(getParamValue("x",t,r,a),getParamValue("clipValueMin",t,r,a),getParamValue("clipValueMax",t,r,a))];case"Relu6":return[n.relu6(getParamValue("x",t,r,a))];case"Rsqrt":return[n.rsqrt(getTensor(t.inputNames[0],r,a))];case"LeakyRelu":return[n.leakyRelu(getParamValue("x",t,r,a),getParamValue("alpha",t,r,a))];case"Prelu":return[n.prelu(getParamValue("x",t,r,a),getParamValue("alpha",t,r,a))];case"IsNan":return[n.isNaN(getTensor(t.inputNames[0],r,a))];case"IsInf":return[n.isInf(getTensor(t.inputNames[0],r,a))];case"IsFinite":return[n.isFinite(getTensor(t.inputNames[0],r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"control":return control_executor_executeOp(t,r,a);case"convolution":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Conv1D":{let s=getParamValue("stride",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("dataFormat",t,r,a).toUpperCase(),l=getParamValue("dilation",t,r,a);return[n.conv1d(getParamValue("x",t,r,a),getParamValue("filter",t,r,a),s,i,o,l)]}case"Conv2D":{let s=getParamValue("strides",t,r,a),i=getPadding(t,r,a),o=getParamValue("dataFormat",t,r,a).toUpperCase(),l=getParamValue("dilations",t,r,a);return[n.conv2d(getParamValue("x",t,r,a),getParamValue("filter",t,r,a),[s[1],s[2]],i,o,[l[1],l[2]])]}case"_FusedConv2D":{let{stride:s,pad:i,dataFormat:o,dilations:l,biasArg:u,preluArg:p,activationFunc:m,leakyreluAlpha:y}=fusedConvAndDepthWiseParams(t,r,a);return[n.fused.conv2d({x:getParamValue("x",t,r,a),filter:getParamValue("filter",t,r,a),strides:[s[1],s[2]],pad:i,dataFormat:o,dilations:[l[1],l[2]],bias:u,activation:m,preluActivationWeights:p,leakyreluAlpha:y})]}case"FusedDepthwiseConv2dNative":{let{stride:s,pad:i,dataFormat:o,dilations:l,biasArg:u,preluArg:p,activationFunc:m,leakyreluAlpha:y}=fusedConvAndDepthWiseParams(t,r,a);return[n.fused.depthwiseConv2d({x:getParamValue("x",t,r,a),filter:getParamValue("filter",t,r,a),strides:[s[1],s[2]],pad:i,dataFormat:o,dilations:[l[1],l[2]],bias:u,activation:m,preluActivationWeights:p,leakyreluAlpha:y})]}case"Conv2DBackpropInput":case"Conv2dTranspose":{let s=getParamValue("outputShape",t,r,a),i=getParamValue("strides",t,r,a),o=getPadding(t,r,a);return[n.conv2dTranspose(getParamValue("x",t,r,a),getParamValue("filter",t,r,a),s,[i[1],i[2]],o)]}case"DepthwiseConv2dNative":case"DepthwiseConv2d":{let s=getParamValue("strides",t,r,a),i=getPadding(t,r,a),o=getParamValue("dilations",t,r,a),l=getParamValue("dataFormat",t,r,a).toUpperCase();return[n.depthwiseConv2d(getParamValue("input",t,r,a),getParamValue("filter",t,r,a),[s[1],s[2]],i,l,[o[1],o[2]])]}case"Conv3D":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("dataFormat",t,r,a).toUpperCase(),l=getParamValue("dilations",t,r,a);return[n.conv3d(getParamValue("x",t,r,a),getParamValue("filter",t,r,a),[s[1],s[2],s[3]],i,o,[l[1],l[2],l[3]])]}case"AvgPool":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("kernelSize",t,r,a);return[n.avgPool(getParamValue("x",t,r,a),[o[1],o[2]],[s[1],s[2]],i)]}case"MaxPool":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("kernelSize",t,r,a);return[n.maxPool(getParamValue("x",t,r,a),[o[1],o[2]],[s[1],s[2]],i)]}case"MaxPoolWithArgmax":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("kernelSize",t,r,a),l=getParamValue("includeBatchInIndex",t,r,a),{result:u,indexes:p}=n.maxPoolWithArgmax(getParamValue("x",t,r,a),[o[1],o[2]],[s[1],s[2]],i,l);return[u,p]}case"AvgPool3D":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("kernelSize",t,r,a);return[n.avgPool3d(getParamValue("x",t,r,a),[o[1],o[2],o[3]],[s[1],s[2],s[3]],i)]}case"MaxPool3D":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("kernelSize",t,r,a);return[n.maxPool3d(getParamValue("x",t,r,a),[o[1],o[2],o[3]],[s[1],s[2],s[3]],i)]}case"Dilation2D":{let s=getParamValue("strides",t,r,a),i=getParamValue("pad",t,r,a),o=getParamValue("dilations",t,r,a),l=s[1],u=s[2],p=o[1],m=o[2];return[n.dilation2d(getParamValue("x",t,r,a),getParamValue("filter",t,r,a),[l,u],i,[p,m],"NHWC")]}default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"creation":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Fill":{let s=getParamValue("shape",t,r,a),i=getParamValue("dtype",t,r,a),o=getParamValue("value",t,r,a);return[n.fill(s,o,i)]}case"LinSpace":{let s=getParamValue("start",t,r,a),i=getParamValue("stop",t,r,a),o=getParamValue("num",t,r,a);return[n.linspace(s,i,o)]}case"Multinomial":{let s=getParamValue("logits",t,r,a),i=getParamValue("numSamples",t,r,a),o=getParamValue("seed",t,r,a);return[n.multinomial(s,i,o)]}case"OneHot":{let s=getParamValue("indices",t,r,a),i=getParamValue("depth",t,r,a),o=getParamValue("onValue",t,r,a),l=getParamValue("offValue",t,r,a),u=getParamValue("dtype",t,r,a);return[n.oneHot(s,i,o,l,u)]}case"Ones":return[n.ones(getParamValue("shape",t,r,a),getParamValue("dtype",t,r,a))];case"OnesLike":return[n.onesLike(getParamValue("x",t,r,a))];case"RandomStandardNormal":return[n.randomStandardNormal(getParamValue("shape",t,r,a),getParamValue("dtype",t,r,a),getParamValue("seed",t,r,a))];case"RandomUniform":return[n.randomUniform(getParamValue("shape",t,r,a),getParamValue("minval",t,r,a),getParamValue("maxval",t,r,a),getParamValue("dtype",t,r,a))];case"RandomUniformInt":return[n.randomUniformInt(getParamValue("shape",t,r,a),getParamValue("minval",t,r,a),getParamValue("maxval",t,r,a),getParamValue("seed",t,r,a))];case"Range":{let s=getParamValue("start",t,r,a),i=getParamValue("stop",t,r,a),o=getParamValue("step",t,r,a);return[n.range(s,i,o,getParamValue("dtype",t,r,a))]}case"TruncatedNormal":{let s=getParamValue("shape",t,r,a),i=getParamValue("mean",t,r,a),o=getParamValue("stdDev",t,r,a),l=getParamValue("seed",t,r,a);return[n.truncatedNormal(s,i,o,getParamValue("dtype",t,r,a),l)]}case"Zeros":return[n.zeros(getParamValue("shape",t,r,a),getParamValue("dtype",t,r,a))];case"ZerosLike":return[n.zerosLike(getParamValue("x",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"dynamic":return dynamic_executor_executeOp(t,r,a);case"evaluation":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"LowerBound":{let s=getParamValue("sortedSequence",t,r,a),i=getParamValue("values",t,r,a);return[n.lowerBound(s,i)]}case"TopKV2":{let s=getParamValue("x",t,r,a),i=getParamValue("k",t,r,a),o=getParamValue("sorted",t,r,a),l=n.topk(s,i,o);return[l.values,l.indices]}case"UpperBound":{let s=getParamValue("sortedSequence",t,r,a),i=getParamValue("values",t,r,a);return[n.upperBound(s,i)]}case"Unique":{let s=getParamValue("x",t,r,a),i=n.unique(s);return[i.values,i.indices]}case"UniqueV2":{let s=getParamValue("x",t,r,a),i=getParamValue("axis",t,r,a),o=n.unique(s,i);return[o.values,o.indices]}default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"image":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"ResizeBilinear":{let s=getParamValue("images",t,r,a),i=getParamValue("size",t,r,a),o=getParamValue("alignCorners",t,r,a),l=getParamValue("halfPixelCenters",t,r,a);return[n.image.resizeBilinear(s,[i[0],i[1]],o,l)]}case"ResizeNearestNeighbor":{let s=getParamValue("images",t,r,a),i=getParamValue("size",t,r,a),o=getParamValue("alignCorners",t,r,a),l=getParamValue("halfPixelCenters",t,r,a);return[n.image.resizeNearestNeighbor(s,[i[0],i[1]],o,l)]}case"CropAndResize":{let s=getParamValue("image",t,r,a),i=getParamValue("boxes",t,r,a),o=getParamValue("boxInd",t,r,a),l=getParamValue("cropSize",t,r,a),u=getParamValue("method",t,r,a),p=getParamValue("extrapolationValue",t,r,a);return[n.image.cropAndResize(s,i,o,l,u,p)]}case"ImageProjectiveTransformV3":{let s=getParamValue("images",t,r,a),i=getParamValue("transforms",t,r,a),o=getParamValue("outputShape",t,r,a),l=getParamValue("fillValue",t,r,a),u=getParamValue("interpolation",t,r,a),p=getParamValue("fillMode",t,r,a);return[n.image.transform(s,i,u.toLowerCase(),p.toLowerCase(),l,o)]}default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"graph":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Const":return r[t.name];case"PlaceholderWithDefault":let s=getParamValue("default",t,r,a);return[getTensor(t.name,r,a)||s];case"Placeholder":return[getTensor(t.name,r,a)];case"Identity":case"StopGradient":case"FakeQuantWithMinMaxVars":case"Snapshot":return[cloneTensor(getParamValue("x",t,r,a))];case"IdentityN":return getParamValue("x",t,r,a).map(t=>cloneTensor(t));case"Shape":return[n.tensor1d(getParamValue("x",t,r,a).shape,"int32")];case"ShapeN":return getParamValue("x",t,r,a).map(t=>n.tensor1d(t.shape));case"Size":return[n.scalar(getParamValue("x",t,r,a).size,"int32")];case"Rank":return[n.scalar(getParamValue("x",t,r,a).rank,"int32")];case"NoOp":return[n.scalar(1)];case"Print":let i=getParamValue("x",t,r,a),o=getParamValue("data",t,r,a),l=getParamValue("message",t,r,a),u=getParamValue("summarize",t,r,a);console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."),console.log(l);for(let t=0;t<o.length;t++)console.log(Array.prototype.slice.call(o[t].dataSync()).slice(0,u));return[i];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"logical":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Equal":return[n.equal(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"NotEqual":return[n.notEqual(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Greater":return[n.greater(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"GreaterEqual":return[n.greaterEqual(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Less":return[n.less(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"LessEqual":return[n.lessEqual(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"LogicalAnd":return[n.logicalAnd(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"LogicalNot":return[n.logicalNot(getParamValue("a",t,r,a))];case"LogicalOr":return[n.logicalOr(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"Select":case"SelectV2":return[n.where(getParamValue("condition",t,r,a),getParamValue("a",t,r,a),getParamValue("b",t,r,a))];case"BitwiseAnd":return[n.bitwiseAnd(getParamValue("a",t,r,a),getParamValue("b",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"matrices":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"BatchMatMul":case"BatchMatMulV2":case"MatMul":return[n.matMul(getParamValue("a",t,r,a),getParamValue("b",t,r,a),getParamValue("transposeA",t,r,a),getParamValue("transposeB",t,r,a))];case"Einsum":return[n.einsum(getParamValue("equation",t,r,a),...getParamValue("tensors",t,r,a))];case"Transpose":return[n.transpose(getParamValue("x",t,r,a),getParamValue("perm",t,r,a))];case"_FusedMatMul":let[s,i]=getParamValue("fusedOps",t,r,a),o="prelu"===i,l=getParamValue("numArgs",t,r,a),u=getParamValue("leakyreluAlpha",t,r,a);if("biasadd"===s){if(o&&2!==l)throw Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!o&&1!==l)throw Error("Fused MatMul with BiasAdd must have one extra argument: bias.")}let[p,m]=getParamValue("args",t,r,a);return[n.fused.matMul({a:getParamValue("a",t,r,a),b:getParamValue("b",t,r,a),transposeA:getParamValue("transposeA",t,r,a),transposeB:getParamValue("transposeB",t,r,a),bias:p,activation:i,preluActivationWeights:m,leakyreluAlpha:u})];case"MatrixBandPart":return[n.linalg.bandPart(getParamValue("a",t,r,a),getParamValue("numLower",t,r,a),getParamValue("numUpper",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"normalization":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"EuclideanNorm":return[n.euclideanNorm(getParamValue("x",t,r,a),getParamValue("axis",t,r,a),getParamValue("keepDims",t,r,a))];case"FusedBatchNorm":case"FusedBatchNormV2":case"FusedBatchNormV3":return[n.batchNorm(getParamValue("x",t,r,a),getParamValue("mean",t,r,a),getParamValue("variance",t,r,a),getParamValue("offset",t,r,a),getParamValue("scale",t,r,a),getParamValue("epsilon",t,r,a))];case"LRN":return[n.localResponseNormalization(getParamValue("x",t,r,a),getParamValue("radius",t,r,a),getParamValue("bias",t,r,a),getParamValue("alpha",t,r,a),getParamValue("beta",t,r,a))];case"Softmax":return[n.softmax(getParamValue("x",t,r,a))];case"LogSoftmax":return[n.logSoftmax(getParamValue("x",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"ragged":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"RaggedGather":{let{outputNestedSplits:s,outputDenseValues:i}=n.raggedGather(getParamValue("paramsNestedSplits",t,r,a),getParamValue("paramsDenseValues",t,r,a),getParamValue("indices",t,r,a),getParamValue("outputRaggedRank",t,r,a));return s.concat(i)}case"RaggedRange":{let{rtNestedSplits:s,rtDenseValues:i}=n.raggedRange(getParamValue("starts",t,r,a),getParamValue("limits",t,r,a),getParamValue("splits",t,r,a));return[s,i]}case"RaggedTensorToTensor":return[n.raggedTensorToTensor(getParamValue("shape",t,r,a),getParamValue("values",t,r,a),getParamValue("defaultValue",t,r,a),getParamValue("rowPartitionTensors",t,r,a),getParamValue("rowPartitionTypes",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"reduction":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Max":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.max(getParamValue("x",t,r,a),s,i)]}case"Mean":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.mean(getParamValue("x",t,r,a),s,i)]}case"Min":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.min(getParamValue("x",t,r,a),s,i)]}case"Sum":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.sum(getParamValue("x",t,r,a),s,i)]}case"All":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.all(getParamValue("x",t,r,a),s,i)]}case"Any":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.any(getParamValue("x",t,r,a),s,i)]}case"ArgMax":{let s=getParamValue("axis",t,r,a);return[n.argMax(getParamValue("x",t,r,a),s)]}case"ArgMin":{let s=getParamValue("axis",t,r,a);return[n.argMin(getParamValue("x",t,r,a),s)]}case"Prod":{let s=getParamValue("axis",t,r,a),i=getParamValue("keepDims",t,r,a);return[n.prod(getParamValue("x",t,r,a),s,i)]}case"Cumprod":{let s=getParamValue("axis",t,r,a),i=getParamValue("exclusive",t,r,a),o=getParamValue("reverse",t,r,a);return[n.cumprod(getParamValue("x",t,r,a),s,i,o)]}case"Cumsum":{let s=getParamValue("axis",t,r,a),i=getParamValue("exclusive",t,r,a),o=getParamValue("reverse",t,r,a);return[n.cumsum(getParamValue("x",t,r,a),s,i,o)]}case"Bincount":let s=getParamValue("x",t,r,a),i=getParamValue("weights",t,r,a),o=getParamValue("size",t,r,a);return[n.bincount(s,i,o)];case"DenseBincount":{let s=getParamValue("x",t,r,a),i=getParamValue("weights",t,r,a),o=getParamValue("size",t,r,a),l=getParamValue("binaryOutput",t,r,a);return[n.denseBincount(s,i,o,l)]}default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"slice_join":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"ConcatV2":case"Concat":{let s=getParamValue("n",t,r,a),i=getParamValue("axis",t,r,a),o=getParamValue("tensors",t,r,a);return o=o.slice(0,s),[n.concat(o,i)]}case"Gather":{let s=getParamValue("x",t,r,a),i=getParamValue("indices",t,r,a);return[n.gather(s,n.cast(i,"int32"),0)]}case"GatherV2":{let s=getParamValue("axis",t,r,a),i=getParamValue("batchDims",t,r,a),o=getParamValue("x",t,r,a),l=getParamValue("indices",t,r,a);return[n.gather(o,n.cast(l,"int32"),s,i)]}case"Reverse":{let s=getParamValue("dims",t,r,a),i=[];for(let t=0;t<s.length;t++)s[t]&&i.push(t);let o=getParamValue("x",t,r,a);return[n.reverse(o,i)]}case"ReverseV2":{let s=getParamValue("axis",t,r,a),i=getParamValue("x",t,r,a);return[n.reverse(i,s)]}case"Slice":{let s=getParamValue("begin",t,r,a),i=getParamValue("size",t,r,a);return[n.slice(getParamValue("x",t,r,a),s,i)]}case"StridedSlice":{let s=getParamValue("begin",t,r,a),i=getParamValue("end",t,r,a),o=getParamValue("strides",t,r,a),l=getParamValue("beginMask",t,r,a),u=getParamValue("endMask",t,r,a),p=getParamValue("ellipsisMask",t,r,a),m=getParamValue("newAxisMask",t,r,a),y=getParamValue("shrinkAxisMask",t,r,a),_=getParamValue("x",t,r,a);return[n.stridedSlice(_,s,i,o,l,u,p,m,y)]}case"Pack":return globals_tidy(()=>{let s=getParamValue("axis",t,r,a),i=getParamValue("tensors",t,r,a),o=i[0].shape,l=n.squeeze(i[0]).shape,u=i.map(t=>{let r=arraysEqual(t.shape,o);if(!r&&!arraysEqual(n.squeeze(t).shape,l))throw Error("the input tensors shape does not match");return r?t:n.reshape(t,o)});return[n.stack(u,s)]});case"Unpack":{let s=getParamValue("axis",t,r,a),i=getParamValue("tensor",t,r,a);return n.unstack(i,s)}case"Tile":{let s=getParamValue("reps",t,r,a);return[n.tile(getParamValue("x",t,r,a),s)]}case"Split":case"SplitV":{let s=getParamValue("axis",t,r,a),i=getParamValue("numOrSizeSplits",t,r,a),o=getParamValue("x",t,r,a);return n.split(o,i,s)}case"ScatterNd":{let s=getParamValue("indices",t,r,a),i=getParamValue("values",t,r,a),o=getParamValue("shape",t,r,a);return[n.scatterND(s,i,o)]}case"GatherNd":{let s=getParamValue("x",t,r,a),i=getParamValue("indices",t,r,a);return[n.gatherND(s,i)]}case"SparseToDense":{let s=getParamValue("sparseIndices",t,r,a),i=getParamValue("outputShape",t,r,a),o=getParamValue("sparseValues",t,r,a),l=getParamValue("defaultValue",t,r,a);return[n.sparseToDense(s,o,i,o.dtype===l.dtype?l:n.cast(l,o.dtype))]}case"TensorScatterUpdate":{let s=getParamValue("indices",t,r,a),i=getParamValue("values",t,r,a),o=getParamValue("tensor",t,r,a);return[n.tensorScatterUpdate(o,s,i)]}default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"sparse":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"SparseFillEmptyRows":{let{outputIndices:s,outputValues:i,emptyRowIndicator:o,reverseIndexMap:l}=n.sparse.sparseFillEmptyRows(getParamValue("indices",t,r,a),getParamValue("values",t,r,a),getParamValue("denseShape",t,r,a),getParamValue("defaultValue",t,r,a));return[s,i,o,l]}case"SparseReshape":{let{outputIndices:s,outputShape:i}=n.sparse.sparseReshape(getParamValue("inputIndices",t,r,a),getParamValue("inputShape",t,r,a),getParamValue("newShape",t,r,a));return[s,i]}case"SparseSegmentMean":return[n.sparse.sparseSegmentMean(getParamValue("data",t,r,a),getParamValue("indices",t,r,a),getParamValue("segmentIds",t,r,a))];case"SparseSegmentSum":return[n.sparse.sparseSegmentSum(getParamValue("data",t,r,a),getParamValue("indices",t,r,a),getParamValue("segmentIds",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"spectral":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"FFT":return[n.fft(getParamValue("x",t,r,a))];case"IFFT":return[n.ifft(getParamValue("x",t,r,a))];case"RFFT":return[n.rfft(getParamValue("x",t,r,a))];case"IRFFT":return[n.irfft(getParamValue("x",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"string":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"StaticRegexReplace":return[n.string.staticRegexReplace(getParamValue("input",t,r,a),getParamValue("pattern",t,r,a),getParamValue("rewrite",t,r,a),getParamValue("replaceGlobal",t,r,a))];case"StringNGrams":{let{nGrams:s,nGramsSplits:i}=n.string.stringNGrams(getParamValue("data",t,r,a),getParamValue("dataSplits",t,r,a),getParamValue("separator",t,r,a),getParamValue("nGramWidths",t,r,a),getParamValue("leftPad",t,r,a),getParamValue("rightPad",t,r,a),getParamValue("padWidth",t,r,a),getParamValue("preserveShortSequences",t,r,a));return[s,i]}case"StringSplit":{let{indices:s,values:i,shape:o}=n.string.stringSplit(getParamValue("input",t,r,a),getParamValue("delimiter",t,r,a),getParamValue("skipEmpty",t,r,a));return[s,i,o]}case"StringToHashBucketFast":return[n.string.stringToHashBucketFast(getParamValue("input",t,r,a),getParamValue("numBuckets",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"transformation":return s(()=>((t,r,a,n=eM)=>{switch(t.op){case"Cast":return[n.cast(getParamValue("x",t,r,a),getParamValue("dtype",t,r,a))];case"ExpandDims":{let s=getParamValue("axis",t,r,a);return[n.expandDims(getParamValue("x",t,r,a),s)]}case"Squeeze":{let s=getParamValue("axis",t,r,a);return[n.squeeze(getParamValue("x",t,r,a),s)]}case"Reshape":return[n.reshape(getParamValue("x",t,r,a),getParamValue("shape",t,r,a))];case"EnsureShape":return[n.ensureShape(getParamValue("x",t,r,a),getParamValue("shape",t,r,a))];case"MirrorPad":return[n.mirrorPad(getParamValue("x",t,r,a),getParamValue("padding",t,r,a),getParamValue("mode",t,r,a))];case"PadV2":case"Pad":return[n.pad(getParamValue("x",t,r,a),getParamValue("padding",t,r,a),getParamValue("constantValue",t,r,a))];case"SpaceToBatchND":{let s=getParamValue("blockShape",t,r,a),i=getParamValue("paddings",t,r,a);return[n.spaceToBatchND(getParamValue("x",t,r,a),s,i)]}case"BatchToSpaceND":{let s=getParamValue("blockShape",t,r,a),i=getParamValue("crops",t,r,a);return[n.batchToSpaceND(getParamValue("x",t,r,a),s,i)]}case"DepthToSpace":{let s=getParamValue("blockSize",t,r,a),i=getParamValue("dataFormat",t,r,a).toUpperCase();return[n.depthToSpace(getParamValue("x",t,r,a),s,i)]}case"BroadcastTo":return[n.broadcastTo(getParamValue("x",t,r,a),getParamValue("shape",t,r,a))];case"BroadcastArgs":return[n.broadcastArgs(getParamValue("s0",t,r,a),getParamValue("s1",t,r,a))];default:throw TypeError(`Node type ${t.op} is not implemented`)}})(t,r,a));case"hash_table":return hash_table_executor_executeOp(t,r,a,n);case"custom":let i=lu[t.op];if(i&&i.customExecutor)return i.customExecutor(new NodeValueImpl(t,r,a));throw TypeError(`Custom op ${t.op} is not registered.`);default:throw TypeError(`Unknown op '${t.op}'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()`)}})(t,r,a);return isPromise(i)?i.then(t=>[].concat(t)):[].concat(i)}let ExecutionContext=class ExecutionContext{constructor(t={},r={},a={},n={},s){this.weightMap=t,this.tensorArrayMap=r,this.tensorListMap=a,this.functionMap=n,this.parseNodeNameCache=s,this.rootContext={id:0,frameName:"",iterationId:0},this.contexts=[this.rootContext],this.lastId=0,this.generateCurrentContextIds()}newFrame(t,r){return{id:t,frameName:r,iterationId:0}}set currentContext(t){this.contexts!==t&&(this.contexts=t,this.generateCurrentContextIds())}get currentContext(){return this.contexts}get currentContextId(){return this._currentContextIds[0]}get currentContextIds(){return this._currentContextIds}generateCurrentContextIds(){let t=[];for(let r=0;r<this.contexts.length-1;r++){let a=this.contexts.slice(0,this.contexts.length-r);t.push(this.contextIdforContexts(a))}t.push(""),this._currentContextIds=t}contextIdforContexts(t){return t?t.map(t=>0===t.id&&0===t.iterationId?"":`${t.frameName}-${t.iterationId}`).join("/"):""}enterFrame(t){this.contexts&&(this.lastId++,this.contexts=this.contexts.slice(),this.contexts.push(this.newFrame(this.lastId,t)),this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)))}exitFrame(){if(this.contexts&&this.contexts.length>1)this.contexts=this.contexts.slice(),this.contexts.splice(-1),this.currentContextIds.shift();else throw Error("Cannot exit frame, the context is empty")}nextIteration(){if(this.contexts&&this.contexts.length>0){this.contexts=this.contexts.slice(),this.lastId++;let t=Object.assign({},this.contexts[this.contexts.length-1]);t.iterationId+=1,t.id=this.lastId,this.contexts.splice(-1,1,t),this._currentContextIds.splice(0,1,this.contextIdforContexts(this.contexts))}else throw Error("Cannot increase frame iteration, the context is empty")}getWeight(t){return this.weightMap[t]}addTensorArray(t){this.tensorArrayMap[t.id]=t}getTensorArray(t){return this.tensorArrayMap[t]}addTensorList(t){this.tensorListMap[t.id]=t}getTensorList(t){return this.tensorListMap[t]}dispose(t){for(let r in this.tensorArrayMap)this.tensorArrayMap[r].clearAndClose(t);for(let r in this.tensorListMap)this.tensorListMap[r].clearAndClose(t)}};function getExecutionSubgraph(t,r,a,n){let s=new Set,i=[],o=null,l=null,u=new Set,p=new Set(Object.keys(t).map(t=>parseNodeName(t)[0])),m=new Set((n=n||[]).map(t=>parseNodeName(t.name)[0])),y=[...r];for(;y.length>0;){let t=y.pop();if((isControlFlow(t)||isDynamicShape(t)||isHashTable(t))&&null==o&&(l=(o=t).children.map(t=>t.name).filter(t=>s.has(t))),s.add(t.name),!(null!=a[t.name]||p.has(t.name)||m.has(t.name))){if(0===t.inputs.length){i.push(t.name);continue}t.inputs.forEach(t=>{u.has(t.name)||(u.add(t.name),y.push(t))})}}return{inputs:t,outputs:r,usedNodes:s,missingInputs:i,dynamicNode:o,syncInputs:l}}function getNodesInTopologicalOrder(t,r){let{usedNodes:a,inputs:n}=r,s=Object.keys(n).map(t=>parseNodeName(t)[0]).map(r=>t.nodes[r]),i=t.initNodes||[],isUsed=t=>a.has("string"==typeof t?t:t.name);function unique(t){return[...new Map(t.map(t=>[t.name,t])).values()]}let o=unique([...s,...t.weights,...i]).filter(isUsed),l=unique([...o,...Object.values(t.nodes)]).filter(isUsed),u=new Map(l.map(t=>[t.name,t])),p={};for(let t of l)for(let r of(p[t.name]=p[t.name]||0,t.children))isUsed(r)||(p[r.name]=1/0),p[r.name]=(p[r.name]||0)+1;let m=Object.entries(p).filter(([,t])=>0===t).map(([t])=>t),y=[...m];for(;m.length>0;){let t=m.pop();for(let r of u.get(t).children.filter(isUsed))0==--p[r.name]&&(y.push(r.name),m.push(r.name))}let _=filterPredefinedReachableNodes(y.map(t=>u.get(t)),o);return validateNodesExecutionOrder(_,o),_}function filterPredefinedReachableNodes(t,r){let a=new Map(t.map(t=>[t.name,t])),n=r.map(t=>t.name),s=new Set(n);for(;n.length>0;){let t=n.pop();for(let r of a.get(t).children)!a.has(r.name)||s.has(r.name)||(s.add(r.name),n.push(r.name))}return t.filter(t=>s.has(t.name))}let NodesExecutionOrderError=class NodesExecutionOrderError extends Error{constructor(t){super(`NodesExecutionOrderError: ${t}`)}};function validateNodesExecutionOrder(t,r){let a=new Map(t.map((t,r)=>[t.name,r])),n=new Set(r.map(t=>t.name)),isPredefined=t=>n.has("string"==typeof t?t:t.name),s=new Set(t.map(t=>t.name)),willBeExecuted=t=>s.has("string"==typeof t?t:t.name);for(let r of t){for(let t of r.children.filter(willBeExecuted)){if(!a.has(t.name))throw new NodesExecutionOrderError(`Child ${t.name} of node ${r.name} is unreachable.`);if(a.get(r.name)>a.get(t.name))throw new NodesExecutionOrderError(`Node ${r.name} is scheduled to run after its child ${t.name}.`)}if(!isPredefined(r))for(let t of r.inputs){if(!a.has(t.name))throw new NodesExecutionOrderError(`Input ${t.name} of node ${r.name} is unreachable.`);if(a.get(t.name)>a.get(r.name))throw new NodesExecutionOrderError(`Node ${r.name} is scheduled to run before its input ${t.name}.`)}}}function getNodeLiveUntilMap(t){let r=new Map(t.map((t,r)=>[t.name,r])),a=Number.MAX_SAFE_INTEGER,n=t.map((t,r)=>isControlFlow(t)?a:r),getSelfLifeSpan=t=>{let a=n[r.get(t.name)];return null==a?-1:a},s=t.map((t,r)=>t.children.map(getSelfLifeSpan).reduce((t,r)=>Math.max(t,r),n[r])),i=new Map;for(let r=0;r<t.length;++r){let n=s[r];if(n===a)continue;let o=t[r],l=t[n];i.has(l.name)||i.set(l.name,[]),i.get(l.name).push(o)}return i}let lA=new Set(["Switch","Merge","Enter","Exit","NextIteration","StatelessIf","StatelessWhile","if","While"]),l$=new Set(["NonMaxSuppressionV2","NonMaxSuppressionV3","NonMaxSuppressionV5","Where"]),lR=new Set(["HashTable","HashTableV2","LookupTableImport","LookupTableImportV2","LookupTableFind","LookupTableFindV2","LookupTableSize","LookupTableSizeV2"]);function isControlFlow(t){return lA.has(t.op)}function isDynamicShape(t){return l$.has(t.op)}function isHashTable(t){return lR.has(t.op)}let GraphExecutor=class GraphExecutor{get weightIds(){return this.parent?this.parent.weightIds:this._weightIds}get functionExecutorMap(){return this.parent?this.parent.functionExecutorMap:this._functionExecutorMap}get weightMap(){return this.parent?this.parent.weightMap:this._weightMap}set weightMap(t){let r=Object.keys(t).map(r=>t[r].map(t=>t.id));this._weightIds=[].concat(...r),this._weightMap=t}set resourceManager(t){this._resourceManager=t}get inputs(){return this._inputs.map(t=>({name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}))}get outputs(){return this._outputs.map(t=>({name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}))}get inputNodes(){return this._inputs.map(t=>t.signatureKey||t.name)}get outputNodes(){return this._outputs.map(t=>{let r=t.signatureKey||t.name;return t.defaultOutput?`${r}:${t.defaultOutput}`:r})}get functions(){return Object.keys(this._functions).reduce((t,r)=>(t[r]=this._functions[r].signature,t),{})}constructor(t,r){this.graph=t,this.parent=r,this.compiledMap=new Map,this.parseNodeNameCache=new Map,this._weightMap={},this.SEPARATOR=",",this._functions={},this._functionExecutorMap={},this.keepIntermediateTensors=!1,this._outputs=t.outputs,this._inputs=t.inputs,this._initNodes=t.initNodes,this._signature=t.signature,this._functions=t.functions,null!=t.functions&&Object.keys(t.functions).forEach(r=>{this._functionExecutorMap[r]=new GraphExecutor(t.functions[r],this)})}getCompilationKey(t,r){let a=t.map(t=>t.name).sort(),n=r.map(t=>t.name).sort();return a.join(this.SEPARATOR)+"--"+n.join(this.SEPARATOR)}compile(t,r){let a=getExecutionSubgraph(t,r,this.weightMap,this._initNodes),{missingInputs:n,dynamicNode:s,syncInputs:i}=a;if(null!=s)throw Error(`This execution contains the node '${s.name}', which has the dynamic op '${s.op}'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [${i}]`);if(n.length>0){let a=r.map(t=>t.name),s=Object.keys(t);throw Error(`Cannot compute the outputs [${a}] from the provided inputs [${s}]. Missing the following inputs: [${n}]`)}let o=getNodesInTopologicalOrder(this.graph,a),l=getNodeLiveUntilMap(o);return{orderedNodes:o,nodeLiveUntilMap:l}}cloneAndKeepTensor(t){if(null==t)return null;let r=t.clone();return keep(r),r}cloneTensorList(t){return t?t.map(t=>this.cloneAndKeepTensor(t)):null}cloneTensorMap(t){return Object.fromEntries(Object.entries(t).map(([t,r])=>[t,this.cloneTensorList(r)]))}execute(t,r){this.disposeIntermediateTensors();let a=Object.keys(t=this.mapInputs(t)).sort();this.checkInputs(t),this.checkInputShapeAndType(t),r=this.mapOutputs(r),this.checkOutputs(r);let n=a.map(t=>this.graph.nodes[parseNodeName(t)[0]]),s=r.map(t=>parseNodeName(t)[0]),i=new Set(s),o=s.map(t=>this.graph.nodes[t]);0===o.length&&(o=this._outputs);let l=this.getCompilationKey(n,o),u=this.compiledMap.get(l);null==u&&(u=this.compile(t,o),this.compiledMap.set(l,u));try{this.keepIntermediateTensors=eV.getBool("KEEP_INTERMEDIATE_TENSORS")}catch(t){this.keepIntermediateTensors=!1,console.warn(t.message)}let p={},m={};return globals_tidy(()=>{let a=new ExecutionContext(this.weightMap,p,m,this.functionExecutorMap,this.parseNodeNameCache),n=Object.assign({},this.weightMap);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap)),Object.keys(t).forEach(r=>{let[s,i]=parseNodeName(r,a),o=[];o[i]=t[r],n[s]=o,this.keepIntermediateTensors&&(this.clonedTensorsMap[s]=this.cloneTensorList(o))});let s=this.getFrozenTensorIds(n),{orderedNodes:o,nodeLiveUntilMap:l}=u;for(let t of o){if(n[t.name])continue;let r=operation_executor_executeOp(t,n,a,this._resourceManager);if(isPromise(r))throw Error(`The execution of the op '${t.op}' returned a promise. Please use model.executeAsync() instead.`);n[t.name]=r,this.keepIntermediateTensors&&(this.clonedTensorsMap[t.name]=this.cloneTensorList(r)),this.checkTensorForDisposalWithNodeLiveUntilInfo(t,n,a,s,i,l.get(t.name))}return null==this.parent&&a.dispose(s),r.map(t=>getTensor(t,n,a))})}getFrozenTensorIds(t){return new Set([].concat.apply([],Object.keys(t).map(r=>t[r]).map(t=>t.map(t=>t.id))))}checkTensorForDisposal(t,r,a,n,s,i,o){if(!(isControlFlow(r)||i.has(t))){for(let n of a[t])null!=n&&(o[n.id]=(o[n.id]||0)+r.children.length);for(let t of r.inputs){if(isControlFlow(t))continue;let r=getTensorsForCurrentContext(t.name,a,n);if(null!=r)for(let t of r){if(!t||t.kept||s.has(t.id))continue;let r=o[t.id];1===r?(t.dispose(),delete o[t.id]):null!=r&&o[t.id]--}}}}checkTensorForDisposalWithNodeLiveUntilInfo(t,r,a,n,s,i){function isNonDisposableNode(t){return isControlFlow(t)||s.has(t.name)}if(!isControlFlow(t)&&null!=i){for(let t of i)if(!isNonDisposableNode(t))for(let s of getTensorsForCurrentContext(t.name,r,a))!s||s.kept||n.has(s.id)||s.dispose()}}async executeAsync(t,r){return this._executeAsync(t,r)}disposeIntermediateTensors(){this.clonedTensorsMap&&(Object.values(this.clonedTensorsMap).forEach(t=>{for(let r of t)r&&!r.isDisposed&&r.dispose()}),this.clonedTensorsMap=null)}getIntermediateTensors(){return this.clonedTensorsMap}async _executeAsync(t,r,a=!1,n={},s={}){this.disposeIntermediateTensors(),a||(t=this.mapInputs(t),this.checkInputs(t),this.checkInputShapeAndType(t),r=this.mapOutputs(r),this.checkOutputs(r));try{this.keepIntermediateTensors=eV.getBool("KEEP_INTERMEDIATE_TENSORS")}catch(t){this.keepIntermediateTensors=!1,console.warn(t.message)}let i=new ExecutionContext(this.weightMap,n,s,this.functionExecutorMap,this.parseNodeNameCache);this.keepIntermediateTensors&&(this.clonedTensorsMap=this.cloneTensorMap(this.weightMap));let o=await this.executeWithControlFlow(t,i,r,a),l=r.map(t=>getTensor(t,o,i)),u=new Set([...l.map(t=>t.id),...Object.keys(t).map(r=>t[r].id),...this.weightIds]);return Object.values(o).forEach(t=>{t.forEach(t=>{!t||t.isDisposed||u.has(t.id)||t.dispose()})}),null==this.parent&&i.dispose(u),l}async executeFunctionAsync(t,r,a){let n=t.reduce((t,r,a)=>(t[this.inputs[a].name]=r,t),{});return this._executeAsync(n,this.outputNodes,!0,r,a)}async executeWithControlFlow(t,r,a,n){let s=Object.keys(t),i=s.map(t=>this.graph.nodes[parseNodeName(t)[0]]),o=a.map(t=>parseNodeName(t)[0]),l=new Set(o),u=o.map(t=>this.graph.nodes[t]);0===u.length&&(u=this._outputs);let{usedNodes:p,missingInputs:m,dynamicNode:y,syncInputs:_}=getExecutionSubgraph(t,u,this.weightMap,this._initNodes),w=[...i,...this.graph.weights,...this._initNodes||[]].map(t=>({node:t,contexts:r.currentContext})),I=Object.assign({},this.weightMap);Object.keys(t).forEach(r=>{let[a,n]=parseNodeName(r),s=[];s[n]=t[r],I[a]=s});let C={},E=this.getFrozenTensorIds(I),A={};for(;w.length>0;){let t=this.processStack(i,w,r,I,A,E,l,C,p);await Promise.all(t)}null!=y||n||console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead.");let $=u.filter(t=>!isControlFlow(t)&&!getTensor(t.name,I,r)).map(t=>t.name);if($.length>0){let t="";throw null!=y&&(t=`Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [${_}]`),Error(`Cannot compute the outputs [${$}] from the provided inputs [${s}]. Consider providing the following inputs: [${m}]. ${t}`)}return I}processStack(t,r,a,n,s,i,o,l,u){let p=[];for(;r.length>0;){let t=r.pop();a.currentContext=t.contexts;let m="";if("Enter"===t.node.op&&getParamValue("isConstant",t.node,n,a)&&([m]=getNodeNameAndIndex(t.node.name,a)),null==n[t.node.name]){let y=operation_executor_executeOp(t.node,n,a,this._resourceManager);m||([m]=getNodeNameAndIndex(t.node.name,a));let _=a.currentContext;isPromise(y)?p.push(y.then(p=>(n[m]=p,this.keepIntermediateTensors&&(this.clonedTensorsMap[m]=this.cloneTensorList(p)),a.currentContext=_,this.checkTensorForDisposal(m,t.node,n,a,i,o,l),this.processChildNodes(t.node,r,a,n,s,u),p))):(n[m]=y,this.keepIntermediateTensors&&(this.clonedTensorsMap[m]=this.cloneTensorList(y)),this.checkTensorForDisposal(m,t.node,n,a,i,o,l),this.processChildNodes(t.node,r,a,n,s,u))}else this.processChildNodes(t.node,r,a,n,s,u)}return p}processChildNodes(t,r,a,n,s,i){t.children.forEach(t=>{let[o]=getNodeNameAndIndex(t.name,a);!s[o]&&i.has(t.name)&&("Merge"===t.op?t.inputNames.some(t=>!!getTensor(t,n,a))&&(s[o]=!0,r.push({contexts:a.currentContext,node:t})):t.inputNames.every(t=>!!getTensor(t,n,a))&&(s[o]=!0,r.push({contexts:a.currentContext,node:t})))})}dispose(){Object.keys(this.weightMap).forEach(t=>this.weightMap[t].forEach(t=>t.dispose()))}checkInputShapeAndType(t){Object.keys(t).forEach(r=>{let a=t[r],[n]=parseNodeName(r),s=this.graph.nodes[n];if(s.attrParams.shape&&s.attrParams.shape.value){let t=s.attrParams.shape.value;assert(t.length===a.shape.length&&a.shape.every((r,a)=>-1===t[a]||t[a]===r),()=>`The shape of dict['${s.name}'] provided in model.execute(dict) must be [${t}], but was [${a.shape}]`)}s.attrParams.dtype&&s.attrParams.dtype.value&&assert(a.dtype===s.attrParams.dtype.value,()=>`The dtype of dict['${s.name}'] provided in model.execute(dict) must be ${s.attrParams.dtype.value}, but was ${a.dtype}`)})}mapInputs(t){var r,a;let n={};for(let s in t){let i=null==(a=null==(r=this._signature)?void 0:r.inputs)?void 0:a[s];null!=i?n[i.name]=t[s]:n[s]=t[s]}return n}checkInputs(t){let r=Object.keys(t).filter(t=>{let[r]=parseNodeName(t);return null==this.graph.nodes[r]});if(r.length>0)throw Error(`The dict provided in model.execute(dict) has keys: [${r}] that are not part of graph`)}mapOutputs(t){return t.map(t=>{var r,a;let n=null==(a=null==(r=this._signature)?void 0:r.outputs)?void 0:a[t];return null!=n?n.name:t},{})}checkOutputs(t){t.forEach(t=>{let[r]=parseNodeName(t);if(!this.graph.nodes[r])throw Error(`The output '${t}' is not found in the graph`)})}};let ResourceManager=class ResourceManager{constructor(t={},r={}){this.hashTableNameToHandle=t,this.hashTableMap=r}addHashTable(t,r){this.hashTableNameToHandle[t]=r.handle,this.hashTableMap[r.id]=r}getHashTableHandleByName(t){return this.hashTableNameToHandle[t]}getHashTableById(t){return this.hashTableMap[t]}dispose(){for(let t in this.hashTableMap)this.hashTableMap[t].clearAndClose(),delete this.hashTableMap[t];for(let t in this.hashTableNameToHandle)this.hashTableNameToHandle[t].dispose(),delete this.hashTableNameToHandle[t]}};let GraphModel=class GraphModel{get modelVersion(){return this.version}get inputNodes(){return this.executor.inputNodes}get outputNodes(){return this.executor.outputNodes}get inputs(){return this.executor.inputs}get outputs(){return this.executor.outputs}get weights(){return this.executor.weightMap}get metadata(){return this.artifacts.userDefinedMetadata}get modelSignature(){return this.signature}get modelStructuredOutputKeys(){return this.structuredOutputKeys}constructor(t,r={},a=eh){this.modelUrl=t,this.loadOptions=r,this.version="n/a",this.io=a,null==r&&(this.loadOptions={}),this.resourceManager=new ResourceManager}findIOHandler(){let t=this.modelUrl;if(null!=t.load)this.handler=t;else if(null!=this.loadOptions.requestInit)this.handler=this.io.browserHTTPRequest(t,this.loadOptions);else{let r=this.io.getLoadHandlers(t,this.loadOptions);if(0===r.length)r.push(this.io.browserHTTPRequest(t,this.loadOptions));else if(r.length>1)throw Error(`Found more than one (${r.length}) load handlers for URL '${[t]}'`);this.handler=r[0]}}load(){if(this.findIOHandler(),null==this.handler.load)throw Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");let t=this.handler.load();return isPromise(t)?t.then(t=>null==t.getWeightStream?this.loadSync(t):this.loadStreaming(t)):this.loadSync(t)}loadSync(t){let r=this.io.decodeWeights(t.weightData,t.weightSpecs);return this.loadWithWeightMap(t,r)}async loadStreaming(t){if(null==t.getWeightStream)throw Error("Model artifacts missing streamWeights function");let r=await decodeWeightsStream(t.getWeightStream(),t.weightSpecs);return this.loadWithWeightMap(t,r)}loadWithWeightMap(t,r){this.artifacts=t;let a=this.artifacts.modelTopology,n=this.artifacts.signature;if(null!=this.artifacts.userDefinedMetadata){let t=this.artifacts.userDefinedMetadata;null!=t.signature&&(n=t.signature),null!=t.structuredOutputKeys&&(this.structuredOutputKeys=t.structuredOutputKeys)}if(this.signature=n,this.version=`${a.versions.producer}.${a.versions.minConsumer}`,this.executor=new GraphExecutor(OperationMapper.Instance.transformGraph(a,this.signature)),this.executor.weightMap=this.convertTensorMapToTensorsMap(r),this.executor.resourceManager=this.resourceManager,null!=t.modelInitializer&&null!=t.modelInitializer.node){let r=OperationMapper.Instance.transformGraph(t.modelInitializer);this.initializer=new GraphExecutor(r),this.initializer.weightMap=this.executor.weightMap,this.initializer.resourceManager=this.resourceManager,this.initializerSignature=t.initializerSignature}return!0}async save(t,r){if("string"==typeof t){let r=this.io.getSaveHandlers(t);if(0===r.length)throw Error(`Cannot find any save handlers for URL '${t}'`);if(r.length>1)throw Error(`Found more than one (${r.length}) save handlers for URL '${t}'`);t=r[0]}if(null==t.save)throw Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return t.save(this.artifacts)}addStructuredOutputNames(t){if(this.structuredOutputKeys){let r={};return(t instanceof tensor_Tensor?[t]:t).forEach((t,a)=>r[this.structuredOutputKeys[a]]=t),r}return t}predict(t,r){let a=this.execute(t,this.outputNodes);return this.addStructuredOutputNames(a)}async predictAsync(t,r){let a=await this.executeAsync(t,this.outputNodes);return this.addStructuredOutputNames(a)}normalizeInputs(t){var r;if(!(t instanceof tensor_Tensor)&&!Array.isArray(t)){let a=null==(r=this.signature)?void 0:r.inputs;if(null!=a)for(let r in a){let n=a[r];null!=n.resourceId&&(t[r]=this.resourceIdToCapturedInput[n.resourceId])}return t}t=Array.isArray(t)?t:[t];let a=Object.keys(this.resourceIdToCapturedInput).length;if(t.length+a!==this.inputNodes.length)throw Error(`Input tensor count mismatch, the graph model has ${this.inputNodes.length-a} non-resource placeholders, while there are ${t.length} input tensors provided.`);let n=0;return this.inputNodes.reduce((r,a)=>{var s,i,o;let l=null==(o=null==(i=null==(s=this.signature)?void 0:s.inputs)?void 0:i[a])?void 0:o.resourceId;return null!=l?r[a]=this.resourceIdToCapturedInput[l]:r[a]=t[n++],r},{})}normalizeOutputs(t){return Array.isArray(t=t||this.outputNodes)?t:[t]}executeInitializerGraph(){return null==this.initializer?[]:null==this.initializerSignature?this.initializer.execute({},[]):this.initializer.execute({},Object.keys(this.initializerSignature.outputs))}async executeInitializerGraphAsync(){return null==this.initializer?[]:null==this.initializerSignature?this.initializer.executeAsync({},[]):this.initializer.executeAsync({},Object.keys(this.initializerSignature.outputs))}setResourceIdToCapturedInput(t){if(this.resourceIdToCapturedInput={},this.initializerSignature){let r=this.initializerSignature.outputs,a=Object.keys(r);for(let n=0;n<a.length;n++){let s=r[a[n]];this.resourceIdToCapturedInput[s.resourceId]=t[n]}}}execute(t,r){null==this.resourceIdToCapturedInput&&this.setResourceIdToCapturedInput(this.executeInitializerGraph()),t=this.normalizeInputs(t),r=this.normalizeOutputs(r);let a=this.executor.execute(t,r);return a.length>1?a:a[0]}async executeAsync(t,r){null==this.resourceIdToCapturedInput&&this.setResourceIdToCapturedInput(await this.executeInitializerGraphAsync()),t=this.normalizeInputs(t),r=this.normalizeOutputs(r);let a=await this.executor.executeAsync(t,r);return a.length>1?a:a[0]}getIntermediateTensors(){return this.executor.getIntermediateTensors()}disposeIntermediateTensors(){this.executor.disposeIntermediateTensors()}convertTensorMapToTensorsMap(t){return Object.keys(t).reduce((r,a)=>(r[a]=[t[a]],r),{})}dispose(){this.executor.dispose(),this.initializer&&(this.initializer.dispose(),this.resourceIdToCapturedInput&&globals_dispose(this.resourceIdToCapturedInput)),this.resourceManager.dispose()}};async function loadGraphModel(t,r={},a=eh){if(null==t)throw Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");null==r&&(r={}),r.fromTFHub&&"string"==typeof t&&(t=getTFHubUrl(t));let n=new GraphModel(t,r,a);return await n.load(),n}function getTFHubUrl(t){return t.endsWith("/")||(t+="/"),`${t}model.json?tfjs-format=file`}function deepMap(t,r){return deepMapInternal(t,r)}function deepMapInternal(t,r,a=new Map,n=new Set){if(null==t)return null;if("function"==typeof Blob&&t instanceof Blob)return t.slice();if(n.has(t))throw Error("Circular references are not supported.");if(a.has(t))return a.get(t);let s=r(t);if(s.recurse&&null!==s.value)throw Error("A deep map function may not return both a value and recurse=true.");if(!s.recurse)return a.set(t,s.value),s.value;if(deep_map_isIterable(t)){let s=Array.isArray(t)?[]:{};for(let i in n.add(t),t){let o=deepMapInternal(t[i],r,a,n);s[i]=o}return n.delete(t),t.__proto__&&(s.__proto__=t.__proto__),s}throw Error(`Can't recurse into non-iterable type: ${t}`)}function deepZip(t,r=zipToList){return deepZipInternal(t,r)}function deepZipInternal(t,r,a=new Set){let n=t[0];if(a.has(n))throw Error("Circular references are not supported.");let s=r(t);if(s.recurse&&null!==s.value)throw Error("A deep zip function may not return both a value and recurse=true.");if(!s.recurse)return s.value;if(deep_map_isIterable(n)){let s=Array.isArray(n)?[]:{};for(let i in a.add(n),n){let n=deepZipInternal(t.map(t=>t[i]),r,a);s[i]=n}return a.delete(n),s}throw Error(`Can't recurse into non-iterable type: ${n}`)}function zipToList(t){return null===t?null:deep_map_isIterable(t[0])?{value:null,recurse:!0}:{value:t,recurse:!1}}function deep_map_isIterable(t){let r=!1;if(eV.get("IS_BROWSER"))r=t instanceof TextDecoder;else{let{StringDecoder:n}=a(0x5395223a);r=t instanceof n}return null!=t&&!ArrayBuffer.isView(t)&&(Array.isArray(t)||"object"==typeof t&&!(t instanceof tensor_Tensor)&&!(t instanceof Promise)&&!r)}function canTensorify(t){return null==t||isPrimitive(t)||Array.isArray(t)||"object"==typeof t&&t instanceof tensor_Tensor||isTypedArray(t)}function isPrimitive(t){return null===t||"object"!=typeof t&&"function"!=typeof t}function deepClone(t){return deepMap(t,cloneIfTensor)}function cloneIfTensor(t){return t instanceof tensor_Tensor?{value:t.clone(),recurse:!1}:deep_map_isIterable(t)?{value:null,recurse:!0}:{value:t,recurse:!1}}let RingBuffer=class RingBuffer{constructor(t){if(this.capacity=t,this.begin=0,this.end=0,null==t)throw RangeError("Can't create a ring buffer of unknown capacity.");if(t<1)throw RangeError("Can't create ring buffer of capacity < 1.");this.data=Array(t),this.doubledCapacity=2*t}wrap(t){for(;t<0;)t+=this.doubledCapacity;return t%this.doubledCapacity}get(t){if(t<0)throw RangeError("Can't get item at a negative index.");return this.data[t%this.capacity]}set(t,r){if(t<0)throw RangeError("Can't set item at a negative index.");this.data[t%this.capacity]=r}length(){let t=this.end-this.begin;return t<0&&(t=this.doubledCapacity+t),t}isFull(){return this.length()===this.capacity}isEmpty(){return 0===this.length()}push(t){if(this.isFull())throw RangeError("Ring buffer is full.");this.set(this.end,t),this.end=this.wrap(this.end+1)}pushAll(t){for(let r of t)this.push(r)}pop(){if(this.isEmpty())throw RangeError("Ring buffer is empty.");this.end=this.wrap(this.end-1);let t=this.get(this.end);return this.set(this.end,void 0),t}unshift(t){if(this.isFull())throw RangeError("Ring buffer is full.");this.begin=this.wrap(this.begin-1),this.set(this.begin,t)}shift(){if(this.isEmpty())throw RangeError("Ring buffer is empty.");let t=this.get(this.begin);return this.set(this.begin,void 0),this.begin=this.wrap(this.begin+1),t}shuffleExcise(t){if(this.isEmpty())throw RangeError("Ring buffer is empty.");let r=this.wrap(this.begin+t),a=this.get(r);return this.set(r,this.pop()),a}};let GrowingRingBuffer=class GrowingRingBuffer extends RingBuffer{constructor(){super(GrowingRingBuffer.INITIAL_CAPACITY)}isFull(){return!1}push(t){super.isFull()&&this.expand(),super.push(t)}unshift(t){super.isFull()&&this.expand(),super.unshift(t)}expand(){let t=2*this.capacity,r=Array(t),a=this.length();for(let t=0;t<a;t++)r[t]=this.get(this.wrap(this.begin+t));this.data=r,this.capacity=t,this.doubledCapacity=2*this.capacity,this.begin=0,this.end=a}};function lazy_iterator_iteratorFromItems(t){return new ArrayIterator(t)}function lazy_iterator_iteratorFromFunction(t){return new FunctionCallIterator(t)}function iteratorFromConcatenated(t,r){return new ChainedIterator(t,r)}GrowingRingBuffer.INITIAL_CAPACITY=32;let LazyIterator=class LazyIterator{async toArray(){let t=[],r=await this.next();for(;!r.done;)t.push(r.value),r=await this.next();return t}async toArrayForTest(){let t=this.prefetch(100),r=[],a=await t.next();for(;!a.done;)r.push(a.value),a=await t.next();return r}async resolveFully(){let t=await this.next();for(;!t.done;)t=await this.next()}async resolveWhile(t){let r=await this.next(),a=t(r.value);for(;!r.done&&a;)a=t((r=await this.next()).value)}handleErrors(t){return new ErrorHandlingLazyIterator(this,t)}filter(t){return new FilterIterator(this,t)}map(t){return new MapIterator(this,t)}mapAsync(t){return new AsyncMapIterator(this,t)}serialMapAsync(t){return new AsyncMapIterator(this,t).serial()}flatmap(t){return new FlatmapIterator(this,t)}async forEachAsync(t){return this.map(t).resolveFully()}async serialForEach(t){return this.serialMapAsync(t).resolveWhile(t=>!0===t)}rowMajorBatch(t,r=!0){return new RowMajorBatchIterator(this,t,r)}columnMajorBatch(t,r=!0,a=zipToList){return this.rowMajorBatch(t,r).map(t=>deepZip(t,a))}concatenate(t,r){return new ChainedIterator(lazy_iterator_iteratorFromItems([this,t]),r)}take(t){return t<0||null==t?this:new TakeIterator(this,t)}skip(t){return t<0||null==t?this:new SkipIterator(this,t)}prefetch(t){return new PrefetchIterator(this,t)}shuffle(t,r){return new ShuffleIterator(this,t,r)}serial(){return new SerialIterator(this)}};let ArrayIterator=class ArrayIterator extends LazyIterator{constructor(t){super(),this.items=t,this.trav=0}summary(){return`Array of ${this.items.length} items`}async next(){if(this.trav>=this.items.length)return{value:null,done:!0};let t=this.items[this.trav];return this.trav++,{value:deepClone(t),done:!1}}};let FunctionCallIterator=class FunctionCallIterator extends LazyIterator{constructor(t){super(),this.nextFn=t}summary(){return"Function call"}async next(){try{return this.nextFn()}catch(t){throw t.message=`Error thrown while iterating through a dataset: ${t.message}`,t}}};let SerialIterator=class SerialIterator extends LazyIterator{constructor(t){super(),this.upstream=t,this.lastRead=Promise.resolve({value:null,done:!1})}summary(){return`${this.upstream.summary()} -> Serial`}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){return this.upstream.next()}};let SkipIterator=class SkipIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.maxCount=r,this.count=0,this.lastRead=Promise.resolve({value:null,done:!1})}summary(){return`${this.upstream.summary()} -> Skip`}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){for(;this.count++<this.maxCount;){let t=await this.upstream.next();if(t.done)return t;globals_dispose(t.value)}return this.upstream.next()}};let TakeIterator=class TakeIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.maxCount=r,this.count=0}summary(){return`${this.upstream.summary()} -> Take`}async next(){return this.count++>=this.maxCount?{value:null,done:!0}:this.upstream.next()}};let RowMajorBatchIterator=class RowMajorBatchIterator extends LazyIterator{constructor(t,r,a=!0){super(),this.upstream=t,this.batchSize=r,this.enableSmallLastBatch=a,this.lastRead=Promise.resolve({value:null,done:!1})}summary(){return`${this.upstream.summary()} -> RowMajorBatch`}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){let t=[];for(;t.length<this.batchSize;){let r=await this.upstream.next();if(r.done){if(this.enableSmallLastBatch&&t.length>0)return{value:t,done:!1};return{value:null,done:!0}}t.push(r.value)}return{value:t,done:!1}}};let FilterIterator=class FilterIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.predicate=r,this.lastRead=Promise.resolve({value:null,done:!1})}summary(){return`${this.upstream.summary()} -> Filter`}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){for(;;){let t=await this.upstream.next();if(t.done||this.predicate(t.value))return t;globals_dispose(t.value)}}};let MapIterator=class MapIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.transform=r}summary(){return`${this.upstream.summary()} -> Map`}async next(){let t=await this.upstream.next();if(t.done)return{value:null,done:!0};let r=getTensorsInContainer(t.value),a=this.transform(t.value),n=getTensorsInContainer(a);for(let t of r)isTensorInList(t,n)||t.dispose();return{value:a,done:!1}}};let ErrorHandlingLazyIterator=class ErrorHandlingLazyIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.handler=r,this.count=0,this.lastRead=Promise.resolve({value:null,done:!1})}summary(){return`${this.upstream.summary()} -> handleErrors`}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){for(;;)try{return await this.upstream.next()}catch(t){if(!this.handler(t))return{value:null,done:!0}}}};let AsyncMapIterator=class AsyncMapIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.transform=r}summary(){return`${this.upstream.summary()} -> AsyncMap`}async next(){let t=await this.upstream.next();if(t.done)return{value:null,done:!0};let r=getTensorsInContainer(t.value),a=await this.transform(t.value),n=getTensorsInContainer(a);for(let t of r)isTensorInList(t,n)||t.dispose();return{value:a,done:!1}}};let OneToManyIterator=class OneToManyIterator extends LazyIterator{constructor(){super(),this.outputQueue=new GrowingRingBuffer,this.lastRead=Promise.resolve({value:null,done:!1})}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}async serialNext(){for(;0===this.outputQueue.length();)if(!await this.pump())return{value:null,done:!0};return{value:this.outputQueue.shift(),done:!1}}};let FlatmapIterator=class FlatmapIterator extends OneToManyIterator{constructor(t,r){super(),this.upstream=t,this.transform=r}summary(){return`${this.upstream.summary()} -> Flatmap`}async pump(){let t=await this.upstream.next();if(t.done)return!1;let r=getTensorsInContainer(t.value),a=this.transform(t.value),n=getTensorsInContainer(a);for(let t of(this.outputQueue.pushAll(a),r))isTensorInList(t,n)||t.dispose();return!0}};let ChainedIterator=class ChainedIterator extends LazyIterator{constructor(t,r){super(),this.baseErrorHandler=r,this.lastRead=null,this.iterator=null,this.moreIterators=t}summary(){return"TODO: fill in upstream of chained summaries -> Chained"}async next(){return this.lastRead=this.readFromChain(this.lastRead),this.lastRead}async readFromChain(t){if(await t,null==this.iterator){let t=await this.moreIterators.next();if(t.done)return{value:null,done:!0};this.iterator=t.value,null!=this.baseErrorHandler&&(this.iterator=this.iterator.handleErrors(this.baseErrorHandler))}let r=await this.iterator.next();return r.done?(this.iterator=null,this.readFromChain(t)):r}};(L=ei||(ei={}))[L.FAIL=0]="FAIL",L[L.SHORTEST=1]="SHORTEST",L[L.LONGEST=2]="LONGEST";let PrefetchIterator=class PrefetchIterator extends LazyIterator{constructor(t,r){super(),this.upstream=t,this.bufferSize=r,this.buffer=new RingBuffer(r)}summary(){return`${this.upstream.summary()} -> Prefetch`}refill(){for(;!this.buffer.isFull();){let t=this.upstream.next();this.buffer.push(t)}}next(){return this.refill(),this.buffer.shift()}};let ShuffleIterator=class ShuffleIterator extends PrefetchIterator{constructor(t,r,a){super(t,r),this.upstream=t,this.windowSize=r,this.upstreamExhausted=!1,this.random=sG.alea(a||util_now().toString()),this.lastRead=Promise.resolve({value:null,done:!1})}async next(){return this.lastRead=this.lastRead.then(()=>this.serialNext()),this.lastRead}randomInt(t){return Math.floor(this.random()*t)}chooseIndex(){return this.randomInt(this.buffer.length())}async serialNext(){for(this.upstreamExhausted||this.refill();!this.buffer.isEmpty();){let t=this.chooseIndex(),r=await this.buffer.shuffleExcise(t);if(!r.done)return this.refill(),r;this.upstreamExhausted=!0}return{value:null,done:!0}}};let Dataset=class Dataset{constructor(){this.size=null}batch(t,r=!0){let a=this;return assert(t>0,()=>`batchSize needs to be positive, but it is
      ${t}`),dataset_datasetFromIteratorFn(async()=>(await a.iterator()).columnMajorBatch(t,r,deepBatchConcat),this.size===1/0||null==this.size?this.size:r?Math.ceil(this.size/t):Math.floor(this.size/t))}concatenate(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).concatenate(await t.iterator()),this.size===1/0||t.size===1/0?1/0:null!=this.size&&null!=t.size?this.size+t.size:null)}filter(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).filter(r=>globals_tidy(()=>t(r))),this.size===1/0?1/0:null)}async forEachAsync(t){return(await this.iterator()).forEachAsync(t)}map(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).map(r=>globals_tidy(()=>t(r))),this.size)}mapAsync(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).mapAsync(t),this.size)}prefetch(t){if(null==t)throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).prefetch(t),this.size)}repeat(t){let r=this;return dataset_datasetFromIteratorFn(async()=>iteratorFromConcatenated(lazy_iterator_iteratorFromFunction(async()=>({value:await r.iterator(),done:!1})).take(t)),null!=this.size&&t>0?this.size*t:0===t?0:null!=this.size&&(void 0===t||t<0)?1/0:null)}skip(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).skip(t),null!=this.size&&t>=0&&this.size>=t?this.size-t:null!=this.size&&(this.size<t||void 0===t||t<0)?0:null)}shuffle(t,r,a=!0){if(null==t||t<0)if(null==this.size)throw RangeError("`Dataset.shuffle()` requires bufferSize to be specified.");else throw RangeError(`\`Dataset.shuffle()\` requires bufferSize to be specified.  If your data fits in main memory (for regular JS objects), and/or GPU memory (for \`tf.Tensor\`s), consider setting bufferSize to the dataset size (${this.size} elements)`);let n=this,s=sG.alea(r||util_now().toString());return dataset_datasetFromIteratorFn(async()=>{let r=s.int32();return a&&(r+=s.int32()),(await n.iterator()).shuffle(t,r.toString())},this.size)}take(t){let r=this;return dataset_datasetFromIteratorFn(async()=>(await r.iterator()).take(t),null!=this.size&&this.size>t?t:null!=this.size&&this.size<=t?this.size:null)}async toArray(){if(this.size===1/0)throw Error("Can not convert infinite data stream to array.");return(await this.iterator()).toArray()}async toArrayForTest(){if(this.size===1/0)throw Error("Can not convert infinite data stream to array.");return(await this.iterator()).toArrayForTest()}};function dataset_datasetFromIteratorFn(t,r=null){return new class extends Dataset{constructor(){super(...arguments),this.size=r}async iterator(){return t()}}}function deepBatchConcat(t){return null===t?null:canTensorify(t[0])?{value:batchConcat(t),recurse:!1}:{value:null,recurse:!0}}function batchConcat(t){if(0===t.length)throw Error("Can't make a batch of zero elements.");return t[0]instanceof tensor_Tensor?ig(t):tensor(t)}Dataset.MAX_BUFFER_SIZE=1e4,Symbol("out"),Symbol("field"),Symbol("quote"),Symbol("quoteafterquote"),Symbol("quoteinquote");let StringIterator=class StringIterator extends LazyIterator{split(t){return new SplitIterator(this,t)}};let SplitIterator=class SplitIterator extends StringIterator{constructor(t,r){super(),this.upstream=t,this.impl=new SplitIteratorImpl(t,r)}summary(){return this.impl.summary()}async next(){return this.impl.next()}};let SplitIteratorImpl=class SplitIteratorImpl extends OneToManyIterator{constructor(t,r){super(),this.upstream=t,this.separator=r,this.carryover=""}summary(){return`${this.upstream.summary()} -> Split('${this.separator}')`}async pump(){let t=await this.upstream.next();if(t.done)return""!==this.carryover&&(this.outputQueue.push(this.carryover),this.carryover="",!0);let r=t.value.split(this.separator);for(let t of(r[0]=this.carryover+r[0],r.slice(0,-1)))this.outputQueue.push(t);return this.carryover=r[r.length-1],!0}};function assertNotComplex(t,r){Array.isArray(t)||(t=[t]),t.forEach(t=>{null!=t&&assert("complex64"!==t.dtype,()=>`${r} does not support complex64 tensors in the CPU backend.`)})}let lF=whereImpl;let MathBackendCPU=class MathBackendCPU extends KernelBackend{nextDataId(){return MathBackendCPU.nextDataId++}constructor(){super(),this.blockSize=48,this.firstUse=!0,this.data=new DataStorage(this,ay)}write(t,r,a){this.firstUse&&(this.firstUse=!1,eV.get("IS_NODE")&&warn(`
============================
Hi, looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, visit https://github.com/tensorflow/tfjs-node for more details. 
============================`));let n={id:this.nextDataId()};return this.data.set(n,{values:t,dtype:a,refCount:1}),n}makeTensorInfo(t,r,a){let n;if("string"===r&&null!=a&&a.length>0&&isString(a[0])){let s=a.map(t=>encodeString(t));n=this.write(s,t,r)}else n=this.write(a,t,r);return{dataId:n,shape:t,dtype:r}}refCount(t){return this.data.has(t)?this.data.get(t).refCount:0}incRef(t){let r=this.data.get(t);r.refCount++}decRef(t){if(this.data.has(t)){let r=this.data.get(t);r.refCount--}}move(t,r,a,n,s){this.data.set(t,{values:r,dtype:n,refCount:s})}numDataIds(){return this.data.numDataIds()}async read(t){return this.readSync(t)}readSync(t){let{dtype:r,complexTensorInfos:a}=this.data.get(t);return"complex64"===r?mergeRealAndImagArrays(this.readSync(a.real.dataId),this.readSync(a.imag.dataId)):convertBackendValuesAndArrayBuffer(this.data.get(t).values,r)}bufferSync(t){let r=this.readSync(t.dataId);if("string"===t.dtype)try{let a=r.map(t=>decodeString(t));return buffer(t.shape,t.dtype,a)}catch{throw Error("Failed to decode encoded string bytes into utf-8")}return buffer(t.shape,t.dtype,r)}makeOutput(t,r,a){return ay.makeTensorFromTensorInfo(this.makeTensorInfo(r,a,t),this)}disposeData(t,r=!1){if(this.data.has(t)){if(this.data.get(t).refCount--,!r&&this.data.get(t).refCount>0)return!1;let{complexTensorInfos:a}=this.data.get(t);null!=a&&(this.disposeData(a.real.dataId,!0),this.disposeData(a.imag.dataId,!0)),this.data.delete(t)}return!0}disposeIntermediateTensorInfo(t){this.disposeData(t.dataId)}async time(t){let r=util_now();return t(),{kernelMs:util_now()-r}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(t){assertNotComplex([t],"where");let r=this.readSync(t.dataId);return lF(t.shape,r)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}};function createSimpleUnaryImpl(t){return(r,a,n)=>{let s=getArrayFromDType(a,r.length);for(let a=0;a<r.length;++a)s[a]=t(r[a],n);return s}}function unaryKernelFunc(t,r,a){return unaryKernelFuncFromImpl(t,createSimpleUnaryImpl(r),a)}function unaryKernelFuncFromImpl(t,r,a){return({inputs:n,attrs:s,backend:i})=>{let o,{x:l}=n;assertNotComplex(l,t);let u=i.data.get(l.dataId).values;if("string"===l.dtype){if(!Array.isArray(u))throw Error("String tensor's value was not an instance of Array");o=fromUint8ToStringArray(u)}else o=u;let p=a||l.dtype,m=r(o,p,s);return i.makeTensorInfo(l.shape,p,m)}}MathBackendCPU.nextDataId=0,registerBackend("cpu",()=>new MathBackendCPU,1);let lD=unaryKernelFunc("Elu",t=>t>=0?t:Math.exp(t)-1);function Identity_identity(t){let{inputs:r,backend:a}=t,{x:n}=r;return a.incRef(n.dataId),{dataId:n.dataId,shape:n.shape,dtype:n.dtype}}function LeakyRelu_leakyRelu(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{alpha:i}=n;assertNotComplex([s],"leakyRelu");let o=sizeFromShape(s.shape),l=a.data.get(s.dataId).values,u=getArrayFromDType("float32",o);for(let t=0;t<l.length;t++)u[t]=l[t]<0?i*l[t]:l[t];return a.makeTensorInfo(s.shape,"float32",u)}function createSimpleBinaryKernelImpl(t){return(r,a,n,s,i)=>{let o=assertAndGetBroadcastShape(r,a),l=o.length,u=computeStrides(o),p=getArrayFromDType(i,sizeFromShape(o)),m=r.length,y=a.length,_=computeStrides(r),w=computeStrides(a),I=getBroadcastDims(r,o),C=getBroadcastDims(a,o);if(I.length+C.length===0)for(let r=0;r<p.length;++r)p[r]=t(n[r%n.length],s[r%s.length]);else for(let r=0;r<p.length;++r){let a=indexToLoc(r,l,u),i=a.slice(-m);I.forEach(t=>i[t]=0);let o=locToIndex(i,m,_),E=a.slice(-y);C.forEach(t=>E[t]=0);let A=locToIndex(E,y,w);p[r]=t(n[o],s[A])}return[p,o]}}let lP=createSimpleBinaryKernelImpl((t,r)=>t<0?r*t:t);function Prelu_prelu(t){let{inputs:r,backend:a}=t,{x:n,alpha:s}=r;assertNotComplex([n,s],"prelu");let i=a.data.get(n.dataId).values,o=a.data.get(s.dataId).values,[l,u]=lP(n.shape,s.shape,i,o,"float32");return a.makeTensorInfo(u,"float32",l)}let lO=unaryKernelFunc(rx,t=>Math.max(0,t)),lM=unaryKernelFunc(rw,t=>Math.min(Math.max(0,t),6)),lL=createSimpleUnaryImpl(t=>1/(1+Math.exp(-t))),lz=unaryKernelFunc(rM,t=>1/(1+Math.exp(-t)));function fused_utils_applyActivation(t,r,a,n,s){if("linear"===a)return Identity_identity({inputs:{x:r},backend:t});if("relu"===a)return lO({inputs:{x:r},backend:t});if("elu"===a)return lD({inputs:{x:r},backend:t});if("relu6"===a)return lM({inputs:{x:r},backend:t});if("prelu"===a)return Prelu_prelu({inputs:{x:r,alpha:n},backend:t});else if("leakyrelu"===a)return LeakyRelu_leakyRelu({inputs:{x:r},backend:t,attrs:{alpha:s}});else if("sigmoid"===a)return lz({inputs:{x:r},backend:t});throw Error(`Activation ${a} has not been implemented for the CPU backend.`)}function Complex_complex(t){let{inputs:r,backend:a}=t,{real:n,imag:s}=r,i=a.data.get(n.dataId).values,o=a.data.get(s.dataId).values,l=a.makeTensorInfo(n.shape,"complex64");return a.data.get(l.dataId).complexTensorInfos={real:a.makeTensorInfo(n.shape,"float32",i),imag:a.makeTensorInfo(s.shape,"float32",o)},l}function zeros_impl_zeros(t,r,a="float32"){if("complex64"===a)return Complex_complex({inputs:{real:zeros_impl_zeros(t,r,"float32"),imag:zeros_impl_zeros(t,r,"float32")},backend:t});let n=makeZerosTypedArray(sizeFromShape(r),a);return t.makeTensorInfo(r,a,n)}function Real_real(t){let{inputs:r,backend:a}=t,{input:n}=r,s=a.data.get(n.dataId).complexTensorInfos.real,i=a.data.get(s.dataId).values;return a.makeTensorInfo(s.shape,s.dtype,i)}function castImpl(t,r,a,n){if("int32"===n)return[r,"int32",Int32Array.from(t)];if("bool"===n){let n=toTypedArray([0],a),[s,i]=createSimpleBinaryKernelImpl((t,r)=>+(t!==r))(r,[],t,n,"bool");return[i,"bool",s]}throw Error(`Error in Cast: failed to cast ${a} to ${n}`)}function Cast_cast(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{dtype:i}=n;if("complex64"===i){if("complex64"===s.dtype)return Identity_identity({inputs:{x:s},backend:a});let t=zeros_impl_zeros(a,s.shape,s.dtype),r=Cast_cast({inputs:{x:s},backend:a,attrs:{dtype:"float32"}}),n=Complex_complex({inputs:{real:r,imag:t},backend:a});return a.disposeIntermediateTensorInfo(t),a.disposeIntermediateTensorInfo(r),n}if("complex64"===s.dtype){let t=Real_real({inputs:{input:s},backend:a}),r=Cast_cast({inputs:{x:t},backend:a,attrs:{dtype:i}});return a.disposeIntermediateTensorInfo(t),r}if(!hasEncodingLoss(s.dtype,i)){let t=Identity_identity({inputs:{x:s},backend:a});return{dataId:t.dataId,shape:t.shape,dtype:i}}let[o,l,u]=castImpl(a.data.get(s.dataId).values,s.shape,s.dtype,i);return a.makeTensorInfo(o,l,u)}function binaryKernelFunc(t,r,a,n){return null==a?({inputs:a,backend:s})=>{let{a:i,b:o}=a;assertNotComplex([i,o],t);let l=s.data.get(i.dataId).values,u=s.data.get(o.dataId).values,p="string"===i.dtype?fromUint8ToStringArray(l):l,m="string"===i.dtype?fromUint8ToStringArray(u):u,y=n||i.dtype,[_,w]=r(i.shape,o.shape,p,m,y);return s.makeTensorInfo(w,y,_)}:({inputs:t,backend:s})=>{let{a:i,b:o}=t;if("complex64"===i.dtype||"complex64"===o.dtype){let t=Cast_cast({inputs:{x:i},backend:s,attrs:{dtype:"complex64"}}),r=s.data.get(t.dataId),n=r.complexTensorInfos.real,l=r.complexTensorInfos.imag,u=s.data.get(n.dataId).values,p=s.data.get(l.dataId).values,m=Cast_cast({inputs:{x:o},backend:s,attrs:{dtype:"complex64"}}),y=s.data.get(m.dataId),_=y.complexTensorInfos.real,w=y.complexTensorInfos.imag,I=s.data.get(_.dataId).values,C=s.data.get(w.dataId).values,[E,A,$]=a(i.shape,o.shape,u,p,I,C),F=s.makeTensorInfo($,"float32",E),D=s.makeTensorInfo($,"float32",A),P=Complex_complex({inputs:{real:F,imag:D},backend:s});return s.disposeIntermediateTensorInfo(t),s.disposeIntermediateTensorInfo(m),s.disposeIntermediateTensorInfo(F),s.disposeIntermediateTensorInfo(D),P}{let t=s.data.get(i.dataId).values,a=s.data.get(o.dataId).values,l=n||i.dtype,[u,p]=r(i.shape,o.shape,t,a,l);return s.makeTensorInfo(p,l,u)}}}function createComplexBinaryKernelImpl(t){return(r,a,n,s,i,o)=>{let l=assertAndGetBroadcastShape(r,a),u=sizeFromShape(l),p=l.length,m=computeStrides(l),y=getArrayFromDType("float32",u),_=getArrayFromDType("float32",u),w=getBroadcastDims(r,l),I=getBroadcastDims(a,l),C=mergeRealAndImagArrays(n,s),E=mergeRealAndImagArrays(i,o),A=r.length,$=computeStrides(r),F=a.length,D=computeStrides(a);if(w.length+I.length===0)for(let r=0;r<y.length;r++){let a=r%C.length,n=r%E.length,s=t(C[2*a],C[2*a+1],E[2*n],E[2*n+1]);y[r]=s.real,_[r]=s.imag}else for(let r=0;r<y.length;r++){let a=indexToLoc(r,p,m),n=a.slice(-A);w.forEach(t=>n[t]=0);let s=locToIndex(n,A,$),i=a.slice(-F);I.forEach(t=>i[t]=0);let o=locToIndex(i,F,D),l=t(C[2*s],C[2*s+1],E[2*o],E[2*o+1]);y[r]=l.real,_[r]=l.imag}return[y,_,l]}}let lV=createSimpleBinaryKernelImpl((t,r)=>t+r),lB=binaryKernelFunc("Add",lV,createComplexBinaryKernelImpl((t,r,a,n)=>({real:t+a,imag:r+n})));function Reshape_reshape(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{shape:i}=n,o=sizeFromShape(s.shape),l=inferFromImplicitShape(i,o),u=sizeFromShape(l);assert(o===u,()=>`The new shape (${l}) has ${u} elements and the old shape (${s.shape}) has ${o} elements. The new shape and old shape must have the same number of elements.`),a.incRef(s.dataId);let p=a.data.get(s.dataId);if(null!=p.complexTensorInfos){let t=p.complexTensorInfos.real,r=p.complexTensorInfos.imag;t.shape=l,r.shape=l}return{dataId:s.dataId,shape:l,dtype:s.dtype}}function batchMatMul(t){let{inputs:r,backend:a,attrs:n}=t,{a:s,b:i}=r,{transposeA:o,transposeB:l}=n;assertNotComplex([s,i],"matMul");let u=s.shape.length,p=i.shape.length,m=o?s.shape[u-2]:s.shape[u-1],y=l?i.shape[p-1]:i.shape[p-2],_=o?s.shape[u-1]:s.shape[u-2],w=l?i.shape[p-2]:i.shape[p-1],I=s.shape.slice(0,-2),C=i.shape.slice(0,-2),E=sizeFromShape(I),A=sizeFromShape(C),$=assertAndGetBroadcastShape(s.shape.slice(0,-2),i.shape.slice(0,-2)).concat([_,w]);assert(m===y,()=>`Error in matMul: inner shapes (${m}) and (${y}) of Tensors with shapes ${s.shape} and ${i.shape} and transposeA=${o} and transposeB=${l} must match.`);let F=Reshape_reshape({inputs:{x:s},backend:a,attrs:{shape:o?[E,m,_]:[E,_,m]}}),D=Reshape_reshape({inputs:{x:i},backend:a,attrs:{shape:l?[A,w,y]:[A,y,w]}}),P=o?F.shape[1]:F.shape[2],L=o?F.shape[2]:F.shape[1],z=l?D.shape[1]:D.shape[2],B=Math.max(E,A),G=a.data.get(F.dataId).values,j=a.data.get(D.dataId).values,K=computeStrides(F.shape),H=computeStrides(D.shape),[q,Z,Q]=o?[K[0],1,K[1]]:[K[0],K[1],1],[ee,et,er]=l?[1,H[1],H[0]]:[H[1],1,H[0]],en=L*z,es=buffer([B,L,z],F.dtype),ei=es.values,eo=a.blockSize;for(let t=0;t<B;t++){let r=t%E,a=t%A;for(let n=0;n<L;n+=eo){let s=Math.min(n+eo,L);for(let i=0;i<z;i+=eo){let o=Math.min(i+eo,z);for(let l=0;l<P;l+=eo){let u=Math.min(l+eo,P);for(let p=n;p<s;p++)for(let n=i;n<o;n++){let s=0;for(let t=l;t<u;t++)s+=G[r*q+p*Z+t*Q]*j[t*ee+n*et+a*er];ei[t*en+(p*z+n)]+=s}}}}}return a.disposeIntermediateTensorInfo(F),a.disposeIntermediateTensorInfo(D),a.makeTensorInfo($,es.dtype,es.values)}function _fusedMatMul(t){let r,a,n,{inputs:s,backend:i,attrs:o}=t,{a:l,b:u,bias:p,preluActivationWeights:m}=s,{transposeA:y,transposeB:_,activation:w,leakyreluAlpha:I}=o,C=[];for(let t of(r=batchMatMul({inputs:{a:l,b:u},attrs:{transposeA:y,transposeB:_},backend:i}),p&&(a=lB({inputs:{a:r,b:p},backend:i}),C.push(r),r=a),w&&(n=fused_utils_applyActivation(i,r,w,m,I),C.push(r),r=n),C))i.disposeIntermediateTensorInfo(t);return r}function simpleAbsImpl(t){let r=new Float32Array(t.length);for(let a=0;a<t.length;++a)r[a]=Math.abs(t[a]);return r}let lW=unaryKernelFunc(eB,t=>Math.acos(t)),lU=unaryKernelFunc(eW,t=>Math.acosh(t));function AddN_addN(t){let{inputs:r,backend:a}=t;assertNotComplex(r,"addN");let n=r.map(t=>a.data.get(t.dataId).values),s=buffer(r[0].shape,r[0].dtype),i=s.values;for(let t=0;t<r.length;t++){let r=n[t];for(let t=0;t<i.length;t++)i[t]+=r[t]}return a.makeTensorInfo(s.shape,s.dtype,s.values)}function transposeImpl(t,r,a,n,s){let i=r.length,o=sizeFromShape(r),l=computeStrides(r),u=computeStrides(s),p=getArrayFromDType(a,sizeFromShape(s));for(let r=0;r<o;++r){let a=indexToLoc(r,i,l),s=Array(a.length);for(let t=0;t<s.length;t++)s[t]=a[n[t]];p[locToIndex(s,i,u)]=t[r]}return p}function Transpose_transpose(t){let{inputs:r,attrs:a,backend:n}=t,{x:s}=r,{perm:i}=a;assertNotComplex(s,"transpose");let o=Array(s.shape.length);for(let t=0;t<o.length;t++)o[t]=s.shape[i[t]];let l=transposeImpl(n.data.get(s.dataId).values,s.shape,s.dtype,i,o);return{dataId:n.write(l,o,s.dtype),shape:o,dtype:s.dtype}}function All_all(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,keepDims:o}=n;assertNotComplex(s,"all");let l=parseAxisParam(i,s.shape),u=l,p=getAxesPermutation(u,s.shape.length),m=s;null!=p&&(m=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:p}}),u=getInnerMostAxes(u.length,s.shape.length)),assertAxesAreInnerMostDims("all",u,m.shape.length);let[y,_]=computeOutAndReduceShapes(m.shape,u),w=sizeFromShape(_),I=makeZerosTypedArray(sizeFromShape(y),m.dtype),C=a.data.get(m.dataId).values;for(let t=0;t<I.length;++t){let r=t*w,a=C[r];for(let t=0;t<w;++t){let n=C[r+t];a=a&&n}I[t]=a}null!=p&&a.disposeIntermediateTensorInfo(m);let E=a.makeTensorInfo(y,m.dtype,I);if(o){let t=Reshape_reshape({inputs:{x:E},backend:a,attrs:{shape:expandShapeToKeepDim(y,l)}});return a.disposeIntermediateTensorInfo(E),t}return E}function Any_any(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,keepDims:o}=n;assertNotComplex(s,"any");let l=parseAxisParam(i,s.shape),u=l,p=getAxesPermutation(u,s.shape.length),m=s;null!=p&&(m=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:p}}),u=getInnerMostAxes(u.length,s.shape.length)),assertAxesAreInnerMostDims("any",u,m.shape.length);let[y,_]=computeOutAndReduceShapes(m.shape,u),w=sizeFromShape(_),I=makeZerosTypedArray(sizeFromShape(y),m.dtype),C=a.data.get(m.dataId).values;for(let t=0;t<I.length;++t){let r=t*w,a=C[r];for(let t=0;t<w;++t){let n=C[r+t];a=a||n}I[t]=a}null!=p&&a.disposeIntermediateTensorInfo(m);let E=a.makeTensorInfo(y,m.dtype,I);if(o){let t=Reshape_reshape({inputs:{x:E},backend:a,attrs:{shape:expandShapeToKeepDim(y,l)}});return a.disposeIntermediateTensorInfo(E),t}return E}function ArgMax_argMax(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i}=n;assertNotComplex(s,"argMax");let o=parseAxisParam(i,s.shape),l=getAxesPermutation(o,s.shape.length),u=s,p=[];null!=l&&(p.push(u=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:l}})),o=getInnerMostAxes(o.length,u.shape.length)),assertAxesAreInnerMostDims("argMax",o=[o[0]],u.shape.length);let[m,y]=computeOutAndReduceShapes(u.shape,o),_=makeZerosTypedArray(sizeFromShape(m),"int32"),w=sizeFromShape(y),I=a.data.get(u.dataId).values;for(let t=0;t<_.length;++t){let r=t*w,a=I[r],n=0;for(let t=0;t<w;++t){let s=I[r+t];s>a&&(a=s,n=t)}_[t]=n}return p.forEach(t=>a.disposeIntermediateTensorInfo(t)),a.makeTensorInfo(m,"int32",_)}function ArgMin_argMin(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i}=n;assertNotComplex(s,"argMin");let o=parseAxisParam(i,s.shape),l=getAxesPermutation(o,s.shape.length),u=s,p=[];null!=l&&(p.push(u=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:l}})),o=getInnerMostAxes(o.length,u.shape.length)),assertAxesAreInnerMostDims("argMin",o=[o[0]],u.shape.length);let[m,y]=computeOutAndReduceShapes(u.shape,o),_=makeZerosTypedArray(sizeFromShape(m),"int32"),w=sizeFromShape(y),I=a.data.get(u.dataId).values;for(let t=0;t<_.length;++t){let r=t*w,a=I[r],n=0;for(let t=0;t<w;++t){let s=I[r+t];s<a&&(a=s,n=t)}_[t]=n}return p.forEach(t=>a.disposeIntermediateTensorInfo(t)),a.makeTensorInfo(m,"int32",_)}let lG=unaryKernelFunc(eK,t=>Math.asin(t)),lj=unaryKernelFunc(eH,t=>Math.asinh(t)),lK=unaryKernelFunc(eq,t=>Math.atan(t)),lH=binaryKernelFunc(eY,createSimpleBinaryKernelImpl((t,r)=>Math.atan2(t,r))),lq=unaryKernelFunc(eX,t=>Math.atanh(t));function pool_utils_pool(t,r,a,n,s,i){let o=s.strideHeight,l=s.strideWidth,u=s.dilationHeight,p=s.dilationWidth,m=s.effectiveFilterHeight,y=s.effectiveFilterWidth,_=s.padInfo.top,w=s.padInfo.left,I="max"===i?-1/0:1/0,C=buffer(s.outShape,a),E=C.values,A=s.outShape[1]*s.outShape[2]*s.outShape[3],$=s.outShape[2]*s.outShape[3],F=s.outShape[3];for(let r=0;r<s.batchSize;++r){let a=r*A,C=r*n[0];for(let r=0;r<s.inChannels;++r)for(let A=0;A<s.outHeight;++A){let D=A*o-_,P=Math.max(0,D),L=Math.min(s.inHeight,m+D),z=a+A*$;for(let a=0;a<s.outWidth;++a){let o=a*l-w,m=Math.max(0,o),_=Math.min(s.inWidth,y+o),A=I,$=0,D=0;for(let a=P;a<L;a+=u){let s=C+a*n[1];for(let a=m;a<_;a+=p){let o=t[s+a*n[2]+r];"max"===i&&o>A?A=o:"avg"===i&&($+=o,D++)}if(isNaN(A))break}E[z+a*F+r]="avg"===i?$/D:A}}}return C}function maxPoolPositions(t,r,a,n,s=!1,i=!1){let o=buffer(n.outShape,"int32"),l=n.strideHeight,u=n.strideWidth,p=n.dilationHeight,m=n.dilationWidth,y=n.effectiveFilterHeight,_=n.effectiveFilterWidth,w=n.padInfo.top,I=n.padInfo.left,C=buffer(r,a,t);for(let t=0;t<n.batchSize;++t)for(let r=0;r<n.inChannels;++r)for(let a=0;a<n.outHeight;++a){let E=a*l-w,A=E;for(;A<0;)A+=p;let $=Math.min(n.inHeight,y+E);for(let l=0;l<n.outWidth;++l){let y=l*u-I,w=y;for(;w<0;)w+=m;let F=Math.min(n.inWidth,_+y),D=-1/0,P=-1;for(let a=A;a<$;a+=p){let o=a-E;for(let l=w;l<F;l+=m){let u=l-y,p=C.get(t,a,l,r);p>D&&(D=p,P=s?i?((t*n.inHeight+a)*n.inWidth+l)*n.inChannels+r:(a*n.inWidth+l)*n.inChannels+r:o*_+u)}}o.set(P,t,a,l,r)}}return o}function pool_utils_pool3d(t,r,a,n,s,i){let o=s.strideDepth,l=s.strideHeight,u=s.strideWidth,p=s.dilationDepth,m=s.dilationHeight,y=s.dilationWidth,_=s.effectiveFilterDepth,w=s.effectiveFilterHeight,I=s.effectiveFilterWidth,C=s.padInfo.front,E=s.padInfo.top,A=s.padInfo.left,$="max"===i?-1/0:1/0,F=buffer(s.outShape,a),D=F.values,P=s.outShape[1]*s.outShape[2]*s.outShape[3]*s.outShape[4],L=s.outShape[2]*s.outShape[3]*s.outShape[4],z=s.outShape[3]*s.outShape[4],B=s.outShape[4];for(let r=0;r<s.batchSize;++r){let a=r*P,F=r*n[0];for(let r=0;r<s.inChannels;++r)for(let P=0;P<s.outDepth;++P){let G=P*o-C,j=G;for(;j<0;)j+=p;let K=Math.min(s.inDepth,_+G),H=a+P*L;for(let a=0;a<s.outHeight;++a){let o=a*l-E,_=o;for(;_<0;)_+=m;let C=Math.min(s.inHeight,w+o),P=H+a*z;for(let a=0;a<s.outWidth;++a){let o=a*u-A,l=o;for(;l<0;)l+=y;let w=Math.min(s.inWidth,I+o),E=P+a*B,L=$,z=0,G=0;for(let a=j;a<K;a+=p){let s=F+a*n[1];for(let a=_;a<C;a+=m){let o=s+a*n[2];for(let a=l;a<w;a+=y){let s=t[o+a*n[3]+r];if("max"===i&&s>L?L=s:"avg"===i&&(z+=s,G++),isNaN(L))break}if(isNaN(L))break}if(isNaN(L))break}D[E+r]="avg"===i?z/Math.max(G,1):L}}}}return F}function maxPool3dPositions(t,r){let a=buffer(r.outShape,"int32"),n=r.strideDepth,s=r.strideHeight,i=r.strideWidth,o=r.dilationDepth,l=r.dilationHeight,u=r.dilationWidth,p=r.effectiveFilterDepth,m=r.effectiveFilterHeight,y=r.effectiveFilterWidth,_=r.padInfo.front,w=r.padInfo.top,I=r.padInfo.left;for(let C=0;C<r.batchSize;++C)for(let E=0;E<r.inChannels;++E)for(let A=0;A<r.outDepth;++A){let $=A*n-_,F=$;for(;F<0;)F+=o;let D=Math.min(r.inDepth,p+$);for(let n=0;n<r.outHeight;++n){let p=n*s-w,_=p;for(;_<0;)_+=l;let P=Math.min(r.inHeight,m+p);for(let s=0;s<r.outWidth;++s){let w=s*i-I,L=w;for(;L<0;)L+=u;let z=Math.min(r.inWidth,y+w),B=-1/0,G=-1;for(let r=F;r<D;r+=o){let a=r-$;for(let n=_;n<P;n+=l){let s=n-p;for(let i=L;i<z;i+=u){let o=i-w,l=t.get(C,r,n,i,E);l>=B&&(B=l,G=a*m*y+s*m+o)}}}a.set(G,C,A,n,s,E)}}}return a}function AvgPool_avgPool(t){let r,{inputs:a,backend:n,attrs:s}=t,{x:i}=a;assertNotComplex(i,"avgPool");let{filterSize:o,strides:l,pad:u,dimRoundingMode:p}=s;assert(eitherStridesOrDilationsAreOne(l,1),()=>`Error in avgPool: Either strides or dilations must be 1. Got strides ${l} and dilations '1'`);let m=computePool2DInfo(i.shape,o,l,1,u,p);if(1===m.filterWidth&&1===m.filterHeight&&arraysEqual(m.inShape,m.outShape))r=Identity_identity({inputs:{x:i},backend:n});else{let t=n.data.get(i.dataId).values,a=computeStrides(i.shape),s=pool_utils_pool(t,i.shape,i.dtype,a,m,"avg");r=n.makeTensorInfo(m.outShape,i.dtype,s.values)}return r}function avgPool3D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{filterSize:i,strides:o,pad:l,dimRoundingMode:u,dataFormat:p}=n;assertNotComplex(s,"avgPool3d");let m=computePool3DInfo(s.shape,i,o,1,l,u,p),y=pool_utils_pool3d(a.data.get(s.dataId).values,s.shape,s.dtype,computeStrides(s.shape),m,"avg");return a.makeTensorInfo(y.shape,"float32",y.values)}function avgPool3DGrad(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,input:i}=r,{filterSize:o,strides:l,pad:u,dimRoundingMode:p}=n;assertNotComplex([s,i],"avgPool3DGrad");let m=computePool3DInfo(i.shape,o,l,1,u,p),y=m.strideDepth,_=m.strideHeight,w=m.strideWidth,I=m.filterDepth,C=m.filterHeight,E=m.filterWidth,A=m.dilationDepth,$=m.dilationHeight,F=m.dilationWidth,D=m.effectiveFilterDepth,P=m.effectiveFilterHeight,L=m.effectiveFilterWidth,z=D-1-m.padInfo.front,B=L-1-m.padInfo.left,G=P-1-m.padInfo.top,j=buffer(i.shape,"float32"),K=1/(I*C*E),H=a.bufferSync(s);for(let t=0;t<m.batchSize;++t)for(let r=0;r<m.inChannels;++r)for(let a=0;a<m.inDepth;++a)for(let n=0;n<m.inHeight;++n)for(let s=0;s<m.inWidth;++s){let i=a-z,o=n-G,l=s-B,u=0;for(let a=0;a<D;a+=A){let n=(i+a)/y;if(!(n<0)&&!(n>=m.outDepth)&&Math.floor(n)===n)for(let a=0;a<P;a+=$){let s=(o+a)/_;if(!(s<0)&&!(s>=m.outHeight)&&Math.floor(s)===s)for(let a=0;a<L;a+=F){let i=(l+a)/w;i<0||i>=m.outWidth||Math.floor(i)!==i||(u+=H.get(t,n,s,i,r))}}}j.set(u*K,t,a,n,s,r)}return a.makeTensorInfo(j.shape,j.dtype,j.values)}function AvgPoolGrad_avgPoolGrad(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,input:i}=r;assertNotComplex([s,i],"avgPoolGrad");let{filterSize:o,strides:l,pad:u}=n,p=computePool2DInfo(i.shape,o,l,1,u),m=p.strideHeight,y=p.strideWidth,_=p.filterHeight,w=p.filterWidth,I=p.dilationHeight,C=p.dilationWidth,E=p.effectiveFilterHeight,A=p.effectiveFilterWidth,$=A-1-p.padInfo.left,F=E-1-p.padInfo.top,D=buffer(i.shape,"float32"),P=1/(_*w),L=a.data.get(s.dataId).values,z=buffer(s.shape,"float32",L);for(let t=0;t<p.batchSize;++t)for(let r=0;r<p.inChannels;++r)for(let a=0;a<p.inHeight;++a)for(let n=0;n<p.inWidth;++n){let s=a-F,i=n-$,o=0;for(let a=0;a<E;a+=I){let n=(s+a)/m;if(!(n<0)&&!(n>=p.outHeight)&&Math.floor(n)===n)for(let a=0;a<A;a+=C){let s=(i+a)/y;s<0||s>=p.outWidth||Math.floor(s)!==s||(o+=z.get(t,n,s,r))}}D.set(o*P,t,a,n,r)}return a.makeTensorInfo(D.shape,D.dtype,D.values)}function BatchNorm_batchNorm(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,scale:i,offset:o,mean:l,variance:u}=r;assert(l.shape.length===u.shape.length,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),assert(null==o||l.shape.length===o.shape.length,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),assert(null==i||l.shape.length===i.shape.length,()=>"Batch normalization gradient requires mean and scale to have equal ranks."),assertNotComplex([s,l,u,i,o],"batchNorm");let{varianceEpsilon:p}=n;null==p&&(p=.001);let m=a.data.get(s.dataId).values,y=a.data.get(l.dataId).values,_=a.data.get(u.dataId).values,w=i?a.data.get(i.dataId).values:new Float32Array([1]),I=o?a.data.get(o.dataId).values:new Float32Array([0]),C=new Float32Array(m.length),E=I.length,A=w.length,$=_.length,F=y.length,D=0,P=0,L=0,z=0;for(let t=0;t<m.length;++t)C[t]=I[D++]+(m[t]-y[P++])*w[L++]/Math.sqrt(_[z++]+p),D>=E&&(D=0),P>=F&&(P=0),L>=A&&(L=0),z>=$&&(z=0);return a.makeTensorInfo(s.shape,s.dtype,C)}function sliceImpl(t,r,a,n,s){let i=isSliceContinous(n,r,a),o=sizeFromShape(a),l=computeStrides(n);if(i){let a=computeFlatOffset(r,l);return"string"===s?t.slice(a,a+o):t.subarray(a,a+o)}let u="string"===s?fromUint8ToStringArray(t):t,p=buffer(n,s,u),m=buffer(a,s);for(let t=0;t<m.size;++t){let a=m.indexToLoc(t),n=a.map((t,a)=>t+r[a]);m.set(p.get(...n),...a)}return"string"===s?fromStringArrayToUint8(m.values):m.values}function Slice_slice(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{begin:i,size:o}=n;assertNotComplex(s,"slice");let[l,u]=parseSliceParams(s,i,o);assertParamsValid(s,l,u);let p=sliceImpl(a.data.get(s.dataId).values,l,u,s.shape,s.dtype);return a.makeTensorInfo(u,s.dtype,p)}function BatchToSpaceND_batchToSpaceND(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{blockShape:i,crops:o}=n;assertNotComplex([s],"batchToSpaceND");let l=i.reduce((t,r)=>t*r),u=getReshaped(s.shape,i,l),p=getPermuted(u.length,i.length),m=getReshapedPermuted(s.shape,i,l),y=getSliceBeginCoords(o,i.length),_=getSliceSize(m,o,i.length),w=Reshape_reshape({inputs:{x:s},backend:a,attrs:{shape:u}}),I=Transpose_transpose({inputs:{x:w},backend:a,attrs:{perm:p}}),C=Reshape_reshape({inputs:{x:I},backend:a,attrs:{shape:m}}),E=Slice_slice({inputs:{x:C},backend:a,attrs:{begin:y,size:_}});return a.disposeIntermediateTensorInfo(w),a.disposeIntermediateTensorInfo(I),a.disposeIntermediateTensorInfo(C),E}function bincountImpl(t,r,a,n,s){let i=sizeFromShape(n),o=makeZerosTypedArray(s,a);for(let a=0;a<t.length;a++){let n=t[a];if(n<0)throw Error("Input x must be non-negative!");n>=s||(i>0?o[n]+=r[a]:o[n]+=1)}return o}function bincountReduceImpl(t,r,a,n=!1){let s=t.shape[0],i=t.shape[1],o=buffer([s,a],r.dtype);for(let l=0;l<s;l++)for(let s=0;s<i;s++){let i=t.get(l,s);if(i<0)throw Error("Input x must be non-negative!");i>=a||(n?o.set(1,l,i):r.size>0?o.set(o.get(l,i)+r.get(l,s),l,i):o.set(o.get(l,i)+1,l,i))}return o}function Bincount_bincount(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,weights:i}=r,{size:o}=n,l=bincountImpl(a.data.get(s.dataId).values,a.data.get(i.dataId).values,i.dtype,i.shape,o);return a.makeTensorInfo([o],i.dtype,l)}let lX=createSimpleBinaryKernelImpl((t,r)=>t&r),lY=binaryKernelFunc(e4,lX);function BroadcastArgs_broadcastArgs(t){let{inputs:r,backend:a}=t,{s0:n,s1:s}=r,i=a.data.get(n.dataId).values,o=a.data.get(s.dataId).values,l=assertAndGetBroadcastShape(Array.from(i),Array.from(o));return a.makeTensorInfo([l.length],"int32",Int32Array.from(l))}let lZ=createSimpleUnaryImpl(t=>Math.ceil(t)),lJ=unaryKernelFuncFromImpl(e8,lZ),lQ=unaryKernelFunc(e7,(t,r)=>t>r.clipValueMax?r.clipValueMax:t<r.clipValueMin?r.clipValueMin:t);function concatImpl(t,r,a,n){let s=getArrayFromDType(a,sizeFromShape(r));if(n&&"string"!==a){let r=0;t.forEach(t=>{let a=sizeFromShape(t.shape);s.set(t.vals,r),r+=a})}else{let n=0;t.forEach(t=>{let i="string"===a?fromUint8ToStringArray(t.vals):t.vals,o=0;for(let a=0;a<t.shape[0];++a){let l=a*r[1]+n;for(let r=0;r<t.shape[1];++r)s[l+r]=i[o++]}n+=t.shape[1]})}return s}function Imag_imag(t){let{inputs:r,backend:a}=t,{input:n}=r,s=a.data.get(n.dataId).complexTensorInfos.imag,i=a.data.get(s.dataId).values;return a.makeTensorInfo(s.shape,s.dtype,i)}function Concat_concat(t){let{inputs:r,backend:a,attrs:n}=t,{axis:s}=n,i=parseAxisParam(s,r[0].shape)[0];assertParamsConsistent(r.map(t=>t.shape),i);let o=concat_util_computeOutShape(r.map(t=>t.shape),i);if(0===sizeFromShape(o))return a.makeTensorInfo(o,r[0].dtype,[]);let l=r.filter(t=>sizeFromShape(t.shape)>0);if(1===l.length)return Identity_identity({inputs:{x:l[0]},backend:a});if("complex64"===l[0].dtype){let t=l.map(t=>Real_real({inputs:{input:t},backend:a})),r=l.map(t=>Imag_imag({inputs:{input:t},backend:a})),n=Concat_concat({inputs:t,backend:a,attrs:{axis:i}}),s=Concat_concat({inputs:r,backend:a,attrs:{axis:i}}),o=Complex_complex({inputs:{real:n,imag:s},backend:a});return t.forEach(t=>a.disposeIntermediateTensorInfo(t)),r.forEach(t=>a.disposeIntermediateTensorInfo(t)),a.disposeIntermediateTensorInfo(n),a.disposeIntermediateTensorInfo(s),o}let u=l.map(t=>{let r=sizeFromShape(t.shape.slice(i));return Reshape_reshape({inputs:{x:t},backend:a,attrs:{shape:[-1,r]}})}),p=u.map(t=>({vals:a.data.get(t.dataId).values,shape:t.shape}));o=concat_util_computeOutShape(u.map(t=>t.shape),1);let m=1===u[0].shape[0],y=concatImpl(p,o,r[0].dtype,m),_=concat_util_computeOutShape(l.map(t=>t.shape),i),w=a.makeTensorInfo(_,r[0].dtype,y);return u.forEach(t=>a.disposeIntermediateTensorInfo(t)),w}function conv2D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,filter:i}=r,{strides:o,pad:l,dataFormat:u,dilations:p,dimRoundingMode:m}=n;assertNotComplex([s,i],"conv2d");let y=convertConv2DDataFormat(u),_=computeConv2DInfo(s.shape,i.shape,o,p,l,m,!1,y),w=_.filterHeight,I=_.filterWidth,C=_.dilationHeight,E=_.dilationWidth,A=_.padInfo.left,$=_.padInfo.top,F="channelsLast"===_.dataFormat,D=new TensorBuffer(_.outShape,s.dtype),P=computeStrides(s.shape),L=computeStrides(i.shape),z=P[0],B=F?P[1]:P[2],G=F?P[2]:1,j=F?1:P[1],K=D.strides[0],H=F?D.strides[1]:D.strides[2],q=F?D.strides[2]:1,Z=F?1:D.strides[1],Q=a.data.get(s.dataId).values,ee=a.data.get(i.dataId).values,et=D.values;for(let t=0;t<_.batchSize;++t){let r=t*z,a=t*K;for(let t=0;t<_.outHeight;++t){let n=a+t*H,s=t*_.strideHeight-$;for(let t=0;t<w;++t){let a=s+t*C;if(a<0||a>=_.inHeight)continue;let i=t*L[0],o=r+a*B;for(let t=0;t<_.outWidth;++t){let r=n+t*q,a=t*_.strideWidth-A;for(let t=0;t<I;++t){let n=a+t*E;if(n<0||n>=_.inWidth)continue;let s=i+t*L[1],l=o+n*G,u=s;for(let t=0;t<_.inChannels;++t){let a=Q[l+t*j];for(let t=0;t<_.outChannels;++t)et[r+t*Z]+=a*ee[u+t];u+=_.outChannels}}}}}}return a.makeTensorInfo(D.shape,D.dtype,et)}function Conv2DBackpropFilter_conv2DBackpropFilter(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,dy:i}=r,{strides:o,pad:l,dataFormat:u,dimRoundingMode:p,filterShape:m}=n;assertNotComplex([s,i],"conv2dBackpropFilter");let y=convertConv2DDataFormat(u),_=computeConv2DInfo(s.shape,m,o,1,l,p,!1,y),{strideHeight:w,strideWidth:I,filterHeight:C,filterWidth:E}=_,A="channelsLast"===_.dataFormat,$=new TensorBuffer(_.filterShape,"float32"),F=_.padInfo.left,D=_.padInfo.top,P=a.data.get(s.dataId).values,L=a.data.get(i.dataId).values,z=new TensorBuffer(s.shape,s.dtype,P),B=new TensorBuffer(i.shape,i.dtype,L);for(let t=0;t<C;++t){let r=Math.max(0,Math.ceil((D-t)/w)),a=Math.min(_.outHeight,(_.inHeight+D-t)/w);for(let n=0;n<E;++n){let s=Math.max(0,Math.ceil((F-n)/I)),i=Math.min(_.outWidth,(_.inWidth+F-n)/I);for(let o=0;o<_.inChannels;++o)for(let l=0;l<_.outChannels;++l){let u=0;for(let p=0;p<_.batchSize;++p)for(let m=r;m<a;++m){let r=t+m*w-D;for(let t=s;t<i;++t){let a=n+t*I-F;A?u+=z.get(p,r,a,o)*B.get(p,m,t,l):u+=z.get(p,o,r,a)*B.get(p,l,m,t)}}$.set(u,t,n,o,l)}}}return a.makeTensorInfo($.shape,$.dtype,$.values)}function Conv2DBackpropInput_conv2DBackpropInput(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,filter:i}=r,{inputShape:o,strides:l,pad:u,dataFormat:p,dimRoundingMode:m}=n;assertNotComplex([s,i],"conv2dBackpropInput");let y=computeStrides(i.shape),_=computeStrides(s.shape),w=convertConv2DDataFormat(p),I=computeConv2DInfo(o,i.shape,l,1,u,m,!1,w),C=new TensorBuffer(I.inShape,"float32"),E=C.values,A=a.data.get(s.dataId).values,$=a.data.get(i.dataId).values,[F,D,P]=y,{batchSize:L,filterHeight:z,filterWidth:B,inChannels:G,inHeight:j,inWidth:K,outChannels:H,outHeight:q,outWidth:Z,strideHeight:Q,strideWidth:ee}=I;w=I.dataFormat;let et=z-1-I.padInfo.top,er=B-1-I.padInfo.left,en="channelsLast"===w,es=C.strides[0],ei=en?C.strides[1]:C.strides[2],eo=en?C.strides[2]:1,el=en?1:C.strides[1],eu=_[0],ep=en?_[1]:_[2],eh=en?_[2]:1,ec=en?1:_[1];for(let t=0;t<L;++t)for(let r=0;r<G;++r)for(let a=0;a<j;++a){let n=a-et,s=Math.max(0,Math.ceil(n/Q)),i=Math.min(q,(z+n)/Q);for(let o=0;o<K;++o){let l=o-er,u=Math.max(0,Math.ceil(l/ee)),p=Math.min(Z,(B+l)/ee),m=0;for(let a=s;a<i;++a){let s=a*Q-n;for(let n=u;n<p;++n){let i=n*ee-l,o=eu*t+ep*a+eh*n,u=F*(z-1-s)+D*(B-1-i)+P*r;for(let t=0;t<H;++t)m+=A[o+ec*t]*$[u+t]}}E[es*t+ei*a+eo*o+el*r]=m}}return a.makeTensorInfo(C.shape,C.dtype,C.values)}function conv3D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,filter:i}=r,{strides:o,pad:l,dilations:u}=n;assertNotComplex([s,i],"conv3d");let p=computeConv3DInfo(s.shape,i.shape,o,u,l),{filterDepth:m,filterHeight:y,filterWidth:_,dilationDepth:w,dilationHeight:I,dilationWidth:C,padInfo:E}=p,A=E.front,$=E.left,F=E.top,D=new TensorBuffer(p.outShape,s.dtype),P=a.data.get(s.dataId).values,L=a.data.get(i.dataId).values,z=D.values,B=computeStrides(s.shape),G=computeStrides(i.shape);for(let t=0;t<p.batchSize;++t){let r=t*B[0],a=t*D.strides[0];for(let t=0;t<p.outDepth;++t){let n=a+t*D.strides[1],s=t*p.strideDepth-A;for(let t=0;t<m;++t){let a=s+t*w;if(a<0||a>=p.inDepth)continue;let i=t*G[0],o=r+a*B[1];for(let t=0;t<p.outHeight;++t){let r=n+t*D.strides[2],a=t*p.strideHeight-F;for(let t=0;t<y;++t){let n=a+t*I;if(n<0||n>=p.inHeight)continue;let s=i+t*G[1],l=o+n*B[2];for(let t=0;t<p.outWidth;++t){let a=r+t*p.outChannels,n=t*p.strideWidth-$;for(let t=0;t<_;++t){let r=n+t*C;if(r<0||r>=p.inWidth)continue;let i=s+t*G[2],o=l+r*p.inChannels,u=i;for(let t=0;t<p.inChannels;++t){let r=P[o+t];for(let t=0;t<p.outChannels;++t)z[a+t]+=r*L[u+t];u+=p.outChannels}}}}}}}}return a.makeTensorInfo(D.shape,D.dtype,D.values)}function conv3DBackpropFilterV2(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,dy:i}=r,{strides:o,pad:l,filterShape:u}=n;assertNotComplex([s,i],"conv3dBackpropFilterV2");let p=computeStrides(s.shape),m=computeStrides(i.shape),y=computeConv3DInfo(s.shape,u,o,1,l),_=y.strideDepth,w=y.strideHeight,I=y.strideWidth,C=y.filterDepth,E=y.filterHeight,A=y.filterWidth,$=new TensorBuffer(y.filterShape,"float32"),F=$.values,[D,P,L,z]=$.strides,B=a.data.get(i.dataId).values,[G,j,K,H]=m,q=a.data.get(s.dataId).values,[Z,Q,ee,et]=p,er=y.padInfo.front,en=y.padInfo.left,es=y.padInfo.top;for(let t=0;t<C;++t){let r=Math.max(0,Math.ceil((er-t)/_)),a=Math.min(y.outDepth,(y.inDepth+er-t)/_),n=t*D;for(let s=0;s<E;++s){let i=Math.max(0,Math.ceil((es-s)/w)),o=Math.min(y.outHeight,(y.inHeight+es-s)/w),l=s*P+n;for(let n=0;n<A;++n){let u=Math.max(0,Math.ceil((en-n)/I)),p=Math.min(y.outWidth,(y.inWidth+en-n)/I),m=n*L+l;for(let l=0;l<y.inChannels;++l){let C=l*z+m;for(let m=0;m<y.outChannels;++m){let E=0;for(let C=0;C<y.batchSize;++C){let y=C*Z,A=C*G;for(let C=r;C<a;++C){let r=(t+C*_-er)*Q+y,a=C*j+A;for(let t=i;t<o;++t){let i=(s+t*w-es)*ee+r,o=t*K+a;for(let t=u;t<p;++t){let r=(n+t*I-en)*et+i,a=t*H+o;E+=q[r+l]*B[a+m]}}}}F[C+m]=E}}}}}return a.makeTensorInfo($.shape,$.dtype,$.values)}function conv3DBackpropInputV2(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,filter:i}=r,{pad:o,strides:l,inputShape:u}=n;assertNotComplex([s],"conv3dBackpropInputV2");let p=computeStrides(s.shape),m=computeStrides(i.shape),y=computeConv3DInfo(u,i.shape,l,1,o),_=new TensorBuffer(y.inShape,"float32"),w=_.values,[I,C,E,A]=_.strides,$=a.data.get(s.dataId).values,[F,D,P,L]=p,z=a.data.get(i.dataId).values,[B,G,j,K]=m,{batchSize:H,filterDepth:q,filterHeight:Z,filterWidth:Q,inChannels:ee,inDepth:et,inHeight:er,inWidth:en,outChannels:es,outDepth:ei,outHeight:eo,outWidth:el,strideDepth:eu,strideHeight:ep,strideWidth:eh}=y,ec=q-1-y.padInfo.front,ed=Z-1-y.padInfo.top,em=Q-1-y.padInfo.left;for(let t=0;t<H;++t)for(let r=0;r<ee;++r)for(let a=0;a<et;++a){let n=a-ec,s=Math.max(0,Math.ceil(n/eu)),i=Math.min(ei,(q+n)/eu);for(let o=0;o<er;++o){let l=o-ed,u=Math.max(0,Math.ceil(l/ep)),p=Math.min(eo,(Z+l)/ep);for(let m=0;m<en;++m){let y=m-em,_=Math.max(0,Math.ceil(y/eh)),H=Math.min(el,(Q+y)/eh),ee=0;for(let a=s;a<i;++a){let s=a*eu-n;for(let n=u;n<p;++n){let i=n*ep-l;for(let o=_;o<H;++o){let l=o*eh-y,u=F*t+D*a+P*n+L*o,p=B*(q-1-s)+G*(Z-1-i)+j*(Q-1-l)+K*r;for(let t=0;t<es;++t)ee+=$[u+t]*z[p+t]}}}w[I*t+C*a+E*o+A*m+r]=ee}}}return a.makeTensorInfo(_.shape,_.dtype,_.values)}let l0=unaryKernelFunc("Cos",t=>Math.cos(t)),l1=unaryKernelFunc(tu,t=>Math.cosh(t));function CropAndResize_cropAndResize(t){let{inputs:r,backend:a,attrs:n}=t,{image:s,boxes:i,boxInd:o}=r,{cropSize:l,method:u,extrapolationValue:p}=n,[m,y,_,w]=s.shape,I=i.shape[0],[C,E]=l,A=buffer([I,C,E,w],"float32"),$=a.data.get(i.dataId).values,F=a.data.get(o.dataId).values,D=a.data.get(s.dataId).values,P=computeStrides(s.shape),L=computeStrides(A.shape);for(let t=0;t<I;t++){let r=4*t,a=$[r],n=$[r+1],s=$[r+2],i=$[r+3],o=F[t];if(o>=m)continue;let l=C>1?(s-a)*(y-1)/(C-1):0,I=E>1?(i-n)*(_-1)/(E-1):0;for(let r=0;r<C;r++){let m=C>1?a*(y-1)+r*l:.5*(a+s)*(y-1);if(m<0||m>y-1){for(let a=0;a<E;a++)for(let n=0;n<w;n++){let s=n+a*L[2]+r*L[1]+t*L[0];A.values[s]=p}continue}if("bilinear"===u){let a=Math.floor(m),s=Math.ceil(m),l=m-a;for(let u=0;u<E;u++){let m=E>1?n*(_-1)+u*I:.5*(n+i)*(_-1);if(m<0||m>_-1){for(let a=0;a<w;a++){let n=a+u*L[2]+r*L[1]+t*L[0];A.values[n]=p}continue}let y=Math.floor(m),C=Math.ceil(m),$=m-y;for(let n=0;n<w;n++){let i=n+y*P[2]+a*P[1]+o*P[0],p=D[i],m=D[i=n+C*P[2]+a*P[1]+o*P[0]],_=D[i=n+y*P[2]+s*P[1]+o*P[0]],w=D[i=n+C*P[2]+s*P[1]+o*P[0]],I=p+(m-p)*$,E=_+(w-_)*$;i=n+u*L[2]+r*L[1]+t*L[0],A.values[i]=I+(E-I)*l}}}else for(let a=0;a<E;++a){let s=E>1?n*(_-1)+a*I:.5*(n+i)*(_-1);if(s<0||s>_-1){for(let n=0;n<w;n++){let s=n+a*L[2]+r*L[1]+t*L[0];A.values[s]=p}continue}let l=Math.round(s),u=Math.round(m);for(let n=0;n<w;n++){let s=n+l*P[2]+u*P[1]+o*P[0],i=n+a*L[2]+r*L[1]+t*L[0];A.values[i]=D[s]}}}}return a.makeTensorInfo(A.shape,A.dtype,A.values)}function Cumprod_cumprod(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,exclusive:o,reverse:l}=n;assertNotComplex(s,"cumprod");let u=getAxesPermutation([i],s.shape.length),p=s;null!=u&&(p=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:u}}));let m=getInnerMostAxes(1,s.shape.length)[0];if(m!==p.shape.length-1)throw Error(`backend.cumprod in CPU expects an inner-most axis=${p.shape.length-1} but got axis=${m}`);let y=upcastType(p.dtype,"int32"),_=makeOnesTypedArray(sizeFromShape(p.shape),y),w=a.data.get(p.dataId).values,I=p.shape[p.shape.length-1],C=l?(t,r)=>t+I-r-1:(t,r)=>t+r;for(let t=0;t<w.length;t+=I)for(let r=0;r<I;r++){let a=C(t,r);if(0===r)_[a]=o?1:w[a];else{let n=C(t,r-1);_[a]=o?w[n]*_[n]:w[a]*_[n]}}let E=a.makeTensorInfo(p.shape,y,_);if(null!=u){let t=Transpose_transpose({inputs:{x:E},backend:a,attrs:{perm:getUndoAxesPermutation(u)}});return a.disposeIntermediateTensorInfo(E),a.disposeIntermediateTensorInfo(p),t}return E}function Cumsum_cumsum(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,exclusive:o,reverse:l}=n;assertNotComplex(s,"cumsum");let u=getAxesPermutation([i],s.shape.length),p=s;null!=u&&(p=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:u}}));let m=getInnerMostAxes(1,s.shape.length)[0];if(m!==p.shape.length-1)throw Error(`backend.cumsum in CPU expects an inner-most axis=${p.shape.length-1} but got axis=${m}`);let y=upcastType(p.dtype,"int32"),_=makeZerosTypedArray(sizeFromShape(p.shape),y),w=a.data.get(p.dataId).values,I=p.shape[p.shape.length-1],C=l?(t,r)=>t+I-r-1:(t,r)=>t+r;for(let t=0;t<w.length;t+=I)for(let r=0;r<I;r++){let a=C(t,r);if(0===r)_[a]=o?0:w[a];else{let n=C(t,r-1);_[a]=o?w[n]+_[n]:w[a]+_[n]}}let E=a.makeTensorInfo(p.shape,y,_);if(null!=u){let t=Transpose_transpose({inputs:{x:E},backend:a,attrs:{perm:getUndoAxesPermutation(u)}});return a.disposeIntermediateTensorInfo(E),a.disposeIntermediateTensorInfo(p),t}return E}function DenseBincount_denseBincount(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,weights:i}=r,{size:o,binaryOutput:l}=n;if(1===s.shape.length){let t=bincountImpl(a.data.get(s.dataId).values,a.data.get(i.dataId).values,i.dtype,i.shape,o);return a.makeTensorInfo([o],i.dtype,t)}if(2===s.shape.length){let t=bincountReduceImpl(a.bufferSync(s),a.bufferSync(i),o,l);return a.makeTensorInfo(t.shape,i.dtype,t.values)}throw Error(`Error in denseBincount: input must be at most rank 2, but got rank${s.shape.length}.`)}function DepthToSpace_depthToSpace(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{blockSize:i,dataFormat:o}=n;assert("NHWC"===o,()=>`Only NHWC dataFormat supported on CPU for depthToSpace. Got ${o}`);let l=s.shape[0],u=s.shape[1],p=s.shape[2],m=s.shape[3],y=u*i,_=p*i,w=m/(i*i),I=a.data.get(s.dataId).values,C=new Float32Array(l*y*_*w),E=0;for(let t=0;t<l;++t)for(let r=0;r<y;++r){let a=Math.floor(r/i),n=r%i;for(let r=0;r<_;++r){let s=Math.floor(r/i),o=r%i,l=(n*i+o)*w;for(let r=0;r<w;++r){let n=r+l+m*(s+p*(a+u*t));C[E++]=I[n]}}}return a.makeTensorInfo([l,y,_,w],s.dtype,C)}function depthwiseConv2dNative(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,filter:i}=r,{strides:o,pad:l,dilations:u,dimRoundingMode:p}=n;assertNotComplex([s,i],"depthwiseConv2DNative");let m=computeStrides(s.shape),y=computeStrides(i.shape),_=u;null==_&&(_=[1,1]),assert(eitherStridesOrDilationsAreOne(o,_),()=>`Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${o} and dilations '${_}'`);let w=computeConv2DInfo(s.shape,i.shape,o,_,l,p,!0),{filterHeight:I,filterWidth:C,dilationHeight:E,dilationWidth:A,padInfo:$}=w,F=$.left,D=$.top,P=w.outChannels/w.inChannels,L=new TensorBuffer(w.outShape,s.dtype),z=a.data.get(s.dataId).values,B=a.data.get(i.dataId).values,G=L.values;for(let t=0;t<w.batchSize;++t){let r=t*m[0],a=t*L.strides[0];for(let t=0;t<w.outHeight;++t){let n=a+t*L.strides[1],s=t*w.strideHeight-D;for(let t=0;t<I;++t){let a=s+t*E;if(a<0||a>=w.inHeight)continue;let i=t*y[0],o=r+a*m[1];for(let t=0;t<w.outWidth;++t){let r=n+t*L.strides[2],a=t*w.strideWidth-F;for(let t=0;t<C;++t){let n=a+t*A;if(n<0||n>=w.inWidth)continue;let s=i+t*y[1],l=o+n*w.inChannels,u=r,p=s;for(let t=0;t<w.inChannels;++t){let r=z[l+t];for(let t=0;t<P;++t)G[u+t]+=r*B[p+t];u+=P,p+=P}}}}}}return a.makeTensorInfo(L.shape,L.dtype,L.values)}function DepthwiseConv2dNativeBackpropFilter_depthwiseConv2dNativeBackpropFilter(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,dy:i}=r,{strides:o,dilations:l,pad:u,dimRoundingMode:p,filterShape:m}=n;assertNotComplex([s,i],"depthwiseConv2dNativeBackpropFilter");let y=computeConv2DInfo(s.shape,m,o,l,u,p,!0),{strideHeight:_,strideWidth:w,filterHeight:I,filterWidth:C}=y,E=new TensorBuffer(y.filterShape,"float32"),A=y.padInfo.left,$=y.padInfo.top,F=y.outChannels/y.inChannels,D=a.data.get(s.dataId).values,P=new TensorBuffer(s.shape,s.dtype,D),L=a.data.get(i.dataId).values,z=new TensorBuffer(i.shape,i.dtype,L);for(let t=0;t<I;++t){let r=Math.max(0,Math.ceil(($-t)/_)),a=Math.min(y.outHeight,(y.inHeight+$-t)/_);for(let n=0;n<C;++n){let s=Math.max(0,Math.ceil((A-n)/w)),i=Math.min(y.outWidth,(y.inWidth+A-n)/w);for(let o=0;o<y.outChannels;++o){let l=Math.trunc(o/F),u=o%F,p=0;for(let u=0;u<y.batchSize;++u)for(let m=r;m<a;++m){let r=t+m*_-$;for(let t=s;t<i;++t){let a=n+t*w-A;p+=P.get(u,r,a,l)*z.get(u,m,t,o)}}E.set(p,t,n,l,u)}}}return a.makeTensorInfo(E.shape,E.dtype,E.values)}function DepthwiseConv2dNativeBackpropInput_depthwiseConv2dNativeBackpropInput(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,filter:i}=r,{strides:o,dilations:l,pad:u,dimRoundingMode:p,inputShape:m}=n;assertNotComplex([s,i],"depthwiseConv2DNativeBackpropInput");let y=computeStrides(s.shape),_=computeStrides(i.shape),w=computeConv2DInfo(m,i.shape,o,l,u,p,!0),I=new TensorBuffer(w.inShape,"float32"),C=I.values,[E,A,$]=I.strides,F=a.data.get(s.dataId).values,[D,P,L]=y,z=a.data.get(i.dataId).values,[B,G,j]=_,{batchSize:K,filterHeight:H,filterWidth:q,inChannels:Z,inHeight:Q,inWidth:ee,outChannels:et,outHeight:er,outWidth:en,strideHeight:es,strideWidth:ei}=w,eo=H-1-w.padInfo.top,el=q-1-w.padInfo.left,eu=et/Z;for(let t=0;t<K;++t)for(let r=0;r<Z;++r)for(let a=0;a<Q;++a){let n=a-eo,s=Math.max(0,Math.ceil(n/es)),i=Math.min(er,(H+n)/es);for(let o=0;o<ee;++o){let l=o-el,u=Math.max(0,Math.ceil(l/ei)),p=Math.min(en,(q+l)/ei),m=0;for(let a=s;a<i;++a){let s=a*es-n;for(let n=u;n<p;++n){let i=n*ei-l,o=D*t+P*a+L*n,u=B*(H-1-s)+G*(q-1-i)+j*r;for(let t=0;t<eu;++t)m+=F[o+(r*eu+t)]*z[u+t]}}C[E*t+A*a+$*o+r]=m}}return a.makeTensorInfo(I.shape,I.dtype,I.values)}function Diag_diag(t){let{inputs:r,backend:a}=t,{x:n}=r,s=sizeFromShape(n.shape),i=a.data.get(n.dataId).values,o=buffer([s,s],n.dtype),l=o.values;for(let t=0;t<i.length;t++)l[t*s+t]=i[t];let u=[...n.shape,...n.shape];return a.makeTensorInfo(u,o.dtype,o.values)}function Draw_draw(t){let{inputs:r,backend:a,attrs:n}=t,{image:s}=r,{canvas:i,options:o}=n,{contextOptions:l,imageOptions:u}=o||{},p=(null==u?void 0:u.alpha)||1,m=(null==l?void 0:l.contextType)||"2d";if("2d"!==m)throw Error(`Context type ${l.contextType} is not supported by the CPU backend.`);let y=i.getContext(m,(null==l?void 0:l.contextAttributes)||{});if(null==y)throw Error(`Could not get the context with ${m} type.`);let[_,w]=s.shape.slice(0,2),I=2===s.shape.length?1:s.shape[2],C=a.data.get(s.dataId).values,E="float32"===s.dtype?255:1,A=new Uint8ClampedArray(w*_*4);for(let t=0;t<_*w;++t){let r=[0,0,0,255*p];for(let a=0;a<I;a++){let n=C[t*I+a];if("float32"===s.dtype){if(n<0||n>1)throw Error(`Tensor values for a float32 Tensor must be in the range [0 - 1] but encountered ${n}.`)}else if("int32"===s.dtype&&(n<0||n>255))throw Error(`Tensor values for a int32 Tensor must be in the range [0 - 255] but encountered ${n}.`);1===I?(r[0]=n*E,r[1]=n*E,r[2]=n*E):r[a]=n*E}let a=4*t;A[a+0]=Math.round(r[0]),A[a+1]=Math.round(r[1]),A[a+2]=Math.round(r[2]),A[a+3]=Math.round(r[3])}i.width=w,i.height=_;let $=new ImageData(A,w,_);return y.putImageData($,0,0),s}let l2=createSimpleBinaryKernelImpl((t,r)=>t*r),l3=binaryKernelFunc(re,l2,createComplexBinaryKernelImpl((t,r,a,n)=>({real:t*a-r*n,imag:t*n+r*a})));function Sum_sum(t){let r,{inputs:a,backend:n,attrs:s}=t,{x:i}=a,{axis:o,keepDims:l}=s;assertNotComplex(i,"sum");let u=(r="bool"===i.dtype?Cast_cast({inputs:{x:i},backend:n,attrs:{dtype:"int32"}}):Identity_identity({inputs:{x:i},backend:n})).shape.length,p=parseAxisParam(o,r.shape),m=getAxesPermutation(p,u),y=p,_=r;null!=m&&(_=Transpose_transpose({inputs:{x:r},backend:n,attrs:{perm:m}}),y=getInnerMostAxes(y.length,u)),assertAxesAreInnerMostDims("sum",y,_.shape.length);let[w,I]=computeOutAndReduceShapes(_.shape,y),C=zeros_impl_zeros(n,w,upcastType(_.dtype,"int32")),E=sizeFromShape(I),A=n.data.get(C.dataId).values,$=n.data.get(_.dataId).values;for(let t=0;t<A.length;++t){let r=t*E,a=0;for(let t=0;t<E;++t)a+=$[r+t];A[t]=a}if(l){let t=expandShapeToKeepDim(C.shape,p),r=C;C=Reshape_reshape({inputs:{x:C},backend:n,attrs:{shape:t}}),n.disposeIntermediateTensorInfo(r)}return n.disposeIntermediateTensorInfo(r),null!=m&&n.disposeIntermediateTensorInfo(_),C}function Einsum_einsum(t){let{inputs:r,backend:a,attrs:n}=t,{equation:s}=n,{allDims:i,summedDims:o,idDims:l}=decodeEinsumEquation(s,r.length);checkEinsumDimSizes(i.length,l,r);let{path:u,steps:p}=getEinsumComputePath(o,l),m=p.length,y=null,_=i.length,w=[];for(let t=0;t<m;++t){for(let n of p[t]){let t,{permutationIndices:s,expandDims:i}=getEinsumPermutation(_,l[n]);isIdentityPermutation(s)?t=r[n]:(t=Transpose_transpose({inputs:{x:r[n]},backend:a,attrs:{perm:s}}),w.push(t));let o=t.shape.slice();for(let t=0;t<i.length;++t)o.splice(i[t],0,1);arraysEqual(t.shape,o)||(t=Reshape_reshape({inputs:{x:t},backend:a,attrs:{shape:o}}),w.push(t)),null===y?y=t:(y=l3({inputs:{a:t,b:y},backend:a}),w.push(y))}t<m-1&&(u[t]>=0&&(y=Sum_sum({inputs:{x:y},backend:a,attrs:{axis:u[t]-(i.length-_),keepDims:!1}}),w.push(y)),_--)}for(let t of w)t!==y&&a.disposeIntermediateTensorInfo(t);return y}function eluGrad(t){let{inputs:r,backend:a}=t,{dy:n,y:s}=r;assertNotComplex([n,s],"eluGrad");let i=new Float32Array(sizeFromShape(s.shape)),o=a.data.get(s.dataId).values,l=a.data.get(n.dataId).values;for(let t=0;t<o.length;++t){let r=o[t];r>=0?i[t]=l[t]:i[t]=l[t]*(r+1)}return a.makeTensorInfo(s.shape,"float32",i)}let l4=createSimpleBinaryKernelImpl((t,r)=>+(t===r)),l6=binaryKernelFunc(tN,l4,null,"bool"),l5=unaryKernelFunc("Erf",t=>{let r=Math.sign(t),a=Math.abs(t),n=1/(1+oS*a);return r*(1-((((oE*n+oC)*n+oN)*n+oI)*n+ow)*n*Math.exp(-a*a))}),l8=createSimpleUnaryImpl(t=>Math.exp(t)),l7=unaryKernelFuncFromImpl("Exp",l8,"float32");function ExpandDims_expandDims(t){let{inputs:r,backend:a,attrs:n}=t,{input:s}=r,{dim:i}=n,o=s.shape.length,l=s.shape.slice(),u=i;return i<0&&(assert(-(o+1)<=i,()=>`Axis must be in the interval [${-(o+1)}, ${o}]`),u=o+i+1),l.splice(u,0,1),Reshape_reshape({inputs:{x:s},backend:a,attrs:{shape:l}})}let l9=createSimpleUnaryImpl(t=>Math.expm1(t)),ue=unaryKernelFuncFromImpl(tE,l9),ut=binaryKernelFunc(tS,createSimpleBinaryKernelImpl((t,r)=>t/r)),ur={kernelName:tS,backendName:"cpu",kernelFunc:ut},un=createSimpleBinaryKernelImpl((t,r)=>t-r),us=binaryKernelFunc("Sub",un,createComplexBinaryKernelImpl((t,r,a,n)=>({real:t-a,imag:r-n})));function fftBatch(t,r,a){let n=t.shape,s=n[0],i=n[1],o=a.data.get(t.dataId),l=o.complexTensorInfos.real,u=o.complexTensorInfos.imag,p=[s,i],m=sizeFromShape(p),y=getArrayFromDType("float32",m),_=getArrayFromDType("float32",m);for(let t=0;t<s;t++){let n=Slice_slice({inputs:{x:l},backend:a,attrs:{begin:[t,0],size:[1,i]}}),s=Slice_slice({inputs:{x:u},backend:a,attrs:{begin:[t,0],size:[1,i]}}),o=Complex_complex({inputs:{real:n,imag:s},backend:a}),{real:p,imag:m}=fftImpl(o,r,a),w=mergeRealAndImagArrays(p,m);for(let r=0;r<i;r++){let a=getComplexWithIndex(w,r);y[t*i+r]=a.real,_[t*i+r]=a.imag}a.disposeIntermediateTensorInfo(n),a.disposeIntermediateTensorInfo(s),a.disposeIntermediateTensorInfo(o)}let w=a.makeTensorInfo(p,"float32",y),I=a.makeTensorInfo(p,"float32",_),C=Complex_complex({inputs:{real:w,imag:I},backend:a});return a.disposeIntermediateTensorInfo(w),a.disposeIntermediateTensorInfo(I),C}function fftImpl(t,r,a){let n=sizeFromShape(t.shape),s=a.data.get(t.dataId),i=a.data.get(s.complexTensorInfos.real.dataId).values,o=a.data.get(s.complexTensorInfos.imag.dataId).values;if(!isExponentOf2(n))return splitRealAndImagArrays(fourierTransformByMatmul(mergeRealAndImagArrays(i,o),n,r));{let s=fftRadix2(i,o,n,r,a),l=[t.shape[0],t.shape[1]];if(r){let t=a.makeTensorInfo(l,"float32",s.real),r=a.makeTensorInfo(l,"float32",s.imag),i=a.makeTensorInfo([],"float32",createScalarValue(n,"float32")),o=Identity_identity({inputs:{x:i},backend:a}),u=ur.kernelFunc({inputs:{a:t,b:i},backend:a}),p=ur.kernelFunc({inputs:{a:r,b:o},backend:a}),m=a.data.get(u.dataId).values,y=a.data.get(p.dataId).values;return a.disposeIntermediateTensorInfo(t),a.disposeIntermediateTensorInfo(r),a.disposeIntermediateTensorInfo(i),a.disposeIntermediateTensorInfo(o),a.disposeIntermediateTensorInfo(u),a.disposeIntermediateTensorInfo(p),{real:m,imag:y}}return s}}function isExponentOf2(t){return(t&t-1)==0}function fftRadix2(t,r,a,n,s){if(1===a)return{real:t,imag:r};let i=mergeRealAndImagArrays(t,r),o=a/2,l=complexWithEvenIndex(i),u=l.real,p=l.imag,m=[u.length],y=s.makeTensorInfo(m,"float32",u),_=s.makeTensorInfo(m,"float32",p),w=Complex_complex({inputs:{real:y,imag:_},backend:s}),I=complexWithOddIndex(i),C=I.real,E=I.imag,A=[C.length],$=s.makeTensorInfo(A,"float32",C),F=s.makeTensorInfo(A,"float32",E),D=Complex_complex({inputs:{real:$,imag:F},backend:s}),P=fftRadix2(u,p,o,n,s),L=P.real,z=P.imag,B=[L.length],G=s.makeTensorInfo(B,"float32",L),j=s.makeTensorInfo(B,"float32",z),K=Complex_complex({inputs:{real:G,imag:j},backend:s}),H=fftRadix2(C,E,o,n,s),q=H.real,Z=H.imag,Q=[q.length],ee=s.makeTensorInfo(Q,"float32",q),et=s.makeTensorInfo(Q,"float32",Z),er=Complex_complex({inputs:{real:ee,imag:et},backend:s}),en=exponents(a,n),es=[en.real.length],ei=s.makeTensorInfo(es,"float32",en.real),eo=s.makeTensorInfo(es,"float32",en.imag),el=Complex_complex({inputs:{real:ei,imag:eo},backend:s}),eu=l3({inputs:{a:el,b:er},backend:s}),ep=lB({inputs:{a:K,b:eu},backend:s}),eh=us({inputs:{a:K,b:eu},backend:s}),ec=Real_real({inputs:{input:ep},backend:s}),ed=Real_real({inputs:{input:eh},backend:s}),em=Imag_imag({inputs:{input:ep},backend:s}),ef=Imag_imag({inputs:{input:eh},backend:s}),eg=Concat_concat({inputs:[ec,ed],backend:s,attrs:{axis:0}}),ey=Concat_concat({inputs:[em,ef],backend:s,attrs:{axis:0}}),ex=s.data.get(eg.dataId).values,ev=s.data.get(ey.dataId).values;return s.disposeIntermediateTensorInfo(y),s.disposeIntermediateTensorInfo(_),s.disposeIntermediateTensorInfo(w),s.disposeIntermediateTensorInfo($),s.disposeIntermediateTensorInfo(F),s.disposeIntermediateTensorInfo(D),s.disposeIntermediateTensorInfo(G),s.disposeIntermediateTensorInfo(j),s.disposeIntermediateTensorInfo(K),s.disposeIntermediateTensorInfo(ee),s.disposeIntermediateTensorInfo(et),s.disposeIntermediateTensorInfo(er),s.disposeIntermediateTensorInfo(ei),s.disposeIntermediateTensorInfo(eo),s.disposeIntermediateTensorInfo(el),s.disposeIntermediateTensorInfo(eu),s.disposeIntermediateTensorInfo(ep),s.disposeIntermediateTensorInfo(eh),s.disposeIntermediateTensorInfo(ec),s.disposeIntermediateTensorInfo(em),s.disposeIntermediateTensorInfo(ed),s.disposeIntermediateTensorInfo(ef),s.disposeIntermediateTensorInfo(eg),s.disposeIntermediateTensorInfo(ey),{real:ex,imag:ev}}function fourierTransformByMatmul(t,r,a){let n=new Float32Array(2*r);for(let s=0;s<r;s++){let i=0,o=0;for(let n=0;n<r;n++){let l=exponent(s*n,r,a),u=getComplexWithIndex(t,n);i+=u.real*l.real-u.imag*l.imag,o+=u.real*l.imag+u.imag*l.real}a&&(i/=r,o/=r),assignToTypedArray(n,i,o,s)}return n}function FFT_fft(t){let{inputs:r,backend:a}=t,{input:n}=r,s=sizeFromShape(n.shape),i=n.shape[n.shape.length-1],o=Reshape_reshape({inputs:{x:n},backend:a,attrs:{shape:[s/i,i]}}),l=fftBatch(o,!1,a),u=Reshape_reshape({inputs:{x:l},backend:a,attrs:{shape:n.shape}});return a.disposeIntermediateTensorInfo(o),a.disposeIntermediateTensorInfo(l),u}function Fill_fill(t){let{backend:r,attrs:a}=t,{shape:n,value:s,dtype:i}=a,o=i||inferDtype(s),l=getArrayFromDType(o,sizeFromShape(n));return fillValues(l,s,o),r.makeTensorInfo(n,o,l)}function fillValues(t,r,a){t.fill(r)}let ui=createSimpleUnaryImpl(t=>Math.floor(t)),uo=unaryKernelFuncFromImpl(tR,ui),ul=binaryKernelFunc(tF,createSimpleBinaryKernelImpl((t,r)=>Math.floor(t/r)),null,"int32");function fusedConv2D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,filter:i,bias:o,preluActivationWeights:l}=r,{strides:u,pad:p,dataFormat:m,dilations:y,dimRoundingMode:_,activation:w,leakyreluAlpha:I}=n,C=conv2D({inputs:{x:s,filter:i},backend:a,attrs:{strides:u,pad:p,dataFormat:m,dilations:y,dimRoundingMode:_}});if(o){let t=C;if("NCHW"===m&&1===o.shape.length&&1!==o.shape[0]){let t=Reshape_reshape({inputs:{x:o},backend:a,attrs:{shape:[o.shape[0],1,1]}});C=lB({inputs:{a:C,b:t},backend:a}),a.disposeIntermediateTensorInfo(t)}else C=lB({inputs:{a:C,b:o},backend:a});a.disposeIntermediateTensorInfo(t)}if(w){let t=C;if("NCHW"===m&&"prelu"===w&&1===l.shape.length&&1!==l.shape[0]){let t=Reshape_reshape({inputs:{x:l},backend:a,attrs:{shape:[l.shape[0],1,1]}});C=fused_utils_applyActivation(a,C,w,t,I),a.disposeIntermediateTensorInfo(t)}else C=fused_utils_applyActivation(a,C,w,l,I);a.disposeIntermediateTensorInfo(t)}return C}function fusedDepthwiseConv2D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,filter:i,bias:o,preluActivationWeights:l}=r,{strides:u,pad:p,dataFormat:m,dilations:y,dimRoundingMode:_,activation:w,leakyreluAlpha:I}=n,C=depthwiseConv2dNative({inputs:{x:s,filter:i},backend:a,attrs:{strides:u,pad:p,dataFormat:m,dilations:y,dimRoundingMode:_}});if(o){let t=C;C=lB({inputs:{a:C,b:o},backend:a}),a.disposeIntermediateTensorInfo(t)}if(w){let t=C;C=fused_utils_applyActivation(a,C,w,l,I),a.disposeIntermediateTensorInfo(t)}return C}function gatherNdImpl(t,r,a,n,s,i,o,l,u){let p=buffer([n,i],a);for(let a=0;a<n;a++){let n=[],m=0;for(let r=0;r<s;r++){let i=t[a*s+r];m+=i*o[r],n.push(i)}if(m<0||m>=u/i)throw Error(`Invalid indices: ${n} does not index into ${l}`);for(let t=0;t<i;t++)p.values[a*i+t]=r.get(...r.indexToLoc(m*i+t))}return p}function gatherNd(t){let{inputs:r,backend:a}=t,{params:n,indices:s}=r,i=sizeFromShape(n.shape),o=s.shape,l=o[o.length-1],[u,p,m,y]=prepareAndValidate(n,s);if(0===p)return a.makeTensorInfo(u,n.dtype,[]);let _=gatherNdImpl(a.data.get(s.dataId).values,a.bufferSync(n),n.dtype,p,l,m,y,n.shape,i);return a.makeTensorInfo(u,n.dtype,_.values)}function gatherV2Impl(t,r,a){let n=buffer(a,t.dtype);for(let a=0;a<n.size;++a){let s=n.indexToLoc(a).slice(),i=s[0],o=s[2],l=r.locToIndex([i,o]);s[2]=r.values[l];let u=t.locToIndex(s);0<=u&&u<t.values.length&&(n.values[a]=t.values[u])}return n}function gatherV2(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,indices:i}=r,{axis:o,batchDims:l}=n;assertNotComplex([s,i],"gatherV2");let u=parseAxisParam(o,s.shape)[0],p=a.data.get(i.dataId).values,m=s.shape[u];for(let t=0;t<p.length;++t){let r=p[t];assert(r<=m-1&&r>=0,()=>`GatherV2: the index value ${r} is not in [0, ${m-1}]`)}let y=l;null==l&&(y=0);let _=sizeFromShape(i.shape),w=collectGatherOpShapeInfo(s,i,u,y),I=Reshape_reshape({inputs:{x:s},backend:a,attrs:{shape:[w.batchSize,w.outerSize,w.dimSize,w.sliceSize]}}),C=Reshape_reshape({inputs:{x:i},backend:a,attrs:{shape:[w.batchSize,_/w.batchSize]}}),E=[w.batchSize,w.outerSize,_/w.batchSize,w.sliceSize],A=a.bufferSync(C),$=gatherV2Impl(a.bufferSync(I),A,E);return a.disposeIntermediateTensorInfo(I),a.disposeIntermediateTensorInfo(C),a.makeTensorInfo(w.outputShape,$.dtype,$.values)}let uu=createSimpleBinaryKernelImpl((t,r)=>+(t>r)),up=binaryKernelFunc(tM,uu,null,"bool"),uh=createSimpleBinaryKernelImpl((t,r)=>+(t>=r)),uc=binaryKernelFunc(tL,uh,null,"bool");function IFFT_ifft(t){let{inputs:r,backend:a}=t,{input:n}=r,s=sizeFromShape(n.shape),i=n.shape[n.shape.length-1],o=Reshape_reshape({inputs:{x:n},backend:a,attrs:{shape:[s/i,i]}}),l=fftBatch(o,!0,a),u=Reshape_reshape({inputs:{x:l},backend:a,attrs:{shape:n.shape}});return a.disposeIntermediateTensorInfo(o),a.disposeIntermediateTensorInfo(l),u}let ud=unaryKernelFunc(tW,t=>+!!Number.isFinite(t),"bool"),um=unaryKernelFunc(tU,t=>+(Math.abs(t)===1/0),"bool"),uf=unaryKernelFunc(tG,t=>+!!Number.isNaN(t),"bool"),ug=createSimpleBinaryKernelImpl((t,r)=>+(t<r)),uy=binaryKernelFunc(tK,ug,null,"bool"),ux=createSimpleBinaryKernelImpl((t,r)=>+(t<=r)),uv=binaryKernelFunc(tH,ux,null,"bool");function linSpaceImpl(t,r,a){let n=(r-t)/(a-1),s=makeZerosTypedArray(a,"float32");s[0]=t;for(let t=1;t<s.length;t++)s[t]=s[t-1]+n;return s}function linSpace(t){let{backend:r,attrs:a}=t,{start:n,stop:s,num:i}=a,o=linSpaceImpl(n,s,i);return r.makeTensorInfo([o.length],"float32",o)}let u_=createSimpleUnaryImpl(t=>Math.log(t)),uT=unaryKernelFuncFromImpl("Log",u_),uk=unaryKernelFunc(tX,t=>Math.log1p(t)),uS=binaryKernelFunc(tY,createSimpleBinaryKernelImpl((t,r)=>t&&r),null,"bool"),uw=unaryKernelFunc(tZ,t=>+!t,"bool"),uI=binaryKernelFunc(tJ,createSimpleBinaryKernelImpl((t,r)=>t||r),null,"bool");function lRN(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{depthRadius:i,bias:o,alpha:l,beta:u}=n;assertNotComplex(s,"LRN");let p=s.shape[3],m=p-1,y=a.data.get(s.dataId).values,_=sizeFromShape(s.shape),w=new Float32Array(_);function sumAcrossChannels(t){let r=t%p,a=t-r+Math.max(0,r-i),n=t-r+Math.min(r+i,m),s=0;for(;a<=n;a++){let t=y[a];s+=t*t}return s}for(let t=0;t<_;t++){let r=sumAcrossChannels(t),a=y[t]*Math.pow(o+l*r,-u);w[t]=a}return a.makeTensorInfo(s.shape,s.dtype,w)}function lRNGrad(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,y:i,dy:o}=r,{depthRadius:l,bias:u,alpha:p,beta:m}=n;assertNotComplex(o,"LRNGrad");let y=sizeFromShape(o.shape),_=o.shape[3],w=a.data.get(o.dataId).values,I=a.data.get(s.dataId).values,C=a.data.get(i.dataId).values,E=new Float32Array(y);for(let t=0;t<y;t++){let r=t%_,a=t-r+Math.max(0,r-l),n=t-r+Math.min(_,r+l+1),s=0;for(let t=a;t<n;t++)s+=Math.pow(I[t],2);s=p*s+u;for(let r=a;r<n;r++){let a=-2*p*m*I[r]*C[t]/s;t===r&&(a+=Math.pow(s,-m)),a*=w[t],E[r]+=a}}return a.makeTensorInfo(o.shape,s.dtype,E)}function maxImpl(t,r,a,n){let s=getArrayFromDType(n,sizeFromShape(a));for(let a=0;a<s.length;++a){let n=a*r,i=t[n];for(let a=0;a<r;++a){let r=t[n+a];(Number.isNaN(r)||r>i)&&(i=r)}s[a]=i}return s}function Max_max(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{reductionIndices:i,keepDims:o}=n,l=s.shape,u=l.length,p=parseAxisParam(i,l),m=p,y=getAxesPermutation(m,u),_=a.data.get(s.dataId).values;if(null!=y){let t=Array(u);for(let r=0;r<t.length;r++)t[r]=l[y[r]];_=transposeImpl(_,l,s.dtype,y,t),m=getInnerMostAxes(m.length,u),l=t}assertNotComplex(s,"max"),assertAxesAreInnerMostDims("max",m,u);let[w,I]=computeOutAndReduceShapes(l,m),C=maxImpl(_,sizeFromShape(I),w,s.dtype),E=a.write(C,w,s.dtype),A=w;return o&&(A=expandShapeToKeepDim(w,p)),{dataId:E,shape:A,dtype:s.dtype}}let uN=createSimpleBinaryKernelImpl((t,r)=>Math.max(t,r)),uC=binaryKernelFunc(t0,uN);function MaxPool_maxPool(t){let r,{inputs:a,backend:n,attrs:s}=t,{x:i}=a;assertNotComplex(i,"maxPool");let{filterSize:o,strides:l,pad:u,dimRoundingMode:p}=s;assert(eitherStridesOrDilationsAreOne(l,1),()=>`Error in maxPool: Either strides or dilations must be 1. Got strides ${l} and dilations '1'`);let m=computePool2DInfo(i.shape,o,l,1,u,p);if(1===m.filterWidth&&1===m.filterHeight&&arraysEqual(m.inShape,m.outShape))r=Identity_identity({inputs:{x:i},backend:n});else{let t=n.data.get(i.dataId).values,a=computeStrides(i.shape),s=pool_utils_pool(t,i.shape,i.dtype,a,m,"max");r=n.makeTensorInfo(m.outShape,i.dtype,s.values)}return r}function maxPool3D(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{filterSize:i,strides:o,pad:l,dimRoundingMode:u,dataFormat:p}=n;assertNotComplex(s,"maxPool3d");let m=computePool3DInfo(s.shape,i,o,1,l,u,p),y=pool_utils_pool3d(a.data.get(s.dataId).values,s.shape,s.dtype,computeStrides(s.shape),m,"max");return a.makeTensorInfo(y.shape,"float32",y.values)}function maxPool3DGrad(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,input:i}=r,{filterSize:o,strides:l,pad:u,dimRoundingMode:p}=n;assertNotComplex([s,i],"maxPool3DGrad");let m=computePool3DInfo(i.shape,o,l,1,u,p),y=maxPool3dPositions(a.bufferSync(i),m),_=m.strideDepth,w=m.strideHeight,I=m.strideWidth,C=m.dilationDepth,E=m.dilationHeight,A=m.dilationWidth,$=m.effectiveFilterDepth,F=m.effectiveFilterHeight,D=m.effectiveFilterWidth,P=$-1-m.padInfo.front,L=D-1-m.padInfo.left,z=F-1-m.padInfo.top,B=buffer(i.shape,"float32"),G=a.bufferSync(s);for(let t=0;t<m.batchSize;++t)for(let r=0;r<m.inChannels;++r)for(let a=0;a<m.inDepth;++a)for(let n=0;n<m.inHeight;++n)for(let s=0;s<m.inWidth;++s){let i=a-P,o=n-z,l=s-L,u=0;for(let a=0;a<$;a+=C){let n=(i+a)/_;if(!(n<0)&&!(n>=m.outDepth)&&Math.floor(n)===n)for(let s=0;s<F;s+=E){let i=(o+s)/w;if(!(i<0)&&!(i>=m.outHeight)&&Math.floor(i)===i)for(let o=0;o<D;o+=A){let p=(l+o)/I;if(p<0||p>=m.outWidth||Math.floor(p)!==p)continue;let _=+($*F*D-1-y.get(t,n,i,p,r)===a*F*D+s*D+o);0!==_&&(u+=G.get(t,n,i,p,r)*_)}}}B.set(u,t,a,n,s,r)}return a.makeTensorInfo(B.shape,B.dtype,B.values)}function MaxPoolGrad_maxPoolGrad(t){let{inputs:r,backend:a,attrs:n}=t,{dy:s,input:i,output:o}=r;assertNotComplex([i,o],"maxPoolGrad");let{filterSize:l,strides:u,pad:p,dimRoundingMode:m}=n,y=computePool2DInfo(i.shape,l,u,1,p,m),_=a.data.get(i.dataId).values,w=buffer(y.outShape,i.dtype,maxPoolPositions(_,i.shape,i.dtype,y).values),I=y.strideHeight,C=y.strideWidth,E=y.dilationHeight,A=y.dilationWidth,$=y.effectiveFilterHeight,F=y.effectiveFilterWidth,D=F-1-y.padInfo.left,P=$-1-y.padInfo.top,L=buffer(i.shape,"float32"),z=a.data.get(s.dataId).values,B=buffer(s.shape,"float32",z);for(let t=0;t<y.batchSize;++t)for(let r=0;r<y.inChannels;++r)for(let a=0;a<y.inHeight;++a)for(let n=0;n<y.inWidth;++n){let s=a-P,i=n-D,o=0;for(let a=0;a<$;a+=E){let n=(s+a)/I;if(!(n<0)&&!(n>=y.outHeight)&&Math.floor(n)===n)for(let s=0;s<F;s+=A){let l=(i+s)/C;if(l<0||l>=y.outWidth||Math.floor(l)!==l)continue;let u=+($*F-1-w.get(t,n,l,r)===a*F+s);0!==u&&(o+=B.get(t,n,l,r)*u)}}L.set(o,t,a,n,r)}return a.makeTensorInfo(L.shape,L.dtype,L.values)}function maxPoolWithArgmaxImpl(t,r,a,n,s){let i=computeStrides(r),o=pool_utils_pool(t,r,a,i,s,"max"),l=maxPoolPositions(t,r,a,s,!0,n);return[o.values,l.values]}function Mean_mean(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,keepDims:o}=n,l=parseAxisParam(i,s.shape),u=sizeFromShape(computeOutAndReduceShapes(s.shape,l)[1]),p=[],m=a.makeTensorInfo([],"float32",new Float32Array([u]));p.push(m);let y=Cast_cast({inputs:{x:s},backend:a,attrs:{dtype:"float32"}});p.push(y);let _=ut({inputs:{a:y,b:m},backend:a});p.push(_);let w=Sum_sum({inputs:{x:_},backend:a,attrs:{axis:i,keepDims:o}});return p.forEach(t=>a.disposeIntermediateTensorInfo(t)),w}function Min_min(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,keepDims:o}=n;assertNotComplex(s,"min");let l=parseAxisParam(i,s.shape),u=l,p=getAxesPermutation(u,s.shape.length),m=s;null!=p&&(m=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:p}}),u=getInnerMostAxes(u.length,s.shape.length)),assertAxesAreInnerMostDims("min",u,m.shape.length);let[y,_]=computeOutAndReduceShapes(m.shape,u),w=sizeFromShape(_),I=makeZerosTypedArray(sizeFromShape(y),m.dtype),C=a.data.get(m.dataId).values;for(let t=0;t<I.length;++t){let r=t*w,a=C[r];for(let t=0;t<w;++t){let n=C[r+t];(Number.isNaN(n)||n<a)&&(a=n)}I[t]=a}null!=p&&a.disposeIntermediateTensorInfo(m);let E=a.makeTensorInfo(y,m.dtype,I);if(o){let t=Reshape_reshape({inputs:{x:E},backend:a,attrs:{shape:expandShapeToKeepDim(y,l)}});return a.disposeIntermediateTensorInfo(E),t}return E}let uE=createSimpleBinaryKernelImpl((t,r)=>Math.min(t,r)),uA=binaryKernelFunc(t8,uE);function MirrorPad_mirrorPad(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{paddings:i,mode:o}=n;assertNotComplex(s,"mirrorPad");let l=i.map((t,r)=>t[0]+s.shape[r]+t[1]),u=i.map(t=>t[0]),p=i.map((t,r)=>t[0]+s.shape[r]),m=+("reflect"!==o),y=a.data.get(s.dataId).values,_=s.shape.length,w=computeStrides(s.shape),I=sizeFromShape(l),C=l.length,E=computeStrides(l),A=getArrayFromDType(s.dtype,I);for(let t=0;t<I;t++){let r=indexToLoc(t,C,E);for(let t=0;t<C;t++)r[t]<u[t]?r[t]=2*u[t]-r[t]-m:r[t]>=p[t]&&(r[t]=(p[t]-1)*2-r[t]+m);let a=locToIndex(r=r.map((t,r)=>t-u[r]),_,w);A[t]=y[a]}return{dataId:a.write(A,l,s.dtype),shape:l,dtype:s.dtype}}let u$=binaryKernelFunc("Mod",createSimpleBinaryKernelImpl((t,r)=>{let a=t%r;return t<0&&r<0||t>=0&&r>=0?a:(a+r)%r}));function Softmax_softmax(t){let{inputs:r,backend:a,attrs:n}=t,{logits:s}=r,{dim:i}=n,o=s.shape.length,l=i;if(-1===l&&(l=o-1),l!==o-1)throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${o} and dim was ${l}`);let u=parseAxisParam([l],s.shape),p=Max_max({inputs:{x:s},backend:a,attrs:{reductionIndices:u,keepDims:!1}}),m=expandShapeToKeepDim(p.shape,u),y=Reshape_reshape({inputs:{x:p},backend:a,attrs:{shape:m}}),_=us({inputs:{a:s,b:y},backend:a}),w=l7({inputs:{x:_},backend:a}),I=Sum_sum({inputs:{x:w},backend:a,attrs:{axis:u,keepDims:!1}}),C=Reshape_reshape({inputs:{x:I},backend:a,attrs:{shape:m}}),E=ut({inputs:{a:w,b:C},backend:a});return a.disposeIntermediateTensorInfo(p),a.disposeIntermediateTensorInfo(y),a.disposeIntermediateTensorInfo(_),a.disposeIntermediateTensorInfo(w),a.disposeIntermediateTensorInfo(I),a.disposeIntermediateTensorInfo(C),E}function Multinomial_multinomial(t){let{inputs:r,backend:a,attrs:n}=t,{logits:s}=r,{numSamples:i,seed:o,normalized:l}=n;assertNotComplex(s,"multinomial");let u=l?s:Softmax_softmax({inputs:{logits:s},backend:a,attrs:{dim:-1}}),p=u.shape[0],m=u.shape[1],y=a.data.get(u.dataId).values,_=[p,i],w=makeZerosTypedArray(sizeFromShape(_),"int32");for(let t=0;t<p;++t){let r=t*m,a=new Float32Array(m-1);a[0]=y[r];for(let t=1;t<a.length;++t)a[t]=a[t-1]+y[r+t];let n=sG.alea(o.toString()),s=t*i;for(let t=0;t<i;++t){let r=n();w[s+t]=a.length;for(let n=0;n<a.length;n++)if(r<a[n]){w[s+t]=n;break}}}return l||a.disposeIntermediateTensorInfo(u),a.makeTensorInfo(_,"int32",w)}function negImpl(t,r,a){return l2([],r,createScalarValue(-1,a),t,a)}function Neg_neg(t){let{inputs:r,backend:a}=t,{x:n}=r;assertNotComplex(n,"neg");let[s,i]=negImpl(a.data.get(n.dataId).values,n.shape,n.dtype);return a.makeTensorInfo(i,n.dtype,s)}let uR=nonMaxSuppressionV3Impl;function nonMaxSuppressionV3(t){let{inputs:r,backend:a,attrs:n}=t,{boxes:s,scores:i}=r,{maxOutputSize:o,iouThreshold:l,scoreThreshold:u}=n;assertNotComplex(s,"NonMaxSuppression");let{selectedIndices:p}=uR(a.data.get(s.dataId).values,a.data.get(i.dataId).values,o,l,u);return a.makeTensorInfo([p.length],"int32",new Int32Array(p))}let uF=nonMaxSuppressionV4Impl;function nonMaxSuppressionV4(t){let{inputs:r,backend:a,attrs:n}=t,{boxes:s,scores:i}=r,{maxOutputSize:o,iouThreshold:l,scoreThreshold:u,padToMaxOutputSize:p}=n;assertNotComplex(s,"NonMaxSuppressionPadded");let{selectedIndices:m,validOutputs:y}=uF(a.data.get(s.dataId).values,a.data.get(i.dataId).values,o,l,u,p);return[a.makeTensorInfo([m.length],"int32",new Int32Array(m)),a.makeTensorInfo([],"int32",new Int32Array([y]))]}let uD=nonMaxSuppressionV5Impl;function nonMaxSuppressionV5(t){let{inputs:r,backend:a,attrs:n}=t,{boxes:s,scores:i}=r,{maxOutputSize:o,iouThreshold:l,scoreThreshold:u,softNmsSigma:p}=n;assertNotComplex(s,"NonMaxSuppressionWithScore");let{selectedIndices:m,selectedScores:y}=uD(a.data.get(s.dataId).values,a.data.get(i.dataId).values,o,l,u,p);return[a.makeTensorInfo([m.length],"int32",new Int32Array(m)),a.makeTensorInfo([y.length],"float32",new Float32Array(y))]}let uP=createSimpleBinaryKernelImpl((t,r)=>+(t!==r)),uO=binaryKernelFunc(rt,uP,null,"bool");function OneHot_oneHot(t){let{inputs:r,backend:a,attrs:n}=t,{indices:s}=r,{dtype:i,depth:o,onValue:l,offValue:u}=n;assertNotComplex(s,"oneHot");let p=sizeFromShape(s.shape),m=new Float32Array(p*o);m.fill(u);let y=a.data.get(s.dataId).values;for(let t=0;t<p;++t)y[t]>=0&&y[t]<o&&(m[t*o+y[t]]=l);return a.makeTensorInfo([...s.shape,o],i,m)}function ZerosLike_zerosLike(t){let{inputs:r,backend:a}=t,{x:n}=r;if("string"===n.dtype)throw Error("zerosLike is not supported for string tensors");if("complex64"!==n.dtype)return Fill_fill({backend:a,attrs:{shape:n.shape,value:0,dtype:n.dtype}});{let t=Real_real({inputs:{input:n},backend:a}),r=ZerosLike_zerosLike({inputs:{x:t},backend:a}),s=Imag_imag({inputs:{input:n},backend:a}),i=ZerosLike_zerosLike({inputs:{x:s},backend:a}),o=Complex_complex({inputs:{real:r,imag:i},backend:a});return a.disposeIntermediateTensorInfo(t),a.disposeIntermediateTensorInfo(r),a.disposeIntermediateTensorInfo(s),a.disposeIntermediateTensorInfo(i),o}}function OnesLike_onesLike(t){let{inputs:r,backend:a}=t,{x:n}=r;if("string"===n.dtype)throw Error("onesLike is not supported for string tensors");if("complex64"!==n.dtype)return Fill_fill({backend:a,attrs:{shape:n.shape,value:1,dtype:n.dtype}});{let t=Real_real({inputs:{input:n},backend:a}),r=OnesLike_onesLike({inputs:{x:t},backend:a}),s=Imag_imag({inputs:{input:n},backend:a}),i=ZerosLike_zerosLike({inputs:{x:s},backend:a}),o=Complex_complex({inputs:{real:r,imag:i},backend:a});return a.disposeIntermediateTensorInfo(t),a.disposeIntermediateTensorInfo(r),a.disposeIntermediateTensorInfo(s),a.disposeIntermediateTensorInfo(i),o}}function pack(t){let{inputs:r,backend:a,attrs:n}=t,{axis:s}=n;if(1===r.length)return ExpandDims_expandDims({inputs:{input:r[0]},backend:a,attrs:{dim:s}});let i=r[0].shape,o=r[0].dtype;r.forEach(t=>{assertShapesMatch(i,t.shape,"All tensors passed to stack must have matching shapes"),assert(o===t.dtype,()=>"All tensors passed to stack must have matching dtypes")});let l=[],u=Concat_concat({inputs:r.map(t=>{let r=ExpandDims_expandDims({inputs:{input:t},backend:a,attrs:{dim:s}});return l.push(r),r}),backend:a,attrs:{axis:s}});return l.forEach(t=>a.disposeIntermediateTensorInfo(t)),u}let uM={kernelName:ru,backendName:"cpu",kernelFunc:function(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{paddings:i,constantValue:o}=n;assertNotComplex(s,"pad");let l=i.map((t,r)=>t[0]+s.shape[r]+t[1]),u=i.map(t=>t[0]),p=a.data.get(s.dataId).values,m=sizeFromShape(s.shape),y=s.shape.length,_=computeStrides(s.shape),w=sizeFromShape(l),I=l.length,C=computeStrides(l),E=getArrayFromDType(s.dtype,w);0!==o&&E.fill(o);for(let t=0;t<m;t++)E[locToIndex(indexToLoc(t,y,_).map((t,r)=>t+u[r]),I,C)]=p[t];return{dataId:a.write(E,l,s.dtype),shape:l,dtype:s.dtype}}},uL=binaryKernelFunc("Pow",createSimpleBinaryKernelImpl((t,r)=>Math.pow(t,r)));function prodImpl(t,r,a,n){let[s,i]=computeOutAndReduceShapes(t,n),o=upcastType(r,"int32"),l=makeZerosTypedArray(sizeFromShape(s),o),u=sizeFromShape(i);for(let t=0;t<l.length;++t){let r=t*u,n=1;for(let t=0;t<u;++t)n*=a[r+t];l[t]=n}return{outVals:l,outShape:s,outDtype:o}}function Prod_prod(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{axis:i,keepDims:o}=n;assertNotComplex(s,"prod");let l=s.shape.length,u=parseAxisParam(i,s.shape),p=getAxesPermutation(u,l),m=u,y=s,_=[];null!=p&&(_.push(y=Transpose_transpose({inputs:{x:s},backend:a,attrs:{perm:p}})),m=getInnerMostAxes(m.length,l));let w=a.data.get(y.dataId).values,{outVals:I,outShape:C,outDtype:E}=prodImpl(y.shape,y.dtype,w,m),A=C;return o&&(A=expandShapeToKeepDim(C,u)),_.forEach(t=>a.disposeIntermediateTensorInfo(t)),a.makeTensorInfo(A,E,I)}function validateIndices(t,r,a){t.forEach((t,n)=>{if(t<0||t>=a){let s=indexToLoc(n,r.length,computeStrides(r)).join(",");throw Error(`indices[${s}] = ${t} is not in [0, ${a})`)}})}function validateSplits(t,r){for(let a=0;a<t.length;++a){let n=t[a],s=a===t.length-1?r:t[a+1].length;if(0===n.length)throw Error("Ragged splits may not be empty");if(n[0]<0)throw Error("Ragged splits must be non-negative");if(n[n.length-1]>s)throw Error("Ragged splits must not point past values");for(let t=1;t<n.length;++t)if(n[t-1]>n[t])throw Error("Ragged splits must be sorted in ascending order")}}function makeSplits(t,r,a,n){let s=[],i=0,o=Array(r.length-1+a.length).fill(null).map(()=>[0]);validateSplits(a,n);let l=1;for(let t=0;t<r.length-1;++t){l*=r[t];let a=r[t+1];for(let r=1;r<l+1;++r)o[t].push(r*a)}for(let n=0;n<t.length;++n){let l=t[n],u=t[n]+1;for(let t=0;t<a.length;++t){let n=a[t],s=t+r.length-1;if(s>=0){let t=o[s],r=t[t.length-1]-n[l];for(let t=l;t<u;++t)o[s].push(n[t+1]+r)}l=n[l],u=n[u]}u!==l&&(s.push([l,u]),i+=u-l)}return{outSplits:o,valueSlices:s,numValues:i}}function getSplits(t){let r=[];for(let a=0;a<t.length;++a){let n=getArrayFromDType("int32",t[a].length);r.push(n),t[a].forEach((t,r)=>n[r]=t)}return r}function computeFlatOuterDims(t,r){let a=t.slice(0,r);for(;a.length<r;)a.push(1);for(let n=r;n<t.length;n++)a[r-1]*=t[n];return a}function writeValueSlices(t,r,a,n,s,i){let o=computeFlatOuterDims(r,2)[1],l=computeFlatOuterDims(i,2)[1],u=0;for(let r of a)for(let a=r[0];a<r[1];++a){for(let r=0;r<n;++r)s[u*l+r]=t[a*o+r];++u}}function getValues(t,r,a,n,s){let i=r.slice();i[0]=s;let o=getArrayFromDType(a,sizeFromShape(i)),l=t.length,u=0===l?0:l/r[0];return writeValueSlices(t,r,n,u,o,i),[o,i]}function raggedGatherImpl(t,r,a,n,s,i,o,l){if(0===t.length)throw Error("paramsNestedSplits must be non empty");if(0===r[0].length)throw Error("Split tensors must not be scalars");if(validateIndices(i,o,r[0][0]-1),0===n.length)throw Error("params.rank must be nonzero");let{outSplits:u,valueSlices:p,numValues:m}=makeSplits(i,o,t,n[0]),y=getSplits(u),_=getValues(a,n,s,p,m);return[y,_[0],_[1]]}function RaggedGather_raggedGather(t){let{inputs:r,backend:a,attrs:n}=t,{paramsNestedSplits:s,paramsDenseValues:i,indices:o}=r,{outputRaggedRank:l}=n,u=s.map(t=>a.data.get(t.dataId).values),p=s.map(t=>t.shape),m=a.data.get(i.dataId).values,y=a.data.get(o.dataId).values,[_,w,I]=raggedGatherImpl(u,p,m,i.shape,i.dtype,y,o.shape,l),C=_.map(t=>a.makeTensorInfo([t.length],"int32",t)),E=a.makeTensorInfo(I,i.dtype,w);return C.concat([E])}function raggedRangeImpl(t,r,a,n,s,i,o){if(r.length>1)throw Error("starts must be a scalar or vector");if(s.length>1)throw Error("limits must be a scalar or vector");if(o.length>1)throw Error("deltas must be a scalar or vector");let l=0===r.length,u=0===s.length,p=0===o.length,m=[];l||m.push(r[0]),u||m.push(s[0]),p||m.push(o[0]);for(let t=1;t<m.length;++t)if(m[t]!==m[t-1])throw Error("starts, limits, and deltas must have the same shape");let y=0===m.length?1:m[0],_=getArrayFromDType("int32",y+1);_[0]=0;for(let r=0;r<y;++r){let a,s=l?t[0]:t[r],o=u?n[0]:n[r],m=p?i[0]:i[r];if(0===m)throw Error("Requires delta != 0");if(m>0&&o<s||m<0&&o>s)a=0;else if((a=Math.ceil(Math.abs((o-s)/m)))>0x7fffffff)throw Error("Requires ((limit - start) / delta) <= 2147483647");_[r+1]=_[r]+a}let w=getArrayFromDType(a,_[y]),I=0;for(let r=0;r<y;++r){let a=_[r+1]-_[r],n=l?t[0]:t[r],s=p?i[0]:i[r];for(let t=0;t<a;++t)w[I++]=n,n+=s}return[_,w]}function RaggedRange_raggedRange(t){let{inputs:r,backend:a}=t,{starts:n,limits:s,deltas:i}=r,o=a.data.get(n.dataId).values,l=a.data.get(s.dataId).values,u=a.data.get(i.dataId).values,[p,m]=raggedRangeImpl(o,n.shape,n.dtype,l,s.shape,u,i.shape);return[a.makeTensorInfo([p.length],"int32",p),a.makeTensorInfo([m.length],n.dtype,m)]}var uz=et;let RaggedTensorToTensorOp=class RaggedTensorToTensorOp{constructor(t,r,a,n,s,i,o,l,u,p){this.shape=t,this.shapeShape=r,this.values=a,this.valuesShape=n,this.valuesDType=s,this.defaultValue=i,this.defaultValueShape=o,this.rowPartitionValues=l,this.rowPartitionValuesShapes=u,this.rowPartitionTypes=getRowPartitionTypesHelper(p),this.raggedRank=getRaggedRank(this.rowPartitionTypes)}getRowPartitionTypeByDimension(t){return this.rowPartitionTypes[0]===uz.FIRST_DIM_SIZE?this.rowPartitionTypes[t+1]:this.rowPartitionTypes[t]}getRowPartitionTensor(t){return this.rowPartitionTypes[0]===uz.FIRST_DIM_SIZE?this.rowPartitionValues[t+1]:this.rowPartitionValues[t]}getMaxWidth(t){let r=this.getRowPartitionTensor(t-1);switch(this.getRowPartitionTypeByDimension(t-1)){case uz.VALUE_ROWIDS:return RaggedTensorToTensorOp.getMaxWidthValueRowID(r);case uz.ROW_SPLITS:return RaggedTensorToTensorOp.getMaxWidthRowSplit(r);default:throw Error(`Cannot handle partition type ${uz[this.getRowPartitionTypeByDimension(t-1)]}`)}}static getMaxWidthRowSplit(t){let r=t.length;if(0===r||1===r)return 0;let a=0;for(let n=0;n<r-1;++n){let r=t[n+1]-t[n];r>a&&(a=r)}return a}static getMaxWidthValueRowID(t){let r=t.length;if(0===r)return 0;let a=0,n=t[0],s=0;for(let i=1;i<r;++i){let r=t[i];r!==n&&(n=r,s=Math.max(i-a,s),a=i)}return Math.max(r-a,s)}tensorShapeFromTensor(t,r,a=!0){if(0===r.length){if(-1===t[0])return[];throw Error("The only valid scalar shape tensor is the fully unknown shape specified as -1.")}return makeShape(t,a)}calculateOutputSize(t){let r=this.valuesShape;validateDefaultValueShape(this.defaultValueShape,r);let a=this.tensorShapeFromTensor(this.shape,this.shapeShape),n=combineRaggedTensorToTensorShapes(this.raggedRank,a,r);n[0]<0&&(n[0]=t);for(let t=1;t<=this.raggedRank;++t)n[t]<0&&(n[t]=this.getMaxWidth(t));return n}calculateFirstParentOutputIndex(t,r,a){let n=Math.min(t,a),s=[],i=0;for(let t=0;t<n;++t,i+=r)s.push(i);for(let r=n;r<t;++r)s.push(-1);return assert(s.length===t,()=>"Final length of result must be equal to firstDimension."),s}calculateOutputIndexRowSplit(t,r,a,n){let s=t.length,i=[];for(let o=0;o<s-1;++o){let s=t[o+1]-t[o],l=Math.min(n,s),u=r[o];-1===u&&(l=0);for(let t=0;t<l;++t)i.push(u),u+=a;for(let t=0;t<s-l;++t)i.push(-1)}if(s>0&&i.length!==t[s-1])throw Error("Invalid row split size.");return i}calculateOutputIndexValueRowID(t,r,a,n){let s=t.length,i=[];if(0===s)return[];let o=0,l=t[0];if(l>=r.length)throw Error(`Got currentValueRowId=${l}, which is not less than ${r.length}`);let u=r[l];i.push(u);for(let p=1;p<s;++p){let s=t[p];if(s===l)u>=0&&(++o<n?u+=a:u=-1);else{if(o=0,l=s,s>=r.length)throw Error(`Got nextValueRowId=${s} which is not less than ${r.length}`);u=r[s]}i.push(u)}if(i.length!==t.length)throw Error("Invalid row ids.");return i}calculateOutputIndex(t,r,a,n){let s=this.getRowPartitionTensor(t),i=this.getRowPartitionTypeByDimension(t);switch(i){case uz.VALUE_ROWIDS:return this.calculateOutputIndexValueRowID(s,r,a,n);case uz.ROW_SPLITS:if(s.length-1>r.length)throw Error(`Row partition size is greater than output size: ${s.length-1} > ${r.length}`);return this.calculateOutputIndexRowSplit(s,r,a,n);default:throw Error(`Unsupported partition type: ${uz[i]}`)}}getFirstDimensionSize(){let t=this.rowPartitionValues[0];if(0===this.rowPartitionTypes.length)throw Error("No row_partition_types given.");let r=this.rowPartitionTypes[0];switch(r){case uz.FIRST_DIM_SIZE:return t[0];case uz.VALUE_ROWIDS:throw Error("Cannot handle VALUE_ROWIDS in first dimension.");case uz.ROW_SPLITS:return this.rowPartitionValuesShapes[0][0]-1;default:throw Error(`Cannot handle type ${uz[r]}`)}}compute(){if(this.rowPartitionValues[0].length<=0)throw Error("Invalid first partition input. Tensor requires at least one element.");let t=this.getFirstDimensionSize(),r=this.calculateOutputSize(t),a=Array(this.raggedRank+1);a[a.length-1]=1;for(let t=a.length-2;t>=0;--t)a[t]=a[t+1]*r[t+1];let n=makeShape(r,!1),s=getArrayFromDType(this.valuesDType,sizeFromShape(n));if(a[0]*r[0]>0){let i=this.calculateFirstParentOutputIndex(t,a[0],r[0]);for(let t=1;t<=this.raggedRank;++t)i=this.calculateOutputIndex(t-1,i,a[t],r[t]);this.setOutput(this.raggedRank,i,s,n)}return[n,s]}setOutput(t,r,a,n){if(0===a.length)return;let s=this.values,i=n.slice(),o=sizeFromShape(i=i.slice(t+1)),l=r.length,u=this.defaultValue;if(u.length!==o&&1!==u.length){let t=this.defaultValueShape;globals_tidy(()=>{u=nd(a6(u,t),i).dataSync()})}let p=0,m=0,y=0;for(let t=0;t<=l;++t){let n=t<l?r[t]:-1;if(n===y){++y;continue}if(m<y){let t=s.subarray(p*o);copyArray(a.subarray(m*o),t,(y-m)*o)}if(t>=l&&(n=Math.floor(a.length/o)),n>y)if(1===this.defaultValue.length)a.subarray(y*o,n*o).fill(this.defaultValue[0]),y=n;else for(;n>y;)copyArray(a.slice(y*o),u,o),++y;n<0?(p=t+1,m=y):(p=t,y=(m=y)+1)}}};function copyArray(t,r,a){for(let n=0;n<a;n++)t[n]=r[n]}function makeShape(t,r){let a=[];for(let n of t){if(n<0){if(!r)throw Error(`Dimension ${n} must be >= 0`);if(n<-1)throw Error(`Dimension ${n} must be >= -1`);n=-1}a.push(n)}return a}function raggedTensorToTensorImpl(t,r,a,n,s,i,o,l,u,p){return new RaggedTensorToTensorOp(t,r,a,n,s,i,o,l,u,p).compute()}function RaggedTensorToTensor_raggedTensorToTensor(t){let{inputs:r,backend:a,attrs:n}=t,{shape:s,values:i,defaultValue:o,rowPartitionTensors:l}=r,{rowPartitionTypes:u}=n,p=a.data.get(s.dataId).values,m=a.data.get(i.dataId).values,y=a.data.get(o.dataId).values,_=l.map(t=>a.data.get(t.dataId).values),w=l.map(t=>t.shape),[I,C]=raggedTensorToTensorImpl(p,s.shape,m,i.shape,i.dtype,y,o.shape,_,w,u);return a.makeTensorInfo(I,i.dtype,C)}function rangeImpl(t,r,a,n){let s=t===r,i=t<r&&a<0,o=r<t&&a>1;if(s||i||o)return makeZerosTypedArray(0,n);let l=makeZerosTypedArray(Math.abs(Math.ceil((r-t)/a)),n);r<t&&1===a&&(a=-1),l[0]=t;for(let t=1;t<l.length;t++)l[t]=l[t-1]+a;return l}function Range_range(t){let{backend:r,attrs:a}=t,{start:n,stop:s,dtype:i,step:o}=a,l=rangeImpl(n,s,o,i);return r.makeTensorInfo([l.length],i,l)}let uV=unaryKernelFunc(ry,t=>1/t);function ResizeBilinear_resizeBilinear(t){let{inputs:r,backend:a,attrs:n}=t,{images:s}=r,{alignCorners:i,halfPixelCenters:o,size:l}=n;assertNotComplex(s,"resizeBilinear");let u=computeStrides(s.shape),[p,m]=l,[y,_,w,I]=s.shape,C=a.data.get(s.dataId).values,E=new Float32Array(sizeFromShape([y,p,m,I])),A=[i&&p>1?_-1:_,i&&m>1?w-1:w],$=[i&&p>1?p-1:p,i&&m>1?m-1:m],F=0,D=A[0]/$[0],P=A[1]/$[1];for(let t=0;t<y;t++)for(let r=0;r<p;r++){let a,n=Math.max(0,Math.floor(a=o?D*(r+.5)-.5:D*r)),s=a-n,i=Math.min(_-1,Math.ceil(a)),l=t*u[0]+n*u[1],p=t*u[0]+i*u[1];for(let t=0;t<m;t++){let r,a=Math.max(0,Math.floor(r=o?P*(t+.5)-.5:P*t)),n=r-a,i=Math.min(w-1,Math.ceil(r)),m=l+a*u[2],y=p+a*u[2],_=l+i*u[2],A=p+i*u[2];for(let t=0;t<I;t++){let r=C[m+t],a=C[y+t],i=C[_+t],o=C[A+t],l=r+(i-r)*n,u=l+(a+(o-a)*n-l)*s;E[F++]=u}}}return a.makeTensorInfo([y,p,m,I],"float32",E)}function resizeBilinearGrad(t){let{inputs:r,backend:a,attrs:n}=t,{images:s,dy:i}=r,{alignCorners:o}=n;assertNotComplex([i,s],"resizeBilinearGrad");let l=computeStrides(s.shape),[u,p,m,y]=s.shape,[,_,w]=i.shape,I=new Float32Array(u*p*m*y),C=[o&&_>1?p-1:p,o&&w>1?m-1:m],E=[o&&_>1?_-1:_,o&&w>1?w-1:w],A=C[0]/E[0],$=C[1]/E[1],F=a.data.get(i.dataId).values,D=0;for(let t=0;t<u;t++){let r=t*l[0];for(let t=0;t<_;t++){let a=t*A,n=Math.floor(a),s=Math.min(Math.ceil(a),p-1),i=r+n*l[1],o=r+s*l[1],u=a-n,_=1-u;for(let t=0;t<w;t++){let r=t*$,a=Math.floor(r),n=Math.min(Math.ceil(r),m-1),s=r-a,p=1-s,w=i+a*l[2],C=i+n*l[2],E=o+a*l[2],A=o+n*l[2],P=_*p,L=_*s,z=u*p,B=u*s;for(let t=0;t<y;t++){let r=F[D++];I[w+t]+=r*P,I[C+t]+=r*L,I[E+t]+=r*z,I[A+t]+=r*B}}}}return a.makeTensorInfo([u,m,p,y],"float32",I)}function ResizeNearestNeighbor_resizeNearestNeighbor(t){let{inputs:r,backend:a,attrs:n}=t,{images:s}=r,{alignCorners:i,halfPixelCenters:o,size:l}=n;assertNotComplex(s,"resizeNearestNeighbor");let u=computeStrides(s.shape),[p,m]=l,[y,_,w,I]=s.shape,C=a.data.get(s.dataId).values,E=new Float32Array(y*p*m*I),A=[i&&p>1?_-1:_,i&&m>1?w-1:w],$=[i&&p>1?p-1:p,i&&m>1?m-1:m],F=A[0]/$[0],D=A[1]/$[1],P=0;for(let t=0;t<y;t++){let r=t*u[0];for(let t=0;t<p;t++){let a=o?F*(t+.5):F*t,n=Math.min(_-1,i?Math.round(a):Math.floor(a));o&&(n=Math.max(0,n));let s=r+n*u[1];for(let t=0;t<m;t++){let r=o?D*(t+.5):D*t,a=Math.min(w-1,i?Math.round(r):Math.floor(r));o&&(a=Math.max(0,a));let n=s+a*u[2];for(let t=0;t<I;t++){let r=C[n+t];E[P++]=r}}}}return a.makeTensorInfo([y,p,m,I],s.dtype,E)}function resizeNearestNeighborGrad(t){let{inputs:r,backend:a,attrs:n}=t,{images:s,dy:i}=r,{alignCorners:o}=n;assertNotComplex([i,s],"resizeNearestNeighborGrad");let l=computeStrides(s.shape),u=computeStrides(i.shape),[p,m,y,_]=s.shape,[,w,I]=i.shape,C=new Float32Array(p*m*y*_),E=a.data.get(i.dataId).values,A=[o&&w>1?m-1:m,o&&I>1?y-1:y],$=[o&&w>1?w-1:w,o&&I>1?I-1:I],F=A[0]/$[0],D=A[1]/$[1],P=1/F,L=1/D,z=2*Math.ceil(P)+2,B=2*Math.ceil(L)+2;for(let t=0;t<p;t++){let r=t*l[0];for(let t=0;t<m;t++){let a=r+t*l[1],n=Math.floor(Math.floor(t*P)-z/2);for(let s=0;s<y;s++){let i=a+s*l[2],p=Math.floor(Math.floor(s*L)-B/2);for(let a=0;a<_;a++){let l=0;for(let i=0;i<z;i++){let _=i+n;if(_<0||_>=w)continue;let C=r+_*u[1],A=_*F;if(t===Math.min(m-1,o?Math.round(A):Math.floor(A)))for(let t=0;t<B;t++){let r=t+p;if(r<0||r>=I)continue;let n=C+r*u[2],i=r*D;s===Math.min(y-1,o?Math.round(i):Math.floor(i))&&(l+=E[n+a])}}C[i+a]=l}}}}return a.makeTensorInfo(s.shape,s.dtype,C)}function Reverse_reverse(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{dims:i}=n;assertNotComplex(s,"reverse");let o=s.shape.length,l=parseAxisParam(i,s.shape);if(0===o)return Identity_identity({inputs:{x:s},backend:a});let u=new TensorBuffer(s.shape,s.dtype),p=a.bufferSync(s);for(let t=0;t<u.size;t++){let r=u.indexToLoc(t),a=r.slice();l.forEach(t=>a[t]=s.shape[t]-1-a[t]),u.set(p.get(...a),...r)}return a.makeTensorInfo(u.shape,u.dtype,u.values)}let uB=unaryKernelFunc(rN,t=>{let r=Math.floor(t);return t-r<.5?Math.floor(t):t-r>.5?Math.ceil(t):r%2==0?r:r+1}),uW=createSimpleUnaryImpl(t=>1/Math.sqrt(t)),uU=unaryKernelFuncFromImpl(rC,uW);function scatterImpl(t,r,a,n,s,i,o,l,u,p){let m=t.values,y=r.values;if(0===n)return buffer(a,r.dtype);let _=u instanceof TensorBuffer?u:buffer([n/s,s],r.dtype);"string"==typeof u||"number"==typeof u?_.values.fill(u):"boolean"==typeof u&&_.values.fill(+u);for(let t=0;t<i;t++){let i=[],u=0;for(let r=0;r<o;r++){let a=m[t*o+r];i.push(a),u+=a*l[r]}if(u<0||u>=n/s)throw Error(`Invalid indices: ${i} does not index into ${a}`);for(let a=0;a<s;a++)p?_.values[u*s+a]+=y[t*s+a]:_.values[u*s+a]=0===r.rank?y[0]:y[t*s+a]}return _}function scatterNd(t){let{inputs:r,backend:a,attrs:n}=t,{indices:s,updates:i}=r,{shape:o}=n,{sliceRank:l,numUpdates:u,sliceSize:p,strides:m,outputSize:y}=calculateShapes(i,s,o),_=scatterImpl(a.bufferSync(s),a.bufferSync(i),o,y,p,u,l,m,0,!0);return a.makeTensorInfo(o,_.dtype,_.values)}function SearchSorted_impl_lowerBound(t,r){let a=0,n=t.length,s=0;for(;a<n;)t[s=Math.floor((a+n)/2)]<r?a=s+1:n=s;return n}function SearchSorted_impl_upperBound(t,r){let a=0,n=t.length,s=0;for(;a<n;)t[s=Math.floor((a+n)/2)]<=r?a=s+1:n=s;return n}function searchSortedImpl(t,r,a,n,s,i){let o=getArrayFromDType("int32",a*s);for(let l=0;l<a;++l){let a=t.slice(l*n,(l+1)*n),u=l*s;for(let t=0;t<s;++t)o[u+t]="left"===i?SearchSorted_impl_lowerBound(a,r[t+u]):SearchSorted_impl_upperBound(a,r[t+u])}return o}function SearchSorted_searchSorted(t){let{inputs:r,backend:a,attrs:n}=t,{sortedSequence:s,values:i}=r,{side:o}=n,l=searchSortedImpl(a.data.get(s.dataId).values,a.data.get(i.dataId).values,s.shape[0],s.shape[1],i.shape[1],o);return a.makeTensorInfo(i.shape,"int32",l)}function Select_select(t){let{inputs:r,backend:a}=t,{condition:n,t:s,e:i}=r;assertNotComplex([n,s,i],"select");let o=n.shape.length,l=a.data.get(n.dataId).values,u=a.data.get(s.dataId).values,p=a.data.get(i.dataId).values,m=upcastType(s.dtype,i.dtype),y=makeZerosTypedArray(sizeFromShape(s.shape),m),_=0,w=0===o||o>1||1===s.shape.length?1:sizeFromShape(s.shape.slice(1));for(let t=0;t<l.length;t++)for(let r=0;r<w;r++)1===l[t]?y[_++]=u[t]:y[_++]=p[t];return a.makeTensorInfo(s.shape,m,y)}let uG=unaryKernelFunc(rF,t=>t>=0?ok*t:oT*(Math.exp(t)-1)),uj=unaryKernelFunc(rO,t=>t<0?-1:+(t>0)),uK=unaryKernelFunc("Sin",t=>Math.sin(t)),uH=unaryKernelFunc(rP,t=>Math.sinh(t)),uq=Math.log(11920928955078125e-23)+2,uX=unaryKernelFunc(rL,t=>{let r=Math.exp(t);return t<uq?r:t>-uq?t:Math.log(1+r)});function SpaceToBatchND_spaceToBatchND(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{blockShape:i,paddings:o}=n;assertNotComplex([s],"spaceToBatchND");let l=sizeFromShape(i),u=[[0,0]];u.push(...o);for(let t=1+i.length;t<s.shape.length;++t)u.push([0,0]);let p=uM.kernelFunc({inputs:{x:s},backend:a,attrs:{paddings:u,constantValue:0}}),m=getReshaped(p.shape,i,l,!1),y=getPermuted(m.length,i.length,!1),_=getReshapedPermuted(p.shape,i,l,!1),w=Reshape_reshape({inputs:{x:p},backend:a,attrs:{shape:m}}),I=Transpose_transpose({inputs:{x:w},backend:a,attrs:{perm:y}}),C=Reshape_reshape({inputs:{x:I},backend:a,attrs:{shape:_}});return a.disposeIntermediateTensorInfo(p),a.disposeIntermediateTensorInfo(w),a.disposeIntermediateTensorInfo(I),C}function sparseFillEmptyRowsImpl(t,r,a,n,s,i,o){let l=r[0],u=i[0],p=Array(u),m=Array(l),y=r[1];if(0===u){if(0!==l)throw Error(getSparseFillEmptyRowsIndicesDenseShapeMismatch(l));return[getArrayFromDType(a,0),[0,y],getArrayFromDType(s,0),p,m]}let _=!0,w=0,I=Array(u).fill(0);for(let r=0;r<l;++r){let a=t[r*y];if(a<0)throw Error(getSparseFillEmptyRowsNegativeIndexErrorMessage(r,a));if(a>=u)throw Error(getSparseFillEmptyRowsOutOfRangeIndexErrorMessage(r,a,u));++I[a],_=_&&a>=w,w=a}let C=!0;for(let t=0;t<u;++t){let r=0===I[t];p[t]=r,C=C&&!r,I[t]=Math.max(I[t],1),t>0&&(I[t]+=I[t-1])}if(C&&_){for(let t=0;t<l;++t)m[t]=t;return[t,[l,y],n,p,m]}{let r=I[u-1],i=getArrayFromDType(a,r*y),_=getArrayFromDType(s,r),w=Array(u).fill(0);for(let r=0;r<l;++r){let a=t[r*y],s=w[a],o=(0===a?0:I[a-1])+s;w[a]++;for(let a=0;a<y;++a)i[o*y+a]=t[r*y+a];_[o]=n[r],m[r]=o}for(let t=0;t<u;++t)if(0===w[t]){let r=0===t?0:I[t-1];i[r*y+0]=t;for(let t=1;t<y;++t)i[r*y+t]=0;_[r]=o}return[i,[r,y],_,p,m]}}function SparseFillEmptyRows_sparseFillEmptyRows(t){let{inputs:r,backend:a}=t,{indices:n,values:s,denseShape:i,defaultValue:o}=r;if(1!==i.shape.length)throw Error(`Dense shape must be a vector, saw:
        ${i.shape}`);if(2!==n.shape.length)throw Error(`Indices must be a matrix, saw:
        ${n.shape}`);if(1!==s.shape.length)throw Error(`Values must be a vector, saw:
        ${s.shape}`);if(0!==o.shape.length)throw Error(`Default value must be a scalar, saw:
        ${o.shape}`);let l=a.data.get(n.dataId).values,u=a.data.get(s.dataId).values,p=a.data.get(i.dataId).values,m=a.data.get(o.dataId).values[0],[y,_,w,I,C]=sparseFillEmptyRowsImpl(l,n.shape,n.dtype,u,s.dtype,p,m);return[a.makeTensorInfo(_,n.dtype,y),a.makeTensorInfo([_[0]],s.dtype,w),a.makeTensorInfo([I.length],"bool",new Uint8Array(I.map(t=>Number(t)))),a.makeTensorInfo([C.length],n.dtype,new Int32Array(C))]}function sparseReshapeImpl(t,r,a,n,s){let i=sizeFromShape(n),o=r[0],l=s.length,u=[],p=1,m=-1;for(let t=0;t<l;++t){let r=s[t];if(-1===r){if(-1!==m)throw Error(getSparseReshapeMultipleNegativeOneOutputDimErrorMessage(m,t));m=t,u.push(1)}else{if(r<0)throw Error(getSparseReshapeNegativeOutputDimErrorMessage(t,r));p*=r,u.push(r)}}if(-1!==m){if(p<=0)throw Error(getSparseReshapeEmptyTensorZeroOutputDimErrorMessage());let t=Math.trunc(i/p);if(p*t!==i)throw Error(getSparseReshapeInputOutputMultipleErrorMessage(n,u));u[m]=t}if(sizeFromShape(u)!==i)throw Error(getSparseReshapeInputOutputMismatchErrorMessage(n,u));let y=n.length,_=[];if(y>0){_[y-1]=1;for(let t=y-2;t>=0;--t)_[t]=_[t+1]*n[t+1]}let w=[];if(l>0){w[l-1]=1;for(let t=l-2;t>=0;--t)w[t]=w[t+1]*u[t+1]}let I=getArrayFromDType(a,o*l);for(let r=0;r<o;++r){let a=0;for(let n=0;n<y;++n)a+=t[r*y+n]*_[n];for(let t=0;t<l;++t)I[r*l+t]=Math.trunc(a/w[t]),a%=w[t]}return[I,[o,l],u]}function SparseReshape_sparseReshape(t){let{inputs:r,backend:a}=t,{inputIndices:n,inputShape:s,newShape:i}=r;if(2!==n.shape.length)throw Error(`Input indices should be a matrix but received shape
        ${n.shape}`);if(1!==s.shape.length)throw Error(`Input shape should be a vector but received shape
        ${s.shape}`);if(1!==i.shape.length)throw Error(`Target shape should be a vector but received shape ${i.shape}`);let o=Array.from(a.data.get(s.dataId).values),l=a.data.get(n.dataId).values,u=Array.from(a.data.get(i.dataId).values),[p,m,y]=sparseReshapeImpl(l,n.shape,n.dtype,o,u);return[a.makeTensorInfo(m,n.dtype,p),a.makeTensorInfo([y.length],i.dtype,new Int32Array(y))]}function sparseSegmentReductionImpl(t,r,a,n,s,i=!1,o=0){let l=n.length,u=[r[0],t.length/r[0]],p=u[1],m=l>0?s[l-1]+1:0;if(m<0)throw Error(getSparseSegmentReductionNegativeSegmentIdsErrorMessage());let y=r.slice();y[0]=m;let _=getArrayFromDType(a,y.reduce((t,r)=>t*r,1));if(0===l)return m>0&&_.fill(o),[_,y];if(m<=0)throw Error(getSparseSegmentReductionNegativeSegmentIdsErrorMessage());let w=0,I=1,C=0,E=s[0];for(;;){let r=0;if(I<l){if(E===(r=s[I])){++I;continue}if(E>=r)throw Error(getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage())}if(E<0||E>=m)throw Error(getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage(E,m));E>C&&_.fill(o,C*p,E*p);for(let r=w;r<I;++r){let a=n[r];if(a<0||a>=u[0])throw Error(getSparseSegmentReductionIndicesOutOfRangeErrorMessage(r,n[r],u[0]));for(let r=0;r<p;r++)_[E*p+r]+=t[a*p+r]}if(i)for(let t=0;t<p;t++)_[E*p+t]/=I-w;if(w=I,++I,C=E+1,E=r,I>l)break}return C<m&&_.fill(o,C*p,m*p),[_,y]}function SparseSegmentMean_sparseSegmentMean(t){let{inputs:r,backend:a}=t,{data:n,indices:s,segmentIds:i}=r;if(n.shape.length<1)throw Error("Data should be at least 1 dimensional but received scalar");if(1!==s.shape.length)throw Error(`Indices should be a vector but received shape
          ${s.shape}`);if(1!==i.shape.length)throw Error(`Segment ids should be a vector but received shape
          ${i.shape}`);if(s.shape[0]!==i.shape[0])throw Error("segmentIds and indices should have same size.");let o=a.data.get(n.dataId).values,l=a.data.get(s.dataId).values,u=a.data.get(i.dataId).values,[p,m]=sparseSegmentReductionImpl(o,n.shape,n.dtype,l,u,!0);return a.makeTensorInfo(m,n.dtype,p)}function SparseSegmentSum_sparseSegmentSum(t){let{inputs:r,backend:a}=t,{data:n,indices:s,segmentIds:i}=r;if(n.shape.length<1)throw Error("Data should be at least 1 dimensional but received scalar");if(1!==s.shape.length)throw Error(`Indices should be a vector but received shape
         ${s.shape}`);if(1!==i.shape.length)throw Error(`Segment ids should be a vector but received shape
         ${i.shape}`);if(s.shape[0]!==i.shape[0])throw Error("segmentIds and indices should have same size.");let o=a.data.get(n.dataId).values,l=a.data.get(s.dataId).values,u=a.data.get(i.dataId).values,[p,m]=sparseSegmentReductionImpl(o,n.shape,n.dtype,l,u);return a.makeTensorInfo(m,n.dtype,p)}function SparseToDense_sparseToDense(t){let r,{inputs:a,backend:n,attrs:s}=t,{sparseIndices:i,sparseValues:o,defaultValue:l}=a,{outputShape:u}=s,{sliceRank:p,numUpdates:m,sliceSize:y,strides:_,outputSize:w}=calculateShapes(o,i,u),I=n.bufferSync(i);switch(o.dtype){case"bool":r=scatterImpl(I,n.bufferSync(o),u,w,y,m,p,_,!!n.data.get(l.dataId).values[0],!1);break;case"float32":case"int32":r=scatterImpl(I,n.bufferSync(o),u,w,y,m,p,_,n.data.get(l.dataId).values[0],!1);break;case"string":r=scatterImpl(I,n.bufferSync(o),u,w,y,m,p,_,decodeString(n.data.get(l.dataId).values[0]),!1);break;default:throw Error(`Unsupported type ${o.dtype}`)}return n.makeTensorInfo(u,r.dtype,r.values)}function splitV(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{numOrSizeSplits:i,axis:o}=n,l=parseAxisParam(o,s.shape)[0],u=prepareSplitSize(s,i,l),p=Array(s.shape.length).fill(0),m=s.shape.slice();return u.map(t=>{let r=[...m];r[l]=t;let n=Slice_slice({inputs:{x:s},backend:a,attrs:{begin:p,size:r}});return p[l]+=t,n})}let uY=createSimpleUnaryImpl(t=>Math.sqrt(t)),uZ=unaryKernelFunc(rz,t=>Math.sqrt(t)),uJ=binaryKernelFunc(rq,createSimpleBinaryKernelImpl((t,r)=>{let a=t-r;return a*a})),uQ=createSimpleUnaryImpl((t,r)=>{let{pattern:a,replaceGlobal:n,rewrite:s}=r;return t.replace(new RegExp(a,n?"g":""),s)}),u0=unaryKernelFuncFromImpl(rY,uQ),u1=unaryKernelFunc(ae,(t,r)=>isNaN(t)?NaN:t>0?1:r.alpha);function stridedSliceImpl(t,r,a,n){let s=buffer(t,r.dtype);for(let t=0;t<s.size;t++){let i=s.indexToLoc(t),o=Array(i.length);for(let t=0;t<o.length;t++)o[t]=i[t]*a[t]+n[t];s.set(r.get(...o),...i)}return s}function StridedSlice_stridedSlice(t){let r,{inputs:a,backend:n,attrs:s}=t,{x:i}=a,{begin:o,end:l,strides:u,beginMask:p,endMask:m,ellipsisMask:y,newAxisMask:_,shrinkAxisMask:w}=s;assertNotComplex(i,"stridedSlice");let{finalShapeSparse:I,finalShape:C,isIdentity:E,sliceDim0:A,isSimpleSlice:$,begin:F,end:D,strides:P}=sliceInfo(i.shape,o,l,u,p,m,y,_,w);if(E)r=Reshape_reshape({inputs:{x:i},backend:n,attrs:{shape:C}});else if(A||$){assert(i.shape.length>=1,()=>`Input must have rank at least 1, got: ${i.shape.length}`);let t=computeOutShape(F,D,P),a=Slice_slice({inputs:{x:i},backend:n,attrs:{begin:F,size:t}});r=Reshape_reshape({inputs:{x:a},backend:n,attrs:{shape:C}}),n.disposeIntermediateTensorInfo(a)}else{let t=stridedSliceImpl(I,n.bufferSync(i),P,F);r=n.makeTensorInfo(C,t.dtype,t.values)}return r}let StringNGramsOp=class StringNGramsOp{constructor(t,r,a,n,s,i){this.separator=encodeString(t),this.nGramWidths=r,this.leftPad=encodeString(a),this.rightPad=encodeString(n),this.padWidth=s,this.preserveShort=i}getPadWidth(t){return Math.min(this.padWidth<0?t-1:this.padWidth,t-1)}getNumNGrams(t,r){return Math.max(0,t+2*this.getPadWidth(r)-r+1)}createNGrams(t,r,a,n,s,i){for(let o=0;o<s;++o){let l,u=this.getPadWidth(i),p=Math.max(0,u-o),m=Math.max(0,u-(s-(o+1))),y=i-(p+m),_=r+(p>0?0:o-u);l=0+p*this.leftPad.length;for(let r=0;r<y;++r)l+=t[_+r].length;l+=m*this.rightPad.length,l+=(p+m+y-1)*this.separator.length,a[n+o]=new Uint8Array(l);let w=a[n+o],I=0,appendToNGram=t=>t.forEach(t=>w[I++]=t);for(let t=0;t<p;++t)appendToNGram(this.leftPad),appendToNGram(this.separator);for(let r=0;r<y-1;++r)appendToNGram(t[_+r]),appendToNGram(this.separator);if(y>0){appendToNGram(t[_+y-1]);for(let t=0;t<m;++t)appendToNGram(this.separator),appendToNGram(this.rightPad)}else{for(let t=0;t<m-1;++t)appendToNGram(this.rightPad),appendToNGram(this.separator);appendToNGram(this.rightPad)}}}compute(t,r){let a=t.length,n=r.length;if(n>0){let t=r[0];if(0!==t)throw Error(`First split value must be 0, got ${t}`);for(let s=1;s<n;++s){let n=r[s]>=t;if(!(n=n&&r[s]<=a))throw Error(`Invalid split value ${r[s]}, must be in [${t}, ${a}]`);t=r[s]}if(t!==a)throw Error(`Last split value must be data size. Expected ${a}, got ${t}`)}let s=n-1,i=getArrayFromDType("int32",n);if(0===a||0===n){let t=Array(a);for(let t=0;t<=s;++t)i[t]=0;return[t,i]}i[0]=0;for(let t=1;t<=s;++t){let a=r[t]-r[t-1],n=0;this.nGramWidths.forEach(t=>{n+=this.getNumNGrams(a,t)}),this.preserveShort&&a>0&&0===n&&(n=1),i[t]=i[t-1]+n}let o=Array(i[s]);for(let a=0;a<s;++a){let n=r[a],s=i[a];if(this.nGramWidths.forEach(i=>{let l=r[a+1]-r[a],u=this.getNumNGrams(l,i);this.createNGrams(t,n,o,s,u,i),s+=u}),this.preserveShort&&s===i[a]){let i=r[a+1]-r[a];if(0===i)continue;let l=i+2*this.padWidth;this.createNGrams(t,n,o,s,1,l)}}return[o,i]}};function stringNGramsImpl(t,r,a,n,s,i,o,l){return new StringNGramsOp(a,n,s,i,o,l).compute(t,r)}function StringNGrams_stringNGrams(t){let{inputs:r,backend:a,attrs:n}=t,{separator:s,nGramWidths:i,leftPad:o,rightPad:l,padWidth:u,preserveShortSequences:p}=n,{data:m,dataSplits:y}=r,[_,w]=stringNGramsImpl(a.data.get(m.dataId).values,a.data.get(y.dataId).values,s,i,o,l,u,p);return[a.makeTensorInfo([_.length],"string",_),a.makeTensorInfo(y.shape,"int32",w)]}function StringSplit_impl_split(t,r,a,n){if(!t.length)return;if(0===r.length){for(let r=0;r<t.length;++r)n.push(t.subarray(r,r+1));return}if(1===r.length){let s=r[0],i=t.indexOf(s);for(;-1!==i;){let r=t.subarray(0,i);a&&0===r.length||n.push(r),i=(t=t.subarray(i+1)).indexOf(s)}a&&0===t.length||n.push(t);return}let s=0;for(let i=0;i<t.length+1;i++)if(i===t.length||-1!==r.indexOf(t[i])){let r=t.subarray(s,i);a&&0===r.length||n.push(r),s=i+1}}function stringSplitImpl(t,r,a){let n=t.length,s=[],i=0,o=0,l=Array(n);for(let u=0;u<n;++u){let n=s.length;StringSplit_impl_split(t[u],r,a,s);let p=s.length-n;l[u]=p,i+=p,o=Math.max(o,p)}let u=getArrayFromDType("int32",2*i),p=Array(i),m=[n,o],y=0;for(let t=0;t<n;++t)for(let r=0;r<l[t];++r)u[2*y]=t,u[2*y+1]=r,p[y]=s[y],++y;return[u,p,m]}function StringSplit_stringSplit(t){let{inputs:r,backend:a,attrs:n}=t,{skipEmpty:s}=n,{input:i,delimiter:o}=r;if("string"!==i.dtype)throw Error("Input must be of datatype string");if(1!==i.shape.length)throw Error(`Input must be a vector, got shape: ${i.shape}`);if(0!==o.shape.length)throw Error(`Delimiter must be a scalar, got shape: ${o.shape}`);let[l,u,p]=stringSplitImpl(a.data.get(i.dataId).values,a.data.get(o.dataId).values[0],s),m=u.length;return[a.makeTensorInfo([m,2],"int32",l),a.makeTensorInfo([m],"string",u),a.makeTensorInfo([2],"int32",new Int32Array(p))]}function stringToHashBucketFastImpl(t,r){let a=getArrayFromDType("int32",t.length);for(let n=0;n<t.length;++n)a[n]=fingerPrint64(t[n]).modulo(r).getLowBitsUnsigned();return a}function StringToHashBucketFast_stringToHashBucketFast(t){let{inputs:r,backend:a,attrs:n}=t,{numBuckets:s}=n,{input:i}=r;if("string"!==i.dtype)throw Error("Input must be of datatype string");if(s<=0)throw Error("Number of buckets must be at least 1");let o=stringToHashBucketFastImpl(a.data.get(i.dataId).values,s);return a.makeTensorInfo(i.shape,"int32",o)}let u2=unaryKernelFunc("Tan",t=>Math.tan(t)),u3=unaryKernelFunc(r1,t=>Math.tanh(t));function tileImpl(t,r){let a=Array(t.rank);for(let n=0;n<a.length;n++)a[n]=t.shape[n]*r[n];let n=buffer(a,t.dtype);for(let r=0;r<n.values.length;++r){let a=n.indexToLoc(r),s=Array(t.rank);for(let r=0;r<s.length;r++)s[r]=a[r]%t.shape[r];let i=t.locToIndex(s);n.values[r]=t.values[i]}return n}let comparePair=(t,r)=>{let a=r.value-t.value;return 0===a?t.index-r.index:a};function TopK_impl_select(t,r,a=0,n=t.length-1){for(;n>a;){if(n-a>600){let s=n-a+1,i=r-a+1,o=Math.log(s),l=.5*Math.exp(2*o/3),u=.5*Math.sqrt(o*l*(s-l)/s)*Math.sign(i-s/2),p=Math.max(a,Math.floor(r-i*l/s+u)),m=Math.min(n,Math.floor(r+(s-i)*l/s+u));TopK_impl_select(t,r,p,m)}let s=t[r],i=a,o=n;for(swap(t,a,r),comparePair(t[n],s)>0&&swap(t,a,n);i<o;){for(swap(t,i,o),i++,o--;0>comparePair(t[i],s);)i+=1;for(;comparePair(t[o],s)>0;)o-=1}0===comparePair(t[a],s)?swap(t,a,o):swap(t,o+=1,n),o<=r&&(a=o+1),r<=o&&(n=o-1)}}function topKImpl(t,r,a,n,s){let i=r[r.length-1],[o,l]=[t.length/i,i],u=getArrayFromDType(a,o*n),p=getArrayFromDType("int32",o*n);for(let r=0;r<o;r++){let a=r*l,i=t.subarray(a,a+l),o=Array(i.length);i.forEach((t,r)=>o[r]={value:t,index:r}),n<o.length&&(TopK_impl_select(o,n),o=o.slice(0,n)),s&&o.sort(comparePair);let m=r*n,y=u.subarray(m,m+n),_=p.subarray(m,m+n);for(let t=0;t<n;t++)y[t]=o[t].value,_[t]=o[t].index}let m=r.slice();return m[m.length-1]=n,[buffer(m,a,u),buffer(m,"int32",p)]}function mapCoord(t,r,a){switch(a){case"reflect":return mapCoordReflect(t,r);case"wrap":return mapCoordWrap(t,r);case"nearest":return mapCoordNearest(t,r);default:return mapCoordConstant(t,r)}}function mapCoordReflect(t,r){let a=t;if(a<0)if(r<=1)a=0;else{let t=2*r;a<t&&(a=t*Math.trunc(-a/t)+a),a=a<-r?a+t:-a-1}else if(a>r-1)if(r<=1)a=0;else{let t=2*r;(a-=t*Math.trunc(a/t))>=r&&(a=t-a-1)}return clamp(0,a,r-1)}function mapCoordWrap(t,r){let a=t;return a<0?r<=1?a=0:a+=r*(Math.trunc(-a/(r-1))+1):a>r-1&&(r<=1?a=0:a-=r*Math.trunc(a/(r-1))),clamp(0,a,r-1)}function mapCoordConstant(t,r){return t}function mapCoordNearest(t,r){return clamp(0,t,r-1)}function readWithFillValue(t,r,a,n,s,i,o,l,u,p,m){return 0<=l&&l<r&&0<=u&&u<a?t[o*n+l*s+u*i+p]:m}function nearestInterpolation(t,r,a,n,s,i,o,l,u,p,m){return readWithFillValue(t,r,a,n,s,i,o,Math.round(l),Math.round(u),p,m)}function bilinearInterpolation(t,r,a,n,s,i,o,l,u,p,m){let y=Math.floor(l),_=Math.floor(u),w=y+1,I=_+1,C=(I-u)*readWithFillValue(t,r,a,n,s,i,o,y,_,p,m)+(u-_)*readWithFillValue(t,r,a,n,s,i,o,y,I,p,m),E=(I-u)*readWithFillValue(t,r,a,n,s,i,o,w,_,p,m)+(u-_)*readWithFillValue(t,r,a,n,s,i,o,w,I,p,m);return(w-l)*C+(l-y)*E}function uniqueImpl(t,r,a,n){let s=parseAxisParam(r,a)[0],i=[1,a[0],1];for(let t=0;t<s;t++)i[0]*=a[t];i[1]=a[s];for(let t=s+1;t<a.length;t++)i[2]*=a[t];let o=new Map,l=new Int32Array(a[s]),u=new TensorBuffer(i,n,t),p=[],m=1===i[0]&&1===i[2];for(let r=0;r<a[s];r++){let a;if(m)a=t[r].toString();else{let t=[];for(let a=0;a<i[0];a++)for(let n=0;n<i[2];n++)t.push(u.get(a,r,n));a=t.join(",")}let n=o.get(a);if(null!=n)l[r]=n;else{let t=o.size;o.set(a,t),l[r]=t,p.push(r)}}let y=i.slice();y[1]=o.size;let _=new TensorBuffer(y,n);p.forEach((t,r)=>{for(let a=0;a<i[0];a++)for(let n=0;n<i[2];n++)_.set(u.get(a,t,n),a,r,n)});let w=a.slice();return w[s]=y[1],{outputValues:_.values,outputShape:w,indices:l}}function unpack(t){let{inputs:r,backend:a,attrs:n}=t,{value:s}=r,{axis:i}=n;i<0&&(i+=s.shape.length);let o=s.shape.length,l=s.shape[i],u=Array(o-1),p=0;for(let t=0;t<o;t++)t!==i&&(u[p++]=s.shape[t]);let m=Array(o).fill(0),y=s.shape.slice();y[i]=1;let _=Array(l);for(let t=0;t<_.length;t++){m[i]=t;let r=Slice_slice({inputs:{x:s},backend:a,attrs:{begin:m,size:y}});_[t]=Reshape_reshape({inputs:{x:r},backend:a,attrs:{shape:u}}),a.disposeIntermediateTensorInfo(r)}return _}function UnsortedSegmentSum_unsortedSegmentSum(t){let{inputs:r,backend:a,attrs:n}=t,{x:s,segmentIds:i}=r,{numSegments:o}=n;assertNotComplex(s,"unsortedSegmentSum");let l=s.shape.length,u=i.shape.length,p=[],m=[],y=l-u,_=i;for(let t=0;t<y;++t){let r=ExpandDims_expandDims({inputs:{input:_},backend:a,attrs:{dim:t+1}});_=r,m.push(r)}for(let t=0;t<o;++t){let r=createScalarValue(t,"int32"),n=a.makeTensorInfo([],"int32",r),i=l6({inputs:{a:n,b:_},backend:a}),o=Cast_cast({inputs:{x:i},backend:a,attrs:{dtype:"float32"}}),l=l3({inputs:{a:o,b:s},backend:a}),u=Sum_sum({inputs:{x:l},backend:a,attrs:{axis:0,keepDims:!1}});p.push(u),m.push(n),m.push(i),m.push(o),m.push(l),m.push(u)}let w=pack({inputs:p,backend:a,attrs:{axis:0}});return m.forEach(t=>a.disposeIntermediateTensorInfo(t)),w}for(let t of[{kernelName:an,backendName:"cpu",kernelFunc:_fusedMatMul},{kernelName:"Abs",backendName:"cpu",kernelFunc:t=>{let{x:r}=t.inputs,a=t.backend;assertNotComplex(r,"abs");let n=new Float32Array(sizeFromShape(r.shape));return n=simpleAbsImpl(a.data.get(r.dataId).values),a.makeOutput(n,r.shape,r.dtype)}},{kernelName:eB,backendName:"cpu",kernelFunc:lW},{kernelName:eW,backendName:"cpu",kernelFunc:lU},{kernelName:"Add",backendName:"cpu",kernelFunc:lB},{kernelName:eU,backendName:"cpu",kernelFunc:AddN_addN},{kernelName:"All",backendName:"cpu",kernelFunc:All_all},{kernelName:"Any",backendName:"cpu",kernelFunc:Any_any},{kernelName:eG,backendName:"cpu",kernelFunc:ArgMax_argMax},{kernelName:ej,backendName:"cpu",kernelFunc:ArgMin_argMin},{kernelName:eK,backendName:"cpu",kernelFunc:lG},{kernelName:eH,backendName:"cpu",kernelFunc:lj},{kernelName:eq,backendName:"cpu",kernelFunc:lK},{kernelName:eY,backendName:"cpu",kernelFunc:lH},{kernelName:eX,backendName:"cpu",kernelFunc:lq},{kernelName:eZ,backendName:"cpu",kernelFunc:AvgPool_avgPool},{kernelName:eQ,backendName:"cpu",kernelFunc:avgPool3D},{kernelName:e0,backendName:"cpu",kernelFunc:avgPool3DGrad},{kernelName:eJ,backendName:"cpu",kernelFunc:AvgPoolGrad_avgPoolGrad},{kernelName:e1,backendName:"cpu",kernelFunc:batchMatMul},{kernelName:tD,backendName:"cpu",kernelFunc:BatchNorm_batchNorm},{kernelName:e2,backendName:"cpu",kernelFunc:BatchToSpaceND_batchToSpaceND},{kernelName:e3,backendName:"cpu",kernelFunc:Bincount_bincount},{kernelName:e4,backendName:"cpu",kernelFunc:lY},{kernelName:e6,backendName:"cpu",kernelFunc:BroadcastArgs_broadcastArgs},{kernelName:e5,backendName:"cpu",kernelFunc:Cast_cast},{kernelName:e8,backendName:"cpu",kernelFunc:lJ},{kernelName:e7,backendName:"cpu",kernelFunc:lQ},{kernelName:e9,backendName:"cpu",kernelFunc:Complex_complex},{kernelName:te,backendName:"cpu",kernelFunc:t=>{let{x:r}=t.inputs,a=t.backend,n=new Float32Array(sizeFromShape(r.shape)),s=a.data.get(r.dataId),i=s.complexTensorInfos.real,o=s.complexTensorInfos.imag,l=a.data.get(i.dataId).values,u=a.data.get(o.dataId).values;for(let t=0;t<l.length;t++){let r=l[t],a=u[t];n[t]=Math.hypot(r,a)}return a.makeOutput(n,r.shape,"float32")}},{kernelName:tt,backendName:"cpu",kernelFunc:Concat_concat},{kernelName:tr,backendName:"cpu",kernelFunc:conv2D},{kernelName:tn,backendName:"cpu",kernelFunc:Conv2DBackpropFilter_conv2DBackpropFilter},{kernelName:ts,backendName:"cpu",kernelFunc:Conv2DBackpropInput_conv2DBackpropInput},{kernelName:ti,backendName:"cpu",kernelFunc:conv3D},{kernelName:to,backendName:"cpu",kernelFunc:conv3DBackpropFilterV2},{kernelName:tl,backendName:"cpu",kernelFunc:conv3DBackpropInputV2},{kernelName:"Cos",backendName:"cpu",kernelFunc:l0},{kernelName:tu,backendName:"cpu",kernelFunc:l1},{kernelName:tc,backendName:"cpu",kernelFunc:CropAndResize_cropAndResize},{kernelName:tp,backendName:"cpu",kernelFunc:Cumprod_cumprod},{kernelName:th,backendName:"cpu",kernelFunc:Cumsum_cumsum},{kernelName:td,backendName:"cpu",kernelFunc:DenseBincount_denseBincount},{kernelName:tm,backendName:"cpu",kernelFunc:DepthToSpace_depthToSpace},{kernelName:tf,backendName:"cpu",kernelFunc:depthwiseConv2dNative},{kernelName:tg,backendName:"cpu",kernelFunc:DepthwiseConv2dNativeBackpropFilter_depthwiseConv2dNativeBackpropFilter},{kernelName:ty,backendName:"cpu",kernelFunc:DepthwiseConv2dNativeBackpropInput_depthwiseConv2dNativeBackpropInput},{kernelName:tx,backendName:"cpu",kernelFunc:Diag_diag},{kernelName:tv,backendName:"cpu",kernelFunc:({inputs:t,backend:r,attrs:a})=>{let{x:n,filter:s}=t,{strides:i,pad:o,dilations:l}=a,u=r.data.get(n.dataId).values,p=n.shape.length,m=r.data.get(s.dataId).values,y=s.shape.length,{batchSize:_,inHeight:w,inWidth:I,inChannels:C,outHeight:E,outWidth:A,padInfo:$,strideHeight:F,strideWidth:D,filterHeight:P,filterWidth:L,dilationHeight:z,dilationWidth:B,outShape:G}=computeDilation2DInfo(n.shape,s.shape,i,o,"NHWC",l),j=sizeFromShape(G),K=G.length,H=getArrayFromDType(n.dtype,j);for(let t=0;t<_;++t)for(let r=0;r<E;++r){let a=r*F-$.top;for(let i=0;i<A;++i){let o=i*D-$.left;for(let l=0;l<C;++l){let _=Number.MIN_SAFE_INTEGER;for(let r=0;r<P;++r){let i=a+r*z;if(i>=0&&i<w)for(let a=0;a<L;++a){let w=o+a*B;if(w>=0&&w<I){let o=locToIndex([t,i,w,l],p,computeStrides(n.shape)),I=locToIndex([r,a,l],y,computeStrides(s.shape)),C=u[o]+m[I];C>_&&(_=C)}}}H[locToIndex([t,r,i,l],K,computeStrides(G))]=_}}}return{dataId:r.write(toTypedArray(H,n.dtype),G,n.dtype),shape:G,dtype:n.dtype}}},{kernelName:tT,backendName:"cpu",kernelFunc:({inputs:t,backend:r,attrs:a})=>{let{x:n,filter:s,dy:i}=t,{strides:o,pad:l,dilations:u}=a,p=toNestedArray(n.shape,r.data.get(n.dataId).values),m=toNestedArray(s.shape,r.data.get(s.dataId).values),{batchSize:y,inHeight:_,inWidth:w,inChannels:I,outHeight:C,outWidth:E,padInfo:A,strideHeight:$,strideWidth:F,filterHeight:D,filterWidth:P,dilationHeight:L,dilationWidth:z,outShape:B}=computeDilation2DInfo(n.shape,s.shape,o,l,"NHWC",u);assert(i.rank===B.length,()=>`Error in ${tT}, dy must have the same rank as output ${B.length}, but got ${i.rank}`);let G=toNestedArray(B,r.data.get(i.dataId).values),j=makeZerosNestedTypedArray(s.shape,s.dtype);for(let t=0;t<y;++t)for(let r=0;r<C;++r){let a=r*$-A.top;for(let n=0;n<E;++n){let s=n*F-A.left;for(let i=0;i<I;++i){let o=Number.MIN_SAFE_INTEGER,l=0,u=0;for(let r=0;r<D;++r){let n=a+r*L;if(n>=0&&n<_)for(let a=0;a<P;++a){let y=s+a*z;if(y>=0&&y<w){let s=p[t][n][y][i]+m[r][a][i];s>o&&(o=s,l=r,u=a)}}}j[l][u][i]+=G[t][r][n][i]}}}return{dataId:r.write(toTypedArray(j,n.dtype),s.shape,s.dtype),shape:s.shape,dtype:s.dtype}}},{kernelName:t_,backendName:"cpu",kernelFunc:({inputs:t,backend:r,attrs:a})=>{let{x:n,filter:s,dy:i}=t,{strides:o,pad:l,dilations:u}=a,p=toNestedArray(n.shape,r.data.get(n.dataId).values),m=toNestedArray(s.shape,r.data.get(s.dataId).values),{batchSize:y,inHeight:_,inWidth:w,inChannels:I,outHeight:C,outWidth:E,padInfo:A,strideHeight:$,strideWidth:F,filterHeight:D,filterWidth:P,dilationHeight:L,dilationWidth:z,outShape:B}=computeDilation2DInfo(n.shape,s.shape,o,l,"NHWC",u);assert(i.rank===B.length,()=>`Error in ${t_}, dy must have the same rank as output ${B.length}, but got ${i.rank}`);let G=toNestedArray(B,r.data.get(i.dataId).values),j=makeZerosNestedTypedArray(n.shape,n.dtype);for(let t=0;t<y;++t)for(let r=0;r<C;++r){let a=r*$-A.top;for(let n=0;n<E;++n){let s=n*F-A.left;for(let i=0;i<I;++i){let o=Number.MIN_SAFE_INTEGER,l=a<0?0:a,u=s<0?0:s;for(let r=0;r<D;++r){let n=a+r*L;if(n>=0&&n<_)for(let a=0;a<P;++a){let y=s+a*z;if(y>=0&&y<w){let s=p[t][n][y][i]+m[r][a][i];s>o&&(o=s,l=n,u=y)}}}j[t][l][u][i]+=G[t][r][n][i]}}}return{dataId:r.write(toTypedArray(j,n.dtype),n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},{kernelName:tk,backendName:"cpu",kernelFunc:Draw_draw},{kernelName:tw,backendName:"cpu",kernelFunc:Einsum_einsum},{kernelName:"Elu",backendName:"cpu",kernelFunc:lD},{kernelName:tI,backendName:"cpu",kernelFunc:eluGrad},{kernelName:tN,backendName:"cpu",kernelFunc:l6},{kernelName:"Erf",backendName:"cpu",kernelFunc:l5},{kernelName:"Exp",backendName:"cpu",kernelFunc:l7},{kernelName:tC,backendName:"cpu",kernelFunc:ExpandDims_expandDims},{kernelName:tE,backendName:"cpu",kernelFunc:ue},{kernelName:"FFT",backendName:"cpu",kernelFunc:FFT_fft},{kernelName:tA,backendName:"cpu",kernelFunc:Fill_fill},{kernelName:t$,backendName:"cpu",kernelFunc:({inputs:t,attrs:r,backend:a})=>{let{image:n}=t,s=getArrayFromDType(n.dtype,sizeFromShape(n.shape)),[i,o,l,u]=n.shape,p=a.data.get(n.dataId).values;for(let t=0;t<i;t++){let r=t*l*o*u;for(let t=0;t<o;t++){let a=l*u*t;for(let t=0;t<l;t++){let n=t*u;for(let i=0;i<u;i++){let o=Math.round(l-t-1),m=r+a+n+i,y=p[m];o>=0&&o<l&&(y=p[r+a+o*u+i]),s[m]=y}}}}return{dataId:a.write(s,n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},{kernelName:tR,backendName:"cpu",kernelFunc:uo},{kernelName:tF,backendName:"cpu",kernelFunc:ul},{kernelName:as,backendName:"cpu",kernelFunc:fusedConv2D},{kernelName:ai,backendName:"cpu",kernelFunc:fusedDepthwiseConv2D},{kernelName:tO,backendName:"cpu",kernelFunc:gatherNd},{kernelName:tP,backendName:"cpu",kernelFunc:gatherV2},{kernelName:tM,backendName:"cpu",kernelFunc:up},{kernelName:tL,backendName:"cpu",kernelFunc:uc},{kernelName:tz,backendName:"cpu",kernelFunc:Identity_identity},{kernelName:tV,backendName:"cpu",kernelFunc:IFFT_ifft},{kernelName:tB,backendName:"cpu",kernelFunc:Imag_imag},{kernelName:tW,backendName:"cpu",kernelFunc:ud},{kernelName:tU,backendName:"cpu",kernelFunc:um},{kernelName:tG,backendName:"cpu",kernelFunc:uf},{kernelName:tj,backendName:"cpu",kernelFunc:LeakyRelu_leakyRelu},{kernelName:tK,backendName:"cpu",kernelFunc:uy},{kernelName:tH,backendName:"cpu",kernelFunc:uv},{kernelName:tq,backendName:"cpu",kernelFunc:linSpace},{kernelName:"Log",backendName:"cpu",kernelFunc:uT},{kernelName:tX,backendName:"cpu",kernelFunc:uk},{kernelName:tY,backendName:"cpu",kernelFunc:uS},{kernelName:tZ,backendName:"cpu",kernelFunc:uw},{kernelName:tJ,backendName:"cpu",kernelFunc:uI},{kernelName:"LRN",backendName:"cpu",kernelFunc:lRN},{kernelName:tQ,backendName:"cpu",kernelFunc:lRNGrad},{kernelName:"Max",backendName:"cpu",kernelFunc:Max_max},{kernelName:t0,backendName:"cpu",kernelFunc:uC},{kernelName:t1,backendName:"cpu",kernelFunc:MaxPool_maxPool},{kernelName:t3,backendName:"cpu",kernelFunc:maxPool3D},{kernelName:t4,backendName:"cpu",kernelFunc:maxPool3DGrad},{kernelName:t2,backendName:"cpu",kernelFunc:MaxPoolGrad_maxPoolGrad},{kernelName:t6,backendName:"cpu",kernelFunc:({inputs:t,attrs:r,backend:a})=>{let{x:n}=t,{filterSize:s,strides:i,pad:o,includeBatchInIndex:l}=r;assertNotComplex(n,"MaxPoolWithArgmax");let u=a.data.get(n.dataId).values,p=computePool2DInfo(n.shape,s,i,[1,1],o),[m,y]=maxPoolWithArgmaxImpl(u,n.shape,n.dtype,l,p),_=a.write(m,p.outShape,n.dtype),w=a.write(y,p.outShape,n.dtype);return[{dataId:_,shape:p.outShape,dtype:n.dtype},{dataId:w,shape:p.outShape,dtype:"int32"}]}},{kernelName:t5,backendName:"cpu",kernelFunc:Mean_mean},{kernelName:"Min",backendName:"cpu",kernelFunc:Min_min},{kernelName:t8,backendName:"cpu",kernelFunc:uA},{kernelName:t7,backendName:"cpu",kernelFunc:MirrorPad_mirrorPad},{kernelName:"Mod",backendName:"cpu",kernelFunc:u$},{kernelName:t9,backendName:"cpu",kernelFunc:Multinomial_multinomial},{kernelName:re,backendName:"cpu",kernelFunc:l3},{kernelName:"Neg",backendName:"cpu",kernelFunc:Neg_neg},{kernelName:rr,backendName:"cpu",kernelFunc:nonMaxSuppressionV3},{kernelName:rn,backendName:"cpu",kernelFunc:nonMaxSuppressionV4},{kernelName:rs,backendName:"cpu",kernelFunc:nonMaxSuppressionV5},{kernelName:rt,backendName:"cpu",kernelFunc:uO},{kernelName:ro,backendName:"cpu",kernelFunc:OneHot_oneHot},{kernelName:ri,backendName:"cpu",kernelFunc:OnesLike_onesLike},{kernelName:rl,backendName:"cpu",kernelFunc:pack},uM,{kernelName:"Pow",backendName:"cpu",kernelFunc:uL},{kernelName:rp,backendName:"cpu",kernelFunc:Prelu_prelu},{kernelName:rh,backendName:"cpu",kernelFunc:Prod_prod},{kernelName:rc,backendName:"cpu",kernelFunc:RaggedGather_raggedGather},{kernelName:rd,backendName:"cpu",kernelFunc:RaggedRange_raggedRange},{kernelName:rm,backendName:"cpu",kernelFunc:RaggedTensorToTensor_raggedTensorToTensor},{kernelName:rf,backendName:"cpu",kernelFunc:Range_range},{kernelName:rg,backendName:"cpu",kernelFunc:Real_real},ur,{kernelName:ry,backendName:"cpu",kernelFunc:uV},{kernelName:rx,backendName:"cpu",kernelFunc:lO},{kernelName:rw,backendName:"cpu",kernelFunc:lM},{kernelName:rv,backendName:"cpu",kernelFunc:Reshape_reshape},{kernelName:rk,backendName:"cpu",kernelFunc:ResizeBilinear_resizeBilinear},{kernelName:rS,backendName:"cpu",kernelFunc:resizeBilinearGrad},{kernelName:r_,backendName:"cpu",kernelFunc:ResizeNearestNeighbor_resizeNearestNeighbor},{kernelName:rT,backendName:"cpu",kernelFunc:resizeNearestNeighborGrad},{kernelName:rI,backendName:"cpu",kernelFunc:Reverse_reverse},{kernelName:ar,backendName:"cpu",kernelFunc:({inputs:t,attrs:r,backend:a})=>{let{image:n}=t,{radians:s,fillValue:i,center:o}=r,l=getArrayFromDType(n.dtype,sizeFromShape(n.shape)),[u,p,m,y]=n.shape,[_,w]=getImageCenter(o,p,m),I=Math.sin(s),C=Math.cos(s),E=a.data.get(n.dataId).values;for(let t=0;t<u;t++){let r=t*m*p*y;for(let t=0;t<p;t++){let a=m*y*t;for(let n=0;n<m;n++){let s=n*y;for(let o=0;o<y;o++){let A=[u,t,n,o],$=A[2],F=A[1],D=($-_)*C-(F-w)*I,P=($-_)*I+(F-w)*C;D=Math.round(D+_),P=Math.round(P+w);let L=i;"number"!=typeof i&&(L=3===o?255:i[o]),D>=0&&D<m&&P>=0&&P<p&&(L=E[r+m*y*P+D*y+o]),l[r+a+s+o]=L}}}}return{dataId:a.write(l,n.shape,n.dtype),shape:n.shape,dtype:n.dtype}}},{kernelName:rN,backendName:"cpu",kernelFunc:uB},{kernelName:rC,backendName:"cpu",kernelFunc:uU},{kernelName:rE,backendName:"cpu",kernelFunc:scatterNd},{kernelName:r$,backendName:"cpu",kernelFunc:SearchSorted_searchSorted},{kernelName:rR,backendName:"cpu",kernelFunc:Select_select},{kernelName:rF,backendName:"cpu",kernelFunc:uG},{kernelName:rM,backendName:"cpu",kernelFunc:lz},{kernelName:rO,backendName:"cpu",kernelFunc:uj},{kernelName:"Sin",backendName:"cpu",kernelFunc:uK},{kernelName:rP,backendName:"cpu",kernelFunc:uH},{kernelName:rD,backendName:"cpu",kernelFunc:Slice_slice},{kernelName:rW,backendName:"cpu",kernelFunc:Softmax_softmax},{kernelName:rL,backendName:"cpu",kernelFunc:uX},{kernelName:rV,backendName:"cpu",kernelFunc:SpaceToBatchND_spaceToBatchND},{kernelName:rU,backendName:"cpu",kernelFunc:SparseFillEmptyRows_sparseFillEmptyRows},{kernelName:rG,backendName:"cpu",kernelFunc:SparseReshape_sparseReshape},{kernelName:rj,backendName:"cpu",kernelFunc:SparseSegmentMean_sparseSegmentMean},{kernelName:rK,backendName:"cpu",kernelFunc:SparseSegmentSum_sparseSegmentSum},{kernelName:rH,backendName:"cpu",kernelFunc:SparseToDense_sparseToDense},{kernelName:rB,backendName:"cpu",kernelFunc:splitV},{kernelName:rz,backendName:"cpu",kernelFunc:uZ},{kernelName:rX,backendName:"cpu",kernelFunc:({inputs:t,backend:r})=>{let{x:a}=t;assertNotComplex(a,"square");let n=r.data.get(a.dataId).values,s=new Float32Array(n.length);for(let t=0;t<n.length;++t){let r=n[t];s[t]=r*r}return{dataId:r.write(s,a.shape,a.dtype),shape:a.shape,dtype:a.dtype}}},{kernelName:rq,backendName:"cpu",kernelFunc:uJ},{kernelName:rY,backendName:"cpu",kernelFunc:u0},{kernelName:ae,backendName:"cpu",kernelFunc:u1},{kernelName:rZ,backendName:"cpu",kernelFunc:StridedSlice_stridedSlice},{kernelName:rJ,backendName:"cpu",kernelFunc:StringNGrams_stringNGrams},{kernelName:rQ,backendName:"cpu",kernelFunc:StringSplit_stringSplit},{kernelName:r0,backendName:"cpu",kernelFunc:StringToHashBucketFast_stringToHashBucketFast},{kernelName:"Sub",backendName:"cpu",kernelFunc:us},{kernelName:"Sum",backendName:"cpu",kernelFunc:Sum_sum},{kernelName:"Tan",backendName:"cpu",kernelFunc:u2},{kernelName:r1,backendName:"cpu",kernelFunc:u3},{kernelName:rA,backendName:"cpu",kernelFunc:function TensorScatterUpdate_tensorScatterUpdate(t){let{inputs:r,backend:a}=t,{tensor:n,indices:s,updates:i}=r,{sliceRank:o,numUpdates:l,sliceSize:u,strides:p,outputSize:m}=calculateShapes(i,s,n.shape),y=a.bufferSync(s),_=a.bufferSync(i),w=a.bufferSync(n),I=scatterImpl(y,_,n.shape,m,u,l,o,p,w,!1);return a.makeTensorInfo(n.shape,I.dtype,I.values)}},{kernelName:r2,backendName:"cpu",kernelFunc:function Tile_tile(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{reps:i}=n;assertNotComplex(s,"tile");let o=tileImpl(a.bufferSync(s),i);return a.makeTensorInfo(o.shape,o.dtype,o.values)}},{kernelName:r3,backendName:"cpu",kernelFunc:function topK(t){let{inputs:r,backend:a,attrs:n}=t,{x:s}=r,{k:i,sorted:o}=n;assertNotComplex(s,"topk");let[l,u]=topKImpl(a.data.get(s.dataId).values,s.shape,s.dtype,i,o);return[a.makeTensorInfo(l.shape,l.dtype,l.values),a.makeTensorInfo(u.shape,u.dtype,u.values)]}},{kernelName:r4,backendName:"cpu",kernelFunc:function Transform_transform(t){let{inputs:r,attrs:a,backend:n}=t,{image:s,transforms:i}=r,{interpolation:o,fillMode:l,fillValue:u,outputShape:p}=a,[m,y,_,w]=s.shape,[I,C]=null!=p?p:[y,_],E=[m,I,C,w],A=computeStrides(s.shape),$=A[0],F=A[1],D=A[2],P=computeStrides(E),L=P[0],z=P[1],B=P[2],G=getArrayFromDType(s.dtype,sizeFromShape(E));G.fill(u);let j=n.data.get(s.dataId).values,K=n.data.get(i.dataId).values;for(let t=0;t<m;++t){let r=1===i.shape[0]?K:K.subarray(8*t,8*t+8);for(let a=0;a<I;++a)for(let n=0;n<C;++n)for(let s=0;s<w;++s){let i,p=r[6]*n+r[7]*a+1;if(0===p)continue;let m=(r[0]*n+r[1]*a+r[2])/p,w=(r[3]*n+r[4]*a+r[5])/p,I=mapCoord(m,_,l),C=mapCoord(w,y,l);switch(o){case"nearest":i=nearestInterpolation(j,y,_,$,F,D,t,C,I,s,u);break;case"bilinear":i=bilinearInterpolation(j,y,_,$,F,D,t,C,I,s,u);break;default:throw Error(`Error in Transform: Expect 'nearest' or 'bilinear', but got ${o}`)}G[t*L+a*z+n*B+s]=i}return n.makeTensorInfo(E,s.dtype,G)}return{dataId:n.write(G,E,s.dtype),shape:s.shape,dtype:s.dtype}}},{kernelName:r6,backendName:"cpu",kernelFunc:Transpose_transpose},{kernelName:r5,backendName:"cpu",kernelFunc:function Unique_unique(t){let{inputs:r,attrs:a,backend:n}=t,{axis:s}=a,{x:i}=r;assertNotComplex(i,"unique");let{outputValues:o,outputShape:l,indices:u}=uniqueImpl(n.data.get(i.dataId).values,s,i.shape,i.dtype);return[n.makeTensorInfo(l,i.dtype,o),n.makeTensorInfo([u.length],"int32",u)]}},{kernelName:r8,backendName:"cpu",kernelFunc:unpack},{kernelName:r7,backendName:"cpu",kernelFunc:UnsortedSegmentSum_unsortedSegmentSum},{kernelName:r9,backendName:"cpu",kernelFunc:ZerosLike_zerosLike}])registerKernel(t);let u4={},u6={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function setWebGLContext(t,r){u4[t]=r}function getWebGLContext(t,r){if(!(t in u4)||null!=r){let a=getWebGLRenderingContext(t,r);if(null===a)return console.log("Could not get context for WebGL version",t),null;u4[t]=a}let a=u4[t];return null==a||a.isContextLost()?(delete u4[t],getWebGLContext(t)):(a.disable(a.DEPTH_TEST),a.disable(a.STENCIL_TEST),a.disable(a.BLEND),a.disable(a.DITHER),a.disable(a.POLYGON_OFFSET_FILL),a.disable(a.SAMPLE_COVERAGE),a.enable(a.SCISSOR_TEST),a.enable(a.CULL_FACE),a.cullFace(a.BACK),u4[t])}function createCanvas(t){if(!eV.getBool("IS_SAFARI")&&"u">typeof OffscreenCanvas&&2===t)return new OffscreenCanvas(300,150);if("u">typeof document)return document.createElement("canvas");throw Error("Cannot create a canvas in this context")}function getWebGLRenderingContext(t,r){if(1!==t&&2!==t)throw Error("Cannot get WebGL rendering context, WebGL is disabled.");let a=null==r?createCanvas(t):r;return(a.addEventListener("webglcontextlost",r=>{r.preventDefault(),delete u4[t]},!1),eV.getBool("SOFTWARE_WEBGL_ENABLED")&&(u6.failIfMajorPerformanceCaveat=!1),1===t)?a.getContext("webgl",u6)||a.getContext("experimental-webgl",u6):a.getContext("webgl2",u6)}function getUnpackedArraySizeFromMatrixSize(t,r){return t*r}function getDenseTexShape(t){return sizeToSquarishShape(Math.ceil(sizeFromShape(t)/4))}function getPackedMatrixTextureShapeWidthHeight(t,r){return[Math.max(1,Math.ceil(r/2)),Math.max(1,Math.ceil(t/2))]}function getPackedRGBAArraySizeFromMatrixShape(t,r){let[a,n]=getPackedMatrixTextureShapeWidthHeight(t,r);return a*n*4}function getTextureConfig(t,r){let a,n,s,i,o,l,u,p,m,y;return 2===eV.getNumber("WEBGL_VERSION")?(a=t.R32F,n=t.R16F,s=t.RGBA16F,i=t.RGBA32F,o=t.RED,u=4,p=1,m=t.HALF_FLOAT,y=t.FLOAT,l=t.RGBA8):(a=t.RGBA,n=t.RGBA,s=t.RGBA,i=t.RGBA,o=t.RGBA,u=4,p=4,m=null!=r?r.HALF_FLOAT_OES:null,y=t.FLOAT,l=t.RGBA),{internalFormatFloat:a,internalFormatHalfFloat:n,internalFormatPackedHalfFloat:s,internalFormatPackedFloat:i,textureFormatFloat:o,downloadTextureFormat:l,downloadUnpackNumChannels:u,defaultNumChannels:p,textureTypeHalfFloat:m,textureTypeFloat:y}}function callAndCheck(t,r){let a=r();return eV.getBool("DEBUG")&&checkWebGLError(t),a}function checkWebGLError(t){let r=t.getError();if(r!==t.NO_ERROR)throw Error("WebGL Error: "+getWebGLErrorMessage(t,r))}function canBeRepresented(t){return!!(eV.getBool("WEBGL_RENDER_FLOAT32_ENABLED")||0===t||596e-10<Math.abs(t)&&65504>Math.abs(t))}function getWebGLErrorMessage(t,r){switch(r){case t.NO_ERROR:return"NO_ERROR";case t.INVALID_ENUM:return"INVALID_ENUM";case t.INVALID_VALUE:return"INVALID_VALUE";case t.INVALID_OPERATION:return"INVALID_OPERATION";case t.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case t.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case t.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return`Unknown error code ${r}`}}function getExtensionOrThrow(t,r){return throwIfNull(t,()=>t.getExtension(r),'Extension "'+r+'" not supported on this browser.')}function createVertexShader(t,r){let a=throwIfNull(t,()=>t.createShader(t.VERTEX_SHADER),"Unable to create vertex WebGLShader.");if(callAndCheck(t,()=>t.shaderSource(a,r)),callAndCheck(t,()=>t.compileShader(a)),!1===t.getShaderParameter(a,t.COMPILE_STATUS))throw console.log(t.getShaderInfoLog(a)),Error("Failed to compile vertex shader.");return a}function createFragmentShader(t,r){let a=throwIfNull(t,()=>t.createShader(t.FRAGMENT_SHADER),"Unable to create fragment WebGLShader.");if(callAndCheck(t,()=>t.shaderSource(a,r)),callAndCheck(t,()=>t.compileShader(a)),eV.get("ENGINE_COMPILE_ONLY"))return a;if(!1===t.getShaderParameter(a,t.COMPILE_STATUS))throw logShaderSourceAndInfoLog(r,t.getShaderInfoLog(a)),Error("Failed to compile fragment shader.");return a}(z=eo||(eo={}))[z.DENSE=0]="DENSE",z[z.SHARED_BATCH=1]="SHARED_BATCH",(B=el||(el={}))[B.RENDER=0]="RENDER",B[B.UPLOAD=1]="UPLOAD",B[B.PIXELS=2]="PIXELS",B[B.DOWNLOAD=3]="DOWNLOAD",(G=eu||(eu={}))[G.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",G[G.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",G[G.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",G[G.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",G[G.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16";let u5=/ERROR: [0-9]+:([0-9]+):/g;function logShaderSourceAndInfoLog(t,r){let a=u5.exec(r);if(null==a){console.log(`Couldn't parse line number in error: ${r}`),console.log(t);return}let n=+a[1],s=t.split(`
`),i=s.length.toString().length+2,o=s.map((t,r)=>rightPad((r+1).toString(),i)+t),l=0;for(let t=0;t<o.length;t++)l=Math.max(o[t].length,l);let u=o.slice(0,n-1),p=o.slice(n-1,n),m=o.slice(n);console.log(u.join(`
`)),console.log(r.split(`
`)[0]),console.log(`%c ${rightPad(p[0],l)}`,"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(m.join(`
`))}function createProgram(t){return throwIfNull(t,()=>t.createProgram(),"Unable to create WebGLProgram.")}function linkProgram(t,r){if(callAndCheck(t,()=>t.linkProgram(r)),!eV.get("ENGINE_COMPILE_ONLY")&&!1===t.getProgramParameter(r,t.LINK_STATUS))throw console.log(t.getProgramInfoLog(r)),Error("Failed to link vertex and fragment shaders.")}function validateProgram(t,r){if(callAndCheck(t,()=>t.validateProgram(r)),!1===t.getProgramParameter(r,t.VALIDATE_STATUS))throw console.log(t.getProgramInfoLog(r)),Error("Shader program validation failed.")}function createStaticVertexBuffer(t,r){let a=throwIfNull(t,()=>t.createBuffer(),"Unable to create WebGLBuffer");return callAndCheck(t,()=>t.bindBuffer(t.ARRAY_BUFFER,a)),callAndCheck(t,()=>t.bufferData(t.ARRAY_BUFFER,r,t.STATIC_DRAW)),a}function createStaticIndexBuffer(t,r){let a=throwIfNull(t,()=>t.createBuffer(),"Unable to create WebGLBuffer");return callAndCheck(t,()=>t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,a)),callAndCheck(t,()=>t.bufferData(t.ELEMENT_ARRAY_BUFFER,r,t.STATIC_DRAW)),a}function createTexture(t){return throwIfNull(t,()=>t.createTexture(),"Unable to create WebGLTexture.")}function validateTextureSize(t,r){let a=eV.getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t<=0||r<=0)throw Error(`Requested texture size [${t}x${r}] is invalid.`);if(t>a||r>a)throw Error(`Requested texture size [${t}x${r}] greater than WebGL maximum on this browser / GPU [${a}x${a}].`)}function createFramebuffer(t){return throwIfNull(t,()=>t.createFramebuffer(),"Unable to create WebGLFramebuffer.")}function bindVertexBufferToProgramAttribute(t,r,a,n,s,i,o){let l=t.getAttribLocation(r,a);return -1!==l&&(callAndCheck(t,()=>t.bindBuffer(t.ARRAY_BUFFER,n)),callAndCheck(t,()=>t.vertexAttribPointer(l,s,t.FLOAT,!1,i,o)),callAndCheck(t,()=>t.enableVertexAttribArray(l)),!0)}function bindTextureUnit(t,r,a){validateTextureUnit(t,a),callAndCheck(t,()=>t.activeTexture(t.TEXTURE0+a)),callAndCheck(t,()=>t.bindTexture(t.TEXTURE_2D,r))}function getProgramUniformLocationOrThrow(t,r,a){return throwIfNull(t,()=>t.getUniformLocation(r,a),'uniform "'+a+'" not present in program.')}function getProgramUniformLocation(t,r,a){return t.getUniformLocation(r,a)}function bindTextureToProgramUniformSampler(t,r,a,n){callAndCheck(t,()=>bindTextureUnit(t,r,n)),callAndCheck(t,()=>t.uniform1i(a,n))}function bindColorTextureToFramebuffer(t,r,a){callAndCheck(t,()=>t.bindFramebuffer(t.FRAMEBUFFER,a)),callAndCheck(t,()=>t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0))}function unbindColorTextureFromFramebuffer(t,r){callAndCheck(t,()=>t.bindFramebuffer(t.FRAMEBUFFER,r)),callAndCheck(t,()=>t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,null,0))}function validateFramebuffer(t){let r=t.checkFramebufferStatus(t.FRAMEBUFFER);if(r!==t.FRAMEBUFFER_COMPLETE)throw Error("Error binding framebuffer: "+getFramebufferErrorMessage(t,r))}function getFramebufferErrorMessage(t,r){switch(r){case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case t.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return`unknown error ${r}`}}function throwIfNull(t,r,a){let n=callAndCheck(t,()=>r());if(null==n)throw Error(a);return n}function validateTextureUnit(t,r){let a=t.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,n=r+t.TEXTURE0;if(n<t.TEXTURE0||n>a){let t=`[gl.TEXTURE0, gl.TEXTURE${a}]`;throw Error(`textureUnit must be in ${t}.`)}}function getBatchDim(t,r=2){return sizeFromShape(t.slice(0,t.length-r))}function getRowsCols(t){if(0===t.length)throw Error("Cannot get rows and columns of an empty shape array.");return[t.length>1?t[t.length-2]:1,t[t.length-1]]}function getShapeAs3D(t){let r=[1,1,1];return 0!==t.length&&(1!==t.length||1!==t[0])&&(r=[getBatchDim(t),...getRowsCols(t)]),r}function getTextureShapeFromLogicalShape(t,r=!1){let a=eV.getNumber("WEBGL_MAX_TEXTURE_SIZE"),n=eV.getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");n===1/0&&eV.getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE")&&(n=a/2),r&&(a*=2,n*=2,1===(t=t.map((r,a)=>a>=t.length-2?nearestLargerEven(t[a]):t[a])).length&&(t=[2,t[0]])),2!==t.length&&(t=util_base_squeezeShape(t).newShape);let s=sizeFromShape(t),i=null;t.length<=1&&s<=a?i=[1,s]:2===t.length&&t[0]<=a&&t[1]<=a?i=t:3===t.length&&t[0]*t[1]<=a&&t[2]<=a?i=[t[0]*t[1],t[2]]:3===t.length&&t[0]<=a&&t[1]*t[2]<=a?i=[t[0],t[1]*t[2]]:4===t.length&&t[0]*t[1]*t[2]<=a&&t[3]<=a?i=[t[0]*t[1]*t[2],t[3]]:4===t.length&&t[0]<=a&&t[1]*t[2]*t[3]<=a&&(i=[t[0],t[1]*t[2]*t[3]]);let o=null!=i&&Math.max(...i)>n&&Math.min(...i)<=(r?2:1)&&Math.min(...i)>0;if(null==i||o)if(r){let r=getBatchDim(t),a=2,n=2;t.length&&([a,n]=getRowsCols(t)),i=sizeToSquarishShape(s=a/2*r*(n/2)).map(t=>2*t)}else i=sizeToSquarishShape(s);return i}function isReshapeFree(t,r){if(arraysEqual(t=t.slice(-2),r=r.slice(-2))||!t.length||!r.length||0===t[0]||0===t[1]||0===r[0]||0===r[1])return!0;if(t.length!==r.length){let a=t[t.length-1],n=r[r.length-1];if(a===n||a%2==0&&n%2==0&&(1===t[0]||1===r[0]))return!0}return t[1]===r[1]&&t[0]%2==0&&r[0]%2==0}function getWebGLMaxTextureSize(t){if(null==u){let r=getWebGLContext(t);u=r.getParameter(r.MAX_TEXTURE_SIZE)}return u}function getMaxTexturesInShader(t){if(null==p){let r=getWebGLContext(t);p=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,p)}function getWebGLDisjointQueryTimerVersion(t){if(0===t)return 0;let r=getWebGLContext(t);return hasExtension(r,