From 123f7f02616d97e3991ca34fe40a2558e2b2e4bb Mon Sep 17 00:00:00 2001 From: Igor Trentini Date: Tue, 20 Feb 2024 18:35:37 -0300 Subject: [PATCH] Updates --- .../{index-TuQ91GCH.js => index-B3O1ace8.js} | 394 +++++++++--------- index.html | 2 +- 2 files changed, 198 insertions(+), 198 deletions(-) rename assets/{index-TuQ91GCH.js => index-B3O1ace8.js} (67%) diff --git a/assets/index-TuQ91GCH.js b/assets/index-B3O1ace8.js similarity index 67% rename from assets/index-TuQ91GCH.js rename to assets/index-B3O1ace8.js index d178fd4..e5e8afe 100644 --- a/assets/index-TuQ91GCH.js +++ b/assets/index-B3O1ace8.js @@ -1,4 +1,4 @@ -var m1=Object.defineProperty;var g1=(e,t,n)=>t in e?m1(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var y1=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qr=(e,t,n)=>(g1(e,typeof t!="symbol"?t+"":t,n),n);var _I=y1((SI,d1)=>{(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const i of o)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(o){const i={};return o.integrity&&(i.integrity=o.integrity),o.referrerPolicy&&(i.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?i.credentials="include":o.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(o){if(o.ep)return;o.ep=!0;const i=n(o);fetch(o.href,i)}})();var x1=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Av(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Pv={exports:{}},Cs={},Fv={exports:{}},pe={};/** +var d1=Object.defineProperty;var h1=(e,t,n)=>t in e?d1(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var p1=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Gr=(e,t,n)=>(h1(e,typeof t!="symbol"?t+"":t,n),n);var gI=p1((xI,s1)=>{(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const i of o)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(o){const i={};return o.integrity&&(i.integrity=o.integrity),o.referrerPolicy&&(i.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?i.credentials="include":o.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(o){if(o.ep)return;o.ep=!0;const i=n(o);fetch(o.href,i)}})();var v1=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Iv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Dv={exports:{}},ws={},Tv={exports:{}},pe={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ var m1=Object.defineProperty;var g1=(e,t,n)=>t in e?m1(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Ea=Symbol.for("react.element"),w1=Symbol.for("react.portal"),b1=Symbol.for("react.fragment"),C1=Symbol.for("react.strict_mode"),_1=Symbol.for("react.profiler"),E1=Symbol.for("react.provider"),S1=Symbol.for("react.context"),k1=Symbol.for("react.forward_ref"),R1=Symbol.for("react.suspense"),I1=Symbol.for("react.memo"),D1=Symbol.for("react.lazy"),_h=Symbol.iterator;function T1(e){return e===null||typeof e!="object"?null:(e=_h&&e[_h]||e["@@iterator"],typeof e=="function"?e:null)}var Mv={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Ov=Object.assign,Bv={};function xi(e,t,n){this.props=e,this.context=t,this.refs=Bv,this.updater=n||Mv}xi.prototype.isReactComponent={};xi.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};xi.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Lv(){}Lv.prototype=xi.prototype;function _f(e,t,n){this.props=e,this.context=t,this.refs=Bv,this.updater=n||Mv}var Ef=_f.prototype=new Lv;Ef.constructor=_f;Ov(Ef,xi.prototype);Ef.isPureReactComponent=!0;var Eh=Array.isArray,Wv=Object.prototype.hasOwnProperty,Sf={current:null},zv={key:!0,ref:!0,__self:!0,__source:!0};function Uv(e,t,n){var r,o={},i=null,a=null;if(t!=null)for(r in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(i=""+t.key),t)Wv.call(t,r)&&!zv.hasOwnProperty(r)&&(o[r]=t[r]);var u=arguments.length-2;if(u===1)o.children=n;else if(1t in e?m1(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var O1=Jn,B1=Symbol.for("react.element"),L1=Symbol.for("react.fragment"),W1=Object.prototype.hasOwnProperty,z1=O1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,U1={key:!0,ref:!0,__self:!0,__source:!0};function Vv(e,t,n){var r,o={},i=null,a=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(a=t.ref);for(r in t)W1.call(t,r)&&!U1.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:B1,type:e,key:i,ref:a,props:o,_owner:z1.current}}Cs.Fragment=L1;Cs.jsx=Vv;Cs.jsxs=Vv;Pv.exports=Cs;var cn=Pv.exports,ac={},$v={exports:{}},Xt={},Hv={exports:{}},jv={};/** + */var A1=Yn,P1=Symbol.for("react.element"),F1=Symbol.for("react.fragment"),M1=Object.prototype.hasOwnProperty,O1=A1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,B1={key:!0,ref:!0,__self:!0,__source:!0};function Lv(e,t,n){var r,o={},i=null,a=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(a=t.ref);for(r in t)M1.call(t,r)&&!B1.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:P1,type:e,key:i,ref:a,props:o,_owner:O1.current}}ws.Fragment=F1;ws.jsx=Lv;ws.jsxs=Lv;Dv.exports=ws;var ln=Dv.exports,oc={},Wv={exports:{}},Xt={},zv={exports:{}},Uv={};/** * @license React * scheduler.production.min.js * @@ -22,7 +22,7 @@ var m1=Object.defineProperty;var g1=(e,t,n)=>t in e?m1(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */(function(e){function t(P,M){var B=P.length;P.push(M);e:for(;0>>1,q=P[G];if(0>>1;Go(le,B))aeo(fe,le)?(P[G]=fe,P[ae]=B,G=ae):(P[G]=le,P[oe]=B,G=oe);else if(aeo(fe,B))P[G]=fe,P[ae]=B,G=ae;else break e}}return M}function o(P,M){var B=P.sortIndex-M.sortIndex;return B!==0?B:P.id-M.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,u=a.now();e.unstable_now=function(){return a.now()-u}}var s=[],l=[],c=1,f=null,d=3,h=!1,p=!1,m=!1,g=typeof setTimeout=="function"?setTimeout:null,v=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function x(P){for(var M=n(l);M!==null;){if(M.callback===null)r(l);else if(M.startTime<=P)r(l),M.sortIndex=M.expirationTime,t(s,M);else break;M=n(l)}}function w(P){if(m=!1,x(P),!p)if(n(s)!==null)p=!0,$(b);else{var M=n(l);M!==null&&V(w,M.startTime-P)}}function b(P,M){p=!1,m&&(m=!1,v(E),E=-1),h=!0;var B=d;try{for(x(M),f=n(s);f!==null&&(!(f.expirationTime>M)||P&&!T());){var G=f.callback;if(typeof G=="function"){f.callback=null,d=f.priorityLevel;var q=G(f.expirationTime<=M);M=e.unstable_now(),typeof q=="function"?f.callback=q:f===n(s)&&r(s),x(M)}else r(s);f=n(s)}if(f!==null)var re=!0;else{var oe=n(l);oe!==null&&V(w,oe.startTime-M),re=!1}return re}finally{f=null,d=B,h=!1}}var C=!1,_=null,E=-1,R=5,k=-1;function T(){return!(e.unstable_now()-kP||125G?(P.sortIndex=B,t(l,P),n(s)===null&&P===n(l)&&(m?(v(E),E=-1):m=!0,V(w,B-G))):(P.sortIndex=q,t(s,P),p||h||(p=!0,$(b))),P},e.unstable_shouldYield=T,e.unstable_wrapCallback=function(P){var M=d;return function(){var B=d;d=M;try{return P.apply(this,arguments)}finally{d=B}}}})(jv);Hv.exports=jv;var V1=Hv.exports;/** + */(function(e){function t(P,M){var B=P.length;P.push(M);e:for(;0>>1,q=P[G];if(0>>1;Go(le,B))aeo(fe,le)?(P[G]=fe,P[ae]=B,G=ae):(P[G]=le,P[oe]=B,G=oe);else if(aeo(fe,B))P[G]=fe,P[ae]=B,G=ae;else break e}}return M}function o(P,M){var B=P.sortIndex-M.sortIndex;return B!==0?B:P.id-M.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,u=a.now();e.unstable_now=function(){return a.now()-u}}var s=[],l=[],c=1,f=null,d=3,h=!1,p=!1,m=!1,g=typeof setTimeout=="function"?setTimeout:null,v=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function x(P){for(var M=n(l);M!==null;){if(M.callback===null)r(l);else if(M.startTime<=P)r(l),M.sortIndex=M.expirationTime,t(s,M);else break;M=n(l)}}function w(P){if(m=!1,x(P),!p)if(n(s)!==null)p=!0,$(b);else{var M=n(l);M!==null&&V(w,M.startTime-P)}}function b(P,M){p=!1,m&&(m=!1,v(E),E=-1),h=!0;var B=d;try{for(x(M),f=n(s);f!==null&&(!(f.expirationTime>M)||P&&!T());){var G=f.callback;if(typeof G=="function"){f.callback=null,d=f.priorityLevel;var q=G(f.expirationTime<=M);M=e.unstable_now(),typeof q=="function"?f.callback=q:f===n(s)&&r(s),x(M)}else r(s);f=n(s)}if(f!==null)var re=!0;else{var oe=n(l);oe!==null&&V(w,oe.startTime-M),re=!1}return re}finally{f=null,d=B,h=!1}}var C=!1,_=null,E=-1,R=5,k=-1;function T(){return!(e.unstable_now()-kP||125G?(P.sortIndex=B,t(l,P),n(s)===null&&P===n(l)&&(m?(v(E),E=-1):m=!0,V(w,B-G))):(P.sortIndex=q,t(s,P),p||h||(p=!0,$(b))),P},e.unstable_shouldYield=T,e.unstable_wrapCallback=function(P){var M=d;return function(){var B=d;d=M;try{return P.apply(this,arguments)}finally{d=B}}}})(Uv);zv.exports=Uv;var L1=zv.exports;/** * @license React * react-dom.production.min.js * @@ -30,14 +30,14 @@ var m1=Object.defineProperty;var g1=(e,t,n)=>t in e?m1(e,t,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Gv=Jn,qt=V1;function j(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),uc=Object.prototype.hasOwnProperty,$1=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,kh={},Rh={};function H1(e){return uc.call(Rh,e)?!0:uc.call(kh,e)?!1:$1.test(e)?Rh[e]=!0:(kh[e]=!0,!1)}function j1(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function G1(e,t,n,r){if(t===null||typeof t>"u"||j1(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function kt(e,t,n,r,o,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var ft={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ft[e]=new kt(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ft[t]=new kt(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ft[e]=new kt(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ft[e]=new kt(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){ft[e]=new kt(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ft[e]=new kt(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ft[e]=new kt(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ft[e]=new kt(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ft[e]=new kt(e,5,!1,e.toLowerCase(),null,!1,!1)});var Rf=/[\-:]([a-z])/g;function If(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(Rf,If);ft[t]=new kt(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Rf,If);ft[t]=new kt(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Rf,If);ft[t]=new kt(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ft[e]=new kt(e,1,!1,e.toLowerCase(),null,!1,!1)});ft.xlinkHref=new kt("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ft[e]=new kt(e,1,!1,e.toLowerCase(),null,!0,!0)});function Df(e,t,n,r){var o=ft.hasOwnProperty(t)?ft[t]:null;(o!==null?o.type!==0:r||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ic=Object.prototype.hasOwnProperty,W1=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,bh={},Ch={};function z1(e){return ic.call(Ch,e)?!0:ic.call(bh,e)?!1:W1.test(e)?Ch[e]=!0:(bh[e]=!0,!1)}function U1(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function V1(e,t,n,r){if(t===null||typeof t>"u"||U1(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function St(e,t,n,r,o,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var ft={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ft[e]=new St(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ft[t]=new St(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ft[e]=new St(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ft[e]=new St(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){ft[e]=new St(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ft[e]=new St(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ft[e]=new St(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ft[e]=new St(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ft[e]=new St(e,5,!1,e.toLowerCase(),null,!1,!1)});var Sf=/[\-:]([a-z])/g;function kf(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(Sf,kf);ft[t]=new St(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(Sf,kf);ft[t]=new St(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(Sf,kf);ft[t]=new St(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ft[e]=new St(e,1,!1,e.toLowerCase(),null,!1,!1)});ft.xlinkHref=new St("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ft[e]=new St(e,1,!1,e.toLowerCase(),null,!0,!0)});function Rf(e,t,n,r){var o=ft.hasOwnProperty(t)?ft[t]:null;(o!==null?o.type!==0:r||!(2u||o[a]!==i[u]){var s=` -`+o[a].replace(" at new "," at ");return e.displayName&&s.includes("")&&(s=s.replace("",e.displayName)),s}while(1<=a&&0<=u);break}}}finally{sl=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Oi(e):""}function q1(e){switch(e.tag){case 5:return Oi(e.type);case 16:return Oi("Lazy");case 13:return Oi("Suspense");case 19:return Oi("SuspenseList");case 0:case 2:case 15:return e=ll(e.type,!1),e;case 11:return e=ll(e.type.render,!1),e;case 1:return e=ll(e.type,!0),e;default:return""}}function fc(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Bo:return"Fragment";case Oo:return"Portal";case sc:return"Profiler";case Tf:return"StrictMode";case lc:return"Suspense";case cc:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Xv:return(e.displayName||"Context")+".Consumer";case Kv:return(e._context.displayName||"Context")+".Provider";case Nf:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Af:return t=e.displayName||null,t!==null?t:fc(e.type)||"Memo";case yr:t=e._payload,e=e._init;try{return fc(e(t))}catch{}}return null}function K1(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return fc(t);case 8:return t===Tf?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Lr(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Qv(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function X1(e){var t=Qv(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return o.call(this)},set:function(a){r=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Ua(e){e._valueTracker||(e._valueTracker=X1(e))}function Jv(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Qv(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Tu(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function dc(e,t){var n=t.checked;return Be({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Dh(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Lr(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Zv(e,t){t=t.checked,t!=null&&Df(e,"checked",t,!1)}function hc(e,t){Zv(e,t);var n=Lr(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?pc(e,t.type,n):t.hasOwnProperty("defaultValue")&&pc(e,t.type,Lr(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Th(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function pc(e,t,n){(t!=="number"||Tu(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Bi=Array.isArray;function Ko(e,t,n,r){if(e=e.options,t){t={};for(var o=0;o"+t.valueOf().toString()+"",t=Va.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Zi(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var zi={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Y1=["Webkit","ms","Moz","O"];Object.keys(zi).forEach(function(e){Y1.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),zi[t]=zi[e]})});function rm(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||zi.hasOwnProperty(e)&&zi[e]?(""+t).trim():t+"px"}function om(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=rm(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,o):e[n]=o}}var Q1=Be({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function gc(e,t){if(t){if(Q1[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(j(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(j(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(j(61))}if(t.style!=null&&typeof t.style!="object")throw Error(j(62))}}function yc(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var xc=null;function Pf(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var wc=null,Xo=null,Yo=null;function Ph(e){if(e=Ra(e)){if(typeof wc!="function")throw Error(j(280));var t=e.stateNode;t&&(t=Rs(t),wc(e.stateNode,e.type,t))}}function im(e){Xo?Yo?Yo.push(e):Yo=[e]:Xo=e}function am(){if(Xo){var e=Xo,t=Yo;if(Yo=Xo=null,Ph(e),t)for(e=0;e>>=0,e===0?32:31-(sx(e)/lx|0)|0}var $a=64,Ha=4194304;function Li(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Fu(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,o=e.suspendedLanes,i=e.pingedLanes,a=n&268435455;if(a!==0){var u=a&~o;u!==0?r=Li(u):(i&=a,i!==0&&(r=Li(i)))}else a=n&~o,a!==0?r=Li(a):i!==0&&(r=Li(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&o)&&(o=r&-r,i=t&-t,o>=i||o===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function Sa(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-mn(t),e[t]=n}function hx(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Vi),Vh=" ",$h=!1;function km(e,t){switch(e){case"keyup":return Ux.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Rm(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Lo=!1;function $x(e,t){switch(e){case"compositionend":return Rm(t);case"keypress":return t.which!==32?null:($h=!0,Vh);case"textInput":return e=t.data,e===Vh&&$h?null:e;default:return null}}function Hx(e,t){if(Lo)return e==="compositionend"||!Uf&&km(e,t)?(e=Em(),wu=Lf=Cr=null,Lo=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=qh(n)}}function Nm(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Nm(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Am(){for(var e=window,t=Tu();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Tu(e.document)}return t}function Vf(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Zx(e){var t=Am(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Nm(n.ownerDocument.documentElement,n)){if(r!==null&&Vf(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var o=n.textContent.length,i=Math.min(r.start,o);r=r.end===void 0?i:Math.min(r.end,o),!e.extend&&i>r&&(o=r,r=i,i=o),o=Kh(n,i);var a=Kh(n,r);o&&a&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(o.node,o.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Wo=null,kc=null,Hi=null,Rc=!1;function Xh(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Rc||Wo==null||Wo!==Tu(r)||(r=Wo,"selectionStart"in r&&Vf(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Hi&&ia(Hi,r)||(Hi=r,r=Bu(kc,"onSelect"),0Vo||(e.current=Pc[Vo],Pc[Vo]=null,Vo--)}function Se(e,t){Vo++,Pc[Vo]=e.current,e.current=t}var Wr={},bt=Vr(Wr),Nt=Vr(!1),co=Wr;function si(e,t){var n=e.type.contextTypes;if(!n)return Wr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var o={},i;for(i in n)o[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=o),o}function At(e){return e=e.childContextTypes,e!=null}function Wu(){De(Nt),De(bt)}function np(e,t,n){if(bt.current!==Wr)throw Error(j(168));Se(bt,t),Se(Nt,n)}function Um(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in t))throw Error(j(108,K1(e)||"Unknown",o));return Be({},n,r)}function zu(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Wr,co=bt.current,Se(bt,e),Se(Nt,Nt.current),!0}function rp(e,t,n){var r=e.stateNode;if(!r)throw Error(j(169));n?(e=Um(e,t,co),r.__reactInternalMemoizedMergedChildContext=e,De(Nt),De(bt),Se(bt,e)):De(Nt),Se(Nt,n)}var Qn=null,Is=!1,_l=!1;function Vm(e){Qn===null?Qn=[e]:Qn.push(e)}function fw(e){Is=!0,Vm(e)}function $r(){if(!_l&&Qn!==null){_l=!0;var e=0,t=_e;try{var n=Qn;for(_e=1;e>=a,o-=a,er=1<<32-mn(t)+o|n<E?(R=_,_=null):R=_.sibling;var k=d(v,_,x[E],w);if(k===null){_===null&&(_=R);break}e&&_&&k.alternate===null&&t(v,_),y=i(k,y,E),C===null?b=k:C.sibling=k,C=k,_=R}if(E===x.length)return n(v,_),Te&&Yr(v,E),b;if(_===null){for(;EE?(R=_,_=null):R=_.sibling;var T=d(v,_,k.value,w);if(T===null){_===null&&(_=R);break}e&&_&&T.alternate===null&&t(v,_),y=i(T,y,E),C===null?b=T:C.sibling=T,C=T,_=R}if(k.done)return n(v,_),Te&&Yr(v,E),b;if(_===null){for(;!k.done;E++,k=x.next())k=f(v,k.value,w),k!==null&&(y=i(k,y,E),C===null?b=k:C.sibling=k,C=k);return Te&&Yr(v,E),b}for(_=r(v,_);!k.done;E++,k=x.next())k=h(_,v,E,k.value,w),k!==null&&(e&&k.alternate!==null&&_.delete(k.key===null?E:k.key),y=i(k,y,E),C===null?b=k:C.sibling=k,C=k);return e&&_.forEach(function(N){return t(v,N)}),Te&&Yr(v,E),b}function g(v,y,x,w){if(typeof x=="object"&&x!==null&&x.type===Bo&&x.key===null&&(x=x.props.children),typeof x=="object"&&x!==null){switch(x.$$typeof){case za:e:{for(var b=x.key,C=y;C!==null;){if(C.key===b){if(b=x.type,b===Bo){if(C.tag===7){n(v,C.sibling),y=o(C,x.props.children),y.return=v,v=y;break e}}else if(C.elementType===b||typeof b=="object"&&b!==null&&b.$$typeof===yr&&cp(b)===C.type){n(v,C.sibling),y=o(C,x.props),y.ref=Di(v,C,x),y.return=v,v=y;break e}n(v,C);break}else t(v,C);C=C.sibling}x.type===Bo?(y=uo(x.props.children,v.mode,w,x.key),y.return=v,v=y):(w=Iu(x.type,x.key,x.props,null,v.mode,w),w.ref=Di(v,y,x),w.return=v,v=w)}return a(v);case Oo:e:{for(C=x.key;y!==null;){if(y.key===C)if(y.tag===4&&y.stateNode.containerInfo===x.containerInfo&&y.stateNode.implementation===x.implementation){n(v,y.sibling),y=o(y,x.children||[]),y.return=v,v=y;break e}else{n(v,y);break}else t(v,y);y=y.sibling}y=Nl(x,v.mode,w),y.return=v,v=y}return a(v);case yr:return C=x._init,g(v,y,C(x._payload),w)}if(Bi(x))return p(v,y,x,w);if(Ei(x))return m(v,y,x,w);Qa(v,x)}return typeof x=="string"&&x!==""||typeof x=="number"?(x=""+x,y!==null&&y.tag===6?(n(v,y.sibling),y=o(y,x),y.return=v,v=y):(n(v,y),y=Tl(x,v.mode,w),y.return=v,v=y),a(v)):n(v,y)}return g}var ci=Ym(!0),Qm=Ym(!1),Ia={},Mn=Vr(Ia),la=Vr(Ia),ca=Vr(Ia);function ro(e){if(e===Ia)throw Error(j(174));return e}function Qf(e,t){switch(Se(ca,t),Se(la,e),Se(Mn,Ia),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:mc(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=mc(t,e)}De(Mn),Se(Mn,t)}function fi(){De(Mn),De(la),De(ca)}function Jm(e){ro(ca.current);var t=ro(Mn.current),n=mc(t,e.type);t!==n&&(Se(la,e),Se(Mn,n))}function Jf(e){la.current===e&&(De(Mn),De(la))}var Pe=Vr(0);function Gu(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var El=[];function Zf(){for(var e=0;en?n:4,e(!0);var r=Sl.transition;Sl.transition={};try{e(!1),t()}finally{_e=n,Sl.transition=r}}function pg(){return an().memoizedState}function vw(e,t,n){var r=Pr(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},vg(e))mg(t,n);else if(n=Gm(e,t,n,r),n!==null){var o=Et();gn(n,e,r,o),gg(n,t,r)}}function mw(e,t,n){var r=Pr(e),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(vg(e))mg(t,o);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,u=i(a,n);if(o.hasEagerState=!0,o.eagerState=u,xn(u,a)){var s=t.interleaved;s===null?(o.next=o,Xf(t)):(o.next=s.next,s.next=o),t.interleaved=o;return}}catch{}finally{}n=Gm(e,t,o,r),n!==null&&(o=Et(),gn(n,e,r,o),gg(n,t,r))}}function vg(e){var t=e.alternate;return e===Oe||t!==null&&t===Oe}function mg(e,t){ji=qu=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function gg(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Mf(e,n)}}var Ku={readContext:on,useCallback:dt,useContext:dt,useEffect:dt,useImperativeHandle:dt,useInsertionEffect:dt,useLayoutEffect:dt,useMemo:dt,useReducer:dt,useRef:dt,useState:dt,useDebugValue:dt,useDeferredValue:dt,useTransition:dt,useMutableSource:dt,useSyncExternalStore:dt,useId:dt,unstable_isNewReconciler:!1},gw={readContext:on,useCallback:function(e,t){return Rn().memoizedState=[e,t===void 0?null:t],e},useContext:on,useEffect:dp,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Eu(4194308,4,lg.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Eu(4194308,4,e,t)},useInsertionEffect:function(e,t){return Eu(4,2,e,t)},useMemo:function(e,t){var n=Rn();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Rn();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=vw.bind(null,Oe,e),[r.memoizedState,e]},useRef:function(e){var t=Rn();return e={current:e},t.memoizedState=e},useState:fp,useDebugValue:od,useDeferredValue:function(e){return Rn().memoizedState=e},useTransition:function(){var e=fp(!1),t=e[0];return e=pw.bind(null,e[1]),Rn().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Oe,o=Rn();if(Te){if(n===void 0)throw Error(j(407));n=n()}else{if(n=t(),rt===null)throw Error(j(349));ho&30||tg(r,t,n)}o.memoizedState=n;var i={value:n,getSnapshot:t};return o.queue=i,dp(rg.bind(null,r,i,e),[e]),r.flags|=2048,ha(9,ng.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Rn(),t=rt.identifierPrefix;if(Te){var n=tr,r=er;n=(r&~(1<<32-mn(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=fa++,0")&&(s=s.replace("",e.displayName)),s}while(1<=a&&0<=u);break}}}finally{al=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Fi(e):""}function $1(e){switch(e.tag){case 5:return Fi(e.type);case 16:return Fi("Lazy");case 13:return Fi("Suspense");case 19:return Fi("SuspenseList");case 0:case 2:case 15:return e=ul(e.type,!1),e;case 11:return e=ul(e.type.render,!1),e;case 1:return e=ul(e.type,!0),e;default:return""}}function lc(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Mo:return"Fragment";case Fo:return"Portal";case ac:return"Profiler";case If:return"StrictMode";case uc:return"Suspense";case sc:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case jv:return(e.displayName||"Context")+".Consumer";case Hv:return(e._context.displayName||"Context")+".Provider";case Df:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Tf:return t=e.displayName||null,t!==null?t:lc(e.type)||"Memo";case gr:t=e._payload,e=e._init;try{return lc(e(t))}catch{}}return null}function H1(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return lc(t);case 8:return t===If?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Br(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function qv(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function j1(e){var t=qv(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return o.call(this)},set:function(a){r=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Wa(e){e._valueTracker||(e._valueTracker=j1(e))}function Kv(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=qv(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Ru(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function cc(e,t){var n=t.checked;return Be({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Eh(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Br(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Xv(e,t){t=t.checked,t!=null&&Rf(e,"checked",t,!1)}function fc(e,t){Xv(e,t);var n=Br(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?dc(e,t.type,n):t.hasOwnProperty("defaultValue")&&dc(e,t.type,Br(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Sh(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function dc(e,t,n){(t!=="number"||Ru(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Mi=Array.isArray;function Go(e,t,n,r){if(e=e.options,t){t={};for(var o=0;o"+t.valueOf().toString()+"",t=za.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Qi(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Li={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},G1=["Webkit","ms","Moz","O"];Object.keys(Li).forEach(function(e){G1.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Li[t]=Li[e]})});function Zv(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Li.hasOwnProperty(e)&&Li[e]?(""+t).trim():t+"px"}function em(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=Zv(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,o):e[n]=o}}var q1=Be({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function vc(e,t){if(t){if(q1[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(j(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(j(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(j(61))}if(t.style!=null&&typeof t.style!="object")throw Error(j(62))}}function mc(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var gc=null;function Nf(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var yc=null,qo=null,Ko=null;function Ih(e){if(e=Sa(e)){if(typeof yc!="function")throw Error(j(280));var t=e.stateNode;t&&(t=Ss(t),yc(e.stateNode,e.type,t))}}function tm(e){qo?Ko?Ko.push(e):Ko=[e]:qo=e}function nm(){if(qo){var e=qo,t=Ko;if(Ko=qo=null,Ih(e),t)for(e=0;e>>=0,e===0?32:31-(ox(e)/ix|0)|0}var Ua=64,Va=4194304;function Oi(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Nu(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,o=e.suspendedLanes,i=e.pingedLanes,a=n&268435455;if(a!==0){var u=a&~o;u!==0?r=Oi(u):(i&=a,i!==0&&(r=Oi(i)))}else a=n&~o,a!==0?r=Oi(a):i!==0&&(r=Oi(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&o)&&(o=r&-r,i=t&-t,o>=i||o===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function _a(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-vn(t),e[t]=n}function lx(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=zi),Bh=" ",Lh=!1;function Cm(e,t){switch(e){case"keyup":return Bx.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function _m(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Oo=!1;function Wx(e,t){switch(e){case"compositionend":return _m(t);case"keypress":return t.which!==32?null:(Lh=!0,Bh);case"textInput":return e=t.data,e===Bh&&Lh?null:e;default:return null}}function zx(e,t){if(Oo)return e==="compositionend"||!Wf&&Cm(e,t)?(e=wm(),gu=Of=br=null,Oo=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Vh(n)}}function Rm(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Rm(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Im(){for(var e=window,t=Ru();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Ru(e.document)}return t}function zf(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Xx(e){var t=Im(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Rm(n.ownerDocument.documentElement,n)){if(r!==null&&zf(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var o=n.textContent.length,i=Math.min(r.start,o);r=r.end===void 0?i:Math.min(r.end,o),!e.extend&&i>r&&(o=r,r=i,i=o),o=$h(n,i);var a=$h(n,r);o&&a&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(o.node,o.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Bo=null,Ec=null,Vi=null,Sc=!1;function Hh(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Sc||Bo==null||Bo!==Ru(r)||(r=Bo,"selectionStart"in r&&zf(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Vi&&ra(Vi,r)||(Vi=r,r=Fu(Ec,"onSelect"),0zo||(e.current=Nc[zo],Nc[zo]=null,zo--)}function Se(e,t){zo++,Nc[zo]=e.current,e.current=t}var Lr={},wt=Ur(Lr),Nt=Ur(!1),so=Lr;function ai(e,t){var n=e.type.contextTypes;if(!n)return Lr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var o={},i;for(i in n)o[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=o),o}function At(e){return e=e.childContextTypes,e!=null}function Ou(){De(Nt),De(wt)}function Qh(e,t,n){if(wt.current!==Lr)throw Error(j(168));Se(wt,t),Se(Nt,n)}function Bm(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in t))throw Error(j(108,H1(e)||"Unknown",o));return Be({},n,r)}function Bu(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Lr,so=wt.current,Se(wt,e),Se(Nt,Nt.current),!0}function Jh(e,t,n){var r=e.stateNode;if(!r)throw Error(j(169));n?(e=Bm(e,t,so),r.__reactInternalMemoizedMergedChildContext=e,De(Nt),De(wt),Se(wt,e)):De(Nt),Se(Nt,n)}var Xn=null,ks=!1,bl=!1;function Lm(e){Xn===null?Xn=[e]:Xn.push(e)}function uw(e){ks=!0,Lm(e)}function Vr(){if(!bl&&Xn!==null){bl=!0;var e=0,t=_e;try{var n=Xn;for(_e=1;e>=a,o-=a,Jn=1<<32-vn(t)+o|n<E?(R=_,_=null):R=_.sibling;var k=d(v,_,x[E],w);if(k===null){_===null&&(_=R);break}e&&_&&k.alternate===null&&t(v,_),y=i(k,y,E),C===null?b=k:C.sibling=k,C=k,_=R}if(E===x.length)return n(v,_),Te&&Kr(v,E),b;if(_===null){for(;EE?(R=_,_=null):R=_.sibling;var T=d(v,_,k.value,w);if(T===null){_===null&&(_=R);break}e&&_&&T.alternate===null&&t(v,_),y=i(T,y,E),C===null?b=T:C.sibling=T,C=T,_=R}if(k.done)return n(v,_),Te&&Kr(v,E),b;if(_===null){for(;!k.done;E++,k=x.next())k=f(v,k.value,w),k!==null&&(y=i(k,y,E),C===null?b=k:C.sibling=k,C=k);return Te&&Kr(v,E),b}for(_=r(v,_);!k.done;E++,k=x.next())k=h(_,v,E,k.value,w),k!==null&&(e&&k.alternate!==null&&_.delete(k.key===null?E:k.key),y=i(k,y,E),C===null?b=k:C.sibling=k,C=k);return e&&_.forEach(function(N){return t(v,N)}),Te&&Kr(v,E),b}function g(v,y,x,w){if(typeof x=="object"&&x!==null&&x.type===Mo&&x.key===null&&(x=x.props.children),typeof x=="object"&&x!==null){switch(x.$$typeof){case La:e:{for(var b=x.key,C=y;C!==null;){if(C.key===b){if(b=x.type,b===Mo){if(C.tag===7){n(v,C.sibling),y=o(C,x.props.children),y.return=v,v=y;break e}}else if(C.elementType===b||typeof b=="object"&&b!==null&&b.$$typeof===gr&&ip(b)===C.type){n(v,C.sibling),y=o(C,x.props),y.ref=ki(v,C,x),y.return=v,v=y;break e}n(v,C);break}else t(v,C);C=C.sibling}x.type===Mo?(y=io(x.props.children,v.mode,w,x.key),y.return=v,v=y):(w=Su(x.type,x.key,x.props,null,v.mode,w),w.ref=ki(v,y,x),w.return=v,v=w)}return a(v);case Fo:e:{for(C=x.key;y!==null;){if(y.key===C)if(y.tag===4&&y.stateNode.containerInfo===x.containerInfo&&y.stateNode.implementation===x.implementation){n(v,y.sibling),y=o(y,x.children||[]),y.return=v,v=y;break e}else{n(v,y);break}else t(v,y);y=y.sibling}y=Dl(x,v.mode,w),y.return=v,v=y}return a(v);case gr:return C=x._init,g(v,y,C(x._payload),w)}if(Mi(x))return p(v,y,x,w);if(bi(x))return m(v,y,x,w);Xa(v,x)}return typeof x=="string"&&x!==""||typeof x=="number"?(x=""+x,y!==null&&y.tag===6?(n(v,y.sibling),y=o(y,x),y.return=v,v=y):(n(v,y),y=Il(x,v.mode,w),y.return=v,v=y),a(v)):n(v,y)}return g}var si=Gm(!0),qm=Gm(!1),ka={},Fn=Ur(ka),ua=Ur(ka),sa=Ur(ka);function to(e){if(e===ka)throw Error(j(174));return e}function Xf(e,t){switch(Se(sa,t),Se(ua,e),Se(Fn,ka),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:pc(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=pc(t,e)}De(Fn),Se(Fn,t)}function li(){De(Fn),De(ua),De(sa)}function Km(e){to(sa.current);var t=to(Fn.current),n=pc(t,e.type);t!==n&&(Se(ua,e),Se(Fn,n))}function Yf(e){ua.current===e&&(De(Fn),De(ua))}var Pe=Ur(0);function $u(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var Cl=[];function Qf(){for(var e=0;en?n:4,e(!0);var r=_l.transition;_l.transition={};try{e(!1),t()}finally{_e=n,_l.transition=r}}function cg(){return an().memoizedState}function fw(e,t,n){var r=Ar(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},fg(e))dg(t,n);else if(n=Vm(e,t,n,r),n!==null){var o=_t();mn(n,e,r,o),hg(n,t,r)}}function dw(e,t,n){var r=Ar(e),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(fg(e))dg(t,o);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,u=i(a,n);if(o.hasEagerState=!0,o.eagerState=u,yn(u,a)){var s=t.interleaved;s===null?(o.next=o,qf(t)):(o.next=s.next,s.next=o),t.interleaved=o;return}}catch{}finally{}n=Vm(e,t,o,r),n!==null&&(o=_t(),mn(n,e,r,o),hg(n,t,r))}}function fg(e){var t=e.alternate;return e===Oe||t!==null&&t===Oe}function dg(e,t){$i=Hu=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function hg(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Pf(e,n)}}var ju={readContext:on,useCallback:dt,useContext:dt,useEffect:dt,useImperativeHandle:dt,useInsertionEffect:dt,useLayoutEffect:dt,useMemo:dt,useReducer:dt,useRef:dt,useState:dt,useDebugValue:dt,useDeferredValue:dt,useTransition:dt,useMutableSource:dt,useSyncExternalStore:dt,useId:dt,unstable_isNewReconciler:!1},hw={readContext:on,useCallback:function(e,t){return kn().memoizedState=[e,t===void 0?null:t],e},useContext:on,useEffect:up,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,bu(4194308,4,ig.bind(null,t,e),n)},useLayoutEffect:function(e,t){return bu(4194308,4,e,t)},useInsertionEffect:function(e,t){return bu(4,2,e,t)},useMemo:function(e,t){var n=kn();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=kn();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=fw.bind(null,Oe,e),[r.memoizedState,e]},useRef:function(e){var t=kn();return e={current:e},t.memoizedState=e},useState:ap,useDebugValue:nd,useDeferredValue:function(e){return kn().memoizedState=e},useTransition:function(){var e=ap(!1),t=e[0];return e=cw.bind(null,e[1]),kn().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Oe,o=kn();if(Te){if(n===void 0)throw Error(j(407));n=n()}else{if(n=t(),rt===null)throw Error(j(349));co&30||Qm(r,t,n)}o.memoizedState=n;var i={value:n,getSnapshot:t};return o.queue=i,up(Zm.bind(null,r,i,e),[e]),r.flags|=2048,fa(9,Jm.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=kn(),t=rt.identifierPrefix;if(Te){var n=Zn,r=Jn;n=(r&~(1<<32-vn(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=la++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[Tn]=t,e[sa]=r,kg(e,t,!1,!1),t.stateNode=e;e:{switch(a=yc(n,r),n){case"dialog":Re("cancel",e),Re("close",e),o=r;break;case"iframe":case"object":case"embed":Re("load",e),o=r;break;case"video":case"audio":for(o=0;ohi&&(t.flags|=128,r=!0,Ti(i,!1),t.lanes=4194304)}else{if(!r)if(e=Gu(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Ti(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!Te)return ht(t),null}else 2*He()-i.renderingStartTime>hi&&n!==1073741824&&(t.flags|=128,r=!0,Ti(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(n=i.last,n!==null?n.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=He(),t.sibling=null,n=Pe.current,Se(Pe,r?n&1|2:n&1),t):(ht(t),null);case 22:case 23:return cd(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Lt&1073741824&&(ht(t),t.subtreeFlags&6&&(t.flags|=8192)):ht(t),null;case 24:return null;case 25:return null}throw Error(j(156,t.tag))}function Sw(e,t){switch(Hf(t),t.tag){case 1:return At(t.type)&&Wu(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return fi(),De(Nt),De(bt),Zf(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Jf(t),null;case 13:if(De(Pe),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(j(340));li()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return De(Pe),null;case 4:return fi(),null;case 10:return Kf(t.type._context),null;case 22:case 23:return cd(),null;case 24:return null;default:return null}}var Za=!1,vt=!1,kw=typeof WeakSet=="function"?WeakSet:Set,Y=null;function Go(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Ue(e,t,r)}else n.current=null}function jc(e,t,n){try{n()}catch(r){Ue(e,t,r)}}var bp=!1;function Rw(e,t){if(Ic=Mu,e=Am(),Vf(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var a=0,u=-1,s=-1,l=0,c=0,f=e,d=null;t:for(;;){for(var h;f!==n||o!==0&&f.nodeType!==3||(u=a+o),f!==i||r!==0&&f.nodeType!==3||(s=a+r),f.nodeType===3&&(a+=f.nodeValue.length),(h=f.firstChild)!==null;)d=f,f=h;for(;;){if(f===e)break t;if(d===n&&++l===o&&(u=a),d===i&&++c===r&&(s=a),(h=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=h}n=u===-1||s===-1?null:{start:u,end:s}}else n=null}n=n||{start:0,end:0}}else n=null;for(Dc={focusedElem:e,selectionRange:n},Mu=!1,Y=t;Y!==null;)if(t=Y,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Y=e;else for(;Y!==null;){t=Y;try{var p=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(p!==null){var m=p.memoizedProps,g=p.memoizedState,v=t.stateNode,y=v.getSnapshotBeforeUpdate(t.elementType===t.type?m:fn(t.type,m),g);v.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var x=t.stateNode.containerInfo;x.nodeType===1?x.textContent="":x.nodeType===9&&x.documentElement&&x.removeChild(x.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(j(163))}}catch(w){Ue(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,Y=e;break}Y=t.return}return p=bp,bp=!1,p}function Gi(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&e)===e){var i=o.destroy;o.destroy=void 0,i!==void 0&&jc(t,n,i)}o=o.next}while(o!==r)}}function Ns(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Gc(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Dg(e){var t=e.alternate;t!==null&&(e.alternate=null,Dg(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Tn],delete t[sa],delete t[Ac],delete t[lw],delete t[cw])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Tg(e){return e.tag===5||e.tag===3||e.tag===4}function Cp(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Tg(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function qc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Lu));else if(r!==4&&(e=e.child,e!==null))for(qc(e,t,n),e=e.sibling;e!==null;)qc(e,t,n),e=e.sibling}function Kc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Kc(e,t,n),e=e.sibling;e!==null;)Kc(e,t,n),e=e.sibling}var at=null,dn=!1;function vr(e,t,n){for(n=n.child;n!==null;)Ng(e,t,n),n=n.sibling}function Ng(e,t,n){if(Fn&&typeof Fn.onCommitFiberUnmount=="function")try{Fn.onCommitFiberUnmount(_s,n)}catch{}switch(n.tag){case 5:vt||Go(n,t);case 6:var r=at,o=dn;at=null,vr(e,t,n),at=r,dn=o,at!==null&&(dn?(e=at,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):at.removeChild(n.stateNode));break;case 18:at!==null&&(dn?(e=at,n=n.stateNode,e.nodeType===8?Cl(e.parentNode,n):e.nodeType===1&&Cl(e,n),ra(e)):Cl(at,n.stateNode));break;case 4:r=at,o=dn,at=n.stateNode.containerInfo,dn=!0,vr(e,t,n),at=r,dn=o;break;case 0:case 11:case 14:case 15:if(!vt&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var i=o,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&jc(n,t,a),o=o.next}while(o!==r)}vr(e,t,n);break;case 1:if(!vt&&(Go(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(u){Ue(n,t,u)}vr(e,t,n);break;case 21:vr(e,t,n);break;case 22:n.mode&1?(vt=(r=vt)||n.memoizedState!==null,vr(e,t,n),vt=r):vr(e,t,n);break;default:vr(e,t,n)}}function _p(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new kw),t.forEach(function(r){var o=Ow.bind(null,e,r);n.has(r)||(n.add(r),r.then(o,o))})}}function sn(e,t){var n=t.deletions;if(n!==null)for(var r=0;ro&&(o=a),r&=~i}if(r=o,r=He()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Dw(r/1960))-r,10e?16:e,_r===null)var r=!1;else{if(e=_r,_r=null,Qu=0,xe&6)throw Error(j(331));var o=xe;for(xe|=4,Y=e.current;Y!==null;){var i=Y,a=i.child;if(Y.flags&16){var u=i.deletions;if(u!==null){for(var s=0;sHe()-sd?ao(e,0):ud|=n),Pt(e,t)}function Wg(e,t){t===0&&(e.mode&1?(t=Ha,Ha<<=1,!(Ha&130023424)&&(Ha=4194304)):t=1);var n=Et();e=ir(e,t),e!==null&&(Sa(e,t,n),Pt(e,n))}function Mw(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Wg(e,n)}function Ow(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(j(314))}r!==null&&r.delete(t),Wg(e,n)}var zg;zg=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Nt.current)Tt=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Tt=!1,_w(e,t,n);Tt=!!(e.flags&131072)}else Tt=!1,Te&&t.flags&1048576&&$m(t,Vu,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Su(e,t),e=t.pendingProps;var o=si(t,bt.current);Jo(t,n),o=td(null,t,r,e,o,n);var i=nd();return t.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,At(r)?(i=!0,zu(t)):i=!1,t.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,Yf(t),o.updater=Ds,t.stateNode=o,o._reactInternals=t,Lc(t,r,e,n),t=Uc(null,t,r,!0,i,n)):(t.tag=0,Te&&i&&$f(t),_t(null,t,o,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Su(e,t),e=t.pendingProps,o=r._init,r=o(r._payload),t.type=r,o=t.tag=Lw(r),e=fn(r,e),o){case 0:t=zc(null,t,r,e,n);break e;case 1:t=yp(null,t,r,e,n);break e;case 11:t=mp(null,t,r,e,n);break e;case 14:t=gp(null,t,r,fn(r.type,e),n);break e}throw Error(j(306,r,""))}return t;case 0:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:fn(r,o),zc(e,t,r,o,n);case 1:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:fn(r,o),yp(e,t,r,o,n);case 3:e:{if(_g(t),e===null)throw Error(j(387));r=t.pendingProps,i=t.memoizedState,o=i.element,qm(e,t),ju(t,r,null,n);var a=t.memoizedState;if(r=a.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){o=di(Error(j(423)),t),t=xp(e,t,r,n,o);break e}else if(r!==o){o=di(Error(j(424)),t),t=xp(e,t,r,n,o);break e}else for(Ut=Tr(t.stateNode.containerInfo.firstChild),jt=t,Te=!0,hn=null,n=Qm(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(li(),r===o){t=ar(e,t,n);break e}_t(e,t,r,n)}t=t.child}return t;case 5:return Jm(t),e===null&&Mc(t),r=t.type,o=t.pendingProps,i=e!==null?e.memoizedProps:null,a=o.children,Tc(r,o)?a=null:i!==null&&Tc(r,i)&&(t.flags|=32),Cg(e,t),_t(e,t,a,n),t.child;case 6:return e===null&&Mc(t),null;case 13:return Eg(e,t,n);case 4:return Qf(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ci(t,null,r,n):_t(e,t,r,n),t.child;case 11:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:fn(r,o),mp(e,t,r,o,n);case 7:return _t(e,t,t.pendingProps,n),t.child;case 8:return _t(e,t,t.pendingProps.children,n),t.child;case 12:return _t(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,o=t.pendingProps,i=t.memoizedProps,a=o.value,Se($u,r._currentValue),r._currentValue=a,i!==null)if(xn(i.value,a)){if(i.children===o.children&&!Nt.current){t=ar(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var u=i.dependencies;if(u!==null){a=i.child;for(var s=u.firstContext;s!==null;){if(s.context===r){if(i.tag===1){s=nr(-1,n&-n),s.tag=2;var l=i.updateQueue;if(l!==null){l=l.shared;var c=l.pending;c===null?s.next=s:(s.next=c.next,c.next=s),l.pending=s}}i.lanes|=n,s=i.alternate,s!==null&&(s.lanes|=n),Oc(i.return,n,t),u.lanes|=n;break}s=s.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error(j(341));a.lanes|=n,u=a.alternate,u!==null&&(u.lanes|=n),Oc(a,n,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}_t(e,t,o.children,n),t=t.child}return t;case 9:return o=t.type,r=t.pendingProps.children,Jo(t,n),o=on(o),r=r(o),t.flags|=1,_t(e,t,r,n),t.child;case 14:return r=t.type,o=fn(r,t.pendingProps),o=fn(r.type,o),gp(e,t,r,o,n);case 15:return wg(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:fn(r,o),Su(e,t),t.tag=1,At(r)?(e=!0,zu(t)):e=!1,Jo(t,n),Xm(t,r,o),Lc(t,r,o,n),Uc(null,t,r,!0,e,n);case 19:return Sg(e,t,n);case 22:return bg(e,t,n)}throw Error(j(156,t.tag))};function Ug(e,t){return hm(e,t)}function Bw(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function tn(e,t,n,r){return new Bw(e,t,n,r)}function dd(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Lw(e){if(typeof e=="function")return dd(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Nf)return 11;if(e===Af)return 14}return 2}function Fr(e,t){var n=e.alternate;return n===null?(n=tn(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Iu(e,t,n,r,o,i){var a=2;if(r=e,typeof e=="function")dd(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Bo:return uo(n.children,o,i,t);case Tf:a=8,o|=8;break;case sc:return e=tn(12,n,t,o|2),e.elementType=sc,e.lanes=i,e;case lc:return e=tn(13,n,t,o),e.elementType=lc,e.lanes=i,e;case cc:return e=tn(19,n,t,o),e.elementType=cc,e.lanes=i,e;case Yv:return Ps(n,o,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Kv:a=10;break e;case Xv:a=9;break e;case Nf:a=11;break e;case Af:a=14;break e;case yr:a=16,r=null;break e}throw Error(j(130,e==null?e:typeof e,""))}return t=tn(a,n,t,o),t.elementType=e,t.type=r,t.lanes=i,t}function uo(e,t,n,r){return e=tn(7,e,r,t),e.lanes=n,e}function Ps(e,t,n,r){return e=tn(22,e,r,t),e.elementType=Yv,e.lanes=n,e.stateNode={isHidden:!1},e}function Tl(e,t,n){return e=tn(6,e,null,t),e.lanes=n,e}function Nl(e,t,n){return t=tn(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Ww(e,t,n,r,o){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=fl(0),this.expirationTimes=fl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=fl(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function hd(e,t,n,r,o,i,a,u,s){return e=new Ww(e,t,n,u,s),t===1?(t=1,i===!0&&(t|=8)):t=0,i=tn(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Yf(i),e}function zw(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(jg)}catch(e){console.error(e)}}jg(),$v.exports=Xt;var jw=$v.exports,Np=jw;ac.createRoot=Np.createRoot,ac.hydrateRoot=Np.hydrateRoot;var Gg={exports:{}};(function(e,t){(function(r,o){e.exports=o(Jn)})(x1,function(n){return function(r){var o={};function i(a){if(o[a])return o[a].exports;var u=o[a]={i:a,l:!1,exports:{}};return r[a].call(u.exports,u,u.exports,i),u.l=!0,u.exports}return i.m=r,i.c=o,i.d=function(a,u,s){i.o(a,u)||Object.defineProperty(a,u,{enumerable:!0,get:s})},i.r=function(a){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},i.t=function(a,u){if(u&1&&(a=i(a)),u&8||u&4&&typeof a=="object"&&a&&a.__esModule)return a;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:a}),u&2&&typeof a!="string")for(var l in a)i.d(s,l,(function(c){return a[c]}).bind(null,l));return s},i.n=function(a){var u=a&&a.__esModule?function(){return a.default}:function(){return a};return i.d(u,"a",u),u},i.o=function(a,u){return Object.prototype.hasOwnProperty.call(a,u)},i.p="",i(i.s="./src/react-webcam.tsx")}({"./src/react-webcam.tsx":function(r,o,i){i.r(o);var a=i("react"),u=function(){var d=function(h,p){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(m,g){m.__proto__=g}||function(m,g){for(var v in g)g.hasOwnProperty(v)&&(m[v]=g[v])},d(h,p)};return function(h,p){d(h,p);function m(){this.constructor=h}h.prototype=p===null?Object.create(p):(m.prototype=p.prototype,new m)}}(),s=function(){return s=Object.assign||function(d){for(var h,p=1,m=arguments.length;p"u"||(navigator.mediaDevices===void 0&&(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia===void 0&&(navigator.mediaDevices.getUserMedia=function(h){var p=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;return p?new Promise(function(m,g){p.call(navigator,h,m,g)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}))})();function c(){return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}var f=function(d){u(h,d);function h(p){var m=d.call(this,p)||this;return m.canvas=null,m.ctx=null,m.requestUserMediaId=0,m.unmounted=!1,m.state={hasUserMedia:!1},m}return h.prototype.componentDidMount=function(){var p=this,m=p.state,g=p.props;if(this.unmounted=!1,!c()){g.onUserMediaError("getUserMedia not supported");return}m.hasUserMedia||this.requestUserMedia(),g.children&&typeof g.children!="function"&&console.warn("children must be a function")},h.prototype.componentDidUpdate=function(p){var m=this.props;if(!c()){m.onUserMediaError("getUserMedia not supported");return}var g=JSON.stringify(p.audioConstraints)!==JSON.stringify(m.audioConstraints),v=JSON.stringify(p.videoConstraints)!==JSON.stringify(m.videoConstraints),y=p.minScreenshotWidth!==m.minScreenshotWidth,x=p.minScreenshotHeight!==m.minScreenshotHeight;(v||y||x)&&(this.canvas=null,this.ctx=null),(g||v)&&(this.stopAndCleanup(),this.requestUserMedia())},h.prototype.componentWillUnmount=function(){this.unmounted=!0,this.stopAndCleanup()},h.stopMediaStream=function(p){p&&(p.getVideoTracks&&p.getAudioTracks?(p.getVideoTracks().map(function(m){p.removeTrack(m),m.stop()}),p.getAudioTracks().map(function(m){p.removeTrack(m),m.stop()})):p.stop())},h.prototype.stopAndCleanup=function(){var p=this.state;p.hasUserMedia&&(h.stopMediaStream(this.stream),p.src&&window.URL.revokeObjectURL(p.src))},h.prototype.getScreenshot=function(p){var m=this,g=m.state,v=m.props;if(!g.hasUserMedia)return null;var y=this.getCanvas(p);return y&&y.toDataURL(v.screenshotFormat,v.screenshotQuality)},h.prototype.getCanvas=function(p){var m=this,g=m.state,v=m.props;if(!this.video||!g.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var y=this.video.videoWidth,x=this.video.videoHeight;if(!this.props.forceScreenshotSourceSize){var w=y/x;y=v.minScreenshotWidth||this.video.clientWidth,x=y/w,v.minScreenshotHeight&&x0?w[0]:typeof w=="object"&&w.ideal?w.ideal:null};MediaStreamTrack.getSources(function(x){var w=null,b=null;x.forEach(function(E){E.kind==="audio"?w=E.id:E.kind==="video"&&(b=E.id)});var C=y(m.audioConstraints);C&&(w=C);var _=y(m.videoConstraints);_&&(b=_),g(v(w),v(b))})}},h.prototype.handleUserMedia=function(p,m){var g=this.props;if(p||!m){this.setState({hasUserMedia:!1}),g.onUserMediaError(p);return}this.stream=m;try{this.video&&(this.video.srcObject=m),this.setState({hasUserMedia:!0})}catch{this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(m)})}g.onUserMedia(m)},h.prototype.render=function(){var p=this,m=this,g=m.state,v=m.props,y=v.audio;v.forceScreenshotSourceSize;var x=v.disablePictureInPicture;v.onUserMedia,v.onUserMediaError,v.screenshotFormat,v.screenshotQuality,v.minScreenshotWidth,v.minScreenshotHeight,v.audioConstraints,v.videoConstraints,v.imageSmoothing;var w=v.mirrored,b=v.style,C=b===void 0?{}:b,_=v.children,E=l(v,["audio","forceScreenshotSourceSize","disablePictureInPicture","onUserMedia","onUserMediaError","screenshotFormat","screenshotQuality","minScreenshotWidth","minScreenshotHeight","audioConstraints","videoConstraints","imageSmoothing","mirrored","style","children"]),R=w?s(s({},C),{transform:(C.transform||"")+" scaleX(-1)"}):C,k={getScreenshot:this.getScreenshot.bind(this)};return a.createElement(a.Fragment,null,a.createElement("video",s({autoPlay:!0,disablePictureInPicture:x,src:g.src,muted:!y,playsInline:!0,ref:function(T){p.video=T},style:R},E)),_&&_(k))},h.defaultProps={audio:!1,disablePictureInPicture:!1,forceScreenshotSourceSize:!1,imageSmoothing:!0,mirrored:!1,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",screenshotQuality:.92},h}(a.Component);o.default=f},react:function(r,o){r.exports=n}}).default})})(Gg);var Gw=Gg.exports;const qw=Av(Gw);/** +`+i.stack}return{value:e,source:t,stack:o,digest:null}}function kl(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Bc(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var mw=typeof WeakMap=="function"?WeakMap:Map;function pg(e,t,n){n=er(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){qu||(qu=!0,qc=r),Bc(e,t)},n}function vg(e,t,n){n=er(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var o=t.value;n.payload=function(){return r(o)},n.callback=function(){Bc(e,t)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(n.callback=function(){Bc(e,t),typeof r!="function"&&(Nr===null?Nr=new Set([this]):Nr.add(this));var a=t.stack;this.componentDidCatch(t.value,{componentStack:a!==null?a:""})}),n}function sp(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new mw;var o=new Set;r.set(t,o)}else o=r.get(t),o===void 0&&(o=new Set,r.set(t,o));o.has(n)||(o.add(n),e=Tw.bind(null,e,t,n),t.then(e,e))}function lp(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function cp(e,t,n,r,o){return e.mode&1?(e.flags|=65536,e.lanes=o,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=er(-1,1),t.tag=2,Tr(n,t,1))),n.lanes|=1),e)}var gw=ar.ReactCurrentOwner,Dt=!1;function Ct(e,t,n,r){t.child=e===null?qm(t,null,n,r):si(t,e.child,n,r)}function fp(e,t,n,r,o){n=n.render;var i=t.ref;return Yo(t,o),r=Zf(e,t,n,r,i,o),n=ed(),e!==null&&!Dt?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,or(e,t,o)):(Te&&n&&Uf(t),t.flags|=1,Ct(e,t,r,o),t.child)}function dp(e,t,n,r,o){if(e===null){var i=n.type;return typeof i=="function"&&!cd(i)&&i.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=i,mg(e,t,i,r,o)):(e=Su(n.type,null,r,t,t.mode,o),e.ref=t.ref,e.return=t,t.child=e)}if(i=e.child,!(e.lanes&o)){var a=i.memoizedProps;if(n=n.compare,n=n!==null?n:ra,n(a,r)&&e.ref===t.ref)return or(e,t,o)}return t.flags|=1,e=Pr(i,r),e.ref=t.ref,e.return=t,t.child=e}function mg(e,t,n,r,o){if(e!==null){var i=e.memoizedProps;if(ra(i,r)&&e.ref===t.ref)if(Dt=!1,t.pendingProps=r=i,(e.lanes&o)!==0)e.flags&131072&&(Dt=!0);else return t.lanes=e.lanes,or(e,t,o)}return Lc(e,t,n,r,o)}function gg(e,t,n){var r=t.pendingProps,o=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},Se(jo,Lt),Lt|=n;else{if(!(n&1073741824))return e=i!==null?i.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,Se(jo,Lt),Lt|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:n,Se(jo,Lt),Lt|=r}else i!==null?(r=i.baseLanes|n,t.memoizedState=null):r=n,Se(jo,Lt),Lt|=r;return Ct(e,t,o,n),t.child}function yg(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Lc(e,t,n,r,o){var i=At(n)?so:wt.current;return i=ai(t,i),Yo(t,o),n=Zf(e,t,n,r,i,o),r=ed(),e!==null&&!Dt?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,or(e,t,o)):(Te&&r&&Uf(t),t.flags|=1,Ct(e,t,n,o),t.child)}function hp(e,t,n,r,o){if(At(n)){var i=!0;Bu(t)}else i=!1;if(Yo(t,o),t.stateNode===null)Cu(e,t),jm(t,n,r),Oc(t,n,r,o),r=!0;else if(e===null){var a=t.stateNode,u=t.memoizedProps;a.props=u;var s=a.context,l=n.contextType;typeof l=="object"&&l!==null?l=on(l):(l=At(n)?so:wt.current,l=ai(t,l));var c=n.getDerivedStateFromProps,f=typeof c=="function"||typeof a.getSnapshotBeforeUpdate=="function";f||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(u!==r||s!==l)&&op(t,a,r,l),yr=!1;var d=t.memoizedState;a.state=d,Vu(t,r,a,o),s=t.memoizedState,u!==r||d!==s||Nt.current||yr?(typeof c=="function"&&(Mc(t,n,c,r),s=t.memoizedState),(u=yr||rp(t,n,u,r,d,s,l))?(f||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount=="function"&&(t.flags|=4194308)):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=s),a.props=r,a.state=s,a.context=l,r=u):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,$m(e,t),u=t.memoizedProps,l=t.type===t.elementType?u:cn(t.type,u),a.props=l,f=t.pendingProps,d=a.context,s=n.contextType,typeof s=="object"&&s!==null?s=on(s):(s=At(n)?so:wt.current,s=ai(t,s));var h=n.getDerivedStateFromProps;(c=typeof h=="function"||typeof a.getSnapshotBeforeUpdate=="function")||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(u!==f||d!==s)&&op(t,a,r,s),yr=!1,d=t.memoizedState,a.state=d,Vu(t,r,a,o);var p=t.memoizedState;u!==f||d!==p||Nt.current||yr?(typeof h=="function"&&(Mc(t,n,h,r),p=t.memoizedState),(l=yr||rp(t,n,l,r,d,p,s)||!1)?(c||typeof a.UNSAFE_componentWillUpdate!="function"&&typeof a.componentWillUpdate!="function"||(typeof a.componentWillUpdate=="function"&&a.componentWillUpdate(r,p,s),typeof a.UNSAFE_componentWillUpdate=="function"&&a.UNSAFE_componentWillUpdate(r,p,s)),typeof a.componentDidUpdate=="function"&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof a.componentDidUpdate!="function"||u===e.memoizedProps&&d===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||u===e.memoizedProps&&d===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=s,r=l):(typeof a.componentDidUpdate!="function"||u===e.memoizedProps&&d===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||u===e.memoizedProps&&d===e.memoizedState||(t.flags|=1024),r=!1)}return Wc(e,t,n,r,i,o)}function Wc(e,t,n,r,o,i){yg(e,t);var a=(t.flags&128)!==0;if(!r&&!a)return o&&Jh(t,n,!1),or(e,t,i);r=t.stateNode,gw.current=t;var u=a&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&a?(t.child=si(t,e.child,null,i),t.child=si(t,null,u,i)):Ct(e,t,u,i),t.memoizedState=r.state,o&&Jh(t,n,!0),t.child}function xg(e){var t=e.stateNode;t.pendingContext?Qh(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Qh(e,t.context,!1),Xf(e,t.containerInfo)}function pp(e,t,n,r,o){return ui(),$f(o),t.flags|=256,Ct(e,t,n,r),t.child}var zc={dehydrated:null,treeContext:null,retryLane:0};function Uc(e){return{baseLanes:e,cachePool:null,transitions:null}}function wg(e,t,n){var r=t.pendingProps,o=Pe.current,i=!1,a=(t.flags&128)!==0,u;if((u=a)||(u=e!==null&&e.memoizedState===null?!1:(o&2)!==0),u?(i=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Se(Pe,o&1),e===null)return Pc(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(a=r.children,e=r.fallback,i?(r=t.mode,i=t.child,a={mode:"hidden",children:a},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=a):i=Ns(a,r,0,null),e=io(e,r,n,null),i.return=t,e.return=t,i.sibling=e,t.child=i,t.child.memoizedState=Uc(n),t.memoizedState=zc,e):rd(t,a));if(o=e.memoizedState,o!==null&&(u=o.dehydrated,u!==null))return yw(e,t,a,r,u,o,n);if(i){i=r.fallback,a=t.mode,o=e.child,u=o.sibling;var s={mode:"hidden",children:r.children};return!(a&1)&&t.child!==o?(r=t.child,r.childLanes=0,r.pendingProps=s,t.deletions=null):(r=Pr(o,s),r.subtreeFlags=o.subtreeFlags&14680064),u!==null?i=Pr(u,i):(i=io(i,a,n,null),i.flags|=2),i.return=t,r.return=t,r.sibling=i,t.child=r,r=i,i=t.child,a=e.child.memoizedState,a=a===null?Uc(n):{baseLanes:a.baseLanes|n,cachePool:null,transitions:a.transitions},i.memoizedState=a,i.childLanes=e.childLanes&~n,t.memoizedState=zc,r}return i=e.child,e=i.sibling,r=Pr(i,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function rd(e,t){return t=Ns({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Ya(e,t,n,r){return r!==null&&$f(r),si(t,e.child,null,n),e=rd(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function yw(e,t,n,r,o,i,a){if(n)return t.flags&256?(t.flags&=-257,r=kl(Error(j(422))),Ya(e,t,a,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(i=r.fallback,o=t.mode,r=Ns({mode:"visible",children:r.children},o,0,null),i=io(i,o,a,null),i.flags|=2,r.return=t,i.return=t,r.sibling=i,t.child=r,t.mode&1&&si(t,e.child,null,a),t.child.memoizedState=Uc(a),t.memoizedState=zc,i);if(!(t.mode&1))return Ya(e,t,a,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var u=r.dgst;return r=u,i=Error(j(419)),r=kl(i,r,void 0),Ya(e,t,a,r)}if(u=(a&e.childLanes)!==0,Dt||u){if(r=rt,r!==null){switch(a&-a){case 4:o=2;break;case 16:o=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:o=32;break;case 536870912:o=268435456;break;default:o=0}o=o&(r.suspendedLanes|a)?0:o,o!==0&&o!==i.retryLane&&(i.retryLane=o,rr(e,o),mn(r,e,o,-1))}return ld(),r=kl(Error(j(421))),Ya(e,t,a,r)}return o.data==="$?"?(t.flags|=128,t.child=e.child,t=Nw.bind(null,e),o._reactRetry=t,null):(e=i.treeContext,Ut=Dr(o.nextSibling),jt=t,Te=!0,dn=null,e!==null&&(Qt[Jt++]=Jn,Qt[Jt++]=Zn,Qt[Jt++]=lo,Jn=e.id,Zn=e.overflow,lo=t),t=rd(t,r.children),t.flags|=4096,t)}function vp(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Fc(e.return,t,n)}function Rl(e,t,n,r,o){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:o}:(i.isBackwards=t,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=n,i.tailMode=o)}function bg(e,t,n){var r=t.pendingProps,o=r.revealOrder,i=r.tail;if(Ct(e,t,r.children,n),r=Pe.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&vp(e,n,t);else if(e.tag===19)vp(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Se(Pe,r),!(t.mode&1))t.memoizedState=null;else switch(o){case"forwards":for(n=t.child,o=null;n!==null;)e=n.alternate,e!==null&&$u(e)===null&&(o=n),n=n.sibling;n=o,n===null?(o=t.child,t.child=null):(o=n.sibling,n.sibling=null),Rl(t,!1,o,n,i);break;case"backwards":for(n=null,o=t.child,t.child=null;o!==null;){if(e=o.alternate,e!==null&&$u(e)===null){t.child=o;break}e=o.sibling,o.sibling=n,n=o,o=e}Rl(t,!0,n,null,i);break;case"together":Rl(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Cu(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function or(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),fo|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(j(153));if(t.child!==null){for(e=t.child,n=Pr(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Pr(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function xw(e,t,n){switch(t.tag){case 3:xg(t),ui();break;case 5:Km(t);break;case 1:At(t.type)&&Bu(t);break;case 4:Xf(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,o=t.memoizedProps.value;Se(zu,r._currentValue),r._currentValue=o;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(Se(Pe,Pe.current&1),t.flags|=128,null):n&t.child.childLanes?wg(e,t,n):(Se(Pe,Pe.current&1),e=or(e,t,n),e!==null?e.sibling:null);Se(Pe,Pe.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return bg(e,t,n);t.flags|=128}if(o=t.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Se(Pe,Pe.current),r)break;return null;case 22:case 23:return t.lanes=0,gg(e,t,n)}return or(e,t,n)}var Cg,Vc,_g,Eg;Cg=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Vc=function(){};_g=function(e,t,n,r){var o=e.memoizedProps;if(o!==r){e=t.stateNode,to(Fn.current);var i=null;switch(n){case"input":o=cc(e,o),r=cc(e,r),i=[];break;case"select":o=Be({},o,{value:void 0}),r=Be({},r,{value:void 0}),i=[];break;case"textarea":o=hc(e,o),r=hc(e,r),i=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Mu)}vc(n,r);var a;n=null;for(l in o)if(!r.hasOwnProperty(l)&&o.hasOwnProperty(l)&&o[l]!=null)if(l==="style"){var u=o[l];for(a in u)u.hasOwnProperty(a)&&(n||(n={}),n[a]="")}else l!=="dangerouslySetInnerHTML"&&l!=="children"&&l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(Yi.hasOwnProperty(l)?i||(i=[]):(i=i||[]).push(l,null));for(l in r){var s=r[l];if(u=o!=null?o[l]:void 0,r.hasOwnProperty(l)&&s!==u&&(s!=null||u!=null))if(l==="style")if(u){for(a in u)!u.hasOwnProperty(a)||s&&s.hasOwnProperty(a)||(n||(n={}),n[a]="");for(a in s)s.hasOwnProperty(a)&&u[a]!==s[a]&&(n||(n={}),n[a]=s[a])}else n||(i||(i=[]),i.push(l,n)),n=s;else l==="dangerouslySetInnerHTML"?(s=s?s.__html:void 0,u=u?u.__html:void 0,s!=null&&u!==s&&(i=i||[]).push(l,s)):l==="children"?typeof s!="string"&&typeof s!="number"||(i=i||[]).push(l,""+s):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&(Yi.hasOwnProperty(l)?(s!=null&&l==="onScroll"&&Re("scroll",e),i||u===s||(i=[])):(i=i||[]).push(l,s))}n&&(i=i||[]).push("style",n);var l=i;(t.updateQueue=l)&&(t.flags|=4)}};Eg=function(e,t,n,r){n!==r&&(t.flags|=4)};function Ri(e,t){if(!Te)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function ht(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var o=e.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags&14680064,r|=o.flags&14680064,o.return=e,o=o.sibling;else for(o=e.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=e,o=o.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function ww(e,t,n){var r=t.pendingProps;switch(Vf(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return ht(t),null;case 1:return At(t.type)&&Ou(),ht(t),null;case 3:return r=t.stateNode,li(),De(Nt),De(wt),Qf(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Ka(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,dn!==null&&(Yc(dn),dn=null))),Vc(e,t),ht(t),null;case 5:Yf(t);var o=to(sa.current);if(n=t.type,e!==null&&t.stateNode!=null)_g(e,t,n,r,o),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(j(166));return ht(t),null}if(e=to(Fn.current),Ka(t)){r=t.stateNode,n=t.type;var i=t.memoizedProps;switch(r[Dn]=t,r[aa]=i,e=(t.mode&1)!==0,n){case"dialog":Re("cancel",r),Re("close",r);break;case"iframe":case"object":case"embed":Re("load",r);break;case"video":case"audio":for(o=0;o<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[Dn]=t,e[aa]=r,Cg(e,t,!1,!1),t.stateNode=e;e:{switch(a=mc(n,r),n){case"dialog":Re("cancel",e),Re("close",e),o=r;break;case"iframe":case"object":case"embed":Re("load",e),o=r;break;case"video":case"audio":for(o=0;ofi&&(t.flags|=128,r=!0,Ri(i,!1),t.lanes=4194304)}else{if(!r)if(e=$u(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Ri(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!Te)return ht(t),null}else 2*He()-i.renderingStartTime>fi&&n!==1073741824&&(t.flags|=128,r=!0,Ri(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(n=i.last,n!==null?n.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=He(),t.sibling=null,n=Pe.current,Se(Pe,r?n&1|2:n&1),t):(ht(t),null);case 22:case 23:return sd(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Lt&1073741824&&(ht(t),t.subtreeFlags&6&&(t.flags|=8192)):ht(t),null;case 24:return null;case 25:return null}throw Error(j(156,t.tag))}function bw(e,t){switch(Vf(t),t.tag){case 1:return At(t.type)&&Ou(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return li(),De(Nt),De(wt),Qf(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Yf(t),null;case 13:if(De(Pe),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(j(340));ui()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return De(Pe),null;case 4:return li(),null;case 10:return Gf(t.type._context),null;case 22:case 23:return sd(),null;case 24:return null;default:return null}}var Qa=!1,vt=!1,Cw=typeof WeakSet=="function"?WeakSet:Set,Y=null;function Ho(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Ue(e,t,r)}else n.current=null}function $c(e,t,n){try{n()}catch(r){Ue(e,t,r)}}var mp=!1;function _w(e,t){if(kc=Au,e=Im(),zf(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var a=0,u=-1,s=-1,l=0,c=0,f=e,d=null;t:for(;;){for(var h;f!==n||o!==0&&f.nodeType!==3||(u=a+o),f!==i||r!==0&&f.nodeType!==3||(s=a+r),f.nodeType===3&&(a+=f.nodeValue.length),(h=f.firstChild)!==null;)d=f,f=h;for(;;){if(f===e)break t;if(d===n&&++l===o&&(u=a),d===i&&++c===r&&(s=a),(h=f.nextSibling)!==null)break;f=d,d=f.parentNode}f=h}n=u===-1||s===-1?null:{start:u,end:s}}else n=null}n=n||{start:0,end:0}}else n=null;for(Rc={focusedElem:e,selectionRange:n},Au=!1,Y=t;Y!==null;)if(t=Y,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Y=e;else for(;Y!==null;){t=Y;try{var p=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(p!==null){var m=p.memoizedProps,g=p.memoizedState,v=t.stateNode,y=v.getSnapshotBeforeUpdate(t.elementType===t.type?m:cn(t.type,m),g);v.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var x=t.stateNode.containerInfo;x.nodeType===1?x.textContent="":x.nodeType===9&&x.documentElement&&x.removeChild(x.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(j(163))}}catch(w){Ue(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,Y=e;break}Y=t.return}return p=mp,mp=!1,p}function Hi(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&e)===e){var i=o.destroy;o.destroy=void 0,i!==void 0&&$c(t,n,i)}o=o.next}while(o!==r)}}function Ds(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Hc(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Sg(e){var t=e.alternate;t!==null&&(e.alternate=null,Sg(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Dn],delete t[aa],delete t[Tc],delete t[iw],delete t[aw])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function kg(e){return e.tag===5||e.tag===3||e.tag===4}function gp(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||kg(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function jc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Mu));else if(r!==4&&(e=e.child,e!==null))for(jc(e,t,n),e=e.sibling;e!==null;)jc(e,t,n),e=e.sibling}function Gc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Gc(e,t,n),e=e.sibling;e!==null;)Gc(e,t,n),e=e.sibling}var at=null,fn=!1;function pr(e,t,n){for(n=n.child;n!==null;)Rg(e,t,n),n=n.sibling}function Rg(e,t,n){if(Pn&&typeof Pn.onCommitFiberUnmount=="function")try{Pn.onCommitFiberUnmount(bs,n)}catch{}switch(n.tag){case 5:vt||Ho(n,t);case 6:var r=at,o=fn;at=null,pr(e,t,n),at=r,fn=o,at!==null&&(fn?(e=at,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):at.removeChild(n.stateNode));break;case 18:at!==null&&(fn?(e=at,n=n.stateNode,e.nodeType===8?wl(e.parentNode,n):e.nodeType===1&&wl(e,n),ta(e)):wl(at,n.stateNode));break;case 4:r=at,o=fn,at=n.stateNode.containerInfo,fn=!0,pr(e,t,n),at=r,fn=o;break;case 0:case 11:case 14:case 15:if(!vt&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var i=o,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&$c(n,t,a),o=o.next}while(o!==r)}pr(e,t,n);break;case 1:if(!vt&&(Ho(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(u){Ue(n,t,u)}pr(e,t,n);break;case 21:pr(e,t,n);break;case 22:n.mode&1?(vt=(r=vt)||n.memoizedState!==null,pr(e,t,n),vt=r):pr(e,t,n);break;default:pr(e,t,n)}}function yp(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Cw),t.forEach(function(r){var o=Aw.bind(null,e,r);n.has(r)||(n.add(r),r.then(o,o))})}}function sn(e,t){var n=t.deletions;if(n!==null)for(var r=0;ro&&(o=a),r&=~i}if(r=o,r=He()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Sw(r/1960))-r,10e?16:e,Cr===null)var r=!1;else{if(e=Cr,Cr=null,Ku=0,xe&6)throw Error(j(331));var o=xe;for(xe|=4,Y=e.current;Y!==null;){var i=Y,a=i.child;if(Y.flags&16){var u=i.deletions;if(u!==null){for(var s=0;sHe()-ad?oo(e,0):id|=n),Pt(e,t)}function Mg(e,t){t===0&&(e.mode&1?(t=Va,Va<<=1,!(Va&130023424)&&(Va=4194304)):t=1);var n=_t();e=rr(e,t),e!==null&&(_a(e,t,n),Pt(e,n))}function Nw(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Mg(e,n)}function Aw(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(j(314))}r!==null&&r.delete(t),Mg(e,n)}var Og;Og=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Nt.current)Dt=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Dt=!1,xw(e,t,n);Dt=!!(e.flags&131072)}else Dt=!1,Te&&t.flags&1048576&&Wm(t,Wu,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Cu(e,t),e=t.pendingProps;var o=ai(t,wt.current);Yo(t,n),o=Zf(null,t,r,e,o,n);var i=ed();return t.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,At(r)?(i=!0,Bu(t)):i=!1,t.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,Kf(t),o.updater=Rs,t.stateNode=o,o._reactInternals=t,Oc(t,r,e,n),t=Wc(null,t,r,!0,i,n)):(t.tag=0,Te&&i&&Uf(t),Ct(null,t,o,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Cu(e,t),e=t.pendingProps,o=r._init,r=o(r._payload),t.type=r,o=t.tag=Fw(r),e=cn(r,e),o){case 0:t=Lc(null,t,r,e,n);break e;case 1:t=hp(null,t,r,e,n);break e;case 11:t=fp(null,t,r,e,n);break e;case 14:t=dp(null,t,r,cn(r.type,e),n);break e}throw Error(j(306,r,""))}return t;case 0:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:cn(r,o),Lc(e,t,r,o,n);case 1:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:cn(r,o),hp(e,t,r,o,n);case 3:e:{if(xg(t),e===null)throw Error(j(387));r=t.pendingProps,i=t.memoizedState,o=i.element,$m(e,t),Vu(t,r,null,n);var a=t.memoizedState;if(r=a.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){o=ci(Error(j(423)),t),t=pp(e,t,r,n,o);break e}else if(r!==o){o=ci(Error(j(424)),t),t=pp(e,t,r,n,o);break e}else for(Ut=Dr(t.stateNode.containerInfo.firstChild),jt=t,Te=!0,dn=null,n=qm(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(ui(),r===o){t=or(e,t,n);break e}Ct(e,t,r,n)}t=t.child}return t;case 5:return Km(t),e===null&&Pc(t),r=t.type,o=t.pendingProps,i=e!==null?e.memoizedProps:null,a=o.children,Ic(r,o)?a=null:i!==null&&Ic(r,i)&&(t.flags|=32),yg(e,t),Ct(e,t,a,n),t.child;case 6:return e===null&&Pc(t),null;case 13:return wg(e,t,n);case 4:return Xf(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=si(t,null,r,n):Ct(e,t,r,n),t.child;case 11:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:cn(r,o),fp(e,t,r,o,n);case 7:return Ct(e,t,t.pendingProps,n),t.child;case 8:return Ct(e,t,t.pendingProps.children,n),t.child;case 12:return Ct(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,o=t.pendingProps,i=t.memoizedProps,a=o.value,Se(zu,r._currentValue),r._currentValue=a,i!==null)if(yn(i.value,a)){if(i.children===o.children&&!Nt.current){t=or(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var u=i.dependencies;if(u!==null){a=i.child;for(var s=u.firstContext;s!==null;){if(s.context===r){if(i.tag===1){s=er(-1,n&-n),s.tag=2;var l=i.updateQueue;if(l!==null){l=l.shared;var c=l.pending;c===null?s.next=s:(s.next=c.next,c.next=s),l.pending=s}}i.lanes|=n,s=i.alternate,s!==null&&(s.lanes|=n),Fc(i.return,n,t),u.lanes|=n;break}s=s.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error(j(341));a.lanes|=n,u=a.alternate,u!==null&&(u.lanes|=n),Fc(a,n,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}Ct(e,t,o.children,n),t=t.child}return t;case 9:return o=t.type,r=t.pendingProps.children,Yo(t,n),o=on(o),r=r(o),t.flags|=1,Ct(e,t,r,n),t.child;case 14:return r=t.type,o=cn(r,t.pendingProps),o=cn(r.type,o),dp(e,t,r,o,n);case 15:return mg(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:cn(r,o),Cu(e,t),t.tag=1,At(r)?(e=!0,Bu(t)):e=!1,Yo(t,n),jm(t,r,o),Oc(t,r,o,n),Wc(null,t,r,!0,e,n);case 19:return bg(e,t,n);case 22:return gg(e,t,n)}throw Error(j(156,t.tag))};function Bg(e,t){return lm(e,t)}function Pw(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function tn(e,t,n,r){return new Pw(e,t,n,r)}function cd(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Fw(e){if(typeof e=="function")return cd(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Df)return 11;if(e===Tf)return 14}return 2}function Pr(e,t){var n=e.alternate;return n===null?(n=tn(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Su(e,t,n,r,o,i){var a=2;if(r=e,typeof e=="function")cd(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Mo:return io(n.children,o,i,t);case If:a=8,o|=8;break;case ac:return e=tn(12,n,t,o|2),e.elementType=ac,e.lanes=i,e;case uc:return e=tn(13,n,t,o),e.elementType=uc,e.lanes=i,e;case sc:return e=tn(19,n,t,o),e.elementType=sc,e.lanes=i,e;case Gv:return Ns(n,o,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Hv:a=10;break e;case jv:a=9;break e;case Df:a=11;break e;case Tf:a=14;break e;case gr:a=16,r=null;break e}throw Error(j(130,e==null?e:typeof e,""))}return t=tn(a,n,t,o),t.elementType=e,t.type=r,t.lanes=i,t}function io(e,t,n,r){return e=tn(7,e,r,t),e.lanes=n,e}function Ns(e,t,n,r){return e=tn(22,e,r,t),e.elementType=Gv,e.lanes=n,e.stateNode={isHidden:!1},e}function Il(e,t,n){return e=tn(6,e,null,t),e.lanes=n,e}function Dl(e,t,n){return t=tn(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Mw(e,t,n,r,o){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=ll(0),this.expirationTimes=ll(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ll(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function fd(e,t,n,r,o,i,a,u,s){return e=new Mw(e,t,n,u,s),t===1?(t=1,i===!0&&(t|=8)):t=0,i=tn(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Kf(i),e}function Ow(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Ug)}catch(e){console.error(e)}}Ug(),Wv.exports=Xt;var Uw=Wv.exports,kp=Uw;oc.createRoot=kp.createRoot,oc.hydrateRoot=kp.hydrateRoot;var Vg={exports:{}};(function(e,t){(function(r,o){e.exports=o(Yn)})(v1,function(n){return function(r){var o={};function i(a){if(o[a])return o[a].exports;var u=o[a]={i:a,l:!1,exports:{}};return r[a].call(u.exports,u,u.exports,i),u.l=!0,u.exports}return i.m=r,i.c=o,i.d=function(a,u,s){i.o(a,u)||Object.defineProperty(a,u,{enumerable:!0,get:s})},i.r=function(a){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},i.t=function(a,u){if(u&1&&(a=i(a)),u&8||u&4&&typeof a=="object"&&a&&a.__esModule)return a;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:a}),u&2&&typeof a!="string")for(var l in a)i.d(s,l,(function(c){return a[c]}).bind(null,l));return s},i.n=function(a){var u=a&&a.__esModule?function(){return a.default}:function(){return a};return i.d(u,"a",u),u},i.o=function(a,u){return Object.prototype.hasOwnProperty.call(a,u)},i.p="",i(i.s="./src/react-webcam.tsx")}({"./src/react-webcam.tsx":function(r,o,i){i.r(o);var a=i("react"),u=function(){var d=function(h,p){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(m,g){m.__proto__=g}||function(m,g){for(var v in g)g.hasOwnProperty(v)&&(m[v]=g[v])},d(h,p)};return function(h,p){d(h,p);function m(){this.constructor=h}h.prototype=p===null?Object.create(p):(m.prototype=p.prototype,new m)}}(),s=function(){return s=Object.assign||function(d){for(var h,p=1,m=arguments.length;p"u"||(navigator.mediaDevices===void 0&&(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia===void 0&&(navigator.mediaDevices.getUserMedia=function(h){var p=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;return p?new Promise(function(m,g){p.call(navigator,h,m,g)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}))})();function c(){return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}var f=function(d){u(h,d);function h(p){var m=d.call(this,p)||this;return m.canvas=null,m.ctx=null,m.requestUserMediaId=0,m.unmounted=!1,m.state={hasUserMedia:!1},m}return h.prototype.componentDidMount=function(){var p=this,m=p.state,g=p.props;if(this.unmounted=!1,!c()){g.onUserMediaError("getUserMedia not supported");return}m.hasUserMedia||this.requestUserMedia(),g.children&&typeof g.children!="function"&&console.warn("children must be a function")},h.prototype.componentDidUpdate=function(p){var m=this.props;if(!c()){m.onUserMediaError("getUserMedia not supported");return}var g=JSON.stringify(p.audioConstraints)!==JSON.stringify(m.audioConstraints),v=JSON.stringify(p.videoConstraints)!==JSON.stringify(m.videoConstraints),y=p.minScreenshotWidth!==m.minScreenshotWidth,x=p.minScreenshotHeight!==m.minScreenshotHeight;(v||y||x)&&(this.canvas=null,this.ctx=null),(g||v)&&(this.stopAndCleanup(),this.requestUserMedia())},h.prototype.componentWillUnmount=function(){this.unmounted=!0,this.stopAndCleanup()},h.stopMediaStream=function(p){p&&(p.getVideoTracks&&p.getAudioTracks?(p.getVideoTracks().map(function(m){p.removeTrack(m),m.stop()}),p.getAudioTracks().map(function(m){p.removeTrack(m),m.stop()})):p.stop())},h.prototype.stopAndCleanup=function(){var p=this.state;p.hasUserMedia&&(h.stopMediaStream(this.stream),p.src&&window.URL.revokeObjectURL(p.src))},h.prototype.getScreenshot=function(p){var m=this,g=m.state,v=m.props;if(!g.hasUserMedia)return null;var y=this.getCanvas(p);return y&&y.toDataURL(v.screenshotFormat,v.screenshotQuality)},h.prototype.getCanvas=function(p){var m=this,g=m.state,v=m.props;if(!this.video||!g.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var y=this.video.videoWidth,x=this.video.videoHeight;if(!this.props.forceScreenshotSourceSize){var w=y/x;y=v.minScreenshotWidth||this.video.clientWidth,x=y/w,v.minScreenshotHeight&&x0?w[0]:typeof w=="object"&&w.ideal?w.ideal:null};MediaStreamTrack.getSources(function(x){var w=null,b=null;x.forEach(function(E){E.kind==="audio"?w=E.id:E.kind==="video"&&(b=E.id)});var C=y(m.audioConstraints);C&&(w=C);var _=y(m.videoConstraints);_&&(b=_),g(v(w),v(b))})}},h.prototype.handleUserMedia=function(p,m){var g=this.props;if(p||!m){this.setState({hasUserMedia:!1}),g.onUserMediaError(p);return}this.stream=m;try{this.video&&(this.video.srcObject=m),this.setState({hasUserMedia:!0})}catch{this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(m)})}g.onUserMedia(m)},h.prototype.render=function(){var p=this,m=this,g=m.state,v=m.props,y=v.audio;v.forceScreenshotSourceSize;var x=v.disablePictureInPicture;v.onUserMedia,v.onUserMediaError,v.screenshotFormat,v.screenshotQuality,v.minScreenshotWidth,v.minScreenshotHeight,v.audioConstraints,v.videoConstraints,v.imageSmoothing;var w=v.mirrored,b=v.style,C=b===void 0?{}:b,_=v.children,E=l(v,["audio","forceScreenshotSourceSize","disablePictureInPicture","onUserMedia","onUserMediaError","screenshotFormat","screenshotQuality","minScreenshotWidth","minScreenshotHeight","audioConstraints","videoConstraints","imageSmoothing","mirrored","style","children"]),R=w?s(s({},C),{transform:(C.transform||"")+" scaleX(-1)"}):C,k={getScreenshot:this.getScreenshot.bind(this)};return a.createElement(a.Fragment,null,a.createElement("video",s({autoPlay:!0,disablePictureInPicture:x,src:g.src,muted:!y,playsInline:!0,ref:function(T){p.video=T},style:R},E)),_&&_(k))},h.defaultProps={audio:!1,disablePictureInPicture:!1,forceScreenshotSourceSize:!1,imageSmoothing:!0,mirrored:!1,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",screenshotQuality:.92},h}(a.Component);o.default=f},react:function(r,o){r.exports=n}}).default})})(Vg);var Vw=Vg.exports;const $w=Iv(Vw);/** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,20 +52,20 @@ Error generating stack: `+i.message+` * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= - */var qg=function(e,t){return(qg=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)r.hasOwnProperty(o)&&(n[o]=r[o])})(e,t)};function wn(e,t){function n(){this.constructor=e}qg(e,t),e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function Q(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(l){try{s(r.next(l))}catch(c){i(c)}}function u(l){try{s(r.throw(l))}catch(c){i(c)}}function s(l){l.done?o(l.value):new n(function(c){c(l.value)}).then(a,u)}s((r=r.apply(e,t||[])).next())})}function J(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function u(s){return function(l){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){a=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]=n?o():setTimeout(a,u)}};a()})}function e2(e,t){for(var n=1,r=-1,o=0;o=0)n*=e[o];else if(e[o]===-1){if(r!==-1)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+o);r=o}else if(e[o]<0)throw Error("Shapes can not be < 0. Found "+e[o]+" at dim "+o);if(r===-1){if(t>0&&t!==n)throw Error("Size("+t+") must match the product of shape "+e);return e}if(n===0)throw Error("Cannot infer the missing size in ["+e+"] when there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+t+" / "+n);var i=e.slice();return i[r]=t/n,i}function et(e,t){var n=t.length;return I((e=e==null?t.map(function(r,o){return o}):[].concat(e)).every(function(r){return r>=-n&&ru)&&e[u]===1&&(n.push(e[u]),r.push(u)),i[a]<=u&&a++}e[u]!==1&&(n.push(e[u]),r.push(u))}return{newShape:n,keptDims:r}}function va(e,t){var n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else{if(e!=="bool")throw new Error("Unknown data type "+e);n=new Uint8Array(t)}return n}function ts(e,t){var n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else if(e==="bool")n=new Uint8Array(t);else{if(e!=="string")throw new Error("Unknown data type "+e);n=new Array(t)}return n}function t2(e,t){for(var n=0;n=0;--r)n[r]=n[r+1]*e[r+1];return n}function e0(e,t,n){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=pi(e)),n&&t2(e,t),function(i,a){return i instanceof Float32Array&&a==="float32"||i instanceof Int32Array&&a==="int32"||i instanceof Uint8Array&&a==="bool"}(e,t))return e;if(t==null||t==="float32"||t==="complex64")return new Float32Array(e);if(t==="int32")return new Int32Array(e);if(t==="bool"){for(var r=new Uint8Array(e.length),o=0;o=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+e+"]."})})}function u2(e,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",z().platform.encode(e,t)}function ns(e,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",z().platform.decode(e,t)}function Mp(e,t,n){if(t===0)return 0;if(t===1)return e[0];for(var r=e[e.length-1],o=0;o0?p:"")+" "}console.log("%c"+s+" %c"+u+" %c"+l+"D "+f+" %c"+c+" %c"+d+" %c"+a,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}(),Op=20,Ai=3,Al=7;function f2(e,t,n,r){var o=Bn(t),i=function(l,c,f,d){var h=Z(c),p=d[d.length-1],m=new Array(p).fill(0),g=c.length,v=f==="complex64"?Fi(l):l;if(g>1)for(var y=0;yOp){var x=Ai*g,w=Array.from(c.slice(0,x)),b=Array.from(c.slice((v-Ai)*g,v*g));return d==="complex64"&&(w=Fi(w),b=Fi(b)),["["+w.map(function(U,$){return Pi(U,p[$],d)}).join(", ")+", ..., "+b.map(function(U,$){return Pi(U,p[v-Ai+$],d)}).join(", ")+"]"]}return["["+(d==="complex64"?Fi(c):Array.from(c)).map(function(U,$){return Pi(U,p[$],d)}).join(", ")+"]"]}var C=f.slice(1),_=h.slice(1),E=h[0]*g,R=[];if(v>Op){for(var k=0;k0&&o[o.length-1])&&(c[0]===6||c[0]===2)){a=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]=n?o():setTimeout(a,u)}};a()})}function Yw(e,t){for(var n=1,r=-1,o=0;o=0)n*=e[o];else if(e[o]===-1){if(r!==-1)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+o);r=o}else if(e[o]<0)throw Error("Shapes can not be < 0. Found "+e[o]+" at dim "+o);if(r===-1){if(t>0&&t!==n)throw Error("Size("+t+") must match the product of shape "+e);return e}if(n===0)throw Error("Cannot infer the missing size in ["+e+"] when there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+t+" / "+n);var i=e.slice();return i[r]=t/n,i}function et(e,t){var n=t.length;return I((e=e==null?t.map(function(r,o){return o}):[].concat(e)).every(function(r){return r>=-n&&ru)&&e[u]===1&&(n.push(e[u]),r.push(u)),i[a]<=u&&a++}e[u]!==1&&(n.push(e[u]),r.push(u))}return{newShape:n,keptDims:r}}function ha(e,t){var n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else{if(e!=="bool")throw new Error("Unknown data type "+e);n=new Uint8Array(t)}return n}function Ju(e,t){var n=null;if(e==null||e==="float32")n=new Float32Array(t);else if(e==="int32")n=new Int32Array(t);else if(e==="bool")n=new Uint8Array(t);else{if(e!=="string")throw new Error("Unknown data type "+e);n=new Array(t)}return n}function Qw(e,t){for(var n=0;n=0;--r)n[r]=n[r+1]*e[r+1];return n}function Yg(e,t,n){if(t==="string")throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=di(e)),n&&Qw(e,t),function(i,a){return i instanceof Float32Array&&a==="float32"||i instanceof Int32Array&&a==="int32"||i instanceof Uint8Array&&a==="bool"}(e,t))return e;if(t==null||t==="float32"||t==="complex64")return new Float32Array(e);if(t==="int32")return new Int32Array(e);if(t==="bool"){for(var r=new Uint8Array(e.length),o=0;o=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+e+"]."})})}function r2(e,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",z().platform.encode(e,t)}function Zu(e,t){return t===void 0&&(t="utf-8"),t=t||"utf-8",z().platform.decode(e,t)}function Tp(e,t,n){if(t===0)return 0;if(t===1)return e[0];for(var r=e[e.length-1],o=0;o0?p:"")+" "}console.log("%c"+s+" %c"+u+" %c"+l+"D "+f+" %c"+c+" %c"+d+" %c"+a,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},e}(),Np=20,Di=3,Tl=7;function u2(e,t,n,r){var o=On(t),i=function(l,c,f,d){var h=Z(c),p=d[d.length-1],m=new Array(p).fill(0),g=c.length,v=f==="complex64"?Ni(l):l;if(g>1)for(var y=0;yNp){var x=Di*g,w=Array.from(c.slice(0,x)),b=Array.from(c.slice((v-Di)*g,v*g));return d==="complex64"&&(w=Ni(w),b=Ni(b)),["["+w.map(function(U,$){return Ti(U,p[$],d)}).join(", ")+", ..., "+b.map(function(U,$){return Ti(U,p[v-Di+$],d)}).join(", ")+"]"]}return["["+(d==="complex64"?Ni(c):Array.from(c)).map(function(U,$){return Ti(U,p[$],d)}).join(", ")+"]"]}var C=f.slice(1),_=h.slice(1),E=h[0]*g,R=[];if(v>Np){for(var k=0;k=this.shape[r]){var u="Requested out of range element at "+t+". Buffer shape="+this.shape;throw new Error(u)}r++}for(var s=t[t.length-1],l=0;l0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+u+" data ids) after running '"+t+"'")},e.prototype.runKernelFunc=function(t,n,r,o,i,a,u){var s,l=this;a===void 0&&(a=[]),u===void 0&&(u=[]);var c=[],f=this.isTapeOn();o==null&&(o=this.state.activeScope!=null?this.state.activeScope.name:"");var d,h=function(y){f&&(c=y.map(function(x){return l.keep(l.clone(x))}))},p=this.state.numBytes,m=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var g,v=Xg(o,this.backendName);return d=v!=null?function(){var y=l.backend.numDataIds();g=v.kernelFunc({inputs:n,attrs:i,backend:l.backend});var x=Array.isArray(g)?g:[g];l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(o,y,x);var w=x.map(function(C){var _=C.dataId,E=C.shape,R=C.dtype;return l.makeTensorFromDataId(_,E,R)}),b=w.filter(function(C,_){return u[_]});return h((a||[]).slice().concat(b)),w}:function(){var y=l.backend.numDataIds();g=l.tidy(function(){return t(l.backend,h)});var x=Array.isArray(g)?g:[g];return l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(o,y,x),x},this.scopedRun(function(){return l.state.kernelDepth++},function(){return l.state.kernelDepth--},function(){s=l.ENV.getBool("DEBUG")?l.profiler.profileKernel(o,n,function(){return d()}):d()}),f&&this.addTapeNode(o,n,s,r,c),this.state.profiling&&this.state.activeProfile.kernels.push({name:o,bytesAdded:this.state.numBytes-p,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-m,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(n).map(function(y){return n[y].shape}),outputShapes:s.map(function(y){return y.shape})}),Array.isArray(g)?s:s[0]},e.prototype.makeTensor=function(t,n,r,o){if(t==null)throw new Error("Values passed to engine.makeTensor() are null");r=r||"float32",o=o||this.backend;var i=t;r==="string"&&gd(t[0])&&(i=t.map(function(c){return u2(c)}));var a=o.write(i,n,r),u=new Fe(n,r,a,this.nextTensorId());if(this.incRef(u,o),r==="string"){var s=this.state.tensorInfo.get(a),l=o2(i);this.state.numBytes+=l-s.bytes,s.bytes=l}return u},e.prototype.makeTensorFromDataId=function(t,n,r,o){var i=new Fe(n,r=r||"float32",t,this.nextTensorId());return this.incRef(i,o),i},e.prototype.makeVariable=function(t,n,r,o){n===void 0&&(n=!0),r=r||this.nextVariableId().toString(),o!=null&&o!==t.dtype&&(t=t.asType(o));var i=new vi(t,n,r,this.nextTensorId());if(this.state.registeredVariables[i.name]!=null)throw new Error("Variable with name "+i.name+" was already registered");return this.state.registeredVariables[i.name]=i,this.incRef(i,this.backend),i},e.prototype.incRef=function(t,n){var r=this.state.tensorInfo.has(t.dataId)?this.state.tensorInfo.get(t.dataId).refCount:0;if(this.state.numTensors++,t.dtype==="string"&&this.state.numStringTensors++,r===0){this.state.numDataBuffers++;var o=0;t.dtype!=="complex64"&&t.dtype!=="string"&&(o=t.size*Zg(t.dtype)),this.state.tensorInfo.set(t.dataId,{backend:n||this.backend,dtype:t.dtype,shape:t.shape,bytes:o,refCount:0}),this.state.numBytes+=o}this.state.tensorInfo.get(t.dataId).refCount++,t instanceof vi||this.track(t)},e.prototype.disposeTensor=function(t){if(this.state.tensorInfo.has(t.dataId)){this.state.numTensors--,t.dtype==="string"&&this.state.numStringTensors--;var n=this.state.tensorInfo.get(t.dataId);n.refCount<=1?(t.dtype!=="complex64"&&(this.state.numBytes-=n.bytes),this.state.numDataBuffers--,n.backend.disposeData(t.dataId),this.state.tensorInfo.delete(t.dataId)):this.state.tensorInfo.get(t.dataId).refCount--}},e.prototype.disposeVariables=function(){for(var t in this.state.registeredVariables){var n=this.state.registeredVariables[t];this.disposeVariable(n)}},e.prototype.disposeVariable=function(t){this.disposeTensor(t),this.state.registeredVariables[t.name]!=null&&delete this.state.registeredVariables[t.name]},e.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.state.numTensors,t.numDataBuffers=this.state.numDataBuffers,t.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(t.unreliable=!0,t.reasons==null&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},e.prototype.profile=function(t){return Q(this,void 0,void 0,function(){var n,r;return J(this,function(o){return this.state.profiling=!0,n=this.state.numBytes,r=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=t(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(i){return i.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-n,this.state.activeProfile.newTensors=this.state.numTensors-r,[2,this.state.activeProfile]})})},e.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&this.state.kernelDepth===0},e.prototype.addTapeNode=function(t,n,r,o,i){var a=this,u={id:this.state.nextTapeNodeId++,kernelName:t,inputs:n,outputs:r,saved:i},s=Yw(t);s!=null&&(o=s.gradFunc),o!=null&&(u.gradient=function(l){return l=l.map(function(c,f){if(c==null){var d=r[f],h=Ta(d.size,d.dtype);return a.makeTensor(h,d.shape,d.dtype)}return c}),o(l.length>1?l:l[0],i)}),this.state.activeTape.push(u)},e.prototype.keep=function(t){return t.kept=!0,t},e.prototype.startTape=function(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++},e.prototype.endTape=function(){this.state.gradientDepth--},e.prototype.startScope=function(t){var n={track:[],name:"unnamed scope",id:this.state.nextScopeId++};t&&(n.name=t),this.state.scopeStack.push(n),this.state.activeScope=n},e.prototype.endScope=function(t){for(var n=this,r=i0(t),o=new Set(r.map(function(s){return s.id})),i=0;i0,function(){return"gradients() received an empty list of xs."}),r!=null&&r.dtype!=="float32")throw new Error("dy must have 'float32' dtype, but has '"+r.dtype+"'");var a=this.scopedRun(function(){return i.startTape()},function(){return i.endTape()},function(){return i.tidy("forward",t)});I(a instanceof Fe,function(){return"The result y returned by f() must be a tensor."});var u=function(s,l,c){for(var f={},d={},h=0;h=0;h--)for(p=(C=s[h]).inputs,y=0;y0)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 s,l,c={};c[a.id]=r??(s=a.shape,l=t0(Z(s),"float32"),A.makeTensor(l,s,"float32")),function(d,h,p){for(var m=function(v){var y=h[v],x=[];if(y.outputs.forEach(function(_){var E=d[_.id];E!=null?x.push(E):x.push(null)}),y.gradient==null)throw new Error("Cannot compute gradient: gradient function not found for "+y.kernelName+".");var w=y.gradient(x),b=function(_){if(!(_ in w))throw new Error("Cannot backprop through input "+_+". Available gradients found: "+Object.keys(w)+".");var E=p(function(){return w[_]()});if(E.dtype!=="float32")throw new Error("Error in gradient for op "+y.kernelName+". The gradient of input "+_+" must have 'float32' dtype, but has '"+E.dtype+"'");var R=y.inputs[_];if(!ot(E.shape,R.shape))throw new Error("Error in gradient for op "+y.kernelName+". The gradient of input '"+_+"' has shape '"+E.shape+"', which does not match the shape of the input '"+R.shape+"'");if(d[R.id]==null)d[R.id]=E;else{var k=d[R.id];d[R.id]=k.add(E),k.dispose()}};for(var C in y.inputs)b(C)},g=h.length-1;g>=0;g--)m(g)}(c,u,function(d){return i.tidy(d)});var f=n.map(function(d){return c[d.id]});return i.state.gradientDepth===0&&(i.state.activeTape.forEach(function(d){for(var h=0,p=d.saved;h"u")throw new Error("Could not find a global object");n=self}Fl=n}return Fl}();if(e._tfengine==null){var t=new Kw(e);e._tfengine=new p2(t)}return function(n){Kg=n}(e._tfengine.ENV),Nn=function(){return e._tfengine},e._tfengine}();function a0(){return typeof window<"u"&&window.document!=null||typeof WorkerGlobalScope<"u"}var Kn=z();Kn.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.")}),Kn.registerFlag("IS_BROWSER",function(){return a0()}),Kn.registerFlag("IS_NODE",function(){return typeof process<"u"&&process.versions!==void 0&&process.versions.node!==void 0}),Kn.registerFlag("IS_CHROME",function(){return typeof navigator<"u"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),Kn.registerFlag("PROD",function(){return!1}),Kn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return Kn.getBool("DEBUG")}),Kn.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),Kn.registerFlag("IS_TEST",function(){return!1});var ga,Vt,zt,Jr={},Ml={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function v2(e,t){Jr[e]=t}function Vn(e){e in Jr||(Jr[e]=function(n){if(n!==1&&n!==2)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var r=function(o){if(typeof OffscreenCanvas<"u"&&o===2)return new OffscreenCanvas(300,150);if(typeof document<"u")return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(n);return r.addEventListener("webglcontextlost",function(o){o.preventDefault(),delete Jr[n]},!1),n===1?r.getContext("webgl",Ml)||r.getContext("experimental-webgl",Ml):r.getContext("webgl2",Ml)}(e));var t=Jr[e];return t.isContextLost()?(delete Jr[e],Vn(e)):(t.disable(t.DEPTH_TEST),t.disable(t.STENCIL_TEST),t.disable(t.BLEND),t.disable(t.DITHER),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SAMPLE_COVERAGE),t.enable(t.SCISSOR_TEST),t.enable(t.CULL_FACE),t.cullFace(t.BACK),Jr[e])}function Ls(e,t){return[t,e]}function Xi(e){var t=Z(e);return tf(Math.ceil(t/4))}function Na(e,t){return[Math.max(1,Math.ceil(t/2)),Math.max(1,Math.ceil(e/2))]}function yd(e,t){var n,r,o,i,a,u,s,l,c,f=e;return z().getNumber("WEBGL_VERSION")===2?(n=f.R32F,r=f.R16F,o=f.RGBA16F,i=f.RGBA32F,a=f.RED,u=4,s=1,l=f.HALF_FLOAT,c=f.FLOAT):(n=e.RGBA,r=e.RGBA,o=e.RGBA,i=f.RGBA,a=e.RGBA,u=4,s=4,l=t!=null?t.HALF_FLOAT_OES:null,c=e.FLOAT),{internalFormatFloat:n,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:o,internalFormatPackedFloat:i,textureFormatFloat:a,downloadTextureFormat:e.RGBA,downloadUnpackNumChannels:u,defaultNumChannels:s,textureTypeHalfFloat:l,textureTypeFloat:c}}function ee(e,t,n){var r=n();return t&&function(o){var i=o.getError();if(i!==o.NO_ERROR)throw new Error("WebGL Error: "+x2(o,i))}(e),r}(function(e){e[e.DENSE=0]="DENSE",e[e.SHARED_BATCH=1]="SHARED_BATCH"})(ga||(ga={})),function(e){e[e.RENDER=0]="RENDER",e[e.UPLOAD=1]="UPLOAD",e[e.PIXELS=2]="PIXELS",e[e.DOWNLOAD=3]="DOWNLOAD"}(Vt||(Vt={})),function(e){e[e.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",e[e.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",e[e.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",e[e.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",e[e.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}(zt||(zt={}));var m2=596e-10,g2=65504;function y2(e){return!!(z().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||e===0||m2=this.shape[r]){var u="Requested out of range element at "+t+". Buffer shape="+this.shape;throw new Error(u)}r++}for(var s=t[t.length-1],l=0;l0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+u+" data ids) after running '"+t+"'")},e.prototype.runKernelFunc=function(t,n,r,o,i,a,u){var s,l=this;a===void 0&&(a=[]),u===void 0&&(u=[]);var c=[],f=this.isTapeOn();o==null&&(o=this.state.activeScope!=null?this.state.activeScope.name:"");var d,h=function(y){f&&(c=y.map(function(x){return l.keep(l.clone(x))}))},p=this.state.numBytes,m=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var g,v=jg(o,this.backendName);return d=v!=null?function(){var y=l.backend.numDataIds();g=v.kernelFunc({inputs:n,attrs:i,backend:l.backend});var x=Array.isArray(g)?g:[g];l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(o,y,x);var w=x.map(function(C){var _=C.dataId,E=C.shape,R=C.dtype;return l.makeTensorFromDataId(_,E,R)}),b=w.filter(function(C,_){return u[_]});return h((a||[]).slice().concat(b)),w}:function(){var y=l.backend.numDataIds();g=l.tidy(function(){return t(l.backend,h)});var x=Array.isArray(g)?g:[g];return l.shouldCheckForMemLeaks()&&l.checkKernelForMemLeak(o,y,x),x},this.scopedRun(function(){return l.state.kernelDepth++},function(){return l.state.kernelDepth--},function(){s=l.ENV.getBool("DEBUG")?l.profiler.profileKernel(o,n,function(){return d()}):d()}),f&&this.addTapeNode(o,n,s,r,c),this.state.profiling&&this.state.activeProfile.kernels.push({name:o,bytesAdded:this.state.numBytes-p,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-m,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(n).map(function(y){return n[y].shape}),outputShapes:s.map(function(y){return y.shape})}),Array.isArray(g)?s:s[0]},e.prototype.makeTensor=function(t,n,r,o){if(t==null)throw new Error("Values passed to engine.makeTensor() are null");r=r||"float32",o=o||this.backend;var i=t;r==="string"&&vd(t[0])&&(i=t.map(function(c){return r2(c)}));var a=o.write(i,n,r),u=new Fe(n,r,a,this.nextTensorId());if(this.incRef(u,o),r==="string"){var s=this.state.tensorInfo.get(a),l=e2(i);this.state.numBytes+=l-s.bytes,s.bytes=l}return u},e.prototype.makeTensorFromDataId=function(t,n,r,o){var i=new Fe(n,r=r||"float32",t,this.nextTensorId());return this.incRef(i,o),i},e.prototype.makeVariable=function(t,n,r,o){n===void 0&&(n=!0),r=r||this.nextVariableId().toString(),o!=null&&o!==t.dtype&&(t=t.asType(o));var i=new hi(t,n,r,this.nextTensorId());if(this.state.registeredVariables[i.name]!=null)throw new Error("Variable with name "+i.name+" was already registered");return this.state.registeredVariables[i.name]=i,this.incRef(i,this.backend),i},e.prototype.incRef=function(t,n){var r=this.state.tensorInfo.has(t.dataId)?this.state.tensorInfo.get(t.dataId).refCount:0;if(this.state.numTensors++,t.dtype==="string"&&this.state.numStringTensors++,r===0){this.state.numDataBuffers++;var o=0;t.dtype!=="complex64"&&t.dtype!=="string"&&(o=t.size*Xg(t.dtype)),this.state.tensorInfo.set(t.dataId,{backend:n||this.backend,dtype:t.dtype,shape:t.shape,bytes:o,refCount:0}),this.state.numBytes+=o}this.state.tensorInfo.get(t.dataId).refCount++,t instanceof hi||this.track(t)},e.prototype.disposeTensor=function(t){if(this.state.tensorInfo.has(t.dataId)){this.state.numTensors--,t.dtype==="string"&&this.state.numStringTensors--;var n=this.state.tensorInfo.get(t.dataId);n.refCount<=1?(t.dtype!=="complex64"&&(this.state.numBytes-=n.bytes),this.state.numDataBuffers--,n.backend.disposeData(t.dataId),this.state.tensorInfo.delete(t.dataId)):this.state.tensorInfo.get(t.dataId).refCount--}},e.prototype.disposeVariables=function(){for(var t in this.state.registeredVariables){var n=this.state.registeredVariables[t];this.disposeVariable(n)}},e.prototype.disposeVariable=function(t){this.disposeTensor(t),this.state.registeredVariables[t.name]!=null&&delete this.state.registeredVariables[t.name]},e.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.state.numTensors,t.numDataBuffers=this.state.numDataBuffers,t.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(t.unreliable=!0,t.reasons==null&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},e.prototype.profile=function(t){return Q(this,void 0,void 0,function(){var n,r;return J(this,function(o){return this.state.profiling=!0,n=this.state.numBytes,r=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=t(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(i){return i.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-n,this.state.activeProfile.newTensors=this.state.numTensors-r,[2,this.state.activeProfile]})})},e.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&this.state.kernelDepth===0},e.prototype.addTapeNode=function(t,n,r,o,i){var a=this,u={id:this.state.nextTapeNodeId++,kernelName:t,inputs:n,outputs:r,saved:i},s=Gw(t);s!=null&&(o=s.gradFunc),o!=null&&(u.gradient=function(l){return l=l.map(function(c,f){if(c==null){var d=r[f],h=Ia(d.size,d.dtype);return a.makeTensor(h,d.shape,d.dtype)}return c}),o(l.length>1?l:l[0],i)}),this.state.activeTape.push(u)},e.prototype.keep=function(t){return t.kept=!0,t},e.prototype.startTape=function(){this.state.gradientDepth===0&&(this.state.activeTape=[]),this.state.gradientDepth++},e.prototype.endTape=function(){this.state.gradientDepth--},e.prototype.startScope=function(t){var n={track:[],name:"unnamed scope",id:this.state.nextScopeId++};t&&(n.name=t),this.state.scopeStack.push(n),this.state.activeScope=n},e.prototype.endScope=function(t){for(var n=this,r=t0(t),o=new Set(r.map(function(s){return s.id})),i=0;i0,function(){return"gradients() received an empty list of xs."}),r!=null&&r.dtype!=="float32")throw new Error("dy must have 'float32' dtype, but has '"+r.dtype+"'");var a=this.scopedRun(function(){return i.startTape()},function(){return i.endTape()},function(){return i.tidy("forward",t)});I(a instanceof Fe,function(){return"The result y returned by f() must be a tensor."});var u=function(s,l,c){for(var f={},d={},h=0;h=0;h--)for(p=(C=s[h]).inputs,y=0;y0)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 s,l,c={};c[a.id]=r??(s=a.shape,l=Qg(Z(s),"float32"),A.makeTensor(l,s,"float32")),function(d,h,p){for(var m=function(v){var y=h[v],x=[];if(y.outputs.forEach(function(_){var E=d[_.id];E!=null?x.push(E):x.push(null)}),y.gradient==null)throw new Error("Cannot compute gradient: gradient function not found for "+y.kernelName+".");var w=y.gradient(x),b=function(_){if(!(_ in w))throw new Error("Cannot backprop through input "+_+". Available gradients found: "+Object.keys(w)+".");var E=p(function(){return w[_]()});if(E.dtype!=="float32")throw new Error("Error in gradient for op "+y.kernelName+". The gradient of input "+_+" must have 'float32' dtype, but has '"+E.dtype+"'");var R=y.inputs[_];if(!ot(E.shape,R.shape))throw new Error("Error in gradient for op "+y.kernelName+". The gradient of input '"+_+"' has shape '"+E.shape+"', which does not match the shape of the input '"+R.shape+"'");if(d[R.id]==null)d[R.id]=E;else{var k=d[R.id];d[R.id]=k.add(E),k.dispose()}};for(var C in y.inputs)b(C)},g=h.length-1;g>=0;g--)m(g)}(c,u,function(d){return i.tidy(d)});var f=n.map(function(d){return c[d.id]});return i.state.gradientDepth===0&&(i.state.activeTape.forEach(function(d){for(var h=0,p=d.saved;h"u")throw new Error("Could not find a global object");n=self}Al=n}return Al}();if(e._tfengine==null){var t=new Hw(e);e._tfengine=new c2(t)}return function(n){Hg=n}(e._tfengine.ENV),Tn=function(){return e._tfengine},e._tfengine}();function n0(){return typeof window<"u"&&window.document!=null||typeof WorkerGlobalScope<"u"}var Gn=z();Gn.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.")}),Gn.registerFlag("IS_BROWSER",function(){return n0()}),Gn.registerFlag("IS_NODE",function(){return typeof process<"u"&&process.versions!==void 0&&process.versions.node!==void 0}),Gn.registerFlag("IS_CHROME",function(){return typeof navigator<"u"&&navigator!=null&&navigator.userAgent!=null&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),Gn.registerFlag("PROD",function(){return!1}),Gn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return Gn.getBool("DEBUG")}),Gn.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),Gn.registerFlag("IS_TEST",function(){return!1});var va,Vt,zt,Yr={},Pl={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function f2(e,t){Yr[e]=t}function zn(e){e in Yr||(Yr[e]=function(n){if(n!==1&&n!==2)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var r=function(o){if(typeof OffscreenCanvas<"u"&&o===2)return new OffscreenCanvas(300,150);if(typeof document<"u")return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(n);return r.addEventListener("webglcontextlost",function(o){o.preventDefault(),delete Yr[n]},!1),n===1?r.getContext("webgl",Pl)||r.getContext("experimental-webgl",Pl):r.getContext("webgl2",Pl)}(e));var t=Yr[e];return t.isContextLost()?(delete Yr[e],zn(e)):(t.disable(t.DEPTH_TEST),t.disable(t.STENCIL_TEST),t.disable(t.BLEND),t.disable(t.DITHER),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SAMPLE_COVERAGE),t.enable(t.SCISSOR_TEST),t.enable(t.CULL_FACE),t.cullFace(t.BACK),Yr[e])}function Os(e,t){return[t,e]}function qi(e){var t=Z(e);return Zc(Math.ceil(t/4))}function Da(e,t){return[Math.max(1,Math.ceil(t/2)),Math.max(1,Math.ceil(e/2))]}function md(e,t){var n,r,o,i,a,u,s,l,c,f=e;return z().getNumber("WEBGL_VERSION")===2?(n=f.R32F,r=f.R16F,o=f.RGBA16F,i=f.RGBA32F,a=f.RED,u=4,s=1,l=f.HALF_FLOAT,c=f.FLOAT):(n=e.RGBA,r=e.RGBA,o=e.RGBA,i=f.RGBA,a=e.RGBA,u=4,s=4,l=t!=null?t.HALF_FLOAT_OES:null,c=e.FLOAT),{internalFormatFloat:n,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:o,internalFormatPackedFloat:i,textureFormatFloat:a,downloadTextureFormat:e.RGBA,downloadUnpackNumChannels:u,defaultNumChannels:s,textureTypeHalfFloat:l,textureTypeFloat:c}}function ee(e,t,n){var r=n();return t&&function(o){var i=o.getError();if(i!==o.NO_ERROR)throw new Error("WebGL Error: "+v2(o,i))}(e),r}(function(e){e[e.DENSE=0]="DENSE",e[e.SHARED_BATCH=1]="SHARED_BATCH"})(va||(va={})),function(e){e[e.RENDER=0]="RENDER",e[e.UPLOAD=1]="UPLOAD",e[e.PIXELS=2]="PIXELS",e[e.DOWNLOAD=3]="DOWNLOAD"}(Vt||(Vt={})),function(e){e[e.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",e[e.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",e[e.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",e[e.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",e[e.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}(zt||(zt={}));var d2=596e-10,h2=65504;function p2(e){return!!(z().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||e===0||d2n||t>n)throw r="["+e+"x"+t+"]",new Error("Requested texture size "+r+" greater than WebGL maximum on this browser / GPU "+("["+n+"x"+n+"]")+".")}function D2(e,t){return sr(e,t,function(){return e.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function Wp(e,t,n,r,o,i,a,u){var s=e.getAttribLocation(n,r);return s!==-1&&(ee(e,t,function(){return e.bindBuffer(e.ARRAY_BUFFER,o)}),ee(e,t,function(){return e.vertexAttribPointer(s,i,e.FLOAT,!1,a,u)}),ee(e,t,function(){return e.enableVertexAttribArray(s)}),!0)}function T2(e,t,n,r){M2(e,r),ee(e,t,function(){return e.activeTexture(e.TEXTURE0+r)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)})}function N2(e,t,n,r){return sr(e,t,function(){return e.getUniformLocation(n,r)},'uniform "'+r+'" not present in program.')}function A2(e,t,n){return e.getUniformLocation(t,n)}function P2(e,t,n,r,o,i){ee(e,t,function(){return T2(e,t,r,i)}),ee(e,t,function(){return e.uniform1i(o,i)})}function Wl(e,t,n,r){ee(e,t,function(){return e.bindFramebuffer(e.FRAMEBUFFER,r)}),ee(e,t,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0)})}function zp(e,t,n){ee(e,t,function(){return e.bindFramebuffer(e.FRAMEBUFFER,n)}),ee(e,t,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0)})}function ru(e){var t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+F2(e,t))}function F2(e,t){switch(t){case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case e.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+t}}function sr(e,t,n,r){var o=ee(e,t,function(){return n()});if(o==null)throw new Error(r);return o}function M2(e,t){var n=e.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,r=t+e.TEXTURE0;if(rn)throw new Error("textureUnit must be in "+("[gl.TEXTURE0, gl.TEXTURE"+n+"]")+".")}function rs(e,t){return t===void 0&&(t=2),Z(e.slice(0,e.length-t))}function os(e){if(e.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[e.length>1?e[e.length-2]:1,e[e.length-1]]}function zl(e){var t=[1,1,1];return e.length===0||e.length===1&&e[0]===1||(t=[rs(e)].concat(os(e))),t}function O2(e,t){var n;t===void 0&&(t=!1);var r=z().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t&&(r*=2,(e=e.map(function(l,c){return c>=e.length-2?Jg(e[c]):e[c]})).length===1&&(e=[2,e[0]])),e.length!==2){var o=eo(e);e=o.newShape}var i=Z(e);if(e.length<=1&&i<=r)return[1,i];if(e.length===2&&e[0]<=r&&e[1]<=r)return e;if(e.length===3&&e[0]*e[1]<=r&&e[2]<=r)return[e[0]*e[1],e[2]];if(e.length===3&&e[0]<=r&&e[1]*e[2]<=r)return[e[0],e[1]*e[2]];if(e.length===4&&e[0]*e[1]*e[2]<=r&&e[3]<=r)return[e[0]*e[1]*e[2],e[3]];if(e.length===4&&e[0]<=r&&e[1]*e[2]*e[3]<=r)return[e[0],e[1]*e[2]*e[3]];if(t){var a=rs(e),u=2,s=2;return e.length&&(u=(n=os(e))[0],s=n[1]),tf(i=a*(u/2)*(s/2)).map(function(l){return 2*l})}return tf(i)}function ou(e){return e%2==0}function iu(e,t){if(ot(e=e.slice(-2),t=t.slice(-2))||!e.length||!t.length||e[0]===0||e[1]===0||t[0]===0||t[1]===0)return!0;if(e.length!==t.length){var n=e.slice(-1)[0],r=t.slice(-1)[0];if(n===r||ou(n)&&ou(r)&&(e[0]===1||t[0]===1))return!0}return e[1]===t[1]&&ou(e[0])&&ou(t[0])}function B2(e){if(Ol==null){var t=Vn(e);Ol=t.getParameter(t.MAX_TEXTURE_SIZE)}return Ol}function L2(e){if(Bl==null){var t=Vn(e);Bl=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,Bl)}function W2(e){if(e===0)return 0;var t=Vn(e);return nn(t,"EXT_disjoint_timer_query_webgl2")&&e===2?2:nn(t,"EXT_disjoint_timer_query")?1:0}function nn(e,t){return e.getExtension(t)!=null}function Up(e){try{if(Vn(e)!=null)return!0}catch{return!1}return!1}function z2(e){if(e===0)return!1;var t=Vn(e);if(e===1){if(!nn(t,"OES_texture_float"))return!1}else if(!nn(t,"EXT_color_buffer_float"))return!1;return lf(t)}function U2(e){if(e===0)return!1;var t=Vn(e);if(e!==1){if(nn(t,"EXT_color_buffer_float"))return lf(t);if(nn(t,"EXT_color_buffer_half_float")){var n=t.getExtension("EXT_color_buffer_half_float");return function(r,o){var i=yd(r,o),a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texImage2D(r.TEXTURE_2D,0,i.internalFormatHalfFloat,1,1,0,i.textureFormatFloat,i.textureTypeHalfFloat,null);var u=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,u),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0);var s=r.checkFramebufferStatus(r.FRAMEBUFFER)===r.FRAMEBUFFER_COMPLETE;return r.bindTexture(r.TEXTURE_2D,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.deleteTexture(a),r.deleteFramebuffer(u),s}(t,n)}return!1}return!!nn(t,"OES_texture_float")&&!!nn(t,"WEBGL_color_buffer_float")&&lf(t)}function lf(e){var t=yd(e),n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,t.internalFormatFloat,1,1,0,t.textureFormatFloat,t.textureTypeFloat,null);var r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0);var o=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;return e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(n),e.deleteFramebuffer(r),o}function V2(e){return e===2&&Vn(e).fenceSync!=null}var ie=z();function u0(e){z().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function X(e,t){return A.tidy(e,t)}function Ft(e){i0(e).forEach(function(t){return t.dispose()})}function $2(e){return A.keep(e)}function is(){for(var e=[],t=0;t0,function(){return"Element arr["+u.join("][")+"] should be a primitive, but is an array of "+i.length+" elements"}),I(i.length===a[0],function(){return"Element arr["+u.join("][")+"] should have "+a[0]+" elements, but has "+i.length+" elements"});for(var s=a.slice(1),l=0;l=0&&(o=r),Vp(r,o,t,n),e==null||!On(e)&&!Array.isArray(e)&&typeof e!="number"&&typeof e!="boolean"&&typeof e!="string"){var i=e==null?"null":e.constructor.name;throw new Error("Argument '"+t+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+i+"'")}var a=Hr(e,o);On(e)||Array.isArray(e)||(e=[e]);var u=o!=="string"?e0(e,o,z().getBool("DEBUG")):pi(e,[],!0);return A.makeTensor(u,a,o)}function as(e,t,n,r){if(r===void 0&&(r="numeric"),!Array.isArray(e))throw new Error("Argument "+t+" passed to "+n+" must be a `Tensor[]` or `TensorLike[]`");return e.map(function(o,i){return S(o,t+"["+i+"]",n)},r)}function s0(e,t){for(var n=0;n=0&&t0}),ie.registerFlag("WEBGL_VERSION",function(){return Up(2)?2:Up(1)?1:0}),ie.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return ie.get("WEBGL_VERSION")===2}),ie.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),ie.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),ie.registerFlag("WEBGL_PACK",function(){return ie.getBool("HAS_WEBGL")}),ie.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_CLIP",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),ie.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_REDUCE",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_LAZILY_UNPACK",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_CONV_IM2COL",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return B2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return L2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var e=ie.getNumber("WEBGL_VERSION");return e===0?0:W2(e)}),ie.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return ie.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(e=navigator.userAgent||navigator.vendor||window.opera,!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4))));var e}),ie.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return z2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!ie.getBool("WEBGL_FORCE_F16_TEXTURES")&&ie.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),ie.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return U2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return V2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return ie.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),o0=u0;var ut=D({complex_:function(e,t){var n=S(e,"real","complex"),r=S(t,"imag","complex");return Ce(n.shape,r.shape,"real and imag shapes, "+n.shape+" and "+r.shape+", must match in call to tf.complex()."),A.runKernelFunc(function(o){return o.complex(n,r)},{$real:n,$imag:r})}}),en=D({real_:function(e){var t=S(e,"input","real");return A.runKernelFunc(function(n){return n.real(t)},{$input:t})}}),An=D({imag_:function(e){var t=S(e,"input","imag");return A.runKernelFunc(function(n){return n.imag(t)},{$input:t})}});function lt(e,t,n){return jr(e,t,Hr(e,n),n)}function jr(e,t,n,r){if(r==null&&(r=Da(e)),r==="complex64")throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!On(e)&&!Array.isArray(e)&&typeof e!="number"&&typeof e!="boolean"&&typeof e!="string")throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(t!=null){n0(t);var o=Z(t),i=Z(n);I(o===i,function(){return"Based on the provided shape, ["+t+"], the tensor should have "+o+" values but has "+i});for(var a=0;a1)return Ie([0],r);var o=Ta(Math.abs(Math.ceil((t-e)/n)),r);t=1,function(){return"Pass at least one tensor to concat"});var n=as(e,"tensors","concat");n[0].dtype==="complex64"&&n.forEach(function(u){if(u.dtype!=="complex64")throw new Error(`Cannot concatenate complex64 tensors with a tensor - with dtype `+u.dtype+". ")}),t=et(t,n[0].shape)[0];var r=mi(n.map(function(u){return u.shape}),t);if(Z(r)===0)return lt([],r);if((n=n.filter(function(u){return u.size>0})).length===1)return n[0];var o=n.map(function(u){return u.shape});j2(o,t);var i=n,a={axis:t};return A.runKernelFunc(function(u){return u.concat(n,t)},i,function(u){var s=o.map(function(l){return l[t]});return bd(u,s,t).map(function(l){return function(){return l}})},"Concat",a)}}),Y2=D({concat1d_:function(e){return Ye(e,0)}}),Q2=D({concat2d_:function(e,t){return Ye(e,t)}}),J2=D({concat3d_:function(e,t){return Ye(e,t)}}),Z2=D({concat4d_:function(e,t){return Ye(e,t)}}),bd=D({split_:function(e,t,n){n===void 0&&(n=0);var r,o=S(e,"x","split");return n=et(n,o.shape)[0],typeof t=="number"?(I(o.shape[n]%t==0,function(){return"Number of splits must evenly divide the axis."}),r=new Array(t).fill(o.shape[n]/t)):(I(o.shape[n]===t.reduce(function(i,a){return i+a}),function(){return"The sum of sizes must match the size of the axis dimension."}),r=t),A.runKernelFunc(function(i){return i.split(o,r,n)},{$x:o},function(i){return{$x:function(){return Ye(i,n)}}})}});function xo(e,t){return e(t={exports:{}},t.exports),t.exports}var eb=xo(function(e){(function(t,n,r){function o(u){var s,l=this,c=(s=4022871197,function(f){f=f.toString();for(var d=0;d>>0,s=(h*=s)>>>0,s+=4294967296*(h-=s)}return 23283064365386963e-26*(s>>>0)});l.next=function(){var f=2091639*l.s0+23283064365386963e-26*l.c;return l.s0=l.s1,l.s1=l.s2,l.s2=f-(l.c=0|f)},l.c=1,l.s0=c(" "),l.s1=c(" "),l.s2=c(" "),l.s0-=c(u),l.s0<0&&(l.s0+=1),l.s1-=c(u),l.s1<0&&(l.s1+=1),l.s2-=c(u),l.s2<0&&(l.s2+=1),c=null}function i(u,s){return s.c=u.c,s.s0=u.s0,s.s1=u.s1,s.s2=u.s2,s}function a(u,s){var l=new o(u),c=s&&s.state,f=l.next;return f.int32=function(){return 4294967296*l.next()|0},f.double=function(){return f()+11102230246251565e-32*(2097152*f()|0)},f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.alea=a})(0,e,!1)}),tb=xo(function(e){(function(t,n,r){function o(u){var s=this,l="";s.x=0,s.y=0,s.z=0,s.w=0,s.next=function(){var f=s.x^s.x<<11;return s.x=s.y,s.y=s.z,s.z=s.w,s.w^=s.w>>>19^f^f>>>8},u===(0|u)?s.x=u:l+=u;for(var c=0;c>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xor128=a})(0,e,!1)}),nb=xo(function(e){(function(t,n,r){function o(u){var s=this,l="";s.next=function(){var f=s.x^s.x>>>2;return s.x=s.y,s.y=s.z,s.z=s.w,s.w=s.v,(s.d=s.d+362437|0)+(s.v=s.v^s.v<<4^f^f<<1)|0},s.x=0,s.y=0,s.z=0,s.w=0,s.v=0,u===(0|u)?s.x=u:l+=u;for(var c=0;c>>4),s.next()}function i(u,s){return s.x=u.x,s.y=u.y,s.z=u.z,s.w=u.w,s.v=u.v,s.d=u.d,s}function a(u,s){var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xorwow=a})(0,e,!1)}),rb=xo(function(e){(function(t,n,r){function o(u){var s=this;s.next=function(){var l,c,f=s.x,d=s.i;return l=f[d],c=(l^=l>>>7)^l<<24,c^=(l=f[d+1&7])^l>>>10,c^=(l=f[d+3&7])^l>>>3,c^=(l=f[d+4&7])^l<<7,l=f[d+7&7],c^=(l^=l<<13)^l<<9,f[d]=c,s.i=d+1&7,c},function(l,c){var f,d=[];if(c===(0|c))d[0]=c;else for(c=""+c,f=0;f0;--f)l.next()}(s,u)}function i(u,s){return s.x=u.x.slice(),s.i=u.i,s}function a(u,s){u==null&&(u=+new Date);var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(c.x&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xorshift7=a})(0,e,!1)}),ob=xo(function(e){(function(t,n,r){function o(u){var s=this;s.next=function(){var l,c,f=s.w,d=s.X,h=s.i;return s.w=f=f+1640531527|0,c=d[h+34&127],l=d[h=h+1&127],c^=c<<13,l^=l<<17,c^=c>>>15,l^=l>>>12,c=d[h]=c^l,s.i=h,c+(f^f>>>16)|0},function(l,c){var f,d,h,p,m,g=[],v=128;for(c===(0|c)?(d=c,c=null):(c+="\0",d=0,v=Math.max(v,c.length)),h=0,p=-32;p>>15,d^=d<<4,d^=d>>>13,p>=0&&(m=m+1640531527|0,h=(f=g[127&p]^=d+m)==0?h+1:0);for(h>=128&&(g[127&(c&&c.length||0)]=-1),h=127,p=512;p>0;--p)d=g[h+34&127],f=g[h=h+1&127],d^=d<<13,f^=f<<17,d^=d>>>15,f^=f>>>12,g[h]=d^f;l.w=m,l.X=g,l.i=h}(s,u)}function i(u,s){return s.i=u.i,s.w=u.w,s.X=u.X.slice(),s}function a(u,s){u==null&&(u=+new Date);var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(c.X&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xor4096=a})(0,e,!1)}),ib=xo(function(e){(function(t,n,r){function o(u){var s=this,l="";s.next=function(){var f=s.b,d=s.c,h=s.d,p=s.a;return f=f<<25^f>>>7^d,d=d-h|0,h=h<<24^h>>>8^p,p=p-f|0,s.b=f=f<<20^f>>>12^d,s.c=d=d-h|0,s.d=h<<16^d>>>16^p,s.a=p-f|0},s.a=0,s.b=0,s.c=-1640531527,s.d=1367130551,u===Math.floor(u)?(s.a=u/4294967296|0,s.b=0|u):l+=u;for(var c=0;c>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.tychei=a})(0,e,!1)}),Zr=xo(function(e){(function(t,n){var r,o=this,i=256,a=6,u="random",s=n.pow(i,a),l=n.pow(2,52),c=2*l,f=i-1;function d(v,y,x){var w=[],b=m(function E(R,k){var T,N=[],W=typeof R;if(k&&W=="object")for(T in R)try{N.push(E(R[T],k-1))}catch{}return N.length?N:W=="string"?R:R+"\0"}((y=y==1?{entropy:!0}:y||{}).entropy?[v,g(t)]:v??function(){try{var E;return r&&(E=r.randomBytes)?E=E(i):(E=new Uint8Array(i),(o.crypto||o.msCrypto).getRandomValues(E)),g(E)}catch{var R=o.navigator,k=R&&R.plugins;return[+new Date,o,k,o.screen,g(t)]}}(),3),w),C=new h(w),_=function(){for(var E=C.g(a),R=s,k=0;E=c;)E/=2,R/=2,k>>>=1;return(E+k)/R};return _.int32=function(){return 0|C.g(4)},_.quick=function(){return C.g(4)/4294967296},_.double=_,m(g(C.S),t),(y.pass||x||function(E,R,k,T){return T&&(T.S&&p(T,C),E.state=function(){return p(C,{})}),k?(n[u]=E,R):E})(_,b,"global"in y?y.global:this==n,y.state)}function h(v){var y,x=v.length,w=this,b=0,C=w.i=w.j=0,_=w.S=[];for(x||(v=[x++]);b=1||u===0);var s=Math.sqrt(-2*Math.log(u)/u);n=this.mean+this.stdDev*i*s,r=this.mean+this.stdDev*a*s,this.truncated&&!this.isValidTruncated(n)||(o=!0)}return this.truncated&&!this.isValidTruncated(r)||(this.nextVal=this.convertValue(r)),this.convertValue(n)},e.prototype.convertValue=function(t){return this.dtype==null||this.dtype==="float32"?t:Math.round(t)},e.prototype.isValidTruncated=function(t){return t<=this.upper&&t>=this.lower},e}(),ab=function(){function e(t,n,r,o){this.alpha=t,this.beta=1/n,this.dtype=r;var i=o||Math.random();this.randu=Ws(i.toString()),this.randn=new Cd(0,1,r,!1,this.randu()),this.d=t<1?t+2/3:t-1/3,this.c=1/Math.sqrt(9*this.d)}return e.prototype.nextValue=function(){for(var t,n,r,o,i,a;;){do o=this.randn.nextValue(),a=1+this.c*o;while(a<=0);if(a*=a*a,n=1-.331*(t=o*o)*t,r=.5*t+this.d*(1-a+Math.log(a)),(i=this.randu())=1+t.length,function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+t.length}),I(n.length===t.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+t.length}),I(r.shape[0]%o==0,function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+t.join(" * ")+" === "+o}),A.runKernelFunc(function(i){return i.batchToSpaceND(r,t,n)},{$x:r},function(i){return{$x:function(){return i.spaceToBatchND(t,n)}}})}}),lb=D({broadcastTo_:function(e,t){var n=S(e,"broadcastTo","x"),r=n.shape;if(t.some(function(s){return!(s>0)||s%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+t+"].");if(t.lengthn.rank){for(var o=n.shape.slice();o.length=0;a--)if(n.shape[a]===t[a])i[a]=1;else if(n.shape[a]!==1)throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+t+"].");var u=i.map(function(s,l){return s>1?l:-1}).filter(function(s){return s>=0});return u.length===0?n.clone():A.runKernelFunc(function(s){return s.tile(n,i)},{input:n},function(s){return{input:function(){return s.sum(u,!0)}}})}}),cb=D({cast_:function(e,t){var n=S(e,"x","cast");if(!n2(t))throw new Error("Failed to cast to unknown dtype "+t);if(t==="string"&&n.dtype!=="string"||t!=="string"&&n.dtype==="string")throw new Error("Only strings can be casted to strings");var r={dtype:t};return A.runKernelFunc(function(o){return o.cast(n,t)},{x:n},function(o){return{x:function(){return o.clone()}}},"Cast",r)}}),fb=D({clone_:function(e){var t=S(e,"x","clone",null);return A.runKernelFunc(function(){return A.makeTensorFromDataId(t.dataId,t.shape,t.dtype)},{$x:t},function(n){return{$x:function(){return n.toFloat()}}})}}),db=D({cumsum_:function(e,t,n,r){t===void 0&&(t=0),n===void 0&&(n=!1),r===void 0&&(r=!1);var o=S(e,"x","cumsum"),i=$n([t|=0],o.rank),a=o;i!=null&&(a=o.transpose(i));var u=Hn(1,o.rank)[0],s=A.runKernelFunc(function(l){return l.cumsum(a,u,n,r)},{permutedX:a},function(l){return{permutedX:function(){return l.cumsum(t,n,!r)}}});return i!=null&&(s=s.transpose(i)),s}}),hb=D({depthToSpace_:function(e,t,n){n===void 0&&(n="NHWC");var r=S(e,"x","depthToSpace"),o=n==="NHWC"?r.shape[1]:r.shape[2],i=n==="NHWC"?r.shape[2]:r.shape[3],a=n==="NHWC"?r.shape[3]:r.shape[1];return I(o*t>=0,function(){return`Negative dimension size caused by overflow when multiplying +`)[0]),console.log("%c "+Jo(p[0],f),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(m.join(` +`))}(n,e.getShaderInfoLog(r)),new Error("Failed to compile fragment shader.");return r}var Fl,Ml,y2=/ERROR: [0-9]+:([0-9]+):/g;function x2(e,t){return ur(e,t,function(){return e.createProgram()},"Unable to create WebGLProgram.")}function w2(e,t,n){if(ee(e,t,function(){return e.linkProgram(n)}),e.getProgramParameter(n,e.LINK_STATUS)===!1)throw console.log(e.getProgramInfoLog(n)),new Error("Failed to link vertex and fragment shaders.")}function Ol(e,t,n){if(ee(e,t,function(){return e.validateProgram(n)}),e.getProgramParameter(n,e.VALIDATE_STATUS)===!1)throw console.log(e.getProgramInfoLog(n)),new Error("Shader program validation failed.")}function b2(e,t,n){var r=ur(e,t,function(){return e.createBuffer()},"Unable to create WebGLBuffer");return ee(e,t,function(){return e.bindBuffer(e.ARRAY_BUFFER,r)}),ee(e,t,function(){return e.bufferData(e.ARRAY_BUFFER,n,e.STATIC_DRAW)}),r}function C2(e,t,n){var r=ur(e,t,function(){return e.createBuffer()},"Unable to create WebGLBuffer");return ee(e,t,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r)}),ee(e,t,function(){return e.bufferData(e.ELEMENT_ARRAY_BUFFER,n,e.STATIC_DRAW)}),r}function _2(e,t){return ur(e,t,function(){return e.createTexture()},"Unable to create WebGLTexture.")}function E2(e,t){var n=z().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(e<=0||t<=0){var r="["+e+"x"+t+"]";throw new Error("Requested texture size "+r+" is invalid.")}if(e>n||t>n)throw r="["+e+"x"+t+"]",new Error("Requested texture size "+r+" greater than WebGL maximum on this browser / GPU "+("["+n+"x"+n+"]")+".")}function S2(e,t){return ur(e,t,function(){return e.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function Fp(e,t,n,r,o,i,a,u){var s=e.getAttribLocation(n,r);return s!==-1&&(ee(e,t,function(){return e.bindBuffer(e.ARRAY_BUFFER,o)}),ee(e,t,function(){return e.vertexAttribPointer(s,i,e.FLOAT,!1,a,u)}),ee(e,t,function(){return e.enableVertexAttribArray(s)}),!0)}function k2(e,t,n,r){N2(e,r),ee(e,t,function(){return e.activeTexture(e.TEXTURE0+r)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)})}function R2(e,t,n,r){return ur(e,t,function(){return e.getUniformLocation(n,r)},'uniform "'+r+'" not present in program.')}function I2(e,t,n){return e.getUniformLocation(t,n)}function D2(e,t,n,r,o,i){ee(e,t,function(){return k2(e,t,r,i)}),ee(e,t,function(){return e.uniform1i(o,i)})}function Bl(e,t,n,r){ee(e,t,function(){return e.bindFramebuffer(e.FRAMEBUFFER,r)}),ee(e,t,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0)})}function Mp(e,t,n){ee(e,t,function(){return e.bindFramebuffer(e.FRAMEBUFFER,n)}),ee(e,t,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0)})}function tu(e){var t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+T2(e,t))}function T2(e,t){switch(t){case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case e.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+t}}function ur(e,t,n,r){var o=ee(e,t,function(){return n()});if(o==null)throw new Error(r);return o}function N2(e,t){var n=e.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,r=t+e.TEXTURE0;if(rn)throw new Error("textureUnit must be in "+("[gl.TEXTURE0, gl.TEXTURE"+n+"]")+".")}function es(e,t){return t===void 0&&(t=2),Z(e.slice(0,e.length-t))}function ts(e){if(e.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[e.length>1?e[e.length-2]:1,e[e.length-1]]}function Ll(e){var t=[1,1,1];return e.length===0||e.length===1&&e[0]===1||(t=[es(e)].concat(ts(e))),t}function A2(e,t){var n;t===void 0&&(t=!1);var r=z().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t&&(r*=2,(e=e.map(function(l,c){return c>=e.length-2?Kg(e[c]):e[c]})).length===1&&(e=[2,e[0]])),e.length!==2){var o=Jr(e);e=o.newShape}var i=Z(e);if(e.length<=1&&i<=r)return[1,i];if(e.length===2&&e[0]<=r&&e[1]<=r)return e;if(e.length===3&&e[0]*e[1]<=r&&e[2]<=r)return[e[0]*e[1],e[2]];if(e.length===3&&e[0]<=r&&e[1]*e[2]<=r)return[e[0],e[1]*e[2]];if(e.length===4&&e[0]*e[1]*e[2]<=r&&e[3]<=r)return[e[0]*e[1]*e[2],e[3]];if(e.length===4&&e[0]<=r&&e[1]*e[2]*e[3]<=r)return[e[0],e[1]*e[2]*e[3]];if(t){var a=es(e),u=2,s=2;return e.length&&(u=(n=ts(e))[0],s=n[1]),Zc(i=a*(u/2)*(s/2)).map(function(l){return 2*l})}return Zc(i)}function nu(e){return e%2==0}function ru(e,t){if(ot(e=e.slice(-2),t=t.slice(-2))||!e.length||!t.length||e[0]===0||e[1]===0||t[0]===0||t[1]===0)return!0;if(e.length!==t.length){var n=e.slice(-1)[0],r=t.slice(-1)[0];if(n===r||nu(n)&&nu(r)&&(e[0]===1||t[0]===1))return!0}return e[1]===t[1]&&nu(e[0])&&nu(t[0])}function P2(e){if(Fl==null){var t=zn(e);Fl=t.getParameter(t.MAX_TEXTURE_SIZE)}return Fl}function F2(e){if(Ml==null){var t=zn(e);Ml=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,Ml)}function M2(e){if(e===0)return 0;var t=zn(e);return nn(t,"EXT_disjoint_timer_query_webgl2")&&e===2?2:nn(t,"EXT_disjoint_timer_query")?1:0}function nn(e,t){return e.getExtension(t)!=null}function Op(e){try{if(zn(e)!=null)return!0}catch{return!1}return!1}function O2(e){if(e===0)return!1;var t=zn(e);if(e===1){if(!nn(t,"OES_texture_float"))return!1}else if(!nn(t,"EXT_color_buffer_float"))return!1;return uf(t)}function B2(e){if(e===0)return!1;var t=zn(e);if(e!==1){if(nn(t,"EXT_color_buffer_float"))return uf(t);if(nn(t,"EXT_color_buffer_half_float")){var n=t.getExtension("EXT_color_buffer_half_float");return function(r,o){var i=md(r,o),a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texImage2D(r.TEXTURE_2D,0,i.internalFormatHalfFloat,1,1,0,i.textureFormatFloat,i.textureTypeHalfFloat,null);var u=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,u),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0);var s=r.checkFramebufferStatus(r.FRAMEBUFFER)===r.FRAMEBUFFER_COMPLETE;return r.bindTexture(r.TEXTURE_2D,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.deleteTexture(a),r.deleteFramebuffer(u),s}(t,n)}return!1}return!!nn(t,"OES_texture_float")&&!!nn(t,"WEBGL_color_buffer_float")&&uf(t)}function uf(e){var t=md(e),n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,t.internalFormatFloat,1,1,0,t.textureFormatFloat,t.textureTypeFloat,null);var r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0);var o=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;return e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(n),e.deleteFramebuffer(r),o}function L2(e){return e===2&&zn(e).fenceSync!=null}var ie=z();function r0(e){z().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(e+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function X(e,t){return A.tidy(e,t)}function Ft(e){t0(e).forEach(function(t){return t.dispose()})}function W2(e){return A.keep(e)}function ns(){for(var e=[],t=0;t0,function(){return"Element arr["+u.join("][")+"] should be a primitive, but is an array of "+i.length+" elements"}),I(i.length===a[0],function(){return"Element arr["+u.join("][")+"] should have "+a[0]+" elements, but has "+i.length+" elements"});for(var s=a.slice(1),l=0;l=0&&(o=r),Bp(r,o,t,n),e==null||!Mn(e)&&!Array.isArray(e)&&typeof e!="number"&&typeof e!="boolean"&&typeof e!="string"){var i=e==null?"null":e.constructor.name;throw new Error("Argument '"+t+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+i+"'")}var a=$r(e,o);Mn(e)||Array.isArray(e)||(e=[e]);var u=o!=="string"?Yg(e,o,z().getBool("DEBUG")):di(e,[],!0);return A.makeTensor(u,a,o)}function rs(e,t,n,r){if(r===void 0&&(r="numeric"),!Array.isArray(e))throw new Error("Argument "+t+" passed to "+n+" must be a `Tensor[]` or `TensorLike[]`");return e.map(function(o,i){return S(o,t+"["+i+"]",n)},r)}function o0(e,t){for(var n=0;n=0&&t0}),ie.registerFlag("WEBGL_VERSION",function(){return Op(2)?2:Op(1)?1:0}),ie.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return ie.get("WEBGL_VERSION")===2}),ie.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),ie.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),ie.registerFlag("WEBGL_PACK",function(){return ie.getBool("HAS_WEBGL")}),ie.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_CLIP",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),ie.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_PACK_REDUCE",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_LAZILY_UNPACK",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_CONV_IM2COL",function(){return ie.getBool("WEBGL_PACK")}),ie.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return P2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return F2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var e=ie.getNumber("WEBGL_VERSION");return e===0?0:M2(e)}),ie.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return ie.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(e=navigator.userAgent||navigator.vendor||window.opera,!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4))));var e}),ie.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return O2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!ie.getBool("WEBGL_FORCE_F16_TEXTURES")&&ie.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),ie.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return B2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return L2(ie.getNumber("WEBGL_VERSION"))}),ie.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return ie.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),e0=r0;var ut=D({complex_:function(e,t){var n=S(e,"real","complex"),r=S(t,"imag","complex");return Ce(n.shape,r.shape,"real and imag shapes, "+n.shape+" and "+r.shape+", must match in call to tf.complex()."),A.runKernelFunc(function(o){return o.complex(n,r)},{$real:n,$imag:r})}}),en=D({real_:function(e){var t=S(e,"input","real");return A.runKernelFunc(function(n){return n.real(t)},{$input:t})}}),Nn=D({imag_:function(e){var t=S(e,"input","imag");return A.runKernelFunc(function(n){return n.imag(t)},{$input:t})}});function lt(e,t,n){return Hr(e,t,$r(e,n),n)}function Hr(e,t,n,r){if(r==null&&(r=Ra(e)),r==="complex64")throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!Mn(e)&&!Array.isArray(e)&&typeof e!="number"&&typeof e!="boolean"&&typeof e!="string")throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(t!=null){Jg(t);var o=Z(t),i=Z(n);I(o===i,function(){return"Based on the provided shape, ["+t+"], the tensor should have "+o+" values but has "+i});for(var a=0;a1)return Ie([0],r);var o=Ia(Math.abs(Math.ceil((t-e)/n)),r);t=1,function(){return"Pass at least one tensor to concat"});var n=rs(e,"tensors","concat");n[0].dtype==="complex64"&&n.forEach(function(u){if(u.dtype!=="complex64")throw new Error(`Cannot concatenate complex64 tensors with a tensor + with dtype `+u.dtype+". ")}),t=et(t,n[0].shape)[0];var r=pi(n.map(function(u){return u.shape}),t);if(Z(r)===0)return lt([],r);if((n=n.filter(function(u){return u.size>0})).length===1)return n[0];var o=n.map(function(u){return u.shape});U2(o,t);var i=n,a={axis:t};return A.runKernelFunc(function(u){return u.concat(n,t)},i,function(u){var s=o.map(function(l){return l[t]});return xd(u,s,t).map(function(l){return function(){return l}})},"Concat",a)}}),G2=D({concat1d_:function(e){return Ye(e,0)}}),q2=D({concat2d_:function(e,t){return Ye(e,t)}}),K2=D({concat3d_:function(e,t){return Ye(e,t)}}),X2=D({concat4d_:function(e,t){return Ye(e,t)}}),xd=D({split_:function(e,t,n){n===void 0&&(n=0);var r,o=S(e,"x","split");return n=et(n,o.shape)[0],typeof t=="number"?(I(o.shape[n]%t==0,function(){return"Number of splits must evenly divide the axis."}),r=new Array(t).fill(o.shape[n]/t)):(I(o.shape[n]===t.reduce(function(i,a){return i+a}),function(){return"The sum of sizes must match the size of the axis dimension."}),r=t),A.runKernelFunc(function(i){return i.split(o,r,n)},{$x:o},function(i){return{$x:function(){return Ye(i,n)}}})}});function go(e,t){return e(t={exports:{}},t.exports),t.exports}var Y2=go(function(e){(function(t,n,r){function o(u){var s,l=this,c=(s=4022871197,function(f){f=f.toString();for(var d=0;d>>0,s=(h*=s)>>>0,s+=4294967296*(h-=s)}return 23283064365386963e-26*(s>>>0)});l.next=function(){var f=2091639*l.s0+23283064365386963e-26*l.c;return l.s0=l.s1,l.s1=l.s2,l.s2=f-(l.c=0|f)},l.c=1,l.s0=c(" "),l.s1=c(" "),l.s2=c(" "),l.s0-=c(u),l.s0<0&&(l.s0+=1),l.s1-=c(u),l.s1<0&&(l.s1+=1),l.s2-=c(u),l.s2<0&&(l.s2+=1),c=null}function i(u,s){return s.c=u.c,s.s0=u.s0,s.s1=u.s1,s.s2=u.s2,s}function a(u,s){var l=new o(u),c=s&&s.state,f=l.next;return f.int32=function(){return 4294967296*l.next()|0},f.double=function(){return f()+11102230246251565e-32*(2097152*f()|0)},f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.alea=a})(0,e,!1)}),Q2=go(function(e){(function(t,n,r){function o(u){var s=this,l="";s.x=0,s.y=0,s.z=0,s.w=0,s.next=function(){var f=s.x^s.x<<11;return s.x=s.y,s.y=s.z,s.z=s.w,s.w^=s.w>>>19^f^f>>>8},u===(0|u)?s.x=u:l+=u;for(var c=0;c>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xor128=a})(0,e,!1)}),J2=go(function(e){(function(t,n,r){function o(u){var s=this,l="";s.next=function(){var f=s.x^s.x>>>2;return s.x=s.y,s.y=s.z,s.z=s.w,s.w=s.v,(s.d=s.d+362437|0)+(s.v=s.v^s.v<<4^f^f<<1)|0},s.x=0,s.y=0,s.z=0,s.w=0,s.v=0,u===(0|u)?s.x=u:l+=u;for(var c=0;c>>4),s.next()}function i(u,s){return s.x=u.x,s.y=u.y,s.z=u.z,s.w=u.w,s.v=u.v,s.d=u.d,s}function a(u,s){var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xorwow=a})(0,e,!1)}),Z2=go(function(e){(function(t,n,r){function o(u){var s=this;s.next=function(){var l,c,f=s.x,d=s.i;return l=f[d],c=(l^=l>>>7)^l<<24,c^=(l=f[d+1&7])^l>>>10,c^=(l=f[d+3&7])^l>>>3,c^=(l=f[d+4&7])^l<<7,l=f[d+7&7],c^=(l^=l<<13)^l<<9,f[d]=c,s.i=d+1&7,c},function(l,c){var f,d=[];if(c===(0|c))d[0]=c;else for(c=""+c,f=0;f0;--f)l.next()}(s,u)}function i(u,s){return s.x=u.x.slice(),s.i=u.i,s}function a(u,s){u==null&&(u=+new Date);var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(c.x&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xorshift7=a})(0,e,!1)}),eb=go(function(e){(function(t,n,r){function o(u){var s=this;s.next=function(){var l,c,f=s.w,d=s.X,h=s.i;return s.w=f=f+1640531527|0,c=d[h+34&127],l=d[h=h+1&127],c^=c<<13,l^=l<<17,c^=c>>>15,l^=l>>>12,c=d[h]=c^l,s.i=h,c+(f^f>>>16)|0},function(l,c){var f,d,h,p,m,g=[],v=128;for(c===(0|c)?(d=c,c=null):(c+="\0",d=0,v=Math.max(v,c.length)),h=0,p=-32;p>>15,d^=d<<4,d^=d>>>13,p>=0&&(m=m+1640531527|0,h=(f=g[127&p]^=d+m)==0?h+1:0);for(h>=128&&(g[127&(c&&c.length||0)]=-1),h=127,p=512;p>0;--p)d=g[h+34&127],f=g[h=h+1&127],d^=d<<13,f^=f<<17,d^=d>>>15,f^=f>>>12,g[h]=d^f;l.w=m,l.X=g,l.i=h}(s,u)}function i(u,s){return s.i=u.i,s.w=u.w,s.X=u.X.slice(),s}function a(u,s){u==null&&(u=+new Date);var l=new o(u),c=s&&s.state,f=function(){return(l.next()>>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(c.X&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.xor4096=a})(0,e,!1)}),tb=go(function(e){(function(t,n,r){function o(u){var s=this,l="";s.next=function(){var f=s.b,d=s.c,h=s.d,p=s.a;return f=f<<25^f>>>7^d,d=d-h|0,h=h<<24^h>>>8^p,p=p-f|0,s.b=f=f<<20^f>>>12^d,s.c=d=d-h|0,s.d=h<<16^d>>>16^p,s.a=p-f|0},s.a=0,s.b=0,s.c=-1640531527,s.d=1367130551,u===Math.floor(u)?(s.a=u/4294967296|0,s.b=0|u):l+=u;for(var c=0;c>>0)/4294967296};return f.double=function(){do var d=((l.next()>>>11)+(l.next()>>>0)/4294967296)/2097152;while(d===0);return d},f.int32=l.next,f.quick=f,c&&(typeof c=="object"&&i(c,l),f.state=function(){return i(l,{})}),f}n&&n.exports?n.exports=a:r&&r.amd?r(function(){return a}):this.tychei=a})(0,e,!1)}),Qr=go(function(e){(function(t,n){var r,o=this,i=256,a=6,u="random",s=n.pow(i,a),l=n.pow(2,52),c=2*l,f=i-1;function d(v,y,x){var w=[],b=m(function E(R,k){var T,N=[],W=typeof R;if(k&&W=="object")for(T in R)try{N.push(E(R[T],k-1))}catch{}return N.length?N:W=="string"?R:R+"\0"}((y=y==1?{entropy:!0}:y||{}).entropy?[v,g(t)]:v??function(){try{var E;return r&&(E=r.randomBytes)?E=E(i):(E=new Uint8Array(i),(o.crypto||o.msCrypto).getRandomValues(E)),g(E)}catch{var R=o.navigator,k=R&&R.plugins;return[+new Date,o,k,o.screen,g(t)]}}(),3),w),C=new h(w),_=function(){for(var E=C.g(a),R=s,k=0;E=c;)E/=2,R/=2,k>>>=1;return(E+k)/R};return _.int32=function(){return 0|C.g(4)},_.quick=function(){return C.g(4)/4294967296},_.double=_,m(g(C.S),t),(y.pass||x||function(E,R,k,T){return T&&(T.S&&p(T,C),E.state=function(){return p(C,{})}),k?(n[u]=E,R):E})(_,b,"global"in y?y.global:this==n,y.state)}function h(v){var y,x=v.length,w=this,b=0,C=w.i=w.j=0,_=w.S=[];for(x||(v=[x++]);b=1||u===0);var s=Math.sqrt(-2*Math.log(u)/u);n=this.mean+this.stdDev*i*s,r=this.mean+this.stdDev*a*s,this.truncated&&!this.isValidTruncated(n)||(o=!0)}return this.truncated&&!this.isValidTruncated(r)||(this.nextVal=this.convertValue(r)),this.convertValue(n)},e.prototype.convertValue=function(t){return this.dtype==null||this.dtype==="float32"?t:Math.round(t)},e.prototype.isValidTruncated=function(t){return t<=this.upper&&t>=this.lower},e}(),nb=function(){function e(t,n,r,o){this.alpha=t,this.beta=1/n,this.dtype=r;var i=o||Math.random();this.randu=Bs(i.toString()),this.randn=new wd(0,1,r,!1,this.randu()),this.d=t<1?t+2/3:t-1/3,this.c=1/Math.sqrt(9*this.d)}return e.prototype.nextValue=function(){for(var t,n,r,o,i,a;;){do o=this.randn.nextValue(),a=1+this.c*o;while(a<=0);if(a*=a*a,n=1-.331*(t=o*o)*t,r=.5*t+this.d*(1-a+Math.log(a)),(i=this.randu())=1+t.length,function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+t.length}),I(n.length===t.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+t.length}),I(r.shape[0]%o==0,function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+t.join(" * ")+" === "+o}),A.runKernelFunc(function(i){return i.batchToSpaceND(r,t,n)},{$x:r},function(i){return{$x:function(){return i.spaceToBatchND(t,n)}}})}}),ib=D({broadcastTo_:function(e,t){var n=S(e,"broadcastTo","x"),r=n.shape;if(t.some(function(s){return!(s>0)||s%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+t+"].");if(t.lengthn.rank){for(var o=n.shape.slice();o.length=0;a--)if(n.shape[a]===t[a])i[a]=1;else if(n.shape[a]!==1)throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+t+"].");var u=i.map(function(s,l){return s>1?l:-1}).filter(function(s){return s>=0});return u.length===0?n.clone():A.runKernelFunc(function(s){return s.tile(n,i)},{input:n},function(s){return{input:function(){return s.sum(u,!0)}}})}}),ab=D({cast_:function(e,t){var n=S(e,"x","cast");if(!Jw(t))throw new Error("Failed to cast to unknown dtype "+t);if(t==="string"&&n.dtype!=="string"||t!=="string"&&n.dtype==="string")throw new Error("Only strings can be casted to strings");var r={dtype:t};return A.runKernelFunc(function(o){return o.cast(n,t)},{x:n},function(o){return{x:function(){return o.clone()}}},"Cast",r)}}),ub=D({clone_:function(e){var t=S(e,"x","clone",null);return A.runKernelFunc(function(){return A.makeTensorFromDataId(t.dataId,t.shape,t.dtype)},{$x:t},function(n){return{$x:function(){return n.toFloat()}}})}}),sb=D({cumsum_:function(e,t,n,r){t===void 0&&(t=0),n===void 0&&(n=!1),r===void 0&&(r=!1);var o=S(e,"x","cumsum"),i=Un([t|=0],o.rank),a=o;i!=null&&(a=o.transpose(i));var u=Vn(1,o.rank)[0],s=A.runKernelFunc(function(l){return l.cumsum(a,u,n,r)},{permutedX:a},function(l){return{permutedX:function(){return l.cumsum(t,n,!r)}}});return i!=null&&(s=s.transpose(i)),s}}),lb=D({depthToSpace_:function(e,t,n){n===void 0&&(n="NHWC");var r=S(e,"x","depthToSpace"),o=n==="NHWC"?r.shape[1]:r.shape[2],i=n==="NHWC"?r.shape[2]:r.shape[3],a=n==="NHWC"?r.shape[3]:r.shape[1];return I(o*t>=0,function(){return`Negative dimension size caused by overflow when multiplying `+o+" and "+t+` for depthToSpace with input shape `+r.shape}),I(i*t>=0,function(){return`Negative dimension size caused by overflow when multiplying `+i+" and "+t+` for depthToSpace with input shape - `+r.shape}),I(a%(t*t)==0,function(){return"Dimension size must be evenly divisible by "+t*t+" but is "+a+" for depthToSpace with input shape "+r.shape}),A.runKernelFunc(function(u){return u.depthToSpace(r,t,n)},{$x:r})}}),Zt=D({expandDims_:function(e,t){t===void 0&&(t=0);var n=S(e,"x","expandDims",null);I(t<=n.rank,function(){return"Axis must be <= rank of the tensor"});var r=n.shape.slice();return t<0&&(I(-(n.rank+1)<=t,function(){return"Axis must be in the interval ["+-(n.rank+1)+", "+n.rank+"]"}),t=n.rank+t+1),r.splice(t,0,1),vn(n,r)}}),f0=D({eye_:function(e,t,n,r){r===void 0&&(r="float32"),t==null&&(t=e);for(var o=se([e,t],r),i=e<=t?e:t,a=0;a2)throw new Error("Rank of probabilities must be 1 or 2, but is "+a);n=n||Math.random();var u=a===1?o.as2D(1,-1):o,s=A.runKernelFunc(function(l){return l.multinomial(u,r,t,n)},{logits2D:u});return a===1?s.as1D():s}}),cf=D({oneHot_:function(e,t,n,r){if(n===void 0&&(n=1),r===void 0&&(r=0),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+t);var o=S(e,"indices","oneHot","int32"),i=o.shape.concat([t]);return o=o.flatten(),A.runKernelFunc(function(a){return a.oneHot(o,t,n,r)},{$indices:o},function(a){return{$indices:function(){return Ie(o.shape,"float32")}}}).reshape(i)}}),wo=D({pad_:function(e,t,n){n===void 0&&(n=0);var r=S(e,"x","pad");if(r.rank===0)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var o={paddings:t,constantValue:n};return A.runKernelFunc(function(i){return i.pad(r,t,n)},{x:r},function(i){var a=t.map(function(u){return u[0]});return{x:function(){return i.slice(a,r.shape)}}},"PadV2",o)}}),vb=D({pad1d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===2,function(){return"Invalid number of paddings. Must be length of 2."}),wo(e,[t],n)}}),mb=D({pad2d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===2&&t[0].length===2&&t[1].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),wo(e,t,n)}}),gb=D({pad3d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===3&&t[0].length===2&&t[1].length===2&&t[2].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),wo(e,t,n)}}),yb=D({pad4d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===4&&t[0].length===2&&t[1].length===2&&t[2].length===2&&t[3].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),wo(e,t,n)}}),xb=D({rand_:function(e,t,n){var r=Z(e),o=null;if(n==null||n==="float32")o=new Float32Array(r);else if(n==="int32")o=new Int32Array(r);else{if(n!=="bool")throw new Error("Unknown data type "+n);o=new Uint8Array(r)}for(var i=0;i=1+t.length,function(){return"input rank "+r.rank+" should be > than [blockShape] "+t.length}),I(n.length===t.length,function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+t.length}),I(r.shape.reduce(function(o,i,a){return a>0&&a<=t.length?o&&(i+n[a-1][0]+n[a-1][1])%t[a-1]==0:o},!0),function(){return"input spatial dimensions "+r.shape.slice(1)+" with paddings "+n.toString()+" must be divisible by blockShapes "+t.toString()}),A.runKernelFunc(function(o){return o.spaceToBatchND(r,t,n)},{$x:r},function(o){return{$x:function(){return o.batchToSpaceND(t,n)}}})}}),p0=D({squeeze_:function(e,t){var n=S(e,"x","squeeze");return vn(n,eo(n.shape,t).newShape)}}),Gt=D({stack_:function(e,t){t===void 0&&(t=0);var n=as(e,"tensors","stack");if(I(n.length>=1,function(){return"Pass at least one tensor to tf.stack"}),n.length===1)return n[0].expandDims(t);var r=n[0].rank,o=n[0].shape,i=n[0].dtype;I(t<=r,function(){return"Axis must be <= rank of the tensor"}),n.forEach(function(u){Ce(o,u.shape,"All tensors passed to stack must have matching shapes")}),n.forEach(function(u){I(i===u.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var a=n.map(function(u){return u.expandDims(t)});return Ye(a,t)}}),ti=D({tile_:function(e,t){var n=S(e,"x","tile",null);I(n.rank===t.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of reps "+t+"."});var r=[n],o={reps:t};return A.runKernelFunc(function(i,a){var u=i.tile(n,t);return a([n]),u},{x:n},function(i,a){var u=a[0];return{x:function(){var s=ye(u);if(u.rank===1)for(var l=0;l=-n.shape.length&&t=2*t+1||o%2==1?a.push(o):i.push(o);r.push.apply(r,i),r.push(0),r.push.apply(r,a)}return r}function cs(e,t,n,r){r===void 0&&(r=!0);var o=[];r?o.push(e[0]/n):o.push(e[0]*n);for(var i=1;ie.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+t.shape[t.rank-1]+" vs. "+e.rank);if(e.size===0)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+e.shape+".");for(var n=t.shape,r=n[n.length-1],o=1,i=0;i1?t.shape[t.rank-1]:1,o=t.rank>1?t.rank-1:1,i="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+n.shape+", indices.shape: "+t.shape+", shape: "+e+", sliceDim: "+r+", and batchDim: "+o+".";if(n.rank1?t.shape[r-1]:1,i=n.length,a=1,u=o;u0;)1&e&&t.push(n),e/=2,n++;return t}function _d(e,t,n){for(var r=[],o=0;o0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var u=r[o];return i<0&&(i+=u),i=ef(0,i,u-1)}function Ib(e,t,n,r,o){var i=t[o],a=n[o]||1;(e&1<0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var u=r[o];return i<0&&(i+=u),i=a>0?ef(0,i,u):ef(-1,i,u-1)}function x0(e,t,n){for(var r=n.length,o=0;o1){r=o;break}for(o=r+1;o0||n[o]!==e[o])return!1;return!0}function w0(e,t){for(var n=e.length>0?e[e.length-1]:1,r=0;r0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+i+" variables is trainable."});var a=A.gradients(e,t,null,!0),u=a.value,s=a.grads;I(s.some(function(c){return c!=null}),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()."}),I(u.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+u.rank+" tensor"});var l={};return t.forEach(function(c,f){s[f]!=null&&(l[c.name]=s[f])}),o!=null&&o.forEach(function(c){return l[c.name]=null}),{value:u,grads:l}}function zs(e){return A.customGrad(e)}var lr=D({softmax_:function(e,t){t===void 0&&(t=-1);var n=S(e,"logits","softmax","float32");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and dim was "+t);return A.runKernelFunc(function(r,o){var i=r.softmax(n,t);return o([i]),i},{logits:n},function(r,o){var i=o[0],a=r.mul(i);return{logits:function(){return a.sub(a.sum([t],!0).mul(i))}}},"Softmax",{dim:t},[],[!0])}}),Tb=D({logSoftmax_:function(e,t){t===void 0&&(t=-1);var n=S(e,"logits","logSoftmax");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and axis was "+t);return zs(function(r,o){var i=r.max(t,!0),a=r.sub(i),u=a.toFloat().sub(a.exp().sum(t,!0).log());return o([u]),{value:u,gradFunc:function(s,l){var c=l[0].exp();return s.sub(s.sum(t,!0).mul(c))}}})(n)}}),b0=function(){function e(t,n){this.backend=t,this.dataMover=n,this.data=new WeakMap,this.dataIdsCount=0}return e.prototype.get=function(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)},e.prototype.set=function(t,n){this.dataIdsCount++,this.data.set(t,n)},e.prototype.has=function(t){return this.data.has(t)},e.prototype.delete=function(t){return this.dataIdsCount--,this.data.delete(t)},e.prototype.numDataIds=function(){return this.dataIdsCount},e}(),C0=function(){function e(){}return e.prototype.time=function(t){return F("time")},e.prototype.read=function(t){return F("read")},e.prototype.readSync=function(t){return F("readSync")},e.prototype.numDataIds=function(){return F("numDataIds")},e.prototype.disposeData=function(t){return F("disposeData")},e.prototype.write=function(t,n,r){return F("write")},e.prototype.move=function(t,n,r,o){return F("move")},e.prototype.memory=function(){return F("memory")},e.prototype.floatPrecision=function(){return F("floatPrecision")},e.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},e.prototype.batchMatMul=function(t,n,r,o){return F("batchMatMul")},e.prototype.fusedBatchMatMul=function(t){return t.a,t.b,t.transposeA,t.transposeB,t.bias,t.activation,t.preluActivationWeights,F("fusedBatchMatMul")},e.prototype.slice=function(t,n,r){return F("slice")},e.prototype.stridedSlice=function(t,n,r,o){return F("stridedSlice")},e.prototype.unstack=function(t,n){return F("unstack")},e.prototype.reverse=function(t,n){return F("reverse")},e.prototype.concat=function(t,n){return F("concat")},e.prototype.neg=function(t){return F("neg")},e.prototype.add=function(t,n){return F("add")},e.prototype.addN=function(t){return F("addN")},e.prototype.subtract=function(t,n){return F("subtract")},e.prototype.multiply=function(t,n){return F("multiply")},e.prototype.realDivide=function(t,n){return F("realDivide")},e.prototype.floorDiv=function(t,n){return F("floorDiv")},e.prototype.sum=function(t,n){return F("sum")},e.prototype.prod=function(t,n){return F("prod")},e.prototype.unsortedSegmentSum=function(t,n,r){return F("unsortedSegmentSum")},e.prototype.argMin=function(t,n){return F("argMin")},e.prototype.argMax=function(t,n){return F("argMax")},e.prototype.equal=function(t,n){return F("equal")},e.prototype.notEqual=function(t,n){return F("notEqual")},e.prototype.less=function(t,n){return F("less")},e.prototype.lessEqual=function(t,n){return F("lessEqual")},e.prototype.greater=function(t,n){return F("greater")},e.prototype.greaterEqual=function(t,n){return F("greaterEqual")},e.prototype.logicalNot=function(t){return F("logicalNot")},e.prototype.logicalAnd=function(t,n){return F("logicalAnd")},e.prototype.logicalOr=function(t,n){return F("logicalOr")},e.prototype.where=function(t){return F("where")},e.prototype.select=function(t,n,r){return F("select")},e.prototype.topk=function(t,n,r){return F("topk")},e.prototype.min=function(t,n){return F("min")},e.prototype.minimum=function(t,n){return F("minimum")},e.prototype.mod=function(t,n){return F("mod")},e.prototype.max=function(t,n){return F("max")},e.prototype.maximum=function(t,n){return F("maximum")},e.prototype.all=function(t,n){return F("all")},e.prototype.any=function(t,n){return F("any")},e.prototype.squaredDifference=function(t,n){return F("squaredDifference")},e.prototype.ceil=function(t){return F("ceil")},e.prototype.floor=function(t){return F("floor")},e.prototype.round=function(t){return F("round")},e.prototype.sign=function(t){return F("sign")},e.prototype.isNaN=function(t){return F("isNaN")},e.prototype.isInf=function(t){return F("isInf")},e.prototype.isFinite=function(t){return F("isFinite")},e.prototype.pow=function(t,n){return F("pow")},e.prototype.exp=function(t){return F("exp")},e.prototype.expm1=function(t){return F("expm1")},e.prototype.softmax=function(t,n){return F("softmax")},e.prototype.log=function(t){return F("log")},e.prototype.log1p=function(t){return F("log1p")},e.prototype.sqrt=function(t){return F("sqrt")},e.prototype.rsqrt=function(t){return F("rsqrt")},e.prototype.square=function(t){return F("square")},e.prototype.reciprocal=function(t){return F("reciprocal")},e.prototype.relu=function(t){return F("relu")},e.prototype.relu6=function(t){return F("relu6")},e.prototype.prelu=function(t,n){return F("prelu")},e.prototype.elu=function(t){return F("elu")},e.prototype.eluDer=function(t,n){return F("eluDer")},e.prototype.selu=function(t){return F("selu")},e.prototype.int=function(t){return F("int")},e.prototype.clip=function(t,n,r){return F("clip")},e.prototype.abs=function(t){return F("abs")},e.prototype.complexAbs=function(t){return F("complexAbs")},e.prototype.sigmoid=function(t){return F("sigmoid")},e.prototype.softplus=function(t){return F("softplus")},e.prototype.sin=function(t){return F("sin")},e.prototype.cos=function(t){return F("cos")},e.prototype.tan=function(t){return F("tan")},e.prototype.asin=function(t){return F("asin")},e.prototype.acos=function(t){return F("acos")},e.prototype.atan=function(t){return F("atan")},e.prototype.atan2=function(t,n){return F("atan2")},e.prototype.sinh=function(t){return F("sinh")},e.prototype.cosh=function(t){return F("cosh")},e.prototype.tanh=function(t){return F("tanh")},e.prototype.asinh=function(t){return F("asinh")},e.prototype.acosh=function(t){return F("acosh")},e.prototype.atanh=function(t){return F("atanh")},e.prototype.erf=function(t){return F("erf")},e.prototype.step=function(t,n){return F("step")},e.prototype.fusedConv2d=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,F("fusedConv2d")},e.prototype.conv2d=function(t,n,r){return F("conv2d")},e.prototype.conv2dDerInput=function(t,n,r){return F("conv2dDerInput")},e.prototype.conv2dDerFilter=function(t,n,r){return F("conv2dDerFilter")},e.prototype.fusedDepthwiseConv2D=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,F("fusedDepthwiseConv2D")},e.prototype.depthwiseConv2D=function(t,n,r){return F("depthwiseConv2D")},e.prototype.depthwiseConv2DDerInput=function(t,n,r){return F("depthwiseConv2DDerInput")},e.prototype.depthwiseConv2DDerFilter=function(t,n,r){return F("depthwiseConv2DDerFilter")},e.prototype.conv3d=function(t,n,r){return F("conv3d")},e.prototype.conv3dDerInput=function(t,n,r){return F("conv3dDerInput")},e.prototype.conv3dDerFilter=function(t,n,r){return F("conv3dDerFilter")},e.prototype.maxPool=function(t,n){return F("maxPool")},e.prototype.maxPoolBackprop=function(t,n,r,o){return F("maxPoolBackprop")},e.prototype.avgPool=function(t,n){return F("avgPool")},e.prototype.avgPoolBackprop=function(t,n,r){return F("avgPoolBackprop")},e.prototype.avgPool3d=function(t,n){return F("avgPool3d")},e.prototype.avgPool3dBackprop=function(t,n,r){return F("avgPool3dBackprop")},e.prototype.maxPool3d=function(t,n){return F("maxPool3d")},e.prototype.maxPool3dBackprop=function(t,n,r,o){return F("maxPool3dBackprop")},e.prototype.reshape=function(t,n){return F("reshape")},e.prototype.cast=function(t,n){return F("cast")},e.prototype.tile=function(t,n){return F("tile")},e.prototype.pad=function(t,n,r){return F("pad")},e.prototype.transpose=function(t,n){return F("transpose")},e.prototype.gather=function(t,n,r){return F("gather")},e.prototype.gatherND=function(t,n){return F("gatherND")},e.prototype.scatterND=function(t,n,r){return F("scatterND")},e.prototype.batchToSpaceND=function(t,n,r){return F("batchToSpaceND")},e.prototype.spaceToBatchND=function(t,n,r){return F("spaceToBatchND")},e.prototype.resizeBilinear=function(t,n,r,o){return F("resizeBilinear")},e.prototype.resizeBilinearBackprop=function(t,n,r){return F("resizeBilinearBackprop")},e.prototype.resizeNearestNeighbor=function(t,n,r,o){return F("resizeNearestNeighbor")},e.prototype.resizeNearestNeighborBackprop=function(t,n,r){return F("resizeNearestNeighborBackprop")},e.prototype.batchNormalization=function(t,n,r,o,i,a){return F("batchNormalization")},e.prototype.localResponseNormalization4D=function(t,n,r,o,i){return F("localResponseNormalization4D")},e.prototype.LRNGrad=function(t,n,r,o,i,a,u){return F("LRNGrad")},e.prototype.multinomial=function(t,n,r,o){return F("multinomial")},e.prototype.oneHot=function(t,n,r,o){return F("oneHot")},e.prototype.cumsum=function(t,n,r,o){return F("cumsum")},e.prototype.nonMaxSuppression=function(t,n,r,o,i){return F("nonMaxSuppression")},e.prototype.fft=function(t){return F("fft")},e.prototype.ifft=function(t){return F("ifft")},e.prototype.complex=function(t,n){return F("complex")},e.prototype.real=function(t){return F("real")},e.prototype.imag=function(t){return F("imag")},e.prototype.cropAndResize=function(t,n,r,o,i,a){return F("cropAndResize")},e.prototype.depthToSpace=function(t,n,r){return F("depthToSpace")},e.prototype.split=function(t,n,r){return F("split")},e.prototype.sparseToDense=function(t,n,r,o){return F("sparseToDense")},e.prototype.diag=function(t){return F("diag")},e.prototype.fill=function(t,n,r){return F("fill")},e.prototype.onesLike=function(t){return F("onesLike")},e.prototype.zerosLike=function(t){return F("zerosLike")},e.prototype.linspace=function(t,n,r){return F("linspace")},e.prototype.dispose=function(){return F("dispose")},e}();function F(e){throw new Error("'"+e+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function Er(e,t){for(var n=e.length,r=[],o=0;o1&&a===1&&r.unshift(i)}return r}function Je(e,t){for(var n=[],r=0;r1)&&n.unshift(i)}return n}function he(e,t){for(var n=[],r=Math.max(e.length,t.length),o=0;o>>1)]);m>0?f=h+1:(d=h,p=!m)}return p?f:-f-1}(i,a,u||Fb)}(e,t,n),o=r<0?-(r+1):r;e.splice(o,0,t)}function Fb(e,t){return e>t?1:eo}).sort(jp),l=i>0?-.5/i:0,c=[],f=[];c.length0;){var d=s.pop(),h=d.score,p=d.boxIndex,m=d.suppressBeginIndex;if(h=m;--v){var y=Mb(e,p,c[v]);if(y>=r){g=!0;break}if(d.score=d.score*Ob(r,l,y),d.score<=o)break}d.suppressBeginIndex=c.length,g||(d.score===h?(c.push(p),f.push(d.score)):d.score>o&&Pb(s,d,jp))}var x=c.length;return u&&(c.fill(0,x),f.fill(0,x)),{selectedIndices:Ge(c,"int32"),selectedScores:Ge(f,"float32"),numValidOutputs:K(x,"int32")}}function Mb(e,t,n){var r=e.subarray(4*t,4*t+4),o=e.subarray(4*n,4*n+4),i=Math.min(r[0],r[2]),a=Math.min(r[1],r[3]),u=Math.max(r[0],r[2]),s=Math.max(r[1],r[3]),l=Math.min(o[0],o[2]),c=Math.min(o[1],o[3]),f=Math.max(o[0],o[2]),d=Math.max(o[1],o[3]),h=(u-i)*(s-a),p=(f-l)*(d-c);if(h<=0||p<=0)return 0;var m=Math.max(i,l),g=Math.max(a,c),v=Math.min(u,f),y=Math.min(s,d),x=Math.max(v-m,0)*Math.max(y-g,0);return x/(h+p-x)}function Ob(e,t,n){var r=Math.exp(t*n*n);return n<=e?r:0}function jp(e,t){return e.score-t.score||e.score===t.score&&t.boxIndex-e.boxIndex}function R0(e,t,n){var r=new Array(e.rank).fill(0),o=e.shape.slice();return t.map(function(i){o[n]=i;var a=e.slice(r,o);return r[n]+=i,a})}function I0(e,t){for(var n=new Array(e.rank),r=0;r2)throw new Error("Rank of probabilities must be 1 or 2, but is "+a);n=n||Math.random();var u=a===1?o.as2D(1,-1):o,s=A.runKernelFunc(function(l){return l.multinomial(u,r,t,n)},{logits2D:u});return a===1?s.as1D():s}}),sf=D({oneHot_:function(e,t,n,r){if(n===void 0&&(n=1),r===void 0&&(r=0),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+t);var o=S(e,"indices","oneHot","int32"),i=o.shape.concat([t]);return o=o.flatten(),A.runKernelFunc(function(a){return a.oneHot(o,t,n,r)},{$indices:o},function(a){return{$indices:function(){return Ie(o.shape,"float32")}}}).reshape(i)}}),yo=D({pad_:function(e,t,n){n===void 0&&(n=0);var r=S(e,"x","pad");if(r.rank===0)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var o={paddings:t,constantValue:n};return A.runKernelFunc(function(i){return i.pad(r,t,n)},{x:r},function(i){var a=t.map(function(u){return u[0]});return{x:function(){return i.slice(a,r.shape)}}},"PadV2",o)}}),fb=D({pad1d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===2,function(){return"Invalid number of paddings. Must be length of 2."}),yo(e,[t],n)}}),db=D({pad2d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===2&&t[0].length===2&&t[1].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),yo(e,t,n)}}),hb=D({pad3d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===3&&t[0].length===2&&t[1].length===2&&t[2].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),yo(e,t,n)}}),pb=D({pad4d_:function(e,t,n){return n===void 0&&(n=0),I(t.length===4&&t[0].length===2&&t[1].length===2&&t[2].length===2&&t[3].length===2,function(){return"Invalid number of paddings. Must be length of 2 each."}),yo(e,t,n)}}),vb=D({rand_:function(e,t,n){var r=Z(e),o=null;if(n==null||n==="float32")o=new Float32Array(r);else if(n==="int32")o=new Int32Array(r);else{if(n!=="bool")throw new Error("Unknown data type "+n);o=new Uint8Array(r)}for(var i=0;i=1+t.length,function(){return"input rank "+r.rank+" should be > than [blockShape] "+t.length}),I(n.length===t.length,function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+t.length}),I(r.shape.reduce(function(o,i,a){return a>0&&a<=t.length?o&&(i+n[a-1][0]+n[a-1][1])%t[a-1]==0:o},!0),function(){return"input spatial dimensions "+r.shape.slice(1)+" with paddings "+n.toString()+" must be divisible by blockShapes "+t.toString()}),A.runKernelFunc(function(o){return o.spaceToBatchND(r,t,n)},{$x:r},function(o){return{$x:function(){return o.batchToSpaceND(t,n)}}})}}),c0=D({squeeze_:function(e,t){var n=S(e,"x","squeeze");return pn(n,Jr(n.shape,t).newShape)}}),Gt=D({stack_:function(e,t){t===void 0&&(t=0);var n=rs(e,"tensors","stack");if(I(n.length>=1,function(){return"Pass at least one tensor to tf.stack"}),n.length===1)return n[0].expandDims(t);var r=n[0].rank,o=n[0].shape,i=n[0].dtype;I(t<=r,function(){return"Axis must be <= rank of the tensor"}),n.forEach(function(u){Ce(o,u.shape,"All tensors passed to stack must have matching shapes")}),n.forEach(function(u){I(i===u.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var a=n.map(function(u){return u.expandDims(t)});return Ye(a,t)}}),Zo=D({tile_:function(e,t){var n=S(e,"x","tile",null);I(n.rank===t.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of reps "+t+"."});var r=[n],o={reps:t};return A.runKernelFunc(function(i,a){var u=i.tile(n,t);return a([n]),u},{x:n},function(i,a){var u=a[0];return{x:function(){var s=ye(u);if(u.rank===1)for(var l=0;l=-n.shape.length&&t=2*t+1||o%2==1?a.push(o):i.push(o);r.push.apply(r,i),r.push(0),r.push.apply(r,a)}return r}function us(e,t,n,r){r===void 0&&(r=!0);var o=[];r?o.push(e[0]/n):o.push(e[0]*n);for(var i=1;ie.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+t.shape[t.rank-1]+" vs. "+e.rank);if(e.size===0)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+e.shape+".");for(var n=t.shape,r=n[n.length-1],o=1,i=0;i1?t.shape[t.rank-1]:1,o=t.rank>1?t.rank-1:1,i="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+n.shape+", indices.shape: "+t.shape+", shape: "+e+", sliceDim: "+r+", and batchDim: "+o+".";if(n.rank1?t.shape[r-1]:1,i=n.length,a=1,u=o;u0;)1&e&&t.push(n),e/=2,n++;return t}function bd(e,t,n){for(var r=[],o=0;o0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var u=r[o];return i<0&&(i+=u),i=Jc(0,i,u-1)}function Eb(e,t,n,r,o){var i=t[o],a=n[o]||1;(e&1<0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var u=r[o];return i<0&&(i+=u),i=a>0?Jc(0,i,u):Jc(-1,i,u-1)}function v0(e,t,n){for(var r=n.length,o=0;o1){r=o;break}for(o=r+1;o0||n[o]!==e[o])return!1;return!0}function m0(e,t){for(var n=e.length>0?e[e.length-1]:1,r=0;r0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+i+" variables is trainable."});var a=A.gradients(e,t,null,!0),u=a.value,s=a.grads;I(s.some(function(c){return c!=null}),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()."}),I(u.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+u.rank+" tensor"});var l={};return t.forEach(function(c,f){s[f]!=null&&(l[c.name]=s[f])}),o!=null&&o.forEach(function(c){return l[c.name]=null}),{value:u,grads:l}}function Ls(e){return A.customGrad(e)}var sr=D({softmax_:function(e,t){t===void 0&&(t=-1);var n=S(e,"logits","softmax","float32");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and dim was "+t);return A.runKernelFunc(function(r,o){var i=r.softmax(n,t);return o([i]),i},{logits:n},function(r,o){var i=o[0],a=r.mul(i);return{logits:function(){return a.sub(a.sum([t],!0).mul(i))}}},"Softmax",{dim:t},[],[!0])}}),kb=D({logSoftmax_:function(e,t){t===void 0&&(t=-1);var n=S(e,"logits","logSoftmax");if(t===-1&&(t=n.rank-1),t!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and axis was "+t);return Ls(function(r,o){var i=r.max(t,!0),a=r.sub(i),u=a.toFloat().sub(a.exp().sum(t,!0).log());return o([u]),{value:u,gradFunc:function(s,l){var c=l[0].exp();return s.sub(s.sum(t,!0).mul(c))}}})(n)}}),g0=function(){function e(t,n){this.backend=t,this.dataMover=n,this.data=new WeakMap,this.dataIdsCount=0}return e.prototype.get=function(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)},e.prototype.set=function(t,n){this.dataIdsCount++,this.data.set(t,n)},e.prototype.has=function(t){return this.data.has(t)},e.prototype.delete=function(t){return this.dataIdsCount--,this.data.delete(t)},e.prototype.numDataIds=function(){return this.dataIdsCount},e}(),y0=function(){function e(){}return e.prototype.time=function(t){return F("time")},e.prototype.read=function(t){return F("read")},e.prototype.readSync=function(t){return F("readSync")},e.prototype.numDataIds=function(){return F("numDataIds")},e.prototype.disposeData=function(t){return F("disposeData")},e.prototype.write=function(t,n,r){return F("write")},e.prototype.move=function(t,n,r,o){return F("move")},e.prototype.memory=function(){return F("memory")},e.prototype.floatPrecision=function(){return F("floatPrecision")},e.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},e.prototype.batchMatMul=function(t,n,r,o){return F("batchMatMul")},e.prototype.fusedBatchMatMul=function(t){return t.a,t.b,t.transposeA,t.transposeB,t.bias,t.activation,t.preluActivationWeights,F("fusedBatchMatMul")},e.prototype.slice=function(t,n,r){return F("slice")},e.prototype.stridedSlice=function(t,n,r,o){return F("stridedSlice")},e.prototype.unstack=function(t,n){return F("unstack")},e.prototype.reverse=function(t,n){return F("reverse")},e.prototype.concat=function(t,n){return F("concat")},e.prototype.neg=function(t){return F("neg")},e.prototype.add=function(t,n){return F("add")},e.prototype.addN=function(t){return F("addN")},e.prototype.subtract=function(t,n){return F("subtract")},e.prototype.multiply=function(t,n){return F("multiply")},e.prototype.realDivide=function(t,n){return F("realDivide")},e.prototype.floorDiv=function(t,n){return F("floorDiv")},e.prototype.sum=function(t,n){return F("sum")},e.prototype.prod=function(t,n){return F("prod")},e.prototype.unsortedSegmentSum=function(t,n,r){return F("unsortedSegmentSum")},e.prototype.argMin=function(t,n){return F("argMin")},e.prototype.argMax=function(t,n){return F("argMax")},e.prototype.equal=function(t,n){return F("equal")},e.prototype.notEqual=function(t,n){return F("notEqual")},e.prototype.less=function(t,n){return F("less")},e.prototype.lessEqual=function(t,n){return F("lessEqual")},e.prototype.greater=function(t,n){return F("greater")},e.prototype.greaterEqual=function(t,n){return F("greaterEqual")},e.prototype.logicalNot=function(t){return F("logicalNot")},e.prototype.logicalAnd=function(t,n){return F("logicalAnd")},e.prototype.logicalOr=function(t,n){return F("logicalOr")},e.prototype.where=function(t){return F("where")},e.prototype.select=function(t,n,r){return F("select")},e.prototype.topk=function(t,n,r){return F("topk")},e.prototype.min=function(t,n){return F("min")},e.prototype.minimum=function(t,n){return F("minimum")},e.prototype.mod=function(t,n){return F("mod")},e.prototype.max=function(t,n){return F("max")},e.prototype.maximum=function(t,n){return F("maximum")},e.prototype.all=function(t,n){return F("all")},e.prototype.any=function(t,n){return F("any")},e.prototype.squaredDifference=function(t,n){return F("squaredDifference")},e.prototype.ceil=function(t){return F("ceil")},e.prototype.floor=function(t){return F("floor")},e.prototype.round=function(t){return F("round")},e.prototype.sign=function(t){return F("sign")},e.prototype.isNaN=function(t){return F("isNaN")},e.prototype.isInf=function(t){return F("isInf")},e.prototype.isFinite=function(t){return F("isFinite")},e.prototype.pow=function(t,n){return F("pow")},e.prototype.exp=function(t){return F("exp")},e.prototype.expm1=function(t){return F("expm1")},e.prototype.softmax=function(t,n){return F("softmax")},e.prototype.log=function(t){return F("log")},e.prototype.log1p=function(t){return F("log1p")},e.prototype.sqrt=function(t){return F("sqrt")},e.prototype.rsqrt=function(t){return F("rsqrt")},e.prototype.square=function(t){return F("square")},e.prototype.reciprocal=function(t){return F("reciprocal")},e.prototype.relu=function(t){return F("relu")},e.prototype.relu6=function(t){return F("relu6")},e.prototype.prelu=function(t,n){return F("prelu")},e.prototype.elu=function(t){return F("elu")},e.prototype.eluDer=function(t,n){return F("eluDer")},e.prototype.selu=function(t){return F("selu")},e.prototype.int=function(t){return F("int")},e.prototype.clip=function(t,n,r){return F("clip")},e.prototype.abs=function(t){return F("abs")},e.prototype.complexAbs=function(t){return F("complexAbs")},e.prototype.sigmoid=function(t){return F("sigmoid")},e.prototype.softplus=function(t){return F("softplus")},e.prototype.sin=function(t){return F("sin")},e.prototype.cos=function(t){return F("cos")},e.prototype.tan=function(t){return F("tan")},e.prototype.asin=function(t){return F("asin")},e.prototype.acos=function(t){return F("acos")},e.prototype.atan=function(t){return F("atan")},e.prototype.atan2=function(t,n){return F("atan2")},e.prototype.sinh=function(t){return F("sinh")},e.prototype.cosh=function(t){return F("cosh")},e.prototype.tanh=function(t){return F("tanh")},e.prototype.asinh=function(t){return F("asinh")},e.prototype.acosh=function(t){return F("acosh")},e.prototype.atanh=function(t){return F("atanh")},e.prototype.erf=function(t){return F("erf")},e.prototype.step=function(t,n){return F("step")},e.prototype.fusedConv2d=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,F("fusedConv2d")},e.prototype.conv2d=function(t,n,r){return F("conv2d")},e.prototype.conv2dDerInput=function(t,n,r){return F("conv2dDerInput")},e.prototype.conv2dDerFilter=function(t,n,r){return F("conv2dDerFilter")},e.prototype.fusedDepthwiseConv2D=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,F("fusedDepthwiseConv2D")},e.prototype.depthwiseConv2D=function(t,n,r){return F("depthwiseConv2D")},e.prototype.depthwiseConv2DDerInput=function(t,n,r){return F("depthwiseConv2DDerInput")},e.prototype.depthwiseConv2DDerFilter=function(t,n,r){return F("depthwiseConv2DDerFilter")},e.prototype.conv3d=function(t,n,r){return F("conv3d")},e.prototype.conv3dDerInput=function(t,n,r){return F("conv3dDerInput")},e.prototype.conv3dDerFilter=function(t,n,r){return F("conv3dDerFilter")},e.prototype.maxPool=function(t,n){return F("maxPool")},e.prototype.maxPoolBackprop=function(t,n,r,o){return F("maxPoolBackprop")},e.prototype.avgPool=function(t,n){return F("avgPool")},e.prototype.avgPoolBackprop=function(t,n,r){return F("avgPoolBackprop")},e.prototype.avgPool3d=function(t,n){return F("avgPool3d")},e.prototype.avgPool3dBackprop=function(t,n,r){return F("avgPool3dBackprop")},e.prototype.maxPool3d=function(t,n){return F("maxPool3d")},e.prototype.maxPool3dBackprop=function(t,n,r,o){return F("maxPool3dBackprop")},e.prototype.reshape=function(t,n){return F("reshape")},e.prototype.cast=function(t,n){return F("cast")},e.prototype.tile=function(t,n){return F("tile")},e.prototype.pad=function(t,n,r){return F("pad")},e.prototype.transpose=function(t,n){return F("transpose")},e.prototype.gather=function(t,n,r){return F("gather")},e.prototype.gatherND=function(t,n){return F("gatherND")},e.prototype.scatterND=function(t,n,r){return F("scatterND")},e.prototype.batchToSpaceND=function(t,n,r){return F("batchToSpaceND")},e.prototype.spaceToBatchND=function(t,n,r){return F("spaceToBatchND")},e.prototype.resizeBilinear=function(t,n,r,o){return F("resizeBilinear")},e.prototype.resizeBilinearBackprop=function(t,n,r){return F("resizeBilinearBackprop")},e.prototype.resizeNearestNeighbor=function(t,n,r,o){return F("resizeNearestNeighbor")},e.prototype.resizeNearestNeighborBackprop=function(t,n,r){return F("resizeNearestNeighborBackprop")},e.prototype.batchNormalization=function(t,n,r,o,i,a){return F("batchNormalization")},e.prototype.localResponseNormalization4D=function(t,n,r,o,i){return F("localResponseNormalization4D")},e.prototype.LRNGrad=function(t,n,r,o,i,a,u){return F("LRNGrad")},e.prototype.multinomial=function(t,n,r,o){return F("multinomial")},e.prototype.oneHot=function(t,n,r,o){return F("oneHot")},e.prototype.cumsum=function(t,n,r,o){return F("cumsum")},e.prototype.nonMaxSuppression=function(t,n,r,o,i){return F("nonMaxSuppression")},e.prototype.fft=function(t){return F("fft")},e.prototype.ifft=function(t){return F("ifft")},e.prototype.complex=function(t,n){return F("complex")},e.prototype.real=function(t){return F("real")},e.prototype.imag=function(t){return F("imag")},e.prototype.cropAndResize=function(t,n,r,o,i,a){return F("cropAndResize")},e.prototype.depthToSpace=function(t,n,r){return F("depthToSpace")},e.prototype.split=function(t,n,r){return F("split")},e.prototype.sparseToDense=function(t,n,r,o){return F("sparseToDense")},e.prototype.diag=function(t){return F("diag")},e.prototype.fill=function(t,n,r){return F("fill")},e.prototype.onesLike=function(t){return F("onesLike")},e.prototype.zerosLike=function(t){return F("zerosLike")},e.prototype.linspace=function(t,n,r){return F("linspace")},e.prototype.dispose=function(){return F("dispose")},e}();function F(e){throw new Error("'"+e+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function _r(e,t){for(var n=e.length,r=[],o=0;o1&&a===1&&r.unshift(i)}return r}function Je(e,t){for(var n=[],r=0;r1)&&n.unshift(i)}return n}function he(e,t){for(var n=[],r=Math.max(e.length,t.length),o=0;o>>1)]);m>0?f=h+1:(d=h,p=!m)}return p?f:-f-1}(i,a,u||Tb)}(e,t,n),o=r<0?-(r+1):r;e.splice(o,0,t)}function Tb(e,t){return e>t?1:eo}).sort(zp),l=i>0?-.5/i:0,c=[],f=[];c.length0;){var d=s.pop(),h=d.score,p=d.boxIndex,m=d.suppressBeginIndex;if(h=m;--v){var y=Nb(e,p,c[v]);if(y>=r){g=!0;break}if(d.score=d.score*Ab(r,l,y),d.score<=o)break}d.suppressBeginIndex=c.length,g||(d.score===h?(c.push(p),f.push(d.score)):d.score>o&&Db(s,d,zp))}var x=c.length;return u&&(c.fill(0,x),f.fill(0,x)),{selectedIndices:Ge(c,"int32"),selectedScores:Ge(f,"float32"),numValidOutputs:K(x,"int32")}}function Nb(e,t,n){var r=e.subarray(4*t,4*t+4),o=e.subarray(4*n,4*n+4),i=Math.min(r[0],r[2]),a=Math.min(r[1],r[3]),u=Math.max(r[0],r[2]),s=Math.max(r[1],r[3]),l=Math.min(o[0],o[2]),c=Math.min(o[1],o[3]),f=Math.max(o[0],o[2]),d=Math.max(o[1],o[3]),h=(u-i)*(s-a),p=(f-l)*(d-c);if(h<=0||p<=0)return 0;var m=Math.max(i,l),g=Math.max(a,c),v=Math.min(u,f),y=Math.min(s,d),x=Math.max(v-m,0)*Math.max(y-g,0);return x/(h+p-x)}function Ab(e,t,n){var r=Math.exp(t*n*n);return n<=e?r:0}function zp(e,t){return e.score-t.score||e.score===t.score&&t.boxIndex-e.boxIndex}function _0(e,t,n){var r=new Array(e.rank).fill(0),o=e.shape.slice();return t.map(function(i){o[n]=i;var a=e.slice(r,o);return r[n]+=i,a})}function E0(e,t){for(var n=new Array(e.rank),r=0;r":"<",s=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=` + `},Mb=function(e,t,n){this.variableNames=["A"];var r=e.windowSize,o=e.batchSize,i=e.inSize,a=Math.ceil(i/r);n||this.variableNames.push("bestIndicesA"),this.outputShape=[o,a];var u=t==="max"?">":"<",s=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode=` void main() { ivec2 coords = getOutputCoords(); int batch = coords[0]; @@ -101,7 +101,7 @@ Error generating stack: `+i.message+` } setOutput(float(bestIndex)); } - `};function T0(e,t){return["x","y","z","w","u","v"].slice(0,t).map(function(n){return e+"."+n})}function Dt(e,t){return t===1?[e]:T0(e,t)}function gt(){var e,t,n,r,o,i,a,u,s,l;return z().getNumber("WEBGL_VERSION")===2?(e="#version 300 es",t="in",n="out",r="in",o="texture",i="outputColor",a="out vec4 outputColor;",u=` + `};function k0(e,t){return["x","y","z","w","u","v"].slice(0,t).map(function(n){return e+"."+n})}function It(e,t){return t===1?[e]:k0(e,t)}function gt(){var e,t,n,r,o,i,a,u,s,l;return z().getNumber("WEBGL_VERSION")===2?(e="#version 300 es",t="in",n="out",r="in",o="texture",i="outputColor",a="out vec4 outputColor;",u=` bool isnan_custom(float val) { return (val > 0.0 || val < 0.0) ? false : val != 0.0; } @@ -146,11 +146,11 @@ Error generating stack: `+i.message+` ivec4 round(vec4 value) { return ivec4(floor(value + vec4(0.5))); } - `),{version:e,attribute:t,varyingVs:n,varyingFs:r,texture2D:o,output:i,defineOutput:a,defineSpecialNaN:u,defineSpecialInf:s,defineRound:l}}function oo(e,t,n){n===void 0&&(n="index");var r=Bn(t);return r.map(function(o,i){return"int "+e[i]+" = "+n+" / "+o+"; "+(i===r.length-1?"int "+e[i+1]+" = "+n+" - "+e[i]+" * "+o:"index -= "+e[i]+" * "+o)+";"}).join("")}function Id(e){var t=Bn(e).map(function(n){return n.toString()});return` + `),{version:e,attribute:t,varyingVs:n,varyingFs:r,texture2D:o,output:i,defineOutput:a,defineSpecialNaN:u,defineSpecialInf:s,defineRound:l}}function no(e,t,n){n===void 0&&(n="index");var r=On(t);return r.map(function(o,i){return"int "+e[i]+" = "+n+" / "+o+"; "+(i===r.length-1?"int "+e[i+1]+" = "+n+" - "+e[i]+" * "+o:"index -= "+e[i]+" * "+o)+";"}).join("")}function kd(e){var t=On(e).map(function(n){return n.toString()});return` int getFlatIndex(ivec3 coords) { return coords.x * `+t[0]+" + coords.y * "+t[1]+` + coords.z; } -`}var N0=` +`}var R0=` const float FLOAT_MAX = 1.70141184e38; const float FLOAT_MIN = 1.17549435e-38; @@ -189,8 +189,8 @@ Error generating stack: `+i.message+` return c / 255.0; } -`;function zb(e,t,n,r){var o=[];e.forEach(function(h){var p=Z(h.shapeInfo.logicalShape);h.shapeInfo.isUniform?o.push("uniform float "+h.name+(p>1?"["+p+"]":"")+";"):(o.push("uniform sampler2D "+h.name+";"),o.push("uniform int offset"+h.name+";"))});var i,a,u=o.join(` -`),s=e.map(function(h){return function(p,m,g){g===void 0&&(g=!1);var v="";v+=g?A0(p):Ao(p);var y=p.shapeInfo.logicalShape,x=m.logicalShape;return y.length<=x.length&&(v+=g?function(w,b){var C,_=w.name,E=_.charAt(0).toUpperCase()+_.slice(1),R="get"+E+"AtOutCoords",k=w.shapeInfo.logicalShape.length,T=b.logicalShape.length,N=Er(w.shapeInfo.logicalShape,b.logicalShape),W=ke(T),L=T-k,U=["x","y","z","w","u","v"];C=k===0?"":T<2&&N.length>=1?"coords = 0;":N.map(function(q){return"coords."+U[q+L]+" = 0;"}).join(` +`;function Ob(e,t,n,r){var o=[];e.forEach(function(h){var p=Z(h.shapeInfo.logicalShape);h.shapeInfo.isUniform?o.push("uniform float "+h.name+(p>1?"["+p+"]":"")+";"):(o.push("uniform sampler2D "+h.name+";"),o.push("uniform int offset"+h.name+";"))});var i,a,u=o.join(` +`),s=e.map(function(h){return function(p,m,g){g===void 0&&(g=!1);var v="";v+=g?I0(p):To(p);var y=p.shapeInfo.logicalShape,x=m.logicalShape;return y.length<=x.length&&(v+=g?function(w,b){var C,_=w.name,E=_.charAt(0).toUpperCase()+_.slice(1),R="get"+E+"AtOutCoords",k=w.shapeInfo.logicalShape.length,T=b.logicalShape.length,N=_r(w.shapeInfo.logicalShape,b.logicalShape),W=ke(T),L=T-k,U=["x","y","z","w","u","v"];C=k===0?"":T<2&&N.length>=1?"coords = 0;":N.map(function(q){return"coords."+U[q+L]+" = 0;"}).join(` `);var $="";$=T<2&&k>0?"coords":w.shapeInfo.logicalShape.map(function(q,re){return"coords."+U[re+L]}).join(", ");var V="return outputValue;",P=Z(w.shapeInfo.logicalShape)===1,M=Z(b.logicalShape)===1;if(k!==1||P||M){if(P&&!M)V=T===1?` return vec4(outputValue.x, outputValue.x, 0., 0.); `:` @@ -208,7 +208,7 @@ Error generating stack: `+i.message+` float `+E+`() { return sampleTexture(`+C+`, resultUV); } - `;var W,L=ke(N),U=Er(w.shapeInfo.logicalShape,b.logicalShape),$=N-T,V=["x","y","z","w","u","v"];W=T===0?"":N<2&&U.length>=1?"coords = 0;":U.map(function(M){return"coords."+V[M+$]+" = 0;"}).join(` + `;var W,L=ke(N),U=_r(w.shapeInfo.logicalShape,b.logicalShape),$=N-T,V=["x","y","z","w","u","v"];W=T===0?"":N<2&&U.length>=1?"coords = 0;":U.map(function(M){return"coords."+V[M+$]+" = 0;"}).join(` `);var P="";return P=N<2&&T>0?"coords":w.shapeInfo.logicalShape.map(function(M,B){return"coords."+V[B+$]}).join(", "),` float `+E+`() { `+L+` coords = getOutputCoords(); @@ -275,9 +275,9 @@ Error generating stack: `+i.message+` return fract((p3.x + p3.y) * p3.z); } - `+Ub+` - `+Vb+` - `+$b+` + `+Bb+` + `+Lb+` + `+Wb+` `}(c);return t.isPacked?(i=function(h,p){switch(h.length){case 0:return` int getOutputCoords() { return 0; @@ -393,7 +393,7 @@ Error generating stack: `+i.message+` int c = index - r * `+v[1]+`; return ivec2(r, c); } - `}(h,p);case 3:return m=p,g=oo(["r","c","d"],h),` + `}(h,p);case 3:return m=p,g=no(["r","c","d"],h),` ivec3 getOutputCoords() { ivec2 resTexRC = ivec2(resultUV.yx * vec2(`+m[0]+", "+m[1]+`)); @@ -401,7 +401,7 @@ Error generating stack: `+i.message+` `+g+` return ivec3(r, c, d); } - `;case 4:return function(v,y){var x=oo(["r","c","d","d2"],v);return` + `;case 4:return function(v,y){var x=no(["r","c","d","d2"],v);return` ivec4 getOutputCoords() { ivec2 resTexRC = ivec2(resultUV.yx * vec2(`+y[0]+", "+y[1]+`)); @@ -409,7 +409,7 @@ Error generating stack: `+i.message+` `+x+` return ivec4(r, c, d, d2); } - `}(h,p);case 5:return function(v,y){var x=oo(["r","c","d","d2","d3"],v);return` + `}(h,p);case 5:return function(v,y){var x=no(["r","c","d","d2","d3"],v);return` ivec5 getOutputCoords() { ivec2 resTexRC = ivec2(resultUV.yx * vec2(`+y[0]+`, `+y[1]+`)); @@ -421,7 +421,7 @@ Error generating stack: `+i.message+` ivec5 outShape = ivec5(r, c, d, d2, d3); return outShape; } - `}(h,p);case 6:return function(v,y){var x=oo(["r","c","d","d2","d3","d4"],v);return` + `}(h,p);case 6:return function(v,y){var x=no(["r","c","d","d2","d3","d4"],v);return` ivec6 getOutputCoords() { ivec2 resTexRC = ivec2(resultUV.yx * vec2(`+y[0]+", "+y[1]+`)); @@ -436,25 +436,25 @@ Error generating stack: `+i.message+` void setOutput(float val) { `+h.output+` = vec4(val, 0, 0, 0); } - `}(c)),r&&(d+=Hb),[d,f,a,u,i,s,n].join(` -`)}function Ao(e){var t=e.shapeInfo.logicalShape;switch(t.length){case 0:return function(n){var r=n.name,o="get"+r.charAt(0).toUpperCase()+r.slice(1);if(n.shapeInfo.isUniform)return"float "+o+"() {return "+r+";}";var i=n.shapeInfo.texShape,a=i[0],u=i[1];if(a===1&&u===1)return` + `}(c)),r&&(d+=zb),[d,f,a,u,i,s,n].join(` +`)}function To(e){var t=e.shapeInfo.logicalShape;switch(t.length){case 0:return function(n){var r=n.name,o="get"+r.charAt(0).toUpperCase()+r.slice(1);if(n.shapeInfo.isUniform)return"float "+o+"() {return "+r+";}";var i=n.shapeInfo.texShape,a=i[0],u=i[1];if(a===1&&u===1)return` float `+o+`() { return sampleTexture(`+r+`, halfCR); } - `;var s=n.shapeInfo.texShape,l=s[0],c=s[1],f=Kr(r);return` + `;var s=n.shapeInfo.texShape,l=s[0],c=s[1],f=qr(r);return` float `+o+`() { vec2 uv = uvFromFlat(`+l+", "+c+", "+f+`); return sampleTexture(`+r+`, uv); } `}(e);case 1:return function(n){var r=n.name,o="get"+r.charAt(0).toUpperCase()+r.slice(1);if(n.shapeInfo.isUniform)return` float `+o+`(int index) { - `+Io(n)+` + `+ko(n)+` } `;var i=n.shapeInfo.texShape,a=i[0],u=i[1];if(u===1&&a===1)return` float `+o+`(int index) { return sampleTexture(`+r+`, halfCR); } - `;var s=Kr(r);return u===1?` + `;var s=qr(r);return u===1?` float `+o+`(int index) { vec2 uv = vec2(0.5, (float(index + `+s+") + 0.5) / "+a+`.0); return sampleTexture(`+r+`, uv); @@ -474,17 +474,17 @@ Error generating stack: `+i.message+` vec2 uv = (vec2(col, row) + halfCR) / vec2(`+s+".0, "+u+`.0); return sampleTexture(`+o+`, uv); } - `}var l=eo(r),c=l.newShape,f=l.keptDims,d=c;if(d.length2,function(){return"Packed arg"+(n.charAt(0).toUpperCase()+n.slice(1))+" supports only inputs with rank above 2."});var o=e[e.length-1],i=Math.ceil(o/t);this.outputShape=e.slice(0,-1),i>1&&this.outputShape.push(i),r||this.variableNames.push("bestIndicesA");var a,u,s=this.outputShape,l=s.length,c=ke(l),f=Dt("coords",l);if(i===1){var d=ke(u=l+1);a=` + `}function ke(e){if(e<=1)return"int";if(e===2)return"ivec2";if(e===3)return"ivec3";if(e===4)return"ivec4";if(e===5)return"ivec5";if(e===6)return"ivec6";throw Error("GPU for rank "+e+" is not yet supported")}function No(e,t){var n=JSON.parse(JSON.stringify(e));return n.shapeInfo.logicalShape=t,n}function Ao(e,t){return t.map(function(n){return e[n]}).join(", ")}var Ub=function(e,t,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,I(e.length>2,function(){return"Packed arg"+(n.charAt(0).toUpperCase()+n.slice(1))+" supports only inputs with rank above 2."});var o=e[e.length-1],i=Math.ceil(o/t);this.outputShape=e.slice(0,-1),i>1&&this.outputShape.push(i),r||this.variableNames.push("bestIndicesA");var a,u,s=this.outputShape,l=s.length,c=ke(l),f=It("coords",l);if(i===1){var d=ke(u=l+1);a=` `+d+" sourceLocR = "+d+"("+f.join()+`, 0); ++`+f[l-1]+`; `+d+" sourceLocG = "+d+"("+f.join()+`, 0); @@ -767,7 +767,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+c+` sourceLocA = coords; --`+f[l-1]+`; `+c+` sourceLocB = coords; - --`+f[l-2]+";";var h=["x","y","z","w","u","v"].slice(0,u),p="."+h[u-1],m=h.map(function(E){return"int "+E}),g=Dt("sourceLocR",u-1).concat("inIdx.r"),v=Dt("sourceLocG",u-1).concat("inIdx.g"),y=Dt("sourceLocB",u-1).concat("inIdx.b"),x=Dt("sourceLocA",u-1).concat("inIdx.a"),w=n==="max"?"greaterThan":"lessThan",b=r?"":` + --`+f[l-2]+";";var h=["x","y","z","w","u","v"].slice(0,u),p="."+h[u-1],m=h.map(function(E){return"int "+E}),g=It("sourceLocR",u-1).concat("inIdx.r"),v=It("sourceLocG",u-1).concat("inIdx.g"),y=It("sourceLocB",u-1).concat("inIdx.b"),x=It("sourceLocA",u-1).concat("inIdx.a"),w=n==="max"?"greaterThan":"lessThan",b=r?"":` inIdx = round(vec4(getBestIndicesAChannel(`+g.join()+`), getBestIndicesAChannel(`+v.join()+`), getBestIndicesAChannel(`+y.join()+`), @@ -813,7 +813,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(bestIndex); } - `},Gb=function(e){this.variableNames=["dy"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=e.dilationHeight,a=e.dilationWidth,u=e.effectiveFilterHeight,s=e.effectiveFilterWidth,l=u-1-e.padInfo.top,c=s-1-e.padInfo.left,f=1/(t*n);this.userCode=` + `},Vb=function(e){this.variableNames=["dy"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=e.dilationHeight,a=e.dilationWidth,u=e.effectiveFilterHeight,s=e.effectiveFilterWidth,l=u-1-e.padInfo.top,c=s-1-e.padInfo.left,f=1/(t*n);this.userCode=` const ivec2 pads = ivec2(`+l+", "+c+`); const float avgMultiplier = float(`+f+`); @@ -855,7 +855,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},qb=function(e){this.variableNames=["dy"],this.outputShape=e.inShape;var t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=e.dilationDepth,s=e.dilationHeight,l=e.dilationWidth,c=e.effectiveFilterDepth,f=e.effectiveFilterHeight,d=e.effectiveFilterWidth,h=c-1-e.padInfo.front,p=f-1-e.padInfo.top,m=d-1-e.padInfo.left,g=1/(t*n*r);this.userCode=` + `},$b=function(e){this.variableNames=["dy"],this.outputShape=e.inShape;var t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=e.dilationDepth,s=e.dilationHeight,l=e.dilationWidth,c=e.effectiveFilterDepth,f=e.effectiveFilterHeight,d=e.effectiveFilterWidth,h=c-1-e.padInfo.front,p=f-1-e.padInfo.top,m=d-1-e.padInfo.left,g=1/(t*n*r);this.userCode=` const ivec3 pads = ivec3(`+h+", "+p+", "+m+`); const float avgMultiplier = float(`+g+`); @@ -911,7 +911,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},Kb=function(e,t,n,r,o,i){this.outputShape=[],this.variableNames=["x","mean","variance"],he(e,t),he(e,n);var a="0.0";r!=null&&(he(e,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var u="1.0";o!=null&&(he(e,o),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=` + `},Hb=function(e,t,n,r,o,i){this.outputShape=[],this.variableNames=["x","mean","variance"],he(e,t),he(e,n);var a="0.0";r!=null&&(he(e,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var u="1.0";o!=null&&(he(e,o),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=` void main() { float x = getXAtOutCoords(); float mean = getMeanAtOutCoords(); @@ -921,7 +921,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, float inv = scale * inversesqrt(variance + float(`+i+`)); setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1))); } - `},Xb=function(e,t,n,r,o,i){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],he(e,t),he(e,n);var a="vec4(0.0)";r!=null&&(he(e,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var u="vec4(1.0)";o!=null&&(he(e,o),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=` + `},jb=function(e,t,n,r,o,i){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],he(e,t),he(e,n);var a="vec4(0.0)";r!=null&&(he(e,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var u="vec4(1.0)";o!=null&&(he(e,o),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=e,this.userCode=` void main() { vec4 offset = `+a+`; vec4 scale = `+u+`; @@ -934,7 +934,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput((x - mean) * inv + offset); } - `},Yb="return areal * breal - aimag * bimag;",Qb="return areal * bimag + aimag * breal;",Gp=function(e,t,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=he(t,n),this.userCode=` + `},Gb="return areal * breal - aimag * bimag;",qb="return areal * bimag + aimag * breal;",Up=function(e,t,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=he(t,n),this.userCode=` float binaryOpComplex( float areal, float aimag, float breal, float bimag) { `+e+` @@ -947,7 +947,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, float bimag = getBImagAtOutCoords(); setOutput(binaryOpComplex(areal, aimag, breal, bimag)); } - `},Vl="return a + b;",$l="return a - b;",qp="return a * b;",P0="return (a < 0.) ? b * a : a;",ze=function(e,t,n){this.variableNames=["A","B"],this.outputShape=he(t,n),this.userCode=` + `},zl="return a + b;",Ul="return a - b;",Vp="return a * b;",D0="return (a < 0.) ? b * a : a;",ze=function(e,t,n){this.variableNames=["A","B"],this.outputShape=he(t,n),this.userCode=` float binaryOperation(float a, float b) { `+e+` } @@ -957,10 +957,10 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, float b = getBAtOutCoords(); setOutput(binaryOperation(a, b)); } - `},F0=` + `},T0=` vec4 aLessThanZero = vec4(lessThan(a, vec4(0.))); return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a); -`,Xn=function(e,t,n,r){r===void 0&&(r=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=he(t,n);var o=this.outputShape.length,i="";if(r)if(o===0||Z(this.outputShape)===1)i=` +`,qn=function(e,t,n,r){r===void 0&&(r=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=he(t,n);var o=this.outputShape.length,i="";if(r)if(o===0||Z(this.outputShape)===1)i=` result.y = 0.; result.z = 0.; result.w = 0.; @@ -970,7 +970,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, result.y = (coords + 1) >= `+this.outputShape[0]+` ? 0. : result.y; result.z = 0.; result.w = 0.; - `;else{var a=Dt("coords",o);i+=` + `;else{var a=It("coords",o);i+=` bool nextRowOutOfBounds = (`+a[o-2]+" + 1) >= "+this.outputShape[o-2]+`; bool nextColOutOfBounds = @@ -992,7 +992,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(result); } - `},Jb=function(){function e(t){this.variableNames=["A"],this.outputShape=t,this.userCode=` + `},Kb=function(){function e(t){this.variableNames=["A"],this.outputShape=t,this.userCode=` uniform float minVal; uniform float maxVal; @@ -1005,7 +1005,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(clamp(value, minVal, maxVal)); } - `}return e.prototype.getCustomSetupFunc=function(t,n){var r=this;return function(o,i){r.minLoc==null&&(r.minLoc=o.getUniformLocationNoThrow(i,"minVal"),r.maxLoc=o.getUniformLocationNoThrow(i,"maxVal")),o.gl.uniform1f(r.minLoc,t),o.gl.uniform1f(r.maxLoc,n)}},e}(),Zb=function(){function e(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode=` + `}return e.prototype.getCustomSetupFunc=function(t,n){var r=this;return function(o,i){r.minLoc==null&&(r.minLoc=o.getUniformLocationNoThrow(i,"minVal"),r.maxLoc=o.getUniformLocationNoThrow(i,"maxVal")),o.gl.uniform1f(r.minLoc,t),o.gl.uniform1f(r.maxLoc,n)}},e}(),Xb=function(){function e(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode=` uniform float minVal; uniform float maxVal; @@ -1019,7 +1019,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(clamp(value, vec4(minVal), vec4(maxVal))); } - `}return e.prototype.getCustomSetupFunc=function(t,n){var r=this;return function(o,i){r.minLoc==null&&(r.minLoc=o.getUniformLocationNoThrow(i,"minVal"),r.maxLoc=o.getUniformLocationNoThrow(i,"maxVal")),o.gl.uniform1f(r.minLoc,t),o.gl.uniform1f(r.maxLoc,n)}},e}(),eC=function(e){this.variableNames=["real","imag"],this.outputShape=e,this.userCode=` + `}return e.prototype.getCustomSetupFunc=function(t,n){var r=this;return function(o,i){r.minLoc==null&&(r.minLoc=o.getUniformLocationNoThrow(i,"minVal"),r.maxLoc=o.getUniformLocationNoThrow(i,"maxVal")),o.gl.uniform1f(r.minLoc,t),o.gl.uniform1f(r.maxLoc,n)}},e}(),Yb=function(e){this.variableNames=["real","imag"],this.outputShape=e,this.userCode=` void main() { float re = abs(getRealAtOutCoords()); float im = abs(getImagAtOutCoords()); @@ -1032,7 +1032,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx)) ); } - `},tC=function(e){this.outputShape=[],this.outputShape=mi(e,1),this.variableNames=e.map(function(u,s){return"T"+s});var t=new Array(e.length-1);t[0]=e[0][1];for(var n=1;n= "+u[s-1]+`) { return getChannel( - getT`+s+"("+au(a,l,h)+`), - vec2(`+au(c,l,h)+`)); + getT`+s+"("+ou(a,l,h)+`), + vec2(`+ou(c,l,h)+`)); }`}var p=u.length,m=u[u.length-1];d+=` return getChannel( - getT`+p+"("+au(a,l,m)+`), - vec2(`+au(c,l,m)+"));",this.userCode=` + getT`+p+"("+ou(a,l,m)+`), + vec2(`+ou(c,l,m)+"));",this.userCode=` float getValue(`+a.map(function(g){return"int "+g})+`) { `+d+` } @@ -1078,7 +1078,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(result); } - `};function au(e,t,n){var r=e.indexOf(t);return e.map(function(o,i){return i===r?o+" - "+n:o}).join()}var rC=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,o=e.padInfo.left,i=e.dataFormat==="channelsLast";this.userCode=` + `};function ou(e,t,n){var r=e.indexOf(t);return e.map(function(o,i){return i===r?o+" - "+n:o}).join()}var Zb=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,o=e.padInfo.left,i=e.dataFormat==="channelsLast";this.userCode=` void main() { ivec4 coords = getOutputCoords(); int wR = coords.x; @@ -1120,7 +1120,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},oC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=e.dataFormat==="channelsLast",a=t-1-e.padInfo.top,u=n-1-e.padInfo.left,s=i?1:2,l=i?2:3,c=i?3:1;this.userCode=` + `},eC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=e.dataFormat==="channelsLast",a=t-1-e.padInfo.top,u=n-1-e.padInfo.left,s=i?1:2,l=i?2:3,c=i?3:1;this.userCode=` const ivec2 pads = ivec2(`+a+", "+u+`); void main() { @@ -1173,7 +1173,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},iC=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,o=e.padInfo.front,i=e.padInfo.top,a=e.padInfo.left;this.userCode=` + `},tC=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,o=e.padInfo.front,i=e.padInfo.top,a=e.padInfo.left;this.userCode=` void main() { ivec5 coords = getOutputCoords(); int wF = coords.x; @@ -1215,7 +1215,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},aC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=t-1-e.padInfo.front,s=n-1-e.padInfo.top,l=r-1-e.padInfo.left;this.userCode=` + `},nC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterDepth,n=e.filterHeight,r=e.filterWidth,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=t-1-e.padInfo.front,s=n-1-e.padInfo.top,l=r-1-e.padInfo.left;this.userCode=` const ivec3 pads = ivec3(`+u+", "+s+", "+l+`); void main() { @@ -1272,7 +1272,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},uC=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,o=e.padInfo.left,i=e.outChannels/e.inChannels;this.userCode=` + `},rC=function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,o=e.padInfo.left,i=e.outChannels/e.inChannels;this.userCode=` void main() { ivec4 coords = getOutputCoords(); int wR = coords.x; @@ -1307,7 +1307,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},sC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=t-1-e.padInfo.top,a=n-1-e.padInfo.left,u=e.outChannels/e.inChannels;this.userCode=` + `},oC=function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,o=e.strideWidth,i=t-1-e.padInfo.top,a=n-1-e.padInfo.left,u=e.outChannels/e.inChannels;this.userCode=` const ivec2 pads = ivec2(`+i+", "+a+`); void main() { @@ -1352,7 +1352,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},Kp=function(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=e.outShape;var o=e.padInfo.top,i=e.padInfo.left,a=e.strideHeight,u=e.strideWidth,s=e.dilationHeight,l=e.dilationWidth,c=e.filterHeight,f=e.filterWidth,d=4*Math.floor(e.inChannels/4),h=e.inChannels%4,p=e.dataFormat==="channelsLast",m=p?1:2,g=p?2:3,v=p?3:1,y="",x="";n&&(y=r?`float activation(float a) { + `},$p=function(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=e.outShape;var o=e.padInfo.top,i=e.padInfo.left,a=e.strideHeight,u=e.strideWidth,s=e.dilationHeight,l=e.dilationWidth,c=e.filterHeight,f=e.filterWidth,d=4*Math.floor(e.inChannels/4),h=e.inChannels%4,p=e.dataFormat==="channelsLast",m=p?1:2,g=p?2:3,v=p?3:1,y="",x="";n&&(y=r?`float activation(float a) { float b = getPreluActivationWeightsAtOutCoords(); `+n+` }`:` @@ -1483,7 +1483,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+x+` setOutput(result); } - `},lC=function(e){this.variableNames=["x","W"],this.outputShape=e.outShape;var t=e.padInfo.front,n=e.padInfo.top,r=e.padInfo.left,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=e.dilationDepth,s=e.dilationHeight,l=e.dilationWidth,c=e.filterDepth,f=e.filterHeight,d=e.filterWidth,h=4*Math.floor(e.inChannels/4),p=e.inChannels%4;this.userCode=` + `},iC=function(e){this.variableNames=["x","W"],this.outputShape=e.outShape;var t=e.padInfo.front,n=e.padInfo.top,r=e.padInfo.left,o=e.strideDepth,i=e.strideHeight,a=e.strideWidth,u=e.dilationDepth,s=e.dilationHeight,l=e.dilationWidth,c=e.filterDepth,f=e.filterHeight,d=e.filterWidth,h=4*Math.floor(e.inChannels/4),p=e.inChannels%4;this.userCode=` const ivec3 strides = ivec3(`+o+", "+i+", "+a+`); const ivec3 pads = ivec3(`+t+", "+n+", "+r+`); @@ -1571,7 +1571,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},Xp=function(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=e.outShape;var o=e.inHeight,i=e.inWidth,a=e.padInfo.top,u=e.padInfo.left,s=e.strideHeight,l=e.strideWidth,c=e.dilationHeight,f=e.dilationWidth,d=e.filterHeight,h=e.filterWidth,p=e.outChannels/e.inChannels,m="",g="";n&&(m=r?`float activation(float a) { + `},Hp=function(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.outputShape=e.outShape;var o=e.inHeight,i=e.inWidth,a=e.padInfo.top,u=e.padInfo.left,s=e.strideHeight,l=e.strideWidth,c=e.dilationHeight,f=e.dilationWidth,d=e.filterHeight,h=e.filterWidth,p=e.outChannels/e.inChannels,m="",g="";n&&(m=r?`float activation(float a) { float b = getPreluActivationWeightsAtOutCoords(); `+n+` }`:` @@ -1624,7 +1624,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+g+` setOutput(result); } - `},Yp=function(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=null),r===void 0&&(r=!1),this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e.outShape;for(var o=e.inHeight,i=e.inWidth,a=e.padInfo.top,u=e.padInfo.left,s=e.strideHeight,l=e.strideWidth,c=e.dilationHeight,f=e.dilationWidth,d=e.filterHeight,h=e.filterWidth,p=h,m="int xR; int xC; int xCOffset;",g=0;g= 0 && xR < `+o+` && @@ -1774,7 +1774,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+b+` setOutput(result); } - `},cC=function(e,t,n,r,o){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var i=e[0],a=e[1],u=e[2],s=e[3],l=t[0],c=n[0],f=n[1];this.outputShape=[l,c,f,s];var d=r==="bilinear"?1:0,h=[a-1+".0",u-1+".0"],p=h[0],m=h[1],g=c>1?[""+(a-1)/(c-1),"(y2-y1) * height_ratio","y1*"+p+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+p],v=g[0],y=g[1],x=g[2],w=f>1?[""+(u-1)/(f-1),"(x2-x1) * width_ratio","x1*"+m+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+m],b=w[0],C=w[1],_=w[2];this.userCode=` + `},aC=function(e,t,n,r,o){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var i=e[0],a=e[1],u=e[2],s=e[3],l=t[0],c=n[0],f=n[1];this.outputShape=[l,c,f,s];var d=r==="bilinear"?1:0,h=[a-1+".0",u-1+".0"],p=h[0],m=h[1],g=c>1?[""+(a-1)/(c-1),"(y2-y1) * height_ratio","y1*"+p+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+p],v=g[0],y=g[1],x=g[2],w=f>1?[""+(u-1)/(f-1),"(x2-x1) * width_ratio","x1*"+m+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+m],b=w[0],C=w[1],_=w[2];this.userCode=` const float height_ratio = float(`+v+`); const float width_ratio = float(`+b+`); void main() { @@ -1835,14 +1835,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(newValue); } } - `},fC=function(e,t,n){this.variableNames=["x"],this.outputShape=e;var r=e.length,o=e[e.length-1],i=n?"<":">";this.userCode=` + `},uC=function(e,t,n){this.variableNames=["x"],this.outputShape=e;var r=e.length,o=e[e.length-1],i=n?"<":">";this.userCode=` int getIndex(int i) { `+(n?"return "+o+" -i - 1;":"return i;")+` } void main() { `+ke(r)+` coords = getOutputCoords(); - int end = `+Qp(r,"coords")+`; + int end = `+Gp(r,"coords")+`; float val = 0.0; for (int i = `+o+` - 1; i >= 0; i -= 1) { int idx = getIndex(i); @@ -1852,14 +1852,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, if (idx == end && `+t+`) { continue; } - `+Qp(r,"coords")+` = idx; + `+Gp(r,"coords")+` = idx; val += getX(`+function(a,u){if(a===1)return""+u;if(a===2)return u+".x, "+u+".y";if(a===3)return u+".x, "+u+".y, "+u+".z";if(a===4)return u+".x, "+u+".y, "+u+".z, "+u+".w";throw Error("Cumulative sum for rank "+a+" is not yet supported")}(r,"coords")+`); } setOutput(val); } - `};function Qp(e,t){if(e===1)return""+t;if(e===2)return t+".y";if(e===3)return t+".z";if(e===4)return t+".w";throw Error("Cumulative sum for rank "+e+" is not yet supported")}var dC=function(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=ga.DENSE;var t=Xi(e),n=gt();this.outputShape=e,this.userCode=` + `};function Gp(e,t){if(e===1)return""+t;if(e===2)return t+".y";if(e===3)return t+".z";if(e===4)return t+".w";throw Error("Cumulative sum for rank "+e+" is not yet supported")}var sC=function(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=va.DENSE;var t=qi(e),n=gt();this.outputShape=e,this.userCode=` ivec3 outCoordsFromFlatIndex(int index) { - `+oo(["r","c","d"],e)+` + `+no(["r","c","d"],e)+` return ivec3(r, c, d); } @@ -1878,9 +1878,9 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+n.output+` = result; } - `},hC=function(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=ga.DENSE;var t=Xi(e),n=gt();this.outputShape=e,this.userCode=` + `},lC=function(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=va.DENSE;var t=qi(e),n=gt();this.outputShape=e,this.userCode=` ivec3 outCoordsFromFlatIndex(int index) { - `+oo(["r","c","d"],e)+` + `+no(["r","c","d"],e)+` return ivec3(r, c, d); } @@ -1899,7 +1899,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+n.output+` = result; } - `},pC=function(){function e(t,n,r){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=n,this.dataFormat=r,this.userCode=` + `},cC=function(){function e(t,n,r){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=n,this.dataFormat=r,this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords[0]; @@ -1918,29 +1918,29 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, float result = `+this.getInputSamplingString()+`; setOutput(result); } - `}return e.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},e.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},e.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},e.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},e.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},e}(),vC=function(e){this.variableNames=["X"],this.outputShape=[e,e],this.userCode=` + `}return e.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},e.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},e.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},e.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},e.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},e}(),fC=function(e){this.variableNames=["X"],this.outputShape=[e,e],this.userCode=` void main() { ivec2 coords = getOutputCoords(); float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0; setOutput(val); } - `},mC=function(e){this.variableNames=["A"],this.outTexUsage=Vt.DOWNLOAD;var t=gt();this.outputShape=e,this.userCode=` - `+N0+` + `},dC=function(e){this.variableNames=["A"],this.outTexUsage=Vt.DOWNLOAD;var t=gt();this.outputShape=e,this.userCode=` + `+R0+` void main() { float x = getAAtOutCoords(); `+t.output+` = encode_float(x); } - `},gC=function(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=Vt.DOWNLOAD;var t=gt();this.outputShape=e,this.userCode=` - `+N0+` + `},hC=function(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=Vt.DOWNLOAD;var t=gt();this.outputShape=e,this.userCode=` + `+R0+` void main() { ivec3 coords = getOutputCoords(); float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z)); `+t.output+` = encode_float(x); } - `},yC=function(e,t,n){n===void 0&&(n=!1),this.variableNames=["A"];var r=gt(),o=t[0],i=t[1];this.outputShape=e;var a="result";n&&(a="floor(result * 255. + 0.5)"),this.userCode=` - `+Id(e)+` + `},pC=function(e,t,n){n===void 0&&(n=!1),this.variableNames=["A"];var r=gt(),o=t[0],i=t[1];this.outputShape=e;var a="result";n&&(a="floor(result * 255. + 0.5)"),this.userCode=` + `+kd(e)+` void main() { ivec3 coords = getOutputCoords(); @@ -1969,7 +1969,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+r.output+" = vec4("+a+`, 0., 0., 0.); } - `},xC=function(e,t,n){n===void 0&&(n=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var r=gt(),o=t[0],i=t[1];this.outputShape=e;var a="",u="result";n&&(u="floor(result * 255. + 0.5)");for(var s=0;s<=1;s++)for(var l=0;l<=1;l++){var c=2*s+l;a+=` + `},vC=function(e,t,n){n===void 0&&(n=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var r=gt(),o=t[0],i=t[1];this.outputShape=e;var a="",u="result";n&&(u="floor(result * 255. + 0.5)");for(var s=0;s<=1;s++)for(var l=0;l<=1;l++){var c=2*s+l;a+=` localCoords = coords; if(localCoords[2] + `+l+" < "+e[2]+`) { localCoords[2] += `+l+`; @@ -1998,7 +1998,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } } `}this.userCode=` - `+Id(e)+` + `+kd(e)+` void main() { ivec3 coords = getOutputCoords(); @@ -2013,7 +2013,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+r.output+" = "+u+`; } - `},wC="return real * expR - imag * expI;",bC="return real * expI + imag * expR;",Jp=function(e,t,n){this.variableNames=["real","imag"];var r=t[1];this.outputShape=t;var o=n?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,i=n?r+".0":"1.0";this.userCode=` + `},mC="return real * expR - imag * expI;",gC="return real * expI + imag * expR;",qp=function(e,t,n){this.variableNames=["real","imag"];var r=t[1];this.outputShape=t;var o=n?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,i=n?r+".0":"1.0";this.userCode=` const float exponentMultiplier = `+o+`; float unaryOpComplex(float real, float expR, float imag, float expI) { @@ -2046,18 +2046,18 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, ivec2 coords = getOutputCoords(); setOutput(mulMatDFT(coords[0], coords[1])); } - `},CC=function(){function e(t,n){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode=` + `},yC=function(){function e(t,n){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode=` uniform float value; void main() { // Input can be obtained from uniform value. setOutput(value); } - `}return e.prototype.getCustomSetupFunc=function(t){var n=this;return function(r,o){n.valueLoc==null&&(n.valueLoc=r.getUniformLocationNoThrow(o,"value")),r.gl.uniform1f(n.valueLoc,t)}},e}(),_C=function(e,t,n){this.variableNames=["A","indices"];var r=e.slice();r[n]=t,this.outputShape=r,this.rank=r.length;var o=ke(this.rank),i=function(a,u){var s=a.length;if(s>4)throw Error("Gather for rank "+s+" is not yet supported");if(s===1)return"int(getIndices(resRC))";for(var l=["resRC.x","resRC.y","resRC.z","resRC.w"],c=[],f=0;f4)throw Error("Gather for rank "+s+" is not yet supported");if(s===1)return"int(getIndices(resRC))";for(var l=["resRC.x","resRC.y","resRC.z","resRC.w"],c=[],f=0;f1?"strides[j]":"strides";this.userCode=` + `},wC=function(e,t,n){this.sliceDim=e,this.strides=t,this.variableNames=["x","indices"],this.outputShape=n;var r=ke(t.length),o=ke(n.length),i=this.sliceDim>1?"strides[j]":"strides";this.userCode=` `+r+" strides = "+r+"("+this.strides+`); void main() { `+o+` coords = getOutputCoords(); @@ -2068,7 +2068,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(getX(flattenIndex, coords[1])); } - `};function SC(e,t){var n=gt();return w2(e,t,n.version+` + `};function bC(e,t){var n=gt();return m2(e,t,n.version+` precision highp float; `+n.attribute+` vec3 clipSpacePos; `+n.attribute+` vec2 uv; @@ -2077,7 +2077,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, void main() { gl_Position = vec4(clipSpacePos, 1); resultUV = uv; - }`)}function kC(e,t){return S2(e,t,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function RC(e,t){return k2(e,t,new Uint16Array([0,1,2,2,1,3]))}function Aa(e,t,n,r,o,i,a){I2(n,r);var u=R2(e,t),s=e.TEXTURE_2D;return ee(e,t,function(){return e.bindTexture(s,u)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_MIN_FILTER,e.NEAREST)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_MAG_FILTER,e.NEAREST)}),ee(e,t,function(){return e.texImage2D(s,0,o,n,r,0,i,a,null)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)}),u}function IC(e,t,n,r,o){var i=Ls(n,r);return Aa(e,t,i[0],i[1],o.internalFormatFloat,o.textureFormatFloat,e.FLOAT)}function DC(e,t,n,r,o){var i=Ls(n,r);return Aa(e,t,i[0],i[1],o.internalFormatHalfFloat,o.textureFormatFloat,o.textureTypeHalfFloat)}function TC(e,t,n,r,o){var i=Ls(n,r);return Aa(e,t,i[0],i[1],e.RGBA,e.RGBA,e.UNSIGNED_BYTE)}function NC(e,t,n,r,o){var i=Na(n,r);return Aa(e,t,i[0],i[1],o.internalFormatPackedFloat,e.RGBA,e.FLOAT)}function AC(e,t,n,r,o){var i=Na(n,r);return Aa(e,t,i[0],i[1],o.internalFormatPackedHalfFloat,e.RGBA,o.textureTypeHalfFloat)}function PC(e,t,n,r){return ee(e,t,function(){return e.bindBuffer(e.ARRAY_BUFFER,r)}),Wp(e,t,n,"clipSpacePos",r,3,20,0)&&Wp(e,t,n,"uv",r,2,20,12)}function FC(e,t,n,r,o,i,a){var u,s,l;ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)}),i instanceof Uint8Array?(u=new Uint8Array(r*o*4),s=e.UNSIGNED_BYTE,l=e.RGBA):(u=new Float32Array(r*o*4),s=e.FLOAT,l=a.internalFormatPackedFloat),u.set(i),ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,l,r,o,0,e.RGBA,s,u)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)})}function MC(e,t,n,r){ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)}),r.data instanceof Uint8Array?ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r.width,r.height,0,e.RGBA,e.UNSIGNED_BYTE,r.data)}):ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)})}function OC(e,t,n,r,o){var i=e.createBuffer();ee(e,t,function(){return e.bindBuffer(e.PIXEL_PACK_BUFFER,i)});var a=16*n*r;return ee(e,t,function(){return e.bufferData(e.PIXEL_PACK_BUFFER,a,e.STREAM_READ)}),ee(e,t,function(){return e.readPixels(0,0,r,n,e.RGBA,e.FLOAT,0)}),ee(e,t,function(){return e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}),i}function BC(e,t,n){var r=e,o=new Float32Array(n);return r.bindBuffer(r.PIXEL_PACK_BUFFER,t),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,o),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),o}function LC(e,t,n,r,o){var i=Ls(n,r),a=i[0],u=i[1],s=new Uint8Array(n*r*4);return ee(e,t,function(){return e.readPixels(0,0,a,u,o.downloadTextureFormat,e.UNSIGNED_BYTE,s)}),new Float32Array(s.buffer)}function WC(e,t,n,r,o,i,a,u){var s=e,l=new Float32Array(function(c,f){var d=Na(c,f);return d[0]*d[1]*4}(i,a));return s.bindBuffer(s.PIXEL_PACK_BUFFER,t),s.getBufferSubData(s.PIXEL_PACK_BUFFER,0,l),s.bindBuffer(s.PIXEL_PACK_BUFFER,null),l}function zC(e,t,n,r){var o=new Float32Array(n*r*4);return ee(e,t,function(){return e.readPixels(0,0,r,n,e.RGBA,e.FLOAT,o)}),o}var UC=function(){function e(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var n=z().getNumber("WEBGL_VERSION");t!=null?(this.gl=t,v2(n,t)):this.gl=Vn(n);var r="WEBGL_color_buffer_float";if(z().getNumber("WEBGL_VERSION")===1){if(this.textureFloatExtension=nu(this.gl,this.debug,"OES_texture_float"),nn(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=nu(this.gl,this.debug,"OES_texture_half_float");else if(z().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(r),nn(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=nu(this.gl,this.debug,"EXT_color_buffer_half_float");else if(z().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(r="EXT_color_buffer_float",nn(this.gl,r))this.colorBufferFloatExtension=this.gl.getExtension(r);else{if(!nn(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=kC(this.gl,this.debug),this.indexBuffer=RC(this.gl,this.debug),this.framebuffer=D2(this.gl,this.debug),this.textureConfig=yd(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(e.prototype,"debug",{get:function(){return z().getBool("DEBUG")},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){var t=this;if(!this.disposed){this.program!=null&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),this.outputTexture!=null&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var n=this.gl;ee(n,this.debug,function(){return n.finish()}),ee(n,this.debug,function(){return n.bindFramebuffer(n.FRAMEBUFFER,null)}),ee(n,this.debug,function(){return n.deleteFramebuffer(t.framebuffer)}),ee(n,this.debug,function(){return n.bindBuffer(n.ARRAY_BUFFER,null)}),ee(n,this.debug,function(){return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null)}),ee(n,this.debug,function(){return n.deleteBuffer(t.indexBuffer)}),this.disposed=!0}},e.prototype.createFloat32MatrixTexture=function(t,n){return this.throwIfDisposed(),IC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createFloat16MatrixTexture=function(t,n){return this.throwIfDisposed(),DC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createUnsignedBytesMatrixTexture=function(t,n){return this.throwIfDisposed(),TC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.uploadPixelDataToTexture=function(t,n){this.throwIfDisposed(),MC(this.gl,this.debug,t,n)},e.prototype.uploadDenseMatrixToTexture=function(t,n,r,o){this.throwIfDisposed(),FC(this.gl,this.debug,t,n,r,o,this.textureConfig)},e.prototype.createFloat16PackedMatrixTexture=function(t,n){return this.throwIfDisposed(),AC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createPackedMatrixTexture=function(t,n){return this.throwIfDisposed(),NC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.deleteMatrixTexture=function(t){var n=this;this.throwIfDisposed(),this.outputTexture===t&&(zp(this.gl,this.debug,this.framebuffer),this.outputTexture=null),ee(this.gl,this.debug,function(){return n.gl.deleteTexture(t)})},e.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(t,n,r){var o=this;return this.downloadMatrixDriver(t,function(){return LC(o.gl,o.debug,n,r,o.textureConfig)})},e.prototype.downloadPackedMatrixFromBuffer=function(t,n,r,o,i,a){return WC(this.gl,t,0,0,0,i,a,this.textureConfig)},e.prototype.downloadFloat32MatrixFromBuffer=function(t,n){return BC(this.gl,t,n)},e.prototype.createBufferFromTexture=function(t,n,r){this.bindTextureToFrameBuffer(t);var o=OC(this.gl,this.debug,n,r,this.textureConfig);return this.unbindTextureToFrameBuffer(),o},e.prototype.createAndWaitForFence=function(){var t=this.createFence(this.gl);return this.pollFence(t)},e.prototype.createFence=function(t){var n,r,o=this;if(z().getBool("WEBGL_FENCE_API_ENABLED")){var i=t,a=i.fenceSync(i.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),r=function(){var u=i.clientWaitSync(a,0,0);return u===i.ALREADY_SIGNALED||u===i.CONDITION_SATISFIED},n=a}else z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(n=this.beginQuery(),this.endQuery(),r=function(){return o.isQueryAvailable(n,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):r=function(){return!0};return{query:n,isFencePassed:r}},e.prototype.downloadMatrixFromPackedTexture=function(t,n,r){var o=this;return this.downloadMatrixDriver(t,function(){return zC(o.gl,o.debug,n,r)})},e.prototype.createProgram=function(t){this.throwIfDisposed();var n=this.gl,r=b2(n,this.debug,t),o=SC(n,this.debug),i=_2(n,this.debug);return ee(n,this.debug,function(){return n.attachShader(i,o)}),ee(n,this.debug,function(){return n.attachShader(i,r)}),E2(n,this.debug,i),this.debug&&Ll(n,this.debug,i),this.vertexAttrsAreBound||(this.setProgram(i),this.vertexAttrsAreBound=PC(n,this.debug,this.program,this.vertexBuffer)),i},e.prototype.deleteProgram=function(t){var n=this;this.throwIfDisposed(),t===this.program&&(this.program=null),t!=null&&ee(this.gl,this.debug,function(){return n.gl.deleteProgram(t)})},e.prototype.setProgram=function(t){var n=this;this.throwIfDisposed(),this.program=t,this.program!=null&&this.debug&&Ll(this.gl,this.debug,this.program),ee(this.gl,this.debug,function(){return n.gl.useProgram(t)})},e.prototype.getUniformLocation=function(t,n,r){return r===void 0&&(r=!0),this.throwIfDisposed(),r?N2(this.gl,this.debug,t,n):A2(this.gl,t,n)},e.prototype.getAttributeLocation=function(t,n){var r=this;return this.throwIfDisposed(),ee(this.gl,this.debug,function(){return r.gl.getAttribLocation(t,n)})},e.prototype.getUniformLocationNoThrow=function(t,n){return this.throwIfDisposed(),this.gl.getUniformLocation(t,n)},e.prototype.setInputMatrixTexture=function(t,n,r){this.throwIfDisposed(),this.throwIfNoProgram(),P2(this.gl,this.debug,this.program,t,n,r)},e.prototype.setOutputMatrixTexture=function(t,n,r){this.setOutputMatrixTextureDriver(t,r,n)},e.prototype.setOutputPackedMatrixTexture=function(t,n,r){this.throwIfDisposed();var o=Na(n,r),i=o[0],a=o[1];this.setOutputMatrixTextureDriver(t,i,a)},e.prototype.setOutputMatrixWriteRegion=function(t,n,r,o){this.setOutputMatrixWriteRegionDriver(r,t,o,n)},e.prototype.setOutputPackedMatrixWriteRegion=function(t,n,r,o){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},e.prototype.debugValidate=function(){this.program!=null&&Ll(this.gl,this.debug,this.program),ru(this.gl)},e.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var t=this.gl;this.debug&&this.debugValidate(),ee(t,this.debug,function(){return t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)})},e.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),ee(this.gl,this.debug,function(){return t.gl.finish()})},e.prototype.getQueryTimerExtension=function(){return this.disjointQueryTimerExtension==null&&(this.disjointQueryTimerExtension=nu(this.gl,this.debug,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},e.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},e.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},e.prototype.beginQuery=function(){if(z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var t=this.gl,n=this.getQueryTimerExtensionWebGL2(),r=t.createQuery();return t.beginQuery(n.TIME_ELAPSED_EXT,r),r}var o=this.getQueryTimerExtensionWebGL1(),i=o.createQueryEXT();return o.beginQueryEXT(o.TIME_ELAPSED_EXT,i),i},e.prototype.endQuery=function(){if(z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")!==2){var t=this.getQueryTimerExtensionWebGL1();t.endQueryEXT(t.TIME_ELAPSED_EXT)}else{var n=this.gl,r=this.getQueryTimerExtensionWebGL2();n.endQuery(r.TIME_ELAPSED_EXT)}},e.prototype.waitForQueryAndGetTime=function(t){return Q(this,void 0,void 0,function(){var n=this;return J(this,function(r){switch(r.label){case 0:return[4,Pp(function(){return n.disposed||n.isQueryAvailable(t,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return r.sent(),[2,this.getQueryTime(t,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},e.prototype.getQueryTime=function(t,n){if(n===0)return null;if(n===2){var r=this.gl;return r.getQueryParameter(t,r.QUERY_RESULT)/1e6}var o=this.getQueryTimerExtensionWebGL1();return o.getQueryObjectEXT(t,o.QUERY_RESULT_EXT)/1e6},e.prototype.isQueryAvailable=function(t,n){if(n===0)return!0;if(n===2){var r=this.gl,o=this.getQueryTimerExtensionWebGL2(),i=r.getQueryParameter(t,r.QUERY_RESULT_AVAILABLE);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(o.GPU_DISJOINT_EXT)),i&&!this.disjoint}return i=(o=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t,o.QUERY_RESULT_AVAILABLE_EXT),this.disjoint==null&&(this.disjoint=this.gl.getParameter(o.GPU_DISJOINT_EXT)),i&&!this.disjoint},e.prototype.pollFence=function(t){var n=this;return new Promise(function(r){n.addItemToPoll(function(){return t.isFencePassed()},function(){return r()})})},e.prototype.pollItems=function(){for(var t=function(r){for(var o=0;o1||Pp(function(){return r.pollItems(),r.itemsToPoll.length===0})},e.prototype.bindTextureToFrameBuffer=function(t){this.throwIfDisposed(),Wl(this.gl,this.debug,t,this.framebuffer),this.debug&&ru(this.gl)},e.prototype.unbindTextureToFrameBuffer=function(){this.outputTexture!=null?(Wl(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&ru(this.gl)):zp(this.gl,this.debug,this.framebuffer)},e.prototype.downloadMatrixDriver=function(t,n){this.bindTextureToFrameBuffer(t);var r=n();return this.unbindTextureToFrameBuffer(),r},e.prototype.setOutputMatrixTextureDriver=function(t,n,r){this.throwIfDisposed();var o=this.gl;Wl(o,this.debug,t,this.framebuffer),this.debug&&ru(o),this.outputTexture=t,ee(o,this.debug,function(){return o.viewport(0,0,n,r)}),ee(o,this.debug,function(){return o.scissor(0,0,n,r)})},e.prototype.setOutputMatrixWriteRegionDriver=function(t,n,r,o){var i=this;this.throwIfDisposed(),ee(this.gl,this.debug,function(){return i.gl.scissor(t,n,r,o)})},e.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},e.prototype.throwIfNoProgram=function(){if(this.program==null)throw new Error("No GPU program is currently set.")},e}();function Zp(e,t){if(e.length!==t.length)throw Error("Binary was compiled with "+e.length+" inputs, but was executed with "+t.length+" inputs");e.forEach(function(n,r){var o=n.logicalShape,i=t[r],a=i.shape;if(!ot(o,a))throw Error("Binary was compiled with different shapes than the current args. Shapes "+o+" and "+a+" must match");if(!n.isUniform||!i.isUniform){var u=n.texShape,s=i.isUniform?null:i.texData.texShape;if(!ot(u,s))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+u+" and "+s+" must match")}})}var VC=function(e,t,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;for(var r=n.filterWidth,o=n.inChannels,i=n.strideWidth,a=n.strideHeight,u=n.padInfo,s=n.outWidth,l=n.dilationWidth,c=n.dilationHeight,f=n.dataFormat,d=u.left,h=u.top,p=o*r,m=gt(),g=f==="channelsLast",v=g?0:1,y=g?1:2,x="",w=0;w<=1;w++)for(var b=0;b<=1;b++)x+=` + }`)}function CC(e,t){return b2(e,t,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function _C(e,t){return C2(e,t,new Uint16Array([0,1,2,2,1,3]))}function Ta(e,t,n,r,o,i,a){E2(n,r);var u=_2(e,t),s=e.TEXTURE_2D;return ee(e,t,function(){return e.bindTexture(s,u)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_MIN_FILTER,e.NEAREST)}),ee(e,t,function(){return e.texParameteri(s,e.TEXTURE_MAG_FILTER,e.NEAREST)}),ee(e,t,function(){return e.texImage2D(s,0,o,n,r,0,i,a,null)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)}),u}function EC(e,t,n,r,o){var i=Os(n,r);return Ta(e,t,i[0],i[1],o.internalFormatFloat,o.textureFormatFloat,e.FLOAT)}function SC(e,t,n,r,o){var i=Os(n,r);return Ta(e,t,i[0],i[1],o.internalFormatHalfFloat,o.textureFormatFloat,o.textureTypeHalfFloat)}function kC(e,t,n,r,o){var i=Os(n,r);return Ta(e,t,i[0],i[1],e.RGBA,e.RGBA,e.UNSIGNED_BYTE)}function RC(e,t,n,r,o){var i=Da(n,r);return Ta(e,t,i[0],i[1],o.internalFormatPackedFloat,e.RGBA,e.FLOAT)}function IC(e,t,n,r,o){var i=Da(n,r);return Ta(e,t,i[0],i[1],o.internalFormatPackedHalfFloat,e.RGBA,o.textureTypeHalfFloat)}function DC(e,t,n,r){return ee(e,t,function(){return e.bindBuffer(e.ARRAY_BUFFER,r)}),Fp(e,t,n,"clipSpacePos",r,3,20,0)&&Fp(e,t,n,"uv",r,2,20,12)}function TC(e,t,n,r,o,i,a){var u,s,l;ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)}),i instanceof Uint8Array?(u=new Uint8Array(r*o*4),s=e.UNSIGNED_BYTE,l=e.RGBA):(u=new Float32Array(r*o*4),s=e.FLOAT,l=a.internalFormatPackedFloat),u.set(i),ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,l,r,o,0,e.RGBA,s,u)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)})}function NC(e,t,n,r){ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,n)}),r.data instanceof Uint8Array?ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r.width,r.height,0,e.RGBA,e.UNSIGNED_BYTE,r.data)}):ee(e,t,function(){return e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r)}),ee(e,t,function(){return e.bindTexture(e.TEXTURE_2D,null)})}function AC(e,t,n,r,o){var i=e.createBuffer();ee(e,t,function(){return e.bindBuffer(e.PIXEL_PACK_BUFFER,i)});var a=16*n*r;return ee(e,t,function(){return e.bufferData(e.PIXEL_PACK_BUFFER,a,e.STREAM_READ)}),ee(e,t,function(){return e.readPixels(0,0,r,n,e.RGBA,e.FLOAT,0)}),ee(e,t,function(){return e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}),i}function PC(e,t,n){var r=e,o=new Float32Array(n);return r.bindBuffer(r.PIXEL_PACK_BUFFER,t),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,o),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),o}function FC(e,t,n,r,o){var i=Os(n,r),a=i[0],u=i[1],s=new Uint8Array(n*r*4);return ee(e,t,function(){return e.readPixels(0,0,a,u,o.downloadTextureFormat,e.UNSIGNED_BYTE,s)}),new Float32Array(s.buffer)}function MC(e,t,n,r,o,i,a,u){var s=e,l=new Float32Array(function(c,f){var d=Da(c,f);return d[0]*d[1]*4}(i,a));return s.bindBuffer(s.PIXEL_PACK_BUFFER,t),s.getBufferSubData(s.PIXEL_PACK_BUFFER,0,l),s.bindBuffer(s.PIXEL_PACK_BUFFER,null),l}function OC(e,t,n,r){var o=new Float32Array(n*r*4);return ee(e,t,function(){return e.readPixels(0,0,r,n,e.RGBA,e.FLOAT,o)}),o}var BC=function(){function e(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var n=z().getNumber("WEBGL_VERSION");t!=null?(this.gl=t,f2(n,t)):this.gl=zn(n);var r="WEBGL_color_buffer_float";if(z().getNumber("WEBGL_VERSION")===1){if(this.textureFloatExtension=eu(this.gl,this.debug,"OES_texture_float"),nn(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=eu(this.gl,this.debug,"OES_texture_half_float");else if(z().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(r),nn(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=eu(this.gl,this.debug,"EXT_color_buffer_half_float");else if(z().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(r="EXT_color_buffer_float",nn(this.gl,r))this.colorBufferFloatExtension=this.gl.getExtension(r);else{if(!nn(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=CC(this.gl,this.debug),this.indexBuffer=_C(this.gl,this.debug),this.framebuffer=S2(this.gl,this.debug),this.textureConfig=md(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(e.prototype,"debug",{get:function(){return z().getBool("DEBUG")},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){var t=this;if(!this.disposed){this.program!=null&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),this.outputTexture!=null&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var n=this.gl;ee(n,this.debug,function(){return n.finish()}),ee(n,this.debug,function(){return n.bindFramebuffer(n.FRAMEBUFFER,null)}),ee(n,this.debug,function(){return n.deleteFramebuffer(t.framebuffer)}),ee(n,this.debug,function(){return n.bindBuffer(n.ARRAY_BUFFER,null)}),ee(n,this.debug,function(){return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null)}),ee(n,this.debug,function(){return n.deleteBuffer(t.indexBuffer)}),this.disposed=!0}},e.prototype.createFloat32MatrixTexture=function(t,n){return this.throwIfDisposed(),EC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createFloat16MatrixTexture=function(t,n){return this.throwIfDisposed(),SC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createUnsignedBytesMatrixTexture=function(t,n){return this.throwIfDisposed(),kC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.uploadPixelDataToTexture=function(t,n){this.throwIfDisposed(),NC(this.gl,this.debug,t,n)},e.prototype.uploadDenseMatrixToTexture=function(t,n,r,o){this.throwIfDisposed(),TC(this.gl,this.debug,t,n,r,o,this.textureConfig)},e.prototype.createFloat16PackedMatrixTexture=function(t,n){return this.throwIfDisposed(),IC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.createPackedMatrixTexture=function(t,n){return this.throwIfDisposed(),RC(this.gl,this.debug,t,n,this.textureConfig)},e.prototype.deleteMatrixTexture=function(t){var n=this;this.throwIfDisposed(),this.outputTexture===t&&(Mp(this.gl,this.debug,this.framebuffer),this.outputTexture=null),ee(this.gl,this.debug,function(){return n.gl.deleteTexture(t)})},e.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(t,n,r){var o=this;return this.downloadMatrixDriver(t,function(){return FC(o.gl,o.debug,n,r,o.textureConfig)})},e.prototype.downloadPackedMatrixFromBuffer=function(t,n,r,o,i,a){return MC(this.gl,t,0,0,0,i,a,this.textureConfig)},e.prototype.downloadFloat32MatrixFromBuffer=function(t,n){return PC(this.gl,t,n)},e.prototype.createBufferFromTexture=function(t,n,r){this.bindTextureToFrameBuffer(t);var o=AC(this.gl,this.debug,n,r,this.textureConfig);return this.unbindTextureToFrameBuffer(),o},e.prototype.createAndWaitForFence=function(){var t=this.createFence(this.gl);return this.pollFence(t)},e.prototype.createFence=function(t){var n,r,o=this;if(z().getBool("WEBGL_FENCE_API_ENABLED")){var i=t,a=i.fenceSync(i.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),r=function(){var u=i.clientWaitSync(a,0,0);return u===i.ALREADY_SIGNALED||u===i.CONDITION_SATISFIED},n=a}else z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(n=this.beginQuery(),this.endQuery(),r=function(){return o.isQueryAvailable(n,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):r=function(){return!0};return{query:n,isFencePassed:r}},e.prototype.downloadMatrixFromPackedTexture=function(t,n,r){var o=this;return this.downloadMatrixDriver(t,function(){return OC(o.gl,o.debug,n,r)})},e.prototype.createProgram=function(t){this.throwIfDisposed();var n=this.gl,r=g2(n,this.debug,t),o=bC(n,this.debug),i=x2(n,this.debug);return ee(n,this.debug,function(){return n.attachShader(i,o)}),ee(n,this.debug,function(){return n.attachShader(i,r)}),w2(n,this.debug,i),this.debug&&Ol(n,this.debug,i),this.vertexAttrsAreBound||(this.setProgram(i),this.vertexAttrsAreBound=DC(n,this.debug,this.program,this.vertexBuffer)),i},e.prototype.deleteProgram=function(t){var n=this;this.throwIfDisposed(),t===this.program&&(this.program=null),t!=null&&ee(this.gl,this.debug,function(){return n.gl.deleteProgram(t)})},e.prototype.setProgram=function(t){var n=this;this.throwIfDisposed(),this.program=t,this.program!=null&&this.debug&&Ol(this.gl,this.debug,this.program),ee(this.gl,this.debug,function(){return n.gl.useProgram(t)})},e.prototype.getUniformLocation=function(t,n,r){return r===void 0&&(r=!0),this.throwIfDisposed(),r?R2(this.gl,this.debug,t,n):I2(this.gl,t,n)},e.prototype.getAttributeLocation=function(t,n){var r=this;return this.throwIfDisposed(),ee(this.gl,this.debug,function(){return r.gl.getAttribLocation(t,n)})},e.prototype.getUniformLocationNoThrow=function(t,n){return this.throwIfDisposed(),this.gl.getUniformLocation(t,n)},e.prototype.setInputMatrixTexture=function(t,n,r){this.throwIfDisposed(),this.throwIfNoProgram(),D2(this.gl,this.debug,this.program,t,n,r)},e.prototype.setOutputMatrixTexture=function(t,n,r){this.setOutputMatrixTextureDriver(t,r,n)},e.prototype.setOutputPackedMatrixTexture=function(t,n,r){this.throwIfDisposed();var o=Da(n,r),i=o[0],a=o[1];this.setOutputMatrixTextureDriver(t,i,a)},e.prototype.setOutputMatrixWriteRegion=function(t,n,r,o){this.setOutputMatrixWriteRegionDriver(r,t,o,n)},e.prototype.setOutputPackedMatrixWriteRegion=function(t,n,r,o){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},e.prototype.debugValidate=function(){this.program!=null&&Ol(this.gl,this.debug,this.program),tu(this.gl)},e.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var t=this.gl;this.debug&&this.debugValidate(),ee(t,this.debug,function(){return t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)})},e.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),ee(this.gl,this.debug,function(){return t.gl.finish()})},e.prototype.getQueryTimerExtension=function(){return this.disjointQueryTimerExtension==null&&(this.disjointQueryTimerExtension=eu(this.gl,this.debug,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},e.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},e.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},e.prototype.beginQuery=function(){if(z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")===2){var t=this.gl,n=this.getQueryTimerExtensionWebGL2(),r=t.createQuery();return t.beginQuery(n.TIME_ELAPSED_EXT,r),r}var o=this.getQueryTimerExtensionWebGL1(),i=o.createQueryEXT();return o.beginQueryEXT(o.TIME_ELAPSED_EXT,i),i},e.prototype.endQuery=function(){if(z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")!==2){var t=this.getQueryTimerExtensionWebGL1();t.endQueryEXT(t.TIME_ELAPSED_EXT)}else{var n=this.gl,r=this.getQueryTimerExtensionWebGL2();n.endQuery(r.TIME_ELAPSED_EXT)}},e.prototype.waitForQueryAndGetTime=function(t){return Q(this,void 0,void 0,function(){var n=this;return J(this,function(r){switch(r.label){case 0:return[4,Ip(function(){return n.disposed||n.isQueryAvailable(t,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return r.sent(),[2,this.getQueryTime(t,z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},e.prototype.getQueryTime=function(t,n){if(n===0)return null;if(n===2){var r=this.gl;return r.getQueryParameter(t,r.QUERY_RESULT)/1e6}var o=this.getQueryTimerExtensionWebGL1();return o.getQueryObjectEXT(t,o.QUERY_RESULT_EXT)/1e6},e.prototype.isQueryAvailable=function(t,n){if(n===0)return!0;if(n===2){var r=this.gl,o=this.getQueryTimerExtensionWebGL2(),i=r.getQueryParameter(t,r.QUERY_RESULT_AVAILABLE);return this.disjoint==null&&(this.disjoint=this.gl.getParameter(o.GPU_DISJOINT_EXT)),i&&!this.disjoint}return i=(o=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t,o.QUERY_RESULT_AVAILABLE_EXT),this.disjoint==null&&(this.disjoint=this.gl.getParameter(o.GPU_DISJOINT_EXT)),i&&!this.disjoint},e.prototype.pollFence=function(t){var n=this;return new Promise(function(r){n.addItemToPoll(function(){return t.isFencePassed()},function(){return r()})})},e.prototype.pollItems=function(){for(var t=function(r){for(var o=0;o1||Ip(function(){return r.pollItems(),r.itemsToPoll.length===0})},e.prototype.bindTextureToFrameBuffer=function(t){this.throwIfDisposed(),Bl(this.gl,this.debug,t,this.framebuffer),this.debug&&tu(this.gl)},e.prototype.unbindTextureToFrameBuffer=function(){this.outputTexture!=null?(Bl(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&tu(this.gl)):Mp(this.gl,this.debug,this.framebuffer)},e.prototype.downloadMatrixDriver=function(t,n){this.bindTextureToFrameBuffer(t);var r=n();return this.unbindTextureToFrameBuffer(),r},e.prototype.setOutputMatrixTextureDriver=function(t,n,r){this.throwIfDisposed();var o=this.gl;Bl(o,this.debug,t,this.framebuffer),this.debug&&tu(o),this.outputTexture=t,ee(o,this.debug,function(){return o.viewport(0,0,n,r)}),ee(o,this.debug,function(){return o.scissor(0,0,n,r)})},e.prototype.setOutputMatrixWriteRegionDriver=function(t,n,r,o){var i=this;this.throwIfDisposed(),ee(this.gl,this.debug,function(){return i.gl.scissor(t,n,r,o)})},e.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},e.prototype.throwIfNoProgram=function(){if(this.program==null)throw new Error("No GPU program is currently set.")},e}();function Kp(e,t){if(e.length!==t.length)throw Error("Binary was compiled with "+e.length+" inputs, but was executed with "+t.length+" inputs");e.forEach(function(n,r){var o=n.logicalShape,i=t[r],a=i.shape;if(!ot(o,a))throw Error("Binary was compiled with different shapes than the current args. Shapes "+o+" and "+a+" must match");if(!n.isUniform||!i.isUniform){var u=n.texShape,s=i.isUniform?null:i.texData.texShape;if(!ot(u,s))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+u+" and "+s+" must match")}})}var LC=function(e,t,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;for(var r=n.filterWidth,o=n.inChannels,i=n.strideWidth,a=n.strideHeight,u=n.padInfo,s=n.outWidth,l=n.dilationWidth,c=n.dilationHeight,f=n.dataFormat,d=u.left,h=u.top,p=o*r,m=gt(),g=f==="channelsLast",v=g?0:1,y=g?1:2,x="",w=0;w<=1;w++)for(var b=0;b<=1;b++)x+=` blockIndex = rc.y + `+b+`; pos = rc.x + `+w+`; @@ -2121,7 +2121,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `+m.output+` = result; } - `},$C=function(e,t,n,r,o){this.variableNames=["x"],this.outputShape=[];var i,a=t,u=e[3]-1;this.outputShape=e;var s="float("+n+") + float("+r+") * sum";i=o===.5?"inversesqrt("+s+")":o===1?"1.0/("+s+")":"exp(log("+s+") * float(-"+o+"));",this.userCode=` + `},WC=function(e,t,n,r,o){this.variableNames=["x"],this.outputShape=[];var i,a=t,u=e[3]-1;this.outputShape=e;var s="float("+n+") + float("+r+") * sum";i=o===.5?"inversesqrt("+s+")":o===1?"1.0/("+s+")":"exp(log("+s+") * float(-"+o+"));",this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords[0]; @@ -2140,7 +2140,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, float val = x * `+i+`; setOutput(val); } - `},HC=function(e,t,n,r,o){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=e,this.depth=e[3],this.depthRadius=t,this.bias=n,this.alpha=r,this.beta=o,this.userCode=` + `},zC=function(e,t,n,r,o){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=e,this.depth=e[3],this.depthRadius=t,this.bias=n,this.alpha=r,this.beta=o,this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords[0]; @@ -2195,7 +2195,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(result); } - `},jC=function(e,t,n,r,o){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var i,a=t,u=e[3]-1;this.outputShape=e;var s="float("+n+") + float("+r+") * sum";i=o===.5?"inversesqrt("+s+")":o===1?"1.0/("+s+")":"exp(log("+s+") * float(-"+o+"));",this.userCode=` + `},UC=function(e,t,n,r,o){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var i,a=t,u=e[3]-1;this.outputShape=e;var s="float("+n+") + float("+r+") * sum";i=o===.5?"inversesqrt("+s+")":o===1?"1.0/("+s+")":"exp(log("+s+") * float(-"+o+"));",this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords.x; @@ -2257,7 +2257,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, vec4 result = xAtOutputCoords * `+i+`; setOutput(result); } - `},GC=function(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;var t=e.strideHeight,n=e.strideWidth,r=e.dilationHeight,o=e.effectiveFilterHeight,i=e.effectiveFilterWidth,a=o-1-e.padInfo.top,u=i-1-e.padInfo.left,s=o*i-1;this.userCode=` + `},VC=function(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;var t=e.strideHeight,n=e.strideWidth,r=e.dilationHeight,o=e.effectiveFilterHeight,i=e.effectiveFilterWidth,a=o-1-e.padInfo.top,u=i-1-e.padInfo.left,s=o*i-1;this.userCode=` const ivec2 pads = ivec2(`+a+", "+u+`); void main() { @@ -2303,7 +2303,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},qC=function(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;var t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,o=e.dilationDepth,i=e.dilationHeight,a=e.dilationWidth,u=e.effectiveFilterDepth,s=e.effectiveFilterHeight,l=e.effectiveFilterWidth,c=u-1-e.padInfo.front,f=s-1-e.padInfo.top,d=l-1-e.padInfo.left,h=u*s*l-1;this.userCode=` + `},$C=function(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;var t=e.strideDepth,n=e.strideHeight,r=e.strideWidth,o=e.dilationDepth,i=e.dilationHeight,a=e.dilationWidth,u=e.effectiveFilterDepth,s=e.effectiveFilterHeight,l=e.effectiveFilterWidth,c=u-1-e.padInfo.front,f=s-1-e.padInfo.top,d=l-1-e.padInfo.left,h=u*s*l-1;this.userCode=` const ivec3 pads = ivec3(`+c+", "+f+", "+d+`); void main() { @@ -2367,7 +2367,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(dotProd); } - `},Hl=function(e,t,n,r,o,i,a){n===void 0&&(n=!1),r===void 0&&(r=!1),o===void 0&&(o=!1),i===void 0&&(i=null),a===void 0&&(a=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;var u=n?e[1]:e[2],s=Math.ceil(u/2),l=n?"i * 2, rc.y":"rc.y, i * 2",c=r?"rc.z, i * 2":"i * 2, rc.z",f=n?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],d=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],h="",p="";i&&(h=a?`vec4 activation(vec4 a) { + `},Vl=function(e,t,n,r,o,i,a){n===void 0&&(n=!1),r===void 0&&(r=!1),o===void 0&&(o=!1),i===void 0&&(i=null),a===void 0&&(a=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;var u=n?e[1]:e[2],s=Math.ceil(u/2),l=n?"i * 2, rc.y":"rc.y, i * 2",c=r?"rc.z, i * 2":"i * 2, rc.z",f=n?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],d=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],h="",p="";i&&(h=a?`vec4 activation(vec4 a) { vec4 b = getPreluActivationWeightsAtOutCoords(); `+i+` }`:`vec4 activation(vec4 x) { @@ -2401,7 +2401,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(result); } - `},KC=function(){function e(t,n,r){this.variableNames=["probs"],this.outputShape=[t,r],this.userCode=` + `},HC=function(){function e(t,n,r){this.variableNames=["probs"],this.outputShape=[t,r],this.userCode=` uniform float seed; void main() { @@ -2423,18 +2423,18 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, // If no other event happened, last event happened. setOutput(float(`+(n-1)+`)); } - `}return e.prototype.getCustomSetupFunc=function(t){var n=this;return function(r,o){n.seedLoc==null&&(n.seedLoc=r.getUniformLocation(o,"seed")),r.gl.uniform1f(n.seedLoc,t)}},e}(),XC=function(e,t,n,r){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode=` + `}return e.prototype.getCustomSetupFunc=function(t){var n=this;return function(r,o){n.seedLoc==null&&(n.seedLoc=r.getUniformLocation(o,"seed")),r.gl.uniform1f(n.seedLoc,t)}},e}(),jC=function(e,t,n,r){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode=` void main() { ivec2 coords = getOutputCoords(); int index = round(getIndices(coords.x)); setOutput(mix(float(`+r+"), float("+n+`), float(index == coords.y))); } - `},YC=function(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=e;var t=e.length;if(t===0)this.userCode=` + `},GC=function(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=e;var t=e.length;if(t===0)this.userCode=` void main() { setOutput(vec4(getA(), 0., 0., 0.)); } - `;else{var n=Dt("rc",t),r=ke(t),o=function(u,s,l){if(u===1)return"rc > "+s[0];for(var c="",f=u-2;f= "+s[f],f "+s[0];for(var c="",f=u-2;f= "+s[f],f1&&(o+="thisRC.y += 1;"),n+=` + `},YC=function(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;for(var n="",r=0;r<4;r++){var o="thisRC = rc;";r%2==1&&(o+="thisRC.z += 1;"),r>1&&(o+="thisRC.y += 1;"),n+=` `+o+` `+(r>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+` int flatIndex = getFlatIndex(thisRC); @@ -2912,11 +2912,11 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, `}this.userCode=` ivec3 inputCoordsFromReshapedOutCoords(int index) { - `+oo(["r","c","d"],t)+` + `+no(["r","c","d"],t)+` return ivec3(r, c, d); } - `+Id(e)+` + `+kd(e)+` void main() { ivec3 rc = getOutputCoords(); @@ -2931,7 +2931,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(result); } - `},t_=function(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;var r=t.shape,o=r[1],i=r[2],a=e.shape,u=a[1],s=a[2],l=[n&&u>1?o-1:o,n&&s>1?i-1:i],c=[n&&u>1?u-1:u,n&&s>1?s-1:s],f=l[0]/c[0],d=l[1]/c[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode=` + `},QC=function(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;var r=t.shape,o=r[1],i=r[2],a=e.shape,u=a[1],s=a[2],l=[n&&u>1?o-1:o,n&&s>1?i-1:i],c=[n&&u>1?u-1:u,n&&s>1?s-1:s],f=l[0]/c[0],d=l[1]/c[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords[0]; @@ -3012,7 +3012,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(accumulator); } - `},n_=function(e,t,n,r){this.variableNames=["A"],this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n];this.userCode=` + `},JC=function(e,t,n,r){this.variableNames=["A"],this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n];this.userCode=` const vec2 effectiveInputOverOutputRatioRC = vec2( `+s[0]/l[0]+`, `+s[1]/l[1]+`); @@ -3045,7 +3045,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(newValue); } - `},r_=function(e,t,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n];this.userCode=` + `},ZC=function(e,t,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n];this.userCode=` const vec3 effectiveInputOverOutputRatioRC = vec3( `+s[0]/l[0]+`, `+s[1]/l[1]+`, @@ -3122,7 +3122,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(newValue); } - `},o_=function(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;var r=t.shape,o=r[1],i=r[2],a=e.shape,u=a[1],s=a[2],l=[n&&u>1?o-1:o,n&&s>1?i-1:i],c=[n&&u>1?u-1:u,n&&s>1?s-1:s],f=l[0]/c[0],d=l[1]/c[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode=` + `},e_=function(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;var r=t.shape,o=r[1],i=r[2],a=e.shape,u=a[1],s=a[2],l=[n&&u>1?o-1:o,n&&s>1?i-1:i],c=[n&&u>1?u-1:u,n&&s>1?s-1:s],f=l[0]/c[0],d=l[1]/c[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode=` void main() { ivec4 coords = getOutputCoords(); int b = coords[0]; @@ -3192,7 +3192,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(accumulator); } - `},i_=function(e,t,n,r){this.variableNames=["A"],this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n],c=r?"0.5":"0.0";this.userCode=` + `},t_=function(e,t,n,r){this.variableNames=["A"],this.outputShape=[];var o=e[0],i=e[1],a=e[2],u=e[3];this.outputShape=[o,t,n,u];var s=[r&&t>1?i-1:i,r&&n>1?a-1:a],l=[r&&t>1?t-1:t,r&&n>1?n-1:n],c=r?"0.5":"0.0";this.userCode=` const vec2 effectiveInputOverOutputRatioRC = vec2( `+s[0]/l[0]+`, `+s[1]/l[1]+`); @@ -3215,7 +3215,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(newValue); } - `},a_=function(e,t){this.variableNames=["x"];var n=e.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");if(this.outputShape=e,n!==1){var r=e.map(function(i,a){return function(u){return t.indexOf(u)!==-1&&e[u]!==1?e[u]+" - coords["+u+"] - 1":"coords["+u+"]"}(a)}).join(","),o=ke(n);this.userCode=` + `},n_=function(e,t){this.variableNames=["x"];var n=e.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");if(this.outputShape=e,n!==1){var r=e.map(function(i,a){return function(u){return t.indexOf(u)!==-1&&e[u]!==1?e[u]+" - coords["+u+"] - 1":"coords["+u+"]"}(a)}).join(","),o=ke(n);this.userCode=` void main() { `+o+` coords = getOutputCoords(); setOutput(getX(`+r+`)); @@ -3225,7 +3225,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, int coord = getOutputCoords(); setOutput(getX(`+e[0]+` - coord - 1)); } - `},u_=function(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var n=e.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");this.outputShape=e;var r=Dt("rc",n),o=r[n-1]+" + 1 < "+this.outputShape[n-1],i=r[n-2]+" + 1 < "+this.outputShape[n-2],a=ke(n);function u(s){var l=e.map(function(c,f){return function(d,h){return t.indexOf(d)!==-1&&e[d]!==1?e[d]+" - "+h[d]+" - 1":""+h[d]}(f,s)});return"getChannel(getX("+l.join(",")+"), vec2("+l.slice(-2).join(",")+"))"}this.userCode=n===1?` + `},r_=function(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var n=e.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");this.outputShape=e;var r=It("rc",n),o=r[n-1]+" + 1 < "+this.outputShape[n-1],i=r[n-2]+" + 1 < "+this.outputShape[n-2],a=ke(n);function u(s){var l=e.map(function(c,f){return function(d,h){return t.indexOf(d)!==-1&&e[d]!==1?e[d]+" - "+h[d]+" - 1":""+h[d]}(f,s)});return"getChannel(getX("+l.join(",")+"), vec2("+l.slice(-2).join(",")+"))"}this.userCode=n===1?` void main(){ int rc = getOutputCoords(); vec4 result = vec4(0.); @@ -3253,7 +3253,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(result); } - `},ev=function(e,t,n,r,o,i,a){this.variableNames=["updates","indices","defaultValue"],this.outputShape=i;var u=ke(o.length),s=ke(i.length),l="";n===1?l="i":n===2&&(l="i, j");var c="getIndices("+l+")",f="";r===1?f="i":r===2&&(f="i, coords[1]");var d="getUpdates("+f+")",h=t>1?"strides[j]":"strides";this.userCode=` + `},Xp=function(e,t,n,r,o,i,a){this.variableNames=["updates","indices","defaultValue"],this.outputShape=i;var u=ke(o.length),s=ke(i.length),l="";n===1?l="i":n===2&&(l="i, j");var c="getIndices("+l+")",f="";r===1?f="i":r===2&&(f="i, coords[1]");var d="getUpdates("+f+")",h=t>1?"strides[j]":"strides";this.userCode=` `+u+" strides = "+u+"("+o+`); void main() { @@ -3273,7 +3273,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(mix(getDefaultValue(), sum, float(found))); } - `},s_=function(e,t){this.variableNames=["x","segmentIds"];var n=e.windowSize,r=e.batchSize,o=e.inSize,i=e.numSegments,a=i*Math.ceil(o/n);this.outputShape=[r,a];var u=4*Math.floor(n/4),s=n%4,l=` + `},o_=function(e,t){this.variableNames=["x","segmentIds"];var n=e.windowSize,r=e.batchSize,o=e.inSize,i=e.numSegments,a=i*Math.ceil(o/n);this.outputShape=[r,a];var u=4*Math.floor(n/4),s=n%4,l=` sumValue += dot(values, segFilter); `,c="";o%n>0&&(c=` if (inIdx < 0 || inIdx >= `+o+`) { @@ -3379,7 +3379,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, } setOutput(sumValue); } - `},l_=function(e,t,n){var r,o;if(this.variableNames=["c","a","b"],this.outputShape=t,n>4)throw Error("Where for rank "+n+" is not yet supported");if(n===1)o="resRC",r="resRC";else{for(var i=["resRC.x","resRC.y","resRC.z","resRC.w"],a=[],u=[],s=0;s4)throw Error("Where for rank "+n+" is not yet supported");if(n===1)o="resRC",r="resRC";else{for(var i=["resRC.x","resRC.y","resRC.z","resRC.w"],a=[],u=[],s=0;s0){this.numFreeTextures--,this.numUsedTextures++,this.log();var u=this.freeTextures[a].shift();return this.usedTextures[a].push(u),u}return this.numUsedTextures++,this.log(),i===zt.PACKED_2X2_FLOAT32?o=this.gpgpu.createPackedMatrixTexture(t[0],t[1]):i===zt.PACKED_2X2_FLOAT16?o=this.gpgpu.createFloat16PackedMatrixTexture(t[0],t[1]):i===zt.UNPACKED_FLOAT32?o=this.gpgpu.createFloat32MatrixTexture(t[0],t[1]):i===zt.UNPACKED_FLOAT16?o=this.gpgpu.createFloat16MatrixTexture(t[0],t[1]):i===zt.PACKED_4X1_UNSIGNED_BYTE&&(o=this.gpgpu.createUnsignedBytesMatrixTexture(t[0],t[1])),this.usedTextures[a].push(o),o},e.prototype.releaseTexture=function(t,n,r,o){if(this.freeTextures!=null){var i=nv(n,tv(r,o),o);i in this.freeTextures||(this.freeTextures[i]=[]),this.freeTextures[i].push(t),this.numFreeTextures++,this.numUsedTextures--;var a=this.usedTextures[i],u=a.indexOf(t);if(u<0)throw new Error("Cannot release a texture that was never provided by this texture manager");a.splice(u,1),this.log()}},e.prototype.log=function(){if(this.logEnabled){var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")")}},e.prototype.getNumUsedTextures=function(){return this.numUsedTextures},e.prototype.getNumFreeTextures=function(){return this.numFreeTextures},e.prototype.dispose=function(){var t=this;if(this.freeTextures!=null){for(var n in this.freeTextures)this.freeTextures[n].forEach(function(r){t.gpgpu.deleteMatrixTexture(r)});for(var n in this.usedTextures)this.usedTextures[n].forEach(function(o){t.gpgpu.deleteMatrixTexture(o)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},e}();function tv(e,t){if(e===Vt.UPLOAD)return zt.PACKED_2X2_FLOAT32;if(e===Vt.RENDER||e==null)return function(n){return z().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?n?zt.PACKED_2X2_FLOAT32:zt.UNPACKED_FLOAT32:n?zt.PACKED_2X2_FLOAT16:zt.UNPACKED_FLOAT16}(t);if(e===Vt.DOWNLOAD||e===Vt.PIXELS)return zt.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+e)}function nv(e,t,n){return e[0]+"_"+e[1]+"_"+t+"_"+n}var p_=function(e,t){this.variableNames=["A"];for(var n=new Array(e.length),r=0;r5)throw Error("Tile for rank "+u+" is not yet supported");if(u===1)return"imod(resRC, "+a[0]+")";for(var s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],l=[],c=0;c0){this.numFreeTextures--,this.numUsedTextures++,this.log();var u=this.freeTextures[a].shift();return this.usedTextures[a].push(u),u}return this.numUsedTextures++,this.log(),i===zt.PACKED_2X2_FLOAT32?o=this.gpgpu.createPackedMatrixTexture(t[0],t[1]):i===zt.PACKED_2X2_FLOAT16?o=this.gpgpu.createFloat16PackedMatrixTexture(t[0],t[1]):i===zt.UNPACKED_FLOAT32?o=this.gpgpu.createFloat32MatrixTexture(t[0],t[1]):i===zt.UNPACKED_FLOAT16?o=this.gpgpu.createFloat16MatrixTexture(t[0],t[1]):i===zt.PACKED_4X1_UNSIGNED_BYTE&&(o=this.gpgpu.createUnsignedBytesMatrixTexture(t[0],t[1])),this.usedTextures[a].push(o),o},e.prototype.releaseTexture=function(t,n,r,o){if(this.freeTextures!=null){var i=Qp(n,Yp(r,o),o);i in this.freeTextures||(this.freeTextures[i]=[]),this.freeTextures[i].push(t),this.numFreeTextures++,this.numUsedTextures--;var a=this.usedTextures[i],u=a.indexOf(t);if(u<0)throw new Error("Cannot release a texture that was never provided by this texture manager");a.splice(u,1),this.log()}},e.prototype.log=function(){if(this.logEnabled){var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")")}},e.prototype.getNumUsedTextures=function(){return this.numUsedTextures},e.prototype.getNumFreeTextures=function(){return this.numFreeTextures},e.prototype.dispose=function(){var t=this;if(this.freeTextures!=null){for(var n in this.freeTextures)this.freeTextures[n].forEach(function(r){t.gpgpu.deleteMatrixTexture(r)});for(var n in this.usedTextures)this.usedTextures[n].forEach(function(o){t.gpgpu.deleteMatrixTexture(o)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},e}();function Yp(e,t){if(e===Vt.UPLOAD)return zt.PACKED_2X2_FLOAT32;if(e===Vt.RENDER||e==null)return function(n){return z().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?n?zt.PACKED_2X2_FLOAT32:zt.UNPACKED_FLOAT32:n?zt.PACKED_2X2_FLOAT16:zt.UNPACKED_FLOAT16}(t);if(e===Vt.DOWNLOAD||e===Vt.PIXELS)return zt.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+e)}function Qp(e,t,n){return e[0]+"_"+e[1]+"_"+t+"_"+n}var c_=function(e,t){this.variableNames=["A"];for(var n=new Array(e.length),r=0;r5)throw Error("Tile for rank "+u+" is not yet supported");if(u===1)return"imod(resRC, "+a[0]+")";for(var s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],l=[],c=0;c6)throw Error("Transpose for rank "+u+" is not yet supported");for(var s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],l=new Array(u),c=0;c6)throw Error("Transpose for rank "+u+" is not yet supported");for(var s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],l=new Array(u),c=0;c6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var o=ke(this.rank),i=T0("rc",this.rank),a=new Array(this.rank);for(r=0;r6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var o=ke(this.rank),i=k0("rc",this.rank),a=new Array(this.rank);for(r=0;r= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0); -`,ov="return -x;",iv="return ceil(x);",av="return floor(x);",uv="return exp(x);",sv="return exp(x) - 1.0;",x_=bn+` +`,Zp="return -x;",ev="return ceil(x);",tv="return floor(x);",nv="return exp(x);",rv="return exp(x) - 1.0;",v_=wn+` return sin(x); -`,w_=bn+` +`,m_=wn+` return cos(x); -`,b_=bn+` +`,g_=wn+` if (abs(x) > 1.) { return NAN; } return asin(x); -`,C_=bn+` +`,y_=wn+` if (abs(x) > 1.) { return NAN; } return acos(x); -`,__=bn+` +`,x_=wn+` return atan(x); -`,E_=bn+"return log(x + sqrt(x * x + 1.0));",S_=bn+` +`,w_=wn+"return log(x + sqrt(x * x + 1.0));",b_=wn+` if (x < 1.0) return NAN; - return log(x + sqrt(x * x - 1.0));`,k_=bn+` + return log(x + sqrt(x * x - 1.0));`,C_=wn+` if ((x < -1.0) || (x > 1.0)) return NAN; - return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,uu="return x;",R_="return x;",L0=` + return (log(1.0 + x) - log(1.0 - x)) / 2.0;`,iu="return x;",__="return x;",F0=` vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0))); bvec4 isNaN = isnan(x); @@ -3516,7 +3516,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, result.a = isNaN.a ? x.a : result.a; return result; -`,W0=` +`,M0=` vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0))); bvec4 isNaN = isnan(x); @@ -3526,7 +3526,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, result.a = isNaN.a ? x.a : result.a; return result; -`,z0=` +`,O0=` vec4 result; result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0); @@ -3535,7 +3535,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0); return result; -`,Mi=function(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.userCode=` +`,Ai=function(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.userCode=` vec4 unaryOperation(vec4 x) { `+t+` } @@ -3546,14 +3546,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, setOutput(y); } - `},I_=function(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=e;var t=e.length,n=Dt("rc",t),r=ke(t),o=function(u,s){if(u===1)return"rc";for(var l="",c=0;c0?[4,Promise.all(a)]:[3,2];case 1:return l=c.sent(),s.kernelMs=Jw(l),s.getExtraProfileInfo=function(){return l.map(function(f,d){return{name:u[d],ms:f}}).map(function(f){return f.name+": "+f.ms}).join(", ")},[3,3];case 2:s.kernelMs={error:"WebGL query timers are not supported in this environment."},c.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,s]}})})},t.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},t.prototype.startTimer=function(){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:Dn(),endMs:null}},t.prototype.endTimer=function(n){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),n):(n.endMs=Dn(),n)},t.prototype.getQueryTime=function(n){return Q(this,void 0,void 0,function(){var r;return J(this,function(o){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(n)]:[2,(r=n).endMs-r.startMs]})})},t.prototype.disposeData=function(n){if(!this.pendingDisposal.has(n)){if(this.pendingRead.has(n))return this.pendingDisposal.add(n),void this.pendingDeletes++;if(this.texData.has(n)){this.releaseGPUData(n);var r=this.texData.get(n).complexTensors;r!=null&&(r.real.dispose(),r.imag.dispose()),this.texData.delete(n)}}},t.prototype.releaseGPUData=function(n){var r=this.texData.get(n),o=r.texture,i=r.dtype,a=r.texShape,u=r.usage,s=r.isPacked,l=r.slice,c=l&&l.origDataId||n,f=this.dataRefCount.get(c);f>1?this.dataRefCount.set(c,f-1):(this.dataRefCount.delete(c),o!=null&&(this.numBytesInGPU-=this.computeBytes(a,i),this.textureManager.releaseTexture(o,a,u,s)));var d=this.texData.get(n);d.texture=null,d.texShape=null,d.isPacked=!1,d.slice=null},t.prototype.getTexture=function(n){return this.uploadToGPU(n),this.texData.get(n).texture},t.prototype.getDataInfo=function(n){return this.texData.get(n)},t.prototype.getCPUBackend=function(){return z().getBool("WEBGL_CPU_FORWARD")?(this.cpuBackend==null&&(this.cpuBackend=A.findBackend("cpu")),this.cpuBackend):null},t.prototype.shouldExecuteOnCPU=function(n,r){var o=this;return r===void 0&&(r=128),this.getCPUBackend()!=null&&n.every(function(i){return o.texData.get(i.dataId).texture==null&&i.sizez().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var a=Math.floor(n.length/2),u=this.concat(n.slice(0,a),r),s=this.concat(n.slice(a),r);return this.concat([u,s],r)}if(z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&n[0].rank>1){var l=new nC(n.map(function(h){return h.shape}),r);return this.compileAndRun(l,n)}var c=mi(n.map(function(h){return h.shape}),r),f=n.map(function(h){return h.as2D(-1,Z(h.shape.slice(r)))}),d=new tC(f.map(function(h){return h.shape}));return this.compileAndRun(d,f).reshape(c)},t.prototype.neg=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.neg(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,ov,n.dtype);var r=new ce(n.shape,ov);return this.compileAndRun(r,[n])},t.prototype.batchMatMul=function(n,r,o,i){var a=o?n.shape[2]:n.shape[1],u=i?r.shape[1]:r.shape[2],s=o?n.shape[1]:n.shape[2],l=n.shape[0];if((a===1||u===1)&&s>1e3){o&&(n=n.transpose([0,2,1])),i&&(r=r.transpose([0,2,1]));var c=u===1?n:n.as3D(l,s,1),f=u===1?2:1,d=u===1?r.as3D(l,1,s):r;return this.multiply(c,d).sum(f,!0)}var h=st(n.dtype,r.dtype),p=new Hl(n.shape,[l,a,u],o,i);return this.compileAndRun(p,[n,r],h)},t.prototype.fusedBatchMatMul=function(n){var r=n.a,o=n.b,i=n.transposeA,a=n.transposeB,u=n.bias,s=n.activation,l=n.preluActivationWeights,c=i?r.shape[2]:r.shape[1],f=a?o.shape[1]:o.shape[2],d=r.shape[0],h=st(r.dtype,o.dtype),p=u!=null,m=l!=null,g=s?lu(s,!0):null,v=new Hl(r.shape,[d,c,f],i,a,p,g,m),y=[r,o];return u&&y.push(u),l&&y.push(l),this.compileAndRun(v,y,h)},t.prototype.multiply=function(n,r){if(n.dtype==="complex64"){var o=this.texData.get(n.dataId),i=this.texData.get(r.dataId),a=new Gp(Yb,n.shape,r.shape),u=new Gp(Qb,n.shape,r.shape),s=[this.makeComplexComponentTensorInfo(n,o.complexTensors.real),this.makeComplexComponentTensorInfo(n,o.complexTensors.imag),this.makeComplexComponentTensorInfo(r,i.complexTensors.real),this.makeComplexComponentTensorInfo(r,i.complexTensors.imag)],l=this.compileAndRun(a,s),c=this.compileAndRun(u,s),f=this.complex(l,c);return l.dispose(),c.dispose(),f}if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.multiply(n,r);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,qp,n.dtype);var d=new ze(qp,n.shape,r.shape);return this.compileAndRun(d,[n,r],n.dtype)},t.prototype.batchNormalization=function(n,r,o,i,a,u){var s=[n,r,o],l=null;u!=null&&(l=u.shape,s.push(u));var c=null;if(a!=null&&(c=a.shape,s.push(a)),z().getBool("WEBGL_PACK_NORMALIZATION")){var f=new Xb(n.shape,r.shape,o.shape,l,c,i);return this.compileAndRun(f,s)}var d=new Kb(n.shape,r.shape,o.shape,l,c,i);return this.compileAndRun(d,s)},t.prototype.localResponseNormalization4D=function(n,r,o,i,a){var u=z().getBool("WEBGL_PACK_NORMALIZATION")?new jC(n.shape,r,o,i,a):new $C(n.shape,r,o,i,a);return this.compileAndRun(u,[n])},t.prototype.LRNGrad=function(n,r,o,i,a,u,s){var l=new HC(r.shape,i,a,u,s);return this.compileAndRun(l,[r,o,n])},t.prototype.tile=function(n,r){if(n.dtype==="string"){var o=this.readSync(n.dataId).map(function(a){return ns(a)});return I0(se(n.shape,n.dtype,o),r)}var i=new p_(n.shape,r);return this.compileAndRun(i,[n])},t.prototype.pad=function(n,r,o){var i=z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new JC(n.shape,r,o):new QC(n.shape,r,o);return this.compileAndRun(i,[n])},t.prototype.transpose=function(n,r){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.transpose(n,r);var o=z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new m_(n.shape,r):new v_(n.shape,r);return this.compileAndRun(o,[n])},t.prototype.gather=function(n,r,o){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.gather(n,r,o);var i=new _C(n.shape,r.size,o);return this.compileAndRun(i,[n,r])},t.prototype.batchToSpaceND=function(n,r,o){I(n.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var i=r.reduce(function(f,d){return f*d}),a=ss(n.shape,r,i),u=ls(a.length,r.length),s=cs(n.shape,r,i),l=v0(o,r.length),c=m0(s,o,r.length);return n.reshape(a).transpose(u).reshape(s).slice(l,c)},t.prototype.spaceToBatchND=function(n,r,o){I(n.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var i=r.reduce(function(d,h){return d*h}),a=[[0,0]];a.push.apply(a,o);for(var u=1+r.length;uh||p===d?m=!0:p=rf(d,p+1);return p}(s,a),c=new s_({windowSize:l,inSize:s,batchSize:u,numSegments:a}),f=this.compileAndRun(c,[n,o],i);return f.shape[1]===a?f:(o=us(0,a).tile([s/l]),this.segOpCompute(f,r,o,i,a))},t.prototype.argMinMaxReduce=function(n,r,o){var i=[r];if(Wt("arg"+o.charAt(0).toUpperCase()+o.slice(1),i,n.rank),!z().getBool("WEBGL_PACK_REDUCE")||n.rank<=2){var a=pt(n.shape,i),u=a[0],s=Z(a[1]),l=n.as2D(-1,s);return this.argReduce(l,o).reshape(u)}return this.argReducePacked(n,o)},t.prototype.argMin=function(n,r){return this.argMinMaxReduce(n,r,"min")},t.prototype.argMax=function(n,r){return this.argMinMaxReduce(n,r,"max")},t.prototype.cumsum=function(n,r,o,i){if(r!==n.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(n.rank-1)+" but got axis="+r);var a=new fC(n.shape,o,i);return this.compileAndRun(a,[n])},t.prototype.equal=function(n,r){if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,` + `},au={};function uu(e,t){if(t===void 0&&(t=!1),e==="linear")return t?__:h_;if(e==="relu")return t?F0:N0;if(e==="elu")return t?O0:P0;if(e==="relu6")return t?M0:A0;if(e==="prelu")return t?T0:D0;throw new Error("Activation "+e+" has not been implemented for the WebGL backend.")}var S_=600,k_=function(e){function t(n){var r,o=e.call(this)||this;if(o.pendingRead=new WeakMap,o.pendingDisposal=new WeakSet,o.dataRefCount=new WeakMap,o.numBytesInGPU=0,o.uploadWaitMs=0,o.downloadWaitMs=0,o.warnedAboutMemory=!1,o.pendingDeletes=0,o.disposed=!1,!z().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(n==null){var i=zn(z().getNumber("WEBGL_VERSION"));o.binaryCache=((r=z().getNumber("WEBGL_VERSION"))in au||(au[r]={}),au[r]),o.gpgpu=new BC(i),o.canvas=i.canvas,o.gpgpuCreatedLocally=!0}else o.gpgpu=n,o.binaryCache={},o.gpgpuCreatedLocally=!1,o.canvas=n.gl.canvas;return o.textureManager=new l_(o.gpgpu),o.numMBBeforeWarning=z().global.screen==null?1024:z().global.screen.height*z().global.screen.width*window.devicePixelRatio*S_/1024/1024,o.texData=new g0(o,A),o}return xn(t,e),t.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},t.prototype.write=function(n,r,o){if(z().getBool("DEBUG")&&this.checkNumericalProblems(n),o==="complex64"&&n!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var i={};return this.texData.set(i,{shape:r,dtype:o,values:n,usage:Vt.UPLOAD}),i},t.prototype.move=function(n,r,o,i){if(z().getBool("DEBUG")&&this.checkNumericalProblems(r),i==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(n,{shape:o,dtype:i,values:r,usage:Vt.UPLOAD})},t.prototype.readSync=function(n){var r=this.texData.get(n),o=r.values,i=r.dtype,a=r.complexTensors,u=r.slice,s=r.shape,l=r.isPacked;if(u!=null){var c=void 0;c=l?new Ai(s,iu):new ce(s,iu);var f=this.runWebGLProgram(c,[{dataId:n,shape:s,dtype:i}],i),d=this.readSync(f.dataId);return this.disposeData(f.dataId),d}if(o!=null)return this.convertAndCacheOnCPU(n);if(i==="string")return o;var h,p,m=this.activeTimers!=null;return m&&(h=In()),i==="complex64"?p=ff(a.real.dataSync(),a.imag.dataSync()):p=this.getValuesFromTexture(n),m&&(this.downloadWaitMs+=In()-h),this.convertAndCacheOnCPU(n,p)},t.prototype.read=function(n){return Q(this,void 0,void 0,function(){var r,o,i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E;return J(this,function(R){switch(R.label){case 0:if(this.pendingRead.has(n))return r=this.pendingRead.get(n),[2,new Promise(function(k){return r.push(k)})];if(o=this.texData.get(n),i=o.values,a=o.shape,u=o.slice,s=o.dtype,l=o.complexTensors,c=o.isPacked,u!=null)return f=void 0,f=c?new Ai(a,iu):new ce(a,iu),d=this.runWebGLProgram(f,[{dataId:n,shape:a,dtype:s}],s),h=this.read(d.dataId),this.disposeData(d.dataId),[2,h];if(i!=null)return[2,this.convertAndCacheOnCPU(n)];if(!z().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&z().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return p=null,s!=="complex64"&&z().get("WEBGL_BUFFER_SUPPORTED")&&(m=this.decode(n),g=this.texData.get(m.dataId),p=(E=this.gpgpu).createBufferFromTexture.apply(E,[g.texture].concat(qi(a)))),this.pendingRead.set(n,[]),s==="complex64"?[3,2]:[4,this.gpgpu.createAndWaitForFence()];case 1:R.sent(),R.label=2;case 2:return s!=="complex64"?[3,4]:[4,Promise.all([l.real.data(),l.imag.data()])];case 3:return y=R.sent(),x=y[0],w=y[1],v=ff(x,w),[3,5];case 4:p==null?v=this.getValuesFromTexture(n):(b=Z(a),v=this.gpgpu.downloadFloat32MatrixFromBuffer(p,b)),R.label=5;case 5:return m!=null&&this.disposeData(m.dataId),C=this.convertAndCacheOnCPU(n,v),_=this.pendingRead.get(n),this.pendingRead.delete(n),_.forEach(function(k){return k(C)}),this.pendingDisposal.has(n)&&(this.pendingDisposal.delete(n),this.disposeData(n),this.pendingDeletes--),[2,C]}})})},t.prototype.checkNumericalProblems=function(n){if(n!=null)for(var r=0;r0?[4,Promise.all(a)]:[3,2];case 1:return l=c.sent(),s.kernelMs=Kw(l),s.getExtraProfileInfo=function(){return l.map(function(f,d){return{name:u[d],ms:f}}).map(function(f){return f.name+": "+f.ms}).join(", ")},[3,3];case 2:s.kernelMs={error:"WebGL query timers are not supported in this environment."},c.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,s]}})})},t.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},t.prototype.startTimer=function(){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:In(),endMs:null}},t.prototype.endTimer=function(n){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),n):(n.endMs=In(),n)},t.prototype.getQueryTime=function(n){return Q(this,void 0,void 0,function(){var r;return J(this,function(o){return z().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(n)]:[2,(r=n).endMs-r.startMs]})})},t.prototype.disposeData=function(n){if(!this.pendingDisposal.has(n)){if(this.pendingRead.has(n))return this.pendingDisposal.add(n),void this.pendingDeletes++;if(this.texData.has(n)){this.releaseGPUData(n);var r=this.texData.get(n).complexTensors;r!=null&&(r.real.dispose(),r.imag.dispose()),this.texData.delete(n)}}},t.prototype.releaseGPUData=function(n){var r=this.texData.get(n),o=r.texture,i=r.dtype,a=r.texShape,u=r.usage,s=r.isPacked,l=r.slice,c=l&&l.origDataId||n,f=this.dataRefCount.get(c);f>1?this.dataRefCount.set(c,f-1):(this.dataRefCount.delete(c),o!=null&&(this.numBytesInGPU-=this.computeBytes(a,i),this.textureManager.releaseTexture(o,a,u,s)));var d=this.texData.get(n);d.texture=null,d.texShape=null,d.isPacked=!1,d.slice=null},t.prototype.getTexture=function(n){return this.uploadToGPU(n),this.texData.get(n).texture},t.prototype.getDataInfo=function(n){return this.texData.get(n)},t.prototype.getCPUBackend=function(){return z().getBool("WEBGL_CPU_FORWARD")?(this.cpuBackend==null&&(this.cpuBackend=A.findBackend("cpu")),this.cpuBackend):null},t.prototype.shouldExecuteOnCPU=function(n,r){var o=this;return r===void 0&&(r=128),this.getCPUBackend()!=null&&n.every(function(i){return o.texData.get(i.dataId).texture==null&&i.sizez().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var a=Math.floor(n.length/2),u=this.concat(n.slice(0,a),r),s=this.concat(n.slice(a),r);return this.concat([u,s],r)}if(z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&n[0].rank>1){var l=new Jb(n.map(function(h){return h.shape}),r);return this.compileAndRun(l,n)}var c=pi(n.map(function(h){return h.shape}),r),f=n.map(function(h){return h.as2D(-1,Z(h.shape.slice(r)))}),d=new Qb(f.map(function(h){return h.shape}));return this.compileAndRun(d,f).reshape(c)},t.prototype.neg=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.neg(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,Zp,n.dtype);var r=new ce(n.shape,Zp);return this.compileAndRun(r,[n])},t.prototype.batchMatMul=function(n,r,o,i){var a=o?n.shape[2]:n.shape[1],u=i?r.shape[1]:r.shape[2],s=o?n.shape[1]:n.shape[2],l=n.shape[0];if((a===1||u===1)&&s>1e3){o&&(n=n.transpose([0,2,1])),i&&(r=r.transpose([0,2,1]));var c=u===1?n:n.as3D(l,s,1),f=u===1?2:1,d=u===1?r.as3D(l,1,s):r;return this.multiply(c,d).sum(f,!0)}var h=st(n.dtype,r.dtype),p=new Vl(n.shape,[l,a,u],o,i);return this.compileAndRun(p,[n,r],h)},t.prototype.fusedBatchMatMul=function(n){var r=n.a,o=n.b,i=n.transposeA,a=n.transposeB,u=n.bias,s=n.activation,l=n.preluActivationWeights,c=i?r.shape[2]:r.shape[1],f=a?o.shape[1]:o.shape[2],d=r.shape[0],h=st(r.dtype,o.dtype),p=u!=null,m=l!=null,g=s?uu(s,!0):null,v=new Vl(r.shape,[d,c,f],i,a,p,g,m),y=[r,o];return u&&y.push(u),l&&y.push(l),this.compileAndRun(v,y,h)},t.prototype.multiply=function(n,r){if(n.dtype==="complex64"){var o=this.texData.get(n.dataId),i=this.texData.get(r.dataId),a=new Up(Gb,n.shape,r.shape),u=new Up(qb,n.shape,r.shape),s=[this.makeComplexComponentTensorInfo(n,o.complexTensors.real),this.makeComplexComponentTensorInfo(n,o.complexTensors.imag),this.makeComplexComponentTensorInfo(r,i.complexTensors.real),this.makeComplexComponentTensorInfo(r,i.complexTensors.imag)],l=this.compileAndRun(a,s),c=this.compileAndRun(u,s),f=this.complex(l,c);return l.dispose(),c.dispose(),f}if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.multiply(n,r);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,Vp,n.dtype);var d=new ze(Vp,n.shape,r.shape);return this.compileAndRun(d,[n,r],n.dtype)},t.prototype.batchNormalization=function(n,r,o,i,a,u){var s=[n,r,o],l=null;u!=null&&(l=u.shape,s.push(u));var c=null;if(a!=null&&(c=a.shape,s.push(a)),z().getBool("WEBGL_PACK_NORMALIZATION")){var f=new jb(n.shape,r.shape,o.shape,l,c,i);return this.compileAndRun(f,s)}var d=new Hb(n.shape,r.shape,o.shape,l,c,i);return this.compileAndRun(d,s)},t.prototype.localResponseNormalization4D=function(n,r,o,i,a){var u=z().getBool("WEBGL_PACK_NORMALIZATION")?new UC(n.shape,r,o,i,a):new WC(n.shape,r,o,i,a);return this.compileAndRun(u,[n])},t.prototype.LRNGrad=function(n,r,o,i,a,u,s){var l=new zC(r.shape,i,a,u,s);return this.compileAndRun(l,[r,o,n])},t.prototype.tile=function(n,r){if(n.dtype==="string"){var o=this.readSync(n.dataId).map(function(a){return Zu(a)});return E0(se(n.shape,n.dtype,o),r)}var i=new c_(n.shape,r);return this.compileAndRun(i,[n])},t.prototype.pad=function(n,r,o){var i=z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new KC(n.shape,r,o):new qC(n.shape,r,o);return this.compileAndRun(i,[n])},t.prototype.transpose=function(n,r){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.transpose(n,r);var o=z().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new d_(n.shape,r):new f_(n.shape,r);return this.compileAndRun(o,[n])},t.prototype.gather=function(n,r,o){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.gather(n,r,o);var i=new xC(n.shape,r.size,o);return this.compileAndRun(i,[n,r])},t.prototype.batchToSpaceND=function(n,r,o){I(n.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var i=r.reduce(function(f,d){return f*d}),a=is(n.shape,r,i),u=as(a.length,r.length),s=us(n.shape,r,i),l=f0(o,r.length),c=d0(s,o,r.length);return n.reshape(a).transpose(u).reshape(s).slice(l,c)},t.prototype.spaceToBatchND=function(n,r,o){I(n.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var i=r.reduce(function(d,h){return d*h}),a=[[0,0]];a.push.apply(a,o);for(var u=1+r.length;uh||p===d?m=!0:p=tf(d,p+1);return p}(s,a),c=new o_({windowSize:l,inSize:s,batchSize:u,numSegments:a}),f=this.compileAndRun(c,[n,o],i);return f.shape[1]===a?f:(o=os(0,a).tile([s/l]),this.segOpCompute(f,r,o,i,a))},t.prototype.argMinMaxReduce=function(n,r,o){var i=[r];if(Wt("arg"+o.charAt(0).toUpperCase()+o.slice(1),i,n.rank),!z().getBool("WEBGL_PACK_REDUCE")||n.rank<=2){var a=pt(n.shape,i),u=a[0],s=Z(a[1]),l=n.as2D(-1,s);return this.argReduce(l,o).reshape(u)}return this.argReducePacked(n,o)},t.prototype.argMin=function(n,r){return this.argMinMaxReduce(n,r,"min")},t.prototype.argMax=function(n,r){return this.argMinMaxReduce(n,r,"max")},t.prototype.cumsum=function(n,r,o,i){if(r!==n.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(n.rank-1)+" but got axis="+r);var a=new uC(n.shape,o,i);return this.compileAndRun(a,[n])},t.prototype.equal=function(n,r){if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,` return vec4(equal(a, b)); `,"bool");var o=new ze("return float(a == b);",n.shape,r.shape);return this.compileAndRun(o,[n,r],"bool")},t.prototype.notEqual=function(n,r){if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,` return vec4(notEqual(a, b)); @@ -3574,7 +3574,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, vec4(greaterThanEqual(a, vec4(1.0))) + vec4(greaterThanEqual(b, vec4(1.0))), vec4(1.0)); -`,"bool");var o=new ze("return float(a >= 1.0 || b >= 1.0);",n.shape,r.shape);return this.compileAndRun(o,[n,r],"bool")},t.prototype.select=function(n,r,o){var i=new l_(n.rank,r.shape,r.rank);return this.compileAndRun(i,[n,r,o],st(r.dtype,o.dtype))},t.prototype.where=function(n){is("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var r=n.dataSync();return Rd(n.shape,r)},t.prototype.topk=function(n,r,o){return D0(n.dataSync(),n.shape,n.dtype,r)},t.prototype.min=function(n,r){Wt("min",r,n.rank);var o=pt(n.shape,r),i=o[0],a=Z(o[1]),u=n.as2D(-1,a);return this.reduce(u,"min",u.dtype).reshape(i)},t.prototype.minimum=function(n,r){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.minimum(n,r);var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` +`,"bool");var o=new ze("return float(a >= 1.0 || b >= 1.0);",n.shape,r.shape);return this.compileAndRun(o,[n,r],"bool")},t.prototype.select=function(n,r,o){var i=new i_(n.rank,r.shape,r.rank);return this.compileAndRun(i,[n,r,o],st(r.dtype,o.dtype))},t.prototype.where=function(n){ns("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var r=n.dataSync();return Sd(n.shape,r)},t.prototype.topk=function(n,r,o){return S0(n.dataSync(),n.shape,n.dtype,r)},t.prototype.min=function(n,r){Wt("min",r,n.rank);var o=pt(n.shape,r),i=o[0],a=Z(o[1]),u=n.as2D(-1,a);return this.reduce(u,"min",u.dtype).reshape(i)},t.prototype.minimum=function(n,r){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.minimum(n,r);var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` vec4 result = vec4(min(a, b)); vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0)); @@ -3589,7 +3589,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, if (isnan(b)) return b; return min(a, b); -`,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.mod=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` +`,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.mod=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` vec4 result = mod(a, b); vec4 isNaN = vec4(equal(b, vec4(0.0))); @@ -3600,7 +3600,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC, return result; `,n.shape,r.shape):new ze(`if (b == 0.0) return NAN; - return mod(a, b);`,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.max=function(n,r){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.max(n,r);Wt("max",r,n.rank);var o=pt(n.shape,r),i=o[0],a=Z(o[1]),u=n.as2D(-1,a);return this.reduce(u,"max",u.dtype).reshape(i)},t.prototype.maximum=function(n,r){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.maximum(n,r);var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` + return mod(a, b);`,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.max=function(n,r){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.max(n,r);Wt("max",r,n.rank);var o=pt(n.shape,r),i=o[0],a=Z(o[1]),u=n.as2D(-1,a);return this.reduce(u,"max",u.dtype).reshape(i)},t.prototype.maximum=function(n,r){if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.maximum(n,r);var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` vec4 result = vec4(max(a, b)); vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0)); @@ -3668,7 +3668,7 @@ return a / b;`,n.shape,r.shape);return this.compileAndRun(o,[n,r],"float32")},t. } else { return NAN; } -`,n.shape,r.shape);return this.compileAndRun(o,[n,r],"int32")},t.prototype.add=function(n,r){if(n.dtype==="complex64"&&r.dtype==="complex64")return this.complexSeparableBinaryOp(n,r,Vl);if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.add(n,r);var o=st(n.dtype,r.dtype);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,Vl,o);var i=new ze(Vl,n.shape,r.shape);return this.compileAndRun(i,[n,r],o)},t.prototype.packedUnaryOp=function(n,r,o){var i=new Mi(n.shape,r);return this.compileAndRun(i,[n],o)},t.prototype.packedBinaryOp=function(n,r,o,i,a){a===void 0&&(a=!1);var u=new Xn(o,n.shape,r.shape,a);return this.compileAndRun(u,[n,r],i)},t.prototype.complexSeparableBinaryOp=function(n,r,o){var i=this,a=this.texData.get(n.dataId),u=this.texData.get(r.dataId),s=[[a.complexTensors.real,u.complexTensors.real],[a.complexTensors.imag,u.complexTensors.imag]].map(function(d){var h=d[0],p=d[1],m=i.makeComplexComponentTensorInfo(n,h),g=i.makeComplexComponentTensorInfo(r,p),v=new ze(o,n.shape,r.shape);return i.compileAndRun(v,[m,g],st(h.dtype,p.dtype))}),l=s[0],c=s[1],f=this.complex(l,c);return l.dispose(),c.dispose(),f},t.prototype.makeComplexComponentTensorInfo=function(n,r){return{dataId:r.dataId,dtype:r.dtype,shape:n.shape}},t.prototype.addN=function(n){if(n.length===1)return n[0];if(n.length>z().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var r=Math.floor(n.length/2),o=this.addN(n.slice(0,r)),i=this.addN(n.slice(r));return this.addN([o,i])}var a=n.map(function(l){return l.dtype}).reduce(function(l,c){return st(l,c)}),u=n.map(function(l){return l.shape}),s=z().getBool("WEBGL_PACK")?new Lb(n[0].shape,u):new Bb(n[0].shape,u);return this.compileAndRun(s,n,a)},t.prototype.subtract=function(n,r){if(n.dtype==="complex64"&&r.dtype==="complex64")return this.complexSeparableBinaryOp(n,r,$l);if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.subtract(n,r);var o=st(n.dtype,r.dtype);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,$l,n.dtype);var i=new ze($l,n.shape,r.shape);return this.compileAndRun(i,[n,r],o)},t.prototype.pow=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` +`,n.shape,r.shape);return this.compileAndRun(o,[n,r],"int32")},t.prototype.add=function(n,r){if(n.dtype==="complex64"&&r.dtype==="complex64")return this.complexSeparableBinaryOp(n,r,zl);if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.add(n,r);var o=st(n.dtype,r.dtype);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,zl,o);var i=new ze(zl,n.shape,r.shape);return this.compileAndRun(i,[n,r],o)},t.prototype.packedUnaryOp=function(n,r,o){var i=new Ai(n.shape,r);return this.compileAndRun(i,[n],o)},t.prototype.packedBinaryOp=function(n,r,o,i,a){a===void 0&&(a=!1);var u=new qn(o,n.shape,r.shape,a);return this.compileAndRun(u,[n,r],i)},t.prototype.complexSeparableBinaryOp=function(n,r,o){var i=this,a=this.texData.get(n.dataId),u=this.texData.get(r.dataId),s=[[a.complexTensors.real,u.complexTensors.real],[a.complexTensors.imag,u.complexTensors.imag]].map(function(d){var h=d[0],p=d[1],m=i.makeComplexComponentTensorInfo(n,h),g=i.makeComplexComponentTensorInfo(r,p),v=new ze(o,n.shape,r.shape);return i.compileAndRun(v,[m,g],st(h.dtype,p.dtype))}),l=s[0],c=s[1],f=this.complex(l,c);return l.dispose(),c.dispose(),f},t.prototype.makeComplexComponentTensorInfo=function(n,r){return{dataId:r.dataId,dtype:r.dtype,shape:n.shape}},t.prototype.addN=function(n){if(n.length===1)return n[0];if(n.length>z().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var r=Math.floor(n.length/2),o=this.addN(n.slice(0,r)),i=this.addN(n.slice(r));return this.addN([o,i])}var a=n.map(function(l){return l.dtype}).reduce(function(l,c){return st(l,c)}),u=n.map(function(l){return l.shape}),s=z().getBool("WEBGL_PACK")?new Fb(n[0].shape,u):new Pb(n[0].shape,u);return this.compileAndRun(s,n,a)},t.prototype.subtract=function(n,r){if(n.dtype==="complex64"&&r.dtype==="complex64")return this.complexSeparableBinaryOp(n,r,Ul);if(this.shouldExecuteOnCPU([n,r]))return this.cpuBackend.subtract(n,r);var o=st(n.dtype,r.dtype);if(z().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(n,r,Ul,n.dtype);var i=new ze(Ul,n.shape,r.shape);return this.compileAndRun(i,[n,r],o)},t.prototype.pow=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise. vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1))); vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1); @@ -3698,7 +3698,7 @@ if (b == 0.0) { } return (round(mod(b, 2.0)) != 1) ? pow(abs(a), b) : sign(a) * pow(abs(a), b); -`,n.shape,r.shape),i=st(n.dtype,r.dtype);return this.compileAndRun(o,[n,r],i)},t.prototype.ceil=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.ceil(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,iv,n.dtype);var r=new ce(n.shape,iv);return this.compileAndRun(r,[n])},t.prototype.floor=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.floor(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,av,n.dtype);var r=new ce(n.shape,av);return this.compileAndRun(r,[n])},t.prototype.sign=function(n){var r=new ce(n.shape,` +`,n.shape,r.shape),i=st(n.dtype,r.dtype);return this.compileAndRun(o,[n,r],i)},t.prototype.ceil=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.ceil(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,ev,n.dtype);var r=new ce(n.shape,ev);return this.compileAndRun(r,[n])},t.prototype.floor=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.floor(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,tv,n.dtype);var r=new ce(n.shape,tv);return this.compileAndRun(r,[n])},t.prototype.sign=function(n){var r=new ce(n.shape,` if (isnan(x)) { return 0.0; } return sign(x); `);return this.compileAndRun(r,[n])},t.prototype.isNaN=function(n){var r=new ce(n.shape,"return float(isnan(x));");return this.compileAndRun(r,[n],"bool")},t.prototype.isInf=function(n){var r=new ce(n.shape,"return float(isinf(x));");return this.compileAndRun(r,[n],"bool")},t.prototype.isFinite=function(n){var r=new ce(n.shape,"return float(!isnan(x) && !isinf(x));");return this.compileAndRun(r,[n],"bool")},t.prototype.round=function(n){var r=new ce(n.shape,` @@ -3716,7 +3716,7 @@ return (round(mod(b, 2.0)) != 1) ? return base + 1.0; } } -`);return this.compileAndRun(r,[n])},t.prototype.exp=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.exp(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,uv,n.dtype);var r=new ce(n.shape,uv);return this.compileAndRun(r,[n])},t.prototype.expm1=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.expm1(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,sv,n.dtype);var r=new ce(n.shape,sv);return this.compileAndRun(r,[n])},t.prototype.softmax=function(n,r){var o=et([r],n.shape),i=this.max(n,o),a=Mt(i.shape,o),u=this.subtract(n,i.reshape(a)),s=this.exp(u),l=this.sum(s,o).reshape(a);return this.realDivide(s,l)},t.prototype.log=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.log(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,` +`);return this.compileAndRun(r,[n])},t.prototype.exp=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.exp(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,nv,n.dtype);var r=new ce(n.shape,nv);return this.compileAndRun(r,[n])},t.prototype.expm1=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.expm1(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,rv,n.dtype);var r=new ce(n.shape,rv);return this.compileAndRun(r,[n])},t.prototype.softmax=function(n,r){var o=et([r],n.shape),i=this.max(n,o),a=Mt(i.shape,o),u=this.subtract(n,i.reshape(a)),s=this.exp(u),l=this.sum(s,o).reshape(a);return this.realDivide(s,l)},t.prototype.log=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.log(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,` vec4 result = log(x); vec4 isNaN = vec4(lessThan(x, vec4(0.0))); result.r = isNaN.r == 1.0 ? NAN : result.r; @@ -3726,10 +3726,10 @@ return (round(mod(b, 2.0)) != 1) ? return result; `,n.dtype);var r=new ce(n.shape,`if (x < 0.0) return NAN; - return log(x);`);return this.compileAndRun(r,[n])},t.prototype.log1p=function(n){var r=new ce(n.shape,"return log(1.0 + x);");return this.compileAndRun(r,[n])},t.prototype.sqrt=function(n){var r=new ce(n.shape,"return sqrt(x);");return this.compileAndRun(r,[n])},t.prototype.rsqrt=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.rsqrt(n);var r=new ce(n.shape,"return inversesqrt(x);");return this.compileAndRun(r,[n])},t.prototype.reciprocal=function(n){var r=new ce(n.shape,"return 1.0 / x;");return this.compileAndRun(r,[n])},t.prototype.relu=function(n){var r;return r=z().getBool("WEBGL_PACK")?new Mi(n.shape,L0):new ce(n.shape,M0),this.compileAndRun(r,[n])},t.prototype.relu6=function(n){var r;return r=z().getBool("WEBGL_PACK")?new Mi(n.shape,W0):new ce(n.shape,O0),this.compileAndRun(r,[n])},t.prototype.prelu=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(F0,n.shape,r.shape):new ze(P0,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.elu=function(n){if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,z0,n.dtype);var r=new ce(n.shape,B0);return this.compileAndRun(r,[n])},t.prototype.eluDer=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` + return log(x);`);return this.compileAndRun(r,[n])},t.prototype.log1p=function(n){var r=new ce(n.shape,"return log(1.0 + x);");return this.compileAndRun(r,[n])},t.prototype.sqrt=function(n){var r=new ce(n.shape,"return sqrt(x);");return this.compileAndRun(r,[n])},t.prototype.rsqrt=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.rsqrt(n);var r=new ce(n.shape,"return inversesqrt(x);");return this.compileAndRun(r,[n])},t.prototype.reciprocal=function(n){var r=new ce(n.shape,"return 1.0 / x;");return this.compileAndRun(r,[n])},t.prototype.relu=function(n){var r;return r=z().getBool("WEBGL_PACK")?new Ai(n.shape,F0):new ce(n.shape,N0),this.compileAndRun(r,[n])},t.prototype.relu6=function(n){var r;return r=z().getBool("WEBGL_PACK")?new Ai(n.shape,M0):new ce(n.shape,A0),this.compileAndRun(r,[n])},t.prototype.prelu=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(T0,n.shape,r.shape):new ze(D0,n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.elu=function(n){if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,O0,n.dtype);var r=new ce(n.shape,P0);return this.compileAndRun(r,[n])},t.prototype.eluDer=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.))); return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0)))); -`,n.shape,r.shape):new ze("return (b >= 1.0) ? a : a * (b + 1.0);",n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.selu=function(n){var r=new ce(n.shape,y_);return this.compileAndRun(r,[n])},t.prototype.int=function(n){var r=new ce(n.shape,"return float(int(x));");return this.compileAndRun(r,[n],"int32")},t.prototype.clip=function(n,r,o){var i,a=(i=z().getBool("WEBGL_PACK_CLIP")?new Zb(n.shape):new Jb(n.shape)).getCustomSetupFunc(r,o);return this.compileAndRun(i,[n],null,a)},t.prototype.abs=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.abs(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,rv,n.dtype);var r=new ce(n.shape,rv);return this.compileAndRun(r,[n])},t.prototype.complexAbs=function(n){var r=this.texData.get(n.dataId),o=new eC(n.shape),i=[this.makeComplexComponentTensorInfo(n,r.complexTensors.real),this.makeComplexComponentTensorInfo(n,r.complexTensors.imag)];return this.compileAndRun(o,i)},t.prototype.sigmoid=function(n){var r=new ce(n.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(r,[n])},t.prototype.softplus=function(n){var r=new ce(n.shape,` +`,n.shape,r.shape):new ze("return (b >= 1.0) ? a : a * (b + 1.0);",n.shape,r.shape);return this.compileAndRun(o,[n,r])},t.prototype.selu=function(n){var r=new ce(n.shape,p_);return this.compileAndRun(r,[n])},t.prototype.int=function(n){var r=new ce(n.shape,"return float(int(x));");return this.compileAndRun(r,[n],"int32")},t.prototype.clip=function(n,r,o){var i,a=(i=z().getBool("WEBGL_PACK_CLIP")?new Xb(n.shape):new Kb(n.shape)).getCustomSetupFunc(r,o);return this.compileAndRun(i,[n],null,a)},t.prototype.abs=function(n){if(this.shouldExecuteOnCPU([n]))return this.cpuBackend.abs(n);if(z().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(n,Jp,n.dtype);var r=new ce(n.shape,Jp);return this.compileAndRun(r,[n])},t.prototype.complexAbs=function(n){var r=this.texData.get(n.dataId),o=new Yb(n.shape),i=[this.makeComplexComponentTensorInfo(n,r.complexTensors.real),this.makeComplexComponentTensorInfo(n,r.complexTensors.imag)];return this.compileAndRun(o,i)},t.prototype.sigmoid=function(n){var r=new ce(n.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(r,[n])},t.prototype.softplus=function(n){var r=new ce(n.shape,` float epsilon = 1.1920928955078125e-7; float threshold = log(epsilon) + 2.0; @@ -3749,7 +3749,7 @@ return (round(mod(b, 2.0)) != 1) ? result = log(exp_x + 1.0); } return result; -`);return this.compileAndRun(r,[n])},t.prototype.sin=function(n){var r=new ce(n.shape,x_);return this.compileAndRun(r,[n])},t.prototype.cos=function(n){var r=new ce(n.shape,w_);return this.compileAndRun(r,[n])},t.prototype.tan=function(n){var r=new ce(n.shape,"return tan(x);");return this.compileAndRun(r,[n])},t.prototype.asin=function(n){var r=new ce(n.shape,b_);return this.compileAndRun(r,[n])},t.prototype.acos=function(n){var r=new ce(n.shape,C_);return this.compileAndRun(r,[n])},t.prototype.atan=function(n){var r=new ce(n.shape,__);return this.compileAndRun(r,[n])},t.prototype.atan2=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Xn(` +`);return this.compileAndRun(r,[n])},t.prototype.sin=function(n){var r=new ce(n.shape,v_);return this.compileAndRun(r,[n])},t.prototype.cos=function(n){var r=new ce(n.shape,m_);return this.compileAndRun(r,[n])},t.prototype.tan=function(n){var r=new ce(n.shape,"return tan(x);");return this.compileAndRun(r,[n])},t.prototype.asin=function(n){var r=new ce(n.shape,g_);return this.compileAndRun(r,[n])},t.prototype.acos=function(n){var r=new ce(n.shape,y_);return this.compileAndRun(r,[n])},t.prototype.atan=function(n){var r=new ce(n.shape,x_);return this.compileAndRun(r,[n])},t.prototype.atan2=function(n,r){var o=z().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new qn(` vec4 result = atan(a, b); vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0)); @@ -3773,7 +3773,7 @@ return (round(mod(b, 2.0)) != 1) ? `);return this.compileAndRun(r,[n])},t.prototype.tanh=function(n){var r=new ce(n.shape,` float e2x = exp(-2.0 * abs(x)); return sign(x) * (1.0 - e2x) / (1.0 + e2x); -`);return this.compileAndRun(r,[n])},t.prototype.asinh=function(n){var r=new ce(n.shape,E_);return this.compileAndRun(r,[n])},t.prototype.acosh=function(n){var r=new ce(n.shape,S_);return this.compileAndRun(r,[n])},t.prototype.atanh=function(n){var r=new ce(n.shape,k_);return this.compileAndRun(r,[n])},t.prototype.erf=function(n){var r=new ce(n.shape,` +`);return this.compileAndRun(r,[n])},t.prototype.asinh=function(n){var r=new ce(n.shape,w_);return this.compileAndRun(r,[n])},t.prototype.acosh=function(n){var r=new ce(n.shape,b_);return this.compileAndRun(r,[n])},t.prototype.atanh=function(n){var r=new ce(n.shape,C_);return this.compileAndRun(r,[n])},t.prototype.erf=function(n){var r=new ce(n.shape,` // Error function is calculated approximately with elementary function. // See "Handbook of Mathematical Functions with Formulas, // Graphs, and Mathematical Tables", Abramowitz and Stegun. @@ -3788,13 +3788,13 @@ return (round(mod(b, 2.0)) != 1) ? x = abs(x); float t = 1.0 / (1.0 + p * x); return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x)); -`);return this.compileAndRun(r,[n])},t.prototype.step=function(n,r){var o=new ce(n.shape,function(i){return i===void 0&&(i=0),bn+` +`);return this.compileAndRun(r,[n])},t.prototype.step=function(n,r){var o=new ce(n.shape,function(i){return i===void 0&&(i=0),wn+` return x > 0.0 ? 1.0 : float(`+i+`); - `}(r));return this.compileAndRun(o,[n])},t.prototype.conv2dByMatMul=function(n,r,o,i,a,u){var s=n.shape,l=this.texData.get(n.dataId),c=o.inChannels,f=s[0]*s[1]*s[2],d=o.outChannels,h=o.dataFormat==="channelsLast",p=(f===1||d===1)&&c>1e3,m=s[2]%2!=0&&!!l.isPacked;if(p||!z().getBool("WEBGL_LAZILY_UNPACK")||!z().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!m){var g=h?s[0]*s[1]*s[2]:s[0]*s[2]*s[3],v=this.reshape(n,[1,g,o.inChannels]),y=this.reshape(r,[1,o.inChannels,o.outChannels]);return this.reshape(this.fusedBatchMatMul({a:v,b:y,transposeA:!1,transposeB:!1,bias:i,activation:a,preluActivationWeights:u}),o.outShape)}var x=h?s[0]*s[1]*(s[2]+1):s[0]*s[2]*(s[3]+1),w={dataId:n.dataId,shape:[1,x,o.inChannels],dtype:n.dtype},b=l.shape;l.shape=l.shape.slice(),l.shape[l.shape.length-2]++,I(iu(l.shape,w.shape),function(){return"packed reshape "+l.shape+" to "+w.shape+" isn't free"});var C=this.reshape(r,[1,o.inChannels,o.outChannels]),_=this.fusedBatchMatMul({a:w,b:C,transposeA:!1,transposeB:!1,bias:i,activation:a,preluActivationWeights:u}),E=this.texData.get(_.dataId);return I(E.isPacked,function(){return"batchMatMul result is expected to be packed"}),l.shape=b,E.shape=o.outShape,A.makeTensorFromDataId(_.dataId,o.outShape,_.dtype)},t.prototype.conv2dWithIm2Row=function(n,r,o,i,a,u){var s=o.filterWidth,l=o.filterHeight,c=o.inChannels,f=o.outWidth,d=o.outHeight,h=o.dataFormat==="channelsLast",p=s*l*c,m=d*f,g=[p,m],v=n.squeeze([0]),y=r.reshape([1,p,-1]),x=new VC(g,v.shape,o),w=this.compileAndRun(x,[v]).reshape([1,g[0],g[1]]),b=i!=null,C=u!=null,_=a?lu(a,!0):null,E=new Hl(w.shape,[1,m,o.outChannels],!0,!1,b,_,C),R=[w,y];i&&R.push(i),C&&R.push(u);var k=this.compileAndRun(E,R);return h?k.reshape([1,d,f,o.outChannels]):k.reshape([1,o.outChannels,d,f])},t.prototype.fusedConv2d=function(n){var r=n.input,o=n.filter,i=n.convInfo,a=n.bias,u=n.activation,s=n.preluActivationWeights;if(i.filterHeight===1&&i.filterWidth===1&&i.dilationHeight===1&&i.dilationWidth===1&&i.strideHeight===1&&i.strideWidth===1&&(i.padInfo.type==="SAME"||i.padInfo.type==="VALID"))return this.conv2dByMatMul(r,o,i,a,u,s);if(z().getBool("WEBGL_CONV_IM2COL")&&r.shape[0]===1)return this.conv2dWithIm2Row(r,o,i,a,u,s);var l=a!=null,c=s!=null,f=u?lu(u,!1):null,d=new Kp(i,l,f,c),h=[r,o];return a&&h.push(a),s&&h.push(s),this.compileAndRun(d,h)},t.prototype.conv2d=function(n,r,o){if(o.filterHeight===1&&o.filterWidth===1&&o.dilationHeight===1&&o.dilationWidth===1&&o.strideHeight===1&&o.strideWidth===1&&(o.padInfo.type==="SAME"||o.padInfo.type==="VALID"))return this.conv2dByMatMul(n,r,o);if(z().getBool("WEBGL_CONV_IM2COL")&&n.shape[0]===1)return this.conv2dWithIm2Row(n,r,o);var i=new Kp(o);return this.compileAndRun(i,[n,r])},t.prototype.conv2dDerInput=function(n,r,o){var i=new oC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv2dDerFilter=function(n,r,o){var i=new rC(o);return this.compileAndRun(i,[n,r])},t.prototype.fusedDepthwiseConv2D=function(n){var r,o=n.input,i=n.filter,a=n.convInfo,u=n.bias,s=n.activation,l=n.preluActivationWeights,c=z().getBool("WEBGL_PACK_DEPTHWISECONV")&&a.strideWidth<=2&&a.outChannels/a.inChannels==1,f=s?lu(s,c):null,d=[o,i],h=u!=null,p=l!=null;return h&&d.push(u),p&&d.push(l),c?(r=new Yp(a,h,f,p),this.compileAndRun(r,d)):(r=new Xp(a,h,f,p),this.compileAndRun(r,d))},t.prototype.depthwiseConv2D=function(n,r,o){var i;return z().getBool("WEBGL_PACK_DEPTHWISECONV")&&o.strideWidth<=2&&o.outChannels/o.inChannels==1?(i=new Yp(o),this.compileAndRun(i,[n,r])):(i=new Xp(o),this.compileAndRun(i,[n,r]))},t.prototype.depthwiseConv2DDerInput=function(n,r,o){var i=new sC(o);return this.compileAndRun(i,[n,r])},t.prototype.depthwiseConv2DDerFilter=function(n,r,o){var i=new uC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3d=function(n,r,o){var i=new lC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3dDerInput=function(n,r,o){var i=new aC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3dDerFilter=function(n,r,o){var i=new iC(o);return this.compileAndRun(i,[n,r])},t.prototype.maxPool=function(n,r){var o=new jl(r,"max",!1);return this.compileAndRun(o,[n])},t.prototype.avgPool=function(n,r){var o=new jl(r,"avg",!1);return this.compileAndRun(o,[n],"float32")},t.prototype.maxPoolBackprop=function(n,r,o,i){var a=new jl(i,"max",!0),u=this.compileAndRun(a,[r]),s=new GC(i),l=this.compileAndRun(s,[n,u],r.dtype);return u.dispose(),l},t.prototype.avgPoolBackprop=function(n,r,o){var i=new Gb(o);return this.compileAndRun(i,[n],r.dtype)},t.prototype.cast=function(n,r){return E0(n,r,this)},t.prototype.unstack=function(n,r){for(var o=n.shape[r],i=new Array(n.rank-1),a=0,u=0;u1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+r});var i=n.shape[0],a=o==="NHWC"?n.shape[1]:n.shape[2],u=o==="NHWC"?n.shape[2]:n.shape[3],s=o==="NHWC"?n.shape[3]:n.shape[1],l=a*r,c=u*r,f=s/(r*r),d=new pC(o==="NHWC"?[i,l,c,f]:[i,f,l,c],r,o);return this.compileAndRun(d,[n])},t.prototype.split=function(n,r,o){return R0(n,r,o)},t.prototype.scatterND=function(n,r,o){var i=fs(0,n,o),a=i.sliceRank,u=i.numUpdates,s=i.sliceSize,l=i.strides,c=i.outputSize,f=[c/s,s],d=n.reshape([u,a]),h=r.reshape([u,s]);if(c===0)return df(lt([]),o);var p=K(0),m=new ev(u,a,d.rank,h.rank,l,f);return this.compileAndRun(m,[h,d,p]).reshape(o)},t.prototype.sparseToDense=function(n,r,o,i){var a=fs(0,n,o),u=a.sliceRank,s=a.numUpdates,l=a.strides,c=a.outputSize,f=new ev(s,u,n.rank,r.rank,l,[c,1]);return this.compileAndRun(f,[r,n,i]).reshape(o)},t.prototype.fft=function(n){return this.fftImpl(n,!1)},t.prototype.ifft=function(n){return this.fftImpl(n,!0)},t.prototype.fftImpl=function(n,r){var o=this.texData.get(n.dataId),i=new Jp(wC,n.shape,r),a=new Jp(bC,n.shape,r),u=[this.makeComplexComponentTensorInfo(n,o.complexTensors.real),this.makeComplexComponentTensorInfo(n,o.complexTensors.imag)],s=this.compileAndRun(i,u),l=this.compileAndRun(a,u),c=this.complex(s,l).as2D(n.shape[0],n.shape[1]);return s.dispose(),l.dispose(),c},t.prototype.gatherND=function(n,r){var o=r.shape,i=o[o.length-1],a=g0(n,r),u=a[0],s=a[1],l=a[2],c=a[3],f=r.reshape([s,i]),d=n.reshape([n.size/l,l]),h=new EC(i,c,[s,l]);return this.compileAndRun(h,[d,f]).reshape(u)},t.prototype.fill=function(n,r,o){if((o=o||Da(r))==="string"){var i=ts(o,Z(n));return i.fill(r),A.makeTensor(i,n,o,this)}var a=new CC(n,r),u=a.getCustomSetupFunc(r);return this.compileAndRun(a,[],o,u)},t.prototype.onesLike=function(n){if(n.dtype==="string")throw new Error("onesLike is not supported under string dtype");return this.fill(n.shape,1,n.dtype)},t.prototype.zerosLike=function(n){return this.fill(n.shape,n.dtype==="string"?"":0,n.dtype)},t.prototype.linspace=function(n,r,o){return S0(n,r,o)},t.prototype.makeTensorInfo=function(n,r){var o=this.write(null,n,r);return this.texData.get(o).usage=null,{dataId:o,shape:n,dtype:r}},t.prototype.makeOutput=function(n,r){var o=this.makeTensorInfo(n,r).dataId;return A.makeTensorFromDataId(o,n,r,this)},t.prototype.unpackTensor=function(n){var r=new I_(n.shape);return this.runWebGLProgram(r,[n],n.dtype)},t.prototype.packTensor=function(n){var r=new YC(n.shape);return this.runWebGLProgram(r,[n],n.dtype,null,!0)},t.prototype.packedReshape=function(n,r){var o=[rs(n.shape)].concat(os(n.shape)),i={dtype:n.dtype,shape:o,dataId:n.dataId},a=[rs(r)].concat(os(r)),u=new e_(a,o),s=this.runWebGLProgram(u,[i],n.dtype,null,!0);return{dataId:s.dataId,shape:r,dtype:s.dtype}},t.prototype.decode=function(n){var r,o=this.texData.get(n),i=o.isPacked,a=o.shape,u=o.dtype,s=zl(a);return r=i?new hC(s):new dC(s),{dtype:u,shape:a,dataId:this.runWebGLProgram(r,[{shape:s,dtype:u,dataId:n}],u,null,!0).dataId}},t.prototype.runWebGLProgram=function(n,r,o,i,a){var u=this;a===void 0&&(a=!1);var s=this.makeTensorInfo(n.outputShape,o),l=this.texData.get(s.dataId);if(n.packedOutput&&(l.isPacked=!0),n.outPackingScheme===ga.DENSE){var c=Xi(n.outputShape);l.texShape=c.map(function(x){return 2*x})}if(n.outTexUsage!=null&&(l.usage=n.outTexUsage),Z(s.shape)===0)return l.values=va(s.dtype,0),s;var f=[],d=r.map(function(x){if(x.dtype==="complex64")throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var w=u.texData.get(x.dataId);if(w.texture==null){if(!n.packedInputs&&Z(x.shape)<=z().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:x.shape,texData:null,isUniform:!0,uniformValues:w.values};n.packedInputs&&(w.isPacked=!0,w.shape=x.shape)}else if(!!w.isPacked!=!!n.packedInputs)x=w.isPacked?u.unpackTensor(x):u.packTensor(x),f.push(x),w=u.texData.get(x.dataId);else if(w.isPacked&&!iu(w.shape,x.shape)){var b=x,C=x.shape;x.shape=w.shape,x=u.packedReshape(x,C),f.push(x),w=u.texData.get(x.dataId),b.shape=C}return u.uploadToGPU(x.dataId),{shape:x.shape,texData:w,isUniform:!1}});this.uploadToGPU(s.dataId);var h,p={shape:s.shape,texData:l,isUniform:!1},m=function(x,w,b){var C="";w.concat(b).forEach(function(R){var k=R.texData!=null&&R.texData.slice!=null&&R.texData.slice.flatOffset>0,T=R.isUniform?"uniform":R.texData.texShape;C+=R.shape+"_"+T+"_"+k});var _=x.userCode,E=x.constructor.name;return E+="_"+C+"_"+_}(n,d,p),g=this.getAndSaveBinary(m,function(){return function(x,w,b,C){var _=w.userCode,E=b.map(function(P,M){var B={logicalShape:P.shape,texShape:P.isUniform?null:P.texData.texShape,isUniform:P.isUniform,isPacked:!P.isUniform&&P.texData.isPacked,flatOffset:null};return P.texData!=null&&P.texData.slice!=null&&P.texData.slice.flatOffset>0&&(B.flatOffset=P.texData.slice.flatOffset),{name:w.variableNames[M],shapeInfo:B}}),R=E.map(function(P){return P.shapeInfo}),k={logicalShape:C.shape,texShape:C.texData.texShape,isUniform:!1,isPacked:C.texData.isPacked,flatOffset:null},T=zb(E,k,_,w.packedInputs),N=x.createProgram(T),W=null,L=x.getUniformLocation(N,"NAN",!1);z().getNumber("WEBGL_VERSION")===1&&(W=x.getUniformLocation(N,"INFINITY",!1));for(var U={},$=0;$0)return 32}return 16})),this.floatPrecisionValue},t.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},t.prototype.uploadToGPU=function(n){var r,o=this.texData.get(n),i=o.shape,a=o.dtype,u=o.values,s=o.texture,l=o.usage,c=o.isPacked;if(s==null){var f,d=this.activeTimers!=null;d&&(f=Dn());var h=o.texShape;if(h==null&&(h=O2(i,c),o.texShape=h),u!=null){var p=zl(i),m=void 0,g=h[1],v=h[0],y=u instanceof Uint8Array;c?(g=(r=Na(h[0],h[1]))[0],v=r[1],m=new xC(p,[v,g],y)):m=new yC(p,[v,g],y);var x=this.makeTensorInfo([v,g],a);this.texData.get(x.dataId).usage=y?Vt.PIXELS:Vt.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(x.dataId),g,v,u);var w=this.runWebGLProgram(m,[x],a,null,!0),b=this.texData.get(w.dataId);o.texture=b.texture,o.texShape=b.texShape,o.isPacked=b.isPacked,o.usage=b.usage,this.disposeData(x.dataId),this.texData.delete(w.dataId),o.values=null,d&&(this.uploadWaitMs+=Dn()-f)}else{var C=this.acquireTexture(h,l,a,c);o.texture=C}}},t.prototype.convertAndCacheOnCPU=function(n,r){var o=this.texData.get(n),i=o.dtype;return this.releaseGPUData(n),r!=null&&(o.values=function(a,u){if(u==="float32"||u==="complex64")return a;if(u==="int32"||u==="bool"){for(var s=u==="int32"?new Int32Array(a.length):new Uint8Array(a.length),l=0;l1024*this.numMBBeforeWarning*1024){var a=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+a+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(n,r,i)},t.prototype.computeBytes=function(n,r){return n[0]*n[1]*Zg(r)},t}(C0);a0()&&A.registerBackend("webgl",function(){return new T_},2);var N_=D({square_:function(e){var t=S(e,"x","square"),n=[t];return A.runKernelFunc(function(r,o){return o([t]),r.square(t)},{x:t},null,"Square",{},n,[])}}),xa="SquaredDifference",U0=D({squaredDifference_:function(e,t){var n,r=S(e,"a","squaredDifference"),o=S(t,"b","squaredDifference");n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape);var i={a:r,b:o},a=[r,o];return A.runKernelFunc(function(u,s){var l=u.squaredDifference(r,o);return s([r,o]),l},i,function(u,s){var l=s[0],c=s[1],f=K(2);return{a:function(){return u.mul(l.sub(c).mul(f))},b:function(){return u.mul(c.sub(l).mul(f))}}},xa,{},a,[])}}),A_=D({abs_:function(e){var t=S(e,"x","abs");return t.dtype==="complex64"?A.runKernelFunc(function(n){return n.complexAbs(t)},{$x:t}):A.runKernelFunc(function(n,r){var o=n.abs(t);return r([t]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mul(o.toFloat().step(-1))}}},"Abs")}}),P_=D({acos_:function(e){var t=S(e,"x","acos");return A.runKernelFunc(function(n,r){var o=n.acos(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).sub(o.toFloat().square()).sqrt()).neg()}}})}}),F_=D({acosh_:function(e){var t=S(e,"x","acosh");return A.runKernelFunc(function(n,r){var o=n.acosh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(o.toFloat().square().sub(1).sqrt())}}})}}),M_=D({asin_:function(e){var t=S(e,"x","asin");return A.runKernelFunc(function(n,r){var o=n.asin(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).sub(o.toFloat().square()).sqrt())}}})}}),O_=D({asinh_:function(e){var t=S(e,"x","asinh");return A.runKernelFunc(function(n,r){var o=n.asinh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).add(o.toFloat().square()).sqrt())}}})}}),B_=D({atan_:function(e){var t=S(e,"x","atan");return A.runKernelFunc(function(n,r){var o=n.atan(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.toFloat().square().add(1))}}})}}),L_=D({atanh_:function(e){var t=S(e,"x","atanh");return A.runKernelFunc(function(n,r){var o=n.atanh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(K(1).sub(o.toFloat().square()))}}})}}),W_=D({ceil_:function(e){var t=S(e,"x","ceil");return A.runKernelFunc(function(n){return n.ceil(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),Nd=D({clipByValue_:function(e,t,n){var r=S(e,"x","clipByValue");I(t<=n,function(){return"Error in clip: min ("+t+") must be less than or equal to max ("+n+")."});var o=[r],i={min:t,max:n};return A.runKernelFunc(function(a,u){var s=a.clip(r,t,n);return u([r]),s},{x:r},function(a,u){var s=u[0];return{x:function(){return a.where(s.greaterEqual(t).logicalAnd(s.lessEqual(n)),ye(a))}}},"ClipByValue",i,o)}}),z_=D({cos_:function(e){var t=S(e,"x","cos"),n=[t];return A.runKernelFunc(function(r,o){var i=r.cos(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return i.toFloat().sin().neg().mul(r)}}},"Cos",{},n)}}),U_=D({cosh_:function(e){var t=S(e,"x","cosh");return A.runKernelFunc(function(n,r){var o=n.cosh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return o.toFloat().sinh().mulStrict(n)}}})}}),V_=D({erf_:function(e){var t=S(e,"x","erf");return I(t.dtype==="int32"||t.dtype==="float32",function(){return"Input dtype must be `int32` or `float32`."}),t.dtype==="int32"&&(t=t.toFloat()),A.runKernelFunc(function(n,r){var o=n.erf(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),pf=D({exp_:function(e){var t=S(e,"x","exp");return A.runKernelFunc(function(n,r){var o=n.exp(t);return r([o]),o},{x:t},function(n,r){return{x:function(){return n.mulStrict(r[0])}}},"Exp",{},[],[!0])}}),$_=D({expm1_:function(e){var t=S(e,"x","expm1");return A.runKernelFunc(function(n,r){var o=n.expm1(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.exp())}}})}}),H_=D({floor_:function(e){var t=S(e,"x","floor");return A.runKernelFunc(function(n){return n.floor(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),j_=D({log_:function(e){var t=S(e,"x","log"),n=[t];return A.runKernelFunc(function(r,o){var i=r.log(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return r.div(i.toFloat())}}},"Log",{},n)}}),G_=D({log1p_:function(e){var t=S(e,"x","log1p");return A.runKernelFunc(function(n,r){var o=n.log1p(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.add(1))}}})}}),q_=D({logSigmoid_:function(e){var t=S(e,"x","logSigmoid");return A.runKernelFunc(function(n,r){var o=n.softplus(t.neg()).neg();return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.neg().sigmoid())}}})}}),vs=D({neg_:function(e){var t=S(e,"x","neg"),n=[t];return A.runKernelFunc(function(r){return r.neg(t)},{x:t},function(r){return{x:function(){return r.neg()}}},"Neg",{},n)}}),K_=D({reciprocal_:function(e){var t=S(e,"x","reciprocal");return A.runKernelFunc(function(n,r){var o=n.reciprocal(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.square().neg())}}})}}),X_=D({round_:function(e){var t=S(e,"x","round");return A.runKernelFunc(function(n){return n.round(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),V0=D({rsqrt_:function(e){var t=S(e,"x","rsqrt"),n=[t];return A.runKernelFunc(function(r,o){var i=r.rsqrt(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return r.div(i.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},n)}}),$0=D({sigmoid_:function(e){var t=S(e,"x","sigmoid");return A.runKernelFunc(function(n,r){var o=n.sigmoid(t);return r([o]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mul(o.mul(K(1).sub(o)))}}},"Sigmoid")}}),Y_=D({sign_:function(e){var t=S(e,"x","sign");return A.runKernelFunc(function(n){return n.sign(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),Q_=D({isNaN_:function(e){var t=S(e,"x","isNaN");return A.runKernelFunc(function(n){return n.isNaN(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),J_=D({isInf_:function(e){var t=S(e,"x","isInf");return A.runKernelFunc(function(n){return n.isInf(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),Z_=D({isFinite_:function(e){var t=S(e,"x","isFinite");return A.runKernelFunc(function(n){return n.isFinite(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),eE=D({sin_:function(e){var t=S(e,"x","sin"),n=[t];return A.runKernelFunc(function(r,o){var i=r.sin(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return i.toFloat().cos().mul(r)}}},"Sin",{},n)}}),tE=D({sinh_:function(e){var t=S(e,"x","sinh");return A.runKernelFunc(function(n,r){var o=n.sinh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return o.toFloat().cosh().mulStrict(n)}}})}}),nE=D({softplus_:function(e){var t=S(e,"x","softplus");return A.runKernelFunc(function(n,r){var o=n.softplus(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.sigmoid())}}})}}),rE=D({sqrt_:function(e){var t=S(e,"x","sqrt");return A.runKernelFunc(function(n,r){var o=n.sqrt(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.toFloat().sqrt().mul(2))}}})}}),oE=D({step_:function(e,t){t===void 0&&(t=0);var n=S(e,"x","step");return A.runKernelFunc(function(r){return r.step(n,t)},{$x:n},function(r){return{$x:function(){return ye(r)}}})}}),iE=D({tan_:function(e){var t=S(e,"x","tan");return A.runKernelFunc(function(n,r){var o=n.tan(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.cos().square())}}})}}),aE=D({tanh_:function(e){var t=S(e,"x","tanh");return A.runKernelFunc(function(n,r){var o=n.tanh(t);return r([o]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return K(1).sub(o.square()).mulStrict(n)}}},"Tanh",{},null,[!0])}});function H0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===2,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+s.rank+"."}),I(l.rank===2||l.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+l.rank+"."}),I(c.rank===2||c.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===2||a.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===2||u.rank===1,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+u.rank+"."}),Pa(s,l,c,u,a,i)}function j0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===3,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+s.rank+"."}),I(l.rank===3||l.rank===1,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+l.rank+"."}),I(c.rank===3||c.rank===1,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===3||a.rank===1,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===3||u.rank===1,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+u.rank+"."}),Pa(s,l,c,u,a,i)}function G0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===4,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+s.rank+"."}),I(l.rank===4||l.rank===1,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+l.rank+"."}),I(c.rank===4||c.rank===1,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===4||a.rank===1,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===4||u.rank===1,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+u.rank+"."}),Pa(s,l,c,u,a,i)}function Pa(e,t,n,r,o,i){i==null&&(i=.001);var a,u,s,l=S(e,"x","batchNorm"),c=S(t,"mean","batchNorm"),f=S(n,"variance","batchNorm");o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(c.rank===f.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),I(u==null||c.rank===u.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),I(a==null||c.rank===a.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),s=l.rank===0||l.rank===1?l.as4D(1,1,1,l.size):l.rank===2?l.as4D(1,1,l.shape[0],l.shape[1]):l.rank===3?l.as4D(1,l.shape[0],l.shape[1],l.shape[2]):l;var d=[l,c,f,a];return A.runKernelFunc(function(h,p){var m=h.batchNormalization(s,cu(c),cu(f),i,cu(a),cu(u));return p([l,c,f,a]),m},{x:l,mean:c,variance:f,scale:a,offset:u},function(h,p){var m=p,g=m[0],v=m[1],y=m[2],x=m[3],w=x??K(1),b=Je(v.shape,s.shape),C=[];if(v.rank===1){for(var _=0;_0&&(u=u.sum(s)),u.reshape(r.shape)},b:function(){var u=a,s=Je(o.shape,i);return s.length>0&&(u=u.sum(s)),u.reshape(o.shape)}}},"Add")}}),mE=D({addN_:function(e){I(Array.isArray(e),function(){return"The argument passed to tf.addN() must be a list of tensors"}),I(e.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+e.length});var t=e.map(function(o,i){return S(o,"tensors"+i,"addN")}),n=t[0];t.forEach(function(o){if(o.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(function(o){if(!ot(o.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var r=t;return A.runKernelFunc(function(o){return o.addN(t)},r,function(o){var i={};return t.forEach(function(a,u){i[u]=function(){return o.clone()}}),i},"AddN")}}),gE=D({addStrict_:function(e,t){var n=S(e,"a","addStrict"),r=S(t,"b","addStrict");return Ce(n.shape,r.shape,"Error in addStrict: "),n.add(r)}}),yE=D({atan2_:function(e,t){var n,r=S(e,"a","atan2"),o=S(t,"b","atan2");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.atan2(r,o);return u([r,o]),s},{$a:r,$b:o},function(a,u){var s=u[0],l=u[1];return{$a:function(){var c=de(s.square(),l.square()),f=a.mul(l.div(c)),d=Je(s.shape,i);return d.length>0&&(f=f.sum(d)),f.reshape(s.shape)},$b:function(){var c=de(s.square(),l.square()),f=vs(a.mul(s.div(c))),d=Je(l.shape,i);return d.length>0&&(f=f.sum(d)),f.reshape(l.shape)}}})}}),pn=D({div_:function(e,t){var n,r=S(e,"a","div"),o=S(t,"b","div");if(n=Le(r,o),r=n[0],o=n[1],r.dtype==="int32"&&o.dtype==="int32")return Y0(r,o);var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.realDivide(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.div(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);f.length>0&&(c=c.sum(f).reshape(l.shape));var d=l.square();return c.div(d.toFloat()).neg()}}},"Div")}}),xE=D({divNoNan_:function(e,t){var n,r=S(e,"a","div"),o=S(t,"b","div");r=(n=Le(r,o))[0],o=n[1];var i=pn(r,o),a=ye(i),u=o.equal(a);return mo(u,a,i)}}),wE=D({divStrict_:function(e,t){var n=S(e,"a","div"),r=S(t,"b","div");return Ce(n.shape,r.shape,"Error in divideStrict: "),n.div(r)}}),Y0=D({floorDiv_:function(e,t){var n,r=S(e,"a","floorDiv"),o=S(t,"b","floorDiv");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.floorDiv(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.div(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);f.length>0&&(c=c.sum(f).reshape(l.shape));var d=l.square();return c.div(d.toFloat()).neg()}}},"FloorDiv")}}),Ad=D({maximum_:function(e,t){var n,r=S(e,"a","maximum"),o=S(t,"b","maximum");return n=Le(r,o),r=n[0],o=n[1],r.dtype==="bool"&&(r=r.toInt(),o=o.toInt()),he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.maximum(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return i.mul(u.greaterEqual(s).toFloat())},b:function(){return i.mul(u.less(s).toFloat())}}},"Maximum")}}),bE=D({maximumStrict_:function(e,t){var n=S(e,"a","maximumStrict"),r=S(t,"b","maximumStrict");return Ce(n.shape,r.shape,"Error in maximumStrict: "),n.maximum(r)}}),Q0=D({minimum_:function(e,t){var n,r=S(e,"a","minimum"),o=S(t,"b","minimum");return n=Le(r,o),r=n[0],o=n[1],r.dtype==="bool"&&(r=r.toInt(),o=o.toInt()),he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.minimum(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return i.mul(u.lessEqual(s).toFloat())},b:function(){return i.mul(u.greater(s).toFloat())}}},"Minimum")}}),CE=D({minimumStrict_:function(e,t){var n=S(e,"a","minimumStrict"),r=S(t,"b","minimumStrict");return Ce(n.shape,r.shape,"Error in minimumStrict: "),n.minimum(r)}}),_E=D({mod_:function(e,t){var n,r=S(e,"a","mod"),o=S(t,"b","mod");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.mod(r,o);return u([r,o]),s},{$a:r,$b:o},function(a,u){var s=u[0],l=u[1];return{$a:function(){var c=Je(s.shape,i);return c.length>0?a.sum(c).reshape(s.shape):a},$b:function(){var c=a.mul(s.div(l).floor().neg()),f=Je(l.shape,i);return f.length>0?c.sum(f).reshape(l.shape):c}}})}}),EE=D({modStrict_:function(e,t){var n=S(e,"a","modStrict"),r=S(t,"b","modStrict");return Ce(n.shape,r.shape,"Error in modStrict: "),n.mod(r)}}),xt=D({mul_:function(e,t){var n,r=S(e,"a","mul"),o=S(t,"b","mul");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.multiply(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.mul(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);return f.length>0?c.sum(f).reshape(l.shape):c}}},"Mul")}}),SE=D({mulStrict_:function(e,t){var n=S(e,"a","mul"),r=S(t,"b","mul");return Ce(n.shape,r.shape,"Error in multiplyStrict: "),n.mul(r)}}),ms=D({pow_:function(e,t){var n,r=S(e,"base","pow"),o=S(t,"exp","pow");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape),a=[r,o];return A.runKernelFunc(function(u,s){var l=u.pow(r,o);return s([r,o,l]),l},{a:r,b:o},function(u,s){var l=s[0],c=s[1],f=s[2];return{a:function(){var d=c.toFloat(),h=u.mul(d.mul(l.pow(d.sub(K(1))))),p=Je(l.shape,i);return p.length>0&&(h=h.sum(p)),h.reshape(l.shape)},b:function(){var d=l.greater(0),h=l.log().where(d,ye(l)),p=u.mul(f.mul(h)),m=Je(c.shape,i);return m.length>0&&(p=p.sum(m)),p.reshape(c.shape)}}},"Pow",{},a,[!0])}}),kE=D({powStrict_:function(e,t){return Ce(e.shape,t.shape,"Error in powStrict: "),e.pow(t)}}),RE=D({squaredDifferenceStrict_:function(e,t){var n=S(e,"a","squaredDifferenceStrict"),r=S(t,"b","squaredDifferenceStrict");return Ce(n.shape,r.shape,"Error in squaredDifferenceStrict: "),n.squaredDifference(r)}}),Ze=D({sub_:function(e,t){var n,r=S(e,"a","sub"),o=S(t,"b","sub");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a){return a.subtract(r,o)},{a:r,b:o},function(a){return{a:function(){var u=a,s=Je(r.shape,i);return s.length>0&&(u=u.sum(s)),u.reshape(r.shape)},b:function(){var u=a,s=Je(o.shape,i);return s.length>0&&(u=u.sum(s)),u.neg().reshape(o.shape)}}},"Sub")}}),IE=D({subStrict_:function(e,t){var n=S(e,"a","subStrict"),r=S(t,"b","subStrict");return Ce(n.shape,r.shape,"Error in subStrict: "),n.sub(r)}}),J0=D({equal_:function(e,t){var n,r=S(e,"a","equal"),o=S(t,"b","equal");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.equal(r,o)},{$a:r,$b:o})}}),DE=D({equalStrict_:function(e,t){var n=S(e,"a","equalStrict"),r=S(t,"b","equalStrict");return Ce(n.shape,r.shape,"Error in equalStrict: "),n.equal(r)}}),TE=D({greater_:function(e,t){var n,r=S(e,"a","greater"),o=S(t,"b","greater");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.greater(r,o)},{a:r,b:o},null,"Greater")}}),Z0=D({greaterEqual_:function(e,t){var n,r=S(e,"a","greaterEqual"),o=S(t,"b","greaterEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.greaterEqual(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return ye(u)},b:function(){return ye(s)}}},"GreaterEqual")}}),NE=D({greaterEqualStrict_:function(e,t){var n=S(e,"a","greaterEqualStrict"),r=S(t,"b","greaterEqualStrict");return Ce(n.shape,r.shape,"Error in greaterEqualStrict: "),n.greaterEqual(r)}}),AE=D({greaterStrict_:function(e,t){var n=S(e,"a","greaterStrict"),r=S(t,"b","greaterStrict");return Ce(n.shape,r.shape,"Error in greaterStrict: "),n.greater(r)}}),PE=D({less_:function(e,t){var n,r=S(e,"a","less"),o=S(t,"b","less");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.less(r,o)},{a:r,b:o},null,"Less")}}),FE=D({lessEqual_:function(e,t){var n,r=S(e,"a","lessEqual"),o=S(t,"b","lessEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.lessEqual(r,o);return a([r,o]),u},{a:r,b:o},null,"LessEqual")}}),ME=D({lessEqualStrict_:function(e,t){var n=S(e,"a","lessEqualStrict"),r=S(t,"b","lessEqualStrict");return Ce(n.shape,r.shape,"Error in lessEqualStrict: "),n.lessEqual(r)}}),OE=D({lessStrict_:function(e,t){var n=S(e,"a","lessStrict"),r=S(t,"b","lessStrict");return Ce(n.shape,r.shape,"Error in lessStrict: "),n.less(r)}}),BE=D({notEqual_:function(e,t){var n,r=S(e,"a","notEqual"),o=S(t,"b","notEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.notEqual(r,o)},{a:r,b:o},null,"NotEqual")}}),LE=D({notEqualStrict_:function(e,t){var n=S(e,"a","notEqualStrict"),r=S(t,"b","notEqualStrict");return Ce(n.shape,r.shape,"Error in notEqualStrict: "),n.notEqual(r)}});function lv(e,t){for(var n=[],r=e;r0,function(){return"mask cannot be scalar"}),Ce(u.slice(i,i+a),o.shape,"mask's shape must match the first K dimensions of tensor's shape,"),s=1,l=i;l=2&&a.rank>=2&&i.rank===a.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+i.rank+" and "+a.rank+"."}),I(ot(f,d),function(){return"Error in matMul: outer dimensions ("+f+") and ("+d+") of Tensors with shapes "+i.shape+" and "+a.shape+" must match."}),I(u===s,function(){return"Error in matMul: inner shapes ("+u+") and ("+s+") of Tensors with shapes "+i.shape+" and "+a.shape+" and transposeA="+n+" and transposeB="+r+" must match."});var m=i.shape.slice(0,-2).concat([l,c]),g=n?i.as3D(h,u,l):i.as3D(h,l,u),v=r?a.as3D(p,c,s):a.as3D(p,s,c),y={transposeA:n,transposeB:r};return A.runKernelFunc(function(x,w){var b=x.batchMatMul(g,v,n,r);return w([g,v]),b},{a:g,b:v},function(x,w){var b=w,C=b[0],_=b[1];return n||r?!n&&r?{a:function(){return x.matMul(_,!1,!1)},b:function(){return x.matMul(C,!0,!1)}}:n&&!r?{a:function(){return _.matMul(x,!1,!0)},b:function(){return C.matMul(x,!1,!1)}}:{a:function(){return _.matMul(x,!0,!0)},b:function(){return x.matMul(C,!0,!0)}}:{a:function(){return x.matMul(_,!1,!0)},b:function(){return C.matMul(x,!0,!1)}}},"BatchMatMul",y).reshape(m)}}),HE=D({dot_:function(e,t){var n=S(e,"t1","dot"),r=S(t,"t2","dot");I(!(n.rank!==1&&n.rank!==2||r.rank!==1&&r.rank!==2),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+n.rank+" and "+r.rank+"."});var o=n.rank===1?n.size:n.shape[1],i=r.rank===1?r.size:r.shape[0];return I(o===i,function(){return"Error in dot: inner dimensions of inputs must match, but got "+o+" and "+i+"."}),n.rank===1&&r.rank===1?n.as2D(1,-1).matMul(r.as2D(-1,1)).asScalar():n.rank===1&&r.rank===2?n.as2D(1,-1).matMul(r.as2D(r.shape[0],r.shape[1])).as1D():n.rank===2&&r.rank===1?n.matMul(r.as2D(-1,1)).as1D():n.matMul(r.as2D(r.shape[0],r.shape[1]))}}),jE=D({outerProduct_:function(e,t){var n=S(e,"v1","outerProduct"),r=S(t,"v2","outerProduct");return I(n.rank===1&&r.rank===1,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+n.rank+" and "+r.rank+"."}),n.as2D(-1,1).matMul(r.as2D(1,-1))}}),Fa=D({reverse_:function(e,t){var n=S(e,"x","reverse");if(n.rank===0)return n.clone();var r=et(t,n.shape);return A.runKernelFunc(function(o){return o.reverse(n,r)},{$x:n},function(o){return{$x:function(){return o.reverse(r)}}}).reshapeAs(n)}}),GE=D({reverse1d_:function(e){var t=S(e,"x","reverse");return I(t.rank===1,function(){return"Error in reverse1D: x must be rank 1 but got rank "+t.rank+"."}),Fa(t,0)}}),qE=D({reverse2d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===2,function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."}),Fa(n,t)}}),KE=D({reverse3d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===3,function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."}),Fa(n,t)}}),XE=D({reverse4d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===4,function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."}),Fa(n,t)}});function ay(e,t,n,r,o,i){var a=S(e,"x","maxPool"),u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),r==null&&(r=[1,1]),I(u.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+u.rank+"."}),I(Ot(n,r),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"}),i!=null&&I(Ve(o),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+o+"."});var l=ya(u.shape,t,n,r,o,i);if(l.filterWidth===1&&l.filterHeight===1&&ot(l.inShape,l.outShape))return a.clone();var c=[u],f=A.runKernelFunc(function(d,h){var p=d.maxPool(u,l);return h([u,p]),p},{x:u},function(d,h){var p=h[0],m=h[1];return{x:function(){return function(g,v,y,x,w,b,C,_){var E=S(g,"dy","maxPoolBackprop"),R=S(v,"input","maxPoolBackprop"),k=S(y,"output","maxPoolBackprop");I(R.rank===E.rank,function(){return"Rank of input ("+R.rank+") does not match rank of dy ("+E.rank+")"}),b==null&&(b=[1,1]),I(Ot(w,b),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+w+" and dilations '"+b+"'"}),I(E.rank===4,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+E.rank+"."}),I(R.rank===4,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+R.rank+"."}),_!=null&&I(Ve(C),function(){return"Error in maxPoolBackprop: pad must be an integer when using, dimRoundingMode "+_+" but got pad "+C+"."});var T=ya(R.shape,x,w,b,C,_);return A.runKernelFunc(function(N){return N.maxPoolBackprop(E,R,k,T)},{$dy:E,$input:R})}(d,p,m,t,n,r,o)}}},"MaxPool",l,c);return s?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f}function uy(e,t,n,r,o,i){var a=S(e,"x","avgPool","float32");r==null&&(r=[1,1]),I(Ot(n,r),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"});var u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),I(u.rank===4,function(){return"Error in avgPool: x must be rank 4 but got rank "+u.rank+"."}),i!=null&&I(Ve(o),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+o+"."});var l=ya(u.shape,t,n,r,o,i);if(l.filterWidth===1&&l.filterHeight===1&&ot(l.inShape,l.outShape))return a.clone();var c=A.runKernelFunc(function(f){return f.avgPool(u,l)},{x:u},function(f){return{x:function(){return function(d,h,p,m,g,v){var y=S(d,"dy","avgPoolBackprop"),x=S(h,"input","avgPoolBackprop");I(x.rank===y.rank,function(){return"Rank of input ("+x.rank+") does not match rank of dy ("+y.rank+")"}),g==null&&(g=[1,1]),I(Ot(m,g),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+m+" and dilations '"+g+"'"});var w=x,b=y,C=!1;x.rank===3&&(C=!0,w=x.as4D(1,x.shape[0],x.shape[1],x.shape[2]),b=y.as4D(1,y.shape[0],y.shape[1],y.shape[2])),I(b.rank===4,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+b.rank+"."}),I(w.rank===4,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+w.rank+"."});var _=ya(w.shape,p,m,g,v),E=A.runKernelFunc(function(R){return R.avgPoolBackprop(b,w,_)},{dy4D:b,input4D:w});return C?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}(f,u,t,n,r,o)}}},"AvgPool",l);return c=c.cast(a.dtype),s?c.as3D(c.shape[1],c.shape[2],c.shape[3]):c}var tt=D({maxPool_:function(e,t,n,r,o){return ay(e,t,n,1,r,o)}}),Ma=D({avgPool_:function(e,t,n,r,o){return uy(e,t,n,1,r,o)}}),YE=D({pool_:function(e,t,n,r,o,i){o==null&&(o=[1,1]),i==null&&(i=1),r===0&&(r="valid");var a=S(e,"x","maxPool"),u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),I(Ot(i,o),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+o+"'"});var l,c=ya(u.shape,t,i,o,r),f=[c.dilationHeight,c.dilationWidth];l=r==="same"?function(w,b){var C=w.map(function(R,k){return R+(R-1)*(b[k]-1)}).map(function(R){return R-1}),_=C.map(function(R){return Math.floor(R/2)}),E=C.map(function(R,k){return R-_[k]});return C.map(function(R,k){return[_[k],E[k]]})}([c.filterHeight,c.filterWidth],f):[[0,0],[0,0]];var d=f[0]===1&&f[1]===1,h=function(w,b,C){var _=C.map(function(L){return L[0]}),E=C.map(function(L){return L[1]}),R=w.concat(_,E),k=b.map(function(L,U){return(L-R[U]%L)%L}),T=E.map(function(L,U){return L+k[U]}),N=b.map(function(L,U){return[_[U],T[U]]}),W=b.map(function(L,U){return[0,k[U]]});return[N,W]}([c.inHeight,c.inWidth],f,l),p=h[0],m=h[1],g=d?r:"valid",v=d?u:h0(u,f,p),y=(n==="avg"?function(){return uy(v,t,i,1,g)}:function(){return ay(v,t,i,1,g)})(),x=d?y:c0(y,f,m);return s?x.as3D(x.shape[1],x.shape[2],x.shape[3]):x}}),QE=D({maxPool3d_:function(e,t,n,r,o,i,a){i===void 0&&(i="NDHWC");var u=S(e,"x","maxPool3d"),s=u,l=!1;u.rank===4&&(l=!0,s=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),a==null&&(a=[1,1,1]),I(s.rank===5,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+s.rank+"."}),I(i==="NDHWC",function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+i}),I(Ot(n,a),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),o!=null&&I(Ve(r),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var c=ds(s.shape,t,n,a,r,o,i),f=A.runKernelFunc(function(d,h){var p=d.maxPool3d(s,c);return h([s,p]),p},{x:s},function(d,h){var p=h[0],m=h[1];return{x:function(){return function(g,v,y,x,w,b,C,_){var E=S(g,"dy","maxPool3dBackprop"),R=S(v,"input","maxPool3dBackprop"),k=S(y,"output","maxPool3dBackprop"),T=E,N=R,W=k,L=!1;R.rank===4&&(L=!0,T=E.as5D(1,E.shape[0],E.shape[1],E.shape[2],E.shape[3]),N=R.as5D(1,R.shape[0],R.shape[1],R.shape[2],R.shape[3]),W=k.as5D(1,k.shape[0],k.shape[1],k.shape[2],k.shape[3])),I(T.rank===5,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+T.rank+"."}),I(N.rank===5,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+N.rank+"."}),I(W.rank===5,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+W.rank+"."}),b==null&&(b=[1,1,1]),I(Ot(w,b),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+w+" and dilations '"+b+"'"}),_!=null&&I(Ve(C),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+_+" but got pad "+C+"."});var U=ds(N.shape,x,w,b,C,_),$=A.runKernelFunc(function(V){return V.maxPool3dBackprop(T,N,W,U)},{dy5D:T,input5D:N});return L?$.as4D($.shape[1],$.shape[2],$.shape[3],$.shape[4]):$}(d,p,m,t,n,a,r,o)}}});return l?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),JE=D({avgPool3d_:function(e,t,n,r,o,i,a){i===void 0&&(i="NDHWC");var u=S(e,"x","avgPool3d","float32"),s=u,l=!1;u.rank===4&&(l=!0,s=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),a==null&&(a=[1,1,1]),I(s.rank===5,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+s.rank+"."}),I(i==="NDHWC",function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+i}),I(Ot(n,a),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),o!=null&&I(Ve(r),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var c=ds(s.shape,t,n,a,r,o,i),f=A.runKernelFunc(function(d){return d.avgPool3d(s,c)},{x:s},function(d){return{x:function(){return function(h,p,m,g,v,y,x){var w=S(h,"dy","avgPool3dBackprop"),b=S(p,"input","avgPool3dBackprop"),C=w,_=b,E=!1;b.rank===4&&(E=!0,C=w.as5D(1,w.shape[0],w.shape[1],w.shape[2],w.shape[3]),_=b.as5D(1,b.shape[0],b.shape[1],b.shape[2],b.shape[3])),I(C.rank===5,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+C.rank+"."}),I(_.rank===5,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+_.rank+"."}),v==null&&(v=[1,1,1]),I(Ot(g,v),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+g+" and dilations '"+v+"'"}),x!=null&&I(Ve(y),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+x+" but got pad "+y+"."});var R=ds(_.shape,m,g,v,y,x),k=A.runKernelFunc(function(T){return T.avgPool3dBackprop(C,_,R)},{dy5D:C,input5D:_});return E?k.as4D(k.shape[1],k.shape[2],k.shape[3],k.shape[4]):k}(d,s,t,n,a,r,o)}}});return f=f.cast(s.dtype),l?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),Wn=D({slice_:function(e,t,n){var r,o,i=S(e,"x","slice");if(i.rank===0)throw new Error("Slicing scalar is not possible");(r=typeof t=="number"?[t].concat(new Array(i.rank-1).fill(0)):t.length=0?s:(I(s===-1,function(){return"Negative size values should be exactly -1 but got "+s+" for the slice() size at index "+l+"."}),i.shape[l]-r[l])}),kb(i,r,o);var a=i.shape,u={begin:r,size:o};return A.runKernelFunc(function(s){return s.slice(i,r,o)},{x:i},function(s){for(var l=[],c=0;c0&&(l=l.sum(c)),l.reshape(u.shape)}}},"Prelu")}}),Me=D({relu_:function(e){var t=S(e,"x","relu");return t.dtype==="bool"?t.toInt():A.runKernelFunc(function(n,r){var o=n.relu(t);return r([t]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mulStrict(o.step().toFloat())}}},"Relu")}}),hy=D({relu6_:function(e){var t=S(e,"x","relu6");return t.dtype==="bool"?t.toInt():A.runKernelFunc(function(n,r){var o=n.relu6(t);return r([t]),o},{x:t},function(n,r){var o=r[0],i=o.lessEqual(6).mul(o.step());return{x:function(){return n.mulStrict(i.toFloat())}}},"Relu6")}}),dS=D({selu_:function(e){var t=S(e,"x","selu");return A.runKernelFunc(function(n,r){var o=n.selu(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){var i=o.greater(K(0)),a=K(Dd),u=K(Td),s=n.mul(u),l=n.mul(a).mul(o.toFloat().exp());return mo(i,s,l)}}})}}),zr=D({transpose_:function(e,t){var n=S(e,"x","transpose");if(t==null&&(t=n.shape.map(function(o,i){return i}).reverse()),I(n.rank===t.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+t+"."}),t.forEach(function(o){I(o>=0&&oo)throw new Error("'k' passed to topk() must be <= the last dimension ("+o+") but got "+t);var i=A.runKernelFunc(function(a){return a.topk(r,t,n)},{$x:r});return{values:i[0],indices:i[1]}}}),xS=D({scatterND_:function(e,t,n){var r=S(e,"indices","scatterND","int32"),o=S(t,"updates","scatterND");return Sb(o,r,n),A.runKernelFunc(function(i){return i.scatterND(r,o,n)},{indices:r,updates:o},null,"ScatterNd",{shape:n})}}),Od=D({fft_:function(e){I(e.dtype==="complex64",function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+e.dtype+"."});var t=e.shape[e.shape.length-1],n=e.size/t,r=e.as2D(n,t);return A.runKernelFunc(function(o){return o.fft(r)},{input:e}).reshape(e.shape)}}),gs=D({ifft_:function(e){I(e.dtype==="complex64",function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+e.dtype+"."});var t=e.shape[e.shape.length-1],n=e.size/t,r=e.as2D(n,t);return A.runKernelFunc(function(o){return o.ifft(r)},{input:e}).reshape(e.shape)}}),Bd=D({rfft_:function(e,t){I(e.dtype==="float32",function(){return"The dtype for rfft() must be real value but got "+e.dtype});var n,r=e.shape[e.shape.length-1],o=e.size/r;if(t!=null&&tr){var u=e.shape.map(function(v){return v});u[e.shape.length-1]=t-r,n=e.concat(Ie(u),e.shape.length-1),r=t}else n=e;var s=n.zerosLike(),l=ut(n,s).as2D(o,r),c=Od(l),f=Math.floor(r/2)+1,d=en(c),h=An(c),p=d.split([f,r-f],d.shape.length-1),m=h.split([f,r-f],h.shape.length-1),g=n.shape.slice();return g[n.shape.length-1]=f,ut(p[0],m[0]).reshape(g)}}),vy=D({irfft_:function(e){var t=e.shape[e.shape.length-1],n=e.size/t;if(t<=2){var r=e.as2D(n,t),o=gs(r);return en(o)}var i=[n,2*(t-1)],a=en(e).as2D(n,t),u=An(e).as2D(n,t),s=a.slice([0,1],[n,t-2]).reverse(1),l=u.slice([0,1],[n,t-2]).reverse(1).mul(K(-1)),c=a.concat(s,1),f=u.concat(l,1);return r=ut(c,f).as2D(i[0],i[1]),o=gs(r),en(o)}}),wS=Object.freeze({fft:Od,ifft:gs,rfft:Bd,irfft:vy}),bS=D({sparseToDense_:function(e,t,n,r){r===void 0&&(r=0);var o=S(e,"sparseIndices","sparseToDense","int32"),i=S(t,"sparseValues","sparseToDense"),a=S(r,"defaultValue","sparseToDense",i.dtype);return function(u,s,l,c){if(u.dtype!=="int32")throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+u.dtype+".");if(u.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+u.shape+".");var f=u.rank>0?u.shape[0]:1,d=u.rank>1?u.shape[1]:1;if(l.length!==d)throw new Error("outputShape has incorrect number of elements:, "+l.length+", should be: "+d+".");var h=s.size;if(s.rank!==0&&(s.rank!==1||h!==f))throw new Error("sparseValues has incorrect shape "+s.shape+", should be [] or ["+f+"]");if(s.dtype!==c.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(o,i,n,a),A.runKernelFunc(function(u){return u.sparseToDense(o,i,n,a)},{$sparseIndices:o,$sparseValues:i,$defaultValue:a})}}),CS=D({gatherND_:function(e,t){var n=S(t,"indices","gatherND","int32"),r=S(e,"x","gatherND");return A.runKernelFunc(function(o){return o.gatherND(r,n)},{x:r,indices:n},null,"GatherNd")}}),_S=D({diag_:function(e){var t=S(e,"x","diag").flatten(),n=e.shape.concat(e.shape);return A.runKernelFunc(function(r){return r.diag(t)},{$x:t}).reshape(n)}}),ES=D({dropout_:function(e,t,n,r){var o=S(e,"x","dropout");if(I(o.dtype==="float32",function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+o.dtype+" tensor instead."}),I(t>=0&&t<1,function(){return"rate must be a float in the range [0, 1), but got "+t+"."}),t===0)return e instanceof Fe?o.clone():o;var i=function(s,l){if(l==null)return s.shape.slice();if(ot(s.shape,l))return l;if(s.shape.length===l.length){for(var c=[],f=0;f1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank}),I(r.rank-1===o.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+o.rank}),Ce(r.shape.slice(0,r.shape.length-1),o.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),i=r.shape[r.shape.length-1],I(n>0&&n<=i,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+i+"), but got "+n}),[4,r.data()];case 1:return a=v.sent(),[4,o.data()];case 2:for(u=v.sent(),s=[a.length/i,i],c=s[1],f=va("bool",l=s[0]),d=0;d1?u.div(K(a)):u}if(n===yt.SUM_BY_NONZERO_WEIGHTS){if(o==null)return i.sum().div(K(r.size));var s=o.mul(_i(r.shape)).notEqual(K(0)).sum().toFloat();return i.sum().div(s)}throw Error("Unknown reduction: "+n)}}),IS=D({cosineDistance_:function(e,t,n,r,o){o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","cosineDistance"),a=S(t,"predictions","cosineDistance"),u=null;r!=null&&(u=S(r,"weights","cosineDistance")),Ce(i.shape,a.shape,"Error in cosineDistance: ");var s=K(1).sub(i.mul(a).sum(n,!0));return cr(s,u,o)}}),DS=D({hingeLoss_:function(e,t,n,r){r===void 0&&(r=yt.SUM_BY_NONZERO_WEIGHTS);var o=S(e,"labels","hingeLoss"),i=S(t,"predictions","hingeLoss"),a=null;n!=null&&(a=S(n,"weights","hingeLoss")),Ce(o.shape,i.shape,"Error in hingeLoss: ");var u=K(1);o=K(2).mul(o).sub(u);var s=u.sub(o.mul(i)).relu();return cr(s,a,r)}}),TS=D({huberLoss_:function(e,t,n,r,o){r===void 0&&(r=1),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","huberLoss"),a=S(t,"predictions","huberLoss"),u=null;n!=null&&(u=S(n,"weights","huberLoss")),Ce(i.shape,a.shape,"Error in huberLoss: ");var s=K(r),l=a.sub(i).abs(),c=Q0(l,s),f=l.sub(c),d=K(.5).mul(c.square()).add(s.mul(f));return cr(d,u,o)}}),NS=D({logLoss_:function(e,t,n,r,o){r===void 0&&(r=1e-7),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","logLoss"),a=S(t,"predictions","logLoss"),u=null;n!=null&&(u=S(n,"weights","logLoss")),Ce(i.shape,a.shape,"Error in logLoss: ");var s=K(1),l=K(r),c=i.mul(a.add(l).log()).neg().sub(s.sub(i).mul(s.sub(a).add(l).log()));return cr(c,u,o)}}),AS=D({meanSquaredError_:function(e,t,n,r){r===void 0&&(r=yt.SUM_BY_NONZERO_WEIGHTS);var o=S(e,"labels","meanSquaredError"),i=S(t,"predictions","meanSquaredError"),a=null;n!=null&&(a=S(n,"weights","meanSquaredError")),Ce(o.shape,i.shape,"Error in meanSquaredError: ");var u=o.squaredDifference(i);return cr(u,a,r)}}),PS=D({sigmoidCrossEntropy_:function(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"multiClassLabels","sigmoidCrossEntropy"),a=S(t,"logits","sigmoidCrossEntropy"),u=null;if(n!=null&&(u=S(n,"weights","sigmoidCrossEntropy")),Ce(i.shape,a.shape,"Error in sigmoidCrossEntropy: "),r>0){var s=K(r),l=K(1),c=K(.5);i=i.mul(l.sub(s)).add(c.mul(s))}var f=function(d,h){var p=S(d,"labels","sigmoidCrossEntropyWithLogits"),m=S(h,"logits","sigmoidCrossEntropyWithLogits");Ce(p.shape,m.shape,"Error in sigmoidCrossEntropyWithLogits: ");var g=m.relu(),v=m.mul(p),y=m.abs().neg().exp().log1p();return g.sub(v).add(y)}(i,a);return cr(f,u,o)}}),FS=D({softmaxCrossEntropy_:function(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"onehotLabels","softmaxCrossEntropy"),a=S(t,"logits","softmaxCrossEntropy"),u=null;if(n!=null&&(u=S(n,"weights","softmaxCrossEntropy")),Ce(i.shape,a.shape,"Error in softmaxCrossEntropy: "),r>0){var s=K(r),l=K(1),c=K(i.shape[1]);i=i.mul(l.sub(s)).add(s.div(c))}var f=function(d,h,p){if(p===void 0&&(p=-1),p===-1&&(p=h.rank-1),p!==h.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+h.rank+" and dim was "+p);return zs(function(m,g,v){var y=g.logSumExp([p],!0),x=g.toFloat().sub(y);return v([m,x]),{value:x.mul(m).neg().sum([p]),gradFunc:function(w,b){var C=b[0],_=b[1],E=Mt(w.shape,[p]);return[w.reshape(E).mul(C.toFloat().sub(_.exp())),w.reshape(E).mul(_.exp().sub(C.toFloat()))]}}})(d,h)}(i,a);return cr(f,u,o)}}),MS=Object.freeze({get Reduction(){return yt},absoluteDifference:RS,computeWeightedLoss:cr,cosineDistance:IS,hingeLoss:DS,huberLoss:TS,logLoss:NS,meanSquaredError:AS,sigmoidCrossEntropy:PS,softmaxCrossEntropy:FS});function fv(e,t){return t===void 0&&(t=!1),A.tidy(function(){if(e.shape.length!==2)throw new Error("qr2d() requires a 2D Tensor, but got a "+e.shape.length+"D Tensor.");for(var n=e.shape[0],r=e.shape[1],o=f0(n),i=e.clone(),a=Mr([[1]],[1,1]),u=a.clone(),s=n>=r?r:n,l=function(f){var d,h=i,p=u,m=o;d=A.tidy(function(){var g=i.slice([f,f],[n-f,1]),v=g.norm(),y=i.slice([f,f],[1,1]),x=Mr([[-1]]).where(y.greater(0),Mr([[1]])),w=y.sub(x.mul(v)),b=g.div(w);u=b.shape[0]===1?a.clone():a.concat(b.slice([1,0],[b.shape[0]-1,b.shape[1]]),0);var C=x.matMul(w).div(v).neg(),_=i.slice([f,0],[n-f,r]),E=C.mul(u);if(f===0)i=_.sub(E.matMul(u.transpose().matMul(_)));else{var R=_.sub(E.matMul(u.transpose().matMul(_)));i=i.slice([0,0],[f,r]).concat(R,0)}var k=o.slice([0,f],[n,o.shape[1]-f]);if(f===0)o=k.sub(k.matMul(u).matMul(E.transpose()));else{var T=k.sub(k.matMul(u).matMul(E.transpose()));o=o.slice([0,0],[n,f]).concat(T,1)}return[u,i,o]}),u=d[0],i=d[1],o=d[2],Ft([h,p,m])},c=0;cr&&(o=o.slice([0,0],[n,r]),i=i.slice([0,0],[r,r])),[o,i]})}var OS=D({bandPart_:function(e,t,n){if(t%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+t+".");if(n%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+n+".");var r=S(e,"a","bandPart");if(r.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+r.rank+".");var o=r.shape,i=r.shape.slice(-2),a=i[0],u=i[1];if(!(t<=a))throw new Error("bandPart(): numLower ("+t+") must not be greater than the number of rows ("+a+").");if(!(n<=u))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+u+").");t<0&&(t=a),n<0&&(n=u);var s=us(0,a,1,"int32").reshape([-1,1]),l=us(0,u,1,"int32"),c=Ze(s,l),f=Vs(c.lessEqual(K(+t,"int32")),c.greaterEqual(K(-n,"int32"))),d=Ie([a,u],r.dtype);return Gt(Qe(r.reshape([-1,a,u])).map(function(h){return mo(f,h,d)})).reshape(o)}}),BS=D({gramSchmidt_:function(e){var t;if(Array.isArray(e)){t=!1,I(e!=null&&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(s){I(e[s].shape[0]===n,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+e[s].shape[0]+" vs. "+n+")"})},o=1;o0)for(var c=0;c= 2, but got rank "+e.rank);if(e.rank===2)return fv(e,t);var n=e.shape.slice(0,e.shape.length-2).reduce(function(a,u){return a*u}),r=Qe(e.reshape([n,e.shape[e.shape.length-2],e.shape[e.shape.length-1]]),0),o=[],i=[];return r.forEach(function(a){var u=fv(a,t),s=u[0],l=u[1];o.push(s),i.push(l)}),[Gt(o,0).reshape(e.shape),Gt(i,0).reshape(e.shape)]}}),WS=Object.freeze({bandPart:OS,gramSchmidt:BS,qr:LS});function Gs(e,t,n,r,o,i){r==null&&(r=.5),o==null&&(o=Number.NEGATIVE_INFINITY),i==null&&(i=0);var a=e.shape[0];return n=Math.min(n,a),I(0<=r&&r<=1,function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"}),I(e.rank===2,function(){return"boxes must be a 2D tensor, but was of rank '"+e.rank+"'"}),I(e.shape[1]===4,function(){return"boxes must have 4 columns, but 2nd dimension was "+e.shape[1]}),I(t.rank===1,function(){return"scores must be a 1D tensor"}),I(t.shape[0]===a,function(){return"scores has incompatible shape with boxes. Expected "+a+", but was "+t.shape[0]}),I(0<=i&&i<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+i+"'"}),{maxOutputSize:n,iouThreshold:r,scoreThreshold:o,softNmsSigma:i}}var zS=D({resizeBilinear_:function(e,t,n){n===void 0&&(n=!1);var r=S(e,"images","resizeBilinear");I(r.rank===3||r.rank===4,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+r.rank+"."}),I(t.length===2,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+t+"."});var o=r,i=!1;r.rank===3&&(i=!0,o=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var a=t[0],u=t[1],s=A.runKernelFunc(function(l,c){return c([o]),l.resizeBilinear(o,a,u,n)},{x:o},function(l,c){return{x:function(){return A.runKernelFunc(function(f){return f.resizeBilinearBackprop(l,c[0],n)},{})}}},"ResizeBilinear",{alignCorners:n,newHeight:a,newWidth:u});return i?s.as3D(s.shape[1],s.shape[2],s.shape[3]):s}}),US=D({resizeNearestNeighbor_:function(e,t,n){n===void 0&&(n=!1);var r=S(e,"images","resizeNearestNeighbor");I(r.rank===3||r.rank===4,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+r.rank+"."}),I(t.length===2,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+t+"."}),I(r.dtype==="float32"||r.dtype==="int32",function(){return"`images` must have `int32` or `float32` as dtype"});var o=r,i=!1;r.rank===3&&(i=!0,o=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var a=t[0],u=t[1],s=A.runKernelFunc(function(l,c){return c([o]),l.resizeNearestNeighbor(o,a,u,n)},{batchImages:o},function(l,c){return{batchImages:function(){return A.runKernelFunc(function(f){return f.resizeNearestNeighborBackprop(l,c[0],n)},{})}}});return i?s.as3D(s.shape[1],s.shape[2],s.shape[3]):s}}),VS=D({nonMaxSuppression_:function(e,t,n,r,o){r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY);var i=S(e,"boxes","nonMaxSuppression"),a=S(t,"scores","nonMaxSuppression"),u=Gs(i,a,n,r,o);n=u.maxOutputSize,r=u.iouThreshold,o=u.scoreThreshold;var s={maxOutputSize:n,iouThreshold:r,scoreThreshold:o};return A.runKernelFunc(function(l){return l.nonMaxSuppression(i,a,n,r,o)},{boxes:i,scores:a},null,"NonMaxSuppressionV3",s)}}),$S=function(e,t,n,r,o){return r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),Q(this,void 0,void 0,function(){var i,a,u,s,l,c,f;return J(this,function(d){switch(d.label){case 0:return i=S(e,"boxes","nonMaxSuppressionAsync"),a=S(t,"scores","nonMaxSuppressionAsync"),u=Gs(i,a,n,r,o),n=u.maxOutputSize,r=u.iouThreshold,o=u.scoreThreshold,[4,Promise.all([i.data(),a.data()])];case 1:return s=d.sent(),l=s[0],c=s[1],f=Sd(l,c,n,r,o),i!==e&&i.dispose(),a!==t&&a.dispose(),[2,f]}})})},HS=D({nonMaxSuppressionWithScore_:function(e,t,n,r,o,i){r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),i===void 0&&(i=0);var a=S(e,"boxes","nonMaxSuppression"),u=S(t,"scores","nonMaxSuppression"),s=Gs(a,u,n,r,o,i),l={maxOutputSize:n=s.maxOutputSize,iouThreshold:r=s.iouThreshold,scoreThreshold:o=s.scoreThreshold,softNmsSigma:i=s.softNmsSigma},c=A.runKernel("NonMaxSuppressionV5",{boxes:a,scores:u},l);return{selectedIndices:c[0],selectedScores:c[1]}}}),jS=function(e,t,n,r,o,i){return r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),i===void 0&&(i=0),Q(this,void 0,void 0,function(){var a,u,s,l,c,f,d;return J(this,function(h){switch(h.label){case 0:return a=S(e,"boxes","nonMaxSuppressionAsync"),u=S(t,"scores","nonMaxSuppressionAsync"),s=Gs(a,u,n,r,o,i),n=s.maxOutputSize,r=s.iouThreshold,o=s.scoreThreshold,i=s.softNmsSigma,[4,Promise.all([a.data(),u.data()])];case 1:return l=h.sent(),c=l[0],f=l[1],d=kd(c,f,n,r,o,i),a!==e&&a.dispose(),u!==t&&u.dispose(),[2,d]}})})},GS=D({cropAndResize_:function(e,t,n,r,o,i){var a=S(e,"image","cropAndResize"),u=S(t,"boxes","cropAndResize","float32"),s=S(n,"boxInd","cropAndResize","int32");o=o||"bilinear",i=i||0;var l=u.shape[0];return I(a.rank===4,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+a.rank+"."}),I(u.rank===2&&u.shape[1]===4,function(){return"Error in cropAndResize: boxes must be have size ["+l+",4] but had shape "+u.shape+"."}),I(s.rank===1&&s.shape[0]===l,function(){return"Error in cropAndResize: boxInd must be have size ["+l+"] but had shape "+u.shape+"."}),I(r.length===2,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."}),I(r[0]>=1&&r[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+r}),I(o==="bilinear"||o==="nearest",function(){return"method must be bilinear or nearest, but was "+o}),A.runKernelFunc(function(c,f){return c.cropAndResize(a,u,s,r,o,i)},{images:a,boxes:u,boxInd:s},null,"CropAndResize",{method:o,extrapolationValue:i,cropSize:r})}}),zd=Object.freeze({resizeBilinear:zS,resizeNearestNeighbor:US,nonMaxSuppression:VS,nonMaxSuppressionAsync:$S,nonMaxSuppressionWithScore:HS,nonMaxSuppressionWithScoreAsync:jS,cropAndResize:GS}),Ud=function(e,t){return!(e>0)||t==="linear"},Vd=function(e,t,n){if(n==null||n==="linear")return e;if(n==="relu")return e.mul(t.step());throw new Error("Gradient for activation "+n+" has not been implemented yet.")},$d=function(e,t){var n=t,r=Je(e.shape,t.shape);return r.length>0&&(n=n.sum(r)),n.reshape(e.shape)},Hd=function(e,t,n){if(t==="linear")return e;if(t==="relu")return Me(e);if(t==="elu")return fy(e);if(t==="relu6")return hy(e);if(t==="prelu")return dy(e,n);throw new Error("Unknown fused activation "+t+".")},qS=D({fusedMatMul_:function(e){var t,n=e.a,r=e.b,o=e.transposeA,i=o!==void 0&&o,a=e.transposeB,u=a!==void 0&&a,s=e.bias,l=e.activation,c=l===void 0?"linear":l,f=e.preluActivationWeights;if(Ud(A.state.gradientDepth,c)===!1){var d=Hs(n,r,i,u);return s!=null&&(d=de(d,s)),Hd(d,c,f)}var h=S(n,"a","fused matMul"),p=S(r,"b","fused matMul");t=Le(h,p),h=t[0],p=t[1];var m=i?h.shape[h.rank-2]:h.shape[h.rank-1],g=u?p.shape[p.rank-1]:p.shape[p.rank-2],v=i?h.shape[h.rank-1]:h.shape[h.rank-2],y=u?p.shape[p.rank-2]:p.shape[p.rank-1],x=h.shape.slice(0,-2),w=p.shape.slice(0,-2),b=Z(x),C=Z(w);I(h.rank>=2&&p.rank>=2&&h.rank===p.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+h.rank+" and "+p.rank+"."}),I(ot(x,w),function(){return"Error in fused matMul: outer dimensions ("+x+") and ("+w+") of Tensors with shapes "+h.shape+" and "+p.shape+" must match."}),I(m===g,function(){return"Error in fused matMul: inner shapes ("+m+") and ("+g+") of Tensors with shapes "+h.shape+" and "+p.shape+" and transposeA="+i+" and transposeB="+u+" must match."});var _,E,R=h.shape.slice(0,-2).concat([v,y]),k=i?h.as3D(b,m,v):h.as3D(b,v,m),T=u?p.as3D(C,y,g):p.as3D(C,g,y);s!=null&&he(R,(_=Le(_=S(s,"bias","fused matMul"),h)[0]).shape),f!=null&&(E=S(f,"prelu weights","fused matMul"));var N={a:k,b:T};s!=null&&(N.bias=_),f!=null&&(N.preluActivationWeights=E);var W=[k,T];return A.runKernelFunc(function(L,U){var $=L.fusedBatchMatMul({a:k,b:T,transposeA:i,transposeB:u,bias:_,activation:c,preluActivationWeights:E});return U([k,T,$]),$},N,function(L,U){var $=U[0],V=U[1],P=U[2],M=Vd(L,P,c),B={};return s!=null&&(B={bias:function(){return $d(_,M)}}),Object.assign(i||u?!i&&u?{a:function(){return M.matMul(V,!1,!1)},b:function(){return M.matMul($,!0,!1)}}:i&&!u?{a:function(){return V.matMul(M,!1,!0)},b:function(){return $.matMul(M,!1,!1)}}:{a:function(){return V.matMul(M,!0,!0)},b:function(){return M.matMul($,!0,!0)}}:{a:function(){return M.matMul(V,!1,!0)},b:function(){return $.matMul(M,!0,!1)}},B)},"_FusedMatMul",{transposeA:i,transposeB:u,activation:c},W,[!0]).reshape(R)}}),KS=D({fusedConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,o=e.pad,i=e.dataFormat,a=i===void 0?"NHWC":i,u=e.dilations,s=u===void 0?[1,1]:u,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=f===void 0?"linear":f,h=e.preluActivationWeights;if(d=d||"linear",Ud(A.state.gradientDepth,d)===!1){var p=un(t,n,r,o,a,s,l);return c!=null&&(p=de(p,c)),Hd(p,d,h)}var m=S(t,"x","conv2d"),g=S(n,"filter","conv2d"),v=m,y=!1;m.rank===3&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),I(v.rank===4,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+v.rank+"."}),I(g.rank===4,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+g.rank+"."}),l!=null&&I(Ve(o),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+l+" but got pad "+o+"."}),I(v.shape[3]===g.shape[2],function(){return"Error in conv2d: depth of input ("+v.shape[3]+") must match input depth for filter "+g.shape[2]+"."}),I(Ot(r,s),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+s+"'"}),I(a==="NHWC",function(){return"Error in conv2d: got dataFormat of "+a+" but only NHWC is currently supported."});var x,w,b=bo(v.shape,g.shape,r,s,o,l);c!=null&&(x=Le(x=S(c,"bias","fused conv2d"),m)[0],he(b.outShape,x.shape)),h!=null&&(w=S(h,"prelu weights","fused conv2d"));var C={x:v,filter:g};c!=null&&(C.bias=x),h!=null&&(C.preluActivationWeights=w);var _=[g,v],E=A.runKernelFunc(function(R,k){var T=R.fusedConv2d({input:v,filter:g,convInfo:b,bias:x,activation:d,preluActivationWeights:w});return k([g,v,T]),T},C,function(R,k){var T=k,N=T[0],W=T[1],L=T[2],U=Vd(R,L,d);I(gi(s),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+s+"'"});var $={};return c!=null&&($={bias:function(){return $d(x,U)}}),Object.assign({x:function(){return ry(W.shape,U,N,r,o)},filter:function(){return Fd(W,U,N.shape,r,o)}},$)},"FusedConv2D",{convInfo:b,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),XS=D({fusedDepthwiseConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,o=e.pad,i=e.dataFormat,a=i===void 0?"NHWC":i,u=e.dilations,s=u===void 0?[1,1]:u,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=f===void 0?"linear":f,h=e.preluActivationWeights;if(Ud(A.state.gradientDepth,d)===!1){var p=$s(t,n,r,o,a,s,l);return c!=null&&(p=de(p,c)),Hd(p,d,h)}var m=S(t,"x","depthwiseConv2d"),g=S(n,"filter","depthwiseConv2d"),v=m,y=!1;m.rank===3&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),I(v.rank===4,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+v.rank+"."}),I(g.rank===4,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+g.rank+"."}),I(v.shape[3]===g.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+v.shape[3]+") must match the inChannels dimension in filter "+g.shape[2]+"."}),s==null&&(s=[1,1]),I(Ot(r,s),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+s+"'"}),l!=null&&I(Ve(o),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+l+" but got pad "+o+"."});var x,w,b=bo(v.shape,g.shape,r,s,o,l,!0);c!=null&&(x=Le(x=S(c,"bias","fused conv2d"),m)[0],he(b.outShape,x.shape)),h!=null&&(w=S(h,"prelu weights","fused depthwiseConv2d"));var C={x:v,filter:g};c!=null&&(C.bias=x),h!=null&&(C.preluActivationWeights=w);var _=[g,v],E=A.runKernelFunc(function(R,k){var T=R.fusedDepthwiseConv2D({input:v,filter:g,convInfo:b,bias:x,activation:d,preluActivationWeights:w});return k([g,v,T]),T},C,function(R,k){I(gi(s),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+s+"'"});var T=k[0],N=k[1],W=k[2],L=Vd(R,W,d),U={};return c!=null&&(U={bias:function(){return $d(x,L)}}),Object.assign({x:function(){return oy(N.shape,L,T,b)},filter:function(){return iy(N,L,T.shape,b)}},U)},"FusedDepthwiseConv2D",{convInfo:b,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),YS=Object.freeze({matMul:qS,conv2d:KS,depthwiseConv2d:XS}),QS=Object.freeze({image:zd,linalg:WS,losses:MS,spectral:wS,fused:YS,signal:SS,square:N_,squaredDifference:U0,conv1d:zE,conv2d:un,conv3d:UE,depthwiseConv2d:$s,separableConv2d:Md,conv2dTranspose:VE,conv3dTranspose:$E,op:D,batchNormalization2d:uE,batchNormalization3d:sE,batchNormalization4d:lE,batchNormalization:cE,batchNorm:q0,batchNorm2d:fE,batchNorm3d:dE,batchNorm4d:hE,booleanMaskAsync:WE,complex:ut,real:en,imag:An,concat:Ye,concat1d:Y2,concat2d:Q2,concat3d:J2,concat4d:Z2,split:bd,matMul:Hs,dot:HE,outerProduct:jE,reverse:Fa,reverse1d:GE,reverse2d:qE,reverse3d:KE,reverse4d:XE,maxPool:tt,avgPool:Ma,pool:YE,maxPool3d:QE,avgPool3d:JE,slice:Wn,slice1d:ZE,slice2d:eS,slice3d:sy,slice4d:tS,abs:A_,acos:P_,acosh:F_,asin:M_,asinh:O_,atan:B_,atanh:L_,ceil:W_,clipByValue:Nd,cos:z_,cosh:U_,erf:V_,exp:pf,expm1:$_,floor:H_,log:j_,log1p:G_,logSigmoid:q_,neg:vs,reciprocal:K_,round:X_,rsqrt:V0,sigmoid:$0,sign:Y_,isNaN:Q_,isInf:J_,isFinite:Z_,sin:eE,sinh:tE,softplus:nE,sqrt:rE,step:oE,tan:iE,tanh:aE,all:nS,any:rS,argMax:oS,argMin:iS,logSumExp:aS,max:js,mean:uS,min:sS,moments:lS,sum:cy,prod:cS,equal:J0,equalStrict:DE,greater:TE,greaterEqual:Z0,greaterEqualStrict:NE,greaterStrict:AE,less:PE,lessEqual:FE,lessEqualStrict:ME,lessStrict:OE,notEqual:BE,notEqualStrict:LE,add:de,addN:mE,addStrict:gE,atan2:yE,div:pn,divNoNan:xE,divStrict:wE,floorDiv:Y0,maximum:Ad,maximumStrict:bE,minimum:Q0,minimumStrict:CE,mod:_E,modStrict:EE,mul:xt,mulStrict:SE,pow:ms,powStrict:kE,squaredDifferenceStrict:RE,sub:Ze,subStrict:IE,elu:fy,leakyRelu:fS,prelu:dy,relu:Me,relu6:hy,selu:dS,logicalAnd:Vs,logicalNot:pE,logicalOr:K0,logicalXor:vE,where:mo,whereAsync:X0,buffer:se,print:sb,batchToSpaceND:c0,broadcastTo:lb,cast:cb,clone:fb,cumsum:db,depthToSpace:hb,expandDims:Zt,eye:f0,multinomial:pb,oneHot:cf,pad:wo,pad1d:vb,pad2d:mb,pad3d:gb,pad4d:yb,rand:xb,randomNormal:wb,randomGamma:bb,randomUniform:d0,reshape:vn,spaceToBatchND:h0,squeeze:p0,stack:Gt,tile:ti,truncatedNormal:Cb,unstack:Qe,setdiff1dAsync:_b,fill:Ln,linspace:X2,ones:_i,range:us,scalar:K,tensor:lt,tensor1d:Ge,tensor2d:Mr,tensor3d:wd,tensor4d:It,tensor5d:G2,tensor6d:q2,variable:K2,zeros:Ie,onesLike:l0,zerosLike:ye,transpose:zr,softmax:lr,logSoftmax:Tb,localResponseNormalization:hS,norm:py,gather:Pd,unsortedSegmentSum:ey,basicLSTMCell:pS,multiRNNCell:vS,movingAverage:mS,stridedSlice:gS,topk:yS,scatterND:xS,fft:Od,ifft:gs,rfft:Bd,irfft:vy,sparseToDense:bS,gatherND:CS,diag:_S,dropout:ES,hannWindow:Ld,hammingWindow:gy,frame:Wd,stft:yy,inTopKAsync:kS});function H(e,t){Array.isArray(e)||(e=[e]),e.forEach(function(n){n!=null&&I(n.dtype!=="complex64",function(){return t+" does not support complex64 tensors."})})}function Xl(e,t,n,r){if(n==="linear")return e.linear(t);if(n==="relu")return e.relu(t);if(n==="elu")return e.elu(t);if(n==="relu6")return e.relu6(t);if(n==="prelu")return e.prelu(t,r);throw new Error("Activation "+n+" has not been implemented for the CPU backend.")}var JS=function(e){function t(){var n=e.call(this)||this;return n.blockSize=48,n.firstUse=!0,n.data=new b0(n,A),n}return wn(t,e),t.prototype.write=function(n,r,o){this.firstUse&&(this.firstUse=!1,z().get("IS_NODE")&&is(` + `}(r));return this.compileAndRun(o,[n])},t.prototype.conv2dByMatMul=function(n,r,o,i,a,u){var s=n.shape,l=this.texData.get(n.dataId),c=o.inChannels,f=s[0]*s[1]*s[2],d=o.outChannels,h=o.dataFormat==="channelsLast",p=(f===1||d===1)&&c>1e3,m=s[2]%2!=0&&!!l.isPacked;if(p||!z().getBool("WEBGL_LAZILY_UNPACK")||!z().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!m){var g=h?s[0]*s[1]*s[2]:s[0]*s[2]*s[3],v=this.reshape(n,[1,g,o.inChannels]),y=this.reshape(r,[1,o.inChannels,o.outChannels]);return this.reshape(this.fusedBatchMatMul({a:v,b:y,transposeA:!1,transposeB:!1,bias:i,activation:a,preluActivationWeights:u}),o.outShape)}var x=h?s[0]*s[1]*(s[2]+1):s[0]*s[2]*(s[3]+1),w={dataId:n.dataId,shape:[1,x,o.inChannels],dtype:n.dtype},b=l.shape;l.shape=l.shape.slice(),l.shape[l.shape.length-2]++,I(ru(l.shape,w.shape),function(){return"packed reshape "+l.shape+" to "+w.shape+" isn't free"});var C=this.reshape(r,[1,o.inChannels,o.outChannels]),_=this.fusedBatchMatMul({a:w,b:C,transposeA:!1,transposeB:!1,bias:i,activation:a,preluActivationWeights:u}),E=this.texData.get(_.dataId);return I(E.isPacked,function(){return"batchMatMul result is expected to be packed"}),l.shape=b,E.shape=o.outShape,A.makeTensorFromDataId(_.dataId,o.outShape,_.dtype)},t.prototype.conv2dWithIm2Row=function(n,r,o,i,a,u){var s=o.filterWidth,l=o.filterHeight,c=o.inChannels,f=o.outWidth,d=o.outHeight,h=o.dataFormat==="channelsLast",p=s*l*c,m=d*f,g=[p,m],v=n.squeeze([0]),y=r.reshape([1,p,-1]),x=new LC(g,v.shape,o),w=this.compileAndRun(x,[v]).reshape([1,g[0],g[1]]),b=i!=null,C=u!=null,_=a?uu(a,!0):null,E=new Vl(w.shape,[1,m,o.outChannels],!0,!1,b,_,C),R=[w,y];i&&R.push(i),C&&R.push(u);var k=this.compileAndRun(E,R);return h?k.reshape([1,d,f,o.outChannels]):k.reshape([1,o.outChannels,d,f])},t.prototype.fusedConv2d=function(n){var r=n.input,o=n.filter,i=n.convInfo,a=n.bias,u=n.activation,s=n.preluActivationWeights;if(i.filterHeight===1&&i.filterWidth===1&&i.dilationHeight===1&&i.dilationWidth===1&&i.strideHeight===1&&i.strideWidth===1&&(i.padInfo.type==="SAME"||i.padInfo.type==="VALID"))return this.conv2dByMatMul(r,o,i,a,u,s);if(z().getBool("WEBGL_CONV_IM2COL")&&r.shape[0]===1)return this.conv2dWithIm2Row(r,o,i,a,u,s);var l=a!=null,c=s!=null,f=u?uu(u,!1):null,d=new $p(i,l,f,c),h=[r,o];return a&&h.push(a),s&&h.push(s),this.compileAndRun(d,h)},t.prototype.conv2d=function(n,r,o){if(o.filterHeight===1&&o.filterWidth===1&&o.dilationHeight===1&&o.dilationWidth===1&&o.strideHeight===1&&o.strideWidth===1&&(o.padInfo.type==="SAME"||o.padInfo.type==="VALID"))return this.conv2dByMatMul(n,r,o);if(z().getBool("WEBGL_CONV_IM2COL")&&n.shape[0]===1)return this.conv2dWithIm2Row(n,r,o);var i=new $p(o);return this.compileAndRun(i,[n,r])},t.prototype.conv2dDerInput=function(n,r,o){var i=new eC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv2dDerFilter=function(n,r,o){var i=new Zb(o);return this.compileAndRun(i,[n,r])},t.prototype.fusedDepthwiseConv2D=function(n){var r,o=n.input,i=n.filter,a=n.convInfo,u=n.bias,s=n.activation,l=n.preluActivationWeights,c=z().getBool("WEBGL_PACK_DEPTHWISECONV")&&a.strideWidth<=2&&a.outChannels/a.inChannels==1,f=s?uu(s,c):null,d=[o,i],h=u!=null,p=l!=null;return h&&d.push(u),p&&d.push(l),c?(r=new jp(a,h,f,p),this.compileAndRun(r,d)):(r=new Hp(a,h,f,p),this.compileAndRun(r,d))},t.prototype.depthwiseConv2D=function(n,r,o){var i;return z().getBool("WEBGL_PACK_DEPTHWISECONV")&&o.strideWidth<=2&&o.outChannels/o.inChannels==1?(i=new jp(o),this.compileAndRun(i,[n,r])):(i=new Hp(o),this.compileAndRun(i,[n,r]))},t.prototype.depthwiseConv2DDerInput=function(n,r,o){var i=new oC(o);return this.compileAndRun(i,[n,r])},t.prototype.depthwiseConv2DDerFilter=function(n,r,o){var i=new rC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3d=function(n,r,o){var i=new iC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3dDerInput=function(n,r,o){var i=new nC(o);return this.compileAndRun(i,[n,r])},t.prototype.conv3dDerFilter=function(n,r,o){var i=new tC(o);return this.compileAndRun(i,[n,r])},t.prototype.maxPool=function(n,r){var o=new $l(r,"max",!1);return this.compileAndRun(o,[n])},t.prototype.avgPool=function(n,r){var o=new $l(r,"avg",!1);return this.compileAndRun(o,[n],"float32")},t.prototype.maxPoolBackprop=function(n,r,o,i){var a=new $l(i,"max",!0),u=this.compileAndRun(a,[r]),s=new VC(i),l=this.compileAndRun(s,[n,u],r.dtype);return u.dispose(),l},t.prototype.avgPoolBackprop=function(n,r,o){var i=new Vb(o);return this.compileAndRun(i,[n],r.dtype)},t.prototype.cast=function(n,r){return w0(n,r,this)},t.prototype.unstack=function(n,r){for(var o=n.shape[r],i=new Array(n.rank-1),a=0,u=0;u1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+r});var i=n.shape[0],a=o==="NHWC"?n.shape[1]:n.shape[2],u=o==="NHWC"?n.shape[2]:n.shape[3],s=o==="NHWC"?n.shape[3]:n.shape[1],l=a*r,c=u*r,f=s/(r*r),d=new cC(o==="NHWC"?[i,l,c,f]:[i,f,l,c],r,o);return this.compileAndRun(d,[n])},t.prototype.split=function(n,r,o){return _0(n,r,o)},t.prototype.scatterND=function(n,r,o){var i=ss(0,n,o),a=i.sliceRank,u=i.numUpdates,s=i.sliceSize,l=i.strides,c=i.outputSize,f=[c/s,s],d=n.reshape([u,a]),h=r.reshape([u,s]);if(c===0)return cf(lt([]),o);var p=K(0),m=new Xp(u,a,d.rank,h.rank,l,f);return this.compileAndRun(m,[h,d,p]).reshape(o)},t.prototype.sparseToDense=function(n,r,o,i){var a=ss(0,n,o),u=a.sliceRank,s=a.numUpdates,l=a.strides,c=a.outputSize,f=new Xp(s,u,n.rank,r.rank,l,[c,1]);return this.compileAndRun(f,[r,n,i]).reshape(o)},t.prototype.fft=function(n){return this.fftImpl(n,!1)},t.prototype.ifft=function(n){return this.fftImpl(n,!0)},t.prototype.fftImpl=function(n,r){var o=this.texData.get(n.dataId),i=new qp(mC,n.shape,r),a=new qp(gC,n.shape,r),u=[this.makeComplexComponentTensorInfo(n,o.complexTensors.real),this.makeComplexComponentTensorInfo(n,o.complexTensors.imag)],s=this.compileAndRun(i,u),l=this.compileAndRun(a,u),c=this.complex(s,l).as2D(n.shape[0],n.shape[1]);return s.dispose(),l.dispose(),c},t.prototype.gatherND=function(n,r){var o=r.shape,i=o[o.length-1],a=h0(n,r),u=a[0],s=a[1],l=a[2],c=a[3],f=r.reshape([s,i]),d=n.reshape([n.size/l,l]),h=new wC(i,c,[s,l]);return this.compileAndRun(h,[d,f]).reshape(u)},t.prototype.fill=function(n,r,o){if((o=o||Ra(r))==="string"){var i=Ju(o,Z(n));return i.fill(r),A.makeTensor(i,n,o,this)}var a=new yC(n,r),u=a.getCustomSetupFunc(r);return this.compileAndRun(a,[],o,u)},t.prototype.onesLike=function(n){if(n.dtype==="string")throw new Error("onesLike is not supported under string dtype");return this.fill(n.shape,1,n.dtype)},t.prototype.zerosLike=function(n){return this.fill(n.shape,n.dtype==="string"?"":0,n.dtype)},t.prototype.linspace=function(n,r,o){return b0(n,r,o)},t.prototype.makeTensorInfo=function(n,r){var o=this.write(null,n,r);return this.texData.get(o).usage=null,{dataId:o,shape:n,dtype:r}},t.prototype.makeOutput=function(n,r){var o=this.makeTensorInfo(n,r).dataId;return A.makeTensorFromDataId(o,n,r,this)},t.prototype.unpackTensor=function(n){var r=new E_(n.shape);return this.runWebGLProgram(r,[n],n.dtype)},t.prototype.packTensor=function(n){var r=new GC(n.shape);return this.runWebGLProgram(r,[n],n.dtype,null,!0)},t.prototype.packedReshape=function(n,r){var o=[es(n.shape)].concat(ts(n.shape)),i={dtype:n.dtype,shape:o,dataId:n.dataId},a=[es(r)].concat(ts(r)),u=new YC(a,o),s=this.runWebGLProgram(u,[i],n.dtype,null,!0);return{dataId:s.dataId,shape:r,dtype:s.dtype}},t.prototype.decode=function(n){var r,o=this.texData.get(n),i=o.isPacked,a=o.shape,u=o.dtype,s=Ll(a);return r=i?new lC(s):new sC(s),{dtype:u,shape:a,dataId:this.runWebGLProgram(r,[{shape:s,dtype:u,dataId:n}],u,null,!0).dataId}},t.prototype.runWebGLProgram=function(n,r,o,i,a){var u=this;a===void 0&&(a=!1);var s=this.makeTensorInfo(n.outputShape,o),l=this.texData.get(s.dataId);if(n.packedOutput&&(l.isPacked=!0),n.outPackingScheme===va.DENSE){var c=qi(n.outputShape);l.texShape=c.map(function(x){return 2*x})}if(n.outTexUsage!=null&&(l.usage=n.outTexUsage),Z(s.shape)===0)return l.values=ha(s.dtype,0),s;var f=[],d=r.map(function(x){if(x.dtype==="complex64")throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var w=u.texData.get(x.dataId);if(w.texture==null){if(!n.packedInputs&&Z(x.shape)<=z().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:x.shape,texData:null,isUniform:!0,uniformValues:w.values};n.packedInputs&&(w.isPacked=!0,w.shape=x.shape)}else if(!!w.isPacked!=!!n.packedInputs)x=w.isPacked?u.unpackTensor(x):u.packTensor(x),f.push(x),w=u.texData.get(x.dataId);else if(w.isPacked&&!ru(w.shape,x.shape)){var b=x,C=x.shape;x.shape=w.shape,x=u.packedReshape(x,C),f.push(x),w=u.texData.get(x.dataId),b.shape=C}return u.uploadToGPU(x.dataId),{shape:x.shape,texData:w,isUniform:!1}});this.uploadToGPU(s.dataId);var h,p={shape:s.shape,texData:l,isUniform:!1},m=function(x,w,b){var C="";w.concat(b).forEach(function(R){var k=R.texData!=null&&R.texData.slice!=null&&R.texData.slice.flatOffset>0,T=R.isUniform?"uniform":R.texData.texShape;C+=R.shape+"_"+T+"_"+k});var _=x.userCode,E=x.constructor.name;return E+="_"+C+"_"+_}(n,d,p),g=this.getAndSaveBinary(m,function(){return function(x,w,b,C){var _=w.userCode,E=b.map(function(P,M){var B={logicalShape:P.shape,texShape:P.isUniform?null:P.texData.texShape,isUniform:P.isUniform,isPacked:!P.isUniform&&P.texData.isPacked,flatOffset:null};return P.texData!=null&&P.texData.slice!=null&&P.texData.slice.flatOffset>0&&(B.flatOffset=P.texData.slice.flatOffset),{name:w.variableNames[M],shapeInfo:B}}),R=E.map(function(P){return P.shapeInfo}),k={logicalShape:C.shape,texShape:C.texData.texShape,isUniform:!1,isPacked:C.texData.isPacked,flatOffset:null},T=Ob(E,k,_,w.packedInputs),N=x.createProgram(T),W=null,L=x.getUniformLocation(N,"NAN",!1);z().getNumber("WEBGL_VERSION")===1&&(W=x.getUniformLocation(N,"INFINITY",!1));for(var U={},$=0;$0)return 32}return 16})),this.floatPrecisionValue},t.prototype.epsilon=function(){return this.floatPrecision()===32?1e-7:1e-4},t.prototype.uploadToGPU=function(n){var r,o=this.texData.get(n),i=o.shape,a=o.dtype,u=o.values,s=o.texture,l=o.usage,c=o.isPacked;if(s==null){var f,d=this.activeTimers!=null;d&&(f=In());var h=o.texShape;if(h==null&&(h=A2(i,c),o.texShape=h),u!=null){var p=Ll(i),m=void 0,g=h[1],v=h[0],y=u instanceof Uint8Array;c?(g=(r=Da(h[0],h[1]))[0],v=r[1],m=new vC(p,[v,g],y)):m=new pC(p,[v,g],y);var x=this.makeTensorInfo([v,g],a);this.texData.get(x.dataId).usage=y?Vt.PIXELS:Vt.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(x.dataId),g,v,u);var w=this.runWebGLProgram(m,[x],a,null,!0),b=this.texData.get(w.dataId);o.texture=b.texture,o.texShape=b.texShape,o.isPacked=b.isPacked,o.usage=b.usage,this.disposeData(x.dataId),this.texData.delete(w.dataId),o.values=null,d&&(this.uploadWaitMs+=In()-f)}else{var C=this.acquireTexture(h,l,a,c);o.texture=C}}},t.prototype.convertAndCacheOnCPU=function(n,r){var o=this.texData.get(n),i=o.dtype;return this.releaseGPUData(n),r!=null&&(o.values=function(a,u){if(u==="float32"||u==="complex64")return a;if(u==="int32"||u==="bool"){for(var s=u==="int32"?new Int32Array(a.length):new Uint8Array(a.length),l=0;l1024*this.numMBBeforeWarning*1024){var a=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+a+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(n,r,i)},t.prototype.computeBytes=function(n,r){return n[0]*n[1]*Xg(r)},t}(y0);n0()&&A.registerBackend("webgl",function(){return new k_},2);var R_=D({square_:function(e){var t=S(e,"x","square"),n=[t];return A.runKernelFunc(function(r,o){return o([t]),r.square(t)},{x:t},null,"Square",{},n,[])}}),ga="SquaredDifference",B0=D({squaredDifference_:function(e,t){var n,r=S(e,"a","squaredDifference"),o=S(t,"b","squaredDifference");n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape);var i={a:r,b:o},a=[r,o];return A.runKernelFunc(function(u,s){var l=u.squaredDifference(r,o);return s([r,o]),l},i,function(u,s){var l=s[0],c=s[1],f=K(2);return{a:function(){return u.mul(l.sub(c).mul(f))},b:function(){return u.mul(c.sub(l).mul(f))}}},ga,{},a,[])}}),I_=D({abs_:function(e){var t=S(e,"x","abs");return t.dtype==="complex64"?A.runKernelFunc(function(n){return n.complexAbs(t)},{$x:t}):A.runKernelFunc(function(n,r){var o=n.abs(t);return r([t]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mul(o.toFloat().step(-1))}}},"Abs")}}),D_=D({acos_:function(e){var t=S(e,"x","acos");return A.runKernelFunc(function(n,r){var o=n.acos(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).sub(o.toFloat().square()).sqrt()).neg()}}})}}),T_=D({acosh_:function(e){var t=S(e,"x","acosh");return A.runKernelFunc(function(n,r){var o=n.acosh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(o.toFloat().square().sub(1).sqrt())}}})}}),N_=D({asin_:function(e){var t=S(e,"x","asin");return A.runKernelFunc(function(n,r){var o=n.asin(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).sub(o.toFloat().square()).sqrt())}}})}}),A_=D({asinh_:function(e){var t=S(e,"x","asinh");return A.runKernelFunc(function(n,r){var o=n.asinh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.divStrict(K(1).add(o.toFloat().square()).sqrt())}}})}}),P_=D({atan_:function(e){var t=S(e,"x","atan");return A.runKernelFunc(function(n,r){var o=n.atan(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.toFloat().square().add(1))}}})}}),F_=D({atanh_:function(e){var t=S(e,"x","atanh");return A.runKernelFunc(function(n,r){var o=n.atanh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(K(1).sub(o.toFloat().square()))}}})}}),M_=D({ceil_:function(e){var t=S(e,"x","ceil");return A.runKernelFunc(function(n){return n.ceil(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),Dd=D({clipByValue_:function(e,t,n){var r=S(e,"x","clipByValue");I(t<=n,function(){return"Error in clip: min ("+t+") must be less than or equal to max ("+n+")."});var o=[r],i={min:t,max:n};return A.runKernelFunc(function(a,u){var s=a.clip(r,t,n);return u([r]),s},{x:r},function(a,u){var s=u[0];return{x:function(){return a.where(s.greaterEqual(t).logicalAnd(s.lessEqual(n)),ye(a))}}},"ClipByValue",i,o)}}),O_=D({cos_:function(e){var t=S(e,"x","cos"),n=[t];return A.runKernelFunc(function(r,o){var i=r.cos(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return i.toFloat().sin().neg().mul(r)}}},"Cos",{},n)}}),B_=D({cosh_:function(e){var t=S(e,"x","cosh");return A.runKernelFunc(function(n,r){var o=n.cosh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return o.toFloat().sinh().mulStrict(n)}}})}}),L_=D({erf_:function(e){var t=S(e,"x","erf");return I(t.dtype==="int32"||t.dtype==="float32",function(){return"Input dtype must be `int32` or `float32`."}),t.dtype==="int32"&&(t=t.toFloat()),A.runKernelFunc(function(n,r){var o=n.erf(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),df=D({exp_:function(e){var t=S(e,"x","exp");return A.runKernelFunc(function(n,r){var o=n.exp(t);return r([o]),o},{x:t},function(n,r){return{x:function(){return n.mulStrict(r[0])}}},"Exp",{},[],[!0])}}),W_=D({expm1_:function(e){var t=S(e,"x","expm1");return A.runKernelFunc(function(n,r){var o=n.expm1(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.exp())}}})}}),z_=D({floor_:function(e){var t=S(e,"x","floor");return A.runKernelFunc(function(n){return n.floor(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),U_=D({log_:function(e){var t=S(e,"x","log"),n=[t];return A.runKernelFunc(function(r,o){var i=r.log(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return r.div(i.toFloat())}}},"Log",{},n)}}),V_=D({log1p_:function(e){var t=S(e,"x","log1p");return A.runKernelFunc(function(n,r){var o=n.log1p(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.add(1))}}})}}),$_=D({logSigmoid_:function(e){var t=S(e,"x","logSigmoid");return A.runKernelFunc(function(n,r){var o=n.softplus(t.neg()).neg();return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.neg().sigmoid())}}})}}),ds=D({neg_:function(e){var t=S(e,"x","neg"),n=[t];return A.runKernelFunc(function(r){return r.neg(t)},{x:t},function(r){return{x:function(){return r.neg()}}},"Neg",{},n)}}),H_=D({reciprocal_:function(e){var t=S(e,"x","reciprocal");return A.runKernelFunc(function(n,r){var o=n.reciprocal(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.square().neg())}}})}}),j_=D({round_:function(e){var t=S(e,"x","round");return A.runKernelFunc(function(n){return n.round(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),L0=D({rsqrt_:function(e){var t=S(e,"x","rsqrt"),n=[t];return A.runKernelFunc(function(r,o){var i=r.rsqrt(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return r.div(i.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},n)}}),W0=D({sigmoid_:function(e){var t=S(e,"x","sigmoid");return A.runKernelFunc(function(n,r){var o=n.sigmoid(t);return r([o]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mul(o.mul(K(1).sub(o)))}}},"Sigmoid")}}),G_=D({sign_:function(e){var t=S(e,"x","sign");return A.runKernelFunc(function(n){return n.sign(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),q_=D({isNaN_:function(e){var t=S(e,"x","isNaN");return A.runKernelFunc(function(n){return n.isNaN(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),K_=D({isInf_:function(e){var t=S(e,"x","isInf");return A.runKernelFunc(function(n){return n.isInf(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),X_=D({isFinite_:function(e){var t=S(e,"x","isFinite");return A.runKernelFunc(function(n){return n.isFinite(t)},{$x:t},function(n){return{$x:function(){return ye(n)}}})}}),Y_=D({sin_:function(e){var t=S(e,"x","sin"),n=[t];return A.runKernelFunc(function(r,o){var i=r.sin(t);return o([t]),i},{x:t},function(r,o){var i=o[0];return{x:function(){return i.toFloat().cos().mul(r)}}},"Sin",{},n)}}),Q_=D({sinh_:function(e){var t=S(e,"x","sinh");return A.runKernelFunc(function(n,r){var o=n.sinh(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return o.toFloat().cosh().mulStrict(n)}}})}}),J_=D({softplus_:function(e){var t=S(e,"x","softplus");return A.runKernelFunc(function(n,r){var o=n.softplus(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.mul(o.sigmoid())}}})}}),Z_=D({sqrt_:function(e){var t=S(e,"x","sqrt");return A.runKernelFunc(function(n,r){var o=n.sqrt(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.toFloat().sqrt().mul(2))}}})}}),eE=D({step_:function(e,t){t===void 0&&(t=0);var n=S(e,"x","step");return A.runKernelFunc(function(r){return r.step(n,t)},{$x:n},function(r){return{$x:function(){return ye(r)}}})}}),tE=D({tan_:function(e){var t=S(e,"x","tan");return A.runKernelFunc(function(n,r){var o=n.tan(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){return n.div(o.cos().square())}}})}}),nE=D({tanh_:function(e){var t=S(e,"x","tanh");return A.runKernelFunc(function(n,r){var o=n.tanh(t);return r([o]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return K(1).sub(o.square()).mulStrict(n)}}},"Tanh",{},null,[!0])}});function z0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===2,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+s.rank+"."}),I(l.rank===2||l.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+l.rank+"."}),I(c.rank===2||c.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===2||a.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===2||u.rank===1,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+u.rank+"."}),Na(s,l,c,u,a,i)}function U0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===3,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+s.rank+"."}),I(l.rank===3||l.rank===1,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+l.rank+"."}),I(c.rank===3||c.rank===1,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===3||a.rank===1,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===3||u.rank===1,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+u.rank+"."}),Na(s,l,c,u,a,i)}function V0(e,t,n,r,o,i){var a,u,s=S(e,"x","batchNorm"),l=S(t,"mean","batchNorm"),c=S(n,"variance","batchNorm");return o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(s.rank===4,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+s.rank+"."}),I(l.rank===4||l.rank===1,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+l.rank+"."}),I(c.rank===4||c.rank===1,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+c.rank+"."}),a!=null&&I(a.rank===4||a.rank===1,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+a.rank+"."}),u!=null&&I(u.rank===4||u.rank===1,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+u.rank+"."}),Na(s,l,c,u,a,i)}function Na(e,t,n,r,o,i){i==null&&(i=.001);var a,u,s,l=S(e,"x","batchNorm"),c=S(t,"mean","batchNorm"),f=S(n,"variance","batchNorm");o!=null&&(a=S(o,"scale","batchNorm")),r!=null&&(u=S(r,"offset","batchNorm")),I(c.rank===f.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),I(u==null||c.rank===u.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),I(a==null||c.rank===a.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),s=l.rank===0||l.rank===1?l.as4D(1,1,1,l.size):l.rank===2?l.as4D(1,1,l.shape[0],l.shape[1]):l.rank===3?l.as4D(1,l.shape[0],l.shape[1],l.shape[2]):l;var d=[l,c,f,a];return A.runKernelFunc(function(h,p){var m=h.batchNormalization(s,su(c),su(f),i,su(a),su(u));return p([l,c,f,a]),m},{x:l,mean:c,variance:f,scale:a,offset:u},function(h,p){var m=p,g=m[0],v=m[1],y=m[2],x=m[3],w=x??K(1),b=Je(v.shape,s.shape),C=[];if(v.rank===1){for(var _=0;_0&&(u=u.sum(s)),u.reshape(r.shape)},b:function(){var u=a,s=Je(o.shape,i);return s.length>0&&(u=u.sum(s)),u.reshape(o.shape)}}},"Add")}}),dE=D({addN_:function(e){I(Array.isArray(e),function(){return"The argument passed to tf.addN() must be a list of tensors"}),I(e.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+e.length});var t=e.map(function(o,i){return S(o,"tensors"+i,"addN")}),n=t[0];t.forEach(function(o){if(o.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),t.forEach(function(o){if(!ot(o.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var r=t;return A.runKernelFunc(function(o){return o.addN(t)},r,function(o){var i={};return t.forEach(function(a,u){i[u]=function(){return o.clone()}}),i},"AddN")}}),hE=D({addStrict_:function(e,t){var n=S(e,"a","addStrict"),r=S(t,"b","addStrict");return Ce(n.shape,r.shape,"Error in addStrict: "),n.add(r)}}),pE=D({atan2_:function(e,t){var n,r=S(e,"a","atan2"),o=S(t,"b","atan2");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.atan2(r,o);return u([r,o]),s},{$a:r,$b:o},function(a,u){var s=u[0],l=u[1];return{$a:function(){var c=de(s.square(),l.square()),f=a.mul(l.div(c)),d=Je(s.shape,i);return d.length>0&&(f=f.sum(d)),f.reshape(s.shape)},$b:function(){var c=de(s.square(),l.square()),f=ds(a.mul(s.div(c))),d=Je(l.shape,i);return d.length>0&&(f=f.sum(d)),f.reshape(l.shape)}}})}}),hn=D({div_:function(e,t){var n,r=S(e,"a","div"),o=S(t,"b","div");if(n=Le(r,o),r=n[0],o=n[1],r.dtype==="int32"&&o.dtype==="int32")return G0(r,o);var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.realDivide(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.div(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);f.length>0&&(c=c.sum(f).reshape(l.shape));var d=l.square();return c.div(d.toFloat()).neg()}}},"Div")}}),vE=D({divNoNan_:function(e,t){var n,r=S(e,"a","div"),o=S(t,"b","div");r=(n=Le(r,o))[0],o=n[1];var i=hn(r,o),a=ye(i),u=o.equal(a);return po(u,a,i)}}),mE=D({divStrict_:function(e,t){var n=S(e,"a","div"),r=S(t,"b","div");return Ce(n.shape,r.shape,"Error in divideStrict: "),n.div(r)}}),G0=D({floorDiv_:function(e,t){var n,r=S(e,"a","floorDiv"),o=S(t,"b","floorDiv");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.floorDiv(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.div(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);f.length>0&&(c=c.sum(f).reshape(l.shape));var d=l.square();return c.div(d.toFloat()).neg()}}},"FloorDiv")}}),Td=D({maximum_:function(e,t){var n,r=S(e,"a","maximum"),o=S(t,"b","maximum");return n=Le(r,o),r=n[0],o=n[1],r.dtype==="bool"&&(r=r.toInt(),o=o.toInt()),he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.maximum(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return i.mul(u.greaterEqual(s).toFloat())},b:function(){return i.mul(u.less(s).toFloat())}}},"Maximum")}}),gE=D({maximumStrict_:function(e,t){var n=S(e,"a","maximumStrict"),r=S(t,"b","maximumStrict");return Ce(n.shape,r.shape,"Error in maximumStrict: "),n.maximum(r)}}),q0=D({minimum_:function(e,t){var n,r=S(e,"a","minimum"),o=S(t,"b","minimum");return n=Le(r,o),r=n[0],o=n[1],r.dtype==="bool"&&(r=r.toInt(),o=o.toInt()),he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.minimum(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return i.mul(u.lessEqual(s).toFloat())},b:function(){return i.mul(u.greater(s).toFloat())}}},"Minimum")}}),yE=D({minimumStrict_:function(e,t){var n=S(e,"a","minimumStrict"),r=S(t,"b","minimumStrict");return Ce(n.shape,r.shape,"Error in minimumStrict: "),n.minimum(r)}}),xE=D({mod_:function(e,t){var n,r=S(e,"a","mod"),o=S(t,"b","mod");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.mod(r,o);return u([r,o]),s},{$a:r,$b:o},function(a,u){var s=u[0],l=u[1];return{$a:function(){var c=Je(s.shape,i);return c.length>0?a.sum(c).reshape(s.shape):a},$b:function(){var c=a.mul(s.div(l).floor().neg()),f=Je(l.shape,i);return f.length>0?c.sum(f).reshape(l.shape):c}}})}}),wE=D({modStrict_:function(e,t){var n=S(e,"a","modStrict"),r=S(t,"b","modStrict");return Ce(n.shape,r.shape,"Error in modStrict: "),n.mod(r)}}),xt=D({mul_:function(e,t){var n,r=S(e,"a","mul"),o=S(t,"b","mul");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a,u){var s=a.multiply(r,o);return u([r,o]),s},{a:r,b:o},function(a,u){var s=u[0],l=u[1];return{a:function(){var c=a.mul(l.toFloat()),f=Je(s.shape,i);return f.length>0?c.sum(f).reshape(s.shape):c},b:function(){var c=a.mul(s.toFloat()),f=Je(l.shape,i);return f.length>0?c.sum(f).reshape(l.shape):c}}},"Mul")}}),bE=D({mulStrict_:function(e,t){var n=S(e,"a","mul"),r=S(t,"b","mul");return Ce(n.shape,r.shape,"Error in multiplyStrict: "),n.mul(r)}}),hs=D({pow_:function(e,t){var n,r=S(e,"base","pow"),o=S(t,"exp","pow");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape),a=[r,o];return A.runKernelFunc(function(u,s){var l=u.pow(r,o);return s([r,o,l]),l},{a:r,b:o},function(u,s){var l=s[0],c=s[1],f=s[2];return{a:function(){var d=c.toFloat(),h=u.mul(d.mul(l.pow(d.sub(K(1))))),p=Je(l.shape,i);return p.length>0&&(h=h.sum(p)),h.reshape(l.shape)},b:function(){var d=l.greater(0),h=l.log().where(d,ye(l)),p=u.mul(f.mul(h)),m=Je(c.shape,i);return m.length>0&&(p=p.sum(m)),p.reshape(c.shape)}}},"Pow",{},a,[!0])}}),CE=D({powStrict_:function(e,t){return Ce(e.shape,t.shape,"Error in powStrict: "),e.pow(t)}}),_E=D({squaredDifferenceStrict_:function(e,t){var n=S(e,"a","squaredDifferenceStrict"),r=S(t,"b","squaredDifferenceStrict");return Ce(n.shape,r.shape,"Error in squaredDifferenceStrict: "),n.squaredDifference(r)}}),Ze=D({sub_:function(e,t){var n,r=S(e,"a","sub"),o=S(t,"b","sub");n=Le(r,o),r=n[0],o=n[1];var i=he(r.shape,o.shape);return A.runKernelFunc(function(a){return a.subtract(r,o)},{a:r,b:o},function(a){return{a:function(){var u=a,s=Je(r.shape,i);return s.length>0&&(u=u.sum(s)),u.reshape(r.shape)},b:function(){var u=a,s=Je(o.shape,i);return s.length>0&&(u=u.sum(s)),u.neg().reshape(o.shape)}}},"Sub")}}),EE=D({subStrict_:function(e,t){var n=S(e,"a","subStrict"),r=S(t,"b","subStrict");return Ce(n.shape,r.shape,"Error in subStrict: "),n.sub(r)}}),K0=D({equal_:function(e,t){var n,r=S(e,"a","equal"),o=S(t,"b","equal");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.equal(r,o)},{$a:r,$b:o})}}),SE=D({equalStrict_:function(e,t){var n=S(e,"a","equalStrict"),r=S(t,"b","equalStrict");return Ce(n.shape,r.shape,"Error in equalStrict: "),n.equal(r)}}),kE=D({greater_:function(e,t){var n,r=S(e,"a","greater"),o=S(t,"b","greater");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.greater(r,o)},{a:r,b:o},null,"Greater")}}),X0=D({greaterEqual_:function(e,t){var n,r=S(e,"a","greaterEqual"),o=S(t,"b","greaterEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.greaterEqual(r,o);return a([r,o]),u},{a:r,b:o},function(i,a){var u=a[0],s=a[1];return{a:function(){return ye(u)},b:function(){return ye(s)}}},"GreaterEqual")}}),RE=D({greaterEqualStrict_:function(e,t){var n=S(e,"a","greaterEqualStrict"),r=S(t,"b","greaterEqualStrict");return Ce(n.shape,r.shape,"Error in greaterEqualStrict: "),n.greaterEqual(r)}}),IE=D({greaterStrict_:function(e,t){var n=S(e,"a","greaterStrict"),r=S(t,"b","greaterStrict");return Ce(n.shape,r.shape,"Error in greaterStrict: "),n.greater(r)}}),DE=D({less_:function(e,t){var n,r=S(e,"a","less"),o=S(t,"b","less");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.less(r,o)},{a:r,b:o},null,"Less")}}),TE=D({lessEqual_:function(e,t){var n,r=S(e,"a","lessEqual"),o=S(t,"b","lessEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i,a){var u=i.lessEqual(r,o);return a([r,o]),u},{a:r,b:o},null,"LessEqual")}}),NE=D({lessEqualStrict_:function(e,t){var n=S(e,"a","lessEqualStrict"),r=S(t,"b","lessEqualStrict");return Ce(n.shape,r.shape,"Error in lessEqualStrict: "),n.lessEqual(r)}}),AE=D({lessStrict_:function(e,t){var n=S(e,"a","lessStrict"),r=S(t,"b","lessStrict");return Ce(n.shape,r.shape,"Error in lessStrict: "),n.less(r)}}),PE=D({notEqual_:function(e,t){var n,r=S(e,"a","notEqual"),o=S(t,"b","notEqual");return n=Le(r,o),r=n[0],o=n[1],he(r.shape,o.shape),A.runKernelFunc(function(i){return i.notEqual(r,o)},{a:r,b:o},null,"NotEqual")}}),FE=D({notEqualStrict_:function(e,t){var n=S(e,"a","notEqualStrict"),r=S(t,"b","notEqualStrict");return Ce(n.shape,r.shape,"Error in notEqualStrict: "),n.notEqual(r)}});function ov(e,t){for(var n=[],r=e;r0,function(){return"mask cannot be scalar"}),Ce(u.slice(i,i+a),o.shape,"mask's shape must match the first K dimensions of tensor's shape,"),s=1,l=i;l=2&&a.rank>=2&&i.rank===a.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+i.rank+" and "+a.rank+"."}),I(ot(f,d),function(){return"Error in matMul: outer dimensions ("+f+") and ("+d+") of Tensors with shapes "+i.shape+" and "+a.shape+" must match."}),I(u===s,function(){return"Error in matMul: inner shapes ("+u+") and ("+s+") of Tensors with shapes "+i.shape+" and "+a.shape+" and transposeA="+n+" and transposeB="+r+" must match."});var m=i.shape.slice(0,-2).concat([l,c]),g=n?i.as3D(h,u,l):i.as3D(h,l,u),v=r?a.as3D(p,c,s):a.as3D(p,s,c),y={transposeA:n,transposeB:r};return A.runKernelFunc(function(x,w){var b=x.batchMatMul(g,v,n,r);return w([g,v]),b},{a:g,b:v},function(x,w){var b=w,C=b[0],_=b[1];return n||r?!n&&r?{a:function(){return x.matMul(_,!1,!1)},b:function(){return x.matMul(C,!0,!1)}}:n&&!r?{a:function(){return _.matMul(x,!1,!0)},b:function(){return C.matMul(x,!1,!1)}}:{a:function(){return _.matMul(x,!0,!0)},b:function(){return x.matMul(C,!0,!0)}}:{a:function(){return x.matMul(_,!1,!0)},b:function(){return C.matMul(x,!0,!1)}}},"BatchMatMul",y).reshape(m)}}),zE=D({dot_:function(e,t){var n=S(e,"t1","dot"),r=S(t,"t2","dot");I(!(n.rank!==1&&n.rank!==2||r.rank!==1&&r.rank!==2),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+n.rank+" and "+r.rank+"."});var o=n.rank===1?n.size:n.shape[1],i=r.rank===1?r.size:r.shape[0];return I(o===i,function(){return"Error in dot: inner dimensions of inputs must match, but got "+o+" and "+i+"."}),n.rank===1&&r.rank===1?n.as2D(1,-1).matMul(r.as2D(-1,1)).asScalar():n.rank===1&&r.rank===2?n.as2D(1,-1).matMul(r.as2D(r.shape[0],r.shape[1])).as1D():n.rank===2&&r.rank===1?n.matMul(r.as2D(-1,1)).as1D():n.matMul(r.as2D(r.shape[0],r.shape[1]))}}),UE=D({outerProduct_:function(e,t){var n=S(e,"v1","outerProduct"),r=S(t,"v2","outerProduct");return I(n.rank===1&&r.rank===1,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+n.rank+" and "+r.rank+"."}),n.as2D(-1,1).matMul(r.as2D(1,-1))}}),Aa=D({reverse_:function(e,t){var n=S(e,"x","reverse");if(n.rank===0)return n.clone();var r=et(t,n.shape);return A.runKernelFunc(function(o){return o.reverse(n,r)},{$x:n},function(o){return{$x:function(){return o.reverse(r)}}}).reshapeAs(n)}}),VE=D({reverse1d_:function(e){var t=S(e,"x","reverse");return I(t.rank===1,function(){return"Error in reverse1D: x must be rank 1 but got rank "+t.rank+"."}),Aa(t,0)}}),$E=D({reverse2d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===2,function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."}),Aa(n,t)}}),HE=D({reverse3d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===3,function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."}),Aa(n,t)}}),jE=D({reverse4d_:function(e,t){var n=S(e,"x","reverse");return I(n.rank===4,function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."}),Aa(n,t)}});function ny(e,t,n,r,o,i){var a=S(e,"x","maxPool"),u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),r==null&&(r=[1,1]),I(u.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+u.rank+"."}),I(Ot(n,r),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"}),i!=null&&I(Ve(o),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+o+"."});var l=ma(u.shape,t,n,r,o,i);if(l.filterWidth===1&&l.filterHeight===1&&ot(l.inShape,l.outShape))return a.clone();var c=[u],f=A.runKernelFunc(function(d,h){var p=d.maxPool(u,l);return h([u,p]),p},{x:u},function(d,h){var p=h[0],m=h[1];return{x:function(){return function(g,v,y,x,w,b,C,_){var E=S(g,"dy","maxPoolBackprop"),R=S(v,"input","maxPoolBackprop"),k=S(y,"output","maxPoolBackprop");I(R.rank===E.rank,function(){return"Rank of input ("+R.rank+") does not match rank of dy ("+E.rank+")"}),b==null&&(b=[1,1]),I(Ot(w,b),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+w+" and dilations '"+b+"'"}),I(E.rank===4,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+E.rank+"."}),I(R.rank===4,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+R.rank+"."}),_!=null&&I(Ve(C),function(){return"Error in maxPoolBackprop: pad must be an integer when using, dimRoundingMode "+_+" but got pad "+C+"."});var T=ma(R.shape,x,w,b,C,_);return A.runKernelFunc(function(N){return N.maxPoolBackprop(E,R,k,T)},{$dy:E,$input:R})}(d,p,m,t,n,r,o)}}},"MaxPool",l,c);return s?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f}function ry(e,t,n,r,o,i){var a=S(e,"x","avgPool","float32");r==null&&(r=[1,1]),I(Ot(n,r),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"});var u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),I(u.rank===4,function(){return"Error in avgPool: x must be rank 4 but got rank "+u.rank+"."}),i!=null&&I(Ve(o),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+o+"."});var l=ma(u.shape,t,n,r,o,i);if(l.filterWidth===1&&l.filterHeight===1&&ot(l.inShape,l.outShape))return a.clone();var c=A.runKernelFunc(function(f){return f.avgPool(u,l)},{x:u},function(f){return{x:function(){return function(d,h,p,m,g,v){var y=S(d,"dy","avgPoolBackprop"),x=S(h,"input","avgPoolBackprop");I(x.rank===y.rank,function(){return"Rank of input ("+x.rank+") does not match rank of dy ("+y.rank+")"}),g==null&&(g=[1,1]),I(Ot(m,g),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+m+" and dilations '"+g+"'"});var w=x,b=y,C=!1;x.rank===3&&(C=!0,w=x.as4D(1,x.shape[0],x.shape[1],x.shape[2]),b=y.as4D(1,y.shape[0],y.shape[1],y.shape[2])),I(b.rank===4,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+b.rank+"."}),I(w.rank===4,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+w.rank+"."});var _=ma(w.shape,p,m,g,v),E=A.runKernelFunc(function(R){return R.avgPoolBackprop(b,w,_)},{dy4D:b,input4D:w});return C?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}(f,u,t,n,r,o)}}},"AvgPool",l);return c=c.cast(a.dtype),s?c.as3D(c.shape[1],c.shape[2],c.shape[3]):c}var tt=D({maxPool_:function(e,t,n,r,o){return ny(e,t,n,1,r,o)}}),Pa=D({avgPool_:function(e,t,n,r,o){return ry(e,t,n,1,r,o)}}),GE=D({pool_:function(e,t,n,r,o,i){o==null&&(o=[1,1]),i==null&&(i=1),r===0&&(r="valid");var a=S(e,"x","maxPool"),u=a,s=!1;a.rank===3&&(s=!0,u=a.as4D(1,a.shape[0],a.shape[1],a.shape[2])),I(Ot(i,o),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+o+"'"});var l,c=ma(u.shape,t,i,o,r),f=[c.dilationHeight,c.dilationWidth];l=r==="same"?function(w,b){var C=w.map(function(R,k){return R+(R-1)*(b[k]-1)}).map(function(R){return R-1}),_=C.map(function(R){return Math.floor(R/2)}),E=C.map(function(R,k){return R-_[k]});return C.map(function(R,k){return[_[k],E[k]]})}([c.filterHeight,c.filterWidth],f):[[0,0],[0,0]];var d=f[0]===1&&f[1]===1,h=function(w,b,C){var _=C.map(function(L){return L[0]}),E=C.map(function(L){return L[1]}),R=w.concat(_,E),k=b.map(function(L,U){return(L-R[U]%L)%L}),T=E.map(function(L,U){return L+k[U]}),N=b.map(function(L,U){return[_[U],T[U]]}),W=b.map(function(L,U){return[0,k[U]]});return[N,W]}([c.inHeight,c.inWidth],f,l),p=h[0],m=h[1],g=d?r:"valid",v=d?u:l0(u,f,p),y=(n==="avg"?function(){return ry(v,t,i,1,g)}:function(){return ny(v,t,i,1,g)})(),x=d?y:a0(y,f,m);return s?x.as3D(x.shape[1],x.shape[2],x.shape[3]):x}}),qE=D({maxPool3d_:function(e,t,n,r,o,i,a){i===void 0&&(i="NDHWC");var u=S(e,"x","maxPool3d"),s=u,l=!1;u.rank===4&&(l=!0,s=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),a==null&&(a=[1,1,1]),I(s.rank===5,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+s.rank+"."}),I(i==="NDHWC",function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+i}),I(Ot(n,a),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),o!=null&&I(Ve(r),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var c=ls(s.shape,t,n,a,r,o,i),f=A.runKernelFunc(function(d,h){var p=d.maxPool3d(s,c);return h([s,p]),p},{x:s},function(d,h){var p=h[0],m=h[1];return{x:function(){return function(g,v,y,x,w,b,C,_){var E=S(g,"dy","maxPool3dBackprop"),R=S(v,"input","maxPool3dBackprop"),k=S(y,"output","maxPool3dBackprop"),T=E,N=R,W=k,L=!1;R.rank===4&&(L=!0,T=E.as5D(1,E.shape[0],E.shape[1],E.shape[2],E.shape[3]),N=R.as5D(1,R.shape[0],R.shape[1],R.shape[2],R.shape[3]),W=k.as5D(1,k.shape[0],k.shape[1],k.shape[2],k.shape[3])),I(T.rank===5,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+T.rank+"."}),I(N.rank===5,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+N.rank+"."}),I(W.rank===5,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+W.rank+"."}),b==null&&(b=[1,1,1]),I(Ot(w,b),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+w+" and dilations '"+b+"'"}),_!=null&&I(Ve(C),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+_+" but got pad "+C+"."});var U=ls(N.shape,x,w,b,C,_),$=A.runKernelFunc(function(V){return V.maxPool3dBackprop(T,N,W,U)},{dy5D:T,input5D:N});return L?$.as4D($.shape[1],$.shape[2],$.shape[3],$.shape[4]):$}(d,p,m,t,n,a,r,o)}}});return l?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),KE=D({avgPool3d_:function(e,t,n,r,o,i,a){i===void 0&&(i="NDHWC");var u=S(e,"x","avgPool3d","float32"),s=u,l=!1;u.rank===4&&(l=!0,s=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),a==null&&(a=[1,1,1]),I(s.rank===5,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+s.rank+"."}),I(i==="NDHWC",function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+i}),I(Ot(n,a),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),o!=null&&I(Ve(r),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var c=ls(s.shape,t,n,a,r,o,i),f=A.runKernelFunc(function(d){return d.avgPool3d(s,c)},{x:s},function(d){return{x:function(){return function(h,p,m,g,v,y,x){var w=S(h,"dy","avgPool3dBackprop"),b=S(p,"input","avgPool3dBackprop"),C=w,_=b,E=!1;b.rank===4&&(E=!0,C=w.as5D(1,w.shape[0],w.shape[1],w.shape[2],w.shape[3]),_=b.as5D(1,b.shape[0],b.shape[1],b.shape[2],b.shape[3])),I(C.rank===5,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+C.rank+"."}),I(_.rank===5,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+_.rank+"."}),v==null&&(v=[1,1,1]),I(Ot(g,v),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+g+" and dilations '"+v+"'"}),x!=null&&I(Ve(y),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+x+" but got pad "+y+"."});var R=ls(_.shape,m,g,v,y,x),k=A.runKernelFunc(function(T){return T.avgPool3dBackprop(C,_,R)},{dy5D:C,input5D:_});return E?k.as4D(k.shape[1],k.shape[2],k.shape[3],k.shape[4]):k}(d,s,t,n,a,r,o)}}});return f=f.cast(s.dtype),l?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),Ln=D({slice_:function(e,t,n){var r,o,i=S(e,"x","slice");if(i.rank===0)throw new Error("Slicing scalar is not possible");(r=typeof t=="number"?[t].concat(new Array(i.rank-1).fill(0)):t.length=0?s:(I(s===-1,function(){return"Negative size values should be exactly -1 but got "+s+" for the slice() size at index "+l+"."}),i.shape[l]-r[l])}),Cb(i,r,o);var a=i.shape,u={begin:r,size:o};return A.runKernelFunc(function(s){return s.slice(i,r,o)},{x:i},function(s){for(var l=[],c=0;c0&&(l=l.sum(c)),l.reshape(u.shape)}}},"Prelu")}}),Me=D({relu_:function(e){var t=S(e,"x","relu");return t.dtype==="bool"?t.toInt():A.runKernelFunc(function(n,r){var o=n.relu(t);return r([t]),o},{x:t},function(n,r){var o=r[0];return{x:function(){return n.mulStrict(o.step().toFloat())}}},"Relu")}}),ly=D({relu6_:function(e){var t=S(e,"x","relu6");return t.dtype==="bool"?t.toInt():A.runKernelFunc(function(n,r){var o=n.relu6(t);return r([t]),o},{x:t},function(n,r){var o=r[0],i=o.lessEqual(6).mul(o.step());return{x:function(){return n.mulStrict(i.toFloat())}}},"Relu6")}}),sS=D({selu_:function(e){var t=S(e,"x","selu");return A.runKernelFunc(function(n,r){var o=n.selu(t);return r([t]),o},{$x:t},function(n,r){var o=r[0];return{$x:function(){var i=o.greater(K(0)),a=K(Rd),u=K(Id),s=n.mul(u),l=n.mul(a).mul(o.toFloat().exp());return po(i,s,l)}}})}}),Wr=D({transpose_:function(e,t){var n=S(e,"x","transpose");if(t==null&&(t=n.shape.map(function(o,i){return i}).reverse()),I(n.rank===t.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+t+"."}),t.forEach(function(o){I(o>=0&&oo)throw new Error("'k' passed to topk() must be <= the last dimension ("+o+") but got "+t);var i=A.runKernelFunc(function(a){return a.topk(r,t,n)},{$x:r});return{values:i[0],indices:i[1]}}}),vS=D({scatterND_:function(e,t,n){var r=S(e,"indices","scatterND","int32"),o=S(t,"updates","scatterND");return bb(o,r,n),A.runKernelFunc(function(i){return i.scatterND(r,o,n)},{indices:r,updates:o},null,"ScatterNd",{shape:n})}}),Fd=D({fft_:function(e){I(e.dtype==="complex64",function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+e.dtype+"."});var t=e.shape[e.shape.length-1],n=e.size/t,r=e.as2D(n,t);return A.runKernelFunc(function(o){return o.fft(r)},{input:e}).reshape(e.shape)}}),ps=D({ifft_:function(e){I(e.dtype==="complex64",function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+e.dtype+"."});var t=e.shape[e.shape.length-1],n=e.size/t,r=e.as2D(n,t);return A.runKernelFunc(function(o){return o.ifft(r)},{input:e}).reshape(e.shape)}}),Md=D({rfft_:function(e,t){I(e.dtype==="float32",function(){return"The dtype for rfft() must be real value but got "+e.dtype});var n,r=e.shape[e.shape.length-1],o=e.size/r;if(t!=null&&tr){var u=e.shape.map(function(v){return v});u[e.shape.length-1]=t-r,n=e.concat(Ie(u),e.shape.length-1),r=t}else n=e;var s=n.zerosLike(),l=ut(n,s).as2D(o,r),c=Fd(l),f=Math.floor(r/2)+1,d=en(c),h=Nn(c),p=d.split([f,r-f],d.shape.length-1),m=h.split([f,r-f],h.shape.length-1),g=n.shape.slice();return g[n.shape.length-1]=f,ut(p[0],m[0]).reshape(g)}}),fy=D({irfft_:function(e){var t=e.shape[e.shape.length-1],n=e.size/t;if(t<=2){var r=e.as2D(n,t),o=ps(r);return en(o)}var i=[n,2*(t-1)],a=en(e).as2D(n,t),u=Nn(e).as2D(n,t),s=a.slice([0,1],[n,t-2]).reverse(1),l=u.slice([0,1],[n,t-2]).reverse(1).mul(K(-1)),c=a.concat(s,1),f=u.concat(l,1);return r=ut(c,f).as2D(i[0],i[1]),o=ps(r),en(o)}}),mS=Object.freeze({fft:Fd,ifft:ps,rfft:Md,irfft:fy}),gS=D({sparseToDense_:function(e,t,n,r){r===void 0&&(r=0);var o=S(e,"sparseIndices","sparseToDense","int32"),i=S(t,"sparseValues","sparseToDense"),a=S(r,"defaultValue","sparseToDense",i.dtype);return function(u,s,l,c){if(u.dtype!=="int32")throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+u.dtype+".");if(u.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+u.shape+".");var f=u.rank>0?u.shape[0]:1,d=u.rank>1?u.shape[1]:1;if(l.length!==d)throw new Error("outputShape has incorrect number of elements:, "+l.length+", should be: "+d+".");var h=s.size;if(s.rank!==0&&(s.rank!==1||h!==f))throw new Error("sparseValues has incorrect shape "+s.shape+", should be [] or ["+f+"]");if(s.dtype!==c.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(o,i,n,a),A.runKernelFunc(function(u){return u.sparseToDense(o,i,n,a)},{$sparseIndices:o,$sparseValues:i,$defaultValue:a})}}),yS=D({gatherND_:function(e,t){var n=S(t,"indices","gatherND","int32"),r=S(e,"x","gatherND");return A.runKernelFunc(function(o){return o.gatherND(r,n)},{x:r,indices:n},null,"GatherNd")}}),xS=D({diag_:function(e){var t=S(e,"x","diag").flatten(),n=e.shape.concat(e.shape);return A.runKernelFunc(function(r){return r.diag(t)},{$x:t}).reshape(n)}}),wS=D({dropout_:function(e,t,n,r){var o=S(e,"x","dropout");if(I(o.dtype==="float32",function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+o.dtype+" tensor instead."}),I(t>=0&&t<1,function(){return"rate must be a float in the range [0, 1), but got "+t+"."}),t===0)return e instanceof Fe?o.clone():o;var i=function(s,l){if(l==null)return s.shape.slice();if(ot(s.shape,l))return l;if(s.shape.length===l.length){for(var c=[],f=0;f1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank}),I(r.rank-1===o.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+o.rank}),Ce(r.shape.slice(0,r.shape.length-1),o.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),i=r.shape[r.shape.length-1],I(n>0&&n<=i,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+i+"), but got "+n}),[4,r.data()];case 1:return a=v.sent(),[4,o.data()];case 2:for(u=v.sent(),s=[a.length/i,i],c=s[1],f=ha("bool",l=s[0]),d=0;d1?u.div(K(a)):u}if(n===yt.SUM_BY_NONZERO_WEIGHTS){if(o==null)return i.sum().div(K(r.size));var s=o.mul(wi(r.shape)).notEqual(K(0)).sum().toFloat();return i.sum().div(s)}throw Error("Unknown reduction: "+n)}}),ES=D({cosineDistance_:function(e,t,n,r,o){o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","cosineDistance"),a=S(t,"predictions","cosineDistance"),u=null;r!=null&&(u=S(r,"weights","cosineDistance")),Ce(i.shape,a.shape,"Error in cosineDistance: ");var s=K(1).sub(i.mul(a).sum(n,!0));return lr(s,u,o)}}),SS=D({hingeLoss_:function(e,t,n,r){r===void 0&&(r=yt.SUM_BY_NONZERO_WEIGHTS);var o=S(e,"labels","hingeLoss"),i=S(t,"predictions","hingeLoss"),a=null;n!=null&&(a=S(n,"weights","hingeLoss")),Ce(o.shape,i.shape,"Error in hingeLoss: ");var u=K(1);o=K(2).mul(o).sub(u);var s=u.sub(o.mul(i)).relu();return lr(s,a,r)}}),kS=D({huberLoss_:function(e,t,n,r,o){r===void 0&&(r=1),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","huberLoss"),a=S(t,"predictions","huberLoss"),u=null;n!=null&&(u=S(n,"weights","huberLoss")),Ce(i.shape,a.shape,"Error in huberLoss: ");var s=K(r),l=a.sub(i).abs(),c=q0(l,s),f=l.sub(c),d=K(.5).mul(c.square()).add(s.mul(f));return lr(d,u,o)}}),RS=D({logLoss_:function(e,t,n,r,o){r===void 0&&(r=1e-7),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"labels","logLoss"),a=S(t,"predictions","logLoss"),u=null;n!=null&&(u=S(n,"weights","logLoss")),Ce(i.shape,a.shape,"Error in logLoss: ");var s=K(1),l=K(r),c=i.mul(a.add(l).log()).neg().sub(s.sub(i).mul(s.sub(a).add(l).log()));return lr(c,u,o)}}),IS=D({meanSquaredError_:function(e,t,n,r){r===void 0&&(r=yt.SUM_BY_NONZERO_WEIGHTS);var o=S(e,"labels","meanSquaredError"),i=S(t,"predictions","meanSquaredError"),a=null;n!=null&&(a=S(n,"weights","meanSquaredError")),Ce(o.shape,i.shape,"Error in meanSquaredError: ");var u=o.squaredDifference(i);return lr(u,a,r)}}),DS=D({sigmoidCrossEntropy_:function(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"multiClassLabels","sigmoidCrossEntropy"),a=S(t,"logits","sigmoidCrossEntropy"),u=null;if(n!=null&&(u=S(n,"weights","sigmoidCrossEntropy")),Ce(i.shape,a.shape,"Error in sigmoidCrossEntropy: "),r>0){var s=K(r),l=K(1),c=K(.5);i=i.mul(l.sub(s)).add(c.mul(s))}var f=function(d,h){var p=S(d,"labels","sigmoidCrossEntropyWithLogits"),m=S(h,"logits","sigmoidCrossEntropyWithLogits");Ce(p.shape,m.shape,"Error in sigmoidCrossEntropyWithLogits: ");var g=m.relu(),v=m.mul(p),y=m.abs().neg().exp().log1p();return g.sub(v).add(y)}(i,a);return lr(f,u,o)}}),TS=D({softmaxCrossEntropy_:function(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=yt.SUM_BY_NONZERO_WEIGHTS);var i=S(e,"onehotLabels","softmaxCrossEntropy"),a=S(t,"logits","softmaxCrossEntropy"),u=null;if(n!=null&&(u=S(n,"weights","softmaxCrossEntropy")),Ce(i.shape,a.shape,"Error in softmaxCrossEntropy: "),r>0){var s=K(r),l=K(1),c=K(i.shape[1]);i=i.mul(l.sub(s)).add(s.div(c))}var f=function(d,h,p){if(p===void 0&&(p=-1),p===-1&&(p=h.rank-1),p!==h.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+h.rank+" and dim was "+p);return Ls(function(m,g,v){var y=g.logSumExp([p],!0),x=g.toFloat().sub(y);return v([m,x]),{value:x.mul(m).neg().sum([p]),gradFunc:function(w,b){var C=b[0],_=b[1],E=Mt(w.shape,[p]);return[w.reshape(E).mul(C.toFloat().sub(_.exp())),w.reshape(E).mul(_.exp().sub(C.toFloat()))]}}})(d,h)}(i,a);return lr(f,u,o)}}),NS=Object.freeze({get Reduction(){return yt},absoluteDifference:_S,computeWeightedLoss:lr,cosineDistance:ES,hingeLoss:SS,huberLoss:kS,logLoss:RS,meanSquaredError:IS,sigmoidCrossEntropy:DS,softmaxCrossEntropy:TS});function av(e,t){return t===void 0&&(t=!1),A.tidy(function(){if(e.shape.length!==2)throw new Error("qr2d() requires a 2D Tensor, but got a "+e.shape.length+"D Tensor.");for(var n=e.shape[0],r=e.shape[1],o=u0(n),i=e.clone(),a=Fr([[1]],[1,1]),u=a.clone(),s=n>=r?r:n,l=function(f){var d,h=i,p=u,m=o;d=A.tidy(function(){var g=i.slice([f,f],[n-f,1]),v=g.norm(),y=i.slice([f,f],[1,1]),x=Fr([[-1]]).where(y.greater(0),Fr([[1]])),w=y.sub(x.mul(v)),b=g.div(w);u=b.shape[0]===1?a.clone():a.concat(b.slice([1,0],[b.shape[0]-1,b.shape[1]]),0);var C=x.matMul(w).div(v).neg(),_=i.slice([f,0],[n-f,r]),E=C.mul(u);if(f===0)i=_.sub(E.matMul(u.transpose().matMul(_)));else{var R=_.sub(E.matMul(u.transpose().matMul(_)));i=i.slice([0,0],[f,r]).concat(R,0)}var k=o.slice([0,f],[n,o.shape[1]-f]);if(f===0)o=k.sub(k.matMul(u).matMul(E.transpose()));else{var T=k.sub(k.matMul(u).matMul(E.transpose()));o=o.slice([0,0],[n,f]).concat(T,1)}return[u,i,o]}),u=d[0],i=d[1],o=d[2],Ft([h,p,m])},c=0;cr&&(o=o.slice([0,0],[n,r]),i=i.slice([0,0],[r,r])),[o,i]})}var AS=D({bandPart_:function(e,t,n){if(t%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+t+".");if(n%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+n+".");var r=S(e,"a","bandPart");if(r.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+r.rank+".");var o=r.shape,i=r.shape.slice(-2),a=i[0],u=i[1];if(!(t<=a))throw new Error("bandPart(): numLower ("+t+") must not be greater than the number of rows ("+a+").");if(!(n<=u))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+u+").");t<0&&(t=a),n<0&&(n=u);var s=os(0,a,1,"int32").reshape([-1,1]),l=os(0,u,1,"int32"),c=Ze(s,l),f=zs(c.lessEqual(K(+t,"int32")),c.greaterEqual(K(-n,"int32"))),d=Ie([a,u],r.dtype);return Gt(Qe(r.reshape([-1,a,u])).map(function(h){return po(f,h,d)})).reshape(o)}}),PS=D({gramSchmidt_:function(e){var t;if(Array.isArray(e)){t=!1,I(e!=null&&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(s){I(e[s].shape[0]===n,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+e[s].shape[0]+" vs. "+n+")"})},o=1;o0)for(var c=0;c= 2, but got rank "+e.rank);if(e.rank===2)return av(e,t);var n=e.shape.slice(0,e.shape.length-2).reduce(function(a,u){return a*u}),r=Qe(e.reshape([n,e.shape[e.shape.length-2],e.shape[e.shape.length-1]]),0),o=[],i=[];return r.forEach(function(a){var u=av(a,t),s=u[0],l=u[1];o.push(s),i.push(l)}),[Gt(o,0).reshape(e.shape),Gt(i,0).reshape(e.shape)]}}),MS=Object.freeze({bandPart:AS,gramSchmidt:PS,qr:FS});function Hs(e,t,n,r,o,i){r==null&&(r=.5),o==null&&(o=Number.NEGATIVE_INFINITY),i==null&&(i=0);var a=e.shape[0];return n=Math.min(n,a),I(0<=r&&r<=1,function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"}),I(e.rank===2,function(){return"boxes must be a 2D tensor, but was of rank '"+e.rank+"'"}),I(e.shape[1]===4,function(){return"boxes must have 4 columns, but 2nd dimension was "+e.shape[1]}),I(t.rank===1,function(){return"scores must be a 1D tensor"}),I(t.shape[0]===a,function(){return"scores has incompatible shape with boxes. Expected "+a+", but was "+t.shape[0]}),I(0<=i&&i<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+i+"'"}),{maxOutputSize:n,iouThreshold:r,scoreThreshold:o,softNmsSigma:i}}var OS=D({resizeBilinear_:function(e,t,n){n===void 0&&(n=!1);var r=S(e,"images","resizeBilinear");I(r.rank===3||r.rank===4,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+r.rank+"."}),I(t.length===2,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+t+"."});var o=r,i=!1;r.rank===3&&(i=!0,o=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var a=t[0],u=t[1],s=A.runKernelFunc(function(l,c){return c([o]),l.resizeBilinear(o,a,u,n)},{x:o},function(l,c){return{x:function(){return A.runKernelFunc(function(f){return f.resizeBilinearBackprop(l,c[0],n)},{})}}},"ResizeBilinear",{alignCorners:n,newHeight:a,newWidth:u});return i?s.as3D(s.shape[1],s.shape[2],s.shape[3]):s}}),BS=D({resizeNearestNeighbor_:function(e,t,n){n===void 0&&(n=!1);var r=S(e,"images","resizeNearestNeighbor");I(r.rank===3||r.rank===4,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+r.rank+"."}),I(t.length===2,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+t+"."}),I(r.dtype==="float32"||r.dtype==="int32",function(){return"`images` must have `int32` or `float32` as dtype"});var o=r,i=!1;r.rank===3&&(i=!0,o=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var a=t[0],u=t[1],s=A.runKernelFunc(function(l,c){return c([o]),l.resizeNearestNeighbor(o,a,u,n)},{batchImages:o},function(l,c){return{batchImages:function(){return A.runKernelFunc(function(f){return f.resizeNearestNeighborBackprop(l,c[0],n)},{})}}});return i?s.as3D(s.shape[1],s.shape[2],s.shape[3]):s}}),LS=D({nonMaxSuppression_:function(e,t,n,r,o){r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY);var i=S(e,"boxes","nonMaxSuppression"),a=S(t,"scores","nonMaxSuppression"),u=Hs(i,a,n,r,o);n=u.maxOutputSize,r=u.iouThreshold,o=u.scoreThreshold;var s={maxOutputSize:n,iouThreshold:r,scoreThreshold:o};return A.runKernelFunc(function(l){return l.nonMaxSuppression(i,a,n,r,o)},{boxes:i,scores:a},null,"NonMaxSuppressionV3",s)}}),WS=function(e,t,n,r,o){return r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),Q(this,void 0,void 0,function(){var i,a,u,s,l,c,f;return J(this,function(d){switch(d.label){case 0:return i=S(e,"boxes","nonMaxSuppressionAsync"),a=S(t,"scores","nonMaxSuppressionAsync"),u=Hs(i,a,n,r,o),n=u.maxOutputSize,r=u.iouThreshold,o=u.scoreThreshold,[4,Promise.all([i.data(),a.data()])];case 1:return s=d.sent(),l=s[0],c=s[1],f=_d(l,c,n,r,o),i!==e&&i.dispose(),a!==t&&a.dispose(),[2,f]}})})},zS=D({nonMaxSuppressionWithScore_:function(e,t,n,r,o,i){r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),i===void 0&&(i=0);var a=S(e,"boxes","nonMaxSuppression"),u=S(t,"scores","nonMaxSuppression"),s=Hs(a,u,n,r,o,i),l={maxOutputSize:n=s.maxOutputSize,iouThreshold:r=s.iouThreshold,scoreThreshold:o=s.scoreThreshold,softNmsSigma:i=s.softNmsSigma},c=A.runKernel("NonMaxSuppressionV5",{boxes:a,scores:u},l);return{selectedIndices:c[0],selectedScores:c[1]}}}),US=function(e,t,n,r,o,i){return r===void 0&&(r=.5),o===void 0&&(o=Number.NEGATIVE_INFINITY),i===void 0&&(i=0),Q(this,void 0,void 0,function(){var a,u,s,l,c,f,d;return J(this,function(h){switch(h.label){case 0:return a=S(e,"boxes","nonMaxSuppressionAsync"),u=S(t,"scores","nonMaxSuppressionAsync"),s=Hs(a,u,n,r,o,i),n=s.maxOutputSize,r=s.iouThreshold,o=s.scoreThreshold,i=s.softNmsSigma,[4,Promise.all([a.data(),u.data()])];case 1:return l=h.sent(),c=l[0],f=l[1],d=Ed(c,f,n,r,o,i),a!==e&&a.dispose(),u!==t&&u.dispose(),[2,d]}})})},VS=D({cropAndResize_:function(e,t,n,r,o,i){var a=S(e,"image","cropAndResize"),u=S(t,"boxes","cropAndResize","float32"),s=S(n,"boxInd","cropAndResize","int32");o=o||"bilinear",i=i||0;var l=u.shape[0];return I(a.rank===4,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+a.rank+"."}),I(u.rank===2&&u.shape[1]===4,function(){return"Error in cropAndResize: boxes must be have size ["+l+",4] but had shape "+u.shape+"."}),I(s.rank===1&&s.shape[0]===l,function(){return"Error in cropAndResize: boxInd must be have size ["+l+"] but had shape "+u.shape+"."}),I(r.length===2,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."}),I(r[0]>=1&&r[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+r}),I(o==="bilinear"||o==="nearest",function(){return"method must be bilinear or nearest, but was "+o}),A.runKernelFunc(function(c,f){return c.cropAndResize(a,u,s,r,o,i)},{images:a,boxes:u,boxInd:s},null,"CropAndResize",{method:o,extrapolationValue:i,cropSize:r})}}),Ld=Object.freeze({resizeBilinear:OS,resizeNearestNeighbor:BS,nonMaxSuppression:LS,nonMaxSuppressionAsync:WS,nonMaxSuppressionWithScore:zS,nonMaxSuppressionWithScoreAsync:US,cropAndResize:VS}),Wd=function(e,t){return!(e>0)||t==="linear"},zd=function(e,t,n){if(n==null||n==="linear")return e;if(n==="relu")return e.mul(t.step());throw new Error("Gradient for activation "+n+" has not been implemented yet.")},Ud=function(e,t){var n=t,r=Je(e.shape,t.shape);return r.length>0&&(n=n.sum(r)),n.reshape(e.shape)},Vd=function(e,t,n){if(t==="linear")return e;if(t==="relu")return Me(e);if(t==="elu")return uy(e);if(t==="relu6")return ly(e);if(t==="prelu")return sy(e,n);throw new Error("Unknown fused activation "+t+".")},$S=D({fusedMatMul_:function(e){var t,n=e.a,r=e.b,o=e.transposeA,i=o!==void 0&&o,a=e.transposeB,u=a!==void 0&&a,s=e.bias,l=e.activation,c=l===void 0?"linear":l,f=e.preluActivationWeights;if(Wd(A.state.gradientDepth,c)===!1){var d=Vs(n,r,i,u);return s!=null&&(d=de(d,s)),Vd(d,c,f)}var h=S(n,"a","fused matMul"),p=S(r,"b","fused matMul");t=Le(h,p),h=t[0],p=t[1];var m=i?h.shape[h.rank-2]:h.shape[h.rank-1],g=u?p.shape[p.rank-1]:p.shape[p.rank-2],v=i?h.shape[h.rank-1]:h.shape[h.rank-2],y=u?p.shape[p.rank-2]:p.shape[p.rank-1],x=h.shape.slice(0,-2),w=p.shape.slice(0,-2),b=Z(x),C=Z(w);I(h.rank>=2&&p.rank>=2&&h.rank===p.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+h.rank+" and "+p.rank+"."}),I(ot(x,w),function(){return"Error in fused matMul: outer dimensions ("+x+") and ("+w+") of Tensors with shapes "+h.shape+" and "+p.shape+" must match."}),I(m===g,function(){return"Error in fused matMul: inner shapes ("+m+") and ("+g+") of Tensors with shapes "+h.shape+" and "+p.shape+" and transposeA="+i+" and transposeB="+u+" must match."});var _,E,R=h.shape.slice(0,-2).concat([v,y]),k=i?h.as3D(b,m,v):h.as3D(b,v,m),T=u?p.as3D(C,y,g):p.as3D(C,g,y);s!=null&&he(R,(_=Le(_=S(s,"bias","fused matMul"),h)[0]).shape),f!=null&&(E=S(f,"prelu weights","fused matMul"));var N={a:k,b:T};s!=null&&(N.bias=_),f!=null&&(N.preluActivationWeights=E);var W=[k,T];return A.runKernelFunc(function(L,U){var $=L.fusedBatchMatMul({a:k,b:T,transposeA:i,transposeB:u,bias:_,activation:c,preluActivationWeights:E});return U([k,T,$]),$},N,function(L,U){var $=U[0],V=U[1],P=U[2],M=zd(L,P,c),B={};return s!=null&&(B={bias:function(){return Ud(_,M)}}),Object.assign(i||u?!i&&u?{a:function(){return M.matMul(V,!1,!1)},b:function(){return M.matMul($,!0,!1)}}:i&&!u?{a:function(){return V.matMul(M,!1,!0)},b:function(){return $.matMul(M,!1,!1)}}:{a:function(){return V.matMul(M,!0,!0)},b:function(){return M.matMul($,!0,!0)}}:{a:function(){return M.matMul(V,!1,!0)},b:function(){return $.matMul(M,!0,!1)}},B)},"_FusedMatMul",{transposeA:i,transposeB:u,activation:c},W,[!0]).reshape(R)}}),HS=D({fusedConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,o=e.pad,i=e.dataFormat,a=i===void 0?"NHWC":i,u=e.dilations,s=u===void 0?[1,1]:u,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=f===void 0?"linear":f,h=e.preluActivationWeights;if(d=d||"linear",Wd(A.state.gradientDepth,d)===!1){var p=un(t,n,r,o,a,s,l);return c!=null&&(p=de(p,c)),Vd(p,d,h)}var m=S(t,"x","conv2d"),g=S(n,"filter","conv2d"),v=m,y=!1;m.rank===3&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),I(v.rank===4,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+v.rank+"."}),I(g.rank===4,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+g.rank+"."}),l!=null&&I(Ve(o),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+l+" but got pad "+o+"."}),I(v.shape[3]===g.shape[2],function(){return"Error in conv2d: depth of input ("+v.shape[3]+") must match input depth for filter "+g.shape[2]+"."}),I(Ot(r,s),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+s+"'"}),I(a==="NHWC",function(){return"Error in conv2d: got dataFormat of "+a+" but only NHWC is currently supported."});var x,w,b=xo(v.shape,g.shape,r,s,o,l);c!=null&&(x=Le(x=S(c,"bias","fused conv2d"),m)[0],he(b.outShape,x.shape)),h!=null&&(w=S(h,"prelu weights","fused conv2d"));var C={x:v,filter:g};c!=null&&(C.bias=x),h!=null&&(C.preluActivationWeights=w);var _=[g,v],E=A.runKernelFunc(function(R,k){var T=R.fusedConv2d({input:v,filter:g,convInfo:b,bias:x,activation:d,preluActivationWeights:w});return k([g,v,T]),T},C,function(R,k){var T=k,N=T[0],W=T[1],L=T[2],U=zd(R,L,d);I(vi(s),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+s+"'"});var $={};return c!=null&&($={bias:function(){return Ud(x,U)}}),Object.assign({x:function(){return Z0(W.shape,U,N,r,o)},filter:function(){return Ad(W,U,N.shape,r,o)}},$)},"FusedConv2D",{convInfo:b,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),jS=D({fusedDepthwiseConv2d_:function(e){var t=e.x,n=e.filter,r=e.strides,o=e.pad,i=e.dataFormat,a=i===void 0?"NHWC":i,u=e.dilations,s=u===void 0?[1,1]:u,l=e.dimRoundingMode,c=e.bias,f=e.activation,d=f===void 0?"linear":f,h=e.preluActivationWeights;if(Wd(A.state.gradientDepth,d)===!1){var p=Us(t,n,r,o,a,s,l);return c!=null&&(p=de(p,c)),Vd(p,d,h)}var m=S(t,"x","depthwiseConv2d"),g=S(n,"filter","depthwiseConv2d"),v=m,y=!1;m.rank===3&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),I(v.rank===4,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+v.rank+"."}),I(g.rank===4,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+g.rank+"."}),I(v.shape[3]===g.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+v.shape[3]+") must match the inChannels dimension in filter "+g.shape[2]+"."}),s==null&&(s=[1,1]),I(Ot(r,s),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+s+"'"}),l!=null&&I(Ve(o),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+l+" but got pad "+o+"."});var x,w,b=xo(v.shape,g.shape,r,s,o,l,!0);c!=null&&(x=Le(x=S(c,"bias","fused conv2d"),m)[0],he(b.outShape,x.shape)),h!=null&&(w=S(h,"prelu weights","fused depthwiseConv2d"));var C={x:v,filter:g};c!=null&&(C.bias=x),h!=null&&(C.preluActivationWeights=w);var _=[g,v],E=A.runKernelFunc(function(R,k){var T=R.fusedDepthwiseConv2D({input:v,filter:g,convInfo:b,bias:x,activation:d,preluActivationWeights:w});return k([g,v,T]),T},C,function(R,k){I(vi(s),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+s+"'"});var T=k[0],N=k[1],W=k[2],L=zd(R,W,d),U={};return c!=null&&(U={bias:function(){return Ud(x,L)}}),Object.assign({x:function(){return ey(N.shape,L,T,b)},filter:function(){return ty(N,L,T.shape,b)}},U)},"FusedDepthwiseConv2D",{convInfo:b,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),GS=Object.freeze({matMul:$S,conv2d:HS,depthwiseConv2d:jS}),qS=Object.freeze({image:Ld,linalg:MS,losses:NS,spectral:mS,fused:GS,signal:bS,square:R_,squaredDifference:B0,conv1d:OE,conv2d:un,conv3d:BE,depthwiseConv2d:Us,separableConv2d:Pd,conv2dTranspose:LE,conv3dTranspose:WE,op:D,batchNormalization2d:rE,batchNormalization3d:oE,batchNormalization4d:iE,batchNormalization:aE,batchNorm:$0,batchNorm2d:uE,batchNorm3d:sE,batchNorm4d:lE,booleanMaskAsync:ME,complex:ut,real:en,imag:Nn,concat:Ye,concat1d:G2,concat2d:q2,concat3d:K2,concat4d:X2,split:xd,matMul:Vs,dot:zE,outerProduct:UE,reverse:Aa,reverse1d:VE,reverse2d:$E,reverse3d:HE,reverse4d:jE,maxPool:tt,avgPool:Pa,pool:GE,maxPool3d:qE,avgPool3d:KE,slice:Ln,slice1d:XE,slice2d:YE,slice3d:oy,slice4d:QE,abs:I_,acos:D_,acosh:T_,asin:N_,asinh:A_,atan:P_,atanh:F_,ceil:M_,clipByValue:Dd,cos:O_,cosh:B_,erf:L_,exp:df,expm1:W_,floor:z_,log:U_,log1p:V_,logSigmoid:$_,neg:ds,reciprocal:H_,round:j_,rsqrt:L0,sigmoid:W0,sign:G_,isNaN:q_,isInf:K_,isFinite:X_,sin:Y_,sinh:Q_,softplus:J_,sqrt:Z_,step:eE,tan:tE,tanh:nE,all:JE,any:ZE,argMax:eS,argMin:tS,logSumExp:nS,max:$s,mean:rS,min:oS,moments:iS,sum:ay,prod:aS,equal:K0,equalStrict:SE,greater:kE,greaterEqual:X0,greaterEqualStrict:RE,greaterStrict:IE,less:DE,lessEqual:TE,lessEqualStrict:NE,lessStrict:AE,notEqual:PE,notEqualStrict:FE,add:de,addN:dE,addStrict:hE,atan2:pE,div:hn,divNoNan:vE,divStrict:mE,floorDiv:G0,maximum:Td,maximumStrict:gE,minimum:q0,minimumStrict:yE,mod:xE,modStrict:wE,mul:xt,mulStrict:bE,pow:hs,powStrict:CE,squaredDifferenceStrict:_E,sub:Ze,subStrict:EE,elu:uy,leakyRelu:uS,prelu:sy,relu:Me,relu6:ly,selu:sS,logicalAnd:zs,logicalNot:cE,logicalOr:H0,logicalXor:fE,where:po,whereAsync:j0,buffer:se,print:ob,batchToSpaceND:a0,broadcastTo:ib,cast:ab,clone:ub,cumsum:sb,depthToSpace:lb,expandDims:Zt,eye:u0,multinomial:cb,oneHot:sf,pad:yo,pad1d:fb,pad2d:db,pad3d:hb,pad4d:pb,rand:vb,randomNormal:mb,randomGamma:gb,randomUniform:s0,reshape:pn,spaceToBatchND:l0,squeeze:c0,stack:Gt,tile:Zo,truncatedNormal:yb,unstack:Qe,setdiff1dAsync:xb,fill:Bn,linspace:j2,ones:wi,range:os,scalar:K,tensor:lt,tensor1d:Ge,tensor2d:Fr,tensor3d:yd,tensor4d:Rt,tensor5d:V2,tensor6d:$2,variable:H2,zeros:Ie,onesLike:i0,zerosLike:ye,transpose:Wr,softmax:sr,logSoftmax:kb,localResponseNormalization:lS,norm:cy,gather:Nd,unsortedSegmentSum:Y0,basicLSTMCell:cS,multiRNNCell:fS,movingAverage:dS,stridedSlice:hS,topk:pS,scatterND:vS,fft:Fd,ifft:ps,rfft:Md,irfft:fy,sparseToDense:gS,gatherND:yS,diag:xS,dropout:wS,hannWindow:Od,hammingWindow:hy,frame:Bd,stft:py,inTopKAsync:CS});function H(e,t){Array.isArray(e)||(e=[e]),e.forEach(function(n){n!=null&&I(n.dtype!=="complex64",function(){return t+" does not support complex64 tensors."})})}function ql(e,t,n,r){if(n==="linear")return e.linear(t);if(n==="relu")return e.relu(t);if(n==="elu")return e.elu(t);if(n==="relu6")return e.relu6(t);if(n==="prelu")return e.prelu(t,r);throw new Error("Activation "+n+" has not been implemented for the CPU backend.")}var KS=function(e){function t(){var n=e.call(this)||this;return n.blockSize=48,n.firstUse=!0,n.data=new g0(n,A),n}return xn(t,e),t.prototype.write=function(n,r,o){this.firstUse&&(this.firstUse=!1,z().get("IS_NODE")&&ns(` ============================ Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details. -============================`));var i={};return this.data.set(i,{values:n,dtype:o}),i},t.prototype.move=function(n,r,o,i){this.data.set(n,{values:r,dtype:i})},t.prototype.numDataIds=function(){return this.data.numDataIds()},t.prototype.read=function(n){return Q(this,void 0,void 0,function(){return J(this,function(r){return[2,this.readSync(n)]})})},t.prototype.readSync=function(n){var r=this.data.get(n),o=r.dtype,i=r.complexTensors;return o==="complex64"?hf(this.readSync(i.real.dataId),this.readSync(i.imag.dataId)):this.data.get(n).values},t.prototype.bufferSync=function(n){var r=this.readSync(n.dataId),o=r;if(n.dtype==="string")try{o=r.map(function(i){return ns(i)})}catch{throw new Error("Failed to decode encoded string bytes into utf-8")}return se(n.shape,n.dtype,o)},t.prototype.makeOutput=function(n,r,o){var i=this.write(n,r,o);return A.makeTensorFromDataId(i,r,o,this)},t.prototype.disposeData=function(n){if(this.data.has(n)){var r=this.data.get(n).complexTensors;r!=null&&(r.real.dispose(),r.imag.dispose()),this.data.delete(n)}},t.prototype.time=function(n){return Q(this,void 0,void 0,function(){var r;return J(this,function(o){return r=Dn(),n(),[2,{kernelMs:Dn()-r}]})})},t.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},t.prototype.complex=function(n,r){var o=this.makeOutput(null,n.shape,"complex64");return this.data.get(o.dataId).complexTensors={real:A.keep(n.clone()),imag:A.keep(r.clone())},o},t.prototype.real=function(n){return this.data.get(n.dataId).complexTensors.real.clone()},t.prototype.imag=function(n){return this.data.get(n.dataId).complexTensors.imag.clone()},t.prototype.slice=function(n,r,o){if(H(n,"slice"),x0(n.shape,r,o)){var i=w0(r,n.strides),a=Z(o);return lt(this.readSync(n.dataId).subarray(i,i+a),o,n.dtype)}for(var u=se(o,n.dtype),s=this.bufferSync(n),l=0;lp&&(p=v,m=g)}c[d]=m}return s},t.prototype.cumsum=function(n,r,o,i){if(H(n,"cumsum"),r!==n.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(n.rank-1)+" but got axis="+r);for(var a=st(n.dtype,"int32"),u=Ie(n.shape,a),s=this.readSync(u.dataId),l=this.readSync(n.dataId),c=n.shape[n.rank-1],f=i?function(g,v){return g+c-v-1}:function(g,v){return g+v},d=0;di?1:0})},t.prototype.greaterEqual=function(n,r){return H([n,r],"greaterEqual"),this.broadcastedBinaryOp(n,r,"bool",function(o,i){return o>=i?1:0})},t.prototype.logicalNot=function(n){H(n,"logicalNot");for(var r=this.readSync(n.dataId),o=new Uint8Array(r.length),i=0;i1||r.rank===1?1:Z(r.shape.slice(1)),d=0;d=0&&i>=0?a:(a+i)%i})},t.prototype.max=function(n,r){H(n,"max"),Wt("max",r,n.rank);for(var o=pt(n.shape,r),i=o[0],a=o[1],u=Ie(i,n.dtype),s=Z(a),l=this.readSync(u.dataId),c=this.readSync(n.dataId),f=0;fh&&(h=m)}l[f]=h}return u},t.prototype.maximum=function(n,r){return H([n,r],"maximum"),this.broadcastedBinaryOp(n,r,n.dtype,function(o,i){return Math.max(o,i)})},t.prototype.all=function(n,r){H(n,"all"),Wt("all",r,n.rank);for(var o=pt(n.shape,r),i=o[0],a=o[1],u=Ie(i,n.dtype),s=Z(a),l=this.readSync(u.dataId),c=this.readSync(n.dataId),f=0;f0?o[i]=1:o[i]=0;return this.makeOutput(o,n.shape,"float32")},t.prototype.isNaN=function(n){H(n,"x");for(var r=this.readSync(n.dataId),o=new Uint8Array(r.length),i=0;i.5?o[i]=Math.ceil(r[i]):o[i]=a%2==0?a:a+1}return this.makeOutput(o,n.shape,"float32")},t.prototype.exp=function(n){H(n,"exp");for(var r=this.readSync(n.dataId),o=new Float32Array(r.length),i=0;i=0?a:Math.exp(a)-1}return this.makeOutput(r,n.shape,"float32")},t.prototype.eluDer=function(n,r){H([n,r],"eluDer");for(var o=new Float32Array(r.size),i=this.readSync(r.dataId),a=this.readSync(n.dataId),u=0;u=1?a[u]:a[u]*(s+1)}return this.makeOutput(o,r.shape,"float32")},t.prototype.selu=function(n){H(n,"selu");for(var r=Dd,o=Td,i=new Float32Array(n.size),a=this.readSync(n.dataId),u=0;u=0?o*s:r*(Math.exp(s)-1)}return this.makeOutput(i,n.shape,"float32")},t.prototype.clip=function(n,r,o){H(n,"clip");for(var i=new Float32Array(n.size),a=this.readSync(n.dataId),u=0;uo?o:s-r,s=i[a]0?1:r}return this.makeOutput(o,n.shape,"float32")},t.prototype.fusedConv2d=function(n){var r=n.input,o=n.filter,i=n.convInfo,a=n.bias,u=n.activation,s=n.preluActivationWeights,l=this.conv2d(r,o,i);return a&&(l=this.add(l,a)),u&&(l=Xl(this,l,u,s)),l},t.prototype.conv2d=function(n,r,o){H([n,r],"conv2d");for(var i=o.filterHeight,a=o.filterWidth,u=o.dilationHeight,s=o.dilationWidth,l=o.padInfo.left,c=o.padInfo.top,f=o.dataFormat==="channelsLast",d=se(o.outShape,n.dtype),h=n.strides[0],p=f?n.strides[1]:n.strides[2],m=f?n.strides[2]:1,g=f?1:n.strides[1],v=d.strides[0],y=f?d.strides[1]:d.strides[2],x=f?d.strides[2]:1,w=f?1:d.strides[1],b=this.readSync(n.dataId),C=this.readSync(r.dataId),_=d.values,E=0;E=o.inHeight))for(var $=L*r.strides[0],V=R+U*p,P=0;P=o.inWidth))for(var re=V+q*m,oe=$+G*r.strides[1],le=0;le=o.inDepth))for(var k=E*r.strides[0],T=x+R*n.strides[1],N=0;N=o.inHeight))for(var V=k+U*r.strides[1],P=T+$*n.strides[2],M=0;M=o.inWidth))for(var oe=V+q*r.strides[2],le=P+re*o.inChannels,ae=oe,fe=0;fe=o.inHeight))for(var E=C*r.strides[0],R=v+_*n.strides[1],k=0;k=o.inWidth))for(var U=E+W*r.strides[1],$=R+L*o.inChannels,V=T,P=U,M=0;MV?V=re:o==="avg"&&(P+=re,M++)}if(isNaN(V))break}g[N+W*x+_]=o==="avg"?P/M:V}return m.toTensor()},t.prototype.maxPool=function(n,r){return this.pool(n,r,"max")},t.prototype.maxPoolPositions=function(n,r){for(var o=se(r.outShape,"int32"),i=r.strideHeight,a=r.strideWidth,u=r.dilationHeight,s=r.dilationWidth,l=r.effectiveFilterHeight,c=r.effectiveFilterWidth,f=r.padInfo.top,d=r.padInfo.left,h=this.bufferSync(n),p=0;pE&&(E=L,R=T*c+W)}o.set(R,p,g,w,m)}}return o.toTensor()},t.prototype.maxPoolBackprop=function(n,r,o,i){H([r,o],"maxPoolBackprop");for(var a=this.maxPoolPositions(r,i),u=i.strideHeight,s=i.strideWidth,l=i.dilationHeight,c=i.dilationWidth,f=i.effectiveFilterHeight,d=i.effectiveFilterWidth,h=d-1-i.padInfo.left,p=f-1-i.padInfo.top,m=se(r.shape,"float32"),g=this.bufferSync(a),v=this.bufferSync(n),y=0;y=i.outHeight||Math.floor(k)!==k))for(var T=0;T=i.outWidth||Math.floor(N)!==N)){var W=f*d-1-g.get(y,k,N,x)===R*d+T?1:0;W!==0&&(E+=v.get(y,k,N,x)*W)}}}m.set(E,y,w,b,x)}return m.toTensor()},t.prototype.avgPoolBackprop=function(n,r,o){H([n,r],"avgPoolBackprop");for(var i=o.strideHeight,a=o.strideWidth,u=o.filterHeight,s=o.filterWidth,l=o.dilationHeight,c=o.dilationWidth,f=o.effectiveFilterHeight,d=o.effectiveFilterWidth,h=d-1-o.padInfo.left,p=f-1-o.padInfo.top,m=se(r.shape,"float32"),g=1/(u*s),v=this.bufferSync(n),y=0;y=o.outHeight||Math.floor(k)!==k))for(var T=0;T=o.outWidth||Math.floor(N)!==N||(E+=v.get(y,k,N,x))}}m.set(E*g,y,w,b,x)}return m.toTensor()},t.prototype.pool3d=function(n,r,o){H(n,"pool3d");for(var i=r.strideDepth,a=r.strideHeight,u=r.strideWidth,s=r.dilationDepth,l=r.dilationHeight,c=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=r.padInfo.front,m=r.padInfo.top,g=r.padInfo.left,v=o==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,y=this.readSync(n.dataId),x=se(r.outShape,n.dtype),w=x.values,b=r.outShape[1]*r.outShape[2]*r.outShape[3]*r.outShape[4],C=r.outShape[2]*r.outShape[3]*r.outShape[4],_=r.outShape[3]*r.outShape[4],E=r.outShape[4],R=0;Rve?ve=Ae:o==="avg"&&(ge+=Ae,$e++),isNaN(ve))break}if(isNaN(ve))break}if(isNaN(ve))break}w[fe+N]=o==="avg"?ge/$e:ve}}}return x.toTensor()},t.prototype.avgPool3d=function(n,r){return H(n,"avgPool3d"),this.pool3d(n,r,"avg").toFloat()},t.prototype.avgPool3dBackprop=function(n,r,o){H([n,r],"avgPool3dBackprop");for(var i=o.strideDepth,a=o.strideHeight,u=o.strideWidth,s=o.filterDepth,l=o.filterHeight,c=o.filterWidth,f=o.dilationDepth,d=o.dilationHeight,h=o.dilationWidth,p=o.effectiveFilterDepth,m=o.effectiveFilterHeight,g=o.effectiveFilterWidth,v=p-1-o.padInfo.front,y=g-1-o.padInfo.left,x=m-1-o.padInfo.top,w=se(r.shape,"float32"),b=1/(s*l*c),C=this.bufferSync(n),_=0;_=o.outDepth||Math.floor(V)!==V))for(var P=0;P=o.outHeight||Math.floor(M)!==M))for(var B=0;B=o.outWidth||Math.floor(G)!==G||(U+=C.get(_,V,M,G,E))}}}w.set(U*b,_,R,k,T,E)}return w.toTensor()},t.prototype.maxPool3d=function(n,r){return H(n,"maxPool3d"),this.pool3d(n,r,"max").toFloat()},t.prototype.maxPool3dPositions=function(n,r){for(var o=se(r.outShape,"int32"),i=r.strideDepth,a=r.strideHeight,u=r.strideWidth,s=r.dilationDepth,l=r.dilationHeight,c=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=r.padInfo.front,m=r.padInfo.top,g=r.padInfo.left,v=this.bufferSync(n),y=0;y=$&&($=oe,V=M*d*h+G*d+re)}o.set(V,y,w,E,N,x)}}}return o.toTensor()},t.prototype.maxPool3dBackprop=function(n,r,o,i){H([r,o],"maxPool3dBackprop");for(var a=this.maxPool3dPositions(r,i),u=i.strideDepth,s=i.strideHeight,l=i.strideWidth,c=i.dilationDepth,f=i.dilationHeight,d=i.dilationWidth,h=i.effectiveFilterDepth,p=i.effectiveFilterHeight,m=i.effectiveFilterWidth,g=h-1-i.padInfo.front,v=m-1-i.padInfo.left,y=p-1-i.padInfo.top,x=se(r.shape,"float32"),w=this.bufferSync(a),b=this.bufferSync(n),C=0;C=i.outDepth||Math.floor($)!==$))for(var V=0;V=i.outHeight||Math.floor(P)!==P))for(var M=0;M=i.outWidth||Math.floor(B)!==B)){var G=h*p*m-1-w.get(C,$,P,B,_)===U*p*m+V*m+M?1:0;G!==0&&(L+=b.get(C,$,P,B,_)*G)}}}}x.set(L,C,E,R,k,_)}return x.toTensor()},t.prototype.cast=function(n,r){return E0(n,r,this)},t.prototype.reshape=function(n,r){return df(n,r)},t.prototype.avgPool=function(n,r){return H(n,"avgPool"),this.pool(n,r,"avg").toFloat()},t.prototype.resizeBilinear=function(n,r,o,i){H(n,"resizeBilinear");for(var a=n.shape,u=a[0],s=a[1],l=a[2],c=a[3],f=this.readSync(n.dataId),d=new Float32Array(Z([u,r,o,c])),h=[i&&r>1?s-1:s,i&&o>1?l-1:l],p=[i&&r>1?r-1:r,i&&o>1?o-1:o],m=0,g=h[0]/p[0],v=h[1]/p[1],y=0;y1?u-1:u,o&&d>1?s-1:s],m=[o&&f>1?f-1:f,o&&d>1?d-1:d],g=p[0]/m[0],v=p[1]/m[1],y=this.readSync(n.dataId),x=0,w=0;w1?s-1:s,i&&o>1?l-1:l],p=[i&&r>1?r-1:r,i&&o>1?o-1:o],m=h[0]/p[0],g=h[1]/p[1],v=0,y=0;y1?u-1:u,o&&d>1?s-1:s],g=[o&&f>1?f-1:f,o&&d>1?d-1:d],v=m[0]/g[0],y=m[1]/g[1],x=1/v,w=1/y,b=2*Math.ceil(x)+2,C=2*Math.ceil(w)+2,_=0;_=f)){var G=E+B*n.strides[1],q=B*v;if(R===Math.min(u-1,o?Math.round(q):Math.floor(q)))for(var re=0;re=d)){var le=G+oe*n.strides[2],ae=oe*y;W===Math.min(s-1,o?Math.round(ae):Math.floor(ae))&&(P+=p[le+V])}}}}h[L+V]=P}return It(h,r.shape,r.dtype)},t.prototype.batchNormalization=function(n,r,o,i,a,u){H([n,r,o,a,u],"batchNorm");for(var s=this.readSync(n.dataId),l=this.readSync(r.dataId),c=this.readSync(o.dataId),f=a?this.readSync(a.dataId):new Float32Array([1]),d=u?this.readSync(u.dataId):new Float32Array([0]),h=new Float32Array(s.length),p=d.length,m=f.length,g=c.length,v=l.length,y=0,x=0,w=0,b=0,C=0;C=p&&(y=0),x>=v&&(x=0),w>=m&&(w=0),b>=g&&(b=0);return It(h,n.shape)},t.prototype.localResponseNormalization4D=function(n,r,o,i,a){H(n,"localResponseNormalization4D");var u=n.shape[3],s=u-1,l=this.readSync(n.dataId),c=n.size,f=new Float32Array(c);function d(g){for(var v=g%u,y=g-v+Math.max(0,v-r),x=g-v+Math.min(v+r,s),w=0;y<=x;y++){var b=l[y];w+=b*b}return w}for(var h=0;h=0&&u[s]1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+r});for(var i=n.shape[0],a=n.shape[1],u=n.shape[2],s=n.shape[3],l=a*r,c=u*r,f=s/(r*r),d=this.readSync(n.dataId),h=new Float32Array(i*l*c*f),p=0,m=0;m=l))for(var W=p>1?(k-E)*(c-1)/(p-1):0,L=m>1?(T-R)*(f-1)/(m-1):0,U=0;U1?E*(c-1)+U*W:.5*(E+k)*(c-1);if($<0||$>c-1)for(var V=0;V1?R*(f-1)+V*L:.5*(R+T)*(f-1))<0||me>f-1)for(P=0;P1?R*(f-1)+V*L:.5*(R+T)*(f-1))<0||me>f-1)for(P=0;P=n.size/l)throw new Error("Invalid indices: "+m+" does not index into "+n.shape);for(var x=0;x=i/a)throw new Error("Invalid indices: "+v+" does not index into "+o);for(var b=0;bp&&(p=v,m=g)}c[d]=m}return s},t.prototype.cumsum=function(n,r,o,i){if(H(n,"cumsum"),r!==n.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(n.rank-1)+" but got axis="+r);for(var a=st(n.dtype,"int32"),u=Ie(n.shape,a),s=this.readSync(u.dataId),l=this.readSync(n.dataId),c=n.shape[n.rank-1],f=i?function(g,v){return g+c-v-1}:function(g,v){return g+v},d=0;di?1:0})},t.prototype.greaterEqual=function(n,r){return H([n,r],"greaterEqual"),this.broadcastedBinaryOp(n,r,"bool",function(o,i){return o>=i?1:0})},t.prototype.logicalNot=function(n){H(n,"logicalNot");for(var r=this.readSync(n.dataId),o=new Uint8Array(r.length),i=0;i1||r.rank===1?1:Z(r.shape.slice(1)),d=0;d=0&&i>=0?a:(a+i)%i})},t.prototype.max=function(n,r){H(n,"max"),Wt("max",r,n.rank);for(var o=pt(n.shape,r),i=o[0],a=o[1],u=Ie(i,n.dtype),s=Z(a),l=this.readSync(u.dataId),c=this.readSync(n.dataId),f=0;fh&&(h=m)}l[f]=h}return u},t.prototype.maximum=function(n,r){return H([n,r],"maximum"),this.broadcastedBinaryOp(n,r,n.dtype,function(o,i){return Math.max(o,i)})},t.prototype.all=function(n,r){H(n,"all"),Wt("all",r,n.rank);for(var o=pt(n.shape,r),i=o[0],a=o[1],u=Ie(i,n.dtype),s=Z(a),l=this.readSync(u.dataId),c=this.readSync(n.dataId),f=0;f0?o[i]=1:o[i]=0;return this.makeOutput(o,n.shape,"float32")},t.prototype.isNaN=function(n){H(n,"x");for(var r=this.readSync(n.dataId),o=new Uint8Array(r.length),i=0;i.5?o[i]=Math.ceil(r[i]):o[i]=a%2==0?a:a+1}return this.makeOutput(o,n.shape,"float32")},t.prototype.exp=function(n){H(n,"exp");for(var r=this.readSync(n.dataId),o=new Float32Array(r.length),i=0;i=0?a:Math.exp(a)-1}return this.makeOutput(r,n.shape,"float32")},t.prototype.eluDer=function(n,r){H([n,r],"eluDer");for(var o=new Float32Array(r.size),i=this.readSync(r.dataId),a=this.readSync(n.dataId),u=0;u=1?a[u]:a[u]*(s+1)}return this.makeOutput(o,r.shape,"float32")},t.prototype.selu=function(n){H(n,"selu");for(var r=Rd,o=Id,i=new Float32Array(n.size),a=this.readSync(n.dataId),u=0;u=0?o*s:r*(Math.exp(s)-1)}return this.makeOutput(i,n.shape,"float32")},t.prototype.clip=function(n,r,o){H(n,"clip");for(var i=new Float32Array(n.size),a=this.readSync(n.dataId),u=0;uo?o:s-r,s=i[a]0?1:r}return this.makeOutput(o,n.shape,"float32")},t.prototype.fusedConv2d=function(n){var r=n.input,o=n.filter,i=n.convInfo,a=n.bias,u=n.activation,s=n.preluActivationWeights,l=this.conv2d(r,o,i);return a&&(l=this.add(l,a)),u&&(l=ql(this,l,u,s)),l},t.prototype.conv2d=function(n,r,o){H([n,r],"conv2d");for(var i=o.filterHeight,a=o.filterWidth,u=o.dilationHeight,s=o.dilationWidth,l=o.padInfo.left,c=o.padInfo.top,f=o.dataFormat==="channelsLast",d=se(o.outShape,n.dtype),h=n.strides[0],p=f?n.strides[1]:n.strides[2],m=f?n.strides[2]:1,g=f?1:n.strides[1],v=d.strides[0],y=f?d.strides[1]:d.strides[2],x=f?d.strides[2]:1,w=f?1:d.strides[1],b=this.readSync(n.dataId),C=this.readSync(r.dataId),_=d.values,E=0;E=o.inHeight))for(var $=L*r.strides[0],V=R+U*p,P=0;P=o.inWidth))for(var re=V+q*m,oe=$+G*r.strides[1],le=0;le=o.inDepth))for(var k=E*r.strides[0],T=x+R*n.strides[1],N=0;N=o.inHeight))for(var V=k+U*r.strides[1],P=T+$*n.strides[2],M=0;M=o.inWidth))for(var oe=V+q*r.strides[2],le=P+re*o.inChannels,ae=oe,fe=0;fe=o.inHeight))for(var E=C*r.strides[0],R=v+_*n.strides[1],k=0;k=o.inWidth))for(var U=E+W*r.strides[1],$=R+L*o.inChannels,V=T,P=U,M=0;MV?V=re:o==="avg"&&(P+=re,M++)}if(isNaN(V))break}g[N+W*x+_]=o==="avg"?P/M:V}return m.toTensor()},t.prototype.maxPool=function(n,r){return this.pool(n,r,"max")},t.prototype.maxPoolPositions=function(n,r){for(var o=se(r.outShape,"int32"),i=r.strideHeight,a=r.strideWidth,u=r.dilationHeight,s=r.dilationWidth,l=r.effectiveFilterHeight,c=r.effectiveFilterWidth,f=r.padInfo.top,d=r.padInfo.left,h=this.bufferSync(n),p=0;pE&&(E=L,R=T*c+W)}o.set(R,p,g,w,m)}}return o.toTensor()},t.prototype.maxPoolBackprop=function(n,r,o,i){H([r,o],"maxPoolBackprop");for(var a=this.maxPoolPositions(r,i),u=i.strideHeight,s=i.strideWidth,l=i.dilationHeight,c=i.dilationWidth,f=i.effectiveFilterHeight,d=i.effectiveFilterWidth,h=d-1-i.padInfo.left,p=f-1-i.padInfo.top,m=se(r.shape,"float32"),g=this.bufferSync(a),v=this.bufferSync(n),y=0;y=i.outHeight||Math.floor(k)!==k))for(var T=0;T=i.outWidth||Math.floor(N)!==N)){var W=f*d-1-g.get(y,k,N,x)===R*d+T?1:0;W!==0&&(E+=v.get(y,k,N,x)*W)}}}m.set(E,y,w,b,x)}return m.toTensor()},t.prototype.avgPoolBackprop=function(n,r,o){H([n,r],"avgPoolBackprop");for(var i=o.strideHeight,a=o.strideWidth,u=o.filterHeight,s=o.filterWidth,l=o.dilationHeight,c=o.dilationWidth,f=o.effectiveFilterHeight,d=o.effectiveFilterWidth,h=d-1-o.padInfo.left,p=f-1-o.padInfo.top,m=se(r.shape,"float32"),g=1/(u*s),v=this.bufferSync(n),y=0;y=o.outHeight||Math.floor(k)!==k))for(var T=0;T=o.outWidth||Math.floor(N)!==N||(E+=v.get(y,k,N,x))}}m.set(E*g,y,w,b,x)}return m.toTensor()},t.prototype.pool3d=function(n,r,o){H(n,"pool3d");for(var i=r.strideDepth,a=r.strideHeight,u=r.strideWidth,s=r.dilationDepth,l=r.dilationHeight,c=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=r.padInfo.front,m=r.padInfo.top,g=r.padInfo.left,v=o==="max"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,y=this.readSync(n.dataId),x=se(r.outShape,n.dtype),w=x.values,b=r.outShape[1]*r.outShape[2]*r.outShape[3]*r.outShape[4],C=r.outShape[2]*r.outShape[3]*r.outShape[4],_=r.outShape[3]*r.outShape[4],E=r.outShape[4],R=0;Rve?ve=Ae:o==="avg"&&(ge+=Ae,$e++),isNaN(ve))break}if(isNaN(ve))break}if(isNaN(ve))break}w[fe+N]=o==="avg"?ge/$e:ve}}}return x.toTensor()},t.prototype.avgPool3d=function(n,r){return H(n,"avgPool3d"),this.pool3d(n,r,"avg").toFloat()},t.prototype.avgPool3dBackprop=function(n,r,o){H([n,r],"avgPool3dBackprop");for(var i=o.strideDepth,a=o.strideHeight,u=o.strideWidth,s=o.filterDepth,l=o.filterHeight,c=o.filterWidth,f=o.dilationDepth,d=o.dilationHeight,h=o.dilationWidth,p=o.effectiveFilterDepth,m=o.effectiveFilterHeight,g=o.effectiveFilterWidth,v=p-1-o.padInfo.front,y=g-1-o.padInfo.left,x=m-1-o.padInfo.top,w=se(r.shape,"float32"),b=1/(s*l*c),C=this.bufferSync(n),_=0;_=o.outDepth||Math.floor(V)!==V))for(var P=0;P=o.outHeight||Math.floor(M)!==M))for(var B=0;B=o.outWidth||Math.floor(G)!==G||(U+=C.get(_,V,M,G,E))}}}w.set(U*b,_,R,k,T,E)}return w.toTensor()},t.prototype.maxPool3d=function(n,r){return H(n,"maxPool3d"),this.pool3d(n,r,"max").toFloat()},t.prototype.maxPool3dPositions=function(n,r){for(var o=se(r.outShape,"int32"),i=r.strideDepth,a=r.strideHeight,u=r.strideWidth,s=r.dilationDepth,l=r.dilationHeight,c=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=r.padInfo.front,m=r.padInfo.top,g=r.padInfo.left,v=this.bufferSync(n),y=0;y=$&&($=oe,V=M*d*h+G*d+re)}o.set(V,y,w,E,N,x)}}}return o.toTensor()},t.prototype.maxPool3dBackprop=function(n,r,o,i){H([r,o],"maxPool3dBackprop");for(var a=this.maxPool3dPositions(r,i),u=i.strideDepth,s=i.strideHeight,l=i.strideWidth,c=i.dilationDepth,f=i.dilationHeight,d=i.dilationWidth,h=i.effectiveFilterDepth,p=i.effectiveFilterHeight,m=i.effectiveFilterWidth,g=h-1-i.padInfo.front,v=m-1-i.padInfo.left,y=p-1-i.padInfo.top,x=se(r.shape,"float32"),w=this.bufferSync(a),b=this.bufferSync(n),C=0;C=i.outDepth||Math.floor($)!==$))for(var V=0;V=i.outHeight||Math.floor(P)!==P))for(var M=0;M=i.outWidth||Math.floor(B)!==B)){var G=h*p*m-1-w.get(C,$,P,B,_)===U*p*m+V*m+M?1:0;G!==0&&(L+=b.get(C,$,P,B,_)*G)}}}}x.set(L,C,E,R,k,_)}return x.toTensor()},t.prototype.cast=function(n,r){return w0(n,r,this)},t.prototype.reshape=function(n,r){return cf(n,r)},t.prototype.avgPool=function(n,r){return H(n,"avgPool"),this.pool(n,r,"avg").toFloat()},t.prototype.resizeBilinear=function(n,r,o,i){H(n,"resizeBilinear");for(var a=n.shape,u=a[0],s=a[1],l=a[2],c=a[3],f=this.readSync(n.dataId),d=new Float32Array(Z([u,r,o,c])),h=[i&&r>1?s-1:s,i&&o>1?l-1:l],p=[i&&r>1?r-1:r,i&&o>1?o-1:o],m=0,g=h[0]/p[0],v=h[1]/p[1],y=0;y1?u-1:u,o&&d>1?s-1:s],m=[o&&f>1?f-1:f,o&&d>1?d-1:d],g=p[0]/m[0],v=p[1]/m[1],y=this.readSync(n.dataId),x=0,w=0;w1?s-1:s,i&&o>1?l-1:l],p=[i&&r>1?r-1:r,i&&o>1?o-1:o],m=h[0]/p[0],g=h[1]/p[1],v=0,y=0;y1?u-1:u,o&&d>1?s-1:s],g=[o&&f>1?f-1:f,o&&d>1?d-1:d],v=m[0]/g[0],y=m[1]/g[1],x=1/v,w=1/y,b=2*Math.ceil(x)+2,C=2*Math.ceil(w)+2,_=0;_=f)){var G=E+B*n.strides[1],q=B*v;if(R===Math.min(u-1,o?Math.round(q):Math.floor(q)))for(var re=0;re=d)){var le=G+oe*n.strides[2],ae=oe*y;W===Math.min(s-1,o?Math.round(ae):Math.floor(ae))&&(P+=p[le+V])}}}}h[L+V]=P}return Rt(h,r.shape,r.dtype)},t.prototype.batchNormalization=function(n,r,o,i,a,u){H([n,r,o,a,u],"batchNorm");for(var s=this.readSync(n.dataId),l=this.readSync(r.dataId),c=this.readSync(o.dataId),f=a?this.readSync(a.dataId):new Float32Array([1]),d=u?this.readSync(u.dataId):new Float32Array([0]),h=new Float32Array(s.length),p=d.length,m=f.length,g=c.length,v=l.length,y=0,x=0,w=0,b=0,C=0;C=p&&(y=0),x>=v&&(x=0),w>=m&&(w=0),b>=g&&(b=0);return Rt(h,n.shape)},t.prototype.localResponseNormalization4D=function(n,r,o,i,a){H(n,"localResponseNormalization4D");var u=n.shape[3],s=u-1,l=this.readSync(n.dataId),c=n.size,f=new Float32Array(c);function d(g){for(var v=g%u,y=g-v+Math.max(0,v-r),x=g-v+Math.min(v+r,s),w=0;y<=x;y++){var b=l[y];w+=b*b}return w}for(var h=0;h=0&&u[s]1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+r});for(var i=n.shape[0],a=n.shape[1],u=n.shape[2],s=n.shape[3],l=a*r,c=u*r,f=s/(r*r),d=this.readSync(n.dataId),h=new Float32Array(i*l*c*f),p=0,m=0;m=l))for(var W=p>1?(k-E)*(c-1)/(p-1):0,L=m>1?(T-R)*(f-1)/(m-1):0,U=0;U1?E*(c-1)+U*W:.5*(E+k)*(c-1);if($<0||$>c-1)for(var V=0;V1?R*(f-1)+V*L:.5*(R+T)*(f-1))<0||me>f-1)for(P=0;P1?R*(f-1)+V*L:.5*(R+T)*(f-1))<0||me>f-1)for(P=0;P=n.size/l)throw new Error("Invalid indices: "+m+" does not index into "+n.shape);for(var x=0;x=i/a)throw new Error("Invalid indices: "+v+" does not index into "+o);for(var b=0;b"u"||typeof atob>"u"||typeof btoa>"u");function vv(e){return mf?Buffer.byteLength(e):new Blob([e]).size}function jd(e){var t=0;e.forEach(function(o){t+=o.byteLength});var n=new Uint8Array(t),r=0;return e.forEach(function(o){n.set(new Uint8Array(o),r),r+=o.byteLength}),n.buffer}function mv(e){for(e=e.trim();e.endsWith("/");)e=e.slice(0,e.length-1);var t=e.split("/");return t[t.length-1]}function Oa(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:e.modelTopology==null?0:vv(JSON.stringify(e.modelTopology)),weightSpecsBytes:e.weightSpecs==null?0:vv(JSON.stringify(e.weightSpecs)),weightDataBytes:e.weightData==null?0:e.weightData.byteLength}}var $t=function(){function e(){this.saveRouters=[],this.loadRouters=[]}return e.getInstance=function(){return e.instance==null&&(e.instance=new e),e.instance},e.registerSaveRouter=function(t){e.getInstance().saveRouters.push(t)},e.registerLoadRouter=function(t){e.getInstance().loadRouters.push(t)},e.getSaveHandlers=function(t){return e.getHandlers(t,"save")},e.getLoadHandlers=function(t,n){return e.getHandlers(t,"load",n)},e.getHandlers=function(t,n,r){var o=[];return(n==="load"?e.getInstance().loadRouters:e.getInstance().saveRouters).forEach(function(i){var a=i(t,r);a!==null&&o.push(a)}),o},e}(),ri="://",Or=function(){function e(){this.managers={}}return e.getInstance=function(){return e.instance==null&&(e.instance=new e),e.instance},e.registerManager=function(t,n){I(t!=null,function(){return"scheme must not be undefined or null."}),t.endsWith(ri)&&(t=t.slice(0,t.indexOf(ri))),I(t.length>0,function(){return"scheme must not be an empty string."});var r=e.getInstance();I(r.managers[t]==null,function(){return"A model store manager is already registered for scheme '"+t+"'."}),r.managers[t]=n},e.getManager=function(t){var n=this.getInstance().managers[t];if(n==null)throw new Error("Cannot find model manager for scheme '"+t+"'");return n},e.getSchemes=function(){return Object.keys(this.getInstance().managers)},e}();function Du(e){if(e.indexOf(ri)===-1)throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+Or.getSchemes().join(","));return{scheme:e.split(ri)[0],path:e.split(ri)[1]}}function gv(e,t,n){return n===void 0&&(n=!1),Q(this,void 0,void 0,function(){var r,o,i,a,u,s,l,c,f;return J(this,function(d){switch(d.label){case 0:return I(e!==t,function(){return"Old path and new path are the same: '"+e+"'"}),I((r=$t.getLoadHandlers(e)).length>0,function(){return"Copying failed because no load handler is found for source URL "+e+"."}),I(r.length<2,function(){return"Copying failed because more than one ("+r.length+") load handlers for source URL "+e+"."}),o=r[0],I((i=$t.getSaveHandlers(t)).length>0,function(){return"Copying failed because no save handler is found for destination URL "+t+"."}),I(i.length<2,function(){return"Copying failed because more than one ("+r.length+") save handlers for destination URL "+t+"."}),a=i[0],u=Du(e).scheme,s=Du(e).path,l=u===Du(e).scheme,[4,o.load()];case 1:return c=d.sent(),n&&l?[4,Or.getManager(u).removeModel(s)]:[3,3];case 2:d.sent(),d.label=3;case 3:return[4,a.save(c)];case 4:return f=d.sent(),!n||l?[3,6]:[4,Or.getManager(u).removeModel(s)];case 5:d.sent(),d.label=6;case 6:return[2,f.modelArtifactsInfo]}})})}var io="models_store",Sr="model_info_store";function wy(){if(!z().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var e=window||self,t=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB||e.shimIndexedDB;if(t==null)throw new Error("The current browser does not appear to support IndexedDB.");return t}function gf(e){var t=e.result;t.createObjectStore(io,{keyPath:"modelPath"}),t.createObjectStore(Sr,{keyPath:"modelPath"})}var oi=function(){function e(t){if(this.indexedDB=wy(),t==null||!t)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=t}return e.prototype.save=function(t){return Q(this,void 0,void 0,function(){return J(this,function(n){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,t)]})})},e.prototype.load=function(){return Q(this,void 0,void 0,function(){return J(this,function(t){return[2,this.databaseAction(this.modelPath)]})})},e.prototype.databaseAction=function(t,n){var r=this;return new Promise(function(o,i){var a=r.indexedDB.open("tensorflowjs",1);a.onupgradeneeded=function(){return gf(a)},a.onsuccess=function(){var u=a.result;if(n==null){var s=u.transaction(io,"readonly"),l=s.objectStore(io).get(r.modelPath);l.onsuccess=function(){if(l.result==null)return u.close(),i(new Error("Cannot find model with path '"+r.modelPath+"' in IndexedDB."));o(l.result.modelArtifacts)},l.onerror=function(m){return u.close(),i(l.error)},s.oncomplete=function(){return u.close()}}else{var c,f=Oa(n),d=u.transaction(Sr,"readwrite"),h=d.objectStore(Sr),p=h.put({modelPath:r.modelPath,modelArtifactsInfo:f});p.onsuccess=function(){var m=(c=u.transaction(io,"readwrite")).objectStore(io).put({modelPath:r.modelPath,modelArtifacts:n,modelArtifactsInfo:f});m.onsuccess=function(){return o({modelArtifactsInfo:f})},m.onerror=function(g){var v=(h=d.objectStore(Sr)).delete(r.modelPath);v.onsuccess=function(){return u.close(),i(m.error)},v.onerror=function(y){return u.close(),i(m.error)}}},p.onerror=function(m){return u.close(),i(p.error)},d.oncomplete=function(){c==null?u.close():c.oncomplete=function(){return u.close()}}}},a.onerror=function(u){return i(a.error)}})},e.URL_SCHEME="indexeddb://",e}(),yv=function(e){return z().getBool("IS_BROWSER")&&!Array.isArray(e)&&e.startsWith(oi.URL_SCHEME)?(t=e.slice(oi.URL_SCHEME.length),new oi(t)):null;var t};$t.registerSaveRouter(yv),$t.registerLoadRouter(yv);var ik=function(){function e(){this.indexedDB=wy()}return e.prototype.listModels=function(){return Q(this,void 0,void 0,function(){var t=this;return J(this,function(n){return[2,new Promise(function(r,o){var i=t.indexedDB.open("tensorflowjs",1);i.onupgradeneeded=function(){return gf(i)},i.onsuccess=function(){var a=i.result,u=a.transaction(Sr,"readonly"),s=u.objectStore(Sr).getAll();s.onsuccess=function(){for(var l={},c=0,f=s.result;c"u"||window.localStorage===void 0)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,t==null||!t)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=t,this.keys=Cy(this.modelPath)}return e.prototype.save=function(t){return Q(this,void 0,void 0,function(){var n,r,o;return J(this,function(i){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");n=JSON.stringify(t.modelTopology),r=JSON.stringify(t.weightSpecs),o=Oa(t);try{return this.LS.setItem(this.keys.info,JSON.stringify(o)),this.LS.setItem(this.keys.topology,n),this.LS.setItem(this.keys.weightSpecs,r),this.LS.setItem(this.keys.weightData,function(a){if(mf)return Buffer.from(a).toString("base64");for(var u=new Uint8Array(a),s="",l=0,c=u.length;l"u"||window.localStorage!==void 0,function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return e.prototype.listModels=function(){return Q(this,void 0,void 0,function(){var t,n,r,o,i,a;return J(this,function(u){for(t={},n=Mo+Zn,r=Zn+by,o=0;o"u")throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(n=window.URL.createObjectURL(new Blob([t.weightData],{type:"application/octet-stream"})),!(t.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:t.weightSpecs}],o={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,weightsManifest:r},i=window.URL.createObjectURL(new Blob([JSON.stringify(o)],{type:"application/json"})),(a=this.jsonAnchor==null?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,a.href=i,[4,wv(function(){return a.dispatchEvent(new MouseEvent("click"))})];case 2:return s.sent(),t.weightData==null?[3,4]:((u=this.weightDataAnchor==null?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,u.href=n,[4,wv(function(){return u.dispatchEvent(new MouseEvent("click"))})]);case 3:s.sent(),s.label=4;case 4:return[2,{modelArtifactsInfo:Oa(t)}]}})})},e.URL_SCHEME="downloads://",e}(),vk=function(){function e(t){if(t==null||t.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+t);this.files=t}return e.prototype.load=function(){return Q(this,void 0,void 0,function(){var t,n,r=this;return J(this,function(o){return t=this.files[0],n=this.files.slice(1),[2,new Promise(function(i,a){var u=new FileReader;u.onload=function(s){var l=JSON.parse(s.target.result),c=l.modelTopology;if(c!=null){n.length===0&&i({modelTopology:c});var f=l.weightsManifest;if(f!=null){var d;try{d=r.checkManifestAndWeightFiles(f,n)}catch(g){return void a(g)}var h=[],p=[],m=[];f.forEach(function(g){g.paths.forEach(function(v){p.push(v),m.push(null)}),h.push.apply(h,g.weights)}),f.forEach(function(g){g.paths.forEach(function(v){var y=new FileReader;y.onload=function(x){var w=x.target.result,b=p.indexOf(v);m[b]=w,m.indexOf(null)===-1&&i({modelTopology:c,weightSpecs:h,weightData:jd(m),format:l.format,generatedBy:l.generatedBy,convertedBy:l.convertedBy,userDefinedMetadata:l.userDefinedMetadata})},y.onerror=function(x){return a("Failed to weights data from file of path '"+v+"'.")},y.readAsArrayBuffer(d[v])})})}else a(new Error("weightManifest field is missing from file "+t.name))}else a(new Error("modelTopology field is missing from file "+t.name))},u.onerror=function(s){return a("Failed to read model topology and weights manifest JSON from file '"+t.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},u.readAsText(t)})]})})},e.prototype.checkManifestAndWeightFiles=function(t,n){for(var r=[],o=n.map(function(s){return mv(s.name)}),i={},a=0,u=t;a0,function(){return"promises must be a none empty array"})})(e),function(i,a){I(i>=0&&i<=1,function(){return"Progress fraction must be in range [0, 1], but got startFraction "+i}),I(a>=0&&a<=1,function(){return"Progress fraction must be in range [0, 1], but got endFraction "+a}),I(a>=i,function(){return"startFraction must be no more than endFraction, but got startFraction "+i+" and endFraction "+a})}(n=n??0,r=r??1);var o=0;return Promise.all(e.map(function(i){return i.then(function(a){var u=n+ ++o/e.length*(r-n);return t(u),a}),i}))}function _y(e,t){return Q(this,void 0,void 0,function(){var n,r,o,i,a,u,s,l,c;return J(this,function(f){switch(f.label){case 0:return t==null&&(t={}),n=t.fetchFunc==null?z().platform.fetch:t.fetchFunc,r=e.map(function(d){return n(d,t.requestInit,{isBinary:!0})}),o=0,i=.5,t.onProgress!=null?[3,2]:[4,Promise.all(r)];case 1:return a=f.sent(),[3,4];case 2:return[4,bv(r,t.onProgress,o,i)];case 3:a=f.sent(),f.label=4;case 4:return u=a.map(function(d){return d.arrayBuffer()}),s=.5,l=1,t.onProgress!=null?[3,6]:[4,Promise.all(u)];case 5:return c=f.sent(),[3,8];case 6:return[4,bv(u,t.onProgress,s,l)];case 7:c=f.sent(),f.label=8;case 8:return[2,c]}})})}function Cv(e){var t=this;return function(n,r,o){return r===void 0&&(r=""),Q(t,void 0,void 0,function(){var i,a,u,s,l,c,f,d,h,p;return J(this,function(m){switch(m.label){case 0:if(i=n.map(function(){return!1}),a={},u=o!=null?o.map(function(){return!1}):[],s=[],n.forEach(function(g,v){var y=0;g.weights.forEach(function(x){var w="quantization"in x?x.quantization.dtype:x.dtype,b=vf[w]*Z(x.shape),C=function(){i[v]=!0,a[v]==null&&(a[v]=[]),a[v].push({manifestEntry:x,groupOffset:y,sizeBytes:b})};o!=null?o.forEach(function(_,E){_===x.name&&(C(),u[E]=!0)}):C(),s.push(x.name),y+=b})}),!u.every(function(g){return g}))throw l=o.filter(function(g,v){return!u[v]}),new Error("Could not find weights in manifest with names: "+l.join(", ")+`. -Manifest JSON has weights with names: `+s.join(", ")+".");return c=i.reduce(function(g,v,y){return v&&g.push(y),g},[]),f=[],c.forEach(function(g){n[g].paths.forEach(function(v){var y=r+(r.endsWith("/")?"":"/")+v;f.push(y)})}),[4,e(f)];case 1:return d=m.sent(),h={},p=0,c.forEach(function(g){for(var v=n[g].paths.length,y=0,x=0;x0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(t)&&I(t.length===2,function(){return"URL paths for http must have a length of 2, (actual length is "+t.length+")."}),this.path=t,n.requestInit!=null&&n.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=n.requestInit||{}}return e.prototype.save=function(t){return Q(this,void 0,void 0,function(){var n,r,o,i;return J(this,function(a){switch(a.label){case 0:if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(n=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,r=[{paths:["./model.weights.bin"],weights:t.weightSpecs}],o={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata,weightsManifest:r},n.body.append("model.json",new Blob([JSON.stringify(o)],{type:"application/json"}),"model.json"),t.weightData!=null&&n.body.append("model.weights.bin",new Blob([t.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,n)];case 1:if((i=a.sent()).ok)return[2,{modelArtifactsInfo:Oa(t),responses:[i]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+i.status+".")}})})},e.prototype.load=function(){return Q(this,void 0,void 0,function(){var t,n,r,o,i,a,u,s,l,c,f,d;return J(this,function(h){switch(h.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(t=h.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+t.status+". Please verify this URL points to the model JSON of the model to load.");h.label=2;case 2:return h.trys.push([2,4,,5]),[4,t.json()];case 3:return n=h.sent(),[3,5];case 4:throw h.sent(),r="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?r+=" 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.":r+=" Please make sure the server is serving valid JSON for this request.",new Error(r);case 5:if(o=n.modelTopology,i=n.weightsManifest,a=n.generatedBy,u=n.convertedBy,s=n.format,l=n.userDefinedMetadata,o==null&&i==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return i==null?[3,7]:[4,this.loadWeights(i)];case 6:d=h.sent(),c=d[0],f=d[1],h.label=7;case 7:return[2,{modelTopology:o,weightSpecs:c,weightData:f,userDefinedMetadata:l,generatedBy:a,convertedBy:u,format:s}]}})})},e.prototype.loadWeights=function(t){return Q(this,void 0,void 0,function(){var n,r,o,i,a,u,s,l,c,f,d;return J(this,function(h){switch(h.label){case 0:for(n=Array.isArray(this.path)?this.path[1]:this.path,r=function(p){var m=p.lastIndexOf("/"),g=p.lastIndexOf("?"),v=p.substring(0,m),y=g>m?p.substring(g):"";return[v+"/",y]}(n),o=r[0],i=r[1],a=this.weightPathPrefix||o,u=[],s=0,l=t;s"u"?null:(Array.isArray(e)?e.every(function(n){return yf(n)}):yf(e))?xf(e,{onProgress:t}):null};function xf(e,t){return new Ey(e,t)}$t.registerSaveRouter(_v),$t.registerLoadRouter(_v);var tc=function(){function e(t){this.modelArtifacts=t}return e.prototype.load=function(){return Q(this,void 0,void 0,function(){return J(this,function(t){return[2,this.modelArtifacts]})})},e}(),mk=function(){function e(t){this.saveHandler=t}return e.prototype.save=function(t){return Q(this,void 0,void 0,function(){return J(this,function(n){return[2,this.saveHandler(t)]})})},e}(),Sy=Object.freeze({browserFiles:function(e){return new vk(e)},browserHTTPRequest:function(e,t){return xf(e,t)},concatenateArrayBuffers:jd,decodeWeights:xy,encodeWeights:function(e,t){return Q(this,void 0,void 0,function(){var n,r,o,i,a,u=this;return J(this,function(s){switch(s.label){case 0:for(n=[],r=[],o=Array.isArray(e)?e.map(function(l){return l.name}):Object.keys(e),i=function(l){var c=o[l],f=Array.isArray(e)?e[l].tensor:e[c];if(f.dtype!=="float32"&&f.dtype!=="int32"&&f.dtype!=="bool"&&f.dtype!=="string")throw new Error("Unsupported dtype in weight '"+c+"': "+f.dtype);var d={name:c,shape:f.shape,dtype:f.dtype};if(f.dtype==="string"){var h=new Promise(function(p){return Q(u,void 0,void 0,function(){var m,g,v,y,x,w,b;return J(this,function(C){switch(C.label){case 0:return[4,f.bytes()];case 1:for(m=C.sent(),g=m.reduce(function(_,E){return _+E.length},0)+ys*m.length,v=new Uint8Array(g),y=0,x=0;x0&&Number.isInteger(n),function(){return"If provided, numClasses must be a positive integer, but got "+n}),I(r.rank===1,function(){return"Expected the rank of labels to be 1, but got "+r.rank}),I(o.rank===1,function(){return"Expected the rank of predictions to be 1, but got "+o.rank}),I(r.shape[0]===o.shape[0],function(){return"Mismatch in the number of examples: "+r.shape[0]+" vs. "+o.shape[0]+". Labels and predictions should have the same number of elements."}),I(n>0&&Number.isInteger(n),function(){return"numClasses is required to be a positive integer, but got "+n});var i=cf(r.asType("int32"),n),a=cf(o.asType("int32"),n);return i.transpose().matMul(a).asType("int32")}});var gk=D({fromPixels_:function(e,t){if(t===void 0&&(t=3),t>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(e==null)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var n=!1,r=!1,o=!1,i=!1,a=!1;if(e.data instanceof Uint8Array)n=!0;else if(typeof ImageData<"u"&&e instanceof ImageData)r=!0;else if(typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement)o=!0;else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement)i=!0;else{if(e.getContext==null)throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was "+e.constructor.name);a=!0}if(o&&o&&e.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the