text: /**
   * @license
   * Copyright 2021 Google LLC. All Rights Reserved.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * =============================================================================
   */
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).tf=e.tf||{})}(this,(function(e){"use strict";var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,n)};function n(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(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 a(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])}}}var o=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}(),i=function(){function e(){}return e.prototype.refCount=function(e){return s("refCount")},e.prototype.incRef=function(e){return s("incRef")},e.prototype.timerAvailable=function(){return!0},e.prototype.time=function(e){return s("time")},e.prototype.read=function(e){return s("read")},e.prototype.readSync=function(e){return s("readSync")},e.prototype.numDataIds=function(){return s("numDataIds")},e.prototype.disposeData=function(e,t){return s("disposeData")},e.prototype.write=function(e,t,n){return s("write")},e.prototype.move=function(e,t,n,r,a){return s("move")},e.prototype.memory=function(){return s("memory")},e.prototype.floatPrecision=function(){return s("floatPrecision")},e.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},e.prototype.dispose=function(){return s("dispose")},e}();function s(e){throw new Error("'"+e+"' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen")}function u(e){for(var t=e.length,n=0,r=0;t>0;)r=Math.random()*t|0,n=e[--t],e[t]=e[r],e[r]=n}function l(e,t,n){return Math.max(e,Math.min(t,n))}function c(e,t){if(!e)throw new Error("string"==typeof t?t:t())}function f(e,t,n){void 0===n&&(n=""),c(v(e,t),(function(){return n+" Shapes "+e+" and "+t+" must match"}))}function h(e){c(null!=e,(function(){return"The input to the tensor constructor must be a non-null value."}))}function d(e,t,n){if(void 0===t&&(t=[]),void 0===n&&(n=!1),null==t&&(t=[]),Array.isArray(e)||S(e)&&!n)for(var r=0;r<e.length;++r)d(e[r],t,n);else t.push(e);return t}function p(e){if(0===e.length)return 1;for(var t=e[0],n=1;n<e.length;n++)t*=e[n];return t}function v(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 m(e){return e%1==0}function g(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function y(e,t){var n=t.length;return c((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 [-"+n+", "+n+") but got axis "+e})),c(e.every((function(e){return m(e)})),(function(){return"All values in axis param must be integers but got axis "+e})),e.map((function(e){return e<0?n+e:e}))}function b(e,t){for(var n=[],r=[],a=null!=t&&Array.isArray(t)&&0===t.length,o=null==t||a?null:y(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 "+s+" since its dim '"+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 w(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)throw new Error("Unknown data type "+e);n=new Uint8Array(t)}return n}function k(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 "+e);n=new Array(t)}return n}function x(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 "+t+" being uploaded contains "+r+".")}}function E(e){return"bool"===e||"complex64"===e||"float32"===e||"int32"===e||"string"===e}function S(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array}function A(e){if("float32"===e||"int32"===e)return 4;if("complex64"===e)return 8;if("bool"===e)return 1;throw new Error("Unknown dtype "+e)}function M(e){if(null==e)return 0;var t=0;return e.forEach((function(e){return t+=e.length})),t}function I(e){return"string"==typeof e||e instanceof String}function N(e){return"boolean"==typeof e}function _(e){return"number"==typeof e}function D(e){return Array.isArray(e)?D(e[0]):e instanceof Float32Array?"float32":e instanceof Int32Array||e instanceof Uint8Array?"int32":_(e)?"float32":I(e)?"string":N(e)?"bool":"float32"}function T(e){return!!(e&&e.constructor&&e.call&&e.apply)}function R(e,t){for(var n=t;n<e;++n)if(e%n==0)return n;return e}function F(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 C(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("["+e+"] does not match the input size "+t.length+(n?" for a complex tensor":"")+".");return function e(t,n,r,a){void 0===a&&(a=!1);var o=new Array;if(1===n.length)for(var i=n[0]*(a?2:1),s=0;s<i;s++)o[s]=r[t+s];else{i=n[0];var u=n.slice(1),l=u.reduce((function(e,t){return e*t}))*(a?2:1);for(s=0;s<i;s++)o[s]=e(t+s*l,u,r,a)}return o}(0,e,t,n)}function B(e,t){for(var n=P(e,t),r=0;r<n.length;r++)n[r]=1;return n}function P(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 "+t)}function L(e){e.forEach((function(t){c(Number.isInteger(t)&&t>=0,(function(){return"Tensor must have a shape comprised of positive integers but got shape ["+e+"]."}))}))}function z(e){return e&&e.then&&"function"==typeof e.then}var O,K=function(){function e(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=W,this.populateURLFlags()}return e.prototype.setPlatform=function(e,t){null!=this.platform&&console.warn("Platform "+this.platformName+" has already been set. Overwriting the platform with "+t+"."),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];console.warn("Setting feature override from URL "+e+": "+r+"."),this.set(e,r)}},e.prototype.getAsync=function(e){return r(this,void 0,void 0,(function(){var t,n;return a(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(z(t))throw new Error("Flag "+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.getFlags=function(){return this.flags},Object.defineProperty(e.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),e.prototype.set=function(e,t){if(null==this.flagRegistry[e])throw new Error("Cannot set flag "+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 '"+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(void 0!==this.global&&void 0!==this.global.location&&void 0!==this.global.location.search){var t=this.getQueryParams(this.global.location.search);if("tfjsflags"in t)t.tfjsflags.split(",").forEach((function(t){var n=t.split(":"),r=n[0],a=n[1];e.urlFlags[r]=function(e,t){if("true"===(t=t.toLowerCase())||"false"===t)return"true"===t;if(""+ +t===t)return+t;throw new Error("Could not parse value flag value "+t+" for flag "+e+".")}(r,a)}))}},e}();function W(e){var t={};return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return q(t,n[0],n[1]),n.join("=")})),t}function q(e,t,n){e[decodeURIComponent(t)]=decodeURIComponent(n||"")}function U(){return e.ENV}function G(){if(null==O){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}O=e}return O}function V(e,t){var n,r=(null==(n=G())._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 H=V("kernelRegistry",(function(){return new Map})),j=V("gradRegistry",(function(){return new Map}));function J(e,t){var n=$(e,t);return H.get(n)}function Y(e){return j.get(e)}function Z(e){for(var t=H.entries(),n=[];;){var r=t.next(),a=r.done,o=r.value;if(a)break;var i=o[0],s=o[1];i.split("_")[0]===e&&n.push(s)}return n}function X(e){var t=e.kernelName,n=e.backendName,r=$(t,n);H.has(r)&&console.warn("The kernel '"+t+"' for backend '"+n+"' is already registered"),H.set(r,e)}function $(e,t){return t+"_"+e}function Q(e,t){if("string"===t)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=d(e)),U().getBool("DEBUG")&&x(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 "+t)}function ee(){return U().platform.now()}function te(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",U().platform.encode(e,t)}function ne(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",U().platform.decode(e,t)}var re={__proto__:null,createScalarValue:function(e,t){return"string"===t?te(e):Q([e],t)},toTypedArray:Q,now:ee,fetch:function(e,t){return U().platform.fetch(e,t)},encodeString:te,decodeString:ne,shuffle:u,shuffleCombo:function(e,t){if(e.length!==t.length)throw new Error("Array sizes must match to be shuffled together First array length was "+e.length+"Second array length was "+t.length);for(var n,r,a=e.length,o=0;a>0;)o=Math.random()*a|0,n=e[--a],r=t[a],e[a]=e[o],t[a]=t[o],e[o]=n,t[o]=r},clamp:l,nearestLargerEven:function(e){return e%2==0?e:e+1},sum:function(e){for(var t=0,n=0;n<e.length;n++)t+=e[n];return t},randUniform:function(e,t){var n=Math.random();return t*n+(1-n)*e},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},assert:c,assertShapesMatch:f,assertNonNull:h,flatten:d,sizeFromShape:p,isScalarShape:function(e){return 0===e.length},arraysEqual:v,isInt:m,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)},sizeToSquarishShape:function(e){var t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)]},createShuffledIndices:function(e){for(var t=new Uint32Array(e),n=0;n<e;++n)t[n]=n;return u(t),t},rightPad:g,repeatedTry:function(e,t,n){return void 0===t&&(t=function(e){return 0}),new Promise((function(r,a){var o=0,i=function(){if(e())r();else{o++;var s=t(o);null!=n&&o>=n?a():setTimeout(i,s)}};i()}))},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 "+r+" and dim "+a);r=a}else if(e[a]<0)throw Error("Shapes can not be < 0. Found "+e[a]+" at dim "+a);if(-1===r){if(t>0&&t!==n)throw Error("Size("+t+") must match the product of shape "+e);return e}if(0===n)throw Error("Cannot infer the missing size in ["+e+"] when there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+t+" / "+n);var o=e.slice();return o[r]=t/n,o},parseAxisParam:y,squeezeShape:b,getTypedArrayFromDType:w,getArrayFromDType:k,checkConversionForErrors:x,isValidDtype:E,hasEncodingLoss:function(e,t){return"complex64"!==t&&(("float32"!==t||"complex64"===e)&&(("int32"!==t||"float32"===e||"complex64"===e)&&("bool"!==t||"bool"!==e)))},isTypedArray:S,bytesPerElement:A,bytesFromStringArray:M,isString:I,isBoolean:N,isNumber:_,inferDtype:D,isFunction:T,nearestDivisor:R,computeStrides:F,toNestedArray:C,makeOnesTypedArray:B,makeZerosTypedArray:P,makeZerosNestedTypedArray:function(e,t){var n=e.reduce((function(e,t){return e*t}),1);if(null==t||"float32"===t)return C(e,new Float32Array(n));if("int32"===t)return C(e,new Int32Array(n));if("bool"===t)return C(e,new Uint8Array(n));throw new Error("Unknown data type "+t)},assertNonNegativeIntegerDimensions:L,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},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},isPromise:z},ae=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new oe)}return e.prototype.profileKernel=function(e,t,n){var r,a,o=function(){r=n()},i=ee();if(this.backendTimer.timerAvailable())a=this.backendTimer.time(o);else{o();for(var s=0,u=r;s<u.length;s++){u[s].dataSync()}a=Promise.resolve({kernelMs:ee()-i})}if(U().getBool("CHECK_COMPUTATION_FOR_ERRORS"))for(var l=function(t){var n=r[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 "+a+" in the result of '"+n+"'"),!0}}(t,n.dtype,e)}))},c=0;c<r.length;c++)l(c);return{kernelName:e,outputs:r,inputs:t,timeMs:a.then((function(e){return e.kernelMs})),extraInfo:a.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 oe=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,r,a,o){var i="number"==typeof r?g(r+"ms",9):r.error,s=g(e,25),u=t.rank,l=t.size,c=g(t.shape.toString(),14),f="";for(var h in a){var d=a[h];if(null!=d){var p=d.shape||t.shape,v=p.length;f+=h+": "+v+"D "+(v>0?p:"")+" "}}console.log("%c"+s+"\t%c"+i+"\t%c"+u+"D "+c+"\t%c"+l+"\t%c"+f+"\t%c"+o,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}();function ie(e,t,n,r){var a=F(t),o=function(e,t,n,r){var a=p(t),o=r[r.length-1],i=new Array(o).fill(0),s=t.length,u="complex64"===n?le(e):e;if(s>1)for(var l=0;l<a/o;l++)for(var c=l*o,f=0;f<o;f++)i[f]=Math.max(i[f],se(u[c+f],0,n).length);return i}(e,t,n,a),i=t.length,s=function e(t,n,r,a,o,i){void 0===i&&(i=!0);var s="complex64"===r?2:1,u=n[0],l=n.length;if(0===l){return"complex64"===r?[se(le(t)[0],0,r)]:"bool"===r?[ue(t[0])]:[t[0].toString()]}if(1===l){if(u>20){var c=3*s,f=Array.from(t.slice(0,c)),h=Array.from(t.slice((u-3)*s,u*s));return"complex64"===r&&(f=le(f),h=le(h)),["["+f.map((function(e,t){return se(e,o[t],r)})).join(", ")+", ..., "+h.map((function(e,t){return se(e,o[u-3+t],r)})).join(", ")+"]"]}return["["+("complex64"===r?le(t):Array.from(t)).map((function(e,t){return se(e,o[t],r)})).join(", ")+"]"]}var d=n.slice(1),p=a.slice(1),v=a[0]*s,m=[];if(u>20){for(var g=0;g<3;g++){var y=(b=g*v)+v;m.push.apply(m,e(t.slice(b,y),d,r,p,o,!1))}m.push("...");for(g=u-3;g<u;g++){y=(b=g*v)+v;m.push.apply(m,e(t.slice(b,y),d,r,p,o,g===u-1))}}else for(g=0;g<u;g++){var b;y=(b=g*v)+v;m.push.apply(m,e(t.slice(b,y),d,r,p,o,g===u-1))}var w=2===l?",":"";m[0]="["+m[0]+w;for(g=1;g<m.length-1;g++)m[g]=" "+m[g]+w;var k=",\n";for(g=2;g<l;g++)k+="\n";return m[m.length-1]=" "+m[m.length-1]+"]"+(i?"":k),m}(e,t,n,a,o),u=["Tensor"];return r&&(u.push("  dtype: "+n),u.push("  rank: "+i),u.push("  shape: ["+t+"]"),u.push("  values:")),u.push(s.map((function(e){return"    "+e})).join("\n")),u.join("\n")}function se(e,t,n){return g(Array.isArray(e)?parseFloat(e[0].toFixed(7))+" + "+parseFloat(e[1].toFixed(7))+"j":I(e)?"'"+e+"'":"bool"===n?ue(e):parseFloat(e.toFixed(7)).toString(),t)}function ue(e){return 0===e?"false":"true"}function le(e){for(var t=[],n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var ce=function(){function e(e,t,n){var r=this;if(this.dtype=t,this.shape=e.slice(),this.size=p(e),null!=n){var a=n.length;c(a===this.size,(function(){return"Length of values '"+a+"' does not match the size inferred by the shape '"+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||k(t,this.size),this.strides=F(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]),c(n.length===this.rank,(function(){return"The number of provided coordinates ("+n.length+") must match the rank ("+t.rank+")"}));var a=this.locToIndex(n);this.values[a]=e},e.prototype.get=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];0===e.length&&(e=[0]);for(var n=0,r=0,a=e;r<a.length;r++){var o=a[r];if(o<0||o>=this.shape[n]){var i="Requested out of range element at "+e+".   Buffer shape="+this.shape;throw new Error(i)}n++}for(var s=e[e.length-1],u=0;u<e.length-1;++u)s+=this.strides[u]*e[u];return this.values[s]},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:!0,configurable:!0}),e.prototype.toTensor=function(){return fe().makeTensor(this.values,this.shape,this.dtype)},e}(),fe=null,he=null;var de=function(){function e(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=p(e),this.strides=F(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:!0,configurable:!0}),e.prototype.buffer=function(){return r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return[4,this.data()];case 1:return e=t.sent(),[2,he.buffer(this.shape,this.dtype,e)]}}))}))},e.prototype.bufferSync=function(){return he.buffer(this.shape,this.dtype,this.dataSync())},e.prototype.array=function(){return r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return[4,this.data()];case 1:return e=t.sent(),[2,C(this.shape,e,"complex64"===this.dtype)]}}))}))},e.prototype.arraySync=function(){return C(this.shape,this.dataSync(),"complex64"===this.dtype)},e.prototype.data=function(){return r(this,void 0,void 0,(function(){var e,t;return a(this,(function(n){switch(n.label){case 0:return this.throwIfDisposed(),e=fe().read(this.dataId),"string"!==this.dtype?[3,2]:[4,e];case 1:t=n.sent();try{return[2,t.map((function(e){return ne(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.dataSync=function(){this.throwIfDisposed();var e=fe().readSync(this.dataId);if("string"===this.dtype)try{return e.map((function(e){return ne(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 r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return this.throwIfDisposed(),[4,fe().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||(fe().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(e.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,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),he.print(this,e)},e.prototype.clone=function(){return this.throwIfDisposed(),he.clone(this)},e.prototype.toString=function(e){return void 0===e&&(e=!1),ie(this.dataSync(),this.shape,this.dtype,e)},e.prototype.cast=function(e){return this.throwIfDisposed(),he.cast(this,e)},e.prototype.variable=function(e,t,n){return void 0===e&&(e=!0),this.throwIfDisposed(),fe().makeVariable(this,e,t,n)},e}();Object.defineProperty(de,Symbol.hasInstance,{value:function(e){return!!e&&null!=e.data&&null!=e.dataSync&&null!=e.throwIfDisposed}}),V("Tensor",(function(){return de}));var pe,ve,me,ge,ye,be=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 n(t,e),t.prototype.assign=function(e){if(e.dtype!==this.dtype)throw new Error("dtype of the new value ("+e.dtype+") and previous value ("+this.dtype+") must match");if(!v(e.shape,this.shape))throw new Error("shape of the new value ("+e.shape+") and previous value ("+this.shape+") must match");fe().disposeTensor(this),this.dataId=e.dataId,fe().incRef(this,null)},t.prototype.dispose=function(){fe().disposeVariable(this),this.isDisposedInternal=!0},t}(de);Object.defineProperty(be,Symbol.hasInstance,{value:function(e){return e instanceof de&&null!=e.assign&&e.assign instanceof Function}}),(pe=e.Rank||(e.Rank={})).R0="R0",pe.R1="R1",pe.R2="R2",pe.R3="R3",pe.R4="R4",pe.R5="R5",pe.R6="R6",function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64"}(ve||(ve={})),function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64"}(me||(me={})),function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64"}(ge||(ge={})),function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64"}(ye||(ye={}));var we={float32:ge,int32:ve,bool:me,complex64:ye};function ke(e,t){if("string"===e||"string"===t){if("string"===e&&"string"===t)return"string";throw new Error("Can not upcast "+e+" with "+t)}return we[e][t]}function xe(e,t){if(e.dtype===t.dtype)return[e,t];var n=ke(e.dtype,t.dtype);return[e.cast(n),t.cast(n)]}function Ee(e,t){c(e.dtype===t.dtype,(function(){return"The dtypes of the first("+e.dtype+") and second("+t.dtype+") input must match"}))}function Se(e){var t=[];return function e(t,n,r){if(null==t)return;if(t instanceof de)return void n.push(t);if(a=t,!Array.isArray(a)&&"object"!=typeof a)return;var a;var o=t;for(var i in o){var s=o[i];r.has(s)||(r.add(s),e(s,n,r))}}(e,t,new Set),t}var Ae={__proto__:null,makeTypesMatch:xe,assertTypesMatch:Ee,isTensorInList:function(e,t){return t.some((function(t){return t.id===e.id}))},getTensorsInContainer:Se};function Me(e){return null!=e.kernelName}var Ie=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}(),Ne=function(){function e(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new Ie}return e.prototype.ready=function(){return r(this,void 0,void 0,(function(){var e,t,n;return a(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 '"+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 '"+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:!0,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?(console.warn(e+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[e]={factory:t,priority:n},!0)},e.prototype.setBackend=function(e){return r(this,void 0,void 0,(function(){var t,n,r;return a(this,(function(a){switch(a.label){case 0:if(null==this.registryFactory[e])throw new Error("Backend name '"+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 ae(this.backendInstance),[2,!0]}}))}))},e.prototype.setupRegisteredKernels=function(){var e=this;Z(this.backendName).forEach((function(t){null!=t.setupFunc&&t.setupFunc(e.backendInstance)}))},e.prototype.disposeRegisteredKernels=function(e){var t=this;Z(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 "+e+", no registration found.");try{var r=n.factory();if(!r||r instanceof i||"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,console.warn("Initialization of backend "+e+" failed"),console.warn(n.stack||n.message)),!1}));return this.pendingBackendInit=o,{success:o,asyncInit:!0}}catch(t){return console.warn("Initialization of backend "+e+" failed"),console.warn(t.stack||t.message),{success:!1,asyncInit:!1}}},e.prototype.removeBackend=function(e){if(!(e in this.registryFactory))throw new Error(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.backend=e,e.move(t,a,n.shape,n.dtype,o),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},e.prototype.tidy=function(e,t){var n,r=this,a=null;if(null==t){if("function"!=typeof e)throw new Error("Please provide a function to tidy()");t=e}else{if("string"!=typeof e&&!(e instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof t)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");a=e}return this.scopedRun((function(){return r.startScope(a)}),(function(){return r.endScope(n)}),(function(){return(n=t())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),n}))},e.prototype.scopedRun=function(e,t,n){e();try{var r=n();return t(),r}catch(e){throw t(),e}},e.prototype.nextTensorId=function(){return e.nextTensorId++},e.prototype.nextVariableId=function(){return e.nextVariableId++},e.prototype.clone=function(e){var t=De.runKernel("Identity",{x:e}),n={x:e};return this.addTapeNode(this.state.activeScope.name,n,[t],(function(e){return{x:function(){var t={x:e},n={dtype:"float32"};return De.runKernel("Cast",t,n)}}}),[],{}),t},e.prototype.runKernel=function(e,t,n){if(!(null!=J(e,this.backendName)))throw new Error("Kernel '"+e+"' not registered for backend '"+this.backendName+"'");return this.runKernelFunc({kernelName:e,inputs:t,attrs:n})},e.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},e.prototype.checkKernelForMemLeak=function(e,t,n){var r=this.backend.numDataIds(),a=0;n.forEach((function(e){a+="complex64"===e.dtype?3:1}));var o=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],i=r-t-a-o;if(i>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+i+" data ids) after running '"+e+"'")},e.prototype.runKernelFunc=function(e){var t,n,r,a=this,o=[],i=this.isTapeOn(),s=this.state.numBytes,u=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0),null==this.backendName&&this.backend;var l=Me(e)?e.kernelName:null!=this.state.activeScope?this.state.activeScope.name:"";if(Me(e)){var f=e.kernelName,h=e.inputs,d=e.attrs;null==this.backendName&&this.backend;var p=J(f,this.backendName);c(null!=p,(function(){return"Cannot find registered kernel '"+f+"' for backend '"+a.backendName+"'"})),n=function(){var e=a.backend.numDataIds();r=p.kernelFunc({inputs:h,attrs:d,backend:a.backend});var t=Array.isArray(r)?r:[r];a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(f,e,t);var n=t.map((function(e){if(null!=e.rank)return e;var t=e,n=t.dataId,r=t.shape,o=t.dtype;return a.makeTensorFromDataId(n,r,o)}));if(i){var s=a.getTensorsForGradient(f,h,n);o=a.saveTensorsForBackwardMode(s)}return n}}else{var v=e.forwardFunc,m=function(e){i&&(o=e.map((function(e){return a.keep(a.clone(e))})))};n=function(){var e=a.backend.numDataIds();r=a.tidy((function(){return v(a.backend,m)}));var t=Array.isArray(r)?r:[r];return a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(l,e,t),t}}var g,y=e.inputs,b=e.attrs,w=Me(e)?null:e.backwardsFunc;return this.scopedRun((function(){return a.state.kernelDepth++}),(function(){return a.state.kernelDepth--}),(function(){a.ENV.getBool("DEBUG")||a.state.profiling?(g=a.profiler.profileKernel(l,y,(function(){return n()})),a.ENV.getBool("DEBUG")&&a.profiler.logKernelProfile(g),t=g.outputs):t=n()})),i&&this.addTapeNode(l,y,t,w,o,b),this.state.profiling&&this.state.activeProfile.kernels.push({name:l,bytesAdded:this.state.numBytes-s,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-u,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(y).map((function(e){return null!=y[e]?y[e].shape:null})),outputShapes:t.map((function(e){return e.shape})),kernelTimeMs:g.timeMs,extraInfo:g.extraInfo}),Array.isArray(r)?t:t[0]},e.prototype.saveTensorsForBackwardMode=function(e){var t=this;return e.map((function(e){return t.keep(t.clone(e))}))},e.prototype.getTensorsForGradient=function(e,t,n){var r=Y(e);if(null!=r){var a=r.inputsToSave||[],o=r.outputsToSave||[],i=void 0;r.saveAllInputs?(c(Array.isArray(t),(function(){return"saveAllInputs is true, expected inputs to be an array."})),i=Object.keys(t).map((function(e){return t[e]}))):i=a.map((function(e){return t[e]}));var s=n.filter((function(e,t){return o[t]}));return i.concat(s)}return[]},e.prototype.makeTensor=function(e,t,n,r){if(null==e)throw new Error("Values passed to engine.makeTensor() are null");n=n||"float32",r=r||this.backend;var a=e;"string"===n&&I(e[0])&&(a=e.map((function(e){return te(e)})));var o=r.write(a,t,n),i=new de(t,n,o,this.nextTensorId());if(this.trackTensor(i,r),"string"===n){var s=this.state.tensorInfo.get(o),u=M(a);this.state.numBytes+=u-s.bytes,s.bytes=u}return i},e.prototype.makeTensorFromDataId=function(e,t,n,r){var a=new de(t,n=n||"float32",e,this.nextTensorId());return this.trackTensor(a,r),a},e.prototype.makeVariable=function(e,t,n,r){void 0===t&&(t=!0),n=n||this.nextVariableId().toString(),null!=r&&r!==e.dtype&&(e=e.cast(r));var a=new be(e,t,n,this.nextTensorId());if(null!=this.state.registeredVariables[a.name])throw new Error("Variable with name "+a.name+" was already registered");return this.state.registeredVariables[a.name]=a,this.incRef(a,this.backend),a},e.prototype.trackTensor=function(e,t){this.state.numTensors++,"string"===e.dtype&&this.state.numStringTensors++;var n=0;"complex64"!==e.dtype&&"string"!==e.dtype&&(n=e.size*A(e.dtype)),this.state.numBytes+=n,this.state.tensorInfo.has(e.dataId)||(this.state.numDataBuffers++,this.state.tensorInfo.set(e.dataId,{backend:t||this.backend,dtype:e.dtype,shape:e.shape,bytes:n})),e instanceof be||this.track(e)},e.prototype.incRef=function(e,t){this.trackTensor(e,t),this.backend.incRef(e.dataId)},e.prototype.removeDataId=function(e,t){this.state.tensorInfo.has(e)&&this.state.tensorInfo.get(e).backend===t&&(this.state.tensorInfo.delete(e),this.state.numDataBuffers--)},e.prototype.disposeTensor=function(e){if(this.state.tensorInfo.has(e.dataId)){var t=this.state.tensorInfo.get(e.dataId);if(this.state.numTensors--,"string"===e.dtype&&(this.state.numStringTensors--,this.state.numBytes-=t.bytes),"complex64"!==e.dtype&&"string"!==e.dtype){var n=e.size*A(e.dtype);this.state.numBytes-=n}t.backend.disposeData(e.dataId)&&this.removeDataId(e.dataId,t.backend)}},e.prototype.disposeVariables=function(){for(var e in this.state.registeredVariables){var t=this.state.registeredVariables[e];this.disposeVariable(t)}},e.prototype.disposeVariable=function(e){this.disposeTensor(e),null!=this.state.registeredVariables[e.name]&&delete this.state.registeredVariables[e.name]},e.prototype.memory=function(){var e=this.backend.memory();return e.numTensors=this.state.numTensors,e.numDataBuffers=this.state.numDataBuffers,e.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(e.unreliable=!0,null==e.reasons&&(e.reasons=[]),e.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),e},e.prototype.profile=function(e){return r(this,void 0,void 0,(function(){var t,n,r,o,i,s,u,l;return a(this,(function(a){switch(a.label){case 0:return this.state.profiling=!0,t=this.state.numBytes,n=this.state.numTensors,this.state.activeProfile.kernels=[],r=this.state.activeProfile,[4,e()];case 1:r.result=a.sent(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map((function(e){return e.totalBytesSnapshot}))),this.state.activeProfile.newBytes=this.state.numBytes-t,this.state.activeProfile.newTensors=this.state.numTensors-n,o=0,i=this.state.activeProfile.kernels,a.label=2;case 2:return o<i.length?(s=i[o],u=s,[4,s.kernelTimeMs]):[3,6];case 3:return u.kernelTimeMs=a.sent(),l=s,[4,s.extraInfo];case 4:l.extraInfo=a.sent(),a.label=5;case 5:return o++,[3,2];case 6:return[2,this.state.activeProfile]}}))}))},e.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&0===this.state.kernelDepth},e.prototype.addTapeNode=function(e,t,n,r,a,o){var i=this,s={id:this.state.nextTapeNodeId++,kernelName:e,inputs:t,outputs:n,saved:a},u=Y(e);null!=u&&(r=u.gradFunc),null!=r&&(s.gradient=function(e){return e=e.map((function(e,t){if(null==e){var r=n[t],a=P(r.size,r.dtype);return i.makeTensor(a,r.shape,r.dtype)}return e})),r(e.length>1?e:e[0],a,o)}),this.state.activeTape.push(s)},e.prototype.keep=function(e){return e.kept=!0,e},e.prototype.startTape=function(){0===this.state.gradientDepth&&(this.state.activeTape=[]),this.state.gradientDepth++},e.prototype.endTape=function(){this.state.gradientDepth--},e.prototype.startScope=function(e){var t={track:[],name:"unnamed scope",id:this.state.nextScopeId++};e&&(t.name=e),this.state.scopeStack.push(t),this.state.activeScope=t},e.prototype.endScope=function(e){for(var t=this,n=Se(e),r=new Set(n.map((function(e){return e.id}))),a=0;a<this.state.activeScope.track.length;a++){var o=this.state.activeScope.track[a];o.kept||r.has(o.id)||o.dispose()}var i=this.state.scopeStack.pop();this.state.activeScope=0===this.state.scopeStack.length?null:this.state.scopeStack[this.state.scopeStack.length-1],n.forEach((function(e){e.kept||e.scopeId!==i.id||t.track(e)}))},e.prototype.gradients=function(e,t,n,r){var a=this;if(void 0===r&&(r=!1),c(t.length>0,(function(){return"gradients() received an empty list of xs."})),null!=n&&"float32"!==n.dtype)throw new Error("dy must have 'float32' dtype, but has '"+n.dtype+"'");var o=this.scopedRun((function(){return a.startTape()}),(function(){return a.endTape()}),(function(){return a.tidy("forward",e)}));c(o instanceof de,(function(){return"The result y returned by f() must be a tensor."}));var i=function(e,t,n){for(var r={},a={},o=0;o<t.length;o++)r[t[o].id]=!0;for(o=0;o<e.length;o++){var i=(p=e[o]).inputs;for(var s in i){for(var u=i[s],l=!1,c=0;c<t.length;c++)if(r[u.id]){p.outputs.forEach((function(e){return r[e.id]=!0})),l=!0,a[p.id]=!0;break}if(l)break}}var f={};f[n.id]=!0;var h={};for(o=e.length-1;o>=0;o--)for(i=(p=e[o]).inputs,c=0;c<p.outputs.length;c++)if(f[p.outputs[c].id]){for(var s in i)f[i[s].id]=!0,h[p.id]=!0;break}var d=[];for(o=0;o<e.length;o++){var p;if(a[(p=e[o]).id]&&h[p.id]){var v={};for(var s in p.inputs){var m=p.inputs[s];r[m.id]&&(v[s]=m)}var g=Object.assign({},p);g.inputs=v,g.outputs=p.outputs,d.push(g)}}return d}(this.state.activeTape,t,o);if(!r&&0===i.length&&t.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");return this.tidy("backward",(function(){var e,r,s={};s[o.id]=null==n?(e=o.shape,r=B(p(e),"float32"),De.makeTensor(r,e,"float32")):n,function(e,t,n,r){for(var a=function(a){var o=t[a],i=[];if(o.outputs.forEach((function(t){var n=e[t.id];null!=n?i.push(n):i.push(null)})),null==o.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+o.kernelName+".");var s=o.gradient(i),u=function(t){if(!(t in s))throw new Error("Cannot backprop through input "+t+". Available gradients found: "+Object.keys(s)+".");var a=n((function(){return s[t]()}));if("float32"!==a.dtype)throw new Error("Error in gradient for op "+o.kernelName+". The gradient of input "+t+" must have 'float32' dtype, but has '"+a.dtype+"'");var i=o.inputs[t];if(!v(a.shape,i.shape))throw new Error("Error in gradient for op "+o.kernelName+". The gradient of input '"+t+"' has shape '"+a.shape+"', which does not match the shape of the input '"+i.shape+"'");if(null==e[i.id])e[i.id]=a;else{var u=e[i.id];e[i.id]=r(u,a),u.dispose()}};for(var l in o.inputs)u(l)},o=t.length-1;o>=0;o--)a(o)}(s,i,(function(e){return a.tidy(e)}),Te);var u=t.map((function(e){return s[e.id]}));return 0===a.state.gradientDepth&&(a.state.activeTape.forEach((function(e){for(var t=0,n=e.saved;t<n.length;t++){n[t].dispose()}})),a.state.activeTape=null),{value:o,grads:u}}))},e.prototype.customGrad=function(e){var t=this;return c(T(e),(function(){return"The f passed in customGrad(f) must be a function."})),function(){for(var n,r=[],a=0;a<arguments.length;a++)r[a]=arguments[a];c(r.every((function(e){return e instanceof de})),(function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"}));var o={};r.forEach((function(e,t){o[t]=e}));var i=function(t,a){return c((n=e.apply(void 0,r.concat([a]))).value instanceof de,(function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"})),c(T(n.gradFunc),(function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."})),n.value},s=function(e,t){var a=n.gradFunc(e,t),o=Array.isArray(a)?a:[a];c(o.length===r.length,(function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."})),c(o.every((function(e){return e instanceof de})),(function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."}));var i={};return o.forEach((function(e,t){i[t]=function(){return e}})),i};return t.runKernelFunc({forwardFunc:i,backwardsFunc:s,inputs:o})}},e.prototype.readSync=function(e){return this.state.tensorInfo.get(e).backend.readSync(e)},e.prototype.read=function(e){return this.state.tensorInfo.get(e).backend.read(e)},e.prototype.time=function(e){return r(this,void 0,void 0,(function(){var t,n;return a(this,(function(r){switch(r.label){case 0:return t=ee(),[4,this.backend.time(e)];case 1:return(n=r.sent()).wallMs=ee()-t,[2,n]}}))}))},e.prototype.track=function(e){return null!=this.state.activeScope&&(e.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(e)),e},Object.defineProperty(e.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),e.prototype.reset=function(){for(var e in this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new Ie,this.registry)this.disposeRegisteredKernels(e),this.registry[e].dispose(),delete this.registry[e];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},e.nextTensorId=0,e.nextVariableId=0,e}();function _e(){var t=G();if(null==t._tfengine){var n=new K(t);t._tfengine=new Ne(n)}return function(t){e.ENV=t}(t._tfengine.ENV),fe=function(){return t._tfengine},t._tfengine}var De=_e();function Te(e,t){var n={a:e,b:t};return De.runKernel("Add",n)}function Re(){return"undefined"!=typeof window&&null!=window.document||"undefined"!=typeof WorkerGlobalScope}var Fe={__proto__:null,isMobile:function(e){if(e||"undefined"!=typeof navigator&&null!=navigator){if(e||(e=navigator),"ReactNative"===e.product)return!0;var t=e.userAgent||e.vendor||window.opera;return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))}return!1},isBrowser:Re},Ce=U();function Be(e,t){var n=e;if(S(e))return"string"===t?[]:[e.length];if(!Array.isArray(e))return[];for(var r=[];Array.isArray(n)||S(n)&&"string"!==t;)r.push(n.length),n=n[0];return Array.isArray(e)&&U().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function e(t,n,r){if(r=r||[],!Array.isArray(t)&&!S(t))return void c(0===n.length,(function(){return"Element arr["+r.join("][")+"] is a primitive, but should be an array/TypedArray of "+n[0]+" elements"}));c(n.length>0,(function(){return"Element arr["+r.join("][")+"] should be a primitive, but is an array of "+t.length+" elements"})),c(t.length===n[0],(function(){return"Element arr["+r.join("][")+"] should have "+n[0]+" elements, but has "+t.length+" elements"}));for(var a=n.slice(1),o=0;o<t.length;++o)e(t[o],a,r.concat(o))}(e,r,[]),r}function Pe(e,t,n,r){if("string_or_numeric"!==e){if(null==e)throw new Error("Expected dtype cannot be null.");if("numeric"!==e&&e!==t||"numeric"===e&&"string"===t)throw new Error("Argument '"+n+"' passed to '"+r+"' must be "+e+" tensor, but got "+t+" tensor")}}function Le(e,t,n,r){if(void 0===r&&(r="numeric"),e instanceof de)return Pe(r,e.dtype,t,n),e;var a=D(e);if("string"!==a&&["bool","int32","float32"].indexOf(r)>=0&&(a=r),Pe(r,a,t,n),null==e||!S(e)&&!Array.isArray(e)&&"number"!=typeof e&&"boolean"!=typeof e&&"string"!=typeof e){var o=null==e?"null":e.constructor.name;throw new Error("Argument '"+t+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+o+"'")}var i=Be(e,a);S(e)||Array.isArray(e)||(e=[e]);var s="string"!==a?Q(e,a):d(e,[],!0);return De.makeTensor(s,i,a)}function ze(e,t,n,r){if(void 0===r&&(r="numeric"),!Array.isArray(e))throw new Error("Argument "+t+" passed to "+n+" must be a `Tensor[]` or `TensorLike[]`");return e.map((function(e,a){return Le(e,t+"["+a+"]",n,r)}))}Ce.registerFlag("DEBUG",(function(){return!1}),(function(e){e&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")})),Ce.registerFlag("IS_BROWSER",(function(){return Re()})),Ce.registerFlag("IS_NODE",(function(){return"undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.node})),Ce.registerFlag("IS_CHROME",(function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)})),Ce.registerFlag("PROD",(function(){return!1})),Ce.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",(function(){return Ce.getBool("DEBUG")})),Ce.registerFlag("DEPRECATION_WARNINGS_ENABLED",(function(){return!0})),Ce.registerFlag("IS_TEST",(function(){return!1})),Ce.registerFlag("CHECK_COMPUTATION_FOR_ERRORS",(function(){return!0})),Ce.registerFlag("WRAP_TO_IMAGEBITMAP",(function(){return!1}));function Oe(e){var t=Object.keys(e);if(1!==t.length)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+t.length+" keys.");var n=t[0],r=e[n];n.endsWith("_")&&(n=n.substring(0,n.length-1)),n+="__op";var a=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];De.startScope(n);try{var a=r.apply(void 0,e);return z(a)&&console.error("Cannot return a Promise inside of tidy."),De.endScope(a),a}catch(e){throw De.endScope(null),e}};return Object.defineProperty(a,"name",{value:n,configurable:!0}),a}var Ke=Oe({complex_:function(e,t){var n=Le(e,"real","complex"),r=Le(t,"imag","complex");f(n.shape,r.shape,"real and imag shapes, "+n.shape+" and "+r.shape+", must match in call to tf.complex().");var a={real:n,imag:r};return De.runKernel("Complex",a)}});function We(e,t,n,r){if(null==r&&(r=D(e)),"complex64"===r)throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!S(e)&&!Array.isArray(e)&&"number"!=typeof e&&"boolean"!=typeof e&&"string"!=typeof e)throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(null!=t){L(t);var a=p(t),o=p(n);c(a===o,(function(){return"Based on the provided shape, ["+t+"], the tensor should have "+a+" values but has "+o}));for(var i=0;i<n.length;++i){var s=n[i],u=i!==n.length-1||s!==p(t.slice(i));c(n[i]===t[i]||!u,(function(){return"Error creating a new Tensor. Inferred shape ("+n+") does not match the provided shape ("+t+"). "}))}}return S(e)||Array.isArray(e)||(e=[e]),t=t||n,e="string"!==r?Q(e,r):d(e,[],!0),De.makeTensor(e,t,r)}function qe(e,t,n){return We(e,t,Be(e,n),n)}var Ue={float32:4,float16:2,int32:4,uint16:2,uint8:1,bool:1,complex64:8};function Ge(e,t){for(var n,r={},a=0,o=0,i=t;o<i.length;o++){var s=i[o],u=s.name,l=s.dtype,c=s.shape,f=p(c),h=void 0;if("quantization"in s){var d=s.quantization;if("uint8"===d.dtype||"uint16"===d.dtype){if(!("min"in d)||!("scale"in d))throw new Error("Weight "+s.name+" with quantization "+d.dtype+" doesn't have corresponding metadata min and scale.")}else{if("float16"!==d.dtype)throw new Error("Weight "+s.name+" has unknown quantization dtype "+d.dtype+". Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'.");if("float32"!==l)throw new Error("Weight "+s.name+" is quantized with "+d.dtype+" which only supports weights of type float32 not "+l+".")}var v=Ue[d.dtype],m=e.slice(a,a+f*v),g="uint8"===d.dtype?new Uint8Array(m):new Uint16Array(m);if("float32"===l)if("uint8"===d.dtype||"uint16"===d.dtype){h=new Float32Array(g.length);for(var y=0;y<g.length;y++){var b=g[y];h[y]=b*d.scale+d.min}}else{if("float16"!==d.dtype)throw new Error("Unsupported quantization type "+d.dtype+" for weight type float32.");void 0===n&&(n=Xe()),h=n(g)}else{if("int32"!==l)throw new Error("Unsupported dtype in weight '"+u+"': "+l);if("uint8"!==d.dtype&&"uint16"!==d.dtype)throw new Error("Unsupported quantization type "+d.dtype+" for weight type int32.");h=new Int32Array(g.length);for(y=0;y<g.length;y++){b=g[y];h[y]=Math.round(b*d.scale+d.min)}}a+=f*v}else if("string"===l){var w=p(s.shape);h=[];for(y=0;y<w;y++){var k=new Uint32Array(e.slice(a,a+4))[0];a+=4;var x=new Uint8Array(e.slice(a,a+k));h.push(x),a+=k}}else{var E=Ue[l];m=e.slice(a,a+f*E);if("float32"===l)h=new Float32Array(m);else if("int32"===l)h=new Int32Array(m);else if("bool"===l)h=new Uint8Array(m);else{if("complex64"!==l)throw new Error("Unsupported dtype in weight '"+u+"': "+l);h=new Float32Array(m);var S=new Float32Array(h.length/2),A=new Float32Array(h.length/2);for(y=0;y<S.length;y++)S[y]=h[2*y],A[y]=h[2*y+1];var M=qe(S,c,"float32"),I=qe(A,c,"float32");r[u]=Ke(M,I),M.dispose(),I.dispose()}a+=f*E}"complex64"!==l&&(r[u]=qe(h,c,l))}return r}function Ve(e){if(null===e)throw new Error("Invalid input value: "+JSON.stringify(e));var t=0,n=[];e.forEach((function(e){if(t+=e.byteLength,n.push(e.byteLength===e.buffer.byteLength?e:new e.constructor(e)),!(e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+e.constructor.name)}));var r=new Uint8Array(t),a=0;return n.forEach((function(e){r.set(new Uint8Array(e.buffer),a),a+=e.byteLength})),r.buffer}var He="undefined"!=typeof Buffer&&("undefined"==typeof Blob||"undefined"==typeof atob||"undefined"==typeof btoa);function je(e){return He?Buffer.byteLength(e):new Blob([e]).size}function Je(e){if(1===e.length)return e[0];var t=0;e.forEach((function(e){t+=e.byteLength}));var n=new Uint8Array(t),r=0;return e.forEach((function(e){n.set(new Uint8Array(e),r),r+=e.byteLength})),n.buffer}function Ye(e){for(e=e.trim();e.endsWith("/");)e=e.slice(0,e.length-1);var t=e.split("/");return t[t.length-1]}function Ze(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:null==e.modelTopology?0:je(JSON.stringify(e.modelTopology)),weightSpecsBytes:null==e.weightSpecs?0:je(JSON.stringify(e.weightSpecs)),weightDataBytes:null==e.weightData?0:e.weightData.byteLength}}function Xe(){var e=function(){var e=function(e){for(var t=e<<13,n=0;0==(8388608&t);)n-=8388608,t<<=1;return(t&=-8388609)|(n+=947912704)},t=new Uint32Array(2048);t[0]=0;for(var n=1;n<1024;n++)t[n]=e(n);for(n=1024;n<2048;n++)t[n]=939524096+(n-1024<<13);return t}(),t=function(){var e=new Uint32Array(64);e[0]=0,e[31]=1199570944,e[32]=2147483648,e[63]=3347054592;for(var t=1;t<31;t++)e[t]=t<<23;for(t=33;t<63;t++)e[t]=2147483648+(t-32<<23);return e}(),n=function(){for(var e=new Uint32Array(64),t=0;t<64;t++)e[t]=1024;return e[0]=e[32]=0,e}();return function(r){for(var a=new ArrayBuffer(4*r.length),o=new Uint32Array(a),i=0;i<r.length;i++){var s=r[i],u=e[n[s>>10]+(1023&s)]+t[s>>10];o[i]=u}return new Float32Array(a)}}var $e=function(){function e(){this.saveRouters=[],this.loadRouters=[]}return e.getInstance=function(){return null==e.instance&&(e.instance=new e),e.instance},e.registerSaveRouter=function(t){e.getInstance().saveRouters.push(t)},e.registerLoadRouter=function(t){e.getInstance().loadRouters.push(t)},e.getSaveHandlers=function(t){return e.getHandlers(t,"save")},e.getLoadHandlers=function(t,n){return e.getHandlers(t,"load",n)},e.getHandlers=function(t,n,r){var a=[];return("load"===n?e.getInstance().loadRouters:e.getInstance().saveRouters).forEach((function(e){var n=e(t,r);null!==n&&a.push(n)})),a},e}();function Qe(){if(!U().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var e="undefined"==typeof window?self:window,t=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB||e.shimIndexedDB;if(null==t)throw new Error("The current browser does not appear to support IndexedDB.");return t}function et(e){var t=e.result;t.createObjectStore("models_store",{keyPath:"modelPath"}),t.createObjectStore("model_info_store",{keyPath:"modelPath"})}var tt=function(){function e(e){if(this.indexedDB=Qe(),null==e||!e)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=e}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(t){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,e)]}))}))},e.prototype.load=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){return[2,this.databaseAction(this.modelPath)]}))}))},e.prototype.databaseAction=function(e,t){var n=this;return new Promise((function(e,r){var a=n.indexedDB.open("tensorflowjs",1);a.onupgradeneeded=function(){return et(a)},a.onsuccess=function(){var o=a.result;if(null==t){var i=o.transaction("models_store","readonly"),s=i.objectStore("models_store").get(n.modelPath);s.onsuccess=function(){if(null==s.result)return o.close(),r(new Error("Cannot find model with path '"+n.modelPath+"' in IndexedDB."));e(s.result.modelArtifacts)},s.onerror=function(e){return o.close(),r(s.error)},i.oncomplete=function(){return o.close()}}else{var u,l=Ze(t),c=o.transaction("model_info_store","readwrite"),f=c.objectStore("model_info_store"),h=f.put({modelPath:n.modelPath,modelArtifactsInfo:l});h.onsuccess=function(){var a=(u=o.transaction("models_store","readwrite")).objectStore("models_store").put({modelPath:n.modelPath,modelArtifacts:t,modelArtifactsInfo:l});a.onsuccess=function(){return e({modelArtifactsInfo:l})},a.onerror=function(e){var t=(f=c.objectStore("model_info_store")).delete(n.modelPath);t.onsuccess=function(){return o.close(),r(a.error)},t.onerror=function(e){return o.close(),r(a.error)}}},h.onerror=function(e){return o.close(),r(h.error)},c.oncomplete=function(){null==u?o.close():u.oncomplete=function(){return o.close()}}}},a.onerror=function(e){return r(a.error)}}))},e.URL_SCHEME="indexeddb://",e}(),nt=function(e){return U().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(tt.URL_SCHEME)?(t=e.slice(tt.URL_SCHEME.length),new tt(t)):null;var t};$e.registerSaveRouter(nt),$e.registerLoadRouter(nt);var rt=function(){function e(){this.indexedDB=Qe()}return e.prototype.listModels=function(){return r(this,void 0,void 0,(function(){var e=this;return a(this,(function(t){return[2,new Promise((function(t,n){var r=e.indexedDB.open("tensorflowjs",1);r.onupgradeneeded=function(){return et(r)},r.onsuccess=function(){var e=r.result,a=e.transaction("model_info_store","readonly"),o=a.objectStore("model_info_store").getAll();o.onsuccess=function(){for(var e={},n=0,r=o.result;n<r.length;n++){var a=r[n];e[a.modelPath]=a.modelArtifactsInfo}t(e)},o.onerror=function(t){return e.close(),n(o.error)},a.oncomplete=function(){return e.close()}},r.onerror=function(e){return n(r.error)}}))]}))}))},e.prototype.removeModel=function(e){return r(this,void 0,void 0,(function(){var t=this;return a(this,(function(n){var r;return e=(r=e).startsWith(tt.URL_SCHEME)?r.slice(tt.URL_SCHEME.length):r,[2,new Promise((function(n,r){var a=t.indexedDB.open("tensorflowjs",1);a.onupgradeneeded=function(){return et(a)},a.onsuccess=function(){var t,o=a.result,i=o.transaction("model_info_store","readwrite"),s=i.objectStore("model_info_store"),u=s.get(e);u.onsuccess=function(){if(null==u.result)return o.close(),r(new Error("Cannot find model with path '"+e+"' in IndexedDB."));var a=s.delete(e),i=function(){var a=(t=o.transaction("models_store","readwrite")).objectStore("models_store").delete(e);a.onsuccess=function(){return n(u.result.modelArtifactsInfo)},a.onerror=function(e){return r(u.error)}};a.onsuccess=i,a.onerror=function(e){return i(),o.close(),r(u.error)}},u.onerror=function(e){return o.close(),r(u.error)},i.oncomplete=function(){null==t?o.close():t.oncomplete=function(){return o.close()}}},a.onerror=function(e){return r(a.error)}}))]}))}))},e}(),at="tensorflowjs_models",ot="info",it="model_topology",st="weight_specs",ut="weight_data",lt="model_metadata";function ct(e){return{info:[at,e,ot].join("/"),topology:[at,e,it].join("/"),weightSpecs:[at,e,st].join("/"),weightData:[at,e,ut].join("/"),modelMetadata:[at,e,lt].join("/")}}function ft(e){var t=e.split("/");if(t.length<3)throw new Error("Invalid key format: "+e);return t.slice(1,t.length-1).join("/")}var ht=function(){function e(e){if(!U().getBool("IS_BROWSER")||"undefined"==typeof window||void 0===window.localStorage)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,null==e||!e)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=e,this.keys=ct(this.modelPath)}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){var t,n,r,o;return a(this,(function(a){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");t=JSON.stringify(e.modelTopology),n=JSON.stringify(e.weightSpecs),r=Ze(e);try{return this.LS.setItem(this.keys.info,JSON.stringify(r)),this.LS.setItem(this.keys.topology,t),this.LS.setItem(this.keys.weightSpecs,n),this.LS.setItem(this.keys.weightData,function(e){if(He)return Buffer.from(e).toString("base64");for(var t=new Uint8Array(e),n="",r=0,a=t.length;r<a;r++)n+=String.fromCharCode(t[r]);return btoa(n)}(e.weightData)),o={format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy},null!=e.signature&&(o.signature=e.signature),null!=e.userDefinedMetadata&&(o.userDefinedMetadata=e.userDefinedMetadata),null!=e.modelInitializer&&(o.modelInitializer=e.modelInitializer),this.LS.setItem(this.keys.modelMetadata,JSON.stringify(o)),[2,{modelArtifactsInfo:r}]}catch(e){throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes="+r.modelTopologyBytes+", weightSpecsBytes="+r.weightSpecsBytes+", weightDataBytes="+r.weightDataBytes+".")}return[2]}))}))},e.prototype.load=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,i,s;return a(this,(function(a){if(null==(e=JSON.parse(this.LS.getItem(this.keys.info))))throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if("JSON"!==e.modelTopologyType)throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(t={},null==(n=JSON.parse(this.LS.getItem(this.keys.topology))))throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(t.modelTopology=n,null==(r=JSON.parse(this.LS.getItem(this.keys.weightSpecs))))throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(t.weightSpecs=r,null!=(o=this.LS.getItem(this.keys.modelMetadata))&&(i=JSON.parse(o),t.format=i.format,t.generatedBy=i.generatedBy,t.convertedBy=i.convertedBy,null!=i.signature&&(t.signature=i.signature),null!=i.userDefinedMetadata&&(t.userDefinedMetadata=i.userDefinedMetadata),null!=i.modelInitializer&&(t.modelInitializer=i.modelInitializer)),null==(s=this.LS.getItem(this.keys.weightData)))throw new Error("In local storage, the binary weight values of model '"+this.modelPath+"' are missing.");return t.weightData=function(e){if(He){var t=Buffer.from(e,"base64");return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}for(var n=atob(e),r=new Uint8Array(n.length),a=0;a<n.length;++a)r.set([n.charCodeAt(a)],a);return r.buffer}(s),[2,t]}))}))},e.URL_SCHEME="localstorage://",e}(),dt=function(e){return U().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(ht.URL_SCHEME)?(t=e.slice(ht.URL_SCHEME.length),new ht(t)):null;var t};$e.registerSaveRouter(dt),$e.registerLoadRouter(dt);var pt=function(){function e(){c(U().getBool("IS_BROWSER"),(function(){return"Current environment is not a web browser"})),c("undefined"==typeof window||void 0!==window.localStorage,(function(){return"Current browser does not appear to support localStorage"})),this.LS=window.localStorage}return e.prototype.listModels=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,i;return a(this,(function(a){for(e={},t=at+"/",n="/"+ot,r=0;r<this.LS.length;++r)(o=this.LS.key(r)).startsWith(t)&&o.endsWith(n)&&(i=ft(o),e[i]=JSON.parse(this.LS.getItem(o)));return[2,e]}))}))},e.prototype.removeModel=function(e){return r(this,void 0,void 0,(function(){var t,n;return a(this,(function(r){var a;if(e=(a=e).startsWith(ht.URL_SCHEME)?a.slice(ht.URL_SCHEME.length):a,t=ct(e),null==this.LS.getItem(t.info))throw new Error("Cannot find model at path '"+e+"'");return n=JSON.parse(this.LS.getItem(t.info)),this.LS.removeItem(t.info),this.LS.removeItem(t.topology),this.LS.removeItem(t.weightSpecs),this.LS.removeItem(t.weightData),[2,n]}))}))},e}(),vt=function(){function e(){this.managers={}}return e.getInstance=function(){return null==e.instance&&(e.instance=new e),e.instance},e.registerManager=function(t,n){c(null!=t,(function(){return"scheme must not be undefined or null."})),t.endsWith("://")&&(t=t.slice(0,t.indexOf("://"))),c(t.length>0,(function(){return"scheme must not be an empty string."}));var r=e.getInstance();c(null==r.managers[t],(function(){return"A model store manager is already registered for scheme '"+t+"'."})),r.managers[t]=n},e.getManager=function(e){var t=this.getInstance().managers[e];if(null==t)throw new Error("Cannot find model manager for scheme '"+e+"'");return t},e.getSchemes=function(){return Object.keys(this.getInstance().managers)},e}();function mt(e){if(-1===e.indexOf("://"))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+vt.getSchemes().join(","));return{scheme:e.split("://")[0],path:e.split("://")[1]}}function gt(e,t,n){return void 0===n&&(n=!1),r(this,void 0,void 0,(function(){var r,o,i,s,u,l,f,h,d;return a(this,(function(a){switch(a.label){case 0:return c(e!==t,(function(){return"Old path and new path are the same: '"+e+"'"})),c((r=$e.getLoadHandlers(e)).length>0,(function(){return"Copying failed because no load handler is found for source URL "+e+"."})),c(r.length<2,(function(){return"Copying failed because more than one ("+r.length+") load handlers for source URL "+e+"."})),o=r[0],c((i=$e.getSaveHandlers(t)).length>0,(function(){return"Copying failed because no save handler is found for destination URL "+t+"."})),c(i.length<2,(function(){return"Copying failed because more than one ("+r.length+") save handlers for destination URL "+t+"."})),s=i[0],u=mt(e).scheme,l=mt(e).path,f=u===mt(e).scheme,[4,o.load()];case 1:return h=a.sent(),n&&f?[4,vt.getManager(u).removeModel(l)]:[3,3];case 2:a.sent(),a.label=3;case 3:return[4,s.save(h)];case 4:return d=a.sent(),!n||f?[3,6]:[4,vt.getManager(u).removeModel(l)];case 5:a.sent(),a.label=6;case 6:return[2,d.modelArtifactsInfo]}}))}))}var yt=function(){function e(){}return e.prototype.fetch=function(e,t){return fetch(e,t)},e.prototype.now=function(){return performance.now()},e.prototype.encode=function(e,t){if("utf-8"!==t&&"utf8"!==t)throw new Error("Browser's encoder only supports utf-8, but got "+t);return null==this.textEncoder&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(e)},e.prototype.decode=function(e,t){return new TextDecoder(t).decode(e)},e}();if(U().get("IS_BROWSER")){U().setPlatform("browser",new yt);try{vt.registerManager(ht.URL_SCHEME,new pt)}catch(e){}try{vt.registerManager(tt.URL_SCHEME,new rt)}catch(e){}}var bt,wt=function(){return require("node-fetch")},kt=function(){function e(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return e.prototype.fetch=function(e,t){return null!=U().global.fetch?U().global.fetch(e,t):(null==bt&&(bt=wt()),bt(e,t))},e.prototype.now=function(){var e=process.hrtime();return 1e3*e[0]+e[1]/1e6},e.prototype.encode=function(e,t){if("utf-8"!==t&&"utf8"!==t)throw new Error("Node built-in encoder only supports utf-8, but got "+t);return this.textEncoder.encode(e)},e.prototype.decode=function(e,t){return 0===e.length?"":new this.util.TextDecoder(t).decode(e)},e}();function xt(e,t,n){return void 0===t&&(t="float32"),t=t||"float32",L(e),new ce(e,t,n)}U().get("IS_NODE")&&U().setPlatform("node",new kt);var Et=Oe({cast_:function(e,t){var n=Le(e,"x","cast");if(!E(t))throw new Error("Failed to cast to unknown dtype "+t);if("string"===t&&"string"!==n.dtype||"string"!==t&&"string"===n.dtype)throw new Error("Only strings can be casted to strings");var r={x:n},a={dtype:t};return De.runKernel("Cast",r,a)}});var St=Oe({clone_:function(e){var t={x:Le(e,"x","clone","string_or_numeric")};return De.runKernel("Identity",t)}});function At(e,t){void 0===t&&(t=!1),console.log(e.toString(t))}_e(),he={buffer:xt,cast:Et,clone:St,print:At};function Mt(e){return new Promise((function(e){return setTimeout(e)})).then(e)}var It=function(){function e(t){if(!U().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");t.startsWith(e.URL_SCHEME)&&(t=t.slice(e.URL_SCHEME.length)),null!=t&&0!==t.length||(t="model"),this.modelTopologyFileName=t+".json",this.weightDataFileName=t+".weights.bin"}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){var t,n,r,o,i,s;return a(this,(function(a){switch(a.label){case 0:if("undefined"==typeof document)throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(t=window.URL.createObjectURL(new Blob([e.weightData],{type:"application/octet-stream"})),!(e.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return n=[{paths:["./"+this.weightDataFileName],weights:e.weightSpecs}],r={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:n},null!=e.signature&&(r.signature=e.signature),null!=e.userDefinedMetadata&&(r.userDefinedMetadata=e.userDefinedMetadata),null!=e.modelInitializer&&(r.modelInitializer=e.modelInitializer),o=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),(i=null==this.jsonAnchor?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,i.href=o,[4,Mt((function(){return i.dispatchEvent(new MouseEvent("click"))}))];case 2:return a.sent(),null==e.weightData?[3,4]:((s=null==this.weightDataAnchor?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,s.href=t,[4,Mt((function(){return s.dispatchEvent(new MouseEvent("click"))}))]);case 3:a.sent(),a.label=4;case 4:return[2,{modelArtifactsInfo:Ze(e)}]}}))}))},e.URL_SCHEME="downloads://",e}(),Nt=function(){function e(e){if(null==e||e.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+e);this.files=e}return e.prototype.load=function(){return r(this,void 0,void 0,(function(){var e,t,n=this;return a(this,(function(r){return e=this.files[0],t=this.files.slice(1),[2,new Promise((function(r,a){var o=new FileReader;o.onload=function(o){var i=JSON.parse(o.target.result),s=i.modelTopology;if(null!=s){0===t.length&&r({modelTopology:s});var u=i.weightsManifest;if(null!=u){var l;try{l=n.checkManifestAndWeightFiles(u,t)}catch(e){return void a(e)}var c=[],f=[],h=[];u.forEach((function(e){e.paths.forEach((function(e){f.push(e),h.push(null)})),c.push.apply(c,e.weights)})),u.forEach((function(e){e.paths.forEach((function(e){var t=new FileReader;t.onload=function(t){var n=t.target.result,a=f.indexOf(e);if(h[a]=n,-1===h.indexOf(null)){var o={modelTopology:s,weightSpecs:c,weightData:Je(h),format:i.format,generatedBy:i.generatedBy,convertedBy:i.convertedBy};null!=i.signature&&(o.signature=i.signature),null!=i.userDefinedMetadata&&(o.userDefinedMetadata=i.userDefinedMetadata),null!=i.modelInitializer&&(o.modelInitializer=i.modelInitializer),r(o)}},t.onerror=function(t){return a("Failed to weights data from file of path '"+e+"'.")},t.readAsArrayBuffer(l[e])}))}))}else a(new Error("weightManifest field is missing from file "+e.name))}else a(new Error("modelTopology field is missing from file "+e.name))},o.onerror=function(t){return a("Failed to read model topology and weights manifest JSON from file '"+e.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},o.readAsText(e)}))]}))}))},e.prototype.checkManifestAndWeightFiles=function(e,t){for(var n=[],r=t.map((function(e){return Ye(e.name)})),a={},o=0,i=e;o<i.length;o++){i[o].paths.forEach((function(e){var o=Ye(e);if(-1!==n.indexOf(o))throw new Error("Duplicate file basename found in weights manifest: '"+o+"'");if(n.push(o),-1===r.indexOf(o))throw new Error("Weight file with basename '"+o+"' is not provided.");a[e]=t[r.indexOf(o)]}))}if(n.length!==t.length)throw new Error("Mismatch in the number of files in weights manifest ("+n.length+") and the number of weight files provided ("+t.length+").");return a},e}();function _t(e,t,n,r){!function(e){c(null!=e&&Array.isArray(e)&&e.length>0,(function(){return"promises must be a none empty array"}))}(e),function(e,t){c(e>=0&&e<=1,(function(){return"Progress fraction must be in range [0, 1], but got startFraction "+e})),c(t>=0&&t<=1,(function(){return"Progress fraction must be in range [0, 1], but got endFraction "+t})),c(t>=e,(function(){return"startFraction must be no more than endFraction, but got startFraction "+e+" and endFraction "+t}))}(n=null==n?0:n,r=null==r?1:r);var a=0;return Promise.all(e.map((function(o){return o.then((function(o){var i=n+ ++a/e.length*(r-n);return t(i),o})),o})))}function Dt(e,t){return r(this,void 0,void 0,(function(){var n,r,o,i,s,u,l,c,f;return a(this,(function(a){switch(a.label){case 0:return null==t&&(t={}),n=null==t.fetchFunc?U().platform.fetch:t.fetchFunc,r=e.map((function(e){return n(e,t.requestInit,{isBinary:!0})})),o=0,i=.5,null!=t.onProgress?[3,2]:[4,Promise.all(r)];case 1:return s=a.sent(),[3,4];case 2:return[4,_t(r,t.onProgress,o,i)];case 3:s=a.sent(),a.label=4;case 4:return u=s.map((function(e){return e.arrayBuffer()})),l=.5,c=1,null!=t.onProgress?[3,6]:[4,Promise.all(u)];case 5:return f=a.sent(),[3,8];case 6:return[4,_t(u,t.onProgress,l,c)];case 7:f=a.sent(),a.label=8;case 8:return[2,f]}}))}))}function Tt(e){var t=this;return function(n,o,i){return void 0===o&&(o=""),r(t,void 0,void 0,(function(){var t,r,s,u,l,c,f,h,d,v;return a(this,(function(a){switch(a.label){case 0:if(t=n.map((function(){return!1})),r={},s=null!=i?i.map((function(){return!1})):[],u=[],n.forEach((function(e,n){var a=0;e.weights.forEach((function(e){var o="quantization"in e?e.quantization.dtype:e.dtype,l=Ue[o]*p(e.shape),c=function(){t[n]=!0,null==r[n]&&(r[n]=[]),r[n].push({manifestEntry:e,groupOffset:a,sizeBytes:l})};null!=i?i.forEach((function(t,n){t===e.name&&(c(),s[n]=!0)})):c(),u.push(e.name),a+=l}))})),!s.every((function(e){return e})))throw l=i.filter((function(e,t){return!s[t]})),new Error("Could not find weights in manifest with names: "+l.join(", ")+". \nManifest JSON has weights with names: "+u.join(", ")+".");return c=t.reduce((function(e,t,n){return t&&e.push(n),e}),[]),f=[],c.forEach((function(e){n[e].paths.forEach((function(e){var t=o+(o.endsWith("/")?"":"/")+e;f.push(t)}))})),[4,e(f)];case 1:return h=a.sent(),d={},v=0,c.forEach((function(e){for(var t=n[e].paths.length,a=0,o=0;o<t;o++)a+=h[v+o].byteLength;for(var i=new ArrayBuffer(a),s=new Uint8Array(i),u=0,l=0;l<t;l++){var c=new Uint8Array(h[v+l]);s.set(c,u),u+=c.byteLength}r[e].forEach((function(e){var t=Ge(i.slice(e.groupOffset,e.groupOffset+e.sizeBytes),[e.manifestEntry]);for(var n in t)d[n]=t[n]})),v+=t})),[2,d]}}))}))}}$e.registerSaveRouter((function(e){return U().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(It.URL_SCHEME)?function(e){void 0===e&&(e="model");return new It(e)}(e.slice(It.URL_SCHEME.length)):null}));var Rt=function(){function e(e,t){if(this.DEFAULT_METHOD="POST",null==t&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,null!=t.fetchFunc?(c("function"==typeof t.fetchFunc,(function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"})),this.fetch=t.fetchFunc):this.fetch=U().platform.fetch,c(null!=e&&e.length>0,(function(){return"URL path for http must not be null, undefined or empty."})),Array.isArray(e)&&c(2===e.length,(function(){return"URL paths for http must have a length of 2, (actual length is "+e.length+")."})),this.path=e,null!=t.requestInit&&null!=t.requestInit.body)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){var t,n,r,o;return a(this,(function(a){switch(a.label){case 0:if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],r={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:n},null!=e.signature&&(r.signature=e.signature),null!=e.userDefinedMetadata&&(r.userDefinedMetadata=e.userDefinedMetadata),null!=e.modelInitializer&&(r.modelInitializer=e.modelInitializer),t.body.append("model.json",new Blob([JSON.stringify(r)],{type:"application/json"}),"model.json"),null!=e.weightData&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,t)];case 1:if((o=a.sent()).ok)return[2,{modelArtifactsInfo:Ze(e),responses:[o]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+o.status+".")}}))}))},e.prototype.load=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,i,s,u,l,c,f,h,d,p,v;return a(this,(function(a){switch(a.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(e=a.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+e.status+". Please verify this URL points to the model JSON of the model to load.");a.label=2;case 2:return a.trys.push([2,4,,5]),[4,e.json()];case 3:return t=a.sent(),[3,5];case 4:throw a.sent(),n="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?n+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":n+=" Please make sure the server is serving valid JSON for this request.",new Error(n);case 5:if(r=t.modelTopology,o=t.weightsManifest,i=t.generatedBy,s=t.convertedBy,u=t.format,l=t.signature,c=t.userDefinedMetadata,null==r&&null==o)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return null==o?[3,7]:[4,this.loadWeights(o)];case 6:d=a.sent(),f=d[0],h=d[1],a.label=7;case 7:return p={modelTopology:r,weightSpecs:f,weightData:h,generatedBy:i,convertedBy:s,format:u},null!=l&&(p.signature=l),null!=c&&(p.userDefinedMetadata=c),(v=t.modelInitializer)&&(p.modelInitializer=v),[2,p]}}))}))},e.prototype.loadWeights=function(e){return r(this,void 0,void 0,(function(){var t,n,r,o,i,s,u,l,c,f,h,d,p,v,m,g,y,b,w,k,x;return a(this,(function(a){switch(a.label){case 0:for(t=Array.isArray(this.path)?this.path[1]:this.path,n=function(e){var t=e.lastIndexOf("/"),n=e.lastIndexOf("?"),r=e.substring(0,t),a=n>t?e.substring(n):"";return[r+"/",a]}(t),r=n[0],o=n[1],i=this.weightPathPrefix||r,s=[],u=0,l=e;u<l.length;u++)c=l[u],s.push.apply(s,c.weights);for(f=[],h=[],d=0,p=e;d<p.length;d++)for(v=p[d],m=0,g=v.paths;m<g.length;m++)y=g[m],null!=this.weightUrlConverter?h.push(this.weightUrlConverter(y)):f.push(i+y+o);return this.weightUrlConverter?(w=(b=f.push).apply,k=[f],[4,Promise.all(h)]):[3,2];case 1:w.apply(b,k.concat([a.sent()])),a.label=2;case 2:return[4,Dt(f,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 3:return x=a.sent(),[2,[s,Je(x)]]}}))}))},e.URL_SCHEME_REGEX=/^https?:\/\//,e}();function Ft(e){return null!=e.match(Rt.URL_SCHEME_REGEX)}var Ct=function(e,t){if("undefined"==typeof fetch&&(null==t||null==t.fetchFunc))return null;return(Array.isArray(e)?e.every((function(e){return Ft(e)})):Ft(e))?Bt(e,t):null};function Bt(e,t){return new Rt(e,t)}$e.registerSaveRouter(Ct),$e.registerLoadRouter(Ct);var Pt=function(){function e(e){this.modelArtifacts=e}return e.prototype.load=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){return[2,this.modelArtifacts]}))}))},e}(),Lt=function(){function e(e){this.saveHandler=e}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.saveHandler(e)]}))}))},e}();var zt={__proto__:null,browserFiles:function(e){return new Nt(e)},browserHTTPRequest:function(e,t){return Bt(e,t)},concatenateArrayBuffers:Je,decodeWeights:Ge,encodeWeights:function(e,t){return r(this,void 0,void 0,(function(){var n,o,i,s,u,l=this;return a(this,(function(c){switch(c.label){case 0:for(n=[],o=[],i=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e),s=function(s){var u=i[s],c=Array.isArray(e)?e[s].tensor:e[u];if("float32"!==c.dtype&&"int32"!==c.dtype&&"bool"!==c.dtype&&"string"!==c.dtype&&"complex64"!==c.dtype)throw new Error("Unsupported dtype in weight '"+u+"': "+c.dtype);var f={name:u,shape:c.shape,dtype:c.dtype};if("string"===c.dtype){var h=new Promise((function(e){return r(l,void 0,void 0,(function(){var t,n,r,o,i,s,u;return a(this,(function(a){switch(a.label){case 0:return[4,c.bytes()];case 1:for(t=a.sent(),n=t.reduce((function(e,t){return e+t.length}),0)+4*t.length,r=new Uint8Array(n),o=0,i=0;i<t.length;i++)s=t[i],u=new Uint8Array(new Uint32Array([s.length]).buffer),r.set(u,o),o+=4,r.set(s,o),o+=s.length;return e(r),[2]}}))}))}));o.push(h)}else o.push(c.data());null!=t&&(f.group=t),n.push(f)},u=0;u<i.length;++u)s(u);return[4,Promise.all(o)];case 1:return[2,{data:Ve(c.sent()),specs:n}]}}))}))},fromMemory:function(e,t,n,r){if(1===arguments.length){var a=null!=e.modelTopology||null!=e.weightSpecs;return a?new Pt(e):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new Pt({modelTopology:e}))}return console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new Pt({modelTopology:e,weightSpecs:t,weightData:n,trainingConfig:r})},getLoadHandlers:function(e,t){return $e.getLoadHandlers(e,t)},getModelArtifactsInfoForJSON:Ze,getSaveHandlers:function(e){return $e.getSaveHandlers(e)},http:Bt,isHTTPScheme:Ft,loadWeights:function(e,t,n,o){return void 0===t&&(t=""),r(this,void 0,void 0,(function(){return a(this,(function(r){return[2,Tt((function(e){return Dt(e,{requestInit:o})}))(e,t,n)]}))}))},registerLoadRouter:function(e){return $e.registerLoadRouter(e)},registerSaveRouter:function(e){return $e.registerSaveRouter(e)},weightsLoaderFactory:Tt,withSaveHandler:function(e){return new Lt(e)},copyModel:function(e,t){return r(this,void 0,void 0,(function(){return a(this,(function(n){return!1,[2,gt(e,t,!1)]}))}))},listModels:function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,i,s;return a(this,(function(a){switch(a.label){case 0:e=vt.getSchemes(),t={},n=0,r=e,a.label=1;case 1:return n<r.length?(o=r[n],[4,vt.getManager(o).listModels()]):[3,4];case 2:for(s in i=a.sent())t[o+"://"+s]=i[s];a.label=3;case 3:return n++,[3,1];case 4:return[2,t]}}))}))},moveModel:function(e,t){return r(this,void 0,void 0,(function(){return a(this,(function(n){return!0,[2,gt(e,t,!0)]}))}))},removeModel:function(e){return r(this,void 0,void 0,(function(){var t;return a(this,(function(n){return t=mt(e),[2,vt.getManager(t.scheme).removeModel(t.path)]}))}))}};var Ot=Oe({matMul_:function(e,t,n,r){var a;void 0===n&&(n=!1),void 0===r&&(r=!1);var o=Le(e,"a","matMul"),i=Le(t,"b","matMul"),s={a:o=(a=xe(o,i))[0],b:i=a[1]},u={transposeA:n,transposeB:r};return De.runKernel("BatchMatMul",s,u)}});var Kt=Oe({oneHot_:function(e,t,n,r){if(void 0===n&&(n=1),void 0===r&&(r=0),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+t);var a={indices:Le(e,"indices","oneHot","int32")},o={depth:t,onValue:n,offValue:r};return De.runKernel("OneHot",a,o)}});var Wt=Oe({transpose_:function(e,t){var n=Le(e,"x","transpose");if(null==t&&(t=n.shape.map((function(e,t){return t})).reverse()),c(n.rank===t.length,(function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+t+"."})),t.forEach((function(e){c(e>=0&&e<n.rank,(function(){return"All entries in 'perm' must be between 0 and "+(n.rank-1)+" but got "+t}))})),n.rank<=1)return n.clone();var r={x:n},a={perm:t};return De.runKernel("Transpose",r,a)}});var qt,Ut={__proto__:null,confusionMatrix:Oe({confusionMatrix_:function(e,t,n){var r=Le(e,"labels","confusionMatrix"),a=Le(t,"predictions","confusionMatrix");c(null==n||n>0&&Number.isInteger(n),(function(){return"If provided, numClasses must be a positive integer, but got "+n})),c(1===r.rank,(function(){return"Expected the rank of labels to be 1, but got "+r.rank})),c(1===a.rank,(function(){return"Expected the rank of predictions to be 1, but got "+a.rank})),c(r.shape[0]===a.shape[0],(function(){return"Mismatch in the number of examples: "+r.shape[0]+" vs. "+a.shape[0]+". Labels and predictions should have the same number of elements."})),c(n>0&&Number.isInteger(n),(function(){return"numClasses is required to be a positive integer, but got "+n}));var o=Kt(Et(r,"int32"),n),i=Kt(Et(a,"int32"),n),s=Wt(o),u=Ot(s,i);return Et(u,"int32")}})};function Gt(e,t,n){if(h(e),null!=t&&3!==t.length)throw new Error("tensor3d() requires shape to have three numbers");var r=Be(e,n);if(3!==r.length&&1!==r.length)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(1===r.length&&null==t)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return We(e,t,r,n)}function Vt(e,t){if(void 0===t&&(t=3),t>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(null==e)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var n=!1,r=!1,a=!1,o=!1,i=!1,s=!1;if(e.data instanceof Uint8Array)n=!0;else if("undefined"!=typeof ImageData&&e instanceof ImageData)r=!0;else if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement)a=!0;else if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement)o=!0;else if(null!=e.getContext)i=!0;else{if(!("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap))throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was "+e.constructor.name);s=!0}if(a){if(a&&e.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.")}if(null!=J("FromPixels",De.backendName)){var u={pixels:e},l={numChannels:t};return De.runKernel("FromPixels",u,l)}var c,f,h=a?[e.videoWidth,e.videoHeight]:[e.width,e.height],d=h[0],p=h[1];if(i?c=e.getContext("2d").getImageData(0,0,d,p).data:r||n?c=e.data:(o||a||s)&&(null==qt&&(qt=document.createElement("canvas").getContext("2d")),qt.canvas.width=d,qt.canvas.height=p,qt.drawImage(e,0,0,d,p),c=qt.getImageData(0,0,d,p).data),4===t)f=new Int32Array(c);else{var v=d*p;f=new Int32Array(v*t);for(var m=0;m<v;m++)for(var g=0;g<t;++g)f[m*t+g]=c[4*m+g]}return Gt(f,[p,d,t],"int32")}function Ht(e){return"undefined"!=typeof window&&"undefined"!=typeof ImageBitmap&&window.hasOwnProperty("createImageBitmap")&&!(e instanceof ImageBitmap)&&function(e){return null!=e&&0!==e.width&&0!==e.height}(e)&&!function(e){return null!=e&&e.data instanceof Uint8Array}(e)}var jt={__proto__:null,fromPixelsAsync:function(e,t){return void 0===t&&(t=3),r(this,void 0,void 0,(function(){var n,r;return a(this,(function(a){switch(a.label){case 0:if(n=null,!U().getBool("WRAP_TO_IMAGEBITMAP")||!Ht(e))return[3,5];r=void 0,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,createImageBitmap(e,{premultiplyAlpha:"none"})];case 2:return r=a.sent(),[3,4];case 3:return a.sent(),r=null,[3,4];case 4:return n=null!=r&&r.width===e.width&&r.height===e.height?r:e,[3,6];case 5:n=e,a.label=6;case 6:return[2,Vt(n,t)]}}))}))},toPixels:function(e,t){return r(this,void 0,void 0,(function(){var n,r,o,i,s,u,l,c,f,h,d,p,v,m,g,y;return a(this,(function(a){switch(a.label){case 0:if(n=Le(e,"img","toPixels"),e instanceof de||(n=Et(r=n,"int32"),r.dispose()),2!==n.rank&&3!==n.rank)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+n.rank+".");if(o=n.shape.slice(0,2),i=o[0],s=o[1],(u=2===n.rank?1:n.shape[2])>4||2===u)throw new Error("toPixels only supports depth of size 1, 3 or 4 but got "+u);if("float32"!==n.dtype&&"int32"!==n.dtype)throw new Error("Unsupported type for toPixels: "+n.dtype+". Please use float32 or int32 tensors.");return[4,n.data()];case 1:for(l=a.sent(),c="float32"===n.dtype?255:1,f=new Uint8ClampedArray(s*i*4),h=0;h<i*s;++h){for(d=[0,0,0,255],p=0;p<u;p++){if(v=l[h*u+p],"float32"===n.dtype){if(v<0||v>1)throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but encountered "+v+".")}else if("int32"===n.dtype&&(v<0||v>255))throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but encountered "+v+".");1===u?(d[0]=v*c,d[1]=v*c,d[2]=v*c):d[p]=v*c}f[(m=4*h)+0]=Math.round(d[0]),f[m+1]=Math.round(d[1]),f[m+2]=Math.round(d[2]),f[m+3]=Math.round(d[3])}return null!=t&&(t.width=s,t.height=i,g=t.getContext("2d"),y=new ImageData(f,s,i),g.putImageData(y,0,0)),n!==e&&n.dispose(),[2,f]}}))}))},fromPixels:Oe({fromPixels_:Vt})};function Jt(e,t){var n=e.shape.length,r=t.shape.length;if(n<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was "+n+".");if(r<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was "+r+".");if("int32"!==t.dtype)throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was "+t.dtype+".");if(t.shape[r-1]>n)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+t.shape[r-1]+" vs. "+n);if(0===p(e.shape))throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+e.shape+".");for(var a=t.shape,o=a[a.length-1],i=1,s=0;s<a.length-1;++s)i*=a[s];var u=e.shape,l=a.slice();l.pop();var c=1;for(s=o;s<n;++s)c*=u[s],l.push(u[s]);var f=F(e.shape).map((function(e){return e/c})).concat([1]).slice(0,o);return[l,i,c,f]}var Yt={__proto__:null,prepareAndValidate:Jt};function Zt(e,t,n){var r=t.rank>1?t.shape[t.rank-1]:1,a=t.rank>1?t.rank-1:1,o="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+n.shape+", indices.shape: "+t.shape+", shape: "+e+", sliceDim: "+r+", and batchDim: "+a+".";if(n.rank<a)throw new Error(o+" update.rank < "+a+". ");if(e.length<r+(n.rank-a))throw new Error(o+" Output shape length < "+(r+(n.rank-a)));if(n.rank!==a+e.length-r)throw new Error(o+" update.rank != "+(a+e.length-r));for(var i=0;i<a;++i)if(n.shape[i]!==t.shape[i])throw new Error(o+" updates.shape["+i+"] ("+n.shape[i]+") != indices.shape["+i+"] ("+t.shape[i]+").");for(i=0;i<n.rank-a;++i)if(n.shape[i+a]!==e[i+r])throw new Error(o+" updates.shape["+(i+a)+"] ("+n.shape[i+a]+") != shape["+(i+a)+"] ("+e[i+a]+")")}function Xt(e,t,n){if(t.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was "+t.rank+".");if(e.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was "+e.rank+".");if("int32"!==t.dtype)throw new Error("The dtype of 'indices' should be int32, but got dtype: "+t.dtype);if(n.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+n);if(0===n.length){if(0===t.size)throw new Error("Indices specified for empty output. indices shape: "+t.shape);if(0===e.size)throw new Error("Updates specified for empty output. updates shape: "+e.shape)}Zt(n,t,e)}function $t(e,t,n){for(var r=t.shape.length,a=r>1?t.shape[r-1]:1,o=n.length,i=1,s=a;s<o;++s)i*=n[s];var u=a<1?1:a;return{sliceRank:a,numUpdates:p(t.shape)/u,sliceSize:i,strides:F(n.slice(0,a)).concat([1]),outputSize:p(n)}}var Qt={__proto__:null,validateUpdateShape:Zt,validateInput:Xt,calculateShapes:$t};function en(e){for(var t=[],n=0;e>0;)1&e&&t.push(n),e/=2,n++;return t}function tn(e,t,n){for(var r=[],a=0;a<e.length;a++)r[a]=Math.ceil((t[a]-e[a])/n[a]);return r}function nn(e,t,n,r){for(var a=e.slice(),o=a.length;o<r.length;o++)a.push(1);for(o=0;o<n;o++)0===o?a[t]=1:(a.splice(t,0,1),a.pop());return a}function rn(e,t,n){return n<=e?n:n-(t-1)}function an(e,t){for(var n=[],r=0;r<e;r++)n.push(t+r);return n}function on(e,t,n,r,a,o,i,s,u){var l=e.length,c=new Array(l),f=new Array(l),h=new Array(l);if(t.length&&n>0){var d=t[0],p=n+1;c=sn(i,d,p,r,e),f=un(s,d,p,a,e),h=nn(o,d,p,e)}else for(var v=0;v<l;v++)c[v]=cn(i,r,o,e,v,u),f[v]=fn(s,a,o,e,v,u),h[v]=ln(o,v,u);return{begin:c,end:f,strides:h}}function sn(e,t,n,r,a){for(var o=a.slice(),i=an(n,t),s=0;s<o.length;s++)if(i.indexOf(s)>-1)o[s]=0;else{var u=rn(t,n,s),l=r[u];e&1<<u&&(l=0),o[s]=l}return o}function un(e,t,n,r,a){for(var o=a.slice(),i=an(n,t),s=0;s<o.length;s++)if(i.indexOf(s)>-1)o[s]=Number.MAX_SAFE_INTEGER;else{var u=rn(t,n,s),c=r[u];e&1<<u&&(c=Number.MAX_SAFE_INTEGER),o[s]=c}for(var f=0;f<o.length;f++){var h=a[f];o[f]<0&&(o[f]+=h),o[f]=l(0,o[f],a[f])}return o}function ln(e,t,n){var r=e[t];return(n&1<<t||null==r)&&(r=1),r}function cn(e,t,n,r,a,o){var i=t[a],s=n[a]||1;(e&1<<a||o&1<<a||null==i)&&(i=s>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var u=r[a];return i<0&&(i+=u),i=l(0,i,u-1)}function fn(e,t,n,r,a,o){var i=t[a],s=n[a]||1;(e&1<<a||o&1<<a||null==i)&&(i=s>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var u=r[a];return i<0&&(i+=u),i=s>0?l(0,i,u):l(-1,i,u-1)}var hn={__proto__:null,assertParamsValid:function(e,t,n){var r=e.shape.length;c(r===t.length,(function(){return"Error in slice"+r+"D: Length of begin "+t+" must match the rank of the array ("+r+")."})),c(r===n.length,(function(){return"Error in slice"+r+"D: Length of size "+n+" must match the rank of the array ("+r+")."}));for(var a=function(a){c(t[a]+n[a]<=e.shape[a],(function(){return"Error in slice"+r+"D: begin["+a+"] + size["+a+"] ("+(t[a]+n[a])+") would overflow input.shape["+a+"] ("+e.shape[a]+")"}))},o=0;o<r;++o)a(o)},maskToAxes:en,computeOutShape:tn,stridesWithElidedDims:nn,getNormalizedAxes:on,startIndicesWithElidedDims:sn,stopIndicesWithElidedDims:un,stridesForAxis:ln,startForAxis:cn,stopForAxis:fn,isSliceContinous:function(e,t,n){for(var r=n.length,a=0;a<n.length;a++)if(n[a]>1){r=a;break}for(a=r+1;a<n.length;a++)if(t[a]>0||n[a]!==e[a])return!1;return!0},computeFlatOffset:function(e,t){for(var n=e.length>0?e[e.length-1]:1,r=0;r<e.length-1;r++)n+=e[r]*t[r];return n},parseSliceParams:function(e,t,n){var r,a,o=e.shape.length;return(r="number"==typeof t?[t].concat(new Array(o-1).fill(0)):t.length<o?t.concat(new Array(o-t.length).fill(0)):t.slice()).forEach((function(e){c(-1!==e,(function(){return"slice() does not support negative begin indexing."}))})),a=(a=null==n?new Array(o).fill(-1):"number"==typeof n?[n].concat(new Array(o-1).fill(-1)):n.length<o?n.concat(new Array(o-n.length).fill(-1)):n).map((function(t,n){return t>=0?t:(c(-1===t,(function(){return"Negative size values should be exactly -1 but got "+t+" for the slice() size at index "+n+"."})),e.shape[n]-r[n])})),[r,a]},sliceInfo:function(e,t,n,r,a,o,i,s,u){var l=t.slice(),c=n.slice(),f=r;null==r&&(f=new Array(l.length));var h=en(i);if(h.length>1)throw new Error("Multiple ellipses in slice is not allowed.");if(0!==i&&0!==s)throw new Error("Using both ellipsisMask and newAxisMask is not yet supported.");if(0!==i&&0!==u)throw new Error("Using both ellipsisMask and shrinkAxisMask is not yet supported.");var d=e.length-l.length,p=en(s),v=e.slice();p.forEach((function(e){l[e]=0,c[e]=1,v.splice(e,0,1)}));var m=on(v,h,d,l,c,f,a,o,i),g=m.begin,y=m.end,b=m.strides;l=g,c=y,f=b;var w=en(u);w.forEach((function(e){c[e]=l[e]+1,f[e]=1}));var k=tn(l,c,f),x=k.filter((function(e,t){return-1===w.indexOf(t)}));return{nonStrided:f.every((function(e){return 1===e})),$begin:l,$end:c,$strides:f,size:k,newShape:v,outShape:x}}},dn=function(){function e(){}return e.prototype.getClassName=function(){return this.constructor.className},e.fromConfig=function(e,t){return new e(t)},e}(),pn=function(){function e(){this.classNameMap={}}return e.getMap=function(){return null==e.instance&&(e.instance=new e),e.instance},e.register=function(t){e.getMap().classNameMap[t.className]=[t,t.fromConfig]},e}();function vn(e){c(null!=e.className,(function(){return"Class being registered does not have the static className property defined."})),c("string"==typeof e.className,(function(){return"className is required to be a string, but got type "+typeof e.className})),c(e.className.length>0,(function(){return"Class being registered has an empty-string as its className, which is disallowed."})),pn.register(e)}var mn={__proto__:null,Serializable:dn,SerializationMap:pn,registerClass:vn};function gn(){return 32===De.backend.floatPrecision()?.001:.1}function yn(e,t,n){var r=!0;if((S(e)||S(t))&&(r=!1),S(e)&&S(t)&&(r=!0),r){var a=e.constructor.name,o=t.constructor.name;if(a!==o)throw new Error("Arrays are of different type. Actual: "+a+". Expected: "+o)}if(Array.isArray(e)&&Array.isArray(t)){var i=Be(e),s=Be(t);if(!v(i,s))throw new Error("Arrays have different shapes. Actual: ["+i+"]. Expected: ["+s+"]")}var u=S(e)?e:d(e),l=S(t)?t:d(t);if(u.length!==l.length)throw new Error("Arrays have different lengths actual: "+u.length+" vs expected: "+l.length+".\nActual:   "+u+".\nExpected: "+l+".");for(var c=0;c<l.length;++c){var f=u[c],h=l[c];if(!n(f,h))throw new Error("Arrays differ: actual["+c+"] = "+f+", expected["+c+"] = "+h+".\nActual:   "+u+".\nExpected: "+l+".")}}function bn(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}var wn={__proto__:null,TEST_EPSILON_FLOAT16:.1,expectArraysClose:function(e,t,n){return null==n&&(n=gn()),yn(e,t,(function(e,t){return bn(e,t,n)}))},testEpsilon:gn,expectPromiseToFail:function(e,t){e().then((function(){return t.fail()}),(function(){return t()}))},expectArraysEqual:function(e,t){var n="string"==typeof t||"number"==typeof t||"boolean"==typeof t?[t]:t;return I(e)||I(e[0])||I(t)||I(t[0])?yn(e,n,(function(e,t){return e==t})):yn(e,t,(function(e,t){return bn(e,t,0)}))},expectNumbersClose:function(e,t,n){if(null==n&&(n=gn()),!bn(e,t,n))throw new Error("Numbers differ: actual === "+e+", expected === "+t)},expectValuesInRange:function(e,t,n){for(var r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw new Error("Value out of range:"+e[r]+" low: "+t+", high: "+n)},expectArrayBuffersEqual:function(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))},encodeStrings:function e(t){for(var n=0;n<t.length;n++){var r=t[n];Array.isArray(r)?e(r):t[n]=te(r)}return t}};function kn(e,t){return De.tidy(e,t)}function xn(e){Se(e).forEach((function(e){return e.dispose()}))}function En(e){return De.keep(e)}var Sn=Oe({add_:function(e,t){var n,r=Le(e,"a","add"),a=Le(t,"b","add"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Add",o)}});var An=Oe({floorDiv_:function(e,t){var n,r=Le(e,"a","floorDiv"),a=Le(t,"b","floorDiv"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("FloorDiv",o)}});var Mn=Oe({div_:function(e,t){var n,r=Le(e,"a","div"),a=Le(t,"b","div");if(r=(n=xe(r,a))[0],a=n[1],"int32"===r.dtype&&"int32"===a.dtype)return An(r,a);var o={a:r,b:a};return De.runKernel("RealDiv",o,{})}});var In=Oe({mul_:function(e,t){var n,r=Le(e,"a","mul"),a=Le(t,"b","mul"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Multiply",o)}});var Nn=Oe({abs_:function(e){var t=Le(e,"x","abs");if("complex64"===t.dtype){var n={x:t};return De.runKernel("ComplexAbs",n)}return n={x:t},De.runKernel("Abs",n)}});var _n=Oe({acos_:function(e){var t={x:Le(e,"x","acos")};return De.runKernel("Acos",t)}});var Dn=Oe({acosh_:function(e){var t={x:Le(e,"x","acosh")};return De.runKernel("Acosh",t)}});var Tn=Oe({addN_:function(e){c(Array.isArray(e),(function(){return"The argument passed to tf.addN() must be a list of tensors"})),c(e.length>=1,(function(){return"Must pass at least one tensor to tf.addN(), but got "+e.length}));var t=e.map((function(e,t){return Le(e,"tensors"+t,"addN")})),n=t[0];t.forEach((function(e){if(e.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")})),t.forEach((function(e){if(!v(e.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")}));var r=t;return De.runKernel("AddN",r)}});var Rn=Oe({all_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:Le(e,"x","all","bool")},a={axis:t,keepDims:n};return De.runKernel("All",r,a)}});var Fn=Oe({any_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:Le(e,"x","any","bool")},a={axis:t,keepDims:n};return De.runKernel("Any",r,a)}});var Cn=Oe({argMax_:function(e,t){void 0===t&&(t=0);var n={x:Le(e,"x","argMax")},r={axis:t};return De.runKernel("ArgMax",n,r)}});var Bn=Oe({argMin_:function(e,t){void 0===t&&(t=0);var n={x:Le(e,"x","argMin")},r={axis:t};return De.runKernel("ArgMin",n,r)}});var Pn=Oe({asin_:function(e){var t={x:Le(e,"x","asin")};return De.runKernel("Asin",t)}});var Ln=Oe({asinh_:function(e){var t={x:Le(e,"x","asinh")};return De.runKernel("Asinh",t)}});var zn=Oe({atan_:function(e){var t={x:Le(e,"x","atan")};return De.runKernel("Atan",t)}});var On=Oe({atan2_:function(e,t){var n,r=Le(e,"a","atan2"),a=Le(t,"b","atan2"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Atan2",o)}});var Kn=Oe({atanh_:function(e){var t={x:Le(e,"x","atanh")};return De.runKernel("Atanh",t)}});function Wn(e,t,n,r,a,o,i){void 0===i&&(i="channelsLast");var s,u=Vn(t),l=u[0],c=u[1];if("channelsLast"===i)s=[l,c,e[3],e[3]];else{if("channelsFirst"!==i)throw new Error("Unknown dataFormat "+i);s=[l,c,e[1],e[1]]}return qn(e,s,n,r,a,o,!1,i)}function qn(e,t,n,r,a,o,i,s){void 0===i&&(i=!1),void 0===s&&(s="channelsLast");var u=[-1,-1,-1,-1],l=u[0],c=u[1],f=u[2],h=u[3];if("channelsLast"===s)l=e[0],c=e[1],f=e[2],h=e[3];else{if("channelsFirst"!==s)throw new Error("Unknown dataFormat "+s);l=e[0],h=e[1],c=e[2],f=e[3]}var d,p=t[0],v=t[1],m=t[3],g=Vn(n),y=g[0],b=g[1],w=Vn(r),k=w[0],x=w[1],E=jn(p,k),S=jn(v,x),A=function(e,t,n,r,a,o,i,s,u){var l,c,f;if("number"==typeof e){l={top:e,bottom:e,left:e,right:e,type:0===e?"VALID":"NUMBER"};var h=function(e,t,n,r,a){null==r&&(r=Gn(e,t,n));var o=e[0],i=e[1],s=Jn((o-t+2*r)/n+1,a),u=Jn((i-t+2*r)/n+1,a);return[s,u]}([t,n],o,r,e,s);c=h[0],f=h[1]}else if("same"===e){c=Math.ceil(t/r),f=Math.ceil(n/a);var d=Math.max(0,(c-1)*r+o-t),p=Math.max(0,(f-1)*a+i-n),v=Math.floor(d/2),m=d-v,g=Math.floor(p/2);l={top:v,bottom:m,left:g,right:b=p-g,type:"SAME"}}else if("valid"===e)l={top:0,bottom:0,left:0,right:0,type:"VALID"},c=Math.ceil((t-o+1)/r),f=Math.ceil((n-i+1)/a);else{if("object"!=typeof e)throw Error("Unknown padding parameter: "+e);var y="channelsLast"===u?e[1][0]:e[2][0],b=(m="channelsLast"===u?e[1][1]:e[2][1],g="channelsLast"===u?e[2][0]:e[3][0],"channelsLast"===u?e[2][1]:e[3][1]);l={top:y,bottom:m,left:g,right:b,type:0===y&&0===m&&0===g&&0===b?"VALID":"EXPLICIT"},c=Jn((t-o+y+m)/r+1,s),f=Jn((n-i+g+b)/a+1,s)}return{padInfo:l,outHeight:c,outWidth:f}}(a,c,f,y,b,E,S,o,s),M=A.padInfo,I=A.outHeight,N=A.outWidth,_=i?m*h:m;return"channelsFirst"===s?d=[l,_,I,N]:"channelsLast"===s&&(d=[l,I,N,_]),{batchSize:l,dataFormat:s,inHeight:c,inWidth:f,inChannels:h,outHeight:I,outWidth:N,outChannels:_,padInfo:M,strideHeight:y,strideWidth:b,filterHeight:p,filterWidth:v,effectiveFilterHeight:E,effectiveFilterWidth:S,dilationHeight:k,dilationWidth:x,inShape:e,outShape:d,filterShape:t}}function Un(e,t,n,r,a,o,i,s){void 0===o&&(o=!1),void 0===i&&(i="channelsLast");var u=[-1,-1,-1,-1,-1],l=u[0],c=u[1],f=u[2],h=u[3],d=u[4];if("channelsLast"===i)l=e[0],c=e[1],f=e[2],h=e[3],d=e[4];else{if("channelsFirst"!==i)throw new Error("Unknown dataFormat "+i);l=e[0],d=e[1],c=e[2],f=e[3],h=e[4]}var p,v=t[0],m=t[1],g=t[2],y=t[4],b=Hn(n),w=b[0],k=b[1],x=b[2],E=Hn(r),S=E[0],A=E[1],M=E[2],I=jn(v,S),N=jn(m,A),_=jn(g,M),D=function(e,t,n,r,a,o,i,s,u,l,c){var f,h,d,p;if("number"==typeof e){f={top:e,bottom:e,left:e,right:e,front:e,back:e,type:0===e?"VALID":"NUMBER"};var v=function(e,t,n,r,a,o){null==a&&(a=Gn(e,t,r));var i=e[0],s=e[1],u=e[2],l=Jn((i-t+2*a)/r+1,o),c=Jn((s-t+2*a)/r+1,o),f=Jn((u-t+2*a)/r+1,o);return[l,c,f,n]}([t,n,r,1],s,1,a,e,c);h=v[0],d=v[1],p=v[2]}else if("same"===e){h=Math.ceil(t/a),d=Math.ceil(n/o),p=Math.ceil(r/i);var m=(h-1)*a+s-t,g=(d-1)*o+u-n,y=(p-1)*i+l-r,b=Math.floor(m/2),w=m-b,k=Math.floor(g/2),x=g-k,E=Math.floor(y/2);f={top:k,bottom:x,left:E,right:y-E,front:b,back:w,type:"SAME"}}else{if("valid"!==e)throw Error("Unknown padding parameter: "+e);f={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},h=Math.ceil((t-s+1)/a),d=Math.ceil((n-u+1)/o),p=Math.ceil((r-l+1)/i)}return{padInfo:f,outDepth:h,outHeight:d,outWidth:p}}(a,c,f,h,w,k,x,I,N,_,s),T=D.padInfo,R=D.outDepth,F=D.outHeight,C=D.outWidth,B=o?y*d:y;return"channelsFirst"===i?p=[l,B,R,F,C]:"channelsLast"===i&&(p=[l,R,F,C,B]),{batchSize:l,dataFormat:i,inDepth:c,inHeight:f,inWidth:h,inChannels:d,outDepth:R,outHeight:F,outWidth:C,outChannels:B,padInfo:T,strideDepth:w,strideHeight:k,strideWidth:x,filterDepth:v,filterHeight:m,filterWidth:g,effectiveFilterDepth:I,effectiveFilterHeight:N,effectiveFilterWidth:_,dilationDepth:S,dilationHeight:A,dilationWidth:M,inShape:e,outShape:p,filterShape:t}}function Gn(e,t,n,r){void 0===r&&(r=1);var a=jn(t,r);return Math.floor((e[0]*(n-1)-n+a)/2)}function Vn(e){return"number"==typeof e?[e,e,e]:2===e.length?[e[0],e[1],1]:e}function Hn(e){return"number"==typeof e?[e,e,e]:e}function jn(e,t){return t<=1?e:e+(e-1)*(t-1)}function Jn(e,t){if(!t)return Math.trunc(e);switch(t){case"round":return Math.round(e);case"ceil":return Math.ceil(e);case"floor":return Math.floor(e);default:throw new Error("Unknown roundingMode "+t)}}function Yn(e){var t=Vn(e),n=t[0],r=t[1],a=t[2];return 1===n&&1===r&&1===a}function Zn(e,t){return Yn(e)||Yn(t)}function Xn(e){if("NHWC"===e)return"channelsLast";if("NCHW"===e)return"channelsFirst";throw new Error("Unknown dataFormat "+e)}var $n=Oe({reshape_:function(e,t){var n={x:Le(e,"x","reshape","string_or_numeric")},r={shape:t};return De.runKernel("Reshape",n,r)}});var Qn=Oe({avgPool_:function(e,t,n,r,a){var o=Le(e,"x","avgPool","float32");c(Zn(n,1),(function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '1'"}));var i=o,s=!1;3===o.rank&&(s=!0,i=$n(o,[1,o.shape[0],o.shape[1],o.shape[2]])),c(4===i.rank,(function(){return"Error in avgPool: x must be rank 4 but got rank "+i.rank+"."})),null!=a&&c(m(r),(function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var u={x:i},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a},f=De.runKernel("AvgPool",u,l);return f=Et(f,o.dtype),s?$n(f,[f.shape[1],f.shape[2],f.shape[3]]):f}});var er=Oe({avgPool3d_:function(e,t,n,r,a,o){void 0===o&&(o="NDHWC");var i=Le(e,"x","avgPool3d","float32"),s=i,u=!1;4===i.rank&&(u=!0,s=$n(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),c(5===s.rank,(function(){return"Error in avgPool3d: x must be rank 5 but got rank "+s.rank+"."})),c("NDHWC"===o,(function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+o})),null!=a&&c(m(r),(function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var l={x:s},f={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:o},h=De.runKernel("AvgPool3D",l,f);return h=Et(h,s.dtype),u?$n(h,[h.shape[1],h.shape[2],h.shape[3],h.shape[4]]):h}});var tr=Oe({concat_:function(e,t){void 0===t&&(t=0),c(e.length>=1,(function(){return"Pass at least one tensor to concat"}));var n=ze(e,"tensors","concat","string_or_numeric");if("complex64"===n[0].dtype&&n.forEach((function(e){if("complex64"!==e.dtype)throw new Error("Cannot concatenate complex64 tensors with a tensor\n          with dtype "+e.dtype+". ")})),1===n.length)return St(n[0]);var r=n,a={axis:t};return De.runKernel("Concat",r,a)}});var nr=Oe({sigmoid_:function(e){var t={x:Le(e,"x","sigmoid")};return De.runKernel("Sigmoid",t)}});var rr=Oe({slice_:function(e,t,n){var r=Le(e,"x","slice","string_or_numeric");if(0===r.rank)throw new Error("Slicing scalar is not possible");var a={x:r},o={begin:t,size:n};return De.runKernel("Slice",a,o)}});var ar=Oe({tanh_:function(e){var t={x:Le(e,"x","tanh")};return De.runKernel("Tanh",t)}});var or=Oe({basicLSTMCell_:function(e,t,n,r,a,o){var i=Le(e,"forgetBias","basicLSTMCell"),s=Le(t,"lstmKernel","basicLSTMCell"),u=Le(n,"lstmBias","basicLSTMCell"),l=Le(r,"data","basicLSTMCell"),c=Le(a,"c","basicLSTMCell"),f=Le(o,"h","basicLSTMCell"),h=tr([l,f],1),d=Ot(h,s),p=Sn(d,u),v=p.shape[0],m=p.shape[1]/4,g=[v,m],y=rr(p,[0,0],g),b=rr(p,[0,m],g),w=rr(p,[0,2*m],g),k=rr(p,[0,3*m],g),x=Sn(In(nr(y),ar(b)),In(c,nr(Sn(i,w))));return[x,In(ar(x),nr(k))]}});var ir=Oe({batchToSpaceND_:function(e,t,n){var r=Le(e,"x","batchToSpaceND"),a=t.reduce((function(e,t){return e*t}));c(r.rank>=1+t.length,(function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+t.length})),c(n.length===t.length,(function(){return"crops.length is "+n.length+" but should be equal to blockShape.length  "+t.length})),c(r.shape[0]%a==0,(function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+t.join(" * ")+" === "+a}));var o={x:r},i={blockShape:t,crops:n};return De.runKernel("BatchToSpaceND",o,i)}});var sr=Oe({batchNorm_:function(e,t,n,r,a,o){null==o&&(o=.001);var i,s,u=Le(e,"x","batchNorm"),l=Le(t,"mean","batchNorm"),f=Le(n,"variance","batchNorm");null!=a&&(i=Le(a,"scale","batchNorm")),null!=r&&(s=Le(r,"offset","batchNorm")),c(l.rank===f.rank,(function(){return"Batch normalization gradient requires mean and variance to have equal ranks."})),c(null==s||l.rank===s.rank,(function(){return"Batch normalization gradient requires mean and offset to have equal ranks."})),c(null==i||l.rank===i.rank,(function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}));var h={x:function(e){return 0===e.rank||1===e.rank?$n(e,[1,1,1,e.size]):2===e.rank?$n(e,[1,1,e.shape[0],e.shape[1]]):3===e.rank?$n(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e}(u),scale:i,offset:s,mean:l,variance:f},d={varianceEpsilon:o},p=De.runKernel("FusedBatchNorm",h,d);return $n(p,u.shape)}});var ur=Oe({batchNorm2d_:function(e,t,n,r,a,o){var i,s,u=Le(e,"x","batchNorm"),l=Le(t,"mean","batchNorm"),f=Le(n,"variance","batchNorm");return null!=a&&(i=Le(a,"scale","batchNorm")),null!=r&&(s=Le(r,"offset","batchNorm")),c(2===u.rank,(function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+u.rank+"."})),c(2===l.rank||1===l.rank,(function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+l.rank+"."})),c(2===f.rank||1===f.rank,(function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+f.rank+"."})),null!=i&&c(2===i.rank||1===i.rank,(function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+i.rank+"."})),null!=s&&c(2===s.rank||1===s.rank,(function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+s.rank+"."})),sr(u,l,f,s,i,o)}});var lr=Oe({batchNorm3d_:function(e,t,n,r,a,o){var i,s,u=Le(e,"x","batchNorm"),l=Le(t,"mean","batchNorm"),f=Le(n,"variance","batchNorm");return null!=a&&(i=Le(a,"scale","batchNorm")),null!=r&&(s=Le(r,"offset","batchNorm")),c(3===u.rank,(function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."})),c(3===l.rank||1===l.rank,(function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+l.rank+"."})),c(3===f.rank||1===f.rank,(function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+f.rank+"."})),null!=i&&c(3===i.rank||1===i.rank,(function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+i.rank+"."})),null!=s&&c(3===s.rank||1===s.rank,(function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+s.rank+"."})),sr(u,l,f,s,i,o)}});var cr=Oe({batchNorm4d_:function(e,t,n,r,a,o){var i,s,u=Le(e,"x","batchNorm"),l=Le(t,"mean","batchNorm"),f=Le(n,"variance","batchNorm");return null!=a&&(i=Le(a,"scale","batchNorm")),null!=r&&(s=Le(r,"offset","batchNorm")),c(4===u.rank,(function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+u.rank+"."})),c(4===l.rank||1===l.rank,(function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+l.rank+"."})),c(4===f.rank||1===f.rank,(function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+f.rank+"."})),null!=i&&c(4===i.rank||1===i.rank,(function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+i.rank+"."})),null!=s&&c(4===s.rank||1===s.rank,(function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+s.rank+"."})),sr(u,l,f,s,i,o)}});var fr=Oe({bincount_:function(e,t,n){var r=Le(e,"x","bincount"),a=Le(t,"weights","bincount");c("int32"===r.dtype,(function(){return"Error in bincount: input dtype must be int32, but got "+r.dtype})),c(n>=0,(function(){return"size must be non-negative, but got "+n+"."})),c(a.size===r.size||0===a.size,(function(){return"Error in bincount: weights must have the same size as input or0-length, but got input shape: "+r.shape+", weights shape: "+a.shape+"."}));var o={x:r,weights:a},i={size:n};return De.runKernel("Bincount",o,i)}});var hr=Oe({broadcastTo_:function(e,t){var n=Le(e,"broadcastTo","x"),r=n.shape;if(t.some((function(e){return!(e>0)||e%1!=0})))throw new Error("broadcastTo(): Invalid broadcast shape ["+t+"].");if(t.length<n.rank)throw new Error("broadcastTo(): shape.length="+t.length+" < input.rank="+n.rank+".");if(t.length>n.rank){for(var a=n.shape.slice();a.length<t.length;)a.unshift(1);n=$n(n,a)}for(var o=n.shape,i=Array.from(t),s=t.length-1;s>=0;s--)if(o[s]===t[s])i[s]=1;else if(1!==n.shape[s])throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+t+"].");if(0===i.map((function(e,t){return e>1?t:-1})).filter((function(e){return e>=0})).length)return St(n);var u={x:n},l={reps:i};return De.runKernel("Tile",u,l)}});var dr=Oe({ceil_:function(e){var t={x:Le(e,"x","ceil")};return De.runKernel("Ceil",t)}});var pr=Oe({clipByValue_:function(e,t,n){var r=Le(e,"x","clipByValue");c(t<=n,(function(){return"Error in clip: min ("+t+") must be less than or equal to max ("+n+")."}));var a={x:r},o={clipValueMin:t,clipValueMax:n};return De.runKernel("ClipByValue",a,o)}});var vr=Oe({concat1d_:function(e){return tr(e,0)}});var mr=Oe({concat2d_:function(e,t){return tr(e,t)}});var gr=Oe({concat3d_:function(e,t){return tr(e,t)}});var yr=Oe({concat4d_:function(e,t){return tr(e,t)}});var br=Oe({conv2d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NHWC"),void 0===o&&(o=[1,1]);var s=Le(e,"x","conv2d"),u=Le(t,"filter","conv2d"),l=s,f=!1;3===s.rank&&(f=!0,l=$n(s,[1,s.shape[0],s.shape[1],s.shape[2]])),c(4===l.rank,(function(){return"Error in conv2d: input must be rank 4, but got rank "+l.rank+"."})),c(4===u.rank,(function(){return"Error in conv2d: filter must be rank 4, but got rank "+u.rank+"."})),null!=i&&c(m(r),(function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."}));var h="NHWC"===a?l.shape[3]:l.shape[1];c(h===u.shape[2],(function(){return"Error in conv2d: depth of input ("+h+") must match input depth for filter "+u.shape[2]+"."})),c(Zn(n,o),(function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"}));var d={x:l,filter:u},p={strides:n,pad:r,dataFormat:a,dilations:o,dimRoundingMode:i},v=De.runKernel("Conv2D",d,p);return f?$n(v,[v.shape[1],v.shape[2],v.shape[3]]):v}});var wr=Oe({conv1d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NWC"),void 0===o&&(o=1);var s=Le(e,"x","conv1d"),u=Le(t,"filter","conv1d"),l=s,f=!1;2===s.rank&&(f=!0,l=$n(s,[1,s.shape[0],s.shape[1]])),c(3===l.rank,(function(){return"Error in conv1d: input must be rank 3, but got rank "+l.rank+"."})),c(3===u.rank,(function(){return"Error in conv1d: filter must be rank 3, but got rank "+u.rank+"."})),null!=i&&c(m(r),(function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."})),c(l.shape[2]===u.shape[1],(function(){return"Error in conv1d: depth of input ("+l.shape[2]+") must match input depth for filter "+u.shape[1]+"."})),c(Zn(n,o),(function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+n+" and dilation '"+o+"'"})),c("NWC"===a,(function(){return"Error in conv1d: got dataFormat of "+a+" but only NWC is currently supported."}));var h=$n(u,[1,u.shape[0],u.shape[1],u.shape[2]]),d=$n(l,[l.shape[0],1,l.shape[1],l.shape[2]]),p=br(d,h,[1,n],r,"NHWC",[1,o],i);return $n(p,f?[p.shape[2],p.shape[3]]:[p.shape[0],p.shape[2],p.shape[3]])}});var kr=Oe({conv2DBackpropInput_:function(e,t,n,r,a,o,i){void 0===o&&(o="NHWC"),c(e.length===t.rank,(function(){return"Length of inShape ("+e.length+") and rank of dy ("+t.rank+") must match"}));var s=e,u=t,l=!1;3===t.rank&&(l=!0,u=$n(t,[1,t.shape[0],t.shape[1],t.shape[2]]),s=[1,e[0],e[1],e[2]]),c(4===s.length,(function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+s.length+"."})),c(4===u.rank,(function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+u.rank})),c(4===n.rank,(function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+n.rank}));var f="NHWC"===o?s[3]:s[1],h="NHWC"===o?u.shape[3]:u.shape[1];c(f===n.shape[2],(function(){return"Error in conv2dDerInput: depth of input ("+f+") must match input depth for filter "+n.shape[2]+"."})),c(h===n.shape[3],(function(){return"Error in conv2dDerInput: depth of output ("+h+") must match output depth for filter "+n.shape[3]+"."})),null!=i&&c(m(a),(function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+a+"."}));var d={dy:u,filter:n},p={strides:r,pad:a,dataFormat:o,dimRoundingMode:i,inputShape:s},v=De.runKernel("Conv2DBackpropInput",d,p);return l?$n(v,[v.shape[1],v.shape[2],v.shape[3]]):v}});var xr=Oe({conv2dTranspose_:function(e,t,n,r,a,o){var i=Le(e,"x","conv2dTranspose"),s=Le(t,"filter","conv2dTranspose");return kr(n,i,s,r,a,"NHWC",o)}});var Er=Oe({conv3d_:function(e,t,n,r,a,o){void 0===a&&(a="NDHWC"),void 0===o&&(o=[1,1,1]);var i=Le(e,"x","conv3d"),s=Le(t,"filter","conv3d"),u=i,l=!1;4===i.rank&&(l=!0,u=$n(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),c(5===u.rank,(function(){return"Error in conv3d: input must be rank 5, but got rank "+u.rank+"."})),c(5===s.rank,(function(){return"Error in conv3d: filter must be rank 5, but got rank "+s.rank+"."})),c(u.shape[4]===s.shape[3],(function(){return"Error in conv3d: depth of input ("+u.shape[4]+") must match input depth for filter "+s.shape[3]+"."})),c(Zn(n,o),(function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"})),c("NDHWC"===a,(function(){return"Error in conv3d: got dataFormat of "+a+" but only NDHWC is currently supported."}));var f={x:u,filter:s},h={strides:n,pad:r,dataFormat:a,dilations:o},d=De.runKernel("Conv3D",f,h);return l?$n(d,[d.shape[1],d.shape[2],d.shape[3],d.shape[4]]):d}});var Sr=Oe({conv3DBackpropInput_:function(e,t,n,r,a){c(e.length===t.rank,(function(){return"Length of inShape ("+e.length+") and rank of dy ("+t.rank+") must match"}));var o=e,i=t,s=!1;4===t.rank&&(s=!0,i=$n(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]]),o=[1,e[0],e[1],e[2],e[3]]);var u=o[4],l=i.shape[4];c(5===o.length,(function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+o.length+"."})),c(5===i.rank,(function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+i.rank})),c(5===n.rank,(function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+n.rank})),c(u===n.shape[3],(function(){return"Error in conv3dDerInput: depth of input ("+u+") must match input depth for filter "+n.shape[3]+"."})),c(l===n.shape[4],(function(){return"Error in conv3dDerInput: depth of output ("+l+") must match output depth for filter "+n.shape[4]+"."}));var f={dy:i,filter:n},h={pad:a,strides:r,inputShape:o},d=De.runKernel("Conv3DBackpropInputV2",f,h);return s?$n(d,[d.shape[1],d.shape[2],d.shape[3],d.shape[4]]):d}});var Ar=Oe({conv3dTranspose_:function(e,t,n,r,a){var o=Le(e,"x","conv3dTranspose"),i=Le(t,"filter","conv3dTranspose");return Sr(n,o,i,r,a)}});var Mr=Oe({cos_:function(e){var t={x:Le(e,"x","cos")};return De.runKernel("Cos",t)}});var Ir=Oe({cosh_:function(e){var t={x:Le(e,"x","cosh")};return De.runKernel("Cosh",t)}});var Nr=Oe({cumsum_:function(e,t,n,r){void 0===t&&(t=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var a={x:Le(e,"x","cumsum")},o={axis:t,exclusive:n,reverse:r};return De.runKernel("Cumsum",a,o)}});var _r=Oe({denseBincount_:function(e,t,n,r){void 0===r&&(r=!1);var a=Le(e,"x","denseBincount"),o=Le(t,"weights","denseBincount");c("int32"===a.dtype,(function(){return"Error in denseBincount: input dtype must be int32, but got "+a.dtype})),c(a.rank<=2,(function(){return"Error in denseBincount: input must be at most rank 2, but got rank "+a.rank+"."})),c(n>=0,(function(){return"size must be non-negative, but got "+n+"."})),c(o.size===a.size||0===o.size,(function(){return"Error in denseBincount: weights must have the same shape as x or 0-length, but got x shape: "+a.shape+", weights shape: "+o.shape+"."}));var i={x:a,weights:o},s={size:n,binaryOutput:r};return De.runKernel("DenseBincount",i,s)}});var Dr=Oe({depthToSpace_:function(e,t,n){void 0===n&&(n="NHWC");var r=Le(e,"x","depthToSpace"),a="NHWC"===n?r.shape[1]:r.shape[2],o="NHWC"===n?r.shape[2]:r.shape[3],i="NHWC"===n?r.shape[3]:r.shape[1];c(a*t>=0,(function(){return"Negative dimension size caused by overflow when multiplying\n    "+a+" and "+t+"  for depthToSpace with input shape\n    "+r.shape})),c(o*t>=0,(function(){return"Negative dimension size caused by overflow when multiplying\n    "+o+" and "+t+" for depthToSpace with input shape\n        "+r.shape})),c(i%(t*t)==0,(function(){return"Dimension size must be evenly divisible by "+t*t+" but is "+i+" for depthToSpace with input shape "+r.shape}));var s={x:r},u={blockSize:t,dataFormat:n};return De.runKernel("DepthToSpace",s,u)}});var Tr=Oe({depthwiseConv2d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NHWC"),void 0===o&&(o=[1,1]);var s=Le(e,"x","depthwiseConv2d"),u=Le(t,"filter","depthwiseConv2d"),l=s,f=!1;3===s.rank&&(f=!0,l=$n(s,[1,s.shape[0],s.shape[1],s.shape[2]])),c(4===l.rank,(function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+l.rank+"."})),c(4===u.rank,(function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+u.rank+"."})),c(l.shape[3]===u.shape[2],(function(){return"Error in depthwiseConv2d: number of input channels ("+l.shape[3]+") must match the inChannels dimension in filter "+u.shape[2]+"."})),null!=i&&c(m(r),(function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."}));var h={x:l,filter:u},d={strides:n,pad:r,dataFormat:a,dilations:o,dimRoundingMode:i},p=De.runKernel("DepthwiseConv2dNative",h,d);return f?$n(p,[p.shape[1],p.shape[2],p.shape[3]]):p}});var Rr=Oe({diag_:function(e){var t={x:Le(e,"x","diag")};return De.runKernel("Diag",t)}});var Fr=Oe({dilation2d_:function(e,t,n,r,a,o){void 0===a&&(a=[1,1]),void 0===o&&(o="NHWC");var i=Le(e,"x","dilation2d"),s=Le(t,"filter","dilation2d");c(3===i.rank||4===i.rank,(function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+i.rank+"."})),c(3===s.rank,(function(){return"Error in dilation2d: filter must be rank 3, but got rank "+s.rank+"."})),c("NHWC"===o,(function(){return"Error in dilation2d: Only NHWC is currently supported, but got dataFormat of "+o}));var u=i,l=!1;3===i.rank&&(u=$n(i,[1,i.shape[0],i.shape[1],i.shape[2]]),l=!0);var f={x:u,filter:s},h={strides:n,pad:r,dilations:a},d=De.runKernel("Dilation2D",f,h);return l?$n(d,[d.shape[1],d.shape[2],d.shape[3]]):d}});function Cr(e,t){for(var n=[],r=0;r<t.length;r++){var a=e[e.length-r-1],o=t.length-r-1,i=t[o];(null==a||1===a&&i>1)&&n.unshift(o)}return n}function Br(e,t){for(var n=[],r=Math.max(e.length,t.length),a=0;a<r;a++){var o=e[e.length-a-1];null==o&&(o=1);var i=t[t.length-a-1];if(null==i&&(i=1),1===o)n.unshift(i);else if(1===i)n.unshift(o);else{if(o!==i)throw Error("Operands could not be broadcast together with shapes "+e+" and "+t+".");n.unshift(o)}}return n}var Pr=Oe({equal_:function(e,t){var n,r=Le(e,"a","equal"),a=Le(t,"b","equal");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("Equal",o)}});var Lr=Oe({where_:function(e,t,n){var r=Le(t,"a","where"),a=Le(n,"b","where"),o=Le(e,"condition","where","bool"),i=Br(Br(o.shape,r.shape),a.shape),s={condition:hr(o,i),t:hr(r,i),e:hr(a,i)};return De.runKernel("Select",s)}});var zr=Oe({zerosLike_:function(e){var t={x:Le(e,"x","zerosLike")};return De.runKernel("ZerosLike",t)}});var Or=Oe({divNoNan_:function(e,t){var n,r=Le(e,"a","div"),a=Le(t,"b","div");r=(n=xe(r,a))[0],a=n[1];var o=Mn(r,a),i=zr(o),s=Pr(a,i);return Lr(s,i,o)}});var Kr=Oe({dot_:function(e,t){var n=Le(e,"t1","dot"),r=Le(t,"t2","dot");c(!(1!==n.rank&&2!==n.rank||1!==r.rank&&2!==r.rank),(function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+n.rank+" and "+r.rank+"."}));var a=1===n.rank?n.size:n.shape[1],o=1===r.rank?r.size:r.shape[0];if(c(a===o,(function(){return"Error in dot: inner dimensions of inputs must match, but got "+a+" and "+o+"."})),1===n.rank&&1===r.rank){var i=$n(n,[1,-1]),s=$n(r,[-1,1]),u=Ot(i,s);return $n(u,[])}if(1===n.rank&&2===r.rank){i=$n(n,[1,-1]),s=$n(r,[r.shape[0],r.shape[1]]),u=Ot(i,s);return $n(u,[u.size])}if(2===n.rank&&1===r.rank){s=$n(r,[-1,1]),u=Ot(n,s);return $n(u,[u.size])}return s=$n(r,[r.shape[0],r.shape[1]]),u=Ot(n,s)}});var Wr=Oe({einsum_:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=t.map((function(e,t){return Le(e,"tensors"+t,"einsum")})),a={equation:e};return De.runKernel("Einsum",r,a)}});var qr=Oe({elu_:function(e){var t={x:Le(e,"x","elu")};return De.runKernel("Elu",t)}});var Ur=Oe({erf_:function(e){var t=Le(e,"x","erf");c("int32"===t.dtype||"float32"===t.dtype,(function(){return"Input dtype must be `int32` or `float32`."})),"int32"===t.dtype&&(t=Et(t,"float32"));var n={x:t};return De.runKernel("Erf",n)}});var Gr=Oe({exp_:function(e){var t={x:Le(e,"x","exp")};return De.runKernel("Exp",t)}});var Vr=Oe({expandDims_:function(e,t){void 0===t&&(t=0);var n=Le(e,"x","expandDims","string_or_numeric");c(t<=n.rank,(function(){return"Axis must be <= rank of the tensor"}));var r={input:n},a={dim:t};return De.runKernel("ExpandDims",r,a)}});var Hr=Oe({expm1_:function(e){var t={x:Le(e,"x","expm1")};return De.runKernel("Expm1",t)}});var jr=Oe({tile_:function(e,t){var n=Le(e,"x","tile","string_or_numeric");c(n.rank===t.length,(function(){return"Error in transpose: rank of input "+n.rank+" must match length of reps "+t+"."}));var r={x:n},a={reps:t};return De.runKernel("Tile",r,a)}});var Jr=Oe({eye_:function(e,t,n,r){void 0===r&&(r="float32"),null==t&&(t=e);for(var a=xt([e,t],r),o=e<=t?e:t,i=0;i<o;++i)a.set(1,i,i);var s=$n(a.toTensor(),[e,t]);if(null==n)return s;if(1===n.length)return jr(Vr(s,0),[n[0],1,1]);if(2===n.length)return jr(Vr(Vr(s,0),0),[n[0],n[1],1,1]);if(3===n.length)return jr(Vr(Vr(Vr(s,0),0),0),[n[0],n[1],n[2],1,1]);throw new Error("eye() currently supports only 1D and 2D batchShapes, but received "+n.length+"D.")}});function Yr(e,t,n){var r={shape:e,value:t,dtype:n};return De.runKernel("Fill",{},r)}var Zr=Oe({floor_:function(e){var t={x:Le(e,"x","floor")};return De.runKernel("Floor",t)}});var Xr=Oe({gather_:function(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var a={x:Le(e,"x","gather"),indices:Le(t,"indices","gather","int32")},o={axis:n,batchDims:r};return De.runKernel("GatherV2",a,o)}});var $r=Oe({greater_:function(e,t){var n,r=Le(e,"a","greater"),a=Le(t,"b","greater");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("Greater",o)}});var Qr=Oe({greaterEqual_:function(e,t){var n,r=Le(e,"a","greaterEqual"),a=Le(t,"b","greaterEqual");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("GreaterEqual",o)}});var ea=Oe({imag_:function(e){var t={input:Le(e,"input","imag")};return De.runKernel("Imag",t)}});var ta=Oe({isFinite_:function(e){var t={x:Le(e,"x","isFinite")};return De.runKernel("IsFinite",t)}});var na=Oe({isInf_:function(e){var t={x:Le(e,"x","isInf")};return De.runKernel("IsInf",t)}});var ra=Oe({isNaN_:function(e){var t={x:Le(e,"x","isNaN")};return De.runKernel("IsNan",t)}});var aa=Oe({leakyRelu_:function(e,t){void 0===t&&(t=.2);var n={x:Le(e,"x","leakyRelu")},r={alpha:t};return De.runKernel("LeakyRelu",n,r)}});var oa=Oe({less_:function(e,t){var n,r=Le(e,"a","less"),a=Le(t,"b","less");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("Less",o)}});var ia=Oe({lessEqual_:function(e,t){var n,r=Le(e,"a","lessEqual"),a=Le(t,"b","lessEqual");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("LessEqual",o)}});var sa=Oe({localResponseNormalization_:function(e,t,n,r,a){void 0===t&&(t=5),void 0===n&&(n=1),void 0===r&&(r=1),void 0===a&&(a=.5);var o=Le(e,"x","localResponseNormalization");c(4===o.rank||3===o.rank,(function(){return"Error in localResponseNormalization: x must be rank 3 or 4 but got\n               rank "+o.rank+"."})),c(m(t),(function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+t+"."}));var i=o,s=!1;3===o.rank&&(s=!0,i=$n(o,[1,o.shape[0],o.shape[1],o.shape[2]]));var u={x:i},l={depthRadius:t,bias:n,alpha:r,beta:a},f=De.runKernel("LRN",u,l);return s?$n(f,[f.shape[1],f.shape[2],f.shape[3]]):f}});var ua=Oe({log_:function(e){var t={x:Le(e,"x","log")};return De.runKernel("Log",t)}});var la=Oe({log1p_:function(e){var t={x:Le(e,"x","log1p")};return De.runKernel("Log1p",t)}});function ca(e,t){c(T(e),(function(){return"The f passed in variableGrads(f) must be a function"})),c(null==t||Array.isArray(t)&&t.every((function(e){return e instanceof be})),(function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"}));var n=null!=t;if(!n)for(var r in t=[],De.registeredVariables)t.push(De.registeredVariables[r]);var a=n?t.filter((function(e){return!e.trainable})):null,o=t.length;c((t=t.filter((function(e){return e.trainable}))).length>0,(function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+o+" variables is trainable."}));var i=De.gradients(e,t,null,!0),s=i.value,u=i.grads;c(u.some((function(e){return null!=e})),(function(){return"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."})),c(0===s.rank,(function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+s.rank+" tensor"}));var l={};return t.forEach((function(e,t){null!=u[t]&&(l[e.name]=u[t])})),null!=a&&a.forEach((function(e){return l[e.name]=null})),{value:s,grads:l}}function fa(e){return De.customGrad(e)}function ha(e){if(e.filter((function(e){return null==e})).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n    the f you passed encloses all operations that lead from x to y.")}var da=Oe({neg_:function(e){var t={x:Le(e,"x","neg")};return De.runKernel("Neg",t)}});var pa=Oe({softplus_:function(e){var t={x:Le(e,"x","softplus")};return De.runKernel("Softplus",t)}});var va=Oe({logSigmoid_:function(e){var t=Le(e,"x","logSigmoid");return fa((function(e){return{value:da(pa(da(e))),gradFunc:function(t){return In(t,nr(da(e)))}}}))(t)}});var ma=Oe({max_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:Le(e,"x","max")},a={reductionIndices:t,keepDims:n};return De.runKernel("Max",r,a)}});var ga=Oe({sub_:function(e,t){var n,r=Le(e,"a","sub"),a=Le(t,"b","sub"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Sub",o)}});var ya=Oe({sum_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=Le(e,"x","sum");"bool"===r.dtype&&(r=Et(r,"int32"));var a={x:r},o={axis:t,keepDims:n};return De.runKernel("Sum",a,o)}});var ba=Oe({logSoftmax_:function(e,t){void 0===t&&(t=-1);var n=Le(e,"logits","logSoftmax");if(-1===t&&(t=n.rank-1),t!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and axis was "+t);return fa((function(e,n){var r=ma(e,t,!0),a=ga(e,r),o=ga(Et(a,"float32"),ua(ya(Gr(a),t,!0)));n([o]);return{value:o,gradFunc:function(e,n){var r=n[0],a=Gr(r);return ga(e,In(ya(e,t,!0),a))}}}))(n)}});function wa(e,t){for(var n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function ka(e,t,n){for(var r=e.length+t.length,a=[],o=0,i=0,s=0;s<r;s++)-1===n.indexOf(s)?a.push(e[o++]):a.push(t[i++]);return a}function xa(e,t){return ka(e,t.map((function(e){return 1})),t)}var Ea=Oe({logSumExp_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=Le(e,"x","logSumExp"),a=y(t,r.shape),o=ma(r,a,!0),i=ga(r,o),s=Gr(i),u=ya(s,a),l=ua(u),c=Sn($n(o,l.shape),l);if(n){var f=xa(c.shape,a);return $n(c,f)}return c}});var Sa=Oe({logicalAnd_:function(e,t){var n=Le(e,"a","logicalAnd","bool"),r=Le(t,"b","logicalAnd","bool");Br(n.shape,r.shape);var a={a:n,b:r};return De.runKernel("LogicalAnd",a)}});var Aa=Oe({logicalNot_:function(e){var t={x:Le(e,"x","logicalNot","bool")};return De.runKernel("LogicalNot",t)}});var Ma=Oe({logicalOr_:function(e,t){var n=Le(e,"a","logicalOr","bool"),r=Le(t,"b","logicalOr","bool");Br(n.shape,r.shape);var a={a:n,b:r};return De.runKernel("LogicalOr",a)}});var Ia=Oe({logicalXor_:function(e,t){var n=Le(e,"a","logicalXor","bool"),r=Le(t,"b","logicalXor","bool");return Br(n.shape,r.shape),Sa(Ma(e,t),Aa(Sa(e,t)))}});var Na=Oe({maxPool_:function(e,t,n,r,a){var o=Le(e,"x","maxPool"),i=o,s=!1;3===o.rank&&(s=!0,i=$n(o,[1,o.shape[0],o.shape[1],o.shape[2]])),c(4===i.rank,(function(){return"Error in maxPool: input must be rank 4 but got rank "+i.rank+"."})),c(Zn(n,1),(function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '1'"})),null!=a&&c(m(r),(function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var u={x:i},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a},f=De.runKernel("MaxPool",u,l);return s?$n(f,[f.shape[1],f.shape[2],f.shape[3]]):f}});var _a=Oe({maxPool3d_:function(e,t,n,r,a,o){void 0===t&&(t=[1,1,1]),void 0===o&&(o="NDHWC");var i=Le(e,"x","maxPool3d"),s=i,u=!1;4===i.rank&&(u=!0,s=$n(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),c(5===s.rank,(function(){return"Error in maxPool3d: x must be rank 5 but got rank "+s.rank+"."})),c("NDHWC"===o,(function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+o})),null!=a&&c(m(r),(function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var l={x:s},f={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:o},h=De.runKernel("MaxPool3D",l,f);return u?$n(h,[h.shape[1],h.shape[2],h.shape[3],h.shape[4]]):h}});var Da=Oe({maxPoolWithArgmax_:function(e,t,n,r,a){void 0===a&&(a=!1);var o={x:Le(e,"x","maxPoolWithArgmax")},i={filterSize:t,strides:n,pad:r,includeBatchInIndex:a},s=De.runKernel("MaxPoolWithArgmax",o,i);return{result:s[0],indexes:s[1]}}});var Ta=Oe({maximum_:function(e,t){var n,r=Le(e,"a","maximum"),a=Le(t,"b","maximum");r=(n=xe(r,a))[0],a=n[1],"bool"===r.dtype&&(r=Et(r,"int32"),a=Et(a,"int32")),Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("Maximum",o)}});var Ra=Oe({mean_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:Le(e,"x","mean")},a={axis:t,keepDims:n};return De.runKernel("Mean",r,a)}});function Fa(e,t){if(void 0===t&&(t="float32"),"complex64"===t){var n=Fa(e,"float32"),r=Fa(e,"float32");return Ke(n,r)}var a=P(p(e),t);return De.makeTensor(a,e,t)}function Ca(e,t){if(void 0===t&&(t="float32"),"complex64"===t){var n=Ca(e,"float32"),r=Fa(e,"float32");return Ke(n,r)}var a=B(p(e),t);return De.makeTensor(a,e,t)}var Ba=Oe({min_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:Le(e,"x","min")},a={axis:t,keepDims:n};return De.runKernel("Min",r,a)}});var Pa=Oe({minimum_:function(e,t){var n,r=Le(e,"a","minimum"),a=Le(t,"b","minimum");r=(n=xe(r,a))[0],a=n[1],"bool"===r.dtype&&(r=Et(r,"int32"),a=Et(a,"int32")),Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("Minimum",o)}});var La=Oe({mirrorPad_:function(e,t,n){c("reflect"===n||"symmetric"===n,(function(){return"Invalid mode. Mode must be either reflect or symmetric. Got "+n+"."}));var r=Le(e,"x","mirrorPad");if(0===r.rank)throw new Error("mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad");c(t.length===r.rank,(function(){return"Padding doesn't match input. Must be "+r.rank+". Got "+t.length+"."}));for(var a="reflect"===n?1:0,o=function(e){c(2===t[e].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),c(t[e][0]>=0&&t[e][0]<=r.shape[e]-a&&t[e][1]>=0&&t[e][1]<=r.shape[e]-a,(function(){return"Padding in dimension "+e+" cannot be greater than or equal to "+(r.shape[e]-a)+" or less than 0 for input of shape "+r.shape}))},i=0;i<r.rank;i++)o(i);var s={paddings:t,mode:n},u={x:r};return De.runKernel("MirrorPad",u,s)}});var za=Oe({mod_:function(e,t){var n,r=Le(e,"a","mod"),a=Le(t,"b","mod"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Mod",o)}});var Oa=Oe({square_:function(e){var t=Le(e,"x","square");return De.runKernel("Square",{x:t},{})}});var Ka=Oe({moments_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=y(t,(e=Le(e,"x","moments")).shape),a=Ra(e,r,n),o=a.shape;n||(o=xa(a.shape,r));var i=Oa(ga(Et(e,"float32"),$n(a,o)));return{mean:a,variance:Ra(i,r,n)}}});var Wa=Oe({multiRNNCell_:function(e,t,n,r){for(var a=Le(t,"data","multiRNNCell"),o=ze(n,"c","multiRNNCell"),i=ze(r,"h","multiRNNCell"),s=a,u=[],l=0;l<e.length;l++){var c=e[l](s,o[l],i[l]);u.push(c[0]),u.push(c[1]),s=c[1]}var f=[],h=[];for(l=0;l<u.length;l+=2)f.push(u[l]),h.push(u[l+1]);return[f,h]}});var qa=Oe({multinomial_:function(e,t,n,r){void 0===r&&(r=!1);var a=Le(e,"logits","multinomial"),o=a.size,i=a.rank;if(o<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+o+".");if(i>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+i);n=n||Math.random();var s={logits:1===i?$n(a,[1,-1]):a},u={numSamples:t,seed:n,normalized:r},l=De.runKernel("Multinomial",s,u);return 1===i?$n(l,[l.size]):l}});var Ua=Oe({notEqual_:function(e,t){var n,r=Le(e,"a","notEqual"),a=Le(t,"b","notEqual");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("NotEqual",o)}});var Ga=Oe({onesLike_:function(e){var t={x:Le(e,"x","onesLike")};return De.runKernel("OnesLike",t)}});var Va=Oe({outerProduct_:function(e,t){var n=Le(e,"v1","outerProduct"),r=Le(t,"v2","outerProduct");c(1===n.rank&&1===r.rank,(function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+n.rank+" and "+r.rank+"."}));var a=$n(n,[-1,1]),o=$n(r,[1,-1]);return Ot(a,o)}});var Ha=Oe({pad_:function(e,t,n){void 0===n&&(n=0);var r=Le(e,"x","pad");if(0===r.rank)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var a={paddings:t,constantValue:n},o={x:r};return De.runKernel("PadV2",o,a)}});var ja=Oe({pad1d_:function(e,t,n){return void 0===n&&(n=0),c(2===t.length,(function(){return"Invalid number of paddings. Must be length of 2."})),Ha(e,[t],n)}});var Ja=Oe({pad2d_:function(e,t,n){return void 0===n&&(n=0),c(2===t.length&&2===t[0].length&&2===t[1].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),Ha(e,t,n)}});var Ya=Oe({pad3d_:function(e,t,n){return void 0===n&&(n=0),c(3===t.length&&2===t[0].length&&2===t[1].length&&2===t[2].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),Ha(e,t,n)}});var Za=Oe({pad4d_:function(e,t,n){return void 0===n&&(n=0),c(4===t.length&&2===t[0].length&&2===t[1].length&&2===t[2].length&&2===t[3].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),Ha(e,t,n)}});var Xa=Oe({spaceToBatchND_:function(e,t,n){var r=Le(e,"x","spaceToBatchND");c(r.rank>=1+t.length,(function(){return"input rank "+r.rank+" should be > than [blockShape] "+t.length})),c(n.length===t.length,(function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+t.length})),c(r.shape.reduce((function(e,r,a){return a>0&&a<=t.length?e&&(r+n[a-1][0]+n[a-1][1])%t[a-1]==0:e}),!0),(function(){return"input spatial dimensions "+r.shape.slice(1)+" with paddings "+n.toString()+" must be divisible by blockShapes "+t.toString()}));var a={x:r},o={blockShape:t,paddings:n};return De.runKernel("SpaceToBatchND",a,o)}});var $a=Oe({pool_:function(e,t,n,r,a,o){null==a&&(a=[1,1]),null==o&&(o=1),0===r&&(r="valid");var i=Le(e,"x","maxPool"),s=i,u=!1;3===i.rank&&(u=!0,s=$n(i,[1,i.shape[0],i.shape[1],i.shape[2]])),c(Zn(o,a),(function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+o+" and dilations '"+a+"'"}));var l,f=Wn(s.shape,t,o,a,r),h=[f.dilationHeight,f.dilationWidth];l="same"===r?function(e,t){var n=e.map((function(e,n){return e+(e-1)*(t[n]-1)})).map((function(e){return e-1})),r=n.map((function(e){return Math.floor(e/2)})),a=n.map((function(e,t){return e-r[t]}));return n.map((function(e,t){return[r[t],a[t]]}))}([f.filterHeight,f.filterWidth],h):[[0,0],[0,0]];var d=1===h[0]&&1===h[1],p=function(e,t,n){var r=n.map((function(e){return e[0]})),a=n.map((function(e){return e[1]})),o=e.concat(r,a),i=t.map((function(e,t){return(e-o[t]%e)%e})),s=a.map((function(e,t){return e+i[t]})),u=t.map((function(e,t){return[r[t],s[t]]})),l=t.map((function(e,t){return[0,i[t]]}));return[u,l]}([f.inHeight,f.inWidth],h,l),v=p[0],m=p[1],g=d?r:"valid",y=d?s:Xa(s,h,v),b=("avg"===n?function(){return Qn(y,t,o,g)}:function(){return Na(y,t,o,g)})(),w=d?b:ir(b,h,m);return u?$n(w,[w.shape[1],w.shape[2],w.shape[3]]):w}});var Qa=Oe({pow_:function(e,t){var n,r=Le(e,"base","pow"),a=Le(t,"exp","pow"),o={a:r=(n=xe(r,a))[0],b:a=n[1]};return De.runKernel("Pow",o)}});var eo=Oe({prelu_:function(e,t){var n={x:Le(e,"x","prelu"),alpha:Le(t,"alpha","prelu")};return De.runKernel("Prelu",n)}});var to=Oe({prod_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=Le(e,"x","prod");"bool"===r.dtype&&(r=Et(r,"int32"));var a={x:r},o={axis:t,keepDims:n};return De.runKernel("Prod",a,o)}});var no=Oe({rand_:function(e,t,n){var r=p(e),a=null;if(null==n||"float32"===n)a=new Float32Array(r);else if("int32"===n)a=new Int32Array(r);else{if("bool"!==n)throw new Error("Unknown data type "+n);a=new Uint8Array(r)}for(var o=0;o<r;o++)a[o]=t();return De.makeTensor(a,e,n)}});"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function ro(e,t){return e(t={exports:{}},t.exports),t.exports}var ao=ro((function(e){!function(e,t,n){function r(e){var t,n=this,r=(t=4022871197,function(e){e=e.toString();for(var n=0;n<e.length;n++){var r=.02519603282416938*(t+=e.charCodeAt(n));r-=t=r>>>0,t=(r*=t)>>>0,t+=4294967296*(r-=t)}return 2.3283064365386963e-10*(t>>>0)});n.next=function(){var e=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=e-(n.c=0|e)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(e),n.s0<0&&(n.s0+=1),n.s1-=r(e),n.s1<0&&(n.s1+=1),n.s2-=r(e),n.s2<0&&(n.s2+=1),r=null}function a(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function o(e,t){var n=new r(e),o=t&&t.state,i=n.next;return i.int32=function(){return 4294967296*n.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.alea=o}(0,e,!1)})),oo=ro((function(e){!function(e,t,n){function r(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),t.next()}function a(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t}function o(e,t){var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xor128=o}(0,e,!1)})),io=ro((function(e){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),r==n.length&&(t.d=t.x<<10^t.x>>>4),t.next()}function a(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function o(e,t){var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xorwow=o}(0,e,!1)})),so=ro((function(e){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.x,a=t.i;return e=r[a],n=(e^=e>>>7)^e<<24,n^=(e=r[a+1&7])^e>>>10,n^=(e=r[a+3&7])^e>>>3,n^=(e=r[a+4&7])^e<<7,e=r[a+7&7],n^=(e^=e<<13)^e<<9,r[a]=n,t.i=a+1&7,n},function(e,t){var n,r=[];if(t===(0|t))r[0]=t;else for(t=""+t,n=0;n<t.length;++n)r[7&n]=r[7&n]<<15^t.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],e.x=r,e.i=0,n=256;n>0;--n)e.next()}(t,e)}function a(e,t){return t.x=e.x.slice(),t.i=e.i,t}function o(e,t){null==e&&(e=+new Date);var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&(o.x&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xorshift7=o}(0,e,!1)})),uo=ro((function(e){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.w,a=t.X,o=t.i;return t.w=r=r+1640531527|0,n=a[o+34&127],e=a[o=o+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=a[o]=n^e,t.i=o,n+(r^r>>>16)|0},function(e,t){var n,r,a,o,i,s=[],u=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,u=Math.max(u,t.length)),a=0,o=-32;o<u;++o)t&&(r^=t.charCodeAt((o+32)%t.length)),0===o&&(i=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,o>=0&&(i=i+1640531527|0,a=0==(n=s[127&o]^=r+i)?a+1:0);for(a>=128&&(s[127&(t&&t.length||0)]=-1),a=127,o=512;o>0;--o)r=s[a+34&127],n=s[a=a+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[a]=r^n;e.w=i,e.X=s,e.i=a}(t,e)}function a(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function o(e,t){null==e&&(e=+new Date);var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&(o.X&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xor4096=o}(0,e,!1)})),lo=ro((function(e){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,r=t.d,a=t.a;return e=e<<25^e>>>7^n,n=n-r|0,r=r<<24^r>>>8^a,a=a-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-r|0,t.d=r<<16^n>>>16^a,t.a=a-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var r=0;r<n.length+20;r++)t.b^=0|n.charCodeAt(r),t.next()}function a(e,t){return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t}function o(e,t){var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.tychei=o}(0,e,!1)})),co=ro((function(e){!function(t,n){var r,a=this,o=n.pow(256,6),i=n.pow(2,52),s=2*i;function u(e,u,d){var p=[],v=f(function e(t,n){var r,a=[],o=typeof t;if(n&&"object"==o)for(r in t)try{a.push(e(t[r],n-1))}catch(e){}return a.length?a:"string"==o?t:t+"\0"}((u=1==u?{entropy:!0}:u||{}).entropy?[e,h(t)]:null==e?function(){try{var e;return r&&(e=r.randomBytes)?e=e(256):(e=new Uint8Array(256),(a.crypto||a.msCrypto).getRandomValues(e)),h(e)}catch(e){var n=a.navigator,o=n&&n.plugins;return[+new Date,a,o,a.screen,h(t)]}}():e,3),p),m=new l(p),g=function(){for(var e=m.g(6),t=o,n=0;e<i;)e=256*(e+n),t*=256,n=m.g(1);for(;e>=s;)e/=2,t/=2,n>>>=1;return(e+n)/t};return g.int32=function(){return 0|m.g(4)},g.quick=function(){return m.g(4)/4294967296},g.double=g,f(h(m.S),t),(u.pass||d||function(e,t,r,a){return a&&(a.S&&c(a,m),e.state=function(){return c(m,{})}),r?(n.random=e,t):e})(g,v,"global"in u?u.global:this==n,u.state)}function l(e){var t,n=e.length,r=this,a=0,o=r.i=r.j=0,i=r.S=[];for(n||(e=[n++]);a<256;)i[a]=a++;for(a=0;a<256;a++)i[a]=i[o=255&o+e[a%n]+(t=i[a])],i[o]=t;(r.g=function(e){for(var t,n=0,a=r.i,o=r.j,i=r.S;e--;)t=i[a=255&a+1],n=256*n+i[255&(i[a]=i[o=255&o+t])+(i[o]=t)];return r.i=a,r.j=o,n})(256)}function c(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function f(e,t){for(var n,r=e+"",a=0;a<r.length;)t[255&a]=255&(n^=19*t[255&a])+r.charCodeAt(a++);return h(t)}function h(e){return String.fromCharCode.apply(0,e)}if(n.seedrandom=u,f(n.random(),t),e.exports){e.exports=u;try{r=require("crypto")}catch(e){}}}([],Math)}));co.alea=ao,co.xor128=oo,co.xorwow=io,co.xorshift7=so,co.xor4096=uo,co.tychei=lo;var fo=co.alea,ho=function(){function e(e,t,n,r,a){this.mean=e,this.stdDev=t,this.dtype=n,this.nextVal=NaN,this.truncated=r,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var o=a||Math.random();this.random=fo(o.toString())}return e.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var e=this.nextVal;return this.nextVal=NaN,e}for(var t,n,r=!1;!r;){var a=void 0,o=void 0,i=void 0;do{i=(a=2*this.random()-1)*a+(o=2*this.random()-1)*o}while(i>=1||0===i);var s=Math.sqrt(-2*Math.log(i)/i);t=this.mean+this.stdDev*a*s,n=this.mean+this.stdDev*o*s,this.truncated&&!this.isValidTruncated(t)||(r=!0)}return this.truncated&&!this.isValidTruncated(n)||(this.nextVal=this.convertValue(n)),this.convertValue(t)},e.prototype.convertValue=function(e){return null==this.dtype||"float32"===this.dtype?e:Math.round(e)},e.prototype.isValidTruncated=function(e){return e<=this.upper&&e>=this.lower},e}(),po=function(){function e(e,t,n,r){this.alpha=e,this.beta=1/t,this.dtype=n;var a=r||Math.random();this.randu=fo(a.toString()),this.randn=new ho(0,1,n,!1,this.randu()),this.d=e<1?e+2/3:e-1/3,this.c=1/Math.sqrt(9*this.d)}return e.prototype.nextValue=function(){for(var e,t,n,r,a,o;;){do{r=this.randn.nextValue(),o=1+this.c*r}while(o<=0);if(o*=o*o,t=1-.331*(e=r*r)*e,n=.5*e+this.d*(1-o+Math.log(o)),(a=this.randu())<t||Math.log(a)<n)break}return o=1/this.beta*this.d*o,this.alpha<1&&(o*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(o)},e.prototype.convertValue=function(e){return"float32"===this.dtype?e:Math.round(e)},e}(),vo=function(){function e(e,t,n,r){var a=this;if(void 0===e&&(e=0),void 0===t&&(t=1),this.canReturnFloat=function(){return null==a.dtype||"float32"===a.dtype},this.min=e,this.range=t-e,this.dtype=n,null==r&&(r=Math.random()),"number"==typeof r&&(r=r.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+e+" - "+t+" <= 1 and dtype is not float");this.random=fo(r)}return e.prototype.convertValue=function(e){return this.canReturnFloat()?e:Math.round(e)},e.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},e}();var mo=Oe({randomGamma_:function(e,t,n,r,a){if(void 0===n&&(n=1),void 0===r&&(r="float32"),null==n&&(n=1),null==r&&(r="float32"),"float32"!==r&&"int32"!==r)throw new Error("Unsupported data type "+r);for(var o=new po(t,n,r,a),i=xt(e,r),s=0;s<i.values.length;s++)i.values[s]=o.nextValue();return i.toTensor()}});var go=Oe({randomNormal_:function(e,t,n,r,a){if(void 0===t&&(t=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type "+r);for(var o=new ho(t,n,r,!1,a),i=xt(e,r),s=0;s<i.values.length;s++)i.values[s]=o.nextValue();return i.toTensor()}});var yo=Oe({randomUniform_:function(e,t,n,r,a){void 0===t&&(t=0),void 0===n&&(n=1),void 0===r&&(r="float32");for(var o=xt(e,r),i=new vo(t,n,null,a),s=0;s<o.values.length;s++)o.values[s]=i.nextValue();return o.toTensor()}});function bo(e,t,n,r){if(void 0===n&&(n=1),void 0===r&&(r="float32"),0===n)throw new Error("Cannot have a step of zero");var a={start:e,stop:t,step:n,dtype:r};return De.runKernel("Range",{},a)}var wo=Oe({real_:function(e){var t={input:Le(e,"input","real")};return De.runKernel("Real",t)}});var ko=Oe({reciprocal_:function(e){var t={x:Le(e,"x","reciprocal")};return De.runKernel("Reciprocal",t)}});var xo=Oe({relu_:function(e){var t={x:Le(e,"x","relu")};return De.runKernel("Relu",t)}});var Eo=Oe({relu6_:function(e){var t={x:Le(e,"x","relu6")};return De.runKernel("Relu6",t)}});var So=Oe({reverse_:function(e,t){var n={x:Le(e,"x","reverse")},r={dims:t};return De.runKernel("Reverse",n,r)}});var Ao=Oe({reverse1d_:function(e){var t=Le(e,"x","reverse");return c(1===t.rank,(function(){return"Error in reverse1D: x must be rank 1 but got rank "+t.rank+"."})),So(t,0)}});var Mo=Oe({reverse2d_:function(e,t){var n=Le(e,"x","reverse");return c(2===n.rank,(function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."})),So(n,t)}});var Io=Oe({reverse3d_:function(e,t){var n=Le(e,"x","reverse");return c(3===n.rank,(function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."})),So(n,t)}});var No=Oe({reverse4d_:function(e,t){var n=Le(e,"x","reverse");return c(4===n.rank,(function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."})),So(n,t)}});var _o=Oe({round_:function(e){var t={x:Le(e,"x","round")};return De.runKernel("Round",t)}});var Do=Oe({rsqrt_:function(e){var t={x:Le(e,"x","rsqrt")};return De.runKernel("Rsqrt",t)}});function To(e,t){if((S(e)&&"string"!==t||Array.isArray(e))&&"complex64"!==t)throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if("string"===t&&S(e)&&!(e instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return We(e,[],[],t)}var Ro=Oe({selu_:function(e){var t={x:Le(e,"x","selu")};return De.runKernel("Selu",t)}});var Fo=Oe({separableConv2d_:function(e,t,n,r,a,o,i){void 0===o&&(o=[1,1]),void 0===i&&(i="NHWC");var s=Le(e,"x","separableConv2d"),u=Le(t,"depthwiseFilter","separableConv2d"),l=Le(n,"pointwiseFilter","separableConv2d"),f=s,h=!1;if(3===s.rank&&(h=!0,f=$n(s,[1,s.shape[0],s.shape[1],s.shape[2]])),"NCHW"===i)throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");c(4===f.rank,(function(){return"Error in separableConv2d: input must be rank 4, but got rank "+f.rank+"."})),c(4===u.rank,(function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+u.rank+"."})),c(4===l.rank,(function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+u.rank+"."})),c(1===l.shape[0],(function(){return"Error in separableConv2d: the first dimension of pointwise filter  must be 1, but got "+l.shape[0]+"."})),c(1===l.shape[1],(function(){return"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+l.shape[1]+"."}));var d=u.shape[2],p=u.shape[3];c(l.shape[2]===d*p,(function(){return"Error in separableConv2d: the third dimension of pointwise filter must be "+d*p+", but got "+l.shape[2]+"."}));var v=Tr(f,u,r,a,i,o),m=br(v,l,1,"valid",i);return h?$n(m,[m.shape[1],m.shape[2],m.shape[3]]):m}});var Co=function(e,t){return r(this,void 0,void 0,(function(){var n,r,o,i,s,u,l,f,h,d;return a(this,(function(a){switch(a.label){case 0:return n=Le(e,"x","setdiff1d"),r=Le(t,"y","setdiff1d"),c(n.dtype===r.dtype,(function(){return"x and y should have the same dtype, but got x ("+n.dtype+") and y ("+r.dtype+")."})),c(1===n.rank,(function(){return"x should be 1D tensor, but got x ("+n.shape+")."})),c(1===r.rank,(function(){return"y should be 1D tensor, but got y ("+r.shape+")."})),[4,n.data()];case 1:return o=a.sent(),[4,r.data()];case 2:for(i=a.sent(),s=new Set(i),u=0,h=0;h<o.length;h++)s.has(o[h])||u++;for(l=new ce([u],n.dtype),f=new ce([u],"int32"),h=0,d=0;h<o.length;h++)s.has(o[h])||(l.values[d]=o[h],f.values[d]=h,d++);return[2,[l.toTensor(),f.toTensor()]]}}))}))};var Bo=Oe({sign_:function(e){var t={x:Le(e,"x","sign")};return De.runKernel("Sign",t)}});var Po=Oe({sin_:function(e){var t={x:Le(e,"x","sin")};return De.runKernel("Sin",t)}});var Lo=Oe({sinh_:function(e){var t={x:Le(e,"x","sinh")};return De.runKernel("Sinh",t)}});var zo=Oe({slice1d_:function(e,t,n){var r=Le(e,"x","slice1d");return c(1===r.rank,(function(){return"slice1d expects a rank-1 tensor, but got a rank-"+r.rank+" tensor"})),rr(r,[t],[n])}});var Oo=Oe({slice2d_:function(e,t,n){var r=Le(e,"x","slice2d");return c(2===r.rank,(function(){return"slice2d expects a rank-2 tensor, but got a rank-"+r.rank+" tensor"})),rr(r,t,n)}});var Ko=Oe({slice3d_:function(e,t,n){var r=Le(e,"x","slice3d");return c(3===r.rank,(function(){return"slice3d expects a rank-3 tensor, but got a rank-"+r.rank+" tensor"})),rr(r,t,n)}});var Wo=Oe({slice4d_:function(e,t,n){var r=Le(e,"x","slice4d");return c(4===r.rank,(function(){return"slice4d expects a rank-4 tensor, but got a rank-"+r.rank+" tensor"})),rr(r,t,n)}});var qo=Oe({softmax_:function(e,t){void 0===t&&(t=-1);var n=Le(e,"logits","softmax","float32");if(-1===t&&(t=n.rank-1),t!==n.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and dim was "+t);var r={logits:n},a={dim:t};return De.runKernel("Softmax",r,a)}});var Uo=Oe({fft_:function(e){c("complex64"===e.dtype,(function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+e.dtype+"."}));var t={input:e};return De.runKernel("FFT",t)}});var Go=Oe({ifft_:function(e){c("complex64"===e.dtype,(function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+e.dtype+"."}));var t={input:e};return De.runKernel("IFFT",t)}});var Vo=Oe({irfft_:function(e){var t,n=e.shape[e.shape.length-1],r=e.size/n;if(n<=2){var a=$n(e,[r,n]);t=Go(a)}else{var o=[r,2*(n-1)],i=$n(wo(e),[r,n]),s=$n(ea(e),[r,n]),u=So(rr(i,[0,1],[r,n-2]),1),l=In(So(rr(s,[0,1],[r,n-2]),1),To(-1)),c=tr([i,u],1),f=tr([s,l],1);a=$n(Ke(c,f),[o[0],o[1]]);t=Go(a)}if(t=wo(t),3===e.rank&&0!==e.shape[0]){var h=t,d=e.shape[0];t=$n(t,[d,t.shape[0]/d,t.shape[1]]),h.dispose()}return t}});var Ho=Oe({split_:function(e,t,n){void 0===n&&(n=0);var r={x:Le(e,"x","split")},a={numOrSizeSplits:t,axis:n};return De.runKernel("SplitV",r,a)}});var jo=Oe({rfft_:function(e,t){c("float32"===e.dtype,(function(){return"The dtype for rfft() must be real value but got "+e.dtype}));var n,r=e.shape[e.shape.length-1],a=e.size/r;if(null!=t&&t<r){var o=e.shape.map((function(e){return 0})),i=e.shape.map((function(e){return e}));i[e.shape.length-1]=t,n=rr(e,o,i),r=t}else if(null!=t&&t>r){var s=e.shape.map((function(e){return e}));s[e.shape.length-1]=t-r,n=tr([e,Fa(s)],e.shape.length-1),r=t}else n=e;var u=zr(n),l=$n(Ke(n,u),[a,r]),f=Uo(l),h=Math.floor(r/2)+1,d=wo(f),p=ea(f),v=Ho(d,[h,r-h],d.shape.length-1),m=Ho(p,[h,r-h],p.shape.length-1),g=n.shape.slice();return g[n.shape.length-1]=h,$n(Ke(v[0],m[0]),g)}});var Jo=Oe({sqrt_:function(e){var t={x:Le(e,"x","sqrt")};return De.runKernel("Sqrt",t)}});var Yo=Oe({squaredDifference_:function(e,t){var n,r=Le(e,"a","squaredDifference"),a=Le(t,"b","squaredDifference");r=(n=xe(r,a))[0],a=n[1],Br(r.shape,a.shape);var o={a:r,b:a};return De.runKernel("SquaredDifference",o,{})}});var Zo=Oe({squeeze_:function(e,t){var n=Le(e,"x","squeeze");return $n(n,b(n.shape,t).newShape)}});var Xo=Oe({stack_:function(e,t){void 0===t&&(t=0);var n=ze(e,"tensors","stack","string_or_numeric");c(n.length>=1,(function(){return"Pass at least one tensor to tf.stack"})),n.length>0&&c(t<=n[0].rank,(function(){return"Axis must be <= rank of the tensor"}));var r=n,a={axis:t};return De.runKernel("Pack",r,a)}});var $o=Oe({step_:function(e,t){void 0===t&&(t=0);var n={x:Le(e,"x","step")},r={alpha:t};return De.runKernel("Step",n,r)}});var Qo=Oe({stridedSlice_:function(e,t,n,r,a,o,i,s,u){void 0===a&&(a=0),void 0===o&&(o=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===u&&(u=0);var l={x:Le(e,"x","stridedSlice")},c={begin:t,end:n,strides:r,beginMask:a,endMask:o,ellipsisMask:i,newAxisMask:s,shrinkAxisMask:u};return De.runKernel("StridedSlice",l,c)}});var ei=Oe({tan_:function(e){var t={x:Le(e,"x","tan")};return De.runKernel("Tan",t)}});function ti(e,t){h(e);var n=Be(e,t);if(1!==n.length)throw new Error("tensor1d() requires values to be a flat/TypedArray");return We(e,null,n,t)}function ni(e,t,n){if(h(e),null!=t&&2!==t.length)throw new Error("tensor2d() requires shape to have two numbers");var r=Be(e,n);if(2!==r.length&&1!==r.length)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(1===r.length&&null==t)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return We(e,t,r,n)}var ri=Oe({topk_:function(e,t,n){void 0===t&&(t=1),void 0===n&&(n=!0);var r=Le(e,"x","topk");if(0===r.rank)throw new Error("topk() expects the input to be of rank 1 or higher");var a=r.shape[r.shape.length-1];if(t>a)throw new Error("'k' passed to topk() must be <= the last dimension ("+a+") but got "+t);var o={x:r},i={k:t,sorted:n},s=De.runKernel("TopK",o,i);return{values:s[0],indices:s[1]}}});var ai=Oe({truncatedNormal_:function(e,t,n,r,a){if(void 0===t&&(t=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type $ { dtype }");for(var o=new ho(t,n,r,!0,a),i=xt(e,r),s=0;s<i.values.length;s++)i.values[s]=o.nextValue();return i.toTensor()}});var oi=Oe({unique_:function(e,t){void 0===t&&(t=0);var n=Le(e,"x","unique","string_or_numeric");c(n.rank>0,(function(){return"The input tensor must be at least 1D"}));var r={x:n},a={axis:t},o=De.runKernel("Unique",r,a);return{values:o[0],indices:o[1]}}});var ii=Oe({unsortedSegmentSum_:function(e,t,n){var r=Le(e,"x","unsortedSegmentSum"),a=Le(t,"segmentIds","unsortedSegmentSum","int32");c(m(n),(function(){return"numSegments must be of dtype int"}));var o={x:r,segmentIds:a},i={numSegments:n};return De.runKernel("UnsortedSegmentSum",o,i)}});var si=Oe({unstack_:function(e,t){void 0===t&&(t=0);var n=Le(e,"x","unstack","string_or_numeric");c(t>=-n.shape.length&&t<n.shape.length,(function(){return"Axis = "+t+" is not in [-"+n.shape.length+", "+n.shape.length+")"}));var r={value:n},a={axis:t};return De.runKernel("Unpack",r,a)}});function ui(e,t){for(var n=[],r=0;r<t.length;r++)t[r]&&n.push(r);var a=xt(e,"int32"),o=xt([n.length,e.length],"int32");for(r=0;r<n.length;r++){var i=a.indexToLoc(n[r]),s=r*e.length;o.values.set(i,s)}return o.toTensor()}var li=function(e){return r(this,void 0,void 0,(function(){var t,n,r;return a(this,(function(a){switch(a.label){case 0:return[4,(t=Le(e,"condition","whereAsync","bool")).data()];case 1:return n=a.sent(),r=ui(t.shape,n),e!==t&&t.dispose(),[2,r]}}))}))};var ci=function(e,t,n){return r(this,void 0,void 0,(function(){var r,o,i,s,u,l,h,d,p,v,m,g,y;return a(this,(function(a){switch(a.label){case 0:for(r=Le(e,"tensor","boolMask"),o=Le(t,"mask","boolMask","bool"),i=null==n?0:n,s=o.rank,u=r.shape,c(s>0,(function(){return"mask cannot be scalar"})),f(u.slice(i,i+s),o.shape,"mask's shape must match the first K dimensions of tensor's shape,"),l=1,h=i;h<i+s;h++)l*=u[h];return d=u.slice(0,i).concat([l],u.slice(i+s)),p=$n(r,d),v=$n(o,[-1]),[4,li(v)];case 1:return m=a.sent(),g=Zo(m,[1]),y=Xr(p,g,i),e!==r&&r.dispose(),t!==o&&o.dispose(),g.dispose(),p.dispose(),v.dispose(),m.dispose(),[2,y]}}))}))};var fi=Oe({norm_:function(e,t,n,r){void 0===t&&(t="euclidean"),void 0===n&&(n=null),void 0===r&&(r=!1);var a=function e(t,n,r){void 0===r&&(r=null);if(0===t.rank)return Nn(t);if(1!==t.rank&&null===r)return e($n(t,[-1]),n,r);if(1===t.rank||"number"==typeof r||Array.isArray(r)&&1===r.length){if(1===n)return ya(Nn(t),r);if(n===1/0)return ma(Nn(t),r);if(n===-1/0)return Ba(Nn(t),r);if("euclidean"===n||2===n)return Jo(ya(Qa(Nn(t),To(2,"int32")),r));throw new Error("Error in norm: invalid ord value: "+n)}if(Array.isArray(r)&&2===r.length){if(1===n)return ma(ya(Nn(t),r[0]),r[1]-1);if(n===1/0)return ma(ya(Nn(t),r[1]),r[0]);if(n===-1/0)return Ba(ya(Nn(t),r[1]),r[0]);if("fro"===n||"euclidean"===n)return Jo(ya(Oa(t),r));throw new Error("Error in norm: invalid ord value: "+n)}throw new Error("Error in norm: invalid axis: "+r)}(e=Le(e,"x","norm"),t,n),o=a.shape;if(r){var i=y(n,e.shape);o=xa(a.shape,i)}return $n(a,o)}});var hi=Oe({movingAverage_:function(e,t,n,r,a){void 0===a&&(a=!0);var o=Le(e,"v","movingAverage"),i=Le(t,"x","movingAverage"),s=Le(n,"decay","movingAverage");Ee(o,i),c(v(o.shape,i.shape),(function(){return"Shape mismatch in v and x"}));var u=To(1),l=ga(u,s),f=In(ga(i,o),l);if(a){c(null!=r,(function(){return"When using zeroDebias: true, step is required."}));var h=Le(r,"step","movingAverage");f=Mn(f,ga(u,Qa(s,h)))}return Sn(o,f)}});var di=Oe({scatterND_:function(e,t,n){var r=Le(e,"indices","scatterND","int32"),a=Le(t,"updates","scatterND");Xt(a,r,n);var o={indices:r,updates:a},i={shape:n};return De.runKernel("ScatterNd",o,i)}});var pi=Oe({sparseToDense_:function(e,t,n,r){void 0===r&&(r=0);var a=Le(e,"sparseIndices","sparseToDense","int32"),o=Le(t,"sparseValues","sparseToDense"),i=Le(r,"defaultValue","sparseToDense",o.dtype);!function(e,t,n,r){if("int32"!==e.dtype)throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+e.dtype+".");if(e.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+e.shape+".");var a=e.rank>0?e.shape[0]:1,o=e.rank>1?e.shape[1]:1;if(n.length!==o)throw new Error("outputShape has incorrect number of elements:, "+n.length+", should be: "+o+".");var i=t.size;if(0!==t.rank&&(1!==t.rank||i!==a))throw new Error("sparseValues has incorrect shape "+t.shape+", should be [] or ["+a+"]");if(t.dtype!==r.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(a,o,n,i);var s={sparseIndices:a,sparseValues:o,defaultValue:i},u={outputShape:n};return De.runKernel("SparseToDense",s,u)}});var vi=Oe({gatherND_:function(e,t){var n=Le(t,"indices","gatherND","int32"),r={params:Le(e,"x","gatherND"),indices:n};return De.runKernel("GatherNd",r)}});var mi=Oe({dropout_:function(e,t,n,r){var a=Le(e,"x","dropout");if(c("float32"===a.dtype,(function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+a.dtype+" tensor instead."})),c(t>=0&&t<1,(function(){return"rate must be a float in the range [0, 1), but got "+t+"."})),0===t)return e instanceof de?a.clone():a;var o=function(e,t){if(null==t)return e.shape.slice();if(v(e.shape,t))return t;if(e.shape.length===t.length){for(var n=[],r=0;r<e.shape.length;r++)null==t[r]&&null!=e.shape[r]?n.push(e.shape[r]):n.push(t[r]);return n}return t}(a,n),i=1-t,s=Mn(Zr(Sn(yo(o,0,1,"float32",r),i)),i);return In(a,s)}});function gi(e){return Math.floor(Math.pow(2,Math.ceil(Math.log(e)/Math.log(2))))}function yi(e,t,n){for(var r=1-e%2,a=new Float32Array(e),o=0;o<e;++o){var i=2*Math.PI*o/(e+r-1);a[o]=t-n*Math.cos(i)}return ti(a,"float32")}var bi=function(e,t,n){return void 0===n&&(n=1),r(this,void 0,void 0,(function(){var r,o,i,s,u,l,h,d,p,v,m,g,y,b;return a(this,(function(a){switch(a.label){case 0:return r=Le(e,"predictions","inTopK"),o=Le(t,"targets","inTopK"),c(r.rank>1,(function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank})),c(r.rank-1===o.rank,(function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+o.rank})),f(r.shape.slice(0,r.shape.length-1),o.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),i=r.shape[r.shape.length-1],c(n>0&&n<=i,(function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+i+"), but got "+n})),[4,r.data()];case 1:return s=a.sent(),[4,o.data()];case 2:for(u=a.sent(),l=[s.length/i,i],d=l[1],p=w("bool",h=l[0]),v=0;v<h;v++){for(m=v*d,g=s.subarray(m,m+d),y=[],b=0;b<g.length;b++)y.push({value:g[b],index:b});for(y.sort((function(e,t){return t.value-e.value})),p[v]=0,b=0;b<n;b++)if(y[b].index===u[v]){p[v]=1;break}}return e!==r&&r.dispose(),t!==o&&o.dispose(),[2,qe(p,o.shape,"bool")]}}))}))};var wi=Oe({conv2DBackpropFilter_:function(e,t,n,r,a,o,i){void 0===o&&(o="NHWC");var s=e;3===e.rank&&(s=$n(e,[1,e.shape[0],e.shape[1],e.shape[2]]));var u=t;3===u.rank&&(u=$n(t,[1,t.shape[0],t.shape[1],t.shape[2]])),c(4===s.rank,(function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+s.shape+"."})),c(4===u.rank,(function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+u.shape+"."})),c(4===n.length,(function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+n+"."}));var l="NHWC"===o?s.shape[3]:s.shape[1],f="NHWC"===o?u.shape[3]:u.shape[1];c(l===n[2],(function(){return"Error in conv2dDerFilter: depth of input "+l+") must match input depth in filter ("+n[2]+"."})),c(f===n[3],(function(){return"Error in conv2dDerFilter: depth of dy ("+f+") must match output depth for filter ("+n[3]+")."})),null!=i&&c(m(a),(function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+a+"."}));var h={x:s,dy:u},d={strides:r,pad:a,dataFormat:o,dimRoundingMode:i,filterShape:n};return De.runKernel("Conv2DBackpropFilter",h,d)}});function ki(e,t,n){if(null==n||"linear"===n)return e;if("relu"===n)return In(e,$o(t));throw new Error("Cannot compute gradient for fused activation "+n+".")}function xi(e,t){var n=t,r=Cr(e.shape,t.shape);return r.length>0&&(n=ya(n,r)),$n(n,e.shape)}function Ei(e,t,n,r){if("linear"===t)return e;if("relu"===t)return xo(e);if("elu"===t)return qr(e);if("relu6"===t)return Eo(e);if("prelu"===t)return eo(e,n);if("leakyrelu"===t)return aa(e,r);if("sigmoid"===t)return nr(e);throw new Error("Unknown fused activation "+t+".")}var Si=function(e,t){return!(e>0)||"linear"===t};var Ai=Oe({fusedConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,a=e.pad,o=e.dataFormat,i=void 0===o?"NHWC":o,s=e.dilations,u=void 0===s?[1,1]:s,l=e.dimRoundingMode,f=e.bias,h=e.activation,d=void 0===h?"linear":h,p=e.preluActivationWeights,v=e.leakyreluAlpha;if(d=d||"linear",!1===Si(De.state.gradientDepth,d)){var g=br(t,n,r,a,i,u,l);return null!=f&&(g=Sn(g,f)),Ei(g,d,p,v)}var y=Le(t,"x","conv2d"),b=Le(n,"filter","conv2d"),w=y,k=!1;3===y.rank&&(k=!0,w=$n(y,[1,y.shape[0],y.shape[1],y.shape[2]])),c(4===w.rank,(function(){return"Error in fused conv2d: input must be rank 4, but got rank "+w.rank+"."})),c(4===b.rank,(function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+b.rank+"."})),null!=l&&c(m(a),(function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+l+" but got pad "+a+"."})),c(w.shape[3]===b.shape[2],(function(){return"Error in conv2d: depth of input ("+w.shape[3]+") must match input depth for filter "+b.shape[2]+"."})),c(Zn(r,u),(function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"})),c("NHWC"===i,(function(){return"Error in conv2d: got dataFormat of "+i+" but only NHWC is currently supported."}));var x,E,S=qn(w.shape,b.shape,r,u,a,l);null!=f&&(x=xe(x=Le(f,"bias","fused conv2d"),y)[0],Br(S.outShape,x.shape)),null!=p&&(E=Le(p,"prelu weights","fused conv2d"));var A=function(e,t){var n=t,o=n[0],i=n[1],s=n[2],l=n[3],f=ki(e,s,d);c(Yn(u),(function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+u+"'"}));var h=[kr(i.shape,f,o,r,a),wi(i,f,o.shape,r,a)];if(null!=l){var p=xi(l,f);h.push(p)}return h},M={x:w,filter:b,bias:x,preluActivationWeights:E},I={strides:r,pad:a,dataFormat:i,dilations:u,dimRoundingMode:l,activation:d,leakyreluAlpha:v};return null==f?fa((function(e,t,n){var r=De.runKernel("FusedConv2D",M,I);return n([t,e,r]),k&&(r=$n(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:A}}))(w,b):fa((function(e,t,n,r){var a=De.runKernel("FusedConv2D",M,I);return r([t,e,a,n]),k&&(a=$n(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:A}}))(w,b,x)}});var Mi=Oe({depthwiseConv2dNativeBackpropFilter_:function(e,t,n,r,a,o,i){void 0===o&&(o=[1,1]);var s=e;3===e.rank&&(s=$n(e,[1,e.shape[0],e.shape[1],e.shape[2]]));var u=t;3===u.rank&&(u=$n(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var l={x:s,dy:u},c={strides:r,pad:a,dimRoundingMode:i,dilations:o,filterShape:n};return De.runKernel("DepthwiseConv2dNativeBackpropFilter",l,c)}});var Ii=Oe({depthwiseConv2dNativeBackpropInput_:function(e,t,n,r,a,o,i){void 0===o&&(o=[1,1]);var s=t,u=!1;3===t.rank&&(u=!0,s=$n(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var l={dy:s,filter:n},c={strides:r,pad:a,dimRoundingMode:i,dilations:o,inputShape:e},f=De.runKernel("DepthwiseConv2dNativeBackpropInput",l,c);return u?$n(f,[f.shape[1],f.shape[2],f.shape[3]]):f}});var Ni={__proto__:null,conv2d:Ai,depthwiseConv2d:Oe({fusedDepthwiseConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,a=e.pad,o=e.dataFormat,i=void 0===o?"NHWC":o,s=e.dilations,u=void 0===s?[1,1]:s,l=e.dimRoundingMode,f=e.bias,h=e.activation,d=void 0===h?"linear":h,p=e.preluActivationWeights,v=e.leakyreluAlpha;if(!1===Si(De.state.gradientDepth,d)){var g=Tr(t,n,r,a,i,u,l);return null!=f&&(g=Sn(g,f)),Ei(g,d,p,v)}var y=Le(t,"x","depthwiseConv2d"),b=Le(n,"filter","depthwiseConv2d"),w=y,k=!1;3===y.rank&&(k=!0,w=$n(y,[1,y.shape[0],y.shape[1],y.shape[2]])),c(4===w.rank,(function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+w.rank+"."})),c(4===b.rank,(function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+b.rank+"."})),c(w.shape[3]===b.shape[2],(function(){return"Error in fused depthwiseConv2d: number of input channels ("+w.shape[3]+") must match the inChannels dimension in filter "+b.shape[2]+"."})),null==u&&(u=[1,1]),c(Zn(r,u),(function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"})),null!=l&&c(m(a),(function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+l+" but got pad "+a+"."}));var x,E,S=qn(w.shape,b.shape,r,u,a,l,!0);null!=f&&(x=xe(x=Le(f,"bias","fused conv2d"),y)[0],Br(S.outShape,x.shape)),null!=p&&(E=Le(p,"prelu weights","fused depthwiseConv2d"));var A=function(e,t){c(Yn(u),(function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+u+"'"}));var n=t[0],o=t[1],i=t[2],s=t[3],f=ki(e,i,d),h=Ii(o.shape,f,n,r,a,u,l),p=Mi(o,f,n.shape,r,a,u,l);return null!=s?[h,p,xi(x,f)]:[h,p]},M={x:w,filter:b,bias:x,preluActivationWeights:E},I={strides:r,pad:a,dataFormat:i,dilations:u,dimRoundingMode:l,activation:d,leakyreluAlpha:v};return null==f?fa((function(e,t,n){var r=De.runKernel("FusedDepthwiseConv2D",M,I);return n([t,e,r]),k&&(r=$n(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:A}}))(w,b):fa((function(e,t,n,r){var a=De.runKernel("FusedDepthwiseConv2D",M,I);return r([t,e,a,n]),k&&(a=$n(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:A}}))(w,b,x)}}),matMul:Oe({fusedMatMul_:function(e){var t,n=e.a,r=e.b,a=e.transposeA,o=void 0!==a&&a,i=e.transposeB,s=void 0!==i&&i,u=e.bias,l=e.activation,f=void 0===l?"linear":l,h=e.preluActivationWeights,d=e.leakyreluAlpha;if(!1===Si(De.state.gradientDepth,f)){var m=Ot(n,r,o,s);return null!=u&&(m=Sn(m,u)),Ei(m,f,h,d)}var g=Le(n,"a","fused matMul"),y=Le(r,"b","fused matMul");t=xe(g,y),g=t[0],y=t[1];var b=o?g.shape[g.rank-2]:g.shape[g.rank-1],w=s?y.shape[y.rank-1]:y.shape[y.rank-2],k=o?g.shape[g.rank-1]:g.shape[g.rank-2],x=s?y.shape[y.rank-2]:y.shape[y.rank-1],E=g.shape.slice(0,-2),S=y.shape.slice(0,-2),A=p(E),M=p(S);c(g.rank>=2&&y.rank>=2&&g.rank===y.rank,(function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+g.rank+" and "+y.rank+"."})),c(v(E,S),(function(){return"Error in fused matMul: outer dimensions ("+E+") and ("+S+") of Tensors with shapes "+g.shape+" and "+y.shape+" must match."})),c(b===w,(function(){return"Error in fused matMul: inner shapes ("+b+") and ("+w+") of Tensors with shapes "+g.shape+" and "+y.shape+" and transposeA="+o+" and transposeB="+s+" must match."}));var I,N,_=g.shape.slice(0,-2).concat([k,x]),D=$n(g,o?[A,b,k]:[A,k,b]),T=$n(y,s?[M,x,w]:[M,w,x]);null!=u&&(I=xe(I=Le(u,"bias","fused matMul"),g)[0],Br(_,I.shape)),null!=h&&(N=Le(h,"prelu weights","fused matMul"));var R=function(e,t){var n,r,a=t[0],i=t[1],l=t[2],c=t[3],h=ki($n(e,l.shape),l,f);return o||s?!o&&s?(n=Ot(h,i,!1,!1),r=Ot(h,a,!0,!1)):o&&!s?(n=Ot(i,h,!1,!0),r=Ot(a,h,!1,!1)):(n=Ot(i,h,!0,!0),r=Ot(h,a,!0,!0)):(n=Ot(h,i,!1,!0),r=Ot(a,h,!0,!1)),null!=u?[n,r,xi(c,h)]:[n,r]},F={a:D,b:T,bias:I,preluActivationWeights:N},C={transposeA:o,transposeB:s,activation:f,leakyreluAlpha:d};return null==u?fa((function(e,t,n){var r=De.runKernel("_FusedMatMul",F,C);return n([e,t,r]),{value:$n(r,_),gradFunc:R}}))(D,T):fa((function(e,t,n,r){var a=De.runKernel("_FusedMatMul",F,C);return r([e,t,a,n]),{value:$n(a,_),gradFunc:R}}))(D,T,I)}})};var _i=Oe({hammingWindow_:function(e){return yi(e,.54,.46)}});var Di=Oe({hannWindow_:function(e){return yi(e,.5,.5)}});var Ti=Oe({frame_:function(e,t,n,r,a){void 0===r&&(r=!1),void 0===a&&(a=0);for(var o=0,i=[];o+t<=e.size;)i.push(rr(e,o,t)),o+=n;if(r)for(;o<e.size;){var s=o+t-e.size,u=tr([rr(e,o,t-s),Yr([s],a)]);i.push(u),o+=n}return 0===i.length?ni([],[0,t]):$n(tr(i),[i.length,t])}});var Ri=Oe({stft_:function(e,t,n,r,a){void 0===a&&(a=Di),null==r&&(r=gi(t));var o=Ti(e,t,n),i=In(o,a(t));return jo(i,r)}});var Fi=Oe({cropAndResize_:function(e,t,n,r,a,o){void 0===a&&(a="bilinear"),void 0===o&&(o=0);var i=Le(e,"image","cropAndResize"),s=Le(t,"boxes","cropAndResize","float32"),u=Le(n,"boxInd","cropAndResize","int32"),l=s.shape[0];c(4===i.rank,(function(){return"Error in cropAndResize: image must be rank 4,but got rank "+i.rank+"."})),c(2===s.rank&&4===s.shape[1],(function(){return"Error in cropAndResize: boxes must be have size ["+l+",4] but had shape "+s.shape+"."})),c(1===u.rank&&u.shape[0]===l,(function(){return"Error in cropAndResize: boxInd must be have size ["+l+"] but had shape "+s.shape+"."})),c(2===r.length,(function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."})),c(r[0]>=1&&r[1]>=1,(function(){return"cropSize must be atleast [1,1], but was "+r})),c("bilinear"===a||"nearest"===a,(function(){return"method must be bilinear or nearest, but was "+a}));var f={image:i,boxes:s,boxInd:u},h={method:a,extrapolationValue:o,cropSize:r};return De.runKernel("CropAndResize",f,h)}});var Ci=Oe({flipLeftRight_:function(e){var t=Le(e,"image","flipLeftRight","float32");c(4===t.rank,(function(){return"Error in flipLeftRight: image must be rank 4,but got rank "+t.rank+"."}));var n={image:t};return De.runKernel("FlipLeftRight",n,{})}});var Bi=Oe({rotateWithOffset_:function(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=.5);var a=Le(e,"image","rotateWithOffset","float32");c(4===a.rank,(function(){return"Error in rotateWithOffset: image must be rank 4,but got rank "+a.rank+"."}));var o={image:a},i={radians:t,fillValue:n,center:r};return De.runKernel("RotateWithOffset",o,i)}});function Pi(e,t,n,r,a,o){null==r&&(r=.5),null==a&&(a=Number.NEGATIVE_INFINITY),null==o&&(o=0);var i=e.shape[0];return n=Math.min(n,i),c(0<=r&&r<=1,(function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"})),c(2===e.rank,(function(){return"boxes must be a 2D tensor, but was of rank '"+e.rank+"'"})),c(4===e.shape[1],(function(){return"boxes must have 4 columns, but 2nd dimension was "+e.shape[1]})),c(1===t.rank,(function(){return"scores must be a 1D tensor"})),c(t.shape[0]===i,(function(){return"scores has incompatible shape with boxes. Expected "+i+", but was "+t.shape[0]})),c(0<=o&&o<=1,(function(){return"softNmsSigma must be in [0, 1], but was '"+o+"'"})),{maxOutputSize:n,iouThreshold:r,scoreThreshold:a,softNmsSigma:o}}var Li=Oe({nonMaxSuppression_:function(e,t,n,r,a){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY);var o=Le(e,"boxes","nonMaxSuppression"),i=Le(t,"scores","nonMaxSuppression"),s=Pi(o,i,n,r,a),u={maxOutputSize:n=s.maxOutputSize,iouThreshold:r=s.iouThreshold,scoreThreshold:a=s.scoreThreshold};return De.runKernel("NonMaxSuppressionV3",{boxes:o,scores:i},u)}});function zi(e,t,n){var r=function(e,t,n){return function(e,t,n){var r=0,a=e.length,o=0,i=!1;for(;r<a;){var s=n(t,e[o=r+(a-r>>>1)]);s>0?r=o+1:(a=o,i=!s)}return i?r:-r-1}(e,t,n||Oi)}(e,t,n),a=r<0?-(r+1):r;e.splice(a,0,t)}function Oi(e,t){return e>t?1:e<t?-1:0}function Ki(e,t,n,r,a){return Ui(e,t,n,r,a,0)}function Wi(e,t,n,r,a,o){return Ui(e,t,n,r,a,0,!1,o,!0)}function qi(e,t,n,r,a,o){return Ui(e,t,n,r,a,o,!0)}function Ui(e,t,n,r,a,o,i,s,u){void 0===i&&(i=!1),void 0===s&&(s=!1),void 0===u&&(u=!1);for(var l=[],c=0;c<t.length;c++)t[c]>a&&l.push({score:t[c],boxIndex:c,suppressBeginIndex:0});l.sort(Hi);for(var f=o>0?-.5/o:0,h=[],d=[];h.length<n&&l.length>0;){var p=l.pop(),v=p.score,m=p.boxIndex,g=p.suppressBeginIndex;if(v<a)break;for(var y=!1,b=h.length-1;b>=g;--b){var w=Gi(e,m,h[b]);if(w>=r){y=!0;break}if(p.score=p.score*Vi(r,f,w),p.score<=a)break}p.suppressBeginIndex=h.length,y||(p.score===v?(h.push(m),d.push(p.score)):p.score>a&&zi(l,p,Hi))}var k=h.length,x=n-k;s&&x>0&&(h.push.apply(h,new Array(x).fill(0)),d.push.apply(d,new Array(x).fill(0)));var E={selectedIndices:h};return i&&(E.selectedScores=d),u&&(E.validOutputs=k),E}function Gi(e,t,n){var r=e.subarray(4*t,4*t+4),a=e.subarray(4*n,4*n+4),o=Math.min(r[0],r[2]),i=Math.min(r[1],r[3]),s=Math.max(r[0],r[2]),u=Math.max(r[1],r[3]),l=Math.min(a[0],a[2]),c=Math.min(a[1],a[3]),f=Math.max(a[0],a[2]),h=Math.max(a[1],a[3]),d=(s-o)*(u-i),p=(f-l)*(h-c);if(d<=0||p<=0)return 0;var v=Math.max(o,l),m=Math.max(i,c),g=Math.min(s,f),y=Math.min(u,h),b=Math.max(g-v,0)*Math.max(y-m,0);return b/(d+p-b)}function Vi(e,t,n){var r=Math.exp(t*n*n);return n<=e?r:0}function Hi(e,t){return e.score-t.score||e.score===t.score&&t.boxIndex-e.boxIndex}var ji=function(e,t,n,o,i){return void 0===o&&(o=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),r(this,void 0,void 0,(function(){var r,s,u,l,c,f,h;return a(this,(function(a){switch(a.label){case 0:return r=Le(e,"boxes","nonMaxSuppressionAsync"),s=Le(t,"scores","nonMaxSuppressionAsync"),u=Pi(r,s,n,o,i),n=u.maxOutputSize,o=u.iouThreshold,i=u.scoreThreshold,[4,Promise.all([r.data(),s.data()])];case 1:return l=a.sent(),c=l[0],f=l[1],h=Ki(c,f,n,o,i).selectedIndices,r!==e&&r.dispose(),s!==t&&s.dispose(),[2,ti(h,"int32")]}}))}))};var Ji=Oe({nonMaxSuppressionWithScore_:function(e,t,n,r,a,o){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===o&&(o=0);var i=Le(e,"boxes","nonMaxSuppression"),s=Le(t,"scores","nonMaxSuppression"),u=Pi(i,s,n,r,a,o),l={boxes:i,scores:s},c={maxOutputSize:n=u.maxOutputSize,iouThreshold:r=u.iouThreshold,scoreThreshold:a=u.scoreThreshold,softNmsSigma:o=u.softNmsSigma},f=De.runKernel("NonMaxSuppressionV5",l,c);return{selectedIndices:f[0],selectedScores:f[1]}}});var Yi=function(e,t,n,o,i,s){return void 0===o&&(o=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===s&&(s=0),r(this,void 0,void 0,(function(){var r,u,l,c,f,h,d,p,v;return a(this,(function(a){switch(a.label){case 0:return r=Le(e,"boxes","nonMaxSuppressionAsync"),u=Le(t,"scores","nonMaxSuppressionAsync"),l=Pi(r,u,n,o,i,s),n=l.maxOutputSize,o=l.iouThreshold,i=l.scoreThreshold,s=l.softNmsSigma,[4,Promise.all([r.data(),u.data()])];case 1:return c=a.sent(),f=c[0],h=c[1],d=qi(f,h,n,o,i,s),p=d.selectedIndices,v=d.selectedScores,r!==e&&r.dispose(),u!==t&&u.dispose(),[2,{selectedIndices:ti(p,"int32"),selectedScores:ti(v)}]}}))}))};var Zi=Oe({nonMaxSuppressionPadded_:function(e,t,n,r,a,o){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===o&&(o=!1);var i=Le(e,"boxes","nonMaxSuppression"),s=Le(t,"scores","nonMaxSuppression"),u=Pi(i,s,n,r,a,null),l={boxes:i,scores:s},c={maxOutputSize:u.maxOutputSize,iouThreshold:u.iouThreshold,scoreThreshold:u.scoreThreshold,padToMaxOutputSize:o},f=De.runKernel("NonMaxSuppressionV4",l,c);return{selectedIndices:f[0],validOutputs:f[1]}}});var Xi=function(e,t,n,o,i,s){return void 0===o&&(o=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===s&&(s=!1),r(this,void 0,void 0,(function(){var r,u,l,c,f,h,d,p,v,m,g,y;return a(this,(function(a){switch(a.label){case 0:return r=Le(e,"boxes","nonMaxSuppressionAsync"),u=Le(t,"scores","nonMaxSuppressionAsync"),l=Pi(r,u,n,o,i,null),c=l.maxOutputSize,f=l.iouThreshold,h=l.scoreThreshold,[4,Promise.all([r.data(),u.data()])];case 1:return d=a.sent(),p=d[0],v=d[1],m=Wi(p,v,c,f,h,s),g=m.selectedIndices,y=m.validOutputs,r!==e&&r.dispose(),u!==t&&u.dispose(),[2,{selectedIndices:ti(g,"int32"),validOutputs:To(y,"int32")}]}}))}))};var $i=Oe({resizeBilinear_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=Le(e,"images","resizeBilinear");c(3===a.rank||4===a.rank,(function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+a.rank+"."})),c(2===t.length,(function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+t+"."})),c(!1===r||!1===n,(function(){return"Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false."}));var o=a,i=!1;3===a.rank&&(i=!0,o=$n(a,[1,a.shape[0],a.shape[1],a.shape[2]]));var s={images:o},u={alignCorners:n,halfPixelCenters:r,size:t},l=De.runKernel("ResizeBilinear",s,u);return i?$n(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var Qi=Oe({resizeNearestNeighbor_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=Le(e,"images","resizeNearestNeighbor");c(3===a.rank||4===a.rank,(function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+a.rank+"."})),c(2===t.length,(function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+t+"."})),c("float32"===a.dtype||"int32"===a.dtype,(function(){return"`images` must have `int32` or `float32` as dtype"})),c(!1===r||!1===n,(function(){return"Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false."}));var o=a,i=!1;3===a.rank&&(i=!0,o=$n(a,[1,a.shape[0],a.shape[1],a.shape[2]]));var s={images:o},u={alignCorners:n,halfPixelCenters:r,size:t},l=De.runKernel("ResizeNearestNeighbor",s,u);return i?$n(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var es=Oe({threshold_:function(e,t,n,r){var a;void 0===t&&(t="binary"),void 0===n&&(n=!1),void 0===r&&(r=.5);var o,i,s,u,l=Le(e,"image","threshold"),f=l.shape[0]*l.shape[1],h=In(ti([r]),255);if(c(3===l.rank,(function(){return"Error in threshold: image must be rank 3,but got rank "+l.rank+"."})),c(3===l.shape[2]||1===l.shape[2],(function(){return"Error in threshold: image color channel must be equal to 3 or 1but got "+l.shape[2]+"."})),c("int32"===l.dtype||"float32"===l.dtype,(function(){return"Error in dtype: image dtype must be int32 or float32,but got dtype "+l.dtype+"."})),c("otsu"===t||"binary"===t,(function(){return"Method must be binary or otsu, but was "+t})),3===l.shape[2]){o=(a=Ho(l,[1,1,1],-1))[0],i=a[1],s=a[2];var d=In(o,.2989),p=In(i,.587),v=In(s,.114);u=Sn(Sn(d,p),v)}else u=e;"otsu"===t&&(h=function(e,t){for(var n,r,a,o,i,s,u=ti([-1]),l=ti([0]),c=ti([0]),f=0;f<e.size-1;f++){n=rr(e,0,f+1),r=rr(e,f+1),i=Mn(ya(n),t),s=Mn(ya(r),t);var h=ya(In(n,bo(0,n.size)));a=Mn(h,ya(n));var d=Yr(r.shape,n.size),p=Sn(bo(0,r.size),d),v=In(r,p);o=Mn(ya(v),ya(r));var m=ga(a,o),g=ga(a,o),y=In(i,s);c=In(In(y,m),g);var b=$r(c,l);l=Lr(b,c,l),u=Lr(b,ti([f]),u)}return u}(fr(Et(_o(u),"int32"),qe([]),256),f));var m=n?ia(u,h):$r(u,h);return Et(In(m,255),"int32")}});var ts=Oe({transform_:function(e,t,n,r,a,o){void 0===n&&(n="nearest"),void 0===r&&(r="constant"),void 0===a&&(a=0);var i=Le(e,"image","transform","float32"),s=Le(t,"transforms","transform","float32");c(4===i.rank,(function(){return"Error in transform: image must be rank 4,but got rank "+i.rank+"."})),c(2===s.rank&&(s.shape[0]===i.shape[0]||1===s.shape[0])&&8===s.shape[1],(function(){return"Error in transform: Input transform should be batch x 8 or 1 x 8"})),c(null==o||2===o.length,(function(){return"Error in transform: outputShape must be [height, width] or null, but got "+o+"."}));var u={image:i,transforms:s},l={interpolation:n,fillMode:r,fillValue:a,outputShape:o};return De.runKernel("Transform",u,l)}});var ns=Oe({bandPart_:function(e,t,n){c(t%1==0,(function(){return"bandPart(): numLower must be an integer, got "+t+"."})),c(n%1==0,(function(){return"bandPart(): numUpper must be an integer, got "+n+"."}));var r=Le(e,"a","bandPart");c(r.rank>=2,(function(){return"bandPart(): Rank must be at least 2, got "+r.rank+"."}));var a=r.shape,o=r.shape.slice(-2),i=o[0],s=o[1];if(!(t<=i))throw new Error("bandPart(): numLower ("+t+") must not be greater than the number of rows ("+i+").");if(!(n<=s))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+s+").");t<0&&(t=i),n<0&&(n=s);var u=$n(bo(0,i,1,"int32"),[-1,1]),l=bo(0,s,1,"int32"),f=ga(u,l),h=Sa(ia(f,To(+t,"int32")),Qr(f,To(-n,"int32"))),d=Fa([i,s],r.dtype);return $n(Xo(si($n(r,[-1,i,s])).map((function(e){return Lr(h,e,d)}))),a)}});var rs=Oe({gramSchmidt_:function(e){var t;if(Array.isArray(e)){t=!1,c(null!=e&&e.length>0,(function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"}));for(var n=e[0].shape[0],r=function(t){c(e[t].shape[0]===n,(function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+e[t].shape[0]+" vs. "+n+")"}))},a=1;a<e.length;++a)r(a)}else t=!0,e=Ho(e,e.shape[0],0).map((function(e){return Zo(e,[0])}));c(e.length<=e[0].shape[0],(function(){return"Gram-Schmidt: Number of vectors ("+e.length+") exceeds number of dimensions ("+e[0].shape[0]+")."}));var o=[],i=e,s=function(e){o.push(De.tidy((function(){var t=i[e];if(e>0)for(var n=0;n<e;++n){var r=In(ya(In(o[n],t)),o[n]);t=ga(t,r)}return Mn(t,fi(t,"euclidean"))})))};for(a=0;a<e.length;++a)s(a);return t?Xo(o,0):o}});function as(e,t){return void 0===t&&(t=!1),De.tidy((function(){c(2===e.shape.length,(function(){return"qr2d() requires a 2D Tensor, but got a "+e.shape.length+"D Tensor."}));for(var n=e.shape[0],r=e.shape[1],a=Jr(n),o=St(e),i=ni([[1]],[1,1]),s=St(i),u=n>=r?r:n,l=function(e){var t,u=o,l=s,c=a;t=De.tidy((function(){var t=rr(o,[e,e],[n-e,1]),u=fi(t),l=rr(o,[e,e],[1,1]),c=Lr($r(l,0),ni([[-1]]),ni([[1]])),f=ga(l,In(c,u)),h=Mn(t,f);s=1===h.shape[0]?St(i):tr([i,rr(h,[1,0],[h.shape[0]-1,h.shape[1]])],0);var d=da(Mn(Ot(c,f),u)),p=rr(o,[e,0],[n-e,r]),v=In(d,s),m=Wt(s);if(0===e)o=ga(p,Ot(v,Ot(m,p)));else{var g=ga(p,Ot(v,Ot(m,p)));o=tr([rr(o,[0,0],[e,r]),g],0)}var y=Wt(v),b=rr(a,[0,e],[n,a.shape[1]-e]);if(0===e)a=ga(b,Ot(Ot(b,s),y));else{var w=ga(b,Ot(Ot(b,s),y));a=tr([rr(a,[0,0],[n,e]),w],1)}return[s,o,a]})),s=t[0],o=t[1],a=t[2],xn([u,l,c])},f=0;f<u;++f)l(f);return!t&&n>r&&(a=rr(a,[0,0],[n,r]),o=rr(o,[0,0],[r,r])),[a,o]}))}var os,is=Oe({qr_:function(e,t){if(void 0===t&&(t=!1),c(e.rank>=2,(function(){return"qr() requires input tensor to have a rank >= 2, but got rank "+e.rank})),2===e.rank)return as(e,t);var n=e.shape.slice(0,e.shape.length-2).reduce((function(e,t){return e*t})),r=si($n(e,[n,e.shape[e.shape.length-2],e.shape[e.shape.length-1]]),0),a=[],o=[];return r.forEach((function(e){var n=as(e,t),r=n[0],i=n[1];a.push(r),o.push(i)})),[$n(Xo(a,0),e.shape),$n(Xo(o,0),e.shape)]}});(os=e.Reduction||(e.Reduction={}))[os.NONE=0]="NONE",os[os.MEAN=1]="MEAN",os[os.SUM=2]="SUM",os[os.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS";var ss=Oe({computeWeightedLoss_:function(t,n,r){void 0===r&&(r=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=Le(t,"losses","computeWeightedLoss"),o=null;null!=n&&(o=Le(n,"weights","computeWeightedLoss"));var i=null==o?a:In(a,o);if(r===e.Reduction.NONE)return i;if(r===e.Reduction.SUM)return ya(i);if(r===e.Reduction.MEAN){if(null==o)return Ra(i);var s=a.size/o.size,u=Mn(ya(i),ya(o));return s>1?Mn(u,To(s)):u}if(r===e.Reduction.SUM_BY_NONZERO_WEIGHTS){if(null==o)return Mn(ya(i),To(a.size));var l=In(o,Ca(a.shape)),c=Et(ya(Ua(l,To(0))),"float32");return Mn(ya(i),c)}throw Error("Unknown reduction: "+r)}});var us=Oe({absoluteDifference_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=Le(t,"labels","absoluteDifference"),i=Le(n,"predictions","absoluteDifference"),s=null;null!=r&&(s=Le(r,"weights","absoluteDifference")),f(o.shape,i.shape,"Error in absoluteDifference: ");var u=Nn(ga(o,i));return ss(u,s,a)}});var ls=Oe({cosineDistance_:function(t,n,r,a,o){void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=Le(t,"labels","cosineDistance"),s=Le(n,"predictions","cosineDistance"),u=null;null!=a&&(u=Le(a,"weights","cosineDistance")),f(i.shape,s.shape,"Error in cosineDistance: ");var l=To(1),c=ga(l,ya(In(i,s),r,!0));return ss(c,u,o)}});var cs=Oe({hingeLoss_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=Le(t,"labels","hingeLoss"),i=Le(n,"predictions","hingeLoss"),s=null;null!=r&&(s=Le(r,"weights","hingeLoss")),f(o.shape,i.shape,"Error in hingeLoss: ");var u=To(1);o=ga(In(To(2),o),u);var l=xo(ga(u,In(o,i)));return ss(l,s,a)}});var fs=Oe({huberLoss_:function(t,n,r,a,o){void 0===a&&(a=1),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=Le(t,"labels","huberLoss"),s=Le(n,"predictions","huberLoss"),u=null;null!=r&&(u=Le(r,"weights","huberLoss")),f(i.shape,s.shape,"Error in huberLoss: ");var l=To(a),c=Nn(ga(s,i)),h=Pa(c,l),d=ga(c,h),p=Sn(In(To(.5),Oa(h)),In(l,d));return ss(p,u,o)}});var hs=Oe({logLoss_:function(t,n,r,a,o){void 0===a&&(a=1e-7),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=Le(t,"labels","logLoss"),s=Le(n,"predictions","logLoss"),u=null;null!=r&&(u=Le(r,"weights","logLoss")),f(i.shape,s.shape,"Error in logLoss: ");var l=To(1),c=To(a),h=da(In(i,ua(Sn(s,c)))),d=In(ga(l,i),ua(Sn(ga(l,s),c))),p=ga(h,d);return ss(p,u,o)}});var ds=Oe({meanSquaredError_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=Le(t,"labels","meanSquaredError"),i=Le(n,"predictions","meanSquaredError"),s=null;null!=r&&(s=Le(r,"weights","meanSquaredError")),f(o.shape,i.shape,"Error in meanSquaredError: ");var u=Yo(o,i);return ss(u,s,a)}});var ps=Oe({sigmoidCrossEntropy_:function(t,n,r,a,o){void 0===a&&(a=0),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=Le(t,"multiClassLabels","sigmoidCrossEntropy"),s=Le(n,"logits","sigmoidCrossEntropy"),u=null;if(null!=r&&(u=Le(r,"weights","sigmoidCrossEntropy")),f(i.shape,s.shape,"Error in sigmoidCrossEntropy: "),a>0){var l=To(a),c=To(1),h=To(.5);i=Sn(In(i,ga(c,l)),In(h,l))}var d=function(e,t){var n=Le(e,"labels","sigmoidCrossEntropyWithLogits"),r=Le(t,"logits","sigmoidCrossEntropyWithLogits");f(n.shape,r.shape,"Error in sigmoidCrossEntropyWithLogits: ");var a=xo(r),o=In(r,n),i=la(Gr(da(Nn(r))));return Sn(ga(a,o),i)}(i,s);return ss(d,u,o)}});var vs=Oe({softmaxCrossEntropy_:function(t,n,r,a,o){void 0===a&&(a=0),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=Le(t,"onehotLabels","softmaxCrossEntropy"),s=Le(n,"logits","softmaxCrossEntropy"),u=null;if(null!=r&&(u=Le(r,"weights","softmaxCrossEntropy")),f(i.shape,s.shape,"Error in softmaxCrossEntropy: "),a>0){var l=To(a),c=To(1),h=To(i.shape[1]);i=Sn(In(i,ga(c,l)),Mn(l,h))}var d=function(e,t,n){if(void 0===n&&(n=-1),-1===n&&(n=t.rank-1),n!==t.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+t.rank+" and dim was "+n);return fa((function(e,t,r){var a=Ea(t,[n],!0),o=ga(Et(t,"float32"),a);r([e,o]);var i=da(In(o,e));return{value:ya(i,[n]),gradFunc:function(e,t){var r=t[0],a=t[1],o=xa(e.shape,[n]);return[In($n(e,o),ga(Et(r,"float32"),Gr(a))),In($n(e,o),ga(Gr(a),Et(r,"float32")))]}}}))(e,t)}(i,s);return ss(d,u,o)}});var ms=Oe({sparseFillEmptyRows_:function(e,t,n,r){var a=Le(e,"indices","sparseFillEmptyRows"),o=Le(t,"values","sparseFillEmptyRows"),i=Le(n,"denseShape","sparseFillEmptyRows"),s=Le(r,"defaultValue","sparseFillEmptyRows",o.dtype);if(2!==a.rank)throw new Error("Indices should be Tensor2D but received shape\n        "+a.shape);if(1!==o.rank)throw new Error("Values should be Tensor1D but received shape "+o.shape);if(1!==i.rank)throw new Error("Dense shape should be Tensor1D but received shape "+i.shape);if(0!==s.rank)throw new Error("Default value should be a scalar but received shape "+s.shape);var u={indices:a,values:o,denseShape:i,defaultValue:s},l=De.runKernel("SparseFillEmptyRows",u);return{outputIndices:l[0],outputValues:l[1],emptyRowIndicator:l[2],reverseIndexMap:l[3]}}});var gs=Oe({sparseReshape_:function(e,t,n){var r=Le(e,"inputIndices","sparseReshape"),a=Le(t,"inputShape","sparseReshape"),o=Le(n,"newShape","sparseReshape");if(2!==r.rank)throw new Error("Input indices should be Tensor2D but received shape\n        "+r.shape);if(1!==a.rank)throw new Error("Input shape should be Tensor1D but received shape "+a.shape);if(1!==o.rank)throw new Error("New shape should be Tensor1D but received shape "+o.shape);var i={inputIndices:r,inputShape:a,newShape:o},s=De.runKernel("SparseReshape",i);return{outputIndices:s[0],outputShape:s[1]}}}),ys={fft:Uo,ifft:Go,rfft:jo,irfft:Vo},bs={hammingWindow:_i,hannWindow:Di,frame:Ti,stft:Ri},ws={flipLeftRight:Ci,resizeNearestNeighbor:Qi,resizeBilinear:$i,rotateWithOffset:Bi,cropAndResize:Fi,nonMaxSuppression:Li,nonMaxSuppressionAsync:ji,nonMaxSuppressionWithScore:Ji,nonMaxSuppressionWithScoreAsync:Yi,nonMaxSuppressionPadded:Zi,nonMaxSuppressionPaddedAsync:Xi,threshold:es,transform:ts},ks={bandPart:ns,gramSchmidt:rs,qr:is},xs={absoluteDifference:us,computeWeightedLoss:ss,cosineDistance:ls,hingeLoss:cs,huberLoss:fs,logLoss:hs,meanSquaredError:ds,sigmoidCrossEntropy:ps,softmaxCrossEntropy:vs},Es={sparseFillEmptyRows:ms,sparseReshape:gs},Ss=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.minimize=function(e,t,n){void 0===t&&(t=!1);var r=this.computeGradients(e,n),a=r.value,o=r.grads;if(null!=n){var i=n.map((function(e){return{name:e.name,tensor:o[e.name]}}));this.applyGradients(i)}else this.applyGradients(o);return xn(o),t?a:(a.dispose(),null)},Object.defineProperty(t.prototype,"iterations",{get:function(){return null==this.iterations_&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return ca(e,t)},t.prototype.dispose=function(){null!=this.iterations_&&xn(this.iterations_)},t.prototype.saveIterations=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){return null==this.iterations_&&(this.iterations_=0),[2,{name:"iter",tensor:To(this.iterations_,"int32")}]}))}))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){throw new Error("getWeights() is not implemented for this optimizer yet.")}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(e){throw new Error("setWeights() is not implemented for this optimizer class "+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return r(this,void 0,void 0,(function(){var t;return a(this,(function(n){switch(n.label){case 0:return t=this,[4,e[0].tensor.data()];case 1:return t.iterations_=n.sent()[0],[2,e.slice(1)]}}))}))},t}(dn);Object.defineProperty(Ss,Symbol.hasInstance,{value:function(e){return null!=e.minimize&&null!=e.computeGradients&&null!=e.applyGradients}});var As=function(e){function t(t,n,r){void 0===r&&(r=null);var a=e.call(this)||this;return a.learningRate=t,a.rho=n,a.epsilon=r,a.accumulatedGrads=[],a.accumulatedUpdates=[],null==r&&(a.epsilon=De.backend.epsilon()),a}return n(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=De.registeredVariables[n];null==t.accumulatedGrads[r]&&(t.accumulatedGrads[r]={originalName:n+"/accum_grad",variable:kn((function(){return zr(a).variable(!1)}))}),null==t.accumulatedUpdates[r]&&(t.accumulatedUpdates[r]={originalName:n+"/accum_var",variable:kn((function(){return zr(a).variable(!1)}))});var o=Array.isArray(e)?e[r].tensor:e[n];if(null!=o){var i=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;kn((function(){var e=Sn(In(i,t.rho),In(Oa(o),1-t.rho)),n=In(Mn(Jo(Sn(s,t.epsilon)),Jo(Sn(i,t.epsilon))),o),r=Sn(In(s,t.rho),In(Oa(n),1-t.rho));i.assign(e),s.assign(r);var u=Sn(In(n,-t.learningRate),a);a.assign(u)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedUpdates&&(xn(this.accumulatedGrads.map((function(e){return e.variable}))),xn(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){var t;return a(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=e.length/2,!1,this.accumulatedGrads=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.rho,t.epsilon)},t.className="Adadelta",t}(Ss);vn(As);var Ms=function(e){function t(t,n){void 0===n&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return n(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=De.registeredVariables[n];if(null==t.accumulatedGrads[r]){t.accumulatedGrads[r]={originalName:n+"/accumulator",variable:kn((function(){return Yr(a.shape,t.initialAccumulatorValue).variable(!1)}))}}var o=Array.isArray(e)?e[r].tensor:e[n];if(null!=o){var i=t.accumulatedGrads[r].variable;kn((function(){var e=Sn(i,Oa(o));i.assign(e);var n=Sn(In(Mn(o,Jo(Sn(e,De.backend.epsilon()))),-t.learningRate),a);a.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedGrads&&xn(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),!1,this.accumulatedGrads=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,t){return new e(t.learningRate,t.initialAccumulatorValue)},t.className="Adagrad",t}(Ss);vn(Ms);var Is=function(e){function t(t,n,r,a){void 0===a&&(a=null);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=a,o.accumulatedFirstMoment=[],o.accumulatedSecondMoment=[],kn((function(){o.accBeta1=To(n).variable(),o.accBeta2=To(r).variable()})),null==a&&(o.epsilon=De.backend.epsilon()),o}return n(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);kn((function(){var r=ga(1,t.accBeta1),a=ga(1,t.accBeta2);n.forEach((function(n,o){var i=De.registeredVariables[n];null==t.accumulatedFirstMoment[o]&&(t.accumulatedFirstMoment[o]={originalName:n+"/m",variable:kn((function(){return zr(i).variable(!1)}))}),null==t.accumulatedSecondMoment[o]&&(t.accumulatedSecondMoment[o]={originalName:n+"/v",variable:kn((function(){return zr(i).variable(!1)}))});var s=Array.isArray(e)?e[o].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[o].variable,l=t.accumulatedSecondMoment[o].variable,c=Sn(In(u,t.beta1),In(s,1-t.beta1)),f=Sn(In(l,t.beta2),In(Oa(s),1-t.beta2)),h=Mn(c,r),d=Mn(f,a);u.assign(c),l.assign(f);var p=Sn(In(Mn(h,Sn(Jo(d),t.epsilon)),-t.learningRate),i);i.assign(p)}})),t.accBeta1.assign(In(t.accBeta1,t.beta1)),t.accBeta2.assign(In(t.accBeta2,t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),null!=this.accumulatedFirstMoment&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedSecondMoment&&xn(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){var t,n=this;return a(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),kn((function(){n.accBeta1.assign(Qa(n.beta1,n.iterations_+1)),n.accBeta2.assign(Qa(n.beta2,n.iterations_+1))})),t=e.length/2,!1,this.accumulatedFirstMoment=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)},t.className="Adam",t}(Ss);vn(Is);var Ns=function(e){function t(t,n,r,a,o){void 0===a&&(a=null),void 0===o&&(o=0);var i=e.call(this)||this;return i.learningRate=t,i.beta1=n,i.beta2=r,i.epsilon=a,i.decay=o,i.accumulatedFirstMoment=[],i.accumulatedWeightedInfNorm=[],kn((function(){i.iteration=To(0).variable(),i.accBeta1=To(n).variable()})),null==a&&(i.epsilon=De.backend.epsilon()),i}return n(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);kn((function(){var r=ga(1,t.accBeta1),a=Mn(-t.learningRate,Sn(In(t.iteration,t.decay),1));n.forEach((function(n,o){var i=De.registeredVariables[n];null==t.accumulatedFirstMoment[o]&&(t.accumulatedFirstMoment[o]={originalName:n+"/m",variable:zr(i).variable(!1)}),null==t.accumulatedWeightedInfNorm[o]&&(t.accumulatedWeightedInfNorm[o]={originalName:n+"/v",variable:zr(i).variable(!1)});var s=Array.isArray(e)?e[o].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[o].variable,l=t.accumulatedWeightedInfNorm[o].variable,c=Sn(In(u,t.beta1),In(s,1-t.beta1)),f=In(l,t.beta2),h=Nn(s),d=Ta(f,h);u.assign(c),l.assign(d);var p=Sn(In(Mn(a,r),Mn(c,Sn(d,t.epsilon))),i);i.assign(p)}})),t.iteration.assign(Sn(t.iteration,1)),t.accBeta1.assign(In(t.accBeta1,t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),null!=this.accumulatedFirstMoment&&xn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedWeightedInfNorm&&xn(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){throw new Error("getWeights() is not implemented for Adamax yet.")}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(e){throw new Error("setWeights() is not implemented for Adamax yet.")}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)},t.className="Adamax",t}(Ss);vn(Ns);var _s=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return n(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=Array.isArray(e)?e[r].tensor:e[n];if(null!=a){var o=De.registeredVariables[n];kn((function(){var e=Sn(In(t.c,a),o);o.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,null!=this.c&&this.c.dispose(),this.c=En(To(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:if(0!==(e=t.sent()).length)throw new Error("SGD optimizer does not have settable weights.");return[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,t){return new e(t.learningRate)},t.className="SGD",t}(Ss);vn(_s);var Ds=function(e){function t(t,n,r){void 0===r&&(r=!1);var a=e.call(this,t)||this;return a.learningRate=t,a.momentum=n,a.useNesterov=r,a.accumulations=[],a.m=To(a.momentum),a}return n(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=De.registeredVariables[n];if(null==t.accumulations[r]){t.accumulations[r]={originalName:n+"/momentum",variable:kn((function(){return zr(a).variable(!1)}))}}var o=t.accumulations[r].variable,i=Array.isArray(e)?e[r].tensor:e[n];null!=i&&kn((function(){var e,n=Sn(In(t.m,o),i);e=t.useNesterov?Sn(In(t.c,Sn(i,In(n,t.m))),a):Sn(In(t.c,n),a),o.assign(n),a.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),null!=this.accumulations&&xn(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),!1,this.accumulations=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)},t.className="Momentum",t}(_s);vn(Ds);var Ts=function(e){function t(t,n,r,a,o){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===a&&(a=null),void 0===o&&(o=!1);var i=e.call(this)||this;if(i.learningRate=t,i.decay=n,i.momentum=r,i.epsilon=a,i.accumulatedMeanSquares=[],i.accumulatedMoments=[],i.accumulatedMeanGrads=[],i.centered=o,null==a&&(i.epsilon=De.backend.epsilon()),null==t)throw new Error("learningRate for RMSPropOptimizer must be defined.");return i}return n(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=De.registeredVariables[n];null==t.accumulatedMeanSquares[r]&&(t.accumulatedMeanSquares[r]={originalName:n+"/rms",variable:kn((function(){return zr(a).variable(!1)}))}),null==t.accumulatedMoments[r]&&(t.accumulatedMoments[r]={originalName:n+"/momentum",variable:kn((function(){return zr(a).variable(!1)}))}),null==t.accumulatedMeanGrads[r]&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+"/mg",variable:kn((function(){return zr(a).variable(!1)}))});var o=Array.isArray(e)?e[r].tensor:e[n];if(null!=o){var i=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;kn((function(){var e=Sn(In(i,t.decay),In(Oa(o),1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,u=Sn(In(n,t.decay),In(o,1-t.decay)),l=Mn(In(o,t.learningRate),Jo(ga(e,Sn(Oa(u),t.epsilon)))),c=Sn(In(s,t.momentum),l);i.assign(e),n.assign(u),s.assign(c);var f=ga(a,c);a.assign(f)}else{var h=Sn(In(i,t.decay),In(Oa(o),1-t.decay));c=Sn(In(s,t.momentum),Mn(In(o,t.learningRate),Jo(Sn(h,t.epsilon))));i.assign(h),s.assign(c);f=ga(a,c);a.assign(f)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedMeanSquares&&xn(this.accumulatedMeanSquares.map((function(e){return e.variable}))),null!=this.accumulatedMeanGrads&&this.centered&&xn(this.accumulatedMeanGrads.map((function(e){return e.variable}))),null!=this.accumulatedMoments&&xn(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return r(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return r(this,void 0,void 0,(function(){var t;return a(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=this.centered?e.length/3:e.length/2,!1,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}}))),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)},t.className="RMSProp",t}(Ss);vn(Ts);var Rs=function(){function e(){}return e.sgd=function(e){return new _s(e)},e.momentum=function(e,t,n){return void 0===n&&(n=!1),new Ds(e,t,n)},e.rmsprop=function(e,t,n,r,a){return void 0===t&&(t=.9),void 0===n&&(n=0),void 0===r&&(r=null),void 0===a&&(a=!1),new Ts(e,t,n,r,a)},e.adam=function(e,t,n,r){return void 0===e&&(e=.001),void 0===t&&(t=.9),void 0===n&&(n=.999),void 0===r&&(r=null),new Is(e,t,n,r)},e.adadelta=function(e,t,n){return void 0===e&&(e=.001),void 0===t&&(t=.95),void 0===n&&(n=null),new As(e,t,n)},e.adamax=function(e,t,n,r,a){return void 0===e&&(e=.002),void 0===t&&(t=.9),void 0===n&&(n=.999),void 0===r&&(r=null),void 0===a&&(a=0),new Ns(e,t,n,r,a)},e.adagrad=function(e,t){return void 0===t&&(t=.1),new Ms(e,t)},e}(),Fs={sgd:Rs.sgd,momentum:Rs.momentum,adadelta:Rs.adadelta,adagrad:Rs.adagrad,rmsprop:Rs.rmsprop,adamax:Rs.adamax,adam:Rs.adam},Cs="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:"undefined"!=typeof setImmediate?setImmediate:function(e){return e()};var Bs=/->/g;function Ps(e,t){for(var n=[],r=0;r<e.length;++r)0!==e[r].length&&-1===e[r].indexOf(t)&&-1!==t||n.push(r);return n}var Ls={__proto__:null,slice_util:hn,segment_util:{__proto__:null,segOpComputeOptimalWindowSize:function(e,t){var n,r=!1;for(e<=30?(n=e,r=!0):n=R(e,Math.floor(Math.sqrt(e)));!r;)n>t||n===e?r=!0:n=R(e,n+1);return n},computeOutShape:function(e,t,n){for(var r=[],a=e.length,o=0;o<a;o++)o!==t?r.push(e[o]):r.push(n);return r},collectGatherOpShapeInfo:function(e,t,n,r){var a=t.shape.length,o=e.shape.length;if(0!==r&&(r<-a||r>a))throw new Error("Expect batchDims in the range of [-"+a+", "+a+"], but got "+r);if(r<0&&(r+=a),r>o)throw new Error("batchDims ("+r+") must be less than rank(x) (\n    "+o+").");if(n<r)throw new Error("batchDims ("+r+") must be less than or equal to axis ("+n+").");for(var i=0;i<r;++i)if(e.shape[i]!==t.shape[i])throw new Error("x.shape["+i+"]: "+e.shape[i]+" should be equal to indices.shape["+i+"]: "+t.shape[i]+".");var s=e.shape[n],u=[],l=1,c=1,f=1;for(i=0;i<r;++i)u.push(e.shape[i]),l*=e.shape[i];for(i=r;i<n;i++)u.push(e.shape[i]),c*=e.shape[i];for(i=r;i<a;i++)u.push(t.shape[i]);for(i=n+1;i<o;i++)u.push(e.shape[i]),f*=e.shape[i];return{batchSize:l,sliceSize:f,outerSize:c,dimSize:s,outputShape:u}}},fromUint8ToStringArray:function(e){try{return e.map((function(e){return ne(e)}))}catch(e){throw new Error("Failed to decode encoded string bytes into utf-8, error: "+e)}},fromStringArrayToUint8:function(e){return e.map((function(e){return te(e)}))},upcastType:ke,axesAreInnerMostDims:wa,combineLocations:ka,computeOutAndReduceShapes:function(e,t){for(var n=[],r=e.length,a=0;a<r;a++)-1===t.indexOf(a)&&n.push(e[a]);return[n,t.map((function(t){return e[t]}))]},expandShapeToKeepDim:xa,assertAxesAreInnerMostDims:function(e,t,n){c(wa(t,n),(function(){return e+" supports only inner-most axes for now. Got axes "+t+" and rank-"+n+" input."}))},getAxesPermutation:function(e,t){if(wa(e,t))return null;for(var n=[],r=0;r<t;++r)-1===e.indexOf(r)&&n.push(r);return e.forEach((function(e){return n.push(e)})),n},getUndoAxesPermutation:function(e){return e.map((function(e,t){return[t,e]})).sort((function(e,t){return e[1]-t[1]})).map((function(e){return e[0]}))},getInnerMostAxes:function(e,t){for(var n=[],r=t-e;r<t;++r)n.push(r);return n},getBroadcastDims:function(e,t){for(var n=e.length,r=[],a=0;a<n;a++){var o=n-1-a,i=e[o]||1;(t[t.length-1-a]||1)>1&&1===i&&r.unshift(o)}return r},getReductionAxes:Cr,assertAndGetBroadcastShape:Br,assertParamsConsistent:function(e,t){var n=e[0].length;e.forEach((function(e,t){c(e.length===n,(function(){return"Error in concat"+n+"D: rank of tensors["+t+"] must be the same as the rank of the rest ("+n+")"}))})),c(t>=0&&t<n,(function(){return"Error in concat"+n+"D: axis must be between 0 and "+(n-1)+"."}));var r=e[0];e.forEach((function(e,a){for(var o=0;o<n;o++)c(o===t||e[o]===r[o],(function(){return"Error in concat"+n+"D: Shape of tensors["+a+"] ("+e+") does not match the shape of the rest ("+r+") along the non-concatenated axis "+a+"."}))}))},computeOutShape:function(e,t){for(var n=e[0].slice(),r=1;r<e.length;r++)n[t]+=e[r][t];return n},computeDilation2DInfo:function(e,t,n,r,a,o){void 0===a&&(a="NHWC");var i=e[3];return qn(e,t.concat([i]),n,o,r,null,null,Xn(a))},computePool2DInfo:Wn,computePool3DInfo:function(e,t,n,r,a,o,i){void 0===i&&(i="NDHWC");var s,u,l=Hn(t),c=l[0],f=l[1],h=l[2];if("NDHWC"===i)u="channelsLast",s=[c,f,h,e[4],e[4]];else{if("NCDHW"!==i)throw new Error("Unknown dataFormat "+i);u="channelsFirst",s=[c,f,h,e[1],e[1]]}return Un(e,s,n,r,a,!1,u,o)},computeConv2DInfo:qn,computeConv3DInfo:Un,computeDefaultPad:Gn,tupleValuesAreOne:Yn,eitherStridesOrDilationsAreOne:Zn,convertConv2DDataFormat:Xn,getFusedDyActivation:ki,getFusedBiasGradient:xi,applyActivation:Ei,shouldFuse:Si,PARALLELIZE_THRESHOLD:30,computeOptimalWindowSize:function(e){return e<=30?e:R(e,Math.floor(Math.sqrt(e)))},getImageCenter:function(e,t,n){return[n*("number"==typeof e?e:e[0]),t*("number"==typeof e?e:e[1])]},getReshaped:function(e,t,n,r){void 0===r&&(r=!0);var a=[];if(r)(a=a.concat(t.slice(0))).push(e[0]/n),a=a.concat(e.slice(1));else{a=a.concat(e[0]);for(var o=t.length,i=0;i<o;++i)a=a.concat([e[i+1]/t[i],t[i]]);a=a.concat(e.slice(o+1))}return a},getPermuted:function(e,t,n){void 0===n&&(n=!0);var r=[];if(n){r.push(t);for(var a=t+1;a<e;++a)a<=2*t?(r.push(a),r.push(a-(t+1))):r.push(a)}else{var o=[],i=[];for(a=1;a<e;++a)a>=2*t+1||a%2==1?i.push(a):o.push(a);r.push.apply(r,o),r.push(0),r.push.apply(r,i)}return r},getReshapedPermuted:function(e,t,n,r){void 0===r&&(r=!0);var a=[];r?a.push(e[0]/n):a.push(e[0]*n);for(var o=1;o<e.length;++o)o<=t.length?r?a.push(t[o-1]*e[o]):a.push(e[o]/t[o-1]):a.push(e[o]);return a},getSliceBeginCoords:function(e,t){for(var n=[0],r=0;r<t;++r)n.push(e[r][0]);return n},getSliceSize:function(e,t,n){for(var r=e.slice(0,1),a=0;a<n;++a)r.push(e[a+1]-t[a][0]-t[a][1]);return r},prepareAndValidate:Jt,validateUpdateShape:Zt,validateInput:Xt,calculateShapes:$t,SELU_SCALEALPHA:1.7580993408473768,SELU_SCALE:1.0507009873554805,ERF_P:.3275911,ERF_A1:.254829592,ERF_A2:-.284496736,ERF_A3:1.421413741,ERF_A4:-1.453152027,ERF_A5:1.061405429,warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];U().getBool("IS_TEST")||console.warn.apply(console,e)},log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];U().getBool("IS_TEST")||console.log.apply(console,e)},mergeRealAndImagArrays:function(e,t){if(e.length!==t.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+e.length+", imag: "+t.length+".");for(var n=new Float32Array(2*e.length),r=0;r<n.length;r+=2)n[r]=e[r/2],n[r+1]=t[r/2];return n},splitRealAndImagArrays:function(e){for(var t=new Float32Array(e.length/2),n=new Float32Array(e.length/2),r=0;r<e.length;r+=2)t[r/2]=e[r],n[r/2]=e[r+1];return{real:t,imag:n}},complexWithEvenIndex:function(e){for(var t=Math.ceil(e.length/4),n=new Float32Array(t),r=new Float32Array(t),a=0;a<e.length;a+=4)n[Math.floor(a/4)]=e[a],r[Math.floor(a/4)]=e[a+1];return{real:n,imag:r}},complexWithOddIndex:function(e){for(var t=Math.floor(e.length/4),n=new Float32Array(t),r=new Float32Array(t),a=2;a<e.length;a+=4)n[Math.floor(a/4)]=e[a],r[Math.floor(a/4)]=e[a+1];return{real:n,imag:r}},getComplexWithIndex:function(e,t){return{real:e[2*t],imag:e[2*t+1]}},assignToTypedArray:function(e,t,n,r){e[2*r]=t,e[2*r+1]=n},exponents:function(e,t){for(var n=new Float32Array(e/2),r=new Float32Array(e/2),a=0;a<Math.ceil(e/2);a++){var o=(t?2:-2)*Math.PI*(a/e);n[a]=Math.cos(o),r[a]=Math.sin(o)}return{real:n,imag:r}},exponent:function(e,t,n){var r=(n?2:-2)*Math.PI*(e/t);return{real:Math.cos(r),imag:Math.sin(r)}},decodeEinsumEquation:function(e,t){var n=((e=e.replace(/\s/g,"")).length-e.replace(Bs,"").length)/"->".length;if(n<1)throw new Error("Equations without an arrow are not supported.");if(n>1)throw new Error('Equation must contain exactly one arrow ("->").');var r=e.split("->"),a=r[0],o=r[1];c(-1===a.indexOf("..."),(function(){return'The ellipsis notation ("...") is not supported yet.'}));var i=a.split(","),s=i.length;if(t!==s)throw new Error("Expected "+s+" input tensors, received "+t);if(s>2)throw new Error("Support for more than 2 input tensors is not implemented yet.");for(var u=[],l=function(e){var t=o[e];if(!i.some((function(e){return-1!==e.indexOf(t)})))throw new Error("Output subscripts contain the label "+t+" not present in the input subscripts.");-1===u.indexOf(t)&&u.push(t)},f=0;f<o.length;++f)l(f);for(f=0;f<a.length;++f){var h=a[f];-1===u.indexOf(h)&&","!==h&&u.push(h)}var d=new Array(i.length);for(f=0;f<s;++f){if(new Set(i[f].split("")).size!==i[f].length)throw new Error("Found duplicate axes in input component "+i[f]+". Support for duplicate axes in input is not implemented yet.");d[f]=[];for(var p=0;p<i[f].length;++p)d[f].push(u.indexOf(i[f][p]))}var v=u.length,m=[];for(f=o.length;f<v;++f)m.push(f);return{allDims:u,summedDims:m,idDims:d}},getEinsumPermutation:function(e,t){var n=new Array(e);n.fill(-1);for(var r=0;r<t.length;++r)n[t[r]]=r;var a=[];for(r=0;r<e;++r)-1===n[r]&&a.push(r);return{permutationIndices:n=n.filter((function(e){return-1!==e})),expandDims:a}},checkEinsumDimSizes:function(e,t,n){for(var r=new Array(e),a=function(e){for(var a=n[e].shape,o=function(n){void 0===r[t[e][n]]?r[t[e][n]]=a[n]:c(r[t[e][n]]===a[n],(function(){return"Expected dimension "+r[t[e][n]]+" at axis "+n+" of input shaped "+JSON.stringify(a)+", but got dimension "+a[n]}))},i=0;i<t[e].length;++i)o(i)},o=0;o<n.length;++o)a(o)},getEinsumComputePath:function(e,t){var n,r=e,a=[];0===e.length&&r.push(-1),n=e.length+1;for(var o=0;o<n;++o)a.push([]);var i=[];for(o=0;o<r.length;++o)for(var s=0,u=Ps(t,r[o]);s<u.length;s++){var l=u[s];-1===i.indexOf(l)&&(a[o].push(l),i.push(l))}return{path:r,steps:a}},isIdentityPermutation:function(e){return e.every((function(e,t){return e===t}))},prepareSplitSize:function(e,t,n){void 0===n&&(n=0);var r=[];if("number"==typeof t)c(e.shape[n]%t==0,(function(){return"Number of splits must evenly divide the axis."})),r=new Array(t).fill(e.shape[n]/t);else{c(t.reduce((function(e,t){return-1===t&&(e+=1),e}),0)<=1,(function(){return"There should be only one negative value in split array."}));var a=t.indexOf(-1);if(-1!==a){var o=t.reduce((function(e,t){return t>0?e+t:e}));t[a]=e.shape[n]-o}c(e.shape[n]===t.reduce((function(e,t){return e+t})),(function(){return"The sum of sizes must match the size of the axis dimension."})),r=t}return r}},zs={__proto__:null,nonMaxSuppressionV3Impl:Ki,nonMaxSuppressionV4Impl:Wi,nonMaxSuppressionV5Impl:qi,whereImpl:ui};e.Abs="Abs",e.Acos="Acos",e.Acosh="Acosh",e.AdadeltaOptimizer=As,e.AdagradOptimizer=Ms,e.AdamOptimizer=Is,e.AdamaxOptimizer=Ns,e.Add="Add",e.AddN="AddN",e.All="All",e.Any="Any",e.ArgMax="ArgMax",e.ArgMin="ArgMin",e.Asin="Asin",e.Asinh="Asinh",e.Atan="Atan",e.Atan2="Atan2",e.Atanh="Atanh",e.AvgPool="AvgPool",e.AvgPool3D="AvgPool3D",e.AvgPool3DGrad="AvgPool3DGrad",e.AvgPoolGrad="AvgPoolGrad",e.BatchMatMul="BatchMatMul",e.BatchToSpaceND="BatchToSpaceND",e.Bincount="Bincount",e.BroadcastTo="BroadcastTo",e.Cast="Cast",e.Ceil="Ceil",e.ClipByValue="ClipByValue",e.Complex="Complex",e.ComplexAbs="ComplexAbs",e.Concat="Concat",e.Conv2D="Conv2D",e.Conv2DBackpropFilter="Conv2DBackpropFilter",e.Conv2DBackpropInput="Conv2DBackpropInput",e.Conv3D="Conv3D",e.Conv3DBackpropFilterV2="Conv3DBackpropFilterV2",e.Conv3DBackpropInputV2="Conv3DBackpropInputV2",e.Cos="Cos",e.Cosh="Cosh",e.CropAndResize="CropAndResize",e.Cumsum="Cumsum",e.DataStorage=o,e.DenseBincount="DenseBincount",e.DepthToSpace="DepthToSpace",e.DepthwiseConv2dNative="DepthwiseConv2dNative",e.DepthwiseConv2dNativeBackpropFilter="DepthwiseConv2dNativeBackpropFilter",e.DepthwiseConv2dNativeBackpropInput="DepthwiseConv2dNativeBackpropInput",e.Diag="Diag",e.Dilation2D="Dilation2D",e.Dilation2DBackpropFilter="Dilation2DBackpropFilter",e.Dilation2DBackpropInput="Dilation2DBackpropInput",e.Einsum="Einsum",e.Elu="Elu",e.EluGrad="EluGrad",e.Environment=K,e.Equal="Equal",e.Erf="Erf",e.Exp="Exp",e.ExpandDims="ExpandDims",e.Expm1="Expm1",e.FFT="FFT",e.Fill="Fill",e.FlipLeftRight="FlipLeftRight",e.Floor="Floor",e.FloorDiv="FloorDiv",e.FromPixels="FromPixels",e.FusedBatchNorm="FusedBatchNorm",e.FusedConv2D="FusedConv2D",e.FusedDepthwiseConv2D="FusedDepthwiseConv2D",e.GatherNd="GatherNd",e.GatherV2="GatherV2",e.Greater="Greater",e.GreaterEqual="GreaterEqual",e.IFFT="IFFT",e.Identity="Identity",e.Imag="Imag",e.IsFinite="IsFinite",e.IsInf="IsInf",e.IsNan="IsNan",e.KernelBackend=i,e.LRN="LRN",e.LRNGrad="LRNGrad",e.LeakyRelu="LeakyRelu",e.Less="Less",e.LessEqual="LessEqual",e.LinSpace="LinSpace",e.Log="Log",e.Log1p="Log1p",e.LogSoftmax="LogSoftmax",e.LogicalAnd="LogicalAnd",e.LogicalNot="LogicalNot",e.LogicalOr="LogicalOr",e.Max="Max",e.MaxPool="MaxPool",e.MaxPool3D="MaxPool3D",e.MaxPool3DGrad="MaxPool3DGrad",e.MaxPoolGrad="MaxPoolGrad",e.MaxPoolWithArgmax="MaxPoolWithArgmax",e.Maximum="Maximum",e.Mean="Mean",e.Min="Min",e.Minimum="Minimum",e.MirrorPad="MirrorPad",e.Mod="Mod",e.MomentumOptimizer=Ds,e.Multinomial="Multinomial",e.Multiply="Multiply",e.Neg="Neg",e.NonMaxSuppressionV3="NonMaxSuppressionV3",e.NonMaxSuppressionV4="NonMaxSuppressionV4",e.NonMaxSuppressionV5="NonMaxSuppressionV5",e.NotEqual="NotEqual",e.OP_SCOPE_SUFFIX="__op",e.OneHot="OneHot",e.OnesLike="OnesLike",e.Optimizer=Ss,e.Pack="Pack",e.PadV2="PadV2",e.Pool="Pool",e.Pow="Pow",e.Prelu="Prelu",e.Prod="Prod",e.RMSPropOptimizer=Ts,e.Range="Range",e.Real="Real",e.RealDiv="RealDiv",e.Reciprocal="Reciprocal",e.Relu="Relu",e.Relu6="Relu6",e.Reshape="Reshape",e.ResizeBilinear="ResizeBilinear",e.ResizeBilinearGrad="ResizeBilinearGrad",e.ResizeNearestNeighbor="ResizeNearestNeighbor",e.ResizeNearestNeighborGrad="ResizeNearestNeighborGrad",e.Reverse="Reverse",e.RotateWithOffset="RotateWithOffset",e.Round="Round",e.Rsqrt="Rsqrt",e.SGDOptimizer=_s,e.ScatterNd="ScatterNd",e.Select="Select",e.Selu="Selu",e.Sigmoid="Sigmoid",e.Sign="Sign",e.Sin="Sin",e.Sinh="Sinh",e.Slice="Slice",e.Softmax="Softmax",e.Softplus="Softplus",e.SpaceToBatchND="SpaceToBatchND",e.SparseFillEmptyRows="SparseFillEmptyRows",e.SparseReshape="SparseReshape",e.SparseToDense="SparseToDense",e.SplitV="SplitV",e.Sqrt="Sqrt",e.Square="Square",e.SquaredDifference="SquaredDifference",e.Step="Step",e.StridedSlice="StridedSlice",e.Sub="Sub",e.Sum="Sum",e.Tan="Tan",e.Tanh="Tanh",e.Tensor=de,e.TensorBuffer=ce,e.Tile="Tile",e.TopK="TopK",e.Transform="Transform",e.Transpose="Transpose",e.Unique="Unique",e.Unpack="Unpack",e.UnsortedSegmentSum="UnsortedSegmentSum",e.Variable=be,e.ZerosLike="ZerosLike",e._FusedMatMul="_FusedMatMul",e.abs=Nn,e.acos=_n,e.acosh=Dn,e.add=Sn,e.addN=Tn,e.all=Rn,e.any=Fn,e.argMax=Cn,e.argMin=Bn,e.asin=Pn,e.asinh=Ln,e.atan=zn,e.atan2=On,e.atanh=Kn,e.avgPool=Qn,e.avgPool3d=er,e.backend=function(){return De.backend},e.backend_util=Ls,e.basicLSTMCell=or,e.batchNorm=sr,e.batchNorm2d=ur,e.batchNorm3d=lr,e.batchNorm4d=cr,e.batchToSpaceND=ir,e.bincount=fr,e.booleanMaskAsync=ci,e.broadcastTo=hr,e.browser=jt,e.buffer=xt,e.cast=Et,e.ceil=dr,e.clipByValue=pr,e.clone=St,e.complex=Ke,e.concat=tr,e.concat1d=vr,e.concat2d=mr,e.concat3d=gr,e.concat4d=yr,e.conv1d=wr,e.conv2d=br,e.conv2dTranspose=xr,e.conv3d=Er,e.conv3dTranspose=Ar,e.copyRegisteredKernels=function(e,t){Z(e).forEach((function(e){X(Object.assign({},e,{backendName:t}))}))},e.cos=Mr,e.cosh=Ir,e.cosineWindow=yi,e.cumsum=Nr,e.customGrad=fa,e.denseBincount=_r,e.deprecationWarn=function(e){U().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")},e.depthToSpace=Dr,e.depthwiseConv2d=Tr,e.device_util=Fe,e.diag=Rr,e.dilation2d=Fr,e.disableDeprecationWarnings=function(){U().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")},e.dispose=xn,e.disposeVariables=function(){De.disposeVariables()},e.div=Mn,e.divNoNan=Or,e.dot=Kr,e.dropout=mi,e.einsum=Wr,e.elu=qr,e.enableDebugMode=function(){U().set("DEBUG",!0)},e.enableProdMode=function(){U().set("PROD",!0)},e.enclosingPowerOfTwo=gi,e.engine=function(){return De},e.env=U,e.equal=Pr,e.erf=Ur,e.exp=Gr,e.expandDims=Vr,e.expm1=Hr,e.eye=Jr,e.fft=Uo,e.fill=Yr,e.findBackend=function(e){return De.findBackend(e)},e.findBackendFactory=function(e){return De.findBackendFactory(e)},e.floor=Zr,e.floorDiv=An,e.fused=Ni,e.gather=Xr,e.gatherND=vi,e.gather_util=Yt,e.getBackend=function(){return De.backendName},e.getGradient=Y,e.getKernel=J,e.getKernelsForBackend=Z,e.grad=function(e){return c(T(e),(function(){return"The f passed in grad(f) must be a function"})),function(t,n){var r=Le(t,"x","tf.grad","string_or_numeric"),a=null!=n?Le(n,"dy","tf.grad"):null;return De.tidy((function(){var t=De.gradients((function(){return e(r)}),[r],a),n=t.value,o=t.grads;return null!=a&&f(n.shape,a.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),ha(o),o[0]}))}},e.grads=function(e){return c(T(e),(function(){return"The f passed in grads(f) must be a function"})),function(t,n){c(Array.isArray(t),(function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"}));var r=ze(t,"args","tf.grads","string_or_numeric"),a=null!=n?Le(n,"dy","tf.grads"):null;return De.tidy((function(){var t=De.gradients((function(){return e.apply(void 0,r)}),r,a),n=t.value,o=t.grads;return null!=a&&f(n.shape,a.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ha(o),o}))}},e.greater=$r,e.greaterEqual=Qr,e.ifft=Go,e.imag=ea,e.image=ws,e.inTopKAsync=bi,e.io=zt,e.irfft=Vo,e.isFinite=ta,e.isInf=na,e.isNaN=ra,e.keep=En,e.kernel_impls=zs,e.leakyRelu=aa,e.less=oa,e.lessEqual=ia,e.linalg=ks,e.linspace=function(e,t,n){if(n<=0)throw new Error("The number of values should be positive.");var r={start:e,stop:t,num:n};return De.runKernel("LinSpace",{},r)},e.localResponseNormalization=sa,e.log=ua,e.log1p=la,e.logSigmoid=va,e.logSoftmax=ba,e.logSumExp=Ea,e.logicalAnd=Sa,e.logicalNot=Aa,e.logicalOr=Ma,e.logicalXor=Ia,e.losses=xs,e.matMul=Ot,e.math=Ut,e.max=ma,e.maxPool=Na,e.maxPool3d=_a,e.maxPoolWithArgmax=Da,e.maximum=Ta,e.mean=Ra,e.memory=function(){return De.memory()},e.meshgrid=function(e,t,n){var r=(void 0===n?{}:n).indexing,a=void 0===r?"xy":r;if("xy"!==a&&"ij"!==a)throw new TypeError(a+" is not a valid third argument to meshgrid");if(void 0===e)return[];var o=Le(e,"x","meshgrid",e instanceof de?e.dtype:"float32");if(void 0===t)return[o];var i=Le(t,"y","meshgrid",t instanceof de?t.dtype:"float32"),s=p(o.shape),u=p(i.shape);return"xy"===a?(o=$n(o,[1,-1]),i=$n(i,[-1,1]),[Ot(Ca([u,1],o.dtype),o),Ot(i,Ca([1,s],i.dtype))]):(o=$n(o,[-1,1]),i=$n(i,[1,-1]),[Ot(o,Ca([1,u],o.dtype)),Ot(Ca([s,1],i.dtype),i)])},e.min=Ba,e.minimum=Pa,e.mirrorPad=La,e.mod=za,e.moments=Ka,e.movingAverage=hi,e.mul=In,e.multiRNNCell=Wa,e.multinomial=qa,e.neg=da,e.nextFrame=function(){return new Promise((function(e){return Cs((function(){return e()}))}))},e.norm=fi,e.notEqual=Ua,e.oneHot=Kt,e.ones=Ca,e.onesLike=Ga,e.op=Oe,e.outerProduct=Va,e.pad=Ha,e.pad1d=ja,e.pad2d=Ja,e.pad3d=Ya,e.pad4d=Za,e.pool=$a,e.pow=Qa,e.prelu=eo,e.print=At,e.prod=to,e.profile=function(e){return De.profile(e)},e.rand=no,e.randomGamma=mo,e.randomNormal=go,e.randomUniform=yo,e.range=bo,e.ready=function(){return De.ready()},e.real=wo,e.reciprocal=ko,e.registerBackend=function(e,t,n){return void 0===n&&(n=1),De.registerBackend(e,t,n)},e.registerGradient=function(e){var t=e.kernelName;j.has(t)&&U().getBool("DEBUG")&&console.warn("Overriding the gradient for '"+t+"'"),j.set(t,e)},e.registerKernel=X,e.relu=xo,e.relu6=Eo,e.removeBackend=function(e){De.removeBackend(e)},e.reshape=$n,e.reverse=So,e.reverse1d=Ao,e.reverse2d=Mo,e.reverse3d=Io,e.reverse4d=No,e.rfft=jo,e.round=_o,e.rsqrt=Do,e.scalar=To,e.scatterND=di,e.scatter_util=Qt,e.selu=Ro,e.separableConv2d=Fo,e.serialization=mn,e.setBackend=function(e){return De.setBackend(e)},e.setPlatform=function(e,t){U().setPlatform(e,t)},e.setdiff1dAsync=Co,e.sigmoid=nr,e.sign=Bo,e.signal=bs,e.sin=Po,e.sinh=Lo,e.slice=rr,e.slice1d=zo,e.slice2d=Oo,e.slice3d=Ko,e.slice4d=Wo,e.slice_util=hn,e.softmax=qo,e.softplus=pa,e.spaceToBatchND=Xa,e.sparse=Es,e.sparseToDense=pi,e.spectral=ys,e.split=Ho,e.sqrt=Jo,e.square=Oa,e.squaredDifference=Yo,e.squeeze=Zo,e.stack=Xo,e.step=$o,e.stridedSlice=Qo,e.sub=ga,e.sum=ya,e.sumOutType=function(e){return ke(e,"int32")},e.tan=ei,e.tanh=ar,e.tensor=qe,e.tensor1d=ti,e.tensor2d=ni,e.tensor3d=Gt,e.tensor4d=function(e,t,n){if(h(e),null!=t&&4!==t.length)throw new Error("tensor4d() requires shape to have four numbers");var r=Be(e,n);if(4!==r.length&&1!==r.length)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(1===r.length&&null==t)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return We(e,t,r,n)},e.tensor5d=function(e,t,n){if(h(e),null!=t&&5!==t.length)throw new Error("tensor5d() requires shape to have five numbers");var r=Be(e,n);if(5!==r.length&&1!==r.length)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(1===r.length&&null==t)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return We(e,t,r,n)},e.tensor6d=function(e,t,n){if(h(e),null!=t&&6!==t.length)throw new Error("tensor6d() requires shape to have six numbers");var r=Be(e,n);if(6!==r.length&&1!==r.length)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(1===r.length&&null==t)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return We(e,t=t||r,r,n)},e.tensor_util=Ae,e.test_util=wn,e.tidy=kn,e.tile=jr,e.time=function(e){return De.time(e)},e.topk=ri,e.train=Fs,e.transpose=Wt,e.truncatedNormal=ai,e.unique=oi,e.unregisterGradient=function(e){if(!j.has(e))throw new Error("The gradient '"+e+"' for backend is not registered");j.delete(e)},e.unregisterKernel=function(e,t){var n=$(e,t);if(!H.has(n))throw new Error("The kernel '"+e+"' for backend '"+t+"' is not registered");H.delete(n)},e.unsortedSegmentSum=ii,e.unstack=si,e.upcastType=ke,e.util=re,e.valueAndGrad=function(e){return c(T(e),(function(){return"The f passed in valueAndGrad(f) must be a function"})),function(t,n){c(t instanceof de,(function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"})),c(null==n||n instanceof de,(function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"}));var r=De.gradients((function(){return e(t)}),[t],n),a=r.grads,o=r.value;return ha(a),{grad:a[0],value:o}}},e.valueAndGrads=function(e){return c(T(e),(function(){return"The f passed in valueAndGrads(f) must be a function"})),function(t,n){c(Array.isArray(t)&&t.every((function(e){return e instanceof de})),(function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"})),c(null==n||n instanceof de,(function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"}));var r=De.gradients((function(){return e.apply(void 0,t)}),t,n);return null!=n&&f(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ha(r.grads),r}},e.variable=function(e,t,n,r){return void 0===t&&(t=!0),De.makeVariable(e,t,n,r)},e.variableGrads=ca,e.version_core="3.6.0",e.where=Lr,e.whereAsync=li,e.zeros=Fa,e.zerosLike=zr,Object.defineProperty(e,"__esModule",{value:!0})}));
  //# sourceMappingURL=tf-core.min.js.map
  