@tensorflow/tfjs-core
Version:
Hardware-accelerated JavaScript library for machine intelligence
17 lines • 294 kB
JavaScript
/**
* @license
* Copyright 2024 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).tf=e.tf||{})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),e}var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},n(e,t)};function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function i(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i}function u(e,t,n){if(n||2===arguments.length)for(var r,a=0,o=t.length;a<o;a++)!r&&a in t||(r||(r=Array.prototype.slice.call(t,0,a)),r[a]=t[a]);return e.concat(r||Array.prototype.slice.call(t))}var c=function(){function e(e,t){this.backend=e,this.dataMover=t,this.data=new WeakMap,this.dataIdsCount=0}return e.prototype.get=function(e){return this.data.has(e)||this.dataMover.moveData(this.backend,e),this.data.get(e)},e.prototype.set=function(e,t){this.dataIdsCount++,this.data.set(e,t)},e.prototype.has=function(e){return this.data.has(e)},e.prototype.delete=function(e){return this.dataIdsCount--,this.data.delete(e)},e.prototype.numDataIds=function(){return this.dataIdsCount},e}(),l=function(){function e(){}return e.prototype.refCount=function(e){return h("refCount")},e.prototype.incRef=function(e){return h("incRef")},e.prototype.timerAvailable=function(){return!0},e.prototype.time=function(e){return h("time")},e.prototype.read=function(e){return h("read")},e.prototype.readSync=function(e){return h("readSync")},e.prototype.readToGPU=function(e,t){return h("readToGPU")},e.prototype.numDataIds=function(){return h("numDataIds")},e.prototype.disposeData=function(e,t){return h("disposeData")},e.prototype.write=function(e,t,n){return h("write")},e.prototype.move=function(e,t,n,r,a){return h("move")},e.prototype.createTensorFromGPUData=function(e,t,n){return h("createTensorFromGPUData")},e.prototype.memory=function(){return h("memory")},e.prototype.floatPrecision=function(){return h("floatPrecision")},e.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},e.prototype.dispose=function(){return h("dispose")},e}();function h(e){throw new Error("'".concat(e,"' not yet implemented or not found in the registry. ")+"This kernel may not be supported by the tfjs backend you have chosen")}function f(e){for(var t=e.length,n=0;t>0;)n=Math.random()*t|0,p(e,--t,n)}function d(e,t,n){return Math.max(e,Math.min(t,n))}function p(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function g(e,t){if(!e)throw new Error("string"==typeof t?t:t())}function v(e,t,n){void 0===n&&(n=""),g(w(e,t),(function(){return n+" Shapes ".concat(e," and ").concat(t," must match")}))}function m(e){g(null!=e,(function(){return"The input to the tensor constructor must be a non-null value."}))}function y(e){if(0===e.length)return 1;for(var t=e[0],n=1;n<e.length;n++)t*=e[n];return t}function b(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(null!==e[n]&&null!==t[n]&&e[n]!==t[n])return!1;return!0}function w(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function k(e){return e%1==0}function x(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function E(e,t){var n=t.length;return g((e=null==e?t.map((function(e,t){return t})):[].concat(e)).every((function(e){return e>=-n&&e<n})),(function(){return"All values in axis param must be in range [-".concat(n,", ").concat(n,") but ")+"got axis ".concat(e)})),g(e.every((function(e){return k(e)})),(function(){return"All values in axis param must be integers but "+"got axis ".concat(e)})),e.map((function(e){return e<0?n+e:e}))}function S(e,t){for(var n=[],r=[],a=null!=t&&Array.isArray(t)&&0===t.length,o=null==t||a?null:E(t,e).sort(),i=0,s=0;s<e.length;++s){if(null!=o){if(o[i]===s&&1!==e[s])throw new Error("Can't squeeze axis ".concat(s," since its dim '").concat(e[s],"' is not 1"));(null==o[i]||o[i]>s)&&1===e[s]&&(n.push(e[s]),r.push(s)),o[i]<=s&&i++}1!==e[s]&&(n.push(e[s]),r.push(s))}return{newShape:n,keptDims:r}}function A(e,t){return _(e,t)}function _(e,t){var n=null;if(null==e||"float32"===e)n=new Float32Array(t);else if("int32"===e)n=new Int32Array(t);else if("bool"===e)n=new Uint8Array(t);else{if("string"!==e)throw new Error("Unknown data type ".concat(e));n=new Array(t)}return n}function I(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(isNaN(r)||!isFinite(r))throw Error("A tensor of type ".concat(t," being uploaded contains ").concat(r,"."))}}function N(e){return"bool"===e||"complex64"===e||"float32"===e||"int32"===e||"string"===e}function M(e){if("float32"===e||"int32"===e)return 4;if("complex64"===e)return 8;if("bool"===e)return 1;throw new Error("Unknown dtype ".concat(e))}function T(e){if(null==e)return 0;var t=0;return e.forEach((function(e){return t+=e.length})),t}function D(e){return"string"==typeof e||e instanceof String}function R(e){return"boolean"==typeof e}function B(e){return"number"==typeof e}function F(e){return Array.isArray(e)?F(e[0]):e instanceof Float32Array?"float32":e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray?"int32":B(e)?"float32":D(e)?"string":R(e)?"bool":"float32"}function C(e){return!!(e&&e.constructor&&e.call&&e.apply)}function P(e,t){for(var n=t;n<e;++n)if(e%n==0)return n;return e}function O(e){var t=e.length;if(t<2)return[];var n=new Array(t-1);n[t-2]=e[t-1];for(var r=t-3;r>=0;--r)n[r]=n[r+1]*e[r+1];return n}function L(e,t,n,r){void 0===r&&(r=!1);var a=new Array;if(1===t.length)for(var o=t[0]*(r?2:1),i=0;i<o;i++)a[i]=n[e+i];else{o=t[0];var s=t.slice(1),u=s.reduce((function(e,t){return e*t}))*(r?2:1);for(i=0;i<o;i++)a[i]=L(e+i*u,s,n,r)}return a}function z(e,t,n){if(void 0===n&&(n=!1),0===e.length)return t[0];var r=e.reduce((function(e,t){return e*t}))*(n?2:1);if(0===r)return[];if(r!==t.length)throw new Error("[".concat(e,"] does not match the input size ").concat(t.length).concat(n?" for a complex tensor":"","."));return L(0,e,t,n)}function U(e,t){for(var n=W(e,t),r=0;r<n.length;r++)n[r]=1;return n}function W(e,t){if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t)return new Uint8Array(e);throw new Error("Unknown data type ".concat(t))}function G(e){e.forEach((function(t){g(Number.isInteger(t)&&t>=0,(function(){return"Tensor must have a shape comprised of positive integers but got "+"shape [".concat(e,"].")}))}))}function q(e){return e&&e.then&&"function"==typeof e.then}var K,V="tfjsflags",H=function(){function e(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=j,this.populateURLFlags()}return e.prototype.setPlatform=function(e,t){null!=this.platform&&(Z().getBool("IS_TEST")||Z().getBool("PROD")||console.warn("Platform ".concat(this.platformName," has already been set. ")+"Overwriting the platform with ".concat(e,"."))),this.platformName=e,this.platform=t},e.prototype.registerFlag=function(e,t,n){if(this.flagRegistry[e]={evaluationFn:t,setHook:n},null!=this.urlFlags[e]){var r=this.urlFlags[e];Z().getBool("IS_TEST")||Z().getBool("PROD")||console.warn("Setting feature override from URL ".concat(e,": ").concat(r,".")),this.set(e,r)}},e.prototype.getAsync=function(e){return a(this,void 0,void 0,(function(){var t,n;return o(this,(function(r){switch(r.label){case 0:return e in this.flags?[2,this.flags[e]]:(t=this.flags,n=e,[4,this.evaluateFlag(e)]);case 1:return t[n]=r.sent(),[2,this.flags[e]]}}))}))},e.prototype.get=function(e){if(e in this.flags)return this.flags[e];var t=this.evaluateFlag(e);if(q(t))throw new Error("Flag ".concat(e," cannot be synchronously evaluated. ")+"Please use getAsync() instead.");return this.flags[e]=t,this.flags[e]},e.prototype.getNumber=function(e){return this.get(e)},e.prototype.getBool=function(e){return this.get(e)},e.prototype.getString=function(e){return this.get(e)},e.prototype.getFlags=function(){return this.flags},Object.defineProperty(e.prototype,"features",{get:function(){return this.flags},enumerable:!1,configurable:!0}),e.prototype.set=function(e,t){if(null==this.flagRegistry[e])throw new Error("Cannot set flag ".concat(e," as it has not been registered."));this.flags[e]=t,null!=this.flagRegistry[e].setHook&&this.flagRegistry[e].setHook(t)},e.prototype.evaluateFlag=function(e){if(null==this.flagRegistry[e])throw new Error("Cannot evaluate flag '".concat(e,"': no evaluation function found."));return this.flagRegistry[e].evaluationFn()},e.prototype.setFlags=function(e){this.flags=Object.assign({},e)},e.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},e.prototype.populateURLFlags=function(){var e=this;if("undefined"!=typeof this.global&&"undefined"!=typeof this.global.location&&"undefined"!=typeof this.global.location.search){var t=this.getQueryParams(this.global.location.search);if(V in t)t.tfjsflags.split(",").forEach((function(t){var n=s(t.split(":"),2),r=n[0],a=n[1];e.urlFlags[r]=function(e,t){var n=t.toLowerCase();return"true"===n||"false"===n?"true"===n:"".concat(+n)===n?+n:t}(0,a)}))}},e}();function j(e){var t={};return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return J(t,n[0],n[1]),n.join("=")})),t}function J(e,t,n){e[decodeURIComponent(t)]=decodeURIComponent(n||"")}function Z(){return e.ENV}function Y(){if(null==K){var e=void 0;if("undefined"!=typeof window)e=window;else if("undefined"!=typeof global)e=global;else if("undefined"!=typeof process)e=process;else{if("undefined"==typeof self)throw new Error("Could not find a global object");e=self}K=e}return K}function X(e,t){var n,r=(null==(n=Y())._tfGlobals&&(n._tfGlobals=new Map),n._tfGlobals);if(r.has(e))return r.get(e);var a=t();return r.set(e,a),r.get(e)}e.ENV=null;var Q="Acos",$="Acosh",ee="Add",te="AddN",ne="ArgMax",re="ArgMin",ae="Asin",oe="Asinh",ie="Atan",se="Atanh",ue="Atan2",ce="AvgPool",le="AvgPool3D",he="BatchMatMul",fe="BatchToSpaceND",de="Bincount",pe="BitwiseAnd",ge="BroadcastArgs",ve="Cast",me="Ceil",ye="ClipByValue",be="Complex",we="ComplexAbs",ke="Concat",xe="Conv2D",Ee="Conv2DBackpropFilter",Se="Conv2DBackpropInput",Ae="Conv3D",_e="Conv3DBackpropInputV2",Ie="Cosh",Ne="Cumprod",Me="Cumsum",Te="CropAndResize",De="DenseBincount",Re="DepthToSpace",Be="DepthwiseConv2dNative",Fe="DepthwiseConv2dNativeBackpropFilter",Ce="DepthwiseConv2dNativeBackpropInput",Pe="Diag",Oe="Dilation2D",Le="Draw",ze="RealDiv",Ue="Einsum",We="Equal",Ge="ExpandDims",qe="Expm1",Ke="Fill",Ve="FlipLeftRight",He="Floor",je="FloorDiv",Je="FusedBatchNorm",Ze="GatherV2",Ye="GatherNd",Xe="Greater",Qe="GreaterEqual",$e="Identity",et="IFFT",tt="Imag",nt="IsFinite",rt="IsInf",at="IsNan",ot="LeakyRelu",it="Less",st="LessEqual",ut="LinSpace",ct="Log1p",lt="LogicalAnd",ht="LogicalNot",ft="LogicalOr",dt="Maximum",pt="MaxPool",gt="MaxPool3D",vt="MaxPoolWithArgmax",mt="Mean",yt="Minimum",bt="MirrorPad",wt="Multinomial",kt="Multiply",xt="NotEqual",Et="NonMaxSuppressionV3",St="NonMaxSuppressionV4",At="NonMaxSuppressionV5",_t="OnesLike",It="OneHot",Nt="Pack",Mt="PadV2",Tt="Prelu",Dt="Prod",Rt="RaggedGather",Bt="RaggedRange",Ft="RaggedTensorToTensor",Ct="Range",Pt="Real",Ot="Reciprocal",Lt="Relu",zt="Reshape",Ut="ResizeNearestNeighbor",Wt="ResizeBilinear",Gt="Relu6",qt="Reverse",Kt="Round",Vt="Rsqrt",Ht="ScatterNd",jt="TensorScatterUpdate",Jt="SearchSorted",Zt="Select",Yt="Selu",Xt="Slice",Qt="Sinh",$t="Sign",en="Sigmoid",tn="Softplus",nn="Sqrt",rn="SpaceToBatchND",an="SplitV",on="Softmax",sn="SparseFillEmptyRows",un="SparseReshape",cn="SparseSegmentMean",ln="SparseSegmentSum",hn="SparseToDense",fn="SquaredDifference",dn="StaticRegexReplace",pn="StridedSlice",gn="StringNGrams",vn="StringSplit",mn="StringToHashBucketFast",yn="Tanh",bn="Tile",wn="TopK",kn="Transform",xn="Transpose",En="Unique",Sn="Unpack",An="UnsortedSegmentSum",_n="ZerosLike",In="Step",Nn="FromPixels",Mn="RotateWithOffset",Tn="_FusedMatMul",Dn="FusedConv2D",Rn="FusedDepthwiseConv2D";function Bn(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];Z().getBool("IS_TEST")||Z().getBool("PROD")||console.warn.apply(console,u([],s(e),!1))}var Fn=X("kernelRegistry",(function(){return new Map})),Cn=X("gradRegistry",(function(){return new Map}));function Pn(e,t){var n=Un(e,t);return Fn.get(n)}function On(e){return Cn.get(e)}function Ln(e){for(var t=Fn.entries(),n=[];;){var r=t.next(),a=r.done,o=r.value;if(a)break;var i=s(o,2),u=i[0],c=i[1];s(u.split("_"),1)[0]===e&&n.push(c)}return n}function zn(e){var t=e.kernelName,n=e.backendName,r=Un(t,n);Fn.has(r)&&Bn("The kernel '".concat(t,"' for backend ")+"'".concat(n,"' is already registered")),Fn.set(r,e)}function Un(e,t){return"".concat(t,"_").concat(e)}function Wn(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray}var Gn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function qn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Kn=Hn,Vn=null;try{Vn=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function Hn(e,t,n){this.low=0|e,this.high=0|t,this.unsigned=!!n}function jn(e){return!0===(e&&e.__isLong__)}Hn.prototype.__isLong__,Object.defineProperty(Hn.prototype,"__isLong__",{value:!0}),Hn.isLong=jn;var Jn={},Zn={};function Yn(e,t){var n,r,a;return t?(a=0<=(e>>>=0)&&e<256)&&(r=Zn[e])?r:(n=Qn(e,(0|e)<0?-1:0,!0),a&&(Zn[e]=n),n):(a=-128<=(e|=0)&&e<128)&&(r=Jn[e])?r:(n=Qn(e,e<0?-1:0,!1),a&&(Jn[e]=n),n)}function Xn(e,t){if(isNaN(e))return t?sr:ir;if(t){if(e<0)return sr;if(e>=rr)return fr}else{if(e<=-ar)return dr;if(e+1>=ar)return hr}return e<0?Xn(-e,t).neg():Qn(e%nr|0,e/nr|0,t)}function Qn(e,t,n){return new Hn(e,t,n)}Hn.fromInt=Yn,Hn.fromNumber=Xn,Hn.fromBits=Qn;var $n=Math.pow;function er(e,t,n){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return ir;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return er(e.substring(1),t,n).neg();for(var a=Xn($n(n,8)),o=ir,i=0;i<e.length;i+=8){var s=Math.min(8,e.length-i),u=parseInt(e.substring(i,i+s),n);if(s<8){var c=Xn($n(n,s));o=o.mul(c).add(Xn(u))}else o=(o=o.mul(a)).add(Xn(u))}return o.unsigned=t,o}function tr(e,t){return"number"==typeof e?Xn(e,t):"string"==typeof e?er(e,t):Qn(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}Hn.fromString=er,Hn.fromValue=tr;var nr=4294967296,rr=nr*nr,ar=rr/2,or=Yn(1<<24),ir=Yn(0);Hn.ZERO=ir;var sr=Yn(0,!0);Hn.UZERO=sr;var ur=Yn(1);Hn.ONE=ur;var cr=Yn(1,!0);Hn.UONE=cr;var lr=Yn(-1);Hn.NEG_ONE=lr;var hr=Qn(-1,2147483647,!1);Hn.MAX_VALUE=hr;var fr=Qn(-1,-1,!0);Hn.MAX_UNSIGNED_VALUE=fr;var dr=Qn(0,-2147483648,!1);Hn.MIN_VALUE=dr;var pr=Hn.prototype;pr.toInt=function(){return this.unsigned?this.low>>>0:this.low},pr.toNumber=function(){return this.unsigned?(this.high>>>0)*nr+(this.low>>>0):this.high*nr+(this.low>>>0)},pr.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(dr)){var t=Xn(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var a=Xn($n(e,6),this.unsigned),o=this,i="";;){var s=o.div(a),u=(o.sub(s.mul(a)).toInt()>>>0).toString(e);if((o=s).isZero())return u+i;for(;u.length<6;)u="0"+u;i=""+u+i}},pr.getHighBits=function(){return this.high},pr.getHighBitsUnsigned=function(){return this.high>>>0},pr.getLowBits=function(){return this.low},pr.getLowBitsUnsigned=function(){return this.low>>>0},pr.getNumBitsAbs=function(){if(this.isNegative())return this.eq(dr)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},pr.isZero=function(){return 0===this.high&&0===this.low},pr.eqz=pr.isZero,pr.isNegative=function(){return!this.unsigned&&this.high<0},pr.isPositive=function(){return this.unsigned||this.high>=0},pr.isOdd=function(){return 1==(1&this.low)},pr.isEven=function(){return 0==(1&this.low)},pr.equals=function(e){return jn(e)||(e=tr(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},pr.eq=pr.equals,pr.notEquals=function(e){return!this.eq(e)},pr.neq=pr.notEquals,pr.ne=pr.notEquals,pr.lessThan=function(e){return this.comp(e)<0},pr.lt=pr.lessThan,pr.lessThanOrEqual=function(e){return this.comp(e)<=0},pr.lte=pr.lessThanOrEqual,pr.le=pr.lessThanOrEqual,pr.greaterThan=function(e){return this.comp(e)>0},pr.gt=pr.greaterThan,pr.greaterThanOrEqual=function(e){return this.comp(e)>=0},pr.gte=pr.greaterThanOrEqual,pr.ge=pr.greaterThanOrEqual,pr.compare=function(e){if(jn(e)||(e=tr(e)),this.eq(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},pr.comp=pr.compare,pr.negate=function(){return!this.unsigned&&this.eq(dr)?dr:this.not().add(ur)},pr.neg=pr.negate,pr.add=function(e){jn(e)||(e=tr(e));var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,o=e.high>>>16,i=65535&e.high,s=e.low>>>16,u=0,c=0,l=0,h=0;return l+=(h+=a+(65535&e.low))>>>16,c+=(l+=r+s)>>>16,u+=(c+=n+i)>>>16,u+=t+o,Qn((l&=65535)<<16|(h&=65535),(u&=65535)<<16|(c&=65535),this.unsigned)},pr.subtract=function(e){return jn(e)||(e=tr(e)),this.add(e.neg())},pr.sub=pr.subtract,pr.multiply=function(e){if(this.isZero())return ir;if(jn(e)||(e=tr(e)),Vn)return Qn(Vn.mul(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned);if(e.isZero())return ir;if(this.eq(dr))return e.isOdd()?dr:ir;if(e.eq(dr))return this.isOdd()?dr:ir;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(or)&&e.lt(or))return Xn(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,o=e.high>>>16,i=65535&e.high,s=e.low>>>16,u=65535&e.low,c=0,l=0,h=0,f=0;return h+=(f+=a*u)>>>16,l+=(h+=r*u)>>>16,h&=65535,l+=(h+=a*s)>>>16,c+=(l+=n*u)>>>16,l&=65535,c+=(l+=r*s)>>>16,l&=65535,c+=(l+=a*i)>>>16,c+=t*u+n*s+r*i+a*o,Qn((h&=65535)<<16|(f&=65535),(c&=65535)<<16|(l&=65535),this.unsigned)},pr.mul=pr.multiply,pr.divide=function(e){if(jn(e)||(e=tr(e)),e.isZero())throw Error("division by zero");var t,n,r;if(Vn)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?Qn((this.unsigned?Vn.div_u:Vn.div_s)(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?sr:ir;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return sr;if(e.gt(this.shru(1)))return cr;r=sr}else{if(this.eq(dr))return e.eq(ur)||e.eq(lr)?dr:e.eq(dr)?ur:(t=this.shr(1).div(e).shl(1)).eq(ir)?e.isNegative()?ur:lr:(n=this.sub(e.mul(t)),r=t.add(n.div(e)));if(e.eq(dr))return this.unsigned?sr:ir;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=ir}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(t)/Math.LN2),o=a<=48?1:$n(2,a-48),i=Xn(t),s=i.mul(e);s.isNegative()||s.gt(n);)s=(i=Xn(t-=o,this.unsigned)).mul(e);i.isZero()&&(i=ur),r=r.add(i),n=n.sub(s)}return r},pr.div=pr.divide,pr.modulo=function(e){return jn(e)||(e=tr(e)),Vn?Qn((this.unsigned?Vn.rem_u:Vn.rem_s)(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},pr.mod=pr.modulo,pr.rem=pr.modulo,pr.not=function(){return Qn(~this.low,~this.high,this.unsigned)},pr.and=function(e){return jn(e)||(e=tr(e)),Qn(this.low&e.low,this.high&e.high,this.unsigned)},pr.or=function(e){return jn(e)||(e=tr(e)),Qn(this.low|e.low,this.high|e.high,this.unsigned)},pr.xor=function(e){return jn(e)||(e=tr(e)),Qn(this.low^e.low,this.high^e.high,this.unsigned)},pr.shiftLeft=function(e){return jn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Qn(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):Qn(0,this.low<<e-32,this.unsigned)},pr.shl=pr.shiftLeft,pr.shiftRight=function(e){return jn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Qn(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):Qn(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},pr.shr=pr.shiftRight,pr.shiftRightUnsigned=function(e){if(jn(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?Qn(this.low>>>e|t<<32-e,t>>>e,this.unsigned):Qn(32===e?t:t>>>e-32,0,this.unsigned)},pr.shru=pr.shiftRightUnsigned,pr.shr_u=pr.shiftRightUnsigned,pr.toSigned=function(){return this.unsigned?Qn(this.low,this.high,!1):this},pr.toUnsigned=function(){return this.unsigned?this:Qn(this.low,this.high,!0)},pr.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},pr.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},pr.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},Hn.fromBytes=function(e,t,n){return n?Hn.fromBytesLE(e,t):Hn.fromBytesBE(e,t)},Hn.fromBytesLE=function(e,t){return new Hn(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},Hn.fromBytesBE=function(e,t){return new Hn(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};var gr=qn(Kn),vr=gr||t({__proto__:null,default:gr},[Kn]);function mr(e){return vr.fromString(e,!0,16)}var yr=mr("c3a5c85c97cb3127"),br=mr("b492b66fbe98f273"),wr=mr("9ae16a3b2f90404f");function kr(e){return e.xor(e.shru(47))}function xr(e,t,n){var r=e.slice(t,t+n);return vr.fromBytes(Array.from(r),!0,!0)}function Er(e,t){return xr(e,t,8)}function Sr(e,t){return xr(e,t,4)}function Ar(e,t){return 0===t?e:e.shru(t).or(e.shl(64-t))}function _r(e,t,n){void 0===n&&(n=mr("9ddfea08eb382d69"));var r=e.xor(t).mul(n);r=r.xor(r.shru(47));var a=t.xor(r).mul(n);return a=(a=a.xor(a.shru(47))).mul(n)}function Ir(e,t,n,r){return function(e,t,n,r,a,o){a=a.add(e),o=Ar(o.add(a).add(r),21);var i=a;return a=(a=a.add(t)).add(n),o=o.add(Ar(a,44)),[a.add(r),o.add(i)]}(Er(e,t),Er(e,t+8),Er(e,t+16),Er(e,t+24),n,r)}function Nr(e,t){if("string"===t)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=Br(e)),Z().getBool("DEBUG")&&I(e,t),function(e,t){return e instanceof Float32Array&&"float32"===t||e instanceof Int32Array&&"int32"===t||e instanceof Uint8Array&&"bool"===t}(e,t))return e;if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t){for(var n=new Uint8Array(e.length),r=0;r<n.length;++r)0!==Math.round(e[r])&&(n[r]=1);return n}throw new Error("Unknown data type ".concat(t))}function Mr(){return Z().platform.now()}function Tr(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",Z().platform.encode(e,t)}function Dr(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",Z().platform.decode(e,t)}function Rr(e){return null!=Z().platform.isTypedArray?Z().platform.isTypedArray(e):Wn(e)}function Br(e,t,n){var r,a;if(void 0===t&&(t=[]),void 0===n&&(n=!1),null==t&&(t=[]),"boolean"==typeof e||"number"==typeof e||"string"==typeof e||q(e)||null==e||Rr(e)&&n)t.push(e);else if(Array.isArray(e)||Rr(e))for(var o=0;o<e.length;++o)Br(e[o],t,n);else{var s=-1;try{for(var u=i(Object.keys(e)),c=u.next();!c.done;c=u.next()){var l=c.value;/^([1-9]+[0-9]*|0)$/.test(l)&&(s=Math.max(s,Number(l)))}}catch(e){r={error:e}}finally{try{c&&!c.done&&(a=u.return)&&a.call(u)}finally{if(r)throw r.error}}for(o=0;o<=s;o++)Br(e[o],t,n)}return t}var Fr={__proto__:null,arraysEqual:w,arraysEqualWithNull:b,assert:g,assertNonNegativeIntegerDimensions:G,assertNonNull:m,assertShapesMatch:v,bytesFromStringArray:T,bytesPerElement:M,checkConversionForErrors:I,clamp:d,computeStrides:O,convertBackendValuesAndArrayBuffer:function(e,t){if(Array.isArray(e))return e;if("float32"===t)return e instanceof Float32Array?e:new Float32Array(e);if("int32"===t)return e instanceof Int32Array?e:new Int32Array(e);if("bool"===t||"string"===t)return Uint8Array.from(new Int32Array(e));throw new Error("Unknown dtype ".concat(t))},createScalarValue:function(e,t){return"string"===t?Tr(e):Nr([e],t)},createShuffledIndices:function(e){for(var t=new Uint32Array(e),n=0;n<e;++n)t[n]=n;return f(t),t},decodeString:Dr,distSquared:function(e,t){for(var n=0,r=0;r<e.length;r++){var a=Number(e[r])-Number(t[r]);n+=a*a}return n},encodeString:Tr,fetch:function(e,t){return Z().platform.fetch(e,t)},fingerPrint64:function(e,t){var n,r;void 0===t&&(t=e.length);var a=vr.fromNumber(81,!0);if(t<=32)return t<=16?function(e,t){if(void 0===t&&(t=e.length),t>=8){var n=wr.add(2*t),r=Er(e,0).add(wr);return _r(Ar(a=Er(e,t-8),37).mul(n).add(r),Ar(r,25).add(a).mul(n),n)}if(t>=4)return n=wr.add(2*t),_r((r=Sr(e,0)).shl(3).add(t),Sr(e,t-4),n);if(t>0){var a,o=(r=e[0])+((a=e[t>>1])<<8),i=t+(e[t-1]<<2);return kr(wr.mul(o).xor(yr.mul(i))).mul(wr)}return wr}(e,t):function(e,t){void 0===t&&(t=e.length);var n=wr.add(2*t),r=Er(e,0).mul(br),a=Er(e,8),o=Er(e,t-8).mul(n),i=Er(e,t-16).mul(wr);return _r(Ar(r.add(a),43).add(Ar(o,30)).add(i),r.add(Ar(a.add(wr),18)).add(o),n)}(e,t);if(t<=64)return function(e,t){void 0===t&&(t=e.length);var n=wr.add(2*t),r=Er(e,0).mul(wr),a=Er(e,8),o=Er(e,t-8).mul(n),i=Er(e,t-16).mul(wr),s=Ar(r.add(a),43).add(Ar(o,30)).add(i),u=_r(s,r.add(Ar(a.add(wr),18)).add(o),n),c=Er(e,16).mul(n),l=Er(e,24),h=s.add(Er(e,t-32)).mul(n),f=u.add(Er(e,t-24)).mul(n);return _r(Ar(c.add(l),43).add(Ar(h,30)).add(f),c.add(Ar(l.add(r),18)).add(h),n)}(e,t);var o=a,i=a.mul(br).add(113),u=kr(i.mul(wr).add(113)).mul(wr),c=[vr.UZERO,vr.UZERO],l=[vr.UZERO,vr.UZERO];o=o.mul(wr).add(Er(e,0));var h=0,f=64*(t-1>>6),d=f+(t-1&63)-63;do{o=Ar(o.add(i).add(c[0]).add(Er(e,h+8)),37).mul(br),i=Ar(i.add(c[1]).add(Er(e,h+48)),42).mul(br),o=o.xor(l[1]),i=i.add(c[0]).add(Er(e,h+40)),u=Ar(u.add(l[0]),33).mul(br),c=Ir(e,h,c[1].mul(br),o.add(l[0])),l=Ir(e,h+32,u.add(l[1]),i.add(Er(e,h+16))),u=(n=s([o,u],2))[0],o=n[1],h+=64}while(h!==f);var p=br.add(u.and(255).shl(1));return h=d,l[0]=l[0].add(t-1&63),c[0]=c[0].add(l[0]),l[0]=l[0].add(c[0]),o=Ar(o.add(i).add(c[0]).add(Er(e,h+8)),37).mul(p),i=Ar(i.add(c[1]).add(Er(e,h+48)),42).mul(p),o=o.xor(l[1].mul(9)),i=i.add(c[0].mul(9).add(Er(e,h+40))),u=Ar(u.add(l[0]),33).mul(p),c=Ir(e,h,c[1].mul(p),o.add(l[0])),l=Ir(e,h+32,u.add(l[1]),i.add(Er(e,h+16))),u=(r=s([o,u],2))[0],o=r[1],_r(_r(c[0],l[0],p).add(kr(i).mul(yr)).add(u),_r(c[1],l[1],p).add(o),p)},flatten:Br,getArrayFromDType:_,getTypedArrayFromDType:A,hasEncodingLoss:function(e,t){return"complex64"!==t&&(("float32"!==t||"complex64"===e)&&(("int32"!==t||"float32"===e||"complex64"===e)&&("bool"!==t||"bool"!==e)))},hexToLong:mr,indexToLoc:function(e,t,n){if(0===t)return[];if(1===t)return[e];for(var r=new Array(t),a=0;a<r.length-1;++a)r[a]=Math.floor(e/n[a]),e-=r[a]*n[a];return r[r.length-1]=e,r},inferDtype:F,inferFromImplicitShape:function(e,t){for(var n=1,r=-1,a=0;a<e.length;++a)if(e[a]>=0)n*=e[a];else if(-1===e[a]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. "+"Found -1 at dim ".concat(r," and dim ").concat(a));r=a}else if(e[a]<0)throw Error("Shapes can not be < 0. Found ".concat(e[a]," at dim ").concat(a));if(-1===r){if(t>0&&t!==n)throw Error("Size(".concat(t,") must match the product of shape ").concat(e));return e}if(0===n)throw Error("Cannot infer the missing size in [".concat(e,"] when ")+"there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. "+"Got ".concat(t," / ").concat(n));var o=e.slice();return o[r]=t/n,o},isBoolean:R,isFunction:C,isInt:k,isNumber:B,isPromise:q,isScalarShape:function(e){return 0===e.length},isString:D,isTypedArray:Rr,isValidDtype:N,locToIndex:function(e,t,n){if(0===t)return 0;if(1===t)return e[0];for(var r=e[e.length-1],a=0;a<e.length-1;++a)r+=n[a]*e[a];return r},makeOnesTypedArray:U,makeZerosNestedTypedArray:function(e,t){var n=e.reduce((function(e,t){return e*t}),1);if(null==t||"float32"===t)return z(e,new Float32Array(n));if("int32"===t)return z(e,new Int32Array(n));if("bool"===t)return z(e,new Uint8Array(n));throw new Error("Unknown data type ".concat(t))},makeZerosTypedArray:W,nearestDivisor:P,nearestLargerEven:function(e){return e%2==0?e:e+1},now:Mr,parseAxisParam:E,randUniform:function(e,t){var n=Math.random();return t*n+(1-n)*e},repeatedTry:function(e,t,n,r){return void 0===t&&(t=function(e){return 0}),new Promise((function(a,o){var i=0,s=function(){if(e())a();else{i++;var u=t(i);null!=n&&i>=n?o():null!=r?r(s,u):setTimeout(s,u)}};s()}))},rightPad:x,shuffle:f,shuffleCombo:function(e,t){if(e.length!==t.length)throw new Error("Array sizes must match to be shuffled together "+"First array length was ".concat(e.length)+"Second array length was ".concat(t.length));for(var n=e.length,r=0;n>0;)r=Math.random()*n|0,p(e,--n,r),p(t,n,r)},sizeFromShape:y,sizeToSquarishShape:function(e){var t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)]},squeezeShape:S,sum:function(e){for(var t=0,n=0;n<e.length;n++)t+=e[n];return t},swap:p,tanh:function(e){if(null!=Math.tanh)return Math.tanh(e);if(e===1/0)return 1;if(e===-1/0)return-1;var t=Math.exp(2*e);return(t-1)/(t+1)},toNestedArray:z,toTypedArray:Nr},Cr=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new Pr)}return e.prototype.profileKernel=function(e,t,n){var r,a,o,s,u=function(){o=n()},c=Mr();if(this.backendTimer.timerAvailable())s=this.backendTimer.time(u);else{u();try{for(var l=i(o),h=l.next();!h.done;h=l.next()){h.value.dataSync()}}catch(e){r={error:e}}finally{try{h&&!h.done&&(a=l.return)&&a.call(l)}finally{if(r)throw r.error}}s=Promise.resolve({kernelMs:Mr()-c})}if(Z().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(var f=function(t){var n=o[t];n.data().then((function(t){!function(e,t,n){if("float32"!==t)return!1;for(var r=0;r<e.length;r++){var a=e[r];if(isNaN(a)||!isFinite(a))return console.warn("Found ".concat(a," in the result of '").concat(n,"'")),!0}}(t,n.dtype,e)}))},d=0;d<o.length;d++)f(d);return{kernelName:e,outputs:o,inputs:t,timeMs:s.then((function(e){return e.kernelMs})),extraInfo:s.then((function(e){return null!=e.getExtraProfileInfo?e.getExtraProfileInfo():""}))}},e.prototype.logKernelProfile=function(e){var t=this,n=e.kernelName,r=e.outputs,a=e.timeMs,o=e.inputs,i=e.extraInfo;r.forEach((function(e){Promise.all([e.data(),a,i]).then((function(r){t.logger.logKernelProfile(n,e,r[0],r[1],o,r[2])}))}))},e}();var Pr=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,r,a,o){var i="number"==typeof r?x("".concat(r,"ms"),9):r.error,s=x(e,25),u=t.rank,c=t.size,l=x(t.shape.toString(),14),h="";for(var f in a){var d=a[f];if(null!=d){var p=d.shape||t.shape,g=p.length;h+="".concat(f,": ").concat(g,"D ").concat(g>0?p:""," ")}}console.log("%c".concat(s,"\t%c").concat(i,"\t%c").concat(u,"D ").concat(l,"\t%c").concat(c,"\t%c").concat(h,"\t%c").concat(o),"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}();function Or(e,t,n,r){var a=O(t),o=function(e,t,n,r){var a=y(t),o=r[r.length-1],i=new Array(o).fill(0),s=t.length,u="complex64"===n?Wr(e):e;if(s>1)for(var c=0;c<a/o;c++)for(var l=c*o,h=0;h<o;h++)i[h]=Math.max(i[h],Lr(u[l+h],0,n).length);return i}(e,t,n,a),i=t.length,s=Ur(e,t,n,a,o),u=["Tensor"];return r&&(u.push(" dtype: ".concat(n)),u.push(" rank: ".concat(i)),u.push(" shape: [".concat(t,"]")),u.push(" values:")),u.push(s.map((function(e){return" "+e})).join("\n")),u.join("\n")}function Lr(e,t,n){return x(Array.isArray(e)?"".concat(parseFloat(e[0].toFixed(7))," + ")+"".concat(parseFloat(e[1].toFixed(7)),"j"):D(e)?"'".concat(e,"'"):"bool"===n?zr(e):parseFloat(e.toFixed(7)).toString(),t)}function zr(e){return 0===e?"false":"true"}function Ur(e,t,n,r,a,o){void 0===o&&(o=!0);var i="complex64"===n?2:1,c=t[0],l=t.length;if(0===l)return"complex64"===n?[Lr(Wr(e)[0],0,n)]:"bool"===n?[zr(e[0])]:[e[0].toString()];if(1===l){if(c>20){var h=3*i,f=Array.from(e.slice(0,h)),d=Array.from(e.slice((c-3)*i,c*i));return"complex64"===n&&(f=Wr(f),d=Wr(d)),["["+f.map((function(e,t){return Lr(e,a[t],n)})).join(", ")+", ..., "+d.map((function(e,t){return Lr(e,a[c-3+t],n)})).join(", ")+"]"]}return["["+("complex64"===n?Wr(e):Array.from(e)).map((function(e,t){return Lr(e,a[t],n)})).join(", ")+"]"]}var p=t.slice(1),g=r.slice(1),v=r[0]*i,m=[];if(c>20){for(var y=0;y<3;y++){var b=(w=y*v)+v;m.push.apply(m,u([],s(Ur(e.slice(w,b),p,n,g,a,!1)),!1))}m.push("...");for(y=c-3;y<c;y++){b=(w=y*v)+v;m.push.apply(m,u([],s(Ur(e.slice(w,b),p,n,g,a,y===c-1)),!1))}}else for(y=0;y<c;y++){var w;b=(w=y*v)+v;m.push.apply(m,u([],s(Ur(e.slice(w,b),p,n,g,a,y===c-1)),!1))}var k=2===l?",":"";m[0]="["+(c>0?m[0]+k:"");for(y=1;y<m.length-1;y++)m[y]=" "+m[y]+k;var x=",\n";for(y=2;y<l;y++)x+="\n";return m[m.length-1]=" "+m[m.length-1]+"]"+(o?"":x),m}function Wr(e){for(var t=[],n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var Gr=function(){function e(e,t,n){var r=this;if(this.dtype=t,this.shape=e.slice(),this.size=y(e),null!=n){var a=n.length;g(a===this.size,(function(){return"Length of values '".concat(a,"' does not match the size ")+"inferred by the shape '".concat(r.size,"'.")}))}if("complex64"===t)throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||_(t,this.size),this.strides=O(e)}return e.prototype.set=function(e){for(var t=this,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];0===n.length&&(n=[0]),g(n.length===this.rank,(function(){return"The number of provided coordinates (".concat(n.length,") must ")+"match the rank (".concat(t.rank,")")}));var a=this.locToIndex(n);this.values[a]=e},e.prototype.get=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];0===n.length&&(n=[0]);var a=0;try{for(var o=i(n),s=o.next();!s.done;s=o.next()){var u=s.value;if(u<0||u>=this.shape[a]){var c="Requested out of range element at ".concat(n,". ")+" Buffer shape=".concat(this.shape);throw new Error(c)}a++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}for(var l=n[n.length-1],h=0;h<n.length-1;++h)l+=this.strides[h]*n[h];return this.values[l]},e.prototype.locToIndex=function(e){if(0===this.rank)return 0;if(1===this.rank)return e[0];for(var t=e[e.length-1],n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t},e.prototype.indexToLoc=function(e){if(0===this.rank)return[];if(1===this.rank)return[e];for(var t=new Array(this.shape.length),n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t},Object.defineProperty(e.prototype,"rank",{get:function(){return this.shape.length},enumerable:!1,configurable:!0}),e.prototype.toTensor=function(){return qr().makeTensor(this.values,this.shape,this.dtype)},e}(),qr=null,Kr=null;var Vr=function(){function e(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=y(e),this.strides=O(e),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}return Object.defineProperty(e.prototype,"rank",{get:function(){return this.shape.length},enumerable:!1,configurable:!0}),e.prototype.buffer=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return[4,this.data()];case 1:return e=t.sent(),[2,Kr.buffer(this.shape,this.dtype,e)]}}))}))},e.prototype.bufferSync=function(){return Kr.buffer(this.shape,this.dtype,this.dataSync())},e.prototype.array=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return[4,this.data()];case 1:return e=t.sent(),[2,z(this.shape,e,"complex64"===this.dtype)]}}))}))},e.prototype.arraySync=function(){return z(this.shape,this.dataSync(),"complex64"===this.dtype)},e.prototype.data=function(){return a(this,void 0,void 0,(function(){var e,t;return o(this,(function(n){switch(n.label){case 0:return this.throwIfDisposed(),e=qr().read(this.dataId),"string"!==this.dtype?[3,2]:[4,e];case 1:t=n.sent();try{return[2,t.map((function(e){return Dr(e)}))]}catch(e){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}n.label=2;case 2:return[2,e]}}))}))},e.prototype.dataToGPU=function(e){return this.throwIfDisposed(),qr().readToGPU(this.dataId,e)},e.prototype.dataSync=function(){this.throwIfDisposed();var e=qr().readSync(this.dataId);if("string"===this.dtype)try{return e.map((function(e){return Dr(e)}))}catch(e){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e},e.prototype.bytes=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return this.throwIfDisposed(),[4,qr().read(this.dataId)];case 1:return e=t.sent(),"string"===this.dtype?[2,e]:[2,new Uint8Array(e.buffer)]}}))}))},e.prototype.dispose=function(){this.isDisposed||(this.kerasMask&&this.kerasMask.dispose(),qr().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(e.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!1,configurable:!0}),e.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},e.prototype.print=function(e){return void 0===e&&(e=!1),Kr.print(this,e)},e.prototype.clone=function(){return this.throwIfDisposed(),Kr.clone(this)},e.prototype.toString=function(e){return void 0===e&&(e=!1),Or(this.dataSync(),this.shape,this.dtype,e)},e.prototype.cast=function(e){return this.throwIfDisposed(),Kr.cast(this,e)},e.prototype.variable=function(e,t,n){return void 0===e&&(e=!0),this.throwIfDisposed(),qr().makeVariable(this,e,t,n)},e}();function Hr(){return X("Tensor",(function(){return Vr}))}Object.defineProperty(Vr,Symbol.hasInstance,{value:function(e){return!!e&&null!=e.data&&null!=e.dataSync&&null!=e.throwIfDisposed}}),Hr();var jr,Jr,Zr,Yr,Xr,Qr=function(e){function t(t,n,r,a){var o=e.call(this,t.shape,t.dtype,t.dataId,a)||this;return o.trainable=n,o.name=r,o}return r(t,e),t.prototype.assign=function(e){if(e.dtype!==this.dtype)throw new Error("dtype of the new value (".concat(e.dtype,") and ")+"previous value (".concat(this.dtype,") must match"));if(!w(e.shape,this.shape))throw new Error("shape of the new value (".concat(e.shape,") and ")+"previous value (".concat(this.shape,") must match"));qr().disposeTensor(this),this.dataId=e.dataId,qr().incRef(this,null)},t.prototype.dispose=function(){qr().disposeVariable(this),this.isDisposedInternal=!0},t}(Vr);Object.defineProperty(Qr,Symbol.hasInstance,{value:function(e){return e instanceof Vr&&null!=e.assign&&e.assign instanceof Function}}),e.Rank=void 0,(jr=e.Rank||(e.Rank={})).R0="R0",jr.R1="R1",jr.R2="R2",jr.R3="R3",jr.R4="R4",jr.R5="R5",jr.R6="R6",function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64"}(Jr||(Jr={})),function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64"}(Zr||(Zr={})),function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64"}(Yr||(Yr={})),function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64"}(Xr||(Xr={}));var $r={float32:Yr,int32:Jr,bool:Zr,complex64:Xr};function ea(e,t){if("string"===e||"string"===t){if("string"===e&&"string"===t)return"string";throw new Error("Can not upcast ".concat(e," with ").concat(t))}return $r[e][t]}function ta(e){return null!=e&&"object"==typeof e&&"texture"in e&&e.texture instanceof WebGLTexture}function na(e){return"undefined"!=typeof GPUBuffer&&null!=e&&"object"==typeof e&&"buffer"in e&&e.buffer instanceof GPUBuffer}function ra(e,t){if(e.dtype===t.dtype)return[e,t];var n=ea(e.dtype,t.dtype);return[e.cast(n),t.cast(n)]}function aa(e,t){g(e.dtype===t.dtype,(function(){return"The dtypes of the first(".concat(e.dtype,") and")+" second(".concat(t.dtype,") input must match")}))}function oa(e){var t=[];return ia(e,t,new Set),t}function ia(e,t,n){if(null!=e)if(e instanceof Vr)t.push(e);else if(r=e,Array.isArray(r)||"object"==typeof r){var r,a=e;for(var o in a){var i=a[o];n.has(i)||(n.add(i),ia(i,t,n))}}}var sa={__proto__:null,assertTypesMatch:aa,getTensorsInContainer:oa,isTensorInList:function(e,t){return t.some((function(t){return t.id===e.id}))},makeTypesMatch:ra};function ua(e){return null!=e.kernelName}var ca=function(){function e(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null,get kernelNames(){return Array.from(new Set(this.kernels.map((function(e){return e.name}))))}}}return e.prototype.dispose=function(){for(var e in this.registeredVariables)this.registeredVariables[e].dispose()},e}(),la=function(){function e(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new ca}return e.prototype.ready=function(){return a(this,void 0,void 0,(function(){var e,t,n;return o(this,(function(r){switch(r.label){case 0:if(null!=this.pendingBackendInit)return[2,this.pendingBackendInit.then((function(){}))];if(null!=this.backendInstance)return[2];e=this.getSortedBackends(),t=0,r.label=1;case 1:return t<e.length?(n=e[t],[4,this.initializeBackend(n).success]):[3,5];case 2:return r.sent()?[4,this.setBackend(n)]:[3,4];case 3:return r.sent(),[2];case 4:return t++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}}))}))},Object.defineProperty(e.prototype,"backend",{get:function(){if(null!=this.pendingBackendInit)throw new Error("Backend '".concat(this.backendName,"' has not yet been initialized. Make ")+"sure to await tf.ready() or await tf.setBackend() before calling other methods");if(null==this.backendInstance){var e=this.initializeBackendsAndReturnBest(),t=e.name;if(e.asyncInit)throw new Error("The highest priority backend '".concat(t,"' has not yet been ")+"initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");this.setBackend(t)}return this.backendInstance},enumerable:!1,configurable:!0}),e.prototype.backendNames=function(){return Object.keys(this.registryFactory)},e.prototype.findBackend=function(e){if(!(e in this.registry)){if(!(e in this.registryFactory))return null;if(this.initializeBackend(e).asyncInit)return null}return this.registry[e]},e.prototype.findBackendFactory=function(e){return e in this.registryFactory?this.registryFactory[e].factory:null},e.prototype.registerBackend=function(e,t,n){return void 0===n&&(n=1),e in this.registryFactory?(Bn("".concat(e," backend was already registered. ")+"Reusing existing backend factory."),!1):(this.registryFactory[e]={factory:t,priority:n},!0)},e.prototype.setBackend=function(e){return a(this,void 0,void 0,(function(){var t,n,r;return o(this,(function(a){switch(a.label){case 0:if(null==this.registryFactory[e])throw new Error("Backend name '".concat(e,"' not found in registry"));return this.backendName=e,null!=this.registry[e]?[3,4]:(this.backendInstance=null,t=this.initializeBackend(e),n=t.success,t.asyncInit?[4,n]:[3,2]);case 1:return r=a.sent(),[3,3];case 2:r=n,a.label=3;case 3:if(!r)return[2,!1];a.label=4;case 4:return this.backendInstance=this.registry[e],this.setupRegisteredKernels(),this.profiler=new Cr(this.backendInstance),[2,!0]}}))}))},e.prototype.setupRegisteredKernels=function(){var e=this;Ln(this.backendName).forEach((function(t){null!=t.setupFunc&&t.setupFunc(e.backendInstance)}))},e.prototype.disposeRegisteredKernels=function(e){var t=this;Ln(e).forEach((function(n){null!=n.disposeFunc&&n.disposeFunc(t.registry[e])}))},e.prototype.initializeBackend=function(e){var t=this,n=this.registryFactory[e];if(null==n)throw new Error("Cannot initialize backend ".concat(e,", no registration found."));try{var r=n.factory();if(!r||r instanceof l||"function"!=typeof r.then)return this.registry[e]=r,{success:!0,asyncInit:!1};var a=++this.pendingBackendInitId,o=r.then((function(n){return!(a<t.pendingBackendInitId)&&(t.registry[e]=n,t.pendingBackendInit=null,!0)})).catch((function(n){return a<t.pendingBackendInitId||(t.pendingBackendInit=null,Bn("Initialization of backend ".concat(e," failed")),Bn(n.stack||n.message)),!1}));return this.pendingBackendInit=o,{success:o,asyncInit:!0}}catch(t){return Bn("Initialization of backend ".concat(e," failed")),Bn(t.stack||t.message),{success:!1,asyncInit:!1}}},e.prototype.removeBackend=function(e){if(!(e in this.registryFactory))throw new Error("".concat(e," backend not found in registry"));this.backendName===e&&null!=this.pendingBackendInit&&this.pendingBackendInitId++,e in this.registry&&(this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e]),delete this.registryFactory[e],this.backendName===e&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},e.prototype.getSortedBackends=function(){var e=this;if(0===Object.keys(this.registryFactory).length)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort((function(t,n){return e.registryFactory[n].priority-e.registryFactory[t].priority}))},e.prototype.initializeBackendsAndReturnBest=function(){for(var e=this.getSortedBackends(),t=0;t<e.length;t++){var n=e[t],r=this.initializeBackend(n),a=r.success,o=r.asyncInit;if(o||a)return{name:n,asyncInit:o}}throw new Error("Could not initialize any backends, all backend initializations failed.")},e.prototype.moveData=function(e,t){var n=this.state.tensorInfo.get(t),r=n.backend,a=this.readSync(t),o=r.refCount(t);r.disposeData(t,!0),n.b