/** * @license * Copyright 2024 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).tf=e.tf||{})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),e}var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},n(e,t)};function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function o(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i}function u(e,t,n){if(n||2===arguments.length)for(var r,a=0,o=t.length;a0;)n=Math.random()*t|0,p(e,--t,n)}function d(e,t,n){return Math.max(e,Math.min(t,n))}function p(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function g(e,t){if(!e)throw new Error("string"==typeof t?t:t())}function v(e,t,n){void 0===n&&(n=""),g(w(e,t),(function(){return n+" Shapes ".concat(e," and ").concat(t," must match")}))}function m(e){g(null!=e,(function(){return"The input to the tensor constructor must be a non-null value."}))}function y(e){if(0===e.length)return 1;for(var t=e[0],n=1;n=-n&&es)&&1===e[s]&&(n.push(e[s]),r.push(s)),o[i]<=s&&i++}1!==e[s]&&(n.push(e[s]),r.push(s))}return{newShape:n,keptDims:r}}function A(e,t){return _(e,t)}function _(e,t){var n=null;if(null==e||"float32"===e)n=new Float32Array(t);else if("int32"===e)n=new Int32Array(t);else if("bool"===e)n=new Uint8Array(t);else{if("string"!==e)throw new Error("Unknown data type ".concat(e));n=new Array(t)}return n}function I(e,t){for(var n=0;n=0;--r)n[r]=n[r+1]*e[r+1];return n}function L(e,t,n,r){void 0===r&&(r=!1);var a=new Array;if(1===t.length)for(var o=t[0]*(r?2:1),i=0;i=0,(function(){return"Tensor must have a shape comprised of positive integers but got "+"shape [".concat(e,"].")}))}))}function q(e){return e&&e.then&&"function"==typeof e.then}var K,V="tfjsflags",H=function(){function e(e){this.global=e,this.flags={},this.flagRegistry={},this.urlFlags={},this.getQueryParams=j,this.populateURLFlags()}return e.prototype.setPlatform=function(e,t){null!=this.platform&&(Z().getBool("IS_TEST")||Z().getBool("PROD")||console.warn("Platform ".concat(this.platformName," has already been set. ")+"Overwriting the platform with ".concat(e,"."))),this.platformName=e,this.platform=t},e.prototype.registerFlag=function(e,t,n){if(this.flagRegistry[e]={evaluationFn:t,setHook:n},null!=this.urlFlags[e]){var r=this.urlFlags[e];Z().getBool("IS_TEST")||Z().getBool("PROD")||console.warn("Setting feature override from URL ".concat(e,": ").concat(r,".")),this.set(e,r)}},e.prototype.getAsync=function(e){return a(this,void 0,void 0,(function(){var t,n;return o(this,(function(r){switch(r.label){case 0:return e in this.flags?[2,this.flags[e]]:(t=this.flags,n=e,[4,this.evaluateFlag(e)]);case 1:return t[n]=r.sent(),[2,this.flags[e]]}}))}))},e.prototype.get=function(e){if(e in this.flags)return this.flags[e];var t=this.evaluateFlag(e);if(q(t))throw new Error("Flag ".concat(e," cannot be synchronously evaluated. ")+"Please use getAsync() instead.");return this.flags[e]=t,this.flags[e]},e.prototype.getNumber=function(e){return this.get(e)},e.prototype.getBool=function(e){return this.get(e)},e.prototype.getString=function(e){return this.get(e)},e.prototype.getFlags=function(){return this.flags},Object.defineProperty(e.prototype,"features",{get:function(){return this.flags},enumerable:!1,configurable:!0}),e.prototype.set=function(e,t){if(null==this.flagRegistry[e])throw new Error("Cannot set flag ".concat(e," as it has not been registered."));this.flags[e]=t,null!=this.flagRegistry[e].setHook&&this.flagRegistry[e].setHook(t)},e.prototype.evaluateFlag=function(e){if(null==this.flagRegistry[e])throw new Error("Cannot evaluate flag '".concat(e,"': no evaluation function found."));return this.flagRegistry[e].evaluationFn()},e.prototype.setFlags=function(e){this.flags=Object.assign({},e)},e.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},e.prototype.populateURLFlags=function(){var e=this;if("undefined"!=typeof this.global&&"undefined"!=typeof this.global.location&&"undefined"!=typeof this.global.location.search){var t=this.getQueryParams(this.global.location.search);if(V in t)t.tfjsflags.split(",").forEach((function(t){var n=s(t.split(":"),2),r=n[0],a=n[1];e.urlFlags[r]=function(e,t){var n=t.toLowerCase();return"true"===n||"false"===n?"true"===n:"".concat(+n)===n?+n:t}(0,a)}))}},e}();function j(e){var t={};return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,(function(e){for(var n=[],r=1;r>>=0)&&e<256)&&(r=Zn[e])?r:(n=Qn(e,(0|e)<0?-1:0,!0),a&&(Zn[e]=n),n):(a=-128<=(e|=0)&&e<128)&&(r=Jn[e])?r:(n=Qn(e,e<0?-1:0,!1),a&&(Jn[e]=n),n)}function Xn(e,t){if(isNaN(e))return t?sr:ir;if(t){if(e<0)return sr;if(e>=rr)return fr}else{if(e<=-ar)return dr;if(e+1>=ar)return hr}return e<0?Xn(-e,t).neg():Qn(e%nr|0,e/nr|0,t)}function Qn(e,t,n){return new Hn(e,t,n)}Hn.fromInt=Yn,Hn.fromNumber=Xn,Hn.fromBits=Qn;var $n=Math.pow;function er(e,t,n){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return ir;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||360)throw Error("interior hyphen");if(0===r)return er(e.substring(1),t,n).neg();for(var a=Xn($n(n,8)),o=ir,i=0;i>>0:this.low},pr.toNumber=function(){return this.unsigned?(this.high>>>0)*nr+(this.low>>>0):this.high*nr+(this.low>>>0)},pr.toString=function(e){if((e=e||10)<2||36>>0).toString(e);if((o=s).isZero())return u+i;for(;u.length<6;)u="0"+u;i=""+u+i}},pr.getHighBits=function(){return this.high},pr.getHighBitsUnsigned=function(){return this.high>>>0},pr.getLowBits=function(){return this.low},pr.getLowBitsUnsigned=function(){return this.low>>>0},pr.getNumBitsAbs=function(){if(this.isNegative())return this.eq(dr)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<=0},pr.isOdd=function(){return 1==(1&this.low)},pr.isEven=function(){return 0==(1&this.low)},pr.equals=function(e){return jn(e)||(e=tr(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},pr.eq=pr.equals,pr.notEquals=function(e){return!this.eq(e)},pr.neq=pr.notEquals,pr.ne=pr.notEquals,pr.lessThan=function(e){return this.comp(e)<0},pr.lt=pr.lessThan,pr.lessThanOrEqual=function(e){return this.comp(e)<=0},pr.lte=pr.lessThanOrEqual,pr.le=pr.lessThanOrEqual,pr.greaterThan=function(e){return this.comp(e)>0},pr.gt=pr.greaterThan,pr.greaterThanOrEqual=function(e){return this.comp(e)>=0},pr.gte=pr.greaterThanOrEqual,pr.ge=pr.greaterThanOrEqual,pr.compare=function(e){if(jn(e)||(e=tr(e)),this.eq(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},pr.comp=pr.compare,pr.negate=function(){return!this.unsigned&&this.eq(dr)?dr:this.not().add(ur)},pr.neg=pr.negate,pr.add=function(e){jn(e)||(e=tr(e));var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,o=e.high>>>16,i=65535&e.high,s=e.low>>>16,u=0,c=0,l=0,h=0;return l+=(h+=a+(65535&e.low))>>>16,c+=(l+=r+s)>>>16,u+=(c+=n+i)>>>16,u+=t+o,Qn((l&=65535)<<16|(h&=65535),(u&=65535)<<16|(c&=65535),this.unsigned)},pr.subtract=function(e){return jn(e)||(e=tr(e)),this.add(e.neg())},pr.sub=pr.subtract,pr.multiply=function(e){if(this.isZero())return ir;if(jn(e)||(e=tr(e)),Vn)return Qn(Vn.mul(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned);if(e.isZero())return ir;if(this.eq(dr))return e.isOdd()?dr:ir;if(e.eq(dr))return this.isOdd()?dr:ir;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(or)&&e.lt(or))return Xn(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,a=65535&this.low,o=e.high>>>16,i=65535&e.high,s=e.low>>>16,u=65535&e.low,c=0,l=0,h=0,f=0;return h+=(f+=a*u)>>>16,l+=(h+=r*u)>>>16,h&=65535,l+=(h+=a*s)>>>16,c+=(l+=n*u)>>>16,l&=65535,c+=(l+=r*s)>>>16,l&=65535,c+=(l+=a*i)>>>16,c+=t*u+n*s+r*i+a*o,Qn((h&=65535)<<16|(f&=65535),(c&=65535)<<16|(l&=65535),this.unsigned)},pr.mul=pr.multiply,pr.divide=function(e){if(jn(e)||(e=tr(e)),e.isZero())throw Error("division by zero");var t,n,r;if(Vn)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?Qn((this.unsigned?Vn.div_u:Vn.div_s)(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?sr:ir;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return sr;if(e.gt(this.shru(1)))return cr;r=sr}else{if(this.eq(dr))return e.eq(ur)||e.eq(lr)?dr:e.eq(dr)?ur:(t=this.shr(1).div(e).shl(1)).eq(ir)?e.isNegative()?ur:lr:(n=this.sub(e.mul(t)),r=t.add(n.div(e)));if(e.eq(dr))return this.unsigned?sr:ir;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=ir}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(t)/Math.LN2),o=a<=48?1:$n(2,a-48),i=Xn(t),s=i.mul(e);s.isNegative()||s.gt(n);)s=(i=Xn(t-=o,this.unsigned)).mul(e);i.isZero()&&(i=ur),r=r.add(i),n=n.sub(s)}return r},pr.div=pr.divide,pr.modulo=function(e){return jn(e)||(e=tr(e)),Vn?Qn((this.unsigned?Vn.rem_u:Vn.rem_s)(this.low,this.high,e.low,e.high),Vn.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},pr.mod=pr.modulo,pr.rem=pr.modulo,pr.not=function(){return Qn(~this.low,~this.high,this.unsigned)},pr.and=function(e){return jn(e)||(e=tr(e)),Qn(this.low&e.low,this.high&e.high,this.unsigned)},pr.or=function(e){return jn(e)||(e=tr(e)),Qn(this.low|e.low,this.high|e.high,this.unsigned)},pr.xor=function(e){return jn(e)||(e=tr(e)),Qn(this.low^e.low,this.high^e.high,this.unsigned)},pr.shiftLeft=function(e){return jn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Qn(this.low<>>32-e,this.unsigned):Qn(0,this.low<>>e|this.high<<32-e,this.high>>e,this.unsigned):Qn(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},pr.shr=pr.shiftRight,pr.shiftRightUnsigned=function(e){if(jn(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?Qn(this.low>>>e|t<<32-e,t>>>e,this.unsigned):Qn(32===e?t:t>>>e-32,0,this.unsigned)},pr.shru=pr.shiftRightUnsigned,pr.shr_u=pr.shiftRightUnsigned,pr.toSigned=function(){return this.unsigned?Qn(this.low,this.high,!1):this},pr.toUnsigned=function(){return this.unsigned?this:Qn(this.low,this.high,!0)},pr.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},pr.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},pr.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},Hn.fromBytes=function(e,t,n){return n?Hn.fromBytesLE(e,t):Hn.fromBytesBE(e,t)},Hn.fromBytesLE=function(e,t){return new Hn(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},Hn.fromBytesBE=function(e,t){return new Hn(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};var gr=qn(Kn),vr=gr||t({__proto__:null,default:gr},[Kn]);function mr(e){return vr.fromString(e,!0,16)}var yr=mr("c3a5c85c97cb3127"),br=mr("b492b66fbe98f273"),wr=mr("9ae16a3b2f90404f");function kr(e){return e.xor(e.shru(47))}function xr(e,t,n){var r=e.slice(t,t+n);return vr.fromBytes(Array.from(r),!0,!0)}function Er(e,t){return xr(e,t,8)}function Sr(e,t){return xr(e,t,4)}function Ar(e,t){return 0===t?e:e.shru(t).or(e.shl(64-t))}function _r(e,t,n){void 0===n&&(n=mr("9ddfea08eb382d69"));var r=e.xor(t).mul(n);r=r.xor(r.shru(47));var a=t.xor(r).mul(n);return a=(a=a.xor(a.shru(47))).mul(n)}function Ir(e,t,n,r){return function(e,t,n,r,a,o){a=a.add(e),o=Ar(o.add(a).add(r),21);var i=a;return a=(a=a.add(t)).add(n),o=o.add(Ar(a,44)),[a.add(r),o.add(i)]}(Er(e,t),Er(e,t+8),Er(e,t+16),Er(e,t+24),n,r)}function Nr(e,t){if("string"===t)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=Br(e)),Z().getBool("DEBUG")&&I(e,t),function(e,t){return e instanceof Float32Array&&"float32"===t||e instanceof Int32Array&&"int32"===t||e instanceof Uint8Array&&"bool"===t}(e,t))return e;if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t){for(var n=new Uint8Array(e.length),r=0;r=8){var n=wr.add(2*t),r=Er(e,0).add(wr);return _r(Ar(a=Er(e,t-8),37).mul(n).add(r),Ar(r,25).add(a).mul(n),n)}if(t>=4)return n=wr.add(2*t),_r((r=Sr(e,0)).shl(3).add(t),Sr(e,t-4),n);if(t>0){var a,o=(r=e[0])+((a=e[t>>1])<<8),i=t+(e[t-1]<<2);return kr(wr.mul(o).xor(yr.mul(i))).mul(wr)}return wr}(e,t):function(e,t){void 0===t&&(t=e.length);var n=wr.add(2*t),r=Er(e,0).mul(br),a=Er(e,8),o=Er(e,t-8).mul(n),i=Er(e,t-16).mul(wr);return _r(Ar(r.add(a),43).add(Ar(o,30)).add(i),r.add(Ar(a.add(wr),18)).add(o),n)}(e,t);if(t<=64)return function(e,t){void 0===t&&(t=e.length);var n=wr.add(2*t),r=Er(e,0).mul(wr),a=Er(e,8),o=Er(e,t-8).mul(n),i=Er(e,t-16).mul(wr),s=Ar(r.add(a),43).add(Ar(o,30)).add(i),u=_r(s,r.add(Ar(a.add(wr),18)).add(o),n),c=Er(e,16).mul(n),l=Er(e,24),h=s.add(Er(e,t-32)).mul(n),f=u.add(Er(e,t-24)).mul(n);return _r(Ar(c.add(l),43).add(Ar(h,30)).add(f),c.add(Ar(l.add(r),18)).add(h),n)}(e,t);var o=a,i=a.mul(br).add(113),u=kr(i.mul(wr).add(113)).mul(wr),c=[vr.UZERO,vr.UZERO],l=[vr.UZERO,vr.UZERO];o=o.mul(wr).add(Er(e,0));var h=0,f=64*(t-1>>6),d=f+(t-1&63)-63;do{o=Ar(o.add(i).add(c[0]).add(Er(e,h+8)),37).mul(br),i=Ar(i.add(c[1]).add(Er(e,h+48)),42).mul(br),o=o.xor(l[1]),i=i.add(c[0]).add(Er(e,h+40)),u=Ar(u.add(l[0]),33).mul(br),c=Ir(e,h,c[1].mul(br),o.add(l[0])),l=Ir(e,h+32,u.add(l[1]),i.add(Er(e,h+16))),u=(n=s([o,u],2))[0],o=n[1],h+=64}while(h!==f);var p=br.add(u.and(255).shl(1));return h=d,l[0]=l[0].add(t-1&63),c[0]=c[0].add(l[0]),l[0]=l[0].add(c[0]),o=Ar(o.add(i).add(c[0]).add(Er(e,h+8)),37).mul(p),i=Ar(i.add(c[1]).add(Er(e,h+48)),42).mul(p),o=o.xor(l[1].mul(9)),i=i.add(c[0].mul(9).add(Er(e,h+40))),u=Ar(u.add(l[0]),33).mul(p),c=Ir(e,h,c[1].mul(p),o.add(l[0])),l=Ir(e,h+32,u.add(l[1]),i.add(Er(e,h+16))),u=(r=s([o,u],2))[0],o=r[1],_r(_r(c[0],l[0],p).add(kr(i).mul(yr)).add(u),_r(c[1],l[1],p).add(o),p)},flatten:Br,getArrayFromDType:_,getTypedArrayFromDType:A,hasEncodingLoss:function(e,t){return"complex64"!==t&&(("float32"!==t||"complex64"===e)&&(("int32"!==t||"float32"===e||"complex64"===e)&&("bool"!==t||"bool"!==e)))},hexToLong:mr,indexToLoc:function(e,t,n){if(0===t)return[];if(1===t)return[e];for(var r=new Array(t),a=0;a=0)n*=e[a];else if(-1===e[a]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. "+"Found -1 at dim ".concat(r," and dim ").concat(a));r=a}else if(e[a]<0)throw Error("Shapes can not be < 0. Found ".concat(e[a]," at dim ").concat(a));if(-1===r){if(t>0&&t!==n)throw Error("Size(".concat(t,") must match the product of shape ").concat(e));return e}if(0===n)throw Error("Cannot infer the missing size in [".concat(e,"] when ")+"there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. "+"Got ".concat(t," / ").concat(n));var o=e.slice();return o[r]=t/n,o},isBoolean:R,isFunction:C,isInt:k,isNumber:B,isPromise:q,isScalarShape:function(e){return 0===e.length},isString:D,isTypedArray:Rr,isValidDtype:N,locToIndex:function(e,t,n){if(0===t)return 0;if(1===t)return e[0];for(var r=e[e.length-1],a=0;a=n?o():null!=r?r(s,u):setTimeout(s,u)}};s()}))},rightPad:x,shuffle:f,shuffleCombo:function(e,t){if(e.length!==t.length)throw new Error("Array sizes must match to be shuffled together "+"First array length was ".concat(e.length)+"Second array length was ".concat(t.length));for(var n=e.length,r=0;n>0;)r=Math.random()*n|0,p(e,--n,r),p(t,n,r)},sizeFromShape:y,sizeToSquarishShape:function(e){var t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)]},squeezeShape:S,sum:function(e){for(var t=0,n=0;n0?p:""," ")}}console.log("%c".concat(s,"\t%c").concat(i,"\t%c").concat(u,"D ").concat(l,"\t%c").concat(c,"\t%c").concat(h,"\t%c").concat(o),"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}();function Or(e,t,n,r){var a=O(t),o=function(e,t,n,r){var a=y(t),o=r[r.length-1],i=new Array(o).fill(0),s=t.length,u="complex64"===n?Wr(e):e;if(s>1)for(var c=0;c20){var h=3*i,f=Array.from(e.slice(0,h)),d=Array.from(e.slice((c-3)*i,c*i));return"complex64"===n&&(f=Wr(f),d=Wr(d)),["["+f.map((function(e,t){return Lr(e,a[t],n)})).join(", ")+", ..., "+d.map((function(e,t){return Lr(e,a[c-3+t],n)})).join(", ")+"]"]}return["["+("complex64"===n?Wr(e):Array.from(e)).map((function(e,t){return Lr(e,a[t],n)})).join(", ")+"]"]}var p=t.slice(1),g=r.slice(1),v=r[0]*i,m=[];if(c>20){for(var y=0;y<3;y++){var b=(w=y*v)+v;m.push.apply(m,u([],s(Ur(e.slice(w,b),p,n,g,a,!1)),!1))}m.push("...");for(y=c-3;y0?m[0]+k:"");for(y=1;y=this.shape[a]){var c="Requested out of range element at ".concat(n,". ")+" Buffer shape=".concat(this.shape);throw new Error(c)}a++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}for(var l=n[n.length-1],h=0;h0)throw new Error("Backend '".concat(this.backendName,"' has an internal memory leak ")+"(".concat(i," data ids) after running '").concat(e,"'"))},e.prototype.runKernelFunc=function(e){var t,n,r,a=this,o=[],i=this.isTapeOn(),s=this.state.numBytes,u=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0),null==this.backendName&&this.backend;var c=ua(e)?e.kernelName:null!=this.state.activeScope?this.state.activeScope.name:"";if(ua(e)){var l=e.kernelName,h=e.inputs,f=e.attrs;null==this.backendName&&this.backend;var d=Pn(l,this.backendName);g(null!=d,(function(){return"Cannot find registered kernel '".concat(l,"' for backend '").concat(a.backendName,"'")})),n=function(){var e=a.backend.numDataIds();r=d.kernelFunc({inputs:h,attrs:f,backend:a.backend});var t=Array.isArray(r)?r:[r];a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(l,e,t);var n=t.map((function(e){return null!=e.rank?e:a.makeTensorFromTensorInfo(e)}));if(i){var s=a.getTensorsForGradient(l,h,n);o=a.saveTensorsForBackwardMode(s)}return n}}else{var p=e.forwardFunc,v=function(e){i&&(o=e.map((function(e){return a.keep(a.clone(e))})))};n=function(){var e=a.backend.numDataIds();r=a.tidy((function(){return p(a.backend,v)}));var t=Array.isArray(r)?r:[r];return a.shouldCheckForMemLeaks()&&a.checkKernelForMemLeak(c,e,t),t}}var m,y=e.inputs,b=e.attrs,w=ua(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(c,y,(function(){return n()})),a.ENV.getBool("DEBUG")&&a.profiler.logKernelProfile(m),t=m.outputs):t=n()})),i&&this.addTapeNode(c,y,t,w,o,b),this.state.profiling&&this.state.activeProfile.kernels.push({name:c,bytesAdded:this.state.numBytes-s,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-u,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(y).map((function(e){return null!=y[e]?y[e].shape:null})),outputShapes:t.map((function(e){return e.shape})),kernelTimeMs:m.timeMs,extraInfo:m.extraInfo}),Array.isArray(r)?t:t[0]},e.prototype.saveTensorsForBackwardMode=function(e){var t=this,n=e.map((function(e){return t.keep(t.clone(e))}));return n},e.prototype.getTensorsForGradient=function(e,t,n){var r=On(e);if(null!=r){var a=r.inputsToSave||[],o=r.outputsToSave||[],i=void 0;r.saveAllInputs?(g(Array.isArray(t),(function(){return"saveAllInputs is true, expected inputs to be an array."})),i=Object.keys(t).map((function(e){return t[e]}))):i=a.map((function(e){return t[e]}));var s=n.filter((function(e,t){return o[t]}));return i.concat(s)}return[]},e.prototype.makeTensor=function(e,t,n,r){if(null==e)throw new Error("Values passed to engine.makeTensor() are null");n=n||"float32",r=r||this.backend;var a=e;"string"===n&&D(e[0])&&(a=e.map((function(e){return Tr(e)})));var o=r.write(a,t,n),i=new Vr(t,n,o,this.nextTensorId());if(this.trackTensor(i,r),"string"===n){var s=this.state.tensorInfo.get(o),u=T(a);this.state.numBytes+=u-s.bytes,s.bytes=u}return i},e.prototype.makeTensorFromDataId=function(e,t,n,r){var a={dataId:e,shape:t,dtype:n=n||"float32"};return this.makeTensorFromTensorInfo(a,r)},e.prototype.makeTensorFromTensorInfo=function(e,t){var n=e.dataId,r=e.shape,a=e.dtype,o=new Vr(r,a,n,this.nextTensorId());return this.trackTensor(o,t),o},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 Qr(e,t,n,this.nextTensorId());if(null!=this.state.registeredVariables[a.name])throw new Error("Variable with name ".concat(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*M(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 Qr||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*M(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 a(this,void 0,void 0,(function(){var t,n,r,a,c,l,h,f,d,p,g;return o(this,(function(o){switch(o.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=o.sent(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,u([],s(this.state.activeProfile.kernels.map((function(e){return e.totalBytesSnapshot}))),!1)),this.state.activeProfile.newBytes=this.state.numBytes-t,this.state.activeProfile.newTensors=this.state.numTensors-n,o.label=2;case 2:o.trys.push([2,8,9,10]),a=i(this.state.activeProfile.kernels),c=a.next(),o.label=3;case 3:return c.done?[3,7]:(l=c.value,h=l,[4,l.kernelTimeMs]);case 4:return h.kernelTimeMs=o.sent(),f=l,[4,l.extraInfo];case 5:f.extraInfo=o.sent(),o.label=6;case 6:return c=a.next(),[3,3];case 7:return[3,10];case 8:return d=o.sent(),p={error:d},[3,10];case 9:try{c&&!c.done&&(g=a.return)&&g.call(a)}finally{if(p)throw p.error}return[7];case 10:return[2,this.state.activeProfile]}}))}))},e.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&0===this.state.kernelDepth},e.prototype.addTapeNode=function(e,t,n,r,a,o){var i=this,s={id:this.state.nextTapeNodeId++,kernelName:e,inputs:t,outputs:n,saved:a},u=On(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=W(r.size,r.dtype);return i.makeTensor(a,r.shape,r.dtype)}return e})),r(e.length>1?e:e[0],a,o)}),this.state.activeTape.push(s)},e.prototype.keep=function(e){return e.kept=!0,e},e.prototype.startTape=function(){0===this.state.gradientDepth&&(this.state.activeTape=[]),this.state.gradientDepth++},e.prototype.endTape=function(){this.state.gradientDepth--},e.prototype.startScope=function(e){var t={track:[],name:"unnamed scope",id:this.state.nextScopeId++};e&&(t.name=e),this.state.scopeStack.push(t),this.state.activeScope=t},e.prototype.endScope=function(e){for(var t=this,n=oa(e),r=new Set(n.map((function(e){return e.id}))),a=0;a0,(function(){return"gradients() received an empty list of xs."})),null!=n&&"float32"!==n.dtype)throw new Error("dy must have 'float32' dtype, but has '".concat(n.dtype,"'"));var o=this.scopedRun((function(){return a.startTape()}),(function(){return a.endTape()}),(function(){return a.tidy("forward",e)}));g(o instanceof Vr,(function(){return"The result y returned by f() must be a tensor."}));var s=function(e,t,n){for(var r={},a={},o=0;o=0;o--)for(i=(p=e[o]).inputs,l=0;l0)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,u={};u[o.id]=null==n?(e=o.shape,r=U(y(e),"float32"),da.makeTensor(r,e,"float32")):n,function(e,t,n,r){for(var a=function(a){var o=t[a],i=[];if(o.outputs.forEach((function(t){var n=e[t.id];null!=n?i.push(n):i.push(null)})),null==o.gradient)throw new Error("Cannot compute gradient: gradient function not found "+"for ".concat(o.kernelName,"."));var s=o.gradient(i),u=function(t){if(!(t in s))throw new Error("Cannot backprop through input ".concat(t,". ")+"Available gradients found: ".concat(Object.keys(s),"."));var a=n((function(){return s[t]()}));if("float32"!==a.dtype)throw new Error("Error in gradient for op ".concat(o.kernelName,". The gradient of input ")+"".concat(t," must have 'float32' dtype, but has '").concat(a.dtype,"'"));var i=o.inputs[t];if(!w(a.shape,i.shape))throw new Error("Error in gradient for op ".concat(o.kernelName,". The gradient of input ")+"'".concat(t,"' has shape '").concat(a.shape,"', which does not match ")+"the shape of the input '".concat(i.shape,"'"));if(null==e[i.id])e[i.id]=a;else{var u=e[i.id];e[i.id]=r(u,a),u.dispose()}};for(var c in o.inputs)u(c)},o=t.length-1;o>=0;o--)a(o)}(u,s,(function(e){return a.tidy(e)}),pa);var c=t.map((function(e){return u[e.id]}));return 0===a.state.gradientDepth&&(a.state.activeTape.forEach((function(e){var t,n;try{for(var r=i(e.saved),a=r.next();!a.done;a=r.next()){a.value.dispose()}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}})),a.state.activeTape=null),{value:o,grads:c}}))},e.prototype.customGrad=function(e){var t=this;return g(C(e),(function(){return"The f passed in customGrad(f) must be a function."})),function(){for(var n,r=[],a=0;a0,(function(){return"Element arr[".concat(n.join("]["),"] should be a primitive, ")+"but is an array of ".concat(e.length," elements")})),g(e.length===t[0],(function(){return"Element arr[".concat(n.join("]["),"] should have ").concat(t[0]," ")+"elements, but has ".concat(e.length," elements")}));for(var r=t.slice(1),a=0;a=0&&(a=r),wa(r,a,t,n),null==e||!Rr(e)&&!Array.isArray(e)&&"number"!=typeof e&&"boolean"!=typeof e&&"string"!=typeof e){var o=null==e?"null":e.constructor.name;throw new Error("Argument '".concat(t,"' passed to '").concat(n,"' must be a ")+"Tensor or TensorLike, but got '".concat(o,"'"))}var i=ya(e,a);Rr(e)||Array.isArray(e)||(e=[e]);var s="string"!==a?Nr(e,a):Br(e,[],!0);return da.makeTensor(s,i,a)}function xa(e,t,n,r){if(void 0===r&&(r="numeric"),!Array.isArray(e))throw new Error("Argument ".concat(t," passed to ").concat(n," must be a ")+"`Tensor[]` or `TensorLike[]`");return e.map((function(e,a){return ka(e,"".concat(t,"[").concat(a,"]"),n,r)}))}ma.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.")})),ma.registerFlag("IS_BROWSER",(function(){return ga()})),ma.registerFlag("IS_NODE",(function(){return"undefined"!=typeof process&&"undefined"!=typeof process.versions&&"undefined"!=typeof process.versions.node})),ma.registerFlag("IS_CHROME",(function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)})),ma.registerFlag("IS_SAFARI",(function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Safari/.test(navigator.userAgent)&&/Apple/.test(navigator.vendor)})),ma.registerFlag("PROD",(function(){return!1})),ma.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",(function(){return ma.getBool("DEBUG")})),ma.registerFlag("DEPRECATION_WARNINGS_ENABLED",(function(){return!0})),ma.registerFlag("IS_TEST",(function(){return!1})),ma.registerFlag("CHECK_COMPUTATION_FOR_ERRORS",(function(){return ma.getBool("DEBUG")})),ma.registerFlag("WRAP_TO_IMAGEBITMAP",(function(){return!1})),ma.registerFlag("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU",(function(){return!1})),ma.registerFlag("USE_SETTIMEOUTCUSTOM",(function(){return!1}));var Ea="__op";function Sa(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 "+"".concat(t.length," keys."));var n=t[0],r=e[n];n.endsWith("_")&&(n=n.substring(0,n.length-1)),n+=Ea;var a=function(){for(var e=[],t=0;t=this.byteLength)return-1;if(null!=this.bufferUniformSize)return this.previousShardIndex=Math.floor(e/this.bufferUniformSize),this.previousShardIndex;function t(t){return e=t.end?1:0}if(0===t(this.shards[this.previousShardIndex]))return this.previousShardIndex;var n=function(e,t){var n=0,r=e.length;for(;n<=r;){var a=Math.floor((r-n)/2)+n,o=t(e[a]);if(0===o)return a;o<0?r=a:n=a+1}return-1}(this.shards,t);return-1===n?-1:(this.previousShardIndex=n,this.previousShardIndex)},e}();function Ta(e,t){return da.tidy(e,t)}function Da(e){oa(e).forEach((function(e){return e.dispose()}))}function Ra(e){return da.keep(e)}function Ba(){return da.backendName}function Fa(){return da.backend}function Ca(e,t){var n,r,a=new Ma(e),o={},s=0;try{for(var u=i(t),c=u.next();!c.done;c=u.next()){var l=c.value,h=Pa(l,(function(e,t){return a.slice(s+e,s+t)}));o[l.name]=La(l,a.slice(s,s+h)),s+=h}}catch(e){n={error:e}}finally{try{c&&!c.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}return o}function Pa(e,t){var n,r=y(e.shape);if("quantization"in e){var a=e.quantization;n=Na[a.dtype]}else{if("string"===e.dtype){for(var o=0,i=0;i>10]+(1023&s)]+a[s>>10];n[i]=u}return new Float32Array(t)});n=v(d)}else{if("int32"!==s)throw new Error("Unsupported dtype in weight '".concat(i,"': ").concat(s));if("uint8"!==h.dtype&&"uint16"!==h.dtype)throw new Error("Unsupported quantization type ".concat(h.dtype," ")+"for weight type int32.");n=new Int32Array(d.length);for(p=0;p0,(function(){return"scheme must not be an empty string."}));var r=e.getInstance();g(null==r.managers[t],(function(){return"A model store manager is already registered for scheme '".concat(t,"'.")})),r.managers[t]=n},e.getManager=function(t){var n=e.getInstance().managers[t];if(null==n)throw new Error("Cannot find model manager for scheme '".concat(t,"'"));return n},e.getSchemes=function(){return Object.keys(e.getInstance().managers)},e}();function wo(e){if(-1===e.indexOf(yo))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+"".concat(bo.getSchemes().join(",")));return{scheme:e.split(yo)[0],path:e.split(yo)[1]}}function ko(e,t,n){return void 0===n&&(n=!1),a(this,void 0,void 0,(function(){var r,a,i,s,u,c,l,h,f;return o(this,(function(o){switch(o.label){case 0:return g(e!==t,(function(){return"Old path and new path are the same: '".concat(e,"'")})),g((r=Za.getLoadHandlers(e)).length>0,(function(){return"Copying failed because no load handler is found for source URL ".concat(e,".")})),g(r.length<2,(function(){return"Copying failed because more than one (".concat(r.length,") ")+"load handlers for source URL ".concat(e,".")})),a=r[0],g((i=Za.getSaveHandlers(t)).length>0,(function(){return"Copying failed because no save handler is found for destination "+"URL ".concat(t,".")})),g(i.length<2,(function(){return"Copying failed because more than one (".concat(r.length,") ")+"save handlers for destination URL ".concat(t,".")})),s=i[0],u=wo(e).scheme,c=wo(e).path,l=u===wo(e).scheme,[4,a.load()];case 1:return h=o.sent(),n&&l?[4,bo.getManager(u).removeModel(c)]:[3,3];case 2:o.sent(),o.label=3;case 3:return[4,s.save(h)];case 4:return f=o.sent(),!n||l?[3,6]:[4,bo.getManager(u).removeModel(c)];case 5:o.sent(),o.label=6;case 6:return[2,f.modelArtifactsInfo]}}))}))}var xo=function(){function e(){this.messageName="setTimeoutCustom",this.functionRefs=[],this.handledMessageCount=0,this.hasEventListener=!1}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 ".concat(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.prototype.setTimeoutCustom=function(e,t){var n=this;"undefined"!=typeof window&&Z().getBool("USE_SETTIMEOUTCUSTOM")?(this.functionRefs.push(e),setTimeout((function(){window.postMessage({name:n.messageName,index:n.functionRefs.length-1},"*")}),t),this.hasEventListener||(this.hasEventListener=!0,window.addEventListener("message",(function(e){e.source===window&&e.data.name===n.messageName&&(e.stopPropagation(),(0,n.functionRefs[e.data.index])(),n.handledMessageCount++,n.handledMessageCount===n.functionRefs.length&&(n.functionRefs=[],n.handledMessageCount=0))}),!0))):setTimeout(e,t)},e.prototype.isTypedArray=function(e){return Wn(e)},e}();if(Z().get("IS_BROWSER")){Z().setPlatform("browser",new xo);try{bo.registerManager(go.URL_SCHEME,new mo)}catch(e){}try{bo.registerManager(to.URL_SCHEME,new ro)}catch(e){}}var Eo,So=function(){return require("node-fetch")},Ao=function(){function e(){this.util=require("util"),this.textEncoder=new this.util.TextEncoder}return e.prototype.fetch=function(e,t){return null!=Z().global.fetch?Z().global.fetch(e,t):(null==Eo&&(Eo=So()),Eo(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 ".concat(t));return this.textEncoder.encode(e)},e.prototype.decode=function(e,t){return 0===e.length?"":new this.util.TextDecoder(t).decode(e)},e.prototype.isTypedArray=function(e){return this.util.types.isFloat32Array(e)||this.util.types.isInt32Array(e)||this.util.types.isUint8Array(e)||this.util.types.isUint8ClampedArray(e)},e}();function _o(e,t,n){return void 0===t&&(t="float32"),t=t||"float32",G(e),new Gr(e,t,n)}Z().get("IS_NODE")&&!Z().get("IS_BROWSER")&&Z().setPlatform("node",new Ao);var Io=Sa({cast_:function(e,t){var n=ka(e,"x","cast");if(!N(t))throw new Error("Failed to cast to unknown dtype ".concat(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 da.runKernel(ve,r,a)}});var No=Sa({clone_:function(e){var t={x:ka(e,"x","clone","string_or_numeric")};return da.runKernel($e,t)}});function Mo(e,t){void 0===t&&(t=!1),console.log(e.toString(t))}ha(),Kr={buffer:_o,cast:Io,clone:No,print:Mo};var To=Sa({add_:function(e,t){var n,r=ka(e,"a","add"),a=ka(t,"b","add"),o={a:r=(n=s(ra(r,a),2))[0],b:a=n[1]};return da.runKernel(ee,o)}});var Do=Sa({floorDiv_:function(e,t){var n,r=ka(e,"a","floorDiv"),a=ka(t,"b","floorDiv"),o={a:r=(n=s(ra(r,a),2))[0],b:a=n[1]};return da.runKernel(je,o)}});var Ro=Sa({div_:function(e,t){var n,r=ka(e,"a","div"),a=ka(t,"b","div");if(r=(n=s(ra(r,a),2))[0],a=n[1],"int32"===r.dtype&&"int32"===a.dtype)return Do(r,a);var o={a:r,b:a};return da.runKernel(ze,o,{})}});var Bo=Sa({mul_:function(e,t){var n,r=ka(e,"a","mul"),a=ka(t,"b","mul"),o={a:r=(n=s(ra(r,a),2))[0],b:a=n[1]};return da.runKernel(kt,o)}});var Fo=Sa({abs_:function(e){var t=ka(e,"x","abs");if("complex64"===t.dtype){var n={x:t};return da.runKernel(we,n)}return n={x:t},da.runKernel("Abs",n)}});var Co=Sa({acos_:function(e){var t={x:ka(e,"x","acos")};return da.runKernel(Q,t)}});var Po=Sa({acosh_:function(e){var t={x:ka(e,"x","acosh")};return da.runKernel($,t)}});var Oo=Sa({addN_:function(e){g(Array.isArray(e),(function(){return"The argument passed to tf.addN() must be a list of tensors"})),g(e.length>=1,(function(){return"Must pass at least one tensor to tf.addN(), but got "+"".concat(e.length)}));var t=e.map((function(e,t){return ka(e,"tensors".concat(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(!w(e.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")}));var r=t;return da.runKernel(te,r)}});var Lo=Sa({all_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:ka(e,"x","all","bool")},a={axis:t,keepDims:n};return da.runKernel("All",r,a)}});var zo=Sa({any_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:ka(e,"x","any","bool")},a={axis:t,keepDims:n};return da.runKernel("Any",r,a)}});var Uo=Sa({argMax_:function(e,t){void 0===t&&(t=0);var n={x:ka(e,"x","argMax")},r={axis:t};return da.runKernel(ne,n,r)}});var Wo=Sa({argMin_:function(e,t){void 0===t&&(t=0);var n={x:ka(e,"x","argMin")},r={axis:t};return da.runKernel(re,n,r)}});var Go=Sa({asin_:function(e){var t={x:ka(e,"x","asin")};return da.runKernel(ae,t)}});var qo=Sa({asinh_:function(e){var t={x:ka(e,"x","asinh")};return da.runKernel(oe,t)}});var Ko=Sa({atan_:function(e){var t={x:ka(e,"x","atan")};return da.runKernel(ie,t)}});var Vo=Sa({atan2_:function(e,t){var n,r=ka(e,"a","atan2"),a=ka(t,"b","atan2"),o={a:r=(n=s(ra(r,a),2))[0],b:a=n[1]};return da.runKernel(ue,o)}});var Ho=Sa({atanh_:function(e){var t={x:ka(e,"x","atanh")};return da.runKernel(se,t)}});function jo(e,t,n,r,a,o,i){void 0===i&&(i="channelsLast");var u,c=s(Xo(t),2),l=c[0],h=c[1];if("channelsLast"===i)u=[l,h,e[3],e[3]];else{if("channelsFirst"!==i)throw new Error("Unknown dataFormat ".concat(i));u=[l,h,e[1],e[1]]}return Jo(e,u,n,r,a,o,!1,i)}function Jo(e,t,n,r,a,o,i,u){var c,l;void 0===i&&(i=!1),void 0===u&&(u="channelsLast");var h=s([-1,-1,-1,-1],4),f=h[0],d=h[1],p=h[2],g=h[3];if("channelsLast"===u)f=(c=s(e,4))[0],d=c[1],p=c[2],g=c[3];else{if("channelsFirst"!==u)throw new Error("Unknown dataFormat ".concat(u));f=(l=s(e,4))[0],g=l[1],d=l[2],p=l[3]}var v,m=s(t,4),y=m[0],b=m[1],w=m[3],k=s(Xo(n),2),x=k[0],E=k[1],S=s(Xo(r),2),A=S[0],_=S[1],I=$o(y,A),N=$o(b,_),M=function(e,t,n,r,a,o,i,s,u){var c,l,h;if("number"==typeof e){c={top:e,bottom:e,left:e,right:e,type:0===e?"VALID":"NUMBER"};var f=function(e,t,n,r,a){null==r&&(r=Yo(e,t,n));var o=e[0],i=e[1],s=ei((o-t+2*r)/n+1,a),u=ei((i-t+2*r)/n+1,a);return[s,u]}([t,n],o,r,e,s);l=f[0],h=f[1]}else if("same"===e){l=Math.ceil(t/r),h=Math.ceil(n/a);var d=Math.max(0,(l-1)*r+o-t),p=Math.max(0,(h-1)*a+i-n);c={top:g=Math.floor(d/2),bottom:v=d-g,left:m=Math.floor(p/2),right:y=p-m,type:"SAME"}}else if("valid"===e)c={top:0,bottom:0,left:0,right:0,type:"VALID"},l=Math.ceil((t-o+1)/r),h=Math.ceil((n-i+1)/a);else{if("object"!=typeof e)throw Error("Unknown padding parameter: ".concat(e));var g,v,m,y;c={top:g="channelsLast"===u?e[1][0]:e[2][0],bottom:v="channelsLast"===u?e[1][1]:e[2][1],left:m="channelsLast"===u?e[2][0]:e[3][0],right:y="channelsLast"===u?e[2][1]:e[3][1],type:0===g&&0===v&&0===m&&0===y?"VALID":"EXPLICIT"},l=ei((t-o+g+v)/r+1,s),h=ei((n-i+m+y)/a+1,s)}return{padInfo:c,outHeight:l,outWidth:h}}(a,d,p,x,E,I,N,o,u),T=M.padInfo,D=M.outHeight,R=M.outWidth,B=i?w*g:w;return"channelsFirst"===u?v=[f,B,D,R]:"channelsLast"===u&&(v=[f,D,R,B]),{batchSize:f,dataFormat:u,inHeight:d,inWidth:p,inChannels:g,outHeight:D,outWidth:R,outChannels:B,padInfo:T,strideHeight:x,strideWidth:E,filterHeight:y,filterWidth:b,effectiveFilterHeight:I,effectiveFilterWidth:N,dilationHeight:A,dilationWidth:_,inShape:e,outShape:v,filterShape:t}}function Zo(e,t,n,r,a,o,i,u){var c,l;void 0===o&&(o=!1),void 0===i&&(i="channelsLast");var h=s([-1,-1,-1,-1,-1],5),f=h[0],d=h[1],p=h[2],g=h[3],v=h[4];if("channelsLast"===i)f=(c=s(e,5))[0],d=c[1],p=c[2],g=c[3],v=c[4];else{if("channelsFirst"!==i)throw new Error("Unknown dataFormat ".concat(i));f=(l=s(e,5))[0],v=l[1],d=l[2],p=l[3],g=l[4]}var m,y=s(t,5),b=y[0],w=y[1],k=y[2],x=y[4],E=s(Qo(n),3),S=E[0],A=E[1],_=E[2],I=s(Qo(r),3),N=I[0],M=I[1],T=I[2],D=$o(b,N),R=$o(w,M),B=$o(k,T),F=function(e,t,n,r,a,o,i,s,u,c,l){var h,f,d,p;"valid"===e&&(e=0);if("number"==typeof e){h={top:e,bottom:e,left:e,right:e,front:e,back:e,type:0===e?"VALID":"NUMBER"};var g=function(e,t,n,r,a,o){null==a&&(a=Yo(e,t[0],r[0]));for(var i=[0,0,0,n],s=0;s<3;s++)e[s]+2*a>=t[s]&&(i[s]=ei((e[s]-t[s]+2*a)/r[s]+1,o));return i}([t,n,r,1],[s,u,c],1,[a,o,i],e,l);f=g[0],d=g[1],p=g[2]}else{if("same"!==e)throw Error("Unknown padding parameter: ".concat(e));var v=((f=Math.ceil(t/a))-1)*a+s-t,m=((d=Math.ceil(n/o))-1)*o+u-n,y=((p=Math.ceil(r/i))-1)*i+c-r,b=Math.floor(v/2),w=v-b,k=Math.floor(m/2),x=m-k,E=Math.floor(y/2);h={top:k,bottom:x,left:E,right:y-E,front:b,back:w,type:"SAME"}}return{padInfo:h,outDepth:f,outHeight:d,outWidth:p}}(a,d,p,g,S,A,_,D,R,B,u),C=F.padInfo,P=F.outDepth,O=F.outHeight,L=F.outWidth,z=o?x*v:x;return"channelsFirst"===i?m=[f,z,P,O,L]:"channelsLast"===i&&(m=[f,P,O,L,z]),{batchSize:f,dataFormat:i,inDepth:d,inHeight:p,inWidth:g,inChannels:v,outDepth:P,outHeight:O,outWidth:L,outChannels:z,padInfo:C,strideDepth:S,strideHeight:A,strideWidth:_,filterDepth:b,filterHeight:w,filterWidth:k,effectiveFilterDepth:D,effectiveFilterHeight:R,effectiveFilterWidth:B,dilationDepth:N,dilationHeight:M,dilationWidth:T,inShape:e,outShape:m,filterShape:t}}function Yo(e,t,n,r){void 0===r&&(r=1);var a=$o(t,r);return Math.floor((e[0]*(n-1)-n+a)/2)}function Xo(e){return"number"==typeof e?[e,e,e]:2===e.length?[e[0],e[1],1]:e}function Qo(e){return"number"==typeof e?[e,e,e]:e}function $o(e,t){return t<=1?e:e+(e-1)*(t-1)}function ei(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 ".concat(t))}}function ti(e){var t=s(Xo(e),3),n=t[0],r=t[1],a=t[2];return 1===n&&1===r&&1===a}function ni(e,t){return ti(e)||ti(t)}function ri(e){return Xo(e).every((function(e){return e>0}))}function ai(e){if("NHWC"===e)return"channelsLast";if("NCHW"===e)return"channelsFirst";throw new Error("Unknown dataFormat ".concat(e))}function oi(e,t,n){if(null!=n){if("string"==typeof t)throw Error("Error in ".concat(e,": pad must be an integer when using ")+"dimRoundingMode ".concat(n," but got pad ").concat(t,"."));if("number"==typeof t)g(k(t),(function(){return"Error in ".concat(e,": pad must be an integer when using ")+"dimRoundingMode ".concat(n," but got pad ").concat(t,".")}));else{if("object"!=typeof t)throw Error("Error in ".concat(e,": Unknown padding parameter: ").concat(t));t.forEach((function(t){t.forEach((function(t){g(k(t),(function(){return"Error in ".concat(e,": pad must be an integer when using ")+"dimRoundingMode ".concat(n," but got pad ").concat(t,".")}))}))}))}}}var ii=Sa({reshape_:function(e,t){var n={x:ka(e,"x","reshape","string_or_numeric")},r={shape:t};return da.runKernel(zt,n,r)}});var si=Sa({avgPool_:function(e,t,n,r,a){var o=ka(e,"x","avgPool","float32");g(ni(n,1),(function(){return"Error in avgPool: Either strides or dilations must be 1. "+"Got strides ".concat(n," and dilations '").concat(1,"'")}));var i=o,s=!1;3===o.rank&&(s=!0,i=ii(o,[1,o.shape[0],o.shape[1],o.shape[2]])),g(4===i.rank,(function(){return"Error in avgPool: x must be rank 4 but got rank ".concat(i.rank,".")})),oi("avgPool",r,a);var u={x:i},c={filterSize:t,strides:n,pad:r,dimRoundingMode:a},l=da.runKernel(ce,u,c);return l=Io(l,o.dtype),s?ii(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var ui=Sa({avgPool3d_:function(e,t,n,r,a,o){void 0===o&&(o="NDHWC");var i=ka(e,"x","avgPool3d","float32"),s=i,u=!1;4===i.rank&&(u=!0,s=ii(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),g(5===s.rank,(function(){return"Error in avgPool3d: x must be rank 5 but got rank ".concat(s.rank,".")})),g("NDHWC"===o,(function(){return"Error in avgPool3d: Only NDHWC is currently supported, "+"but got dataFormat of ".concat(o)})),g("number"==typeof n&&n>0||Array.isArray(n)&&n[0]>0&&n[1]>0&&n[2]>0,(function(){return"Error in avgPool3d: Stride must be > 0, but got '".concat(n,"'")})),oi("avgPool3d",r,a);var c={x:s},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:o},h=da.runKernel(le,c,l);return h=Io(h,s.dtype),u?ii(h,[h.shape[1],h.shape[2],h.shape[3],h.shape[4]]):h}});var ci=Sa({concat_:function(e,t){void 0===t&&(t=0),g(e.length>=1,(function(){return"Pass at least one tensor to concat"}));var n=xa(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 ".concat(e.dtype,". "))})),1===n.length)return No(n[0]);var r=n,a={axis:t};return da.runKernel(ke,r,a)}});var li=Sa({matMul_:function(e,t,n,r){var a;void 0===n&&(n=!1),void 0===r&&(r=!1);var o=ka(e,"a","matMul"),i=ka(t,"b","matMul"),u={a:o=(a=s(ra(o,i),2))[0],b:i=a[1]},c={transposeA:n,transposeB:r};return da.runKernel(he,u,c)}});var hi=Sa({sigmoid_:function(e){var t={x:ka(e,"x","sigmoid","float32")};return da.runKernel(en,t)}});var fi=Sa({slice_:function(e,t,n){var r=ka(e,"x","slice","string_or_numeric");if(0===r.rank)throw new Error("Slicing scalar is not possible");var a={x:r},o={begin:t,size:n};return da.runKernel(Xt,a,o)}});var di=Sa({tanh_:function(e){var t={x:ka(e,"x","tanh","float32")};return da.runKernel(yn,t)}});var pi=Sa({basicLSTMCell_:function(e,t,n,r,a,o){var i=ka(e,"forgetBias","basicLSTMCell"),s=ka(t,"lstmKernel","basicLSTMCell"),u=ka(n,"lstmBias","basicLSTMCell"),c=ka(r,"data","basicLSTMCell"),l=ka(a,"c","basicLSTMCell"),h=ka(o,"h","basicLSTMCell"),f=ci([c,h],1),d=li(f,s),p=To(d,u),g=p.shape[0],v=p.shape[1]/4,m=[g,v],y=fi(p,[0,0],m),b=fi(p,[0,v],m),w=fi(p,[0,2*v],m),k=fi(p,[0,3*v],m),x=To(Bo(hi(y),di(b)),Bo(l,hi(To(i,w))));return[x,Bo(di(x),hi(k))]}});var gi=Sa({batchToSpaceND_:function(e,t,n){var r=ka(e,"x","batchToSpaceND"),a=t.reduce((function(e,t){return e*t}));g(r.rank>=1+t.length,(function(){return"input rank is ".concat(r.rank," but should be > than blockShape.length ").concat(t.length)})),g(n.length===t.length,(function(){return"crops.length is ".concat(n.length," but should be equal to blockShape.length ").concat(t.length)})),g(r.shape[0]%a==0,(function(){return"input tensor batch is ".concat(r.shape[0]," but is not divisible by the product of ")+"the elements of blockShape ".concat(t.join(" * ")," === ").concat(a)}));var o={x:r},i={blockShape:t,crops:n};return da.runKernel(fe,o,i)}});var vi=Sa({batchNorm_:function(e,t,n,r,a,o){null==o&&(o=.001);var i,s,u=ka(e,"x","batchNorm"),c=ka(t,"mean","batchNorm"),l=ka(n,"variance","batchNorm");null!=a&&(i=ka(a,"scale","batchNorm")),null!=r&&(s=ka(r,"offset","batchNorm")),g(c.rank===l.rank,(function(){return"Batch normalization gradient requires mean and variance to have equal ranks."})),g(null==s||c.rank===s.rank,(function(){return"Batch normalization gradient requires mean and offset to have equal ranks."})),g(null==i||c.rank===i.rank,(function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}));var h=function(e){return 0===e.rank||1===e.rank?ii(e,[1,1,1,e.size]):2===e.rank?ii(e,[1,1,e.shape[0],e.shape[1]]):3===e.rank?ii(e,[1,e.shape[0],e.shape[1],e.shape[2]]):e}(u),f={x:h,scale:i,offset:s,mean:c,variance:l},d={varianceEpsilon:o},p=da.runKernel(Je,f,d);return ii(p,u.shape)}});var mi=Sa({batchNorm2d_:function(e,t,n,r,a,o){var i,s,u=ka(e,"x","batchNorm"),c=ka(t,"mean","batchNorm"),l=ka(n,"variance","batchNorm");return null!=a&&(i=ka(a,"scale","batchNorm")),null!=r&&(s=ka(r,"offset","batchNorm")),g(2===u.rank,(function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+"".concat(u.rank,".")})),g(2===c.rank||1===c.rank,(function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but "+"got rank ".concat(c.rank,".")})),g(2===l.rank||1===l.rank,(function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 "+"but got rank ".concat(l.rank,".")})),null!=i&&g(2===i.rank||1===i.rank,(function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 "+"but got rank ".concat(i.rank,".")})),null!=s&&g(2===s.rank||1===s.rank,(function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 "+"but got rank ".concat(s.rank,".")})),vi(u,c,l,s,i,o)}});var yi=Sa({batchNorm3d_:function(e,t,n,r,a,o){var i,s,u=ka(e,"x","batchNorm"),c=ka(t,"mean","batchNorm"),l=ka(n,"variance","batchNorm");return null!=a&&(i=ka(a,"scale","batchNorm")),null!=r&&(s=ka(r,"offset","batchNorm")),g(3===u.rank,(function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+"".concat(u.rank,".")})),g(3===c.rank||1===c.rank,(function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but "+"got rank ".concat(c.rank,".")})),g(3===l.rank||1===l.rank,(function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 "+"but got rank ".concat(l.rank,".")})),null!=i&&g(3===i.rank||1===i.rank,(function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 "+"but got rank ".concat(i.rank,".")})),null!=s&&g(3===s.rank||1===s.rank,(function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 "+"but got rank ".concat(s.rank,".")})),vi(u,c,l,s,i,o)}});var bi=Sa({batchNorm4d_:function(e,t,n,r,a,o){var i,s,u=ka(e,"x","batchNorm"),c=ka(t,"mean","batchNorm"),l=ka(n,"variance","batchNorm");return null!=a&&(i=ka(a,"scale","batchNorm")),null!=r&&(s=ka(r,"offset","batchNorm")),g(4===u.rank,(function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+"".concat(u.rank,".")})),g(4===c.rank||1===c.rank,(function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but "+"got rank ".concat(c.rank,".")})),g(4===l.rank||1===l.rank,(function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 "+"but got rank ".concat(l.rank,".")})),null!=i&&g(4===i.rank||1===i.rank,(function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 "+"but got rank ".concat(i.rank,".")})),null!=s&&g(4===s.rank||1===s.rank,(function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 "+"but got rank ".concat(s.rank,".")})),vi(u,c,l,s,i,o)}});var wi=Sa({bincount_:function(e,t,n){var r=ka(e,"x","bincount"),a=ka(t,"weights","bincount");g("int32"===r.dtype,(function(){return"Error in bincount: input "+"dtype must be int32, but got ".concat(r.dtype)})),g(n>=0,(function(){return"size must be non-negative, but got ".concat(n,".")})),g(a.size===r.size||0===a.size,(function(){return"Error in bincount: weights must have the same size as input or"+"0-length, but got input shape: ".concat(r.shape,", weights shape: ")+"".concat(a.shape,".")}));var o={x:r,weights:a},i={size:n};return da.runKernel(de,o,i)}});var ki=Sa({bitwiseAnd_:function(e,t){var n=ka(e,"x","bitwiseAnd"),r=ka(t,"y","bitwiseAnd");if(!w(n.shape,r.shape))throw new Error("BitwiseAnd: Tensors must have the same shape. x: ".concat(n.shape,", y: ").concat(r.shape));if("int32"!==n.dtype||"int32"!==r.dtype)throw new Error("BitwiseAnd: Only supports 'int32' values in tensor, found type of x: ".concat(n.dtype," and type of y: ").concat(r.dtype));var a={a:n,b:r};return da.runKernel(pe,a)}});var xi=Sa({broadcastArgs_:function(e,t){var n=ka(e,"s0","broadcastArgs","int32"),r=ka(t,"s1","broadcastArgs","int32");if(1!==n.rank)throw new Error("broadcastArgs(): first input must be a vector (rank=1). "+"Has rank ".concat(n.rank));if(1!==r.rank)throw new Error("broadcastArgs(): second input must be a vector (rank=1). "+"Has rank ".concat(r.rank));var a={s0:n,s1:r};return da.runKernel(ge,a)}});var Ei=Sa({broadcastTo_:function(e,t){var n=ka(e,"broadcastTo","x"),r=n.shape;if(G(t),t.lengthn.rank){for(var a=n.shape.slice();a.length=0;s--)if(o[s]===t[s])i[s]=1;else if(1!==n.shape[s])throw new Error("broadcastTo(): [".concat(r,"] cannot be broadcast to [").concat(t,"]."));var u=i.map((function(e,t){return e>1?t:-1})).filter((function(e){return e>=0}));if(0===u.length)return No(n);var c={x:n},l={reps:i};return da.runKernel(bn,c,l)}});var Si=Sa({ceil_:function(e){var t={x:ka(e,"x","ceil","float32")};return da.runKernel(me,t)}});function Ai(e,t,n){G(e);var r={shape:e,value:t,dtype:n=n||F(t)};return da.runKernel(Ke,{},r)}var _i=Sa({clipByValue_:function(e,t,n){var r=ka(e,"x","clipByValue");if(g(t<=n,(function(){return"Error in clip: min (".concat(t,") must be ")+"less than or equal to max (".concat(n,").")})),t===n)return Ai(r.shape,t,r.dtype);var a={x:r},o={clipValueMin:t,clipValueMax:n};return da.runKernel(ye,a,o)}});var Ii=Sa({concat1d_:function(e){return ci(e,0)}});var Ni=Sa({concat2d_:function(e,t){return ci(e,t)}});var Mi=Sa({concat3d_:function(e,t){return ci(e,t)}});var Ti=Sa({concat4d_:function(e,t){return ci(e,t)}});var Di=Sa({conv2d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NHWC"),void 0===o&&(o=[1,1]);var s=ka(e,"x","conv2d","float32"),u=ka(t,"filter","conv2d","float32"),c=s,l=!1;3===s.rank&&(l=!0,c=ii(s,[1,s.shape[0],s.shape[1],s.shape[2]])),g(4===c.rank,(function(){return"Error in conv2d: input must be rank 4, but got rank ".concat(c.rank,".")})),g(4===u.rank,(function(){return"Error in conv2d: filter must be rank 4, but got rank "+"".concat(u.rank,".")})),oi("conv2d",r,i);var h="NHWC"===a?c.shape[3]:c.shape[1];g(h===u.shape[2],(function(){return"Error in conv2d: depth of input (".concat(h,") must match ")+"input depth for filter ".concat(u.shape[2],".")})),g(ni(n,o),(function(){return"Error in conv2D: Either strides or dilations must be 1. "+"Got strides ".concat(n," and dilations '").concat(o,"'")})),g(ri(o),(function(){return"Error in conv2D: Dilated rates should be larger than 0."})),g(ri(n),(function(){return"Error in conv2D: Strides should be larger than 0."}));var f={x:c,filter:u},d={strides:n,pad:r,dataFormat:a,dilations:o,dimRoundingMode:i},p=da.runKernel(xe,f,d);return l?ii(p,[p.shape[1],p.shape[2],p.shape[3]]):p}});var Ri=Sa({conv1d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NWC"),void 0===o&&(o=1);var s=ka(e,"x","conv1d"),u=ka(t,"filter","conv1d"),c=s,l=!1;2===s.rank&&(l=!0,c=ii(s,[1,s.shape[0],s.shape[1]])),g(3===c.rank,(function(){return"Error in conv1d: input must be rank 3, but got rank ".concat(c.rank,".")})),g(3===u.rank,(function(){return"Error in conv1d: filter must be rank 3, but got rank "+"".concat(u.rank,".")})),oi("conv1d",r,i),g(c.shape[2]===u.shape[1],(function(){return"Error in conv1d: depth of input (".concat(c.shape[2],") must match ")+"input depth for filter ".concat(u.shape[1],".")})),g(ni(n,o),(function(){return"Error in conv1D: Either stride or dilation must be 1. "+"Got stride ".concat(n," and dilation '").concat(o,"'")})),g(ri(o),(function(){return"Error in conv1D: Dilated rates should be larger than 0."})),g(ri(n),(function(){return"Error in conv1D: Stride should be larger than 0."})),g("NWC"===a,(function(){return"Error in conv1d: got dataFormat of ".concat(a," but only NWC is currently supported.")}));var h=ii(u,[1,u.shape[0],u.shape[1],u.shape[2]]),f=ii(c,[c.shape[0],1,c.shape[1],c.shape[2]]),d=Di(f,h,[1,n],r,"NHWC",[1,o],i);return ii(d,l?[d.shape[2],d.shape[3]]:[d.shape[0],d.shape[2],d.shape[3]])}});var Bi=Sa({conv2DBackpropInput_:function(e,t,n,r,a,o,i){void 0===o&&(o="NHWC"),g(e.length===t.rank,(function(){return"Length of inShape "+"(".concat(e.length,") and rank of dy (").concat(t.rank,") must match")}));var s=e,u=t,c=!1;3===t.rank&&(c=!0,u=ii(t,[1,t.shape[0],t.shape[1],t.shape[2]]),s=[1,e[0],e[1],e[2]]),g(4===s.length,(function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+"".concat(s.length,".")})),g(4===u.rank,(function(){return"Error in conv2dDerInput: dy must be rank 4, but got "+"rank ".concat(u.rank)})),g(4===n.rank,(function(){return"Error in conv2dDerInput: filter must be rank 4, but got "+"rank ".concat(n.rank)}));var l="NHWC"===o?s[3]:s[1],h="NHWC"===o?u.shape[3]:u.shape[1];g(l===n.shape[2],(function(){return"Error in conv2dDerInput: depth of input (".concat(l,") must ")+"match input depth for filter ".concat(n.shape[2],".")})),g(h===n.shape[3],(function(){return"Error in conv2dDerInput: depth of output (".concat(h,") must ")+"match output depth for filter ".concat(n.shape[3],".")})),oi("conv2dDerInput",a,i);var f={dy:u,filter:n},d={strides:r,pad:a,dataFormat:o,dimRoundingMode:i,inputShape:s},p=da.runKernel(Se,f,d);return c?ii(p,[p.shape[1],p.shape[2],p.shape[3]]):p}});var Fi=Sa({conv2dTranspose_:function(e,t,n,r,a,o){var i=ka(e,"x","conv2dTranspose"),s=ka(t,"filter","conv2dTranspose");return Bi(n,i,s,r,a,"NHWC",o)}});var Ci=Sa({conv3d_:function(e,t,n,r,a,o){void 0===a&&(a="NDHWC"),void 0===o&&(o=[1,1,1]);var i=ka(e,"x","conv3d"),s=ka(t,"filter","conv3d"),u=i,c=!1;4===i.rank&&(c=!0,u=ii(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),g(5===u.rank,(function(){return"Error in conv3d: input must be rank 5, but got rank ".concat(u.rank,".")})),g(5===s.rank,(function(){return"Error in conv3d: filter must be rank 5, but got rank "+"".concat(s.rank,".")})),g(u.shape[4]===s.shape[3],(function(){return"Error in conv3d: depth of input (".concat(u.shape[4],") must match ")+"input depth for filter ".concat(s.shape[3],".")})),g(ni(n,o),(function(){return"Error in conv3D: Either strides or dilations must be 1. "+"Got strides ".concat(n," and dilations '").concat(o,"'")})),g("NDHWC"===a,(function(){return"Error in conv3d: got dataFormat of ".concat(a," but only NDHWC is currently supported.")})),g(ri(o),(function(){return"Error in conv3D: Dilated rates should be larger than 0."})),g(ri(n),(function(){return"Error in conv3D: Strides should be larger than 0."}));var l={x:u,filter:s},h={strides:n,pad:r,dataFormat:a,dilations:o},f=da.runKernel(Ae,l,h);return c?ii(f,[f.shape[1],f.shape[2],f.shape[3],f.shape[4]]):f}});var Pi=Sa({conv3DBackpropInput_:function(e,t,n,r,a){g(e.length===t.rank,(function(){return"Length of inShape "+"(".concat(e.length,") and rank of dy (").concat(t.rank,") must match")}));var o=e,i=t,s=!1;4===t.rank&&(s=!0,i=ii(t,[1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]]),o=[1,e[0],e[1],e[2],e[3]]);var u=o[4],c=i.shape[4];g(5===o.length,(function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+"".concat(o.length,".")})),g(5===i.rank,(function(){return"Error in conv3dDerInput: dy must be rank 5, but got "+"rank ".concat(i.rank)})),g(5===n.rank,(function(){return"Error in conv3dDerInput: filter must be rank 5, but got "+"rank ".concat(n.rank)})),g(u===n.shape[3],(function(){return"Error in conv3dDerInput: depth of input (".concat(u,") must ")+"match input depth for filter ".concat(n.shape[3],".")})),g(c===n.shape[4],(function(){return"Error in conv3dDerInput: depth of output (".concat(c,") must ")+"match output depth for filter ".concat(n.shape[4],".")}));var l={dy:i,filter:n},h={pad:a,strides:r,inputShape:o},f=da.runKernel(_e,l,h);return s?ii(f,[f.shape[1],f.shape[2],f.shape[3],f.shape[4]]):f}});var Oi=Sa({conv3dTranspose_:function(e,t,n,r,a){var o=ka(e,"x","conv3dTranspose"),i=ka(t,"filter","conv3dTranspose");return Pi(n,o,i,r,a)}});var Li=Sa({cos_:function(e){var t={x:ka(e,"x","cos","float32")};return da.runKernel("Cos",t)}});var zi=Sa({cosh_:function(e){var t={x:ka(e,"x","cosh","float32")};return da.runKernel(Ie,t)}});var Ui=Sa({cumprod_:function(e,t,n,r){void 0===t&&(t=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var a={x:ka(e,"x","cumprod")},o={axis:t,exclusive:n,reverse:r};return da.runKernel(Ne,a,o)}});var Wi=Sa({cumsum_:function(e,t,n,r){void 0===t&&(t=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var a={x:ka(e,"x","cumsum")},o={axis:t,exclusive:n,reverse:r};return da.runKernel(Me,a,o)}});var Gi=Sa({denseBincount_:function(e,t,n,r){void 0===r&&(r=!1);var a=ka(e,"x","denseBincount"),o=ka(t,"weights","denseBincount");g("int32"===a.dtype,(function(){return"Error in denseBincount: input "+"dtype must be int32, but got ".concat(a.dtype)})),g(a.rank<=2,(function(){return"Error in denseBincount: input must be at most rank 2, but got "+"rank ".concat(a.rank,".")})),g(n>=0,(function(){return"size must be non-negative, but got ".concat(n,".")})),g(o.size===a.size||0===o.size,(function(){return"Error in denseBincount: weights must have the same shape as x or "+"0-length, but got x shape: ".concat(a.shape,", weights shape: ")+"".concat(o.shape,".")}));var i={x:a,weights:o},s={size:n,binaryOutput:r};return da.runKernel(De,i,s)}});var qi=Sa({depthToSpace_:function(e,t,n){void 0===n&&(n="NHWC");var r=ka(e,"x","depthToSpace","float32"),a="NHWC"===n?r.shape[1]:r.shape[2],o="NHWC"===n?r.shape[2]:r.shape[3],i="NHWC"===n?r.shape[3]:r.shape[1];g(t>1,(function(){return"blockSize should be > 1 for depthToSpace, but was: ".concat(t)})),g(a*t>=0,(function(){return"Negative dimension size caused by overflow when multiplying\n ".concat(a," and ").concat(t," for depthToSpace with input shape\n ").concat(r.shape)})),g(o*t>=0,(function(){return"Negative dimension size caused by overflow when multiplying\n ".concat(o," and ").concat(t," for depthToSpace with input shape\n ").concat(r.shape)})),g(i%(t*t)==0,(function(){return"Dimension size must be evenly divisible by ".concat(t*t," but is ").concat(i," for depthToSpace with input shape ").concat(r.shape)}));var s={x:r},u={blockSize:t,dataFormat:n};return da.runKernel(Re,s,u)}});var Ki=Sa({depthwiseConv2d_:function(e,t,n,r,a,o,i){void 0===a&&(a="NHWC"),void 0===o&&(o=[1,1]);var s=ka(e,"x","depthwiseConv2d","float32"),u=ka(t,"filter","depthwiseConv2d","float32"),c=s,l=!1;3===s.rank&&(l=!0,c=ii(s,[1,s.shape[0],s.shape[1],s.shape[2]])),g(4===c.rank,(function(){return"Error in depthwiseConv2d: input must be rank 4, but got "+"rank ".concat(c.rank,".")})),g(4===u.rank,(function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+"".concat(u.rank,".")}));var h="NHWC"===a?c.shape[3]:c.shape[1];g(h===u.shape[2],(function(){return"Error in depthwiseConv2d: number of input channels "+"(".concat(h,") must match the inChannels dimension in ")+"filter ".concat(u.shape[2],".")})),oi("depthwiseConv2d",r,i);var f={x:c,filter:u},d={strides:n,pad:r,dataFormat:a,dilations:o,dimRoundingMode:i},p=da.runKernel(Be,f,d);return l?ii(p,[p.shape[1],p.shape[2],p.shape[3]]):p}});var Vi=Sa({diag_:function(e){var t={x:ka(e,"x","diag")};return da.runKernel(Pe,t)}});var Hi=Sa({dilation2d_:function(e,t,n,r,a,o){void 0===a&&(a=[1,1]),void 0===o&&(o="NHWC");var i=ka(e,"x","dilation2d"),s=ka(t,"filter","dilation2d");g(3===i.rank||4===i.rank,(function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+"".concat(i.rank,".")})),g(3===s.rank,(function(){return"Error in dilation2d: filter must be rank 3, but got rank "+"".concat(s.rank,".")})),g("NHWC"===o,(function(){return"Error in dilation2d: Only NHWC is currently supported, "+"but got dataFormat of ".concat(o)}));var u=i,c=!1;3===i.rank&&(u=ii(i,[1,i.shape[0],i.shape[1],i.shape[2]]),c=!0),g(u.shape[3]===s.shape[2],(function(){return"Error in dilation2d: input and filter must have the same depth: ".concat(u.shape[3]," vs ").concat(s.shape[2])}));var l={x:u,filter:s},h={strides:n,pad:r,dilations:a},f=da.runKernel(Oe,l,h);return c?ii(f,[f.shape[1],f.shape[2],f.shape[3]]):f}});function ji(e,t){for(var n=e.length,r=[],a=0;a1&&1===i&&r.unshift(o)}return r}function Ji(e,t){for(var n=[],r=0;r1)&&n.unshift(o)}return n}function Zi(e,t){for(var n=Math.max(e.length,t.length),r=new Array(n),a=0;a0,(function(){return"variableGrads() expects at least one of the input variables to "+"be trainable, but none of the ".concat(o," variables is ")+"trainable."}));var i=da.gradients(e,t,null,!0),s=i.value,u=i.grads;g(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()."})),g(0===s.rank,(function(){return"The f passed in variableGrads(f) must return a scalar, but it "+"returned a rank-".concat(s.rank," tensor")}));var c={};return t.forEach((function(e,t){null!=u[t]&&(c[e.name]=u[t])})),null!=a&&a.forEach((function(e){return c[e.name]=null})),{value:s,grads:c}}function zs(e){return da.customGrad(e)}function Us(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 Ws=Sa({neg_:function(e){var t={x:ka(e,"x","neg")};return da.runKernel("Neg",t)}});var Gs=Sa({softplus_:function(e){var t={x:ka(e,"x","softplus")};return da.runKernel(tn,t)}});var qs=Sa({logSigmoid_:function(e){var t=ka(e,"x","logSigmoid"),n=zs((function(e){return{value:Ws(Gs(Ws(e))),gradFunc:function(t){return Bo(t,hi(Ws(e)))}}}));return n(t)}});var Ks=Sa({sub_:function(e,t){var n,r=ka(e,"a","sub"),a=ka(t,"b","sub"),o={a:r=(n=s(ra(r,a),2))[0],b:a=n[1]};return da.runKernel("Sub",o)}});var Vs=Sa({logSoftmax_:function(e,t){void 0===t&&(t=-1);var n=ka(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 ".concat(n.rank," and axis was ").concat(t));var r=zs((function(e,n){var r=cs(e,t,!0),a=Ks(e,r),o=Ks(Io(a,"float32"),Ps(gs(bs(a),t,!0)));n([o]);return{value:o,gradFunc:function(e,n){var r=s(n,1)[0],a=bs(r);return Ks(e,Bo(gs(e,t,!0),a))}}}));return r(n)}});var Hs=Sa({logSumExp_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=ka(e,"x","logSumExp"),a=E(t,r.shape),o=cs(r,a,!0),i=Ks(r,o),s=bs(i),u=gs(s,a),c=Ps(u),l=To(ii(o,c.shape),c);if(n){var h=us(l.shape,a);return ii(l,h)}return l}});var js=Sa({logicalAnd_:function(e,t){var n=ka(e,"a","logicalAnd","bool"),r=ka(t,"b","logicalAnd","bool");Zi(n.shape,r.shape);var a={a:n,b:r};return da.runKernel(lt,a)}});var Js=Sa({logicalNot_:function(e){var t={x:ka(e,"x","logicalNot","bool")};return da.runKernel(ht,t)}});var Zs=Sa({logicalOr_:function(e,t){var n=ka(e,"a","logicalOr","bool"),r=ka(t,"b","logicalOr","bool");Zi(n.shape,r.shape);var a={a:n,b:r};return da.runKernel(ft,a)}});var Ys=Sa({logicalXor_:function(e,t){var n=ka(e,"a","logicalXor","bool"),r=ka(t,"b","logicalXor","bool");return Zi(n.shape,r.shape),js(Zs(e,t),Js(js(e,t)))}}),Xs=2147483648;var Qs=Sa({searchSorted_:function(e,t,n){void 0===n&&(n="left");var r=ka(e,"sortedSequence","searchSorted"),a=ka(t,"values","searchSorted"),o=r.shape[r.shape.length-1],i=a.shape[a.shape.length-1],s=ii(r,[-1,o]),u=ii(a,[-1,i]);if(s.rank<2)throw new Error("Sorted input argument must be at least 2-dimensional");if(s.shape[0]!==u.shape[0])throw new Error("Leading dimension of 'sortedSequence' and 'values' must match.");if(y(u.shape)>=Xs)throw new Error("values tensor size must less than ".concat(Xs));if(s.shape[1]>=Xs)throw new Error("trailing dim_size must less than ".concat(Xs," for int32 output type, was ").concat(s.shape[1]));var c={sortedSequence:s,values:u},l={side:n};return da.runKernel(Jt,c,l)}});var $s=Sa({maxPool_:function(e,t,n,r,a){var o=ka(e,"x","maxPool"),i=o,s=!1;3===o.rank&&(s=!0,i=ii(o,[1,o.shape[0],o.shape[1],o.shape[2]])),g(4===i.rank,(function(){return"Error in maxPool: input must be rank 4 but got rank ".concat(i.rank,".")})),g(ni(n,1),(function(){return"Error in maxPool: Either strides or dilations must be 1. "+"Got strides ".concat(n," and dilations '").concat(1,"'")})),oi("maxPool",r,a);var u={x:i},c={filterSize:t,strides:n,pad:r,dimRoundingMode:a},l=da.runKernel(pt,u,c);return s?ii(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var eu=Sa({maxPool3d_:function(e,t,n,r,a,o){void 0===t&&(t=[1,1,1]),void 0===o&&(o="NDHWC");var i=ka(e,"x","maxPool3d"),s=i,u=!1;4===i.rank&&(u=!0,s=ii(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),g(5===s.rank,(function(){return"Error in maxPool3d: x must be rank 5 but got rank ".concat(s.rank,".")})),g("NDHWC"===o,(function(){return"Error in maxPool3d: Only NDHWC is currently supported, "+"but got dataFormat of ".concat(o)})),oi("maxPool3d",r,a);var c={x:s},l={filterSize:t,strides:n,pad:r,dimRoundingMode:a,dataFormat:o},h=da.runKernel(gt,c,l);return u?ii(h,[h.shape[1],h.shape[2],h.shape[3],h.shape[4]]):h}});var tu=Sa({maxPoolWithArgmax_:function(e,t,n,r,a){void 0===a&&(a=!1);var o={x:ka(e,"x","maxPoolWithArgmax")},i={filterSize:t,strides:n,pad:r,includeBatchInIndex:a},s=da.runKernel(vt,o,i);return{result:s[0],indexes:s[1]}}});var nu=Sa({maximum_:function(e,t){var n,r=ka(e,"a","maximum"),a=ka(t,"b","maximum");r=(n=s(ra(r,a),2))[0],a=n[1],"bool"===r.dtype&&(r=Io(r,"int32"),a=Io(a,"int32")),Zi(r.shape,a.shape);var o={a:r,b:a};return da.runKernel(dt,o)}});var ru=Sa({mean_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r={x:ka(e,"x","mean")},a={axis:t,keepDims:n};return da.runKernel(mt,r,a)}});function au(e,t){if(void 0===t&&(t="float32"),G(e),"complex64"===t){var n=au(e,"float32"),r=au(e,"float32");return Aa(n,r)}var a=W(y(e),t);return da.makeTensor(a,e,t)}function ou(e,t){if(void 0===t&&(t="float32"),G(e),"complex64"===t){var n=ou(e,"float32"),r=au(e,"float32");return Aa(n,r)}var a=U(y(e),t);return da.makeTensor(a,e,t)}var iu=Sa({minimum_:function(e,t){var n,r=ka(e,"a","minimum"),a=ka(t,"b","minimum");r=(n=s(ra(r,a),2))[0],a=n[1],"bool"===r.dtype&&(r=Io(r,"int32"),a=Io(a,"int32")),Zi(r.shape,a.shape);var o={a:r,b:a};return da.runKernel(yt,o)}});var su=Sa({mirrorPad_:function(e,t,n){g("reflect"===n||"symmetric"===n,(function(){return"Invalid mode. Mode must be either reflect or symmetric. "+"Got ".concat(n,".")}));var r=ka(e,"x","mirrorPad");if(0===r.rank)throw new Error("mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad");g(t.length===r.rank,(function(){return"Padding doesn't match input. Must be ".concat(r.rank,". ")+"Got ".concat(t.length,".")}));for(var a="reflect"===n?1:0,o=function(e){g(2===t[e].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),g(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 ".concat(e," cannot be greater than or equal ")+"to ".concat(r.shape[e]-a," or less than 0 for input of ")+"shape ".concat(r.shape)}))},i=0;i2)throw new Error("Rank of probabilities must be 1 or 2, but is ".concat(i));n=n||Math.random();var s={logits:1===i?ii(a,[1,-1]):a},u={numSamples:t,seed:n,normalized:r},c=da.runKernel(wt,s,u);return 1===i?ii(c,[c.size]):c}});var fu=Sa({notEqual_:function(e,t){var n,r=ka(e,"a","notEqual","string_or_numeric"),a=ka(t,"b","notEqual","string_or_numeric");r=(n=s(ra(r,a),2))[0],a=n[1],Zi(r.shape,a.shape);var o={a:r,b:a};return da.runKernel(xt,o)}});var du=Sa({oneHot_:function(e,t,n,r,a){if(void 0===n&&(n=1),void 0===r&&(r=0),void 0===a&&(a="int32"),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is ".concat(t));var o={indices:ka(e,"indices","oneHot","int32")},i={dtype:a,depth:t,onValue:n,offValue:r};return da.runKernel(It,o,i)}});var pu=Sa({onesLike_:function(e){var t={x:ka(e,"x","onesLike")};return da.runKernel(_t,t)}});var gu=Sa({outerProduct_:function(e,t){var n=ka(e,"v1","outerProduct"),r=ka(t,"v2","outerProduct");g(1===n.rank&&1===r.rank,(function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+"".concat(n.rank," and ").concat(r.rank,".")}));var a=ii(n,[-1,1]),o=ii(r,[1,-1]);return li(a,o)}});var vu=Sa({pad_:function(e,t,n){void 0===n&&(n=0);var r=ka(e,"x","pad");if(0===r.rank)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var a={paddings:t,constantValue:n},o={x:r};return da.runKernel(Mt,o,a)}});var mu=Sa({pad1d_:function(e,t,n){return void 0===n&&(n=0),g(2===t.length,(function(){return"Invalid number of paddings. Must be length of 2."})),vu(e,[t],n)}});var yu=Sa({pad2d_:function(e,t,n){return void 0===n&&(n=0),g(2===t.length&&2===t[0].length&&2===t[1].length,(function(){return"Invalid number of paddings. Must be length of 2 each."})),vu(e,t,n)}});var bu=Sa({pad3d_:function(e,t,n){return void 0===n&&(n=0),g(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."})),vu(e,t,n)}});var wu=Sa({pad4d_:function(e,t,n){return void 0===n&&(n=0),g(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."})),vu(e,t,n)}});var ku=Sa({spaceToBatchND_:function(e,t,n){var r=ka(e,"x","spaceToBatchND");g(r.rank>=1+t.length,(function(){return"input rank ".concat(r.rank," should be > than [blockShape] ").concat(t.length)})),g(n.length===t.length,(function(){return"paddings.shape[0] ".concat(n.length," must be equal to [blockShape] ").concat(t.length)})),g(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 ".concat(r.shape.slice(1)," with paddings ").concat(n.toString()," must be divisible by blockShapes ").concat(t.toString())}));var a={x:r},o={blockShape:t,paddings:n};return da.runKernel(rn,a,o)}});var xu=Sa({pool_:function(e,t,n,r,a,o,i){null==a&&(a=[1,1]),null==o&&(o=1),0===r&&(r="valid");var u=ka(e,"x","maxPool"),c=u,l=!1;3===u.rank&&(l=!0,c=ii(u,[1,u.shape[0],u.shape[1],u.shape[2]])),g(ni(o,a),(function(){return"Error in pool: Either strides or dilations must be 1. "+"Got strides ".concat(o," and dilations '").concat(a,"'")}));var h,f=jo(c.shape,t,o,a,r),d=[f.dilationHeight,f.dilationWidth];h="same"===r?function(e,t){var n=e.map((function(e,n){return e+(e-1)*(t[n]-1)})).map((function(e){return e-1})),r=n.map((function(e){return Math.floor(e/2)})),a=n.map((function(e,t){return e-r[t]}));return n.map((function(e,t){return[r[t],a[t]]}))}([f.filterHeight,f.filterWidth],d):[[0,0],[0,0]];var p=1===d[0]&&1===d[1],v=s(function(e,t,n){var r=n.map((function(e){return e[0]})),a=n.map((function(e){return e[1]})),o=e.concat(r,a),i=t.map((function(e,t){return(e-o[t]%e)%e})),s=a.map((function(e,t){return e+i[t]})),u=t.map((function(e,t){return[r[t],s[t]]})),c=t.map((function(e,t){return[0,i[t]]}));return[u,c]}([f.inHeight,f.inWidth],d,h),2),m=v[0],y=v[1],b=p?r:"valid",w=p?c:ku(c,d,m),k=("avg"===n?function(){return si(w,t,o,b,i)}:function(){return $s(w,t,o,b,i)})(),x=p?k:gi(k,d,y);return l?ii(x,[x.shape[1],x.shape[2],x.shape[3]]):x}});var Eu=Sa({prelu_:function(e,t){var n={x:ka(e,"x","prelu"),alpha:ka(t,"alpha","prelu")};return da.runKernel(Tt,n)}});var Su=Sa({prod_:function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=ka(e,"x","prod");"bool"===r.dtype&&(r=Io(r,"int32"));var a={x:r},o={axis:t,keepDims:n};return da.runKernel(Dt,a,o)}});var Au=Sa({raggedGather_:function(e,t,n,r){var a={paramsNestedSplits:e.map((function(e,t){return ka(e,"tensors".concat(t),"raggedGather","int32")})),paramsDenseValues:ka(t,"paramsDenseValues","raggedGather"),indices:ka(n,"indices","raggedGather","int32")},o={outputRaggedRank:r},i=da.runKernel(Rt,a,o);return{outputNestedSplits:i.slice(0,i.length-1),outputDenseValues:i[i.length-1]}}});var _u=Sa({raggedRange_:function(e,t,n){var r=ka(e,"starts","raggedRange"),a={starts:r,limits:ka(t,"limits","raggedRange",r.dtype),deltas:ka(n,"deltas","raggedRange",r.dtype)},o=da.runKernel(Bt,a);return{rtNestedSplits:o[0],rtDenseValues:o[1]}}});var Iu=Sa({raggedTensorToTensor_:function(e,t,n,r,a){var o=ka(e,"shape","raggedTensorToTensor","int32"),i=ka(t,"values","raggedTensorToTensor"),s={shape:o,values:i,defaultValue:ka(n,"defaultValue","raggedTensorToTensor",i.dtype),rowPartitionTensors:r.map((function(e,t){return ka(e,"tensors".concat(t),"raggedTensorToTensor","int32")}))},u={rowPartitionTypes:a};return da.runKernel(Ft,s,u)}});var Nu=Sa({rand_:function(e,t,n){G(e);var r=y(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 ".concat(n));a=new Uint8Array(r)}for(var o=0;o>>0,t=(r*=t)>>>0,t+=4294967296*(r-=t)}return 2.3283064365386963e-10*(t>>>0)});n.next=function(){var e=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=e-(n.c=0|e)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(e),n.s0<0&&(n.s0+=1),n.s1-=r(e),n.s1<0&&(n.s1+=1),n.s2-=r(e),n.s2<0&&(n.s2+=1),r=null}function a(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function o(e,t){var n=new r(e),o=t&&t.state,i=n.next;return i.int32=function(){return 4294967296*n.next()|0},i.double=function(){return i()+11102230246251565e-32*(2097152*i()|0)},i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.alea=o}(0,e,!1)}(Mu);var Tu=Mu.exports,Du={exports:{}};!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>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xor128=o}(0,e,!1)}(Du);var Ru=Du.exports,Bu={exports:{}};!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>>4),t.next()}function a(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function o(e,t){var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xorwow=o}(0,e,!1)}(Bu);var Fu=Bu.exports,Cu={exports:{}};!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;n0;--n)e.next()}(t,e)}function a(e,t){return t.x=e.x.slice(),t.i=e.i,t}function o(e,t){null==e&&(e=+new Date);var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&(o.x&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xorshift7=o}(0,e,!1)}(Cu);var Pu=Cu.exports,Ou={exports:{}};!function(e){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.w,a=t.X,o=t.i;return t.w=r=r+1640531527|0,n=a[o+34&127],e=a[o=o+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=a[o]=n^e,t.i=o,n+(r^r>>>16)|0},function(e,t){var n,r,a,o,i,s=[],u=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,u=Math.max(u,t.length)),a=0,o=-32;o>>15,r^=r<<4,r^=r>>>13,o>=0&&(i=i+1640531527|0,a=0==(n=s[127&o]^=r+i)?a+1:0);for(a>=128&&(s[127&(t&&t.length||0)]=-1),a=127,o=512;o>0;--o)r=s[a+34&127],n=s[a=a+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[a]=r^n;e.w=i,e.X=s,e.i=a}(t,e)}function a(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function o(e,t){null==e&&(e=+new Date);var n=new r(e),o=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&(o.X&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.xor4096=o}(0,e,!1)}(Ou);var Lu=Ou.exports,zu={exports:{}};!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>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,o&&("object"==typeof o&&a(o,n),i.state=function(){return a(n,{})}),i}t&&t.exports?t.exports=o:n&&n.amd?n((function(){return o})):this.tychei=o}(0,e,!1)}(zu);var Uu=zu.exports,Wu={exports:{}};!function(e){!function(t,n,r){var a,o=256,i=r.pow(o,6),s=r.pow(2,52),u=2*s,c=255;function l(e,c,l){var v=[],m=p(d((c=1==c?{entropy:!0}:c||{}).entropy?[e,g(n)]:null==e?function(){try{var e;return a&&(e=a.randomBytes)?e=e(o):(e=new Uint8Array(o),(t.crypto||t.msCrypto).getRandomValues(e)),g(e)}catch(e){var r=t.navigator,i=r&&r.plugins;return[+new Date,t,i,t.screen,g(n)]}}():e,3),v),y=new h(v),b=function(){for(var e=y.g(6),t=i,n=0;e=u;)e/=2,t/=2,n>>>=1;return(e+n)/t};return b.int32=function(){return 0|y.g(4)},b.quick=function(){return y.g(4)/4294967296},b.double=b,p(g(y.S),n),(c.pass||l||function(e,t,n,a){return a&&(a.S&&f(a,y),e.state=function(){return f(y,{})}),n?(r.random=e,t):e})(b,m,"global"in c?c.global:this==r,c.state)}function h(e){var t,n=e.length,r=this,a=0,i=r.i=r.j=0,s=r.S=[];for(n||(e=[n++]);an)}var $u={__proto__:null,TEST_EPSILON_FLOAT16:.1,createVideoElement:function(e){var t=document.createElement("video");return"playsInline"in t&&(t.playsInline=!0),t.muted=!0,t.loop=!0,t.style.position="fixed",t.style.left="0px",t.style.top="0px",t.preload="auto",t.appendChild(e),new Promise((function(e){t.addEventListener("loadeddata",(function(n){return e(t)})),t.load()}))},encodeStrings:function e(t){for(var n=0;nn)throw new Error("Value out of range:".concat(e[r]," low: ").concat(t,", high: ").concat(n))},play:function(e){return a(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,e.play()];case 1:return t.sent(),"requestVideoFrameCallback"in e?[4,new Promise((function(t){e.requestVideoFrameCallback(t)}))]:[3,3];case 2:t.sent(),t.label=3;case 3:return[2]}}))}))},testEpsilon:Yu},ec=function(){function e(e,t,n,r,a){this.mean=e,this.stdDev=t,this.dtype=n,this.nextVal=NaN,this.truncated=r,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var o=a||Math.random();this.random=Zu.alea(o.toString())}return e.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var e=this.nextVal;return this.nextVal=NaN,e}for(var t,n,r=!1;!r;){var a=void 0,o=void 0,i=void 0;do{i=(a=2*this.random()-1)*a+(o=2*this.random()-1)*o}while(i>=1||0===i);var s=Math.sqrt(-2*Math.log(i)/i);t=this.mean+this.stdDev*a*s,n=this.mean+this.stdDev*o*s,this.truncated&&!this.isValidTruncated(t)||(r=!0)}return this.truncated&&!this.isValidTruncated(n)||(this.nextVal=this.convertValue(n)),this.convertValue(t)},e.prototype.convertValue=function(e){return null==this.dtype||"float32"===this.dtype?e:Math.round(e)},e.prototype.isValidTruncated=function(e){return e<=this.upper&&e>=this.lower},e}(),tc=function(){function e(e,t,n,r){this.alpha=e,this.beta=1/t,this.dtype=n;var a=r||Math.random();this.randu=Zu.alea(a.toString()),this.randn=new ec(0,1,n,!1,this.randu()),this.d=e<1?e+2/3:e-1/3,this.c=1/Math.sqrt(9*this.d)}return e.prototype.nextValue=function(){for(var e,t,n,r,a,o;;){do{r=this.randn.nextValue(),o=1+this.c*r}while(o<=0);if(o*=o*o,t=1-.331*(e=r*r)*e,n=.5*e+this.d*(1-o+Math.log(o)),(a=this.randu())r){var s=e.shape.map((function(e){return e}));s[e.shape.length-1]=t-r,n=ci([e,au(s)],e.shape.length-1),r=t}else n=e;var u=$i(n),c=ii(Aa(n,u),[a,r]),l=Dc(c),h=Math.floor(r/2)+1,f=cc(l),d=Ns(l),p=Fc(f,[h,r-h],f.shape.length-1),v=Fc(d,[h,r-h],d.shape.length-1),m=n.shape.slice();return m[n.shape.length-1]=h,ii(Aa(p[0],v[0]),m)}});var Pc=Sa({squaredDifference_:function(e,t){var n,r=ka(e,"a","squaredDifference"),a=ka(t,"b","squaredDifference");r=(n=s(ra(r,a),2))[0],a=n[1],Zi(r.shape,a.shape);var o={a:r,b:a};return da.runKernel(fn,o,{})}});var Oc=Sa({squeeze_:function(e,t){var n=ka(e,"x","squeeze","string_or_numeric");return ii(n,S(n.shape,t).newShape)}});var Lc=Sa({stack_:function(e,t){void 0===t&&(t=0);var n=xa(e,"tensors","stack","string_or_numeric");g(n.length>=1,(function(){return"Pass at least one tensor to tf.stack"})),n.length>0&&g(t<=n[0].rank,(function(){return"Axis must be <= rank of the tensor"}));var r=n,a={axis:t};return da.runKernel(Nt,r,a)}});var zc=Sa({step_:function(e,t){void 0===t&&(t=0);var n={x:ka(e,"x","step")},r={alpha:t};return da.runKernel(In,n,r)}});var Uc=Sa({stridedSlice_:function(e,t,n,r,a,o,i,s,u){void 0===a&&(a=0),void 0===o&&(o=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===u&&(u=0);var c={x:ka(e,"x","stridedSlice","string_or_numeric")},l={begin:t,end:n,strides:r,beginMask:a,endMask:o,ellipsisMask:i,newAxisMask:s,shrinkAxisMask:u};return da.runKernel(pn,c,l)}});var Wc=Sa({tan_:function(e){var t={x:ka(e,"x","tan","float32")};return da.runKernel("Tan",t)}});function Gc(e,t){m(e);var n=ya(e,t);if(1!==n.length)throw new Error("tensor1d() requires values to be a flat/TypedArray");return _a(e,null,n,t)}function qc(e,t,n){if(m(e),null!=t&&2!==t.length)throw new Error("tensor2d() requires shape to have two numbers");var r=ya(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 _a(e,t,r,n)}function Kc(e,t,n){if(m(e),null!=t&&3!==t.length)throw new Error("tensor3d() requires shape to have three numbers");var r=ya(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 _a(e,t,r,n)}function Vc(e,t,n){var r=t.rank>1?t.shape[t.rank-1]:1,a=t.rank>1?t.rank-1:1,o="Must have updates.shape = indices.shape[:batchDim] + "+"shape[sliceDim:], got updates.shape: ".concat(n.shape)+", indices.shape: ".concat(t.shape,", shape: ").concat(e)+", sliceDim: ".concat(r,", and batchDim: ").concat(a,".");if(n.rank1?t.shape[r-1]:1,o=n.length,i=1,c=a;c= 0 but got ".concat(t));if(t>a)throw new Error("'k' passed to topk() must be <= the last dimension (".concat(a,") ")+"but got ".concat(t));var o={x:r},i={k:t,sorted:n},u=s(da.runKernel(wn,o,i),2);return{values:u[0],indices:u[1]}}});var Xc=Sa({truncatedNormal_:function(e,t,n,r,a){if(void 0===t&&(t=0),void 0===n&&(n=1),G(e),null!=r&&"bool"===r)throw new Error("Unsupported data type $ { dtype }");for(var o=new ec(t,n,r,!0,a),i=_o(e,r),s=0;s0,(function(){return"The input tensor must be at least 1D"}));var r={x:n},a={axis:t},o=s(da.runKernel(En,r,a),2);return{values:o[0],indices:o[1]}}});var $c=Sa({unsortedSegmentSum_:function(e,t,n){var r=ka(e,"x","unsortedSegmentSum"),a=ka(t,"segmentIds","unsortedSegmentSum","int32");g(k(n),(function(){return"numSegments must be of dtype int"}));var o={x:r,segmentIds:a},i={numSegments:n};return da.runKernel(An,o,i)}});var el=Sa({unstack_:function(e,t){void 0===t&&(t=0);var n=ka(e,"x","unstack","string_or_numeric");g(t>=-n.shape.length&&t0,(function(){return"mask cannot be scalar"})),v(u.slice(i,i+s),a.shape,"mask's shape must match the first K dimensions of tensor's shape,"),c=1,l=i;l=0&&e2)throw new Error("sparseIndices should be a scalar, vector, or matrix,"+" but got shape ".concat(e.shape,"."));var a=e.rank>0?e.shape[0]:1,o=e.rank>1?e.shape[1]:1;if(n.length!==o)throw new Error("outputShape has incorrect number of elements:,"+" ".concat(n.length,", should be: ").concat(o,"."));var i=t.size;if(0!==t.rank&&(1!==t.rank||i!==a))throw new Error("sparseValues has incorrect shape "+"".concat(t.shape,", should be [] or [").concat(a,"]"));if(t.dtype!==r.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(a,o,n,i);var s={sparseIndices:a,sparseValues:o,defaultValue:i},u={outputShape:n};return da.runKernel(hn,s,u)}});var ul=Sa({gatherND_:function(e,t){var n=ka(t,"indices","gatherND","int32"),r={params:ka(e,"x","gatherND","string_or_numeric"),indices:n};return da.runKernel(Ye,r)}});var cl=Sa({dropout_:function(e,t,n,r){var a=ka(e,"x","dropout");if(g("float32"===a.dtype,(function(){return"x has to be a floating point tensor since it's going to be "+"scaled, but got a ".concat(a.dtype," tensor instead.")})),g(t>=0&&t<1,(function(){return"rate must be a float in the range [0, 1), but got ".concat(t,".")})),0===t)return e instanceof Vr?a.clone():a;var o=function(e,t){if(null==t)return e.shape.slice();if(w(e.shape,t))return t;if(e.shape.length===t.length){for(var n=[],r=0;r1,(function(){return"inTopK() expects the predictions to be of rank 2 or higher, "+"but got ".concat(r.rank)})),g(r.rank-1===a.rank,(function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+"".concat(r.rank," and targets rank ").concat(a.rank)})),v(r.shape.slice(0,r.shape.length-1),a.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),i=r.shape[r.shape.length-1],g(n>0&&n<=i,(function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last "+"dimension (".concat(i,"), but got ").concat(n)})),[4,r.data()];case 1:return u=o.sent(),[4,a.data()];case 2:for(c=o.sent(),l=s([u.length/i,i],2),h=l[0],f=l[1],d=A("bool",h),p=0;p0&&(n=gs(n,r)),ii(n,e.shape)}function vl(e,t,n,r){if("linear"===t)return e;if("relu"===t)return hc(e);if("elu"===t)return rs(e);if("relu6"===t)return fc(e);if("prelu"===t)return Eu(e,n);if("leakyrelu"===t)return Rs(e,r);if("sigmoid"===t)return hi(e);throw new Error("Unknown fused activation ".concat(t,"."))}var ml=function(e,t){return!(e>0)||"linear"===t};var yl=Sa({fusedConv2d_:function(e){var t,n=e.x,r=e.filter,a=e.strides,o=e.pad,i=e.dataFormat,u=void 0===i?"NHWC":i,c=e.dilations,l=void 0===c?[1,1]:c,h=e.dimRoundingMode,f=e.bias,d=e.activation,p=void 0===d?"linear":d,v=e.preluActivationWeights,m=e.leakyreluAlpha;if(p=p||"linear",!1===ml(da.state.gradientDepth,p)){g("NHWC"===u,(function(){return"Error in fused conv2d: got dataFormat of ".concat(u," but ")+"only NHWC is currently supported for the case of gradient depth is 0 and the activation is not linear."}));var y=Di(n,r,a,o,u,l,h);return null!=f&&(y=To(y,f)),vl(y,p,v,m)}var b=ka(n,"x","conv2d","float32"),w=ka(r,"filter","conv2d","float32"),k=b,x=!1;3===b.rank&&(x=!0,k=ii(b,[1,b.shape[0],b.shape[1],b.shape[2]])),g(4===k.rank,(function(){return"Error in fused conv2d: input must be rank 4, but got rank "+"".concat(k.rank,".")})),g(4===w.rank,(function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+"".concat(w.rank,".")})),oi("fused conv2d",o,h);var E="NHWC"===u?k.shape[3]:k.shape[1];g(w.shape[2]===E,(function(){return"Error in conv2d: depth of input (".concat(E,") must match ")+"input depth for filter ".concat(w.shape[2],".")})),g(ni(a,l),(function(){return"Error in conv2D: Either strides or dilations must be 1. "+"Got strides ".concat(a," and dilations '").concat(l,"'")}));var S,A,_=Jo(k.shape,w.shape,a,l,o,h);if(null!=f&&(t=s(ra(S=ka(f,"bias","fused conv2d"),b),1),S=t[0],"NHWC"===u?Zi(_.outShape,S.shape):(g(S.shape.length<=1,(function(){return"Error in fused conv2d: only supports scalar or 1-D Tensor bias for NCHW format but got the bias of "+"rank-".concat(S.shape.length,".")})),g(0===S.shape.length||S.shape[0]===_.outChannels||1===S.shape[0],(function(){return"Error in fused conv2d: bias shape (".concat(S.shape,") is not ")+"compatible with the number of output channels "+"(".concat(_.outChannels,")")})))),null!=v){var I=v.shape;if(g(I.length<=1||3===I.length,(function(){return"Error in fused conv2d: only supports scalar, 1-D Tensor or 3-D Tensor PReLU activation weights but got a tensor of "+"rank-".concat(I.length,".")})),1===I.length)g(1===I[0]||I[0]===_.outChannels,(function(){return"Error in fused conv2d: PReLU activation weights "+"(".concat(I,") is not compatible with the number of output ")+"channels (".concat(_.outChannels,").")}));else if(3===I.length)try{Zi(I,_.outShape)}catch(e){var N="Error in fused conv2d: PReLU activation weights (".concat(I,") ")+"is not compatible with the output shape of the conv2d "+"(".concat(_.outShape,").");throw Error(N)}A=ka(v,"prelu weights","fused conv2d")}var M=function(e,t){g("NHWC"===u,(function(){return"Error in gradient of fused conv2D: got dataFormat of ".concat(u," but only NHWC is currently supported.")}));var n=s(t,4),r=n[0],i=n[1],c=n[2],h=n[3],f=pl(e,c,p);g(ti(l),(function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 "+"are not yet supported in gradients. Got dilations '".concat(l,"'")}));var d=[Bi(i.shape,f,r,a,o),dl(i,f,r.shape,a,o)];if(null!=h){var v=gl(h,f);d.push(v)}return d},T={x:k,filter:w,bias:S,preluActivationWeights:A},D={strides:a,pad:o,dataFormat:u,dilations:l,dimRoundingMode:h,activation:p,leakyreluAlpha:m};if(null==f){var R=zs((function(e,t,n){var r=da.runKernel(Dn,T,D);return n([t,e,r]),x&&(r=ii(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:M}}));return R(k,w)}var B=zs((function(e,t,n,r){var a=da.runKernel(Dn,T,D);return r([t,e,a,n]),x&&(a=ii(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:M}}));return B(k,w,S)}});var bl=Sa({depthwiseConv2dNativeBackpropFilter_:function(e,t,n,r,a,o,i){void 0===o&&(o=[1,1]);var s=e;3===e.rank&&(s=ii(e,[1,e.shape[0],e.shape[1],e.shape[2]]));var u=t;3===u.rank&&(u=ii(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var c={x:s,dy:u},l={strides:r,pad:a,dimRoundingMode:i,dilations:o,filterShape:n};return da.runKernel(Fe,c,l)}});var wl=Sa({depthwiseConv2dNativeBackpropInput_:function(e,t,n,r,a,o,i){void 0===o&&(o=[1,1]);var s=t,u=!1;3===t.rank&&(u=!0,s=ii(t,[1,t.shape[0],t.shape[1],t.shape[2]]));var c={dy:s,filter:n},l={strides:r,pad:a,dimRoundingMode:i,dilations:o,inputShape:e},h=da.runKernel(Ce,c,l);return u?ii(h,[h.shape[1],h.shape[2],h.shape[3]]):h}});var kl=Sa({fusedDepthwiseConv2d_:function(e){var t,n=e.x,r=e.filter,a=e.strides,o=e.pad,i=e.dataFormat,u=void 0===i?"NHWC":i,c=e.dilations,l=void 0===c?[1,1]:c,h=e.dimRoundingMode,f=e.bias,d=e.activation,p=void 0===d?"linear":d,v=e.preluActivationWeights,m=e.leakyreluAlpha;if(!1===ml(da.state.gradientDepth,p)){var y=Ki(n,r,a,o,u,l,h);return null!=f&&(y=To(y,f)),vl(y,p,v,m)}var b=ka(n,"x","depthwiseConv2d","float32"),w=ka(r,"filter","depthwiseConv2d","float32"),k=b,x=!1;3===b.rank&&(x=!0,k=ii(b,[1,b.shape[0],b.shape[1],b.shape[2]])),g(4===k.rank,(function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got "+"rank ".concat(k.rank,".")})),g(4===w.rank,(function(){return"Error in fused depthwiseConv2d: filter must be rank 4, "+"but got rank ".concat(w.rank,".")})),g(k.shape[3]===w.shape[2],(function(){return"Error in fused depthwiseConv2d: number of input channels "+"(".concat(k.shape[3],") must match the inChannels dimension in ")+"filter ".concat(w.shape[2],".")})),null==l&&(l=[1,1]),g(ni(a,l),(function(){return"Error in fused depthwiseConv2d: Either strides or dilations must "+"be 1. Got strides ".concat(a," and dilations '").concat(l,"'")})),oi("fused depthwiseConv2d",o,h);var E,S,A=Jo(k.shape,w.shape,a,l,o,h,!0);null!=f&&(t=s(ra(E=ka(f,"bias","fused conv2d"),b),1),E=t[0],Zi(A.outShape,E.shape)),null!=v&&(S=ka(v,"prelu weights","fused depthwiseConv2d"));var _=function(e,t){g(ti(l),(function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations "+"'".concat(l,"'")}));var n=s(t,4),r=n[0],i=n[1],u=n[2],c=n[3],f=pl(e,u,p),d=wl(i.shape,f,r,a,o,l,h),v=bl(i,f,r.shape,a,o,l,h);return null!=c?[d,v,gl(E,f)]:[d,v]},I={x:k,filter:w,bias:E,preluActivationWeights:S},N={strides:a,pad:o,dataFormat:u,dilations:l,dimRoundingMode:h,activation:p,leakyreluAlpha:m};if(null==f){var M=zs((function(e,t,n){var r=da.runKernel(Rn,I,N);return n([t,e,r]),x&&(r=ii(r,[r.shape[1],r.shape[2],r.shape[3]])),{value:r,gradFunc:_}}));return M(k,w)}var T=zs((function(e,t,n,r){var a=da.runKernel(Rn,I,N);return r([t,e,a,n]),x&&(a=ii(a,[a.shape[1],a.shape[2],a.shape[3]])),{value:a,gradFunc:_}}));return T(k,w,E)}});var xl=Sa({fusedMatMul_:function(e){var t,n=e.a,r=e.b,a=e.transposeA,o=void 0!==a&&a,i=e.transposeB,u=void 0!==i&&i,c=e.bias,l=e.activation,h=void 0===l?"linear":l,f=e.preluActivationWeights,d=e.leakyreluAlpha,p=void 0===d?.2:d;if(!1===ml(da.state.gradientDepth,h)){var v=li(n,r,o,u);return null!=c&&(v=To(v,c)),vl(v,h,f,p)}var m=ka(n,"a","fused matMul"),b=ka(r,"b","fused matMul");t=s(ra(m,b),2),m=t[0],b=t[1];var w=o?m.shape[m.rank-2]:m.shape[m.rank-1],k=u?b.shape[b.rank-1]:b.shape[b.rank-2],x=o?m.shape[m.rank-1]:m.shape[m.rank-2],E=u?b.shape[b.rank-2]:b.shape[b.rank-1],S=m.shape.slice(0,-2),A=b.shape.slice(0,-2),_=y(S),I=y(A);g(w===k,(function(){return"Error in fused matMul: inner shapes (".concat(w,") and (")+"".concat(k,") of Tensors with shapes ").concat(m.shape," and ")+"".concat(b.shape," and transposeA=").concat(o)+" and transposeB=".concat(u," must match.")}));var N,M,T=Zi(m.shape.slice(0,-2),b.shape.slice(0,-2)).concat([x,E]),D=ii(m,o?[_,w,x]:[_,x,w]),R=ii(b,u?[I,E,k]:[I,k,E]);null!=c&&(N=s(ra(N=ka(c,"bias","fused matMul"),m),1)[0],Zi(T,N.shape)),null!=f&&(M=ka(f,"prelu weights","fused matMul"));var B=function(e,t){var n,r,a=s(t,4),i=a[0],l=a[1],f=a[2],d=a[3],p=pl(ii(e,f.shape),f,h);return o||u?!o&&u?(n=li(p,l,!1,!1),r=li(p,i,!0,!1)):o&&!u?(n=li(l,p,!1,!0),r=li(i,p,!1,!1)):(n=li(l,p,!0,!0),r=li(p,i,!0,!0)):(n=li(p,l,!1,!0),r=li(i,p,!0,!1)),null!=c?[n,r,gl(d,p)]:[n,r]},F={a:D,b:R,bias:N,preluActivationWeights:M},C={transposeA:o,transposeB:u,activation:h,leakyreluAlpha:p};if(null==c){var P=zs((function(e,t,n){var r=da.runKernel(Tn,F,C);return n([e,t,r]),{value:ii(r,T),gradFunc:B}}));return P(D,R)}var O=zs((function(e,t,n,r){var a=da.runKernel(Tn,F,C);return r([e,t,a,n]),{value:ii(a,T),gradFunc:B}}));return O(D,R,N)}}),El={__proto__:null,conv2d:yl,depthwiseConv2d:kl,matMul:xl};var Sl=Sa({hammingWindow_:function(e){return hl(e,.54,.46)}});var Al=Sa({hannWindow_:function(e){return hl(e,.5,.5)}});var _l=Sa({frame_:function(e,t,n,r,a){void 0===r&&(r=!1),void 0===a&&(a=0);for(var o=0,i=[];o+t<=e.size;)i.push(fi(e,o,t)),o+=n;if(r)for(;o=1&&r[1]>=1,(function(){return"cropSize must be atleast [1,1], but was ".concat(r)})),g("bilinear"===a||"nearest"===a,(function(){return"method must be bilinear or nearest, but was ".concat(a)}));var l={image:i,boxes:s,boxInd:u},h={method:a,extrapolationValue:o,cropSize:r};return da.runKernel(Te,l,h)}});var Ml=Sa({flipLeftRight_:function(e){var t=ka(e,"image","flipLeftRight","float32");g(4===t.rank,(function(){return"Error in flipLeftRight: image must be rank 4,"+"but got rank ".concat(t.rank,".")}));var n={image:t};return da.runKernel(Ve,n,{})}});var Tl=Sa({grayscaleToRGB_:function(e){var t=ka(e,"image","grayscaleToRGB"),n=t.rank-1,r=t.shape[n];g(t.rank>=2,(function(){return"Error in grayscaleToRGB: images must be at least rank 2, "+"but got rank ".concat(t.rank,".")})),g(1===r,(function(){return"Error in grayscaleToRGB: last dimension of a grayscale image "+"should be size 1, but got size ".concat(r,".")}));var a=new Array(t.rank);return a.fill(1,0,n),a[n]=3,xs(t,a)}});var Dl=Sa({rgbToGrayscale_:function(e){var t=ka(e,"image","RGBToGrayscale"),n=t.rank-1,r=t.shape[n];g(t.rank>=2,(function(){return"Error in RGBToGrayscale: images must be at least rank 2, "+"but got rank ".concat(t.rank,".")})),g(3===r,(function(){return"Error in RGBToGrayscale: last dimension of an RGB image "+"should be size 3, but got size ".concat(r,".")}));var a,o=t.dtype,i=Io(t,"float32"),s=Gc([.2989,.587,.114]);switch(t.rank){case 2:a=ns("ij,j->i",i,s);break;case 3:a=ns("ijk,k->ij",i,s);break;case 4:a=ns("ijkl,l->ijk",i,s);break;case 5:a=ns("ijklm,m->ijkl",i,s);break;case 6:a=ns("ijklmn,n->ijklm",i,s);break;default:throw new Error("Not a valid tensor rank.")}return a=ws(a,-1),Io(a,o)}});var Rl=Sa({rotateWithOffset_:function(e,t,n,r){void 0===n&&(n=0),void 0===r&&(r=.5);var a=ka(e,"image","rotateWithOffset","float32");g(4===a.rank,(function(){return"Error in rotateWithOffset: image must be rank 4,"+"but got rank ".concat(a.rank,".")}));var o={image:a},i={radians:t,fillValue:n,center:r};return da.runKernel(Mn,o,i)}});function Bl(e,t,n,r,a,o){null==r&&(r=.5),null==a&&(a=Number.NEGATIVE_INFINITY),null==o&&(o=0);var i=e.shape[0];return n=Math.min(n,i),g(0<=r&&r<=1,(function(){return"iouThreshold must be in [0, 1], but was '".concat(r,"'")})),g(2===e.rank,(function(){return"boxes must be a 2D tensor, but was of rank '".concat(e.rank,"'")})),g(4===e.shape[1],(function(){return"boxes must have 4 columns, but 2nd dimension was ".concat(e.shape[1])})),g(1===t.rank,(function(){return"scores must be a 1D tensor"})),g(t.shape[0]===i,(function(){return"scores has incompatible shape with boxes. Expected ".concat(i,", ")+"but was ".concat(t.shape[0])})),g(0<=o&&o<=1,(function(){return"softNmsSigma must be in [0, 1], but was '".concat(o,"'")})),{maxOutputSize:n,iouThreshold:r,scoreThreshold:a,softNmsSigma:o}}var Fl=Sa({nonMaxSuppression_:function(e,t,n,r,a){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY);var o=ka(e,"boxes","nonMaxSuppression","float32"),i=ka(t,"scores","nonMaxSuppression","float32"),s=Bl(o,i,n,r,a),u={maxOutputSize:n=s.maxOutputSize,iouThreshold:r=s.iouThreshold,scoreThreshold:a=s.scoreThreshold};return da.runKernel(Et,{boxes:o,scores:i},u)}});function Cl(e,t,n){var r=function(e,t,n){return function(e,t,n){var r=0,a=e.length,o=0,i=!1;for(;r>>1)]);s>0?r=o+1:(a=o,i=!s)}return i?r:-r-1}(e,t,n||Pl)}(e,t,n),a=r<0?-(r+1):r;e.splice(a,0,t)}function Pl(e,t){return e>t?1:ea&&h.push({score:t[f],boxIndex:f,suppressBeginIndex:0});h.sort(ql);for(var d=o>0?-.5/o:0,p=[],g=[];p.length0;){var v=h.pop(),m=v.score,y=v.boxIndex,b=v.suppressBeginIndex;if(m=b;--k){var x=Wl(e,y,p[k]);if(x>=r){w=!0;break}if(v.score=v.score*Gl(r,d,x),v.score<=a)break}v.suppressBeginIndex=p.length,w||(v.score===m?(p.push(y),g.push(v.score)):v.score>a&&Cl(h,v,ql))}var E=p.length,S=n-E;c&&S>0&&(p.push.apply(p,u([],s(new Array(S).fill(0)),!1)),g.push.apply(g,u([],s(new Array(S).fill(0)),!1)));var A={selectedIndices:p};return i&&(A.selectedScores=g),l&&(A.validOutputs=E),A}function Wl(e,t,n){var r=e.subarray(4*t,4*t+4),a=e.subarray(4*n,4*n+4),o=Math.min(r[0],r[2]),i=Math.min(r[1],r[3]),s=Math.max(r[0],r[2]),u=Math.max(r[1],r[3]),c=Math.min(a[0],a[2]),l=Math.min(a[1],a[3]),h=Math.max(a[0],a[2]),f=Math.max(a[1],a[3]),d=(s-o)*(u-i),p=(h-c)*(f-l);if(d<=0||p<=0)return 0;var g=Math.max(o,c),v=Math.max(i,l),m=Math.min(s,h),y=Math.min(u,f),b=Math.max(m-g,0)*Math.max(y-v,0);return b/(d+p-b)}function Gl(e,t,n){var r=Math.exp(t*n*n);return n<=e?r:0}function ql(e,t){return e.score-t.score||e.score===t.score&&t.boxIndex-e.boxIndex}var Kl=function(e,t,n,r,i){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),a(this,void 0,void 0,(function(){var a,s,u,c,l,h,f;return o(this,(function(o){switch(o.label){case 0:return a=ka(e,"boxes","nonMaxSuppressionAsync"),s=ka(t,"scores","nonMaxSuppressionAsync"),u=Bl(a,s,n,r,i),n=u.maxOutputSize,r=u.iouThreshold,i=u.scoreThreshold,[4,Promise.all([a.data(),s.data()])];case 1:return c=o.sent(),l=c[0],h=c[1],f=Ol(l,h,n,r,i).selectedIndices,a!==e&&a.dispose(),s!==t&&s.dispose(),[2,Gc(f,"int32")]}}))}))};var Vl=Sa({nonMaxSuppressionWithScore_:function(e,t,n,r,a,o){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===o&&(o=0);var i=ka(e,"boxes","nonMaxSuppression"),s=ka(t,"scores","nonMaxSuppression"),u=Bl(i,s,n,r,a,o),c={boxes:i,scores:s},l={maxOutputSize:n=u.maxOutputSize,iouThreshold:r=u.iouThreshold,scoreThreshold:a=u.scoreThreshold,softNmsSigma:o=u.softNmsSigma},h=da.runKernel(At,c,l);return{selectedIndices:h[0],selectedScores:h[1]}}});var Hl=function(e,t,n,r,i,s){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===s&&(s=0),a(this,void 0,void 0,(function(){var a,u,c,l,h,f,d,p,g;return o(this,(function(o){switch(o.label){case 0:return a=ka(e,"boxes","nonMaxSuppressionAsync"),u=ka(t,"scores","nonMaxSuppressionAsync"),c=Bl(a,u,n,r,i,s),n=c.maxOutputSize,r=c.iouThreshold,i=c.scoreThreshold,s=c.softNmsSigma,[4,Promise.all([a.data(),u.data()])];case 1:return l=o.sent(),h=l[0],f=l[1],d=zl(h,f,n,r,i,s),p=d.selectedIndices,g=d.selectedScores,a!==e&&a.dispose(),u!==t&&u.dispose(),[2,{selectedIndices:Gc(p,"int32"),selectedScores:Gc(g)}]}}))}))};var jl=Sa({nonMaxSuppressionPadded_:function(e,t,n,r,a,o){void 0===r&&(r=.5),void 0===a&&(a=Number.NEGATIVE_INFINITY),void 0===o&&(o=!1);var i=ka(e,"boxes","nonMaxSuppression"),s=ka(t,"scores","nonMaxSuppression"),u=Bl(i,s,n,r,a,null),c={boxes:i,scores:s},l={maxOutputSize:u.maxOutputSize,iouThreshold:u.iouThreshold,scoreThreshold:u.scoreThreshold,padToMaxOutputSize:o},h=da.runKernel(St,c,l);return{selectedIndices:h[0],validOutputs:h[1]}}});var Jl=function(e,t,n,r,i,u){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===u&&(u=!1),a(this,void 0,void 0,(function(){var a,c,l,h,f,d,p,g,v,m,y,b;return o(this,(function(o){switch(o.label){case 0:return a=ka(e,"boxes","nonMaxSuppressionAsync"),c=ka(t,"scores","nonMaxSuppressionAsync"),l=Bl(a,c,n,r,i,null),h=l.maxOutputSize,f=l.iouThreshold,d=l.scoreThreshold,[4,Promise.all([a.data(),c.data()])];case 1:return p=s.apply(void 0,[o.sent(),2]),g=p[0],v=p[1],m=Ll(g,v,h,f,d,u),y=m.selectedIndices,b=m.validOutputs,a!==e&&a.dispose(),c!==t&&c.dispose(),[2,{selectedIndices:Gc(y,"int32"),validOutputs:fs(b,"int32")}]}}))}))};var Zl=Sa({resizeBilinear_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=ka(e,"images","resizeBilinear");g(3===a.rank||4===a.rank,(function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got "+"rank ".concat(a.rank,".")})),g(2===t.length,(function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+"".concat(t,".")})),g(!1===r||!1===n,(function(){return"Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false."}));var o=a,i=!1;3===a.rank&&(i=!0,o=ii(a,[1,a.shape[0],a.shape[1],a.shape[2]])),s(t,0);var u={images:o},c={alignCorners:n,halfPixelCenters:r,size:t},l=da.runKernel(Wt,u,c);return i?ii(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var Yl=Sa({resizeNearestNeighbor_:function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var a=ka(e,"images","resizeNearestNeighbor");g(3===a.rank||4===a.rank,(function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got "+"rank ".concat(a.rank,".")})),g(2===t.length,(function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+"".concat(t,".")})),g("float32"===a.dtype||"int32"===a.dtype,(function(){return"`images` must have `int32` or `float32` as dtype"})),g(!1===r||!1===n,(function(){return"Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false."}));var o=a,i=!1;3===a.rank&&(i=!0,o=ii(a,[1,a.shape[0],a.shape[1],a.shape[2]])),s(t,0);var u={images:o},c={alignCorners:n,halfPixelCenters:r,size:t},l=da.runKernel(Ut,u,c);return i?ii(l,[l.shape[1],l.shape[2],l.shape[3]]):l}});var Xl=Sa({threshold_:function(e,t,n,r){var a;void 0===t&&(t="binary"),void 0===n&&(n=!1),void 0===r&&(r=.5);var o,i,u,c,l=ka(e,"image","threshold"),h=l.shape[0]*l.shape[1],f=Bo(Gc([r]),255);if(g(3===l.rank,(function(){return"Error in threshold: image must be rank 3,"+"but got rank ".concat(l.rank,".")})),g(3===l.shape[2]||1===l.shape[2],(function(){return"Error in threshold: image color channel must be equal to 3 or 1"+"but got ".concat(l.shape[2],".")})),g("int32"===l.dtype||"float32"===l.dtype,(function(){return"Error in dtype: image dtype must be int32 or float32,"+"but got dtype ".concat(l.dtype,".")})),g("otsu"===t||"binary"===t,(function(){return"Method must be binary or otsu, but was ".concat(t)})),3===l.shape[2]){o=(a=s(Fc(l,[1,1,1],-1),3))[0],i=a[1],u=a[2];var d=Bo(o,.2989),p=Bo(i,.587),v=Bo(u,.114);c=To(To(d,p),v)}else c=e;"otsu"===t&&(f=function(e,t){for(var n,r,a,o,i,s,u=Gc([-1]),c=Gc([0]),l=Gc([0]),h=0;h=2,(function(){return"bandPart(): Rank must be at least 2, got ".concat(r.rank,".")}));var a,o,i=r.shape,u=s(r.shape.slice(-2),2),c=u[0],l=u[1];"number"==typeof t?(g(t%1==0,(function(){return"bandPart(): numLower must be an integer, got ".concat(t,".")})),g(t<=c,(function(){return"bandPart(): numLower (".concat(t,")")+" must not be greater than the number of rows (".concat(c,").")})),a=ka(t<0?c:t,"numLower","bandPart")):(g("int32"===t.dtype,(function(){return"bandPart(): numLower's dtype must be an int32."})),a=Qi(Bs(t,0),c,iu(t,c))),"number"==typeof n?(g(n%1==0,(function(){return"bandPart(): numUpper must be an integer, got ".concat(n,".")})),g(n<=l,(function(){return"bandPart(): numUpper (".concat(n,")")+" must not be greater than the number of columns (".concat(l,").")})),o=ka(n<0?l:n,"numUpper","bandPart")):(g("int32"===n.dtype,(function(){return"bandPart(): numUpper's dtype must be an int32."})),o=Qi(Bs(n,0),l,iu(n,l)));var h=ii(uc(0,c,1,"int32"),[-1,1]),f=uc(0,l,1,"int32"),d=Ks(h,f),p=js(Fs(d,a),Is(d,Ws(o))),v=au([c,l],r.dtype);return ii(Lc(el(ii(r,[-1,c,l])).map((function(e){return Qi(p,e,v)}))),i)}});var eh=Sa({gramSchmidt_:function(e){var t;if(Array.isArray(e)){t=!1,g(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){g(e[t].shape[0]===n,(function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: "+"(".concat(e[t].shape[0]," vs. ").concat(n,")")}))},a=1;a0)for(var n=0;n=r?r:n,l=function(e){var t,c=o,l=u,h=a;t=s(da.tidy((function(){var t=fi(o,[e,e],[n-e,1]),s=ms(t),c=fi(o,[e,e],[1,1]),l=Qi(_s(c,0),qc([[-1]]),qc([[1]])),h=Ks(c,Bo(l,s)),f=Ro(t,h);u=1===f.shape[0]?No(i):ci([i,fi(f,[1,0],[f.shape[0]-1,f.shape[1]])],0);var d=Ws(Ro(li(l,h),s)),p=fi(o,[e,0],[n-e,r]),g=Bo(d,u),v=al(u);if(0===e)o=Ks(p,li(g,li(v,p)));else{var m=Ks(p,li(g,li(v,p)));o=ci([fi(o,[0,0],[e,r]),m],0)}var y=al(g),b=fi(a,[0,e],[n,a.shape[1]-e]);if(0===e)a=Ks(b,li(li(b,u),y));else{var w=Ks(b,li(li(b,u),y));a=ci([fi(a,[0,0],[n,e]),w],1)}return[u,o,a]})),3),u=t[0],o=t[1],a=t[2],Da([c,l,h])},h=0;hr&&(a=fi(a,[0,0],[n,r]),o=fi(o,[0,0],[r,r])),[a,o]}))}var nh,rh=Sa({qr_:function(e,t){if(void 0===t&&(t=!1),g(e.rank>=2,(function(){return"qr() requires input tensor to have a rank >= 2, but got rank ".concat(e.rank)})),2===e.rank)return th(e,t);var n=e.shape.slice(0,e.shape.length-2).reduce((function(e,t){return e*t})),r=el(ii(e,[n,e.shape[e.shape.length-2],e.shape[e.shape.length-1]]),0),a=[],o=[];return r.forEach((function(e){var n=s(th(e,t),2),r=n[0],i=n[1];a.push(r),o.push(i)})),[ii(Lc(a,0),e.shape),ii(Lc(o,0),e.shape)]}});e.Reduction=void 0,(nh=e.Reduction||(e.Reduction={}))[nh.NONE=0]="NONE",nh[nh.MEAN=1]="MEAN",nh[nh.SUM=2]="SUM",nh[nh.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS";var ah=Sa({computeWeightedLoss_:function(t,n,r){void 0===r&&(r=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var a=ka(t,"losses","computeWeightedLoss"),o=null;null!=n&&(o=ka(n,"weights","computeWeightedLoss"));var i=null==o?a:Bo(a,o);if(r===e.Reduction.NONE)return i;if(r===e.Reduction.SUM)return gs(i);if(r===e.Reduction.MEAN){if(null==o)return ru(i);var s=a.size/o.size,u=Ro(gs(i),gs(o));return s>1?Ro(u,fs(s)):u}if(r===e.Reduction.SUM_BY_NONZERO_WEIGHTS){if(null==o)return Ro(gs(i),fs(a.size));var c=Bo(o,ou(a.shape)),l=Io(gs(fu(c,fs(0))),"float32");return Ro(gs(i),l)}throw Error("Unknown reduction: ".concat(r))}});var oh=Sa({absoluteDifference_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=ka(t,"labels","absoluteDifference"),i=ka(n,"predictions","absoluteDifference"),s=null;null!=r&&(s=ka(r,"weights","absoluteDifference")),v(o.shape,i.shape,"Error in absoluteDifference: ");var u=Fo(Ks(o,i));return ah(u,s,a)}});var ih=Sa({cosineDistance_:function(t,n,r,a,o){void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=ka(t,"labels","cosineDistance"),s=ka(n,"predictions","cosineDistance"),u=null;null!=a&&(u=ka(a,"weights","cosineDistance")),v(i.shape,s.shape,"Error in cosineDistance: ");var c=fs(1),l=Ks(c,gs(Bo(i,s),r,!0));return ah(l,u,o)}});var sh=Sa({hingeLoss_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=ka(t,"labels","hingeLoss"),i=ka(n,"predictions","hingeLoss"),s=null;null!=r&&(s=ka(r,"weights","hingeLoss")),v(o.shape,i.shape,"Error in hingeLoss: ");var u=fs(1);o=Ks(Bo(fs(2),o),u);var c=hc(Ks(u,Bo(o,i)));return ah(c,s,a)}});var uh=Sa({huberLoss_:function(t,n,r,a,o){void 0===a&&(a=1),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=ka(t,"labels","huberLoss"),s=ka(n,"predictions","huberLoss"),u=null;null!=r&&(u=ka(r,"weights","huberLoss")),v(i.shape,s.shape,"Error in huberLoss: ");var c=fs(a),l=Fo(Ks(s,i)),h=iu(l,c),f=Ks(l,h),d=To(Bo(fs(.5),ps(h)),Bo(c,f));return ah(d,u,o)}});var ch=Sa({logLoss_:function(t,n,r,a,o){void 0===a&&(a=1e-7),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=ka(t,"labels","logLoss"),s=ka(n,"predictions","logLoss"),u=null;null!=r&&(u=ka(r,"weights","logLoss")),v(i.shape,s.shape,"Error in logLoss: ");var c=fs(1),l=fs(a),h=Ws(Bo(i,Ps(To(s,l)))),f=Bo(Ks(c,i),Ps(To(Ks(c,s),l))),d=Ks(h,f);return ah(d,u,o)}});var lh=Sa({meanSquaredError_:function(t,n,r,a){void 0===a&&(a=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var o=ka(t,"labels","meanSquaredError"),i=ka(n,"predictions","meanSquaredError"),s=null;null!=r&&(s=ka(r,"weights","meanSquaredError")),v(o.shape,i.shape,"Error in meanSquaredError: ");var u=Pc(o,i);return ah(u,s,a)}});var hh=Sa({sigmoidCrossEntropy_:function(t,n,r,a,o){void 0===a&&(a=0),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=ka(t,"multiClassLabels","sigmoidCrossEntropy"),s=ka(n,"logits","sigmoidCrossEntropy"),u=null;if(null!=r&&(u=ka(r,"weights","sigmoidCrossEntropy")),v(i.shape,s.shape,"Error in sigmoidCrossEntropy: "),a>0){var c=fs(a),l=fs(1),h=fs(.5);i=To(Bo(i,Ks(l,c)),Bo(h,c))}var f=function(e,t){var n=ka(e,"labels","sigmoidCrossEntropyWithLogits"),r=ka(t,"logits","sigmoidCrossEntropyWithLogits");v(n.shape,r.shape,"Error in sigmoidCrossEntropyWithLogits: ");var a=hc(r),o=Bo(r,n),i=Os(bs(Ws(Fo(r))));return To(Ks(a,o),i)}(i,s);return ah(f,u,o)}});var fh=Sa({softmaxCrossEntropy_:function(t,n,r,a,o){void 0===a&&(a=0),void 0===o&&(o=e.Reduction.SUM_BY_NONZERO_WEIGHTS);var i=ka(t,"onehotLabels","softmaxCrossEntropy"),u=ka(n,"logits","softmaxCrossEntropy"),c=null;if(null!=r&&(c=ka(r,"weights","softmaxCrossEntropy")),v(i.shape,u.shape,"Error in softmaxCrossEntropy: "),a>0){var l=fs(a),h=fs(1),f=fs(i.shape[1]);i=To(Bo(i,Ks(h,l)),Ro(l,f))}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 ".concat(t.rank," ")+"and dim was ".concat(n));var r=zs((function(e,t,r){var a=Hs(t,[n],!0),o=Ks(Io(t,"float32"),a);r([e,o]);var i=Ws(Bo(o,e));return{value:gs(i,[n]),gradFunc:function(e,t){var r=s(t,2),a=r[0],o=r[1],i=us(e.shape,[n]);return[Bo(ii(e,i),Ks(Io(a,"float32"),bs(o))),Bo(ii(e,i),Ks(bs(o),Io(a,"float32")))]}}}));return r(e,t)}(i,u);return ah(d,c,o)}});var dh=Sa({sparseFillEmptyRows_:function(e,t,n,r){var a=ka(e,"indices","sparseFillEmptyRows","int32"),o=ka(t,"values","sparseFillEmptyRows"),i=ka(n,"denseShape","sparseFillEmptyRows","int32"),s=ka(r,"defaultValue","sparseFillEmptyRows",o.dtype);if(2!==a.rank)throw new Error("Indices should be Tensor2D but received shape\n ".concat(a.shape));if(1!==o.rank)throw new Error("Values should be Tensor1D but received shape ".concat(o.shape));if(1!==i.rank)throw new Error("Dense shape should be Tensor1D but received shape ".concat(i.shape));if(0!==s.rank)throw new Error("Default value should be a scalar but received shape ".concat(s.shape));var u={indices:a,values:o,denseShape:i,defaultValue:s},c=da.runKernel(sn,u);return{outputIndices:c[0],outputValues:c[1],emptyRowIndicator:c[2],reverseIndexMap:c[3]}}});var ph=Sa({sparseReshape_:function(e,t,n){var r=ka(e,"inputIndices","sparseReshape","int32"),a=ka(t,"inputShape","sparseReshape","int32"),o=ka(n,"newShape","sparseReshape","int32");if(2!==r.rank)throw new Error("Input indices should be Tensor2D but received shape\n ".concat(r.shape));if(1!==a.rank)throw new Error("Input shape should be Tensor1D but received shape ".concat(a.shape));if(1!==o.rank)throw new Error("New shape should be Tensor1D but received shape ".concat(o.shape));var i={inputIndices:r,inputShape:a,newShape:o},s=da.runKernel(un,i);return{outputIndices:s[0],outputShape:s[1]}}});var gh=Sa({sparseSegmentMean_:function(e,t,n){var r=ka(e,"data","sparseSegmentMean"),a=ka(t,"indices","sparseSegmentMean","int32"),o=ka(n,"segmentIds","sparseSegmentMean","int32");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 ".concat(a.shape));if(1!==o.rank)throw new Error("Segment ids should be Tensor1D but received shape\n ".concat(o.shape));var i={data:r,indices:a,segmentIds:o};return da.runKernel(cn,i)}});var vh=Sa({sparseSegmentSum_:function(e,t,n){var r=ka(e,"data","sparseSegmentSum"),a=ka(t,"indices","sparseSegmentSum","int32"),o=ka(n,"segmentIds","sparseSegmentSum","int32");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 ".concat(a.shape));if(1!==o.rank)throw new Error("Segment ids should be Tensor1D but received shape\n ".concat(o.shape));var i={data:r,indices:a,segmentIds:o};return da.runKernel(ln,i)}});var mh=Sa({stringNGrams_:function(e,t,n,r,a,o,i,s){var u=ka(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: ".concat(u.shape));var c=ka(t,"dataSplits","stringNGrams");if("int32"!==c.dtype)throw new Error("Data splits must be of datatype int32");var l={separator:n,nGramWidths:r,leftPad:a,rightPad:o,padWidth:i,preserveShortSequences:s},h={data:u,dataSplits:c},f=da.runKernel(gn,h,l);return{nGrams:f[0],nGramsSplits:f[1]}}});var yh={fft:Dc,ifft:Rc,rfft:Cc,irfft:Bc},bh={hammingWindow:Sl,hannWindow:Al,frame:_l,stft:Il},wh={flipLeftRight:Ml,grayscaleToRGB:Tl,resizeNearestNeighbor:Yl,resizeBilinear:Zl,rgbToGrayscale:Dl,rotateWithOffset:Rl,cropAndResize:Nl,nonMaxSuppression:Fl,nonMaxSuppressionAsync:Kl,nonMaxSuppressionWithScore:Vl,nonMaxSuppressionWithScoreAsync:Hl,nonMaxSuppressionPadded:jl,nonMaxSuppressionPaddedAsync:Jl,threshold:Xl,transform:Ql},kh={bandPart:$l,gramSchmidt:eh,qr:rh},xh={absoluteDifference:oh,computeWeightedLoss:ah,cosineDistance:ih,hingeLoss:sh,huberLoss:uh,logLoss:ch,meanSquaredError:lh,sigmoidCrossEntropy:hh,softmaxCrossEntropy:fh},Eh={sparseFillEmptyRows:dh,sparseReshape:ph,sparseSegmentMean:gh,sparseSegmentSum:vh},Sh={stringNGrams:mh,stringSplit:Sa({stringSplit_:function(e,t,n){void 0===n&&(n=!0);var r=ka(e,"input","stringSplit","string"),a=ka(t,"delimiter","stringSplit","string");if(1!==r.rank)throw new Error("Input should be Tensor1D but received shape ".concat(r.shape));if(0!==a.rank)throw new Error("Delimiter should be a scalar but received shape ".concat(a.shape));var o={skipEmpty:n},i={input:r,delimiter:a},s=da.runKernel(vn,i,o);return{indices:s[0],values:s[1],shape:s[2]}}}),stringToHashBucketFast:Sa({stringToHashBucketFast_:function(e,t){var n=ka(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 da.runKernel(mn,a,r)}}),staticRegexReplace:Sa({staticRegexReplace_:function(e,t,n,r){void 0===r&&(r=!0);var a=ka(e,"input","staticRegexReplace","string"),o={pattern:t,rewrite:n,replaceGlobal:r};return da.runKernel(dn,{x:a},o)}})},Ah=new Map,_h=new Map,Ih=function(){function e(){}return e.prototype.getClassName=function(){return this.constructor.className},e.fromConfig=function(e,t){return new e(t)},e}(),Nh=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 Mh(e,t,n){g(null!=e.className,(function(){return"Class being registered does not have the static className property defined."})),g("string"==typeof e.className,(function(){return"className is required to be a string, but got type "+typeof e.className})),g(e.className.length>0,(function(){return"Class being registered has an empty-string as its className, which is disallowed."})),"undefined"==typeof t&&(t="Custom"),"undefined"==typeof n&&(n=e.className);var r=t+">"+n;return Nh.register(e),Ah.set(r,e),_h.set(e,r),e}var Th={__proto__:null,Serializable:Ih,SerializationMap:Nh,getRegisteredName:function(e){return _h.has(e)?_h.get(e):e.className},registerClass:Mh},Dh=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.minimize=function(e,t,n){void 0===t&&(t=!1);var r=this.computeGradients(e,n),a=r.value,o=r.grads;if(null!=n){var i=n.map((function(e){return{name:e.name,tensor:o[e.name]}}));this.applyGradients(i)}else this.applyGradients(o);return Da(o),t?a:(a.dispose(),null)},Object.defineProperty(t.prototype,"iterations",{get:function(){return null==this.iterations_&&(this.iterations_=0),this.iterations_},enumerable:!1,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return Ls(e,t)},t.prototype.dispose=function(){null!=this.iterations_&&Da(this.iterations_)},t.prototype.saveIterations=function(){return a(this,void 0,void 0,(function(){return o(this,(function(e){return null==this.iterations_&&(this.iterations_=0),[2,{name:"iter",tensor:fs(this.iterations_,"int32")}]}))}))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){return o(this,(function(e){throw new Error("getWeights() is not implemented for this optimizer yet.")}))}))},t.prototype.setWeights=function(e){return a(this,void 0,void 0,(function(){return o(this,(function(e){throw new Error("setWeights() is not implemented for this optimizer class "+"".concat(this.getClassName()))}))}))},t.prototype.extractIterations=function(e){return a(this,void 0,void 0,(function(){var t;return o(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}(Ih);Object.defineProperty(Dh,Symbol.hasInstance,{value:function(e){return null!=e.minimize&&null!=e.computeGradients&&null!=e.applyGradients}});var Rh=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=da.backend.epsilon()),a}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"Adadelta"},enumerable:!1,configurable:!0}),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=da.registeredVariables[n];null==t.accumulatedGrads[r]&&(t.accumulatedGrads[r]={originalName:"".concat(n,"/accum_grad"),variable:Ta((function(){return $i(a).variable(false)}))}),null==t.accumulatedUpdates[r]&&(t.accumulatedUpdates[r]={originalName:"".concat(n,"/accum_var"),variable:Ta((function(){return $i(a).variable(false)}))});var o=Array.isArray(e)?e[r].tensor:e[n];if(null!=o){var i=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;Ta((function(){var e=To(Bo(i,t.rho),Bo(ps(o),1-t.rho)),n=Bo(Ro(ds(To(s,t.epsilon)),ds(To(i,t.epsilon))),o),r=To(Bo(s,t.rho),Bo(ps(n),1-t.rho));i.assign(e),s.assign(r);var u=To(Bo(n,-t.learningRate),a);a.assign(u)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedUpdates&&(Da(this.accumulatedGrads.map((function(e){return e.variable}))),Da(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return e=u(u([],s(this.accumulatedGrads),!1),s(this.accumulatedUpdates),!1),[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 a(this,void 0,void 0,(function(){var t;return o(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(false)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(false)}})),[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}(Dh),Bh=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 r(t,e),Object.defineProperty(t,"className",{get:function(){return"Adagrad"},enumerable:!1,configurable:!0}),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=da.registeredVariables[n];if(null==t.accumulatedGrads[r]){t.accumulatedGrads[r]={originalName:"".concat(n,"/accumulator"),variable:Ta((function(){return Ai(a.shape,t.initialAccumulatorValue).variable(false)}))}}var o=Array.isArray(e)?e[r].tensor:e[n];if(null!=o){var i=t.accumulatedGrads[r].variable;Ta((function(){var e=To(i,ps(o));i.assign(e);var n=To(Bo(Ro(o,ds(To(e,da.backend.epsilon()))),-t.learningRate),a);a.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedGrads&&Da(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){return o(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 a(this,void 0,void 0,(function(){return o(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(false)}})),[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}(Dh),Fh=function(e){function t(t,n,r,a){void 0===a&&(a=null);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=a,o.accumulatedFirstMoment=[],o.accumulatedSecondMoment=[],Ta((function(){o.accBeta1=fs(n).variable(),o.accBeta2=fs(r).variable()})),null==a&&(o.epsilon=da.backend.epsilon()),o}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"Adam"},enumerable:!1,configurable:!0}),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);Ta((function(){var r=Ks(1,t.accBeta1),a=Ks(1,t.accBeta2);n.forEach((function(n,o){var i=da.registeredVariables[n];null==t.accumulatedFirstMoment[o]&&(t.accumulatedFirstMoment[o]={originalName:"".concat(n,"/m"),variable:Ta((function(){return $i(i).variable(false)}))}),null==t.accumulatedSecondMoment[o]&&(t.accumulatedSecondMoment[o]={originalName:"".concat(n,"/v"),variable:Ta((function(){return $i(i).variable(false)}))});var s=Array.isArray(e)?e[o].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[o].variable,c=t.accumulatedSecondMoment[o].variable,l=To(Bo(u,t.beta1),Bo(s,1-t.beta1)),h=To(Bo(c,t.beta2),Bo(ps(s),1-t.beta2)),f=Ro(l,r),d=Ro(h,a);u.assign(l),c.assign(h);var p=To(Bo(Ro(f,To(ds(d),t.epsilon)),-t.learningRate),i);i.assign(p)}})),t.accBeta1.assign(Bo(t.accBeta1,t.beta1)),t.accBeta2.assign(Bo(t.accBeta2,t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),null!=this.accumulatedFirstMoment&&Da(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedSecondMoment&&Da(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return e=u(u([],s(this.accumulatedFirstMoment),!1),s(this.accumulatedSecondMoment),!1),[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 a(this,void 0,void 0,(function(){var t,n=this;return o(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),Ta((function(){n.accBeta1.assign(hs(n.beta1,n.iterations_+1)),n.accBeta2.assign(hs(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(false)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(false)}})),[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}(Dh),Ch=function(e){function t(t,n,r,a,o){void 0===a&&(a=null),void 0===o&&(o=0);var i=e.call(this)||this;return i.learningRate=t,i.beta1=n,i.beta2=r,i.epsilon=a,i.decay=o,i.accumulatedFirstMoment=[],i.accumulatedWeightedInfNorm=[],Ta((function(){i.iteration=fs(0).variable(),i.accBeta1=fs(n).variable()})),null==a&&(i.epsilon=da.backend.epsilon()),i}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"Adamax"},enumerable:!1,configurable:!0}),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);Ta((function(){var r=Ks(1,t.accBeta1),a=Ro(-t.learningRate,To(Bo(t.iteration,t.decay),1));n.forEach((function(n,o){var i=da.registeredVariables[n];null==t.accumulatedFirstMoment[o]&&(t.accumulatedFirstMoment[o]={originalName:"".concat(n,"/m"),variable:$i(i).variable(false)}),null==t.accumulatedWeightedInfNorm[o]&&(t.accumulatedWeightedInfNorm[o]={originalName:"".concat(n,"/v"),variable:$i(i).variable(false)});var s=Array.isArray(e)?e[o].tensor:e[n];if(null!=s){var u=t.accumulatedFirstMoment[o].variable,c=t.accumulatedWeightedInfNorm[o].variable,l=To(Bo(u,t.beta1),Bo(s,1-t.beta1)),h=Bo(c,t.beta2),f=Fo(s),d=nu(h,f);u.assign(l),c.assign(d);var p=To(Bo(Ro(a,r),Ro(l,To(d,t.epsilon))),i);i.assign(p)}})),t.iteration.assign(To(t.iteration,1)),t.accBeta1.assign(Bo(t.accBeta1,t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),null!=this.accumulatedFirstMoment&&Da(this.accumulatedFirstMoment.map((function(e){return e.variable}))),null!=this.accumulatedWeightedInfNorm&&Da(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){return o(this,(function(e){throw new Error("getWeights() is not implemented for Adamax yet.")}))}))},t.prototype.setWeights=function(e){return a(this,void 0,void 0,(function(){return o(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}(Dh),Ph=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"SGD"},enumerable:!1,configurable:!0}),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var a=Array.isArray(e)?e[r].tensor:e[n];if(null!=a){var o=da.registeredVariables[n];Ta((function(){var e=To(Bo(t.c,a),o);o.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,null!=this.c&&this.c.dispose(),this.c=Ra(fs(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return a(this,void 0,void 0,(function(){return o(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}(Dh),Oh=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=fs(a.momentum),a}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"Momentum"},enumerable:!1,configurable:!0}),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=da.registeredVariables[n];if(null==t.accumulations[r]){t.accumulations[r]={originalName:"".concat(n,"/momentum"),variable:Ta((function(){return $i(a).variable(false)}))}}var o=t.accumulations[r].variable,i=Array.isArray(e)?e[r].tensor:e[n];null!=i&&Ta((function(){var e,n=To(Bo(t.m,o),i);e=t.useNesterov?To(Bo(t.c,To(i,Bo(n,t.m))),a):To(Bo(t.c,n),a),o.assign(n),a.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),null!=this.accumulations&&Da(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){return o(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 a(this,void 0,void 0,(function(){return o(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(false)}})),[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}(Ph),Lh=function(e){function t(t,n,r,a,o){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===a&&(a=null),void 0===o&&(o=!1);var i=e.call(this)||this;if(i.learningRate=t,i.decay=n,i.momentum=r,i.epsilon=a,i.accumulatedMeanSquares=[],i.accumulatedMoments=[],i.accumulatedMeanGrads=[],i.centered=o,null==a&&(i.epsilon=da.backend.epsilon()),null==t)throw new Error("learningRate for RMSPropOptimizer must be defined.");return i}return r(t,e),Object.defineProperty(t,"className",{get:function(){return"RMSProp"},enumerable:!1,configurable:!0}),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=da.registeredVariables[n],o=!1;null==t.accumulatedMeanSquares[r]&&(t.accumulatedMeanSquares[r]={originalName:"".concat(n,"/rms"),variable:Ta((function(){return $i(a).variable(o)}))}),null==t.accumulatedMoments[r]&&(t.accumulatedMoments[r]={originalName:"".concat(n,"/momentum"),variable:Ta((function(){return $i(a).variable(o)}))}),null==t.accumulatedMeanGrads[r]&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:"".concat(n,"/mg"),variable:Ta((function(){return $i(a).variable(o)}))});var i=Array.isArray(e)?e[r].tensor:e[n];if(null!=i){var s=t.accumulatedMeanSquares[r].variable,u=t.accumulatedMoments[r].variable;Ta((function(){var e=To(Bo(s,t.decay),Bo(ps(i),1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,o=To(Bo(n,t.decay),Bo(i,1-t.decay)),c=Ro(Bo(i,t.learningRate),ds(Ks(e,To(ps(o),t.epsilon)))),l=To(Bo(u,t.momentum),c);s.assign(e),n.assign(o),u.assign(l);var h=Ks(a,l);a.assign(h)}else{var f=To(Bo(s,t.decay),Bo(ps(i),1-t.decay));l=To(Bo(u,t.momentum),Ro(Bo(i,t.learningRate),ds(To(f,t.epsilon))));s.assign(f),u.assign(l);h=Ks(a,l);a.assign(h)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){null!=this.accumulatedMeanSquares&&Da(this.accumulatedMeanSquares.map((function(e){return e.variable}))),null!=this.accumulatedMeanGrads&&this.centered&&Da(this.accumulatedMeanGrads.map((function(e){return e.variable}))),null!=this.accumulatedMoments&&Da(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return a(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return e=u(u([],s(this.accumulatedMeanSquares),!1),s(this.accumulatedMoments),!1),this.centered&&e.push.apply(e,u([],s(this.accumulatedMeanGrads),!1)),[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 a(this,void 0,void 0,(function(){var t,n;return o(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),t=this.centered?e.length/3:e.length/2,n=!1,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(n)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(n)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(n)}}))),[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}(Dh),zh=[Rh,Bh,Fh,Ch,Oh,Lh,Ph];function Uh(e){return new Promise((function(e){return setTimeout(e)})).then(e)}var Wh=function(){function e(t){if(!Z().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 a(this,void 0,void 0,(function(){var t,n,r,a,i,s,u;return o(this,(function(o){switch(o.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=Ma.join(e.weightData),n=window.URL.createObjectURL(new Blob([t],{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 r=[{paths:["./"+this.weightDataFileName],weights:e.weightSpecs}],a=Ka(e,r),i=window.URL.createObjectURL(new Blob([JSON.stringify(a)],{type:"application/json"})),(s=null==this.modelJsonAnchor?document.createElement("a"):this.modelJsonAnchor).download=this.modelJsonFileName,s.href=i,[4,Uh((function(){return s.dispatchEvent(new MouseEvent("click"))}))];case 2:return o.sent(),null==e.weightData?[3,4]:((u=null==this.weightDataAnchor?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,u.href=n,[4,Uh((function(){return u.dispatchEvent(new MouseEvent("click"))}))]);case 3:o.sent(),o.label=4;case 4:return[2,{modelArtifactsInfo:ja(e)}]}}))}))},e}();Wh.URL_SCHEME="downloads://";var Gh=function(){function e(e){if(null==e||e.length<1)throw new Error("When calling browserFiles, at least 1 file is required, "+"but received ".concat(e));this.jsonFile=e[0],this.weightsFiles=e.slice(1)}return e.prototype.load=function(){return a(this,void 0,void 0,(function(){var e=this;return o(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),o=a.modelTopology;if(null!=o)if(null!=a.weightsManifest)if(0!==e.weightsFiles.length){var i=Ha(a,(function(t){return e.loadWeights(t)}));t(i)}else t({modelTopology:o});else n(new Error("weightManifest field is missing from file ".concat(e.jsonFile.name)));else n(new Error("modelTopology field is missing from file ".concat(e.jsonFile.name)))},r.onerror=function(t){return n("Failed to read model topology and weights manifest JSON "+"from file '".concat(e.jsonFile.name,"'. BrowserFiles supports loading ")+"Keras-style tf.Model artifacts only.")},r.readAsText(e.jsonFile)}))]}))}))},e.prototype.loadWeights=function(e){var t,n,r=this,a=[],o=[];try{for(var c=i(e),l=c.next();!l.done;l=c.next()){var h=l.value;a.push.apply(a,u([],s(h.weights),!1)),o.push.apply(o,u([],s(h.paths),!1))}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=c.return)&&n.call(c)}finally{if(t)throw t.error}}var f=this.checkManifestAndWeightFiles(e),d=o.map((function(e){return r.loadWeightsFile(e,f[e])}));return Promise.all(d).then((function(e){return[a,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 '".concat(e,"'."))},a.readAsArrayBuffer(t)}))},e.prototype.checkManifestAndWeightFiles=function(e){var t,n,r=this,a=[],o=this.weightsFiles.map((function(e){return qa(e.name)})),s={};try{for(var u=i(e),c=u.next();!c.done;c=u.next()){c.value.paths.forEach((function(e){var t=qa(e);if(-1!==a.indexOf(t))throw new Error("Duplicate file basename found in weights manifest: "+"'".concat(t,"'"));if(a.push(t),-1===o.indexOf(t))throw new Error("Weight file with basename '".concat(t,"' is not provided."));s[e]=r.weightsFiles[o.indexOf(t)]}))}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}if(a.length!==this.weightsFiles.length)throw new Error("Mismatch in the number of files in weights manifest "+"(".concat(a.length,") and the number of weight files provided ")+"(".concat(this.weightsFiles.length,")."));return s},e}();function qh(e,t,n,r){!function(e){g(null!=e&&Array.isArray(e)&&e.length>0,(function(){return"promises must be a none empty array"}))}(e),function(e,t){g(e>=0&&e<=1,(function(){return"Progress fraction must be in range [0, 1], but "+"got startFraction ".concat(e)})),g(t>=0&&t<=1,(function(){return"Progress fraction must be in range [0, 1], but "+"got endFraction ".concat(t)})),g(t>=e,(function(){return"startFraction must be no more than endFraction, but "+"got startFraction ".concat(e," and endFraction ")+"".concat(t)}))}(n=null==n?0:n,r=null==r?1:r);var a=0;return Promise.all(e.map((function(o){return o.then((function(o){var i=n+ ++a/e.length*(r-n);return t(i),o})),o})))}function Kh(e,t){return a(this,void 0,void 0,(function(){var n,r,a,i,s,u,c,l,h;return o(this,(function(o){switch(o.label){case 0:return null==t&&(t={}),n=null==t.fetchFunc?Z().platform.fetch:t.fetchFunc,r=e.map((function(e){return n(e,t.requestInit,{isBinary:!0})})),a=0,i=.5,null!=t.onProgress?[3,2]:[4,Promise.all(r)];case 1:return s=o.sent(),[3,4];case 2:return[4,qh(r,t.onProgress,a,i)];case 3:s=o.sent(),o.label=4;case 4:return u=s.map((function(e){return e.arrayBuffer()})),c=.5,l=1,null!=t.onProgress?[3,6]:[4,Promise.all(u)];case 5:return h=o.sent(),[3,8];case 6:return[4,qh(u,t.onProgress,c,l)];case 7:h=o.sent(),o.label=8;case 8:return[2,h]}}))}))}function Vh(e){var t=this;return function(n,r,i){return void 0===r&&(r=""),a(t,void 0,void 0,(function(){var t,a,s,u,c,l,h,f,d,p;return o(this,(function(o){switch(o.label){case 0:if(t=n.map((function(){return!1})),a={},s=null!=i?i.map((function(){return!1})):[],u=[],n.forEach((function(e,n){var r=0;e.weights.forEach((function(e){var o="quantization"in e?e.quantization.dtype:e.dtype,c=Na[o]*y(e.shape),l=function(){t[n]=!0,null==a[n]&&(a[n]=[]),a[n].push({manifestEntry:e,groupOffset:r,sizeBytes:c})};null!=i?i.forEach((function(t,n){t===e.name&&(l(),s[n]=!0)})):l(),u.push(e.name),r+=c}))})),!s.every((function(e){return e})))throw c=i.filter((function(e,t){return!s[t]})),new Error("Could not find weights in manifest with names: "+"".concat(c.join(", "),". \n")+"Manifest JSON has weights with names: "+"".concat(u.join(", "),"."));return l=t.reduce((function(e,t,n){return t&&e.push(n),e}),[]),h=[],l.forEach((function(e){n[e].paths.forEach((function(e){var t=r+(r.endsWith("/")?"":"/")+e;h.push(t)}))})),[4,e(h)];case 1:return f=o.sent(),d={},p=0,l.forEach((function(e){var t=n[e].paths.length,r=new Ma(f.slice(p,p+t));a[e].forEach((function(e){var t=Ca(r.slice(e.groupOffset,e.groupOffset+e.sizeBytes),[e.manifestEntry]);for(var n in t)d[n]=t[n]})),p+=t})),[2,d]}}))}))}}Za.registerSaveRouter((function(e){return Z().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(Wh.URL_SCHEME)?function(e){void 0===e&&(e="model");return new Wh(e)}(e.slice(Wh.URL_SCHEME.length)):null}));var Hh=function(){function e(e,t){if(this.DEFAULT_METHOD="POST",null==t&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.weightUrlConverter=t.weightUrlConverter,null!=t.fetchFunc?(g("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=Z().platform.fetch,g(null!=e&&e.length>0,(function(){return"URL path for http must not be null, undefined or empty."})),Array.isArray(e)&&g(2===e.length,(function(){return"URL paths for http must have a length of 2, "+"(actual length is ".concat(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||{},this.loadOptions=t}return e.prototype.save=function(e){return a(this,void 0,void 0,(function(){var t,n,r,a,i;return o(this,(function(o){switch(o.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=Ka(e,n),t.body.append("model.json",new Blob([JSON.stringify(r)],{type:"application/json"}),"model.json"),null!=e.weightData&&(a=Ma.join(e.weightData),t.body.append("model.weights.bin",new Blob([a],{type:"application/octet-stream"}),"model.weights.bin")),[4,this.fetch(this.path,t)];case 1:if((i=o.sent()).ok)return[2,{modelArtifactsInfo:ja(e),responses:[i]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+"".concat(i.status,"."))}}))}))},e.prototype.loadModelJSON=function(){return a(this,void 0,void 0,(function(){var e,t,n,r,a;return o(this,(function(o){switch(o.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(e=o.sent()).ok)throw new Error("Request to ".concat(this.path," failed with status code ")+"".concat(e.status,". Please verify this URL points to ")+"the model JSON of the model to load.");o.label=2;case 2:return o.trys.push([2,4,,5]),[4,e.json()];case 3:return t=o.sent(),[3,5];case 4:throw o.sent(),n="Failed to parse model JSON of response from ".concat(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,a=t.weightsManifest,null==r&&null==a)throw new Error("The JSON from HTTP path ".concat(this.path," contains neither model ")+"topology or manifest for weights.");return[2,t]}}))}))},e.prototype.load=function(){return a(this,void 0,void 0,(function(){var e=this;return o(this,(function(t){switch(t.label){case 0:return this.loadOptions.streamWeights?[2,this.loadStream()]:[4,this.loadModelJSON()];case 1:return[2,Ha(t.sent(),(function(t){return e.loadWeights(t)}))]}}))}))},e.prototype.loadStream=function(){return a(this,void 0,void 0,(function(){var e,t,n,r,i=this;return o(this,(function(s){switch(s.label){case 0:return[4,this.loadModelJSON()];case 1:return e=s.sent(),[4,this.getWeightUrls(e.weightsManifest)];case 2:return t=s.sent(),n=Ja(e.weightsManifest),r=function(){return function(e,t){var n,r,i=this,s=null==t.fetchFunc?Z().platform.fetch:t.fetchFunc,u=0;return null===(n=t.onProgress)||void 0===n||n.call(t,0),new ReadableStream({pull:function(n){return a(i,void 0,void 0,(function(){var a,i,c,l,h;return o(this,(function(o){switch(o.label){case 0:return ut?e.substring(n):"";return[r+"/",a]}(t),2),r=n[0],a=n[1],c=this.weightPathPrefix||r,l=[],h=[];try{for(f=i(e),d=f.next();!d.done;d=f.next()){p=d.value;try{for(S=void 0,g=i(p.paths),v=g.next();!v.done;v=g.next())m=v.value,null!=this.weightUrlConverter?h.push(this.weightUrlConverter(m)):l.push(c+m+a)}catch(e){S={error:e}}finally{try{v&&!v.done&&(A=g.return)&&A.call(g)}finally{if(S)throw S.error}}}}catch(e){x={error:e}}finally{try{d&&!d.done&&(E=f.return)&&E.call(f)}finally{if(x)throw x.error}}return this.weightUrlConverter?(b=(y=l.push).apply,w=[l],k=[[]],[4,Promise.all(h)]):[3,2];case 1:b.apply(y,w.concat([u.apply(void 0,k.concat([s.apply(void 0,[o.sent()]),!1]))])),o.label=2;case 2:return[2,l]}}))}))},e.prototype.loadWeights=function(e){return a(this,void 0,void 0,(function(){var t,n,r;return o(this,(function(a){switch(a.label){case 0:return[4,this.getWeightUrls(e)];case 1:return t=a.sent(),n=Ja(e),[4,Kh(t,this.loadOptions)];case 2:return r=a.sent(),[2,[n,r]]}}))}))},e}();function jh(e){return null!=e.match(Hh.URL_SCHEME_REGEX)}Hh.URL_SCHEME_REGEX=/^https?:\/\//;var Jh=function(e,t){if("undefined"==typeof fetch&&(null==t||null==t.fetchFunc))return null;return(Array.isArray(e)?e.every((function(e){return jh(e)})):jh(e))?Zh(e,t):null};function Zh(e,t){return new Hh(e,t)}Za.registerSaveRouter(Jh),Za.registerLoadRouter(Jh);var Yh=function(){function e(e){this.modelArtifacts=e}return e.prototype.load=function(){return this.modelArtifacts},e}(),Xh=function(){function e(e){this.saveHandler=e}return e.prototype.save=function(e){return this.saveHandler(e)},e}(),Qh=function(e){e.load&&(this.load=function(){return Promise.resolve(e.load())}),e.save&&(this.save=function(t){return Promise.resolve(e.save(t))})};function $h(e,t,n,r){if(1===arguments.length){var a=null!=e.modelTopology||null!=e.weightSpecs;return a?new Yh(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 Yh({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 Yh({modelTopology:e,weightSpecs:t,weightData:n,trainingConfig:r})}var ef={__proto__:null,CompositeArrayBuffer:Ma,browserFiles:function(e){return new Gh(e)},browserHTTPRequest:function(e,t){return Zh(e,t)},concatenateArrayBuffers:function(e){return Ma.join(e)},copyModel:function(e,t){return a(this,void 0,void 0,(function(){return o(this,(function(n){return!1,[2,ko(e,t,false)]}))}))},decodeWeights:Ca,decodeWeightsStream:function(e,t){return a(this,void 0,void 0,(function(){var n,r,s,u,c,l,h,f,d,p,g,v,m,b=this;return o(this,(function(w){switch(w.label){case 0:n={},r=e.getReader(),s=new ArrayBuffer(0),w.label=1;case 1:w.trys.push([1,7,8,9]),u=i(t),c=u.next(),w.label=2;case 2:return c.done?[3,6]:[4,Oa(l=c.value,(function(e,t){return a(b,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,za(r,s,t)];case 1:return[2,(s=n.sent()).slice(e,t)]}}))}))}))];case 3:return h=w.sent(),[4,za(r,s,h)];case 4:s=w.sent(),f=s.slice(0,h),s=s.slice(h),d=La(l,f),n[l.name]=d,"webgpu"===Ba()&&"uploadToGPU"in(p=Fa())&&y(d.shape)>=Z().get("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD")&&p.uploadToGPU(d.dataId),w.label=5;case 5:return c=u.next(),[3,2];case 6:return[3,9];case 7:return g=w.sent(),v={error:g},[3,9];case 8:try{c&&!c.done&&(m=u.return)&&m.call(u)}finally{if(v)throw v.error}return[7];case 9:return[2,n]}}))}))},encodeWeights:function(e,t){return a(this,void 0,void 0,(function(){var n,r,i,s,u,c=this;return o(this,(function(l){switch(l.label){case 0:for(n=[],r=[],i=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e),s=function(s){var u=i[s],l=Array.isArray(e)?e[s].tensor:e[u];if("float32"!==l.dtype&&"int32"!==l.dtype&&"bool"!==l.dtype&&"string"!==l.dtype&&"complex64"!==l.dtype)throw new Error("Unsupported dtype in weight '".concat(u,"': ").concat(l.dtype));var h={name:u,shape:l.shape,dtype:l.dtype};if("string"===l.dtype){var f=new Promise((function(e){return a(c,void 0,void 0,(function(){var t,n,r,a,i,s,u;return o(this,(function(o){switch(o.label){case 0:return[4,l.bytes()];case 1:for(t=o.sent(),n=t.reduce((function(e,t){return e+t.length}),0)+4*t.length,r=new Uint8Array(n),a=0,i=0;i0&&Number.isInteger(n),(function(){return"If provided, numClasses must be a positive integer, "+"but got ".concat(n)})),g(1===r.rank,(function(){return"Expected the rank of labels to be 1, but got ".concat(r.rank)})),g(1===a.rank,(function(){return"Expected the rank of predictions to be 1, "+"but got ".concat(a.rank)})),g(r.shape[0]===a.shape[0],(function(){return"Mismatch in the number of examples: "+"".concat(r.shape[0]," vs. ").concat(a.shape[0],". ")+"Labels and predictions should have the same number of elements."})),g(n>0&&Number.isInteger(n),(function(){return"numClasses is required to be a positive integer, but got "+"".concat(n)}));var o=du(Io(r,"int32"),n),i=du(Io(a,"int32"),n),s=al(o),u=li(s,i);return Io(u,"int32")}})},rf=!1;function af(e,t){if(void 0===t&&(t=3),t>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(null==e)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var n=!1,r=!1,a=!1,o=!1,i=!1,u=!1;if(e.data instanceof Uint8Array)n=!0;else if("undefined"!=typeof ImageData&&e instanceof ImageData)r=!0;else if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement)a=!0;else if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement)o=!0;else if(null!=e.getContext)i=!0;else{if(!("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap))throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, "+"but was ".concat(e.constructor.name));u=!0}if(null!=Pn(Nn,da.backendName)){var c={pixels:e},l={numChannels:t};return da.runKernel(Nn,c,l)}var h,f,d=s(a?[e.videoWidth,e.videoHeight]:[e.width,e.height],2),p=d[0],g=d[1];if(i)h=e.getContext("2d").getImageData(0,0,p,g).data;else if(r||n)h=e.data;else if(o||a||u){if(null==tf)if("undefined"==typeof document){if("undefined"==typeof OffscreenCanvas||"undefined"==typeof OffscreenCanvasRenderingContext2D)throw new Error("Cannot parse input in current context. Reason: OffscreenCanvas Context2D rendering is not supported.");tf=new OffscreenCanvas(1,1).getContext("2d")}else tf=document.createElement("canvas").getContext("2d",{willReadFrequently:!0});tf.canvas.width=p,tf.canvas.height=g,tf.drawImage(e,0,0,p,g),h=tf.getImageData(0,0,p,g).data}if(4===t)f=new Int32Array(h);else{var v=p*g;f=new Int32Array(v*t);for(var m=0;m4||2===t)throw new Error("toPixels only supports depth of size "+"1, 3 or 4 but got ".concat(t));if("float32"!==e.dtype&&"int32"!==e.dtype)throw new Error("Unsupported type for toPixels: ".concat(e.dtype,".")+" Please use float32 or int32 tensors.")}var uf={__proto__:null,draw:function(e,t,n){var r=ka(e,"img","draw");if(!(e instanceof Vr)){var a=r;r=Io(a,"int32"),a.dispose()}sf(r),function(e){var t=(null==e?void 0:e.alpha)||1;if(t>1||t<0)throw new Error("Alpha value ".concat(t," is suppoed to be in range [0 - 1]."))}(null==n?void 0:n.imageOptions);var o={image:r},i={canvas:t,options:n};da.runKernel(Le,o,i)},fromPixels:Sa({fromPixels_:af}),fromPixelsAsync:function(e,t){return void 0===t&&(t=3),a(this,void 0,void 0,(function(){var n,r;return o(this,(function(a){switch(a.label){case 0:if(n=null,!Z().getBool("WRAP_TO_IMAGEBITMAP")||!of(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,af(n,t)]}}))}))},toPixels:function(e,t){return a(this,void 0,void 0,(function(){var n,r,a,i,u,c,l,h,f,d,p,g,v,m,y,b;return o(this,(function(o){switch(o.label){case 0:return n=ka(e,"img","toPixels"),e instanceof Vr||(n=Io(r=n,"int32"),r.dispose()),sf(n),a=s(n.shape.slice(0,2),2),i=a[0],u=a[1],c=2===n.rank?1:n.shape[2],[4,n.data()];case 1:for(l=o.sent(),h="float32"===n.dtype?255:1,f=new Uint8ClampedArray(u*i*4),d=0;d1)throw new Error("Tensor values for a float32 Tensor must be in the "+"range [0 - 1] but encountered ".concat(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 ".concat(v,"."));1===c?(p[0]=v*h,p[1]=v*h,p[2]=v*h):p[g]=v*h}f[(m=4*d)+0]=Math.round(p[0]),f[m+1]=Math.round(p[1]),f[m+2]=Math.round(p[2]),f[m+3]=Math.round(p[3])}return null!=t&&(rf||null!=Pn(Le,da.backendName)&&(console.warn("tf.browser.toPixels is not efficient to draw tensor on canvas. Please try tf.browser.draw instead."),rf=!0),t.width=u,t.height=i,y=t.getContext("2d"),b=new ImageData(f,u,i),y.putImageData(b,0,0)),n!==e&&n.dispose(),[2,f]}}))}))}};function cf(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 ".concat(n,"."));if(r<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher,"+" but the rank was ".concat(r,"."));if("int32"!==t.dtype)throw new Error("tf.gatherND() expects the indices to be int32 type,"+" but the dtype was ".concat(t.dtype,"."));if(t.shape[r-1]>n)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+"".concat(t.shape[r-1]," vs. ").concat(n));if(0===y(e.shape))throw new Error("Requested more than 0 entries, but input is empty."+" Input shape: ".concat(e.shape,"."));for(var a=t.shape,o=a[a.length-1],i=1,c=0;c-1)o[c]=0;else{var l=ff(t,n,c),h=r[l];e&1<-1)o[c]=Number.MAX_SAFE_INTEGER;else{var l=ff(t,n,c),h=r[l];e&1<0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var u=r[a];return i<0&&(i+=u),i=d(0,i,u-1)}function yf(e,t,n,r,a,o){var i=t[a],s=n[a]||1;(e&1<0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var u=r[a];return i<0&&(i+=u),i=s>0?d(0,i,u):d(-1,i,u-1)}function bf(e,t,n,r,a,o){if(a[t])return n>0?o[t]:o[t+1&1];var i=e<0?r+e:e;return io[1]?o[1]:i}var wf,kf={__proto__:null,assertParamsValid:function(e,t,n){var r=e.shape.length;g(r===t.length,(function(){return"Error in slice".concat(r,"D: Length of begin ").concat(t," must ")+"match the rank of the array (".concat(r,").")})),g(r===n.length,(function(){return"Error in slice".concat(r,"D: Length of size ").concat(n," must ")+"match the rank of the array (".concat(r,").")}));for(var a=function(a){g(t[a]+n[a]<=e.shape[a],(function(){return"Error in slice".concat(r,"D: begin[").concat(a,"] + size[").concat(a,"] ")+"(".concat(t[a]+n[a],") would overflow input.shape[").concat(a,"] (").concat(e.shape[a],")")}))},o=0;o0?e[e.length-1]:1,r=0;r0){var d=t[0],p=n+1;l=pf(i,d,p,r,e),h=gf(s,d,p,a,e),f=hf(o,d,p,e)}else for(var g=0;g1){r=a;break}for(a=r+1;a0||n[a]!==e[a])return!1;return!0},maskToAxes:function(e){for(var t=[],n=0;e>0;)1&e&&t.push(n),e/=2,n++;return t},parseSliceParams:function(e,t,n){var r,a,o=e.shape.length;return(r="number"==typeof t?u([t],s(new Array(o-1).fill(0)),!1):t.length=0?t:(g(-1===t,(function(){return"Negative size values should be exactly -1 but got "+"".concat(t," for the slice() size at index ").concat(n,".")})),e.shape[n]-r[n])})),[r,a]},sliceInfo:function(e,t,n,r,a,o,i,s,u){var c;if(null==r?(c=new Array(t.length)).fill(1):c=r,null!=i&&0!=(i&i-1))throw new Error("Multiple ellipses in slice is not allowed.");for(var l=!1,h={dims:c.length,numAddAxisAfterEllipsis:0,begin:t.slice(),end:n.slice(),strides:c.slice(),beginMask:a,endMask:o,ellipsisMask:i,newAxisMask:s,shrinkAxisMask:u},f=0;f0?0:-1,d.strides[f]>0?w:w-1];if(b&&d.strides[f]<=0)throw Error("only stride 1 allowed on non-range indexing.");v=v&&1===d.strides[f];var E=!!(d.beginMask&1<=w)throw Error("slice index ".concat(d.begin[f]," of dimension ").concat(f," out of bounds."))}else d.begin[f]=bf(d.begin[f],0,d.strides[f],w,k,x),d.end[f]=bf(d.end[f],1,d.strides[f],w,k,x);var A=1===d.strides[f]&&0===d.begin[f]&&d.end[f]===w;p=p&&A,g=g&&(0===f&&1===d.strides[f]||A)}else p=p&&1===d.strides[f]&&E,g=g&&(0===f&&1===d.strides[f]||E);var _=void 0,I=!1;if(d.beginValid&&d.endValid?(_=d.end[f]-d.begin[f],I=!0):b?(_=1,I=!0):E&&w>=0&&(_=d.strides[f]<0?-w:w,I=!0),I){var N=void 0;N=0===_||_<0!=d.strides[f]<0?0:Math.trunc(_/d.strides[f])+(_%d.strides[f]!=0?1:0),m.push(N)}else m.push(-1)}else m.push(b?1:-1)}for(var M=0;M=0?y.push(m[T]):-2===T&&y.push(1)}var D=y.filter((function(e,t){return-2!==d.finalShapeGatherIndices[t]}));return{finalShapeSparse:D,finalShape:y,isIdentity:p,sliceDim0:g,isSimpleSlice:v,begin:d.begin,end:d.end,strides:d.strides}},startForAxis:mf,startIndicesWithElidedDims:pf,stopForAxis:yf,stopIndicesWithElidedDims:gf,stridesForAxis:vf,stridesWithElidedDims:hf},xf=function(){function e(){}return e.sgd=function(e){return new Ph(e)},e.momentum=function(e,t,n){return void 0===n&&(n=!1),new Oh(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 Lh(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 Fh(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 Rh(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 Ch(e,t,n,r,a)},e.adagrad=function(e,t){return void 0===t&&(t=.1),new Bh(e,t)},e}(),Ef=xf,Sf="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:"undefined"!=typeof setImmediate?setImmediate:function(e){return e()};!function(e){e[e.FIRST_DIM_SIZE=0]="FIRST_DIM_SIZE",e[e.VALUE_ROWIDS=1]="VALUE_ROWIDS",e[e.ROW_LENGTHS=2]="ROW_LENGTHS",e[e.ROW_SPLITS=3]="ROW_SPLITS",e[e.ROW_LIMITS=4]="ROW_LIMITS",e[e.ROW_STARTS=5]="ROW_STARTS"}(wf||(wf={}));var Af="->",_f=/->/g;function If(e,t){for(var n=[],r=0;r=0&&t1)throw new Error('Equation must contain exactly one arrow ("'.concat(Af,'").'));var r=s(e.split(Af),2),a=r[0],o=r[1];g(-1===a.indexOf("..."),(function(){return'The ellipsis notation ("'.concat("...",'") is not supported yet.')}));var i=a.split(","),u=i.length;if(t!==u)throw new Error("Expected ".concat(u," input tensors, received ").concat(t));if(u>2)throw new Error("Support for more than 2 input tensors is not implemented yet.");for(var c=[],l=function(e){var t=o[e];if(!i.some((function(e){return-1!==e.indexOf(t)})))throw new Error("Output subscripts contain the label ".concat(t," ")+"not present in the input subscripts.");-1===c.indexOf(t)&&c.push(t)},h=0;h=2*t+1||a%2==1?i.push(a):o.push(a);r.push.apply(r,u([],s(o),!1)),r.push(0),r.push.apply(r,u([],s(i),!1))}return r},getRaggedRank:function(e){return 0===e.length?0:e[0]===wf.FIRST_DIM_SIZE?e.length-1:e.length},getReductionAxes:Ji,getReshaped:function(e,t,n,r){void 0===r&&(r=!0);var a=[];if(r)(a=a.concat(t.slice(0))).push(e[0]/n),a=a.concat(e.slice(1));else{a=a.concat(e[0]);for(var o=t.length,i=0;i= ").concat(n)},getSparseReshapeEmptyTensorZeroOutputDimErrorMessage:function(){return"reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero"},getSparseReshapeInputOutputMismatchErrorMessage:function(e,t){var n=y(e),r=y(t);return"Input to reshape is a tensor with ".concat(n," dense values, but the requested shape has ").concat(r,". inputShape=").concat(e," outputShape=").concat(t)},getSparseReshapeInputOutputMultipleErrorMessage:function(e,t){var n=y(e),r=y(t);return"Input to reshape is a SparseTensor with ".concat(n,"\n dense values, but the requested shape requires a multiple of ").concat(r,". inputShape=").concat(e," outputShape= ").concat(t)},getSparseReshapeMultipleNegativeOneOutputDimErrorMessage:function(e,t){return"only one output dimension may be -1, not both ".concat(e," and ").concat(t)},getSparseReshapeNegativeOutputDimErrorMessage:function(e,t){return"size ".concat(e," must be non-negative, not ").concat(t)},getSparseSegmentReductionIndicesOutOfRangeErrorMessage:function(e,t,n){return"Bad: indices[".concat(e,"] == ").concat(t," out of range [0, ").concat(n,")")},getSparseSegmentReductionNegativeSegmentIdsErrorMessage:function(){return"segment ids must be >= 0"},getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage:function(){return"segment ids are not increasing"},getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage:function(e,t){return"Segment id ".concat(e," out of range [0, ").concat(t,"), possibly because segmentIds input is not sorted.")},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]}))},isIdentityPermutation:function(e){return e.every((function(e,t){return e===t}))},log:function(){for(var e=[],t=0;t0?e+t:e}));t[a]=e.shape[n]-o}g(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},segment_util:{__proto__:null,collectGatherOpShapeInfo:function(e,t,n,r){var a=t.shape.length,o=e.shape.length;if(0!==r&&(r<-a||r>a))throw new Error("Expect batchDims in the range of [-".concat(a,", ").concat(a,"], but got ").concat(r));if(r<0&&(r+=a),r>o)throw new Error("batchDims (".concat(r,") must be less than rank(x) (\n ").concat(o,")."));if(nt||n===e?r=!0:n=P(e,n+1);return n}},shouldFuse:ml,slice_util:kf,splitRealAndImagArrays:function(e){for(var t=new Float32Array(e.length/2),n=new Float32Array(e.length/2),r=0;r=r)throw new Error("defaultValue.shape=".concat(e," and ragged tensor flatValues.shape=").concat(t,", are incompatible: defaultValue.rank = ").concat(n," must be less than ragged tensor input flatValues.rank = ").concat(r,")"));for(var a=0;a=0&&i>=0&&1!==o&&o!==i)throw new Error("defaultValue.shape=".concat(e,", and ragged tensor input flatValues.shape=").concat(t," are incompatible: defaultValue.shape[").concat(a-e.length,"] = ").concat(o," but ragged tensor input.flatValues.shape[").concat(a-e.length,"] = ").concat(i))}}},validateInput:Hc,validateUpdateShape:Vc,warn:Bn},Mf={__proto__:null,nonMaxSuppressionV3Impl:Ol,nonMaxSuppressionV4Impl:Ll,nonMaxSuppressionV5Impl:zl,whereImpl:tl};!function(){var e,t;try{for(var n=i(zh),r=n.next();!r.done;r=n.next()){Mh(r.value)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}}(),e.Abs="Abs",e.Acos=Q,e.Acosh=$,e.AdadeltaOptimizer=Rh,e.AdagradOptimizer=Bh,e.AdamOptimizer=Fh,e.AdamaxOptimizer=Ch,e.Add=ee,e.AddN=te,e.All="All",e.Any="Any",e.ArgMax=ne,e.ArgMin=re,e.Asin=ae,e.Asinh=oe,e.Atan=ie,e.Atan2=ue,e.Atanh=se,e.AvgPool=ce,e.AvgPool3D=le,e.AvgPool3DGrad="AvgPool3DGrad",e.AvgPoolGrad="AvgPoolGrad",e.BatchMatMul=he,e.BatchToSpaceND=fe,e.Bincount=de,e.BitwiseAnd=pe,e.BroadcastArgs=ge,e.BroadcastTo="BroadcastTo",e.Cast=ve,e.Ceil=me,e.ClipByValue=ye,e.Complex=be,e.ComplexAbs=we,e.Concat=ke,e.Conv2D=xe,e.Conv2DBackpropFilter=Ee,e.Conv2DBackpropInput=Se,e.Conv3D=Ae,e.Conv3DBackpropFilterV2="Conv3DBackpropFilterV2",e.Conv3DBackpropInputV2=_e,e.Cos="Cos",e.Cosh=Ie,e.CropAndResize=Te,e.Cumprod=Ne,e.Cumsum=Me,e.DataStorage=c,e.DenseBincount=De,e.DepthToSpace=Re,e.DepthwiseConv2dNative=Be,e.DepthwiseConv2dNativeBackpropFilter=Fe,e.DepthwiseConv2dNativeBackpropInput=Ce,e.Diag=Pe,e.Dilation2D=Oe,e.Dilation2DBackpropFilter="Dilation2DBackpropFilter",e.Dilation2DBackpropInput="Dilation2DBackpropInput",e.Draw=Le,e.Einsum=Ue,e.Elu="Elu",e.EluGrad="EluGrad",e.Environment=H,e.Equal=We,e.Erf="Erf",e.Exp="Exp",e.ExpandDims=Ge,e.Expm1=qe,e.FFT="FFT",e.Fill=Ke,e.FlipLeftRight=Ve,e.Floor=He,e.FloorDiv=je,e.FromPixels=Nn,e.FusedBatchNorm=Je,e.FusedConv2D=Dn,e.FusedDepthwiseConv2D=Rn,e.GatherNd=Ye,e.GatherV2=Ze,e.Greater=Xe,e.GreaterEqual=Qe,e.IFFT=et,e.Identity=$e,e.Imag=tt,e.IsFinite=nt,e.IsInf=rt,e.IsNan=at,e.KernelBackend=l,e.LRN="LRN",e.LRNGrad="LRNGrad",e.LeakyRelu=ot,e.Less=it,e.LessEqual=st,e.LinSpace=ut,e.Log="Log",e.Log1p=ct,e.LogSoftmax="LogSoftmax",e.LogicalAnd=lt,e.LogicalNot=ht,e.LogicalOr=ft,e.LogicalXor="LogicalXor",e.LowerBound="LowerBound",e.MatrixBandPart="MatrixBandPart",e.Max="Max",e.MaxPool=pt,e.MaxPool3D=gt,e.MaxPool3DGrad="MaxPool3DGrad",e.MaxPoolGrad="MaxPoolGrad",e.MaxPoolWithArgmax=vt,e.Maximum=dt,e.Mean=mt,e.Min="Min",e.Minimum=yt,e.MirrorPad=bt,e.Mod="Mod",e.MomentumOptimizer=Oh,e.Multinomial=wt,e.Multiply=kt,e.Neg="Neg",e.NonMaxSuppressionV3=Et,e.NonMaxSuppressionV4=St,e.NonMaxSuppressionV5=At,e.NotEqual=xt,e.OP_SCOPE_SUFFIX=Ea,e.OneHot=It,e.OnesLike=_t,e.Optimizer=Dh,e.OptimizerConstructors=xf,e.Pack=Nt,e.PadV2=Mt,e.Pool="Pool",e.Pow="Pow",e.Prelu=Tt,e.Prod=Dt,e.RMSPropOptimizer=Lh,e.RaggedGather=Rt,e.RaggedRange=Bt,e.RaggedTensorToTensor=Ft,e.Range=Ct,e.Real=Pt,e.RealDiv=ze,e.Reciprocal=Ot,e.Relu=Lt,e.Relu6=Gt,e.Reshape=zt,e.ResizeBilinear=Wt,e.ResizeBilinearGrad="ResizeBilinearGrad",e.ResizeNearestNeighbor=Ut,e.ResizeNearestNeighborGrad="ResizeNearestNeighborGrad",e.Reverse=qt,e.RotateWithOffset=Mn,e.Round=Kt,e.Rsqrt=Vt,e.SGDOptimizer=Ph,e.ScatterNd=Ht,e.SearchSorted=Jt,e.Select=Zt,e.Selu=Yt,e.Sigmoid=en,e.Sign=$t,e.Sin="Sin",e.Sinh=Qt,e.Slice=Xt,e.Softmax=on,e.Softplus=tn,e.SpaceToBatchND=rn,e.SparseFillEmptyRows=sn,e.SparseReshape=un,e.SparseSegmentMean=cn,e.SparseSegmentSum=ln,e.SparseToDense=hn,e.SplitV=an,e.Sqrt=nn,e.Square="Square",e.SquaredDifference=fn,e.StaticRegexReplace=dn,e.Step=In,e.StridedSlice=pn,e.StringNGrams=gn,e.StringSplit=vn,e.StringToHashBucketFast=mn,e.Sub="Sub",e.Sum="Sum",e.Tan="Tan",e.Tanh=yn,e.Tensor=Vr,e.TensorBuffer=Gr,e.TensorScatterUpdate=jt,e.Tile=bn,e.TopK=wn,e.Transform=kn,e.Transpose=xn,e.Unique=En,e.Unpack=Sn,e.UnsortedSegmentSum=An,e.UpperBound="UpperBound",e.Variable=Qr,e.ZerosLike=_n,e._FusedMatMul=Tn,e.abs=Fo,e.acos=Co,e.acosh=Po,e.add=To,e.addN=Oo,e.all=Lo,e.any=zo,e.argMax=Uo,e.argMin=Wo,e.asin=Go,e.asinh=qo,e.atan=Ko,e.atan2=Vo,e.atanh=Ho,e.avgPool=si,e.avgPool3d=ui,e.backend=Fa,e.backend_util=Nf,e.basicLSTMCell=pi,e.batchNorm=vi,e.batchNorm2d=mi,e.batchNorm3d=yi,e.batchNorm4d=bi,e.batchToSpaceND=gi,e.bincount=wi,e.bitwiseAnd=ki,e.booleanMaskAsync=rl,e.broadcastArgs=xi,e.broadcastTo=Ei,e.broadcast_util=Yi,e.browser=uf,e.buffer=_o,e.cast=Io,e.ceil=Si,e.clipByValue=_i,e.clone=No,e.complex=Aa,e.concat=ci,e.concat1d=Ii,e.concat2d=Ni,e.concat3d=Mi,e.concat4d=Ti,e.conv1d=Ri,e.conv2d=Di,e.conv2dTranspose=Fi,e.conv3d=Ci,e.conv3dTranspose=Oi,e.copyRegisteredKernels=function(e,t){Ln(e).forEach((function(e){zn(Object.assign({},e,{backendName:t}))}))},e.cos=Li,e.cosh=zi,e.cosineWindow=hl,e.cumprod=Ui,e.cumsum=Wi,e.customGrad=zs,e.denseBincount=Gi,e.deprecationWarn=function(e){Z().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")},e.depthToSpace=qi,e.depthwiseConv2d=Ki,e.device_util=va,e.diag=Vi,e.dilation2d=Hi,e.disableDeprecationWarnings=function(){Z().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")},e.dispose=Da,e.disposeVariables=function(){da.disposeVariables()},e.div=Ro,e.divNoNan=es,e.dot=ts,e.dropout=cl,e.einsum=ns,e.elu=rs,e.enableDebugMode=function(){Z().set("DEBUG",!0)},e.enableProdMode=function(){Z().set("PROD",!0)},e.enclosingPowerOfTwo=ll,e.engine=function(){return da},e.ensureShape=as,e.env=Z,e.equal=Xi,e.erf=os,e.euclideanNorm=ys,e.exp=bs,e.expandDims=ws,e.expm1=ks,e.eye=Es,e.fft=Dc,e.fill=Ai,e.findBackend=function(e){return da.findBackend(e)},e.findBackendFactory=function(e){return da.findBackendFactory(e)},e.floor=Ss,e.floorDiv=Do,e.fused=El,e.gather=As,e.gatherND=ul,e.gather_util=lf,e.getBackend=Ba,e.getGradient=On,e.getKernel=Pn,e.getKernelsForBackend=Ln,e.grad=function(e){return g(C(e),(function(){return"The f passed in grad(f) must be a function"})),function(t,n){var r=ka(t,"x","tf.grad","string_or_numeric"),a=null!=n?ka(n,"dy","tf.grad"):null;return da.tidy((function(){var t=da.gradients((function(){return e(r)}),[r],a),n=t.value,o=t.grads;return null!=a&&v(n.shape,a.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Us(o),o[0]}))}},e.grads=function(e){return g(C(e),(function(){return"The f passed in grads(f) must be a function"})),function(t,n){g(Array.isArray(t),(function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"}));var r=xa(t,"args","tf.grads","string_or_numeric"),a=null!=n?ka(n,"dy","tf.grads"):null;return da.tidy((function(){var t=da.gradients((function(){return e.apply(void 0,u([],s(r),!1))}),r,a),n=t.value,o=t.grads;return null!=a&&v(n.shape,a.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Us(o),o}))}},e.greater=_s,e.greaterEqual=Is,e.ifft=Rc,e.imag=Ns,e.image=wh,e.inTopKAsync=fl,e.io=ef,e.irfft=Bc,e.isFinite=Ms,e.isInf=Ts,e.isNaN=Ds,e.keep=Ra,e.kernel_impls=Mf,e.leakyRelu=Rs,e.less=Bs,e.lessEqual=Fs,e.linalg=kh,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 da.runKernel(ut,{},r)},e.localResponseNormalization=Cs,e.log=Ps,e.log1p=Os,e.logSigmoid=qs,e.logSoftmax=Vs,e.logSumExp=Hs,e.logicalAnd=js,e.logicalNot=Js,e.logicalOr=Zs,e.logicalXor=Ys,e.losses=xh,e.lowerBound=function(e,t){return Qs(e,t,"left")},e.matMul=li,e.math=nf,e.max=cs,e.maxPool=$s,e.maxPool3d=eu,e.maxPoolWithArgmax=tu,e.maximum=nu,e.mean=ru,e.memory=function(){return da.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("".concat(a," is not a valid third argument to meshgrid"));if(void 0===e)return[];var o=ka(e,"x","meshgrid",e instanceof Vr?e.dtype:"float32");if(void 0===t)return[o];var i=ka(t,"y","meshgrid",t instanceof Vr?t.dtype:"float32"),s=y(o.shape),u=y(i.shape);return"xy"===a?(o=ii(o,[1,-1]),i=ii(i,[-1,1]),[li(ou([u,1],o.dtype),o),li(i,ou([1,s],i.dtype))]):(o=ii(o,[-1,1]),i=ii(i,[1,-1]),[li(o,ou([1,u],o.dtype)),li(ou([s,1],i.dtype),i)])},e.min=ls,e.minimum=iu,e.mirrorPad=su,e.mod=uu,e.moments=cu,e.movingAverage=ol,e.mul=Bo,e.multiRNNCell=lu,e.multinomial=hu,e.neg=Ws,e.nextFrame=function(){return new Promise((function(e){return Sf((function(){return e()}))}))},e.norm=ms,e.notEqual=fu,e.oneHot=du,e.ones=ou,e.onesLike=pu,e.op=Sa,e.outerProduct=gu,e.pad=vu,e.pad1d=mu,e.pad2d=yu,e.pad3d=bu,e.pad4d=wu,e.pool=xu,e.pow=hs,e.prelu=Eu,e.print=Mo,e.prod=Su,e.profile=function(e){return da.profile(e)},e.raggedGather=Au,e.raggedRange=_u,e.raggedTensorToTensor=Iu,e.rand=Nu,e.randomGamma=rc,e.randomNormal=ac,e.randomStandardNormal=oc,e.randomUniform=ic,e.randomUniformInt=sc,e.range=uc,e.ready=function(){return da.ready()},e.real=cc,e.reciprocal=lc,e.registerBackend=function(e,t,n){return void 0===n&&(n=1),da.registerBackend(e,t,n)},e.registerGradient=function(e){var t=e.kernelName;Cn.has(t)&&Z().getBool("DEBUG")&&Bn("Overriding the gradient for '".concat(t,"'")),Cn.set(t,e)},e.registerKernel=zn,e.relu=hc,e.relu6=fc,e.removeBackend=function(e){da.removeBackend(e)},e.reshape=ii,e.reverse=dc,e.reverse1d=pc,e.reverse2d=gc,e.reverse3d=vc,e.reverse4d=mc,e.rfft=Cc,e.round=yc,e.rsqrt=bc,e.scalar=fs,e.scatterND=il,e.scatter_util=Jc,e.searchSorted=Qs,e.selu=wc,e.separableConv2d=kc,e.serialization=Th,e.setBackend=function(e){return da.setBackend(e)},e.setPlatform=function(e,t){Z().setPlatform(e,t)},e.setdiff1dAsync=xc,e.sigmoid=hi,e.sign=Ec,e.signal=bh,e.sin=Sc,e.sinh=Ac,e.slice=fi,e.slice1d=_c,e.slice2d=Ic,e.slice3d=Nc,e.slice4d=Mc,e.slice_util=kf,e.softmax=Tc,e.softplus=Gs,e.spaceToBatchND=ku,e.sparse=Eh,e.sparseToDense=sl,e.spectral=yh,e.split=Fc,e.sqrt=ds,e.square=ps,e.squaredDifference=Pc,e.squeeze=Oc,e.stack=Lc,e.step=zc,e.stridedSlice=Uc,e.string=Sh,e.sub=Ks,e.sum=gs,e.sumOutType=function(e){return ea(e,"int32")},e.tan=Wc,e.tanh=di,e.tensor=Ia,e.tensor1d=Gc,e.tensor2d=qc,e.tensor3d=Kc,e.tensor4d=function(e,t,n){if(m(e),null!=t&&4!==t.length)throw new Error("tensor4d() requires shape to have four numbers");var r=ya(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 _a(e,t,r,n)},e.tensor5d=function(e,t,n){if(m(e),null!=t&&5!==t.length)throw new Error("tensor5d() requires shape to have five numbers");var r=ya(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 _a(e,t,r,n)},e.tensor6d=function(e,t,n){if(m(e),null!=t&&6!==t.length)throw new Error("tensor6d() requires shape to have six numbers");var r=ya(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 _a(e,t=t||r,r,n)},e.tensorScatterUpdate=Zc,e.tensor_util=sa,e.test_util=$u,e.tidy=Ta,e.tile=xs,e.time=function(e){return da.time(e)},e.topk=Yc,e.train=Ef,e.transpose=al,e.truncatedNormal=Xc,e.unique=Qc,e.unregisterGradient=function(e){if(!Cn.has(e))throw new Error("The gradient '".concat(e,"' for backend is not registered"));Cn.delete(e)},e.unregisterKernel=function(e,t){var n=Un(e,t);if(!Fn.has(n))throw new Error("The kernel '".concat(e,"' for backend ")+"'".concat(t,"' is not registered"));Fn.delete(n)},e.unsortedSegmentSum=$c,e.unstack=el,e.upcastType=ea,e.upperBound=function(e,t){return Qs(e,t,"right")},e.util=Fr,e.valueAndGrad=function(e){return g(C(e),(function(){return"The f passed in valueAndGrad(f) must be a function"})),function(t,n){g(t instanceof Vr,(function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"})),g(null==n||n instanceof Vr,(function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"}));var r=da.gradients((function(){return e(t)}),[t],n),a=r.grads,o=r.value;return Us(a),{grad:a[0],value:o}}},e.valueAndGrads=function(e){return g(C(e),(function(){return"The f passed in valueAndGrads(f) must be a function"})),function(t,n){g(Array.isArray(t)&&t.every((function(e){return e instanceof Vr})),(function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"})),g(null==n||n instanceof Vr,(function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"}));var r=da.gradients((function(){return e.apply(void 0,u([],s(t),!1))}),t,n);return null!=n&&v(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Us(r.grads),r}},e.variable=function(e,t,n,r){return void 0===t&&(t=!0),da.makeVariable(e,t,n,r)},e.variableGrads=Ls,e.version_core="4.22.0",e.where=Qi,e.whereAsync=nl,e.zeros=au,e.zerosLike=$i})); //# sourceMappingURL=tf-core.min.js.map