UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

1 lines 325 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tfc=e()}}(function(){return function(){function e(t,n,r){function o(i,s){if(!n[i]){if(!t[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[i]={exports:{}};t[i][0].call(l.exports,function(e){var n=t[i][1][e];return o(n||e)},l,l.exports,e,t,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}return e}()({1:[function(e,t,n){},{}],2:[function(e,t,n){var r=e("./lib/alea"),o=e("./lib/xor128"),a=e("./lib/xorwow"),i=e("./lib/xorshift7"),s=e("./lib/xor4096"),u=e("./lib/tychei"),c=e("./seedrandom");c.alea=r,c.xor128=o,c.xorwow=a,c.xorshift7=i,c.xor4096=s,c.tychei=u,t.exports=c},{"./lib/alea":3,"./lib/tychei":4,"./lib/xor128":5,"./lib/xor4096":6,"./lib/xorshift7":7,"./lib/xorwow":8,"./seedrandom":9}],3:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n=i();t.next=function(){var e=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=e-(t.c=0|e)},t.c=1,t.s0=n(" "),t.s1=n(" "),t.s2=n(" "),t.s0-=n(e),t.s0<0&&(t.s0+=1),t.s1-=n(e),t.s1<0&&(t.s1+=1),t.s2-=n(e),t.s2<0&&(t.s2+=1),n=null}function o(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function a(e,t){var n=new r(e),a=t&&t.state,i=n.next;return i.int32=function(){return 4294967296*n.next()|0},i.double=function(){return i()+1.1102230246251565e-16*(2097152*i()|0)},i.quick=i,a&&("object"==typeof a&&o(a,n),i.state=function(){return o(n,{})}),i}function i(){var e=4022871197;return function(t){t=t.toString();for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)}}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.alea=a}(0,"object"==typeof t&&t,!1)},{}],4:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,r=t.d,o=t.a;return e=e<<25^e>>>7^n,n=n-r|0,r=r<<24^r>>>8^o,o=o-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-r|0,t.d=r<<16^n>>>16^o,t.a=o-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var r=0;r<n.length+20;r++)t.b^=0|n.charCodeAt(r),t.next()}function o(e,t){return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t}function a(e,t){var n=new r(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&o(a,n),i.state=function(){return o(n,{})}),i}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.tychei=a}(0,"object"==typeof t&&t,!1)},{}],5:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),t.next()}function o(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t}function a(e,t){var n=new r(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&o(a,n),i.state=function(){return o(n,{})}),i}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xor128=a}(0,"object"==typeof t&&t,!1)},{}],6:[function(e,t,n){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.w,o=t.X,a=t.i;return t.w=r=r+1640531527|0,n=o[a+34&127],e=o[a=a+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=o[a]=n^e,t.i=a,n+(r^r>>>16)|0},function(e,t){var n,r,o,a,i,s=[],u=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,u=Math.max(u,t.length)),o=0,a=-32;a<u;++a)t&&(r^=t.charCodeAt((a+32)%t.length)),0===a&&(i=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,a>=0&&(i=i+1640531527|0,o=0==(n=s[127&a]^=r+i)?o+1:0);for(o>=128&&(s[127&(t&&t.length||0)]=-1),o=127,a=512;a>0;--a)r=s[o+34&127],n=s[o=o+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[o]=r^n;e.w=i,e.X=s,e.i=o}(t,e)}function o(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function a(e,t){null==e&&(e=+new Date);var n=new r(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&(a.X&&o(a,n),i.state=function(){return o(n,{})}),i}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xor4096=a}(0,"object"==typeof t&&t,!1)},{}],7:[function(e,t,n){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.x,o=t.i;return e=r[o],e^=e>>>7,n=e^e<<24,e=r[o+1&7],n^=e^e>>>10,e=r[o+3&7],n^=e^e>>>3,e=r[o+4&7],n^=e^e<<7,e=r[o+7&7],e^=e<<13,n^=e^e<<9,r[o]=n,t.i=o+1&7,n},function(e,t){var n,r=[];if(t===(0|t))r[0]=t;else for(t=""+t,n=0;n<t.length;++n)r[7&n]=r[7&n]<<15^t.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],e.x=r,e.i=0,n=256;n>0;--n)e.next()}(t,e)}function o(e,t){return t.x=e.x.slice(),t.i=e.i,t}function a(e,t){null==e&&(e=+new Date);var n=new r(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&(a.x&&o(a,n),i.state=function(){return o(n,{})}),i}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xorshift7=a}(0,"object"==typeof t&&t,!1)},{}],8:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var r=0;r<n.length+64;r++)t.x^=0|n.charCodeAt(r),r==n.length&&(t.d=t.x<<10^t.x>>>4),t.next()}function o(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function a(e,t){var n=new r(e),a=t&&t.state,i=function(){return(n.next()>>>0)/4294967296};return i.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},i.int32=n.next,i.quick=i,a&&("object"==typeof a&&o(a,n),i.state=function(){return o(n,{})}),i}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xorwow=a}(0,"object"==typeof t&&t,!1)},{}],9:[function(e,t,n){!function(n,r){function o(e,t,o){var p=[],d=u(s((t=1==t?{entropy:!0}:t||{}).entropy?[e,l(n)]:null==e?c():e,3),p),b=new a(p),x=function(){for(var e=b.g(f),t=m,n=0;e<v;)e=(e+n)*h,t*=h,n=b.g(1);for(;e>=y;)e/=2,t/=2,n>>>=1;return(e+n)/t};return x.int32=function(){return 0|b.g(4)},x.quick=function(){return b.g(4)/4294967296},x.double=x,u(l(b.S),n),(t.pass||o||function(e,t,n,o){return o&&(o.S&&i(o,b),e.state=function(){return i(b,{})}),n?(r[g]=e,t):e})(x,d,"global"in t?t.global:this==r,t.state)}function a(e){var t,n=e.length,r=this,o=0,a=r.i=r.j=0,i=r.S=[];for(n||(e=[n++]);o<h;)i[o]=o++;for(o=0;o<h;o++)i[o]=i[a=b&a+e[o%n]+(t=i[o])],i[a]=t;(r.g=function(e){for(var t,n=0,o=r.i,a=r.j,i=r.S;e--;)t=i[o=b&o+1],n=n*h+i[b&(i[o]=i[a=b&a+t])+(i[a]=t)];return r.i=o,r.j=a,n})(h)}function i(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function s(e,t){var n,r=[],o=typeof e;if(t&&"object"==o)for(n in e)try{r.push(s(e[n],t-1))}catch(e){}return r.length?r:"string"==o?e:e+"\0"}function u(e,t){for(var n,r=e+"",o=0;o<r.length;)t[b&o]=b&(n^=19*t[b&o])+r.charCodeAt(o++);return l(t)}function c(){try{var e;return p&&(e=p.randomBytes)?e=e(h):(e=new Uint8Array(h),(d.crypto||d.msCrypto).getRandomValues(e)),l(e)}catch(e){var t=d.navigator,r=t&&t.plugins;return[+new Date,d,r,d.screen,l(n)]}}function l(e){return String.fromCharCode.apply(0,e)}var p,d=this,h=256,f=6,g="random",m=r.pow(h,f),v=r.pow(2,52),y=2*v,b=h-1;if(r["seed"+g]=o,u(r.random(),n),"object"==typeof t&&t.exports){t.exports=o;try{p=e("crypto")}catch(e){}}}([],Math)},{crypto:1}],10:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i};Object.defineProperty(n,"__esModule",{value:!0});var o=e("./doc"),a=function(){function e(){}return e.nextFrame=function(){return new Promise(function(e){return requestAnimationFrame(function(){return e()})})},r([o.doc({heading:"Performance",subheading:"Timing"})],e,"nextFrame",null),e}();n.BrowserUtil=a},{"./doc":12}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.isMobile=function(){var e=navigator.userAgent||navigator.vendor||window.opera;return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(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))}},{}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.doc=function(e){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}}},{}],13:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(i,s)}u((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,a&&(i=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(i=i.call(a,n[1])).done)return i;switch(a=0,i&&(n=[0,i.value]),n[0]){case 0:case 1:i=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){u.label=n[1];break}if(6===n[0]&&u.label<i[1]){u.label=i[1],i=n;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(n);break}i[2]&&u.ops.pop(),u.trys.pop();continue}n=t.call(e,u)}catch(e){n=[6,e],a=0}finally{o=i=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,a,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(n,"__esModule",{value:!0});var a=e("./environment"),i=e("./globals"),s=e("./ops/ops"),u=e("./profiler"),c=e("./tape"),l=e("./tensor"),p=e("./util"),d=function(){function e(e,t){this.backend=e,this.safeMode=t,this.registeredVariables={},this.refCounter=new WeakMap,this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numDataBuffers=0,this.gradientScopeCount=0,this.customGradientDepth=0,this.activeScope={keep:[],track:[]},this.scopeStack=[this.activeScope],this.profiler=new u.Profiler(e)}return e.prototype.runKernel=function(e,t,n){var r,o=this,i=[],s=function(e){return i.push(e),e},u=this.activeScope.name;if(this.customGradientDepth++,r=a.ENV.get("DEBUG")?this.profiler.profileKernel(u,function(){return e(o.backend,s)}):e(this.backend,s),this.customGradientDepth--,this.shouldRecord()){var c={id:this.nextTapeNodeId++,name:u,inputs:t,output:r};null!=n&&(c.gradient=function(e){return n(e,i)}),this.activeTape.push(c)}return r},e.prototype.registerTensor=function(e){var t=this.refCounter.has(e.dataId)?this.refCounter.get(e.dataId):0;this.numTensors++,0===t&&(this.numDataBuffers++,this.numBytes+=p.sizeFromShape(e.shape)*p.bytesPerElement(e.dtype),this.backend.register(e.dataId,e.shape,e.dtype)),this.refCounter.set(e.dataId,t+1),e instanceof l.Variable||this.track(e)},e.prototype.registerVariable=function(e){if(null!=this.registeredVariables[e.name])throw new Error("Variable with name "+e.name+" was already registered");this.registeredVariables[e.name]=e},e.prototype.disposeTensor=function(e){if(this.refCounter.has(e.dataId)){this.numTensors--;var t=this.refCounter.get(e.dataId);t<=1?(this.refCounter.delete(e.dataId),this.backend.disposeData(e.dataId),this.numDataBuffers--,this.numBytes-=p.sizeFromShape(e.shape)*p.bytesPerElement(e.dtype)):this.refCounter.set(e.dataId,t-1)}},e.prototype.memory=function(){var e=this.backend.memory();return e.numTensors=this.numTensors,e.numDataBuffers=this.numDataBuffers,e.numBytes=this.numBytes,e},e.prototype.shouldRecord=function(){return null!=this.activeTape&&0===this.customGradientDepth},e.prototype.addTapeNode=function(e,t,n){var r={};e.forEach(function(e,t){r[t]=e});var o={id:this.nextTapeNodeId++,name:this.activeScope.name,inputs:r,output:t,gradient:function(e){var t={};return n(e).forEach(function(e,n){t[n]=function(){return e}}),t}};this.activeTape.push(o)},e.prototype.keep=function(e){if(1===this.scopeStack.length&&a.ENV.engine.safeMode)throw new Error("Safe mode is ON. Enclose all tensor operations inside tf.tidy(): tf.tidy(() => {...}) to avoid memory leaks.");return this.activeScope.keep.push(e),e},e.prototype.startScope=function(e,t){void 0===t&&(t=!1),t&&0===this.gradientScopeCount&&(this.activeTape=[]),t&&this.gradientScopeCount++;var n={keep:[],track:[]};e&&(n.name=e),this.scopeStack.push(n),this.activeScope=n},e.prototype.endScope=function(e,t){var n=this;void 0===t&&(t=!1),t&&0===--this.gradientScopeCount&&(this.activeTape=null);var r=this.activeScope.keep,o=p.extractTensorsFromContainer(e);r=r.concat(o);for(var a=0;a<this.activeScope.track.length;a++){var i=this.activeScope.track[a];p.isTensorInList(i,r)||(null!=this.activeTape?o.push(i):i.dispose())}this.scopeStack.pop(),this.activeScope=0===this.scopeStack.length?{keep:[],track:[]}:this.scopeStack[this.scopeStack.length-1],o.forEach(function(e){p.isTensorInList(e,n.activeScope.keep)||n.track(e)})},e.prototype.dispose=function(){},e.prototype.gradients=function(e,t,n,r){var o=this;return void 0===r&&(r=!1),p.assert(t.length>0,"gradients() received an empty list of xs."),i.tidy("gradients",function(){var a=e();p.assert(a instanceof l.Tensor,"The result y returned by f() must be a tensor.");var i=c.getFilteredNodesXToY(o.activeTape,t,a);if(!r&&0===i.length&&t.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");var u={};return u[a.id]=null==n?s.ones(a.shape):n,c.backpropagateGradients(u,i),{value:a,grads:t.map(function(e){return u[e.id]})}},!0)},e.prototype.customGrad=function(e){var t=this;return p.assert(p.isFunction(e),"The f passed in customGrad(f) must be a function."),function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];p.assert(n.every(function(e){return e instanceof l.Tensor}),"The args passed in customGrad(f)(x1, x2,...) must all be tensors"),t.customGradientDepth++;var o,a=i.tidy(e.name,function(){var t=e.apply(void 0,n),r=t.value,a=t.gradFunc;return p.assert(r instanceof l.Tensor,"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"),p.assert(p.isFunction(a),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."),o=a,r},!0);if(t.customGradientDepth--,t.shouldRecord()){t.addTapeNode(n,a,function(e){var t=o(e),r=Array.isArray(t)?t:[t];return p.assert(r.length===n.length,"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."),p.assert(r.every(function(e){return e instanceof l.Tensor}),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."),r})}return a}},e.prototype.write=function(e,t){this.backend.write(e,t)},e.prototype.readSync=function(e){return this.backend.readSync(e)},e.prototype.read=function(e){return this.backend.read(e)},e.prototype.fromPixels=function(e,t){return this.backend.fromPixels(e,t)},e.prototype.time=function(e){return r(this,void 0,void 0,function(){var t,n;return o(this,function(r){switch(r.label){case 0:return t=performance.now(),[4,this.backend.time(e)];case 1:return n=r.sent(),n.wallMs=performance.now()-t,[2,n]}})})},e.prototype.track=function(e){if(1===this.scopeStack.length&&this.safeMode)throw new Error("Safe mode is ON. Enclose all tensor operations inside tf.tidy(): tf.tidy(() => {op();...}); to avoid memory leaks.");return this.activeScope.track.push(e),e},e}();n.Engine=d},{"./environment":14,"./globals":15,"./ops/ops":79,"./profiler":100,"./tape":101,"./tensor":102,"./util":108}],14:[function(e,t,n){(function(t){"use strict";function r(e,t){return null!=e.getExtension(t)}function o(e){if(0===e)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var t=document.createElement("canvas");return 1===e?t.getContext("webgl")||t.getContext("experimental-webgl"):t.getContext("webgl2")}function a(e){if(null!=e){var t=e.getExtension("WEBGL_lose_context");if(null==t)throw new Error("Extension WEBGL_lose_context not supported on this browser.");t.loseContext()}}function i(e){var t=o(e);return null!=t&&(a(t),!0)}function s(e){if(0===e)return 0;var t,n=o(e);return t=r(n,"EXT_disjoint_timer_query_webgl2")&&2===e?2:r(n,"EXT_disjoint_timer_query")?1:0,null!=n&&a(n),t}function u(e){if(0===e)return!1;var t=o(e);if(1===e){if(!r(t,"OES_texture_float"))return!1}else if(!r(t,"EXT_color_buffer_float"))return!1;var n=t.createFramebuffer(),i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);var s=2===e?t.RGBA32F:t.RGBA;t.texImage2D(t.TEXTURE_2D,0,s,1,1,0,t.RGBA,t.FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,n),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i,0);var u=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;t.readPixels(0,0,1,1,t.RGBA,t.FLOAT,new Float32Array(4));var c=t.getError()===t.NO_ERROR;return a(t),u&&c}function c(e){if(e>0)return!1;if(2!==e)return!1;var t=o(e),n=r(t,"WEBGL_get_buffer_sub_data_async");return a(t),n}function l(){var e={};if("undefined"==typeof window||void 0===window.location)return e;var t=v.getQueryParams(window.location.search);if(b in t){var r={};t[b].split(",").forEach(function(e){var t=e.split(":"),n=t[0],o=t[1];r[n]=o}),n.URL_PROPERTIES.forEach(function(t){t.name in r&&(console.log("Setting feature override from URL "+t.name+": "+r[t.name]),t.type===h.NUMBER?e[t.name]=+r[t.name]:t.type===h.BOOLEAN?e[t.name]="true"===r[t.name]:t.type===h.STRING?e[t.name]=r[t.name]:console.warn("Unknown URL param: "+t.name+"."))})}return e}function p(){var e;if("undefined"!=typeof window)e=window;else{if(void 0===t)throw new Error("Could not find a global object");e=t}return e}var d=this&&this.__decorate||function(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i};Object.defineProperty(n,"__esModule",{value:!0});var h,f=e("./device_util"),g=e("./doc"),m=e("./engine"),v=e("./util");!function(e){e[e.NUMBER=0]="NUMBER",e[e.BOOLEAN=1]="BOOLEAN",e[e.STRING=2]="STRING"}(h=n.Type||(n.Type={})),n.URL_PROPERTIES=[{name:"DEBUG",type:h.BOOLEAN},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",type:h.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:h.BOOLEAN},{name:"WEBGL_VERSION",type:h.NUMBER},{name:"WEBGL_FLOAT_TEXTURE_ENABLED",type:h.BOOLEAN},{name:"WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED",type:h.BOOLEAN},{name:"BACKEND",type:h.STRING}];var y=function(){function e(e){this.features={},this.registry={},null!=e&&(this.features=e),this.get("DEBUG")&&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.")}return e.setBackend=function(e,t){if(void 0===t&&(t=!1),!(e in n.ENV.registry))throw new Error("Backend type '"+e+"' not found in registry");n.ENV.initBackend(e,t)},e.getBackend=function(){return n.ENV.initDefaultBackend(),n.ENV.currentBackend},e.memory=function(){return n.ENV.engine.memory()},e.prototype.get=function(e){return e in this.features?this.features[e]:(this.features[e]=this.evaluateFeature(e),this.features[e])},e.prototype.set=function(e,t){this.features[e]=t},e.prototype.getBestBackendType=function(){var e=this;if(0===Object.keys(this.registry).length)throw new Error("No backend found in registry.");return Object.keys(this.registry).map(function(t){return{name:t,entry:e.registry[t]}}).sort(function(e,t){return t.entry.priority-e.entry.priority})[0].name},e.prototype.evaluateFeature=function(e){if("DEBUG"===e)return!1;if("BACKEND"===e)return this.getBestBackendType();if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"===e){var t=this.get("WEBGL_VERSION");return 0===t?0:s(t)}if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE"===e)return this.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&!f.isMobile();if("WEBGL_VERSION"===e)return i(2)?2:i(1)?1:0;if("WEBGL_FLOAT_TEXTURE_ENABLED"===e)return u(this.get("WEBGL_VERSION"));if("WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED"===e)return c(this.get("WEBGL_VERSION"));throw new Error("Unknown feature "+e+".")},e.prototype.setFeatures=function(e){this.features=e},e.prototype.reset=function(){this.features=l(),null!=this.globalEngine&&(this.globalEngine.dispose(),this.globalEngine=null)},e.prototype.initBackend=function(e,t){void 0===t&&(t=!1),this.currentBackend=e,null!=this.globalEngine&&this.globalEngine.dispose();var r=n.ENV.findBackend(e);this.globalEngine=new m.Engine(r,t)},e.prototype.findBackend=function(e){return e in this.registry?this.registry[e].backend:null},e.prototype.registerBackend=function(e,t,n){void 0===n&&(n=1),e in this.registry&&console.warn(e+" backend was already registered");try{var r=t();return this.registry[e]={backend:r,priority:n},!0}catch(e){return console.warn(e.message),!1}},e.prototype.removeBackend=function(e){if(!(e in this.registry))throw new Error(e+" backend not found in registry");this.registry[e].backend.dispose(),delete this.registry[e]},Object.defineProperty(e.prototype,"engine",{get:function(){return this.initDefaultBackend(),this.globalEngine},enumerable:!0,configurable:!0}),e.prototype.initDefaultBackend=function(){null==this.globalEngine&&this.initBackend(n.ENV.get("BACKEND"),!1)},d([g.doc({heading:"Environment"})],e,"setBackend",null),d([g.doc({heading:"Environment"})],e,"getBackend",null),d([g.doc({heading:"Performance",subheading:"Memory"})],e,"memory",null),e}();n.Environment=y;var b="tfjsflags";n.ENV=function(){var e=p();return e.ENV=e.ENV||new y(l()),e.ENV}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./device_util":11,"./doc":12,"./engine":13,"./util":108}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./gradients"),o=e("./tracking");n.tidy=o.Tracking.tidy,n.keep=o.Tracking.keep,n.dispose=o.Tracking.dispose,n.time=o.Tracking.time,n.grad=r.Gradients.grad,n.valueAndGrad=r.Gradients.valueAndGrad,n.grads=r.Gradients.grads,n.valueAndGrads=r.Gradients.valueAndGrads,n.variableGrads=r.Gradients.variableGrads,n.customGrad=r.Gradients.customGrad},{"./gradients":16,"./tracking":105}],16:[function(e,t,n){"use strict";function r(e){if(e.filter(function(e){return null==e}).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.")}var o=this&&this.__decorate||function(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i};Object.defineProperty(n,"__esModule",{value:!0});var a=e("./doc"),i=e("./environment"),s=e("./globals"),u=e("./tensor"),c=e("./util"),l=function(){function e(){}return e.gradScope=function(e,t){return s.tidy(e,t,!0)},e.grad=function(e){return c.assert(c.isFunction(e),"The f passed in grad(f) must be a function"),function(t,n){c.assert(t instanceof u.Tensor,"The x passed in grad(f)(x) must be a tensor"),c.assert(null==n||n instanceof u.Tensor,"The dy passed in grad(f)(x, dy) must be a tensor");var o=i.ENV.engine.gradients(function(){return e(t)},[t],n),a=o.value,s=o.grads;return null!=n&&c.assertShapesMatch(a.shape,n.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),a.dispose(),r(s),s[0]}},e.grads=function(e){return c.assert(c.isFunction(e),"The f passed in grads(f) must be a function"),function(t,n){c.assert(Array.isArray(t)&&t.every(function(e){return e instanceof u.Tensor}),"The args passed in grads(f)(args) must be an array of tensors"),c.assert(null==n||n instanceof u.Tensor,"The dy passed in grads(f)(args, dy) must be a tensor");var o=i.ENV.engine.gradients(function(){return e.apply(void 0,t)},t,n),a=o.value,s=o.grads;return null!=n&&c.assertShapesMatch(a.shape,n.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),a.dispose(),r(s),s}},e.valueAndGrad=function(e){return c.assert(c.isFunction(e),"The f passed in valueAndGrad(f) must be a function"),function(t,n){c.assert(t instanceof u.Tensor,"The x passed in valueAndGrad(f)(x) must be a tensor"),c.assert(null==n||n instanceof u.Tensor,"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");var o=i.ENV.engine.gradients(function(){return e(t)},[t],n),a=o.grads,s=o.value;return r(a),{grad:a[0],value:s}}},e.valueAndGrads=function(e){return c.assert(c.isFunction(e),"The f passed in valueAndGrads(f) must be a function"),function(t,n){c.assert(Array.isArray(t)&&t.every(function(e){return e instanceof u.Tensor}),"The args passed in valueAndGrads(f)(args) must be array of tensors"),c.assert(null==n||n instanceof u.Tensor,"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");var o=i.ENV.engine.gradients(function(){return e.apply(void 0,t)},t,n);return null!=n&&c.assertShapesMatch(o.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),r(o.grads),o}},e.variableGrads=function(e,t){if(c.assert(c.isFunction(e),"The f passed in variableGrads(f) must be a function"),c.assert(null==t||Array.isArray(t)&&t.every(function(e){return e instanceof u.Variable}),"The varList passed in variableGrads(f, varList) must be an array of variables"),null==t){t=[];for(var n in i.ENV.engine.registeredVariables)t.push(i.ENV.engine.registeredVariables[n])}var r=t.length;t=t.filter(function(e){return e.trainable}),c.assert(t.length>0,"variableGrads() expects at least one of the input variables to be trainable, but none of the "+r+" variables is trainable.");var o=i.ENV.engine.gradients(e,t,null,!0),a=o.value,s=o.grads;c.assert(s.some(function(e){return null!=e}),"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),c.assert(0===a.rank,"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+a.rank+" tensor");var l={};return t.forEach(function(e,t){null!=s[t]&&(l[e.name]=s[t])}),{value:a,grads:l}},e.customGrad=function(e){return i.ENV.engine.customGrad(e)},o([a.doc({heading:"Training",subheading:"Gradients"})],e,"grad",null),o([a.doc({heading:"Training",subheading:"Gradients"})],e,"grads",null),o([a.doc({heading:"Training",subheading:"Gradients"})],e,"valueAndGrad",null),o([a.doc({heading:"Training",subheading:"Gradients"})],e,"valueAndGrads",null),o([a.doc({heading:"Training",subheading:"Gradients"})],e,"variableGrads",null),o([a.doc({heading:"Training",subheading:"Gradients"})],e,"customGrad",null),e}();n.Gradients=l},{"./doc":12,"./environment":14,"./globals":15,"./tensor":102,"./util":108}],17:[function(e,t,n){"use strict";function r(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}Object.defineProperty(n,"__esModule",{value:!0}),e("./kernels/backend_webgl"),e("./kernels/backend_cpu");var o=e("./browser_util"),a=e("./environment");n.environment=a;var i=e("./environment"),s=e("./io/io");n.io=s;var u=e("./kernels/webgl/gpgpu_util"),c=e("./kernels/webgl/webgl_util"),l=e("./test_util");n.test_util=l;var p=e("./util");n.util=p;var d=e("./version");n.version_core=d.version;var h=e("./optimizers/adadelta_optimizer");n.AdadeltaOptimizer=h.AdadeltaOptimizer;var f=e("./optimizers/adagrad_optimizer");n.AdagradOptimizer=f.AdagradOptimizer;var g=e("./optimizers/adam_optimizer");n.AdamOptimizer=g.AdamOptimizer;var m=e("./optimizers/adamax_optimizer");n.AdamaxOptimizer=m.AdamaxOptimizer;var v=e("./optimizers/momentum_optimizer");n.MomentumOptimizer=v.MomentumOptimizer;var y=e("./optimizers/optimizer");n.Optimizer=y.Optimizer;var b=e("./optimizers/rmsprop_optimizer");n.RMSPropOptimizer=b.RMSPropOptimizer;var x=e("./optimizers/sgd_optimizer");n.SGDOptimizer=x.SGDOptimizer;var w=e("./tensor");n.Tensor=w.Tensor,n.TensorBuffer=w.TensorBuffer,n.variable=w.variable,n.Variable=w.Variable;var E=e("./types");n.Rank=E.Rank,r(e("./ops/ops"));var A=e("./ops/loss_ops");n.Reduction=A.Reduction,r(e("./train")),r(e("./globals"));var T=e("./environment");n.ENV=T.ENV,n.Environment=T.Environment,n.setBackend=i.Environment.setBackend,n.getBackend=i.Environment.getBackend,n.memory=i.Environment.memory;var _=e("./doc");n.doc=_.doc,n.nextFrame=o.BrowserUtil.nextFrame,n.webgl={webgl_util:c,gpgpu_util:u}},{"./browser_util":10,"./doc":12,"./environment":14,"./globals":15,"./io/io":18,"./kernels/backend_cpu":22,"./kernels/backend_webgl":24,"./kernels/webgl/gpgpu_util":38,"./kernels/webgl/webgl_util":58,"./ops/loss_ops":72,"./ops/ops":79,"./optimizers/adadelta_optimizer":91,"./optimizers/adagrad_optimizer":92,"./optimizers/adam_optimizer":93,"./optimizers/adamax_optimizer":94,"./optimizers/momentum_optimizer":95,"./optimizers/optimizer":96,"./optimizers/rmsprop_optimizer":98,"./optimizers/sgd_optimizer":99,"./tensor":102,"./test_util":104,"./train":106,"./types":107,"./util":108,"./version":109}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./io_utils");n.decodeWeights=r.decodeWeights,n.encodeWeights=r.encodeWeights;var o=e("./weights_loader");n.loadWeights=o.loadWeights},{"./io_utils":19,"./weights_loader":21}],19:[function(e,t,n){"use strict";function r(e){if(null===e)throw new Error("Invalid input value: "+JSON.stringify(e));var t=0;e.forEach(function(e){if(e instanceof Float32Array||e instanceof Int32Array)t+=4*e.length;else{if(!(e instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+e.constructor.name);t+=e.length}});var n=new Uint8Array(t),r=0;return e.forEach(function(e){n.set(new Uint8Array(e.buffer),r),e instanceof Float32Array||e instanceof Int32Array?r+=4*e.length:r+=e.length}),n.buffer}var o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(i,s)}u((r=r.apply(e,t||[])).next())})},a=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,a&&(i=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(i=i.call(a,n[1])).done)return i;switch(a=0,i&&(n=[0,i.value]),n[0]){case 0:case 1:i=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){u.label=n[1];break}if(6===n[0]&&u.label<i[1]){u.label=i[1],i=n;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(n);break}i[2]&&u.ops.pop(),u.trys.pop();continue}n=t.call(e,u)}catch(e){n=[6,e],a=0}finally{o=i=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,a,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../ops/array_ops"),s=e("../util"),u=e("./types");n.encodeWeights=function(e){return o(this,void 0,void 0,function(){var t,n,o,i,s;return a(this,function(a){switch(a.label){case 0:t=[],n=[];for(o in e){if("float32"!==(i=e[o]).dtype&&"int32"!==i.dtype&&"bool"!==i.dtype)throw new Error("Unsupported dtype in weight '"+o+"': "+i.dtype);t.push({name:o,shape:i.shape,dtype:i.dtype}),n.push(i.data())}return[4,Promise.all(n)];case 1:return s=a.sent(),[2,{data:r(s),specs:t}]}})})},n.decodeWeights=function(e,t){for(var n={},r=0,o=0,a=t;o<a.length;o++){var c=a[o],l=c.name,p=c.dtype,d=c.shape;if(null!=c.quantization)throw new Error("decodeWeights does not support quantization yet, but encountered weight '"+l+" with quantization.'");var h=s.sizeFromShape(d),f=void 0;if("float32"===p)f=i.ArrayOps.tensor(new Float32Array(e,r,h),d,"float32");else if("int32"===p)f=i.ArrayOps.tensor(new Int32Array(e,r,h),d,"int32");else{if("bool"!==p)throw new Error("Unsupported dtype in weight '"+l+"': "+p);f=i.ArrayOps.tensor(new Uint8Array(e,r,h),d,"bool")}n[l]=f,r+=h*u.DTYPE_VALUE_SIZE_MAP[p]}return n},n.concatenateTypedArrays=r},{"../ops/array_ops":59,"../util":108,"./types":20}],20:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.DTYPE_VALUE_SIZE_MAP={float32:4,int32:4,uint16:2,uint8:1,bool:1}},{}],21:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(i,s)}u((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,a&&(i=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(i=i.call(a,n[1])).done)return i;switch(a=0,i&&(n=[0,i.value]),n[0]){case 0:case 1:i=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){u.label=n[1];break}if(6===n[0]&&u.label<i[1]){u.label=i[1],i=n;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(n);break}i[2]&&u.ops.pop(),u.trys.pop();continue}n=t.call(e,u)}catch(e){n=[6,e],a=0}finally{o=i=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,a,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(n,"__esModule",{value:!0});var a=e("../ops/ops"),i=e("../util"),s=e("./types");n.loadWeights=function(e,t,n,u){return void 0===t&&(t=""),r(this,void 0,void 0,function(){var r,c,l,p,d,h,f,g,m,v,y;return o(this,function(o){switch(o.label){case 0:if(r=e.map(function(){return!1}),c={},l=null!=n?n.map(function(){return!1}):[],p=[],e.forEach(function(e,t){var o=0;e.weights.forEach(function(e){var a="quantization"in e?e.quantization.dtype:e.dtype,u=s.DTYPE_VALUE_SIZE_MAP[a]*i.sizeFromShape(e.shape),d=function(){r[t]=!0,null==c[t]&&(c[t]=[]),c[t].push({manifestEntry:e,groupOffset:o,sizeBytes:u})};null!=n?n.forEach(function(t,n){t===e.name&&(d(),l[n]=!0)}):d(),p.push(e.name),o+=u})}),!l.every(function(e){return e}))throw d=n.filter(function(e,t){return!l[t]}),new Error("Could not find weights in manifest with names: "+d.join(", ")+". \nManifest JSON has weights with names: "+p.join(", ")+".");return h=r.reduce(function(e,t,n){return t&&e.push(n),e},[]),f=[],h.forEach(function(n){e[n].paths.forEach(function(e){var n=t+(t.endsWith("/")?"":"/")+e;f.push(fetch(n,u))})}),[4,Promise.all(f)];case 1:return g=o.sent(),[4,Promise.all(g.map(function(e){return e.arrayBuffer()}))];case 2:return m=o.sent(),v={},y=0,h.forEach(function(t){for(var n=e[t].paths.length,r=0,o=0;o<n;o++)r+=m[y+o].byteLength;for(var i=new ArrayBuffer(r),s=new Uint8Array(i),u=0,l=0;l<n;l++){var p=new Uint8Array(m[y+l]);s.set(p,u),u+=p.byteLength}c[t].forEach(function(e){var t,n=i.slice(e.groupOffset,e.groupOffset+e.sizeBytes),r=e.manifestEntry.dtype;if("quantization"in e.manifestEntry){var o=e.manifestEntry.quantization;if("uint8"!==o.dtype&&"uint16"!==o.dtype)throw new Error("Weight "+e.manifestEntry.name+" has unknown quantization dtype "+o.dtype+".");var s="uint8"===o.dtype?new Uint8Array(n):new Uint16Array(n);if("float32"===r)t=Float32Array.from(s,function(e){return e*o.scale+o.min});else{if("int32"!==r)throw new Error("Weight "+e.manifestEntry.name+" has a dtype not supported by quantization: "+r);t=Int32Array.from(s,function(e){return Math.round(e*o.scale+o.min)})}}else if("float32"===r)t=new Float32Array(n);else{if("int32"!==r)throw new Error("Weight "+e.manifestEntry.name+" has unknown dtype "+r+".");t=new Int32Array(n)}var u=e.manifestEntry.name;if(null!=v[u])throw new Error("Duplicate weight with name "+u+". Please make sure weights names are unique in the manifest JSON.");v[u]=a.tensor(t,e.manifestEntry.shape,e.manifestEntry.dtype)}),y+=n}),[2,v]}})})}},{"../ops/ops":79,"../util":108,"./types":20}],22:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(i,s)}u((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,a&&(i=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(i=i.call(a,n[1])).done)return i;switch(a=0,i&&(n=[0,i.value]),n[0]){case 0:case 1:i=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){u.label=n[1];break}if(6===n[0]&&u.label<i[1]){u.label=i[1],i=n;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(n);break}i[2]&&u.ops.pop(),u.trys.pop();continue}n=t.call(e,u)}catch(e){n=[6,e],a=0}finally{o=i=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,a,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(n,"__esModule",{value:!0});var a=e("seedrandom"),i=e("../environment"),s=e("../ops/axis_util"),u=e("../ops/broadcast_util"),c=e("../ops/concat_util"),l=e("../ops/ops"),p=e("../ops/ops"),d=e("../ops/selu_util"),h=e("../ops/erf_util"),f=e("../tensor"),g=e("../types"),m=e("../util"),v=e("./backend_util"),y=function(){function e(){this.data=new WeakMap,"undefined"!=typeof document&&(this.canvas=document.createElement("canvas"))}return e.prototype.register=function(e,t,n){if(this.data.has(e))throw new Error("Data buffer is already registered");this.data.set(e,null)},e.prototype.write=function(e,t){if(null==t)throw new Error("MathBackendCPU.write(): values can not be null");this.throwIfNoData(e),this.data.set(e,t)},e.prototype.fromPixels=function(e,t){if(null==e)throw new Error("MathBackendCPU.writePixels(): pixels can not be null");var n;if(e instanceof ImageData)n=e.data;else if(e instanceof HTMLCanvasElement)n=e.getContext("2d").getImageData(0,0,e.width,e.height).data;else{if(!(e instanceof HTMLImageElement||e instanceof HTMLVideoElement))throw new Error("pixels is of unknown type: "+e.constructor.name);if(null==this.canvas)throw new Error("Can't read pixels from HTMLImageElement outside the browser.");this.canvas.width=e.width,this.canvas.height=e.height,this.canvas.getContext("2d").drawImage(e,0,0,e.width,e.height),n=this.canvas.getContext("2d").getImageData(0,0,e.width,e.height).data}var r;if(4===t)r=new Int32Array(n);else{var o=e.width*e.height;r=new Int32Array(o*t);for(var a=0;a<o;a++)for(var i=0;i<t;++i)r[a*t+i]=n[4*a+i]}var s=[e.height,e.width,t];return p.tensor3d(r,s,"int32")},e.prototype.read=function(e){return r(this,void 0,void 0,function(){return o(this,function(t){return[2,this.readSync(e)]})})},e.prototype.readSync=function(e){return this.throwIfNoData(e),this.data.get(e)},e.prototype.disposeData=function(e){this.data.has(e)&&this.data.delete(e)},e.prototype.time=function(e){return r(this,void 0,void 0,function(){var t,n;return o(this,function(r){return t=performance.now(),e(),n=performance.now()-t,[2,{kernelMs:n}]})})},e.prototype.memory=function(){return{unreliable:!0}},e.prototype.throwIfNoData=function(e){if(!this.data.has(e))throw new Error("CPU backend: No data found for this tensor. Did you change your backend in the middle of the program? New backends can't use Tensors created with previous backends")},e.prototype.slice=function(e,t,n){for(var r=l.buffer(n,e.dtype),o=0;o<r.size;++o){var a=r.indexToLoc(o),i=a.map(function(e,n){return e+t[n]});r.set.apply(r,[e.get.apply(e,i)].concat(a))}return r.toTensor()},e.prototype.reverse=function(e,t){for(var n=l.buffer(e.shape,e.dtype),r=e.buffer(),o=0;o<n.size;o++)!function(o){var a=n.indexToLoc(o),i=a.slice();t.forEach(function(t){return i[t]=e.shape[t]-1-i[t]}),n.set.apply(n,[r.get.apply(r,i)].concat(a))}(o);return n.toTensor()},e.prototype.concat=function(e,t){var n=c.computeOutShape(e.shape,t.shape,1),r=l.buffer(n,e.dtype);if(1===e.shape[0]&&1===t.shape[0]){var o=e.dataSync(),a=t.dataSync(),i=r.values;return i.set(o,0),i.set(a,e.size),r.toTensor()}for(var s=0;s<n[0];++s){for(u=0;u<e.shape[1];++u)r.set(e.get(s,u),s,u);for(var u=0;u<t.shape[1];++u)r.set(t.get(s,u),s,u+e.shape[1])}return r.toTensor()},e.prototype.neg=function(e){return this.multiply(l.scalar(-1),e)},e.prototype.add=function(e,t){return this.broadcastedBinaryOp(e,t,g.upcastType(e.dtype,t.dtype),function(e,t){return e+t})},e.prototype.subtract=function(e,t){return this.broadcastedBinaryOp(e,t,g.upcastType(e.dtype,t.dtype),function(e,t){return e-t})},e.prototype.pow=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){return Math.pow(e,t)})},e.prototype.matMul=function(e,t,n,r){for(var o=n?e.shape[0]:e.shape[1],a=n?e.shape[1]:e.shape[0],i=r?t.shape[0]:t.shape[1],s=e.dataSync(),u=t.dataSync(),c=n?[1,e.strides[0]]:[e.strides[0],1],p=c[0],d=c[1],h=r?[t.strides[0],1]:[1,t.strides[0]],f=h[0],g=h[1],m=a*p,v=i*f,y=new Float32Array(a*i),b=0,x=0;x<m;x+=p)for(var w=0;w<v;w+=f){for(var E=x,A=w,T=0,_=0;_<o;++_)T+=s[E]*u[A],E+=d,A+=g;y[b++]=T}return l.tensor2d(y,[a,i])},e.prototype.multiply=function(e,t){return this.broadcastedBinaryOp(e,t,g.upcastType(e.dtype,t.dtype),function(e,t){return e*t})},e.prototype.divide=function(e,t){var n,r;return"int32"===e.dtype&&"int32"===t.dtype?(r="int32",n=function(e,t){return Math.floor(e/t)}):(r="float32",n=function(e,t){return e/t}),this.broadcastedBinaryOp(e,t,r,n)},e.prototype.sum=function(e,t){s.assertAxesAreInnerMostDims("sum",t,e.rank);for(var n=s.computeOutAndReduceShapes(e.shape,t),r=n[0],o=n[1],a=g.upcastType(e.dtype,"int32"),i=l.zeros(r,a),u=m.sizeFromShape(o),c=i.dataSync(),p=e.dataSync(),d=0;d<c.length;++d){for(var h=d*u,f=0,v=0;v<u;++v)f+=p[h+v];c[d]=f}return i},e.prototype.argMin=function(e,t){var n=[t];s.assertAxesAreInnerMostDims("argMin",n,e.rank);for(var r=s.computeOutAndReduceShapes(e.shape,n),o=r[0],a=r[1],i=l.zeros(o,"int32"),u=m.sizeFromShape(a),c=i.dataSync(),p=e.dataSync(),d=0;d<c.length;++d){for(var h=d*u,f=p[h],g=0,v=0;v<u;++v){var y=p[h+v];y<f&&(f=y,g=v)}c[d]=g}return i},e.prototype.argMax=function(e,t){var n=[t];s.assertAxesAreInnerMostDims("argMax",n,e.rank);for(var r=s.computeOutAndReduceShapes(e.shape,n),o=r[0],a=r[1],i=l.zeros(o,"int32"),u=m.sizeFromShape(a),c=i.dataSync(),p=e.dataSync(),d=0;d<c.length;++d){for(var h=d*u,f=p[h],g=0,v=0;v<u;++v){var y=p[h+v];y>f&&(f=y,g=v)}c[d]=g}return i},e.prototype.equal=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e===t?1:0})},e.prototype.notEqual=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e!==t?1:0})},e.prototype.less=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e<t?1:0})},e.prototype.lessEqual=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e<=t?1:0})},e.prototype.greater=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e>t?1:0})},e.prototype.greaterEqual=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e>=t?1:0})},e.prototype.logicalNot=function(e){for(var t=e.dataSync(),n=new Int32Array(t.length),r=0;r<t.length;++r)n[r]=t[r]?0:1;return f.Tensor.make(e.shape,{values:n},"bool")},e.prototype.logicalAnd=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e&&t})},e.prototype.logicalOr=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(e,t){return e||t})},e.prototype.where=function(e,t,n,r){for(var o=e.dataSync(),a=t.dataSync(),i=n.dataSync(),s=l.zeros(t.shape,r),u=s.dataSync(),c=0,p=0===e.rank||e.rank>1||1===t.rank?1:t.shape[1],d=0;d<o.length;d++)for(var h=0;h<p;h++)1===o[d]?u[c++]=a[d]:u[c++]=i[d];return s},e.prototype.topKValues=function(e,t){return this.topK(e,t).values},e.prototype.topKIndices=function(e,t){return this.topK(e,t).indices},e.prototype.topK=function(e,t){for(var n=e.dataSync(),r=[],o=0;o<n.length;o++)r.push({value:n[o],index:o});r.sort(function(e,t){return t.value-e.value});for(var a=m.getTypedArrayFromDType(e.dtype,t),i=new Int32Array(t),o=0;o<t;o++)a[o]=r[o].value,i[o]=r[o].index;return{values:l.tensor1d(a,e.dtype),indices:l.tensor1d(i,"int32")}},e.prototype.min=function(e,t){s.assertAxesAreInnerMostDims("min",t,e.rank);for(var n=s.computeOutAndReduceShapes(e.shape,t),r=n[0],o=n[1],a=l.zeros(r,e.dtype),i=m.sizeFromShape(o),u=a.dataSync(),c=e.dataSync(),p=0;p<u.length;++p){for(var d=p*i,h=c[0],f=0;f<i;++f){var g=c[d+f];g<h&&(h=g)}u[p]=h}return a},e.prototype.minimum=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){return Math.min(e,t)})},e.prototype.mod=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){var n=e%t;return e<0&&t<0||e>=0&&t>=0?n:(n+t)%t})},e.prototype.max=function(e,t){s.assertAxesAreInnerMostDims("max",t,e.rank);for(var n=s.computeOutAndReduceShapes(e.shape,t),r=n[0],o=n[1],a=l.zeros(r,e.dtype),i=m.sizeFromShape(o),u=a.dataSync(),c=e.dataSync(),p=0;p<u.length;++p){for(var d=p*i,h=c[d],f=0;f<i;++f){var g=c[d+f];g>h&&(h=g)}u[p]=h}return a},e.prototype.maximum=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){return Math.max(e,t)})},e.prototype.squaredDifference=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){var n=e-t;return n*n})},e.prototype.ceil=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r<t.length;++r)n[r]=Math.ceil(t[r]);return f.Tensor.make(e.shape,{values:n})},e.prototype.floor=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r<t.length;++r)n[r]=Math.floor(t[r]);return f.Tensor.make(e.shape,{values:n})},e.prototype.sign=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r<t.length;++r)t[r]<0?n[r]=-1:t[r]>0?n[r]=1:n[r]=0;return f.Tensor.make(e.shape,{values:n})},e.prototype.round=function(e){for(var t=e.dataSync(),n=new Floa