-
Notifications
You must be signed in to change notification settings - Fork 0
/
deeplearn.min.js
1 lines (1 loc) · 266 KB
/
deeplearn.min.js
1
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).deeplearn=t()}}(function(){return function t(e,r,n){function a(i,s){if(!r[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(o)return o(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var p=r[i]={exports:{}};e[i][0].call(p.exports,function(t){var r=e[i][1][t];return a(r||t)},p,p.exports,t,e,r,n)}return r[i].exports}for(var o="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}({1:[function(t,e,r){},{}],2:[function(t,e,r){var n=t("./lib/alea"),a=t("./lib/xor128"),o=t("./lib/xorwow"),i=t("./lib/xorshift7"),s=t("./lib/xor4096"),u=t("./lib/tychei"),c=t("./seedrandom");c.alea=n,c.xor128=a,c.xorwow=o,c.xorshift7=i,c.xor4096=s,c.tychei=u,e.exports=c},{"./lib/alea":3,"./lib/tychei":4,"./lib/xor128":5,"./lib/xor4096":6,"./lib/xorshift7":7,"./lib/xorwow":8,"./seedrandom":9}],3:[function(t,e,r){!function(t,e,r){function n(t){var e=this,r=i();e.next=function(){var t=2091639*e.s0+2.3283064365386963e-10*e.c;return e.s0=e.s1,e.s1=e.s2,e.s2=t-(e.c=0|t)},e.c=1,e.s0=r(" "),e.s1=r(" "),e.s2=r(" "),e.s0-=r(t),e.s0<0&&(e.s0+=1),e.s1-=r(t),e.s1<0&&(e.s1+=1),e.s2-=r(t),e.s2<0&&(e.s2+=1),r=null}function a(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function o(t,e){var r=new n(t),o=e&&e.state,i=r.next;return i.int32=function(){return 4294967296*r.next()|0},i.double=function(){return i()+1.1102230246251565e-16*(2097152*i()|0)},i.quick=i,o&&("object"==typeof o&&a(o,r),i.state=function(){return a(r,{})}),i}function i(){var t=4022871197;return function(e){e=e.toString();for(var r=0;r<e.length;r++){var n=.02519603282416938*(t+=e.charCodeAt(r));n-=t=n>>>0,t=(n*=t)>>>0,t+=4294967296*(n-=t)}return 2.3283064365386963e-10*(t>>>0)}}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.alea=o}(0,"object"==typeof e&&e,!1)},{}],4:[function(t,e,r){!function(t,e,r){function n(t){var e=this,r="";e.next=function(){var t=e.b,r=e.c,n=e.d,a=e.a;return t=t<<25^t>>>7^r,r=r-n|0,n=n<<24^n>>>8^a,a=a-t|0,e.b=t=t<<20^t>>>12^r,e.c=r=r-n|0,e.d=n<<16^r>>>16^a,e.a=a-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):r+=t;for(var n=0;n<r.length+20;n++)e.b^=0|r.charCodeAt(n),e.next()}function a(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function o(t,e){var r=new n(t),o=e&&e.state,i=function(){return(r.next()>>>0)/4294967296};return i.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},i.int32=r.next,i.quick=i,o&&("object"==typeof o&&a(o,r),i.state=function(){return a(r,{})}),i}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.tychei=o}(0,"object"==typeof e&&e,!1)},{}],5:[function(t,e,r){!function(t,e,r){function n(t){var e=this,r="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:r+=t;for(var n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),e.next()}function a(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function o(t,e){var r=new n(t),o=e&&e.state,i=function(){return(r.next()>>>0)/4294967296};return i.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},i.int32=r.next,i.quick=i,o&&("object"==typeof o&&a(o,r),i.state=function(){return a(r,{})}),i}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.xor128=o}(0,"object"==typeof e&&e,!1)},{}],6:[function(t,e,r){!function(t,e,r){function n(t){var e=this;e.next=function(){var t,r,n=e.w,a=e.X,o=e.i;return e.w=n=n+1640531527|0,r=a[o+34&127],t=a[o=o+1&127],r^=r<<13,t^=t<<17,r^=r>>>15,t^=t>>>12,r=a[o]=r^t,e.i=o,r+(n^n>>>16)|0},function(t,e){var r,n,a,o,i,s=[],u=128;for(e===(0|e)?(n=e,e=null):(e+="\0",n=0,u=Math.max(u,e.length)),a=0,o=-32;o<u;++o)e&&(n^=e.charCodeAt((o+32)%e.length)),0===o&&(i=n),n^=n<<10,n^=n>>>15,n^=n<<4,n^=n>>>13,o>=0&&(i=i+1640531527|0,a=0==(r=s[127&o]^=n+i)?a+1:0);for(a>=128&&(s[127&(e&&e.length||0)]=-1),a=127,o=512;o>0;--o)n=s[a+34&127],r=s[a=a+1&127],n^=n<<13,r^=r<<17,n^=n>>>15,r^=r>>>12,s[a]=n^r;t.w=i,t.X=s,t.i=a}(e,t)}function a(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function o(t,e){null==t&&(t=+new Date);var r=new n(t),o=e&&e.state,i=function(){return(r.next()>>>0)/4294967296};return i.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},i.int32=r.next,i.quick=i,o&&(o.X&&a(o,r),i.state=function(){return a(r,{})}),i}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.xor4096=o}(0,"object"==typeof e&&e,!1)},{}],7:[function(t,e,r){!function(t,e,r){function n(t){var e=this;e.next=function(){var t,r,n=e.x,a=e.i;return t=n[a],t^=t>>>7,r=t^t<<24,t=n[a+1&7],r^=t^t>>>10,t=n[a+3&7],r^=t^t>>>3,t=n[a+4&7],r^=t^t<<7,t=n[a+7&7],t^=t<<13,r^=t^t<<9,n[a]=r,e.i=a+1&7,r},function(t,e){var r,n=[];if(e===(0|e))n[0]=e;else for(e=""+e,r=0;r<e.length;++r)n[7&r]=n[7&r]<<15^e.charCodeAt(r)+n[r+1&7]<<13;for(;n.length<8;)n.push(0);for(r=0;r<8&&0===n[r];++r);for(8==r?n[7]=-1:n[r],t.x=n,t.i=0,r=256;r>0;--r)t.next()}(e,t)}function a(t,e){return e.x=t.x.slice(),e.i=t.i,e}function o(t,e){null==t&&(t=+new Date);var r=new n(t),o=e&&e.state,i=function(){return(r.next()>>>0)/4294967296};return i.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},i.int32=r.next,i.quick=i,o&&(o.x&&a(o,r),i.state=function(){return a(r,{})}),i}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.xorshift7=o}(0,"object"==typeof e&&e,!1)},{}],8:[function(t,e,r){!function(t,e,r){function n(t){var e=this,r="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:r+=t;for(var n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),n==r.length&&(e.d=e.x<<10^e.x>>>4),e.next()}function a(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function o(t,e){var r=new n(t),o=e&&e.state,i=function(){return(r.next()>>>0)/4294967296};return i.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},i.int32=r.next,i.quick=i,o&&("object"==typeof o&&a(o,r),i.state=function(){return a(r,{})}),i}e&&e.exports?e.exports=o:r&&r.amd?r(function(){return o}):this.xorwow=o}(0,"object"==typeof e&&e,!1)},{}],9:[function(t,e,r){!function(r,n){function a(t,e,a){var l=[],h=u(s((e=1==e?{entropy:!0}:e||{}).entropy?[t,p(r)]:null==t?c():t,3),l),x=new o(l),w=function(){for(var t=x.g(d),e=m,r=0;t<y;)t=(t+r)*f,e*=f,r=x.g(1);for(;t>=g;)t/=2,e/=2,r>>>=1;return(t+r)/e};return w.int32=function(){return 0|x.g(4)},w.quick=function(){return x.g(4)/4294967296},w.double=w,u(p(x.S),r),(e.pass||a||function(t,e,r,a){return a&&(a.S&&i(a,x),t.state=function(){return i(x,{})}),r?(n[v]=t,e):t})(w,h,"global"in e?e.global:this==n,e.state)}function o(t){var e,r=t.length,n=this,a=0,o=n.i=n.j=0,i=n.S=[];for(r||(t=[r++]);a<f;)i[a]=a++;for(a=0;a<f;a++)i[a]=i[o=x&o+t[a%r]+(e=i[a])],i[o]=e;(n.g=function(t){for(var e,r=0,a=n.i,o=n.j,i=n.S;t--;)e=i[a=x&a+1],r=r*f+i[x&(i[a]=i[o=x&o+e])+(i[o]=e)];return n.i=a,n.j=o,r})(f)}function i(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function s(t,e){var r,n=[],a=typeof t;if(e&&"object"==a)for(r in t)try{n.push(s(t[r],e-1))}catch(t){}return n.length?n:"string"==a?t:t+"\0"}function u(t,e){for(var r,n=t+"",a=0;a<n.length;)e[x&a]=x&(r^=19*e[x&a])+n.charCodeAt(a++);return p(e)}function c(){try{var t;return l&&(t=l.randomBytes)?t=t(f):(t=new Uint8Array(f),(h.crypto||h.msCrypto).getRandomValues(t)),p(t)}catch(t){var e=h.navigator,n=e&&e.plugins;return[+new Date,h,n,h.screen,p(r)]}}function p(t){return String.fromCharCode.apply(0,t)}var l,h=this,f=256,d=6,v="random",m=n.pow(f,d),y=n.pow(2,52),g=2*y,x=f-1;if(n["seed"+v]=a,u(n.random(),r),"object"==typeof e&&e.exports){e.exports=a;try{l=t("crypto")}catch(t){}}}([],Math)},{crypto:1}],10:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../math/ndarray"),a=function(){function t(t){this.urlPath=t,"/"!==this.urlPath.charAt(this.urlPath.length-1)&&(this.urlPath+="/")}return t.prototype.loadManifest=function(){var t=this;return new Promise(function(e,r){var n=new XMLHttpRequest;n.open("GET",t.urlPath+"manifest.json"),n.onload=function(){t.checkpointManifest=JSON.parse(n.responseText),e()},n.onerror=function(e){throw new Error("manifest.json not found at "+t.urlPath+". "+e)},n.send()})},t.prototype.getCheckpointManifest=function(){var t=this;return null==this.checkpointManifest?new Promise(function(e,r){t.loadManifest().then(function(){e(t.checkpointManifest)})}):new Promise(function(e,r){e(t.checkpointManifest)})},t.prototype.getAllVariables=function(){var t=this;return null!=this.variables?new Promise(function(e,r){e(t.variables)}):new Promise(function(e,r){t.getCheckpointManifest().then(function(r){for(var n=Object.keys(t.checkpointManifest),a=[],o=0;o<n.length;o++)a.push(t.getVariable(n[o]));Promise.all(a).then(function(r){t.variables={};for(var a=0;a<r.length;a++)t.variables[n[a]]=r[a];e(t.variables)})})})},t.prototype.getVariable=function(t){var e=this;if(!(t in this.checkpointManifest))throw new Error("Cannot load non-existant variable "+t);var r=function(r,a){var o=new XMLHttpRequest;o.responseType="arraybuffer";var i=e.checkpointManifest[t].filename;o.open("GET",e.urlPath+i),o.onload=function(){var a=new Float32Array(o.response),i=n.NDArray.make(e.checkpointManifest[t].shape,{values:a});r(i)},o.onerror=function(e){throw new Error("Could not fetch variable "+t+": "+e)},o.send()};return null==this.checkpointManifest?new Promise(function(t,n){e.loadManifest().then(function(){new Promise(r).then(t)})}):new Promise(r)},t}();r.CheckpointLoader=a},{"../math/ndarray":63}],11:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../math/ndarray"),a=t("../util"),o=function(){function t(t){this.dataShapes=t,this.normalizationInfo={}}return t.prototype.getDataShape=function(t){return this.dataShapes[t]},t.prototype.getData=function(){return this.dataset},t.prototype.getStats=function(){var t=this;if(null==this.dataset)throw new Error("Data is null.");return this.dataset.map(function(e){return t.getStatsForData(e)})},t.prototype.getStatsForData=function(t){var e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,n=t.map(function(t,e){return e});a.shuffle(n),n=n.slice(.1*n.length);for(var o=0;o<n.length;o++)for(var i=t[n[o]].getValues(),s=0;s<i.length;s++)e=Math.min(e,i[s]),r=Math.max(r,i[s]);return{inputMin:e,inputMax:r,exampleCount:t.length,shape:t[0].shape}},t.prototype.normalizeExamplesToRange=function(t,e,r,o,i){var s=r instanceof Float32Array&&e instanceof Float32Array,u=o instanceof Float32Array&&i instanceof Float32Array,c=a.sizeFromShape(t[0].shape),p=[];return t.forEach(function(t){for(var a=t.getValues(),l=new Float32Array(c),h=0;h<c;h++){var f=s?e[h]:e,d=(s?r[h]:r)-f,v=u?o[h]:o,m=(u?i[h]:i)-v;l[h]=0===d?v:v+m*(a[h]-f)/d}p.push(n.NDArray.make(t.shape,{values:l}))}),p},t.prototype.computeBounds=function(t){var e=this;if(null==this.dataset)throw new Error("Data is null.");var r=a.sizeFromShape(this.dataset[t][0].shape);this.normalizationInfo[t]={isNormalized:!1,minValues:new Float32Array(r),maxValues:new Float32Array(r)};for(var n=0;n<r;n++)this.normalizationInfo[t].minValues[n]=Number.POSITIVE_INFINITY,this.normalizationInfo[t].maxValues[n]=Number.NEGATIVE_INFINITY;this.dataset[t].forEach(function(n){for(var a=n.getValues(),o=0;o<r;o++)e.normalizationInfo[t].minValues[o]=Math.min(e.normalizationInfo[t].minValues[o],a[o]),e.normalizationInfo[t].maxValues[o]=Math.max(e.normalizationInfo[t].maxValues[o],a[o])})},t.prototype.normalizeWithinBounds=function(t,e,r){if(null==this.dataset)throw new Error("Data is null.");if(t>=this.dataset.length)throw new Error("dataIndex out of bounds.");null==this.normalizationInfo[t]&&this.computeBounds(t);var n,a;this.normalizationInfo[t].isNormalized?(n=this.normalizationInfo[t].lowerBound,a=this.normalizationInfo[t].upperBound):(n=this.normalizationInfo[t].minValues,a=this.normalizationInfo[t].maxValues),this.dataset[t]=this.normalizeExamplesToRange(this.dataset[t],n,a,e,r),this.normalizationInfo[t].isNormalized=!0,this.normalizationInfo[t].lowerBound=e,this.normalizationInfo[t].upperBound=r},t.prototype.isNormalized=function(t){return null!=this.normalizationInfo&&this.normalizationInfo[t].isNormalized},t.prototype.removeNormalization=function(t){if(null==this.dataset)throw new Error("Training or test data is null.");this.isNormalized(t)&&(this.dataset[t]=this.normalizeExamplesToRange(this.dataset[t],this.normalizationInfo[t].lowerBound,this.normalizationInfo[t].upperBound,this.normalizationInfo[t].minValues,this.normalizationInfo[t].maxValues),this.normalizationInfo[t].isNormalized=!1)},t.prototype.unnormalizeExamples=function(t,e){return this.isNormalized(e)?this.normalizeExamplesToRange(t,this.normalizationInfo[e].lowerBound,this.normalizationInfo[e].upperBound,this.normalizationInfo[e].minValues,this.normalizationInfo[e].maxValues):t},t.prototype.dispose=function(){if(null!=this.dataset){for(var t=0;t<this.dataset.length;t++)for(var e=0;e<this.dataset[t].length;e++)this.dataset[t][e].dispose();this.dataset=[]}},t}();r.InMemoryDataset=o},{"../math/ndarray":63,"../util":96}],12:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../math/ndarray"),o=t("../util"),i=function(){function t(t){this.inputs=t,this.idx=0,this.inputCounter=0,this.epoch=0,this.shuffledIndices=o.createShuffledIndices(t[0].length),this.numInputs=t.length;for(var e=this.inputs[0].length,r=0;r<this.numInputs;r++)o.assert(this.inputs[r].length===e,"Number of examples must match across different inputs.");for(r=0;r<this.numInputs;r++)for(var n=this.inputs[r][0].shape,a=0;a<this.inputs[r].length;a++)o.assertShapesMatch(n,this.inputs[r][a].shape)}return t.prototype.getCurrentExampleIndex=function(){var t=this.idx;return++this.inputCounter>=this.numInputs&&(this.idx++,this.inputCounter=0,this.idx>=this.inputs[0].length&&(this.idx=0,this.epoch++)),t},t.prototype.getNextInput=function(t){var e=this.getCurrentExampleIndex();return this.inputs[t][this.shuffledIndices[e]]},t.prototype.getEpoch=function(){return this.epoch},t.prototype.getInputProviders=function(){for(var t=[],e=0;e<this.numInputs;e++)t.push(this.getInputProvider(e));return t},t}();r.InMemoryShuffledInputProviderBuilder=i;var s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.getInputProvider=function(t){var e=this;return{getNextCopy:function(r){return a.NDArray.like(e.getNextInput(t))},disposeCopy:function(t,e){e.dispose()}}},e}(i);r.InCPUMemoryShuffledInputProviderBuilder=s;var u=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.getInputProvider=function(t){var e=this;return{getNextCopy:function(r){return r.clone(e.getNextInput(t))},disposeCopy:function(t,e){e.dispose()}}},e}(i);r.InGPUMemoryShuffledInputProviderBuilder=u},{"../math/ndarray":63,"../util":96}],13:[function(t,e,r){"use strict";function n(t){return new Promise(function(e,r){var n=new XMLHttpRequest;n.open("GET",t.path),n.responseType="arraybuffer",n.onload=function(r){var a="float32"===t.dataType?new Float32Array(n.response):new Uint8Array(n.response);e(a)},n.onerror=function(t){return r(t)},n.send()})}function a(t,e,r){for(var n=r,a=0;a<t.length;a+=4)e[n++]=t[a]}function o(t,e,r){for(var n=r,a=0;a<t.length;a+=4)e[n]=t[a],e[n+1]=t[a+1],e[n+2]=t[a+2],n+=3}function i(t,e){var r=document.createElement("canvas"),n=r.getContext("2d"),i=t.height,s=p.sizeFromShape(e),u=new Uint8Array(i*s);if(t.width!==e[0]*e[1])throw new Error("Image width ("+t.width+") must be multiple of rows*columns ("+e[0]+"*"+e[1]+") of the ndarray");r.width=t.width,r.height=h;for(var c=r.width,l=r.height,f=c,d=l,v=e[2],m=0,y=Math.ceil(i/r.height),g=0;g<y;++g){var x=g*r.height;g===y-1&&i%r.height>0&&(r.height=i%r.height,d=l=r.height),n.drawImage(t,0,x,c,l,0,0,f,d);var w=n.getImageData(0,0,r.width,r.height).data;1===v?a(w,u,m):o(w,u,m),m+=r.height*s}return u}function s(t,e){return new Promise(function(r,n){var a=new Image;a.setAttribute("crossOrigin",""),a.onload=function(){var t=i(a,e);a.src="",a=null,r(t)},a.src=t.path})}var u=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var c=t("../math/ndarray"),p=t("../util"),l=t("./dataset"),h=1e3;r.getXhrDatasetConfig=function(t){return new Promise(function(e,r){var n=new XMLHttpRequest;n.open("GET",t),n.onload=function(){e(JSON.parse(n.responseText))},n.onerror=function(t){r(t)},n.send()})};var f=function(t){function e(e){var r=t.call(this,e.data.map(function(t){return t.shape}))||this;return r.xhrDatasetConfig=e,r}return u(e,t),e.prototype.getNDArray=function(t){return("png"===t.dataType?s(t,t.shape):n(t)).then(function(e){for(var r=p.sizeFromShape(t.shape),n=[],a=0;a<e.length/r;a++){var o=e.subarray(a*r,(a+1)*r),i=c.NDArray.make(t.shape,{values:new Float32Array(o)});n.push(i)}return n})},e.prototype.fetchData=function(){var t=this;return new Promise(function(e,r){var n=t.xhrDatasetConfig.data.map(function(e){return t.getNDArray(e)});Promise.all(n).then(function(r){t.dataset=r,e()})})},e}(l.InMemoryDataset);r.XhrDataset=f},{"../math/ndarray":63,"../util":96,"./dataset":11}],14:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.isMobile=function(){var t=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(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))}},{}],15:[function(t,e,r){"use strict";function n(t){if(0===t)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var e=document.createElement("canvas");return 1===t?e.getContext("webgl")||e.getContext("experimental-webgl"):e.getContext("webgl2")}function a(t){if(null!=t){var e=t.getExtension("WEBGL_lose_context");if(null==e)throw new Error("Extension WEBGL_lose_context not supported on this browser.");e.loseContext()}}function o(t){var e=n(t);return null!=e&&(a(e),!0)}function i(t){var e=n(t),r=1===t?"EXT_disjoint_timer_query":"EXT_disjoint_timer_query_webgl2",o=null!=e.getExtension(r);return null!=e&&a(e),o}function s(t){if(0===t)return!1;var e=n(t);if(1===t){if(null==e.getExtension("OES_texture_float"))return!1}else if(null==e.getExtension("EXT_color_buffer_float"))return!1;var r=e.createFramebuffer(),o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o);var i=2===t?e.RGBA32F:e.RGBA;e.texImage2D(e.TEXTURE_2D,0,i,1,1,0,e.RGBA,e.FLOAT,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0);var s=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;e.readPixels(0,0,1,1,e.RGBA,e.FLOAT,new Float32Array(4));var u=e.getError()===e.NO_ERROR;return a(e),s&&u}function u(t){if(2!==t)return!1;var e=n(t),r=null!=e.getExtension("WEBGL_get_buffer_sub_data_async");return a(e),r}Object.defineProperty(r,"__esModule",{value:!0});var c,p=t("./device_util"),l=t("./util");!function(t){t[t.NUMBER=0]="NUMBER",t[t.BOOLEAN=1]="BOOLEAN"}(c=r.Type||(r.Type={})),r.URL_PROPERTIES=[{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_ENABLED",type:c.BOOLEAN},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:c.BOOLEAN},{name:"WEBGL_VERSION",type:c.NUMBER},{name:"WEBGL_FLOAT_TEXTURE_ENABLED",type:c.BOOLEAN},{name:"WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED",type:c.BOOLEAN}];var h=function(){function t(t){this.features={},null!=t&&(this.features=t)}return t.prototype.get=function(t){return t in this.features?this.features[t]:(this.features[t]=this.evaluateFeature(t),this.features[t])},t.prototype.evaluateFeature=function(t){if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_ENABLED"===t){var e=this.get("WEBGL_VERSION");return 0!==e&&i(e)}if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE"===t)return this.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_ENABLED")&&!p.isMobile();if("WEBGL_VERSION"===t)return o(2)?2:o(1)?1:0;if("WEBGL_FLOAT_TEXTURE_ENABLED"===t)return s(this.get("WEBGL_VERSION"));if("WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED"===t)return u(this.get("WEBGL_VERSION"));throw new Error("Unknown feature "+t+".")},t}();r.Environment=h;var f="dljsflags";r.ENV=new h(function(){var t={};if("undefined"==typeof window)return t;var e=l.getQueryParams(window.location.search);if(f in e){var n={};e[f].split(",").forEach(function(t){var e=t.split(":"),r=e[0],a=e[1];n[r]=a}),r.URL_PROPERTIES.forEach(function(e){e.name in n&&(console.log("Setting feature override from URL "+e.name+": "+n[e.name]),e.type===c.NUMBER?t[e.name]=+n[e.name]:e.type===c.BOOLEAN?t[e.name]="true"===n[e.name]:console.warn("Unknown URL param: "+e.name+"."))})}return t}()),r.setEnvironment=function(t){r.ENV=t}},{"./device_util":14,"./util":96}],16:[function(t,e,r){"use strict";function n(t,e){return 1===t.length&&1===e.length?[1]:1===t.length&&2===e.length?[e[1]]:2===t.length&&1===e.length?[t[0]]:[t[0],e[1]]}var a=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=t("../initializers"),i=t("../math/concat_util"),s=t("../math/conv_util"),u=t("../math/ndarray"),c=t("../util"),p=function(){function t(t){this.g=t}return t.prototype.dense=function(t,e,r,n,a,i,s){void 0===n&&(n=null),void 0===a&&(a=!0),void 0===i&&(i=new o.VarianceScalingInitializer),void 0===s&&(s=new o.ZerosInitializer);var u=this.g.variable(t+"-weights",i.initialize([e.shape[0],r],e.shape[0],r)),c=this.g.matmul(e,u);if(a){var p=this.g.variable(t+"-bias",s.initialize([r],e.shape[0],r));c=this.g.add(c,p)}return null!=n&&(c=n(c)),c},t}();r.GraphLayers=p;var l=function(){function t(){this.nodes=[],this.layers=new p(this)}return t.prototype.variable=function(t,e){return this.addNodeAndReturnOutput(new d(this,t,e))},t.prototype.placeholder=function(t,e){return this.addNodeAndReturnOutput(new v(this,t,e))},t.prototype.constant=function(t){var e;if("number"==typeof t)e=u.Scalar.new(t);else if(t instanceof u.NDArray)e=t;else{if(!(t instanceof Array))throw new Error("unimplemented constant type.");var r=c.flatten(t),n=new Float32Array(r);e=u.NDArray.make(c.inferShape(t),{values:n})}return this.addNodeAndReturnOutput(new m(this,e))},t.prototype.reshape=function(t,e){return this.addNodeAndReturnOutput(new y(this,"Reshape",t,e))},t.prototype.fusedLinearCombination=function(t,e,r,n){return this.addNodeAndReturnOutput(new g(this,t,e,r,n))},t.prototype.add=function(t,e){return this.addNodeAndReturnOutput(new x(this,t,e))},t.prototype.subtract=function(t,e){return this.addNodeAndReturnOutput(new w(this,t,e))},t.prototype.multiply=function(t,e){return this.addNodeAndReturnOutput(new b(this,t,e))},t.prototype.divide=function(t,e){return this.addNodeAndReturnOutput(new _(this,t,e))},t.prototype.reduceSum=function(t){return this.addNodeAndReturnOutput(new A(this,t))},t.prototype.concat3d=function(t,e,r){return this.addNodeAndReturnOutput(new T(this,t,e,r))},t.prototype.matmul=function(t,e){return this.addNodeAndReturnOutput(new E(this,t,e))},t.prototype.conv2d=function(t,e,r,n,a,o,i){return void 0===o&&(o=1),this.addNodeAndReturnOutput(new S(this,t,e,r,n,a,o,i))},t.prototype.maxPool=function(t,e,r,n){return void 0===r&&(r=1),this.addNodeAndReturnOutput(new C(this,t,e,r,n))},t.prototype.exp=function(t){return this.addNodeAndReturnOutput(new R(this,t))},t.prototype.log=function(t){return this.addNodeAndReturnOutput(new M(this,t))},t.prototype.relu=function(t){return this.addNodeAndReturnOutput(new N(this,t))},t.prototype.leakyRelu=function(t,e){return this.addNodeAndReturnOutput(new O(this,t,e))},t.prototype.tanh=function(t){return this.addNodeAndReturnOutput(new D(this,t))},t.prototype.sigmoid=function(t){return this.addNodeAndReturnOutput(new I(this,t))},t.prototype.square=function(t){return this.addNodeAndReturnOutput(new P(this,t))},t.prototype.softmax=function(t){return this.addNodeAndReturnOutput(new z(this,t))},t.prototype.softmaxCrossEntropyCost=function(t,e){return this.addNodeAndReturnOutput(new k(this,t,e))},t.prototype.meanSquaredCost=function(t,e){return this.addNodeAndReturnOutput(new F(this,t,e))},t.prototype.argmax=function(t){return this.addNodeAndReturnOutput(new U(this,t))},t.prototype.argmaxEquals=function(t,e){return this.addNodeAndReturnOutput(new B(this,t,e))},t.prototype.addNodeAndReturnOutput=function(t){return this.nodes.push(t),t.validate(),t.output},t.prototype.getNodes=function(){return this.nodes},t}();r.Graph=l;var h=function(){function t(e){this.shape=e,this.id=t.nextID++}return t.nextID=0,t}();r.Tensor=h;var f=function(){function t(e,r,n,a){this.graph=e,this.name=r,this.inputs=n,this.output=a,this.id=t.nextID++,a.node=this}return t.nextID=0,t}();r.Node=f;var d=function(t){function e(e,r,n){var a=t.call(this,e,r,{},new h(n.shape))||this;return a.data=n,a}return a(e,t),e.prototype.validate=function(){c.assert(null!=this.data,"Error adding variable op: Data for variable '"+this.name+"' is null or undefined")},e}(f);r.VariableNode=d;var v=function(t){function e(e,r,n){return t.call(this,e,r,{},new h(n))||this}return a(e,t),e.prototype.validate=function(){},e}(f);r.PlaceholderNode=v;var m=function(t){function e(e,r){var n=t.call(this,e,"Constant",{},new h(r.shape))||this;return n.data=r,n}return a(e,t),e.prototype.validate=function(){c.assert(null!=this.data,"Error adding constant: data for placeholder '"+this.name+"' is null or undefined")},e}(f);r.ConstantNode=m;var y=function(t){function e(e,r,n,a){var o=t.call(this,e,r,{x:n},new h(a))||this;return o.name=r,o.x=n,o.shape=a,o}return a(e,t),e.prototype.validate=function(){var t=c.sizeFromShape(this.x.shape),e=c.sizeFromShape(this.shape);c.assert(t===e,"Error making reshape operation: input to reshape '"+this.name+"' of shape ("+this.x.shape+") does not match size of requested shape "+this.shape+".")},e.X="x",e}(f);r.ReshapeNode=y;var g=function(t){function e(e,r,n,a,o){var i=t.call(this,e,"Linear Combination",{t1:r,t2:n,c1:a,c2:o},new h(r.shape))||this;return i.t1=r,i.t2=n,i.c1=a,i.c2=o,i}return a(e,t),e.prototype.validate=function(){if(c.assertShapesMatch(this.t1.shape,this.t2.shape),!c.isScalarShape(this.c1.shape))throw new Error("Error adding fusedLinearCombination: c1 is not a scalar, got shape: "+this.c1.shape);if(!c.isScalarShape(this.c2.shape))throw new Error("Error adding fusedLinearCombination: c2 is not a scalar, got shape: "+this.c2.shape)},e.T1="t1",e.T2="t2",e.C1="c1",e.C2="c2",e}(f);r.FusedLinearCombinationNode=g;var x=function(t){function e(e,r,n){var a=t.call(this,e,"Add",{t1:r,t2:n},new h(1===c.sizeFromShape(r.shape)?n.shape:r.shape))||this;return a.t1=r,a.t2=n,a}return a(e,t),e.prototype.validate=function(){c.assert(1===c.sizeFromShape(this.t1.shape)||1===c.sizeFromShape(this.t2.shape)||c.arraysEqual(this.t1.shape,this.t2.shape),"Error adding add operation op: one of inputs must be scalar or the shapes "+this.t1.shape+" and "+this.t2.shape+" must match.")},e.T1="t1",e.T2="t2",e}(f);r.AddNode=x;var w=function(t){function e(e,r,n){var a=t.call(this,e,"Subtract",{t1:r,t2:n},new h(1===c.sizeFromShape(r.shape)?n.shape:r.shape))||this;return a.t1=r,a.t2=n,a}return a(e,t),e.prototype.validate=function(){c.assert(1===c.sizeFromShape(this.t1.shape)||1===c.sizeFromShape(this.t2.shape)||c.arraysEqual(this.t1.shape,this.t2.shape),"Error adding subtract op: one of inputs must be scalar or the shapes "+this.t1.shape+" and "+this.t2.shape+" must match.")},e.T1="t1",e.T2="t2",e}(f);r.SubtractNode=w;var b=function(t){function e(e,r,n){var a=t.call(this,e,"Multiply",{t1:r,t2:n},new h(1===c.sizeFromShape(r.shape)?n.shape:r.shape))||this;return a.t1=r,a.t2=n,a}return a(e,t),e.prototype.validate=function(){c.assert(1===c.sizeFromShape(this.t1.shape)||1===c.sizeFromShape(this.t2.shape)||c.arraysEqual(this.t1.shape,this.t2.shape),"Error adding multiply op: one of inputs must be scalar or the shapes "+this.t1.shape+" and "+this.t2.shape+" must match.")},e.T1="t1",e.T2="t2",e}(f);r.MultiplyNode=b;var _=function(t){function e(e,r,n){var a=t.call(this,e,"Divide",{t1:r,t2:n},new h(1===c.sizeFromShape(r.shape)?n.shape:r.shape))||this;return a.t1=r,a.t2=n,a}return a(e,t),e.prototype.validate=function(){c.assert(1===c.sizeFromShape(this.t1.shape)||1===c.sizeFromShape(this.t2.shape)||c.arraysEqual(this.t1.shape,this.t2.shape),"Error adding divide op: one of inputs must be scalar or the shapes "+this.t1.shape+" and "+this.t2.shape+" must match.")},e.T1="t1",e.T2="t2",e}(f);r.DivideNode=_;var A=function(t){function e(e,r){return t.call(this,e,"ReduceSum",{x:r},new h([]))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.ReduceSumNode=A;var T=function(t){function e(e,r,n,a){var o=t.call(this,e,"Concat3D",{x1:r,x2:n},new h(i.computeOutShape(r.shape,n.shape,a)))||this;return o.x1=r,o.x2=n,o.axis=a,o}return a(e,t),e.prototype.validate=function(){i.assertParams(this.x1.shape,this.x2.shape,this.axis)},e.X1="x1",e.X2="x2",e.AXIS="axis",e}(f);r.Concat3DNode=T;var E=function(t){function e(e,r,a){var o=t.call(this,e,"MatMul",{x1:r,x2:a},new h(n(r.shape,a.shape)))||this;return o.x1=r,o.x2=a,o}return a(e,t),e.prototype.validate=function(){if(2===this.x1.shape.length&&2===this.x2.shape.length)c.assert(this.x1.shape[1]===this.x2.shape[0],"Error adding matmul op: inner shapes of matrices with shapes "+this.x1.shape+" and "+this.x2.shape+" must match.");else if(2===this.x1.shape.length&&1===this.x2.shape.length)c.assert(this.x1.shape[1]===this.x2.shape[0],"Error adding matmul op: second dimension of matrix with shape "+this.x1.shape.toString()+" must match size of vector with shape "+this.x2.shape+".");else{if(1!==this.x1.shape.length||2!==this.x2.shape.length)throw new Error("Error adding matmul op: inputs must be vectors or matrices.");c.assert(this.x1.shape[0]===this.x2.shape[0],"Error adding matmul op: size of vector with shape "+this.x1.shape+" must match first dimension of matrix with shape "+this.x2.shape+".")}},e.X1="x1",e.X2="x2",e}(f);r.MatMulNode=E;var S=function(t){function e(e,r,n,a,o,i,u,c){void 0===u&&(u=1);var p=t.call(this,e,"Convolution 2D",{x:r,w:n,b:a},new h(s.computeOutputShape3D(r.shape,o,i,u,c)))||this;return p.x=r,p.w=n,p.b=a,p.fieldSize=o,p.outputDepth=i,p.stride=u,p.zeroPad=c,p}return a(e,t),e.prototype.validate=function(){c.assert(3===this.x.shape.length,"Error adding conv2d op: input must be of rank 3, but got shape: "+this.x.shape+"."),c.assert(4===this.w.shape.length,"Error adding conv2d op: weights must be of rank 4, but got shape: "+this.w.shape+"."),c.assert(1===this.b.shape.length,"Error adding conv2d op: biases must be of rank 1, but got shape: "+this.b.shape+"."),c.assert(this.x.shape[2]===this.w.shape[2],"Error adding conv2d op: depth of input ("+this.x.shape[2]+") must match input depth for weights ("+this.w.shape[2]+").")},e.X="x",e.W="w",e.B="b",e}(f);r.Convolution2DNode=S;var C=function(t){function e(e,r,n,a,o){void 0===a&&(a=1);var i=t.call(this,e,"Max pool",{x:r},new h(s.computeOutputShape3D(r.shape,n,r.shape[2],a,o)))||this;return i.x=r,i.fieldSize=n,i.stride=a,i.zeroPad=o,i}return a(e,t),e.prototype.validate=function(){c.assert(3===this.x.shape.length,"Error adding maxPool op: input must be of rank 3, but got shape: "+this.x.shape+".")},e.X="x",e}(f);r.MaxPoolNode=C;var N=function(t){function e(e,r){return t.call(this,e,"ReLU",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.ReLUNode=N;var O=function(t){function e(e,r,n){var a=t.call(this,e,"LeakyReLU",{x:r},new h(r.shape))||this;return a.alpha=n,a}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.LeakyReLUNode=O;var R=function(t){function e(e,r){return t.call(this,e,"Exp",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.ExpNode=R;var M=function(t){function e(e,r){return t.call(this,e,"Log",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.LogNode=M;var D=function(t){function e(e,r){return t.call(this,e,"TanH",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.TanHNode=D;var I=function(t){function e(e,r){return t.call(this,e,"Sigmoid",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.SigmoidNode=I;var P=function(t){function e(e,r){return t.call(this,e,"Square",{x:r},new h(r.shape))||this}return a(e,t),e.prototype.validate=function(){},e.X="x",e}(f);r.SquareNode=P;var k=function(t){function e(e,r,n){var a=t.call(this,e,"SoftmaxCrossEntropyCost",{x:r,target:n},new h([]))||this;return a.x=r,a.target=n,a}return a(e,t),e.prototype.validate=function(){c.assert(c.arraysEqual(this.x.shape,this.target.shape),"Error adding softmaxCrossEntropyCost op: x shape ("+this.x.shape+") must match target shape ("+this.target.shape+").")},e.X="x",e.TARGET="target",e}(f);r.SoftmaxCrossEntropyCostNode=k;var z=function(t){function e(e,r){var n=t.call(this,e,"Softmax",{x:r},new h(r.shape))||this;return n.x=r,n}return a(e,t),e.prototype.validate=function(){c.assert(1===this.x.shape.length,"The input to a softmax must be a 1-D tensor"),c.assert(this.x.shape[0]>=2,"The input to a softmax must have at least 2 values")},e.X="x",e}(f);r.SoftmaxNode=z;var F=function(t){function e(e,r,n){var a=t.call(this,e,"Mean Squared Cost",{label:r,prediction:n},new h([]))||this;return a.label=r,a.prediction=n,a}return a(e,t),e.prototype.validate=function(){c.assert(c.arraysEqual(this.label.shape,this.prediction.shape),"Error adding meanSquaredCost op: label shape ("+this.label.shape+") must match prediction shape ("+this.prediction.shape+").")},e.LABEL="label",e.PREDICTION="prediction",e}(f);r.MeanSquaredCostNode=F;var U=function(t){function e(e,r){var n=t.call(this,e,"ArgMax",{x:r},new h([1]))||this;return n.x=r,n}return a(e,t),e.prototype.validate=function(){c.assert(c.sizeFromShape(this.x.shape)>0,"Error adding argmax op: input tensor must have at least one entry.")},e.X="x",e}(f);r.ArgMaxNode=U;var B=function(t){function e(e,r,n){var a=t.call(this,e,"ArgMaxEquals",{x1:r,x2:n},new h([1]))||this;return a.x1=r,a.x2=n,a}return a(e,t),e.prototype.validate=function(){c.assert(c.arraysEqual(this.x1.shape,this.x2.shape),"Error adding ArgMaxEquals op: x1 shape ("+this.x1.shape+") must match x2 shape ("+this.x2.shape+").")},e.X1="x1",e.X2="x2",e}(f);r.ArgMaxEqualsNode=B},{"../initializers":52,"../math/concat_util":56,"../math/conv_util":57,"../math/ndarray":63,"../util":96}],17:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("./graph"),a=t("./priority_queue"),o=t("./priority_queue");r.getUnorderedEvaluationSet=function(t,e){var r={},n={},a=[],o=t.slice();e.forEach(function(t){return r[t.id]=t});for(;0!==o.length;)!function(){var t=o.pop();null==n[t.id]&&(null==r[t.id]&&Object.keys(t.inputs).map(function(e){return t.inputs[e]}).forEach(function(t){return o.push(t.node)}),a.push(t),n[t.id]=t)}();return a},r.getOrderedEvaluationSet=function(t){var e=[],r={},n={},i=new o.PriorityQueue(function(t,e){return a.defaultCompare(n[t.id],n[e.id])},function(t,e){return r[t.id]=e});for(t.forEach(function(t){return n[t.id]=0}),t.forEach(function(e){return Object.keys(e.inputs).map(function(t){return e.inputs[t]}).forEach(function(e){-1!==t.indexOf(e.node)&&n[e.node.id]++})}),t.forEach(function(t){return i.enqueue(t)});!i.empty();)e.unshift(i.dequeue()),Object.keys(e[0].inputs).map(function(t){return e[0].inputs[t]}).forEach(function(e){-1!==t.indexOf(e.node)&&(n[e.node.id]--,i.update(e.node,r[e.node.id]))});return e},r.isInputNode=function(t){return 0===Object.keys(t.inputs).length},r.shouldBackProp=function(t){return!(t.node instanceof n.ConstantNode)},r.isPassthroughNode=function(t,e){for(var r=Object.keys(t.inputs),n=0;n<r.length;n++){var a=t.inputs[r[n]];if(e.get(a,!0)===e.get(t.output,!0))return!0}return!1}},{"./graph":16,"./priority_queue":46}],18:[function(t,e,r){"use strict";function n(t){if(t instanceof a.ReshapeNode)return[new b.Reshape(t.inputs[a.ReshapeNode.X],t.output)];if(t instanceof a.MatMulNode){var e=t.inputs[a.MatMulNode.X1],r=t.inputs[a.MatMulNode.X2];return[new y.MatMul(e,r,t.output)]}if(t instanceof a.Convolution2DNode){var n=t.inputs[a.Convolution2DNode.W],T=t.inputs[a.Convolution2DNode.X],E=t.inputs[a.Convolution2DNode.B];return[new p.Convolution2D(n,T,E,t.output,t.fieldSize,t.outputDepth,t.stride,t.zeroPad)]}if(t instanceof a.MaxPoolNode){T=t.inputs[a.MaxPoolNode.X];return[new g.MaxPool(T,t.output,t.fieldSize,t.stride,t.zeroPad)]}if(t instanceof a.ExpNode)return[new d.Exp(t.inputs[a.ExpNode.X],t.output)];if(t instanceof a.LogNode)return[new m.Log(t.inputs[a.LogNode.X],t.output)];if(t instanceof a.ReLUNode)return[new h.ReLU(t.inputs[a.ReLUNode.X],t.output)];if(t instanceof a.LeakyReLUNode)return[new h.LeakyReLU(t.inputs[a.LeakyReLUNode.X],t.output,t.alpha)];if(t instanceof a.TanHNode)return[new h.TanH(t.inputs[a.TanHNode.X],t.output)];if(t instanceof a.SigmoidNode)return[new h.Sigmoid(t.inputs[a.SigmoidNode.X],t.output)];if(t instanceof a.SoftmaxCrossEntropyCostNode){var T=t.inputs[a.SoftmaxCrossEntropyCostNode.X],S=t.inputs[a.SoftmaxCrossEntropyCostNode.TARGET];return[new _.SoftmaxCrossEntropyCost(T,S,t.output)]}if(t instanceof a.SoftmaxNode)return[new _.Softmax(t.inputs[a.SoftmaxNode.X],t.output)];if(t instanceof a.MeanSquaredCostNode){var C=t.inputs[a.MeanSquaredCostNode.LABEL],N=t.inputs[a.MeanSquaredCostNode.PREDICTION];return[new f.MeanSquaredCost(C,N,t.output)]}if(t instanceof a.ArgMaxEqualsNode)return[new u.ArgMaxEquals(t.inputs[a.ArgMaxEqualsNode.X1],t.inputs[a.ArgMaxEqualsNode.X2],t.output)];if(t instanceof a.ArgMaxNode)return[new s.ArgMax(t.x,t.output)];if(t instanceof a.FusedLinearCombinationNode)return[new v.LinearCombination(t.inputs[a.FusedLinearCombinationNode.T1],t.inputs[a.FusedLinearCombinationNode.T2],t.inputs[a.FusedLinearCombinationNode.C1],t.inputs[a.FusedLinearCombinationNode.C2],t.output)];if(t instanceof a.Concat3DNode)return[new c.Concat3D(t.inputs[a.Concat3DNode.X1],t.inputs[a.Concat3DNode.X2],t.axis,t.output)];if(t instanceof a.SquareNode)return[new h.Square(t.inputs[a.SquareNode.X],t.output)];if(t instanceof a.AddNode)return[new i.Add(t.inputs[a.AddNode.T1],t.inputs[a.AddNode.T2],t.output)];if(t instanceof a.SubtractNode)return[new A.Subtract(t.inputs[a.SubtractNode.T1],t.inputs[a.SubtractNode.T2],t.output)];if(t instanceof a.MultiplyNode)return[new x.Multiply(t.inputs[a.MultiplyNode.T1],t.inputs[a.MultiplyNode.T2],t.output)];if(t instanceof a.DivideNode)return[new l.Divide(t.inputs[a.DivideNode.T1],t.inputs[a.DivideNode.T2],t.output)];if(t instanceof a.ReduceSumNode)return[new w.ReduceSum(t.inputs[a.ReduceSumNode.X],t.output)];if(o.isInputNode(t))return[];throw Error("Unsupported node type: "+t.constructor.name)}Object.defineProperty(r,"__esModule",{value:!0});var a=t("./graph"),o=t("./graph_util"),i=t("./ops/add"),s=t("./ops/argmax"),u=t("./ops/argmaxequals"),c=t("./ops/concat3d"),p=t("./ops/convolution"),l=t("./ops/divide"),h=t("./ops/element_wise_activation"),f=t("./ops/element_wise_cost"),d=t("./ops/exp"),v=t("./ops/linear_combination"),m=t("./ops/log"),y=t("./ops/matmul"),g=t("./ops/max_pool"),x=t("./ops/multiply"),w=t("./ops/reduce_sum"),b=t("./ops/reshape"),_=t("./ops/softmax"),A=t("./ops/subtract");r.emitFromGraphNodes=function(t){var e=[];return t.forEach(function(t){return Array.prototype.push.apply(e,n(t))}),e}},{"./graph":16,"./graph_util":17,"./ops/add":19,"./ops/argmax":20,"./ops/argmaxequals":21,"./ops/concat3d":22,"./ops/convolution":23,"./ops/divide":24,"./ops/element_wise_activation":25,"./ops/element_wise_cost":26,"./ops/exp":27,"./ops/linear_combination":28,"./ops/log":29,"./ops/matmul":30,"./ops/max_pool":31,"./ops/multiply":32,"./ops/reduce_sum":34,"./ops/reshape":35,"./ops/softmax":36,"./ops/subtract":37}],19:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../../util"),i=t("../graph_util"),s=function(t){function e(e,r,n){var a=t.call(this)||this;return a.x1Tensor=e,a.x2Tensor=r,a.yTensor=n,o.assert(1===o.sizeFromShape(e.shape)||1===o.sizeFromShape(r.shape)||o.arraysEqual(e.shape,r.shape),"One of t1 or t2 must be a scalar, or t1 and t2 must have the same shape"),a}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor);t.scope(function(i){var s;s=o.isScalarShape(n.shape)?t.scalarPlusArray(n,a):o.isScalarShape(a.shape)?t.scalarPlusArray(a,n):t.add(n,a),e.set(r.yTensor,i(s))})},e.prototype.backProp=function(t,e,r){var n=this,s=r.get(this.yTensor);t.scope(function(){if(i.shouldBackProp(n.x1Tensor))if(o.isScalarShape(n.x1Tensor.shape)){e=t.sum(s);null==n.dySizeScalar&&(n.dySizeScalar=a.Scalar.new(s.size)),r.add(n.x1Tensor,t.divide(e,n.dySizeScalar))}else r.add(n.x1Tensor,t.clone(s));if(i.shouldBackProp(n.x2Tensor))if(o.isScalarShape(n.x2Tensor.shape)){var e=t.sum(s);null==n.dySizeScalar&&(n.dySizeScalar=a.Scalar.new(s.size)),r.add(n.x2Tensor,t.divide(e,n.dySizeScalar))}else r.add(n.x2Tensor,t.clone(s))})},e.prototype.dispose=function(){null!=this.dySizeScalar&&this.dySizeScalar.dispose()},e}(t("./op").Operation);r.Add=s},{"../../math/ndarray":63,"../../util":96,"../graph_util":17,"./op":33}],20:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=function(t){function e(e,r){var n=t.call(this)||this;return n.xTensor=e,n.yTensor=r,n}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor);t.scope(function(a){e.set(r.yTensor,a(t.argMax(n)))})},e.prototype.backProp=function(t,e,r){throw new Error("ArgMax backprop unimplemented")},e}(t("./op").Operation);r.ArgMax=a},{"./op":33}],21:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=function(t){function e(e,r,n){var a=t.call(this)||this;return a.x1Tensor=e,a.x2Tensor=r,a.yTensor=n,a}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor);t.scope(function(o){e.set(r.yTensor,o(t.argMaxEquals(n,a)))})},e.prototype.backProp=function(t,e,r){throw new Error("ArgMaxEquals backprop unimplemented")},e}(t("./op").Operation);r.ArgMaxEquals=a},{"./op":33}],22:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/concat_util"),o=function(t){function e(e,r,n,o){var i=t.call(this)||this;return i.x1Tensor=e,i.x2Tensor=r,i.axis=n,i.yTensor=o,a.assertParams(e.shape,r.shape,n),i}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor);t.scope(function(o){var i=t.concat3D(n,a,r.axis);e.set(r.yTensor,o(i))})},e.prototype.backProp=function(t,e,r){throw new Error("Concat3D backprop not implemented.")},e}(t("./op").Operation);r.Concat3D=o},{"../../math/concat_util":56,"./op":33}],23:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/conv_util"),o=t("../../util"),i=function(t){function e(e,r,n,i,s,u,c,p){void 0===c&&(c=1);var l=t.call(this)||this;return l.wTensor=e,l.xTensor=r,l.bTensor=n,l.yTensor=i,l.fieldSize=s,l.outputDepth=u,l.stride=c,l.assertWeightsShape(e.shape),l.zeroPad=null!=p?p:a.computeDefaultPad(l.xTensor.shape,l.fieldSize,l.stride),o.assert(o.isInt(l.zeroPad),"The zero padding ("+l.zeroPad+") must be an integer. Change the stride and/or zero pad parameters"),l}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.wTensor),a=e.get(this.bTensor),o=e.get(this.xTensor);t.scope(function(i){e.set(r.yTensor,i(t.conv2d(o,n,a,r.stride,r.zeroPad)))})},e.prototype.backProp=function(t,e,r){var n=this,a=e.get(this.wTensor),o=e.get(this.xTensor),i=r.get(this.yTensor);t.scope(function(){var e=t.conv2dBackProp(o,i,a,n.stride,n.zeroPad),s=e.dw,u=e.db,c=e.dx;r.add(n.wTensor,s),r.add(n.bTensor,u),r.add(n.xTensor,c)})},e.prototype.assertWeightsShape=function(t){o.assert(t[0]===this.fieldSize&&t[1]===this.fieldSize&&t[2]===this.xTensor.shape[2]&&t[3]===this.outputDepth,"weights must be of shape ["+this.fieldSize+","+this.fieldSize+","+this.xTensor.shape[2]+","+this.outputDepth+"] but they are ofshape ["+t+"]")},e}(t("./op").Operation);r.Convolution2D=i},{"../../math/conv_util":57,"../../util":96,"./op":33}],24:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../util"),o=t("../graph_util"),i=function(t){function e(e,r,n){var o=t.call(this)||this;return o.x1Tensor=e,o.x2Tensor=r,o.yTensor=n,a.assert(1===a.sizeFromShape(e.shape)||1===a.sizeFromShape(r.shape)||a.arraysEqual(e.shape,r.shape),"One of t1 or t2 must be a scalar, or t1 and t2 must have the same shape"),o}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),o=e.get(this.x2Tensor);t.scope(function(i){var s;s=a.isScalarShape(n.shape)?t.scalarDividedByArray(n,o):a.isScalarShape(o.shape)?t.arrayDividedByScalar(n,o):t.divide(n,o),e.set(r.yTensor,i(s))})},e.prototype.backProp=function(t,e,r){var n=this,i=e.get(this.x1Tensor),s=e.get(this.x2Tensor),u=r.get(this.yTensor),c=a.isScalarShape(i.shape),p=a.isScalarShape(s.shape);t.scope(function(){if(o.shouldBackProp(n.x1Tensor))if(c){var e=t.divide(u,s);r.add(n.x1Tensor,t.sum(e)),e.dispose()}else p?r.add(n.x1Tensor,t.arrayDividedByScalar(u,s)):r.add(n.x1Tensor,t.divide(u,s));if(o.shouldBackProp(n.x2Tensor)){var a=t.elementWiseMul(s,s),l=void 0;l=p?t.arrayDividedByScalar(i,a):c?t.scalarDividedByArray(i,a):t.divide(i,a);var h=t.neg(l),f=t.elementWiseMul(u,h);p?r.add(n.x2Tensor,t.sum(f)):r.add(n.x2Tensor,f)}})},e}(t("./op").Operation);r.Divide=i},{"../../util":96,"../graph_util":17,"./op":33}],25:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/activation_functions"),o=function(t){function e(e,r,n){var a=t.call(this)||this;return a.xTensor=e,a.yTensor=r,a.func=n,a}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor);t.scope(function(a){e.set(r.yTensor,a(r.func.output(t,n)))})},e.prototype.backProp=function(t,e,r){var n=this,a=e.get(this.xTensor),o=e.get(this.yTensor),i=r.get(this.yTensor);t.scope(function(){var e=n.func.der(t,a,o);r.add(n.xTensor,t.elementWiseMul(i,e)),e.dispose()})},e.prototype.dispose=function(){this.func.dispose()},e}(t("./op").Operation);r.ElementWiseActivation=o;var i=function(t){function e(e,r){return t.call(this,e,r,new a.ReLUFunc)||this}return n(e,t),e}(o);r.ReLU=i;var s=function(t){function e(e,r,n){return t.call(this,e,r,new a.LeakyReluFunc(n))||this}return n(e,t),e}(o);r.LeakyReLU=s;var u=function(t){function e(e,r){return t.call(this,e,r,new a.TanHFunc)||this}return n(e,t),e}(o);r.TanH=u;var c=function(t){function e(e,r){return t.call(this,e,r,new a.SigmoidFunc)||this}return n(e,t),e}(o);r.Sigmoid=c;var p=function(t){function e(e,r){return t.call(this,e,r,new a.SquareFunc)||this}return n(e,t),e}(o);r.Square=p},{"../../math/activation_functions":53,"./op":33}],26:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/cost_functions"),o=t("../../math/ndarray"),i=t("../../util"),s=t("../graph_util"),u=function(t){function e(e,r,n,a){var s=t.call(this)||this;return s.x1Tensor=e,s.x2Tensor=r,s.yTensor=n,s.func=a,s.oneOverNScalar=o.Scalar.new(1/i.sizeFromShape(e.shape)),s}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor);t.scope(function(o){var i=r.func.cost(t,n,a),s=t.sum(i),u=t.scalarTimesArray(r.oneOverNScalar,s);e.set(r.yTensor,o(u))})},e.prototype.backProp=function(t,e,r){var n=this,a=e.get(this.x1Tensor),o=e.get(this.x2Tensor);t.scope(function(){s.shouldBackProp(n.x1Tensor)&&r.add(n.x1Tensor,n.func.der(t,a,o)),s.shouldBackProp(n.x2Tensor)&&r.add(n.x2Tensor,n.func.der(t,o,a))})},e.prototype.dispose=function(){this.func.dispose(),this.oneOverNScalar.dispose()},e}(t("./op").Operation);r.ElementWiseCost=u;var c=function(t){function e(e,r,n){return t.call(this,e,r,n,new a.SquareCostFunc)||this}return n(e,t),e}(u);r.MeanSquaredCost=c},{"../../math/cost_functions":59,"../../math/ndarray":63,"../../util":96,"../graph_util":17,"./op":33}],27:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../graph_util"),o=function(t){function e(e,r){var n=t.call(this)||this;return n.xTensor=e,n.yTensor=r,n}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor);t.scope(function(a){e.set(r.yTensor,a(t.exp(n)))})},e.prototype.backProp=function(t,e,r){var n=this,o=e.get(this.yTensor),i=r.get(this.yTensor);t.scope(function(){a.shouldBackProp(n.xTensor)&&r.add(n.xTensor,t.elementWiseMul(o,i))})},e}(t("./op").Operation);r.Exp=o},{"../graph_util":17,"./op":33}],28:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../graph_util"),o=function(t){function e(e,r,n,a,o){var i=t.call(this)||this;return i.x1Tensor=e,i.x2Tensor=r,i.c1Tensor=n,i.c2Tensor=a,i.outTensor=o,i}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor),o=e.get(this.c1Tensor).asScalar(),i=e.get(this.c2Tensor).asScalar();t.scope(function(s){e.set(r.outTensor,s(t.scaledArrayAdd(o,n,i,a)))})},e.prototype.backProp=function(t,e,r){var n=this,o=e.get(this.x1Tensor),i=e.get(this.x2Tensor),s=e.get(this.c1Tensor),u=e.get(this.c2Tensor),c=r.get(this.outTensor);t.scope(function(){if(a.shouldBackProp(n.x1Tensor)&&r.add(n.x1Tensor,t.scalarTimesArray(s,c)),a.shouldBackProp(n.x2Tensor)&&r.add(n.x2Tensor,t.scalarTimesArray(u,c)),a.shouldBackProp(n.c1Tensor)){var e=t.elementWiseMul(o,c);r.add(n.c1Tensor,t.sum(e))}if(a.shouldBackProp(n.c2Tensor)){var p=t.elementWiseMul(i,c);r.add(n.c2Tensor,t.sum(p))}})},e}(t("./op").Operation);r.LinearCombination=o},{"../graph_util":17,"./op":33}],29:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../graph_util"),o=function(t){function e(e,r){var n=t.call(this)||this;return n.xTensor=e,n.yTensor=r,n}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor);t.scope(function(a){e.set(r.yTensor,a(t.log(n)))})},e.prototype.backProp=function(t,e,r){var n=this,o=e.get(this.xTensor),i=r.get(this.yTensor);t.scope(function(){a.shouldBackProp(n.xTensor)&&r.add(n.xTensor,t.divide(i,o))})},e}(t("./op").Operation);r.Log=o},{"../graph_util":17,"./op":33}],30:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/math"),o=t("../graph_util"),i=function(t){function e(e,r,n){var a=t.call(this)||this;return a.x1Tensor=e,a.x2Tensor=r,a.yTensor=n,a}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),a=e.get(this.x2Tensor);t.scope(function(o){2===n.shape.length&&2===a.shape.length?e.set(r.yTensor,o(t.matMul(n,a))):2===n.shape.length&&1===a.shape.length?e.set(r.yTensor,o(t.matrixTimesVector(n,a))):1===n.shape.length&&2===a.shape.length&&e.set(r.yTensor,o(t.vectorTimesMatrix(n,a)))})},e.prototype.backProp=function(t,e,r){var n=this,i=e.get(this.x1Tensor),s=e.get(this.x2Tensor),u=r.get(this.yTensor);1===i.shape.length&&(i=i.reshape([1,i.size]),u=u.reshape([1,u.size])),1===s.shape.length&&(s=s.reshape([s.size,1]),u=u.reshape([u.size,1])),t.scope(function(){if(o.shouldBackProp(n.x1Tensor)){var e=t.matMul(u,s,a.MatrixOrientation.REGULAR,a.MatrixOrientation.TRANSPOSED);r.add(n.x1Tensor,1===n.x1Tensor.shape.length?e.as1D():e)}if(o.shouldBackProp(n.x2Tensor)){var c=t.matMul(i,u,a.MatrixOrientation.TRANSPOSED,a.MatrixOrientation.REGULAR);r.add(n.x2Tensor,1===n.x2Tensor.shape.length?c.as1D():c)}})},e}(t("./op").Operation);r.MatMul=i},{"../../math/math":60,"../graph_util":17,"./op":33}],31:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/conv_util"),o=t("../../util"),i=function(t){function e(e,r,n,i,s){void 0===i&&(i=1);var u=t.call(this)||this;return u.xTensor=e,u.yTensor=r,u.fieldSize=n,u.stride=i,u.pad=null!=s?s:a.computeDefaultPad(e.shape,u.fieldSize,u.stride),o.assert(o.isInt(u.pad),"The zero padding ("+u.pad+") must be an integer. Change the stride and/or zero pad parameters"),u}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor);t.scope(function(a){e.set(r.yTensor,a(t.maxPool(n,r.fieldSize,r.stride,r.pad)))})},e.prototype.backProp=function(t,e,r){var n=this,a=e.get(this.xTensor),o=r.get(this.yTensor);t.scope(function(){r.add(n.xTensor,t.maxPoolBackprop(o,a,n.fieldSize,n.stride,n.pad))})},e}(t("./op").Operation);r.MaxPool=i},{"../../math/conv_util":57,"../../util":96,"./op":33}],32:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../util"),o=t("../graph_util"),i=function(t){function e(e,r,n){var o=t.call(this)||this;return o.x1Tensor=e,o.x2Tensor=r,o.yTensor=n,a.assert(1===a.sizeFromShape(e.shape)||1===a.sizeFromShape(r.shape)||a.arraysEqual(e.shape,r.shape),"One of t1 or t2 must be a scalar, or t1 and t2 must have the same shape"),o}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x1Tensor),o=e.get(this.x2Tensor);t.scope(function(i){var s;s=a.isScalarShape(n.shape)?t.scalarTimesArray(n,o):a.isScalarShape(o.shape)?t.scalarTimesArray(o,n):t.elementWiseMul(n,o),e.set(r.yTensor,i(s))})},e.prototype.backProp=function(t,e,r){var n=this,i=e.get(this.x1Tensor),s=e.get(this.x2Tensor),u=r.get(this.yTensor);t.scope(function(){if(o.shouldBackProp(n.x1Tensor))if(a.isScalarShape(n.x1Tensor.shape)){e=t.elementWiseMul(u,s);r.add(n.x1Tensor,t.sum(e))}else a.isScalarShape(s.shape)?r.add(n.x1Tensor,t.scalarTimesArray(s,u)):r.add(n.x1Tensor,t.elementWiseMul(s,u));if(o.shouldBackProp(n.x2Tensor))if(a.isScalarShape(n.x2Tensor.shape)){var e=t.elementWiseMul(u,i);r.add(n.x2Tensor,t.sum(e))}else a.isScalarShape(i.shape)?r.add(n.x2Tensor,t.scalarTimesArray(i,u)):r.add(n.x2Tensor,t.elementWiseMul(i,u))})},e}(t("./op").Operation);r.Multiply=i},{"../../util":96,"../graph_util":17,"./op":33}],33:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function t(){}return t.prototype.disposeTransientArrays=function(t,e){},t.prototype.dispose=function(){},t}();r.Operation=n},{}],34:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../../util"),i=t("../graph_util"),s=function(t){function e(e,r){var n=t.call(this)||this;return n.x=e,n.outTensor=r,o.assertShapesMatch(r.shape,[]),n}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.x);t.scope(function(a){e.set(r.outTensor,a(t.sum(n)))})},e.prototype.backProp=function(t,e,r){var n=this;i.shouldBackProp(this.x)&&t.scope(function(){var o=r.get(n.outTensor);if(null==n.ones){var i=e.get(n.x);n.ones=a.NDArray.zerosLike(i),n.ones.fill(1)}r.add(n.x,t.scalarTimesArray(o,n.ones))})},e}(t("./op").Operation);r.ReduceSum=s},{"../../math/ndarray":63,"../../util":96,"../graph_util":17,"./op":33}],35:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../util"),o=function(t){function e(e,r){var n=t.call(this)||this;n.xTensor=e,n.yTensor=r;var o=a.sizeFromShape(e.shape),i=a.sizeFromShape(r.shape);return a.assert(o===i,"The input size ("+o+") and output size ("+i+") must match"),n}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.xTensor),a=t.clone(n);t.scope(function(t){e.set(r.yTensor,t(a.reshape(r.yTensor.shape)))})},e.prototype.backProp=function(t,e,r){var n=this,a=r.get(this.yTensor),o=t.clone(a);t.scope(function(){r.add(n.xTensor,o.reshape(n.xTensor.shape))})},e}(t("./op").Operation);r.Reshape=o},{"../../util":96,"./op":33}],36:[function(t,e,r){"use strict";function n(t,e,r,n){return i.assert(e.size===r.size,"The output and target must be the same size"),t.scope(function(){var a=t.scalarPlusArray(n,e),o=t.log(a),i=t.elementWiseMul(r,o),s=t.neg(i);return t.sum(s)})}var a=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=t("../../math/ndarray"),i=t("../../util"),s=t("../graph"),u=t("./op"),c=function(t){function e(e,r){var n=t.call(this)||this;return n.logitsTensor=e,n.output=r,n}return a(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.logitsTensor);return t.scope(function(a){e.set(r.output,a(t.softmax(n)))})},e.prototype.backProp=function(){throw Error("Softmax backprop is not yet implemented")},e}(u.Operation);r.Softmax=c;var p=function(t){function e(e,r,n){var a=t.call(this)||this;return a.logitsTensor=e,a.labelTensor=r,a.yTensor=n,a.epsilon=o.Scalar.new(1e-5),a.softmaxTensor=new s.Tensor(e.shape),a}return a(e,t),e.prototype.feedForward=function(t,e){var r=this,a=e.get(this.logitsTensor),o=e.get(this.labelTensor);t.scope(function(i){var s=t.softmax(a);e.set(r.softmaxTensor,i(s)),e.set(r.yTensor,i(n(t,s,o,r.epsilon)))})},e.prototype.backProp=function(t,e,r){var n=this,a=e.get(this.softmaxTensor),o=e.get(this.labelTensor);t.scope(function(){r.add(n.logitsTensor,t.subtract(a,o))})},e.prototype.disposeTransientArrays=function(t,e){t.disposeArray(this.softmaxTensor)},e.prototype.dispose=function(){this.epsilon.dispose()},e}(u.Operation);r.SoftmaxCrossEntropyCost=p,r.crossEntropyCost=n},{"../../math/ndarray":63,"../../util":96,"../graph":16,"./op":33}],37:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../../util"),i=t("../graph_util"),s=function(t){function e(e,r,n){var a=t.call(this)||this;return a.t1=e,a.t2=r,a.outTensor=n,o.assert(1===o.sizeFromShape(e.shape)||1===o.sizeFromShape(r.shape)||o.arraysEqual(e.shape,r.shape),"One of t1 or t2 must be a scalar, or t1 and t2 must have the same shape"),a}return n(e,t),e.prototype.feedForward=function(t,e){var r=this,n=e.get(this.t1),a=e.get(this.t2);t.scope(function(i){var s;s=o.isScalarShape(n.shape)?t.scalarMinusArray(n,a):o.isScalarShape(a.shape)?t.arrayMinusScalar(n,a):t.subtract(n,a),e.set(r.outTensor,i(s))})},e.prototype.backProp=function(t,e,r){var n=this,s=r.get(this.outTensor);t.scope(function(){if(i.shouldBackProp(n.t1))if(o.isScalarShape(n.t1.shape)){e=t.sum(s);null==n.dySizeScalar&&(n.dySizeScalar=a.Scalar.new(s.size)),r.add(n.t1,t.divide(e,n.dySizeScalar))}else r.add(n.t1,t.clone(s));if(i.shouldBackProp(n.t2))if(o.isScalarShape(n.t2.shape)){var e=t.sum(s),u=t.neg(e);null==n.dySizeScalar&&(n.dySizeScalar=a.Scalar.new(s.size)),r.add(n.t2,t.divide(u,n.dySizeScalar))}else r.add(n.t2,t.neg(s))})},e.prototype.dispose=function(){null!=this.dySizeScalar&&this.dySizeScalar.dispose()},e}(t("./op").Operation);r.Subtract=s},{"../../math/ndarray":63,"../../util":96,"../graph_util":17,"./op":33}],38:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r,n){var i=t.call(this,e,n)||this;return i.learningRate=e,i.gamma=r,i.accumulatedSquaredGradients=new o.TensorArrayMap,i.accumulatedUpdates=new o.TensorArrayMap,i.eps=a.Scalar.new(1e-6),i.g=a.Scalar.new(i.gamma),i}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.accumulatedSquaredGradients.size()&&this.variableNodes.forEach(function(t){s.accumulatedSquaredGradients.set(t.output,a.NDArray.zeros(t.output.shape)),s.accumulatedUpdates.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.accumulatedSquaredGradients.get(r.output),u=i.accumulatedUpdates.get(r.output),c=t.multiply(o,o),p=t.scaledArrayAdd(i.g,s,t.subtract(i.one,i.g),c),l=t.multiply(t.divide(t.sqrt(t.add(u,i.eps)),t.sqrt(t.add(s,i.eps))),o),h=t.scaledArrayAdd(i.c,l,i.one,a),f=t.multiply(l,l),d=t.scaledArrayAdd(i.g,u,t.subtract(i.one,i.g),f);i.accumulatedSquaredGradients.set(r.output,e(p)),i.accumulatedUpdates.set(r.output,e(d)),n.set(r.output,e(h)),r.data=h,a.dispose(),s.dispose(),u.dispose()})}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.eps.dispose(),this.g.dispose(),this.accumulatedSquaredGradients.dispose(),this.accumulatedUpdates.dispose()},e}(t("./optimizer").Optimizer);r.AdadeltaOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./optimizer":43}],39:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r){var n=t.call(this,e,r)||this;return n.learningRate=e,n.accumulatedSquaredGradients=new o.TensorArrayMap,n.eps=a.Scalar.new(1e-6),n}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.accumulatedSquaredGradients.size()&&this.variableNodes.forEach(function(t){s.accumulatedSquaredGradients.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.accumulatedSquaredGradients.get(r.output),u=t.multiply(o,o),c=t.add(s,u),p=t.scaledArrayAdd(i.c,t.divide(o,t.add(t.sqrt(c),i.eps)),i.one,a);i.accumulatedSquaredGradients.set(r.output,e(c)),n.set(r.output,e(p)),r.data=p,a.dispose(),s.dispose()})}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.eps.dispose(),this.accumulatedSquaredGradients.dispose()},e}(t("./optimizer").Optimizer);r.AdagradOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./optimizer":43}],40:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r,n,i){var s=t.call(this,e,i)||this;return s.learningRate=e,s.beta1=r,s.beta2=n,s.firstMoment=new o.TensorArrayMap,s.secondMoment=new o.TensorArrayMap,s.eps=a.Scalar.new(1e-8),s.b1=a.Scalar.new(s.beta1),s.b2=a.Scalar.new(s.beta2),s.accB1=a.Scalar.new(s.beta1),s.accB2=a.Scalar.new(s.beta2),s}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.firstMoment.size()&&this.variableNodes.forEach(function(t){s.firstMoment.set(t.output,a.NDArray.zeros(t.output.shape))}),0===this.secondMoment.size()&&this.variableNodes.forEach(function(t){s.secondMoment.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.firstMoment.get(r.output),u=i.secondMoment.get(r.output),c=t.scaledArrayAdd(i.b1,s,t.subtract(i.one,i.b1),o),p=t.multiply(o,o),l=t.scaledArrayAdd(i.b2,u,t.subtract(i.one,i.b2),p),h=t.divide(c,t.subtract(i.one,i.accB1)),f=t.divide(l,t.subtract(i.one,i.accB2)),d=t.scaledArrayAdd(i.c,t.divide(h,t.add(t.sqrt(f),i.eps)),i.one,a);n.set(r.output,e(d)),r.data=d,i.firstMoment.set(r.output,e(c)),i.secondMoment.set(r.output,e(l)),a.dispose(),o.dispose(),s.dispose(),u.dispose()});var r=i.accB1,a=i.accB2;i.accB1=e(t.multiply(i.accB1,i.b1)),i.accB2=e(t.multiply(i.accB2,i.b2)),r.dispose(),a.dispose()}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.firstMoment.dispose(),this.secondMoment.dispose(),this.eps.dispose(),this.b1.dispose(),this.b2.dispose(),this.accB1.dispose(),this.accB2.dispose()},e}(t("./optimizer").Optimizer);r.AdamOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./optimizer":43}],41:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r,n,i){var s=t.call(this,e,i)||this;return s.learningRate=e,s.beta1=r,s.beta2=n,s.firstMoment=new o.TensorArrayMap,s.weightedInfNorm=new o.TensorArrayMap,s.eps=a.Scalar.new(1e-8),s.b1=a.Scalar.new(s.beta1),s.b2=a.Scalar.new(s.beta2),s.accB1=a.Scalar.new(s.beta1),s}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.firstMoment.size()&&this.variableNodes.forEach(function(t){s.firstMoment.set(t.output,a.NDArray.zeros(t.output.shape))}),0===this.weightedInfNorm.size()&&this.variableNodes.forEach(function(t){s.weightedInfNorm.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.firstMoment.get(r.output),u=i.weightedInfNorm.get(r.output),c=t.scaledArrayAdd(i.b1,s,t.subtract(i.one,i.b1),o),p=t.multiply(i.b2,u),l=t.abs(o),h=t.add(t.relu(t.subtract(p,l)),l),f=t.scaledArrayAdd(i.one,a,t.divide(i.c,t.subtract(i.one,i.accB1)),t.divide(c,t.add(i.eps,h)));n.set(r.output,e(f)),r.data=f,i.firstMoment.set(r.output,e(c)),i.weightedInfNorm.set(r.output,e(h)),a.dispose(),o.dispose(),s.dispose(),u.dispose()});var r=i.accB1;i.accB1=e(t.multiply(i.accB1,i.b1)),r.dispose()}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.firstMoment.dispose(),this.weightedInfNorm.dispose(),this.eps.dispose(),this.accB1.dispose(),this.b1.dispose(),this.b2.dispose()},e}(t("./optimizer").Optimizer);r.AdamaxOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./optimizer":43}],42:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r,n){var i=t.call(this,e,n)||this;return i.learningRate=e,i.momentum=r,i.variableVelocities=new o.TensorArrayMap,i.m=a.Scalar.new(i.momentum),i}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.variableVelocities.size()&&this.variableNodes.forEach(function(t){s.variableVelocities.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.variableVelocities.get(r.output),u=t.scaledArrayAdd(i.m,s,i.one,o),c=t.scaledArrayAdd(i.c,u,i.one,a);i.variableVelocities.set(r.output,e(u)),n.set(r.output,e(c)),r.data=c,a.dispose(),s.dispose()})}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.m.dispose(),this.variableVelocities.dispose()},e.prototype.setMomentum=function(t){this.momentum=t},e}(t("./sgd_optimizer").SGDOptimizer);r.MomentumOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./sgd_optimizer":45}],43:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../../math/ndarray"),a=t("../session_util"),o=t("../tensor_array_map"),i=function(){function t(t,e){this.learningRate=t,this.variableGradients=new o.TensorArrayMap,this.one=n.Scalar.new(1),null!=e&&(this.specifiedVariableNodes=e)}return t.prototype.beforeBatch=function(t,e,r,o,i){var s=this;this.variableNodes=null==this.specifiedVariableNodes?a.getVariableNodesFromEvaluationSet(r.nodes):this.specifiedVariableNodes,e!==this.prevBatchSize&&(null!=this.c&&this.c.dispose(),this.prevBatchSize=e,this.c=n.Scalar.new(-this.learningRate/e)),this.variableNodes.forEach(function(t){return s.variableGradients.set(t.output,n.NDArray.zeros(t.output.shape))})},t.prototype.afterExample=function(t,e,r,n){var a=this;t.scope(function(e){a.variableNodes.forEach(function(r){var o=n.get(r.output),i=a.variableGradients.get(r.output);a.variableGradients.set(r.output,e(t.add(o,i))),i.dispose()})})},t.prototype.dispose=function(){null!=this.c&&this.c.dispose(),this.one.dispose()},t}();r.Optimizer=i},{"../../math/ndarray":63,"../session_util":48,"../tensor_array_map":49}],44:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../../math/ndarray"),o=t("../tensor_array_map"),i=function(t){function e(e,r,n){var i=t.call(this,e,n)||this;return i.learningRate=e,i.gamma=r,i.accumulatedSquaredGradients=new o.TensorArrayMap,i.eps=a.Scalar.new(1e-6),i.g=a.Scalar.new(i.gamma),i}return n(e,t),e.prototype.beforeBatch=function(e,r,n,o,i){var s=this;t.prototype.beforeBatch.call(this,e,r,n,o,i),0===this.accumulatedSquaredGradients.size()&&this.variableNodes.forEach(function(t){s.accumulatedSquaredGradients.set(t.output,a.NDArray.zeros(t.output.shape))})},e.prototype.afterBatch=function(t,e,r,n,a){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=i.accumulatedSquaredGradients.get(r.output),u=t.multiply(o,o),c=t.scaledArrayAdd(i.g,s,t.subtract(i.one,i.g),u),p=t.scaledArrayAdd(i.c,t.divide(o,t.add(t.sqrt(c),i.eps)),i.one,a);i.accumulatedSquaredGradients.set(r.output,e(c)),n.set(r.output,e(p)),r.data=p,a.dispose(),s.dispose()})}),this.variableGradients.dispose(),this.variableGradients=new o.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this),this.eps.dispose(),this.g.dispose(),this.accumulatedSquaredGradients.dispose()},e}(t("./optimizer").Optimizer);r.RMSPropOptimizer=i},{"../../math/ndarray":63,"../tensor_array_map":49,"./optimizer":43}],45:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../tensor_array_map"),o=function(t){function e(e,r){var n=t.call(this,e,r)||this;return n.learningRate=e,n}return n(e,t),e.prototype.afterBatch=function(t,e,r,n,o){var i=this;t.scope(function(e){i.variableNodes.forEach(function(r){var a=n.get(r.output),o=i.variableGradients.get(r.output),s=t.scaledArrayAdd(i.c,o,i.one,a);n.set(r.output,e(s)),r.data=s,a.dispose()})}),this.variableGradients.dispose(),this.variableGradients=new a.TensorArrayMap},e.prototype.dispose=function(){t.prototype.dispose.call(this)},e.prototype.setLearningRate=function(t){this.learningRate=t},e}(t("./optimizer").Optimizer);r.SGDOptimizer=o},{"../tensor_array_map":49,"./optimizer":43}],46:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.defaultCompare=function(t,e){return t===e?0:t<e?-1:1};var n=function(){function t(t,e){this.comparator=t,this.indexObserver=e,this.heap=[]}return t.prototype.enqueue=function(t){this.heap.push(t),this.onIndexChanged(t,this.heap.length-1),this.siftUp(this.heap.length-1)},t.prototype.dequeue=function(){if(this.empty())throw new Error("dequeue called on empty priority queue.");var t=this.heap[0];return this.swap(0,this.heap.length-1),this.heap.pop(),this.siftDown(0),t},t.prototype.update=function(t,e){var r=e===this.heap.length-1;r||this.swap(e,this.heap.length-1),this.heap.pop(),r||(-1!==this.siftUpIndex(e)?this.siftUp(e):-1!==this.siftDownIndex(e)&&this.siftDown(e)),this.enqueue(t)},t.prototype.empty=function(){return 0===this.heap.length},t.prototype.onIndexChanged=function(t,e){this.indexObserver&&this.indexObserver(t,e)},t.prototype.getParentIndex=function(t){return 0===t?-1:Math.floor((t-1)/2)},t.prototype.getLeftChildIndex=function(t){var e=2*t+1;return e<this.heap.length?e:-1},t.prototype.getRightChildIndex=function(t){var e=2*t+2;return e<this.heap.length?e:-1},t.prototype.siftUpIndex=function(t){var e=this.getParentIndex(t);return-1===e?-1:this.compare(e,t)>0?e:-1},t.prototype.siftUp=function(t){for(var e=this.siftUpIndex(t);-1!==e;)this.swap(t,e),t=e,e=this.siftUpIndex(t)},t.prototype.siftDownIndex=function(t){if(t>=this.heap.length)return-1;var e=t,r=this.getLeftChildIndex(t);-1!==r&&this.compare(r,e)<0&&(e=r);var n=this.getRightChildIndex(t);return-1!==n&&this.compare(n,e)<0&&(e=n),e===t?-1:e},t.prototype.siftDown=function(t){for(var e=this.siftDownIndex(t);-1!==e;)this.swap(t,e),t=e,e=this.siftDownIndex(t)},t.prototype.compare=function(t,e){return this.comparator(this.heap[t],this.heap[e])},t.prototype.swap=function(t,e){var r=this.heap[t];this.heap[t]=this.heap[e],this.heap[e]=r,this.onIndexChanged(this.heap[t],t),this.onIndexChanged(this.heap[e],e)},t}();r.PriorityQueue=n},{}],47:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../math/ndarray"),a=t("../util"),o=t("./operation_emitter"),i=t("./session_util"),s=t("./tensor_array_map"),u=function(){return function(t){var e=this;this.dict={},t&&t.forEach(function(t){return e.dict[t.tensor.id]=t})}}();r.FeedDictionary=u;var c;!function(t){t[t.NONE=0]="NONE",t[t.SUM=1]="SUM",t[t.MEAN=2]="MEAN"}(c=r.CostReduction||(r.CostReduction={}));var p=function(){function t(t,e){this.math=e,this.activationArrayMap=new s.TensorArrayMap,this.runtimeCache={},this.oneScalar=n.Scalar.new(1),this.gradientArrayMap=new s.SummedTensorArrayMap(this.math)}return t.prototype.dispose=function(){var t=this;this.activationArrayMap.dispose(),Object.keys(this.runtimeCache).forEach(function(e){var r=t.runtimeCache[e];r.operations&&r.operations.forEach(function(t){return t.dispose()})}),this.runtimeCache={},null!=this.batchSizeScalar&&this.batchSizeScalar.dispose(),this.oneScalar.dispose()},t.prototype.evalAll=function(t,e){var r=this;return this.math.scope(function(){var n=new u(e),a=r.getOrCreateRuntime(t,n),o=r.activationArrayMap;i.disposeAndInitializeOperationOutputs(a.nodes,o),i.disposeTransientOperationArrays(a.operations,r.activationArrayMap,r.gradientArrayMap),i.addPersistentArraysToTensorArrayMap(a.nodes,o),i.loadInputsFromFeedDictionaryToTensorArrayMap(n,o,r.math),a.operations.forEach(function(t){return t.feedForward(r.math,o)});var s=t.map(function(t){return o.get(t)});return t.forEach(function(t){return o.delete(t)}),i.releaseFeedDictionaryInputsFromTensorArrayMap(n,o,r.math),s})},t.prototype.eval=function(t,e){return this.evalAll([t],e)[0]},t.prototype.train=function(t,e,r,o,s){var p=this;void 0===s&&(s=c.NONE),a.assert(a.isScalarShape(t.shape),"Cost tensor for training must be a scalar value."),this.prevBatchSize!==r&&(this.prevBatchSize=r,this.batchSizeScalar=n.Scalar.new(r));var l=new u(e);i.throwIfFeedDictionaryContainsNDArrays(l);var h=this.getOrCreateRuntime([t],l),f=h.operations,d=h.operations.slice().reverse(),v=this.activationArrayMap,m=this.gradientArrayMap;return m.nullify(t),m.add(t,this.oneScalar),i.addPersistentArraysToTensorArrayMap(h.nodes,v),o.beforeBatch(this.math,r,h,v,m),this.math.scope(function(e,a){for(var u=a(n.Scalar.new(0)),c=0;c<r;++c)i.disposeAndInitializeOperationOutputs(h.nodes,v),i.disposeAndInitializeOperationInputGradients(h.nodes,m),i.disposeTransientOperationArrays(h.operations,v,m),i.loadInputsFromFeedDictionaryToTensorArrayMap(l,v,p.math),f.forEach(function(t){return t.feedForward(p.math,v)}),d.forEach(function(t){return t.backProp(p.math,v,m)}),o.afterExample(p.math,h,v,m),i.releaseFeedDictionaryInputsFromTensorArrayMap(l,v,p.math),u=p.updateCostForExample(u,v.get(t),s);return o.afterBatch(p.math,r,h,v,m),p.updateCostForBatch(u,s)})},t.prototype.updateCostForExample=function(t,e,r){return r===c.MEAN||r===c.SUM?this.math.add(t,e):t},t.prototype.updateCostForBatch=function(t,e){return e===c.MEAN?this.math.divide(t,this.batchSizeScalar):t},t.prototype.getOrCreateRuntime=function(t,e){var r=this.makeRuntimeCacheKey(t,e),n=this.runtimeCache[r];if(void 0===n){var a=i.getOrderedEvaluationSetFromEvalTensor(t,e);i.removeFeedDictionaryNodesFromEvaluationSet(e,a),i.throwErrorIfEvaluationSetContainsPlaceholderNodes(a),n={nodes:a,operations:o.emitFromGraphNodes(a)},this.runtimeCache[r]=n}return n},t.prototype.makeRuntimeCacheKey=function(t,e){return t.map(function(t){return t.id}).sort().join("_")+"__"+Object.keys(e.dict).sort().join("_")},t}();r.Session=p},{"../math/ndarray":63,"../util":96,"./operation_emitter":18,"./session_util":48,"./tensor_array_map":49}],48:[function(t,e,r){"use strict";function n(t){return Object.keys(t.dict).map(function(e){return t.dict[+e].tensor.node})}Object.defineProperty(r,"__esModule",{value:!0});var a=t("../math/ndarray"),o=t("../util"),i=t("./graph"),s=t("./graph_util");r.getTerminatingNodesFromFeedDictionary=n,r.getOrderedEvaluationSetFromEvalTensor=function(t,e){var r=n(e),a=t.map(function(t){return t.node}),o=s.getUnorderedEvaluationSet(a,r);return s.getOrderedEvaluationSet(o)},r.addPersistentArraysToTensorArrayMap=function(t,e){t.forEach(function(t){(t instanceof i.VariableNode||t instanceof i.ConstantNode)&&e.set(t.output,t.data)})},r.getVariableNodesFromEvaluationSet=function(t){var e=[];return t.forEach(function(t){t instanceof i.VariableNode&&e.push(t)}),e},r.throwIfFeedDictionaryContainsNDArrays=function(t){Object.keys(t.dict).forEach(function(e){if(t.dict[+e].data instanceof a.NDArray)throw new Error("training requires FeedDictionary entries to be InputProvidersand not NDArrays.")})},r.loadInputsFromFeedDictionaryToTensorArrayMap=function(t,e,r){Object.keys(t.dict).forEach(function(n){var i,s=t.dict[+n];i=s.data instanceof a.NDArray?s.data:s.data.getNextCopy(r),o.assert(o.arraysEqual(s.tensor.shape,i.shape),"Error loading FeedEntry: feeding NDArray of shape "+i.shape+" does not match Tensor (id: "+s.tensor.id+") shape: "+s.tensor.shape+"."),e.set(s.tensor,i)})},r.releaseFeedDictionaryInputsFromTensorArrayMap=function(t,e,r){Object.keys(t.dict).forEach(function(n){var o=t.dict[+n];if(!(o.data instanceof a.NDArray)){var i=o.data,s=e.get(o.tensor);i.disposeCopy(r,s)}e.delete(o.tensor)})},r.removeFeedDictionaryNodesFromEvaluationSet=function(t,e){for(var r=0;r<e.length;){var n=e[r];null!=t.dict[n.output.id]?e.splice(r,1):++r}},r.disposeAndInitializeOperationOutputs=function(t,e){t.forEach(function(t){s.isInputNode(t)||(s.isPassthroughNode(t,e)||e.disposeArray(t.output),e.set(t.output,null))})},r.disposeAndInitializeOperationInputGradients=function(t,e){t.forEach(function(t){Object.keys(t.inputs).forEach(function(r){var n=t.inputs[r];e.get(n,!0)!==e.get(t.output,!0)&&e.disposeArray(n),e.nullify(n)})})},r.disposeTransientOperationArrays=function(t,e,r){t.forEach(function(t){return t.disposeTransientArrays(e,r)})},r.throwErrorIfEvaluationSetContainsPlaceholderNodes=function(t){t.forEach(function(t){if(t instanceof i.PlaceholderNode){var e="["+t.output.shape.join(", ")+"]";throw new Error('Placeholder node "'+t.name+'" '+e+" not present in feed dictionary.")}})}},{"../math/ndarray":63,"../util":96,"./graph":16,"./graph_util":17}],49:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function t(){this.dict={}}return t.prototype.get=function(t,e){if(void 0===e&&(e=!1),!e&&void 0===this.dict[t.id])throw new Error("tensor "+t.id+" not in array map.");var r=this.dict[t.id];if(!e&&null===r)throw new Error("tensor "+t.id+" has null array.");return r},t.prototype.delete=function(t){delete this.dict[t.id]},t.prototype.nullify=function(t){this.dict[t.id]=null},t.prototype.disposeArray=function(t){if(void 0!==this.dict[t.id]){var e=this.dict[t.id];null!==e&&(e.dispose(),this.dict[t.id]=null)}},t.prototype.size=function(){return Object.keys(this.dict).length},t.prototype.dispose=function(){var t=this;Object.keys(this.dict).forEach(function(e){var r=t.dict[+e];r&&r.dispose()}),this.dict={}},t.prototype.hasNullArray=function(t){if(void 0===this.dict[t.id])throw new Error("tensor "+t.id+" not in array map.");return null===this.dict[t.id]},t}();r.TensorArrayMapBase=a;var o=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.set=function(t,e){this.dict[t.id]=e},e}(a);r.TensorArrayMap=o;var i=function(t){function e(e){var r=t.call(this)||this;return r.math=e,r}return n(e,t),e.prototype.add=function(t,e){if(null==this.dict[t.id])this.dict[t.id]=this.math.keep(e);else{var r=this.get(t),n=this.math.keep(this.math.addStrict(r,e));this.dict[t.id]=n,r.dispose()}},e}(a);r.SummedTensorArrayMap=i},{}],50:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n,a=t("./graph/session"),o=t("./math/ndarray");!function(t){t[t.SUM=0]="SUM",t[t.MEAN=1]="MEAN"}(n=r.MetricReduction||(r.MetricReduction={}));var i=function(){function t(t,e,r){this.math=t,this.session=e,this.eventObserver=r,this.lastCostTimestamp=0,this.lastEvalTimestamp=0,this.totalIdleTimeMs=0,this.resetStatistics(),this.zeroScalar=o.Scalar.new(0)}return t.prototype.resetStatistics=function(){this.totalBatchesTrained=0,this.totalIdleTimeMs=0,this.lastStopTimestamp=null},t.prototype.train=function(t,e,r,a,i,s,u,c,p,l,h){void 0===p&&(p=n.MEAN),void 0===l&&(l=1500),void 0===h&&(h=500),this.costTensor=t,this.trainFeedEntries=e,this.metricTensor=s,this.metricFeedEntries=u,null!=c&&this.metricBatchSize!==c&&(null!=this.metricBatchSizeScalar&&this.metricBatchSizeScalar.dispose(),this.metricBatchSizeScalar=o.Scalar.new(c)),this.metricBatchSize=c,this.metricReduction=p,this.batchSize=r,this.optimizer=a,this.metricIntervalMs=l,this.costIntervalMs=h,this.currentTrainLoopNumBatches=i,this.batchesTrainedThisRun=0,this.isTraining=!0,this.trainStartTimestamp=performance.now(),this.trainNetwork()},t.prototype.stopTraining=function(){this.isTraining=!1,this.lastStopTimestamp=performance.now()},t.prototype.resumeTraining=function(){this.isTraining=!0,null!=this.lastStopTimestamp&&(this.totalIdleTimeMs+=performance.now()-this.lastStopTimestamp),this.trainNetwork()},t.prototype.trainNetwork=function(){var t=this;if(this.batchesTrainedThisRun===this.currentTrainLoopNumBatches&&this.stopTraining(),this.isTraining){var e=performance.now(),r=null!=this.eventObserver.avgCostCallback&&e-this.lastCostTimestamp>this.costIntervalMs;r&&(this.lastCostTimestamp=e);var n=r?a.CostReduction.MEAN:a.CostReduction.NONE;this.math.scope(function(a){var o=t.session.train(t.costTensor,t.trainFeedEntries,t.batchSize,t.optimizer,n);if(r){var i=performance.now()-e;if(t.eventObserver.avgCostCallback(o),null!=t.eventObserver.trainExamplesPerSecCallback){var s=1e3*t.batchSize/i;t.eventObserver.trainExamplesPerSecCallback(s)}}null!=t.eventObserver.metricCallback&&null!=t.metricFeedEntries&&e-t.lastEvalTimestamp>t.metricIntervalMs&&(t.lastEvalTimestamp=e,null!=t.lastComputedMetric&&t.lastComputedMetric.dispose(),t.lastComputedMetric=t.computeMetric(),t.eventObserver.metricCallback(t.lastComputedMetric)),null!=t.eventObserver.totalTimeCallback&&t.eventObserver.totalTimeCallback((e-t.trainStartTimestamp)/1e3),t.batchesTrainedThisRun++,t.totalBatchesTrained++,null!=t.eventObserver.batchesTrainedCallback&&t.eventObserver.batchesTrainedCallback(t.totalBatchesTrained)}),requestAnimationFrame(function(){return t.trainNetwork()})}else null!=this.eventObserver.doneTrainingCallback&&this.eventObserver.doneTrainingCallback()},t.prototype.infer=function(t,e,r,n,a){var i=this;if(void 0===r&&(r=3e3),void 0===n&&(n=5),null==this.eventObserver.inferenceExamplesCallback&&null==this.eventObserver.inferenceExamplesPerSecCallback)throw new Error("Cannot start inference loop, no inference example or examples/sec observer provided.");for(var s=0;s<e.length;s++)if(e[s].data instanceof o.NDArray)throw new Error("Cannot start inference on the model runner with feed entries of type NDArray. Please use InputProviders.");this.inferenceExampleIntervalMs=r,this.inferenceTensor=t,this.inferenceFeedEntries=e,this.inferenceExampleCount=n,this.currentInferenceLoopNumPasses=a,this.isInferring||(this.inferencePassesThisRun=0,requestAnimationFrame(function(){return i.inferNetwork()})),this.isInferring=!0},t.prototype.inferNetwork=function(){var t=this;this.isInferring&&this.inferencePassesThisRun!==this.currentInferenceLoopNumPasses&&(this.math.scope(function(e,r){for(var n=[],a=[],o=performance.now(),i=0;i<t.inferenceExampleCount;i++){for(var s=[],u=0;u<t.inferenceFeedEntries.length;u++){var c=t.inferenceFeedEntries[u],p=c.data.getNextCopy(t.math);s.push({tensor:c.tensor,data:r(p)})}n.push(s),a.push(t.session.eval(t.inferenceTensor,s))}if(null!=t.eventObserver.inferenceExamplesPerSecCallback){a[a.length-1].getValues();var l=performance.now()-o,h=1e3*t.inferenceExampleCount/l;t.eventObserver.inferenceExamplesPerSecCallback(h)}null!=t.eventObserver.inferenceExamplesCallback&&t.eventObserver.inferenceExamplesCallback(n,a),t.inferencePassesThisRun++}),this.lastInferTimeoutID=window.setTimeout(function(){return t.inferNetwork()},this.inferenceExampleIntervalMs))},t.prototype.stopInferring=function(){this.isInferring=!1,window.clearTimeout(this.lastInferTimeoutID)},t.prototype.isInferenceRunning=function(){return this.isInferring},t.prototype.computeMetric=function(){var t=this;if(null==this.metricFeedEntries)throw new Error("Cannot compute metric, no metric FeedEntries provided.");var e=this.zeroScalar;return this.math.scope(function(r){for(var a=0;a<t.metricBatchSize;a++){var o=t.session.eval(t.metricTensor,t.metricFeedEntries);e=t.math.add(e,o)}return t.metricReduction===n.MEAN&&(e=t.math.divide(e,t.metricBatchSizeScalar)),e})},t.prototype.getTotalBatchesTrained=function(){return this.totalBatchesTrained},t.prototype.getLastComputedMetric=function(){return this.lastComputedMetric},t.prototype.setMath=function(t){this.math=t},t.prototype.setSession=function(t){this.session=t},t.prototype.setInferenceTensor=function(t){this.inferenceTensor=t},t.prototype.setInferenceExampleCount=function(t){this.inferenceExampleCount=t},t}();r.GraphRunner=i},{"./graph/session":47,"./math/ndarray":63}],51:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("./data/xhr-dataset");r.xhr_dataset=n;var a=t("./environment");r.environment=a;var o=t("./math/conv_util");r.conv_util=o;var i=t("./math/webgl/gpgpu_util");r.gpgpu_util=i;var s=t("./math/webgl/render_ndarray_gpu_util");r.render_ndarray_gpu_util=s;var u=t("./math/webgl/webgl_util");r.webgl_util=u;var c=t("./test_util");r.test_util=c;var p=t("./util");r.util=p;var l=t("./version");r.version=l.version;var h=t("./data/checkpoint_loader");r.CheckpointLoader=h.CheckpointLoader;var f=t("./data/dataset");r.InMemoryDataset=f.InMemoryDataset;var d=t("./data/input_provider");r.InCPUMemoryShuffledInputProviderBuilder=d.InCPUMemoryShuffledInputProviderBuilder,r.InGPUMemoryShuffledInputProviderBuilder=d.InGPUMemoryShuffledInputProviderBuilder;var v=t("./data/xhr-dataset");r.XhrDataset=v.XhrDataset;var m=t("./environment");r.ENV=m.ENV,r.Environment=m.Environment;var y=t("./graph/graph");r.Graph=y.Graph,r.Tensor=y.Tensor;var g=t("./graph/optimizers/adadelta_optimizer");r.AdadeltaOptimizer=g.AdadeltaOptimizer;var x=t("./graph/optimizers/adagrad_optimizer");r.AdagradOptimizer=x.AdagradOptimizer;var w=t("./graph/optimizers/adam_optimizer");r.AdamOptimizer=w.AdamOptimizer;var b=t("./graph/optimizers/adamax_optimizer");r.AdamaxOptimizer=b.AdamaxOptimizer;var _=t("./graph/optimizers/momentum_optimizer");r.MomentumOptimizer=_.MomentumOptimizer;var A=t("./graph/optimizers/optimizer");r.Optimizer=A.Optimizer;var T=t("./graph/optimizers/rmsprop_optimizer");r.RMSPropOptimizer=T.RMSPropOptimizer;var E=t("./graph/optimizers/sgd_optimizer");r.SGDOptimizer=E.SGDOptimizer;var S=t("./graph/session");r.CostReduction=S.CostReduction,r.Session=S.Session;var C=t("./graph_runner");r.GraphRunner=C.GraphRunner,r.MetricReduction=C.MetricReduction;var N=t("./initializers");r.ConstantInitializer=N.ConstantInitializer,r.NDArrayInitializer=N.NDArrayInitializer,r.OnesInitializer=N.OnesInitializer,r.RandomNormalInitializer=N.RandomNormalInitializer,r.RandomTruncatedNormalInitializer=N.RandomTruncatedNormalInitializer,r.RandomUniformInitializer=N.RandomUniformInitializer,r.VarianceScalingInitializer=N.VarianceScalingInitializer,r.ZerosInitializer=N.ZerosInitializer;var O=t("./math/math");r.MatrixOrientation=O.MatrixOrientation,r.NDArrayMath=O.NDArrayMath;var R=t("./math/math_cpu");r.NDArrayMathCPU=R.NDArrayMathCPU;var M=t("./math/math_gpu");r.NDArrayMathGPU=M.NDArrayMathGPU;var D=t("./math/ndarray");r.initializeGPU=D.initializeGPU;var I=t("./math/ndarray");r.Array1D=I.Array1D,r.Array2D=I.Array2D,r.Array3D=I.Array3D,r.Array4D=I.Array4D,r.NDArray=I.NDArray,r.Scalar=I.Scalar;var P=t("./math/webgl/gpgpu_context");r.GPGPUContext=P.GPGPUContext},{"./data/checkpoint_loader":10,"./data/dataset":11,"./data/input_provider":12,"./data/xhr-dataset":13,"./environment":15,"./graph/graph":16,"./graph/optimizers/adadelta_optimizer":38,"./graph/optimizers/adagrad_optimizer":39,"./graph/optimizers/adam_optimizer":40,"./graph/optimizers/adamax_optimizer":41,"./graph/optimizers/momentum_optimizer":42,"./graph/optimizers/optimizer":43,"./graph/optimizers/rmsprop_optimizer":44,"./graph/optimizers/sgd_optimizer":45,"./graph/session":47,"./graph_runner":50,"./initializers":52,"./math/conv_util":57,"./math/math":60,"./math/math_cpu":61,"./math/math_gpu":62,"./math/ndarray":63,"./math/webgl/gpgpu_context":76,"./math/webgl/gpgpu_util":78,"./math/webgl/render_ndarray_gpu_util":85,"./math/webgl/webgl_util":94,"./test_util":95,"./util":96,"./version":97}],52:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("./math/ndarray"),a=function(){function t(t,e,r){void 0===t&&(t=1),void 0===e&&(e="fan_in"),void 0===r&&(r="normal"),this.scale=t,this.mode=e,this.distribution=r}return t.prototype.initialize=function(t,e,r){var a=0;if("fan_in"===this.mode)a=e;else if("fan_out"===this.mode)a=r;else{if("fan_avg"!==this.mode)throw new Error("Unexpected mode for variance scaling initializer: "+this.mode);a=(e+r)/2}if("normal"===this.distribution)return n.NDArray.randTruncatedNormal(t,0,Math.sqrt(this.scale/a));if("uniform"===this.distribution)return n.NDArray.randUniform(t,0,Math.sqrt(3*this.scale/a));throw new Error("Unexpected distribution for variance scaling initializer: "+this.distribution)},t}();r.VarianceScalingInitializer=a;var o=function(){function t(){}return t.prototype.initialize=function(t,e,r){return n.NDArray.zeros(t)},t}();r.ZerosInitializer=o;var i=function(){function t(){}return t.prototype.initialize=function(t,e,r){var a=n.NDArray.zeros(t);return a.fill(1),a},t}();r.OnesInitializer=i;var s=function(){function t(t){void 0===t&&(t=0),this.value=t}return t.prototype.initialize=function(t,e,r){var a=n.NDArray.zeros(t);return a.fill(this.value),a},t}();r.ConstantInitializer=s;var u=function(){function t(t){this.ndarray=t}return t.prototype.initialize=function(t,e,r){return this.ndarray},t}();r.NDArrayInitializer=u;var c=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=.05),this.mean=t,this.stdev=e}return t.prototype.initialize=function(t,e,r){return n.NDArray.randNormal(t,this.mean,this.stdev)},t}();r.RandomNormalInitializer=c;var p=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=.05),this.mean=t,this.stdev=e}return t.prototype.initialize=function(t,e,r){return n.NDArray.randTruncatedNormal(t,this.mean,this.stdev)},t}();r.RandomTruncatedNormalInitializer=p;var l=function(){function t(t,e){void 0===t&&(t=-.05),void 0===e&&(e=.05),this.minval=t,this.maxval=e}return t.prototype.initialize=function(t,e,r){return n.NDArray.randUniform(t,this.minval,this.maxval)},t}();r.RandomUniformInitializer=l},{"./math/ndarray":63}],53:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("./ndarray"),a=function(){function t(){}return t.prototype.output=function(t,e){return t.scope(function(){return t.tanh(e)})},t.prototype.der=function(t,e,r){return t.scope(function(){var e=t.elementWiseMul(r,r);return t.scalarMinusArray(n.Scalar.ONE,e)})},t.prototype.dispose=function(){},t}();r.TanHFunc=a;var o=function(){function t(){}return t.prototype.output=function(t,e){return t.scope(function(){return t.relu(e)})},t.prototype.der=function(t,e,r){return t.scope(function(){return t.step(e)})},t.prototype.dispose=function(){},t}();r.ReLUFunc=o;var i=function(){function t(t){this.alpha=t}return t.prototype.output=function(t,e){return t.leakyRelu(e,this.alpha)},t.prototype.der=function(t,e,r){return t.step(e,this.alpha)},t.prototype.dispose=function(){},t}();r.LeakyReluFunc=i;var s=function(){function t(){}return t.prototype.output=function(t,e){return t.scope(function(){return t.sigmoid(e)})},t.prototype.der=function(t,e,r){return t.scope(function(){var e=t.elementWiseMul(r,r);return t.subStrict(r,e)})},t.prototype.dispose=function(){},t}();r.SigmoidFunc=s;var u=function(){function t(){}return t.prototype.output=function(t,e){return t.scope(function(){return t.elementWiseMul(e,e)})},t.prototype.der=function(t,e,r){return t.scope(function(){return t.scalarTimesArray(n.Scalar.TWO,e)})},t.prototype.dispose=function(){},t}();r.SquareFunc=u},{"./ndarray":63}],54:[function(t,e,r){"use strict";function n(t,e){for(var r=0;r<t.length;++r)if(t[t.length-r-1]!==e-1-r)return!1;return!0}function a(t,e,r){for(var n=t.length+e.length,a=[],o=0,i=0,s=0;s<n;s++)-1===r.indexOf(s)?a.push(t[o++]):a.push(e[i++]);return a}Object.defineProperty(r,"__esModule",{value:!0}),r.axesAreInnerMostDims=n,r.combineLocations=a,r.computeOutAndReduceShapes=function(t,e){for(var r=[],n=t.length,a=0;a<n;a++)-1===e.indexOf(a)&&r.push(t[a]);return[r,e.map(function(e){return t[e]})]},r.expandShapeToKeepDim=function(t,e){return a(t,e.map(function(t){return 1}),e)},r.parseAxisParam=function(t,e){return null==t?t=e.map(function(t,e){return e}):"number"==typeof t&&(t=[t]),t},r.assertAxesAreInnerMostDims=function(t,e,r){if(!n(e,r))throw new Error(t+" supports only inner-most axes for now. Got axes "+e+" and rank-"+r+" input.")},r.getPermutedAxes=function(t,e){if(n(t,e))return null;for(var r=[],a=0;a<e;++a)-1===t.indexOf(a)&&r.push(a);return t.forEach(function(t){return r.push(t)}),r},r.getInnerMostAxes=function(t,e){for(var r=[],n=e-t;n<e;++n)r.push(n);return r}},{}],55:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.getBroadcastDims=function(t,e){for(var r=t.length,n=[],a=0;a<r;a++){var o=r-1-a,i=t[o]||1;(e[e.length-1-a]||1)>1&&1===i&&n.unshift(o)}return n},r.broadcastDimsAreOuter=function(t){for(var e=0;e<t.length;e++)if(t[e]!==e)return!1;return!0},r.assertAndGetBroadcastShape=function(t,e){for(var r=[],n="Operands could not be broadcast together with shapes "+t+" and "+e+".",a=Math.max(t.length,e.length),o=0;o<a;o++){var i=t[t.length-o-1]||1,s=e[e.length-o-1]||1;if(i>1&&s>1&&i!==s)throw Error(n);r.unshift(Math.max(i,s))}return r}},{}],56:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../util");r.assertParams=function(t,e,r){var a=t.length,o=e.length;n.assert(t.length===e.length,"Error in concat"+a+"D: rank of x1 ("+a+") and x2 ("+o+") must be the same."),n.assert(r>=0&&r<a,"Error in concat"+a+"D: axis must be between 0 and "+(a-1)+".");for(var i=0;i<a;i++)n.assert(i===r||t[i]===e[i],"Error in concat"+a+"D: Shape ("+t+") does not match ("+e+") along the non-concatenated axis "+i+".")},r.computeOutShape=function(t,e,r){n.assert(t.length===e.length,"x1 and x2 should have the same rank.");var a=t.slice();return a[r]+=e[r],a}},{"../util":96}],57:[function(t,e,r){"use strict";function n(t,e,r,n,o){null==o&&(o=a(t,e,n));var i=t[0],u=t[1],c=(i-e+2*o)/n+1;s.assert(s.isInt(c),"The output # of rows ("+c+") must be an integer. Change the stride and/or zero pad parameters");var p=(u-e+2*o)/n+1;return s.assert(s.isInt(p),"The output # of columns ("+p+") must be an integer. Change the stride and/or zero pad parameters"),[c,p,r]}function a(t,e,r){return Math.floor((t[0]*(r-1)-r+e)/2)}function o(t){return"number"==typeof t?[t,t]:t}function i(t,e,r,a,o,i,s){var u,c,p;if("number"==typeof t){u={top:t,bottom:t,left:t,right:t};var l=n([e,r,1],i,1,a,t);c=l[0],p=l[1]}else if("same"===t){var h=((c=Math.ceil(e/a))-1)*a+i-e,f=((p=Math.ceil(r/o))-1)*o+s-r,d=Math.floor(h/2),v=h-d,m=Math.floor(f/2);u={top:d,bottom:v,left:m,right:f-m}}else{if("valid"!==t)throw Error("Unknown padding parameter: "+t);u={top:0,bottom:0,left:0,right:0},c=Math.ceil((e-i+1)/a),p=Math.ceil((r-s+1)/o)}return{padInfo:u,outHeight:c,outWidth:p}}Object.defineProperty(r,"__esModule",{value:!0});var s=t("../util");r.computeDepthwiseConv2DInfo=function(t,e,r,n){var a=e[0],s=e[1],u=e[2],c=e[3],p=o(r),l=p[0],h=p[1],f=t[1],d=t[2],v=t[0],m=i(n,f,d,l,h,a,s),y=m.padInfo;return{inShape:t,outShape:[v,m.outHeight,m.outWidth,u*c],channelMul:c,strideHeight:l,strideWidth:h,filterHeight:a,filterWidth:s,padInfo:y}},r.computeConv2DInfo=function(t,e,r,n,a,o,s){var u=i(s,t[0],t[1],a,o,e,r),c=u.padInfo;return{inShape:t,outShape:[u.outHeight,u.outWidth,n],padInfo:c,strideHeight:a,strideWidth:o,filterHeight:e,filterWidth:r}},r.computeOutputShape3D=n,r.computeDefaultPad=a,r.computeWeightsShape4D=function(t,e,r,n){return[r,n,t,e]},r.computeDilatedRC=function(t,e){return[(t[0]-1)*e+1,(t[1]-1)*e+1]}},{"../util":96}],58:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.validateShapes=function(t,e){var r=t[0]*t[1],n=e[0]*e[1];if(r!==n){var a="["+t[0]+", "+t[1]+"]",o="["+e[0]+", "+e[1]+"]";throw new Error("copy2D shapes have different areas:\n sourceSize "+a+", area "+r+"\n destSize "+o+", area "+n)}}},{}],59:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("./ndarray"),a=function(){function t(){this.halfOne=n.Scalar.new(.5)}return t.prototype.cost=function(t,e,r){var n=t.subStrict(e,r),a=t.elementWiseMul(n,n),o=t.scalarTimesArray(this.halfOne,a);return n.dispose(),a.dispose(),o},t.prototype.der=function(t,e,r){return t.subStrict(e,r)},t.prototype.dispose=function(){this.halfOne.dispose()},t}();r.SquareCostFunc=a},{"./ndarray":63}],60:[function(t,e,r){"use strict";function n(t){return"number"==typeof t?[t,t]:t}Object.defineProperty(r,"__esModule",{value:!0});var a=t("../util"),o=t("./axis_util"),i=t("./broadcast_util"),s=t("./concat_util"),u=t("./conv_util"),c=t("./copy2d_util"),p=t("./ndarray"),l=t("./slice_util");!function(t){t.float32="float32",t.int32="int32",t.bool="int32"}(r.SumTypesMap||(r.SumTypesMap={}));var h=function(){function t(t){this.safeMode=t,this.ndarrayScopes=[],this.ndarraysToKeep=[],this.activeScopeNDArraysToKeep=[],this.debugMode=!1}return t.prototype.scope=function(t){var e=this;this.startScope();var r=t(function(t){return e.keep(t)},function(t){return e.track(t)});return r instanceof Promise?(r.then(function(t){return e.endScope(t)}),r):(this.endScope(r),r)},t.prototype.enableDebugMode=function(){this.debugMode=!0,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.")},t.prototype.startScope=function(){var t=[];this.ndarrayScopes.push(t),this.activeScope=t;var e=[];this.ndarraysToKeep.push(e),this.activeScopeNDArraysToKeep=e},t.prototype.extractNDArraysFromScopeResult=function(t){if(null==t)return[];if(t instanceof p.NDArray)return[t];var e=[],r=t;for(var n in r){var a=r[n];a instanceof p.NDArray&&e.push(a)}return e},t.prototype.endScope=function(t){var e=this,r=this.activeScopeNDArraysToKeep,n=this.extractNDArraysFromScopeResult(t);r=r.concat(n);for(var a=0;a<this.activeScope.length;a++){var o=this.activeScope[a];this.isNDArrayDataInList(o,r)||o.dispose()}this.ndarrayScopes.pop(),this.activeScope=0===this.ndarrayScopes.length?null:this.ndarrayScopes[this.ndarrayScopes.length-1],n.forEach(function(t){e.isNDArrayDataInList(t,e.activeScopeNDArraysToKeep)||e.track(t)}),this.ndarraysToKeep.pop(),this.activeScopeNDArraysToKeep=0===this.ndarraysToKeep.length?null:this.ndarraysToKeep[this.ndarraysToKeep.length-1]},t.prototype.isNDArrayDataInList=function(t,e){for(var r=0;r<e.length;r++)if(e[r].getData()===t.getData())return!0;return!1},t.prototype.keep=function(t){if(null==this.activeScope){if(this.safeMode)throw new Error("You are using math in safe mode. Enclose all math.method() calls inside a scope: math.scope(() => {math.method();...}) to avoid memory leaks.");return t}return this.activeScopeNDArraysToKeep.push(t),t},t.prototype.checkForNaN=function(t,e,r){for(var n=0;n<t.length;n++)if(a.isValNaN(t[n],e))throw Error("The result of the last math."+r+" has NaNs.")},t.prototype.track=function(t){if(null==this.activeScope){if(this.safeMode)throw new Error("You are using math in safe mode. Enclose all math.method() calls inside a scope: math.scope(() => {math.method();...}) to avoid memory leaks.");return t}return this.activeScope.push(t),t},t.prototype.dispose=function(){},t.prototype.matMul=function(t,e,r,n){var o=this;void 0===r&&(r=f.REGULAR),void 0===n&&(n=f.REGULAR);var i=r===f.REGULAR?t.shape[1]:t.shape[0],s=n===f.REGULAR?e.shape[0]:e.shape[1];return a.assert(2===t.rank&&2===e.rank,"Error in matMul: inputs must be rank 2, got ranks "+t.rank+" and "+e.rank+"."),a.assert(i===s,"Error in matMul: inner shapes ("+i+") and ("+s+") of NDArrays with shapes "+t.shape+" and "+e.shape+" and orientations "+f[r]+" and "+f[n]+" must match."),this.executeOp("matMul",function(){return o.matMulInternal(t,e,r,n)})},t.prototype.executeOp=function(t,e){var r;this.debugMode&&(r=performance.now());var n=e();if(this.debugMode){var o=n.getValues(),i=a.rightPad(performance.now()-r+"ms",9),s=a.rightPad(t,25),u=n.rank,c=n.size,p=a.rightPad(n.shape.toString(),14);console.log("%c"+s+"\t%c"+i+"\t%c"+u+"D "+p+"\t%c"+c,"font-weight:bold","color:red","color:blue","color: orange"),this.checkForNaN(o,n.dtype,t)}return this.track(n)},t.prototype.vectorTimesMatrix=function(t,e){return a.assert(1===t.rank,"Error in vectorTimesMatrix: first input must be rank 1, but got rank "+t.rank+"."),a.assert(2===e.rank,"Error in vectorTimesMatrix: second input must be rank 2, but got rank "+e.rank+"."),a.assert(t.size===e.shape[0],"Error in vectorTimesMatrix: size of vector ("+t.size+") must match first dimension of matrix ("+e.shape[0]+")"),this.matMul(t.as2D(1,-1),e).as1D()},t.prototype.matrixTimesVector=function(t,e){return a.assert(1===e.rank,"Error in matrixTimesVector: second input must rank 1, but got rank "+e.rank+"."),a.assert(2===t.rank,"Error in matrixTimesVector: first input must be a rank 2, but got rank "+t.rank+"."),a.assert(e.size===t.shape[1],"Error in matrixTimesVector: size of first rank 1 input "+e.size+" must match inner dimension of second rank 2 input, but got shape "+t.shape+"."),this.matMul(t,e.as2D(-1,1)).as1D()},t.prototype.dotProduct=function(t,e){return a.assert(1===t.rank&&1===e.rank,"Error in dotProduct: inputs must be rank 1, but got ranks "+t.rank+" and "+e.rank+"."),a.assert(t.size===e.size,"Error in dotProduct: size of inputs ("+t.size+") and ("+e.size+") must match."),this.matMul(t.as2D(1,-1),e.as2D(-1,1)).asScalar()},t.prototype.outerProduct=function(t,e){return a.assert(1===t.rank&&1===e.rank,"Error in outerProduct: inputs must be rank 1, but got ranks "+t.rank+" and "+e.rank+"."),this.matMul(t.as2D(-1,1),e.as2D(1,-1))},t.prototype.clone=function(t){var e=this;return this.executeOp("clone",function(){return e.cloneInternal(t)})},t.prototype.reshape=function(t,e){return console.warn("math.reshape() is deprecated. Please call reshape() directly on the ndarray object"),t.reshape(e)},t.prototype.slice1D=function(t,e,r){var n=this;return l.assertParamsValid(t,[e],[r]),this.executeOp("slice1D",function(){return n.slice1DInternal(t,e,r)})},t.prototype.slice2D=function(t,e,r){var n=this;return l.assertParamsValid(t,e,r),this.executeOp("slice2D",function(){return n.slice2DInternal(t,e,r)})},t.prototype.slice3D=function(t,e,r){var n=this;return l.assertParamsValid(t,e,r),this.executeOp("slice3D",function(){return n.slice3DInternal(t,e,r)})},t.prototype.slice4D=function(t,e,r){var n=this;return l.assertParamsValid(t,e,r),this.executeOp("slice4D",function(){return n.slice4DInternal(t,e,r)})},t.prototype.copy2D=function(t,e,r,n,o,i){var s=this;a.assert(e[0]+r[0]<=t.shape[0]&&e[1]+r[1]<=t.shape[1],"Error in copy2D: requested source start position "+e+" and source size "+r+" would overflow source NDArrayof shape "+t.shape+"."),a.assert(o[0]+i[0]<=n.shape[0]&&o[1]+i[1]<=n.shape[1],"Error in copy2D: requested dest start position "+o+" and source size "+i+" would overflow dest NDArray ofshape "+n.shape+"."),c.validateShapes(r,i),this.executeOp("copy2D",function(){return s.copy2DInternal(t,e,r,n,o,i),n})},t.prototype.concat1D=function(t,e){var r=this;return s.assertParams(t.shape,e.shape,0),this.executeOp("concat1D",function(){return r.concat1DInternal(t,e)})},t.prototype.concat2D=function(t,e,r){var n=this;return s.assertParams(t.shape,e.shape,r),this.executeOp("concat2D",function(){return n.concat2DInternal(t,e,r)})},t.prototype.concat3D=function(t,e,r){var n=this;return s.assertParams(t.shape,e.shape,r),this.executeOp("concat3D",function(){return n.concat3DInternal(t,e,r)})},t.prototype.concat4D=function(t,e,r){var n=this;return s.assertParams(t.shape,e.shape,r),this.executeOp("concat4D",function(){return n.concat4DInternal(t,e,r)})},t.prototype.logSumExp=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var a=o.parseAxisParam(e,t.shape);return this.executeOp("logSumExp",function(){var e=n.max(t,a,!0),i=n.subtract(t,e),s=n.exp(i),u=n.sum(s,a),c=n.log(u),p=n.add(e.reshape(c.shape),c);if(r){var l=o.expandShapeToKeepDim(p.shape,a);return p.reshape(l)}return p})},t.prototype.sum=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var a=o.parseAxisParam(e,t.shape),i=a,s=o.getPermutedAxes(i,t.rank);return this.executeOp("sum",function(){null!=s&&(t=n.transpose(t,s),i=o.getInnerMostAxes(i.length,t.rank));var e=n.sumInternal(t,i);if(r){var u=o.expandShapeToKeepDim(e.shape,a);return e.reshape(u)}return e})},t.prototype.mean=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var i=o.parseAxisParam(e,t.shape),s=o.computeOutAndReduceShapes(t.shape,i)[1],u=a.sizeFromShape(s);return this.executeOp("mean",function(){return n.scope(function(a,o){var i=n.divide(t,o(p.Scalar.new(u)));return n.sum(i,e,r)})})},t.prototype.argMin=function(t,e){var r=this;void 0===e&&(e=null);var n=o.parseAxisParam(e,t.shape),a=o.getPermutedAxes(n,t.rank);return this.executeOp("argMin",function(){return null!=a&&(t=r.transpose(t,a),n=o.getInnerMostAxes(n.length,t.rank)),r.argMinInternal(t,n)})},t.prototype.argMax=function(t,e){var r=this;void 0===e&&(e=null);var n=o.parseAxisParam(e,t.shape),a=o.getPermutedAxes(n,t.rank);return this.executeOp("argMax",function(){return null!=a&&(t=r.transpose(t,a),n=o.getInnerMostAxes(n.length,t.rank)),r.argMaxInternal(t,n)})},t.prototype.argMaxEquals=function(t,e){var r=this;return a.assertShapesMatch(t.shape,e.shape,"Error in argMaxEquals: "),this.executeOp("argMaxEquals",function(){return r.scope(function(){return r.equal(r.argMax(t),r.argMax(e))})})},t.prototype.equal=function(t,e){var r=this;return this.executeOp("equal",function(){return r.equalInternal(t,e)})},t.prototype.equalStrict=function(t,e){return a.assertShapesMatch(t.shape,e.shape,"Error in equalStrict: "),this.equal(t,e)},t.prototype.topK=function(t,e){var r=this;a.assert(e<=t.size,"Error in topK: k value ("+e+") must be less than size of input ndarray, got shape "+t.shape+".");var n;return this.executeOp("topK",function(){return(n=r.topKInternal(t,e)).values}),this.track(n.indices),n},t.prototype.min=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var a=o.parseAxisParam(e,t.shape),i=a,s=o.getPermutedAxes(i,t.rank);return this.executeOp("min",function(){null!=s&&(t=n.transpose(t,s),i=o.getInnerMostAxes(i.length,t.rank));var e=n.minInternal(t,i);if(r){var u=o.expandShapeToKeepDim(e.shape,a);return e.reshape(u)}return e})},t.prototype.max=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var a=o.parseAxisParam(e,t.shape),i=a,s=o.getPermutedAxes(i,t.rank);return this.executeOp("max",function(){null!=s&&(t=n.transpose(t,s),i=o.getInnerMostAxes(i.length,t.rank));var e=n.maxInternal(t,i);if(r){var u=o.expandShapeToKeepDim(e.shape,a);return e.reshape(u)}return e})},t.prototype.softmax=function(t,e){var r=this;if(void 0===e&&(e=-1),-1===e&&(e=t.rank-1),e!==t.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+t.rank+" and dim was "+e);return this.executeOp("softmax",function(){return r.scope(function(){var n=r.logSumExp(t,[e],!0),a=r.subtract(t,n);return r.exp(a)})})},t.prototype.switchDim=function(t,e){return this.transpose(t,e)},t.prototype.tile=function(t,e){var r=this;return a.assert(t.rank===e.length,"Error in transpose: rank of input "+t.rank+" must match length of reps "+e+"."),this.executeOp("tile",function(){return r.tileInternal(t,e)})},t.prototype.transpose=function(t,e){var r=this;return null==e&&(e=t.shape.map(function(t,e){return e}).reverse()),a.assert(t.rank===e.length,"Error in transpose: rank of input "+t.rank+" must match length of perm "+e+"."),this.executeOp("transpose",function(){return r.transposeInternal(t,e)})},t.prototype.scalarPlusArray=function(t,e){return a.assert(1===t.size,"Error in scalarPlusArray: first argument must be rank 0, but got rank "+t.rank+"."),this.add(t,e)},t.prototype.scalarMinusArray=function(t,e){return a.assert(1===t.size,"Error in scalarMinusArray: first argument must be rank 0, but got rank "+t.rank+"."),this.subtract(t,e)},t.prototype.arrayMinusScalar=function(t,e){return a.assert(1===e.size,"Error in arrayMinusScalar: second argument must be rank 0, but got rank "+e.rank+"."),this.subtract(t,e)},t.prototype.neg=function(t){var e=this;return this.executeOp("neg",function(){return e.negInternal(t)})},t.prototype.add=function(t,e){var r=this;return i.assertAndGetBroadcastShape(t.shape,e.shape),this.executeOp("add",function(){return r.addInternal(t,e)})},t.prototype.addStrict=function(t,e){return a.assertShapesMatch(t.shape,e.shape,"Error in addStrict: "),this.add(t,e)},t.prototype.subtract=function(t,e){var r=this;return i.assertAndGetBroadcastShape(t.shape,e.shape),this.executeOp("subtract",function(){return r.subtractInternal(t,e)})},t.prototype.sub=function(t,e){return this.subtract(t,e)},t.prototype.subStrict=function(t,e){return a.assertShapesMatch(t.shape,e.shape,"Error in subStrict: "),this.subtract(t,e)},t.prototype.multiply=function(t,e){var r=this;return i.assertAndGetBroadcastShape(t.shape,e.shape),this.executeOp("multiply",function(){return r.multiplyInternal(t,e)})},t.prototype.elementWiseMul=function(t,e){return this.multiplyStrict(t,e)},t.prototype.multiplyStrict=function(t,e){return a.assertShapesMatch(t.shape,e.shape,"Error in multiplyStrict: "),this.multiply(t,e)},t.prototype.divide=function(t,e){var r=this;return i.assertAndGetBroadcastShape(t.shape,e.shape),this.executeOp("divide",function(){return r.divideInternal(t,e)})},t.prototype.divideStrict=function(t,e){return a.assertShapesMatch(t.shape,e.shape,"Error in divideStrict: "),this.divide(t,e)},t.prototype.scalarDividedByArray=function(t,e){return a.assert(1===t.size,"Error in scalarDividedByArray: first argument must be rank 0, but got NDArray of rank "+t.rank+"."),this.divide(t,e)},t.prototype.arrayDividedByScalar=function(t,e){return a.assert(1===e.size,"Error in arrayDividedByScalar: second argument must be rank 0, but got NDArray of rank "+e.rank+"."),this.divide(t,e)},t.prototype.ceil=function(t){var e=this;return this.executeOp("ceil",function(){return e.ceilInternal(t)})},t.prototype.floor=function(t){var e=this;return this.executeOp("floor",function(){return e.floorInternal(t)})},t.prototype.exp=function(t){var e=this;return this.executeOp("exp",function(){return e.expInternal(t)})},t.prototype.log=function(t){var e=this;return this.executeOp("log",function(){return e.logInternal(t)})},t.prototype.sqrt=function(t){var e=this;return this.executeOp("sqrt",function(){return e.sqrtInternal(t)})},t.prototype.square=function(t){var e=this;return this.executeOp("square",function(){return e.squareInternal(t)})},t.prototype.abs=function(t){var e=this;return this.executeOp("abs",function(){return e.absInternal(t)})},t.prototype.clip=function(t,e,r){var n=this;return a.assert(e<=r,"Error in clip: min ("+e+") must beless than or equal to max ("+r+")."),this.executeOp("clip",function(){return n.clipInternal(t,e,r)})},t.prototype.relu=function(t){var e=this;return this.executeOp("relu",function(){return e.reluInternal(t)})},t.prototype.elu=function(t){var e=this;return this.executeOp("elu",function(){return e.eluInternal(t)})},t.prototype.leakyRelu=function(t,e){var r=this;return void 0===e&&(e=.2),this.executeOp("leakyRelu",function(){return r.leakyReluInternal(t,e)})},t.prototype.sigmoid=function(t){var e=this;return this.executeOp("sigmoid",function(){return e.sigmoidInternal(t)})},t.prototype.sin=function(t){var e=this;return this.executeOp("sin",function(){return e.sinInternal(t)})},t.prototype.cos=function(t){var e=this;return this.executeOp("cos",function(){return e.cosInternal(t)})},t.prototype.tan=function(t){var e=this;return this.executeOp("tan",function(){return e.tanInternal(t)})},t.prototype.asin=function(t){var e=this;return this.executeOp("asin",function(){return e.asinInternal(t)})},t.prototype.acos=function(t){var e=this;return this.executeOp("acos",function(){return e.acosInternal(t)})},t.prototype.atan=function(t){var e=this;return this.executeOp("atan",function(){return e.atanInternal(t)})},t.prototype.sinh=function(t){var e=this;return this.executeOp("sinh",function(){return e.sinhInternal(t)})},t.prototype.cosh=function(t){var e=this;return this.executeOp("cosh",function(){return e.coshInternal(t)})},t.prototype.tanh=function(t){var e=this;return this.executeOp("tanh",function(){return e.tanhInternal(t)})},t.prototype.step=function(t,e){var r=this;return void 0===e&&(e=0),this.executeOp("step",function(){return r.stepInternal(t,e)})},t.prototype.scaledArrayAdd=function(t,e,r,n){var o=this;return a.assert(1===t.size,"Error in scaledArrayAdd: first argument must rank 0, but got rank "+t.rank+"."),a.assert(1===r.size,"Error in scaledArrayAdd: third argument must be rank 0, but got NDArray of rank "+r.rank+"."),a.assertShapesMatch(e.shape,n.shape,"Error in scaledArrayAdd: "),this.executeOp("scaledArrayAdd",function(){return o.scaledArrayAddInternal(t,e,r,n)})},t.prototype.scalarTimesArray=function(t,e){return a.assert(1===t.size,"Error in arrayDividedByScalar: first argument must be rank 0, but got rank "+t.rank+"."),this.multiply(t,e)},t.prototype.elementWiseMulBroadcast=function(t,e){return a.assert(2===t.rank,"Error in elementWiseMulBroadcast: first argument must be rank 2, but got rank "+t.rank+"."),a.assert(2===e.rank,"Error in elementWiseMulBroadcast: second argument must be rank 2, but got rank "+e.rank+"."),this.multiply(t,e)},t.prototype.conv2d=function(t,e,r,o,i){var s=this;a.assert(3===t.rank,"Error in conv2d: x must be rank 3, but got rank "+t.rank+"."),a.assert(4===e.rank,"Error in conv2d: filter must be rank 4, but got rank "+e.rank+"."),null!=r&&a.assert(1===r.rank,"Error in conv2d: bias must be rank 1, but got rank "+r.rank+"."),a.assert(t.shape[2]===e.shape[2],"Error in conv2d: depth of input ("+t.shape[2]+") must match input depth for filter "+e.shape[2]+".");var c=e.shape[0],p=e.shape[1],l=e.shape[3],h=n(o),f=h[0],d=h[1],v=u.computeConv2DInfo(t.shape,c,p,l,f,d,i);return this.executeOp("conv2d",function(){return s.conv2dInternal(t,e,r,v)})},t.prototype.conv2dBackProp=function(t,e,r,n,a){var o=this.conv2dDerFilter(t,e,r.shape,n,a);return{db:this.conv2dDerBias(e),dw:o,dx:this.conv2dDerInput(t.shape,e,r,n,a)}},t.prototype.conv2dDerInput=function(t,e,r,o,i){var s=this,c=t[2],p=e.shape[2];a.assert(3===t.length,"Error in conv2dDerInput: x must be rank 3, but got rank "+t.length+"."),a.assert(3===e.rank,"Error in conv2dDerInput: dy must be rank 3, but got rank "+e.rank),a.assert(4===r.rank,"Error in conv2dDerInput: filter must be rank 4, but got rank "+r.rank),a.assert(c===r.shape[2],"Error in conv2dDerInput: depth of input ("+c+") must match input depth for filter "+r.shape[2]+"."),a.assert(p===r.shape[3],"Error in conv2dDerInput: depth of output ("+p+") mustmatch output depth for filter "+r.shape[3]+".");var l=r.shape[0],h=r.shape[1],f=n(o),d=f[0],v=f[1],m=u.computeConv2DInfo(t,l,h,p,d,v,i);return this.executeOp("conv2dDerInput",function(){return s.conv2dDerInputInternal(e,r,m)})},t.prototype.conv2dDerBias=function(t){return this.track(this.conv2dDerBiasInternal(t))},t.prototype.conv2dDerFilter=function(t,e,r,o,i){a.assert(3===t.rank,"Error in conv2dDerFilter: x must be rank 3, but got shape "+t.shape+"."),a.assert(3===e.rank,"Error in conv2dDerFilter: dy must be rank 3, but got shape "+e.shape+"."),a.assert(4===r.length,"Error in conv2dDerFilter: filterSize must be length 4, but got "+r+"."),a.assert(t.shape[2]===r[2],"Error in conv2dDerFilter: depth of x "+t.shape[2]+") must match input depth in filter ("+r[2]+"."),a.assert(e.shape[2]===r[3],"Error in conv2dDerFilter: depth of dy ("+e.shape[2]+") must match output depth for filter ("+r[3]+").");var s=r[0],c=r[1],p=r[3],l=n(o),h=l[0],f=l[1],d=u.computeConv2DInfo(t.shape,s,c,p,h,f,i);return this.track(this.conv2dDerFilterInternal(t,e,d))},t.prototype.conv2dTranspose=function(t,e,r,n,a){return this.conv2dDerInput(r,t,e,n,a)},t.prototype.depthwiseConv2D=function(t,e,r,o,i){var s=this;void 0===i&&(i=[1,1]);var c=t,p=!1;3===t.rank&&(p=!0,c=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),a.assert(4===c.rank,"Error in depthwiseConv2D: input must be rank 4, but got rank "+c.rank+"."),a.assert(4===e.rank,"Error in depthwiseConv2D: filter must be rank 4, but got rank "+e.rank+"."),a.assert(c.shape[3]===e.shape[2],"Error in depthwiseConv2D: number of input channels ("+c.shape[3]+") must match the inChannels dimension in filter "+e.shape[2]+".");var l=n(i=i||[1,1]),h=l[0],f=l[1];a.assert(1===h&&1===f,"Error in depthwiseConv2D: rates greater than 1 are not yet supported. Got rates '"+i+"'");var d=u.computeDepthwiseConv2DInfo(c.shape,e.shape,r,o);return this.executeOp("depthwiseConv2D",function(){var t=s.depthwiseConv2DInternal(c,e,d);return p?t.as3D(t.shape[1],t.shape[2],t.shape[3]):t})},t.prototype.maxPool=function(t,e,r,o){var i=this;a.assert(3===t.rank,"Error in maxPool: x must be rank 3 but got rank "+t.rank+".");var s=n(e),c=s[0],p=s[1],l=t.shape[2],h=n(r),f=h[0],d=h[1],v=u.computeConv2DInfo(t.shape,c,p,l,f,d,o);return this.executeOp("maxPool",function(){return i.maxPoolInternal(t,v)})},t.prototype.maxPoolBackprop=function(t,e,r,o,i){var s=this;a.assert(3===t.rank,"Error in maxPoolBackprop: dy must be rank 3 but got rank "+t.rank+"."),a.assert(3===e.rank,"Error in maxPoolBackprop: x must be rank 3 but got rank "+e.rank+".");var c=n(r),p=c[0],l=c[1],h=e.shape[2],f=n(o),d=f[0],v=f[1],m=u.computeConv2DInfo(e.shape,p,l,h,d,v,i);return this.executeOp("maxPoolBackprop",function(){return s.maxPoolBackpropInternal(t,e,m)})},t.prototype.minPool=function(t,e,r,o){var i=this;a.assert(3===t.rank,"Error in minPool: x must be rank 3 but got rank "+t.rank+".");var s=n(e),c=s[0],p=s[1],l=t.shape[2],h=n(r),f=h[0],d=h[1],v=u.computeConv2DInfo(t.shape,c,p,l,f,d,o);return this.executeOp("minPool",function(){return i.minPoolInternal(t,v)})},t.prototype.avgPool=function(t,e,r,o){var i=this;a.assert(3===t.rank,"Error in avgPool: x must be rank 3 but got rank "+t.rank+".");var s=n(e),c=s[0],p=s[1],l=t.shape[2],h=n(r),f=h[0],d=h[1],v=u.computeConv2DInfo(t.shape,c,p,l,f,d,o);return this.executeOp("avgPool",function(){return i.avgPoolInternal(t,v)})},t.prototype.resizeBilinear3D=function(t,e,r){var n=this;return void 0===r&&(r=!1),a.assert(3===t.rank,"Error in resizeBilinear3D: x must be rank 3 but got rank "+t.rank+"."),a.assert(2===e.length,"Error in resizeBilinear3D: new shape must 2D, but got shape "+e+"."),this.executeOp("resizeBilinear3D",function(){return n.resizeBilinear3DInternal(t,e,r)})},t.prototype.batchNormalization2D=function(t,e,r,n,o,i){var s=this;return void 0===n&&(n=.001),a.assert(2===t.rank,"Error in batchNormalization3D: x must be rank 3 but got rank "+t.rank+"."),a.assert(2===e.rank||1===e.rank,"Error in batchNormalization2D: mean must be rank 2 or rank 1 but got rank "+e.rank+"."),a.assert(2===r.rank||1===r.rank,"Error in batchNormalization2D: variance must be rank 2 or rank 1 but got rank "+r.rank+"."),null!=o&&a.assert(2===o.rank||1===o.rank,"Error in batchNormalization2D: scale must be rank 2 or rank 1 but got rank "+o.rank+"."),null!=i&&a.assert(2===i.rank||1===i.rank,"Error in batchNormalization2D: offset must be rank 2 or rank 1 but got rank "+i.rank+"."),this.executeOp("batchNorm2D",function(){return s.batchNormalization2DInternal(t,e,r,n,o,i)})},t.prototype.batchNormalization3D=function(t,e,r,n,o,i){var s=this;return void 0===n&&(n=.001),a.assert(3===t.rank,"Error in batchNormalization3D: x must be rank 3 but got rank "+t.rank+"."),a.assert(3===e.rank||1===e.rank,"Error in batchNormalization3D: mean must be rank 3 or rank 1 but got rank "+e.rank+"."),a.assert(3===r.rank||1===r.rank,"Error in batchNormalization3D: variance must be rank 3 or rank 1 but got rank "+r.rank+"."),null!=o&&a.assert(3===o.rank||1===o.rank,"Error in batchNormalization3D: scale must be rank 3 or rank 1 but got rank "+o.rank+"."),null!=i&&a.assert(3===i.rank||1===i.rank,"Error in batchNormalization3D: offset must be rank 3 or rank 1 but got rank "+i.rank+"."),this.executeOp("batchNorm3D",function(){return s.batchNormalization3DInternal(t,e,r,n,o,i)})},t.prototype.multiRNNCell=function(t,e,r,n){for(var a=this.scope(function(){for(var a=e,o=[],i=0;i<t.length;i++){var s=t[i](a,r[i],n[i]);o.push(s[0]),o.push(s[1]),a=s[1]}return o}),o=[],i=[],s=0;s<a.length;s+=2)o.push(a[s]),i.push(a[s+1]);return[o,i]},t.prototype.basicLSTMCell=function(t,e,r,n,a,o){var i=this,s=this.scope(function(){var s=i.concat2D(n,o,1),u=i.matMul(s,e),c=i.add(u,r),p=c.shape[0],l=c.shape[1]/4,h=[p,l],f=i.slice2D(c,[0,0],h),d=i.slice2D(c,[0,l],h),v=i.slice2D(c,[0,2*l],h),m=i.slice2D(c,[0,3*l],h),y=i.addStrict(i.multiplyStrict(a,i.sigmoid(i.scalarPlusArray(t,v))),i.multiplyStrict(i.sigmoid(f),i.tanh(d)));return[y,i.multiplyStrict(i.tanh(y),i.sigmoid(m))]});return[s[0],s[1]]},t.prototype.multinomial=function(t,e,r){var n=this,a=t.size;if(a<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+a+".");if(t.rank>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+t.rank);r=r||Math.random();var o=t.rank;return 1===t.rank&&(t=t.as2D(1,-1)),this.executeOp("multinomial",function(){var a=n.multinomialInternal(t,e,r);return 1===o?a.as1D():a})},t.prototype.oneHot=function(t,e,r,n){var a=this;if(void 0===r&&(r=1),void 0===n&&(n=0),e<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+e);return this.executeOp("oneHot",function(){return a.oneHotInternal(t,e,r,n)})},t.prototype.moments=function(t,e,r){var n=this;void 0===e&&(e=null),void 0===r&&(r=!1);var a=o.parseAxisParam(e,t.shape);return this.scope(function(){var e=n.mean(t,a,r),i=e.shape;r||(i=o.expandShapeToKeepDim(e.shape,a));var s=n.square(n.subtract(t,e.reshape(i)));return{mean:e,variance:n.mean(s,a,r)}})},t}();r.NDArrayMath=h;var f;!function(t){t[t.REGULAR=0]="REGULAR",t[t.TRANSPOSED=1]="TRANSPOSED"}(f=r.MatrixOrientation||(r.MatrixOrientation={}))},{"../util":96,"./axis_util":54,"./broadcast_util":55,"./concat_util":56,"./conv_util":57,"./copy2d_util":58,"./ndarray":63,"./slice_util":65}],61:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("seedrandom"),o=t("../util"),i=t("./axis_util"),s=t("./broadcast_util"),u=t("./concat_util"),c=t("./conv_util"),p=t("./copy2d_util"),l=t("./math"),h=t("./ndarray"),f=function(t){function e(e){return void 0===e&&(e=!1),t.call(this,e)||this}return n(e,t),e.prototype.cloneInternal=function(t){return h.NDArray.make(t.shape,{values:new Float32Array(t.getValues())})},e.prototype.slice1DInternal=function(t,e,r){var n=t.getValues().slice(e,e+r);return h.Array1D.new(n)},e.prototype.slice2DInternal=function(t,e,r){for(var n=h.Array2D.zeros(r),a=e[0],o=e[1],i=0;i<r[0];++i)for(var s=0;s<r[1];++s){var u=t.get(i+a,s+o);n.set(u,i,s)}return n},e.prototype.slice3DInternal=function(t,e,r){for(var n=h.Array3D.zeros(r),a=e[0],o=e[1],i=e[2],s=0;s<r[0];++s)for(var u=0;u<r[1];++u)for(var c=0;c<r[2];++c){var p=t.get(s+a,u+o,c+i);n.set(p,s,u,c)}return n},e.prototype.slice4DInternal=function(t,e,r){for(var n=h.Array4D.zeros(r),a=e[0],o=e[1],i=e[2],s=e[3],u=0;u<r[0];++u)for(var c=0;c<r[1];++c)for(var p=0;p<r[2];++p)for(var l=0;l<r[3];++l){var f=t.get(u+a,c+o,p+i,l+s);n.set(f,u,c,p,l)}return n},e.prototype.copy2DInternal=function(t,e,r,n,a,o){p.validateShapes(r,o);for(var i=t.getValues(),s=n.getValues(),u=r[0]*r[1],c=0;c<u;++c){var l=e[0]+Math.floor(c/r[1]),h=e[1]+c%r[1],f=l*t.shape[1]+h,d=a[0]+Math.floor(c/o[1]),v=a[1]+c%o[1];s[d*n.shape[1]+v]=i[f]}},e.prototype.concat1DInternal=function(t,e){var r=u.computeOutShape(t.shape,e.shape,0),n=h.Array1D.zeros(r),a=t.getValues(),o=e.getValues(),i=n.getValues();return i.set(a,0),i.set(o,t.size),n},e.prototype.concat2DInternal=function(t,e,r){var n=u.computeOutShape(t.shape,e.shape,r),a=h.Array2D.zeros(n);if(0===r){var o=t.getValues(),i=e.getValues(),s=a.getValues();return s.set(o,0),s.set(i,t.size),a}for(var c=0;c<n[0];++c)for(var p=0;p<n[1];++p){var l=[c,p],f=void 0;if(l[r]<t.shape[r])f=t.get(c,p);else{l[r]-=t.shape[r];var d=l[0],v=l[1];f=e.get(d,v)}a.set(f,c,p)}return a},e.prototype.concat3DInternal=function(t,e,r){var n=u.computeOutShape(t.shape,e.shape,r),a=h.Array3D.zeros(n);if(0===r){var o=t.getValues(),i=e.getValues(),s=a.getValues();return s.set(o,0),s.set(i,t.size),a}for(var c=0;c<n[0];++c)for(var p=0;p<n[1];++p)for(var l=0;l<n[2];++l){var f=[c,p,l],d=void 0;if(f[r]<t.shape[r])d=t.get(c,p,l);else{f[r]-=t.shape[r];var v=f[0],m=f[1],y=f[2];d=e.get(v,m,y)}a.set(d,c,p,l)}return a},e.prototype.concat4DInternal=function(t,e,r){var n=u.computeOutShape(t.shape,e.shape,r),a=h.Array4D.zeros(n);if(0===r){var o=t.getValues(),i=e.getValues(),s=a.getValues();return s.set(o,0),s.set(i,t.size),a}for(var c=0;c<n[0];++c)for(var p=0;p<n[1];++p)for(var l=0;l<n[2];++l)for(var f=0;f<n[3];++f){var d=[c,p,l,f],v=void 0;if(d[r]<t.shape[r])v=t.get(c,p,l,f);else{d[r]-=t.shape[r];var m=d[0],y=d[1],g=d[2],x=d[3];v=e.get(m,y,g,x)}a.set(v,c,p,l,f)}return a},e.prototype.scaledArrayAddInternal=function(t,e,r,n){var a=t.get(),o=r.get();return this.broadcastedBinaryOp(e,n,"float32",function(t,e){return a*t+o*e})},e.prototype.negInternal=function(t){return this.scalarTimesArray(h.Scalar.NEG_ONE,t)},e.prototype.addInternal=function(t,e){return this.scaledArrayAddInternal(h.Scalar.ONE,t,h.Scalar.ONE,e)},e.prototype.subtractInternal=function(t,e){return this.scaledArrayAddInternal(h.Scalar.ONE,t,h.Scalar.NEG_ONE,e)},e.prototype.matMulInternal=function(t,e,r,n){void 0===r&&(r=l.MatrixOrientation.REGULAR),void 0===n&&(n=l.MatrixOrientation.REGULAR);for(var a=r===l.MatrixOrientation.REGULAR?t.shape[1]:t.shape[0],o=r===l.MatrixOrientation.REGULAR?t.shape[0]:t.shape[1],i=n===l.MatrixOrientation.REGULAR?e.shape[1]:e.shape[0],s=function(t,e,r){return t.get(e,r)},u=function(t,e,r){return t.get(r,e)},c=r===l.MatrixOrientation.REGULAR?s:u,p=n===l.MatrixOrientation.REGULAR?s:u,f=new Float32Array(o*i),d=0,v=0;v<o;++v)for(var m=0;m<i;++m){for(var y=0,g=0;g<a;++g)y+=c(t,v,g)*p(e,g,m);f[d++]=y}return h.Array2D.new([o,i],f)},e.prototype.multiplyInternal=function(t,e){for(var r=s.assertAndGetBroadcastShape(t.shape,e.shape),n=new Float32Array(o.sizeFromShape(r)),a=t.getValues(),i=e.getValues(),u=0;u<n.length;++u)n[u]=a[u%t.size]*i[u%e.size];return h.NDArray.make(r,{values:n})},e.prototype.divideInternal=function(t,e){for(var r=s.assertAndGetBroadcastShape(t.shape,e.shape),n=new Float32Array(o.sizeFromShape(r)),a=t.getValues(),i=e.getValues(),u=0;u<n.length;++u)n[u]=a[u%t.size]/i[u%e.size];return h.NDArray.make(r,{values:n},"float32")},e.prototype.sumInternal=function(t,e){i.assertAxesAreInnerMostDims("sum",e,t.rank);for(var r=i.computeOutAndReduceShapes(t.shape,e),n=r[0],a=r[1],s=l.SumTypesMap[t.dtype],u=h.NDArray.zeros(n,s),c=o.sizeFromShape(a),p=u.getValues(),f=t.getValues(),d=0;d<p.length;++d){for(var v=d*c,m=0,y=0;y<c;++y)m+=f[v+y];p[d]=m}return u},e.prototype.argMinInternal=function(t,e){i.assertAxesAreInnerMostDims("argMin",e,t.rank);for(var r=i.computeOutAndReduceShapes(t.shape,e),n=r[0],a=r[1],s=h.NDArray.zeros(n,"int32"),u=o.sizeFromShape(a),c=s.getValues(),p=t.getValues(),l=0;l<c.length;++l){for(var f=l*u,d=p[f],v=0,m=0;m<u;++m){var y=p[f+m];if(isNaN(y)){v=o.NAN_INT32;break}y<d&&(d=y,v=m)}c[l]=v}return s},e.prototype.argMaxInternal=function(t,e){i.assertAxesAreInnerMostDims("argMax",e,t.rank);for(var r=i.computeOutAndReduceShapes(t.shape,e),n=r[0],a=r[1],s=h.NDArray.zeros(n,"int32"),u=o.sizeFromShape(a),c=s.getValues(),p=t.getValues(),l=0;l<c.length;++l){for(var f=l*u,d=p[f],v=0,m=0;m<u;++m){var y=p[f+m];if(isNaN(y)){v=o.NAN_INT32;break}y>d&&(d=y,v=m)}c[l]=v}return s},e.prototype.equalInternal=function(t,e){return this.broadcastedBinaryOp(t,e,"bool",function(r,n){return o.isValNaN(r,t.dtype)||o.isValNaN(n,e.dtype)?o.getNaN("bool"):r===n?1:0})},e.prototype.topKInternal=function(t,e){for(var r=t.getValues(),n=[],a=0;a<r.length;a++)n.push({value:r[a],index:a});n.sort(function(t,e){return e.value-t.value});for(var o=new Float32Array(e),i=new Float32Array(e),a=0;a<e;a++)o[a]=n[a].value,i[a]=n[a].index;return{values:h.Array1D.new(o),indices:h.Array1D.new(i)}},e.prototype.minInternal=function(t,e){i.assertAxesAreInnerMostDims("min",e,t.rank);for(var r=i.computeOutAndReduceShapes(t.shape,e),n=r[0],a=r[1],s=h.NDArray.zeros(n,t.dtype),u=o.sizeFromShape(a),c=s.getValues(),p=t.getValues(),l=0;l<c.length;++l){for(var f=l*u,d=p[0],v=0;v<u;++v){var m=p[f+v];if(isNaN(m)){d=Number.NaN;break}m<d&&(d=m)}c[l]=d}return s},e.prototype.maxInternal=function(t,e){i.assertAxesAreInnerMostDims("max",e,t.rank);for(var r=i.computeOutAndReduceShapes(t.shape,e),n=r[0],a=r[1],s=h.NDArray.zeros(n,t.dtype),u=o.sizeFromShape(a),c=s.getValues(),p=t.getValues(),l=0;l<c.length;++l){for(var f=l*u,d=p[f],v=0;v<u;++v){var m=p[f+v];if(isNaN(m)){d=Number.NaN;break}m>d&&(d=m)}c[l]=d}return s},e.prototype.ceilInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n)r[n]=Math.ceil(e[n]);return h.NDArray.make(t.shape,{values:r})},e.prototype.floorInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n)r[n]=Math.floor(e[n]);return h.NDArray.make(t.shape,{values:r})},e.prototype.expInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n)r[n]=Math.exp(e[n]);return h.NDArray.make(t.shape,{values:r})},e.prototype.logInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n){var a=e[n];r[n]=Math.log(a)}return h.NDArray.make(t.shape,{values:r})},e.prototype.sqrtInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n){var a=e[n];r[n]=Math.sqrt(a)}return h.NDArray.make(t.shape,{values:r})},e.prototype.squareInternal=function(t){for(var e=t.getValues(),r=new Float32Array(e.length),n=0;n<e.length;++n){var a=e[n];r[n]=a*a}return h.NDArray.make(t.shape,{values:r})},e.prototype.reluInternal=function(t){for(var e=h.NDArray.zeros(t.shape,t.dtype),r=e.getValues(),n=t.getValues(),a=0;a<n.length;++a){var i=n[a];o.isValNaN(i,t.dtype)?r[a]=o.getNaN(e.dtype):r[a]=Math.max(0,n[a])}return e},e.prototype.eluInternal=function(t){for(var e=new Float32Array(t.size),r=t.dataSync(),n=0;n<r.length;++n){var a=r[n];e[n]=a>=0?a:Math.exp(a)-1}return h.NDArray.make(t.shape,{values:e})},e.prototype.leakyReluInternal=function(t,e){for(var r=new Float32Array(t.size),n=t.dataSync(),a=0;a<n.length;a++){var o=n[a];r[a]=o>=0?o:e*o}return h.NDArray.make(t.shape,{values:r})},e.prototype.clipInternal=function(t,e,r){for(var n=new Float32Array(t.size),a=t.getValues(),o=0;o<a.length;++o)n[o]=Math.min(r,Math.max(e,a[o]));return h.NDArray.make(t.shape,{values:n})},e.prototype.absInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.abs(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.sigmoidInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=1/(1+Math.exp(-r[n]));return h.NDArray.make(t.shape,{values:e})},e.prototype.sinInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.sin(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.cosInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.cos(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.tanInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.tan(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.asinInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.asin(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.acosInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.acos(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.atanInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.atan(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.sinhInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.sinh(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.coshInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=Math.cosh(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.tanhInternal=function(t){for(var e=new Float32Array(t.size),r=t.getValues(),n=0;n<r.length;++n)e[n]=o.tanh(r[n]);return h.NDArray.make(t.shape,{values:e})},e.prototype.stepInternal=function(t,e){void 0===e&&(e=0);for(var r=new Float32Array(t.size),n=t.getValues(),a=0;a<n.length;++a){var o=n[a];r[a]=o>0?1:o<0?e:o}return h.NDArray.make(t.shape,{values:r})},e.prototype.conv2dInternal=function(t,e,r,n){for(var a=t.shape,o=a[0],i=a[1],s=a[2],u=e.shape[0],c=e.shape[1],p=e.shape[3],l=n.padInfo.left,f=n.padInfo.top,d=h.Array3D.zeros(n.outShape),v=0;v<p;++v)for(var m=0;m<d.shape[0];++m)for(var y=m*n.strideHeight-l,g=Math.max(0,y),x=Math.min(o,u+y),w=0;w<d.shape[1];++w){for(var b=w*n.strideWidth-f,_=Math.max(0,b),A=Math.min(i,c+b),T=0,E=g;E<x;++E)for(var S=E-y,C=_;C<A;++C)for(var N=C-b,O=0;O<s;++O)T+=t.get(E,C,O)*e.get(S,N,O,v);var R=null!=r?r.get(v):0;d.set(T+R,m,w,v)}return d},e.prototype.conv2dDerInputInternal=function(t,e,r){for(var n=e.shape[2],a=e.shape[3],o=t.shape[0],i=t.shape[1],s=e.shape[0],u=e.shape[1],c=s-1-r.padInfo.top,p=u-1-r.padInfo.left,l=r.strideHeight,f=r.strideWidth,d=h.Array3D.zeros(r.inShape),v=0;v<n;++v)for(var m=0;m<d.shape[0];++m)for(var y=m-p,g=Math.max(0,Math.ceil(y/l)),x=Math.min(o,(s+y)/l),w=0;w<d.shape[1];++w){for(var b=w-c,_=Math.max(0,Math.ceil(b/f)),A=Math.min(i,(u+b)/f),T=0,E=g;E<x;++E)for(var S=E*l-y,C=_;C<A;++C)for(var N=C*f-b,O=0;O<a;++O)T+=t.get(E,C,O)*e.get(s-1-S,u-1-N,v,O);d.set(T,m,w,v)}return d},e.prototype.conv2dDerFilterInternal=function(t,e,r){for(var n=t.shape[2],a=e.shape[2],o=r.strideHeight,i=r.strideWidth,s=r.filterHeight,u=r.filterWidth,p=c.computeWeightsShape4D(n,a,s,u),l=h.Array4D.zeros(p),f=e.shape[0],d=e.shape[1],v=t.shape[0],m=t.shape[1],y=r.padInfo.left,g=r.padInfo.top,x=0;x<s;++x)for(var w=Math.max(0,Math.ceil((g-x)/o)),b=Math.min(f,(v+g-x)/o),_=0;_<u;++_)for(var A=Math.max(0,Math.ceil((y-_)/i)),T=Math.min(d,(m+y-_)/i),E=0;E<n;++E)for(var S=0;S<a;++S){for(var C=0,N=w;N<b;++N)for(var O=x+N*o-g,R=A;R<T;++R){var M=_+R*i-y;C+=t.get(O,M,E)*e.get(N,R,S)}l.set(C,x,_,E,S)}return l},e.prototype.conv2dDerBiasInternal=function(t){for(var e=t.shape[2],r=t.shape[0],n=t.shape[1],a=new Float32Array(e),o=0;o<e;++o){for(var i=0,s=0;s<r;++s)for(var u=0;u<n;++u)i+=t.get(s,u,o);a[o]=i}return h.Array1D.new(a)},e.prototype.depthwiseConv2DInternal=function(t,e,r){for(var n=r.inShape,a=n[0],o=n[1],i=n[2],s=n[3],u=r.filterHeight,c=r.filterWidth,p=r.padInfo.left,l=r.padInfo.top,f=r.outShape[1],d=r.outShape[2],v=r.channelMul,m=h.Array4D.zeros(r.outShape),y=0;y<a;++y)for(var g=0;g<s;++g)for(var x=0;x<f;++x)for(var w=x*r.strideHeight-p,b=Math.max(0,w),_=Math.min(o,u+w),A=0;A<d;++A)for(var T=A*r.strideWidth-l,E=Math.max(0,T),S=Math.min(i,c+T),C=0;C<v;++C){for(var N=0,O=b;O<_;++O)for(var R=O-w,M=E;M<S;++M){var D=M-T;N+=t.get(y,O,M,g)*e.get(R,D,g,C)}m.set(N,y,x,A,g*v+C)}return m},e.prototype.tileInternal=function(t,e){for(var r=new Array(t.rank),n=0;n<r.length;n++)r[n]=t.shape[n]*e[n];var a;if("float32"===t.dtype)a=Float32Array;else if("int32"===t.dtype)a=Int32Array;else{if("bool"!==t.dtype)throw new Error("Dtype "+t.dtype+" not supported for tile");a=Uint8Array}for(var i=new a(o.sizeFromShape(r)),s=h.NDArray.make(r,{values:i},t.dtype),u=t.getValues(),n=0;n<s.size;++n){for(var c=s.indexToLoc(n),p=new Array(t.rank),l=0;l<p.length;l++)p[l]=c[l]%t.shape[l];var f=t.locToIndex(p);i[n]=u[f]}return s},e.prototype.transposeInternal=function(t,e){for(var r=new Array(t.rank),n=0;n<r.length;n++)r[n]=t.shape[e[n]];for(var a=new Float32Array(t.size),o=t.getValues(),i=h.NDArray.make(r,{values:a}),n=0;n<t.size;++n){for(var s=t.indexToLoc(n),u=new Array(s.length),c=0;c<u.length;c++)u[c]=s[e[c]];a[i.locToIndex(u)]=o[n]}return i},e.prototype.pool=function(t,e,r){for(var n=t.shape,a=n[0],o=n[1],i=n[2],s=e.strideHeight,u=e.strideWidth,c=e.filterHeight,p=e.filterWidth,l=h.Array3D.zeros(e.outShape),f=e.padInfo.top,d=e.padInfo.left,v=0;v<i;++v)for(var m=0;m<l.shape[0];++m)for(var y=m*s-f,g=Math.max(0,y),x=Math.min(a,c+y),w=0;w<l.shape[1];++w){for(var b=w*u-d,_=Math.max(0,b),A=Math.min(o,p+b),T="max"===r?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,E=0,S=g;S<x;++S){for(var C=_;C<A;++C){var N=t.get(S,C,v);if(isNaN(N)){T=NaN,E=NaN;break}"max"===r&&N>T||"min"===r&&N<T?T=N:"avg"===r&&(E+=N/(c*p))}if(isNaN(T))break}l.set("avg"===r?E:T,m,w,v)}return l},e.prototype.maxPoolInternal=function(t,e){return this.pool(t,e,"max")},e.prototype.maxPoolPositions=function(t,e){for(var r=t.shape,n=r[0],a=r[1],o=r[2],i=e.outShape,s=h.Array3D.zeros(i),u=e.strideHeight,c=e.strideWidth,p=e.filterHeight,l=e.filterWidth,f=e.padInfo.top,d=e.padInfo.left,v=0;v<o;++v)for(var m=0;m<i[0];++m)for(var y=m*u-f,g=Math.max(0,y),x=Math.min(n,p+y),w=0;w<i[1];++w){for(var b=w*c-d,_=Math.max(0,b),A=Math.min(a,l+b),T=Number.NEGATIVE_INFINITY,E=-1,S=g;S<x;++S)for(var C=S-y,N=_;N<A;++N){var O=N-b,R=t.get(S,N,v);R>T&&(T=R,E=C*l+O)}s.set(E,m,w,v)}return s},e.prototype.maxPoolBackpropInternal=function(t,e,r){for(var n=this.maxPoolPositions(e,r),a=r.strideHeight,o=r.strideWidth,i=r.filterHeight,s=r.filterWidth,u=s-1-r.padInfo.left,c=i-1-r.padInfo.top,p=t.shape,l=p[0],f=p[1],d=p[2],v=h.Array3D.zeros(e.shape),m=0;m<d;++m)for(var y=0;y<v.shape[0];++y)for(var g=0;g<v.shape[1];++g){for(var x=y-c,w=g-u,b=0,_=0;_<i;++_){var A=(x+_)/a;if(!(A<0||A>=l||Math.floor(A)!==A))for(var T=0;T<s;++T){var E=(w+T)/o;if(!(E<0||E>=f||Math.floor(E)!==E)){var S=i*s-1-n.get(A,E,m)===_*s+T?1:0;0!==S&&(b+=t.get(A,E,m)*S)}}}v.set(b,y,g,m)}return v},e.prototype.minPoolInternal=function(t,e){return this.pool(t,e,"min")},e.prototype.avgPoolInternal=function(t,e){return this.pool(t,e,"avg")},e.prototype.resizeBilinear3DInternal=function(t,e,r){for(var n=h.Array3D.zeros([e[0],e[1],t.shape[2]]),a=r?[t.shape[0]-1,t.shape[1]-1,t.shape[2]]:t.shape,o=r?[n.shape[0]-1,n.shape[1]-1,n.shape[2]]:n.shape,i=0;i<n.shape[0];i++)for(var s=0;s<n.shape[1];s++)for(var u=0;u<n.shape[2];u++){var c=a[0]*i/o[0],p=a[1]*s/o[1],l=Math.floor(c),f=Math.min(t.shape[0]-1,Math.ceil(c)),d=Math.floor(p),v=Math.min(t.shape[1]-1,Math.ceil(p)),m=t.get(l,d,u),y=t.get(f,d,u),g=p-d,x=m+(t.get(l,v,u)-m)*g,w=x+(y+(t.get(f,v,u)-y)*g-x)*(c-l);n.set(w,i,s,u)}return n},e.prototype.batchNormalization2DInternal=function(t,e,r,n,a,o){for(var i=t.getValues(),s=e.getValues(),u=r.getValues(),c=a?a.getValues():new Float32Array([1]),p=o?o.getValues():new Float32Array([0]),l=new Float32Array(i.length),f=0;f<i.length;f++)l[f]=p[f%p.length]+(i[f]-s[f%s.length])*c[f%c.length]/Math.sqrt(u[f%u.length]+n);return h.Array2D.new(t.shape,l)},e.prototype.batchNormalization3DInternal=function(t,e,r,n,a,o){for(var i=t.getValues(),s=e.getValues(),u=r.getValues(),c=a?a.getValues():new Float32Array([1]),p=o?o.getValues():new Float32Array([0]),l=new Float32Array(i.length),f=0;f<i.length;f++)l[f]=p[f%p.length]+(i[f]-s[f%s.length])*c[f%c.length]/Math.sqrt(u[f%u.length]+n);return h.Array3D.new(t.shape,l)},e.prototype.multinomialInternal=function(t,e,r){for(var n=t.shape[0],o=t.shape[1],i=h.Array2D.zeros([n,e],"int32"),s=i.getValues(),u=t.getValues(),c=0;c<n;++c){var p=c*o,l=new Float32Array(o-1);l[0]=u[p];for(var f=1;f<l.length;++f)l[f]=l[f-1]+u[p+f];for(var d=a.alea(r.toString()),v=c*e,m=0;m<e;++m){var y=d();s[v+m]=l.length;for(var g=0;g<l.length;g++)if(y<l[g]){s[v+m]=g;break}}}return i},e.prototype.oneHotInternal=function(t,e,r,n){var a=new Float32Array(t.size*e);a.fill(n);for(var o=0;o<t.size;++o)a[o*e+t.get(o)]=r;return h.Array2D.new([t.size,e],a)},e.prototype.broadcastedBinaryOp=function(t,e,r,n){for(var a=s.assertAndGetBroadcastShape(t.shape,e.shape),o=h.NDArray.zeros(a,r),i=o.getValues(),u=t.getValues(),c=e.getValues(),p=s.getBroadcastDims(t.shape,a),l=s.getBroadcastDims(e.shape,a),f=0;f<i.length;++f)!function(r){var a=o.indexToLoc(r),s=a.slice(-t.rank);p.forEach(function(t){return s[t]=0});var h=t.locToIndex(s),f=a.slice(-e.rank);l.forEach(function(t){return f[t]=0});var d=e.locToIndex(f);i[r]=n(u[h],c[d])}(f);return o},e}(l.NDArrayMath);r.NDArrayMathCPU=f},{"../util":96,"./axis_util":54,"./broadcast_util":55,"./concat_util":56,"./conv_util":57,"./copy2d_util":58,"./math":60,"./ndarray":63,seedrandom:2}],62:[function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var a=t("../util"),o=t("./axis_util"),i=t("./math"),s=t("./ndarray"),u=t("./ndarray"),c=t("./reduce_util"),p=t("./webgl/addscaledmat_gpu"),l=t("./webgl/argminmax_gpu"),h=t("./webgl/batchnorm_gpu"),f=t("./webgl/binaryop_gpu"),d=t("./webgl/binaryop_gpu"),v=t("./webgl/clip_gpu"),m=t("./webgl/concat_gpu"),y=t("./webgl/conv_backprop_gpu"),g=t("./webgl/conv_gpu"),x=t("./webgl/conv_gpu_depthwise"),w=t("./webgl/copy_gpu"),b=t("./webgl/gpgpu_context"),_=t("./webgl/gpgpu_math"),A=t("./webgl/gpgpu_util"),T=t("./webgl/max_pool_backprop_gpu"),E=t("./webgl/mulmat_gpu"),S=t("./webgl/multinomial_gpu"),C=t("./webgl/onehot_gpu"),N=t("./webgl/pool_gpu"),O=t("./webgl/reduce_gpu"),R=t("./webgl/resize_bilinear_gpu"),M=t("./webgl/slice_gpu"),D=t("./webgl/texture_manager"),I=t("./webgl/tile_gpu"),P=t("./webgl/transpose_gpu"),k=t("./webgl/unaryop_gpu"),z=t("./webgl/unaryop_gpu"),F=t("./webgl/webgl_util"),U=function(t){function e(e,r){void 0===r&&(r=!1);var n=t.call(this,r)||this;if(n.binaryCache={},null==e){var a=A.createWebGLContext();n.gpgpu=new b.GPGPUContext(a),n.gpgpuCreatedLocally=!0}else n.gpgpu=e,n.gpgpuCreatedLocally=!1;return n.textureManager=new D.TextureManager(n.gpgpu),s.initializeGPU(n.gpgpu,n.textureManager),n}return n(e,t),e.prototype.getGPGPUContext=function(){return this.gpgpu},e.prototype.cloneInternal=function(t){var e=t.getTextureShapeRC(),r=t.as2D(e[0],e[1]),n=this.makeOutputArray(e,t.dtype);return this.copy2D(r,[0,0],e,n,[0,0],e),n.reshape(t.shape)},e.prototype.slice1DInternal=function(t,e,r){var n=new M.SliceProgram([r]),a=n.getCustomSetupFunc([e]);return this.compileAndRun(n,[t],null,a)},e.prototype.slice2DInternal=function(t,e,r){var n=new M.SliceProgram(r),a=n.getCustomSetupFunc(e);return this.compileAndRun(n,[t],null,a)},e.prototype.slice3DInternal=function(t,e,r){var n=new M.SliceProgram(r),a=n.getCustomSetupFunc(e);return this.compileAndRun(n,[t],null,a)},e.prototype.slice4DInternal=function(t,e,r){var n=new M.SliceProgram(r),a=n.getCustomSetupFunc(e);return this.compileAndRun(n,[t],null,a)},e.prototype.copy2DInternal=function(t,e,r,n,a,o){var i=new w.Copy2DProgram(r[1],o[1]),s=i.getCustomSetupFunc(e,a,o);this.compileAndRun(i,[t],n,s)},e.prototype.concat1DInternal=function(t,e){var r=new m.ConcatProgram(t.shape,e.shape,0);return this.compileAndRun(r,[t,e])},e.prototype.concat2DInternal=function(t,e,r){var n=new m.ConcatProgram(t.shape,e.shape,r);return this.compileAndRun(n,[t,e])},e.prototype.concat3DInternal=function(t,e,r){var n=new m.ConcatProgram(t.shape,e.shape,r);return this.compileAndRun(n,[t,e])},e.prototype.concat4DInternal=function(t,e,r){var n=new m.ConcatProgram(t.shape,e.shape,r);return this.compileAndRun(n,[t,e])},e.prototype.scaledArrayAddInternal=function(t,e,r,n){var a=new p.AddScaledMatProgram(e.shape,n.shape);return this.compileAndRun(a,[e,n,t,r])},e.prototype.negInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.NEG);return this.compileAndRun(e,[t])},e.prototype.makeOutputArray=function(t,e){var r=F.getTextureShapeFromLogicalShape(this.gpgpu.gl,t),n=this.textureManager.acquireTexture(r);return u.NDArray.make(t,{texture:n,textureShapeRC:r},e)},e.prototype.compileAndRun=function(t,e,r,n){var a=this;null==r&&(r=this.makeOutputArray(t.outputShape,e[0].dtype));var o=_.makeShaderKey(t,e,r),i=this.getAndSaveBinary(o,function(){return _.compileProgram(a.gpgpu,t,e,r)});return _.runProgram(i,e,r,n),r},e.prototype.matMulInternal=function(t,e,r,n){var a=new E.MatMulProgram(t.shape,e.shape,r,n);return this.compileAndRun(a,[t,e])},e.prototype.multiplyInternal=function(t,e){var r=new d.BinaryOpProgram(f.MUL,t.shape,e.shape);return this.compileAndRun(r,[t,e])},e.prototype.batchNormalization2DInternal=function(t,e,r,n,a,o){var i=[t,e,r],s=null;null!=o&&(s=o.shape,i.push(o));var u=null;null!=a&&(u=a.shape,i.push(a));var c=new h.BatchNormProgram(t.shape,e.shape,r.shape,s,u,n);return this.compileAndRun(c,i)},e.prototype.batchNormalization3DInternal=function(t,e,r,n,a,o){var i=[t,e,r],s=null;null!=o&&(s=o.shape,i.push(o));var u=null;null!=a&&(u=a.shape,i.push(a));var c=new h.BatchNormProgram(t.shape,e.shape,r.shape,s,u,n);return this.compileAndRun(c,i)},e.prototype.tileInternal=function(t,e){var r=new I.TileProgram(t.shape,e);return this.compileAndRun(r,[t])},e.prototype.transposeInternal=function(t,e){var r=new P.TransposeProgram(t.shape,e);return this.compileAndRun(r,[t])},e.prototype.reduce=function(t,e,r){var n=t.shape[0],a=t.shape[1],o={windowSize:c.computeOptimalWindowSize(a),inSize:a,batchSize:n},i=new O.ReduceProgram(o,e),s=i.outputShape,u=s[0],p=s[1],l=this.makeOutputArray(i.outputShape,r).as2D(u,p);return this.compileAndRun(i,[t],l),1===l.shape[1]?l:this.reduce(l,e,r)},e.prototype.argReduce=function(t,e,r){void 0===r&&(r=null);var n=t.shape[0],a=t.shape[1];null!=r&&(n=r.shape[0],a=r.shape[1]);var o={windowSize:c.computeOptimalWindowSize(a),inSize:a,batchSize:n},i=new l.ArgMinMaxProgram(o,e,null==r),s=i.outputShape,u=s[0],p=s[1],h=this.makeOutputArray(i.outputShape,"int32").as2D(u,p),f=[t];return null!=r&&f.push(r),this.compileAndRun(i,f,h),1===h.shape[1]?h:this.argReduce(t,e,h)},e.prototype.sumInternal=function(t,e){o.assertAxesAreInnerMostDims("sum",e,t.rank);var r=o.computeOutAndReduceShapes(t.shape,e),n=r[0],s=r[1],u=a.sizeFromShape(s),c=t.as2D(-1,u),p=i.SumTypesMap[t.dtype];return this.reduce(c,"sum",p).reshape(n)},e.prototype.argMinInternal=function(t,e){o.assertAxesAreInnerMostDims("argMin",e,t.rank);var r=o.computeOutAndReduceShapes(t.shape,e),n=r[0],i=r[1],s=a.sizeFromShape(i),u=t.as2D(-1,s);return this.argReduce(u,"min").reshape(n)},e.prototype.argMaxInternal=function(t,e){o.assertAxesAreInnerMostDims("argMax",e,t.rank);var r=o.computeOutAndReduceShapes(t.shape,e),n=r[0],i=r[1],s=a.sizeFromShape(i),u=t.as2D(-1,s);return this.argReduce(u,"max").reshape(n)},e.prototype.equalInternal=function(t,e){var r=new d.BinaryOpProgram(f.EQUAL,t.shape,e.shape),n=this.makeOutputArray(r.outputShape,"bool");return this.compileAndRun(r,[t,e],n)},e.prototype.topKInternal=function(t,e){throw new Error("topK GPU not yet implemented!")},e.prototype.minInternal=function(t,e){o.assertAxesAreInnerMostDims("min",e,t.rank);var r=o.computeOutAndReduceShapes(t.shape,e),n=r[0],i=r[1],s=a.sizeFromShape(i),u=t.as2D(-1,s);return this.reduce(u,"min",u.dtype).reshape(n)},e.prototype.maxInternal=function(t,e){o.assertAxesAreInnerMostDims("max",e,t.rank);var r=o.computeOutAndReduceShapes(t.shape,e),n=r[0],i=r[1],s=a.sizeFromShape(i),u=t.as2D(-1,s);return this.reduce(u,"max",u.dtype).reshape(n)},e.prototype.divideInternal=function(t,e){var r=new d.BinaryOpProgram(f.DIV,t.shape,e.shape),n=this.makeOutputArray(r.outputShape,"float32");return this.compileAndRun(r,[t,e],n)},e.prototype.addInternal=function(t,e){var r=new d.BinaryOpProgram(f.ADD,t.shape,e.shape);return this.compileAndRun(r,[t,e])},e.prototype.subtractInternal=function(t,e){var r=new d.BinaryOpProgram(f.SUB,t.shape,e.shape);return this.compileAndRun(r,[t,e])},e.prototype.ceilInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.CEIL);return this.compileAndRun(e,[t])},e.prototype.floorInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.FLOOR);return this.compileAndRun(e,[t])},e.prototype.expInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.EXP);return this.compileAndRun(e,[t])},e.prototype.logInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.LOG);return this.compileAndRun(e,[t])},e.prototype.sqrtInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.SQRT);return this.compileAndRun(e,[t])},e.prototype.squareInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.SQUARE);return this.compileAndRun(e,[t])},e.prototype.reluInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.RELU);return this.compileAndRun(e,[t])},e.prototype.eluInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.ELU);return this.compileAndRun(e,[t])},e.prototype.leakyReluInternal=function(t,e){var r=new z.UnaryOpProgram(t.shape,k.LEAKY_RELU(e));return this.compileAndRun(r,[t])},e.prototype.clipInternal=function(t,e,r){var n=new v.ClipProgram(t.shape,e,r);return this.compileAndRun(n,[t])},e.prototype.absInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.ABS);return this.compileAndRun(e,[t])},e.prototype.sigmoidInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.SIGMOID);return this.compileAndRun(e,[t])},e.prototype.sinInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.SIN);return this.compileAndRun(e,[t])},e.prototype.cosInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.COS);return this.compileAndRun(e,[t])},e.prototype.tanInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.TAN);return this.compileAndRun(e,[t])},e.prototype.asinInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.ASIN);return this.compileAndRun(e,[t])},e.prototype.acosInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.ACOS);return this.compileAndRun(e,[t])},e.prototype.atanInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.ATAN);return this.compileAndRun(e,[t])},e.prototype.sinhInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.SINH);return this.compileAndRun(e,[t])},e.prototype.coshInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.COSH);return this.compileAndRun(e,[t])},e.prototype.tanhInternal=function(t){var e=new z.UnaryOpProgram(t.shape,k.TANH);return this.compileAndRun(e,[t])},e.prototype.stepInternal=function(t,e){var r=new z.UnaryOpProgram(t.shape,k.STEP(e));return this.compileAndRun(r,[t])},e.prototype.conv2dInternal=function(t,e,r,n){var a=new g.Conv2DProgram(n,null!=r),o=null!=r?[t,e,r]:[t,e];return this.compileAndRun(a,o)},e.prototype.conv2dDerInputInternal=function(t,e,r){var n=new y.Conv2DDerInputProgram(r);return this.compileAndRun(n,[t,e])},e.prototype.conv2dDerFilterInternal=function(t,e,r){var n=new y.Conv2DDerWeightsProgram(r);return this.compileAndRun(n,[t,e])},e.prototype.conv2dDerBiasInternal=function(t){var e=new y.Conv2DDerBiasProgram(t.shape);return this.compileAndRun(e,[t])},e.prototype.depthwiseConv2DInternal=function(t,e,r){var n=new x.DepthwiseConv2DProgram(r);return this.compileAndRun(n,[t,e])},e.prototype.maxPoolInternal=function(t,e){var r=new N.Pool2DProgram(e,"max",!1);return this.compileAndRun(r,[t])},e.prototype.minPoolInternal=function(t,e){var r=new N.Pool2DProgram(e,"min",!1);return this.compileAndRun(r,[t])},e.prototype.avgPoolInternal=function(t,e){var r=new N.Pool2DProgram(e,"avg",!1);return this.compileAndRun(r,[t])},e.prototype.maxPoolBackpropInternal=function(t,e,r){var n=new N.Pool2DProgram(r,"max",!0),a=this.compileAndRun(n,[e]),o=new T.MaxPool2DBackpropProgram(r),i=this.compileAndRun(o,[t,a]);return a.dispose(),i},e.prototype.resizeBilinear3DInternal=function(t,e,r){var n=new R.ResizeBilinear3DProgram(t.shape,e,r);return this.compileAndRun(n,[t])},e.prototype.multinomialInternal=function(t,e,r){var n=t.shape[0],a=t.shape[1],o=new S.MultinomialProgram(n,a,e),i=this.makeOutputArray(o.outputShape,"int32"),s=o.getCustomSetupFunc(r);return this.compileAndRun(o,[t],i,s)},e.prototype.oneHotInternal=function(t,e,r,n){var a=new C.OneHotProgram(t.size,e,r,n);return this.compileAndRun(a,[t])},e.prototype.getAndSaveBinary=function(t,e){return t in this.binaryCache||(this.binaryCache[t]=e()),this.binaryCache[t]},e.prototype.getTextureManager=function(){return this.textureManager},e.prototype.dispose=function(){for(var t in this.binaryCache)this.gpgpu.deleteProgram(this.binaryCache[t].webGLProgram);this.textureManager.dispose(),this.gpgpuCreatedLocally&&this.gpgpu.dispose()},e}(i.NDArrayMath);r.NDArrayMathGPU=U},{"../util":96,"./axis_util":54,"./math":60,"./ndarray":63,"./reduce_util":64,"./webgl/addscaledmat_gpu":66,"./webgl/argminmax_gpu":67,"./webgl/batchnorm_gpu":68,"./webgl/binaryop_gpu":69,"./webgl/clip_gpu":70,"./webgl/concat_gpu":71,"./webgl/conv_backprop_gpu":72,"./webgl/conv_gpu":73,"./webgl/conv_gpu_depthwise":74,"./webgl/copy_gpu":75,"./webgl/gpgpu_context":76,"./webgl/gpgpu_math":77,"./webgl/gpgpu_util":78,"./webgl/max_pool_backprop_gpu":79,"./webgl/mulmat_gpu":80,"./webgl/multinomial_gpu":81,"./webgl/onehot_gpu":82,"./webgl/pool_gpu":83,"./webgl/reduce_gpu":84,"./webgl/resize_bilinear_gpu":86,"./webgl/slice_gpu":88,"./webgl/texture_manager":90,"./webgl/tile_gpu":91,"./webgl/transpose_gpu":92,"./webgl/unaryop_gpu":93,"./webgl/webgl_util":94}],63:[function(t,e,r){"use strict";function n(){if(null==r.GPGPU||null==r.TEXTURE_MANAGER)throw new Error("GPU not intialized.")}function a(t,e){if(null==e||"float32"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e){for(var r=new Uint8Array(t.length),n=0;n<r.length;++n){var a=t[n];v.isValNaN(a,"bool")?r[n]=v.getNaN("bool"):a&&(r[n]=1)}return r}throw new Error("Unknown data type "+e)}function o(t){return t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array}function i(t,e){return t instanceof Float32Array&&"float32"===e||t instanceof Int32Array&&"int32"===e||t instanceof Uint8Array&&"bool"===e}function s(t,e){return i(t,e)?t:(Array.isArray(t)&&(t=v.flatten(t)),a(t,e))}function u(t,e){if(null==e||"float32"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e)return new Uint8Array(t);throw new Error("Unknown data type "+e)}function c(t,e){if(t instanceof Float32Array)return t;for(var r=new Float32Array(t.length),n=0;n<r.length;n++){var a=t[n];r[n]=v.isValNaN(a,e)?NaN:a}return r}function p(t,e){if("float32"===e)return t;if("int32"===e||"bool"===e){for(var r="int32"===e?new Int32Array(t.length):new Uint8Array(t.length),n=0;n<r.length;++n){var a=t[n];a=isNaN(a)?v.getNaN(e):Math.round(a),r[n]=a}return r}throw new Error("Unknown dtype "+e)}var l=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),h=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(a,o){function i(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){t.done?a(t.value):new r(function(e){e(t.value)}).then(i,s)}u((n=n.apply(t,e||[])).next())})},f=this&&this.__generator||function(t,e){function r(t){return function(e){return n([t,e])}}function n(r){if(a)throw new TypeError("Generator is already executing.");for(;u;)try{if(a=1,o&&(i=o[2&r[0]?"return":r[0]?"throw":"next"])&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[0,i.value]),r[0]){case 0:case 1:i=r;break;case 4:return u.label++,{value:r[1],done:!1};case 5:u.label++,o=r[1],r=[0];continue;case 7:r=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){u=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){u.label=r[1];break}if(6===r[0]&&u.label<i[1]){u.label=i[1],i=r;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(r);break}i[2]&&u.ops.pop(),u.trys.pop();continue}r=e.call(t,u)}catch(t){r=[6,t],o=0}finally{a=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var a,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(r,"__esModule",{value:!0});var d=t("../environment"),v=t("../util"),m=t("./webgl/tex_util"),y=t("./webgl/webgl_util");r.GPGPU=null,r.TEXTURE_MANAGER=null;!function(t){t.float32="float32",t.int32="int32",t.bool="bool"}(r.DType||(r.DType={})),r.initializeGPU=function(t,e){r.GPGPU=t,r.TEXTURE_MANAGER=e};var g=function(){function t(t,e,r){v.assert(null!=e.values||null!=e.texture,"Either `values` or `texture` must be defined"),v.assert(null==e.texture||null!=e.textureShapeRC,"`textureShape` must be defined when `texture` is defined"),this.size=v.sizeFromShape(t),null!=e.values&&v.assert(this.size===e.values.length,"Constructing ndarray of shape ("+this.size+") should match the length of values ("+e.values.length+")"),this.shape=t,null==e.textureType&&(e.textureType=m.TextureType.DEFAULT),this.ndarrayData=e,this.dtype=r||"float32";var n=this.shape.length;if(n<2)this.strides=[];else{this.strides=new Array(n-1),this.strides[n-2]=this.shape[n-1];for(var a=n-3;a>=0;--a)this.strides[a]=this.strides[a+1]*this.shape[a+1]}}return t.zeros=function(e,r){var n=u(v.sizeFromShape(e),r);return t.make(e,{values:n},r)},t.zerosLike=function(e){return t.zeros(e.shape,e.dtype)},t.like=function(e){var r=a(e.getValues(),e.dtype);return t.make(e.shape,{values:r},e.dtype)},t.make=function(e,r,n){if(r.isDisposed)throw new Error("Cannot make new NDArray from disposed NDArrayData.");switch(e.length){case 0:return new x(r,n);case 1:return new w(r,n);case 2:return new b(e,r,n);case 3:return new _(e,r,n);case 4:return new A(e,r,n);default:return new t(e,r,n)}},t.fromPixels=function(t,e){if(void 0===e&&(e=3),e>4)throw new Error("Cannot construct NDArray with more than 4 channels from pixels.");var n=[t.height,t.width,e],a=[n[0],n[1]],o=r.TEXTURE_MANAGER.acquireTexture(a),i=m.TextureType.RGBA_COLOR;return r.GPGPU.uploadPixelDataToTexture(o,t),_.make(n,{texture:o,textureShapeRC:a,textureType:i})},t.prototype.reshape=function(e){return this.throwIfDisposed(),e=v.inferFromImplicitShape(e,this.size),v.arraysEqual(this.shape,e)?this:(v.assert(this.size===v.sizeFromShape(e),"new shape and old shape must have the same number of elements."),t.make(e,this.ndarrayData,this.dtype))},t.prototype.flatten=function(){return this instanceof w?this:this.as1D()},t.prototype.asScalar=function(){return v.assert(1===this.size,"The array must have only 1 element."),this.reshape([])},t.prototype.as1D=function(){return this.reshape([this.size])},t.prototype.as2D=function(t,e){return this.reshape([t,e])},t.prototype.as3D=function(t,e,r){return this.reshape([t,e,r])},t.prototype.as4D=function(t,e,r,n){return this.reshape([t,e,r,n])},t.prototype.asType=function(e){this.throwIfDisposed();var r=this.getData();return null!=r.values&&(r={values:s(r.values,e)}),t.make(this.shape,r,e)},Object.defineProperty(t.prototype,"rank",{get:function(){return this.throwIfDisposed(),this.shape.length},enumerable:!0,configurable:!0}),t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.throwIfDisposed();for(var r=t[t.length-1],n=0;n<t.length-1;++n)r+=this.strides[n]*t[n];return this.getValues()[r]},t.prototype.add=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.throwIfDisposed(),this.set.apply(this,[this.get.apply(this,e)+t].concat(e))},t.prototype.set=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.throwIfDisposed();for(var n=e[e.length-1],a=0;a<e.length-1;++a)n+=this.strides[a]*e[a];this.getValues()[n]=t},t.prototype.val=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return h(this,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:return this.throwIfDisposed(),[4,this.data()];case 1:return e.sent(),[2,this.get.apply(this,t)]}})})},t.prototype.locToIndex=function(t){for(var e=t[t.length-1],r=0;r<t.length-1;++r)e+=this.strides[r]*t[r];return e},t.prototype.indexToLoc=function(t){for(var e=new Array(this.shape.length),r=0;r<e.length-1;++r)e[r]=Math.floor(t/this.strides[r]),t-=e[r]*this.strides[r];return e[e.length-1]=t,e},t.prototype.fill=function(t){this.throwIfDisposed(),this.getValues().fill(t)},t.prototype.getData=function(){return this.ndarrayData},t.prototype.getValues=function(){return this.dataSync()},t.prototype.getValuesAsync=function(){return this.data()},t.prototype.data=function(){return h(this,void 0,void 0,function(){var t,e;return f(this,function(n){switch(n.label){case 0:return this.throwIfDisposed(),null!=this.ndarrayData.values?[2,this.ndarrayData.values]:d.ENV.get("WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED")&&this.ndarrayData.textureType===m.TextureType.DEFAULT?(t=this.ndarrayData,[4,r.GPGPU.downloadMatrixFromTextureAsync(this.ndarrayData.texture,this.ndarrayData.textureShapeRC[0],this.ndarrayData.textureShapeRC[1])]):[3,2];case 1:return t.values=n.sent(),[2,this.ndarrayData.values];case 2:return d.ENV.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_ENABLED")?[3,4]:[4,this.dataSync()];case 3:return[2,n.sent()];case 4:return e=function(){},[4,r.GPGPU.runQuery(e)];case 5:return n.sent(),[2,this.dataSync()]}})})},t.prototype.dataSync=function(){if(this.throwIfDisposed(),null==this.ndarrayData.values){n();var t=void 0;t=this.ndarrayData.textureType===m.TextureType.DEFAULT?r.GPGPU.downloadMatrixFromTexture(this.ndarrayData.texture,this.ndarrayData.textureShapeRC[0],this.ndarrayData.textureShapeRC[1]):r.GPGPU.downloadMatrixFromRGBAColorTexture(this.ndarrayData.texture,this.ndarrayData.textureShapeRC[0],this.ndarrayData.textureShapeRC[1],this.shape[2]),this.ndarrayData.values=p(t,this.dtype),this.disposeTexture()}return this.ndarrayData.values},t.prototype.uploadToGPU=function(){n(),this.throwIfDisposed(),this.ndarrayData.textureShapeRC=y.getTextureShapeFromLogicalShape(r.GPGPU.gl,this.shape),this.ndarrayData.texture=r.TEXTURE_MANAGER.acquireTexture(this.ndarrayData.textureShapeRC),this.ndarrayData.textureType=m.TextureType.DEFAULT,r.GPGPU.uploadMatrixToTexture(this.ndarrayData.texture,this.ndarrayData.textureShapeRC[0],this.ndarrayData.textureShapeRC[1],c(this.ndarrayData.values,this.dtype)),this.ndarrayData.values=null},t.prototype.getTexture=function(){return this.throwIfDisposed(),null==this.ndarrayData.texture&&this.uploadToGPU(),this.ndarrayData.texture},t.prototype.getTextureShapeRC=function(){return this.throwIfDisposed(),null==this.ndarrayData.textureShapeRC&&this.uploadToGPU(),this.ndarrayData.textureShapeRC},t.prototype.throwIfDisposed=function(){if(this.ndarrayData.isDisposed)throw new Error("NDArray is disposed.")},t.prototype.dispose=function(){this.ndarrayData.values=null,this.shape=null,this.ndarrayData.isDisposed=!0,null!=this.ndarrayData.texture&&this.disposeTexture()},t.prototype.disposeTexture=function(){n(),r.TEXTURE_MANAGER.releaseTexture(this.ndarrayData.texture,this.ndarrayData.textureShapeRC),this.ndarrayData.texture=null,this.ndarrayData.textureShapeRC=null,this.ndarrayData.textureType=null},t.prototype.inGPU=function(){return this.throwIfDisposed(),null!=this.ndarrayData.texture},t.prototype.equals=function(t){return this.throwIfDisposed(),this.dtype===t.dtype&&v.arraysEqual(this.shape,t.shape)&&v.arraysEqual(this.getValues(),t.getValues())},t.rand=function(e,r){for(var n=v.sizeFromShape(e),a=new Float32Array(n),o=0;o<n;o++)a[o]=r();return t.make(e,{values:a})},t.randNormal=function(e,r,n){return void 0===r&&(r=0),void 0===n&&(n=1),t.rand(e,function(){return v.randGauss(r,n)})},t.randTruncatedNormal=function(e,r,n){return void 0===r&&(r=0),void 0===n&&(n=1),t.rand(e,function(){return v.randGauss(r,n,!0)})},t.randUniform=function(e,r,n){return t.rand(e,function(){return v.randUniform(r,n)})},t}();r.NDArray=g;var x=function(t){function e(e,r){return null!=e.texture&&(e.textureShapeRC=[1,1]),t.call(this,[],e,r)||this}return l(e,t),e.new=function(t,r){return new e({values:s([t],r)},r)},e.prototype.get=function(){return this.getValues()[0]},e.prototype.val=function(){return h(this,void 0,void 0,function(){return f(this,function(t){switch(t.label){case 0:return[4,this.data()];case 1:return t.sent(),[2,this.get()]}})})},e.prototype.set=function(t){this.getValues()[0]=t},e.prototype.add=function(t){this.getValues()[0]+=t},e.prototype.asType=function(e){return t.prototype.asType.call(this,e)},e.prototype.locToIndex=function(t){return 0},e.prototype.indexToLoc=function(t){return[]},e.ZERO=e.new(0),e.ONE=e.new(1),e.TWO=e.new(2),e.NEG_ONE=e.new(-1),e}(g);r.Scalar=x;var w=function(t){function e(e,r){var n=null!=e.values?[e.values.length]:[v.sizeFromShape(e.textureShapeRC)];return t.call(this,n,e,r)||this}return l(e,t),e.new=function(t,r){if(!o(t)){var n=v.inferShape(t);v.assert(1===n.length,"Error constructing Array1D. Shape of values "+n+" is not 1 dimensional.")}return new e({values:s(t,r)},r)},e.prototype.get=function(t){return this.getValues()[t]},e.prototype.set=function(t,e){this.getValues()[e]=t},e.prototype.val=function(t){return h(this,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return e.sent(),[2,this.get(t)]}})})},e.prototype.add=function(t,e){this.getValues()[e]+=t},e.prototype.locToIndex=function(t){return t[0]},e.prototype.indexToLoc=function(t){return[t]},e.prototype.asType=function(e){return t.prototype.asType.call(this,e)},e.zeros=function(t,e){return g.zeros(t,e)},e.randNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r)})},e.randTruncatedNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r,!0)})},e.randUniform=function(t,e,r){return g.rand(t,function(){return v.randUniform(e,r)})},e}(g);r.Array1D=w;var b=function(t){function e(e,r,n){var a=this;return v.assert(2===e.length,"Shape should be of length 2"),a=t.call(this,e,r,n)||this,a.stride0=a.strides[0],a}return l(e,t),e.new=function(t,r,n){if(!o(r)){var a=v.inferShape(r);a.length>1&&v.assertShapesMatch(t,a,"Error when constructing Array2D. Shape of values "+a+" does not match the provided shape "+t+". ")}return new e(t,{values:s(r,n)},n)},e.prototype.get=function(t,e){return this.getValues()[this.stride0*t+e]},e.prototype.set=function(t,e,r){this.getValues()[this.stride0*e+r]=t},e.prototype.add=function(t,e,r){this.getValues()[this.stride0*e+r]+=t},e.prototype.val=function(t,e){return h(this,void 0,void 0,function(){return f(this,function(r){switch(r.label){case 0:return[4,this.data()];case 1:return r.sent(),[2,this.get(t,e)]}})})},e.prototype.locToIndex=function(t){return this.stride0*t[0]+t[1]},e.prototype.indexToLoc=function(t){return[Math.floor(t/this.stride0),t%this.stride0]},e.prototype.asType=function(e){return t.prototype.asType.call(this,e)},e.zeros=function(t,e){return g.zeros(t,e)},e.randNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r)})},e.randTruncatedNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r,!0)})},e.randUniform=function(t,e,r){return g.rand(t,function(){return v.randUniform(e,r)})},e}(g);r.Array2D=b;var _=function(t){function e(e,r,n){var a=this;return v.assert(3===e.length,"Shape should be of length 3"),a=t.call(this,e,r,n)||this,a.stride0=a.strides[0],a.stride1=a.strides[1],a}return l(e,t),e.new=function(t,r,n){if(!o(r)){var a=v.inferShape(r);a.length>1&&v.assertShapesMatch(t,a,"Error when constructing Array3D. Shape of values "+a+" does not match the provided shape "+t+". ")}return new e(t,{values:s(r,n)},n)},e.prototype.get=function(t,e,r){return this.getValues()[this.stride0*t+this.stride1*e+r]},e.prototype.set=function(t,e,r,n){this.getValues()[this.stride0*e+this.stride1*r+n]=t},e.prototype.val=function(t,e,r){return h(this,void 0,void 0,function(){return f(this,function(n){switch(n.label){case 0:return[4,this.data()];case 1:return n.sent(),[2,this.get(t,e,r)]}})})},e.prototype.add=function(t,e,r,n){this.getValues()[this.stride0*e+this.stride1*r+n]+=t},e.prototype.locToIndex=function(t){return this.stride0*t[0]+this.stride1*t[1]+t[2]},e.prototype.indexToLoc=function(t){var e=Math.floor(t/this.stride0);return t-=e*this.stride0,[e,Math.floor(t/this.stride1),t%this.stride1]},e.prototype.asType=function(e){return t.prototype.asType.call(this,e)},e.zeros=function(t,e){return g.zeros(t,e)},e.randNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r)})},e.randTruncatedNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r,!0)})},e.randUniform=function(t,e,r){return g.rand(t,function(){return v.randUniform(e,r)})},e}(g);r.Array3D=_;var A=function(t){function e(e,r,n){var a=this;return v.assert(4===e.length,"Shape should be of length 4"),a=t.call(this,e,r,n)||this,a.stride0=a.strides[0],a.stride1=a.strides[1],a.stride2=a.strides[2],a}return l(e,t),e.new=function(t,r,n){if(!o(r)){var a=v.inferShape(r);a.length>1&&v.assertShapesMatch(t,a,"Error when constructing Array4D. Shape of values "+a+" does not match the provided shape "+t+". ")}return new e(t,{values:s(r,n)},n)},e.prototype.get=function(t,e,r,n){return this.getValues()[this.stride0*t+this.stride1*e+this.stride2*r+n]},e.prototype.set=function(t,e,r,n,a){this.getValues()[this.stride0*e+this.stride1*r+this.stride2*n+a]=t},e.prototype.val=function(t,e,r,n){return h(this,void 0,void 0,function(){return f(this,function(a){switch(a.label){case 0:return[4,this.data()];case 1:return a.sent(),[2,this.get(t,e,r,n)]}})})},e.prototype.add=function(t,e,r,n,a){this.getValues()[this.stride0*e+this.stride1*r+this.stride2*n+a]+=t},e.prototype.locToIndex=function(t){return this.stride0*t[0]+this.stride1*t[1]+this.stride2*t[2]+t[3]},e.prototype.indexToLoc=function(t){var e=Math.floor(t/this.stride0);t-=e*this.stride0;var r=Math.floor(t/this.stride1);return t-=r*this.stride1,[e,r,Math.floor(t/this.stride2),t%this.stride2]},e.prototype.asType=function(e){return t.prototype.asType.call(this,e)},e.zeros=function(t,e){return g.zeros(t,e)},e.randNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r)})},e.randTruncatedNormal=function(t,e,r){return void 0===e&&(e=0),void 0===r&&(r=1),g.rand(t,function(){return v.randGauss(e,r,!0)})},e.randUniform=function(t,e,r){return g.rand(t,function(){return v.randUniform(e,r)})},e}(g);r.Array4D=A},{"../environment":15,"../util":96,"./webgl/tex_util":89,"./webgl/webgl_util":94}],64:[function(t,e,r){"use strict";function n(t,e){for(var r=e;r<t;++r)if(t%r==0)return r;return t}Object.defineProperty(r,"__esModule",{value:!0}),r.PARALLELIZE_THRESHOLD=30,r.computeOptimalWindowSize=function(t){return t<=r.PARALLELIZE_THRESHOLD?t:n(t,Math.floor(Math.sqrt(t)))}},{}],65:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../util");r.assertParamsValid=function(t,e,r){n.assert(t.rank===e.length,"Error in slice"+t.rank+"D: Length of begin "+e+" must match the rank of the array ("+t.rank+")."),n.assert(t.rank===r.length,"Error in slice"+t.rank+"D: Length of size "+r+" must match the rank of the array ("+t.rank+").");for(var a=0;a<t.rank;++a)n.assert(e[a]+r[a]<=t.shape[a],"Error in slice"+t.rank+"D: begin["+a+"] + size["+a+"] ("+(e[a]+r[a])+") would overflow input.shape["+a+"] ("+t.shape[a]+")")}},{"../util":96}],66:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../broadcast_util"),a=function(){return function(t,e){this.variableNames=["A","B","c1","c2"],this.supportsBroadcasting=!0,this.outputShape=n.assertAndGetBroadcastShape(t,e),this.userCode="\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n float c1 = getC1();\n float c2 = getC2();\n setOutput(dot(vec2(c1, c2), vec2(a, b)));\n }\n "}}();r.AddScaledMatProgram=a},{"../broadcast_util":55}],67:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e,r){this.variableNames=["A"];var n=t.windowSize,a=t.batchSize,o=t.inSize,i=Math.ceil(o/n);r||this.variableNames.push("bestIndicesA"),this.outputShape=[a,i];var s="max"===e?">":"<",u=r?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+n+";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < "+n+"; i++) {\n int inIdx = "+u+";\n float candidate = getA(batch, inIdx);\n if (isNaN(candidate)) {\n setOutput(candidate);\n return;\n }\n if (candidate "+s+" bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "}}();r.ArgMinMaxProgram=n},{}],68:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../broadcast_util"),a=function(){return function(t,e,r,a,o,i){this.outputShape=[],this.supportsBroadcasting=!0,this.variableNames=["x","mean","variance"],n.assertAndGetBroadcastShape(t,e),n.assertAndGetBroadcastShape(t,r);var s="0.0";null!=a&&(n.assertAndGetBroadcastShape(t,a),this.variableNames.push("offset"),s="getOffsetAtOutCoords()");var u="1.0";null!=o&&(n.assertAndGetBroadcastShape(t,o),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = "+s+";\n float scale = "+u+";\n float inv = scale / sqrt(variance + float("+i+"));\n setOutput((x - mean) * inv + offset);\n }\n "}}();r.BatchNormProgram=a},{"../broadcast_util":55}],69:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../broadcast_util");r.ADD="return a + b;",r.SUB="return a - b;",r.MUL="return a * b;",r.DIV="return a / b;",r.EQUAL="\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n return float(a == b);\n";var a=function(){return function(t,e,r){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.outputShape=n.assertAndGetBroadcastShape(e,r),this.userCode="\n float binaryOperation(float a, float b) {\n "+t+"\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "}}();r.BinaryOpProgram=a},{"../broadcast_util":55}],70:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e,r){this.variableNames=["A"],this.outputShape=t;var n=e.toFixed(20),a=r.toFixed(20);this.userCode="\n void main() {\n float value = getAAtOutCoords();\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, "+n+", "+a+"));\n }\n "}}();r.ClipProgram=n},{}],71:[function(t,e,r){"use strict";function n(t){if(1===t)return"yR";if(2===t)return"yR, yC";if(3===t)return"yR, yC, yD";if(4===t)return"yR, yC, yD, yW";throw Error("Concat for rank "+t+" is not yet supported")}function a(t){var e=1===t?"int yR = coords;":"int yR = coords.x;";if(t>1&&(e+="\nint yC = coords.y;"),t>2&&(e+="\nint yD = coords.z;"),t>3&&(e+="\nint yW = coords.w;"),t>4)throw Error("Concat for rank "+t+" is not yet supported");return e}Object.defineProperty(r,"__esModule",{value:!0});var o=t("../concat_util"),i=t("./shader_compiler"),s=function(){return function(t,e,r){this.variableNames=["A","B"],this.outputShape=[];var s=["yR","yC","yD","yW"][r];this.outputShape=o.computeOutShape(t,e,r);var u=i.getCoordsDataType(t.length),c=a(t.length),p=n(t.length);this.userCode="\n void main() {\n "+u+" coords = getOutputCoords();\n "+c+"\n\n float value = 0.0;\n if ("+s+" < "+t[r]+") {\n value = getA("+p+");\n } else {\n "+s+" -= "+t[r]+";\n value = getB("+p+");\n }\n\n setOutput(value);\n }\n "}}();r.ConcatProgram=s},{"../concat_util":56,"./shader_compiler":87}],72:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../conv_util"),a=function(){return function(t){this.variableNames=["x","dy"];var e=t.outShape,r=e[0],a=e[1],o=e[2],i=t.inShape,s=i[0],u=i[1],c=i[2],p=t.strideHeight,l=t.strideWidth;this.outputShape=n.computeWeightsShape4D(c,o,t.filterHeight,t.filterWidth);var h=t.padInfo.top,f=t.padInfo.left;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int yR = 0; yR < "+r+"; yR++) {\n int xR = wR + yR * "+p+" - "+h+";\n\n if (xR < 0 || xR >= "+s+") {\n continue;\n }\n\n for (int yC = 0; yC < "+a+"; yC++) {\n int xC = wC + yC * "+l+" - "+f+";\n\n if (xC < 0 || xC >= "+u+") {\n continue;\n }\n\n float dyValue = getDy(yR, yC, d2);\n float xValue = getX(xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n setOutput(dotProd);\n }\n "}}();r.Conv2DDerWeightsProgram=a;var o=function(){return function(t){this.variableNames=["dy","W"];var e=t.outShape,r=e[0],n=e[1],a=e[2];this.outputShape=t.inShape;var o=t.filterHeight,i=t.filterWidth,s=t.strideHeight,u=t.strideWidth,c=o-1-t.padInfo.top,p=i-1-t.padInfo.left;this.userCode="\n const ivec2 pads = ivec2("+c+", "+p+");\n\n void main() {\n ivec3 coords = getOutputCoords();\n int d1 = coords.z;\n\n ivec2 dyCorner = coords.xy - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+o+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+s+".0;\n\n if (dyR < 0.0 || dyR >= "+r+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+o+" - 1 - wR;\n\n for (int wC = 0; wC < "+i+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+u+".0;\n\n if (dyC < 0.0 || dyC >= "+n+".0 || fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+i+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+a+"; d2++) {\n float xValue = getDy(idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "}}();r.Conv2DDerInputProgram=o;var i=function(){return function(t){this.variableNames=["dy"];var e=t[0],r=t[1],n=t[2];this.outputShape=[n],this.userCode="\n void main() {\n int d2 = getOutputCoords();\n\n float derBias = 0.0;\n for (int yR = 0; yR < "+e+"; yR++) {\n for (int yC = 0; yC < "+r+"; yC++) {\n derBias += getDy(yR, yC, d2);\n }\n }\n setOutput(derBias);\n }\n "}}();r.Conv2DDerBiasProgram=i},{"../conv_util":57}],73:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e){this.variableNames=["x","W"],e&&this.variableNames.push("bias"),this.outputShape=t.outShape;var r=e?"dotProd += getBias(d2);":"",n=t.inShape,a=n[0],o=n[1],i=n[2],s=t.padInfo.top,u=t.padInfo.left,c=t.strideHeight,p=t.strideWidth,l=t.filterHeight,h=t.filterWidth,f=4*Math.floor(i/4),d=i%4;this.userCode="\n const ivec2 strides = ivec2("+c+", "+p+");\n const ivec2 pads = ivec2("+s+", "+u+");\n\n void main() {\n ivec3 coords = getOutputCoords();\n int d2 = coords.z;\n\n ivec2 xRCCorner = coords.xy * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+l+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+a+") {\n continue;\n }\n\n for (int wC = 0; wC < "+h+"; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+o+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+f+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(xR, xC, d1),\n getX(xR, xC, d1 + 1),\n getX(xR, xC, d1 + 2),\n getX(xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if ("+(1===d)+") {\n dotProd +=\n getX(xR, xC, "+f+") *\n getW(wR, wC, "+f+", d2);\n } else if ("+(2===d)+") {\n vec2 xValues = vec2(\n getX(xR, xC, "+f+"),\n getX(xR, xC, "+f+" + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, "+f+", d2),\n getW(wR, wC, "+f+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===d)+") {\n vec3 xValues = vec3(\n getX(xR, xC, "+f+"),\n getX(xR, xC, "+f+" + 1),\n getX(xR, xC, "+f+" + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, "+f+", d2),\n getW(wR, wC, "+f+" + 1, d2),\n getW(wR, wC, "+f+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n "+r+"\n setOutput(dotProd);\n }\n "}}();r.Conv2DProgram=n},{}],74:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.inShape[1],r=t.inShape[2],n=t.padInfo.top,a=t.padInfo.left,o=t.strideHeight,i=t.strideWidth,s=t.filterHeight,u=t.filterWidth,c=t.channelMul;this.userCode="\n const ivec2 strides = ivec2("+o+", "+i+");\n const ivec2 pads = ivec2("+n+", "+a+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / "+c+";\n int q = d2 - d1 * "+c+";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < "+s+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+e+") {\n continue;\n }\n\n for (int wC = 0; wC < "+u+"; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+r+") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n "}}();r.DepthwiseConv2DProgram=n},{}],75:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function t(t,e){this.variableNames=["source"],this.outputShape=null,this.userCode="\n uniform ivec2 sourceStart;\n uniform ivec2 destStart;\n\n void main() {\n ivec2 destCoords = getOutputCoords() - destStart;\n int index = destCoords.x * "+e+" + destCoords.y;\n int r = index / "+t+";\n ivec2 sourceCoords = sourceStart + ivec2(r, index - r * "+t+");\n setOutput(getSource(sourceCoords.x, sourceCoords.y));\n }\n "}return t.prototype.getCustomSetupFunc=function(t,e,r){return function(n,a){n.setOutputMatrixWriteRegion(e[0],r[0],e[1],r[1]);var o=n.getUniformLocation(a,"sourceStart");n.gl.uniform2i(o,t[0],t[1]);var i=n.getUniformLocation(a,"destStart");n.gl.uniform2i(i,e[0],e[1])}},t}();r.Copy2DProgram=n},{}],76:[function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(a,o){function i(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){t.done?a(t.value):new r(function(e){e(t.value)}).then(i,s)}u((n=n.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){function r(t){return function(e){return n([t,e])}}function n(r){if(a)throw new TypeError("Generator is already executing.");for(;u;)try{if(a=1,o&&(i=o[2&r[0]?"return":r[0]?"throw":"next"])&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[0,i.value]),r[0]){case 0:case 1:i=r;break;case 4:return u.label++,{value:r[1],done:!1};case 5:u.label++,o=r[1],r=[0];continue;case 7:r=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){u=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){u.label=r[1];break}if(6===r[0]&&u.label<i[1]){u.label=i[1],i=r;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(r);break}i[2]&&u.ops.pop(),u.trys.pop();continue}r=e.call(t,u)}catch(t){r=[6,t],o=0}finally{a=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var a,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(r,"__esModule",{value:!0});var o=t("../../environment"),i=t("../../util"),s=t("./gpgpu_util"),u=t("./tex_util"),c=t("./webgl_util"),p=function(){function t(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.autoDebugValidate=!1,this.gl=null!=t?t:s.createWebGLContext(),1===o.ENV.get("WEBGL_VERSION")?(this.textureFloatExtension=c.getExtensionOrThrow(this.gl,"OES_texture_float"),this.colorBufferFloatExtension=this.gl.getExtension("WEBGL_color_buffer_float")):this.colorBufferFloatExtension=c.getExtensionOrThrow(this.gl,"EXT_color_buffer_float"),this.loseContextExtension=c.getExtensionOrThrow(this.gl,"WEBGL_lose_context"),o.ENV.get("WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED")&&(this.getBufferSubDataAsyncExtension=this.gl.getExtension("WEBGL_get_buffer_sub_data_async")),this.vertexBuffer=s.createVertexBuffer(this.gl),this.indexBuffer=s.createIndexBuffer(this.gl),this.framebuffer=c.createFramebuffer(this.gl)}return t.prototype.dispose=function(){var t=this;this.throwIfDisposed(),null!=this.program&&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."),null!=this.outputTexture&&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 e=this.gl;c.callAndCheck(e,function(){return e.finish()}),c.callAndCheck(e,function(){return e.bindFramebuffer(e.FRAMEBUFFER,null)}),c.callAndCheck(e,function(){return e.deleteFramebuffer(t.framebuffer)}),c.callAndCheck(e,function(){return e.bindBuffer(e.ARRAY_BUFFER,null)}),c.callAndCheck(e,function(){return e.deleteBuffer(t.vertexBuffer)}),c.callAndCheck(e,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null)}),c.callAndCheck(e,function(){return e.deleteBuffer(t.indexBuffer)}),this.loseContextExtension.loseContext(),this.disposed=!0},t.prototype.enableAutomaticDebugValidation=function(t){this.autoDebugValidate=t,c.enableDebugWebGLErrorChecking(t)},t.prototype.createMatrixTexture=function(t,e){return this.throwIfDisposed(),s.createMatrixTexture(this.gl,t,e)},t.prototype.uploadPixelDataToTexture=function(t,e){this.throwIfDisposed(),s.uploadPixelDataToTexture(this.gl,t,e)},t.prototype.createPackedMatrixTexture=function(t,e){return this.throwIfDisposed(),s.createPackedMatrixTexture(this.gl,t,e)},t.prototype.deleteMatrixTexture=function(t){var e=this;this.throwIfDisposed(),this.outputTexture===t&&(c.unbindColorTextureFromFramebuffer(this.gl,this.framebuffer),this.outputTexture=null),c.callAndCheck(this.gl,function(){return e.gl.deleteTexture(t)})},t.prototype.uploadMatrixToTexture=function(t,e,r,n){this.throwIfDisposed();return s.uploadMatrixToTexture(this.gl,t,e,r,n,1)},t.prototype.uploadMatrixToPackedTexture=function(t,e,r,n){return this.throwIfDisposed(),s.uploadMatrixToPackedTexture(this.gl,t,e,r,n)},t.prototype.downloadMatrixFromTexture=function(t,e,r){var n=this;return this.downloadMatrixDriver(t,function(){return s.downloadMatrixFromOutputTexture(n.gl,e,r)})},t.prototype.downloadMatrixFromTextureAsync=function(t,e,r){return n(this,void 0,void 0,function(){var n=this;return a(this,function(a){if(null==this.getBufferSubDataAsyncExtension)throw new Error("Cannot download matrix from output texture asynchronously, WEBGL_get_buffer_sub_data_async is not enabled.");return[2,this.downloadMatrixDriverAsync(t,function(){return s.downloadMatrixFromOutputTextureAsync(n.gl,n.getBufferSubDataAsyncExtension,e,r)})]})})},t.prototype.downloadMatrixFromRGBAColorTexture=function(t,e,r,n){var a=this;return this.downloadMatrixDriver(t,function(){return s.downloadMatrixFromRGBAColorTexture(a.gl,e,r,n)})},t.prototype.downloadMatrixFromPackedTexture=function(t,e,r){var n=this;return this.downloadMatrixDriver(t,function(){return s.downloadMatrixFromPackedOutputTexture(n.gl,e,r)})},t.prototype.createProgram=function(t){this.throwIfDisposed();var e=this.gl,r=c.createFragmentShader(e,t),n=s.createVertexShader(e),a=c.createProgram(e);return c.callAndCheck(e,function(){return e.attachShader(a,n)}),c.callAndCheck(e,function(){return e.attachShader(a,r)}),c.linkProgram(e,a),this.autoDebugValidate&&c.validateProgram(e,a),a},t.prototype.deleteProgram=function(t){var e=this;this.throwIfDisposed(),t===this.program&&(this.program=null),null!=t&&c.callAndCheck(this.gl,function(){return e.gl.deleteProgram(t)})},t.prototype.setProgram=function(t){var e=this;this.throwIfDisposed(),this.program=t,null!=this.program&&this.autoDebugValidate&&c.validateProgram(this.gl,this.program),c.callAndCheck(this.gl,function(){return e.gl.useProgram(t)})},t.prototype.getUniformLocation=function(t,e){return this.throwIfDisposed(),c.getProgramUniformLocationOrThrow(this.gl,t,e)},t.prototype.getAttributeLocation=function(t,e){var r=this;return this.throwIfDisposed(),c.callAndCheck(this.gl,function(){return r.gl.getAttribLocation(t,e)})},t.prototype.getUniformLocationNoThrow=function(t,e){return this.throwIfDisposed(),this.gl.getUniformLocation(t,e)},t.prototype.setInputMatrixTexture=function(t,e,r){this.throwIfDisposed(),this.throwIfNoProgram(),c.bindTextureToProgramUniformSampler(this.gl,this.program,t,e,r)},t.prototype.setOutputMatrixTexture=function(t,e,r){this.setOutputMatrixTextureDriver(t,r,e)},t.prototype.setOutputPackedMatrixTexture=function(t,e,r){this.throwIfDisposed();var n=u.getPackedMatrixTextureShapeWidthHeight(e,r),a=n[0],o=n[1];this.setOutputMatrixTextureDriver(t,a,o)},t.prototype.setOutputMatrixWriteRegion=function(t,e,r,n){this.setOutputMatrixWriteRegionDriver(r,t,n,e)},t.prototype.setOutputPackedMatrixWriteRegion=function(t,e,r,n){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},t.prototype.debugValidate=function(){null!=this.program&&c.validateProgram(this.gl,this.program),c.validateFramebuffer(this.gl)},t.prototype.executeProgram=function(t){this.throwIfDisposed(),this.throwIfNoProgram();var e=this.gl;s.bindVertexProgramAttributeStreams(e,this.program,this.vertexBuffer,t),this.autoDebugValidate&&this.debugValidate(),c.callAndCheck(e,function(){return e.drawElements(e.TRIANGLES,6,e.UNSIGNED_SHORT,0)})},t.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),c.callAndCheck(this.gl,function(){return t.gl.finish()})},t.prototype.runQuery=function(t){return 2===o.ENV.get("WEBGL_VERSION")?this.runQueryWebGL2(t):this.runQueryWebGL1(t)},t.prototype.runQueryWebGL2=function(t){var e=this,r=c.getExtensionOrThrow(this.gl,"EXT_disjoint_timer_query_webgl2"),n=this.gl.createQuery();return this.gl.beginQuery(r.TIME_ELAPSED_EXT,n),t(),this.gl.endQuery(r.TIME_ELAPSED_EXT),new Promise(function(t,a){i.repeatedTry(function(){var t=e.gl.getQueryParameter(n,e.gl.QUERY_RESULT_AVAILABLE),a=e.gl.getParameter(r.GPU_DISJOINT_EXT);return t&&!a}).then(function(){var r=e.gl.getQueryParameter(n,e.gl.QUERY_RESULT);t(r/1e6)}).catch(function(){console.warn("Disjoint query timer never available."),t(-1)})})},t.prototype.runQueryWebGL1=function(t){var e=this,r=c.getExtensionOrThrow(this.gl,"EXT_disjoint_timer_query"),n=r.createQueryEXT();return r.beginQueryEXT(r.TIME_ELAPSED_EXT,n),t(),r.endQueryEXT(r.TIME_ELAPSED_EXT),new Promise(function(t,a){i.repeatedTry(function(){var t=r.getQueryObjectEXT(n,r.QUERY_RESULT_AVAILABLE_EXT),a=e.gl.getParameter(r.GPU_DISJOINT_EXT);return t&&!a}).then(function(){var e=r.getQueryObjectEXT(n,r.QUERY_RESULT_EXT);t(e/1e6)}).catch(function(){console.warn("Disjoint query timer never available."),t(-1)})})},t.prototype.downloadMatrixDriverSetup=function(t){this.throwIfDisposed(),c.bindColorTextureToFramebuffer(this.gl,t,this.framebuffer),this.autoDebugValidate&&c.validateFramebuffer(this.gl)},t.prototype.downloadMatrixDriverTeardown=function(){null!=this.outputTexture?(c.bindColorTextureToFramebuffer(this.gl,this.outputTexture,this.framebuffer),this.autoDebugValidate&&c.validateFramebuffer(this.gl)):c.unbindColorTextureFromFramebuffer(this.gl,this.framebuffer)},t.prototype.downloadMatrixDriver=function(t,e){this.downloadMatrixDriverSetup(t);var r=e();return this.downloadMatrixDriverTeardown(),r},t.prototype.downloadMatrixDriverAsync=function(t,e){return n(this,void 0,void 0,function(){var r;return a(this,function(n){switch(n.label){case 0:return this.downloadMatrixDriverSetup(t),[4,e()];case 1:return r=n.sent(),this.downloadMatrixDriverTeardown(),[2,r]}})})},t.prototype.setOutputMatrixTextureDriver=function(t,e,r){this.throwIfDisposed();var n=this.gl;c.bindColorTextureToFramebuffer(n,t,this.framebuffer),this.autoDebugValidate&&c.validateFramebuffer(n),this.outputTexture=t,c.callAndCheck(n,function(){return n.viewport(0,0,e,r)}),c.callAndCheck(n,function(){return n.scissor(0,0,e,r)})},t.prototype.setOutputMatrixWriteRegionDriver=function(t,e,r,n){var a=this;this.throwIfDisposed(),c.callAndCheck(this.gl,function(){return a.gl.scissor(t,e,r,n)})},t.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},t.prototype.throwIfNoProgram=function(){if(null==this.program)throw new Error("No GPU program is currently set.")},t}();r.GPGPUContext=p},{"../../environment":15,"../../util":96,"./gpgpu_util":78,"./tex_util":89,"./webgl_util":94}],77:[function(t,e,r){"use strict";function n(){return!o.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")}function a(t,e){if(t.length!==e.length)throw Error("Binary was compiled with "+t.length+" inputs, but was executed with "+e.length+" inputs");t.forEach(function(t,r){var n=t.logicalShape,a=t.texShape,o=e[r].shape,s=e[r].getTextureShapeRC();if(!i.arraysEqual(n,o))throw Error("Binary was compiled with different shapes than the current args. Shapes "+n+" and "+o+" must match");if(!i.arraysEqual(a,s))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+a+" and "+s+" must match")})}Object.defineProperty(r,"__esModule",{value:!0});var o=t("../../environment"),i=t("../../util"),s=t("./shader_compiler"),u=["uv","clipSpacePos"],c="NaN";r.compileProgram=function(t,e,r,a){for(var o=e.userCode,i=r.map(function(t,r){var n={logicalShape:t.shape,texShape:t.getTextureShapeRC(),textureType:t.getData().textureType};return{name:e.variableNames[r],shapeInfo:n}}),p=i.map(function(t){return t.shapeInfo}),l={logicalShape:a.shape,texShape:a.getTextureShapeRC(),textureType:a.getData().textureType},h=s.makeShader(i,l,o,!0===e.supportsBroadcasting),f=t.createProgram(h),d={},v=0;v<e.variableNames.length;v++){var m=e.variableNames[v];d[m]=t.getUniformLocation(f,m)}var y={};return u.forEach(function(e){y[e]=t.getAttributeLocation(f,e)}),n()&&(d[c]=t.getUniformLocation(f,c)),{program:e,source:h,webGLProgram:f,uniformLocations:d,attributeLocations:y,gpgpu:t,inShapeInfos:p,outShapeInfo:l}},r.runProgram=function(t,e,r,o){a(t.inShapeInfos,e),a([t.outShapeInfo],[r]);var i=r.getTexture(),s=r.getTextureShapeRC(),u=t.gpgpu;u.setOutputMatrixTexture(i,s[0],s[1]),u.setProgram(t.webGLProgram),e.forEach(function(e,r){var n=e.getTexture(),a=t.program.variableNames[r],o=t.uniformLocations[a];u.setInputMatrixTexture(n,o,r)}),n()&&u.gl.uniform1f(t.uniformLocations[c],NaN),null!=o&&o(u,t.webGLProgram),u.executeProgram(t.attributeLocations)},r.makeShaderKey=function(t,e,r){var n="";e.concat(r).forEach(function(t){n+=t.shape+"_"+t.getTextureShapeRC()});var a=t.userCode,o=(!0===t.supportsBroadcasting).toString(),i=t.constructor.name;return i+="_"+o+"_"+n+"_"+a}},{"../../environment":15,"../../util":96,"./shader_compiler":87}],78:[function(t,e,r){"use strict";function n(){return{alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0}}function a(t,e){return f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")&&2===f.ENV.get("WEBGL_VERSION")?4===e?t.RGBA32F:t.R32F:t.RGBA}function o(t,e){return f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")&&2===f.ENV.get("WEBGL_VERSION")?4===e?t.RGBA:t.RED:t.RGBA}function i(t){return f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?t.FLOAT:t.UNSIGNED_BYTE}function s(t,e,r,n){v.validateTextureSize(t,e,r);var s=v.createTexture(t),u=t.TEXTURE_2D,c=a(t,n),p=o(t,n);return v.callAndCheck(t,function(){return t.bindTexture(u,s)}),v.callAndCheck(t,function(){return t.texParameteri(u,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)}),v.callAndCheck(t,function(){return t.texParameteri(u,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}),v.callAndCheck(t,function(){return t.texParameteri(u,t.TEXTURE_MIN_FILTER,t.NEAREST)}),v.callAndCheck(t,function(){return t.texParameteri(u,t.TEXTURE_MAG_FILTER,t.NEAREST)}),v.callAndCheck(t,function(){return t.texImage2D(u,0,c,e,r,0,p,i(t),null)}),v.callAndCheck(t,function(){return t.bindTexture(t.TEXTURE_2D,null)}),s}function u(t,e,r,n,a,s){var u=o(t,s);v.validateTextureSize(t,r,n),v.callAndCheck(t,function(){return t.bindTexture(t.TEXTURE_2D,e)}),v.callAndCheck(t,function(){return t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,n,u,i(t),a)}),v.callAndCheck(t,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function c(t,e,r){return f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?new Float32Array(d.getUnpackedArraySizeFromMatrixSize(t*e,r)):new Uint8Array(t*e*r)}function p(t,e,r,n){if(f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")){var a=new Float32Array(e*r);return d.decodeMatrixFromUnpackedArray(t,a,n),a}return d.decodeToFloatArray(t)}var l=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(a,o){function i(t){try{u(n.next(t))}catch(t){o(t)}}function s(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){t.done?a(t.value):new r(function(e){e(t.value)}).then(i,s)}u((n=n.apply(t,e||[])).next())})},h=this&&this.__generator||function(t,e){function r(t){return function(e){return n([t,e])}}function n(r){if(a)throw new TypeError("Generator is already executing.");for(;u;)try{if(a=1,o&&(i=o[2&r[0]?"return":r[0]?"throw":"next"])&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[0,i.value]),r[0]){case 0:case 1:i=r;break;case 4:return u.label++,{value:r[1],done:!1};case 5:u.label++,o=r[1],r=[0];continue;case 7:r=u.ops.pop(),u.trys.pop();continue;default:if(i=u.trys,!(i=i.length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){u=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){u.label=r[1];break}if(6===r[0]&&u.label<i[1]){u.label=i[1],i=r;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(r);break}i[2]&&u.ops.pop(),u.trys.pop();continue}r=e.call(t,u)}catch(t){r=[6,t],o=0}finally{a=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}var a,o,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s};Object.defineProperty(r,"__esModule",{value:!0});var f=t("../../environment"),d=t("./tex_util"),v=t("./webgl_util");r.getWebGLContextAttributes=n,r.createWebGLContext=function(t){var e,r=n();return e=null!=t?v.createWebGLRenderingContextFromCanvas(t,r):v.createWebGLRenderingContext(r),v.callAndCheck(e,function(){return e.disable(e.DEPTH_TEST)}),v.callAndCheck(e,function(){return e.disable(e.STENCIL_TEST)}),v.callAndCheck(e,function(){return e.disable(e.BLEND)}),v.callAndCheck(e,function(){return e.disable(e.DITHER)}),v.callAndCheck(e,function(){return e.disable(e.POLYGON_OFFSET_FILL)}),v.callAndCheck(e,function(){return e.disable(e.SAMPLE_COVERAGE)}),v.callAndCheck(e,function(){return e.enable(e.SCISSOR_TEST)}),v.callAndCheck(e,function(){return e.enable(e.CULL_FACE)}),v.callAndCheck(e,function(){return e.cullFace(e.BACK)}),e},r.createVertexShader=function(t){return v.createVertexShader(t,"\n precision highp float;\n attribute vec3 clipSpacePos;\n attribute vec2 uv;\n varying vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }")},r.createVertexBuffer=function(t){var e=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return v.createStaticVertexBuffer(t,e)},r.createIndexBuffer=function(t){var e=new Uint16Array([0,1,2,2,1,3]);return v.createStaticIndexBuffer(t,e)},r.createMatrixTexture=function(t,e,r){var n=d.getUnpackedMatrixTextureShapeWidthHeight(e,r);return s(t,n[0],n[1],1)},r.createColorMatrixTexture=function(t,e,r){var n=d.getColorMatrixTextureShapeWidthHeight(e,r);return s(t,n[0],n[1],4)},r.createPackedMatrixTexture=function(t,e,r){var n=d.getPackedMatrixTextureShapeWidthHeight(e,r);return s(t,n[0],n[1],4)},r.bindVertexProgramAttributeStreams=function(t,e,r,n){v.callAndCheck(t,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),v.bindVertexBufferToProgramAttribute(t,e,"clipSpacePos",r,3,20,0,n),v.bindVertexBufferToProgramAttribute(t,e,"uv",r,2,20,12,n)},r.uploadPixelDataToTexture=function(t,e,r){v.callAndCheck(t,function(){return t.bindTexture(t.TEXTURE_2D,e)}),v.callAndCheck(t,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}),v.callAndCheck(t,function(){return t.bindTexture(t.TEXTURE_2D,null)})},r.uploadMatrixToTexture=function(t,e,r,n,a,o){var i,s=d.getUnpackedMatrixTextureShapeWidthHeight(r,n),c=s[0],p=s[1];if(f.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")){var l=1===o?v.getChannelsPerTexture():o;1===l?i=a:(i=new Float32Array(d.getUnpackedArraySizeFromMatrixSize(a.length,l)),d.encodeMatrixToUnpackedArray(a,i,l))}else i=d.encodeFloatArray(a);u(t,e,c,p,i,o)},r.uploadMatrixToPackedTexture=function(t,e,r,n,a){var o=d.getPackedMatrixTextureShapeWidthHeight(r,n),i=o[0],s=o[1],c=new Float32Array(d.getPackedRGBAArraySizeFromMatrixShape(r,n));d.encodeMatrixToPackedRGBA(a,r,n,c);u(t,e,i,s,c,4)},r.downloadMatrixFromOutputTextureAsync=function(t,e,r,n){return l(this,void 0,void 0,function(){var a,o,s,u,l;return h(this,function(h){switch(h.label){case 0:return a=t,o=4,s=c(r,n,o),u=s instanceof Float32Array?4*s.length:s,l=t.createBuffer(),v.callAndCheck(t,function(){return t.bindBuffer(a.PIXEL_PACK_BUFFER,l)}),v.callAndCheck(t,function(){return t.bufferData(a.PIXEL_PACK_BUFFER,u,t.STATIC_DRAW)}),v.callAndCheck(t,function(){return a.readPixels(0,0,n,r,t.RGBA,i(t),0)}),[4,e.getBufferSubDataAsync(a.PIXEL_PACK_BUFFER,0,s)];case 1:return h.sent(),[2,p(s,r,n,o)]}})})},r.downloadMatrixFromOutputTexture=function(t,e,r){var n=d.getUnpackedMatrixTextureShapeWidthHeight(e,r),a=n[0],o=n[1],s=c(e,r,4);return v.callAndCheck(t,function(){return t.readPixels(0,0,a,o,t.RGBA,i(t),s)}),p(s,e,r,4)},r.downloadMatrixFromRGBAColorTexture=function(t,e,r,n){var a=e*r*4,o=new Uint8Array(a);v.callAndCheck(t,function(){return t.readPixels(0,0,r,e,t.RGBA,t.UNSIGNED_BYTE,o)});for(var i=new Float32Array(a),s=0;s<o.length;s++)i[s]=o[s];var u=new Float32Array(e*r*n);return d.decodeMatrixFromUnpackedColorRGBAArray(i,u,n),u},r.downloadMatrixFromPackedOutputTexture=function(t,e,r){var n=d.getPackedMatrixTextureShapeWidthHeight(e,r),a=n[0],o=n[1],s=new Float32Array(d.getPackedRGBAArraySizeFromMatrixShape(e,r));v.callAndCheck(t,function(){return t.readPixels(0,0,a,o,t.RGBA,i(t),s)});var u=new Float32Array(e*r);return d.decodeMatrixFromPackedRGBA(s,e,r,u)}},{"../../environment":15,"./tex_util":89,"./webgl_util":94}],79:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.outShape[0],r=t.outShape[1],n=t.filterHeight,a=t.filterWidth,o=t.strideHeight,i=t.strideWidth,s=n-1-t.padInfo.top,u=a-1-t.padInfo.left,c=n*a-1;this.userCode="\n const ivec2 pads = ivec2("+s+", "+u+");\n\n void main() {\n ivec3 coords = getOutputCoords();\n int d = coords.z;\n\n ivec2 dyRCCorner = coords.xy - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+n+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+o+".0;\n\n if (dyR < 0.0 || dyR >= "+e+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+a+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+r+".0 || fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(idyR, idyC, d);\n int maxPosValue = "+c+" - int(getMaxPos(idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * "+a+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "}}();r.MaxPool2DBackpropProgram=n},{}],80:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=t("../math"),a=function(){return function(t,e,r,a){void 0===r&&(r=n.MatrixOrientation.REGULAR),void 0===a&&(a=n.MatrixOrientation.REGULAR),this.variableNames=["matrixA","matrixB"];var o=r===n.MatrixOrientation.REGULAR?t[0]:t[1],i=a===n.MatrixOrientation.REGULAR?e[1]:e[0];this.outputShape=[o,i];var s=r===n.MatrixOrientation.REGULAR?t[1]:t[0],u=function(t,e){return r===n.MatrixOrientation.REGULAR?"aRow, "+e+" + "+t:e+" + "+t+", aRow"},c=function(t,e){return a===n.MatrixOrientation.REGULAR?e+" + "+t+", bCol":"bCol, "+e+" + "+t},p=4*Math.floor(s/4),l=s%4;this.userCode=" float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < "+p+"; i += 4) {\n vec4 a = vec4(\n getMatrixA("+u(0,"i")+"),\n getMatrixA("+u(1,"i")+"),\n getMatrixA("+u(2,"i")+"),\n getMatrixA("+u(3,"i")+")\n );\n vec4 b = vec4(\n getMatrixB("+c(0,"i")+"),\n getMatrixB("+c(1,"i")+"),\n getMatrixB("+c(2,"i")+"),\n getMatrixB("+c(3,"i")+")\n );\n\n result += dot(a, b);\n }\n\n if ("+(1===l)+") {\n result += getMatrixA("+u(0,p)+") *\n getMatrixB("+c(0,p)+");\n } else if ("+(2===l)+") {\n vec2 a = vec2(\n getMatrixA("+u(0,p)+"),\n getMatrixA("+u(1,p)+")\n );\n vec2 b = vec2(\n getMatrixB("+c(0,p)+"),\n getMatrixB("+c(1,p)+")\n );\n result += dot(a, b);\n } else if ("+(3===l)+") {\n vec3 a = vec3(\n getMatrixA("+u(0,p)+"),\n getMatrixA("+u(1,p)+"),\n getMatrixA("+u(2,p)+")\n );\n vec3 b = vec3(\n getMatrixB("+c(0,p)+"),\n getMatrixB("+c(1,p)+"),\n getMatrixB("+c(2,p)+")\n );\n result += dot(a, b);\n }\n\n return result;\n }\n\n void main() {\n ivec2 resRC = getOutputCoords();\n setOutput(dotARowBCol(resRC.x, resRC.y));\n }\n "}}();r.MatMulProgram=a},{"../math":60}],81:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function t(t,e,r){this.variableNames=["probs"],this.outputShape=[t,r],this.userCode="\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < "+(e-1)+"; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float("+(e-1)+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(r,n){null==e.seedLoc&&(e.seedLoc=r.getUniformLocation(n,"seed")),r.gl.uniform1f(e.seedLoc,t)}},t}();r.MultinomialProgram=n},{}],82:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function t(t,e,r,n){this.variableNames=["indices"],this.outputShape=[t,e],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float("+n+"), float("+r+"),\n float(index == coords.y)));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(r,n){null==e.seedLoc&&(e.seedLoc=r.getUniformLocation(n,"seed")),r.gl.uniform1f(e.seedLoc,t)}},t}();r.OneHotProgram=n},{}],83:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e,r){if(this.variableNames=["x"],"avg"===e&&r)throw new Error("Cannot compute positions for average pool.");var n=t.filterHeight,a=t.filterWidth,o=t.strideHeight,i=t.strideWidth,s=t.inShape[0],u=t.inShape[1],c=t.padInfo.top,p=t.padInfo.left;this.outputShape=t.outShape;var l="avg"===e,h="0.0";if(l||(h="min"===e?"1.0 / 0.0":"-1.0 / 0.0"),r){var f="min"===e?"<=":">=";this.userCode="\n const ivec2 strides = ivec2("+o+", "+i+");\n const ivec2 pads = ivec2("+c+", "+p+");\n\n void main() {\n ivec3 coords = getOutputCoords();\n int d = coords.z;\n\n ivec2 xRCCorner = coords.xy * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < "+n+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+s+") {\n continue;\n }\n\n for (int wC = 0; wC < "+a+"; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+u+") {\n continue;\n }\n\n float value = getX(xR, xC, d);\n\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value "+f+" currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * "+a+" + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "}else{var d="min"===e?"min":"max",v=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(v="avgValue / "+n*a+".0");var m=4*Math.floor(a/4),y=a%4,g="\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n if ("+l+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = "+d+"(values, minMaxValue);\n }\n ";this.userCode="\n const ivec2 strides = ivec2("+o+", "+i+");\n const ivec2 pads = ivec2("+c+", "+p+");\n const float initializationValue = "+h+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int xR, int xC, int d) {\n if (xC < 0 || xC >= "+u+") {\n return initializationValue;\n }\n return getX(xR, xC, d);\n }\n\n void main() {\n ivec3 coords = getOutputCoords();\n int d = coords.z;\n\n ivec2 xRCCorner = coords.xy * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4("+h+");\n float avgValue = 0.0;\n\n for (int wR = 0; wR < "+n+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+s+") {\n continue;\n }\n\n for (int wC = 0; wC < "+m+"; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(xR, xC, d),\n getValue(xR, xC + 1, d),\n getValue(xR, xC + 2, d),\n getValue(xR, xC + 3, d)\n );\n\n "+g+"\n }\n\n int xC = xCCorner + "+m+";\n if ("+(1===y)+") {\n vec4 values = vec4(\n getValue(xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n "+g+"\n } else if ("+(2===y)+") {\n vec4 values = vec4(\n getValue(xR, xC, d),\n getValue(xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n "+g+"\n } else if ("+(3===y)+") {\n vec4 values = vec4(\n getValue(xR, xC, d),\n getValue(xR, xC + 1, d),\n getValue(xR, xC + 2, d),\n initializationValue\n );\n\n "+g+"\n }\n }\n setOutput("+v+");\n }\n "}}}();r.Pool2DProgram=n},{}],84:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e){this.variableNames=["x"];var r=t.windowSize,n=t.batchSize,a=t.inSize,o=Math.ceil(a/r);this.outputShape=[n,o];var i="sum"===e,s="0.0";i||(s="min"===e?"1.0 / 0.0":"-1.0 / 0.0");var u="min"===e?"min":"max",c=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"sum"===e&&(c="sumValue");var p=4*Math.floor(r/4),l=r%4,h="\n if ("+i+") {\n sumValue += dot(values, ones);\n } else {\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n minMaxValue = "+u+"(values, minMaxValue);\n }\n ",f="";a%r>0&&(f="\n if (inIdx < 0 || inIdx >= "+a+") {\n return initializationValue;\n }\n "),this.userCode="\n const float initializationValue = "+s+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n "+f+"\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+r+";\n\n vec4 minMaxValue = vec4("+s+");\n float sumValue = 0.0;\n\n for (int i = 0; i < "+p+"; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n "+h+"\n }\n\n int inIdx = inOffset + "+p+";\n if ("+(1===l)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n "+h+"\n } else if ("+(2===l)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n "+h+"\n } else if ("+(3===l)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n "+h+"\n }\n setOutput("+c+");\n }\n "}}();r.ReduceProgram=n},{}],85:[function(t,e,r){"use strict";function n(t,e,r){t.setProgram(e);var n=a.getProgramUniformLocationOrThrow(t.gl,e,"source");t.setInputMatrixTexture(r,n,0),t.executeProgram()}Object.defineProperty(r,"__esModule",{value:!0});var a=t("./webgl_util");r.getRenderRGBShader=function(t,e){var r="\n precision highp float;\n uniform sampler2D source;\n varying vec2 resultUV;\n\n const float destinationWidth = "+e+".0;\n const float a = 1.0;\n\n void main() {\n float xr = floor(resultUV.s * destinationWidth) * 3.0;\n vec3 x = xr + vec3(0, 1, 2);\n\n float sourceWidth = destinationWidth * 3.0;\n vec3 u = (x + 0.5) / sourceWidth;\n float v = 1.0 - resultUV.t;\n\n float r = texture2D(source, vec2(u[0], v)).r;\n float g = texture2D(source, vec2(u[1], v)).r;\n float b = texture2D(source, vec2(u[2], v)).r;\n\n gl_FragColor = vec4(r, g, b, a);\n }";return t.createProgram(r)},r.renderToCanvas=function(t,e,r){a.bindCanvasToFramebuffer(t.gl),n(t,e,r)},r.renderToFramebuffer=n},{"./webgl_util":94}],86:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e,r){this.variableNames=["A"],this.outputShape=[];var n=t[2];this.outputShape=[e[0],e[1],n];var a=r?[t[0]-1,t[1]-1,n]:t,o=r?[this.outputShape[0]-1,this.outputShape[1]-1,n]:this.outputShape;this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+a[0]/o[0]+",\n "+a[1]/o[1]+");\n const vec2 inputShapeRC = vec2("+t[0]+".0, "+t[1]+".0);\n\n void main() {\n ivec3 coords = getOutputCoords();\n ivec2 yRC = coords.xy;\n int d = coords.z;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "}}();r.ResizeBilinear3DProgram=n},{}],87:[function(t,e,r){"use strict";function n(){return _.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?O:C}function a(){return _.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?R:N}function o(t){var e=t.shapeInfo.logicalShape;switch(e.length){case 0:return h(t);case 1:return f(t);case 2:return d(t);case 3:return v(t);case 4:return m(t);default:throw new Error(e.length+"-D input sampling is not yet supported")}}function i(t,e,r){var n=y(t);return n+=o(t),(r||A.arraysEqual(t.shapeInfo.logicalShape,e.logicalShape))&&(n+=x(t,e,r)),n}function s(t,e){switch(t.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return u(t,e);case 2:return l(t,e);case 3:return c(t,e);case 4:return p(t,e);default:throw new Error(t.length+"-D output sampling is not yet supported")}}function u(t,e){return 1===e[0]?"\n int getOutputCoords() {\n return int(resultUV.x * "+e[1]+".0);\n }\n ":1===e[1]?"\n int getOutputCoords() {\n return int(resultUV.y * "+e[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n return resTexRC.x * "+e[1]+" + resTexRC.y;\n }\n "}function c(t,e){var r=t[1]*t[2],n=t[2];return"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n int r = index / "+r+";\n index -= r * "+r+";\n int c = index / "+n+";\n int d = index - c * "+n+";\n return ivec3(r, c, d);\n }\n "}function p(t,e){var r=t[3],n=t[2]*r,a=t[1]*n;return"\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n\n int r = index / "+a+";\n index -= r * "+a+";\n\n int c = index / "+n+";\n index -= c * "+n+";\n\n int d = index / "+r+";\n int d2 = index - d * "+r+";\n\n return ivec4(r, c, d, d2);\n }\n "}function l(t,e){return A.arraysEqual(t,e)?"\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2("+e[0]+", "+e[1]+"));\n }\n ":1===t[1]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(index, 0);\n }\n ":1===t[0]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(0, index);\n }\n ":"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n int r = index / "+t[1]+";\n int c = index - r * "+t[1]+";\n return ivec2(r, c);\n }\n "}function h(t){var e=t.name;return"\n float "+("get"+e.charAt(0).toUpperCase()+e.slice(1))+"() {\n return sample("+e+", halfCR);\n }\n "}function f(t){var e=t.name,r="get"+e.charAt(0).toUpperCase()+e.slice(1);return"\n float "+r+"(int index) {\n return "+r+"Flat(index);\n }\n "}function d(t){var e=t.shapeInfo.logicalShape,r=t.shapeInfo.texShape,n=t.name,a="get"+n.charAt(0).toUpperCase()+n.slice(1),i=r[0],s=r[1];if(A.arraysEqual(e,r))return"\n float "+a+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+s+".0, "+i+".0);\n return sample("+n+", uv);\n }\n ";var u=A.squeezeShape(e),c=u.newShape,p=u.keptDims,l=c;if(l.length<e.length){var h=["row","col"];return"\n "+o(w(t,l))+"\n float "+a+"(int row, int col) {\n return "+a+"("+b(h,p)+");\n }\n "}return 1===s?"\n float "+a+"(int row, int col) {\n int index = row * "+e[1]+" + col;\n vec2 uv = vec2(0.5, (float(index) + 0.5) / "+i+".0);\n return sample("+n+", uv);\n }\n ":1===i?"\n float "+a+"(int row, int col) {\n int index = row * "+e[1]+" + col;\n vec2 uv = vec2((float(index) + 0.5) / "+s+".0, 0.5);\n return sample("+n+", uv);\n }\n ":"\n float "+a+"(int row, int col) {\n vec2 uv = UVfrom2D("+i+", "+s+", "+e[1]+", row, col);\n return sample("+n+", uv);\n }\n"}function v(t){var e=t.shapeInfo.texShape,r=t.shapeInfo.logicalShape,n=t.name,a="get"+n.charAt(0).toUpperCase()+n.slice(1),i=e[0],s=e[1],u=r[1]*r[2],c=r[2],p=t.shapeInfo.textureType;if(p===S.TextureType.DEFAULT){var l=A.squeezeShape(r),h=l.newShape,f=l.keptDims,d=h;if(d.length<r.length){var v=["row","col","depth"];return"\n "+o(w(t,d))+"\n float "+a+"(int row, int col, int depth) {\n return "+a+"("+b(v,f)+");\n }\n "}}if(s===u){if(p===S.TextureType.DEFAULT)return"\n float "+a+"(int row, int col, int depth) {\n int texR = row;\n int texC = col * "+c+" + depth;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+s+".0, "+i+".0);\n return sample("+n+", uv);\n }\n ";if(p===S.TextureType.RGBA_COLOR)return"\n float "+a+"(int row, int col, int depth) {\n vec2 uv = (vec2(col, row) + halfCR) /\n vec2("+s+".0, "+i+".0);\n return sampleUVAndDepth("+n+", uv, depth);\n }\n ";throw new Error("Unknown TextureType "+p+".")}if(s===c&&p===S.TextureType.DEFAULT)return"\n float "+a+"(int row, int col, int depth) {\n int texR = row * "+r[1]+" + col;\n int texC = depth;\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+s+".0, "+i+".0);\n return sample("+n+", uv);\n }\n ";if(p===S.TextureType.DEFAULT)return"\n float "+a+"(int row, int col, int depth) {\n vec2 uv = UVfrom3D(\n "+i+", "+s+", "+u+", "+c+", row, col, depth);\n return sample("+n+", uv);\n }\n ";if(p===S.TextureType.RGBA_COLOR)return"\n float "+a+"(int row, int col, int depth) {\n vec2 uv = UVfrom2D("+i+", "+s+", "+r[1]+", row, col);\n return sampleUVAndDepth("+n+", uv, depth);\n }\n ";throw new Error("Unknown TextureType "+p+".")}function m(t){var e=t.shapeInfo.logicalShape,r=t.shapeInfo.texShape,n=t.name,a="get"+n.charAt(0).toUpperCase()+n.slice(1),i=r[0],s=r[1],u=e[3],c=e[2]*u,p=e[1]*c,l=A.squeezeShape(e),h=l.newShape,f=l.keptDims;if(h.length<e.length){var d=["row","col","depth","depth2"];return"\n "+o(w(t,h))+"\n float "+a+"(int row, int col, int depth, int depth2) {\n return "+a+"("+b(d,f)+");\n }\n "}return s===p?"\n float "+a+"(int row, int col, int depth, int depth2) {\n int texR = row;\n int texC = col * "+c+" + depth * "+u+" + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+s+".0, "+i+".0);\n return sample("+n+", uv);\n }\n ":s===u?"\n float "+a+"(int row, int col, int depth, int depth2) {\n int texR = row * "+e[1]*e[2]+" + col * "+e[2]+" + depth;\n int texC = depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+s+".0, "+i+".0);\n return sample("+n+", uv);\n }\n ":"\n float "+a+"(int row, int col, int depth, int depth2) {\n vec2 uv = UVfrom4D("+i+", "+s+", "+p+", "+c+",\n "+u+", row, col, depth, depth2);\n return sample("+n+", uv);\n }\n "}function y(t){var e=t.name,r=t.shapeInfo.texShape,n="get"+e.charAt(0).toUpperCase()+e.slice(1)+"Flat",a=r[0],o=r[1];return 1===o&&1===a?"\n float "+n+"(int index) {\n return sample("+e+", halfCR);\n }\n ":1===o?"\n float "+n+"(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / "+a+".0);\n return sample("+e+", uv);\n }\n ":1===a?"\n float "+n+"(int index) {\n vec2 uv = vec2((float(index) + 0.5) / "+o+".0, 0.5);\n return sample("+e+", uv);\n }\n ":"\n float "+n+"(int index) {\n vec2 uv = UVfrom1D("+a+", "+o+", index);\n return sample("+e+", uv);\n }\n "}function g(t,e,r,n){var a=t.shapeInfo.logicalShape.length,o=e.logicalShape.length,i="int";2===o?i="ivec2":3===o?i="ivec3":4===o&&(i="ivec4");var s,u=T.getBroadcastDims(t.shapeInfo.logicalShape,e.logicalShape),c=o-a;s=0===a?"":o<2&&u.length>=1?"coords = 0;":u.map(function(t){return"coords["+(t+c)+"] = 0;"}).join("\n");var p="";return p=o<2&&a>0?"coords":t.shapeInfo.logicalShape.map(function(t,e){return"coords["+(e+c)+"]"}).join(", "),"\n float "+n+"() {\n "+i+" coords = getOutputCoords();\n "+s+"\n return get"+r+"("+p+");\n }\n "}function x(t,e,r){var n=t.shapeInfo.texShape,a=t.name,o=t.shapeInfo.textureType===S.TextureType.RGBA_COLOR,i=a.charAt(0).toUpperCase()+a.slice(1),s="get"+i+"AtOutCoords",u=T.getBroadcastDims(t.shapeInfo.logicalShape,e.logicalShape),c=t.shapeInfo.logicalShape.length,p=e.logicalShape.length,l=r&&(p>c||u.length>0),h=T.broadcastDimsAreOuter(u);if(l&&!h)return g(t,e,i,s);var f=e.texShape;if(A.arraysEqual(n,f)&&!o)return"\n float "+s+"() {\n return sample("+a+", resultUV);\n }\n ";var d=o?[n[0],n[1]*t.shapeInfo.logicalShape[2]]:n,v="return sample("+a+", uv);",m="";o&&(m="\n int col = texC / "+t.shapeInfo.logicalShape[2]+";\n int texD = texC - col * "+t.shapeInfo.logicalShape[2]+";\n texC = col;\n ",v="return sampleUVAndDepth("+a+", uv, texD);");var y=A.sizeFromShape(d),x="";return l&&h&&(x="\n int mainPart = index / "+y+";\n index -= mainPart * "+y+";\n "),"\n float "+s+"() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+f[0]+", "+f[1]+"));\n int index = resTexRC.x * "+f[1]+" + resTexRC.y;\n "+x+"\n int texR = index / "+d[1]+";\n int texC = index - texR * "+d[1]+";\n\n "+m+"\n\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+n[1]+".0, "+n[0]+".0);\n\n "+v+"\n }\n "}function w(t,e){var r=JSON.parse(JSON.stringify(t));return r.shapeInfo.logicalShape=e,r}function b(t,e){return e.map(function(e){return t[e]}).join(", ")}Object.defineProperty(r,"__esModule",{value:!0});var _=t("../../environment"),A=t("../../util"),T=t("../broadcast_util"),E=t("./tex_util"),S=t("./tex_util");r.makeShader=function(t,e,r,o){var u=n(),c=a(),p=t.map(function(t){return"uniform sampler2D "+t.name+";"}).join("\n"),l=t.map(function(t){return i(t,e,o)}).join("\n"),h=e.texShape,f=s(e.logicalShape,h);return[M,u,c,p,f,l,r].join("\n")};var C="\n uniform float NaN;\n\n const vec4 floatDeltas = vec4(\n 1.0,\n 1.0 / 255.0,\n 1.0 / (255.0 * 255.0),\n 1.0 / (255.0 * 255.0 * 255.0)\n );\n const float minValue = "+E.FLOAT_MIN+".0;\n const float maxValue = "+E.FLOAT_MAX+".0;\n const float range = (maxValue - minValue) / 255.0;\n const vec2 dotRange = vec2(1.0, range);\n\n float sample(sampler2D texture, vec2 uv) {\n vec4 sampleValue = texture2D(texture, uv);\n if (all(equal(sampleValue, vec4("+E.BYTE_NAN_VALUE+")))) {\n return NaN;\n }\n\n vec4 encValue = floor(sampleValue * 255.0 + 0.5);\n float decodedValue = dot(encValue, floatDeltas);\n return dot(vec2(minValue, decodedValue), dotRange);\n }\n",N="\n const vec4 floatPowers = vec4(\n 1.0,\n 255.0,\n 255.0 * 255.0,\n 255.0 * 255.0 * 255.0\n );\n const vec2 recipRange = vec2(1.0/range);\n const vec2 recipRange255 = vec2(1.0/(maxValue - minValue));\n\n void setOutput(float decodedValue) {\n if (isNaN(decodedValue)) {\n gl_FragColor = vec4("+E.BYTE_NAN_VALUE+");\n return;\n }\n\n float a = dot(vec2(decodedValue, -minValue), recipRange);\n float b = fract(a) * 255.0;\n float c = fract(b) * 255.0;\n float d = fract(c) * 255.0;\n gl_FragColor = floor(vec4(a, b, c, d)) / 255.0;\n\n // TODO(dsmilkov): Version above gets better accuracy but probably slower\n // than the version below. Benchmark to determine if the accuracy is worth\n // the cost.\n\n // float normValue = dot(vec2(decodedValue, -minValue), recipRange255);\n // vec4 f = normValue * floatPowers;\n // gl_FragColor = floor(fract(f) * 255.0) / 255.0;\n }\n",O="\n float sample(sampler2D texture, vec2 uv) {\n return texture2D(texture, uv).r;\n }\n",R="\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n",M="\n precision highp float;\n precision highp int;\n varying vec2 resultUV;\n const vec2 halfCR = vec2(0.5, 0.5);\n\n bool isNaN(float val) {\n return val == val ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n return any(notEqual(values, values));\n }\n\n float getNaN(vec4 values) {\n return dot(vec4(1), values);\n }\n\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n const vec2 randomConst = vec2(\n 23.14069263277926, // e^pi (Gelfond's constant)\n 2.665144142690225 // 2^sqrt(2) (Gelfond–Schneider constant)\n );\n\n float random(float seed) {\n return fract(cos(dot(resultUV * seed, randomConst)) * 12345.6789);\n }\n\n float sampleUVAndDepth(sampler2D texture, vec2 uv, int depth) {\n float value;\n if (depth == 0) {\n value = texture2D(texture, uv).r;\n } else if (depth == 1) {\n value = texture2D(texture, uv).g;\n } else if (depth == 2) {\n value = texture2D(texture, uv).b;\n } else if (depth == 3) {\n value = texture2D(texture, uv).a;\n }\n return floor(value * 255.0 + 0.5);\n }\n\n \nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n\n \nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\n int index = row * numC + col;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n\n \nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\n int stride1, int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n\n \nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int row, int col, int depth,\n int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n\n";r.getCoordsDataType=function(t){if(1===t)return"int";if(2===t)return"ivec2";if(3===t)return"ivec3";if(4===t)return"ivec4";throw Error("GPU for rank "+t+" is not yet supported")}},{"../../environment":15,"../../util":96,"../broadcast_util":55,"./tex_util":89}],88:[function(t,e,r){"use strict";function n(t){if(1===t)return"sourceLoc";if(2===t)return"sourceLoc.x, sourceLoc.y";if(3===t)return"sourceLoc.x, sourceLoc.y, sourceLoc.z";if(4===t)return"sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w";throw Error("Slicing for rank "+t+" is not yet supported")}Object.defineProperty(r,"__esModule",{value:!0});var a=t("./shader_compiler"),o=function(){function t(t){this.variableNames=["source"],this.outputShape=t,this.rank=t.length;var e=a.getCoordsDataType(this.rank),r=n(this.rank);this.userCode="\n uniform "+e+" start;\n\n void main() {\n "+e+" sourceLoc = start + getOutputCoords();\n setOutput(getSource("+r+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+t.length+")");return function(r,n){if(null!=e.startLoc||(e.startLoc=r.getUniformLocationNoThrow(n,"start"),null!=e.startLoc))if(1===e.rank)r.gl.uniform1i(e.startLoc,t[0]);else if(2===e.rank)r.gl.uniform2i(e.startLoc,t[0],t[1]);else if(3===e.rank)r.gl.uniform3i(e.startLoc,t[0],t[1],t[2]);else{if(4!==e.rank)throw Error("Slicing for rank "+e.rank+" is not yet supported");r.gl.uniform4i(e.startLoc,t[0],t[1],t[2],t[3])}}},t}();r.SliceProgram=o},{"./shader_compiler":87}],89:[function(t,e,r){"use strict";function n(t,e){return t*e}function a(t,e){if(t%e!=0)throw new Error("unpackedSize ("+t+") must be a multiple of "+e);return t/e}function o(t,e){return[Math.ceil(e/2),Math.ceil(t/2)]}function i(t,e){var r=o(t,e);return r[0]*r[1]*4}Object.defineProperty(r,"__esModule",{value:!0});!function(t){t[t.DEFAULT=0]="DEFAULT",t[t.RGBA_COLOR=1]="RGBA_COLOR"}(r.TextureType||(r.TextureType={})),r.getUnpackedMatrixTextureShapeWidthHeight=function(t,e){return[e,t]},r.getUnpackedArraySizeFromMatrixSize=n,r.getColorMatrixTextureShapeWidthHeight=function(t,e){return[4*e,t]},r.getMatrixSizeFromUnpackedArraySize=a,r.encodeMatrixToUnpackedArray=function(t,e,r){var a=n(t.length,r);if(e.length<a)throw new Error("unpackedArray length ("+e.length+") must be >= "+a);for(var o=0,i=0;i<t.length;++i)e[o]=t[i],o+=r},r.FLOAT_MAX=2e4,r.FLOAT_MIN=-r.FLOAT_MAX;var s=(r.FLOAT_MAX-r.FLOAT_MIN)/255,u=[1,1/255,1/65025,1/16581375],c=[1,255,65025];r.BYTE_NAN_VALUE=0,r.encodeFloatArray=function(t){for(var e=new Uint8Array(4*t.length),n=0;n<e.length;n+=4)!function(n){var a=t[n/4];if(isNaN(a))return e[n]=r.BYTE_NAN_VALUE,e[n+1]=r.BYTE_NAN_VALUE,e[n+2]=r.BYTE_NAN_VALUE,e[n+3]=r.BYTE_NAN_VALUE,"continue";var o=(a-r.FLOAT_MIN)/s,i=c.map(function(t){return t*o}).map(function(t){return Math.floor(t%1*255)});e[n]=Math.floor(o),e[n+1]=i[0],e[n+2]=i[1],e[n+3]=i[2]}(n);return e},r.decodeToFloatArray=function(t){for(var e=new Float32Array(t.length/4),n=0;n<t.length;n+=4)!function(n){if(t[n]===r.BYTE_NAN_VALUE&&t[n+1]===r.BYTE_NAN_VALUE&&t[n+2]===r.BYTE_NAN_VALUE&&t[n+3]===r.BYTE_NAN_VALUE)return e[n/4]=NaN,"continue";var a=0;u.forEach(function(e,r){a+=e*t[n+r]});var o=a*s+r.FLOAT_MIN;e[n/4]=o}(n);return e},r.decodeMatrixFromUnpackedArray=function(t,e,r){var n=a(t.length,r);if(e.length<n)throw new Error("matrix length ("+e.length+") must be >= "+n);for(var o=0,i=0;i<t.length;i+=r)e[o++]=t[i]},r.decodeMatrixFromUnpackedColorRGBAArray=function(t,e,r){var n=t.length*r/4;if(e.length<n)throw new Error("matrix length ("+e.length+") must be >= "+n);for(var a=0,o=0;o<t.length;o+=4)for(var i=0;i<r;i++)e[a++]=t[o+i]},r.getPackedMatrixTextureShapeWidthHeight=o,r.getPackedRGBAArraySizeFromMatrixShape=i,r.encodeMatrixToPackedRGBA=function(t,e,r,n){var a=i(e,r);if(n.length<a)throw new Error("packedRGBA length ("+n.length+") must be >= "+a);for(var s=o(e,r),u=s[0],c=s[1],p=r%2==1,l=e%2==1,h=Math.floor(r/2),f=Math.floor(e/2),d=p?4:0,v=r,m=0,y=0;y<f;++y){for(var g=2*y*r,x=0;x<h;++x)w=g+2*x,n[m]=t[w],n[m+1]=t[w+1],n[m+2]=t[w+v],n[m+3]=t[w+v+1],m+=4;m+=d}if(p)for(var w=r-1,m=4*(u-1),b=2*r,d=4*u,y=0;y<f;++y)n[m]=t[w],n[m+2]=t[w+r],w+=b,m+=d;if(l)for(var w=(e-1)*r,m=(c-1)*u*4,x=0;x<h;++x)n[m++]=t[w++],n[m++]=t[w++],m+=2;return p&&l&&(n[n.length-4]=t[t.length-1]),n},r.decodeMatrixFromPackedRGBA=function(t,e,r,n){var a=e*r;if(a<n.length)throw new Error("matrix length ("+n.length+") must be >= "+a);for(var i=r%2==1,s=e%2==1,u=Math.floor(r/2),c=Math.floor(e/2),p=o(e,r),l=p[0],h=p[1],f=i?4:0,d=r+(i?1:0),v=0,m=0,y=r,g=0;g<c;++g){for(w=0;w<u;++w)n[m++]=t[v++],n[m++]=t[v++],n[y++]=t[v++],n[y++]=t[v++];v+=f,m+=d,y+=d}if(i)for(var v=4*(l-1),x=r-1,f=4*l,d=2*r,g=0;g<c;++g)n[x]=t[v],n[x+r]=t[v+2],v+=f,x+=d;if(s)for(var v=(h-1)*l*4,x=(e-1)*r,w=0;w<u;++w)n[x++]=t[v++],n[x++]=t[v++],v+=2;return i&&s&&(n[n.length-1]=t[t.length-4]),n}},{}],90:[function(t,e,r){"use strict";function n(t){return t[0]+"_"+t[1]}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function t(t){this.gpgpu=t,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextureCount={}}return t.prototype.acquireTexture=function(t){var e=n(t);return e in this.freeTextures||(this.freeTextures[e]=[]),e in this.usedTextureCount||(this.usedTextureCount[e]=0),this.usedTextureCount[e]++,this.freeTextures[e].length>0?(this.numFreeTextures--,this.numUsedTextures++,this.log(),this.freeTextures[e].shift()):(this.numUsedTextures++,this.log(),this.gpgpu.createMatrixTexture(t[0],t[1]))},t.prototype.releaseTexture=function(t,e){var r=n(e);r in this.freeTextures||(this.freeTextures[r]=[]),this.freeTextures[r].push(t),this.numFreeTextures++,this.numUsedTextures--,this.usedTextureCount[r]--,this.log()},t.prototype.log=function(){if(this.logEnabled){var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")")}},t.prototype.getNumUsedTextures=function(){return this.numUsedTextures},t.prototype.getNumFreeTextures=function(){return this.numFreeTextures},t.prototype.dispose=function(){for(var t in this.freeTextures)if(this.freeTextures.hasOwnProperty(t))for(var e=0;e<this.freeTextures[t].length;e++)this.gpgpu.deleteMatrixTexture(this.freeTextures[t][e])},t}();r.TextureManager=a},{}],91:[function(t,e,r){"use strict";function n(t){var e=t.length;if(e>4)throw Error("Tile for rank "+e+" is not yet supported");if(1===e)return"imod(resRC, "+t[0]+")";for(var r=["resRC.x","resRC.y","resRC.z","resRC.w"],n=[],a=0;a<t.length;a++)n.push("imod("+r[a]+", "+t[a]+")");return n.join()}Object.defineProperty(r,"__esModule",{value:!0});var a=t("./shader_compiler"),o=function(){return function(t,e){this.variableNames=["A"];for(var r=new Array(t.length),o=0;o<r.length;o++)r[o]=t[o]*e[o];this.outputShape=r,this.rank=r.length;var i=a.getCoordsDataType(this.rank),s=n(t);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+s+"));\n }\n "}}();r.TileProgram=o},{"./shader_compiler":87}],92:[function(t,e,r){"use strict";function n(t){var e=t.length;if(e>4)throw Error("Transpose for rank "+e+" is not yet supported");for(var r=["resRC.x","resRC.y","resRC.z","resRC.w"],n=new Array(e),a=0;a<t.length;a++)n[t[a]]=r[a];return n.join()}Object.defineProperty(r,"__esModule",{value:!0});var a=t("./shader_compiler"),o=function(){return function(t,e){this.variableNames=["A"];for(var r=new Array(t.length),o=0;o<r.length;o++)r[o]=t[e[o]];this.outputShape=r,this.rank=r.length;var i=a.getCoordsDataType(this.rank),s=n(e);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+s+"));\n }\n "}}();r.TransposeProgram=o},{"./shader_compiler":87}],93:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(t,e){this.variableNames=["A"],this.outputShape=t,this.userCode="\n float unaryOperation(float x) {\n "+e+"\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "}}();r.UnaryOpProgram=n,r.CHECK_NAN_SNIPPET="\n if (isNaN(x)) {\n return x;\n }\n",r.ABS="\n return abs(x);\n",r.RELU="\n return (x < 0.0) ? 0.0 : x;\n",r.ELU="\n return (x >= 0.0) ? x : (exp(x) - 1.0);\n",r.LEAKY_RELU=function(t){return"\n return (x >= 0.0) ? x : "+t+" * x;\n "},r.STEP=function(t){return void 0===t&&(t=0),"\n return (x == x) ? (x > 0.0 ? 1.0 : float("+t+")) : x;\n "},r.NEG="\n return -x;\n",r.CEIL="\n return ceil(x);\n",r.FLOOR="\n return floor(x);\n",r.EXP="\n return exp(x);\n",r.LOG="\n return log(x);\n",r.SQRT=r.CHECK_NAN_SNIPPET+"\n return sqrt(x);\n",r.SIGMOID="\n return 1.0 / (1.0 + exp(-1.0 * x));\n",r.SIN=r.CHECK_NAN_SNIPPET+"\n return sin(x);\n",r.COS=r.CHECK_NAN_SNIPPET+"\n return cos(x);\n",r.TAN="\n return tan(x);\n",r.ASIN=r.CHECK_NAN_SNIPPET+"\n return asin(x);\n",r.ACOS=r.CHECK_NAN_SNIPPET+"\n return acos(x);\n",r.ATAN=r.CHECK_NAN_SNIPPET+"\n return atan(x);\n",r.SINH="\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n",r.COSH="\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n",r.TANH="\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n",r.SQUARE="\n return x * x;\n"},{}],94:[function(t,e,r){"use strict";function n(t,e){var r,n=v.ENV.get("WEBGL_VERSION");if(2===n?r=t.getContext("webgl2",e):1===n&&(r=t.getContext("webgl",e)||t.getContext("experimental-webgl",e)),0===n||null==r)throw new Error("This browser does not support WebGL.");return r}function a(t,e){var r=e();return o(t),r}function o(t){if(m){var e=t.getError();if(e!==t.NO_ERROR)throw new Error("WebGL Error: "+i(t,e))}}function i(t,e){switch(e){case t.NO_ERROR:return"NO_ERROR";case t.INVALID_ENUM:return"INVALID_ENUM";case t.INVALID_VALUE:return"INVALID_VALUE";case t.INVALID_OPERATION:return"INVALID_OPERATION";case t.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case t.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case t.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+e}}function s(t,e){var r=y.exec(e);if(null==r)return console.log("Couldn't parse line number in error: "+e),void console.log(t);for(var n=+r[1],a=t.split("\n"),o=a.length.toString().length+2,i=a.map(function(t,e){return d.rightPad((e+1).toString(),o)+t}),s=0,u=0;u<i.length;u++)s=Math.max(i[u].length,s);var c=i.slice(0,n-1),p=i.slice(n-1,n),l=i.slice(n);console.log(c.join("\n")),console.log(e.split("\n")[0]),console.log("%c "+d.rightPad(p[0],s),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(l.join("\n"))}function u(t){return null!=f?f:f=a(t,function(){return t.getParameter(t.MAX_TEXTURE_SIZE)})}function c(t,e,r){h(t,r),a(t,function(){return t.activeTexture(t.TEXTURE0+r)}),a(t,function(){return t.bindTexture(t.TEXTURE_2D,e)})}function p(t,e){switch(e){case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case t.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+e}}function l(t,e,r){var n=a(t,function(){return e()});if(null==n)throw new Error(r);return n}function h(t,e){var r=t.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,n=e+t.TEXTURE0;if(n<t.TEXTURE0||n>r){var a="[gl.TEXTURE0, gl.TEXTURE"+r+"]";throw new Error("textureUnit must be in "+a+".")}}Object.defineProperty(r,"__esModule",{value:!0});var f=null,d=t("../../util"),v=t("../../environment");r.createWebGLRenderingContext=function(t){var e=document.createElement("canvas");return e.width=1,e.height=1,n(e,t)},r.createWebGLRenderingContextFromCanvas=n,r.callAndCheck=a;var m=!1;r.enableDebugWebGLErrorChecking=function(t){m=t},r.checkWebGLError=o,r.getWebGLErrorMessage=i,r.getExtensionOrThrow=function(t,e){return l(t,function(){return t.getExtension(e)},'Extension "'+e+'" not supported on this browser.')},r.createVertexShader=function(t,e){var r=l(t,function(){return t.createShader(t.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(a(t,function(){return t.shaderSource(r,e)}),a(t,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw console.log(t.getShaderInfoLog(r)),new Error("Failed to compile vertex shader.");return r},r.createFragmentShader=function(t,e){var r=l(t,function(){return t.createShader(t.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(a(t,function(){return t.shaderSource(r,e)}),a(t,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw s(e,t.getShaderInfoLog(r)),new Error("Failed to compile fragment shader.");return r};var y=/ERROR: [0-9]+:([0-9]+):/g;r.createProgram=function(t){return l(t,function(){return t.createProgram()},"Unable to create WebGLProgram.")},r.linkProgram=function(t,e){if(a(t,function(){return t.linkProgram(e)}),!1===t.getProgramParameter(e,t.LINK_STATUS))throw console.log(t.getProgramInfoLog(e)),new Error("Failed to link vertex and fragment shaders.")},r.validateProgram=function(t,e){if(a(t,function(){return t.validateProgram(e)}),!1===t.getProgramParameter(e,t.VALIDATE_STATUS))throw console.log(t.getProgramInfoLog(e)),new Error("Shader program validation failed.")},r.createStaticVertexBuffer=function(t,e){var r=l(t,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return a(t,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),a(t,function(){return t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW)}),r},r.createStaticIndexBuffer=function(t,e){var r=l(t,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return a(t,function(){return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,r)}),a(t,function(){return t.bufferData(t.ELEMENT_ARRAY_BUFFER,e,t.STATIC_DRAW)}),r},r.queryMaxTextureSize=u,r.getChannelsPerTexture=function(){return v.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")&&2===v.ENV.get("WEBGL_VERSION")?1:4},r.createTexture=function(t){return l(t,function(){return t.createTexture()},"Unable to create WebGLTexture.")},r.validateTextureSize=function(t,e,r){var n=u(t);if(e<=0||r<=0)throw a="["+e+"x"+r+"]",new Error("Requested texture size "+a+" is invalid.");if(e>n||r>n){var a="["+e+"x"+r+"]",o="["+n+"x"+n+"]";throw new Error("Requested texture size "+a+" greater than WebGL maximum on this browser / GPU "+o+".")}},r.createFramebuffer=function(t){return l(t,function(){return t.createFramebuffer()},"Unable to create WebGLFramebuffer.")},r.bindVertexBufferToProgramAttribute=function(t,e,r,n,o,i,s,u){var c=-1;-1!==(c=null!=u&&r in u?u[r]:t.getAttribLocation(e,r))&&(a(t,function(){return t.bindBuffer(t.ARRAY_BUFFER,n)}),a(t,function(){return t.vertexAttribPointer(c,o,t.FLOAT,!1,i,s)}),a(t,function(){return t.enableVertexAttribArray(c)}))},r.bindTextureUnit=c,r.unbindTextureUnit=function(t,e){h(t,e),a(t,function(){return t.activeTexture(t.TEXTURE0+e)}),a(t,function(){return t.bindTexture(t.TEXTURE_2D,null)})},r.getProgramUniformLocationOrThrow=function(t,e,r){return l(t,function(){return t.getUniformLocation(e,r)},'uniform "'+r+'" not present in program.')},r.bindTextureToProgramUniformSampler=function(t,e,r,n,o){a(t,function(){return c(t,r,o)}),a(t,function(){return t.uniform1i(n,o)})},r.bindCanvasToFramebuffer=function(t){a(t,function(){return t.bindFramebuffer(t.FRAMEBUFFER,null)}),a(t,function(){return t.viewport(0,0,t.canvas.width,t.canvas.height)}),a(t,function(){return t.scissor(0,0,t.canvas.width,t.canvas.height)})},r.bindColorTextureToFramebuffer=function(t,e,r){a(t,function(){return t.bindFramebuffer(t.FRAMEBUFFER,r)}),a(t,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)})},r.unbindColorTextureFromFramebuffer=function(t,e){a(t,function(){return t.bindFramebuffer(t.FRAMEBUFFER,e)}),a(t,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,null,0)})},r.validateFramebuffer=function(t){var e=t.checkFramebufferStatus(t.FRAMEBUFFER);if(e!==t.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+p(t,e))},r.getFramebufferErrorMessage=p,r.getTextureShapeFromLogicalShape=function(t,e){2!==e.length&&(e=d.squeezeShape(e).newShape);var r=u(t),n=d.sizeFromShape(e);return e.length<=1&&n<=r?[n,1]:2===e.length&&e[0]<=r&&e[1]<=r?e:3===e.length&&e[0]<=r&&e[1]*e[2]<=r?[e[0],e[1]*e[2]]:4===e.length&&e[0]<=r&&e[1]*e[2]*e[3]<=r?[e[0],e[1]*e[2]*e[3]]:d.sizeToSquarishShape(n)}},{"../../environment":15,"../../util":96}],95:[function(t,e,r){"use strict";function n(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return e/t.length}function a(t,e){for(var r=0,n=0;n<t.length;n++){var a=t[n]-e;r+=a*a}return Math.sqrt(r/t.length)}function o(t){for(var e=n(t),r=t.length,a=0,o=0,i=0;i<r;i++){var s=t[i]-e;a+=Math.pow(s,2),o+=Math.pow(s,4)}return 1/r*o/Math.pow(1/r*a,2)-3}function i(t){for(var e=n(t),r=t.length,a=0,o=0,i=-1;++i<r;){var s=t[i]-e;a+=Math.pow(s,2),o+=Math.pow(s,3)}return 1/r*o/Math.pow(1/(r-1)*a,1.5)}function s(t,e,n){if(void 0===n&&(n=r.TEST_EPSILON),!u(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)}function u(t,e,r){return!(!isNaN(t)||!isNaN(e))||!(isNaN(t)||isNaN(e)||Math.abs(t-e)>r)}function c(t,e,r,n){null!=n?n.forEach(function(n){var a=t+" "+JSON.stringify(n);r(a,e,n)}):r(t,e)}function p(t,e,r,n){var a;l(t,e,n,function(){(a=r()).startScope()},function(){a.endScope(null),a.dispose()},function(t,e){y(t,function(){return e(a)})})}function l(t,e,r,n,a,o){void 0===o&&(o=y),describe(t,function(){beforeEach(function(){null!=r&&h.setEnvironment(new f.Environment(r)),null!=n&&n()}),afterEach(function(){null!=a&&a(),null!=r&&h.setEnvironment(new f.Environment)}),e.forEach(function(t){return t(o)})})}Object.defineProperty(r,"__esModule",{value:!0});var h=t("./environment"),f=t("./environment"),d=t("./math/math_cpu"),v=t("./math/math_gpu"),m=t("./util");r.TEST_EPSILON=.01,r.mean=n,r.standardDeviation=a,r.kurtosis=o,r.skewness=i,r.jarqueBeraNormalityTest=function(t){var e=i(t),r=o(t),n=t.length*(Math.pow(e,2)/6+Math.pow(r,2)/24);if(n>5.991)throw new Error("Invalid p-value for JB: "+n)},r.expectArrayInMeanStdRange=function(t,e,o,i){void 0===i&&(i=r.TEST_EPSILON);var u=n(t);s(u,e,i),s(a(t,u),o,i)},r.expectArraysClose=function(t,e,n){void 0===n&&(n=r.TEST_EPSILON);var a=t.constructor.name,o=e.constructor.name;if(a!==o)throw new Error("Arrays are of different type "+a+" vs "+o);if(t.length!==e.length)throw new Error("Matrices have different lengths ("+t.length+" vs "+e.length+").");for(var i=0;i<e.length;++i){var s=t[i],c=e[i];if(!u(s,c,n)){var p="actual["+i+"] === "+s,l="expected["+i+"] === "+c;throw new Error("Arrays differ: "+p+", "+l)}}},r.expectNumbersClose=s,r.expectValuesInRange=function(t,e,r){for(var n=0;n<t.length;n++)if(t[n]<e||t[n]>r)throw new Error("Value out of range:"+t[n]+" low: "+e+", high: "+r)},r.randomArrayInRange=function(t,e,r){for(var n=new Float32Array(t),a=r-e,o=0;o<t;++o)n[o]=Math.random()*a+e;return n},r.makeIdentity=function(t){for(var e=new Float32Array(t*t),r=0;r<t;++r)e[r*t+r]=1;return e},r.cpuMultiplyMatrix=function(t,e,r,n,a,o){for(var i=new Float32Array(e*o),s=0;s<e;++s)for(var u=s*r,c=s*o,p=0;p<o;++p){for(var l=0,h=0;h<r;++h)l+=t[u+h]*n[h*o+p];i[c+p]=l}return i},r.cpuDotProduct=function(t,e){if(t.length!==e.length)throw new Error("cpuDotProduct: incompatible vectors.");for(var r=0,n=0;n<t.length;++n)r+=t[n]*e[n];return r},r.describeMathCPU=function(t,e,r){c("math_cpu."+t,e,function(t,e,r){return p(t,e,function(){return new d.NDArrayMathCPU},r)},r)},r.describeMathGPU=function(t,e,r){c("math_gpu."+t,e,function(t,e,r){return p(t,e,function(){return new v.NDArrayMathGPU},r)},r)},r.describeCustom=function(t,e,r,n,a){c(t,[e],function(t,e,r){return l(t,e,r,n,a)},r)};var y=function(t,e){it(t,function(t){var r=e();r instanceof Promise?r.then(t,function(e){fail(e),t()}):t()})};r.executeMathTests=p,r.executeTests=l,r.assertIsNan=function(t,e){if(!m.isValNaN(t,e))throw new Error("Value "+t+" does not represent NaN for dtype "+e)}},{"./environment":15,"./math/math_cpu":61,"./math/math_gpu":62,"./util":96}],96:[function(t,e,r){"use strict";function n(t){for(var e=t.length,r=0,n=0;e>0;)n=Math.random()*e|0,r=t[--e],t[e]=t[n],t[n]=r}function a(t,e,r){void 0===t&&(t=0),void 0===e&&(e=1),void 0===r&&(r=!1);var n,o,i;do{i=(n=2*Math.random()-1)*n+(o=2*Math.random()-1)*o}while(i>1);var s=Math.sqrt(-2*Math.log(i)/i)*n;return r&&Math.abs(s)>2?a(t,e,!0):t+e*s}function o(t,e){if(!t)throw new Error(e)}function i(t,e){if(void 0===e&&(e=[]),Array.isArray(t))for(var r=0;r<t.length;++r)i(t[r],e);else e.push(t);return e}function s(t,e){if(t.length!==e.length)return!1;for(var r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}function u(t,e,r){t[decodeURIComponent(e)]=decodeURIComponent(r||"")}Object.defineProperty(r,"__esModule",{value:!0}),r.shuffle=n,r.clamp=function(t,e,r){return Math.max(t,Math.min(e,r))},r.randUniform=function(t,e){return Math.random()*(e-t)+t},r.randGauss=a,r.distSquared=function(t,e){for(var r=0,n=0;n<t.length;n++){var a=Number(t[n])-Number(e[n]);r+=a*a}return r},r.assert=o,r.assertShapesMatch=function(t,e,r){void 0===r&&(r=""),o(s(t,e),r+"Shapes "+t+" and "+e+" must match")},r.flatten=i,r.inferShape=function(t){for(var e=[];t instanceof Array;)e.push(t.length),t=t[0];return e},r.sizeFromShape=function(t){if(0===t.length)return 1;for(var e=t[0],r=1;r<t.length;r++)e*=t[r];return e},r.isScalarShape=function(t){return 0===t.length},r.arraysEqual=s,r.isInt=function(t){return t%1==0},r.tanh=function(t){if(null!=Math.tanh)return Math.tanh(t);if(t===1/0)return 1;if(t===-1/0)return-1;var e=Math.exp(2*t);return(e-1)/(e+1)},r.sizeToSquarishShape=function(t){for(var e=Math.floor(Math.sqrt(t));e>1;--e)if(t%e==0)return[e,t/e];return[1,t]},r.createShuffledIndices=function(t){for(var e=new Uint32Array(t),r=0;r<t;++r)e[r]=r;return n(e),e},r.rightPad=function(t,e){return e<=t.length?t:t+" ".repeat(e-t.length)},r.repeatedTry=function(t,e,r){return void 0===e&&(e=function(t){return 0}),new Promise(function(n,a){var o=0,i=function(){if(t())n();else{var s=e(++o);null!=r&&o>=r?a():setTimeout(i,s)}};setTimeout(i,0)})},r.getQueryParams=function(t){var e={};return t.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return u(e,r[0],r[1]),r.join("=")}),e},r.inferFromImplicitShape=function(t,e){for(var r=1,n=-1,a=0;a<t.length;++a)if(t[a]>0)r*=t[a];else if(-1===t[a]){if(-1!==n)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+n+" and dim "+a);n=a}else if(t[a]<=0)throw Error("Shapes can not be <= 0. Found "+t[a]+" at dim "+a);if(-1===n){if(e>0&&e!==r)throw Error("Size ("+e+") must match the product of shape "+t);return t}if(e%r!=0)throw Error("The implicit shape can't be a fractional number. Got "+e+" / "+r);var o=t.slice();return o[n]=e/r,o},r.NAN_INT32=1<<31,r.NAN_BOOL=255,r.NAN_FLOAT32=NaN,r.getNaN=function(t){if("float32"===t)return r.NAN_FLOAT32;if("int32"===t)return r.NAN_INT32;if("bool"===t)return r.NAN_BOOL;throw new Error("Unknown dtype "+t)},r.isValNaN=function(t,e){if("float32"===e)return isNaN(t);if("int32"===e)return t===r.NAN_INT32;if("bool"===e)return t===r.NAN_BOOL;throw new Error("Unknown dtype "+e)},r.squeezeShape=function(t){for(var e=[],r=[],n=0;n<t.length;++n)t[n]>1&&(e.push(t[n]),r.push(n));return{newShape:e,keptDims:r}}},{}],97:[function(t,e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});r.version="0.3.11"},{}]},{},[51])(51)}),this.dl=this.deeplearn;