!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tf=e()}}(function(){return function(){function e(t,n,r){function i(o,s){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return i(n||e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var a="function"==typeof require&&require,o=0;o=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("./doc"),a=function(){function e(){}return e.nextFrame=function(){return new Promise(function(e){return requestAnimationFrame(function(){return e()})})},r([i.doc({heading:"Performance",subheading:"Timing"})],e,"nextFrame",null),e}();n.BrowserUtil=a},{"./doc":3}],2:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.isMobile=function(){var e=navigator.userAgent||navigator.vendor||window.opera;return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4))}},{}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.doc=function(e){return function(){for(var e=[],t=0;t0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1] {...}) to avoid memory leaks.");return this.activeScope.keep.push(e),e},e.prototype.startScope=function(e,t){void 0===t&&(t=!1),t&&0===this.gradientScopeCount&&(this.activeTape=[]),t&&this.gradientScopeCount++;var n={keep:[],track:[]};e&&(n.name=e),this.scopeStack.push(n),this.activeScope=n},e.prototype.endScope=function(e,t){var n=this;void 0===t&&(t=!1),t&&0===--this.gradientScopeCount&&(this.activeTape=null);var r=this.activeScope.keep,i=p.extractTensorsFromContainer(e);r=r.concat(i);for(var a=0;a0,"gradients() received an empty list of xs."),o.tidy("gradients",function(){var a=e();p.assert(a instanceof c.Tensor,"The result y returned by f() must be a tensor.");var o=l.getFilteredNodesXToY(i.activeTape,t,a);if(!r&&0===o.length&&t.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");var u={};return u[a.id]=null==n?s.ones(a.shape):n,l.backpropagateGradients(u,o),{value:a,grads:t.map(function(e){return u[e.id]})}},!0)},e.prototype.customGrad=function(e){var t=this;return p.assert(p.isFunction(e),"The f passed in customGrad(f) must be a function."),function(){for(var n=[],r=0;r {op();...}); to avoid memory leaks.");return this.activeScope.track.push(e),e},e}();n.Engine=h},{"./environment":5,"./globals":6,"./ops/ops":63,"./profiler":84,"./tape":85,"./tensor":86,"./util":92}],5:[function(e,t,n){(function(t){"use strict";function r(e,t){return null!=e.getExtension(t)}function i(e){if(0===e)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var t=document.createElement("canvas");return 1===e?t.getContext("webgl")||t.getContext("experimental-webgl"):t.getContext("webgl2")}function a(e){if(null!=e){var t=e.getExtension("WEBGL_lose_context");if(null==t)throw new Error("Extension WEBGL_lose_context not supported on this browser.");t.loseContext()}}function o(e){var t=i(e);return null!=t&&(a(t),!0)}function s(e){if(0===e)return 0;var t,n=i(e);return t=r(n,"EXT_disjoint_timer_query_webgl2")&&2===e?2:r(n,"EXT_disjoint_timer_query")?1:0,null!=n&&a(n),t}function u(e){if(0===e)return!1;var t=i(e);if(1===e){if(!r(t,"OES_texture_float"))return!1}else if(!r(t,"EXT_color_buffer_float"))return!1;var n=t.createFramebuffer(),o=t.createTexture();t.bindTexture(t.TEXTURE_2D,o);var s=2===e?t.RGBA32F:t.RGBA;t.texImage2D(t.TEXTURE_2D,0,s,1,1,0,t.RGBA,t.FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,n),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,o,0);var u=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;t.readPixels(0,0,1,1,t.RGBA,t.FLOAT,new Float32Array(4));var l=t.getError()===t.NO_ERROR;return a(t),u&&l}function l(e){if(e>0)return!1;if(2!==e)return!1;var t=i(e),n=r(t,"WEBGL_get_buffer_sub_data_async");return a(t),n}function c(){var e={};if("undefined"==typeof window)return e;var t=v.getQueryParams(window.location.search);if(w in t){var r={};t[w].split(",").forEach(function(e){var t=e.split(":"),n=t[0],i=t[1];r[n]=i}),n.URL_PROPERTIES.forEach(function(t){t.name in r&&(console.log("Setting feature override from URL "+t.name+": "+r[t.name]),t.type===d.NUMBER?e[t.name]=+r[t.name]:t.type===d.BOOLEAN?e[t.name]="true"===r[t.name]:t.type===d.STRING?e[t.name]=r[t.name]:console.warn("Unknown URL param: "+t.name+"."))})}return e}function p(){var e;if("undefined"!=typeof window)e=window;else{if(void 0===t)throw new Error("Could not find a global object");e=t}return e}var h=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var d,f=e("./device_util"),g=e("./doc"),m=e("./engine"),v=e("./util");!function(e){e[e.NUMBER=0]="NUMBER",e[e.BOOLEAN=1]="BOOLEAN",e[e.STRING=2]="STRING"}(d=n.Type||(n.Type={})),n.URL_PROPERTIES=[{name:"DEBUG",type:d.BOOLEAN},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",type:d.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:d.BOOLEAN},{name:"WEBGL_VERSION",type:d.NUMBER},{name:"WEBGL_FLOAT_TEXTURE_ENABLED",type:d.BOOLEAN},{name:"WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED",type:d.BOOLEAN},{name:"BACKEND",type:d.STRING}];var y=["webgl","cpu"],b=function(){function e(e){this.features={},this.BACKEND_REGISTRY={},this.backends=this.BACKEND_REGISTRY,null!=e&&(this.features=e),this.get("DEBUG")&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")}return e.setBackend=function(e,t){if(void 0===t&&(t=!1),!(e in n.ENV.backends))throw new Error("Backend type '"+e+"' not found in registry");n.ENV.initBackend(e,t)},e.getBackend=function(){return n.ENV.initDefaultBackend(),n.ENV.currentBackendType},e.memory=function(){return n.ENV.engine.memory()},e.prototype.get=function(e){return e in this.features?this.features[e]:(this.features[e]=this.evaluateFeature(e),this.features[e])},e.prototype.set=function(e,t){this.features[e]=t},e.prototype.getBestBackendType=function(){for(var e=0;e0&&!f.isMobile();if("WEBGL_VERSION"===e)return o(2)?2:o(1)?1:0;if("WEBGL_FLOAT_TEXTURE_ENABLED"===e)return u(this.get("WEBGL_VERSION"));if("WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED"===e)return l(this.get("WEBGL_VERSION"));throw new Error("Unknown feature "+e+".")},e.prototype.setFeatures=function(e){this.reset(),this.features=e,this.backends={}},e.prototype.reset=function(){if(this.features=c(),null!=this.globalEngine&&(this.globalEngine.dispose(),this.globalEngine=null),this.backends!==this.BACKEND_REGISTRY){for(var e in this.backends)this.backends[e].dispose();this.backends=this.BACKEND_REGISTRY}},e.prototype.initBackend=function(e,t){void 0===t&&(t=!1);var r=!1;"string"==typeof e?(this.currentBackendType=e,e=n.ENV.findBackend(e)):(r=!0,this.currentBackendType="custom"),this.globalEngine=new m.Engine(e,r,t)},e.prototype.findBackend=function(e){return this.backends[e]},e.prototype.addCustomBackend=function(e,t){if(e in this.backends)throw new Error(e+" backend was already registered");try{var n=t();return this.backends[e]=n,!0}catch(e){return!1}},e.prototype.registerBackend=function(e,t){if(e in this.BACKEND_REGISTRY)throw new Error(e+" backend was already registered as global");try{var n=t();return this.BACKEND_REGISTRY[e]=n,!0}catch(e){return!1}},Object.defineProperty(e.prototype,"engine",{get:function(){return this.initDefaultBackend(),this.globalEngine},enumerable:!0,configurable:!0}),e.prototype.initDefaultBackend=function(){null==this.globalEngine&&this.initBackend(n.ENV.get("BACKEND"),!1)},h([g.doc({heading:"Environment"})],e,"setBackend",null),h([g.doc({heading:"Environment"})],e,"getBackend",null),h([g.doc({heading:"Performance",subheading:"Memory"})],e,"memory",null),e}();n.Environment=b;var w="dljsflags";n.ENV=function(){var e=p();return e.ENV=e.ENV||new b(c()),e.ENV}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./device_util":2,"./doc":3,"./engine":4,"./util":92}],6:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./gradients"),i=e("./tracking");n.tidy=i.Tracking.tidy,n.keep=i.Tracking.keep,n.dispose=i.Tracking.dispose,n.time=i.Tracking.time,n.grad=r.Gradients.grad,n.valueAndGrad=r.Gradients.valueAndGrad,n.grads=r.Gradients.grads,n.valueAndGrads=r.Gradients.valueAndGrads,n.variableGrads=r.Gradients.variableGrads,n.customGrad=r.Gradients.customGrad},{"./gradients":7,"./tracking":89}],7:[function(e,t,n){"use strict";function r(e){if(e.filter(function(e){return null==e}).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.")}var i=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var a=e("./doc"),o=e("./environment"),s=e("./globals"),u=e("./tensor"),l=e("./util"),c=function(){function e(){}return e.gradScope=function(e,t){return s.tidy(e,t,!0)},e.grad=function(e){return l.assert(l.isFunction(e),"The f passed in grad(f) must be a function"),function(t,n){l.assert(t instanceof u.Tensor,"The x passed in grad(f)(x) must be a tensor"),l.assert(null==n||n instanceof u.Tensor,"The dy passed in grad(f)(x, dy) must be a tensor");var i=o.ENV.engine.gradients(function(){return e(t)},[t],n),a=i.value,s=i.grads;return null!=n&&l.assertShapesMatch(a.shape,n.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),a.dispose(),r(s),s[0]}},e.grads=function(e){return l.assert(l.isFunction(e),"The f passed in grads(f) must be a function"),function(t,n){l.assert(Array.isArray(t)&&t.every(function(e){return e instanceof u.Tensor}),"The args passed in grads(f)(args) must be an array of tensors"),l.assert(null==n||n instanceof u.Tensor,"The dy passed in grads(f)(args, dy) must be a tensor");var i=o.ENV.engine.gradients(function(){return e.apply(void 0,t)},t,n),a=i.value,s=i.grads;return null!=n&&l.assertShapesMatch(a.shape,n.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),a.dispose(),r(s),s}},e.valueAndGrad=function(e){return l.assert(l.isFunction(e),"The f passed in valueAndGrad(f) must be a function"),function(t,n){l.assert(t instanceof u.Tensor,"The x passed in valueAndGrad(f)(x) must be a tensor"),l.assert(null==n||n instanceof u.Tensor,"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");var i=o.ENV.engine.gradients(function(){return e(t)},[t],n),a=i.grads,s=i.value;return r(a),{grad:a[0],value:s}}},e.valueAndGrads=function(e){return l.assert(l.isFunction(e),"The f passed in valueAndGrads(f) must be a function"),function(t,n){l.assert(Array.isArray(t)&&t.every(function(e){return e instanceof u.Tensor}),"The args passed in valueAndGrads(f)(args) must be array of tensors"),l.assert(null==n||n instanceof u.Tensor,"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");var i=o.ENV.engine.gradients(function(){return e.apply(void 0,t)},t,n);return null!=n&&l.assertShapesMatch(i.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),r(i.grads),i}},e.variableGrads=function(e,t){if(l.assert(l.isFunction(e),"The f passed in variableGrads(f) must be a function"),l.assert(null==t||Array.isArray(t)&&t.every(function(e){return e instanceof u.Variable}),"The varList passed in variableGrads(f, varList) must be an array of variables"),null==t){t=[];for(var n in o.ENV.engine.registeredVariables)t.push(o.ENV.engine.registeredVariables[n])}var r=t.length;t=t.filter(function(e){return e.trainable}),l.assert(t.length>0,"variableGrads() expects at least one of the input variables to be trainable, but none of the "+r+" variables is trainable.");var i=o.ENV.engine.gradients(e,t,null,!0),a=i.value,s=i.grads;l.assert(s.some(function(e){return null!=e}),"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),l.assert(0===a.rank,"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+a.rank+" tensor");var c={};return t.forEach(function(e,t){null!=s[t]&&(c[e.name]=s[t])}),{value:a,grads:c}},e.customGrad=function(e){return o.ENV.engine.customGrad(e)},i([a.doc({heading:"Training",subheading:"Gradients"})],e,"grad",null),i([a.doc({heading:"Training",subheading:"Gradients"})],e,"grads",null),i([a.doc({heading:"Training",subheading:"Gradients"})],e,"valueAndGrad",null),i([a.doc({heading:"Training",subheading:"Gradients"})],e,"valueAndGrads",null),i([a.doc({heading:"Training",subheading:"Gradients"})],e,"variableGrads",null),i([a.doc({heading:"Training",subheading:"Gradients"})],e,"customGrad",null),e}();n.Gradients=c},{"./doc":3,"./environment":5,"./globals":6,"./tensor":86,"./util":92}],8:[function(e,t,n){"use strict";function r(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}Object.defineProperty(n,"__esModule",{value:!0});var i=e("./browser_util"),a=e("./environment");n.environment=a;var o=e("./environment"),s=e("./kernels/webgl/gpgpu_util"),u=e("./kernels/webgl/webgl_util"),l=e("./test_util");n.test_util=l;var c=e("./util");n.util=c;var p=e("./version");n.version_core=p.version;var h=e("./optimizers/adadelta_optimizer");n.AdadeltaOptimizer=h.AdadeltaOptimizer;var d=e("./optimizers/adagrad_optimizer");n.AdagradOptimizer=d.AdagradOptimizer;var f=e("./optimizers/adam_optimizer");n.AdamOptimizer=f.AdamOptimizer;var g=e("./optimizers/adamax_optimizer");n.AdamaxOptimizer=g.AdamaxOptimizer;var m=e("./optimizers/momentum_optimizer");n.MomentumOptimizer=m.MomentumOptimizer;var v=e("./optimizers/optimizer");n.Optimizer=v.Optimizer;var y=e("./optimizers/rmsprop_optimizer");n.RMSPropOptimizer=y.RMSPropOptimizer;var b=e("./optimizers/sgd_optimizer");n.SGDOptimizer=b.SGDOptimizer;var w=e("./tensor");n.Tensor=w.Tensor,n.TensorBuffer=w.TensorBuffer,n.variable=w.variable,n.Variable=w.Variable;var x=e("./types");n.Rank=x.Rank;var E=e("./weights_loader");n.loadWeights=E.loadWeights,r(e("./ops/ops"));var _=e("./ops/loss_ops");n.Reduction=_.Reduction,r(e("./train")),r(e("./globals"));var A=e("./environment");n.ENV=A.ENV,n.Environment=A.Environment,n.setBackend=o.Environment.setBackend,n.getBackend=o.Environment.getBackend,n.memory=o.Environment.memory;var S=e("./doc");n.doc=S.doc,n.nextFrame=i.BrowserUtil.nextFrame,n.webgl={webgl_util:u,gpgpu_util:s}},{"./browser_util":1,"./doc":3,"./environment":5,"./globals":6,"./kernels/webgl/gpgpu_util":25,"./kernels/webgl/webgl_util":44,"./ops/loss_ops":57,"./ops/ops":63,"./optimizers/adadelta_optimizer":75,"./optimizers/adagrad_optimizer":76,"./optimizers/adam_optimizer":77,"./optimizers/adamax_optimizer":78,"./optimizers/momentum_optimizer":79,"./optimizers/optimizer":80,"./optimizers/rmsprop_optimizer":82,"./optimizers/sgd_optimizer":83,"./tensor":86,"./test_util":88,"./train":90,"./types":91,"./util":92,"./version":93,"./weights_loader":94}],9:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,a){function o(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,s)}u((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(o=o.call(a,n[1])).done)return o;switch(a=0,o&&(n=[0,o.value]),n[0]){case 0:case 1:o=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]d&&(d=v,f=m)}u[p]=f}return a},e.prototype.equal=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(n,r){return g.isValNaN(n,e.dtype)||g.isValNaN(r,t.dtype)?g.getNaN("bool"):n===r?1:0})},e.prototype.notEqual=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(n,r){return g.isValNaN(n,e.dtype)||g.isValNaN(r,t.dtype)?g.getNaN("bool"):n!==r?1:0})},e.prototype.less=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(n,r){return g.isValNaN(n,e.dtype)||g.isValNaN(r,t.dtype)?g.getNaN("bool"):nr?1:0})},e.prototype.greaterEqual=function(e,t){return this.broadcastedBinaryOp(e,t,"bool",function(n,r){return g.isValNaN(n,e.dtype)||g.isValNaN(r,t.dtype)?g.getNaN("bool"):n>=r?1:0})},e.prototype.logicalNot=function(e){for(var t=e.dataSync(),n=new Int32Array(t.length),r=0;r1||1===t.rank?1:t.shape[1],h=0;h=0&&t>=0?n:(n+t)%t})},e.prototype.max=function(e,t){s.assertAxesAreInnerMostDims("max",t,e.rank);for(var n=s.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=c.zeros(r,e.dtype),o=g.sizeFromShape(i),u=a.dataSync(),l=e.dataSync(),p=0;pd&&(d=m)}u[p]=d}return a},e.prototype.maximum=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){return Math.max(e,t)})},e.prototype.squaredDifference=function(e,t){return this.broadcastedBinaryOp(e,t,e.dtype,function(e,t){var n=e-t;return n*n})},e.prototype.ceil=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r0?n[r]=1:n[r]=0;return d.Tensor.make(e.shape,{values:n})},e.prototype.round=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r.5?n[r]=Math.ceil(t[r]):n[r]=i%2==0?i:i+1}return d.Tensor.make(e.shape,{values:n})},e.prototype.exp=function(e){for(var t=e.dataSync(),n=new Float32Array(t.length),r=0;r=0?i:Math.exp(i)-1}return d.Tensor.make(e.shape,{values:t})},e.prototype.eluDer=function(e){for(var t=new Float32Array(e.size),n=e.dataSync(),r=0;r=0?1:Math.exp(i)}return d.Tensor.make(e.shape,{values:t})},e.prototype.selu=function(e){for(var t=h.SELU_SCALEALPHA,n=h.SELU_SCALE,r=new Float32Array(e.size),i=e.dataSync(),a=0;a=0?n*o:t*(Math.exp(o)-1)}return d.Tensor.make(e.shape,{values:r})},e.prototype.leakyRelu=function(e,t){for(var n=new Float32Array(e.size),r=e.dataSync(),i=0;i=0?a:t*a}return d.Tensor.make(e.shape,{values:n})},e.prototype.prelu=function(e,t){for(var n=new Float32Array(e.size),r=e.dataSync(),i=t.dataSync(),a=0;a=0?o:i[a]*o}return d.Tensor.make(e.shape,{values:n})},e.prototype.preluDer=function(e,t){for(var n=new Float32Array(e.size),r=e.dataSync(),i=t.dataSync(),a=0;a0?1:o<0?i[a]:o}return d.Tensor.make(e.shape,{values:n})},e.prototype.clip=function(e,t,n){for(var r=new Float32Array(e.size),i=e.dataSync(),a=0;a0?1:t}return d.Tensor.make(e.shape,{values:n})},e.prototype.conv2d=function(e,t,n){for(var r=n.filterHeight,i=n.filterWidth,a=n.dilationHeight,o=n.dilationWidth,s=n.padInfo.left,u=n.padInfo.top,l=c.buffer(n.outShape,e.dtype),p=0;p=n.inHeight))for(var w=0;w=n.inWidth))for(var E=0;E=n.inHeight))for(var E=0;E=n.inWidth||(b+=e.get(h,x,_,d)*t.get(w,E,d,y))}}p.set(b,h,f,m,d*l+y)}return p.toTensor()},e.prototype.tile=function(e,t){for(var n=new Array(e.rank),r=0;rx||"min"===n&&Sw&&(w=O,x=_*o+S)}n.set(x,l,h,m,p)}return n.toTensor()},e.prototype.maxPoolBackprop=function(e,t,n){for(var r=this.maxPoolPositions(t,n),i=n.strideHeight,a=n.strideWidth,o=n.filterHeight,s=n.filterWidth,u=s-1-n.padInfo.left,l=o-1-n.padInfo.top,p=c.buffer(t.shape,"float32"),h=0;h=n.outHeight||Math.floor(w)!==w))for(var x=0;x=n.outWidth||Math.floor(E)!==E)){var _=o*s-1-r.get(h,w,E,d)===b*s+x?1:0;0!==_&&(y+=e.get(h,w,E,d)*_)}}}p.set(y,h,f,g,d)}return p.toTensor()},e.prototype.avgPoolBackprop=function(e,t,n){for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s=o-1-n.padInfo.left,u=a-1-n.padInfo.top,l=c.buffer(t.shape,"float32"),p=1/(a*o),h=0;h=n.outHeight||Math.floor(w)!==w))for(var x=0;x=n.outWidth||Math.floor(E)!==E||(y+=e.get(h,w,E,d))}}l.set(y*p,h,f,g,d)}return l.toTensor()},e.prototype.cast=function(e,t){return m.castTensor(e,t,this)},e.prototype.reshape=function(e,t){return m.reshapeTensor(e,t)},e.prototype.minPool=function(e,t){return this.pool(e,t,"min")},e.prototype.avgPool=function(e,t){return this.pool(e,t,"avg").toFloat()},e.prototype.resizeBilinear=function(e,t,n,r){for(var i=e.shape,a=i[0],o=i[1],s=i[2],u=i[3],l=c.buffer([a,t,n,u],e.dtype),p=r?[o-1,s-1]:[o,s],h=r?[t-1,n-1]:[t,n],d=0;d0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]0?this.gpgpu.beginQuery():{startMs:performance.now(),endMs:null}},e.prototype.endTimer=function(e){return s.ENV.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(this.gpgpu.endQuery(),e):(e.endMs=performance.now(),e)},e.prototype.getQueryTime=function(e){return a(this,void 0,void 0,function(){var t;return o(this,function(n){return s.ENV.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?[2,this.gpgpu.pollQueryTime(e)]:(t=e,[2,t.endMs-t.startMs])})})},e.prototype.disposeData=function(e){if(this.texData.has(e)){var t=this.texData.get(e),n=t.texture,r=t.texShape,i=t.texType;null!=n&&this.textureManager.releaseTexture(n,r,i),this.texData.delete(e)}},e.prototype.getTexture=function(e){return this.uploadToGPU(e),this.texData.get(e).texture},e.prototype.getTextureData=function(e){return this.uploadToGPU(e),this.texData.get(e)},e.prototype.getGPGPUContext=function(){return this.gpgpu},e.prototype.slice=function(e,t,n){var r=new V.SliceProgram(n),i=r.getCustomSetupFunc(t);return this.compileAndRun(r,[e],null,i)},e.prototype.reverse=function(e,t){var n=new F.ReverseProgram(e.shape,t);return this.compileAndRun(n,[e])},e.prototype.concat=function(e,t){var n=new w.ConcatProgram(e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.neg=function(e){var t=new q.UnaryOpProgram(e.shape,W.NEG);return this.compileAndRun(t,[e])},e.prototype.matMul=function(e,t,n,r){var i=new R.MatMulProgram(e.shape,t.shape,n,r);return this.compileAndRun(i,[e,t])},e.prototype.multiply=function(e,t){var n=new y.BinaryOpProgram(v.MUL,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,p.upcastType(e.dtype,t.dtype));return this.compileAndRun(n,[e,t],r)},e.prototype.batchNormalization4D=function(e,t,n,r,i,a){var o=[e,t,n],s=null;null!=a&&(s=a.shape,o.push(a));var u=null;null!=i&&(u=i.shape,o.push(i));var l=new m.BatchNormProgram(e.shape,t.shape,n.shape,s,u,r);return this.compileAndRun(l,o)},e.prototype.localResponseNormalization4D=function(e,t,n,r,i,a){var o=new C.LRNProgram(e.shape,t,n,r,i,a);return this.compileAndRun(o,[e])},e.prototype.tile=function(e,t){var n=new U.TileProgram(e.shape,t);return this.compileAndRun(n,[e])},e.prototype.pad=function(e,t,n){var r=new M.PadProgram(e.shape,t,n);return this.compileAndRun(r,[e])},e.prototype.transpose=function(e,t){var n=new G.TransposeProgram(e.shape,t);return this.compileAndRun(n,[e])},e.prototype.gather=function(e,t,n){var r=new S.GatherProgram(e.shape,t.size,n);return this.compileAndRun(r,[e,t])},e.prototype.reduce=function(e,t,n){var r=e.shape[0],i=e.shape[1],a={windowSize:l.computeOptimalWindowSize(i),inSize:i,batchSize:r},o=new L.ReduceProgram(a,t),s=o.outputShape,u=s[0],c=s[1],p=this.makeOutputArray([u,c],n);return this.compileAndRun(o,[e],p),1===p.shape[1]?p:this.reduce(p,t,n)},e.prototype.argReduce=function(e,t,n){void 0===n&&(n=null);var r=e.shape[0],i=e.shape[1];null!=n&&(r=n.shape[0],i=n.shape[1]);var a={windowSize:l.computeOptimalWindowSize(i),inSize:i,batchSize:r},o=new f.ArgMinMaxProgram(a,t,null==n),s=o.outputShape,u=s[0],c=s[1],p=this.makeOutputArray([u,c],"int32"),h=[e];return null!=n&&h.push(n),this.compileAndRun(o,h,p),1===p.shape[1]?p:this.argReduce(e,t,p)},e.prototype.sum=function(e,t){u.assertAxesAreInnerMostDims("sum",t,e.rank);var n=u.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=h.sizeFromShape(i),o=e.as2D(-1,a),s=p.sumOutType(e.dtype);return this.reduce(o,"sum",s).reshape(r)},e.prototype.argMin=function(e,t){u.assertAxesAreInnerMostDims("argMin",t,e.rank);var n=u.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=h.sizeFromShape(i),o=e.as2D(-1,a);return this.argReduce(o,"min").reshape(r)},e.prototype.argMax=function(e,t){u.assertAxesAreInnerMostDims("argMax",t,e.rank);var n=u.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=h.sizeFromShape(i),o=e.as2D(-1,a);return this.argReduce(o,"max").reshape(r)},e.prototype.equal=function(e,t){var n=new y.BinaryOpProgram(v.EQUAL,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.notEqual=function(e,t){var n=new y.BinaryOpProgram(v.NOT_EQUAL,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.less=function(e,t){var n=new y.BinaryOpProgram(v.LESS,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.lessEqual=function(e,t){var n=new y.BinaryOpProgram(v.LESS_EQUAL,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.greater=function(e,t){var n=new y.BinaryOpProgram(v.GREATER,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.greaterEqual=function(e,t){var n=new y.BinaryOpProgram(v.GREATER_EQUAL,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.logicalNot=function(e){var t=new q.UnaryOpProgram(e.shape,W.LOGICAL_NOT);return this.compileAndRun(t,[e])},e.prototype.logicalAnd=function(e,t){var n=new y.BinaryOpProgram(v.LOGICAL_AND,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.logicalOr=function(e,t){var n=new y.BinaryOpProgram(v.LOGICAL_OR,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.logicalXor=function(e,t){var n=new y.BinaryOpProgram(v.LOGICAL_XOR,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[e,t],r)},e.prototype.where=function(e,t,n,r){var i=new k.WhereProgram(e.rank,t.shape,t.rank),a=this.makeOutputArray(i.outputShape,r);return this.compileAndRun(i,[e,t,n],a)},e.prototype.topKValues=function(e,t){throw new Error("topKValues GPU not yet implemented!")},e.prototype.topKIndices=function(e,t){throw new Error("topKIndices GPU not yet implemented!")},e.prototype.min=function(e,t){u.assertAxesAreInnerMostDims("min",t,e.rank);var n=u.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=h.sizeFromShape(i),o=e.as2D(-1,a);return this.reduce(o,"min",o.dtype).reshape(r)},e.prototype.minimum=function(e,t){var n=new y.BinaryOpProgram(v.MIN,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.mod=function(e,t){var n=new y.BinaryOpProgram(v.MOD,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.max=function(e,t){u.assertAxesAreInnerMostDims("max",t,e.rank);var n=u.computeOutAndReduceShapes(e.shape,t),r=n[0],i=n[1],a=h.sizeFromShape(i),o=e.as2D(-1,a);return this.reduce(o,"max",o.dtype).reshape(r)},e.prototype.maximum=function(e,t){var n=new y.BinaryOpProgram(v.MAX,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.squaredDifference=function(e,t){var n=new y.BinaryOpProgram(v.SQUARED_DIFFERENCE,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.divide=function(e,t){var n=new y.BinaryOpProgram(v.DIV,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,"float32");return this.compileAndRun(n,[e,t],r)},e.prototype.add=function(e,t){var n=new y.BinaryOpProgram(v.ADD,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,p.upcastType(e.dtype,t.dtype));return this.compileAndRun(n,[e,t],r)},e.prototype.subtract=function(e,t){var n=new y.BinaryOpProgram(v.SUB,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,p.upcastType(e.dtype,t.dtype));return this.compileAndRun(n,[e,t],r)},e.prototype.pow=function(e,t){var n=new y.BinaryOpProgram(v.POW,e.shape,t.shape),r=this.makeOutputArray(n.outputShape,p.upcastType(e.dtype,t.dtype));return this.compileAndRun(n,[e,t],r)},e.prototype.ceil=function(e){var t=new q.UnaryOpProgram(e.shape,W.CEIL);return this.compileAndRun(t,[e])},e.prototype.floor=function(e){var t=new q.UnaryOpProgram(e.shape,W.FLOOR);return this.compileAndRun(t,[e])},e.prototype.sign=function(e){var t=new q.UnaryOpProgram(e.shape,W.SIGN);return this.compileAndRun(t,[e])},e.prototype.round=function(e){var t=new q.UnaryOpProgram(e.shape,W.ROUND);return this.compileAndRun(t,[e])},e.prototype.exp=function(e){var t=new q.UnaryOpProgram(e.shape,W.EXP);return this.compileAndRun(t,[e])},e.prototype.expm1=function(e){var t=new q.UnaryOpProgram(e.shape,W.EXPM1);return this.compileAndRun(t,[e])},e.prototype.log=function(e){var t=new q.UnaryOpProgram(e.shape,W.LOG);return this.compileAndRun(t,[e])},e.prototype.log1p=function(e){var t=new q.UnaryOpProgram(e.shape,W.LOG1P);return this.compileAndRun(t,[e])},e.prototype.sqrt=function(e){var t=new q.UnaryOpProgram(e.shape,W.SQRT);return this.compileAndRun(t,[e])},e.prototype.rsqrt=function(e){var t=new q.UnaryOpProgram(e.shape,W.RSQRT);return this.compileAndRun(t,[e])},e.prototype.square=function(e){var t=new q.UnaryOpProgram(e.shape,W.SQUARE);return this.compileAndRun(t,[e])},e.prototype.reciprocal=function(e){var t=new q.UnaryOpProgram(e.shape,W.RECIPROCAL);return this.compileAndRun(t,[e])},e.prototype.relu=function(e){var t=new q.UnaryOpProgram(e.shape,W.RELU);return this.compileAndRun(t,[e])},e.prototype.elu=function(e){var t=new q.UnaryOpProgram(e.shape,W.ELU);return this.compileAndRun(t,[e])},e.prototype.eluDer=function(e){var t=new q.UnaryOpProgram(e.shape,W.ELU_DER);return this.compileAndRun(t,[e])},e.prototype.selu=function(e){var t=new q.UnaryOpProgram(e.shape,W.SELU);return this.compileAndRun(t,[e])},e.prototype.leakyRelu=function(e,t){var n=new q.UnaryOpProgram(e.shape,W.LEAKY_RELU(t));return this.compileAndRun(n,[e])},e.prototype.prelu=function(e,t){var n=new y.BinaryOpProgram(v.PRELU,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.preluDer=function(e,t){var n=new y.BinaryOpProgram(v.PRELU_DER,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.int=function(e){var t=new q.UnaryOpProgram(e.shape,W.TO_INT),n=this.makeOutputArray(t.outputShape,"int32");return this.compileAndRun(t,[e],n)},e.prototype.clip=function(e,t,n){var r=new b.ClipProgram(e.shape,t,n);return this.compileAndRun(r,[e])},e.prototype.abs=function(e){var t=new q.UnaryOpProgram(e.shape,W.ABS);return this.compileAndRun(t,[e])},e.prototype.sigmoid=function(e){var t=new q.UnaryOpProgram(e.shape,W.SIGMOID);return this.compileAndRun(t,[e])},e.prototype.sin=function(e){var t=new q.UnaryOpProgram(e.shape,W.SIN);return this.compileAndRun(t,[e])},e.prototype.cos=function(e){var t=new q.UnaryOpProgram(e.shape,W.COS);return this.compileAndRun(t,[e])},e.prototype.tan=function(e){var t=new q.UnaryOpProgram(e.shape,W.TAN);return this.compileAndRun(t,[e])},e.prototype.asin=function(e){var t=new q.UnaryOpProgram(e.shape,W.ASIN);return this.compileAndRun(t,[e])},e.prototype.acos=function(e){var t=new q.UnaryOpProgram(e.shape,W.ACOS);return this.compileAndRun(t,[e])},e.prototype.atan=function(e){var t=new q.UnaryOpProgram(e.shape,W.ATAN);return this.compileAndRun(t,[e])},e.prototype.atan2=function(e,t){var n=new y.BinaryOpProgram(v.ATAN2,e.shape,t.shape);return this.compileAndRun(n,[e,t])},e.prototype.sinh=function(e){var t=new q.UnaryOpProgram(e.shape,W.SINH);return this.compileAndRun(t,[e])},e.prototype.cosh=function(e){var t=new q.UnaryOpProgram(e.shape,W.COSH);return this.compileAndRun(t,[e])},e.prototype.tanh=function(e){var t=new q.UnaryOpProgram(e.shape,W.TANH);return this.compileAndRun(t,[e])},e.prototype.asinh=function(e){var t=new q.UnaryOpProgram(e.shape,W.ASINH);return this.compileAndRun(t,[e])},e.prototype.acosh=function(e){var t=new q.UnaryOpProgram(e.shape,W.ACOSH);return this.compileAndRun(t,[e])},e.prototype.atanh=function(e){var t=new q.UnaryOpProgram(e.shape,W.ATANH);return this.compileAndRun(t,[e])},e.prototype.step=function(e,t){var n=new q.UnaryOpProgram(e.shape,W.STEP(t));return this.compileAndRun(n,[e])},e.prototype.conv2d=function(e,t,n){var r=new E.Conv2DProgram(n);return this.compileAndRun(r,[e,t])},e.prototype.conv2dDerInput=function(e,t,n){var r=new x.Conv2DDerInputProgram(n);return this.compileAndRun(r,[e,t])},e.prototype.conv2dDerFilter=function(e,t,n){var r=new x.Conv2DDerFilterProgram(n);return this.compileAndRun(r,[e,t])},e.prototype.depthwiseConv2D=function(e,t,n){var r=new _.DepthwiseConv2DProgram(n);return this.compileAndRun(r,[e,t])},e.prototype.maxPool=function(e,t){var n=new D.Pool2DProgram(t,"max",!1),r=this.makeOutputArray(n.outputShape,e.dtype);return this.compileAndRun(n,[e],r)},e.prototype.minPool=function(e,t){var n=new D.Pool2DProgram(t,"min",!1),r=this.makeOutputArray(n.outputShape,e.dtype);return this.compileAndRun(n,[e],r)},e.prototype.avgPool=function(e,t){var n=new D.Pool2DProgram(t,"avg",!1),r=this.makeOutputArray(n.outputShape,"float32");return this.compileAndRun(n,[e],r)},e.prototype.maxPoolBackprop=function(e,t,n){var r=new D.Pool2DProgram(n,"max",!0),i=this.compileAndRun(r,[t]),a=new N.MaxPool2DBackpropProgram(n),o=this.makeOutputArray(a.outputShape,t.dtype),s=this.compileAndRun(a,[e,i],o);return i.dispose(),s},e.prototype.avgPoolBackprop=function(e,t,n){var r=new g.AvgPool2DBackpropProgram(n),i=this.makeOutputArray(r.outputShape,t.dtype);return this.compileAndRun(r,[e],i)},e.prototype.cast=function(e,t){return d.castTensor(e,t,this)},e.prototype.reshape=function(e,t){return d.reshapeTensor(e,t)},e.prototype.resizeBilinear=function(e,t,n,r){var i=new P.ResizeBilinearProgram(e.shape,t,n,r);return this.compileAndRun(i,[e])},e.prototype.multinomial=function(e,t,n){var r=e.shape[0],i=e.shape[1],a=new I.MultinomialProgram(r,i,t),o=this.makeOutputArray(a.outputShape,"int32"),s=a.getCustomSetupFunc(n);return this.compileAndRun(a,[e],o,s)},e.prototype.oneHot=function(e,t,n,r){var i=new z.OneHotProgram(e.size,t,n,r);return this.compileAndRun(i,[e])},e.prototype.makeOutputArray=function(e,t){return c.Tensor.make(e,{},t)},e.prototype.compileAndRun=function(e,t,n,r){var i=this;null==n&&(n=this.makeOutputArray(e.outputShape,t[0].dtype));var a=t.map(function(e){return i.uploadToGPU(e.dataId),{tensor:e,texData:i.texData.get(e.dataId)}});this.uploadToGPU(n.dataId);var o,s={tensor:n,texData:this.texData.get(n.dataId)},u=T.makeShaderKey(e,a,s),l=this.getAndSaveBinary(u,function(){return T.compileProgram(i.gpgpu,e,a,s)}),c=null!=this.activeTimers;return c&&(o=this.startTimer()),T.runProgram(l,a,s,r),c&&(o=this.endTimer(o),this.activeTimers.push(this.getQueryTime(o))),n},e.prototype.getAndSaveBinary=function(e,t){return e in this.binaryCache||(this.binaryCache[e]=t()),this.binaryCache[e]},e.prototype.getTextureManager=function(){return this.textureManager},e.prototype.dispose=function(){if(!this.disposed){for(var e in this.binaryCache)this.gpgpu.deleteProgram(this.binaryCache[e].webGLProgram);this.textureManager.dispose(),this.canvas.remove(),this.gpgpuCreatedLocally&&this.gpgpu.dispose(),this.disposed=!0}},e.prototype.throwIfNoData=function(e){if(!this.texData.has(e))throw new Error("WebGL backend: No data found for this tensor. Did you change your backend in the middle of the program? New backends can't use Tensors created with previous backends")},e.prototype.uploadToGPU=function(e){this.throwIfNoData(e);var t=this.texData.get(e),n=t.shape,r=t.values,a=t.texture,o=t.dtype,s=t.texType;if(null==a){var u,l=null!=this.activeTimers;l&&(u=performance.now());var c=K.getTextureShapeFromLogicalShape(this.gpgpu.gl,n);t.texShape=c;var p=this.textureManager.acquireTexture(c,s);t.texture=p,null!=r&&(this.gpgpu.uploadMatrixToTexture(p,c[0],c[1],i(r,o)),t.values=null,l&&(this.uploadWaitMs+=performance.now()-u))}},e.prototype.cacheOnCPU=function(e,t){var n=this.delayedStorage,i=this.texData.get(e),a=i.texture,o=i.texShape,s=i.dtype,u=i.texType;n&&null!=a&&(this.textureManager.releaseTexture(a,o,u),i.texture=null,i.texShape=null),null!=t&&(i.values=r(t,s))},e}();n.MathBackendWebGL=H,s.ENV.registerBackend("webgl",function(){return new H})},{"../environment":5,"../ops/axis_util":46,"../ops/reduce_util":66,"../tensor":86,"../types":91,"../util":92,"./backend_util":10,"./webgl/argminmax_gpu":12,"./webgl/avg_pool_backprop_gpu":13,"./webgl/batchnorm_gpu":14,"./webgl/binaryop_gpu":15,"./webgl/clip_gpu":16,"./webgl/concat_gpu":17,"./webgl/conv_backprop_gpu":18,"./webgl/conv_gpu":19,"./webgl/conv_gpu_depthwise":20,"./webgl/from_pixels_gpu":21,"./webgl/gather_gpu":22,"./webgl/gpgpu_context":23,"./webgl/gpgpu_math":24,"./webgl/logical_gpu":26,"./webgl/lrn_gpu":27,"./webgl/max_pool_backprop_gpu":28,"./webgl/mulmat_gpu":29,"./webgl/multinomial_gpu":30,"./webgl/onehot_gpu":31,"./webgl/pad_gpu":32,"./webgl/pool_gpu":33,"./webgl/reduce_gpu":34,"./webgl/resize_bilinear_gpu":35,"./webgl/reverse_gpu":36,"./webgl/slice_gpu":38,"./webgl/tex_util":39,"./webgl/texture_manager":40,"./webgl/tile_gpu":41,"./webgl/transpose_gpu":42,"./webgl/unaryop_gpu":43,"./webgl/webgl_util":44}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n){this.variableNames=["A"];var r=e.windowSize,i=e.batchSize,a=e.inSize,o=Math.ceil(a/r);n||this.variableNames.push("bestIndicesA"),this.outputShape=[i,o];var s="max"===t?">":"<",u=n?"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 * "+r+";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < "+r+"; 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 "}}();n.ArgMinMaxProgram=r},{}],13:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["dy"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,i=e.strideWidth,a=t-1-e.padInfo.top,o=n-1-e.padInfo.left,s=1/(t*n);this.userCode="\n const ivec2 pads = ivec2("+a+", "+o+");\n const float avgMultiplier = float("+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - 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 < "+t+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+e.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+e.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "}}();n.AvgPool2DBackpropProgram=r},{}],14:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("../../ops/broadcast_util"),i=function(){return function(e,t,n,i,a,o){this.outputShape=[],this.supportsBroadcasting=!0,this.variableNames=["x","mean","variance"],r.assertAndGetBroadcastShape(e,t),r.assertAndGetBroadcastShape(e,n);var s="0.0";null!=i&&(r.assertAndGetBroadcastShape(e,i),this.variableNames.push("offset"),s="getOffsetAtOutCoords()");var u="1.0";null!=a&&(r.assertAndGetBroadcastShape(e,a),this.variableNames.push("scale"),u="getScaleAtOutCoords()"),this.outputShape=e,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("+o+"));\n setOutput((x - mean) * inv + offset);\n }\n "}}();n.BatchNormProgram=i},{"../../ops/broadcast_util":49}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("../../ops/broadcast_util"),i="\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n";n.ADD="return a + b;",n.SUB="return a - b;",n.MUL="return a * b;",n.DIV="return a / b;",n.POW="\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n",n.SQUARED_DIFFERENCE="return (a - b) * (a - b);",n.EQUAL=i+"\n return float(a == b);\n",n.NOT_EQUAL=i+"\n return float(a != b);\n",n.LESS=i+"\n return float(a < b);\n",n.LESS_EQUAL=i+"\n return float(a <= b);\n",n.GREATER=i+"\n return float(a > b);\n",n.GREATER_EQUAL=i+"\n return float(a >= b);\n",n.LOGICAL_AND=i+"\n return float(a >= 1.0 && b >= 1.0);\n",n.LOGICAL_OR=i+"\n return float(a >= 1.0 || b >= 1.0);\n",n.LOGICAL_XOR=i+"\n return float(a >= 1.0 ^^ b >= 1.0);\n",n.PRELU="\n return (a >= 0.0) ? a : b * a;\n",n.PRELU_DER="\n return (a > 0.0) ? 1.0 : ((a < 0.0) ? b : a);\n",n.MAX=i+"\n return max(a, b);\n",n.MIN=i+"\n return min(a, b);\n",n.MOD=i+"\n return mod(a, b);\n",n.ATAN2=i+"\n return atan(a, b);\n";var a=function(){return function(e,t,n){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.outputShape=r.assertAndGetBroadcastShape(t,n),this.userCode="\n float binaryOperation(float a, float b) {\n "+e+"\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "}}();n.BinaryOpProgram=a},{"../../ops/broadcast_util":49}],16:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n){this.variableNames=["A"],this.outputShape=e;var r=t.toFixed(20),i=n.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, "+r+", "+i+"));\n }\n "}}();n.ClipProgram=r},{}],17:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("../../ops/concat_util"),i=function(){return function(e,t){this.variableNames=["A","B"],this.outputShape=[],this.outputShape=r.computeOutShape(e,t,1),this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n float value = 0.0;\n if (yC < "+e[1]+") {\n value = getA(yR, yC);\n } else {\n yC -= "+e[1]+";\n value = getB(yR, yC);\n }\n\n setOutput(value);\n }\n "}}();n.ConcatProgram=i},{"../../ops/concat_util":52}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;var t=e.strideHeight,n=e.strideWidth,r=e.padInfo.top,i=e.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\n for (int b = 0; b < "+e.batchSize+"; b++) {\n for (int yR = 0; yR < "+e.outHeight+"; yR++) {\n int xR = wR + yR * "+t+" - "+r+";\n\n if (xR < 0 || xR >= "+e.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+e.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+i+";\n\n if (xC < 0 || xC >= "+e.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "}}();n.Conv2DDerFilterProgram=r;var i=function(){return function(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,i=e.strideWidth,a=t-1-e.padInfo.top,o=n-1-e.padInfo.left;this.userCode="\n const ivec2 pads = ivec2("+a+", "+o+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - 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 < "+t+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+e.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+t+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+e.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+e.outChannels+"; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "}}();n.Conv2DDerInputProgram=i},{}],19:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["x","W"],this.outputShape=e.outShape;var t=e.padInfo.top,n=e.padInfo.left,r=e.strideHeight,i=e.strideWidth,a=e.dilationHeight,o=e.dilationWidth,s=e.filterHeight,u=e.filterWidth,l=4*Math.floor(e.inChannels/4),c=e.inChannels%4;this.userCode="\n const ivec2 strides = ivec2("+r+", "+i+");\n const ivec2 pads = ivec2("+t+", "+n+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * 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 < "+s+"; wR++) {\n int xR = xRCorner + wR * "+a+";\n\n if (xR < 0 || xR >= "+e.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+u+"; wC++) {\n int xC = xCCorner + wC * "+o+";\n\n if (xC < 0 || xC >= "+e.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+l+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, 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===c)+") {\n dotProd +=\n getX(batch, xR, xC, "+l+") *\n getW(wR, wC, "+l+", d2);\n } else if ("+(2===c)+") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, "+l+"),\n getX(batch, xR, xC, "+l+" + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, "+l+", d2),\n getW(wR, wC, "+l+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===c)+") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, "+l+"),\n getX(batch, xR, xC, "+l+" + 1),\n getX(batch, xR, xC, "+l+" + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, "+l+", d2),\n getW(wR, wC, "+l+" + 1, d2),\n getW(wR, wC, "+l+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n "}}();n.Conv2DProgram=r},{}],20:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["x","W"],this.outputShape=e.outShape;var t=e.inHeight,n=e.inWidth,r=e.padInfo.top,i=e.padInfo.left,a=e.strideHeight,o=e.strideWidth,s=e.dilationHeight,u=e.dilationWidth,l=e.filterHeight,c=e.filterWidth,p=e.outChannels/e.inChannels;this.userCode="\n const ivec2 strides = ivec2("+a+", "+o+");\n const ivec2 pads = ivec2("+r+", "+i+");\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 / "+p+";\n int q = d2 - d1 * "+p+";\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 < "+l+"; wR++) {\n int xR = xRCorner + wR * "+s+";\n\n if (xR < 0 || xR >= "+t+") {\n continue;\n }\n\n for (int wC = 0; wC < "+c+"; wC++) {\n int xC = xCCorner + wC * "+u+";\n\n if (xC < 0 || xC >= "+n+") {\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 "}}();n.DepthwiseConv2DProgram=r},{}],21:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["A"];var t=e[0],n=e[1];this.outputShape=e,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+n+".0, "+t+".0);\n\n vec4 values = texture2D(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "}}();n.FromPixelsProgram=r},{}],22:[function(e,t,n){"use strict";function r(e,t){var n=e.length;if(n>4)throw Error("Gather for rank "+n+" is not yet supported");if(1===n)return"int(getIndices(resRC))";for(var r=["resRC.x","resRC.y","resRC.z","resRC.w"],i=[],a=0;a0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]4)throw Error("Where for rank "+n+" is not yet supported");if(1===n)a="resRC",i="resRC";else{for(var o=["resRC.x","resRC.y","resRC.z","resRC.w"],s=[],u=[],l=0;l= 1.0) {\n setOutput(getA("+a+"));\n } else {\n setOutput(getB("+a+"));\n }\n }\n "}}();n.WhereProgram=i},{"./shader_compiler":37}],27:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n,r,i,a){this.variableNames=["x"],this.outputShape=[];var o=t,s=e[1]-1,u=e[2]-1,l=e[3]-1;this.outputShape=e;var c,p="float("+n+") + float("+r+") * sum";c=.5===i?"inversesqrt("+p+")":1===i?"1.0/("+p+")":"exp(log("+p+") * float(-"+i+"));",this.userCode="withinChannel"===a?"\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int u = -"+o+"; u <= "+o+"; u++) {\n for (int v = -"+o+"; v <= "+o+"; v++) {\n int idx = r + u;\n int idy = c + v;\n if (idx >= 0 && idx <= "+s+" && idy >= 0 && idy <= "+u+") {\n float z = getX(b, idx, idy, d);\n sum += z * z;\n }\n }\n }\n float val = x * "+c+";\n setOutput(val);\n }\n ":"\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -"+o+"; j <= "+o+"; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= "+l+") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * "+c+";\n setOutput(val);\n }\n "}}();n.LRNProgram=r},{}],28:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;var t=e.filterHeight,n=e.filterWidth,r=e.strideHeight,i=e.strideWidth,a=t-1-e.padInfo.top,o=n-1-e.padInfo.left,s=t*n-1;this.userCode="\n const ivec2 pads = ivec2("+a+", "+o+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - 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 < "+t+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+e.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+e.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = "+s+" - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * "+n+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "}}();n.MaxPool2DBackpropProgram=r},{}],29:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1),this.variableNames=["matrixA","matrixB"];var i=n?e[1]:e[0],a=r?t[0]:t[1],o=n?e[0]:e[1];this.outputShape=[i,a];var s=function(e,t){return n?t+" + "+e+", aRow":"aRow, "+t+" + "+e},u=function(e,t){return r?"bCol, "+t+" + "+e:t+" + "+e+", bCol"},l=4*Math.floor(o/4),c=o%4;this.userCode=" float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < "+l+"; i += 4) {\n vec4 a = vec4(\n getMatrixA("+s(0,"i")+"),\n getMatrixA("+s(1,"i")+"),\n getMatrixA("+s(2,"i")+"),\n getMatrixA("+s(3,"i")+")\n );\n vec4 b = vec4(\n getMatrixB("+u(0,"i")+"),\n getMatrixB("+u(1,"i")+"),\n getMatrixB("+u(2,"i")+"),\n getMatrixB("+u(3,"i")+")\n );\n\n result += dot(a, b);\n }\n\n if ("+(1===c)+") {\n result += getMatrixA("+s(0,l)+") *\n getMatrixB("+u(0,l)+");\n } else if ("+(2===c)+") {\n vec2 a = vec2(\n getMatrixA("+s(0,l)+"),\n getMatrixA("+s(1,l)+")\n );\n vec2 b = vec2(\n getMatrixB("+u(0,l)+"),\n getMatrixB("+u(1,l)+")\n );\n result += dot(a, b);\n } else if ("+(3===c)+") {\n vec3 a = vec3(\n getMatrixA("+s(0,l)+"),\n getMatrixA("+s(1,l)+"),\n getMatrixA("+s(2,l)+")\n );\n vec3 b = vec3(\n getMatrixB("+u(0,l)+"),\n getMatrixB("+u(1,l)+"),\n getMatrixB("+u(2,l)+")\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 "}}();n.MatMulProgram=r},{}],30:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t,n){this.variableNames=["probs"],this.outputShape=[e,n],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 < "+(t-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("+(t-1)+"));\n }\n "}return e.prototype.getCustomSetupFunc=function(e){var t=this;return function(n,r){null==t.seedLoc&&(t.seedLoc=n.getUniformLocation(r,"seed")),n.gl.uniform1f(t.seedLoc,e)}},e}();n.MultinomialProgram=r},{}],31:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n,r){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float("+r+"), float("+n+"),\n float(index == coords.y)));\n }\n "}}();n.OneHotProgram=r},{}],32:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./shader_compiler"),i=function(){return function(e,t,n){this.variableNames=["x"],this.outputShape=t.map(function(t,n){return t[0]+e[n]+t[1]});var i=e.length,a=r.getCoordsDataType(i),o=t.map(function(e){return e[0]}).join(","),s=t.map(function(t,n){return t[0]+e[n]}).join(","),u=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,i);this.userCode=1!==i?"\n "+a+" start = "+a+"("+o+");\n "+a+" end = "+a+"("+s+");\n\n void main() {\n "+a+" outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float("+n+"));\n } else {\n "+a+" coords = outC - start;\n setOutput(getX("+u+"));\n }\n }\n ":"\n int start = "+o+";\n int end = "+s+";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float("+n+"));\n } else {\n setOutput(getX(outC - start));\n }\n }\n "}}();n.PadProgram=i},{"./shader_compiler":37}],33:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n){if(this.variableNames=["x"],"avg"===t&&n)throw new Error("Cannot compute positions for average pool.");var r=e.filterHeight,i=e.filterWidth,a=e.strideHeight,o=e.strideWidth,s=e.padInfo.top,u=e.padInfo.left;this.outputShape=e.outShape;var l="avg"===t,c="0.0";if(l||(c="min"===t?"1.0 / 0.0":"-1.0 / 0.0"),n){var p="min"===t?"<=":">=";this.userCode="\n const ivec2 strides = ivec2("+a+", "+o+");\n const ivec2 pads = ivec2("+s+", "+u+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * 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 < "+r+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+e.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+i+"; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+e.inWidth+") {\n continue;\n }\n\n float value = getX(batch, 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 "+p+" currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * "+i+" + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "}else{var h="min"===t?"min":"max",d=t+"("+t+"("+t+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===t&&(d="avgValue / "+r*i+".0");var f=4*Math.floor(i/4),g=i%4,m="\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n if ("+l+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = "+h+"(values, minMaxValue);\n }\n ";this.userCode="\n const ivec2 strides = ivec2("+a+", "+o+");\n const ivec2 pads = ivec2("+s+", "+u+");\n const float initializationValue = "+c+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= "+e.inWidth+") {\n return initializationValue;\n }\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * 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("+c+");\n float avgValue = 0.0;\n\n for (int wR = 0; wR < "+r+"; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+e.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+f+"; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n getValue(batch, xR, xC + 3, d)\n );\n\n "+m+"\n }\n\n int xC = xCCorner + "+f+";\n if ("+(1===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n "+m+"\n } else if ("+(2===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n "+m+"\n } else if ("+(3===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n initializationValue\n );\n\n "+m+"\n }\n }\n setOutput("+d+");\n }\n "}}}();n.Pool2DProgram=r},{}],34:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t){this.variableNames=["x"];var n=e.windowSize,r=e.batchSize,i=e.inSize,a=Math.ceil(i/n);this.outputShape=[r,a];var o="sum"===t,s="0.0";o||(s="min"===t?"1.0 / 0.0":"-1.0 / 0.0");var u="min"===t?"min":"max",l=t+"("+t+"("+t+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"sum"===t&&(l="sumValue");var c=4*Math.floor(n/4),p=n%4,h="\n if ("+o+") {\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 ",d="";i%n>0&&(d="\n if (inIdx < 0 || inIdx >= "+i+") {\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 "+d+"\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 * "+n+";\n\n vec4 minMaxValue = vec4("+s+");\n float sumValue = 0.0;\n\n for (int i = 0; i < "+c+"; 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 + "+c+";\n if ("+(1===p)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n "+h+"\n } else if ("+(2===p)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n "+h+"\n } else if ("+(3===p)+") {\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("+l+");\n }\n "}}();n.ReduceProgram=r},{}],35:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){return function(e,t,n,r){this.variableNames=["A"],this.outputShape=[];var i=e[0],a=e[1],o=e[2],s=e[3];this.outputShape=[i,t,n,s];var u=r?[a-1,o-1]:[a,o],l=r?[t-1,n-1]:[t,n];this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+u[0]/l[0]+",\n "+u[1]/l[1]+");\n const vec2 inputShapeRC = vec2("+a+".0, "+o+".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\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(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, 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 "}}();n.ResizeBilinearProgram=r},{}],36:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./shader_compiler"),i=function(){return function(e,t){this.variableNames=["x"];var n=e.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");if(this.outputShape=e,1!==n){var i=function(n){return-1!==t.indexOf(n)&&1!==e[n]?e[n]+" - coords["+n+"] - 1":"coords["+n+"]"},a=e.map(function(e,t){return i(t)}).join(","),o=r.getCoordsDataType(n);this.userCode="\n void main() {\n "+o+" coords = getOutputCoords();\n setOutput(getX("+a+"));\n }\n "}else this.userCode="\n void main() {\n int coord = getOutputCoords();\n setOutput(getX("+e[0]+" - coord - 1));\n }\n "}}();n.ReverseProgram=i},{"./shader_compiler":37}],37:[function(e,t,n){"use strict";function r(){return E.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?k:O}function i(){return E.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")?C:T}function a(e){var t=e.shapeInfo.logicalShape;switch(t.length){case 0:return h(e);case 1:return d(e);case 2:return f(e);case 3:return g(e);case 4:return m(e);default:throw new Error(t.length+"-D input sampling is not yet supported")}}function o(e,t,n){var r=v(e);return r+=a(e),(n||_.arraysEqual(e.shapeInfo.logicalShape,t.logicalShape))&&(r+=b(e,t,n)),r}function s(e,t){switch(e.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return u(e,t);case 2:return p(e,t);case 3:return l(e,t);case 4:return c(e,t);default:throw new Error(e.length+"-D output sampling is not yet supported")}}function u(e,t){return 1===t[0]?"\n int getOutputCoords() {\n return int(resultUV.x * "+t[1]+".0);\n }\n ":1===t[1]?"\n int getOutputCoords() {\n return int(resultUV.y * "+t[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n return resTexRC.x * "+t[1]+" + resTexRC.y;\n }\n "}function l(e,t){var n=e[1]*e[2],r=e[2];return"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n int index = resTexRC.x * "+t[1]+" + resTexRC.y;\n int r = index / "+n+";\n index -= r * "+n+";\n int c = index / "+r+";\n int d = index - c * "+r+";\n return ivec3(r, c, d);\n }\n "}function c(e,t){var n=e[3],r=e[2]*n,i=e[1]*r;return"\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n int index = resTexRC.x * "+t[1]+" + resTexRC.y;\n\n int r = index / "+i+";\n index -= r * "+i+";\n\n int c = index / "+r+";\n index -= c * "+r+";\n\n int d = index / "+n+";\n int d2 = index - d * "+n+";\n\n return ivec4(r, c, d, d2);\n }\n "}function p(e,t){return _.arraysEqual(e,t)?"\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2("+t[0]+", "+t[1]+"));\n }\n ":1===e[1]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n int index = resTexRC.x * "+t[1]+" + resTexRC.y;\n return ivec2(index, 0);\n }\n ":1===e[0]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n int index = resTexRC.x * "+t[1]+" + resTexRC.y;\n return ivec2(0, index);\n }\n ":"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+t[0]+", "+t[1]+"));\n int index = resTexRC.x * "+t[1]+" + resTexRC.y;\n int r = index / "+e[1]+";\n int c = index - r * "+e[1]+";\n return ivec2(r, c);\n }\n "}function h(e){var t=e.name;return"\n float "+("get"+t.charAt(0).toUpperCase()+t.slice(1))+"() {\n return sampleTexture("+t+", halfCR);\n }\n "}function d(e){var t=e.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1);return"\n float "+n+"(int index) {\n return "+n+"Flat(index);\n }\n "}function f(e){var t=e.shapeInfo.logicalShape,n=e.shapeInfo.texShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),o=n[0],s=n[1];if(_.arraysEqual(t,n))return"\n float "+i+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+s+".0, "+o+".0);\n return sampleTexture("+r+", uv);\n }\n ";var u=_.squeezeShape(t),l=u.newShape,c=u.keptDims,p=l;if(p.length=1?"coords = 0;":u.map(function(e){return"coords["+(e+l)+"] = 0;"}).join("\n");var c="";return c=a<2&&i>0?"coords":e.shapeInfo.logicalShape.map(function(e,t){return"coords["+(t+l)+"]"}).join(", "),"\n float "+r+"() {\n "+o+" coords = getOutputCoords();\n "+s+"\n return get"+n+"("+c+");\n }\n "}function b(e,t,n){var r=e.shapeInfo.texShape,i=e.name,a=i.charAt(0).toUpperCase()+i.slice(1),o="get"+a+"AtOutCoords",s=A.getBroadcastDims(e.shapeInfo.logicalShape,t.logicalShape),u=e.shapeInfo.logicalShape.length,l=t.logicalShape.length,c=n&&(l>u||s.length>0),p=A.broadcastDimsAreOuter(s);if(c&&!p)return y(e,t,a,o);var h=t.texShape;if(_.arraysEqual(r,h))return"\n float "+o+"() {\n return sampleTexture("+i+", resultUV);\n }\n ";var d=_.sizeFromShape(r),f="";return c&&p&&(f="\n int mainPart = index / "+d+";\n index -= mainPart * "+d+";\n "),"\n float "+o+"() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+h[0]+", "+h[1]+"));\n int index = resTexRC.x * "+h[1]+" + resTexRC.y;\n "+f+"\n int texR = index / "+r[1]+";\n int texC = index - texR * "+r[1]+";\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+r[1]+".0, "+r[0]+".0);\n\n return sampleTexture("+i+", uv);\n }\n "}function w(e,t){var n=JSON.parse(JSON.stringify(e));return n.shapeInfo.logicalShape=t,n}function x(e,t){return t.map(function(t){return e[t]}).join(", ")}Object.defineProperty(n,"__esModule",{value:!0});var E=e("../../environment"),_=e("../../util"),A=e("../../ops/broadcast_util"),S=e("./tex_util");n.makeShader=function(e,t,n,a){var u=r(),l=i(),c=e.map(function(e){return"uniform sampler2D "+e.name+";"}).join("\n"),p=e.map(function(e){return o(e,t,a)}).join("\n"),h=t.texShape,d=s(t.logicalShape,h);return[N,u,l,c,d,p,n].join("\n")};var O="\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 = "+S.FLOAT_MIN+".0;\n const float maxValue = "+S.FLOAT_MAX+".0;\n const float range = (maxValue - minValue) / 255.0;\n const vec2 dotRange = vec2(1.0, range);\n\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n vec4 sampleValue = texture2D(textureSampler, uv);\n if (all(equal(sampleValue, vec4("+S.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",T="\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("+S.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",k="\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return texture2D(textureSampler, uv).r;\n }\n",C="\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n",N="\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 float v1 = val * val;\n float v2 = val * val;\n return v1 == v2 ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n vec4 v1 = values * values;\n vec4 v2 = values * values;\n return any(notEqual(v1, v2));\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 \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";n.getCoordsDataType=function(e){if(e<=1)return"int";if(2===e)return"ivec2";if(3===e)return"ivec3";if(4===e)return"ivec4";throw Error("GPU for rank "+e+" is not yet supported")}},{"../../environment":5,"../../ops/broadcast_util":49,"../../util":92,"./tex_util":39}],38:[function(e,t,n){"use strict";function r(e){if(1===e)return"sourceLoc";if(2===e)return"sourceLoc.x, sourceLoc.y";if(3===e)return"sourceLoc.x, sourceLoc.y, sourceLoc.z";if(4===e)return"sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w";throw Error("Slicing for rank "+e+" is not yet supported")}Object.defineProperty(n,"__esModule",{value:!0});var i=e("./shader_compiler"),a=function(){function e(e){this.variableNames=["source"],this.outputShape=e,this.rank=e.length;var t=i.getCoordsDataType(this.rank),n=r(this.rank);this.userCode="\n uniform "+t+" start;\n\n void main() {\n "+t+" sourceLoc = start + getOutputCoords();\n setOutput(getSource("+n+"));\n }\n "}return e.prototype.getCustomSetupFunc=function(e){var t=this;if(e.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+e.length+")");return function(n,r){if(null!=t.startLoc||(t.startLoc=n.getUniformLocationNoThrow(r,"start"),null!=t.startLoc))if(1===t.rank)n.gl.uniform1i(t.startLoc,e[0]);else if(2===t.rank)n.gl.uniform2i(t.startLoc,e[0],e[1]);else if(3===t.rank)n.gl.uniform3i(t.startLoc,e[0],e[1],e[2]);else{if(4!==t.rank)throw Error("Slicing for rank "+t.rank+" is not yet supported");n.gl.uniform4i(t.startLoc,e[0],e[1],e[2],e[3])}}},e}();n.SliceProgram=a},{"./shader_compiler":37}],39:[function(e,t,n){"use strict";function r(e,t){return e*t}function i(e,t){if(e%t!=0)throw new Error("unpackedSize ("+e+") must be a multiple of "+t);return e/t}function a(e,t){return[Math.ceil(t/2),Math.ceil(e/2)]}function o(e,t){var n=a(e,t);return n[0]*n[1]*4}Object.defineProperty(n,"__esModule",{value:!0});!function(e){e[e.FLOAT=0]="FLOAT",e[e.UNSIGNED_BYTE=1]="UNSIGNED_BYTE"}(n.TextureType||(n.TextureType={})),n.getUnpackedMatrixTextureShapeWidthHeight=function(e,t){return[t,e]},n.getUnpackedArraySizeFromMatrixSize=r,n.getColorMatrixTextureShapeWidthHeight=function(e,t){return[4*t,e]},n.getMatrixSizeFromUnpackedArraySize=i,n.encodeMatrixToUnpackedArray=function(e,t,n){var i=r(e.length,n);if(t.length= "+i);for(var a=0,o=0;o= "+r);for(var a=0,o=0;o= "+r);for(var i=0,a=0;a= "+i);for(var s=a(t,n),u=s[0],l=s[1],c=n%2==1,p=t%2==1,h=Math.floor(n/2),d=Math.floor(t/2),f=c?4:0,g=n,m=0,v=0;v= "+i);for(var o=n%2==1,s=t%2==1,u=Math.floor(n/2),l=Math.floor(t/2),c=a(t,n),p=c[0],h=c[1],d=o?4:0,f=n+(o?1:0),g=0,m=0,v=n,y=0;y0)return this.numFreeTextures--,this.numUsedTextures++,this.log(),this.freeTextures[n].shift();this.numUsedTextures++,this.log();var a=this.gpgpu.createMatrixTexture(e[0],e[1]);return this.allocatedTextures.push(a),a},e.prototype.releaseTexture=function(e,t,n){void 0===n&&(n=i.TextureType.FLOAT);var a=r(t,n);a in this.freeTextures||(this.freeTextures[a]=[]),this.freeTextures[a].push(e),this.numFreeTextures++,this.numUsedTextures--,this.usedTextureCount[a]--,this.log()},e.prototype.log=function(){if(this.logEnabled){var e=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+e+")")}},e.prototype.getNumUsedTextures=function(){return this.numUsedTextures},e.prototype.getNumFreeTextures=function(){return this.numFreeTextures},e.prototype.dispose=function(){var e=this;null!=this.allocatedTextures&&(this.allocatedTextures.forEach(function(t){e.gpgpu.deleteMatrixTexture(t)}),this.freeTextures=null,this.allocatedTextures=null,this.usedTextureCount=null,this.numUsedTextures=0,this.numFreeTextures=0)},e}();n.TextureManager=a},{"./tex_util":39}],41:[function(e,t,n){"use strict";function r(e){var t=e.length;if(t>4)throw Error("Tile for rank "+t+" is not yet supported");if(1===t)return"imod(resRC, "+e[0]+")";for(var n=["resRC.x","resRC.y","resRC.z","resRC.w"],r=[],i=0;i4)throw Error("Transpose for rank "+t+" is not yet supported");for(var n=["resRC.x","resRC.y","resRC.z","resRC.w"],r=new Array(t),i=0;i= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n",n.LEAKY_RELU=function(e){return"\n return (x >= 0.0) ? x : "+e+" * x;\n "},n.STEP=function(e){return void 0===e&&(e=0),a+"\n return x > 0.0 ? 1.0 : float("+e+");\n "},n.NEG="\n return -x;\n",n.CEIL="\n return ceil(x);\n",n.FLOOR="\n return floor(x);\n",n.SIGN="\n return sign(x);\n",n.ROUND="\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n",n.EXP="\n return exp(x);\n",n.EXPM1="\n return exp(x) - 1.0;\n",n.LOG="\n return log(x);\n",n.LOG1P="\n return log(1.0 + x);\n",n.SQRT=a+"\n return sqrt(x);\n",n.RSQRT=a+"\n return inversesqrt(x);\n",n.SIGMOID="\n return 1.0 / (1.0 + exp(-1.0 * x));\n",n.SIN=a+"\n return sin(x);\n",n.COS=a+"\n return cos(x);\n",n.TAN="\n return tan(x);\n",n.ASIN=a+"\n return asin(x);\n",n.ACOS=a+"\n return acos(x);\n",n.ATAN=a+"\n return atan(x);\n",n.SINH="\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n",n.COSH="\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n",n.TANH="\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n",n.ASINH="\n return log(x + sqrt(x * x + 1.0));\n",n.ACOSH="\n return log(x + sqrt(x * x - 1.0));\n",n.ATANH="\n return (log(1.0 + x) - log(1.0 - x)) / 2.0;\n",n.SQUARE="\n return x * x;\n",n.RECIPROCAL=a+"\n return 1.0 / x;\n",n.LOGICAL_NOT=a+"\n return float(!(x >= 1.0));\n",n.TO_INT="\n return float(int(x));\n"},{"../../ops/selu_util":69}],44:[function(e,t,n){"use strict";function r(e,t){var n,r=g.ENV.get("WEBGL_VERSION");if(2===r?n=e.getContext("webgl2",t):1===r&&(n=e.getContext("webgl",t)||e.getContext("experimental-webgl",t)),0===r||null==n)throw new Error("This browser does not support WebGL.");return n}function i(e,t){var n=t();return a(e),n}function a(e){if(m){var t=e.getError();if(t!==e.NO_ERROR)throw new Error("WebGL Error: "+o(e,t))}}function o(e,t){switch(t){case e.NO_ERROR:return"NO_ERROR";case e.INVALID_ENUM:return"INVALID_ENUM";case e.INVALID_VALUE:return"INVALID_VALUE";case e.INVALID_OPERATION:return"INVALID_OPERATION";case e.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case e.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case e.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+t}}function s(e,t){var n=v.exec(t);if(null==n)return console.log("Couldn't parse line number in error: "+t),void console.log(e);for(var r=+n[1],i=e.split("\n"),a=i.length.toString().length+2,o=i.map(function(e,t){return f.rightPad((t+1).toString(),a)+e}),s=0,u=0;un){var i="[gl.TEXTURE0, gl.TEXTURE"+n+"]";throw new Error("textureUnit must be in "+i+".")}}Object.defineProperty(n,"__esModule",{value:!0});var d=null,f=e("../../util"),g=e("../../environment");n.createWebGLRenderingContext=function(e){var t=document.createElement("canvas");return t.width=1,t.height=1,r(t,e)},n.createWebGLRenderingContextFromCanvas=r,n.callAndCheck=i;var m=!1;n.enableDebugWebGLErrorChecking=function(e){m=e},n.checkWebGLError=a,n.getWebGLErrorMessage=o,n.getExtensionOrThrow=function(e,t){return p(e,function(){return e.getExtension(t)},'Extension "'+t+'" not supported on this browser.')},n.createVertexShader=function(e,t){var n=p(e,function(){return e.createShader(e.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(i(e,function(){return e.shaderSource(n,t)}),i(e,function(){return e.compileShader(n)}),!1===e.getShaderParameter(n,e.COMPILE_STATUS))throw console.log(e.getShaderInfoLog(n)),new Error("Failed to compile vertex shader.");return n},n.createFragmentShader=function(e,t){var n=p(e,function(){return e.createShader(e.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(i(e,function(){return e.shaderSource(n,t)}),i(e,function(){return e.compileShader(n)}),!1===e.getShaderParameter(n,e.COMPILE_STATUS))throw s(t,e.getShaderInfoLog(n)),new Error("Failed to compile fragment shader.");return n};var v=/ERROR: [0-9]+:([0-9]+):/g;n.createProgram=function(e){return p(e,function(){return e.createProgram()},"Unable to create WebGLProgram.")},n.linkProgram=function(e,t){if(i(e,function(){return e.linkProgram(t)}),!1===e.getProgramParameter(t,e.LINK_STATUS))throw console.log(e.getProgramInfoLog(t)),new Error("Failed to link vertex and fragment shaders.")},n.validateProgram=function(e,t){if(i(e,function(){return e.validateProgram(t)}),!1===e.getProgramParameter(t,e.VALIDATE_STATUS))throw console.log(e.getProgramInfoLog(t)),new Error("Shader program validation failed.")},n.createStaticVertexBuffer=function(e,t){var n=p(e,function(){return e.createBuffer()},"Unable to create WebGLBuffer");return i(e,function(){return e.bindBuffer(e.ARRAY_BUFFER,n)}),i(e,function(){return e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW)}),n},n.createStaticIndexBuffer=function(e,t){var n=p(e,function(){return e.createBuffer()},"Unable to create WebGLBuffer");return i(e,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n)}),i(e,function(){return e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW)}),n},n.queryMaxTextureSize=u,n.getChannelsPerTexture=function(){return g.ENV.get("WEBGL_FLOAT_TEXTURE_ENABLED")&&2===g.ENV.get("WEBGL_VERSION")?1:4},n.createTexture=function(e){return p(e,function(){return e.createTexture()},"Unable to create WebGLTexture.")},n.validateTextureSize=function(e,t,n){var r=u(e);if(t<=0||n<=0)throw i="["+t+"x"+n+"]",new Error("Requested texture size "+i+" is invalid.");if(t>r||n>r){var i="["+t+"x"+n+"]",a="["+r+"x"+r+"]";throw new Error("Requested texture size "+i+" greater than WebGL maximum on this browser / GPU "+a+".")}},n.createFramebuffer=function(e){return p(e,function(){return e.createFramebuffer()},"Unable to create WebGLFramebuffer.")},n.bindVertexBufferToProgramAttribute=function(e,t,n,r,a,o,s){var u=e.getAttribLocation(t,n);-1!==u&&(i(e,function(){return e.bindBuffer(e.ARRAY_BUFFER,r)}),i(e,function(){return e.vertexAttribPointer(u,a,e.FLOAT,!1,o,s)}),i(e,function(){return e.enableVertexAttribArray(u)}))},n.bindTextureUnit=l,n.unbindTextureUnit=function(e,t){h(e,t),i(e,function(){return e.activeTexture(e.TEXTURE0+t)}),i(e,function(){return e.bindTexture(e.TEXTURE_2D,null)})},n.getProgramUniformLocationOrThrow=function(e,t,n){return p(e,function(){return e.getUniformLocation(t,n)},'uniform "'+n+'" not present in program.')},n.getProgramUniformLocation=function(e,t,n){return e.getUniformLocation(t,n)},n.bindTextureToProgramUniformSampler=function(e,t,n,r,a){i(e,function(){return l(e,n,a)}),i(e,function(){return e.uniform1i(r,a)})},n.bindCanvasToFramebuffer=function(e){i(e,function(){return e.bindFramebuffer(e.FRAMEBUFFER,null)}),i(e,function(){return e.viewport(0,0,e.canvas.width,e.canvas.height)}),i(e,function(){return e.scissor(0,0,e.canvas.width,e.canvas.height)})},n.bindColorTextureToFramebuffer=function(e,t,n){i(e,function(){return e.bindFramebuffer(e.FRAMEBUFFER,n)}),i(e,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0)})},n.unbindColorTextureFromFramebuffer=function(e,t){i(e,function(){return e.bindFramebuffer(e.FRAMEBUFFER,t)}),i(e,function(){return e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0)})},n.validateFramebuffer=function(e){var t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+c(e,t))},n.getFramebufferErrorMessage=c,n.getTextureShapeFromLogicalShape=function(e,t){2!==t.length&&(t=f.squeezeShape(t).newShape);var n=u(e),r=f.sizeFromShape(t);return t.length<=1&&r<=n?[r,1]:2===t.length&&t[0]<=n&&t[1]<=n?t:3===t.length&&t[0]<=n&&t[1]*t[2]<=n?[t[0],t[1]*t[2]]:4===t.length&&t[0]<=n&&t[1]*t[2]*t[3]<=n?[t[0],t[1]*t[2]*t[3]]:f.sizeToSquarishShape(r)}},{"../../environment":5,"../../util":92}],45:[function(e,t,n){"use strict";function r(e,t){if(null==t||"float32"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t)return new Uint8Array(e);throw new Error("Unknown data type $ {dtype}")}function i(e,t){for(var n=r(e,t),i=0;i=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var u=e("../doc"),l=e("../environment"),c=e("../tensor"),p=e("../tensor_util"),h=e("../util"),d=e("./axis_util"),f=e("./concat"),g=e("./operation"),m=e("./ops"),v=e("./rand"),y=function(){function e(){}return e.tensor=function(e,t,n){void 0===n&&(n="float32");var r=h.inferShape(e);return null!=t&&1!==r.length&&h.assertShapesMatch(t,r,"Error creating a new Tensor. Inferred shape ("+r+") does not match the provided shape ("+t+"). "),h.isTypedArray(e)||Array.isArray(e)||(e=[e]),t=t||r,c.Tensor.make(t,{values:a(e,n)},n)},e.scalar=function(t,n){if(void 0===n&&(n="float32"),h.isTypedArray(t)||Array.isArray(t))throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean)");return e.tensor(t,[],n)},e.tensor1d=function(t,n){void 0===n&&(n="float32");var r=h.inferShape(t);if(1!==r.length)throw new Error("Error creating a new Tensor1D: values must be a flat/TypedArray");return e.tensor(t,r,n)},e.tensor2d=function(t,n,r){void 0===r&&(r="float32");var i=h.inferShape(t);if(2!==i.length&&1!==i.length)throw new Error("Error creating a new Tensor2D: values must be number[][] or flat/TypedArray");return n=n||i,e.tensor(t,n,r)},e.tensor3d=function(t,n,r){void 0===r&&(r="float32");var i=h.inferShape(t);if(3!==i.length&&1!==i.length)throw new Error("Error creating a new Tensor3D: values must be number[][][]or flat/TypedArray");return n=n||i,e.tensor(t,n,r)},e.tensor4d=function(t,n,r){void 0===r&&(r="float32");var i=h.inferShape(t);if(4!==i.length&&1!==i.length)throw new Error("Error creating a new Tensor4D: values must be number[][][][]or flat/TypedArray");return n=n||i,e.tensor(t,n,r)},e.ones=function(e,t){void 0===t&&(t="float32");var n=i(h.sizeFromShape(e),t);return c.Tensor.make(e,{values:n},t)},e.zeros=function(e,t){void 0===t&&(t="float32");var n=r(h.sizeFromShape(e),t);return c.Tensor.make(e,{values:n},t)},e.fill=function(e,t,n){void 0===n&&(n="float32");var r=h.getTypedArrayFromDType(n,h.sizeFromShape(e));return r.fill(t),c.Tensor.make(e,{values:r},n)},e.onesLike=function(t){return e.ones(t.shape,t.dtype)},e.zerosLike=function(t){return e.zeros(t.shape,t.dtype)},e.clone=function(e){return l.ENV.engine.runKernel(function(t){return c.Tensor.make(e.shape,{dataId:e.dataId},e.dtype)},{x:e},function(e){return{x:function(){return e.toFloat()}}})},e.randomNormal=function(t,n,r,i,a){if(void 0===n&&(n=0),void 0===r&&(r=1),null!=i&&"bool"===i)throw new Error("Unsupported data type "+i);for(var o=new v.MPRandGauss(n,r,i,!1,a),s=e.buffer(t,i),u=0;u2)throw new Error("Rank of probabilities must be 1 or 2, but is "+a);r||(e=m.softmax(e)),n=n||Math.random();var o=1===a?e.as2D(1,-1):e,s=l.ENV.engine.runKernel(function(e){return e.multinomial(o,t,n)},{prob2D:o});return 1===a?s.as1D():s},e.oneHot=function(e,t,n,r){if(void 0===n&&(n=1),void 0===r&&(r=0),t<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+t);return l.ENV.engine.runKernel(function(i){return i.oneHot(e,t,n,r)},{indices:e})},e.fromPixels=function(e,t){if(void 0===t&&(t=3),t>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");return l.ENV.engine.fromPixels(e,t)},e.reshape=function(e,t){t=h.inferFromImplicitShape(t,e.size),h.assert(e.size===h.sizeFromShape(t),"new shape and old shape must have the same number of elements.");return l.ENV.engine.runKernel(function(n){return n.reshape(e,t)},{x:e},function(t){return{x:function(){return t.reshape(e.shape)}}})},e.squeeze=function(t,n){return e.reshape(t,h.squeezeShape(t.shape,n).newShape)},e.cast=function(e,t){return l.ENV.engine.runKernel(function(n){return n.cast(e,t)},{x:e},function(e){return{x:function(){return e.clone()}}})},e.tile=function(t,n){h.assert(t.rank===n.length,"Error in transpose: rank of input "+t.rank+" must match length of reps "+n+".");return l.ENV.engine.runKernel(function(e){return e.tile(t,n)},{x:t},function(r){return{x:function(){var i=e.zerosLike(t);if(1===t.rank)for(a=0;a=1,"Pass at least one tensor to tf.stack"),1===e.length)return e[0].expandDims(t);var n=e[0].rank,r=e[0].shape,i=e[0].dtype;h.assert(t<=n,"Axis must be <= rank of the tensor"),e.forEach(function(e){h.assertShapesMatch(r,e.shape,"All tensors passed to stack must have matching shapes")}),e.forEach(function(e){h.assert(i===e.dtype,"All tensors passed to stack must have matching dtypes")});var a=e.map(function(e){return e.expandDims(t)});return f.ConcatOps.concat(a,t)},e.split=function(e,t,n){void 0===n&&(n=0),n=d.parseAxisParam(n,e.shape)[0];var r;"number"==typeof t?(h.assert(e.shape[n]%t==0,"Number of splits must evenly divide the axis."),r=Array(t).fill(e.shape[n]/t)):(h.assert(e.shape[n]===t.reduce(function(e,t){return e+t}),"The sum of sizes must match the size of the axis dimension."),r=t);var i=Array(e.rank).fill(0),a=e.shape.slice();return r.map(function(t){a[n]=t;var r=e.slice(i,a);return i[n]+=t,r})},e.expandDims=function(t,n){void 0===n&&(n=0),h.assert(n<=t.rank,"Axis must be <= rank of the tensor");var r=t.shape.slice();return r.splice(n,0,1),e.reshape(t,r)},e.linspace=function(t,n,i){if(0===i)throw new Error("Cannot request zero samples");var a=(n-t)/(i-1),o=r(i,"float32");o[0]=t;for(var s=1;s1;if(o||s||u)return e.zeros([0],a);var l=r(Math.abs(Math.ceil((n-t)/i)),a);n=-n&&e=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var a=e("../doc"),o=e("../environment"),s=e("../util"),u=e("./operation"),l=function(){function e(){}return e.batchNormalization2d=function(t,n,r,i,a,o){return void 0===i&&(i=.001),s.assert(2===t.rank,"Error in batchNormalization3D: x must be rank 3 but got rank "+t.rank+"."),s.assert(2===n.rank||1===n.rank,"Error in batchNormalization2D: mean must be rank 2 or rank 1 but got rank "+n.rank+"."),s.assert(2===r.rank||1===r.rank,"Error in batchNormalization2D: variance must be rank 2 or rank 1 but got rank "+r.rank+"."),null!=a&&s.assert(2===a.rank||1===a.rank,"Error in batchNormalization2D: scale must be rank 2 or rank 1 but got rank "+a.rank+"."),null!=o&&s.assert(2===o.rank||1===o.rank,"Error in batchNormalization2D: offset must be rank 2 or rank 1 but got rank "+o.rank+"."),e.batchNormalization(t,n,r,i,a,o)},e.batchNormalization3d=function(t,n,r,i,a,o){return void 0===i&&(i=.001),s.assert(3===t.rank,"Error in batchNormalization3D: x must be rank 3 but got rank "+t.rank+"."),s.assert(3===n.rank||1===n.rank,"Error in batchNormalization3D: mean must be rank 3 or rank 1 but got rank "+n.rank+"."),s.assert(3===r.rank||1===r.rank,"Error in batchNormalization3D: variance must be rank 3 or rank 1 but got rank "+r.rank+"."),null!=a&&s.assert(3===a.rank||1===a.rank,"Error in batchNormalization3D: scale must be rank 3 or rank 1 but got rank "+a.rank+"."),null!=o&&s.assert(3===o.rank||1===o.rank,"Error in batchNormalization3D: offset must be rank 3 or rank 1 but got rank "+o.rank+"."),e.batchNormalization(t,n,r,i,a,o)},e.batchNormalization4d=function(t,n,r,i,a,o){return void 0===i&&(i=.001),s.assert(4===t.rank,"Error in batchNormalization4D: x must be rank 4 but got rank "+t.rank+"."),s.assert(4===n.rank||1===n.rank,"Error in batchNormalization4D: mean must be rank 4 or rank 1 but got rank "+n.rank+"."),s.assert(4===r.rank||1===r.rank,"Error in batchNormalization4D: variance must be rank 4 or rank 1 but got rank "+r.rank+"."),null!=a&&s.assert(4===a.rank||1===a.rank,"Error in batchNormalization4D: scale must be rank 4 or rank 1 but got rank "+a.rank+"."),null!=o&&s.assert(4===o.rank||1===o.rank,"Error in batchNormalization4D: offset must be rank 4 or rank 1 but got rank "+o.rank+"."),e.batchNormalization(t,n,r,i,a,o)},e.batchNormalization=function(e,t,n,i,a,s){void 0===i&&(i=.001);var u;return u=0===e.rank||1===e.rank?e.as4D(1,1,1,e.size):2===e.rank?e.as4D(1,1,e.shape[0],e.shape[1]):3===e.rank?e.as4D(1,e.shape[0],e.shape[1],e.shape[2]):e,o.ENV.engine.runKernel(function(e){return e.batchNormalization4D(u,r(t),r(n),i,r(a),r(s))},{x:e,mean:t,variance:n}).reshape(e.shape)},i([u.operation],e,"batchNormalization2d",null),i([u.operation],e,"batchNormalization3d",null),i([u.operation],e,"batchNormalization4d",null),i([a.doc({heading:"Operations",subheading:"Normalization"})],e,"batchNormalization",null),e}();n.BatchNormOps=l},{"../doc":3,"../environment":5,"../util":92,"./operation":62}],48:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./broadcast_util"),u=e("./operation"),l=e("./ops"),c=function(){function e(){}return e.add=function(e,t){o.assertTypesMatch(e,t);var n=s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.add(e,t)},{a:e,b:t},function(r){return{a:function(){var t=r,i=s.getReductionAxes(e.shape,n);return i.length>0&&(t=t.sum(i)),t.reshape(e.shape)},b:function(){var e=r,i=s.getReductionAxes(t.shape,n);return i.length>0&&(e=e.sum(i)),e.reshape(t.shape)}}})},e.addStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in addStrict: "),e.add(t)},e.sub=function(e,t){o.assertTypesMatch(e,t);var n=s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.subtract(e,t)},{a:e,b:t},function(r){return{a:function(){var t=r,i=s.getReductionAxes(e.shape,n);return i.length>0&&(t=t.sum(i)),t.reshape(e.shape)},b:function(){var e=r,i=s.getReductionAxes(t.shape,n);return i.length>0&&(e=e.sum(i)),e.neg().reshape(t.shape)}}})},e.subStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in subStrict: "),e.sub(t)},e.pow=function(e,t){s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.pow(e,t)},{base:e},function(n){if(!o.arraysEqual(e.shape,t.shape)&&!o.isScalarShape(t.shape))throw new Error("Gradient of pow not yet supported for broadcasted shapes.");return{base:function(){var r=t.toFloat(),i=r.mul(e.toFloat().pow(r.sub(l.scalar(1))));return n.mulStrict(i)}}})},e.powStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in powStrict: "),e.pow(t)},e.mul=function(e,t){o.assertTypesMatch(e,t);var n=s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.multiply(e,t)},{a:e,b:t},function(r){return{a:function(){var i=r.mul(t.toFloat()),a=s.getReductionAxes(e.shape,n);return a.length>0?i.sum(a).reshape(e.shape):i},b:function(){var i=r.mul(e.toFloat()),a=s.getReductionAxes(t.shape,n);return a.length>0?i.sum(a).reshape(t.shape):i}}})},e.mulStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in multiplyStrict: "),e.mul(t)},e.div=function(e,t){o.assertTypesMatch(e,t);var n=s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.divide(e,t)},{a:e,b:t},function(r){return{a:function(){var i=r.div(t.toFloat()),a=s.getReductionAxes(e.shape,n);return a.length>0?i.sum(a).reshape(e.shape):i},b:function(){var i=r.mul(e.toFloat()),a=s.getReductionAxes(t.shape,n);a.length>0&&(i=i.sum(a).reshape(t.shape));var o=t.square();return i.div(o.toFloat()).neg()}}})},e.divStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in divideStrict: "),e.div(t)},e.mod=function(e,t){o.assertTypesMatch(e,t);var n=s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.mod(e,t)},{a:e,b:t},function(r){return{a:function(){var t=s.getReductionAxes(e.shape,n);return t.length>0?r.sum(t).reshape(e.shape):r},b:function(){var i=r.mul(e.div(t).floor().neg()),a=s.getReductionAxes(t.shape,n);return a.length>0?i.sum(a).reshape(t.shape):i}}})},e.modStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in modStrict: "),e.mod(t)},e.minimum=function(e,t){o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.minimum(e,t)},{a:e,b:t},function(n){return{a:function(){return n.mul(e.lessEqual(t).toFloat())},b:function(){return n.mul(e.greater(t).toFloat())}}})},e.minimumStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in minimumStrict: "),e.minimum(t)},e.maximum=function(e,t){o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.maximum(e,t)},{a:e,b:t},function(n){return{a:function(){return n.mul(e.greaterEqual(t).toFloat())},b:function(){return n.mul(e.less(t).toFloat())}}})},e.maximumStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in minimumStrict: "),e.maximum(t)},e.squaredDifference=function(e,t){o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape);return a.ENV.engine.runKernel(function(n){return n.squaredDifference(e,t)},{a:e,b:t},function(n){var r=l.scalar(2);return{a:function(){return n.mul(e.sub(t).mul(r))},b:function(){return n.mul(t.sub(e).mul(r))}}})},e.squaredDifferenceStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in squaredDifferenceStrict: "),e.squaredDifference(t)},e.atan2=function(t,n){o.assertTypesMatch(t,n);var r=s.assertAndGetBroadcastShape(t.shape,n.shape);return a.ENV.engine.runKernel(function(e){return e.atan2(t,n)},{a:t,b:n},function(i){return{a:function(){var a=e.add(l.square(t),l.square(n)),o=i.mul(n.div(a)),u=s.getReductionAxes(t.shape,r);return u.length>0&&(o=o.sum(u)),o.reshape(t.shape)},b:function(){var a=e.add(l.square(t),l.square(n)),o=l.neg(i.mul(t.div(a))),u=s.getReductionAxes(n.shape,r);return u.length>0&&(o=o.sum(u)),o.reshape(n.shape)}}})},r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"add",null),r([u.operation],e,"addStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"sub",null),r([u.operation],e,"subStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"pow",null),r([u.operation],e,"powStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"mul",null),r([u.operation],e,"mulStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"div",null),r([u.operation],e,"divStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"mod",null),r([u.operation],e,"modStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"minimum",null),r([u.operation],e,"minimumStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"maximum",null),r([u.operation],e,"maximumStrict",null),r([i.doc({heading:"Operations",subheading:"Arithmetic"}),u.operation],e,"squaredDifference",null),r([u.operation],e,"squaredDifferenceStrict",null),r([u.operation],e,"atan2",null),e}();n.BinaryOps=c},{"../doc":3,"../environment":5,"../util":92,"./broadcast_util":49,"./operation":62,"./ops":63}],49:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.getBroadcastDims=function(e,t){for(var n=e.length,r=[],i=0;i1&&1===o&&r.unshift(a)}return r},n.getReductionAxes=function(e,t){for(var n=[],r=0;r1)&&n.unshift(a)}return n},n.broadcastDimsAreOuter=function(e){for(var t=0;t1&&s>1&&o!==s)throw Error(r);n.unshift(Math.max(o,s))}return n}},{}],50:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./broadcast_util"),u=e("./operation"),l=function(){function e(){}return e.notEqual=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.notEqual(e,t)},{a:e,b:t})},e.notEqualStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in notEqualStrict: "),e.notEqual(t)},e.less=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.less(e,t)},{a:e,b:t})},e.lessStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in lessStrict: "),e.less(t)},e.equal=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.equal(e,t)},{a:e,b:t})},e.equalStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in equalStrict: "),e.equal(t)},e.lessEqual=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.lessEqual(e,t)},{a:e,b:t})},e.lessEqualStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in lessEqualStrict: "),e.lessEqual(t)},e.greater=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.greater(e,t)},{a:e,b:t})},e.greaterStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in greaterStrict: "),e.greater(t)},e.greaterEqual=function(e,t){return o.assertTypesMatch(e,t),s.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.greaterEqual(e,t)},{a:e,b:t})},e.greaterEqualStrict=function(e,t){return o.assertShapesMatch(e.shape,t.shape,"Error in greaterEqualStrict: "),e.greaterEqual(t)},r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"notEqual",null),r([u.operation],e,"notEqualStrict",null),r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"less",null),r([u.operation],e,"lessStrict",null),r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"equal",null),r([u.operation],e,"equalStrict",null),r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"lessEqual",null),r([u.operation],e,"lessEqualStrict",null),r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"greater",null),r([u.operation],e,"greaterStrict",null),r([i.doc({heading:"Operations",subheading:"Logical"}),u.operation],e,"greaterEqual",null),r([u.operation],e,"greaterEqualStrict",null),e}();n.CompareOps=l},{"../doc":3,"../environment":5,"../util":92,"./broadcast_util":49,"./operation":62}],51:[function(e,t,n){"use strict";function r(e,t,n){l.assertParams(e.shape,t.shape,n);var r=l.computeOutShape(e.shape,t.shape,n),i=e.as2D(-1,s.sizeFromShape(e.shape.slice(n))),a=t.as2D(-1,s.sizeFromShape(t.shape.slice(n))),u=l.computeGradientSliceShapes(i.shape,a.shape),c=u.aBegin,p=u.aSize,h=u.bBegin,d=u.bSize;return o.ENV.engine.runKernel(function(e){return e.concat(i,a)},{a:i,b:a},function(e){return{a:function(){return e.slice(c,p)},b:function(){return e.slice(h,d)}}}).reshape(r)}var i=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var a=e("../doc"),o=e("../environment"),s=e("../util"),u=e("./axis_util"),l=e("./concat_util"),c=e("./operation"),p=function(){function e(){}return e.concat1d=function(t){return e.concat(t,0)},e.concat2d=function(t,n){return e.concat(t,n)},e.concat3d=function(t,n){return e.concat(t,n)},e.concat4d=function(t,n){return e.concat(t,n)},e.concat=function(e,t){void 0===t&&(t=0),s.assert(e.length>=1,"Pass at least one tensor to concat");var n=e[0];if(1===e.length)return n;for(var i=u.parseAxisParam(t,n.shape),a=1;a=0&&n=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var s=e("../doc"),u=e("../environment"),l=e("../util"),c=e("./conv_util"),p=e("./operation"),h=function(){function e(){}return e.conv1d=function(t,n,r,i,o,s,u){void 0===o&&(o="NWC"),void 0===s&&(s=1);var c=t,p=!1;2===t.rank&&(p=!0,c=t.as3D(1,t.shape[0],t.shape[1])),l.assert(3===c.rank,"Error in conv1d: input must be rank 3, but got rank "+c.rank+"."),l.assert(3===n.rank,"Error in conv1d: filter must be rank 3, but got rank "+n.rank+"."),null!=u&&l.assert(l.isInt(i),"Error in conv1d: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+i+"."),l.assert(c.shape[2]===n.shape[1],"Error in conv1d: depth of input ("+c.shape[2]+") must match input depth for filter "+n.shape[1]+"."),l.assert(a(r,s),"Error in conv1D: Either stride or dilation must be 1.Got stride "+r+" and dilation '"+s+"'"),l.assert("NWC"===o,"Error in conv1d: got dataFormat of "+o+" but only NWC is currently supported.");var h=n.as4D(1,n.shape[0],n.shape[1],n.shape[2]),d=c.as4D(c.shape[0],1,c.shape[1],c.shape[2]),f=[1,r],g=[1,s],m=e.conv2d(d,h,f,i,"NHWC",g,u);return p?m.as2D(m.shape[2],m.shape[3]):m.as3D(m.shape[0],m.shape[2],m.shape[3])},e.conv2d=function(t,n,r,o,s,p,h){void 0===s&&(s="NHWC"),void 0===p&&(p=[1,1]);var d=t,f=!1;3===t.rank&&(f=!0,d=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),l.assert(4===d.rank,"Error in conv2d: input must be rank 4, but got rank "+d.rank+"."),l.assert(4===n.rank,"Error in conv2d: filter must be rank 4, but got rank "+n.rank+"."),null!=h&&l.assert(l.isInt(o),"Error in conv2d: pad must be an integer when using, dimRoundingMode "+h+" but got pad "+o+"."),l.assert(d.shape[3]===n.shape[2],"Error in conv2d: depth of input ("+d.shape[3]+") must match input depth for filter "+n.shape[2]+"."),l.assert(a(r,p),"Error in conv2D: Either strides or dilations must be 1.Got strides "+r+" and dilations '"+p+"'"),l.assert("NHWC"===s,"Error in conv2d: got dataFormat of "+s+" but only NHWC is currently supported.");var g=c.computeConv2DInfo(d.shape,n.shape,r,p,o,h),m=u.ENV.engine.runKernel(function(e){return e.conv2d(d,n,g)},{x:d,filter:n},function(t){return l.assert(i(p),"Error in gradient of conv2D: dilation rates greater than 1 are notyet supported in gradients. Got dilations '"+p+"'"),{x:function(){return e.conv2dDerInput(d.shape,t,n,r,o)},filter:function(){return e.conv2dDerFilter(d,t,n.shape,r,o)}}});return f?m.as3D(m.shape[1],m.shape[2],m.shape[3]):m},e.conv2dDerInput=function(e,t,n,r,i,a){l.assert(e.length===t.rank,"Length of inShape ("+e.length+") and rank of dy ("+t.rank+") must match");var o=e,s=t,p=!1;3===t.rank&&(p=!0,s=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]),o=[1,e[0],e[1],e[2]]);var h=o[3],d=s.shape[3];l.assert(4===o.length,"Error in conv2dDerInput: inShape must be length 4, but got length "+o.length+"."),l.assert(4===s.rank,"Error in conv2dDerInput: dy must be rank 4, but got rank "+s.rank),l.assert(4===n.rank,"Error in conv2dDerInput: filter must be rank 4, but got rank "+n.rank),l.assert(h===n.shape[2],"Error in conv2dDerInput: depth of input ("+h+") must match input depth for filter "+n.shape[2]+"."),l.assert(d===n.shape[3],"Error in conv2dDerInput: depth of output ("+d+") mustmatch output depth for filter "+n.shape[3]+"."),null!=a&&l.assert(l.isInt(i),"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+".");var f=c.computeConv2DInfo(o,n.shape,r,1,i,a),g=u.ENV.engine.runKernel(function(e){return e.conv2dDerInput(s,n,f)},{dy4D:s});return p?g.as3D(g.shape[1],g.shape[2],g.shape[3]):g},e.conv2dDerFilter=function(e,t,n,r,i,a){var o=e;3===e.rank&&(o=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]));var s=t;3===s.rank&&(s=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),l.assert(4===o.rank,"Error in conv2dDerFilter: input must be rank 4, but got shape "+o.shape+"."),l.assert(4===s.rank,"Error in conv2dDerFilter: dy must be rank 4, but got shape "+s.shape+"."),l.assert(4===n.length,"Error in conv2dDerFilter: filterShape must be length 4, but got "+n+"."),l.assert(o.shape[3]===n[2],"Error in conv2dDerFilter: depth of input "+o.shape[3]+") must match input depth in filter ("+n[2]+"."),l.assert(s.shape[3]===n[3],"Error in conv2dDerFilter: depth of dy ("+s.shape[3]+") must match output depth for filter ("+n[3]+")."),null!=a&&l.assert(l.isInt(i),"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+".");var p=c.computeConv2DInfo(o.shape,n,r,1,i,a);return u.ENV.engine.runKernel(function(e){return e.conv2dDerFilter(o,s,p)},{x4D:o,dy4D:s})},e.conv2dTranspose=function(t,n,r,i,a,o){return e.conv2dDerInput(r,t,n,i,a,o)},e.depthwiseConv2d=function(e,t,n,r,i,o,s){void 0===i&&(i="NHWC"),void 0===o&&(o=[1,1]);var p=e,h=!1;3===e.rank&&(h=!0,p=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),l.assert(4===p.rank,"Error in depthwiseConv2D: input must be rank 4, but got rank "+p.rank+"."),l.assert(4===t.rank,"Error in depthwiseConv2D: filter must be rank 4, but got rank "+t.rank+"."),l.assert(p.shape[3]===t.shape[2],"Error in depthwiseConv2D: number of input channels ("+p.shape[3]+") must match the inChannels dimension in filter "+t.shape[2]+"."),null==o&&(o=[1,1]),l.assert(a(n,o),"Error in depthwiseConv2d: Either strides or dilations must be 1.Got strides "+n+" and dilations '"+o+"'"),null!=s&&l.assert(l.isInt(r),"Error in depthwiseConv2D: pad must be an integer when using, dimRoundingMode "+s+" but got pad "+r+".");var d=c.computeConv2DInfo(p.shape,t.shape,n,o,r,s,!0),f=u.ENV.engine.runKernel(function(e){return e.depthwiseConv2D(p,t,d)},{input4D:p,filter:t});return h?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f},e.separableConv2d=function(t,n,r,i,a,o,s){void 0===o&&(o=[1,1]),void 0===s&&(s="NHWC");var u=t,c=!1;if(3===t.rank&&(c=!0,u=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),"NCHW"===s)throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");l.assert(4===u.rank,"Error in separableConv2d: input must be rank 4, but got rank "+u.rank+"."),l.assert(4===n.rank,"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+n.rank+"."),l.assert(4===r.rank,"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+n.rank+"."),l.assert(1===r.shape[0],"Error in separableConv2d: the first dimension of pointwise filter must be 1, but got "+r.shape[0]+"."),l.assert(1===r.shape[1],"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+r.shape[1]+".");var p=n.shape[2],h=n.shape[3];l.assert(r.shape[2]===p*h,"Error in separableConv2d: the third dimension of pointwise filter must be "+p*h+", but got "+r.shape[2]+".");var d=e.depthwiseConv2d(u,n,i,a,s,o),f=e.conv2d(d,r,1,"valid",s);return c?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f},o([s.doc({heading:"Operations",subheading:"Convolution"}),p.operation],e,"conv1d",null),o([s.doc({heading:"Operations",subheading:"Convolution"}),p.operation],e,"conv2d",null),o([p.operation],e,"conv2dDerInput",null),o([p.operation],e,"conv2dDerFilter",null),o([s.doc({heading:"Operations",subheading:"Convolution"}),p.operation],e,"conv2dTranspose",null),o([s.doc({heading:"Operations",subheading:"Convolution"}),p.operation],e,"depthwiseConv2d",null),o([s.doc({heading:"Operations",subheading:"Convolution"}),p.operation],e,"separableConv2d",null),e}();n.ConvOps=h},{"../doc":3,"../environment":5,"../util":92,"./conv_util":54,"./operation":62}],54:[function(e,t,n){"use strict";function r(e,t,n,r,i,a,l,c){void 0===l&&(l=!1),void 0===c&&(c="channelsLast");var p=[-1,-1,-1,-1],h=p[0],d=p[1],f=p[2],g=p[3];if("channelsLast"===c)h=e[0],d=e[1],f=e[2],g=e[3];else{if("channelsFirst"!==c)throw new Error("Unknown dataFormat "+c);h=e[0],g=e[1],d=e[2],f=e[3]}var m,v=t[0],y=t[1],b=t[3],w=o(n),x=w[0],E=w[1],_=o(r),A=_[0],S=_[1],O=u(i,d,f,x,E,s(v,A),s(y,S),a),T=O.padInfo,k=O.outHeight,C=O.outWidth,N=l?b*g:b;return"channelsFirst"===c?m=[h,N,k,C]:"channelsLast"===c&&(m=[h,k,C,N]),{batchSize:h,dataFormat:c,inHeight:d,inWidth:f,inChannels:g,outHeight:k,outWidth:C,outChannels:N,padInfo:T,strideHeight:x,strideWidth:E,filterHeight:v,filterWidth:y,dilationHeight:A,dilationWidth:S,inShape:e,outShape:m,filterShape:t}}function i(e,t,n,r,i,o){null==i&&(i=a(e,t,r));var s=e[0],u=e[1],p=l((s-t+2*i)/r+1,o);c.assert(c.isInt(p),"The output # of rows ("+p+") must be an integer. Change the stride and/or zero pad parameters");var h=l((u-t+2*i)/r+1,o);return c.assert(c.isInt(h),"The output # of columns ("+h+") must be an integer. Change the stride and/or zero pad parameters"),[p,h,n]}function a(e,t,n,r){void 0===r&&(r=1);var i=s(t,r);return Math.floor((e[0]*(n-1)-n+i)/2)}function o(e){return"number"==typeof e?[e,e]:e}function s(e,t){return t<=1?e:e+(e-1)*(t-1)}function u(e,t,n,r,a,o,s,u){var l,c,p;if("number"==typeof e){l={top:e,bottom:e,left:e,right:e};var h=i([t,n,1],o,1,r,e,u);c=h[0],p=h[1]}else if("same"===e){var d=((c=Math.ceil(t/r))-1)*r+o-t,f=((p=Math.ceil(n/a))-1)*a+s-n,g=Math.floor(d/2),m=d-g,v=Math.floor(f/2);l={top:g,bottom:m,left:v,right:f-v}}else{if("valid"!==e)throw Error("Unknown padding parameter: "+e);l={top:0,bottom:0,left:0,right:0},c=Math.ceil((t-o+1)/r),p=Math.ceil((n-s+1)/a)}return{padInfo:l,outHeight:c,outWidth:p}}function l(e,t){if(!t)return e;switch(t){case"round":return Math.round(e);case"ceil":return Math.ceil(e);case"floor":return Math.floor(e);default:throw new Error("Unknown roundingMode "+t)}}Object.defineProperty(n,"__esModule",{value:!0});var c=e("../util");n.computePool2DInfo=function(e,t,n,i,a,s){void 0===s&&(s="channelsLast");var u,l=o(t),c=l[0],p=l[1];if("channelsLast"===s)u=[c,p,e[3],e[3]];else{if("channelsFirst"!==s)throw new Error("Unknown dataFormat "+s);u=[c,p,e[1],e[1]]}return r(e,u,n,1,i,a,!1,s)},n.computeConv2DInfo=r,n.computeDefaultPad=a},{"../util":92}],55:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./operation"),u=function(){function e(){}return e.resizeBilinear=function(e,t,n){void 0===n&&(n=!1),o.assert(3===e.rank||4===e.rank,"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+e.rank+"."),o.assert(2===t.length,"Error in resizeBilinear: new shape must 2D, but got shape "+t+".");var r=e,i=!1;3===e.rank&&(i=!0,r=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]));var s=t[0],u=t[1],l=a.ENV.engine.runKernel(function(e){return e.resizeBilinear(r,s,u,n)},{batchImages:r});return i?l.as3D(l.shape[1],l.shape[2],l.shape[3]):l},r([i.doc({heading:"Operations",subheading:"Images",namespace:"image"}),s.operation],e,"resizeBilinear",null),e}();n.ImageOps=u},{"../doc":3,"../environment":5,"../util":92,"./operation":62}],56:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../types"),s=e("../util"),u=e("./broadcast_util"),l=e("./operation"),c=function(){function e(){}return e.logicalNot=function(e){return s.assert("bool"===e.dtype,"Error Array must be of type bool."),a.ENV.engine.runKernel(function(t){return t.logicalNot(e)},{x:e})},e.logicalAnd=function(e,t){return s.assert("bool"===e.dtype&&"bool"===t.dtype,"Error Array must be of type bool."),u.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.logicalAnd(e,t)},{a:e,b:t})},e.logicalOr=function(e,t){return s.assert("bool"===e.dtype&&"bool"===t.dtype,"Error Array must be of type bool."),u.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.logicalOr(e,t)},{a:e,b:t})},e.logicalXor=function(e,t){return s.assert("bool"===e.dtype&&"bool"===t.dtype,"Error Array must be of type bool."),u.assertAndGetBroadcastShape(e.shape,t.shape),a.ENV.engine.runKernel(function(n){return n.logicalXor(e,t)},{a:e,b:t})},e.where=function(e,t,n){s.assert("bool"===e.dtype||"bool"===t.dtype||"bool"===n.dtype,"Error Array must be of type bool."),s.assertShapesMatch(t.shape,n.shape,"Error in where: "),1===e.rank?s.assert(e.shape[0]===t.shape[0],"The first dimension of `a` must match the size of `condition`."):s.assertShapesMatch(e.shape,n.shape,"Error in where: ");var r=o.upcastType(t.dtype,n.dtype);return a.ENV.engine.runKernel(function(i){return i.where(e,t,n,r)},{condition:e,a:t,b:n})},r([i.doc({heading:"Operations",subheading:"Logical"}),l.operation],e,"logicalNot",null),r([i.doc({heading:"Operations",subheading:"Logical"}),l.operation],e,"logicalAnd",null),r([i.doc({heading:"Operations",subheading:"Logical"}),l.operation],e,"logicalOr",null),r([i.doc({heading:"Operations",subheading:"Logical"}),l.operation],e,"logicalXor",null),r([i.doc({heading:"Operations",subheading:"Logical"}),l.operation],e,"where",null),e}();n.LogicalOps=c},{"../doc":3,"../environment":5,"../types":91,"../util":92,"./broadcast_util":49,"./operation":62}],57:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i,a=e("../doc"),o=e("../util"),s=e("./operation"),u=e("./ops");!function(e){e[e.NONE=0]="NONE",e[e.MEAN=1]="MEAN",e[e.SUM=2]="SUM",e[e.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"}(i=n.Reduction||(n.Reduction={}));var l=function(){function e(){}return e.computeWeightedLoss=function(e,t,n){void 0===n&&(n=i.SUM_BY_NONZERO_WEIGHTS);var r=null==t?e:e.mul(t);if(n===i.NONE)return r;if(n===i.SUM)return r.sum();if(n===i.MEAN)return null==t?r.mean():r.sum().div(t.sum());if(n===i.SUM_BY_NONZERO_WEIGHTS){if(null==t)return r.sum().div(u.scalar(e.size));var a=t.notEqual(u.scalar(0)).sum().toFloat();return r.sum().div(a)}throw Error("Unknown reduction: "+n)},e.absoluteDifference=function(t,n,r,a){void 0===a&&(a=i.SUM_BY_NONZERO_WEIGHTS),o.assertShapesMatch(t.shape,n.shape,"Error in absoluteDifference: ");var s=t.sub(n).abs();return e.computeWeightedLoss(s,r,a)},r([a.doc({heading:"Training",subheading:"Losses",namespace:"losses"}),s.operation],e,"computeWeightedLoss",null),r([a.doc({heading:"Training",subheading:"Losses",namespace:"losses"}),s.operation],e,"absoluteDifference",null),e}();n.LossOps=l},{"../doc":3,"../util":92,"./operation":62,"./ops":63}],58:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./operation"),u=function(){function e(){}return e.localResponseNormalization=function(e,t,n,r,i,s){void 0===t&&(t=5),void 0===n&&(n=1),void 0===r&&(r=1),void 0===i&&(i=.5),void 0===s&&(s="acrossChannels"),o.assert(4===e.rank||3===e.rank,"Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank "+e.rank+"."),o.assert(o.isInt(t),"Error in localResponseNormalization3D: radius must be an integer\n but got radius "+t+".");var u=e,l=!1;3===e.rank&&(l=!0,u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]));var c=a.ENV.engine.runKernel(function(e){return e.localResponseNormalization4D(u,t,n,r,i,s)},{x4D:u});return l?c.as3D(c.shape[1],c.shape[2],c.shape[3]):c},r([i.doc({heading:"Operations",subheading:"Normalization"}),s.operation],e,"localResponseNormalization",null),e}();n.LRNOps=u},{"../doc":3,"../environment":5,"../util":92,"./operation":62}],59:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("./operation"),o=function(){function e(){}return e.multiRNNCell=function(e,t,n,r){for(var i=t,a=[],o=0;o=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./operation"),u=function(){function e(){}return e.matMul=function(e,t,n,r){void 0===n&&(n=!1),void 0===r&&(r=!1);var i=n?e.shape[0]:e.shape[1],s=r?t.shape[1]:t.shape[0];o.assert(2===e.rank&&2===t.rank,"Error in matMul: inputs must be rank 2, got ranks "+e.rank+" and "+t.rank+"."),o.assert(i===s,"Error in matMul: inner shapes ("+i+") and ("+s+") of Tensors with shapes "+e.shape+" and "+t.shape+" and transposeA="+n+" and transposeB="+r+" must match.");return a.ENV.engine.runKernel(function(i){return i.matMul(e,t,n,r)},{a:e,b:t},function(i){if(n||r)throw new Error("Backprop for transposed MatMul not yet implemented.");return{a:function(){return i.matMul(t.toFloat(),!1,!0)},b:function(){return e.toFloat().matMul(i,!0,!1)}}})},e.vectorTimesMatrix=function(e,t){return o.assert(1===e.rank,"Error in vectorTimesMatrix: first input must be rank 1, but got rank "+e.rank+"."),o.assert(2===t.rank,"Error in vectorTimesMatrix: second input must be rank 2, but got rank "+t.rank+"."),o.assert(e.size===t.shape[0],"Error in vectorTimesMatrix: size of vector ("+e.size+") must match first dimension of matrix ("+t.shape[0]+")"),e.as2D(1,-1).matMul(t).as1D()},e.matrixTimesVector=function(e,t){return o.assert(1===t.rank,"Error in matrixTimesVector: second input must rank 1, but got rank "+t.rank+"."),o.assert(2===e.rank,"Error in matrixTimesVector: first input must be a rank 2, but got rank "+e.rank+"."),o.assert(t.size===e.shape[1],"Error in matrixTimesVector: size of first rank 1 input "+t.size+" must match inner dimension of second rank 2 input, but got shape "+e.shape+"."),e.matMul(t.as2D(-1,1)).as1D()},e.dotProduct=function(e,t){return o.assert(1===e.rank&&1===t.rank,"Error in dotProduct: inputs must be rank 1, but got ranks "+e.rank+" and "+t.rank+"."),o.assert(e.size===t.size,"Error in dotProduct: size of inputs ("+e.size+") and ("+t.size+") must match."),e.as2D(1,-1).matMul(t.as2D(-1,1)).asScalar()},e.outerProduct=function(e,t){return o.assert(1===e.rank&&1===t.rank,"Error in outerProduct: inputs must be rank 1, but got ranks "+e.rank+" and "+t.rank+"."),e.as2D(-1,1).matMul(t.as2D(1,-1))},r([i.doc({heading:"Operations",subheading:"Matrices"}),s.operation],e,"matMul",null),r([s.operation],e,"vectorTimesMatrix",null),r([s.operation],e,"matrixTimesVector",null),r([s.operation],e,"dotProduct",null),r([i.doc({heading:"Operations",subheading:"Matrices"}),s.operation],e,"outerProduct",null),e}();n.MatmulOps=u},{"../doc":3,"../environment":5,"../util":92,"./operation":62}],61:[function(e,t,n){"use strict";function r(e,t,n){if(void 0===n&&(n=null),0===e.rank)return e.abs();if(1!==e.rank&&null===n)return r(e.reshape([-1]),t,n);if(1===e.rank||"number"==typeof n||n instanceof Array&&1===n.length){if(1===t)return e.abs().sum(n);if(t===1/0)return e.abs().max(n);if(t===-1/0)return e.abs().min(n);if("euclidean"===t||2===t)return e.abs().pow(u.scalar(2,"int32")).sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+t)}if(n instanceof Array&&2===n.length){if(1===t)return e.abs().sum(n[0]).max(n[1]-1);if(t===1/0)return e.abs().sum(n[1]).max(n[0]);if(t===-1/0)return e.abs().sum(n[1]).min(n[0]);if("fro"===t||"euclidean"===t)return e.square().sum(n).sqrt();throw new Error("Error in norm: invalid ord value: "+t)}throw new Error("Error in norm: invalid axis: "+n)}var i=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var a=e("../doc"),o=e("./axis_util"),s=e("./operation"),u=e("./ops"),l=function(){function e(){}return e.norm=function(e,t,n,i){void 0===t&&(t="euclidean"),void 0===n&&(n=null),void 0===i&&(i=!1);var a=r(e,t,n),s=a.shape;if(i){var u=o.parseAxisParam(n,e.shape);s=o.expandShapeToKeepDim(a.shape,u)}return a.reshape(s)},i([a.doc({heading:"Operations",subheading:"Matrices"}),s.operation],e,"norm",null),e}();n.NormOps=l},{"../doc":3,"./axis_util":46,"./operation":62,"./ops":63}],62:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("../globals");n.operation=function(e,t,n){var i=n.value;return n.value=function(){for(var e=[],n=0;n=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./conv_util"),u=e("./operation"),l=function(){function e(){}return e.maxPool=function(t,n,r,i,u){var l=t,c=!1;3===t.rank&&(c=!0,l=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),o.assert(4===l.rank,"Error in maxPool: input must be rank 4 but got rank "+l.rank+"."),null!=u&&o.assert(o.isInt(i),"Error in maxPool: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+i+".");var p=s.computePool2DInfo(l.shape,n,r,i,u),h=a.ENV.engine.runKernel(function(e){return e.maxPool(l,p)},{x:l},function(t){return{x:function(){return e.maxPoolBackprop(t,l,n,r,i)}}});return c?h.as3D(h.shape[1],h.shape[2],h.shape[3]):h},e.maxPoolBackprop=function(e,t,n,r,i,u){o.assert(t.rank===e.rank,"Rank of input ("+t.rank+") does not match rank of dy ("+e.rank+")");var l=t,c=e,p=!1;3===t.rank&&(p=!0,l=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]),c=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),o.assert(4===c.rank,"Error in maxPoolBackprop: dy must be rank 4 but got rank "+c.rank+"."),o.assert(4===l.rank,"Error in maxPoolBackprop: input must be rank 4 but got rank "+l.rank+"."),null!=u&&o.assert(o.isInt(i),"Error in maxPoolBackprop: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+i+".");var h=s.computePool2DInfo(l.shape,n,r,i,u),d=a.ENV.engine.runKernel(function(e){return e.maxPoolBackprop(c,l,h)},{dy4D:c,input4D:l});return p?d.as3D(d.shape[1],d.shape[2],d.shape[3]):d},e.minPool=function(e,t,n,r,i){var u=e,l=!1;3===e.rank&&(l=!0,u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),o.assert(4===u.rank,"Error in minPool: x must be rank 4 but got rank "+u.rank+"."),null!=i&&o.assert(o.isInt(r),"Error in minPool: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+".");var c=s.computePool2DInfo(u.shape,t,n,r,i),p=a.ENV.engine.runKernel(function(e){return e.minPool(u,c)},{input4D:u});return l?p.as3D(p.shape[1],p.shape[2],p.shape[3]):p},e.avgPool=function(t,n,r,i,u){var l=t,c=!1;3===t.rank&&(c=!0,l=t.as4D(1,t.shape[0],t.shape[1],t.shape[2])),o.assert(4===l.rank,"Error in avgPool: x must be rank 4 but got rank "+l.rank+"."),null!=u&&o.assert(o.isInt(i),"Error in avgPool: pad must be an integer when using, dimRoundingMode "+u+" but got pad "+i+".");var p=s.computePool2DInfo(l.shape,n,r,i),h=a.ENV.engine.runKernel(function(e){return e.avgPool(l,p)},{x:l},function(t){return{x:function(){return e.avgPoolBackprop(t,l,n,r,i)}}});return c?h.as3D(h.shape[1],h.shape[2],h.shape[3]):h},e.avgPoolBackprop=function(e,t,n,r,i){o.assert(t.rank===e.rank,"Rank of input ("+t.rank+") does not match rank of dy ("+e.rank+")");var u=t,l=e,c=!1;3===t.rank&&(c=!0,u=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]),l=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),o.assert(4===l.rank,"Error in avgPoolBackprop: dy must be rank 4 but got rank "+l.rank+"."),o.assert(4===u.rank,"Error in avgPoolBackprop: input must be rank 4 but got rank "+u.rank+".");var p=s.computePool2DInfo(u.shape,n,r,i),h=a.ENV.engine.runKernel(function(e){return e.avgPoolBackprop(l,u,p)},{dy4D:l,input4D:u});return c?h.as3D(h.shape[1],h.shape[2],h.shape[3]):h},r([i.doc({heading:"Operations",subheading:"Convolution"}),u.operation],e,"maxPool",null),r([u.operation],e,"maxPoolBackprop",null),r([i.doc({heading:"Operations",subheading:"Convolution"}),u.operation],e,"minPool",null),r([i.doc({heading:"Operations",subheading:"Convolution"}),u.operation],e,"avgPool",null),r([u.operation],e,"avgPoolBackprop",null),e}();n.PoolOps=l},{"../doc":3,"../environment":5,"../util":92,"./conv_util":54,"./operation":62}],65:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("seedrandom"),i=function(){function e(e,t,n,i,a){this.mean=e,this.stdDev=t,this.dtype=n,this.nextVal=NaN,this.truncated=i,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var o=a||Math.random();this.random=r.alea(o.toString())}return e.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var e=this.nextVal;return this.nextVal=NaN,e}for(var t,n,r=!1;!r;){var i=void 0,a=void 0,o=void 0;do{o=(i=2*this.random()-1)*i+(a=2*this.random()-1)*a}while(o>=1||0===o);var s=Math.sqrt(-2*Math.log(o)/o);t=this.mean+this.stdDev*i*s,n=this.mean+this.stdDev*a*s,this.truncated&&!this.isValidTruncated(t)||(r=!0)}return this.truncated&&!this.isValidTruncated(n)||(this.nextVal=this.convertValue(n)),this.convertValue(t)},e.prototype.convertValue=function(e){return null==this.dtype||"float32"===this.dtype?e:Math.round(e)},e.prototype.isValidTruncated=function(e){return e<=this.upper&&e>=this.lower},e}();n.MPRandGauss=i},{seedrandom:132}],66:[function(e,t,n){"use strict";function r(e,t){for(var n=t;n=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../globals"),s=e("../util"),u=e("./axis_util"),l=e("./operation"),c=e("./ops"),p=function(){function e(){}return e.logSumExp=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape),i=e.max(r,!0),a=e.sub(i).exp().sum(r).log(),o=i.reshape(a.shape).add(a);if(n){var s=u.expandShapeToKeepDim(o.shape,r);return o.reshape(s)}return o},e.sum=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape);return o.customGrad(function(e){var t=u.getAxesPermutation(r,e.rank),i=r,o=e;null!=t&&(o=e.transpose(t),i=u.getInnerMostAxes(i.length,e.rank));var s=a.ENV.engine.runKernel(function(e){return e.sum(o,i)},{permutedX:o});if(n){var l=u.expandShapeToKeepDim(s.shape,r);s=s.reshape(l)}return{value:s,gradFunc:function(t){var n=e.shape.slice();return r.forEach(function(e){n[e]=1}),t.reshape(n).mul(c.ones(e.shape,"float32"))}}})(e)},e.mean=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape),i=u.computeOutAndReduceShapes(e.shape,r)[1],a=s.sizeFromShape(i);return o.customGrad(function(e){var i=c.scalar(a);return{value:(i.dtype===e.dtype?e:e.cast(i.dtype)).div(i).sum(t,n),gradFunc:function(t){var n=e.shape.slice();return r.forEach(function(e){n[e]=1}),t.reshape(n).mul(c.ones(e.shape,"float32")).div(i)}}})(e)},e.min=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape),i=r,o=u.getAxesPermutation(i,e.rank);null!=o&&(e=e.transpose(o),i=u.getInnerMostAxes(i.length,e.rank));var s=a.ENV.engine.runKernel(function(t){return t.min(e,i)},{x:e});if(n){var l=u.expandShapeToKeepDim(s.shape,r);return s.reshape(l)}return s},e.max=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape),i=r,o=u.getAxesPermutation(i,e.rank);null!=o&&(e=e.transpose(o),i=u.getInnerMostAxes(i.length,e.rank));var s=a.ENV.engine.runKernel(function(t){return t.max(e,i)},{x:e});if(n){var l=u.expandShapeToKeepDim(s.shape,r);return s.reshape(l)}return s},e.argMin=function(e,t){void 0===t&&(t=null);var n=u.parseAxisParam(t,e.shape),r=u.getAxesPermutation(n,e.rank);return null!=r&&(e=e.transpose(r),n=u.getInnerMostAxes(n.length,e.rank)),a.ENV.engine.runKernel(function(t){return t.argMin(e,n)},{x:e})},e.argMax=function(e,t){void 0===t&&(t=null);var n=u.parseAxisParam(t,e.shape),r=u.getAxesPermutation(n,e.rank);return null!=r&&(e=e.transpose(r),n=u.getInnerMostAxes(n.length,e.rank)),a.ENV.engine.runKernel(function(t){return t.argMax(e,n)},{x:e})},e.moments=function(e,t,n){void 0===t&&(t=null),void 0===n&&(n=!1);var r=u.parseAxisParam(t,e.shape),i=e.mean(r,n),a=i.shape;return n||(a=u.expandShapeToKeepDim(i.shape,r)),{mean:i,variance:e.toFloat().sub(i.reshape(a)).square().mean(r,n)}},r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"logSumExp",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"sum",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"mean",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"min",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"max",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"argMin",null),r([i.doc({heading:"Operations",subheading:"Reduction"}),l.operation],e,"argMax",null),r([i.doc({heading:"Operations",subheading:"Normalization"}),l.operation],e,"moments",null),e}();n.ReductionOps=p},{"../doc":3,"../environment":5,"../globals":6,"../util":92,"./axis_util":46,"./operation":62,"./ops":63}],68:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./axis_util"),u=e("./operation"),l=function(){function e(){}return e.reverse1d=function(t){return o.assert(1===t.rank,"Error in reverse1D: x must be rank 1 but got\n rank "+t.rank+"."),e.reverse(t,0)},e.reverse2d=function(t,n){return o.assert(2===t.rank,"Error in reverse2D: x must be rank 2 but got\n rank "+t.rank+"."),e.reverse(t,n)},e.reverse3d=function(t,n){return o.assert(3===t.rank,"Error in reverse3D: x must be rank 3 but got\n rank "+t.rank+"."),e.reverse(t,n)},e.reverse4d=function(t,n){return o.assert(4===t.rank,"Error in reverse4D: x must be rank 4 but got\n rank "+t.rank+"."),e.reverse(t,n)},e.reverse=function(e,t){if(0===e.rank)return e.clone();var n=s.parseAxisParam(t,e.shape);return a.ENV.engine.runKernel(function(t){return t.reverse(e,n)},{x:e},function(e){return{x:function(){return e.reverse(n)}}}).reshapeAs(e)},r([i.doc({heading:"Tensors",subheading:"Slicing and Joining"}),u.operation],e,"reverse",null),e}();n.ReverseOps=l},{"../doc":3,"../environment":5,"../util":92,"./axis_util":46,"./operation":62}],69:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.SELU_SCALEALPHA=1.7580993408473768,n.SELU_SCALE=1.0507009873554805},{}],70:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./operation"),u=e("./slice_util"),l=function(){function e(){}return e.slice1d=function(t,n,r){return o.assert(1===t.rank,"slice1d expects a rank-1 tensor, but got a rank-"+t.rank+" tensor"),e.slice(t,[n],[r])},e.slice2d=function(t,n,r){return o.assert(2===t.rank,"slice1d expects a rank-2 tensor, but got a rank-"+t.rank+" tensor"),e.slice(t,n,r)},e.slice3d=function(t,n,r){return o.assert(3===t.rank,"slice1d expects a rank-3 tensor, but got a rank-"+t.rank+" tensor"),e.slice(t,n,r)},e.slice4d=function(t,n,r){return o.assert(4===t.rank,"slice1d expects a rank-4 tensor, but got a rank-"+t.rank+" tensor"),e.slice(t,n,r)},e.slice=function(e,t,n){if(u.assertParamsValid(e,t,n),0===e.rank)throw new Error("Slicing scalar is not possible");var r=e.shape;return a.ENV.engine.runKernel(function(r){return r.slice(e,t,n)},{x:e},function(e){for(var i=[],a=0;a=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../globals"),o=e("../util"),s=e("./axis_util"),u=e("./operation"),l=e("./ops"),c=function(){function e(){}return e.softmax=function(e,t){if(void 0===t&&(t=-1),-1===t&&(t=e.rank-1),t!==e.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+e.rank+" and dim was "+t);return a.customGrad(function(e){var n=e.logSumExp([t],!0),r=e.toFloat().sub(n).exp();return{value:r,gradFunc:function(e){var n=e.mul(r);return n.sub(n.sum([t],!0).mul(r))}}})(e)},e.softmaxCrossEntropy=function(e,t,n){if(void 0===n&&(n=-1),o.assertShapesMatch(e.shape,t.shape,"Error in softmaxCrossEntropy: "),-1===n&&(n=t.rank-1),n!==t.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+t.rank+" and dim was "+n);return a.customGrad(function(e,t){var r=t.softmax(n);return{value:l.scalar(1e-5).add(r).log().mul(e).neg().sum([n]),gradFunc:function(t){var i=s.expandShapeToKeepDim(t.shape,[n]);return[t.reshape(i).mul(e.toFloat().sub(r)),t.reshape(i).mul(r.sub(e.toFloat()))]}}})(e,t)},r([i.doc({heading:"Operations",subheading:"Normalization"}),u.operation],e,"softmax",null),r([i.doc({heading:"Training",subheading:"Losses",namespace:"losses"}),u.operation],e,"softmaxCrossEntropy",null),e}();n.SoftmaxOps=c},{"../doc":3,"../globals":6,"../util":92,"./axis_util":46,"./operation":62,"./ops":63}],73:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../environment"),o=e("../util"),s=e("./axis_util"),u=e("./operation"),l=function(){function e(){}return e.transpose=function(e,t){null==t&&(t=e.shape.map(function(e,t){return t}).reverse());return o.assert(e.rank===t.length,"Error in transpose: rank of input "+e.rank+" must match length of perm "+t+"."),a.ENV.engine.runKernel(function(n){return n.transpose(e,t)},{x:e},function(e){var n=s.getUndoAxesPermutation(t);return{x:function(){return e.transpose(n)}}})},r([i.doc({heading:"Operations",subheading:"Matrices"}),u.operation],e,"transpose",null),e}();n.TransposeOps=l},{"../doc":3,"../environment":5,"../util":92,"./axis_util":46,"./operation":62}],74:[function(e,t,n){"use strict";function r(e,t){return s.ENV.engine.runKernel(function(n){return n.preluDer(e,t)},{x:e,alpha:t})}function i(e){return s.ENV.engine.runKernel(function(t){return t.eluDer(e)},{x:e})}var a=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var o=e("../doc"),s=e("../environment"),u=e("../util"),l=e("./operation"),c=e("./ops"),p=e("./ops"),h=e("./selu_util"),d=function(){function e(){}return e.neg=function(e){return s.ENV.engine.runKernel(function(t){return t.neg(e)},{x:e},function(e){return{x:function(){return e.neg()}}})},e.ceil=function(e){return s.ENV.engine.runKernel(function(t){return t.ceil(e)},{x:e},function(e){return{x:function(){return c.zerosLike(e)}}})},e.floor=function(e){return s.ENV.engine.runKernel(function(t){return t.floor(e)},{x:e},function(e){return{x:function(){return c.zerosLike(e)}}})},e.sign=function(e){return s.ENV.engine.runKernel(function(t){return t.sign(e)},{x:e},function(e){return{x:function(){return c.zerosLike(e)}}})},e.round=function(e){return s.ENV.engine.runKernel(function(t){return t.round(e)},{x:e},function(e){return{x:function(){return c.zerosLike(e)}}})},e.exp=function(e){return s.ENV.engine.runKernel(function(t,n){return n(t.exp(e))},{x:e},function(e,t){var n=t[0];return{x:function(){return e.mulStrict(n)}}})},e.expm1=function(e){return s.ENV.engine.runKernel(function(t){return t.expm1(e)},{x:e},function(t){return{x:function(){return t.mulStrict(e.exp())}}})},e.log=function(e){return s.ENV.engine.runKernel(function(t){return t.log(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.toFloat())}}})},e.log1p=function(e){return s.ENV.engine.runKernel(function(t){return t.log1p(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.add(c.scalar(1)))}}})},e.sqrt=function(e){return s.ENV.engine.runKernel(function(t){return t.sqrt(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.toFloat().sqrt().mul(c.scalar(2)))}}})},e.rsqrt=function(e){return s.ENV.engine.runKernel(function(t){return t.rsqrt(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.pow(c.scalar(1.5)).mul(c.scalar(2))).neg()}}})},e.square=function(e){return s.ENV.engine.runKernel(function(t){return t.square(e)},{x:e},function(t){return{x:function(){return t.mulStrict(e.toFloat().mul(c.scalar(2)))}}})},e.reciprocal=function(e){return s.ENV.engine.runKernel(function(t){return t.reciprocal(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.square().neg())}}})},e.abs=function(e){return s.ENV.engine.runKernel(function(t){return t.abs(e)},{x:e},function(t){return{x:function(){return t.mulStrict(e.toFloat().step(-1))}}})},e.clipByValue=function(e,t,n){u.assert(t<=n,"Error in clip: min ("+t+") must beless than or equal to max ("+n+").");return s.ENV.engine.runKernel(function(r){return r.clip(e,t,n)},{x:e},function(r){return{x:function(){return r.where(e.greater(c.scalar(t)).logicalAnd(e.less(c.scalar(n))),p.zerosLike(r))}}})},e.relu=function(e){return s.ENV.engine.runKernel(function(t){return t.relu(e)},{x:e},function(t){var n=e.step();return{x:function(){return t.mulStrict(n.toFloat())}}})},e.elu=function(e){return s.ENV.engine.runKernel(function(t){return t.elu(e)},{x:e},function(t){return{x:function(){return t.mulStrict(i(e))}}})},e.selu=function(e){return s.ENV.engine.runKernel(function(t){return t.selu(e)},{x:e},function(t){return{x:function(){var n=e.greater(c.scalar(0)),r=c.scalar(h.SELU_SCALEALPHA),i=c.scalar(h.SELU_SCALE),a=t.mul(i),o=t.mul(r).mul(e.toFloat().exp());return c.where(n,a,o)}}})},e.leakyRelu=function(e,t){void 0===t&&(t=.2);return s.ENV.engine.runKernel(function(n){return n.leakyRelu(e,t)},{x:e},function(n){return{x:function(){return n.mulStrict(e.step(t))}}})},e.prelu=function(e,t){return s.ENV.engine.runKernel(function(n){return n.prelu(e,t)},{x:e},function(n){return{x:function(){return n.mulStrict(r(e,t))}}})},e.sigmoid=function(e){return s.ENV.engine.runKernel(function(t,n){return n(t.sigmoid(e))},{x:e},function(e,t){var n=t[0];return{x:function(){return e.mulStrict(n.mul(c.scalar(1).sub(n)))}}})},e.sin=function(e){return s.ENV.engine.runKernel(function(t){return t.sin(e)},{x:e},function(t){return{x:function(){return e.toFloat().cos().mulStrict(t)}}})},e.cos=function(e){return s.ENV.engine.runKernel(function(t){return t.cos(e)},{x:e},function(t){return{x:function(){return e.toFloat().sin().neg().mulStrict(t)}}})},e.tan=function(e){return s.ENV.engine.runKernel(function(t){return t.tan(e)},{x:e},function(t){return{x:function(){return t.divStrict(e.cos().square())}}})},e.asin=function(t){return s.ENV.engine.runKernel(function(e){return e.asin(t)},{x:t},function(n){return{x:function(){return n.divStrict(e.sqrt(c.scalar(1).sub(t.toFloat().square())))}}})},e.acos=function(t){return s.ENV.engine.runKernel(function(e){return e.acos(t)},{x:t},function(n){return{x:function(){return n.divStrict(e.sqrt(c.scalar(1).sub(t.toFloat().square()))).neg()}}})},e.atan=function(e){return s.ENV.engine.runKernel(function(t){return t.atan(e)},{x:e},function(t){return{x:function(){return t.divStrict(c.scalar(1).add(e.toFloat().square()))}}})},e.sinh=function(e){return s.ENV.engine.runKernel(function(t){return t.sinh(e)},{x:e},function(t){return{x:function(){return e.toFloat().cosh().mulStrict(t)}}})},e.cosh=function(e){return s.ENV.engine.runKernel(function(t){return t.cosh(e)},{x:e},function(t){return{x:function(){return e.toFloat().sinh().mulStrict(t)}}})},e.tanh=function(e){return s.ENV.engine.runKernel(function(t,n){return n(t.tanh(e))},{x:e},function(e,t){var n=t[0];return{x:function(){return c.scalar(1).sub(n.square()).mulStrict(e)}}})},e.asinh=function(t){return s.ENV.engine.runKernel(function(e){return e.asinh(t)},{x:t},function(n){return{x:function(){return n.divStrict(e.sqrt(c.scalar(1).add(t.toFloat().square())))}}})},e.acosh=function(t){return s.ENV.engine.runKernel(function(e){return e.acosh(t)},{x:t},function(n){return{x:function(){return n.divStrict(e.sqrt(t.toFloat().square().sub(c.scalar(1))))}}})},e.atanh=function(e){return s.ENV.engine.runKernel(function(t){return t.atanh(e)},{x:e},function(t){return{x:function(){return t.divStrict(c.scalar(1).sub(e.toFloat().square()))}}})},e.step=function(e,t){void 0===t&&(t=0);return s.ENV.engine.runKernel(function(n){return n.step(e,t)},{x:e},function(e){return{x:function(){return c.zerosLike(e)}}})},a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"neg",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"ceil",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"floor",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"sign",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"round",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"exp",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"expm1",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"log",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"log1p",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"sqrt",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"rsqrt",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"square",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"reciprocal",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"abs",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"clipByValue",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"relu",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"elu",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"selu",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"leakyRelu",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"prelu",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"sigmoid",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"sin",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"cos",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"tan",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"asin",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"acos",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"atan",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"sinh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"cosh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"tanh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"asinh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"acosh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"atanh",null),a([o.doc({heading:"Operations",subheading:"Basic math"}),l.operation],e,"step",null),e}();n.UnaryOps=d},{"../doc":3,"../environment":5,"../util":92,"./operation":62,"./ops":63,"./selu_util":69}],75:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n,r){void 0===r&&(r=1e-8);var i=e.call(this)||this;return i.accumulatedGrads={},i.accumulatedUpdates={},i.c=a.keep(o.scalar(-t)),i.epsilon=a.keep(o.scalar(r)),i.rho=a.keep(o.scalar(n)),i.oneMinusRho=a.keep(o.scalar(1-n)),i}return r(t,e),t.prototype.applyGradients=function(e){var t=this,n=this;for(var r in e)!function(r){var s=i.ENV.engine.registeredVariables[r];null==n.accumulatedGrads[r]&&a.tidy(function(){t.accumulatedGrads[r]=o.zerosLike(s).variable(!1)});null==n.accumulatedUpdates[r]&&a.tidy(function(){t.accumulatedUpdates[r]=o.zerosLike(s).variable(!1)});var u=e[r],l=n.accumulatedGrads[r],c=n.accumulatedUpdates[r];a.tidy(function(){var e=t.rho.mul(l).add(t.oneMinusRho.mul(u.square())),n=c.add(t.epsilon).sqrt().div(l.add(t.epsilon).sqrt()).mul(u),i=t.rho.mul(c).add(t.oneMinusRho.mul(n.square()));t.accumulatedGrads[r].assign(e),t.accumulatedUpdates[r].assign(i);var a=t.c.mul(n).add(s);s.assign(a)})}(r)},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsilon.dispose(),this.rho.dispose(),this.oneMinusRho.dispose(),null!=this.accumulatedUpdates&&(Object.keys(this.accumulatedUpdates).forEach(function(t){return e.accumulatedUpdates[t].dispose()}),Object.keys(this.accumulatedGrads).forEach(function(t){return e.accumulatedGrads[t].dispose()}))},t}(e("./optimizer").Optimizer);n.AdadeltaOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],76:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n){void 0===n&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads={},r.c=a.keep(o.scalar(-t)),r.epsilon=a.keep(o.scalar(1e-8)),r}return r(t,e),t.prototype.applyGradients=function(e){var t=this,n=this;for(var r in e)!function(r){var s=i.ENV.engine.registeredVariables[r];null==n.accumulatedGrads[r]&&a.tidy(function(){t.accumulatedGrads[r]=o.fill(s.shape,t.initialAccumulatorValue).variable(!1)});var u=e[r],l=n.accumulatedGrads[r];a.tidy(function(){var e=l.add(u.square());t.accumulatedGrads[r].assign(e);var n=t.c.mul(u.div(e.add(t.epsilon).sqrt())).add(s);s.assign(n)})}(r)},t.prototype.dispose=function(){var e=this;this.epsilon.dispose(),this.c.dispose(),null!=this.accumulatedGrads&&Object.keys(this.accumulatedGrads).forEach(function(t){return e.accumulatedGrads[t].dispose()})},t}(e("./optimizer").Optimizer);n.AdagradOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],77:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n,r,i){void 0===i&&(i=1e-8);var s=e.call(this)||this;return s.learningRate=t,s.accumulatedFirstMoment={},s.accumulatedSecondMoment={},s.c=a.keep(o.scalar(-t)),s.eps=a.keep(o.scalar(i)),s.beta1=a.keep(o.scalar(n)),s.beta2=a.keep(o.scalar(r)),a.tidy(function(){s.accBeta1=o.scalar(n).variable(),s.accBeta2=o.scalar(r).variable()}),s.oneMinusBeta1=a.keep(o.scalar(1-n)),s.oneMinusBeta2=a.keep(o.scalar(1-r)),s.one=a.keep(o.scalar(1)),s}return r(t,e),t.prototype.applyGradients=function(e){var t=this;a.tidy(function(){var n=t.one.sub(t.accBeta1),r=t.one.sub(t.accBeta2);for(var a in e){var s=i.ENV.engine.registeredVariables[a];if(null==t.accumulatedFirstMoment[a]){u=!1;t.accumulatedFirstMoment[a]=o.zerosLike(s).variable(u)}if(null==t.accumulatedSecondMoment[a]){var u=!1;t.accumulatedSecondMoment[a]=o.zerosLike(s).variable(u)}var l=e[a],c=t.accumulatedFirstMoment[a],p=t.accumulatedSecondMoment[a],h=t.beta1.mul(c).add(t.oneMinusBeta1.mul(l)),d=t.beta2.mul(p).add(t.oneMinusBeta2.mul(l.square())),f=h.div(n),g=d.div(r);t.accumulatedFirstMoment[a].assign(h),t.accumulatedSecondMoment[a].assign(d);var m=t.c.mul(f.div(t.eps.add(g.sqrt()))).add(s);s.assign(m)}t.accBeta1.assign(t.accBeta1.mul(t.beta1)),t.accBeta2.assign(t.accBeta2.mul(t.beta2))})},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.eps.dispose(),this.beta1.dispose(),this.beta2.dispose(),this.accBeta1.dispose(),this.accBeta2.dispose(),this.oneMinusBeta1.dispose(),this.oneMinusBeta2.dispose(),this.one.dispose(),null!=this.accumulatedFirstMoment&&Object.keys(this.accumulatedFirstMoment).forEach(function(t){return e.accumulatedFirstMoment[t].dispose()}),null!=this.accumulatedSecondMoment&&Object.keys(this.accumulatedSecondMoment).forEach(function(t){return e.accumulatedSecondMoment[t].dispose()})},t}(e("./optimizer").Optimizer);n.AdamOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],78:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n,r,i,s){void 0===i&&(i=1e-8),void 0===s&&(s=0);var u=e.call(this)||this;return u.learningRate=t,u.accumulatedFirstMoment={},u.accumulatedWeightedInfNorm={},u.c=a.keep(o.scalar(-t)),u.eps=a.keep(o.scalar(i)),u.beta1=a.keep(o.scalar(n)),u.beta2=a.keep(o.scalar(r)),u.decay=a.keep(o.scalar(s)),a.tidy(function(){u.iteration=o.scalar(0).variable(),u.accBeta1=o.scalar(n).variable()}),u.oneMinusBeta1=a.keep(o.scalar(1-n)),u.one=a.keep(o.scalar(1)),u}return r(t,e),t.prototype.applyGradients=function(e){var t=this;a.tidy(function(){var n=t.one.sub(t.accBeta1),r=t.c.div(t.one.add(t.decay.mul(t.iteration)));for(var a in e){var s=i.ENV.engine.registeredVariables[a];if(null==t.accumulatedFirstMoment[a]){u=!1;t.accumulatedFirstMoment[a]=o.zerosLike(s).variable(u)}if(null==t.accumulatedWeightedInfNorm[a]){var u=!1;t.accumulatedWeightedInfNorm[a]=o.zerosLike(s).variable(u)}var l=e[a],c=t.accumulatedFirstMoment[a],p=t.accumulatedWeightedInfNorm[a],h=t.beta1.mul(c).add(t.oneMinusBeta1.mul(l)),d=t.beta2.mul(p),f=l.abs(),g=d.maximum(f);t.accumulatedFirstMoment[a].assign(h),t.accumulatedWeightedInfNorm[a].assign(g);var m=r.div(n).mul(h.div(t.eps.add(g))).add(s);s.assign(m)}t.iteration.assign(t.iteration.add(t.one)),t.accBeta1.assign(t.accBeta1.mul(t.beta1))})},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.eps.dispose(),this.accBeta1.dispose(),this.beta1.dispose(),this.beta2.dispose(),this.oneMinusBeta1.dispose(),this.decay.dispose(),this.iteration.dispose(),this.one.dispose(),null!=this.accumulatedFirstMoment&&Object.keys(this.accumulatedFirstMoment).forEach(function(t){return e.accumulatedFirstMoment[t].dispose()}),null!=this.accumulatedWeightedInfNorm&&Object.keys(this.accumulatedWeightedInfNorm).forEach(function(t){return e.accumulatedWeightedInfNorm[t].dispose()})},t}(e("./optimizer").Optimizer);n.AdamaxOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],79:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n,r){void 0===r&&(r=!1);var i=e.call(this,t)||this;return i.learningRate=t,i.momentum=n,i.useNesterov=r,i.m=o.scalar(i.momentum),i.accumulations={},i}return r(t,e),t.prototype.applyGradients=function(e){var t=this,n=this;for(var r in e)!function(r){var s=i.ENV.engine.registeredVariables[r];null==n.accumulations[r]&&a.tidy(function(){t.accumulations[r]=o.zerosLike(s).variable(!1)});var u=n.accumulations[r],l=e[r];a.tidy(function(){var e,n=t.m.mul(u).add(l);e=t.useNesterov?t.c.mul(l.add(n.mul(t.m))).add(s):t.c.mul(n).add(s),t.accumulations[r].assign(n),s.assign(e)})}(r)},t.prototype.dispose=function(){if(e.prototype.dispose.call(this),this.m.dispose(),null!=this.accumulations)for(var t in this.accumulations)this.accumulations[t].dispose()},t.prototype.setMomentum=function(e){this.momentum=e},t}(e("./sgd_optimizer").SGDOptimizer);n.MomentumOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./sgd_optimizer":83}],80:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("../globals"),o=function(){function e(){}return e.prototype.minimize=function(e,t,n){void 0===t&&(t=!1);var r=this.computeGradients(e,n),i=r.value,a=r.grads;return this.applyGradients(a),Object.keys(a).forEach(function(e){return a[e].dispose()}),t?i:(i.dispose(),null)},e.prototype.computeGradients=function(e,t){return a.variableGrads(e,t)},r([i.doc({heading:"Training",subheading:"Optimizers"})],e.prototype,"minimize",null),e=r([i.doc({heading:"Training",subheading:"Classes",namespace:"train"})],e)}();n.Optimizer=o},{"../doc":3,"../globals":6}],81:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("../doc"),a=e("./adadelta_optimizer"),o=e("./adagrad_optimizer"),s=e("./adam_optimizer"),u=e("./adamax_optimizer"),l=e("./momentum_optimizer"),c=e("./rmsprop_optimizer"),p=e("./sgd_optimizer"),h=function(){function e(){}return e.sgd=function(e){return new p.SGDOptimizer(e)},e.momentum=function(e,t,n){return void 0===n&&(n=!1),new l.MomentumOptimizer(e,t,n)},e.rmsprop=function(e,t,n,r,i){return void 0===t&&(t=.9),void 0===n&&(n=0),void 0===r&&(r=1e-8),void 0===i&&(i=!1),new c.RMSPropOptimizer(e,t,n,r,i)},e.adam=function(e,t,n,r){return void 0===e&&(e=.001),void 0===t&&(t=.9),void 0===n&&(n=.999),void 0===r&&(r=1e-8),new s.AdamOptimizer(e,t,n,r)},e.adadelta=function(e,t,n){return void 0===e&&(e=.001),void 0===t&&(t=.95),void 0===n&&(n=1e-8),new a.AdadeltaOptimizer(e,t,n)},e.adamax=function(e,t,n,r,i){return void 0===e&&(e=.002),void 0===t&&(t=.9),void 0===n&&(n=.999),void 0===r&&(r=1e-8),void 0===i&&(i=0),new u.AdamaxOptimizer(e,t,n,r,i)},e.adagrad=function(e,t){return void 0===t&&(t=.1),new o.AdagradOptimizer(e,t)},r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"sgd",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"momentum",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"rmsprop",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"adam",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"adadelta",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"adamax",null),r([i.doc({heading:"Training",subheading:"Optimizers",namespace:"train"})],e,"adagrad",null),e}();n.OptimizerConstructors=h},{"../doc":3,"./adadelta_optimizer":75,"./adagrad_optimizer":76,"./adam_optimizer":77,"./adamax_optimizer":78,"./momentum_optimizer":79,"./rmsprop_optimizer":82,"./sgd_optimizer":83}],82:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t,n,r,i,s){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===i&&(i=1e-8),void 0===s&&(s=!1);var u=e.call(this)||this;return u.learningRate=t,u.accumulatedMeanSquares={},u.accumulatedMeanGrads={},u.accumulatedMoments={},u.c=a.keep(o.scalar(t)),u.epsilon=a.keep(o.scalar(i)),u.decay=a.keep(o.scalar(n)),u.momentum=a.keep(o.scalar(r)),u.oneMinusDecay=a.keep(o.scalar(1-n)),u.centered=s,u}return r(t,e),t.prototype.applyGradients=function(e){var t=this,n=this;for(var r in e)!function(r){var s=i.ENV.engine.registeredVariables[r];null==n.accumulatedMeanSquares[r]&&a.tidy(function(){t.accumulatedMeanSquares[r]=o.zerosLike(s).variable(!1)});null==n.accumulatedMeanGrads[r]&&n.centered&&a.tidy(function(){t.accumulatedMeanGrads[r]=o.zerosLike(s).variable(!1)});null==n.accumulatedMoments[r]&&a.tidy(function(){t.accumulatedMoments[r]=o.zerosLike(s).variable(!1)});var u=n.accumulatedMeanSquares[r],l=n.accumulatedMeanGrads[r],c=n.accumulatedMoments[r],p=e[r];a.tidy(function(){var e=t.decay.mul(u).add(t.oneMinusDecay.mul(p.square()));if(t.centered){var n=t.decay.mul(l).add(t.oneMinusDecay.mul(p)),i=t.momentum.mul(c).add(t.c.mul(p).div(e.sub(n.square().add(t.epsilon)).sqrt()));t.accumulatedMeanSquares[r].assign(e),t.accumulatedMeanGrads[r].assign(n),t.accumulatedMoments[r].assign(i),o=s.sub(i),s.assign(o)}else{var a=t.decay.mul(u).add(t.oneMinusDecay.mul(p.square())),i=t.momentum.mul(c).add(t.c.mul(p).div(a.add(t.epsilon).sqrt()));t.accumulatedMeanSquares[r].assign(a),t.accumulatedMoments[r].assign(i);var o=s.sub(i);s.assign(o)}})}(r)},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsilon.dispose(),this.decay.dispose(),this.momentum.dispose(),this.oneMinusDecay.dispose(),null!=this.accumulatedMeanSquares&&Object.keys(this.accumulatedMeanSquares).forEach(function(t){return e.accumulatedMeanSquares[t].dispose()}),null!=this.accumulatedMeanGrads&&this.centered&&Object.keys(this.accumulatedMeanGrads).forEach(function(t){return e.accumulatedMeanGrads[t].dispose()}),null!=this.accumulatedMoments&&Object.keys(this.accumulatedMoments).forEach(function(t){return e.accumulatedMoments[t].dispose()})},t}(e("./optimizer").Optimizer);n.RMSPropOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],83:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../environment"),a=e("../globals"),o=e("../ops/ops"),s=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return r(t,e),t.prototype.applyGradients=function(e){var t=this;Object.keys(e).forEach(function(n){var r=e[n],o=i.ENV.engine.registeredVariables[n];a.tidy(function(){var e=t.c.mul(r).add(o);o.assign(e)})})},t.prototype.setLearningRate=function(e){this.learningRate=e,null!=this.c&&this.c.dispose(),this.c=a.keep(o.scalar(-e))},t.prototype.dispose=function(){this.c.dispose()},t}(e("./optimizer").Optimizer);n.SGDOptimizer=s},{"../environment":5,"../globals":6,"../ops/ops":63,"./optimizer":80}],84:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./util"),i=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new a)}return e.prototype.profileKernel=function(e,t){var n,i=this,a=this.backendTimer.time(function(){n=t()}),o=n.dataSync();return r.checkForNaN(o,n.dtype,e),a.then(function(t){i.logger.logKernelProfile(e,n,o,t.kernelMs)}),n},e}();n.Profiler=i;var a=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,i){var a=r.rightPad(i+"ms",9),o=r.rightPad(e,25),s=t.rank,u=t.size,l=r.rightPad(t.shape.toString(),14);console.log("%c"+o+"\t%c"+a+"\t%c"+s+"D "+l+"\t%c"+u,"font-weight:bold","color:red","color:blue","color: orange")},e}();n.Logger=a},{"./util":92}],85:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./util");n.getFilteredNodesXToY=function(e,t,n){for(var r={},i={},a=0;a=0;a--){var h=(g=e[a]).inputs,d=[];for(d.push(g.output),l=0;l=0;n--){var i=t[n],a=e[i.output.id];if(null==i.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+i.name+".");var o=i.gradient(a);for(var s in i.inputs){if(!(s in o))throw new Error("Cannot backprop through input "+s+". Available gradients found: "+Object.keys(o)+".");var u=o[s](),l=i.inputs[s];if(!r.arraysEqual(u.shape,l.shape))throw new Error("Error in gradient for op "+i.name+". The gradient of input '"+s+"' has shape '"+u.shape+"', which does not match the shape of the input '"+l.shape+"'");if(null==e[l.id])e[l.id]=u;else{var c=e[l.id];e[l.id]=c.add(u),c.dispose()}}}}},{"./util":92}],86:[function(e,t,n){"use strict";function r(e){var t=e.length;if(t<2)return[];var n=new Array(t-1);n[t-2]=e[t-1];for(var r=t-3;r>=0;--r)n[r]=n[r+1]*e[r+1];return n}var i=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),a=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,a){function o(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,s)}u((r=r.apply(e,t||[])).next())})},s=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(o=o.call(a,n[1])).done)return o;switch(a=0,o&&(n=[0,o.value]),n[0]){case 0:case 1:o=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]1)for(var o=0;os){var p=Array.from(e.subarray(0,u)),h=Array.from(e.subarray(l-u,l));return["["+p.map(function(e,t){return i(e,r[t])}).join(", ")+", ..., "+h.map(function(e,t){return i(e,r[l-u+t])}).join(", ")+"]"]}return["["+Array.from(e).map(function(e,t){return i(e,r[t])}).join(", ")+"]"]}var d=t.slice(1),f=n.slice(1),g=n[0],m=[];if(l>s){for(x=0;xn)}function a(e,t,n){describe(e,function(){beforeEach(function(){o.ENV.setFeatures(n||{}),o.ENV.addCustomBackend("webgl",function(){return new u.MathBackendWebGL}),o.ENV.addCustomBackend("cpu",function(){return new s.MathBackendCPU}),n&&null!=n.BACKEND&&o.Environment.setBackend(n.BACKEND),o.ENV.engine.startScope()}),afterEach(function(){o.ENV.engine.endScope(null),o.ENV.reset()}),t()})}Object.defineProperty(n,"__esModule",{value:!0});var o=e("./environment"),s=e("./kernels/backend_cpu"),u=e("./kernels/backend_webgl"),l=e("./tensor"),c=e("./util");n.WEBGL_ENVS=[{BACKEND:"webgl",WEBGL_FLOAT_TEXTURE_ENABLED:!0,WEBGL_VERSION:1},{BACKEND:"webgl",WEBGL_FLOAT_TEXTURE_ENABLED:!0,WEBGL_VERSION:2}],n.CPU_ENVS=[{BACKEND:"cpu"}],n.ALL_ENVS=n.WEBGL_ENVS.concat(n.CPU_ENVS),n.TEST_EPSILON=.001,n.expectArraysClose=r,n.expectArraysEqual=function(e,t){return r(e,t,0)},n.expectNumbersClose=function(e,t,r){if(void 0===r&&(r=n.TEST_EPSILON),!i(e,t,r))throw new Error("Numbers differ: actual === "+e+", expected === "+t)},n.expectValuesInRange=function(e,t,n){var r;r=e instanceof l.Tensor?e.dataSync():e;for(var i=0;in)throw new Error("Value out of range:"+r[i]+" low: "+t+", high: "+n)},n.describeWithFlags=function(e,t,n){t.forEach(function(t){a(e+" "+JSON.stringify(t),n,t)})},n.assertIsNan=function(e,t){if(!c.isValNaN(e,t))throw new Error("Value "+e+" does not represent NaN for dtype "+t)}},{"./environment":5,"./kernels/backend_cpu":9,"./kernels/backend_webgl":11,"./tensor":86,"./util":92}],89:[function(e,t,n){"use strict";var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("./doc"),a=e("./environment"),o=e("./util"),s=function(){function e(){}return e.tidy=function(e,t,n){void 0===n&&(n=!1);var r=null;if(null==t){if("function"!=typeof e)throw new Error("Please provide a function to tidy()");t=e}else{if("string"!=typeof e&&!(e instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof t)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");r=e}a.ENV.engine.startScope(r,n);var i=t();return i instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),a.ENV.engine.endScope(i,n),i},e.dispose=function(e){o.extractTensorsFromAny(e).forEach(function(e){return e.dispose()})},e.keep=function(e){return a.ENV.engine.keep(e)},e.time=function(e){return a.ENV.engine.time(e)},r([i.doc({heading:"Performance",subheading:"Memory"})],e,"tidy",null),r([i.doc({heading:"Performance",subheading:"Memory"})],e,"keep",null),r([i.doc({heading:"Performance",subheading:"Timing"})],e,"time",null),e}();n.Tracking=s},{"./doc":3,"./environment":5,"./util":92}],90:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./optimizers/adadelta_optimizer"),i=e("./optimizers/adagrad_optimizer"),a=e("./optimizers/adam_optimizer"),o=e("./optimizers/adamax_optimizer"),s=e("./optimizers/momentum_optimizer"),u=e("./optimizers/optimizer_constructors"),l=e("./optimizers/rmsprop_optimizer"),c=e("./optimizers/sgd_optimizer");s.MomentumOptimizer,c.SGDOptimizer,r.AdadeltaOptimizer,i.AdagradOptimizer,l.RMSPropOptimizer,o.AdamaxOptimizer,a.AdamOptimizer,n.train={sgd:u.OptimizerConstructors.sgd,momentum:u.OptimizerConstructors.momentum,adadelta:u.OptimizerConstructors.adadelta,adagrad:u.OptimizerConstructors.adagrad,rmsprop:u.OptimizerConstructors.rmsprop,adamax:u.OptimizerConstructors.adamax,adam:u.OptimizerConstructors.adam}},{"./optimizers/adadelta_optimizer":75,"./optimizers/adagrad_optimizer":76,"./optimizers/adam_optimizer":77,"./optimizers/adamax_optimizer":78,"./optimizers/momentum_optimizer":79,"./optimizers/optimizer_constructors":81,"./optimizers/rmsprop_optimizer":82,"./optimizers/sgd_optimizer":83}],91:[function(e,t,n){"use strict";function r(e,t){return s[e][t]}Object.defineProperty(n,"__esModule",{value:!0});!function(e){e.float32="float32",e.int32="int32",e.bool="bool"}(n.DType||(n.DType={}));!function(e){e.R0="R0",e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4"}(n.Rank||(n.Rank={}));var i;!function(e){e.float32="float32",e.int32="int32",e.bool="int32"}(i||(i={}));var a;!function(e){e.float32="float32",e.int32="int32",e.bool="bool"}(a||(a={}));var o;!function(e){e.float32="float32",e.int32="float32",e.bool="float32"}(o||(o={}));var s={float32:o,int32:i,bool:a};n.upcastType=r,n.sumOutType=function(e){return r(e,"int32")}},{}],92:[function(e,t,n){"use strict";function r(e){for(var t=e.length,n=0,r=0;t>0;)r=Math.random()*t|0,n=e[--t],e[t]=e[r],e[r]=n}function i(e,t){if(!e)throw new Error(t)}function a(e,t){if(void 0===t&&(t=[]),Array.isArray(e))for(var n=0;n1;--t)if(e%t==0)return[t,e/t];return[1,e]},n.createShuffledIndices=function(e){for(var t=new Uint32Array(e),n=0;n=n?i():setTimeout(o,s)}};setTimeout(o,0)})},n.getQueryParams=function(e){var t={};return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(e){for(var n=[],r=1;r0&&t!==n)throw Error("Size ("+t+") must match the product of shape "+e);return e}if(t%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+t+" / "+n);var a=e.slice();return a[r]=t/n,a},n.NAN_INT32=1<<31,n.NAN_BOOL=255,n.NAN_FLOAT32=NaN,n.getNaN=u,n.isValNaN=l,n.squeezeShape=function(e,t){for(var n=[],r=[],i=0,a=0;a1)throw new Error("Can't squeeze axis "+a+" since its dim '"+e[a]+"' is not 1");(null==t[i]||t[i]>a)&&1===e[a]&&(n.push(e[a]),r.push(a)),t[i]<=a&&i++}e[a]>1&&(n.push(e[a]),r.push(a))}return{newShape:n,keptDims:r}},n.getTypedArrayFromDType=function(e,t){var n=null;if(null==e||"float32"===e)n=new Float32Array(t);else if("int32"===e)n=new Int32Array(t);else{if("bool"!==e)throw new Error("Unknown data type "+e);n=new Uint8Array(t)}return n},n.isTensorInList=function(e,t){for(var n=0;n0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]0?t.reduce(function(e,t){return e*t}):1},n.cast=function(e,t){return e.asType(t)},n.reshape=u,n.transpose=l,n.permuteDimensions=l,n.reverse=c,n.expandDims=p,n.squeeze=function(e,t){return W.squeeze(e,[t])},n.temporalPadding=function(e,t){if(3!==o(e))throw new X.ValueError("temporalPadding expects input tensor to be 3-D, but received a "+o(e)+"-D tensor.");if(null==t&&(t=[1,1]),2!==t.length)throw new X.ValueError("temporalPadding expects input padding pattern to be a length-2 array, but received a length-"+t.length+" array.");var n=[[0,0],t,[0,0]];return W.pad(e,n)},n.spatial2dPadding=function(e,t,n){if(4!==o(e))throw new X.ValueError("temporalPadding expects input tensor to be 4-D, but received a "+o(e)+"-D tensor.");if(null==t&&(t=[[1,1],[1,1]]),2!==t.length||2!==t[0].length||2!==t[1].length)throw new X.ValueError("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers.");if(null==n&&(n=$.imageDataFormat()),"channelsLast"!==n&&"channelsFirst"!==n)throw new X.ValueError("Unknown data format: "+n+". Supported data formats are 'channelsLast' and 'channelsFirst.");var r;return r="channelsFirst"===n?[[0,0],[0,0],t[0],t[1]]:[[0,0],t[0],t[1],[0,0]],W.pad(e,r)},n.repeat=function(e,t){if(2!==e.shape.length)throw new X.ValueError("repeat() expects a rank-2 tensor, but received a rank-"+e.shape.length+" tensor.");return g(p(e,1),[1,t,1])},n.flatten=h,n.batchFlatten=function(e){if(o(e)<=1)throw new X.ValueError("batchFlatten requires a minimum rank of 2. Got rank: "+o(e)+".");return u(e,[e.shape[0],Z.arrayProd(e.shape,1)])},n.sliceAlongFirstAxis=d,n.sliceAlongLastAxis=function(e,t,n){switch(e.rank){case 1:return W.slice1d(e,t,n);case 2:return W.slice2d(e,[0,t],[e.shape[0],n]);case 3:return W.slice3d(e,[0,0,t],[e.shape[0],e.shape[1],n]);case 4:return W.slice4d(e,[0,0,0,t],[e.shape[0],e.shape[1],e.shape[2],n]);default:throw new X.ValueError("sliceAlongLastAxis() received an unsupported subtype of Tensor: "+e.constructor.name)}},n.concatenate=function(e,t){void 0===t&&(t=-1);var n;return t<0&&(t=0!==(n=o(e[0]))?n:0),t===o(e[0])&&(t=-1),W.concat(e,t)},n.concatAlongFirstAxis=f,n.tile=g,n.variable=function(e,t,n,r){return new Y.LayerVariable(e,t,n,!0,r)},n.batchGetValue=function(e){return e.map(function(e){return e.read()})},n.batchSetValue=function(e){e.map(function(e){e[0].write(e[1])})},n.zeros=m,n.zerosVariable=function(e,t,n){return new Y.LayerVariable(m(e),t,n)},n.zerosLike=function(e,t,n){return new Y.LayerVariable(W.zerosLike(e),t,n)},n.ones=function(e,t){return W.ones(e)},n.onesVariable=function(e,t,n){var r=W.ones(e);return new Y.LayerVariable(r,t,n)},n.onesLike=function(e,t,n){var r=W.onesLike(e);return new Y.LayerVariable(r,t,n)},n.identity=function(e){return e.clone()},n.eye=v,n.eyeVariable=function(e,t,n){return new Y.LayerVariable(v(e,t),t,n)},n.neg=y,n.add=b,n.subtract=w,n.multiply=x,n.divide=E,n.scalarTimesArray=_,n.scalarPlusArray=A,n.randomUniform=S,n.randomUniformVariable=function(e,t,n,r,i,a){return void 0===a&&(a="randomUniform"),new Y.LayerVariable(S(e,t,n,r,i),r,a)},n.truncatedNormal=O,n.truncatedNormalVariable=function(e,t,n,r,i,a){return void 0===t&&(t=0),void 0===n&&(n=1),void 0===a&&(a="truncatedNormal"),new Y.LayerVariable(O(e,t,n,r,i),r,a)},n.randomNormal=T,n.randomNormalVariable=function(e,t,n,r,i,a){return void 0===t&&(t=0),void 0===n&&(n=1),void 0===a&&(a="randomNormal"),new Y.LayerVariable(T(e,t,n,r,i),r,a)},n.update=function(e,t){return e.write(t)},n.updateAdd=function(e,t){return e.write(W.add(e.read(),t))},n.updateSub=function(e,t){return e.write(W.sub(e.read(),t))},n.dot=function(e,t){if(2!==o(t))throw new X.NotImplementedError("dot support for y other than rank 2 is not yet implemented: y shape = "+a);if(2===o(e))return W.matMul(e,t);if(3===o(e)){var n=e.shape[0],r=e.shape[1],i=e.shape[2];return e=e.reshape([n*r,i]),W.matMul(e,t).reshape([n,r,t.shape[1]])}throw new X.NotImplementedError("dot support for x of rank "+o(e)+" is not yet implemented: x shape = "+a)},n.sign=k,n.qr=function(e){if(2!==e.shape.length)throw new X.ValueError("qr() requires a 2D Tensor, but got a "+e.shape.length+"D Tensor.");if(e.shape[0]= x.shape[1], but got shape: ["+e.shape+"]");for(var t=e.shape[0],n=e.shape[1],r=v(t),i=e,a=q.tensor2d([[1]],[1,1]),o=0;o0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]0){var n=e+"_"+t;return s.set(n,1),n}return e};var c=new RegExp(/^[A-Za-z][A-Za-z0-9\._\/]*$/);n.isValidTensorName=i},{"./errors":104,"./utils/generic_utils":127}],100:[function(e,t,n){"use strict";function r(e,t){return u.sqrt(u.sum(u.square(e),t,!0))}function i(e,t){return void 0===t&&(t={}),l.deserializeKerasObject(e,l.ClassNameMap.getMap().pythonClassNameMap,t,"constraint")}var a=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),o=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var s=e("@tensorflow/tfjs-core"),u=e("./backend/tfjs_backend"),l=e("./utils/generic_utils"),c=function(){function e(){}return e.prototype.getConfig=function(){return{}},e=o([s.doc({heading:"Constraints",subheading:"Classes",namespace:"constraints"})],e)}();n.Constraint=c;var p=function(e){function t(t){var n=e.call(this)||this;return n.defaultMaxValue=2,n.defaultAxis=0,n.maxValue=null!=t.maxValue?t.maxValue:n.defaultMaxValue,n.axis=null!=t.axis?t.axis:n.defaultAxis,n}return a(t,e),t.prototype.apply=function(e){var t=r(e,this.axis),n=u.clip(t,0,this.maxValue);return u.multiply(e,u.divide(n,u.scalarPlusArray(u.getScalar(u.epsilon()),t)))},t.prototype.getConfig=function(){return{maxValue:this.maxValue,axis:this.axis}},t}(c);n.MaxNorm=p,l.ClassNameMap.register("MaxNorm",p);var h=function(e){function t(t){var n=e.call(this)||this;return n.defaultAxis=0,n.axis=null!=t.axis?t.axis:n.defaultAxis,n}return a(t,e),t.prototype.apply=function(e){return u.divide(e,u.scalarPlusArray(u.getScalar(u.epsilon()),r(e,this.axis)))},t.prototype.getConfig=function(){return{axis:this.axis}},t}(c);n.UnitNorm=h,l.ClassNameMap.register("UnitNorm",h);var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.apply=function(e){return u.relu(e)},t}(c);n.NonNeg=d,l.ClassNameMap.register("NonNeg",d);var f=function(e){function t(t){var n=e.call(this)||this;return n.defaultMinValue=0,n.defaultMaxValue=1,n.defaultRate=1,n.defaultAxis=0,n.minValue=null!=t.minValue?t.minValue:n.defaultMinValue,n.maxValue=null!=t.maxValue?t.maxValue:n.defaultMaxValue,n.rate=null!=t.rate?t.rate:n.defaultRate,n.axis=null!=t.axis?t.axis:n.defaultAxis,n}return a(t,e),t.prototype.apply=function(e){var t=r(e,this.axis),n=u.add(u.scalarTimesArray(u.getScalar(this.rate),u.clip(t,this.minValue,this.maxValue)),u.scalarTimesArray(u.getScalar(1-this.rate),t));return u.multiply(e,u.divide(n,u.scalarPlusArray(u.getScalar(u.epsilon()),t)))},t.prototype.getConfig=function(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}},t}(c);n.MinMaxNorm=f,l.ClassNameMap.register("MinMaxNorm",f),n.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"},n.serializeConstraint=function(e){return l.serializeKerasObject(e)},n.deserializeConstraint=i,n.getConstraint=function(e){return null==e?null:"string"==typeof e?i({className:e in n.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP?n.CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP[e]:e,config:{}}):e instanceof c?e:i(e)}},{"./backend/tfjs_backend":97,"./utils/generic_utils":127,"@tensorflow/tfjs-core":8}],101:[function(e,t,n){"use strict";function r(e,t){if(null!=e.dtype&&e.dtype!==t.dtype)throw new o.ValueError("The dtype of the feed ("+t.dtype+") is incompatible with that of the key '"+e.name+"' ("+e.dtype+").");if(null!=e.shape){if(e.shape.length!==t.shape.length)throw new o.ValueError("The rank of feed ("+t.shape.length+") does not match the rank of the key ("+e.shape.length+").");for(var n=0;n0)&&(t=e.sourceLayer,n=e.nodeIndex),0===t.inboundNodes.length)return[e];var r=t.inboundNodes[n];if(0===r.inboundLayers.length)return r.inputTensors;for(var i=[],o=0;o0)throw new g.ValueError(p.length+" of "+r+" weights are not set: "+p);f.batchSetValue(l)}function l(e,t,n){void 0===n&&(n=!1);for(var r=e.keras_version,i=e.backend,a=t.map(function(e){return e.name}),u={},l=0,c=t;l=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var h=e("@tensorflow/tfjs-core"),d=e("underscore"),f=e("../backend/tfjs_backend"),g=e("../errors"),m=e("../layers/serialization"),v=e("../types"),y=e("../utils/generic_utils"),b=e("../utils/serialization_utils"),w=function(){return function(e){this.dtype=e.dtype,this.shape=e.shape,null!=e.shape?this.ndim=e.shape.length:this.ndim=e.ndim,this.maxNDim=e.maxNDim,this.minNDim=e.minNDim,this.axes=e.axes||{}}}();n.InputSpec=w;var x=0,E=function(){function e(e,t){this.callArgs=t,this.id=x++,this.outboundLayer=e.outboundLayer,this.inboundLayers=e.inboundLayers,this.nodeIndices=e.nodeIndices,this.tensorIndices=e.tensorIndices,this.inputTensors=e.inputTensors,this.outputTensors=e.outputTensors,this.inputMasks=e.inputMasks,this.outputMasks=e.outputMasks,this.inputShapes=e.inputShapes,this.outputShapes=e.outputShapes;for(var n=0,r=e.inboundLayers;n1)throw new g.AttributeError("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use `getInputAt(nodeIndex)` instead.');if(0===this.inboundNodes.length)throw new g.AttributeError("Layer "+this.name+" is not connected, no input to return.");return y.singletonOrArray(this.getNodeAtIndex(0,"input").inputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"output",{get:function(){if(0===this.inboundNodes.length)throw new g.AttributeError("Layer "+this.name+" has no inbound nodes.");if(this.inboundNodes.length>1)throw new g.AttributeError("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');return y.singletonOrArray(this.getNodeAtIndex(0,"output").outputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"losses",{get:function(){return this._losses},enumerable:!0,configurable:!0}),e.prototype.calculateLosses=function(){return this.losses.map(function(e){return e()})},Object.defineProperty(e.prototype,"updates",{get:function(){return this._updates},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"built",{get:function(){return this._built},set:function(e){this._built=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"trainableWeights",{get:function(){return this.trainable?this._trainableWeights:[]},set:function(e){this._trainableWeights=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this._nonTrainableWeights:this._trainableWeights.concat(this._nonTrainableWeights)},set:function(e){this._nonTrainableWeights=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weights",{get:function(){return this.trainableWeights.concat(this.nonTrainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stateful",{get:function(){return this._stateful},enumerable:!0,configurable:!0}),e.prototype.assertInputCompatibility=function(e){if(e=y.toList(e),null!=this.inputSpec&&0!==this.inputSpec.length){var t=y.toList(this.inputSpec);if(e.length!==t.length)throw new g.ValueError("Layer "+this.name+" expects "+t.length+" inputs, but it received "+e.length+" input tensors. Input received: "+e);for(var n=0;n=0?s[p]:s[s.length+p];if(null!=h&&!d.contains([h,null],m))throw new g.ValueError("Input "+n+" is incompatible with layer "+this.name+": expected axis "+p+" of input shape to have value "+h+" but got shape "+s+".")}if(null!=i.shape)for(var s=f.intShape(r),v=0,b=d.zip(i.shape,s);v0&&Array.isArray(E[0])?E.map(function(r,i){return new v.SymbolicTensor(_,r,n,y.toList(e),t,n.name,i)}):new v.SymbolicTensor(_,E,n,y.toList(e),t,n.name),n.addInboundNode(e,p,null,null,x,E,t),null!=n.activityRegularizer)throw new g.NotImplementedError("Layer invocation in the presence of activity regularizer(s) is not supported yet.");return p})},e.prototype.build=function(e){this.built=!0},e.prototype.getWeights=function(){return f.batchGetValue(this.weights)},e.prototype.setWeights=function(e){var t=this.weights;if(t.length!==e.length)throw new g.ValueError('You called setWeights(weights) on layer "'+this.name+'" with a weight list of length '+e.length+", but the layer was expecting "+t.length+" weights. Provided weights: "+e+"...");if(0!==t.length){for(var n=[],r=f.batchGetValue(t),i=0,a=d.zip(r,t,e);i1 nodes"),y.assert(0===l,"input layer has >1 tensors"),r.inputLayers.push(s),r.inputLayersNodeIndices.push(u),r.inputLayersTensorIndices.push(l)}r.inputNames=[],r.outputNames=[],r.feedInputShapes=[],r.feedInputNames=[],r.feedOutputNames=[];for(D=0;D=0;)i.splice(i.indexOf(u),1);A.push(u)}},T=[],k=[],C=0,N=r.outputs;Cr?1:0});for(var $=0,ee=J;$0)throw new g.ValueError("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array.");if(!this.trainable)return[];for(var e=[],t=0,n=this.layers;t1)for(var s=0,u=o;s0)){for(var d=[],f=0;f0)s=!0;else if(a(e)){for(var u in e)if(e.hasOwnProperty(u)){s=!0;break}}else s=!0;if(s)throw new _.ValueError("Error when checking model "+o+" expected no data, but got "+e)}return[]}if(null==e)return t.map(function(e){return null});var l;if(a(e)){e=e,l=[];for(var c=0,p=t;c1)throw new _.ValueError("The model "+o+" expects "+t.length+" Tensor(s), but only received one Tensor. Found: Tensor with shape "+e.shape);l=[e]}for(d=0;d=0&&m!==v)throw new _.ValueError("Error when checking "+o+": expected "+t[d]+" to have shape ["+n[d]+"], but got array with shape ["+f.shape+"].")}}return l}function s(e,t,n){var r=w.unique(e.map(function(e){return e.shape[0]}));r.sort();var i=w.unique(t.map(function(e){return e.shape[0]}));if(i.sort(),r.length>1)throw new _.ValueError("All input Tensors (x) should have the same number of samples. Got array shapes: "+JSON.stringify(e.map(function(e){return e.shape})));if(i.length>1)throw new _.ValueError("All target Tensors (y) should have the same number of samples. Got array shapes: "+JSON.stringify(t.map(function(e){return e.shape})));if(r.length>0&&i.length>0&&!w.isEqual(r,i))throw new _.ValueError("Input Tensors should have the same number of samples as target Tensors. Found "+r[0]+" input sample(s) and "+i[0]+" target sample(s).")}function u(e,t,n){for(var r=[A.meanSquaredError,A.binaryCrossentropy,A.categoricalCrossentropy],i=0;i=e&&(i=e),n.push([r,i]),r=i;return n}function c(e,t,n){return null==e?[null]:Array.isArray(e)?e.map(function(e){return x.sliceAlongFirstAxis(e,t,n-t)}):x.sliceAlongFirstAxis(e,t,n-t)}function p(e,t){return null==e?null:Array.isArray(e)?e.map(function(e){return p(e,t)}):x.gather(e,t)}function h(e,t,n,r,i){void 0===r&&(r=!0),void 0===i&&(i="");var a;if(Array.isArray(e)){if(e.length!==t.length)throw new _.ValueError("Error when checking model "+i+": the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see "+t.length+" Tensor(s), but instead got "+e.length+" Tensors(s).");a=e}else{if(t.length>1)throw new _.ValueError("The model expects "+t.length+" "+i+" Tensors, but only received one Tensor. Found: array with shape "+JSON.stringify(e.shape)+".");a=[e]}if(null!=n)for(var o=0;o=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},m=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,a){function o(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,s)}u((r=r.apply(e,t||[])).next())})},v=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(o=o.call(a,n[1])).done)return o;switch(a=0,o&&(n=[0,o.value]),n[0]){case 0:case 1:o=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]1&&(t.metricsTensors.push([n,e]),t.metricsNames.push(t.outputNames[e]+"_loss"))}});var c=d(e.metrics,this.outputNames),p=function(e,n,r){t.outputNames.length>1&&(n=t.outputNames[e]+"_"+n),t.metricsNames.push(n),t.metricsTensors.push([r,e])};x.nameScope("metric",function(){for(var e=0;e0&&e[0].shape[0]%r!=0)throw new _.ValueError("In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size "+r+". Found: "+e[0].shape[0]+" sample(s).");return[e,t,null]},t.prototype.fitLoop=function(e,t,n,r,i,a,o,s,u,c,h,d,f,g){return void 0===d&&(d=0),m(this,void 0,void 0,function(){var m,A,S,O,T,k,C=this;return v(this,function(N){switch(N.label){case 0:if(null==r&&(r=32),null==i&&(i=100),null==c&&(c=!0),null==d&&(d=0),m=!1,null!=s&&null!=u&&(m=!0),null!=g&&(m=!0,null==f))throw new _.ValueError("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");if(null!=(A=this.checkNumSamples(t,r,f,"steps_per_epoch"))&&(S=w.range(A)),this.history=new E.History,o=null==o?[new E.BaseLogger]:[new E.BaseLogger].concat(o),o=o.concat([this.history]),a>0)throw new _.NotImplementedError("Verbose mode is not implemented yet.");return(O=new E.CallbackList(o)).setModel(this),O.setParams({epochs:i,steps:f,verbose:a,doValidation:m,metrics:h}),[4,O.onTrainBegin()];case 1:N.sent(),T=function(i){var a,o,h,d,g,T;return v(this,function(k){switch(k.label){case 0:return[4,O.onEpochBegin(i)];case 1:if(k.sent(),a={},o=S,null==f)return[3,2];throw new _.NotImplementedError("stepsPerEpoch mode is not implemented yet.");case 2:if("batch"===c)throw new _.NotImplementedError("batch shuffling is not implemneted yet");c&&(o=w.shuffle(S)),h=b.tensor1d(o),d=l(A,r),g=function(i){var o;return v(this,function(l){switch(l.label){case 0:return o={},[4,O.onBatchBegin(i,o)];case 1:return l.sent(),y.tidy(function(){var l=d[i][0],c=d[i][1],f=x.sliceAlongFirstAxis(h,l,c-l);o.batch=i,o.size=c-l;for(var g=p(t,f),v=e(g),y=0;y1&&(i+="_"+T.count(e.slice(0,n),r)),t.push(i)}return t},t.prototype.makeTestFunction=function(){var e=this;this.testFunction=function(t){return y.tidy(function(){for(var n,r=[],i=t.slice(0,e.inputs.length),a=t.slice(e.inputs.length,e.inputs.length+e.outputs.length),o=[],s=0;s0){if(s=!0,2!==n.validationData.length)throw 3===n.validationData.length?new _.NotImplementedError("validationData including sample weights is not supported yet."):new _.ValueError("When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; "+n.validationData+" is invalid.");u=n.validationData[0],l=n.validationData[1],h=this.standardizeUserData(u,l,!0,r),u=h[0],l=h[1],p=u.concat(l)}else null!=n.validationSplit&&n.validationSplit>0&&n.validationSplit<1?(s=!0,d=Math.floor(a[0].shape[0]*(1-n.validationSplit)),f=a[0].shape[0],u=c(a,d,f),a=c(a,0,d),l=c(o,d,f),o=c(o,0,d),p=u.concat(l)):null!=n.validationSteps&&(s=!0);return g=a.concat(o),this.checkTrainableWeightsConsistency(),m=function(e){var t=[],n=[],r=e.slice(0,S.inputs.length),i=e.slice(S.inputs.length,S.inputs.length+S.outputs.length),a=[],o=S.collectedTrainableWeights.map(function(e){return e.read()});return[S.optimizer.minimize(function(){for(var e=[],o=0;o=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var i=e("@tensorflow/tfjs-core"),a=e("./constraints"),o=e("./engine/topology"),s=e("./engine/training"),u=e("./initializers"),l=e("./layers/advanced_activations"),c=e("./layers/convolutional"),p=e("./layers/convolutional_depthwise"),h=e("./layers/core"),d=e("./layers/embeddings"),f=e("./layers/merge"),g=e("./layers/normalization"),m=e("./layers/padding"),v=e("./layers/pooling"),y=e("./layers/recurrent"),b=e("./layers/wrappers"),w=e("./models"),x=e("./regularizers"),E=function(){function e(){}return e.model=function(e){return new s.Model(e)},e.sequential=function(e){return new w.Sequential(e)},e.loadModel=function(e){return w.loadModelInternal(e)},e.input=function(e){return o.Input(e)},r([i.doc({heading:"Models",subheading:"Creation",configParamIndices:[0]})],e,"model",null),r([i.doc({heading:"Models",subheading:"Creation",configParamIndices:[0]})],e,"sequential",null),r([i.doc({heading:"Models",subheading:"Loading",useDocsFrom:"loadModelInternal"})],e,"loadModel",null),r([i.doc({heading:"Models",subheading:"Inputs",useDocsFrom:"Input",configParamIndices:[0]})],e,"input",null),e}();n.ModelExports=E;var _=function(){function e(){}return e.inputLayer=function(e){return new o.InputLayer(e)},e.elu=function(e){return new l.ELU(e)},e.leakyReLU=function(e){return new l.LeakyReLU(e)},e.softmax=function(e){return new l.Softmax(e)},e.thresohldedReLU=function(e){return new l.ThresholdedReLU(e)},e.conv1d=function(e){return new c.Conv1D(e)},e.conv2d=function(e){return new c.Conv2D(e)},e.conv2dTranspose=function(e){return new c.Conv2DTranspose(e)},e.separableConv2d=function(e){return new c.SeparableConv2D(e)},e.depthwiseConv2d=function(e){return new p.DepthwiseConv2D(e)},e.activation=function(e){return new h.Activation(e)},e.dense=function(e){return new h.Dense(e)},e.dropout=function(e){return new h.Dropout(e)},e.flatten=function(e){return new h.Flatten(e)},e.repeatVector=function(e){return new h.RepeatVector(e)},e.embedding=function(e){return new d.Embedding(e)},e.add=function(e){return new f.Add(e)},e.average=function(e){return new f.Average(e)},e.concatenate=function(e){return new f.Concatenate(e)},e.maximum=function(e){return new f.Maximum(e)},e.minimum=function(e){return new f.Minimum(e)},e.multiply=function(e){return new f.Multiply(e)},e.batchNormalization=function(e){return new g.BatchNormalization(e)},e.zeroPadding2d=function(e){return new m.ZeroPadding2D(e)},e.averagePooling1d=function(e){return new v.AveragePooling1D(e)},e.avgPool1d=function(t){return e.averagePooling1d(t)},e.avgPooling1d=function(t){return e.averagePooling1d(t)},e.averagePooling2d=function(e){return new v.AveragePooling2D(e)},e.avgPool2d=function(t){return e.averagePooling2d(t)},e.avgPooling2d=function(t){return e.averagePooling2d(t)},e.globalAveragePooling1d=function(e){return new v.GlobalAveragePooling1D(e)},e.globalAveragePooling2d=function(e){return new v.GlobalAveragePooling2D(e)},e.globalMaxPooling1d=function(e){return new v.GlobalMaxPooling1D(e)},e.globalMaxPooling2d=function(e){return new v.GlobalMaxPooling2D(e)},e.maxPooling1d=function(e){return new v.MaxPooling1D(e)},e.maxPooling2d=function(e){return new v.MaxPooling2D(e)},e.gru=function(e){return new y.GRU(e)},e.gruCell=function(e){return new y.GRUCell(e)},e.lstm=function(e){return new y.LSTM(e)},e.lstmCell=function(e){return new y.LSTMCell(e)},e.simpleRNN=function(e){return new y.SimpleRNN(e)},e.simpleRNNCell=function(e){return new y.SimpleRNNCell(e)},e.rnn=function(e){return new y.RNN(e)},e.stackedRNNCells=function(e){return new y.StackedRNNCells(e)},e.bidirectional=function(e){return new b.Bidirectional(e)},e.timeDistributed=function(e){return new b.TimeDistributed(e)},e.Layer=o.Layer,e.RNNCell=y.RNNCell,e.input=E.input,r([i.doc({heading:"Layers",subheading:"Inputs",namespace:"layers",useDocsFrom:"InputLayer",configParamIndices:[0]})],e,"inputLayer",null),r([i.doc({heading:"Layers",subheading:"Advanced Activation",namespace:"layers",useDocsFrom:"ELU",configParamIndices:[0]})],e,"elu",null),r([i.doc({heading:"Layers",subheading:"Advanced Activation",namespace:"layers",useDocsFrom:"LeakyReLU",configParamIndices:[0]})],e,"leakyReLU",null),r([i.doc({heading:"Layers",subheading:"Advanced Activation",namespace:"layers",useDocsFrom:"Softmax",configParamIndices:[0]})],e,"softmax",null),r([i.doc({heading:"Layers",subheading:"Advanced Activation",namespace:"layers",useDocsFrom:"ThresholdedReLU",configParamIndices:[0]})],e,"thresohldedReLU",null),r([i.doc({heading:"Layers",subheading:"Convolutional",namespace:"layers",useDocsFrom:"Conv1D",configParamIndices:[0]})],e,"conv1d",null),r([i.doc({heading:"Layers",subheading:"Convolutional",namespace:"layers",useDocsFrom:"Conv2D",configParamIndices:[0]})],e,"conv2d",null),r([i.doc({heading:"Layers",subheading:"Convolutional",namespace:"layers",useDocsFrom:"Conv2DTranspose",configParamIndices:[0]})],e,"conv2dTranspose",null),r([i.doc({heading:"Layers",subheading:"Convolutional",namespace:"layers",useDocsFrom:"SeparableConv2D",configParamIndices:[0]})],e,"separableConv2d",null),r([i.doc({heading:"Layers",subheading:"Convolutional",namespace:"layers",useDocsFrom:"DepthwiseConv2D",configParamIndices:[0]})],e,"depthwiseConv2d",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"Activation",configParamIndices:[0]})],e,"activation",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"Dense",configParamIndices:[0]})],e,"dense",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"Dropout",configParamIndices:[0]})],e,"dropout",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"Flatten",configParamIndices:[0]})],e,"flatten",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"RepeatVector",configParamIndices:[0]})],e,"repeatVector",null),r([i.doc({heading:"Layers",subheading:"Basic",namespace:"layers",useDocsFrom:"Embedding",configParamIndices:[0]})],e,"embedding",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Add",configParamIndices:[0]})],e,"add",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Average",configParamIndices:[0]})],e,"average",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Concatenate",configParamIndices:[0]})],e,"concatenate",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Maximum",configParamIndices:[0]})],e,"maximum",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Minimum",configParamIndices:[0]})],e,"minimum",null),r([i.doc({heading:"Layers",subheading:"Merge",namespace:"layers",useDocsFrom:"Multiply",configParamIndices:[0]})],e,"multiply",null),r([i.doc({heading:"Layers",subheading:"Normalization",namespace:"layers",useDocsFrom:"BatchNormalization",configParamIndices:[0]})],e,"batchNormalization",null),r([i.doc({heading:"Layers",subheading:"Padding",namespace:"layers",useDocsFrom:"ZeroPadding2D",configParamIndices:[0]})],e,"zeroPadding2d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"AveragePooling1D",configParamIndices:[0]})],e,"averagePooling1d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"AveragePooling2D",configParamIndices:[0]})],e,"averagePooling2d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"GlobalAveragePooling1D",configParamIndices:[0]})],e,"globalAveragePooling1d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"GlobalAveragePooling2D",configParamIndices:[0]})],e,"globalAveragePooling2d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"GlobalMaxPooling1D",configParamIndices:[0]})],e,"globalMaxPooling1d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"GlobalMaxPooling2D",configParamIndices:[0]})],e,"globalMaxPooling2d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"MaxPooling1D",configParamIndices:[0]})],e,"maxPooling1d",null),r([i.doc({heading:"Layers",subheading:"Pooling",namespace:"layers",useDocsFrom:"MaxPooling2D",configParamIndices:[0]})],e,"maxPooling2d",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"GRU",configParamIndices:[0]})],e,"gru",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"GRUCell",configParamIndices:[0]})],e,"gruCell",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"LSTM",configParamIndices:[0]})],e,"lstm",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"LSTMCell",configParamIndices:[0]})],e,"lstmCell",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"SimpleRNN",configParamIndices:[0]})],e,"simpleRNN",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"SimpleRNNCell",configParamIndices:[0]})],e,"simpleRNNCell",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"RNN",configParamIndices:[0]})],e,"rnn",null),r([i.doc({heading:"Layers",subheading:"Recurrent",namespace:"layers",useDocsFrom:"RNN",configParamIndices:[0]})],e,"stackedRNNCells",null),r([i.doc({heading:"Layers",subheading:"Wrapper",namespace:"layers",useDocsFrom:"Bidirectional",configParamIndices:[0]})],e,"bidirectional",null),r([i.doc({heading:"Layers",subheading:"Wrapper",namespace:"layers",useDocsFrom:"TimeDistributed",configParamIndices:[0]})],e,"timeDistributed",null),e}();n.LayerExports=_;var A=function(){function e(){}return e.maxNorm=function(e){return new a.MaxNorm(e)},e.unitNorm=function(e){return new a.UnitNorm(e)},e.nonNeg=function(){return new a.NonNeg},e.minMaxNorm=function(e){return new a.MinMaxNorm(e)},r([i.doc({heading:"Constraints",namespace:"constraints",useDocsFrom:"MaxNorm",configParamIndices:[0]})],e,"maxNorm",null),r([i.doc({heading:"Constraints",namespace:"constraints",useDocsFrom:"UnitNorm",configParamIndices:[0]})],e,"unitNorm",null),r([i.doc({heading:"Constraints",namespace:"constraints",useDocsFrom:"NonNeg"})],e,"nonNeg",null),r([i.doc({heading:"Constraints",namespace:"constraints",useDocsFrom:"MinMaxNormConfig",configParamIndices:[0]})],e,"minMaxNorm",null),e}();n.ConstraintExports=A;var S=function(){function e(){}return e.zeros=function(){return new u.Zeros},e.ones=function(){return new u.Ones},e.constant=function(e){return new u.Constant(e)},e.randomUniform=function(e){return new u.RandomUniform(e)},e.randomNormal=function(e){return new u.RandomNormal(e)},e.truncatedNormal=function(e){return new u.TruncatedNormal(e)},e.identity=function(e){return new u.Identity(e)},e.varianceScaling=function(e){return new u.VarianceScaling(e)},e.glorotUniform=function(e){return new u.GlorotUniform(e)},e.glorotNormal=function(e){return new u.GlorotNormal(e)},e.heNormal=function(e){return new u.HeNormal(e)},e.leCunNormal=function(e){return new u.LeCunNormal(e)},e.orthogonal=function(e){return new u.Orthogonal(e)},r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"Zeros"})],e,"zeros",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"Ones"})],e,"ones",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"Constant",configParamIndices:[0]})],e,"constant",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"RandomUniform",configParamIndices:[0]})],e,"randomUniform",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"RandomNormal",configParamIndices:[0]})],e,"randomNormal",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"TruncatedNormal",configParamIndices:[0]})],e,"truncatedNormal",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"Identity",configParamIndices:[0]})],e,"identity",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"VarianceScaling",configParamIndices:[0]})],e,"varianceScaling",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"GlorotUniform",configParamIndices:[0]})],e,"glorotUniform",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"GlorotNormal",configParamIndices:[0]})],e,"glorotNormal",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"HeNormal",configParamIndices:[0]})],e,"heNormal",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"LeCunNormal",configParamIndices:[0]})],e,"leCunNormal",null),r([i.doc({heading:"Initializers",namespace:"initializers",useDocsFrom:"Orthogonal",configParamIndices:[0]})],e,"orthogonal",null),e}();n.InitializerExports=S;var O=function(){function e(){}return e.l1l2=function(e){return new x.L1L2(e)},e.l1=function(e){return x.l1(e)},e.l2=function(e){return x.l2(e)},r([i.doc({heading:"Regularizers",namespace:"regularizers",useDocsFrom:"L1L2"})],e,"l1l2",null),r([i.doc({heading:"Regularizers",namespace:"regularizers",useDocsFrom:"L1L2"})],e,"l1",null),r([i.doc({heading:"Regularizers",namespace:"regularizers",useDocsFrom:"L1L2"})],e,"l2",null),e}();n.RegularizerExports=O},{"./constraints":100,"./engine/topology":102,"./engine/training":103,"./initializers":107,"./layers/advanced_activations":108,"./layers/convolutional":109,"./layers/convolutional_depthwise":110,"./layers/core":111,"./layers/embeddings":112,"./layers/merge":113,"./layers/normalization":114,"./layers/padding":115,"./layers/pooling":116,"./layers/recurrent":117,"./layers/wrappers":119,"./models":122,"./regularizers":124,"@tensorflow/tfjs-core":8}],106:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("./backend/tfjs_backend");n.backend=r;var i=e("./exports"),a=e("./callbacks");n.Callback=a.Callback,n.CallbackList=a.CallbackList,n.CustomCallback=a.CustomCallback;var o=e("./engine/training");n.Model=o.Model;var s=e("./layers/recurrent");n.RNN=s.RNN;var u=e("./models");n.Sequential=u.Sequential;var l=e("./types");n.SymbolicTensor=l.SymbolicTensor;var c=e("./version");n.version_layers=c.version,n.model=i.ModelExports.model,n.sequential=i.ModelExports.sequential,n.loadModel=i.ModelExports.loadModel,n.input=i.ModelExports.input,n.layers=i.LayerExports,n.constraints=i.ConstraintExports,n.initializers=i.InitializerExports,n.regularizers=i.RegularizerExports},{"./backend/tfjs_backend":97,"./callbacks":98,"./engine/training":103,"./exports":105,"./layers/recurrent":117,"./models":122,"./types":125,"./version":130}],107:[function(e,t,n){"use strict";function r(e){if(null!=e&&n.VALID_FAN_MODE_VALUES.indexOf(e)<0)throw new d.ValueError(e+" is not a valid FanMode. Valid values as "+n.VALID_FAN_MODE_VALUES)}function i(e){if(null!=e&&n.VALID_DISTRIBUTION_VALUES.indexOf(e)<0)throw new d.ValueError(e+" is not a valid Distribution. Valid values as "+n.VALID_DISTRIBUTION_VALUES)}function a(e,t){void 0===t&&(t="channelsLast");var n,r;if(h.checkDataFormat(t),2===e.length)n=e[0],r=e[1];else if(c.contains([3,4,5],e.length)){if("channelsFirst"===t){i=m.arrayProd(e,2);n=e[1]*i,r=e[0]*i}else if("channelsLast"===t){var i=m.arrayProd(e,0,e.length-2);n=e[e.length-2]*i,r=e[e.length-1]*i}}else{var a=m.arrayProd(e);n=Math.sqrt(a),r=Math.sqrt(a)}return[n,r]}function o(e,t){return void 0===t&&(t={}),g.deserializeKerasObject(e,g.ClassNameMap.getMap().pythonClassNameMap,t,"initializer")}var s=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),u=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var l=e("@tensorflow/tfjs-core"),c=e("underscore"),p=e("./backend/tfjs_backend"),h=e("./common"),d=e("./errors"),f=e("./types"),g=e("./utils/generic_utils"),m=e("./utils/math_utils");g.SerializableEnumRegistry.register("mode",{fan_in:"fanIn",fan_out:"fanOut",fan_avg:"fanAvg"}),n.VALID_FAN_MODE_VALUES=["fanIn","fanOut","fanAvg",void 0,null],n.checkFanMode=r,g.SerializableEnumRegistry.register("distribution",{normal:"normal",uniform:"uniform"}),n.VALID_DISTRIBUTION_VALUES=["normal","uniform",void 0,null],n.checkDistribution=i;var v=function(){function e(){}return e.fromConfig=function(e,t){return new e(t)},e.prototype.fromConfigUsesCustomObjects=function(){return!1},e.prototype.getConfig=function(){return{}},e=u([l.doc({heading:"Initializers",subheading:"Classes",namespace:"initializers"})],e)}();n.Initializer=v;var y=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.prototype.apply=function(e,t){return p.zeros(e,t)},t}(v);n.Zeros=y,g.ClassNameMap.register("Zeros",y);var b=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.prototype.apply=function(e,t){return p.ones(e,t)},t}(v);n.Ones=b,g.ClassNameMap.register("Ones",b);var w=function(e){function t(t){var n=e.call(this)||this;return n.value=t.value,n}return s(t,e),t.prototype.apply=function(e,t){return p.scalarTimesArray(l.scalar(this.value),p.ones(e,t))},t.prototype.getConfig=function(){return{value:this.value}},t}(v);n.Constant=w,g.ClassNameMap.register("Constant",w);var x=function(e){function t(t){var n=e.call(this)||this;return n.DEFAULT_MINVAL=-.05,n.DEFAULT_MAXVAL=.05,n.minval=t.minval||n.DEFAULT_MINVAL,n.maxval=t.maxval||n.DEFAULT_MAXVAL,n.seed=t.seed,n}return s(t,e),t.prototype.apply=function(e,t){return p.randomUniform(e,this.minval,this.maxval,t,this.seed)},t.prototype.getConfig=function(){return{minval:this.minval,maxval:this.maxval,seed:this.seed}},t}(v);n.RandomUniform=x,g.ClassNameMap.register("RandomUniform",x);var E=function(e){function t(t){var n=e.call(this)||this;return n.DEFAULT_MEAN=0,n.DEFAULT_STDDEV=.05,n.mean=t.mean||n.DEFAULT_MEAN,n.stddev=t.stddev||n.DEFAULT_STDDEV,n.seed=t.seed,n}return s(t,e),t.prototype.apply=function(e,t){return p.randomNormal(e,this.mean,this.stddev,t,this.seed)},t.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},t}(v);n.RandomNormal=E,g.ClassNameMap.register("RandomNormal",E);var _=function(e){function t(t){var n=e.call(this)||this;return n.DEFAULT_MEAN=0,n.DEFAULT_STDDEV=.05,n.mean=t.mean||n.DEFAULT_MEAN,n.stddev=t.stddev||n.DEFAULT_STDDEV,n.seed=t.seed,n}return s(t,e),t.prototype.apply=function(e,t){return p.truncatedNormal(e,this.mean,this.stddev,t,this.seed)},t.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},t}(v);n.TruncatedNormal=_,g.ClassNameMap.register("TruncatedNormal",_);var A=function(e){function t(t){var n=e.call(this)||this;return n.gain=null!=t.gain?l.scalar(t.gain):p.getScalar(1),n}return s(t,e),t.prototype.apply=function(e,t){if(2!==e.length||e[0]!==e[1])throw new d.ValueError("Identity matrix initializer can only be used for 2D square matrices.");return p.scalarTimesArray(this.gain,p.eye(e[0]))},t.prototype.getConfig=function(){return{gain:this.gain.get()}},t}(v);n.Identity=A,g.ClassNameMap.register("Identity",A);var S=function(e){function t(t){var n=e.call(this)||this;if(t.scale<0)throw new d.ValueError("scale must be a positive float. Got: "+t.scale);return n.scale=null==t.scale?1:t.scale,n.mode=t.mode,r(n.mode),n.distribution=t.distribution,i(n.distribution),n.seed=t.seed,n}return s(t,e),t.prototype.apply=function(e,t){var n=a(e),r=n[0],i=n[1],o=this.scale;if("fanIn"===this.mode?o/=Math.max(1,r):"fanOut"===this.mode?o/=Math.max(1,i):o/=Math.max(1,(r+i)/2),"normal"===this.distribution){var s=Math.sqrt(o);return p.truncatedNormal(e,0,s,t,this.seed)}var u=Math.sqrt(3*o);return p.randomUniform(e,-u,u,t,this.seed)},t.prototype.getConfig=function(){return{scale:this.scale,mode:this.mode,distribution:this.distribution,seed:this.seed}},t}(v);n.VarianceScaling=S,g.ClassNameMap.register("VarianceScaling",S);var O=function(e){function t(t){return e.call(this,{scale:1,mode:"fanAvg",distribution:"uniform",seed:t.seed})||this}return s(t,e),t}(S);n.GlorotUniform=O,g.ClassNameMap.register("GlorotUniform",O);var T=function(e){function t(t){return e.call(this,{scale:1,mode:"fanAvg",distribution:"normal",seed:t.seed})||this}return s(t,e),t}(S);n.GlorotNormal=T,g.ClassNameMap.register("GlorotNormal",T);var k=function(e){function t(t){return e.call(this,{scale:2,mode:"fanIn",distribution:"normal",seed:t.seed})||this}return s(t,e),t}(S);n.HeNormal=k,g.ClassNameMap.register("HeNormal",k);var C=function(e){function t(t){return e.call(this,{scale:1,mode:"fanIn",distribution:"normal",seed:t.seed})||this}return s(t,e),t}(S);n.LeCunNormal=C,g.ClassNameMap.register("LeCunNormal",C);var N=function(e){function t(t){var n=e.call(this)||this;if(n.DEFAULT_GAIN=1,n.gain=null==t.gain?n.DEFAULT_GAIN:t.gain,n.seed=t.seed,null!=n.seed)throw new d.NotImplementedError("Random seed is not implemented for Orthogonal Initializer yet.");return n}return s(t,e),t.prototype.apply=function(e,t){if(2!==e.length)throw new d.NotImplementedError("The Orthogonal Initializer does not support non-2D shapes yet.");var n=e[0]>=e[1]?e:[e[1],e[0]],r=p.randomNormal(n,0,1,f.DType.float32),i=p.qr(r)[0];return i.shape[1]>n[1]&&(i=i.slice([0,0],n)),e[0]1)throw new s.ValueError("Can not merge tensors with different batch sizes. Got tensors with shapes: "+JSON.stringify(e)+".");for(var a=null==e[0]?null:e[0].slice(1),o=1;o1){v=i.range(1,E).concat([0]);n.push(a.permuteDimensions(x,v)),o=!0}else n.push(x)}var f=this.mergeFunction(n),g=a.ndim(f);if(o)if(null==g){var m=a.shape(f),h=[p=m[m.length-1]].concat(m.slice(0,m.length-1));f=a.reshape(a.permuteDimensions(a.reshape(f,[-1,p]),[1,0]),h)}else if(g>1){var v=[g-1].concat(i.range(0,g-1));f=a.permuteDimensions(f,v)}return f}for(var y=i.max(r),b=0,w=e;b1)throw new s.ValueError("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: "+JSON.stringify(e))}},t.prototype.mergeFunction=function(e){return a.concatenate(e,this.axis)},t.prototype.computeOutputShape=function(e){if(!Array.isArray(e)||!Array.isArray(e[0]))throw new s.ValueError("A `Concatenate` layer should be called on a list of inputs.");for(var t=e,n=t[0].slice(),r=this.axis<0?n.length+this.axis:this.axis,i=0,a=t.slice(1);i=0?this.axis:this.axis+e.length,n=e[t];if(null==n)throw new u.ValueError("Axis "+t+" of input tensor should have a defined dimension but the layer received an input with shape "+JSON.stringify(e)+".");this.inputSpec=[new s.InputSpec({ndim:e.length,axes:(i={},i[t]=n,i)})];var r=[n];this.scale&&(this.gamma=this.addWeight("gamma",r,null,this.gammaInitializer,this.gammaRegularizer,!0,this.gammaConstraint)),this.center&&(this.beta=this.addWeight("beta",r,null,this.betaInitializer,this.betaRegularizer,!0,this.betaConstraint)),this.movingMean=this.addWeight("moving_mean",r,null,this.movingMeanInitializer,null,!1),this.movingVariance=this.addWeight("moving_variance",r,null,this.movingVarianceInitializer,null,!1),this.built=!0;var i},t.prototype.call=function(e,t){var n=this,r=null!=t.training&&t.training,o=p.getExactlyOneTensor(e),s=a.shape(o),l=s.length,c=i.range(l),h=this.axis>=0?this.axis:this.axis+l;c.splice(h,1);var d=p.pyListRepeat(1,l);d[h]=s[h];var f=c.slice();f.sort();var g=!i.isEqual(f,i.range(l).slice(0,l-1));if(!r)return function(){if(g){var e=a.reshape(n.movingMean.read(),d),t=a.reshape(n.movingVariance.read(),d),r=n.center?a.reshape(n.beta.read(),d):null,i=n.scale?a.reshape(n.gamma.read(),d):null;return a.batchNormalization(o,e,t,r,i,n.epsilon)}return a.batchNormalization(o,n.movingMean.read(),n.movingVariance.read(),null==n.beta?null:n.beta.read(),null==n.gamma?null:n.gamma.read(),n.epsilon)}();throw new u.NotImplementedError("BatchNormalization.call() has not been implemented for training mode yet.")},t.prototype.getConfig=function(){var t={axis:this.axis,momentum:this.momentum,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:l.serializeInitializer(this.betaInitializer),gammaInitializer:l.serializeInitializer(this.gammaInitializer),movingMeanInitializer:l.serializeInitializer(this.movingMeanInitializer),movingVarianceInitializer:l.serializeInitializer(this.movingVarianceInitializer),betaRegularizer:c.serializeRegularizer(this.betaRegularizer),gammaRegularizer:c.serializeRegularizer(this.gammaRegularizer),betaConstraint:o.serializeConstraint(this.betaConstraint),gammaConstraint:o.serializeConstraint(this.gammaConstraint)},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(s.Layer);n.BatchNormalization=h,p.ClassNameMap.register("BatchNormalization",h)},{"../backend/tfjs_backend":97,"../constraints":100,"../engine/topology":102,"../errors":104,"../initializers":107,"../regularizers":124,"../utils/generic_utils":127,underscore:140}],115:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../backend/common"),a=e("../backend/tfjs_backend"),o=e("../engine/topology"),s=e("../errors"),u=e("../utils/generic_utils"),l=function(e){function t(t){var n=this;if(null==t&&(t={}),n=e.call(this,t)||this,n.dataFormat=null==t.dataFormat?i.imageDataFormat():t.dataFormat,null==t.padding)n.padding=[[1,1],[1,1]];else if("number"==typeof t.padding)n.padding=[[t.padding,t.padding],[t.padding,t.padding]];else{if(t.padding=t.padding,2!==t.padding.length)throw new s.ValueError("ZeroPadding2D expects padding to be a length-2 array, but received a length-"+t.padding.length+" array.");var r=void 0,a=void 0;if("number"==typeof t.padding[0])r=[t.padding[0],t.padding[0]],a=[t.padding[1],t.padding[1]];else{if(t.padding=t.padding,2!==t.padding[0].length)throw new s.ValueError("ZeroPadding2D expects height padding to be a length-2 array, but received a length-"+t.padding[0].length+" array.");if(r=t.padding[0],2!==t.padding[1].length)throw new s.ValueError("ZeroPadding2D expects width padding to be a length-2 array, but received a length-"+t.padding[1].length+" array.");a=t.padding[1]}n.padding=[r,a]}return n.inputSpec=[new o.InputSpec({ndim:4})],n}return r(t,e),t.prototype.computeOutputShape=function(e){e=u.getExactlyOneShape(e);var t,n;return"channelsFirst"===this.dataFormat?(t=null!=e[2]&&e[2]>=0?e[2]+this.padding[0][0]+this.padding[0][1]:null,n=null!=e[3]&&e[3]>=0?e[3]+this.padding[1][0]+this.padding[1][1]:null,[e[0],e[1],t,n]):(t=null!=e[1]&&e[1]>=0?e[1]+this.padding[0][0]+this.padding[0][1]:null,n=null!=e[2]&&e[2]>=0?e[2]+this.padding[1][0]+this.padding[1][1]:null,[e[0],t,n,e[3]])},t.prototype.call=function(e,t){return a.spatial2dPadding(u.getExactlyOneTensor(e),this.padding,this.dataFormat)},t.prototype.getConfig=function(){var t={padding:this.padding,dataFormat:this.dataFormat},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(o.Layer);n.ZeroPadding2D=l,u.ClassNameMap.register("ZeroPadding2D",l)},{"../backend/common":96,"../backend/tfjs_backend":97,"../engine/topology":102,"../errors":104,"../utils/generic_utils":127}],116:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(n,"__esModule",{value:!0});var i=e("../backend/tfjs_backend"),a=e("../common"),o=e("../engine/topology"),s=e("../engine/topology"),u=e("../errors"),l=e("../utils/conv_utils"),c=e("../utils/generic_utils"),p=function(e){function t(t){var n=this;return null==t.poolSize&&(t.poolSize=2),n=e.call(this,t)||this,n.poolSize=[t.poolSize],n.strides=null==t.strides?n.poolSize:[t.strides],n.padding=null==t.padding?"valid":t.padding,a.checkPaddingMode(n.padding),n.inputSpec=[new o.InputSpec({ndim:3})],n}return r(t,e),t.prototype.computeOutputShape=function(e){return e=c.getExactlyOneShape(e),length=l.convOutputLength(e[1],this.poolSize[0],this.padding,this.strides[0]),[e[0],length,e[2]]},t.prototype.call=function(e,t){this.invokeCallHook(e,t),e=i.expandDims(c.getExactlyOneTensor(e),2);var n=this.poolingFunction(c.getExactlyOneTensor(e),[this.poolSize[0],1],[this.strides[0],1],this.padding,"channelsLast");return i.squeeze(n,2)},t.prototype.getConfig=function(){var t={poolSize:this.poolSize,padding:this.padding,strides:this.strides},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(s.Layer);n.Pooling1D=p;var h=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.poolingFunction=function(e,t,n,r,o){return a.checkDataFormat(o),a.checkPaddingMode(r),i.pool2d(e,t,n,r,o,"max")},t}(p);n.MaxPooling1D=h,c.ClassNameMap.register("MaxPooling1D",h);var d=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.poolingFunction=function(e,t,n,r,o){return a.checkDataFormat(o),a.checkPaddingMode(r),i.pool2d(e,t,n,r,o,"avg")},t}(p);n.AveragePooling1D=d,c.ClassNameMap.register("AveragePooling1D",d);var f=function(e){function t(t){var n=this;return null==t.poolSize&&(t.poolSize=[2,2]),n=e.call(this,t)||this,n.poolSize=Array.isArray(t.poolSize)?t.poolSize:[t.poolSize,t.poolSize],n.strides=null==t.strides?n.poolSize:t.strides,n.padding=null==t.padding?"valid":t.padding,n.dataFormat=null==t.dataFormat?"channelsLast":t.dataFormat,a.checkDataFormat(n.dataFormat),a.checkPaddingMode(n.padding),n.inputSpec=[new o.InputSpec({ndim:4})],n}return r(t,e),t.prototype.computeOutputShape=function(e){e=c.getExactlyOneShape(e);var t="channelsFirst"===this.dataFormat?e[2]:e[1],n="channelsFirst"===this.dataFormat?e[3]:e[2];return t=l.convOutputLength(t,this.poolSize[0],this.padding,this.strides[0]),n=l.convOutputLength(n,this.poolSize[1],this.padding,this.strides[1]),"channelsFirst"===this.dataFormat?[e[0],e[1],t,n]:[e[0],t,n,e[3]]},t.prototype.call=function(e,t){return this.invokeCallHook(e,t),this.poolingFunction(c.getExactlyOneTensor(e),this.poolSize,this.strides,this.padding,this.dataFormat)},t.prototype.getConfig=function(){var t={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(s.Layer);n.Pooling2D=f;var g=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.poolingFunction=function(e,t,n,r,o){return a.checkDataFormat(o),a.checkPaddingMode(r),i.pool2d(e,t,n,r,o,"max")},t}(f);n.MaxPooling2D=g,c.ClassNameMap.register("MaxPooling2D",g);var m=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.poolingFunction=function(e,t,n,r,o){return a.checkDataFormat(o),a.checkPaddingMode(r),i.pool2d(e,t,n,r,o,"avg")},t}(f);n.AveragePooling2D=m,c.ClassNameMap.register("AveragePooling2D",m);var v=function(e){function t(t){var n=e.call(this,t)||this;return n.inputSpec=[new o.InputSpec({ndim:3})],n}return r(t,e),t.prototype.computeOutputShape=function(e){return[e[0],e[2]]},t.prototype.call=function(e,t){throw new u.NotImplementedError},t}(s.Layer);n.GlobalPooling1D=v;var y=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.call=function(e,t){var n=c.getExactlyOneTensor(e);return i.mean(n,1)},t}(v);n.GlobalAveragePooling1D=y,c.ClassNameMap.register("GlobalAveragePooling1D",y);var b=function(e){function t(t){return e.call(this,t)||this}return r(t,e),t.prototype.call=function(e,t){var n=c.getExactlyOneTensor(e);return i.max(n,1)},t}(v);n.GlobalMaxPooling1D=b,c.ClassNameMap.register("GlobalMaxPooling1D",b);var w=function(e){function t(t){var n=e.call(this,t)||this;return n.dataFormat=null==t.dataFormat?"channelsLast":t.dataFormat,a.checkDataFormat(n.dataFormat),n.inputSpec=[new o.InputSpec({ndim:4})],n}return r(t,e),t.prototype.computeOutputShape=function(e){return e=e,"channelsLast"===this.dataFormat?[e[0],e[3]]:[e[0],e[1]]},t.prototype.call=function(e,t){throw new u.NotImplementedError},t.prototype.getConfig=function(){var t={dataFormat:this.dataFormat},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(s.Layer);n.GlobalPooling2D=w;var x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.call=function(e,t){var n=c.getExactlyOneTensor(e);return"channelsLast"===this.dataFormat?i.mean(n,[1,2]):i.mean(n,[2,3])},t}(w);n.GlobalAveragePooling2D=x,c.ClassNameMap.register("GlobalAveragePooling2D",x);var E=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.call=function(e,t){var n=c.getExactlyOneTensor(e);return"channelsLast"===this.dataFormat?i.max(n,[1,2]):i.max(n,[2,3])},t}(w);n.GlobalMaxPooling2D=E,c.ClassNameMap.register("GlobalMaxPooling2D",E)},{"../backend/tfjs_backend":97,"../common":99,"../engine/topology":102,"../errors":104,"../utils/conv_utils":126,"../utils/generic_utils":127}],117:[function(e,t,n){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),i=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var a=e("@tensorflow/tfjs-core"),o=e("underscore"),s=e("../activations"),u=e("../backend/tfjs_backend"),l=e("../constraints"),c=e("../engine/topology"),p=e("../engine/topology"),h=e("../errors"),d=e("../initializers"),f=e("../regularizers"),g=e("../types"),m=e("../utils/generic_utils"),v=e("../utils/math_utils"),y=e("./serialization"),b=function(e){function t(t){var n,r=e.call(this,t)||this;if(null==t.cell)throw new h.ValueError("cell property is missing for the constructor of RNN.");if(null==(n=Array.isArray(t.cell)?new T({cells:t.cell}):t.cell).stateSize)throw new h.ValueError("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");return r.cell=n,r.returnSequences=null!=t.returnSequences&&t.returnSequences,r.returnState=null!=t.returnState&&t.returnState,r.goBackwards=null!=t.goBackwards&&t.goBackwards,r._stateful=null!=t.stateful&&t.stateful,r.unroll=null!=t.unroll&&t.unroll,r.supportsMasking=!0,r.inputSpec=[new c.InputSpec({ndim:3})],r.stateSpec=null,r.states=null,r.numConstants=null,r}return r(t,e),t.prototype.getStates=function(){if(null==this.states){var e=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1;return o.range(e).map(function(e){return null})}return this.states},t.prototype.setStates=function(e){this.states=e},t.prototype.computeOutputShape=function(e){m.isArrayOfShapes(e)&&(e=e[0]),e=e;var t=this.cell.stateSize;Array.isArray(t)||(t=[t]);var n,r=t[0];if(n=this.returnSequences?[e[0],e[1],r]:[e[0],r],this.returnState){for(var i=[],a=0,o=t;a1&&(t=e.slice(1,e.length)),e=e[0]}return t=r(t),n=r(n),{inputs:e,initialState:t,constants:n}},t.prototype.apply=function(t,n){var r=null==n?null:n.initialState,i=null==n?null:n.constants;null==n&&(n={});var a=this.standardizeArgs(t,r,i);t=a.inputs,r=a.initialState,i=a.constants;var o=[],s=[];if(null!=r){n.initialState=r,o=o.concat(r),this.stateSpec=[];for(var u=0,l=r;u1?u.tile(t,[1,e]):t}):this.cell.stateSize>1?[u.tile(t,[1,this.cell.stateSize])]:[t]},Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.trainable?this.cell.trainableWeights:[]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this.cell.nonTrainableWeights:this.cell.weights},enumerable:!0,configurable:!0}),t.prototype.getConfig=function(){var t={returnSequences:this.returnSequences,returnState:this.returnState,goBackwards:this.goBackwards,stateful:this.stateful,unroll:this.unroll};null!=this.numConstants&&(t.numConstants=this.numConstants);var n=this.cell.getConfig();t.cell={className:this.cell.constructor.name,config:n};var r=e.prototype.getConfig.call(this);return Object.assign(t,r),t},t}(p.Layer);n.RNN=b,m.ClassNameMap.register("RNN",b);var w=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t=i([a.doc({heading:"Layers",subheading:"Classes"})],t)}(p.Layer);n.RNNCell=w;var x=function(e){function t(t){var n=e.call(this,t)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=t.units,n.activation=s.getActivation(null==t.activation?n.DEFAULT_ACTIVATION:t.activation),n.useBias=null==t.useBias||t.useBias,n.kernelInitializer=d.getInitializer(t.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=d.getInitializer(t.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=d.getInitializer(t.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.kernelRegularizer=f.getRegularizer(t.kernelRegularizer),n.recurrentRegularizer=f.getRegularizer(t.recurrentRegularizer),n.biasRegularizer=f.getRegularizer(t.biasRegularizer),n.kernelConstraint=l.getConstraint(t.kernelConstraint),n.recurrentConstraint=l.getConstraint(t.recurrentConstraint),n.biasConstraint=l.getConstraint(t.biasConstraint),n.dropout=v.min([1,v.max([0,null==t.dropout?0:t.dropout])]),n.recurrentDropout=v.min([1,v.max([0,null==t.recurrentDropout?0:t.recurrentDropout])]),n.stateSize=n.units,n}return r(t,e),t.prototype.build=function(e){e=m.getExactlyOneShape(e),this.kernel=this.addWeight("kernel",[e[e.length-1],this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},t.prototype.call=function(e,t){if(2!==(e=e).length)throw new h.ValueError("SimpleRNNCell expects 2 input Tensors, got "+e.length+".");var n=e[1];if(e=e[0],0!==this.dropout||0!==this.recurrentDropout)throw new h.NotImplementedError("Dropout is not implemented for SimpleRNNCell yet");var r=u.dot(e,this.kernel.read());null!=this.bias&&(r=u.biasAdd(r,this.bias.read()));var i=u.add(r,u.dot(n,this.recurrentKernel.read()));return null!=this.activation&&(i=this.activation(i)),[i,i]},t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(w);n.SimpleRNNCell=x,m.ClassNameMap.register("SimpleRNNCell",x);var E=function(e){function t(t){return t.cell=new x(t),e.call(this,t)||this}return r(t,e),t.prototype.call=function(t,n){var r=null==n?null:n.mask,i=null==n?null:n.training,a=null==n?null:n.initialState;return e.prototype.call.call(this,t,{mask:r,training:i,initialState:a})},Object.defineProperty(t.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(b);n.SimpleRNN=E,m.ClassNameMap.register("SimpleRNN",E);var _=function(e){function t(t){var n=e.call(this,t)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=t.units,n.activation=s.getActivation(void 0===t.activation?n.DEFAULT_ACTIVATION:t.activation),n.recurrentActivation=s.getActivation(void 0===t.activation?n.DEFAULT_RECURRENT_ACTIVATION:t.recurrentActivation),n.useBias=null==t.useBias||t.useBias,n.kernelInitializer=d.getInitializer(t.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=d.getInitializer(t.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=d.getInitializer(t.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.kernelRegularizer=f.getRegularizer(t.kernelRegularizer),n.recurrentRegularizer=f.getRegularizer(t.recurrentRegularizer),n.biasRegularizer=f.getRegularizer(t.biasRegularizer),n.kernelConstraint=l.getConstraint(t.kernelConstraint),n.recurrentConstraint=l.getConstraint(t.recurrentConstraint),n.biasConstraint=l.getConstraint(t.biasConstraint),n.dropout=v.min([1,v.max([0,null==t.dropout?0:t.dropout])]),n.recurrentDropout=v.min([1,v.max([0,null==t.recurrentDropout?0:t.recurrentDropout])]),n.implementation=t.implementation,n.stateSize=n.units,n}return r(t,e),t.prototype.build=function(e){var t=(e=m.getExactlyOneShape(e))[e.length-1];this.kernel=this.addWeight("kernel",[t,3*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,3*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[3*this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},t.prototype.call=function(e,t){if(0!==this.dropout||0!==this.recurrentDropout)throw new h.NotImplementedError("Dropout is not implemented for GRUCell yet");if(2!==(e=e).length)throw new h.ValueError("GRUCell expects 2 input Tensors (inputs, h, c), got "+e.length+".");var n=e[1];e=e[0];var r,i,a;if(1===this.implementation){var o=u.sliceAlongLastAxis(this.kernel.read(),0,this.units),s=u.sliceAlongLastAxis(this.kernel.read(),this.units,this.units),l=u.sliceAlongLastAxis(this.kernel.read(),2*this.units,this.units),c=u.sliceAlongLastAxis(this.recurrentKernel.read(),0,this.units),p=u.sliceAlongLastAxis(this.recurrentKernel.read(),this.units,this.units),d=u.sliceAlongLastAxis(this.recurrentKernel.read(),2*this.units,this.units),f=e,g=e,m=e,v=u.dot(f,o),y=u.dot(g,s),b=u.dot(m,l);if(this.useBias){var w=u.sliceAlongFirstAxis(this.bias.read(),0,this.units),x=u.sliceAlongFirstAxis(this.bias.read(),this.units,this.units),E=u.sliceAlongFirstAxis(this.bias.read(),2*this.units,this.units);v=u.biasAdd(v,w),y=u.biasAdd(y,x),b=u.biasAdd(b,E)}var _=n,A=n,S=n;r=this.recurrentActivation(u.add(v,u.dot(_,c))),i=this.recurrentActivation(u.add(y,u.dot(A,p))),a=this.activation(u.add(b,u.dot(u.multiply(i,S),d)))}else{var O=u.dot(e,this.kernel.read());this.useBias&&(O=u.biasAdd(O,this.bias.read()));var T=u.dot(n,u.sliceAlongLastAxis(this.recurrentKernel.read(),0,2*this.units)),v=u.sliceAlongLastAxis(O,0,this.units),y=u.sliceAlongLastAxis(O,this.units,this.units),k=u.sliceAlongLastAxis(T,0,this.units),C=u.sliceAlongLastAxis(T,this.units,this.units);r=this.recurrentActivation(u.add(v,k)),i=this.recurrentActivation(u.add(y,C));var b=u.sliceAlongLastAxis(O,2*this.units,this.units),N=u.dot(u.multiply(i,n),u.sliceAlongLastAxis(this.recurrentKernel.read(),2*this.units,this.units));a=this.activation(u.add(b,N))}var R=u.add(u.multiply(r,n),u.multiply(u.scalarPlusArray(u.getScalar(1),u.neg(r)),a));return[R,R]},t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(w);n.GRUCell=_,m.ClassNameMap.register("GRUCell",_);var A=function(e){function t(t){return 0===t.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),t.cell=new _(t),e.call(this,t)||this}return r(t,e),t.prototype.call=function(t,n){var r=null==n?null:n.mask,i=null==n?null:n.training,a=null==n?null:n.initialState;return e.prototype.call.call(this,t,{mask:r,training:i,initialState:a})},Object.defineProperty(t.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"implementation",{get:function(){return this.cell.implementation},enumerable:!0,configurable:!0}),t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t.fromConfig=function(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)},t}(b);n.GRU=A,m.ClassNameMap.register("GRU",A);var S=function(e){function t(t){var n=e.call(this,t)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=t.units,n.activation=s.getActivation(void 0===t.activation?n.DEFAULT_ACTIVATION:t.activation),n.recurrentActivation=s.getActivation(void 0===t.activation?n.DEFAULT_RECURRENT_ACTIVATION:t.recurrentActivation),n.useBias=null==t.useBias||t.useBias,n.kernelInitializer=d.getInitializer(t.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=d.getInitializer(t.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=d.getInitializer(t.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.unitForgetBias=t.unitForgetBias,n.kernelRegularizer=f.getRegularizer(t.kernelRegularizer),n.recurrentRegularizer=f.getRegularizer(t.recurrentRegularizer),n.biasRegularizer=f.getRegularizer(t.biasRegularizer),n.kernelConstraint=l.getConstraint(t.kernelConstraint),n.recurrentConstraint=l.getConstraint(t.recurrentConstraint),n.biasConstraint=l.getConstraint(t.biasConstraint),n.dropout=v.min([1,v.max([0,null==t.dropout?0:t.dropout])]),n.recurrentDropout=v.min([1,v.max([0,null==t.recurrentDropout?0:t.recurrentDropout])]),n.implementation=t.implementation,n.stateSize=[n.units,n.units],n}return r(t,e),t.prototype.build=function(e){var t=(e=m.getExactlyOneShape(e))[e.length-1];this.kernel=this.addWeight("kernel",[t,4*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,4*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint);var n;if(this.useBias){if(this.unitForgetBias){var i=this.biasInitializer,a=this.units;n=new(function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.apply=function(e,t){var n=i.apply([a]),r=(new d.Ones).apply([a]),o=i.apply([2*a]);return u.concatAlongFirstAxis(u.concatAlongFirstAxis(n,r),o)},t}(d.Initializer))}else n=this.biasInitializer;this.bias=this.addWeight("bias",[4*this.units],null,n,this.biasRegularizer,!0,this.biasConstraint)}else this.bias=null;this.built=!0},t.prototype.call=function(e,t){if(0!==this.dropout||0!==this.recurrentDropout)throw new h.NotImplementedError("Dropout is not implemented for LSTMCell yet");if(3!==(e=e).length)throw new h.ValueError("LSTMCell expects 3 input Tensors (inputs, h, c), got "+e.length+".");var n=e[1],r=e[2];e=e[0];var i,a,o,s;if(1===this.implementation){var l=u.sliceAlongLastAxis(this.kernel.read(),0,this.units),c=u.sliceAlongLastAxis(this.kernel.read(),this.units,this.units),p=u.sliceAlongLastAxis(this.kernel.read(),2*this.units,this.units),d=u.sliceAlongLastAxis(this.kernel.read(),3*this.units,this.units),f=u.sliceAlongLastAxis(this.recurrentKernel.read(),0,this.units),g=u.sliceAlongLastAxis(this.recurrentKernel.read(),this.units,this.units),m=u.sliceAlongLastAxis(this.recurrentKernel.read(),2*this.units,this.units),v=u.sliceAlongLastAxis(this.recurrentKernel.read(),3*this.units,this.units),y=e,b=e,w=e,x=e,E=u.dot(y,l),_=u.dot(b,c),A=u.dot(w,p),S=u.dot(x,d);if(this.useBias){var O=u.sliceAlongFirstAxis(this.bias.read(),0,this.units),T=u.sliceAlongFirstAxis(this.bias.read(),this.units,this.units),k=u.sliceAlongFirstAxis(this.bias.read(),2*this.units,this.units),C=u.sliceAlongFirstAxis(this.bias.read(),3*this.units,this.units);E=u.biasAdd(E,O),_=u.biasAdd(_,T),A=u.biasAdd(A,k),S=u.biasAdd(S,C)}var N=n,R=n,I=n,z=n;i=this.recurrentActivation(u.add(E,u.dot(N,f))),a=this.recurrentActivation(u.add(_,u.dot(R,g))),o=u.add(u.multiply(a,r),u.multiply(i,this.activation(u.add(A,u.dot(I,m))))),s=this.recurrentActivation(u.add(S,u.dot(z,v)))}else{var M=u.dot(e,this.kernel.read());M=u.add(M,u.dot(n,this.recurrentKernel.read())),this.useBias&&(M=u.biasAdd(M,this.bias.read()));var D=u.sliceAlongLastAxis(M,0,this.units),L=u.sliceAlongLastAxis(M,this.units,this.units),P=u.sliceAlongLastAxis(M,2*this.units,this.units),F=u.sliceAlongLastAxis(M,3*this.units,this.units);i=this.recurrentActivation(D),a=this.recurrentActivation(L),o=u.add(u.multiply(a,r),u.multiply(i,this.activation(P))),s=this.recurrentActivation(F)}var V=u.multiply(s,this.activation(o));return[V,V,o]},t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t}(w);n.LSTMCell=S,m.ClassNameMap.register("LSTMCell",S);var O=function(e){function t(t){return 0===t.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),t.cell=new S(t),e.call(this,t)||this}return r(t,e),t.prototype.call=function(t,n){var r=null==n?null:n.mask,i=null==n?null:n.training,a=null==n?null:n.initialState;return e.prototype.call.call(this,t,{mask:r,training:i,initialState:a})},Object.defineProperty(t.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"unitForgetBias",{get:function(){return this.cell.unitForgetBias},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"implementation",{get:function(){return this.cell.implementation},enumerable:!0,configurable:!0}),t.prototype.getConfig=function(){var t={units:this.units,activation:s.serializeActivation(this.activation),useBias:this.useBias,kernelInitializer:d.serializeInitializer(this.kernelInitializer),recurrentInitializer:d.serializeInitializer(this.recurrentInitializer),biasInitializer:d.serializeInitializer(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:f.serializeRegularizer(this.kernelRegularizer),recurrentRegularizer:f.serializeRegularizer(this.recurrentRegularizer),biasRegularizer:f.serializeRegularizer(this.biasRegularizer),activityRegularizer:f.serializeRegularizer(this.activityRegularizer),kernelConstraint:l.serializeConstraint(this.kernelConstraint),recurrentConstraint:l.serializeConstraint(this.recurrentConstraint),biasConstraint:l.serializeConstraint(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=e.prototype.getConfig.call(this);return Object.assign(t,n),t},t.fromConfig=function(e,t){return 0===t.implmentation&&(t.implementation=1),new e(t)},t}(b);n.LSTM=O,m.ClassNameMap.register("LSTM",O);var T=function(e){function t(t){var n=e.call(this,t)||this;return n.cells=t.cells,n}return r(t,e),Object.defineProperty(t.prototype,"stateSize",{get:function(){for(var e=[],t=0,n=this.cells.slice().reverse();t= 3D, but received input shape "+JSON.stringify(t));this.inputSpec=[{shape:t}];var n=[t[0]].concat(t.slice(2));this.layer.built||(this.layer.build(n),this.layer.built=!0),e.prototype.build.call(this,t)},t.prototype.computeOutputShape=function(e){var t=[(e=s.getExactlyOneShape(e))[0]].concat(e.slice(2)),n=this.layer.computeOutputShape(t),r=e[1];return[n[0],r].concat(n.slice(1))},t.prototype.call=function(e,t){var n=this;e=s.getExactlyOneTensor(e);return i.rnn(function(e,r){return[n.layer.call(e,t),[]]},e,[],!1,null,null,!1,e.shape[1])[1]},t}(l);n.TimeDistributed=c,s.ClassNameMap.register("TimeDistributed",c);var p;!function(e){e[e.SUM=0]="SUM",e[e.MUL=1]="MUL",e[e.CONCAT=2]="CONCAT",e[e.AVE=3]="AVE"}(p=n.BidirectionalMergeMode||(n.BidirectionalMergeMode={})),s.SerializableEnumRegistry.register("merge_mode",{sum:p.SUM,mul:p.MUL,concat:p.CONCAT,ave:p.AVE});var h=function(e){function t(t){var n=e.call(this,t)||this;n.forwardLayer=t.layer;var r=t.layer.getConfig();if(r.goBackwards=!0!==r.goBackwards,n.backwardLayer=u.deserialize({className:t.layer.constructor.name,config:r}),n.forwardLayer.name="forward_"+n.forwardLayer.name,n.backwardLayer.name="backward_"+n.backwardLayer.name,n.mergeMode=t.mergeMode,t.weights)throw new o.NotImplementedError("weights support is not implemented for Bidirectional layer yet.");return n._stateful=t.layer.stateful,n.returnSequences=t.layer.returnSequences,n.returnState=t.layer.returnState,n.supportsMasking=!0,n._trainable=!0,n.inputSpec=t.layer.inputSpec,n}return r(t,e),Object.defineProperty(t.prototype,"trainable",{get:function(){return this._trainable},set:function(e){this._trainable=e,null!=this.forwardLayer&&(this.forwardLayer.trainable=e),null!=this.backwardLayer&&(this.backwardLayer.trainable=e)},enumerable:!0,configurable:!0}),t.prototype.getWeights=function(){return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights())},t.prototype.setWeights=function(e){var t=e.length,n=Math.floor(t/2);this.forwardLayer.setWeights(e.slice(0,n)),this.backwardLayer.setWeights(e.slice(n))},t.prototype.computeOutputShape=function(e){var t=this.forwardLayer.computeOutputShape(e);Array.isArray(t)&&Array.isArray(t[0])||(t=[t]),t=t;var n,r,i;return this.returnState?(i=t.slice(1),n=t[0]):n=t[0],n=n,this.mergeMode===p.CONCAT?(n[n.length-1]*=2,r=[n]):r=null==this.mergeMode?[n,n.slice()]:[n],this.returnState?null==this.mergeMode?r.concat(i).concat(i.slice()):[n].concat(i).concat(i.slice()):s.singletonOrArray(r)},t.prototype.apply=function(t,n){var r=null;if(null!=n&&(r=n.initialState),Array.isArray(t)&&(r=t.slice(1),t=t[0]),null==r||0===r.length)return e.prototype.apply.call(this,t,n);throw new o.NotImplementedError("The support for initial states is not implemented for Bidirectional layers yet.")},t.prototype.call=function(e,t){if(null!=t.mask)throw new o.NotImplementedError("The support for masking is not implemented for Bidirectional layers yet.");if(null!=t.initialState)throw new o.NotImplementedError("The support for initial states is not implemented for Bidirectional layers yet.");var n,r=this.forwardLayer.call(e,t),a=this.backwardLayer.call(e,t);this.returnState&&(Array.isArray(r)&&(n=r.slice(1).concat(a.slice(1))),r=r[0],a=a[0]),this.returnSequences&&(a=i.reverse(a,1));var s;return this.mergeMode===p.CONCAT?s=i.concatenate([r,a]):this.mergeMode===p.SUM?s=i.add(r,a):this.mergeMode===p.AVE?s=i.scalarTimesArray(i.getScalar(.5),i.add(r,a)):this.mergeMode===p.MUL?s=i.multiply(r,a):null==this.mergeMode&&(s=[r,a]),this.returnState?null==this.mergeMode?s.concat(n):[s].concat(n):s},t.prototype.resetStates=function(e){this.forwardLayer.resetStates(),this.backwardLayer.resetStates()},t.prototype.build=function(e){var t=this;i.nameScope(this.forwardLayer.name,function(){t.forwardLayer.build(e)}),i.nameScope(this.backwardLayer.name,function(){t.backwardLayer.build(e)}),this.built=!0},Object.defineProperty(t.prototype,"trainableWeights",{get:function(){return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nonTrainableWeights",{get:function(){return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights)},enumerable:!0,configurable:!0}),t}(l);n.Bidirectional=h,s.ClassNameMap.register("Bidirectional",h)},{"../backend/tfjs_backend":97,"../engine/topology":102,"../errors":104,"../utils/generic_utils":127,"./serialization":118}],120:[function(e,t,n){"use strict";function r(e,t){return v.mean(v.square(v.subtract(t,e)),-1)}function i(e,t){return v.mean(v.abs(v.subtract(t,e)),-1)}function a(e,t){var n=v.subtract(e,t),r=v.clip(v.abs(e),v.epsilon(),Number.MAX_VALUE),i=v.abs(v.divide(n,r));return v.scalarTimesArray(v.getScalar(100),v.mean(i,-1))}function o(e,t){var n=v.getScalar(1),r=v.clip(t,v.epsilon(),Number.MAX_VALUE),i=v.log(v.scalarPlusArray(n,r)),a=v.clip(e,v.epsilon(),Number.MAX_VALUE),o=v.log(v.scalarPlusArray(n,a));return v.mean(v.square(v.subtract(i,o)),-1)}function s(e,t){var n=v.getScalar(0),r=v.getScalar(1),i=v.maximum(n,v.subtract(r,v.multiply(e,t)));return v.mean(v.square(i),-1)}function u(e,t){var n=v.getScalar(0),r=v.getScalar(1),i=v.maximum(n,v.subtract(r,v.multiply(e,t)));return v.mean(i,-1)}function l(e,t){var n=v.getScalar(0),r=v.getScalar(1),i=v.sum(v.multiply(e,t),-1),a=v.max(v.multiply(v.subtract(r,e),t),-1);return v.maximum(n,v.scalarPlusArray(r,v.subtract(a,i)))}function c(e,t){var n=v.getScalar(Math.log(2)),r=v.subtract(t,e),i=v.subtract(v.add(r,v.softplus(v.scalarTimesArray(v.getScalar(-2),r))),n);return v.mean(i,-1)}function p(e,t){return v.categoricalCrossentropy(e,t)}function h(e,t){return v.sparseCategoricalCrossentropy(e,t)}function d(e,t){return v.mean(v.binaryCrossentropy(e,t),-1)}function f(e,t){var n=v.clip(e,v.epsilon(),1),r=v.clip(t,v.epsilon(),1);return v.sum(v.multiply(e,v.log(v.divide(n,r))),-1)}function g(e,t){var n=v.log(v.scalarPlusArray(v.getScalar(v.epsilon()),t));return v.mean(v.subtract(t,v.multiply(e,n)),-1)}function m(e,t){var n=v.l2Normalize(e,-1),r=v.l2Normalize(t,-1),i=v.multiply(n,r);return v.neg(v.sum(i,-1))}Object.defineProperty(n,"__esModule",{value:!0});var v=e("./backend/tfjs_backend"),y=e("./errors");n.meanSquaredError=r,n.meanAbsoluteError=i,n.meanAbsolutePercentageError=a,n.meanSquaredLogarithmicError=o,n.squaredHinge=s,n.hinge=u,n.categoricalHinge=l,n.logcosh=c,n.categoricalCrossentropy=p,n.sparseCategoricalCrossentropy=h,n.binaryCrossentropy=d,n.kullbackLeiblerDivergence=f,n.poisson=g,n.cosineProximity=m,n.mse=r,n.MSE=r,n.mae=i,n.MAE=i,n.mape=a,n.MAPE=a,n.msle=o,n.MSLE=o,n.kld=f,n.KLD=f,n.cosine=m,n.get=function(e){var t={meanSquaredError:r,meanAbsoluteError:i,meanAbsolutePercentageError:a,meanSquaredLogarithmicError:o,squaredHinge:s,hinge:u,categoricalHinge:l,logcosh:c,categoricalCrossentropy:p,sparseCategoricalCrossentropy:h,binaryCrossentropy:d,kullbackLeiblerDivergence:f,poisson:g,cosineProximity:m};if(e in t)return t[e];throw new y.ValueError("Unknown loss "+e)}},{"./backend/tfjs_backend":97,"./errors":104}],121:[function(e,t,n){"use strict";function r(e,t){var n=o.scalarTimesArray(o.getScalar(.5),a.onesLike(t)),r=o.cast(o.greater(t,n),e.dtype);return o.mean(o.equal(e,r),-1)}function i(e,t){return o.cast(o.equal(o.argmax(e,-1),o.argmax(t,-1)),"float32")}Object.defineProperty(n,"__esModule",{value:!0});var a=e("@tensorflow/tfjs-core"),o=e("./backend/tfjs_backend"),s=e("./errors"),u=e("./losses");n.binaryAccuracy=r,n.categoricalAccuracy=i,n.binaryCrossentropy=function(e,t){throw new s.NotImplementedError},n.categoricalCrossentropy=function(e,t){throw new s.NotImplementedError},n.sparseCategoricalAccuracy=function(e,t){throw new s.NotImplementedError},n.sparseCategoricalCrossentropy=function(e,t){throw new s.NotImplementedError},n.topKCategoricalAccuracy=function(e,t){throw new s.NotImplementedError},n.sparseTopKCategoricalAccuracy=function(e,t){throw new s.NotImplementedError},n.mse=u.meanSquaredError,n.MSE=u.meanSquaredError,n.mae=u.meanAbsoluteError,n.MAE=u.meanAbsoluteError,n.mape=u.meanAbsolutePercentageError,n.MAPE=u.meanAbsolutePercentageError,n.cosine=u.cosineProximity,n.get=function(e){var t={binaryAccuracy:r,categoricalAccuracy:i,mse:n.mse,MSE:n.MSE,mae:n.mae,MAE:n.MAE,mape:n.mape,MAPE:n.MAPE,cosine:n.cosine};if("string"==typeof e&&e in t)return t[e];if("string"!=typeof e&&null!=e)return e;throw new s.ValueError("Unknown metric "+e)}},{"./backend/tfjs_backend":97,"./errors":104,"./losses":120,"@tensorflow/tfjs-core":8}],122:[function(e,t,n){"use strict";function r(e,t){return o(this,void 0,void 0,function(){var n,r,i,a,o,l,c,p,h,f;return s(this,function(s){switch(s.label){case 0:return null!=(n=e.modelTopology).model_config&&(n=n.model_config),r=g.convertPythonicToTs(n),i=d.deserialize(r,t),null==e.weightsManifest?[3,2]:[4,u.loadWeights(e.weightsManifest,e.pathPrefix,i.weights.map(function(e){return e.originalName}))];case 1:for(a=s.sent(),o={},l=0,c=i.weights;l=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,a){function o(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,s)}u((r=r.apply(e,t||[])).next())})},s=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,a&&(o=a[2&n[0]?"return":n[0]?"throw":"next"])&&!(o=o.call(a,n[1])).done)return o;switch(a=0,o&&(n=[0,o.value]),n[0]){case 0:case 1:o=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(o=u.trys,!(o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var o=e("@tensorflow/tfjs-core"),s=e("./backend/tfjs_backend"),u=e("./utils/generic_utils"),l=function(){return function(){}}();n.Regularizer=l;var c=function(e){function t(t){var n=e.call(this)||this,r=null==t||null==t.l1?.01:t.l1,i=null==t||null==t.l2?.01:t.l2;return n.hasL1=0!==r,n.hasL2=0!==i,n.l1=s.getScalar(r),n.l2=s.getScalar(i),n}return i(t,e),n=t,t.prototype.apply=function(e){var t=o.zeros([1]);return this.hasL1&&(t=s.add(t,s.sum(s.scalarTimesArray(this.l1,s.abs(e))))),this.hasL2&&(t=s.add(t,s.sum(s.scalarTimesArray(this.l2,s.square(e))))),t.asScalar()},t.prototype.getConfig=function(){return{l1:this.l1.dataSync()[0],l2:this.l2.dataSync()[0]}},t.fromConfig=function(e,t){return new n({l1:t.l1,l2:t.l2})},t=n=a([o.doc({heading:"Regularizers",namespace:"regularizers"})],t);var n}(l);n.L1L2=c,u.ClassNameMap.register("L1L2",c),n.l1=function(e){return new c({l1:null!=e?e.l1:null,l2:0})},n.l2=function(e){return new c({l2:null!=e?e.l2:null,l1:0})},n.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP={l1l2:"L1L2"},n.serializeRegularizer=function(e){return u.serializeKerasObject(e)},n.deserializeRegularizer=r,n.getRegularizer=function(e){return null==e?null:"string"==typeof e?r({className:e in n.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP?n.REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[e]:e,config:{}}):e instanceof l?e:r(e)}},{"./backend/tfjs_backend":97,"./utils/generic_utils":127,"@tensorflow/tfjs-core":8}],125:[function(e,t,n){"use strict";function r(e,t){if(e.shape.toString()!==t.shape.toString())throw new Error("Shape mismatch: "+JSON.stringify(e.shape)+" vs. "+JSON.stringify(t.shape))}function i(e){return e instanceof p?e.value():e}var a=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o};Object.defineProperty(n,"__esModule",{value:!0});var o,s=e("@tensorflow/tfjs-core"),u=e("./common");!function(e){e.float32="float32",e.int32="int32",e.bool="bool"}(o=n.DType||(n.DType={}));var l=0,c=function(){function e(e,t,n,r,i,a,o){this.dtype=e,this.shape=t,this.sourceLayer=n,this.inputs=r,this.callArgs=i,this.outputTensorIndex=o,this.id=l++,null!=a&&(this.originalName=u.getScopedTensorName(a),this.name=u.getUniqueTensorName(this.originalName))}return e=a([s.doc({heading:"Models",subheading:"Classes"})],e)}();n.SymbolicTensor=c;var p=function(){function e(e,t){this.dtype=o.float32,this.shape=e.shape,this.val=e,this.id=l++,null!=t&&(this.originalName=u.getScopedTensorName(t),this.name=u.getUniqueTensorName(this.originalName))}return e.prototype.value=function(){return this.val},e}();n.ConcreteTensor=p;var h="Variable",d=function(){function e(e,t,n,r,a){void 0===t&&(t=o.float32),void 0===n&&(n=h),void 0===r&&(r=!0),void 0===a&&(a=null),this.dtype=null==t?o.float32:t,this.shape=e.shape,this.id=l++,n=null==n?h:n,this.originalName=u.getScopedTensorName(n),this.name=u.getUniqueTensorName(this.originalName),this.trainable=r,this.constraint=a,this.val=s.variable(i(e),this.trainable,this.name,this.dtype)}return e.prototype.read=function(){return this.val},e.prototype.write=function(e){return r(this.val,e),this.val.assign(i(e)),null!=this.constraint&&this.val.assign(this.constraint.apply(this.val)),this},e}();n.LayerVariable=d},{"./common":99,"@tensorflow/tfjs-core":8}],126:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=e("../errors"),i=e("./generic_utils"),a=e("./math_utils");n.normalizeArray=function(e,t,n){if("number"==typeof e)return i.pyListRepeat(e,t);if(e.length!==t)throw new r.ValueError("The "+n+" argument must be a tuple of "+t+" integers. Received: "+e.length+" elements.");for(var o=0;ot?1:0}var a=this&&this.__assign||Object.assign||function(e){for(var t,n=1,r=arguments.length;n=e.length)throw new s.IndexError(n);return t},n.assert=function(e,t){if(!e)throw new s.AssertionError(t)},n.count=function(e,t){for(var n=0,r=0,i=e;r>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)}}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.alea=a}(0,"object"==typeof t&&t,!1)},{}],134:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.b,n=t.c,r=t.d,i=t.a;return e=e<<25^e>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-e|0,t.b=e=e<<20^e>>>12^n,t.c=n=n-r|0,t.d=r<<16^n>>>16^i,t.a=i-e|0},t.a=0,t.b=0,t.c=-1640531527,t.d=1367130551,e===Math.floor(e)?(t.a=e/4294967296|0,t.b=0|e):n+=e;for(var r=0;r>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,a&&("object"==typeof a&&i(a,n),o.state=function(){return i(n,{})}),o}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.tychei=a}(0,"object"==typeof t&&t,!1)},{}],135:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.x=0,t.y=0,t.z=0,t.w=0,t.next=function(){var e=t.x^t.x<<11;return t.x=t.y,t.y=t.z,t.z=t.w,t.w^=t.w>>>19^e^e>>>8},e===(0|e)?t.x=e:n+=e;for(var r=0;r>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,a&&("object"==typeof a&&i(a,n),o.state=function(){return i(n,{})}),o}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xor128=a}(0,"object"==typeof t&&t,!1)},{}],136:[function(e,t,n){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.w,i=t.X,a=t.i;return t.w=r=r+1640531527|0,n=i[a+34&127],e=i[a=a+1&127],n^=n<<13,e^=e<<17,n^=n>>>15,e^=e>>>12,n=i[a]=n^e,t.i=a,n+(r^r>>>16)|0},function(e,t){var n,r,i,a,o,s=[],u=128;for(t===(0|t)?(r=t,t=null):(t+="\0",r=0,u=Math.max(u,t.length)),i=0,a=-32;a>>15,r^=r<<4,r^=r>>>13,a>=0&&(o=o+1640531527|0,i=0==(n=s[127&a]^=r+o)?i+1:0);for(i>=128&&(s[127&(t&&t.length||0)]=-1),i=127,a=512;a>0;--a)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;e.w=o,e.X=s,e.i=i}(t,e)}function i(e,t){return t.i=e.i,t.w=e.w,t.X=e.X.slice(),t}function a(e,t){null==e&&(e=+new Date);var n=new r(e),a=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,a&&(a.X&&i(a,n),o.state=function(){return i(n,{})}),o}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xor4096=a}(0,"object"==typeof t&&t,!1)},{}],137:[function(e,t,n){!function(e,t,n){function r(e){var t=this;t.next=function(){var e,n,r=t.x,i=t.i;return e=r[i],e^=e>>>7,n=e^e<<24,e=r[i+1&7],n^=e^e>>>10,e=r[i+3&7],n^=e^e>>>3,e=r[i+4&7],n^=e^e<<7,e=r[i+7&7],e^=e<<13,n^=e^e<<9,r[i]=n,t.i=i+1&7,n},function(e,t){var n,r=[];if(t===(0|t))r[0]=t;else for(t=""+t,n=0;n0;--n)e.next()}(t,e)}function i(e,t){return t.x=e.x.slice(),t.i=e.i,t}function a(e,t){null==e&&(e=+new Date);var n=new r(e),a=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,a&&(a.x&&i(a,n),o.state=function(){return i(n,{})}),o}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xorshift7=a}(0,"object"==typeof t&&t,!1)},{}],138:[function(e,t,n){!function(e,t,n){function r(e){var t=this,n="";t.next=function(){var e=t.x^t.x>>>2;return t.x=t.y,t.y=t.z,t.z=t.w,t.w=t.v,(t.d=t.d+362437|0)+(t.v=t.v^t.v<<4^e^e<<1)|0},t.x=0,t.y=0,t.z=0,t.w=0,t.v=0,e===(0|e)?t.x=e:n+=e;for(var r=0;r>>4),t.next()}function i(e,t){return t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w,t.v=e.v,t.d=e.d,t}function a(e,t){var n=new r(e),a=t&&t.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var e=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===e);return e},o.int32=n.next,o.quick=o,a&&("object"==typeof a&&i(a,n),o.state=function(){return i(n,{})}),o}t&&t.exports?t.exports=a:n&&n.amd?n(function(){return a}):this.xorwow=a}(0,"object"==typeof t&&t,!1)},{}],139:[function(e,t,n){!function(n,r){function i(e,t,i){var p=[],h=u(s((t=1==t?{entropy:!0}:t||{}).entropy?[e,c(n)]:null==e?l():e,3),p),b=new a(p),w=function(){for(var e=b.g(f),t=m,n=0;e=y;)e/=2,t/=2,n>>>=1;return(e+n)/t};return w.int32=function(){return 0|b.g(4)},w.quick=function(){return b.g(4)/4294967296},w.double=w,u(c(b.S),n),(t.pass||i||function(e,t,n,i){return i&&(i.S&&o(i,b),e.state=function(){return o(b,{})}),n?(r[g]=e,t):e})(w,h,"global"in t?t.global:this==r,t.state)}function a(e){var t,n=e.length,r=this,i=0,a=r.i=r.j=0,o=r.S=[];for(n||(e=[n++]);i=0&&a0?0:s-1;return arguments.length<3&&(i=n[o?o[u]:u],u+=e),t(n,r,i,o,u,s)}}function r(e){return function(t,n,r){n=E(n,r);for(var i=T(t),a=e>0?0:i-1;a>=0&&a0?o=a>=0?a:Math.max(a+s,o):s=a>=0?Math.min(a+1,s):a+s+1;else if(n&&a&&s)return a=n(r,i),r[a]===i?a:-1;if(i!==i)return(a=t(h.call(r,o,s),w.isNaN))>=0?a+o:-1;for(a=e>0?o:s-1;a>=0&&a=0&&t<=O};w.each=w.forEach=function(e,t,n){t=x(t,n);var r,i;if(k(e))for(r=0,i=e.length;r=0},w.invoke=function(e,t){var n=h.call(arguments,2),r=w.isFunction(t);return w.map(e,function(e){var i=r?t:e[t];return null==i?i:i.apply(e,n)})},w.pluck=function(e,t){return w.map(e,w.property(t))},w.where=function(e,t){return w.filter(e,w.matcher(t))},w.findWhere=function(e,t){return w.find(e,w.matcher(t))},w.max=function(e,t,n){var r,i,a=-1/0,o=-1/0;if(null==t&&null!=e)for(var s=0,u=(e=k(e)?e:w.values(e)).length;sa&&(a=r);else t=E(t,n),w.each(e,function(e,n,r){((i=t(e,n,r))>o||i===-1/0&&a===-1/0)&&(a=e,o=i)});return a},w.min=function(e,t,n){var r,i,a=1/0,o=1/0;if(null==t&&null!=e)for(var s=0,u=(e=k(e)?e:w.values(e)).length;sr||void 0===n)return 1;if(nt?(o&&(clearTimeout(o),o=null),s=l,a=e.apply(r,i),o||(r=i=null)):o||!1===n.trailing||(o=setTimeout(u,c)),a}},w.debounce=function(e,t,n){var r,i,a,o,s,u=function(){var l=w.now()-o;l=0?r=setTimeout(u,t-l):(r=null,n||(s=e.apply(a,i),r||(a=i=null)))};return function(){a=this,i=arguments,o=w.now();var l=n&&!r;return r||(r=setTimeout(u,t)),l&&(s=e.apply(a,i),a=i=null),s}},w.wrap=function(e,t){return w.partial(t,e)},w.negate=function(e){return function(){return!e.apply(this,arguments)}},w.compose=function(){var e=arguments,t=e.length-1;return function(){for(var n=t,r=e[t].apply(this,arguments);n--;)r=e[n].call(this,r);return r}},w.after=function(e,t){return function(){if(--e<1)return t.apply(this,arguments)}},w.before=function(e,t){var n;return function(){return--e>0&&(n=t.apply(this,arguments)),e<=1&&(t=null),n}},w.once=w.partial(w.before,2);var I=!{toString:null}.propertyIsEnumerable("toString"),z=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];w.keys=function(e){if(!w.isObject(e))return[];if(m)return m(e);var t=[];for(var n in e)w.has(e,n)&&t.push(n);return I&&a(e,t),t},w.allKeys=function(e){if(!w.isObject(e))return[];var t=[];for(var n in e)t.push(n);return I&&a(e,t),t},w.values=function(e){for(var t=w.keys(e),n=t.length,r=Array(n),i=0;i":">",'"':""","'":"'","`":"`"},L=w.invert(D),P=function(e){var t=function(t){return e[t]},n="(?:"+w.keys(e).join("|")+")",r=RegExp(n),i=RegExp(n,"g");return function(e){return e=null==e?"":""+e,r.test(e)?e.replace(i,t):e}};w.escape=P(D),w.unescape=P(L),w.result=function(e,t,n){var r=null==e?void 0:e[t];return void 0===r&&(r=n),w.isFunction(r)?r.call(e):r};var F=0;w.uniqueId=function(e){var t=++F+"";return e?e+t:t},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var V=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\u2028|\u2029/g,U=function(e){return"\\"+B[e]};w.template=function(e,t,n){!t&&n&&(t=n),t=w.defaults({},t,w.templateSettings);var r=RegExp([(t.escape||V).source,(t.interpolate||V).source,(t.evaluate||V).source].join("|")+"|$","g"),i=0,a="__p+='";e.replace(r,function(t,n,r,o,s){return a+=e.slice(i,s).replace(j,U),i=s+t.length,n?a+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?a+="'+\n((__t=("+r+"))==null?'':__t)+\n'":o&&(a+="';\n"+o+"\n__p+='"),t}),a+="';\n",t.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{var o=new Function(t.variable||"obj","_",a)}catch(e){throw e.source=a,e}var s=function(e){return o.call(this,e,w)},u=t.variable||"obj";return s.source="function("+u+"){\n"+a+"}",s},w.chain=function(e){var t=w(e);return t._chain=!0,t};var G=function(e,t){return e._chain?w(t).chain():t};w.mixin=function(e){w.each(w.functions(e),function(t){var n=w[t]=e[t];w.prototype[t]=function(){var e=[this._wrapped];return p.apply(e,arguments),G(this,n.apply(w,e))}})},w.mixin(w),w.each(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=u[e];w.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!==e&&"splice"!==e||0!==n.length||delete n[0],G(this,n)}}),w.each(["concat","join","slice"],function(e){var t=u[e];w.prototype[e]=function(){return G(this,t.apply(this._wrapped,arguments))}}),w.prototype.value=function(){return this._wrapped},w.prototype.valueOf=w.prototype.toJSON=w.prototype.value,w.prototype.toString=function(){return""+this._wrapped}}).call(this)},{}],141:[function(e,t,n){"use strict";function r(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}Object.defineProperty(n,"__esModule",{value:!0}),r(e("@tensorflow/tfjs-core")),r(e("@tensorflow/tfjs-layers"));var i=e("@tensorflow/tfjs-core"),a=e("@tensorflow/tfjs-layers"),o=e("./version");n.version={"tfjs-core":i.version_core,"tfjs-layers":a.version_layers,tfjs:o.version}},{"./version":142,"@tensorflow/tfjs-core":8,"@tensorflow/tfjs-layers":106}],142:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});n.version="0.9.0"},{}]},{},[141])(141)});