{"size": 257515, "ext": "js", "max_stars_repo_path": "node_modules/@tensorflow/tfjs-core/dist/tf-core.min.js", "max_stars_repo_name": "devthagichu/tensorflow-color-classifier", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@tensorflow/tfjs-core/dist/tf-core.min.js", "max_issues_repo_name": "devthagichu/tensorflow-color-classifier", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/@tensorflow/tfjs-core/dist/tf-core.min.js", "max_forks_repo_name": "devthagichu/tensorflow-color-classifier", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 13553.4210526316, "max_line_length": 256771, "alphanum_fraction": 0.6815641807}
/**
 * @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,i){function o(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(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(o,s)}u((r=r.apply(e,t||[])).next())}))}function a(e,t){var n,r,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(a=2&i[0]?r.return:i[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,i[1])).done)return a;switch(r=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],r=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var i=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}(),o=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;t>0;)n=Math.random()*t|0,c(e,--t,n)}function l(e,t,n){return Math.max(e,Math.min(t,n))}function c(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function h(e,t){if(!e)throw new Error("string"==typeof t?t:t())}function f(e,t,n){void 0===n&&(n=""),h(g(e,t),(function(){return n+" Shapes "+e+" and "+t+" must match"}))}function d(e){h(null!=e,(function(){return"The input to the tensor constructor must be a non-null value."}))}function p(e,t,n){if(void 0===t&&(t=[]),void 0===n&&(n=!1),null==t&&(t=[]),Array.isArray(e)||A(e)&&!n)for(var r=0;r<e.length;++r)p(e[r],t,n);else t.push(e);return t}function v(e){if(0===e.length)return 1;for(var t=e[0],n=1;n<e.length;n++)t*=e[n];return t}function g(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 b(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function y(e,t){var n=t.length;return h((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})),h(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 w(e,t){for(var n=[],r=[],a=null!=t&&Array.isArray(t)&&0===t.length,i=null==t||a?null:y(t,e).sort(),o=0,s=0;s<e.length;++s){if(null!=i){if(i[o]===s&&1!==e[s])throw new Error("Can't squeeze axis "+s+" since its dim '"+e[s]+"' is not 1");(null==i[o]||i[o]>s)&&1===e[s]&&(n.push(e[s]),r.push(s)),i[o]<=s&&o++}1!==e[s]&&(n.push(e[s]),r.push(s))}return{newShape:n,keptDims:r}}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)throw new Error("Unknown data type "+e);n=new Uint8Array(t)}return n}function x(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 E(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 S(e){return"bool"===e||"complex64"===e||"float32"===e||"int32"===e||"string"===e}function A(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array}function _(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 N(e){if(null==e)return 0;var t=0;return e.forEach((function(e){return t+=e.length})),t}function M(e){return"string"==typeof e||e instanceof String}function I(e){return"boolean"==typeof e}function T(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":T(e)?"float32":M(e)?"string":I(e)?"bool":"float32"}function R(e){return!!(e&&e.constructor&&e.call&&e.apply)}function F(e,t){for(var n=t;n<e;++n)if(e%n==0)return n;return e}function C(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 B(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 i=new Array;if(1===n.length)for(var o=n[0]*(a?2:1),s=0;s<o;s++)i[s]=r[t+s];else{o=n[0];var u=n.slice(1),l=u.reduce((function(e,t){return e*t}))*(a?2:1);for(s=0;s<o;s++)i[s]=e(t+s*l,u,r,a)}return i}(0,e,t,n)}function P(e,t){for(var n=L(e,t),r=0;r<n.length;r++)n[r]=1;return n}function L(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 O(e){e.forEach((function(t){h(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 q,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 U(t,n[0],n[1]),n.join("=")})),t}function U(e,t,n){e[decodeURIComponent(t)]=decodeURIComponent(n||"")}function G(){return e.ENV}function V(){if(null==q){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}q=e}return q}function H(e,t){var n,r=(null==(n=V())._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 j=H("kernelRegistry",(function(){return new Map})),J=H("gradRegistry",(function(){return new Map}));function Z(e,t){var n=Q(e,t);return j.get(n)}function Y(e){return J.get(e)}function X(e){for(var t=j.entries(),n=[];;){var r=t.next(),a=r.done,i=r.value;if(a)break;var o=i[0],s=i[1];o.split("_")[0]===e&&n.push(s)}return n}function $(e){var t=e.kernelName,n=e.backendName,r=Q(t,n);j.has(r)&&console.warn("The kernel '"+t+"' for backend '"+n+"' is already registered"),j.set(r,e)}function Q(e,t){return t+"_"+e}var ee=ne,te=null;try{te=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function ne(e,t,n){this.low=0|e,this.high=0|t,this.unsigned=!!n}function re(e){return!0===(e&&e.__isLong__)}ne.prototype.__isLong__,Object.defineProperty(ne.prototype,"__isLong__",{value:!0}),ne.isLong=re;var ae={},ie={};function oe(e,t){var n,r,a;return t?(a=0<=(e>>>=0)&&e<256)&&(r=ie[e])?r:(n=ue(e,(0|e)<0?-1:0,!0),a&&(ie[e]=n),n):(a=-128<=(e|=0)&&e<128)&&(r=ae[e])?r:(n=ue(e,e<0?-1:0,!1),a&&(ae[e]=n),n)}function se(e,t){if(isNaN(e))return t?me:ge;if(t){if(e<0)return me;if(e>=de)return xe}else{if(e<=-pe)return Ee;if(e+1>=pe)return ke}return e<0?se(-e,t).neg():ue(e%fe|0,e/fe|0,t)}function ue(e,t,n){return new ne(e,t,n)}ne.fromInt=oe,ne.fromNumber=se,ne.fromBits=ue;var le=Math.pow;function ce(e,t,n){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return ge;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return ce(e.substring(1),t,n).neg();for(var a=se(le(n,8)),i=ge,o=0;o<e.length;o+=8){var s=Math.min(8,e.length-o),u=parseInt(e.substring(o,o+s),n);if(s<8){var l=se(le(n,s));i=i.mul(l).add(se(u))}else i=(i=i.mul(a)).add(se(u))}return i.unsigned=t,i}function he(e,t){return"number"==typeof e?se(e,t):"string"==typeof e?ce(e,t):ue(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}ne.fromString=ce,ne.fromValue=he;var fe=4294967296,de=fe*fe,pe=de/2,ve=oe(1<<24),ge=oe(0);ne.ZERO=ge;var me=oe(0,!0);ne.UZERO=me;var be=oe(1);ne.ONE=be;var ye=oe(1,!0);ne.UONE=ye;var we=oe(-1);ne.NEG_ONE=we;var ke=ue(-1,2147483647,!1);ne.MAX_VALUE=ke;var xe=ue(-1,-1,!0);ne.MAX_UNSIGNED_VALUE=xe;var Ee=ue(0,-2147483648,!1);ne.MIN_VALUE=Ee;var Se=ne.prototype;Se.toInt=function(){return this.unsigned?this.low>>>0:this.low},Se.toNumber=function(){return this.unsigned?(this.high>>>0)*fe+(this.low>>>0):this.high*fe+(this.low>>>0)},Se.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(Ee)){var t=se(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var a=se(le(e,6),this.unsigned),i=this,o="";;){var s=i.div(a),u=(i.sub(s.mul(a)).toInt()>>>0).toString(e);if((i=s).isZero())return u+o;for(;u.length<6;)u="0"+u;o=""+u+o}},Se.getHighBits=function(){return this.high},Se.getHighBitsUnsigned=function(){return this.high>>>0},Se.getLowBits=function(){return this.low},Se.getLowBitsUnsigned=function(){return this.low>>>0},Se.getNumBitsAbs=function(){if(this.isNegative())return this.eq(Ee)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},Se.isZero=function(){return 0===this.high&&0===this.low},Se.eqz=Se.isZero,Se.isNegative=function(){return!this.unsigned&&this.high<0},Se.isPositive=function(){return this.unsigned||this.high>=0},Se.isOdd=function(){return 1==(1&this.low)},Se.isEven=function(){return 0==(1&this.low)},Se.equals=function(e){return re(e)||(e=he(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},Se.eq=Se.equals,Se.notEquals=function(e){return!this.eq(e)},Se.neq=Se.notEquals,Se.ne=Se.notEquals,Se.lessThan=function(e){return this.comp(e)<0},Se.lt=Se.lessThan,Se.lessThanOrEqual=function(e){return this.comp(e)<=0},Se.lte=Se.lessThanOrEqual,Se.le=Se.lessThanOrEqual,Se.greaterThan=function(e){return this.comp(e)>0},Se.gt=Se.greaterThan,Se.greaterThanOrEqual=function(e){return this.comp(e)>=0},Se.gte=Se.greaterThanOrEqual,Se.ge=Se.greaterThanOrEqual,Se.compare=function(e){if(re(e)||(e=he(e)),this.eq(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},Se.comp=Se.compare,Se.negate=function(){return!this.unsigned&&this.eq(Ee)?Ee:this.not().add(be)},Se.neg=Se.negate,Se.add=function(e){re(e)||(e=he(e));var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,i=e.high>>>16,o=65535&e.high,s=e.low>>>16,u=0,l=0,c=0,h=0;return c+=(h+=a+(65535&e.low))>>>16,l+=(c+=r+s)>>>16,u+=(l+=n+o)>>>16,u+=t+i,ue((c&=65535)<<16|(h&=65535),(u&=65535)<<16|(l&=65535),this.unsigned)},Se.subtract=function(e){return re(e)||(e=he(e)),this.add(e.neg())},Se.sub=Se.subtract,Se.multiply=function(e){if(this.isZero())return ge;if(re(e)||(e=he(e)),te)return ue(te.mul(this.low,this.high,e.low,e.high),te.get_high(),this.unsigned);if(e.isZero())return ge;if(this.eq(Ee))return e.isOdd()?Ee:ge;if(e.eq(Ee))return this.isOdd()?Ee:ge;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(ve)&&e.lt(ve))return se(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,i=e.high>>>16,o=65535&e.high,s=e.low>>>16,u=65535&e.low,l=0,c=0,h=0,f=0;return h+=(f+=a*u)>>>16,c+=(h+=r*u)>>>16,h&=65535,c+=(h+=a*s)>>>16,l+=(c+=n*u)>>>16,c&=65535,l+=(c+=r*s)>>>16,c&=65535,l+=(c+=a*o)>>>16,l+=t*u+n*s+r*o+a*i,ue((h&=65535)<<16|(f&=65535),(l&=65535)<<16|(c&=65535),this.unsigned)},Se.mul=Se.multiply,Se.divide=function(e){if(re(e)||(e=he(e)),e.isZero())throw Error("division by zero");var t,n,r;if(te)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?ue((this.unsigned?te.div_u:te.div_s)(this.low,this.high,e.low,e.high),te.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?me:ge;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return me;if(e.gt(this.shru(1)))return ye;r=me}else{if(this.eq(Ee))return e.eq(be)||e.eq(we)?Ee:e.eq(Ee)?be:(t=this.shr(1).div(e).shl(1)).eq(ge)?e.isNegative()?be:we:(n=this.sub(e.mul(t)),r=t.add(n.div(e)));if(e.eq(Ee))return this.unsigned?me:ge;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=ge}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(t)/Math.LN2),i=a<=48?1:le(2,a-48),o=se(t),s=o.mul(e);s.isNegative()||s.gt(n);)s=(o=se(t-=i,this.unsigned)).mul(e);o.isZero()&&(o=be),r=r.add(o),n=n.sub(s)}return r},Se.div=Se.divide,Se.modulo=function(e){return re(e)||(e=he(e)),te?ue((this.unsigned?te.rem_u:te.rem_s)(this.low,this.high,e.low,e.high),te.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},Se.mod=Se.modulo,Se.rem=Se.modulo,Se.not=function(){return ue(~this.low,~this.high,this.unsigned)},Se.and=function(e){return re(e)||(e=he(e)),ue(this.low&e.low,this.high&e.high,this.unsigned)},Se.or=function(e){return re(e)||(e=he(e)),ue(this.low|e.low,this.high|e.high,this.unsigned)},Se.xor=function(e){return re(e)||(e=he(e)),ue(this.low^e.low,this.high^e.high,this.unsigned)},Se.shiftLeft=function(e){return re(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?ue(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):ue(0,this.low<<e-32,this.unsigned)},Se.shl=Se.shiftLeft,Se.shiftRight=function(e){return re(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?ue(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):ue(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},Se.shr=Se.shiftRight,Se.shiftRightUnsigned=function(e){if(re(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?ue(this.low>>>e|t<<32-e,t>>>e,this.unsigned):ue(32===e?t:t>>>e-32,0,this.unsigned)},Se.shru=Se.shiftRightUnsigned,Se.shr_u=Se.shiftRightUnsigned,Se.toSigned=function(){return this.unsigned?ue(this.low,this.high,!1):this},Se.toUnsigned=function(){return this.unsigned?this:ue(this.low,this.high,!0)},Se.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},Se.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},Se.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},ne.fromBytes=function(e,t,n){return n?ne.fromBytesLE(e,t):ne.fromBytesBE(e,t)},ne.fromBytesLE=function(e,t){return new ne(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},ne.fromBytesBE=function(e,t){return new ne(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};var Ae=ee||{__proto__:null,default:ee,__moduleExports:ee};function _e(e){return Ae.fromString(e,!0,16)}var Ne=_e("c3a5c85c97cb3127"),Me=_e("b492b66fbe98f273"),Ie=_e("9ae16a3b2f90404f");function Te(e){return e.xor(e.shru(47))}function De(e,t,n){var r=e.slice(t,t+n);return Ae.fromBytes(Array.from(r),!0,!0)}function Re(e,t){return De(e,t,8)}function Fe(e,t){return De(e,t,4)}function Ce(e,t){return 0===t?e:e.shru(t).or(e.shl(64-t))}function Be(e,t,n){void 0===n&&(n=_e("9ddfea08eb382d69"));var r=e.xor(t).mul(n);r=r.xor(r.shru(47));var a=t.xor(r).mul(n);return a=(a=a.xor(a.shru(47))).mul(n)}function Pe(e,t,n,r){return function(e,t,n,r,a,i){a=a.add(e),i=Ce(i.add(a).add(r),21);var o=a;return a=(a=a.add(t)).add(n),i=i.add(Ce(a,44)),[a.add(r),i.add(o)]}(Re(e,t),Re(e,t+8),Re(e,t+16),Re(e,t+24),n,r)}function Le(e,t){if("string"===t)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=p(e)),G().getBool("DEBUG")&&E(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 Oe(){return G().platform.now()}function ze(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",G().platform.encode(e,t)}function qe(e,t){return void 0===t&&(t="utf-8"),t=t||"utf-8",G().platform.decode(e,t)}var Ke={__proto__:null,createScalarValue:function(e,t){return"string"===t?ze(e):Le([e],t)},toTypedArray:Le,now:Oe,fetch:function(e,t){return G().platform.fetch(e,t)},encodeString:ze,decodeString:qe,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=e.length,r=0;n>0;)r=Math.random()*n|0,c(e,--n,r),c(t,n,r)},clamp:l,nearestLargerEven:function(e){return e%2==0?e:e+1},swap:c,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:h,assertShapesMatch:f,assertNonNull:d,flatten:p,sizeFromShape:v,isScalarShape:function(e){return 0===e.length},arraysEqual:g,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:b,repeatedTry:function(e,t,n){return void 0===t&&(t=function(e){return 0}),new Promise((function(r,a){var i=0,o=function(){if(e())r();else{i++;var s=t(i);null!=n&&i>=n?a():setTimeout(o,s)}};o()}))},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 i=e.slice();return i[r]=t/n,i},parseAxisParam:y,squeezeShape:w,getTypedArrayFromDType:k,getArrayFromDType:x,checkConversionForErrors:E,isValidDtype:S,hasEncodingLoss:function(e,t){return"complex64"!==t&&(("float32"!==t||"complex64"===e)&&(("int32"!==t||"float32"===e||"complex64"===e)&&("bool"!==t||"bool"!==e)))},isTypedArray:A,bytesPerElement:_,bytesFromStringArray:N,isString:M,isBoolean:I,isNumber:T,inferDtype:D,isFunction:R,nearestDivisor:F,computeStrides:C,toNestedArray:B,makeOnesTypedArray:P,makeZerosTypedArray:L,makeZerosNestedTypedArray:function(e,t){var n=e.reduce((function(e,t){return e*t}),1);if(null==t||"float32"===t)return B(e,new Float32Array(n));if("int32"===t)return B(e,new Int32Array(n));if("bool"===t)return B(e,new Uint8Array(n));throw new Error("Unknown data type "+t)},assertNonNegativeIntegerDimensions:O,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,hexToLong:_e,fingerPrint64:function(e,t){var n,r;void 0===t&&(t=e.length);var a=Ae.fromNumber(81,!0);if(t<=32)return t<=16?function(e,t){if(void 0===t&&(t=e.length),t>=8){var n=Ie.add(2*t),r=Re(e,0).add(Ie);return Be(Ce(a=Re(e,t-8),37).mul(n).add(r),Ce(r,25).add(a).mul(n),n)}if(t>=4){n=Ie.add(2*t);return Be((r=Fe(e,0)).shl(3).add(t),Fe(e,t-4),n)}if(t>0){var a,i=(r=e[0])+((a=e[t>>1])<<8),o=t+(e[t-1]<<2);return Te(Ie.mul(i).xor(Ne.mul(o))).mul(Ie)}return Ie}(e,t):function(e,t){void 0===t&&(t=e.length);var n=Ie.add(2*t),r=Re(e,0).mul(Me),a=Re(e,8),i=Re(e,t-8).mul(n),o=Re(e,t-16).mul(Ie);return Be(Ce(r.add(a),43).add(Ce(i,30)).add(o),r.add(Ce(a.add(Ie),18)).add(i),n)}(e,t);if(t<=64)return function(e,t){void 0===t&&(t=e.length);var n=Ie.add(2*t),r=Re(e,0).mul(Ie),a=Re(e,8),i=Re(e,t-8).mul(n),o=Re(e,t-16).mul(Ie),s=Ce(r.add(a),43).add(Ce(i,30)).add(o),u=Be(s,r.add(Ce(a.add(Ie),18)).add(i),n),l=Re(e,16).mul(n),c=Re(e,24),h=s.add(Re(e,t-32)).mul(n),f=u.add(Re(e,t-24)).mul(n);return Be(Ce(l.add(c),43).add(Ce(h,30)).add(f),l.add(Ce(c.add(r),18)).add(h),n)}(e,t);var i=a,o=a.mul(Me).add(113),s=Te(o.mul(Ie).add(113)).mul(Ie),u=[Ae.UZERO,Ae.UZERO],l=[Ae.UZERO,Ae.UZERO];i=i.mul(Ie).add(Re(e,0));var c=0,h=64*(t-1>>6),f=h+(t-1&63)-63;do{i=Ce(i.add(o).add(u[0]).add(Re(e,c+8)),37).mul(Me),o=Ce(o.add(u[1]).add(Re(e,c+48)),42).mul(Me),i=i.xor(l[1]),o=o.add(u[0]).add(Re(e,c+40)),s=Ce(s.add(l[0]),33).mul(Me),u=Pe(e,c,u[1].mul(Me),i.add(l[0])),l=Pe(e,c+32,s.add(l[1]),o.add(Re(e,c+16))),s=(n=[i,s])[0],i=n[1],c+=64}while(c!==h);var d=Me.add(s.and(255).shl(1));return c=f,l[0]=l[0].add(t-1&63),u[0]=u[0].add(l[0]),l[0]=l[0].add(u[0]),i=Ce(i.add(o).add(u[0]).add(Re(e,c+8)),37).mul(d),o=Ce(o.add(u[1]).add(Re(e,c+48)),42).mul(d),i=i.xor(l[1].mul(9)),o=o.add(u[0].mul(9).add(Re(e,c+40))),s=Ce(s.add(l[0]),33).mul(d),u=Pe(e,c,u[1].mul(d),i.add(l[0])),l=Pe(e,c+32,s.add(l[1]),o.add(Re(e,c+16))),s=(r=[i,s])[0],i=r[1],Be(Be(u[0],l[0],d).add(Te(o).mul(Ne)).add(s),Be(u[1],l[1],d).add(i),d)}},We=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new Ue)}return e.prototype.profileKernel=function(e,t,n){var r,a,i=function(){r=n()},o=Oe();if(this.backendTimer.timerAvailable())a=this.backendTimer.time(i);else{i();for(var s=0,u=r;s<u.length;s++){u[s].dataSync()}a=Promise.resolve({kernelMs:Oe()-o})}if(G().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,i=e.inputs,o=e.extraInfo;r.forEach((function(e){Promise.all([e.data(),a,o]).then((function(r){t.logger.logKernelProfile(n,e,r[0],r[1],i,r[2])}))}))},e}();var Ue=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,r,a,i){var o="number"==typeof r?b(r+"ms",9):r.error,s=b(e,25),u=t.rank,l=t.size,c=b(t.shape.toString(),14),h="";for(var f in a){var d=a[f];if(null!=d){var p=d.shape||t.shape,v=p.length;h+=f+": "+v+"D "+(v>0?p:"")+" "}}console.log("%c"+s+"\t%c"+o+"\t%c"+u+"D "+c+"\t%c"+l+"\t%c"+h+"\t%c"+i,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}();function Ge(e,t,n,r){var a=C(t),i=function(e,t,n,r){var a=v(t),i=r[r.length-1],o=new Array(i).fill(0),s=t.length,u="complex64"===n?je(e):e;if(s>1)for(var l=0;l<a/i;l++)for(var c=l*i,h=0;h<i;h++)o[h]=Math.max(o[h],Ve(u[c+h],0,n).length);return o}(e,t,n,a),o=t.length,s=function e(t,n,r,a,i,o){void 0===o&&(o=!0);var s="complex64"===r?2:1,u=n[0],l=n.length;if(0===l){return"complex64"===r?[Ve(je(t)[0],0,r)]:"bool"===r?[He(t[0])]:[t[0].toString()]}if(1===l){if(u>20){var c=3*s,h=Array.from(t.slice(0,c)),f=Array.from(t.slice((u-3)*s,u*s));return"complex64"===r&&(h=je(h),f=je(f)),["["+h.map((function(e,t){return Ve(e,i[t],r)})).join(", ")+", ..., "+f.map((function(e,t){return Ve(e,i[u-3+t],r)})).join(", ")+"]"]}return["["+("complex64"===r?je(t):Array.from(t)).map((function(e,t){return Ve(e,i[t],r)})).join(", ")+"]"]}var d=n.slice(1),p=a.slice(1),v=a[0]*s,g=[];if(u>20){for(var m=0;m<3;m++){var b=(y=m*v)+v;g.push.apply(g,e(t.slice(y,b),d,r,p,i,!1))}g.push("...");for(m=u-3;m<u;m++){b=(y=m*v)+v;g.push.apply(g,e(t.slice(y,b),d,r,p,i,m===u-1))}}else for(m=0;m<u;m++){var y;b=(y=m*v)+v;g.push.apply(g,e(t.slice(y,b),d,r,p,i,m===u-1))}var w=2===l?",":"";g[0]="["+g[0]+w;for(m=1;m<g.length-1;m++)g[m]=" "+g[m]+w;var k=",\n";for(m=2;m<l;m++)k+="\n";return g[g.length-1]=" "+g[g.length-1]+"]"+(o?"":k),g}(e,t,n,a,i),u=["Tensor"];return r&&(u.push("  dtype: "+n),u.push("  rank: "+o),u.push("  shape: ["+t+"]"),u.push("  values:")),u.push(s.map((function(e){return"    "+e})).join("\n")),u.join("\n")}function Ve(e,t,n){return b(Array.isArray(e)?parseFloat(e[0].toFixed(7))+" + "+parseFloat(e[1].toFixed(7))+"j":M(e)?"'"+e+"'":"bool"===n?He(e):parseFloat(e.toFixed(7)).toString(),t)}function He(e){return 0===e?"false":"true"}function je(e){for(var t=[],n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var Je=function(){function e(e,t,n){var r=this;if(this.dtype=t,this.shape=e.slice(),this.size=v(e),null!=n){var a=n.length;h(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||x(t,this.size),this.strides=C(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]),h(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 i=a[r];if(i<0||i>=this.shape[n]){var o="Requested out of range element at "+e+".   Buffer shape="+this.shape;throw new Error(o)}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 Ze().makeTensor(this.values,this.shape,this.dtype)},e}(),Ze=null,Ye=null;var Xe=function(){function e(e,t,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=v(e),this.strides=C(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,Ye.buffer(this.shape,this.dtype,e)]}}))}))},e.prototype.bufferSync=function(){return Ye.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,B(this.shape,e,"complex64"===this.dtype)]}}))}))},e.prototype.arraySync=function(){return B(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=Ze().read(this.dataId),"string"!==this.dtype?[3,2]:[4,e];case 1:t=n.sent();try{return[2,t.map((function(e){return qe(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=Ze().readSync(this.dataId);if("string"===this.dtype)try{return e.map((function(e){return qe(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,Ze().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||(Ze().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),Ye.print(this,e)},e.prototype.clone=function(){return this.throwIfDisposed(),Ye.clone(this)},e.prototype.toString=function(e){return void 0===e&&(e=!1),Ge(this.dataSync(),this.shape,this.dtype,e)},e.prototype.cast=function(e){return this.throwIfDisposed(),Ye.cast(this,e)},e.prototype.variable=function(e,t,n){return void 0===e&&(e=!0),this.throwIfDisposed(),Ze().makeVariable(this,e,t,n)},e}();Object.defineProperty(Xe,Symbol.hasInstance,{value:function(e){return!!e&&null!=e.data&&null!=e.dataSync&&null!=e.throwIfDisposed}}),H("Tensor",(function(){return Xe}));var $e,Qe,et,tt,nt,rt=function(e){function t(t,n,r,a){var i=e.call(this,t.shape,t.dtype,t.dataId,a)||this;return i.trainable=n,i.name=r,i}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(!g(e.shape,this.shape))throw new Error("shape of the new value ("+e.shape+") and previous value ("+this.shape+") must match");Ze().disposeTensor(this),this.dataId=e.dataId,Ze().incRef(this,null)},t.prototype.dispose=function(){Ze().disposeVariable(this),this.isDisposedInternal=!0},t}(Xe);Object.defineProperty(rt,Symbol.hasInstance,{value:function(e){return e instanceof Xe&&null!=e.assign&&e.assign instanceof Function}}),($e=e.Rank||(e.Rank={})).R0="R0",$e.R1="R1",$e.R2="R2",$e.R3="R3",$e.R4="R4",$e.R5="R5",$e.R6="R6",function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64"}(Qe||(Qe={})),function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64"}(et||(et={})),function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64"}(tt||(tt={})),function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64"}(nt||(nt={}));var at={float32:tt,int32:Qe,bool:et,complex64:nt};function it(e,t){if("string"===e||"string"===t){if("string"===e&&"string"===t)return"string";throw new Error("Can not upcast "+e+" with "+t)}return at[e][t]}function ot(e,t){if(e.dtype===t.dtype)return[e,t];var n=it(e.dtype,t.dtype);return[e.cast(n),t.cast(n)]}function st(e,t){h(e.dtype===t.dtype,(function(){return"The dtypes of the first("+e.dtype+") and second("+t.dtype+") input must match"}))}function ut(e){var t=[];return function e(t,n,r){if(null==t)return;if(t instanceof Xe)return void n.push(t);if(a=t,!Array.isArray(a)&&"object"!=typeof a)return;var a;var i=t;for(var o in i){var s=i[o];r.has(s)||(r.add(s),e(s,n,r))}}(e,t,new Set),t}var lt={__proto__:null,makeTypesMatch:ot,assertTypesMatch:st,isTensorInList:function(e,t){return t.some((function(t){return t.id===e.id}))},getTensorsInContainer:ut};function ct(e){return null!=e.kernelName}var ht=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}(),ft=function(){function e(e){this.ENV=e,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new ht}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 We(this.backendInstance),[2,!0]}}))}))},e.prototype.setupRegisteredKernels=function(){var e=this;X(this.backendName).forEach((function(t){null!=t.setupFunc&&t.setupFunc(e.backendInstance)}))},e.prototype.disposeRegisteredKernels=function(e){var t=this;X(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 o||"function"!=typeof r.then)return this.registry[e]=r,{success:!0,asyncInit:!1};var a=++this.pendingBackendInitId,i=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=i,{success:i,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,i=r.asyncInit;if(i||a)return{name:n,asyncInit:i}}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),i=r.refCount(t);r.disposeData(t,!0),n.backend=e,e.move(t,a,n.shape,n.dtype,i),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=pt.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 pt.runKernel("Cast",t,n)}}}),[],{}),t},e.prototype.runKernel=function(e,t,n){if(null==this.backendName&&this.backend,!(null!=Z(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 i=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],o=r-t-a-i;if(o>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+o+" data ids) after running '"+e+"'")},e.prototype.runKernelFunc=function(e){var t,n,r,a=this,i=[],o=this.isTapeOn(),s=this.state.numBytes,u=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0),null==this.backendName&&this.backend;var l=ct(e)?e.kernelName:null!=this.state.activeScope?this.state.activeScope.name:"";if(ct(e)){var c=e.kernelName,f=e.inputs,d=e.attrs;null==this.backendName&&this.backend;var p=Z(c,this.backendName);h(null!=p,(function(){return"Cannot find registered kernel '"+c+"' for backend '"+a.backendName+"'"})),n=function(){var e=a.backend.numDataIds();r=p.kernelFunc({inputs:f,attrs:d,backend:a.backend});var t=Array.isArray(r)?r:[r];a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(c,e,t);var n=t.map((function(e){if(null!=e.rank)return e;var t=e,n=t.dataId,r=t.shape,i=t.dtype;return a.makeTensorFromDataId(n,r,i)}));if(o){var s=a.getTensorsForGradient(c,f,n);i=a.saveTensorsForBackwardMode(s)}return n}}else{var v=e.forwardFunc,g=function(e){o&&(i=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,g)}));var t=Array.isArray(r)?r:[r];return a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(l,e,t),t}}var m,b=e.inputs,y=e.attrs,w=ct(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?(m=a.profiler.profileKernel(l,b,(function(){return n()})),a.ENV.getBool("DEBUG")&&a.profiler.logKernelProfile(m),t=m.outputs):t=n()})),o&&this.addTapeNode(l,b,t,w,i,y),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(b).map((function(e){return null!=b[e]?b[e].shape:null})),outputShapes:t.map((function(e){return e.shape})),kernelTimeMs:m.timeMs,extraInfo:m.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||[],i=r.outputsToSave||[],o=void 0;r.saveAllInputs?(h(Array.isArray(t),(function(){return"saveAllInputs is true, expected inputs to be an array."})),o=Object.keys(t).map((function(e){return t[e]}))):o=a.map((function(e){return t[e]}));var s=n.filter((function(e,t){return i[t]}));return o.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&&M(e[0])&&(a=e.map((function(e){return ze(e)})));var i=r.write(a,t,n),o=new Xe(t,n,i,this.nextTensorId());if(this.trackTensor(o,r),"string"===n){var s=this.state.tensorInfo.get(i),u=N(a);this.state.numBytes+=u-s.bytes,s.bytes=u}return o},e.prototype.makeTensorFromDataId=function(e,t,n,r){var a=new Xe(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 rt(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*_(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 rt||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*_(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,i,o,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,i=0,o=this.state.activeProfile.kernels,a.label=2;case 2:return i<o.length?(s=o[i],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 i++,[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,i){var o=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=L(r.size,r.dtype);return o.makeTensor(a,r.shape,r.dtype)}return e})),r(e.length>1?e:e[0],a,i)}),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=ut(e),r=new Set(n.map((function(e){return e.id}))),a=0;a<this.state.activeScope.track.length;a++){var i=this.state.activeScope.track[a];i.kept||r.has(i.id)||i.dispose()}var o=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!==o.id||t.track(e)}))},e.prototype.gradients=function(e,t,n,r){var a=this;if(void 0===r&&(r=!1),h(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 i=this.scopedRun((function(){return a.startTape()}),(function(){return a.endTape()}),(function(){return a.tidy("forward",e)}));h(i instanceof Xe,(function(){return"The result y returned by f() must be a tensor."}));var o=function(e,t,n){for(var r={},a={},i=0;i<t.length;i++)r[t[i].id]=!0;for(i=0;i<e.length;i++){var o=(p=e[i]).inputs;for(var s in o){for(var u=o[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 h={};h[n.id]=!0;var f={};for(i=e.length-1;i>=0;i--)for(o=(p=e[i]).inputs,c=0;c<p.outputs.length;c++)if(h[p.outputs[c].id]){for(var s in o)h[o[s].id]=!0,f[p.id]=!0;break}var d=[];for(i=0;i<e.length;i++){var p;if(a[(p=e[i]).id]&&f[p.id]){var v={};for(var s in p.inputs){var g=p.inputs[s];r[g.id]&&(v[s]=g)}var m=Object.assign({},p);m.inputs=v,m.outputs=p.outputs,d.push(m)}}return d}(this.state.activeTape,t,i);if(!r&&0===o.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[i.id]=null==n?(e=i.shape,r=P(v(e),"float32"),pt.makeTensor(r,e,"float32")):n,function(e,t,n,r){for(var a=function(a){var i=t[a],o=[];if(i.outputs.forEach((function(t){var n=e[t.id];null!=n?o.push(n):o.push(null)})),null==i.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+i.kernelName+".");var s=i.gradient(o),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 "+i.kernelName+". The gradient of input "+t+" must have 'float32' dtype, but has '"+a.dtype+"'");var o=i.inputs[t];if(!g(a.shape,o.shape))throw new Error("Error in gradient for op "+i.kernelName+". The gradient of input '"+t+"' has shape '"+a.shape+"', which does not match the shape of the input '"+o.shape+"'");if(null==e[o.id])e[o.id]=a;else{var u=e[o.id];e[o.id]=r(u,a),u.dispose()}};for(var l in i.inputs)u(l)},i=t.length-1;i>=0;i--)a(i)}(s,o,(function(e){return a.tidy(e)}),vt);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:i,grads:u}}))},e.prototype.customGrad=function(e){var t=this;return h(R(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];h(r.every((function(e){return e instanceof Xe})),(function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"}));var i={};r.forEach((function(e,t){i[t]=e}));var o=function(t,a){return h((n=e.apply(void 0,r.concat([a]))).value instanceof Xe,(function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"})),h(R(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),i=Array.isArray(a)?a:[a];h(i.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(...)."})),h(i.every((function(e){return e instanceof Xe})),(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 o={};return i.forEach((function(e,t){o[t]=function(){return e}})),o};return t.runKernelFunc({forwardFunc:o,backwardsFunc:s,inputs:i})}},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=Oe(),[4,this.backend.time(e)];case 1:return(n=r.sent()).wallMs=Oe()-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 ht,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 dt(){var t=V();if(null==t._tfengine){var n=new K(t);t._tfengine=new ft(n)}return function(t){e.ENV=t}(t._tfengine.ENV),Ze=function(){return t._tfengine},t._tfengine}var pt=dt();function vt(e,t){var n={a:e,b:t};return pt.runKernel("Add",n)}function gt(){return"undefined"!=typeof window&&null!=window.document||"undefined"!=typeof WorkerGlobalScope}var mt={__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:gt},bt=G();function yt(e,t){var n=e;if(A(e))return"string"===t?[]:[e.length];if(!Array.isArray(e))return[];for(var r=[];Array.isArray(n)||A(n)&&"string"!==t;)r.push(n.length),n=n[0];return Array.isArray(e)&&G().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function e(t,n,r){if(r=r||[],!Array.isArray(t)&&!A(t))return void h(0===n.length,(function(){return"Element arr["+r.join("][")+"] is a primitive, but should be an array/TypedArray of "+n[0]+" elements"}));h(n.length>0,(function(){return"Element arr["+r.join("][")+"] should be a primitive, but is an array of "+t.length+" elements"})),h(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),i=0;i<t.length;++i)e(t[i],a,r.concat(i))}(e,r,[]),r}function wt(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 kt(e,t,n,r){if(void 0===r&&(r="numeric"),e instanceof Xe)return wt(r,e.dtype,t,n),e;var a=D(e);if("string"!==a&&["bool","int32","float32"].indexOf(r)>=0&&(a=r),wt(r,a,t,n),null==e||!A(e)&&!Array.isArray(e)&&"number"!=typeof e&&"boolean"!=typeof e&&"string"!=typeof e){var i=null==e?"null":e.constructor.name;throw new Error("Argument '"+t+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+i+"'")}var o=yt(e,a);A(e)||Array.isArray(e)||(e=[e]);var s="string"!==a?Le(e,a):p(e,[],!0);return pt.makeTensor(s,o,a)}function xt(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 kt(e,t+"["+a+"]",n,r)}))}bt.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.")})),bt.registerFlag("IS_BROWSER",(function(){return gt()})),bt.registerFlag("IS_NODE",(function(){return"undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.node})),bt.registerFlag("IS_CHROME",(function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)})),bt.registerFlag("PROD",(function(){return!1})),bt.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",(function(){return bt.getBool("DEBUG")})),bt.registerFlag("DEPRECATION_WARNINGS_ENABLED",(function(){return!0})),bt.registerFlag("IS_TEST",(function(){return!1})),bt.registerFlag("CHECK_COMPUTATION_FOR_ERRORS",(function(){return!0})),bt.registerFlag("WRAP_TO_IMAGEBITMAP",(function(){return!1}));function Et(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];pt.startScope(n);try{var a=r.apply(void 0,e);return z(a)&&console.error("Cannot return a Promise inside of tidy."),pt.endScope(a),a}catch(e){throw pt.endScope(null),e}};return Object.defineProperty(a,"name",{value:n,configurable:!0}),a}var St=Et({complex_:function(e,t){var n=kt(e,"real","complex"),r=kt(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 pt.runKernel("Complex",a)}});function At(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(!A(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){O(t);var a=v(t),i=v(n);h(a===i,(function(){return"Based on the provided shape, ["+t+"], the tensor should have "+a+" values but has "+i}));for(var o=0;o<n.length;++o){var s=n[o],u=o!==n.length-1||s!==v(t.slice(o));h(n[o]===t[o]||!u,(function(){return"Error creating a new Tensor. Inferred shape ("+n+") does not match the provided shape ("+t+"). "}))}}return A(e)||Array.isArray(e)||(e=[e]),t=t||n,e="string"!==r?Le(e,r):p(e,[],!0),pt.makeTensor(e,t,r)}function _t(e,t,n){return At(e,t,yt(e,n),n)}var Nt={float32:4,float16:2,int32:4,uint16:2,uint8:1,bool:1,complex64:8};function Mt(e,t){for(var n,r={},a=0,i=0,o=t;i<o.length;i++){var s=o[i],u=s.name,l=s.dtype,c=s.shape,h=v(c),f=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 p=Nt[d.dtype],g=e.slice(a,a+h*p),m="uint8"===d.dtype?new Uint8Array(g):new Uint16Array(g);if("float32"===l)if("uint8"===d.dtype||"uint16"===d.dtype){f=new Float32Array(m.length);for(var b=0;b<m.length;b++){var y=m[b];f[b]=y*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=Lt()),f=n(m)}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.");f=new Int32Array(m.length);for(b=0;b<m.length;b++){y=m[b];f[b]=Math.round(y*d.scale+d.min)}}a+=h*p}else if("string"===l){var w=v(s.shape);f=[];for(b=0;b<w;b++){var k=new Uint32Array(e.slice(a,a+4))[0];a+=4;var x=new Uint8Array(e.slice(a,a+k));f.push(x),a+=k}}else{var E=Nt[l];g=e.slice(a,a+h*E);if("float32"===l)f=new Float32Array(g);else if("int32"===l)f=new Int32Array(g);else if("bool"===l)f=new Uint8Array(g);else{if("complex64"!==l)throw new Error("Unsupported dtype in weight '"+u+"': "+l);f=new Float32Array(g);var S=new Float32Array(f.length/2),A=new Float32Array(f.length/2);for(b=0;b<S.length;b++)S[b]=f[2*b],A[b]=f[2*b+1];var _=_t(S,c,"float32"),N=_t(A,c,"float32");r[u]=St(_,N),_.dispose(),N.dispose()}a+=h*E}"complex64"!==l&&(r[u]=_t(f,c,l))}return r}function It(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 Tt="undefined"!=typeof Buffer&&("undefined"==typeof Blob||"undefined"==typeof atob||"undefined"==typeof btoa);function Dt(e){return Tt?Buffer.byteLength(e):new Blob([e]).size}function Rt(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 Ft(e){for(e=e.trim();e.endsWith("/");)e=e.slice(0,e.length-1);var t=e.split("/");return t[t.length-1]}function Ct(e,t){var n={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,weightsManifest:t};return null!=e.signature&&(n.signature=e.signature),null!=e.userDefinedMetadata&&(n.userDefinedMetadata=e.userDefinedMetadata),null!=e.modelInitializer&&(n.modelInitializer=e.modelInitializer),null!=e.trainingConfig&&(n.trainingConfig=e.trainingConfig),n}function Bt(e,t){return r(this,void 0,void 0,(function(){var n,r,i,o;return a(this,(function(a){switch(a.label){case 0:return n={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy},null!=e.trainingConfig&&(n.trainingConfig=e.trainingConfig),null==e.weightsManifest?[3,2]:[4,t(e.weightsManifest)];case 1:r=a.sent(),i=r[0],o=r[1],n.weightSpecs=i,n.weightData=o,a.label=2;case 2:return null!=e.signature&&(n.signature=e.signature),null!=e.userDefinedMetadata&&(n.userDefinedMetadata=e.userDefinedMetadata),null!=e.modelInitializer&&(n.modelInitializer=e.modelInitializer),[2,n]}}))}))}function Pt(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:Dt(JSON.stringify(e.modelTopology)),weightSpecsBytes:null==e.weightSpecs?0:Dt(JSON.stringify(e.weightSpecs)),weightDataBytes:null==e.weightData?0:e.weightData.byteLength}}function Lt(){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),i=new Uint32Array(a),o=0;o<r.length;o++){var s=r[o],u=e[n[s>>10]+(1023&s)]+t[s>>10];i[o]=u}return new Float32Array(a)}}var Ot=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 zt(){if(!G().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 qt(e){var t=e.result;t.createObjectStore("models_store",{keyPath:"modelPath"}),t.createObjectStore("model_info_store",{keyPath:"modelPath"})}var Kt=function(){function e(e){if(this.indexedDB=zt(),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 qt(a)},a.onsuccess=function(){var i=a.result;if(null==t){var o=i.transaction("models_store","readonly"),s=o.objectStore("models_store").get(n.modelPath);s.onsuccess=function(){if(null==s.result)return i.close(),r(new Error("Cannot find model with path '"+n.modelPath+"' in IndexedDB."));e(s.result.modelArtifacts)},s.onerror=function(e){return i.close(),r(s.error)},o.oncomplete=function(){return i.close()}}else{var u,l=Pt(t),c=i.transaction("model_info_store","readwrite"),h=c.objectStore("model_info_store"),f=h.put({modelPath:n.modelPath,modelArtifactsInfo:l});f.onsuccess=function(){var a=(u=i.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=(h=c.objectStore("model_info_store")).delete(n.modelPath);t.onsuccess=function(){return i.close(),r(a.error)},t.onerror=function(e){return i.close(),r(a.error)}}},f.onerror=function(e){return i.close(),r(f.error)},c.oncomplete=function(){null==u?i.close():u.oncomplete=function(){return i.close()}}}},a.onerror=function(e){return r(a.error)}}))},e.URL_SCHEME="indexeddb://",e}(),Wt=function(e){return G().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(Kt.URL_SCHEME)?(t=e.slice(Kt.URL_SCHEME.length),new Kt(t)):null;var t};Ot.registerSaveRouter(Wt),Ot.registerLoadRouter(Wt);var Ut=function(){function e(){this.indexedDB=zt()}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 qt(r)},r.onsuccess=function(){var e=r.result,a=e.transaction("model_info_store","readonly"),i=a.objectStore("model_info_store").getAll();i.onsuccess=function(){for(var e={},n=0,r=i.result;n<r.length;n++){var a=r[n];e[a.modelPath]=a.modelArtifactsInfo}t(e)},i.onerror=function(t){return e.close(),n(i.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(Kt.URL_SCHEME)?r.slice(Kt.URL_SCHEME.length):r,[2,new Promise((function(n,r){var a=t.indexedDB.open("tensorflowjs",1);a.onupgradeneeded=function(){return qt(a)},a.onsuccess=function(){var t,i=a.result,o=i.transaction("model_info_store","readwrite"),s=o.objectStore("model_info_store"),u=s.get(e);u.onsuccess=function(){if(null==u.result)return i.close(),r(new Error("Cannot find model with path '"+e+"' in IndexedDB."));var a=s.delete(e),o=function(){var a=(t=i.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=o,a.onerror=function(e){return o(),i.close(),r(u.error)}},u.onerror=function(e){return i.close(),r(u.error)},o.oncomplete=function(){null==t?i.close():t.oncomplete=function(){return i.close()}}},a.onerror=function(e){return r(a.error)}}))]}))}))},e}(),Gt="tensorflowjs_models",Vt="info",Ht="model_topology",jt="weight_specs",Jt="weight_data",Zt="model_metadata";function Yt(e){return{info:[Gt,e,Vt].join("/"),topology:[Gt,e,Ht].join("/"),weightSpecs:[Gt,e,jt].join("/"),weightData:[Gt,e,Jt].join("/"),modelMetadata:[Gt,e,Zt].join("/")}}function Xt(e){for(var t=0,n=Object.values(e);t<n.length;t++){var r=n[t];window.localStorage.removeItem(r)}}function $t(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 Qt=function(){function e(e){if(!G().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=Yt(this.modelPath)}return e.prototype.save=function(e){return r(this,void 0,void 0,(function(){var t,n,r,i;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=Pt(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(Tt)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)),i={format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,signature:null!=e.signature?e.signature:void 0,userDefinedMetadata:null!=e.userDefinedMetadata?e.userDefinedMetadata:void 0,modelInitializer:null!=e.modelInitializer?e.modelInitializer:void 0,trainingConfig:null!=e.trainingConfig?e.trainingConfig:void 0},this.LS.setItem(this.keys.modelMetadata,JSON.stringify(i)),[2,{modelArtifactsInfo:r}]}catch(e){throw Xt(this.keys),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,i,o,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!=(i=this.LS.getItem(this.keys.modelMetadata))&&(o=JSON.parse(i),t.format=o.format,t.generatedBy=o.generatedBy,t.convertedBy=o.convertedBy,null!=o.signature&&(t.signature=o.signature),null!=o.userDefinedMetadata&&(t.userDefinedMetadata=o.userDefinedMetadata),null!=o.modelInitializer&&(t.modelInitializer=o.modelInitializer),null!=o.trainingConfig&&(t.trainingConfig=o.trainingConfig)),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(Tt){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}(),en=function(e){return G().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(Qt.URL_SCHEME)?(t=e.slice(Qt.URL_SCHEME.length),new Qt(t)):null;var t};Ot.registerSaveRouter(en),Ot.registerLoadRouter(en);var tn=function(){function e(){h(G().getBool("IS_BROWSER"),(function(){return"Current environment is not a web browser"})),h("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,i,o;return a(this,(function(a){for(e={},t=Gt+"/",n="/"+Vt,r=0;r<this.LS.length;++r)(i=this.LS.key(r)).startsWith(t)&&i.endsWith(n)&&(o=$t(i),e[o]=JSON.parse(this.LS.getItem(i)));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(Qt.URL_SCHEME)?a.slice(Qt.URL_SCHEME.length):a,t=Yt(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)),Xt(t),[2,n]}))}))},e}(),nn=function(){function e(){this.managers={}}return e.getInstance=function(){return null==e.instance&&(e.instance=new e),e.instance},e.registerManager=function(t,n){h(null!=t,(function(){return"scheme must not be undefined or null."})),t.endsWith("://")&&(t=t.slice(0,t.indexOf("://"))),h(t.length>0,(function(){return"scheme must not be an empty string."}));var r=e.getInstance();h(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 rn(e){if(-1===e.indexOf("://"))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+nn.getSchemes().join(","));return{scheme:e.split("://")[0],path:e.split("://")[1]}}function an(e,t,n){return void 0===n&&(n=!1),r(this,void 0,void 0,(function(){var r,i,o,s,u,l,c,f,d;return a(this,(function(a){switch(a.label){case 0:return h(e!==t,(function(){return"Old path and new path are the same: '"+e+"'"})),h((r=Ot.getLoadHandlers(e)).length>0,(function(){return"Copying failed because no load handler is found for source URL "+e+"."})),h(r.length<2,(function(){return"Copying failed because more than one ("+r.length+") load handlers for source URL "+e+"."})),i=r[0],h((o=Ot.getSaveHandlers(t)).length>0,(function(){return"Copying failed because no save handler is found for destination URL "+t+"."})),h(o.length<2,(function(){return"Copying failed because more than one ("+r.length+") save handlers for destination URL "+t+"."})),s=o[0],u=rn(e).scheme,l=rn(e).path,c=u===rn(e).scheme,[4,i.load()];case 1:return f=a.sent(),n&&c?[4,nn.getManager(u).removeModel(l)]:[3,3];case 2:a.sent(),a.label=3;case 3:return[4,s.save(f)];case 4:return d=a.sent(),!n||c?[3,6]:[4,nn.getManager(u).removeModel(l)];case 5:a.sent(),a.label=6;case 6:return[2,d.modelArtifactsInfo]}}))}))}var on=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(G().get("IS_BROWSER")){G().setPlatform("browser",new on);try{nn.registerManager(Qt.URL_SCHEME,new tn)}catch(e){}try{nn.registerManager(Kt.URL_SCHEME,new Ut)}catch(e){}}var sn,un=function(){return require("node-fetch")},ln=function(){function e(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return e.prototype.fetch=function(e,t){return null!=G().global.fetch?G().global.fetch(e,t):(null==sn&&(sn=un()),sn(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 cn(e,t,n){return void 0===t&&(t="float32"),t=t||"float32",O(e),new Je(e,t,n)}G().get("IS_NODE")&&G().setPlatform("node",new ln);var hn=Et({cast_:function(e,t){var n=kt(e,"x","cast");if(!S(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 pt.runKernel("Cast",r,a)}});var fn=Et({clone_:function(e){var t={x:kt(e,"x","clone","string_or_numeric")};return pt.runKernel("Identity",t)}});function dn(e,t){void 0===t&&(t=!1),console.log(e.toString(t))}dt(),Ye={buffer:cn,cast:hn,clone:fn,print:dn};function pn(e){return new Promise((function(e){return setTimeout(e)})).then(e)}var vn=function(){function e(t){if(!G().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.modelJsonFileName=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,i,o,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=Ct(e,n),i=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),(o=null==this.modelJsonAnchor?document.createElement("a"):this.modelJsonAnchor).download=this.modelJsonFileName,o.href=i,[4,pn((function(){return o.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,pn((function(){return s.dispatchEvent(new MouseEvent("click"))}))]);case 3:a.sent(),a.label=4;case 4:return[2,{modelArtifactsInfo:Pt(e)}]}}))}))},e.URL_SCHEME="downloads://",e}(),gn=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.jsonFile=e[0],this.weightsFiles=e.slice(1)}return e.prototype.load=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=new FileReader;r.onload=function(r){var a=JSON.parse(r.target.result),i=a.modelTopology;if(null!=i)if(null!=a.weightsManifest)if(0!==e.weightsFiles.length){var o=Bt(a,(function(t){return e.loadWeights(t)}));t(o)}else t({modelTopology:i});else n(new Error("weightManifest field is missing from file "+e.jsonFile.name));else n(new Error("modelTopology field is missing from file "+e.jsonFile.name))},r.onerror=function(t){return n("Failed to read model topology and weights manifest JSON from file '"+e.jsonFile.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},r.readAsText(e.jsonFile)}))]}))}))},e.prototype.loadWeights=function(e){for(var t=this,n=[],r=[],a=0,i=e;a<i.length;a++){var o=i[a];n.push.apply(n,o.weights),r.push.apply(r,o.paths)}var s=this.checkManifestAndWeightFiles(e),u=r.map((function(e){return t.loadWeightsFile(e,s[e])}));return Promise.all(u).then((function(e){return[n,Rt(e)]}))},e.prototype.loadWeightsFile=function(e,t){return new Promise((function(n,r){var a=new FileReader;a.onload=function(e){var t=e.target.result;n(t)},a.onerror=function(t){return r("Failed to weights data from file of path '"+e+"'.")},a.readAsArrayBuffer(t)}))},e.prototype.checkManifestAndWeightFiles=function(e){for(var t=this,n=[],r=this.weightsFiles.map((function(e){return Ft(e.name)})),a={},i=0,o=e;i<o.length;i++){o[i].paths.forEach((function(e){var i=Ft(e);if(-1!==n.indexOf(i))throw new Error("Duplicate file basename found in weights manifest: '"+i+"'");if(n.push(i),-1===r.indexOf(i))throw new Error("Weight file with basename '"+i+"' is not provided.");a[e]=t.weightsFiles[r.indexOf(i)]}))}if(n.length!==this.weightsFiles.length)throw new Error("Mismatch in the number of files in weights manifest ("+n.length+") and the number of weight files provided ("+this.weightsFiles.length+").");return a},e}();function mn(e,t,n,r){!function(e){h(null!=e&&Array.isArray(e)&&e.length>0,(function(){return"promises must be a none empty array"}))}(e),function(e,t){h(e>=0&&e<=1,(function(){return"Progress fraction must be in range [0, 1], but got startFraction "+e})),h(t>=0&&t<=1,(function(){return"Progress fraction must be in range [0, 1], but got endFraction "+t})),h(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(i){return i.then((function(i){var o=n+ ++a/e.length*(r-n);return t(o),i})),i})))}function bn(e,t){return r(this,void 0,void 0,(function(){var n,r,i,o,s,u,l,c,h;return a(this,(function(a){switch(a.label){case 0:return null==t&&(t={}),n=null==t.fetchFunc?G().platform.fetch:t.fetchFunc,r=e.map((function(e){return n(e,t.requestInit,{isBinary:!0})})),i=0,o=.5,null!=t.onProgress?[3,2]:[4,Promise.all(r)];case 1:return s=a.sent(),[3,4];case 2:return[4,mn(r,t.onProgress,i,o)];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 h=a.sent(),[3,8];case 6:return[4,mn(u,t.onProgress,l,c)];case 7:h=a.sent(),a.label=8;case 8:return[2,h]}}))}))}function yn(e){var t=this;return function(n,i,o){return void 0===i&&(i=""),r(t,void 0,void 0,(function(){var t,r,s,u,l,c,h,f,d,p;return a(this,(function(a){switch(a.label){case 0:if(t=n.map((function(){return!1})),r={},s=null!=o?o.map((function(){return!1})):[],u=[],n.forEach((function(e,n){var a=0;e.weights.forEach((function(e){var i="quantization"in e?e.quantization.dtype:e.dtype,l=Nt[i]*v(e.shape),c=function(){t[n]=!0,null==r[n]&&(r[n]=[]),r[n].push({manifestEntry:e,groupOffset:a,sizeBytes:l})};null!=o?o.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=o.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}),[]),h=[],c.forEach((function(e){n[e].paths.forEach((function(e){var t=i+(i.endsWith("/")?"":"/")+e;h.push(t)}))})),[4,e(h)];case 1:return f=a.sent(),d={},p=0,c.forEach((function(e){for(var t=n[e].paths.length,a=0,i=0;i<t;i++)a+=f[p+i].byteLength;for(var o=new ArrayBuffer(a),s=new Uint8Array(o),u=0,l=0;l<t;l++){var c=new Uint8Array(f[p+l]);s.set(c,u),u+=c.byteLength}r[e].forEach((function(e){var t=Mt(o.slice(e.groupOffset,e.groupOffset+e.sizeBytes),[e.manifestEntry]);for(var n in t)d[n]=t[n]})),p+=t})),[2,d]}}))}))}}Ot.registerSaveRouter((function(e){return G().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(vn.URL_SCHEME)?function(e){void 0===e&&(e="model");return new vn(e)}(e.slice(vn.URL_SCHEME.length)):null}));var wn=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?(h("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=G().platform.fetch,h(null!=e&&e.length>0,(function(){return"URL path for http must not be null, undefined or empty."})),Array.isArray(e)&&h(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,i;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=Ct(e,n),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((i=a.sent()).ok)return[2,{modelArtifactsInfo:Pt(e),responses:[i]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+i.status+".")}}))}))},e.prototype.load=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,i,o=this;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,i=t.weightsManifest,null==r&&null==i)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return[2,Bt(t,(function(e){return o.loadWeights(e)}))]}}))}))},e.prototype.loadWeights=function(e){return r(this,void 0,void 0,(function(){var t,n,r,i,o,s,u,l,c,h,f,d,p,v,g,m,b,y,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],i=n[1],o=this.weightPathPrefix||r,s=[],u=0,l=e;u<l.length;u++)c=l[u],s.push.apply(s,c.weights);for(h=[],f=[],d=0,p=e;d<p.length;d++)for(v=p[d],g=0,m=v.paths;g<m.length;g++)b=m[g],null!=this.weightUrlConverter?f.push(this.weightUrlConverter(b)):h.push(o+b+i);return this.weightUrlConverter?(w=(y=h.push).apply,k=[h],[4,Promise.all(f)]):[3,2];case 1:w.apply(y,k.concat([a.sent()])),a.label=2;case 2:return[4,bn(h,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 3:return x=a.sent(),[2,[s,Rt(x)]]}}))}))},e.URL_SCHEME_REGEX=/^https?:\/\//,e}();function kn(e){return null!=e.match(wn.URL_SCHEME_REGEX)}var xn=function(e,t){if("undefined"==typeof fetch&&(null==t||null==t.fetchFunc))return null;return(Array.isArray(e)?e.every((function(e){return kn(e)})):kn(e))?En(e,t):null};function En(e,t){return new wn(e,t)}Ot.registerSaveRouter(xn),Ot.registerLoadRouter(xn);var Sn=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}(),An=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 _n={__proto__:null,browserFiles:function(e){return new gn(e)},browserHTTPRequest:function(e,t){return En(e,t)},concatenateArrayBuffers:Rt,decodeWeights:Mt,encodeWeights:function(e,t){return r(this,void 0,void 0,(function(){var n,i,o,s,u,l=this;return a(this,(function(c){switch(c.label){case 0:for(n=[],i=[],o=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e),s=function(s){var u=o[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 h={name:u,shape:c.shape,dtype:c.dtype};if("string"===c.dtype){var f=new Promise((function(e){return r(l,void 0,void 0,(function(){var t,n,r,i,o,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),i=0,o=0;o<t.length;o++)s=t[o],u=new Uint8Array(new Uint32Array([s.length]).buffer),r.set(u,i),i+=4,r.set(s,i),i+=s.length;return e(r),[2]}}))}))}));i.push(f)}else i.push(c.data());null!=t&&(h.group=t),n.push(h)},u=0;u<o.length;++u)s(u);return[4,Promise.all(i)];case 1:return[2,{data:It(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 Sn(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 Sn({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 Sn({modelTopology:e,weightSpecs:t,weightData:n,trainingConfig:r})},getLoadHandlers:function(e,t){return Ot.getLoadHandlers(e,t)},getModelArtifactsForJSON:Bt,getModelArtifactsInfoForJSON:Pt,getSaveHandlers:function(e){return Ot.getSaveHandlers(e)},http:En,isHTTPScheme:kn,loadWeights:function(e,t,n,i){return void 0===t&&(t=""),r(this,void 0,void 0,(function(){return a(this,(function(r){return[2,yn((function(e){return bn(e,{requestInit:i})}))(e,t,n)]}))}))},registerLoadRouter:function(e){return Ot.registerLoadRouter(e)},registerSaveRouter:function(e){return Ot.registerSaveRouter(e)},weightsLoaderFactory:yn,withSaveHandler:function(e){return new An(e)},copyModel:function(e,t){return r(this,void 0,void 0,(function(){return a(this,(function(n){return!1,[2,an(e,t,!1)]}))}))},listModels:function(){return r(this,void 0,void 0,(function(){var e,t,n,r,i,o,s;return a(this,(function(a){switch(a.label){case 0:e=nn.getSchemes(),t={},n=0,r=e,a.label=1;case 1:return n<r.length?(i=r[n],[4,nn.getManager(i).listModels()]):[3,4];case 2:for(s in o=a.sent())t[i+"://"+s]=o[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,an(e,t,!0)]}))}))},removeModel:function(e){return r(this,void 0,void 0,(function(){var t;return a(this,(function(n){return t=rn(e),[2,nn.getManager(t.scheme).removeModel(t.path)]}))}))}};var Nn=Et({matMul_:function(e,t,n,r){var a;void 0===n&&(n=!1),void 0===r&&(r=!1);var i=kt(e,"a","matMul"),o=kt(t,"b","matMul"),s={a:i=(a=ot(i,o))[0],b:o=a[1]},u={transposeA:n,transposeB:r};return pt.runKernel("BatchMatMul",s,u)}});var Mn=Et({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:kt(e,"indices","oneHot","int32")},i={depth:t,onValue:n,offValue:r};return pt.runKernel("OneHot",a,i)}});var In=Et({transpose_:function(e,t){var n=kt(e,"x","transpose");if(null==t&&(t=n.shape.map((function(e,t){return t})).reverse()),h(n.rank===t.length,(function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+t+"."})),t.forEach((function(e){h(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 pt.runKernel("Transpose",r,a)}});var Tn,Dn={__proto__:null,confusionMatrix:Et({confusionMatrix_:function(e,t,n){var r=kt(e,"labels","confusionMatrix"),a=kt(t,"predictions","confusionMatrix");h(null==n||n>0&&Number.isInteger(n),(function(){return"If provided, numClasses must be a positive integer, but got "+n})),h(1===r.rank,(function(){return"Expected the rank of labels to be 1, but got "+r.rank})),h(1===a.rank,(function(){return"Expected the rank of predictions to be 1, but got "+a.rank})),h(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."})),h(n>0&&Number.isInteger(n),(function(){return"numClasses is required to be a positive integer, but got "+n}));var i=Mn(hn(r,"int32"),n),o=Mn(hn(a,"int32"),n),s=In(i),u=Nn(s,o);return hn(u,"int32")}})};function Rn(e,t,n){if(d(e),null!=t&&3!==t.length)throw new Error("tensor3d() requires shape to have three numbers");var r=yt(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 At(e,t,r,n)}function Fn(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,i=!1,o=!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)i=!0;else if(null!=e.getContext)o=!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!=Z("FromPixels",pt.backendName)){var u={pixels:e},l={numChannels:t};return pt.runKernel("FromPixels",u,l)}var c,h,f=a?[e.videoWidth,e.videoHeight]:[e.width,e.height],d=f[0],p=f[1];if(o?c=e.getContext("2d").getImageData(0,0,d,p).data:r||n?c=e.data:(i||a||s)&&(null==Tn&&(Tn=document.createElement("canvas").getContext("2d")),Tn.canvas.width=d,Tn.canvas.height=p,Tn.drawImage(e,0,0,d,p),c=Tn.getImageData(0,0,d,p).data),4===t)h=new Int32Array(c);else{var v=d*p;h=new Int32Array(v*t);for(var g=0;g<v;g++)for(var m=0;m<t;++m)h[g*t+m]=c[4*g+m]}return Rn(h,[p,d,t],"int32")}function Cn(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 Bn={__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,!G().getBool("WRAP_TO_IMAGEBITMAP")||!Cn(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,Fn(n,t)]}}))}))},toPixels:function(e,t){return r(this,void 0,void 0,(function(){var n,r,i,o,s,u,l,c,h,f,d,p,v,g,m,b;return a(this,(function(a){switch(a.label){case 0:if(n=kt(e,"img","toPixels"),e instanceof Xe||(n=hn(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(i=n.shape.slice(0,2),o=i[0],s=i[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,h=new Uint8ClampedArray(s*o*4),f=0;f<o*s;++f){for(d=[0,0,0,255],p=0;p<u;p++){if(v=l[f*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}h[(g=4*f)+0]=Math.round(d[0]),h[g+1]=Math.round(d[1]),h[g+2]=Math.round(d[2]),h[g+3]=Math.round(d[3])}return null!=t&&(t.width=s,t.height=o,m=t.getContext("2d"),b=new ImageData(h,s,o),m.putImageData(b,0,0)),n!==e&&n.dispose(),[2,h]}}))}))},fromPixels:Et({fromPixels_:Fn})};function Pn(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===v(e.shape))throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+e.shape+".");for(var a=t.shape,i=a[a.length-1],o=1,s=0;s<a.length-1;++s)o*=a[s];var u=e.shape,l=a.slice();l.pop();var c=1;for(s=i;s<n;++s)c*=u[s],l.push(u[s]);var h=C(e.shape).map((function(e){return e/c})).concat([1]).slice(0,i);return[l,o,c,h]}var Ln={__proto__:null,prepareAndValidate:Pn};function On(e,t,n){var r=t.rank>1?t.shape[t.rank-1]:1,a=t.rank>1?t.rank-1:1,i="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(i+" update.rank < "+a+". ");if(e.length<r+(n.rank-a))throw new Error(i+" Output shape length < "+(r+(n.rank-a)));if(n.rank!==a+e.length-r)throw new Error(i+" update.rank != "+(a+e.length-r));for(var o=0;o<a;++o)if(n.shape[o]!==t.shape[o])throw new Error(i+" updates.shape["+o+"] ("+n.shape[o]+") != indices.shape["+o+"] ("+t.shape[o]+").");for(o=0;o<n.rank-a;++o)if(n.shape[o+a]!==e[o+r])throw new Error(i+" updates.shape["+(o+a)+"] ("+n.shape[o+a]+") != shape["+(o+a)+"] ("+e[o+a]+")")}function zn(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)}On(n,t,e)}function qn(e,t,n){for(var r=t.shape.length,a=r>1?t.shape[r-1]:1,i=n.length,o=1,s=a;s<i;++s)o*=n[s];var u=a<1?1:a;return{sliceRank:a,numUpdates:v(t.shape)/u,sliceSize:o,strides:C(n.slice(0,a)).concat([1]),outputSize:v(n)}}var Kn={__proto__:null,validateUpdateShape:On,validateInput:zn,calculateShapes:qn};function Wn(e){for(var t=[],n=0;e>0;)1&e&&t.push(n),e/=2,n++;return t}function Un(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 Gn(e,t,n,r){for(var a=e.slice(),i=a.length;i<r.length;i++)a.push(1);for(i=0;i<n;i++)0===i?a[t]=1:(a.splice(t,0,1),a.pop());return a}function Vn(e,t,n){return n<=e?n:n-(t-1)}function Hn(e,t){for(var n=[],r=0;r<e;r++)n.push(t+r);return n}function jn(e,t,n,r,a,i,o,s,u){var l=e.length,c=new Array(l),h=new Array(l),f=new Array(l);if(t.length&&n>0){var d=t[0],p=n+1;c=Jn(o,d,p,r,e),h=Zn(s,d,p,a,e),f=Gn(i,d,p,e)}else for(var v=0;v<l;v++)c[v]=Xn(o,r,i,e,v,u),h[v]=$n(s,a,i,e,v,u),f[v]=Yn(i,v,u);return{begin:c,end:h,strides:f}}function Jn(e,t,n,r,a){for(var i=a.slice(),o=Hn(n,t),s=0;s<i.length;s++)if(o.indexOf(s)>-1)i[s]=0;else{var u=Vn(t,n,s),l=r[u];e&1<<u&&(l=0),i[s]=l}return i}function Zn(e,t,n,r,a){for(var i=a.slice(),o=Hn(n,t),s=0;s<i.length;s++)if(o.indexOf(s)>-1)i[s]=Number.MAX_SAFE_INTEGER;else{var u=Vn(t,n,s),c=r[u];e&1<<u&&(c=Number.MAX_SAFE_INTEGER),i[s]=c}for(var h=0;h<i.length;h++){var f=a[h];i[h]<0&&(i[h]+=f),i[h]=l(0,i[h],a[h])}return i}function Yn(e,t,n){var r=e[t];return(n&1<<t||null==r)&&(r=1),r}function Xn(e,t,n,r,a,i){var o=t[a],s=n[a]||1;(e&1<<a||i&1<<a||null==o)&&(o=s>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var u=r[a];return o<0&&(o+=u),o=l(0,o,u-1)}function $n(e,t,n,r,a,i){var o=t[a],s=n[a]||1;(e&1<<a||i&1<<a||null==o)&&(o=s>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var u=r[a];return o<0&&(o+=u),o=s>0?l(0,o,u):l(-1,o,u-1)}var Qn={__proto__:null,assertParamsValid:function(e,t,n){var r=e.shape.length;h(r===t.length,(function(){return"Error in slice"+r+"D: Length of begin "+t+" must match the rank of the array ("+r+")."})),h(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){h(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]+")"}))},i=0;i<r;++i)a(i)},maskToAxes:Wn,computeOutShape:Un,stridesWithElidedDims:Gn,getNormalizedAxes:jn,startIndicesWithElidedDims:Jn,stopIndicesWithElidedDims:Zn,stridesForAxis:Yn,startForAxis:Xn,stopForAxis:$n,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,i=e.shape.length;return(r="number"==typeof t?[t].concat(new Array(i-1).fill(0)):t.length<i?t.concat(new Array(i-t.length).fill(0)):t.slice()).forEach((function(e){h(-1!==e,(function(){return"slice() does not support negative begin indexing."}))})),a=(a=null==n?new Array(i).fill(-1):"number"==typeof n?[n].concat(new Array(i-1).fill(-1)):n.length<i?n.concat(new Array(i-n.length).fill(-1)):n).map((function(t,n){return t>=0?t:(h(-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,i,o,s,u){var l=t.slice(),c=n.slice(),h=r;null==r&&(h=new Array(l.length));var f=Wn(o);if(f.length>1)throw new Error("Multiple ellipses in slice is not allowed.");if(0!==o&&0!==s)throw new Error("Using both ellipsisMask and newAxisMask is not yet supported.");if(0!==o&&0!==u)throw new Error("Using both ellipsisMask and shrinkAxisMask is not yet supported.");var d=e.length-l.length,p=Wn(s),v=e.slice();p.forEach((function(e){l[e]=0,c[e]=1,v.splice(e,0,1)}));var g=jn(v,f,d,l,c,h,a,i,o),m=g.begin,b=g.end,y=g.strides;l=m,c=b,h=y;var w=Wn(u);w.forEach((function(e){c[e]=l[e]+1,h[e]=1}));var k=Un(l,c,h),x=k.filter((function(e,t){return-1===w.indexOf(t)}));return{nonStrided:h.every((function(e){return 1===e})),$begin:l,$end:c,$strides:h,size:k,newShape:v,outShape:x}}},er=function(){function e(){}return e.prototype.getClassName=function(){return this.constructor.className},e.fromConfig=function(e,t){return new e(t)},e}(),tr=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 nr(e){h(null!=e.className,(function(){return"Class being registered does not have the static className property defined."})),h("string"==typeof e.className,(function(){return"className is required to be a string, but got type "+typeof e.className})),h(e.className.length>0,(function(){return"Class being registered has an empty-string as its className, which is disallowed."})),tr.register(e)}var rr={__proto__:null,Serializable:er,SerializationMap:tr,registerClass:nr};function ar(){return 32===pt.backend.floatPrecision()?.001:.1}function ir(e,t,n){var r=!0;if((A(e)||A(t))&&(r=!1),A(e)&&A(t)&&(r=!0),r){var a=e.constructor.name,i=t.constructor.name;if(a!==i)throw new Error("Arrays are of different type. Actual: "+a+". Expected: "+i)}if(Array.isArray(e)&&Array.isArray(t)){var o=yt(e),s=yt(t);if(!g(o,s))throw new Error("Arrays have different shapes. Actual: ["+o+"]. Expected: ["+s+"]")}var u=A(e)?e:p(e),l=A(t)?t:p(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 h=u[c],f=l[c];if(!n(h,f))throw new Error("Arrays differ: actual["+c+"] = "+h+", expected["+c+"] = "+f+".\nActual:   "+u+".\nExpected: "+l+".")}}function or(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}var sr={__proto__:null,TEST_EPSILON_FLOAT16:.1,expectArraysClose:function(e,t,n){return null==n&&(n=ar()),ir(e,t,(function(e,t){return or(e,t,n)}))},testEpsilon:ar,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 M(e)||M(e[0])||M(t)||M(t[0])?ir(e,n,(function(e,t){return e==t})):ir(e,t,(function(e,t){return or(e,t,0)}))},expectNumbersClose:function(e,t,n){if(null==n&&(n=ar()),!or(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]=ze(r)}return t}};function ur(e,t){return pt.tidy(e,t)}function lr(e){ut(e).forEach((function(e){return e.dispose()}))}function cr(e){return pt.keep(e)}var hr=Et({add_:function(e,t){var n,r=kt(e,"a","add"),a=kt(t,"b","add"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Add",i)}});var fr=Et({floorDiv_:function(e,t){var n,r=kt(e,"a","floorDiv"),a=kt(t,"b","floorDiv"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("FloorDiv",i)}});var dr=Et({div_:function(e,t){var n,r=kt(e,"a","div"),a=kt(t,"b","div");if(r=(n=ot(r,a))[0],a=n[1],"int32"===r.dtype&&"int32"===a.dtype)return fr(r,a);var i={a:r,b:a};return pt.runKernel("RealDiv",i,{})}});var pr=Et({mul_:function(e,t){var n,r=kt(e,"a","mul"),a=kt(t,"b","mul"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Multiply",i)}});var vr=Et({abs_:function(e){var t=kt(e,"x","abs");if("complex64"===t.dtype){var n={x:t};return pt.runKernel("ComplexAbs",n)}return n={x:t},pt.runKernel("Abs",n)}});var gr=Et({acos_:function(e){var t={x:kt(e,"x","acos")};return pt.runKernel("Acos",t)}});var mr=Et({acosh_:function(e){var t={x:kt(e,"x","acosh")};return pt.runKernel("Acosh",t)}});var br=Et({addN_:function(e){h(Array.isArray(e),(function(){return"The argument passed to tf.addN() must be a list of tensors"})),h(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 kt(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(!g(e.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")}));var r=t;return pt.runKernel("AddN",r)}});var yr=Et({all_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:kt(e,"x","all","bool")},a={axis:t,keepDims:n};return pt.runKernel("All",r,a)}});var wr=Et({any_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:kt(e,"x","any","bool")},a={axis:t,keepDims:n};return pt.runKernel("Any",r,a)}});var kr=Et({argMax_:function(e,t){void 0===t&&(t=0);var n={x:kt(e,"x","argMax")},r={axis:t};return pt.runKernel("ArgMax",n,r)}});var xr=Et({argMin_:function(e,t){void 0===t&&(t=0);var n={x:kt(e,"x","argMin")},r={axis:t};return pt.runKernel("ArgMin",n,r)}});var Er=Et({asin_:function(e){var t={x:kt(e,"x","asin")};return pt.runKernel("Asin",t)}});var Sr=Et({asinh_:function(e){var t={x:kt(e,"x","asinh")};return pt.runKernel("Asinh",t)}});var Ar=Et({atan_:function(e){var t={x:kt(e,"x","atan")};return pt.runKernel("Atan",t)}});var _r=Et({atan2_:function(e,t){var n,r=kt(e,"a","atan2"),a=kt(t,"b","atan2"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Atan2",i)}});var Nr=Et({atanh_:function(e){var t={x:kt(e,"x","atanh")};return pt.runKernel("Atanh",t)}});function Mr(e,t,n,r,a,i,o){void 0===o&&(o="channelsLast");var s,u=Rr(t),l=u[0],c=u[1];if("channelsLast"===o)s=[l,c,e[3],e[3]];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);s=[l,c,e[1],e[1]]}return Ir(e,s,n,r,a,i,!1,o)}function Ir(e,t,n,r,a,i,o,s){void 0===o&&(o=!1),void 0===s&&(s="channelsLast");var u=[-1,-1,-1,-1],l=u[0],c=u[1],h=u[2],f=u[3];if("channelsLast"===s)l=e[0],c=e[1],h=e[2],f=e[3];else{if("channelsFirst"!==s)throw new Error("Unknown dataFormat "+s);l=e[0],f=e[1],c=e[2],h=e[3]}var d,p=t[0],v=t[1],g=t[3],m=Rr(n),b=m[0],y=m[1],w=Rr(r),k=w[0],x=w[1],E=Cr(p,k),S=Cr(v,x),A=function(e,t,n,r,a,i,o,s,u){var l,c,h;if("number"==typeof e){l={top:e,bottom:e,left:e,right:e,type:0===e?"VALID":"NUMBER"};var f=function(e,t,n,r,a){null==r&&(r=Dr(e,t,n));var i=e[0],o=e[1],s=Br((i-t+2*r)/n+1,a),u=Br((o-t+2*r)/n+1,a);return[s,u]}([t,n],i,r,e,s);c=f[0],h=f[1]}else if("same"===e){c=Math.ceil(t/r),h=Math.ceil(n/a);var d=Math.max(0,(c-1)*r+i-t),p=Math.max(0,(h-1)*a+o-n),v=Math.floor(d/2),g=d-v,m=Math.floor(p/2);l={top:v,bottom:g,left:m,right:y=p-m,type:"SAME"}}else if("valid"===e)l={top:0,bottom:0,left:0,right:0,type:"VALID"},c=Math.ceil((t-i+1)/r),h=Math.ceil((n-o+1)/a);else{if("object"!=typeof e)throw Error("Unknown padding parameter: "+e);var b="channelsLast"===u?e[1][0]:e[2][0],y=(g="channelsLast"===u?e[1][1]:e[2][1],m="channelsLast"===u?e[2][0]:e[3][0],"channelsLast"===u?e[2][1]:e[3][1]);l={top:b,bottom:g,left:m,right:y,type:0===b&&0===g&&0===m&&0===y?"VALID":"EXPLICIT"},c=Br((t-i+b+g)/r+1,s),h=Br((n-o+m+y)/a+1,s)}return{padInfo:l,outHeight:c,outWidth:h}}(a,c,h,b,y,E,S,i,s),_=A.padInfo,N=A.outHeight,M=A.outWidth,I=o?g*f:g;return"channelsFirst"===s?d=[l,I,N,M]:"channelsLast"===s&&(d=[l,N,M,I]),{batchSize:l,dataFormat:s,inHeight:c,inWidth:h,inChannels:f,outHeight:N,outWidth:M,outChannels:I,padInfo:_,strideHeight:b,strideWidth:y,filterHeight:p,filterWidth:v,effectiveFilterHeight:E,effectiveFilterWidth:S,dilationHeight:k,dilationWidth:x,inShape:e,outShape:d,filterShape:t}}function Tr(e,t,n,r,a,i,o,s){void 0===i&&(i=!1),void 0===o&&(o="channelsLast");var u=[-1,-1,-1,-1,-1],l=u[0],c=u[1],h=u[2],f=u[3],d=u[4];if("channelsLast"===o)l=e[0],c=e[1],h=e[2],f=e[3],d=e[4];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);l=e[0],d=e[1],c=e[2],h=e[3],f=e[4]}var p,v=t[0],g=t[1],m=t[2],b=t[4],y=Fr(n),w=y[0],k=y[1],x=y[2],E=Fr(r),S=E[0],A=E[1],_=E[2],N=Cr(v,S),M=Cr(g,A),I=Cr(m,_),T=function(e,t,n,r,a,i,o,s,u,l,c){var h,f,d,p;if("number"==typeof e){h={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,i){null==a&&(a=Dr(e,t,r));var o=e[0],s=e[1],u=e[2],l=Br((o-t+2*a)/r+1,i),c=Br((s-t+2*a)/r+1,i),h=Br((u-t+2*a)/r+1,i);return[l,c,h,n]}([t,n,r,1],s,1,a,e,c);f=v[0],d=v[1],p=v[2]}else if("same"===e){f=Math.ceil(t/a),d=Math.ceil(n/i),p=Math.ceil(r/o);var g=(f-1)*a+s-t,m=(d-1)*i+u-n,b=(p-1)*o+l-r,y=Math.floor(g/2),w=g-y,k=Math.floor(m/2),x=m-k,E=Math.floor(b/2);h={top:k,bottom:x,left:E,right:b-E,front:y,back:w,type:"SAME"}}else{if("valid"!==e)throw Error("Unknown padding parameter: "+e);h={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},f=Math.ceil((t-s+1)/a),d=Math.ceil((n-u+1)/i),p=Math.ceil((r-l+1)/o)}return{padInfo:h,outDepth:f,outHeight:d,outWidth:p}}(a,c,h,f,w,k,x,N,M,I,s),D=T.padInfo,R=T.outDepth,F=T.outHeight,C=T.outWidth,B=i?b*d:b;return"channelsFirst"===o?p=[l,B,R,F,C]:"channelsLast"===o&&(p=[l,R,F,C,B]),{batchSize:l,dataFormat:o,inDepth:c,inHeight:h,inWidth:f,inChannels:d,outDepth:R,outHeight:F,outWidth:C,outChannels:B,padInfo:D,strideDepth:w,strideHeight:k,strideWidth:x,filterDepth:v,filterHeight:g,filterWidth:m,effectiveFilterDepth:N,effectiveFilterHeight:M,effectiveFilterWidth:I,dilationDepth:S,dilationHeight:A,dilationWidth:_,inShape:e,outShape:p,filterShape:t}}function Dr(e,t,n,r){void 0===r&&(r=1);var a=Cr(t,r);return Math.floor((e[0]*(n-1)-n+a)/2)}function Rr(e){return"number"==typeof e?[e,e,e]:2===e.length?[e[0],e[1],1]:e}function Fr(e){return"number"==typeof e?[e,e,e]:e}function Cr(e,t){return t<=1?e:e+(e-1)*(t-1)}function Br(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 Pr(e){var t=Rr(e),n=t[0],r=t[1],a=t[2];return 1===n&&1===r&&1===a}function Lr(e,t){return Pr(e)||Pr(t)}function Or(e){if("NHWC"===e)return"channelsLast";if("NCHW"===e)return"channelsFirst";throw new Error("Unknown dataFormat "+e)}var zr=Et({reshape_:function(e,t){var n={x:kt(e,"x","reshape","string_or_numeric")},r={shape:t};return pt.runKernel("Reshape",n,r)}});var qr=Et({avgPool_:function(e,t,n,r,a){var i=kt(e,"x","avgPool","float32");h(Lr(n,1),(function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '1'"}));var o=i,s=!1;3===i.rank&&(s=!0,o=zr(i,[1,i.shape[0],i.shape[1],i.shape[2]])),h(4===o.rank,(function(){return"Error in avgPool: x must be rank 4 but got rank "+o.rank+"."})),null!=a&&h(m(r),(function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var u={x:o},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a},c=pt.runKernel("AvgPool",u,l);return c=hn(c,i.dtype),s?zr(c,[c.shape[1],c.shape[2],c.shape[3]]):c}});var Kr=Et({avgPool3d_:function(e,t,n,r,a,i){void 0===i&&(i="NDHWC");var o=kt(e,"x","avgPool3d","float32"),s=o,u=!1;4===o.rank&&(u=!0,s=zr(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),h(5===s.rank,(function(){return"Error in avgPool3d: x must be rank 5 but got rank "+s.rank+"."})),h("NDHWC"===i,(function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+i})),null!=a&&h(m(r),(function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var l={x:s},c={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:i},f=pt.runKernel("AvgPool3D",l,c);return f=hn(f,s.dtype),u?zr(f,[f.shape[1],f.shape[2],f.shape[3],f.shape[4]]):f}});var Wr=Et({concat_:function(e,t){void 0===t&&(t=0),h(e.length>=1,(function(){return"Pass at least one tensor to concat"}));var n=xt(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 fn(n[0]);var r=n,a={axis:t};return pt.runKernel("Concat",r,a)}});var Ur=Et({sigmoid_:function(e){var t={x:kt(e,"x","sigmoid")};return pt.runKernel("Sigmoid",t)}});var Gr=Et({slice_:function(e,t,n){var r=kt(e,"x","slice","string_or_numeric");if(0===r.rank)throw new Error("Slicing scalar is not possible");var a={x:r},i={begin:t,size:n};return pt.runKernel("Slice",a,i)}});var Vr=Et({tanh_:function(e){var t={x:kt(e,"x","tanh")};return pt.runKernel("Tanh",t)}});var Hr=Et({basicLSTMCell_:function(e,t,n,r,a,i){var o=kt(e,"forgetBias","basicLSTMCell"),s=kt(t,"lstmKernel","basicLSTMCell"),u=kt(n,"lstmBias","basicLSTMCell"),l=kt(r,"data","basicLSTMCell"),c=kt(a,"c","basicLSTMCell"),h=kt(i,"h","basicLSTMCell"),f=Wr([l,h],1),d=Nn(f,s),p=hr(d,u),v=p.shape[0],g=p.shape[1]/4,m=[v,g],b=Gr(p,[0,0],m),y=Gr(p,[0,g],m),w=Gr(p,[0,2*g],m),k=Gr(p,[0,3*g],m),x=hr(pr(Ur(b),Vr(y)),pr(c,Ur(hr(o,w))));return[x,pr(Vr(x),Ur(k))]}});var jr=Et({batchToSpaceND_:function(e,t,n){var r=kt(e,"x","batchToSpaceND"),a=t.reduce((function(e,t){return e*t}));h(r.rank>=1+t.length,(function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+t.length})),h(n.length===t.length,(function(){return"crops.length is "+n.length+" but should be equal to blockShape.length  "+t.length})),h(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 i={x:r},o={blockShape:t,crops:n};return pt.runKernel("BatchToSpaceND",i,o)}});var Jr=Et({batchNorm_:function(e,t,n,r,a,i){null==i&&(i=.001);var o,s,u=kt(e,"x","batchNorm"),l=kt(t,"mean","batchNorm"),c=kt(n,"variance","batchNorm");null!=a&&(o=kt(a,"scale","batchNorm")),null!=r&&(s=kt(r,"offset","batchNorm")),h(l.rank===c.rank,(function(){return"Batch normalization gradient requires mean and variance to have equal ranks."})),h(null==s||l.rank===s.rank,(function(){return"Batch normalization gradient requires mean and offset to have equal ranks."})),h(null==o||l.rank===o.rank,(function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}));var f={x:function(e){return 0===e.rank||1===e.rank?zr(e,[1,1,1,e.size]):2===e.rank?zr(e,[1,1,e.shape[0],e.shape[1]]):3===e.rank?zr(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e}(u),scale:o,offset:s,mean:l,variance:c},d={varianceEpsilon:i},p=pt.runKernel("FusedBatchNorm",f,d);return zr(p,u.shape)}});var Zr=Et({batchNorm2d_:function(e,t,n,r,a,i){var o,s,u=kt(e,"x","batchNorm"),l=kt(t,"mean","batchNorm"),c=kt(n,"variance","batchNorm");return null!=a&&(o=kt(a,"scale","batchNorm")),null!=r&&(s=kt(r,"offset","batchNorm")),h(2===u.rank,(function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+u.rank+"."})),h(2===l.rank||1===l.rank,(function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+l.rank+"."})),h(2===c.rank||1===c.rank,(function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+c.rank+"."})),null!=o&&h(2===o.rank||1===o.rank,(function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+o.rank+"."})),null!=s&&h(2===s.rank||1===s.rank,(function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+s.rank+"."})),Jr(u,l,c,s,o,i)}});var Yr=Et({batchNorm3d_:function(e,t,n,r,a,i){var o,s,u=kt(e,"x","batchNorm"),l=kt(t,"mean","batchNorm"),c=kt(n,"variance","batchNorm");return null!=a&&(o=kt(a,"scale","batchNorm")),null!=r&&(s=kt(r,"offset","batchNorm")),h(3===u.rank,(function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."})),h(3===l.rank||1===l.rank,(function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+l.rank+"."})),h(3===c.rank||1===c.rank,(function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+c.rank+"."})),null!=o&&h(3===o.rank||1===o.rank,(function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+o.rank+"."})),null!=s&&h(3===s.rank||1===s.rank,(function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+s.rank+"."})),Jr(u,l,c,s,o,i)}});var Xr=Et({batchNorm4d_:function(e,t,n,r,a,i){var o,s,u=kt(e,"x","batchNorm"),l=kt(t,"mean","batchNorm"),c=kt(n,"variance","batchNorm");return null!=a&&(o=kt(a,"scale","batchNorm")),null!=r&&(s=kt(r,"offset","batchNorm")),h(4===u.rank,(function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+u.rank+"."})),h(4===l.rank||1===l.rank,(function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+l.rank+"."})),h(4===c.rank||1===c.rank,(function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+c.rank+"."})),null!=o&&h(4===o.rank||1===o.rank,(function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+o.rank+"."})),null!=s&&h(4===s.rank||1===s.rank,(function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+s.rank+"."})),Jr(u,l,c,s,o,i)}});var $r=Et({bincount_:function(e,t,n){var r=kt(e,"x","bincount"),a=kt(t,"weights","bincount");h("int32"===r.dtype,(function(){return"Error in bincount: input dtype must be int32, but got "+r.dtype})),h(n>=0,(function(){return"size must be non-negative, but got "+n+"."})),h(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 i={x:r,weights:a},o={size:n};return pt.runKernel("Bincount",i,o)}});var Qr=Et({broadcastTo_:function(e,t){var n=kt(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=zr(n,a)}for(var i=n.shape,o=Array.from(t),s=t.length-1;s>=0;s--)if(i[s]===t[s])o[s]=1;else if(1!==n.shape[s])throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+t+"].");if(0===o.map((function(e,t){return e>1?t:-1})).filter((function(e){return e>=0})).length)return fn(n);var u={x:n},l={reps:o};return pt.runKernel("Tile",u,l)}});var ea=Et({ceil_:function(e){var t={x:kt(e,"x","ceil")};return pt.runKernel("Ceil",t)}});var ta=Et({clipByValue_:function(e,t,n){var r=kt(e,"x","clipByValue");h(t<=n,(function(){return"Error in clip: min ("+t+") must be less than or equal to max ("+n+")."}));var a={x:r},i={clipValueMin:t,clipValueMax:n};return pt.runKernel("ClipByValue",a,i)}});var na=Et({concat1d_:function(e){return Wr(e,0)}});var ra=Et({concat2d_:function(e,t){return Wr(e,t)}});var aa=Et({concat3d_:function(e,t){return Wr(e,t)}});var ia=Et({concat4d_:function(e,t){return Wr(e,t)}});var oa=Et({conv2d_:function(e,t,n,r,a,i,o){void 0===a&&(a="NHWC"),void 0===i&&(i=[1,1]);var s=kt(e,"x","conv2d"),u=kt(t,"filter","conv2d"),l=s,c=!1;3===s.rank&&(c=!0,l=zr(s,[1,s.shape[0],s.shape[1],s.shape[2]])),h(4===l.rank,(function(){return"Error in conv2d: input must be rank 4, but got rank "+l.rank+"."})),h(4===u.rank,(function(){return"Error in conv2d: filter must be rank 4, but got rank "+u.rank+"."})),null!=o&&h(m(r),(function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."}));var f="NHWC"===a?l.shape[3]:l.shape[1];h(f===u.shape[2],(function(){return"Error in conv2d: depth of input ("+f+") must match input depth for filter "+u.shape[2]+"."})),h(Lr(n,i),(function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+i+"'"}));var d={x:l,filter:u},p={strides:n,pad:r,dataFormat:a,dilations:i,dimRoundingMode:o},v=pt.runKernel("Conv2D",d,p);return c?zr(v,[v.shape[1],v.shape[2],v.shape[3]]):v}});var sa=Et({conv1d_:function(e,t,n,r,a,i,o){void 0===a&&(a="NWC"),void 0===i&&(i=1);var s=kt(e,"x","conv1d"),u=kt(t,"filter","conv1d"),l=s,c=!1;2===s.rank&&(c=!0,l=zr(s,[1,s.shape[0],s.shape[1]])),h(3===l.rank,(function(){return"Error in conv1d: input must be rank 3, but got rank "+l.rank+"."})),h(3===u.rank,(function(){return"Error in conv1d: filter must be rank 3, but got rank "+u.rank+"."})),null!=o&&h(m(r),(function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."})),h(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]+"."})),h(Lr(n,i),(function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+n+" and dilation '"+i+"'"})),h("NWC"===a,(function(){return"Error in conv1d: got dataFormat of "+a+" but only NWC is currently supported."}));var f=zr(u,[1,u.shape[0],u.shape[1],u.shape[2]]),d=zr(l,[l.shape[0],1,l.shape[1],l.shape[2]]),p=oa(d,f,[1,n],r,"NHWC",[1,i],o);return zr(p,c?[p.shape[2],p.shape[3]]:[p.shape[0],p.shape[2],p.shape[3]])}});var ua=Et({conv2DBackpropInput_:function(e,t,n,r,a,i,o){void 0===i&&(i="NHWC"),h(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=zr(t,[1,t.shape[0],t.shape[1],t.shape[2]]),s=[1,e[0],e[1],e[2]]),h(4===s.length,(function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+s.length+"."})),h(4===u.rank,(function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+u.rank})),h(4===n.rank,(function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+n.rank}));var c="NHWC"===i?s[3]:s[1],f="NHWC"===i?u.shape[3]:u.shape[1];h(c===n.shape[2],(function(){return"Error in conv2dDerInput: depth of input ("+c+") must match input depth for filter "+n.shape[2]+"."})),h(f===n.shape[3],(function(){return"Error in conv2dDerInput: depth of output ("+f+") must match output depth for filter "+n.shape[3]+"."})),null!=o&&h(m(a),(function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+a+"."}));var d={dy:u,filter:n},p={strides:r,pad:a,dataFormat:i,dimRoundingMode:o,inputShape:s},v=pt.runKernel("Conv2DBackpropInput",d,p);return l?zr(v,[v.shape[1],v.shape[2],v.shape[3]]):v}});var la=Et({conv2dTranspose_:function(e,t,n,r,a,i){var o=kt(e,"x","conv2dTranspose"),s=kt(t,"filter","conv2dTranspose");return ua(n,o,s,r,a,"NHWC",i)}});var ca=Et({conv3d_:function(e,t,n,r,a,i){void 0===a&&(a="NDHWC"),void 0===i&&(i=[1,1,1]);var o=kt(e,"x","conv3d"),s=kt(t,"filter","conv3d"),u=o,l=!1;4===o.rank&&(l=!0,u=zr(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),h(5===u.rank,(function(){return"Error in conv3d: input must be rank 5, but got rank "+u.rank+"."})),h(5===s.rank,(function(){return"Error in conv3d: filter must be rank 5, but got rank "+s.rank+"."})),h(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]+"."})),h(Lr(n,i),(function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+i+"'"})),h("NDHWC"===a,(function(){return"Error in conv3d: got dataFormat of "+a+" but only NDHWC is currently supported."}));var c={x:u,filter:s},f={strides:n,pad:r,dataFormat:a,dilations:i},d=pt.runKernel("Conv3D",c,f);return l?zr(d,[d.shape[1],d.shape[2],d.shape[3],d.shape[4]]):d}});var ha=Et({conv3DBackpropInput_:function(e,t,n,r,a){h(e.length===t.rank,(function(){return"Length of inShape ("+e.length+") and rank of dy ("+t.rank+") must match"}));var i=e,o=t,s=!1;4===t.rank&&(s=!0,o=zr(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]]),i=[1,e[0],e[1],e[2],e[3]]);var u=i[4],l=o.shape[4];h(5===i.length,(function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+i.length+"."})),h(5===o.rank,(function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+o.rank})),h(5===n.rank,(function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+n.rank})),h(u===n.shape[3],(function(){return"Error in conv3dDerInput: depth of input ("+u+") must match input depth for filter "+n.shape[3]+"."})),h(l===n.shape[4],(function(){return"Error in conv3dDerInput: depth of output ("+l+") must match output depth for filter "+n.shape[4]+"."}));var c={dy:o,filter:n},f={pad:a,strides:r,inputShape:i},d=pt.runKernel("Conv3DBackpropInputV2",c,f);return s?zr(d,[d.shape[1],d.shape[2],d.shape[3],d.shape[4]]):d}});var fa=Et({conv3dTranspose_:function(e,t,n,r,a){var i=kt(e,"x","conv3dTranspose"),o=kt(t,"filter","conv3dTranspose");return ha(n,i,o,r,a)}});var da=Et({cos_:function(e){var t={x:kt(e,"x","cos")};return pt.runKernel("Cos",t)}});var pa=Et({cosh_:function(e){var t={x:kt(e,"x","cosh")};return pt.runKernel("Cosh",t)}});var va=Et({cumsum_:function(e,t,n,r){void 0===t&&(t=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var a={x:kt(e,"x","cumsum")},i={axis:t,exclusive:n,reverse:r};return pt.runKernel("Cumsum",a,i)}});var ga=Et({denseBincount_:function(e,t,n,r){void 0===r&&(r=!1);var a=kt(e,"x","denseBincount"),i=kt(t,"weights","denseBincount");h("int32"===a.dtype,(function(){return"Error in denseBincount: input dtype must be int32, but got "+a.dtype})),h(a.rank<=2,(function(){return"Error in denseBincount: input must be at most rank 2, but got rank "+a.rank+"."})),h(n>=0,(function(){return"size must be non-negative, but got "+n+"."})),h(i.size===a.size||0===i.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: "+i.shape+"."}));var o={x:a,weights:i},s={size:n,binaryOutput:r};return pt.runKernel("DenseBincount",o,s)}});var ma=Et({depthToSpace_:function(e,t,n){void 0===n&&(n="NHWC");var r=kt(e,"x","depthToSpace"),a="NHWC"===n?r.shape[1]:r.shape[2],i="NHWC"===n?r.shape[2]:r.shape[3],o="NHWC"===n?r.shape[3]:r.shape[1];h(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})),h(i*t>=0,(function(){return"Negative dimension size caused by overflow when multiplying\n    "+i+" and "+t+" for depthToSpace with input shape\n        "+r.shape})),h(o%(t*t)==0,(function(){return"Dimension size must be evenly divisible by "+t*t+" but is "+o+" for depthToSpace with input shape "+r.shape}));var s={x:r},u={blockSize:t,dataFormat:n};return pt.runKernel("DepthToSpace",s,u)}});var ba=Et({depthwiseConv2d_:function(e,t,n,r,a,i,o){void 0===a&&(a="NHWC"),void 0===i&&(i=[1,1]);var s=kt(e,"x","depthwiseConv2d"),u=kt(t,"filter","depthwiseConv2d"),l=s,c=!1;3===s.rank&&(c=!0,l=zr(s,[1,s.shape[0],s.shape[1],s.shape[2]])),h(4===l.rank,(function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+l.rank+"."})),h(4===u.rank,(function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+u.rank+"."})),h(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!=o&&h(m(r),(function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."}));var f={x:l,filter:u},d={strides:n,pad:r,dataFormat:a,dilations:i,dimRoundingMode:o},p=pt.runKernel("DepthwiseConv2dNative",f,d);return c?zr(p,[p.shape[1],p.shape[2],p.shape[3]]):p}});var ya=Et({diag_:function(e){var t={x:kt(e,"x","diag")};return pt.runKernel("Diag",t)}});var wa=Et({dilation2d_:function(e,t,n,r,a,i){void 0===a&&(a=[1,1]),void 0===i&&(i="NHWC");var o=kt(e,"x","dilation2d"),s=kt(t,"filter","dilation2d");h(3===o.rank||4===o.rank,(function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+o.rank+"."})),h(3===s.rank,(function(){return"Error in dilation2d: filter must be rank 3, but got rank "+s.rank+"."})),h("NHWC"===i,(function(){return"Error in dilation2d: Only NHWC is currently supported, but got dataFormat of "+i}));var u=o,l=!1;3===o.rank&&(u=zr(o,[1,o.shape[0],o.shape[1],o.shape[2]]),l=!0);var c={x:u,filter:s},f={strides:n,pad:r,dilations:a},d=pt.runKernel("Dilation2D",c,f);return l?zr(d,[d.shape[1],d.shape[2],d.shape[3]]):d}});function ka(e,t){for(var n=[],r=0;r<t.length;r++){var a=e[e.length-r-1],i=t.length-r-1,o=t[i];(null==a||1===a&&o>1)&&n.unshift(i)}return n}function xa(e,t){for(var n=[],r=Math.max(e.length,t.length),a=0;a<r;a++){var i=e[e.length-a-1];null==i&&(i=1);var o=t[t.length-a-1];if(null==o&&(o=1),1===i)n.unshift(o);else if(1===o)n.unshift(i);else{if(i!==o)throw Error("Operands could not be broadcast together with shapes "+e+" and "+t+".");n.unshift(i)}}return n}var Ea=Et({equal_:function(e,t){var n,r=kt(e,"a","equal","string_or_numeric"),a=kt(t,"b","equal","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("Equal",i)}});var Sa=Et({where_:function(e,t,n){var r=kt(t,"a","where"),a=kt(n,"b","where"),i=kt(e,"condition","where","bool"),o=xa(xa(i.shape,r.shape),a.shape),s={condition:Qr(i,o),t:Qr(r,o),e:Qr(a,o)};return pt.runKernel("Select",s)}});var Aa=Et({zerosLike_:function(e){var t={x:kt(e,"x","zerosLike")};return pt.runKernel("ZerosLike",t)}});var _a=Et({divNoNan_:function(e,t){var n,r=kt(e,"a","div"),a=kt(t,"b","div");r=(n=ot(r,a))[0],a=n[1];var i=dr(r,a),o=Aa(i),s=Ea(a,o);return Sa(s,o,i)}});var Na=Et({dot_:function(e,t){var n=kt(e,"t1","dot"),r=kt(t,"t2","dot");h(!(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],i=1===r.rank?r.size:r.shape[0];if(h(a===i,(function(){return"Error in dot: inner dimensions of inputs must match, but got "+a+" and "+i+"."})),1===n.rank&&1===r.rank){var o=zr(n,[1,-1]),s=zr(r,[-1,1]),u=Nn(o,s);return zr(u,[])}if(1===n.rank&&2===r.rank){o=zr(n,[1,-1]),s=zr(r,[r.shape[0],r.shape[1]]),u=Nn(o,s);return zr(u,[u.size])}if(2===n.rank&&1===r.rank){s=zr(r,[-1,1]),u=Nn(n,s);return zr(u,[u.size])}return s=zr(r,[r.shape[0],r.shape[1]]),u=Nn(n,s)}});var Ma=Et({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 kt(e,"tensors"+t,"einsum")})),a={equation:e};return pt.runKernel("Einsum",r,a)}});var Ia=Et({elu_:function(e){var t={x:kt(e,"x","elu")};return pt.runKernel("Elu",t)}});var Ta=Et({erf_:function(e){var t=kt(e,"x","erf");h("int32"===t.dtype||"float32"===t.dtype,(function(){return"Input dtype must be `int32` or `float32`."})),"int32"===t.dtype&&(t=hn(t,"float32"));var n={x:t};return pt.runKernel("Erf",n)}});var Da=Et({exp_:function(e){var t={x:kt(e,"x","exp")};return pt.runKernel("Exp",t)}});var Ra=Et({expandDims_:function(e,t){void 0===t&&(t=0);var n=kt(e,"x","expandDims","string_or_numeric");h(t<=n.rank,(function(){return"Axis must be <= rank of the tensor"}));var r={input:n},a={dim:t};return pt.runKernel("ExpandDims",r,a)}});var Fa=Et({expm1_:function(e){var t={x:kt(e,"x","expm1")};return pt.runKernel("Expm1",t)}});var Ca=Et({tile_:function(e,t){var n=kt(e,"x","tile","string_or_numeric");h(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 pt.runKernel("Tile",r,a)}});var Ba=Et({eye_:function(e,t,n,r){void 0===r&&(r="float32"),null==t&&(t=e);for(var a=cn([e,t],r),i=e<=t?e:t,o=0;o<i;++o)a.set(1,o,o);var s=zr(a.toTensor(),[e,t]);if(null==n)return s;if(1===n.length)return Ca(Ra(s,0),[n[0],1,1]);if(2===n.length)return Ca(Ra(Ra(s,0),0),[n[0],n[1],1,1]);if(3===n.length)return Ca(Ra(Ra(Ra(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 Pa(e,t,n){var r={shape:e,value:t,dtype:n};return pt.runKernel("Fill",{},r)}var La=Et({floor_:function(e){var t={x:kt(e,"x","floor")};return pt.runKernel("Floor",t)}});var Oa=Et({gather_:function(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var a={x:kt(e,"x","gather"),indices:kt(t,"indices","gather","int32")},i={axis:n,batchDims:r};return pt.runKernel("GatherV2",a,i)}});var za=Et({greater_:function(e,t){var n,r=kt(e,"a","greater","string_or_numeric"),a=kt(t,"b","greater","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("Greater",i)}});var qa=Et({greaterEqual_:function(e,t){var n,r=kt(e,"a","greaterEqual","string_or_numeric"),a=kt(t,"b","greaterEqual","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("GreaterEqual",i)}});var Ka=Et({imag_:function(e){var t={input:kt(e,"input","imag")};return pt.runKernel("Imag",t)}});var Wa=Et({isFinite_:function(e){var t={x:kt(e,"x","isFinite")};return pt.runKernel("IsFinite",t)}});var Ua=Et({isInf_:function(e){var t={x:kt(e,"x","isInf")};return pt.runKernel("IsInf",t)}});var Ga=Et({isNaN_:function(e){var t={x:kt(e,"x","isNaN")};return pt.runKernel("IsNan",t)}});var Va=Et({leakyRelu_:function(e,t){void 0===t&&(t=.2);var n={x:kt(e,"x","leakyRelu")},r={alpha:t};return pt.runKernel("LeakyRelu",n,r)}});var Ha=Et({less_:function(e,t){var n,r=kt(e,"a","less","string_or_numeric"),a=kt(t,"b","less","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("Less",i)}});var ja=Et({lessEqual_:function(e,t){var n,r=kt(e,"a","lessEqual","string_or_numeric"),a=kt(t,"b","lessEqual","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("LessEqual",i)}});var Ja=Et({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 i=kt(e,"x","localResponseNormalization");h(4===i.rank||3===i.rank,(function(){return"Error in localResponseNormalization: x must be rank 3 or 4 but got\n               rank "+i.rank+"."})),h(m(t),(function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+t+"."}));var o=i,s=!1;3===i.rank&&(s=!0,o=zr(i,[1,i.shape[0],i.shape[1],i.shape[2]]));var u={x:o},l={depthRadius:t,bias:n,alpha:r,beta:a},c=pt.runKernel("LRN",u,l);return s?zr(c,[c.shape[1],c.shape[2],c.shape[3]]):c}});var Za=Et({log_:function(e){var t={x:kt(e,"x","log")};return pt.runKernel("Log",t)}});var Ya=Et({log1p_:function(e){var t={x:kt(e,"x","log1p")};return pt.runKernel("Log1p",t)}});function Xa(e,t){h(R(e),(function(){return"The f passed in variableGrads(f) must be a function"})),h(null==t||Array.isArray(t)&&t.every((function(e){return e instanceof rt})),(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=[],pt.registeredVariables)t.push(pt.registeredVariables[r]);var a=n?t.filter((function(e){return!e.trainable})):null,i=t.length;h((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 "+i+" variables is trainable."}));var o=pt.gradients(e,t,null,!0),s=o.value,u=o.grads;h(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()."})),h(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 $a(e){return pt.customGrad(e)}function Qa(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 ei=Et({neg_:function(e){var t={x:kt(e,"x","neg")};return pt.runKernel("Neg",t)}});var ti=Et({softplus_:function(e){var t={x:kt(e,"x","softplus")};return pt.runKernel("Softplus",t)}});var ni=Et({logSigmoid_:function(e){var t=kt(e,"x","logSigmoid");return $a((function(e){return{value:ei(ti(ei(e))),gradFunc:function(t){return pr(t,Ur(ei(e)))}}}))(t)}});var ri=Et({max_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:kt(e,"x","max")},a={reductionIndices:t,keepDims:n};return pt.runKernel("Max",r,a)}});var ai=Et({sub_:function(e,t){var n,r=kt(e,"a","sub"),a=kt(t,"b","sub"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Sub",i)}});var ii=Et({sum_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=kt(e,"x","sum");"bool"===r.dtype&&(r=hn(r,"int32"));var a={x:r},i={axis:t,keepDims:n};return pt.runKernel("Sum",a,i)}});var oi=Et({logSoftmax_:function(e,t){void 0===t&&(t=-1);var n=kt(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 $a((function(e,n){var r=ri(e,t,!0),a=ai(e,r),i=ai(hn(a,"float32"),Za(ii(Da(a),t,!0)));n([i]);return{value:i,gradFunc:function(e,n){var r=n[0],a=Da(r);return ai(e,pr(ii(e,t,!0),a))}}}))(n)}});function si(e,t){for(var n=0;n<e.length;++n)if(e[e.length-n-1]!==t-1-n)return!1;return!0}function ui(e,t,n){for(var r=e.length+t.length,a=[],i=0,o=0,s=0;s<r;s++)-1===n.indexOf(s)?a.push(e[i++]):a.push(t[o++]);return a}function li(e,t){return ui(e,t.map((function(e){return 1})),t)}var ci=Et({logSumExp_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=kt(e,"x","logSumExp"),a=y(t,r.shape),i=ri(r,a,!0),o=ai(r,i),s=Da(o),u=ii(s,a),l=Za(u),c=hr(zr(i,l.shape),l);if(n){var h=li(c.shape,a);return zr(c,h)}return c}});var hi=Et({logicalAnd_:function(e,t){var n=kt(e,"a","logicalAnd","bool"),r=kt(t,"b","logicalAnd","bool");xa(n.shape,r.shape);var a={a:n,b:r};return pt.runKernel("LogicalAnd",a)}});var fi=Et({logicalNot_:function(e){var t={x:kt(e,"x","logicalNot","bool")};return pt.runKernel("LogicalNot",t)}});var di=Et({logicalOr_:function(e,t){var n=kt(e,"a","logicalOr","bool"),r=kt(t,"b","logicalOr","bool");xa(n.shape,r.shape);var a={a:n,b:r};return pt.runKernel("LogicalOr",a)}});var pi=Et({logicalXor_:function(e,t){var n=kt(e,"a","logicalXor","bool"),r=kt(t,"b","logicalXor","bool");return xa(n.shape,r.shape),hi(di(e,t),fi(hi(e,t)))}});var vi=Et({maxPool_:function(e,t,n,r,a){var i=kt(e,"x","maxPool"),o=i,s=!1;3===i.rank&&(s=!0,o=zr(i,[1,i.shape[0],i.shape[1],i.shape[2]])),h(4===o.rank,(function(){return"Error in maxPool: input must be rank 4 but got rank "+o.rank+"."})),h(Lr(n,1),(function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '1'"})),null!=a&&h(m(r),(function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var u={x:o},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a},c=pt.runKernel("MaxPool",u,l);return s?zr(c,[c.shape[1],c.shape[2],c.shape[3]]):c}});var gi=Et({maxPool3d_:function(e,t,n,r,a,i){void 0===t&&(t=[1,1,1]),void 0===i&&(i="NDHWC");var o=kt(e,"x","maxPool3d"),s=o,u=!1;4===o.rank&&(u=!0,s=zr(o,[1,o.shape[0],o.shape[1],o.shape[2],o.shape[3]])),h(5===s.rank,(function(){return"Error in maxPool3d: x must be rank 5 but got rank "+s.rank+"."})),h("NDHWC"===i,(function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+i})),null!=a&&h(m(r),(function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+r+"."}));var l={x:s},c={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:i},f=pt.runKernel("MaxPool3D",l,c);return u?zr(f,[f.shape[1],f.shape[2],f.shape[3],f.shape[4]]):f}});var mi=Et({maxPoolWithArgmax_:function(e,t,n,r,a){void 0===a&&(a=!1);var i={x:kt(e,"x","maxPoolWithArgmax")},o={filterSize:t,strides:n,pad:r,includeBatchInIndex:a},s=pt.runKernel("MaxPoolWithArgmax",i,o);return{result:s[0],indexes:s[1]}}});var bi=Et({maximum_:function(e,t){var n,r=kt(e,"a","maximum"),a=kt(t,"b","maximum");r=(n=ot(r,a))[0],a=n[1],"bool"===r.dtype&&(r=hn(r,"int32"),a=hn(a,"int32")),xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("Maximum",i)}});var yi=Et({mean_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:kt(e,"x","mean")},a={axis:t,keepDims:n};return pt.runKernel("Mean",r,a)}});function wi(e,t){if(void 0===t&&(t="float32"),"complex64"===t){var n=wi(e,"float32"),r=wi(e,"float32");return St(n,r)}var a=L(v(e),t);return pt.makeTensor(a,e,t)}function ki(e,t){if(void 0===t&&(t="float32"),"complex64"===t){var n=ki(e,"float32"),r=wi(e,"float32");return St(n,r)}var a=P(v(e),t);return pt.makeTensor(a,e,t)}var xi=Et({min_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:kt(e,"x","min")},a={axis:t,keepDims:n};return pt.runKernel("Min",r,a)}});var Ei=Et({minimum_:function(e,t){var n,r=kt(e,"a","minimum"),a=kt(t,"b","minimum");r=(n=ot(r,a))[0],a=n[1],"bool"===r.dtype&&(r=hn(r,"int32"),a=hn(a,"int32")),xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("Minimum",i)}});var Si=Et({mirrorPad_:function(e,t,n){h("reflect"===n||"symmetric"===n,(function(){return"Invalid mode. Mode must be either reflect or symmetric. Got "+n+"."}));var r=kt(e,"x","mirrorPad");if(0===r.rank)throw new Error("mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad");h(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,i=function(e){h(2===t[e].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),h(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}))},o=0;o<r.rank;o++)i(o);var s={paddings:t,mode:n},u={x:r};return pt.runKernel("MirrorPad",u,s)}});var Ai=Et({mod_:function(e,t){var n,r=kt(e,"a","mod"),a=kt(t,"b","mod"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Mod",i)}});var _i=Et({square_:function(e){var t=kt(e,"x","square");return pt.runKernel("Square",{x:t},{})}});var Ni=Et({moments_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=y(t,(e=kt(e,"x","moments")).shape),a=yi(e,r,n),i=a.shape;n||(i=li(a.shape,r));var o=_i(ai(hn(e,"float32"),zr(a,i)));return{mean:a,variance:yi(o,r,n)}}});var Mi=Et({multiRNNCell_:function(e,t,n,r){for(var a=kt(t,"data","multiRNNCell"),i=xt(n,"c","multiRNNCell"),o=xt(r,"h","multiRNNCell"),s=a,u=[],l=0;l<e.length;l++){var c=e[l](s,i[l],o[l]);u.push(c[0]),u.push(c[1]),s=c[1]}var h=[],f=[];for(l=0;l<u.length;l+=2)h.push(u[l]),f.push(u[l+1]);return[h,f]}});var Ii=Et({multinomial_:function(e,t,n,r){void 0===r&&(r=!1);var a=kt(e,"logits","multinomial"),i=a.size,o=a.rank;if(i<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+i+".");if(o>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+o);n=n||Math.random();var s={logits:1===o?zr(a,[1,-1]):a},u={numSamples:t,seed:n,normalized:r},l=pt.runKernel("Multinomial",s,u);return 1===o?zr(l,[l.size]):l}});var Ti=Et({notEqual_:function(e,t){var n,r=kt(e,"a","notEqual","string_or_numeric"),a=kt(t,"b","notEqual","string_or_numeric");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("NotEqual",i)}});var Di=Et({onesLike_:function(e){var t={x:kt(e,"x","onesLike")};return pt.runKernel("OnesLike",t)}});var Ri=Et({outerProduct_:function(e,t){var n=kt(e,"v1","outerProduct"),r=kt(t,"v2","outerProduct");h(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=zr(n,[-1,1]),i=zr(r,[1,-1]);return Nn(a,i)}});var Fi=Et({pad_:function(e,t,n){void 0===n&&(n=0);var r=kt(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},i={x:r};return pt.runKernel("PadV2",i,a)}});var Ci=Et({pad1d_:function(e,t,n){return void 0===n&&(n=0),h(2===t.length,(function(){return"Invalid number of paddings. Must be length of 2."})),Fi(e,[t],n)}});var Bi=Et({pad2d_:function(e,t,n){return void 0===n&&(n=0),h(2===t.length&&2===t[0].length&&2===t[1].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),Fi(e,t,n)}});var Pi=Et({pad3d_:function(e,t,n){return void 0===n&&(n=0),h(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."})),Fi(e,t,n)}});var Li=Et({pad4d_:function(e,t,n){return void 0===n&&(n=0),h(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."})),Fi(e,t,n)}});var Oi=Et({spaceToBatchND_:function(e,t,n){var r=kt(e,"x","spaceToBatchND");h(r.rank>=1+t.length,(function(){return"input rank "+r.rank+" should be > than [blockShape] "+t.length})),h(n.length===t.length,(function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+t.length})),h(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},i={blockShape:t,paddings:n};return pt.runKernel("SpaceToBatchND",a,i)}});var zi=Et({pool_:function(e,t,n,r,a,i){null==a&&(a=[1,1]),null==i&&(i=1),0===r&&(r="valid");var o=kt(e,"x","maxPool"),s=o,u=!1;3===o.rank&&(u=!0,s=zr(o,[1,o.shape[0],o.shape[1],o.shape[2]])),h(Lr(i,a),(function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+a+"'"}));var l,c=Mr(s.shape,t,i,a,r),f=[c.dilationHeight,c.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]]}))}([c.filterHeight,c.filterWidth],f):[[0,0],[0,0]];var d=1===f[0]&&1===f[1],p=function(e,t,n){var r=n.map((function(e){return e[0]})),a=n.map((function(e){return e[1]})),i=e.concat(r,a),o=t.map((function(e,t){return(e-i[t]%e)%e})),s=a.map((function(e,t){return e+o[t]})),u=t.map((function(e,t){return[r[t],s[t]]})),l=t.map((function(e,t){return[0,o[t]]}));return[u,l]}([c.inHeight,c.inWidth],f,l),v=p[0],g=p[1],m=d?r:"valid",b=d?s:Oi(s,f,v),y=("avg"===n?function(){return qr(b,t,i,m)}:function(){return vi(b,t,i,m)})(),w=d?y:jr(y,f,g);return u?zr(w,[w.shape[1],w.shape[2],w.shape[3]]):w}});var qi=Et({pow_:function(e,t){var n,r=kt(e,"base","pow"),a=kt(t,"exp","pow"),i={a:r=(n=ot(r,a))[0],b:a=n[1]};return pt.runKernel("Pow",i)}});var Ki=Et({prelu_:function(e,t){var n={x:kt(e,"x","prelu"),alpha:kt(t,"alpha","prelu")};return pt.runKernel("Prelu",n)}});var Wi=Et({prod_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=kt(e,"x","prod");"bool"===r.dtype&&(r=hn(r,"int32"));var a={x:r},i={axis:t,keepDims:n};return pt.runKernel("Prod",a,i)}});var Ui=Et({rand_:function(e,t,n){var r=v(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 i=0;i<r;i++)a[i]=t();return pt.makeTensor(a,e,n)}});"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function Gi(e,t){return e(t={exports:{}},t.exports),t.exports}var Vi=Gi((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 i(e,t){var n=new r(e),i=t&&t.state,o=n.next;return o.int32=function(){return 4294967296*n.next()|0},o.double=function(){return o()+11102230246251565e-32*(2097152*o()|0)},o.quick=o,i&&("object"==typeof i&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.alea=i}(0,e,!1)})),Hi=Gi((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 i(e,t){var n=new r(e),i=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,i&&("object"==typeof i&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.xor128=i}(0,e,!1)})),ji=Gi((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 i(e,t){var n=new r(e),i=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,i&&("object"==typeof i&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.xorwow=i}(0,e,!1)})),Ji=Gi((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 i(e,t){null==e&&(e=+new Date);var n=new r(e),i=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,i&&(i.x&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.xorshift7=i}(0,e,!1)})),Zi=Gi((function(e){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.w,a=t.X,i=t.i;return t.w=r=r+1640531527|0,n=a[i+34&127],e=a[i=i+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=a[i]=n^e,t.i=i,n+(r^r>>>16)|0},function(e,t){var n,r,a,i,o,s=[],u=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,u=Math.max(u,t.length)),a=0,i=-32;i<u;++i)t&&(r^=t.charCodeAt((i+32)%t.length)),0===i&&(o=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,i>=0&&(o=o+1640531527|0,a=0==(n=s[127&i]^=r+o)?a+1:0);for(a>=128&&(s[127&(t&&t.length||0)]=-1),a=127,i=512;i>0;--i)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=o,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 i(e,t){null==e&&(e=+new Date);var n=new r(e),i=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,i&&(i.X&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.xor4096=i}(0,e,!1)})),Yi=Gi((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 i(e,t){var n=new r(e),i=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,i&&("object"==typeof i&&a(i,n),o.state=function(){return a(n,{})}),o}t&&t.exports?t.exports=i:n&&n.amd?n((function(){return i})):this.tychei=i}(0,e,!1)})),Xi=Gi((function(e){!function(t,n){var r,a=this,i=n.pow(256,6),o=n.pow(2,52),s=2*o;function u(e,u,d){var p=[],v=h(function e(t,n){var r,a=[],i=typeof t;if(n&&"object"==i)for(r in t)try{a.push(e(t[r],n-1))}catch(e){}return a.length?a:"string"==i?t:t+"\0"}((u=1==u?{entropy:!0}:u||{}).entropy?[e,f(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)),f(e)}catch(e){var n=a.navigator,i=n&&n.plugins;return[+new Date,a,i,a.screen,f(t)]}}():e,3),p),g=new l(p),m=function(){for(var e=g.g(6),t=i,n=0;e<o;)e=256*(e+n),t*=256,n=g.g(1);for(;e>=s;)e/=2,t/=2,n>>>=1;return(e+n)/t};return m.int32=function(){return 0|g.g(4)},m.quick=function(){return g.g(4)/4294967296},m.double=m,h(f(g.S),t),(u.pass||d||function(e,t,r,a){return a&&(a.S&&c(a,g),e.state=function(){return c(g,{})}),r?(n.random=e,t):e})(m,v,"global"in u?u.global:this==n,u.state)}function l(e){var t,n=e.length,r=this,a=0,i=r.i=r.j=0,o=r.S=[];for(n||(e=[n++]);a<256;)o[a]=a++;for(a=0;a<256;a++)o[a]=o[i=255&i+e[a%n]+(t=o[a])],o[i]=t;(r.g=function(e){for(var t,n=0,a=r.i,i=r.j,o=r.S;e--;)t=o[a=255&a+1],n=256*n+o[255&(o[a]=o[i=255&i+t])+(o[i]=t)];return r.i=a,r.j=i,n})(256)}function c(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function h(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 f(t)}function f(e){return String.fromCharCode.apply(0,e)}if(n.seedrandom=u,h(n.random(),t),e.exports){e.exports=u;try{r=require("crypto")}catch(e){}}}([],Math)}));Xi.alea=Vi,Xi.xor128=Hi,Xi.xorwow=ji,Xi.xorshift7=Ji,Xi.xor4096=Zi,Xi.tychei=Yi;var $i=Xi.alea,Qi=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 i=a||Math.random();this.random=$i(i.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,i=void 0,o=void 0;do{o=(a=2*this.random()-1)*a+(i=2*this.random()-1)*i}while(o>=1||0===o);var s=Math.sqrt(-2*Math.log(o)/o);t=this.mean+this.stdDev*a*s,n=this.mean+this.stdDev*i*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}(),eo=function(){function e(e,t,n,r){this.alpha=e,this.beta=1/t,this.dtype=n;var a=r||Math.random();this.randu=$i(a.toString()),this.randn=new Qi(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,i;;){do{r=this.randn.nextValue(),i=1+this.c*r}while(i<=0);if(i*=i*i,t=1-.331*(e=r*r)*e,n=.5*e+this.d*(1-i+Math.log(i)),(a=this.randu())<t||Math.log(a)<n)break}return i=1/this.beta*this.d*i,this.alpha<1&&(i*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(i)},e.prototype.convertValue=function(e){return"float32"===this.dtype?e:Math.round(e)},e}(),to=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=$i(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 no=Et({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 i=new eo(t,n,r,a),o=cn(e,r),s=0;s<o.values.length;s++)o.values[s]=i.nextValue();return o.toTensor()}});var ro=Et({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 i=new Qi(t,n,r,!1,a),o=cn(e,r),s=0;s<o.values.length;s++)o.values[s]=i.nextValue();return o.toTensor()}});var ao=Et({randomUniform_:function(e,t,n,r,a){void 0===t&&(t=0),void 0===n&&(n=1),void 0===r&&(r="float32");for(var i=cn(e,r),o=new to(t,n,null,a),s=0;s<i.values.length;s++)i.values[s]=o.nextValue();return i.toTensor()}});function io(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 pt.runKernel("Range",{},a)}var oo=Et({real_:function(e){var t={input:kt(e,"input","real")};return pt.runKernel("Real",t)}});var so=Et({reciprocal_:function(e){var t={x:kt(e,"x","reciprocal")};return pt.runKernel("Reciprocal",t)}});var uo=Et({relu_:function(e){var t={x:kt(e,"x","relu")};return pt.runKernel("Relu",t)}});var lo=Et({relu6_:function(e){var t={x:kt(e,"x","relu6")};return pt.runKernel("Relu6",t)}});var co=Et({reverse_:function(e,t){var n={x:kt(e,"x","reverse")},r={dims:t};return pt.runKernel("Reverse",n,r)}});var ho=Et({reverse1d_:function(e){var t=kt(e,"x","reverse");return h(1===t.rank,(function(){return"Error in reverse1D: x must be rank 1 but got rank "+t.rank+"."})),co(t,0)}});var fo=Et({reverse2d_:function(e,t){var n=kt(e,"x","reverse");return h(2===n.rank,(function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."})),co(n,t)}});var po=Et({reverse3d_:function(e,t){var n=kt(e,"x","reverse");return h(3===n.rank,(function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."})),co(n,t)}});var vo=Et({reverse4d_:function(e,t){var n=kt(e,"x","reverse");return h(4===n.rank,(function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."})),co(n,t)}});var go=Et({round_:function(e){var t={x:kt(e,"x","round")};return pt.runKernel("Round",t)}});var mo=Et({rsqrt_:function(e){var t={x:kt(e,"x","rsqrt")};return pt.runKernel("Rsqrt",t)}});function bo(e,t){if((A(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&&A(e)&&!(e instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return At(e,[],[],t)}var yo=Et({selu_:function(e){var t={x:kt(e,"x","selu")};return pt.runKernel("Selu",t)}});var wo=Et({separableConv2d_:function(e,t,n,r,a,i,o){void 0===i&&(i=[1,1]),void 0===o&&(o="NHWC");var s=kt(e,"x","separableConv2d"),u=kt(t,"depthwiseFilter","separableConv2d"),l=kt(n,"pointwiseFilter","separableConv2d"),c=s,f=!1;if(3===s.rank&&(f=!0,c=zr(s,[1,s.shape[0],s.shape[1],s.shape[2]])),"NCHW"===o)throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");h(4===c.rank,(function(){return"Error in separableConv2d: input must be rank 4, but got rank "+c.rank+"."})),h(4===u.rank,(function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+u.rank+"."})),h(4===l.rank,(function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+u.rank+"."})),h(1===l.shape[0],(function(){return"Error in separableConv2d: the first dimension of pointwise filter  must be 1, but got "+l.shape[0]+"."})),h(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];h(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=ba(c,u,r,a,o,i),g=oa(v,l,1,"valid",o);return f?zr(g,[g.shape[1],g.shape[2],g.shape[3]]):g}});var ko=function(e,t){return r(this,void 0,void 0,(function(){var n,r,i,o,s,u,l,c,f,d;return a(this,(function(a){switch(a.label){case 0:return n=kt(e,"x","setdiff1d"),r=kt(t,"y","setdiff1d"),h(n.dtype===r.dtype,(function(){return"x and y should have the same dtype, but got x ("+n.dtype+") and y ("+r.dtype+")."})),h(1===n.rank,(function(){return"x should be 1D tensor, but got x ("+n.shape+")."})),h(1===r.rank,(function(){return"y should be 1D tensor, but got y ("+r.shape+")."})),[4,n.data()];case 1:return i=a.sent(),[4,r.data()];case 2:for(o=a.sent(),s=new Set(o),u=0,f=0;f<i.length;f++)s.has(i[f])||u++;for(l=new Je([u],n.dtype),c=new Je([u],"int32"),f=0,d=0;f<i.length;f++)s.has(i[f])||(l.values[d]=i[f],c.values[d]=f,d++);return[2,[l.toTensor(),c.toTensor()]]}}))}))};var xo=Et({sign_:function(e){var t={x:kt(e,"x","sign")};return pt.runKernel("Sign",t)}});var Eo=Et({sin_:function(e){var t={x:kt(e,"x","sin")};return pt.runKernel("Sin",t)}});var So=Et({sinh_:function(e){var t={x:kt(e,"x","sinh")};return pt.runKernel("Sinh",t)}});var Ao=Et({slice1d_:function(e,t,n){var r=kt(e,"x","slice1d");return h(1===r.rank,(function(){return"slice1d expects a rank-1 tensor, but got a rank-"+r.rank+" tensor"})),Gr(r,[t],[n])}});var _o=Et({slice2d_:function(e,t,n){var r=kt(e,"x","slice2d");return h(2===r.rank,(function(){return"slice2d expects a rank-2 tensor, but got a rank-"+r.rank+" tensor"})),Gr(r,t,n)}});var No=Et({slice3d_:function(e,t,n){var r=kt(e,"x","slice3d");return h(3===r.rank,(function(){return"slice3d expects a rank-3 tensor, but got a rank-"+r.rank+" tensor"})),Gr(r,t,n)}});var Mo=Et({slice4d_:function(e,t,n){var r=kt(e,"x","slice4d");return h(4===r.rank,(function(){return"slice4d expects a rank-4 tensor, but got a rank-"+r.rank+" tensor"})),Gr(r,t,n)}});var Io=Et({softmax_:function(e,t){void 0===t&&(t=-1);var n=kt(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 pt.runKernel("Softmax",r,a)}});var To=Et({fft_:function(e){h("complex64"===e.dtype,(function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+e.dtype+"."}));var t={input:e};return pt.runKernel("FFT",t)}});var Do=Et({ifft_:function(e){h("complex64"===e.dtype,(function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+e.dtype+"."}));var t={input:e};return pt.runKernel("IFFT",t)}});var Ro=Et({irfft_:function(e){var t,n=e.shape[e.shape.length-1],r=e.size/n;if(n<=2){var a=zr(e,[r,n]);t=Do(a)}else{var i=[r,2*(n-1)],o=zr(oo(e),[r,n]),s=zr(Ka(e),[r,n]),u=co(Gr(o,[0,1],[r,n-2]),1),l=pr(co(Gr(s,[0,1],[r,n-2]),1),bo(-1)),c=Wr([o,u],1),h=Wr([s,l],1);a=zr(St(c,h),[i[0],i[1]]);t=Do(a)}if(t=oo(t),3===e.rank&&0!==e.shape[0]){var f=t,d=e.shape[0];t=zr(t,[d,t.shape[0]/d,t.shape[1]]),f.dispose()}return t}});var Fo=Et({split_:function(e,t,n){void 0===n&&(n=0);var r={x:kt(e,"x","split")},a={numOrSizeSplits:t,axis:n};return pt.runKernel("SplitV",r,a)}});var Co=Et({rfft_:function(e,t){h("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 i=e.shape.map((function(e){return 0})),o=e.shape.map((function(e){return e}));o[e.shape.length-1]=t,n=Gr(e,i,o),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=Wr([e,wi(s)],e.shape.length-1),r=t}else n=e;var u=Aa(n),l=zr(St(n,u),[a,r]),c=To(l),f=Math.floor(r/2)+1,d=oo(c),p=Ka(c),v=Fo(d,[f,r-f],d.shape.length-1),g=Fo(p,[f,r-f],p.shape.length-1),m=n.shape.slice();return m[n.shape.length-1]=f,zr(St(v[0],g[0]),m)}});var Bo=Et({sqrt_:function(e){var t={x:kt(e,"x","sqrt")};return pt.runKernel("Sqrt",t)}});var Po=Et({squaredDifference_:function(e,t){var n,r=kt(e,"a","squaredDifference"),a=kt(t,"b","squaredDifference");r=(n=ot(r,a))[0],a=n[1],xa(r.shape,a.shape);var i={a:r,b:a};return pt.runKernel("SquaredDifference",i,{})}});var Lo=Et({squeeze_:function(e,t){var n=kt(e,"x","squeeze");return zr(n,w(n.shape,t).newShape)}});var Oo=Et({stack_:function(e,t){void 0===t&&(t=0);var n=xt(e,"tensors","stack","string_or_numeric");h(n.length>=1,(function(){return"Pass at least one tensor to tf.stack"})),n.length>0&&h(t<=n[0].rank,(function(){return"Axis must be <= rank of the tensor"}));var r=n,a={axis:t};return pt.runKernel("Pack",r,a)}});var zo=Et({step_:function(e,t){void 0===t&&(t=0);var n={x:kt(e,"x","step")},r={alpha:t};return pt.runKernel("Step",n,r)}});var qo=Et({stridedSlice_:function(e,t,n,r,a,i,o,s,u){void 0===a&&(a=0),void 0===i&&(i=0),void 0===o&&(o=0),void 0===s&&(s=0),void 0===u&&(u=0);var l={x:kt(e,"x","stridedSlice","string_or_numeric")},c={begin:t,end:n,strides:r,beginMask:a,endMask:i,ellipsisMask:o,newAxisMask:s,shrinkAxisMask:u};return pt.runKernel("StridedSlice",l,c)}});var Ko=Et({tan_:function(e){var t={x:kt(e,"x","tan")};return pt.runKernel("Tan",t)}});function Wo(e,t){d(e);var n=yt(e,t);if(1!==n.length)throw new Error("tensor1d() requires values to be a flat/TypedArray");return At(e,null,n,t)}function Uo(e,t,n){if(d(e),null!=t&&2!==t.length)throw new Error("tensor2d() requires shape to have two numbers");var r=yt(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 At(e,t,r,n)}var Go=Et({topk_:function(e,t,n){void 0===t&&(t=1),void 0===n&&(n=!0);var r=kt(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<0)throw new Error("'k' passed to topk() must be >= 0 but got "+t);if(t>a)throw new Error("'k' passed to topk() must be <= the last dimension ("+a+") but got "+t);var i={x:r},o={k:t,sorted:n},s=pt.runKernel("TopK",i,o);return{values:s[0],indices:s[1]}}});var Vo=Et({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 i=new Qi(t,n,r,!0,a),o=cn(e,r),s=0;s<o.values.length;s++)o.values[s]=i.nextValue();return o.toTensor()}});var Ho=Et({unique_:function(e,t){void 0===t&&(t=0);var n=kt(e,"x","unique","string_or_numeric");h(n.rank>0,(function(){return"The input tensor must be at least 1D"}));var r={x:n},a={axis:t},i=pt.runKernel("Unique",r,a);return{values:i[0],indices:i[1]}}});var jo=Et({unsortedSegmentSum_:function(e,t,n){var r=kt(e,"x","unsortedSegmentSum"),a=kt(t,"segmentIds","unsortedSegmentSum","int32");h(m(n),(function(){return"numSegments must be of dtype int"}));var i={x:r,segmentIds:a},o={numSegments:n};return pt.runKernel("UnsortedSegmentSum",i,o)}});var Jo=Et({unstack_:function(e,t){void 0===t&&(t=0);var n=kt(e,"x","unstack","string_or_numeric");h(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 pt.runKernel("Unpack",r,a)}});function Zo(e,t){for(var n=[],r=0;r<t.length;r++)t[r]&&n.push(r);var a=cn(e,"int32"),i=cn([n.length,e.length],"int32");for(r=0;r<n.length;r++){var o=a.indexToLoc(n[r]),s=r*e.length;i.values.set(o,s)}return i.toTensor()}var Yo=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=kt(e,"condition","whereAsync","bool")).data()];case 1:return n=a.sent(),r=Zo(t.shape,n),e!==t&&t.dispose(),[2,r]}}))}))};var Xo=function(e,t,n){return r(this,void 0,void 0,(function(){var r,i,o,s,u,l,c,d,p,v,g,m,b;return a(this,(function(a){switch(a.label){case 0:for(r=kt(e,"tensor","boolMask"),i=kt(t,"mask","boolMask","bool"),o=null==n?0:n,s=i.rank,u=r.shape,h(s>0,(function(){return"mask cannot be scalar"})),f(u.slice(o,o+s),i.shape,"mask's shape must match the first K dimensions of tensor's shape,"),l=1,c=o;c<o+s;c++)l*=u[c];return d=u.slice(0,o).concat([l],u.slice(o+s)),p=zr(r,d),v=zr(i,[-1]),[4,Yo(v)];case 1:return g=a.sent(),m=Lo(g,[1]),b=Oa(p,m,o),e!==r&&r.dispose(),t!==i&&i.dispose(),m.dispose(),p.dispose(),v.dispose(),g.dispose(),[2,b]}}))}))};var $o=Et({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 vr(t);if(1!==t.rank&&null===r)return e(zr(t,[-1]),n,r);if(1===t.rank||"number"==typeof r||Array.isArray(r)&&1===r.length){if(1===n)return ii(vr(t),r);if(n===1/0)return ri(vr(t),r);if(n===-1/0)return xi(vr(t),r);if("euclidean"===n||2===n)return Bo(ii(qi(vr(t),bo(2,"int32")),r));throw new Error("Error in norm: invalid ord value: "+n)}if(Array.isArray(r)&&2===r.length){if(1===n)return ri(ii(vr(t),r[0]),r[1]-1);if(n===1/0)return ri(ii(vr(t),r[1]),r[0]);if(n===-1/0)return xi(ii(vr(t),r[1]),r[0]);if("fro"===n||"euclidean"===n)return Bo(ii(_i(t),r));throw new Error("Error in norm: invalid ord value: "+n)}throw new Error("Error in norm: invalid axis: "+r)}(e=kt(e,"x","norm"),t,n),i=a.shape;if(r){var o=y(n,e.shape);i=li(a.shape,o)}return zr(a,i)}});var Qo=Et({movingAverage_:function(e,t,n,r,a){void 0===a&&(a=!0);var i=kt(e,"v","movingAverage"),o=kt(t,"x","movingAverage"),s=kt(n,"decay","movingAverage");st(i,o),h(g(i.shape,o.shape),(function(){return"Shape mismatch in v and x"}));var u=bo(1),l=ai(u,s),c=pr(ai(o,i),l);if(a){h(null!=r,(function(){return"When using zeroDebias: true, step is required."}));var f=kt(r,"step","movingAverage");c=dr(c,ai(u,qi(s,f)))}return hr(i,c)}});var es=Et({scatterND_:function(e,t,n){var r=kt(e,"indices","scatterND","int32"),a=kt(t,"updates","scatterND");zn(a,r,n);var i={indices:r,updates:a},o={shape:n};return pt.runKernel("ScatterNd",i,o)}});var ts=Et({sparseToDense_:function(e,t,n,r){void 0===r&&(r=0);var a=kt(e,"sparseIndices","sparseToDense","int32"),i=kt(t,"sparseValues","sparseToDense"),o=kt(r,"defaultValue","sparseToDense",i.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,i=e.rank>1?e.shape[1]:1;if(n.length!==i)throw new Error("outputShape has incorrect number of elements:, "+n.length+", should be: "+i+".");var o=t.size;if(0!==t.rank&&(1!==t.rank||o!==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,i,n,o);var s={sparseIndices:a,sparseValues:i,defaultValue:o},u={outputShape:n};return pt.runKernel("SparseToDense",s,u)}});var ns=Et({gatherND_:function(e,t){var n=kt(t,"indices","gatherND","int32"),r={params:kt(e,"x","gatherND","string_or_numeric"),indices:n};return pt.runKernel("GatherNd",r)}});var rs=Et({dropout_:function(e,t,n,r){var a=kt(e,"x","dropout");if(h("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."})),h(t>=0&&t<1,(function(){return"rate must be a float in the range [0, 1), but got "+t+"."})),0===t)return e instanceof Xe?a.clone():a;var i=function(e,t){if(null==t)return e.shape.slice();if(g(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),o=1-t,s=dr(La(hr(ao(i,0,1,"float32",r),o)),o);return pr(a,s)}});function as(e){return Math.floor(Math.pow(2,Math.ceil(Math.log(e)/Math.log(2))))}function is(e,t,n){for(var r=1-e%2,a=new Float32Array(e),i=0;i<e;++i){var o=2*Math.PI*i/(e+r-1);a[i]=t-n*Math.cos(o)}return Wo(a,"float32")}var os=function(e,t,n){return void 0===n&&(n=1),r(this,void 0,void 0,(function(){var r,i,o,s,u,l,c,d,p,v,g,m,b,y;return a(this,(function(a){switch(a.label){case 0:return r=kt(e,"predictions","inTopK"),i=kt(t,"targets","inTopK"),h(r.rank>1,(function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank})),h(r.rank-1===i.rank,(function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+i.rank})),f(r.shape.slice(0,r.shape.length-1),i.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),o=r.shape[r.shape.length-1],h(n>0&&n<=o,(function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+o+"), but got "+n})),[4,r.data()];case 1:return s=a.sent(),[4,i.data()];case 2:for(u=a.sent(),l=[s.length/o,o],d=l[1],p=k("bool",c=l[0]),v=0;v<c;v++){for(g=v*d,m=s.subarray(g,g+d),b=[],y=0;y<m.length;y++)b.push({value:m[y],index:y});for(b.sort((function(e,t){return t.value-e.value})),p[v]=0,y=0;y<n;y++)if(b[y].index===u[v]){p[v]=1;break}}return e!==r&&r.dispose(),t!==i&&i.dispose(),[2,_t(p,i.shape,"bool")]}}))}))};var ss=Et({conv2DBackpropFilter_:function(e,t,n,r,a,i,o){void 0===i&&(i="NHWC");var s=e;3===e.rank&&(s=zr(e,[1,e.shape[0],e.shape[1],e.shape[2]]));var u=t;3===u.rank&&(u=zr(t,[1,t.shape[0],t.shape[1],t.shape[2]])),h(4===s.rank,(function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+s.shape+"."})),h(4===u.rank,(function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+u.shape+"."})),h(4===n.length,(function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+n+"."}));var l="NHWC"===i?s.shape[3]:s.shape[1],c="NHWC"===i?u.shape[3]:u.shape[1];h(l===n[2],(function(){return"Error in conv2dDerFilter: depth of input "+l+") must match input depth in filter ("+n[2]+"."})),h(c===n[3],(function(){return"Error in conv2dDerFilter: depth of dy ("+c+") must match output depth for filter ("+n[3]+")."})),null!=o&&h(m(a),(function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+a+"."}));var f={x:s,dy:u},d={strides:r,pad:a,dataFormat:i,dimRoundingMode:o,filterShape:n};return pt.runKernel("Conv2DBackpropFilter",f,d)}});function us(e,t,n){if(null==n||"linear"===n)return e;if("relu"===n)return pr(e,zo(t));throw new Error("Cannot compute gradient for fused activation "+n+".")}function ls(e,t){var n=t,r=ka(e.shape,t.shape);return r.length>0&&(n=ii(n,r)),zr(n,e.shape)}function cs(e,t,n,r){if("linear"===t)return e;if("relu"===t)return uo(e);if("elu"===t)return Ia(e);if("relu6"===t)return lo(e);if("prelu"===t)return Ki(e,n);if("leakyrelu"===t)return Va(e,r);if("sigmoid"===t)return Ur(e);throw new Error("Unknown fused activation "+t+".")}var hs=function(e,t){return!(e>0)||"linear"===t};var fs=Et({fusedConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,a=e.pad,i=e.dataFormat,o=void 0===i?"NHWC":i,s=e.dilations,u=void 0===s?[1,1]:s,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=void 0===f?"linear":f,p=e.preluActivationWeights,v=e.leakyreluAlpha;if(d=d||"linear",!1===hs(pt.state.gradientDepth,d)){var g=oa(t,n,r,a,o,u,l);return null!=c&&(g=hr(g,c)),cs(g,d,p,v)}var b=kt(t,"x","conv2d"),y=kt(n,"filter","conv2d"),w=b,k=!1;3===b.rank&&(k=!0,w=zr(b,[1,b.shape[0],b.shape[1],b.shape[2]])),h(4===w.rank,(function(){return"Error in fused conv2d: input must be rank 4, but got rank "+w.rank+"."})),h(4===y.rank,(function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+y.rank+"."})),null!=l&&h(m(a),(function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+l+" but got pad "+a+"."})),h(w.shape[3]===y.shape[2],(function(){return"Error in conv2d: depth of input ("+w.shape[3]+") must match input depth for filter "+y.shape[2]+"."})),h(Lr(r,u),(function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"})),h("NHWC"===o,(function(){return"Error in conv2d: got dataFormat of "+o+" but only NHWC is currently supported."}));var x,E,S=Ir(w.shape,y.shape,r,u,a,l);null!=c&&(x=ot(x=kt(c,"bias","fused conv2d"),b)[0],xa(S.outShape,x.shape)),null!=p&&(E=kt(p,"prelu weights","fused conv2d"));var A=function(e,t){var n=t,i=n[0],o=n[1],s=n[2],l=n[3],c=us(e,s,d);h(Pr(u),(function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+u+"'"}));var f=[ua(o.shape,c,i,r,a),ss(o,c,i.shape,r,a)];if(null!=l){var p=ls(l,c);f.push(p)}return f},_={x:w,filter:y,bias:x,preluActivationWeights:E},N={strides:r,pad:a,dataFormat:o,dilations:u,dimRoundingMode:l,activation:d,leakyreluAlpha:v};return null==c?$a((function(e,t,n){var r=pt.runKernel("FusedConv2D",_,N);return n([t,e,r]),k&&(r=zr(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:A}}))(w,y):$a((function(e,t,n,r){var a=pt.runKernel("FusedConv2D",_,N);return r([t,e,a,n]),k&&(a=zr(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:A}}))(w,y,x)}});var ds=Et({depthwiseConv2dNativeBackpropFilter_:function(e,t,n,r,a,i,o){void 0===i&&(i=[1,1]);var s=e;3===e.rank&&(s=zr(e,[1,e.shape[0],e.shape[1],e.shape[2]]));var u=t;3===u.rank&&(u=zr(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var l={x:s,dy:u},c={strides:r,pad:a,dimRoundingMode:o,dilations:i,filterShape:n};return pt.runKernel("DepthwiseConv2dNativeBackpropFilter",l,c)}});var ps=Et({depthwiseConv2dNativeBackpropInput_:function(e,t,n,r,a,i,o){void 0===i&&(i=[1,1]);var s=t,u=!1;3===t.rank&&(u=!0,s=zr(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var l={dy:s,filter:n},c={strides:r,pad:a,dimRoundingMode:o,dilations:i,inputShape:e},h=pt.runKernel("DepthwiseConv2dNativeBackpropInput",l,c);return u?zr(h,[h.shape[1],h.shape[2],h.shape[3]]):h}});var vs={__proto__:null,conv2d:fs,depthwiseConv2d:Et({fusedDepthwiseConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,a=e.pad,i=e.dataFormat,o=void 0===i?"NHWC":i,s=e.dilations,u=void 0===s?[1,1]:s,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=void 0===f?"linear":f,p=e.preluActivationWeights,v=e.leakyreluAlpha;if(!1===hs(pt.state.gradientDepth,d)){var g=ba(t,n,r,a,o,u,l);return null!=c&&(g=hr(g,c)),cs(g,d,p,v)}var b=kt(t,"x","depthwiseConv2d"),y=kt(n,"filter","depthwiseConv2d"),w=b,k=!1;3===b.rank&&(k=!0,w=zr(b,[1,b.shape[0],b.shape[1],b.shape[2]])),h(4===w.rank,(function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+w.rank+"."})),h(4===y.rank,(function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+y.rank+"."})),h(w.shape[3]===y.shape[2],(function(){return"Error in fused depthwiseConv2d: number of input channels ("+w.shape[3]+") must match the inChannels dimension in filter "+y.shape[2]+"."})),null==u&&(u=[1,1]),h(Lr(r,u),(function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"})),null!=l&&h(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=Ir(w.shape,y.shape,r,u,a,l,!0);null!=c&&(x=ot(x=kt(c,"bias","fused conv2d"),b)[0],xa(S.outShape,x.shape)),null!=p&&(E=kt(p,"prelu weights","fused depthwiseConv2d"));var A=function(e,t){h(Pr(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],i=t[1],o=t[2],s=t[3],c=us(e,o,d),f=ps(i.shape,c,n,r,a,u,l),p=ds(i,c,n.shape,r,a,u,l);return null!=s?[f,p,ls(x,c)]:[f,p]},_={x:w,filter:y,bias:x,preluActivationWeights:E},N={strides:r,pad:a,dataFormat:o,dilations:u,dimRoundingMode:l,activation:d,leakyreluAlpha:v};return null==c?$a((function(e,t,n){var r=pt.runKernel("FusedDepthwiseConv2D",_,N);return n([t,e,r]),k&&(r=zr(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:A}}))(w,y):$a((function(e,t,n,r){var a=pt.runKernel("FusedDepthwiseConv2D",_,N);return r([t,e,a,n]),k&&(a=zr(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:A}}))(w,y,x)}}),matMul:Et({fusedMatMul_:function(e){var t,n=e.a,r=e.b,a=e.transposeA,i=void 0!==a&&a,o=e.transposeB,s=void 0!==o&&o,u=e.bias,l=e.activation,c=void 0===l?"linear":l,f=e.preluActivationWeights,d=e.leakyreluAlpha;if(!1===hs(pt.state.gradientDepth,c)){var p=Nn(n,r,i,s);return null!=u&&(p=hr(p,u)),cs(p,c,f,d)}var m=kt(n,"a","fused matMul"),b=kt(r,"b","fused matMul");t=ot(m,b),m=t[0],b=t[1];var y=i?m.shape[m.rank-2]:m.shape[m.rank-1],w=s?b.shape[b.rank-1]:b.shape[b.rank-2],k=i?m.shape[m.rank-1]:m.shape[m.rank-2],x=s?b.shape[b.rank-2]:b.shape[b.rank-1],E=m.shape.slice(0,-2),S=b.shape.slice(0,-2),A=v(E),_=v(S);h(m.rank>=2&&b.rank>=2&&m.rank===b.rank,(function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+m.rank+" and "+b.rank+"."})),h(g(E,S),(function(){return"Error in fused matMul: outer dimensions ("+E+") and ("+S+") of Tensors with shapes "+m.shape+" and "+b.shape+" must match."})),h(y===w,(function(){return"Error in fused matMul: inner shapes ("+y+") and ("+w+") of Tensors with shapes "+m.shape+" and "+b.shape+" and transposeA="+i+" and transposeB="+s+" must match."}));var N,M,I=m.shape.slice(0,-2).concat([k,x]),T=zr(m,i?[A,y,k]:[A,k,y]),D=zr(b,s?[_,x,w]:[_,w,x]);null!=u&&(N=ot(N=kt(u,"bias","fused matMul"),m)[0],xa(I,N.shape)),null!=f&&(M=kt(f,"prelu weights","fused matMul"));var R=function(e,t){var n,r,a=t[0],o=t[1],l=t[2],h=t[3],f=us(zr(e,l.shape),l,c);return i||s?!i&&s?(n=Nn(f,o,!1,!1),r=Nn(f,a,!0,!1)):i&&!s?(n=Nn(o,f,!1,!0),r=Nn(a,f,!1,!1)):(n=Nn(o,f,!0,!0),r=Nn(f,a,!0,!0)):(n=Nn(f,o,!1,!0),r=Nn(a,f,!0,!1)),null!=u?[n,r,ls(h,f)]:[n,r]},F={a:T,b:D,bias:N,preluActivationWeights:M},C={transposeA:i,transposeB:s,activation:c,leakyreluAlpha:d};return null==u?$a((function(e,t,n){var r=pt.runKernel("_FusedMatMul",F,C);return n([e,t,r]),{value:zr(r,I),gradFunc:R}}))(T,D):$a((function(e,t,n,r){var a=pt.runKernel("_FusedMatMul",F,C);return r([e,t,a,n]),{value:zr(a,I),gradFunc:R}}))(T,D,N)}})};var gs=Et({hammingWindow_:function(e){return is(e,.54,.46)}});var ms=Et({hannWindow_:function(e){return is(e,.5,.5)}});var bs=Et({frame_:function(e,t,n,r,a){void 0===r&&(r=!1),void 0===a&&(a=0);for(var i=0,o=[];i+t<=e.size;)o.push(Gr(e,i,t)),i+=n;if(r)for(;i<e.size;){var s=i+t-e.size,u=Wr([Gr(e,i,t-s),Pa([s],a)]);o.push(u),i+=n}return 0===o.length?Uo([],[0,t]):zr(Wr(o),[o.length,t])}});var ys=Et({stft_:function(e,t,n,r,a){void 0===a&&(a=ms),null==r&&(r=as(t));var i=bs(e,t,n),o=pr(i,a(t));return Co(o,r)}});var ws=Et({cropAndResize_:function(e,t,n,r,a,i){void 0===a&&(a="bilinear"),void 0===i&&(i=0);var o=kt(e,"image","cropAndResize"),s=kt(t,"boxes","cropAndResize","float32"),u=kt(n,"boxInd","cropAndResize","int32"),l=s.shape[0];h(4===o.rank,(function(){return"Error in cropAndResize: image must be rank 4,but got rank "+o.rank+"."})),h(2===s.rank&&4===s.shape[1],(function(){return"Error in cropAndResize: boxes must be have size ["+l+",4] but had shape "+s.shape+"."})),h(1===u.rank&&u.shape[0]===l,(function(){return"Error in cropAndResize: boxInd must be have size ["+l+"] but had shape "+s.shape+"."})),h(2===r.length,(function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."})),h(r[0]>=1&&r[1]>=1,(function(){return"cropSize must be atleast [1,1], but was "+r})),h("bilinear"===a||"nearest"===a,(function(){return"method must be bilinear or nearest, but was "+a}));var c={image:o,boxes:s,boxInd:u},f={method:a,extrapolationValue:i,cropSize:r};return pt.runKernel("CropAndResize",c,f)}});var ks=Et({flipLeftRight_:function(e){var t=kt(e,"image","flipLeftRight","float32");h(4===t.rank,(function(){return"Error in flipLeftRight: image must be rank 4,but got rank "+t.rank+"."}));var n={image:t};return pt.runKernel("FlipLeftRight",n,{})}});var xs=Et({rotateWithOffset_:function(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=.5);var a=kt(e,"image","rotateWithOffset","float32");h(4===a.rank,(function(){return"Error in rotateWithOffset: image must be rank 4,but got rank "+a.rank+"."}));var i={image:a},o={radians:t,fillValue:n,center:r};return pt.runKernel("RotateWithOffset",i,o)}});function Es(e,t,n,r,a,i){null==r&&(r=.5),null==a&&(a=Number.NEGATIVE_INFINITY),null==i&&(i=0);var o=e.shape[0];return n=Math.min(n,o),h(0<=r&&r<=1,(function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"})),h(2===e.rank,(function(){return"boxes must be a 2D tensor, but was of rank '"+e.rank+"'"})),h(4===e.shape[1],(function(){return"boxes must have 4 columns, but 2nd dimension was "+e.shape[1]})),h(1===t.rank,(function(){return"scores must be a 1D tensor"})),h(t.shape[0]===o,(function(){return"scores has incompatible shape with boxes. Expected "+o+", but was "+t.shape[0]})),h(0<=i&&i<=1,(function(){return"softNmsSigma must be in [0, 1], but was '"+i+"'"})),{maxOutputSize:n,iouThreshold:r,scoreThreshold:a,softNmsSigma:i}}var Ss=Et({nonMaxSuppression_:function(e,t,n,r,a){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY);var i=kt(e,"boxes","nonMaxSuppression"),o=kt(t,"scores","nonMaxSuppression"),s=Es(i,o,n,r,a),u={maxOutputSize:n=s.maxOutputSize,iouThreshold:r=s.iouThreshold,scoreThreshold:a=s.scoreThreshold};return pt.runKernel("NonMaxSuppressionV3",{boxes:i,scores:o},u)}});function As(e,t,n){var r=function(e,t,n){return function(e,t,n){var r=0,a=e.length,i=0,o=!1;for(;r<a;){var s=n(t,e[i=r+(a-r>>>1)]);s>0?r=i+1:(a=i,o=!s)}return o?r:-r-1}(e,t,n||_s)}(e,t,n),a=r<0?-(r+1):r;e.splice(a,0,t)}function _s(e,t){return e>t?1:e<t?-1:0}function Ns(e,t,n,r,a){return Ts(e,t,n,r,a,0)}function Ms(e,t,n,r,a,i){return Ts(e,t,n,r,a,0,!1,i,!0)}function Is(e,t,n,r,a,i){return Ts(e,t,n,r,a,i,!0)}function Ts(e,t,n,r,a,i,o,s,u){void 0===o&&(o=!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(Fs);for(var h=i>0?-.5/i:0,f=[],d=[];f.length<n&&l.length>0;){var p=l.pop(),v=p.score,g=p.boxIndex,m=p.suppressBeginIndex;if(v<a)break;for(var b=!1,y=f.length-1;y>=m;--y){var w=Ds(e,g,f[y]);if(w>=r){b=!0;break}if(p.score=p.score*Rs(r,h,w),p.score<=a)break}p.suppressBeginIndex=f.length,b||(p.score===v?(f.push(g),d.push(p.score)):p.score>a&&As(l,p,Fs))}var k=f.length,x=n-k;s&&x>0&&(f.push.apply(f,new Array(x).fill(0)),d.push.apply(d,new Array(x).fill(0)));var E={selectedIndices:f};return o&&(E.selectedScores=d),u&&(E.validOutputs=k),E}function Ds(e,t,n){var r=e.subarray(4*t,4*t+4),a=e.subarray(4*n,4*n+4),i=Math.min(r[0],r[2]),o=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]),h=Math.max(a[0],a[2]),f=Math.max(a[1],a[3]),d=(s-i)*(u-o),p=(h-l)*(f-c);if(d<=0||p<=0)return 0;var v=Math.max(i,l),g=Math.max(o,c),m=Math.min(s,h),b=Math.min(u,f),y=Math.max(m-v,0)*Math.max(b-g,0);return y/(d+p-y)}function Rs(e,t,n){var r=Math.exp(t*n*n);return n<=e?r:0}function Fs(e,t){return e.score-t.score||e.score===t.score&&t.boxIndex-e.boxIndex}var Cs=function(e,t,n,i,o){return void 0===i&&(i=.5),void 0===o&&(o=Number.NEGATIVE_INFINITY),r(this,void 0,void 0,(function(){var r,s,u,l,c,h,f;return a(this,(function(a){switch(a.label){case 0:return r=kt(e,"boxes","nonMaxSuppressionAsync"),s=kt(t,"scores","nonMaxSuppressionAsync"),u=Es(r,s,n,i,o),n=u.maxOutputSize,i=u.iouThreshold,o=u.scoreThreshold,[4,Promise.all([r.data(),s.data()])];case 1:return l=a.sent(),c=l[0],h=l[1],f=Ns(c,h,n,i,o).selectedIndices,r!==e&&r.dispose(),s!==t&&s.dispose(),[2,Wo(f,"int32")]}}))}))};var Bs=Et({nonMaxSuppressionWithScore_:function(e,t,n,r,a,i){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===i&&(i=0);var o=kt(e,"boxes","nonMaxSuppression"),s=kt(t,"scores","nonMaxSuppression"),u=Es(o,s,n,r,a,i),l={boxes:o,scores:s},c={maxOutputSize:n=u.maxOutputSize,iouThreshold:r=u.iouThreshold,scoreThreshold:a=u.scoreThreshold,softNmsSigma:i=u.softNmsSigma},h=pt.runKernel("NonMaxSuppressionV5",l,c);return{selectedIndices:h[0],selectedScores:h[1]}}});var Ps=function(e,t,n,i,o,s){return void 0===i&&(i=.5),void 0===o&&(o=Number.NEGATIVE_INFINITY),void 0===s&&(s=0),r(this,void 0,void 0,(function(){var r,u,l,c,h,f,d,p,v;return a(this,(function(a){switch(a.label){case 0:return r=kt(e,"boxes","nonMaxSuppressionAsync"),u=kt(t,"scores","nonMaxSuppressionAsync"),l=Es(r,u,n,i,o,s),n=l.maxOutputSize,i=l.iouThreshold,o=l.scoreThreshold,s=l.softNmsSigma,[4,Promise.all([r.data(),u.data()])];case 1:return c=a.sent(),h=c[0],f=c[1],d=Is(h,f,n,i,o,s),p=d.selectedIndices,v=d.selectedScores,r!==e&&r.dispose(),u!==t&&u.dispose(),[2,{selectedIndices:Wo(p,"int32"),selectedScores:Wo(v)}]}}))}))};var Ls=Et({nonMaxSuppressionPadded_:function(e,t,n,r,a,i){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===i&&(i=!1);var o=kt(e,"boxes","nonMaxSuppression"),s=kt(t,"scores","nonMaxSuppression"),u=Es(o,s,n,r,a,null),l={boxes:o,scores:s},c={maxOutputSize:u.maxOutputSize,iouThreshold:u.iouThreshold,scoreThreshold:u.scoreThreshold,padToMaxOutputSize:i},h=pt.runKernel("NonMaxSuppressionV4",l,c);return{selectedIndices:h[0],validOutputs:h[1]}}});var Os=function(e,t,n,i,o,s){return void 0===i&&(i=.5),void 0===o&&(o=Number.NEGATIVE_INFINITY),void 0===s&&(s=!1),r(this,void 0,void 0,(function(){var r,u,l,c,h,f,d,p,v,g,m,b;return a(this,(function(a){switch(a.label){case 0:return r=kt(e,"boxes","nonMaxSuppressionAsync"),u=kt(t,"scores","nonMaxSuppressionAsync"),l=Es(r,u,n,i,o,null),c=l.maxOutputSize,h=l.iouThreshold,f=l.scoreThreshold,[4,Promise.all([r.data(),u.data()])];case 1:return d=a.sent(),p=d[0],v=d[1],g=Ms(p,v,c,h,f,s),m=g.selectedIndices,b=g.validOutputs,r!==e&&r.dispose(),u!==t&&u.dispose(),[2,{selectedIndices:Wo(m,"int32"),validOutputs:bo(b,"int32")}]}}))}))};var zs=Et({resizeBilinear_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=kt(e,"images","resizeBilinear");h(3===a.rank||4===a.rank,(function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+a.rank+"."})),h(2===t.length,(function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+t+"."})),h(!1===r||!1===n,(function(){return"Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false."}));var i=a,o=!1;3===a.rank&&(o=!0,i=zr(a,[1,a.shape[0],a.shape[1],a.shape[2]]));var s={images:i},u={alignCorners:n,halfPixelCenters:r,size:t},l=pt.runKernel("ResizeBilinear",s,u);return o?zr(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var qs=Et({resizeNearestNeighbor_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=kt(e,"images","resizeNearestNeighbor");h(3===a.rank||4===a.rank,(function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+a.rank+"."})),h(2===t.length,(function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+t+"."})),h("float32"===a.dtype||"int32"===a.dtype,(function(){return"`images` must have `int32` or `float32` as dtype"})),h(!1===r||!1===n,(function(){return"Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false."}));var i=a,o=!1;3===a.rank&&(o=!0,i=zr(a,[1,a.shape[0],a.shape[1],a.shape[2]]));var s={images:i},u={alignCorners:n,halfPixelCenters:r,size:t},l=pt.runKernel("ResizeNearestNeighbor",s,u);return o?zr(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var Ks=Et({threshold_:function(e,t,n,r){var a;void 0===t&&(t="binary"),void 0===n&&(n=!1),void 0===r&&(r=.5);var i,o,s,u,l=kt(e,"image","threshold"),c=l.shape[0]*l.shape[1],f=pr(Wo([r]),255);if(h(3===l.rank,(function(){return"Error in threshold: image must be rank 3,but got rank "+l.rank+"."})),h(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]+"."})),h("int32"===l.dtype||"float32"===l.dtype,(function(){return"Error in dtype: image dtype must be int32 or float32,but got dtype "+l.dtype+"."})),h("otsu"===t||"binary"===t,(function(){return"Method must be binary or otsu, but was "+t})),3===l.shape[2]){i=(a=Fo(l,[1,1,1],-1))[0],o=a[1],s=a[2];var d=pr(i,.2989),p=pr(o,.587),v=pr(s,.114);u=hr(hr(d,p),v)}else u=e;"otsu"===t&&(f=function(e,t){for(var n,r,a,i,o,s,u=Wo([-1]),l=Wo([0]),c=Wo([0]),h=0;h<e.size-1;h++){n=Gr(e,0,h+1),r=Gr(e,h+1),o=dr(ii(n),t),s=dr(ii(r),t);var f=ii(pr(n,io(0,n.size)));a=dr(f,ii(n));var d=Pa(r.shape,n.size),p=hr(io(0,r.size),d),v=pr(r,p);i=dr(ii(v),ii(r));var g=ai(a,i),m=ai(a,i),b=pr(o,s);c=pr(pr(b,g),m);var y=za(c,l);l=Sa(y,c,l),u=Sa(y,Wo([h]),u)}return u}($r(hn(go(u),"int32"),_t([]),256),c));var g=n?ja(u,f):za(u,f);return hn(pr(g,255),"int32")}});var Ws=Et({transform_:function(e,t,n,r,a,i){void 0===n&&(n="nearest"),void 0===r&&(r="constant"),void 0===a&&(a=0);var o=kt(e,"image","transform","float32"),s=kt(t,"transforms","transform","float32");h(4===o.rank,(function(){return"Error in transform: image must be rank 4,but got rank "+o.rank+"."})),h(2===s.rank&&(s.shape[0]===o.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"})),h(null==i||2===i.length,(function(){return"Error in transform: outputShape must be [height, width] or null, but got "+i+"."}));var u={image:o,transforms:s},l={interpolation:n,fillMode:r,fillValue:a,outputShape:i};return pt.runKernel("Transform",u,l)}});var Us=Et({bandPart_:function(e,t,n){h(t%1==0,(function(){return"bandPart(): numLower must be an integer, got "+t+"."})),h(n%1==0,(function(){return"bandPart(): numUpper must be an integer, got "+n+"."}));var r=kt(e,"a","bandPart");h(r.rank>=2,(function(){return"bandPart(): Rank must be at least 2, got "+r.rank+"."}));var a=r.shape,i=r.shape.slice(-2),o=i[0],s=i[1];if(!(t<=o))throw new Error("bandPart(): numLower ("+t+") must not be greater than the number of rows ("+o+").");if(!(n<=s))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+s+").");t<0&&(t=o),n<0&&(n=s);var u=zr(io(0,o,1,"int32"),[-1,1]),l=io(0,s,1,"int32"),c=ai(u,l),f=hi(ja(c,bo(+t,"int32")),qa(c,bo(-n,"int32"))),d=wi([o,s],r.dtype);return zr(Oo(Jo(zr(r,[-1,o,s])).map((function(e){return Sa(f,e,d)}))),a)}});var Gs=Et({gramSchmidt_:function(e){var t;if(Array.isArray(e)){t=!1,h(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){h(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=Fo(e,e.shape[0],0).map((function(e){return Lo(e,[0])}));h(e.length<=e[0].shape[0],(function(){return"Gram-Schmidt: Number of vectors ("+e.length+") exceeds number of dimensions ("+e[0].shape[0]+")."}));var i=[],o=e,s=function(e){i.push(pt.tidy((function(){var t=o[e];if(e>0)for(var n=0;n<e;++n){var r=pr(ii(pr(i[n],t)),i[n]);t=ai(t,r)}return dr(t,$o(t,"euclidean"))})))};for(a=0;a<e.length;++a)s(a);return t?Oo(i,0):i}});function Vs(e,t){return void 0===t&&(t=!1),pt.tidy((function(){h(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=Ba(n),i=fn(e),o=Uo([[1]],[1,1]),s=fn(o),u=n>=r?r:n,l=function(e){var t,u=i,l=s,c=a;t=pt.tidy((function(){var t=Gr(i,[e,e],[n-e,1]),u=$o(t),l=Gr(i,[e,e],[1,1]),c=Sa(za(l,0),Uo([[-1]]),Uo([[1]])),h=ai(l,pr(c,u)),f=dr(t,h);s=1===f.shape[0]?fn(o):Wr([o,Gr(f,[1,0],[f.shape[0]-1,f.shape[1]])],0);var d=ei(dr(Nn(c,h),u)),p=Gr(i,[e,0],[n-e,r]),v=pr(d,s),g=In(s);if(0===e)i=ai(p,Nn(v,Nn(g,p)));else{var m=ai(p,Nn(v,Nn(g,p)));i=Wr([Gr(i,[0,0],[e,r]),m],0)}var b=In(v),y=Gr(a,[0,e],[n,a.shape[1]-e]);if(0===e)a=ai(y,Nn(Nn(y,s),b));else{var w=ai(y,Nn(Nn(y,s),b));a=Wr([Gr(a,[0,0],[n,e]),w],1)}return[s,i,a]})),s=t[0],i=t[1],a=t[2],lr([u,l,c])},c=0;c<u;++c)l(c);return!t&&n>r&&(a=Gr(a,[0,0],[n,r]),i=Gr(i,[0,0],[r,r])),[a,i]}))}var Hs,js=Et({qr_:function(e,t){if(void 0===t&&(t=!1),h(e.rank>=2,(function(){return"qr() requires input tensor to have a rank >= 2, but got rank "+e.rank})),2===e.rank)return Vs(e,t);var n=e.shape.slice(0,e.shape.length-2).reduce((function(e,t){return e*t})),r=Jo(zr(e,[n,e.shape[e.shape.length-2],e.shape[e.shape.length-1]]),0),a=[],i=[];return r.forEach((function(e){var n=Vs(e,t),r=n[0],o=n[1];a.push(r),i.push(o)})),[zr(Oo(a,0),e.shape),zr(Oo(i,0),e.shape)]}});(Hs=e.Reduction||(e.Reduction={}))[Hs.NONE=0]="NONE",Hs[Hs.MEAN=1]="MEAN",Hs[Hs.SUM=2]="SUM",Hs[Hs.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS";var Js=Et({computeWeightedLoss_:function(t,n,r){void 0===r&&(r=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=kt(t,"losses","computeWeightedLoss"),i=null;null!=n&&(i=kt(n,"weights","computeWeightedLoss"));var o=null==i?a:pr(a,i);if(r===e.Reduction.NONE)return o;if(r===e.Reduction.SUM)return ii(o);if(r===e.Reduction.MEAN){if(null==i)return yi(o);var s=a.size/i.size,u=dr(ii(o),ii(i));return s>1?dr(u,bo(s)):u}if(r===e.Reduction.SUM_BY_NONZERO_WEIGHTS){if(null==i)return dr(ii(o),bo(a.size));var l=pr(i,ki(a.shape)),c=hn(ii(Ti(l,bo(0))),"float32");return dr(ii(o),c)}throw Error("Unknown reduction: "+r)}});var Zs=Et({absoluteDifference_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=kt(t,"labels","absoluteDifference"),o=kt(n,"predictions","absoluteDifference"),s=null;null!=r&&(s=kt(r,"weights","absoluteDifference")),f(i.shape,o.shape,"Error in absoluteDifference: ");var u=vr(ai(i,o));return Js(u,s,a)}});var Ys=Et({cosineDistance_:function(t,n,r,a,i){void 0===i&&(i=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=kt(t,"labels","cosineDistance"),s=kt(n,"predictions","cosineDistance"),u=null;null!=a&&(u=kt(a,"weights","cosineDistance")),f(o.shape,s.shape,"Error in cosineDistance: ");var l=bo(1),c=ai(l,ii(pr(o,s),r,!0));return Js(c,u,i)}});var Xs=Et({hingeLoss_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=kt(t,"labels","hingeLoss"),o=kt(n,"predictions","hingeLoss"),s=null;null!=r&&(s=kt(r,"weights","hingeLoss")),f(i.shape,o.shape,"Error in hingeLoss: ");var u=bo(1);i=ai(pr(bo(2),i),u);var l=uo(ai(u,pr(i,o)));return Js(l,s,a)}});var $s=Et({huberLoss_:function(t,n,r,a,i){void 0===a&&(a=1),void 0===i&&(i=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=kt(t,"labels","huberLoss"),s=kt(n,"predictions","huberLoss"),u=null;null!=r&&(u=kt(r,"weights","huberLoss")),f(o.shape,s.shape,"Error in huberLoss: ");var l=bo(a),c=vr(ai(s,o)),h=Ei(c,l),d=ai(c,h),p=hr(pr(bo(.5),_i(h)),pr(l,d));return Js(p,u,i)}});var Qs=Et({logLoss_:function(t,n,r,a,i){void 0===a&&(a=1e-7),void 0===i&&(i=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=kt(t,"labels","logLoss"),s=kt(n,"predictions","logLoss"),u=null;null!=r&&(u=kt(r,"weights","logLoss")),f(o.shape,s.shape,"Error in logLoss: ");var l=bo(1),c=bo(a),h=ei(pr(o,Za(hr(s,c)))),d=pr(ai(l,o),Za(hr(ai(l,s),c))),p=ai(h,d);return Js(p,u,i)}});var eu=Et({meanSquaredError_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=kt(t,"labels","meanSquaredError"),o=kt(n,"predictions","meanSquaredError"),s=null;null!=r&&(s=kt(r,"weights","meanSquaredError")),f(i.shape,o.shape,"Error in meanSquaredError: ");var u=Po(i,o);return Js(u,s,a)}});var tu=Et({sigmoidCrossEntropy_:function(t,n,r,a,i){void 0===a&&(a=0),void 0===i&&(i=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=kt(t,"multiClassLabels","sigmoidCrossEntropy"),s=kt(n,"logits","sigmoidCrossEntropy"),u=null;if(null!=r&&(u=kt(r,"weights","sigmoidCrossEntropy")),f(o.shape,s.shape,"Error in sigmoidCrossEntropy: "),a>0){var l=bo(a),c=bo(1),h=bo(.5);o=hr(pr(o,ai(c,l)),pr(h,l))}var d=function(e,t){var n=kt(e,"labels","sigmoidCrossEntropyWithLogits"),r=kt(t,"logits","sigmoidCrossEntropyWithLogits");f(n.shape,r.shape,"Error in sigmoidCrossEntropyWithLogits: ");var a=uo(r),i=pr(r,n),o=Ya(Da(ei(vr(r))));return hr(ai(a,i),o)}(o,s);return Js(d,u,i)}});var nu=Et({softmaxCrossEntropy_:function(t,n,r,a,i){void 0===a&&(a=0),void 0===i&&(i=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=kt(t,"onehotLabels","softmaxCrossEntropy"),s=kt(n,"logits","softmaxCrossEntropy"),u=null;if(null!=r&&(u=kt(r,"weights","softmaxCrossEntropy")),f(o.shape,s.shape,"Error in softmaxCrossEntropy: "),a>0){var l=bo(a),c=bo(1),h=bo(o.shape[1]);o=hr(pr(o,ai(c,l)),dr(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 $a((function(e,t,r){var a=ci(t,[n],!0),i=ai(hn(t,"float32"),a);r([e,i]);var o=ei(pr(i,e));return{value:ii(o,[n]),gradFunc:function(e,t){var r=t[0],a=t[1],i=li(e.shape,[n]);return[pr(zr(e,i),ai(hn(r,"float32"),Da(a))),pr(zr(e,i),ai(Da(a),hn(r,"float32")))]}}}))(e,t)}(o,s);return Js(d,u,i)}});var ru=Et({sparseFillEmptyRows_:function(e,t,n,r){var a=kt(e,"indices","sparseFillEmptyRows"),i=kt(t,"values","sparseFillEmptyRows"),o=kt(n,"denseShape","sparseFillEmptyRows"),s=kt(r,"defaultValue","sparseFillEmptyRows",i.dtype);if(2!==a.rank)throw new Error("Indices should be Tensor2D but received shape\n        "+a.shape);if(1!==i.rank)throw new Error("Values should be Tensor1D but received shape "+i.shape);if(1!==o.rank)throw new Error("Dense shape should be Tensor1D but received shape "+o.shape);if(0!==s.rank)throw new Error("Default value should be a scalar but received shape "+s.shape);var u={indices:a,values:i,denseShape:o,defaultValue:s},l=pt.runKernel("SparseFillEmptyRows",u);return{outputIndices:l[0],outputValues:l[1],emptyRowIndicator:l[2],reverseIndexMap:l[3]}}});var au=Et({sparseReshape_:function(e,t,n){var r=kt(e,"inputIndices","sparseReshape"),a=kt(t,"inputShape","sparseReshape"),i=kt(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!==i.rank)throw new Error("New shape should be Tensor1D but received shape "+i.shape);var o={inputIndices:r,inputShape:a,newShape:i},s=pt.runKernel("SparseReshape",o);return{outputIndices:s[0],outputShape:s[1]}}});var iu=Et({sparseSegmentMean_:function(e,t,n){var r=kt(e,"data","sparseSegmentMean"),a=kt(t,"indices","sparseSegmentMean"),i=kt(n,"segmentIds","sparseSegmentMean");if(r.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(1!==a.rank)throw new Error("Indices should be Tensor1D but received shape\n          "+a.shape);if(1!==i.rank)throw new Error("Segment ids should be Tensor1D but received shape\n          "+i.shape);var o={data:r,indices:a,segmentIds:i};return pt.runKernel("SparseSegmentMean",o)}});var ou=Et({sparseSegmentSum_:function(e,t,n){var r=kt(e,"data","sparseSegmentSum"),a=kt(t,"indices","sparseSegmentSum"),i=kt(n,"segmentIds","sparseSegmentSum");if(r.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(1!==a.rank)throw new Error("Indices should be Tensor1D but received shape\n         "+a.shape);if(1!==i.rank)throw new Error("Segment ids should be Tensor1D but received shape\n         "+i.shape);var o={data:r,indices:a,segmentIds:i};return pt.runKernel("SparseSegmentSum",o)}});var su=Et({stringNGrams_:function(e,t,n,r,a,i,o,s){var u=kt(e,"data","stringNGrams","string");if("string"!==u.dtype)throw new Error("Data must be of datatype string");if(1!==u.shape.length)throw new Error("Data must be a vector, saw: "+u.shape);var l=kt(t,"dataSplits","stringNGrams");if("int32"!==l.dtype)throw new Error("Data splits must be of datatype int32");var c={separator:n,nGramWidths:r,leftPad:a,rightPad:i,padWidth:o,preserveShortSequences:s},h={data:u,dataSplits:l},f=pt.runKernel("StringNGrams",h,c);return{nGrams:f[0],nGramsSplits:f[1]}}});var uu=Et({stringSplit_:function(e,t,n){void 0===n&&(n=!0);var r=kt(e,"input","stringSplit","string"),a=kt(t,"delimiter","stringSplit","string");if(1!==r.rank)throw new Error("Input should be Tensor1D but received shape "+r.shape);if(0!==a.rank)throw new Error("Delimiter should be a scalar but received shape "+a.shape);var i={skipEmpty:n},o={input:r,delimiter:a},s=pt.runKernel("StringSplit",o,i);return{indices:s[0],values:s[1],shape:s[2]}}});var lu=Et({stringToHashBucketFast_:function(e,t){var n=kt(e,"input","stringToHashBucketFast","string"),r={numBuckets:t};if(t<=0)throw new Error("Number of buckets must be at least 1");var a={input:n};return pt.runKernel("StringToHashBucketFast",a,r)}}),cu={fft:To,ifft:Do,rfft:Co,irfft:Ro},hu={hammingWindow:gs,hannWindow:ms,frame:bs,stft:ys},fu={flipLeftRight:ks,resizeNearestNeighbor:qs,resizeBilinear:zs,rotateWithOffset:xs,cropAndResize:ws,nonMaxSuppression:Ss,nonMaxSuppressionAsync:Cs,nonMaxSuppressionWithScore:Bs,nonMaxSuppressionWithScoreAsync:Ps,nonMaxSuppressionPadded:Ls,nonMaxSuppressionPaddedAsync:Os,threshold:Ks,transform:Ws},du={bandPart:Us,gramSchmidt:Gs,qr:js},pu={absoluteDifference:Zs,computeWeightedLoss:Js,cosineDistance:Ys,hingeLoss:Xs,huberLoss:$s,logLoss:Qs,meanSquaredError:eu,sigmoidCrossEntropy:tu,softmaxCrossEntropy:nu},vu={sparseFillEmptyRows:ru,sparseReshape:au,sparseSegmentMean:iu,sparseSegmentSum:ou},gu={stringNGrams:su,stringSplit:uu,stringToHashBucketFast:lu},mu=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,i=r.grads;if(null!=n){var o=n.map((function(e){return{name:e.name,tensor:i[e.name]}}));this.applyGradients(o)}else this.applyGradients(i);return lr(i),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 Xa(e,t)},t.prototype.dispose=function(){null!=this.iterations_&&lr(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:bo(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}(er);Object.defineProperty(mu,Symbol.hasInstance,{value:function(e){return null!=e.minimize&&null!=e.computeGradients&&null!=e.applyGradients}});var bu=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=pt.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=pt.registeredVariables[n];null==t.accumulatedGrads[r]&&(t.accumulatedGrads[r]={originalName:n+"/accum_grad",variable:ur((function(){return Aa(a).variable(!1)}))}),null==t.accumulatedUpdates[r]&&(t.accumulatedUpdates[r]={originalName:n+"/accum_var",variable:ur((function(){return Aa(a).variable(!1)}))});var i=Array.isArray(e)?e[r].tensor:e[n];if(null!=i){var o=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;ur((function(){var e=hr(pr(o,t.rho),pr(_i(i),1-t.rho)),n=pr(dr(Bo(hr(s,t.epsilon)),Bo(hr(o,t.epsilon))),i),r=hr(pr(s,t.rho),pr(_i(n),1-t.rho));o.assign(e),s.assign(r);var u=hr(pr(n,-t.learningRate),a);a.assign(u)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedUpdates&&(lr(this.accumulatedGrads.map((function(e){return e.variable}))),lr(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}(mu);nr(bu);var yu=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=pt.registeredVariables[n];if(null==t.accumulatedGrads[r]){t.accumulatedGrads[r]={originalName:n+"/accumulator",variable:ur((function(){return Pa(a.shape,t.initialAccumulatorValue).variable(!1)}))}}var i=Array.isArray(e)?e[r].tensor:e[n];if(null!=i){var o=t.accumulatedGrads[r].variable;ur((function(){var e=hr(o,_i(i));o.assign(e);var n=hr(pr(dr(i,Bo(hr(e,pt.backend.epsilon()))),-t.learningRate),a);a.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedGrads&&lr(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}(mu);nr(yu);var wu=function(e){function t(t,n,r,a){void 0===a&&(a=null);var i=e.call(this)||this;return i.learningRate=t,i.beta1=n,i.beta2=r,i.epsilon=a,i.accumulatedFirstMoment=[],i.accumulatedSecondMoment=[],ur((function(){i.accBeta1=bo(n).variable(),i.accBeta2=bo(r).variable()})),null==a&&(i.epsilon=pt.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);ur((function(){var r=ai(1,t.accBeta1),a=ai(1,t.accBeta2);n.forEach((function(n,i){var o=pt.registeredVariables[n];null==t.accumulatedFirstMoment[i]&&(t.accumulatedFirstMoment[i]={originalName:n+"/m",variable:ur((function(){return Aa(o).variable(!1)}))}),null==t.accumulatedSecondMoment[i]&&(t.accumulatedSecondMoment[i]={originalName:n+"/v",variable:ur((function(){return Aa(o).variable(!1)}))});var s=Array.isArray(e)?e[i].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[i].variable,l=t.accumulatedSecondMoment[i].variable,c=hr(pr(u,t.beta1),pr(s,1-t.beta1)),h=hr(pr(l,t.beta2),pr(_i(s),1-t.beta2)),f=dr(c,r),d=dr(h,a);u.assign(c),l.assign(h);var p=hr(pr(dr(f,hr(Bo(d),t.epsilon)),-t.learningRate),o);o.assign(p)}})),t.accBeta1.assign(pr(t.accBeta1,t.beta1)),t.accBeta2.assign(pr(t.accBeta2,t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),null!=this.accumulatedFirstMoment&&lr(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedSecondMoment&&lr(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(),ur((function(){n.accBeta1.assign(qi(n.beta1,n.iterations_+1)),n.accBeta2.assign(qi(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}(mu);nr(wu);var ku=function(e){function t(t,n,r,a,i){void 0===a&&(a=null),void 0===i&&(i=0);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=a,o.decay=i,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],ur((function(){o.iteration=bo(0).variable(),o.accBeta1=bo(n).variable()})),null==a&&(o.epsilon=pt.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);ur((function(){var r=ai(1,t.accBeta1),a=dr(-t.learningRate,hr(pr(t.iteration,t.decay),1));n.forEach((function(n,i){var o=pt.registeredVariables[n];null==t.accumulatedFirstMoment[i]&&(t.accumulatedFirstMoment[i]={originalName:n+"/m",variable:Aa(o).variable(!1)}),null==t.accumulatedWeightedInfNorm[i]&&(t.accumulatedWeightedInfNorm[i]={originalName:n+"/v",variable:Aa(o).variable(!1)});var s=Array.isArray(e)?e[i].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[i].variable,l=t.accumulatedWeightedInfNorm[i].variable,c=hr(pr(u,t.beta1),pr(s,1-t.beta1)),h=pr(l,t.beta2),f=vr(s),d=bi(h,f);u.assign(c),l.assign(d);var p=hr(pr(dr(a,r),dr(c,hr(d,t.epsilon))),o);o.assign(p)}})),t.iteration.assign(hr(t.iteration,1)),t.accBeta1.assign(pr(t.accBeta1,t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),null!=this.accumulatedFirstMoment&&lr(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedWeightedInfNorm&&lr(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}(mu);nr(ku);var xu=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 i=pt.registeredVariables[n];ur((function(){var e=hr(pr(t.c,a),i);i.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,null!=this.c&&this.c.dispose(),this.c=cr(bo(-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}(mu);nr(xu);var Eu=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=bo(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=pt.registeredVariables[n];if(null==t.accumulations[r]){t.accumulations[r]={originalName:n+"/momentum",variable:ur((function(){return Aa(a).variable(!1)}))}}var i=t.accumulations[r].variable,o=Array.isArray(e)?e[r].tensor:e[n];null!=o&&ur((function(){var e,n=hr(pr(t.m,i),o);e=t.useNesterov?hr(pr(t.c,hr(o,pr(n,t.m))),a):hr(pr(t.c,n),a),i.assign(n),a.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),null!=this.accumulations&&lr(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}(xu);nr(Eu);var Su=function(e){function t(t,n,r,a,i){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===a&&(a=null),void 0===i&&(i=!1);var o=e.call(this)||this;if(o.learningRate=t,o.decay=n,o.momentum=r,o.epsilon=a,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=i,null==a&&(o.epsilon=pt.backend.epsilon()),null==t)throw new Error("learningRate for RMSPropOptimizer must be defined.");return o}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=pt.registeredVariables[n];null==t.accumulatedMeanSquares[r]&&(t.accumulatedMeanSquares[r]={originalName:n+"/rms",variable:ur((function(){return Aa(a).variable(!1)}))}),null==t.accumulatedMoments[r]&&(t.accumulatedMoments[r]={originalName:n+"/momentum",variable:ur((function(){return Aa(a).variable(!1)}))}),null==t.accumulatedMeanGrads[r]&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+"/mg",variable:ur((function(){return Aa(a).variable(!1)}))});var i=Array.isArray(e)?e[r].tensor:e[n];if(null!=i){var o=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;ur((function(){var e=hr(pr(o,t.decay),pr(_i(i),1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,u=hr(pr(n,t.decay),pr(i,1-t.decay)),l=dr(pr(i,t.learningRate),Bo(ai(e,hr(_i(u),t.epsilon)))),c=hr(pr(s,t.momentum),l);o.assign(e),n.assign(u),s.assign(c);var h=ai(a,c);a.assign(h)}else{var f=hr(pr(o,t.decay),pr(_i(i),1-t.decay));c=hr(pr(s,t.momentum),dr(pr(i,t.learningRate),Bo(hr(f,t.epsilon))));o.assign(f),s.assign(c);h=ai(a,c);a.assign(h)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedMeanSquares&&lr(this.accumulatedMeanSquares.map((function(e){return e.variable}))),null!=this.accumulatedMeanGrads&&this.centered&&lr(this.accumulatedMeanGrads.map((function(e){return e.variable}))),null!=this.accumulatedMoments&&lr(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}(mu);nr(Su);var Au=function(){function e(){}return e.sgd=function(e){return new xu(e)},e.momentum=function(e,t,n){return void 0===n&&(n=!1),new Eu(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 Su(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 wu(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 bu(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 ku(e,t,n,r,a)},e.adagrad=function(e,t){return void 0===t&&(t=.1),new yu(e,t)},e}(),_u={sgd:Au.sgd,momentum:Au.momentum,adadelta:Au.adadelta,adagrad:Au.adagrad,rmsprop:Au.rmsprop,adamax:Au.adamax,adam:Au.adam},Nu="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:"undefined"!=typeof setImmediate?setImmediate:function(e){return e()};var Mu=/->/g;function Iu(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 Tu={__proto__:null,slice_util:Qn,segment_util:{__proto__:null,segOpComputeOptimalWindowSize:function(e,t){var n,r=!1;for(e<=30?(n=e,r=!0):n=F(e,Math.floor(Math.sqrt(e)));!r;)n>t||n===e?r=!0:n=F(e,n+1);return n},computeOutShape:function(e,t,n){for(var r=[],a=e.length,i=0;i<a;i++)i!==t?r.push(e[i]):r.push(n);return r},collectGatherOpShapeInfo:function(e,t,n,r){var a=t.shape.length,i=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>i)throw new Error("batchDims ("+r+") must be less than rank(x) (\n    "+i+").");if(n<r)throw new Error("batchDims ("+r+") must be less than or equal to axis ("+n+").");for(var o=0;o<r;++o)if(e.shape[o]!==t.shape[o])throw new Error("x.shape["+o+"]: "+e.shape[o]+" should be equal to indices.shape["+o+"]: "+t.shape[o]+".");var s=e.shape[n],u=[],l=1,c=1,h=1;for(o=0;o<r;++o)u.push(e.shape[o]),l*=e.shape[o];for(o=r;o<n;o++)u.push(e.shape[o]),c*=e.shape[o];for(o=r;o<a;o++)u.push(t.shape[o]);for(o=n+1;o<i;o++)u.push(e.shape[o]),h*=e.shape[o];return{batchSize:l,sliceSize:h,outerSize:c,dimSize:s,outputShape:u}}},fromUint8ToStringArray:function(e){try{return e.map((function(e){return qe(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 ze(e)}))},upcastType:it,axesAreInnerMostDims:si,combineLocations:ui,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:li,assertAxesAreInnerMostDims:function(e,t,n){h(si(t,n),(function(){return e+" supports only inner-most axes for now. Got axes "+t+" and rank-"+n+" input."}))},getAxesPermutation:function(e,t){if(si(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 i=n-1-a,o=e[i]||1;(t[t.length-1-a]||1)>1&&1===o&&r.unshift(i)}return r},getReductionAxes:ka,assertAndGetBroadcastShape:xa,assertParamsConsistent:function(e,t){var n=e[0].length;e.forEach((function(e,t){h(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+")"}))})),h(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 i=0;i<n;i++)h(i===t||e[i]===r[i],(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,i){void 0===a&&(a="NHWC");var o=e[3];return Ir(e,t.concat([o]),n,i,r,null,null,Or(a))},computePool2DInfo:Mr,computePool3DInfo:function(e,t,n,r,a,i,o){void 0===o&&(o="NDHWC");var s,u,l=Fr(t),c=l[0],h=l[1],f=l[2];if("NDHWC"===o)u="channelsLast",s=[c,h,f,e[4],e[4]];else{if("NCDHW"!==o)throw new Error("Unknown dataFormat "+o);u="channelsFirst",s=[c,h,f,e[1],e[1]]}return Tr(e,s,n,r,a,!1,u,i)},computeConv2DInfo:Ir,computeConv3DInfo:Tr,computeDefaultPad:Dr,tupleValuesAreOne:Pr,eitherStridesOrDilationsAreOne:Lr,convertConv2DDataFormat:Or,getFusedDyActivation:us,getFusedBiasGradient:ls,applyActivation:cs,shouldFuse:hs,PARALLELIZE_THRESHOLD:30,computeOptimalWindowSize:function(e){return e<=30?e:F(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 i=t.length,o=0;o<i;++o)a=a.concat([e[o+1]/t[o],t[o]]);a=a.concat(e.slice(i+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 i=[],o=[];for(a=1;a<e;++a)a>=2*t+1||a%2==1?o.push(a):i.push(a);r.push.apply(r,i),r.push(0),r.push.apply(r,o)}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 i=1;i<e.length;++i)i<=t.length?r?a.push(t[i-1]*e[i]):a.push(e[i]/t[i-1]):a.push(e[i]);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:Pn,validateUpdateShape:On,validateInput:zn,calculateShapes:qn,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];G().getBool("IS_TEST")||console.warn.apply(console,e)},log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];G().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 i=(t?2:-2)*Math.PI*(a/e);n[a]=Math.cos(i),r[a]=Math.sin(i)}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(Mu,"").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],i=r[1];h(-1===a.indexOf("..."),(function(){return'The ellipsis notation ("...") is not supported yet.'}));var o=a.split(","),s=o.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=i[e];if(!o.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)},c=0;c<i.length;++c)l(c);for(c=0;c<a.length;++c){var f=a[c];-1===u.indexOf(f)&&","!==f&&u.push(f)}var d=new Array(o.length);for(c=0;c<s;++c){if(new Set(o[c].split("")).size!==o[c].length)throw new Error("Found duplicate axes in input component "+o[c]+". Support for duplicate axes in input is not implemented yet.");d[c]=[];for(var p=0;p<o[c].length;++p)d[c].push(u.indexOf(o[c][p]))}var v=u.length,g=[];for(c=i.length;c<v;++c)g.push(c);return{allDims:u,summedDims:g,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,i=function(n){void 0===r[t[e][n]]?r[t[e][n]]=a[n]:h(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]}))},o=0;o<t[e].length;++o)i(o)},i=0;i<n.length;++i)a(i)},getEinsumComputePath:function(e,t){var n,r=e,a=[];0===e.length&&r.push(-1),n=e.length+1;for(var i=0;i<n;++i)a.push([]);var o=[];for(i=0;i<r.length;++i)for(var s=0,u=Iu(t,r[i]);s<u.length;s++){var l=u[s];-1===o.indexOf(l)&&(a[i].push(l),o.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)h(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{h(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 i=t.reduce((function(e,t){return t>0?e+t:e}));t[a]=e.shape[n]-i}h(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}},Du={__proto__:null,nonMaxSuppressionV3Impl:Ns,nonMaxSuppressionV4Impl:Ms,nonMaxSuppressionV5Impl:Is,whereImpl:Zo};e.Abs="Abs",e.Acos="Acos",e.Acosh="Acosh",e.AdadeltaOptimizer=bu,e.AdagradOptimizer=yu,e.AdamOptimizer=wu,e.AdamaxOptimizer=ku,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=i,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=o,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=Eu,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=mu,e.Pack="Pack",e.PadV2="PadV2",e.Pool="Pool",e.Pow="Pow",e.Prelu="Prelu",e.Prod="Prod",e.RMSPropOptimizer=Su,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=xu,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.SparseSegmentMean="SparseSegmentMean",e.SparseSegmentSum="SparseSegmentSum",e.SparseToDense="SparseToDense",e.SplitV="SplitV",e.Sqrt="Sqrt",e.Square="Square",e.SquaredDifference="SquaredDifference",e.Step="Step",e.StridedSlice="StridedSlice",e.StringNGrams="StringNGrams",e.StringSplit="StringSplit",e.StringToHashBucketFast="StringToHashBucketFast",e.Sub="Sub",e.Sum="Sum",e.Tan="Tan",e.Tanh="Tanh",e.Tensor=Xe,e.TensorBuffer=Je,e.Tile="Tile",e.TopK="TopK",e.Transform="Transform",e.Transpose="Transpose",e.Unique="Unique",e.Unpack="Unpack",e.UnsortedSegmentSum="UnsortedSegmentSum",e.Variable=rt,e.ZerosLike="ZerosLike",e._FusedMatMul="_FusedMatMul",e.abs=vr,e.acos=gr,e.acosh=mr,e.add=hr,e.addN=br,e.all=yr,e.any=wr,e.argMax=kr,e.argMin=xr,e.asin=Er,e.asinh=Sr,e.atan=Ar,e.atan2=_r,e.atanh=Nr,e.avgPool=qr,e.avgPool3d=Kr,e.backend=function(){return pt.backend},e.backend_util=Tu,e.basicLSTMCell=Hr,e.batchNorm=Jr,e.batchNorm2d=Zr,e.batchNorm3d=Yr,e.batchNorm4d=Xr,e.batchToSpaceND=jr,e.bincount=$r,e.booleanMaskAsync=Xo,e.broadcastTo=Qr,e.browser=Bn,e.buffer=cn,e.cast=hn,e.ceil=ea,e.clipByValue=ta,e.clone=fn,e.complex=St,e.concat=Wr,e.concat1d=na,e.concat2d=ra,e.concat3d=aa,e.concat4d=ia,e.conv1d=sa,e.conv2d=oa,e.conv2dTranspose=la,e.conv3d=ca,e.conv3dTranspose=fa,e.copyRegisteredKernels=function(e,t){X(e).forEach((function(e){$(Object.assign({},e,{backendName:t}))}))},e.cos=da,e.cosh=pa,e.cosineWindow=is,e.cumsum=va,e.customGrad=$a,e.denseBincount=ga,e.deprecationWarn=function(e){G().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")},e.depthToSpace=ma,e.depthwiseConv2d=ba,e.device_util=mt,e.diag=ya,e.dilation2d=wa,e.disableDeprecationWarnings=function(){G().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")},e.dispose=lr,e.disposeVariables=function(){pt.disposeVariables()},e.div=dr,e.divNoNan=_a,e.dot=Na,e.dropout=rs,e.einsum=Ma,e.elu=Ia,e.enableDebugMode=function(){G().set("DEBUG",!0)},e.enableProdMode=function(){G().set("PROD",!0)},e.enclosingPowerOfTwo=as,e.engine=function(){return pt},e.env=G,e.equal=Ea,e.erf=Ta,e.exp=Da,e.expandDims=Ra,e.expm1=Fa,e.eye=Ba,e.fft=To,e.fill=Pa,e.findBackend=function(e){return pt.findBackend(e)},e.findBackendFactory=function(e){return pt.findBackendFactory(e)},e.floor=La,e.floorDiv=fr,e.fused=vs,e.gather=Oa,e.gatherND=ns,e.gather_util=Ln,e.getBackend=function(){return pt.backendName},e.getGradient=Y,e.getKernel=Z,e.getKernelsForBackend=X,e.grad=function(e){return h(R(e),(function(){return"The f passed in grad(f) must be a function"})),function(t,n){var r=kt(t,"x","tf.grad","string_or_numeric"),a=null!=n?kt(n,"dy","tf.grad"):null;return pt.tidy((function(){var t=pt.gradients((function(){return e(r)}),[r],a),n=t.value,i=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)"),Qa(i),i[0]}))}},e.grads=function(e){return h(R(e),(function(){return"The f passed in grads(f) must be a function"})),function(t,n){h(Array.isArray(t),(function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"}));var r=xt(t,"args","tf.grads","string_or_numeric"),a=null!=n?kt(n,"dy","tf.grads"):null;return pt.tidy((function(){var t=pt.gradients((function(){return e.apply(void 0,r)}),r,a),n=t.value,i=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,...])"),Qa(i),i}))}},e.greater=za,e.greaterEqual=qa,e.ifft=Do,e.imag=Ka,e.image=fu,e.inTopKAsync=os,e.io=_n,e.irfft=Ro,e.isFinite=Wa,e.isInf=Ua,e.isNaN=Ga,e.keep=cr,e.kernel_impls=Du,e.leakyRelu=Va,e.less=Ha,e.lessEqual=ja,e.linalg=du,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 pt.runKernel("LinSpace",{},r)},e.localResponseNormalization=Ja,e.log=Za,e.log1p=Ya,e.logSigmoid=ni,e.logSoftmax=oi,e.logSumExp=ci,e.logicalAnd=hi,e.logicalNot=fi,e.logicalOr=di,e.logicalXor=pi,e.losses=pu,e.matMul=Nn,e.math=Dn,e.max=ri,e.maxPool=vi,e.maxPool3d=gi,e.maxPoolWithArgmax=mi,e.maximum=bi,e.mean=yi,e.memory=function(){return pt.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 i=kt(e,"x","meshgrid",e instanceof Xe?e.dtype:"float32");if(void 0===t)return[i];var o=kt(t,"y","meshgrid",t instanceof Xe?t.dtype:"float32"),s=v(i.shape),u=v(o.shape);return"xy"===a?(i=zr(i,[1,-1]),o=zr(o,[-1,1]),[Nn(ki([u,1],i.dtype),i),Nn(o,ki([1,s],o.dtype))]):(i=zr(i,[-1,1]),o=zr(o,[1,-1]),[Nn(i,ki([1,u],i.dtype)),Nn(ki([s,1],o.dtype),o)])},e.min=xi,e.minimum=Ei,e.mirrorPad=Si,e.mod=Ai,e.moments=Ni,e.movingAverage=Qo,e.mul=pr,e.multiRNNCell=Mi,e.multinomial=Ii,e.neg=ei,e.nextFrame=function(){return new Promise((function(e){return Nu((function(){return e()}))}))},e.norm=$o,e.notEqual=Ti,e.oneHot=Mn,e.ones=ki,e.onesLike=Di,e.op=Et,e.outerProduct=Ri,e.pad=Fi,e.pad1d=Ci,e.pad2d=Bi,e.pad3d=Pi,e.pad4d=Li,e.pool=zi,e.pow=qi,e.prelu=Ki,e.print=dn,e.prod=Wi,e.profile=function(e){return pt.profile(e)},e.rand=Ui,e.randomGamma=no,e.randomNormal=ro,e.randomUniform=ao,e.range=io,e.ready=function(){return pt.ready()},e.real=oo,e.reciprocal=so,e.registerBackend=function(e,t,n){return void 0===n&&(n=1),pt.registerBackend(e,t,n)},e.registerGradient=function(e){var t=e.kernelName;J.has(t)&&G().getBool("DEBUG")&&console.warn("Overriding the gradient for '"+t+"'"),J.set(t,e)},e.registerKernel=$,e.relu=uo,e.relu6=lo,e.removeBackend=function(e){pt.removeBackend(e)},e.reshape=zr,e.reverse=co,e.reverse1d=ho,e.reverse2d=fo,e.reverse3d=po,e.reverse4d=vo,e.rfft=Co,e.round=go,e.rsqrt=mo,e.scalar=bo,e.scatterND=es,e.scatter_util=Kn,e.selu=yo,e.separableConv2d=wo,e.serialization=rr,e.setBackend=function(e){return pt.setBackend(e)},e.setPlatform=function(e,t){G().setPlatform(e,t)},e.setdiff1dAsync=ko,e.sigmoid=Ur,e.sign=xo,e.signal=hu,e.sin=Eo,e.sinh=So,e.slice=Gr,e.slice1d=Ao,e.slice2d=_o,e.slice3d=No,e.slice4d=Mo,e.slice_util=Qn,e.softmax=Io,e.softplus=ti,e.spaceToBatchND=Oi,e.sparse=vu,e.sparseToDense=ts,e.spectral=cu,e.split=Fo,e.sqrt=Bo,e.square=_i,e.squaredDifference=Po,e.squeeze=Lo,e.stack=Oo,e.step=zo,e.stridedSlice=qo,e.string=gu,e.sub=ai,e.sum=ii,e.sumOutType=function(e){return it(e,"int32")},e.tan=Ko,e.tanh=Vr,e.tensor=_t,e.tensor1d=Wo,e.tensor2d=Uo,e.tensor3d=Rn,e.tensor4d=function(e,t,n){if(d(e),null!=t&&4!==t.length)throw new Error("tensor4d() requires shape to have four numbers");var r=yt(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 At(e,t,r,n)},e.tensor5d=function(e,t,n){if(d(e),null!=t&&5!==t.length)throw new Error("tensor5d() requires shape to have five numbers");var r=yt(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 At(e,t,r,n)},e.tensor6d=function(e,t,n){if(d(e),null!=t&&6!==t.length)throw new Error("tensor6d() requires shape to have six numbers");var r=yt(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 At(e,t=t||r,r,n)},e.tensor_util=lt,e.test_util=sr,e.tidy=ur,e.tile=Ca,e.time=function(e){return pt.time(e)},e.topk=Go,e.train=_u,e.transpose=In,e.truncatedNormal=Vo,e.unique=Ho,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=Q(e,t);if(!j.has(n))throw new Error("The kernel '"+e+"' for backend '"+t+"' is not registered");j.delete(n)},e.unsortedSegmentSum=jo,e.unstack=Jo,e.upcastType=it,e.util=Ke,e.valueAndGrad=function(e){return h(R(e),(function(){return"The f passed in valueAndGrad(f) must be a function"})),function(t,n){h(t instanceof Xe,(function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"})),h(null==n||n instanceof Xe,(function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"}));var r=pt.gradients((function(){return e(t)}),[t],n),a=r.grads,i=r.value;return Qa(a),{grad:a[0],value:i}}},e.valueAndGrads=function(e){return h(R(e),(function(){return"The f passed in valueAndGrads(f) must be a function"})),function(t,n){h(Array.isArray(t)&&t.every((function(e){return e instanceof Xe})),(function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"})),h(null==n||n instanceof Xe,(function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"}));var r=pt.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,...])"),Qa(r.grads),r}},e.variable=function(e,t,n,r){return void 0===t&&(t=!0),pt.makeVariable(e,t,n,r)},e.variableGrads=Xa,e.version_core="3.8.0",e.where=Sa,e.whereAsync=Yo,e.zeros=wi,e.zerosLike=Aa,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=tf-core.min.js.map
