// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles

parcelRequire = (function (modules, cache, entry, globalName) {
  // Save the require from previous bundle to this closure if any
  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
  var nodeRequire = typeof require === 'function' && require;


  function newRequire(name, jumped) {
    if (!cache[name]) {
      if (!modules[name]) {
        // if we cannot find the module within our internal map or
        // cache jump to the current global require ie. the last bundle
        // that was added to the page.
        var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
        if (!jumped && currentRequire) {
          return currentRequire(name, true);
        }

        // If there are other bundles on this page the require from the
        // previous one is saved to 'previousRequire'. Repeat this as
        // many times as there are bundles until the module is found or
        // we exhaust the require chain.
        if (previousRequire) {
          return previousRequire(name, true);
        }

        // Try the node require function if it exists.
        if (nodeRequire && typeof name === 'string') {
          return nodeRequire(name);
        }

        var err = new Error('Cannot find module \'' + name + '\'');
        err.code = 'MODULE_NOT_FOUND';
        throw err;
      }

      localRequire.resolve = resolve;
      localRequire.cache = {};

      var module = cache[name] = new newRequire.Module(name);

      modules[name][0].call(module.exports, localRequire, module, module.exports, this);
    }

    return cache[name].exports;

    function localRequire(x) {
      return newRequire(localRequire.resolve(x));
    }

    function resolve(x) {
      return modules[name][1][x] || x;
    }
  }

  function Module(moduleName) {
    this.id = moduleName;
    this.bundle = newRequire;
    this.exports = {};
  }

  newRequire.isParcelRequire = true;
  newRequire.Module = Module;
  newRequire.modules = modules;
  newRequire.cache = cache;
  newRequire.parent = previousRequire;
  newRequire.register = function (id, exports) {
    modules[id] = [function (require, module) {
      module.exports = exports;
    }, {}];
  };

  var error;
  for (var i = 0; i < entry.length; i++) {
    try {
      newRequire(entry[i]);
    } catch (e) {
      // Save first error but execute all entries
      if (!error) {
        error = e;
      }
    }
  }

  if (entry.length) {
    // Expose entry point to Node, AMD or browser globals
    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
    var mainExports = newRequire(entry[entry.length - 1]);

    // CommonJS
    if (typeof exports === "object" && typeof module !== "undefined") {
      module.exports = mainExports;

      // RequireJS
    } else if (typeof define === "function" && define.amd) {
      define(function () {
        return mainExports;
      });

      // <script>
    } else if (globalName) {
      this[globalName] = mainExports;
    }
  }

  // Override the current require with this new one
  parcelRequire = newRequire;

  if (error) {
    // throw error from earlier, _after updating parcelRequire_
    throw error;
  }

  return newRequire;
})({
  "node_modules/parcel-bundler/src/builtins/_empty.js": [function (require, module, exports) {

  }, {}], "node_modules/process/browser.js": [function (require, module, exports) {

    // shim for using process in browser
    var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
    // don't break things.  But we need to wrap it in a try catch in case it is
    // wrapped in strict mode code which doesn't define any globals.  It's inside a
    // function because try/catches deoptimize in certain engines.

    var cachedSetTimeout;
    var cachedClearTimeout;

    function defaultSetTimout() {
      throw new Error('setTimeout has not been defined');
    }

    function defaultClearTimeout() {
      throw new Error('clearTimeout has not been defined');
    }

    (function () {
      try {
        if (typeof setTimeout === 'function') {
          cachedSetTimeout = setTimeout;
        } else {
          cachedSetTimeout = defaultSetTimout;
        }
      } catch (e) {
        cachedSetTimeout = defaultSetTimout;
      }

      try {
        if (typeof clearTimeout === 'function') {
          cachedClearTimeout = clearTimeout;
        } else {
          cachedClearTimeout = defaultClearTimeout;
        }
      } catch (e) {
        cachedClearTimeout = defaultClearTimeout;
      }
    })();

    function runTimeout(fun) {
      if (cachedSetTimeout === setTimeout) {
        //normal enviroments in sane situations
        return setTimeout(fun, 0);
      } // if setTimeout wasn't available but was latter defined


      if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
        cachedSetTimeout = setTimeout;
        return setTimeout(fun, 0);
      }

      try {
        // when when somebody has screwed with setTimeout but no I.E. maddness
        return cachedSetTimeout(fun, 0);
      } catch (e) {
        try {
          // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
          return cachedSetTimeout.call(null, fun, 0);
        } catch (e) {
          // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
          return cachedSetTimeout.call(this, fun, 0);
        }
      }
    }

    function runClearTimeout(marker) {
      if (cachedClearTimeout === clearTimeout) {
        //normal enviroments in sane situations
        return clearTimeout(marker);
      } // if clearTimeout wasn't available but was latter defined


      if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
        cachedClearTimeout = clearTimeout;
        return clearTimeout(marker);
      }

      try {
        // when when somebody has screwed with setTimeout but no I.E. maddness
        return cachedClearTimeout(marker);
      } catch (e) {
        try {
          // When we are in I.E. but the script has been evaled so I.E. doesn't  trust the global object when called normally
          return cachedClearTimeout.call(null, marker);
        } catch (e) {
          // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
          // Some versions of I.E. have different rules for clearTimeout vs setTimeout
          return cachedClearTimeout.call(this, marker);
        }
      }
    }

    var queue = [];
    var draining = false;
    var currentQueue;
    var queueIndex = -1;

    function cleanUpNextTick() {
      if (!draining || !currentQueue) {
        return;
      }

      draining = false;

      if (currentQueue.length) {
        queue = currentQueue.concat(queue);
      } else {
        queueIndex = -1;
      }

      if (queue.length) {
        drainQueue();
      }
    }

    function drainQueue() {
      if (draining) {
        return;
      }

      var timeout = runTimeout(cleanUpNextTick);
      draining = true;
      var len = queue.length;

      while (len) {
        currentQueue = queue;
        queue = [];

        while (++queueIndex < len) {
          if (currentQueue) {
            currentQueue[queueIndex].run();
          }
        }

        queueIndex = -1;
        len = queue.length;
      }

      currentQueue = null;
      draining = false;
      runClearTimeout(timeout);
    }

    process.nextTick = function (fun) {
      var args = new Array(arguments.length - 1);

      if (arguments.length > 1) {
        for (var i = 1; i < arguments.length; i++) {
          args[i - 1] = arguments[i];
        }
      }

      queue.push(new Item(fun, args));

      if (queue.length === 1 && !draining) {
        runTimeout(drainQueue);
      }
    }; // v8 likes predictible objects


    function Item(fun, array) {
      this.fun = fun;
      this.array = array;
    }

    Item.prototype.run = function () {
      this.fun.apply(null, this.array);
    };

    process.title = 'browser';
    process.env = {};
    process.argv = [];
    process.version = ''; // empty string to avoid regexp issues

    process.versions = {};

    function noop() { }

    process.on = noop;
    process.addListener = noop;
    process.once = noop;
    process.off = noop;
    process.removeListener = noop;
    process.removeAllListeners = noop;
    process.emit = noop;
    process.prependListener = noop;
    process.prependOnceListener = noop;

    process.listeners = function (name) {
      return [];
    };

    process.binding = function (name) {
      throw new Error('process.binding is not supported');
    };

    process.cwd = function () {
      return '/';
    };

    process.chdir = function (dir) {
      throw new Error('process.chdir is not supported');
    };

    process.umask = function () {
      return 0;
    };
  }, {}], "node_modules/base64-js/index.js": [function (require, module, exports) {
    'use strict'

    exports.byteLength = byteLength
    exports.toByteArray = toByteArray
    exports.fromByteArray = fromByteArray

    var lookup = []
    var revLookup = []
    var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array

    var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    for (var i = 0, len = code.length; i < len; ++i) {
      lookup[i] = code[i]
      revLookup[code.charCodeAt(i)] = i
    }

    // Support decoding URL-safe base64 strings, as Node.js does.
    // See: https://en.wikipedia.org/wiki/Base64#URL_applications
    revLookup['-'.charCodeAt(0)] = 62
    revLookup['_'.charCodeAt(0)] = 63

    function getLens(b64) {
      var len = b64.length

      if (len % 4 > 0) {
        throw new Error('Invalid string. Length must be a multiple of 4')
      }

      // Trim off extra bytes after placeholder bytes are found
      // See: https://github.com/beatgammit/base64-js/issues/42
      var validLen = b64.indexOf('=')
      if (validLen === -1) validLen = len

      var placeHoldersLen = validLen === len
        ? 0
        : 4 - (validLen % 4)

      return [validLen, placeHoldersLen]
    }

    // base64 is 4/3 + up to two characters of the original data
    function byteLength(b64) {
      var lens = getLens(b64)
      var validLen = lens[0]
      var placeHoldersLen = lens[1]
      return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
    }

    function _byteLength(b64, validLen, placeHoldersLen) {
      return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
    }

    function toByteArray(b64) {
      var tmp
      var lens = getLens(b64)
      var validLen = lens[0]
      var placeHoldersLen = lens[1]

      var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))

      var curByte = 0

      // if there are placeholders, only get up to the last complete 4 chars
      var len = placeHoldersLen > 0
        ? validLen - 4
        : validLen

      var i
      for (i = 0; i < len; i += 4) {
        tmp =
          (revLookup[b64.charCodeAt(i)] << 18) |
          (revLookup[b64.charCodeAt(i + 1)] << 12) |
          (revLookup[b64.charCodeAt(i + 2)] << 6) |
          revLookup[b64.charCodeAt(i + 3)]
        arr[curByte++] = (tmp >> 16) & 0xFF
        arr[curByte++] = (tmp >> 8) & 0xFF
        arr[curByte++] = tmp & 0xFF
      }

      if (placeHoldersLen === 2) {
        tmp =
          (revLookup[b64.charCodeAt(i)] << 2) |
          (revLookup[b64.charCodeAt(i + 1)] >> 4)
        arr[curByte++] = tmp & 0xFF
      }

      if (placeHoldersLen === 1) {
        tmp =
          (revLookup[b64.charCodeAt(i)] << 10) |
          (revLookup[b64.charCodeAt(i + 1)] << 4) |
          (revLookup[b64.charCodeAt(i + 2)] >> 2)
        arr[curByte++] = (tmp >> 8) & 0xFF
        arr[curByte++] = tmp & 0xFF
      }

      return arr
    }

    function tripletToBase64(num) {
      return lookup[num >> 18 & 0x3F] +
        lookup[num >> 12 & 0x3F] +
        lookup[num >> 6 & 0x3F] +
        lookup[num & 0x3F]
    }

    function encodeChunk(uint8, start, end) {
      var tmp
      var output = []
      for (var i = start; i < end; i += 3) {
        tmp =
          ((uint8[i] << 16) & 0xFF0000) +
          ((uint8[i + 1] << 8) & 0xFF00) +
          (uint8[i + 2] & 0xFF)
        output.push(tripletToBase64(tmp))
      }
      return output.join('')
    }

    function fromByteArray(uint8) {
      var tmp
      var len = uint8.length
      var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
      var parts = []
      var maxChunkLength = 16383 // must be multiple of 3

      // go through the array every three bytes, we'll deal with trailing stuff later
      for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
        parts.push(encodeChunk(
          uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
        ))
      }

      // pad the end with zeros, but make sure to not forget the extra bytes
      if (extraBytes === 1) {
        tmp = uint8[len - 1]
        parts.push(
          lookup[tmp >> 2] +
          lookup[(tmp << 4) & 0x3F] +
          '=='
        )
      } else if (extraBytes === 2) {
        tmp = (uint8[len - 2] << 8) + uint8[len - 1]
        parts.push(
          lookup[tmp >> 10] +
          lookup[(tmp >> 4) & 0x3F] +
          lookup[(tmp << 2) & 0x3F] +
          '='
        )
      }

      return parts.join('')
    }

  }, {}], "node_modules/ieee754/index.js": [function (require, module, exports) {
    exports.read = function (buffer, offset, isLE, mLen, nBytes) {
      var e, m
      var eLen = (nBytes * 8) - mLen - 1
      var eMax = (1 << eLen) - 1
      var eBias = eMax >> 1
      var nBits = -7
      var i = isLE ? (nBytes - 1) : 0
      var d = isLE ? -1 : 1
      var s = buffer[offset + i]

      i += d

      e = s & ((1 << (-nBits)) - 1)
      s >>= (-nBits)
      nBits += eLen
      for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) { }

      m = e & ((1 << (-nBits)) - 1)
      e >>= (-nBits)
      nBits += mLen
      for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) { }

      if (e === 0) {
        e = 1 - eBias
      } else if (e === eMax) {
        return m ? NaN : ((s ? -1 : 1) * Infinity)
      } else {
        m = m + Math.pow(2, mLen)
        e = e - eBias
      }
      return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
    }

    exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
      var e, m, c
      var eLen = (nBytes * 8) - mLen - 1
      var eMax = (1 << eLen) - 1
      var eBias = eMax >> 1
      var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
      var i = isLE ? 0 : (nBytes - 1)
      var d = isLE ? 1 : -1
      var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0

      value = Math.abs(value)

      if (isNaN(value) || value === Infinity) {
        m = isNaN(value) ? 1 : 0
        e = eMax
      } else {
        e = Math.floor(Math.log(value) / Math.LN2)
        if (value * (c = Math.pow(2, -e)) < 1) {
          e--
          c *= 2
        }
        if (e + eBias >= 1) {
          value += rt / c
        } else {
          value += rt * Math.pow(2, 1 - eBias)
        }
        if (value * c >= 2) {
          e++
          c /= 2
        }

        if (e + eBias >= eMax) {
          m = 0
          e = eMax
        } else if (e + eBias >= 1) {
          m = ((value * c) - 1) * Math.pow(2, mLen)
          e = e + eBias
        } else {
          m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
          e = 0
        }
      }

      for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) { }

      e = (e << mLen) | m
      eLen += mLen
      for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) { }

      buffer[offset + i - d] |= s * 128
    }

  }, {}], "node_modules/isarray/index.js": [function (require, module, exports) {
    var toString = {}.toString;

    module.exports = Array.isArray || function (arr) {
      return toString.call(arr) == '[object Array]';
    };

  }, {}], "node_modules/buffer/index.js": [function (require, module, exports) {

    var global = arguments[3];
    /*!
     * The buffer module from node.js, for the browser.
     *
     * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
     * @license  MIT
     */
    /* eslint-disable no-proto */

    'use strict'

    var base64 = require('base64-js')
    var ieee754 = require('ieee754')
    var isArray = require('isarray')

    exports.Buffer = Buffer
    exports.SlowBuffer = SlowBuffer
    exports.INSPECT_MAX_BYTES = 50

    /**
     * If `Buffer.TYPED_ARRAY_SUPPORT`:
     *   === true    Use Uint8Array implementation (fastest)
     *   === false   Use Object implementation (most compatible, even IE6)
     *
     * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
     * Opera 11.6+, iOS 4.2+.
     *
     * Due to various browser bugs, sometimes the Object implementation will be used even
     * when the browser supports typed arrays.
     *
     * Note:
     *
     *   - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
     *     See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
     *
     *   - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
     *
     *   - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
     *     incorrect length in some situations.
    
     * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
     * get the Object implementation, which is slower but behaves correctly.
     */
    Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
      ? global.TYPED_ARRAY_SUPPORT
      : typedArraySupport()

    /*
     * Export kMaxLength after typed array support is determined.
     */
    exports.kMaxLength = kMaxLength()

    function typedArraySupport() {
      try {
        var arr = new Uint8Array(1)
        arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
        return arr.foo() === 42 && // typed array instances can be augmented
          typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
          arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
      } catch (e) {
        return false
      }
    }

    function kMaxLength() {
      return Buffer.TYPED_ARRAY_SUPPORT
        ? 0x7fffffff
        : 0x3fffffff
    }

    function createBuffer(that, length) {
      if (kMaxLength() < length) {
        throw new RangeError('Invalid typed array length')
      }
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        // Return an augmented `Uint8Array` instance, for best performance
        that = new Uint8Array(length)
        that.__proto__ = Buffer.prototype
      } else {
        // Fallback: Return an object instance of the Buffer class
        if (that === null) {
          that = new Buffer(length)
        }
        that.length = length
      }

      return that
    }

    /**
     * The Buffer constructor returns instances of `Uint8Array` that have their
     * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
     * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
     * and the `Uint8Array` methods. Square bracket notation works as expected -- it
     * returns a single octet.
     *
     * The `Uint8Array` prototype remains unmodified.
     */

    function Buffer(arg, encodingOrOffset, length) {
      if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
        return new Buffer(arg, encodingOrOffset, length)
      }

      // Common case.
      if (typeof arg === 'number') {
        if (typeof encodingOrOffset === 'string') {
          throw new Error(
            'If encoding is specified then the first argument must be a string'
          )
        }
        return allocUnsafe(this, arg)
      }
      return from(this, arg, encodingOrOffset, length)
    }

    Buffer.poolSize = 8192 // not used by this implementation

    // TODO: Legacy, not needed anymore. Remove in next major version.
    Buffer._augment = function (arr) {
      arr.__proto__ = Buffer.prototype
      return arr
    }

    function from(that, value, encodingOrOffset, length) {
      if (typeof value === 'number') {
        throw new TypeError('"value" argument must not be a number')
      }

      if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
        return fromArrayBuffer(that, value, encodingOrOffset, length)
      }

      if (typeof value === 'string') {
        return fromString(that, value, encodingOrOffset)
      }

      return fromObject(that, value)
    }

    /**
     * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
     * if value is a number.
     * Buffer.from(str[, encoding])
     * Buffer.from(array)
     * Buffer.from(buffer)
     * Buffer.from(arrayBuffer[, byteOffset[, length]])
     **/
    Buffer.from = function (value, encodingOrOffset, length) {
      return from(null, value, encodingOrOffset, length)
    }

    if (Buffer.TYPED_ARRAY_SUPPORT) {
      Buffer.prototype.__proto__ = Uint8Array.prototype
      Buffer.__proto__ = Uint8Array
      if (typeof Symbol !== 'undefined' && Symbol.species &&
        Buffer[Symbol.species] === Buffer) {
        // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
        Object.defineProperty(Buffer, Symbol.species, {
          value: null,
          configurable: true
        })
      }
    }

    function assertSize(size) {
      if (typeof size !== 'number') {
        throw new TypeError('"size" argument must be a number')
      } else if (size < 0) {
        throw new RangeError('"size" argument must not be negative')
      }
    }

    function alloc(that, size, fill, encoding) {
      assertSize(size)
      if (size <= 0) {
        return createBuffer(that, size)
      }
      if (fill !== undefined) {
        // Only pay attention to encoding if it's a string. This
        // prevents accidentally sending in a number that would
        // be interpretted as a start offset.
        return typeof encoding === 'string'
          ? createBuffer(that, size).fill(fill, encoding)
          : createBuffer(that, size).fill(fill)
      }
      return createBuffer(that, size)
    }

    /**
     * Creates a new filled Buffer instance.
     * alloc(size[, fill[, encoding]])
     **/
    Buffer.alloc = function (size, fill, encoding) {
      return alloc(null, size, fill, encoding)
    }

    function allocUnsafe(that, size) {
      assertSize(size)
      that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
      if (!Buffer.TYPED_ARRAY_SUPPORT) {
        for (var i = 0; i < size; ++i) {
          that[i] = 0
        }
      }
      return that
    }

    /**
     * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
     * */
    Buffer.allocUnsafe = function (size) {
      return allocUnsafe(null, size)
    }
    /**
     * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
     */
    Buffer.allocUnsafeSlow = function (size) {
      return allocUnsafe(null, size)
    }

    function fromString(that, string, encoding) {
      if (typeof encoding !== 'string' || encoding === '') {
        encoding = 'utf8'
      }

      if (!Buffer.isEncoding(encoding)) {
        throw new TypeError('"encoding" must be a valid string encoding')
      }

      var length = byteLength(string, encoding) | 0
      that = createBuffer(that, length)

      var actual = that.write(string, encoding)

      if (actual !== length) {
        // Writing a hex string, for example, that contains invalid characters will
        // cause everything after the first invalid character to be ignored. (e.g.
        // 'abxxcd' will be treated as 'ab')
        that = that.slice(0, actual)
      }

      return that
    }

    function fromArrayLike(that, array) {
      var length = array.length < 0 ? 0 : checked(array.length) | 0
      that = createBuffer(that, length)
      for (var i = 0; i < length; i += 1) {
        that[i] = array[i] & 255
      }
      return that
    }

    function fromArrayBuffer(that, array, byteOffset, length) {
      array.byteLength // this throws if `array` is not a valid ArrayBuffer

      if (byteOffset < 0 || array.byteLength < byteOffset) {
        throw new RangeError('\'offset\' is out of bounds')
      }

      if (array.byteLength < byteOffset + (length || 0)) {
        throw new RangeError('\'length\' is out of bounds')
      }

      if (byteOffset === undefined && length === undefined) {
        array = new Uint8Array(array)
      } else if (length === undefined) {
        array = new Uint8Array(array, byteOffset)
      } else {
        array = new Uint8Array(array, byteOffset, length)
      }

      if (Buffer.TYPED_ARRAY_SUPPORT) {
        // Return an augmented `Uint8Array` instance, for best performance
        that = array
        that.__proto__ = Buffer.prototype
      } else {
        // Fallback: Return an object instance of the Buffer class
        that = fromArrayLike(that, array)
      }
      return that
    }

    function fromObject(that, obj) {
      if (Buffer.isBuffer(obj)) {
        var len = checked(obj.length) | 0
        that = createBuffer(that, len)

        if (that.length === 0) {
          return that
        }

        obj.copy(that, 0, 0, len)
        return that
      }

      if (obj) {
        if ((typeof ArrayBuffer !== 'undefined' &&
          obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
          if (typeof obj.length !== 'number' || isnan(obj.length)) {
            return createBuffer(that, 0)
          }
          return fromArrayLike(that, obj)
        }

        if (obj.type === 'Buffer' && isArray(obj.data)) {
          return fromArrayLike(that, obj.data)
        }
      }

      throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
    }

    function checked(length) {
      // Note: cannot use `length < kMaxLength()` here because that fails when
      // length is NaN (which is otherwise coerced to zero.)
      if (length >= kMaxLength()) {
        throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
          'size: 0x' + kMaxLength().toString(16) + ' bytes')
      }
      return length | 0
    }

    function SlowBuffer(length) {
      if (+length != length) { // eslint-disable-line eqeqeq
        length = 0
      }
      return Buffer.alloc(+length)
    }

    Buffer.isBuffer = function isBuffer(b) {
      return !!(b != null && b._isBuffer)
    }

    Buffer.compare = function compare(a, b) {
      if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
        throw new TypeError('Arguments must be Buffers')
      }

      if (a === b) return 0

      var x = a.length
      var y = b.length

      for (var i = 0, len = Math.min(x, y); i < len; ++i) {
        if (a[i] !== b[i]) {
          x = a[i]
          y = b[i]
          break
        }
      }

      if (x < y) return -1
      if (y < x) return 1
      return 0
    }

    Buffer.isEncoding = function isEncoding(encoding) {
      switch (String(encoding).toLowerCase()) {
        case 'hex':
        case 'utf8':
        case 'utf-8':
        case 'ascii':
        case 'latin1':
        case 'binary':
        case 'base64':
        case 'ucs2':
        case 'ucs-2':
        case 'utf16le':
        case 'utf-16le':
          return true
        default:
          return false
      }
    }

    Buffer.concat = function concat(list, length) {
      if (!isArray(list)) {
        throw new TypeError('"list" argument must be an Array of Buffers')
      }

      if (list.length === 0) {
        return Buffer.alloc(0)
      }

      var i
      if (length === undefined) {
        length = 0
        for (i = 0; i < list.length; ++i) {
          length += list[i].length
        }
      }

      var buffer = Buffer.allocUnsafe(length)
      var pos = 0
      for (i = 0; i < list.length; ++i) {
        var buf = list[i]
        if (!Buffer.isBuffer(buf)) {
          throw new TypeError('"list" argument must be an Array of Buffers')
        }
        buf.copy(buffer, pos)
        pos += buf.length
      }
      return buffer
    }

    function byteLength(string, encoding) {
      if (Buffer.isBuffer(string)) {
        return string.length
      }
      if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
        (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
        return string.byteLength
      }
      if (typeof string !== 'string') {
        string = '' + string
      }

      var len = string.length
      if (len === 0) return 0

      // Use a for loop to avoid recursion
      var loweredCase = false
      for (; ;) {
        switch (encoding) {
          case 'ascii':
          case 'latin1':
          case 'binary':
            return len
          case 'utf8':
          case 'utf-8':
          case undefined:
            return utf8ToBytes(string).length
          case 'ucs2':
          case 'ucs-2':
          case 'utf16le':
          case 'utf-16le':
            return len * 2
          case 'hex':
            return len >>> 1
          case 'base64':
            return base64ToBytes(string).length
          default:
            if (loweredCase) return utf8ToBytes(string).length // assume utf8
            encoding = ('' + encoding).toLowerCase()
            loweredCase = true
        }
      }
    }
    Buffer.byteLength = byteLength

    function slowToString(encoding, start, end) {
      var loweredCase = false

      // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
      // property of a typed array.

      // This behaves neither like String nor Uint8Array in that we set start/end
      // to their upper/lower bounds if the value passed is out of range.
      // undefined is handled specially as per ECMA-262 6th Edition,
      // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
      if (start === undefined || start < 0) {
        start = 0
      }
      // Return early if start > this.length. Done here to prevent potential uint32
      // coercion fail below.
      if (start > this.length) {
        return ''
      }

      if (end === undefined || end > this.length) {
        end = this.length
      }

      if (end <= 0) {
        return ''
      }

      // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
      end >>>= 0
      start >>>= 0

      if (end <= start) {
        return ''
      }

      if (!encoding) encoding = 'utf8'

      while (true) {
        switch (encoding) {
          case 'hex':
            return hexSlice(this, start, end)

          case 'utf8':
          case 'utf-8':
            return utf8Slice(this, start, end)

          case 'ascii':
            return asciiSlice(this, start, end)

          case 'latin1':
          case 'binary':
            return latin1Slice(this, start, end)

          case 'base64':
            return base64Slice(this, start, end)

          case 'ucs2':
          case 'ucs-2':
          case 'utf16le':
          case 'utf-16le':
            return utf16leSlice(this, start, end)

          default:
            if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
            encoding = (encoding + '').toLowerCase()
            loweredCase = true
        }
      }
    }

    // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
    // Buffer instances.
    Buffer.prototype._isBuffer = true

    function swap(b, n, m) {
      var i = b[n]
      b[n] = b[m]
      b[m] = i
    }

    Buffer.prototype.swap16 = function swap16() {
      var len = this.length
      if (len % 2 !== 0) {
        throw new RangeError('Buffer size must be a multiple of 16-bits')
      }
      for (var i = 0; i < len; i += 2) {
        swap(this, i, i + 1)
      }
      return this
    }

    Buffer.prototype.swap32 = function swap32() {
      var len = this.length
      if (len % 4 !== 0) {
        throw new RangeError('Buffer size must be a multiple of 32-bits')
      }
      for (var i = 0; i < len; i += 4) {
        swap(this, i, i + 3)
        swap(this, i + 1, i + 2)
      }
      return this
    }

    Buffer.prototype.swap64 = function swap64() {
      var len = this.length
      if (len % 8 !== 0) {
        throw new RangeError('Buffer size must be a multiple of 64-bits')
      }
      for (var i = 0; i < len; i += 8) {
        swap(this, i, i + 7)
        swap(this, i + 1, i + 6)
        swap(this, i + 2, i + 5)
        swap(this, i + 3, i + 4)
      }
      return this
    }

    Buffer.prototype.toString = function toString() {
      var length = this.length | 0
      if (length === 0) return ''
      if (arguments.length === 0) return utf8Slice(this, 0, length)
      return slowToString.apply(this, arguments)
    }

    Buffer.prototype.equals = function equals(b) {
      if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
      if (this === b) return true
      return Buffer.compare(this, b) === 0
    }

    Buffer.prototype.inspect = function inspect() {
      var str = ''
      var max = exports.INSPECT_MAX_BYTES
      if (this.length > 0) {
        str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
        if (this.length > max) str += ' ... '
      }
      return '<Buffer ' + str + '>'
    }

    Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
      if (!Buffer.isBuffer(target)) {
        throw new TypeError('Argument must be a Buffer')
      }

      if (start === undefined) {
        start = 0
      }
      if (end === undefined) {
        end = target ? target.length : 0
      }
      if (thisStart === undefined) {
        thisStart = 0
      }
      if (thisEnd === undefined) {
        thisEnd = this.length
      }

      if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
        throw new RangeError('out of range index')
      }

      if (thisStart >= thisEnd && start >= end) {
        return 0
      }
      if (thisStart >= thisEnd) {
        return -1
      }
      if (start >= end) {
        return 1
      }

      start >>>= 0
      end >>>= 0
      thisStart >>>= 0
      thisEnd >>>= 0

      if (this === target) return 0

      var x = thisEnd - thisStart
      var y = end - start
      var len = Math.min(x, y)

      var thisCopy = this.slice(thisStart, thisEnd)
      var targetCopy = target.slice(start, end)

      for (var i = 0; i < len; ++i) {
        if (thisCopy[i] !== targetCopy[i]) {
          x = thisCopy[i]
          y = targetCopy[i]
          break
        }
      }

      if (x < y) return -1
      if (y < x) return 1
      return 0
    }

    // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
    // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
    //
    // Arguments:
    // - buffer - a Buffer to search
    // - val - a string, Buffer, or number
    // - byteOffset - an index into `buffer`; will be clamped to an int32
    // - encoding - an optional encoding, relevant is val is a string
    // - dir - true for indexOf, false for lastIndexOf
    function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
      // Empty buffer means no match
      if (buffer.length === 0) return -1

      // Normalize byteOffset
      if (typeof byteOffset === 'string') {
        encoding = byteOffset
        byteOffset = 0
      } else if (byteOffset > 0x7fffffff) {
        byteOffset = 0x7fffffff
      } else if (byteOffset < -0x80000000) {
        byteOffset = -0x80000000
      }
      byteOffset = +byteOffset  // Coerce to Number.
      if (isNaN(byteOffset)) {
        // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
        byteOffset = dir ? 0 : (buffer.length - 1)
      }

      // Normalize byteOffset: negative offsets start from the end of the buffer
      if (byteOffset < 0) byteOffset = buffer.length + byteOffset
      if (byteOffset >= buffer.length) {
        if (dir) return -1
        else byteOffset = buffer.length - 1
      } else if (byteOffset < 0) {
        if (dir) byteOffset = 0
        else return -1
      }

      // Normalize val
      if (typeof val === 'string') {
        val = Buffer.from(val, encoding)
      }

      // Finally, search either indexOf (if dir is true) or lastIndexOf
      if (Buffer.isBuffer(val)) {
        // Special case: looking for empty string/buffer always fails
        if (val.length === 0) {
          return -1
        }
        return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
      } else if (typeof val === 'number') {
        val = val & 0xFF // Search for a byte value [0-255]
        if (Buffer.TYPED_ARRAY_SUPPORT &&
          typeof Uint8Array.prototype.indexOf === 'function') {
          if (dir) {
            return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
          } else {
            return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
          }
        }
        return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
      }

      throw new TypeError('val must be string, number or Buffer')
    }

    function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
      var indexSize = 1
      var arrLength = arr.length
      var valLength = val.length

      if (encoding !== undefined) {
        encoding = String(encoding).toLowerCase()
        if (encoding === 'ucs2' || encoding === 'ucs-2' ||
          encoding === 'utf16le' || encoding === 'utf-16le') {
          if (arr.length < 2 || val.length < 2) {
            return -1
          }
          indexSize = 2
          arrLength /= 2
          valLength /= 2
          byteOffset /= 2
        }
      }

      function read(buf, i) {
        if (indexSize === 1) {
          return buf[i]
        } else {
          return buf.readUInt16BE(i * indexSize)
        }
      }

      var i
      if (dir) {
        var foundIndex = -1
        for (i = byteOffset; i < arrLength; i++) {
          if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
            if (foundIndex === -1) foundIndex = i
            if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
          } else {
            if (foundIndex !== -1) i -= i - foundIndex
            foundIndex = -1
          }
        }
      } else {
        if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
        for (i = byteOffset; i >= 0; i--) {
          var found = true
          for (var j = 0; j < valLength; j++) {
            if (read(arr, i + j) !== read(val, j)) {
              found = false
              break
            }
          }
          if (found) return i
        }
      }

      return -1
    }

    Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
      return this.indexOf(val, byteOffset, encoding) !== -1
    }

    Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
      return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
    }

    Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
      return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
    }

    function hexWrite(buf, string, offset, length) {
      offset = Number(offset) || 0
      var remaining = buf.length - offset
      if (!length) {
        length = remaining
      } else {
        length = Number(length)
        if (length > remaining) {
          length = remaining
        }
      }

      // must be an even number of digits
      var strLen = string.length
      if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')

      if (length > strLen / 2) {
        length = strLen / 2
      }
      for (var i = 0; i < length; ++i) {
        var parsed = parseInt(string.substr(i * 2, 2), 16)
        if (isNaN(parsed)) return i
        buf[offset + i] = parsed
      }
      return i
    }

    function utf8Write(buf, string, offset, length) {
      return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
    }

    function asciiWrite(buf, string, offset, length) {
      return blitBuffer(asciiToBytes(string), buf, offset, length)
    }

    function latin1Write(buf, string, offset, length) {
      return asciiWrite(buf, string, offset, length)
    }

    function base64Write(buf, string, offset, length) {
      return blitBuffer(base64ToBytes(string), buf, offset, length)
    }

    function ucs2Write(buf, string, offset, length) {
      return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
    }

    Buffer.prototype.write = function write(string, offset, length, encoding) {
      // Buffer#write(string)
      if (offset === undefined) {
        encoding = 'utf8'
        length = this.length
        offset = 0
        // Buffer#write(string, encoding)
      } else if (length === undefined && typeof offset === 'string') {
        encoding = offset
        length = this.length
        offset = 0
        // Buffer#write(string, offset[, length][, encoding])
      } else if (isFinite(offset)) {
        offset = offset | 0
        if (isFinite(length)) {
          length = length | 0
          if (encoding === undefined) encoding = 'utf8'
        } else {
          encoding = length
          length = undefined
        }
        // legacy write(string, encoding, offset, length) - remove in v0.13
      } else {
        throw new Error(
          'Buffer.write(string, encoding, offset[, length]) is no longer supported'
        )
      }

      var remaining = this.length - offset
      if (length === undefined || length > remaining) length = remaining

      if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
        throw new RangeError('Attempt to write outside buffer bounds')
      }

      if (!encoding) encoding = 'utf8'

      var loweredCase = false
      for (; ;) {
        switch (encoding) {
          case 'hex':
            return hexWrite(this, string, offset, length)

          case 'utf8':
          case 'utf-8':
            return utf8Write(this, string, offset, length)

          case 'ascii':
            return asciiWrite(this, string, offset, length)

          case 'latin1':
          case 'binary':
            return latin1Write(this, string, offset, length)

          case 'base64':
            // Warning: maxLength not taken into account in base64Write
            return base64Write(this, string, offset, length)

          case 'ucs2':
          case 'ucs-2':
          case 'utf16le':
          case 'utf-16le':
            return ucs2Write(this, string, offset, length)

          default:
            if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
            encoding = ('' + encoding).toLowerCase()
            loweredCase = true
        }
      }
    }

    Buffer.prototype.toJSON = function toJSON() {
      return {
        type: 'Buffer',
        data: Array.prototype.slice.call(this._arr || this, 0)
      }
    }

    function base64Slice(buf, start, end) {
      if (start === 0 && end === buf.length) {
        return base64.fromByteArray(buf)
      } else {
        return base64.fromByteArray(buf.slice(start, end))
      }
    }

    function utf8Slice(buf, start, end) {
      end = Math.min(buf.length, end)
      var res = []

      var i = start
      while (i < end) {
        var firstByte = buf[i]
        var codePoint = null
        var bytesPerSequence = (firstByte > 0xEF) ? 4
          : (firstByte > 0xDF) ? 3
            : (firstByte > 0xBF) ? 2
              : 1

        if (i + bytesPerSequence <= end) {
          var secondByte, thirdByte, fourthByte, tempCodePoint

          switch (bytesPerSequence) {
            case 1:
              if (firstByte < 0x80) {
                codePoint = firstByte
              }
              break
            case 2:
              secondByte = buf[i + 1]
              if ((secondByte & 0xC0) === 0x80) {
                tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
                if (tempCodePoint > 0x7F) {
                  codePoint = tempCodePoint
                }
              }
              break
            case 3:
              secondByte = buf[i + 1]
              thirdByte = buf[i + 2]
              if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
                tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
                if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
                  codePoint = tempCodePoint
                }
              }
              break
            case 4:
              secondByte = buf[i + 1]
              thirdByte = buf[i + 2]
              fourthByte = buf[i + 3]
              if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
                tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
                if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
                  codePoint = tempCodePoint
                }
              }
          }
        }

        if (codePoint === null) {
          // we did not generate a valid codePoint so insert a
          // replacement char (U+FFFD) and advance only 1 byte
          codePoint = 0xFFFD
          bytesPerSequence = 1
        } else if (codePoint > 0xFFFF) {
          // encode to utf16 (surrogate pair dance)
          codePoint -= 0x10000
          res.push(codePoint >>> 10 & 0x3FF | 0xD800)
          codePoint = 0xDC00 | codePoint & 0x3FF
        }

        res.push(codePoint)
        i += bytesPerSequence
      }

      return decodeCodePointsArray(res)
    }

    // Based on http://stackoverflow.com/a/22747272/680742, the browser with
    // the lowest limit is Chrome, with 0x10000 args.
    // We go 1 magnitude less, for safety
    var MAX_ARGUMENTS_LENGTH = 0x1000

    function decodeCodePointsArray(codePoints) {
      var len = codePoints.length
      if (len <= MAX_ARGUMENTS_LENGTH) {
        return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
      }

      // Decode in chunks to avoid "call stack size exceeded".
      var res = ''
      var i = 0
      while (i < len) {
        res += String.fromCharCode.apply(
          String,
          codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
        )
      }
      return res
    }

    function asciiSlice(buf, start, end) {
      var ret = ''
      end = Math.min(buf.length, end)

      for (var i = start; i < end; ++i) {
        ret += String.fromCharCode(buf[i] & 0x7F)
      }
      return ret
    }

    function latin1Slice(buf, start, end) {
      var ret = ''
      end = Math.min(buf.length, end)

      for (var i = start; i < end; ++i) {
        ret += String.fromCharCode(buf[i])
      }
      return ret
    }

    function hexSlice(buf, start, end) {
      var len = buf.length

      if (!start || start < 0) start = 0
      if (!end || end < 0 || end > len) end = len

      var out = ''
      for (var i = start; i < end; ++i) {
        out += toHex(buf[i])
      }
      return out
    }

    function utf16leSlice(buf, start, end) {
      var bytes = buf.slice(start, end)
      var res = ''
      for (var i = 0; i < bytes.length; i += 2) {
        res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
      }
      return res
    }

    Buffer.prototype.slice = function slice(start, end) {
      var len = this.length
      start = ~~start
      end = end === undefined ? len : ~~end

      if (start < 0) {
        start += len
        if (start < 0) start = 0
      } else if (start > len) {
        start = len
      }

      if (end < 0) {
        end += len
        if (end < 0) end = 0
      } else if (end > len) {
        end = len
      }

      if (end < start) end = start

      var newBuf
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        newBuf = this.subarray(start, end)
        newBuf.__proto__ = Buffer.prototype
      } else {
        var sliceLen = end - start
        newBuf = new Buffer(sliceLen, undefined)
        for (var i = 0; i < sliceLen; ++i) {
          newBuf[i] = this[i + start]
        }
      }

      return newBuf
    }

    /*
     * Need to make sure that buffer isn't trying to write out of bounds.
     */
    function checkOffset(offset, ext, length) {
      if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
      if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
    }

    Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) checkOffset(offset, byteLength, this.length)

      var val = this[offset]
      var mul = 1
      var i = 0
      while (++i < byteLength && (mul *= 0x100)) {
        val += this[offset + i] * mul
      }

      return val
    }

    Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) {
        checkOffset(offset, byteLength, this.length)
      }

      var val = this[offset + --byteLength]
      var mul = 1
      while (byteLength > 0 && (mul *= 0x100)) {
        val += this[offset + --byteLength] * mul
      }

      return val
    }

    Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 1, this.length)
      return this[offset]
    }

    Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 2, this.length)
      return this[offset] | (this[offset + 1] << 8)
    }

    Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 2, this.length)
      return (this[offset] << 8) | this[offset + 1]
    }

    Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)

      return ((this[offset]) |
        (this[offset + 1] << 8) |
        (this[offset + 2] << 16)) +
        (this[offset + 3] * 0x1000000)
    }

    Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)

      return (this[offset] * 0x1000000) +
        ((this[offset + 1] << 16) |
          (this[offset + 2] << 8) |
          this[offset + 3])
    }

    Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) checkOffset(offset, byteLength, this.length)

      var val = this[offset]
      var mul = 1
      var i = 0
      while (++i < byteLength && (mul *= 0x100)) {
        val += this[offset + i] * mul
      }
      mul *= 0x80

      if (val >= mul) val -= Math.pow(2, 8 * byteLength)

      return val
    }

    Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) checkOffset(offset, byteLength, this.length)

      var i = byteLength
      var mul = 1
      var val = this[offset + --i]
      while (i > 0 && (mul *= 0x100)) {
        val += this[offset + --i] * mul
      }
      mul *= 0x80

      if (val >= mul) val -= Math.pow(2, 8 * byteLength)

      return val
    }

    Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 1, this.length)
      if (!(this[offset] & 0x80)) return (this[offset])
      return ((0xff - this[offset] + 1) * -1)
    }

    Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 2, this.length)
      var val = this[offset] | (this[offset + 1] << 8)
      return (val & 0x8000) ? val | 0xFFFF0000 : val
    }

    Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 2, this.length)
      var val = this[offset + 1] | (this[offset] << 8)
      return (val & 0x8000) ? val | 0xFFFF0000 : val
    }

    Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)

      return (this[offset]) |
        (this[offset + 1] << 8) |
        (this[offset + 2] << 16) |
        (this[offset + 3] << 24)
    }

    Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)

      return (this[offset] << 24) |
        (this[offset + 1] << 16) |
        (this[offset + 2] << 8) |
        (this[offset + 3])
    }

    Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)
      return ieee754.read(this, offset, true, 23, 4)
    }

    Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 4, this.length)
      return ieee754.read(this, offset, false, 23, 4)
    }

    Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 8, this.length)
      return ieee754.read(this, offset, true, 52, 8)
    }

    Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
      if (!noAssert) checkOffset(offset, 8, this.length)
      return ieee754.read(this, offset, false, 52, 8)
    }

    function checkInt(buf, value, offset, ext, max, min) {
      if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
      if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
      if (offset + ext > buf.length) throw new RangeError('Index out of range')
    }

    Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
      value = +value
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) {
        var maxBytes = Math.pow(2, 8 * byteLength) - 1
        checkInt(this, value, offset, byteLength, maxBytes, 0)
      }

      var mul = 1
      var i = 0
      this[offset] = value & 0xFF
      while (++i < byteLength && (mul *= 0x100)) {
        this[offset + i] = (value / mul) & 0xFF
      }

      return offset + byteLength
    }

    Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
      value = +value
      offset = offset | 0
      byteLength = byteLength | 0
      if (!noAssert) {
        var maxBytes = Math.pow(2, 8 * byteLength) - 1
        checkInt(this, value, offset, byteLength, maxBytes, 0)
      }

      var i = byteLength - 1
      var mul = 1
      this[offset + i] = value & 0xFF
      while (--i >= 0 && (mul *= 0x100)) {
        this[offset + i] = (value / mul) & 0xFF
      }

      return offset + byteLength
    }

    Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
      if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
      this[offset] = (value & 0xff)
      return offset + 1
    }

    function objectWriteUInt16(buf, value, offset, littleEndian) {
      if (value < 0) value = 0xffff + value + 1
      for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
        buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
          (littleEndian ? i : 1 - i) * 8
      }
    }

    Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value & 0xff)
        this[offset + 1] = (value >>> 8)
      } else {
        objectWriteUInt16(this, value, offset, true)
      }
      return offset + 2
    }

    Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value >>> 8)
        this[offset + 1] = (value & 0xff)
      } else {
        objectWriteUInt16(this, value, offset, false)
      }
      return offset + 2
    }

    function objectWriteUInt32(buf, value, offset, littleEndian) {
      if (value < 0) value = 0xffffffff + value + 1
      for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
        buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
      }
    }

    Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset + 3] = (value >>> 24)
        this[offset + 2] = (value >>> 16)
        this[offset + 1] = (value >>> 8)
        this[offset] = (value & 0xff)
      } else {
        objectWriteUInt32(this, value, offset, true)
      }
      return offset + 4
    }

    Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value >>> 24)
        this[offset + 1] = (value >>> 16)
        this[offset + 2] = (value >>> 8)
        this[offset + 3] = (value & 0xff)
      } else {
        objectWriteUInt32(this, value, offset, false)
      }
      return offset + 4
    }

    Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) {
        var limit = Math.pow(2, 8 * byteLength - 1)

        checkInt(this, value, offset, byteLength, limit - 1, -limit)
      }

      var i = 0
      var mul = 1
      var sub = 0
      this[offset] = value & 0xFF
      while (++i < byteLength && (mul *= 0x100)) {
        if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
          sub = 1
        }
        this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
      }

      return offset + byteLength
    }

    Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) {
        var limit = Math.pow(2, 8 * byteLength - 1)

        checkInt(this, value, offset, byteLength, limit - 1, -limit)
      }

      var i = byteLength - 1
      var mul = 1
      var sub = 0
      this[offset + i] = value & 0xFF
      while (--i >= 0 && (mul *= 0x100)) {
        if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
          sub = 1
        }
        this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
      }

      return offset + byteLength
    }

    Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
      if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
      if (value < 0) value = 0xff + value + 1
      this[offset] = (value & 0xff)
      return offset + 1
    }

    Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value & 0xff)
        this[offset + 1] = (value >>> 8)
      } else {
        objectWriteUInt16(this, value, offset, true)
      }
      return offset + 2
    }

    Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value >>> 8)
        this[offset + 1] = (value & 0xff)
      } else {
        objectWriteUInt16(this, value, offset, false)
      }
      return offset + 2
    }

    Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value & 0xff)
        this[offset + 1] = (value >>> 8)
        this[offset + 2] = (value >>> 16)
        this[offset + 3] = (value >>> 24)
      } else {
        objectWriteUInt32(this, value, offset, true)
      }
      return offset + 4
    }

    Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
      value = +value
      offset = offset | 0
      if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
      if (value < 0) value = 0xffffffff + value + 1
      if (Buffer.TYPED_ARRAY_SUPPORT) {
        this[offset] = (value >>> 24)
        this[offset + 1] = (value >>> 16)
        this[offset + 2] = (value >>> 8)
        this[offset + 3] = (value & 0xff)
      } else {
        objectWriteUInt32(this, value, offset, false)
      }
      return offset + 4
    }

    function checkIEEE754(buf, value, offset, ext, max, min) {
      if (offset + ext > buf.length) throw new RangeError('Index out of range')
      if (offset < 0) throw new RangeError('Index out of range')
    }

    function writeFloat(buf, value, offset, littleEndian, noAssert) {
      if (!noAssert) {
        checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
      }
      ieee754.write(buf, value, offset, littleEndian, 23, 4)
      return offset + 4
    }

    Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
      return writeFloat(this, value, offset, true, noAssert)
    }

    Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
      return writeFloat(this, value, offset, false, noAssert)
    }

    function writeDouble(buf, value, offset, littleEndian, noAssert) {
      if (!noAssert) {
        checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
      }
      ieee754.write(buf, value, offset, littleEndian, 52, 8)
      return offset + 8
    }

    Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
      return writeDouble(this, value, offset, true, noAssert)
    }

    Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
      return writeDouble(this, value, offset, false, noAssert)
    }

    // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
    Buffer.prototype.copy = function copy(target, targetStart, start, end) {
      if (!start) start = 0
      if (!end && end !== 0) end = this.length
      if (targetStart >= target.length) targetStart = target.length
      if (!targetStart) targetStart = 0
      if (end > 0 && end < start) end = start

      // Copy 0 bytes; we're done
      if (end === start) return 0
      if (target.length === 0 || this.length === 0) return 0

      // Fatal error conditions
      if (targetStart < 0) {
        throw new RangeError('targetStart out of bounds')
      }
      if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
      if (end < 0) throw new RangeError('sourceEnd out of bounds')

      // Are we oob?
      if (end > this.length) end = this.length
      if (target.length - targetStart < end - start) {
        end = target.length - targetStart + start
      }

      var len = end - start
      var i

      if (this === target && start < targetStart && targetStart < end) {
        // descending copy from end
        for (i = len - 1; i >= 0; --i) {
          target[i + targetStart] = this[i + start]
        }
      } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
        // ascending copy from start
        for (i = 0; i < len; ++i) {
          target[i + targetStart] = this[i + start]
        }
      } else {
        Uint8Array.prototype.set.call(
          target,
          this.subarray(start, start + len),
          targetStart
        )
      }

      return len
    }

    // Usage:
    //    buffer.fill(number[, offset[, end]])
    //    buffer.fill(buffer[, offset[, end]])
    //    buffer.fill(string[, offset[, end]][, encoding])
    Buffer.prototype.fill = function fill(val, start, end, encoding) {
      // Handle string cases:
      if (typeof val === 'string') {
        if (typeof start === 'string') {
          encoding = start
          start = 0
          end = this.length
        } else if (typeof end === 'string') {
          encoding = end
          end = this.length
        }
        if (val.length === 1) {
          var code = val.charCodeAt(0)
          if (code < 256) {
            val = code
          }
        }
        if (encoding !== undefined && typeof encoding !== 'string') {
          throw new TypeError('encoding must be a string')
        }
        if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
          throw new TypeError('Unknown encoding: ' + encoding)
        }
      } else if (typeof val === 'number') {
        val = val & 255
      }

      // Invalid ranges are not set to a default, so can range check early.
      if (start < 0 || this.length < start || this.length < end) {
        throw new RangeError('Out of range index')
      }

      if (end <= start) {
        return this
      }

      start = start >>> 0
      end = end === undefined ? this.length : end >>> 0

      if (!val) val = 0

      var i
      if (typeof val === 'number') {
        for (i = start; i < end; ++i) {
          this[i] = val
        }
      } else {
        var bytes = Buffer.isBuffer(val)
          ? val
          : utf8ToBytes(new Buffer(val, encoding).toString())
        var len = bytes.length
        for (i = 0; i < end - start; ++i) {
          this[i + start] = bytes[i % len]
        }
      }

      return this
    }

    // HELPER FUNCTIONS
    // ================

    var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g

    function base64clean(str) {
      // Node strips out invalid characters like \n and \t from the string, base64-js does not
      str = stringtrim(str).replace(INVALID_BASE64_RE, '')
      // Node converts strings with length < 2 to ''
      if (str.length < 2) return ''
      // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
      while (str.length % 4 !== 0) {
        str = str + '='
      }
      return str
    }

    function stringtrim(str) {
      if (str.trim) return str.trim()
      return str.replace(/^\s+|\s+$/g, '')
    }

    function toHex(n) {
      if (n < 16) return '0' + n.toString(16)
      return n.toString(16)
    }

    function utf8ToBytes(string, units) {
      units = units || Infinity
      var codePoint
      var length = string.length
      var leadSurrogate = null
      var bytes = []

      for (var i = 0; i < length; ++i) {
        codePoint = string.charCodeAt(i)

        // is surrogate component
        if (codePoint > 0xD7FF && codePoint < 0xE000) {
          // last char was a lead
          if (!leadSurrogate) {
            // no lead yet
            if (codePoint > 0xDBFF) {
              // unexpected trail
              if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
              continue
            } else if (i + 1 === length) {
              // unpaired lead
              if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
              continue
            }

            // valid lead
            leadSurrogate = codePoint

            continue
          }

          // 2 leads in a row
          if (codePoint < 0xDC00) {
            if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
            leadSurrogate = codePoint
            continue
          }

          // valid surrogate pair
          codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
        } else if (leadSurrogate) {
          // valid bmp char, but last char was a lead
          if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
        }

        leadSurrogate = null

        // encode utf8
        if (codePoint < 0x80) {
          if ((units -= 1) < 0) break
          bytes.push(codePoint)
        } else if (codePoint < 0x800) {
          if ((units -= 2) < 0) break
          bytes.push(
            codePoint >> 0x6 | 0xC0,
            codePoint & 0x3F | 0x80
          )
        } else if (codePoint < 0x10000) {
          if ((units -= 3) < 0) break
          bytes.push(
            codePoint >> 0xC | 0xE0,
            codePoint >> 0x6 & 0x3F | 0x80,
            codePoint & 0x3F | 0x80
          )
        } else if (codePoint < 0x110000) {
          if ((units -= 4) < 0) break
          bytes.push(
            codePoint >> 0x12 | 0xF0,
            codePoint >> 0xC & 0x3F | 0x80,
            codePoint >> 0x6 & 0x3F | 0x80,
            codePoint & 0x3F | 0x80
          )
        } else {
          throw new Error('Invalid code point')
        }
      }

      return bytes
    }

    function asciiToBytes(str) {
      var byteArray = []
      for (var i = 0; i < str.length; ++i) {
        // Node's code seems to be doing this and not & 0x7F..
        byteArray.push(str.charCodeAt(i) & 0xFF)
      }
      return byteArray
    }

    function utf16leToBytes(str, units) {
      var c, hi, lo
      var byteArray = []
      for (var i = 0; i < str.length; ++i) {
        if ((units -= 2) < 0) break

        c = str.charCodeAt(i)
        hi = c >> 8
        lo = c % 256
        byteArray.push(lo)
        byteArray.push(hi)
      }

      return byteArray
    }

    function base64ToBytes(str) {
      return base64.toByteArray(base64clean(str))
    }

    function blitBuffer(src, dst, offset, length) {
      for (var i = 0; i < length; ++i) {
        if ((i + offset >= dst.length) || (i >= src.length)) break
        dst[i + offset] = src[i]
      }
      return i
    }

    function isnan(val) {
      return val !== val // eslint-disable-line no-self-compare
    }

  }, { "base64-js": "node_modules/base64-js/index.js", "ieee754": "node_modules/ieee754/index.js", "isarray": "node_modules/isarray/index.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js": [function (require, module, exports) {
    var global = arguments[3];
    var process = require("process");
    var Buffer = require("buffer").Buffer;
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.backend = on;
    exports.buffer = ur;
    exports.customGrad = oo;
    exports.deprecationWarn = ze;
    exports.disableDeprecationWarnings = Ve;
    exports.dispose = Xe;
    exports.disposeVariables = Ge;
    exports.enableDebugMode = Ue;
    exports.enableProdMode = We;
    exports.engine = He;
    exports.env = a;
    exports.fill = Ln;
    exports.findBackend = en;
    exports.findBackendFactory = nn;
    exports.getBackend = Ze;
    exports.getKernel = s;
    exports.getKernelsForBackend = c;
    exports.grad = Zr;
    exports.grads = to;
    exports.keep = $e;
    exports.linspace = Wn;
    exports.memory = qe;
    exports.nextFrame = ep;
    exports.ones = Bn;
    exports.op = Cn;
    exports.print = sr;
    exports.profile = Ke;
    exports.range = Un;
    exports.ready = Je;
    exports.registerBackend = rn;
    exports.registerKernel = l;
    exports.removeBackend = tn;
    exports.scalar = An;
    exports.setBackend = Qe;
    exports.setPlatform = an;
    exports.tensor = kn;
    exports.tensor1d = Dn;
    exports.tensor2d = Tn;
    exports.tensor3d = Nn;
    exports.tensor4d = Fn;
    exports.tensor5d = On;
    exports.tensor6d = _n;
    exports.tidy = je;
    exports.time = Ye;
    exports.unregisterKernel = h;
    exports.valueAndGrad = eo;
    exports.valueAndGrads = no;
    exports.variable = Mn;
    exports.variableGrads = ro;
    exports.zeros = Pn;
    exports.isFinite = exports.irfft = exports.io = exports.inTopKAsync = exports.image = exports.imag = exports.ifft = exports.hannWindow = exports.hammingWindow = exports.greaterStrict = exports.greaterEqualStrict = exports.greaterEqual = exports.greater = exports.gatherND = exports.gather = exports.fused = exports.frame = exports.floorDiv = exports.floor = exports.fft = exports.eye = exports.expm1 = exports.expandDims = exports.exp = exports.erf = exports.equalStrict = exports.equal = exports.elu = exports.dropout = exports.dot = exports.divStrict = exports.div = exports.diag = exports.depthwiseConv2d = exports.depthToSpace = exports.cumsum = exports.cosh = exports.cos = exports.conv3dTranspose = exports.conv3d = exports.conv2dTranspose = exports.conv2d = exports.conv1d = exports.concat4d = exports.concat3d = exports.concat2d = exports.concat1d = exports.concat = exports.complex = exports.clone = exports.clipByValue = exports.ceil = exports.cast = exports.browser = exports.booleanMaskAsync = exports.batchToSpaceND = exports.batchNormalization4d = exports.batchNormalization3d = exports.batchNormalization2d = exports.batchNormalization = exports.batchNorm4d = exports.batchNorm3d = exports.batchNorm2d = exports.batchNorm = exports.basicLSTMCell = exports.backend_util = exports.avgPool3d = exports.avgPool = exports.atanh = exports.atan2 = exports.atan = exports.asinh = exports.asin = exports.argMin = exports.argMax = exports.any = exports.all = exports.addStrict = exports.addN = exports.add = exports.acosh = exports.acos = exports.abs = exports.Variable = exports.TensorBuffer = exports.Tensor = exports.SGDOptimizer = exports.Reduction = exports.Rank = exports.RMSPropOptimizer = exports.Optimizer = exports.MomentumOptimizer = exports.KernelBackend = exports.Environment = exports.ENV = exports.DataStorage = exports.AdamaxOptimizer = exports.AdamOptimizer = exports.AdagradOptimizer = exports.AdadeltaOptimizer = void 0;
    exports.stack = exports.squeeze = exports.squaredDifferenceStrict = exports.squaredDifference = exports.square = exports.sqrt = exports.split = exports.spectral = exports.sparseToDense = exports.spaceToBatchND = exports.softplus = exports.softmax = exports.slice_util = exports.slice4d = exports.slice3d = exports.slice2d = exports.slice1d = exports.slice = exports.sinh = exports.sin = exports.signal = exports.sign = exports.sigmoid = exports.setdiff1dAsync = exports.serialization = exports.separableConv2d = exports.selu = exports.scatterND = exports.rsqrt = exports.round = exports.rfft = exports.reverse4d = exports.reverse3d = exports.reverse2d = exports.reverse1d = exports.reverse = exports.reshape = exports.relu6 = exports.relu = exports.reciprocal = exports.real = exports.randomUniform = exports.randomNormal = exports.randomGamma = exports.rand = exports.prod = exports.prelu = exports.powStrict = exports.pow = exports.pool = exports.pad4d = exports.pad3d = exports.pad2d = exports.pad1d = exports.pad = exports.outerProduct = exports.onesLike = exports.oneHot = exports.notEqualStrict = exports.notEqual = exports.norm = exports.neg = exports.multinomial = exports.multiRNNCell = exports.mulStrict = exports.mul = exports.movingAverage = exports.moments = exports.modStrict = exports.mod = exports.minimumStrict = exports.minimum = exports.min = exports.mean = exports.maximumStrict = exports.maximum = exports.maxPool3d = exports.maxPool = exports.max = exports.math = exports.matMul = exports.losses = exports.logicalXor = exports.logicalOr = exports.logicalNot = exports.logicalAnd = exports.logSumExp = exports.logSoftmax = exports.logSigmoid = exports.log1p = exports.log = exports.localResponseNormalization = exports.linalg = exports.lessStrict = exports.lessEqualStrict = exports.lessEqual = exports.less = exports.leakyRelu = exports.isNaN = exports.isInf = void 0;
    exports.zerosLike = exports.whereAsync = exports.where = exports.webgl = exports.version_core = exports.util = exports.unstack = exports.unsortedSegmentSum = exports.truncatedNormal = exports.transpose = exports.train = exports.topk = exports.tile = exports.test_util = exports.tensor_util = exports.tanh = exports.tan = exports.sum = exports.subStrict = exports.sub = exports.stridedSlice = exports.stft = exports.step = void 0;

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    var t = function (e, n) {
      return (t = Object.setPrototypeOf || {
        __proto__: []
      } instanceof Array && function (t, e) {
        t.__proto__ = e;
      } || function (t, e) {
        for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
      })(e, n);
    };

    function e(e, n) {
      function r() {
        this.constructor = e;
      }

      t(e, n), e.prototype = null === n ? Object.create(n) : (r.prototype = n.prototype, new r());
    }

    function n(t, e, n, r) {
      return new (n || (n = Promise))(function (o, a) {
        function i(t) {
          try {
            s(r.next(t));
          } catch (t) {
            a(t);
          }
        }

        function u(t) {
          try {
            s(r.throw(t));
          } catch (t) {
            a(t);
          }
        }

        function s(t) {
          t.done ? o(t.value) : new n(function (e) {
            e(t.value);
          }).then(i, u);
        }

        s((r = r.apply(t, e || [])).next());
      });
    }

    function r(t, e) {
      var n,
        r,
        o,
        a,
        i = {
          label: 0,
          sent: function () {
            if (1 & o[0]) throw o[1];
            return o[1];
          },
          trys: [],
          ops: []
        };
      return a = {
        next: u(0),
        throw: u(1),
        return: u(2)
      }, "function" == typeof Symbol && (a[Symbol.iterator] = function () {
        return this;
      }), a;

      function u(a) {
        return function (u) {
          return function (a) {
            if (n) throw new TypeError("Generator is already executing.");

            for (; i;) try {
              if (n = 1, r && (o = 2 & a[0] ? r.return : a[0] ? r.throw || ((o = r.return) && o.call(r), 0) : r.next) && !(o = o.call(r, a[1])).done) return o;

              switch (r = 0, o && (a = [2 & a[0], o.value]), a[0]) {
                case 0:
                case 1:
                  o = a;
                  break;

                case 4:
                  return i.label++, {
                    value: a[1],
                    done: !1
                  };

                case 5:
                  i.label++, r = a[1], a = [0];
                  continue;

                case 7:
                  a = i.ops.pop(), i.trys.pop();
                  continue;

                default:
                  if (!(o = (o = i.trys).length > 0 && o[o.length - 1]) && (6 === a[0] || 2 === a[0])) {
                    i = 0;
                    continue;
                  }

                  if (3 === a[0] && (!o || a[1] > o[0] && a[1] < o[3])) {
                    i.label = a[1];
                    break;
                  }

                  if (6 === a[0] && i.label < o[1]) {
                    i.label = o[1], o = a;
                    break;
                  }

                  if (o && i.label < o[2]) {
                    i.label = o[2], i.ops.push(a);
                    break;
                  }

                  o[2] && i.ops.pop(), i.trys.pop();
                  continue;
              }

              a = e.call(t, i);
            } catch (t) {
              a = [6, t], r = 0;
            } finally {
                n = o = 0;
              }

            if (5 & a[0]) throw a[1];
            return {
              value: a[0] ? a[1] : void 0,
              done: !0
            };
          }([a, u]);
        };
      }
    }

    var o = function () {
      function t(t) {
        this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.populateURLFlags();
      }

      return t.prototype.setPlatform = function (t, e) {
        null != this.platform && console.warn("Platform " + this.platformName + " has already been set. Overwriting the platform with " + e + "."), this.platformName = t, this.platform = e;
      }, t.prototype.registerFlag = function (t, e, n) {
        if (this.flagRegistry[t] = {
          evaluationFn: e,
          setHook: n
        }, null != this.urlFlags[t]) {
          var r = this.urlFlags[t];
          console.warn("Setting feature override from URL " + t + ": " + r + "."), this.set(t, r);
        }
      }, t.prototype.get = function (t) {
        return t in this.flags ? this.flags[t] : (this.flags[t] = this.evaluateFlag(t), this.flags[t]);
      }, t.prototype.getNumber = function (t) {
        return this.get(t);
      }, t.prototype.getBool = function (t) {
        return this.get(t);
      }, t.prototype.getFlags = function () {
        return this.flags;
      }, Object.defineProperty(t.prototype, "features", {
        get: function () {
          return this.flags;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.set = function (t, e) {
        if (null == this.flagRegistry[t]) throw new Error("Cannot set flag " + t + " as it has not been registered.");
        this.flags[t] = e, null != this.flagRegistry[t].setHook && this.flagRegistry[t].setHook(e);
      }, t.prototype.evaluateFlag = function (t) {
        if (null == this.flagRegistry[t]) throw new Error("Cannot evaluate flag '" + t + "': no evaluation function found.");
        return this.flagRegistry[t].evaluationFn();
      }, t.prototype.setFlags = function (t) {
        this.flags = Object.assign({}, t);
      }, t.prototype.reset = function () {
        this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
      }, t.prototype.populateURLFlags = function () {
        var t = this;

        if (void 0 !== this.global && void 0 !== this.global.location && void 0 !== this.global.location.search) {
          var e,
            n,
            r = (e = this.global.location.search, n = {}, e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (t) {
              for (var e = [], r = 1; r < arguments.length; r++) e[r - 1] = arguments[r];

              return function (t, e, n) {
                t[decodeURIComponent(e)] = decodeURIComponent(n || "");
              }(n, e[0], e[1]), e.join("=");
            }), n);
          if ("tfjsflags" in r) r.tfjsflags.split(",").forEach(function (e) {
            var n = e.split(":"),
              r = n[0],
              o = n[1];

            t.urlFlags[r] = function (t, e) {
              if ("true" === (e = e.toLowerCase()) || "false" === e) return "true" === e;
              if ("" + +e === e) return +e;
              throw new Error("Could not parse value flag value " + e + " for flag " + t + ".");
            }(r, o);
          });
        }
      }, t;
    }();

    exports.Environment = o;

    function a() {
      return i;
    }

    var i = null;
    exports.ENV = i;
    var u = new Map();

    function s(t, e) {
      var n = f(t, e);
      return u.get(n);
    }

    function c(t) {
      for (var e = u.entries(), n = []; ;) {
        var r = e.next(),
          o = r.done,
          a = r.value;
        if (o) break;
        var i = a[0],
          s = a[1];
        i.split("_")[0] === t && n.push(s);
      }

      return n;
    }

    function l(t) {
      var e = t.kernelName,
        n = t.backendName,
        r = f(e, n);
      if (u.has(r)) throw new Error("The kernel '" + e + "' for backend '" + n + "' is already registered");
      u.set(r, t);
    }

    function h(t, e) {
      var n = f(t, e);
      if (!u.has(n)) throw new Error("The kernel '" + t + "' for backend '" + e + "' is not registered");
      u.delete(n);
    }

    function f(t, e) {
      return e + "_" + t;
    }

    function p(t) {
      for (var e = t.length, n = 0, r = 0; e > 0;) r = Math.random() * e | 0, n = t[--e], t[e] = t[r], t[r] = n;
    }

    function d(t, e, n) {
      return Math.max(t, Math.min(e, n));
    }

    function v(t) {
      return t % 2 == 0 ? t : t + 1;
    }

    function m(t) {
      for (var e = 0, n = 0; n < t.length; n++) e += t[n];

      return e;
    }

    function g(t, e) {
      if (!t) throw new Error("string" == typeof e ? e : e());
    }

    function y(t, e, n) {
      void 0 === n && (n = ""), g(C(t, e), function () {
        return n + " Shapes " + t + " and " + e + " must match";
      });
    }

    function x(t) {
      g(null != t, function () {
        return "The input to the tensor constructor must be a non-null value.";
      });
    }

    function b(t, e, n) {
      if (void 0 === e && (e = []), void 0 === n && (n = !1), null == e && (e = []), Array.isArray(t) || B(t) && !n) for (var r = 0; r < t.length; ++r) b(t[r], e, n); else e.push(t);
      return e;
    }

    function w(t) {
      if (0 === t.length) return 1;

      for (var e = t[0], n = 1; n < t.length; n++) e *= t[n];

      return e;
    }

    function C(t, e) {
      if (t === e) return !0;
      if (null == t || null == e) return !1;
      if (t.length !== e.length) return !1;

      for (var n = 0; n < t.length; n++) if (t[n] !== e[n]) return !1;

      return !0;
    }

    function E(t) {
      return t % 1 == 0;
    }

    function R(t) {
      if (null != Math.tanh) return Math.tanh(t);
      if (t === 1 / 0) return 1;
      if (t === -1 / 0) return -1;
      var e = Math.exp(2 * t);
      return (e - 1) / (e + 1);
    }

    function I(t) {
      var e = Math.ceil(Math.sqrt(t));
      return [e, Math.ceil(t / e)];
    }

    function k(t, e) {
      return e <= t.length ? t : t + " ".repeat(e - t.length);
    }

    function S(t, e, n) {
      return void 0 === e && (e = function (t) {
        return 0;
      }), new Promise(function (r, o) {
        var a = 0,
          i = function () {
            if (t()) r(); else {
              var u = e(++a);
              null != n && a >= n ? o() : setTimeout(i, u);
            }
          };

        i();
      });
    }

    function A(t, e) {
      for (var n = 1, r = -1, o = 0; o < t.length; ++o) if (t[o] >= 0) n *= t[o]; else if (-1 === t[o]) {
        if (-1 !== r) throw Error("Shapes can only have 1 implicit size. Found -1 at dim " + r + " and dim " + o);
        r = o;
      } else if (t[o] < 0) throw Error("Shapes can not be < 0. Found " + t[o] + " at dim " + o);

      if (-1 === r) {
        if (e > 0 && e !== n) throw Error("Size(" + e + ") must match the product of shape " + t);
        return t;
      }

      if (0 === n) throw Error("Cannot infer the missing size in [" + t + "] when there are 0 elements");
      if (e % n != 0) throw Error("The implicit shape can't be a fractional number. Got " + e + " / " + n);
      var a = t.slice();
      return a[r] = e / n, a;
    }

    function D(t, e) {
      var n = e.length;
      return g((t = null == t ? e.map(function (t, e) {
        return e;
      }) : [].concat(t)).every(function (t) {
        return t >= -n && t < n;
      }), function () {
        return "All values in axis param must be in range [-" + n + ", " + n + ") but got axis " + t;
      }), g(t.every(function (t) {
        return E(t);
      }), function () {
        return "All values in axis param must be integers but got axis " + t;
      }), t.map(function (t) {
        return t < 0 ? n + t : t;
      });
    }

    function T(t, e) {
      for (var n = [], r = [], o = null != e && Array.isArray(e) && 0 === e.length, a = null == e || o ? null : D(e, t).sort(), i = 0, u = 0; u < t.length; ++u) {
        if (null != a) {
          if (a[i] === u && 1 !== t[u]) throw new Error("Can't squeeze axis " + u + " since its dim '" + t[u] + "' is not 1");
          (null == a[i] || a[i] > u) && 1 === t[u] && (n.push(t[u]), r.push(u)), a[i] <= u && i++;
        }

        1 !== t[u] && (n.push(t[u]), r.push(u));
      }

      return {
        newShape: n,
        keptDims: r
      };
    }

    function N(t, e) {
      var n = null;
      if (null == t || "float32" === t) n = new Float32Array(e); else if ("int32" === t) n = new Int32Array(e); else {
        if ("bool" !== t) throw new Error("Unknown data type " + t);
        n = new Uint8Array(e);
      }
      return n;
    }

    function F(t, e) {
      var n = null;
      if (null == t || "float32" === t) n = new Float32Array(e); else if ("int32" === t) n = new Int32Array(e); else if ("bool" === t) n = new Uint8Array(e); else {
        if ("string" !== t) throw new Error("Unknown data type " + t);
        n = new Array(e);
      }
      return n;
    }

    function O(t, e) {
      for (var n = 0; n < t.length; n++) {
        var r = t[n];
        if (isNaN(r) || !isFinite(r)) throw Error("A tensor of type " + e + " being uploaded contains " + r + ".");
      }
    }

    function _(t) {
      return "bool" === t || "complex64" === t || "float32" === t || "int32" === t || "string" === t;
    }

    function M(t, e) {
      return "complex64" !== e && ("float32" !== e || "complex64" === t) && ("int32" !== e || "float32" === t || "complex64" === t) && ("bool" !== e || "bool" !== t);
    }

    function B(t) {
      return t instanceof Float32Array || t instanceof Int32Array || t instanceof Uint8Array;
    }

    function P(t) {
      if ("float32" === t || "int32" === t) return 4;
      if ("complex64" === t) return 8;
      if ("bool" === t) return 1;
      throw new Error("Unknown dtype " + t);
    }

    function L(t) {
      if (null == t) return 0;
      var e = 0;
      return t.forEach(function (t) {
        return e += t.length;
      }), e;
    }

    function W(t) {
      return "string" == typeof t || t instanceof String;
    }

    function U(t) {
      return "boolean" == typeof t;
    }

    function V(t) {
      return "number" == typeof t;
    }

    function z(t) {
      return Array.isArray(t) ? z(t[0]) : t instanceof Float32Array ? "float32" : t instanceof Int32Array || t instanceof Uint8Array ? "int32" : V(t) ? "float32" : W(t) ? "string" : U(t) ? "bool" : "float32";
    }

    function G(t) {
      return !!(t && t.constructor && t.call && t.apply);
    }

    function H(t, e) {
      for (var n = e; n < t; ++n) if (t % n == 0) return n;

      return t;
    }

    function q(t) {
      var e = t.length;
      if (e < 2) return [];
      var n = new Array(e - 1);
      n[e - 2] = t[e - 1];

      for (var r = e - 3; r >= 0; --r) n[r] = n[r + 1] * t[r + 1];

      return n;
    }

    function K(t, e, n) {
      if ("string" === e) throw new Error("Cannot convert a string[] to a TypedArray");
      if (Array.isArray(t) && (t = b(t)), n && O(t, e), function (t, e) {
        return t instanceof Float32Array && "float32" === e || t instanceof Int32Array && "int32" === e || t instanceof Uint8Array && "bool" === e;
      }(t, e)) return t;
      if (null == e || "float32" === e || "complex64" === e) return new Float32Array(t);
      if ("int32" === e) return new Int32Array(t);

      if ("bool" === e) {
        for (var r = new Uint8Array(t.length), o = 0; o < r.length; ++o) 0 !== Math.round(t[o]) && (r[o] = 1);

        return r;
      }

      throw new Error("Unknown data type " + e);
    }

    function j(t, e) {
      if (0 === t.length) return e[0];
      var n = t.reduce(function (t, e) {
        return t * e;
      });
      if (0 === n) return [];
      if (n !== e.length) throw new Error("[" + t + "] does not match the input size.");
      return function t(e, n, r) {
        var o = new Array();
        if (1 === n.length) for (var a = n[0], i = 0; i < a; i++) o[i] = r[e + i]; else {
          a = n[0];
          var u = n.slice(1),
            s = u.reduce(function (t, e) {
              return t * e;
            });

          for (i = 0; i < a; i++) o[i] = t(e + i * s, u, r);
        }
        return o;
      }(0, t, e);
    }

    function X(t, e) {
      for (var n = $(t, e), r = 0; r < n.length; r++) n[r] = 1;

      return n;
    }

    function $(t, e) {
      if (null == e || "float32" === e || "complex64" === e) return new Float32Array(t);
      if ("int32" === e) return new Int32Array(t);
      if ("bool" === e) return new Uint8Array(t);
      throw new Error("Unknown data type " + e);
    }

    function Y() {
      return a().platform.now();
    }

    function Q(t) {
      t.forEach(function (e) {
        g(Number.isInteger(e) && e >= 0, function () {
          return "Tensor must have a shape comprised of positive integers but got shape [" + t + "].";
        });
      });
    }

    function J(t, e) {
      return void 0 === e && (e = "utf-8"), e = e || "utf-8", a().platform.encode(t, e);
    }

    function Z(t, e) {
      return void 0 === e && (e = "utf-8"), e = e || "utf-8", a().platform.decode(t, e);
    }

    var tt = Object.freeze({
      shuffle: p,
      clamp: d,
      nearestLargerEven: v,
      sum: m,
      randUniform: function (t, e) {
        var n = Math.random();
        return e * n + (1 - n) * t;
      },
      distSquared: function (t, e) {
        for (var n = 0, r = 0; r < t.length; r++) {
          var o = Number(t[r]) - Number(e[r]);
          n += o * o;
        }

        return n;
      },
      assert: g,
      assertShapesMatch: y,
      assertNonNull: x,
      flatten: b,
      sizeFromShape: w,
      isScalarShape: function (t) {
        return 0 === t.length;
      },
      arraysEqual: C,
      isInt: E,
      tanh: R,
      sizeToSquarishShape: I,
      createShuffledIndices: function (t) {
        for (var e = new Uint32Array(t), n = 0; n < t; ++n) e[n] = n;

        return p(e), e;
      },
      rightPad: k,
      repeatedTry: S,
      inferFromImplicitShape: A,
      parseAxisParam: D,
      squeezeShape: T,
      getTypedArrayFromDType: N,
      getArrayFromDType: F,
      checkConversionForErrors: O,
      isValidDtype: _,
      hasEncodingLoss: M,
      isTypedArray: B,
      bytesPerElement: P,
      bytesFromStringArray: L,
      isString: W,
      isBoolean: U,
      isNumber: V,
      inferDtype: z,
      isFunction: G,
      nearestDivisor: H,
      computeStrides: q,
      toTypedArray: K,
      toNestedArray: j,
      makeOnesTypedArray: X,
      makeZerosTypedArray: $,
      now: Y,
      assertNonNegativeIntegerDimensions: Q,
      fetch: function (t, e) {
        return a().platform.fetch(t, e);
      },
      encodeString: J,
      decodeString: Z
    }),
      et = function () {
        function t(t, e) {
          this.backendTimer = t, this.logger = e, null == e && (this.logger = new nt());
        }

        return t.prototype.profileKernel = function (t, e, n) {
          var r,
            o = this,
            a = this.backendTimer.time(function () {
              r = n();
            });
          return r.forEach(function (n) {
            n.data().then(function (r) {
              !function (t, e, n) {
                if ("float32" !== e) return !1;

                for (var r = 0; r < t.length; r++) {
                  var o = t[r];
                  if (isNaN(o) || !isFinite(o)) return console.warn("Found " + o + " in the result of '" + n + "'"), !0;
                }
              }(r, n.dtype, t), a.then(function (a) {
                var i = "";
                null != a.getExtraProfileInfo && (i = a.getExtraProfileInfo()), o.logger.logKernelProfile(t, n, r, a.kernelMs, e, i);
              });
            });
          }), r;
        }, t;
      }();

    exports.util = tt;

    var nt = function () {
      function t() { }

      return t.prototype.logKernelProfile = function (t, e, n, r, o, a) {
        var i = k(r + "ms", 9),
          u = k(t, 25),
          s = e.rank,
          c = e.size,
          l = k(e.shape.toString(), 14),
          h = "";

        for (var f in o) {
          var p = o[f].shape,
            d = p.length;
          h += f + ": " + d + "D " + (d > 0 ? p : "") + " ";
        }

        console.log("%c" + u + "\t%c" + i + "\t%c" + s + "D " + l + "\t%c" + c + "\t%c" + h + "\t%c" + a, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
      }, t;
    }();

    var rt = 20,
      ot = 3,
      at = 7;

    function it(t, e, n, r) {
      var o = q(e),
        a = function (t, e, n, r) {
          var o = w(e),
            a = r[r.length - 1],
            i = new Array(a).fill(0),
            u = e.length,
            s = "complex64" === n ? ct(t) : t;
          if (u > 1) for (var c = 0; c < o / a; c++) for (var l = c * a, h = 0; h < a; h++) i[h] = Math.max(i[h], ut(s[l + h], 0, n).length);
          return i;
        }(t, e, n, o),
        i = e.length,
        u = function t(e, n, r, o, a, i) {
          void 0 === i && (i = !0);
          var u = "complex64" === r ? 2 : 1;
          var s = n[0];
          var c = n.length;

          if (0 === c) {
            if ("complex64" === r) {
              var l = ct(e);
              return [ut(l[0], 0, r)];
            }

            return "bool" === r ? [st(e[0])] : [e[0].toString()];
          }

          if (1 === c) {
            if (s > rt) {
              var h = ot * u,
                f = Array.from(e.slice(0, h)),
                p = Array.from(e.slice(s - ot * u, s));
              return "complex64" === r && (f = ct(f), p = ct(p)), ["[" + f.map(function (t, e) {
                return ut(t, a[e], r);
              }).join(", ") + ", ..., " + p.map(function (t, e) {
                return ut(t, a[s - ot + e], r);
              }).join(", ") + "]"];
            }

            var d = "complex64" === r ? ct(e) : Array.from(e);
            return ["[" + d.map(function (t, e) {
              return ut(t, a[e], r);
            }).join(", ") + "]"];
          }

          var v = n.slice(1);
          var m = o.slice(1);
          var g = o[0] * u;
          var y = [];

          if (s > rt) {
            for (var x = 0; x < ot; x++) {
              var b = x * g,
                w = b + g;
              y.push.apply(y, t(e.slice(b, w), v, r, m, a, !1));
            }

            y.push("...");

            for (var x = s - ot; x < s; x++) {
              var b = x * g,
                w = b + g;
              y.push.apply(y, t(e.slice(b, w), v, r, m, a, x === s - 1));
            }
          } else for (var x = 0; x < s; x++) {
            var b = x * g,
              w = b + g;
            y.push.apply(y, t(e.slice(b, w), v, r, m, a, x === s - 1));
          }

          var C = 2 === c ? "," : "";
          y[0] = "[" + y[0] + C;

          for (var x = 1; x < y.length - 1; x++) y[x] = " " + y[x] + C;

          var E = ",\n";

          for (var x = 2; x < c; x++) E += "\n";

          y[y.length - 1] = " " + y[y.length - 1] + "]" + (i ? "" : E);
          return y;
        }(t, e, n, o, a),
        s = ["Tensor"];

      return r && (s.push("  dtype: " + n), s.push("  rank: " + i), s.push("  shape: [" + e + "]"), s.push("  values:")), s.push(u.map(function (t) {
        return "    " + t;
      }).join("\n")), s.join("\n");
    }

    function ut(t, e, n) {
      return k(Array.isArray(t) ? parseFloat(t[0].toFixed(at)) + " + " + parseFloat(t[1].toFixed(at)) + "j" : W(t) ? "'" + t + "'" : "bool" === n ? st(t) : parseFloat(t.toFixed(at)).toString(), e);
    }

    function st(t) {
      return 0 === t ? "false" : "true";
    }

    function ct(t) {
      for (var e = [], n = 0; n < t.length; n += 2) e.push([t[n], t[n + 1]]);

      return e;
    }

    var lt = function () {
      function t(t, e, n) {
        var r = this;

        if (this.dtype = e, this.shape = t.slice(), this.size = w(t), null != n) {
          var o = n.length;
          g(o === this.size, function () {
            return "Length of values '" + o + "' does not match the size inferred by the shape '" + r.size + "'.";
          });
        }

        if ("complex64" === e) throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
        this.values = n || F(e, this.size), this.strides = q(t);
      }

      return t.prototype.set = function (t) {
        for (var e = this, n = [], r = 1; r < arguments.length; r++) n[r - 1] = arguments[r];

        0 === n.length && (n = [0]), g(n.length === this.rank, function () {
          return "The number of provided coordinates (" + n.length + ") must match the rank (" + e.rank + ")";
        });
        var o = this.locToIndex(n);
        this.values[o] = t;
      }, t.prototype.get = function () {
        for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];

        0 === t.length && (t = [0]);

        for (var n = 0, r = 0, o = t; r < o.length; r++) {
          var a = o[r];

          if (a < 0 || a >= this.shape[n]) {
            var i = "Requested out of range element at " + t + ".   Buffer shape=" + this.shape;
            throw new Error(i);
          }

          n++;
        }

        for (var u = t[t.length - 1], s = 0; s < t.length - 1; ++s) u += this.strides[s] * t[s];

        return this.values[u];
      }, t.prototype.locToIndex = function (t) {
        if (0 === this.rank) return 0;
        if (1 === this.rank) return t[0];

        for (var e = t[t.length - 1], n = 0; n < t.length - 1; ++n) e += this.strides[n] * t[n];

        return e;
      }, t.prototype.indexToLoc = function (t) {
        if (0 === this.rank) return [];
        if (1 === this.rank) return [t];

        for (var e = new Array(this.shape.length), n = 0; n < e.length - 1; ++n) e[n] = Math.floor(t / this.strides[n]), t -= e[n] * this.strides[n];

        return e[e.length - 1] = t, e;
      }, Object.defineProperty(t.prototype, "rank", {
        get: function () {
          return this.shape.length;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.toTensor = function () {
        return ht().makeTensor(this.values, this.shape, this.dtype);
      }, t;
    }(),
      ht = null,
      ft = null,
      pt = null;

    exports.TensorBuffer = lt;

    var dt = function () {
      function t(t, e, n, r) {
        this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = e || "float32", this.size = w(t), this.strides = q(t), this.dataId = n, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
      }

      return t.prototype.flatten = function () {
        return this.throwIfDisposed(), this.as1D();
      }, t.prototype.asScalar = function () {
        return this.throwIfDisposed(), g(1 === this.size, function () {
          return "The array must have only 1 element.";
        }), this.reshape([]);
      }, t.prototype.as1D = function () {
        return this.throwIfDisposed(), this.reshape([this.size]);
      }, t.prototype.as2D = function (t, e) {
        return this.throwIfDisposed(), this.reshape([t, e]);
      }, t.prototype.as3D = function (t, e, n) {
        return this.throwIfDisposed(), this.reshape([t, e, n]);
      }, t.prototype.as4D = function (t, e, n, r) {
        return this.throwIfDisposed(), this.reshape([t, e, n, r]);
      }, t.prototype.as5D = function (t, e, n, r, o) {
        return this.throwIfDisposed(), this.reshape([t, e, n, r, o]);
      }, t.prototype.asType = function (t) {
        return this.throwIfDisposed(), ft.cast(this, t);
      }, Object.defineProperty(t.prototype, "rank", {
        get: function () {
          return this.shape.length;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.buffer = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, this.data()];

              case 1:
                return t = e.sent(), [2, ft.buffer(this.shape, this.dtype, t)];
            }
          });
        });
      }, t.prototype.bufferSync = function () {
        return ft.buffer(this.shape, this.dtype, this.dataSync());
      }, t.prototype.array = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, this.data()];

              case 1:
                return t = e.sent(), [2, j(this.shape, t)];
            }
          });
        });
      }, t.prototype.arraySync = function () {
        return j(this.shape, this.dataSync());
      }, t.prototype.data = function () {
        return n(this, void 0, void 0, function () {
          var t, e;
          return r(this, function (n) {
            switch (n.label) {
              case 0:
                return this.throwIfDisposed(), t = ht().read(this.dataId), "string" !== this.dtype ? [3, 2] : [4, t];

              case 1:
                e = n.sent();

                try {
                  return [2, e.map(function (t) {
                    return Z(t);
                  })];
                } catch (t) {
                  throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
                }

                n.label = 2;

              case 2:
                return [2, t];
            }
          });
        });
      }, t.prototype.dataSync = function () {
        this.throwIfDisposed();
        var t = ht().readSync(this.dataId);
        if ("string" === this.dtype) try {
          return t.map(function (t) {
            return Z(t);
          });
        } catch (t) {
          throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
        }
        return t;
      }, t.prototype.bytes = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return this.throwIfDisposed(), [4, ht().read(this.dataId)];

              case 1:
                return t = e.sent(), "string" === this.dtype ? [2, t] : [2, new Uint8Array(t.buffer)];
            }
          });
        });
      }, t.prototype.dispose = function () {
        this.isDisposed || (ht().disposeTensor(this), this.isDisposedInternal = !0);
      }, Object.defineProperty(t.prototype, "isDisposed", {
        get: function () {
          return this.isDisposedInternal;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.throwIfDisposed = function () {
        if (this.isDisposed) throw new Error("Tensor is disposed.");
      }, t.prototype.toFloat = function () {
        return this.asType("float32");
      }, t.prototype.toInt = function () {
        return this.asType("int32");
      }, t.prototype.toBool = function () {
        return this.asType("bool");
      }, t.prototype.print = function (t) {
        return void 0 === t && (t = !1), ft.print(this, t);
      }, t.prototype.reshape = function (t) {
        return this.throwIfDisposed(), ft.reshape(this, t);
      }, t.prototype.reshapeAs = function (t) {
        return this.throwIfDisposed(), this.reshape(t.shape);
      }, t.prototype.expandDims = function (t) {
        return void 0 === t && (t = 0), ft.expandDims(this, t);
      }, t.prototype.cumsum = function (t, e, n) {
        return void 0 === t && (t = 0), void 0 === e && (e = !1), void 0 === n && (n = !1), ft.cumsum(this, t, e, n);
      }, t.prototype.squeeze = function (t) {
        return this.throwIfDisposed(), ft.squeeze(this, t);
      }, t.prototype.clone = function () {
        return this.throwIfDisposed(), ft.clone(this);
      }, t.prototype.oneHot = function (t, e, n) {
        return this.throwIfDisposed(), ft.oneHot(this, t, e, n);
      }, t.prototype.toString = function (t) {
        return void 0 === t && (t = !1), it(this.dataSync(), this.shape, this.dtype, t);
      }, t.prototype.tile = function (t) {
        return this.throwIfDisposed(), ft.tile(this, t);
      }, t.prototype.gather = function (t, e) {
        return void 0 === e && (e = 0), this.throwIfDisposed(), ft.gather(this, t, e);
      }, t.prototype.matMul = function (t, e, n) {
        return void 0 === e && (e = !1), void 0 === n && (n = !1), this.throwIfDisposed(), ft.matMul(this, t, e, n);
      }, t.prototype.dot = function (t) {
        return this.throwIfDisposed(), ft.dot(this, t);
      }, t.prototype.norm = function (t, e, n) {
        return void 0 === t && (t = "euclidean"), void 0 === e && (e = null), void 0 === n && (n = !1), this.throwIfDisposed(), ft.norm(this, t, e, n);
      }, t.prototype.slice = function (t, e) {
        return this.throwIfDisposed(), ft.slice(this, t, e);
      }, t.prototype.reverse = function (t) {
        return this.throwIfDisposed(), ft.reverse(this, t);
      }, t.prototype.concat = function (e, n) {
        return void 0 === n && (n = 0), this.throwIfDisposed(), e instanceof t && (e = [e]), ft.concat([this].concat(e), n);
      }, t.prototype.split = function (t, e) {
        return void 0 === e && (e = 0), this.throwIfDisposed(), ft.split(this, t, e);
      }, t.prototype.stack = function (t, e) {
        return void 0 === e && (e = 0), ft.stack([this, t], e);
      }, t.prototype.unstack = function (t) {
        return void 0 === t && (t = 0), ft.unstack(this, t);
      }, t.prototype.pad = function (t, e) {
        return void 0 === e && (e = 0), ft.pad(this, t, e);
      }, t.prototype.batchNormalization = function (t, e, n, r, o) {
        return void 0 === n && (n = .001), pt("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"), this.batchNorm(t, e, o, r, n);
      }, t.prototype.batchNorm = function (t, e, n, r, o) {
        return void 0 === o && (o = .001), this.throwIfDisposed(), ft.batchNorm(this, t, e, n, r, o);
      }, t.prototype.all = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.all(this, t, e);
      }, t.prototype.any = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.any(this, t, e);
      }, t.prototype.logSumExp = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.logSumExp(this, t, e);
      }, t.prototype.sum = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.sum(this, t, e);
      }, t.prototype.prod = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.prod(this, t, e);
      }, t.prototype.mean = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.mean(this, t, e);
      }, t.prototype.min = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.min(this, t, e);
      }, t.prototype.max = function (t, e) {
        return void 0 === t && (t = null), void 0 === e && (e = !1), this.throwIfDisposed(), ft.max(this, t, e);
      }, t.prototype.argMin = function (t) {
        return void 0 === t && (t = null), this.throwIfDisposed(), ft.argMin(this, t);
      }, t.prototype.argMax = function (t) {
        return void 0 === t && (t = null), this.throwIfDisposed(), ft.argMax(this, t);
      }, t.prototype.cast = function (t) {
        return this.throwIfDisposed(), ft.cast(this, t);
      }, t.prototype.add = function (t) {
        return this.throwIfDisposed(), ft.add(this, t);
      }, t.prototype.addStrict = function (t) {
        return this.throwIfDisposed(), ft.addStrict(this, t);
      }, t.prototype.atan2 = function (t) {
        return this.throwIfDisposed(), ft.atan2(this, t);
      }, t.prototype.sub = function (t) {
        return this.throwIfDisposed(), ft.sub(this, t);
      }, t.prototype.subStrict = function (t) {
        return this.throwIfDisposed(), ft.subStrict(this, t);
      }, t.prototype.pow = function (t) {
        return this.throwIfDisposed(), ft.pow(this, t);
      }, t.prototype.powStrict = function (t) {
        return this.throwIfDisposed(), ft.powStrict(this, t);
      }, t.prototype.mul = function (t) {
        return this.throwIfDisposed(), ft.mul(this, t);
      }, t.prototype.mulStrict = function (t) {
        return this.throwIfDisposed(), ft.mulStrict(this, t);
      }, t.prototype.div = function (t) {
        return this.throwIfDisposed(), ft.div(this, t);
      }, t.prototype.floorDiv = function (t) {
        return this.throwIfDisposed(), ft.floorDiv(this, t);
      }, t.prototype.divStrict = function (t) {
        return this.throwIfDisposed(), ft.divStrict(this, t);
      }, t.prototype.minimum = function (t) {
        return this.throwIfDisposed(), ft.minimum(this, t);
      }, t.prototype.minimumStrict = function (t) {
        return this.throwIfDisposed(), ft.minimumStrict(this, t);
      }, t.prototype.maximum = function (t) {
        return this.throwIfDisposed(), ft.maximum(this, t);
      }, t.prototype.maximumStrict = function (t) {
        return this.throwIfDisposed(), ft.maximumStrict(this, t);
      }, t.prototype.mod = function (t) {
        return this.throwIfDisposed(), ft.mod(this, t);
      }, t.prototype.modStrict = function (t) {
        return this.throwIfDisposed(), ft.modStrict(this, t);
      }, t.prototype.squaredDifference = function (t) {
        return this.throwIfDisposed(), ft.squaredDifference(this, t);
      }, t.prototype.squaredDifferenceStrict = function (t) {
        return this.throwIfDisposed(), ft.squaredDifferenceStrict(this, t);
      }, t.prototype.transpose = function (t) {
        return this.throwIfDisposed(), ft.transpose(this, t);
      }, t.prototype.notEqual = function (t) {
        return this.throwIfDisposed(), ft.notEqual(this, t);
      }, t.prototype.notEqualStrict = function (t) {
        return this.throwIfDisposed(), ft.notEqualStrict(this, t);
      }, t.prototype.less = function (t) {
        return this.throwIfDisposed(), ft.less(this, t);
      }, t.prototype.lessStrict = function (t) {
        return this.throwIfDisposed(), ft.lessStrict(this, t);
      }, t.prototype.equal = function (t) {
        return this.throwIfDisposed(), ft.equal(this, t);
      }, t.prototype.equalStrict = function (t) {
        return this.throwIfDisposed(), ft.equalStrict(this, t);
      }, t.prototype.lessEqual = function (t) {
        return this.throwIfDisposed(), ft.lessEqual(this, t);
      }, t.prototype.lessEqualStrict = function (t) {
        return this.throwIfDisposed(), ft.lessEqualStrict(this, t);
      }, t.prototype.greater = function (t) {
        return this.throwIfDisposed(), ft.greater(this, t);
      }, t.prototype.greaterStrict = function (t) {
        return this.throwIfDisposed(), ft.greaterStrict(this, t);
      }, t.prototype.greaterEqual = function (t) {
        return this.throwIfDisposed(), ft.greaterEqual(this, t);
      }, t.prototype.greaterEqualStrict = function (t) {
        return this.throwIfDisposed(), ft.greaterEqualStrict(this, t);
      }, t.prototype.logicalAnd = function (t) {
        return this.throwIfDisposed(), ft.logicalAnd(this, t);
      }, t.prototype.logicalOr = function (t) {
        return this.throwIfDisposed(), ft.logicalOr(this, t);
      }, t.prototype.logicalNot = function () {
        return this.throwIfDisposed(), ft.logicalNot(this);
      }, t.prototype.logicalXor = function (t) {
        return this.throwIfDisposed(), ft.logicalXor(this, t);
      }, t.prototype.where = function (t, e) {
        return this.throwIfDisposed(), ft.where(t, this, e);
      }, t.prototype.neg = function () {
        return this.throwIfDisposed(), ft.neg(this);
      }, t.prototype.ceil = function () {
        return this.throwIfDisposed(), ft.ceil(this);
      }, t.prototype.floor = function () {
        return this.throwIfDisposed(), ft.floor(this);
      }, t.prototype.sign = function () {
        return this.throwIfDisposed(), ft.sign(this);
      }, t.prototype.isNaN = function () {
        return this.throwIfDisposed(), ft.isNaN(this);
      }, t.prototype.isInf = function () {
        return this.throwIfDisposed(), ft.isInf(this);
      }, t.prototype.isFinite = function () {
        return this.throwIfDisposed(), ft.isFinite(this);
      }, t.prototype.exp = function () {
        return this.throwIfDisposed(), ft.exp(this);
      }, t.prototype.expm1 = function () {
        return this.throwIfDisposed(), ft.expm1(this);
      }, t.prototype.log = function () {
        return this.throwIfDisposed(), ft.log(this);
      }, t.prototype.log1p = function () {
        return this.throwIfDisposed(), ft.log1p(this);
      }, t.prototype.sqrt = function () {
        return this.throwIfDisposed(), ft.sqrt(this);
      }, t.prototype.rsqrt = function () {
        return this.throwIfDisposed(), ft.rsqrt(this);
      }, t.prototype.square = function () {
        return this.throwIfDisposed(), ft.square(this);
      }, t.prototype.reciprocal = function () {
        return this.throwIfDisposed(), ft.reciprocal(this);
      }, t.prototype.abs = function () {
        return this.throwIfDisposed(), ft.abs(this);
      }, t.prototype.clipByValue = function (t, e) {
        return this.throwIfDisposed(), ft.clipByValue(this, t, e);
      }, t.prototype.relu = function () {
        return this.throwIfDisposed(), ft.relu(this);
      }, t.prototype.relu6 = function () {
        return this.throwIfDisposed(), ft.relu6(this);
      }, t.prototype.elu = function () {
        return this.throwIfDisposed(), ft.elu(this);
      }, t.prototype.selu = function () {
        return this.throwIfDisposed(), ft.selu(this);
      }, t.prototype.leakyRelu = function (t) {
        return void 0 === t && (t = .2), this.throwIfDisposed(), ft.leakyRelu(this, t);
      }, t.prototype.prelu = function (t) {
        return this.throwIfDisposed(), ft.prelu(this, t);
      }, t.prototype.sigmoid = function () {
        return this.throwIfDisposed(), ft.sigmoid(this);
      }, t.prototype.logSigmoid = function () {
        return this.throwIfDisposed(), ft.logSigmoid(this);
      }, t.prototype.softplus = function () {
        return this.throwIfDisposed(), ft.softplus(this);
      }, t.prototype.zerosLike = function () {
        return this.throwIfDisposed(), ft.zerosLike(this);
      }, t.prototype.onesLike = function () {
        return this.throwIfDisposed(), ft.onesLike(this);
      }, t.prototype.sin = function () {
        return this.throwIfDisposed(), ft.sin(this);
      }, t.prototype.cos = function () {
        return this.throwIfDisposed(), ft.cos(this);
      }, t.prototype.tan = function () {
        return this.throwIfDisposed(), ft.tan(this);
      }, t.prototype.asin = function () {
        return this.throwIfDisposed(), ft.asin(this);
      }, t.prototype.acos = function () {
        return this.throwIfDisposed(), ft.acos(this);
      }, t.prototype.atan = function () {
        return this.throwIfDisposed(), ft.atan(this);
      }, t.prototype.sinh = function () {
        return this.throwIfDisposed(), ft.sinh(this);
      }, t.prototype.cosh = function () {
        return this.throwIfDisposed(), ft.cosh(this);
      }, t.prototype.tanh = function () {
        return this.throwIfDisposed(), ft.tanh(this);
      }, t.prototype.asinh = function () {
        return this.throwIfDisposed(), ft.asinh(this);
      }, t.prototype.acosh = function () {
        return this.throwIfDisposed(), ft.acosh(this);
      }, t.prototype.atanh = function () {
        return this.throwIfDisposed(), ft.atanh(this);
      }, t.prototype.erf = function () {
        return this.throwIfDisposed(), ft.erf(this);
      }, t.prototype.round = function () {
        return this.throwIfDisposed(), ft.round(this);
      }, t.prototype.step = function (t) {
        return void 0 === t && (t = 0), this.throwIfDisposed(), ft.step(this, t);
      }, t.prototype.softmax = function (t) {
        return void 0 === t && (t = -1), this.throwIfDisposed(), ft.softmax(this, t);
      }, t.prototype.logSoftmax = function (t) {
        return void 0 === t && (t = -1), this.throwIfDisposed(), ft.logSoftmax(this, t);
      }, t.prototype.resizeBilinear = function (t, e) {
        return void 0 === e && (e = !1), this.throwIfDisposed(), ft.image.resizeBilinear(this, t, e);
      }, t.prototype.resizeNearestNeighbor = function (t, e) {
        return void 0 === e && (e = !1), this.throwIfDisposed(), ft.image.resizeNearestNeighbor(this, t, e);
      }, t.prototype.conv1d = function (t, e, n, r, o, a) {
        return void 0 === r && (r = "NWC"), void 0 === o && (o = 1), this.throwIfDisposed(), ft.conv1d(this, t, e, n, r, o, a);
      }, t.prototype.conv2d = function (t, e, n, r, o, a) {
        return void 0 === r && (r = "NHWC"), void 0 === o && (o = [1, 1]), this.throwIfDisposed(), ft.conv2d(this, t, e, n, r, o, a);
      }, t.prototype.conv2dTranspose = function (t, e, n, r, o) {
        return this.throwIfDisposed(), ft.conv2dTranspose(this, t, e, n, r, o);
      }, t.prototype.depthwiseConv2D = function (t, e, n, r, o, a) {
        return void 0 === r && (r = "NHWC"), void 0 === o && (o = [1, 1]), this.throwIfDisposed(), ft.depthwiseConv2d(this, t, e, n, r, o, a);
      }, t.prototype.separableConv2d = function (t, e, n, r, o, a) {
        return void 0 === o && (o = [1, 1]), void 0 === a && (a = "NHWC"), this.throwIfDisposed(), ft.separableConv2d(this, t, e, n, r, o, a);
      }, t.prototype.avgPool = function (t, e, n, r) {
        return this.throwIfDisposed(), ft.avgPool(this, t, e, n, r);
      }, t.prototype.maxPool = function (t, e, n, r) {
        return this.throwIfDisposed(), ft.maxPool(this, t, e, n, r);
      }, t.prototype.localResponseNormalization = function (t, e, n, r) {
        return void 0 === t && (t = 5), void 0 === e && (e = 1), void 0 === n && (n = 1), void 0 === r && (r = .5), ft.localResponseNormalization(this, t, e, n, r);
      }, t.prototype.pool = function (t, e, n, r, o) {
        return this.throwIfDisposed(), ft.pool(this, t, e, n, r, o);
      }, t.prototype.variable = function (t, e, n) {
        return void 0 === t && (t = !0), this.throwIfDisposed(), ht().makeVariable(this, t, e, n);
      }, t.prototype.unsortedSegmentSum = function (t, e) {
        return this.throwIfDisposed(), ft.unsortedSegmentSum(this, t, e);
      }, t.prototype.batchToSpaceND = function (t, e) {
        return this.throwIfDisposed(), ft.batchToSpaceND(this, t, e);
      }, t.prototype.spaceToBatchND = function (t, e) {
        return this.throwIfDisposed(), ft.spaceToBatchND(this, t, e);
      }, t.prototype.topk = function (t, e) {
        return void 0 === t && (t = 1), void 0 === e && (e = !0), this.throwIfDisposed(), ft.topk(this, t, e);
      }, t.prototype.stridedSlice = function (t, e, n, r, o, a, i, u) {
        return void 0 === r && (r = 0), void 0 === o && (o = 0), void 0 === a && (a = 0), void 0 === i && (i = 0), void 0 === u && (u = 0), this.throwIfDisposed(), ft.stridedSlice(this, t, e, n, r, o, a, i, u);
      }, t.prototype.depthToSpace = function (t, e) {
        return this.throwIfDisposed(), ft.depthToSpace(this, t, e);
      }, t.prototype.fft = function () {
        return this.throwIfDisposed(), ft.spectral.fft(this);
      }, t.prototype.ifft = function () {
        return this.throwIfDisposed(), ft.spectral.ifft(this);
      }, t.prototype.rfft = function () {
        return this.throwIfDisposed(), ft.spectral.rfft(this);
      }, t.prototype.irfft = function () {
        return this.throwIfDisposed(), ft.spectral.irfft(this);
      }, t;
    }();

    exports.Tensor = dt;
    Object.defineProperty(dt, Symbol.hasInstance, {
      value: function (t) {
        return !!t && null != t.dataId && null != t.shape && null != t.dtype;
      }
    });

    var vt,
      mt,
      gt,
      yt,
      xt,
      bt = function (t) {
        function n(e, n, r, o) {
          var a = t.call(this, e.shape, e.dtype, e.dataId, o) || this;
          return a.trainable = n, a.name = r, a;
        }

        return e(n, t), n.prototype.assign = function (t) {
          if (t.dtype !== this.dtype) throw new Error("dtype of the new value (" + t.dtype + ") and previous value (" + this.dtype + ") must match");
          if (!C(t.shape, this.shape)) throw new Error("shape of the new value (" + t.shape + ") and previous value (" + this.shape + ") must match");
          ht().disposeTensor(this), this.dataId = t.dataId, ht().incRef(this, null);
        }, n.prototype.dispose = function () {
          ht().disposeVariable(this), this.isDisposedInternal = !0;
        }, n;
      }(dt);

    exports.Variable = bt;
    exports.Rank = vt;
    Object.defineProperty(bt, Symbol.hasInstance, {
      value: function (t) {
        return t instanceof dt && null != t.assign && t.assign instanceof Function;
      }
    }), function (t) {
      t.R0 = "R0", t.R1 = "R1", t.R2 = "R2", t.R3 = "R3", t.R4 = "R4", t.R5 = "R5", t.R6 = "R6";
    }(vt || (exports.Rank = vt = {})), function (t) {
      t.float32 = "float32", t.int32 = "int32", t.bool = "int32", t.complex64 = "complex64";
    }(mt || (mt = {})), function (t) {
      t.float32 = "float32", t.int32 = "int32", t.bool = "bool", t.complex64 = "complex64";
    }(gt || (gt = {})), function (t) {
      t.float32 = "float32", t.int32 = "float32", t.bool = "float32", t.complex64 = "complex64";
    }(yt || (yt = {})), function (t) {
      t.float32 = "complex64", t.int32 = "complex64", t.bool = "complex64", t.complex64 = "complex64";
    }(xt || (xt = {}));
    var wt = {
      float32: yt,
      int32: mt,
      bool: gt,
      complex64: xt
    };

    function Ct(t, e) {
      if ("string" === t || "string" === e) {
        if ("string" === t && "string" === e) return "string";
        throw new Error("Can not upcast " + t + " with " + e);
      }

      return wt[t][e];
    }

    function Et(t) {
      return Ct(t, "int32");
    }

    function Rt(t, e) {
      if (t.dtype === e.dtype) return [t, e];
      var n = Ct(t.dtype, e.dtype);
      return [t.cast(n), e.cast(n)];
    }

    function It(t, e) {
      g(t.dtype === e.dtype, function () {
        return "The dtypes of the first(" + t.dtype + ") and second(" + e.dtype + ") input must match";
      });
    }

    function kt(t) {
      var e = [];
      return function t(e, n, r) {
        if (null == e) return;
        if (e instanceof dt) return void n.push(e);
        if (o = e, !Array.isArray(o) && "object" != typeof o) return;
        var o;
        var a = e;

        for (var i in a) {
          var u = a[i];
          r.has(u) || (r.add(u), t(u, n, r));
        }
      }(t, e, new Set()), e;
    }

    var St,
      At = Object.freeze({
        makeTypesMatch: Rt,
        assertTypesMatch: It,
        isTensorInList: function (t, e) {
          for (var n = 0; n < e.length; n++) if (e[n].id === t.id) return !0;

          return !1;
        },
        getTensorsInContainer: kt
      }),
      Dt = function () {
        function t() {
          this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = new WeakMap(), this.profiling = !1, this.activeProfile = {
            newBytes: 0,
            newTensors: 0,
            peakBytes: 0,
            kernels: [],
            result: null
          };
        }

        return t.prototype.dispose = function () {
          for (var t in this.registeredVariables) this.registeredVariables[t].dispose();
        }, t;
      }(),
      Tt = function () {
        function t(t) {
          this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Dt();
        }

        return t.prototype.ready = function () {
          return n(this, void 0, void 0, function () {
            var t, e, n;
            return r(this, function (r) {
              switch (r.label) {
                case 0:
                  if (null != this.pendingBackendInit) return [2, this.pendingBackendInit.then(function () { })];
                  if (null != this.backendInstance) return [2];
                  t = this.getSortedBackends(), e = 0, r.label = 1;

                case 1:
                  return e < t.length ? (n = t[e], [4, this.initializeBackend(n).success]) : [3, 5];

                case 2:
                  return r.sent() ? [4, this.setBackend(n)] : [3, 4];

                case 3:
                  return r.sent(), [2];

                case 4:
                  return e++, [3, 1];

                case 5:
                  throw new Error("Could not initialize any backends, all backend initializations failed.");
              }
            });
          });
        }, Object.defineProperty(t.prototype, "backend", {
          get: function () {
            if (null != this.pendingBackendInit) throw new Error("Backend '" + this.backendName + "' has not yet been initialized. Make sure to await tf.ready() before calling other methods");

            if (null == this.backendInstance) {
              var t = this.initializeBackendsAndReturnBest(),
                e = t.name;
              if (t.asyncInit) throw new Error("The highest priority backend '" + e + "' has not yet been initialized. Make sure to await tf.ready() before calling other methods");
              this.setBackend(e);
            }

            return this.backendInstance;
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.backendNames = function () {
          return Object.keys(this.registryFactory);
        }, t.prototype.findBackend = function (t) {
          if (!(t in this.registry)) {
            if (!(t in this.registryFactory)) return null;
            if (this.initializeBackend(t).asyncInit) return null;
          }

          return this.registry[t];
        }, t.prototype.findBackendFactory = function (t) {
          return t in this.registryFactory ? this.registryFactory[t].factory : null;
        }, t.prototype.registerBackend = function (t, e, n) {
          return void 0 === n && (n = 1), t in this.registryFactory ? (console.warn(t + " backend was already registered. Reusing existing backend factory."), !1) : (this.registryFactory[t] = {
            factory: e,
            priority: n
          }, !0);
        }, t.prototype.setBackend = function (t) {
          return n(this, void 0, void 0, function () {
            var e, n, o;
            return r(this, function (r) {
              switch (r.label) {
                case 0:
                  if (null == this.registryFactory[t]) throw new Error("Backend name '" + t + "' not found in registry");
                  return this.backendName = t, null != this.registry[t] ? [3, 4] : (this.backendInstance = null, e = this.initializeBackend(t), n = e.success, e.asyncInit ? [4, n] : [3, 2]);

                case 1:
                  return o = r.sent(), [3, 3];

                case 2:
                  o = n, r.label = 3;

                case 3:
                  if (!o) return [2, !1];
                  r.label = 4;

                case 4:
                  return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new et(this.backendInstance), [2, !0];
              }
            });
          });
        }, t.prototype.setupRegisteredKernels = function () {
          var t = this;
          c(this.backendName).forEach(function (e) {
            null != e.setupFunc && e.setupFunc(t.backendInstance);
          });
        }, t.prototype.disposeRegisteredKernels = function (t) {
          var e = this;
          c(t).forEach(function (n) {
            null != n.disposeFunc && n.disposeFunc(e.registry[t]);
          });
        }, t.prototype.initializeBackend = function (t) {
          var e = this,
            n = this.registryFactory[t];
          if (null == n) throw new Error("Cannot initialize backend " + t + ", no registration found.");

          try {
            var r = n.factory();

            if (Promise.resolve(r) === r) {
              var o = ++this.pendingBackendInitId,
                a = r.then(function (n) {
                  return !(o < e.pendingBackendInitId) && (e.registry[t] = n, e.pendingBackendInit = null, !0);
                }).catch(function (n) {
                  return !(o < e.pendingBackendInitId) && (e.pendingBackendInit = null, console.warn("Initialization of backend " + t + " failed"), console.warn(n.stack || n.message), !1);
                });
              return this.pendingBackendInit = a, {
                success: a,
                asyncInit: !0
              };
            }

            return this.registry[t] = r, {
              success: !0,
              asyncInit: !1
            };
          } catch (e) {
            return console.warn("Initialization of backend " + t + " failed"), console.warn(e.stack || e.message), {
              success: !1,
              asyncInit: !1
            };
          }
        }, t.prototype.removeBackend = function (t) {
          if (!(t in this.registryFactory)) throw new Error(t + " backend not found in registry");
          this.backendName === t && null != this.pendingBackendInit && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null);
        }, t.prototype.getSortedBackends = function () {
          var t = this;
          if (0 === Object.keys(this.registryFactory).length) throw new Error("No backend found in registry.");
          return Object.keys(this.registryFactory).sort(function (e, n) {
            return t.registryFactory[n].priority - t.registryFactory[e].priority;
          });
        }, t.prototype.initializeBackendsAndReturnBest = function () {
          for (var t = this.getSortedBackends(), e = 0; e < t.length; e++) {
            var n = t[e],
              r = this.initializeBackend(n),
              o = r.success,
              a = r.asyncInit;
            if (a || o) return {
              name: n,
              asyncInit: a
            };
          }

          throw new Error("Could not initialize any backends, all backend initializations failed.");
        }, t.prototype.moveData = function (t, e) {
          var n = this.state.tensorInfo.get(e),
            r = n.backend,
            o = this.readSync(e);
          r.disposeData(e), n.backend = t, t.move(e, o, n.shape, n.dtype), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
        }, t.prototype.tidy = function (t, e) {
          var n,
            r = this,
            o = null;

          if (null == e) {
            if ("function" != typeof t) throw new Error("Please provide a function to tidy()");
            e = t;
          } else {
            if ("string" != typeof t && !(t instanceof String)) throw new Error("When calling with two arguments, the first argument to tidy() must be a string");
            if ("function" != typeof e) throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
            o = t;
          }

          return this.scopedRun(function () {
            return r.startScope(o);
          }, function () {
            return r.endScope(n);
          }, function () {
            return (n = e()) instanceof Promise && console.error("Cannot return a Promise inside of tidy."), n;
          });
        }, t.prototype.scopedRun = function (t, e, n) {
          t();

          try {
            var r = n();
            return e(), r;
          } catch (t) {
            throw e(), t;
          }
        }, t.prototype.nextTensorId = function () {
          return t.nextTensorId++;
        }, t.prototype.nextVariableId = function () {
          return t.nextVariableId++;
        }, t.prototype.clone = function (t) {
          var e = this.makeTensorFromDataId(t.dataId, t.shape, t.dtype),
            n = {
              x: t
            };
          return this.addTapeNode(this.state.activeScope.name, n, [e], function (t) {
            return {
              x: function () {
                return t.toFloat();
              }
            };
          }, []), e;
        }, t.prototype.runKernel = function (t, e, n, r, o) {
          return this.runKernelFunc(null, e, null, t, n, r, o);
        }, t.prototype.shouldCheckForMemLeaks = function () {
          return this.ENV.getBool("IS_TEST");
        }, t.prototype.checkKernelForMemLeak = function (t, e, n) {
          var r = this.backend.numDataIds(),
            o = 0;
          n.forEach(function (t) {
            o += "complex64" === t.dtype ? 3 : 1;
          });
          var a = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1],
            i = r - e - o - a;
          if (i > 0) throw new Error("Backend '" + this.backendName + "' has an internal memory leak (" + i + " data ids) after running '" + t + "'");
        }, t.prototype.runKernelFunc = function (t, e, n, r, o, a, i) {
          var u,
            c = this;
          void 0 === a && (a = []), void 0 === i && (i = []);

          var l,
            h = [],
            f = this.isTapeOn(),
            p = null != this.state.activeScope ? this.state.activeScope.name : "",
            d = function (t) {
              f && (h = t.map(function (t) {
                return c.keep(c.clone(t));
              }));
            },
            v = this.state.numBytes,
            m = this.state.numTensors;

          this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
          var g,
            y = s(r, this.backendName);
          return l = null != y ? function () {
            var t = c.backend.numDataIds();
            g = y.kernelFunc({
              inputs: e,
              attrs: o,
              backend: c.backend
            });
            var n = Array.isArray(g) ? g : [g];
            c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(p, t, n);
            var r = n.map(function (t) {
              var e = t.dataId,
                n = t.shape,
                r = t.dtype;
              return c.makeTensorFromDataId(e, n, r);
            }),
              u = r.filter(function (t, e) {
                return i[e];
              });
            return d(a.slice().concat(u)), r;
          } : function () {
            var e = c.backend.numDataIds();
            g = c.tidy(function () {
              return t(c.backend, d);
            });
            var n = Array.isArray(g) ? g : [g];
            return c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(p, e, n), n;
          }, this.scopedRun(function () {
            return c.state.kernelDepth++;
          }, function () {
            return c.state.kernelDepth--;
          }, function () {
            u = c.ENV.getBool("DEBUG") ? c.profiler.profileKernel(p, e, function () {
              return l();
            }) : l();
          }), f && this.addTapeNode(p, e, u, n, h), this.state.profiling && this.state.activeProfile.kernels.push({
            name: p,
            bytesAdded: this.state.numBytes - v,
            totalBytesSnapshot: this.state.numBytes,
            tensorsAdded: this.state.numTensors - m,
            totalTensorsSnapshot: this.state.numTensors,
            inputShapes: Object.keys(e).map(function (t) {
              return e[t].shape;
            }),
            outputShapes: u.map(function (t) {
              return t.shape;
            })
          }), Array.isArray(g) ? u : u[0];
        }, t.prototype.makeTensor = function (t, e, n, r) {
          if (null == t) throw new Error("Values passed to engine.makeTensor() are null");
          n = n || "float32", r = r || this.backend;
          var o = t;
          "string" === n && W(t[0]) && (o = t.map(function (t) {
            return J(t);
          }));
          var a = r.write(o, e, n),
            i = new dt(e, n, a, this.nextTensorId());

          if (this.incRef(i, r), "string" === n) {
            var u = this.state.tensorInfo.get(a),
              s = L(o);
            this.state.numBytes += s - u.bytes, u.bytes = s;
          }

          return i;
        }, t.prototype.makeTensorFromDataId = function (t, e, n, r) {
          var o = new dt(e, n = n || "float32", t, this.nextTensorId());
          return this.incRef(o, r), o;
        }, t.prototype.makeVariable = function (t, e, n, r) {
          void 0 === e && (e = !0), n = n || this.nextVariableId().toString(), null != r && r !== t.dtype && (t = t.asType(r));
          var o = new bt(t, e, n, this.nextTensorId());
          if (null != this.state.registeredVariables[o.name]) throw new Error("Variable with name " + o.name + " was already registered");
          return this.state.registeredVariables[o.name] = o, this.incRef(o, this.backend), o;
        }, t.prototype.incRef = function (t, e) {
          var n = this.state.tensorInfo.has(t.dataId) ? this.state.tensorInfo.get(t.dataId).refCount : 0;

          if (this.state.numTensors++, "string" === t.dtype && this.state.numStringTensors++, 0 === n) {
            this.state.numDataBuffers++;
            var r = 0;
            "complex64" !== t.dtype && "string" !== t.dtype && (r = t.size * P(t.dtype)), this.state.tensorInfo.set(t.dataId, {
              backend: e || this.backend,
              dtype: t.dtype,
              shape: t.shape,
              bytes: r,
              refCount: 0
            }), this.state.numBytes += r;
          }

          this.state.tensorInfo.get(t.dataId).refCount++, t instanceof bt || this.track(t);
        }, t.prototype.disposeTensor = function (t) {
          if (this.state.tensorInfo.has(t.dataId)) {
            this.state.numTensors--, "string" === t.dtype && this.state.numStringTensors--;
            var e = this.state.tensorInfo.get(t.dataId);
            e.refCount <= 1 ? ("complex64" !== t.dtype && (this.state.numBytes -= e.bytes), this.state.numDataBuffers--, e.backend.disposeData(t.dataId), this.state.tensorInfo.delete(t.dataId)) : this.state.tensorInfo.get(t.dataId).refCount--;
          }
        }, t.prototype.disposeVariables = function () {
          for (var t in this.state.registeredVariables) {
            var e = this.state.registeredVariables[t];
            this.disposeVariable(e);
          }
        }, t.prototype.disposeVariable = function (t) {
          this.disposeTensor(t), null != this.state.registeredVariables[t.name] && delete this.state.registeredVariables[t.name];
        }, t.prototype.memory = function () {
          var t = this.backend.memory();
          return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = !0, null == t.reasons && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t;
        }, t.prototype.profile = function (t) {
          return n(this, void 0, void 0, function () {
            var e, n;
            return r(this, function (r) {
              return this.state.profiling = !0, e = this.state.numBytes, n = this.state.numTensors, this.state.activeProfile.kernels = [], this.state.activeProfile.result = t(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max.apply(Math, this.state.activeProfile.kernels.map(function (t) {
                return t.totalBytesSnapshot;
              })), this.state.activeProfile.newBytes = this.state.numBytes - e, this.state.activeProfile.newTensors = this.state.numTensors - n, [2, this.state.activeProfile];
            });
          });
        }, t.prototype.isTapeOn = function () {
          return this.state.gradientDepth > 0 && 0 === this.state.kernelDepth;
        }, t.prototype.addTapeNode = function (t, e, n, r, o) {
          var a = this,
            i = {
              id: this.state.nextTapeNodeId++,
              name: t,
              inputs: e,
              outputs: n,
              saved: o
            };
          null != r && (i.gradient = function (t) {
            return t = t.map(function (t, e) {
              if (null == t) {
                var r = n[e],
                  o = $(r.size, r.dtype);
                return a.makeTensor(o, r.shape, r.dtype);
              }

              return t;
            }), r(t.length > 1 ? t : t[0], o);
          }), this.state.activeTape.push(i);
        }, t.prototype.keep = function (t) {
          return t.kept = !0, t;
        }, t.prototype.startTape = function () {
          0 === this.state.gradientDepth && (this.state.activeTape = []), this.state.gradientDepth++;
        }, t.prototype.endTape = function () {
          this.state.gradientDepth--;
        }, t.prototype.startScope = function (t) {
          var e = {
            track: [],
            name: "unnamed scope",
            id: this.state.nextScopeId++
          };
          t && (e.name = t), this.state.scopeStack.push(e), this.state.activeScope = e;
        }, t.prototype.endScope = function (t) {
          for (var e = this, n = kt(t), r = new Set(n.map(function (t) {
            return t.id;
          })), o = 0; o < this.state.activeScope.track.length; o++) {
            var a = this.state.activeScope.track[o];
            a.kept || r.has(a.id) || a.dispose();
          }

          var i = this.state.scopeStack.pop();
          this.state.activeScope = 0 === this.state.scopeStack.length ? null : this.state.scopeStack[this.state.scopeStack.length - 1], n.forEach(function (t) {
            t.kept || t.scopeId !== i.id || e.track(t);
          });
        }, t.prototype.gradients = function (t, e, n, r) {
          var o = this;
          if (void 0 === r && (r = !1), g(e.length > 0, function () {
            return "gradients() received an empty list of xs.";
          }), null != n && "float32" !== n.dtype) throw new Error("dy must have 'float32' dtype, but has '" + n.dtype + "'");
          var a = this.scopedRun(function () {
            return o.startTape();
          }, function () {
            return o.endTape();
          }, function () {
            return o.tidy("forward", t);
          });
          g(a instanceof dt, function () {
            return "The result y returned by f() must be a tensor.";
          });

          var i = function (t, e, n) {
            for (var r = {}, o = {}, a = 0; a < e.length; a++) r[e[a].id] = !0;

            for (a = 0; a < t.length; a++) {
              var i = (d = t[a]).inputs;

              for (var u in i) {
                for (var s = i[u], c = !1, l = 0; l < e.length; l++) if (r[s.id]) {
                  d.outputs.forEach(function (t) {
                    return r[t.id] = !0;
                  }), c = !0, o[d.id] = !0;
                  break;
                }

                if (c) break;
              }
            }

            var h = {};
            h[n.id] = !0;
            var f = {};

            for (a = t.length - 1; a >= 0; a--) for (i = (d = t[a]).inputs, l = 0; l < d.outputs.length; l++) if (h[d.outputs[l].id]) {
              for (var u in i) h[i[u].id] = !0, f[d.id] = !0;

              break;
            }

            var p = [];

            for (a = 0; a < t.length; a++) {
              var d;

              if (o[(d = t[a]).id] && f[d.id]) {
                var v = {};

                for (var u in d.inputs) {
                  var m = d.inputs[u];
                  r[m.id] && (v[u] = m);
                }

                var g = Object.assign({}, d);
                g.inputs = v, g.outputs = d.outputs, p.push(g);
              }
            }

            return p;
          }(this.state.activeTape, e, a);

          if (!r && 0 === i.length && e.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.");
          return this.tidy("backward", function () {
            var t,
              r,
              u = {};
            u[a.id] = null == n ? (t = a.shape, r = X(w(t), "float32"), Nt.makeTensor(r, t, "float32")) : n, function (t, e, n) {
              for (var r = function (r) {
                var o = e[r],
                  a = [];
                if (o.outputs.forEach(function (e) {
                  var n = t[e.id];
                  null != n ? a.push(n) : a.push(null);
                }), null == o.gradient) throw new Error("Cannot compute gradient: gradient function not found for " + o.name + ".");

                var i = o.gradient(a),
                  u = function (e) {
                    if (!(e in i)) throw new Error("Cannot backprop through input " + e + ". Available gradients found: " + Object.keys(i) + ".");
                    var r = n(function () {
                      return i[e]();
                    });
                    if ("float32" !== r.dtype) throw new Error("Error in gradient for op " + o.name + ". The gradient of input " + e + " must have 'float32' dtype, but has '" + r.dtype + "'");
                    var a = o.inputs[e];
                    if (!C(r.shape, a.shape)) throw new Error("Error in gradient for op " + o.name + ". The gradient of input '" + e + "' has shape '" + r.shape + "', which does not match the shape of the input '" + a.shape + "'");
                    if (null == t[a.id]) t[a.id] = r; else {
                      var u = t[a.id];
                      t[a.id] = u.add(r), u.dispose();
                    }
                  };

                for (var s in o.inputs) u(s);
              }, o = e.length - 1; o >= 0; o--) r(o);
            }(u, i, function (t) {
              return o.tidy(t);
            });
            var s = e.map(function (t) {
              return u[t.id];
            });
            return 0 === o.state.gradientDepth && (o.state.activeTape.forEach(function (t) {
              for (var e in t.saved) t.saved[e].dispose();
            }), o.state.activeTape = null), {
              value: a,
              grads: s
            };
          });
        }, t.prototype.customGrad = function (t) {
          var e = this;
          return g(G(t), function () {
            return "The f passed in customGrad(f) must be a function.";
          }), function () {
            for (var n, r = [], o = 0; o < arguments.length; o++) r[o] = arguments[o];

            g(r.every(function (t) {
              return t instanceof dt;
            }), function () {
              return "The args passed in customGrad(f)(x1, x2,...) must all be tensors";
            });
            var a = {};
            return r.forEach(function (t, e) {
              a[e] = t;
            }), e.runKernelFunc(function (e, o) {
              return g((n = t.apply(void 0, r.concat([o]))).value instanceof dt, function () {
                return "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor";
              }), g(G(n.gradFunc), function () {
                return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function.";
              }), n.value;
            }, a, function (t, e) {
              var o = n.gradFunc(t, e),
                a = Array.isArray(o) ? o : [o];
              g(a.length === r.length, function () {
                return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...).";
              }), g(a.every(function (t) {
                return t instanceof dt;
              }), function () {
                return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.";
              });
              var i = {};
              return a.forEach(function (t, e) {
                i[e] = function () {
                  return t;
                };
              }), i;
            });
          };
        }, t.prototype.readSync = function (t) {
          return this.state.tensorInfo.get(t).backend.readSync(t);
        }, t.prototype.read = function (t) {
          return this.state.tensorInfo.get(t).backend.read(t);
        }, t.prototype.fromPixels = function (t, e) {
          return this.backend.fromPixels(t, e);
        }, t.prototype.time = function (t) {
          return n(this, void 0, void 0, function () {
            var e, n;
            return r(this, function (r) {
              switch (r.label) {
                case 0:
                  return e = Y(), [4, this.backend.time(t)];

                case 1:
                  return (n = r.sent()).wallMs = Y() - e, [2, n];
              }
            });
          });
        }, t.prototype.track = function (t) {
          return null != this.state.activeScope && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t;
        }, Object.defineProperty(t.prototype, "registeredVariables", {
          get: function () {
            return this.state.registeredVariables;
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.reset = function () {
          for (var t in this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new Dt(), this.registry) this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t];

          this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
        }, t.nextTensorId = 0, t.nextVariableId = 0, t;
      }();

    exports.tensor_util = At;

    var Nt = function () {
      var t = function () {
        if (null == St) {
          var t = void 0;
          if ("undefined" != typeof window) t = window; else if ("undefined" != typeof global) t = global; else if ("undefined" != typeof process) t = process; else {
            if ("undefined" == typeof self) throw new Error("Could not find a global object");
            t = self;
          }
          St = t;
        }

        return St;
      }();

      if (null == t._tfengine) {
        var e = new o(t);
        t._tfengine = new Tt(e);
      }

      return function (t) {
        exports.ENV = i = t;
      }(t._tfengine.ENV), ht = function () {
        return t._tfengine;
      }, t._tfengine;
    }();

    function Ft() {
      return "undefined" != typeof window && null != window.document || "undefined" != typeof WorkerGlobalScope;
    }

    var Ot = a();
    Ot.registerFlag("DEBUG", function () {
      return !1;
    }, function (t) {
      t && 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.");
    }), Ot.registerFlag("IS_BROWSER", function () {
      return Ft();
    }), Ot.registerFlag("IS_NODE", function () {
      return "undefined" != typeof process && void 0 !== process.versions && void 0 !== process.versions.node;
    }), Ot.registerFlag("IS_CHROME", function () {
      return "undefined" != typeof navigator && null != navigator && null != navigator.userAgent && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
    }), Ot.registerFlag("PROD", function () {
      return !1;
    }), Ot.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", function () {
      return Ot.getBool("DEBUG");
    }), Ot.registerFlag("DEPRECATION_WARNINGS_ENABLED", function () {
      return !0;
    }), Ot.registerFlag("IS_TEST", function () {
      return !1;
    });

    var _t,
      Mt,
      Bt,
      Pt = {},
      Lt = {
        alpha: !1,
        antialias: !1,
        premultipliedAlpha: !1,
        preserveDrawingBuffer: !1,
        depth: !1,
        stencil: !1,
        failIfMajorPerformanceCaveat: !0
      };

    function Wt(t, e) {
      Pt[t] = e;
    }

    function Ut(t) {
      t in Pt || (Pt[t] = function (t) {
        if (1 !== t && 2 !== t) throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
        var e = Vt(t);
        if (e.addEventListener("webglcontextlost", function (e) {
          e.preventDefault(), delete Pt[t];
        }, !1), 1 === t) return e.getContext("webgl", Lt) || e.getContext("experimental-webgl", Lt);
        return e.getContext("webgl2", Lt);
      }(t));
      var e = Pt[t];
      return e.isContextLost() ? (delete Pt[t], Ut(t)) : (e.disable(e.DEPTH_TEST), e.disable(e.STENCIL_TEST), e.disable(e.BLEND), e.disable(e.DITHER), e.disable(e.POLYGON_OFFSET_FILL), e.disable(e.SAMPLE_COVERAGE), e.enable(e.SCISSOR_TEST), e.enable(e.CULL_FACE), e.cullFace(e.BACK), Pt[t]);
    }

    function Vt(t) {
      if ("undefined" != typeof OffscreenCanvas && 2 === t) return new OffscreenCanvas(300, 150);
      if ("undefined" != typeof document) return document.createElement("canvas");
      throw new Error("Cannot create a canvas in this context");
    }

    function zt(t, e) {
      return [e, t];
    }

    function Gt(t) {
      var e = w(t);
      return I(Math.ceil(e / 4));
    }

    function Ht(t, e) {
      return [Math.max(1, Math.ceil(e / 2)), Math.max(1, Math.ceil(t / 2))];
    }

    function qt(t, e) {
      var n,
        r,
        o,
        i,
        u,
        s,
        c,
        l,
        h,
        f = t;
      return 2 === a().getNumber("WEBGL_VERSION") ? (n = f.R32F, r = f.R16F, o = f.RGBA16F, i = f.RGBA32F, u = f.RED, s = 4, c = 1, l = f.HALF_FLOAT, h = f.FLOAT) : (n = t.RGBA, r = t.RGBA, o = t.RGBA, i = f.RGBA, u = t.RGBA, s = 4, c = 4, l = null != e ? e.HALF_FLOAT_OES : null, h = t.FLOAT), {
        internalFormatFloat: n,
        internalFormatHalfFloat: r,
        internalFormatPackedHalfFloat: o,
        internalFormatPackedFloat: i,
        textureFormatFloat: u,
        downloadTextureFormat: t.RGBA,
        downloadUnpackNumChannels: s,
        defaultNumChannels: c,
        textureTypeHalfFloat: l,
        textureTypeFloat: h
      };
    }

    function Kt(t, e, n) {
      var r = n();
      return e && function (t) {
        var e = t.getError();
        if (e !== t.NO_ERROR) throw new Error("WebGL Error: " + Yt(t, e));
      }(t), r;
    }

    !function (t) {
      t[t.DENSE = 0] = "DENSE", t[t.SHARED_BATCH = 1] = "SHARED_BATCH";
    }(_t || (_t = {})), function (t) {
      t[t.RENDER = 0] = "RENDER", t[t.UPLOAD = 1] = "UPLOAD", t[t.PIXELS = 2] = "PIXELS", t[t.DOWNLOAD = 3] = "DOWNLOAD";
    }(Mt || (Mt = {})), function (t) {
      t[t.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", t[t.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", t[t.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", t[t.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", t[t.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
    }(Bt || (Bt = {}));
    var jt = 5.96e-8,
      Xt = 65504;

    function $t(t) {
      return !!(a().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || 0 === t || jt < Math.abs(t) && Math.abs(t) < Xt);
    }

    function Yt(t, e) {
      switch (e) {
        case t.NO_ERROR:
          return "NO_ERROR";

        case t.INVALID_ENUM:
          return "INVALID_ENUM";

        case t.INVALID_VALUE:
          return "INVALID_VALUE";

        case t.INVALID_OPERATION:
          return "INVALID_OPERATION";

        case t.INVALID_FRAMEBUFFER_OPERATION:
          return "INVALID_FRAMEBUFFER_OPERATION";

        case t.OUT_OF_MEMORY:
          return "OUT_OF_MEMORY";

        case t.CONTEXT_LOST_WEBGL:
          return "CONTEXT_LOST_WEBGL";

        default:
          return "Unknown error code " + e;
      }
    }

    function Qt(t, e, n) {
      return be(t, e, function () {
        return t.getExtension(n);
      }, 'Extension "' + n + '" not supported on this browser.');
    }

    function Jt(t, e, n) {
      var r = be(t, e, function () {
        return t.createShader(t.VERTEX_SHADER);
      }, "Unable to create vertex WebGLShader.");
      if (Kt(t, e, function () {
        return t.shaderSource(r, n);
      }), Kt(t, e, function () {
        return t.compileShader(r);
      }), !1 === t.getShaderParameter(r, t.COMPILE_STATUS)) throw console.log(t.getShaderInfoLog(r)), new Error("Failed to compile vertex shader.");
      return r;
    }

    function Zt(t, e, n) {
      var r = be(t, e, function () {
        return t.createShader(t.FRAGMENT_SHADER);
      }, "Unable to create fragment WebGLShader.");
      if (Kt(t, e, function () {
        return t.shaderSource(r, n);
      }), Kt(t, e, function () {
        return t.compileShader(r);
      }), !1 === t.getShaderParameter(r, t.COMPILE_STATUS)) throw function (t, e) {
        var n = ne.exec(e);
        if (null == n) return console.log("Couldn't parse line number in error: " + e), void console.log(t);

        for (var r = +n[1], o = t.split("\n"), a = o.length.toString().length + 2, i = o.map(function (t, e) {
          return k((e + 1).toString(), a) + t;
        }), u = 0, s = 0; s < i.length; s++) u = Math.max(i[s].length, u);

        var c = i.slice(0, r - 1),
          l = i.slice(r - 1, r),
          h = i.slice(r);
        console.log(c.join("\n")), console.log(e.split("\n")[0]), console.log("%c " + k(l[0], u), "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(h.join("\n"));
      }(n, t.getShaderInfoLog(r)), new Error("Failed to compile fragment shader.");
      return r;
    }

    var te,
      ee,
      ne = /ERROR: [0-9]+:([0-9]+):/g;

    function re(t, e) {
      return be(t, e, function () {
        return t.createProgram();
      }, "Unable to create WebGLProgram.");
    }

    function oe(t, e, n) {
      if (Kt(t, e, function () {
        return t.linkProgram(n);
      }), !1 === t.getProgramParameter(n, t.LINK_STATUS)) throw console.log(t.getProgramInfoLog(n)), new Error("Failed to link vertex and fragment shaders.");
    }

    function ae(t, e, n) {
      if (Kt(t, e, function () {
        return t.validateProgram(n);
      }), !1 === t.getProgramParameter(n, t.VALIDATE_STATUS)) throw console.log(t.getProgramInfoLog(n)), new Error("Shader program validation failed.");
    }

    function ie(t, e, n) {
      var r = be(t, e, function () {
        return t.createBuffer();
      }, "Unable to create WebGLBuffer");
      return Kt(t, e, function () {
        return t.bindBuffer(t.ARRAY_BUFFER, r);
      }), Kt(t, e, function () {
        return t.bufferData(t.ARRAY_BUFFER, n, t.STATIC_DRAW);
      }), r;
    }

    function ue(t, e, n) {
      var r = be(t, e, function () {
        return t.createBuffer();
      }, "Unable to create WebGLBuffer");
      return Kt(t, e, function () {
        return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, r);
      }), Kt(t, e, function () {
        return t.bufferData(t.ELEMENT_ARRAY_BUFFER, n, t.STATIC_DRAW);
      }), r;
    }

    function se(t, e) {
      return be(t, e, function () {
        return t.createTexture();
      }, "Unable to create WebGLTexture.");
    }

    function ce(t, e) {
      var n = a().getNumber("WEBGL_MAX_TEXTURE_SIZE");

      if (t <= 0 || e <= 0) {
        var r = "[" + t + "x" + e + "]";
        throw new Error("Requested texture size " + r + " is invalid.");
      }

      if (t > n || e > n) {
        r = "[" + t + "x" + e + "]";
        throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + ("[" + n + "x" + n + "]") + ".");
      }
    }

    function le(t, e) {
      return be(t, e, function () {
        return t.createFramebuffer();
      }, "Unable to create WebGLFramebuffer.");
    }

    function he(t, e, n, r, o, a, i, u) {
      var s = t.getAttribLocation(n, r);
      return -1 !== s && (Kt(t, e, function () {
        return t.bindBuffer(t.ARRAY_BUFFER, o);
      }), Kt(t, e, function () {
        return t.vertexAttribPointer(s, a, t.FLOAT, !1, i, u);
      }), Kt(t, e, function () {
        return t.enableVertexAttribArray(s);
      }), !0);
    }

    function fe(t, e, n, r) {
      we(t, r), Kt(t, e, function () {
        return t.activeTexture(t.TEXTURE0 + r);
      }), Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, n);
      });
    }

    function pe(t, e, n, r) {
      return be(t, e, function () {
        return t.getUniformLocation(n, r);
      }, 'uniform "' + r + '" not present in program.');
    }

    function de(t, e, n) {
      return t.getUniformLocation(e, n);
    }

    function ve(t, e, n, r, o, a) {
      Kt(t, e, function () {
        return fe(t, e, r, a);
      }), Kt(t, e, function () {
        return t.uniform1i(o, a);
      });
    }

    function me(t, e, n, r) {
      Kt(t, e, function () {
        return t.bindFramebuffer(t.FRAMEBUFFER, r);
      }), Kt(t, e, function () {
        return t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, n, 0);
      });
    }

    function ge(t, e, n) {
      Kt(t, e, function () {
        return t.bindFramebuffer(t.FRAMEBUFFER, n);
      }), Kt(t, e, function () {
        return t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, null, 0);
      });
    }

    function ye(t) {
      var e = t.checkFramebufferStatus(t.FRAMEBUFFER);
      if (e !== t.FRAMEBUFFER_COMPLETE) throw new Error("Error binding framebuffer: " + xe(t, e));
    }

    function xe(t, e) {
      switch (e) {
        case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
          return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";

        case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
          return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";

        case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
          return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";

        case t.FRAMEBUFFER_UNSUPPORTED:
          return "FRAMEBUFFER_UNSUPPORTED";

        default:
          return "unknown error " + e;
      }
    }

    function be(t, e, n, r) {
      var o = Kt(t, e, function () {
        return n();
      });
      if (null == o) throw new Error(r);
      return o;
    }

    function we(t, e) {
      var n = t.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1,
        r = e + t.TEXTURE0;
      if (r < t.TEXTURE0 || r > n) throw new Error("textureUnit must be in " + ("[gl.TEXTURE0, gl.TEXTURE" + n + "]") + ".");
    }

    function Ce(t, e) {
      return void 0 === e && (e = 2), w(t.slice(0, t.length - e));
    }

    function Ee(t) {
      if (0 === t.length) throw Error("Cannot get rows and columns of an empty shape array.");
      return [t.length > 1 ? t[t.length - 2] : 1, t[t.length - 1]];
    }

    function Re(t) {
      var e = [1, 1, 1];
      return 0 === t.length || 1 === t.length && 1 === t[0] || (e = [Ce(t)].concat(Ee(t))), e;
    }

    function Ie(t, e) {
      var n;
      void 0 === e && (e = !1);
      var r = a().getNumber("WEBGL_MAX_TEXTURE_SIZE");

      if (e && (r *= 2, 1 === (t = t.map(function (e, n) {
        return n >= t.length - 2 ? v(t[n]) : t[n];
      })).length && (t = [2, t[0]])), 2 !== t.length) {
        var o = T(t);
        t = o.newShape;
      }

      var i = w(t);
      if (t.length <= 1 && i <= r) return [1, i];
      if (2 === t.length && t[0] <= r && t[1] <= r) return t;
      if (3 === t.length && t[0] * t[1] <= r && t[2] <= r) return [t[0] * t[1], t[2]];
      if (3 === t.length && t[0] <= r && t[1] * t[2] <= r) return [t[0], t[1] * t[2]];
      if (4 === t.length && t[0] * t[1] * t[2] <= r && t[3] <= r) return [t[0] * t[1] * t[2], t[3]];
      if (4 === t.length && t[0] <= r && t[1] * t[2] * t[3] <= r) return [t[0], t[1] * t[2] * t[3]];

      if (e) {
        var u = Ce(t),
          s = 2,
          c = 2;
        return t.length && (s = (n = Ee(t))[0], c = n[1]), I(i = u * (s / 2) * (c / 2)).map(function (t) {
          return 2 * t;
        });
      }

      return I(i);
    }

    function ke(t) {
      return t % 2 == 0;
    }

    function Se(t, e) {
      if (C(t = t.slice(-2), e = e.slice(-2))) return !0;
      if (!t.length || !e.length) return !0;
      if (0 === t[0] || 0 === t[1] || 0 === e[0] || 0 === e[1]) return !0;

      if (t.length !== e.length) {
        var n = t.slice(-1)[0],
          r = e.slice(-1)[0];
        if (n === r) return !0;
        if (ke(n) && ke(r) && (1 === t[0] || 1 === e[0])) return !0;
      }

      return t[1] === e[1] && ke(t[0]) && ke(e[0]);
    }

    function Ae(t) {
      if (null == te) {
        var e = Ut(t);
        te = e.getParameter(e.MAX_TEXTURE_SIZE);
      }

      return te;
    }

    function De(t) {
      if (null == ee) {
        var e = Ut(t);
        ee = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);
      }

      return Math.min(16, ee);
    }

    function Te(t) {
      if (0 === t) return 0;
      var e = Ut(t);
      return Ne(e, "EXT_disjoint_timer_query_webgl2") && 2 === t ? 2 : Ne(e, "EXT_disjoint_timer_query") ? 1 : 0;
    }

    function Ne(t, e) {
      return null != t.getExtension(e);
    }

    function Fe(t) {
      try {
        if (null != Ut(t)) return !0;
      } catch (t) {
        return !1;
      }

      return !1;
    }

    function Oe(t) {
      if (0 === t) return !1;
      var e = Ut(t);

      if (1 === t) {
        if (!Ne(e, "OES_texture_float")) return !1;
      } else if (!Ne(e, "EXT_color_buffer_float")) return !1;

      return Me(e);
    }

    function _e(t) {
      if (0 === t) return !1;
      var e = Ut(t);

      if (1 !== t) {
        if (Ne(e, "EXT_color_buffer_float")) return Me(e);

        if (Ne(e, "EXT_color_buffer_half_float")) {
          var n = e.getExtension("EXT_color_buffer_half_float");
          return function (t, e) {
            var n = qt(t, e),
              r = t.createTexture();
            t.bindTexture(t.TEXTURE_2D, r);
            t.texImage2D(t.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
            var o = t.createFramebuffer();
            t.bindFramebuffer(t.FRAMEBUFFER, o), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, r, 0);
            var a = t.checkFramebufferStatus(t.FRAMEBUFFER) === t.FRAMEBUFFER_COMPLETE;
            return t.bindTexture(t.TEXTURE_2D, null), t.bindFramebuffer(t.FRAMEBUFFER, null), t.deleteTexture(r), t.deleteFramebuffer(o), a;
          }(e, n);
        }

        return !1;
      }

      return !!Ne(e, "OES_texture_float") && !!Ne(e, "WEBGL_color_buffer_float") && Me(e);
    }

    function Me(t) {
      var e = qt(t),
        n = t.createTexture();
      t.bindTexture(t.TEXTURE_2D, n);
      t.texImage2D(t.TEXTURE_2D, 0, e.internalFormatFloat, 1, 1, 0, e.textureFormatFloat, e.textureTypeFloat, null);
      var r = t.createFramebuffer();
      t.bindFramebuffer(t.FRAMEBUFFER, r), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, n, 0);
      var o = t.checkFramebufferStatus(t.FRAMEBUFFER) === t.FRAMEBUFFER_COMPLETE;
      return t.bindTexture(t.TEXTURE_2D, null), t.bindFramebuffer(t.FRAMEBUFFER, null), t.deleteTexture(n), t.deleteFramebuffer(r), o;
    }

    function Be(t) {
      return 2 === t && null != Ut(t).fenceSync;
    }

    var Pe = Object.freeze({
      callAndCheck: Kt,
      canBeRepresented: $t,
      getWebGLErrorMessage: Yt,
      getExtensionOrThrow: Qt,
      createVertexShader: Jt,
      createFragmentShader: Zt,
      createProgram: re,
      linkProgram: oe,
      validateProgram: ae,
      createStaticVertexBuffer: ie,
      createStaticIndexBuffer: ue,
      getNumChannels: function () {
        return 2 === a().getNumber("WEBGL_VERSION") ? 1 : 4;
      },
      createTexture: se,
      validateTextureSize: ce,
      createFramebuffer: le,
      bindVertexBufferToProgramAttribute: he,
      bindTextureUnit: fe,
      unbindTextureUnit: function (t, e, n) {
        we(t, n), Kt(t, e, function () {
          return t.activeTexture(t.TEXTURE0 + n);
        }), Kt(t, e, function () {
          return t.bindTexture(t.TEXTURE_2D, null);
        });
      },
      getProgramUniformLocationOrThrow: pe,
      getProgramUniformLocation: de,
      bindTextureToProgramUniformSampler: ve,
      bindCanvasToFramebuffer: function (t, e) {
        Kt(t, e, function () {
          return t.bindFramebuffer(t.FRAMEBUFFER, null);
        }), Kt(t, e, function () {
          return t.viewport(0, 0, t.canvas.width, t.canvas.height);
        }), Kt(t, e, function () {
          return t.scissor(0, 0, t.canvas.width, t.canvas.height);
        });
      },
      bindColorTextureToFramebuffer: me,
      unbindColorTextureFromFramebuffer: ge,
      validateFramebuffer: ye,
      getFramebufferErrorMessage: xe,
      getBatchDim: Ce,
      getRowsCols: Ee,
      getShapeAs3D: Re,
      getTextureShapeFromLogicalShape: Ie,
      isReshapeFree: Se,
      getWebGLMaxTextureSize: Ae,
      resetMaxTextureSize: function () {
        te = null;
      },
      resetMaxTexturesInShader: function () {
        ee = null;
      },
      getMaxTexturesInShader: De,
      getWebGLDisjointQueryTimerVersion: Te,
      hasExtension: Ne,
      isWebGLVersionEnabled: Fe,
      isCapableOfRenderingToFloatTexture: Oe,
      isDownloadFloatTextureEnabled: _e,
      isWebGLFenceEnabled: Be
    }),
      Le = a();

    function We() {
      a().set("PROD", !0);
    }

    function Ue() {
      a().set("DEBUG", !0);
    }

    function Ve() {
      a().set("DEPRECATION_WARNINGS_ENABLED", !1), console.warn("TensorFlow.js deprecation warnings have been disabled.");
    }

    function ze(t) {
      a().getBool("DEPRECATION_WARNINGS_ENABLED") && console.warn(t + " You can disable deprecation warnings with tf.disableDeprecationWarnings().");
    }

    function Ge() {
      Nt.disposeVariables();
    }

    function He() {
      return Nt;
    }

    function qe() {
      return Nt.memory();
    }

    function Ke(t) {
      return Nt.profile(t);
    }

    function je(t, e) {
      return Nt.tidy(t, e);
    }

    function Xe(t) {
      kt(t).forEach(function (t) {
        return t.dispose();
      });
    }

    function $e(t) {
      return Nt.keep(t);
    }

    function Ye(t) {
      return Nt.time(t);
    }

    function Qe(t) {
      return Nt.setBackend(t);
    }

    function Je() {
      return Nt.ready();
    }

    function Ze() {
      return Nt.backendName;
    }

    function tn(t) {
      Nt.removeBackend(t);
    }

    function en(t) {
      return Nt.findBackend(t);
    }

    function nn(t) {
      return Nt.findBackendFactory(t);
    }

    function rn(t, e, n) {
      return void 0 === n && (n = 1), Nt.registerBackend(t, e, n);
    }

    function on() {
      return Nt.backend;
    }

    function an(t, e) {
      a().setPlatform(t, e);
    }

    function un() {
      for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];

      a().getBool("IS_TEST") || console.warn.apply(console, t);
    }

    function sn(t, e) {
      var n = t;
      if (B(t)) return "string" === e ? [] : [t.length];
      if (!Array.isArray(t)) return [];

      for (var r = []; Array.isArray(n) || B(n) && "string" !== e;) r.push(n.length), n = n[0];

      return Array.isArray(t) && a().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && function t(e, n, r) {
        r = r || [];
        if (!Array.isArray(e) && !B(e)) return void g(0 === n.length, function () {
          return "Element arr[" + r.join("][") + "] is a primitive, but should be an array/TypedArray of " + n[0] + " elements";
        });
        g(n.length > 0, function () {
          return "Element arr[" + r.join("][") + "] should be a primitive, but is an array of " + e.length + " elements";
        });
        g(e.length === n[0], function () {
          return "Element arr[" + r.join("][") + "] should have " + n[0] + " elements, but has " + e.length + " elements";
        });
        var o = n.slice(1);

        for (var a = 0; a < e.length; ++a) t(e[a], o, r.concat(a));
      }(t, r, []), r;
    }

    function cn(t, e, n, r) {
      if (null != t && ("numeric" !== t && t !== e || "numeric" === t && "string" === e)) throw new Error("Argument '" + n + "' passed to '" + r + "' must be " + t + " tensor, but got " + e + " tensor");
    }

    function ln(t, e, n, r) {
      if (void 0 === r && (r = "numeric"), t instanceof dt) return cn(r, t.dtype, e, n), t;
      var o = z(t);

      if ("string" !== o && ["bool", "int32", "float32"].indexOf(r) >= 0 && (o = r), cn(r, o, e, n), null == t || !B(t) && !Array.isArray(t) && "number" != typeof t && "boolean" != typeof t && "string" != typeof t) {
        var i = null == t ? "null" : t.constructor.name;
        throw new Error("Argument '" + e + "' passed to '" + n + "' must be a Tensor or TensorLike, but got '" + i + "'");
      }

      var u = sn(t, o);
      B(t) || Array.isArray(t) || (t = [t]);
      var s = "string" !== o ? K(t, o, a().getBool("DEBUG")) : b(t, [], !0);
      return Nt.makeTensor(s, u, o);
    }

    function hn(t, e, n, r) {
      if (void 0 === r && (r = "numeric"), !Array.isArray(t)) throw new Error("Argument " + e + " passed to " + n + " must be a `Tensor[]` or `TensorLike[]`");
      return t.map(function (t, r) {
        return ln(t, e + "[" + r + "]", n);
      }, r);
    }

    function fn(t, e) {
      for (var n = 0; n < t.length; ++n) if (t[t.length - n - 1] !== e - 1 - n) return !1;

      return !0;
    }

    function pn(t, e, n) {
      for (var r = t.length + e.length, o = [], a = 0, i = 0, u = 0; u < r; u++) -1 === n.indexOf(u) ? o.push(t[a++]) : o.push(e[i++]);

      return o;
    }

    function dn(t, e) {
      for (var n = [], r = t.length, o = 0; o < r; o++) -1 === e.indexOf(o) && n.push(t[o]);

      return [n, e.map(function (e) {
        return t[e];
      })];
    }

    function vn(t, e) {
      return pn(t, e.map(function (t) {
        return 1;
      }), e);
    }

    function mn(t, e, n) {
      g(fn(e, n), function () {
        return t + " supports only inner-most axes for now. Got axes " + e + " and rank-" + n + " input.";
      });
    }

    function gn(t, e) {
      if (fn(t, e)) return null;

      for (var n = [], r = 0; r < e; ++r) -1 === t.indexOf(r) && n.push(r);

      return t.forEach(function (t) {
        return n.push(t);
      }), n;
    }

    function yn(t) {
      return t.map(function (t, e) {
        return [e, t];
      }).sort(function (t, e) {
        return t[1] - e[1];
      }).map(function (t) {
        return t[0];
      });
    }

    function xn(t, e) {
      for (var n = [], r = e - t; r < e; ++r) n.push(r);

      return n;
    }

    function bn(t, e) {
      var n = t[0].length;
      t.forEach(function (t, e) {
        g(t.length === n, function () {
          return "Error in concat" + n + "D: rank of tensors[" + e + "] must be the same as the rank of the rest (" + n + ")";
        });
      }), g(e >= 0 && e < n, function () {
        return "Error in concat" + n + "D: axis must be between 0 and " + (n - 1) + ".";
      });
      var r = t[0];
      t.forEach(function (t, o) {
        for (var a = 0; a < n; a++) g(a === e || t[a] === r[a], function () {
          return "Error in concat" + n + "D: Shape of tensors[" + o + "] (" + t + ") does not match the shape of the rest (" + r + ") along the non-concatenated axis " + o + ".";
        });
      });
    }

    function wn(t, e) {
      for (var n = t[0].slice(), r = 1; r < t.length; r++) n[e] += t[r][e];

      return n;
    }

    function Cn(t) {
      var e = Object.keys(t);
      if (1 !== e.length) throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with " + e.length + " keys.");
      var n = e[0],
        r = t[n];
      n.endsWith("_") && (n = n.substring(0, n.length - 1));

      var o = function () {
        for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];

        Nt.startScope(n);

        try {
          var o = r.apply(void 0, t);
          return o instanceof Promise && console.error("Cannot return a Promise inside of tidy."), Nt.endScope(o), o;
        } catch (t) {
          throw Nt.endScope(null), t;
        }
      };

      return Object.defineProperty(o, "name", {
        value: n,
        configurable: !0
      }), o;
    }

    Le.registerFlag("HAS_WEBGL", function () {
      return Le.getNumber("WEBGL_VERSION") > 0;
    }), Le.registerFlag("WEBGL_VERSION", function () {
      return Fe(2) ? 2 : Fe(1) ? 1 : 0;
    }), Le.registerFlag("WEBGL_BUFFER_SUPPORTED", function () {
      return 2 === Le.get("WEBGL_VERSION");
    }), Le.registerFlag("WEBGL_CPU_FORWARD", function () {
      return !0;
    }), Le.registerFlag("WEBGL_FORCE_F16_TEXTURES", function () {
      return !1;
    }), Le.registerFlag("WEBGL_PACK", function () {
      return Le.getBool("HAS_WEBGL");
    }), Le.registerFlag("WEBGL_PACK_NORMALIZATION", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_CLIP", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_DEPTHWISECONV", function () {
      return !1;
    }), Le.registerFlag("WEBGL_PACK_BINARY_OPERATIONS", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_UNARY_OPERATIONS", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_PACK_REDUCE", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_LAZILY_UNPACK", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_CONV_IM2COL", function () {
      return Le.getBool("WEBGL_PACK");
    }), Le.registerFlag("WEBGL_MAX_TEXTURE_SIZE", function () {
      return Ae(Le.getNumber("WEBGL_VERSION"));
    }), Le.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER", function () {
      return De(Le.getNumber("WEBGL_VERSION"));
    }), Le.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION", function () {
      var t = Le.getNumber("WEBGL_VERSION");
      return 0 === t ? 0 : Te(t);
    }), Le.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE", function () {
      return Le.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 && (t = navigator.userAgent || navigator.vendor || window.opera, !(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0, 4))));
      var t;
    }), Le.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE", function () {
      return Oe(Le.getNumber("WEBGL_VERSION"));
    }), Le.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED", function () {
      return !Le.getBool("WEBGL_FORCE_F16_TEXTURES") && Le.getBool("WEBGL_RENDER_FLOAT32_CAPABLE");
    }), Le.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED", function () {
      return _e(Le.getNumber("WEBGL_VERSION"));
    }), Le.registerFlag("WEBGL_FENCE_API_ENABLED", function () {
      return Be(Le.getNumber("WEBGL_VERSION"));
    }), Le.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM", function () {
      return Le.getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? 4 : 0;
    }), pt = ze;
    var En = Cn({
      complex_: function (t, e) {
        var n = ln(t, "real", "complex"),
          r = ln(e, "imag", "complex");
        return y(n.shape, r.shape, "real and imag shapes, " + n.shape + " and " + r.shape + ", must match in call to tf.complex()."), Nt.runKernelFunc(function (t) {
          return t.complex(n, r);
        }, {
          $real: n,
          $imag: r
        });
      }
    }),
      Rn = Cn({
        real_: function (t) {
          var e = ln(t, "input", "real");
          return Nt.runKernelFunc(function (t) {
            return t.real(e);
          }, {
            $input: e
          });
        }
      }),
      In = Cn({
        imag_: function (t) {
          var e = ln(t, "input", "imag");
          return Nt.runKernelFunc(function (t) {
            return t.imag(e);
          }, {
            $input: e
          });
        }
      });
    exports.imag = In;
    exports.real = Rn;
    exports.complex = En;

    function kn(t, e, n) {
      return Sn(t, e, sn(t, n), n);
    }

    function Sn(t, e, n, r) {
      if (null == r && (r = z(t)), "complex64" === r) throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
      if (!B(t) && !Array.isArray(t) && "number" != typeof t && "boolean" != typeof t && "string" != typeof t) throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");

      if (null != e) {
        Q(e);
        var o = w(e),
          i = w(n);
        g(o === i, function () {
          return "Based on the provided shape, [" + e + "], the tensor should have " + o + " values but has " + i;
        });

        for (var u = 0; u < n.length; ++u) {
          var s = n[u],
            c = u !== n.length - 1 || s !== w(e.slice(u));
          g(n[u] === e[u] || !c, function () {
            return "Error creating a new Tensor. Inferred shape (" + n + ") does not match the provided shape (" + e + "). ";
          });
        }
      }

      return B(t) || Array.isArray(t) || (t = [t]), e = e || n, t = "string" !== r ? K(t, r, a().getBool("DEBUG")) : b(t, [], !0), Nt.makeTensor(t, e, r);
    }

    function An(t, e) {
      if ((B(t) && "string" !== e || Array.isArray(t)) && "complex64" !== e) throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
      if ("string" === e && B(t) && !(t instanceof Uint8Array)) throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
      return Sn(t, [], [], e);
    }

    function Dn(t, e) {
      x(t);
      var n = sn(t, e);
      if (1 !== n.length) throw new Error("tensor1d() requires values to be a flat/TypedArray");
      return Sn(t, null, n, e);
    }

    function Tn(t, e, n) {
      if (x(t), null != e && 2 !== e.length) throw new Error("tensor2d() requires shape to have two numbers");
      var r = sn(t, n);
      if (2 !== r.length && 1 !== r.length) throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");
      if (1 === r.length && null == e) throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");
      return Sn(t, e, r, n);
    }

    function Nn(t, e, n) {
      if (x(t), null != e && 3 !== e.length) throw new Error("tensor3d() requires shape to have three numbers");
      var r = sn(t, n);
      if (3 !== r.length && 1 !== r.length) throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");
      if (1 === r.length && null == e) throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");
      return Sn(t, e, r, n);
    }

    function Fn(t, e, n) {
      if (x(t), null != e && 4 !== e.length) throw new Error("tensor4d() requires shape to have four numbers");
      var r = sn(t, n);
      if (4 !== r.length && 1 !== r.length) throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");
      if (1 === r.length && null == e) throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");
      return Sn(t, e, r, n);
    }

    function On(t, e, n) {
      if (x(t), null != e && 5 !== e.length) throw new Error("tensor5d() requires shape to have five numbers");
      var r = sn(t, n);
      if (5 !== r.length && 1 !== r.length) throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");
      if (1 === r.length && null == e) throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");
      return Sn(t, e, r, n);
    }

    function _n(t, e, n) {
      if (x(t), null != e && 6 !== e.length) throw new Error("tensor6d() requires shape to have six numbers");
      var r = sn(t, n);
      if (6 !== r.length && 1 !== r.length) throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");
      if (1 === r.length && null == e) throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");
      return Sn(t, e = e || r, r, n);
    }

    function Mn(t, e, n, r) {
      return void 0 === e && (e = !0), Nt.makeVariable(t, e, n, r);
    }

    function Bn(t, e) {
      if (void 0 === e && (e = "float32"), "complex64" === e) {
        var n = Bn(t, "float32"),
          r = Pn(t, "float32");
        return En(n, r);
      }

      var o = X(w(t), e);
      return Nt.makeTensor(o, t, e);
    }

    function Pn(t, e) {
      if (void 0 === e && (e = "float32"), "complex64" === e) {
        var n = Pn(t, "float32"),
          r = Pn(t, "float32");
        return En(n, r);
      }

      var o = $(w(t), e);
      return Nt.makeTensor(o, t, e);
    }

    function Ln(t, e, n) {
      return Nt.runKernelFunc(function (r) {
        return r.fill(t, e, n);
      }, {});
    }

    function Wn(t, e, n) {
      if (n <= 0) throw new Error("The number of values should be positive.");
      return Nt.runKernelFunc(function (r) {
        return r.linspace(t, e, n);
      }, {});
    }

    function Un(t, e, n, r) {
      if (void 0 === n && (n = 1), void 0 === r && (r = "float32"), 0 === n) throw new Error("Cannot have a step of zero");
      if (t === e || t < e && n < 0 || e < t && n > 1) return Pn([0], r);
      var o = $(Math.abs(Math.ceil((e - t) / n)), r);
      e < t && 1 === n && (n = -1), o[0] = t;

      for (var a = 1; a < o.length; a++) o[a] = o[a - 1] + n;

      return Dn(o, r);
    }

    var Vn = Cn({
      onesLike_: function (t) {
        var e = ln(t, "x", "onesLike");

        if ("complex64" === e.dtype) {
          var n = Vn(Rn(e)),
            r = zn(In(e));
          return En(n, r);
        }

        return Nt.runKernelFunc(function (t) {
          return t.onesLike(e);
        }, {
          $x: e
        }, function (t, e) {
          return {
            $x: function () {
              return zn(t);
            }
          };
        });
      }
    }),
      zn = Cn({
        zerosLike_: function (t) {
          var e = ln(t, "x", "zerosLike");
          return Nt.runKernelFunc(function (t) {
            return t.zerosLike(e);
          }, {
            $x: e
          }, function (t, e) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      });
    exports.zerosLike = zn;
    exports.onesLike = Vn;
    var Gn = Cn({
      concat_: function (t, e) {
        void 0 === e && (e = 0), g(t.length >= 1, function () {
          return "Pass at least one tensor to concat";
        });
        var n = hn(t, "tensors", "concat");
        "complex64" === n[0].dtype && n.forEach(function (t) {
          if ("complex64" !== t.dtype) throw new Error("Cannot concatenate complex64 tensors with a tensor\n          with dtype " + t.dtype + ". ");
        }), e = D(e, n[0].shape)[0];
        var r = wn(n.map(function (t) {
          return t.shape;
        }), e);
        if (0 === w(r)) return kn([], r);
        if (1 === (n = n.filter(function (t) {
          return t.size > 0;
        })).length) return n[0];
        var o = n.map(function (t) {
          return t.shape;
        });
        bn(o, e);
        var a = n;
        return Nt.runKernelFunc(function (t) {
          return t.concat(n, e);
        }, a, function (t) {
          var n = o.map(function (t) {
            return t[e];
          });
          return Xn(t, n, e).map(function (t) {
            return function () {
              return t;
            };
          });
        });
      }
    }),
      Hn = Cn({
        concat1d_: function (t) {
          return Gn(t, 0);
        }
      }),
      qn = Cn({
        concat2d_: function (t, e) {
          return Gn(t, e);
        }
      }),
      Kn = Cn({
        concat3d_: function (t, e) {
          return Gn(t, e);
        }
      }),
      jn = Cn({
        concat4d_: function (t, e) {
          return Gn(t, e);
        }
      }),
      Xn = Cn({
        split_: function (t, e, n) {
          void 0 === n && (n = 0);
          var r,
            o = ln(t, "x", "split");
          return n = D(n, o.shape)[0], "number" == typeof e ? (g(o.shape[n] % e == 0, function () {
            return "Number of splits must evenly divide the axis.";
          }), r = new Array(e).fill(o.shape[n] / e)) : (g(o.shape[n] === e.reduce(function (t, e) {
            return t + e;
          }), function () {
            return "The sum of sizes must match the size of the axis dimension.";
          }), r = e), Nt.runKernelFunc(function (t) {
            return t.split(o, r, n);
          }, {
            $x: o
          }, function (t) {
            return {
              $x: function () {
                return Gn(t, n);
              }
            };
          });
        }
      });
    exports.split = Xn;
    exports.concat4d = jn;
    exports.concat3d = Kn;
    exports.concat2d = qn;
    exports.concat1d = Hn;
    exports.concat = Gn;
    "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self && self;

    function $n(t, e) {
      return t(e = {
        exports: {}
      }, e.exports), e.exports;
    }

    var Yn = $n(function (t) {
      !function (t, e, n) {
        function r(t) {
          var e,
            n = this,
            r = (e = 4022871197, function (t) {
              t = t.toString();

              for (var n = 0; n < t.length; n++) {
                var r = .02519603282416938 * (e += t.charCodeAt(n));
                r -= e = r >>> 0, e = (r *= e) >>> 0, e += 4294967296 * (r -= e);
              }

              return 2.3283064365386963e-10 * (e >>> 0);
            });
          n.next = function () {
            var t = 2091639 * n.s0 + 2.3283064365386963e-10 * n.c;
            return n.s0 = n.s1, n.s1 = n.s2, n.s2 = t - (n.c = 0 | t);
          }, n.c = 1, n.s0 = r(" "), n.s1 = r(" "), n.s2 = r(" "), n.s0 -= r(t), n.s0 < 0 && (n.s0 += 1), n.s1 -= r(t), n.s1 < 0 && (n.s1 += 1), n.s2 -= r(t), n.s2 < 0 && (n.s2 += 1), r = null;
        }

        function o(t, e) {
          return e.c = t.c, e.s0 = t.s0, e.s1 = t.s1, e.s2 = t.s2, e;
        }

        function a(t, e) {
          var n = new r(t),
            a = e && e.state,
            i = n.next;
          return i.int32 = function () {
            return 4294967296 * n.next() | 0;
          }, i.double = function () {
            return i() + 1.1102230246251565e-16 * (2097152 * i() | 0);
          }, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
            return o(n, {});
          }), i;
        }

        e && e.exports ? e.exports = a : n && n.amd ? n(function () {
          return a;
        }) : this.alea = a;
      }(0, t, !1);
    }),
      Qn = $n(function (t) {
        !function (t, e, n) {
          function r(t) {
            var e = this,
              n = "";
            e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.next = function () {
              var t = e.x ^ e.x << 11;
              return e.x = e.y, e.y = e.z, e.z = e.w, e.w ^= e.w >>> 19 ^ t ^ t >>> 8;
            }, t === (0 | t) ? e.x = t : n += t;

            for (var r = 0; r < n.length + 64; r++) e.x ^= 0 | n.charCodeAt(r), e.next();
          }

          function o(t, e) {
            return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e;
          }

          function a(t, e) {
            var n = new r(t),
              a = e && e.state,
              i = function () {
                return (n.next() >>> 0) / 4294967296;
              };

            return i.double = function () {
              do {
                var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
              return o(n, {});
            }), i;
          }

          e && e.exports ? e.exports = a : n && n.amd ? n(function () {
            return a;
          }) : this.xor128 = a;
        }(0, t, !1);
      }),
      Jn = $n(function (t) {
        !function (t, e, n) {
          function r(t) {
            var e = this,
              n = "";
            e.next = function () {
              var t = e.x ^ e.x >>> 2;
              return e.x = e.y, e.y = e.z, e.z = e.w, e.w = e.v, (e.d = e.d + 362437 | 0) + (e.v = e.v ^ e.v << 4 ^ t ^ t << 1) | 0;
            }, e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.v = 0, t === (0 | t) ? e.x = t : n += t;

            for (var r = 0; r < n.length + 64; r++) e.x ^= 0 | n.charCodeAt(r), r == n.length && (e.d = e.x << 10 ^ e.x >>> 4), e.next();
          }

          function o(t, e) {
            return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e.v = t.v, e.d = t.d, e;
          }

          function a(t, e) {
            var n = new r(t),
              a = e && e.state,
              i = function () {
                return (n.next() >>> 0) / 4294967296;
              };

            return i.double = function () {
              do {
                var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
              return o(n, {});
            }), i;
          }

          e && e.exports ? e.exports = a : n && n.amd ? n(function () {
            return a;
          }) : this.xorwow = a;
        }(0, t, !1);
      }),
      Zn = $n(function (t) {
        !function (t, e, n) {
          function r(t) {
            var e = this;
            e.next = function () {
              var t,
                n,
                r = e.x,
                o = e.i;
              return t = r[o], n = (t ^= t >>> 7) ^ t << 24, n ^= (t = r[o + 1 & 7]) ^ t >>> 10, n ^= (t = r[o + 3 & 7]) ^ t >>> 3, n ^= (t = r[o + 4 & 7]) ^ t << 7, t = r[o + 7 & 7], n ^= (t ^= t << 13) ^ t << 9, r[o] = n, e.i = o + 1 & 7, n;
            }, function (t, e) {
              var n,
                r = [];
              if (e === (0 | e)) r[0] = e; else for (e = "" + e, n = 0; n < e.length; ++n) r[7 & n] = r[7 & n] << 15 ^ e.charCodeAt(n) + r[n + 1 & 7] << 13;

              for (; r.length < 8;) r.push(0);

              for (n = 0; n < 8 && 0 === r[n]; ++n);

              for (8 == n ? r[7] = -1 : r[n], t.x = r, t.i = 0, n = 256; n > 0; --n) t.next();
            }(e, t);
          }

          function o(t, e) {
            return e.x = t.x.slice(), e.i = t.i, e;
          }

          function a(t, e) {
            null == t && (t = +new Date());

            var n = new r(t),
              a = e && e.state,
              i = function () {
                return (n.next() >>> 0) / 4294967296;
              };

            return i.double = function () {
              do {
                var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, i.int32 = n.next, i.quick = i, a && (a.x && o(a, n), i.state = function () {
              return o(n, {});
            }), i;
          }

          e && e.exports ? e.exports = a : n && n.amd ? n(function () {
            return a;
          }) : this.xorshift7 = a;
        }(0, t, !1);
      }),
      tr = $n(function (t) {
        !function (t, e, n) {
          function r(t) {
            var e = this;
            e.next = function () {
              var t,
                n,
                r = e.w,
                o = e.X,
                a = e.i;
              return e.w = r = r + 1640531527 | 0, n = o[a + 34 & 127], t = o[a = a + 1 & 127], n ^= n << 13, t ^= t << 17, n ^= n >>> 15, t ^= t >>> 12, n = o[a] = n ^ t, e.i = a, n + (r ^ r >>> 16) | 0;
            }, function (t, e) {
              var n,
                r,
                o,
                a,
                i,
                u = [],
                s = 128;

              for (e === (0 | e) ? (r = e, e = null) : (e += "\0", r = 0, s = Math.max(s, e.length)), o = 0, a = -32; a < s; ++a) e && (r ^= e.charCodeAt((a + 32) % e.length)), 0 === a && (i = r), r ^= r << 10, r ^= r >>> 15, r ^= r << 4, r ^= r >>> 13, a >= 0 && (i = i + 1640531527 | 0, o = 0 == (n = u[127 & a] ^= r + i) ? o + 1 : 0);

              for (o >= 128 && (u[127 & (e && e.length || 0)] = -1), o = 127, a = 512; a > 0; --a) r = u[o + 34 & 127], n = u[o = o + 1 & 127], r ^= r << 13, n ^= n << 17, r ^= r >>> 15, n ^= n >>> 12, u[o] = r ^ n;

              t.w = i, t.X = u, t.i = o;
            }(e, t);
          }

          function o(t, e) {
            return e.i = t.i, e.w = t.w, e.X = t.X.slice(), e;
          }

          function a(t, e) {
            null == t && (t = +new Date());

            var n = new r(t),
              a = e && e.state,
              i = function () {
                return (n.next() >>> 0) / 4294967296;
              };

            return i.double = function () {
              do {
                var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, i.int32 = n.next, i.quick = i, a && (a.X && o(a, n), i.state = function () {
              return o(n, {});
            }), i;
          }

          e && e.exports ? e.exports = a : n && n.amd ? n(function () {
            return a;
          }) : this.xor4096 = a;
        }(0, t, !1);
      }),
      er = $n(function (t) {
        !function (t, e, n) {
          function r(t) {
            var e = this,
              n = "";
            e.next = function () {
              var t = e.b,
                n = e.c,
                r = e.d,
                o = e.a;
              return t = t << 25 ^ t >>> 7 ^ n, n = n - r | 0, r = r << 24 ^ r >>> 8 ^ o, o = o - t | 0, e.b = t = t << 20 ^ t >>> 12 ^ n, e.c = n = n - r | 0, e.d = r << 16 ^ n >>> 16 ^ o, e.a = o - t | 0;
            }, e.a = 0, e.b = 0, e.c = -1640531527, e.d = 1367130551, t === Math.floor(t) ? (e.a = t / 4294967296 | 0, e.b = 0 | t) : n += t;

            for (var r = 0; r < n.length + 20; r++) e.b ^= 0 | n.charCodeAt(r), e.next();
          }

          function o(t, e) {
            return e.a = t.a, e.b = t.b, e.c = t.c, e.d = t.d, e;
          }

          function a(t, e) {
            var n = new r(t),
              a = e && e.state,
              i = function () {
                return (n.next() >>> 0) / 4294967296;
              };

            return i.double = function () {
              do {
                var t = ((n.next() >>> 11) + (n.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, i.int32 = n.next, i.quick = i, a && ("object" == typeof a && o(a, n), i.state = function () {
              return o(n, {});
            }), i;
          }

          e && e.exports ? e.exports = a : n && n.amd ? n(function () {
            return a;
          }) : this.tychei = a;
        }(0, t, !1);
      }),
      nr = $n(function (t) {
        !function (e, n) {
          var r,
            o = this,
            a = 256,
            i = 6,
            u = "random",
            s = n.pow(a, i),
            c = n.pow(2, 52),
            l = 2 * c,
            h = a - 1;

          function f(t, h, f) {
            var g = [],
              y = v(function t(e, n) {
                var r,
                  o = [],
                  a = typeof e;
                if (n && "object" == a) for (r in e) try {
                  o.push(t(e[r], n - 1));
                } catch (t) { }
                return o.length ? o : "string" == a ? e : e + "\0";
              }((h = 1 == h ? {
                entropy: !0
              } : h || {}).entropy ? [t, m(e)] : null == t ? function () {
                try {
                  var t;
                  return r && (t = r.randomBytes) ? t = t(a) : (t = new Uint8Array(a), (o.crypto || o.msCrypto).getRandomValues(t)), m(t);
                } catch (t) {
                  var n = o.navigator,
                    i = n && n.plugins;
                  return [+new Date(), o, i, o.screen, m(e)];
                }
              }() : t, 3), g),
              x = new p(g),
              b = function () {
                for (var t = x.g(i), e = s, n = 0; t < c;) t = (t + n) * a, e *= a, n = x.g(1);

                for (; t >= l;) t /= 2, e /= 2, n >>>= 1;

                return (t + n) / e;
              };

            return b.int32 = function () {
              return 0 | x.g(4);
            }, b.quick = function () {
              return x.g(4) / 4294967296;
            }, b.double = b, v(m(x.S), e), (h.pass || f || function (t, e, r, o) {
              return o && (o.S && d(o, x), t.state = function () {
                return d(x, {});
              }), r ? (n[u] = t, e) : t;
            })(b, y, "global" in h ? h.global : this == n, h.state);
          }

          function p(t) {
            var e,
              n = t.length,
              r = this,
              o = 0,
              i = r.i = r.j = 0,
              u = r.S = [];

            for (n || (t = [n++]); o < a;) u[o] = o++;

            for (o = 0; o < a; o++) u[o] = u[i = h & i + t[o % n] + (e = u[o])], u[i] = e;

            (r.g = function (t) {
              for (var e, n = 0, o = r.i, i = r.j, u = r.S; t--;) e = u[o = h & o + 1], n = n * a + u[h & (u[o] = u[i = h & i + e]) + (u[i] = e)];

              return r.i = o, r.j = i, n;
            })(a);
          }

          function d(t, e) {
            return e.i = t.i, e.j = t.j, e.S = t.S.slice(), e;
          }

          function v(t, e) {
            for (var n, r = t + "", o = 0; o < r.length;) e[h & o] = h & (n ^= 19 * e[h & o]) + r.charCodeAt(o++);

            return m(e);
          }

          function m(t) {
            return String.fromCharCode.apply(0, t);
          }

          if (n["seed" + u] = f, v(n.random(), e), t.exports) {
            t.exports = f;

            try {
              r = require("crypto");
            } catch (t) { }
          }
        }([], Math);
      });
    nr.alea = Yn, nr.xor128 = Qn, nr.xorwow = Jn, nr.xorshift7 = Zn, nr.xor4096 = tr, nr.tychei = er;

    var rr = nr.alea,
      or = function () {
        function t(t, e, n, r, o) {
          this.mean = t, this.stdDev = e, this.dtype = n, this.nextVal = NaN, this.truncated = r, this.truncated && (this.upper = this.mean + 2 * this.stdDev, this.lower = this.mean - 2 * this.stdDev);
          var a = o || Math.random();
          this.random = rr(a.toString());
        }

        return t.prototype.nextValue = function () {
          if (!isNaN(this.nextVal)) {
            var t = this.nextVal;
            return this.nextVal = NaN, t;
          }

          for (var e, n, r = !1; !r;) {
            var o = void 0,
              a = void 0,
              i = void 0;

            do {
              i = (o = 2 * this.random() - 1) * o + (a = 2 * this.random() - 1) * a;
            } while (i >= 1 || 0 === i);

            var u = Math.sqrt(-2 * Math.log(i) / i);
            e = this.mean + this.stdDev * o * u, n = this.mean + this.stdDev * a * u, this.truncated && !this.isValidTruncated(e) || (r = !0);
          }

          return this.truncated && !this.isValidTruncated(n) || (this.nextVal = this.convertValue(n)), this.convertValue(e);
        }, t.prototype.convertValue = function (t) {
          return null == this.dtype || "float32" === this.dtype ? t : Math.round(t);
        }, t.prototype.isValidTruncated = function (t) {
          return t <= this.upper && t >= this.lower;
        }, t;
      }(),
      ar = function () {
        function t(t, e, n, r) {
          this.alpha = t, this.beta = 1 / e, this.dtype = n;
          var o = r || Math.random();
          this.randu = rr(o.toString()), this.randn = new or(0, 1, n, !1, this.randu()), this.d = t < 1 ? t + 2 / 3 : t - 1 / 3, this.c = 1 / Math.sqrt(9 * this.d);
        }

        return t.prototype.nextValue = function () {
          for (var t, e, n, r, o, a; ;) {
            do {
              r = this.randn.nextValue(), a = 1 + this.c * r;
            } while (a <= 0);

            if (a *= a * a, e = 1 - .331 * (t = r * r) * t, n = .5 * t + this.d * (1 - a + Math.log(a)), (o = this.randu()) < e || Math.log(o) < n) break;
          }

          return a = 1 / this.beta * this.d * a, this.alpha < 1 && (a *= Math.pow(this.randu(), 1 / this.alpha)), this.convertValue(a);
        }, t.prototype.convertValue = function (t) {
          return "float32" === this.dtype ? t : Math.round(t);
        }, t;
      }(),
      ir = function () {
        function t(t, e, n, r) {
          var o = this;
          if (void 0 === t && (t = 0), void 0 === e && (e = 1), this.canReturnFloat = function () {
            return null == o.dtype || "float32" === o.dtype;
          }, this.min = t, this.range = e - t, this.dtype = n, null == r && (r = Math.random()), "number" == typeof r && (r = r.toString()), !this.canReturnFloat() && this.range <= 1) throw new Error("The difference between " + t + " - " + e + " <= 1 and dtype is not float");
          this.random = rr(r);
        }

        return t.prototype.convertValue = function (t) {
          return this.canReturnFloat() ? t : Math.round(t);
        }, t.prototype.nextValue = function () {
          return this.convertValue(this.min + this.range * this.random());
        }, t;
      }();

    function ur(t, e, n) {
      return void 0 === e && (e = "float32"), e = e || "float32", Q(t), new lt(t, e, n);
    }

    function sr(t, e) {
      void 0 === e && (e = !1), console.log(t.toString(e));
    }

    var cr = Cn({
      batchToSpaceND_: function (t, e, n) {
        var r = ln(t, "x", "batchToSpaceND"),
          o = e.reduce(function (t, e) {
            return t * e;
          });
        return g(r.rank >= 1 + e.length, function () {
          return "input rank is " + r.rank + " but should be > than blockShape.length " + e.length;
        }), g(n.length === e.length, function () {
          return "crops.length is " + n.length + " but should be equal to blockShape.length  " + e.length;
        }), g(r.shape[0] % o == 0, function () {
          return "input tensor batch is " + r.shape[0] + " but is not divisible by the product of the elements of blockShape " + e.join(" * ") + " === " + o;
        }), Nt.runKernelFunc(function (t) {
          return t.batchToSpaceND(r, e, n);
        }, {
          $x: r
        }, function (t) {
          return {
            $x: function () {
              return t.spaceToBatchND(e, n);
            }
          };
        });
      }
    }),
      lr = Cn({
        cast_: function (t, e) {
          var n = ln(t, "x", "cast");
          if (!_(e)) throw new Error("Failed to cast to unknown dtype " + e);
          if ("string" === e && "string" !== n.dtype || "string" !== e && "string" === n.dtype) throw new Error("Only strings can be casted to strings");
          var r = {
            dtype: e
          };
          return Nt.runKernelFunc(function (t) {
            return t.cast(n, e);
          }, {
            x: n
          }, function (t) {
            return {
              x: function () {
                return t.clone();
              }
            };
          }, "Cast", r);
        }
      }),
      hr = Cn({
        clone_: function (t) {
          var e = ln(t, "x", "clone", null);
          return Nt.runKernelFunc(function () {
            return Nt.makeTensorFromDataId(e.dataId, e.shape, e.dtype);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return t.toFloat();
              }
            };
          });
        }
      }),
      fr = Cn({
        cumsum_: function (t, e, n, r) {
          void 0 === e && (e = 0), void 0 === n && (n = !1), void 0 === r && (r = !1);
          var o = ln(t, "x", "cumsum"),
            a = gn([e |= 0], o.rank),
            i = o;
          null != a && (i = o.transpose(a));
          var u = xn(1, o.rank)[0],
            s = Nt.runKernelFunc(function (t) {
              return t.cumsum(i, u, n, r);
            }, {
              permutedX: i
            }, function (t) {
              return {
                permutedX: function () {
                  return t.cumsum(e, n, !r);
                }
              };
            });
          return null != a && (s = s.transpose(a)), s;
        }
      }),
      pr = Cn({
        depthToSpace_: function (t, e, n) {
          void 0 === n && (n = "NHWC");
          var r = ln(t, "x", "depthToSpace"),
            o = "NHWC" === n ? r.shape[1] : r.shape[2],
            a = "NHWC" === n ? r.shape[2] : r.shape[3],
            i = "NHWC" === n ? r.shape[3] : r.shape[1];
          return g(o * e >= 0, function () {
            return "Negative dimension size caused by overflow when multiplying\n      " + o + " and " + e + "  for depthToSpace with input shape\n      " + r.shape;
          }), g(a * e >= 0, function () {
            return "Negative dimension size caused by overflow when multiplying\n      " + a + " and " + e + " for depthToSpace with input shape\n          " + r.shape;
          }), g(i % (e * e) == 0, function () {
            return "Dimension size must be evenly divisible by " + e * e + " but is " + i + " for depthToSpace with input shape " + r.shape;
          }), Nt.runKernelFunc(function (t) {
            return t.depthToSpace(r, e, n);
          }, {
            $x: r
          });
        }
      }),
      dr = Cn({
        expandDims_: function (t, e) {
          void 0 === e && (e = 0);
          var n = ln(t, "x", "expandDims", null);
          g(e <= n.rank, function () {
            return "Axis must be <= rank of the tensor";
          });
          var r = n.shape.slice();
          return e < 0 && (g(-(n.rank + 1) <= e, function () {
            return "Axis must be in the interval [" + -(n.rank + 1) + ", " + n.rank + "]";
          }), e = n.rank + e + 1), r.splice(e, 0, 1), Sr(n, r);
        }
      }),
      vr = Cn({
        eye_: function (t, e, n, r) {
          void 0 === r && (r = "float32"), null == e && (e = t);

          for (var o = ur([t, e], r), a = t <= e ? t : e, i = 0; i < a; ++i) o.set(1, i, i);

          var u = o.toTensor().as2D(t, e);
          if (null == n) return u;
          if (1 === n.length) return Nr(dr(u, 0), [n[0], 1, 1]);
          if (2 === n.length) return Nr(dr(dr(u, 0), 0), [n[0], n[1], 1, 1]);
          if (3 === n.length) return Nr(dr(dr(dr(u, 0), 0), 0), [n[0], n[1], n[2], 1, 1]);
          throw new Error("eye() currently supports only 1D and 2D batchShapes, but received " + n.length + "D.");
        }
      }),
      mr = Cn({
        multinomial_: function (t, e, n, r) {
          void 0 === r && (r = !1);
          var o = ln(t, "logits", "multinomial"),
            a = o.size,
            i = o.rank;
          if (a < 2) throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + a + ".");
          if (i > 2) throw new Error("Rank of probabilities must be 1 or 2, but is " + i);
          n = n || Math.random();
          var u = 1 === i ? o.as2D(1, -1) : o,
            s = Nt.runKernelFunc(function (t) {
              return t.multinomial(u, r, e, n);
            }, {
              logits2D: u
            });
          return 1 === i ? s.as1D() : s;
        }
      }),
      gr = Cn({
        oneHot_: function (t, e, n, r) {
          if (void 0 === n && (n = 1), void 0 === r && (r = 0), e < 2) throw new Error("Error in oneHot: depth must be >=2, but it is " + e);
          var o = ln(t, "indices", "oneHot", "int32"),
            a = o.shape.concat([e]);
          return o = o.flatten(), Nt.runKernelFunc(function (t) {
            return t.oneHot(o, e, n, r);
          }, {
            $indices: o
          }, function (t) {
            return {
              $indices: function () {
                return Pn(o.shape, "float32");
              }
            };
          }).reshape(a);
        }
      }),
      yr = Cn({
        pad_: function (t, e, n) {
          void 0 === n && (n = 0);
          var r = ln(t, "x", "pad");
          if (0 === r.rank) throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");
          var o = e.map(function (t) {
            return t[0];
          });
          return Nt.runKernelFunc(function (t) {
            return t.pad(r, e, n);
          }, {
            $x: r
          }, function (t) {
            return {
              $x: function () {
                return t.slice(o, r.shape);
              }
            };
          });
        }
      }),
      xr = Cn({
        pad1d_: function (t, e, n) {
          return void 0 === n && (n = 0), g(2 === e.length, function () {
            return "Invalid number of paddings. Must be length of 2.";
          }), yr(t, [e], n);
        }
      }),
      br = Cn({
        pad2d_: function (t, e, n) {
          return void 0 === n && (n = 0), g(2 === e.length && 2 === e[0].length && 2 === e[1].length, function () {
            return "Invalid number of paddings. Must be length of 2 each.";
          }), yr(t, e, n);
        }
      }),
      wr = Cn({
        pad3d_: function (t, e, n) {
          return void 0 === n && (n = 0), g(3 === e.length && 2 === e[0].length && 2 === e[1].length && 2 === e[2].length, function () {
            return "Invalid number of paddings. Must be length of 2 each.";
          }), yr(t, e, n);
        }
      }),
      Cr = Cn({
        pad4d_: function (t, e, n) {
          return void 0 === n && (n = 0), g(4 === e.length && 2 === e[0].length && 2 === e[1].length && 2 === e[2].length && 2 === e[3].length, function () {
            return "Invalid number of paddings. Must be length of 2 each.";
          }), yr(t, e, n);
        }
      }),
      Er = Cn({
        rand_: function (t, e, n) {
          var r = w(t),
            o = null;
          if (null == n || "float32" === n) o = new Float32Array(r); else if ("int32" === n) o = new Int32Array(r); else {
            if ("bool" !== n) throw new Error("Unknown data type " + n);
            o = new Uint8Array(r);
          }

          for (var a = 0; a < r; a++) o[a] = e();

          return Nt.makeTensor(o, t, n);
        }
      }),
      Rr = Cn({
        randomNormal_: function (t, e, n, r, o) {
          if (void 0 === e && (e = 0), void 0 === n && (n = 1), null != r && "bool" === r) throw new Error("Unsupported data type " + r);

          for (var a = new or(e, n, r, !1, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();

          return i.toTensor();
        }
      }),
      Ir = Cn({
        randomGamma_: function (t, e, n, r, o) {
          if (void 0 === n && (n = 1), void 0 === r && (r = "float32"), null == n && (n = 1), null == r && (r = "float32"), "float32" !== r && "int32" !== r) throw new Error("Unsupported data type " + r);

          for (var a = new ar(e, n, r, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();

          return i.toTensor();
        }
      }),
      kr = Cn({
        randomUniform_: function (t, e, n, r, o) {
          void 0 === e && (e = 0), void 0 === n && (n = 1), void 0 === r && (r = "float32");

          for (var a = ur(t, r), i = new ir(e, n, null, o), u = 0; u < a.values.length; u++) a.values[u] = i.nextValue();

          return a.toTensor();
        }
      }),
      Sr = Cn({
        reshape_: function (t, e) {
          var n = ln(t, "x", "reshape", null);
          e = A(e, n.size), g(n.size === w(e), function () {
            return "new shape and old shape must have the same number of elements.";
          });
          var r = {
            shape: e
          };
          return Nt.runKernelFunc(function (t) {
            return t.reshape(n, e);
          }, {
            x: n
          }, function (t) {
            return {
              x: function () {
                return t.reshape(n.shape);
              }
            };
          }, "Reshape", r);
        }
      }),
      Ar = Cn({
        spaceToBatchND_: function (t, e, n) {
          var r = ln(t, "x", "spaceToBatchND");
          return g(r.rank >= 1 + e.length, function () {
            return "input rank " + r.rank + " should be > than [blockShape] " + e.length;
          }), g(n.length === e.length, function () {
            return "paddings.shape[0] " + n.length + " must be equal to [blockShape] " + e.length;
          }), g(r.shape.reduce(function (t, r, o) {
            return o > 0 && o <= e.length ? t && (r + n[o - 1][0] + n[o - 1][1]) % e[o - 1] == 0 : t;
          }, !0), function () {
            return "input spatial dimensions " + r.shape.slice(1) + " with paddings " + n.toString() + " must be divisible by blockShapes " + e.toString();
          }), Nt.runKernelFunc(function (t) {
            return t.spaceToBatchND(r, e, n);
          }, {
            $x: r
          }, function (t) {
            return {
              $x: function () {
                return t.batchToSpaceND(e, n);
              }
            };
          });
        }
      }),
      Dr = Cn({
        squeeze_: function (t, e) {
          var n = ln(t, "x", "squeeze");
          return Sr(n, T(n.shape, e).newShape);
        }
      }),
      Tr = Cn({
        stack_: function (t, e) {
          void 0 === e && (e = 0);
          var n = hn(t, "tensors", "stack");
          if (g(n.length >= 1, function () {
            return "Pass at least one tensor to tf.stack";
          }), 1 === n.length) return n[0].expandDims(e);
          var r = n[0].rank,
            o = n[0].shape,
            a = n[0].dtype;
          g(e <= r, function () {
            return "Axis must be <= rank of the tensor";
          }), n.forEach(function (t) {
            y(o, t.shape, "All tensors passed to stack must have matching shapes");
          }), n.forEach(function (t) {
            g(a === t.dtype, function () {
              return "All tensors passed to stack must have matching dtypes";
            });
          });
          var i = n.map(function (t) {
            return t.expandDims(e);
          });
          return Gn(i, e);
        }
      }),
      Nr = Cn({
        tile_: function (t, e) {
          var n = ln(t, "x", "tile", null);
          return g(n.rank === e.length, function () {
            return "Error in transpose: rank of input " + n.rank + " must match length of reps " + e + ".";
          }), Nt.runKernelFunc(function (t, r) {
            var o = t.tile(n, e);
            return r([n]), o;
          }, {
            $x: n
          }, function (t, n) {
            var r = n[0];
            return {
              $x: function () {
                var n = zn(r);
                if (1 === r.rank) for (var o = 0; o < e[0]; ++o) n = n.add(t.slice([o * r.shape[0]], [r.shape[0]])); else if (2 === r.rank) for (o = 0; o < e[0]; ++o) for (var a = 0; a < e[1]; ++a) n = n.add(t.slice([o * r.shape[0], a * r.shape[1]], [r.shape[0], r.shape[1]])); else if (3 === r.rank) for (o = 0; o < e[0]; ++o) for (a = 0; a < e[1]; ++a) for (var i = 0; i < e[2]; ++i) n = n.add(t.slice([o * r.shape[0], a * r.shape[1], i * r.shape[2]], [r.shape[0], r.shape[1], r.shape[2]])); else {
                  if (4 !== r.rank) throw new Error("Gradient for tile operation is not implemented for rank-" + r.rank + " tensors yet.");

                  for (o = 0; o < e[0]; ++o) for (a = 0; a < e[1]; ++a) for (i = 0; i < e[2]; ++i) for (var u = 0; u < e[3]; ++u) n = n.add(t.slice([o * r.shape[0], a * r.shape[1], i * r.shape[2], u * r.shape[3]], [r.shape[0], r.shape[1], r.shape[2], r.shape[3]]));
                }
                return n;
              }
            };
          });
        }
      }),
      Fr = Cn({
        truncatedNormal_: function (t, e, n, r, o) {
          if (void 0 === e && (e = 0), void 0 === n && (n = 1), null != r && "bool" === r) throw new Error("Unsupported data type " + r);

          for (var a = new or(e, n, r, !0, o), i = ur(t, r), u = 0; u < i.values.length; u++) i.values[u] = a.nextValue();

          return i.toTensor();
        }
      }),
      Or = Cn({
        unstack_: function (t, e) {
          void 0 === e && (e = 0), e = e || 0;
          var n = ln(t, "x", "unstack");
          return g(e >= -n.shape.length && e < n.shape.length, function () {
            return "Axis = " + e + " is not in [-" + n.shape.length + ", " + n.shape.length + ")";
          }), e < 0 && (e += n.shape.length), Nt.runKernelFunc(function (t) {
            return t.unstack(n, e);
          }, {
            $x: n
          }, function (t) {
            return {
              $x: function () {
                return Tr(t, e);
              }
            };
          });
        }
      }),
      _r = function (t, e) {
        return n(this, void 0, void 0, function () {
          var n, o, a, i, u, s, c, l, h, f;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return n = ln(t, "x", "setdiff1d"), o = ln(e, "y", "setdiff1d"), g(n.dtype === o.dtype, function () {
                  return "x and y should have the same dtype, but got x (" + n.dtype + ") and y (" + o.dtype + ").";
                }), g(1 === n.rank, function () {
                  return "x should be 1D tensor, but got x (" + n.shape + ").";
                }), g(1 === o.rank, function () {
                  return "y should be 1D tensor, but got y (" + o.shape + ").";
                }), [4, n.data()];

              case 1:
                return a = r.sent(), [4, o.data()];

              case 2:
                for (i = r.sent(), u = new Set(i), s = 0, h = 0; h < a.length; h++) u.has(a[h]) || s++;

                for (c = new lt([s], n.dtype), l = new lt([s], "int32"), h = 0, f = 0; h < a.length; h++) u.has(a[h]) || (c.values[f] = a[h], l.values[f] = h, f++);

                return [2, [c.toTensor(), l.toTensor()]];
            }
          });
        });
      };

    exports.setdiff1dAsync = _r;
    exports.unstack = Or;
    exports.truncatedNormal = Fr;
    exports.tile = Nr;
    exports.stack = Tr;
    exports.squeeze = Dr;
    exports.spaceToBatchND = Ar;
    exports.reshape = Sr;
    exports.randomUniform = kr;
    exports.randomGamma = Ir;
    exports.randomNormal = Rr;
    exports.rand = Er;
    exports.pad4d = Cr;
    exports.pad3d = wr;
    exports.pad2d = br;
    exports.pad1d = xr;
    exports.pad = yr;
    exports.oneHot = gr;
    exports.multinomial = mr;
    exports.eye = vr;
    exports.expandDims = dr;
    exports.depthToSpace = pr;
    exports.cumsum = fr;
    exports.clone = hr;
    exports.cast = lr;
    exports.batchToSpaceND = cr;

    function Mr(t, e, n, r) {
      void 0 === r && (r = !0);
      var o = [];
      if (r) (o = o.concat(e.slice(0))).push(t[0] / n), o = o.concat(t.slice(1)); else {
        o = o.concat(t[0]);

        for (var a = e.length, i = 0; i < a; ++i) o = o.concat([t[i + 1] / e[i], e[i]]);

        o = o.concat(t.slice(a + 1));
      }
      return o;
    }

    function Br(t, e, n) {
      void 0 === n && (n = !0);
      var r = [];

      if (n) {
        r.push(e);

        for (var o = e + 1; o < t; ++o) o <= 2 * e ? (r.push(o), r.push(o - (e + 1))) : r.push(o);
      } else {
        var a = [],
          i = [];

        for (o = 1; o < t; ++o) o >= 2 * e + 1 || o % 2 == 1 ? i.push(o) : a.push(o);

        r.push.apply(r, a), r.push(0), r.push.apply(r, i);
      }

      return r;
    }

    function Pr(t, e, n, r) {
      void 0 === r && (r = !0);
      var o = [];
      r ? o.push(t[0] / n) : o.push(t[0] * n);

      for (var a = 1; a < t.length; ++a) a <= e.length ? r ? o.push(e[a - 1] * t[a]) : o.push(t[a] / e[a - 1]) : o.push(t[a]);

      return o;
    }

    function Lr(t, e) {
      for (var n = [0], r = 0; r < e; ++r) n.push(t[r][0]);

      return n;
    }

    function Wr(t, e, n) {
      for (var r = t.slice(0, 1), o = 0; o < n; ++o) r.push(t[o + 1] - e[o][0] - e[o][1]);

      return r;
    }

    function Ur(t, e) {
      if (t.rank < 1) throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was " + t.rank + ".");
      if (e.rank < 1) throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was " + e.rank + ".");
      if ("int32" !== e.dtype) throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was " + e.dtype + ".");
      if (e.shape[e.rank - 1] > t.rank) throw new Error("index innermost dimension length must be <= tensor rank; saw: " + e.shape[e.rank - 1] + " vs. " + t.rank);
      if (0 === t.size) throw new Error("Requested more than 0 entries, but input is empty. Input shape: " + t.shape + ".");

      for (var n = e.shape, r = n[n.length - 1], o = 1, a = 0; a < n.length - 1; ++a) o *= n[a];

      var i = t.shape,
        u = n.slice();
      u.pop();
      var s = 1;

      for (a = r; a < t.rank; ++a) s *= i[a], u.push(i[a]);

      var c = q(t.shape).map(function (t) {
        return t / s;
      }).concat([1]).slice(0, r);
      return [u, o, s, c];
    }

    var Vr = 30;

    function zr(t) {
      return t <= Vr ? t : H(t, Math.floor(Math.sqrt(t)));
    }

    function Gr(t, e, n) {
      if (e.rank < 1) throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was " + e.rank + ".");
      if (t.rank < 1) throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was " + t.rank + ".");
      if ("int32" !== e.dtype) throw new Error("The dtype of 'indices' should be int32, but got dtype: " + e.dtype);
      if (n.length < 1) throw new Error("Output rank must be greater or equal to 1, but got shape: " + n);

      if (0 === n.length) {
        if (0 === e.size) throw new Error("Indices specified for empty output. indices shape: " + e.shape);
        if (0 === t.size) throw new Error("Updates specified for empty output. updates shape: " + t.shape);
      }

      !function (t, e, n) {
        var r = e.rank > 1 ? e.shape[e.rank - 1] : 1,
          o = e.rank > 1 ? e.rank - 1 : 1,
          a = "Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: " + n.shape + ", indices.shape: " + e.shape + ", shape: " + t + ", sliceDim: " + r + ", and batchDim: " + o + ".";
        if (n.rank < o) throw new Error(a + " update.rank < " + o + ". ");
        if (t.length < r + (n.rank - o)) throw new Error(a + " Output shape length < " + (r + (n.rank - o)));
        if (n.rank !== o + t.length - r) throw new Error(a + " update.rank != " + (o + t.length - r));

        for (var i = 0; i < o; ++i) if (n.shape[i] !== e.shape[i]) throw new Error(a + " updates.shape[" + i + "] (" + n.shape[i] + ") != indices.shape[" + i + "] (" + e.shape[i] + ").");

        for (i = 0; i < n.rank - o; ++i) if (n.shape[i + o] !== t[i + r]) throw new Error(a + " updates.shape[" + (i + o) + "] (" + n.shape[i + o] + ") != shape[" + (i + o) + "] (" + t[i + o] + ")");
      }(n, e, t);
    }

    function Hr(t, e, n) {
      for (var r = e.rank > 1 ? e.shape[e.rank - 1] : 1, o = n.length, a = 1, i = r; i < o; ++i) a *= n[i];

      var u = r < 1 ? 1 : r;
      return {
        sliceRank: r,
        numUpdates: e.size / u,
        sliceSize: a,
        strides: q(n.slice(0, r)).concat([1]),
        outputSize: w(n)
      };
    }

    function qr(t, e, n) {
      g(t.rank === e.length, function () {
        return "Error in slice" + t.rank + "D: Length of begin " + e + " must match the rank of the array (" + t.rank + ").";
      }), g(t.rank === n.length, function () {
        return "Error in slice" + t.rank + "D: Length of size " + n + " must match the rank of the array (" + t.rank + ").";
      });

      for (var r = function (r) {
        g(e[r] + n[r] <= t.shape[r], function () {
          return "Error in slice" + t.rank + "D: begin[" + r + "] + size[" + r + "] (" + (e[r] + n[r]) + ") would overflow input.shape[" + r + "] (" + t.shape[r] + ")";
        });
      }, o = 0; o < t.rank; ++o) r(o);
    }

    function Kr(t) {
      for (var e = [], n = 0; t > 0;) 1 & t && e.push(n), t /= 2, n++;

      return e;
    }

    function jr(t, e, n) {
      for (var r = [], o = 0; o < t.length; o++) r[o] = Math.ceil((e[o] - t[o]) / n[o]);

      return r;
    }

    function Xr(t, e, n, r, o) {
      var a = e[o],
        i = n[o] || 1;
      (t & 1 << o || null == a) && (a = i > 0 ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER);
      var u = r[o];
      return a < 0 && (a += u), a = d(0, a, u - 1);
    }

    function $r(t, e, n, r, o) {
      var a = e[o],
        i = n[o] || 1;
      (t & 1 << o || null == a) && (a = i > 0 ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER);
      var u = r[o];
      return a < 0 && (a += u), a = i > 0 ? d(0, a, u) : d(-1, a, u - 1);
    }

    function Yr(t, e, n) {
      for (var r = n.length, o = 0; o < n.length; o++) if (n[o] > 1) {
        r = o;
        break;
      }

      for (o = r + 1; o < n.length; o++) if (e[o] > 0 || n[o] !== t[o]) return !1;

      return !0;
    }

    function Qr(t, e) {
      for (var n = t.length > 0 ? t[t.length - 1] : 1, r = 0; r < t.length - 1; r++) n += t[r] * e[r];

      return n;
    }

    var Jr = Object.freeze({
      assertParamsValid: qr,
      maskToAxes: Kr,
      computeOutShape: jr,
      startForAxis: Xr,
      stopForAxis: $r,
      isSliceContinous: Yr,
      computeFlatOffset: Qr
    });
    exports.slice_util = Jr;

    function Zr(t) {
      return g(G(t), function () {
        return "The f passed in grad(f) must be a function";
      }), function (e, n) {
        var r = ln(e, "x", "tf.grad", null),
          o = null != n ? ln(n, "dy", "tf.grad") : null;
        return Nt.tidy(function () {
          var e = Nt.gradients(function () {
            return t(r);
          }, [r], o),
            n = e.value,
            a = e.grads;
          return null != o && y(n.shape, o.shape, "The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"), ao(a), a[0];
        });
      };
    }

    function to(t) {
      return g(G(t), function () {
        return "The f passed in grads(f) must be a function";
      }), function (e, n) {
        g(Array.isArray(e), function () {
          return "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s";
        });
        var r = hn(e, "args", "tf.grads", null),
          o = null != n ? ln(n, "dy", "tf.grads") : null;
        return Nt.tidy(function () {
          var e = Nt.gradients(function () {
            return t.apply(void 0, r);
          }, r, o),
            n = e.value,
            a = e.grads;
          return null != o && y(n.shape, o.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(a), a;
        });
      };
    }

    function eo(t) {
      return g(G(t), function () {
        return "The f passed in valueAndGrad(f) must be a function";
      }), function (e, n) {
        g(e instanceof dt, function () {
          return "The x passed in valueAndGrad(f)(x) must be a tensor";
        }), g(null == n || n instanceof dt, function () {
          return "The dy passed in valueAndGrad(f)(x, dy) must be a tensor";
        });
        var r = Nt.gradients(function () {
          return t(e);
        }, [e], n),
          o = r.grads,
          a = r.value;
        return ao(o), {
          grad: o[0],
          value: a
        };
      };
    }

    function no(t) {
      return g(G(t), function () {
        return "The f passed in valueAndGrads(f) must be a function";
      }), function (e, n) {
        g(Array.isArray(e) && e.every(function (t) {
          return t instanceof dt;
        }), function () {
          return "The args passed in valueAndGrads(f)(args) must be array of tensors";
        }), g(null == n || n instanceof dt, function () {
          return "The dy passed in valueAndGrads(f)(args, dy) must be a tensor";
        });
        var r = Nt.gradients(function () {
          return t.apply(void 0, e);
        }, e, n);
        return null != n && y(r.value.shape, n.shape, "The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(r.grads), r;
      };
    }

    function ro(t, e) {
      g(G(t), function () {
        return "The f passed in variableGrads(f) must be a function";
      }), g(null == e || Array.isArray(e) && e.every(function (t) {
        return t instanceof bt;
      }), function () {
        return "The varList passed in variableGrads(f, varList) must be an array of variables";
      });
      var n = null != e;
      if (!n) for (var r in e = [], Nt.registeredVariables) e.push(Nt.registeredVariables[r]);
      var o = n ? e.filter(function (t) {
        return !t.trainable;
      }) : null,
        a = e.length;
      g((e = e.filter(function (t) {
        return t.trainable;
      })).length > 0, function () {
        return "variableGrads() expects at least one of the input variables to be trainable, but none of the " + a + " variables is trainable.";
      });
      var i = Nt.gradients(t, e, null, !0),
        u = i.value,
        s = i.grads;
      g(s.some(function (t) {
        return null != t;
      }), function () {
        return "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize().";
      }), g(0 === u.rank, function () {
        return "The f passed in variableGrads(f) must return a scalar, but it returned a rank-" + u.rank + " tensor";
      });
      var c = {};
      return e.forEach(function (t, e) {
        null != s[e] && (c[t.name] = s[e]);
      }), null != o && o.forEach(function (t) {
        return c[t.name] = null;
      }), {
        value: u,
        grads: c
      };
    }

    function oo(t) {
      return Nt.customGrad(t);
    }

    function ao(t) {
      if (t.filter(function (t) {
        return null == t;
      }).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 io = Cn({
      softmax_: function (t, e) {
        void 0 === e && (e = -1);
        var n = ln(t, "logits", "softmax");
        if (-1 === e && (e = n.rank - 1), e !== n.rank - 1) throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank " + n.rank + " and dim was " + e);
        return oo(function (t, n) {
          var r = t.logSumExp([e], !0),
            o = t.toFloat().sub(r).exp();
          return n([o]), {
            value: o,
            gradFunc: function (t, n) {
              var r = n[0],
                o = t.mul(r);
              return o.sub(o.sum([e], !0).mul(r));
            }
          };
        })(n);
      }
    }),
      uo = Cn({
        logSoftmax_: function (t, e) {
          void 0 === e && (e = -1);
          var n = ln(t, "logits", "logSoftmax");
          if (-1 === e && (e = n.rank - 1), e !== n.rank - 1) throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank " + n.rank + " and axis was " + e);
          return oo(function (t, n) {
            var r = t.max(e, !0),
              o = t.sub(r),
              a = o.toFloat().sub(o.exp().sum(e, !0).log());
            return n([a]), {
              value: a,
              gradFunc: function (t, n) {
                var r = n[0].exp();
                return t.sub(t.sum(e, !0).mul(r));
              }
            };
          })(n);
        }
      }),
      so = function () {
        function t(t, e) {
          this.backend = t, this.dataMover = e, this.data = new WeakMap(), this.dataIdsCount = 0;
        }

        return t.prototype.get = function (t) {
          return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t);
        }, t.prototype.set = function (t, e) {
          this.dataIdsCount++, this.data.set(t, e);
        }, t.prototype.has = function (t) {
          return this.data.has(t);
        }, t.prototype.delete = function (t) {
          return this.dataIdsCount--, this.data.delete(t);
        }, t.prototype.numDataIds = function () {
          return this.dataIdsCount;
        }, t;
      }(),
      co = function () {
        function t() { }

        return t.prototype.time = function (t) {
          return lo();
        }, t.prototype.read = function (t) {
          return lo();
        }, t.prototype.readSync = function (t) {
          return lo();
        }, t.prototype.numDataIds = function () {
          return lo();
        }, t.prototype.disposeData = function (t) {
          return lo();
        }, t.prototype.fromPixels = function (t, e) {
          return lo();
        }, t.prototype.write = function (t, e, n) {
          return lo();
        }, t.prototype.move = function (t, e, n, r) {
          return lo();
        }, t.prototype.memory = function () {
          return lo();
        }, t.prototype.floatPrecision = function () {
          return lo();
        }, t.prototype.epsilon = function () {
          return 32 === this.floatPrecision() ? 1e-7 : 1e-4;
        }, t.prototype.batchMatMul = function (t, e, n, r) {
          return lo();
        }, t.prototype.fusedBatchMatMul = function (t) {
          t.a, t.b, t.transposeA, t.transposeB, t.bias, t.activation, t.preluActivationWeights;
          return lo();
        }, t.prototype.slice = function (t, e, n) {
          return lo();
        }, t.prototype.stridedSlice = function (t, e, n, r) {
          return lo();
        }, t.prototype.unstack = function (t, e) {
          return lo();
        }, t.prototype.reverse = function (t, e) {
          return lo();
        }, t.prototype.concat = function (t, e) {
          return lo();
        }, t.prototype.neg = function (t) {
          return lo();
        }, t.prototype.add = function (t, e) {
          return lo();
        }, t.prototype.addN = function (t) {
          return lo();
        }, t.prototype.subtract = function (t, e) {
          return lo();
        }, t.prototype.multiply = function (t, e) {
          return lo();
        }, t.prototype.realDivide = function (t, e) {
          return lo();
        }, t.prototype.floorDiv = function (t, e) {
          return lo();
        }, t.prototype.sum = function (t, e) {
          return lo();
        }, t.prototype.prod = function (t, e) {
          return lo();
        }, t.prototype.unsortedSegmentSum = function (t, e, n) {
          return lo();
        }, t.prototype.argMin = function (t, e) {
          return lo();
        }, t.prototype.argMax = function (t, e) {
          return lo();
        }, t.prototype.equal = function (t, e) {
          return lo();
        }, t.prototype.notEqual = function (t, e) {
          return lo();
        }, t.prototype.less = function (t, e) {
          return lo();
        }, t.prototype.lessEqual = function (t, e) {
          return lo();
        }, t.prototype.greater = function (t, e) {
          return lo();
        }, t.prototype.greaterEqual = function (t, e) {
          return lo();
        }, t.prototype.logicalNot = function (t) {
          return lo();
        }, t.prototype.logicalAnd = function (t, e) {
          return lo();
        }, t.prototype.logicalOr = function (t, e) {
          return lo();
        }, t.prototype.where = function (t) {
          return lo();
        }, t.prototype.select = function (t, e, n) {
          return lo();
        }, t.prototype.topk = function (t, e, n) {
          return lo();
        }, t.prototype.min = function (t, e) {
          return lo();
        }, t.prototype.minimum = function (t, e) {
          return lo();
        }, t.prototype.mod = function (t, e) {
          return lo();
        }, t.prototype.max = function (t, e) {
          return lo();
        }, t.prototype.maximum = function (t, e) {
          return lo();
        }, t.prototype.all = function (t, e) {
          return lo();
        }, t.prototype.any = function (t, e) {
          return lo();
        }, t.prototype.squaredDifference = function (t, e) {
          return lo();
        }, t.prototype.ceil = function (t) {
          return lo();
        }, t.prototype.floor = function (t) {
          return lo();
        }, t.prototype.round = function (t) {
          return lo();
        }, t.prototype.sign = function (t) {
          return lo();
        }, t.prototype.isNaN = function (t) {
          return lo();
        }, t.prototype.isInf = function (t) {
          return lo();
        }, t.prototype.isFinite = function (t) {
          return lo();
        }, t.prototype.pow = function (t, e) {
          return lo();
        }, t.prototype.exp = function (t) {
          return lo();
        }, t.prototype.expm1 = function (t) {
          return lo();
        }, t.prototype.log = function (t) {
          return lo();
        }, t.prototype.log1p = function (t) {
          return lo();
        }, t.prototype.sqrt = function (t) {
          return lo();
        }, t.prototype.rsqrt = function (t) {
          return lo();
        }, t.prototype.square = function (t) {
          return lo();
        }, t.prototype.reciprocal = function (t) {
          return lo();
        }, t.prototype.relu = function (t) {
          return lo();
        }, t.prototype.relu6 = function (t) {
          return lo();
        }, t.prototype.prelu = function (t, e) {
          return lo();
        }, t.prototype.elu = function (t) {
          return lo();
        }, t.prototype.eluDer = function (t, e) {
          return lo();
        }, t.prototype.selu = function (t) {
          return lo();
        }, t.prototype.int = function (t) {
          return lo();
        }, t.prototype.clip = function (t, e, n) {
          return lo();
        }, t.prototype.abs = function (t) {
          return lo();
        }, t.prototype.complexAbs = function (t) {
          return lo();
        }, t.prototype.sigmoid = function (t) {
          return lo();
        }, t.prototype.softplus = function (t) {
          return lo();
        }, t.prototype.sin = function (t) {
          return lo();
        }, t.prototype.cos = function (t) {
          return lo();
        }, t.prototype.tan = function (t) {
          return lo();
        }, t.prototype.asin = function (t) {
          return lo();
        }, t.prototype.acos = function (t) {
          return lo();
        }, t.prototype.atan = function (t) {
          return lo();
        }, t.prototype.atan2 = function (t, e) {
          return lo();
        }, t.prototype.sinh = function (t) {
          return lo();
        }, t.prototype.cosh = function (t) {
          return lo();
        }, t.prototype.tanh = function (t) {
          return lo();
        }, t.prototype.asinh = function (t) {
          return lo();
        }, t.prototype.acosh = function (t) {
          return lo();
        }, t.prototype.atanh = function (t) {
          return lo();
        }, t.prototype.erf = function (t) {
          return lo();
        }, t.prototype.step = function (t, e) {
          return lo();
        }, t.prototype.fusedConv2d = function (t) {
          t.input, t.filter, t.convInfo, t.bias, t.activation, t.preluActivationWeights;
          return lo();
        }, t.prototype.conv2d = function (t, e, n) {
          return lo();
        }, t.prototype.conv2dDerInput = function (t, e, n) {
          return lo();
        }, t.prototype.conv2dDerFilter = function (t, e, n) {
          return lo();
        }, t.prototype.fusedDepthwiseConv2D = function (t) {
          t.input, t.filter, t.convInfo, t.bias, t.activation, t.preluActivationWeights;
          return lo();
        }, t.prototype.depthwiseConv2D = function (t, e, n) {
          return lo();
        }, t.prototype.depthwiseConv2DDerInput = function (t, e, n) {
          return lo();
        }, t.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
          return lo();
        }, t.prototype.conv3d = function (t, e, n) {
          return lo();
        }, t.prototype.conv3dDerInput = function (t, e, n) {
          return lo();
        }, t.prototype.conv3dDerFilter = function (t, e, n) {
          return lo();
        }, t.prototype.maxPool = function (t, e) {
          return lo();
        }, t.prototype.maxPoolBackprop = function (t, e, n, r) {
          return lo();
        }, t.prototype.avgPool = function (t, e) {
          return lo();
        }, t.prototype.avgPoolBackprop = function (t, e, n) {
          return lo();
        }, t.prototype.avgPool3d = function (t, e) {
          return lo();
        }, t.prototype.avgPool3dBackprop = function (t, e, n) {
          return lo();
        }, t.prototype.maxPool3d = function (t, e) {
          return lo();
        }, t.prototype.maxPool3dBackprop = function (t, e, n, r) {
          return lo();
        }, t.prototype.reshape = function (t, e) {
          return lo();
        }, t.prototype.cast = function (t, e) {
          return lo();
        }, t.prototype.tile = function (t, e) {
          return lo();
        }, t.prototype.pad = function (t, e, n) {
          return lo();
        }, t.prototype.transpose = function (t, e) {
          return lo();
        }, t.prototype.gather = function (t, e, n) {
          return lo();
        }, t.prototype.gatherND = function (t, e) {
          return lo();
        }, t.prototype.scatterND = function (t, e, n) {
          return lo();
        }, t.prototype.batchToSpaceND = function (t, e, n) {
          return lo();
        }, t.prototype.spaceToBatchND = function (t, e, n) {
          return lo();
        }, t.prototype.resizeBilinear = function (t, e, n, r) {
          return lo();
        }, t.prototype.resizeBilinearBackprop = function (t, e, n) {
          return lo();
        }, t.prototype.resizeNearestNeighbor = function (t, e, n, r) {
          return lo();
        }, t.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
          return lo();
        }, t.prototype.batchNormalization = function (t, e, n, r, o, a) {
          return lo();
        }, t.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
          return lo();
        }, t.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
          return lo();
        }, t.prototype.multinomial = function (t, e, n, r) {
          return lo();
        }, t.prototype.oneHot = function (t, e, n, r) {
          return lo();
        }, t.prototype.cumsum = function (t, e, n, r) {
          return lo();
        }, t.prototype.nonMaxSuppression = function (t, e, n, r, o) {
          return lo();
        }, t.prototype.fft = function (t) {
          return lo();
        }, t.prototype.ifft = function (t) {
          return lo();
        }, t.prototype.complex = function (t, e) {
          return lo();
        }, t.prototype.real = function (t) {
          return lo();
        }, t.prototype.imag = function (t) {
          return lo();
        }, t.prototype.cropAndResize = function (t, e, n, r, o, a) {
          return lo();
        }, t.prototype.depthToSpace = function (t, e, n) {
          return lo();
        }, t.prototype.split = function (t, e, n) {
          return lo();
        }, t.prototype.sparseToDense = function (t, e, n, r) {
          return lo();
        }, t.prototype.diag = function (t) {
          return lo();
        }, t.prototype.fill = function (t, e, n) {
          throw new Error("Not yet implemented.");
        }, t.prototype.onesLike = function (t) {
          return lo();
        }, t.prototype.zerosLike = function (t) {
          return lo();
        }, t.prototype.linspace = function (t, e, n) {
          return lo();
        }, t.prototype.dispose = function () {
          return lo();
        }, t;
      }();

    exports.KernelBackend = co;
    exports.DataStorage = so;
    exports.logSoftmax = uo;
    exports.softmax = io;

    function lo() {
      throw new Error("Not yet implemented or not found in the registry. Did you forget to import the kernel?");
    }

    function ho(t, e) {
      for (var n = t.length, r = [], o = 0; o < n; o++) {
        var a = n - 1 - o,
          i = t[a] || 1;
        (e[e.length - 1 - o] || 1) > 1 && 1 === i && r.unshift(a);
      }

      return r;
    }

    function fo(t, e) {
      for (var n = [], r = 0; r < e.length; r++) {
        var o = t[t.length - r - 1],
          a = e.length - r - 1,
          i = e[a];
        (null == o || 1 === o && i > 1) && n.unshift(a);
      }

      return n;
    }

    function po(t, e) {
      for (var n = [], r = Math.max(t.length, e.length), o = 0; o < r; o++) {
        var a = t[t.length - o - 1];
        null == a && (a = 1);
        var i = e[e.length - o - 1];
        if (null == i && (i = 1), 1 === a) n.unshift(i); else if (1 === i) n.unshift(a); else {
          if (a !== i) throw Error("Operands could not be broadcast together with shapes " + t + " and " + e + ".");
          n.unshift(a);
        }
      }

      return n;
    }

    function vo(t, e, n, r, o, a, i) {
      void 0 === i && (i = "channelsLast");
      var u,
        s = bo(e),
        c = s[0],
        l = s[1];
      if ("channelsLast" === i) u = [c, l, t[3], t[3]]; else {
        if ("channelsFirst" !== i) throw new Error("Unknown dataFormat " + i);
        u = [c, l, t[1], t[1]];
      }
      return go(t, u, n, r, o, a, !1, i);
    }

    function mo(t, e, n, r, o, a, i) {
      void 0 === i && (i = "NDHWC");
      var u,
        s,
        c = wo(e),
        l = c[0],
        h = c[1],
        f = c[2];
      if ("NDHWC" === i) s = "channelsLast", u = [l, h, f, t[4], t[4]]; else {
        if ("NCDHW" !== i) throw new Error("Unknown dataFormat " + i);
        s = "channelsFirst", u = [l, h, f, t[1], t[1]];
      }
      return yo(t, u, n, r, o, !1, s, a);
    }

    function go(t, e, n, r, o, a, i, u) {
      void 0 === i && (i = !1), void 0 === u && (u = "channelsLast");
      var s = [-1, -1, -1, -1],
        c = s[0],
        l = s[1],
        h = s[2],
        f = s[3];
      if ("channelsLast" === u) c = t[0], l = t[1], h = t[2], f = t[3]; else {
        if ("channelsFirst" !== u) throw new Error("Unknown dataFormat " + u);
        c = t[0], f = t[1], l = t[2], h = t[3];
      }

      var p,
        d = e[0],
        v = e[1],
        m = e[3],
        y = bo(n),
        x = y[0],
        b = y[1],
        w = bo(r),
        C = w[0],
        R = w[1],
        I = Co(d, C),
        k = Co(v, R),
        S = function (t, e, n, r, o, a, i, u) {
          var s, c, l;

          if ("number" == typeof t) {
            var h = 0 === t ? "VALID" : "NUMBER";
            s = {
              top: t,
              bottom: t,
              left: t,
              right: t,
              type: h
            };

            var f = function (t, e, n, r, o) {
              null == r && (r = xo(t, e, n));
              var a = t[0],
                i = t[1],
                u = Eo((a - e + 2 * r) / n + 1, o);
              g(E(u), function () {
                return "The output # of rows (" + u + ") must be an integer. Change the stride and/or zero pad parameters";
              });
              var s = Eo((i - e + 2 * r) / n + 1, o);
              return g(E(s), function () {
                return "The output # of columns (" + s + ") must be an integer. Change the stride and/or zero pad parameters";
              }), [u, s];
            }([e, n], a, r, t, u);

            c = f[0], l = f[1];
          } else if ("same" === t) {
            c = Math.ceil(e / r), l = Math.ceil(n / o);
            var p = Math.max(0, (c - 1) * r + a - e),
              d = Math.max(0, (l - 1) * o + i - n),
              v = Math.floor(p / 2),
              m = p - v,
              y = Math.floor(d / 2),
              x = d - y;
            s = {
              top: v,
              bottom: m,
              left: y,
              right: x,
              type: "SAME"
            };
          } else {
            if ("valid" !== t) throw Error("Unknown padding parameter: " + t);
            s = {
              top: 0,
              bottom: 0,
              left: 0,
              right: 0,
              type: "VALID"
            }, c = Math.ceil((e - a + 1) / r), l = Math.ceil((n - i + 1) / o);
          }

          return {
            padInfo: s,
            outHeight: c,
            outWidth: l
          };
        }(o, l, h, x, b, I, k, a),
        A = S.padInfo,
        D = S.outHeight,
        T = S.outWidth,
        N = i ? m * f : m;

      return "channelsFirst" === u ? p = [c, N, D, T] : "channelsLast" === u && (p = [c, D, T, N]), {
        batchSize: c,
        dataFormat: u,
        inHeight: l,
        inWidth: h,
        inChannels: f,
        outHeight: D,
        outWidth: T,
        outChannels: N,
        padInfo: A,
        strideHeight: x,
        strideWidth: b,
        filterHeight: d,
        filterWidth: v,
        effectiveFilterHeight: I,
        effectiveFilterWidth: k,
        dilationHeight: C,
        dilationWidth: R,
        inShape: t,
        outShape: p,
        filterShape: e
      };
    }

    function yo(t, e, n, r, o, a, i, u) {
      void 0 === a && (a = !1), void 0 === i && (i = "channelsLast");
      var s = [-1, -1, -1, -1, -1],
        c = s[0],
        l = s[1],
        h = s[2],
        f = s[3],
        p = s[4];
      if ("channelsLast" === i) c = t[0], l = t[1], h = t[2], f = t[3], p = t[4]; else {
        if ("channelsFirst" !== i) throw new Error("Unknown dataFormat " + i);
        c = t[0], p = t[1], l = t[2], h = t[3], f = t[4];
      }

      var d,
        v = e[0],
        m = e[1],
        y = e[2],
        x = e[4],
        b = wo(n),
        w = b[0],
        C = b[1],
        R = b[2],
        I = wo(r),
        k = I[0],
        S = I[1],
        A = I[2],
        D = Co(v, k),
        T = Co(m, S),
        N = Co(y, A),
        F = function (t, e, n, r, o, a, i, u, s, c, l) {
          var h, f, p, d;

          if ("number" == typeof t) {
            var v = 0 === t ? "VALID" : "NUMBER";
            h = {
              top: t,
              bottom: t,
              left: t,
              right: t,
              front: t,
              back: t,
              type: v
            };

            var m = function (t, e, n, r, o, a) {
              null == o && (o = xo(t, e, r));
              var i = t[0],
                u = t[1],
                s = t[2],
                c = Eo((i - e + 2 * o) / r + 1, a);
              g(E(c), function () {
                return "The output # of depths (" + c + ") must be an integer. Change the stride and/or zero pad parameters";
              });
              var l = Eo((u - e + 2 * o) / r + 1, a);
              g(E(l), function () {
                return "The output # of rows (" + l + ") must be an integer. Change the stride and/or zero pad parameters";
              });
              var h = Eo((s - e + 2 * o) / r + 1, a);
              return g(E(h), function () {
                return "The output # of columns (" + h + ") must be an integer. Change the stride and/or zero pad parameters";
              }), [c, l, h, n];
            }([e, n, r, 1], u, 1, o, t, l);

            f = m[0], p = m[1], d = m[2];
          } else if ("same" === t) {
            f = Math.ceil(e / o), p = Math.ceil(n / a), d = Math.ceil(r / i);
            var y = (f - 1) * o + u - e,
              x = (p - 1) * a + s - n,
              b = (d - 1) * i + c - r,
              w = Math.floor(y / 2),
              C = y - w,
              R = Math.floor(x / 2),
              I = x - R,
              k = Math.floor(b / 2),
              S = b - k;
            h = {
              top: R,
              bottom: I,
              left: k,
              right: S,
              front: w,
              back: C,
              type: "SAME"
            };
          } else {
            if ("valid" !== t) throw Error("Unknown padding parameter: " + t);
            h = {
              top: 0,
              bottom: 0,
              left: 0,
              right: 0,
              front: 0,
              back: 0,
              type: "VALID"
            }, f = Math.ceil((e - u + 1) / o), p = Math.ceil((n - s + 1) / a), d = Math.ceil((r - c + 1) / i);
          }

          return {
            padInfo: h,
            outDepth: f,
            outHeight: p,
            outWidth: d
          };
        }(o, l, h, f, w, C, R, D, T, N, u),
        O = F.padInfo,
        _ = F.outDepth,
        M = F.outHeight,
        B = F.outWidth,
        P = a ? x * p : x;

      return "channelsFirst" === i ? d = [c, P, _, M, B] : "channelsLast" === i && (d = [c, _, M, B, P]), {
        batchSize: c,
        dataFormat: i,
        inDepth: l,
        inHeight: h,
        inWidth: f,
        inChannels: p,
        outDepth: _,
        outHeight: M,
        outWidth: B,
        outChannels: P,
        padInfo: O,
        strideDepth: w,
        strideHeight: C,
        strideWidth: R,
        filterDepth: v,
        filterHeight: m,
        filterWidth: y,
        effectiveFilterDepth: D,
        effectiveFilterHeight: T,
        effectiveFilterWidth: N,
        dilationDepth: k,
        dilationHeight: S,
        dilationWidth: A,
        inShape: t,
        outShape: d,
        filterShape: e
      };
    }

    function xo(t, e, n, r) {
      void 0 === r && (r = 1);
      var o = Co(e, r);
      return Math.floor((t[0] * (n - 1) - n + o) / 2);
    }

    function bo(t) {
      return "number" == typeof t ? [t, t, t] : 2 === t.length ? [t[0], t[1], 1] : t;
    }

    function wo(t) {
      return "number" == typeof t ? [t, t, t] : t;
    }

    function Co(t, e) {
      return e <= 1 ? t : t + (t - 1) * (e - 1);
    }

    function Eo(t, e) {
      if (!e) return t;

      switch (e) {
        case "round":
          return Math.round(t);

        case "ceil":
          return Math.ceil(t);

        case "floor":
          return Math.floor(t);

        default:
          throw new Error("Unknown roundingMode " + e);
      }
    }

    function Ro(t) {
      var e = bo(t),
        n = e[0],
        r = e[1],
        o = e[2];
      return 1 === n && 1 === r && 1 === o;
    }

    function Io(t, e) {
      return Ro(t) || Ro(e);
    }

    function ko(t) {
      if ("NHWC" === t) return "channelsLast";
      if ("NCHW" === t) return "channelsFirst";
      throw new Error("Unknown dataFormat " + t);
    }

    function So(t, e, n) {
      if ("complex64" === e) {
        if ("complex64" === t.dtype) return t.clone();
        var r = Pn(t.shape),
          o = t.toFloat(),
          a = n.complex(o, r);
        return r.dispose(), o.dispose(), a;
      }

      if (!M(t.dtype, e)) return Nt.makeTensorFromDataId(t.dataId, t.shape, e);

      if ("complex64" === t.dtype) {
        var i = n.real(t);
        a = i.cast(e);
        return i.dispose(), a;
      }

      if ("int32" === e) return n.int(t);

      if ("bool" === e) {
        var u = An(0, t.dtype);
        a = n.notEqual(t, u);
        return u.dispose(), a;
      }

      throw new Error("Error in Cast: failed to cast " + t.dtype + " to " + e);
    }

    function Ao(t, e) {
      return Nt.makeTensorFromDataId(t.dataId, e, t.dtype);
    }

    function Do(t, e, n) {
      var r = (e - t) / (n - 1),
        o = $(n, "float32");
      o[0] = t;

      for (var a = 1; a < o.length; a++) o[a] = o[a - 1] + r;

      return Dn(o, "float32");
    }

    var To = Object.freeze({
      castTensor: So,
      reshapeTensor: Ao,
      linspaceImpl: Do,
      upcastType: Ct,
      axesAreInnerMostDims: fn,
      combineLocations: pn,
      computeOutAndReduceShapes: dn,
      expandShapeToKeepDim: vn,
      assertAxesAreInnerMostDims: mn,
      getAxesPermutation: gn,
      getUndoAxesPermutation: yn,
      getInnerMostAxes: xn,
      getBroadcastDims: ho,
      getReductionAxes: fo,
      assertAndGetBroadcastShape: po,
      assertParamsConsistent: bn,
      computeOutShape: wn,
      computePool2DInfo: vo,
      computePool3DInfo: mo,
      computeConv2DInfo: go,
      computeConv3DInfo: yo,
      computeDefaultPad: xo,
      tupleValuesAreOne: Ro,
      eitherStridesOrDilationsAreOne: Io,
      convertConv2DDataFormat: ko
    });
    exports.backend_util = To;

    function No(t, e) {
      if (t.length !== e.length) throw new Error("Cannot merge real and imag arrays of different lengths. real:" + t.length + ", imag: " + e.length + ".");

      for (var n = new Float32Array(2 * t.length), r = 0; r < n.length; r += 2) n[r] = t[r / 2], n[r + 1] = e[r / 2];

      return n;
    }

    function Fo(t, e) {
      return {
        real: t[2 * e],
        imag: t[2 * e + 1]
      };
    }

    function Oo(t, e, n, r) {
      t[2 * r] = e, t[2 * r + 1] = n;
    }

    function _o(t, e, n) {
      var r = (n ? 2 : -2) * Math.PI * (t / e);
      return {
        real: Math.cos(r),
        imag: Math.sin(r)
      };
    }

    function Mo(t, e, n, r, o) {
      for (var a = Array.from(e).map(function (t, e) {
        return {
          score: t,
          boxIndex: e
        };
      }).filter(function (t) {
        return t.score > o;
      }).sort(function (t, e) {
        return e.score - t.score;
      }), i = [], u = 0; u < a.length; u++) {
        var s = a[u],
          c = s.score,
          l = s.boxIndex;
        if (c < o) break;

        for (var h = !1, f = i.length - 1; f >= 0; --f) {
          if (Bo(t, l, i[f]) >= r) {
            h = !0;
            break;
          }
        }

        if (!h && (i.push(l), i.length >= n)) break;
      }

      return Dn(i, "int32");
    }

    function Bo(t, e, n) {
      var r = t.subarray(4 * e, 4 * e + 4),
        o = t.subarray(4 * n, 4 * n + 4),
        a = Math.min(r[0], r[2]),
        i = Math.min(r[1], r[3]),
        u = Math.max(r[0], r[2]),
        s = Math.max(r[1], r[3]),
        c = Math.min(o[0], o[2]),
        l = Math.min(o[1], o[3]),
        h = Math.max(o[0], o[2]),
        f = Math.max(o[1], o[3]),
        p = (u - a) * (s - i),
        d = (h - c) * (f - l);
      if (p <= 0 || d <= 0) return 0;
      var v = Math.max(a, c),
        m = Math.max(i, l),
        g = Math.min(u, h),
        y = Math.min(s, f),
        x = Math.max(g - v, 0) * Math.max(y - m, 0);
      return x / (p + d - x);
    }

    function Po(t, e, n) {
      var r = new Array(t.rank).fill(0),
        o = t.shape.slice();
      return e.map(function (e) {
        o[n] = e;
        var a = t.slice(r, o);
        return r[n] += e, a;
      });
    }

    function Lo(t, e) {
      for (var n = new Array(t.rank), r = 0; r < n.length; r++) n[r] = t.shape[r] * e[r];

      var o = ur(n, t.dtype);

      for (r = 0; r < o.values.length; ++r) {
        for (var a = o.indexToLoc(r), i = new Array(t.rank), u = 0; u < i.length; u++) i[u] = a[u] % t.shape[u];

        var s = t.locToIndex(i);
        o.values[r] = t.values[s];
      }

      return o.toTensor();
    }

    function Wo(t, e, n, r, o) {
      for (var a = e[e.length - 1], i = [t.length / a, a], u = i[0], s = i[1], c = N(n, u * r), l = N("int32", u * r), h = 0; h < u; h++) {
        for (var f = h * s, p = t.subarray(f, f + s), d = [], v = 0; v < p.length; v++) d.push({
          value: p[v],
          index: v
        });

        d.sort(function (t, e) {
          return e.value - t.value;
        });
        var m = h * r,
          g = c.subarray(m, m + r),
          y = l.subarray(m, m + r);

        for (v = 0; v < r; v++) g[v] = d[v].value, y[v] = d[v].index;
      }

      var x = e.slice();
      return x[x.length - 1] = r, [kn(c, x, n), kn(l, x, "int32")];
    }

    function Uo(t, e) {
      for (var n = [], r = 0; r < e.length; r++) e[r] && n.push(r);

      var o = ur(t, "int32"),
        a = ur([n.length, t.length], "int32");

      for (r = 0; r < n.length; r++) {
        var i = o.indexToLoc(n[r]),
          u = r * t.length;
        a.values.set(i, u);
      }

      return a.toTensor();
    }

    var Vo = function () {
      return function (t, e) {
        this.outputShape = [], this.outputShape = t, this.variableNames = e.map(function (t, e) {
          return "T" + e;
        });
        var n = [];
        this.variableNames.forEach(function (t) {
          n.push("float v" + t + " = get" + t + "AtOutCoords();");
        });
        var r = this.variableNames.map(function (t) {
          return "v" + t;
        }).join(" + ");
        this.userCode = "\n      void main() {\n        " + n.join("\n        ") + "\n\n        float result = " + r + ";\n        setOutput(result);\n      }\n    ";
      };
    }(),
      zo = function () {
        return function (t, e) {
          this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.variableNames = e.map(function (t, e) {
            return "T" + e;
          });
          var n = [];
          this.variableNames.forEach(function (t) {
            n.push("vec4 v" + t + " = get" + t + "AtOutCoords();");
          });
          var r = this.variableNames.map(function (t) {
            return "v" + t;
          }).join(" + ");
          this.userCode = "\n      void main() {\n        " + n.join("\n        ") + "\n\n        vec4 result = " + r + ";\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Go = function () {
        return function (t, e, n) {
          this.variableNames = ["A"];
          var r = t.windowSize,
            o = t.batchSize,
            a = t.inSize,
            i = Math.ceil(a / r);
          n || this.variableNames.push("bestIndicesA"), this.outputShape = [o, i];
          var u = "max" === e ? ">" : "<",
            s = 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 = inOffset;\n        float bestValue = getA(batch, bestIndex);\n\n        for (int i = 0; i < " + r + "; i++) {\n          int inIdx = " + s + ";\n          float candidate = getA(batch, inIdx);\n          if (candidate " + u + " bestValue) {\n            bestValue = candidate;\n            bestIndex = inIdx;\n          }\n        }\n        setOutput(float(bestIndex));\n      }\n    ";
        };
      }();

    function Ho(t, e) {
      return ["x", "y", "z", "w", "u", "v"].slice(0, e).map(function (e) {
        return t + "." + e;
      });
    }

    function qo(t, e) {
      return 1 === e ? [t] : Ho(t, e);
    }

    function Ko() {
      var t, e, n, r, o, i, u, s, c, l;
      return 2 === a().getNumber("WEBGL_VERSION") ? (t = "#version 300 es", e = "in", n = "out", r = "in", o = "texture", i = "outputColor", u = "out vec4 outputColor;", s = "\n      bool isnan_custom(float val) {\n        return (val > 0.0 || val < 0.0) ? false : val != 0.0;\n      }\n\n      bvec4 isnan_custom(vec4 val) {\n        return bvec4(isnan_custom(val.x),\n          isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n      }\n\n      #define isnan(value) isnan_custom(value)\n    ", c = "", l = "\n      #define round(value) newRound(value)\n      int newRound(float value) {\n        return int(floor(value + 0.5));\n      }\n\n      ivec4 newRound(vec4 value) {\n        return ivec4(floor(value + vec4(0.5)));\n      }\n    ") : (t = "", e = "attribute", n = "varying", r = "varying", o = "texture2D", i = "gl_FragColor", u = "", s = "\n      #define isnan(value) isnan_custom(value)\n      bool isnan_custom(float val) {\n        return (val > 0. || val < 1. || val == 0.) ? false : true;\n      }\n      bvec4 isnan_custom(vec4 val) {\n        return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n      }\n    ", c = "\n      uniform float INFINITY;\n\n      bool isinf(float val) {\n        return abs(val) == INFINITY;\n      }\n      bvec4 isinf(vec4 val) {\n        return equal(abs(val), vec4(INFINITY));\n      }\n    ", l = "\n      int round(float value) {\n        return int(floor(value + 0.5));\n      }\n\n      ivec4 round(vec4 value) {\n        return ivec4(floor(value + vec4(0.5)));\n      }\n    "), {
        version: t,
        attribute: e,
        varyingVs: n,
        varyingFs: r,
        texture2D: o,
        output: i,
        defineOutput: u,
        defineSpecialNaN: s,
        defineSpecialInf: c,
        defineRound: l
      };
    }

    function jo(t, e, n) {
      void 0 === n && (n = "index");
      var r = q(e);
      return r.map(function (e, o) {
        return "int " + t[o] + " = " + n + " / " + e + "; " + (o === r.length - 1 ? "int " + t[o + 1] + " = " + n + " - " + t[o] + " * " + e : "index -= " + t[o] + " * " + e) + ";";
      }).join("");
    }

    function Xo(t) {
      var e = q(t).map(function (t) {
        return t.toString();
      });
      return "\n  int getFlatIndex(ivec3 coords) {\n    return coords.x * " + e[0] + " + coords.y * " + e[1] + " + coords.z;\n  }\n";
    }

    var $o = "\n  const float FLOAT_MAX = 1.70141184e38;\n  const float FLOAT_MIN = 1.17549435e-38;\n\n  lowp vec4 encode_float(highp float v) {\n    if (isnan(v)) {\n      return vec4(255, 255, 255, 255);\n    }\n\n    highp float av = abs(v);\n\n    if(av < FLOAT_MIN) {\n      return vec4(0.0, 0.0, 0.0, 0.0);\n    } else if(v > FLOAT_MAX) {\n      return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n    } else if(v < -FLOAT_MAX) {\n      return vec4(0.0, 0.0,  128.0, 255.0) / 255.0;\n    }\n\n    highp vec4 c = vec4(0,0,0,0);\n\n    highp float e = floor(log2(av));\n    highp float m = exp2(fract(log2(av))) - 1.0;\n\n    c[2] = floor(128.0 * m);\n    m -= c[2] / 128.0;\n    c[1] = floor(32768.0 * m);\n    m -= c[1] / 32768.0;\n    c[0] = floor(8388608.0 * m);\n\n    highp float ebias = e + 127.0;\n    c[3] = floor(ebias / 2.0);\n    ebias -= c[3] * 2.0;\n    c[2] += floor(ebias) * 128.0;\n\n    c[3] += 128.0 * step(0.0, -v);\n\n    return c / 255.0;\n  }\n";

    function Yo(t, e, n, r) {
      var o = [];
      t.forEach(function (t) {
        var e = w(t.shapeInfo.logicalShape);
        t.shapeInfo.isUniform ? o.push("uniform float " + t.name + (e > 1 ? "[" + e + "]" : "") + ";") : (o.push("uniform sampler2D " + t.name + ";"), o.push("uniform int offset" + t.name + ";"));
      });

      var a,
        i,
        u = o.join("\n"),
        s = t.map(function (t) {
          return function (t, e, n) {
            void 0 === n && (n = !1);
            var r = "";
            r += n ? Jo(t) : Qo(t);
            var o = t.shapeInfo.logicalShape,
              a = e.logicalShape;
            o.length <= a.length && (r += n ? function (t, e) {
              var n,
                r = t.name,
                o = r.charAt(0).toUpperCase() + r.slice(1),
                a = "get" + o + "AtOutCoords",
                i = t.shapeInfo.logicalShape.length,
                u = e.logicalShape.length,
                s = ho(t.shapeInfo.logicalShape, e.logicalShape),
                c = aa(u),
                l = u - i,
                h = ["x", "y", "z", "w", "u", "v"];
              n = 0 === i ? "" : u < 2 && s.length >= 1 ? "coords = 0;" : s.map(function (t) {
                return "coords." + h[t + l] + " = 0;";
              }).join("\n");
              var f = "";
              f = u < 2 && i > 0 ? "coords" : t.shapeInfo.logicalShape.map(function (t, e) {
                return "coords." + h[e + l];
              }).join(", ");
              var p = "return outputValue;",
                d = 1 === w(t.shapeInfo.logicalShape),
                v = 1 === w(e.logicalShape);

              if (1 !== i || d || v) {
                if (d && !v) p = 1 === u ? "\n        return vec4(outputValue.x, outputValue.x, 0., 0.);\n      " : "\n        return vec4(outputValue.x);\n      "; else if (s.length) {
                  var m = i - 2,
                    g = i - 1;
                  s.indexOf(m) > -1 && s.indexOf(g) > -1 ? p = "return vec4(outputValue.x);" : s.indexOf(m) > -1 ? p = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : s.indexOf(g) > -1 && (p = "return vec4(outputValue.xx, outputValue.zz);");
                }
              } else p = "\n      return vec4(outputValue.xy, outputValue.xy);\n    ";

              return "\n    vec4 " + a + "() {\n      " + c + " coords = getOutputCoords();\n      " + n + "\n      vec4 outputValue = get" + o + "(" + f + ");\n      " + p + "\n    }\n  ";
            }(t, e) : function (t, e) {
              var n = t.name,
                r = n.charAt(0).toUpperCase() + n.slice(1),
                o = "get" + r + "AtOutCoords",
                a = e.texShape,
                i = t.shapeInfo.texShape,
                u = t.shapeInfo.logicalShape.length,
                s = e.logicalShape.length;
              if (!t.shapeInfo.isUniform && u === s && null == t.shapeInfo.flatOffset && C(i, a)) return "\n      float " + o + "() {\n        return sampleTexture(" + n + ", resultUV);\n      }\n    ";
              var c,
                l = aa(s),
                h = ho(t.shapeInfo.logicalShape, e.logicalShape),
                f = s - u,
                p = ["x", "y", "z", "w", "u", "v"];
              c = 0 === u ? "" : s < 2 && h.length >= 1 ? "coords = 0;" : h.map(function (t) {
                return "coords." + p[t + f] + " = 0;";
              }).join("\n");
              var d = "";
              d = s < 2 && u > 0 ? "coords" : t.shapeInfo.logicalShape.map(function (t, e) {
                return "coords." + p[e + f];
              }).join(", ");
              return "\n    float " + o + "() {\n      " + l + " coords = getOutputCoords();\n      " + c + "\n      return get" + r + "(" + d + ");\n    }\n  ";
            }(t, e));
            return r;
          }(t, e, r);
        }).join("\n"),
        c = e.texShape,
        l = Ko(),
        h = function (t) {
          return "\n    float sampleTexture(sampler2D textureSampler, vec2 uv) {\n      return " + t.texture2D + "(textureSampler, uv).r;\n    }\n  ";
        }(l),
        f = function (t) {
          return t.version + "\n    precision highp float;\n    precision highp int;\n    precision highp sampler2D;\n    " + t.varyingFs + " vec2 resultUV;\n    " + t.defineOutput + "\n    const vec2 halfCR = vec2(0.5, 0.5);\n\n    struct ivec5\n    {\n      int x;\n      int y;\n      int z;\n      int w;\n      int u;\n    };\n\n    struct ivec6\n    {\n      int x;\n      int y;\n      int z;\n      int w;\n      int u;\n      int v;\n    };\n\n    uniform float NAN;\n    " + t.defineSpecialNaN + "\n    " + t.defineSpecialInf + "\n    " + t.defineRound + "\n\n    int imod(int x, int y) {\n      return x - y * (x / y);\n    }\n\n    int idiv(int a, int b, float sign) {\n      int res = a / b;\n      int mod = imod(a, b);\n      if (sign < 0. && mod != 0) {\n        res -= 1;\n      }\n      return res;\n    }\n\n    //Based on the work of Dave Hoskins\n    //https://www.shadertoy.com/view/4djSRW\n    #define HASHSCALE1 443.8975\n    float random(float seed){\n      vec2 p = resultUV * seed;\n      vec3 p3  = fract(vec3(p.xyx) * HASHSCALE1);\n      p3 += dot(p3, p3.yzx + 19.19);\n      return fract((p3.x + p3.y) * p3.z);\n    }\n\n    " + Zo + "\n    " + ta + "\n    " + ea + "\n  ";
        }(l);

      return e.isPacked ? (a = function (t, e) {
        switch (t.length) {
          case 0:
            return "\n    int getOutputCoords() {\n      return 0;\n    }\n  ";

          case 1:
            return function (t, e) {
              var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)];
              if (1 === n[0]) return "\n      int getOutputCoords() {\n        return 2 * int(resultUV.x * " + n[1] + ".0);\n      }\n    ";
              if (1 === n[1]) return "\n      int getOutputCoords() {\n        return 2 * int(resultUV.y * " + n[0] + ".0);\n      }\n    ";
              return "\n    int getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + n[0] + ", " + n[1] + "));\n      return 2 * (resTexRC.x * " + n[1] + " + resTexRC.y);\n    }\n  ";
            }(0, e);

          case 2:
            return function (t, e) {
              var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)];
              if (C(t, e)) return "\n      ivec2 getOutputCoords() {\n        return 2 * ivec2(resultUV.yx * vec2(" + n[0] + ", " + n[1] + "));\n      }\n    ";
              var r = Math.ceil(t[1] / 2);
              return "\n    ivec2 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + n[0] + ", " + n[1] + "));\n\n      int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n      int r = 2 * (index / " + r + ");\n      int c = imod(index, " + r + ") * 2;\n\n      return ivec2(r, c);\n    }\n  ";
            }(t, e);

          case 3:
            return n = t, r = e, o = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)], a = Math.ceil(n[2] / 2), i = a * Math.ceil(n[1] / 2), "\n    ivec3 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + o[0] + ", " + o[1] + "));\n      int index = resTexRC.x * " + o[1] + " + resTexRC.y;\n\n      int b = index / " + i + ";\n      index -= b * " + i + ";\n\n      int r = 2 * (index / " + a + ");\n      int c = imod(index, " + a + ") * 2;\n\n      return ivec3(b, r, c);\n    }\n  ";

          default:
            return function (t, e) {
              for (var n = [Math.ceil(e[0] / 2), Math.ceil(e[1] / 2)], r = Math.ceil(t[t.length - 1] / 2), o = r * Math.ceil(t[t.length - 2] / 2), a = o, i = "", u = "b, r, c", s = 2; s < t.length - 1; s++) a *= t[t.length - s - 1], i = "\n      int b" + s + " = index / " + a + ";\n      index -= b" + s + " * " + a + ";\n    " + i, u = "b" + s + ", " + u;

              return "\n    ivec" + t.length + " getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + n[0] + ", " + n[1] + "));\n      int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n\n      " + i + "\n\n      int b = index / " + o + ";\n      index -= b * " + o + ";\n\n      int r = 2 * (index / " + r + ");\n      int c = imod(index, " + r + ") * 2;\n\n      return ivec" + t.length + "(" + u + ");\n    }\n  ";
            }(t, e);
        }

        var n, r, o, a, i;
      }(e.logicalShape, c), i = function (t) {
        return "\n    void setOutput(vec4 val) {\n      " + t.output + " = val;\n    }\n  ";
      }(l)) : (a = function (t, e) {
        switch (t.length) {
          case 0:
            return "\n    int getOutputCoords() {\n      return 0;\n    }\n  ";

          case 1:
            return function (t, e) {
              if (1 === e[0]) return "\n      int getOutputCoords() {\n        return int(resultUV.x * " + e[1] + ".0);\n      }\n    ";
              if (1 === e[1]) return "\n      int getOutputCoords() {\n        return int(resultUV.y * " + e[0] + ".0);\n      }\n    ";
              return "\n    int getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + e[0] + ", " + e[1] + "));\n      return resTexRC.x * " + e[1] + " + resTexRC.y;\n    }\n  ";
            }(0, e);

          case 2:
            return function (t, e) {
              if (C(t, e)) return "\n      ivec2 getOutputCoords() {\n        return ivec2(resultUV.yx * vec2(" + e[0] + ", " + e[1] + "));\n      }\n    ";
              if (1 === t[1]) return "\n      ivec2 getOutputCoords() {\n        ivec2 resTexRC = ivec2(resultUV.yx *\n                               vec2(" + e[0] + ", " + e[1] + "));\n        int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n        return ivec2(index, 0);\n      }\n    ";
              if (1 === t[0]) return "\n      ivec2 getOutputCoords() {\n        ivec2 resTexRC = ivec2(resultUV.yx *\n                               vec2(" + e[0] + ", " + e[1] + "));\n        int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n        return ivec2(0, index);\n      }\n    ";
              return "\n    ivec2 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + e[0] + ", " + e[1] + "));\n      int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n      int r = index / " + t[1] + ";\n      int c = index - r * " + t[1] + ";\n      return ivec2(r, c);\n    }\n  ";
            }(t, e);

          case 3:
            return n = e, r = jo(["r", "c", "d"], t), "\n    ivec3 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n                             vec2(" + n[0] + ", " + n[1] + "));\n      int index = resTexRC.x * " + n[1] + " + resTexRC.y;\n      " + r + "\n      return ivec3(r, c, d);\n    }\n  ";

          case 4:
            return function (t, e) {
              var n = jo(["r", "c", "d", "d2"], t);
              return "\n    ivec4 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n        vec2(" + e[0] + ", " + e[1] + "));\n      int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n      " + n + "\n      return ivec4(r, c, d, d2);\n    }\n  ";
            }(t, e);

          case 5:
            return function (t, e) {
              var n = jo(["r", "c", "d", "d2", "d3"], t);
              return "\n    ivec5 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx * vec2(" + e[0] + ",\n                             " + e[1] + "));\n\n      int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n\n      " + n + "\n\n      ivec5 outShape = ivec5(r, c, d, d2, d3);\n      return outShape;\n    }\n  ";
            }(t, e);

          case 6:
            return function (t, e) {
              var n = jo(["r", "c", "d", "d2", "d3", "d4"], t);
              return "\n    ivec6 getOutputCoords() {\n      ivec2 resTexRC = ivec2(resultUV.yx *\n        vec2(" + e[0] + ", " + e[1] + "));\n      int index = resTexRC.x * " + e[1] + " + resTexRC.y;\n\n      " + n + "\n\n      ivec6 result = ivec6(r, c, d, d2, d3, d4);\n      return result;\n    }\n  ";
            }(t, e);

          default:
            throw new Error(t.length + "-D output sampling is not yet supported");
        }

        var n, r;
      }(e.logicalShape, c), i = function (t) {
        return "\n    void setOutput(float val) {\n      " + t.output + " = vec4(val, 0, 0, 0);\n    }\n  ";
      }(l)), r && (f += na), [f, h, i, u, a, s, n].join("\n");
    }

    function Qo(t) {
      var e = t.shapeInfo.logicalShape;

      switch (e.length) {
        case 0:
          return function (t) {
            var e = t.name,
              n = "get" + e.charAt(0).toUpperCase() + e.slice(1);
            if (t.shapeInfo.isUniform) return "float " + n + "() {return " + e + ";}";
            var r = t.shapeInfo.texShape,
              o = r[0],
              a = r[1];
            if (1 === o && 1 === a) return "\n      float " + n + "() {\n        return sampleTexture(" + e + ", halfCR);\n      }\n    ";
            var i = t.shapeInfo.texShape,
              u = i[0],
              s = i[1],
              c = ra(e);
            return "\n    float " + n + "() {\n      vec2 uv = uvFromFlat(" + u + ", " + s + ", " + c + ");\n      return sampleTexture(" + e + ", uv);\n    }\n  ";
          }(t);

        case 1:
          return function (t) {
            var e = t.name,
              n = "get" + e.charAt(0).toUpperCase() + e.slice(1);
            if (t.shapeInfo.isUniform) return "\n      float " + n + "(int index) {\n        " + oa(t) + "\n      }\n    ";
            var r = t.shapeInfo.texShape,
              o = r[0],
              a = r[1];
            if (1 === a && 1 === o) return "\n      float " + n + "(int index) {\n        return sampleTexture(" + e + ", halfCR);\n      }\n    ";
            var i = ra(e);
            if (1 === a) return "\n      float " + n + "(int index) {\n        vec2 uv = vec2(0.5, (float(index + " + i + ") + 0.5) / " + o + ".0);\n        return sampleTexture(" + e + ", uv);\n      }\n    ";
            if (1 === o) return "\n      float " + n + "(int index) {\n        vec2 uv = vec2((float(index + " + i + ") + 0.5) / " + a + ".0, 0.5);\n        return sampleTexture(" + e + ", uv);\n      }\n    ";
            return "\n    float " + n + "(int index) {\n      vec2 uv = uvFromFlat(" + o + ", " + a + ", index + " + i + ");\n      return sampleTexture(" + e + ", uv);\n    }\n  ";
          }(t);

        case 2:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = t.shapeInfo.texShape;

            if (null != o && C(e, o)) {
              var a = o[0],
                i = o[1];
              return "\n    float " + r + "(int row, int col) {\n      vec2 uv = (vec2(col, row) + halfCR) / vec2(" + i + ".0, " + a + ".0);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
            }

            var u = T(e),
              s = u.newShape,
              c = u.keptDims,
              l = s;

            if (l.length < e.length) {
              var h = ia(t, l);
              return "\n      " + Qo(h) + "\n      float " + r + "(int row, int col) {\n        return " + r + "(" + ua(["row", "col"], c) + ");\n      }\n    ";
            }

            if (t.shapeInfo.isUniform) return "\n      float " + r + "(int row, int col) {\n        int index = round(dot(vec2(row, col), vec2(" + e[1] + ", 1)));\n        " + oa(t) + "\n      }\n    ";
            var f = o[0],
              p = o[1],
              d = ra(n);
            if (1 === p) return "\n    float " + r + "(int row, int col) {\n      float index = dot(vec3(row, col, " + d + "), vec3(" + e[1] + ", 1, 1));\n      vec2 uv = vec2(0.5, (index + 0.5) / " + f + ".0);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
            if (1 === f) return "\n    float " + r + "(int row, int col) {\n      float index = dot(vec3(row, col, " + d + "), vec3(" + e[1] + ", 1, 1));\n      vec2 uv = vec2((index + 0.5) / " + p + ".0, 0.5);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
            return "\n  float " + r + "(int row, int col) {\n    // Explicitly use integer operations as dot() only works on floats.\n    int index = row * " + e[1] + " + col + " + d + ";\n    vec2 uv = uvFromFlat(" + f + ", " + p + ", index);\n    return sampleTexture(" + n + ", uv);\n  }\n";
          }(t);

        case 3:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = e[1] * e[2],
              a = e[2],
              i = T(e),
              u = i.newShape,
              s = i.keptDims,
              c = u;

            if (c.length < e.length) {
              var l = ia(t, c);
              return "\n        " + Qo(l) + "\n        float " + r + "(int row, int col, int depth) {\n          return " + r + "(" + ua(["row", "col", "depth"], s) + ");\n        }\n      ";
            }

            if (t.shapeInfo.isUniform) return "\n      float " + r + "(int row, int col, int depth) {\n        int index = round(dot(vec3(row, col, depth),\n                          vec3(" + o + ", " + a + ", 1)));\n        " + oa(t) + "\n      }\n    ";
            var h = t.shapeInfo.texShape,
              f = h[0],
              p = h[1],
              d = t.shapeInfo.flatOffset;
            if (p === o && null == d) return "\n        float " + r + "(int row, int col, int depth) {\n          float texR = float(row);\n          float texC = dot(vec2(col, depth), vec2(" + a + ", 1));\n          vec2 uv = (vec2(texC, texR) + halfCR) /\n                     vec2(" + p + ".0, " + f + ".0);\n          return sampleTexture(" + n + ", uv);\n        }\n      ";
            if (p === a && null == d) return "\n    float " + r + "(int row, int col, int depth) {\n      float texR = dot(vec2(row, col), vec2(" + e[1] + ", 1));\n      float texC = float(depth);\n      vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + p + ".0, " + f + ".0);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
            var v = ra(n);
            return "\n      float " + r + "(int row, int col, int depth) {\n        // Explicitly use integer operations as dot() only works on floats.\n        int index = row * " + o + " + col * " + a + " + depth + " + v + ";\n        vec2 uv = uvFromFlat(" + f + ", " + p + ", index);\n        return sampleTexture(" + n + ", uv);\n      }\n  ";
          }(t);

        case 4:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = e[3],
              a = e[2] * o,
              i = e[1] * a,
              u = T(e),
              s = u.newShape,
              c = u.keptDims;

            if (s.length < e.length) {
              var l = ia(t, s);
              return "\n      " + Qo(l) + "\n      float " + r + "(int row, int col, int depth, int depth2) {\n        return " + r + "(" + ua(["row", "col", "depth", "depth2"], c) + ");\n      }\n    ";
            }

            if (t.shapeInfo.isUniform) return "\n      float " + r + "(int row, int col, int depth, int depth2) {\n        int index = round(dot(vec4(row, col, depth, depth2),\n                          vec4(" + i + ", " + a + ", " + o + ", 1)));\n        " + oa(t) + "\n      }\n    ";
            var h = t.shapeInfo.flatOffset,
              f = t.shapeInfo.texShape,
              p = f[0],
              d = f[1];
            if (d === i && null == h) return "\n      float " + r + "(int row, int col, int depth, int depth2) {\n        float texR = float(row);\n        float texC =\n            dot(vec3(col, depth, depth2),\n                vec3(" + a + ", " + o + ", 1));\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                   vec2(" + d + ".0, " + p + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            if (d === o && null == h) return "\n      float " + r + "(int row, int col, int depth, int depth2) {\n        float texR = dot(vec3(row, col, depth),\n                         vec3(" + e[1] * e[2] + ", " + e[2] + ", 1));\n        float texC = float(depth2);\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                  vec2(" + d + ".0, " + p + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            var v = ra(n);
            return "\n    float " + r + "(int row, int col, int depth, int depth2) {\n      // Explicitly use integer operations as dot() only works on floats.\n      int index = row * " + i + " + col * " + a + " +\n          depth * " + o + " + depth2;\n      vec2 uv = uvFromFlat(" + p + ", " + d + ", index + " + v + ");\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
          }(t);

        case 5:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = e[4],
              a = e[3] * o,
              i = e[2] * a,
              u = e[1] * i,
              s = T(e),
              c = s.newShape,
              l = s.keptDims;

            if (c.length < e.length) {
              var h = ia(t, c);
              return "\n      " + Qo(h) + "\n      float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n        return " + r + "(" + ua(["row", "col", "depth", "depth2", "depth3"], l) + ");\n      }\n    ";
            }

            if (t.shapeInfo.isUniform) return "\n      float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n        float index = dot(\n          vec4(row, col, depth, depth2),\n          vec4(" + u + ", " + i + ", " + a + ", " + o + ")) +\n          depth3;\n        " + oa(t) + "\n      }\n    ";
            var f = t.shapeInfo.flatOffset,
              p = t.shapeInfo.texShape,
              d = p[0],
              v = p[1];
            if (v === u && null == f) return "\n      float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n        int texR = row;\n        float texC = dot(vec4(col, depth, depth2, depth3),\n                         vec4(" + i + ", " + a + ", " + o + ", 1));\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                   vec2(" + v + ".0, " + d + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            if (v === o && null == f) return "\n      float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n        float texR = dot(\n          vec4(row, col, depth, depth2),\n          vec4(" + e[1] * e[2] * e[3] + ",\n               " + e[2] * e[3] + ", " + e[3] + ", 1));\n        int texC = depth3;\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                  vec2(" + v + ".0, " + d + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            var m = ra(n);
            return "\n    float " + r + "(int row, int col, int depth, int depth2, int depth3) {\n      // Explicitly use integer operations as dot() only works on floats.\n      int index = row * " + u + " + col * " + i + " + depth * " + a + " +\n          depth2 * " + o + " + depth3 + " + m + ";\n      vec2 uv = uvFromFlat(" + d + ", " + v + ", index);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
          }(t);

        case 6:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = T(e),
              a = o.newShape,
              i = o.keptDims;

            if (a.length < e.length) {
              var u = ia(t, a);
              return "\n      " + Qo(u) + "\n      float " + r + "(int row, int col, int depth,\n                    int depth2, int depth3, int depth4) {\n        return " + r + "(" + ua(["row", "col", "depth", "depth2", "depth3", "depth4"], i) + ");\n      }\n    ";
            }

            var s = e[5],
              c = e[4] * s,
              l = e[3] * c,
              h = e[2] * l,
              f = e[1] * h;
            if (t.shapeInfo.isUniform) return "\n      float " + r + "(int row, int col, int depth,\n                  int depth2, int depth3, int depth4) {\n        int index = round(dot(\n          vec4(row, col, depth, depth2),\n          vec4(" + f + ", " + h + ", " + l + ", " + c + ")) +\n          dot(\n            vec2(depth3, depth4),\n            vec2(" + s + ", 1)));\n        " + oa(t) + "\n      }\n    ";
            var p = t.shapeInfo.flatOffset,
              d = t.shapeInfo.texShape,
              v = d[0],
              m = d[1];
            if (m === f && null == p) return "\n      float " + r + "(int row, int col, int depth,\n                    int depth2, int depth3, int depth4) {\n        int texR = row;\n        float texC = dot(vec4(col, depth, depth2, depth3),\n          vec4(" + h + ", " + l + ", " + c + ", " + s + ")) +\n               float(depth4);\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                   vec2(" + m + ".0, " + v + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            if (m === s && null == p) return "\n      float " + r + "(int row, int col, int depth,\n                    int depth2, int depth3, int depth4) {\n        float texR = dot(vec4(row, col, depth, depth2),\n          vec4(" + e[1] * e[2] * e[3] * e[4] + ",\n               " + e[2] * e[3] * e[4] + ",\n               " + e[3] * e[4] + ",\n               " + e[4] + ")) + float(depth3);\n        int texC = depth4;\n        vec2 uv = (vec2(texC, texR) + halfCR) /\n                  vec2(" + m + ".0, " + v + ".0);\n        return sampleTexture(" + n + ", uv);\n      }\n    ";
            var g = ra(n);
            return "\n    float " + r + "(int row, int col, int depth,\n                  int depth2, int depth3, int depth4) {\n      // Explicitly use integer operations as dot() only works on floats.\n      int index = row * " + f + " + col * " + h + " + depth * " + l + " +\n          depth2 * " + c + " + depth3 * " + s + " + depth4 + " + g + ";\n      vec2 uv = uvFromFlat(" + v + ", " + m + ", index);\n      return sampleTexture(" + n + ", uv);\n    }\n  ";
          }(t);

        default:
          throw new Error(e.length + "-D input sampling is not yet supported");
      }
    }

    function Jo(t) {
      var e, n, r;

      switch (t.shapeInfo.logicalShape.length) {
        case 0:
          return e = t.name, n = "get" + e.charAt(0).toUpperCase() + e.slice(1), r = Ko(), "\n    vec4 " + n + "() {\n      return " + r.texture2D + "(" + e + ", halfCR);\n    }\n  ";

        case 1:
          return function (t) {
            var e = t.name,
              n = "get" + e.charAt(0).toUpperCase() + e.slice(1),
              r = t.shapeInfo.texShape,
              o = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)],
              a = Ko();
            return "\n    vec4 " + n + "(int index) {\n      vec2 uv = packedUVfrom1D(\n        " + o[0] + ", " + o[1] + ", index);\n      return " + a.texture2D + "(" + e + ", uv);\n    }\n  ";
          }(t);

        case 2:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = t.shapeInfo.texShape,
              a = o[0],
              i = o[1],
              u = Ko();
            if (null != o && C(e, o)) return "\n      vec4 " + r + "(int row, int col) {\n        vec2 uv = (vec2(col, row) + halfCR) / vec2(" + i + ".0, " + a + ".0);\n\n        return " + u.texture2D + "(" + n + ", uv);\n      }\n    ";
            var s = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)],
              c = Math.ceil(e[1] / 2);
            return "\n    vec4 " + r + "(int row, int col) {\n      vec2 uv = packedUVfrom2D(" + c + ", " + s[0] + ", " + s[1] + ", row, col);\n      return " + u.texture2D + "(" + n + ", uv);\n    }\n  ";
          }(t);

        case 3:
          return function (t) {
            var e = t.shapeInfo.logicalShape,
              n = t.name,
              r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
              o = t.shapeInfo.texShape,
              a = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];

            if (1 === e[0]) {
              var i = e.slice(1),
                u = ia(t, i);
              return "\n        " + Jo(u) + "\n        vec4 " + r + "(int b, int row, int col) {\n          return " + r + "(" + ua(["b", "row", "col"], [1, 2]) + ");\n        }\n      ";
            }

            var s = a[0],
              c = a[1],
              l = Math.ceil(e[2] / 2),
              h = l * Math.ceil(e[1] / 2),
              f = Ko();
            return "\n    vec4 " + r + "(int b, int row, int col) {\n      vec2 uv = packedUVfrom3D(\n        " + s + ", " + c + ", " + h + ", " + l + ", b, row, col);\n      return " + f.texture2D + "(" + n + ", uv);\n    }\n  ";
          }(t);

        default:
          return function (t) {
            for (var e = t.shapeInfo.logicalShape, n = e.length, r = t.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = t.shapeInfo.texShape, i = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], u = i[0], s = i[1], c = Math.ceil(e[n - 1] / 2), l = c * Math.ceil(e[n - 2] / 2), h = "int b, int row, int col", f = "b * " + l + " + (row / 2) * " + c + " + (col / 2)", p = 2; p < n - 1; p++) h = "int b" + p + ", " + h, l *= e[n - p - 1], f = "b" + p + " * " + l + " + " + f;

            var d = Ko();
            return "\n    vec4 " + o + "(" + h + ") {\n      int index = " + f + ";\n      int texR = index / " + s + ";\n      int texC = index - texR * " + s + ";\n      vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + s + ", " + u + ");\n      return " + d.texture2D + "(" + r + ", uv);\n    }\n  ";
          }(t);
      }
    }

    var Zo = "\nvec2 uvFromFlat(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}\nvec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n  int texelIndex = index / 2;\n  int texR = texelIndex / texNumC;\n  int texC = texelIndex - texR * texNumC;\n  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
      ta = "\nvec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,\n  int texNumC, int row, int col) {\n  int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n  int texR = texelIndex / texNumC;\n  int texC = texelIndex - texR * texNumC;\n  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
      ea = "\nvec2 packedUVfrom3D(int texNumR, int texNumC,\n    int texelsInBatch, int texelsInLogicalRow, int b,\n    int row, int col) {\n  int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n  int texR = index / texNumC;\n  int texC = index - texR * texNumC;\n  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",
      na = "\n  float getChannel(vec4 frag, vec2 innerDims) {\n    vec2 modCoord = mod(innerDims, 2.);\n    return modCoord.x == 0. ?\n      (modCoord.y == 0. ? frag.r : frag.g) :\n      (modCoord.y == 0. ? frag.b : frag.a);\n  }\n  float getChannel(vec4 frag, int dim) {\n    float modCoord = mod(float(dim), 2.);\n    return modCoord == 0. ? frag.r : frag.g;\n  }\n";

    function ra(t) {
      return "offset" + t;
    }

    function oa(t) {
      var e = t.name,
        n = w(t.shapeInfo.logicalShape);
      return n < 2 ? "return " + e + ";" : "\n    for (int i = 0; i < " + n + "; i++) {\n      if (i == index) {\n        return " + e + "[i];\n      }\n    }\n  ";
    }

    function aa(t) {
      if (t <= 1) return "int";
      if (2 === t) return "ivec2";
      if (3 === t) return "ivec3";
      if (4 === t) return "ivec4";
      if (5 === t) return "ivec5";
      if (6 === t) return "ivec6";
      throw Error("GPU for rank " + t + " is not yet supported");
    }

    function ia(t, e) {
      var n = JSON.parse(JSON.stringify(t));
      return n.shapeInfo.logicalShape = e, n;
    }

    function ua(t, e) {
      return e.map(function (e) {
        return t[e];
      }).join(", ");
    }

    var sa = function () {
      return function (t, e, n, r) {
        this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, g(t.length > 2, function () {
          return "Packed arg" + (n.charAt(0).toUpperCase() + n.slice(1)) + " supports only inputs with rank above 2.";
        });
        var o = t[t.length - 1],
          a = Math.ceil(o / e);
        this.outputShape = t.slice(0, -1), a > 1 && this.outputShape.push(a), r || this.variableNames.push("bestIndicesA");
        var i,
          u,
          s = this.outputShape,
          c = s.length,
          l = aa(c),
          h = qo("coords", c);

        if (1 === a) {
          var f = aa(u = c + 1);
          i = "\n        " + f + " sourceLocR = " + f + "(" + h.join() + ", 0);\n        ++" + h[c - 1] + ";\n        " + f + " sourceLocG = " + f + "(" + h.join() + ", 0);\n        ++" + h[c - 2] + ";\n        " + f + " sourceLocA = " + f + "(" + h.join() + ", 0);\n        --" + h[c - 1] + ";\n        " + f + " sourceLocB = " + f + "(" + h.join() + ", 0);\n        --" + h[c - 2] + ";";
        } else u = c, i = "\n        " + l + " sourceLocR = coords;\n        ++" + h[c - 1] + ";\n        " + l + " sourceLocG = coords;\n        ++" + h[c - 2] + ";\n        " + l + " sourceLocA = coords;\n        --" + h[c - 1] + ";\n        " + l + " sourceLocB = coords;\n        --" + h[c - 2] + ";";

        var p = ["x", "y", "z", "w", "u", "v"].slice(0, u),
          d = "." + p[u - 1],
          v = p.map(function (t) {
            return "int " + t;
          }),
          m = qo("sourceLocR", u - 1).concat("inIdx.r"),
          y = qo("sourceLocG", u - 1).concat("inIdx.g"),
          x = qo("sourceLocB", u - 1).concat("inIdx.b"),
          b = qo("sourceLocA", u - 1).concat("inIdx.a"),
          w = "max" === n ? "greaterThan" : "lessThan",
          C = r ? "" : "\n          inIdx = round(vec4(getBestIndicesAChannel(" + m.join() + "),\n                             getBestIndicesAChannel(" + y.join() + "),\n                             getBestIndicesAChannel(" + x.join() + "),\n                             getBestIndicesAChannel(" + b.join() + ")));",
          E = "vec4(\n            getAChannel(" + m.join() + "),\n            hasNextCol ? getAChannel(" + y.join() + ") : 0.,\n            hasNextRow ? getAChannel(" + x.join() + ") : 0.,\n            hasNextRow && hasNextCol ? getAChannel(" + b.join() + ") : 0.)",
          R = r ? "" : "\n      float getBestIndicesAChannel(" + v.join() + ") {\n        return getChannel(getBestIndicesA(" + p.join() + "),\n                                          vec2(" + p.slice(-2).join() + "));\n      }";
        this.userCode = "\n      float getAChannel(" + v.join() + ") {\n        return getChannel(getA(" + p.join() + "),\n                               vec2(" + p.slice(-2).join() + "));\n      }\n      " + R + "\n      void main() {\n        " + l + " coords = getOutputCoords();\n        bool hasNextCol = " + h[c - 1] + " < " + (s[c - 1] - 1) + ";\n        bool hasNextRow = " + h[c - 2] + " < " + (s[c - 2] - 1) + ";\n        " + i + "\n        ivec4 srcIdx = ivec4(sourceLocR" + d + ", sourceLocG" + d + ",\n          sourceLocB" + d + ", sourceLocA" + d + ") * " + e + ";\n        ivec4 inIdx = srcIdx;\n        vec4 bestIndex = vec4(inIdx);\n        vec4 bestValue = " + E + ";\n\n        for (int i = 0; i < " + e + "; i++) {\n          inIdx = srcIdx;\n          " + C + "\n          vec4 candidate = " + E + ";\n          bvec4 nan = isnan(candidate);\n          bvec4 replace = bvec4(\n            vec4(" + w + "(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));\n\n          bestValue = vec4(replace.x  ? candidate.x : bestValue.x,\n                           replace.y  ? candidate.y : bestValue.y,\n                           replace.z  ? candidate.z : bestValue.z,\n                           replace.w  ? candidate.w : bestValue.w);\n          bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));\n          srcIdx++;\n        }\n        setOutput(bestIndex);\n      }\n    ";
      };
    }(),
      ca = function () {
        return function (t) {
          this.variableNames = ["dy"], this.outputShape = t.inShape;
          var e = t.filterHeight,
            n = t.filterWidth,
            r = t.strideHeight,
            o = t.strideWidth,
            a = t.dilationHeight,
            i = t.dilationWidth,
            u = t.effectiveFilterHeight,
            s = t.effectiveFilterWidth,
            c = u - 1 - t.padInfo.top,
            l = s - 1 - t.padInfo.left,
            h = 1 / (e * n);
          this.userCode = "\n      const ivec2 pads = ivec2(" + c + ", " + l + ");\n      const float avgMultiplier = float(" + h + ");\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 < " + u + ";\n            wR += " + a + ") {\n          float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n          if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n            continue;\n          }\n          int idyR = int(dyR);\n\n          for (int wC = 0; wC < " + s + ";\n            wC+= " + i + ") {\n            float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n            if (dyC < 0.0 || dyC >= " + t.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    ";
        };
      }(),
      la = function () {
        return function (t) {
          this.variableNames = ["dy"], this.outputShape = t.inShape;
          var e = t.filterDepth,
            n = t.filterHeight,
            r = t.filterWidth,
            o = t.strideDepth,
            a = t.strideHeight,
            i = t.strideWidth,
            u = t.dilationDepth,
            s = t.dilationHeight,
            c = t.dilationWidth,
            l = t.effectiveFilterDepth,
            h = t.effectiveFilterHeight,
            f = t.effectiveFilterWidth,
            p = l - 1 - t.padInfo.front,
            d = h - 1 - t.padInfo.top,
            v = f - 1 - t.padInfo.left,
            m = 1 / (e * n * r);
          this.userCode = "\n      const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n      const float avgMultiplier = float(" + m + ");\n\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int batch = coords.x;\n        int ch = coords.u;\n\n        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n        int dyDCorner = dyCorner.x;\n        int dyRCorner = dyCorner.y;\n        int dyCCorner = dyCorner.z;\n\n        // Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get\n        // dx(xD, xR, xC, ch).\n        // ? = to be determined. : = across all values in that axis.\n        float dotProd = 0.0;\n\n        for (int wD = 0; wD < " + l + ";\n            wD += " + u + ") {\n          float dyD = float(dyDCorner + wD) / " + o + ".0;\n\n          if (dyD < 0.0 || dyD >= " + t.outDepth + ".0 || fract(dyD) > 0.0) {\n            continue;\n          }\n          int idyD = int(dyD);\n\n          for (int wR = 0; wR < " + h + ";\n              wR += " + s + ") {\n            float dyR = float(dyRCorner + wR) / " + a + ".0;\n\n            if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n                fract(dyR) > 0.0) {\n              continue;\n            }\n            int idyR = int(dyR);\n\n            for (int wC = 0; wC < " + f + ";\n                wC += " + c + ") {\n              float dyC = float(dyCCorner + wC) / " + i + ".0;\n\n              if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n                  fract(dyC) > 0.0) {\n                continue;\n              }\n              int idyC = int(dyC);\n\n              float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n\n              dotProd += dyValue * avgMultiplier;\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      ha = function () {
        return function (t, e, n, r, o, a) {
          this.outputShape = [], this.variableNames = ["x", "mean", "variance"], po(t, e), po(t, n);
          var i = "0.0";
          null != r && (po(t, r), this.variableNames.push("offset"), i = "getOffsetAtOutCoords()");
          var u = "1.0";
          null != o && (po(t, o), this.variableNames.push("scale"), u = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = "\n      void main() {\n        float x = getXAtOutCoords();\n        float mean = getMeanAtOutCoords();\n        float variance = getVarianceAtOutCoords();\n        float offset = " + i + ";\n        float scale = " + u + ";\n        float inv = scale * inversesqrt(variance + float(" + a + "));\n        setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));\n      }\n    ";
        };
      }(),
      fa = function () {
        return function (t, e, n, r, o, a) {
          this.packedInputs = !0, this.packedOutput = !0, this.variableNames = ["x", "mean", "variance"], po(t, e), po(t, n);
          var i = "vec4(0.0)";
          null != r && (po(t, r), this.variableNames.push("offset"), i = "getOffsetAtOutCoords()");
          var u = "vec4(1.0)";
          null != o && (po(t, o), this.variableNames.push("scale"), u = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = "\n      void main() {\n        vec4 offset = " + i + ";\n        vec4 scale = " + u + ";\n\n        vec4 x = getXAtOutCoords();\n        vec4 mean = getMeanAtOutCoords();\n        vec4 variance = getVarianceAtOutCoords();\n\n        vec4 inv = scale * inversesqrt(variance + vec4(" + a + "));\n\n        setOutput((x - mean) * inv + offset);\n      }\n    ";
        };
      }(),
      pa = "return areal * breal - aimag * bimag;",
      da = "return areal * bimag + aimag * breal;",
      va = function () {
        return function (t, e, n) {
          this.variableNames = ["AReal", "AImag", "BReal", "BImag"], this.outputShape = po(e, n), this.userCode = "\n      float binaryOpComplex(\n          float areal, float aimag, float breal, float bimag) {\n        " + t + "\n      }\n\n      void main() {\n        float areal = getARealAtOutCoords();\n        float aimag = getAImagAtOutCoords();\n        float breal = getBRealAtOutCoords();\n        float bimag = getBImagAtOutCoords();\n        setOutput(binaryOpComplex(areal, aimag, breal, bimag));\n      }\n    ";
        };
      }(),
      ma = "return a + b;",
      ga = "return a - b;",
      ya = "return a * b;",
      xa = "return (a < 0.) ? b * a : a;",
      ba = function () {
        return function (t, e, n) {
          this.variableNames = ["A", "B"], this.outputShape = po(e, n), this.userCode = "\n      float binaryOperation(float a, float b) {\n        " + t + "\n      }\n\n      void main() {\n        float a = getAAtOutCoords();\n        float b = getBAtOutCoords();\n        setOutput(binaryOperation(a, b));\n      }\n    ";
        };
      }(),
      wa = "\n  vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n  return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n",
      Ca = function () {
        return function (t, e, n, r) {
          void 0 === r && (r = !1), this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = po(e, n);
          var o = this.outputShape.length,
            a = "";
          if (r) if (0 === o || 1 === w(this.outputShape)) a = "\n          result.y = 0.;\n          result.z = 0.;\n          result.w = 0.;\n        "; else if (a = "\n          " + aa(o) + " coords = getOutputCoords();\n        ", 1 === o) a += "\n            result.y = (coords + 1) >= " + this.outputShape[0] + " ? 0. : result.y;\n            result.z = 0.;\n            result.w = 0.;\n          "; else {
            var i = qo("coords", o);
            a += "\n            bool nextRowOutOfBounds =\n              (" + i[o - 2] + " + 1) >= " + this.outputShape[o - 2] + ";\n            bool nextColOutOfBounds =\n              (" + i[o - 1] + " + 1) >= " + this.outputShape[o - 1] + ";\n            result.y = nextColOutOfBounds ? 0. : result.y;\n            result.z = nextRowOutOfBounds ? 0. : result.z;\n            result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;\n          ";
          }
          this.userCode = "\n      vec4 binaryOperation(vec4 a, vec4 b) {\n        " + t + "\n      }\n\n      void main() {\n        vec4 a = getAAtOutCoords();\n        vec4 b = getBAtOutCoords();\n\n        vec4 result = binaryOperation(a, b);\n        " + a + "\n\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Ea = function () {
        function t(t) {
          this.variableNames = ["A"], this.outputShape = t, this.userCode = "\n      uniform float minVal;\n      uniform float maxVal;\n\n      void main() {\n        float value = getAAtOutCoords();\n        if (isnan(value)) {\n          setOutput(value);\n          return;\n        }\n\n        setOutput(clamp(value, minVal, maxVal));\n      }\n    ";
        }

        return t.prototype.getCustomSetupFunc = function (t, e) {
          var n = this;
          return function (r, o) {
            null == n.minLoc && (n.minLoc = r.getUniformLocationNoThrow(o, "minVal"), n.maxLoc = r.getUniformLocationNoThrow(o, "maxVal")), r.gl.uniform1f(n.minLoc, t), r.gl.uniform1f(n.maxLoc, e);
          };
        }, t;
      }(),
      Ra = function () {
        function t(t) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.userCode = "\n      uniform float minVal;\n      uniform float maxVal;\n\n      void main() {\n        vec4 value = getAAtOutCoords();\n\n        if (any(isnan(value))) {\n          setOutput(value);\n          return;\n        }\n\n        setOutput(clamp(value, vec4(minVal), vec4(maxVal)));\n      }\n    ";
        }

        return t.prototype.getCustomSetupFunc = function (t, e) {
          var n = this;
          return function (r, o) {
            null == n.minLoc && (n.minLoc = r.getUniformLocationNoThrow(o, "minVal"), n.maxLoc = r.getUniformLocationNoThrow(o, "maxVal")), r.gl.uniform1f(n.minLoc, t), r.gl.uniform1f(n.maxLoc, e);
          };
        }, t;
      }(),
      Ia = function () {
        return function (t) {
          this.variableNames = ["real", "imag"], this.outputShape = t, this.userCode = "\n      void main() {\n        float re = abs(getRealAtOutCoords());\n        float im = abs(getImagAtOutCoords());\n        float mx = max(re, im);\n\n        // sadly the length function in glsl is not underflow-safe\n        // (at least not on Intel GPUs). So the safe solution is\n        // to ensure underflow-safety in all cases.\n        setOutput(\n          mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))\n        );\n      }\n    ";
        };
      }(),
      ka = function () {
        return function (t) {
          this.outputShape = [], this.outputShape = wn(t, 1), this.variableNames = t.map(function (t, e) {
            return "T" + e;
          });
          var e = new Array(t.length - 1);
          e[0] = t[0][1];

          for (var n = 1; n < e.length; n++) e[n] = e[n - 1] + t[n][1];

          var r = ["if (yC < " + e[0] + ") setOutput(getT0(yR, yC));"];

          for (n = 1; n < e.length; n++) {
            var o = e[n - 1];
            r.push("else if (yC < " + e[n] + ") setOutput(getT" + n + "(yR, yC-" + o + "));");
          }

          var a = e.length,
            i = e[e.length - 1];
          r.push("else setOutput(getT" + a + "(yR, yC-" + i + "));"), this.userCode = "\n      void main() {\n        ivec2 coords = getOutputCoords();\n        int yR = coords.x;\n        int yC = coords.y;\n\n        " + r.join("\n        ") + "\n      }\n    ";
        };
      }(),
      Sa = function () {
        return function (t, e) {
          this.packedInputs = !0, this.packedOutput = !0, this.outputShape = [], this.outputShape = wn(t, e);
          var n = this.outputShape,
            r = n.length,
            o = aa(r),
            a = qo("coords", r),
            i = ["x", "y", "z", "w", "u", "v"].slice(0, r);
          this.variableNames = t.map(function (t, e) {
            return "T" + e;
          });
          var u = new Array(t.length - 1);
          u[0] = t[0][e];

          for (var s = 1; s < u.length; s++) u[s] = u[s - 1] + t[s][e];

          var c = i[e],
            l = i.slice(-2),
            h = i.join(),
            f = "if (" + c + " < " + u[0] + ") {\n        return getChannel(\n            getT0(" + h + "), vec2(" + l.join() + "));\n        }";

          for (s = 1; s < u.length; s++) {
            var p = u[s - 1];
            f += "\n        if (" + c + " < " + u[s] + "  && " + c + " >= " + u[s - 1] + ") {\n          return getChannel(\n            getT" + s + "(" + Aa(i, c, p) + "),\n            vec2(" + Aa(l, c, p) + "));\n        }";
          }

          var d = u.length,
            v = u[u.length - 1];
          f += "\n        return getChannel(\n          getT" + d + "(" + Aa(i, c, v) + "),\n          vec2(" + Aa(l, c, v) + "));", this.userCode = "\n      float getValue(" + i.map(function (t) {
            return "int " + t;
          }) + ") {\n        " + f + "\n      }\n\n      void main() {\n        " + o + " coords = getOutputCoords();\n        vec4 result = vec4(getValue(" + a + "), 0., 0., 0.);\n\n        " + a[r - 1] + " = " + a[r - 1] + " + 1;\n        if (" + a[r - 1] + " < " + n[r - 1] + ") {\n          result.g = getValue(" + a + ");\n        }\n\n        " + a[r - 2] + " = " + a[r - 2] + " + 1;\n        if (" + a[r - 2] + " < " + n[r - 2] + ") {\n          result.a = getValue(" + a + ");\n        }\n\n        " + a[r - 1] + " = " + a[r - 1] + " - 1;\n        if (" + a[r - 2] + " < " + n[r - 2] + " &&\n            " + a[r - 1] + " < " + n[r - 1] + ") {\n          result.b = getValue(" + a + ");\n        }\n        setOutput(result);\n      }\n    ";
        };
      }();

    function Aa(t, e, n) {
      var r = t.indexOf(e);
      return t.map(function (t, e) {
        return e === r ? t + " - " + n : t;
      }).join();
    }

    var Da = function () {
      return function (t) {
        this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
        var e = t.strideHeight,
          n = t.strideWidth,
          r = t.padInfo.top,
          o = t.padInfo.left,
          a = "channelsLast" === t.dataFormat;
        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 < " + t.batchSize + "; b++) {\n          for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n            int xR = wR + yR * " + e + " - " + r + ";\n\n            if (xR < 0 || xR >= " + t.inHeight + ") {\n              continue;\n            }\n\n            for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n              int xC = wC + yC * " + n + " - " + o + ";\n\n              if (xC < 0 || xC >= " + t.inWidth + ") {\n                continue;\n              }\n\n              if (" + a + ") {\n                float dyValue = getDy(b, yR, yC, d2);\n                float xValue = getX(b, xR, xC, d1);\n                dotProd += (xValue * dyValue);\n              } else {\n                float dyValue = getDy(b, d2, yR, yC);\n                float xValue = getX(b, d1, xR, xC);\n                dotProd += (xValue * dyValue);\n              }\n\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
      };
    }(),
      Ta = function () {
        return function (t) {
          this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
          var e = t.filterHeight,
            n = t.filterWidth,
            r = t.strideHeight,
            o = t.strideWidth,
            a = "channelsLast" === t.dataFormat,
            i = e - 1 - t.padInfo.top,
            u = n - 1 - t.padInfo.left,
            s = a ? 1 : 2,
            c = a ? 2 : 3,
            l = a ? 3 : 1;
          this.userCode = "\n      const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int batch = coords[0];\n        int d1 = coords[" + l + "];\n\n        ivec2 dyCorner = ivec2(coords[" + s + "], coords[" + c + "]) - 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 < " + e + "; wR++) {\n          float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n          if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n            continue;\n          }\n          int idyR = int(dyR);\n\n          int wRPerm = " + e + " - 1 - wR;\n\n          for (int wC = 0; wC < " + n + "; wC++) {\n            float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n            if (dyC < 0.0 || dyC >= " + t.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 < " + t.outChannels + "; d2++) {\n\n              if (" + a + ") {\n                float xValue = getDy(batch, idyR, idyC, d2);\n                float wValue = getW(wRPerm, wCPerm, d1, d2);\n                dotProd += xValue * wValue;\n              } else {\n                float xValue = getDy(batch, d2, idyR, idyC);\n                float wValue = getW(wRPerm, wCPerm, d1, d2);\n                dotProd += xValue * wValue;\n              }\n\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Na = function () {
        return function (t) {
          this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
          var e = t.strideDepth,
            n = t.strideHeight,
            r = t.strideWidth,
            o = t.padInfo.front,
            a = t.padInfo.top,
            i = t.padInfo.left;
          this.userCode = "\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int wF = coords.x;\n        int wR = coords.y;\n        int wC = coords.z;\n        int d1 = coords.w;\n        int d2 = coords.u;\n\n        float dotProd = 0.0;\n\n        for (int b = 0; b < " + t.batchSize + "; b++) {\n          for (int yF = 0; yF < " + t.outDepth + "; yF++) {\n            int xF = wF + yF * " + e + " - " + o + ";\n\n            if (xF < 0 || xF >= " + t.inDepth + ") {\n              continue;\n            }\n\n            for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n              int xR = wR + yR * " + n + " - " + a + ";\n\n              if (xR < 0 || xR >= " + t.inHeight + ") {\n                continue;\n              }\n\n              for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n                int xC = wC + yC * " + r + " - " + i + ";\n\n                if (xC < 0 || xC >= " + t.inWidth + ") {\n                  continue;\n                }\n\n                float dyValue = getDy(b, yF, yR, yC, d2);\n                float xValue = getX(b, xF, xR, xC, d1);\n                dotProd += (xValue * dyValue);\n              }\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Fa = function () {
        return function (t) {
          this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
          var e = t.filterDepth,
            n = t.filterHeight,
            r = t.filterWidth,
            o = t.strideDepth,
            a = t.strideHeight,
            i = t.strideWidth,
            u = e - 1 - t.padInfo.front,
            s = n - 1 - t.padInfo.top,
            c = r - 1 - t.padInfo.left;
          this.userCode = "\n      const ivec3 pads = ivec3(" + u + ", " + s + ", " + c + ");\n\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int batch = coords.x;\n        int d1 = coords.u;\n\n\n        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n        int dyFCorner = dyCorner.x;\n        int dyRCorner = dyCorner.y;\n        int dyCCorner = dyCorner.z;\n\n        float dotProd = 0.0;\n        for (int wF = 0; wF < " + e + "; wF++) {\n          float dyF = float(dyFCorner + wF) / " + o + ".0;\n\n          if (dyF < 0.0 || dyF >= " + t.outDepth + ".0 || fract(dyF) > 0.0) {\n            continue;\n          }\n          int idyF = int(dyF);\n\n          int wFPerm = " + e + " - 1 - wF;\n\n          for (int wR = 0; wR < " + n + "; wR++) {\n            float dyR = float(dyRCorner + wR) / " + a + ".0;\n\n            if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n              fract(dyR) > 0.0) {\n              continue;\n            }\n            int idyR = int(dyR);\n\n            int wRPerm = " + n + " - 1 - wR;\n\n            for (int wC = 0; wC < " + r + "; wC++) {\n              float dyC = float(dyCCorner + wC) / " + i + ".0;\n\n              if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n                  fract(dyC) > 0.0) {\n                continue;\n              }\n              int idyC = int(dyC);\n\n              int wCPerm = " + r + " - 1 - wC;\n\n              for (int d2 = 0; d2 < " + t.outChannels + "; d2++) {\n                float xValue = getDy(batch, idyF, idyR, idyC, d2);\n                float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);\n                dotProd += xValue * wValue;\n              }\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Oa = function () {
        return function (t) {
          this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
          var e = t.strideHeight,
            n = t.strideWidth,
            r = t.padInfo.top,
            o = t.padInfo.left,
            a = t.outChannels / t.inChannels;
          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 dm = coords.w;\n        int d2 = d1 * " + a + " + dm;\n\n        float dotProd = 0.0;\n\n        // TO DO: Vec4 over the batch size\n        for (int b = 0; b < " + t.batchSize + "; b++) {\n          for (int yR = 0; yR < " + t.outHeight + "; yR++) {\n            int xR = wR + yR * " + e + " - " + r + ";\n\n            if (xR < 0 || xR >= " + t.inHeight + ") {\n              continue;\n            }\n\n            for (int yC = 0; yC < " + t.outWidth + "; yC++) {\n              int xC = wC + yC * " + n + " - " + o + ";\n\n              if (xC < 0 || xC >= " + t.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    ";
        };
      }(),
      _a = function () {
        return function (t) {
          this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
          var e = t.filterHeight,
            n = t.filterWidth,
            r = t.strideHeight,
            o = t.strideWidth,
            a = e - 1 - t.padInfo.top,
            i = n - 1 - t.padInfo.left,
            u = t.outChannels / t.inChannels;
          this.userCode = "\n      const ivec2 pads = ivec2(" + a + ", " + i + ");\n\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int batch = coords[0];\n        int d1 = coords[3];\n        ivec2 dyCorner = coords.yz - pads;\n        int dyRCorner = dyCorner.x;\n        int dyCCorner = dyCorner.y;\n\n        float dotProd = 0.0;\n\n        for (int wR = 0; wR < " + e + "; wR++) {\n          float dyR = float(dyRCorner + wR) / " + r + ".0;\n\n          if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n            continue;\n          }\n          int idyR = int(dyR);\n\n          int wRPerm = " + e + " - 1 - wR;\n\n          for (int wC = 0; wC < " + n + "; wC++) {\n            float dyC = float(dyCCorner + wC) / " + o + ".0;\n\n            if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n                fract(dyC) > 0.0) {\n              continue;\n            }\n            int idyC = int(dyC);\n\n            int wCPerm = " + n + " - 1 - wC;\n\n            // TO DO: Vec4 over the channelMul\n            for (int dm = 0; dm < " + u + "; dm++) {\n              int d2 = d1 * " + u + " + dm;\n              float xValue = getDy(batch, idyR, idyC, d2);\n              float wValue = getW(wRPerm, wCPerm, d1, dm);\n              dotProd += xValue * wValue;\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Ma = function () {
        return function (t, e, n, r) {
          void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
          var o = t.padInfo.top,
            a = t.padInfo.left,
            i = t.strideHeight,
            u = t.strideWidth,
            s = t.dilationHeight,
            c = t.dilationWidth,
            l = t.filterHeight,
            h = t.filterWidth,
            f = 4 * Math.floor(t.inChannels / 4),
            p = t.inChannels % 4,
            d = "channelsLast" === t.dataFormat,
            v = d ? 1 : 2,
            m = d ? 2 : 3,
            g = d ? 3 : 1,
            y = "",
            x = "";
          n && (y = r ? "float activation(float a) {\n          float b = getPreluActivationWeightsAtOutCoords();\n          " + n + "\n        }" : "\n          float activation(float x) {\n            " + n + "\n          }\n        ", x = "result = activation(result);");
          var b = e ? "result += getBiasAtOutCoords();" : "";
          e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n      " + y + "\n\n      const ivec2 strides = ivec2(" + i + ", " + u + ");\n      const ivec2 pads = ivec2(" + o + ", " + a + ");\n\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int batch = coords[0];\n        int d2 = coords[" + g + "];\n\n        ivec2 xRCCorner =\n            ivec2(coords[" + v + "], coords[" + m + "]) * strides - pads;\n        int xRCorner = xRCCorner.x;\n        int xCCorner = xRCCorner.y;\n\n        // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n        // ? = to be determined. : = across all values in that axis.\n        float dotProd = 0.0;\n        for (int wR = 0; wR < " + l + "; wR++) {\n          int xR = xRCorner + wR * " + s + ";\n\n          if (xR < 0 || xR >= " + t.inHeight + ") {\n            continue;\n          }\n\n          for (int wC = 0; wC < " + h + "; wC++) {\n            int xC = xCCorner + wC * " + c + ";\n\n            if (xC < 0 || xC >= " + t.inWidth + ") {\n              continue;\n            }\n\n            for (int d1 = 0; d1 < " + f + "; d1 += 4) {\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              if (" + d + ") {\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                dotProd += dot(xValues, wValues);\n              } else {\n                vec4 xValues = vec4(\n                  getX(batch, d1, xR, xC),\n                  getX(batch, d1 + 1, xR, xC),\n                  getX(batch, d1 + 2, xR, xC),\n                  getX(batch, d1 + 3, xR, xC)\n                );\n                dotProd += dot(xValues, wValues);\n              }\n            }\n\n            if (" + (1 === p) + ") {\n\n              if (" + d + ") {\n                dotProd +=\n                    getX(batch, xR, xC, " + f + ") *\n                    getW(wR, wC, " + f + ", d2);\n              } else {\n                dotProd +=\n                    getX(batch, " + f + ", xR, xC) *\n                    getW(wR, wC, " + f + ", d2);\n              }\n\n            } else if (" + (2 === p) + ") {\n              vec2 wValues = vec2(\n                getW(wR, wC, " + f + ", d2),\n                getW(wR, wC, " + f + " + 1, d2)\n              );\n\n              if (" + d + ") {\n                vec2 xValues = vec2(\n                  getX(batch, xR, xC, " + f + "),\n                  getX(batch, xR, xC, " + f + " + 1)\n                );\n                dotProd += dot(xValues, wValues);\n              } else {\n                vec2 xValues = vec2(\n                  getX(batch, " + f + ", xR, xC),\n                  getX(batch, " + f + " + 1, xR, xC)\n                );\n                dotProd += dot(xValues, wValues);\n              }\n\n            } else if (" + (3 === p) + ") {\n              vec3 wValues = vec3(\n                getW(wR, wC, " + f + ", d2),\n                getW(wR, wC, " + f + " + 1, d2),\n                getW(wR, wC, " + f + " + 2, d2)\n              );\n\n              if (" + d + ") {\n                vec3 xValues = vec3(\n                  getX(batch, xR, xC, " + f + "),\n                  getX(batch, xR, xC, " + f + " + 1),\n                  getX(batch, xR, xC, " + f + " + 2)\n                );\n                dotProd += dot(xValues, wValues);\n              } else {\n                vec3 xValues = vec3(\n                  getX(batch, " + f + ", xR, xC),\n                  getX(batch, " + f + " + 1, xR, xC),\n                  getX(batch, " + f + " + 2, xR, xC)\n                );\n                dotProd += dot(xValues, wValues);\n              }\n\n            }\n          }\n        }\n\n        float result = dotProd;\n        " + b + "\n        " + x + "\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Ba = function () {
        return function (t) {
          this.variableNames = ["x", "W"], this.outputShape = t.outShape;
          var e = t.padInfo.front,
            n = t.padInfo.top,
            r = t.padInfo.left,
            o = t.strideDepth,
            a = t.strideHeight,
            i = t.strideWidth,
            u = t.dilationDepth,
            s = t.dilationHeight,
            c = t.dilationWidth,
            l = t.filterDepth,
            h = t.filterHeight,
            f = t.filterWidth,
            p = 4 * Math.floor(t.inChannels / 4),
            d = t.inChannels % 4;
          this.userCode = "\n      const ivec3 strides = ivec3(" + o + ", " + a + ", " + i + ");\n      const ivec3 pads = ivec3(" + e + ", " + n + ", " + r + ");\n\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int batch = coords.x;\n        int d2 = coords.u;\n\n        ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n        int xFCorner = xFRCCorner.x;\n        int xRCorner = xFRCCorner.y;\n        int xCCorner = xFRCCorner.z;\n\n        // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get\n        // y(yF, yR, yC, d2). ? = to be determined. : = across all\n        // values in that axis.\n        float dotProd = 0.0;\n        for (int wF = 0; wF < " + l + "; wF++) {\n          int xF = xFCorner + wF * " + u + ";\n\n          if (xF < 0 || xF >= " + t.inDepth + ") {\n            continue;\n          }\n\n          for (int wR = 0; wR < " + h + "; wR++) {\n            int xR = xRCorner + wR * " + s + ";\n\n            if (xR < 0 || xR >= " + t.inHeight + ") {\n              continue;\n            }\n\n            for (int wC = 0; wC < " + f + "; wC++) {\n              int xC = xCCorner + wC * " + c + ";\n\n              if (xC < 0 || xC >= " + t.inWidth + ") {\n                continue;\n              }\n\n              for (int d1 = 0; d1 < " + p + "; d1 += 4) {\n                vec4 xValues = vec4(\n                  getX(batch, xF, xR, xC, d1),\n                  getX(batch, xF, xR, xC, d1 + 1),\n                  getX(batch, xF, xR, xC, d1 + 2),\n                  getX(batch, xF, xR, xC, d1 + 3)\n                );\n                vec4 wValues = vec4(\n                  getW(wF, wR, wC, d1, d2),\n                  getW(wF, wR, wC, d1 + 1, d2),\n                  getW(wF, wR, wC, d1 + 2, d2),\n                  getW(wF, wR, wC, d1 + 3, d2)\n                );\n\n                dotProd += dot(xValues, wValues);\n              }\n\n              if (" + (1 === d) + ") {\n                dotProd +=\n                  getX(batch, xF, xR, xC, " + p + ") *\n                  getW(wF, wR, wC, " + p + ", d2);\n              } else if (" + (2 === d) + ") {\n                vec2 xValues = vec2(\n                  getX(batch, xF, xR, xC, " + p + "),\n                  getX(batch, xF, xR, xC, " + p + " + 1)\n                );\n                vec2 wValues = vec2(\n                  getW(wF, wR, wC, " + p + ", d2),\n                  getW(wF, wR, wC, " + p + " + 1, d2)\n                );\n                dotProd += dot(xValues, wValues);\n              } else if (" + (3 === d) + ") {\n                vec3 xValues = vec3(\n                  getX(batch, xF, xR, xC, " + p + "),\n                  getX(batch, xF, xR, xC, " + p + " + 1),\n                  getX(batch, xF, xR, xC, " + p + " + 2)\n                );\n                vec3 wValues = vec3(\n                  getW(wF, wR, wC, " + p + ", d2),\n                  getW(wF, wR, wC, " + p + " + 1, d2),\n                  getW(wF, wR, wC, " + p + " + 2, d2)\n                );\n                dotProd += dot(xValues, wValues);\n              }\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Pa = function () {
        return function (t, e, n, r) {
          void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
          var o = t.inHeight,
            a = t.inWidth,
            i = t.padInfo.top,
            u = t.padInfo.left,
            s = t.strideHeight,
            c = t.strideWidth,
            l = t.dilationHeight,
            h = t.dilationWidth,
            f = t.filterHeight,
            p = t.filterWidth,
            d = t.outChannels / t.inChannels,
            v = "",
            m = "";
          n && (v = r ? "float activation(float a) {\n          float b = getPreluActivationWeightsAtOutCoords();\n          " + n + "\n        }" : "\n          float activation(float x) {\n            " + n + "\n          }\n        ", m = "result = activation(result);");
          var g = e ? "result += getBiasAtOutCoords();" : "";
          e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n      " + v + "\n\n      const ivec2 strides = ivec2(" + s + ", " + c + ");\n      const ivec2 pads = ivec2(" + i + ", " + u + ");\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 / " + d + ";\n        int q = d2 - d1 * " + d + ";\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        // TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.\n        for (int wR = 0; wR < " + f + "; wR++) {\n          int xR = xRCorner + wR * " + l + ";\n\n          if (xR < 0 || xR >= " + o + ") {\n            continue;\n          }\n\n          for (int wC = 0; wC < " + p + "; wC++) {\n            int xC = xCCorner + wC * " + h + ";\n\n            if (xC < 0 || xC >= " + a + ") {\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\n        float result = dotProd;\n        " + g + "\n        " + m + "\n        setOutput(result);\n      }\n    ";
        };
      }(),
      La = function () {
        return function (t, e, n, r) {
          void 0 === e && (e = !1), void 0 === n && (n = null), void 0 === r && (r = !1), this.variableNames = ["x", "W"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t.outShape;

          for (var o = t.inHeight, a = t.inWidth, i = t.padInfo.top, u = t.padInfo.left, s = t.strideHeight, c = t.strideWidth, l = t.dilationHeight, h = t.dilationWidth, f = t.filterHeight, p = t.filterWidth, d = p, m = "int xR; int xC; int xCOffset;", g = 0; g < f; g++) for (var y = 0; y < p; y++) m += "\n          vec4 xTexelR" + g + "C" + 2 * y + " = vec4(0.);\n          vec4 wR" + g + "C" + y + " = vec4(0.);\n          vec4 xR" + g + "C" + y + " = vec4(0.);";

          for (g = 0; g < f; g++) for (var x = 0; x < d; x++) {
            if (m += "\n          xR = xRCorner + " + g * l + ";\n          xC = xCCorner + " + (y = 2 * x) * h + ";\n        ", 1 === c) {
              if (y < p && (m += u % 2 == 1 ? "\n                xCOffset = xC + 1;\n                if(xR >= 0 && xR < " + o + " && xCOffset >= 0 && xCOffset < " + a + ") {\n                  xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n                } else {\n                  xTexelR" + g + "C" + y + " = vec4(0.);\n                }\n\n                xCOffset = xC + 1 - 2;\n                if(xR >= 0 && xR < " + o + " && xCOffset >= 0 && xCOffset < " + a + ") {\n                  vec4 previous = getX(batch, xR, xCOffset, d1);\n                  xR" + g + "C" + y + " = vec4(previous.zw, xTexelR" + g + "C" + y + ".xy);\n                } else {\n                  xR" + g + "C" + y + " = vec4(0, 0, xTexelR" + g + "C" + y + ".xy);\n                }\n              " : "\n                if(xR >= 0 && xR < " + o + " && xC >= 0 && xC < " + a + ") {\n                  xTexelR" + g + "C" + y + " = getX(batch, xR, xC, d1);\n                } else {\n                  xTexelR" + g + "C" + y + " = vec4(0.);\n                }\n\n                xR" + g + "C" + y + " = xTexelR" + g + "C" + y + ";\n              ", y + 1 < p)) {
                var b = u % 2 == 0 ? v(h) : h;
                h % 2 == 0 && u % 2 == 1 || h % 2 != 0 && u % 2 != 1 ? (m += "\n                  xCOffset = xC + " + u % 2 + " + " + b + ";\n\n                  if(xR >= 0 && xR < " + o + " &&\n                    xCOffset >= 0 && xCOffset < " + a + ") {\n                    xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n                  }\n                ", h > 1 && (m += "\n                    xCOffset -= 2;\n                    if(xR >= 0 && xR < " + o + " &&\n                      xCOffset >= 0 && xCOffset < " + a + ") {\n                      xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n                    } else {\n                      xTexelR" + g + "C" + y + " = vec4(0.);\n                    }\n                  "), m += "\n                  xR" + g + "C" + (y + 1) + " = vec4(\n                    xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".xy);\n                ") : m += "\n                  xCOffset = xC + " + b + ";\n\n                  if(xR >= 0 && xR < " + o + " &&\n                    xCOffset >= 0 && xCOffset < " + a + ") {\n                    xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n                  }\n\n                  xR" + g + "C" + (y + 1) + " = xTexelR" + g + "C" + (y + 2) + ";\n                ";
              }
            } else y < p && (m += "\n              if(xR >= 0 && xR < " + o + ") {\n            ", u % 2 == 1 ? (m += "\n                xCOffset = xC + 1 - " + c + ";\n                if(xCOffset >= 0 && xCOffset < " + a + ") {\n                  xTexelR" + g + "C" + y + " = getX(batch, xR, xCOffset, d1);\n                } else {\n                  xTexelR" + g + "C" + y + " = vec4(0.);\n                }\n\n                if(xC + 1 >= 0 && xC + 1 < " + a + ") {\n                  xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xC + 1, d1);\n                } else {\n                  xTexelR" + g + "C" + (y + 2) + " = vec4(0.);\n                }\n\n                xR" + g + "C" + y + " = vec4(\n                  xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".zw);\n              ", y + 1 < p && (m += "\n                  vec4 final = vec4(0.);\n                  xCOffset = xC + 1 + " + c + ";\n                  if(xCOffset >= 0 && xCOffset < " + a + ") {\n                    final = getX(batch, xR, xCOffset, d1);\n                  }\n                  xR" + g + "C" + (y + 1) + " = vec4(xTexelR" + g + "C" + (y + 2) + ".xy, final.xy);\n                ")) : (m += "\n                if(xC >= 0 && xC < " + a + ") {\n                  xTexelR" + g + "C" + y + " = getX(batch, xR, xC, d1);\n                } else {\n                  xTexelR" + g + "C" + y + " = vec4(0.);\n                }\n\n                xCOffset = xC + " + c + ";\n                if(xCOffset >= 0 && xCOffset < " + a + ") {\n                  xTexelR" + g + "C" + (y + 2) + " = getX(batch, xR, xCOffset, d1);\n                } else {\n                  xTexelR" + g + "C" + (y + 2) + " = vec4(0.);\n                }\n\n                xR" + g + "C" + y + " = vec4(\n                  xTexelR" + g + "C" + y + ".xy, xTexelR" + g + "C" + (y + 2) + ".xy);\n              ", y + 1 < p && (m += "\n                  xR" + g + "C" + (y + 1) + " = vec4(\n                    xTexelR" + g + "C" + y + ".zw, xTexelR" + g + "C" + (y + 2) + ".zw);\n                ")), m += "}");

            y < p && (m += "\n            vec4 wTexelR" + g + "C" + y + " = getW(" + g + ", " + y + ", d1, q);\n            wR" + g + "C" + y + " = vec4(wTexelR" + g + "C" + y + ".xz, wTexelR" + g + "C" + y + ".xz);\n          ", y + 1 < p && (m += "\n              vec4 wTexelR" + g + "C" + (y + 1) + " = getW(" + g + ", " + (y + 1) + ", d1, q);\n              wR" + g + "C" + (y + 1) + " =\n                vec4(wTexelR" + g + "C" + (y + 1) + ".xz, wTexelR" + g + "C" + (y + 1) + ".xz);"));
          }

          for (g = 0; g < f; g++) for (y = 0; y < p; y++) m += "dotProd += xR" + g + "C" + y + " * wR" + g + "C" + y + ";";

          var w = "",
            C = "";
          n && (w = r ? "vec4 activation(vec4 a) {\n          vec4 b = getPreluActivationWeightsAtOutCoords();\n          " + n + "\n        }" : "vec4 activation(vec4 x) {\n          " + n + "\n        }", C = "result = activation(result);");
          var E = e ? "result += getBiasAtOutCoords();" : "";
          e && this.variableNames.push("bias"), r && this.variableNames.push("preluActivationWeights"), this.userCode = "\n      " + w + "\n\n      const ivec2 strides = ivec2(" + s + ", " + c + ");\n      const ivec2 pads = ivec2(" + i + ", " + u + ");\n\n      void main() {\n\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;\n        int q = 0;\n        int xRCorner = xRCCorner.x;\n        int xCCorner = xRCCorner.y;\n\n        vec4 dotProd = vec4(0.);\n\n        " + m + "\n\n        vec4 result = dotProd;\n        " + E + "\n        " + C + "\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Wa = function () {
        return function (t, e, n, r, o) {
          this.variableNames = ["Image", "Boxes", "BoxInd"], this.outputShape = [];
          var a = t[0],
            i = t[1],
            u = t[2],
            s = t[3],
            c = e[0],
            l = n[0],
            h = n[1];
          this.outputShape = [c, l, h, s];
          var f = "bilinear" === r ? 1 : 0,
            p = [i - 1 + ".0", u - 1 + ".0"],
            d = p[0],
            v = p[1],
            m = l > 1 ? ["" + (i - 1) / (l - 1), "(y2-y1) * height_ratio", "y1*" + d + " + float(y)*(height_scale)"] : ["0.0", "0.0", "0.5 * (y1+y2) * " + d],
            g = m[0],
            y = m[1],
            x = m[2],
            b = h > 1 ? ["" + (u - 1) / (h - 1), "(x2-x1) * width_ratio", "x1*" + v + " + float(x)*(width_scale)"] : ["0.0", "0.0", "0.5 * (x1+x2) * " + v],
            w = b[0],
            C = b[1],
            E = b[2];
          this.userCode = "\n      const float height_ratio = float(" + g + ");\n      const float width_ratio = float(" + w + ");\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords[0];\n        int y = coords[1];\n        int x = coords[2];\n        int d = coords[3];\n\n        // get box vals\n        float y1 = getBoxes(b,0);\n        float x1 = getBoxes(b,1);\n        float y2 = getBoxes(b,2);\n        float x2 = getBoxes(b,3);\n\n        // get image in batch index\n        int bInd = round(getBoxInd(b));\n        if(bInd < 0 || bInd >= " + a + ") {\n          return;\n        }\n\n        float height_scale = " + y + ";\n        float width_scale = " + C + ";\n\n        float in_y = " + x + ";\n        if( in_y < 0.0 || in_y > " + d + " ) {\n          setOutput(float(" + o + "));\n          return;\n        }\n        float in_x = " + E + ";\n        if( in_x < 0.0 || in_x > " + v + " ) {\n          setOutput(float(" + o + "));\n          return;\n        }\n\n        vec2 sourceFracIndexCR = vec2(in_x,in_y);\n        if(" + f + " == 1) {\n          // Compute the four integer indices.\n          ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);\n          ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));\n\n          float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);\n          float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);\n          float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);\n          float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);\n\n          vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);\n\n          float top = topLeft + (topRight - topLeft) * fracCR.x;\n          float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;\n          float newValue = top + (bottom - top) * fracCR.y;\n          setOutput(newValue);\n        } else {\n          // Compute the coordinators of nearest neighbor point.\n          ivec2 sourceNearestCR = ivec2(floor(\n            sourceFracIndexCR + vec2(0.5,0.5)));\n          float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);\n          setOutput(newValue);\n        }\n      }\n    ";
        };
      }(),
      Ua = function () {
        return function (t, e, n) {
          this.variableNames = ["x"], this.outputShape = t;
          var r = t.length,
            o = t[t.length - 1],
            a = n ? "<" : ">";

          this.userCode = "\n      int getIndex(int i) {\n        " + (n ? "return " + o + " -i - 1;" : "return i;") + "\n      }\n\n      void main() {\n        " + aa(r) + " coords = getOutputCoords();\n        int end = " + Va(r, "coords") + ";\n        float val = 0.0;\n        for (int i = " + o + " - 1; i >= 0; i -= 1) {\n          int idx = getIndex(i);\n          if (idx " + a + " end) {\n            continue;\n          }\n          if (idx == end && " + e + ") {\n            continue;\n          }\n          " + Va(r, "coords") + " = idx;\n          val += getX(" + function (t, e) {
            if (1 === t) return "" + e;
            if (2 === t) return e + ".x, " + e + ".y";
            if (3 === t) return e + ".x, " + e + ".y, " + e + ".z";
            if (4 === t) return e + ".x, " + e + ".y, " + e + ".z, " + e + ".w";
            throw Error("Cumulative sum for rank " + t + " is not yet supported");
          }(r, "coords") + ");\n        }\n        setOutput(val);\n      }\n    ";
        };
      }();

    function Va(t, e) {
      if (1 === t) return "" + e;
      if (2 === t) return e + ".y";
      if (3 === t) return e + ".z";
      if (4 === t) return e + ".w";
      throw Error("Cumulative sum for rank " + t + " is not yet supported");
    }

    var za = function () {
      return function (t) {
        this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outPackingScheme = _t.DENSE;
        var e = Gt(t),
          n = Ko();
        this.outputShape = t, this.userCode = "\n      ivec3 outCoordsFromFlatIndex(int index) {\n        " + jo(["r", "c", "d"], t) + "\n        return ivec3(r, c, d);\n      }\n\n      void main() {\n        ivec2 resTexRC = ivec2(resultUV.yx *\n          vec2(" + e[0] + ", " + e[1] + "));\n        int index = 4 * (resTexRC.x * " + e[1] + " + resTexRC.y);\n\n        vec4 result = vec4(0.);\n\n        for (int i=0; i<4; i++) {\n          int flatIndex = index + i;\n          ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n          result[i] = getA(rc.x, rc.y, rc.z);\n        }\n\n        " + n.output + " = result;\n      }\n    ";
      };
    }(),
      Ga = function () {
        return function (t) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outPackingScheme = _t.DENSE;
          var e = Gt(t),
            n = Ko();
          this.outputShape = t, this.userCode = "\n      ivec3 outCoordsFromFlatIndex(int index) {\n        " + jo(["r", "c", "d"], t) + "\n        return ivec3(r, c, d);\n      }\n\n      void main() {\n        ivec2 resTexRC = ivec2(resultUV.yx *\n          vec2(" + e[0] + ", " + e[1] + "));\n        int index = 4 * (resTexRC.x * " + e[1] + " + resTexRC.y);\n\n        vec4 result = vec4(0.);\n\n        for (int i=0; i<4; i++) {\n          int flatIndex = index + i;\n          ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n          result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));\n        }\n\n        " + n.output + " = result;\n      }\n    ";
        };
      }(),
      Ha = function () {
        function t(t, e, n) {
          this.variableNames = ["x"], this.outputShape = [], this.outputShape = t, this.blockSize = e, this.dataFormat = n, this.userCode = "\n    void main() {\n      ivec4 coords = getOutputCoords();\n      int b = coords[0];\n      int h = " + this.getHeightCoordString() + ";\n      int w = " + this.getWidthCoordString() + ";\n      int d = " + this.getDepthCoordString() + ";\n\n      int in_h = h / " + e + ";\n      int offset_h = imod(h, " + e + ");\n      int in_w = w / " + e + ";\n      int offset_w = imod(w, " + e + ");\n      int offset_d = (offset_h * " + e + " + offset_w) *\n        " + this.getOutputDepthSize() + ";\n      int in_d = d + offset_d;\n\n      float result = " + this.getInputSamplingString() + ";\n      setOutput(result);\n    }\n  ";
        }

        return t.prototype.getHeightCoordString = function () {
          return "NHWC" === this.dataFormat ? "coords[1]" : "coords[2]";
        }, t.prototype.getWidthCoordString = function () {
          return "NHWC" === this.dataFormat ? "coords[2]" : "coords[3]";
        }, t.prototype.getDepthCoordString = function () {
          return "NHWC" === this.dataFormat ? "coords[3]" : "coords[1]";
        }, t.prototype.getOutputDepthSize = function () {
          return "NHWC" === this.dataFormat ? this.outputShape[3] : this.outputShape[1];
        }, t.prototype.getInputSamplingString = function () {
          return "NHWC" === this.dataFormat ? "getX(b, in_h, in_w, in_d)" : "getX(b, in_d, in_h, in_w)";
        }, t;
      }(),
      qa = function () {
        return function (t) {
          this.variableNames = ["X"], this.outputShape = [t, t], this.userCode = "\n      void main() {\n          ivec2 coords = getOutputCoords();\n          float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;\n          setOutput(val);\n      }\n    ";
        };
      }(),
      Ka = function () {
        return function (t) {
          this.variableNames = ["A"], this.outTexUsage = Mt.DOWNLOAD;
          var e = Ko();
          this.outputShape = t, this.userCode = "\n      " + $o + "\n\n      void main() {\n        float x = getAAtOutCoords();\n        " + e.output + " = encode_float(x);\n      }\n    ";
        };
      }(),
      ja = function () {
        return function (t) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outTexUsage = Mt.DOWNLOAD;
          var e = Ko();
          this.outputShape = t, this.userCode = "\n      " + $o + "\n\n      void main() {\n        ivec3 coords = getOutputCoords();\n        float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));\n        " + e.output + " = encode_float(x);\n      }\n    ";
        };
      }(),
      Xa = function () {
        return function (t, e, n) {
          void 0 === n && (n = !1), this.variableNames = ["A"];
          var r = Ko(),
            o = e[0],
            a = e[1];
          this.outputShape = t;
          var i = "result";
          n && (i = "floor(result * 255. + 0.5)"), this.userCode = "\n      " + Xo(t) + "\n\n      void main() {\n        ivec3 coords = getOutputCoords();\n\n        int flatIndex = getFlatIndex(coords);\n        int offset = imod(flatIndex, 4);\n\n        flatIndex = idiv(flatIndex, 4, 1.);\n        \n        int r = flatIndex / " + a + ";\n        int c = imod(flatIndex, " + a + ");\n        vec2 uv = (vec2(c, r) + halfCR) / vec2(" + a + ".0, " + o + ".0);\n        vec4 values = " + r.texture2D + "(A, uv);\n\n        float result;\n\n        if(offset == 0) {\n          result = values[0];\n        } else if(offset == 1) {\n          result = values[1];\n        } else if(offset == 2) {\n          result = values[2];\n        } else {\n          result = values[3];\n        }\n\n        " + r.output + " = vec4(" + i + ", 0., 0., 0.);\n      }\n    ";
        };
      }(),
      $a = function () {
        return function (t, e, n) {
          void 0 === n && (n = !1), this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0;
          var r = Ko(),
            o = e[0],
            a = e[1];
          this.outputShape = t;
          var i = "",
            u = "result";
          n && (u = "floor(result * 255. + 0.5)");

          for (var s = 0; s <= 1; s++) for (var c = 0; c <= 1; c++) {
            var l = 2 * s + c;
            i += "\n          localCoords = coords;\n          if(localCoords[2] + " + c + " < " + t[2] + ") {\n            localCoords[2] += " + c + ";\n            if(localCoords[1] + " + s + " < " + t[1] + ") {\n              localCoords[1] += " + s + ";\n\n              flatIndex = getFlatIndex(localCoords);\n              offset = imod(flatIndex, 4);\n\n              flatIndex = idiv(flatIndex, 4, 1.);\n\n              r = flatIndex / " + a + ";\n              c = imod(flatIndex, " + a + ");\n              uv = (vec2(c, r) + halfCR) / vec2(" + a + ".0, " + o + ".0);\n              values = " + r.texture2D + "(A, uv);\n\n              if(offset == 0) {\n                result[" + l + "] = values[0];\n              } else if(offset == 1) {\n                result[" + l + "] = values[1];\n              } else if(offset == 2) {\n                result[" + l + "] = values[2];\n              } else {\n                result[" + l + "] = values[3];\n              }\n            }\n          }\n        ";
          }

          this.userCode = "\n      " + Xo(t) + "\n\n      void main() {\n        ivec3 coords = getOutputCoords();\n\n        vec4 result = vec4(0.);\n        int flatIndex, r, c, offset;\n        ivec3 localCoords;\n        vec2 uv;\n        vec4 values;\n\n        " + i + "\n\n        " + r.output + " = " + u + ";\n      }\n    ";
        };
      }(),
      Ya = "return real * expR - imag * expI;",
      Qa = "return real * expI + imag * expR;",
      Ja = function () {
        return function (t, e, n) {
          this.variableNames = ["real", "imag"];
          var r = e[1];
          this.outputShape = e;
          var o = n ? "2.0 * " + Math.PI : "-2.0 * " + Math.PI,
            a = n ? r + ".0" : "1.0";
          this.userCode = "\n      const float exponentMultiplier = " + o + ";\n\n      float unaryOpComplex(float real, float expR, float imag, float expI) {\n        " + t + "\n      }\n\n      float mulMatDFT(int batch, int index) {\n        float indexRatio = float(index) / float(" + r + ");\n        float exponentMultiplierTimesIndexRatio =\n            exponentMultiplier * indexRatio;\n\n        float result = 0.0;\n\n        for (int i = 0; i < " + r + "; i++) {\n          // x = (-2|2 * PI / N) * index * i;\n          float x = exponentMultiplierTimesIndexRatio * float(i);\n          float expR = cos(x);\n          float expI = sin(x);\n          float real = getReal(batch, i);\n          float imag = getImag(batch, i);\n\n          result +=\n              unaryOpComplex(real, expR, imag, expI) / " + a + ";\n        }\n\n        return result;\n      }\n\n      void main() {\n        ivec2 coords = getOutputCoords();\n        setOutput(mulMatDFT(coords[0], coords[1]));\n      }\n    ";
        };
      }(),
      Za = function () {
        function t(t, e) {
          this.outputShape = [], this.variableNames = ["x"], this.outputShape = t, this.userCode = "\n      uniform float value;\n      void main() {\n        // Input can be obtained from uniform value.\n        setOutput(value);\n      }\n    ";
        }

        return t.prototype.getCustomSetupFunc = function (t) {
          var e = this;
          return function (n, r) {
            null == e.valueLoc && (e.valueLoc = n.getUniformLocationNoThrow(r, "value")), n.gl.uniform1f(e.valueLoc, t);
          };
        }, t;
      }(),
      ti = function () {
        return function (t) {
          this.variableNames = ["A"];
          var e = Ko(),
            n = t[0],
            r = t[1];
          this.outputShape = t, 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(" + r + ".0, " + n + ".0);\n\n        vec4 values = " + e.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    ";
        };
      }(),
      ei = function () {
        return function (t) {
          this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0;
          var e = Ko(),
            n = t[0],
            r = t[1];
          this.outputShape = t, 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\n        vec4 result = vec4(0.);\n\n        for(int row=0; row<=1; row++) {\n          for(int col=0; col<=1; col++) {\n            texC = coords[1] + row;\n            depth = coords[2] + col;\n\n            vec2 uv = (vec2(texC, texR) + halfCR) /\n                       vec2(" + r + ".0, " + n + ".0);\n            vec4 values = " + e.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            result[row * 2 + col] = floor(value * 255.0 + 0.5);\n          }\n        }\n\n        " + e.output + " = result;\n      }\n    ";
        };
      }(),
      ni = function () {
        return function (t, e, n) {
          this.variableNames = ["A", "indices"];
          var r = t.slice();
          r[n] = e, this.outputShape = r, this.rank = r.length;

          var o = aa(this.rank),
            a = function (t, e) {
              var n = t.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"], o = [], a = 0; a < t.length; a++) a === e ? o.push("int(getIndices(" + r[a] + "))") : o.push("" + r[a]);

              return o.join();
            }(t, n);

          this.userCode = "\n      void main() {\n        " + o + " resRC = getOutputCoords();\n        setOutput(getA(" + a + "));\n      }\n    ";
        };
      }();

    var ri = function () {
      return function (t, e, n) {
        this.sliceDim = t, this.strides = e, this.variableNames = ["x", "indices"], this.outputShape = n;
        var r = aa(e.length),
          o = aa(n.length),
          a = this.sliceDim > 1 ? "strides[j]" : "strides";
        this.userCode = "\n        " + r + " strides = " + r + "(" + this.strides + ");\n         void main() {\n          " + o + " coords = getOutputCoords();\n          int flattenIndex = 0;\n          for (int j = 0; j < " + this.sliceDim + "; j++) {\n            int index = round(getIndices(coords[0], j));\n            flattenIndex += index * " + a + ";\n          }\n          setOutput(getX(flattenIndex, coords[1]));\n        }\n      ";
      };
    }();

    function oi(t, e) {
      var n = Ko();
      return Jt(t, e, n.version + "\n    precision highp float;\n    " + n.attribute + " vec3 clipSpacePos;\n    " + n.attribute + " vec2 uv;\n    " + n.varyingVs + " vec2 resultUV;\n\n    void main() {\n      gl_Position = vec4(clipSpacePos, 1);\n      resultUV = uv;\n    }");
    }

    function ai(t, e) {
      return ie(t, e, new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]));
    }

    function ii(t, e) {
      return ue(t, e, new Uint16Array([0, 1, 2, 2, 1, 3]));
    }

    function ui(t, e, n, r, o, a, i) {
      ce(n, r);
      var u = se(t, e),
        s = t.TEXTURE_2D;
      return Kt(t, e, function () {
        return t.bindTexture(s, u);
      }), Kt(t, e, function () {
        return t.texParameteri(s, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE);
      }), Kt(t, e, function () {
        return t.texParameteri(s, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE);
      }), Kt(t, e, function () {
        return t.texParameteri(s, t.TEXTURE_MIN_FILTER, t.NEAREST);
      }), Kt(t, e, function () {
        return t.texParameteri(s, t.TEXTURE_MAG_FILTER, t.NEAREST);
      }), Kt(t, e, function () {
        return t.texImage2D(s, 0, o, n, r, 0, a, i, null);
      }), Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, null);
      }), u;
    }

    function si(t, e, n, r, o) {
      var a = zt(n, r);
      return ui(t, e, a[0], a[1], o.internalFormatFloat, o.textureFormatFloat, t.FLOAT);
    }

    function ci(t, e, n, r, o) {
      var a = zt(n, r);
      return ui(t, e, a[0], a[1], o.internalFormatHalfFloat, o.textureFormatFloat, o.textureTypeHalfFloat);
    }

    function li(t, e, n, r, o) {
      var a = zt(n, r);
      return ui(t, e, a[0], a[1], t.RGBA, t.RGBA, t.UNSIGNED_BYTE);
    }

    function hi(t, e, n, r, o) {
      var a = Ht(n, r);
      return ui(t, e, a[0], a[1], o.internalFormatPackedFloat, t.RGBA, t.FLOAT);
    }

    function fi(t, e, n, r, o) {
      var a = Ht(n, r);
      return ui(t, e, a[0], a[1], o.internalFormatPackedHalfFloat, t.RGBA, o.textureTypeHalfFloat);
    }

    function pi(t, e, n, r) {
      return Kt(t, e, function () {
        return t.bindBuffer(t.ARRAY_BUFFER, r);
      }), he(t, e, n, "clipSpacePos", r, 3, 20, 0) && he(t, e, n, "uv", r, 2, 20, 12);
    }

    function di(t, e, n, r, o, a, i) {
      var u, s, c;
      Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, n);
      }), a instanceof Uint8Array ? (u = new Uint8Array(r * o * 4), s = t.UNSIGNED_BYTE, c = t.RGBA) : (u = new Float32Array(r * o * 4), s = t.FLOAT, c = i.internalFormatPackedFloat), u.set(a), Kt(t, e, function () {
        return t.texImage2D(t.TEXTURE_2D, 0, c, r, o, 0, t.RGBA, s, u);
      }), Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, null);
      });
    }

    function vi(t, e, n, r) {
      Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, n);
      }), r.data instanceof Uint8Array ? Kt(t, e, function () {
        return t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, r.width, r.height, 0, t.RGBA, t.UNSIGNED_BYTE, r.data);
      }) : Kt(t, e, function () {
        return t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, r);
      }), Kt(t, e, function () {
        return t.bindTexture(t.TEXTURE_2D, null);
      });
    }

    function mi(t, e, n, r, o) {
      var a = t.createBuffer();
      Kt(t, e, function () {
        return t.bindBuffer(t.PIXEL_PACK_BUFFER, a);
      });
      var i = 16 * n * r;
      return Kt(t, e, function () {
        return t.bufferData(t.PIXEL_PACK_BUFFER, i, t.STREAM_READ);
      }), Kt(t, e, function () {
        return t.readPixels(0, 0, r, n, t.RGBA, t.FLOAT, 0);
      }), Kt(t, e, function () {
        return t.bindBuffer(t.PIXEL_PACK_BUFFER, null);
      }), a;
    }

    function gi(t, e, n) {
      var r = t,
        o = new Float32Array(n);
      return r.bindBuffer(r.PIXEL_PACK_BUFFER, e), r.getBufferSubData(r.PIXEL_PACK_BUFFER, 0, o), r.bindBuffer(r.PIXEL_PACK_BUFFER, null), o;
    }

    function yi(t, e, n, r, o) {
      var a = zt(n, r),
        i = a[0],
        u = a[1],
        s = new Uint8Array(n * r * 4);
      return Kt(t, e, function () {
        return t.readPixels(0, 0, i, u, o.downloadTextureFormat, t.UNSIGNED_BYTE, s);
      }), new Float32Array(s.buffer);
    }

    function xi(t, e, n, r, o, a, i, u) {
      var s = t,
        c = new Float32Array(function (t, e) {
          var n = Ht(t, e);
          return n[0] * n[1] * 4;
        }(a, i));
      return s.bindBuffer(s.PIXEL_PACK_BUFFER, e), s.getBufferSubData(s.PIXEL_PACK_BUFFER, 0, c), s.bindBuffer(s.PIXEL_PACK_BUFFER, null), c;
    }

    function bi(t, e, n, r) {
      var o = new Float32Array(n * r * 4);
      return Kt(t, e, function () {
        return t.readPixels(0, 0, r, n, t.RGBA, t.FLOAT, o);
      }), o;
    }

    var wi = Object.freeze({
      createVertexShader: oi,
      createVertexBuffer: ai,
      createIndexBuffer: ii,
      createFloat32MatrixTexture: si,
      createFloat16MatrixTexture: ci,
      createUnsignedBytesMatrixTexture: li,
      createPackedMatrixTexture: hi,
      createFloat16PackedMatrixTexture: fi,
      bindVertexProgramAttributeStreams: pi,
      uploadDenseMatrixToTexture: di,
      uploadPixelDataToTexture: vi,
      createBufferFromOutputTexture: mi,
      downloadFloat32MatrixFromBuffer: gi,
      downloadByteEncodedFloatMatrixFromOutputTexture: yi,
      downloadPackedMatrixFromBuffer: xi,
      downloadMatrixFromPackedOutputTexture: bi
    }),
      Ci = function () {
        function t(t) {
          this.outputTexture = null, this.program = null, this.disposed = !1, this.vertexAttrsAreBound = !1, this.itemsToPoll = [];
          var e = a().getNumber("WEBGL_VERSION");
          if (null != t ? (this.gl = t, Wt(e, t)) : this.gl = Ut(e), 1 === a().getNumber("WEBGL_VERSION")) this.textureFloatExtension = Qt(this.gl, this.debug, "OES_texture_float"), this.colorBufferFloatExtension = this.gl.getExtension("WEBGL_color_buffer_float"), this.textureHalfFloatExtension = Qt(this.gl, this.debug, "OES_texture_half_float"), this.colorBufferHalfFloatExtension = this.gl.getExtension("EXT_color_buffer_half_float"); else {
            if (Ne(this.gl, "EXT_color_buffer_float")) this.colorBufferFloatExtension = this.gl.getExtension("EXT_color_buffer_float"); else {
              if (!Ne(this.gl, "EXT_color_buffer_half_float")) throw new Error("GL context does not support color renderable floats");
              this.colorBufferHalfFloatExtension = this.gl.getExtension("EXT_color_buffer_half_float");
            }
          }
          this.vertexBuffer = ai(this.gl, this.debug), this.indexBuffer = ii(this.gl, this.debug), this.framebuffer = le(this.gl, this.debug), this.textureConfig = qt(this.gl, this.textureHalfFloatExtension);
        }

        return Object.defineProperty(t.prototype, "debug", {
          get: function () {
            return a().getBool("DEBUG");
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.dispose = function () {
          var t = this;

          if (!this.disposed) {
            null != this.program && console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."), null != this.outputTexture && console.warn("Disposing a GPGPUContext that still has a bound output matrix texture.  This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");
            var e = this.gl;
            Kt(e, this.debug, function () {
              return e.finish();
            }), Kt(e, this.debug, function () {
              return e.bindFramebuffer(e.FRAMEBUFFER, null);
            }), Kt(e, this.debug, function () {
              return e.deleteFramebuffer(t.framebuffer);
            }), Kt(e, this.debug, function () {
              return e.bindBuffer(e.ARRAY_BUFFER, null);
            }), Kt(e, this.debug, function () {
              return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, null);
            }), Kt(e, this.debug, function () {
              return e.deleteBuffer(t.indexBuffer);
            }), this.disposed = !0;
          }
        }, t.prototype.createFloat32MatrixTexture = function (t, e) {
          return this.throwIfDisposed(), si(this.gl, this.debug, t, e, this.textureConfig);
        }, t.prototype.createFloat16MatrixTexture = function (t, e) {
          return this.throwIfDisposed(), ci(this.gl, this.debug, t, e, this.textureConfig);
        }, t.prototype.createUnsignedBytesMatrixTexture = function (t, e) {
          return this.throwIfDisposed(), li(this.gl, this.debug, t, e, this.textureConfig);
        }, t.prototype.uploadPixelDataToTexture = function (t, e) {
          this.throwIfDisposed(), vi(this.gl, this.debug, t, e);
        }, t.prototype.uploadDenseMatrixToTexture = function (t, e, n, r) {
          this.throwIfDisposed(), di(this.gl, this.debug, t, e, n, r, this.textureConfig);
        }, t.prototype.createFloat16PackedMatrixTexture = function (t, e) {
          return this.throwIfDisposed(), fi(this.gl, this.debug, t, e, this.textureConfig);
        }, t.prototype.createPackedMatrixTexture = function (t, e) {
          return this.throwIfDisposed(), hi(this.gl, this.debug, t, e, this.textureConfig);
        }, t.prototype.deleteMatrixTexture = function (t) {
          var e = this;
          this.throwIfDisposed(), this.outputTexture === t && (ge(this.gl, this.debug, this.framebuffer), this.outputTexture = null), Kt(this.gl, this.debug, function () {
            return e.gl.deleteTexture(t);
          });
        }, t.prototype.downloadByteEncodedFloatMatrixFromOutputTexture = function (t, e, n) {
          var r = this;
          return this.downloadMatrixDriver(t, function () {
            return yi(r.gl, r.debug, e, n, r.textureConfig);
          });
        }, t.prototype.downloadPackedMatrixFromBuffer = function (t, e, n, r, o, a) {
          return xi(this.gl, t, 0, 0, 0, o, a, this.textureConfig);
        }, t.prototype.downloadFloat32MatrixFromBuffer = function (t, e) {
          return gi(this.gl, t, e);
        }, t.prototype.createBufferFromTexture = function (t, e, n) {
          this.bindTextureToFrameBuffer(t);
          var r = mi(this.gl, this.debug, e, n, this.textureConfig);
          return this.unbindTextureToFrameBuffer(), r;
        }, t.prototype.createAndWaitForFence = function () {
          var t = this.createFence(this.gl);
          return this.pollFence(t);
        }, t.prototype.createFence = function (t) {
          var e,
            n,
            r = this;

          if (a().getBool("WEBGL_FENCE_API_ENABLED")) {
            var o = t,
              i = o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE, 0);
            t.flush(), n = function () {
              var t = o.clientWaitSync(i, 0, 0);
              return t === o.ALREADY_SIGNALED || t === o.CONDITION_SATISFIED;
            }, e = i;
          } else a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (e = this.beginQuery(), this.endQuery(), n = function () {
            return r.isQueryAvailable(e, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
          }) : n = function () {
            return !0;
          };

          return {
            query: e,
            isFencePassed: n
          };
        }, t.prototype.downloadMatrixFromPackedTexture = function (t, e, n) {
          var r = this;
          return this.downloadMatrixDriver(t, function () {
            return bi(r.gl, r.debug, e, n);
          });
        }, t.prototype.createProgram = function (t) {
          this.throwIfDisposed();
          var e = this.gl,
            n = Zt(e, this.debug, t),
            r = oi(e, this.debug),
            o = re(e, this.debug);
          return Kt(e, this.debug, function () {
            return e.attachShader(o, r);
          }), Kt(e, this.debug, function () {
            return e.attachShader(o, n);
          }), oe(e, this.debug, o), this.debug && ae(e, this.debug, o), this.vertexAttrsAreBound || (this.setProgram(o), this.vertexAttrsAreBound = pi(e, this.debug, this.program, this.vertexBuffer)), o;
        }, t.prototype.deleteProgram = function (t) {
          var e = this;
          this.throwIfDisposed(), t === this.program && (this.program = null), null != t && Kt(this.gl, this.debug, function () {
            return e.gl.deleteProgram(t);
          });
        }, t.prototype.setProgram = function (t) {
          var e = this;
          this.throwIfDisposed(), this.program = t, null != this.program && this.debug && ae(this.gl, this.debug, this.program), Kt(this.gl, this.debug, function () {
            return e.gl.useProgram(t);
          });
        }, t.prototype.getUniformLocation = function (t, e, n) {
          return void 0 === n && (n = !0), this.throwIfDisposed(), n ? pe(this.gl, this.debug, t, e) : de(this.gl, t, e);
        }, t.prototype.getAttributeLocation = function (t, e) {
          var n = this;
          return this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
            return n.gl.getAttribLocation(t, e);
          });
        }, t.prototype.getUniformLocationNoThrow = function (t, e) {
          return this.throwIfDisposed(), this.gl.getUniformLocation(t, e);
        }, t.prototype.setInputMatrixTexture = function (t, e, n) {
          this.throwIfDisposed(), this.throwIfNoProgram(), ve(this.gl, this.debug, this.program, t, e, n);
        }, t.prototype.setOutputMatrixTexture = function (t, e, n) {
          this.setOutputMatrixTextureDriver(t, n, e);
        }, t.prototype.setOutputPackedMatrixTexture = function (t, e, n) {
          this.throwIfDisposed();
          var r = Ht(e, n),
            o = r[0],
            a = r[1];
          this.setOutputMatrixTextureDriver(t, o, a);
        }, t.prototype.setOutputMatrixWriteRegion = function (t, e, n, r) {
          this.setOutputMatrixWriteRegionDriver(n, t, r, e);
        }, t.prototype.setOutputPackedMatrixWriteRegion = function (t, e, n, r) {
          throw new Error("setOutputPackedMatrixWriteRegion not implemented.");
        }, t.prototype.debugValidate = function () {
          null != this.program && ae(this.gl, this.debug, this.program), ye(this.gl);
        }, t.prototype.executeProgram = function () {
          this.throwIfDisposed(), this.throwIfNoProgram();
          var t = this.gl;
          this.debug && this.debugValidate(), Kt(t, this.debug, function () {
            return t.drawElements(t.TRIANGLES, 6, t.UNSIGNED_SHORT, 0);
          });
        }, t.prototype.blockUntilAllProgramsCompleted = function () {
          var t = this;
          this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
            return t.gl.finish();
          });
        }, t.prototype.getQueryTimerExtension = function () {
          return null == this.disjointQueryTimerExtension && (this.disjointQueryTimerExtension = Qt(this.gl, this.debug, 2 === a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") ? "EXT_disjoint_timer_query_webgl2" : "EXT_disjoint_timer_query")), this.disjointQueryTimerExtension;
        }, t.prototype.getQueryTimerExtensionWebGL2 = function () {
          return this.getQueryTimerExtension();
        }, t.prototype.getQueryTimerExtensionWebGL1 = function () {
          return this.getQueryTimerExtension();
        }, t.prototype.beginQuery = function () {
          if (2 === a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")) {
            var t = this.gl,
              e = this.getQueryTimerExtensionWebGL2(),
              n = t.createQuery();
            return t.beginQuery(e.TIME_ELAPSED_EXT, n), n;
          }

          var r = this.getQueryTimerExtensionWebGL1(),
            o = r.createQueryEXT();
          return r.beginQueryEXT(r.TIME_ELAPSED_EXT, o), o;
        }, t.prototype.endQuery = function () {
          if (2 !== a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")) {
            var t = this.getQueryTimerExtensionWebGL1();
            t.endQueryEXT(t.TIME_ELAPSED_EXT);
          } else {
            var e = this.gl,
              n = this.getQueryTimerExtensionWebGL2();
            e.endQuery(n.TIME_ELAPSED_EXT);
          }
        }, t.prototype.waitForQueryAndGetTime = function (t) {
          return n(this, void 0, void 0, function () {
            var e = this;
            return r(this, function (n) {
              switch (n.label) {
                case 0:
                  return [4, S(function () {
                    return e.disposed || e.isQueryAvailable(t, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
                  })];

                case 1:
                  return n.sent(), [2, this.getQueryTime(t, a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))];
              }
            });
          });
        }, t.prototype.getQueryTime = function (t, e) {
          if (0 === e) return null;

          if (2 === e) {
            var n = this.gl;
            return n.getQueryParameter(t, n.QUERY_RESULT) / 1e6;
          }

          var r = this.getQueryTimerExtensionWebGL1();
          return r.getQueryObjectEXT(t, r.QUERY_RESULT_EXT) / 1e6;
        }, t.prototype.isQueryAvailable = function (t, e) {
          if (0 === e) return !0;

          if (2 === e) {
            var n = this.gl,
              r = this.getQueryTimerExtensionWebGL2(),
              o = n.getQueryParameter(t, n.QUERY_RESULT_AVAILABLE);
            return null == this.disjoint && (this.disjoint = this.gl.getParameter(r.GPU_DISJOINT_EXT)), o && !this.disjoint;
          }

          o = (r = this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t, r.QUERY_RESULT_AVAILABLE_EXT);
          return null == this.disjoint && (this.disjoint = this.gl.getParameter(r.GPU_DISJOINT_EXT)), o && !this.disjoint;
        }, t.prototype.pollFence = function (t) {
          var e = this;
          return new Promise(function (n) {
            e.addItemToPoll(function () {
              return t.isFencePassed();
            }, function () {
              return n();
            });
          });
        }, t.prototype.pollItems = function () {
          for (var t = function (t) {
            for (var e = 0; e < t.length; ++e) {
              var n = t[e]();
              if (!n) break;
            }

            return e - 1;
          }(this.itemsToPoll.map(function (t) {
            return t.isDoneFn;
          })), e = 0; e <= t; ++e) {
            (0, this.itemsToPoll[e].resolveFn)();
          }

          this.itemsToPoll = this.itemsToPoll.slice(t + 1);
        }, t.prototype.addItemToPoll = function (t, e) {
          var n = this;
          this.itemsToPoll.push({
            isDoneFn: t,
            resolveFn: e
          }), this.itemsToPoll.length > 1 || S(function () {
            return n.pollItems(), 0 === n.itemsToPoll.length;
          });
        }, t.prototype.bindTextureToFrameBuffer = function (t) {
          this.throwIfDisposed(), me(this.gl, this.debug, t, this.framebuffer), this.debug && ye(this.gl);
        }, t.prototype.unbindTextureToFrameBuffer = function () {
          null != this.outputTexture ? (me(this.gl, this.debug, this.outputTexture, this.framebuffer), this.debug && ye(this.gl)) : ge(this.gl, this.debug, this.framebuffer);
        }, t.prototype.downloadMatrixDriver = function (t, e) {
          this.bindTextureToFrameBuffer(t);
          var n = e();
          return this.unbindTextureToFrameBuffer(), n;
        }, t.prototype.setOutputMatrixTextureDriver = function (t, e, n) {
          this.throwIfDisposed();
          var r = this.gl;
          me(r, this.debug, t, this.framebuffer), this.debug && ye(r), this.outputTexture = t, Kt(r, this.debug, function () {
            return r.viewport(0, 0, e, n);
          }), Kt(r, this.debug, function () {
            return r.scissor(0, 0, e, n);
          });
        }, t.prototype.setOutputMatrixWriteRegionDriver = function (t, e, n, r) {
          var o = this;
          this.throwIfDisposed(), Kt(this.gl, this.debug, function () {
            return o.gl.scissor(t, e, n, r);
          });
        }, t.prototype.throwIfDisposed = function () {
          if (this.disposed) throw new Error("Attempted to use disposed GPGPUContext.");
        }, t.prototype.throwIfNoProgram = function () {
          if (null == this.program) throw new Error("No GPU program is currently set.");
        }, t;
      }();

    function Ei(t, e) {
      if (t.length !== e.length) throw Error("Binary was compiled with " + t.length + " inputs, but was executed with " + e.length + " inputs");
      t.forEach(function (t, n) {
        var r = t.logicalShape,
          o = e[n],
          a = o.shape;
        if (!C(r, a)) throw Error("Binary was compiled with different shapes than the current args. Shapes " + r + " and " + a + " must match");

        if (!t.isUniform || !o.isUniform) {
          var i = t.texShape,
            u = o.isUniform ? null : o.texData.texShape;
          if (!C(i, u)) throw Error("Binary was compiled with different texture shapes than the current args. Shape " + i + " and " + u + " must match");
        }
      });
    }

    var Ri = function () {
      return function (t, e, n) {
        this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t;

        for (var r = n.filterWidth, o = n.inChannels, a = n.strideWidth, i = n.strideHeight, u = n.padInfo, s = n.outWidth, c = n.dilationWidth, l = n.dilationHeight, h = n.dataFormat, f = u.left, p = u.top, d = o * r, v = Ko(), m = "channelsLast" === h, g = m ? 0 : 1, y = m ? 1 : 2, x = "", b = 0; b <= 1; b++) for (var w = 0; w <= 1; w++) x += "\n          blockIndex = rc.y + " + w + ";\n          pos = rc.x + " + b + ";\n\n          if(blockIndex < " + t[1] + " && pos < " + t[0] + ") {\n            offsetY = int(blockIndex / (" + s + ")) * " + i + " - " + p + ";\n            d0 = offsetY + " + l + " * (pos / " + d + ");\n\n            if(d0 < " + e[g] + " && d0 >= 0) {\n\n              offsetX = int(mod(float(blockIndex), " + s + ".) * " + a + ". - " + f + ".);\n              d1 = offsetX + " + c + " * (int(mod(float(pos), " + d + ".) / " + o + ".));\n\n              if(d1 < " + e[y] + " && d1 >= 0) {\n\n                ch = int(mod(float(pos), " + o + ".));\n\n                if (" + m + ") {\n                  innerDims = vec2(d1, ch);\n                  result[" + (2 * b + w) + "] = getChannel(\n                    getA(d0, int(innerDims.x),\n                    int(innerDims.y)), innerDims);\n                } else {\n                  innerDims = vec2(d0, d1);\n                  result[" + (2 * b + w) + "] = getChannel(\n                    getA(ch, int(innerDims.x),\n                    int(innerDims.y)), innerDims);\n                }\n              }\n            }\n          }\n        ";

        this.userCode = "\n      void main() {\n        ivec2 rc = getOutputCoords();\n\n        vec4 result = vec4(0);\n\n        int blockIndex, pos, offsetY, d0, offsetX, d1, ch;\n        vec2 innerDims;\n\n        " + x + "\n\n        " + v.output + " = result;\n      }\n    ";
      };
    }(),
      Ii = function () {
        return function (t, e, n, r, o) {
          this.variableNames = ["x"], this.outputShape = [];
          var a,
            i = e,
            u = t[3] - 1;
          this.outputShape = t;
          var s = "float(" + n + ") + float(" + r + ") * sum";
          a = .5 === o ? "inversesqrt(" + s + ")" : 1 === o ? "1.0/(" + s + ")" : "exp(log(" + s + ") * float(-" + o + "));", this.userCode = "\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 = -" + i + "; j <= " + i + "; j++) {\n          int idx = d + j;\n          if (idx >= 0 && idx <=  " + u + ") {\n            float z = getX(b, r, c, idx);\n            sum += z * z;\n          }\n        }\n        float val = x * " + a + ";\n        setOutput(val);\n      }\n    ";
        };
      }(),
      ki = function () {
        return function (t, e, n, r, o) {
          this.variableNames = ["inputImage", "outputImage", "dy"], this.outputShape = [], this.outputShape = t, this.depth = t[3], this.depthRadius = e, this.bias = n, this.alpha = r, this.beta = o, this.userCode = "\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords[0];\n        int r = coords[1];\n        int c = coords[2];\n\n        float result = 0.0;\n        for (int d = 0; d < " + this.depth + "; ++d) {\n          int depthBegin = int(max(0.0, float(d - " + e + ")));\n          int depthEnd = int(min(float(" + this.depth + "),\n              float(d + " + e + " + 1)));\n\n          const int MIN_DEPTH_BEGIN = 0;\n          const int MAX_DEPTH_END = " + this.depth + ";\n\n          float norm = 0.0;\n          for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {\n            if (k < depthBegin){\n              continue;\n            }\n            else if (k >= depthBegin && k < depthEnd) {\n              norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);\n            }\n            else {\n              break;\n            }\n          }\n\n          norm = float(" + r + ") * norm + float(" + n + ");\n\n          for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){\n            if (k < depthBegin){\n              continue;\n            }\n            else if (k >= depthBegin && k < depthEnd){\n              float dyi = -2.0 * float(" + r + ")\n                * float(" + o + ")\n                * getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)\n                / norm;\n              if (k == d) {\n                dyi += pow(norm, -1.0 * " + o + ");\n              }\n              if (k == coords[3]) {\n                dyi *= getDy(b, r, c, d);\n                result += dyi;\n              }\n            }\n            else {\n              break;\n            }\n          }\n      }\n      setOutput(result);\n      }\n    ";
        };
      }(),
      Si = function () {
        return function (t, e, n, r, o) {
          this.variableNames = ["x"], this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0;
          var a,
            i = e,
            u = t[3] - 1;
          this.outputShape = t;
          var s = "float(" + n + ") + float(" + r + ") * sum";
          a = .5 === o ? "inversesqrt(" + s + ")" : 1 === o ? "1.0/(" + s + ")" : "exp(log(" + s + ") * float(-" + o + "));", this.userCode = "\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords.x;\n        int r = coords.y;\n        int c = coords.z;\n        int d = coords.w;\n\n        bool hasNextCol = d < " + this.outputShape[3] + ";\n        bool hasNextRow = c < " + this.outputShape[2] + ";\n\n        vec4 sum = vec4(0.);\n        vec4 xFragAtOutputCoords = getX(b, r, c, d);\n\n        vec4 xAtOutputCoords = vec4(\n          getChannel(xFragAtOutputCoords, vec2(c, d)),\n          hasNextCol ?\n            getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,\n          hasNextRow ?\n            getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,\n          (hasNextRow && hasNextCol) ?\n            getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0\n        );\n\n        int firstChannel = d - " + i + ";\n        vec2 cache = vec2(0.);\n        if(firstChannel >= 0){\n          vec4 firstChannelFrag = getX(b, r, c, firstChannel);\n          cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));\n            if(hasNextRow){\n              cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));\n            }\n        }\n\n        ivec2 depth = ivec2(d, d + 1);\n        for (int j = - " + i + "; j <= " + i + "; j++) {\n          ivec2 idx = depth + j;\n          bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));\n          bvec2 belowUpperBound = lessThanEqual(idx, ivec2(" + u + "));\n\n          bool depthInRange = aboveLowerBound.x && belowUpperBound.x;\n          bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;\n\n          if(depthInRange || depthPlusOneInRange){\n            vec4 z = vec4(0.);\n            vec4 xFragAtCurrentDepth;\n            z.xz = cache.xy;\n            if(depthPlusOneInRange && hasNextCol){\n              xFragAtCurrentDepth = idx.y != d ?\n                getX(b, r, c, idx.y) : xFragAtOutputCoords;\n              z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));\n              if(hasNextRow){\n                z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));\n              }\n            }\n            cache.xy = z.yw;\n            sum += z * z;\n          }\n        }\n        vec4 result = xAtOutputCoords * " + a + ";\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Ai = function () {
        return function (t) {
          this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
          var e = t.strideHeight,
            n = t.strideWidth,
            r = t.dilationHeight,
            o = t.effectiveFilterHeight,
            a = t.effectiveFilterWidth,
            i = o - 1 - t.padInfo.top,
            u = a - 1 - t.padInfo.left,
            s = o * a - 1;
          this.userCode = "\n      const ivec2 pads = ivec2(" + i + ", " + u + ");\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 < " + o + ";\n          wR += " + r + ") {\n          float dyR = float(dyRCorner + wR) / " + e + ".0;\n\n          if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 || fract(dyR) > 0.0) {\n            continue;\n          }\n          int idyR = int(dyR);\n\n          for (int wC = 0; wC < " + a + "; wC++) {\n            float dyC = float(dyCCorner + wC) / " + n + ".0;\n\n            if (dyC < 0.0 || dyC >= " + t.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 * " + a + " + wC;\n            float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n            dotProd += dyValue * mask;\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Di = function () {
        return function (t) {
          this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
          var e = t.strideDepth,
            n = t.strideHeight,
            r = t.strideWidth,
            o = t.dilationDepth,
            a = t.dilationHeight,
            i = t.dilationWidth,
            u = t.effectiveFilterDepth,
            s = t.effectiveFilterHeight,
            c = t.effectiveFilterWidth,
            l = u - 1 - t.padInfo.front,
            h = s - 1 - t.padInfo.top,
            f = c - 1 - t.padInfo.left,
            p = u * s * c - 1;
          this.userCode = "\n      const ivec3 pads = ivec3(" + l + ", " + h + ", " + f + ");\n\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int batch = coords.x;\n        int ch = coords.u;\n\n        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n        int dyDCorner = dyCorner.x;\n        int dyRCorner = dyCorner.y;\n        int dyCCorner = dyCorner.z;\n\n        // Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get\n        // dx(xD, xR, xC, ch).\n        // ? = to be determined. : = across all values in that axis.\n        float dotProd = 0.0;\n\n        for (int wD = 0; wD < " + u + ";\n           wD += " + o + ") {\n          float dyD = float(dyDCorner + wD) / " + e + ".0;\n\n          if (dyD < 0.0 || dyD >= " + t.outDepth + ".0 || fract(dyD) > 0.0) {\n            continue;\n          }\n          int idyD = int(dyD);\n\n          for (int wR = 0; wR < " + s + ";\n              wR += " + a + ") {\n            float dyR = float(dyRCorner + wR) / " + n + ".0;\n\n            if (dyR < 0.0 || dyR >= " + t.outHeight + ".0 ||\n                fract(dyR) > 0.0) {\n              continue;\n            }\n            int idyR = int(dyR);\n\n            for (int wC = 0; wC < " + c + ";\n                wC += " + i + ") {\n              float dyC = float(dyCCorner + wC) / " + r + ".0;\n\n              if (dyC < 0.0 || dyC >= " + t.outWidth + ".0 ||\n                  fract(dyC) > 0.0) {\n                continue;\n              }\n              int idyC = int(dyC);\n\n              float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n              int maxPosValue = " + p + " -\n                  int(getMaxPos(batch, idyD, idyR, idyC, ch));\n\n              // Get the current value, check it against the value from the\n              // position matrix.\n              int curPosValue =\n                  wD * " + s + " * " + c + " +\n                  wR * " + c + " + wC;\n              float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n              dotProd += dyValue * mask;\n            }\n          }\n        }\n        setOutput(dotProd);\n      }\n    ";
        };
      }(),
      Ti = function () {
        return function (t, e, n, r, o, a, i) {
          void 0 === n && (n = !1), void 0 === r && (r = !1), void 0 === o && (o = !1), void 0 === a && (a = null), void 0 === i && (i = !1), this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e;
          var u = n ? t[1] : t[2],
            s = Math.ceil(u / 2),
            c = n ? "i * 2, rc.y" : "rc.y, i * 2",
            l = r ? "rc.z, i * 2" : "i * 2, rc.z",
            h = n ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"],
            f = r ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"],
            p = "",
            d = "";
          a && (p = i ? "vec4 activation(vec4 a) {\n          vec4 b = getPreluActivationWeightsAtOutCoords();\n          " + a + "\n        }" : "vec4 activation(vec4 x) {\n          " + a + "\n        }", d = "result = activation(result);");
          var v = o ? "result += getBiasAtOutCoords();" : "";
          o && this.variableNames.push("bias"), i && this.variableNames.push("preluActivationWeights"), this.userCode = "\n      " + p + "\n\n      const float sharedDimension = " + s + ".0;\n\n      vec4 dot2x2ARowBCol(ivec3 rc) {\n        vec4 result = vec4(0);\n        for (int i = 0; i < " + s + "; i++) {\n          vec4 a = getMatrixA(rc.x, " + c + ");\n          vec4 b = getMatrixB(rc.x, " + l + ");\n\n          // These swizzled products need to be separately added.\n          // See: https://github.com/tensorflow/tfjs/issues/1735\n          result += (" + h[0] + " * " + f[0] + ");\n          result += (" + h[1] + " * " + f[1] + ");\n        }\n        return result;\n      }\n\n      void main() {\n        ivec3 rc = getOutputCoords();\n        vec4 result = dot2x2ARowBCol(rc);\n\n        " + v + "\n\n        " + d + "\n\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Ni = function () {
        function t(t, e, n) {
          this.variableNames = ["probs"], this.outputShape = [t, 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 < " + (e - 1) + "; i++) {\n          cdf += getProbs(batch, i);\n\n          if (r < cdf) {\n            setOutput(float(i));\n            return;\n          }\n        }\n\n        // If no other event happened, last event happened.\n        setOutput(float(" + (e - 1) + "));\n      }\n    ";
        }

        return t.prototype.getCustomSetupFunc = function (t) {
          var e = this;
          return function (n, r) {
            null == e.seedLoc && (e.seedLoc = n.getUniformLocation(r, "seed")), n.gl.uniform1f(e.seedLoc, t);
          };
        }, t;
      }(),
      Fi = function () {
        return function (t, e, n, r) {
          this.variableNames = ["indices"], this.outputShape = [t, e], this.userCode = "\n      void main() {\n        ivec2 coords = getOutputCoords();\n        int index = round(getIndices(coords.x));\n        setOutput(mix(float(" + r + "), float(" + n + "),\n                      float(index == coords.y)));\n      }\n    ";
        };
      }(),
      Oi = function () {
        return function (t) {
          this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outputShape = t;
          var e = t.length;
          if (0 === e) this.userCode = "\n        void main() {\n          setOutput(vec4(getA(), 0., 0., 0.));\n        }\n      "; else {
            var n = qo("rc", e),
              r = aa(e),
              o = function (t, e, n) {
                if (1 === t) return "rc > " + e[0];

                for (var r = "", o = t - 2; o < t; o++) r += n[o] + " >= " + e[o], o < t - 1 && (r += "||");

                return r;
              }(e, t, n),
              a = function (t, e, n, r) {
                if (1 === t) return "";
                var o = r.slice(-2);
                return "\n    int r = " + o[0] + ";\n    int c = " + o[1] + ";\n    int rp1 = r + 1;\n    int cp1 = c + 1;\n\n    bool cEdge = cp1 >= " + e + ";\n    bool rEdge = rp1 >= " + n + ";\n  ";
              }(e, t[t.length - 1], t[t.length - 2], n),
              i = function (t, e) {
                var n = t.length,
                  r = function (t, e) {
                    for (var n = [], r = 0; r <= 1; r++) for (var o = 0; o <= 1; o++) {
                      for (var a = (0 === r ? "r" : "rp1") + ", " + (0 === o ? "c" : "cp1"), i = 2; i < t; i++) a = e[e.length - 1 - i] + "," + a;

                      n.push(a);
                    }

                    return n;
                  }(n, e);

                return 1 === n ? "getA(rc),\n            rc + 1 >= " + t[0] + " ? 0. : getA(rc + 1),\n            0, 0" : "getA(" + r[0] + "),\n          cEdge ? 0. : getA(" + r[1] + "),\n          rEdge ? 0. : getA(" + r[2] + "),\n          rEdge || cEdge ? 0. : getA(" + r[3] + ")";
              }(t, n);

            this.userCode = "\n        void main() {\n          " + r + " rc = getOutputCoords();\n\n          if(" + o + ") {\n            setOutput(vec4(0));\n          } else {\n            " + a + "\n\n            setOutput(vec4(" + i + "));\n          }\n        }\n      ";
          }
        };
      }();

    var _i = function () {
      return function (t, e, n) {
        this.variableNames = ["x"], this.outputShape = e.map(function (e, n) {
          return e[0] + t[n] + e[1];
        });
        var r = t.length,
          o = aa(r),
          a = e.map(function (t) {
            return t[0];
          }).join(","),
          i = e.map(function (e, n) {
            return e[0] + t[n];
          }).join(","),
          u = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, r);
        this.userCode = 1 !== r ? "\n      " + o + " start = " + o + "(" + a + ");\n      " + o + " end = " + o + "(" + i + ");\n\n      void main() {\n        " + o + " outC = getOutputCoords();\n        if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n          setOutput(float(" + n + "));\n        } else {\n          " + o + " coords = outC - start;\n          setOutput(getX(" + u + "));\n        }\n      }\n    " : "\n        int start = " + a + ";\n        int end = " + i + ";\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      ";
      };
    }(),
      Mi = function () {
        return function (t, e, n) {
          this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e.map(function (e, n) {
            return e[0] + t[n] + e[1];
          });

          for (var r = t.length, o = aa(r), a = e.map(function (t) {
            return t[0];
          }).join(","), i = e.map(function (e, n) {
            return e[0] + t[n];
          }).join(","), u = qo("rc", r), s = qo("source", r), c = u[r - 1] + " < " + this.outputShape[r - 1], l = 1 === r ? "source" : "vec2(" + s.slice(-2).join() + ")", h = [o + " rc = outputLoc;", u[r - 1] + " += 1;\n       if(" + c + ") {\n      ", 1 === r ? "" : "}\n       rc = outputLoc;\n       " + u[r - 2] + " += 1;\n       if(" + u[r - 2] + " < " + this.outputShape[r - 2] + ") {", 1 === r ? "" : "  " + u[r - 1] + " += 1;\n         if(" + c + ") {"], f = 1 === r ? "rc < start || rc >= end" : "any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))", p = "", d = 0, v = 1 === r ? 2 : 4; d < v; d++) p += "\n        " + h[d] + "\n        if (" + f + ") {\n          result[" + d + "] = float(" + n + ");\n        } else {\n          " + o + " source = rc - start;\n          result[" + d + "] = getChannel(getX(" + s.join() + "), " + l + ");\n        }\n      ";

          p += 1 === r ? "} " : "}}", this.userCode = "\n      const " + o + " start = " + o + "(" + a + ");\n      const " + o + " end = " + o + "(" + i + ");\n\n      void main() {\n        " + o + " outputLoc = getOutputCoords();\n        vec4 result = vec4(0.);\n        " + p + "\n        setOutput(result);\n      }\n    ";
        };
      }(),
      Bi = function () {
        return function (t, e, n) {
          if (this.variableNames = ["x"], "avg" === e && n) throw new Error("Cannot compute positions for average pool.");
          var r = t.filterWidth,
            o = t.strideHeight,
            a = t.strideWidth,
            i = t.dilationHeight,
            u = t.dilationWidth,
            s = t.effectiveFilterHeight,
            c = t.effectiveFilterWidth,
            l = t.padInfo.top,
            h = t.padInfo.left;
          this.outputShape = t.outShape;
          var f = "avg" === e,
            p = "0.0";
          if (f || (p = "-1.0 / 1e-20"), n) this.userCode = "\n        const ivec2 strides = ivec2(" + o + ", " + a + ");\n        const ivec2 pads = ivec2(" + l + ", " + h + ");\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 < " + s + ";\n              wR += " + i + ") {\n            int xR = xRCorner + wR;\n\n            if (xR < 0 || xR >= " + t.inHeight + ") {\n              continue;\n            }\n\n            for (int wC = 0; wC < " + c + ";\n                wC += " + u + ") {\n              int xC = xCCorner + wC;\n\n              if (xC < 0 || xC >= " + t.inWidth + ") {\n                continue;\n              }\n\n              float value = getX(batch, xR, xC, d);\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 >= currMinMaxValue) {\n                minMaxValue = value;\n                minMaxValueFound = 1.0;\n                minMaxPosition = wR * " + c + " + wC;\n              }\n            }\n          }\n          setOutput(float(minMaxPosition));\n        }\n      "; else {
            var d = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
            "avg" === e && (d = "avgValue / count");
            var v = 4 * Math.floor(r / 4),
              m = r % 4,
              g = "\n      if (" + f + ") {\n        avgValue += dot(values, ones);\n      } else {\n        minMaxValue = max(values, minMaxValue);\n      }\n    ";
            this.userCode = "\n      const ivec2 strides = ivec2(" + o + ", " + a + ");\n      const ivec2 pads = ivec2(" + l + ", " + h + ");\n      const float initializationValue = " + p + ";\n      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n      float count = 0.0;\n\n      float getValue(int batch, int xR, int xC, int d) {\n        if (xC < 0 || xC >= " + t.inWidth + ") {\n          return initializationValue;\n        }\n        count += 1.0;\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(" + p + ");\n        float avgValue = 0.0;\n        count = 0.0;\n\n        for (int wR = 0; wR < " + s + ";\n            wR += " + i + ") {\n          int xR = xRCorner + wR;\n\n          if (xR < 0 || xR >= " + t.inHeight + ") {\n            continue;\n          }\n\n          for (int wC = 0; wC < " + v + "; wC += 4) {\n            int xC = xCCorner + wC * " + u + ";\n\n            vec4 values = vec4(\n              getValue(batch, xR, xC, d),\n              getValue(batch, xR, xC + " + u + ", d),\n              getValue(batch, xR, xC + 2 * " + u + ", d),\n              getValue(batch, xR, xC + 3 * " + u + ", d)\n            );\n\n            " + g + "\n          }\n\n          int xC = xCCorner + " + v + ";\n          if (" + (1 === m) + ") {\n            vec4 values = vec4(\n              getValue(batch, xR, xC, d),\n              initializationValue,\n              initializationValue,\n              initializationValue\n            );\n\n            " + g + "\n          } else if (" + (2 === m) + ") {\n            vec4 values = vec4(\n              getValue(batch, xR, xC, d),\n              getValue(batch, xR, xC + " + u + ", d),\n              initializationValue,\n              initializationValue\n            );\n\n            " + g + "\n          } else if (" + (3 === m) + ") {\n            vec4 values = vec4(\n              getValue(batch, xR, xC, d),\n              getValue(batch, xR, xC + " + u + ", d),\n              getValue(batch, xR, xC + 2 * " + u + ", d),\n              initializationValue\n            );\n\n            " + g + "\n          }\n        }\n        setOutput(" + d + ");\n      }\n    ";
          }
        };
      }(),
      Pi = function () {
        return function (t, e, n) {
          if (this.variableNames = ["x"], "avg" === e && n) throw new Error("Cannot compute positions for average pool.");
          var r = t.filterWidth,
            o = t.strideDepth,
            a = t.strideHeight,
            i = t.strideWidth,
            u = t.dilationDepth,
            s = t.dilationHeight,
            c = t.dilationWidth,
            l = t.effectiveFilterDepth,
            h = t.effectiveFilterHeight,
            f = t.effectiveFilterWidth,
            p = t.padInfo.front,
            d = t.padInfo.top,
            v = t.padInfo.left;
          this.outputShape = t.outShape;
          var m = "avg" === e,
            g = "0.0";
          if (m || (g = "-1.0 / 1e-20"), n) this.userCode = "\n        const ivec3 strides =\n            ivec3(" + o + ", " + a + ", " + i + ");\n        const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n\n        void main() {\n          ivec5 coords = getOutputCoords();\n          int batch = coords.x;\n          int ch = coords.u;\n\n          ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n          int xDCorner = xCorner.x;\n          int xRCorner = xCorner.y;\n          int xCCorner = xCorner.z;\n\n          // max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).\n          // ? = to be determined\n          float minMaxValue = 0.0;\n          float minMaxValueFound = 0.0;\n          int minMaxPosition = 0;\n\n          for (int wD = 0; wD < " + l + ";\n              wD += " + u + ") {\n            int xD = xDCorner + wD;\n\n            if (xD < 0 || xD >= " + t.inDepth + ") {\n              continue;\n            }\n\n            for (int wR = 0; wR < " + h + ";\n                wR += " + s + ") {\n              int xR = xRCorner + wR;\n\n              if (xR < 0 || xR >= " + t.inHeight + ") {\n                continue;\n              }\n\n              for (int wC = 0; wC < " + f + ";\n                  wC += " + c + ") {\n                int xC = xCCorner + wC;\n\n                if (xC < 0 || xC >= " + t.inWidth + ") {\n                  continue;\n                }\n\n                float value = getX(batch, xD, xR, xC, ch);\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 >= currMinMaxValue) {\n                  minMaxValue = value;\n                  minMaxValueFound = 1.0;\n                  minMaxPosition =\n                      wD * " + h + " * " + f + " +\n                      wR * " + f + " + wC;;\n                }\n              }\n            }\n          }\n          setOutput(float(minMaxPosition));\n        }\n      "; else {
            var y = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
            "avg" === e && (y = "avgValue / count");
            var x = 4 * Math.floor(r / 4),
              b = r % 4,
              w = "\n      if (" + m + ") {\n        avgValue += dot(values, ones);\n      } else {\n        minMaxValue = max(values, minMaxValue);\n      }\n    ";
            this.userCode = "\n      const ivec3 strides =\n        ivec3(" + o + ", " + a + ", " + i + ");\n      const ivec3 pads = ivec3(" + p + ", " + d + ", " + v + ");\n      const float initializationValue = " + g + ";\n      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n      float count = 0.0;\n\n      float getValue(int batch, int xD, int xR, int xC, int ch) {\n        if (xC < 0 || xC >= " + t.inWidth + ") {\n          return initializationValue;\n        }\n        count += 1.0;\n        return getX(batch, xD, xR, xC, ch);\n      }\n\n      void main() {\n        ivec5 coords = getOutputCoords();\n        int batch = coords.x;\n        int ch = coords.u;\n\n        ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n        int xDCorner = xCorner.x;\n        int xRCorner = xCorner.y;\n        int xCCorner = xCorner.z;\n\n        // max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).\n        // ? = to be determined\n        vec4 minMaxValue = vec4(" + g + ");\n        float avgValue = 0.0;\n        count = 0.0;\n\n        for (int wD = 0; wD < " + l + ";\n            wD += " + u + ") {\n          int xD = xDCorner + wD;\n\n          if (xD < 0 || xD >= " + t.inDepth + ") {\n            continue;\n          }\n\n          for (int wR = 0; wR < " + h + ";\n            wR += " + s + ") {\n            int xR = xRCorner + wR;\n\n            if (xR < 0 || xR >= " + t.inHeight + ") {\n              continue;\n            }\n\n            for (int wC = 0; wC < " + x + "; wC += 4) {\n              int xC = xCCorner + wC * " + c + ";\n\n              vec4 values = vec4(\n                getValue(batch, xD, xR, xC, ch),\n                getValue(batch, xD, xR, xC + " + c + ", ch),\n                getValue(batch, xD, xR, xC + 2 * " + c + ", ch),\n                getValue(batch, xD, xR, xC + 3 * " + c + ", ch)\n              );\n\n              " + w + "\n            }\n\n            int xC = xCCorner + " + x + ";\n            if (" + (1 === b) + ") {\n              vec4 values = vec4(\n                getValue(batch, xD, xR, xC, ch),\n                initializationValue,\n                initializationValue,\n                initializationValue\n              );\n\n              " + w + "\n            } else if (" + (2 === b) + ") {\n              vec4 values = vec4(\n                getValue(batch, xD, xR, xC, ch),\n                getValue(batch, xD, xR, xC + " + c + ", ch),\n                initializationValue,\n                initializationValue\n              );\n\n              " + w + "\n            } else if (" + (3 === b) + ") {\n              vec4 values = vec4(\n                getValue(batch, xD, xR, xC, ch),\n                getValue(batch, xD, xR, xC + " + c + ", ch),\n                getValue(batch, xD, xR, xC + 2 * " + c + ", ch),\n                initializationValue\n              );\n\n              " + w + "\n            }\n          }\n          setOutput(" + y + ");\n        }\n      }\n    ";
          }
        };
      }(),
      Li = function () {
        return function (t, e) {
          this.variableNames = ["x"];
          var n = t.windowSize,
            r = t.batchSize,
            o = t.inSize,
            a = Math.ceil(o / n);
          this.outputShape = [r, a];
          var i = "0.0",
            u = "";
          "prod" === e ? i = "1.0" : "min" === e ? (i = "1.0 / 1e-20", u = "min") : "max" === e && (i = "-1.0 / 1e-20", u = "max");
          var s = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
          "sum" === e ? s = "sumValue" : "prod" === e ? s = "prodValue" : "all" === e ? s = "allValue" : "any" === e && (s = "anyValue");
          var c = 4 * Math.floor(n / 4),
            l = n % 4,
            h = "\n      if (" + ("sum" === e) + ") {\n        sumValue += dot(values, ones);\n      } else if (" + ("prod" === e) + ") {\n        vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);\n        prodValue *= tmp[0] * tmp[1];\n      } else {\n        minMaxValue = " + u + "(values, minMaxValue);\n      }\n    ",
            f = "vec4";
          "all" === e ? (i = "1.0", h = "\n        bool reducedAllValue = all(values);\n        float floatedReducedAllValue = float(reducedAllValue);\n        allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n      ", f = "bvec4") : "any" === e && (i = "0.0", h = "\n        bool reducedAnyValue = any(values);\n        float floatedReducedAnyValue = float(reducedAnyValue);\n        anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n      ", f = "bvec4");
          var p = "";
          o % n > 0 && (p = "\n        if (inIdx < 0 || inIdx >= " + o + ") {\n          return initializationValue;\n        }\n      "), this.userCode = "\n      const float initializationValue = " + i + ";\n      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n      float getValue(int batch, int inIdx) {\n        " + p + "\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(" + i + ");\n        float prodValue = 1.0;\n        float sumValue = 0.0;\n        float allValue = 1.0;\n        float anyValue = 0.0;\n\n        for (int i = 0; i < " + c + "; i += 4) {\n          int inIdx = inOffset + i;\n          " + f + " values = " + f + "(\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 === l) + ") {\n          " + f + " values = " + f + "(\n            getValue(batch, inIdx),\n            initializationValue,\n            initializationValue,\n            initializationValue\n          );\n\n          " + h + "\n        } else if (" + (2 === l) + ") {\n          " + f + " values = " + f + "(\n            getValue(batch, inIdx),\n            getValue(batch, inIdx + 1),\n            initializationValue,\n            initializationValue\n          );\n\n          " + h + "\n        } else if (" + (3 === l) + ") {\n          " + f + " values = " + f + "(\n            getValue(batch, inIdx),\n            getValue(batch, inIdx + 1),\n            getValue(batch, inIdx + 2),\n            initializationValue\n          );\n\n          " + h + "\n        }\n        setOutput(" + s + ");\n      }\n    ";
        };
      }(),
      Wi = function () {
        return function (t, e) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t;

          for (var n = "", r = 0; r < 4; r++) {
            var o = "thisRC = rc;";
            r % 2 == 1 && (o += "thisRC.z += 1;"), r > 1 && (o += "thisRC.y += 1;"), n += "\n        " + o + "\n        " + (r > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "") + "\n          int flatIndex = getFlatIndex(thisRC);\n\n          ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);\n          vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));\n\n          result[" + r + "] =\n            getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);\n        " + (r > 0 ? "}" : "") + "\n      ";
          }

          this.userCode = "\n      \n    ivec3 inputCoordsFromReshapedOutCoords(int index) {\n      " + jo(["r", "c", "d"], e) + "\n      return ivec3(r, c, d);\n    }\n  \n      " + Xo(t) + "\n\n      void main() {\n        ivec3 rc = getOutputCoords();\n\n        vec4 result = vec4(0.);\n\n        ivec3 thisRC;\n        int rows = " + t[1] + ";\n        int cols = " + t[2] + ";\n\n        " + n + "\n\n        setOutput(result);\n      }\n    ";
        };
      }();

    var Ui = function () {
      return function (t, e, n) {
        this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
        var r = e.shape,
          o = r[1],
          a = r[2],
          i = t.shape,
          u = i[1],
          s = i[2],
          c = [n && u > 1 ? o - 1 : o, n && s > 1 ? a - 1 : a],
          l = [n && u > 1 ? u - 1 : u, n && s > 1 ? s - 1 : s],
          h = c[0] / l[0],
          f = c[1] / l[1],
          p = 1 / h,
          d = 1 / f,
          v = 2 * Math.ceil(p) + 2,
          m = 2 * Math.ceil(d) + 2;
        this.userCode = "\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords[0];\n        int d = coords[3];\n        int r = coords[1];\n        int c = coords[2];\n\n        float accumulator = 0.0;\n\n        const float heightScale = float(" + h + ");\n        const float widthScale = float(" + f + ");\n\n        const float invHeightScale = float(" + p + ");\n        const float invWidthScale = float(" + d + ");\n\n        const int winHeight = int(" + v + ");\n        const int winWidth = int(" + m + ");\n\n        // Compute bounds for where in dy we will look\n        float startRLerp = floor(float(r) * invHeightScale);\n        int startDyR = int(startRLerp - float(winHeight / 2));\n\n        float startCLerp = floor(float(c) * invWidthScale);\n        int startDyC = int(startCLerp - float(winWidth / 2));\n\n        // Loop over dy\n        for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n          int dyR = dyROffset + startDyR;\n\n          // Guard against the window exceeding the bounds of dy\n          if (dyR < 0 || dyR >= " + u + ") {\n            continue;\n          }\n\n          for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n            int dyC = dyCOffset + startDyC;\n\n            // Guard against the window exceeding the bounds of dy\n            if (dyC < 0 || dyC >= " + s + ") {\n              continue;\n            }\n\n            float dxR = float(dyR) * heightScale;\n            int topDxRIndex = int(floor(dxR));\n            int bottomDxRIndex = int(min(ceil(dxR), " + (o - 1) + ".0));\n            float dxRLerp = dxR - float(topDxRIndex);\n            float inverseDxRLerp = 1.0 - dxRLerp;\n\n            float dxC = float(dyC) * widthScale;\n            int leftDxCIndex = int(floor(dxC));\n            int rightDxCIndex = int(min(ceil(dxC), " + (a - 1) + ".0));\n            float dxCLerp = dxC - float(leftDxCIndex);\n            float inverseDxCLerp = 1.0 - dxCLerp;\n\n            if (r == topDxRIndex && c == leftDxCIndex) {\n              // topLeft\n              accumulator +=\n                getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n            }\n\n            if (r == topDxRIndex && c == rightDxCIndex) {\n              // topRight\n              accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n            }\n\n            if (r == bottomDxRIndex && c == leftDxCIndex) {\n              // bottomLeft\n              accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n            }\n\n            if (r == bottomDxRIndex && c == rightDxCIndex) {\n              // bottomRight\n              accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n            }\n          }\n        }\n        // End loop over dy\n\n        setOutput(accumulator);\n      }\n    ";
      };
    }(),
      Vi = function () {
        return function (t, e, n, r) {
          this.variableNames = ["A"], this.outputShape = [];
          var o = t[0],
            a = t[1],
            i = t[2],
            u = t[3];
          this.outputShape = [o, e, n, u];
          var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
            c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n];
          this.userCode = "\n      const vec2 effectiveInputOverOutputRatioRC = vec2(\n          " + s[0] / c[0] + ",\n          " + s[1] / c[1] + ");\n      const vec2 inputShapeRC = vec2(" + a + ".0, " + i + ".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    ";
        };
      }(),
      zi = function () {
        return function (t, e, n, r) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = [];
          var o = t[0],
            a = t[1],
            i = t[2],
            u = t[3];
          this.outputShape = [o, e, n, u];
          var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
            c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n];
          this.userCode = "\n      const vec3 effectiveInputOverOutputRatioRC = vec3(\n          " + s[0] / c[0] + ",\n          " + s[1] / c[1] + ",\n          " + s[1] / c[1] + ");\n      const vec3 inputShapeRC = vec3(" + a + ".0, " + i + ".0,\n                                     " + i + ".0);\n\n      float getAValue(int b, int r, int c, int d) {\n        return getChannel(getA(b, r, c, d), vec2(c, d));\n      }\n\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords[0];\n        int d = coords[3];\n        // Calculate values for next column in yRC.z.\n        ivec3 yRC = coords.yzz + ivec3(0, 0, 1);\n\n        // Fractional source index.\n        vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;\n\n        // Compute the four integer indices.\n        ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);\n        ivec3 sourceCeilRC = ivec3(\n          min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n        // Should we calculate next column and row elements in 2x2 packed cell.\n        bool hasNextCol = d < " + (u - 1) + ";\n        bool hasNextRow = coords.z < " + (n - 1) + ";\n\n        // In parallel, construct four corners for all four components in\n        // packed 2x2 cell.\n        vec4 topLeft = vec4(\n          getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),\n          hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)\n                     : 0.0,\n          hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)\n                     : 0.0,\n          (hasNextRow && hasNextCol) ?\n            getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n        vec4 bottomLeft = vec4(\n          getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),\n          hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)\n                     : 0.0,\n          hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)\n                     : 0.0,\n          (hasNextRow && hasNextCol) ?\n            getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n        vec4 topRight = vec4(\n          getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),\n          hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)\n                     : 0.0,\n          hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)\n                     : 0.0,\n          (hasNextRow && hasNextCol) ?\n            getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n        vec4 bottomRight = vec4(\n          getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),\n          hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)\n                     : 0.0,\n          hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)\n                     : 0.0,\n          (hasNextRow && hasNextCol) ?\n            getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n        vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);\n\n        vec4 top = mix(topLeft, topRight, fracRC.yyzz);\n        vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);\n        vec4 newValue = mix(top, bottom, fracRC.x);\n\n        setOutput(newValue);\n      }\n    ";
        };
      }(),
      Gi = function () {
        return function (t, e, n) {
          this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
          var r = e.shape,
            o = r[1],
            a = r[2],
            i = t.shape,
            u = i[1],
            s = i[2],
            c = [n && u > 1 ? o - 1 : o, n && s > 1 ? a - 1 : a],
            l = [n && u > 1 ? u - 1 : u, n && s > 1 ? s - 1 : s],
            h = c[0] / l[0],
            f = c[1] / l[1],
            p = 1 / h,
            d = 1 / f,
            v = 2 * Math.ceil(p) + 2,
            m = 2 * Math.ceil(d) + 2;
          this.userCode = "\n      void main() {\n        ivec4 coords = getOutputCoords();\n        int b = coords[0];\n        int d = coords[3];\n        int r = coords[1];\n        int c = coords[2];\n\n        float accumulator = 0.0;\n\n        const float heightScale = float(" + h + ");\n        const float widthScale = float(" + f + ");\n\n        const float invHeightScale = float(" + p + ");\n        const float invWidthScale = float(" + d + ");\n\n        const int winHeight = int(" + v + ");\n        const int winWidth = int(" + m + ");\n\n        // Compute bounds for where in dy we will look\n        float startRLerp = floor(float(r) * invHeightScale);\n        int startDyR = int(floor(startRLerp - float(winHeight / 2)));\n\n        float startCLerp = floor(float(c) * invWidthScale);\n        int startDyC = int(floor(startCLerp - float(winWidth / 2)));\n\n        // Loop over dy\n        for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n          int dyR = dyROffset + startDyR;\n\n          // Guard against the window exceeding the bounds of dy\n          if (dyR < 0 || dyR >= " + u + ") {\n            continue;\n          }\n\n          for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n            int dyC = dyCOffset + startDyC;\n\n            // Guard against the window exceeding the bounds of dy\n            if (dyC < 0 || dyC >= " + s + ") {\n              continue;\n            }\n\n            float sourceFracRow =\n              float(" + c[0] + ") *\n                (float(dyR) / float(" + l[0] + "));\n\n            float sourceFracCol =\n                float(" + c[1] + ") *\n                  (float(dyC) / float(" + l[1] + "));\n\n            int sourceNearestRow = int(min(\n                float(int(" + o + ") - 1),\n                " + n + " ? float(round(sourceFracRow)) :\n                                  float(floor(sourceFracRow))));\n\n            int sourceNearestCol = int(min(\n                float(int(" + a + ") - 1),\n                " + n + " ? float(round(sourceFracCol)) :\n                                  float(floor(sourceFracCol))));\n\n            if (r == sourceNearestRow && c == sourceNearestCol) {\n              accumulator += getDy(b, dyR, dyC, d);\n            }\n          }\n        }\n        // End loop over dy\n\n        setOutput(accumulator);\n      }\n    ";
        };
      }(),
      Hi = function () {
        return function (t, e, n, r) {
          this.variableNames = ["A"], this.outputShape = [];
          var o = t[0],
            a = t[1],
            i = t[2],
            u = t[3];
          this.outputShape = [o, e, n, u];
          var s = [r && e > 1 ? a - 1 : a, r && n > 1 ? i - 1 : i],
            c = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n],
            l = r ? "0.5" : "0.0";
          this.userCode = "\n      const vec2 effectiveInputOverOutputRatioRC = vec2(\n          " + s[0] / c[0] + ",\n          " + s[1] / c[1] + ");\n      const vec2 inputShapeRC = vec2(" + a + ".0, " + i + ".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 coordinators of nearest neighbor point.\n        ivec2 sourceNearestRC = ivec2(\n          min(inputShapeRC - 1.0, floor(sourceFracIndexRC + " + l + ")));\n\n        float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\n\n        setOutput(newValue);\n      }\n    ";
        };
      }(),
      qi = function () {
        return function (t, e) {
          this.variableNames = ["x"];
          var n = t.length;
          if (n > 4) throw new Error("WebGL backend: Reverse of rank-" + n + " tensor is not yet supported");

          if (this.outputShape = t, 1 !== n) {
            var r = t.map(function (n, r) {
              return function (n) {
                return -1 !== e.indexOf(n) && 1 !== t[n] ? t[n] + " - coords[" + n + "] - 1" : "coords[" + n + "]";
              }(r);
            }).join(","),
              o = aa(n);
            this.userCode = "\n      void main() {\n        " + o + " coords = getOutputCoords();\n        setOutput(getX(" + r + "));\n      }\n    ";
          } else this.userCode = "\n        void main() {\n          int coord = getOutputCoords();\n          setOutput(getX(" + t[0] + " - coord - 1));\n        }\n      ";
        };
      }(),
      Ki = function () {
        return function (t, e) {
          this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0;
          var n = t.length;
          if (n > 4) throw new Error("WebGL backend: Reverse of rank-" + n + " tensor is not yet supported");
          this.outputShape = t;
          var r = qo("rc", n),
            o = r[n - 1] + " + 1 < " + this.outputShape[n - 1],
            a = r[n - 2] + " + 1 < " + this.outputShape[n - 2],
            i = aa(n);

          function u(n) {
            var r = t.map(function (r, o) {
              return function (n, r) {
                return -1 !== e.indexOf(n) && 1 !== t[n] ? t[n] + " - " + r[n] + " - 1" : "" + r[n];
              }(o, n);
            });
            return "getChannel(getX(" + r.join(",") + "), vec2(" + r.slice(-2).join(",") + "))";
          }

          this.userCode = 1 === n ? "\n        void main(){\n          int rc = getOutputCoords();\n          vec4 result = vec4(0.);\n          result.r = getChannel(getX(" + t[0] + " - rc - 1),\n            " + t[0] + " - rc - 1);\n          if(" + o + "){\n              result.g = getChannel(getX(" + t[0] + " - (rc  + 1) - 1),\n                " + t[0] + " - (rc  + 1) - 1);\n          }\n          setOutput(result);\n        }\n      " : "\n        void main() {\n          " + i + " rc = getOutputCoords();\n          vec4 result = vec4(0.);\n          result.r = " + function (t) {
            return u(t);
          }(r.slice()) + ";\n          if(" + o + "){\n            result.g = " + function (t) {
            return t[n - 1] = "(" + t[n - 1] + " + 1)", u(t);
          }(r.slice()) + ";\n          }\n          if(" + a + ") {\n            result.b = " + function (t) {
            return t[n - 2] = "(" + t[n - 2] + " + 1)", u(t);
          }(r.slice()) + ";\n            if(" + o + ") {\n              result.a = " + function (t) {
            return t[n - 1] = "(" + t[n - 1] + " + 1)", t[n - 2] = "(" + t[n - 2] + " + 1)", u(t);
          }(r.slice()) + ";\n            }\n          }\n          setOutput(result);\n        }\n    ";
        };
      }(),
      ji = function () {
        return function (t, e, n, r, o, a, i) {
          void 0 === i && (i = !0), this.variableNames = ["updates", "indices", "defaultValue"], this.outputShape = a;
          var u = aa(o.length),
            s = aa(a.length),
            c = "";
          1 === n ? c = "i" : 2 === n && (c = "i, j");
          var l = "getIndices(" + c + ")",
            h = "";
          1 === r ? h = "i" : 2 === r && (h = "i, coords[1]");
          var f = "getUpdates(" + h + ")",
            p = e > 1 ? "strides[j]" : "strides";
          this.userCode = "\n        " + u + " strides = " + u + "(" + o + ");\n\n        void main() {\n          " + s + " coords = getOutputCoords();\n          float sum = 0.0;\n          bool found = false;\n          for (int i = 0; i < " + t + "; i++) {\n            int flattenedIndex = 0;\n            for (int j = 0; j < " + e + "; j++) {\n              int index = round(" + l + ");\n              flattenedIndex += index * " + p + ";\n            }\n            if (flattenedIndex == coords[0]) {\n              sum += " + f + ";\n              found = true;\n            }\n          }\n          setOutput(mix(getDefaultValue(), sum, float(found)));\n        }\n      ";
        };
      }(),
      Xi = function () {
        return function (t, e) {
          this.variableNames = ["x", "segmentIds"];
          var n = t.windowSize,
            r = t.batchSize,
            o = t.inSize,
            a = t.numSegments,
            i = a * Math.ceil(o / n);
          this.outputShape = [r, i];
          var u = 4 * Math.floor(n / 4),
            s = n % 4,
            c = "\n        sumValue += dot(values, segFilter);\n    ",
            l = "";
          o % n > 0 && (l = "\n        if (inIdx < 0 || inIdx >= " + o + ") {\n          return initializationValue;\n        }\n      ");
          var h = "";
          o % n > 0 && (h = "\n        if (inIdx < 0 || inIdx >= " + o + ") {\n          return -1.0;\n        }\n      "), this.userCode = "\n      const float initializationValue = 0.0;\n\n      float getValue(int batch, int inIdx) {\n        " + l + "\n        return getX(batch, inIdx);\n      }\n\n      float getSegmentIdAtIndex(int inIdx) {\n        " + h + "\n        return getSegmentIds(inIdx);\n      }\n\n      void main() {\n        ivec2 coords = getOutputCoords();\n        int batch = coords[0];\n        int outIdx = coords[1];\n        int inOffset = int(floor(float(outIdx) / float(\n          " + a + ")) * float(" + n + "));\n        int currentSeg = int(mod(float(outIdx), float(" + a + ")));\n\n        float sumValue = 0.0;\n\n        for (int i = 0; i < " + u + "; 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          vec4 segFilter = vec4(\n            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0\n          );\n\n          " + c + "\n        }\n\n        int inIdx = inOffset + " + u + ";\n        if (" + (1 === s) + ") {\n          vec4 values = vec4(\n            getValue(batch, inIdx),\n            initializationValue,\n            initializationValue,\n            initializationValue\n          );\n\n          int inIdxSeg = int(getSegmentIdAtIndex(inIdx));\n\n          vec4 segFilter = vec4(\n            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n            0,\n            0,\n            0\n          );\n\n          " + c + "\n        } else if (" + (2 === s) + ") {\n          vec4 values = vec4(\n            getValue(batch, inIdx),\n            getValue(batch, inIdx + 1),\n            initializationValue,\n            initializationValue\n          );\n\n          vec4 segFilter = vec4(\n            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n              0,\n              0\n          );\n\n          " + c + "\n        } else if (" + (3 === s) + ") {\n          vec4 values = vec4(\n            getValue(batch, inIdx),\n            getValue(batch, inIdx + 1),\n            getValue(batch, inIdx + 2),\n            initializationValue\n          );\n\n          vec4 segFilter = vec4(\n            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n            int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n            0\n          );\n\n          " + c + "\n        }\n        setOutput(sumValue);\n      }\n    ";
        };
      }(),
      $i = function () {
        return function (t, e, n) {
          var r, o;
          if (this.variableNames = ["c", "a", "b"], this.outputShape = e, n > 4) throw Error("Where for rank " + n + " is not yet supported");
          if (1 === n) o = "resRC", r = "resRC"; else {
            for (var a = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], i = [], u = [], s = 0; s < e.length; s++) u.push("" + a[s]), s < t && i.push("" + a[s]);

            r = i.join(), o = u.join();
          }
          var c = aa(n);
          this.userCode = "\n      void main() {\n        " + c + " resRC = getOutputCoords();\n        float cVal = getC(" + r + ");\n        if (cVal >= 1.0) {\n          setOutput(getA(" + o + "));\n        } else {\n          setOutput(getB(" + o + "));\n        }\n      }\n    ";
        };
      }(),
      Yi = function () {
        function t(t) {
          this.variableNames = ["source"], this.outputShape = t, this.rank = t.length;

          var e,
            n = aa(this.rank),
            r = "uniform int start[" + this.rank + "];",
            o = function (t) {
              if (1 === t) return "sourceLoc";
              if (t <= 6) return Qi.slice(0, t).map(function (t) {
                return "sourceLoc." + t;
              }).join(",");
              throw Error("Slicing for rank " + t + " is not yet supported");
            }(this.rank);

          e = "\n        " + n + " sourceLoc;\n        " + n + " coords = getOutputCoords();\n        " + t.map(function (t, e) {
            return "sourceLoc." + Qi[e] + " = start[" + e + "] + coords." + Qi[e] + ";";
          }).join("\n") + "\n      ", this.userCode = "\n      " + r + "\n      void main() {\n        " + e + "\n        setOutput(getSource(" + o + "));\n      }\n    ";
        }

        return t.prototype.getCustomSetupFunc = function (t) {
          var e = this;
          if (t.length !== this.rank) throw Error("The rank (" + this.rank + ") of the program must match the length of start (" + t.length + ")");
          return function (n, r) {
            null == e.startLoc && (e.startLoc = n.getUniformLocationNoThrow(r, "start"), null == e.startLoc) || n.gl.uniform1iv(e.startLoc, t);
          };
        }, t;
      }(),
      Qi = ["x", "y", "z", "w", "u", "v"];

    var Ji = function () {
      function t(t) {
        this.variableNames = ["source"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.rank = t.length;
        var e = aa(this.rank),
          n = qo("coords", this.rank),
          r = qo("sourceLoc", this.rank),
          o = 1 === this.rank ? "sourceLoc" : "vec2(" + r.slice(-2).join() + ")",
          a = "getChannel(getSource(" + r.join() + "), " + o + ")",
          i = "\n      result.x = " + a + ";\n      if (++" + n[this.rank - 1] + " < " + t[this.rank - 1] + ") {\n        ++" + r[this.rank - 1] + ";\n        result.y = " + a + ";\n        --" + r[this.rank - 1] + ";\n      }\n    ",
          u = 1 === this.rank ? "" : "\n      --" + n[this.rank - 1] + ";\n      if (++" + n[this.rank - 2] + " < " + t[this.rank - 2] + ") {\n        ++" + r[this.rank - 2] + ";\n        result.z = " + a + ";\n        if (++" + n[this.rank - 1] + " < " + t[this.rank - 1] + ") {\n          ++" + r[this.rank - 1] + ";\n          result.w = " + a + ";\n        }\n      }\n    ",
          s = this.rank <= 4 ? "sourceLoc = coords +\n            " + e + "(" + t.map(function (t, e) {
            return "start[" + e + "]";
          }).join() + ");" : t.map(function (t, e) {
            return r[e] + " = " + n[e] + " + start[" + e + "];";
          }).join("\n");
        this.userCode = "\n      uniform int start[" + this.rank + "];\n      void main() {\n        " + e + " coords = getOutputCoords();\n        " + e + " sourceLoc;\n        " + s + "\n        vec4 result = vec4(0.);\n        " + i + "\n        " + u + "\n        setOutput(result);\n      }\n    ";
      }

      return t.prototype.getCustomSetupFunc = function (t) {
        var e = this;
        if (t.length !== this.rank) throw Error("The rank (" + this.rank + ") of the program must match the length of start (" + t.length + ")");
        return function (n, r) {
          null == e.startLoc && (e.startLoc = n.getUniformLocationNoThrow(r, "start"), null == e.startLoc) || n.gl.uniform1iv(e.startLoc, t);
        };
      }, t;
    }(),
      Zi = function () {
        return function (t, e, n) {
          this.variableNames = ["x"], this.outputShape = n;
          var r = n.length,
            o = aa(n.length),
            a = aa(n.length),
            i = "";
          if (1 === r) i = "coords * strides + begin"; else {
            var u = 0;
            i = n.map(function (t, e) {
              return u++, 1 === n.length ? "coords * strides[" + e + "] + begin[" + e + "]" : "coords[" + (u - 1) + "] * strides[" + e + "] + begin[" + e + "]";
            }).join(",");
          }
          this.userCode = "\n      " + o + " begin = " + o + "(" + t + ");\n      " + o + " strides = " + o + "(" + e + ");\n\n      void main() {\n        " + a + " coords = getOutputCoords();\n        setOutput(getX(" + i + "));\n      }\n    ";
        };
      }(),
      tu = function () {
        function t(t) {
          this.gpgpu = t, this.numUsedTextures = 0, this.numFreeTextures = 0, this.freeTextures = {}, this.logEnabled = !1, this.usedTextures = {};
        }

        return t.prototype.acquireTexture = function (t, e, n) {
          var r,
            o = eu(e, n),
            a = nu(t, o, n);

          if (a in this.freeTextures || (this.freeTextures[a] = []), a in this.usedTextures || (this.usedTextures[a] = []), this.freeTextures[a].length > 0) {
            this.numFreeTextures--, this.numUsedTextures++, this.log();
            var i = this.freeTextures[a].shift();
            return this.usedTextures[a].push(i), i;
          }

          return this.numUsedTextures++, this.log(), o === Bt.PACKED_2X2_FLOAT32 ? r = this.gpgpu.createPackedMatrixTexture(t[0], t[1]) : o === Bt.PACKED_2X2_FLOAT16 ? r = this.gpgpu.createFloat16PackedMatrixTexture(t[0], t[1]) : o === Bt.UNPACKED_FLOAT32 ? r = this.gpgpu.createFloat32MatrixTexture(t[0], t[1]) : o === Bt.UNPACKED_FLOAT16 ? r = this.gpgpu.createFloat16MatrixTexture(t[0], t[1]) : o === Bt.PACKED_4X1_UNSIGNED_BYTE && (r = this.gpgpu.createUnsignedBytesMatrixTexture(t[0], t[1])), this.usedTextures[a].push(r), r;
        }, t.prototype.releaseTexture = function (t, e, n, r) {
          if (null != this.freeTextures) {
            var o = nu(e, eu(n, r), r);
            o in this.freeTextures || (this.freeTextures[o] = []), this.freeTextures[o].push(t), this.numFreeTextures++, this.numUsedTextures--;
            var a = this.usedTextures[o],
              i = a.indexOf(t);
            if (i < 0) throw new Error("Cannot release a texture that was never provided by this texture manager");
            a.splice(i, 1), this.log();
          }
        }, t.prototype.log = function () {
          if (this.logEnabled) {
            var t = this.numFreeTextures + this.numUsedTextures;
            console.log("Free/Used", this.numFreeTextures + " / " + this.numUsedTextures, "(" + t + ")");
          }
        }, t.prototype.getNumUsedTextures = function () {
          return this.numUsedTextures;
        }, t.prototype.getNumFreeTextures = function () {
          return this.numFreeTextures;
        }, t.prototype.dispose = function () {
          var t = this;

          if (null != this.freeTextures) {
            for (var e in this.freeTextures) this.freeTextures[e].forEach(function (e) {
              t.gpgpu.deleteMatrixTexture(e);
            });

            for (var e in this.usedTextures) this.usedTextures[e].forEach(function (e) {
              t.gpgpu.deleteMatrixTexture(e);
            });

            this.freeTextures = null, this.usedTextures = null, this.numUsedTextures = 0, this.numFreeTextures = 0;
          }
        }, t;
      }();

    function eu(t, e) {
      if (t === Mt.UPLOAD) return Bt.PACKED_2X2_FLOAT32;
      if (t === Mt.RENDER || null == t) return function (t) {
        return a().getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? t ? Bt.PACKED_2X2_FLOAT32 : Bt.UNPACKED_FLOAT32 : t ? Bt.PACKED_2X2_FLOAT16 : Bt.UNPACKED_FLOAT16;
      }(e);
      if (t === Mt.DOWNLOAD || t === Mt.PIXELS) return Bt.PACKED_4X1_UNSIGNED_BYTE;
      throw new Error("Unknown logical texture type " + t);
    }

    function nu(t, e, n) {
      return t[0] + "_" + t[1] + "_" + e + "_" + n;
    }

    var ru = function () {
      return function (t, e) {
        this.variableNames = ["A"];

        for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[r] * e[r];

        this.outputShape = n, this.rank = n.length;

        var o = aa(this.rank),
          a = function (t) {
            var e = t.length;
            if (e > 5) throw Error("Tile for rank " + e + " is not yet supported");
            if (1 === e) return "imod(resRC, " + t[0] + ")";

            for (var n = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u"], r = [], o = 0; o < t.length; o++) r.push("imod(" + n[o] + ", " + t[o] + ")");

            return r.join();
          }(t);

        this.userCode = "\n      void main() {\n        " + o + " resRC = getOutputCoords();\n        setOutput(getA(" + a + "));\n      }\n    ";
      };
    }();

    var ou = function () {
      return function (t, e) {
        this.variableNames = ["A"];

        for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[e[r]];

        this.outputShape = n, this.rank = n.length;

        var o = aa(this.rank),
          a = function (t) {
            var e = t.length;
            if (e > 6) throw Error("Transpose for rank " + e + " is not yet supported");

            for (var n = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], r = new Array(e), o = 0; o < t.length; o++) r[t[o]] = n[o];

            return r.join();
          }(e);

        this.userCode = "\n    void main() {\n      " + o + " resRC = getOutputCoords();\n      setOutput(getA(" + a + "));\n    }\n    ";
      };
    }();

    var au = function () {
      return function (t, e) {
        this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;

        for (var n = new Array(t.length), r = 0; r < n.length; r++) n[r] = t[e[r]];

        if (this.outputShape = n, this.rank = n.length, this.rank > 6) throw Error("Packed transpose for rank " + this.rank + " is not yet supported.");
        var o = aa(this.rank),
          a = Ho("rc", this.rank),
          i = new Array(this.rank);

        for (r = 0; r < e.length; r++) i[e[r]] = a[r];

        var u = "vec2(" + i.slice(-2).join() + ")",
          s = "++" + a[this.rank - 1] + " < " + n[this.rank - 1],
          c = "getChannel(getA(" + i.join() + "), " + u + ")";
        this.userCode = "\n    void main() {\n      " + o + " rc = getOutputCoords();\n      vec4 result = vec4(0.);\n      result[0] = " + c + ";\n      if(" + s + ") {\n        result[1] = " + c + ";\n      }\n      --" + a[this.rank - 1] + ";\n      if(++" + a[this.rank - 2] + " < " + n[this.rank - 2] + ") {\n        result[2] = " + c + ";\n        if(" + s + ") {\n          result[3] = " + c + ";\n        }\n      }\n      setOutput(result);\n    }\n    ";
      };
    }(),
      iu = 1.7580993408473768,
      uu = 1.0507009873554805,
      su = function () {
        return function (t, e) {
          this.variableNames = ["A"], this.outputShape = t, this.userCode = "\n      float unaryOperation(float x) {\n        " + e + "\n      }\n\n      void main() {\n        float x = getAAtOutCoords();\n        float y = unaryOperation(x);\n\n        setOutput(y);\n      }\n    ";
        };
      }(),
      cu = "if (isnan(x)) return x;",
      lu = "return x;",
      hu = "return abs(x);",
      fu = cu + "\n  return (x < 0.0) ? 0.0 : x;\n",
      pu = cu + "\n  return (x < 0.0) ? 0.0 : min(6.0, x);\n",
      du = "return (x >= 0.0) ? x : (exp(x) - 1.0);",
      vu = "\n  // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n  // see: https://arxiv.org/abs/1706.02515\n  float scaleAlpha = " + iu + ";\n  float scale = " + uu + ";\n  return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n";

    var mu = "return -x;",
      gu = "return ceil(x);",
      yu = "return floor(x);",
      xu = "return exp(x);",
      bu = "return exp(x) - 1.0;",
      wu = cu + "\n  return sin(x);\n",
      Cu = cu + "\n  return cos(x);\n",
      Eu = cu + "\n  if (abs(x) > 1.) {\n    return NAN;\n  }\n  return asin(x);\n",
      Ru = cu + "\n  if (abs(x) > 1.) {\n    return NAN;\n  }\n  return acos(x);\n",
      Iu = cu + "\n  return atan(x);\n",
      ku = cu + "return log(x + sqrt(x * x + 1.0));",
      Su = cu + "\n  if (x < 1.0) return NAN;\n  return log(x + sqrt(x * x - 1.0));",
      Au = cu + "\n  if ((x < -1.0) || (x > 1.0)) return NAN;\n  return (log(1.0 + x) - log(1.0 - x)) / 2.0;",
      Du = "return x;",
      Tu = "return x;",
      Nu = "\n  vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));\n  bvec4 isNaN = isnan(x);\n\n  result.r = isNaN.r ? x.r : result.r;\n  result.g = isNaN.g ? x.g : result.g;\n  result.b = isNaN.b ? x.b : result.b;\n  result.a = isNaN.a ? x.a : result.a;\n\n  return result;\n",
      Fu = "\n  vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));\n  bvec4 isNaN = isnan(x);\n\n  result.r = isNaN.r ? x.r : result.r;\n  result.g = isNaN.g ? x.g : result.g;\n  result.b = isNaN.b ? x.b : result.b;\n  result.a = isNaN.a ? x.a : result.a;\n\n  return result;\n",
      Ou = "\n  vec4 result;\n\n  result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);\n  result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);\n  result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);\n  result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);\n\n  return result;\n",
      _u = function () {
        return function (t, e) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.userCode = "\n      vec4 unaryOperation(vec4 x) {\n        " + e + "\n      }\n\n      void main() {\n        vec4 x = getAAtOutCoords();\n        vec4 y = unaryOperation(x);\n\n        setOutput(y);\n      }\n    ";
        };
      }(),
      Mu = function () {
        return function (t) {
          this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outputShape = t;

          var e = t.length,
            n = qo("rc", e),
            r = aa(e),
            o = function (t, e) {
              if (1 === t) return "rc";

              for (var n = "", r = 0; r < t; r++) n += e[r], r < t - 1 && (n += ",");

              return n;
            }(e, n),
            a = n.slice(-2),
            i = e <= 1 ? "rc" : "vec2(" + a.join(",") + ")";

          this.userCode = "\n      void main() {\n        " + r + " rc = getOutputCoords();\n        vec4 packedInput = getA(" + o + ");\n\n        setOutput(getChannel(packedInput, " + i + "));\n      }\n    ";
        };
      }(),
      Bu = {};

    function Pu(t, e) {
      if (void 0 === e && (e = !1), "linear" === t) return e ? Tu : lu;
      if ("relu" === t) return e ? Nu : fu;
      if ("elu" === t) return e ? Ou : du;
      if ("relu6" === t) return e ? Fu : pu;
      if ("prelu" === t) return e ? wa : xa;
      throw new Error("Activation " + t + " has not been implemented for the WebGL backend.");
    }

    var Lu = 600;

    var Wu = function (t) {
      function o(e) {
        var n,
          r = t.call(this) || this;
        if (r.gpgpu = e, r.pendingRead = new WeakMap(), r.pendingDisposal = new WeakSet(), r.dataRefCount = new WeakMap(), r.numBytesInGPU = 0, r.uploadWaitMs = 0, r.downloadWaitMs = 0, r.warnedAboutMemory = !1, r.pendingDeletes = 0, r.disposed = !1, !a().getBool("HAS_WEBGL")) throw new Error("WebGL is not supported on this device");

        if (null == e) {
          var o = Ut(a().getNumber("WEBGL_VERSION"));
          r.binaryCache = (n = a().getNumber("WEBGL_VERSION")) in Bu ? Bu[n] : (Bu[n] = {}, Bu[n]), r.gpgpu = new Ci(o), r.canvas = o.canvas, r.gpgpuCreatedLocally = !0;
        } else r.binaryCache = {}, r.gpgpuCreatedLocally = !1, r.canvas = e.gl.canvas;

        return r.textureManager = new tu(r.gpgpu), r.numMBBeforeWarning = null == a().global.screen ? 1024 : a().global.screen.height * a().global.screen.width * window.devicePixelRatio * Lu / 1024 / 1024, r.texData = new so(r, Nt), r;
      }

      return e(o, t), o.prototype.numDataIds = function () {
        return this.texData.numDataIds() + (this.cpuBackend ? this.cpuBackend.numDataIds() : 0) - this.pendingDeletes;
      }, o.prototype.fromPixels = function (t, e) {
        if (null == t) throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
        var n = "undefined" != typeof OffscreenCanvas && t instanceof OffscreenCanvas || "undefined" != typeof HTMLCanvasElement && t instanceof HTMLCanvasElement,
          r = t.data instanceof Uint8Array,
          o = "undefined" != typeof ImageData && t instanceof ImageData,
          i = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement,
          u = "undefined" != typeof HTMLImageElement && t instanceof HTMLImageElement,
          s = i ? [t.videoWidth, t.videoHeight] : [t.width, t.height],
          c = s[0],
          l = s[1],
          h = [l, c],
          f = [l, c, e];
        if (!(n || r || o || i || u)) throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was " + t.constructor.name);
        (u || i) && (null == this.fromPixels2DContext && (this.fromPixels2DContext = Vt(a().getNumber("WEBGL_VERSION")).getContext("2d")), this.fromPixels2DContext.canvas.width = c, this.fromPixels2DContext.canvas.height = l, this.fromPixels2DContext.drawImage(t, 0, 0, c, l), t = this.fromPixels2DContext.canvas);
        var p,
          d,
          v = this.makeTensorInfo(h, "int32");
        return this.texData.get(v.dataId).usage = Mt.PIXELS, this.gpgpu.uploadPixelDataToTexture(this.getTexture(v.dataId), t), a().getBool("WEBGL_PACK") ? (p = new ei(f), d = this.compileAndRun(p, [v])) : (p = new ti(f), d = this.compileAndRun(p, [v])), this.disposeData(v.dataId), d;
      }, o.prototype.write = function (t, e, n) {
        if (a().getBool("DEBUG") && this.checkNumericalProblems(t), "complex64" === n && null != t) throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
        var r = {};
        return this.texData.set(r, {
          shape: e,
          dtype: n,
          values: t,
          usage: Mt.UPLOAD
        }), r;
      }, o.prototype.move = function (t, e, n, r) {
        if (a().getBool("DEBUG") && this.checkNumericalProblems(e), "complex64" === r) throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
        this.texData.set(t, {
          shape: n,
          dtype: r,
          values: e,
          usage: Mt.UPLOAD
        });
      }, o.prototype.readSync = function (t) {
        var e = this.texData.get(t),
          n = e.values,
          r = e.dtype,
          o = e.complexTensors,
          a = e.slice,
          i = e.shape,
          u = e.isPacked;

        if (null != a) {
          var s = void 0;
          s = u ? new _u(i, Du) : new su(i, Du);
          var c = this.runWebGLProgram(s, [{
            dataId: t,
            shape: i,
            dtype: r
          }], r),
            l = this.readSync(c.dataId);
          return this.disposeData(c.dataId), l;
        }

        if (null != n) return this.convertAndCacheOnCPU(t);
        if ("string" === r) return n;
        var h,
          f,
          p = null != this.activeTimers;
        (p && (h = Y()), "complex64" === r) ? f = No(o.real.dataSync(), o.imag.dataSync()) : f = this.getValuesFromTexture(t);
        return p && (this.downloadWaitMs += Y() - h), this.convertAndCacheOnCPU(t, f);
      }, o.prototype.read = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o, i, u, s, c, l, h, f, p, d, v, m, g, y, x, b, C, E, R, I;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                if (this.pendingRead.has(t)) return e = this.pendingRead.get(t), [2, new Promise(function (t) {
                  return e.push(t);
                })];
                if (n = this.texData.get(t), o = n.values, i = n.shape, u = n.slice, s = n.dtype, c = n.complexTensors, l = n.isPacked, null != u) return h = void 0, h = l ? new _u(i, Du) : new su(i, Du), f = this.runWebGLProgram(h, [{
                  dataId: t,
                  shape: i,
                  dtype: s
                }], s), p = this.read(f.dataId), this.disposeData(f.dataId), [2, p];
                if (null != o) return [2, this.convertAndCacheOnCPU(t)];
                if (!a().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED") && 2 === a().getNumber("WEBGL_VERSION")) throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");
                return d = null, "complex64" !== s && a().get("WEBGL_BUFFER_SUPPORTED") && (v = this.decode(t), m = this.texData.get(v.dataId), d = (I = this.gpgpu).createBufferFromTexture.apply(I, [m.texture].concat(Gt(i)))), this.pendingRead.set(t, []), "complex64" === s ? [3, 2] : [4, this.gpgpu.createAndWaitForFence()];

              case 1:
                r.sent(), r.label = 2;

              case 2:
                return "complex64" !== s ? [3, 4] : [4, Promise.all([c.real.data(), c.imag.data()])];

              case 3:
                return y = r.sent(), x = y[0], b = y[1], g = No(x, b), [3, 5];

              case 4:
                null == d ? g = this.getValuesFromTexture(t) : (C = w(i), g = this.gpgpu.downloadFloat32MatrixFromBuffer(d, C)), r.label = 5;

              case 5:
                return null != v && this.disposeData(v.dataId), E = this.convertAndCacheOnCPU(t, g), R = this.pendingRead.get(t), this.pendingRead.delete(t), R.forEach(function (t) {
                  return t(E);
                }), this.pendingDisposal.has(t) && (this.pendingDisposal.delete(t), this.disposeData(t), this.pendingDeletes--), [2, E];
            }
          });
        });
      }, o.prototype.checkNumericalProblems = function (t) {
        if (null != t) for (var e = 0; e < t.length; e++) {
          var n = t[e];

          if (!$t(n)) {
            if (a().getBool("WEBGL_RENDER_FLOAT32_CAPABLE")) throw Error("The value " + n + " cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'");
            throw Error("The value " + n + " cannot be represented on this device.");
          }
        }
      }, o.prototype.getValuesFromTexture = function (t) {
        var e,
          n = this.texData.get(t),
          r = n.shape,
          o = n.dtype,
          i = n.isPacked,
          u = w(r);

        if (a().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")) {
          var s = this.decode(t),
            c = this.texData.get(s.dataId),
            l = (e = this.gpgpu).downloadMatrixFromPackedTexture.apply(e, [c.texture].concat(Gt(r))).subarray(0, u);
          return this.disposeData(s.dataId), l;
        }

        var h = a().getBool("WEBGL_PACK") && !0 === i,
          f = h ? Re(r) : r,
          p = h ? new ja(f) : new Ka(f),
          d = this.runWebGLProgram(p, [{
            shape: f,
            dtype: o,
            dataId: t
          }], "float32"),
          v = this.texData.get(d.dataId),
          m = this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(v.texture, v.texShape[0], v.texShape[1]).subarray(0, u);
        return this.disposeData(d.dataId), m;
      }, o.prototype.time = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o, a, i, u, s;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return e = this.activeTimers, n = [], o = !1, null == this.programTimersStack ? (this.programTimersStack = n, o = !0) : this.activeTimers.push(n), this.activeTimers = n, t(), a = b(this.activeTimers.map(function (t) {
                  return t.query;
                })).filter(function (t) {
                  return null != t;
                }), i = b(this.activeTimers.map(function (t) {
                  return t.name;
                })).filter(function (t) {
                  return null != t;
                }), this.activeTimers = e, o && (this.programTimersStack = null), [4, Promise.all(a)];

              case 1:
                return u = r.sent(), s = {
                  uploadWaitMs: this.uploadWaitMs,
                  downloadWaitMs: this.downloadWaitMs,
                  kernelMs: m(u),
                  getExtraProfileInfo: function () {
                    return u.map(function (t, e) {
                      return {
                        name: i[e],
                        ms: t
                      };
                    }).map(function (t) {
                      return t.name + ": " + t.ms;
                    }).join(", ");
                  },
                  wallMs: null
                }, this.uploadWaitMs = 0, this.downloadWaitMs = 0, [2, s];
            }
          });
        });
      }, o.prototype.memory = function () {
        return {
          unreliable: !1,
          numBytesInGPU: this.numBytesInGPU
        };
      }, o.prototype.startTimer = function () {
        return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? this.gpgpu.beginQuery() : {
          startMs: Y(),
          endMs: null
        };
      }, o.prototype.endTimer = function (t) {
        return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (this.gpgpu.endQuery(), t) : (t.endMs = Y(), t);
      }, o.prototype.getQueryTime = function (t) {
        return n(this, void 0, void 0, function () {
          var e;
          return r(this, function (n) {
            return a().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? [2, this.gpgpu.waitForQueryAndGetTime(t)] : [2, (e = t).endMs - e.startMs];
          });
        });
      }, o.prototype.disposeData = function (t) {
        if (!this.pendingDisposal.has(t)) {
          if (this.pendingRead.has(t)) return this.pendingDisposal.add(t), void this.pendingDeletes++;

          if (this.texData.has(t)) {
            this.releaseGPUData(t);
            var e = this.texData.get(t).complexTensors;
            null != e && (e.real.dispose(), e.imag.dispose()), this.texData.delete(t);
          }
        }
      }, o.prototype.releaseGPUData = function (t) {
        var e = this.texData.get(t),
          n = e.texture,
          r = e.dtype,
          o = e.texShape,
          a = e.usage,
          i = e.isPacked,
          u = e.slice,
          s = u && u.origDataId || t,
          c = this.dataRefCount.get(s);
        c > 1 ? this.dataRefCount.set(s, c - 1) : (this.dataRefCount.delete(s), null != n && (this.numBytesInGPU -= this.computeBytes(o, r), this.textureManager.releaseTexture(n, o, a, i)));
        var l = this.texData.get(t);
        l.texture = null, l.texShape = null, l.isPacked = !1, l.slice = null;
      }, o.prototype.getTexture = function (t) {
        return this.uploadToGPU(t), this.texData.get(t).texture;
      }, o.prototype.getDataInfo = function (t) {
        return this.texData.get(t);
      }, o.prototype.getCPUBackend = function () {
        return a().getBool("WEBGL_CPU_FORWARD") ? (null == this.cpuBackend && (this.cpuBackend = Nt.findBackend("cpu")), this.cpuBackend) : null;
      }, o.prototype.shouldExecuteOnCPU = function (t, e) {
        var n = this;
        return void 0 === e && (e = 128), null != this.getCPUBackend() && t.every(function (t) {
          return null == n.texData.get(t.dataId).texture && t.size < e;
        });
      }, o.prototype.getGPGPUContext = function () {
        return this.gpgpu;
      }, o.prototype.complex = function (t, e) {
        var n = this.makeOutput(t.shape, "complex64");
        return this.texData.get(n.dataId).complexTensors = {
          real: Nt.keep(t.clone()),
          imag: Nt.keep(e.clone())
        }, n;
      }, o.prototype.real = function (t) {
        return this.texData.get(t.dataId).complexTensors.real.clone();
      }, o.prototype.imag = function (t) {
        return this.texData.get(t.dataId).complexTensors.imag.clone();
      }, o.prototype.slice = function (t, e, n) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.slice(t, e, n);
        if (0 === w(n)) return kn([], n, t.dtype);
        var r = this.texData.get(t.dataId).isPacked,
          o = Yr(t.shape, e, n);

        if (r || !o) {
          var i = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Ji(n) : new Yi(n),
            u = i.getCustomSetupFunc(e);
          return this.compileAndRun(i, [t], null, u);
        }

        return this.uploadToGPU(t.dataId), this.shallowSlice(t, e, n);
      }, o.prototype.shallowSlice = function (t, e, n) {
        var r = this.texData.get(t.dataId),
          o = this.makeOutput(n, t.dtype),
          a = this.texData.get(o.dataId);
        Object.assign(a, r), a.shape = n, a.dtype = t.dtype;
        var i = Qr(e, t.strides);
        r.slice && (i += r.slice.flatOffset), a.slice = {
          flatOffset: i,
          origDataId: r.slice && r.slice.origDataId || t.dataId
        };
        var u = this.dataRefCount.get(a.slice.origDataId) || 1;
        return this.dataRefCount.set(a.slice.origDataId, u + 1), o;
      }, o.prototype.stridedSlice = function (t, e, n, r) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.stridedSlice(t, e, n, r);
        var o = jr(e, n, r);
        if (o.some(function (t) {
          return 0 === t;
        })) return kn([], o);
        var a = new Zi(e, r, o);
        return this.compileAndRun(a, [t]);
      }, o.prototype.reverse = function (t, e) {
        var n = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Ki(t.shape, e) : new qi(t.shape, e);
        return this.compileAndRun(n, [t]);
      }, o.prototype.concat = function (t, e) {
        if ("complex64" === t[0].dtype) {
          var n = t.map(function (t) {
            return Rn(t);
          }),
            r = t.map(function (t) {
              return In(t);
            });
          return En(this.concat(n, e), this.concat(r, e));
        }

        if (this.shouldExecuteOnCPU(t)) return this.cpuBackend.concat(t, e);
        if (1 === t.length) return t[0];

        if (t.length > a().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")) {
          var o = Math.floor(t.length / 2),
            i = this.concat(t.slice(0, o), e),
            u = this.concat(t.slice(o), e);
          return this.concat([i, u], e);
        }

        if (a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") && t[0].rank > 1) {
          var s = new Sa(t.map(function (t) {
            return t.shape;
          }), e);
          return this.compileAndRun(s, t);
        }

        var c = wn(t.map(function (t) {
          return t.shape;
        }), e),
          l = t.map(function (t) {
            return t.as2D(-1, w(t.shape.slice(e)));
          }),
          h = new ka(l.map(function (t) {
            return t.shape;
          }));
        return this.compileAndRun(h, l).reshape(c);
      }, o.prototype.neg = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.neg(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, mu, t.dtype);
        var e = new su(t.shape, mu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.batchMatMul = function (t, e, n, r) {
        var o = n ? t.shape[2] : t.shape[1],
          a = r ? e.shape[1] : e.shape[2],
          i = n ? t.shape[1] : t.shape[2],
          u = t.shape[0];

        if ((1 === o || 1 === a) && i > 1e3) {
          n && (t = t.transpose([0, 2, 1])), r && (e = e.transpose([0, 2, 1]));
          var s = 1 === a ? t : t.as3D(u, i, 1),
            c = 1 === a ? 2 : 1,
            l = 1 === a ? e.as3D(u, 1, i) : e;
          return this.multiply(s, l).sum(c, !0);
        }

        var h = Ct(t.dtype, e.dtype),
          f = new Ti(t.shape, [u, o, a], n, r);
        return this.compileAndRun(f, [t, e], h);
      }, o.prototype.fusedBatchMatMul = function (t) {
        var e = t.a,
          n = t.b,
          r = t.transposeA,
          o = t.transposeB,
          a = t.bias,
          i = t.activation,
          u = t.preluActivationWeights,
          s = r ? e.shape[2] : e.shape[1],
          c = o ? n.shape[1] : n.shape[2],
          l = e.shape[0],
          h = Ct(e.dtype, n.dtype),
          f = null != a,
          p = null != u,
          d = i ? Pu(i, !0) : null,
          v = new Ti(e.shape, [l, s, c], r, o, f, d, p),
          m = [e, n];
        return a && m.push(a), u && m.push(u), this.compileAndRun(v, m, h);
      }, o.prototype.multiply = function (t, e) {
        if ("complex64" === t.dtype) {
          var n = this.texData.get(t.dataId),
            r = this.texData.get(e.dataId),
            o = new va(pa, t.shape, e.shape),
            i = new va(da, t.shape, e.shape),
            u = [this.makeComplexComponentTensorInfo(t, n.complexTensors.real), this.makeComplexComponentTensorInfo(t, n.complexTensors.imag), this.makeComplexComponentTensorInfo(e, r.complexTensors.real), this.makeComplexComponentTensorInfo(e, r.complexTensors.imag)],
            s = this.compileAndRun(o, u),
            c = this.compileAndRun(i, u),
            l = this.complex(s, c);
          return s.dispose(), c.dispose(), l;
        }

        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.multiply(t, e);
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ya, t.dtype);
        var h = new ba(ya, t.shape, e.shape);
        return this.compileAndRun(h, [t, e], t.dtype);
      }, o.prototype.batchNormalization = function (t, e, n, r, o, i) {
        var u = [t, e, n],
          s = null;
        null != i && (s = i.shape, u.push(i));
        var c = null;

        if (null != o && (c = o.shape, u.push(o)), a().getBool("WEBGL_PACK_NORMALIZATION")) {
          var l = new fa(t.shape, e.shape, n.shape, s, c, r);
          return this.compileAndRun(l, u);
        }

        var h = new ha(t.shape, e.shape, n.shape, s, c, r);
        return this.compileAndRun(h, u);
      }, o.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
        var i = a().getBool("WEBGL_PACK_NORMALIZATION") ? new Si(t.shape, e, n, r, o) : new Ii(t.shape, e, n, r, o);
        return this.compileAndRun(i, [t]);
      }, o.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
        var u = new ki(e.shape, r, o, a, i);
        return this.compileAndRun(u, [e, n, t]);
      }, o.prototype.tile = function (t, e) {
        if ("string" === t.dtype) {
          var n = this.readSync(t.dataId).map(function (t) {
            return Z(t);
          });
          return Lo(ur(t.shape, t.dtype, n), e);
        }

        var r = new ru(t.shape, e);
        return this.compileAndRun(r, [t]);
      }, o.prototype.pad = function (t, e, n) {
        var r = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Mi(t.shape, e, n) : new _i(t.shape, e, n);
        return this.compileAndRun(r, [t]);
      }, o.prototype.transpose = function (t, e) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.transpose(t, e);
        var n = a().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new au(t.shape, e) : new ou(t.shape, e);
        return this.compileAndRun(n, [t]);
      }, o.prototype.gather = function (t, e, n) {
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.gather(t, e, n);
        var r = new ni(t.shape, e.size, n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.batchToSpaceND = function (t, e, n) {
        g(t.rank <= 4, function () {
          return "batchToSpaceND for rank > 4 with a WebGL backend not implemented yet";
        });
        var r = e.reduce(function (t, e) {
          return t * e;
        }),
          o = Mr(t.shape, e, r),
          a = Br(o.length, e.length),
          i = Pr(t.shape, e, r),
          u = Lr(n, e.length),
          s = Wr(i, n, e.length);
        return t.reshape(o).transpose(a).reshape(i).slice(u, s);
      }, o.prototype.spaceToBatchND = function (t, e, n) {
        g(t.rank <= 4, function () {
          return "spaceToBatchND for rank > 4 with a WebGL backend not implemented yet";
        });
        var r = e.reduce(function (t, e) {
          return t * e;
        }),
          o = [[0, 0]];
        o.push.apply(o, n);

        for (var a = 1 + e.length; a < t.shape.length; ++a) o.push([0, 0]);

        var i = t.pad(o),
          u = Mr(i.shape, e, r, !1),
          s = Br(u.length, e.length, !1),
          c = Pr(i.shape, e, r, !1);
        return i.reshape(u).transpose(s).reshape(c);
      }, o.prototype.reduce = function (t, e, n) {
        var r = t.shape[0],
          o = t.shape[1],
          a = zr(o),
          i = new Li({
            windowSize: a,
            inSize: o,
            batchSize: r
          }, e),
          u = this.compileAndRun(i, [t], n);
        return 1 === u.shape[1] ? u : this.reduce(u, e, n);
      }, o.prototype.argReduce = function (t, e, n) {
        void 0 === n && (n = null);
        var r = t.shape[0],
          o = t.shape[1];
        null != n && (r = n.shape[0], o = n.shape[1]);
        var a = zr(o),
          i = new Go({
            windowSize: a,
            inSize: o,
            batchSize: r
          }, e, null == n),
          u = [t];
        null != n && u.push(n);
        var s = this.compileAndRun(i, u, "int32");
        return 1 === s.shape[1] ? s : this.argReduce(t, e, s);
      }, o.prototype.argReducePacked = function (t, e, n) {
        void 0 === n && (n = null);
        var r = null != n ? n.shape : t.shape,
          o = zr(r[r.length - 1]),
          a = new sa(r, o, e, null == n),
          i = null == n ? [t] : [t, n],
          u = this.compileAndRun(a, i, "int32");
        return u.rank === t.rank ? this.argReducePacked(t, e, u) : u;
      }, o.prototype.sum = function (t, e) {
        mn("sum", e, t.rank);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o),
          i = Et(t.dtype);
        return this.reduce(a, "sum", i).reshape(r);
      }, o.prototype.prod = function (t, e) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.prod(t, e);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o),
          i = Et(t.dtype);
        return this.reduce(a, "prod", i).reshape(r);
      }, o.prototype.unsortedSegmentSum = function (t, e, n) {
        var r = 0,
          o = gn([r], t.rank),
          a = t;
        null != o && (a = t.transpose(o), r = xn(1, t.rank)[0]);

        var i = function (t, e, n) {
          for (var r = [], o = t.length, a = 0; a < o; a++) a !== e ? r.push(t[a]) : r.push(n);

          return r;
        }(a.shape, r, n),
          u = w([a.shape[r]]),
          s = a.as2D(-1, u),
          c = Et(t.dtype),
          l = this.segOpCompute(s, "unsortedSegmentSum", e, c, n).reshape(i);

        return null != o && (l = l.transpose(yn(o))), l;
      }, o.prototype.segOpCompute = function (t, e, n, r, o) {
        var a = t.shape[0],
          i = t.shape[1],
          u = function (t, e) {
            var n,
              r = !1;

            for (t <= Vr ? (n = t, r = !0) : n = H(t, Math.floor(Math.sqrt(t))); !r;) n > e || n === t ? r = !0 : n = H(t, n + 1);

            return n;
          }(i, o),
          s = new Xi({
            windowSize: u,
            inSize: i,
            batchSize: a,
            numSegments: o
          }, e),
          c = this.compileAndRun(s, [t, n], r);

        return c.shape[1] === o ? c : (n = Un(0, o).tile([i / u]), this.segOpCompute(c, e, n, r, o));
      }, o.prototype.argMinMaxReduce = function (t, e, n) {
        var r = [e];

        if (mn("arg" + n.charAt(0).toUpperCase() + n.slice(1), r, t.rank), !a().getBool("WEBGL_PACK_REDUCE") || t.rank <= 2) {
          var o = dn(t.shape, r),
            i = o[0],
            u = w(o[1]),
            s = t.as2D(-1, u);
          return this.argReduce(s, n).reshape(i);
        }

        return this.argReducePacked(t, n);
      }, o.prototype.argMin = function (t, e) {
        return this.argMinMaxReduce(t, e, "min");
      }, o.prototype.argMax = function (t, e) {
        return this.argMinMaxReduce(t, e, "max");
      }, o.prototype.cumsum = function (t, e, n, r) {
        if (e !== t.rank - 1) throw new Error("WebGL cumsum shader expects an inner-most axis=" + (t.rank - 1) + " but got axis=" + e);
        var o = new Ua(t.shape, n, r);
        return this.compileAndRun(o, [t]);
      }, o.prototype.equal = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(equal(a, b));\n", "bool");
        var n = new ba("return float(a == b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.notEqual = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(notEqual(a, b));\n", "bool");
        var n = new ba("return float(a != b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.less = function (t, e) {
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.less(t, e);
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(lessThan(a, b));\n", "bool");
        var n = new ba("return float(a < b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.lessEqual = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(lessThanEqual(a, b));\n", "bool");
        var n = new ba("return float(a <= b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.greater = function (t, e) {
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.greater(t, e);
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(greaterThan(a, b));\n", "bool");
        var n = new ba("return float(a > b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.greaterEqual = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(greaterThanEqual(a, b));\n", "bool");
        var n = new ba("return float(a >= b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.logicalNot = function (t) {
        var e = new su(t.shape, "return float(!(x >= 1.0));");
        return this.compileAndRun(e, [t]);
      }, o.prototype.logicalAnd = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return vec4(\n    vec4(greaterThanEqual(a, vec4(1.0))) *\n    vec4(greaterThanEqual(b, vec4(1.0))));\n", "bool");
        var n = new ba("return float(a >= 1.0 && b >= 1.0);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.logicalOr = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  return min(\n    vec4(greaterThanEqual(a, vec4(1.0))) +\n    vec4(greaterThanEqual(b, vec4(1.0))),\n    vec4(1.0));\n", "bool");
        var n = new ba("return float(a >= 1.0 || b >= 1.0);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "bool");
      }, o.prototype.select = function (t, e, n) {
        var r = new $i(t.rank, e.shape, e.rank);
        return this.compileAndRun(r, [t, e, n], Ct(e.dtype, n.dtype));
      }, o.prototype.where = function (t) {
        un("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");
        var e = t.dataSync();
        return Uo(t.shape, e);
      }, o.prototype.topk = function (t, e, n) {
        return Wo(t.dataSync(), t.shape, t.dtype, e);
      }, o.prototype.min = function (t, e) {
        mn("min", e, t.rank);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o);
        return this.reduce(a, "min", a.dtype).reshape(r);
      }, o.prototype.minimum = function (t, e) {
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.minimum(t, e);
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  vec4 result = vec4(min(a, b));\n  vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n  \n  result.r = isNaN.r > 0. ? NAN : result.r;\n  result.g = isNaN.g > 0. ? NAN : result.g;\n  result.b = isNaN.b > 0. ? NAN : result.b;\n  result.a = isNaN.a > 0. ? NAN : result.a;\n\n  return result;\n", t.shape, e.shape) : new ba("\n  if (isnan(a)) return a;\n  if (isnan(b)) return b;\n\n  return min(a, b);\n", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.mod = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  vec4 result = mod(a, b);\n  vec4 isNaN = vec4(equal(b, vec4(0.0)));\n  \n  result.r = isNaN.r > 0. ? NAN : result.r;\n  result.g = isNaN.g > 0. ? NAN : result.g;\n  result.b = isNaN.b > 0. ? NAN : result.b;\n  result.a = isNaN.a > 0. ? NAN : result.a;\n\n  return result;\n", t.shape, e.shape) : new ba("if (b == 0.0) return NAN;\n  return mod(a, b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.max = function (t, e) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.max(t, e);
        mn("max", e, t.rank);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o);
        return this.reduce(a, "max", a.dtype).reshape(r);
      }, o.prototype.maximum = function (t, e) {
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.maximum(t, e);
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  vec4 result = vec4(max(a, b));\n  vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n  \n  result.r = isNaN.r > 0. ? NAN : result.r;\n  result.g = isNaN.g > 0. ? NAN : result.g;\n  result.b = isNaN.b > 0. ? NAN : result.b;\n  result.a = isNaN.a > 0. ? NAN : result.a;\n\n  return result;\n", t.shape, e.shape) : new ba("\n  if (isnan(a)) return a;\n  if (isnan(b)) return b;\n\n  return max(a, b);\n", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.all = function (t, e) {
        mn("all", e, t.rank);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o);
        return this.reduce(a, "all", a.dtype).reshape(r);
      }, o.prototype.any = function (t, e) {
        mn("any", e, t.rank);
        var n = dn(t.shape, e),
          r = n[0],
          o = w(n[1]),
          a = t.as2D(-1, o);
        return this.reduce(a, "any", a.dtype).reshape(r);
      }, o.prototype.squaredDifference = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("return (a - b) * (a - b);", t.shape, e.shape) : new ba("return (a - b) * (a - b);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.realDivide = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) {
          return this.packedBinaryOp(t, e, "\n  // vec4 one = vec4(equal(a, b));\n  // return one + (vec4(1.0) - one) * a / b;\n  vec4 result = a / b;\n  if(a.x == b.x) {\n    result.x = 1.;\n  }\n  if(a.y == b.y) {\n    result.y = 1.;\n  }\n  if(a.z == b.z) {\n    result.z = 1.;\n  }\n  if(a.w == b.w) {\n    result.w = 1.;\n  }\n\n  return result;\n", "float32", !0);
        }

        var n = new ba("\nif (a == b) {\n  return 1.0;\n};\nreturn a / b;", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "float32");
      }, o.prototype.floorDiv = function (t, e) {
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, "\n  ivec4 ia = round(a);\n  ivec4 ib = round(b);\n  bvec4 cond = notEqual(ib, ivec4(0));\n  ivec4 result = ivec4(0);\n  vec4 s = sign(a) * sign(b);\n\n  // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n  if (cond[0]) {\n    result[0] = idiv(ia[0], ib[0], s[0]);\n  }\n  if (cond[1]) {\n    result[1] = idiv(ia[1], ib[1], s[1]);\n  }\n  if (cond[2]) {\n    result[2] = idiv(ia[2], ib[2], s[2]);\n  }\n  if (cond[3]) {\n    result[3] = idiv(ia[3], ib[3], s[3]);\n  }\n  return vec4(result);\n", "int32");
        var n = new ba("\n  float s = sign(a) * sign(b);\n  int ia = round(a);\n  int ib = round(b);\n  if (ib != 0) {\n    // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n    return float(idiv(ia, ib, s));\n  } else {\n    return NAN;\n  }\n", t.shape, e.shape);
        return this.compileAndRun(n, [t, e], "int32");
      }, o.prototype.add = function (t, e) {
        if ("complex64" === t.dtype && "complex64" === e.dtype) return this.complexSeparableBinaryOp(t, e, ma);
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.add(t, e);
        var n = Ct(t.dtype, e.dtype);
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ma, n);
        var r = new ba(ma, t.shape, e.shape);
        return this.compileAndRun(r, [t, e], n);
      }, o.prototype.packedUnaryOp = function (t, e, n) {
        var r = new _u(t.shape, e);
        return this.compileAndRun(r, [t], n);
      }, o.prototype.packedBinaryOp = function (t, e, n, r, o) {
        void 0 === o && (o = !1);
        var a = new Ca(n, t.shape, e.shape, o);
        return this.compileAndRun(a, [t, e], r);
      }, o.prototype.complexSeparableBinaryOp = function (t, e, n) {
        var r = this,
          o = this.texData.get(t.dataId),
          a = this.texData.get(e.dataId),
          i = [[o.complexTensors.real, a.complexTensors.real], [o.complexTensors.imag, a.complexTensors.imag]].map(function (o) {
            var a = o[0],
              i = o[1],
              u = r.makeComplexComponentTensorInfo(t, a),
              s = r.makeComplexComponentTensorInfo(e, i),
              c = new ba(n, t.shape, e.shape);
            return r.compileAndRun(c, [u, s], Ct(a.dtype, i.dtype));
          }),
          u = i[0],
          s = i[1],
          c = this.complex(u, s);
        return u.dispose(), s.dispose(), c;
      }, o.prototype.makeComplexComponentTensorInfo = function (t, e) {
        return {
          dataId: e.dataId,
          dtype: e.dtype,
          shape: t.shape
        };
      }, o.prototype.addN = function (t) {
        if (1 === t.length) return t[0];

        if (t.length > a().get("WEBGL_MAX_TEXTURES_IN_SHADER")) {
          var e = Math.floor(t.length / 2),
            n = this.addN(t.slice(0, e)),
            r = this.addN(t.slice(e));
          return this.addN([n, r]);
        }

        var o = t.map(function (t) {
          return t.dtype;
        }).reduce(function (t, e) {
          return Ct(t, e);
        }),
          i = t.map(function (t) {
            return t.shape;
          }),
          u = a().getBool("WEBGL_PACK") ? new zo(t[0].shape, i) : new Vo(t[0].shape, i);
        return this.compileAndRun(u, t, o);
      }, o.prototype.subtract = function (t, e) {
        if ("complex64" === t.dtype && "complex64" === e.dtype) return this.complexSeparableBinaryOp(t, e, ga);
        if (this.shouldExecuteOnCPU([t, e])) return this.cpuBackend.subtract(t, e);
        var n = Ct(t.dtype, e.dtype);
        if (a().getBool("WEBGL_PACK_BINARY_OPERATIONS")) return this.packedBinaryOp(t, e, ga, t.dtype);
        var r = new ba(ga, t.shape, e.shape);
        return this.compileAndRun(r, [t, e], n);
      }, o.prototype.pow = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.\n  vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));\n  vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);\n  vec4 result = multiplier * pow(abs(a), b);\n\n  // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS\n  bvec4 isExpZero = equal(b, vec4(0.0));\n  result.r = isExpZero.r ? 1.0 : result.r;\n  result.g = isExpZero.g ? 1.0 : result.g;\n  result.b = isExpZero.b ? 1.0 : result.b;\n  result.a = isExpZero.a ? 1.0 : result.a;\n\n  vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));\n  \n  result.r = isNaN.r > 0. ? NAN : result.r;\n  result.g = isNaN.g > 0. ? NAN : result.g;\n  result.b = isNaN.b > 0. ? NAN : result.b;\n  result.a = isNaN.a > 0. ? NAN : result.a;\n\n  return result;\n", t.shape, e.shape) : new ba("\nif(a < 0.0 && floor(b) < b){\n  return NAN;\n}\nif (b == 0.0) {\n  return 1.0;\n}\nreturn (round(mod(b, 2.0)) != 1) ?\n    pow(abs(a), b) : sign(a) * pow(abs(a), b);\n", t.shape, e.shape),
          r = Ct(t.dtype, e.dtype);
        return this.compileAndRun(n, [t, e], r);
      }, o.prototype.ceil = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.ceil(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, gu, t.dtype);
        var e = new su(t.shape, gu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.floor = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.floor(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, yu, t.dtype);
        var e = new su(t.shape, yu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.sign = function (t) {
        var e = new su(t.shape, "\n  if (isnan(x)) { return 0.0; }\n  return sign(x);\n");
        return this.compileAndRun(e, [t]);
      }, o.prototype.isNaN = function (t) {
        var e = new su(t.shape, "return float(isnan(x));");
        return this.compileAndRun(e, [t], "bool");
      }, o.prototype.isInf = function (t) {
        var e = new su(t.shape, "return float(isinf(x));");
        return this.compileAndRun(e, [t], "bool");
      }, o.prototype.isFinite = function (t) {
        var e = new su(t.shape, "return float(!isnan(x) && !isinf(x));");
        return this.compileAndRun(e, [t], "bool");
      }, o.prototype.round = function (t) {
        var e = new su(t.shape, "\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");
        return this.compileAndRun(e, [t]);
      }, o.prototype.exp = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.exp(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, xu, t.dtype);
        var e = new su(t.shape, xu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.expm1 = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.expm1(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, bu, t.dtype);
        var e = new su(t.shape, bu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.log = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.log(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, "\n  vec4 result = log(x);\n  vec4 isNaN = vec4(lessThan(x, vec4(0.0)));\n  result.r = isNaN.r == 1.0 ? NAN : result.r;\n  result.g = isNaN.g == 1.0 ? NAN : result.g;\n  result.b = isNaN.b == 1.0 ? NAN : result.b;\n  result.a = isNaN.a == 1.0 ? NAN : result.a;\n\n  return result;\n", t.dtype);
        var e = new su(t.shape, "if (x < 0.0) return NAN;\n  return log(x);");
        return this.compileAndRun(e, [t]);
      }, o.prototype.log1p = function (t) {
        var e = new su(t.shape, "return log(1.0 + x);");
        return this.compileAndRun(e, [t]);
      }, o.prototype.sqrt = function (t) {
        var e = new su(t.shape, "return sqrt(x);");
        return this.compileAndRun(e, [t]);
      }, o.prototype.rsqrt = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.rsqrt(t);
        var e = new su(t.shape, "return inversesqrt(x);");
        return this.compileAndRun(e, [t]);
      }, o.prototype.reciprocal = function (t) {
        var e = new su(t.shape, "return 1.0 / x;");
        return this.compileAndRun(e, [t]);
      }, o.prototype.relu = function (t) {
        var e;
        return e = a().getBool("WEBGL_PACK") ? new _u(t.shape, Nu) : new su(t.shape, fu), this.compileAndRun(e, [t]);
      }, o.prototype.relu6 = function (t) {
        var e;
        return e = a().getBool("WEBGL_PACK") ? new _u(t.shape, Fu) : new su(t.shape, pu), this.compileAndRun(e, [t]);
      }, o.prototype.prelu = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca(wa, t.shape, e.shape) : new ba(xa, t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.elu = function (t) {
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, Ou, t.dtype);
        var e = new su(t.shape, du);
        return this.compileAndRun(e, [t]);
      }, o.prototype.eluDer = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));\n  return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));\n", t.shape, e.shape) : new ba("return (b >= 1.0) ? a : a * (b + 1.0);", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.selu = function (t) {
        var e = new su(t.shape, vu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.int = function (t) {
        var e = new su(t.shape, "return float(int(x));");
        return this.compileAndRun(e, [t], "int32");
      }, o.prototype.clip = function (t, e, n) {
        var r,
          o = (r = a().getBool("WEBGL_PACK_CLIP") ? new Ra(t.shape) : new Ea(t.shape)).getCustomSetupFunc(e, n);
        return this.compileAndRun(r, [t], null, o);
      }, o.prototype.abs = function (t) {
        if (this.shouldExecuteOnCPU([t])) return this.cpuBackend.abs(t);
        if (a().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, hu, t.dtype);
        var e = new su(t.shape, hu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.complexAbs = function (t) {
        var e = this.texData.get(t.dataId),
          n = new Ia(t.shape),
          r = [this.makeComplexComponentTensorInfo(t, e.complexTensors.real), this.makeComplexComponentTensorInfo(t, e.complexTensors.imag)];
        return this.compileAndRun(n, r);
      }, o.prototype.sigmoid = function (t) {
        var e = new su(t.shape, "return 1.0 / (1.0 + exp(-1.0 * x));");
        return this.compileAndRun(e, [t]);
      }, o.prototype.softplus = function (t) {
        var e = new su(t.shape, "\n  float epsilon = 1.1920928955078125e-7;\n  float threshold = log(epsilon) + 2.0;\n\n  bool too_large = x > -threshold;\n  bool too_small = x < threshold;\n\n  float result;\n  float exp_x = exp(x);\n\n  if (too_large){\n    result = x;\n  }\n  else if (too_small){\n    result = exp_x;\n  }\n  else{\n    result = log(exp_x + 1.0);\n  }\n  return result;\n");
        return this.compileAndRun(e, [t]);
      }, o.prototype.sin = function (t) {
        var e = new su(t.shape, wu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.cos = function (t) {
        var e = new su(t.shape, Cu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.tan = function (t) {
        var e = new su(t.shape, "return tan(x);");
        return this.compileAndRun(e, [t]);
      }, o.prototype.asin = function (t) {
        var e = new su(t.shape, Eu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.acos = function (t) {
        var e = new su(t.shape, Ru);
        return this.compileAndRun(e, [t]);
      }, o.prototype.atan = function (t) {
        var e = new su(t.shape, Iu);
        return this.compileAndRun(e, [t]);
      }, o.prototype.atan2 = function (t, e) {
        var n = a().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new Ca("\n  vec4 result = atan(a, b);\n  vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n  \n  result.r = isNaN.r > 0. ? NAN : result.r;\n  result.g = isNaN.g > 0. ? NAN : result.g;\n  result.b = isNaN.b > 0. ? NAN : result.b;\n  result.a = isNaN.a > 0. ? NAN : result.a;\n\n  return result;\n", t.shape, e.shape) : new ba("\n  if (isnan(a)) return a;\n  if (isnan(b)) return b;\n\n  return atan(a, b);\n", t.shape, e.shape);
        return this.compileAndRun(n, [t, e]);
      }, o.prototype.sinh = function (t) {
        var e = new su(t.shape, "\n  float e2x = exp(x);\n  return (e2x - 1.0 / e2x) / 2.0;\n");
        return this.compileAndRun(e, [t]);
      }, o.prototype.cosh = function (t) {
        var e = new su(t.shape, "\n  float e2x = exp(-x);\n  return (e2x + 1.0 / e2x) / 2.0;\n");
        return this.compileAndRun(e, [t]);
      }, o.prototype.tanh = function (t) {
        var e = new su(t.shape, "\n  float e2x = exp(-2.0 * abs(x));\n  return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n");
        return this.compileAndRun(e, [t]);
      }, o.prototype.asinh = function (t) {
        var e = new su(t.shape, ku);
        return this.compileAndRun(e, [t]);
      }, o.prototype.acosh = function (t) {
        var e = new su(t.shape, Su);
        return this.compileAndRun(e, [t]);
      }, o.prototype.atanh = function (t) {
        var e = new su(t.shape, Au);
        return this.compileAndRun(e, [t]);
      }, o.prototype.erf = function (t) {
        var e = new su(t.shape, '\n  // Error function is calculated approximately with elementary function.\n  // See "Handbook of Mathematical Functions with Formulas,\n  // Graphs, and Mathematical Tables", Abramowitz and Stegun.\n  float p = 0.3275911;\n  float a1 = 0.254829592;\n  float a2 = -0.284496736;\n  float a3 = 1.421413741;\n  float a4 = -1.453152027;\n  float a5 = 1.061405429;\n\n  float sign = sign(x);\n  x = abs(x);\n  float t = 1.0 / (1.0 + p * x);\n  return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));\n');
        return this.compileAndRun(e, [t]);
      }, o.prototype.step = function (t, e) {
        var n = new su(t.shape, function (t) {
          return void 0 === t && (t = 0), cu + "\n    return x > 0.0 ? 1.0 : float(" + t + ");\n  ";
        }(e));
        return this.compileAndRun(n, [t]);
      }, o.prototype.conv2dByMatMul = function (t, e, n, r, o, i) {
        var u = t.shape,
          s = this.texData.get(t.dataId),
          c = n.inChannels,
          l = u[0] * u[1] * u[2],
          h = n.outChannels,
          f = "channelsLast" === n.dataFormat,
          p = (1 === l || 1 === h) && c > 1e3,
          d = u[2] % 2 != 0 && !!s.isPacked;

        if (p || !a().getBool("WEBGL_LAZILY_UNPACK") || !a().getBool("WEBGL_PACK_BINARY_OPERATIONS") || !d) {
          var v = f ? u[0] * u[1] * u[2] : u[0] * u[2] * u[3],
            m = this.reshape(t, [1, v, n.inChannels]),
            y = this.reshape(e, [1, n.inChannels, n.outChannels]);
          return this.reshape(this.fusedBatchMatMul({
            a: m,
            b: y,
            transposeA: !1,
            transposeB: !1,
            bias: r,
            activation: o,
            preluActivationWeights: i
          }), n.outShape);
        }

        var x = f ? u[0] * u[1] * (u[2] + 1) : u[0] * u[2] * (u[3] + 1),
          b = {
            dataId: t.dataId,
            shape: [1, x, n.inChannels],
            dtype: t.dtype
          },
          w = s.shape;
        s.shape = s.shape.slice(), s.shape[s.shape.length - 2]++, g(Se(s.shape, b.shape), function () {
          return "packed reshape " + s.shape + " to " + b.shape + " isn't free";
        });
        var C = this.reshape(e, [1, n.inChannels, n.outChannels]),
          E = this.fusedBatchMatMul({
            a: b,
            b: C,
            transposeA: !1,
            transposeB: !1,
            bias: r,
            activation: o,
            preluActivationWeights: i
          }),
          R = this.texData.get(E.dataId);
        return g(R.isPacked, function () {
          return "batchMatMul result is expected to be packed";
        }), s.shape = w, R.shape = n.outShape, Nt.makeTensorFromDataId(E.dataId, n.outShape, E.dtype);
      }, o.prototype.conv2dWithIm2Row = function (t, e, n, r, o, a) {
        var i = n.filterWidth,
          u = n.filterHeight,
          s = n.inChannels,
          c = n.outWidth,
          l = n.outHeight,
          h = "channelsLast" === n.dataFormat,
          f = i * u * s,
          p = l * c,
          d = [f, p],
          v = t.squeeze([0]),
          m = e.reshape([1, f, -1]),
          g = new Ri(d, v.shape, n),
          y = this.compileAndRun(g, [v]).reshape([1, d[0], d[1]]),
          x = null != r,
          b = null != a,
          w = o ? Pu(o, !0) : null,
          C = new Ti(y.shape, [1, p, n.outChannels], !0, !1, x, w, b),
          E = [y, m];
        r && E.push(r), b && E.push(a);
        var R = this.compileAndRun(C, E);
        return h ? R.reshape([1, l, c, n.outChannels]) : R.reshape([1, n.outChannels, l, c]);
      }, o.prototype.fusedConv2d = function (t) {
        var e = t.input,
          n = t.filter,
          r = t.convInfo,
          o = t.bias,
          i = t.activation,
          u = t.preluActivationWeights;
        if (1 === r.filterHeight && 1 === r.filterWidth && 1 === r.dilationHeight && 1 === r.dilationWidth && 1 === r.strideHeight && 1 === r.strideWidth && ("SAME" === r.padInfo.type || "VALID" === r.padInfo.type)) return this.conv2dByMatMul(e, n, r, o, i, u);
        if (a().getBool("WEBGL_CONV_IM2COL") && 1 === e.shape[0]) return this.conv2dWithIm2Row(e, n, r, o, i, u);
        var s = null != o,
          c = null != u,
          l = i ? Pu(i, !1) : null,
          h = new Ma(r, s, l, c),
          f = [e, n];
        return o && f.push(o), u && f.push(u), this.compileAndRun(h, f);
      }, o.prototype.conv2d = function (t, e, n) {
        if (1 === n.filterHeight && 1 === n.filterWidth && 1 === n.dilationHeight && 1 === n.dilationWidth && 1 === n.strideHeight && 1 === n.strideWidth && ("SAME" === n.padInfo.type || "VALID" === n.padInfo.type)) return this.conv2dByMatMul(t, e, n);
        if (a().getBool("WEBGL_CONV_IM2COL") && 1 === t.shape[0]) return this.conv2dWithIm2Row(t, e, n);
        var r = new Ma(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.conv2dDerInput = function (t, e, n) {
        var r = new Ta(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.conv2dDerFilter = function (t, e, n) {
        var r = new Da(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.fusedDepthwiseConv2D = function (t) {
        var e,
          n = t.input,
          r = t.filter,
          o = t.convInfo,
          i = t.bias,
          u = t.activation,
          s = t.preluActivationWeights,
          c = a().getBool("WEBGL_PACK_DEPTHWISECONV") && o.strideWidth <= 2 && o.outChannels / o.inChannels == 1,
          l = u ? Pu(u, c) : null,
          h = [n, r],
          f = null != i,
          p = null != s;
        return f && h.push(i), p && h.push(s), c ? (e = new La(o, f, l, p), this.compileAndRun(e, h)) : (e = new Pa(o, f, l, p), this.compileAndRun(e, h));
      }, o.prototype.depthwiseConv2D = function (t, e, n) {
        var r;
        return a().getBool("WEBGL_PACK_DEPTHWISECONV") && n.strideWidth <= 2 && n.outChannels / n.inChannels == 1 ? (r = new La(n), this.compileAndRun(r, [t, e])) : (r = new Pa(n), this.compileAndRun(r, [t, e]));
      }, o.prototype.depthwiseConv2DDerInput = function (t, e, n) {
        var r = new _a(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
        var r = new Oa(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.conv3d = function (t, e, n) {
        var r = new Ba(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.conv3dDerInput = function (t, e, n) {
        var r = new Fa(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.conv3dDerFilter = function (t, e, n) {
        var r = new Na(n);
        return this.compileAndRun(r, [t, e]);
      }, o.prototype.maxPool = function (t, e) {
        var n = new Bi(e, "max", !1);
        return this.compileAndRun(n, [t]);
      }, o.prototype.avgPool = function (t, e) {
        var n = new Bi(e, "avg", !1);
        return this.compileAndRun(n, [t], "float32");
      }, o.prototype.maxPoolBackprop = function (t, e, n, r) {
        var o = new Bi(r, "max", !0),
          a = this.compileAndRun(o, [e]),
          i = new Ai(r),
          u = this.compileAndRun(i, [t, a], e.dtype);
        return a.dispose(), u;
      }, o.prototype.avgPoolBackprop = function (t, e, n) {
        var r = new ca(n);
        return this.compileAndRun(r, [t], e.dtype);
      }, o.prototype.cast = function (t, e) {
        return So(t, e, this);
      }, o.prototype.unstack = function (t, e) {
        for (var n = t.shape[e], r = new Array(t.rank - 1), o = 0, a = 0; a < t.rank; a++) a !== e && (r[o++] = t.shape[a]);

        var i = new Array(t.rank).fill(0),
          u = t.shape.slice();
        u[e] = 1;
        var s = new Array(n);

        for (a = 0; a < s.length; a++) i[e] = a, s[a] = this.slice(t, i, u).reshape(r);

        return s;
      }, o.prototype.avgPool3d = function (t, e) {
        var n = new Pi(e, "avg", !1);
        return this.compileAndRun(n, [t], "float32");
      }, o.prototype.avgPool3dBackprop = function (t, e, n) {
        var r = new la(n);
        return this.compileAndRun(r, [t], e.dtype);
      }, o.prototype.maxPool3d = function (t, e) {
        var n = new Pi(e, "max", !1);
        return this.compileAndRun(n, [t], "float32");
      }, o.prototype.maxPool3dBackprop = function (t, e, n, r) {
        var o = new Pi(r, "max", !0),
          a = this.compileAndRun(o, [e]),
          i = new Di(r),
          u = this.compileAndRun(i, [t, a], e.dtype);
        return a.dispose(), u;
      }, o.prototype.reshape = function (t, e) {
        var n = this.texData.get(t.dataId);

        if (n.isPacked && !Se(t.shape, e) && (null === n.texture || !Se(n.shape, e))) {
          var r = this.packedReshape(t, e);
          return Nt.makeTensorFromDataId(r.dataId, r.shape, r.dtype);
        }

        return Ao(t, e);
      }, o.prototype.resizeBilinear = function (t, e, n, r) {
        var o = a().getBool("WEBGL_PACK_IMAGE_OPERATIONS") ? new zi(t.shape, e, n, r) : new Vi(t.shape, e, n, r);
        return this.compileAndRun(o, [t]);
      }, o.prototype.resizeBilinearBackprop = function (t, e, n) {
        var r = new Ui(t, e, n);
        return this.compileAndRun(r, [t]);
      }, o.prototype.resizeNearestNeighbor = function (t, e, n, r) {
        var o = new Hi(t.shape, e, n, r);
        return this.compileAndRun(o, [t]);
      }, o.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
        var r = new Gi(t, e, n);
        return this.compileAndRun(r, [t]);
      }, o.prototype.multinomial = function (t, e, n, r) {
        var o = e ? t : io(t),
          a = o.shape[0],
          i = o.shape[1],
          u = new Ni(a, i, n),
          s = u.getCustomSetupFunc(r);
        return this.compileAndRun(u, [o], "int32", s);
      }, o.prototype.oneHot = function (t, e, n, r) {
        var o = new Fi(t.size, e, n, r);
        return this.compileAndRun(o, [t]);
      }, o.prototype.diag = function (t) {
        var e = new qa(t.size);
        return this.compileAndRun(e, [t]);
      }, o.prototype.nonMaxSuppression = function (t, e, n, r, o) {
        return un("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"), Mo(t.dataSync(), e.dataSync(), n, r, o);
      }, o.prototype.cropAndResize = function (t, e, n, r, o, a) {
        var i = new Wa(t.shape, e.shape, r, o, a);
        return this.compileAndRun(i, [t, e, n]);
      }, o.prototype.depthToSpace = function (t, e, n) {
        g(e > 1, function () {
          return "blockSize should be > 1 for depthToSpace, but was: " + e;
        });
        var r = t.shape[0],
          o = "NHWC" === n ? t.shape[1] : t.shape[2],
          a = "NHWC" === n ? t.shape[2] : t.shape[3],
          i = "NHWC" === n ? t.shape[3] : t.shape[1],
          u = o * e,
          s = a * e,
          c = i / (e * e),
          l = new Ha("NHWC" === n ? [r, u, s, c] : [r, c, u, s], e, n);
        return this.compileAndRun(l, [t]);
      }, o.prototype.split = function (t, e, n) {
        return Po(t, e, n);
      }, o.prototype.scatterND = function (t, e, n) {
        var r = Hr(0, t, n),
          o = r.sliceRank,
          a = r.numUpdates,
          i = r.sliceSize,
          u = r.strides,
          s = r.outputSize,
          c = [s / i, i],
          l = t.reshape([a, o]),
          h = e.reshape([a, i]);
        if (0 === s) return Ao(kn([]), n);
        var f = An(0),
          p = new ji(a, o, l.rank, h.rank, u, c);
        return this.compileAndRun(p, [h, l, f]).reshape(n);
      }, o.prototype.sparseToDense = function (t, e, n, r) {
        var o = Hr(0, t, n),
          a = o.sliceRank,
          i = o.numUpdates,
          u = o.strides,
          s = o.outputSize,
          c = new ji(i, a, t.rank, e.rank, u, [s, 1], !1);
        return this.compileAndRun(c, [e, t, r]).reshape(n);
      }, o.prototype.fft = function (t) {
        return this.fftImpl(t, !1);
      }, o.prototype.ifft = function (t) {
        return this.fftImpl(t, !0);
      }, o.prototype.fftImpl = function (t, e) {
        var n = this.texData.get(t.dataId),
          r = new Ja(Ya, t.shape, e),
          o = new Ja(Qa, t.shape, e),
          a = [this.makeComplexComponentTensorInfo(t, n.complexTensors.real), this.makeComplexComponentTensorInfo(t, n.complexTensors.imag)],
          i = this.compileAndRun(r, a),
          u = this.compileAndRun(o, a),
          s = this.complex(i, u).as2D(t.shape[0], t.shape[1]);
        return i.dispose(), u.dispose(), s;
      }, o.prototype.gatherND = function (t, e) {
        var n = e.shape,
          r = n[n.length - 1],
          o = Ur(t, e),
          a = o[0],
          i = o[1],
          u = o[2],
          s = o[3],
          c = e.reshape([i, r]),
          l = t.reshape([t.size / u, u]),
          h = new ri(r, s, [i, u]);
        return this.compileAndRun(h, [l, c]).reshape(a);
      }, o.prototype.fill = function (t, e, n) {
        if ("string" === (n = n || z(e))) {
          var r = F(n, w(t));
          return r.fill(e), Nt.makeTensor(r, t, n, this);
        }

        var o = new Za(t, e),
          a = o.getCustomSetupFunc(e);
        return this.compileAndRun(o, [], n, a);
      }, o.prototype.onesLike = function (t) {
        if ("string" === t.dtype) throw new Error("onesLike is not supported under string dtype");
        return this.fill(t.shape, 1, t.dtype);
      }, o.prototype.zerosLike = function (t) {
        return this.fill(t.shape, "string" === t.dtype ? "" : 0, t.dtype);
      }, o.prototype.linspace = function (t, e, n) {
        return Do(t, e, n);
      }, o.prototype.makeTensorInfo = function (t, e) {
        var n = this.write(null, t, e);
        return this.texData.get(n).usage = null, {
          dataId: n,
          shape: t,
          dtype: e
        };
      }, o.prototype.makeOutput = function (t, e) {
        var n = this.makeTensorInfo(t, e).dataId;
        return Nt.makeTensorFromDataId(n, t, e, this);
      }, o.prototype.unpackTensor = function (t) {
        var e = new Mu(t.shape);
        return this.runWebGLProgram(e, [t], t.dtype);
      }, o.prototype.packTensor = function (t) {
        var e = new Oi(t.shape);
        return this.runWebGLProgram(e, [t], t.dtype, null, !0);
      }, o.prototype.packedReshape = function (t, e) {
        var n = [Ce(t.shape)].concat(Ee(t.shape)),
          r = {
            dtype: t.dtype,
            shape: n,
            dataId: t.dataId
          },
          o = [Ce(e)].concat(Ee(e)),
          a = new Wi(o, n),
          i = this.runWebGLProgram(a, [r], t.dtype, null, !0);
        return {
          dataId: i.dataId,
          shape: e,
          dtype: i.dtype
        };
      }, o.prototype.decode = function (t) {
        var e,
          n = this.texData.get(t),
          r = n.isPacked,
          o = n.shape,
          a = n.dtype,
          i = Re(o);
        e = r ? new Ga(i) : new za(i);
        return {
          dtype: a,
          shape: o,
          dataId: this.runWebGLProgram(e, [{
            shape: i,
            dtype: a,
            dataId: t
          }], a, null, !0).dataId
        };
      }, o.prototype.runWebGLProgram = function (t, e, n, r, o) {
        var i = this;
        void 0 === o && (o = !1);
        var u = this.makeTensorInfo(t.outputShape, n),
          s = this.texData.get(u.dataId);

        if (t.packedOutput && (s.isPacked = !0), t.outPackingScheme === _t.DENSE) {
          var c = Gt(t.outputShape);
          s.texShape = c.map(function (t) {
            return 2 * t;
          });
        }

        if (null != t.outTexUsage && (s.usage = t.outTexUsage), 0 === w(u.shape)) return s.values = N(u.dtype, 0), u;
        var l = [],
          h = e.map(function (e) {
            if ("complex64" === e.dtype) throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
            var n = i.texData.get(e.dataId);

            if (null == n.texture) {
              if (!t.packedInputs && w(e.shape) <= a().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM")) return {
                shape: e.shape,
                texData: null,
                isUniform: !0,
                uniformValues: n.values
              };
              t.packedInputs && (n.isPacked = !0, n.shape = e.shape);
            } else if (!!n.isPacked != !!t.packedInputs) e = n.isPacked ? i.unpackTensor(e) : i.packTensor(e), l.push(e), n = i.texData.get(e.dataId); else if (n.isPacked && !Se(n.shape, e.shape)) {
              var r = e,
                o = e.shape;
              e.shape = n.shape, e = i.packedReshape(e, o), l.push(e), n = i.texData.get(e.dataId), r.shape = o;
            }

            return i.uploadToGPU(e.dataId), {
              shape: e.shape,
              texData: n,
              isUniform: !1
            };
          });
        this.uploadToGPU(u.dataId);

        var f,
          p = {
            shape: u.shape,
            texData: s,
            isUniform: !1
          },
          d = function (t, e, n) {
            var r = "";
            e.concat(n).forEach(function (t) {
              var e = null != t.texData && null != t.texData.slice && t.texData.slice.flatOffset > 0,
                n = t.isUniform ? "uniform" : t.texData.texShape;
              r += t.shape + "_" + n + "_" + e;
            });
            var o = t.userCode,
              a = t.constructor.name;
            return a += "_" + r + "_" + o;
          }(t, h, p),
          v = this.getAndSaveBinary(d, function () {
            return function (t, e, n, r) {
              var o = e.userCode,
                i = n.map(function (t, n) {
                  var r = {
                    logicalShape: t.shape,
                    texShape: t.isUniform ? null : t.texData.texShape,
                    isUniform: t.isUniform,
                    isPacked: !t.isUniform && t.texData.isPacked,
                    flatOffset: null
                  };
                  return null != t.texData && null != t.texData.slice && t.texData.slice.flatOffset > 0 && (r.flatOffset = t.texData.slice.flatOffset), {
                    name: e.variableNames[n],
                    shapeInfo: r
                  };
                }),
                u = i.map(function (t) {
                  return t.shapeInfo;
                }),
                s = {
                  logicalShape: r.shape,
                  texShape: r.texData.texShape,
                  isUniform: !1,
                  isPacked: r.texData.isPacked,
                  flatOffset: null
                },
                c = Yo(i, s, o, e.packedInputs),
                l = t.createProgram(c),
                h = null,
                f = t.getUniformLocation(l, "NAN", !1);
              1 === a().getNumber("WEBGL_VERSION") && (h = t.getUniformLocation(l, "INFINITY", !1));

              for (var p = {}, d = 0; d < e.variableNames.length; d++) {
                var v = e.variableNames[d];
                p[v] = t.getUniformLocation(l, v, !1), p["offset" + v] = t.getUniformLocation(l, "offset" + v, !1);
              }

              return {
                program: e,
                source: c,
                webGLProgram: l,
                uniformLocations: p,
                inShapeInfos: u,
                outShapeInfo: s,
                infLoc: h,
                nanLoc: f
              };
            }(i.gpgpu, t, h, p);
          }),
          m = null != this.activeTimers;

        if (m && (f = this.startTimer()), function (t, e, n, r, o) {
          Ei(e.inShapeInfos, n), Ei([e.outShapeInfo], [r]);
          var i = r.texData.texture,
            u = r.texData.texShape;
          r.texData.isPacked ? t.setOutputPackedMatrixTexture(i, u[0], u[1]) : t.setOutputMatrixTexture(i, u[0], u[1]), t.setProgram(e.webGLProgram), 1 === a().getNumber("WEBGL_VERSION") && null !== e.infLoc && t.gl.uniform1f(e.infLoc, 1 / 0), null !== e.nanLoc && t.gl.uniform1f(e.nanLoc, NaN), n.forEach(function (n, r) {
            var o = e.program.variableNames[r],
              a = e.uniformLocations[o],
              i = e.uniformLocations["offset" + o];
            if (null != a) if (n.isUniform) {
              if (w(n.shape) < 2) t.gl.uniform1f(a, n.uniformValues[0]); else {
                var u = n.uniformValues;
                u instanceof Float32Array || (u = new Float32Array(u)), t.gl.uniform1fv(a, u);
              }
            } else null != n.texData.slice && null != i && t.gl.uniform1i(i, n.texData.slice.flatOffset), t.setInputMatrixTexture(n.texData.texture, a, r);
          }), null != o && o(t, e.webGLProgram), t.executeProgram();
        }(this.gpgpu, v, h, p, r), l.forEach(function (t) {
          return i.disposeData(t.dataId);
        }), m && (f = this.endTimer(f), this.activeTimers.push({
          name: t.constructor.name,
          query: this.getQueryTime(f)
        })), !a().getBool("WEBGL_LAZILY_UNPACK") && s.isPacked && !1 === o) {
          var g = this.unpackTensor(u);
          return this.disposeData(u.dataId), g;
        }

        return u;
      }, o.prototype.compileAndRun = function (t, e, n, r, o) {
        void 0 === o && (o = !1), n = n || e[0].dtype;
        var a = this.runWebGLProgram(t, e, n, r, o);
        return Nt.makeTensorFromDataId(a.dataId, a.shape, a.dtype);
      }, o.prototype.getAndSaveBinary = function (t, e) {
        return t in this.binaryCache || (this.binaryCache[t] = e()), this.binaryCache[t];
      }, o.prototype.getTextureManager = function () {
        return this.textureManager;
      }, o.prototype.dispose = function () {
        this.disposed || (this.textureManager.dispose(), null != this.canvas && "undefined" != typeof HTMLCanvasElement && this.canvas instanceof HTMLCanvasElement ? this.canvas.remove() : this.canvas = null, null != this.fromPixels2DContext && this.fromPixels2DContext.canvas.remove && this.fromPixels2DContext.canvas.remove(), this.gpgpuCreatedLocally && (this.gpgpu.program = null, this.gpgpu.dispose()), this.disposed = !0);
      }, o.prototype.floatPrecision = function () {
        var t = this;
        return null == this.floatPrecisionValue && (this.floatPrecisionValue = je(function () {
          if (!a().get("WEBGL_RENDER_FLOAT32_ENABLED")) {
            var e = a().getBool("DEBUG");
            a().set("DEBUG", !1);
            var n = t.abs(An(1e-8)).dataSync()[0];
            if (a().set("DEBUG", e), n > 0) return 32;
          }

          return 16;
        })), this.floatPrecisionValue;
      }, o.prototype.epsilon = function () {
        return 32 === this.floatPrecision() ? 1e-7 : 1e-4;
      }, o.prototype.uploadToGPU = function (t) {
        var e,
          n = this.texData.get(t),
          r = n.shape,
          o = n.dtype,
          a = n.values,
          i = n.texture,
          u = n.usage,
          s = n.isPacked;

        if (null == i) {
          var c,
            l = null != this.activeTimers;
          l && (c = Y());
          var h = n.texShape;

          if (null == h && (h = Ie(r, s), n.texShape = h), null != a) {
            var f = Re(r),
              p = void 0,
              d = h[1],
              v = h[0],
              m = a instanceof Uint8Array;
            s ? (d = (e = Ht(h[0], h[1]))[0], v = e[1], p = new $a(f, [v, d], m)) : p = new Xa(f, [v, d], m);
            var g = this.makeTensorInfo([v, d], o);
            this.texData.get(g.dataId).usage = m ? Mt.PIXELS : Mt.UPLOAD, this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(g.dataId), d, v, a);
            var y = this.runWebGLProgram(p, [g], o, null, !0),
              x = this.texData.get(y.dataId);
            n.texture = x.texture, n.texShape = x.texShape, n.isPacked = x.isPacked, n.usage = x.usage, this.disposeData(g.dataId), this.texData.delete(y.dataId), n.values = null, l && (this.uploadWaitMs += Y() - c);
          } else {
            var b = this.acquireTexture(h, u, o, s);
            n.texture = b;
          }
        }
      }, o.prototype.convertAndCacheOnCPU = function (t, e) {
        var n = this.texData.get(t),
          r = n.dtype;
        return this.releaseGPUData(t), null != e && (n.values = function (t, e) {
          if ("float32" === e || "complex64" === e) return t;

          if ("int32" === e || "bool" === e) {
            for (var n = "int32" === e ? new Int32Array(t.length) : new Uint8Array(t.length), r = 0; r < n.length; ++r) n[r] = Math.round(t[r]);

            return n;
          }

          throw new Error("Unknown dtype " + e);
        }(e, r)), n.values;
      }, o.prototype.acquireTexture = function (t, e, n, r) {
        if (this.numBytesInGPU += this.computeBytes(t, n), !this.warnedAboutMemory && this.numBytesInGPU > 1024 * this.numMBBeforeWarning * 1024) {
          var o = (this.numBytesInGPU / 1024 / 1024).toFixed(2);
          this.warnedAboutMemory = !0, console.warn("High memory usage in GPU: " + o + " MB, most likely due to a memory leak");
        }

        return this.textureManager.acquireTexture(t, e, r);
      }, o.prototype.computeBytes = function (t, e) {
        return t[0] * t[1] * P(e);
      }, o;
    }(co);

    Ft() && Nt.registerBackend("webgl", function () {
      return new Wu();
    }, 2);
    var Uu = Cn({
      square_: function (t) {
        var e = ln(t, "x", "square"),
          n = [e];
        return Nt.runKernelFunc(function (t, n) {
          return n([e]), t.square(e);
        }, {
          x: e
        }, function (t, e) {
          var n = e[0];
          return {
            x: function () {
              return t.mul(n.toFloat().mul(2));
            }
          };
        }, "Square", {}, n, []);
      }
    });
    exports.square = Uu;
    var Vu = Cn({
      abs_: function (t) {
        var e = ln(t, "x", "abs");
        return "complex64" === e.dtype ? Nt.runKernelFunc(function (t) {
          return t.complexAbs(e);
        }, {
          $x: e
        }) : Nt.runKernelFunc(function (t, n) {
          var r = t.abs(e);
          return n([e]), r;
        }, {
          x: e
        }, function (t, e) {
          var n = e[0];
          return {
            x: function () {
              return t.mul(n.toFloat().step(-1));
            }
          };
        }, "Abs");
      }
    }),
      zu = Cn({
        acos_: function (t) {
          var e = ln(t, "x", "acos");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.acos(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.divStrict(An(1).sub(n.toFloat().square()).sqrt()).neg();
              }
            };
          });
        }
      }),
      Gu = Cn({
        acosh_: function (t) {
          var e = ln(t, "x", "acosh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.acosh(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.divStrict(n.toFloat().square().sub(1).sqrt());
              }
            };
          });
        }
      }),
      Hu = Cn({
        asin_: function (t) {
          var e = ln(t, "x", "asin");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.asin(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.divStrict(An(1).sub(n.toFloat().square()).sqrt());
              }
            };
          });
        }
      }),
      qu = Cn({
        asinh_: function (t) {
          var e = ln(t, "x", "asinh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.asinh(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.divStrict(An(1).add(n.toFloat().square()).sqrt());
              }
            };
          });
        }
      }),
      Ku = Cn({
        atan_: function (t) {
          var e = ln(t, "x", "atan");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.atan(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.toFloat().square().add(1));
              }
            };
          });
        }
      }),
      ju = Cn({
        atanh_: function (t) {
          var e = ln(t, "x", "atanh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.atanh(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(An(1).sub(n.toFloat().square()));
              }
            };
          });
        }
      }),
      Xu = Cn({
        ceil_: function (t) {
          var e = ln(t, "x", "ceil");
          return Nt.runKernelFunc(function (t) {
            return t.ceil(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      $u = Cn({
        clipByValue_: function (t, e, n) {
          var r = ln(t, "x", "clipByValue");
          return g(e <= n, function () {
            return "Error in clip: min (" + e + ") must be less than or equal to max (" + n + ").";
          }), Nt.runKernelFunc(function (t, o) {
            var a = t.clip(r, e, n);
            return o([r]), a;
          }, {
            $x: r
          }, function (t, r) {
            var o = r[0];
            return {
              $x: function () {
                return t.where(o.greaterEqual(e).logicalAnd(o.lessEqual(n)), zn(t));
              }
            };
          });
        }
      }),
      Yu = Cn({
        cos_: function (t) {
          var e = ln(t, "x", "cos");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.cos(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return n.toFloat().sin().neg().mul(t);
              }
            };
          });
        }
      }),
      Qu = Cn({
        cosh_: function (t) {
          var e = ln(t, "x", "cosh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.cosh(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return n.toFloat().sinh().mulStrict(t);
              }
            };
          });
        }
      }),
      Ju = Cn({
        erf_: function (t) {
          var e = ln(t, "x", "erf");
          return g("int32" === e.dtype || "float32" === e.dtype, function () {
            return "Input dtype must be `int32` or `float32`.";
          }), "int32" === e.dtype && (e = e.toFloat()), Nt.runKernelFunc(function (t, n) {
            var r = t.erf(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.mul(n.square().neg().exp().mul(2 / Math.sqrt(Math.PI)));
              }
            };
          });
        }
      }),
      Zu = Cn({
        exp_: function (t) {
          var e = ln(t, "x", "exp");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.exp(e);
            return n([r]), r;
          }, {
            $x: e
          }, function (t, e) {
            return {
              $x: function () {
                return t.mulStrict(e[0]);
              }
            };
          });
        }
      }),
      ts = Cn({
        expm1_: function (t) {
          var e = ln(t, "x", "expm1");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.expm1(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.mul(n.exp());
              }
            };
          });
        }
      }),
      es = Cn({
        floor_: function (t) {
          var e = ln(t, "x", "floor");
          return Nt.runKernelFunc(function (t) {
            return t.floor(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      ns = Cn({
        log_: function (t) {
          var e = ln(t, "x", "log");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.log(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.toFloat());
              }
            };
          });
        }
      }),
      rs = Cn({
        log1p_: function (t) {
          var e = ln(t, "x", "log1p");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.log1p(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.add(1));
              }
            };
          });
        }
      }),
      os = Cn({
        logSigmoid_: function (t) {
          var e = ln(t, "x", "logSigmoid");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.softplus(e.neg()).neg();
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.mul(n.neg().sigmoid());
              }
            };
          });
        }
      }),
      as = Cn({
        neg_: function (t) {
          var e = ln(t, "x", "neg");
          return Nt.runKernelFunc(function (t) {
            return t.neg(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return t.neg();
              }
            };
          });
        }
      }),
      is = Cn({
        reciprocal_: function (t) {
          var e = ln(t, "x", "reciprocal");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.reciprocal(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.square().neg());
              }
            };
          });
        }
      }),
      us = Cn({
        round_: function (t) {
          var e = ln(t, "x", "round");
          return Nt.runKernelFunc(function (t) {
            return t.round(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      ss = Cn({
        rsqrt_: function (t) {
          var e = ln(t, "x", "rsqrt");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.rsqrt(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.pow(1.5).mul(2)).neg();
              }
            };
          });
        }
      }),
      cs = Cn({
        sigmoid_: function (t) {
          var e = ln(t, "x", "sigmoid");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.sigmoid(e);
            return n([r]), r;
          }, {
            x: e
          }, function (t, e) {
            var n = e[0];
            return {
              x: function () {
                return t.mul(n.mul(An(1).sub(n)));
              }
            };
          }, "Sigmoid");
        }
      }),
      ls = Cn({
        sign_: function (t) {
          var e = ln(t, "x", "sign");
          return Nt.runKernelFunc(function (t) {
            return t.sign(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      hs = Cn({
        isNaN_: function (t) {
          var e = ln(t, "x", "isNaN");
          return Nt.runKernelFunc(function (t) {
            return t.isNaN(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      fs = Cn({
        isInf_: function (t) {
          var e = ln(t, "x", "isInf");
          return Nt.runKernelFunc(function (t) {
            return t.isInf(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      ps = Cn({
        isFinite_: function (t) {
          var e = ln(t, "x", "isFinite");
          return Nt.runKernelFunc(function (t) {
            return t.isFinite(e);
          }, {
            $x: e
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      ds = Cn({
        sin_: function (t) {
          var e = ln(t, "x", "sin");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.sin(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return n.toFloat().cos().mul(t);
              }
            };
          });
        }
      }),
      vs = Cn({
        sinh_: function (t) {
          var e = ln(t, "x", "sinh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.sinh(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return n.toFloat().cosh().mulStrict(t);
              }
            };
          });
        }
      }),
      ms = Cn({
        softplus_: function (t) {
          var e = ln(t, "x", "softplus");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.softplus(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.mul(n.sigmoid());
              }
            };
          });
        }
      }),
      gs = Cn({
        sqrt_: function (t) {
          var e = ln(t, "x", "sqrt");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.sqrt(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.toFloat().sqrt().mul(2));
              }
            };
          });
        }
      }),
      ys = Cn({
        step_: function (t, e) {
          void 0 === e && (e = 0);
          var n = ln(t, "x", "step");
          return Nt.runKernelFunc(function (t) {
            return t.step(n, e);
          }, {
            $x: n
          }, function (t) {
            return {
              $x: function () {
                return zn(t);
              }
            };
          });
        }
      }),
      xs = Cn({
        tan_: function (t) {
          var e = ln(t, "x", "tan");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.tan(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.div(n.cos().square());
              }
            };
          });
        }
      }),
      bs = Cn({
        tanh_: function (t) {
          var e = ln(t, "x", "tanh");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.tanh(e);
            return n([r]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return An(1).sub(n.square()).mulStrict(t);
              }
            };
          });
        }
      });
    exports.tanh = bs;
    exports.tan = xs;
    exports.step = ys;
    exports.sqrt = gs;
    exports.softplus = ms;
    exports.sinh = vs;
    exports.sin = ds;
    exports.isFinite = ps;
    exports.isInf = fs;
    exports.isNaN = hs;
    exports.sign = ls;
    exports.sigmoid = cs;
    exports.rsqrt = ss;
    exports.round = us;
    exports.reciprocal = is;
    exports.neg = as;
    exports.logSigmoid = os;
    exports.log1p = rs;
    exports.log = ns;
    exports.floor = es;
    exports.expm1 = ts;
    exports.exp = Zu;
    exports.erf = Ju;
    exports.cosh = Qu;
    exports.cos = Yu;
    exports.clipByValue = $u;
    exports.ceil = Xu;
    exports.atanh = ju;
    exports.atan = Ku;
    exports.asinh = qu;
    exports.asin = Hu;
    exports.acosh = Gu;
    exports.acos = zu;
    exports.abs = Vu;

    function ws(t, e, n, r, o, a) {
      var i,
        u,
        s = ln(t, "x", "batchNorm"),
        c = ln(e, "mean", "batchNorm"),
        l = ln(n, "variance", "batchNorm");
      return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(2 === s.rank, function () {
        return "Error in batchNorm3D: x must be rank 3 but got rank " + s.rank + ".";
      }), g(2 === c.rank || 1 === c.rank, function () {
        return "Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank " + c.rank + ".";
      }), g(2 === l.rank || 1 === l.rank, function () {
        return "Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank " + l.rank + ".";
      }), null != i && g(2 === i.rank || 1 === i.rank, function () {
        return "Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank " + i.rank + ".";
      }), null != u && g(2 === u.rank || 1 === u.rank, function () {
        return "Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank " + u.rank + ".";
      }), Rs(s, c, l, u, i, a);
    }

    function Cs(t, e, n, r, o, a) {
      var i,
        u,
        s = ln(t, "x", "batchNorm"),
        c = ln(e, "mean", "batchNorm"),
        l = ln(n, "variance", "batchNorm");
      return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(3 === s.rank, function () {
        return "Error in batchNorm3D: x must be rank 3 but got rank " + s.rank + ".";
      }), g(3 === c.rank || 1 === c.rank, function () {
        return "Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank " + c.rank + ".";
      }), g(3 === l.rank || 1 === l.rank, function () {
        return "Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank " + l.rank + ".";
      }), null != i && g(3 === i.rank || 1 === i.rank, function () {
        return "Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank " + i.rank + ".";
      }), null != u && g(3 === u.rank || 1 === u.rank, function () {
        return "Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank " + u.rank + ".";
      }), Rs(s, c, l, u, i, a);
    }

    function Es(t, e, n, r, o, a) {
      var i,
        u,
        s = ln(t, "x", "batchNorm"),
        c = ln(e, "mean", "batchNorm"),
        l = ln(n, "variance", "batchNorm");
      return null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(4 === s.rank, function () {
        return "Error in batchNorm4D: x must be rank 4 but got rank " + s.rank + ".";
      }), g(4 === c.rank || 1 === c.rank, function () {
        return "Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank " + c.rank + ".";
      }), g(4 === l.rank || 1 === l.rank, function () {
        return "Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank " + l.rank + ".";
      }), null != i && g(4 === i.rank || 1 === i.rank, function () {
        return "Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank " + i.rank + ".";
      }), null != u && g(4 === u.rank || 1 === u.rank, function () {
        return "Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank " + u.rank + ".";
      }), Rs(s, c, l, u, i, a);
    }

    function Rs(t, e, n, r, o, a) {
      null == a && (a = .001);
      var i,
        u,
        s,
        c = ln(t, "x", "batchNorm"),
        l = ln(e, "mean", "batchNorm"),
        h = ln(n, "variance", "batchNorm");
      null != o && (i = ln(o, "scale", "batchNorm")), null != r && (u = ln(r, "offset", "batchNorm")), g(l.rank === h.rank, function () {
        return "Batch normalization gradient requires mean and variance to have equal ranks.";
      }), g(null == u || l.rank === u.rank, function () {
        return "Batch normalization gradient requires mean and offset to have equal ranks.";
      }), g(null == i || l.rank === i.rank, function () {
        return "Batch normalization gradient requires mean and scale to have equal ranks.";
      }), s = 0 === c.rank || 1 === c.rank ? c.as4D(1, 1, 1, c.size) : 2 === c.rank ? c.as4D(1, 1, c.shape[0], c.shape[1]) : 3 === c.rank ? c.as4D(1, c.shape[0], c.shape[1], c.shape[2]) : c;
      var f = [c, l, h, i];
      return Nt.runKernelFunc(function (t, e) {
        var n = t.batchNormalization(s, Is(l), Is(h), a, Is(i), Is(u));
        return e([c, l, h, i]), n;
      }, {
        x: c,
        mean: l,
        variance: h,
        scale: i,
        offset: u
      }, function (t, e) {
        var n = e,
          r = n[0],
          o = n[1],
          i = n[2],
          u = n[3],
          c = null == u ? An(1) : u,
          l = fo(o.shape, s.shape),
          h = [];

        if (1 === o.rank) {
          for (var f = 0; f < s.shape.length - 1; ++f) h.push(s.shape[f]);

          h.push(1);
        }

        var p = r.sub(o),
          d = t.mul(c),
          v = ss(i.add(An(a))),
          m = v.mul(v).mul(v).mul(An(-.5));
        return {
          x: function () {
            return 1 === o.rank ? t.mul(Nr(v.as4D(1, 1, 1, o.shape[0]), h)).mul(c).reshape(r.shape) : t.mul(v).mul(c).reshape(r.shape);
          },
          mean: function () {
            var t = v.mul(An(-1)).mul(d);
            return 1 === o.rank && (t = t.sum(l)), t.reshape(o.shape);
          },
          variance: function () {
            var t = m.mul(p).mul(d);
            return 1 === o.rank && (t = t.sum(l)), t.reshape(o.shape);
          },
          scale: function () {
            var e = p.mul(v),
              n = t.mul(e);
            return 1 === o.rank && (n = n.sum(l)), n.reshape(o.shape);
          },
          offset: function () {
            var e = t;
            return 1 === o.rank && (e = e.sum(l)), e.reshape(o.shape);
          }
        };
      }, "BatchNormalization", {
        varianceEpsilon: a
      }, f).reshape(c.shape);
    }

    function Is(t) {
      return null == t ? null : 0 === t.rank ? t.as1D() : 1 === t.rank ? t : 2 === t.rank ? t.as4D(1, 1, t.shape[0], t.shape[1]) : 3 === t.rank ? t.as4D(1, t.shape[0], t.shape[1], t.shape[2]) : t;
    }

    function ks() {
      ze("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon");
    }

    var Ss = Cn({
      batchNormalization2d_: function (t, e, n, r, o, a) {
        return void 0 === r && (r = .001), ks(), ws(t, e, n, a, o, r);
      }
    }),
      As = Cn({
        batchNormalization3d_: function (t, e, n, r, o, a) {
          return void 0 === r && (r = .001), ks(), Cs(t, e, n, a, o, r);
        }
      }),
      Ds = Cn({
        batchNormalization4d_: function (t, e, n, r, o, a) {
          return void 0 === r && (r = .001), ks(), Es(t, e, n, a, o, r);
        }
      }),
      Ts = Cn({
        batchNormalization_: function (t, e, n, r, o, a) {
          return void 0 === r && (r = .001), ks(), Rs(t, e, n, a, o, r);
        }
      }),
      Ns = Cn({
        batchNorm_: Rs
      }),
      Fs = Cn({
        batchNorm2d_: ws
      }),
      Os = Cn({
        batchNorm3d_: Cs
      }),
      _s = Cn({
        batchNorm4d_: Es
      });

    exports.batchNorm4d = _s;
    exports.batchNorm3d = Os;
    exports.batchNorm2d = Fs;
    exports.batchNorm = Ns;
    exports.batchNormalization = Ts;
    exports.batchNormalization4d = Ds;
    exports.batchNormalization3d = As;
    exports.batchNormalization2d = Ss;

    var Ms = Cn({
      logicalAnd_: function (t, e) {
        var n = ln(t, "a", "logicalAnd", "bool"),
          r = ln(e, "b", "logicalAnd", "bool");
        return po(n.shape, r.shape), Nt.runKernelFunc(function (t) {
          return t.logicalAnd(n, r);
        }, {
          $a: n,
          $b: r
        });
      }
    }),
      Bs = Cn({
        logicalNot_: function (t) {
          var e = ln(t, "x", "logicalNot", "bool");
          return Nt.runKernelFunc(function (t) {
            return t.logicalNot(e);
          }, {
            $x: e
          });
        }
      }),
      Ps = Cn({
        logicalOr_: function (t, e) {
          var n = ln(t, "a", "logicalOr", "bool"),
            r = ln(e, "b", "logicalOr", "bool");
          return po(n.shape, r.shape), Nt.runKernelFunc(function (t) {
            return t.logicalOr(n, r);
          }, {
            $a: n,
            $b: r
          });
        }
      }),
      Ls = Cn({
        logicalXor_: function (t, e) {
          var n = ln(t, "a", "logicalXor", "bool"),
            r = ln(e, "b", "logicalXor", "bool");
          return po(n.shape, r.shape), Ps(t, e).logicalAnd(Ms(t, e).logicalNot());
        }
      }),
      Ws = Cn({
        where_: function (t, e, n) {
          var r = ln(e, "a", "where"),
            o = ln(n, "b", "where"),
            a = ln(t, "condition", "where", "bool");
          return y(r.shape, o.shape, "Error in where: "), 1 === a.rank ? g(a.shape[0] === r.shape[0], function () {
            return "The first dimension of `a` must match the size of `condition`.";
          }) : y(a.shape, o.shape, "Error in where: "), Nt.runKernelFunc(function (t, e) {
            var n = t.select(a, r, o);
            return e([a]), n;
          }, {
            $condition: a,
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0];
            return {
              $condition: function () {
                return zn(n).toFloat();
              },
              $a: function () {
                return t.mul(n.cast(t.dtype));
              },
              $b: function () {
                return t.mul(n.logicalNot().cast(t.dtype));
              }
            };
          });
        }
      }),
      Us = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, (e = ln(t, "condition", "whereAsync", "bool")).data()];

              case 1:
                return n = r.sent(), o = Uo(e.shape, n), t !== e && e.dispose(), [2, o];
            }
          });
        });
      };

    exports.whereAsync = Us;
    exports.where = Ws;
    exports.logicalXor = Ls;
    exports.logicalOr = Ps;
    exports.logicalNot = Bs;
    exports.logicalAnd = Ms;
    var Vs = Cn({
      add_: function (t, e) {
        var n,
          r = ln(t, "a", "add"),
          o = ln(e, "b", "add");
        n = Rt(r, o), r = n[0], o = n[1];
        var a = po(r.shape, o.shape);
        return Nt.runKernelFunc(function (t) {
          return t.add(r, o);
        }, {
          a: r,
          b: o
        }, function (t) {
          return {
            a: function () {
              var e = t,
                n = fo(r.shape, a);
              return n.length > 0 && (e = e.sum(n)), e.reshape(r.shape);
            },
            b: function () {
              var e = t,
                n = fo(o.shape, a);
              return n.length > 0 && (e = e.sum(n)), e.reshape(o.shape);
            }
          };
        }, "Add");
      }
    }),
      zs = Cn({
        addN_: function (t) {
          g(Array.isArray(t), function () {
            return "The argument passed to tf.addN() must be a list of tensors";
          }), g(t.length >= 1, function () {
            return "Must pass at least one tensor to tf.addN(), but got " + t.length;
          });
          var e = t.map(function (t, e) {
            return ln(t, "tensors" + e, "addN");
          }),
            n = e[0];
          e.forEach(function (t) {
            if (t.dtype !== n.dtype) throw new Error("All tensors passed to tf.addN() must have the same dtype");
          }), e.forEach(function (t) {
            if (!C(t.shape, n.shape)) throw new Error("All tensors passed to tf.addN() must have the same shape");
          });
          var r = e;
          return Nt.runKernelFunc(function (t) {
            return t.addN(e);
          }, r, function (t) {
            var n = {};
            return e.forEach(function (e, r) {
              n[r] = function () {
                return t.clone();
              };
            }), n;
          });
        }
      }),
      Gs = Cn({
        addStrict_: function (t, e) {
          var n = ln(t, "a", "addStrict"),
            r = ln(e, "b", "addStrict");
          return y(n.shape, r.shape, "Error in addStrict: "), n.add(r);
        }
      }),
      Hs = Cn({
        atan2_: function (t, e) {
          var n,
            r = ln(t, "a", "atan2"),
            o = ln(e, "b", "atan2");
          n = Rt(r, o), r = n[0], o = n[1];
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t, e) {
            var n = t.atan2(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                var e = Vs(n.square(), r.square()),
                  o = t.mul(r.div(e)),
                  i = fo(n.shape, a);
                return i.length > 0 && (o = o.sum(i)), o.reshape(n.shape);
              },
              $b: function () {
                var e = Vs(n.square(), r.square()),
                  o = as(t.mul(n.div(e))),
                  i = fo(r.shape, a);
                return i.length > 0 && (o = o.sum(i)), o.reshape(r.shape);
              }
            };
          });
        }
      }),
      qs = Cn({
        div_: function (t, e) {
          var n,
            r = ln(t, "a", "div"),
            o = ln(e, "b", "div");
          if (n = Rt(r, o), r = n[0], o = n[1], "int32" === r.dtype && "int32" === o.dtype) return js(r, o);
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t, e) {
            var n = t.realDivide(r, o);
            return e([r, o]), n;
          }, {
            a: r,
            b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              a: function () {
                var e = t.div(r.toFloat()),
                  o = fo(n.shape, a);
                return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
              },
              b: function () {
                var e = t.mul(n.toFloat()),
                  o = fo(r.shape, a);
                o.length > 0 && (e = e.sum(o).reshape(r.shape));
                var i = r.square();
                return e.div(i.toFloat()).neg();
              }
            };
          }, "Div");
        }
      }),
      Ks = Cn({
        divStrict_: function (t, e) {
          var n = ln(t, "a", "div"),
            r = ln(e, "b", "div");
          return y(n.shape, r.shape, "Error in divideStrict: "), n.div(r);
        }
      }),
      js = Cn({
        floorDiv_: function (t, e) {
          var n,
            r = ln(t, "a", "floorDiv"),
            o = ln(e, "b", "floorDiv");
          n = Rt(r, o), r = n[0], o = n[1];
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t, e) {
            var n = t.floorDiv(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                var e = t.div(r.toFloat()),
                  o = fo(n.shape, a);
                return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
              },
              $b: function () {
                var e = t.mul(n.toFloat()),
                  o = fo(r.shape, a);
                o.length > 0 && (e = e.sum(o).reshape(r.shape));
                var i = r.square();
                return e.div(i.toFloat()).neg();
              }
            };
          });
        }
      }),
      Xs = Cn({
        maximum_: function (t, e) {
          var n,
            r = ln(t, "a", "maximum"),
            o = ln(e, "b", "maximum");
          return n = Rt(r, o), r = n[0], o = n[1], "bool" === r.dtype && (r = r.toInt(), o = o.toInt()), po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
            var n = t.maximum(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                return t.mul(n.greaterEqual(r).toFloat());
              },
              $b: function () {
                return t.mul(n.less(r).toFloat());
              }
            };
          });
        }
      }),
      $s = Cn({
        maximumStrict_: function (t, e) {
          var n = ln(t, "a", "maximumStrict"),
            r = ln(e, "b", "maximumStrict");
          return y(n.shape, r.shape, "Error in maximumStrict: "), n.maximum(r);
        }
      }),
      Ys = Cn({
        minimum_: function (t, e) {
          var n,
            r = ln(t, "a", "minimum"),
            o = ln(e, "b", "minimum");
          return n = Rt(r, o), r = n[0], o = n[1], "bool" === r.dtype && (r = r.toInt(), o = o.toInt()), po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
            var n = t.minimum(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                return t.mul(n.lessEqual(r).toFloat());
              },
              $b: function () {
                return t.mul(n.greater(r).toFloat());
              }
            };
          });
        }
      }),
      Qs = Cn({
        minimumStrict_: function (t, e) {
          var n = ln(t, "a", "minimumStrict"),
            r = ln(e, "b", "minimumStrict");
          return y(n.shape, r.shape, "Error in minimumStrict: "), n.minimum(r);
        }
      }),
      Js = Cn({
        mod_: function (t, e) {
          var n,
            r = ln(t, "a", "mod"),
            o = ln(e, "b", "mod");
          n = Rt(r, o), r = n[0], o = n[1];
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t, e) {
            var n = t.mod(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                var e = fo(n.shape, a);
                return e.length > 0 ? t.sum(e).reshape(n.shape) : t;
              },
              $b: function () {
                var e = t.mul(n.div(r).floor().neg()),
                  o = fo(r.shape, a);
                return o.length > 0 ? e.sum(o).reshape(r.shape) : e;
              }
            };
          });
        }
      }),
      Zs = Cn({
        modStrict_: function (t, e) {
          var n = ln(t, "a", "modStrict"),
            r = ln(e, "b", "modStrict");
          return y(n.shape, r.shape, "Error in modStrict: "), n.mod(r);
        }
      }),
      tc = Cn({
        mul_: function (t, e) {
          var n,
            r = ln(t, "a", "mul"),
            o = ln(e, "b", "mul");
          n = Rt(r, o), r = n[0], o = n[1];
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t, e) {
            var n = t.multiply(r, o);
            return e([r, o]), n;
          }, {
            a: r,
            b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              a: function () {
                var e = t.mul(r.toFloat()),
                  o = fo(n.shape, a);
                return o.length > 0 ? e.sum(o).reshape(n.shape) : e;
              },
              b: function () {
                var e = t.mul(n.toFloat()),
                  o = fo(r.shape, a);
                return o.length > 0 ? e.sum(o).reshape(r.shape) : e;
              }
            };
          }, "Mul");
        }
      }),
      ec = Cn({
        mulStrict_: function (t, e) {
          var n = ln(t, "a", "mul"),
            r = ln(e, "b", "mul");
          return y(n.shape, r.shape, "Error in multiplyStrict: "), n.mul(r);
        }
      }),
      nc = Cn({
        pow_: function (t, e) {
          var n = ln(t, "base", "pow"),
            r = ln(e, "exp", "pow"),
            o = po(n.shape, r.shape);
          return t = n.cast(Ct(n.dtype, r.dtype)), e = r.cast(Ct(n.dtype, r.dtype)), Nt.runKernelFunc(function (t, e) {
            var o = t.pow(n, r);
            return e([n, r, o]), o;
          }, {
            $base: n,
            $exp: r
          }, function (t, e) {
            var n = e[0],
              r = e[1],
              a = e[2];
            return {
              $base: function () {
                var e = r.toFloat(),
                  a = t.mul(e.mul(n.pow(e.sub(An(1))))),
                  i = fo(n.shape, o);
                return i.length > 0 && (a = a.sum(i)), a.reshape(n.shape);
              },
              $exp: function () {
                var e = n.greater(0),
                  i = n.log().where(e, zn(n)),
                  u = t.mul(a.mul(i)),
                  s = fo(r.shape, o);
                return s.length > 0 && (u = u.sum(s)), u.reshape(r.shape);
              }
            };
          });
        }
      }),
      rc = Cn({
        powStrict_: function (t, e) {
          return y(t.shape, e.shape, "Error in powStrict: "), t.pow(e);
        }
      }),
      oc = Cn({
        squaredDifference_: function (t, e) {
          var n,
            r = ln(t, "a", "squaredDifference"),
            o = ln(e, "b", "squaredDifference");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
            var n = t.squaredDifference(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1],
              o = An(2);
            return {
              $a: function () {
                return t.mul(n.sub(r).mul(o));
              },
              $b: function () {
                return t.mul(r.sub(n).mul(o));
              }
            };
          });
        }
      }),
      ac = Cn({
        squaredDifferenceStrict_: function (t, e) {
          var n = ln(t, "a", "squaredDifferenceStrict"),
            r = ln(e, "b", "squaredDifferenceStrict");
          return y(n.shape, r.shape, "Error in squaredDifferenceStrict: "), n.squaredDifference(r);
        }
      }),
      ic = Cn({
        sub_: function (t, e) {
          var n,
            r = ln(t, "a", "sub"),
            o = ln(e, "b", "sub");
          n = Rt(r, o), r = n[0], o = n[1];
          var a = po(r.shape, o.shape);
          return Nt.runKernelFunc(function (t) {
            return t.subtract(r, o);
          }, {
            a: r,
            b: o
          }, function (t) {
            return {
              a: function () {
                var e = t,
                  n = fo(r.shape, a);
                return n.length > 0 && (e = e.sum(n)), e.reshape(r.shape);
              },
              b: function () {
                var e = t,
                  n = fo(o.shape, a);
                return n.length > 0 && (e = e.sum(n)), e.neg().reshape(o.shape);
              }
            };
          }, "Sub");
        }
      }),
      uc = Cn({
        subStrict_: function (t, e) {
          var n = ln(t, "a", "subStrict"),
            r = ln(e, "b", "subStrict");
          return y(n.shape, r.shape, "Error in subStrict: "), n.sub(r);
        }
      });
    exports.subStrict = uc;
    exports.sub = ic;
    exports.squaredDifferenceStrict = ac;
    exports.squaredDifference = oc;
    exports.powStrict = rc;
    exports.pow = nc;
    exports.mulStrict = ec;
    exports.mul = tc;
    exports.modStrict = Zs;
    exports.mod = Js;
    exports.minimumStrict = Qs;
    exports.minimum = Ys;
    exports.maximumStrict = $s;
    exports.maximum = Xs;
    exports.floorDiv = js;
    exports.divStrict = Ks;
    exports.div = qs;
    exports.atan2 = Hs;
    exports.addStrict = Gs;
    exports.addN = zs;
    exports.add = Vs;
    var sc = Cn({
      equal_: function (t, e) {
        var n,
          r = ln(t, "a", "equal"),
          o = ln(e, "b", "equal");
        return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
          return t.equal(r, o);
        }, {
          $a: r,
          $b: o
        });
      }
    }),
      cc = Cn({
        equalStrict_: function (t, e) {
          var n = ln(t, "a", "equalStrict"),
            r = ln(e, "b", "equalStrict");
          return y(n.shape, r.shape, "Error in equalStrict: "), n.equal(r);
        }
      }),
      lc = Cn({
        greater_: function (t, e) {
          var n,
            r = ln(t, "a", "greater"),
            o = ln(e, "b", "greater");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
            return t.greater(r, o);
          }, {
            $a: r,
            $b: o
          });
        }
      }),
      hc = Cn({
        greaterEqual_: function (t, e) {
          var n,
            r = ln(t, "a", "greaterEqual"),
            o = ln(e, "b", "greaterEqual");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t, e) {
            var n = t.greaterEqual(r, o);
            return e([r, o]), n;
          }, {
            $a: r,
            $b: o
          }, function (t, e) {
            var n = e[0],
              r = e[1];
            return {
              $a: function () {
                return zn(n);
              },
              $b: function () {
                return zn(r);
              }
            };
          });
        }
      }),
      fc = Cn({
        greaterEqualStrict_: function (t, e) {
          var n = ln(t, "a", "greaterEqualStrict"),
            r = ln(e, "b", "greaterEqualStrict");
          return y(n.shape, r.shape, "Error in greaterEqualStrict: "), n.greaterEqual(r);
        }
      }),
      pc = Cn({
        greaterStrict_: function (t, e) {
          var n = ln(t, "a", "greaterStrict"),
            r = ln(e, "b", "greaterStrict");
          return y(n.shape, r.shape, "Error in greaterStrict: "), n.greater(r);
        }
      }),
      dc = Cn({
        less_: function (t, e) {
          var n,
            r = ln(t, "a", "less"),
            o = ln(e, "b", "less");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
            return t.less(r, o);
          }, {
            $a: r,
            $b: o
          });
        }
      }),
      vc = Cn({
        lessEqual_: function (t, e) {
          var n,
            r = ln(t, "a", "lessEqual"),
            o = ln(e, "b", "lessEqual");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
            return t.lessEqual(r, o);
          }, {
            $a: r,
            $b: o
          });
        }
      }),
      mc = Cn({
        lessEqualStrict_: function (t, e) {
          var n = ln(t, "a", "lessEqualStrict"),
            r = ln(e, "b", "lessEqualStrict");
          return y(n.shape, r.shape, "Error in lessEqualStrict: "), n.lessEqual(r);
        }
      }),
      gc = Cn({
        lessStrict_: function (t, e) {
          var n = ln(t, "a", "lessStrict"),
            r = ln(e, "b", "lessStrict");
          return y(n.shape, r.shape, "Error in lessStrict: "), n.less(r);
        }
      }),
      yc = Cn({
        notEqual_: function (t, e) {
          var n,
            r = ln(t, "a", "notEqual"),
            o = ln(e, "b", "notEqual");
          return n = Rt(r, o), r = n[0], o = n[1], po(r.shape, o.shape), Nt.runKernelFunc(function (t) {
            return t.notEqual(r, o);
          }, {
            $a: r,
            $b: o
          });
        }
      }),
      xc = Cn({
        notEqualStrict_: function (t, e) {
          var n = ln(t, "a", "notEqualStrict"),
            r = ln(e, "b", "notEqualStrict");
          return y(n.shape, r.shape, "Error in notEqualStrict: "), n.notEqual(r);
        }
      });
    exports.notEqualStrict = xc;
    exports.notEqual = yc;
    exports.lessStrict = gc;
    exports.lessEqualStrict = mc;
    exports.lessEqual = vc;
    exports.less = dc;
    exports.greaterStrict = pc;
    exports.greaterEqualStrict = fc;
    exports.greaterEqual = hc;
    exports.greater = lc;
    exports.equalStrict = cc;
    exports.equal = sc;

    function bc(t, e) {
      for (var n = [], r = t; r < e; ++r) n.push(r);

      return n;
    }

    function wc(t) {
      for (var e = [], n = 0; n < t.length; ++n) for (var r = 0; r < t[n].length; ++r) e.push(t[n][r]);

      return e;
    }

    var Cc = Cn({
      gather_: function (t, e, n) {
        void 0 === n && (n = 0);
        var r = ln(t, "x", "gather"),
          o = ln(e, "indices", "gather", "int32");
        n = D(n, r.shape)[0];

        var a = function (t, e, n) {
          for (var r = t.shape[n], o = [], a = 1, i = 1, u = 0; u < n; u++) o.push(t.shape[u]), a *= t.shape[u];

          for (u = 0; u < e.rank; u++) o.push(e.shape[u]);

          for (u = n + 1; u < t.rank; u++) o.push(t.shape[u]), i *= t.shape[u];

          return {
            batchSize: a,
            sliceSize: i,
            dimSize: r,
            outputShape: o
          };
        }(r, o, n);

        return Nt.runKernelFunc(function (t, e) {
          var a = t.gather(r, o.flatten(), n);
          return e([o]), a;
        }, {
          $x: r
        }, function (t, e) {
          var o = e[0];
          return {
            $x: function () {
              var e = r.shape,
                a = o.size,
                i = e.slice(0, n),
                u = i.length,
                s = e.slice(n, e.length).slice(1),
                c = s.length,
                l = bc(0, u),
                h = bc(u + 1, u + 1 + c),
                f = wc([i, [a], s]),
                p = t.reshape(f),
                d = o.reshape([a]),
                v = wc([[u], l, h]),
                m = p.transpose(v),
                g = Ec(m, d, r.shape[n]),
                y = yn(v);
              return g = g.transpose(y);
            }
          };
        }).reshape(a.outputShape);
      }
    }),
      Ec = Cn({
        unsortedSegmentSum_: function (t, e, n) {
          var r = ln(t, "x", "unsortedSegmentSum"),
            o = ln(e, "segmentIds", "unsortedSegmentSum", "int32");
          return g(E(n), function () {
            return "numSegments must be of dtype int";
          }), Nt.runKernelFunc(function (t, e) {
            var a = t.unsortedSegmentSum(r, o, n);
            return e([o]), a;
          }, {
            $x: r
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return function (t, e) {
                  for (var n = Xs(e, zn(e)), r = Cc(t, n), o = hc(e, An(0, "int32")), a = r.rank - o.rank, i = 0; i < a; ++i) o = dr(o, i + 1);

                  o = Ms(o, Bn(r.shape, "bool"));
                  var u = zn(r);
                  return Ws(o, r, u);
                }(t, n);
              }
            };
          });
        }
      });
    exports.unsortedSegmentSum = Ec;
    exports.gather = Cc;

    var Rc = function (t, e, o) {
      return n(this, void 0, void 0, function () {
        var n, a, i, u, s, c, l, h, f, p, d, v, m;
        return r(this, function (r) {
          switch (r.label) {
            case 0:
              for (n = ln(t, "tensor", "boolMask"), a = ln(e, "mask", "boolMask", "bool"), i = null == o ? 0 : o, u = a.rank, s = n.shape, g(u > 0, function () {
                return "mask cannot be scalar";
              }), y(s.slice(i, i + u), a.shape, "mask's shape must match the first K dimensions of tensor's shape,"), c = 1, l = i; l < i + u; l++) c *= s[l];

              return h = s.slice(0, i).concat([c], s.slice(i + u)), f = n.reshape(h), p = a.reshape([-1]), [4, Us(p)];

            case 1:
              return d = r.sent(), v = d.squeeze([1]), m = Cc(f, v, i), t !== n && n.dispose(), e !== a && a.dispose(), v.dispose(), f.dispose(), p.dispose(), d.dispose(), [2, m];
          }
        });
      });
    };

    exports.booleanMaskAsync = Rc;

    function Ic(t, e, n, r, o, a, i) {
      void 0 === a && (a = "NHWC"), g(t.length === e.rank, function () {
        return "Length of inShape (" + t.length + ") and rank of dy (" + e.rank + ") must match";
      });
      var u = t,
        s = e,
        c = !1;
      3 === e.rank && (c = !0, s = e.as4D(1, e.shape[0], e.shape[1], e.shape[2]), u = [1, t[0], t[1], t[2]]), g(4 === u.length, function () {
        return "Error in conv2dDerInput: inShape must be length 4, but got length " + u.length + ".";
      }), g(4 === s.rank, function () {
        return "Error in conv2dDerInput: dy must be rank 4, but got rank " + s.rank;
      }), g(4 === n.rank, function () {
        return "Error in conv2dDerInput: filter must be rank 4, but got rank " + n.rank;
      });
      var l = "NHWC" === a ? u[3] : u[1],
        h = "NHWC" === a ? s.shape[3] : s.shape[1];
      g(l === n.shape[2], function () {
        return "Error in conv2dDerInput: depth of input (" + l + ") must match input depth for filter " + n.shape[2] + ".";
      }), g(h === n.shape[3], function () {
        return "Error in conv2dDerInput: depth of output (" + h + ") must match output depth for filter " + n.shape[3] + ".";
      }), null != i && g(E(o), function () {
        return "Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + o + ".";
      });
      var f = ko(a),
        p = go(u, n.shape, r, 1, o, i, !1, f),
        d = Nt.runKernelFunc(function (t, e) {
          var r = t.conv2dDerInput(s, n, p);
          return e([n, s]), r;
        }, {
          dy4D: s,
          filter: n
        }, function (t, e) {
          var n = e[0],
            u = e[1];
          return {
            dy4D: function () {
              return Dc(t, n, r, o, a, 1, i);
            },
            filter: function () {
              return Nc(t, u, n.shape, r, o, a, i);
            }
          };
        });
      return c ? d.as3D(d.shape[1], d.shape[2], d.shape[3]) : d;
    }

    function kc(t) {
      var e = function (t) {
        return "number" == typeof t ? [t, t, t] : 2 === t.length ? [t[0], t[1], 1] : t;
      }(t),
        n = e[0],
        r = e[1],
        o = e[2];

      return 1 === n && 1 === r && 1 === o;
    }

    function Sc(t, e, n, r, o) {
      g(t.length === e.rank, function () {
        return "Length of inShape (" + t.length + ") and rank of dy (" + e.rank + ") must match";
      });
      var a = t,
        i = e,
        u = !1;
      4 === e.rank && (u = !0, i = e.as5D(1, e.shape[0], e.shape[1], e.shape[2], e.shape[3]), a = [1, t[0], t[1], t[2], t[3]]);
      var s = a[4],
        c = i.shape[4];
      g(5 === a.length, function () {
        return "Error in conv3dDerInput: inShape must be length 5, but got length " + a.length + ".";
      }), g(5 === i.rank, function () {
        return "Error in conv3dDerInput: dy must be rank 5, but got rank " + i.rank;
      }), g(5 === n.rank, function () {
        return "Error in conv3dDerInput: filter must be rank 5, but got rank " + n.rank;
      }), g(s === n.shape[3], function () {
        return "Error in conv3dDerInput: depth of input (" + s + ") must match input depth for filter " + n.shape[3] + ".";
      }), g(c === n.shape[4], function () {
        return "Error in conv3dDerInput: depth of output (" + c + ") must match output depth for filter " + n.shape[4] + ".";
      });
      var l = yo(a, n.shape, r, 1, o),
        h = Nt.runKernelFunc(function (t) {
          return t.conv3dDerInput(i, n, l);
        }, {
          dy5D: i
        });
      return u ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
    }

    var Ac = Cn({
      conv1d_: function (t, e, n, r, o, a, i) {
        void 0 === o && (o = "NWC"), void 0 === a && (a = 1);
        var u = ln(t, "x", "conv1d"),
          s = ln(e, "filter", "conv1d"),
          c = u,
          l = !1;
        2 === u.rank && (l = !0, c = u.as3D(1, u.shape[0], u.shape[1])), g(3 === c.rank, function () {
          return "Error in conv1d: input must be rank 3, but got rank " + c.rank + ".";
        }), g(3 === s.rank, function () {
          return "Error in conv1d: filter must be rank 3, but got rank " + s.rank + ".";
        }), null != i && g(E(r), function () {
          return "Error in conv1d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
        }), g(c.shape[2] === s.shape[1], function () {
          return "Error in conv1d: depth of input (" + c.shape[2] + ") must match input depth for filter " + s.shape[1] + ".";
        }), g(Io(n, a), function () {
          return "Error in conv1D: Either stride or dilation must be 1. Got stride " + n + " and dilation '" + a + "'";
        }), g("NWC" === o, function () {
          return "Error in conv1d: got dataFormat of " + o + " but only NWC is currently supported.";
        });
        var h = s.as4D(1, s.shape[0], s.shape[1], s.shape[2]),
          f = c.as4D(c.shape[0], 1, c.shape[1], c.shape[2]),
          p = Dc(f, h, [1, n], r, "NHWC", [1, a], i);
        return l ? p.as2D(p.shape[2], p.shape[3]) : p.as3D(p.shape[0], p.shape[2], p.shape[3]);
      }
    }),
      Dc = Cn({
        conv2d_: function (t, e, n, r, o, a, i) {
          void 0 === o && (o = "NHWC"), void 0 === a && (a = [1, 1]);
          var u = ln(t, "x", "conv2d"),
            s = ln(e, "filter", "conv2d"),
            c = u,
            l = !1;
          3 === u.rank && (l = !0, c = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), g(4 === c.rank, function () {
            return "Error in conv2d: input must be rank 4, but got rank " + c.rank + ".";
          }), g(4 === s.rank, function () {
            return "Error in conv2d: filter must be rank 4, but got rank " + s.rank + ".";
          }), null != i && g(E(r), function () {
            return "Error in conv2d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
          });
          var h = "NHWC" === o ? c.shape[3] : c.shape[1];
          g(h === s.shape[2], function () {
            return "Error in conv2d: depth of input (" + h + ") must match input depth for filter " + s.shape[2] + ".";
          }), g(Io(n, a), function () {
            return "Error in conv2D: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
          });
          var f = ko(o),
            p = go(c.shape, s.shape, n, a, r, i, !1, f),
            d = Nt.runKernelFunc(function (t, e) {
              var n = t.conv2d(c, s, p);
              return e([s, c]), n;
            }, {
              x: c,
              $filter: s
            }, function (t, e) {
              var i = e,
                u = i[0],
                s = i[1];
              return g(Ro(a), function () {
                return "Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + a + "'";
              }), {
                x: function () {
                  return Fc(s.shape, t, u, n, r, o);
                },
                $filter: function () {
                  return Nc(s, t, u.shape, n, r, o);
                }
              };
            });
          return l ? d.as3D(d.shape[1], d.shape[2], d.shape[3]) : d;
        }
      }),
      Tc = Cn({
        conv3d_: function (t, e, n, r, o, a) {
          void 0 === o && (o = "NDHWC"), void 0 === a && (a = [1, 1, 1]);
          var i = ln(t, "x", "conv3d"),
            u = ln(e, "filter", "conv3d"),
            s = i,
            c = !1;
          4 === i.rank && (c = !0, s = i.as5D(1, i.shape[0], i.shape[1], i.shape[2], i.shape[3])), g(5 === s.rank, function () {
            return "Error in conv3d: input must be rank 5, but got rank " + s.rank + ".";
          }), g(5 === u.rank, function () {
            return "Error in conv3d: filter must be rank 5, but got rank " + u.rank + ".";
          }), g(s.shape[4] === u.shape[3], function () {
            return "Error in conv3d: depth of input (" + s.shape[4] + ") must match input depth for filter " + u.shape[3] + ".";
          }), g(function (t, e) {
            return kc(t) || kc(e);
          }(n, a), function () {
            return "Error in conv3D: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
          }), g("NDHWC" === o, function () {
            return "Error in conv3d: got dataFormat of " + o + " but only NDHWC is currently supported.";
          });
          var l = yo(s.shape, u.shape, n, a, r),
            h = Nt.runKernelFunc(function (t, e) {
              var n = t.conv3d(s, u, l);
              return e([s, u]), n;
            }, {
              x: s,
              $filter: u
            }, function (t, e) {
              g(kc(a), function () {
                return "Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + a + "'";
              });
              var o = e[0],
                i = e[1];
              return {
                x: function () {
                  return Sc(o.shape, t, i, n, r);
                },
                $filter: function () {
                  return function (t, e, n, r, o) {
                    var a = t;
                    4 === t.rank && (a = t.as5D(1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]));
                    var i = e;
                    4 === i.rank && (i = e.as5D(1, e.shape[0], e.shape[1], e.shape[2], e.shape[3])), g(5 === a.rank, function () {
                      return "Error in conv3dDerFilter: input must be rank 5, but got shape " + a.shape + ".";
                    }), g(5 === i.rank, function () {
                      return "Error in conv3dDerFilter: dy must be rank 5, but got shape " + i.shape + ".";
                    }), g(5 === n.length, function () {
                      return "Error in conv3dDerFilter: filterShape must be length 5, but got " + n + ".";
                    }), g(a.shape[4] === n[3], function () {
                      return "Error in conv3dDerFilter: depth of input " + a.shape[4] + ") must match input depth in filter (" + n[3] + ".";
                    }), g(i.shape[4] === n[4], function () {
                      return "Error in conv3dDerFilter: depth of dy (" + i.shape[4] + ") must match output depth for filter (" + n[4] + ").";
                    });
                    var u = yo(a.shape, n, r, 1, o);
                    return Nt.runKernelFunc(function (t) {
                      return t.conv3dDerFilter(a, i, u);
                    }, {
                      x5D: a,
                      dy5D: i
                    });
                  }(o, t, i.shape, n, r);
                }
              };
            });
          return c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
        }
      }),
      Nc = Cn({
        conv2dDerFilter_: function (t, e, n, r, o, a, i) {
          void 0 === a && (a = "NHWC");
          var u = t;
          3 === t.rank && (u = t.as4D(1, t.shape[0], t.shape[1], t.shape[2]));
          var s = e;
          3 === s.rank && (s = e.as4D(1, e.shape[0], e.shape[1], e.shape[2])), g(4 === u.rank, function () {
            return "Error in conv2dDerFilter: input must be rank 4, but got shape " + u.shape + ".";
          }), g(4 === s.rank, function () {
            return "Error in conv2dDerFilter: dy must be rank 4, but got shape " + s.shape + ".";
          }), g(4 === n.length, function () {
            return "Error in conv2dDerFilter: filterShape must be length 4, but got " + n + ".";
          });
          var c = "NHWC" === a ? u.shape[3] : u.shape[1],
            l = "NHWC" === a ? s.shape[3] : s.shape[1];
          g(c === n[2], function () {
            return "Error in conv2dDerFilter: depth of input " + c + ") must match input depth in filter (" + n[2] + ".";
          }), g(l === n[3], function () {
            return "Error in conv2dDerFilter: depth of dy (" + l + ") must match output depth for filter (" + n[3] + ").";
          }), null != i && g(E(o), function () {
            return "Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + o + ".";
          });
          var h = ko(a),
            f = go(u.shape, n, r, 1, o, i, !1, h);
          return Nt.runKernelFunc(function (t) {
            return t.conv2dDerFilter(u, s, f);
          }, {
            x4D: u,
            dy4D: s
          });
        }
      }),
      Fc = Cn({
        conv2dDerInput_: Ic
      }),
      Oc = Cn({
        depthwiseConv2d_: function (t, e, n, r, o, a, i) {
          void 0 === o && (o = "NHWC"), void 0 === a && (a = [1, 1]);
          var u = ln(t, "x", "depthwiseConv2d"),
            s = ln(e, "filter", "depthwiseConv2d"),
            c = u,
            l = !1;
          3 === u.rank && (l = !0, c = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), g(4 === c.rank, function () {
            return "Error in depthwiseConv2d: input must be rank 4, but got rank " + c.rank + ".";
          }), g(4 === s.rank, function () {
            return "Error in depthwiseConv2d: filter must be rank 4, but got rank " + s.rank + ".";
          }), g(c.shape[3] === s.shape[2], function () {
            return "Error in depthwiseConv2d: number of input channels (" + c.shape[3] + ") must match the inChannels dimension in filter " + s.shape[2] + ".";
          }), null == a && (a = [1, 1]), g(Io(n, a), function () {
            return "Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + a + "'";
          }), null != i && g(E(r), function () {
            return "Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + r + ".";
          });
          var h = go(c.shape, s.shape, n, a, r, i, !0),
            f = Nt.runKernelFunc(function (t, e) {
              var n = t.depthwiseConv2D(c, s, h);
              return e([c, s]), n;
            }, {
              x: c,
              $filter: s
            }, function (t, e) {
              g(Ro(a), function () {
                return "Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '" + a + "'";
              });
              var n = e[0],
                r = e[1];
              return {
                x: function () {
                  return _c(n.shape, t, r, h);
                },
                $filter: function () {
                  return Mc(n, t, r.shape, h);
                }
              };
            });
          return l ? f.as3D(f.shape[1], f.shape[2], f.shape[3]) : f;
        }
      }),
      _c = Cn({
        depthwiseConv2dDerInput_: function (t, e, n, r) {
          var o = e,
            a = !1;
          3 === e.rank && (a = !0, o = e.as4D(1, e.shape[0], e.shape[1], e.shape[2]));
          var i = Nt.runKernelFunc(function (t) {
            return t.depthwiseConv2DDerInput(o, n, r);
          }, {
            dy4D: o
          });
          return a ? i.as3D(i.shape[1], i.shape[2], i.shape[3]) : i;
        }
      }),
      Mc = Cn({
        depthwiseConv2dDerFilter_: function (t, e, n, r) {
          var o = t;
          3 === t.rank && (o = t.as4D(1, t.shape[0], t.shape[1], t.shape[2]));
          var a = e;
          return 3 === a.rank && (a = e.as4D(1, e.shape[0], e.shape[1], e.shape[2])), Nt.runKernelFunc(function (t) {
            return t.depthwiseConv2DDerFilter(o, a, r);
          }, {
            x4D: o,
            dy4D: a
          });
        }
      }),
      Bc = Cn({
        separableConv2d_: function (t, e, n, r, o, a, i) {
          void 0 === a && (a = [1, 1]), void 0 === i && (i = "NHWC");
          var u = ln(t, "x", "separableConv2d"),
            s = ln(e, "depthwiseFilter", "separableConv2d"),
            c = ln(n, "pointwiseFilter", "separableConv2d"),
            l = u,
            h = !1;
          if (3 === u.rank && (h = !0, l = u.as4D(1, u.shape[0], u.shape[1], u.shape[2])), "NCHW" === i) throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");
          g(4 === l.rank, function () {
            return "Error in separableConv2d: input must be rank 4, but got rank " + l.rank + ".";
          }), g(4 === s.rank, function () {
            return "Error in separableConv2d: depthwise filter must be rank 4, but got rank " + s.rank + ".";
          }), g(4 === c.rank, function () {
            return "Error in separableConv2d: pointwise filter must be rank 4, but got rank " + s.rank + ".";
          }), g(1 === c.shape[0], function () {
            return "Error in separableConv2d: the first dimension of pointwise filter  must be 1, but got " + c.shape[0] + ".";
          }), g(1 === c.shape[1], function () {
            return "Error in separableConv2d: the second dimension of pointwise filter must be 1, but got " + c.shape[1] + ".";
          });
          var f = s.shape[2],
            p = s.shape[3];
          g(c.shape[2] === f * p, function () {
            return "Error in separableConv2d: the third dimension of pointwise filter must be " + f * p + ", but got " + c.shape[2] + ".";
          });
          var d = Oc(l, s, r, o, i, a),
            v = Dc(d, c, 1, "valid", i);
          return h ? v.as3D(v.shape[1], v.shape[2], v.shape[3]) : v;
        }
      }),
      Pc = Cn({
        conv2dTranspose_: function (t, e, n, r, o, a) {
          return Ic(n, ln(t, "x", "conv2dTranspose"), ln(e, "filter", "conv2dTranspose"), r, o, "NHWC", a);
        }
      }),
      Lc = Cn({
        conv3dTranspose_: function (t, e, n, r, o) {
          return Sc(n, ln(t, "x", "conv3dTranspose"), ln(e, "filter", "conv3dTranspose"), r, o);
        }
      });

    exports.conv3dTranspose = Lc;
    exports.conv2dTranspose = Pc;
    exports.separableConv2d = Bc;
    exports.depthwiseConv2d = Oc;
    exports.conv3d = Tc;
    exports.conv2d = Dc;
    exports.conv1d = Ac;
    var Wc = Cn({
      matMul_: function (t, e, n, r) {
        var o;
        void 0 === n && (n = !1), void 0 === r && (r = !1);
        var a = ln(t, "a", "matMul"),
          i = ln(e, "b", "matMul");
        o = Rt(a, i), a = o[0], i = o[1];
        var u = n ? a.shape[a.rank - 2] : a.shape[a.rank - 1],
          s = r ? i.shape[i.rank - 1] : i.shape[i.rank - 2],
          c = n ? a.shape[a.rank - 1] : a.shape[a.rank - 2],
          l = r ? i.shape[i.rank - 2] : i.shape[i.rank - 1],
          h = a.shape.slice(0, -2),
          f = i.shape.slice(0, -2),
          p = w(h),
          d = w(f);
        g(a.rank >= 2 && i.rank >= 2 && a.rank === i.rank, function () {
          return "Error in matMul: inputs must have the same rank of at least 2, got ranks " + a.rank + " and " + i.rank + ".";
        }), g(C(h, f), function () {
          return "Error in matMul: outer dimensions (" + h + ") and (" + f + ") of Tensors with shapes " + a.shape + " and " + i.shape + " must match.";
        }), g(u === s, function () {
          return "Error in matMul: inner shapes (" + u + ") and (" + s + ") of Tensors with shapes " + a.shape + " and " + i.shape + " and transposeA=" + n + " and transposeB=" + r + " must match.";
        });
        var v = a.shape.slice(0, -2).concat([c, l]),
          m = n ? a.as3D(p, u, c) : a.as3D(p, c, u),
          y = r ? i.as3D(d, l, s) : i.as3D(d, s, l),
          x = {
            transposeA: n,
            transposeB: r
          };
        return Nt.runKernelFunc(function (t, e) {
          var o = t.batchMatMul(m, y, n, r);
          return e([m, y]), o;
        }, {
          a: m,
          b: y
        }, function (t, e) {
          var o = e,
            a = o[0],
            i = o[1];
          return n || r ? !n && r ? {
            a: function () {
              return t.matMul(i, !1, !1);
            },
            b: function () {
              return t.matMul(a, !0, !1);
            }
          } : n && !r ? {
            a: function () {
              return i.matMul(t, !1, !0);
            },
            b: function () {
              return a.matMul(t, !1, !1);
            }
          } : {
                a: function () {
                  return i.matMul(t, !0, !0);
                },
                b: function () {
                  return t.matMul(a, !0, !0);
                }
              } : {
              a: function () {
                return t.matMul(i, !1, !0);
              },
              b: function () {
                return a.matMul(t, !0, !1);
              }
            };
        }, "BatchMatMul", x).reshape(v);
      }
    }),
      Uc = Cn({
        dot_: function (t, e) {
          var n = ln(t, "t1", "dot"),
            r = ln(e, "t2", "dot");
          g(!(1 !== n.rank && 2 !== n.rank || 1 !== r.rank && 2 !== r.rank), function () {
            return "Error in dot: inputs must all be rank 1 or 2, but got ranks " + n.rank + " and " + r.rank + ".";
          });
          var o = 1 === n.rank ? n.size : n.shape[1],
            a = 1 === r.rank ? r.size : r.shape[0];
          return g(o === a, function () {
            return "Error in dot: inner dimensions of inputs must match, but got " + o + " and " + a + ".";
          }), 1 === n.rank && 1 === r.rank ? n.as2D(1, -1).matMul(r.as2D(-1, 1)).asScalar() : 1 === n.rank && 2 === r.rank ? n.as2D(1, -1).matMul(r.as2D(r.shape[0], r.shape[1])).as1D() : 2 === n.rank && 1 === r.rank ? n.matMul(r.as2D(-1, 1)).as1D() : n.matMul(r.as2D(r.shape[0], r.shape[1]));
        }
      }),
      Vc = Cn({
        outerProduct_: function (t, e) {
          var n = ln(t, "v1", "outerProduct"),
            r = ln(e, "v2", "outerProduct");
          return g(1 === n.rank && 1 === r.rank, function () {
            return "Error in outerProduct: inputs must be rank 1, but got ranks " + n.rank + " and " + r.rank + ".";
          }), n.as2D(-1, 1).matMul(r.as2D(1, -1));
        }
      });
    exports.outerProduct = Vc;
    exports.dot = Uc;
    exports.matMul = Wc;
    var zc = Cn({
      reverse_: function (t, e) {
        var n = ln(t, "x", "reverse");
        if (0 === n.rank) return n.clone();
        var r = D(e, n.shape);
        return Nt.runKernelFunc(function (t) {
          return t.reverse(n, r);
        }, {
          $x: n
        }, function (t) {
          return {
            $x: function () {
              return t.reverse(r);
            }
          };
        }).reshapeAs(n);
      }
    }),
      Gc = Cn({
        reverse1d_: function (t) {
          var e = ln(t, "x", "reverse");
          return g(1 === e.rank, function () {
            return "Error in reverse1D: x must be rank 1 but got rank " + e.rank + ".";
          }), zc(e, 0);
        }
      }),
      Hc = Cn({
        reverse2d_: function (t, e) {
          var n = ln(t, "x", "reverse");
          return g(2 === n.rank, function () {
            return "Error in reverse2D: x must be rank 2 but got rank " + n.rank + ".";
          }), zc(n, e);
        }
      }),
      qc = Cn({
        reverse3d_: function (t, e) {
          var n = ln(t, "x", "reverse");
          return g(3 === n.rank, function () {
            return "Error in reverse3D: x must be rank 3 but got rank " + n.rank + ".";
          }), zc(n, e);
        }
      }),
      Kc = Cn({
        reverse4d_: function (t, e) {
          var n = ln(t, "x", "reverse");
          return g(4 === n.rank, function () {
            return "Error in reverse4D: x must be rank 4 but got rank " + n.rank + ".";
          }), zc(n, e);
        }
      });
    exports.reverse4d = Kc;
    exports.reverse3d = qc;
    exports.reverse2d = Hc;
    exports.reverse1d = Gc;
    exports.reverse = zc;

    function jc(t, e, n, r, o, a) {
      var i = ln(t, "x", "maxPool"),
        u = i,
        s = !1;
      3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), null == r && (r = [1, 1]), g(4 === u.rank, function () {
        return "Error in maxPool: input must be rank 4 but got rank " + u.rank + ".";
      }), g(Io(n, r), function () {
        return "Error in maxPool: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + r + "'";
      }), null != a && g(E(o), function () {
        return "Error in maxPool: pad must be an integer when using, dimRoundingMode " + a + " but got pad " + o + ".";
      });
      var c = vo(u.shape, e, n, r, o, a),
        l = Nt.runKernelFunc(function (t, e) {
          var n = t.maxPool(u, c);
          return e([u, n]), n;
        }, {
          x: u
        }, function (t, a) {
          var i = a[0],
            u = a[1];
          return {
            x: function () {
              return function (t, e, n, r, o, a, i, u) {
                var s = ln(t, "dy", "maxPoolBackprop"),
                  c = ln(e, "input", "maxPoolBackprop"),
                  l = ln(n, "output", "maxPoolBackprop");
                g(c.rank === s.rank, function () {
                  return "Rank of input (" + c.rank + ") does not match rank of dy (" + s.rank + ")";
                }), null == a && (a = [1, 1]), g(Io(o, a), function () {
                  return "Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides " + o + " and dilations '" + a + "'";
                }), g(4 === s.rank, function () {
                  return "Error in maxPoolBackprop: dy must be rank 4 but got rank " + s.rank + ".";
                }), g(4 === c.rank, function () {
                  return "Error in maxPoolBackprop: input must be rank 4 but got rank " + c.rank + ".";
                }), null != u && g(E(i), function () {
                  return "Error in maxPoolBackprop: pad must be an integer when using, dimRoundingMode " + u + " but got pad " + i + ".";
                });
                var h = vo(c.shape, r, o, a, i, u);
                return Nt.runKernelFunc(function (t) {
                  return t.maxPoolBackprop(s, c, l, h);
                }, {
                  $dy: s,
                  $input: c
                });
              }(t, i, u, e, n, r, o);
            }
          };
        });
      return s ? l.as3D(l.shape[1], l.shape[2], l.shape[3]) : l;
    }

    function Xc(t, e, n, r, o, a) {
      var i = ln(t, "x", "avgPool", "float32");
      null == r && (r = [1, 1]), g(Io(n, r), function () {
        return "Error in avgPool: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + r + "'";
      });
      var u = i,
        s = !1;
      3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(4 === u.rank, function () {
        return "Error in avgPool: x must be rank 4 but got rank " + u.rank + ".";
      }), null != a && g(E(o), function () {
        return "Error in avgPool: pad must be an integer when using, dimRoundingMode " + a + " but got pad " + o + ".";
      });
      var c = vo(u.shape, e, n, r, o, a),
        l = Nt.runKernelFunc(function (t) {
          return t.avgPool(u, c);
        }, {
          x: u
        }, function (t) {
          return {
            x: function () {
              return function (t, e, n, r, o, a) {
                var i = ln(t, "dy", "avgPoolBackprop"),
                  u = ln(e, "input", "avgPoolBackprop");
                g(u.rank === i.rank, function () {
                  return "Rank of input (" + u.rank + ") does not match rank of dy (" + i.rank + ")";
                }), null == o && (o = [1, 1]), g(Io(r, o), function () {
                  return "Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + o + "'";
                });
                var s = u,
                  c = i,
                  l = !1;
                3 === u.rank && (l = !0, s = u.as4D(1, u.shape[0], u.shape[1], u.shape[2]), c = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(4 === c.rank, function () {
                  return "Error in avgPoolBackprop: dy must be rank 4 but got rank " + c.rank + ".";
                }), g(4 === s.rank, function () {
                  return "Error in avgPoolBackprop: input must be rank 4 but got rank " + s.rank + ".";
                });
                var h = vo(s.shape, n, r, o, a),
                  f = Nt.runKernelFunc(function (t) {
                    return t.avgPoolBackprop(c, s, h);
                  }, {
                    dy4D: c,
                    input4D: s
                  });
                return l ? f.as3D(f.shape[1], f.shape[2], f.shape[3]) : f;
              }(t, u, e, n, r, o);
            }
          };
        });
      return l = l.cast(i.dtype), s ? l.as3D(l.shape[1], l.shape[2], l.shape[3]) : l;
    }

    var $c = Cn({
      maxPool_: function (t, e, n, r, o) {
        return jc(t, e, n, 1, r, o);
      }
    }),
      Yc = Cn({
        avgPool_: function (t, e, n, r, o) {
          return Xc(t, e, n, 1, r, o);
        }
      }),
      Qc = Cn({
        pool_: function (t, e, n, r, o, a) {
          null == o && (o = [1, 1]), null == a && (a = 1), 0 === r && (r = "valid");
          var i = ln(t, "x", "maxPool"),
            u = i,
            s = !1;
          3 === i.rank && (s = !0, u = i.as4D(1, i.shape[0], i.shape[1], i.shape[2])), g(Io(a, o), function () {
            return "Error in pool: Either strides or dilations must be 1. Got strides " + a + " and dilations '" + o + "'";
          });
          var c,
            l = vo(u.shape, e, a, o, r),
            h = [l.dilationHeight, l.dilationWidth];
          c = "same" === r ? function (t, e) {
            var n = t.map(function (t, n) {
              return t + (t - 1) * (e[n] - 1);
            }).map(function (t) {
              return t - 1;
            }),
              r = n.map(function (t) {
                return Math.floor(t / 2);
              }),
              o = n.map(function (t, e) {
                return t - r[e];
              });
            return n.map(function (t, e) {
              return [r[e], o[e]];
            });
          }([l.filterHeight, l.filterWidth], h) : [[0, 0], [0, 0]];

          var f = 1 === h[0] && 1 === h[1],
            p = function (t, e, n) {
              var r = n.map(function (t) {
                return t[0];
              }),
                o = n.map(function (t) {
                  return t[1];
                }),
                a = t.concat(r, o),
                i = e.map(function (t, e) {
                  return (t - a[e] % t) % t;
                }),
                u = o.map(function (t, e) {
                  return t + i[e];
                }),
                s = e.map(function (t, e) {
                  return [r[e], u[e]];
                }),
                c = e.map(function (t, e) {
                  return [0, i[e]];
                });
              return [s, c];
            }([l.inHeight, l.inWidth], h, c),
            d = p[0],
            v = p[1],
            m = f ? r : "valid",
            y = f ? u : Ar(u, h, d),
            x = ("avg" === n ? function () {
              return Xc(y, e, a, 1, m);
            } : function () {
              return jc(y, e, a, 1, m);
            })(),
            b = f ? x : cr(x, h, v);

          return s ? b.as3D(b.shape[1], b.shape[2], b.shape[3]) : b;
        }
      }),
      Jc = Cn({
        maxPool3d_: function (t, e, n, r, o, a, i) {
          void 0 === a && (a = "NDHWC");
          var u = ln(t, "x", "maxPool3d"),
            s = u,
            c = !1;
          4 === u.rank && (c = !0, s = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3])), null == i && (i = [1, 1, 1]), g(5 === s.rank, function () {
            return "Error in maxPool3d: x must be rank 5 but got rank " + s.rank + ".";
          }), g("NDHWC" === a, function () {
            return "Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of " + a;
          }), g(Io(n, i), function () {
            return "Error in maxPool3d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + i + "'";
          }), null != o && g(E(r), function () {
            return "Error in maxPool3d: pad must be an integer when using, dimRoundingMode " + o + " but got pad " + r + ".";
          });
          var l = mo(s.shape, e, n, i, r, o, a),
            h = Nt.runKernelFunc(function (t, e) {
              var n = t.maxPool3d(s, l);
              return e([s, n]), n;
            }, {
              x: s
            }, function (t, a) {
              var u = a[0],
                s = a[1];
              return {
                x: function () {
                  return function (t, e, n, r, o, a, i, u) {
                    var s = ln(t, "dy", "maxPool3dBackprop"),
                      c = ln(e, "input", "maxPool3dBackprop"),
                      l = ln(n, "output", "maxPool3dBackprop"),
                      h = s,
                      f = c,
                      p = l,
                      d = !1;
                    4 === c.rank && (d = !0, h = s.as5D(1, s.shape[0], s.shape[1], s.shape[2], s.shape[3]), f = c.as5D(1, c.shape[0], c.shape[1], c.shape[2], c.shape[3]), p = l.as5D(1, l.shape[0], l.shape[1], l.shape[2], l.shape[3])), g(5 === h.rank, function () {
                      return "Error in maxPool3dBackprop: dy must be rank 5 but got rank " + h.rank + ".";
                    }), g(5 === f.rank, function () {
                      return "Error in maxPool3dBackprop: input must be rank 5 but got rank " + f.rank + ".";
                    }), g(5 === p.rank, function () {
                      return "Error in maxPool3dBackprop: output must be rank 5 but got rank " + p.rank + ".";
                    }), null == a && (a = [1, 1, 1]), g(Io(o, a), function () {
                      return "Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides " + o + " and dilations '" + a + "'";
                    }), null != u && g(E(i), function () {
                      return "Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode " + u + " but got pad " + i + ".";
                    });
                    var v = mo(f.shape, r, o, a, i, u),
                      m = Nt.runKernelFunc(function (t) {
                        return t.maxPool3dBackprop(h, f, p, v);
                      }, {
                        dy5D: h,
                        input5D: f
                      });
                    return d ? m.as4D(m.shape[1], m.shape[2], m.shape[3], m.shape[4]) : m;
                  }(t, u, s, e, n, i, r, o);
                }
              };
            });
          return c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
        }
      }),
      Zc = Cn({
        avgPool3d_: function (t, e, n, r, o, a, i) {
          void 0 === a && (a = "NDHWC");
          var u = ln(t, "x", "avgPool3d", "float32"),
            s = u,
            c = !1;
          4 === u.rank && (c = !0, s = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3])), null == i && (i = [1, 1, 1]), g(5 === s.rank, function () {
            return "Error in avgPool3d: x must be rank 5 but got rank " + s.rank + ".";
          }), g("NDHWC" === a, function () {
            return "Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of " + a;
          }), g(Io(n, i), function () {
            return "Error in avgPool3d: Either strides or dilations must be 1. Got strides " + n + " and dilations '" + i + "'";
          }), null != o && g(E(r), function () {
            return "Error in avgPool3d: pad must be an integer when using, dimRoundingMode " + o + " but got pad " + r + ".";
          });
          var l = mo(s.shape, e, n, i, r, o, a),
            h = Nt.runKernelFunc(function (t) {
              return t.avgPool3d(s, l);
            }, {
              x: s
            }, function (t) {
              return {
                x: function () {
                  return function (t, e, n, r, o, a, i) {
                    var u = ln(t, "dy", "avgPool3dBackprop"),
                      s = ln(e, "input", "avgPool3dBackprop"),
                      c = u,
                      l = s,
                      h = !1;
                    4 === s.rank && (h = !0, c = u.as5D(1, u.shape[0], u.shape[1], u.shape[2], u.shape[3]), l = s.as5D(1, s.shape[0], s.shape[1], s.shape[2], s.shape[3])), g(5 === c.rank, function () {
                      return "Error in avgPool3dBackprop: dy must be rank 5 but got rank " + c.rank + ".";
                    }), g(5 === l.rank, function () {
                      return "Error in avgPool3dBackprop: input must be rank 5 but got rank " + l.rank + ".";
                    }), null == o && (o = [1, 1, 1]), g(Io(r, o), function () {
                      return "Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + o + "'";
                    }), null != i && g(E(a), function () {
                      return "Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode " + i + " but got pad " + a + ".";
                    });
                    var f = mo(l.shape, n, r, o, a, i),
                      p = Nt.runKernelFunc(function (t) {
                        return t.avgPool3dBackprop(c, l, f);
                      }, {
                        dy5D: c,
                        input5D: l
                      });
                    return h ? p.as4D(p.shape[1], p.shape[2], p.shape[3], p.shape[4]) : p;
                  }(t, s, e, n, i, r, o);
                }
              };
            });
          return h = h.cast(s.dtype), c ? h.as4D(h.shape[1], h.shape[2], h.shape[3], h.shape[4]) : h;
        }
      });
    exports.avgPool3d = Zc;
    exports.maxPool3d = Jc;
    exports.pool = Qc;
    exports.avgPool = Yc;
    exports.maxPool = $c;
    var tl = Cn({
      slice_: function (t, e, n) {
        var r,
          o,
          a = ln(t, "x", "slice");
        if (0 === a.rank) throw new Error("Slicing scalar is not possible");
        (r = "number" == typeof e ? [e].concat(new Array(a.rank - 1).fill(0)) : e.length < a.rank ? e.concat(new Array(a.rank - e.length).fill(0)) : e.slice()).forEach(function (t) {
          g(-1 !== t, function () {
            return "slice() does not support negative begin indexing.";
          });
        }), o = (o = null == n ? new Array(a.rank).fill(-1) : "number" == typeof n ? [n].concat(new Array(a.rank - 1).fill(-1)) : n.length < a.rank ? n.concat(new Array(a.rank - n.length).fill(-1)) : n).map(function (t, e) {
          return t >= 0 ? t : (g(-1 === t, function () {
            return "Negative size values should be exactly -1 but got " + t + " for the slice() size at index " + e + ".";
          }), a.shape[e] - r[e]);
        }), qr(a, r, o);
        var i = a.shape,
          u = {
            begin: r,
            size: o
          };
        return Nt.runKernelFunc(function (t) {
          return t.slice(a, r, o);
        }, {
          x: a
        }, function (t) {
          for (var e = [], n = 0; n < t.rank; n++) e.push([r[n], i[n] - r[n] - o[n]]);

          return {
            x: function () {
              return t.pad(e);
            }
          };
        }, "Slice", u);
      }
    }),
      el = Cn({
        slice1d_: function (t, e, n) {
          var r = ln(t, "x", "slice1d");
          return g(1 === r.rank, function () {
            return "slice1d expects a rank-1 tensor, but got a rank-" + r.rank + " tensor";
          }), tl(r, [e], [n]);
        }
      }),
      nl = Cn({
        slice2d_: function (t, e, n) {
          var r = ln(t, "x", "slice2d");
          return g(2 === r.rank, function () {
            return "slice2d expects a rank-2 tensor, but got a rank-" + r.rank + " tensor";
          }), tl(r, e, n);
        }
      }),
      rl = Cn({
        slice3d_: function (t, e, n) {
          var r = ln(t, "x", "slice3d");
          return g(3 === r.rank, function () {
            return "slice3d expects a rank-3 tensor, but got a rank-" + r.rank + " tensor";
          }), tl(r, e, n);
        }
      }),
      ol = Cn({
        slice4d_: function (t, e, n) {
          var r = ln(t, "x", "slice4d");
          return g(4 === r.rank, function () {
            return "slice4d expects a rank-4 tensor, but got a rank-" + r.rank + " tensor";
          }), tl(r, e, n);
        }
      });
    exports.slice4d = ol;
    exports.slice3d = rl;
    exports.slice2d = nl;
    exports.slice1d = el;
    exports.slice = tl;

    function al(t, e, n, r, o) {
      return e.rank < n.rank && (e = e.reshape(vn(e.shape, r))), t.rank < n.rank && (t = t.reshape(vn(t.shape, r))), {
        $x: function () {
          var r = t.mul(n.equal(e).cast(t.dtype));
          return null == o ? r : r.transpose(o);
        }
      };
    }

    var il = Cn({
      all_: function (t, e, n) {
        void 0 === e && (e = null), void 0 === n && (n = !1);
        var r = ln(t, "x", "all", "bool"),
          o = D(e, r.shape),
          a = o,
          i = gn(a, r.rank);
        null != i && (r = r.transpose(i), a = xn(a.length, r.rank));
        var u = Nt.runKernelFunc(function (t) {
          return t.all(r, a);
        }, {
          $x: r
        });

        if (n) {
          var s = vn(u.shape, o);
          return u.reshape(s);
        }

        return u;
      }
    }),
      ul = Cn({
        any_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "any", "bool"),
            o = D(e, r.shape),
            a = o,
            i = gn(a, r.rank);
          null != i && (r = r.transpose(i), a = xn(a.length, r.rank));
          var u = Nt.runKernelFunc(function (t) {
            return t.any(r, a);
          }, {
            $x: r
          });

          if (n) {
            var s = vn(u.shape, o);
            return u.reshape(s);
          }

          return u;
        }
      }),
      sl = Cn({
        argMax_: function (t, e) {
          void 0 === e && (e = 0);
          var n = ln(t, "x", "argMax");
          null == e && (e = 0);
          var r = D(e, n.shape),
            o = gn(r, n.rank);
          return null != o && (n = n.transpose(o), r = xn(r.length, n.rank)), Nt.runKernelFunc(function (t, e) {
            var o = t.argMax(n, r[0]);
            return e([n]), o;
          }, {
            $x: n
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return zn(n);
              }
            };
          });
        }
      }),
      cl = Cn({
        argMin_: function (t, e) {
          void 0 === e && (e = 0);
          var n = ln(t, "x", "argMin");
          null == e && (e = 0);
          var r = D(e, n.shape),
            o = gn(r, n.rank);
          return null != o && (n = n.transpose(o), r = xn(r.length, n.rank)), Nt.runKernelFunc(function (t, e) {
            var o = t.argMin(n, r[0]);
            return e([n]), o;
          }, {
            $x: n
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return zn(n);
              }
            };
          });
        }
      }),
      ll = Cn({
        logSumExp_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "logSumExp"),
            o = D(e, r.shape),
            a = r.max(o, !0),
            i = r.sub(a).exp().sum(o).log(),
            u = a.reshape(i.shape).add(i);

          if (n) {
            var s = vn(u.shape, o);
            return u.reshape(s);
          }

          return u;
        }
      }),
      hl = Cn({
        max_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "max"),
            o = r,
            a = D(e, r.shape),
            i = a,
            u = gn(i, r.rank);
          null != u && (r = r.transpose(u), i = xn(i.length, r.rank));
          var s = Nt.runKernelFunc(function (t, e) {
            var n = t.max(r, i);
            return e([o, n]), n;
          }, {
            $x: r
          }, function (t, e) {
            return al(t, e[1], e[0], a, u);
          });

          if (n) {
            var c = vn(s.shape, a);
            s = s.reshape(c);
          }

          return s;
        }
      }),
      fl = Cn({
        mean_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "mean"),
            o = D(e, r.shape),
            a = w(dn(r.shape, o)[1]);
          return oo(function (t) {
            var r = An(a);
            return {
              value: (r.dtype === t.dtype ? t : t.cast(r.dtype)).div(r).sum(e, n),
              gradFunc: function (e) {
                var n = t.shape.slice();
                return o.forEach(function (t) {
                  n[t] = 1;
                }), e.reshape(n).mul(Bn(t.shape, "float32")).div(a);
              }
            };
          })(r);
        }
      }),
      pl = Cn({
        min_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "min"),
            o = r,
            a = D(e, r.shape),
            i = a,
            u = gn(i, r.rank);
          null != u && (r = r.transpose(u), i = xn(i.length, r.rank));
          var s = Nt.runKernelFunc(function (t, e) {
            var n = t.min(r, i);
            return e([o, n]), n;
          }, {
            $x: r
          }, function (t, e) {
            return al(t, e[1], e[0], a, u);
          });

          if (n) {
            var c = vn(s.shape, a);
            s = s.reshape(c);
          }

          return s;
        }
      }),
      dl = Cn({
        moments_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = D(e, (t = ln(t, "x", "moments")).shape),
            o = t.mean(r, n),
            a = o.shape;
          n || (a = vn(o.shape, r));
          var i = t.toFloat().sub(o.reshape(a)).square();
          return {
            mean: o,
            variance: i.mean(r, n)
          };
        }
      }),
      vl = Cn({
        sum_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "sum");
          "bool" === r.dtype && (r = r.toInt());
          var o = D(e, r.shape);
          return oo(function (t) {
            var e = gn(o, t.rank),
              r = o,
              a = t;
            null != e && (a = t.transpose(e), r = xn(r.length, t.rank));
            var i = Nt.runKernelFunc(function (t) {
              return t.sum(a, r);
            }, {
              permutedX: a
            });

            if (n) {
              var u = vn(i.shape, o);
              i = i.reshape(u);
            }

            return {
              value: i,
              gradFunc: function (e) {
                var n = t.shape.slice();
                return o.forEach(function (t) {
                  n[t] = 1;
                }), e.reshape(n).mul(Bn(t.shape, "float32"));
              }
            };
          })(r);
        }
      }),
      ml = Cn({
        prod_: function (t, e, n) {
          void 0 === e && (e = null), void 0 === n && (n = !1);
          var r = ln(t, "x", "prod");
          "bool" === r.dtype && (r = r.toInt());
          var o = D(e, r.shape),
            a = gn(o, r.rank),
            i = o,
            u = r;
          null != a && (u = r.transpose(a), i = xn(i.length, r.rank));
          var s = Nt.runKernelFunc(function (t) {
            return t.prod(u, i);
          }, {
            permutedX: u
          });

          if (n) {
            var c = vn(s.shape, o);
            s = s.reshape(c);
          }

          return s;
        }
      });
    exports.prod = ml;
    exports.sum = vl;
    exports.moments = dl;
    exports.min = pl;
    exports.mean = fl;
    exports.max = hl;
    exports.logSumExp = ll;
    exports.argMin = cl;
    exports.argMax = sl;
    exports.any = ul;
    exports.all = il;
    var gl = Cn({
      elu_: function (t) {
        var e = ln(t, "x", "elu");
        return Nt.runKernelFunc(function (t, n) {
          var r = t.elu(e);
          return n([r]), r;
        }, {
          $x: e
        }, function (t, e) {
          var n = e[0];
          return {
            $x: function () {
              return Nt.runKernelFunc(function (e) {
                return e.eluDer(t, n);
              }, {
                dy: t,
                y: n
              });
            }
          };
        });
      }
    }),
      yl = Cn({
        leakyRelu_: function (t, e) {
          void 0 === e && (e = .2);
          var n = ln(t, "x", "leakyRelu");
          return Xs(An(e).mul(n), n);
        }
      }),
      xl = Cn({
        prelu_: function (t, e) {
          var n = ln(t, "x", "prelu"),
            r = ln(e, "alpha", "prelu");
          return Nt.runKernelFunc(function (t, e) {
            var o = t.prelu(n, r);
            return e([n, r]), o;
          }, {
            x: n,
            alpha: r
          }, function (t, e) {
            var n = e[0],
              r = e[1],
              o = n.greater(0);
            return {
              x: function () {
                return Ws(o, t, t.mul(r));
              },
              alpha: function () {
                var e = Ws(o, zn(t), t.mul(n)),
                  a = fo(r.shape, t.shape);
                return a.length > 0 && (e = e.sum(a)), e.reshape(r.shape);
              }
            };
          }, "Prelu");
        }
      }),
      bl = Cn({
        relu_: function (t) {
          var e = ln(t, "x", "relu");
          return "bool" === e.dtype ? e.toInt() : Nt.runKernelFunc(function (t, n) {
            var r = t.relu(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                return t.mulStrict(n.step().toFloat());
              }
            };
          });
        }
      }),
      wl = Cn({
        relu6_: function (t) {
          var e = ln(t, "x", "relu6");
          return "bool" === e.dtype ? e.toInt() : Nt.runKernelFunc(function (t, n) {
            var r = t.relu6(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0],
              r = n.lessEqual(6).mul(n.step());
            return {
              $x: function () {
                return t.mulStrict(r.toFloat());
              }
            };
          });
        }
      }),
      Cl = Cn({
        selu_: function (t) {
          var e = ln(t, "x", "selu");
          return Nt.runKernelFunc(function (t, n) {
            var r = t.selu(e);
            return n([e]), r;
          }, {
            $x: e
          }, function (t, e) {
            var n = e[0];
            return {
              $x: function () {
                var e = n.greater(An(0)),
                  r = An(iu),
                  o = An(uu),
                  a = t.mul(o),
                  i = t.mul(r).mul(n.toFloat().exp());
                return Ws(e, a, i);
              }
            };
          });
        }
      });
    exports.selu = Cl;
    exports.relu6 = wl;
    exports.relu = bl;
    exports.prelu = xl;
    exports.leakyRelu = yl;
    exports.elu = gl;
    var El = Cn({
      transpose_: function (t, e) {
        var n = ln(t, "x", "transpose");
        return null == e && (e = n.shape.map(function (t, e) {
          return e;
        }).reverse()), g(n.rank === e.length, function () {
          return "Error in transpose: rank of input " + n.rank + " must match length of perm " + e + ".";
        }), e.forEach(function (t) {
          g(t >= 0 && t < n.rank, function () {
            return "All entries in 'perm' must be between 0 and " + (n.rank - 1) + " but got " + e;
          });
        }), n.rank <= 1 ? n.clone() : Nt.runKernelFunc(function (t) {
          return t.transpose(n, e);
        }, {
          $x: n
        }, function (t) {
          var n = yn(e);
          return {
            $x: function () {
              return t.transpose(n);
            }
          };
        });
      }
    });
    exports.transpose = El;
    var Rl = Cn({
      localResponseNormalization_: function (t, e, n, r, o) {
        void 0 === e && (e = 5), void 0 === n && (n = 1), void 0 === r && (r = 1), void 0 === o && (o = .5);
        var a = ln(t, "x", "localResponseNormalization");
        g(4 === a.rank || 3 === a.rank, function () {
          return "Error in localResponseNormalization: x must be rank 3 or 4 but got\n               rank " + a.rank + ".";
        }), g(E(e), function () {
          return "Error in localResponseNormalization: depthRadius must be an integer but got depthRadius " + e + ".";
        });
        var i = a,
          u = !1;
        3 === a.rank && (u = !0, i = a.as4D(1, a.shape[0], a.shape[1], a.shape[2]));
        var s = Nt.runKernelFunc(function (t, a) {
          var u = t.localResponseNormalization4D(i, e, n, r, o);
          return a([i, u]), u;
        }, {
          x4D: i
        }, function (t, a) {
          var i = a[0],
            u = a[1];
          return {
            x4D: function () {
              return Nt.runKernelFunc(function (a) {
                return a.LRNGrad(t, i, u, e, n, r, o);
              }, {});
            }
          };
        });
        return u ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
      }
    });
    exports.localResponseNormalization = Rl;
    var Il = Cn({
      norm_: function (t, e, n, r) {
        void 0 === e && (e = "euclidean"), void 0 === n && (n = null), void 0 === r && (r = !1);

        var o = function t(e, n, r) {
          if (void 0 === r && (r = null), 0 === e.rank) return e.abs();
          if (1 !== e.rank && null === r) return t(e.reshape([-1]), n, r);

          if (1 === e.rank || "number" == typeof r || Array.isArray(r) && 1 === r.length) {
            if (1 === n) return e.abs().sum(r);
            if (n === 1 / 0) return e.abs().max(r);
            if (n === -1 / 0) return e.abs().min(r);
            if ("euclidean" === n || 2 === n) return e.abs().pow(An(2, "int32")).sum(r).sqrt();
            throw new Error("Error in norm: invalid ord value: " + n);
          }

          if (Array.isArray(r) && 2 === r.length) {
            if (1 === n) return e.abs().sum(r[0]).max(r[1] - 1);
            if (n === 1 / 0) return e.abs().sum(r[1]).max(r[0]);
            if (n === -1 / 0) return e.abs().sum(r[1]).min(r[0]);
            if ("fro" === n || "euclidean" === n) return e.square().sum(r).sqrt();
            throw new Error("Error in norm: invalid ord value: " + n);
          }

          throw new Error("Error in norm: invalid axis: " + r);
        }(t = ln(t, "x", "norm"), e, n),
          a = o.shape;

        if (r) {
          var i = D(n, t.shape);
          a = vn(o.shape, i);
        }

        return o.reshape(a);
      }
    });
    exports.norm = Il;
    var kl = Cn({
      basicLSTMCell_: function (t, e, n, r, o, a) {
        var i = ln(t, "forgetBias", "basicLSTMCell"),
          u = ln(e, "lstmKernel", "basicLSTMCell"),
          s = ln(n, "lstmBias", "basicLSTMCell"),
          c = ln(r, "data", "basicLSTMCell"),
          l = ln(o, "c", "basicLSTMCell"),
          h = ln(a, "h", "basicLSTMCell"),
          f = c.concat(h, 1).matMul(u).add(s),
          p = f.shape[0],
          d = f.shape[1] / 4,
          v = [p, d],
          m = f.slice([0, 0], v),
          g = f.slice([0, d], v),
          y = f.slice([0, 2 * d], v),
          x = f.slice([0, 3 * d], v),
          b = m.sigmoid().mulStrict(g.tanh()).addStrict(l.mulStrict(i.add(y).sigmoid())),
          w = b.tanh().mulStrict(x.sigmoid());
        return [b, w];
      }
    }),
      Sl = Cn({
        multiRNNCell_: function (t, e, n, r) {
          for (var o = ln(e, "data", "multiRNNCell"), a = hn(n, "c", "multiRNNCell"), i = hn(r, "h", "multiRNNCell"), u = o, s = [], c = 0; c < t.length; c++) {
            var l = t[c](u, a[c], i[c]);
            s.push(l[0]), s.push(l[1]), u = l[1];
          }

          var h = [],
            f = [];

          for (c = 0; c < s.length; c += 2) h.push(s[c]), f.push(s[c + 1]);

          return [h, f];
        }
      });
    exports.multiRNNCell = Sl;
    exports.basicLSTMCell = kl;
    var Al = Cn({
      movingAverage_: function (t, e, n, r, o) {
        void 0 === o && (o = !0);
        var a = ln(t, "v", "movingAverage"),
          i = ln(e, "x", "movingAverage"),
          u = ln(n, "decay", "movingAverage");
        It(a, i), g(C(a.shape, i.shape), function () {
          return "Shape mismatch in v and x";
        });
        var s = An(1),
          c = s.sub(u),
          l = i.sub(a).mul(c);

        if (o) {
          g(null != r, function () {
            return "When using zeroDebias: true, step is required.";
          });
          var h = ln(r, "step", "movingAverage");
          l = l.div(s.sub(nc(u, h)));
        }

        return a.add(l);
      }
    });
    exports.movingAverage = Al;
    var Dl = Cn({
      stridedSlice_: function (t, e, n, r, o, a, i, u, s) {
        if (void 0 === o && (o = 0), void 0 === a && (a = 0), void 0 === i && (i = 0), void 0 === u && (u = 0), void 0 === s && (s = 0), null == r && (r = new Array(e.length)), 0 !== i) throw new Error("ellipsis mask is not yet supported");
        var c = ln(t, "x", "stridedSlice"),
          l = Kr(u),
          h = c.shape.slice();
        l.forEach(function (t) {
          e[t] = 0, n[t] = 1, h.splice(t, 0, 1);
        }), c = c.reshape(h);

        for (var f = 0; f < c.rank; f++) e[f] = Xr(o, e, r, c.shape, f), n[f] = $r(a, n, r, c.shape, f), r[f] = r[f] || 1;

        var p = Kr(s);
        p.forEach(function (t) {
          n[t] = e[t] + 1, r[t] = 1;
        });
        var d = jr(e, n, r),
          v = d.filter(function (t, e) {
            return -1 === p.indexOf(e);
          });
        return r.every(function (t) {
          return 1 === t;
        }) ? tl(c, e, d).reshape(v) : Nt.runKernelFunc(function (t) {
          return t.stridedSlice(c, e, n, r);
        }, {
          $x: c
        }).reshape(v);
      }
    });
    exports.stridedSlice = Dl;
    var Tl = Cn({
      topk_: function (t, e, n) {
        void 0 === e && (e = 1), void 0 === n && (n = !0);
        var r = ln(t, "x", "topk");
        if (0 === r.rank) throw new Error("topk() expects the input to be of rank 1 or higher");
        var o = r.shape[r.shape.length - 1];
        if (e > o) throw new Error("'k' passed to topk() must be <= the last dimension (" + o + ") but got " + e);
        var a = Nt.runKernelFunc(function (t) {
          return t.topk(r, e, n);
        }, {
          $x: r
        });
        return {
          values: a[0],
          indices: a[1]
        };
      }
    });
    exports.topk = Tl;
    var Nl = Cn({
      scatterND_: function (t, e, n) {
        var r = ln(t, "indices", "scatterND", "int32"),
          o = ln(e, "updates", "scatterND");
        return Gr(o, r, n), Nt.runKernelFunc(function (t) {
          return t.scatterND(r, o, n);
        }, {
          $indices: r,
          $updates: o
        });
      }
    });
    exports.scatterND = Nl;

    var Fl = Cn({
      fft_: function (t) {
        g("complex64" === t.dtype, function () {
          return "The dtype for tf.spectral.fft() must be complex64 but got " + t.dtype + ".";
        });
        var e = t.shape[t.shape.length - 1],
          n = t.size / e,
          r = t.as2D(n, e);
        return Nt.runKernelFunc(function (t) {
          return t.fft(r);
        }, {
          input: t
        }).reshape(t.shape);
      }
    }),
      Ol = Cn({
        ifft_: function (t) {
          g("complex64" === t.dtype, function () {
            return "The dtype for tf.spectral.ifft() must be complex64 but got " + t.dtype + ".";
          });
          var e = t.shape[t.shape.length - 1],
            n = t.size / e,
            r = t.as2D(n, e);
          return Nt.runKernelFunc(function (t) {
            return t.ifft(r);
          }, {
            input: t
          }).reshape(t.shape);
        }
      }),
      _l = Cn({
        rfft_: function (t, e) {
          g("float32" === t.dtype, function () {
            return "The dtype for rfft() must be real value but got " + t.dtype;
          });
          var n,
            r = t.shape[t.shape.length - 1],
            o = t.size / r;

          if (null != e && e < r) {
            var a = t.shape.map(function (t) {
              return 0;
            }),
              i = t.shape.map(function (t) {
                return t;
              });
            i[t.shape.length - 1] = e, n = t.slice(a, i), r = e;
          } else if (null != e && e > r) {
            var u = t.shape.map(function (t) {
              return t;
            });
            u[t.shape.length - 1] = e - r, n = t.concat(Pn(u), t.shape.length - 1), r = e;
          } else n = t;

          var s = n.zerosLike(),
            c = En(n, s).as2D(o, r),
            l = Fl(c),
            h = Math.floor(r / 2) + 1,
            f = Rn(l),
            p = In(l),
            d = f.split([h, r - h], f.shape.length - 1),
            v = p.split([h, r - h], p.shape.length - 1),
            m = n.shape.slice();
          return m[n.shape.length - 1] = h, En(d[0], v[0]).reshape(m);
        }
      }),
      Ml = Cn({
        irfft_: function (t) {
          var e = t.shape[t.shape.length - 1],
            n = t.size / e;

          if (e <= 2) {
            var r = t.as2D(n, e),
              o = Ol(r);
            return Rn(o);
          }

          var a = [n, 2 * (e - 1)],
            i = Rn(t).as2D(n, e),
            u = In(t).as2D(n, e),
            s = i.slice([0, 1], [n, e - 2]).reverse(1),
            c = u.slice([0, 1], [n, e - 2]).reverse(1).mul(An(-1)),
            l = i.concat(s, 1),
            h = u.concat(c, 1);
          return r = En(l, h).as2D(a[0], a[1]), o = Ol(r), Rn(o);
        }
      }),
      Bl = Object.freeze({
        fft: Fl,
        ifft: Ol,
        rfft: _l,
        irfft: Ml
      });

    exports.spectral = Bl;
    exports.irfft = Ml;
    exports.rfft = _l;
    exports.ifft = Ol;
    exports.fft = Fl;
    var Pl = Cn({
      sparseToDense_: function (t, e, n, r) {
        void 0 === r && (r = 0);
        var o = ln(t, "sparseIndices", "sparseToDense", "int32"),
          a = ln(e, "sparseValues", "sparseToDense"),
          i = ln(r, "defaultValue", "sparseToDense", a.dtype);
        return function (t, e, n, r) {
          if ("int32" !== t.dtype) throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was " + t.dtype + ".");
          if (t.rank > 2) throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape " + t.shape + ".");
          var o = t.rank > 0 ? t.shape[0] : 1,
            a = t.rank > 1 ? t.shape[1] : 1;
          if (n.length !== a) throw new Error("outputShape has incorrect number of elements:, " + n.length + ", should be: " + a + ".");
          var i = e.size;
          if (0 !== e.rank && (1 !== e.rank || i !== o)) throw new Error("sparseValues has incorrect shape " + e.shape + ", should be [] or [" + o + "]");
          if (e.dtype !== r.dtype) throw new Error("sparseValues.dtype must match defaultValues.dtype");
        }(o, a, n, i), Nt.runKernelFunc(function (t) {
          return t.sparseToDense(o, a, n, i);
        }, {
          $sparseIndices: o,
          $sparseValues: a,
          $defaultValue: i
        });
      }
    });
    exports.sparseToDense = Pl;
    var Ll = Cn({
      gatherND_: function (t, e) {
        var n = ln(e, "indices", "gatherND", "int32"),
          r = ln(t, "x", "gatherND");
        return Nt.runKernelFunc(function (t) {
          return t.gatherND(r, n);
        }, {
          $x: r,
          $indices: n
        });
      }
    });
    exports.gatherND = Ll;
    var Wl = Cn({
      diag_: function (t) {
        var e = ln(t, "x", "diag").flatten(),
          n = t.shape.concat(t.shape);
        return Nt.runKernelFunc(function (t) {
          return t.diag(e);
        }, {
          $x: e
        }).reshape(n);
      }
    });
    exports.diag = Wl;
    var Ul = Cn({
      dropout_: function (t, e, n, r) {
        var o = ln(t, "x", "dropout");
        if (g("float32" === o.dtype, function () {
          return "x has to be a floating point tensor since it's going to be scaled, but got a " + o.dtype + " tensor instead.";
        }), g(e >= 0 && e < 1, function () {
          return "rate must be a float in the range [0, 1), but got " + e + ".";
        }), 0 === e) return t instanceof dt ? o.clone() : o;

        var a = function (t, e) {
          if (null == e) return t.shape.slice();
          if (C(t.shape, e)) return e;

          if (t.shape.length === e.length) {
            for (var n = [], r = 0; r < t.shape.length; r++) null == e[r] && null != t.shape[r] ? n.push(t.shape[r]) : n.push(e[r]);

            return n;
          }

          return e;
        }(o, n),
          i = 1 - e,
          u = kr(a, 0, 1, "float32", r).add(i).floor().div(i);

        return o.mul(u);
      }
    });
    exports.dropout = Ul;

    function Vl(t, e, n) {
      for (var r = 1 - t % 2, o = new Float32Array(t), a = 0; a < t; ++a) {
        var i = 2 * Math.PI * a / (t + r - 1);
        o[a] = e - n * Math.cos(i);
      }

      return Dn(o, "float32");
    }

    var zl = Cn({
      hannWindow_: function (t) {
        return Vl(t, .5, .5);
      }
    }),
      Gl = Cn({
        hammingWindow_: function (t) {
          return Vl(t, .54, .46);
        }
      }),
      Hl = Cn({
        frame_: function (t, e, n, r, o) {
          void 0 === r && (r = !1), void 0 === o && (o = 0);

          for (var a = 0, i = []; a + e <= t.size;) i.push(tl(t, a, e)), a += n;

          if (r) for (; a < t.size;) {
            var u = a + e - t.size,
              s = Gn([tl(t, a, e - u), Ln([u], o)]);
            i.push(s), a += n;
          }
          return 0 === i.length ? Tn([], [0, e]) : Gn(i).as2D(i.length, e);
        }
      }),
      ql = Cn({
        stft_: function (t, e, n, r, o) {
          var a;
          void 0 === o && (o = zl), null == r && (a = e, r = Math.floor(Math.pow(2, Math.ceil(Math.log(a) / Math.log(2)))));

          for (var i = Hl(t, e, n), u = tc(i, o(e)), s = [], c = 0; c < i.shape[0]; c++) s.push(_l(u.slice([c, 0], [1, e]), r));

          return Gn(s);
        }
      }),
      Kl = Object.freeze({
        hannWindow: zl,
        hammingWindow: Gl,
        frame: Hl,
        stft: ql
      });
    exports.signal = Kl;
    exports.stft = ql;
    exports.frame = Hl;
    exports.hammingWindow = Gl;
    exports.hannWindow = zl;

    var jl,
      Xl = function (t, e, o) {
        return void 0 === o && (o = 1), n(this, void 0, void 0, function () {
          var n, a, i, u, s, c, l, h, f, p, d, v, m, x;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return n = ln(t, "predictions", "inTopK"), a = ln(e, "targets", "inTopK"), g(n.rank > 1, function () {
                  return "inTopK() expects the predictions to be of rank 2 or higher, but got " + n.rank;
                }), g(n.rank - 1 === a.rank, function () {
                  return "predictions rank should be 1 larger than targets rank, but got predictions rank " + n.rank + " and targets rank " + a.rank;
                }), y(n.shape.slice(0, n.shape.length - 1), a.shape, "predictions's shape should be align with the targets' shape, except the last dimension."), i = n.shape[n.shape.length - 1], g(o > 0 && o <= i, function () {
                  return "'k' passed to inTopK() must be > 0 && <= the predictions last dimension (" + i + "), but got " + o;
                }), [4, n.data()];

              case 1:
                return u = r.sent(), [4, a.data()];

              case 2:
                for (s = r.sent(), c = [u.length / i, i], h = c[1], f = N("bool", l = c[0]), p = 0; p < l; p++) {
                  for (d = p * h, v = u.subarray(d, d + h), m = [], x = 0; x < v.length; x++) m.push({
                    value: v[x],
                    index: x
                  });

                  for (m.sort(function (t, e) {
                    return e.value - t.value;
                  }), f[p] = 0, x = 0; x < o; x++) if (m[x].index === s[p]) {
                    f[p] = 1;
                    break;
                  }
                }

                return t !== n && n.dispose(), e !== a && a.dispose(), [2, kn(f, a.shape, "bool")];
            }
          });
        });
      };

    exports.inTopKAsync = Xl;
    exports.Reduction = jl;
    !function (t) {
      t[t.NONE = 0] = "NONE", t[t.MEAN = 1] = "MEAN", t[t.SUM = 2] = "SUM", t[t.SUM_BY_NONZERO_WEIGHTS = 3] = "SUM_BY_NONZERO_WEIGHTS";
    }(jl || (exports.Reduction = jl = {}));
    var $l = Cn({
      absoluteDifference_: function (t, e, n, r) {
        void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
        var o = ln(t, "labels", "absoluteDifference"),
          a = ln(e, "predictions", "absoluteDifference"),
          i = null;
        null != n && (i = ln(n, "weights", "absoluteDifference")), y(o.shape, a.shape, "Error in absoluteDifference: ");
        var u = o.sub(a).abs();
        return Yl(u, i, r);
      }
    }),
      Yl = Cn({
        computeWeightedLoss_: function (t, e, n) {
          void 0 === n && (n = jl.SUM_BY_NONZERO_WEIGHTS);
          var r = ln(t, "losses", "computeWeightedLoss"),
            o = null;
          null != e && (o = ln(e, "weights", "computeWeightedLoss"));
          var a = null == o ? r : r.mul(o);
          if (n === jl.NONE) return a;
          if (n === jl.SUM) return a.sum();

          if (n === jl.MEAN) {
            if (null == o) return a.mean();
            var i = r.size / o.size,
              u = a.sum().div(o.sum());
            return i > 1 ? u.div(An(i)) : u;
          }

          if (n === jl.SUM_BY_NONZERO_WEIGHTS) {
            if (null == o) return a.sum().div(An(r.size));
            var s = o.mul(Bn(r.shape)).notEqual(An(0)).sum().toFloat();
            return a.sum().div(s);
          }

          throw Error("Unknown reduction: " + n);
        }
      }),
      Ql = Cn({
        cosineDistance_: function (t, e, n, r, o) {
          void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
          var a = ln(t, "labels", "cosineDistance"),
            i = ln(e, "predictions", "cosineDistance"),
            u = null;
          null != r && (u = ln(r, "weights", "cosineDistance")), y(a.shape, i.shape, "Error in cosineDistance: ");
          var s = An(1).sub(a.mul(i).sum(n, !0));
          return Yl(s, u, o);
        }
      }),
      Jl = Cn({
        hingeLoss_: function (t, e, n, r) {
          void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
          var o = ln(t, "labels", "hingeLoss"),
            a = ln(e, "predictions", "hingeLoss"),
            i = null;
          null != n && (i = ln(n, "weights", "hingeLoss")), y(o.shape, a.shape, "Error in hingeLoss: ");
          var u = An(1);
          o = An(2).mul(o).sub(u);
          var s = u.sub(o.mul(a)).relu();
          return Yl(s, i, r);
        }
      }),
      Zl = Cn({
        huberLoss_: function (t, e, n, r, o) {
          void 0 === r && (r = 1), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
          var a = ln(t, "labels", "huberLoss"),
            i = ln(e, "predictions", "huberLoss"),
            u = null;
          null != n && (u = ln(n, "weights", "huberLoss")), y(a.shape, i.shape, "Error in huberLoss: ");
          var s = An(r),
            c = i.sub(a).abs(),
            l = Ys(c, s),
            h = c.sub(l),
            f = An(.5).mul(l.square()).add(s.mul(h));
          return Yl(f, u, o);
        }
      }),
      th = Cn({
        logLoss_: function (t, e, n, r, o) {
          void 0 === r && (r = 1e-7), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
          var a = ln(t, "labels", "logLoss"),
            i = ln(e, "predictions", "logLoss"),
            u = null;
          null != n && (u = ln(n, "weights", "logLoss")), y(a.shape, i.shape, "Error in logLoss: ");
          var s = An(1),
            c = An(r),
            l = a.mul(i.add(c).log()).neg().sub(s.sub(a).mul(s.sub(i).add(c).log()));
          return Yl(l, u, o);
        }
      }),
      eh = Cn({
        meanSquaredError_: function (t, e, n, r) {
          void 0 === r && (r = jl.SUM_BY_NONZERO_WEIGHTS);
          var o = ln(t, "labels", "meanSquaredError"),
            a = ln(e, "predictions", "meanSquaredError"),
            i = null;
          null != n && (i = ln(n, "weights", "meanSquaredError")), y(o.shape, a.shape, "Error in meanSquaredError: ");
          var u = o.squaredDifference(a);
          return Yl(u, i, r);
        }
      }),
      nh = Cn({
        sigmoidCrossEntropy_: function (t, e, n, r, o) {
          void 0 === r && (r = 0), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
          var a = ln(t, "multiClassLabels", "sigmoidCrossEntropy"),
            i = ln(e, "logits", "sigmoidCrossEntropy"),
            u = null;

          if (null != n && (u = ln(n, "weights", "sigmoidCrossEntropy")), y(a.shape, i.shape, "Error in sigmoidCrossEntropy: "), r > 0) {
            var s = An(r),
              c = An(1),
              l = An(.5);
            a = a.mul(c.sub(s)).add(l.mul(s));
          }

          var h = function (t, e) {
            var n = ln(t, "labels", "sigmoidCrossEntropyWithLogits"),
              r = ln(e, "logits", "sigmoidCrossEntropyWithLogits");
            y(n.shape, r.shape, "Error in sigmoidCrossEntropyWithLogits: ");
            var o = r.relu(),
              a = r.mul(n),
              i = r.abs().neg().exp().log1p();
            return o.sub(a).add(i);
          }(a, i);

          return Yl(h, u, o);
        }
      }),
      rh = Cn({
        softmaxCrossEntropy_: function (t, e, n, r, o) {
          void 0 === r && (r = 0), void 0 === o && (o = jl.SUM_BY_NONZERO_WEIGHTS);
          var a = ln(t, "onehotLabels", "softmaxCrossEntropy"),
            i = ln(e, "logits", "softmaxCrossEntropy"),
            u = null;

          if (null != n && (u = ln(n, "weights", "softmaxCrossEntropy")), y(a.shape, i.shape, "Error in softmaxCrossEntropy: "), r > 0) {
            var s = An(r),
              c = An(1),
              l = An(a.shape[1]);
            a = a.mul(c.sub(s)).add(s.div(l));
          }

          var h = function (t, e, n) {
            if (void 0 === n && (n = -1), -1 === n && (n = e.rank - 1), n !== e.rank - 1) throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank " + e.rank + " and dim was " + n);
            return oo(function (t, e, r) {
              var o = e.logSumExp([n], !0),
                a = e.toFloat().sub(o);
              return r([t, a]), {
                value: a.mul(t).neg().sum([n]),
                gradFunc: function (t, e) {
                  var r = e[0],
                    o = e[1],
                    a = vn(t.shape, [n]);
                  return [t.reshape(a).mul(r.toFloat().sub(o.exp())), t.reshape(a).mul(o.exp().sub(r.toFloat()))];
                }
              };
            })(t, e);
          }(a, i);

          return Yl(h, u, o);
        }
      }),
      oh = Object.freeze({
        get Reduction() {
          return jl;
        },

        absoluteDifference: $l,
        computeWeightedLoss: Yl,
        cosineDistance: Ql,
        hingeLoss: Jl,
        huberLoss: Zl,
        logLoss: th,
        meanSquaredError: eh,
        sigmoidCrossEntropy: nh,
        softmaxCrossEntropy: rh
      });
    exports.losses = oh;

    function ah(t, e) {
      return void 0 === e && (e = !1), Nt.tidy(function () {
        if (2 !== t.shape.length) throw new Error("qr2d() requires a 2D Tensor, but got a " + t.shape.length + "D Tensor.");

        for (var n = t.shape[0], r = t.shape[1], o = vr(n), a = t.clone(), i = Tn([[1]], [1, 1]), u = i.clone(), s = n >= r ? r : n, c = function (t) {
          var e,
            s = a,
            c = u,
            l = o;
          e = Nt.tidy(function () {
            var e = a.slice([t, t], [n - t, 1]),
              s = e.norm(),
              c = a.slice([t, t], [1, 1]),
              l = Tn([[-1]]).where(c.greater(0), Tn([[1]])),
              h = c.sub(l.mul(s)),
              f = e.div(h);
            u = 1 === f.shape[0] ? i.clone() : i.concat(f.slice([1, 0], [f.shape[0] - 1, f.shape[1]]), 0);
            var p = l.matMul(h).div(s).neg(),
              d = a.slice([t, 0], [n - t, r]),
              v = p.mul(u);
            if (0 === t) a = d.sub(v.matMul(u.transpose().matMul(d))); else {
              var m = d.sub(v.matMul(u.transpose().matMul(d)));
              a = a.slice([0, 0], [t, r]).concat(m, 0);
            }
            var g = o.slice([0, t], [n, o.shape[1] - t]);
            if (0 === t) o = g.sub(g.matMul(u).matMul(v.transpose())); else {
              var y = g.sub(g.matMul(u).matMul(v.transpose()));
              o = o.slice([0, 0], [n, t]).concat(y, 1);
            }
            return [u, a, o];
          }), u = e[0], a = e[1], o = e[2], Xe([s, c, l]);
        }, l = 0; l < s; ++l) c(l);

        return !e && n > r && (o = o.slice([0, 0], [n, r]), a = a.slice([0, 0], [r, r])), [o, a];
      });
    }

    var ih = Cn({
      gramSchmidt_: function (t) {
        var e;

        if (Array.isArray(t)) {
          e = !1, g(null != t && t.length > 0, function () {
            return "Gram-Schmidt process: input must not be null, undefined, or empty";
          });

          for (var n = t[0].shape[0], r = function (e) {
            g(t[e].shape[0] === n, function () {
              return "Gram-Schmidt: Non-unique lengths found in the input vectors: (" + t[e].shape[0] + " vs. " + n + ")";
            });
          }, o = 1; o < t.length; ++o) r(o);
        } else e = !0, t = Xn(t, t.shape[0], 0).map(function (t) {
          return Dr(t, [0]);
        });

        g(t.length <= t[0].shape[0], function () {
          return "Gram-Schmidt: Number of vectors (" + t.length + ") exceeds number of dimensions (" + t[0].shape[0] + ").";
        });

        var a = [],
          i = t,
          u = function (t) {
            a.push(Nt.tidy(function () {
              var e = i[t];
              if (t > 0) for (var n = 0; n < t; ++n) {
                var r = vl(a[n].mulStrict(e)).mul(a[n]);
                e = e.sub(r);
              }
              return e.div(Il(e, "euclidean"));
            }));
          };

        for (o = 0; o < t.length; ++o) u(o);

        return e ? Tr(a, 0) : a;
      }
    }),
      uh = Cn({
        qr_: function (t, e) {
          if (void 0 === e && (e = !1), t.rank < 2) throw new Error("qr() requires input tensor to have a rank >= 2, but got rank " + t.rank);
          if (2 === t.rank) return ah(t, e);
          var n = t.shape.slice(0, t.shape.length - 2).reduce(function (t, e) {
            return t * e;
          }),
            r = Or(t.reshape([n, t.shape[t.shape.length - 2], t.shape[t.shape.length - 1]]), 0),
            o = [],
            a = [];
          return r.forEach(function (t) {
            var n = ah(t, e),
              r = n[0],
              i = n[1];
            o.push(r), a.push(i);
          }), [Tr(o, 0).reshape(t.shape), Tr(a, 0).reshape(t.shape)];
        }
      }),
      sh = Object.freeze({
        gramSchmidt: ih,
        qr: uh
      });
    exports.linalg = sh;

    function ch(t, e, n, r, o) {
      null == r && (r = .5), null == o && (o = Number.NEGATIVE_INFINITY);
      var a = t.shape[0];
      return n = Math.min(n, a), g(0 <= r && r <= 1, function () {
        return "iouThreshold must be in [0, 1], but was '" + r + "'";
      }), g(2 === t.rank, function () {
        return "boxes must be a 2D tensor, but was of rank '" + t.rank + "'";
      }), g(4 === t.shape[1], function () {
        return "boxes must have 4 columns, but 2nd dimension was " + t.shape[1];
      }), g(1 === e.rank, function () {
        return "scores must be a 1D tensor";
      }), g(e.shape[0] === a, function () {
        return "scores has incompatible shape with boxes. Expected " + a + ", but was " + e.shape[0];
      }), {
        maxOutputSize: n,
        iouThreshold: r,
        scoreThreshold: o
      };
    }

    var lh = Cn({
      resizeBilinear_: function (t, e, n) {
        void 0 === n && (n = !1);
        var r = ln(t, "images", "resizeBilinear");
        g(3 === r.rank || 4 === r.rank, function () {
          return "Error in resizeBilinear: x must be rank 3 or 4, but got rank " + r.rank + ".";
        }), g(2 === e.length, function () {
          return "Error in resizeBilinear: new shape must 2D, but got shape " + e + ".";
        });
        var o = r,
          a = !1;
        3 === r.rank && (a = !0, o = r.as4D(1, r.shape[0], r.shape[1], r.shape[2]));
        var i = e[0],
          u = e[1],
          s = Nt.runKernelFunc(function (t, e) {
            return e([o]), t.resizeBilinear(o, i, u, n);
          }, {
            batchImages: o
          }, function (t, e) {
            return {
              batchImages: function () {
                return Nt.runKernelFunc(function (r) {
                  return r.resizeBilinearBackprop(t, e[0], n);
                }, {});
              }
            };
          });
        return a ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
      }
    }),
      hh = Cn({
        resizeNearestNeighbor_: function (t, e, n) {
          void 0 === n && (n = !1);
          var r = ln(t, "images", "resizeNearestNeighbor");
          g(3 === r.rank || 4 === r.rank, function () {
            return "Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank " + r.rank + ".";
          }), g(2 === e.length, function () {
            return "Error in resizeNearestNeighbor: new shape must 2D, but got shape " + e + ".";
          }), g("float32" === r.dtype || "int32" === r.dtype, function () {
            return "`images` must have `int32` or `float32` as dtype";
          });
          var o = r,
            a = !1;
          3 === r.rank && (a = !0, o = r.as4D(1, r.shape[0], r.shape[1], r.shape[2]));
          var i = e[0],
            u = e[1],
            s = Nt.runKernelFunc(function (t, e) {
              return e([o]), t.resizeNearestNeighbor(o, i, u, n);
            }, {
              batchImages: o
            }, function (t, e) {
              return {
                batchImages: function () {
                  return Nt.runKernelFunc(function (r) {
                    return r.resizeNearestNeighborBackprop(t, e[0], n);
                  }, {});
                }
              };
            });
          return a ? s.as3D(s.shape[1], s.shape[2], s.shape[3]) : s;
        }
      }),
      fh = Cn({
        nonMaxSuppression_: function (t, e, n, r, o) {
          void 0 === r && (r = .5), void 0 === o && (o = Number.NEGATIVE_INFINITY);
          var a = ln(t, "boxes", "nonMaxSuppression"),
            i = ln(e, "scores", "nonMaxSuppression"),
            u = ch(a, i, n, r, o);
          return n = u.maxOutputSize, r = u.iouThreshold, o = u.scoreThreshold, Nt.runKernelFunc(function (t) {
            return t.nonMaxSuppression(a, i, n, r, o);
          }, {
            $boxes: a
          });
        }
      }),
      ph = function (t, e, o, a, i) {
        return void 0 === a && (a = .5), void 0 === i && (i = Number.NEGATIVE_INFINITY), n(this, void 0, void 0, function () {
          var n, u, s, c, l, h, f;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return n = ln(t, "boxes", "nonMaxSuppressionAsync"), u = ln(e, "scores", "nonMaxSuppressionAsync"), s = ch(n, u, o, a, i), o = s.maxOutputSize, a = s.iouThreshold, i = s.scoreThreshold, [4, Promise.all([n.data(), u.data()])];

              case 1:
                return c = r.sent(), l = c[0], h = c[1], f = Mo(l, h, o, a, i), n !== t && n.dispose(), u !== e && u.dispose(), [2, f];
            }
          });
        });
      },
      dh = Cn({
        cropAndResize_: function (t, e, n, r, o, a) {
          var i = ln(t, "image", "cropAndResize", "float32"),
            u = ln(e, "boxes", "cropAndResize", "float32"),
            s = ln(n, "boxInd", "cropAndResize", "int32");
          o = o || "bilinear", a = a || 0;
          var c = u.shape[0];
          return g(4 === i.rank, function () {
            return "Error in cropAndResize: image must be rank 4,but got rank " + i.rank + ".";
          }), g(2 === u.rank && 4 === u.shape[1], function () {
            return "Error in cropAndResize: boxes must be have size [" + c + ",4] but had shape " + u.shape + ".";
          }), g(1 === s.rank && s.shape[0] === c, function () {
            return "Error in cropAndResize: boxInd must be have size [" + c + "] but had shape " + u.shape + ".";
          }), g(2 === r.length, function () {
            return "Error in cropAndResize: cropSize must be of length 2, but got length " + r.length + ".";
          }), g(r[0] >= 1 && r[1] >= 1, function () {
            return "cropSize must be atleast [1,1], but was " + r;
          }), g("bilinear" === o || "nearest" === o, function () {
            return "method must be bilinear or nearest, but was " + o;
          }), Nt.runKernelFunc(function (t, e) {
            return t.cropAndResize(i, u, s, r, o, a);
          }, {
            $image: i,
            $boxes: u
          });
        }
      }),
      vh = Object.freeze({
        resizeBilinear: lh,
        resizeNearestNeighbor: hh,
        nonMaxSuppression: fh,
        nonMaxSuppressionAsync: ph,
        cropAndResize: dh
      }),
      mh = function (t, e) {
        return !(t > 0) && ("linear" === e || "relu" === e);
      },
      gh = function (t, e, n) {
        if (null == n || "linear" === n) return t;
        if ("relu" === n) return t.mul(e.step());
        throw new Error("Gradient for activation " + n + " has not been implemented yet.");
      },
      yh = function (t, e) {
        var n = e,
          r = fo(t.shape, e.shape);
        return r.length > 0 && (n = n.sum(r)), n.reshape(t.shape);
      },
      xh = function (t, e, n) {
        if ("linear" === e) return t;
        if ("relu" === e) return bl(t);
        if ("elu" === e) return gl(t);
        if ("relu6" === e) return wl(t);
        if ("prelu" === e) return xl(t, n);
        throw new Error("Unknown fused activation " + e + ".");
      };

    exports.image = vh;
    var bh = Cn({
      matMul_: function (t) {
        var e,
          n = t.a,
          r = t.b,
          o = t.transposeA,
          a = void 0 !== o && o,
          i = t.transposeB,
          u = void 0 !== i && i,
          s = t.bias,
          c = t.activation,
          l = void 0 === c ? "linear" : c,
          h = t.preluActivationWeights;

        if (!1 === mh(Nt.state.gradientDepth, l)) {
          var f = Wc(n, r, a, u);
          return null != s && (f = Vs(f, s)), xh(f, l, h);
        }

        var p = ln(n, "a", "fused matMul"),
          d = ln(r, "b", "fused matMul");
        e = Rt(p, d), p = e[0], d = e[1];
        var v = a ? p.shape[p.rank - 2] : p.shape[p.rank - 1],
          m = u ? d.shape[d.rank - 1] : d.shape[d.rank - 2],
          y = a ? p.shape[p.rank - 1] : p.shape[p.rank - 2],
          x = u ? d.shape[d.rank - 2] : d.shape[d.rank - 1],
          b = p.shape.slice(0, -2),
          E = d.shape.slice(0, -2),
          R = w(b),
          I = w(E);
        g(p.rank >= 2 && d.rank >= 2 && p.rank === d.rank, function () {
          return "Error in fused matMul: inputs must have the same rank of at least 2, got ranks " + p.rank + " and " + d.rank + ".";
        }), g(C(b, E), function () {
          return "Error in fused matMul: outer dimensions (" + b + ") and (" + E + ") of Tensors with shapes " + p.shape + " and " + d.shape + " must match.";
        }), g(v === m, function () {
          return "Error in fused matMul: inner shapes (" + v + ") and (" + m + ") of Tensors with shapes " + p.shape + " and " + d.shape + " and transposeA=" + a + " and transposeB=" + u + " must match.";
        });
        var k,
          S,
          A = p.shape.slice(0, -2).concat([y, x]),
          D = a ? p.as3D(R, v, y) : p.as3D(R, y, v),
          T = u ? d.as3D(I, x, m) : d.as3D(I, m, x);
        null != s && po(A, (k = Rt(k = ln(s, "bias", "fused matMul"), p)[0]).shape), null != h && (S = ln(h, "prelu weights", "fused matMul"));
        var N = {
          $a: D,
          $b: T
        };
        return null != s && (N.$bias = k), null != h && (N.$preluActivationWeights = S), Nt.runKernelFunc(function (t, e) {
          var n = t.fusedBatchMatMul({
            a: D,
            b: T,
            transposeA: a,
            transposeB: u,
            bias: k,
            activation: l,
            preluActivationWeights: S
          });
          return e([D, T, n]), n;
        }, N, function (t, e) {
          var n = e[0],
            r = e[1],
            o = e[2],
            i = gh(t, o, l),
            c = {};
          return null != s && (c = {
            $bias: function () {
              return yh(k, i);
            }
          }), a || u ? !a && u ? Object.assign({
            $a: function () {
              return i.matMul(r, !1, !1);
            },
            $b: function () {
              return i.matMul(n, !0, !1);
            }
          }, c) : a && !u ? Object.assign({
            $a: function () {
              return r.matMul(i, !1, !0);
            },
            $b: function () {
              return n.matMul(i, !1, !1);
            }
          }, c) : Object.assign({
            $a: function () {
              return r.matMul(i, !0, !0);
            },
            $b: function () {
              return i.matMul(n, !0, !0);
            }
          }, c) : Object.assign({
            $a: function () {
              return i.matMul(r, !1, !0);
            },
            $b: function () {
              return n.matMul(i, !0, !1);
            }
          }, c);
        }).reshape(A);
      }
    }),
      wh = Cn({
        conv2d_: function (t) {
          var e = t.x,
            n = t.filter,
            r = t.strides,
            o = t.pad,
            a = t.dataFormat,
            i = void 0 === a ? "NHWC" : a,
            u = t.dilations,
            s = void 0 === u ? [1, 1] : u,
            c = t.dimRoundingMode,
            l = t.bias,
            h = t.activation,
            f = void 0 === h ? "linear" : h,
            p = t.preluActivationWeights;

          if (f = f || "linear", !1 === mh(Nt.state.gradientDepth, f)) {
            var d = Dc(e, n, r, o, i, s, c);
            return null != l && (d = Vs(d, l)), xh(d, f, p);
          }

          var v = ln(e, "x", "conv2d"),
            m = ln(n, "filter", "conv2d"),
            y = v,
            x = !1;
          3 === v.rank && (x = !0, y = v.as4D(1, v.shape[0], v.shape[1], v.shape[2])), g(4 === y.rank, function () {
            return "Error in fused conv2d: input must be rank 4, but got rank " + y.rank + ".";
          }), g(4 === m.rank, function () {
            return "Error in fused conv2d: filter must be rank 4, but got rank " + m.rank + ".";
          }), null != c && g(E(o), function () {
            return "Error in fused conv2d: pad must be an integer when using, dimRoundingMode " + c + " but got pad " + o + ".";
          }), g(y.shape[3] === m.shape[2], function () {
            return "Error in conv2d: depth of input (" + y.shape[3] + ") must match input depth for filter " + m.shape[2] + ".";
          }), g(Io(r, s), function () {
            return "Error in conv2D: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + s + "'";
          }), g("NHWC" === i, function () {
            return "Error in conv2d: got dataFormat of " + i + " but only NHWC is currently supported.";
          });
          var b,
            w,
            C = go(y.shape, m.shape, r, s, o, c);
          null != l && (b = Rt(b = ln(l, "bias", "fused conv2d"), v)[0], po(C.outShape, b.shape)), null != p && (w = ln(p, "prelu weights", "fused conv2d"));
          var R = {
            x: y,
            $filter: m
          };
          null != l && (R.$bias = b), null != p && (R.$preluActivationWeights = w);
          var I = Nt.runKernelFunc(function (t, e) {
            var n = t.fusedConv2d({
              input: y,
              filter: m,
              convInfo: C,
              bias: b,
              activation: f,
              preluActivationWeights: w
            });
            return e([m, y, n]), n;
          }, R, function (t, e) {
            var n = e,
              a = n[0],
              i = n[1],
              u = n[2],
              c = gh(t, u, f);
            g(Ro(s), function () {
              return "Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '" + s + "'";
            });
            var h = {};
            return null != l && (h = {
              $bias: function () {
                return yh(b, c);
              }
            }), Object.assign({
              x: function () {
                return Fc(i.shape, c, a, r, o);
              },
              $filter: function () {
                return Nc(i, c, a.shape, r, o);
              }
            }, h);
          });
          return x ? I.as3D(I.shape[1], I.shape[2], I.shape[3]) : I;
        }
      }),
      Ch = Cn({
        depthwiseConv2d_: function (t) {
          var e = t.x,
            n = t.filter,
            r = t.strides,
            o = t.pad,
            a = t.dataFormat,
            i = void 0 === a ? "NHWC" : a,
            u = t.dilations,
            s = void 0 === u ? [1, 1] : u,
            c = t.dimRoundingMode,
            l = t.bias,
            h = t.activation,
            f = void 0 === h ? "linear" : h,
            p = t.preluActivationWeights;

          if (!1 === mh(Nt.state.gradientDepth, f)) {
            var d = Oc(e, n, r, o, i, s, c);
            return null != l && (d = Vs(d, l)), xh(d, f, p);
          }

          var v = ln(e, "x", "depthwiseConv2d"),
            m = ln(n, "filter", "depthwiseConv2d"),
            y = v,
            x = !1;
          3 === v.rank && (x = !0, y = v.as4D(1, v.shape[0], v.shape[1], v.shape[2])), g(4 === y.rank, function () {
            return "Error in fused depthwiseConv2d: input must be rank 4, but got rank " + y.rank + ".";
          }), g(4 === m.rank, function () {
            return "Error in fused depthwiseConv2d: filter must be rank 4, but got rank " + m.rank + ".";
          }), g(y.shape[3] === m.shape[2], function () {
            return "Error in fused depthwiseConv2d: number of input channels (" + y.shape[3] + ") must match the inChannels dimension in filter " + m.shape[2] + ".";
          }), null == s && (s = [1, 1]), g(Io(r, s), function () {
            return "Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides " + r + " and dilations '" + s + "'";
          }), null != c && g(E(o), function () {
            return "Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode " + c + " but got pad " + o + ".";
          });
          var b,
            w,
            C = go(y.shape, m.shape, r, s, o, c, !0);
          null != l && (b = Rt(b = ln(l, "bias", "fused conv2d"), v)[0], po(C.outShape, b.shape)), null != p && (w = ln(p, "prelu weights", "fused depthwiseConv2d"));
          var R = {
            x: y,
            $filter: m
          };
          null != l && (R.$bias = b), null != p && (R.$preluActivationWeights = w);
          var I = Nt.runKernelFunc(function (t, e) {
            var n = t.fusedDepthwiseConv2D({
              input: y,
              filter: m,
              convInfo: C,
              bias: b,
              activation: f,
              preluActivationWeights: w
            });
            return e([y, m, n]), n;
          }, R, function (t, e) {
            g(Ro(s), function () {
              return "Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '" + s + "'";
            });
            var n = e[0],
              r = e[1],
              o = e[2],
              a = gh(t, o, f),
              i = {};
            return null != l && (i = {
              $bias: function () {
                return yh(b, a);
              }
            }), Object.assign({
              x: function () {
                return _c(n.shape, a, r, C);
              },
              $filter: function () {
                return Mc(n, a, r.shape, C);
              }
            }, i);
          });
          return x ? I.as3D(I.shape[1], I.shape[2], I.shape[3]) : I;
        }
      }),
      Eh = Object.freeze({
        matMul: bh,
        conv2d: wh,
        depthwiseConv2d: Ch
      }),
      Rh = Object.freeze({
        image: vh,
        linalg: sh,
        losses: oh,
        spectral: Bl,
        fused: Eh,
        signal: Kl,
        square: Uu,
        conv1d: Ac,
        conv2d: Dc,
        conv3d: Tc,
        depthwiseConv2d: Oc,
        separableConv2d: Bc,
        conv2dTranspose: Pc,
        conv3dTranspose: Lc,
        op: Cn,
        batchNormalization2d: Ss,
        batchNormalization3d: As,
        batchNormalization4d: Ds,
        batchNormalization: Ts,
        batchNorm: Ns,
        batchNorm2d: Fs,
        batchNorm3d: Os,
        batchNorm4d: _s,
        booleanMaskAsync: Rc,
        complex: En,
        real: Rn,
        imag: In,
        concat: Gn,
        concat1d: Hn,
        concat2d: qn,
        concat3d: Kn,
        concat4d: jn,
        split: Xn,
        matMul: Wc,
        dot: Uc,
        outerProduct: Vc,
        reverse: zc,
        reverse1d: Gc,
        reverse2d: Hc,
        reverse3d: qc,
        reverse4d: Kc,
        maxPool: $c,
        avgPool: Yc,
        pool: Qc,
        maxPool3d: Jc,
        avgPool3d: Zc,
        slice: tl,
        slice1d: el,
        slice2d: nl,
        slice3d: rl,
        slice4d: ol,
        abs: Vu,
        acos: zu,
        acosh: Gu,
        asin: Hu,
        asinh: qu,
        atan: Ku,
        atanh: ju,
        ceil: Xu,
        clipByValue: $u,
        cos: Yu,
        cosh: Qu,
        erf: Ju,
        exp: Zu,
        expm1: ts,
        floor: es,
        log: ns,
        log1p: rs,
        logSigmoid: os,
        neg: as,
        reciprocal: is,
        round: us,
        rsqrt: ss,
        sigmoid: cs,
        sign: ls,
        isNaN: hs,
        isInf: fs,
        isFinite: ps,
        sin: ds,
        sinh: vs,
        softplus: ms,
        sqrt: gs,
        step: ys,
        tan: xs,
        tanh: bs,
        all: il,
        any: ul,
        argMax: sl,
        argMin: cl,
        logSumExp: ll,
        max: hl,
        mean: fl,
        min: pl,
        moments: dl,
        sum: vl,
        prod: ml,
        equal: sc,
        equalStrict: cc,
        greater: lc,
        greaterEqual: hc,
        greaterEqualStrict: fc,
        greaterStrict: pc,
        less: dc,
        lessEqual: vc,
        lessEqualStrict: mc,
        lessStrict: gc,
        notEqual: yc,
        notEqualStrict: xc,
        add: Vs,
        addN: zs,
        addStrict: Gs,
        atan2: Hs,
        div: qs,
        divStrict: Ks,
        floorDiv: js,
        maximum: Xs,
        maximumStrict: $s,
        minimum: Ys,
        minimumStrict: Qs,
        mod: Js,
        modStrict: Zs,
        mul: tc,
        mulStrict: ec,
        pow: nc,
        powStrict: rc,
        squaredDifference: oc,
        squaredDifferenceStrict: ac,
        sub: ic,
        subStrict: uc,
        elu: gl,
        leakyRelu: yl,
        prelu: xl,
        relu: bl,
        relu6: wl,
        selu: Cl,
        logicalAnd: Ms,
        logicalNot: Bs,
        logicalOr: Ps,
        logicalXor: Ls,
        where: Ws,
        whereAsync: Us,
        buffer: ur,
        print: sr,
        batchToSpaceND: cr,
        cast: lr,
        clone: hr,
        cumsum: fr,
        depthToSpace: pr,
        expandDims: dr,
        eye: vr,
        multinomial: mr,
        oneHot: gr,
        pad: yr,
        pad1d: xr,
        pad2d: br,
        pad3d: wr,
        pad4d: Cr,
        rand: Er,
        randomNormal: Rr,
        randomGamma: Ir,
        randomUniform: kr,
        reshape: Sr,
        spaceToBatchND: Ar,
        squeeze: Dr,
        stack: Tr,
        tile: Nr,
        truncatedNormal: Fr,
        unstack: Or,
        setdiff1dAsync: _r,
        fill: Ln,
        linspace: Wn,
        ones: Bn,
        range: Un,
        scalar: An,
        tensor: kn,
        tensor1d: Dn,
        tensor2d: Tn,
        tensor3d: Nn,
        tensor4d: Fn,
        tensor5d: On,
        tensor6d: _n,
        variable: Mn,
        zeros: Pn,
        onesLike: Vn,
        zerosLike: zn,
        transpose: El,
        softmax: io,
        logSoftmax: uo,
        localResponseNormalization: Rl,
        norm: Il,
        gather: Cc,
        unsortedSegmentSum: Ec,
        basicLSTMCell: kl,
        multiRNNCell: Sl,
        movingAverage: Al,
        stridedSlice: Dl,
        topk: Tl,
        scatterND: Nl,
        fft: Fl,
        ifft: Ol,
        rfft: _l,
        irfft: Ml,
        sparseToDense: Pl,
        gatherND: Ll,
        diag: Wl,
        dropout: Ul,
        hannWindow: zl,
        hammingWindow: Gl,
        frame: Hl,
        stft: ql,
        inTopKAsync: Xl
      });
    exports.fused = Eh;

    function Ih(t, e) {
      Array.isArray(t) || (t = [t]), t.forEach(function (t) {
        null != t && g("complex64" !== t.dtype, function () {
          return e + " does not support complex64 tensors.";
        });
      });
    }

    function kh(t, e, n, r) {
      if ("linear" === n) return t.linear(e);
      if ("relu" === n) return t.relu(e);
      if ("elu" === n) return t.elu(e);
      if ("relu6" === n) return t.relu6(e);
      if ("prelu" === n) return t.prelu(e, r);
      throw new Error("Activation " + n + " has not been implemented for the CPU backend.");
    }

    var Sh = function (t) {
      function o() {
        var e = t.call(this) || this;

        if (e.blockSize = 48, e.firstUse = !0, a().get("IS_BROWSER")) {
          var n = "undefined" != typeof OffscreenCanvas ? new OffscreenCanvas(300, 150) : "undefined" != typeof document ? document.createElement("canvas") : null;
          null !== n && (e.fromPixels2DContext = n.getContext("2d"));
        }

        return e.data = new so(e, Nt), e;
      }

      return e(o, t), o.prototype.write = function (t, e, n) {
        this.firstUse && (this.firstUse = !1, a().get("IS_NODE") && un("\n============================\nHi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.\n============================\n"));
        var r = {};
        return this.data.set(r, {
          values: t,
          dtype: n
        }), r;
      }, o.prototype.move = function (t, e, n, r) {
        this.data.set(t, {
          values: e,
          dtype: r
        });
      }, o.prototype.numDataIds = function () {
        return this.data.numDataIds();
      }, o.prototype.fromPixels = function (t, e) {
        if (null == t) throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
        var n,
          r,
          o = t.data instanceof Uint8Array,
          i = "undefined" != typeof ImageData && t instanceof ImageData,
          u = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement,
          s = "undefined" != typeof HTMLImageElement && t instanceof HTMLImageElement,
          c = u ? [t.videoWidth, t.videoHeight] : [t.width, t.height],
          l = c[0],
          h = c[1];
        if (a().get("IS_NODE") && null == t.getContext) throw new Error("When running in node, pixels must be an HTMLCanvasElement like the one returned by the `canvas` npm package");
        if (null != t.getContext) n = t.getContext("2d").getImageData(0, 0, l, h).data; else if (i || o) n = t.data; else {
          if (!s && !u) throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData or {data: Uint32Array, width: number, height: number}, but was " + t.constructor.name);
          if (null == this.fromPixels2DContext) throw new Error("Can't read pixels from HTMLImageElement outside the browser.");
          this.fromPixels2DContext.canvas.width = l, this.fromPixels2DContext.canvas.height = h, this.fromPixels2DContext.drawImage(t, 0, 0, l, h), n = this.fromPixels2DContext.getImageData(0, 0, l, h).data;
        }
        if (4 === e) r = new Int32Array(n); else {
          var f = l * h;
          r = new Int32Array(f * e);

          for (var p = 0; p < f; p++) for (var d = 0; d < e; ++d) r[p * e + d] = n[4 * p + d];
        }
        return Nn(r, [h, l, e], "int32");
      }, o.prototype.read = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (e) {
            return [2, this.readSync(t)];
          });
        });
      }, o.prototype.readSync = function (t) {
        var e = this.data.get(t),
          n = e.dtype,
          r = e.complexTensors;
        return "complex64" === n ? No(this.readSync(r.real.dataId), this.readSync(r.imag.dataId)) : this.data.get(t).values;
      }, o.prototype.bufferSync = function (t) {
        var e = this.readSync(t.dataId),
          n = e;
        if ("string" === t.dtype) try {
          n = e.map(function (t) {
            return Z(t);
          });
        } catch (t) {
          throw new Error("Failed to decode encoded string bytes into utf-8");
        }
        return ur(t.shape, t.dtype, n);
      }, o.prototype.makeOutput = function (t, e, n) {
        var r = this.write(t, e, n);
        return Nt.makeTensorFromDataId(r, e, n, this);
      }, o.prototype.disposeData = function (t) {
        if (this.data.has(t)) {
          var e = this.data.get(t).complexTensors;
          null != e && (e.real.dispose(), e.imag.dispose()), this.data.delete(t);
        }
      }, o.prototype.time = function (t) {
        return n(this, void 0, void 0, function () {
          var e;
          return r(this, function (n) {
            return e = Y(), t(), [2, {
              kernelMs: Y() - e
            }];
          });
        });
      }, o.prototype.memory = function () {
        return {
          unreliable: !0,
          reasons: ["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]
        };
      }, o.prototype.complex = function (t, e) {
        var n = this.makeOutput(null, t.shape, "complex64");
        return this.data.get(n.dataId).complexTensors = {
          real: Nt.keep(t.clone()),
          imag: Nt.keep(e.clone())
        }, n;
      }, o.prototype.real = function (t) {
        return this.data.get(t.dataId).complexTensors.real.clone();
      }, o.prototype.imag = function (t) {
        return this.data.get(t.dataId).complexTensors.imag.clone();
      }, o.prototype.slice = function (t, e, n) {
        if (Ih(t, "slice"), Yr(t.shape, e, n)) {
          var r = Qr(e, t.strides),
            o = w(n);
          return kn(this.readSync(t.dataId).subarray(r, r + o), n, t.dtype);
        }

        for (var a = ur(n, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; ++u) {
          var s = a.indexToLoc(u).map(function (t, n) {
            return t + e[n];
          });
          a.values[u] = i.get.apply(i, s);
        }

        return a.toTensor();
      }, o.prototype.stridedSlice = function (t, e, n, r) {
        Ih(t, "stridedSlice");
        var o = jr(e, n, r);
        if (o.some(function (t) {
          return 0 === t;
        })) return kn([], o);

        for (var a = ur(o, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; u++) {
          for (var s = a.indexToLoc(u), c = new Array(s.length), l = 0; l < c.length; l++) c[l] = s[l] * r[l] + e[l];

          a.set.apply(a, [i.get.apply(i, c)].concat(s));
        }

        return a.toTensor();
      }, o.prototype.diag = function (t) {
        for (var e = this.readSync(t.dataId), n = ur([t.size, t.size], t.dtype), r = n.values, o = 0; o < e.length; o++) r[o * t.size + o] = e[o];

        return n.toTensor();
      }, o.prototype.unstack = function (t, e) {
        for (var n = t.shape[e], r = new Array(t.rank - 1), o = 0, a = 0; a < t.rank; a++) a !== e && (r[o++] = t.shape[a]);

        var i = new Array(t.rank).fill(0),
          u = t.shape.slice();
        u[e] = 1;
        var s = new Array(n);

        for (a = 0; a < s.length; a++) i[e] = a, s[a] = this.slice(t, i, u).reshape(r);

        return s;
      }, o.prototype.reverse = function (t, e) {
        Ih(t, "reverse");

        for (var n = ur(t.shape, t.dtype), r = this.bufferSync(t), o = function (o) {
          var a = n.indexToLoc(o),
            i = a.slice();
          e.forEach(function (e) {
            return i[e] = t.shape[e] - 1 - i[e];
          }), n.set.apply(n, [r.get.apply(r, i)].concat(a));
        }, a = 0; a < n.size; a++) o(a);

        return n.toTensor();
      }, o.prototype.concat = function (t, e) {
        var n = this;

        if ("complex64" === t[0].dtype) {
          var r = t.map(function (t) {
            return Rn(t);
          }),
            o = t.map(function (t) {
              return In(t);
            });
          return En(this.concat(r, e), this.concat(o, e));
        }

        var a = t.map(function (t) {
          var n = w(t.shape.slice(e));
          return t.as2D(-1, n);
        }),
          i = wn(a.map(function (t) {
            return t.shape;
          }), 1),
          u = ur(i, t[0].dtype).values;

        if (1 === a[0].shape[0]) {
          var s = 0;
          a.forEach(function (t) {
            u.set(n.readSync(t.dataId), s), s += t.size;
          });
        } else {
          var c = 0;
          a.forEach(function (t) {
            for (var e = n.readSync(t.dataId), r = 0, o = 0; o < t.shape[0]; ++o) for (var a = o * i[1] + c, s = 0; s < t.shape[1]; ++s) u[a + s] = e[r++];

            c += t.shape[1];
          });
        }

        var l = wn(t.map(function (t) {
          return t.shape;
        }), e);
        return kn(u, l, t[0].dtype);
      }, o.prototype.neg = function (t) {
        return Ih(t, "neg"), this.multiply(An(-1), t);
      }, o.prototype.add = function (t, e) {
        return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
          return {
            real: t + n,
            imag: e + r
          };
        }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
          return t + e;
        });
      }, o.prototype.addN = function (t) {
        var e = this;
        Ih(t, "addN");

        for (var n = t.map(function (t) {
          return e.readSync(t.dataId);
        }), r = ur(t[0].shape, t[0].dtype), o = r.values, a = 0; a < t.length; a++) for (var i = n[a], u = 0; u < o.length; u++) o[u] += i[u];

        return r.toTensor();
      }, o.prototype.subtract = function (t, e) {
        return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
          return {
            real: t - n,
            imag: e - r
          };
        }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
          return t - e;
        });
      }, o.prototype.pow = function (t, e) {
        return Ih([t, e], "pow"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          return Math.pow(t, e);
        });
      }, o.prototype.batchMatMul = function (t, e, n, r) {
        Ih([t, e], "matMul");

        for (var o = n ? t.shape[1] : t.shape[2], a = n ? t.shape[2] : t.shape[1], i = r ? e.shape[1] : e.shape[2], u = t.shape[0], s = this.readSync(t.dataId), c = this.readSync(e.dataId), l = n ? [t.strides[0], 1, t.strides[1]] : [t.strides[0], t.strides[1], 1], h = l[0], f = l[1], p = l[2], d = r ? [1, e.strides[1], e.strides[0]] : [e.strides[1], 1, e.strides[0]], v = d[0], m = d[1], g = d[2], y = a * i, x = ur([u, a, i], t.dtype), b = x.values, w = this.blockSize, C = 0; C < u; C++) for (var E = 0; E < a; E += w) for (var R = 0; R < i; R += w) for (var I = 0; I < o; I += w) for (var k = Math.min(E + w, a), S = Math.min(R + w, i), A = Math.min(I + w, o), D = E; D < k; D++) for (var T = R; T < S; T++) {
          for (var N = 0, F = I; F < A; F++) N += s[C * h + D * f + F * p] * c[F * v + T * m + C * g];

          b[C * y + (D * i + T)] += N;
        }

        return x.toTensor();
      }, o.prototype.fusedBatchMatMul = function (t) {
        var e = t.a,
          n = t.b,
          r = t.transposeA,
          o = t.transposeB,
          a = t.bias,
          i = t.activation,
          u = t.preluActivationWeights,
          s = this.batchMatMul(e, n, r, o);
        return a && (s = this.add(s, a)), i && (s = kh(this, s, i, u)), s;
      }, o.prototype.multiply = function (t, e) {
        return "complex64" === t.dtype || "complex64" === e.dtype ? this.broadcastedBinaryComplexOp(t.cast("complex64"), e.cast("complex64"), function (t, e, n, r) {
          return {
            real: t * n - e * r,
            imag: t * r + e * n
          };
        }) : this.broadcastedBinaryOp(t, e, Ct(t.dtype, e.dtype), function (t, e) {
          return t * e;
        });
      }, o.prototype.realDivide = function (t, e) {
        Ih([t, e], "realDivide");
        return this.broadcastedBinaryOp(t, e, "float32", function (t, e) {
          return t / e;
        });
      }, o.prototype.floorDiv = function (t, e) {
        Ih([t, e], "floorDiv");
        return this.broadcastedBinaryOp(t, e, "int32", function (t, e) {
          return Math.floor(t / e);
        });
      }, o.prototype.sum = function (t, e) {
        Ih(t, "sum"), mn("sum", e, t.rank);

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, Ct(t.dtype, "int32")), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = 0, f = 0; f < i; ++f) h += s[l + f];

          u[c] = h;
        }

        return a;
      }, o.prototype.prod = function (t, e) {
        Ih(t, "sum");

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, Ct(t.dtype, "int32")), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = 1, f = 0; f < i; ++f) h *= s[l + f];

          u[c] = h;
        }

        return a;
      }, o.prototype.unsortedSegmentSum = function (t, e, n) {
        Ih(t, "unsortedSegmentSum");

        for (var r = [], o = t.rank - e.rank, a = 0; a < o; ++a) e = e.expandDims(a + 1);

        for (a = 0; a < n; ++a) {
          var i = An(a, "int32"),
            u = sc(i, e).asType("float32").mul(t).sum(0);
          r.push(u);
        }

        return Tr(r);
      }, o.prototype.argMin = function (t, e) {
        Ih(t, "argMin");
        var n = [e];
        mn("argMin", n, t.rank);

        for (var r = dn(t.shape, n), o = r[0], a = r[1], i = Pn(o, "int32"), u = w(a), s = this.readSync(i.dataId), c = this.readSync(t.dataId), l = 0; l < s.length; ++l) {
          for (var h = l * u, f = c[h], p = 0, d = 0; d < u; ++d) {
            var v = c[h + d];
            v < f && (f = v, p = d);
          }

          s[l] = p;
        }

        return i;
      }, o.prototype.argMax = function (t, e) {
        Ih(t, "argMax");
        var n = [e];
        mn("argMax", n, t.rank);

        for (var r = dn(t.shape, n), o = r[0], a = r[1], i = Pn(o, "int32"), u = w(a), s = this.readSync(i.dataId), c = this.readSync(t.dataId), l = 0; l < s.length; ++l) {
          for (var h = l * u, f = c[h], p = 0, d = 0; d < u; ++d) {
            var v = c[h + d];
            v > f && (f = v, p = d);
          }

          s[l] = p;
        }

        return i;
      }, o.prototype.cumsum = function (t, e, n, r) {
        if (Ih(t, "cumsum"), e !== t.rank - 1) throw new Error("backend.cumsum in CPU expects an inner-most axis=" + (t.rank - 1) + " but got axis=" + e);

        for (var o = Ct(t.dtype, "int32"), a = Pn(t.shape, o), i = this.readSync(a.dataId), u = this.readSync(t.dataId), s = t.shape[t.rank - 1], c = r ? function (t, e) {
          return t + s - e - 1;
        } : function (t, e) {
          return t + e;
        }, l = 0; l < u.length; l += s) for (var h = 0; h < s; h++) {
          var f = c(l, h);
          if (0 === h) i[f] = n ? 0 : u[f]; else {
            var p = c(l, h - 1);
            i[f] = n ? u[p] + i[p] : u[f] + i[p];
          }
        }

        return a;
      }, o.prototype.equal = function (t, e) {
        return Ih([t, e], "equal"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t === e ? 1 : 0;
        });
      }, o.prototype.notEqual = function (t, e) {
        return Ih([t, e], "notEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t !== e ? 1 : 0;
        });
      }, o.prototype.less = function (t, e) {
        return Ih([t, e], "less"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t < e ? 1 : 0;
        });
      }, o.prototype.lessEqual = function (t, e) {
        return Ih([t, e], "lessEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t <= e ? 1 : 0;
        });
      }, o.prototype.greater = function (t, e) {
        return Ih([t, e], "greater"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t > e ? 1 : 0;
        });
      }, o.prototype.greaterEqual = function (t, e) {
        return Ih([t, e], "greaterEqual"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t >= e ? 1 : 0;
        });
      }, o.prototype.logicalNot = function (t) {
        Ih(t, "logicalNot");

        for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) n[r] = e[r] ? 0 : 1;

        return this.makeOutput(n, t.shape, "bool");
      }, o.prototype.logicalAnd = function (t, e) {
        return Ih([t, e], "logicalAnd"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t && e;
        });
      }, o.prototype.logicalOr = function (t, e) {
        return Ih([t, e], "logicalOr"), this.broadcastedBinaryOp(t, e, "bool", function (t, e) {
          return t || e;
        });
      }, o.prototype.select = function (t, e, n) {
        Ih([t, e, n], "select");

        for (var r = this.readSync(t.dataId), o = this.readSync(e.dataId), a = this.readSync(n.dataId), i = Pn(e.shape, Ct(e.dtype, n.dtype)), u = this.readSync(i.dataId), s = 0, c = 0 === t.rank || t.rank > 1 || 1 === e.rank ? 1 : w(e.shape.slice(1)), l = 0; l < r.length; l++) for (var h = 0; h < c; h++) 1 === r[l] ? u[s++] = o[l] : u[s++] = a[l];

        return i;
      }, o.prototype.where = function (t) {
        Ih([t], "where");
        var e = this.readSync(t.dataId);
        return Uo(t.shape, e);
      }, o.prototype.topk = function (t, e, n) {
        return Ih(t, "topk"), Wo(this.readSync(t.dataId), t.shape, t.dtype, e);
      }, o.prototype.min = function (t, e) {
        Ih(t, "min"), mn("min", e, t.rank);

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
            var p = s[l + f];
            p < h && (h = p);
          }

          u[c] = h;
        }

        return a;
      }, o.prototype.minimum = function (t, e) {
        return Ih([t, e], "minimum"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          return Math.min(t, e);
        });
      }, o.prototype.mod = function (t, e) {
        return Ih([t, e], "mod"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          var n = t % e;
          return t < 0 && e < 0 || t >= 0 && e >= 0 ? n : (n + e) % e;
        });
      }, o.prototype.max = function (t, e) {
        Ih(t, "max"), mn("max", e, t.rank);

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
            var p = s[l + f];
            p > h && (h = p);
          }

          u[c] = h;
        }

        return a;
      }, o.prototype.maximum = function (t, e) {
        return Ih([t, e], "maximum"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          return Math.max(t, e);
        });
      }, o.prototype.all = function (t, e) {
        Ih(t, "all"), mn("all", e, t.rank);

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
            var p = s[l + f];
            h = h && p;
          }

          u[c] = h;
        }

        return a;
      }, o.prototype.any = function (t, e) {
        Ih(t, "any"), mn("any", e, t.rank);

        for (var n = dn(t.shape, e), r = n[0], o = n[1], a = Pn(r, t.dtype), i = w(o), u = this.readSync(a.dataId), s = this.readSync(t.dataId), c = 0; c < u.length; ++c) {
          for (var l = c * i, h = s[l], f = 0; f < i; ++f) {
            var p = s[l + f];
            h = h || p;
          }

          u[c] = h;
        }

        return a;
      }, o.prototype.squaredDifference = function (t, e) {
        return Ih([t, e], "squaredDifference"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          var n = t - e;
          return n * n;
        });
      }, o.prototype.ceil = function (t) {
        Ih(t, "ceil");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.ceil(e[r]);

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.floor = function (t) {
        Ih(t, "floor");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.floor(e[r]);

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.sign = function (t) {
        Ih(t, "x");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) e[r] < 0 ? n[r] = -1 : e[r] > 0 ? n[r] = 1 : n[r] = 0;

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.isNaN = function (t) {
        Ih(t, "x");

        for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Number.isNaN(e[r]) && (n[r] = 1);

        return this.makeOutput(n, t.shape, "bool");
      }, o.prototype.isInf = function (t) {
        Ih(t, "x");

        for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Math.abs(e[r]) === 1 / 0 && (n[r] = 1);

        return this.makeOutput(n, t.shape, "bool");
      }, o.prototype.isFinite = function (t) {
        Ih(t, "x");

        for (var e = this.readSync(t.dataId), n = new Uint8Array(e.length), r = 0; r < e.length; ++r) Number.isFinite(e[r]) && (n[r] = 1);

        return this.makeOutput(n, t.shape, "bool");
      }, o.prototype.round = function (t) {
        Ih(t, "round");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
          var o = Math.floor(e[r]);
          e[r] - o < .5 ? n[r] = Math.floor(e[r]) : e[r] - o > .5 ? n[r] = Math.ceil(e[r]) : n[r] = o % 2 == 0 ? o : o + 1;
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.exp = function (t) {
        Ih(t, "exp");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.exp(e[r]);

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.expm1 = function (t) {
        Ih(t, "expm1");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = Math.expm1(e[r]);

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.log = function (t) {
        Ih(t, "log");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
          var o = e[r];
          n[r] = Math.log(o);
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.log1p = function (t) {
        Ih(t, "log1p");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
          var o = e[r];
          n[r] = Math.log1p(o);
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.sqrt = function (t) {
        Ih(t, "sqrt");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
          var o = e[r];
          n[r] = Math.sqrt(o);
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.rsqrt = function (t) {
        Ih(t, "rsqrt");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) {
          var o = e[r];
          n[r] = 1 / Math.sqrt(o);
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.reciprocal = function (t) {
        Ih(t, "reciprocal");

        for (var e = this.readSync(t.dataId), n = new Float32Array(e.length), r = 0; r < e.length; ++r) n[r] = 1 / e[r];

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.linear = function (t) {
        return t;
      }, o.prototype.relu = function (t) {
        Ih(t, "relu");

        for (var e = Pn(t.shape, t.dtype), n = this.readSync(e.dataId), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) n[o] = Math.max(0, r[o]);

        return e;
      }, o.prototype.relu6 = function (t) {
        Ih(t, "relu");

        for (var e = Pn(t.shape, t.dtype), n = this.readSync(e.dataId), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) n[o] = Math.min(Math.max(0, r[o]), 6);

        return e;
      }, o.prototype.prelu = function (t, e) {
        return Ih([t, e], "prelu"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          return t < 0 ? e * t : t;
        });
      }, o.prototype.elu = function (t) {
        Ih(t, "elu");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) {
          var o = n[r];
          e[r] = o >= 0 ? o : Math.exp(o) - 1;
        }

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.eluDer = function (t, e) {
        Ih([t, e], "eluDer");

        for (var n = new Float32Array(e.size), r = this.readSync(e.dataId), o = this.readSync(t.dataId), a = 0; a < r.length; ++a) {
          var i = r[a];
          n[a] = i >= 1 ? o[a] : o[a] * (i + 1);
        }

        return this.makeOutput(n, e.shape, "float32");
      }, o.prototype.selu = function (t) {
        Ih(t, "selu");

        for (var e = iu, n = uu, r = new Float32Array(t.size), o = this.readSync(t.dataId), a = 0; a < o.length; ++a) {
          var i = o[a];
          r[a] = i >= 0 ? n * i : e * (Math.exp(i) - 1);
        }

        return this.makeOutput(r, t.shape, "float32");
      }, o.prototype.clip = function (t, e, n) {
        Ih(t, "clip");

        for (var r = new Float32Array(t.size), o = this.readSync(t.dataId), a = 0; a < o.length; ++a) {
          var i = o[a];
          r[a] = i > n ? n : i < e ? e : i;
        }

        return this.makeOutput(r, t.shape, "float32");
      }, o.prototype.abs = function (t) {
        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.abs(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.complexAbs = function (t) {
        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < t.size; ++r) {
          var o = n[2 * r],
            a = n[2 * r + 1];
          e[r] = Math.hypot(o, a);
        }

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.int = function (t) {
        Ih(t, "int");

        for (var e = new Int32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = n[r];

        return this.makeOutput(e, t.shape, "int32");
      }, o.prototype.sigmoid = function (t) {
        Ih(t, "sigmoid");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = 1 / (1 + Math.exp(-n[r]));

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.softplus = function (t) {
        Ih(t, "softplus");

        for (var e = Math.log(1.1920928955078125e-7) + 2, n = new Float32Array(t.size), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) {
          var a = r[o] > -e,
            i = r[o] < e,
            u = Math.exp(r[o]),
            s = void 0;
          s = i ? u : a ? r[o] : Math.log(1 + u), n[o] = s;
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.sin = function (t) {
        Ih(t, "sin");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.sin(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.cos = function (t) {
        Ih(t, "cos");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.cos(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.tan = function (t) {
        Ih(t, "tan");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.tan(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.asin = function (t) {
        Ih(t, "asin");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.asin(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.acos = function (t) {
        Ih(t, "acos");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.acos(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.atan = function (t) {
        Ih(t, "atan");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.atan(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.atan2 = function (t, e) {
        return Ih([t, e], "atan2"), this.broadcastedBinaryOp(t, e, t.dtype, function (t, e) {
          return Math.atan2(t, e);
        });
      }, o.prototype.sinh = function (t) {
        Ih(t, "sinh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.sinh(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.cosh = function (t) {
        Ih(t, "cosh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.cosh(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.tanh = function (t) {
        Ih(t, "tanh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = R(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.asinh = function (t) {
        Ih(t, "asinh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.asinh(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.acosh = function (t) {
        Ih(t, "acosh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.acosh(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.atanh = function (t) {
        Ih(t, "atanh");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) e[r] = Math.atanh(n[r]);

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.erf = function (t) {
        Ih(t, "erf");

        for (var e = new Float32Array(t.size), n = this.readSync(t.dataId), r = 0; r < n.length; ++r) {
          var o = Math.sign(n[r]),
            a = Math.abs(n[r]),
            i = 1 / (1 + .3275911 * a);
          e[r] = o * (1 - ((((1.061405429 * i - 1.453152027) * i + 1.421413741) * i - .284496736) * i + .254829592) * i * Math.exp(-a * a));
        }

        return this.makeOutput(e, t.shape, "float32");
      }, o.prototype.step = function (t, e) {
        void 0 === e && (e = 0), Ih(t, "step");

        for (var n = new Float32Array(t.size), r = this.readSync(t.dataId), o = 0; o < r.length; ++o) {
          var a = r[o];
          isNaN(a) ? n[o] = NaN : n[o] = a > 0 ? 1 : e;
        }

        return this.makeOutput(n, t.shape, "float32");
      }, o.prototype.fusedConv2d = function (t) {
        var e = t.input,
          n = t.filter,
          r = t.convInfo,
          o = t.bias,
          a = t.activation,
          i = t.preluActivationWeights,
          u = this.conv2d(e, n, r);
        return o && (u = this.add(u, o)), a && (u = kh(this, u, a, i)), u;
      }, o.prototype.conv2d = function (t, e, n) {
        Ih([t, e], "conv2d");

        for (var r = n.filterHeight, o = n.filterWidth, a = n.dilationHeight, i = n.dilationWidth, u = n.padInfo.left, s = n.padInfo.top, c = "channelsLast" === n.dataFormat, l = ur(n.outShape, t.dtype), h = t.strides[0], f = c ? t.strides[1] : t.strides[2], p = c ? t.strides[2] : 1, d = c ? 1 : t.strides[1], v = l.strides[0], m = c ? l.strides[1] : l.strides[2], g = c ? l.strides[2] : 1, y = c ? 1 : l.strides[1], x = this.readSync(t.dataId), b = this.readSync(e.dataId), w = l.values, C = 0; C < n.batchSize; ++C) for (var E = C * h, R = C * v, I = 0; I < n.outHeight; ++I) for (var k = R + I * m, S = I * n.strideHeight - s, A = 0; A < r; A++) {
          var D = S + A * a;
          if (!(D < 0 || D >= n.inHeight)) for (var T = A * e.strides[0], N = E + D * f, F = 0; F < n.outWidth; ++F) for (var O = k + F * g, _ = F * n.strideWidth - u, M = 0; M < o; M++) {
            var B = _ + M * i;
            if (!(B < 0 || B >= n.inWidth)) for (var P = N + B * p, L = T + M * e.strides[1], W = 0; W < n.inChannels; ++W) {
              for (var U = x[P + W * d], V = 0; V < n.outChannels; ++V) w[O + V * y] += U * b[L + V];

              L += n.outChannels;
            }
          }
        }

        return l.toTensor();
      }, o.prototype.conv3d = function (t, e, n) {
        for (var r = n.filterDepth, o = n.filterHeight, a = n.filterWidth, i = n.dilationDepth, u = n.dilationHeight, s = n.dilationWidth, c = n.padInfo.front, l = n.padInfo.left, h = n.padInfo.top, f = ur(n.outShape, t.dtype), p = this.readSync(t.dataId), d = this.readSync(e.dataId), v = f.values, m = 0; m < n.batchSize; ++m) for (var g = m * t.strides[0], y = m * f.strides[0], x = 0; x < n.outDepth; ++x) for (var b = y + x * f.strides[1], w = x * n.strideDepth - c, C = 0; C < r; C++) {
          var E = w + C * i;
          if (!(E < 0 || E >= n.inDepth)) for (var R = C * e.strides[0], I = g + E * t.strides[1], k = 0; k < n.outHeight; ++k) for (var S = b + k * f.strides[2], A = k * n.strideHeight - h, D = 0; D < o; D++) {
            var T = A + D * u;
            if (!(T < 0 || T >= n.inHeight)) for (var N = R + D * e.strides[1], F = I + T * t.strides[2], O = 0; O < n.outWidth; ++O) for (var _ = S + O * n.outChannels, M = O * n.strideWidth - l, B = 0; B < a; B++) {
              var P = M + B * s;
              if (!(P < 0 || P >= n.inWidth)) for (var L = N + B * e.strides[2], W = F + P * n.inChannels, U = L, V = 0; V < n.inChannels; ++V) {
                for (var z = p[W + V], G = 0; G < n.outChannels; ++G) v[_ + G] += z * d[U + G];

                U += n.outChannels;
              }
            }
          }
        }

        return f.toTensor();
      }, o.prototype.conv2dDerInput = function (t, e, n) {
        Ih([t, e], "conv2dDerInput");

        for (var r = ur(n.inShape, "float32"), o = r.values, a = this.readSync(t.dataId), i = this.readSync(e.dataId), u = e.strides, s = u[0], c = u[1], l = u[2], h = n.batchSize, f = n.filterHeight, p = n.filterWidth, d = n.inChannels, v = n.inHeight, m = n.inWidth, g = n.outChannels, y = n.outHeight, x = n.outWidth, b = n.strideHeight, w = n.strideWidth, C = n.dataFormat, E = f - 1 - n.padInfo.top, R = p - 1 - n.padInfo.left, I = "channelsLast" === C, k = r.strides[0], S = I ? r.strides[1] : r.strides[2], A = I ? r.strides[2] : 1, D = I ? 1 : r.strides[1], T = t.strides[0], N = I ? t.strides[1] : t.strides[2], F = I ? t.strides[2] : 1, O = I ? 1 : t.strides[1], _ = 0; _ < h; ++_) for (var M = 0; M < d; ++M) for (var B = 0; B < v; ++B) for (var P = B - E, L = Math.max(0, Math.ceil(P / b)), W = Math.min(y, (f + P) / b), U = 0; U < m; ++U) {
          for (var V = U - R, z = Math.max(0, Math.ceil(V / w)), G = Math.min(x, (p + V) / w), H = 0, q = L; q < W; ++q) for (var K = q * b - P, j = z; j < G; ++j) for (var X = T * _ + N * q + F * j, $ = s * (f - 1 - K) + c * (p - 1 - (j * w - V)) + l * M, Y = 0; Y < g; ++Y) {
            H += a[X + O * Y] * i[$ + Y];
          }

          o[k * _ + S * B + A * U + D * M] = H;
        }

        return r.toTensor();
      }, o.prototype.conv3dDerInput = function (t, e, n) {
        for (var r = ur(n.inShape, "float32"), o = r.values, a = r.strides, i = a[0], u = a[1], s = a[2], c = a[3], l = this.readSync(t.dataId), h = t.strides, f = h[0], p = h[1], d = h[2], v = h[3], m = this.readSync(e.dataId), g = e.strides, y = g[0], x = g[1], b = g[2], w = g[3], C = n.batchSize, E = n.filterDepth, R = n.filterHeight, I = n.filterWidth, k = n.inChannels, S = n.inDepth, A = n.inHeight, D = n.inWidth, T = n.outChannels, N = n.outDepth, F = n.outHeight, O = n.outWidth, _ = n.strideDepth, M = n.strideHeight, B = n.strideWidth, P = E - 1 - n.padInfo.front, L = R - 1 - n.padInfo.top, W = I - 1 - n.padInfo.left, U = 0; U < C; ++U) for (var V = 0; V < k; ++V) for (var z = 0; z < S; ++z) for (var G = z - P, H = Math.max(0, Math.ceil(G / _)), q = Math.min(N, (E + G) / _), K = 0; K < A; ++K) for (var j = K - L, X = Math.max(0, Math.ceil(j / M)), $ = Math.min(F, (R + j) / M), Y = 0; Y < D; ++Y) {
          for (var Q = Y - W, J = Math.max(0, Math.ceil(Q / B)), Z = Math.min(O, (I + Q) / B), tt = 0, et = H; et < q; ++et) for (var nt = et * _ - G, rt = X; rt < $; ++rt) for (var ot = rt * M - j, at = J; at < Z; ++at) for (var it = f * U + p * et + d * rt + v * at, ut = y * (E - 1 - nt) + x * (R - 1 - ot) + b * (I - 1 - (at * B - Q)) + w * V, st = 0; st < T; ++st) {
            tt += l[it + st] * m[ut + st];
          }

          o[i * U + u * z + s * K + c * Y + V] = tt;
        }

        return r.toTensor();
      }, o.prototype.conv2dDerFilter = function (t, e, n) {
        Ih([t, e], "conv2dDerFilter");

        for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = "channelsLast" === n.dataFormat, s = ur(n.filterShape, "float32"), c = n.padInfo.left, l = n.padInfo.top, h = this.bufferSync(t), f = this.bufferSync(e), p = 0; p < a; ++p) for (var d = Math.max(0, Math.ceil((l - p) / r)), v = Math.min(n.outHeight, (n.inHeight + l - p) / r), m = 0; m < i; ++m) for (var g = Math.max(0, Math.ceil((c - m) / o)), y = Math.min(n.outWidth, (n.inWidth + c - m) / o), x = 0; x < n.inChannels; ++x) for (var b = 0; b < n.outChannels; ++b) {
          for (var w = 0, C = 0; C < n.batchSize; ++C) for (var E = d; E < v; ++E) for (var R = p + E * r - l, I = g; I < y; ++I) {
            var k = m + I * o - c;
            w += u ? h.get(C, R, k, x) * f.get(C, E, I, b) : h.get(C, x, R, k) * f.get(C, b, E, I);
          }

          s.set(w, p, m, x, b);
        }

        return s.toTensor();
      }, o.prototype.conv3dDerFilter = function (t, e, n) {
        for (var r = n.strideDepth, o = n.strideHeight, a = n.strideWidth, i = n.filterDepth, u = n.filterHeight, s = n.filterWidth, c = ur(n.filterShape, "float32"), l = c.values, h = c.strides, f = h[0], p = h[1], d = h[2], v = h[3], m = this.readSync(e.dataId), g = e.strides, y = g[0], x = g[1], b = g[2], w = g[3], C = this.readSync(t.dataId), E = t.strides, R = E[0], I = E[1], k = E[2], S = E[3], A = n.padInfo.front, D = n.padInfo.left, T = n.padInfo.top, N = 0; N < i; ++N) for (var F = Math.max(0, Math.ceil((A - N) / r)), O = Math.min(n.outDepth, (n.inDepth + A - N) / r), _ = N * f, M = 0; M < u; ++M) for (var B = Math.max(0, Math.ceil((T - M) / o)), P = Math.min(n.outHeight, (n.inHeight + T - M) / o), L = M * p + _, W = 0; W < s; ++W) for (var U = Math.max(0, Math.ceil((D - W) / a)), V = Math.min(n.outWidth, (n.inWidth + D - W) / a), z = W * d + L, G = 0; G < n.inChannels; ++G) for (var H = G * v + z, q = 0; q < n.outChannels; ++q) {
          for (var K = 0, j = 0; j < n.batchSize; ++j) for (var X = j * R, $ = j * y, Y = F; Y < O; ++Y) for (var Q = (N + Y * r - A) * I + X, J = Y * x + $, Z = B; Z < P; ++Z) for (var tt = (M + Z * o - T) * k + Q, et = Z * b + J, nt = U; nt < V; ++nt) {
            var rt = nt * w + et;
            K += C[(W + nt * a - D) * S + tt + G] * m[rt + q];
          }

          l[H + q] = K;
        }

        return c.toTensor();
      }, o.prototype.fusedDepthwiseConv2D = function (t) {
        var e = t.input,
          n = t.filter,
          r = t.convInfo,
          o = t.bias,
          a = t.activation,
          i = t.preluActivationWeights,
          u = this.depthwiseConv2D(e, n, r);
        return o && (u = this.add(u, o)), a && (u = kh(this, u, a, i)), u;
      }, o.prototype.depthwiseConv2D = function (t, e, n) {
        Ih([t, e], "depthwiseConv2D");

        for (var r = n.filterHeight, o = n.filterWidth, a = n.dilationHeight, i = n.dilationWidth, u = n.padInfo.left, s = n.padInfo.top, c = n.outChannels / n.inChannels, l = ur(n.outShape, t.dtype), h = this.readSync(t.dataId), f = this.readSync(e.dataId), p = l.values, d = 0; d < n.batchSize; ++d) for (var v = d * t.strides[0], m = d * l.strides[0], g = 0; g < n.outHeight; ++g) for (var y = m + g * l.strides[1], x = g * n.strideHeight - u, b = 0; b < r; ++b) {
          var w = x + b * a;
          if (!(w < 0 || w >= n.inHeight)) for (var C = b * e.strides[0], E = v + w * t.strides[1], R = 0; R < n.outWidth; ++R) for (var I = y + R * l.strides[2], k = R * n.strideWidth - s, S = 0; S < o; ++S) {
            var A = k + S * i;
            if (!(A < 0 || A >= n.inWidth)) for (var D = C + S * e.strides[1], T = E + A * n.inChannels, N = I, F = D, O = 0; O < n.inChannels; ++O) {
              for (var _ = h[T + O], M = 0; M < c; ++M) p[N + M] += _ * f[F + M];

              N += c, F += c;
            }
          }
        }

        return l.toTensor();
      }, o.prototype.depthwiseConv2DDerInput = function (t, e, n) {
        Ih([t, e], "depthwiseConv2DDerInput");

        for (var r = ur(n.inShape, "float32"), o = r.values, a = r.strides, i = a[0], u = a[1], s = a[2], c = this.readSync(t.dataId), l = t.strides, h = l[0], f = l[1], p = l[2], d = this.readSync(e.dataId), v = e.strides, m = v[0], g = v[1], y = v[2], x = n.batchSize, b = n.filterHeight, w = n.filterWidth, C = n.inChannels, E = n.inHeight, R = n.inWidth, I = n.outChannels, k = n.outHeight, S = n.outWidth, A = n.strideHeight, D = n.strideWidth, T = b - 1 - n.padInfo.top, N = w - 1 - n.padInfo.left, F = I / C, O = 0; O < x; ++O) for (var _ = 0; _ < C; ++_) for (var M = 0; M < E; ++M) for (var B = M - T, P = Math.max(0, Math.ceil(B / A)), L = Math.min(k, (b + B) / A), W = 0; W < R; ++W) {
          for (var U = W - N, V = Math.max(0, Math.ceil(U / D)), z = Math.min(S, (w + U) / D), G = 0, H = P; H < L; ++H) for (var q = H * A - B, K = V; K < z; ++K) for (var j = h * O + f * H + p * K, X = m * (b - 1 - q) + g * (w - 1 - (K * D - U)) + y * _, $ = 0; $ < F; ++$) {
            G += c[j + (_ * F + $)] * d[X + $];
          }

          o[i * O + u * M + s * W + _] = G;
        }

        return r.toTensor();
      }, o.prototype.depthwiseConv2DDerFilter = function (t, e, n) {
        Ih([t, e], "depthwiseConv2DDerFilter");

        for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = ur(n.filterShape, "float32"), s = n.padInfo.left, c = n.padInfo.top, l = n.outChannels / n.inChannels, h = this.bufferSync(t), f = this.bufferSync(e), p = 0; p < a; ++p) for (var d = Math.max(0, Math.ceil((c - p) / r)), v = Math.min(n.outHeight, (n.inHeight + c - p) / r), m = 0; m < i; ++m) for (var g = Math.max(0, Math.ceil((s - m) / o)), y = Math.min(n.outWidth, (n.inWidth + s - m) / o), x = 0; x < n.outChannels; ++x) {
          for (var b = Math.trunc(x / l), w = x % l, C = 0, E = 0; E < n.batchSize; ++E) for (var R = d; R < v; ++R) for (var I = p + R * r - c, k = g; k < y; ++k) {
            var S = m + k * o - s;
            C += h.get(E, I, S, b) * f.get(E, R, k, x);
          }

          u.set(C, p, m, b, w);
        }

        return u.toTensor();
      }, o.prototype.tile = function (t, e) {
        return Ih(t, "tile"), Lo(this.bufferSync(t), e);
      }, o.prototype.pad = function (t, e, n) {
        Ih(t, "pad");
        var r = e.map(function (e, n) {
          return e[0] + t.shape[n] + e[1];
        }),
          o = e.map(function (t) {
            return t[0];
          }),
          a = this.bufferSync(t),
          i = ur(r, t.dtype);
        0 !== n && i.values.fill(n);

        for (var u = 0; u < t.size; u++) {
          var s = a.indexToLoc(u),
            c = s.map(function (t, e) {
              return t + o[e];
            });
          i.set.apply(i, [a.get.apply(a, s)].concat(c));
        }

        return i.toTensor();
      }, o.prototype.transpose = function (t, e) {
        Ih(t, "transpose");

        for (var n = new Array(t.rank), r = 0; r < n.length; r++) n[r] = t.shape[e[r]];

        var o = this.readSync(t.dataId),
          a = ur(n, t.dtype),
          i = this.bufferSync(t);

        for (r = 0; r < t.size; ++r) {
          for (var u = i.indexToLoc(r), s = new Array(u.length), c = 0; c < s.length; c++) s[c] = u[e[c]];

          var l = a.locToIndex(s);
          a.values[l] = o[r];
        }

        return a.toTensor();
      }, o.prototype.gather = function (t, e, n) {
        Ih([t, e], "gather");
        var r = t.shape.slice(),
          o = this.readSync(e.dataId);
        r[n] = o.length;

        for (var a = ur(r, t.dtype), i = this.bufferSync(t), u = 0; u < a.size; ++u) {
          var s = a.indexToLoc(u),
            c = s.slice();
          c[n] = o[s[n]];
          var l = i.locToIndex(c);
          a.values[u] = i.values[l];
        }

        return a.toTensor();
      }, o.prototype.batchToSpaceND = function (t, e, n) {
        Ih([t], "batchToSpaceND");
        var r = e.reduce(function (t, e) {
          return t * e;
        }),
          o = Mr(t.shape, e, r),
          a = Br(o.length, e.length),
          i = Pr(t.shape, e, r),
          u = Lr(n, e.length),
          s = Wr(i, n, e.length);
        return t.reshape(o).transpose(a).reshape(i).slice(u, s);
      }, o.prototype.spaceToBatchND = function (t, e, n) {
        Ih([t], "spaceToBatchND");
        var r = e.reduce(function (t, e) {
          return t * e;
        }),
          o = [[0, 0]];
        o.push.apply(o, n);

        for (var a = 1 + e.length; a < t.shape.length; ++a) o.push([0, 0]);

        var i = t.pad(o),
          u = Mr(i.shape, e, r, !1),
          s = Br(u.length, e.length, !1),
          c = Pr(i.shape, e, r, !1);
        return i.reshape(u).transpose(s).reshape(c);
      }, o.prototype.pool = function (t, e, n) {
        Ih(t, "pool");

        for (var r = e.strideHeight, o = e.strideWidth, a = e.dilationHeight, i = e.dilationWidth, u = e.effectiveFilterHeight, s = e.effectiveFilterWidth, c = e.padInfo.top, l = e.padInfo.left, h = "max" === n ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, f = this.readSync(t.dataId), p = ur(e.outShape, t.dtype), d = p.values, v = e.outShape[1] * e.outShape[2] * e.outShape[3], m = e.outShape[2] * e.outShape[3], g = e.outShape[3], y = 0; y < e.batchSize; ++y) for (var x = y * v, b = y * t.strides[0], w = 0; w < e.inChannels; ++w) for (var C = 0; C < e.outHeight; ++C) for (var E = C * r - c, R = Math.max(0, E), I = Math.min(e.inHeight, u + E), k = x + C * m, S = 0; S < e.outWidth; ++S) {
          for (var A = S * o - l, D = Math.max(0, A), T = Math.min(e.inWidth, s + A), N = h, F = 0, O = 0, _ = R; _ < I; _ += a) {
            for (var M = b + _ * t.strides[1], B = D; B < T; B += i) {
              var P = f[M + B * t.strides[2] + w];
              "max" === n && P > N ? N = P : "avg" === n && (F += P, O++);
            }

            if (isNaN(N)) break;
          }

          d[k + S * g + w] = "avg" === n ? F / O : N;
        }

        return p.toTensor();
      }, o.prototype.maxPool = function (t, e) {
        return this.pool(t, e, "max");
      }, o.prototype.maxPoolPositions = function (t, e) {
        for (var n = ur(e.outShape, "int32"), r = e.strideHeight, o = e.strideWidth, a = e.dilationHeight, i = e.dilationWidth, u = e.effectiveFilterHeight, s = e.effectiveFilterWidth, c = e.padInfo.top, l = e.padInfo.left, h = this.bufferSync(t), f = 0; f < e.batchSize; ++f) for (var p = 0; p < e.inChannels; ++p) for (var d = 0; d < e.outHeight; ++d) {
          for (var v = d * r - c, m = v; m < 0;) m += a;

          for (var g = Math.min(e.inHeight, u + v), y = 0; y < e.outWidth; ++y) {
            for (var x = y * o - l, b = x; b < 0;) b += i;

            for (var w = Math.min(e.inWidth, s + x), C = Number.NEGATIVE_INFINITY, E = -1, R = m; R < g; R += a) for (var I = R - v, k = b; k < w; k += i) {
              var S = k - x,
                A = h.get(f, R, k, p);
              A > C && (C = A, E = I * s + S);
            }

            n.set(E, f, d, y, p);
          }
        }

        return n.toTensor();
      }, o.prototype.maxPoolBackprop = function (t, e, n, r) {
        Ih([e, n], "maxPoolBackprop");

        for (var o = this.maxPoolPositions(e, r), a = r.strideHeight, i = r.strideWidth, u = r.dilationHeight, s = r.dilationWidth, c = r.effectiveFilterHeight, l = r.effectiveFilterWidth, h = l - 1 - r.padInfo.left, f = c - 1 - r.padInfo.top, p = ur(e.shape, "float32"), d = this.bufferSync(o), v = this.bufferSync(t), m = 0; m < r.batchSize; ++m) for (var g = 0; g < r.inChannels; ++g) for (var y = 0; y < r.inHeight; ++y) for (var x = 0; x < r.inWidth; ++x) {
          for (var b = y - f, w = x - h, C = 0, E = 0; E < c; E += u) {
            var R = (b + E) / a;
            if (!(R < 0 || R >= r.outHeight || Math.floor(R) !== R)) for (var I = 0; I < l; I += s) {
              var k = (w + I) / i;

              if (!(k < 0 || k >= r.outWidth || Math.floor(k) !== k)) {
                var S = c * l - 1 - d.get(m, R, k, g) === E * l + I ? 1 : 0;
                if (0 !== S) C += v.get(m, R, k, g) * S;
              }
            }
          }

          p.set(C, m, y, x, g);
        }

        return p.toTensor();
      }, o.prototype.avgPoolBackprop = function (t, e, n) {
        Ih([t, e], "avgPoolBackprop");

        for (var r = n.strideHeight, o = n.strideWidth, a = n.filterHeight, i = n.filterWidth, u = n.dilationHeight, s = n.dilationWidth, c = n.effectiveFilterHeight, l = n.effectiveFilterWidth, h = l - 1 - n.padInfo.left, f = c - 1 - n.padInfo.top, p = ur(e.shape, "float32"), d = 1 / (a * i), v = this.bufferSync(t), m = 0; m < n.batchSize; ++m) for (var g = 0; g < n.inChannels; ++g) for (var y = 0; y < n.inHeight; ++y) for (var x = 0; x < n.inWidth; ++x) {
          for (var b = y - f, w = x - h, C = 0, E = 0; E < c; E += u) {
            var R = (b + E) / r;
            if (!(R < 0 || R >= n.outHeight || Math.floor(R) !== R)) for (var I = 0; I < l; I += s) {
              var k = (w + I) / o;
              if (!(k < 0 || k >= n.outWidth || Math.floor(k) !== k)) C += v.get(m, R, k, g);
            }
          }

          p.set(C * d, m, y, x, g);
        }

        return p.toTensor();
      }, o.prototype.pool3d = function (t, e, n) {
        Ih(t, "pool3d");

        for (var r = e.strideDepth, o = e.strideHeight, a = e.strideWidth, i = e.dilationDepth, u = e.dilationHeight, s = e.dilationWidth, c = e.effectiveFilterDepth, l = e.effectiveFilterHeight, h = e.effectiveFilterWidth, f = e.padInfo.front, p = e.padInfo.top, d = e.padInfo.left, v = "max" === n ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, m = this.readSync(t.dataId), g = ur(e.outShape, t.dtype), y = g.values, x = e.outShape[1] * e.outShape[2] * e.outShape[3] * e.outShape[4], b = e.outShape[2] * e.outShape[3] * e.outShape[4], w = e.outShape[3] * e.outShape[4], C = e.outShape[4], E = 0; E < e.batchSize; ++E) for (var R = E * x, I = E * t.strides[0], k = 0; k < e.inChannels; ++k) for (var S = 0; S < e.outDepth; ++S) {
          for (var A = S * r - f, D = A; D < 0;) D += i;

          for (var T = Math.min(e.inDepth, c + A), N = R + S * b, F = 0; F < e.outHeight; ++F) {
            for (var O = F * o - p, _ = O; _ < 0;) _ += u;

            for (var M = Math.min(e.inHeight, l + O), B = N + F * w, P = 0; P < e.outWidth; ++P) {
              for (var L = P * a - d, W = L; W < 0;) W += s;

              for (var U = Math.min(e.inWidth, h + L), V = B + P * C, z = v, G = 0, H = 0, q = D; q < T; q += i) {
                for (var K = I + q * t.strides[1], j = _; j < M; j += u) {
                  for (var X = K + j * t.strides[2], $ = W; $ < U; $ += s) {
                    var Y = m[X + $ * t.strides[3] + k];
                    if ("max" === n && Y > z ? z = Y : "avg" === n && (G += Y, H++), isNaN(z)) break;
                  }

                  if (isNaN(z)) break;
                }

                if (isNaN(z)) break;
              }

              y[V + k] = "avg" === n ? G / H : z;
            }
          }
        }

        return g.toTensor();
      }, o.prototype.avgPool3d = function (t, e) {
        return Ih(t, "avgPool3d"), this.pool3d(t, e, "avg").toFloat();
      }, o.prototype.avgPool3dBackprop = function (t, e, n) {
        Ih([t, e], "avgPool3dBackprop");

        for (var r = n.strideDepth, o = n.strideHeight, a = n.strideWidth, i = n.filterDepth, u = n.filterHeight, s = n.filterWidth, c = n.dilationDepth, l = n.dilationHeight, h = n.dilationWidth, f = n.effectiveFilterDepth, p = n.effectiveFilterHeight, d = n.effectiveFilterWidth, v = f - 1 - n.padInfo.front, m = d - 1 - n.padInfo.left, g = p - 1 - n.padInfo.top, y = ur(e.shape, "float32"), x = 1 / (i * u * s), b = this.bufferSync(t), w = 0; w < n.batchSize; ++w) for (var C = 0; C < n.inChannels; ++C) for (var E = 0; E < n.inDepth; ++E) for (var R = 0; R < n.inHeight; ++R) for (var I = 0; I < n.inWidth; ++I) {
          for (var k = E - v, S = R - g, A = I - m, D = 0, T = 0; T < f; T += c) {
            var N = (k + T) / r;
            if (!(N < 0 || N >= n.outDepth || Math.floor(N) !== N)) for (var F = 0; F < p; F += l) {
              var O = (S + F) / o;
              if (!(O < 0 || O >= n.outHeight || Math.floor(O) !== O)) for (var _ = 0; _ < d; _ += h) {
                var M = (A + _) / a;
                if (!(M < 0 || M >= n.outWidth || Math.floor(M) !== M)) D += b.get(w, N, O, M, C);
              }
            }
          }

          y.set(D * x, w, E, R, I, C);
        }

        return y.toTensor();
      }, o.prototype.maxPool3d = function (t, e) {
        return Ih(t, "maxPool3d"), this.pool3d(t, e, "max").toFloat();
      }, o.prototype.maxPool3dPositions = function (t, e) {
        for (var n = ur(e.outShape, "int32"), r = e.strideDepth, o = e.strideHeight, a = e.strideWidth, i = e.dilationDepth, u = e.dilationHeight, s = e.dilationWidth, c = e.effectiveFilterDepth, l = e.effectiveFilterHeight, h = e.effectiveFilterWidth, f = e.padInfo.front, p = e.padInfo.top, d = e.padInfo.left, v = this.bufferSync(t), m = 0; m < e.batchSize; ++m) for (var g = 0; g < e.inChannels; ++g) for (var y = 0; y < e.outDepth; ++y) {
          for (var x = y * r - f, b = x; b < 0;) b += i;

          for (var w = Math.min(e.inDepth, c + x), C = 0; C < e.outHeight; ++C) {
            for (var E = C * o - p, R = E; R < 0;) R += u;

            for (var I = Math.min(e.inHeight, l + E), k = 0; k < e.outWidth; ++k) {
              for (var S = k * a - d, A = S; A < 0;) A += s;

              for (var D = Math.min(e.inWidth, h + S), T = Number.NEGATIVE_INFINITY, N = -1, F = b; F < w; F += i) for (var O = F - x, _ = R; _ < I; _ += u) for (var M = _ - E, B = A; B < D; B += s) {
                var P = B - S,
                  L = v.get(m, F, _, B, g);
                L >= T && (T = L, N = O * l * h + M * l + P);
              }

              n.set(N, m, y, C, k, g);
            }
          }
        }

        return n.toTensor();
      }, o.prototype.maxPool3dBackprop = function (t, e, n, r) {
        Ih([e, n], "maxPool3dBackprop");

        for (var o = this.maxPool3dPositions(e, r), a = r.strideDepth, i = r.strideHeight, u = r.strideWidth, s = r.dilationDepth, c = r.dilationHeight, l = r.dilationWidth, h = r.effectiveFilterDepth, f = r.effectiveFilterHeight, p = r.effectiveFilterWidth, d = h - 1 - r.padInfo.front, v = p - 1 - r.padInfo.left, m = f - 1 - r.padInfo.top, g = ur(e.shape, "float32"), y = this.bufferSync(o), x = this.bufferSync(t), b = 0; b < r.batchSize; ++b) for (var w = 0; w < r.inChannels; ++w) for (var C = 0; C < r.inDepth; ++C) for (var E = 0; E < r.inHeight; ++E) for (var R = 0; R < r.inWidth; ++R) {
          for (var I = C - d, k = E - m, S = R - v, A = 0, D = 0; D < h; D += s) {
            var T = (I + D) / a;
            if (!(T < 0 || T >= r.outDepth || Math.floor(T) !== T)) for (var N = 0; N < f; N += c) {
              var F = (k + N) / i;
              if (!(F < 0 || F >= r.outHeight || Math.floor(F) !== F)) for (var O = 0; O < p; O += l) {
                var _ = (S + O) / u;

                if (!(_ < 0 || _ >= r.outWidth || Math.floor(_) !== _)) {
                  var M = h * f * p - 1 - y.get(b, T, F, _, w) === D * f * p + N * p + O ? 1 : 0;
                  if (0 !== M) A += x.get(b, T, F, _, w) * M;
                }
              }
            }
          }

          g.set(A, b, C, E, R, w);
        }

        return g.toTensor();
      }, o.prototype.cast = function (t, e) {
        return So(t, e, this);
      }, o.prototype.reshape = function (t, e) {
        return Ao(t, e);
      }, o.prototype.avgPool = function (t, e) {
        return Ih(t, "avgPool"), this.pool(t, e, "avg").toFloat();
      }, o.prototype.resizeBilinear = function (t, e, n, r) {
        Ih(t, "resizeBilinear");

        for (var o = t.shape, a = o[0], i = o[1], u = o[2], s = o[3], c = this.readSync(t.dataId), l = new Float32Array(w([a, e, n, s])), h = [r && e > 1 ? i - 1 : i, r && n > 1 ? u - 1 : u], f = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n], p = 0, d = h[0] / f[0], v = h[1] / f[1], m = 0; m < a; m++) for (var g = 0; g < e; g++) for (var y = d * g, x = Math.floor(y), b = y - x, C = Math.min(i - 1, Math.ceil(y)), E = m * t.strides[0] + x * t.strides[1], R = m * t.strides[0] + C * t.strides[1], I = 0; I < n; I++) for (var k = v * I, S = Math.floor(k), A = k - S, D = Math.min(u - 1, Math.ceil(k)), T = E + S * t.strides[2], N = R + S * t.strides[2], F = E + +D * t.strides[2], O = R + D * t.strides[2], _ = 0; _ < s; _++) {
          var M = c[T + _],
            B = c[N + _],
            P = M + (c[F + _] - M) * A,
            L = P + (B + (c[O + _] - B) * A - P) * b;
          l[p++] = L;
        }

        return kn(l, [a, e, n, s]);
      }, o.prototype.resizeBilinearBackprop = function (t, e, n) {
        Ih([t, e], "resizeBilinearBackprop");

        for (var r = e.shape, o = r[0], a = r[1], i = r[2], u = r[3], s = t.shape, c = s[1], l = s[2], h = new Float32Array(o * a * i * u), f = [n && c > 1 ? a - 1 : a, n && l > 1 ? i - 1 : i], p = [n && c > 1 ? c - 1 : c, n && l > 1 ? l - 1 : l], d = f[0] / p[0], v = f[1] / p[1], m = this.readSync(t.dataId), g = 0, y = 0; y < o; y++) for (var x = y * e.strides[0], b = 0; b < c; b++) for (var w = b * d, C = Math.floor(w), E = Math.min(Math.ceil(w), a - 1), R = x + C * e.strides[1], I = x + E * e.strides[1], k = w - C, S = 1 - k, A = 0; A < l; A++) for (var D = A * v, T = Math.floor(D), N = Math.min(Math.ceil(D), i - 1), F = D - T, O = 1 - F, _ = R + T * e.strides[2], M = R + N * e.strides[2], B = I + T * e.strides[2], P = I + N * e.strides[2], L = S * O, W = S * F, U = k * O, V = k * F, z = 0; z < u; z++) {
          var G = m[g++];
          h[_ + z] += G * L, h[M + z] += G * W, h[B + z] += G * U, h[P + z] += G * V;
        }

        return Fn(h, [o, i, a, u], e.dtype);
      }, o.prototype.resizeNearestNeighbor = function (t, e, n, r) {
        Ih(t, "resizeNearestNeighbor");

        for (var o = t.shape, a = o[0], i = o[1], u = o[2], s = o[3], c = this.readSync(t.dataId), l = new Float32Array(a * e * n * s), h = [r && e > 1 ? i - 1 : i, r && n > 1 ? u - 1 : u], f = [r && e > 1 ? e - 1 : e, r && n > 1 ? n - 1 : n], p = h[0] / f[0], d = h[1] / f[1], v = 0, m = 0; m < a; m++) for (var g = m * t.strides[0], y = 0; y < e; y++) for (var x = p * y, b = g + Math.min(i - 1, r ? Math.round(x) : Math.floor(x)) * t.strides[1], w = 0; w < n; w++) for (var C = d * w, E = b + Math.min(u - 1, r ? Math.round(C) : Math.floor(C)) * t.strides[2], R = 0; R < s; R++) {
          var I = c[E + R];
          l[v++] = I;
        }

        return kn(l, [a, e, n, s], t.dtype);
      }, o.prototype.resizeNearestNeighborBackprop = function (t, e, n) {
        Ih([t, e], "resizeNearestNeighborBackprop");

        for (var r = e.shape, o = r[0], a = r[1], i = r[2], u = r[3], s = t.shape, c = s[1], l = s[2], h = new Float32Array(o * a * i * u), f = this.readSync(t.dataId), p = [n && c > 1 ? a - 1 : a, n && l > 1 ? i - 1 : i], d = [n && c > 1 ? c - 1 : c, n && l > 1 ? l - 1 : l], v = p[0] / d[0], m = p[1] / d[1], g = 1 / v, y = 1 / m, x = 2 * Math.ceil(g) + 2, b = 2 * Math.ceil(y) + 2, w = 0; w < o; w++) for (var C = w * e.strides[0], E = 0; E < a; E++) for (var R = C + E * e.strides[1], I = Math.floor(E * g), k = Math.floor(I - x / 2), S = 0; S < i; S++) for (var A = R + S * e.strides[2], D = Math.floor(S * y), T = Math.floor(D - b / 2), N = 0; N < u; N++) {
          for (var F = 0, O = 0; O < x; O++) {
            var _ = O + k;

            if (!(_ < 0 || _ >= c)) {
              var M = C + _ * t.strides[1],
                B = _ * v;
              if (E === Math.min(a - 1, n ? Math.round(B) : Math.floor(B))) for (var P = 0; P < b; P++) {
                var L = P + T;

                if (!(L < 0 || L >= l)) {
                  var W = M + L * t.strides[2],
                    U = L * m;
                  S === Math.min(i - 1, n ? Math.round(U) : Math.floor(U)) && (F += f[W + N]);
                }
              }
            }
          }

          h[A + N] = F;
        }

        return Fn(h, e.shape, e.dtype);
      }, o.prototype.batchNormalization = function (t, e, n, r, o, a) {
        Ih([t, e, n, o, a], "batchNorm");

        for (var i = this.readSync(t.dataId), u = this.readSync(e.dataId), s = this.readSync(n.dataId), c = o ? this.readSync(o.dataId) : new Float32Array([1]), l = a ? this.readSync(a.dataId) : new Float32Array([0]), h = new Float32Array(i.length), f = l.length, p = c.length, d = s.length, v = u.length, m = 0, g = 0, y = 0, x = 0, b = 0; b < i.length; ++b) h[b] = l[m++] + (i[b] - u[g++]) * c[y++] / Math.sqrt(s[x++] + r), m >= f && (m = 0), g >= v && (g = 0), y >= p && (y = 0), x >= d && (x = 0);

        return Fn(h, t.shape);
      }, o.prototype.localResponseNormalization4D = function (t, e, n, r, o) {
        Ih(t, "localResponseNormalization4D");
        var a = t.shape[3],
          i = a - 1,
          u = this.readSync(t.dataId),
          s = t.size,
          c = new Float32Array(s);

        function l(t) {
          for (var n = t % a, r = t - n + Math.max(0, n - e), o = t - n + Math.min(n + e, i), s = 0; r <= o; r++) {
            var c = u[r];
            s += c * c;
          }

          return s;
        }

        for (var h = 0; h < s; h++) {
          var f = l(h),
            p = u[h] * Math.pow(n + r * f, -o);
          c[h] = p;
        }

        return Fn(c, t.shape);
      }, o.prototype.LRNGrad = function (t, e, n, r, o, a, i) {
        Ih(t, "LRNGrad");

        for (var u = t.shape[3], s = this.readSync(t.dataId), c = this.readSync(e.dataId), l = this.readSync(n.dataId), h = new Float32Array(t.size), f = t.size, p = 0; p < f; p++) {
          for (var d = p % u, v = p - d + Math.max(0, d - r), m = p - d + Math.min(u, d + r + 1), g = 0, y = v; y < m; y++) g += Math.pow(c[y], 2);

          g = a * g + o;

          for (y = v; y < m; y++) {
            var x = -2 * a * i * c[y] * l[p] / g;
            p === y && (x += Math.pow(g, -i)), x *= s[p], h[y] += x;
          }
        }

        return Fn(h, t.shape);
      }, o.prototype.multinomial = function (t, e, n, r) {
        Ih(t, "multinomial");

        for (var o = e ? t : io(t), a = o.shape[0], i = o.shape[1], u = Pn([a, n], "int32"), s = this.readSync(u.dataId), c = this.readSync(o.dataId), l = 0; l < a; ++l) {
          var h = l * i,
            f = new Float32Array(i - 1);
          f[0] = c[h];

          for (var p = 1; p < f.length; ++p) f[p] = f[p - 1] + c[h + p];

          for (var d = rr(r.toString()), v = l * n, m = 0; m < n; ++m) {
            var g = d();
            s[v + m] = f.length;

            for (var y = 0; y < f.length; y++) if (g < f[y]) {
              s[v + m] = y;
              break;
            }
          }
        }

        return u;
      }, o.prototype.oneHot = function (t, e, n, r) {
        Ih(t, "oneHot");
        var o = new Float32Array(t.size * e);
        o.fill(r);

        for (var a = this.readSync(t.dataId), i = 0; i < t.size; ++i) a[i] >= 0 && a[i] < e && (o[i * e + a[i]] = n);

        return Tn(o, [t.size, e], "int32");
      }, o.prototype.nonMaxSuppression = function (t, e, n, r, o) {
        return Ih(t, "nonMaxSuppression"), Mo(this.readSync(t.dataId), this.readSync(e.dataId), n, r, o);
      }, o.prototype.fft = function (t) {
        return this.fftBatch(t, !1);
      }, o.prototype.ifft = function (t) {
        return this.fftBatch(t, !0);
      }, o.prototype.fftBatch = function (t, e) {
        for (var n = t.shape[0], r = t.shape[1], o = ur(t.shape, "float32"), a = ur(t.shape, "float32"), i = Rn(t).as2D(n, r), u = In(t).as2D(n, r), s = 0; s < n; s++) for (var c = i.slice([s, 0], [1, r]), l = u.slice([s, 0], [1, r]), h = En(c, l), f = this.readSync(this.fftImpl(h, e).dataId), p = 0; p < r; p++) {
          var d = Fo(f, p);
          o.values[s * r + p] = d.real, a.values[s * r + p] = d.imag;
        }

        return En(o.toTensor(), a.toTensor()).as2D(n, r);
      }, o.prototype.fftImpl = function (t, e) {
        var n = t.as1D(),
          r = n.size;

        if (this.isExponentOf2(r)) {
          var o = this.fftRadix2(n, r, e).as2D(t.shape[0], t.shape[1]);
          return e && (o = En(Rn(o).div(An(r)), In(o).div(An(r)))), o;
        }

        var a = this.readSync(t.dataId),
          i = function (t) {
            for (var e = new Float32Array(t.length / 2), n = new Float32Array(t.length / 2), r = 0; r < t.length; r += 2) e[r / 2] = t[r], n[r / 2] = t[r + 1];

            return {
              real: e,
              imag: n
            };
          }(this.fourierTransformByMatmul(a, r, e));

        return En(i.real, i.imag).as2D(t.shape[0], t.shape[1]);
      }, o.prototype.isExponentOf2 = function (t) {
        return 0 == (t & t - 1);
      }, o.prototype.fftRadix2 = function (t, e, n) {
        if (1 === e) return t;

        var r = this.readSync(t.dataId),
          o = e / 2,
          a = function (t) {
            for (var e = Math.ceil(t.length / 4), n = new Float32Array(e), r = new Float32Array(e), o = 0; o < t.length; o += 4) n[Math.floor(o / 4)] = t[o], r[Math.floor(o / 4)] = t[o + 1];

            return {
              real: n,
              imag: r
            };
          }(r),
          i = En(a.real, a.imag).as1D(),
          u = function (t) {
            for (var e = Math.floor(t.length / 4), n = new Float32Array(e), r = new Float32Array(e), o = 2; o < t.length; o += 4) n[Math.floor(o / 4)] = t[o], r[Math.floor(o / 4)] = t[o + 1];

            return {
              real: n,
              imag: r
            };
          }(r),
          s = En(u.real, u.imag).as1D();

        i = this.fftRadix2(i, o, n), s = this.fftRadix2(s, o, n);

        var c = function (t, e) {
          for (var n = new Float32Array(t / 2), r = new Float32Array(t / 2), o = 0; o < Math.ceil(t / 2); o++) {
            var a = (e ? 2 : -2) * Math.PI * (o / t);
            n[o] = Math.cos(a), r[o] = Math.sin(a);
          }

          return {
            real: n,
            imag: r
          };
        }(e, n),
          l = En(c.real, c.imag).mul(s),
          h = i.add(l),
          f = i.sub(l),
          p = Rn(h).concat(Rn(f)),
          d = In(h).concat(In(f));

        return En(p, d).as1D();
      }, o.prototype.fourierTransformByMatmul = function (t, e, n) {
        for (var r = new Float32Array(2 * e), o = 0; o < e; o++) {
          for (var a = 0, i = 0, u = 0; u < e; u++) {
            var s = _o(o * u, e, n),
              c = Fo(t, u);

            a += c.real * s.real - c.imag * s.imag, i += c.real * s.imag + c.imag * s.real;
          }

          n && (a /= e, i /= e), Oo(r, a, i, o);
        }

        return r;
      }, o.prototype.depthToSpace = function (t, e, n) {
        g("NHWC" === n, function () {
          return "Only NHWC dataFormat supported on CPU for depthToSpace. Got " + n;
        }), g(e > 1, function () {
          return "blockSize should be > 1 for depthToSpace, but was: " + e;
        });

        for (var r = t.shape[0], o = t.shape[1], a = t.shape[2], i = t.shape[3], u = o * e, s = a * e, c = i / (e * e), l = this.readSync(t.dataId), h = new Float32Array(r * u * s * c), f = 0, p = 0; p < r; ++p) for (var d = 0; d < u; ++d) for (var v = Math.floor(d / e), m = d % e, y = 0; y < s; ++y) for (var x = Math.floor(y / e), b = (m * e + y % e) * c, w = 0; w < c; ++w) {
          var C = w + b + i * (x + a * (v + o * p));
          h[f++] = l[C];
        }

        return Fn(h, [r, u, s, c]);
      }, o.prototype.broadcastedBinaryOp = function (t, e, n, r) {
        var o = po(t.shape, e.shape),
          a = ur(o, n),
          i = this.readSync(t.dataId),
          u = this.readSync(e.dataId),
          s = ho(t.shape, o),
          c = ho(e.shape, o),
          l = a.values;
        if (s.length + c.length === 0) for (var h = 0; h < l.length; ++h) l[h] = r(i[h % i.length], u[h % u.length]); else {
          var f = this.bufferSync(t),
            p = this.bufferSync(e),
            d = function (n) {
              var o = a.indexToLoc(n),
                h = o.slice(-t.rank);
              s.forEach(function (t) {
                return h[t] = 0;
              });
              var d = f.locToIndex(h),
                v = o.slice(-e.rank);
              c.forEach(function (t) {
                return v[t] = 0;
              });
              var m = p.locToIndex(v);
              l[n] = r(i[d], u[m]);
            };

          for (h = 0; h < l.length; ++h) d(h);
        }
        return a.toTensor();
      }, o.prototype.broadcastedBinaryComplexOp = function (t, e, n) {
        var r = po(t.shape, e.shape),
          o = ur(r, "float32"),
          a = ur(r, "float32"),
          i = this.readSync(t.dataId),
          u = this.readSync(e.dataId),
          s = ho(t.shape, r),
          c = ho(e.shape, r),
          l = o.values,
          h = a.values;
        if (s.length + c.length === 0) for (var f = 0; f < l.length; f++) {
          var p = f % i.length,
            d = f % u.length,
            v = n(i[2 * p], i[2 * p + 1], u[2 * d], u[2 * d + 1]);
          l[f] = v.real, h[f] = v.imag;
        } else {
          var m = this.bufferSync(this.data.get(t.dataId).complexTensors.real),
            g = this.bufferSync(this.data.get(e.dataId).complexTensors.real),
            y = function (r) {
              var a = o.indexToLoc(r),
                f = a.slice(-t.rank);
              s.forEach(function (t) {
                return f[t] = 0;
              });
              var p = m.locToIndex(f),
                d = a.slice(-e.rank);
              c.forEach(function (t) {
                return d[t] = 0;
              });
              var v = g.locToIndex(d),
                y = n(i[2 * p], i[2 * p + 1], u[2 * v], u[2 * v + 1]);
              l[r] = y.real, h[r] = y.imag;
            };

          for (f = 0; f < l.length; f++) y(f);
        }
        return this.complex(o.toTensor(), a.toTensor());
      }, o.prototype.split = function (t, e, n) {
        return Po(t, e, n);
      }, o.prototype.dispose = function () { }, o.prototype.floatPrecision = function () {
        return 32;
      }, o.prototype.epsilon = function () {
        return 1e-7;
      }, o.prototype.cropAndResize = function (t, e, n, r, o, a) {
        for (var i = t.shape, u = i[0], s = i[1], c = i[2], l = i[3], h = e.shape[0], f = r[0], p = r[1], d = ur([h, f, p, l], t.dtype), v = this.readSync(e.dataId), m = this.readSync(n.dataId), g = this.readSync(t.dataId), y = t.strides, x = d.strides, b = 0; b < h; b++) {
          var w = 4 * b,
            C = v[w],
            E = v[w + 1],
            R = v[w + 2],
            I = v[w + 3],
            k = m[b];
          if (!(k >= u)) for (var S = f > 1 ? (R - C) * (s - 1) / (f - 1) : 0, A = p > 1 ? (I - E) * (c - 1) / (p - 1) : 0, D = 0; D < f; D++) {
            var T = f > 1 ? C * (s - 1) + D * S : .5 * (C + R) * (s - 1);
            if (T < 0 || T > s - 1) for (var N = 0; N < p; N++) for (var F = 0; F < l; F++) {
              var O = F + N * x[2] + D * x[1] + b * x[0];
              d.values[O] = a;
            } else if ("bilinear" === o) {
              var _ = Math.floor(T),
                M = Math.ceil(T),
                B = T - _;

              for (N = 0; N < p; N++) {
                if ((q = p > 1 ? E * (c - 1) + N * A : .5 * (E + I) * (c - 1)) < 0 || q > c - 1) for (F = 0; F < l; F++) {
                  O = F + N * x[2] + D * x[1] + b * x[0];
                  d.values[O] = a;
                } else {
                  var P = Math.floor(q),
                    L = Math.ceil(q),
                    W = q - P;

                  for (F = 0; F < l; F++) {
                    var U = g[O = F + P * y[2] + _ * y[1] + k * y[0]],
                      V = g[O = F + L * y[2] + _ * y[1] + k * y[0]],
                      z = g[O = F + P * y[2] + M * y[1] + k * y[0]],
                      G = U + (V - U) * W,
                      H = z + (g[O = F + L * y[2] + M * y[1] + k * y[0]] - z) * W;
                    O = F + N * x[2] + D * x[1] + b * x[0], d.values[O] = G + (H - G) * B;
                  }
                }
              }
            } else for (N = 0; N < p; ++N) {
              var q;
              if ((q = p > 1 ? E * (c - 1) + N * A : .5 * (E + I) * (c - 1)) < 0 || q > c - 1) for (F = 0; F < l; F++) {
                O = F + N * x[2] + D * x[1] + b * x[0];
                d.values[O] = a;
              } else {
                var K = Math.round(q),
                  j = Math.round(T);

                for (F = 0; F < l; F++) {
                  var X = F + K * y[2] + j * y[1] + k * y[0],
                    $ = F + N * x[2] + D * x[1] + b * x[0];
                  d.values[$] = g[X];
                }
              }
            }
          }
        }

        return d.toTensor();
      }, o.prototype.sparseToDense = function (t, e, n, r) {
        var o = Hr(0, t, n),
          a = o.sliceRank,
          i = o.numUpdates,
          u = o.sliceSize,
          s = o.strides,
          c = o.outputSize;
        return this.scatter(t, e, n, c, u, i, a, s, r, !1);
      }, o.prototype.gatherND = function (t, e) {
        var n = e.shape,
          r = n[n.length - 1],
          o = Ur(t, e),
          a = o[0],
          i = o[1],
          u = o[2],
          s = o[3];
        if (0 === i) return kn([], a, t.dtype);

        for (var c = new lt([i, u], t.dtype), l = this.readSync(e.dataId), h = this.readSync(t.dataId), f = 0; f < i; f++) {
          for (var p = [], d = 0, v = 0; v < r; v++) {
            var m = l[f * r + v];
            d += m * s[v], p.push(m);
          }

          if (d < 0 || d >= t.size / u) throw new Error("Invalid indices: " + p + " does not index into " + t.shape);

          for (var g = 0; g < u; g++) c.values[f * u + g] = h[d * u + g];
        }

        return c.toTensor().reshape(a);
      }, o.prototype.scatterND = function (t, e, n) {
        var r = Hr(0, t, n),
          o = r.sliceRank,
          a = r.numUpdates,
          i = r.sliceSize,
          u = r.strides,
          s = r.outputSize,
          c = An(0);
        return this.scatter(t, e, n, s, i, a, o, u, c, !0);
      }, o.prototype.fill = function (t, e, n) {
        var r = F(n = n || z(e), w(t));
        return r.fill(e), Nt.makeTensor(r, t, n, this);
      }, o.prototype.onesLike = function (t) {
        if ("string" === t.dtype) throw new Error("onesLike is not supported for string tensors");
        return this.fill(t.shape, 1, t.dtype);
      }, o.prototype.zerosLike = function (t) {
        var e = F(t.dtype, w(t.shape));
        return this.makeOutput(e, t.shape, t.dtype);
      }, o.prototype.linspace = function (t, e, n) {
        return Do(t, e, n);
      }, o.prototype.scatter = function (t, e, n, r, o, a, i, u, s, c) {
        var l = [r / o, o],
          h = this.readSync(t.dataId),
          f = this.readSync(e.dataId);
        if (0 === r) return kn([], n, e.dtype);
        var p = new lt(l, e.dtype);
        p.values.fill(this.readSync(s.dataId)[0]);

        for (var d = 0; d < a; d++) {
          for (var v = [], m = 0, g = 0; g < i; g++) {
            var y = h[d * i + g];
            v.push(y), m += y * u[g];
          }

          if (m < 0 || m >= r / o) throw new Error("Invalid indices: " + v + " does not index into " + n);

          for (var x = 0; x < o; x++) c ? p.values[m * o + x] += f[d * o + x] : p.values[m * o + x] = 0 === e.rank ? f[0] : f[d * o + x];
        }

        return p.toTensor().reshape(n);
      }, o;
    }(co);

    Nt.registerBackend("cpu", function () {
      return new Sh();
    }, 1), l({
      kernelName: "Square",
      backendName: "cpu",
      kernelFunc: function (t) {
        var e = t.inputs,
          n = t.backend,
          r = e.x,
          o = n;
        Ih(r, "square");

        for (var a = o.data.get(r.dataId).values, i = new Float32Array(a.length), u = 0; u < a.length; ++u) {
          var s = a[u];
          i[u] = s * s;
        }

        return {
          dataId: o.write(i, r.shape, r.dtype),
          shape: r.shape,
          dtype: r.dtype
        };
      }
    }), l({
      kernelName: "Square",
      backendName: "webgl",
      kernelFunc: function (t) {
        var e = t.inputs,
          n = t.backend,
          r = e.x,
          o = n,
          a = new su(r.shape, "return x * x;");
        return o.runWebGLProgram(a, [r], r.dtype);
      }
    });

    var Ah = function () {
      function t() { }

      return t.prototype.fetch = function (t, e) {
        return fetch(t, e);
      }, t.prototype.now = function () {
        return performance.now();
      }, t.prototype.encode = function (t, e) {
        if ("utf-8" !== e && "utf8" !== e) throw new Error("Browser's encoder only supports utf-8, but got " + e);
        return null == this.textEncoder && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t);
      }, t.prototype.decode = function (t, e) {
        return new TextDecoder(e).decode(t);
      }, t;
    }();

    a().get("IS_BROWSER") && a().setPlatform("browser", new Ah());

    var Dh,
      Th = function () {
        return require("node-fetch");
      },
      Nh = function () {
        function t() {
          this.util = require("util"), this.textEncoder = new this.util.TextEncoder();
        }

        return t.prototype.fetch = function (t, e) {
          return null != a().global.fetch ? a().global.fetch(t, e) : (null == Dh && (Dh = Th()), Dh(t, e));
        }, t.prototype.now = function () {
          var t = process.hrtime();
          return 1e3 * t[0] + t[1] / 1e6;
        }, t.prototype.encode = function (t, e) {
          if ("utf-8" !== e && "utf8" !== e) throw new Error("Node built-in encoder only supports utf-8, but got " + e);
          return this.textEncoder.encode(t);
        }, t.prototype.decode = function (t, e) {
          return 0 === t.length ? "" : new this.util.TextDecoder(e).decode(t);
        }, t;
      }();

    a().get("IS_NODE") && a().setPlatform("node", new Nh());
    var Fh = {
      float32: 4,
      int32: 4,
      uint16: 2,
      uint8: 1,
      bool: 1
    },
      Oh = 4;

    function _h(t, e) {
      for (var n = {}, r = 0, o = function (e) {
        var o = e.name,
          a = e.dtype,
          i = e.shape,
          u = w(i),
          s = void 0;

        if (("quantization" in e)) {
          var c = e.quantization;
          if ("uint8" !== c.dtype && "uint16" !== c.dtype) throw new Error("Weight " + e.name + " has unknown quantization dtype " + c.dtype + ". Supported quantization dtypes are: 'uint8' and 'uint16'.");
          var l = Fh[c.dtype],
            h = t.slice(r, r + u * l),
            f = "uint8" === c.dtype ? new Uint8Array(h) : new Uint16Array(h);
          if ("float32" === a) s = Float32Array.from(f, function (t) {
            return t * c.scale + c.min;
          }); else {
            if ("int32" !== a) throw new Error("Unsupported dtype in weight '" + o + "': " + a);
            s = Int32Array.from(f, function (t) {
              return Math.round(t * c.scale + c.min);
            });
          }
          r += u * l;
        } else if ("string" === a) {
          var p = w(e.shape);
          s = [];

          for (var d = 0; d < p; d++) {
            var v = new Uint32Array(t.slice(r, r + Oh))[0];
            r += Oh;
            var m = new Uint8Array(t.slice(r, r + v));
            s.push(m), r += v;
          }
        } else {
          var g = Fh[a];
          h = t.slice(r, r + u * g);
          if ("float32" === a) s = new Float32Array(h); else if ("int32" === a) s = new Int32Array(h); else {
            if ("bool" !== a) throw new Error("Unsupported dtype in weight '" + o + "': " + a);
            s = new Uint8Array(h);
          }
          r += u * g;
        }

        n[o] = kn(s, i, a);
      }, a = 0, i = e; a < i.length; a++) {
        o(i[a]);
      }

      return n;
    }

    function Mh(t) {
      if (null === t) throw new Error("Invalid input value: " + JSON.stringify(t));
      var e = 0,
        n = [];
      t.forEach(function (t) {
        if (e += t.byteLength, n.push(t.byteLength === t.buffer.byteLength ? t : new t.constructor(t)), !(t instanceof Float32Array || t instanceof Int32Array || t instanceof Uint8Array)) throw new Error("Unsupported TypedArray subtype: " + t.constructor.name);
      });
      var r = new Uint8Array(e),
        o = 0;
      return n.forEach(function (t) {
        r.set(new Uint8Array(t.buffer), o), o += t.byteLength;
      }), r.buffer;
    }

    var Bh = "undefined" != typeof Buffer && ("undefined" == typeof Blob || "undefined" == typeof atob || "undefined" == typeof btoa);

    function Ph(t) {
      return Bh ? Buffer.byteLength(t) : new Blob([t]).size;
    }

    function Lh(t) {
      var e = 0;
      t.forEach(function (t) {
        e += t.byteLength;
      });
      var n = new Uint8Array(e),
        r = 0;
      return t.forEach(function (t) {
        n.set(new Uint8Array(t), r), r += t.byteLength;
      }), n.buffer;
    }

    function Wh(t) {
      for (t = t.trim(); t.endsWith("/");) t = t.slice(0, t.length - 1);

      var e = t.split("/");
      return e[e.length - 1];
    }

    function Uh(t) {
      if (t.modelTopology instanceof ArrayBuffer) throw new Error("Expected JSON model topology, received ArrayBuffer.");
      return {
        dateSaved: new Date(),
        modelTopologyType: "JSON",
        modelTopologyBytes: null == t.modelTopology ? 0 : Ph(JSON.stringify(t.modelTopology)),
        weightSpecsBytes: null == t.weightSpecs ? 0 : Ph(JSON.stringify(t.weightSpecs)),
        weightDataBytes: null == t.weightData ? 0 : t.weightData.byteLength
      };
    }

    var Vh = function () {
      function t() {
        this.saveRouters = [], this.loadRouters = [];
      }

      return t.getInstance = function () {
        return null == t.instance && (t.instance = new t()), t.instance;
      }, t.registerSaveRouter = function (e) {
        t.getInstance().saveRouters.push(e);
      }, t.registerLoadRouter = function (e) {
        t.getInstance().loadRouters.push(e);
      }, t.getSaveHandlers = function (e) {
        return t.getHandlers(e, "save");
      }, t.getLoadHandlers = function (e, n) {
        return t.getHandlers(e, "load", n);
      }, t.getHandlers = function (e, n, r) {
        var o = [];
        return ("load" === n ? t.getInstance().loadRouters : t.getInstance().saveRouters).forEach(function (t) {
          var n = t(e, r);
          null !== n && o.push(n);
        }), o;
      }, t;
    }(),
      zh = "://",
      Gh = function () {
        function t() {
          this.managers = {};
        }

        return t.getInstance = function () {
          return null == t.instance && (t.instance = new t()), t.instance;
        }, t.registerManager = function (e, n) {
          g(null != e, function () {
            return "scheme must not be undefined or null.";
          }), e.endsWith(zh) && (e = e.slice(0, e.indexOf(zh))), g(e.length > 0, function () {
            return "scheme must not be an empty string.";
          });
          var r = t.getInstance();
          g(null == r.managers[e], function () {
            return "A model store manager is already registered for scheme '" + e + "'.";
          }), r.managers[e] = n;
        }, t.getManager = function (t) {
          var e = this.getInstance().managers[t];
          if (null == e) throw new Error("Cannot find model manager for scheme '" + t + "'");
          return e;
        }, t.getSchemes = function () {
          return Object.keys(this.getInstance().managers);
        }, t;
      }();

    function Hh(t) {
      if (-1 === t.indexOf(zh)) throw new Error("The url string provided does not contain a scheme. Supported schemes are: " + Gh.getSchemes().join(","));
      return {
        scheme: t.split(zh)[0],
        path: t.split(zh)[1]
      };
    }

    function qh(t, e, o) {
      return void 0 === o && (o = !1), n(this, void 0, void 0, function () {
        var n, a, i, u, s, c, l, h, f;
        return r(this, function (r) {
          switch (r.label) {
            case 0:
              return g(t !== e, function () {
                return "Old path and new path are the same: '" + t + "'";
              }), g((n = Vh.getLoadHandlers(t)).length > 0, function () {
                return "Copying failed because no load handler is found for source URL " + t + ".";
              }), g(n.length < 2, function () {
                return "Copying failed because more than one (" + n.length + ") load handlers for source URL " + t + ".";
              }), a = n[0], g((i = Vh.getSaveHandlers(e)).length > 0, function () {
                return "Copying failed because no save handler is found for destination URL " + e + ".";
              }), g(i.length < 2, function () {
                return "Copying failed because more than one (" + n.length + ") save handlers for destination URL " + e + ".";
              }), u = i[0], s = Hh(t).scheme, c = Hh(t).path, l = s === Hh(t).scheme, [4, a.load()];

            case 1:
              return h = r.sent(), o && l ? [4, Gh.getManager(s).removeModel(c)] : [3, 3];

            case 2:
              r.sent(), r.label = 3;

            case 3:
              return [4, u.save(h)];

            case 4:
              return f = r.sent(), !o || l ? [3, 6] : [4, Gh.getManager(s).removeModel(c)];

            case 5:
              r.sent(), r.label = 6;

            case 6:
              return [2, f.modelArtifactsInfo];
          }
        });
      });
    }

    var Kh = "models_store",
      jh = "model_info_store";

    function Xh() {
      if (!a().getBool("IS_BROWSER")) throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
      var t = window,
        e = t.indexedDB || t.mozIndexedDB || t.webkitIndexedDB || t.msIndexedDB || t.shimIndexedDB;
      if (null == e) throw new Error("The current browser does not appear to support IndexedDB.");
      return e;
    }

    function $h(t) {
      var e = t.result;
      e.createObjectStore(Kh, {
        keyPath: "modelPath"
      }), e.createObjectStore(jh, {
        keyPath: "modelPath"
      });
    }

    var Yh = function () {
      function t(t) {
        if (this.indexedDB = Xh(), null == t || !t) throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
        this.modelPath = t;
      }

      return t.prototype.save = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (e) {
            if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
            return [2, this.databaseAction(this.modelPath, t)];
          });
        });
      }, t.prototype.load = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            return [2, this.databaseAction(this.modelPath)];
          });
        });
      }, t.prototype.databaseAction = function (t, e) {
        var n = this;
        return new Promise(function (t, r) {
          var o = n.indexedDB.open("tensorflowjs", 1);
          o.onupgradeneeded = function () {
            return $h(o);
          }, o.onsuccess = function () {
            var a = o.result;

            if (null == e) {
              var i = a.transaction(Kh, "readonly"),
                u = i.objectStore(Kh).get(n.modelPath);
              u.onsuccess = function () {
                if (null == u.result) return a.close(), r(new Error("Cannot find model with path '" + n.modelPath + "' in IndexedDB."));
                t(u.result.modelArtifacts);
              }, u.onerror = function (t) {
                return a.close(), r(u.error);
              }, i.oncomplete = function () {
                return a.close();
              };
            } else {
              var s,
                c = Uh(e),
                l = a.transaction(jh, "readwrite"),
                h = l.objectStore(jh),
                f = h.put({
                  modelPath: n.modelPath,
                  modelArtifactsInfo: c
                });
              f.onsuccess = function () {
                var o = (s = a.transaction(Kh, "readwrite")).objectStore(Kh).put({
                  modelPath: n.modelPath,
                  modelArtifacts: e,
                  modelArtifactsInfo: c
                });
                o.onsuccess = function () {
                  return t({
                    modelArtifactsInfo: c
                  });
                }, o.onerror = function (t) {
                  var e = (h = l.objectStore(jh)).delete(n.modelPath);
                  e.onsuccess = function () {
                    return a.close(), r(o.error);
                  }, e.onerror = function (t) {
                    return a.close(), r(o.error);
                  };
                };
              }, f.onerror = function (t) {
                return a.close(), r(f.error);
              }, l.oncomplete = function () {
                null == s ? a.close() : s.oncomplete = function () {
                  return a.close();
                };
              };
            }
          }, o.onerror = function (t) {
            return r(o.error);
          };
        });
      }, t.URL_SCHEME = "indexeddb://", t;
    }(),
      Qh = function (t) {
        return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(Yh.URL_SCHEME) ? (e = t.slice(Yh.URL_SCHEME.length), new Yh(e)) : null;
        var e;
      };

    Vh.registerSaveRouter(Qh), Vh.registerLoadRouter(Qh);

    var Jh = function () {
      function t() {
        this.indexedDB = Xh();
      }

      return t.prototype.listModels = function () {
        return n(this, void 0, void 0, function () {
          var t = this;
          return r(this, function (e) {
            return [2, new Promise(function (e, n) {
              var r = t.indexedDB.open("tensorflowjs", 1);
              r.onupgradeneeded = function () {
                return $h(r);
              }, r.onsuccess = function () {
                var t = r.result,
                  o = t.transaction(jh, "readonly"),
                  a = o.objectStore(jh).getAll();
                a.onsuccess = function () {
                  for (var t = {}, n = 0, r = a.result; n < r.length; n++) {
                    var o = r[n];
                    t[o.modelPath] = o.modelArtifactsInfo;
                  }

                  e(t);
                }, a.onerror = function (e) {
                  return t.close(), n(a.error);
                }, o.oncomplete = function () {
                  return t.close();
                };
              }, r.onerror = function (t) {
                return n(r.error);
              };
            })];
          });
        });
      }, t.prototype.removeModel = function (t) {
        return n(this, void 0, void 0, function () {
          var e = this;
          return r(this, function (n) {
            var r;
            return t = (r = t).startsWith(Yh.URL_SCHEME) ? r.slice(Yh.URL_SCHEME.length) : r, [2, new Promise(function (n, r) {
              var o = e.indexedDB.open("tensorflowjs", 1);
              o.onupgradeneeded = function () {
                return $h(o);
              }, o.onsuccess = function () {
                var e,
                  a = o.result,
                  i = a.transaction(jh, "readwrite"),
                  u = i.objectStore(jh),
                  s = u.get(t);
                s.onsuccess = function () {
                  if (null == s.result) return a.close(), r(new Error("Cannot find model with path '" + t + "' in IndexedDB."));

                  var o = u.delete(t),
                    i = function () {
                      var o = (e = a.transaction(Kh, "readwrite")).objectStore(Kh).delete(t);
                      o.onsuccess = function () {
                        return n(s.result.modelArtifactsInfo);
                      }, o.onerror = function (t) {
                        return r(s.error);
                      };
                    };

                  o.onsuccess = i, o.onerror = function (t) {
                    return i(), a.close(), r(s.error);
                  };
                }, s.onerror = function (t) {
                  return a.close(), r(s.error);
                }, i.oncomplete = function () {
                  null == e ? a.close() : e.oncomplete = function () {
                    return a.close();
                  };
                };
              }, o.onerror = function (t) {
                return r(o.error);
              };
            })];
          });
        });
      }, t;
    }();

    if (a().getBool("IS_BROWSER")) try {
      Gh.registerManager(Yh.URL_SCHEME, new Jh());
    } catch (t) { }
    var Zh = "/",
      tf = "tensorflowjs_models",
      ef = "info",
      nf = "model_topology",
      rf = "weight_specs",
      of = "weight_data",
      af = "model_metadata";

    function uf(t) {
      return {
        info: [tf, t, ef].join(Zh),
        topology: [tf, t, nf].join(Zh),
        weightSpecs: [tf, t, rf].join(Zh),
        weightData: [tf, t, of].join(Zh),
        modelMetadata: [tf, t, af].join(Zh)
      };
    }

    function sf(t) {
      var e = t.split(Zh);
      if (e.length < 3) throw new Error("Invalid key format: " + t);
      return e.slice(1, e.length - 1).join(Zh);
    }

    var cf = function () {
      function t(t) {
        if (!a().getBool("IS_BROWSER") || void 0 === window.localStorage) throw new Error("The current environment does not support local storage.");
        if (this.LS = window.localStorage, null == t || !t) throw new Error("For local storage, modelPath must not be null, undefined or empty.");
        this.modelPath = t, this.keys = uf(this.modelPath);
      }

      return t.prototype.save = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o;
          return r(this, function (r) {
            if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
            e = JSON.stringify(t.modelTopology), n = JSON.stringify(t.weightSpecs), o = Uh(t);

            try {
              return this.LS.setItem(this.keys.info, JSON.stringify(o)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, n), this.LS.setItem(this.keys.weightData, (a = t.weightData, Bh ? Buffer.from(a).toString("base64") : btoa(String.fromCharCode.apply(null, new Uint8Array(a))))), this.LS.setItem(this.keys.modelMetadata, JSON.stringify({
                format: t.format,
                generatedBy: t.generatedBy,
                convertedBy: t.convertedBy
              })), [2, {
                modelArtifactsInfo: o
              }];
            } catch (t) {
              throw this.LS.removeItem(this.keys.info), this.LS.removeItem(this.keys.topology), this.LS.removeItem(this.keys.weightSpecs), this.LS.removeItem(this.keys.weightData), this.LS.removeItem(this.keys.modelMetadata), new Error("Failed to save model '" + this.modelPath + "' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=" + o.modelTopologyBytes + ", weightSpecsBytes=" + o.weightSpecsBytes + ", weightDataBytes=" + o.weightDataBytes + ".");
            }

            var a;
            return [2];
          });
        });
      }, t.prototype.load = function () {
        return n(this, void 0, void 0, function () {
          var t, e, n, o, a, i, u;
          return r(this, function (r) {
            if (null == (t = JSON.parse(this.LS.getItem(this.keys.info)))) throw new Error("In local storage, there is no model with name '" + this.modelPath + "'");
            if ("JSON" !== t.modelTopologyType) throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
            if (e = {}, null == (n = JSON.parse(this.LS.getItem(this.keys.topology)))) throw new Error("In local storage, the topology of model '" + this.modelPath + "' is missing.");
            if (e.modelTopology = n, null == (o = JSON.parse(this.LS.getItem(this.keys.weightSpecs)))) throw new Error("In local storage, the weight specs of model '" + this.modelPath + "' are missing.");
            if (e.weightSpecs = o, null != (a = this.LS.getItem(this.keys.modelMetadata)) && (i = JSON.parse(a), e.format = i.format, e.generatedBy = i.generatedBy, e.convertedBy = i.convertedBy), null == (u = this.LS.getItem(this.keys.weightData))) throw new Error("In local storage, the binary weight values of model '" + this.modelPath + "' are missing.");
            return e.weightData = function (t) {
              if (Bh) {
                var e = Buffer.from(t, "base64");
                return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
              }

              for (var n = atob(t), r = new Uint8Array(n.length), o = 0; o < n.length; ++o) r.set([n.charCodeAt(o)], o);

              return r.buffer;
            }(u), [2, e];
          });
        });
      }, t.URL_SCHEME = "localstorage://", t;
    }(),
      lf = function (t) {
        return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(cf.URL_SCHEME) ? (e = t.slice(cf.URL_SCHEME.length), new cf(e)) : null;
        var e;
      };

    Vh.registerSaveRouter(lf), Vh.registerLoadRouter(lf);

    var hf = function () {
      function t() {
        g(a().getBool("IS_BROWSER"), function () {
          return "Current environment is not a web browser";
        }), g(void 0 !== window.localStorage, function () {
          return "Current browser does not appear to support localStorage";
        }), this.LS = window.localStorage;
      }

      return t.prototype.listModels = function () {
        return n(this, void 0, void 0, function () {
          var t, e, n, o, a, i;
          return r(this, function (r) {
            for (t = {}, e = tf + Zh, n = Zh + ef, o = 0; o < this.LS.length; ++o) (a = this.LS.key(o)).startsWith(e) && a.endsWith(n) && (i = sf(a), t[i] = JSON.parse(this.LS.getItem(a)));

            return [2, t];
          });
        });
      }, t.prototype.removeModel = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n;
          return r(this, function (r) {
            var o;
            if (t = (o = t).startsWith(cf.URL_SCHEME) ? o.slice(cf.URL_SCHEME.length) : o, e = uf(t), null == this.LS.getItem(e.info)) throw new Error("Cannot find model at path '" + t + "'");
            return n = JSON.parse(this.LS.getItem(e.info)), this.LS.removeItem(e.info), this.LS.removeItem(e.topology), this.LS.removeItem(e.weightSpecs), this.LS.removeItem(e.weightData), [2, n];
          });
        });
      }, t;
    }();

    if (a().getBool("IS_BROWSER")) try {
      Gh.registerManager(cf.URL_SCHEME, new hf());
    } catch (t) { }
    var ff = "model",
      pf = ".json",
      df = ".weights.bin";

    function vf(t) {
      return new Promise(function (t) {
        return setTimeout(t);
      }).then(t);
    }

    var mf = function () {
      function t(e) {
        if (!a().getBool("IS_BROWSER")) throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
        e.startsWith(t.URL_SCHEME) && (e = e.slice(t.URL_SCHEME.length)), null != e && 0 !== e.length || (e = ff), this.modelTopologyFileName = e + pf, this.weightDataFileName = e + df;
      }

      return t.prototype.save = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o, a, i, u;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                if ("undefined" == typeof document) throw new Error("Browser downloads are not supported in this environment since `document` is not present");
                if (e = window.URL.createObjectURL(new Blob([t.weightData], {
                  type: "application/octet-stream"
                })), !(t.modelTopology instanceof ArrayBuffer)) return [3, 1];
                throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");

              case 1:
                return n = [{
                  paths: ["./" + this.weightDataFileName],
                  weights: t.weightSpecs
                }], o = {
                  modelTopology: t.modelTopology,
                  format: t.format,
                  generatedBy: t.generatedBy,
                  convertedBy: t.convertedBy,
                  weightsManifest: n
                }, a = window.URL.createObjectURL(new Blob([JSON.stringify(o)], {
                  type: "application/json"
                })), (i = null == this.jsonAnchor ? document.createElement("a") : this.jsonAnchor).download = this.modelTopologyFileName, i.href = a, [4, vf(function () {
                  return i.dispatchEvent(new MouseEvent("click"));
                })];

              case 2:
                return r.sent(), null == t.weightData ? [3, 4] : ((u = null == this.weightDataAnchor ? document.createElement("a") : this.weightDataAnchor).download = this.weightDataFileName, u.href = e, [4, vf(function () {
                  return u.dispatchEvent(new MouseEvent("click"));
                })]);

              case 3:
                r.sent(), r.label = 4;

              case 4:
                return [2, {
                  modelArtifactsInfo: Uh(t)
                }];
            }
          });
        });
      }, t.URL_SCHEME = "downloads://", t;
    }(),
      gf = function () {
        function t(t) {
          if (null == t || t.length < 1) throw new Error("When calling browserFiles, at least 1 file is required, but received " + t);
          this.files = t;
        }

        return t.prototype.load = function () {
          return n(this, void 0, void 0, function () {
            var t,
              e,
              n = this;
            return r(this, function (r) {
              return t = this.files[0], e = this.files.slice(1), [2, new Promise(function (r, o) {
                var a = new FileReader();
                a.onload = function (a) {
                  var i = JSON.parse(a.target.result),
                    u = i.modelTopology;

                  if (null != u) {
                    0 === e.length && r({
                      modelTopology: u
                    });
                    var s = i.weightsManifest;

                    if (null != s) {
                      var c;

                      try {
                        c = n.checkManifestAndWeightFiles(s, e);
                      } catch (t) {
                        return void o(t);
                      }

                      var l = [],
                        h = [],
                        f = [];
                      s.forEach(function (t) {
                        t.paths.forEach(function (t) {
                          h.push(t), f.push(null);
                        }), l.push.apply(l, t.weights);
                      }), s.forEach(function (t) {
                        t.paths.forEach(function (t) {
                          var e = new FileReader();
                          e.onload = function (e) {
                            var n = e.target.result,
                              o = h.indexOf(t);
                            f[o] = n, -1 === f.indexOf(null) && r({
                              modelTopology: u,
                              weightSpecs: l,
                              weightData: Lh(f)
                            });
                          }, e.onerror = function (e) {
                            return o("Failed to weights data from file of path '" + t + "'.");
                          }, e.readAsArrayBuffer(c[t]);
                        });
                      });
                    } else o(new Error("weightManifest field is missing from file " + t.name));
                  } else o(new Error("modelTopology field is missing from file " + t.name));
                }, a.onerror = function (e) {
                  return o("Failed to read model topology and weights manifest JSON from file '" + t.name + "'. BrowserFiles supports loading Keras-style tf.Model artifacts only.");
                }, a.readAsText(t);
              })];
            });
          });
        }, t.prototype.checkManifestAndWeightFiles = function (t, e) {
          for (var n = [], r = e.map(function (t) {
            return Wh(t.name);
          }), o = {}, a = 0, i = t; a < i.length; a++) {
            i[a].paths.forEach(function (t) {
              var a = Wh(t);
              if (-1 !== n.indexOf(a)) throw new Error("Duplicate file basename found in weights manifest: '" + a + "'");
              if (n.push(a), -1 === r.indexOf(a)) throw new Error("Weight file with basename '" + a + "' is not provided.");
              o[t] = e[r.indexOf(a)];
            });
          }

          if (n.length !== e.length) throw new Error("Mismatch in the number of files in weights manifest (" + n.length + ") and the number of weight files provided (" + e.length + ").");
          return o;
        }, t;
      }();

    function yf(t, e, n, r) {
      !function (t) {
        g(null != t && Array.isArray(t) && t.length > 0, function () {
          return "promises must be a none empty array";
        });
      }(t), function (t, e) {
        g(t >= 0 && t <= 1, function () {
          return "Progress fraction must be in range [0, 1], but got startFraction " + t;
        }), g(e >= 0 && e <= 1, function () {
          return "Progress fraction must be in range [0, 1], but got endFraction " + e;
        }), g(e >= t, function () {
          return "startFraction must be no more than endFraction, but got startFraction " + t + " and endFraction " + e;
        });
      }(n = null == n ? 0 : n, r = null == r ? 1 : r);
      var o = 0;
      return Promise.all(t.map(function (a) {
        return a.then(function (a) {
          var i = n + ++o / t.length * (r - n);
          return e(i), a;
        }), a;
      }));
    }

    function xf(t, e) {
      return n(this, void 0, void 0, function () {
        var n, o, i, u, s, c, l, h, f;
        return r(this, function (r) {
          switch (r.label) {
            case 0:
              return null == e && (e = {}), n = null == e.fetchFunc ? a().platform.fetch : e.fetchFunc, o = t.map(function (t) {
                return n(t, e.requestInit, {
                  isBinary: !0
                });
              }), i = 0, u = .5, null != e.onProgress ? [3, 2] : [4, Promise.all(o)];

            case 1:
              return s = r.sent(), [3, 4];

            case 2:
              return [4, yf(o, e.onProgress, i, u)];

            case 3:
              s = r.sent(), r.label = 4;

            case 4:
              return c = s.map(function (t) {
                return t.arrayBuffer();
              }), l = .5, h = 1, null != e.onProgress ? [3, 6] : [4, Promise.all(c)];

            case 5:
              return f = r.sent(), [3, 8];

            case 6:
              return [4, yf(c, e.onProgress, l, h)];

            case 7:
              f = r.sent(), r.label = 8;

            case 8:
              return [2, f];
          }
        });
      });
    }

    function bf(t) {
      var e = this;
      return function (o, a, i) {
        return void 0 === a && (a = ""), n(e, void 0, void 0, function () {
          var e, n, u, s, c, l, h, f, p, d;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                if (e = o.map(function () {
                  return !1;
                }), n = {}, u = null != i ? i.map(function () {
                  return !1;
                }) : [], s = [], o.forEach(function (t, r) {
                  var o = 0;
                  t.weights.forEach(function (t) {
                    var a = "quantization" in t ? t.quantization.dtype : t.dtype,
                      c = Fh[a] * w(t.shape),
                      l = function () {
                        e[r] = !0, null == n[r] && (n[r] = []), n[r].push({
                          manifestEntry: t,
                          groupOffset: o,
                          sizeBytes: c
                        });
                      };

                    null != i ? i.forEach(function (e, n) {
                      e === t.name && (l(), u[n] = !0);
                    }) : l(), s.push(t.name), o += c;
                  });
                }), !u.every(function (t) {
                  return t;
                })) throw c = i.filter(function (t, e) {
                  return !u[e];
                }), new Error("Could not find weights in manifest with names: " + c.join(", ") + ". \nManifest JSON has weights with names: " + s.join(", ") + ".");
                return l = e.reduce(function (t, e, n) {
                  return e && t.push(n), t;
                }, []), h = [], l.forEach(function (t) {
                  o[t].paths.forEach(function (t) {
                    var e = a + (a.endsWith("/") ? "" : "/") + t;
                    h.push(e);
                  });
                }), [4, t(h)];

              case 1:
                return f = r.sent(), p = {}, d = 0, l.forEach(function (t) {
                  for (var e = o[t].paths.length, r = 0, a = 0; a < e; a++) r += f[d + a].byteLength;

                  for (var i = new ArrayBuffer(r), u = new Uint8Array(i), s = 0, c = 0; c < e; c++) {
                    var l = new Uint8Array(f[d + c]);
                    u.set(l, s), s += l.byteLength;
                  }

                  n[t].forEach(function (t) {
                    var e = _h(i.slice(t.groupOffset, t.groupOffset + t.sizeBytes), [t.manifestEntry]);

                    for (var n in e) p[n] = e[n];
                  }), d += e;
                }), [2, p];
            }
          });
        });
      };
    }

    Vh.registerSaveRouter(function (t) {
      return a().getBool("IS_BROWSER") && !Array.isArray(t) && t.startsWith(mf.URL_SCHEME) ? (e = t.slice(mf.URL_SCHEME.length), void 0 === e && (e = "model"), new mf(e)) : null;
      var e;
    });

    var wf = function () {
      function t(t, e) {
        if (this.DEFAULT_METHOD = "POST", null == e && (e = {}), this.weightPathPrefix = e.weightPathPrefix, this.onProgress = e.onProgress, null != e.fetchFunc ? (g("function" == typeof e.fetchFunc, function () {
          return "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)";
        }), this.fetch = e.fetchFunc) : this.fetch = a().platform.fetch, g(null != t && t.length > 0, function () {
          return "URL path for http must not be null, undefined or empty.";
        }), Array.isArray(t) && g(2 === t.length, function () {
          return "URL paths for http must have a length of 2, (actual length is " + t.length + ").";
        }), this.path = t, null != e.requestInit && null != e.requestInit.body) throw new Error("requestInit is expected to have no pre-existing body, but has one.");
        this.requestInit = e.requestInit || {};
      }

      return t.prototype.save = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o, a;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
                return (e = Object.assign({
                  method: this.DEFAULT_METHOD
                }, this.requestInit)).body = new FormData(), n = [{
                  paths: ["./model.weights.bin"],
                  weights: t.weightSpecs
                }], o = {
                  modelTopology: t.modelTopology,
                  format: t.format,
                  generatedBy: t.generatedBy,
                  convertedBy: t.convertedBy,
                  userDefinedMetadata: t.userDefinedMetadata,
                  weightsManifest: n
                }, e.body.append("model.json", new Blob([JSON.stringify(o)], {
                  type: "application/json"
                }), "model.json"), null != t.weightData && e.body.append("model.weights.bin", new Blob([t.weightData], {
                  type: "application/octet-stream"
                }), "model.weights.bin"), [4, this.fetch(this.path, e)];

              case 1:
                if ((a = r.sent()).ok) return [2, {
                  modelArtifactsInfo: Uh(t),
                  responses: [a]
                }];
                throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status " + a.status + ".");
            }
          });
        });
      }, t.prototype.load = function () {
        return n(this, void 0, void 0, function () {
          var t, e, n, o, a, i, u, s;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, this.fetch(this.path, this.requestInit)];

              case 1:
                if (!(t = r.sent()).ok) throw new Error("Request to " + this.path + " failed with status code " + t.status + ". Please verify this URL points to the model JSON of the model to load.");
                r.label = 2;

              case 2:
                return r.trys.push([2, 4, , 5]), [4, t.json()];

              case 3:
                return e = r.sent(), [3, 5];

              case 4:
                throw r.sent(), n = "Failed to parse model JSON of response from " + this.path + ".", this.path.endsWith(".pb") ? n += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : n += " Please make sure the server is serving valid JSON for this request.", new Error(n);

              case 5:
                if (o = e.modelTopology, a = e.weightsManifest, null == o && null == a) throw new Error("The JSON from HTTP path " + this.path + " contains neither model topology or manifest for weights.");
                return null == a ? [3, 7] : [4, this.loadWeights(a)];

              case 6:
                s = r.sent(), i = s[0], u = s[1], r.label = 7;

              case 7:
                return [2, {
                  modelTopology: o,
                  weightSpecs: i,
                  weightData: u
                }];
            }
          });
        });
      }, t.prototype.loadWeights = function (t) {
        return n(this, void 0, void 0, function () {
          var e, n, o, a, i, u, s, c, l, h, f;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                for (e = Array.isArray(this.path) ? this.path[1] : this.path, n = function (t) {
                  var e = t.lastIndexOf("/"),
                    n = t.lastIndexOf("?"),
                    r = t.substring(0, e),
                    o = n > e ? t.substring(n) : "";
                  return [r + "/", o];
                }(e), o = n[0], a = n[1], i = this.weightPathPrefix || o, u = [], s = 0, c = t; s < c.length; s++) l = c[s], u.push.apply(u, l.weights);

                return h = [], t.forEach(function (t) {
                  t.paths.forEach(function (t) {
                    h.push(i + t + a);
                  });
                }), [4, xf(h, {
                  requestInit: this.requestInit,
                  fetchFunc: this.fetch,
                  onProgress: this.onProgress
                })];

              case 1:
                return f = r.sent(), [2, [u, Lh(f)]];
            }
          });
        });
      }, t.URL_SCHEME_REGEX = /^https?:\/\//, t;
    }();

    function Cf(t) {
      return null != t.match(wf.URL_SCHEME_REGEX);
    }

    var Ef = function (t, e) {
      if ("undefined" == typeof fetch) return null;
      return (Array.isArray(t) ? t.every(function (t) {
        return Cf(t);
      }) : Cf(t)) ? Rf(t, {
        onProgress: e
      }) : null;
    };

    function Rf(t, e) {
      return new wf(t, e);
    }

    Vh.registerSaveRouter(Ef), Vh.registerLoadRouter(Ef);

    var If = function () {
      function t(t) {
        this.modelArtifacts = t;
      }

      return t.prototype.load = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            return [2, this.modelArtifacts];
          });
        });
      }, t;
    }(),
      kf = function () {
        function t(t) {
          this.saveHandler = t;
        }

        return t.prototype.save = function (t) {
          return n(this, void 0, void 0, function () {
            return r(this, function (e) {
              return [2, this.saveHandler(t)];
            });
          });
        }, t;
      }();

    var Sf = Object.freeze({
      browserFiles: function (t) {
        return new gf(t);
      },
      browserHTTPRequest: function (t, e) {
        return Rf(t, e);
      },
      concatenateArrayBuffers: Lh,
      decodeWeights: _h,
      encodeWeights: function (t, e) {
        return n(this, void 0, void 0, function () {
          var o,
            a,
            i,
            u,
            s,
            c = this;
          return r(this, function (l) {
            switch (l.label) {
              case 0:
                for (o = [], a = [], i = Array.isArray(t) ? t.map(function (t) {
                  return t.name;
                }) : Object.keys(t), u = function (u) {
                  var s = i[u],
                    l = Array.isArray(t) ? t[u].tensor : t[s];
                  if ("float32" !== l.dtype && "int32" !== l.dtype && "bool" !== l.dtype && "string" !== l.dtype) throw new Error("Unsupported dtype in weight '" + s + "': " + l.dtype);
                  var h = {
                    name: s,
                    shape: l.shape,
                    dtype: l.dtype
                  };

                  if ("string" === l.dtype) {
                    var f = new Promise(function (t) {
                      return n(c, void 0, void 0, function () {
                        var e, n, o, a, i, u, s;
                        return r(this, function (r) {
                          switch (r.label) {
                            case 0:
                              return [4, l.bytes()];

                            case 1:
                              for (e = r.sent(), n = e.reduce(function (t, e) {
                                return t + e.length;
                              }, 0) + Oh * e.length, o = new Uint8Array(n), a = 0, i = 0; i < e.length; i++) u = e[i], s = new Uint8Array(new Uint32Array([u.length]).buffer), o.set(s, a), a += Oh, o.set(u, a), a += u.length;

                              return t(o), [2];
                          }
                        });
                      });
                    });
                    a.push(f);
                  } else a.push(l.data());

                  null != e && (h.group = e), o.push(h);
                }, s = 0; s < i.length; ++s) u(s);

                return [4, Promise.all(a)];

              case 1:
                return [2, {
                  data: Mh(l.sent()),
                  specs: o
                }];
            }
          });
        });
      },
      fromMemory: function (t, e, n, r) {
        return 1 === arguments.length ? null != t.modelTopology || null != t.weightSpecs ? new If(t) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new If({
          modelTopology: t
        })) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new If({
          modelTopology: t,
          weightSpecs: e,
          weightData: n,
          trainingConfig: r
        }));
      },
      getLoadHandlers: function (t, e) {
        return Vh.getLoadHandlers(t, e);
      },
      getModelArtifactsInfoForJSON: Uh,
      getSaveHandlers: function (t) {
        return Vh.getSaveHandlers(t);
      },
      http: Rf,
      isHTTPScheme: Cf,
      loadWeights: function (t, e, o, a) {
        return void 0 === e && (e = ""), n(this, void 0, void 0, function () {
          return r(this, function (n) {
            return [2, bf(function (t) {
              return xf(t, {
                requestInit: a
              });
            })(t, e, o)];
          });
        });
      },
      registerLoadRouter: function (t) {
        return Vh.registerLoadRouter(t);
      },
      registerSaveRouter: function (t) {
        return Vh.registerSaveRouter(t);
      },
      weightsLoaderFactory: bf,
      withSaveHandler: function (t) {
        return new kf(t);
      },
      copyModel: function (t, e) {
        return n(this, void 0, void 0, function () {
          return r(this, function (n) {
            return [2, qh(t, e, !1)];
          });
        });
      },
      listModels: function () {
        return n(this, void 0, void 0, function () {
          var t, e, n, o, a, i, u;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                t = Gh.getSchemes(), e = {}, n = 0, o = t, r.label = 1;

              case 1:
                return n < o.length ? (a = o[n], [4, Gh.getManager(a).listModels()]) : [3, 4];

              case 2:
                for (u in i = r.sent()) e[a + zh + u] = i[u];

                r.label = 3;

              case 3:
                return n++, [3, 1];

              case 4:
                return [2, e];
            }
          });
        });
      },
      moveModel: function (t, e) {
        return n(this, void 0, void 0, function () {
          return r(this, function (n) {
            return [2, qh(t, e, !0)];
          });
        });
      },
      removeModel: function (t) {
        return n(this, void 0, void 0, function () {
          var e;
          return r(this, function (n) {
            return e = Hh(t), [2, Gh.getManager(e.scheme).removeModel(e.path)];
          });
        });
      }
    });
    exports.io = Sf;
    var Af = Cn({
      confusionMatrix_: function (t, e, n) {
        var r = ln(t, "labels", "confusionMatrix"),
          o = ln(e, "predictions", "confusionMatrix");
        g(null == n || n > 0 && Number.isInteger(n), function () {
          return "If provided, numClasses must be a positive integer, but got " + n;
        }), g(1 === r.rank, function () {
          return "Expected the rank of labels to be 1, but got " + r.rank;
        }), g(1 === o.rank, function () {
          return "Expected the rank of predictions to be 1, but got " + o.rank;
        }), g(r.shape[0] === o.shape[0], function () {
          return "Mismatch in the number of examples: " + r.shape[0] + " vs. " + o.shape[0] + ". Labels and predictions should have the same number of elements.";
        }), g(n > 0 && Number.isInteger(n), function () {
          return "numClasses is required to be a positive integer, but got " + n;
        });
        var a = gr(r.asType("int32"), n),
          i = gr(o.asType("int32"), n);
        return a.transpose().matMul(i).asType("int32");
      }
    }),
      Df = Object.freeze({
        confusionMatrix: Af
      });
    exports.math = Df;

    var Tf = Cn({
      fromPixels_: function (t, e) {
        if (void 0 === e && (e = 3), e > 4) throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");
        var n = "undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement;
        if (n && n && t.readyState < 2) throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");
        return Nt.fromPixels(t, e);
      }
    }),
      Nf = Object.freeze({
        toPixels: function (t, e) {
          return n(this, void 0, void 0, function () {
            var n, o, a, i, u, s, c, l, h, f, p, d, v, m, g, y, x, b, w, C, E, R, I;
            return r(this, function (r) {
              switch (r.label) {
                case 0:
                  if (n = ln(t, "img", "toPixels"), t instanceof dt || (n = n.toInt()), 2 !== n.rank && 3 !== n.rank) throw new Error("toPixels only supports rank 2 or 3 tensors, got rank " + n.rank + ".");
                  if (o = n.shape.slice(0, 2), a = o[0], i = o[1], (u = 2 === n.rank ? 1 : n.shape[2]) > 4 || 2 === u) throw new Error("toPixels only supports depth of size 1, 3 or 4 but got " + u);
                  return [4, n.data()];

                case 1:
                  return s = r.sent(), c = n.min(), l = n.max(), [4, Promise.all([c.data(), l.data()])];

                case 2:
                  if (h = r.sent(), f = h[0], p = h[1], d = f[0], v = p[0], c.dispose(), l.dispose(), "float32" === n.dtype) {
                    if (d < 0 || v > 1) throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range [" + d + " - " + v + "].");
                  } else {
                    if ("int32" !== n.dtype) throw new Error("Unsupported type for toPixels: " + n.dtype + ". Please use float32 or int32 tensors.");
                    if (d < 0 || v > 255) throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range [" + d + " - " + v + "].");
                  }

                  for (m = "float32" === n.dtype ? 255 : 1, g = new Uint8ClampedArray(i * a * 4), y = 0; y < a * i; ++y) x = void 0, b = void 0, w = void 0, C = void 0, 1 === u ? (x = s[y] * m, b = s[y] * m, w = s[y] * m, C = 255) : 3 === u ? (x = s[3 * y] * m, b = s[3 * y + 1] * m, w = s[3 * y + 2] * m, C = 255) : 4 === u && (x = s[4 * y] * m, b = s[4 * y + 1] * m, w = s[4 * y + 2] * m, C = s[4 * y + 3] * m), g[0 + (E = 4 * y)] = Math.round(x), g[E + 1] = Math.round(b), g[E + 2] = Math.round(w), g[E + 3] = Math.round(C);

                  return null != e && (e.width = i, e.height = a, R = e.getContext("2d"), I = new ImageData(g, i, a), R.putImageData(I, 0, 0)), n !== t && n.dispose(), [2, g];
              }
            });
          });
        },
        fromPixels: Tf
      }),
      Ff = function () {
        function t() { }

        return t.prototype.getClassName = function () {
          return this.constructor.className;
        }, t.fromConfig = function (t, e) {
          return new t(e);
        }, t;
      }(),
      Of = function () {
        function t() {
          this.classNameMap = {};
        }

        return t.getMap = function () {
          return null == t.instance && (t.instance = new t()), t.instance;
        }, t.register = function (e) {
          t.getMap().classNameMap[e.className] = [e, e.fromConfig];
        }, t;
      }();

    exports.browser = Nf;

    function _f(t) {
      g(null != t.className, function () {
        return "Class being registered does not have the static className property defined.";
      }), g("string" == typeof t.className, function () {
        return "className is required to be a string, but got type " + typeof t.className;
      }), g(t.className.length > 0, function () {
        return "Class being registered has an empty-string as its className, which is disallowed.";
      }), Of.register(t);
    }

    var Mf = Object.freeze({
      Serializable: Ff,
      SerializationMap: Of,
      registerClass: _f
    }),
      Bf = .001,
      Pf = .1;
    exports.serialization = Mf;

    function Lf() {
      return 32 === Nt.backend.floatPrecision() ? Bf : Pf;
    }

    function Wf(t, e, n) {
      var r = !0;

      if ((B(t) || B(e)) && (r = !1), B(t) && B(e) && (r = !0), r) {
        var o = t.constructor.name,
          a = e.constructor.name;
        if (o !== a) throw new Error("Arrays are of different type. Actual: " + o + ". Expected: " + a);
      }

      if (Array.isArray(t) && Array.isArray(e)) {
        var i = sn(t),
          u = sn(e);
        if (!C(i, u)) throw new Error("Arrays have different shapes. Actual: [" + i + "]. Expected: [" + u + "]");
      }

      var s = B(t) ? t : b(t),
        c = B(e) ? e : b(e);
      if (s.length !== c.length) throw new Error("Arrays have different lengths actual: " + s.length + " vs expected: " + c.length + ".\nActual:   " + s + ".\nExpected: " + c + ".");

      for (var l = 0; l < c.length; ++l) {
        var h = s[l],
          f = c[l];
        if (!n(h, f)) throw new Error("Arrays differ: actual[" + l + "] = " + h + ", expected[" + l + "] = " + f + ".\nActual:   " + s + ".\nExpected: " + c + ".");
      }
    }

    function Uf(t, e, n) {
      return !isFinite(t) && !isFinite(e) || !(isNaN(t) || isNaN(e) || Math.abs(t - e) > n);
    }

    var Vf = Object.freeze({
      TEST_EPSILON_FLOAT16: Pf,
      expectArraysClose: function (t, e, n) {
        return null == n && (n = Lf()), Wf(t, e, function (t, e) {
          return Uf(t, e, n);
        });
      },
      testEpsilon: Lf,
      expectPromiseToFail: function (t, e) {
        t().then(function () {
          return e.fail();
        }, function () {
          return e();
        });
      },
      expectArraysEqual: function (t, e) {
        var n = "string" == typeof e || "number" == typeof e || "boolean" == typeof e ? [e] : e;
        return W(t) || W(t[0]) || W(e) || W(e[0]) ? Wf(t, n, function (t, e) {
          return t == e;
        }) : Wf(t, e, function (t, e) {
          return Uf(t, e, 0);
        });
      },
      expectNumbersClose: function (t, e, n) {
        if (null == n && (n = Lf()), !Uf(t, e, n)) throw new Error("Numbers differ: actual === " + t + ", expected === " + e);
      },
      expectValuesInRange: function (t, e, n) {
        for (var r = 0; r < t.length; r++) if (t[r] < e || t[r] > n) throw new Error("Value out of range:" + t[r] + " low: " + e + ", high: " + n);
      },
      expectArrayBuffersEqual: function (t, e) {
        expect(new Float32Array(t)).toEqual(new Float32Array(e));
      }
    }),
      zf = "1.3.1";
    exports.version_core = zf;
    exports.test_util = Vf;

    var Gf = Object.freeze({
      gpgpu_util: wi,
      webgl_util: Pe,
      forceHalfFloat: function () {
        a().set("WEBGL_FORCE_F16_TEXTURES", !0);
      },
      MathBackendWebGL: Wu,
      setWebGLContext: Wt,
      GPGPUContext: Ci
    }),
      Hf = function (t) {
        function o() {
          return null !== t && t.apply(this, arguments) || this;
        }

        return e(o, t), o.prototype.minimize = function (t, e, n) {
          void 0 === e && (e = !1);
          var r = this.computeGradients(t, n),
            o = r.value,
            a = r.grads;

          if (null != n) {
            var i = n.map(function (t) {
              return {
                name: t.name,
                tensor: a[t.name]
              };
            });
            this.applyGradients(i);
          } else this.applyGradients(a);

          return Xe(a), e ? o : (o.dispose(), null);
        }, Object.defineProperty(o.prototype, "iterations", {
          get: function () {
            return null == this.iterations_ && (this.iterations_ = 0), this.iterations_;
          },
          enumerable: !0,
          configurable: !0
        }), o.prototype.incrementIterations = function () {
          this.iterations_ = this.iterations + 1;
        }, o.prototype.computeGradients = function (t, e) {
          return ro(t, e);
        }, o.prototype.dispose = function () {
          null != this.iterations_ && Xe(this.iterations_);
        }, o.prototype.saveIterations = function () {
          return n(this, void 0, void 0, function () {
            return r(this, function (t) {
              return null == this.iterations_ && (this.iterations_ = 0), [2, {
                name: "iter",
                tensor: An(this.iterations_, "int32")
              }];
            });
          });
        }, o.prototype.getWeights = function () {
          return n(this, void 0, void 0, function () {
            return r(this, function (t) {
              throw new Error("getWeights() is not implemented for this optimizer yet.");
            });
          });
        }, o.prototype.setWeights = function (t) {
          return n(this, void 0, void 0, function () {
            return r(this, function (t) {
              throw new Error("setWeights() is not implemented for this optimizer class " + this.getClassName());
            });
          });
        }, o.prototype.extractIterations = function (t) {
          return n(this, void 0, void 0, function () {
            var e;
            return r(this, function (n) {
              switch (n.label) {
                case 0:
                  return e = this, [4, t[0].tensor.data()];

                case 1:
                  return e.iterations_ = n.sent()[0], [2, t.slice(1)];
              }
            });
          });
        }, o;
      }(Ff);

    exports.Optimizer = Hf;
    exports.webgl = Gf;
    Object.defineProperty(Hf, Symbol.hasInstance, {
      value: function (t) {
        return null != t.minimize && null != t.computeGradients && null != t.applyGradients;
      }
    });

    var qf = function (t) {
      function o(e, n, r) {
        void 0 === r && (r = null);
        var o = t.call(this) || this;
        return o.learningRate = e, o.rho = n, o.epsilon = r, o.accumulatedGrads = [], o.accumulatedUpdates = [], null == r && (o.epsilon = Nt.backend.epsilon()), o;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this;
        (Array.isArray(t) ? t.map(function (t) {
          return t.name;
        }) : Object.keys(t)).forEach(function (n, r) {
          var o = Nt.registeredVariables[n];
          null == e.accumulatedGrads[r] && (e.accumulatedGrads[r] = {
            originalName: n + "/accum_grad",
            variable: je(function () {
              return zn(o).variable(!1);
            })
          }), null == e.accumulatedUpdates[r] && (e.accumulatedUpdates[r] = {
            originalName: n + "/accum_var",
            variable: je(function () {
              return zn(o).variable(!1);
            })
          });
          var a = Array.isArray(t) ? t[r].tensor : t[n];

          if (null != a) {
            var i = e.accumulatedGrads[r].variable,
              u = e.accumulatedUpdates[r].variable;
            je(function () {
              var t = i.mul(e.rho).add(a.square().mul(1 - e.rho)),
                n = u.add(e.epsilon).sqrt().div(i.add(e.epsilon).sqrt()).mul(a),
                r = u.mul(e.rho).add(n.square().mul(1 - e.rho));
              i.assign(t), u.assign(r);
              var s = n.mul(-e.learningRate).add(o);
              o.assign(s);
            });
          }
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        null != this.accumulatedUpdates && (Xe(this.accumulatedGrads.map(function (t) {
          return t.variable;
        })), Xe(this.accumulatedUpdates.map(function (t) {
          return t.variable;
        })));
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return t = this.accumulatedGrads.concat(this.accumulatedUpdates), [4, this.saveIterations()];

              case 1:
                return [2, [e.sent()].concat(t.map(function (t) {
                  return {
                    name: t.originalName,
                    tensor: t.variable
                  };
                }))];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          var e;
          return r(this, function (n) {
            switch (n.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                return t = n.sent(), e = t.length / 2, !1, this.accumulatedGrads = t.slice(0, e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), this.accumulatedUpdates = t.slice(e, 2 * e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          rho: this.rho,
          epsilon: this.epsilon
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.rho, e.epsilon);
      }, o.className = "Adadelta", o;
    }(Hf);

    exports.AdadeltaOptimizer = qf;

    _f(qf);

    var Kf = function (t) {
      function o(e, n) {
        void 0 === n && (n = .1);
        var r = t.call(this) || this;
        return r.learningRate = e, r.initialAccumulatorValue = n, r.accumulatedGrads = [], r;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this;
        (Array.isArray(t) ? t.map(function (t) {
          return t.name;
        }) : Object.keys(t)).forEach(function (n, r) {
          var o = Nt.registeredVariables[n];

          if (null == e.accumulatedGrads[r]) {
            e.accumulatedGrads[r] = {
              originalName: n + "/accumulator",
              variable: je(function () {
                return Ln(o.shape, e.initialAccumulatorValue).variable(!1);
              })
            };
          }

          var a = Array.isArray(t) ? t[r].tensor : t[n];

          if (null != a) {
            var i = e.accumulatedGrads[r].variable;
            je(function () {
              var t = i.add(a.square());
              i.assign(t);
              var n = a.div(t.add(Nt.backend.epsilon()).sqrt()).mul(-e.learningRate).add(o);
              o.assign(n);
            });
          }
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        null != this.accumulatedGrads && Xe(this.accumulatedGrads.map(function (t) {
          return t.variable;
        }));
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            switch (t.label) {
              case 0:
                return [4, this.saveIterations()];

              case 1:
                return [2, [t.sent()].concat(this.accumulatedGrads.map(function (t) {
                  return {
                    name: t.originalName,
                    tensor: t.variable
                  };
                }))];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                return t = e.sent(), !1, this.accumulatedGrads = t.map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          initialAccumulatorValue: this.initialAccumulatorValue
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.initialAccumulatorValue);
      }, o.className = "Adagrad", o;
    }(Hf);

    exports.AdagradOptimizer = Kf;

    _f(Kf);

    var jf = function (t) {
      function o(e, n, r, o) {
        void 0 === o && (o = null);
        var a = t.call(this) || this;
        return a.learningRate = e, a.beta1 = n, a.beta2 = r, a.epsilon = o, a.accumulatedFirstMoment = [], a.accumulatedSecondMoment = [], je(function () {
          a.accBeta1 = An(n).variable(), a.accBeta2 = An(r).variable();
        }), null == o && (a.epsilon = Nt.backend.epsilon()), a;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this,
          n = Array.isArray(t) ? t.map(function (t) {
            return t.name;
          }) : Object.keys(t);
        je(function () {
          var r = ic(1, e.accBeta1),
            o = ic(1, e.accBeta2);
          n.forEach(function (n, a) {
            var i = Nt.registeredVariables[n];
            null == e.accumulatedFirstMoment[a] && (e.accumulatedFirstMoment[a] = {
              originalName: n + "/m",
              variable: je(function () {
                return zn(i).variable(!1);
              })
            }), null == e.accumulatedSecondMoment[a] && (e.accumulatedSecondMoment[a] = {
              originalName: n + "/v",
              variable: je(function () {
                return zn(i).variable(!1);
              })
            });
            var u = Array.isArray(t) ? t[a].tensor : t[n];

            if (null != u) {
              var s = e.accumulatedFirstMoment[a].variable,
                c = e.accumulatedSecondMoment[a].variable,
                l = s.mul(e.beta1).add(u.mul(1 - e.beta1)),
                h = c.mul(e.beta2).add(u.square().mul(1 - e.beta2)),
                f = l.div(r),
                p = h.div(o);
              s.assign(l), c.assign(h);
              var d = f.div(p.sqrt().add(e.epsilon)).mul(-e.learningRate).add(i);
              i.assign(d);
            }
          }), e.accBeta1.assign(e.accBeta1.mul(e.beta1)), e.accBeta2.assign(e.accBeta2.mul(e.beta2));
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        this.accBeta1.dispose(), this.accBeta2.dispose(), null != this.accumulatedFirstMoment && Xe(this.accumulatedFirstMoment.map(function (t) {
          return t.variable;
        })), null != this.accumulatedSecondMoment && Xe(this.accumulatedSecondMoment.map(function (t) {
          return t.variable;
        }));
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return t = this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment), [4, this.saveIterations()];

              case 1:
                return [2, [e.sent()].concat(t.map(function (t) {
                  return {
                    name: t.originalName,
                    tensor: t.variable
                  };
                }))];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          var e,
            n = this;
          return r(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                return t = r.sent(), je(function () {
                  n.accBeta1.assign(nc(n.beta1, n.iterations_ + 1)), n.accBeta2.assign(nc(n.beta2, n.iterations_ + 1));
                }), e = t.length / 2, !1, this.accumulatedFirstMoment = t.slice(0, e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), this.accumulatedSecondMoment = t.slice(e, 2 * e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          beta1: this.beta1,
          beta2: this.beta2,
          epsilon: this.epsilon
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.beta1, e.beta2, e.epsilon);
      }, o.className = "Adam", o;
    }(Hf);

    exports.AdamOptimizer = jf;

    _f(jf);

    var Xf = function (t) {
      function o(e, n, r, o, a) {
        void 0 === o && (o = null), void 0 === a && (a = 0);
        var i = t.call(this) || this;
        return i.learningRate = e, i.beta1 = n, i.beta2 = r, i.epsilon = o, i.decay = a, i.accumulatedFirstMoment = [], i.accumulatedWeightedInfNorm = [], je(function () {
          i.iteration = An(0).variable(), i.accBeta1 = An(n).variable();
        }), null == o && (i.epsilon = Nt.backend.epsilon()), i;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this,
          n = Array.isArray(t) ? t.map(function (t) {
            return t.name;
          }) : Object.keys(t);
        je(function () {
          var r = ic(1, e.accBeta1),
            o = qs(-e.learningRate, e.iteration.mul(e.decay).add(1));
          n.forEach(function (n, a) {
            var i = Nt.registeredVariables[n];
            null == e.accumulatedFirstMoment[a] && (e.accumulatedFirstMoment[a] = {
              originalName: n + "/m",
              variable: zn(i).variable(!1)
            }), null == e.accumulatedWeightedInfNorm[a] && (e.accumulatedWeightedInfNorm[a] = {
              originalName: n + "/v",
              variable: zn(i).variable(!1)
            });
            var u = Array.isArray(t) ? t[a].tensor : t[n];

            if (null != u) {
              var s = e.accumulatedFirstMoment[a].variable,
                c = e.accumulatedWeightedInfNorm[a].variable,
                l = s.mul(e.beta1).add(u.mul(1 - e.beta1)),
                h = c.mul(e.beta2),
                f = u.abs(),
                p = h.maximum(f);
              s.assign(l), c.assign(p);
              var d = o.div(r).mul(l.div(p.add(e.epsilon))).add(i);
              i.assign(d);
            }
          }), e.iteration.assign(e.iteration.add(1)), e.accBeta1.assign(e.accBeta1.mul(e.beta1));
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        this.accBeta1.dispose(), this.iteration.dispose(), null != this.accumulatedFirstMoment && Xe(this.accumulatedFirstMoment.map(function (t) {
          return t.variable;
        })), null != this.accumulatedWeightedInfNorm && Xe(this.accumulatedWeightedInfNorm.map(function (t) {
          return t.variable;
        }));
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            throw new Error("getWeights() is not implemented for Adamax yet.");
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            throw new Error("setWeights() is not implemented for Adamax yet.");
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          beta1: this.beta1,
          beta2: this.beta2,
          epsilon: this.epsilon,
          decay: this.decay
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.beta1, e.beta2, e.epsilon, e.decay);
      }, o.className = "Adamax", o;
    }(Hf);

    exports.AdamaxOptimizer = Xf;

    _f(Xf);

    var $f = function (t) {
      function o(e) {
        var n = t.call(this) || this;
        return n.learningRate = e, n.setLearningRate(e), n;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this;
        (Array.isArray(t) ? t.map(function (t) {
          return t.name;
        }) : Object.keys(t)).forEach(function (n, r) {
          var o = Array.isArray(t) ? t[r].tensor : t[n];

          if (null != o) {
            var a = Nt.registeredVariables[n];
            je(function () {
              var t = e.c.mul(o).add(a);
              a.assign(t);
            });
          }
        }), this.incrementIterations();
      }, o.prototype.setLearningRate = function (t) {
        this.learningRate = t, null != this.c && this.c.dispose(), this.c = $e(An(-t));
      }, o.prototype.dispose = function () {
        this.c.dispose();
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            switch (t.label) {
              case 0:
                return [4, this.saveIterations()];

              case 1:
                return [2, [t.sent()]];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                if (0 !== (t = e.sent()).length) throw new Error("SGD optimizer does not have settable weights.");
                return [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate);
      }, o.className = "SGD", o;
    }(Hf);

    exports.SGDOptimizer = $f;

    _f($f);

    var Yf = function (t) {
      function o(e, n, r) {
        void 0 === r && (r = !1);
        var o = t.call(this, e) || this;
        return o.learningRate = e, o.momentum = n, o.useNesterov = r, o.accumulations = [], o.m = An(o.momentum), o;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this;
        (Array.isArray(t) ? t.map(function (t) {
          return t.name;
        }) : Object.keys(t)).forEach(function (n, r) {
          var o = Nt.registeredVariables[n];

          if (null == e.accumulations[r]) {
            e.accumulations[r] = {
              originalName: n + "/momentum",
              variable: je(function () {
                return zn(o).variable(!1);
              })
            };
          }

          var a = e.accumulations[r].variable,
            i = Array.isArray(t) ? t[r].tensor : t[n];
          null != i && je(function () {
            var t,
              n = e.m.mul(a).add(i);
            t = e.useNesterov ? e.c.mul(i.add(n.mul(e.m))).add(o) : e.c.mul(n).add(o), a.assign(n), o.assign(t);
          });
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        this.m.dispose(), null != this.accumulations && Xe(this.accumulations.map(function (t) {
          return t.variable;
        }));
      }, o.prototype.setMomentum = function (t) {
        this.momentum = t;
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          return r(this, function (t) {
            switch (t.label) {
              case 0:
                return [4, this.saveIterations()];

              case 1:
                return [2, [t.sent()].concat(this.accumulations.map(function (t) {
                  return {
                    name: t.originalName,
                    tensor: t.variable
                  };
                }))];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                return t = e.sent(), !1, this.accumulations = t.map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          momentum: this.momentum,
          useNesterov: this.useNesterov
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.momentum, e.useNesterov);
      }, o.className = "Momentum", o;
    }($f);

    exports.MomentumOptimizer = Yf;

    _f(Yf);

    var Qf = function (t) {
      function o(e, n, r, o, a) {
        void 0 === n && (n = .9), void 0 === r && (r = 0), void 0 === o && (o = null), void 0 === a && (a = !1);
        var i = t.call(this) || this;
        return i.learningRate = e, i.decay = n, i.momentum = r, i.epsilon = o, i.accumulatedMeanSquares = [], i.accumulatedMoments = [], i.accumulatedMeanGrads = [], i.centered = a, null == o && (i.epsilon = Nt.backend.epsilon()), i;
      }

      return e(o, t), o.prototype.applyGradients = function (t) {
        var e = this;
        (Array.isArray(t) ? t.map(function (t) {
          return t.name;
        }) : Object.keys(t)).forEach(function (n, r) {
          var o = Nt.registeredVariables[n];
          null == e.accumulatedMeanSquares[r] && (e.accumulatedMeanSquares[r] = {
            originalName: n + "/rms",
            variable: je(function () {
              return zn(o).variable(!1);
            })
          }), null == e.accumulatedMoments[r] && (e.accumulatedMoments[r] = {
            originalName: n + "/momentum",
            variable: je(function () {
              return zn(o).variable(!1);
            })
          }), null == e.accumulatedMeanGrads[r] && e.centered && (e.accumulatedMeanGrads[r] = {
            originalName: n + "/mg",
            variable: je(function () {
              return zn(o).variable(!1);
            })
          });
          var a = Array.isArray(t) ? t[r].tensor : t[n];

          if (null != a) {
            var i = e.accumulatedMeanSquares[r].variable,
              u = e.accumulatedMoments[r].variable;
            je(function () {
              var t = i.mul(e.decay).add(a.square().mul(1 - e.decay));

              if (e.centered) {
                var n = e.accumulatedMeanGrads[r].variable,
                  s = n.mul(e.decay).add(a.mul(1 - e.decay)),
                  c = u.mul(e.momentum).add(a.mul(e.learningRate).div(t.sub(s.square().add(e.epsilon)).sqrt()));
                i.assign(t), n.assign(s), u.assign(c);
                var l = o.sub(c);
                o.assign(l);
              } else {
                var h = i.mul(e.decay).add(a.square().mul(1 - e.decay));
                c = u.mul(e.momentum).add(a.mul(e.learningRate).div(h.add(e.epsilon).sqrt()));
                i.assign(h), u.assign(c);
                l = o.sub(c);
                o.assign(l);
              }
            });
          }
        }), this.incrementIterations();
      }, o.prototype.dispose = function () {
        null != this.accumulatedMeanSquares && Xe(this.accumulatedMeanSquares.map(function (t) {
          return t.variable;
        })), null != this.accumulatedMeanGrads && this.centered && Xe(this.accumulatedMeanGrads.map(function (t) {
          return t.variable;
        })), null != this.accumulatedMoments && Xe(this.accumulatedMoments.map(function (t) {
          return t.variable;
        }));
      }, o.prototype.getWeights = function () {
        return n(this, void 0, void 0, function () {
          var t;
          return r(this, function (e) {
            switch (e.label) {
              case 0:
                return t = this.accumulatedMeanSquares.concat(this.accumulatedMoments), this.centered && t.push.apply(t, this.accumulatedMeanGrads), [4, this.saveIterations()];

              case 1:
                return [2, [e.sent()].concat(t.map(function (t) {
                  return {
                    name: t.originalName,
                    tensor: t.variable
                  };
                }))];
            }
          });
        });
      }, o.prototype.setWeights = function (t) {
        return n(this, void 0, void 0, function () {
          var e;
          return r(this, function (n) {
            switch (n.label) {
              case 0:
                return [4, this.extractIterations(t)];

              case 1:
                return t = n.sent(), e = this.centered ? t.length / 3 : t.length / 2, !1, this.accumulatedMeanSquares = t.slice(0, e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), this.accumulatedMoments = t.slice(e, 2 * e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                }), this.centered && (this.accumulatedMeanGrads = t.slice(2 * e, 3 * e).map(function (t) {
                  return {
                    originalName: t.name,
                    variable: t.tensor.variable(!1)
                  };
                })), [2];
            }
          });
        });
      }, o.prototype.getConfig = function () {
        return {
          learningRate: this.learningRate,
          decay: this.decay,
          momentum: this.momentum,
          epsilon: this.epsilon,
          centered: this.centered
        };
      }, o.fromConfig = function (t, e) {
        return new t(e.learningRate, e.decay, e.momentum, e.epsilon, e.centered);
      }, o.className = "RMSProp", o;
    }(Hf);

    exports.RMSPropOptimizer = Qf;

    _f(Qf);

    var Jf = function () {
      function t() { }

      return t.sgd = function (t) {
        return new $f(t);
      }, t.momentum = function (t, e, n) {
        return void 0 === n && (n = !1), new Yf(t, e, n);
      }, t.rmsprop = function (t, e, n, r, o) {
        return void 0 === e && (e = .9), void 0 === n && (n = 0), void 0 === r && (r = null), void 0 === o && (o = !1), new Qf(t, e, n, r, o);
      }, t.adam = function (t, e, n, r) {
        return void 0 === t && (t = .001), void 0 === e && (e = .9), void 0 === n && (n = .999), void 0 === r && (r = null), new jf(t, e, n, r);
      }, t.adadelta = function (t, e, n) {
        return void 0 === t && (t = .001), void 0 === e && (e = .95), void 0 === n && (n = null), new qf(t, e, n);
      }, t.adamax = function (t, e, n, r, o) {
        return void 0 === t && (t = .002), void 0 === e && (e = .9), void 0 === n && (n = .999), void 0 === r && (r = null), void 0 === o && (o = 0), new Xf(t, e, n, r, o);
      }, t.adagrad = function (t, e) {
        return void 0 === e && (e = .1), new Kf(t, e);
      }, t;
    }(),
      Zf = {
        sgd: Jf.sgd,
        momentum: Jf.momentum,
        adadelta: Jf.adadelta,
        adagrad: Jf.adagrad,
        rmsprop: Jf.rmsprop,
        adamax: Jf.adamax,
        adam: Jf.adam
      },
      tp = "undefined" != typeof requestAnimationFrame ? requestAnimationFrame : "undefined" != typeof setImmediate ? setImmediate : function (t) {
        return t();
      };

    exports.train = Zf;

    function ep() {
      return new Promise(function (t) {
        return tp(function () {
          return t();
        });
      });
    }

    ft = Rh;
  }, { "crypto": "node_modules/parcel-bundler/src/builtins/_empty.js", "node-fetch": "node_modules/parcel-bundler/src/builtins/_empty.js", "util": "node_modules/parcel-bundler/src/builtins/_empty.js", "process": "node_modules/process/browser.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js": [function (require, module, exports) {
    var Buffer = require("buffer").Buffer;
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.loadGraphModel = loadGraphModel;
    exports.deregisterOp = deregisterOp;
    exports.registerOp = registerOp;
    exports.version_converter = exports.GraphModel = void 0;

    var _tfjsCore = require("@tensorflow/tfjs-core");

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    var DataType,
      SaverDef,
      __assign = function () {
        return (__assign = Object.assign || function (e) {
          for (var t, a = 1, r = arguments.length; a < r; a++) for (var n in t = arguments[a]) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);

          return e;
        }).apply(this, arguments);
      };

    function __awaiter(e, t, a, r) {
      return new (a || (a = Promise))(function (n, s) {
        function o(e) {
          try {
            u(r.next(e));
          } catch (e) {
            s(e);
          }
        }

        function p(e) {
          try {
            u(r.throw(e));
          } catch (e) {
            s(e);
          }
        }

        function u(e) {
          e.done ? n(e.value) : new a(function (t) {
            t(e.value);
          }).then(o, p);
        }

        u((r = r.apply(e, t || [])).next());
      });
    }

    function __generator(e, t) {
      var a,
        r,
        n,
        s,
        o = {
          label: 0,
          sent: function () {
            if (1 & n[0]) throw n[1];
            return n[1];
          },
          trys: [],
          ops: []
        };
      return s = {
        next: p(0),
        throw: p(1),
        return: p(2)
      }, "function" == typeof Symbol && (s[Symbol.iterator] = function () {
        return this;
      }), s;

      function p(s) {
        return function (p) {
          return function (s) {
            if (a) throw new TypeError("Generator is already executing.");

            for (; o;) try {
              if (a = 1, r && (n = 2 & s[0] ? r.return : s[0] ? r.throw || ((n = r.return) && n.call(r), 0) : r.next) && !(n = n.call(r, s[1])).done) return n;

              switch (r = 0, n && (s = [2 & s[0], n.value]), s[0]) {
                case 0:
                case 1:
                  n = s;
                  break;

                case 4:
                  return o.label++, {
                    value: s[1],
                    done: !1
                  };

                case 5:
                  o.label++, r = s[1], s = [0];
                  continue;

                case 7:
                  s = o.ops.pop(), o.trys.pop();
                  continue;

                default:
                  if (!(n = (n = o.trys).length > 0 && n[n.length - 1]) && (6 === s[0] || 2 === s[0])) {
                    o = 0;
                    continue;
                  }

                  if (3 === s[0] && (!n || s[1] > n[0] && s[1] < n[3])) {
                    o.label = s[1];
                    break;
                  }

                  if (6 === s[0] && o.label < n[1]) {
                    o.label = n[1], n = s;
                    break;
                  }

                  if (n && o.label < n[2]) {
                    o.label = n[2], o.ops.push(s);
                    break;
                  }

                  n[2] && o.ops.pop(), o.trys.pop();
                  continue;
              }

              s = t.call(e, o);
            } catch (e) {
              s = [6, e], r = 0;
            } finally {
                a = n = 0;
              }

            if (5 & s[0]) throw s[1];
            return {
              value: s[0] ? s[1] : void 0,
              done: !0
            };
          }([s, p]);
        };
      }
    }

    !function (e) {
      e[e.DT_INVALID = 0] = "DT_INVALID", e[e.DT_FLOAT = 1] = "DT_FLOAT", e[e.DT_DOUBLE = 2] = "DT_DOUBLE", e[e.DT_INT32 = 3] = "DT_INT32", e[e.DT_UINT8 = 4] = "DT_UINT8", e[e.DT_INT16 = 5] = "DT_INT16", e[e.DT_INT8 = 6] = "DT_INT8", e[e.DT_STRING = 7] = "DT_STRING", e[e.DT_COMPLEX64 = 8] = "DT_COMPLEX64", e[e.DT_INT64 = 9] = "DT_INT64", e[e.DT_BOOL = 10] = "DT_BOOL", e[e.DT_QINT8 = 11] = "DT_QINT8", e[e.DT_QUINT8 = 12] = "DT_QUINT8", e[e.DT_QINT32 = 13] = "DT_QINT32", e[e.DT_BFLOAT16 = 14] = "DT_BFLOAT16", e[e.DT_FLOAT_REF = 101] = "DT_FLOAT_REF", e[e.DT_DOUBLE_REF = 102] = "DT_DOUBLE_REF", e[e.DT_INT32_REF = 103] = "DT_INT32_REF", e[e.DT_UINT8_REF = 104] = "DT_UINT8_REF", e[e.DT_INT16_REF = 105] = "DT_INT16_REF", e[e.DT_INT8_REF = 106] = "DT_INT8_REF", e[e.DT_STRING_REF = 107] = "DT_STRING_REF", e[e.DT_COMPLEX64_REF = 108] = "DT_COMPLEX64_REF", e[e.DT_INT64_REF = 109] = "DT_INT64_REF", e[e.DT_BOOL_REF = 110] = "DT_BOOL_REF", e[e.DT_QINT8_REF = 111] = "DT_QINT8_REF", e[e.DT_QUINT8_REF = 112] = "DT_QUINT8_REF", e[e.DT_QINT32_REF = 113] = "DT_QINT32_REF", e[e.DT_BFLOAT16_REF = 114] = "DT_BFLOAT16_REF";
    }(DataType || (DataType = {})), function (e) {
      !function (e) {
        e[e.LEGACY = 0] = "LEGACY", e[e.V1 = 1] = "V1", e[e.V2 = 2] = "V2";
      }(e.CheckpointFormatVersion || (e.CheckpointFormatVersion = {}));
    }(SaverDef || (SaverDef = {}));
    var CUSTOM_OPS = {};

    function registerOp(e, t) {
      var a = {
        tfOpName: e,
        category: "custom",
        inputs: [],
        attrs: [],
        customExecutor: t
      };
      CUSTOM_OPS[e] = a;
    }

    function getRegisteredOp(e) {
      return CUSTOM_OPS[e];
    }

    function deregisterOp(e) {
      delete CUSTOM_OPS[e];
    }

    function getParamValue(e, t, a, r) {
      var n = t.inputParams[e];

      if (n && void 0 !== n.inputIndexStart) {
        var s = n.inputIndexStart,
          o = 0 === n.inputIndexEnd ? void 0 : void 0 === n.inputIndexEnd ? s + 1 : n.inputIndexEnd;
        if ("tensor" === n.type) return getTensor(t.inputNames[n.inputIndexStart], a, r);
        if ("tensors" === n.type) return t.inputNames.slice(s, o).map(function (e) {
          return getTensor(e, a, r);
        });
        var p = Array.prototype.slice.call(getTensor(t.inputNames.slice(s)[0], a, r).dataSync());
        return "number" === n.type ? p[0] : p;
      }

      var u = t.attrParams[e];
      return u && u.value;
    }

    function getTensor(e, t, a) {
      var r = parseNodeName(e),
        n = r[0],
        s = r[1],
        o = a.currentContextIds.find(function (e) {
          return !!t[getNodeNameWithContextId(n, e)];
        });
      return void 0 !== o ? t[getNodeNameWithContextId(n, o)][s] : void 0;
    }

    function getTensorsForCurrentContenxt(e, t, a) {
      return t[getNodeNameWithContextId(e, a.currentContextId)];
    }

    function getNodeNameAndIndex(e, t) {
      var a = parseNodeName(e),
        r = a[0],
        n = a[1];
      return [getNodeNameWithContextId(r, t && t.currentContextId), n];
    }

    function getNodeNameWithContextId(e, t) {
      return t ? e + "-" + t : e;
    }

    function parseNodeName(e) {
      var t = e.lastIndexOf(":");
      return -1 === t ? [e, 0] : [e.substring(0, t), Number(e.substring(t + 1))];
    }

    function split$1(e, t) {
      for (var a = [], r = 0; r < e.length; r += t) a.push(e.slice(r, r + t));

      return a;
    }

    var json = [{
      tfOpName: "Add",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "AddV2",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "AddN",
      category: "arithmetic",
      inputs: [{
        start: 0,
        end: 0,
        name: "tensors",
        type: "tensors"
      }]
    }, {
      tfOpName: "BiasAdd",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "Sub",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "RealDiv",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "Div",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "FloorDiv",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "Mul",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "Maximum",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }]
    }, {
      tfOpName: "Minimum",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }]
    }, {
      tfOpName: "Pow",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "SquaredDifference",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "Mod",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }, {
      tfOpName: "FloorMod",
      category: "arithmetic",
      inputs: [{
        start: 0,
        name: "a",
        type: "tensor"
      }, {
        start: 1,
        name: "b",
        type: "tensor"
      }],
      attrs: [{
        tfName: "T",
        name: "dtype",
        type: "dtype",
        notSupported: !0
      }]
    }],
      arithmetic = Object.freeze({
        json: json
      }),
      json$1 = [{
        tfOpName: "Abs",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Acos",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Asin",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Atan",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Atan2",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "y",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Ceil",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "ClipByValue",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "clip_value_min",
          name: "clipValueMin",
          type: "number"
        }, {
          tfName: "clip_value_max",
          name: "clipValueMax",
          type: "number"
        }]
      }, {
        tfOpName: "Complex",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "real",
          type: "tensor"
        }, {
          start: 1,
          name: "imag",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "ComplexAbs",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Cos",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Cosh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Elu",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Exp",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Floor",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Log",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Imag",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "Tout",
          name: "outputType",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Neg",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Real",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "Tout",
          name: "outputType",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Prelu",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "alpha",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Relu",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Relu6",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "clipValueMin",
          name: "clipValueMin",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "clipValueMax",
          name: "clipValueMax",
          type: "number",
          defaultValue: 6
        }]
      }, {
        tfOpName: "Selu",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Sigmoid",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Sin",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Sinh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Sqrt",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Rsqrt",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Square",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Tan",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Tanh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Sign",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Round",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Expm1",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Log1p",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Reciprocal",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Softplus",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Asinh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Acosh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Atanh",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Erf",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Prod",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axes",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool",
          notSupported: !0
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "LeakyRelu",
        category: "basic_math",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "alpha",
          name: "alpha",
          type: "number",
          defaultValue: .2
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }],
      basicMath = Object.freeze({
        json: json$1
      }),
      json$2 = [{
        tfOpName: "LoopCond",
        category: "control",
        inputs: [{
          start: 0,
          name: "pred",
          type: "tensor"
        }]
      }, {
        tfOpName: "Switch",
        category: "control",
        inputs: [{
          start: 0,
          name: "data",
          type: "tensor"
        }, {
          start: 1,
          name: "pred",
          type: "tensor"
        }]
      }, {
        tfOpName: "Merge",
        category: "control",
        inputs: [{
          start: 0,
          end: 0,
          name: "tensors",
          type: "tensors"
        }]
      }, {
        tfOpName: "Enter",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensor",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "frame_name",
          name: "frameName",
          type: "string"
        }, {
          tfName: "is_constant",
          name: "isConstant",
          type: "bool"
        }]
      }, {
        tfOpName: "Exit",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensor",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "NextIteration",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensor",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "TensorArrayV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "size",
          type: "number"
        }],
        attrs: [{
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "element_shape",
          name: "elementShape",
          type: "shape"
        }, {
          tfName: "dynamic_size",
          name: "dynamicSize",
          type: "bool"
        }, {
          tfName: "clear_after_read",
          name: "clearAfterRead",
          type: "bool"
        }, {
          tfName: "identical_element_shapes",
          name: "identicalElementShapes",
          type: "bool"
        }, {
          tfName: "tensor_array_name",
          name: "name",
          type: "string"
        }]
      }, {
        tfOpName: "TensorArrayWriteV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "index",
          type: "number"
        }, {
          start: 2,
          name: "tensor",
          type: "tensor"
        }, {
          start: 3,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "TensorArrayReadV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "index",
          type: "number"
        }, {
          start: 2,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "dtype",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "TensorArrayGatherV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "indices",
          type: "number[]"
        }, {
          start: 2,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "element_shape",
          name: "elementShape",
          type: "shape"
        }]
      }, {
        tfOpName: "TensorArrayScatterV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "indices",
          type: "number[]"
        }, {
          start: 2,
          name: "tensor",
          type: "tensor"
        }, {
          start: 3,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "TensorArrayConcatV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "element_shape_except0",
          name: "elementShapeExcept0",
          type: "shape",
          notSupported: !0
        }]
      }, {
        tfOpName: "TensorArraySplitV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "tensor",
          type: "tensor"
        }, {
          start: 2,
          name: "lengths",
          type: "number[]"
        }, {
          start: 3,
          name: "flowIn",
          type: "number"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "TensorArraySizeV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }, {
          start: 1,
          name: "flowIn",
          type: "number"
        }]
      }, {
        tfOpName: "TensorArrayCloseV3",
        category: "control",
        inputs: [{
          start: 0,
          name: "tensorArrayId",
          type: "number"
        }]
      }],
      control = Object.freeze({
        json: json$2
      }),
      json$3 = [{
        tfOpName: "AvgPool",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }, {
          tfName: "ksize",
          name: "kernelSize",
          type: "number[]"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "MaxPool",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }, {
          tfName: "ksize",
          name: "kernelSize",
          type: "number[]"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "AvgPool3D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }, {
          tfName: "ksize",
          name: "kernelSize",
          type: "number[]"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "MaxPool3D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }, {
          tfName: "ksize",
          name: "kernelSize",
          type: "number[]"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Conv1D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }],
        attrs: [{
          tfName: "stride",
          name: "stride",
          type: "number"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NWC"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "dilation",
          name: "dilation",
          type: "number",
          defaultValue: 1
        }]
      }, {
        tfOpName: "Conv2D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "useCudnnOnGpu",
          name: "useCudnnOnGpu",
          type: "bool"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NHWC"
        }, {
          tfName: "dilations",
          name: "dilations",
          type: "number[]"
        }]
      }, {
        tfOpName: "_FusedConv2D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }, {
          start: 2,
          end: 0,
          name: "args",
          type: "tensors"
        }],
        attrs: [{
          tfName: "num_args",
          name: "numArgs",
          type: "number"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "explicit_paddings",
          name: "explicitPaddings",
          type: "number[]",
          defaultValue: []
        }, {
          tfName: "use_cudnn_on_gpu",
          name: "useCudnnOnGpu",
          type: "bool",
          defaultValue: !0
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NHWC"
        }, {
          tfName: "dilations",
          name: "dilations",
          type: "number[]",
          defaultValue: [1, 1, 1, 1]
        }, {
          tfName: "fused_ops",
          name: "fusedOps",
          type: "string[]",
          defaultValue: []
        }, {
          tfName: "epsilon",
          name: "epsilon",
          type: "number",
          defaultValue: 1e-4
        }]
      }, {
        tfOpName: "Conv2DBackpropInput",
        category: "convolution",
        inputs: [{
          start: 2,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }, {
          start: 0,
          name: "outputShape",
          type: "number[]"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }]
      }, {
        tfOpName: "DepthwiseConv2d",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "input",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NHWC"
        }, {
          tfName: "dilations",
          name: "dilations",
          type: "number[]"
        }]
      }, {
        tfOpName: "DepthwiseConv2dNative",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "input",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NHWC"
        }, {
          tfName: "dilations",
          name: "dilations",
          type: "number[]"
        }]
      }, {
        tfOpName: "Conv3D",
        category: "convolution",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "filter",
          type: "tensor"
        }],
        attrs: [{
          tfName: "strides",
          name: "strides",
          type: "number[]"
        }, {
          tfName: "padding",
          name: "pad",
          type: "string"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          defaultValue: "NHWC"
        }, {
          tfName: "dilations",
          name: "dilations",
          type: "number[]"
        }]
      }],
      convolution = Object.freeze({
        json: json$3
      }),
      json$4 = [{
        tfOpName: "Fill",
        category: "creation",
        inputs: [{
          start: 0,
          name: "shape",
          type: "number[]"
        }, {
          start: 1,
          name: "value",
          type: "number"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "LinSpace",
        category: "creation",
        inputs: [{
          start: 0,
          name: "start",
          type: "number"
        }, {
          start: 1,
          name: "stop",
          type: "number"
        }, {
          start: 2,
          name: "num",
          type: "number"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "OneHot",
        category: "creation",
        inputs: [{
          start: 0,
          name: "indices",
          type: "tensor"
        }, {
          start: 1,
          name: "depth",
          type: "number"
        }, {
          start: 2,
          name: "onValue",
          type: "number",
          defaultValue: 1
        }, {
          start: 3,
          name: "offValue",
          type: "number",
          defaultValue: 0
        }],
        attrs: [{
          tfName: "axis",
          name: "axis",
          type: "number",
          notSupported: !0
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Ones",
        category: "creation",
        inputs: [{
          start: 0,
          name: "shape",
          type: "number[]"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "OnesLike",
        category: "creation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "RandomUniform",
        category: "creation",
        inputs: [{
          start: 0,
          name: "shape",
          type: "number[]"
        }],
        attrs: [{
          tfName: "minval",
          name: "minval",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "maxval",
          name: "maxval",
          type: "number",
          defaultValue: 1
        }, {
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "seed",
          name: "seed",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "seed2",
          name: "seed2",
          type: "number",
          defaultValue: 0,
          notSupported: !0
        }, {
          tfName: "T",
          name: "T",
          type: "number",
          notSupported: !0
        }]
      }, {
        tfOpName: "Range",
        category: "creation",
        inputs: [{
          start: 0,
          name: "start",
          type: "number"
        }, {
          start: 1,
          name: "stop",
          type: "number"
        }, {
          start: 2,
          name: "step",
          type: "number",
          defaultValue: 0
        }],
        attrs: [{
          tfName: "Tidx",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "TruncatedNormal",
        category: "creation",
        inputs: [{
          start: 0,
          name: "shape",
          type: "number[]"
        }],
        attrs: [{
          tfName: "means",
          name: "mean",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "stddev",
          name: "stdDev",
          type: "number",
          defaultValue: 1
        }, {
          tfName: "seed",
          name: "seed",
          type: "number"
        }, {
          tfName: "seed2",
          name: "seed2",
          type: "number",
          defaultValue: 0,
          notSupported: !0
        }, {
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "T",
          name: "T",
          type: "number",
          notSupported: !0
        }]
      }, {
        tfOpName: "Zeros",
        category: "creation",
        inputs: [{
          start: 0,
          name: "shape",
          type: "number[]"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "ZerosLike",
        category: "creation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "Multinomial",
        category: "creation",
        inputs: [{
          start: 0,
          name: "logits",
          type: "tensor"
        }, {
          start: 1,
          name: "numSamples",
          type: "number"
        }],
        attrs: [{
          tfName: "seed",
          name: "seed",
          type: "number"
        }, {
          tfName: "seed2",
          name: "seed2",
          type: "number"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype"
        }, {
          tfName: "output_dtype",
          name: "output_dtype",
          type: "dtype"
        }]
      }],
      creation = Object.freeze({
        json: json$4
      }),
      json$5 = [{
        tfOpName: "NonMaxSuppressionV2",
        category: "dynamic",
        inputs: [{
          start: 0,
          name: "boxes",
          type: "tensor"
        }, {
          start: 1,
          name: "scores",
          type: "tensor"
        }, {
          start: 2,
          name: "maxOutputSize",
          type: "number"
        }, {
          start: 3,
          name: "iouThreshold",
          type: "number"
        }]
      }, {
        tfOpName: "NonMaxSuppressionV3",
        category: "dynamic",
        inputs: [{
          start: 0,
          name: "boxes",
          type: "tensor"
        }, {
          start: 1,
          name: "scores",
          type: "tensor"
        }, {
          start: 2,
          name: "maxOutputSize",
          type: "number"
        }, {
          start: 3,
          name: "iouThreshold",
          type: "number"
        }, {
          start: 4,
          name: "scoreThreshold",
          type: "number"
        }]
      }, {
        tfOpName: "Where",
        category: "dynamic",
        inputs: [{
          start: 0,
          name: "condition",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "ListDiff",
        category: "dynamic",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "y",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }],
      dynamic = Object.freeze({
        json: json$5
      }),
      json$6 = [{
        tfOpName: "TopKV2",
        category: "evaluation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "k",
          type: "number"
        }],
        attrs: [{
          tfName: "sorted",
          name: "sorted",
          type: "bool"
        }]
      }],
      evaluation = Object.freeze({
        json: json$6
      }),
      json$7 = [{
        tfOpName: "PlaceholderWithDefault",
        category: "graph",
        inputs: [{
          start: 0,
          name: "default",
          type: "tensor"
        }],
        attrs: [{
          tfName: "shape",
          name: "shape",
          type: "shape"
        }, {
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "Placeholder",
        category: "graph",
        attrs: [{
          tfName: "shape",
          name: "shape",
          type: "shape"
        }, {
          tfName: "dtype",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "Const",
        category: "graph"
      }, {
        tfOpName: "Identity",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "IdentityN",
        category: "graph",
        inputs: [{
          start: 0,
          end: 0,
          name: "x",
          type: "tensors"
        }]
      }, {
        tfOpName: "Snapshot",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "Rank",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "Size",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "Shape",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "ShapeN",
        category: "graph",
        inputs: [{
          start: 0,
          end: 0,
          name: "x",
          type: "tensors"
        }]
      }, {
        tfOpName: "Print",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "data",
          type: "tensors"
        }],
        attrs: [{
          tfName: "message",
          name: "message",
          type: "string"
        }, {
          tfName: "first_n",
          name: "firstN",
          type: "number",
          notSupported: !0
        }, {
          tfName: "summarize",
          name: "summarize",
          type: "number",
          defaultValue: 3
        }]
      }, {
        tfOpName: "NoOp",
        category: "graph",
        inputs: []
      }, {
        tfOpName: "StopGradient",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "FakeQuantWithMinMaxVars",
        category: "graph",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "min",
          name: "min",
          type: "number"
        }, {
          tfName: "max",
          name: "max",
          type: "number"
        }]
      }],
      graph = Object.freeze({
        json: json$7
      }),
      json$8 = [{
        tfOpName: "ResizeBilinear",
        category: "image",
        inputs: [{
          start: 0,
          name: "images",
          type: "tensor"
        }, {
          start: 1,
          name: "size",
          type: "number[]"
        }],
        attrs: [{
          tfName: "align_corners",
          name: "alignCorners",
          type: "bool"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "ResizeNearestNeighbor",
        category: "image",
        inputs: [{
          start: 0,
          name: "images",
          type: "tensor"
        }, {
          start: 1,
          name: "size",
          type: "number[]"
        }],
        attrs: [{
          tfName: "align_corners",
          name: "alignCorners",
          type: "bool"
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "CropAndResize",
        category: "image",
        inputs: [{
          start: 0,
          name: "image",
          type: "tensor"
        }, {
          start: 1,
          name: "boxes",
          type: "tensor"
        }, {
          start: 2,
          name: "boxInd",
          type: "tensor"
        }, {
          start: 3,
          name: "cropSize",
          type: "number[]"
        }],
        attrs: [{
          tfName: "method",
          name: "method",
          type: "string"
        }, {
          tfName: "extrapolation_value",
          name: "extrapolationValue",
          type: "number"
        }]
      }],
      image$1 = Object.freeze({
        json: json$8
      }),
      json$9 = [{
        tfOpName: "Equal",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "NotEqual",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Greater",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "GreaterEqual",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Less",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "LessEqual",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "LogicalAnd",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "LogicalNot",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "LogicalOr",
        category: "logical",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Select",
        category: "logical",
        inputs: [{
          start: 0,
          name: "condition",
          type: "tensor"
        }, {
          start: 1,
          name: "a",
          type: "tensor"
        }, {
          start: 2,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }],
      logical = Object.freeze({
        json: json$9
      }),
      json$10 = [{
        tfOpName: "MatMul",
        category: "matrices",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "transpose_a",
          name: "transposeA",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "transpose_b",
          name: "transposeB",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "BatchMatMul",
        category: "matrices",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "adj_x",
          name: "transposeA",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "adj_y",
          name: "transposeB",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "BatchMatMulV2",
        category: "matrices",
        inputs: [{
          start: 0,
          name: "a",
          type: "tensor"
        }, {
          start: 1,
          name: "b",
          type: "tensor"
        }],
        attrs: [{
          tfName: "adj_x",
          name: "transposeA",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "adj_y",
          name: "transposeB",
          type: "bool",
          defaultValue: !1
        }, {
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }, {
        tfOpName: "Transpose",
        category: "matrices",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "perm",
          type: "number[]"
        }],
        attrs: [{
          tfName: "T",
          name: "dtype",
          type: "dtype",
          notSupported: !0
        }]
      }],
      matrices = Object.freeze({
        json: json$10
      }),
      json$11 = [{
        tfOpName: "FusedBatchNorm",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "scale",
          type: "tensor"
        }, {
          start: 2,
          name: "offset",
          type: "tensor"
        }, {
          start: 3,
          name: "mean",
          type: "tensor"
        }, {
          start: 4,
          name: "variance",
          type: "tensor"
        }],
        attrs: [{
          tfName: "epsilon",
          name: "epsilon",
          type: "number",
          defaultValue: .001
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }]
      }, {
        tfOpName: "FusedBatchNormV2",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "scale",
          type: "tensor"
        }, {
          start: 2,
          name: "offset",
          type: "tensor"
        }, {
          start: 3,
          name: "mean",
          type: "tensor"
        }, {
          start: 4,
          name: "variance",
          type: "tensor"
        }],
        attrs: [{
          tfName: "epsilon",
          name: "epsilon",
          type: "number",
          defaultValue: .001
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }]
      }, {
        tfOpName: "FusedBatchNormV3",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "scale",
          type: "tensor"
        }, {
          start: 2,
          name: "offset",
          type: "tensor"
        }, {
          start: 3,
          name: "mean",
          type: "tensor"
        }, {
          start: 4,
          name: "variance",
          type: "tensor"
        }],
        attrs: [{
          tfName: "epsilon",
          name: "epsilon",
          type: "number",
          defaultValue: .001
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string",
          notSupported: !0
        }]
      }, {
        tfOpName: "LRN",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "depth_radius",
          name: "radius",
          type: "number",
          defaultValue: 5
        }, {
          tfName: "bias",
          name: "bias",
          type: "number",
          defaultValue: 1
        }, {
          tfName: "alpha",
          name: "alpha",
          type: "number",
          defaultValue: 1
        }, {
          tfName: "beta",
          name: "beta",
          type: "number",
          defaultValue: .5
        }]
      }, {
        tfOpName: "Softmax",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "LogSoftmax",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "SparseToDense",
        category: "normalization",
        inputs: [{
          start: 0,
          name: "sparseIndices",
          type: "tensor"
        }, {
          start: 1,
          name: "outputShape",
          type: "number[]"
        }, {
          start: 2,
          name: "sparseValues",
          type: "tensor"
        }, {
          start: 3,
          name: "defaultValue",
          type: "tensor"
        }],
        attrs: [{
          tfName: "validate_indices",
          name: "validateIndices",
          type: "bool",
          defaultValue: !0,
          notSupported: !0
        }]
      }],
      normalization = Object.freeze({
        json: json$11
      }),
      json$12 = [{
        tfOpName: "Max",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "Mean",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "Min",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "Sum",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "All",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "Any",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }, {
        tfOpName: "ArgMax",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number"
        }]
      }, {
        tfOpName: "ArgMin",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number"
        }]
      }, {
        tfOpName: "Prod",
        category: "reduction",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }],
        attrs: [{
          tfName: "keep_dims",
          name: "keepDims",
          type: "bool"
        }]
      }],
      reduction = Object.freeze({
        json: json$12
      }),
      json$13 = [{
        tfOpName: "ConcatV2",
        category: "slice_join",
        inputs: [{
          start: 0,
          end: -1,
          name: "tensors",
          type: "tensors"
        }, {
          start: -1,
          name: "axis",
          type: "number"
        }]
      }, {
        tfOpName: "Concat",
        category: "slice_join",
        inputs: [{
          start: 1,
          end: 0,
          name: "tensors",
          type: "tensors"
        }, {
          start: 0,
          name: "axis",
          type: "number"
        }]
      }, {
        tfOpName: "GatherV2",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "indices",
          type: "tensor"
        }, {
          start: 2,
          name: "axis",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "Gather",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "indices",
          type: "tensor"
        }],
        attrs: [{
          tfName: "axis",
          name: "axis",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "validate_indices",
          name: "validateIndices",
          type: "bool",
          notSupported: !0
        }]
      }, {
        tfOpName: "Reverse",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "dims",
          type: "bool",
          notSupported: !0
        }]
      }, {
        tfOpName: "ReverseV2",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number[]"
        }]
      }, {
        tfOpName: "Slice",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "begin",
          type: "number[]"
        }, {
          start: 2,
          name: "size",
          type: "number[]"
        }]
      }, {
        tfOpName: "StridedSlice",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "begin",
          type: "number[]"
        }, {
          start: 2,
          name: "end",
          type: "number[]"
        }, {
          start: 3,
          name: "strides",
          type: "number[]"
        }],
        attrs: [{
          tfName: "begin_mask",
          name: "beginMask",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "end_mask",
          name: "endMask",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "new_axis_mask",
          name: "newAxisMask",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "ellipsis_mask",
          name: "ellipsisMask",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "shrink_axis_mask",
          name: "shrinkAxisMask",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "Pack",
        category: "slice_join",
        inputs: [{
          start: 0,
          end: 0,
          name: "tensors",
          type: "tensors"
        }],
        attrs: [{
          tfName: "axis",
          name: "axis",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "Unpack",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "tensor",
          type: "tensor"
        }],
        attrs: [{
          tfName: "axis",
          name: "axis",
          type: "number",
          defaultValue: 0
        }, {
          tfName: "num",
          name: "num",
          type: "number",
          defaultValue: 0,
          notSupported: !0
        }]
      }, {
        tfOpName: "Tile",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "reps",
          type: "number[]"
        }]
      }, {
        tfOpName: "Split",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "axis",
          type: "number",
          defaultValue: 0
        }, {
          start: 1,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "num_split",
          name: "numOrSizeSplits",
          type: "number",
          defaultValue: 1
        }]
      }, {
        tfOpName: "SplitV",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "numOrSizeSplits",
          type: "number[]"
        }, {
          start: 2,
          name: "axis",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "ScatterNd",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "indices",
          type: "tensor"
        }, {
          start: 1,
          name: "values",
          type: "tensor"
        }, {
          start: 2,
          name: "shape",
          type: "number[]"
        }]
      }, {
        tfOpName: "GatherNd",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "indices",
          type: "tensor"
        }]
      }, {
        tfOpName: "SparseToDense",
        category: "slice_join",
        inputs: [{
          start: 0,
          name: "sparseIndices",
          type: "tensor"
        }, {
          start: 1,
          name: "outputShape",
          type: "number[]"
        }, {
          start: 2,
          name: "sparseValues",
          type: "tensor"
        }, {
          start: 3,
          name: "defaultValue",
          type: "tensor"
        }],
        attrs: [{
          tfName: "validate_indices",
          name: "validateIndices",
          type: "bool",
          defaultValue: !1,
          notSupported: !0
        }]
      }],
      sliceJoin = Object.freeze({
        json: json$13
      }),
      json$14 = [{
        tfOpName: "FFT",
        category: "spectral",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "IFFT",
        category: "spectral",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }]
      }, {
        tfOpName: "RFFT",
        category: "spectral",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "fft_length",
          type: "number",
          notSupported: !0
        }]
      }, {
        tfOpName: "IRFFT",
        category: "spectral",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "fft_length",
          type: "number",
          notSupported: !0
        }]
      }],
      spectral = Object.freeze({
        json: json$14
      }),
      json$15 = [{
        tfOpName: "Cast",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "SrcT",
          name: "sdtype",
          type: "dtype",
          notSupported: !0
        }, {
          tfName: "DstT",
          name: "dtype",
          type: "dtype"
        }]
      }, {
        tfOpName: "ExpandDims",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "axis",
          type: "number"
        }]
      }, {
        tfOpName: "Pad",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "padding",
          type: "number[]"
        }],
        attrs: [{
          tfName: "constant_value",
          name: "constantValue",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "PadV2",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "padding",
          type: "number[]"
        }, {
          start: 2,
          name: "constantValue",
          type: "number",
          defaultValue: 0
        }]
      }, {
        tfOpName: "Reshape",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "shape",
          type: "number[]"
        }]
      }, {
        tfOpName: "Squeeze",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "axis",
          tfDeprecatedName: "squeeze_dims",
          name: "axis",
          type: "number[]"
        }]
      }, {
        tfOpName: "SpaceToBatchND",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "blockShape",
          type: "number[]"
        }, {
          start: 2,
          name: "paddings",
          type: "number[]"
        }]
      }, {
        tfOpName: "BatchToSpaceND",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }, {
          start: 1,
          name: "blockShape",
          type: "number[]"
        }, {
          start: 2,
          name: "crops",
          type: "number[]"
        }]
      }, {
        tfOpName: "DepthToSpace",
        category: "transformation",
        inputs: [{
          start: 0,
          name: "x",
          type: "tensor"
        }],
        attrs: [{
          tfName: "block_size",
          name: "blockSize",
          type: "number"
        }, {
          tfName: "data_format",
          name: "dataFormat",
          type: "string"
        }]
      }],
      transformation = Object.freeze({
        json: json$15
      }),
      OperationMapper = function () {
        function e() {
          var e = [arithmetic, basicMath, control, convolution, creation, dynamic, evaluation, logical, image$1, graph, matrices, normalization, reduction, sliceJoin, spectral, transformation],
            t = [].concat.apply([], e.map(function (e) {
              return e.json;
            }));
          this.opMappers = t.reduce(function (e, t) {
            return e[t.tfOpName] = t, e;
          }, {});
        }

        return Object.defineProperty(e, "Instance", {
          get: function () {
            return this._instance || (this._instance = new this());
          },
          enumerable: !0,
          configurable: !0
        }), e.prototype.transformGraph = function (e) {
          var t = this,
            a = [],
            r = [],
            n = e.node.reduce(function (e, n) {
              return e[n.name] = t.mapNode(n), "Placeholder" === n.op && a.push(e[n.name]), "Const" === n.op && r.push(e[n.name]), e;
            }, {}),
            s = [],
            o = [],
            p = Object.keys(n);
          return p.forEach(function (e) {
            var t = n[e];
            t.inputNames.forEach(function (e) {
              var a = getNodeNameAndIndex(e)[0];
              t.inputs.push(n[a]), n[a].children.push(t);
            }), 0 === t.inputs.length && s.push(t);
          }), p.forEach(function (e) {
            var t = n[e];
            0 === t.children.length && o.push(t);
          }), {
            nodes: n,
            inputs: s,
            outputs: o,
            weights: r,
            placeholders: a
          };
        }, e.prototype.mapNode = function (e) {
          var t = getRegisteredOp(e.op) || this.opMappers[e.op] || {};
          null == e.attr && (e.attr = {});
          var a = {
            name: e.name,
            op: e.op,
            category: t.category,
            inputNames: (e.input || []).map(function (e) {
              return e.startsWith("^") ? e.substr(1) : e;
            }),
            inputs: [],
            children: [],
            inputParams: {},
            attrParams: {},
            rawAttrs: e.attr
          };
          return null != t.inputs && (a.inputParams = t.inputs.reduce(function (e, t) {
            return e[t.name] = {
              type: t.type,
              inputIndexStart: t.start,
              inputIndexEnd: t.end
            }, e;
          }, {})), null != t.attrs && (a.attrParams = t.attrs.reduce(function (t, a) {
            var r = a.type,
              n = void 0;

            switch (a.type) {
              case "string":
                void 0 === (n = getStringParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getStringParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "string[]":
                void 0 === (n = getStringArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getStringArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "number":
                void 0 === (n = getNumberParam(e.attr, a.tfName, a.defaultValue || 0)) && a.tfDeprecatedName && (n = getNumberParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "number[]":
                void 0 === (n = getNumericArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getNumericArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "bool":
                void 0 === (n = getBoolParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getBoolParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "bool[]":
                void 0 === (n = getBoolArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getBoolArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "shape":
                void 0 === (n = getTensorShapeParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getTensorShapeParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "shape[]":
                void 0 === (n = getTensorShapeArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getTensorShapeArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "dtype":
                void 0 === (n = getDtypeParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getDtypeParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "dtype[]":
                void 0 === (n = getDtypeArrayParam(e.attr, a.tfName, a.defaultValue)) && a.tfDeprecatedName && (n = getDtypeArrayParam(e.attr, a.tfDeprecatedName, a.defaultValue));
                break;

              case "tensor":
              case "tensors":
                break;

              default:
                throw new Error("Unsupported param type: " + a.type + " for op: " + e.op);
            }

            return t[a.name] = {
              value: n,
              type: r
            }, t;
          }, {})), a;
        }, e;
      }();

    function decodeBase64(e) {
      var t = (0, _tfjsCore.env)().global;
      if (void 0 !== t.atob) return t.atob(e);
      if ("undefined" != typeof Buffer) return new Buffer(e, "base64").toString();
      throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()");
    }

    function parseStringParam(e, t) {
      var a = Array.isArray(e) ? String.fromCharCode.apply(null, e) : decodeBase64(e);
      return t ? a : a.toLowerCase();
    }

    function getStringParam(e, t, a, r) {
      void 0 === r && (r = !1);
      var n = e[t];
      return null != n ? parseStringParam(n.s, r) : a;
    }

    function getBoolParam(e, t, a) {
      var r = e[t];
      return r ? r.b : a;
    }

    function getNumberParam(e, t, a) {
      var r = e[t] || {},
        n = null != r.i ? r.i : null != r.f ? r.f : a;
      return "number" == typeof n ? n : parseInt(n, 10);
    }

    function parseDtypeParam(e) {
      switch ("string" == typeof e && (e = DataType[e]), e) {
        case DataType.DT_FLOAT:
          return "float32";

        case DataType.DT_INT32:
        case DataType.DT_INT64:
          return "int32";

        case DataType.DT_BOOL:
          return "bool";

        case DataType.DT_DOUBLE:
          return "float32";

        case DataType.DT_STRING:
          return "string";

        default:
          return null;
      }
    }

    function getDtypeParam(e, t, a) {
      var r = e[t];
      return r && r.type ? parseDtypeParam(r.type) : a;
    }

    function getDtypeArrayParam(e, t, a) {
      var r = e[t];
      return r && r.list && r.list.type ? r.list.type.map(function (e) {
        return parseDtypeParam(e);
      }) : a;
    }

    function parseTensorShapeParam(e) {
      if (!e.unknownRank) return null != e.dim ? e.dim.map(function (e) {
        return "number" == typeof e.size ? e.size : parseInt(e.size, 10);
      }) : [];
    }

    function getTensorShapeParam(e, t, a) {
      var r = e[t];
      return r && r.shape ? parseTensorShapeParam(r.shape) : a;
    }

    function getNumericArrayParam(e, t, a) {
      var r = e[t];
      return r ? ((r.list.f && r.list.f.length ? r.list.f : r.list.i) || []).map(function (e) {
        return "number" == typeof e ? e : parseInt(e, 10);
      }) : a;
    }

    function getStringArrayParam(e, t, a, r) {
      void 0 === r && (r = !1);
      var n = e[t];
      return n && n.list && n.list.s ? n.list.s.map(function (e) {
        return parseStringParam(e, r);
      }) : a;
    }

    function getTensorShapeArrayParam(e, t, a) {
      var r = e[t];
      return r && r.list && r.list.shape ? r.list.shape.map(function (e) {
        return parseTensorShapeParam(e);
      }) : a;
    }

    function getBoolArrayParam(e, t, a) {
      var r = e[t];
      return r && r.list && r.list.b ? r.list.b : a;
    }

    var NodeValueImpl = function () {
      function e(e, t, a) {
        var r = this;
        this.node = e, this.tensorMap = t, this.context = a, this.inputs = [], this.attrs = {}, this.inputs = e.inputNames.map(function (e) {
          return r.getInput(e);
        }), null != e.rawAttrs && (this.attrs = Object.keys(e.rawAttrs).reduce(function (e, t) {
          return e[t] = r.getAttr(t), e;
        }, {}));
      }

      return e.prototype.getInput = function (e) {
        return getTensor(e, this.tensorMap, this.context);
      }, e.prototype.getAttr = function (e, t) {
        var a = this.node.rawAttrs[e];
        if (null != a.tensor) return getTensor(e, this.tensorMap, this.context);
        if (null != a.i || null != a.f) return getNumberParam(this.node.rawAttrs, e, t);
        if (null != a.s) return getStringParam(this.node.rawAttrs, e, t);
        if (null != a.b) return getBoolParam(this.node.rawAttrs, e, t);
        if (null != a.shape) return getTensorShapeParam(this.node.rawAttrs, e, t);
        if (null != a.type) return getDtypeParam(this.node.rawAttrs, e, t);

        if (null != a.list) {
          if (null != a.list.i || null != a.list.f) return getNumericArrayParam(this.node.rawAttrs, e, t);
          if (null != a.list.s) return getStringArrayParam(this.node.rawAttrs, e, t);
          if (null != a.list.shape) return getTensorShapeArrayParam(this.node.rawAttrs, e, t);
          if (null != a.list.b) return getBoolArrayParam(this.node.rawAttrs, e, t);
          if (null != a.list.type) return getDtypeArrayParam(this.node.rawAttrs, e, t);
        }

        return t;
      }, e;
    }(),
      executeOp = function (e, t, a) {
        switch (e.op) {
          case "BiasAdd":
          case "AddV2":
          case "Add":
            return [(0, _tfjsCore.add)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "AddN":
            return [(0, _tfjsCore.addN)(getParamValue("tensors", e, t, a))];

          case "FloorMod":
          case "Mod":
            return [(0, _tfjsCore.mod)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Mul":
            return [(0, _tfjsCore.mul)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "RealDiv":
          case "Div":
            return [(0, _tfjsCore.div)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "FloorDiv":
            return [(0, _tfjsCore.floorDiv)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Sub":
            return [(0, _tfjsCore.sub)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Minimum":
            return [(0, _tfjsCore.minimum)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Maximum":
            return [(0, _tfjsCore.maximum)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Pow":
            return [(0, _tfjsCore.pow)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "SquaredDifference":
            return [(0, _tfjsCore.squaredDifference)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$1 = function (e, t, a) {
        switch (e.op) {
          case "Abs":
          case "ComplexAbs":
            return [(0, _tfjsCore.abs)(getParamValue("x", e, t, a))];

          case "Acos":
            return [(0, _tfjsCore.acos)(getParamValue("x", e, t, a))];

          case "Acosh":
            return [(0, _tfjsCore.acosh)(getParamValue("x", e, t, a))];

          case "Asin":
            return [(0, _tfjsCore.asin)(getParamValue("x", e, t, a))];

          case "Asinh":
            return [(0, _tfjsCore.asinh)(getParamValue("x", e, t, a))];

          case "Atan":
            return [(0, _tfjsCore.atan)(getParamValue("x", e, t, a))];

          case "Atan2":
            return [(0, _tfjsCore.atan2)(getParamValue("x", e, t, a), getParamValue("y", e, t, a))];

          case "Atanh":
            return [(0, _tfjsCore.atanh)(getParamValue("x", e, t, a))];

          case "Ceil":
            return [(0, _tfjsCore.ceil)(getParamValue("x", e, t, a))];

          case "Complex":
            return [(0, _tfjsCore.complex)(getParamValue("real", e, t, a), getParamValue("imag", e, t, a))];

          case "Cos":
            return [(0, _tfjsCore.cos)(getParamValue("x", e, t, a))];

          case "Cosh":
            return [(0, _tfjsCore.cosh)(getParamValue("x", e, t, a))];

          case "Elu":
            return [(0, _tfjsCore.elu)(getParamValue("x", e, t, a))];

          case "Erf":
            return [(0, _tfjsCore.erf)(getParamValue("x", e, t, a))];

          case "Exp":
            return [(0, _tfjsCore.exp)(getParamValue("x", e, t, a))];

          case "Expm1":
            return [(0, _tfjsCore.expm1)(getParamValue("x", e, t, a))];

          case "Floor":
            return [(0, _tfjsCore.floor)(getParamValue("x", e, t, a))];

          case "Log":
            return [(0, _tfjsCore.log)(getParamValue("x", e, t, a))];

          case "Log1p":
            return [(0, _tfjsCore.log1p)(getParamValue("x", e, t, a))];

          case "Imag":
            return [(0, _tfjsCore.imag)(getParamValue("x", e, t, a))];

          case "Neg":
            return [(0, _tfjsCore.neg)(getParamValue("x", e, t, a))];

          case "Reciprocal":
            return [(0, _tfjsCore.reciprocal)(getParamValue("x", e, t, a))];

          case "Real":
            return [(0, _tfjsCore.real)(getParamValue("x", e, t, a))];

          case "Relu":
            return [(0, _tfjsCore.relu)(getParamValue("x", e, t, a))];

          case "Round":
            return [(0, _tfjsCore.round)(getParamValue("x", e, t, a))];

          case "Selu":
            return [(0, _tfjsCore.selu)(getParamValue("x", e, t, a))];

          case "Sigmoid":
            return [(0, _tfjsCore.sigmoid)(getParamValue("x", e, t, a))];

          case "Sin":
            return [(0, _tfjsCore.sin)(getParamValue("x", e, t, a))];

          case "Sign":
            return [(0, _tfjsCore.sign)(getParamValue("x", e, t, a))];

          case "Sinh":
            return [(0, _tfjsCore.sinh)(getParamValue("x", e, t, a))];

          case "Softplus":
            return [(0, _tfjsCore.softplus)(getParamValue("x", e, t, a))];

          case "Sqrt":
            return [(0, _tfjsCore.sqrt)(getParamValue("x", e, t, a))];

          case "Square":
            return [(0, _tfjsCore.square)(getParamValue("x", e, t, a))];

          case "Tanh":
            return [(0, _tfjsCore.tanh)(getParamValue("x", e, t, a))];

          case "Tan":
            return [(0, _tfjsCore.tan)(getParamValue("x", e, t, a))];

          case "Relu6":
          case "ClipByValue":
            return [(0, _tfjsCore.clipByValue)(getParamValue("x", e, t, a), getParamValue("clipValueMin", e, t, a), getParamValue("clipValueMax", e, t, a))];

          case "Rsqrt":
            return [(0, _tfjsCore.rsqrt)(getTensor(e.inputNames[0], t, a))];

          case "Prod":
            return [(0, _tfjsCore.prod)(getParamValue("x", e, t, a), getParamValue("axes", e, t, a))];

          case "LeakyRelu":
            return [(0, _tfjsCore.leakyRelu)(getParamValue("x", e, t, a), getParamValue("alpha", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      TensorArray = function () {
        function e(t, a, r, n, s, o, p) {
          this.name = t, this.dtype = a, this.maxSize = r, this.elementShape = n, this.identicalElementShapes = s, this.dynamicSize = o, this.clearAfterRead = p, this.tensors = [], this.closed_ = !1, this.id = e.nextId++;
        }

        return Object.defineProperty(e.prototype, "closed", {
          get: function () {
            return this.closed_;
          },
          enumerable: !0,
          configurable: !0
        }), e.prototype.clearAndClose = function () {
          this.tensors.forEach(function (e) {
            return e.tensor.dispose();
          }), this.tensors = [], this.closed_ = !0;
        }, e.prototype.size = function () {
          return this.tensors.length;
        }, e.prototype.read = function (e) {
          if (this.closed_) throw new Error("TensorArray " + this.name + " has already been closed.");
          if (e < 0 || e >= this.tensors.length) throw new Error("Tried to read from index " + e + ", but array size is: " + this.tensors.length);
          var t = this.tensors[e];
          if (t.cleared) throw new Error("TensorArray " + this.name + ": Could not read index " + e + " twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).");
          return this.clearAfterRead && (t.cleared = !0), t.read = !0, t.tensor;
        }, e.prototype.readMany = function (e) {
          var t = this;
          return e.map(function (e) {
            return t.read(e);
          });
        }, e.prototype.write = function (e, t) {
          if (this.closed_) throw new Error("TensorArray " + this.name + " has already been closed.");
          if (e < 0 || !this.dynamicSize && e >= this.maxSize) throw new Error("Tried to write to index " + e + ", but array is not resizeable and size is: " + this.maxSize);
          var a = this.tensors[e] || {};
          if (t.dtype !== this.dtype) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ",\n          because the value dtype is " + t.dtype + ", but TensorArray dtype is " + this.dtype + ".");
          if (0 !== this.size() || null != this.elementShape && 0 !== this.elementShape.length || (this.elementShape = t.shape), this.assertShapesMatchAllowUndefinedSize(this.elementShape, t.shape, "TensorArray " + this.name + ": Could not write to TensorArray index " + e + "."), a && a.read) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ", because it has already been read.");
          if (a && a.written) throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + e + ", because it has already been written.");
          a.tensor = t, a.written = !0, this.tensors[e] = a;
        }, e.prototype.writeMany = function (e, t) {
          var a = this;
          if (e.length !== t.length) throw new Error("TensorArray " + this.name + ": could not write multiple tensors,because the index size: " + e.length + " is not the same as tensors size: " + t.length + ".");
          e.forEach(function (e, r) {
            return a.write(e, t[r]);
          });
        }, e.prototype.gather = function (e, t) {
          if (t && t !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but gather requested dtype " + t);

          if (!e) {
            e = [];

            for (var a = 0; a < this.size(); a++) e.push(a);
          }

          if (0 === e.length) return (0, _tfjsCore.tensor)([], [0].concat(this.elementShape));
          var r = this.readMany(e);
          return this.assertShapesMatchAllowUndefinedSize(this.elementShape, r[0].shape, "TensorArray shape mismatch: "), (0, _tfjsCore.stack)(r, 0);
        }, e.prototype.concat = function (e) {
          if (e && e !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but concat requested dtype " + e);
          if (0 === this.size()) return (0, _tfjsCore.tensor)([], [0].concat(this.elementShape));

          for (var t = [], a = 0; a < this.size(); a++) t.push(a);

          var r = this.readMany(t);
          return this.assertShapesMatchAllowUndefinedSize(this.elementShape, r[0].shape, "TensorArray shape mismatch: tensor array shape (" + this.elementShape + ") vs first tensor shape (" + r[0].shape + ")"), (0, _tfjsCore.concat)(r, 0);
        }, e.prototype.scatter = function (e, t) {
          if (t.dtype !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + t.dtype);
          if (e.length !== t.shape[0]) throw new Error("Expected len(indices) == tensor.shape[0], but saw: " + e.length + " vs. " + t.shape[0]);
          var a = Math.max.apply(Math, e);
          if (!this.dynamicSize && a >= this.maxSize) throw new Error("Max index must be < array size (" + a + "  vs. " + this.maxSize + ")");
          this.writeMany(e, (0, _tfjsCore.unstack)(t, 0));
        }, e.prototype.split = function (e, t) {
          var a = this;
          if (t.dtype !== this.dtype) throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + t.dtype);
          var r = 0,
            n = e.map(function (e) {
              return r += e;
            });
          if (r !== t.shape[0]) throw new Error("Expected sum of lengths to be equal to\n          tensor.shape[0], but sum of lengths is\n        " + r + ", and tensor's shape is: " + t.shape);
          if (!this.dynamicSize && e.length !== this.maxSize) throw new Error("TensorArray's size is not equal to the size of lengths (" + this.maxSize + " vs. " + e.length + "), and the TensorArray is not marked as dynamically resizeable");
          var s = 0 === r ? 0 : t.size / r,
            o = [];
          (0, _tfjsCore.tidy)(function () {
            t = t.reshape([1, r, s]);

            for (var p = 0; p < e.length; ++p) {
              var u = [0, 0 === p ? 0 : n[p - 1], 0],
                i = [1, e[p], s];
              o[p] = (0, _tfjsCore.slice)(t, u, i).reshape(a.elementShape);
            }

            return o;
          });

          for (var p = [], u = 0; u < e.length; u++) p[u] = u;

          this.writeMany(p, o);
        }, e.prototype.assertShapesMatchAllowUndefinedSize = function (e, t, a) {
          void 0 === a && (a = ""), _tfjsCore.util.assert(this.shapesEqualAllowUndefinedSize(e, t), function () {
            return a + " Shapes " + e + " and " + t + " must match";
          });
        }, e.prototype.shapesEqualAllowUndefinedSize = function (e, t) {
          if (e.length !== t.length) return !1;

          for (var a = 0; a < e.length; a++) if (-1 !== e[a] && -1 !== t[a] && e[a] !== t[a]) return !1;

          return !0;
        }, e.nextId = 0, e;
      }();

    function executeOp$2(e, t, a) {
      return __awaiter(this, void 0, void 0, function () {
        var r, n, s, o, p, u, i, m, l, c, d, y, f, g, h, N, x, V, P, b, T, O, S, v, _, w, A, D, E, I, C, M, k, z, j;

        return __generator(this, function (F) {
          switch (F.label) {
            case 0:
              switch (e.op) {
                case "LoopCond":
                  return [3, 1];

                case "Switch":
                  return [3, 2];

                case "Merge":
                  return [3, 4];

                case "Enter":
                  return [3, 5];

                case "Exit":
                  return [3, 6];

                case "NextIteration":
                  return [3, 7];

                case "TensorArrayV3":
                  return [3, 8];

                case "TensorArrayWriteV3":
                  return [3, 9];

                case "TensorArrayReadV3":
                  return [3, 10];

                case "TensorArrayGatherV3":
                  return [3, 11];

                case "TensorArrayScatterV3":
                  return [3, 12];

                case "TensorArrayConcatV3":
                  return [3, 13];

                case "TensorArraySplitV3":
                  return [3, 14];

                case "TensorArraySizeV3":
                  return [3, 15];

                case "TensorArrayCloseV3":
                  return [3, 16];
              }

              return [3, 17];

            case 1:
              return [2, [getParamValue("pred", e, t, a).clone()]];

            case 2:
              return r = getParamValue("pred", e, t, a), n = getParamValue("data", e, t, a), [4, r.data()];

            case 3:
              return [2, F.sent()[0] ? [void 0, n.clone()] : [n.clone(), void 0]];

            case 4:
              return [2, (s = e.inputNames.find(function (e) {
                return void 0 !== getTensor(e, t, a);
              })) ? [getTensor(s, t, a).clone()] : void 0];

            case 5:
              return o = getParamValue("frameName", e, t, a), p = getParamValue("tensor", e, t, a), a.enterFrame(o), [2, [p.clone()]];

            case 6:
              return u = getParamValue("tensor", e, t, a), a.exitFrame(), [2, [u.clone()]];

            case 7:
              return i = getParamValue("tensor", e, t, a), a.nextIteration(), [2, [i.clone()]];

            case 8:
              return m = getParamValue("size", e, t, a), l = getParamValue("dtype", e, t, a), c = getParamValue("elementShape", e, t, a), d = getParamValue("dynamicSize", e, t, a), y = getParamValue("clearAfterRead", e, t, a), f = getParamValue("identicalElementShapes", e, t, a), g = getParamValue("name", e, t, a), h = new TensorArray(g, l, m, c, f, d, y), a.addTensorArray(h), [2, [(0, _tfjsCore.scalar)(h.id), (0, _tfjsCore.scalar)(1)]];

            case 9:
              return N = getParamValue("tensorArrayId", e, t, a), x = getParamValue("index", e, t, a), V = getParamValue("tensor", e, t, a), a.getTensorArray(N).write(x, V), [2, [(0, _tfjsCore.scalar)(1)]];

            case 10:
              return P = getParamValue("tensorArrayId", e, t, a), b = getParamValue("index", e, t, a), [2, [a.getTensorArray(P).read(b)]];

            case 11:
              return T = getParamValue("tensorArrayId", e, t, a), O = getParamValue("indices", e, t, a), S = getParamValue("dtype", e, t, a), [2, [a.getTensorArray(T).gather(O, S)]];

            case 12:
              return v = getParamValue("tensorArrayId", e, t, a), _ = getParamValue("indices", e, t, a), w = getParamValue("tensor", e, t, a), a.getTensorArray(v).scatter(_, w), [2, [(0, _tfjsCore.scalar)(1)]];

            case 13:
              return A = getParamValue("tensorArrayId", e, t, a), D = a.getTensorArray(A), E = getParamValue("dtype", e, t, a), [2, [D.concat(E)]];

            case 14:
              return I = getParamValue("tensorArrayId", e, t, a), C = getParamValue("tensor", e, t, a), M = getParamValue("lengths", e, t, a), a.getTensorArray(I).split(M, C), [2, [(0, _tfjsCore.scalar)(1)]];

            case 15:
              return k = getParamValue("tensorArrayId", e, t, a), z = a.getTensorArray(k), [2, [(0, _tfjsCore.scalar)(z.size(), "int32")]];

            case 16:
              return j = getParamValue("tensorArrayId", e, t, a), a.getTensorArray(j).clearAndClose(), [2, []];

            case 17:
              throw TypeError("Node type " + e.op + " is not implemented");
          }
        });
      });
    }

    var executeOp$3 = function (e, t, a) {
      var r, n;

      switch (e.op) {
        case "Conv1D":
          var s = getParamValue("stride", e, t, a),
            o = getParamValue("pad", e, t, a),
            p = getParamValue("dataFormat", e, t, a).toUpperCase(),
            u = getParamValue("dilation", e, t, a);
          return [(0, _tfjsCore.conv1d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), s, o, p, u)];

        case "Conv2D":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase();
          var i = getParamValue("dilations", e, t, a);
          return [(0, _tfjsCore.conv2d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2]], o, p, [i[1], i[2]])];

        case "_FusedConv2D":
          var m = (r = getParamValue("fusedOps", e, t, a))[0],
            l = r[1],
            c = "biasadd" === m,
            d = "prelu" === l,
            y = "fusedbatchnorm" === m,
            f = getParamValue("numArgs", e, t, a);

          if (c) {
            if (d && 2 !== f) throw new Error("Fused Conv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");
            if (!d && 1 !== f) throw new Error("Fused Conv2d with BiasAdd must have one extra argument: bias.");
          }

          if (y) throw new Error("Fused Conv2d with FusedBatchNorm is not supported.");
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase(), i = getParamValue("dilations", e, t, a);
          var g = (n = getParamValue("args", e, t, a))[0],
            h = n[1];
          return [_tfjsCore.fused.conv2d({
            x: getParamValue("x", e, t, a),
            filter: getParamValue("filter", e, t, a),
            strides: [s[1], s[2]],
            pad: o,
            dataFormat: p,
            dilations: [i[1], i[2]],
            bias: g,
            activation: l,
            preluActivationWeights: h
          })];

        case "Conv2DBackpropInput":
        case "Conv2dTranspose":
          var N = getParamValue("outputShape", e, t, a);
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a);
          return [(0, _tfjsCore.conv2dTranspose)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), N, [s[1], s[2]], o)];

        case "DepthwiseConv2dNative":
        case "DepthwiseConv2d":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), i = getParamValue("dilations", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase();
          return [(0, _tfjsCore.depthwiseConv2d)(getParamValue("input", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2]], o, p, [i[1], i[2]])];

        case "Conv3D":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), p = getParamValue("dataFormat", e, t, a).toUpperCase(), i = getParamValue("dilations", e, t, a);
          return [(0, _tfjsCore.conv3d)(getParamValue("x", e, t, a), getParamValue("filter", e, t, a), [s[1], s[2], s[3]], o, p, [i[1], i[2], i[3]])];

        case "AvgPool":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a);
          var x = getParamValue("kernelSize", e, t, a);
          return [(0, _tfjsCore.avgPool)(getParamValue("x", e, t, a), [x[1], x[2]], [s[1], s[2]], o)];

        case "MaxPool":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
          return [(0, _tfjsCore.maxPool)(getParamValue("x", e, t, a), [x[1], x[2]], [s[1], s[2]], o)];

        case "AvgPool3D":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
          return [(0, _tfjsCore.avgPool3d)(getParamValue("x", e, t, a), [x[1], x[2], x[3]], [s[1], s[2], s[3]], o)];

        case "MaxPool3D":
          s = getParamValue("strides", e, t, a), o = getParamValue("pad", e, t, a), x = getParamValue("kernelSize", e, t, a);
          return [(0, _tfjsCore.maxPool3d)(getParamValue("x", e, t, a), [x[1], x[2], x[3]], [s[1], s[2], s[3]], o)];

        default:
          throw TypeError("Node type " + e.op + " is not implemented");
      }
    },
      executeOp$4 = function (e, t, a) {
        switch (e.op) {
          case "Fill":
            var r = getParamValue("shape", e, t, a),
              n = getParamValue("dtype", e, t, a),
              s = getParamValue("value", e, t, a);
            return [(0, _tfjsCore.fill)(r, s, n)];

          case "LinSpace":
            var o = getParamValue("start", e, t, a),
              p = getParamValue("stop", e, t, a),
              u = getParamValue("num", e, t, a);
            return [(0, _tfjsCore.linspace)(o, p, u)];

          case "Multinomial":
            var i = getParamValue("logits", e, t, a),
              m = getParamValue("numSamples", e, t, a),
              l = getParamValue("seed", e, t, a);
            return [(0, _tfjsCore.multinomial)(i, m, l)];

          case "OneHot":
            var c = getParamValue("indices", e, t, a),
              d = getParamValue("depth", e, t, a),
              y = getParamValue("onValue", e, t, a),
              f = getParamValue("offValue", e, t, a);
            return [(0, _tfjsCore.oneHot)(c, d, y, f)];

          case "Ones":
            return [(0, _tfjsCore.ones)(getParamValue("shape", e, t, a), getParamValue("dtype", e, t, a))];

          case "OnesLike":
            return [(0, _tfjsCore.onesLike)(getParamValue("x", e, t, a))];

          case "RandomUniform":
            return [(0, _tfjsCore.randomUniform)(getParamValue("shape", e, t, a), getParamValue("minval", e, t, a), getParamValue("maxval", e, t, a), getParamValue("dtype", e, t, a))];

          case "Range":
            o = getParamValue("start", e, t, a);
            var g = getParamValue("stop", e, t, a),
              h = getParamValue("step", e, t, a);
            return [(0, _tfjsCore.range)(o, g, h, getParamValue("dtype", e, t, a))];

          case "TruncatedNormal":
            r = getParamValue("shape", e, t, a);
            var N = getParamValue("mean", e, t, a),
              x = getParamValue("stdDev", e, t, a);
            l = getParamValue("seed", e, t, a);
            return [(0, _tfjsCore.truncatedNormal)(r, N, x, getParamValue("dtype", e, t, a), l)];

          case "Zeros":
            return [(0, _tfjsCore.zeros)(getParamValue("shape", e, t, a), getParamValue("dtype", e, t, a))];

          case "ZerosLike":
            return [(0, _tfjsCore.zerosLike)(getParamValue("x", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      };

    function executeOp$5(e, t, a) {
      return __awaiter(this, void 0, void 0, function () {
        var r, n, s, o, p;
        return __generator(this, function (u) {
          switch (u.label) {
            case 0:
              switch (e.op) {
                case "NonMaxSuppressionV3":
                case "NonMaxSuppressionV2":
                  return [3, 1];

                case "Where":
                  return [3, 3];

                case "ListDiff":
                  return [3, 5];
              }

              return [3, 6];

            case 1:
              return r = getParamValue("boxes", e, t, a), n = getParamValue("scores", e, t, a), s = getParamValue("maxOutputSize", e, t, a), o = getParamValue("iouThreshold", e, t, a), p = getParamValue("scoreThreshold", e, t, a), [4, _tfjsCore.image.nonMaxSuppressionAsync(r, n, s, o, p)];

            case 2:
              return [2, [u.sent()]];

            case 3:
              return [4, (0, _tfjsCore.whereAsync)(getParamValue("condition", e, t, a).asType("bool"))];

            case 4:
              return [2, [u.sent()]];

            case 5:
              return [2, (0, _tfjsCore.setdiff1dAsync)(getParamValue("x", e, t, a), getParamValue("y", e, t, a))];

            case 6:
              throw TypeError("Node type " + e.op + " is not implemented");
          }
        });
      });
    }

    var executeOp$6 = function (e, t, a) {
      switch (e.op) {
        case "TopKV2":
          var r = getParamValue("x", e, t, a),
            n = getParamValue("k", e, t, a),
            s = getParamValue("sorted", e, t, a),
            o = (0, _tfjsCore.topk)(r, n, s);
          return [o.values, o.indices];

        default:
          throw TypeError("Node type " + e.op + " is not implemented");
      }
    },
      executeOp$7 = function (e, t, a) {
        switch (e.op) {
          case "Const":
            return t[e.name];

          case "PlaceholderWithDefault":
            var r = getParamValue("default", e, t, a);
            return [getTensor(e.name, t, a) || r];

          case "Placeholder":
            return [getTensor(e.name, t, a)];

          case "Identity":
          case "StopGradient":
          case "FakeQuantWithMinMaxVars":
            return [getParamValue("x", e, t, a).clone()];

          case "IdentityN":
            return getParamValue("x", e, t, a).map(function (e) {
              return e.clone();
            });

          case "Snapshot":
            return [getParamValue("x", e, t, a).clone()];

          case "Shape":
            return [(0, _tfjsCore.tensor1d)(getParamValue("x", e, t, a).shape, "int32")];

          case "ShapeN":
            return getParamValue("x", e, t, a).map(function (e) {
              return (0, _tfjsCore.tensor1d)(e.shape);
            });

          case "Size":
            return [(0, _tfjsCore.scalar)(getParamValue("x", e, t, a).size, "int32")];

          case "Rank":
            return [(0, _tfjsCore.scalar)(getParamValue("x", e, t, a).rank, "int32")];

          case "NoOp":
            return [];

          case "Print":
            var n = getParamValue("x", e, t, a),
              s = getParamValue("data", e, t, a),
              o = getParamValue("message", e, t, a),
              p = getParamValue("summarize", e, t, a);
            console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."), console.log(o);

            for (var u = 0; u < s.length; u++) console.log(Array.prototype.slice.call(s[u].dataSync()).slice(0, p));

            return [n];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$8 = function (e, t, a) {
        switch (e.op) {
          case "ResizeBilinear":
            var r = getParamValue("images", e, t, a),
              n = getParamValue("size", e, t, a),
              s = getParamValue("alignCorners", e, t, a);
            return [_tfjsCore.image.resizeBilinear(r, [n[0], n[1]], s)];

          case "ResizeNearestNeighbor":
            r = getParamValue("images", e, t, a), n = getParamValue("size", e, t, a), s = getParamValue("alignCorners", e, t, a);
            return [_tfjsCore.image.resizeNearestNeighbor(r, [n[0], n[1]], s)];

          case "CropAndResize":
            var o = getParamValue("image", e, t, a),
              p = getParamValue("boxes", e, t, a),
              u = getParamValue("boxInd", e, t, a),
              i = getParamValue("cropSize", e, t, a),
              m = getParamValue("method", e, t, a),
              l = getParamValue("extrapolationValue", e, t, a);
            return [_tfjsCore.image.cropAndResize(o, p, u, i, m, l)];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$9 = function (e, t, a) {
        switch (e.op) {
          case "Equal":
            return [(0, _tfjsCore.equal)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "NotEqual":
            return [(0, _tfjsCore.notEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Greater":
            return [(0, _tfjsCore.greater)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "GreaterEqual":
            return [(0, _tfjsCore.greaterEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Less":
            return [(0, _tfjsCore.less)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "LessEqual":
            return [(0, _tfjsCore.lessEqual)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "LogicalAnd":
            return [(0, _tfjsCore.logicalAnd)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "LogicalNot":
            return [(0, _tfjsCore.logicalNot)(getParamValue("a", e, t, a))];

          case "LogicalOr":
            return [(0, _tfjsCore.logicalOr)(getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          case "Select":
            return [(0, _tfjsCore.where)(getParamValue("condition", e, t, a), getParamValue("a", e, t, a), getParamValue("b", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$10 = function (e, t, a) {
        switch (e.op) {
          case "BatchMatMul":
          case "BatchMatMulV2":
          case "MatMul":
            return [(0, _tfjsCore.matMul)(getParamValue("a", e, t, a), getParamValue("b", e, t, a), getParamValue("transposeA", e, t, a), getParamValue("transposeB", e, t, a))];

          case "Transpose":
            return [(0, _tfjsCore.transpose)(getParamValue("x", e, t, a), getParamValue("perm", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$11 = function (e, t, a) {
        switch (e.op) {
          case "FusedBatchNorm":
          case "FusedBatchNormV2":
          case "FusedBatchNormV3":
            return [(0, _tfjsCore.batchNorm)(getParamValue("x", e, t, a), getParamValue("mean", e, t, a), getParamValue("variance", e, t, a), getParamValue("offset", e, t, a), getParamValue("scale", e, t, a), getParamValue("epsilon", e, t, a))];

          case "LRN":
            return [(0, _tfjsCore.localResponseNormalization)(getParamValue("x", e, t, a), getParamValue("radius", e, t, a), getParamValue("bias", e, t, a), getParamValue("alpha", e, t, a), getParamValue("beta", e, t, a))];

          case "Softmax":
            return [(0, _tfjsCore.softmax)(getParamValue("x", e, t, a))];

          case "LogSoftmax":
            return [(0, _tfjsCore.logSoftmax)(getParamValue("x", e, t, a))];

          case "SparseToDense":
            return [(0, _tfjsCore.sparseToDense)(getParamValue("sparseIndices", e, t, a), getParamValue("outputShape", e, t, a), getParamValue("sparseValues", e, t, a), getParamValue("defaultValue", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$12 = function (e, t, a) {
        switch (e.op) {
          case "Max":
            var r = getParamValue("axis", e, t, a),
              n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.max)(getParamValue("x", e, t, a), r, n)];

          case "Mean":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.mean)(getParamValue("x", e, t, a), r, n)];

          case "Min":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.min)(getParamValue("x", e, t, a), r, n)];

          case "Sum":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.sum)(getParamValue("x", e, t, a), r, n)];

          case "All":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.all)(getParamValue("x", e, t, a), r, n)];

          case "Any":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.any)(getParamValue("x", e, t, a), r, n)];

          case "ArgMax":
            r = getParamValue("axis", e, t, a);
            return [(0, _tfjsCore.argMax)(getParamValue("x", e, t, a), r)];

          case "ArgMin":
            r = getParamValue("axis", e, t, a);
            return [(0, _tfjsCore.argMin)(getParamValue("x", e, t, a), r)];

          case "Prod":
            r = getParamValue("axis", e, t, a), n = getParamValue("keepDims", e, t, a);
            return [(0, _tfjsCore.prod)(getParamValue("x", e, t, a), r, n)];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$13 = function (e, t, a) {
        switch (e.op) {
          case "ConcatV2":
          case "Concat":
            var r = getParamValue("axis", e, t, a),
              n = getParamValue("tensors", e, t, a);
            return [(0, _tfjsCore.concat)(n, r)];

          case "GatherV2":
          case "Gather":
            r = getParamValue("axis", e, t, a);
            var s = getParamValue("x", e, t, a),
              o = getParamValue("indices", e, t, a);
            return [(0, _tfjsCore.gather)(s, o.asType("int32"), r)];

          case "ReverseV2":
          case "Reverse":
            r = getParamValue("axis", e, t, a), s = getParamValue("x", e, t, a);
            return [(0, _tfjsCore.reverse)(s, r)];

          case "Slice":
            var p = getParamValue("begin", e, t, a),
              u = getParamValue("size", e, t, a);
            return [(0, _tfjsCore.slice)(getParamValue("x", e, t, a), p, u)];

          case "StridedSlice":
            p = getParamValue("begin", e, t, a);
            var i = getParamValue("end", e, t, a),
              m = getParamValue("strides", e, t, a),
              l = getParamValue("beginMask", e, t, a),
              c = getParamValue("endMask", e, t, a),
              d = getParamValue("ellipsisMask", e, t, a),
              y = getParamValue("newAxisMask", e, t, a),
              f = getParamValue("shrinkAxisMask", e, t, a),
              g = getParamValue("x", e, t, a);
            if (1 === p.length && g.shape.length > 1) for (var h = 1; h < g.shape.length; h++) p.push(0), i.push(g.shape[h]), m.push(m[0]);
            return [(0, _tfjsCore.stridedSlice)(g, p, i, m, l, c, d, y, f)];

          case "Pack":
            return (0, _tfjsCore.tidy)(function () {
              var r = getParamValue("axis", e, t, a),
                n = getParamValue("tensors", e, t, a),
                s = n[0].shape,
                o = n[0].squeeze().shape,
                p = n.map(function (e) {
                  var t = _tfjsCore.util.arraysEqual(e.shape, s);

                  if (!t && !_tfjsCore.util.arraysEqual(e.squeeze().shape, o)) throw new Error("the input tensors shape does not match");
                  return t ? e : e.reshape(s);
                });
              return [(0, _tfjsCore.stack)(p, r)];
            });

          case "Unpack":
            return (0, _tfjsCore.tidy)(function () {
              var r = getParamValue("axis", e, t, a),
                n = getParamValue("tensor", e, t, a);
              return (0, _tfjsCore.unstack)(n, r);
            });

          case "Tile":
            var N = getParamValue("reps", e, t, a);
            return [(0, _tfjsCore.tile)(getParamValue("x", e, t, a), N)];

          case "Split":
          case "SplitV":
            r = getParamValue("axis", e, t, a);
            var x = getParamValue("numOrSizeSplits", e, t, a);
            return (0, _tfjsCore.split)(getParamValue("x", e, t, a), x, r);

          case "ScatterNd":
            o = getParamValue("indices", e, t, a);
            var V = getParamValue("values", e, t, a),
              P = getParamValue("shape", e, t, a);
            return [(0, _tfjsCore.scatterND)(o, V, P)];

          case "GatherNd":
            var b = getParamValue("x", e, t, a);
            o = getParamValue("indices", e, t, a);
            return [(0, _tfjsCore.gatherND)(b, o)];

          case "SparseToDense":
            o = getParamValue("sparseIndices", e, t, a), P = getParamValue("outputShape", e, t, a);
            var T = getParamValue("sparseValues", e, t, a),
              O = getParamValue("defaultValue", e, t, a);
            return [(0, _tfjsCore.sparseToDense)(o, T, P, T.dtype === O.dtype ? O : O.asType(T.dtype))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$14 = function (e, t, a) {
        switch (e.op) {
          case "FFT":
            return [(0, _tfjsCore.fft)(getParamValue("x", e, t, a))];

          case "IFFT":
            return [(0, _tfjsCore.ifft)(getParamValue("x", e, t, a))];

          case "RFFT":
            return [(0, _tfjsCore.rfft)(getParamValue("x", e, t, a))];

          case "IRFFT":
            return [(0, _tfjsCore.irfft)(getParamValue("x", e, t, a))];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      },
      executeOp$15 = function (e, t, a) {
        switch (e.op) {
          case "Cast":
            return [(0, _tfjsCore.cast)(getParamValue("x", e, t, a), getParamValue("dtype", e, t, a))];

          case "ExpandDims":
            var r = getParamValue("axis", e, t, a);
            return [(0, _tfjsCore.expandDims)(getParamValue("x", e, t, a), r)];

          case "Squeeze":
            r = getParamValue("axis", e, t, a);
            return [(0, _tfjsCore.squeeze)(getParamValue("x", e, t, a), r)];

          case "Reshape":
            return [(0, _tfjsCore.reshape)(getParamValue("x", e, t, a), getParamValue("shape", e, t, a))];

          case "PadV2":
          case "Pad":
            return [(0, _tfjsCore.pad)(getParamValue("x", e, t, a), split$1(getParamValue("padding", e, t, a), 2), getParamValue("constantValue", e, t, a))];

          case "SpaceToBatchND":
            var n = getParamValue("blockShape", e, t, a),
              s = split$1(getParamValue("paddings", e, t, a), 2);
            return [(0, _tfjsCore.spaceToBatchND)(getParamValue("x", e, t, a), n, s)];

          case "BatchToSpaceND":
            n = getParamValue("blockShape", e, t, a);
            var o = split$1(getParamValue("crops", e, t, a), 2);
            return [(0, _tfjsCore.batchToSpaceND)(getParamValue("x", e, t, a), n, o)];

          case "DepthToSpace":
            var p = getParamValue("blockSize", e, t, a),
              u = getParamValue("dataFormat", e, t, a).toUpperCase();
            return [(0, _tfjsCore.depthToSpace)(getParamValue("x", e, t, a), p, u)];

          default:
            throw TypeError("Node type " + e.op + " is not implemented");
        }
      };

    function executeOp$16(e, t, a) {
      var r = function (e, t, a) {
        switch (e.category) {
          case "arithmetic":
            return executeOp(e, t, a);

          case "basic_math":
            return executeOp$1(e, t, a);

          case "control":
            return executeOp$2(e, t, a);

          case "convolution":
            return executeOp$3(e, t, a);

          case "creation":
            return executeOp$4(e, t, a);

          case "dynamic":
            return executeOp$5(e, t, a);

          case "evaluation":
            return executeOp$6(e, t, a);

          case "image":
            return executeOp$8(e, t, a);

          case "graph":
            return executeOp$7(e, t, a);

          case "logical":
            return executeOp$9(e, t, a);

          case "matrices":
            return executeOp$10(e, t, a);

          case "normalization":
            return executeOp$11(e, t, a);

          case "reduction":
            return executeOp$12(e, t, a);

          case "slice_join":
            return executeOp$13(e, t, a);

          case "spectral":
            return executeOp$14(e, t, a);

          case "transformation":
            return executeOp$15(e, t, a);

          case "custom":
            var r = getRegisteredOp(e.op);
            if (r && r.customExecutor) return r.customExecutor(new NodeValueImpl(e, t, a));
            throw TypeError("Custom op " + e.op + " is not registered.");

          default:
            throw TypeError("Unknown op '" + e.op + "'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()");
        }
      }(e, t, a);

      return r instanceof Promise ? r.then(function (e) {
        return [].concat(e);
      }) : [].concat(r);
    }

    var ExecutionContext = function () {
      function e(e, t) {
        this.weightMap = e, this.tensorArrayMap = t, this.rootContext = {
          id: 0,
          frameName: "",
          iterationId: 0
        }, this.contexts = [this.rootContext], this.lastId = 0, this.generateCurrentContextIds();
      }

      return e.prototype.newFrame = function (e, t) {
        return {
          id: e,
          frameName: t,
          iterationId: 0
        };
      }, Object.defineProperty(e.prototype, "currentContext", {
        get: function () {
          return this.contexts;
        },
        set: function (e) {
          this.contexts !== e && (this.contexts = e, this.generateCurrentContextIds());
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "currentContextId", {
        get: function () {
          return this._currentContextIds[0];
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "currentContextIds", {
        get: function () {
          return this._currentContextIds;
        },
        enumerable: !0,
        configurable: !0
      }), e.prototype.generateCurrentContextIds = function () {
        for (var e = [], t = 0; t < this.contexts.length - 1; t++) {
          var a = this.contexts.slice(0, this.contexts.length - t);
          e.push(this.contextIdforContexts(a));
        }

        e.push(""), this._currentContextIds = e;
      }, e.prototype.contextIdforContexts = function (e) {
        return e ? e.map(function (e) {
          return 0 === e.id && 0 === e.iterationId ? "" : e.frameName + "-" + e.iterationId;
        }).join("/") : "";
      }, e.prototype.enterFrame = function (e) {
        this.contexts && (this.lastId++, this.contexts = this.contexts.slice(), this.contexts.push(this.newFrame(this.lastId, e)), this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)));
      }, e.prototype.exitFrame = function () {
        if (!(this.contexts && this.contexts.length > 1)) throw new Error("Cannot exit frame, the context is empty");
        this.contexts = this.contexts.slice(), this.contexts.splice(-1), this.currentContextIds.shift();
      }, e.prototype.nextIteration = function () {
        if (!(this.contexts && this.contexts.length > 0)) throw new Error("Cannot increase frame iteration, the context is empty");
        this.contexts = this.contexts.slice(), this.lastId++;
        var e = Object.assign({}, this.contexts[this.contexts.length - 1]);
        e.iterationId += 1, e.id = this.lastId, this.contexts.splice(-1, 1, e), this._currentContextIds.splice(0, 1, this.contextIdforContexts(this.contexts));
      }, e.prototype.getWeight = function (e) {
        return this.weightMap[e];
      }, e.prototype.addTensorArray = function (e) {
        this.tensorArrayMap[e.id] = e;
      }, e.prototype.getTensorArray = function (e) {
        return this.tensorArrayMap[e];
      }, e;
    }();

    function getExecutionSubgraph(e, t, a) {
      for (var r = new Set(), n = [], s = null, o = null, p = new Set(), u = t.slice(); u.length > 0;) {
        var i = u.pop();
        (isControlFlow(i) || isDynamicShape(i)) && null == s && (o = (s = i).children.map(function (e) {
          return e.name;
        }).filter(function (e) {
          return r.has(e);
        })), r.add(i.name), null == a[i.name] && null == e[i.name] && (0 !== i.inputs.length ? i.inputs.forEach(function (e) {
          p.has(e.name) || (p.add(e.name), u.push(e));
        }) : n.push(i.name));
      }

      return {
        inputs: e,
        outputs: t,
        usedNodes: r,
        missingInputs: n,
        dynamicNode: s,
        syncInputs: o
      };
    }

    function getNodesInTopologicalOrder(e, t, a) {
      var r = a.usedNodes,
        n = a.inputs,
        s = [];
      Object.keys(n).map(function (t) {
        return e.nodes[t];
      }).forEach(function (e) {
        r.has(e.name) && s.push(e);
      }), e.weights.forEach(function (e) {
        r.has(e.name) && s.push(e);
      });

      for (var o = new Set(), p = []; s.length > 0;) {
        var u = s.pop();
        o.add(u.name), t[u.name] || p.push(u), u.children.forEach(function (e) {
          !o.has(e.name) && r.has(e.name) && e.inputs.every(function (e) {
            return o.has(e.name);
          }) && s.push(e);
        });
      }

      return p;
    }

    var CONTROL_FLOW_OPS = ["Switch", "Merge", "Enter", "Exit", "NextIteration"],
      DYNAMIC_SHAPE_OPS = ["NonMaxSuppressionV2", "NonMaxSuppressionV3", "Where"];

    function isControlFlow(e) {
      return CONTROL_FLOW_OPS.indexOf(e.op) >= 0;
    }

    function isDynamicShape(e) {
      return DYNAMIC_SHAPE_OPS.indexOf(e.op) >= 0;
    }

    var GraphExecutor = function () {
      function e(e) {
        this.graph = e, this.compiledMap = new Map(), this._weightMap = {}, this.SEPERATOR = ",", this.placeholders = e.placeholders, this._outputs = e.outputs;
      }

      return Object.defineProperty(e.prototype, "weightMap", {
        get: function () {
          return this._weightMap;
        },
        set: function (e) {
          var t = Object.keys(e).map(function (t) {
            return e[t].map(function (e) {
              return e.id;
            });
          });
          this.weightIds = [].concat.apply([], t), this._weightMap = e;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "inputs", {
        get: function () {
          return this.placeholders.map(function (e) {
            return {
              name: e.name,
              shape: e.attrParams.shape ? e.attrParams.shape.value : void 0,
              dtype: e.attrParams.dtype ? e.attrParams.dtype.value : void 0
            };
          });
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "outputs", {
        get: function () {
          return this._outputs.map(function (e) {
            return {
              name: e.name,
              shape: e.attrParams.shape ? e.attrParams.shape.value : void 0,
              dtype: e.attrParams.dtype ? e.attrParams.dtype.value : void 0
            };
          });
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "inputNodes", {
        get: function () {
          return this.placeholders.map(function (e) {
            return e.name;
          });
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(e.prototype, "outputNodes", {
        get: function () {
          return this.outputs.map(function (e) {
            return e.name;
          });
        },
        enumerable: !0,
        configurable: !0
      }), e.prototype.getCompilationKey = function (e, t) {
        var a = e.map(function (e) {
          return e.name;
        }).sort(),
          r = t.map(function (e) {
            return e.name;
          }).sort();
        return a.join(this.SEPERATOR) + "--" + r.join(this.SEPERATOR);
      }, e.prototype.compile = function (e, t) {
        var a = getExecutionSubgraph(e, t, this.weightMap),
          r = a.missingInputs,
          n = a.dynamicNode,
          s = a.syncInputs;
        if (null != n) throw new Error("This execution contains the node '" + n.name + "', which has the dynamic op '" + n.op + "'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [" + s + "]");

        if (r.length > 0) {
          var o = t.map(function (e) {
            return e.name;
          }),
            p = Object.keys(e);
          throw new Error("Cannot compute the outputs [" + o + "] from the provided inputs [" + p + "]. Missing the following inputs: [" + r + "]");
        }

        return getNodesInTopologicalOrder(this.graph, this.weightMap, a);
      }, e.prototype.execute = function (e, t) {
        var a = this,
          r = Object.keys(e).sort();
        this.checkInputs(e), this.checkInputShapeAndType(e), this.checkOutputs(t);
        var n = r.map(function (e) {
          return a.graph.nodes[e];
        }),
          s = t.map(function (e) {
            return a.graph.nodes[parseNodeName(e)[0]];
          }),
          o = this.getCompilationKey(n, s),
          p = this.compiledMap.get(o);
        null == p && (p = this.compile(e, s), this.compiledMap.set(o, p));
        var u = {};
        return (0, _tfjsCore.tidy)(function () {
          var r = new ExecutionContext(a._weightMap, u),
            n = __assign({}, a.weightMap);

          Object.keys(e).forEach(function (t) {
            n[t] = [e[t]];
          });

          for (var s = a.getFrozenTensorIds(n), o = {}, i = 0; i < p.length; i++) {
            var m = p[i];

            if (!n[m.name]) {
              var l = executeOp$16(m, n, r);
              if (l instanceof Promise) throw new Error("The execution of the op '" + m.op + "' returned a promise. Please use model.executeAsync() instead.");
              n[m.name] = l, a.checkTensorForDisposal(m.name, m, n, r, s, t, o);
            }
          }

          return t.map(function (e) {
            return getTensor(e, n, r);
          });
        });
      }, e.prototype.getFrozenTensorIds = function (e) {
        var t = [].concat.apply([], Object.keys(e).map(function (t) {
          return e[t];
        }).map(function (e) {
          return e.map(function (e) {
            return e.id;
          });
        }));
        return new Set(t);
      }, e.prototype.checkTensorForDisposal = function (e, t, a, r, n, s, o) {
        "control" !== t.category && -1 === s.indexOf(e) && (a[e].forEach(function (e) {
          null != e && (o[e.id] = (o[e.id] || 0) + t.children.length);
        }), t.inputs.forEach(function (e) {
          if ("control" !== e.category) {
            var t = getTensorsForCurrentContenxt(e.name, a, r);
            null != t && t.forEach(function (e) {
              if (e && !n.has(e.id)) {
                var t = o[e.id];
                1 === t ? (e.dispose(), delete o[e.id]) : null != t && o[e.id]--;
              }
            });
          }
        }));
      }, e.prototype.executeAsync = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          var a,
            r,
            n,
            s,
            o,
            p,
            u = this;
          return __generator(this, function (i) {
            switch (i.label) {
              case 0:
                return this.checkInputs(e), this.checkInputShapeAndType(e), this.checkOutputs(t), a = {}, r = new ExecutionContext(this._weightMap, a), [4, this.executeWithControlFlow(e, r, t)];

              case 1:
                return n = i.sent(), s = t.map(function (e) {
                  return getTensor(e, n, r);
                }), o = new Set(s.map(function (e) {
                  return e.id;
                })), p = new Set(Object.keys(e).map(function (t) {
                  return e[t].id;
                })), Object.keys(n).forEach(function (e) {
                  n[e].forEach(function (e) {
                    !e || e.isDisposed || o.has(e.id) || p.has(e.id) || -1 !== u.weightIds.indexOf(e.id) || e.dispose();
                  });
                }), [2, s];
            }
          });
        });
      }, e.prototype.executeWithControlFlow = function (e, t, a) {
        return __awaiter(this, void 0, void 0, function () {
          var r,
            n,
            s,
            o,
            p,
            u,
            i,
            m,
            l,
            c,
            d,
            y,
            f,
            g,
            h,
            N,
            x = this;
          return __generator(this, function (V) {
            switch (V.label) {
              case 0:
                r = Object.keys(e), n = r.map(function (e) {
                  return x.graph.nodes[e];
                }), s = a.map(function (e) {
                  return x.graph.nodes[parseNodeName(e)[0]];
                }), o = getExecutionSubgraph(e, s, this.weightMap), p = o.usedNodes, u = o.missingInputs, i = o.dynamicNode, m = o.syncInputs, l = n.concat(this.graph.weights).map(function (e) {
                  return {
                    node: e,
                    contexts: t.currentContext
                  };
                }), c = __assign({}, this.weightMap), Object.keys(e).forEach(function (t) {
                  c[t] = [e[t]];
                }), d = {}, y = this.getFrozenTensorIds(c), f = {}, V.label = 1;

              case 1:
                return l.length > 0 ? (g = this.processStack(n, l, t, c, f, y, a, d, p), [4, Promise.all(g)]) : [3, 3];

              case 2:
                return V.sent(), [3, 1];

              case 3:
                if (null == i && console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."), (h = s.filter(function (e) {
                  return !isControlFlow(e) && !getTensor(e.name, c, t);
                }).map(function (e) {
                  return e.name;
                })).length > 0) throw N = "", null != i && (N = "Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [" + m + "]"), new Error("Cannot compute the outputs [" + h + "] from the provided inputs [" + r + "]. Consider providing the following inputs: [" + u + "]. " + N);
                return [2, c];
            }
          });
        });
      }, e.prototype.processStack = function (e, t, a, r, n, s, o, p, u) {
        for (var i = this, m = [], l = function () {
          var l = t.pop();
          a.currentContext = l.contexts;
          var d = "";

          if ("Enter" === l.node.op && getParamValue("isConstant", l.node, r, a) && (d = getNodeNameAndIndex(l.node.name, a)[0]), -1 === e.indexOf(l.node)) {
            var y = executeOp$16(l.node, r, a);
            d || (d = getNodeNameAndIndex(l.node.name, a)[0]);
            var f = a.currentContext;
            y instanceof Promise ? m.push(y.then(function (e) {
              return r[d] = e, a.currentContext = f, i.checkTensorForDisposal(d, l.node, r, a, s, o, p), i.processChildNodes(l.node, t, a, r, n, u), e;
            })) : (r[d] = y, c.checkTensorForDisposal(d, l.node, r, a, s, o, p), c.processChildNodes(l.node, t, a, r, n, u));
          } else c.processChildNodes(l.node, t, a, r, n, u);
        }, c = this; t.length > 0;) l();

        return m;
      }, e.prototype.processChildNodes = function (e, t, a, r, n, s) {
        e.children.forEach(function (e) {
          var o = getNodeNameAndIndex(e.name, a)[0];
          !n[o] && s.has(e.name) && ("Merge" === e.op ? e.inputNames.some(function (e) {
            return !!getTensor(e, r, a);
          }) && (n[o] = !0, t.push({
            contexts: a.currentContext,
            node: e
          })) : e.inputNames.every(function (e) {
            return !!getTensor(e, r, a);
          }) && (n[o] = !0, t.push({
            contexts: a.currentContext,
            node: e
          })));
        });
      }, e.prototype.dispose = function () {
        var e = this;
        Object.keys(this.weightMap).forEach(function (t) {
          return e.weightMap[t].forEach(function (e) {
            return e.dispose();
          });
        });
      }, e.prototype.checkInputShapeAndType = function (e) {
        var t = this;
        Object.keys(e).forEach(function (a) {
          var r = e[a],
            n = t.graph.nodes[a];

          if (n.attrParams.shape && n.attrParams.shape.value) {
            var s = n.attrParams.shape.value,
              o = s.length === r.shape.length && r.shape.every(function (e, t) {
                return -1 === s[t] || s[t] === e;
              });

            _tfjsCore.util.assert(o, function () {
              return "The shape of dict['" + n.name + "'] provided in model.execute(dict) must be [" + s + "], but was [" + r.shape + "]";
            });
          }

          n.attrParams.dtype && n.attrParams.dtype.value && _tfjsCore.util.assert(r.dtype === n.attrParams.dtype.value, function () {
            return "The dtype of dict['" + n.name + "'] provided in model.execute(dict) must be " + n.attrParams.dtype.value + ", but was " + r.dtype;
          });
        });
      }, e.prototype.checkInputs = function (e) {
        var t = this,
          a = Object.keys(e).filter(function (e) {
            return !t.graph.nodes[e];
          });
        if (a.length > 0) throw new Error("The dict provided in model.execute(dict) has keys: [" + a + "] that are not part of graph");
      }, e.prototype.checkOutputs = function (e) {
        var t = this;
        e.forEach(function (e) {
          var a = parseNodeName(e)[0];
          if (!t.graph.nodes[a]) throw new Error("The output '" + e + "' is not found in the graph");
        });
      }, e;
    }(),
      TFHUB_SEARCH_PARAM = "?tfjs-format=file",
      DEFAULT_MODEL_NAME = "model.json",
      GraphModel = function () {
        function e(e, t) {
          void 0 === t && (t = {}), this.modelUrl = e, this.loadOptions = t, this.version = "n/a", null == t && (this.loadOptions = {});
        }

        return Object.defineProperty(e.prototype, "modelVersion", {
          get: function () {
            return this.version;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(e.prototype, "inputNodes", {
          get: function () {
            return this.executor.inputNodes;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(e.prototype, "outputNodes", {
          get: function () {
            return this.executor.outputNodes;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(e.prototype, "inputs", {
          get: function () {
            return this.executor.inputs;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(e.prototype, "outputs", {
          get: function () {
            return this.executor.outputs;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(e.prototype, "weights", {
          get: function () {
            return this.executor.weightMap;
          },
          enumerable: !0,
          configurable: !0
        }), e.prototype.findIOHandler = function () {
          var e = this.modelUrl;
          if (null != e.load) this.handler = e; else if (null != this.loadOptions.requestInit) this.handler = _tfjsCore.io.browserHTTPRequest(e, this.loadOptions); else {
            var t = _tfjsCore.io.getLoadHandlers(e, this.loadOptions.onProgress);

            if (0 === t.length) t.push(_tfjsCore.io.browserHTTPRequest(e, this.loadOptions)); else if (t.length > 1) throw new Error("Found more than one (" + t.length + ") load handlers for URL '" + [e] + "'");
            this.handler = t[0];
          }
        }, e.prototype.load = function () {
          return __awaiter(this, void 0, void 0, function () {
            var e, t, a;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  if (this.findIOHandler(), null == this.handler.load) throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
                  return [4, this.handler.load()];

                case 1:
                  return e = r.sent(), t = e.modelTopology, this.version = t.versions.producer + "." + t.versions.minConsumer, a = _tfjsCore.io.decodeWeights(e.weightData, e.weightSpecs), this.executor = new GraphExecutor(OperationMapper.Instance.transformGraph(t)), this.executor.weightMap = this.convertTensorMapToTensorsMap(a), [2, !0];
              }
            });
          });
        }, e.prototype.predict = function (e, t) {
          return this.execute(e, this.outputNodes);
        }, e.prototype.normalizeInputs = function (e) {
          if (!(e instanceof _tfjsCore.Tensor || Array.isArray(e))) return e;
          if ((e = Array.isArray(e) ? e : [e]).length !== this.inputNodes.length) throw new Error("Input tensor count mismatch,the graph model has " + this.inputNodes.length + " placeholders, while there are " + e.length + " input tensors.");
          return this.inputNodes.reduce(function (t, a, r) {
            return t[a] = e[r], t;
          }, {});
        }, e.prototype.normalizeOutputs = function (e) {
          return e = e || this.outputNodes, Array.isArray(e) ? e : [e];
        }, e.prototype.execute = function (e, t) {
          e = this.normalizeInputs(e), t = this.normalizeOutputs(t);
          var a = this.executor.execute(e, t);
          return a.length > 1 ? a : a[0];
        }, e.prototype.executeAsync = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var a;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return e = this.normalizeInputs(e), t = this.normalizeOutputs(t), [4, this.executor.executeAsync(e, t)];

                case 1:
                  return [2, (a = r.sent()).length > 1 ? a : a[0]];
              }
            });
          });
        }, e.prototype.convertTensorMapToTensorsMap = function (e) {
          return Object.keys(e).reduce(function (t, a) {
            return t[a] = [e[a]], t;
          }, {});
        }, e.prototype.dispose = function () {
          this.executor.dispose();
        }, e;
      }();

    exports.GraphModel = GraphModel;

    function loadGraphModel(e, t) {
      return void 0 === t && (t = {}), __awaiter(this, void 0, void 0, function () {
        var a;
        return __generator(this, function (r) {
          switch (r.label) {
            case 0:
              if (null == e) throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");
              return null == t && (t = {}), t.fromTFHub && null == e.load && (e.endsWith("/") || (e += "/"), e = "" + e + DEFAULT_MODEL_NAME + TFHUB_SEARCH_PARAM), [4, (a = new GraphModel(e, t)).load()];

            case 1:
              return r.sent(), [2, a];
          }
        });
      });
    }

    var version = "1.3.1";
    exports.version_converter = version;
  }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.decodeMultiplePoses = decodeMultiplePoses;
    exports.decodeSinglePose = decodeSinglePose;
    exports.load = load;
    exports.getAdjacentKeyPoints = getAdjacentKeyPoints;
    exports.getBoundingBox = getBoundingBox;
    exports.getBoundingBoxPoints = getBoundingBoxPoints;
    exports.scaleAndFlipPoses = scaleAndFlipPoses;
    exports.scalePose = scalePose;
    exports.PoseNet = exports.poseChain = exports.partNames = exports.partIds = exports.partChannels = exports.MobileNet = void 0;

    var tf = _interopRequireWildcard(require("@tensorflow/tfjs-core"));

    var _tfjsConverter = require("@tensorflow/tfjs-converter");

    function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

    function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

    /**
        * @license
        * Copyright 2019 Google LLC. All Rights Reserved.
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
        * You may obtain a copy of the License at
        *
        * http://www.apache.org/licenses/LICENSE-2.0
        *
        * Unless required by applicable law or agreed to in writing, software
        * distributed under the License is distributed on an "AS IS" BASIS,
        * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        * See the License for the specific language governing permissions and
        * limitations under the License.
        * =============================================================================
        */
    var extendStatics = function (e, t) {
      return (extendStatics = 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]);
      })(e, t);
    };

    function __extends(e, t) {
      function n() {
        this.constructor = e;
      }

      extendStatics(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, new n());
    }

    var __assign = function () {
      return (__assign = Object.assign || function (e) {
        for (var t, n = 1, r = arguments.length; n < r; n++) for (var o in t = arguments[n]) Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);

        return e;
      }).apply(this, arguments);
    };

    function __awaiter(e, t, n, r) {
      return new (n || (n = Promise))(function (o, i) {
        function s(e) {
          try {
            a(r.next(e));
          } catch (e) {
            i(e);
          }
        }

        function u(e) {
          try {
            a(r.throw(e));
          } catch (e) {
            i(e);
          }
        }

        function a(e) {
          e.done ? o(e.value) : new n(function (t) {
            t(e.value);
          }).then(s, u);
        }

        a((r = r.apply(e, t || [])).next());
      });
    }

    function __generator(e, t) {
      var n,
        r,
        o,
        i,
        s = {
          label: 0,
          sent: function () {
            if (1 & o[0]) throw o[1];
            return o[1];
          },
          trys: [],
          ops: []
        };
      return i = {
        next: u(0),
        throw: u(1),
        return: u(2)
      }, "function" == typeof Symbol && (i[Symbol.iterator] = function () {
        return this;
      }), i;

      function u(i) {
        return function (u) {
          return function (i) {
            if (n) throw new TypeError("Generator is already executing.");

            for (; s;) try {
              if (n = 1, r && (o = 2 & i[0] ? r.return : i[0] ? r.throw || ((o = r.return) && o.call(r), 0) : r.next) && !(o = o.call(r, i[1])).done) return o;

              switch (r = 0, o && (i = [2 & i[0], o.value]), i[0]) {
                case 0:
                case 1:
                  o = i;
                  break;

                case 4:
                  return s.label++, {
                    value: i[1],
                    done: !1
                  };

                case 5:
                  s.label++, r = i[1], i = [0];
                  continue;

                case 7:
                  i = s.ops.pop(), s.trys.pop();
                  continue;

                default:
                  if (!(o = (o = s.trys).length > 0 && o[o.length - 1]) && (6 === i[0] || 2 === i[0])) {
                    s = 0;
                    continue;
                  }

                  if (3 === i[0] && (!o || i[1] > o[0] && i[1] < o[3])) {
                    s.label = i[1];
                    break;
                  }

                  if (6 === i[0] && s.label < o[1]) {
                    s.label = o[1], o = i;
                    break;
                  }

                  if (o && s.label < o[2]) {
                    s.label = o[2], s.ops.push(i);
                    break;
                  }

                  o[2] && s.ops.pop(), s.trys.pop();
                  continue;
              }

              i = t.call(e, s);
            } catch (e) {
              i = [6, e], r = 0;
            } finally {
                n = o = 0;
              }

            if (5 & i[0]) throw i[1];
            return {
              value: i[0] ? i[1] : void 0,
              done: !0
            };
          }([i, u]);
        };
      }
    }

    var BaseModel = function () {
      function e(e, t) {
        this.model = e, this.outputStride = t;
        var n = this.model.inputs[0].shape;
        tf.util.assert(-1 === n[1] && -1 === n[2], function () {
          return "Input shape [" + n[1] + ", " + n[2] + "] must both be equal to or -1";
        });
      }

      return e.prototype.predict = function (e) {
        var t = this;
        return (0, tf.tidy)(function () {
          var n = t.preprocessInput(e.toFloat()).expandDims(0),
            r = t.model.predict(n).map(function (e) {
              return e.squeeze([0]);
            }),
            o = t.nameOutputResults(r);
          return {
            heatmapScores: o.heatmap.sigmoid(),
            offsets: o.offsets,
            displacementFwd: o.displacementFwd,
            displacementBwd: o.displacementBwd
          };
        });
      }, e.prototype.dispose = function () {
        this.model.dispose();
      }, e;
    }(),
      MobileNet = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.preprocessInput = function (e) {
          return (0, tf.tidy)(function () {
            return (0, tf.div)(e, 127.5).sub(1);
          });
        }, t.prototype.nameOutputResults = function (e) {
          return {
            offsets: e[0],
            heatmap: e[1],
            displacementFwd: e[2],
            displacementBwd: e[3]
          };
        }, t;
      }(BaseModel);

    exports.MobileNet = MobileNet;

    function half(e) {
      return Math.floor(e / 2);
    }

    var MaxHeap = function () {
      function e(e, t) {
        this.priorityQueue = new Array(e), this.numberOfElements = -1, this.getElementValue = t;
      }

      return e.prototype.enqueue = function (e) {
        this.priorityQueue[++this.numberOfElements] = e, this.swim(this.numberOfElements);
      }, e.prototype.dequeue = function () {
        var e = this.priorityQueue[0];
        return this.exchange(0, this.numberOfElements--), this.sink(0), this.priorityQueue[this.numberOfElements + 1] = null, e;
      }, e.prototype.empty = function () {
        return -1 === this.numberOfElements;
      }, e.prototype.size = function () {
        return this.numberOfElements + 1;
      }, e.prototype.all = function () {
        return this.priorityQueue.slice(0, this.numberOfElements + 1);
      }, e.prototype.max = function () {
        return this.priorityQueue[0];
      }, e.prototype.swim = function (e) {
        for (; e > 0 && this.less(half(e), e);) this.exchange(e, half(e)), e = half(e);
      }, e.prototype.sink = function (e) {
        for (; 2 * e <= this.numberOfElements;) {
          var t = 2 * e;
          if (t < this.numberOfElements && this.less(t, t + 1) && t++, !this.less(e, t)) break;
          this.exchange(e, t), e = t;
        }
      }, e.prototype.getValueAt = function (e) {
        return this.getElementValue(this.priorityQueue[e]);
      }, e.prototype.less = function (e, t) {
        return this.getValueAt(e) < this.getValueAt(t);
      }, e.prototype.exchange = function (e, t) {
        var n = this.priorityQueue[e];
        this.priorityQueue[e] = this.priorityQueue[t], this.priorityQueue[t] = n;
      }, e;
    }();

    function scoreIsMaximumInLocalWindow(e, t, n, r, o, i) {
      for (var s = i.shape, u = s[0], a = s[1], l = !0, p = Math.max(n - o, 0), c = Math.min(n + o + 1, u), f = p; f < c; ++f) {
        for (var d = Math.max(r - o, 0), h = Math.min(r + o + 1, a), m = d; m < h; ++m) if (i.get(f, m, e) > t) {
          l = !1;
          break;
        }

        if (!l) break;
      }

      return l;
    }

    function buildPartWithScoreQueue(e, t, n) {
      for (var r = n.shape, o = r[0], i = r[1], s = r[2], u = new MaxHeap(o * i * s, function (e) {
        return e.score;
      }), a = 0; a < o; ++a) for (var l = 0; l < i; ++l) for (var p = 0; p < s; ++p) {
        var c = n.get(a, l, p);
        c < e || scoreIsMaximumInLocalWindow(p, c, a, l, t, n) && u.enqueue({
          score: c,
          part: {
            heatmapY: a,
            heatmapX: l,
            id: p
          }
        });
      }

      return u;
    }

    var partNames = ["nose", "leftEye", "rightEye", "leftEar", "rightEar", "leftShoulder", "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", "leftHip", "rightHip", "leftKnee", "rightKnee", "leftAnkle", "rightAnkle"],
      NUM_KEYPOINTS = partNames.length,
      partIds = partNames.reduce(function (e, t, n) {
        return e[t] = n, e;
      }, {}),
      connectedPartNames = [["leftHip", "leftShoulder"], ["leftElbow", "leftShoulder"], ["leftElbow", "leftWrist"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["rightHip", "rightShoulder"], ["rightElbow", "rightShoulder"], ["rightElbow", "rightWrist"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"], ["leftShoulder", "rightShoulder"], ["leftHip", "rightHip"]],
      poseChain = [["nose", "leftEye"], ["leftEye", "leftEar"], ["nose", "rightEye"], ["rightEye", "rightEar"], ["nose", "leftShoulder"], ["leftShoulder", "leftElbow"], ["leftElbow", "leftWrist"], ["leftShoulder", "leftHip"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["nose", "rightShoulder"], ["rightShoulder", "rightElbow"], ["rightElbow", "rightWrist"], ["rightShoulder", "rightHip"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"]],
      connectedPartIndices = connectedPartNames.map(function (e) {
        var t = e[0],
          n = e[1];
        return [partIds[t], partIds[n]];
      }),
      partChannels = ["left_face", "right_face", "right_upper_leg_front", "right_lower_leg_back", "right_upper_leg_back", "left_lower_leg_front", "left_upper_leg_front", "left_upper_leg_back", "left_lower_leg_back", "right_feet", "right_lower_leg_front", "left_feet", "torso_front", "torso_back", "right_upper_arm_front", "right_upper_arm_back", "right_lower_arm_back", "left_lower_arm_front", "left_upper_arm_front", "left_upper_arm_back", "left_lower_arm_back", "right_hand", "right_lower_arm_front", "left_hand"];
    exports.partChannels = partChannels;
    exports.poseChain = poseChain;
    exports.partIds = partIds;
    exports.partNames = partNames;

    function getOffsetPoint(e, t, n, r) {
      return {
        y: r.get(e, t, n),
        x: r.get(e, t, n + NUM_KEYPOINTS)
      };
    }

    function getImageCoords(e, t, n) {
      var r = getOffsetPoint(e.heatmapY, e.heatmapX, e.id, n),
        o = r.y,
        i = r.x;
      return {
        x: e.heatmapX * t + i,
        y: e.heatmapY * t + o
      };
    }

    function clamp(e, t, n) {
      return e < t ? t : e > n ? n : e;
    }

    function squaredDistance(e, t, n, r) {
      var o = n - e,
        i = r - t;
      return o * o + i * i;
    }

    function addVectors(e, t) {
      return {
        x: e.x + t.x,
        y: e.y + t.y
      };
    }

    var parentChildrenTuples = poseChain.map(function (e) {
      var t = e[0],
        n = e[1];
      return [partIds[t], partIds[n]];
    }),
      parentToChildEdges = parentChildrenTuples.map(function (e) {
        return e[1];
      }),
      childToParentEdges = parentChildrenTuples.map(function (e) {
        return e[0];
      });

    function getDisplacement(e, t, n) {
      var r = n.shape[2] / 2;
      return {
        y: n.get(t.y, t.x, e),
        x: n.get(t.y, t.x, r + e)
      };
    }

    function getStridedIndexNearPoint(e, t, n, r) {
      return {
        y: clamp(Math.round(e.y / t), 0, n - 1),
        x: clamp(Math.round(e.x / t), 0, r - 1)
      };
    }

    function traverseToTargetKeypoint(e, t, n, r, o, i, s, u) {
      void 0 === u && (u = 2);

      for (var a = r.shape, l = a[0], p = a[1], c = getDisplacement(e, getStridedIndexNearPoint(t.position, i, l, p), s), f = addVectors(t.position, c), d = 0; d < u; d++) {
        var h = getStridedIndexNearPoint(f, i, l, p),
          m = getOffsetPoint(h.y, h.x, n, o);
        f = addVectors({
          x: h.x * i,
          y: h.y * i
        }, {
          x: m.x,
          y: m.y
        });
      }

      var g = getStridedIndexNearPoint(f, i, l, p),
        _ = r.get(g.y, g.x, n);

      return {
        position: f,
        part: partNames[n],
        score: _
      };
    }

    function decodePose(e, t, n, r, o, i) {
      var s = t.shape[2],
        u = parentToChildEdges.length,
        a = new Array(s),
        l = e.part,
        p = e.score,
        c = getImageCoords(l, r, n);
      a[l.id] = {
        score: p,
        part: partNames[l.id],
        position: c
      };

      for (var f = u - 1; f >= 0; --f) {
        var d = parentToChildEdges[f],
          h = childToParentEdges[f];
        a[d] && !a[h] && (a[h] = traverseToTargetKeypoint(f, a[d], h, t, n, r, i));
      }

      for (f = 0; f < u; ++f) {
        d = childToParentEdges[f], h = parentToChildEdges[f];
        a[d] && !a[h] && (a[h] = traverseToTargetKeypoint(f, a[d], h, t, n, r, o));
      }

      return a;
    }

    function withinNmsRadiusOfCorrespondingPoint(e, t, n, r) {
      var o = n.x,
        i = n.y;
      return e.some(function (e) {
        var n = e.keypoints[r].position;
        return squaredDistance(i, o, n.y, n.x) <= t;
      });
    }

    function getInstanceScore(e, t, n) {
      return n.reduce(function (n, r, o) {
        var i = r.position,
          s = r.score;
        return withinNmsRadiusOfCorrespondingPoint(e, t, i, o) || (n += s), n;
      }, 0) / n.length;
    }

    var kLocalMaximumRadius = 1;

    function decodeMultiplePoses(e, t, n, r, o, i, s, u) {
      void 0 === s && (s = .5), void 0 === u && (u = 20);

      for (var a = [], l = buildPartWithScoreQueue(s, kLocalMaximumRadius, e), p = u * u; a.length < i && !l.empty();) {
        var c = l.dequeue();

        if (!withinNmsRadiusOfCorrespondingPoint(a, p, getImageCoords(c.part, o, t), c.part.id)) {
          var f = decodePose(c, e, t, o, n, r),
            d = getInstanceScore(a, p, f);
          a.push({
            keypoints: f,
            score: d
          });
        }
      }

      return a;
    }

    function mod(e, t) {
      return (0, tf.tidy)(function () {
        var n = e.div((0, tf.scalar)(t, "int32"));
        return e.sub(n.mul((0, tf.scalar)(t, "int32")));
      });
    }

    function argmax2d(e) {
      var t = e.shape,
        n = t[0],
        r = t[1],
        o = t[2];
      return (0, tf.tidy)(function () {
        var t = e.reshape([n * r, o]).argMax(0),
          i = t.div((0, tf.scalar)(r, "int32")).expandDims(1),
          s = mod(t, r).expandDims(1);
        return (0, tf.concat)([i, s], 1);
      });
    }

    function getPointsConfidence(e, t) {
      for (var n = t.shape[0], r = new Float32Array(n), o = 0; o < n; o++) {
        var i = t.get(o, 0),
          s = t.get(o, 1);
        r[o] = e.get(i, s, o);
      }

      return r;
    }

    function getOffsetPoint$1(e, t, n, r) {
      return {
        y: r.get(e, t, n),
        x: r.get(e, t, n + NUM_KEYPOINTS)
      };
    }

    function getOffsetVectors(e, t) {
      for (var n = [], r = 0; r < NUM_KEYPOINTS; r++) {
        var o = getOffsetPoint$1(e.get(r, 0).valueOf(), e.get(r, 1).valueOf(), r, t),
          i = o.x,
          s = o.y;
        n.push(s), n.push(i);
      }

      return (0, tf.tensor2d)(n, [NUM_KEYPOINTS, 2]);
    }

    function getOffsetPoints(e, t, n) {
      return (0, tf.tidy)(function () {
        var r = getOffsetVectors(e, n);
        return e.toTensor().mul((0, tf.scalar)(t, "int32")).toFloat().add(r);
      });
    }

    function decodeSinglePose(e, t, n) {
      return __awaiter(this, void 0, void 0, function () {
        var r, o, i, s, u, a, l, p, c, f;
        return __generator(this, function (d) {
          switch (d.label) {
            case 0:
              return r = 0, o = argmax2d(e), [4, Promise.all([e.buffer(), t.buffer(), o.buffer()])];

            case 1:
              return i = d.sent(), s = i[0], u = i[1], a = i[2], [4, (l = getOffsetPoints(a, n, u)).buffer()];

            case 2:
              return p = d.sent(), c = Array.from(getPointsConfidence(s, a)), f = c.map(function (e, t) {
                return r += e, {
                  position: {
                    y: p.get(t, 0),
                    x: p.get(t, 1)
                  },
                  part: partNames[t],
                  score: e
                };
              }), o.dispose(), l.dispose(), [2, {
                keypoints: f,
                score: r / f.length
              }];
          }
        });
      });
    }

    // var MOBILENET_BASE_URL = "https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",
    var MOBILENET_BASE_URL = "https://cocorobo.cn/model/posenet/",
      RESNET50_BASE_URL = "https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";

    function resNet50Checkpoint(e, t) {
      var n = "model-stride" + e + ".json";
      return 4 === t ? RESNET50_BASE_URL + "float/" + n : RESNET50_BASE_URL + "quant" + t + "/" + n;
    }

    function mobileNetCheckpoint(e, t, n) {
      var r = {
        1: "100",
        .75: "075",
        .5: "050"
      },
        o = "model-stride" + e + ".json";
      return 4 === n ? MOBILENET_BASE_URL + "float/" + r[t] + "/" + o : MOBILENET_BASE_URL + o;
    }

    var imageNetMean = [-123.15, -115.9, -103.06],
      ResNet = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.preprocessInput = function (e) {
          return e.add(imageNetMean);
        }, t.prototype.nameOutputResults = function (e) {
          var t = e[0],
            n = e[1];
          return {
            offsets: e[2],
            heatmap: e[3],
            displacementFwd: t,
            displacementBwd: n
          };
        }, t;
      }(BaseModel);

    function eitherPointDoesntMeetConfidence(e, t, n) {
      return e < n || t < n;
    }

    function getAdjacentKeyPoints(e, t) {
      return connectedPartIndices.reduce(function (n, r) {
        var o = r[0],
          i = r[1];
        return eitherPointDoesntMeetConfidence(e[o].score, e[i].score, t) ? n : (n.push([e[o], e[i]]), n);
      }, []);
    }

    var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
      POSITIVE_INFINITY = Number.POSITIVE_INFINITY;

    function getBoundingBox(e) {
      return e.reduce(function (e, t) {
        var n = e.maxX,
          r = e.maxY,
          o = e.minX,
          i = e.minY,
          s = t.position,
          u = s.x,
          a = s.y;
        return {
          maxX: Math.max(n, u),
          maxY: Math.max(r, a),
          minX: Math.min(o, u),
          minY: Math.min(i, a)
        };
      }, {
        maxX: NEGATIVE_INFINITY,
        maxY: NEGATIVE_INFINITY,
        minX: POSITIVE_INFINITY,
        minY: POSITIVE_INFINITY
      });
    }

    function getBoundingBoxPoints(e) {
      var t = getBoundingBox(e),
        n = t.minX,
        r = t.minY,
        o = t.maxX,
        i = t.maxY;
      return [{
        x: n,
        y: r
      }, {
        x: o,
        y: r
      }, {
        x: o,
        y: i
      }, {
        x: n,
        y: i
      }];
    }

    function toTensorBuffers3D(e) {
      return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (t) {
          return [2, Promise.all(e.map(function (e) {
            return e.buffer();
          }))];
        });
      });
    }

    function scalePose(e, t, n, r, o) {
      return void 0 === r && (r = 0), void 0 === o && (o = 0), {
        score: e.score,
        keypoints: e.keypoints.map(function (e) {
          var i = e.score,
            s = e.part,
            u = e.position;
          return {
            score: i,
            part: s,
            position: {
              x: u.x * n + o,
              y: u.y * t + r
            }
          };
        })
      };
    }

    function scalePoses(e, t, n, r, o) {
      return void 0 === r && (r = 0), void 0 === o && (o = 0), 1 === n && 1 === t && 0 === r && 0 === o ? e : e.map(function (e) {
        return scalePose(e, t, n, r, o);
      });
    }

    function flipPoseHorizontal(e, t) {
      return {
        score: e.score,
        keypoints: e.keypoints.map(function (e) {
          var n = e.score,
            r = e.part,
            o = e.position;
          return {
            score: n,
            part: r,
            position: {
              x: t - 1 - o.x,
              y: o.y
            }
          };
        })
      };
    }

    function flipPosesHorizontal(e, t) {
      return t <= 0 ? e : e.map(function (e) {
        return flipPoseHorizontal(e, t);
      });
    }

    function toValidInputResolution(e, t) {
      return isValidInputResolution(e, t) ? e : Math.floor(e / t) * t + 1;
    }

    function validateInputResolution(e) {
      tf.util.assert("number" == typeof e || "object" == typeof e, function () {
        return "Invalid inputResolution " + e + ". Should be a number or an object with width and height";
      }), "object" == typeof e && (tf.util.assert("number" == typeof e.width, function () {
        return "inputResolution.width has a value of " + e.width + " which is invalid; it must be a number";
      }), tf.util.assert("number" == typeof e.height, function () {
        return "inputResolution.height has a value of " + e.height + " which is invalid; it must be a number";
      }));
    }

    function getValidInputResolutionDimensions(e, t) {
      return validateInputResolution(e), "object" == typeof e ? [toValidInputResolution(e.height, t), toValidInputResolution(e.width, t)] : [toValidInputResolution(e, t), toValidInputResolution(e, t)];
    }

    var VALID_OUTPUT_STRIDES = [8, 16, 32];

    function assertValidOutputStride(e) {
      tf.util.assert("number" == typeof e, function () {
        return "outputStride is not a number";
      }), tf.util.assert(VALID_OUTPUT_STRIDES.indexOf(e) >= 0, function () {
        return "outputStride of " + e + " is invalid. It must be either 8, 16, or 32";
      });
    }

    function isValidInputResolution(e, t) {
      return (e - 1) % t == 0;
    }

    function assertValidResolution(e, t) {
      tf.util.assert("number" == typeof e[0] && "number" == typeof e[1], function () {
        return "both resolution values must be a number but had values " + e;
      }), tf.util.assert(isValidInputResolution(e[0], t), function () {
        return "height of " + e[0] + " is invalid for output stride " + t + ".";
      }), tf.util.assert(isValidInputResolution(e[1], t), function () {
        return "width of " + e[1] + " is invalid for output stride " + t + ".";
      });
    }

    function getInputTensorDimensions(e) {
      return e instanceof tf.Tensor ? [e.shape[0], e.shape[1]] : [e.height, e.width];
    }

    function toInputTensor(e) {
      return e instanceof tf.Tensor ? e : tf.browser.fromPixels(e);
    }

    function padAndResizeTo(e, t) {
      var n = t[0],
        r = t[1],
        o = getInputTensorDimensions(e),
        i = o[0],
        s = o[1],
        u = r / n,
        a = [0, 0, 0, 0],
        l = a[0],
        p = a[1],
        c = a[2],
        f = a[3];
      return s / i < u ? (l = 0, p = 0, c = Math.round(.5 * (u * i - s)), f = Math.round(.5 * (u * i - s))) : (l = Math.round(.5 * (1 / u * s - i)), p = Math.round(.5 * (1 / u * s - i)), c = 0, f = 0), {
        resized: (0, tf.tidy)(function () {
          var t = toInputTensor(e);
          return (t = (0, tf.pad3d)(t, [[l, p], [c, f], [0, 0]])).resizeBilinear([n, r]);
        }),
        padding: {
          top: l,
          left: c,
          right: f,
          bottom: p
        }
      };
    }

    function scaleAndFlipPoses(e, t, n, r, o) {
      var i = t[0],
        s = t[1],
        u = n[0],
        a = n[1],
        l = scalePoses(e, (i + r.top + r.bottom) / u, (s + r.left + r.right) / a, -r.top, -r.left);
      return o ? flipPosesHorizontal(l, s) : l;
    }

    var MOBILENET_V1_CONFIG = {
      architecture: "MobileNetV1",
      outputStride: 16,
      multiplier: .75,
      inputResolution: 257
    },
      VALID_ARCHITECTURE = ["MobileNetV1", "ResNet50"],
      VALID_STRIDE = {
        MobileNetV1: [8, 16, 32],
        ResNet50: [32, 16]
      },
      VALID_MULTIPLIER = {
        MobileNetV1: [.5, .75, 1],
        ResNet50: [1]
      },
      VALID_QUANT_BYTES = [1, 2, 4];

    function validateModelConfig(e) {
      if (null == (e = e || MOBILENET_V1_CONFIG).architecture && (e.architecture = "MobileNetV1"), VALID_ARCHITECTURE.indexOf(e.architecture) < 0) throw new Error("Invalid architecture " + e.architecture + ". Should be one of " + VALID_ARCHITECTURE);
      if (null == e.inputResolution && (e.inputResolution = 257), validateInputResolution(e.inputResolution), null == e.outputStride && (e.outputStride = 16), VALID_STRIDE[e.architecture].indexOf(e.outputStride) < 0) throw new Error("Invalid outputStride " + e.outputStride + ". Should be one of " + VALID_STRIDE[e.architecture] + " for architecutre " + e.architecture + ".");
      if (null == e.multiplier && (e.multiplier = 1), VALID_MULTIPLIER[e.architecture].indexOf(e.multiplier) < 0) throw new Error("Invalid multiplier " + e.multiplier + ". Should be one of " + VALID_MULTIPLIER[e.architecture] + " for architecutre " + e.architecture + ".");
      if (null == e.quantBytes && (e.quantBytes = 4), VALID_QUANT_BYTES.indexOf(e.quantBytes) < 0) throw new Error("Invalid quantBytes " + e.quantBytes + ". Should be one of " + VALID_QUANT_BYTES + " for architecutre " + e.architecture + ".");
      return e;
    }

    var SINGLE_PERSON_INFERENCE_CONFIG = {
      flipHorizontal: !1
    },
      MULTI_PERSON_INFERENCE_CONFIG = {
        flipHorizontal: !1,
        maxDetections: 5,
        scoreThreshold: .5,
        nmsRadius: 20
      };

    function validateMultiPersonInputConfig(e) {
      var t = e.maxDetections,
        n = e.scoreThreshold,
        r = e.nmsRadius;
      if (t <= 0) throw new Error("Invalid maxDetections " + t + ". Should be > 0");
      if (n < 0 || n > 1) throw new Error("Invalid scoreThreshold " + n + ". Should be in range [0.0, 1.0]");
      if (r <= 0) throw new Error("Invalid nmsRadius " + r + ".");
    }

    var PoseNet = function () {
      function e(e, t) {
        assertValidOutputStride(e.outputStride), assertValidResolution(t, e.outputStride), this.baseModel = e, this.inputResolution = t;
      }

      return e.prototype.estimateMultiplePoses = function (e, t) {
        return void 0 === t && (t = MULTI_PERSON_INFERENCE_CONFIG), __awaiter(this, void 0, void 0, function () {
          var n, r, o, i, s, u, a, l, p, c, f, d, h, m, g, _, I, v, y, E, b;

          return __generator(this, function (N) {
            switch (N.label) {
              case 0:
                return n = __assign({}, MULTI_PERSON_INFERENCE_CONFIG, t), validateMultiPersonInputConfig(t), r = this.baseModel.outputStride, o = this.inputResolution, i = getInputTensorDimensions(e), s = i[0], u = i[1], a = padAndResizeTo(e, o), l = a.resized, p = a.padding, c = this.baseModel.predict(l), f = c.heatmapScores, d = c.offsets, h = c.displacementFwd, m = c.displacementBwd, [4, toTensorBuffers3D([f, d, h, m])];

              case 1:
                return g = N.sent(), _ = g[0], I = g[1], v = g[2], y = g[3], [4, decodeMultiplePoses(_, I, v, y, r, n.maxDetections, n.scoreThreshold, n.nmsRadius)];

              case 2:
                return E = N.sent(), b = scaleAndFlipPoses(E, [s, u], o, p, n.flipHorizontal), f.dispose(), d.dispose(), h.dispose(), m.dispose(), l.dispose(), [2, b];
            }
          });
        });
      }, e.prototype.estimateSinglePose = function (e, t) {
        return void 0 === t && (t = SINGLE_PERSON_INFERENCE_CONFIG), __awaiter(this, void 0, void 0, function () {
          var n, r, o, i, s, u, a, l, p, c, f, d, h, m, g, _;

          return __generator(this, function (I) {
            switch (I.label) {
              case 0:
                return n = __assign({}, SINGLE_PERSON_INFERENCE_CONFIG, t), r = this.baseModel.outputStride, o = this.inputResolution, i = getInputTensorDimensions(e), s = i[0], u = i[1], a = padAndResizeTo(e, o), l = a.resized, p = a.padding, c = this.baseModel.predict(l), f = c.heatmapScores, d = c.offsets, h = c.displacementFwd, m = c.displacementBwd, [4, decodeSinglePose(f, d, r)];

              case 1:
                return g = I.sent(), _ = scaleAndFlipPoses([g], [s, u], o, p, n.flipHorizontal), f.dispose(), d.dispose(), h.dispose(), m.dispose(), l.dispose(), [2, _[0]];
            }
          });
        });
      }, e.prototype.estimatePoses = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (n) {
            switch (n.label) {
              case 0:
                return "single-person" !== t.decodingMethod ? [3, 2] : [4, this.estimateSinglePose(e, t)];

              case 1:
                return [2, [n.sent()]];

              case 2:
                return [2, this.estimateMultiplePoses(e, t)];
            }
          });
        });
      }, e.prototype.dispose = function () {
        this.baseModel.dispose();
      }, e;
    }();

    exports.PoseNet = PoseNet;

    function loadMobileNet(e) {
      return __awaiter(this, void 0, void 0, function () {
        var t, n, r, o, i, s, u;
        return __generator(this, function (a) {
          switch (a.label) {
            case 0:
              if (t = e.outputStride, n = e.quantBytes, r = e.multiplier, null == tf) throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n        model.");
              return o = mobileNetCheckpoint(t, r, n), [4, (0, _tfjsConverter.loadGraphModel)(e.modelUrl || o)];

            case 1:
              return i = a.sent(), s = new MobileNet(i, t), u = getValidInputResolutionDimensions(e.inputResolution, s.outputStride), [2, new PoseNet(s, u)];
          }
        });
      });
    }

    function loadResNet(e) {
      return __awaiter(this, void 0, void 0, function () {
        var t, n, r, o, i, s;
        return __generator(this, function (u) {
          switch (u.label) {
            case 0:
              if (t = e.outputStride, n = e.quantBytes, null == tf) throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n        model.");
              return r = resNet50Checkpoint(t, n), [4, (0, _tfjsConverter.loadGraphModel)(e.modelUrl || r)];

            case 1:
              return o = u.sent(), i = new ResNet(o, t), s = getValidInputResolutionDimensions(e.inputResolution, i.outputStride), [2, new PoseNet(i, s)];
          }
        });
      });
    }

    function load(e) {
      return void 0 === e && (e = MOBILENET_V1_CONFIG), __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (t) {
          return "ResNet50" === (e = validateModelConfig(e)).architecture ? [2, loadResNet(e)] : "MobileNetV1" === e.architecture ? [2, loadMobileNet(e)] : [2, null];
        });
      });
    }
  }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "@tensorflow/tfjs-converter": "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js" }], "node_modules/dat.gui/build/dat.gui.module.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = exports.GUI = exports.gui = exports.dom = exports.controllers = exports.color = void 0;

    /**
     * dat-gui JavaScript Controller Library
     * http://code.google.com/p/dat-gui
     *
     * Copyright 2011 Data Arts Team, Google Creative Lab
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     */
    function ___$insertStyle(css) {
      if (!css) {
        return;
      }

      if (typeof window === 'undefined') {
        return;
      }

      var style = document.createElement('style');
      style.setAttribute('type', 'text/css');
      style.innerHTML = css;
      document.head.appendChild(style);
      return css;
    }

    function colorToString(color, forceCSSHex) {
      var colorFormat = color.__state.conversionName.toString();

      var r = Math.round(color.r);
      var g = Math.round(color.g);
      var b = Math.round(color.b);
      var a = color.a;
      var h = Math.round(color.h);
      var s = color.s.toFixed(1);
      var v = color.v.toFixed(1);

      if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') {
        var str = color.hex.toString(16);

        while (str.length < 6) {
          str = '0' + str;
        }

        return '#' + str;
      } else if (colorFormat === 'CSS_RGB') {
        return 'rgb(' + r + ',' + g + ',' + b + ')';
      } else if (colorFormat === 'CSS_RGBA') {
        return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
      } else if (colorFormat === 'HEX') {
        return '0x' + color.hex.toString(16);
      } else if (colorFormat === 'RGB_ARRAY') {
        return '[' + r + ',' + g + ',' + b + ']';
      } else if (colorFormat === 'RGBA_ARRAY') {
        return '[' + r + ',' + g + ',' + b + ',' + a + ']';
      } else if (colorFormat === 'RGB_OBJ') {
        return '{r:' + r + ',g:' + g + ',b:' + b + '}';
      } else if (colorFormat === 'RGBA_OBJ') {
        return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}';
      } else if (colorFormat === 'HSV_OBJ') {
        return '{h:' + h + ',s:' + s + ',v:' + v + '}';
      } else if (colorFormat === 'HSVA_OBJ') {
        return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}';
      }

      return 'unknown format';
    }

    var ARR_EACH = Array.prototype.forEach;
    var ARR_SLICE = Array.prototype.slice;
    var Common = {
      BREAK: {},
      extend: function extend(target) {
        this.each(ARR_SLICE.call(arguments, 1), function (obj) {
          var keys = this.isObject(obj) ? Object.keys(obj) : [];
          keys.forEach(function (key) {
            if (!this.isUndefined(obj[key])) {
              target[key] = obj[key];
            }
          }.bind(this));
        }, this);
        return target;
      },
      defaults: function defaults(target) {
        this.each(ARR_SLICE.call(arguments, 1), function (obj) {
          var keys = this.isObject(obj) ? Object.keys(obj) : [];
          keys.forEach(function (key) {
            if (this.isUndefined(target[key])) {
              target[key] = obj[key];
            }
          }.bind(this));
        }, this);
        return target;
      },
      compose: function compose() {
        var toCall = ARR_SLICE.call(arguments);
        return function () {
          var args = ARR_SLICE.call(arguments);

          for (var i = toCall.length - 1; i >= 0; i--) {
            args = [toCall[i].apply(this, args)];
          }

          return args[0];
        };
      },
      each: function each(obj, itr, scope) {
        if (!obj) {
          return;
        }

        if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
          obj.forEach(itr, scope);
        } else if (obj.length === obj.length + 0) {
          var key = void 0;
          var l = void 0;

          for (key = 0, l = obj.length; key < l; key++) {
            if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
              return;
            }
          }
        } else {
          for (var _key in obj) {
            if (itr.call(scope, obj[_key], _key) === this.BREAK) {
              return;
            }
          }
        }
      },
      defer: function defer(fnc) {
        setTimeout(fnc, 0);
      },
      debounce: function debounce(func, threshold, callImmediately) {
        var timeout = void 0;
        return function () {
          var obj = this;
          var args = arguments;

          function delayed() {
            timeout = null;
            if (!callImmediately) func.apply(obj, args);
          }

          var callNow = callImmediately || !timeout;
          clearTimeout(timeout);
          timeout = setTimeout(delayed, threshold);

          if (callNow) {
            func.apply(obj, args);
          }
        };
      },
      toArray: function toArray(obj) {
        if (obj.toArray) return obj.toArray();
        return ARR_SLICE.call(obj);
      },
      isUndefined: function isUndefined(obj) {
        return obj === undefined;
      },
      isNull: function isNull(obj) {
        return obj === null;
      },
      isNaN: function (_isNaN) {
        function isNaN(_x) {
          return _isNaN.apply(this, arguments);
        }

        isNaN.toString = function () {
          return _isNaN.toString();
        };

        return isNaN;
      }(function (obj) {
        return isNaN(obj);
      }),
      isArray: Array.isArray || function (obj) {
        return obj.constructor === Array;
      },
      isObject: function isObject(obj) {
        return obj === Object(obj);
      },
      isNumber: function isNumber(obj) {
        return obj === obj + 0;
      },
      isString: function isString(obj) {
        return obj === obj + '';
      },
      isBoolean: function isBoolean(obj) {
        return obj === false || obj === true;
      },
      isFunction: function isFunction(obj) {
        return Object.prototype.toString.call(obj) === '[object Function]';
      }
    };
    var INTERPRETATIONS = [{
      litmus: Common.isString,
      conversions: {
        THREE_CHAR_HEX: {
          read: function read(original) {
            var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);

            if (test === null) {
              return false;
            }

            return {
              space: 'HEX',
              hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0)
            };
          },
          write: colorToString
        },
        SIX_CHAR_HEX: {
          read: function read(original) {
            var test = original.match(/^#([A-F0-9]{6})$/i);

            if (test === null) {
              return false;
            }

            return {
              space: 'HEX',
              hex: parseInt('0x' + test[1].toString(), 0)
            };
          },
          write: colorToString
        },
        CSS_RGB: {
          read: function read(original) {
            var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);

            if (test === null) {
              return false;
            }

            return {
              space: 'RGB',
              r: parseFloat(test[1]),
              g: parseFloat(test[2]),
              b: parseFloat(test[3])
            };
          },
          write: colorToString
        },
        CSS_RGBA: {
          read: function read(original) {
            var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);

            if (test === null) {
              return false;
            }

            return {
              space: 'RGB',
              r: parseFloat(test[1]),
              g: parseFloat(test[2]),
              b: parseFloat(test[3]),
              a: parseFloat(test[4])
            };
          },
          write: colorToString
        }
      }
    }, {
      litmus: Common.isNumber,
      conversions: {
        HEX: {
          read: function read(original) {
            return {
              space: 'HEX',
              hex: original,
              conversionName: 'HEX'
            };
          },
          write: function write(color) {
            return color.hex;
          }
        }
      }
    }, {
      litmus: Common.isArray,
      conversions: {
        RGB_ARRAY: {
          read: function read(original) {
            if (original.length !== 3) {
              return false;
            }

            return {
              space: 'RGB',
              r: original[0],
              g: original[1],
              b: original[2]
            };
          },
          write: function write(color) {
            return [color.r, color.g, color.b];
          }
        },
        RGBA_ARRAY: {
          read: function read(original) {
            if (original.length !== 4) return false;
            return {
              space: 'RGB',
              r: original[0],
              g: original[1],
              b: original[2],
              a: original[3]
            };
          },
          write: function write(color) {
            return [color.r, color.g, color.b, color.a];
          }
        }
      }
    }, {
      litmus: Common.isObject,
      conversions: {
        RGBA_OBJ: {
          read: function read(original) {
            if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) {
              return {
                space: 'RGB',
                r: original.r,
                g: original.g,
                b: original.b,
                a: original.a
              };
            }

            return false;
          },
          write: function write(color) {
            return {
              r: color.r,
              g: color.g,
              b: color.b,
              a: color.a
            };
          }
        },
        RGB_OBJ: {
          read: function read(original) {
            if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) {
              return {
                space: 'RGB',
                r: original.r,
                g: original.g,
                b: original.b
              };
            }

            return false;
          },
          write: function write(color) {
            return {
              r: color.r,
              g: color.g,
              b: color.b
            };
          }
        },
        HSVA_OBJ: {
          read: function read(original) {
            if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) {
              return {
                space: 'HSV',
                h: original.h,
                s: original.s,
                v: original.v,
                a: original.a
              };
            }

            return false;
          },
          write: function write(color) {
            return {
              h: color.h,
              s: color.s,
              v: color.v,
              a: color.a
            };
          }
        },
        HSV_OBJ: {
          read: function read(original) {
            if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) {
              return {
                space: 'HSV',
                h: original.h,
                s: original.s,
                v: original.v
              };
            }

            return false;
          },
          write: function write(color) {
            return {
              h: color.h,
              s: color.s,
              v: color.v
            };
          }
        }
      }
    }];
    var result = void 0;
    var toReturn = void 0;

    var interpret = function interpret() {
      toReturn = false;
      var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0];
      Common.each(INTERPRETATIONS, function (family) {
        if (family.litmus(original)) {
          Common.each(family.conversions, function (conversion, conversionName) {
            result = conversion.read(original);

            if (toReturn === false && result !== false) {
              toReturn = result;
              result.conversionName = conversionName;
              result.conversion = conversion;
              return Common.BREAK;
            }
          });
          return Common.BREAK;
        }
      });
      return toReturn;
    };

    var tmpComponent = void 0;
    var ColorMath = {
      hsv_to_rgb: function hsv_to_rgb(h, s, v) {
        var hi = Math.floor(h / 60) % 6;
        var f = h / 60 - Math.floor(h / 60);
        var p = v * (1.0 - s);
        var q = v * (1.0 - f * s);
        var t = v * (1.0 - (1.0 - f) * s);
        var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi];
        return {
          r: c[0] * 255,
          g: c[1] * 255,
          b: c[2] * 255
        };
      },
      rgb_to_hsv: function rgb_to_hsv(r, g, b) {
        var min = Math.min(r, g, b);
        var max = Math.max(r, g, b);
        var delta = max - min;
        var h = void 0;
        var s = void 0;

        if (max !== 0) {
          s = delta / max;
        } else {
          return {
            h: NaN,
            s: 0,
            v: 0
          };
        }

        if (r === max) {
          h = (g - b) / delta;
        } else if (g === max) {
          h = 2 + (b - r) / delta;
        } else {
          h = 4 + (r - g) / delta;
        }

        h /= 6;

        if (h < 0) {
          h += 1;
        }

        return {
          h: h * 360,
          s: s,
          v: max / 255
        };
      },
      rgb_to_hex: function rgb_to_hex(r, g, b) {
        var hex = this.hex_with_component(0, 2, r);
        hex = this.hex_with_component(hex, 1, g);
        hex = this.hex_with_component(hex, 0, b);
        return hex;
      },
      component_from_hex: function component_from_hex(hex, componentIndex) {
        return hex >> componentIndex * 8 & 0xFF;
      },
      hex_with_component: function hex_with_component(hex, componentIndex, value) {
        return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent);
      }
    };

    var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
      return typeof obj;
    } : function (obj) {
      return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
    };

    var classCallCheck = function (instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    };

    var createClass = function () {
      function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
          var descriptor = props[i];
          descriptor.enumerable = descriptor.enumerable || false;
          descriptor.configurable = true;
          if ("value" in descriptor) descriptor.writable = true;
          Object.defineProperty(target, descriptor.key, descriptor);
        }
      }

      return function (Constructor, protoProps, staticProps) {
        if (protoProps) defineProperties(Constructor.prototype, protoProps);
        if (staticProps) defineProperties(Constructor, staticProps);
        return Constructor;
      };
    }();

    var get = function get(object, property, receiver) {
      if (object === null) object = Function.prototype;
      var desc = Object.getOwnPropertyDescriptor(object, property);

      if (desc === undefined) {
        var parent = Object.getPrototypeOf(object);

        if (parent === null) {
          return undefined;
        } else {
          return get(parent, property, receiver);
        }
      } else if ("value" in desc) {
        return desc.value;
      } else {
        var getter = desc.get;

        if (getter === undefined) {
          return undefined;
        }

        return getter.call(receiver);
      }
    };

    var inherits = function (subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
      }

      subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
          value: subClass,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
      if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
    };

    var possibleConstructorReturn = function (self, call) {
      if (!self) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }

      return call && (typeof call === "object" || typeof call === "function") ? call : self;
    };

    var Color = function () {
      function Color() {
        classCallCheck(this, Color);
        this.__state = interpret.apply(this, arguments);

        if (this.__state === false) {
          throw new Error('Failed to interpret color arguments');
        }

        this.__state.a = this.__state.a || 1;
      }

      createClass(Color, [{
        key: 'toString',
        value: function toString() {
          return colorToString(this);
        }
      }, {
        key: 'toHexString',
        value: function toHexString() {
          return colorToString(this, true);
        }
      }, {
        key: 'toOriginal',
        value: function toOriginal() {
          return this.__state.conversion.write(this);
        }
      }]);
      return Color;
    }();

    function defineRGBComponent(target, component, componentHexIndex) {
      Object.defineProperty(target, component, {
        get: function get$$1() {
          if (this.__state.space === 'RGB') {
            return this.__state[component];
          }

          Color.recalculateRGB(this, component, componentHexIndex);
          return this.__state[component];
        },
        set: function set$$1(v) {
          if (this.__state.space !== 'RGB') {
            Color.recalculateRGB(this, component, componentHexIndex);
            this.__state.space = 'RGB';
          }

          this.__state[component] = v;
        }
      });
    }

    function defineHSVComponent(target, component) {
      Object.defineProperty(target, component, {
        get: function get$$1() {
          if (this.__state.space === 'HSV') {
            return this.__state[component];
          }

          Color.recalculateHSV(this);
          return this.__state[component];
        },
        set: function set$$1(v) {
          if (this.__state.space !== 'HSV') {
            Color.recalculateHSV(this);
            this.__state.space = 'HSV';
          }

          this.__state[component] = v;
        }
      });
    }

    Color.recalculateRGB = function (color, component, componentHexIndex) {
      if (color.__state.space === 'HEX') {
        color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex);
      } else if (color.__state.space === 'HSV') {
        Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v));
      } else {
        throw new Error('Corrupted color state');
      }
    };

    Color.recalculateHSV = function (color) {
      var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b);
      Common.extend(color.__state, {
        s: result.s,
        v: result.v
      });

      if (!Common.isNaN(result.h)) {
        color.__state.h = result.h;
      } else if (Common.isUndefined(color.__state.h)) {
        color.__state.h = 0;
      }
    };

    Color.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a'];
    defineRGBComponent(Color.prototype, 'r', 2);
    defineRGBComponent(Color.prototype, 'g', 1);
    defineRGBComponent(Color.prototype, 'b', 0);
    defineHSVComponent(Color.prototype, 'h');
    defineHSVComponent(Color.prototype, 's');
    defineHSVComponent(Color.prototype, 'v');
    Object.defineProperty(Color.prototype, 'a', {
      get: function get$$1() {
        return this.__state.a;
      },
      set: function set$$1(v) {
        this.__state.a = v;
      }
    });
    Object.defineProperty(Color.prototype, 'hex', {
      get: function get$$1() {
        if (!this.__state.space !== 'HEX') {
          this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b);
        }

        return this.__state.hex;
      },
      set: function set$$1(v) {
        this.__state.space = 'HEX';
        this.__state.hex = v;
      }
    });

    var Controller = function () {
      function Controller(object, property) {
        classCallCheck(this, Controller);
        this.initialValue = object[property];
        this.domElement = document.createElement('div');
        this.object = object;
        this.property = property;
        this.__onChange = undefined;
        this.__onFinishChange = undefined;
      }

      createClass(Controller, [{
        key: 'onChange',
        value: function onChange(fnc) {
          this.__onChange = fnc;
          return this;
        }
      }, {
        key: 'onFinishChange',
        value: function onFinishChange(fnc) {
          this.__onFinishChange = fnc;
          return this;
        }
      }, {
        key: 'setValue',
        value: function setValue(newValue) {
          this.object[this.property] = newValue;

          if (this.__onChange) {
            this.__onChange.call(this, newValue);
          }

          this.updateDisplay();
          return this;
        }
      }, {
        key: 'getValue',
        value: function getValue() {
          return this.object[this.property];
        }
      }, {
        key: 'updateDisplay',
        value: function updateDisplay() {
          return this;
        }
      }, {
        key: 'isModified',
        value: function isModified() {
          return this.initialValue !== this.getValue();
        }
      }]);
      return Controller;
    }();

    var EVENT_MAP = {
      HTMLEvents: ['change'],
      MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'],
      KeyboardEvents: ['keydown']
    };
    var EVENT_MAP_INV = {};
    Common.each(EVENT_MAP, function (v, k) {
      Common.each(v, function (e) {
        EVENT_MAP_INV[e] = k;
      });
    });
    var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/;

    function cssValueToPixels(val) {
      if (val === '0' || Common.isUndefined(val)) {
        return 0;
      }

      var match = val.match(CSS_VALUE_PIXELS);

      if (!Common.isNull(match)) {
        return parseFloat(match[1]);
      }

      return 0;
    }

    var dom = {
      makeSelectable: function makeSelectable(elem, selectable) {
        if (elem === undefined || elem.style === undefined) return;
        elem.onselectstart = selectable ? function () {
          return false;
        } : function () { };
        elem.style.MozUserSelect = selectable ? 'auto' : 'none';
        elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none';
        elem.unselectable = selectable ? 'on' : 'off';
      },
      makeFullscreen: function makeFullscreen(elem, hor, vert) {
        var vertical = vert;
        var horizontal = hor;

        if (Common.isUndefined(horizontal)) {
          horizontal = true;
        }

        if (Common.isUndefined(vertical)) {
          vertical = true;
        }

        elem.style.position = 'absolute';

        if (horizontal) {
          elem.style.left = 0;
          elem.style.right = 0;
        }

        if (vertical) {
          elem.style.top = 0;
          elem.style.bottom = 0;
        }
      },
      fakeEvent: function fakeEvent(elem, eventType, pars, aux) {
        var params = pars || {};
        var className = EVENT_MAP_INV[eventType];

        if (!className) {
          throw new Error('Event type ' + eventType + ' not supported.');
        }

        var evt = document.createEvent(className);

        switch (className) {
          case 'MouseEvents':
            {
              var clientX = params.x || params.clientX || 0;
              var clientY = params.y || params.clientY || 0;
              evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, 0, clientX, clientY, false, false, false, false, 0, null);
              break;
            }

          case 'KeyboardEvents':
            {
              var init = evt.initKeyboardEvent || evt.initKeyEvent;
              Common.defaults(params, {
                cancelable: true,
                ctrlKey: false,
                altKey: false,
                shiftKey: false,
                metaKey: false,
                keyCode: undefined,
                charCode: undefined
              });
              init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode);
              break;
            }

          default:
            {
              evt.initEvent(eventType, params.bubbles || false, params.cancelable || true);
              break;
            }
        }

        Common.defaults(evt, aux);
        elem.dispatchEvent(evt);
      },
      bind: function bind(elem, event, func, newBool) {
        var bool = newBool || false;

        if (elem.addEventListener) {
          elem.addEventListener(event, func, bool);
        } else if (elem.attachEvent) {
          elem.attachEvent('on' + event, func);
        }

        return dom;
      },
      unbind: function unbind(elem, event, func, newBool) {
        var bool = newBool || false;

        if (elem.removeEventListener) {
          elem.removeEventListener(event, func, bool);
        } else if (elem.detachEvent) {
          elem.detachEvent('on' + event, func);
        }

        return dom;
      },
      addClass: function addClass(elem, className) {
        if (elem.className === undefined) {
          elem.className = className;
        } else if (elem.className !== className) {
          var classes = elem.className.split(/ +/);

          if (classes.indexOf(className) === -1) {
            classes.push(className);
            elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, '');
          }
        }

        return dom;
      },
      removeClass: function removeClass(elem, className) {
        if (className) {
          if (elem.className === className) {
            elem.removeAttribute('class');
          } else {
            var classes = elem.className.split(/ +/);
            var index = classes.indexOf(className);

            if (index !== -1) {
              classes.splice(index, 1);
              elem.className = classes.join(' ');
            }
          }
        } else {
          elem.className = undefined;
        }

        return dom;
      },
      hasClass: function hasClass(elem, className) {
        return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false;
      },
      getWidth: function getWidth(elem) {
        var style = getComputedStyle(elem);
        return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width);
      },
      getHeight: function getHeight(elem) {
        var style = getComputedStyle(elem);
        return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height);
      },
      getOffset: function getOffset(el) {
        var elem = el;
        var offset = {
          left: 0,
          top: 0
        };

        if (elem.offsetParent) {
          do {
            offset.left += elem.offsetLeft;
            offset.top += elem.offsetTop;
            elem = elem.offsetParent;
          } while (elem);
        }

        return offset;
      },
      isActive: function isActive(elem) {
        return elem === document.activeElement && (elem.type || elem.href);
      }
    };

    var BooleanController = function (_Controller) {
      inherits(BooleanController, _Controller);

      function BooleanController(object, property) {
        classCallCheck(this, BooleanController);

        var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property));

        var _this = _this2;
        _this2.__prev = _this2.getValue();
        _this2.__checkbox = document.createElement('input');

        _this2.__checkbox.setAttribute('type', 'checkbox');

        function onChange() {
          _this.setValue(!_this.__prev);
        }

        dom.bind(_this2.__checkbox, 'change', onChange, false);

        _this2.domElement.appendChild(_this2.__checkbox);

        _this2.updateDisplay();

        return _this2;
      }

      createClass(BooleanController, [{
        key: 'setValue',
        value: function setValue(v) {
          var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v);

          if (this.__onFinishChange) {
            this.__onFinishChange.call(this, this.getValue());
          }

          this.__prev = this.getValue();
          return toReturn;
        }
      }, {
        key: 'updateDisplay',
        value: function updateDisplay() {
          if (this.getValue() === true) {
            this.__checkbox.setAttribute('checked', 'checked');

            this.__checkbox.checked = true;
            this.__prev = true;
          } else {
            this.__checkbox.checked = false;
            this.__prev = false;
          }

          return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this);
        }
      }]);
      return BooleanController;
    }(Controller);

    var OptionController = function (_Controller) {
      inherits(OptionController, _Controller);

      function OptionController(object, property, opts) {
        classCallCheck(this, OptionController);

        var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property));

        var options = opts;
        var _this = _this2;
        _this2.__select = document.createElement('select');

        if (Common.isArray(options)) {
          var map = {};
          Common.each(options, function (element) {
            map[element] = element;
          });
          options = map;
        }

        Common.each(options, function (value, key) {
          var opt = document.createElement('option');
          opt.innerHTML = key;
          opt.setAttribute('value', value);

          _this.__select.appendChild(opt);
        });

        _this2.updateDisplay();

        dom.bind(_this2.__select, 'change', function () {
          var desiredValue = this.options[this.selectedIndex].value;

          _this.setValue(desiredValue);
        });

        _this2.domElement.appendChild(_this2.__select);

        return _this2;
      }

      createClass(OptionController, [{
        key: 'setValue',
        value: function setValue(v) {
          var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v);

          if (this.__onFinishChange) {
            this.__onFinishChange.call(this, this.getValue());
          }

          return toReturn;
        }
      }, {
        key: 'updateDisplay',
        value: function updateDisplay() {
          if (dom.isActive(this.__select)) return this;
          this.__select.value = this.getValue();
          return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this);
        }
      }]);
      return OptionController;
    }(Controller);

    var StringController = function (_Controller) {
      inherits(StringController, _Controller);

      function StringController(object, property) {
        classCallCheck(this, StringController);

        var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property));

        var _this = _this2;

        function onChange() {
          _this.setValue(_this.__input.value);
        }

        function onBlur() {
          if (_this.__onFinishChange) {
            _this.__onFinishChange.call(_this, _this.getValue());
          }
        }

        _this2.__input = document.createElement('input');

        _this2.__input.setAttribute('type', 'text');

        dom.bind(_this2.__input, 'keyup', onChange);
        dom.bind(_this2.__input, 'change', onChange);
        dom.bind(_this2.__input, 'blur', onBlur);
        dom.bind(_this2.__input, 'keydown', function (e) {
          if (e.keyCode === 13) {
            this.blur();
          }
        });

        _this2.updateDisplay();

        _this2.domElement.appendChild(_this2.__input);

        return _this2;
      }

      createClass(StringController, [{
        key: 'updateDisplay',
        value: function updateDisplay() {
          if (!dom.isActive(this.__input)) {
            this.__input.value = this.getValue();
          }

          return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this);
        }
      }]);
      return StringController;
    }(Controller);

    function numDecimals(x) {
      var _x = x.toString();

      if (_x.indexOf('.') > -1) {
        return _x.length - _x.indexOf('.') - 1;
      }

      return 0;
    }

    var NumberController = function (_Controller) {
      inherits(NumberController, _Controller);

      function NumberController(object, property, params) {
        classCallCheck(this, NumberController);

        var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property));

        var _params = params || {};

        _this.__min = _params.min;
        _this.__max = _params.max;
        _this.__step = _params.step;

        if (Common.isUndefined(_this.__step)) {
          if (_this.initialValue === 0) {
            _this.__impliedStep = 1;
          } else {
            _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10;
          }
        } else {
          _this.__impliedStep = _this.__step;
        }

        _this.__precision = numDecimals(_this.__impliedStep);
        return _this;
      }

      createClass(NumberController, [{
        key: 'setValue',
        value: function setValue(v) {
          var _v = v;

          if (this.__min !== undefined && _v < this.__min) {
            _v = this.__min;
          } else if (this.__max !== undefined && _v > this.__max) {
            _v = this.__max;
          }

          if (this.__step !== undefined && _v % this.__step !== 0) {
            _v = Math.round(_v / this.__step) * this.__step;
          }

          return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v);
        }
      }, {
        key: 'min',
        value: function min(minValue) {
          this.__min = minValue;
          return this;
        }
      }, {
        key: 'max',
        value: function max(maxValue) {
          this.__max = maxValue;
          return this;
        }
      }, {
        key: 'step',
        value: function step(stepValue) {
          this.__step = stepValue;
          this.__impliedStep = stepValue;
          this.__precision = numDecimals(stepValue);
          return this;
        }
      }]);
      return NumberController;
    }(Controller);

    function roundToDecimal(value, decimals) {
      var tenTo = Math.pow(10, decimals);
      return Math.round(value * tenTo) / tenTo;
    }

    var NumberControllerBox = function (_NumberController) {
      inherits(NumberControllerBox, _NumberController);

      function NumberControllerBox(object, property, params) {
        classCallCheck(this, NumberControllerBox);

        var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params));

        _this2.__truncationSuspended = false;
        var _this = _this2;
        var prevY = void 0;

        function onChange() {
          var attempted = parseFloat(_this.__input.value);

          if (!Common.isNaN(attempted)) {
            _this.setValue(attempted);
          }
        }

        function onFinish() {
          if (_this.__onFinishChange) {
            _this.__onFinishChange.call(_this, _this.getValue());
          }
        }

        function onBlur() {
          onFinish();
        }

        function onMouseDrag(e) {
          var diff = prevY - e.clientY;

          _this.setValue(_this.getValue() + diff * _this.__impliedStep);

          prevY = e.clientY;
        }

        function onMouseUp() {
          dom.unbind(window, 'mousemove', onMouseDrag);
          dom.unbind(window, 'mouseup', onMouseUp);
          onFinish();
        }

        function onMouseDown(e) {
          dom.bind(window, 'mousemove', onMouseDrag);
          dom.bind(window, 'mouseup', onMouseUp);
          prevY = e.clientY;
        }

        _this2.__input = document.createElement('input');

        _this2.__input.setAttribute('type', 'text');

        dom.bind(_this2.__input, 'change', onChange);
        dom.bind(_this2.__input, 'blur', onBlur);
        dom.bind(_this2.__input, 'mousedown', onMouseDown);
        dom.bind(_this2.__input, 'keydown', function (e) {
          if (e.keyCode === 13) {
            _this.__truncationSuspended = true;
            this.blur();
            _this.__truncationSuspended = false;
            onFinish();
          }
        });

        _this2.updateDisplay();

        _this2.domElement.appendChild(_this2.__input);

        return _this2;
      }

      createClass(NumberControllerBox, [{
        key: 'updateDisplay',
        value: function updateDisplay() {
          this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);
          return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this);
        }
      }]);
      return NumberControllerBox;
    }(NumberController);

    function map(v, i1, i2, o1, o2) {
      return o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
    }

    var NumberControllerSlider = function (_NumberController) {
      inherits(NumberControllerSlider, _NumberController);

      function NumberControllerSlider(object, property, min, max, step) {
        classCallCheck(this, NumberControllerSlider);

        var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, {
          min: min,
          max: max,
          step: step
        }));

        var _this = _this2;
        _this2.__background = document.createElement('div');
        _this2.__foreground = document.createElement('div');
        dom.bind(_this2.__background, 'mousedown', onMouseDown);
        dom.bind(_this2.__background, 'touchstart', onTouchStart);
        dom.addClass(_this2.__background, 'slider');
        dom.addClass(_this2.__foreground, 'slider-fg');

        function onMouseDown(e) {
          document.activeElement.blur();
          dom.bind(window, 'mousemove', onMouseDrag);
          dom.bind(window, 'mouseup', onMouseUp);
          onMouseDrag(e);
        }

        function onMouseDrag(e) {
          e.preventDefault();

          var bgRect = _this.__background.getBoundingClientRect();

          _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));

          return false;
        }

        function onMouseUp() {
          dom.unbind(window, 'mousemove', onMouseDrag);
          dom.unbind(window, 'mouseup', onMouseUp);

          if (_this.__onFinishChange) {
            _this.__onFinishChange.call(_this, _this.getValue());
          }
        }

        function onTouchStart(e) {
          if (e.touches.length !== 1) {
            return;
          }

          dom.bind(window, 'touchmove', onTouchMove);
          dom.bind(window, 'touchend', onTouchEnd);
          onTouchMove(e);
        }

        function onTouchMove(e) {
          var clientX = e.touches[0].clientX;

          var bgRect = _this.__background.getBoundingClientRect();

          _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max));
        }

        function onTouchEnd() {
          dom.unbind(window, 'touchmove', onTouchMove);
          dom.unbind(window, 'touchend', onTouchEnd);

          if (_this.__onFinishChange) {
            _this.__onFinishChange.call(_this, _this.getValue());
          }
        }

        _this2.updateDisplay();

        _this2.__background.appendChild(_this2.__foreground);

        _this2.domElement.appendChild(_this2.__background);

        return _this2;
      }

      createClass(NumberControllerSlider, [{
        key: 'updateDisplay',
        value: function updateDisplay() {
          var pct = (this.getValue() - this.__min) / (this.__max - this.__min);

          this.__foreground.style.width = pct * 100 + '%';
          return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this);
        }
      }]);
      return NumberControllerSlider;
    }(NumberController);

    var FunctionController = function (_Controller) {
      inherits(FunctionController, _Controller);

      function FunctionController(object, property, text) {
        classCallCheck(this, FunctionController);

        var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property));

        var _this = _this2;
        _this2.__button = document.createElement('div');
        _this2.__button.innerHTML = text === undefined ? 'Fire' : text;
        dom.bind(_this2.__button, 'click', function (e) {
          e.preventDefault();

          _this.fire();

          return false;
        });
        dom.addClass(_this2.__button, 'button');

        _this2.domElement.appendChild(_this2.__button);

        return _this2;
      }

      createClass(FunctionController, [{
        key: 'fire',
        value: function fire() {
          if (this.__onChange) {
            this.__onChange.call(this);
          }

          this.getValue().call(this.object);

          if (this.__onFinishChange) {
            this.__onFinishChange.call(this, this.getValue());
          }
        }
      }]);
      return FunctionController;
    }(Controller);

    var ColorController = function (_Controller) {
      inherits(ColorController, _Controller);

      function ColorController(object, property) {
        classCallCheck(this, ColorController);

        var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property));

        _this2.__color = new Color(_this2.getValue());
        _this2.__temp = new Color(0);
        var _this = _this2;
        _this2.domElement = document.createElement('div');
        dom.makeSelectable(_this2.domElement, false);
        _this2.__selector = document.createElement('div');
        _this2.__selector.className = 'selector';
        _this2.__saturation_field = document.createElement('div');
        _this2.__saturation_field.className = 'saturation-field';
        _this2.__field_knob = document.createElement('div');
        _this2.__field_knob.className = 'field-knob';
        _this2.__field_knob_border = '2px solid ';
        _this2.__hue_knob = document.createElement('div');
        _this2.__hue_knob.className = 'hue-knob';
        _this2.__hue_field = document.createElement('div');
        _this2.__hue_field.className = 'hue-field';
        _this2.__input = document.createElement('input');
        _this2.__input.type = 'text';
        _this2.__input_textShadow = '0 1px 1px ';
        dom.bind(_this2.__input, 'keydown', function (e) {
          if (e.keyCode === 13) {
            onBlur.call(this);
          }
        });
        dom.bind(_this2.__input, 'blur', onBlur);
        dom.bind(_this2.__selector, 'mousedown', function () {
          dom.addClass(this, 'drag').bind(window, 'mouseup', function () {
            dom.removeClass(_this.__selector, 'drag');
          });
        });
        dom.bind(_this2.__selector, 'touchstart', function () {
          dom.addClass(this, 'drag').bind(window, 'touchend', function () {
            dom.removeClass(_this.__selector, 'drag');
          });
        });
        var valueField = document.createElement('div');
        Common.extend(_this2.__selector.style, {
          width: '122px',
          height: '102px',
          padding: '3px',
          backgroundColor: '#222',
          boxShadow: '0px 1px 3px rgba(0,0,0,0.3)'
        });
        Common.extend(_this2.__field_knob.style, {
          position: 'absolute',
          width: '12px',
          height: '12px',
          border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'),
          boxShadow: '0px 1px 3px rgba(0,0,0,0.5)',
          borderRadius: '12px',
          zIndex: 1
        });
        Common.extend(_this2.__hue_knob.style, {
          position: 'absolute',
          width: '15px',
          height: '2px',
          borderRight: '4px solid #fff',
          zIndex: 1
        });
        Common.extend(_this2.__saturation_field.style, {
          width: '100px',
          height: '100px',
          border: '1px solid #555',
          marginRight: '3px',
          display: 'inline-block',
          cursor: 'pointer'
        });
        Common.extend(valueField.style, {
          width: '100%',
          height: '100%',
          background: 'none'
        });
        linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000');
        Common.extend(_this2.__hue_field.style, {
          width: '15px',
          height: '100px',
          border: '1px solid #555',
          cursor: 'ns-resize',
          position: 'absolute',
          top: '3px',
          right: '3px'
        });
        hueGradient(_this2.__hue_field);
        Common.extend(_this2.__input.style, {
          outline: 'none',
          textAlign: 'center',
          color: '#fff',
          border: 0,
          fontWeight: 'bold',
          textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)'
        });
        dom.bind(_this2.__saturation_field, 'mousedown', fieldDown);
        dom.bind(_this2.__saturation_field, 'touchstart', fieldDown);
        dom.bind(_this2.__field_knob, 'mousedown', fieldDown);
        dom.bind(_this2.__field_knob, 'touchstart', fieldDown);
        dom.bind(_this2.__hue_field, 'mousedown', fieldDownH);
        dom.bind(_this2.__hue_field, 'touchstart', fieldDownH);

        function fieldDown(e) {
          setSV(e);
          dom.bind(window, 'mousemove', setSV);
          dom.bind(window, 'touchmove', setSV);
          dom.bind(window, 'mouseup', fieldUpSV);
          dom.bind(window, 'touchend', fieldUpSV);
        }

        function fieldDownH(e) {
          setH(e);
          dom.bind(window, 'mousemove', setH);
          dom.bind(window, 'touchmove', setH);
          dom.bind(window, 'mouseup', fieldUpH);
          dom.bind(window, 'touchend', fieldUpH);
        }

        function fieldUpSV() {
          dom.unbind(window, 'mousemove', setSV);
          dom.unbind(window, 'touchmove', setSV);
          dom.unbind(window, 'mouseup', fieldUpSV);
          dom.unbind(window, 'touchend', fieldUpSV);
          onFinish();
        }

        function fieldUpH() {
          dom.unbind(window, 'mousemove', setH);
          dom.unbind(window, 'touchmove', setH);
          dom.unbind(window, 'mouseup', fieldUpH);
          dom.unbind(window, 'touchend', fieldUpH);
          onFinish();
        }

        function onBlur() {
          var i = interpret(this.value);

          if (i !== false) {
            _this.__color.__state = i;

            _this.setValue(_this.__color.toOriginal());
          } else {
            this.value = _this.__color.toString();
          }
        }

        function onFinish() {
          if (_this.__onFinishChange) {
            _this.__onFinishChange.call(_this, _this.__color.toOriginal());
          }
        }

        _this2.__saturation_field.appendChild(valueField);

        _this2.__selector.appendChild(_this2.__field_knob);

        _this2.__selector.appendChild(_this2.__saturation_field);

        _this2.__selector.appendChild(_this2.__hue_field);

        _this2.__hue_field.appendChild(_this2.__hue_knob);

        _this2.domElement.appendChild(_this2.__input);

        _this2.domElement.appendChild(_this2.__selector);

        _this2.updateDisplay();

        function setSV(e) {
          if (e.type.indexOf('touch') === -1) {
            e.preventDefault();
          }

          var fieldRect = _this.__saturation_field.getBoundingClientRect();

          var _ref = e.touches && e.touches[0] || e,
            clientX = _ref.clientX,
            clientY = _ref.clientY;

          var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left);
          var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);

          if (v > 1) {
            v = 1;
          } else if (v < 0) {
            v = 0;
          }

          if (s > 1) {
            s = 1;
          } else if (s < 0) {
            s = 0;
          }

          _this.__color.v = v;
          _this.__color.s = s;

          _this.setValue(_this.__color.toOriginal());

          return false;
        }

        function setH(e) {
          if (e.type.indexOf('touch') === -1) {
            e.preventDefault();
          }

          var fieldRect = _this.__hue_field.getBoundingClientRect();

          var _ref2 = e.touches && e.touches[0] || e,
            clientY = _ref2.clientY;

          var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top);

          if (h > 1) {
            h = 1;
          } else if (h < 0) {
            h = 0;
          }

          _this.__color.h = h * 360;

          _this.setValue(_this.__color.toOriginal());

          return false;
        }

        return _this2;
      }

      createClass(ColorController, [{
        key: 'updateDisplay',
        value: function updateDisplay() {
          var i = interpret(this.getValue());

          if (i !== false) {
            var mismatch = false;
            Common.each(Color.COMPONENTS, function (component) {
              if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) {
                mismatch = true;
                return {};
              }
            }, this);

            if (mismatch) {
              Common.extend(this.__color.__state, i);
            }
          }

          Common.extend(this.__temp.__state, this.__color.__state);
          this.__temp.a = 1;
          var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0;

          var _flip = 255 - flip;

          Common.extend(this.__field_knob.style, {
            marginLeft: 100 * this.__color.s - 7 + 'px',
            marginTop: 100 * (1 - this.__color.v) - 7 + 'px',
            backgroundColor: this.__temp.toHexString(),
            border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')'
          });
          this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px';
          this.__temp.s = 1;
          this.__temp.v = 1;
          linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString());
          this.__input.value = this.__color.toString();
          Common.extend(this.__input.style, {
            backgroundColor: this.__color.toHexString(),
            color: 'rgb(' + flip + ',' + flip + ',' + flip + ')',
            textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)'
          });
        }
      }]);
      return ColorController;
    }(Controller);

    var vendors = ['-moz-', '-o-', '-webkit-', '-ms-', ''];

    function linearGradient(elem, x, a, b) {
      elem.style.background = '';
      Common.each(vendors, function (vendor) {
        elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); ';
      });
    }

    function hueGradient(elem) {
      elem.style.background = '';
      elem.style.cssText += 'background: -moz-linear-gradient(top,  #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);';
      elem.style.cssText += 'background: -webkit-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
      elem.style.cssText += 'background: -o-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
      elem.style.cssText += 'background: -ms-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
      elem.style.cssText += 'background: linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);';
    }

    var css = {
      load: function load(url, indoc) {
        var doc = indoc || document;
        var link = doc.createElement('link');
        link.type = 'text/css';
        link.rel = 'stylesheet';
        link.href = url;
        doc.getElementsByTagName('head')[0].appendChild(link);
      },
      inject: function inject(cssContent, indoc) {
        var doc = indoc || document;
        var injected = document.createElement('style');
        injected.type = 'text/css';
        injected.innerHTML = cssContent;
        var head = doc.getElementsByTagName('head')[0];

        try {
          head.appendChild(injected);
        } catch (e) { }
      }
    };
    var saveDialogContents = "<div id=\"dg-save\" class=\"dg dialogue\">\n\n  Here's the new load parameter for your <code>GUI</code>'s constructor:\n\n  <textarea id=\"dg-new-constructor\"></textarea>\n\n  <div id=\"dg-save-locally\">\n\n    <input id=\"dg-local-storage\" type=\"checkbox\"/> Automatically save\n    values to <code>localStorage</code> on exit.\n\n    <div id=\"dg-local-explain\">The values saved to <code>localStorage</code> will\n      override those passed to <code>dat.GUI</code>'s constructor. This makes it\n      easier to work incrementally, but <code>localStorage</code> is fragile,\n      and your friends may not see the same values you do.\n\n    </div>\n\n  </div>\n\n</div>";

    var ControllerFactory = function ControllerFactory(object, property) {
      var initialValue = object[property];

      if (Common.isArray(arguments[2]) || Common.isObject(arguments[2])) {
        return new OptionController(object, property, arguments[2]);
      }

      if (Common.isNumber(initialValue)) {
        if (Common.isNumber(arguments[2]) && Common.isNumber(arguments[3])) {
          if (Common.isNumber(arguments[4])) {
            return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]);
          }

          return new NumberControllerSlider(object, property, arguments[2], arguments[3]);
        }

        if (Common.isNumber(arguments[4])) {
          return new NumberControllerBox(object, property, {
            min: arguments[2],
            max: arguments[3],
            step: arguments[4]
          });
        }

        return new NumberControllerBox(object, property, {
          min: arguments[2],
          max: arguments[3]
        });
      }

      if (Common.isString(initialValue)) {
        return new StringController(object, property);
      }

      if (Common.isFunction(initialValue)) {
        return new FunctionController(object, property, '');
      }

      if (Common.isBoolean(initialValue)) {
        return new BooleanController(object, property);
      }

      return null;
    };

    function requestAnimationFrame(callback) {
      setTimeout(callback, 1000 / 60);
    }

    var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame;

    var CenteredDiv = function () {
      function CenteredDiv() {
        classCallCheck(this, CenteredDiv);
        this.backgroundElement = document.createElement('div');
        Common.extend(this.backgroundElement.style, {
          backgroundColor: 'rgba(0,0,0,0.8)',
          top: 0,
          left: 0,
          display: 'none',
          zIndex: '1000',
          opacity: 0,
          WebkitTransition: 'opacity 0.2s linear',
          transition: 'opacity 0.2s linear'
        });
        dom.makeFullscreen(this.backgroundElement);
        this.backgroundElement.style.position = 'fixed';
        this.domElement = document.createElement('div');
        Common.extend(this.domElement.style, {
          position: 'fixed',
          display: 'none',
          zIndex: '1001',
          opacity: 0,
          WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear',
          transition: 'transform 0.2s ease-out, opacity 0.2s linear'
        });
        document.body.appendChild(this.backgroundElement);
        document.body.appendChild(this.domElement);

        var _this = this;

        dom.bind(this.backgroundElement, 'click', function () {
          _this.hide();
        });
      }

      createClass(CenteredDiv, [{
        key: 'show',
        value: function show() {
          var _this = this;

          this.backgroundElement.style.display = 'block';
          this.domElement.style.display = 'block';
          this.domElement.style.opacity = 0;
          this.domElement.style.webkitTransform = 'scale(1.1)';
          this.layout();
          Common.defer(function () {
            _this.backgroundElement.style.opacity = 1;
            _this.domElement.style.opacity = 1;
            _this.domElement.style.webkitTransform = 'scale(1)';
          });
        }
      }, {
        key: 'hide',
        value: function hide() {
          var _this = this;

          var hide = function hide() {
            _this.domElement.style.display = 'none';
            _this.backgroundElement.style.display = 'none';
            dom.unbind(_this.domElement, 'webkitTransitionEnd', hide);
            dom.unbind(_this.domElement, 'transitionend', hide);
            dom.unbind(_this.domElement, 'oTransitionEnd', hide);
          };

          dom.bind(this.domElement, 'webkitTransitionEnd', hide);
          dom.bind(this.domElement, 'transitionend', hide);
          dom.bind(this.domElement, 'oTransitionEnd', hide);
          this.backgroundElement.style.opacity = 0;
          this.domElement.style.opacity = 0;
          this.domElement.style.webkitTransform = 'scale(1.1)';
        }
      }, {
        key: 'layout',
        value: function layout() {
          this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px';
          this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px';
        }
      }]);
      return CenteredDiv;
    }();

    var styleSheet = ___$insertStyle(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n");

    css.inject(styleSheet);
    var CSS_NAMESPACE = 'dg';
    var HIDE_KEY_CODE = 72;
    var CLOSE_BUTTON_HEIGHT = 20;
    var DEFAULT_DEFAULT_PRESET_NAME = 'Default';

    var SUPPORTS_LOCAL_STORAGE = function () {
      try {
        return !!window.localStorage;
      } catch (e) {
        return false;
      }
    }();

    var SAVE_DIALOGUE = void 0;
    var autoPlaceVirgin = true;
    var autoPlaceContainer = void 0;
    var hide = false;
    var hideableGuis = [];

    var GUI = function GUI(pars) {
      var _this = this;

      var params = pars || {};
      this.domElement = document.createElement('div');
      this.__ul = document.createElement('ul');
      this.domElement.appendChild(this.__ul);
      dom.addClass(this.domElement, CSS_NAMESPACE);
      this.__folders = {};
      this.__controllers = [];
      this.__rememberedObjects = [];
      this.__rememberedObjectIndecesToControllers = [];
      this.__listening = [];
      params = Common.defaults(params, {
        closeOnTop: false,
        autoPlace: true,
        width: GUI.DEFAULT_WIDTH
      });
      params = Common.defaults(params, {
        resizable: params.autoPlace,
        hideable: params.autoPlace
      });

      if (!Common.isUndefined(params.load)) {
        if (params.preset) {
          params.load.preset = params.preset;
        }
      } else {
        params.load = {
          preset: DEFAULT_DEFAULT_PRESET_NAME
        };
      }

      if (Common.isUndefined(params.parent) && params.hideable) {
        hideableGuis.push(this);
      }

      params.resizable = Common.isUndefined(params.parent) && params.resizable;

      if (params.autoPlace && Common.isUndefined(params.scrollable)) {
        params.scrollable = true;
      }

      var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
      var saveToLocalStorage = void 0;
      var titleRow = void 0;
      Object.defineProperties(this, {
        parent: {
          get: function get$$1() {
            return params.parent;
          }
        },
        scrollable: {
          get: function get$$1() {
            return params.scrollable;
          }
        },
        autoPlace: {
          get: function get$$1() {
            return params.autoPlace;
          }
        },
        closeOnTop: {
          get: function get$$1() {
            return params.closeOnTop;
          }
        },
        preset: {
          get: function get$$1() {
            if (_this.parent) {
              return _this.getRoot().preset;
            }

            return params.load.preset;
          },
          set: function set$$1(v) {
            if (_this.parent) {
              _this.getRoot().preset = v;
            } else {
              params.load.preset = v;
            }

            setPresetSelectIndex(this);

            _this.revert();
          }
        },
        width: {
          get: function get$$1() {
            return params.width;
          },
          set: function set$$1(v) {
            params.width = v;
            setWidth(_this, v);
          }
        },
        name: {
          get: function get$$1() {
            return params.name;
          },
          set: function set$$1(v) {
            params.name = v;

            if (titleRow) {
              titleRow.innerHTML = params.name;
            }
          }
        },
        closed: {
          get: function get$$1() {
            return params.closed;
          },
          set: function set$$1(v) {
            params.closed = v;

            if (params.closed) {
              dom.addClass(_this.__ul, GUI.CLASS_CLOSED);
            } else {
              dom.removeClass(_this.__ul, GUI.CLASS_CLOSED);
            }

            this.onResize();

            if (_this.__closeButton) {
              _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED;
            }
          }
        },
        load: {
          get: function get$$1() {
            return params.load;
          }
        },
        useLocalStorage: {
          get: function get$$1() {
            return useLocalStorage;
          },
          set: function set$$1(bool) {
            if (SUPPORTS_LOCAL_STORAGE) {
              useLocalStorage = bool;

              if (bool) {
                dom.bind(window, 'unload', saveToLocalStorage);
              } else {
                dom.unbind(window, 'unload', saveToLocalStorage);
              }

              localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool);
            }
          }
        }
      });

      if (Common.isUndefined(params.parent)) {
        this.closed = params.closed || false;
        dom.addClass(this.domElement, GUI.CLASS_MAIN);
        dom.makeSelectable(this.domElement, false);

        if (SUPPORTS_LOCAL_STORAGE) {
          if (useLocalStorage) {
            _this.useLocalStorage = true;
            var savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui'));

            if (savedGui) {
              params.load = JSON.parse(savedGui);
            }
          }
        }

        this.__closeButton = document.createElement('div');
        this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
        dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);

        if (params.closeOnTop) {
          dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP);
          this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]);
        } else {
          dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM);
          this.domElement.appendChild(this.__closeButton);
        }

        dom.bind(this.__closeButton, 'click', function () {
          _this.closed = !_this.closed;
        });
      } else {
        if (params.closed === undefined) {
          params.closed = true;
        }

        var titleRowName = document.createTextNode(params.name);
        dom.addClass(titleRowName, 'controller-name');
        titleRow = addRow(_this, titleRowName);

        var onClickTitle = function onClickTitle(e) {
          e.preventDefault();
          _this.closed = !_this.closed;
          return false;
        };

        dom.addClass(this.__ul, GUI.CLASS_CLOSED);
        dom.addClass(titleRow, 'title');
        dom.bind(titleRow, 'click', onClickTitle);

        if (!params.closed) {
          this.closed = false;
        }
      }

      if (params.autoPlace) {
        if (Common.isUndefined(params.parent)) {
          if (autoPlaceVirgin) {
            autoPlaceContainer = document.createElement('div');
            dom.addClass(autoPlaceContainer, CSS_NAMESPACE);
            dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER);
            document.body.appendChild(autoPlaceContainer);
            autoPlaceVirgin = false;
          }

          autoPlaceContainer.appendChild(this.domElement);
          dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE);
        }

        if (!this.parent) {
          setWidth(_this, params.width);
        }
      }

      this.__resizeHandler = function () {
        _this.onResizeDebounced();
      };

      dom.bind(window, 'resize', this.__resizeHandler);
      dom.bind(this.__ul, 'webkitTransitionEnd', this.__resizeHandler);
      dom.bind(this.__ul, 'transitionend', this.__resizeHandler);
      dom.bind(this.__ul, 'oTransitionEnd', this.__resizeHandler);
      this.onResize();

      if (params.resizable) {
        addResizeHandle(this);
      }

      saveToLocalStorage = function saveToLocalStorage() {
        if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') {
          localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
        }
      };

      this.saveToLocalStorageIfPossible = saveToLocalStorage;

      function resetWidth() {
        var root = _this.getRoot();

        root.width += 1;
        Common.defer(function () {
          root.width -= 1;
        });
      }

      if (!params.parent) {
        resetWidth();
      }
    };

    GUI.toggleHide = function () {
      hide = !hide;
      Common.each(hideableGuis, function (gui) {
        gui.domElement.style.display = hide ? 'none' : '';
      });
    };

    GUI.CLASS_AUTO_PLACE = 'a';
    GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac';
    GUI.CLASS_MAIN = 'main';
    GUI.CLASS_CONTROLLER_ROW = 'cr';
    GUI.CLASS_TOO_TALL = 'taller-than-window';
    GUI.CLASS_CLOSED = 'closed';
    GUI.CLASS_CLOSE_BUTTON = 'close-button';
    GUI.CLASS_CLOSE_TOP = 'close-top';
    GUI.CLASS_CLOSE_BOTTOM = 'close-bottom';
    GUI.CLASS_DRAG = 'drag';
    GUI.DEFAULT_WIDTH = 245;
    GUI.TEXT_CLOSED = 'Close Controls';
    GUI.TEXT_OPEN = 'Open Controls';

    GUI._keydownHandler = function (e) {
      if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) {
        GUI.toggleHide();
      }
    };

    dom.bind(window, 'keydown', GUI._keydownHandler, false);
    Common.extend(GUI.prototype, {
      add: function add(object, property) {
        return _add(this, object, property, {
          factoryArgs: Array.prototype.slice.call(arguments, 2)
        });
      },
      addColor: function addColor(object, property) {
        return _add(this, object, property, {
          color: true
        });
      },
      remove: function remove(controller) {
        this.__ul.removeChild(controller.__li);

        this.__controllers.splice(this.__controllers.indexOf(controller), 1);

        var _this = this;

        Common.defer(function () {
          _this.onResize();
        });
      },
      destroy: function destroy() {
        if (this.parent) {
          throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.');
        }

        if (this.autoPlace) {
          autoPlaceContainer.removeChild(this.domElement);
        }

        var _this = this;

        Common.each(this.__folders, function (subfolder) {
          _this.removeFolder(subfolder);
        });
        dom.unbind(window, 'keydown', GUI._keydownHandler, false);
        removeListeners(this);
      },
      addFolder: function addFolder(name) {
        if (this.__folders[name] !== undefined) {
          throw new Error('You already have a folder in this GUI by the' + ' name "' + name + '"');
        }

        var newGuiParams = {
          name: name,
          parent: this
        };
        newGuiParams.autoPlace = this.autoPlace;

        if (this.load && this.load.folders && this.load.folders[name]) {
          newGuiParams.closed = this.load.folders[name].closed;
          newGuiParams.load = this.load.folders[name];
        }

        var gui = new GUI(newGuiParams);
        this.__folders[name] = gui;
        var li = addRow(this, gui.domElement);
        dom.addClass(li, 'folder');
        return gui;
      },
      removeFolder: function removeFolder(folder) {
        this.__ul.removeChild(folder.domElement.parentElement);

        delete this.__folders[folder.name];

        if (this.load && this.load.folders && this.load.folders[folder.name]) {
          delete this.load.folders[folder.name];
        }

        removeListeners(folder);

        var _this = this;

        Common.each(folder.__folders, function (subfolder) {
          folder.removeFolder(subfolder);
        });
        Common.defer(function () {
          _this.onResize();
        });
      },
      open: function open() {
        this.closed = false;
      },
      close: function close() {
        this.closed = true;
      },
      onResize: function onResize() {
        var root = this.getRoot();

        if (root.scrollable) {
          var top = dom.getOffset(root.__ul).top;
          var h = 0;
          Common.each(root.__ul.childNodes, function (node) {
            if (!(root.autoPlace && node === root.__save_row)) {
              h += dom.getHeight(node);
            }
          });

          if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {
            dom.addClass(root.domElement, GUI.CLASS_TOO_TALL);
            root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px';
          } else {
            dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL);
            root.__ul.style.height = 'auto';
          }
        }

        if (root.__resize_handle) {
          Common.defer(function () {
            root.__resize_handle.style.height = root.__ul.offsetHeight + 'px';
          });
        }

        if (root.__closeButton) {
          root.__closeButton.style.width = root.width + 'px';
        }
      },
      onResizeDebounced: Common.debounce(function () {
        this.onResize();
      }, 50),
      remember: function remember() {
        if (Common.isUndefined(SAVE_DIALOGUE)) {
          SAVE_DIALOGUE = new CenteredDiv();
          SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents;
        }

        if (this.parent) {
          throw new Error('You can only call remember on a top level GUI.');
        }

        var _this = this;

        Common.each(Array.prototype.slice.call(arguments), function (object) {
          if (_this.__rememberedObjects.length === 0) {
            addSaveMenu(_this);
          }

          if (_this.__rememberedObjects.indexOf(object) === -1) {
            _this.__rememberedObjects.push(object);
          }
        });

        if (this.autoPlace) {
          setWidth(this, this.width);
        }
      },
      getRoot: function getRoot() {
        var gui = this;

        while (gui.parent) {
          gui = gui.parent;
        }

        return gui;
      },
      getSaveObject: function getSaveObject() {
        var toReturn = this.load;
        toReturn.closed = this.closed;

        if (this.__rememberedObjects.length > 0) {
          toReturn.preset = this.preset;

          if (!toReturn.remembered) {
            toReturn.remembered = {};
          }

          toReturn.remembered[this.preset] = getCurrentPreset(this);
        }

        toReturn.folders = {};
        Common.each(this.__folders, function (element, key) {
          toReturn.folders[key] = element.getSaveObject();
        });
        return toReturn;
      },
      save: function save() {
        if (!this.load.remembered) {
          this.load.remembered = {};
        }

        this.load.remembered[this.preset] = getCurrentPreset(this);
        markPresetModified(this, false);
        this.saveToLocalStorageIfPossible();
      },
      saveAs: function saveAs(presetName) {
        if (!this.load.remembered) {
          this.load.remembered = {};
          this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true);
        }

        this.load.remembered[presetName] = getCurrentPreset(this);
        this.preset = presetName;
        addPresetOption(this, presetName, true);
        this.saveToLocalStorageIfPossible();
      },
      revert: function revert(gui) {
        Common.each(this.__controllers, function (controller) {
          if (!this.getRoot().load.remembered) {
            controller.setValue(controller.initialValue);
          } else {
            recallSavedValue(gui || this.getRoot(), controller);
          }

          if (controller.__onFinishChange) {
            controller.__onFinishChange.call(controller, controller.getValue());
          }
        }, this);
        Common.each(this.__folders, function (folder) {
          folder.revert(folder);
        });

        if (!gui) {
          markPresetModified(this.getRoot(), false);
        }
      },
      listen: function listen(controller) {
        var init = this.__listening.length === 0;

        this.__listening.push(controller);

        if (init) {
          updateDisplays(this.__listening);
        }
      },
      updateDisplay: function updateDisplay() {
        Common.each(this.__controllers, function (controller) {
          controller.updateDisplay();
        });
        Common.each(this.__folders, function (folder) {
          folder.updateDisplay();
        });
      }
    });

    function addRow(gui, newDom, liBefore) {
      var li = document.createElement('li');

      if (newDom) {
        li.appendChild(newDom);
      }

      if (liBefore) {
        gui.__ul.insertBefore(li, liBefore);
      } else {
        gui.__ul.appendChild(li);
      }

      gui.onResize();
      return li;
    }

    function removeListeners(gui) {
      dom.unbind(window, 'resize', gui.__resizeHandler);

      if (gui.saveToLocalStorageIfPossible) {
        dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible);
      }
    }

    function markPresetModified(gui, modified) {
      var opt = gui.__preset_select[gui.__preset_select.selectedIndex];

      if (modified) {
        opt.innerHTML = opt.value + '*';
      } else {
        opt.innerHTML = opt.value;
      }
    }

    function augmentController(gui, li, controller) {
      controller.__li = li;
      controller.__gui = gui;
      Common.extend(controller, {
        options: function options(_options) {
          if (arguments.length > 1) {
            var nextSibling = controller.__li.nextElementSibling;
            controller.remove();
            return _add(gui, controller.object, controller.property, {
              before: nextSibling,
              factoryArgs: [Common.toArray(arguments)]
            });
          }

          if (Common.isArray(_options) || Common.isObject(_options)) {
            var _nextSibling = controller.__li.nextElementSibling;
            controller.remove();
            return _add(gui, controller.object, controller.property, {
              before: _nextSibling,
              factoryArgs: [_options]
            });
          }
        },
        name: function name(_name) {
          controller.__li.firstElementChild.firstElementChild.innerHTML = _name;
          return controller;
        },
        listen: function listen() {
          controller.__gui.listen(controller);

          return controller;
        },
        remove: function remove() {
          controller.__gui.remove(controller);

          return controller;
        }
      });

      if (controller instanceof NumberControllerSlider) {
        var box = new NumberControllerBox(controller.object, controller.property, {
          min: controller.__min,
          max: controller.__max,
          step: controller.__step
        });
        Common.each(['updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max'], function (method) {
          var pc = controller[method];
          var pb = box[method];

          controller[method] = box[method] = function () {
            var args = Array.prototype.slice.call(arguments);
            pb.apply(box, args);
            return pc.apply(controller, args);
          };
        });
        dom.addClass(li, 'has-slider');
        controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild);
      } else if (controller instanceof NumberControllerBox) {
        var r = function r(returned) {
          if (Common.isNumber(controller.__min) && Common.isNumber(controller.__max)) {
            var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML;
            var wasListening = controller.__gui.__listening.indexOf(controller) > -1;
            controller.remove();

            var newController = _add(gui, controller.object, controller.property, {
              before: controller.__li.nextElementSibling,
              factoryArgs: [controller.__min, controller.__max, controller.__step]
            });

            newController.name(oldName);
            if (wasListening) newController.listen();
            return newController;
          }

          return returned;
        };

        controller.min = Common.compose(r, controller.min);
        controller.max = Common.compose(r, controller.max);
      } else if (controller instanceof BooleanController) {
        dom.bind(li, 'click', function () {
          dom.fakeEvent(controller.__checkbox, 'click');
        });
        dom.bind(controller.__checkbox, 'click', function (e) {
          e.stopPropagation();
        });
      } else if (controller instanceof FunctionController) {
        dom.bind(li, 'click', function () {
          dom.fakeEvent(controller.__button, 'click');
        });
        dom.bind(li, 'mouseover', function () {
          dom.addClass(controller.__button, 'hover');
        });
        dom.bind(li, 'mouseout', function () {
          dom.removeClass(controller.__button, 'hover');
        });
      } else if (controller instanceof ColorController) {
        dom.addClass(li, 'color');
        controller.updateDisplay = Common.compose(function (val) {
          li.style.borderLeftColor = controller.__color.toString();
          return val;
        }, controller.updateDisplay);
        controller.updateDisplay();
      }

      controller.setValue = Common.compose(function (val) {
        if (gui.getRoot().__preset_select && controller.isModified()) {
          markPresetModified(gui.getRoot(), true);
        }

        return val;
      }, controller.setValue);
    }

    function recallSavedValue(gui, controller) {
      var root = gui.getRoot();

      var matchedIndex = root.__rememberedObjects.indexOf(controller.object);

      if (matchedIndex !== -1) {
        var controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex];

        if (controllerMap === undefined) {
          controllerMap = {};
          root.__rememberedObjectIndecesToControllers[matchedIndex] = controllerMap;
        }

        controllerMap[controller.property] = controller;

        if (root.load && root.load.remembered) {
          var presetMap = root.load.remembered;
          var preset = void 0;

          if (presetMap[gui.preset]) {
            preset = presetMap[gui.preset];
          } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) {
            preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME];
          } else {
            return;
          }

          if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) {
            var value = preset[matchedIndex][controller.property];
            controller.initialValue = value;
            controller.setValue(value);
          }
        }
      }
    }

    function _add(gui, object, property, params) {
      if (object[property] === undefined) {
        throw new Error('Object "' + object + '" has no property "' + property + '"');
      }

      var controller = void 0;

      if (params.color) {
        controller = new ColorController(object, property);
      } else {
        var factoryArgs = [object, property].concat(params.factoryArgs);
        controller = ControllerFactory.apply(gui, factoryArgs);
      }

      if (params.before instanceof Controller) {
        params.before = params.before.__li;
      }

      recallSavedValue(gui, controller);
      dom.addClass(controller.domElement, 'c');
      var name = document.createElement('span');
      dom.addClass(name, 'property-name');
      name.innerHTML = controller.property;
      var container = document.createElement('div');
      container.appendChild(name);
      container.appendChild(controller.domElement);
      var li = addRow(gui, container, params.before);
      dom.addClass(li, GUI.CLASS_CONTROLLER_ROW);

      if (controller instanceof ColorController) {
        dom.addClass(li, 'color');
      } else {
        dom.addClass(li, _typeof(controller.getValue()));
      }

      augmentController(gui, li, controller);

      gui.__controllers.push(controller);

      return controller;
    }

    function getLocalStorageHash(gui, key) {
      return document.location.href + '.' + key;
    }

    function addPresetOption(gui, name, setSelected) {
      var opt = document.createElement('option');
      opt.innerHTML = name;
      opt.value = name;

      gui.__preset_select.appendChild(opt);

      if (setSelected) {
        gui.__preset_select.selectedIndex = gui.__preset_select.length - 1;
      }
    }

    function showHideExplain(gui, explain) {
      explain.style.display = gui.useLocalStorage ? 'block' : 'none';
    }

    function addSaveMenu(gui) {
      var div = gui.__save_row = document.createElement('li');
      dom.addClass(gui.domElement, 'has-save');

      gui.__ul.insertBefore(div, gui.__ul.firstChild);

      dom.addClass(div, 'save-row');
      var gears = document.createElement('span');
      gears.innerHTML = '&nbsp;';
      dom.addClass(gears, 'button gears');
      var button = document.createElement('span');
      button.innerHTML = 'Save';
      dom.addClass(button, 'button');
      dom.addClass(button, 'save');
      var button2 = document.createElement('span');
      button2.innerHTML = 'New';
      dom.addClass(button2, 'button');
      dom.addClass(button2, 'save-as');
      var button3 = document.createElement('span');
      button3.innerHTML = 'Revert';
      dom.addClass(button3, 'button');
      dom.addClass(button3, 'revert');
      var select = gui.__preset_select = document.createElement('select');

      if (gui.load && gui.load.remembered) {
        Common.each(gui.load.remembered, function (value, key) {
          addPresetOption(gui, key, key === gui.preset);
        });
      } else {
        addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false);
      }

      dom.bind(select, 'change', function () {
        for (var index = 0; index < gui.__preset_select.length; index++) {
          gui.__preset_select[index].innerHTML = gui.__preset_select[index].value;
        }

        gui.preset = this.value;
      });
      div.appendChild(select);
      div.appendChild(gears);
      div.appendChild(button);
      div.appendChild(button2);
      div.appendChild(button3);

      if (SUPPORTS_LOCAL_STORAGE) {
        var explain = document.getElementById('dg-local-explain');
        var localStorageCheckBox = document.getElementById('dg-local-storage');
        var saveLocally = document.getElementById('dg-save-locally');
        saveLocally.style.display = 'block';

        if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') {
          localStorageCheckBox.setAttribute('checked', 'checked');
        }

        showHideExplain(gui, explain);
        dom.bind(localStorageCheckBox, 'change', function () {
          gui.useLocalStorage = !gui.useLocalStorage;
          showHideExplain(gui, explain);
        });
      }

      var newConstructorTextArea = document.getElementById('dg-new-constructor');
      dom.bind(newConstructorTextArea, 'keydown', function (e) {
        if (e.metaKey && (e.which === 67 || e.keyCode === 67)) {
          SAVE_DIALOGUE.hide();
        }
      });
      dom.bind(gears, 'click', function () {
        newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2);
        SAVE_DIALOGUE.show();
        newConstructorTextArea.focus();
        newConstructorTextArea.select();
      });
      dom.bind(button, 'click', function () {
        gui.save();
      });
      dom.bind(button2, 'click', function () {
        var presetName = prompt('Enter a new preset name.');

        if (presetName) {
          gui.saveAs(presetName);
        }
      });
      dom.bind(button3, 'click', function () {
        gui.revert();
      });
    }

    function addResizeHandle(gui) {
      var pmouseX = void 0;
      gui.__resize_handle = document.createElement('div');
      Common.extend(gui.__resize_handle.style, {
        width: '6px',
        marginLeft: '-3px',
        height: '200px',
        cursor: 'ew-resize',
        position: 'absolute'
      });

      function drag(e) {
        e.preventDefault();
        gui.width += pmouseX - e.clientX;
        gui.onResize();
        pmouseX = e.clientX;
        return false;
      }

      function dragStop() {
        dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG);
        dom.unbind(window, 'mousemove', drag);
        dom.unbind(window, 'mouseup', dragStop);
      }

      function dragStart(e) {
        e.preventDefault();
        pmouseX = e.clientX;
        dom.addClass(gui.__closeButton, GUI.CLASS_DRAG);
        dom.bind(window, 'mousemove', drag);
        dom.bind(window, 'mouseup', dragStop);
        return false;
      }

      dom.bind(gui.__resize_handle, 'mousedown', dragStart);
      dom.bind(gui.__closeButton, 'mousedown', dragStart);
      gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild);
    }

    function setWidth(gui, w) {
      gui.domElement.style.width = w + 'px';

      if (gui.__save_row && gui.autoPlace) {
        gui.__save_row.style.width = w + 'px';
      }

      if (gui.__closeButton) {
        gui.__closeButton.style.width = w + 'px';
      }
    }

    function getCurrentPreset(gui, useInitialValues) {
      var toReturn = {};
      Common.each(gui.__rememberedObjects, function (val, index) {
        var savedValues = {};
        var controllerMap = gui.__rememberedObjectIndecesToControllers[index];
        Common.each(controllerMap, function (controller, property) {
          savedValues[property] = useInitialValues ? controller.initialValue : controller.getValue();
        });
        toReturn[index] = savedValues;
      });
      return toReturn;
    }

    function setPresetSelectIndex(gui) {
      for (var index = 0; index < gui.__preset_select.length; index++) {
        if (gui.__preset_select[index].value === gui.preset) {
          gui.__preset_select.selectedIndex = index;
        }
      }
    }

    function updateDisplays(controllerArray) {
      if (controllerArray.length !== 0) {
        requestAnimationFrame$1.call(window, function () {
          updateDisplays(controllerArray);
        });
      }

      Common.each(controllerArray, function (c) {
        c.updateDisplay();
      });
    }

    var color = {
      Color: Color,
      math: ColorMath,
      interpret: interpret
    };
    exports.color = color;
    var controllers = {
      Controller: Controller,
      BooleanController: BooleanController,
      OptionController: OptionController,
      StringController: StringController,
      NumberController: NumberController,
      NumberControllerBox: NumberControllerBox,
      NumberControllerSlider: NumberControllerSlider,
      FunctionController: FunctionController,
      ColorController: ColorController
    };
    exports.controllers = controllers;
    var dom$1 = {
      dom: dom
    };
    exports.dom = dom$1;
    var gui = {
      GUI: GUI
    };
    exports.gui = gui;
    var GUI$1 = GUI;
    exports.GUI = GUI$1;
    var index = {
      color: color,
      controllers: controllers,
      dom: dom$1,
      gui: gui,
      GUI: GUI$1
    };
    var _default = index;
    exports.default = _default;
  }, {}], "node_modules/stats.js/build/stats.min.js": [function (require, module, exports) {
    var define;
    // stats.js - http://github.com/mrdoob/stats.js
    (function (f, e) { "object" === typeof exports && "undefined" !== typeof module ? module.exports = e() : "function" === typeof define && define.amd ? define(e) : f.Stats = e() })(this, function () {
      var f = function () {
        function e(a) { c.appendChild(a.dom); return a } function u(a) { for (var d = 0; d < c.children.length; d++)c.children[d].style.display = d === a ? "block" : "none"; l = a } var l = 0, c = document.createElement("div"); c.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000"; c.addEventListener("click", function (a) {
          a.preventDefault();
          u(++l % c.children.length)
        }, !1); var k = (performance || Date).now(), g = k, a = 0, r = e(new f.Panel("FPS", "#0ff", "#002")), h = e(new f.Panel("MS", "#0f0", "#020")); if (self.performance && self.performance.memory) var t = e(new f.Panel("MB", "#f08", "#201")); u(0); return {
          REVISION: 16, dom: c, addPanel: e, showPanel: u, begin: function () { k = (performance || Date).now() }, end: function () {
            a++; var c = (performance || Date).now(); h.update(c - k, 200); if (c > g + 1E3 && (r.update(1E3 * a / (c - g), 100), g = c, a = 0, t)) {
              var d = performance.memory; t.update(d.usedJSHeapSize /
                1048576, d.jsHeapSizeLimit / 1048576)
            } return c
          }, update: function () { k = this.end() }, domElement: c, setMode: u
        }
      }; f.Panel = function (e, f, l) {
        var c = Infinity, k = 0, g = Math.round, a = g(window.devicePixelRatio || 1), r = 80 * a, h = 48 * a, t = 3 * a, v = 2 * a, d = 3 * a, m = 15 * a, n = 74 * a, p = 30 * a, q = document.createElement("canvas"); q.width = r; q.height = h; q.style.cssText = "width:80px;height:48px"; var b = q.getContext("2d"); b.font = "bold " + 9 * a + "px Helvetica,Arial,sans-serif"; b.textBaseline = "top"; b.fillStyle = l; b.fillRect(0, 0, r, h); b.fillStyle = f; b.fillText(e, t, v);
        b.fillRect(d, m, n, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d, m, n, p); return { dom: q, update: function (h, w) { c = Math.min(c, h); k = Math.max(k, h); b.fillStyle = l; b.globalAlpha = 1; b.fillRect(0, 0, r, m); b.fillStyle = f; b.fillText(g(h) + " " + e + " (" + g(c) + "-" + g(k) + ")", t, v); b.drawImage(q, d + a, m, n - a, p, d, m, n - a, p); b.fillRect(d + n - a, m, a, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d + n - a, m, a, g((1 - h / w) * p)) } }
      }; return f
    });

  }, {}], "node_modules/@tensorflow/tfjs-layers/dist/tf-layers.esm.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.input = input;
    exports.loadLayersModel = loadLayersModel;
    exports.model = model;
    exports.registerCallbackConstructor = registerCallbackConstructor;
    exports.sequential = sequential;
    exports.version_layers = exports.LayerVariable = exports.Sequential = exports.RNN = exports.LayersModel = exports.SymbolicTensor = exports.InputSpec = exports.EarlyStopping = exports.callbacks = exports.Callback = exports.History = exports.CustomCallback = exports.CallbackList = exports.regularizers = exports.models = exports.metrics = exports.layers = exports.initializers = exports.constraints = void 0;

    var _tfjsCore = require("@tensorflow/tfjs-core");

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    var extendStatics = function (e, t) {
      return (extendStatics = 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]);
      })(e, t);
    };

    function __extends(e, t) {
      function n() {
        this.constructor = e;
      }

      extendStatics(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, new n());
    }

    var _epsilon,
      __assign = function () {
        return (__assign = Object.assign || function (e) {
          for (var t, n = 1, r = arguments.length; n < r; n++) for (var i in t = arguments[n]) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);

          return e;
        }).apply(this, arguments);
      };

    function __awaiter(e, t, n, r) {
      return new (n || (n = Promise))(function (i, a) {
        function o(e) {
          try {
            l(r.next(e));
          } catch (e) {
            a(e);
          }
        }

        function s(e) {
          try {
            l(r.throw(e));
          } catch (e) {
            a(e);
          }
        }

        function l(e) {
          e.done ? i(e.value) : new n(function (t) {
            t(e.value);
          }).then(o, s);
        }

        l((r = r.apply(e, t || [])).next());
      });
    }

    function __generator(e, t) {
      var n,
        r,
        i,
        a,
        o = {
          label: 0,
          sent: function () {
            if (1 & i[0]) throw i[1];
            return i[1];
          },
          trys: [],
          ops: []
        };
      return a = {
        next: s(0),
        throw: s(1),
        return: s(2)
      }, "function" == typeof Symbol && (a[Symbol.iterator] = function () {
        return this;
      }), a;

      function s(a) {
        return function (s) {
          return function (a) {
            if (n) throw new TypeError("Generator is already executing.");

            for (; o;) try {
              if (n = 1, r && (i = 2 & a[0] ? r.return : a[0] ? r.throw || ((i = r.return) && i.call(r), 0) : r.next) && !(i = i.call(r, a[1])).done) return i;

              switch (r = 0, i && (a = [2 & a[0], i.value]), a[0]) {
                case 0:
                case 1:
                  i = a;
                  break;

                case 4:
                  return o.label++, {
                    value: a[1],
                    done: !1
                  };

                case 5:
                  o.label++, r = a[1], a = [0];
                  continue;

                case 7:
                  a = o.ops.pop(), o.trys.pop();
                  continue;

                default:
                  if (!(i = (i = o.trys).length > 0 && i[i.length - 1]) && (6 === a[0] || 2 === a[0])) {
                    o = 0;
                    continue;
                  }

                  if (3 === a[0] && (!i || a[1] > i[0] && a[1] < i[3])) {
                    o.label = a[1];
                    break;
                  }

                  if (6 === a[0] && o.label < i[1]) {
                    o.label = i[1], i = a;
                    break;
                  }

                  if (i && o.label < i[2]) {
                    o.label = i[2], o.ops.push(a);
                    break;
                  }

                  i[2] && o.ops.pop(), o.trys.pop();
                  continue;
              }

              a = t.call(e, o);
            } catch (e) {
              a = [6, e], r = 0;
            } finally {
                n = i = 0;
              }

            if (5 & a[0]) throw a[1];
            return {
              value: a[0] ? a[1] : void 0,
              done: !0
            };
          }([a, s]);
        };
      }
    }

    function epsilon() {
      return null == _epsilon && (_epsilon = (0, _tfjsCore.backend)().epsilon()), _epsilon;
    }

    function imageDataFormat() {
      return "channelsLast";
    }

    var AttributeError = function (e) {
      function t(n) {
        var r = e.call(this, n) || this;
        return Object.setPrototypeOf(r, t.prototype), r;
      }

      return __extends(t, e), t;
    }(Error),
      RuntimeError = function (e) {
        function t(n) {
          var r = e.call(this, n) || this;
          return Object.setPrototypeOf(r, t.prototype), r;
        }

        return __extends(t, e), t;
      }(Error),
      ValueError = function (e) {
        function t(n) {
          var r = e.call(this, n) || this;
          return Object.setPrototypeOf(r, t.prototype), r;
        }

        return __extends(t, e), t;
      }(Error),
      NotImplementedError = function (e) {
        function t(n) {
          var r = e.call(this, n) || this;
          return Object.setPrototypeOf(r, t.prototype), r;
        }

        return __extends(t, e), t;
      }(Error),
      AssertionError = function (e) {
        function t(n) {
          var r = e.call(this, n) || this;
          return Object.setPrototypeOf(r, t.prototype), r;
        }

        return __extends(t, e), t;
      }(Error),
      IndexError = function (e) {
        function t(n) {
          var r = e.call(this, n) || this;
          return Object.setPrototypeOf(r, t.prototype), r;
        }

        return __extends(t, e), t;
      }(Error);

    function pyListRepeat(e, t) {
      if (Array.isArray(e)) {
        for (var n = [], r = 0; r < t; r++) n = n.concat(e);

        return n;
      }

      return (n = new Array(t)).fill(e), n;
    }

    function assert(e, t) {
      if (!e) throw new AssertionError(t);
    }

    function count(e, t) {
      for (var n = 0, r = 0, i = e; r < i.length; r++) {
        i[r] === t && n++;
      }

      return n;
    }

    function singletonOrArray(e) {
      return 1 === e.length ? e[0] : e;
    }

    function toList(e) {
      return Array.isArray(e) ? e : [e];
    }

    function toSnakeCase(e) {
      var t = e.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
      return "_" !== t[0] ? t : "private" + t;
    }

    function toCamelCase(e) {
      return e.length <= 1 ? e : -1 === e.indexOf("_") ? e : e.replace(/[_]+(\w|$)/g, function (e, t) {
        return t.toUpperCase();
      });
    }

    var _GLOBAL_CUSTOM_OBJECTS = {};

    function serializeKerasObject(e) {
      if (null === e || void 0 === e) return null;
      var t = {};
      return t.className = e.getClassName(), t.config = e.getConfig(), t;
    }

    function convertNDArrayScalarsInConfig(e) {
      if (null != e && "object" == typeof e) if (Array.isArray(e)) e.forEach(function (e) {
        return convertNDArrayScalarsInConfig(e);
      }); else for (var t = 0, n = Object.keys(e); t < n.length; t++) {
        var r = n[t],
          i = e[r];
        null != i && "object" == typeof i && (Array.isArray(i) || "ndarray" !== i.type || "number" != typeof i.value ? convertNDArrayScalarsInConfig(i) : e[r] = i.value);
      }
    }

    function deserializeKerasObject(e, t, n, r, i) {
      var a, o, s;

      if (void 0 === t && (t = {}), void 0 === n && (n = {}), void 0 === r && (r = "object"), void 0 === i && (i = !1), "string" == typeof e) {
        var l = e,
          u = void 0;
        if (l in n) u = n[l]; else if (l in _GLOBAL_CUSTOM_OBJECTS) u = _GLOBAL_CUSTOM_OBJECTS[l]; else if (null == (u = t[l])) throw new ValueError("Unknown " + r + ": " + e + ". This may be due to one of the following reasons:\n1. The " + r + " is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom " + r + " is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");
        return u;
      }

      var c = e;
      if (null == c.className || null == c.config) throw new ValueError(r + ": Improper config format: " + JSON.stringify(c) + ".\n'className' and 'config' must set.");
      var p = c.className,
        h = void 0,
        d = void 0;
      if (p in n ? (h = (a = n[p])[0], d = a[1]) : p in _GLOBAL_CUSTOM_OBJECTS ? (h = (o = _GLOBAL_CUSTOM_OBJECTS.className)[0], d = o[1]) : p in t && (h = (s = t[p])[0], d = s[1]), null == h) throw new ValueError("Unknown " + r + ": " + p + ". This may be due to one of the following reasons:\n1. The " + r + " is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom " + r + " is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");

      if (null != d) {
        for (var f = {}, g = 0, m = Object.keys(_GLOBAL_CUSTOM_OBJECTS); g < m.length; g++) {
          f[S = m[g]] = _GLOBAL_CUSTOM_OBJECTS[S];
        }

        for (var y = 0, v = Object.keys(n); y < v.length; y++) {
          f[S = v[y]] = n[S];
        }

        c.config.customObjects = f;

        for (var b = __assign({}, _GLOBAL_CUSTOM_OBJECTS), w = 0, z = Object.keys(n); w < z.length; w++) {
          var S = z[w];
          _GLOBAL_CUSTOM_OBJECTS[S] = n[S];
        }

        convertNDArrayScalarsInConfig(c.config);
        var A = d(h, c.config, n, i);
        return _GLOBAL_CUSTOM_OBJECTS = __assign({}, b), A;
      }

      b = __assign({}, _GLOBAL_CUSTOM_OBJECTS);

      for (var _ = 0, I = Object.keys(n); _ < I.length; _++) {
        S = I[_];
        _GLOBAL_CUSTOM_OBJECTS[S] = n[S];
      }

      A = new h(c.config);
      return _GLOBAL_CUSTOM_OBJECTS = __assign({}, b), A;
    }

    function numberCompare(e, t) {
      return e < t ? -1 : e > t ? 1 : 0;
    }

    function reverseNumberCompare(e, t) {
      return -1 * numberCompare(e, t);
    }

    function unique(e) {
      if (null == e) return e;

      for (var t = [], n = 0, r = e; n < r.length; n++) {
        var i = r[n];
        -1 === t.indexOf(i) && t.push(i);
      }

      return t;
    }

    function isObjectEmpty(e) {
      if (null == e) throw new ValueError("Invalid value in obj: " + JSON.stringify(e));

      for (var t in e) if (e.hasOwnProperty(t)) return !1;

      return !0;
    }

    function checkStringTypeUnionValue(e, t, n) {
      if (null != n && e.indexOf(n) < 0) throw new ValueError(n + " is not a valid " + t + ".  Valid values are " + e + " or null/undefined.");
    }

    function checkArrayTypeAndLength(e, t, n, r) {
      return void 0 === n && (n = 0), void 0 === r && (r = 1 / 0), assert(n >= 0), assert(r >= n), Array.isArray(e) && e.length >= n && e.length <= r && e.every(function (e) {
        return typeof e === t;
      });
    }

    function assertPositiveInteger(e, t) {
      Array.isArray(e) ? (_tfjsCore.util.assert(e.length > 0, function () {
        return t + " is unexpectedly an empty array.";
      }), e.forEach(function (e, n) {
        return assertPositiveInteger(e, "element " + (n + 1) + " of " + t);
      })) : _tfjsCore.util.assert(Number.isInteger(e) && e > 0, function () {
        return "Expected " + t + " to be a positive integer, but got " + formatAsFriendlyString(e) + ".";
      });
    }

    function formatAsFriendlyString(e) {
      return null === e ? "null" : Array.isArray(e) ? "[" + e.map(function (e) {
        return formatAsFriendlyString(e);
      }).join(",") + "]" : "string" == typeof e ? '"' + e + '"' : "" + e;
    }

    function debounce(e, t) {
      var n,
        r = _tfjsCore.util.now();

      return function () {
        for (var i = [], a = 0; a < arguments.length; a++) i[a] = arguments[a];

        var o = _tfjsCore.util.now();

        return o - r < t ? n : (r = o, n = e.apply(void 0, i));
      };
    }

    function mapActivationToFusedKernel(e) {
      return "relu" === e ? "relu" : "linear" === e ? "linear" : "elu" === e ? "elu" : null;
    }

    function calcL2Norms(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.sqrt)((0, _tfjsCore.sum)((0, _tfjsCore.mulStrict)(e, e), t, !0));
      });
    }

    var Constraint = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.getConfig = function () {
        return {};
      }, t;
    }(_tfjsCore.serialization.Serializable),
      MaxNorm = 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 __extends(t, e), t.prototype.apply = function (e) {
          var t = this;
          return (0, _tfjsCore.tidy)(function () {
            var n = calcL2Norms(e, t.axis),
              r = (0, _tfjsCore.clipByValue)(n, 0, t.maxValue);
            return (0, _tfjsCore.mul)(e, (0, _tfjsCore.div)(r, (0, _tfjsCore.add)(epsilon(), n)));
          });
        }, t.prototype.getConfig = function () {
          return {
            maxValue: this.maxValue,
            axis: this.axis
          };
        }, t.className = "MaxNorm", t;
      }(Constraint);

    _tfjsCore.serialization.registerClass(MaxNorm);

    var UnitNorm = 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 __extends(t, e), t.prototype.apply = function (e) {
        var t = this;
        return (0, _tfjsCore.tidy)(function () {
          return (0, _tfjsCore.div)(e, (0, _tfjsCore.add)(epsilon(), calcL2Norms(e, t.axis)));
        });
      }, t.prototype.getConfig = function () {
        return {
          axis: this.axis
        };
      }, t.className = "UnitNorm", t;
    }(Constraint);

    _tfjsCore.serialization.registerClass(UnitNorm);

    var NonNeg = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.relu)(e);
      }, t.className = "NonNeg", t;
    }(Constraint);

    _tfjsCore.serialization.registerClass(NonNeg);

    var MinMaxNorm = 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 __extends(t, e), t.prototype.apply = function (e) {
        var t = this;
        return (0, _tfjsCore.tidy)(function () {
          var n = calcL2Norms(e, t.axis),
            r = (0, _tfjsCore.add)((0, _tfjsCore.mul)(t.rate, (0, _tfjsCore.clipByValue)(n, t.minValue, t.maxValue)), (0, _tfjsCore.mul)(1 - t.rate, n));
          return (0, _tfjsCore.mul)(e, (0, _tfjsCore.div)(r, (0, _tfjsCore.add)(epsilon(), n)));
        });
      }, t.prototype.getConfig = function () {
        return {
          minValue: this.minValue,
          maxValue: this.maxValue,
          rate: this.rate,
          axis: this.axis
        };
      }, t.className = "MinMaxNorm", t;
    }(Constraint);

    _tfjsCore.serialization.registerClass(MinMaxNorm);

    var CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
      maxNorm: "MaxNorm",
      minMaxNorm: "MinMaxNorm",
      nonNeg: "NonNeg",
      unitNorm: "UnitNorm"
    };

    function serializeConstraint(e) {
      return serializeKerasObject(e);
    }

    function deserializeConstraint(e, t) {
      return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "constraint");
    }

    function getConstraint(e) {
      return null == e ? null : "string" == typeof e ? deserializeConstraint({
        className: e in CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP ? CONSTRAINT_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e,
        config: {}
      }) : e instanceof Constraint ? e : deserializeConstraint(e);
    }

    function maxNorm(e) {
      return new MaxNorm(e);
    }

    function unitNorm(e) {
      return new UnitNorm(e);
    }

    function nonNeg() {
      return new NonNeg();
    }

    function minMaxNorm(e) {
      return new MinMaxNorm(e);
    }

    var exports_constraints = Object.freeze({
      maxNorm: maxNorm,
      unitNorm: unitNorm,
      nonNeg: nonNeg,
      minMaxNorm: minMaxNorm
    }),
      VALID_DATA_FORMAT_VALUES = ["channelsFirst", "channelsLast"],
      VALID_PADDING_MODE_VALUES = ["valid", "same", "causal"],
      VALID_POOL_MODE_VALUES = ["max", "avg"],
      VALID_BIDIRECTIONAL_MERGE_MODES = ["sum", "mul", "concat", "ave"],
      nameMap = new Map();
    exports.constraints = exports_constraints;

    function checkDataFormat(e) {
      checkStringTypeUnionValue(VALID_DATA_FORMAT_VALUES, "DataFormat", e);
    }

    function checkPaddingMode(e) {
      checkStringTypeUnionValue(VALID_PADDING_MODE_VALUES, "PaddingMode", e);
    }

    function checkPoolMode(e) {
      checkStringTypeUnionValue(VALID_POOL_MODE_VALUES, "PoolMode", e);
    }

    var _nameScopeStack = [],
      _nameScopeDivider = "/";

    function nameScope(e, t) {
      _nameScopeStack.push(e);

      try {
        var n = t();
        return _nameScopeStack.pop(), n;
      } catch (e) {
        throw _nameScopeStack.pop(), e;
      }
    }

    function currentNameScopePrefix() {
      return 0 === _nameScopeStack.length ? "" : _nameScopeStack.join(_nameScopeDivider) + _nameScopeDivider;
    }

    function getScopedTensorName(e) {
      if (!isValidTensorName(e)) throw new Error("Not a valid tensor name: '" + e + "'");
      return currentNameScopePrefix() + e;
    }

    function getUniqueTensorName(e) {
      if (!isValidTensorName(e)) throw new Error("Not a valid tensor name: '" + e + "'");
      nameMap.has(e) || nameMap.set(e, 0);
      var t = nameMap.get(e);

      if (nameMap.set(e, nameMap.get(e) + 1), t > 0) {
        var n = e + "_" + t;
        return nameMap.set(n, 1), n;
      }

      return e;
    }

    var tensorNameRegex = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);

    function isValidTensorName(e) {
      return !!e.match(tensorNameRegex);
    }

    function isInteger(e) {
      return e === parseInt(e.toString(), 10);
    }

    function arrayProd(e, t, n) {
      null == t && (t = 0), null == n && (n = e.length);

      for (var r = 1, i = t; i < n; ++i) r *= e[i];

      return r;
    }

    function toArray1D(e) {
      return e = Array.isArray(e) ? new Float32Array(e) : e, (0, _tfjsCore.tensor1d)(e);
    }

    function min$1(e) {
      return (0, _tfjsCore.min)(toArray1D(e)).dataSync()[0];
    }

    function max$1(e) {
      return (0, _tfjsCore.max)(toArray1D(e)).dataSync()[0];
    }

    function range(e, t) {
      if (t < e) throw new ValueError("end (" + t + ") < begin (" + e + ") is forbidden.");

      for (var n = [], r = e; r < t; ++r) n.push(r);

      return n;
    }

    function cast$1(e, t) {
      return e.asType(t);
    }

    function expandDims$1(e, t) {
      void 0 === t && (t = -1);
      var n = e.shape.slice();
      return t < 0 && (t = n.length + t + 1), n.splice(t, 0, 1), e.reshape(n);
    }

    function repeat(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        if (2 !== e.shape.length) throw new ValueError("repeat() expects a rank-2 tensor, but received a rank-" + e.shape.length + " tensor.");
        return tile$1(expandDims$1(e, 1), [1, t, 1]);
      });
    }

    function flatten(e) {
      var t = [arrayProd(e.shape)];
      return e.reshape(t);
    }

    function batchFlatten(e) {
      if (e.rank <= 1) throw new ValueError("batchFlatten requires a minimum rank of 2. Got rank: " + e.rank + ".");
      var t = [e.shape[0], arrayProd(e.shape, 1)];
      return e.reshape(t);
    }

    function sliceAlongFirstAxis(e, t, n) {
      return (0, _tfjsCore.tidy)(function () {
        switch (e.rank) {
          case 1:
            return (0, _tfjsCore.slice1d)(e, t, n);

          case 2:
            return (0, _tfjsCore.slice2d)(e, [t, 0], [n, e.shape[1]]);

          case 3:
            return (0, _tfjsCore.slice3d)(e, [t, 0, 0], [n, e.shape[1], e.shape[2]]);

          case 4:
            return (0, _tfjsCore.slice4d)(e, [t, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3]]);

          case 5:
            return (0, _tfjsCore.slice)(e, [t, 0, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3], e.shape[4]]);

          case 6:
            return (0, _tfjsCore.slice)(e, [t, 0, 0, 0, 0, 0], [n, e.shape[1], e.shape[2], e.shape[3], e.shape[4], e.shape[5]]);

          default:
            throw new ValueError("sliceAlongFirstAxis() received an unsupported tensor rank: " + e.rank);
        }
      });
    }

    function sliceAlongLastAxis(e, t, n) {
      return (0, _tfjsCore.tidy)(function () {
        switch (e.rank) {
          case 1:
            return (0, _tfjsCore.slice1d)(e, t, n);

          case 2:
            return (0, _tfjsCore.slice2d)(e, [0, t], [e.shape[0], n]);

          case 3:
            return (0, _tfjsCore.slice3d)(e, [0, 0, t], [e.shape[0], e.shape[1], n]);

          case 4:
            return (0, _tfjsCore.slice4d)(e, [0, 0, 0, t], [e.shape[0], e.shape[1], e.shape[2], n]);

          default:
            throw new ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " + e.rank);
        }
      });
    }

    function sliceAlongAxis(e, t, n, r) {
      return (0, _tfjsCore.tidy)(function () {
        switch (e.rank) {
          case 1:
            return (0, _tfjsCore.slice1d)(e, t, n);

          case 2:
            switch (r) {
              case 1:
                return sliceAlongFirstAxis(e, t, n);

              case 2:
                return sliceAlongLastAxis(e, t, n);

              default:
                throw new ValueError("The axis is not within the rank of the tensor " + r);
            }

          case 3:
            switch (r) {
              case 1:
                return sliceAlongFirstAxis(e, t, n);

              case 2:
                return (0, _tfjsCore.slice3d)(e, [0, t, 0], [e.shape[0], n, e.shape[2]]);

              case 3:
                return sliceAlongLastAxis(e, t, n);

              default:
                throw new ValueError("The axis is not within the rank of the tensor " + r);
            }

          case 4:
            switch (r) {
              case 1:
                return sliceAlongFirstAxis(e, t, n);

              case 2:
                return (0, _tfjsCore.slice4d)(e, [0, t, 0, 0], [e.shape[0], n, e.shape[2], e.shape[3]]);

              case 3:
                return (0, _tfjsCore.slice4d)(e, [0, 0, t, 0], [e.shape[0], e.shape[1], n, e.shape[3]]);

              case 4:
                return sliceAlongLastAxis(e, t, n);

              default:
                throw new ValueError("The axis is not within the rank of the tensor " + r);
            }

          default:
            throw new ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " + e.rank);
        }
      });
    }

    function concatenate(e, t) {
      var n;
      return void 0 === t && (t = -1), t < 0 && (t = 0 !== (n = e[0].rank) ? n : 0), t === e[0].rank && (t = -1), (0, _tfjsCore.concat)(e, t);
    }

    function concatAlongFirstAxis(e, t) {
      switch (e.rank) {
        case 1:
          return (0, _tfjsCore.concat1d)([e, t]);

        case 2:
          return (0, _tfjsCore.concat2d)([e, t], 0);

        case 3:
          return (0, _tfjsCore.concat3d)([e, t], 0);

        case 4:
          return (0, _tfjsCore.concat4d)([e, t], 0);

        default:
          throw new ValueError("concatAlongFirstAxis() received an unsupported tensor rank: " + e.rank);
      }
    }

    function tile$1(e, t) {
      if (Array.isArray(t) || (t = [t]), e.rank !== t.length) throw new ValueError("The length of input n (" + t.length + ") does not match the number of dimensions in input x (" + e.rank + ")");
      return (0, _tfjsCore.tile)(e, t);
    }

    function randomNormal$1(e, t, n, r, i) {
      return void 0 === t && (t = 0), void 0 === n && (n = 1), (0, _tfjsCore.randomNormal)(e, t, n, r, i);
    }

    function dot(e, t, n, r) {
      if (e.rank < 2 || t.rank < 2) throw new NotImplementedError("dot requires both inputs to be rank >= 2 but got x shape = " + e.shape + " and y shape = " + t.shape);
      if (t.rank >= 3 && e.shape.slice(-1)[0] !== (c = t.shape.slice(-2)[0])) throw new NotImplementedError("If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = " + e.shape + " and  y shape = " + t.shape);

      if (2 === e.rank && 2 === t.rank) {
        var i = !1,
          a = !1;
        return _tfjsCore.fused.matMul({
          a: e,
          b: t,
          transposeA: i,
          transposeB: a,
          bias: r ? reshapeBias(e.rank, r, imageDataFormat()) : null,
          activation: n
        });
      }

      var o = e.shape.slice(),
        s = o.pop();
      e = e.reshape([-1, s]);
      var l = t.shape.slice(),
        u = l.pop(),
        c = l.pop(),
        p = l.concat([u]),
        h = Array.from({
          length: t.rank
        }, function (e, n) {
          return 0 === n ? t.rank - 2 : n <= t.rank - 2 ? n - 1 : n;
        });
      t = t.transpose(h).reshape([c, -1]);
      var d = o.concat(p);
      i = !1, a = !1;
      return _tfjsCore.fused.matMul({
        a: e,
        b: t,
        transposeA: i,
        transposeB: a,
        bias: r ? reshapeBias(e.rank, r, imageDataFormat()) : null,
        activation: n
      }).reshape(d);
    }

    function gather$1(e, t, n) {
      return (0, _tfjsCore.tidy)(function () {
        return t = Array.isArray(t) ? (0, _tfjsCore.tensor1d)(t, "int32") : t.toInt(), (0, _tfjsCore.gather)(e, t, n);
      });
    }

    function square(e) {
      return (0, _tfjsCore.mulStrict)(e, e);
    }

    function reshapeBias(e, t, n) {
      var r = t.shape;
      if (1 !== t.rank && t.rank !== e) throw new ValueError("Unexpected bias dimensions: " + t.rank + "; expected it to be 1 or " + e);

      if (5 === e) {
        if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1, 1, 1]) : t.reshape([1, r[3], r[0], r[1], r[2]]);
        if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, 1, 1, r[0]]) : t.reshape([1].concat(r));
      } else if (4 === e) {
        if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1, 1]) : t.reshape([1, r[2], r[0], r[1]]);
        if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, 1, r[0]]) : t.reshape([1].concat(r));
      } else if (3 === e) {
        if ("channelsFirst" === n) return 1 === r.length ? t.reshape([1, r[0], 1]) : t.reshape([1, r[1], r[0]]);
        if ("channelsLast" === n) return 1 === r.length ? t.reshape([1, 1, r[0]]) : t.reshape([1].concat(r));
      } else if (e < 3) return t;

      throw new ValueError("Unsupported input rank by biasAdd: " + t.rank);
    }

    function biasAdd(e, t, n) {
      return (0, _tfjsCore.tidy)(function () {
        return null == n && (n = imageDataFormat()), checkDataFormat(n), e.add(reshapeBias(e.rank, t, n));
      });
    }

    function elu$1(e, t) {
      if (void 0 === t && (t = 1), 1 !== t) throw new NotImplementedError("Support for alpha values other than 1 (" + t + ") is not implemented yet.");
      return (0, _tfjsCore.elu)(e);
    }

    function softsign(e) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.div)(e, (0, _tfjsCore.abs)(e).add(1));
      });
    }

    function dropout$1(e, t, n, r) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.dropout)(e, t, n, r);
      });
    }

    function hardSigmoid(e) {
      return (0, _tfjsCore.tidy)(function () {
        var t = (0, _tfjsCore.add)(.5, (0, _tfjsCore.mul)(.2, e));
        return (0, _tfjsCore.clipByValue)(t, 0, 1);
      });
    }

    function inTrainPhase(e, t, n) {
      return void 0 === n && (n = !1), n ? e() : t();
    }

    var VALID_FAN_MODE_VALUES = ["fanIn", "fanOut", "fanAvg"],
      VALID_DISTRIBUTION_VALUES = ["normal", "uniform", "truncatedNormal"];

    function checkFanMode(e) {
      checkStringTypeUnionValue(VALID_FAN_MODE_VALUES, "FanMode", e);
    }

    function checkDistribution(e) {
      checkStringTypeUnionValue(VALID_DISTRIBUTION_VALUES, "Distribution", e);
    }

    var Initializer = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.fromConfigUsesCustomObjects = function () {
        return !1;
      }, t.prototype.getConfig = function () {
        return {};
      }, t;
    }(_tfjsCore.serialization.Serializable),
      Zeros = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.apply = function (e, t) {
          return (0, _tfjsCore.zeros)(e, t);
        }, t.className = "Zeros", t;
      }(Initializer);

    _tfjsCore.serialization.registerClass(Zeros);

    var Ones = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        return (0, _tfjsCore.ones)(e, t);
      }, t.className = "Ones", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(Ones);

    var Constant = function (e) {
      function t(t) {
        var n = e.call(this) || this;
        if ("object" != typeof t) throw new ValueError("Expected argument of type ConstantConfig but got " + t);
        if (void 0 === t.value) throw new ValueError("config must have value set but got " + t);
        return n.value = t.value, n;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return (0, _tfjsCore.mul)((0, _tfjsCore.scalar)(n.value), (0, _tfjsCore.ones)(e, t));
        });
      }, t.prototype.getConfig = function () {
        return {
          value: this.value
        };
      }, t.className = "Constant", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(Constant);

    var RandomUniform = 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 __extends(t, e), t.prototype.apply = function (e, t) {
        return (0, _tfjsCore.randomUniform)(e, this.minval, this.maxval, t);
      }, t.prototype.getConfig = function () {
        return {
          minval: this.minval,
          maxval: this.maxval,
          seed: this.seed
        };
      }, t.className = "RandomUniform", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(RandomUniform);

    var RandomNormal = 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 __extends(t, e), t.prototype.apply = function (e, t) {
        if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError("randomNormal does not support dType " + t + ".");
        return randomNormal$1(e, this.mean, this.stddev, t, this.seed);
      }, t.prototype.getConfig = function () {
        return {
          mean: this.mean,
          stddev: this.stddev,
          seed: this.seed
        };
      }, t.className = "RandomNormal", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(RandomNormal);

    var TruncatedNormal = 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 __extends(t, e), t.prototype.apply = function (e, t) {
        if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError("truncatedNormal does not support dType " + t + ".");
        return (0, _tfjsCore.truncatedNormal)(e, this.mean, this.stddev, t, this.seed);
      }, t.prototype.getConfig = function () {
        return {
          mean: this.mean,
          stddev: this.stddev,
          seed: this.seed
        };
      }, t.className = "TruncatedNormal", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(TruncatedNormal);

    var Identity = function (e) {
      function t(t) {
        var n = e.call(this) || this;
        return n.gain = null != t.gain ? t.gain : 1, n;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          if (2 !== e.length || e[0] !== e[1]) throw new ValueError("Identity matrix initializer can only be used for 2D square matrices.");
          return (0, _tfjsCore.mul)(n.gain, (0, _tfjsCore.eye)(e[0]));
        });
      }, t.prototype.getConfig = function () {
        return {
          gain: this.gain
        };
      }, t.className = "Identity", t;
    }(Initializer);

    function computeFans(e, t) {
      var n, r;
      if (void 0 === t && (t = "channelsLast"), checkDataFormat(t), 2 === e.length) n = e[0], r = e[1]; else if (-1 !== [3, 4, 5].indexOf(e.length)) {
        if ("channelsFirst" === t) {
          var i = arrayProd(e, 2);
          n = e[1] * i, r = e[0] * i;
        } else if ("channelsLast" === t) {
          i = arrayProd(e, 0, e.length - 2);
          n = e[e.length - 2] * i, r = e[e.length - 1] * i;
        }
      } else {
        var a = arrayProd(e);
        n = Math.sqrt(a), r = Math.sqrt(a);
      }
      return [n, r];
    }

    _tfjsCore.serialization.registerClass(Identity);

    var VarianceScaling = function (e) {
      function t(t) {
        var n = e.call(this) || this;
        if (t.scale < 0) throw new ValueError("scale must be a positive float. Got: " + t.scale);
        return n.scale = null == t.scale ? 1 : t.scale, n.mode = null == t.mode ? "fanIn" : t.mode, checkFanMode(n.mode), n.distribution = null == t.distribution ? "normal" : t.distribution, checkDistribution(n.distribution), n.seed = t.seed, n;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        var n = computeFans(e),
          r = n[0],
          i = n[1],
          a = this.scale;

        if ("fanIn" === this.mode ? a /= Math.max(1, r) : "fanOut" === this.mode ? a /= Math.max(1, i) : a /= Math.max(1, (r + i) / 2), "normal" === this.distribution) {
          var o = Math.sqrt(a);
          if ("float32" !== (t = t || "float32") && "int32" !== t) throw new NotImplementedError(this.getClassName() + " does not support dType " + t + ".");
          return (0, _tfjsCore.truncatedNormal)(e, 0, o, t, this.seed);
        }

        var s = Math.sqrt(3 * a);
        return (0, _tfjsCore.randomUniform)(e, -s, s, t);
      }, t.prototype.getConfig = function () {
        return {
          scale: this.scale,
          mode: this.mode,
          distribution: this.distribution,
          seed: this.seed
        };
      }, t.className = "VarianceScaling", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(VarianceScaling);

    var GlorotUniform = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 1,
          mode: "fanAvg",
          distribution: "uniform",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "GlorotUniform", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(GlorotUniform);

    var GlorotNormal = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 1,
          mode: "fanAvg",
          distribution: "normal",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "GlorotNormal", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(GlorotNormal);

    var HeNormal = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 2,
          mode: "fanIn",
          distribution: "normal",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "HeNormal", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(HeNormal);

    var HeUniform = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 2,
          mode: "fanIn",
          distribution: "uniform",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "HeUniform", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(HeUniform);

    var LeCunNormal = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 1,
          mode: "fanIn",
          distribution: "normal",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "LeCunNormal", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(LeCunNormal);

    var LeCunUniform = function (e) {
      function t(t) {
        return e.call(this, {
          scale: 1,
          mode: "fanIn",
          distribution: "uniform",
          seed: null == t ? null : t.seed
        }) || this;
      }

      return __extends(t, e), t.prototype.getClassName = function () {
        return VarianceScaling.className;
      }, t.className = "LeCunNormal", t;
    }(VarianceScaling);

    _tfjsCore.serialization.registerClass(LeCunUniform);

    var Orthogonal = 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 NotImplementedError("Random seed is not implemented for Orthogonal Initializer yet.");
        return n;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          if (2 !== e.length) throw new NotImplementedError("The Orthogonal Initializer does not support non-2D shapes yet.");
          e[0] * e[1] > 2e3 && console.warn("Orthogonal initializer is being called on a matrix with more than 2000 (" + e[0] * e[1] + ") elements: Slowness may result.");

          var t = randomNormal$1(e[0] > e[1] ? [e[1], e[0]] : e, 0, 1, "float32"),
            r = _tfjsCore.linalg.gramSchmidt(t);

          return e[0] > e[1] && (r = r.transpose()), (0, _tfjsCore.mul)(n.gain, r);
        });
      }, t.prototype.getConfig = function () {
        return {
          gain: this.gain,
          seed: this.seed
        };
      }, t.className = "Orthogonal", t;
    }(Initializer);

    _tfjsCore.serialization.registerClass(Orthogonal);

    var INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
      constant: "Constant",
      glorotNormal: "GlorotNormal",
      glorotUniform: "GlorotUniform",
      heNormal: "HeNormal",
      heUniform: "HeUniform",
      identity: "Identity",
      leCunNormal: "LeCunNormal",
      leCunUniform: "LeCunUniform",
      ones: "Ones",
      orthogonal: "Orthogonal",
      randomNormal: "RandomNormal",
      randomUniform: "RandomUniform",
      truncatedNormal: "TruncatedNormal",
      varianceScaling: "VarianceScaling",
      zeros: "Zeros"
    };

    function deserializeInitializer(e, t) {
      return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "initializer");
    }

    function serializeInitializer(e) {
      return serializeKerasObject(e);
    }

    function getInitializer(e) {
      if ("string" == typeof e) {
        var t = e in INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ? INITIALIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e;
        if ("GlorotNormal" === t) return new GlorotNormal();
        if ("GlorotUniform" === t) return new GlorotUniform();
        if ("HeNormal" === t) return new HeNormal();
        if ("HeUniform" === t) return new HeUniform();
        if ("LeCunNormal" === t) return new LeCunNormal();
        if ("LeCunUniform" === t) return new LeCunUniform();
        var n = {};
        return n.className = t, n.config = {}, deserializeInitializer(n);
      }

      return e instanceof Initializer ? e : deserializeInitializer(e);
    }

    function zeros$1() {
      return new Zeros();
    }

    function ones$1() {
      return new Ones();
    }

    function constant(e) {
      return new Constant(e);
    }

    function randomUniform$1(e) {
      return new RandomUniform(e);
    }

    function randomNormal$2(e) {
      return new RandomNormal(e);
    }

    function truncatedNormal$1(e) {
      return new TruncatedNormal(e);
    }

    function identity(e) {
      return new Identity(e);
    }

    function varianceScaling(e) {
      return new VarianceScaling(e);
    }

    function glorotUniform(e) {
      return new GlorotUniform(e);
    }

    function glorotNormal(e) {
      return new GlorotNormal(e);
    }

    function heNormal(e) {
      return new HeNormal(e);
    }

    function heUniform(e) {
      return new HeUniform(e);
    }

    function leCunNormal(e) {
      return new LeCunNormal(e);
    }

    function leCunUniform(e) {
      return new LeCunUniform(e);
    }

    function orthogonal(e) {
      return new Orthogonal(e);
    }

    var exports_initializers = Object.freeze({
      zeros: zeros$1,
      ones: ones$1,
      constant: constant,
      randomUniform: randomUniform$1,
      randomNormal: randomNormal$2,
      truncatedNormal: truncatedNormal$1,
      identity: identity,
      varianceScaling: varianceScaling,
      glorotUniform: glorotUniform,
      glorotNormal: glorotNormal,
      heNormal: heNormal,
      heUniform: heUniform,
      leCunNormal: leCunNormal,
      leCunUniform: leCunUniform,
      orthogonal: orthogonal
    }),
      _nextUniqueTensorId = 0;
    exports.initializers = exports_initializers;

    function getNextUniqueTensorId() {
      return _nextUniqueTensorId++;
    }

    var _uidPrefixes = {};

    function getUid(e) {
      return void 0 === e && (e = ""), e in _uidPrefixes || (_uidPrefixes[e] = 0), _uidPrefixes[e] += 1, e + _uidPrefixes[e].toString();
    }

    function isArrayOfShapes(e) {
      return Array.isArray(e) && Array.isArray(e[0]);
    }

    function normalizeShapeList(e) {
      return 0 === e.length ? [] : Array.isArray(e[0]) ? e : [e];
    }

    function getExactlyOneTensor(e) {
      var t;

      if (Array.isArray(e)) {
        if (1 !== e.length) throw new ValueError("Expected Tensor length to be 1; got " + e.length);
        t = e[0];
      } else t = e;

      return t;
    }

    function getExactlyOneShape(e) {
      if (Array.isArray(e) && Array.isArray(e[0])) {
        if (1 === e.length) return (e = e)[0];
        throw new ValueError("Expected exactly 1 Shape; got " + e.length);
      }

      return e;
    }

    function countParamsInWeights(e) {
      for (var t = 0, n = 0, r = e; n < r.length; n++) {
        var i = r[n];
        0 === i.shape.length ? t += 1 : t += i.shape.reduce(function (e, t) {
          return e * t;
        });
      }

      return t;
    }

    var DEFAULT_VARIABLE_NAME_PREFIX = "Variable",
      LayerVariable = function () {
        function e(e, t, n, r, i) {
          void 0 === t && (t = "float32"), void 0 === n && (n = DEFAULT_VARIABLE_NAME_PREFIX), void 0 === r && (r = !0), void 0 === i && (i = null), this.dtype = null == t ? "float32" : t, this.shape = e.shape, this.id = getNextUniqueTensorId(), n = null == n ? DEFAULT_VARIABLE_NAME_PREFIX : n, this.originalName = getScopedTensorName(n), this.name = getUniqueTensorName(this.originalName), this.trainable_ = r, this.constraint = i, this.val = (0, _tfjsCore.variable)(e, this.trainable_, this.name, this.dtype);
        }

        return e.prototype.read = function () {
          return this.assertNotDisposed(), this.val;
        }, e.prototype.write = function (e) {
          return this.assertNotDisposed(), checkShapesMatch(this.val, e), this.val.id !== e.id && (this.val.assign(e), null != this.constraint && this.val.assign(this.constraint.apply(this.val))), this;
        }, e.prototype.dispose = function () {
          this.assertNotDisposed(), this.val.dispose();
        }, e.prototype.assertNotDisposed = function () {
          if (this.val.isDisposed) throw new Error("LayersVariable " + this.name + " is already disposed.");
        }, Object.defineProperty(e.prototype, "trainable", {
          get: function () {
            return this.trainable_;
          },
          set: function (e) {
            this.trainable_ = e, this.val.trainable = e;
          },
          enumerable: !0,
          configurable: !0
        }), e;
      }();

    exports.LayerVariable = LayerVariable;

    function checkShapesMatch(e, t) {
      if (e.shape.toString() !== t.shape.toString()) throw new Error("Shape mismatch: " + JSON.stringify(e.shape) + " vs. " + JSON.stringify(t.shape));
    }

    function batchGetValue(e) {
      return e.map(function (e) {
        return e.read();
      });
    }

    function batchSetValue(e) {
      e.forEach(function (e) {
        e[0].write(e[1]);
      });
    }

    var InputSpec = 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 || {};
      };
    }(),
      SymbolicTensor = function () {
        return function (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 = getNextUniqueTensorId(), null != a && (this.originalName = getScopedTensorName(a), this.name = getUniqueTensorName(this.originalName)), this.rank = t.length;
        };
      }(),
      _nextNodeID = 0,
      Node = function () {
        function e(e, t) {
          this.callArgs = t, this.id = _nextNodeID++, 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; n < r.length; n++) {
            var i = r[n];
            null != i && i.outboundNodes.push(this);
          }

          e.outboundLayer.inboundNodes.push(this);
        }

        return e.prototype.getConfig = function () {
          for (var e = [], t = 0, n = this.inboundLayers; t < n.length; t++) {
            var r = n[t];
            null != r ? e.push(r.name) : e.push(null);
          }

          return {
            outboundLayer: this.outboundLayer ? this.outboundLayer.name : null,
            inboundLayers: e,
            nodeIndices: this.nodeIndices,
            tensorIndices: this.tensorIndices
          };
        }, e;
      }(),
      _nextLayerID = 0,
      Layer = function (e) {
        function t(t) {
          var n = e.call(this) || this;
          n._callHook = null, n._addedWeightNames = [], n._stateful = !1, n.id = _nextLayerID++, n.activityRegularizer = null, n.inputSpec = null, n.supportsMasking = !1, n._trainableWeights = [], n._nonTrainableWeights = [], n._losses = [], n._updates = [], n._built = !1, n.inboundNodes = [], n.outboundNodes = [];
          var r = t.name;

          if (!r) {
            var i = n.getClassName();
            r = toSnakeCase(i) + "_" + getUid(i);
          }

          if (n.name = r, n.trainable_ = null == t.trainable || t.trainable, null != t.inputShape || null != t.batchInputShape) {
            var a = void 0;
            if (null != t.batchInputShape) a = t.batchInputShape; else if (null != t.inputShape) {
              var o = null;
              null != t.batchSize && (o = t.batchSize), a = [o].concat(t.inputShape);
            }
            n.batchInputShape = a;
            var s = t.dtype;
            null == s && (s = t.inputDType), null == s && (s = "float32"), n.dtype = s;
          }

          return null != t.weights ? n.initialWeights = t.weights : n.initialWeights = null, n._refCount = null, n.fastWeightInitDuringBuild = !1, n;
        }

        return __extends(t, e), t.nodeKey = function (e, t) {
          return e.name + "_ib-" + t.toString();
        }, t.prototype.getNodeAtIndex = function (e, t) {
          if (0 === this.inboundNodes.length) throw new RuntimeError("The layer has never been called and thus has no defined " + t + ".");
          if (this.inboundNodes.length <= e) throw new ValueError("Asked to get " + t + " at node " + e + ", but the layer has only " + this.inboundNodes.length + " inbound nodes.");
          return this.inboundNodes[e];
        }, t.prototype.getInputAt = function (e) {
          return singletonOrArray(this.getNodeAtIndex(e, "input").inputTensors);
        }, t.prototype.getOutputAt = function (e) {
          return singletonOrArray(this.getNodeAtIndex(e, "output").outputTensors);
        }, Object.defineProperty(t.prototype, "input", {
          get: function () {
            if (this.inboundNodes.length > 1) throw new 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 AttributeError("Layer " + this.name + " is not connected, no input to return.");
            return singletonOrArray(this.getNodeAtIndex(0, "input").inputTensors);
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "output", {
          get: function () {
            if (0 === this.inboundNodes.length) throw new AttributeError("Layer " + this.name + " has no inbound nodes.");
            if (this.inboundNodes.length > 1) throw new AttributeError("Layer " + this.name + ' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');
            return singletonOrArray(this.getNodeAtIndex(0, "output").outputTensors);
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "losses", {
          get: function () {
            return this._losses;
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.calculateLosses = function () {
          return this.losses.map(function (e) {
            return e();
          });
        }, Object.defineProperty(t.prototype, "updates", {
          get: function () {
            return this._updates;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "built", {
          get: function () {
            return this._built;
          },
          set: function (e) {
            this._built = e;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "trainable", {
          get: function () {
            return this.trainable_;
          },
          set: function (e) {
            this._trainableWeights.forEach(function (t) {
              return t.trainable = e;
            }), this.trainable_ = e;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "trainableWeights", {
          get: function () {
            return this.trainable_ ? this._trainableWeights.filter(function (e) {
              return e.trainable;
            }) : [];
          },
          set: function (e) {
            this._trainableWeights = e;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
          get: function () {
            return this.trainable ? this._trainableWeights.filter(function (e) {
              return !e.trainable;
            }).concat(this._nonTrainableWeights) : this._trainableWeights.concat(this._nonTrainableWeights);
          },
          set: function (e) {
            this._nonTrainableWeights = e;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "weights", {
          get: function () {
            return this.trainableWeights.concat(this.nonTrainableWeights);
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "stateful", {
          get: function () {
            return this._stateful;
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.resetStates = function () {
          if (!this.stateful) throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.");
        }, t.prototype.assertInputCompatibility = function (e) {
          if (e = toList(e), null != this.inputSpec && 0 !== this.inputSpec.length) {
            var t = toList(this.inputSpec);
            if (e.length !== t.length) throw new ValueError("Layer " + this.name + " expects " + t.length + " inputs, but it received " + e.length + " input tensors. Input received: " + e);

            for (var n = 0; n < e.length; n++) {
              var r = e[n],
                i = t[n];

              if (null != i) {
                var a = r.rank;
                if (null != i.ndim && a !== i.ndim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected ndim=" + i.ndim + ", found ndim=" + a);
                if (null != i.maxNDim && a > i.maxNDim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected max_ndim=" + i.maxNDim + ", found ndim=" + a);
                if (null != i.minNDim && a < i.minNDim) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected min_ndim=" + i.minNDim + ", found ndim=" + a + ".");
                if (null != i.dtype && r.dtype !== i.dtype) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + " : expected dtype=" + i.dtype + ", found dtype=" + r.dtype + ".");

                if (i.axes) {
                  var o = r.shape;

                  for (var s in i.axes) {
                    var l = Number(s),
                      u = i.axes[s],
                      c = l >= 0 ? o[l] : o[o.length + l];
                    if (null != u && -1 === [u, null].indexOf(c)) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected axis " + l + " of input shape to have value " + u + " but got shape " + o + ".");
                  }
                }

                if (null != i.shape) for (var p = 0; p < i.shape.length; ++p) {
                  var h = i.shape[p],
                    d = r.shape[p];
                  if (null != h && null != d && h !== d) throw new ValueError("Input " + n + " is incompatible with layer " + this.name + ": expected shape=" + i.shape + ", found shape=" + r.shape + ".");
                }
              }
            }
          }
        }, t.prototype.call = function (e, t) {
          return e;
        }, t.prototype.invokeCallHook = function (e, t) {
          null != this._callHook && this._callHook(e, t);
        }, t.prototype.setCallHook = function (e) {
          this._callHook = e;
        }, t.prototype.clearCallHook = function () {
          this._callHook = null;
        }, t.prototype.apply = function (e, t) {
          var n = this;
          t = t || {}, this.assertNotDisposed();

          for (var r = toList(e), i = !0, a = 0, o = r; a < o.length; a++) {
            if (!(o[a] instanceof SymbolicTensor)) {
              i = !1;
              break;
            }
          }

          for (var s = !0, l = 0, u = r; l < u.length; l++) {
            if (u[l] instanceof SymbolicTensor) {
              s = !1;
              break;
            }
          }

          if (i === s) throw new ValueError("Arguments to apply() must be all SymbolicTensors or all Tensors");
          return nameScope(this.name, function () {
            if (!n.built) {
              n.assertInputCompatibility(e);

              for (var i = [], a = 0, o = toList(e); a < o.length; a++) {
                var l = o[a];
                i.push(l.shape);
              }

              n.build(singletonOrArray(i)), n.built = !0, n.initialWeights && n.setWeights(n.initialWeights), null === n._refCount && s && (n._refCount = 1);
            }

            if (n.assertInputCompatibility(e), s) {
              for (var u = [], c = 0, p = toList(g = n.call(e, t)); c < p.length; c++) {
                var h = p[c];
                -1 !== r.indexOf(h) && (h = h.clone()), u.push(h);
              }

              if (g = singletonOrArray(u), null != n.activityRegularizer) throw new NotImplementedError("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
              return g;
            }

            var d = collectInputShape(e),
              f = n.computeOutputShape(d),
              g = void 0,
              m = guessOutputDType(e);
            if (n.warnOnIncompatibleInputShape(Array.isArray(e) ? d[0] : d), g = null != f && f.length > 0 && Array.isArray(f[0]) ? f.map(function (r, i) {
              return new SymbolicTensor(m, r, n, toList(e), t, n.name, i);
            }) : new SymbolicTensor(m, f, n, toList(e), t, n.name), n.addInboundNode(e, g, null, null, d, f, t), n._refCount++, null != n.activityRegularizer) throw new NotImplementedError("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
            return g;
          });
        }, t.prototype.warnOnIncompatibleInputShape = function (e) {
          if (null != this.batchInputShape) if (e.length !== this.batchInputShape.length) console.warn("The rank of the input tensor provided (shape: " + JSON.stringify(e) + ") does not match that of the batchInputShape (" + JSON.stringify(this.batchInputShape) + ") of the layer " + this.name); else {
            var t = !1;
            this.batchInputShape.forEach(function (n, r) {
              null != n && null != e[r] && e[r] !== n && (t = !0);
            }), t && console.warn("The shape of the input tensor (" + JSON.stringify(e) + ") does not match the expectation of layer " + this.name + ": " + JSON.stringify(this.batchInputShape));
          }
        }, Object.defineProperty(t.prototype, "outputShape", {
          get: function () {
            if (null == this.inboundNodes || 0 === this.inboundNodes.length) throw new AttributeError("The layer " + this.name + " has never been called and thus has no defined output shape.");

            for (var e = [], t = 0, n = this.inboundNodes; t < n.length; t++) {
              var r = n[t],
                i = JSON.stringify(r.outputShapes);
              -1 === e.indexOf(i) && e.push(i);
            }

            if (1 === e.length) {
              var a = this.inboundNodes[0].outputShapes;
              return Array.isArray(a) && Array.isArray(a[0]) && 1 === a.length ? a[0] : a;
            }

            throw new AttributeError("The layer " + this.name + ' has multiple inbound nodes with different output shapes. Hence the notion of "outut shape" is ill-defined for the layer.');
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.countParams = function () {
          if (!this.built) throw new RuntimeError("You tried to call countParams() on " + this.name + ", but the layer is not built yet. Build it first by calling build(batchInputShape).");
          return countParamsInWeights(this.weights);
        }, t.prototype.build = function (e) {
          this.built = !0;
        }, t.prototype.getWeights = function (e) {
          return void 0 === e && (e = !1), batchGetValue(e ? this.trainableWeights : this.weights);
        }, t.prototype.setWeights = function (e) {
          var t = this;
          (0, _tfjsCore.tidy)(function () {
            var n = t.weights;
            if (n.length !== e.length) throw new ValueError('You called setWeights(weights) on layer "' + t.name + '" with a weight list of length ' + e.length + ", but the layer was expecting " + n.length + " weights. Provided weights: " + e + "...");

            if (0 !== n.length) {
              for (var r = [], i = batchGetValue(n), a = 0; a < i.length; ++a) {
                var o = i[a],
                  s = n[a],
                  l = e[a];
                if (!_tfjsCore.util.arraysEqual(o.shape, l.shape)) throw new ValueError("Layer weight shape " + o.shape + " not compatible with provided weight shape " + l.shape);
                r.push([s, l]);
              }

              batchSetValue(r);
            }
          });
        }, t.prototype.addWeight = function (e, t, n, r, i, a, o) {
          if (-1 !== this._addedWeightNames.indexOf(e)) throw new ValueError("Duplicate weight name " + e + " for layer " + this.name);
          this._addedWeightNames.push(e), null == n && (n = "float32"), this.fastWeightInitDuringBuild && (r = getInitializer("zeros"));
          var s = r.apply(t, n),
            l = new LayerVariable(s, n, e, a, o);
          return s.dispose(), null != i && this.addLoss(function () {
            return i.apply(l.read());
          }), null == a && (a = !0), a ? this._trainableWeights.push(l) : this._nonTrainableWeights.push(l), l;
        }, t.prototype.setFastWeightInitDuringBuild = function (e) {
          this.fastWeightInitDuringBuild = e;
        }, t.prototype.addLoss = function (e) {
          var t;
          null == e || Array.isArray(e) && 0 === e.length || (e = toList(e), void 0 !== this._losses && null !== this._losses && (t = this.losses).push.apply(t, e));
        }, t.prototype.computeOutputShape = function (e) {
          return e;
        }, t.prototype.computeMask = function (e, t) {
          var n = this;

          if (!this.supportsMasking) {
            if (null != t) {
              if (!Array.isArray(t)) throw new TypeError("Layer " + this.name + " does not support masking, but was passed an inputMask.");
              t.forEach(function (e) {
                if (null != e) throw new TypeError("Layer " + n.name + " does not support masking, but was passed an inputMask.");
              });
            }

            return null;
          }

          return t;
        }, t.prototype.addInboundNode = function (e, t, n, r, i, a, o) {
          void 0 === o && (o = null);
          var s = toList(e);
          t = toList(t), n = toList(n), r = toList(r), i = normalizeShapeList(i), a = normalizeShapeList(a);

          for (var l = [], u = [], c = [], p = 0, h = s; p < h.length; p++) {
            var d = h[p];
            l.push(d.sourceLayer), u.push(d.nodeIndex), c.push(d.tensorIndex);
          }

          new Node({
            outboundLayer: this,
            inboundLayers: l,
            nodeIndices: u,
            tensorIndices: c,
            inputTensors: s,
            outputTensors: t,
            inputMasks: n,
            outputMasks: r,
            inputShapes: i,
            outputShapes: a
          }, o);

          for (var f = 0; f < t.length; f++) t[f].sourceLayer = this, t[f].nodeIndex = this.inboundNodes.length - 1, t[f].tensorIndex = f;
        }, t.prototype.getConfig = function () {
          var e = {
            name: this.name,
            trainable: this.trainable
          };
          return null != this.batchInputShape && (e.batchInputShape = this.batchInputShape), null != this.dtype && (e.dtype = this.dtype), e;
        }, t.prototype.disposeWeights = function () {
          return this.weights.forEach(function (e) {
            return e.dispose();
          }), this.weights.length;
        }, t.prototype.assertNotDisposed = function () {
          if (0 === this._refCount) throw new Error("Layer '" + this.name + "' is already disposed.");
        }, t.prototype.dispose = function () {
          if (!this.built) throw new Error("Cannot dispose Layer " + this.name + " because it has not been built yet.");
          if (null === this._refCount) throw new Error("Cannot dispose Layer " + this.name + " because it has not been used yet.");
          this.assertNotDisposed();
          var e = 0;
          return 0 == --this._refCount && (e = this.disposeWeights()), {
            refCountAfterDispose: this._refCount,
            numDisposedVariables: e
          };
        }, t;
      }(_tfjsCore.serialization.Serializable);

    exports.SymbolicTensor = SymbolicTensor;
    exports.InputSpec = InputSpec;

    function collectInputShape(e) {
      for (var t = [], n = 0, r = e = toList(e); n < r.length; n++) {
        var i = r[n];
        t.push(i.shape);
      }

      return singletonOrArray(t);
    }

    function guessOutputDType(e) {
      return "float32";
    }

    function getSourceInputs(e, t, n) {
      if ((null == t || null != n && n > 0) && (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 = [], a = 0; a < r.inboundLayers.length; a++) for (var o = 0, s = getSourceInputs(r.inputTensors[a], r.inboundLayers[a], r.nodeIndices[a]); o < s.length; o++) {
        var l = s[o];
        -1 === i.indexOf(l) && i.push(l);
      }

      return i;
    }

    var ModelLoggingVerbosity,
      InputLayer = function (e) {
        function t(t) {
          var n = e.call(this, {
            dtype: t.dtype,
            name: null != t.name ? t.name : getUid("input").toString()
          }) || this;
          if (null == t.batchSize && (t.batchSize = null), null == t.sparse && (t.sparse = !1), n.trainable = !1, n.built = !0, n.sparse = t.sparse, null != t.inputShape && null != t.batchInputShape) throw new ValueError("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time.");
          var r = t.batchInputShape;

          if (null == r) {
            if (null == t.inputShape) throw new ValueError("An InputLayer should be passed either a `batchInputShape` or an `inputShape`.");
            r = [t.batchSize].concat(t.inputShape);
          } else if (null != t.batchSize) throw new ValueError("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer.");

          var i = t.dtype || "float32";
          n.batchInputShape = r, n.dtype = i, n.inputSpec = [{
            shape: r
          }];
          var a = new SymbolicTensor(n.dtype, n.batchInputShape, n, [], {}, n.name);
          return a.nodeIndex = 0, a.tensorIndex = 0, new Node({
            outboundLayer: n,
            inboundLayers: [],
            nodeIndices: [],
            tensorIndices: [],
            inputTensors: [a],
            outputTensors: [a],
            inputMasks: [null],
            outputMasks: [null],
            inputShapes: [r],
            outputShapes: [r]
          }), n;
        }

        return __extends(t, e), t.prototype.apply = function (e, t) {
          throw new ValueError("Cannot pass any input to an InputLayer's apply() method. InputLayer name: " + this.name);
        }, t.prototype.dispose = function () {
          return {
            refCountAfterDispose: this._refCount,
            numDisposedVariables: 0
          };
        }, t.prototype.getConfig = function () {
          return {
            batchInputShape: this.batchInputShape,
            dtype: this.dtype,
            sparse: this.sparse,
            name: this.name
          };
        }, t.className = "InputLayer", t;
      }(Layer);

    function Input(e) {
      if (null == e.batchShape && null == e.shape) throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension.");
      if (null != e.batchShape && null != e.shape) throw new ValueError("Please provide either a `shape` or `batchShape` argument to Input, but not both.");
      var t = e.batchShape;
      null != e.shape && null == t && (t = [null].concat(e.shape));
      var n = e.dtype;
      return null == n && (n = "float32"), new InputLayer({
        batchInputShape: t,
        name: e.name,
        dtype: n,
        sparse: e.sparse
      }).inboundNodes[0].outputTensors[0];
    }

    function resolveScalarsInLogs(e) {
      return __awaiter(this, void 0, void 0, function () {
        var t, n, r, i, a, o, s, l;
        return __generator(this, function (u) {
          switch (u.label) {
            case 0:
              if (null == e) return [2];

              for (i in t = [], n = [], r = [], e) "number" != typeof (a = e[i]) && (o = a, t.push(o.data()), n.push(i), r.push(o));

              return t.length > 0 ? [4, Promise.all(t)] : [3, 2];

            case 1:
              for (s = u.sent(), l = 0; l < s.length; ++l) e[n[l]] = s[l][0];

              (0, _tfjsCore.dispose)(r), u.label = 2;

            case 2:
              return [2];
          }
        });
      });
    }

    function disposeTensorsInLogs(e) {
      if (null != e) for (var t in e) {
        var n = e[t];
        "number" != typeof n && n.dispose();
      }
    }

    _tfjsCore.serialization.registerClass(InputLayer), function (e) {
      e[e.SILENT = 0] = "SILENT", e[e.VERBOSE = 1] = "VERBOSE";
    }(ModelLoggingVerbosity || (ModelLoggingVerbosity = {}));

    var DEFAULT_YIELD_EVERY_MS = 125,
      BaseCallback = function () {
        function e() {
          this.validationData = null;
        }

        return e.prototype.setParams = function (e) {
          this.params = e;
        }, e.prototype.onEpochBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.onEpochEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.onBatchBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.onBatchEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.onTrainBegin = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.onTrainEnd = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2];
            });
          });
        }, e.prototype.setModel = function (e) { }, e;
      }(),
      CallbackList = function () {
        function e(e, t) {
          void 0 === t && (t = 10), null == e && (e = []), this.callbacks = e, this.queueLength = t;
        }

        return e.prototype.append = function (e) {
          this.callbacks.push(e);
        }, e.prototype.setParams = function (e) {
          for (var t = 0, n = this.callbacks; t < n.length; t++) {
            n[t].setParams(e);
          }
        }, e.prototype.setModel = function (e) {
          for (var t = 0, n = this.callbacks; t < n.length; t++) {
            n[t].setModel(e);
          }
        }, e.prototype.onEpochBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;

                case 1:
                  return n < r.length ? [4, r[n].onEpochBegin(e, t)] : [3, 4];

                case 2:
                  i.sent(), i.label = 3;

                case 3:
                  return n++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e.prototype.onEpochEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;

                case 1:
                  return n < r.length ? [4, r[n].onEpochEnd(e, t)] : [3, 4];

                case 2:
                  i.sent(), i.label = 3;

                case 3:
                  return n++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e.prototype.onBatchBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;

                case 1:
                  return n < r.length ? [4, r[n].onBatchBegin(e, t)] : [3, 4];

                case 2:
                  i.sent(), i.label = 3;

                case 3:
                  return n++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e.prototype.onBatchEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  null == t && (t = {}), n = 0, r = this.callbacks, i.label = 1;

                case 1:
                  return n < r.length ? [4, r[n].onBatchEnd(e, t)] : [3, 4];

                case 2:
                  i.sent(), i.label = 3;

                case 3:
                  return n++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e.prototype.onTrainBegin = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            var t, n;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  null == e && (e = {}), t = 0, n = this.callbacks, r.label = 1;

                case 1:
                  return t < n.length ? [4, n[t].onTrainBegin(e)] : [3, 4];

                case 2:
                  r.sent(), r.label = 3;

                case 3:
                  return t++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e.prototype.onTrainEnd = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            var t, n;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  null == e && (e = {}), t = 0, n = this.callbacks, r.label = 1;

                case 1:
                  return t < n.length ? [4, n[t].onTrainEnd(e)] : [3, 4];

                case 2:
                  r.sent(), r.label = 3;

                case 3:
                  return t++, [3, 1];

                case 4:
                  return [2];
              }
            });
          });
        }, e;
      }(),
      BaseLogger = function (e) {
        function t() {
          return e.call(this) || this;
        }

        return __extends(t, e), t.prototype.onEpochBegin = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return this.seen = 0, this.totals = {}, [2];
            });
          });
        }, t.prototype.onBatchEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var e,
              n,
              r,
              i,
              a = this;
            return __generator(this, function (o) {
              for (i in null == t && (t = {}), e = null == t.size ? 0 : t.size, this.seen += e, n = function (n) {
                var i = t[n];
                if ("number" == typeof i) r.totals.hasOwnProperty(n) || (r.totals[n] = 0), r.totals[n] = r.totals[n] + i * e; else {
                  var o = void 0;
                  n in r.totals ? o = r.totals[n] : r.totals[n] = 0;
                  var s = (0, _tfjsCore.tidy)(function () {
                    return (0, _tfjsCore.add)(a.totals[n], (0, _tfjsCore.mul)(i, e));
                  });
                  r.totals[n] = s, null != o && o.dispose();
                }
              }, r = this, t) n(i);

              return [2];
            });
          });
        }, t.prototype.onEpochEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var e,
              n,
              r,
              i,
              a,
              o = this;
            return __generator(this, function (s) {
              if (null != t) for (e = function (e) {
                if (null == n.totals[e]) return "continue";
                "number" == typeof n.totals[e] ? t[e] = n.totals[e] / n.seen : (0, _tfjsCore.tidy)(function () {
                  var n = (0, _tfjsCore.mul)((0, _tfjsCore.div)(1, o.seen), o.totals[e]);
                  t[e] = n, o.totals[e].dispose(), (0, _tfjsCore.keep)(t[e]);
                });
              }, n = this, r = 0, i = this.params.metrics; r < i.length; r++) a = i[r], e(a);
              return [2];
            });
          });
        }, t;
      }(BaseCallback),
      History = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.onTrainBegin = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return this.epoch = [], this.history = {}, [2];
            });
          });
        }, t.prototype.onEpochEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n;
            return __generator(this, function (r) {
              for (n in null == t && (t = {}), this.epoch.push(e), t) null == this.history[n] && (this.history[n] = []), this.history[n].push(t[n]);

              return [2];
            });
          });
        }, t.prototype.syncData = function () {
          return __awaiter(this, void 0, void 0, function () {
            var e, t, n, r, i, a, o, s, l;
            return __generator(this, function (u) {
              switch (u.label) {
                case 0:
                  for (r in e = [], t = [], n = [], this.history) for (i = this.history[r], a = 0; a < i.length; ++a) "number" != typeof i[a] && (o = i[a], e.push(o.data()), t.push(r), n.push(a));

                  return [4, Promise.all(e)];

                case 1:
                  for (s = u.sent(), l = 0; l < s.length; ++l) this.history[t[l]][n[l]].dispose(), this.history[t[l]][n[l]] = s[l][0];

                  return [2];
              }
            });
          });
        }, t;
      }(BaseCallback),
      CustomCallback = function (e) {
        function t(t, n) {
          var r = e.call(this) || this;
          if (r.currentEpoch = 0, r.yieldEvery = n || "auto", "auto" === r.yieldEvery && (r.yieldEvery = DEFAULT_YIELD_EVERY_MS), "never" === r.yieldEvery && null != t.onYield) throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback");
          return _tfjsCore.util.isNumber(r.yieldEvery) && (r.maybeWait = debounce(r.maybeWait.bind(r), r.yieldEvery)), r.trainBegin = t.onTrainBegin, r.trainEnd = t.onTrainEnd, r.epochBegin = t.onEpochBegin, r.epochEnd = t.onEpochEnd, r.batchBegin = t.onBatchBegin, r.batchEnd = t.onBatchEnd, r.yield = t.onYield, r;
        }

        return __extends(t, e), t.prototype.maybeWait = function (e, t, n) {
          return __awaiter(this, void 0, void 0, function () {
            var r;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  return r = [], null == this.yield ? [3, 2] : [4, resolveScalarsInLogs(n)];

                case 1:
                  i.sent(), r.push(this.yield(e, t, n)), i.label = 2;

                case 2:
                  return r.push((0, _tfjsCore.nextFrame)()), [4, Promise.all(r)];

                case 3:
                  return i.sent(), [2];
              }
            });
          });
        }, t.prototype.onEpochBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return this.currentEpoch = e, null == this.epochBegin ? [3, 3] : [4, resolveScalarsInLogs(t)];

                case 1:
                  return n.sent(), [4, this.epochBegin(e, t)];

                case 2:
                  n.sent(), n.label = 3;

                case 3:
                  return [2];
              }
            });
          });
        }, t.prototype.onEpochEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return n = [], null == this.epochEnd ? [3, 2] : [4, resolveScalarsInLogs(t)];

                case 1:
                  r.sent(), n.push(this.epochEnd(e, t)), r.label = 2;

                case 2:
                  return "epoch" === this.yieldEvery && n.push((0, _tfjsCore.nextFrame)()), [4, Promise.all(n)];

                case 3:
                  return r.sent(), [2];
              }
            });
          });
        }, t.prototype.onBatchBegin = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return null == this.batchBegin ? [3, 3] : [4, resolveScalarsInLogs(t)];

                case 1:
                  return n.sent(), [4, this.batchBegin(e, t)];

                case 2:
                  n.sent(), n.label = 3;

                case 3:
                  return [2];
              }
            });
          });
        }, t.prototype.onBatchEnd = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return n = [], null == this.batchEnd ? [3, 2] : [4, resolveScalarsInLogs(t)];

                case 1:
                  r.sent(), n.push(this.batchEnd(e, t)), r.label = 2;

                case 2:
                  return "batch" === this.yieldEvery ? n.push((0, _tfjsCore.nextFrame)()) : _tfjsCore.util.isNumber(this.yieldEvery) && n.push(this.maybeWait(this.currentEpoch, e, t)), [4, Promise.all(n)];

                case 3:
                  return r.sent(), [2];
              }
            });
          });
        }, t.prototype.onTrainBegin = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return null == this.trainBegin ? [3, 3] : [4, resolveScalarsInLogs(e)];

                case 1:
                  return t.sent(), [4, this.trainBegin(e)];

                case 2:
                  t.sent(), t.label = 3;

                case 3:
                  return [2];
              }
            });
          });
        }, t.prototype.onTrainEnd = function (e) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return null == this.trainEnd ? [3, 3] : [4, resolveScalarsInLogs(e)];

                case 1:
                  return t.sent(), [4, this.trainEnd(e)];

                case 2:
                  t.sent(), t.label = 3;

                case 3:
                  return [2];
              }
            });
          });
        }, t;
      }(BaseCallback);

    exports.CustomCallback = CustomCallback;
    exports.History = History;
    exports.CallbackList = CallbackList;

    function standardizeCallbacks(e, t) {
      return null == e && (e = {}), e instanceof BaseCallback ? [e] : Array.isArray(e) && e[0] instanceof BaseCallback ? e : toList(e).map(function (e) {
        return new CustomCallback(e, t);
      });
    }

    var CallbackConstructorRegistry = function () {
      function e() { }

      return e.registerCallbackConstructor = function (t, n) {
        _tfjsCore.util.assert(t >= 0 && Number.isInteger(t), function () {
          return "Verbosity level is expected to be an integer >= 0, but got " + t;
        }), e.checkForDuplicate(n), null == e.constructors[t] && (e.constructors[t] = []), e.constructors[t].push(n);
      }, e.checkForDuplicate = function (t) {
        for (var n in e.constructors) {
          e.constructors[+n].forEach(function (e) {
            if (e === t) throw new ValueError("Duplicate callback constructor.");
          });
        }
      }, e.clear = function () {
        e.constructors = {};
      }, e.createCallbacks = function (t) {
        var n = [];

        for (var r in e.constructors) {
          var i = +r;
          t >= i && n.push.apply(n, e.constructors[i]);
        }

        return n.map(function (e) {
          return new e();
        });
      }, e.constructors = {}, e;
    }();

    function configureCallbacks(e, t, n, r, i, a, o, s, l) {
      var u = new History(),
        c = [new BaseLogger()].concat(CallbackConstructorRegistry.createCallbacks(t));
      null != e && c.push.apply(c, e), c.push(u);
      var p = new CallbackList(c);
      return p.setParams({
        epochs: n,
        initialEpoch: r,
        samples: i,
        steps: a,
        batchSize: o,
        verbose: t,
        doValidation: s,
        metrics: l
      }), {
        callbackList: p,
        history: u
      };
    }

    function deserialize(e, t, n) {
      return void 0 === t && (t = {}), void 0 === n && (n = !1), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "layer", n);
    }

    function l2Normalize(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        "float32" !== e.dtype && (e = e.asType("float32"));
        var n = (0, _tfjsCore.sum)(square(e), t, !0),
          r = (0, _tfjsCore.fill)(n.shape, epsilon()),
          i = (0, _tfjsCore.sqrt)((0, _tfjsCore.maximum)(n, r));
        return (0, _tfjsCore.div)(e, i);
      });
    }

    function meanSquaredError(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.mean)(square((0, _tfjsCore.sub)(t, e)), -1);
      });
    }

    function meanAbsoluteError(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.mean)((0, _tfjsCore.abs)((0, _tfjsCore.sub)(t, e)), -1);
      });
    }

    function meanAbsolutePercentageError(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.sub)(e, t),
          r = (0, _tfjsCore.clipByValue)((0, _tfjsCore.abs)(e), epsilon(), Number.MAX_VALUE),
          i = (0, _tfjsCore.abs)((0, _tfjsCore.div)(n, r));
        return (0, _tfjsCore.mul)(100, (0, _tfjsCore.mean)(i, -1));
      });
    }

    function meanSquaredLogarithmicError(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.clipByValue)(t, epsilon(), Number.MAX_VALUE),
          r = (0, _tfjsCore.log)((0, _tfjsCore.add)(1, n)),
          i = (0, _tfjsCore.clipByValue)(e, epsilon(), Number.MAX_VALUE),
          a = (0, _tfjsCore.log)((0, _tfjsCore.add)(1, i));
        return (0, _tfjsCore.mean)(square((0, _tfjsCore.sub)(r, a)), -1);
      });
    }

    function squaredHinge(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.maximum)(0, (0, _tfjsCore.sub)(1, (0, _tfjsCore.mul)(e, t)));
        return (0, _tfjsCore.mean)(square(n), -1);
      });
    }

    function hinge(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.maximum)(0, (0, _tfjsCore.sub)(1, (0, _tfjsCore.mul)(e, t)));
        return (0, _tfjsCore.mean)(n, -1);
      });
    }

    function categoricalHinge(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.sum)((0, _tfjsCore.mul)(e, t), -1),
          r = (0, _tfjsCore.max)((0, _tfjsCore.mul)((0, _tfjsCore.sub)(1, e), t), -1);
        return (0, _tfjsCore.maximum)(0, (0, _tfjsCore.add)(1, (0, _tfjsCore.sub)(r, n)));
      });
    }

    function logcosh(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = Math.log(2),
          r = (0, _tfjsCore.sub)(t, e),
          i = (0, _tfjsCore.sub)((0, _tfjsCore.add)(r, (0, _tfjsCore.softplus)((0, _tfjsCore.mul)(-2, r))), n);
        return (0, _tfjsCore.mean)(i, -1);
      });
    }

    function categoricalCrossentropy(e, t, n) {
      return void 0 === n && (n = !1), (0, _tfjsCore.tidy)(function () {
        if (n) t = (0, _tfjsCore.softmax)(t); else {
          var r = (0, _tfjsCore.sum)(t, t.shape.length - 1, !0);
          t = (0, _tfjsCore.div)(t, r);
        }
        return t = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon()), (0, _tfjsCore.neg)((0, _tfjsCore.sum)((0, _tfjsCore.mul)(e.toFloat(), (0, _tfjsCore.log)(t)), t.shape.length - 1));
      });
    }

    function sparseCategoricalCrossentropy(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.floor)(flatten(e)).toInt(),
          r = (t = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon())).shape;
        return categoricalCrossentropy((0, _tfjsCore.oneHot)(n, r[r.length - 1]).reshape(r), t, !1);
      });
    }

    function sigmoidCrossEntropyWithLogits(e, t) {
      if (!_tfjsCore.util.arraysEqual(e.shape, t.shape)) throw new ValueError("logits and labels must have the same shape, but got shapes " + JSON.stringify(e.shape) + " and " + JSON.stringify(t.shape));
      return (0, _tfjsCore.tidy)(function () {
        var n = t.relu(),
          r = t.abs().neg();
        return n.sub(t.mul(e)).add(r.exp().log1p());
      });
    }

    function binaryCrossentropy(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n;
        return n = (0, _tfjsCore.clipByValue)(t, epsilon(), 1 - epsilon()), n = (0, _tfjsCore.log)((0, _tfjsCore.div)(n, (0, _tfjsCore.sub)(1, n))), (0, _tfjsCore.mean)(sigmoidCrossEntropyWithLogits(e, n), -1);
      });
    }

    function kullbackLeiblerDivergence(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.clipByValue)(e, epsilon(), 1),
          r = (0, _tfjsCore.clipByValue)(t, epsilon(), 1);
        return (0, _tfjsCore.sum)((0, _tfjsCore.mul)(e, (0, _tfjsCore.log)((0, _tfjsCore.div)(n, r))), -1);
      });
    }

    function poisson(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.log)((0, _tfjsCore.add)(epsilon(), t));
        return (0, _tfjsCore.mean)((0, _tfjsCore.sub)(t, (0, _tfjsCore.mul)(e, n)), -1);
      });
    }

    function cosineProximity(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = l2Normalize(e, -1),
          r = l2Normalize(t, -1),
          i = (0, _tfjsCore.mul)(n, r);
        return (0, _tfjsCore.neg)((0, _tfjsCore.sum)(i, -1));
      });
    }

    var lossesMap = {
      meanSquaredError: meanSquaredError,
      meanAbsoluteError: meanAbsoluteError,
      meanAbsolutePercentageError: meanAbsolutePercentageError,
      meanSquaredLogarithmicError: meanSquaredLogarithmicError,
      squaredHinge: squaredHinge,
      hinge: hinge,
      categoricalHinge: categoricalHinge,
      logcosh: logcosh,
      categoricalCrossentropy: categoricalCrossentropy,
      sparseCategoricalCrossentropy: sparseCategoricalCrossentropy,
      binaryCrossentropy: binaryCrossentropy,
      kullbackLeiblerDivergence: kullbackLeiblerDivergence,
      poisson: poisson,
      cosineProximity: cosineProximity
    };

    function get(e) {
      if ("string" == typeof e) {
        if (e in lossesMap) return lossesMap[e];
        var t = "Unknown loss " + e;
        throw e.toLowerCase().includes("softmaxcrossentropy") && (t = "Unknown loss " + e + '. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy'), new ValueError(t);
      }

      return e;
    }

    function binaryAccuracy(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = (0, _tfjsCore.mul)(.5, (0, _tfjsCore.onesLike)(t)),
          r = cast$1((0, _tfjsCore.greater)(t, n), e.dtype);
        return (0, _tfjsCore.mean)((0, _tfjsCore.equal)(e, r), -1);
      });
    }

    function categoricalAccuracy(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return cast$1((0, _tfjsCore.equal)((0, _tfjsCore.argMax)(e, -1), (0, _tfjsCore.argMax)(t, -1)), "float32");
      });
    }

    function truePositives(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.logicalAnd)(e.equal(1), t.equal(1)).sum().cast("float32");
      });
    }

    function falseNegatives(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.logicalAnd)(e.equal(1), t.equal(0)).sum().cast("float32");
      });
    }

    function falsePositives(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return (0, _tfjsCore.logicalAnd)(e.equal(0), t.equal(1)).sum().cast("float32");
      });
    }

    function precision(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = truePositives(e, t),
          r = falsePositives(e, t),
          i = n.add(r);
        return (0, _tfjsCore.where)((0, _tfjsCore.greater)(i, 0), n.div(i), 0).cast("float32");
      });
    }

    function recall(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        var n = truePositives(e, t),
          r = falseNegatives(e, t),
          i = n.add(r);
        return (0, _tfjsCore.where)((0, _tfjsCore.greater)(i, 0), n.div(i), 0).cast("float32");
      });
    }

    function binaryCrossentropy$1(e, t) {
      return binaryCrossentropy(e, t);
    }

    function sparseCategoricalAccuracy(e, t) {
      return e.rank === t.rank && (e = e.squeeze([e.rank - 1])), (t = t.argMax(-1)).dtype !== e.dtype && (t = t.asType(e.dtype)), (0, _tfjsCore.equal)(e, t).asType("float32");
    }

    var mse$1 = meanSquaredError,
      MSE$1 = meanSquaredError,
      mae$1 = meanAbsoluteError,
      MAE$1 = meanAbsoluteError,
      mape$1 = meanAbsolutePercentageError,
      MAPE$1 = meanAbsolutePercentageError,
      categoricalCrossentropy$1 = categoricalCrossentropy,
      cosine$1 = cosineProximity,
      sparseCategoricalCrossentropy$1 = sparseCategoricalCrossentropy,
      metricsMap = {
        binaryAccuracy: binaryAccuracy,
        categoricalAccuracy: categoricalAccuracy,
        precision: precision,
        categoricalCrossentropy: categoricalCrossentropy$1,
        sparseCategoricalCrossentropy: sparseCategoricalCrossentropy$1,
        mse: mse$1,
        MSE: MSE$1,
        mae: mae$1,
        MAE: MAE$1,
        mape: mape$1,
        MAPE: MAPE$1,
        cosine: cosine$1
      };

    function get$1(e) {
      if ("string" == typeof e && e in metricsMap) return metricsMap[e];
      if ("string" != typeof e && null != e) return e;
      throw new ValueError("Unknown metric " + e);
    }

    function getLossOrMetricName(e) {
      if (assert(null !== e, "Unknown LossOrMetricFn " + e), "string" == typeof e) return e;

      for (var t = void 0, n = 0, r = Object.keys(lossesMap); n < r.length; n++) {
        var i = r[n];

        if (lossesMap[i] === e) {
          t = i;
          break;
        }
      }

      if (void 0 !== t) return t;

      for (var a = 0, o = Object.keys(metricsMap); a < o.length; a++) {
        i = o[a];

        if (metricsMap[i] === e) {
          t = i;
          break;
        }
      }

      return void 0 !== t ? t : e.name;
    }

    function getOptimizer(e) {
      var t = {
        Adagrad: function () {
          return _tfjsCore.train.adagrad(.01);
        },
        Adadelta: function () {
          return _tfjsCore.train.adadelta(1, .95, epsilon());
        },
        Adam: function () {
          return _tfjsCore.train.adam(.001, .9, .999, epsilon());
        },
        Adamax: function () {
          return _tfjsCore.train.adamax(.002, .9, .999, epsilon(), 0);
        },
        RMSProp: function () {
          return _tfjsCore.train.rmsprop(.001, .9, 0, epsilon());
        },
        SGD: function () {
          return _tfjsCore.train.sgd(.01);
        }
      };
      if (t.adagrad = t.Adagrad, t.adadelta = t.Adadelta, t.adam = t.Adam, t.adamax = t.Adamax, t.rmsprop = t.RMSProp, t.sgd = t.SGD, e in t) return t[e]();
      throw new ValueError("Unknown Optimizer " + e);
    }

    var MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH = 1048576;

    function checkUserDefinedMetadata(e, t, n) {
      if (void 0 === n && (n = !1), null == e || "object" != typeof e || Object.getPrototypeOf(e) !== Object.prototype || !plainObjectCheck(e)) throw new Error("User-defined metadata is expected to be a JSON object, but is not.");

      if (n) {
        var r = JSON.stringify(e);
        r.length > MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH && console.warn('User-defined metadata of model "' + t + '" is too large in size (length=' + r.length + " when serialized). It is not recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= " + MAX_USER_DEFINED_METADATA_SERIALIZED_LENGTH + ".");
      }
    }

    function plainObjectCheck(e) {
      if (null === e) return !0;

      if ("object" == typeof e) {
        if (Object.getPrototypeOf(e) === Object.prototype) {
          for (var t = 0, n = Object.keys(e); t < n.length; t++) {
            var r = n[t];
            if ("string" != typeof r) return !1;
            if (!plainObjectCheck(e[r])) return !1;
          }

          return !0;
        }

        if (Array.isArray(e)) {
          for (var i = 0, a = e; i < a.length; i++) {
            if (!plainObjectCheck(a[i])) return !1;
          }

          return !0;
        }

        return !1;
      }

      var o = typeof e;
      return "string" === o || "number" === o || "boolean" === o;
    }

    function printSummary(e, t, n, r) {
      void 0 === r && (r = console.log);
      var i,
        a = isModelSequentialLike(e),
        o = ["Layer (type)", "Output shape", "Param #"];
      if (a ? (t = t || 65, n = n || [.45, .85, 1]) : (t = t || 98, n = n || [.33, .55, .67, 1]), n[n.length - 1] <= 1 && (n = n.map(function (e) {
        return Math.floor(t * e);
      })), !a) for (var s in o.push("Receives inputs"), i = [], e.nodesByDepth) i.push.apply(i, e.nodesByDepth[s]);
      r("_".repeat(t)), printRow(o, n, r), r("=".repeat(t));

      for (var l = e.layers, u = 0; u < l.length; ++u) a ? printLayerSummary(l[u], n, r) : printLayerSummaryWithConnections(l[u], n, i, r), r((u === l.length - 1 ? "=" : "_").repeat(t));

      e.checkTrainableWeightsConsistency();
      var c = countTrainableParams(e),
        p = countParamsInWeights(e.nonTrainableWeights);
      r("Total params: " + (c + p)), r("Trainable params: " + c), r("Non-trainable params: " + p), r("_".repeat(t));
    }

    function countTrainableParams(e) {
      return null != e.collectedTrainableWeights ? countParamsInWeights(e.collectedTrainableWeights) : countParamsInWeights(e.trainableWeights);
    }

    function isModelSequentialLike(e) {
      var t = !0,
        n = [],
        r = [];

      for (var i in e.nodesByDepth) n.push(e.nodesByDepth[i]);

      for (var a = 0, o = n; a < o.length; a++) {
        var s = o[a];

        if (s.length > 1 || 1 === s.length && s[0].inboundLayers.length > 1) {
          t = !1;
          break;
        }

        r.push.apply(r, s);
      }

      if (t) for (var l = 0, u = e.layers; l < u.length; l++) {
        for (var c = !1, p = 0, h = u[l].inboundNodes; p < h.length; p++) {
          var d = h[p];

          if (-1 !== r.indexOf(d)) {
            if (c) {
              t = !1;
              break;
            }

            c = !0;
          }
        }

        if (!t) break;
      }
      return t;
    }

    function printRow(e, t, n) {
      void 0 === n && (n = console.log);

      for (var r = "", i = 0; i < e.length; ++i) i > 0 && (r = r.slice(0, r.length - 1) + " "), r = (r += e[i]).slice(0, t[i]), r += " ".repeat(t[i] - r.length);

      n(r);
    }

    function printLayerSummary(e, t, n) {
      var r;

      try {
        r = JSON.stringify(e.outputShape);
      } catch (e) {
        r = "multiple";
      }

      printRow([e.name + " (" + e.getClassName() + ")", r, e.countParams().toString()], t, n);
    }

    function printLayerSummaryWithConnections(e, t, n, r) {
      var i;

      try {
        i = JSON.stringify(e.outputShape);
      } catch (e) {
        i = "multiple";
      }

      for (var a = [], o = 0, s = e.inboundNodes; o < s.length; o++) {
        var l = s[o];
        if (!(null != n && n.length > 0 && -1 === n.indexOf(l))) for (var u = 0; u < l.inboundLayers.length; ++u) {
          var c = l.inboundLayers[u].name,
            p = l.nodeIndices[u],
            h = l.tensorIndices[u];
          a.push(c + "[" + p + "][" + h + "]");
        }
      }

      var d = e.name,
        f = e.getClassName(),
        g = 0 === a.length ? "" : a[0];
      printRow([d + " (" + f + ")", i, e.countParams().toString(), g], t, r);

      for (u = 1; u < a.length; ++u) printRow(["", "", "", a[u]], t, r);
    }

    function isArrayItemInputOrOutputName(e, t, n) {
      return ("inboundNodes" === e || "outputLayers" === e || "inputLayers" === e) && 0 === t && "string" == typeof n;
    }

    function convertPythonicToTs(e, t) {
      if (null === e) return null;
      if ("string" == typeof e) return toCamelCase(e);
      if ("number" == typeof e || "boolean" == typeof e) return e;

      if (e instanceof Array) {
        for (var n = [], r = e.length, i = 0; i < r; ++i) {
          var a = e[i];
          isArrayItemInputOrOutputName(t, i, a) ? n.push(a) : n.push(convertPythonicToTs(a, t));
        }

        return n;
      }

      for (var o = {}, s = 0, l = Object.keys(e); s < l.length; s++) {
        var u = l[s],
          c = e[u];
        if ("name" === u && "string" == typeof c) o[u] = c; else {
          var p = toCamelCase(u);
          o[p] = convertPythonicToTs(c, p);
        }
      }

      return o;
    }

    function convertTsToPythonic(e, t) {
      if (null === e || void 0 === e) return null;
      if ("string" == typeof e) return toSnakeCase(e);
      if ("number" == typeof e || "boolean" == typeof e) return e;

      if (e instanceof Array) {
        for (var n = [], r = e.length, i = 0; i < r; ++i) {
          var a = e[i];
          isArrayItemInputOrOutputName(t, i, a) ? n.push(a) : n.push(convertTsToPythonic(a, t));
        }

        return n;
      }

      for (var o = {}, s = 0, l = Object.keys(e); s < l.length; s++) {
        var u = l[s],
          c = e[u],
          p = toSnakeCase(u);
        o[p] = "name" !== u && "className" !== u || "string" != typeof c ? convertTsToPythonic(c, u) : c;
      }

      return o;
    }

    var version = "1.3.1";
    exports.version_layers = version;

    function assertFeedCompatibility(e, t) {
      if (null == e.dtype || e.dtype === t.dtype) return t;

      try {
        return (0, _tfjsCore.cast)(t, e.dtype);
      } catch (n) {
        throw new ValueError("The dtype of the feed (" + t.dtype + ") can not be cast to the dtype of the key '" + e.name + "' (" + e.dtype + ").");
      }
    }

    var FeedDict = function () {
      function e(t) {
        if (this.id2Value = {}, this.id2Mask = {}, this.name2Id = {}, t instanceof e) for (var n in t.id2Value) this.id2Value[n] = t.id2Value[n], n in t.id2Mask && (this.id2Mask[n] = t.id2Mask[n]); else {
          if (null == t) return;

          for (var r = 0, i = t; r < i.length; r++) {
            var a = i[r];
            this.add(a.key, a.value);
          }
        }
      }

      return e.prototype.add = function (e, t, n) {
        if (null != this.id2Value[e.id]) throw new ValueError("Duplicate key: name=" + e.name + ", id=" + e.id);
        return this.id2Value[e.id] = assertFeedCompatibility(e, t), this.name2Id[e.name] = e.id, null != n && (this.id2Mask[e.id] = n), this;
      }, e.prototype.addFeed = function (e) {
        this.add(e.key, e.value);
      }, e.prototype.hasKey = function (e) {
        return null != this.id2Value[e.id];
      }, e.prototype.names = function () {
        return Object.keys(this.name2Id);
      }, e.prototype.getValue = function (e) {
        if (e instanceof SymbolicTensor) {
          if (null == this.id2Value[e.id]) throw new ValueError("Nonexistent key: " + e.name);
          return this.id2Value[e.id];
        }

        var t = this.name2Id[e];
        if (null == t) throw new ValueError("Feed dict has no SymbolicTensor name: " + e);
        return this.id2Value[t];
      }, e.prototype.getMask = function (e) {
        if (e instanceof SymbolicTensor) {
          if (null == this.id2Value[e.id]) throw new ValueError("Nonexistent key: " + e.name);
          return this.id2Mask[e.id];
        }

        var t = this.name2Id[e];
        if (null == t) throw new ValueError("Feed dict has no SymbolicTensor name: " + e);
        return this.id2Mask[t];
      }, e.prototype.disposeMasks = function () {
        null != this.id2Mask && (0, _tfjsCore.dispose)(this.id2Mask);
      }, e;
    }(),
      cachedSorted = {},
      cachedRecipientCounts = {};

    function execute(e, t, n, r) {
      for (var i = null != n && n.training, a = Array.isArray(e), o = a ? e : [e], s = o.map(function (e) {
        return e.name;
      }), l = [], u = t.names(), c = 0, p = s; c < p.length; c++) {
        var h = p[c];
        -1 !== u.indexOf(h) ? l.push(t.getValue(h)) : l.push(null);
      }

      null != r && (r.maxNumTensors = -1 / 0, r.minNumTensors = 1 / 0);
      var d,
        f,
        g = s.join(",") + "|" + t.names().join(",");

      if (null == cachedSorted[g]) {
        var m = getTopologicalSortAndRecipientCounts(o, t);
        d = m.sorted, f = m.recipientCounts, cachedSorted[g] = d, cachedRecipientCounts[g] = f;
      }

      d = cachedSorted[g], f = {}, i || Object.assign(f, cachedRecipientCounts[g]);

      for (var y = new FeedDict(t), v = 0; v < d.length; ++v) {
        if (null != r) {
          var b = (0, _tfjsCore.memory)().numTensors;
          b > r.maxNumTensors && (r.maxNumTensors = b), b < r.minNumTensors && (r.minNumTensors = b);
        }

        var w = d[v],
          z = w.sourceLayer;

        if (!(z instanceof InputLayer)) {
          for (var S = [], A = [], _ = [], I = !1, C = 0, E = w.inputs; C < E.length; C++) {
            var N = E[C],
              k = y.getValue(N),
              x = y.getMask(N);
            S.push(k), A.push(x), null != x && (I = !0), i || (f[N.name]--, 0 !== f[N.name] || t.hasKey(N) || -1 !== s.indexOf(N.name) || k.isDisposed || !0 === N.sourceLayer.stateful || _.push(k));
          }

          I && ((n = n || {}).mask = A[0]);
          var L = toList(z.apply(S, n)),
            T = null;
          z.supportsMasking && (T = z.computeMask(S, A));

          for (var D = getNodeOutputs(w), O = Array.isArray(D) ? D : [D], R = 0; R < O.length; ++R) {
            y.hasKey(O[R]) || y.add(O[R], L[R], Array.isArray(T) ? T[0] : T);
            var M = s.indexOf(O[R].name);
            -1 !== M && (l[M] = L[R]);
          }

          i || (0, _tfjsCore.dispose)(_);
        }
      }

      return y.disposeMasks(), a ? l : l[0];
    }

    function getTopologicalSortAndRecipientCounts(e, t) {
      _tfjsCore.util.assert(null != e && e.length > 0, function () {
        return "Expected at least one fetch, got none";
      });

      var n = [],
        r = {};

      if (1 === e.length) {
        var i = getTopologicalSortAndRecipientCountsForOneFetch(e[0], t);
        n = i.sorted, r = i.recipientMap;
      } else for (var a = new Set(), o = 0, s = e; o < s.length; o++) {
        for (var l = getTopologicalSortAndRecipientCountsForOneFetch(s[o], t), u = l.sorted, c = l.recipientMap, p = 0, h = u; p < h.length; p++) {
          var d = h[p];
          a.has(d.name) || (n.push(d), a.add(d.name));
        }

        var f = function (e) {
          null == r[e] && (r[e] = new Set()), c[e].forEach(function (t) {
            return r[e].add(t);
          });
        };

        for (var g in c) f(g);
      }

      return {
        sorted: n,
        recipientCounts: recipientMap2Counts(r)
      };
    }

    function recipientMap2Counts(e) {
      var t = {};

      for (var n in e) t[n] = e[n].size;

      return t;
    }

    function getTopologicalSortAndRecipientCountsForOneFetch(e, t) {
      for (var n = new Set(), r = [], i = {}, a = 0, o = t.names(); a < o.length; a++) {
        var s = o[a];
        n.add(s);
      }

      var l = [],
        u = [];

      for (l.push(e); l.length > 0;) {
        var c = l[l.length - 1];
        if (n.has(c.name)) l.pop(); else {
          var p = u[u.length - 1] === l.length - 1;
          if (0 === c.inputs.length || p) l.pop(), r.push(c), n.add(c.name), p && u.pop(); else {
            u.push(l.length - 1);

            for (var h = 0, d = c.inputs; h < d.length; h++) {
              var f = d[h];
              null == i[f.name] && (i[f.name] = new Set()), i[f.name].add(c.name), n.has(f.name) || l.push(f);
            }
          }
        }
      }

      return {
        sorted: r,
        recipientMap: i
      };
    }

    function getNodeOutputs(e) {
      var t;
      if (1 === e.sourceLayer.inboundNodes.length) t = e.sourceLayer.output; else {
        for (var n = null, r = 0; r < e.sourceLayer.inboundNodes.length; ++r) for (var i = 0, a = e.sourceLayer.inboundNodes[r].outputTensors; i < a.length; i++) {
          if (a[i].id === e.id) {
            n = r;
            break;
          }
        }

        t = e.sourceLayer.getOutputAt(n);
      }
      return t;
    }

    var Container = function (e) {
      function t(n) {
        var r = e.call(this, {}) || this;

        if (r.containerNodes = new Set(), r.name = n.name, null == r.name) {
          var i = r.getClassName().toLowerCase();
          r.name = getUid(i);
        }

        if (r.supportsMasking = !1, r.trainable_ = !0, Array.isArray(n.inputs) ? r.inputs = n.inputs.slice() : r.inputs = [n.inputs], Array.isArray(n.outputs) ? r.outputs = n.outputs.slice() : r.outputs = [n.outputs], unique(r.inputs).length !== r.inputs.length) throw new ValueError("The list of inputs passed to the model is redundant. All inputs should only appear once. Found: " + r.inputs.map(function (e) {
          return e.name;
        }));
        unique(r.outputs).length !== r.outputs.length && console.warn("The list of outputs passed to the model is redundant. All outputs should only appear once. Found: " + r.outputs.map(function (e) {
          return e.name;
        })), r.inputLayers = [], r.inputLayersNodeIndices = [], r.inputLayersTensorIndices = [], r.outputLayers = [], r.outputLayersNodeIndices = [], r.outputLayersTensorIndices = [], r.layers = [], r.internalContainerRefs = [];

        for (var a = 0, o = r.outputs; a < o.length; a++) {
          var s = (C = o[a]).sourceLayer,
            l = C.nodeIndex,
            u = C.tensorIndex;
          r.outputLayers.push(s), r.outputLayersNodeIndices.push(l), r.outputLayersTensorIndices.push(u);
        }

        for (var c = 0, p = r.inputs; c < p.length; c++) {
          s = (C = p[c]).sourceLayer, l = C.nodeIndex, u = C.tensorIndex;
          assert(0 === l, "input layer has >1 nodes"), assert(0 === u, "input layer has >1 tensors"), r.inputLayers.push(s), r.inputLayersNodeIndices.push(l), r.inputLayersTensorIndices.push(u);
        }

        r.inputNames = [], r.outputNames = [], r.feedInputShapes = [], r.feedInputNames = [], r.feedOutputNames = [];

        for (var h = 0; h < r.inputLayers.length; h++) {
          if (!((s = r.inputLayers[h]) instanceof InputLayer)) throw new TypeError("Input layers to a LayersModel must be InputLayer objects. Received inputs: " + n.inputs + ". Input " + h + " (0-based) originates from layer type " + s.getClassName() + ".");
          r.inputNames.push(s.name), r.feedInputShapes.push(s.batchInputShape), r.feedInputNames.push(s.name);
        }

        for (var d = 0, f = r.outputLayers; d < f.length; d++) {
          s = f[d];
          r.outputNames.push(s.name);
        }

        r.internalInputShapes = r.inputs.map(function (e) {
          return e.shape;
        }), r.internalOutputShapes = r.outputs.map(function (e) {
          return e.shape;
        });

        for (var g = {}, m = {}, y = {}, v = {}, b = {}, w = [], z = function (e, n, i, a, o, s) {
          null != a && null != o && null != s || (a = e.sourceLayer, o = e.nodeIndex, s = e.tensorIndex);
          var l = a.inboundNodes[o];
          if (-1 !== i.indexOf(l)) throw new RuntimeError("The tensor " + e.name + ' at layer "' + a.name + '" is part of a cycle.');

          if (-1 === n.indexOf(l)) {
            r.containerNodes.add(t.nodeKey(a, o)), (a.id in b) || (b[a.id] = Object.keys(b).length), -1 === i.indexOf(l) && i.push(l);

            for (var u = l.inboundLayers.length, c = 0; c < u; c++) {
              var p = l.inputTensors[c],
                h = l.inboundLayers[c],
                d = l.nodeIndices[c],
                f = l.tensorIndices[c];
              z(p, n, i, h, d, f);
            }

            for (n.push(l); i.indexOf(l) >= 0;) i.splice(i.indexOf(l), 1);

            w.push(l);
          }
        }, S = [], A = [], _ = 0, I = r.outputs; _ < I.length; _++) {
          var C = I[_];
          z(C, S, A);
        }

        for (var E = 0, N = w.slice().reverse(); E < N.length; E++) {
          m[(K = N[E]).id] = K, K.id in g || (g[K.id] = 0);
          var k = g[K.id],
            x = null == y[K.outboundLayer.id] ? 0 : y[K.outboundLayer.id];
          k = Math.max(k, x), y[K.outboundLayer.id] = k, v[K.outboundLayer.id] = K.outboundLayer, g[K.id] = k;

          for (h = 0; h < K.inboundLayers.length; h++) {
            var L = K.inboundLayers[h],
              T = (l = K.nodeIndices[h], L.inboundNodes[l]),
              D = null == g[T.id] ? 0 : g[T.id];
            g[T.id] = Math.max(k + 1, D), m[T.id] = T;
          }
        }

        var O = {};

        for (var R in g) {
          (k = g[R]) in O || (O[k] = []), O[k].push(m[R]);
        }

        var M = {};

        for (var P in y) {
          (k = y[P]) in M || (M[k] = []), M[k].push(v[P]);
        }

        var F = Object.keys(M).map(function (e) {
          return parseInt(e, 10);
        }).sort(reverseNumberCompare);
        r.layers = [];

        for (var V = 0, B = F; V < B.length; V++) {
          var U = M[k = B[V]];
          U.sort(function (e, t) {
            var n = b[e.id],
              r = b[t.id];
            return n < r ? -1 : n > r ? 1 : 0;
          });

          for (var j = 0, W = U; j < W.length; j++) {
            (s = W[j]) instanceof t && r.internalContainerRefs.push(s), r.layers.push(s);
          }
        }

        r.layersByDepth = M, F = Object.keys(O).map(function (e) {
          return parseInt(e, 10);
        }).sort(reverseNumberCompare);

        for (var $ = r.inputs.slice(), q = [], G = 0, H = F; G < H.length; G++) for (var J = 0, Z = O[k = H[G]]; J < Z.length; J++) {
          var K;

          if (null != (s = (K = Z[J]).outboundLayer)) {
            for (var Y = 0, X = K.inputTensors; Y < X.length; Y++) {
              C = X[Y];
              if (-1 === $.indexOf(C)) throw new RuntimeError("Graph disconnected: cannot obtain value for tensor " + C + ' at layer "' + s.name + '". The following previous layers were accessed without issue: ' + q);
            }

            for (var Q = 0, ee = K.outputTensors; Q < ee.length; Q++) {
              C = ee[Q];
              $.push(C);
            }

            q.push(s.name);
          }
        }

        r.nodesByDepth = O;

        for (var te = r.layers.map(function (e) {
          return e.name;
        }), ne = function (e) {
          var t = te.filter(function (t) {
            return t === e;
          }).length;
          if (1 !== t) throw new RuntimeError('The name "' + e + '" is used ' + t + " times in the model. All layer names should be unique. Layer names: " + JSON.stringify(te));
        }, re = 0, ie = te; re < ie.length; re++) {
          ne(ie[re]);
        }

        return r.outboundNodes = [], r.inboundNodes = [], new Node({
          outboundLayer: r,
          inboundLayers: [],
          nodeIndices: [],
          tensorIndices: [],
          inputTensors: r.inputs,
          outputTensors: r.outputs,
          inputMasks: r.inputs.map(function (e) {
            return null;
          }),
          outputMasks: r.outputs.map(function (e) {
            return null;
          }),
          inputShapes: r.inputs.map(function (e) {
            return e.shape;
          }),
          outputShapes: r.outputs.map(function (e) {
            return e.shape;
          })
        }), r.built = !0, r._refCount = 1, r;
      }

      return __extends(t, e), t.prototype.assertNotDisposed = function () {
        if (0 === this._refCount) throw new Error("Container '" + this.name + "' is already disposed.");
      }, t.prototype.dispose = function () {
        this.assertNotDisposed();
        var e = {
          refCountAfterDispose: null,
          numDisposedVariables: 0
        };

        if (0 == --this._refCount) {
          for (var t = 0, n = this.layers; t < n.length; t++) {
            var r = n[t];
            e.numDisposedVariables += r.dispose().numDisposedVariables;
          }

          for (var i = 0, a = this.internalContainerRefs; i < a.length; i++) {
            var o = a[i];
            e.numDisposedVariables += o.dispose().numDisposedVariables;
          }
        }

        return e.refCountAfterDispose = this._refCount, e;
      }, Object.defineProperty(t.prototype, "trainable", {
        get: function () {
          return this.trainable_;
        },
        set: function (e) {
          this.layers.forEach(function (t) {
            t._trainableWeights.forEach(function (t) {
              return t.trainable = e;
            });
          }), this.trainable_ = e;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "trainableWeights", {
        get: function () {
          if (this._trainableWeights.length > 0) throw new 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; t < n.length; t++) {
            var r = n[t];
            e = e.concat(r.trainableWeights);
          }

          return e;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
        get: function () {
          for (var e = [], t = 0, n = this.layers; t < n.length; t++) {
            var r = n[t];
            e.push.apply(e, r.nonTrainableWeights);
          }

          if (!this.trainable) {
            for (var i = [], a = 0, o = this.layers; a < o.length; a++) {
              r = o[a];
              i.push.apply(i, r.trainableWeights);
            }

            return i.concat(e);
          }

          return e;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "weights", {
        get: function () {
          return this.trainableWeights.concat(this.nonTrainableWeights);
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.loadWeights = function (e, t) {
        void 0 === t && (t = !0);

        for (var n = {}, r = 0, i = 0, a = this.layers; i < a.length; i++) for (var o = 0, s = a[i].weights; o < s.length; o++) {
          var l = s[o];
          if (null != n[l.originalName]) throw new ValueError("Duplicate weight name: " + l.originalName);
          n[l.originalName] = l, r++;
        }

        var u = [];

        for (var c in e) {
          if (null != n[c]) u.push([n[c], e[c]]); else if (t) throw new ValueError("Provided weight data has no target variable: " + c);
          delete n[c];
        }

        if (t) {
          var p = [];

          for (var h in n) p.push(h);

          if (p.length > 0) throw new ValueError(p.length + " of " + r + " weights are not set: " + p);
        }

        batchSetValue(u);
      }, t.prototype.updatedConfig = function () {
        var e = this.getConfig(),
          t = {};
        return t.className = this.getClassName(), t.config = e, t.kerasVersion = "tfjs-layers " + version, t.backend = "TensorFlow.js", t;
      }, t.prototype.toJSON = function (e, t) {
        void 0 === t && (t = !0);
        var n = convertTsToPythonic(this.updatedConfig());
        return t ? JSON.stringify(n) : n;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          e = toList(e);

          for (var r = new FeedDict(), i = 0; i < n.inputs.length; ++i) r.add(n.inputs[i], e[i]);

          return execute(n.outputs, r, t);
        });
      }, t.prototype.computeMask = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var r;
          return e = toList(e), r = null == t ? pyListRepeat(null, e.length) : toList(t), n.runInternalGraph(e, r)[1];
        });
      }, t.prototype.computeOutputShape = function (e) {
        var t = normalizeShapeList(e);
        if (t.length !== this.inputLayers.length) throw new ValueError("Invalid inputShape argument " + e + ": model has " + this.inputLayers.length + " tensor inputs.");

        for (var n = {}, r = 0; r < t.length; r++) {
          var i = this.inputLayers[r],
            a = t[r];
          n[A = i.name + "_0_0"] = a;
        }

        var o = Object.keys(this.nodesByDepth).map(function (e) {
          return parseInt(e, 10);
        }).sort(reverseNumberCompare);
        if (o.length > 1) for (var s = 0, l = o; s < l.length; s++) for (var u = l[s], c = 0, p = this.nodesByDepth[u]; c < p.length; c++) {
          var h = p[c];
          i = h.outboundLayer;

          if (-1 === this.inputLayers.map(function (e) {
            return e.id;
          }).indexOf(i.id)) {
            for (var d = [], f = 0; f < h.inboundLayers.length; f++) {
              var g = h.inboundLayers[f],
                m = h.nodeIndices[f],
                y = h.tensorIndices[f],
                v = n[A = g.name + "_" + m + "_" + y];
              d.push(v);
            }

            var b = normalizeShapeList(i.computeOutputShape(singletonOrArray(d))),
              w = i.inboundNodes.indexOf(h);

            for (f = 0; f < b.length; f++) {
              n[A = i.name + "_" + w + "_" + f] = b[f];
            }
          }
        }
        var z = [],
          S = [];

        for (r = 0; r < this.outputLayers.length; r++) {
          i = this.outputLayers[r], w = this.outputLayersNodeIndices[r], y = this.outputLayersTensorIndices[r];
          var A = i.name + "_" + w + "_" + y;
          S.push(A);
        }

        for (r = 0; r < S.length; r++) {
          var _ = S[r];
          assert(_ in n), z.push(n[_]);
        }

        return singletonOrArray(z);
      }, t.prototype.runInternalGraph = function (e, t) {
        null == t && (t = pyListRepeat(null, e.length));

        for (var n = {}, r = 0; r < this.inputs.length; ++r) {
          var i = this.inputs[r],
            a = e[r],
            o = t[r];
          n[i.id] = [a, o];
        }

        for (var s = 0, l = Object.keys(this.nodesByDepth).map(function (e) {
          return parseInt(e, 10);
        }).sort(reverseNumberCompare); s < l.length; s++) for (var u = l[s], c = 0, p = this.nodesByDepth[u]; c < p.length; c++) {
          for (var h = p[c], d = h.outboundLayer, f = h.inputTensors, g = h.outputTensors, m = new Array(), y = 0, v = f; y < v.length; y++) {
            (i = v[y]).id in n && m.push(n[i.id]);
          }

          if (m.length === f.length) {
            var b = {},
              w = void 0,
              z = void 0,
              S = void 0,
              A = void 0;

            if (null != h.callArgs && (b = h.callArgs), 1 === m.length) {
              var _ = m[0],
                I = _[0],
                C = _[1];
              null == b.mask && (b.mask = C), S = toList(d.call(I, b)), A = toList(d.computeMask(I, C)), w = [I], z = [C];
            } else w = m.map(function (e) {
              return e[0];
            }), z = m.map(function (e) {
              return e[1];
            }), null == b.mask && (b.mask = z), S = toList(d.call(w, b)), A = toList(d.computeMask(w, z));

            if (d.activityRegularizer) throw new NotImplementedError("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet.");

            for (r = 0; r < g.length; ++r) {
              i = g[r], a = S[r], o = A[r];
              n[i.id] = [a, o];
            }
          }
        }

        for (var E = [], N = [], k = [], x = 0, L = this.outputs; x < L.length; x++) {
          assert((i = L[x]).id in n, "Could not compute output " + i.name + " : " + i.id);
          var T = n[i.id],
            D = T[0];
          o = T[1];
          k.push(D.shape), E.push(D), N.push(o);
        }

        return [E, N, k];
      }, t.prototype.buildNodeConversionMap = function (e) {
        for (var n, r = {}, i = 0, a = this.layers; i < a.length; i++) {
          var o = a[i];
          n = o instanceof t ? 1 : 0;

          for (var s = 0; s < o.inboundNodes.length; s++) {
            var l = t.nodeKey(o, s);
            this.containerNodes.has(l) && (r[l] = n, n += 1);
          }
        }

        return r;
      }, t.prototype.getLayer = function (e, t) {
        if (null != t) {
          if (this.layers.length <= t) throw new ValueError("Was asked to retrieve layer at index " + t + ", but model only has " + this.layers.length + " layer(s).");
          return this.layers[t];
        }

        if (null == e) throw new ValueError("Provide either a layer name or layer index");

        for (var n = 0, r = this.layers; n < r.length; n++) {
          var i = r[n];
          if (i.name === e) return i;
        }

        throw new ValueError("No such layer: " + e);
      }, t.prototype.calculateLosses = function () {
        var e = this;
        return (0, _tfjsCore.tidy)(function () {
          for (var n = [], r = 0, i = e.layers; r < i.length; r++) for (var a = i[r], o = 0; o < a.inboundNodes.length; ++o) {
            var s = t.nodeKey(a, o);
            e.containerNodes.has(s) && n.push.apply(n, a.calculateLosses());
          }

          return n;
        });
      }, t.prototype.getConfig = function () {
        for (var e = {
          name: this.name
        }, n = this.buildNodeConversionMap(this.layers), r = [], i = 0, a = this.layers; i < a.length; i++) {
          for (var o = (w = a[i]).getClassName(), s = w.getConfig(), l = [], u = 0; u < w.inboundNodes.length; u++) {
            var c = w.inboundNodes[u],
              p = t.nodeKey(w, u),
              h = {};

            if (this.containerNodes.has(p)) {
              if (c.callArgs) try {
                JSON.stringify(c.callArgs), h = c.callArgs;
              } catch (e) {
                console.warn("Layer " + w.name + " was passed non-serializable keyword arguments: " + c.callArgs + ". They will not be included in the serialized model (and thus will be missing at deserialization time)."), h = {};
              }

              if (c.inboundLayers.length > 0) {
                for (var d = [], f = 0; f < c.inboundLayers.length; f++) {
                  var g = c.inboundLayers[f],
                    m = c.nodeIndices[f],
                    y = c.tensorIndices[f];
                  null == (S = n[t.nodeKey(g, m)]) && (S = 0), d.push([g.name, S, y, h]);
                }

                l.push(d);
              }
            }
          }

          var v = {};
          v.name = w.name, v.className = o, v.config = s, v.inboundNodes = l, r.push(v);
        }

        e.layers = r;
        var b = [];

        for (f = 0; f < this.inputLayers.length; f++) {
          var w = this.inputLayers[f];
          m = this.inputLayersNodeIndices[f], p = t.nodeKey(w, m);

          if (this.containerNodes.has(p)) {
            null !== (S = n[p]) && void 0 !== S || (S = 0);
            y = this.inputLayersTensorIndices[f];
            b.push([w.name, S, y]);
          }
        }

        e.inputLayers = b;
        var z = [];

        for (f = 0; f < this.outputLayers.length; f++) {
          w = this.outputLayers[f], m = this.outputLayersNodeIndices[f], p = t.nodeKey(w, m);

          if (this.containerNodes.has(p)) {
            var S;
            null !== (S = n[p]) && void 0 !== S || (S = 0);
            y = this.outputLayersTensorIndices[f];
            z.push([w.name, S, y]);
          }
        }

        return e.outputLayers = z, e;
      }, t.fromConfig = function (e, t, n, r) {
        void 0 === n && (n = {}), void 0 === r && (r = !1);
        var i = {},
          a = {};

        function o(e, t) {
          e.name in a ? a[e.name].push(t) : a[e.name] = [t];
        }

        function s(e, t) {
          for (var n, r = [], a = 0, s = t; a < s.length; a++) {
            var l = s[a],
              u = l[0],
              c = l[1],
              p = l[2];
            if (n = null == l[3] ? {} : l[3], !(u in i)) return void o(e, t);
            var h = i[u];
            if (h.inboundNodes.length <= c) return void o(e, t);
            var d = h.inboundNodes[c];
            r.push(d.outputTensors[p]);
          }

          r.length > 0 && e.apply(singletonOrArray(r), n);
        }

        function l(e) {
          var n = e.name,
            a = deserialize(e, null != t.customObjects ? t.customObjects : {});
          a.setFastWeightInitDuringBuild(r), i[n] = a, e.inboundNodes.forEach(function (e) {
            if (!(e instanceof Array)) throw new ValueError("Corrupted configuration, expected array for nodeData: " + e);
            o(a, e);
          });
        }

        for (var u = t.name, c = t.layers, p = 0, h = c; p < h.length; p++) {
          l(g = h[p]);
        }

        for (; !isObjectEmpty(a);) for (var d = 0, f = c; d < f.length; d++) {
          var g = f[d];

          if ((k = i[g.name]).name in a) {
            var m = a[k.name];
            delete a[k.name];

            for (var y = 0, v = m; y < v.length; y++) {
              s(k, v[y]);
            }
          }
        }

        for (var b = [], w = [], z = 0, S = t.inputLayers; z < S.length; z++) {
          var A = (g = S[z])[0],
            _ = g[1],
            I = g[2];
          assert(A in i);
          var C = (k = i[A]).inboundNodes[_].outputTensors;
          b.push(C[I]);
        }

        for (var E = 0, N = t.outputLayers; E < N.length; E++) {
          A = (g = N[E])[0], _ = g[1], I = g[2];
          assert(A in i);
          var k;
          C = (k = i[A]).inboundNodes[_].outputTensors;
          w.push(C[I]);
        }

        return new e({
          inputs: b,
          outputs: w,
          name: u
        });
      }, Object.defineProperty(t.prototype, "stateful", {
        get: function () {
          if (this._stateful) throw new ValueError("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false.");

          for (var e = 0, t = this.layers; e < t.length; e++) {
            if (t[e].stateful) return !0;
          }

          return !1;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.resetStates = function () {
        var e = this;
        (0, _tfjsCore.tidy)(function () {
          e.layers.forEach(function (e) {
            e.stateful && e.resetStates();
          });
        });
      }, t;
    }(Layer);

    function standardizeSampleOrClassWeights(e, t, n) {
      var r = t.length;
      if (null == e || Array.isArray(e) && 0 === e.length) return t.map(function (e) {
        return null;
      });
      if (1 === r) return Array.isArray(e) && 1 === e.length ? e : "object" == typeof e && t[0] in e ? [e[t[0]]] : [e];

      if (Array.isArray(e)) {
        if (e.length !== r) throw new Error("Provided " + n + " is an array of " + e.length + " element(s), but the model has " + r + " outputs. Make sure a set of weights is provided for each model output.");
        return e;
      }

      if ("object" == typeof e && Object.keys(e).length > 0 && "object" == typeof e[Object.keys(e)[0]]) {
        var i = [];
        return t.forEach(function (t) {
          t in e ? i.push(e[t]) : i.push(null);
        }), i;
      }

      throw new Error("The model has multiple (" + r + ") outputs, so " + n + " must be either an array with " + r + " elements or an object with " + t + " keys. Provided " + n + " not understood: " + JSON.stringify(e));
    }

    function standardizeClassWeights(e, t) {
      return standardizeSampleOrClassWeights(e, t, "classWeight");
    }

    function standardizeWeights(e, t, n, r) {
      return __awaiter(this, void 0, void 0, function () {
        var i, a, o, s, l;
        return __generator(this, function (u) {
          switch (u.label) {
            case 0:
              if (null != t || null != r) throw new Error("Support sampleWeight is not implemented yet");
              return null == n ? [3, 2] : (i = (0, _tfjsCore.tidy)(function () {
                if (1 === e.shape.length) return e.clone();

                if (2 === e.shape.length) {
                  if (e.shape[1] > 1) {
                    return e.argMax(1);
                  }

                  if (1 === e.shape[1]) return e.reshape([e.shape[0]]);
                  throw new Error("Encountered unexpected last-dimension size (" + e.shape[1] + ") during handling of class weights. The size is expected to be >= 1.");
                }

                throw new Error("Unexpected rank of target (y) tensor (" + e.rank + ") during handling of class weights. The rank is expected to be 1 or 2.");
              }), s = (o = Array).from, [4, i.data()]);

            case 1:
              return a = s.apply(o, [u.sent()]), (0, _tfjsCore.dispose)(i), l = [], a.forEach(function (e) {
                if (null == n[e]) throw new Error("classWeight must contain all classes in the training data. The class " + e + " exists in the data but not in classWeight");
                l.push(n[e]);
              }), [2, (0, _tfjsCore.tensor1d)(l, "float32")];

            case 2:
              return [2, null];
          }
        });
      });
    }

    function computeWeightedLoss(e, t) {
      return (0, _tfjsCore.mul)(e, t);
    }

    var DEFAULT_VALIDATION_BATCH_SIZE = 32;

    function standardizeDataIteratorOutput(e, t) {
      var n,
        r,
        i = t;
      n = i.xs, r = i.ys, _tfjsCore.util.assert(null != n && null != r, function () {
        return "A Dataset iterator for fitDataset() is expected to generate objects of the form `{xs: xVal, ys: yVal}`, where the two values may be `tf.Tensor`, an array of Tensors, or a map of string to Tensor.  The provided Dataset instead generates " + t;
      });
      var a = flattenTensorOrArrayOrMap("input", e.inputNames, n),
        o = flattenTensorOrArrayOrMap("output", e.outputNames, r),
        s = a[0].shape[0];
      _tfjsCore.util.assert(a.length === e.inputs.length, function () {
        return "LayersModel has " + e.inputs.length + " inputs, but the dataset provides " + a.length + " inputs.  (Expected input keys: " + JSON.stringify(e.inputNames) + ")";
      }), _tfjsCore.util.assert(o.length === e.outputs.length, function () {
        return "LayersModel has " + e.outputs.length + " outputs, but the dataset provides " + o.length + " outputs.  (Expected output keys: " + JSON.stringify(e.outputNames) + ")";
      });

      var l = function (t) {
        _tfjsCore.util.assert(a[t].shape[0] === s, function () {
          return "Batch size mismatch: input " + e.inputNames[t] + " has " + a[t].shape[0] + "; expected  " + s + " based on input " + e.inputNames[0] + ".";
        });
      };

      for (var u in a) l(u);

      var c = function (t) {
        _tfjsCore.util.assert(o[t].shape[0] === s, function () {
          return "Batch size mismatch: output " + e.outputNames[t] + " has " + o[t].shape[0] + "; expected  " + s + " based on input " + e.inputNames[0] + ".";
        });
      };

      for (var p in o) c(p);

      return {
        xs: a,
        ys: o
      };
    }

    function flattenTensorOrArrayOrMap(e, t, n) {
      if (n instanceof _tfjsCore.Tensor) return [n];
      if (Array.isArray(n)) return _tfjsCore.util.assert(n.length === t.length, function () {
        return "Received an array of " + n.length + " Tensors, but expected " + t.length + " to match the " + e + " keys " + t + ".";
      }), n;

      for (var r = [], i = 0, a = t; i < a.length; i++) {
        var o = a[i];
        if (null == n[o]) throw new ValueError("The feature data generated by the dataset lacks the required " + e + " key '" + o + "'.");
        r.push(n[o]);
      }

      return r;
    }

    function standardizeTensorValidationData(e) {
      if (3 === e.length) throw new NotImplementedError("Validation with sample weights is not implemented yet.");
      return {
        xs: e[0],
        ys: e[1]
      };
    }

    function fitDataset(e, t, n) {
      return __awaiter(this, void 0, void 0, function () {
        var r, i, a, o, s, l, u, c, p, h, d, f, g, m, y, v, b, w, z, S, A, _, I, C, E, N, k, x, L, T, D, O, R, M;

        return __generator(this, function (P) {
          switch (P.label) {
            case 0:
              if (r = null != n.batchesPerEpoch, _tfjsCore.util.assert(null != e.optimizer, function () {
                return "You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig).";
              }), _tfjsCore.util.assert(null != n, function () {
                return "For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call.";
              }), _tfjsCore.util.assert(null != n.epochs && n.epochs > 0 && Number.isInteger(n.epochs), function () {
                return "For fitDataset(), config.epochs is expected to be a positive integer, but got " + n.epochs;
              }), _tfjsCore.util.assert(!r || n.batchesPerEpoch > 0 && Number.isInteger(n.batchesPerEpoch), function () {
                return "For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got " + n.batchesPerEpoch;
              }), _tfjsCore.util.assert(null == n.validationSplit, function () {
                return "`validationSplit` is not supported by `fitDataset()`. Use validationData instead.";
              }), e.isTraining) throw new Error("Cannot start training because another fit() call is ongoing.");
              e.isTraining = !0, P.label = 1;

            case 1:
              return P.trys.push([1, , 26, 27]), i = null != n.validationData, a = void 0, o = void 0, i && (isDatasetObject(n.validationData) ? _tfjsCore.util.assert(null == n.validationBatches || n.validationBatches > 0 && Number.isInteger(n.validationBatches), function () {
                return "For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got " + n.validationBatches;
              }) : (s = standardizeTensorValidationData(n.validationData), a = s.xs, o = s.ys)), l = e.makeTrainFunction(), u = e.getDedupedMetricsNames(), c = void 0, c = i ? u.slice().concat(u.map(function (e) {
                return "val_" + e;
              })) : u.slice(), p = standardizeCallbacks(n.callbacks, n.yieldEvery), h = null == n.verbose ? 1 : n.verbose, d = configureCallbacks(p, h, n.epochs, null, null, getStepsPerEpoch(t, n), null, i, c), f = d.callbackList, g = d.history, f.setModel(e), e.history = g, [4, f.onTrainBegin()];

            case 2:
              return P.sent(), e.stopTraining_ = !1, m = null == n.initialEpoch ? 0 : n.initialEpoch, [4, t.iterator()];

            case 3:
              y = P.sent(), P.label = 4;

            case 4:
              return m < n.epochs ? (v = {}, [4, f.onEpochBegin(m)]) : [3, 23];

            case 5:
              return P.sent(), b = 0, w = 0, r ? [3, 7] : [4, t.iterator()];

            case 6:
              y = P.sent(), P.label = 7;

            case 7:
              return !r || b < n.batchesPerEpoch ? [4, y.next()] : [3, 21];

            case 8:
              return z = P.sent(), r && z.done ? (console.warn("You provided `batchesPerEpoch` as " + n.batchesPerEpoch + ", but your dataset iterator ran out of data after " + b + " batches; interrupting training. Make sure that your dataset can generate at least `batchesPerEpoch * epochs` batches (in this case, " + n.batchesPerEpoch * n.epochs + " batches). You may need to use the repeat() function when building your dataset."), [3, 21]) : null == z.value ? [3, 15] : (S = standardizeDataIteratorOutput(e, z.value), A = S.xs, _ = S.ys, (I = {}).batch = w, I.size = A[0].shape[0], [4, f.onBatchBegin(w, I)]);

            case 9:
              if (P.sent(), C = [], null == n.classWeight) return [3, 13];
              E = standardizeClassWeights(n.classWeight, e.outputNames), M = 0, P.label = 10;

            case 10:
              return M < E.length ? (k = (N = C).push, [4, standardizeWeights(_[M], null, E[M])]) : [3, 13];

            case 11:
              k.apply(N, [P.sent()]), P.label = 12;

            case 12:
              return ++M, [3, 10];

            case 13:
              for (x = A.concat(_).concat(C), L = l(x), (0, _tfjsCore.dispose)(x), M = 0; M < u.length; ++M) T = u[M], D = L[M], I[T] = D, (0, _tfjsCore.keep)(D);

              return [4, f.onBatchEnd(w, I)];

            case 14:
              P.sent(), disposeTensorsInLogs(I), w++, b++, P.label = 15;

            case 15:
              return (r ? b >= n.batchesPerEpoch : z.done) ? i ? (O = void 0, isDatasetObject(n.validationData) ? (R = toList, [4, e.evaluateDataset(n.validationData, {
                batches: n.validationBatches
              })]) : [3, 17]) : [3, 19] : [3, 20];

            case 16:
              return O = R.apply(void 0, [P.sent()]), [3, 18];

            case 17:
              O = toList(e.evaluate(a, o, {
                batchSize: null == n.validationBatchSize ? DEFAULT_VALIDATION_BATCH_SIZE : n.validationBatchSize,
                verbose: 0
              })), P.label = 18;

            case 18:
              for (M = 0; M < e.metricsNames.length; ++M) v["val_" + e.metricsNames[M]] = O[M];

              P.label = 19;

            case 19:
              return [3, 21];

            case 20:
              return e.stopTraining_ ? [3, 21] : [3, 7];

            case 21:
              return [4, f.onEpochEnd(m, v)];

            case 22:
              return P.sent(), m++, e.stopTraining_ ? [3, 23] : [3, 4];

            case 23:
              return [4, f.onTrainEnd()];

            case 24:
              return P.sent(), [4, e.history.syncData()];

            case 25:
              return P.sent(), [2, e.history];

            case 26:
              return e.isTraining = !1, [7];

            case 27:
              return [2];
          }
        });
      });
    }

    function getStepsPerEpoch(e, t) {
      var n = null;
      return null != t.batchesPerEpoch ? n = t.batchesPerEpoch : Number.isFinite(e.size) && (n = e.size), n;
    }

    function isDatasetObject(e) {
      return "function" == typeof e.iterator;
    }

    function isLazyIteratorObject(e) {
      return "function" == typeof e.next;
    }

    function evaluateDataset(e, t, n) {
      return __awaiter(this, void 0, void 0, function () {
        var r, i, a, o, s, l, u, c, p, h;
        return __generator(this, function (d) {
          switch (d.label) {
            case 0:
              if (r = null != (n = n || {}).batches, i = e.testFunction, a = [], n.verbose > 0) throw new NotImplementedError("Verbose mode is not implemented yet.");
              return _tfjsCore.util.assert(!r || n.batches > 0 && Number.isInteger(n.batches), function () {
                return "Test loop expects `batches` to be a positive integer, but received " + JSON.stringify(n.batches);
              }), isLazyIteratorObject(t) ? (s = t, [3, 3]) : [3, 1];

            case 1:
              return [4, t.iterator()];

            case 2:
              s = d.sent(), d.label = 3;

            case 3:
              o = s, l = 0, u = 0, c = function () {
                var t;
                return __generator(this, function (s) {
                  switch (s.label) {
                    case 0:
                      return [4, o.next()];

                    case 1:
                      return t = s.sent(), a = (0, _tfjsCore.tidy)(function () {
                        if (t.value) {
                          var n = standardizeDataIteratorOutput(e, t.value),
                            r = n.xs,
                            o = n.ys,
                            s = r.concat(o),
                            c = (0, _tfjsCore.tidy)(function () {
                              return i(s);
                            });
                          if ((0, _tfjsCore.dispose)(s), 0 === u) for (var p = 0; p < c.length; ++p) a.push((0, _tfjsCore.scalar)(0));

                          var h = s[0].shape[0],
                            d = function (e) {
                              var t = c[e],
                                n = a[e];
                              a[e] = (0, _tfjsCore.tidy)(function () {
                                return (0, _tfjsCore.add)(a[e], (0, _tfjsCore.mul)(h, t));
                              }), u > 0 && (0, _tfjsCore.dispose)(n);
                            };

                          for (p = 0; p < c.length; ++p) d(p);

                          (0, _tfjsCore.dispose)(c), l += h, ++u;
                        }

                        return a;
                      }), t.done ? (r && console.warn("Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least `batches` batches (in this case, " + n.batches + " batches). You may need to use the repeat() function when building your dataset."), [2, "break"]) : [2];
                  }
                });
              }, d.label = 4;

            case 4:
              return !r || u < n.batches ? [5, c()] : [3, 6];

            case 5:
              return "break" === d.sent() ? [3, 6] : [3, 4];

            case 6:
              for (p = 0; p < a.length; ++p) h = a[p], a[p] = (0, _tfjsCore.div)(a[p], l), (0, _tfjsCore.dispose)(h);

              return [2, singletonOrArray(a)];
          }
        });
      });
    }

    function checkBatchSize(e) {
      _tfjsCore.util.assert(e > 0 && Number.isInteger(e), function () {
        return "batchSize is required to be a positive integer, but got " + e;
      });
    }

    function sliceArrays(e, t, n) {
      return null == e ? [null] : Array.isArray(e) ? e.map(function (e) {
        return sliceAlongFirstAxis(e, t, n - t);
      }) : sliceAlongFirstAxis(e, t, n - t);
    }

    function sliceArraysByIndices(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return null == e ? null : Array.isArray(e) ? e.map(function (e) {
          return sliceArraysByIndices(e, t);
        }) : gather$1(e, "int32" === t.dtype ? t : t.toInt());
      });
    }

    function makeBatches(e, t) {
      for (var n = [], r = 0, i = null; r < e;) (i = r + t) >= e && (i = e), n.push([r, i]), r = i;

      return n;
    }

    function fitLoop(e, t, n, r, i, a, o, s, l, u, c, p, h, d, f) {
      return __awaiter(this, void 0, void 0, function () {
        var g, m, y, v, b, w, z, S;
        return __generator(this, function (A) {
          switch (A.label) {
            case 0:
              if (null == i && (i = 32), null == a && (a = 1), null == c && (c = !0), null == h && (h = 0), g = !1, null != l && null != u && (g = !0), null != f && (g = !0, null == d)) throw new ValueError("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");
              return null != (m = e.checkNumSamples(n, i, d, "steps_per_epoch")) && (y = range(0, m)), null == o && (o = 1), v = configureCallbacks(s, o, a, h, m, d, i, g, p), b = v.callbackList, w = v.history, b.setModel(e), e.history = w, [4, b.onTrainBegin()];

            case 1:
              A.sent(), e.stopTraining_ = !1, z = function (a) {
                var o, s, p, h, f;
                return __generator(this, function (v) {
                  switch (v.label) {
                    case 0:
                      return [4, b.onEpochBegin(a)];

                    case 1:
                      if (v.sent(), o = {}, null == d) 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 && _tfjsCore.util.shuffle(y), s = (0, _tfjsCore.tensor1d)(y), p = makeBatches(m, i), h = function (a) {
                        var c;
                        return __generator(this, function (h) {
                          switch (h.label) {
                            case 0:
                              return c = {}, [4, b.onBatchBegin(a, c)];

                            case 1:
                              return h.sent(), (0, _tfjsCore.tidy)(function () {
                                var h = p[a][0],
                                  d = p[a][1],
                                  f = sliceAlongFirstAxis(s, h, d - h);
                                c.batch = a, c.size = d - h;

                                for (var m = sliceArraysByIndices(n, f), y = t(m), v = 0; v < r.length; ++v) {
                                  var b = r[v],
                                    w = y[v];
                                  c[b] = w, (0, _tfjsCore.keep)(w);
                                }

                                if (a === p.length - 1 && g) {
                                  var z = e.testLoop(l, u, i);

                                  for (v = 0; v < r.length; ++v) {
                                    b = r[v], w = z[v];
                                    (0, _tfjsCore.keep)(w), o["val_" + b] = w;
                                  }
                                }
                              }), [4, b.onBatchEnd(a, c)];

                            case 2:
                              return h.sent(), disposeTensorsInLogs(c), e.stopTraining_ ? [2, "break"] : [2];
                          }
                        });
                      }, f = 0, v.label = 3;

                    case 3:
                      return f < p.length ? [5, h(f)] : [3, 6];

                    case 4:
                      if ("break" === v.sent()) return [3, 6];
                      v.label = 5;

                    case 5:
                      return ++f, [3, 3];

                    case 6:
                      s.dispose(), v.label = 7;

                    case 7:
                      return [4, b.onEpochEnd(a, o)];

                    case 8:
                      return v.sent(), e.stopTraining_ ? [2, "break"] : [2];
                  }
                });
              }, S = h, A.label = 2;

            case 2:
              return S < a ? [5, z(S)] : [3, 5];

            case 3:
              if ("break" === A.sent()) return [3, 5];
              A.label = 4;

            case 4:
              return ++S, [3, 2];

            case 5:
              return [4, b.onTrainEnd()];

            case 6:
              return A.sent(), [4, e.history.syncData()];

            case 7:
              return A.sent(), [2, e.history];
          }
        });
      });
    }

    function fitTensors(e, t, n, r) {
      return void 0 === r && (r = {}), __awaiter(this, void 0, void 0, function () {
        var i, a, o, s, l, u, c, p, h, d, f, g, m, y, v, b, w, z, S, A, _, I;

        return __generator(this, function (C) {
          switch (C.label) {
            case 0:
              if (e.isTraining) throw new Error("Cannot start training because another fit() call is ongoing.");
              e.isTraining = !0, C.label = 1;

            case 1:
              return C.trys.push([1, , 7, 8]), checkBatchSize(p = null == r.batchSize ? 32 : r.batchSize), h = !1, [4, e.standardizeUserData(t, n, r.sampleWeight, r.classWeight, h, p)];

            case 2:
              if (d = C.sent(), i = d[0], a = d[1], c = d[2], f = !1, g = void 0, !(null != r.validationData && r.validationData.length > 0)) return [3, 4];
              if (f = !0, 2 !== r.validationData.length) throw 3 === r.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; " + r.validationData + " is invalid.");
              return o = r.validationData[0], s = r.validationData[1], m = !0, [4, e.standardizeUserData(o, s, null, null, m, p)];

            case 3:
              return y = C.sent(), l = y[0], u = y[1], g = l.concat(u), [3, 5];

            case 4:
              null != r.validationSplit && r.validationSplit > 0 && r.validationSplit < 1 ? (f = !0, v = Math.floor(i[0].shape[0] * (1 - r.validationSplit)), b = i[0].shape[0], l = sliceArrays(i, v, b), i = sliceArrays(i, 0, v), u = sliceArrays(a, v, b), a = sliceArrays(a, 0, v), g = l.concat(u)) : null != r.validationSteps && (f = !0), C.label = 5;

            case 5:
              return w = i.concat(a).concat(c), e.checkTrainableWeightsConsistency(), z = e.makeTrainFunction(), S = e.getDedupedMetricsNames(), A = void 0, _ = void 0, f ? (e.makeTestFunction(), A = e.testFunction, _ = S.slice().concat(S.map(function (e) {
                return "val_" + e;
              }))) : (A = null, g = [], _ = S.slice()), I = standardizeCallbacks(r.callbacks, r.yieldEvery), [4, fitLoop(e, z, w, S, p, r.epochs, r.verbose, I, A, g, r.shuffle, _, r.initialEpoch, null, null)];

            case 6:
              return [2, C.sent()];

            case 7:
              return e.isTraining = !1, disposeNewTensors(i, t), disposeNewTensors(a, n), disposeNewTensors(l, o), disposeNewTensors(u, s), null != c && (0, _tfjsCore.dispose)(c), [7];

            case 8:
              return [2];
          }
        });
      });
    }

    function ensureTensorsRank2OrHigher(e) {
      var t = [];
      e instanceof _tfjsCore.Tensor && (e = [e]);

      for (var n = 0; n < e.length; ++n) {
        var r = e[n];
        if (1 === r.rank) t.push(expandDims$1(r, 1)); else {
          if (0 === r.rank) throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar).");
          t.push(r);
        }
      }

      return t;
    }

    function disposeNewTensors(e, t) {
      if (null != e) {
        var n = [];
        if (t instanceof _tfjsCore.Tensor) n.push(t.id); else if (Array.isArray(t)) t.forEach(function (e) {
          return n.push(e.id);
        }); else if (null != t) for (var r in t) {
          var i = t[r];
          n.push(i.id);
        }
        var a = [];
        if (e instanceof _tfjsCore.Tensor) -1 === n.indexOf(e.id) && a.push(e); else if (Array.isArray(e)) e.forEach(function (e) {
          -1 === n.indexOf(e.id) && a.push(e);
        }); else if (null != e) for (var o in e) {
          var s = e[o];
          -1 === n.indexOf(s.id) && a.push(s);
        }
        a.forEach(function (e) {
          e.isDisposed || e.dispose();
        });
      }
    }

    function isDataTensor(e) {
      return e instanceof _tfjsCore.Tensor;
    }

    function isDataArray(e) {
      return Array.isArray(e);
    }

    function isDataDict(e) {
      return !isDataTensor(e) && !isDataArray(e);
    }

    function standardizeInputData(e, t, n, r, i) {
      if (void 0 === r && (r = !0), void 0 === i && (i = ""), null == t || 0 === t.length) {
        if (null != e) {
          var a = !1;
          if (isDataArray(e) && e.length > 0) a = !0; else if (isDataDict(e)) {
            for (var o in e) if (e.hasOwnProperty(o)) {
              a = !0;
              break;
            }
          } else a = !0;
          if (a) throw new ValueError("Error when checking model " + i + " expected no data, but got " + e);
        }

        return [];
      }

      if (null == e) return t.map(function (e) {
        return null;
      });
      var s;

      if (isDataDict(e)) {
        e = e, s = [];

        for (var l = 0, u = t; l < u.length; l++) {
          var c = u[l];
          if (null == e[c]) throw new ValueError('No data provided for "' + c + '". Need data for each key in: ' + t);
          s.push(e[c]);
        }
      } else if (isDataArray(e)) {
        if ((e = 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 model expected. Expected to see " + t.length + " Tensor(s), but instead got the following list of Tensor(s): " + e);
        s = e;
      } else {
        if (e = e, t.length > 1) throw new ValueError("The model " + i + " expects " + t.length + " Tensor(s), but only received one Tensor. Found: Tensor with shape " + e.shape);
        s = [e];
      }

      if (s = ensureTensorsRank2OrHigher(s), null != n) for (var p = 0; p < t.length; ++p) if (null != n[p]) {
        var h = s[p];
        if (h.shape.length !== n[p].length) throw new ValueError("Error when checking " + i + ": expected " + t[p] + " to have " + n[p].length + " dimension(s). but got array with shape " + h.shape);

        for (var d = 0; d < n[p].length; ++d) if (0 !== d || r) {
          var f = h.shape[d],
            g = n[p][d];
          if (null != g && g >= 0 && f !== g) throw new ValueError("Error when checking " + i + ": expected " + t[p] + " to have shape [" + n[p] + "], but got array with shape [" + h.shape + "].");
        }
      }
      return s;
    }

    function checkArrayLengths(e, t, n) {
      var r = unique(e.map(function (e) {
        return e.shape[0];
      }));
      r.sort();
      var i = 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 && !_tfjsCore.util.arraysEqual(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 checkLossAndTargetCompatibility(e, t, n) {
      for (var r = [meanSquaredError, binaryCrossentropy, categoricalCrossentropy], i = 0; i < e.length; ++i) {
        var a = e[i],
          o = t[i],
          s = n[i];

        if (null != o) {
          if (o === categoricalCrossentropy && 1 === a.shape[a.shape.length - 1]) throw new ValueError("You are passing a target array of shape " + a.shape + " while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].");
          if (-1 !== r.indexOf(o)) for (var l = a.shape.slice(1), u = s.slice(1), c = 0; c < l.length; ++c) {
            var p = l[c],
              h = u[c];
            if (null != h && p !== h) throw new ValueError("A target Tensor with shape " + a.shape + " was passed for an output of shape " + s + ", while using a loss function that expects targets to have the same shape as the output.");
          }
        }
      }
    }

    function checkInputData(e, t, n, r, i) {
      var a;

      if (void 0 === r && (r = !0), void 0 === i && (i = ""), 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 < t.length; ++o) if (null != n[o]) {
        var s = a[o];
        if (s.shape.length !== n[o].length) throw new ValueError("Error when checking " + i + ": expected " + t[o] + " to have " + n[o].length + " dimension(s), but got array with shape " + JSON.stringify(s.shape));

        for (var l = 0; l < n[o].length; ++l) if (0 !== l || r) {
          var u = s.shape[l],
            c = n[o][l];
          if (null != c && c !== u) throw new ValueError("Error when checking " + i + ": expected " + t[o] + " to have shape " + JSON.stringify(n[o]) + " but got array with shape " + JSON.stringify(s.shape) + ".");
        }
      }
    }

    function collectMetrics(e, t) {
      if (null == e || Array.isArray(e) && 0 === e.length) return t.map(function (e) {
        return [];
      });
      var n;
      if ("string" == typeof e || "function" == typeof e) n = [e]; else {
        if (!Array.isArray(e) && "object" != typeof e) throw new TypeError("Type of metrics argument not understood. Expected an string,function, Array, or Object, found: " + e);
        n = e;
      }
      if (Array.isArray(n)) return t.map(function (e) {
        return n;
      });

      for (var r = [], i = 0, a = t; i < a.length; i++) {
        var o = a[i],
          s = n.hasOwnProperty(o) ? n[o] : [];
        Array.isArray(s) || (s = [s]), r.push(s);
      }

      return r;
    }

    var LAYERS_MODEL_FORMAT_NAME = "layers-model",
      LayersModel = function (e) {
        function t(t) {
          var n = e.call(this, t) || this;
          return n.isTraining = !1, n;
        }

        return __extends(t, e), t.prototype.summary = function (e, t, n) {
          if (void 0 === n && (n = console.log), !this.built) throw new ValueError("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");
          printSummary(this, e, t, n);
        }, t.prototype.compile = function (e) {
          var t = this;
          if (null == e.loss && (e.loss = []), this.loss = e.loss, "string" == typeof e.optimizer) this.optimizer_ = getOptimizer(e.optimizer), this.isOptimizerOwned = !0; else {
            if (!(e.optimizer instanceof _tfjsCore.Optimizer)) throw new ValueError("User-defined optimizer must be an instance of tf.Optimizer.");
            this.optimizer_ = e.optimizer, this.isOptimizerOwned = !1;
          }
          var n = [];
          if (Array.isArray(e.loss) || "string" == typeof e.loss || "function" == typeof e.loss) {
            if (Array.isArray(e.loss)) {
              if (e.loss.length !== this.outputs.length) throw new ValueError("When passing an Array as loss, it should have one entry per model output. The model has " + this.outputs.length + " output(s), but you passed loss=" + e.loss + ".");
              var r = e.loss;
              n = r.map(function (e) {
                return get(e);
              });
            } else {
              var i = get(e.loss);
              this.outputs.forEach(function (e) {
                n.push(i);
              });
            }
          } else {
            for (var a in e.loss = e.loss, e.loss) if (-1 === this.outputNames.indexOf(a)) throw new ValueError('Unknown entry in loss dictionary: "' + a + '". Only expected the following keys: ' + this.outputNames);

            for (var o = 0, s = this.outputNames; o < s.length; o++) {
              var l = s[o];
              null == e.loss[l] && console.warn('Output "' + l + '" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to ' + l + " during training"), n.push(get(e.loss[l]));
            }
          }
          this.lossFunctions = n, this.feedOutputNames = [], this.feedOutputShapes = [], this.feedLossFns = [];

          for (var u = 0; u < this.outputs.length; ++u) {
            var c = this.internalOutputShapes[u],
              p = this.outputNames[u];
            this.feedOutputNames.push(p), this.feedOutputShapes.push(c), this.feedLossFns.push(this.lossFunctions[u]);
          }

          var h = [];
          this.metrics = e.metrics, this.metricsNames = ["loss"], this.metricsTensors = [], nameScope("loss", function () {
            for (var e = 0; e < t.outputs.length; ++e) if (-1 === h.indexOf(e)) {
              var n = t.lossFunctions[e];
              t.outputs.length > 1 && (t.metricsTensors.push([n, e]), t.metricsNames.push(t.outputNames[e] + "_loss"));
            }
          });
          var d = collectMetrics(e.metrics, this.outputNames);
          nameScope("metric", function () {
            for (var e = function (e) {
              if (-1 !== h.indexOf(e)) return "continue";
              !function (n) {
                for (var r, i, a, o = function (n) {
                  if ("string" == typeof n && -1 !== ["accuracy", "acc", "crossentropy", "ce"].indexOf(n)) {
                    var o = t.internalOutputShapes[e];
                    1 === o[o.length - 1] || t.lossFunctions[e] === binaryCrossentropy ? -1 !== ["accuracy", "acc"].indexOf(n) ? i = binaryAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = binaryCrossentropy$1) : t.lossFunctions[e] === sparseCategoricalCrossentropy ? -1 !== ["accuracy", "acc"].indexOf(n) ? i = sparseCategoricalAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = sparseCategoricalCrossentropy$1) : -1 !== ["accuracy", "acc"].indexOf(n) ? i = categoricalAccuracy : -1 !== ["crossentropy", "ce"].indexOf(n) && (i = categoricalCrossentropy$1);
                    var s = void 0;
                    -1 !== ["accuracy", "acc"].indexOf(n) ? s = "acc" : -1 !== ["crossentropy", "ce"].indexOf(n) && (s = "ce"), a = i, r = "" + s;
                  } else {
                    var l = get$1(n);
                    a = l, r = "" + getLossOrMetricName(n);
                  }

                  var u;
                  nameScope(r, function () {
                    u = a;
                  }), function (e, n, r) {
                    t.outputNames.length > 1 && (n = t.outputNames[e] + "_" + n), t.metricsNames.push(n), t.metricsTensors.push([r, e]);
                  }(e, r, u);
                }, s = 0, l = n; s < l.length; s++) o(l[s]);
              }(d[e]);
            }, n = 0; n < t.outputs.length; ++n) e(n);
          }), this.collectedTrainableWeights = this.trainableWeights;
        }, t.prototype.checkTrainableWeightsConsistency = function () {
          null != this.collectedTrainableWeights && this.trainableWeights.length !== this.collectedTrainableWeights.length && console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?");
        }, t.prototype.evaluate = function (e, t, n) {
          void 0 === n && (n = {});
          var r = null == n.batchSize ? 32 : n.batchSize;
          checkBatchSize(r);
          var i = this.standardizeUserDataXY(e, t, !0, r);

          try {
            var a = i[0].concat(i[1]);
            this.makeTestFunction();
            var o = this.testFunction;
            return singletonOrArray(this.testLoop(o, a, r, n.verbose, n.steps));
          } finally {
            disposeNewTensors(i[0], e), disposeNewTensors(i[1], t);
          }
        }, t.prototype.evaluateDataset = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (n) {
              return this.makeTestFunction(), [2, evaluateDataset(this, e, t)];
            });
          });
        }, t.prototype.checkNumSamples = function (e, t, n, r) {
          var i;

          if (void 0 === r && (r = "steps"), null != n) {
            if (i = null, null != t) throw new ValueError("If " + r + " is set, batchSize must be null or undefined.Got batchSize = " + t);
          } else {
            if (null == e) throw new ValueError("Either the input data should have a defined shape, or " + r + " shoud be specified.");
            i = Array.isArray(e) ? e[0].shape[0] : e.shape[0];
          }

          return i;
        }, t.prototype.execute = function (e, t) {
          if (Array.isArray(t) && 0 === t.length) throw new ValueError("`outputs` is an empty Array, which is not allowed.");
          var n = Array.isArray(t),
            r = n ? t : [t],
            i = this.retrieveSymbolicTensors(r),
            a = new FeedDict();

          if (e instanceof _tfjsCore.Tensor && (e = [e]), Array.isArray(e)) {
            if (e.length !== this.inputs.length) throw new ValueError("The number of inputs provided (" + e.length + ") does not match the number of inputs of this model (" + this.inputs.length + ").");

            for (var o = 0; o < this.inputs.length; ++o) a.add(this.inputs[o], e[o]);
          } else for (var s = 0, l = this.inputs; s < l.length; s++) {
            var u = l[s],
              c = e[u.name];
            if (null == c) throw new ValueError("No value is provided for the model's input " + u.name);
            a.add(u, c);
          }

          var p = execute(i, a);
          return n ? p : p[0];
        }, t.prototype.retrieveSymbolicTensors = function (e) {
          for (var t = pyListRepeat(null, e.length), n = e.length, r = 0, i = this.layers; r < i.length; r++) {
            for (var a = i[r], o = Array.isArray(a.output) ? a.output : [a.output], s = o.map(function (e) {
              return e.name;
            }), l = 0; l < e.length; ++l) {
              var u = s.indexOf(e[l]);
              if (-1 !== u && (t[l] = o[u], n--), 0 === n) break;
            }

            if (0 === n) break;
          }

          if (n > 0) {
            var c = [];
            throw t.forEach(function (t, n) {
              null == t && c.push(e[n]);
            }), new ValueError("Cannot find SymbolicTensors for output name(s): " + JSON.stringify(c));
          }

          return t;
        }, t.prototype.predictLoop = function (e, t, n) {
          var r = this;
          return void 0 === t && (t = 32), void 0 === n && (n = !1), (0, _tfjsCore.tidy)(function () {
            var i = r.checkNumSamples(e);
            if (n) throw new NotImplementedError("Verbose predictLoop() is not implemented yet.");

            for (var a = makeBatches(i, t), o = r.outputs.map(function (e) {
              return [];
            }), s = function (t) {
              (0, _tfjsCore.tidy)(function () {
                var n = a[t][0],
                  i = a[t][1],
                  o = sliceArrays(e, n, i),
                  s = [];
                if (Array.isArray(o)) for (var l = 0; l < o.length; ++l) s.push({
                  key: r.inputs[l],
                  value: o[l]
                }); else s.push({
                  key: r.inputs[0],
                  value: o
                });
                var u = new FeedDict(s);
                return execute(r.outputs, u);
              }).forEach(function (e, t) {
                return o[t].push(e);
              });
            }, l = 0; l < a.length; ++l) s(l);

            return singletonOrArray(o.map(function (e) {
              return (0, _tfjsCore.concat)(e, 0);
            }));
          });
        }, t.prototype.predict = function (e, t) {
          void 0 === t && (t = {});
          var n = ensureTensorsRank2OrHigher(e);
          checkInputData(n, this.inputNames, this.feedInputShapes, !1);

          try {
            var r = null == t.batchSize ? 32 : t.batchSize;
            return checkBatchSize(r), this.predictLoop(n, r);
          } finally {
            disposeNewTensors(n, e);
          }
        }, t.prototype.predictOnBatch = function (e) {
          checkInputData(e, this.inputNames, this.feedInputShapes, !0);
          var t = (Array.isArray(e) ? e[0] : e).shape[0];
          return this.predictLoop(e, t);
        }, t.prototype.standardizeUserDataXY = function (e, t, n, r) {
          if (void 0 === n && (n = !0), null == this.optimizer_) throw new RuntimeError("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");

          for (var i = [], a = 0; a < this.feedOutputShapes.length; ++a) {
            var o = this.feedOutputShapes[a];
            this.feedLossFns[a] === sparseCategoricalCrossentropy ? i.push(o.slice(0, o.length - 1).concat([1])) : i.push(o);
          }

          if (checkArrayLengths(e = standardizeInputData(e, this.feedInputNames, this.feedInputShapes, !1, "input"), t = standardizeInputData(t, this.feedOutputNames, i, !1, "target"), null), checkLossAndTargetCompatibility(t, this.feedLossFns, this.feedOutputShapes), this.stateful && null != r && r > 0 && 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];
        }, t.prototype.standardizeUserData = function (e, t, n, r, i, a) {
          return void 0 === i && (i = !0), __awaiter(this, void 0, void 0, function () {
            var o, s, l, u, c, p, h, d;
            return __generator(this, function (f) {
              switch (f.label) {
                case 0:
                  if (o = this.standardizeUserDataXY(e, t, i, a), s = o[0], l = o[1], null != n) throw new Error("sample weight is not supported yet.");
                  if (u = null, null == r) return [3, 4];
                  c = standardizeClassWeights(r, this.outputNames), u = [], p = 0, f.label = 1;

                case 1:
                  return p < c.length ? (d = (h = u).push, [4, standardizeWeights(l[p], null, c[p])]) : [3, 4];

                case 2:
                  d.apply(h, [f.sent()]), f.label = 3;

                case 3:
                  return ++p, [3, 1];

                case 4:
                  return [2, [s, l, u]];
              }
            });
          });
        }, t.prototype.testLoop = function (e, t, n, r, i) {
          var a = this;
          return void 0 === r && (r = 0), (0, _tfjsCore.tidy)(function () {
            var o = a.checkNumSamples(t, n, i, "steps"),
              s = [];
            if (r > 0) throw new NotImplementedError("Verbose mode is not implemented yet.");
            if (null != i) throw new NotImplementedError("steps mode in testLoop() is not implemented yet");

            for (var l = makeBatches(o, n), u = (0, _tfjsCore.tensor1d)(range(0, o)), c = 0; c < l.length; ++c) {
              var p = l[c][0],
                h = l[c][1],
                d = sliceAlongFirstAxis(u, p, h - p),
                f = sliceArraysByIndices(t, d),
                g = e(f);
              if (0 === c) for (var m = 0; m < g.length; ++m) s.push((0, _tfjsCore.scalar)(0));

              for (m = 0; m < g.length; ++m) {
                var y = g[m];
                s[m] = (0, _tfjsCore.add)(s[m], (0, _tfjsCore.mul)(h - p, y));
              }
            }

            for (m = 0; m < s.length; ++m) s[m] = (0, _tfjsCore.div)(s[m], o);

            return s;
          });
        }, t.prototype.getDedupedMetricsNames = function () {
          for (var e = this.metricsNames, t = [], n = 0; n < e.length; ++n) {
            var r = e[n],
              i = r;
            if (count(e, r) > 1) i += "_" + count(e.slice(0, n), r);
            t.push(i);
          }

          return t;
        }, t.prototype.makeTrainFunction = function () {
          var e = this;
          return function (t) {
            var n = [],
              r = t.slice(0, e.inputs.length),
              i = t.slice(e.inputs.length, e.inputs.length + e.outputs.length),
              a = t.slice(e.inputs.length + e.outputs.length, e.inputs.length + 2 * e.outputs.length),
              o = [],
              s = e.collectedTrainableWeights.map(function (e) {
                return e.read();
              });
            return [e.optimizer_.minimize(function () {
              for (var t = [], s = 0; s < e.inputs.length; ++s) t.push({
                key: e.inputs[s],
                value: r[s]
              });

              var l,
                u = new FeedDict(t),
                c = execute(e.outputs, u, {
                  training: !0
                });

              for (s = 0; s < e.lossFunctions.length; ++s) {
                var p = (0, e.lossFunctions[s])(i[s], c[s]);
                null != a[s] && (p = computeWeightedLoss(p, a[s]));
                var h = (0, _tfjsCore.mean)(p);
                n.push(h), l = 0 === s ? p : (0, _tfjsCore.add)(l, p);
              }

              for (s = 0; s < e.metricsTensors.length; ++s) {
                var d = void 0;
                if (e.outputs.length > 1 && s < e.outputs.length) d = n[s]; else {
                  var f = e.metricsTensors[s][0],
                    g = e.metricsTensors[s][1];
                  d = (0, _tfjsCore.mean)(f(i[g], c[g]));
                }
                (0, _tfjsCore.keep)(d), o.push(d);
              }

              return l = (0, _tfjsCore.mean)(l), e.calculateLosses().forEach(function (e) {
                l = (0, _tfjsCore.add)(l, e);
              }), l;
            }, !0, s)].concat(o);
          };
        }, t.prototype.makeTestFunction = function () {
          var e = this;

          this.testFunction = function (t) {
            return (0, _tfjsCore.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; s < e.inputs.length; ++s) o.push({
                key: e.inputs[s],
                value: i[s]
              });

              var l = new FeedDict(o),
                u = execute(e.outputs, l);

              for (s = 0; s < e.lossFunctions.length; ++s) {
                var c = e.lossFunctions[s],
                  p = (0, _tfjsCore.mean)(c(a[s], u[s]));
                n = 0 === s ? p : (0, _tfjsCore.add)(n, p), r.push(n);
              }

              for (s = 0; s < e.metricsTensors.length; ++s) {
                var h = e.metricsTensors[s][0],
                  d = e.metricsTensors[s][1],
                  f = (0, _tfjsCore.mean)(h(a[d], u[d]));
                r.push(f);
              }

              return r;
            });
          };
        }, t.prototype.fit = function (e, t, n) {
          return void 0 === n && (n = {}), __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (r) {
              return [2, fitTensors(this, e, t, n)];
            });
          });
        }, t.prototype.fitDataset = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (n) {
              return [2, fitDataset(this, e, t)];
            });
          });
        }, t.prototype.trainOnBatch = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r, i, a, o, s, l, u, c;
            return __generator(this, function (p) {
              switch (p.label) {
                case 0:
                  return [4, this.standardizeUserData(e, t)];

                case 1:
                  n = p.sent(), r = n[0], i = n[1], a = this.makeTrainFunction(), o = a(r.concat(i)), s = [], l = 0, u = o, p.label = 2;

                case 2:
                  return l < u.length ? [4, u[l].data()] : [3, 5];

                case 3:
                  c = p.sent(), s.push(c[0]), p.label = 4;

                case 4:
                  return l++, [3, 2];

                case 5:
                  return (0, _tfjsCore.dispose)(o), [2, singletonOrArray(s)];
              }
            });
          });
        }, t.prototype.getNamedWeights = function (e) {
          for (var t = [], n = null != e && e.trainableOnly, r = n ? this.trainableWeights : this.weights, i = this.getWeights(n), a = 0; a < r.length; ++a) n && !r[a].trainable || t.push({
            name: r[a].originalName,
            tensor: i[a]
          });

          return t;
        }, Object.defineProperty(t.prototype, "stopTraining", {
          get: function () {
            return this.stopTraining_;
          },
          set: function (e) {
            this.stopTraining_ = e;
          },
          enumerable: !0,
          configurable: !0
        }), Object.defineProperty(t.prototype, "optimizer", {
          get: function () {
            return this.optimizer_;
          },
          set: function (e) {
            this.optimizer_ !== e && (this.optimizer_ = e, this.isOptimizerOwned = !1);
          },
          enumerable: !0,
          configurable: !0
        }), t.prototype.dispose = function () {
          var t = e.prototype.dispose.call(this);

          if (0 === t.refCountAfterDispose && null != this.optimizer && this.isOptimizerOwned) {
            var n = (0, _tfjsCore.memory)().numTensors;
            this.optimizer_.dispose(), t.numDisposedVariables += n - (0, _tfjsCore.memory)().numTensors;
          }

          return t;
        }, t.prototype.getLossIdentifiers = function () {
          var e;
          if ("string" == typeof this.loss) e = toSnakeCase(this.loss); else if (Array.isArray(this.loss)) {
            for (var t = 0, n = this.loss; t < n.length; t++) {
              if ("string" != typeof n[t]) throw new Error("Serialization of non-string loss is not supported.");
            }

            e = this.loss.map(function (e) {
              return toSnakeCase(e);
            });
          } else {
            var r = Object.keys(this.loss);
            e = {};

            for (var i = this.loss, a = 0, o = r; a < o.length; a++) {
              var s = o[a];
              if ("string" != typeof i[s]) throw new Error("Serialization of non-string loss is not supported.");
              e[s] = toSnakeCase(i[s]);
            }
          }
          return e;
        }, t.prototype.getMetricIdentifiers = function () {
          if ("string" == typeof this.metrics || "function" == typeof this.metrics) return [toSnakeCase(getLossOrMetricName(this.metrics))];
          if (Array.isArray(this.metrics)) return this.metrics.map(function (e) {
            return toSnakeCase(getLossOrMetricName(e));
          });
          var e = {};

          for (var t in this.metrics) e[t] = toSnakeCase(getLossOrMetricName(this.metrics[t]));

          return e;
        }, t.prototype.getTrainingConfig = function () {
          return {
            loss: this.getLossIdentifiers(),
            metrics: this.getMetricIdentifiers(),
            optimizer_config: {
              class_name: this.optimizer.getClassName(),
              config: this.optimizer.getConfig()
            }
          };
        }, t.prototype.loadTrainingConfig = function (e) {
          if (null != e.weighted_metrics) throw new Error("Loading weight_metrics is not supported yet.");
          if (null != e.loss_weights) throw new Error("Loading loss_weights is not supported yet.");
          if (null != e.sample_weight_mode) throw new Error("Loading sample_weight_mode is not supported yet.");
          var t,
            n,
            r = deserialize(convertPythonicToTs(e.optimizer_config));
          if ("string" == typeof e.loss) t = toCamelCase(e.loss); else if (Array.isArray(e.loss)) t = e.loss.map(function (e) {
            return toCamelCase(e);
          }); else if (null != e.loss) for (var i in t = {}, e.loss) t[i] = toCamelCase(e.loss[i]);
          if (Array.isArray(e.metrics)) n = e.metrics.map(function (e) {
            return toCamelCase(e);
          }); else if (null != e.metrics) for (var i in n = {}, e.metrics) n[i] = toCamelCase(e.metrics[i]);
          this.compile({
            loss: t,
            metrics: n,
            optimizer: r
          });
        }, t.prototype.save = function (e, t) {
          return __awaiter(this, void 0, void 0, function () {
            var n, r, i, a, o, s, l, u, c, p, h, d, f, g;
            return __generator(this, function (m) {
              switch (m.label) {
                case 0:
                  if ("string" == typeof e) {
                    if (0 === (n = _tfjsCore.io.getSaveHandlers(e)).length) throw new ValueError("Cannot find any save handlers for URL '" + e + "'");
                    if (n.length > 1) throw new ValueError("Found more than one (" + n.length + ") save handlers for URL '" + e + "'");
                    e = n[0];
                  }

                  if (null == e.save) throw new ValueError("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");
                  return [4, _tfjsCore.io.encodeWeights(this.getNamedWeights(t))];

                case 1:
                  return r = m.sent(), i = !1, a = null, o = this.toJSON(a, i), s = {
                    modelTopology: o,
                    format: LAYERS_MODEL_FORMAT_NAME,
                    generatedBy: "TensorFlow.js tfjs-layers v" + version,
                    convertedBy: null
                  }, null != t && t.includeOptimizer && null != this.optimizer ? (s.trainingConfig = this.getTrainingConfig(), l = "optimizer", d = (h = _tfjsCore.io).encodeWeights, [4, this.optimizer.getWeights()]) : [3, 4];

                case 2:
                  return [4, d.apply(h, [m.sent(), l])];

                case 3:
                  u = m.sent(), c = u.data, p = u.specs, (g = r.specs).push.apply(g, p), r.data = _tfjsCore.io.concatenateArrayBuffers([r.data, c]), m.label = 4;

                case 4:
                  return null != this.userDefinedMetadata && (f = !0, checkUserDefinedMetadata(this.userDefinedMetadata, this.name, f), s.userDefinedMetadata = this.userDefinedMetadata), s.weightData = r.data, s.weightSpecs = r.specs, [2, e.save(s)];
              }
            });
          });
        }, t.prototype.setUserDefinedMetadata = function (e) {
          checkUserDefinedMetadata(e, this.name), this.userDefinedMetadata = e;
        }, t.prototype.getUserDefinedMetadata = function () {
          return this.userDefinedMetadata;
        }, t.className = "Model", t;
      }(Container);

    exports.LayersModel = LayersModel;

    function modelFromJSON(e, t) {
      return __awaiter(this, void 0, void 0, function () {
        var n, r, i, a, o, s, l, u;
        return __generator(this, function (c) {
          switch (c.label) {
            case 0:
              return "modelTopology" in e || (e = {
                modelTopology: e
              }), null != (n = (e = e).modelTopology).model_config && (n = n.model_config), r = convertPythonicToTs(n), i = deserialize(r, t), null == e.weightsManifest ? [3, 2] : [4, _tfjsCore.io.loadWeights(e.weightsManifest, e.pathPrefix, i.weights.map(function (e) {
                return e.originalName;
              }))];

            case 1:
              for (a = c.sent(), o = {}, s = 0, l = i.weights; s < l.length; s++) u = l[s], o[u.originalName] = a[u.originalName];

              i.loadWeights(o), (0, _tfjsCore.dispose)(a), c.label = 2;

            case 2:
              return [2, i];
          }
        });
      });
    }

    function loadLayersModelInternal(e, t) {
      return __awaiter(this, void 0, void 0, function () {
        var n;
        return __generator(this, function (r) {
          if (null == t && (t = {}), "string" == typeof e) {
            if (0 === (n = _tfjsCore.io.getLoadHandlers(e, t.onProgress)).length) n.push(_tfjsCore.io.browserHTTPRequest(e, t)); else if (n.length > 1) throw new ValueError("Found more than one (" + n.length + ") load handlers for URL '" + e + "'");
            e = n[0];
          }

          return [2, loadLayersModelFromIOHandler(e, void 0, t)];
        });
      });
    }

    function loadLayersModelFromIOHandler(e, t, n) {
      return __awaiter(this, void 0, void 0, function () {
        var r, i, a, o, s, l, u, c, p;
        return __generator(this, function (h) {
          switch (h.label) {
            case 0:
              if (null == n && (n = {}), null == e.load) throw new ValueError("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
              return [4, e.load()];

            case 1:
              if (r = h.sent(), null != (i = r.modelTopology).model_config && (i = i.model_config), a = null == n.strict || n.strict, o = null != r.weightData && null != r.weightSpecs && a, s = deserialize(convertPythonicToTs(i), t, o), null != (l = r.trainingConfig) && s.loadTrainingConfig(l), null != r.userDefinedMetadata && s.setUserDefinedMetadata(r.userDefinedMetadata), null == r.weightData) return [3, 4];
              if (null == r.weightSpecs) throw new ValueError("LayersModel artifacts contains weight data, but not weight specs. Therefore loading of weights cannot proceed.");
              return u = decodeModelAndOptimizerWeights(r.weightData, r.weightSpecs), c = u.modelWeights, p = u.optimizerWeights, s.loadWeights(c, a), null != s.optimizer && p.length > 0 ? [4, s.optimizer.setWeights(p)] : [3, 3];

            case 2:
              h.sent(), h.label = 3;

            case 3:
              (0, _tfjsCore.dispose)(c), (0, _tfjsCore.dispose)(p.map(function (e) {
                return e.tensor;
              })), h.label = 4;

            case 4:
              return [2, s];
          }
        });
      });
    }

    function decodeModelAndOptimizerWeights(e, t) {
      var n = _tfjsCore.io.decodeWeights(e, t),
        r = {},
        i = [];

      return t.forEach(function (e) {
        "optimizer" === e.group ? i.push({
          name: e.name,
          tensor: n[e.name]
        }) : r[e.name] = n[e.name];
      }), {
        modelWeights: r,
        optimizerWeights: i
      };
    }

    _tfjsCore.serialization.registerClass(LayersModel);

    var Sequential = function (e) {
      function t(t) {
        var n = e.call(this, {
          inputs: [],
          outputs: []
        }) || this;
        if (t = t || {}, n.trainable = !0, n.built = !1, n.name = null != t.name ? t.name : getUid("sequential_"), null != t.layers) for (var r = 0, i = t.layers; r < i.length; r++) {
          var a = i[r];
          n.add(a);
        }
        return n;
      }

      return __extends(t, e), t.prototype.checkShape = function (e) {
        if (e.inboundNodes[0].outputTensors[0].shape.some(function (e) {
          return e < 0;
        })) throw new ValueError("Negative dimension size caused by adding layer " + e.name + " with input shape [" + e.inboundNodes[0].inputTensors[0].shape + "]");
      }, t.prototype.add = function (e) {
        var n,
          r = e instanceof t || e instanceof LayersModel;

        if (r) {
          if (1 !== (n = e).outputs.length) throw new ValueError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
          if (1 !== n.inputs.length) throw new ValueError("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.");
        }

        if (0 === this.outputs.length) {
          if (0 === e.inboundNodes.length) {
            if (null == e.batchInputShape) throw new ValueError("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.");
            var i = Input({
              batchShape: e.batchInputShape,
              dtype: e.dtype,
              name: e.name + "_input"
            });
            e.apply(i);
          }

          if (r) this.outputs = n.outputs, this.inputs = n.inputs; else {
            if (1 !== e.inboundNodes.length) throw new ValueError("A layer added to a Sequential model must not already be connected somewhere else. LayersModel received layer " + e.name + " which has " + e.inboundNodes.length + " pre-existing inbound connections.");
            if (1 !== e.inboundNodes[0].outputTensors.length) throw new ValueError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
            this.checkShape(e), this.outputs = [e.inboundNodes[0].outputTensors[0]], this.inputs = getSourceInputs(this.outputs[0]);
          }
          this.inboundNodes = [], new Node({
            outboundLayer: this,
            inboundLayers: [],
            nodeIndices: [],
            tensorIndices: [],
            inputTensors: this.inputs,
            outputTensors: this.outputs,
            inputMasks: pyListRepeat(null, this.inputs.length),
            outputMasks: [null],
            inputShapes: this.inputs.map(function (e) {
              return e.shape;
            }),
            outputShapes: this.outputs[0].shape
          });
        } else {
          var a = e.apply(this.outputs[0]);
          if (Array.isArray(a)) throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
          this.checkShape(e), this.outputs = [a], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
        }

        this.layers.push(e), this.built = !1;
      }, t.prototype.pop = function () {
        if (0 === this.layers.length) throw new TypeError("There are no layers in the model.");
        if (this.layers.pop(), 0 === this.layers.length) this.outputs = [], this.inboundNodes = [], this.outboundNodes = []; else {
          var e = this.layers.length - 1;
          this.layers[e].outboundNodes = [], this.outputs = [this.layers[e].output], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
        }
      }, t.prototype.call = function (e, t) {
        return null == this.model && this.build(), this.model.call(e, t);
      }, t.prototype.build = function (e) {
        if (getExactlyOneShape(e), 0 === this.inputs.length || 0 === this.outputs.length) throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first.");
        this.model = new LayersModel({
          inputs: this.inputs,
          outputs: this.outputs[0],
          name: this.name + "_model"
        }), this.model.trainable = this.trainable, this.supportsMasking = this.model.supportsMasking, this.inputLayers = this.model.inputLayers, this.inputLayersNodeIndices = this.model.inputLayersNodeIndices, this.inputLayersTensorIndices = this.model.inputLayersTensorIndices, this.outputLayers = this.model.outputLayers, this.outputLayersNodeIndices = this.model.outputLayersNodeIndices, this.outputLayersTensorIndices = this.model.outputLayersTensorIndices, this.nodesByDepth = this.model.nodesByDepth, this.containerNodes = this.model.containerNodes, this.outputNames = this.model.outputNames, this.inputNames = this.model.inputNames, this.built = !0;
      }, t.prototype.countParams = function () {
        return this.built || this.build(), e.prototype.countParams.call(this);
      }, t.prototype.summary = function (t, n, r) {
        void 0 === r && (r = console.log), this.built || this.build(), e.prototype.summary.call(this, t, n, r);
      }, t.prototype.setWeights = function (e) {
        null == this.model && this.build(), this.model.setWeights(e);
      }, t.prototype.evaluate = function (e, t, n) {
        if (void 0 === n && (n = {}), !this.built) throw new RuntimeError("The model needs to be compiled before being used.");
        return this.model.evaluate(e, t, n);
      }, t.prototype.evaluateDataset = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (n) {
            if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
            return [2, this.model.evaluateDataset(e, t)];
          });
        });
      }, t.prototype.predict = function (e, t) {
        return void 0 === t && (t = {}), null == this.model && this.build(), this.model.predict(e, t);
      }, t.prototype.predictOnBatch = function (e) {
        return null == this.model && this.build(), this.model.predictOnBatch(e);
      }, t.prototype.compile = function (e) {
        this.build(), this.model.compile(e), this.optimizer_ = this.model.optimizer, this.isOptimizerOwned = this.model.isOptimizerOwned, this.loss = this.model.loss, this.metrics = this.model.metrics, this.metricsTensors = this.model.metricsTensors, this.metricsNames = this.model.metricsNames;
      }, Object.defineProperty(t.prototype, "optimizer", {
        get: function () {
          return null == this.model ? void 0 : this.model.optimizer;
        },
        set: function (e) {
          this.model.optimizer = e;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.fit = function (e, t, n) {
        return void 0 === n && (n = {}), __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (r) {
            if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
            return [2, this.model.fit(e, t, n)];
          });
        });
      }, t.prototype.fitDataset = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (n) {
            if (!this.built) throw new RuntimeError("The model needs to be compiled before being used.");
            return [2, this.model.fitDataset(e, t)];
          });
        });
      }, t.prototype.trainOnBatch = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (n) {
            return [2, this.model.trainOnBatch(e, t)];
          });
        });
      }, t.fromConfig = function (e, n, r, i) {
        var a;
        void 0 === r && (r = {}), void 0 === i && (i = !1);
        var o = {};

        if (n instanceof Array) {
          if (null == n[0].className || "Merge" === n[0].className) throw new ValueError("Legacy serialization format not supported yet.");
          a = n;
        } else _tfjsCore.util.assert(null != n.layers, function () {
          return "When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field.";
        }), a = n.layers, delete n.layers, o = n;

        var s = new e(o);
        if (!(s instanceof t)) throw new NotImplementedError("Sequential.fromConfig called on non-Sequential input: " + s);

        for (var l = 0, u = a; l < u.length; l++) {
          var c = deserialize(u[l], void 0, i);
          i && c.setFastWeightInitDuringBuild(!0), s.add(c);
        }

        return s;
      }, Object.defineProperty(t.prototype, "stopTraining", {
        get: function () {
          if (null == this.model) throw new ValueError("Cannot get the stopTraining property of a sequential model before it is compiled.");
          return this.model.stopTraining;
        },
        set: function (e) {
          if (null == this.model) throw new ValueError("Cannot set the stopTraining property of a sequential model before it is compiled.");
          this.model.stopTraining = e;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.getConfig = function () {
        for (var e = [], t = 0, n = this.layers; t < n.length; t++) {
          var r = n[t],
            i = {};
          i.className = r.getClassName(), i.config = r.getConfig(), e.push(i);
        }

        return {
          name: this.name,
          layers: e
        };
      }, t.className = "Sequential", t;
    }(LayersModel);

    exports.Sequential = Sequential;

    function model(e) {
      return new LayersModel(e);
    }

    function sequential(e) {
      return new Sequential(e);
    }

    function loadLayersModel(e, t) {
      return null == t && (t = {}), loadLayersModelInternal(e, t);
    }

    function input(e) {
      return Input(e);
    }

    function registerCallbackConstructor(e, t) {
      CallbackConstructorRegistry.registerCallbackConstructor(e, t);
    }

    _tfjsCore.serialization.registerClass(Sequential);

    var Activation = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.getConfig = function () {
        return {};
      }, t;
    }(_tfjsCore.serialization.Serializable),
      Elu = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.apply = function (e, t) {
          return void 0 === t && (t = 1), elu$1(e, t);
        }, t.className = "elu", t;
      }(Activation);

    _tfjsCore.serialization.registerClass(Elu);

    var Selu = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.selu)(e);
      }, t.className = "selu", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Selu);

    var Relu = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.relu)(e);
      }, t.className = "relu", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Relu);

    var Relu6 = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.tidy)(function () {
          return (0, _tfjsCore.minimum)(6, (0, _tfjsCore.relu)(e));
        });
      }, t.className = "relu6", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Relu6);

    var Linear = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return e;
      }, t.className = "linear", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Linear);

    var Sigmoid = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.sigmoid)(e);
      }, t.className = "sigmoid", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Sigmoid);

    var HardSigmoid = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return hardSigmoid(e);
      }, t.className = "hardSigmoid", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(HardSigmoid);

    var Softplus = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.softplus)(e);
      }, t.className = "softplus", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Softplus);

    var Softsign = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return softsign(e);
      }, t.className = "softsign", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Softsign);

    var Tanh = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e) {
        return (0, _tfjsCore.tanh)(e);
      }, t.className = "tanh", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Tanh);

    var Softmax = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        return void 0 === t && (t = -1), (0, _tfjsCore.softmax)(e, t);
      }, t.className = "softmax", t;
    }(Activation);

    _tfjsCore.serialization.registerClass(Softmax);

    var LogSoftmax = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.apply = function (e, t) {
        return void 0 === t && (t = -1), (0, _tfjsCore.logSoftmax)(e, t);
      }, t.className = "logSoftmax", t;
    }(Activation);

    function serializeActivation(e) {
      return e.getClassName();
    }

    function deserializeActivation(e, t) {
      return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "activation");
    }

    function getActivation(e) {
      var t;
      return null == e ? deserializeActivation(t = {
        className: "linear",
        config: {}
      }) : "string" == typeof e ? ((t = {}).className = e, t.config = {}, deserializeActivation(t)) : e instanceof Activation ? e : deserializeActivation(e);
    }

    function assertObjectArgs(e) {
      if (null != e && "object" != typeof e) throw new Error("Argument to L1L2 regularizer's constructor is expected to be an object, but received: " + e);
    }

    _tfjsCore.serialization.registerClass(LogSoftmax);

    var Regularizer = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t;
    }(_tfjsCore.serialization.Serializable),
      L1L2 = function (e) {
        function t(t) {
          var n = e.call(this) || this;
          return assertObjectArgs(t), n.l1 = null == t || null == t.l1 ? .01 : t.l1, n.l2 = null == t || null == t.l2 ? .01 : t.l2, n.hasL1 = 0 !== n.l1, n.hasL2 = 0 !== n.l2, n;
        }

        return __extends(t, e), t.prototype.apply = function (e) {
          var t = this;
          return (0, _tfjsCore.tidy)(function () {
            var n = (0, _tfjsCore.zeros)([1]);
            return t.hasL1 && (n = (0, _tfjsCore.add)(n, (0, _tfjsCore.sum)((0, _tfjsCore.mul)(t.l1, (0, _tfjsCore.abs)(e))))), t.hasL2 && (n = (0, _tfjsCore.add)(n, (0, _tfjsCore.sum)((0, _tfjsCore.mul)(t.l2, square(e))))), n.asScalar();
          });
        }, t.prototype.getConfig = function () {
          return {
            l1: this.l1,
            l2: this.l2
          };
        }, t.fromConfig = function (e, t) {
          return new e({
            l1: t.l1,
            l2: t.l2
          });
        }, t.className = "L1L2", t;
      }(Regularizer);

    function l1(e) {
      return assertObjectArgs(e), new L1L2({
        l1: null != e ? e.l1 : null,
        l2: 0
      });
    }

    function l2(e) {
      return assertObjectArgs(e), new L1L2({
        l2: null != e ? e.l2 : null,
        l1: 0
      });
    }

    _tfjsCore.serialization.registerClass(L1L2);

    var REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP = {
      l1l2: "L1L2"
    };

    function serializeRegularizer(e) {
      return serializeKerasObject(e);
    }

    function deserializeRegularizer(e, t) {
      return void 0 === t && (t = {}), deserializeKerasObject(e, _tfjsCore.serialization.SerializationMap.getMap().classNameMap, t, "regularizer");
    }

    function getRegularizer(e) {
      return null == e ? null : "string" == typeof e ? deserializeRegularizer({
        className: e in REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP ? REGULARIZER_IDENTIFIER_REGISTRY_SYMBOL_MAP[e] : e,
        config: {}
      }) : e instanceof Regularizer ? e : deserializeRegularizer(e);
    }

    var ReLU = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        return n.supportsMasking = !0, null != t && (n.maxValue = t.maxValue), n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        e = getExactlyOneTensor(e);
        var n = (0, _tfjsCore.relu)(e);
        return null != this.maxValue && (n = (0, _tfjsCore.clipByValue)(n, 0, this.maxValue)), n;
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = {
          maxValue: this.maxValue
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "ReLU", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(ReLU);

    var LeakyReLU = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        return n.DEFAULT_ALPHA = .3, null == t && (t = {}), n.alpha = null == t.alpha ? n.DEFAULT_ALPHA : t.alpha, n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = getExactlyOneTensor(e);
        return (0, _tfjsCore.leakyRelu)(n, this.alpha);
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = {
          alpha: this.alpha
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "LeakyReLU", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(LeakyReLU);

    var PReLU = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        if (n.DEFAULT_ALPHA_INITIALIZER = "zeros", null == t && (t = {}), n.supportsMasking = !0, n.alphaInitializer = getInitializer(t.alphaInitializer || n.DEFAULT_ALPHA_INITIALIZER), n.alphaRegularizer = getRegularizer(t.alphaRegularizer), n.alphaConstraint = getConstraint(t.alphaConstraint), null == t.sharedAxes) n.sharedAxes = null; else if (Array.isArray(t.sharedAxes)) n.sharedAxes = t.sharedAxes; else {
          if ("number" != typeof t.sharedAxes) throw new ValueError("Expected sharedAxes to be a number or an array of numbers, but got " + t.sharedAxes);
          n.sharedAxes = [t.sharedAxes];
        }
        return n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t = (e = getExactlyOneShape(e)).slice(1);
        if (null != this.sharedAxes) for (var n = 0, r = this.sharedAxes; n < r.length; n++) {
          t[(a = r[n]) - 1] = 1;
        }
        this.alpha = this.addWeight("alpha", t, "float32", this.alphaInitializer, this.alphaRegularizer, !0, this.alphaConstraint);
        var i = {};
        if (null != this.sharedAxes) for (var a = 1; a < e.length; ++a) i[a] = e[a];
        this.inputSpec = [new InputSpec({
          ndim: e.length,
          axes: i
        })], this.built = !0;
      }, t.prototype.call = function (e, t) {
        return e = getExactlyOneTensor(e), (0, _tfjsCore.prelu)(e, this.alpha.read());
      }, t.prototype.getConfig = function () {
        var t = {
          alphaInitializer: serializeInitializer(this.alphaInitializer),
          alphaRegularizer: serializeRegularizer(this.alphaRegularizer),
          alphaConstraint: serializeConstraint(this.alphaConstraint),
          sharedAxes: this.sharedAxes
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "PReLU", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(PReLU);

    var ELU = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        if (n.DEFAULT_ALPHA = 1, null == t && (t = {}), null != t.alpha && t.alpha !== n.DEFAULT_ALPHA) throw new NotImplementedError("Non-default alpha value (" + t.alpha + ") is not supported by the ELU layer yet.");
        return n.alpha = null == t.alpha ? n.DEFAULT_ALPHA : t.alpha, n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = getExactlyOneTensor(e);
        return (0, _tfjsCore.elu)(n);
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = {
          alpha: this.alpha
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "ELU", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(ELU);

    var ThresholdedReLU = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        return n.DEFAULT_THETA = 1, null == t && (t = {}), n.theta = null == t.theta ? n.DEFAULT_THETA : t.theta, n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = getExactlyOneTensor(e);
        return n.mul(cast$1(n.greater(this.theta), "float32"));
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = {
          theta: this.theta
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "ThresholdedReLU", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(ThresholdedReLU);

    var Softmax$1 = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        return n.DEFAULT_AXIS = 1, null == t && (t = {}), n.softmax = new Softmax().apply, n.axis = null == t.axis ? n.DEFAULT_AXIS : t.axis, n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = getExactlyOneTensor(e);
        return this.softmax(n, this.axis);
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = {
          axis: this.axis
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Softmax", t;
    }(Layer);

    function normalizeArray(e, t, n) {
      if ("number" == typeof e) return pyListRepeat(e, t);
      if (e.length !== t) throw new ValueError("The " + n + " argument must be an integer or tuple of " + t + " integers. Received: " + e.length + " elements.");

      for (var r = 0; r < t; ++r) {
        var i = e[r];
        if (!isInteger(i)) throw new ValueError("The " + n + " argument must be an integer or tuple of " + t + " integers. Received: " + JSON.stringify(e) + " including a non-integer number " + i);
      }

      return e;
    }

    function convOutputLength(e, t, n, r, i) {
      return void 0 === i && (i = 1), null == e ? e : (a = "same" === n ? e : e - (t + (t - 1) * (i - 1)) + 1, Math.floor((a + r - 1) / r));
      var a;
    }

    function deconvLength(e, t, n, r) {
      if (null == e) return null;
      if ("valid" === r) e = e * t + max$1([n - t, 0]); else {
        if ("same" !== r) throw new ValueError("Unsupport padding mode: " + r + ".");
        e *= t;
      }
      return e;
    }

    function preprocessConv2DInput(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return checkDataFormat(t), "channelsFirst" === t ? (0, _tfjsCore.transpose)(e, [0, 2, 3, 1]) : e;
      });
    }

    function preprocessConv3DInput(e, t) {
      return (0, _tfjsCore.tidy)(function () {
        return checkDataFormat(t), "channelsFirst" === t ? (0, _tfjsCore.transpose)(e, [0, 2, 3, 4, 1]) : e;
      });
    }

    function conv1dWithBias(e, t, n, r, i, a, o) {
      return void 0 === r && (r = 1), void 0 === i && (i = "valid"), void 0 === o && (o = 1), (0, _tfjsCore.tidy)(function () {
        if (null == a && (a = imageDataFormat()), checkDataFormat(a), 3 !== e.shape.length) throw new ValueError("The input of a conv1dWithBias operation should be 3, but is " + e.shape.length + " instead.");
        if (3 !== t.shape.length) throw new ValueError("The kernel for a conv1dWithBias operation should be 3, but is " + t.shape.length + " instead");
        if (null != n && 1 !== n.shape.length) throw new ValueError("The bias for a conv1dWithBias operation should be 1, but is " + t.shape.length + " instead");
        if ("channelsFirst" === a && (e = (0, _tfjsCore.transpose)(e, [0, 2, 1])), "causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
        var s = (0, _tfjsCore.conv1d)(e, t, r, "same" === i ? "same" : "valid", "NWC", o);
        return null != n && (s = biasAdd(s, n)), s;
      });
    }

    function conv2dWithBiasActivation(e, t, n, r, i, a, o, s) {
      return void 0 === r && (r = [1, 1]), void 0 === i && (i = "valid"), void 0 === s && (s = null), (0, _tfjsCore.tidy)(function () {
        if (null == a && (a = imageDataFormat()), checkDataFormat(a), 3 !== e.rank && 4 !== e.rank) throw new ValueError("conv2dWithBiasActivation expects input to be of rank 3 or 4, but received " + e.rank + ".");
        if (3 !== t.rank && 4 !== t.rank) throw new ValueError("conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received " + e.rank + ".");
        var l = preprocessConv2DInput(e, a);
        if ("causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
        return l = _tfjsCore.fused.conv2d({
          x: l,
          filter: t,
          strides: r,
          pad: "same" === i ? "same" : "valid",
          dilations: o,
          dataFormat: "NHWC",
          bias: n,
          activation: s
        }), "channelsFirst" === a && (l = (0, _tfjsCore.transpose)(l, [0, 3, 1, 2])), l;
      });
    }

    function conv3dWithBias(e, t, n, r, i, a, o) {
      return void 0 === r && (r = [1, 1, 1]), void 0 === i && (i = "valid"), (0, _tfjsCore.tidy)(function () {
        if (null == a && (a = imageDataFormat()), checkDataFormat(a), 4 !== e.rank && 5 !== e.rank) throw new ValueError("conv3dWithBias expects input to be of rank 4 or 5, but received " + e.rank + ".");
        if (4 !== t.rank && 5 !== t.rank) throw new ValueError("conv3dWithBias expects kernel to be of rank 4 or 5, but received " + e.rank + ".");
        var s = preprocessConv3DInput(e, a);
        if ("causal" === i) throw new NotImplementedError("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");
        return s = (0, _tfjsCore.conv3d)(s, t, r, "same" === i ? "same" : "valid", "NDHWC", o), null != n && (s = biasAdd(s, n)), "channelsFirst" === a && (s = (0, _tfjsCore.transpose)(s, [0, 4, 1, 2, 3])), s;
      });
    }

    _tfjsCore.serialization.registerClass(Softmax$1);

    var BaseConv = function (e) {
      function t(n, r) {
        var i = e.call(this, r) || this;
        if (i.bias = null, i.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", i.DEFAULT_BIAS_INITIALIZER = "zeros", t.verifyArgs(r), i.rank = n, assertPositiveInteger(i.rank, "rank"), 1 !== i.rank && 2 !== i.rank && 3 !== i.rank) throw new NotImplementedError("Convolution layer for rank other than 1, 2, or 3 (" + i.rank + ") is not implemented yet.");
        if (i.kernelSize = normalizeArray(r.kernelSize, n, "kernelSize"), i.strides = normalizeArray(null == r.strides ? 1 : r.strides, n, "strides"), i.padding = null == r.padding ? "valid" : r.padding, checkPaddingMode(i.padding), i.dataFormat = null == r.dataFormat ? "channelsLast" : r.dataFormat, checkDataFormat(i.dataFormat), i.activation = getActivation(r.activation), i.useBias = null == r.useBias || r.useBias, i.biasInitializer = getInitializer(r.biasInitializer || i.DEFAULT_BIAS_INITIALIZER), i.biasConstraint = getConstraint(r.biasConstraint), i.biasRegularizer = getRegularizer(r.biasRegularizer), i.activityRegularizer = getRegularizer(r.activityRegularizer), i.dilationRate = normalizeArray(null == r.dilationRate ? 1 : r.dilationRate, n, "dilationRate"), 1 === i.rank && Array.isArray(i.dilationRate) && 1 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or an array of a single number for 1D convolution, but received " + JSON.stringify(i.dilationRate));

        if (2 === i.rank) {
          if ("number" == typeof i.dilationRate) i.dilationRate = [i.dilationRate, i.dilationRate]; else if (2 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or array of two numbers for 2D convolution, but received " + JSON.stringify(i.dilationRate));
        } else if (3 === i.rank) if ("number" == typeof i.dilationRate) i.dilationRate = [i.dilationRate, i.dilationRate, i.dilationRate]; else if (3 !== i.dilationRate.length) throw new ValueError("dilationRate must be a number or array of three numbers for 3D convolution, but received " + JSON.stringify(i.dilationRate));

        return i;
      }

      return __extends(t, e), t.verifyArgs = function (e) {
        if (assert("kernelSize" in e, "required key 'kernelSize' not in config"), "number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 3)) throw new ValueError("BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received " + JSON.stringify(e.kernelSize) + ".");
      }, t.prototype.getConfig = function () {
        var t = {
          kernelSize: this.kernelSize,
          strides: this.strides,
          padding: this.padding,
          dataFormat: this.dataFormat,
          dilationRate: this.dilationRate,
          activation: serializeActivation(this.activation),
          useBias: this.useBias,
          biasInitializer: serializeInitializer(this.biasInitializer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          biasConstraint: serializeConstraint(this.biasConstraint)
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t;
    }(Layer),
      Conv = function (e) {
        function t(n, r) {
          var i = e.call(this, n, r) || this;
          return i.kernel = null, t.verifyArgs(r), i.filters = r.filters, assertPositiveInteger(i.filters, "filters"), i.kernelInitializer = getInitializer(r.kernelInitializer || i.DEFAULT_KERNEL_INITIALIZER), i.kernelConstraint = getConstraint(r.kernelConstraint), i.kernelRegularizer = getRegularizer(r.kernelRegularizer), i;
        }

        return __extends(t, e), t.prototype.build = function (e) {
          var t;
          e = getExactlyOneShape(e);
          var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
          if (null == e[n]) throw new ValueError("The channel dimension of the input should be defined. Found " + e[n]);
          var r = e[n],
            i = this.kernelSize.concat([r, this.filters]);
          this.kernel = this.addWeight("kernel", i, null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [{
            ndim: this.rank + 2,
            axes: (t = {}, t[n] = r, t)
          }], this.built = !0;
        }, t.prototype.call = function (e, t) {
          var n = this;
          return (0, _tfjsCore.tidy)(function () {
            var t;
            e = getExactlyOneTensor(e);
            var r = null == n.bias ? null : n.bias.read(),
              i = mapActivationToFusedKernel(n.activation.getClassName());
            if (null != i && 2 === n.rank) t = conv2dWithBiasActivation(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate, i); else {
              if (1 === n.rank) t = conv1dWithBias(e, n.kernel.read(), r, n.strides[0], n.padding, n.dataFormat, n.dilationRate[0]); else if (2 === n.rank) t = conv2dWithBiasActivation(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate); else {
                if (3 !== n.rank) throw new NotImplementedError("convolutions greater than 3D are not implemented yet.");
                t = conv3dWithBias(e, n.kernel.read(), r, n.strides, n.padding, n.dataFormat, n.dilationRate);
              }
              null != n.activation && (t = n.activation.apply(t));
            }
            return t;
          });
        }, t.prototype.computeOutputShape = function (e) {
          e = getExactlyOneShape(e);

          for (var t = [], n = "channelsLast" === this.dataFormat ? e.slice(1, e.length - 1) : e.slice(2), r = 0; r < n.length; ++r) {
            var i = convOutputLength(n[r], this.kernelSize[r], this.padding, this.strides[r], "number" == typeof this.dilationRate ? this.dilationRate : this.dilationRate[r]);
            t.push(i);
          }

          var a = [e[0]];
          return "channelsLast" === this.dataFormat ? (a = a.concat(t)).push(this.filters) : (a.push(this.filters), a = a.concat(t)), a;
        }, t.prototype.getConfig = function () {
          var t = {
            filters: this.filters,
            kernelInitializer: serializeInitializer(this.kernelInitializer),
            kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
            kernelConstraint: serializeConstraint(this.kernelConstraint)
          },
            n = e.prototype.getConfig.call(this);
          return Object.assign(t, n), t;
        }, t.verifyArgs = function (e) {
          if (!("filters" in e) || "number" != typeof e.filters || e.filters < 1) throw new ValueError("Convolution layer expected config.filters to be a 'number' > 0 but got " + JSON.stringify(e.filters));
        }, t;
      }(BaseConv),
      Conv2D = function (e) {
        function t(n) {
          var r = e.call(this, 2, n) || this;
          return t.verifyArgs(n), r;
        }

        return __extends(t, e), t.prototype.getConfig = function () {
          var t = e.prototype.getConfig.call(this);
          return delete t.rank, t;
        }, t.verifyArgs = function (e) {
          if ("number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 2)) throw new ValueError("Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received " + JSON.stringify(e.kernelSize) + ".");
        }, t.className = "Conv2D", t;
      }(Conv);

    _tfjsCore.serialization.registerClass(Conv2D);

    var Conv3D = function (e) {
      function t(n) {
        var r = e.call(this, 3, n) || this;
        return t.verifyArgs(n), r;
      }

      return __extends(t, e), t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this);
        return delete t.rank, t;
      }, t.verifyArgs = function (e) {
        if ("number" != typeof e.kernelSize && (!Array.isArray(e.kernelSize) || 1 !== e.kernelSize.length && 3 !== e.kernelSize.length)) throw new ValueError("Conv3D expects config.kernelSize to be number or [number, number, number], but received " + JSON.stringify(e.kernelSize) + ".");
      }, t.className = "Conv3D", t;
    }(Conv);

    _tfjsCore.serialization.registerClass(Conv3D);

    var Conv2DTranspose = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        if (n.inputSpec = [new InputSpec({
          ndim: 4
        })], "same" !== n.padding && "valid" !== n.padding) throw new ValueError("Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode " + n.padding);
        return n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t;
        if (4 !== (e = getExactlyOneShape(e)).length) throw new ValueError("Input should have rank 4; Received input shape: " + JSON.stringify(e));
        var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
        if (null == e[n]) throw new ValueError("The channel dimension of the inputs should be defined. Found `None`.");
        var r = e[n],
          i = this.kernelSize.concat([this.filters, r]);
        this.kernel = this.addWeight("kernel", i, "float32", this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [new InputSpec({
          ndim: 4,
          axes: (t = {}, t[n] = r, t)
        })], this.built = !0;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var t = getExactlyOneTensor(e);
          if (4 !== t.shape.length) throw new ValueError("Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-" + t.shape.length);
          var r,
            i,
            a = t.shape,
            o = a[0];
          "channelsFirst" === n.dataFormat ? (r = 2, i = 3) : (r = 1, i = 2);
          var s = a[r],
            l = a[i],
            u = n.kernelSize[0],
            c = n.kernelSize[1],
            p = n.strides[0],
            h = n.strides[1],
            d = [o, deconvLength(s, p, u, n.padding), deconvLength(l, h, c, n.padding), n.filters];
          "channelsLast" !== n.dataFormat && (t = (0, _tfjsCore.transpose)(t, [0, 2, 3, 1]));
          var f = (0, _tfjsCore.conv2dTranspose)(t, n.kernel.read(), d, n.strides, n.padding);
          return "channelsLast" !== n.dataFormat && (f = (0, _tfjsCore.transpose)(f, [0, 3, 1, 2])), null != n.bias && (f = biasAdd(f, n.bias.read(), n.dataFormat)), null != n.activation && (f = n.activation.apply(f)), f;
        });
      }, t.prototype.computeOutputShape = function (e) {
        var t,
          n,
          r,
          i = (e = getExactlyOneShape(e)).slice();
        "channelsFirst" === this.dataFormat ? (t = 1, n = 2, r = 3) : (t = 3, n = 1, r = 2);
        var a = this.kernelSize[0],
          o = this.kernelSize[1],
          s = this.strides[0],
          l = this.strides[1];
        return i[t] = this.filters, i[n] = deconvLength(i[n], s, a, this.padding), i[r] = deconvLength(i[r], l, o, this.padding), i;
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this);
        return delete t.dilationRate, t;
      }, t.className = "Conv2DTranspose", t;
    }(Conv2D);

    _tfjsCore.serialization.registerClass(Conv2DTranspose);

    var SeparableConv = function (e) {
      function t(t, n) {
        var r = e.call(this, t, n) || this;
        if (r.DEFAULT_DEPTHWISE_INITIALIZER = "glorotUniform", r.DEFAULT_POINTWISE_INITIALIZER = "glorotUniform", r.depthwiseKernel = null, r.pointwiseKernel = null, null == n.filters) throw new ValueError("The `filters` configuration field is required by SeparableConv, but is unspecified.");
        if (null != n.kernelInitializer || null != n.kernelRegularizer || null != n.kernelConstraint) throw new ValueError("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");
        if (null != n.padding && "same" !== n.padding && "valid" !== n.padding) throw new ValueError("SeparableConv" + r.rank + "D supports only padding modes: 'same' and 'valid', but received " + JSON.stringify(n.padding));
        return r.depthMultiplier = null == n.depthMultiplier ? 1 : n.depthMultiplier, r.depthwiseInitializer = getInitializer(n.depthwiseInitializer || r.DEFAULT_DEPTHWISE_INITIALIZER), r.depthwiseRegularizer = getRegularizer(n.depthwiseRegularizer), r.depthwiseConstraint = getConstraint(n.depthwiseConstraint), r.pointwiseInitializer = getInitializer(n.depthwiseInitializer || r.DEFAULT_POINTWISE_INITIALIZER), r.pointwiseRegularizer = getRegularizer(n.pointwiseRegularizer), r.pointwiseConstraint = getConstraint(n.pointwiseConstraint), r;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t;
        if ((e = getExactlyOneShape(e)).length < this.rank + 2) throw new ValueError("Inputs to SeparableConv" + this.rank + "D should have rank " + (this.rank + 2) + ", but received input shape: " + JSON.stringify(e));
        var n = "channelsFirst" === this.dataFormat ? 1 : e.length - 1;
        if (null == e[n] || e[n] < 0) throw new ValueError("The channel dimension of the inputs should be defined, but found " + JSON.stringify(e[n]));

        for (var r = e[n], i = this.kernelSize.concat([r, this.depthMultiplier]), a = [], o = 0; o < this.rank; ++o) a.push(1);

        a.push(r * this.depthMultiplier, this.filters);
        this.depthwiseKernel = this.addWeight("depthwise_kernel", i, "float32", this.depthwiseInitializer, this.depthwiseRegularizer, !0, this.depthwiseConstraint), this.pointwiseKernel = this.addWeight("pointwise_kernel", a, "float32", this.pointwiseInitializer, this.pointwiseRegularizer, !0, this.pointwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.inputSpec = [new InputSpec({
          ndim: this.rank + 2,
          axes: (t = {}, t[n] = r, t)
        })], this.built = !0;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var t;
          if (e = getExactlyOneTensor(e), 1 === n.rank) throw new NotImplementedError("1D separable convolution is not implemented yet.");
          return 2 === n.rank && ("channelsFirst" === n.dataFormat && (e = (0, _tfjsCore.transpose)(e, [0, 2, 3, 1])), t = (0, _tfjsCore.separableConv2d)(e, n.depthwiseKernel.read(), n.pointwiseKernel.read(), n.strides, n.padding, n.dilationRate, "NHWC")), n.useBias && (t = biasAdd(t, n.bias.read(), n.dataFormat)), null != n.activation && (t = n.activation.apply(t)), "channelsFirst" === n.dataFormat && (t = (0, _tfjsCore.transpose)(t, [0, 3, 1, 2])), t;
        });
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this);
        return delete t.rank, delete t.kernelInitializer, delete t.kernelRegularizer, delete t.kernelConstraint, t.depthwiseInitializer = serializeInitializer(this.depthwiseInitializer), t.pointwiseInitializer = serializeInitializer(this.pointwiseInitializer), t.depthwiseRegularizer = serializeRegularizer(this.depthwiseRegularizer), t.pointwiseRegularizer = serializeRegularizer(this.pointwiseRegularizer), t.depthwiseConstraint = serializeConstraint(this.depthwiseConstraint), t.pointwiseConstraint = serializeConstraint(this.pointwiseConstraint), t;
      }, t.className = "SeparableConv", t;
    }(Conv),
      SeparableConv2D = function (e) {
        function t(t) {
          return e.call(this, 2, t) || this;
        }

        return __extends(t, e), t.className = "SeparableConv2D", t;
      }(SeparableConv);

    _tfjsCore.serialization.registerClass(SeparableConv2D);

    var Conv1D = function (e) {
      function t(n) {
        var r = e.call(this, 1, n) || this;
        return t.verifyArgs(n), r.inputSpec = [{
          ndim: 3
        }], r;
      }

      return __extends(t, e), t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this);
        return delete t.rank, delete t.dataFormat, t;
      }, t.verifyArgs = function (e) {
        if ("number" != typeof e.kernelSize && !checkArrayTypeAndLength(e.kernelSize, "number", 1, 1)) throw new ValueError("Conv1D expects config.kernelSize to be number or number[] with length 1, but received " + JSON.stringify(e.kernelSize) + ".");
      }, t.className = "Conv1D", t;
    }(Conv);

    _tfjsCore.serialization.registerClass(Conv1D);

    var Cropping2D = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return "number" == typeof t.cropping ? n.cropping = [[t.cropping, t.cropping], [t.cropping, t.cropping]] : "number" == typeof t.cropping[0] ? n.cropping = [[t.cropping[0], t.cropping[0]], [t.cropping[1], t.cropping[1]]] : n.cropping = t.cropping, n.dataFormat = void 0 === t.dataFormat ? "channelsLast" : t.dataFormat, n.inputSpec = [{
          ndim: 4
        }], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return "channelsFirst" === this.dataFormat ? [e[0], e[1], e[2] - this.cropping[0][0] - this.cropping[0][1], e[3] - this.cropping[1][0] - this.cropping[1][1]] : [e[0], e[1] - this.cropping[0][0] - this.cropping[0][1], e[2] - this.cropping[1][0] - this.cropping[1][1], e[3]];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return e = getExactlyOneTensor(e), "channelsLast" === n.dataFormat ? sliceAlongAxis(sliceAlongAxis(e, n.cropping[0][0], e.shape[1] - n.cropping[0][0] - n.cropping[0][1], 2), n.cropping[1][0], e.shape[2] - n.cropping[1][1] - n.cropping[1][0], 3) : sliceAlongAxis(sliceAlongAxis(e, n.cropping[0][0], e.shape[2] - n.cropping[0][0] - n.cropping[0][1], 3), n.cropping[1][0], e.shape[3] - n.cropping[1][1] - n.cropping[1][0], 4);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          cropping: this.cropping,
          dataFormat: this.dataFormat
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Cropping2D", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Cropping2D);

    var UpSampling2D = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.DEFAULT_SIZE = [2, 2], n.inputSpec = [{
          ndim: 4
        }], n.size = null == t.size ? n.DEFAULT_SIZE : t.size, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        if ("channelsFirst" === this.dataFormat) {
          var t = null == e[2] ? null : this.size[0] * e[2],
            n = null == e[3] ? null : this.size[1] * e[3];
          return [e[0], e[1], t, n];
        }

        t = null == e[1] ? null : this.size[0] * e[1], n = null == e[2] ? null : this.size[1] * e[2];
        return [e[0], t, n, e[3]];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var t = getExactlyOneTensor(e),
            r = t.shape;

          if ("channelsFirst" === n.dataFormat) {
            t = (0, _tfjsCore.transpose)(t, [0, 2, 3, 1]);
            var i = n.size[0] * r[2],
              a = n.size[1] * r[3],
              o = t.resizeNearestNeighbor([i, a]);
            return (0, _tfjsCore.transpose)(o, [0, 3, 1, 2]);
          }

          i = n.size[0] * r[1], a = n.size[1] * r[2];
          return t.resizeNearestNeighbor([i, a]);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          size: this.size,
          dataFormat: this.dataFormat
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "UpSampling2D", t;
    }(Layer);

    function depthwiseConv2d$1(e, t, n, r, i, a) {
      return void 0 === n && (n = [1, 1]), void 0 === r && (r = "valid"), (0, _tfjsCore.tidy)(function () {
        null == i && (i = imageDataFormat()), checkDataFormat(i);
        var o = preprocessConv2DInput(e, i);
        if (4 !== e.rank) throw new ValueError("Input for depthwiseConv2d is required to be 4-D, but is instead " + e.rank + "-D");
        if (4 !== t.rank) throw new ValueError("depthwiseKernel is required to be 4-D, but is instead " + t.rank + "-D");
        return o = (0, _tfjsCore.depthwiseConv2d)(o, t, n, "same" === r ? "same" : "valid", "NHWC", a), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 3, 1, 2])), o;
      });
    }

    _tfjsCore.serialization.registerClass(UpSampling2D);

    var DepthwiseConv2D = function (e) {
      function t(t) {
        var n = e.call(this, 2, t) || this;
        return n.depthwiseKernel = null, n.depthMultiplier = null == t.depthMultiplier ? 1 : t.depthMultiplier, n.depthwiseInitializer = getInitializer(t.depthwiseInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.depthwiseConstraint = getConstraint(t.depthwiseConstraint), n.depthwiseRegularizer = getRegularizer(t.depthwiseRegularizer), n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        if ((e = getExactlyOneShape(e)).length < 4) throw new ValueError("Inputs to DepthwiseConv2D should have rank 4. Received input shape: " + JSON.stringify(e) + ".");
        var t = "channelsFirst" === this.dataFormat ? 1 : 3;
        if (null == e[t] || e[t] < 0) throw new ValueError("The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not (" + e[t] + ").");
        var n = e[t],
          r = [this.kernelSize[0], this.kernelSize[1], n, this.depthMultiplier];
        this.depthwiseKernel = this.addWeight("depthwise_kernel", r, null, this.depthwiseInitializer, this.depthwiseRegularizer, !0, this.depthwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [n * this.depthMultiplier], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var t = depthwiseConv2d$1(e = getExactlyOneTensor(e), n.depthwiseKernel.read(), n.strides, n.padding, n.dataFormat, null);
          return n.useBias && (t = biasAdd(t, n.bias.read(), n.dataFormat)), null != n.activation && (t = n.activation.apply(t)), t;
        });
      }, t.prototype.computeOutputShape = function (e) {
        e = getExactlyOneShape(e);
        var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
          n = "channelsFirst" === this.dataFormat ? e[3] : e[2],
          r = "channelsFirst" === this.dataFormat ? e[1] * this.depthMultiplier : e[3] * this.depthMultiplier,
          i = convOutputLength(t, this.kernelSize[0], this.padding, this.strides[0]),
          a = convOutputLength(n, this.kernelSize[1], this.padding, this.strides[1]);
        return "channelsFirst" === this.dataFormat ? [e[0], r, i, a] : [e[0], i, a, r];
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this);
        return t.depthMultiplier = this.depthMultiplier, t.depthwiseInitializer = serializeInitializer(this.depthwiseInitializer), t.depthwiseRegularizer = serializeRegularizer(this.depthwiseRegularizer), t.depthwiseConstraint = serializeConstraint(this.depthwiseRegularizer), t;
      }, t.className = "DepthwiseConv2D", t;
    }(BaseConv);

    _tfjsCore.serialization.registerClass(DepthwiseConv2D);

    var Dropout = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.rate = Math.max(Math.min(t.rate, 1), 0), n.noiseShape = t.noiseShape, n.seed = t.seed, n.supportsMasking = !0, n;
      }

      return __extends(t, e), t.prototype.getNoiseShape = function (e) {
        if (null == this.noiseShape) return this.noiseShape;

        for (var t = e.shape, n = [], r = 0; r < this.noiseShape.length; ++r) n.push(null == this.noiseShape[r] ? t[r] : this.noiseShape[r]);

        return n;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e);

          if (0 < n.rate && n.rate < 1) {
            var i = null != t.training && t.training,
              a = n.getNoiseShape(r);
            return inTrainPhase(function () {
              return dropout$1(r, n.rate, a, n.seed);
            }, function () {
              return r;
            }, i);
          }

          return e;
        });
      }, t.prototype.getConfig = function () {
        var t = {
          rate: this.rate,
          noiseShape: this.noiseShape,
          seed: this.seed
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.prototype.dispose = function () {
        return e.prototype.dispose.call(this);
      }, t.className = "Dropout", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Dropout);

    var Dense = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;

        if (n.activation = null, n.useBias = !0, n.kernel = null, n.bias = null, n.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", n.DEFAULT_BIAS_INITIALIZER = "zeros", null == t.batchInputShape && null == t.inputShape && null != t.inputDim) {
          var r = null;
          null != t.batchSize && (r = t.batchSize), n.batchInputShape = [r, t.inputDim];
        }

        return n.units = t.units, assertPositiveInteger(n.units, "units"), n.activation = getActivation(t.activation), null != t.useBias && (n.useBias = t.useBias), n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelConstraint = getConstraint(t.kernelConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.activityRegularizer = getRegularizer(t.activityRegularizer), n.supportsMasking = !0, n.inputSpec = [{
          minNDim: 2
        }], n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t,
          n = (e = getExactlyOneShape(e))[e.length - 1];
        null == this.kernel && (this.kernel = this.addWeight("kernel", [n, this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint))), this.inputSpec = [{
          minNDim: 2,
          axes: (t = {}, t[-1] = n, t)
        }], this.built = !0;
      }, t.prototype.computeOutputShape = function (e) {
        var t = (e = getExactlyOneShape(e)).slice();
        return t[t.length - 1] = this.units, t;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r,
            i = getExactlyOneTensor(e),
            a = mapActivationToFusedKernel(n.activation.getClassName());
          return null != a ? r = dot(i, n.kernel.read(), a, n.bias ? n.bias.read() : null) : (r = dot(i, n.kernel.read()), null != n.bias && (r = biasAdd(r, n.bias.read())), null != n.activation && (r = n.activation.apply(r))), r;
        });
      }, t.prototype.getConfig = function () {
        var t = {
          units: this.units,
          activation: serializeActivation(this.activation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          biasConstraint: serializeConstraint(this.biasConstraint)
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Dense", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Dense);

    var Flatten = function (e) {
      function t(t) {
        var n = e.call(this, t || {}) || this;
        return n.inputSpec = [{
          minNDim: 3
        }], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        for (var t = 0, n = (e = getExactlyOneShape(e)).slice(1); t < n.length; t++) {
          if (null == n[t]) throw new ValueError('The shape of the input to "Flatten" is not fully defined (got ' + e.slice(1) + '). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.');
        }

        return [e[0], arrayProd(e, 1)];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return n.invokeCallHook(e, t), batchFlatten(getExactlyOneTensor(e));
        });
      }, t.className = "Flatten", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Flatten);

    var Activation$1 = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.supportsMasking = !0, n.activation = getActivation(t.activation), n;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e);
          return n.activation.apply(r);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          activation: serializeActivation(this.activation)
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Activation", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Activation$1);

    var RepeatVector = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.n = t.n, n.inputSpec = [{
          ndim: 2
        }], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return [e[0], this.n, e[1]];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return repeat(e = getExactlyOneTensor(e), n.n);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          n: this.n
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "RepeatVector", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(RepeatVector);

    var Reshape = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        n.targetShape = t.targetShape;

        for (var r = 0; r < n.targetShape.length; ++r) n.isUnknown(n.targetShape[r]) && (n.targetShape[r] = null);

        return n;
      }

      return __extends(t, e), t.prototype.isUnknown = function (e) {
        return e < 0 || null == e;
      }, t.prototype.fixUnknownDimension = function (e, t) {
        for (var n = "Total size of new array must be unchanged.", r = t.slice(), i = 1, a = null, o = 0; o < r.length; ++o) {
          var s = r[o];

          if (this.isUnknown(s)) {
            if (null !== a) throw new ValueError("Can only specifiy one unknown dimension.");
            a = o;
          } else i *= s;
        }

        var l = arrayProd(e);

        if (null !== a) {
          if (0 === i || l % i != 0) throw new ValueError(n);
          r[a] = l / i;
        } else if (l !== i) throw new ValueError(n);

        return r;
      }, t.prototype.computeOutputShape = function (e) {
        for (var t = !1, n = 0; n < e.length; ++n) if (this.isUnknown(e[n])) {
          t = !0;
          break;
        }

        return t ? e.slice(0, 1).concat(this.targetShape) : e.slice(0, 1).concat(this.fixUnknownDimension(e.slice(1), this.targetShape));
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e),
            i = r.shape,
            a = i.slice(0, 1).concat(n.fixUnknownDimension(i.slice(1), n.targetShape));
          return r.reshape(a);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          targetShape: this.targetShape
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Reshape", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Reshape);

    var Permute = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        if (null == t.dims) throw new Error("Required configuration field `dims` is missing during Permute constructor call.");
        if (!Array.isArray(t.dims)) throw new Error("Permute constructor requires `dims` to be an Array, but received " + t.dims + " instead.");
        var r = range(1, t.dims.length + 1);
        if (!_tfjsCore.util.arraysEqual(t.dims.slice().sort(), r)) throw new Error("Invalid permutation `dims`: " + JSON.stringify(t.dims) + " `dims` must contain consecutive integers starting from 1.");
        return n.dims = t.dims, n.dimsIncludingBatch = [0].concat(n.dims), n.inputSpec = [new InputSpec({
          ndim: n.dims.length + 1
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        var t = (e = getExactlyOneShape(e)).slice();
        return this.dims.forEach(function (n, r) {
          t[r + 1] = e[n];
        }), t;
      }, t.prototype.call = function (e, t) {
        return (0, _tfjsCore.transpose)(getExactlyOneTensor(e), this.dimsIncludingBatch);
      }, t.prototype.getConfig = function () {
        var t = {
          dims: this.dims
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Permute", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Permute);

    var Masking = function (e) {
      function t(t) {
        var n = e.call(this, null == t ? {} : t) || this;
        return n.supportsMasking = !0, n.maskValue = null != t ? null == t.maskValue ? 0 : t.maskValue : 0, n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this),
          n = {
            maskValue: this.maskValue
          };
        return Object.assign(n, t), n;
      }, t.prototype.computeMask = function (e, t) {
        var n = getExactlyOneTensor(e);
        return (0, _tfjsCore.any)((0, _tfjsCore.notEqual)(n, this.maskValue), -1);
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e),
            i = (0, _tfjsCore.any)((0, _tfjsCore.notEqual)(r, n.maskValue), -1, !0);
          return r.mul(i.asType(r.dtype));
        });
      }, t.className = "Masking", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Masking);

    var Embedding = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;

        if (n.embeddings = null, n.DEFAULT_EMBEDDINGS_INITIALIZER = "randomUniform", null == t.batchInputShape && null == t.inputShape) {
          var r = null;
          null != t.batchSize && (r = t.batchSize), null == t.inputLength ? n.batchInputShape = [r, null] : n.batchInputShape = [r].concat(toList(t.inputLength));
        }

        return n.inputDim = t.inputDim, assertPositiveInteger(n.inputDim, "inputDim"), n.outputDim = t.outputDim, assertPositiveInteger(n.outputDim, "outputDim"), n.embeddingsInitializer = getInitializer(t.embeddingsInitializer || n.DEFAULT_EMBEDDINGS_INITIALIZER), n.embeddingsRegularizer = getRegularizer(t.embeddingsRegularizer), n.activityRegularizer = getRegularizer(t.activityRegularizer), n.embeddingsConstraint = getConstraint(t.embeddingsConstraint), n.maskZero = t.maskZero, n.supportsMasking = t.maskZero, n.inputLength = t.inputLength, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        this.embeddings = this.addWeight("embeddings", [this.inputDim, this.outputDim], this.dtype, this.embeddingsInitializer, this.embeddingsRegularizer, !0, this.embeddingsConstraint), this.built = !0;
      }, t.prototype.warnOnIncompatibleInputShape = function (e) { }, t.prototype.computeMask = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return n.maskZero ? (e = getExactlyOneTensor(e), (0, _tfjsCore.notEqual)(e, (0, _tfjsCore.zerosLike)(e))) : null;
        });
      }, t.prototype.computeOutputShape = function (e) {
        if (e = getExactlyOneShape(e), null == this.inputLength) return e.concat([this.outputDim]);
        var t = toList(this.inputLength);
        if (t.length !== e.length - 1) throw new ValueError('"inputLength" is ' + this.inputLength + ", but received input shape has shape " + e);

        for (var n = 0, r = 0; r < t.length; ++r) {
          var i = t[r],
            a = e[r + 1];
          if (null != i && null != a && i !== a) throw new ValueError('"inputLength" is ' + this.inputLength + ", but received input shape has shape " + e);
          null == i && (t[n] = a), n++;
        }

        return [e[0]].concat(t, [this.outputDim]);
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e);
          return "int32" !== r.dtype && (r = cast$1(r, "int32")), gather$1(n.embeddings.read(), r.as1D()).reshape(getExactlyOneShape(n.computeOutputShape(r.shape)));
        });
      }, t.prototype.getConfig = function () {
        var t = {
          inputDim: this.inputDim,
          outputDim: this.outputDim,
          embeddingsInitializer: serializeInitializer(this.embeddingsInitializer),
          embeddingsRegularizer: serializeRegularizer(this.embeddingsRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          embeddingsConstraint: serializeConstraint(this.embeddingsConstraint),
          maskZero: this.maskZero,
          inputLength: this.inputLength
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Embedding", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(Embedding);

    var Merge = function (e) {
      function t(t) {
        var n = e.call(this, t || {}) || this;
        return n.supportsMasking = !0, n;
      }

      return __extends(t, e), t.prototype.mergeFunction = function (e) {
        throw new NotImplementedError();
      }, t.prototype.computeElementwiseOpOutputShape = function (e, t) {
        if (null == e || null == t) return null;
        if (e.length < t.length) return this.computeElementwiseOpOutputShape(t, e);
        if (0 === t.length) return e;

        for (var n = e.slice(0, e.length - t.length), r = 0; r < t.length; ++r) {
          var i = e[e.length - t.length + r],
            a = t[r];
          if (null == i || null == a || i < 0 || a < 0) n.push(null); else if (1 === i) n.push(a); else if (1 === a) n.push(i); else {
            if (i !== a) throw new ValueError("Operands could not be broadcast together with shapes " + JSON.stringify(e) + " " + JSON.stringify(t));
            n.push(i);
          }
        }

        return n;
      }, t.prototype.build = function (e) {
        if (Array.isArray(e) && !Array.isArray(e[0]) && (e = [getExactlyOneShape(e)]), (e = e).length < 2) throw new ValueError("A merge layer should be called on an Array of at least 2 inputs. Got " + e.length + " input(s).");

        for (var t = [], n = 0, r = e; n < r.length; n++) {
          null != (o = r[n]) && null !== o[0] && t.push(o[0]);
        }

        if ((t = unique(t)).length > 1) throw new ValueError("Can not merge tensors with different batch sizes. Got tensors with shapes: " + JSON.stringify(e) + ".");

        for (var i = null == e[0] ? null : e[0].slice(1), a = 1; a < e.length; ++a) {
          var o = null == e[a] ? null : e[a].slice(1);
          i = this.computeElementwiseOpOutputShape(i, o);
        }

        var s = e.map(function (e) {
          return e.length;
        });
        -1 === e.indexOf(null) && 1 === unique(s).length ? this.reshapeRequired = !1 : this.reshapeRequired = !0;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          if (e = e, n.reshapeRequired) {
            var t = [],
              r = e.map(function (e) {
                return e.rank;
              });

            if (-1 === r.indexOf(null)) {
              for (var i = max$1(r), a = 0, o = e; a < o.length; a++) {
                for (var s = (h = o[a]).rank, l = 0; l < i - s; ++l) h = expandDims$1(h, 1);

                t.push(h);
              }

              return n.mergeFunction(t);
            }

            for (var u = !1, c = 0, p = e; c < p.length; c++) {
              var h;

              if (null == (s = (h = p[c]).rank)) {
                var d = h.shape,
                  f = d[0],
                  g = d.slice(1).concat([f]),
                  m = h.reshape([f].concat(arrayProd(d.slice(1))));
                m = (m = (0, _tfjsCore.transpose)(m, [1, 0])).reshape(g), t.push(m), u = !0;
              } else if (s > 1) {
                var y = range(1, s).concat([0]);
                t.push((0, _tfjsCore.transpose)(h, y)), u = !0;
              } else t.push(h);
            }

            var v = n.mergeFunction(t),
              b = v.rank;
            if (u) if (null == b) {
              var w = v.shape;
              g = [f = w[w.length - 1]].concat(w.slice(0, w.length - 1));
              v = (0, _tfjsCore.transpose)(v.reshape([-1, f]), [1, 0]).reshape(g);
            } else if (b > 1) {
              y = [b - 1].concat(range(0, b - 1));
              v = (0, _tfjsCore.transpose)(v, y);
            }
            return v;
          }

          return n.mergeFunction(e);
        });
      }, t.prototype.computeOutputShape = function (e) {
        var t;
        t = null == (e = e)[0] ? null : e[0].slice(1);

        for (var n = 1; n < e.length; ++n) {
          var r = null == e[n] ? null : e[n].slice(1);
          t = this.computeElementwiseOpOutputShape(t, r);
        }

        for (var i = [], a = 0, o = e; a < o.length; a++) {
          null != (r = o[a]) && null !== r[0] && i.push(r[0]);
        }

        return t = 1 === (i = unique(i)).length ? i.concat(t) : [null].concat(t);
      }, t.prototype.computeMask = function (e, t) {
        return (0, _tfjsCore.tidy)(function () {
          if (null == t) return null;
          if (!Array.isArray(t)) throw new ValueError("`mask` should be an Array");
          if (!Array.isArray(e)) throw new ValueError("`inputs` should be an Array");
          if (t.length !== e.length) throw new ValueError("The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths (" + e.length + " vs " + t.length + ")");
          if (t.every(function (e) {
            return null == e;
          })) return null;

          for (var n = (t = t.map(function (e) {
            return null == e ? e : (0, _tfjsCore.expandDims)(e, 0);
          }))[0], r = 1; r < t.length - 1; ++r) n = (0, _tfjsCore.logicalAnd)(n, t[r]);

          return n;
        });
      }, t;
    }(Layer),
      Add = function (e) {
        function t(t) {
          return e.call(this, t) || this;
        }

        return __extends(t, e), t.prototype.mergeFunction = function (e) {
          return (0, _tfjsCore.tidy)(function () {
            for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.add)(t, e[n]);

            return t;
          });
        }, t.className = "Add", t;
      }(Merge);

    _tfjsCore.serialization.registerClass(Add);

    var Multiply = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.mergeFunction = function (e) {
        return (0, _tfjsCore.tidy)(function () {
          for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.mul)(t, e[n]);

          return t;
        });
      }, t.className = "Multiply", t;
    }(Merge);

    _tfjsCore.serialization.registerClass(Multiply);

    var Average = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.mergeFunction = function (e) {
        return (0, _tfjsCore.tidy)(function () {
          for (var t = e[0].clone(), n = 1; n < e.length; ++n) t = (0, _tfjsCore.add)(t, e[n]);

          return (0, _tfjsCore.mul)(1 / e.length, t);
        });
      }, t.className = "Average", t;
    }(Merge);

    _tfjsCore.serialization.registerClass(Average);

    var Maximum = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.mergeFunction = function (e) {
        return (0, _tfjsCore.tidy)(function () {
          for (var t = e[0], n = 1; n < e.length; ++n) t = (0, _tfjsCore.maximum)(t, e[n]);

          return t;
        });
      }, t.className = "Maximum", t;
    }(Merge);

    _tfjsCore.serialization.registerClass(Maximum);

    var Minimum = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.mergeFunction = function (e) {
        return (0, _tfjsCore.tidy)(function () {
          for (var t = e[0], n = 1; n < e.length; ++n) t = (0, _tfjsCore.minimum)(t, e[n]);

          return t;
        });
      }, t.className = "Minimum", t;
    }(Merge);

    _tfjsCore.serialization.registerClass(Minimum);

    var Concatenate = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.DEFAULT_AXIS = -1, null == t && (t = {}), n.axis = null == t.axis ? n.DEFAULT_AXIS : t.axis, n.supportsMasking = !0, n.reshapeRequired = !1, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        if (!Array.isArray(e) || !Array.isArray(e[0]) || 1 === e.length) throw new ValueError("A `Concatenate` layer should be called on a list of at least 2 inputs");

        for (var t = !0, n = 0, r = e = e; n < r.length; n++) {
          if (null != (c = r[n])) {
            t = !1;
            break;
          }
        }

        if (!t) {
          for (var i = [], a = 0; a < e.length; ++a) {
            var o = e[a].slice();
            o.splice(this.axis, 1);

            for (var s = !1, l = 0, u = i; l < u.length; l++) {
              var c = u[l];

              if (_tfjsCore.util.arraysEqual(c, o)) {
                s = !0;
                break;
              }
            }

            s || i.push(o);
          }

          if (i.length > 1) throw new 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) {
        var t = this;
        return (0, _tfjsCore.tidy)(function () {
          return concatenate(e, t.axis);
        });
      }, t.prototype.computeOutputShape = function (e) {
        if (!Array.isArray(e) || !Array.isArray(e[0])) throw new 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 < a.length; i++) {
          var o = a[i];

          if (null == n[r] || null == o[r]) {
            n[r] = null;
            break;
          }

          n[r] += o[r];
        }

        return n;
      }, t.prototype.computeMask = function (e, t) {
        var n = this;
        if (null == t) return null;
        if (!Array.isArray(t)) throw new ValueError("`mask` should be an array for Concatenate");
        if (!Array.isArray(e)) throw new ValueError("`inputs` should be an array for Concatenate");
        if (t.length !== e.length) throw new ValueError("Mismatch in the length of mask (" + t.length + ") and the legnth of inputs (" + e.length + ")");
        return (0, _tfjsCore.tidy)(function () {
          var r = !0;
          if (t.forEach(function (e) {
            null == e || (r = !1);
          }), r) return null;

          for (var i = [], a = 0; a < e.length; ++a) null == t[a] ? i.push((0, _tfjsCore.onesLike)(e[a]).asType("bool")) : t[a].rank < e[a].rank ? i.push((0, _tfjsCore.expandDims)(t[a], -1)) : i.push(t[a]);

          var o = (0, _tfjsCore.concat)(i, n.axis);
          return (0, _tfjsCore.all)(o, -1, !1);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          axis: this.axis
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Concatenate", t;
    }(Merge);

    function interpretAxis(e, t) {
      for (; e < 0;) e += t;

      return e;
    }

    function batchDot(e, t, n) {
      if (e.shape.length > 3 || t.shape.length > 3) throw new NotImplementedError("batchDot is not implemented for tensors of 4D or higher rank yet");
      if (_tfjsCore.util.assert(e.shape.length >= 2, function () {
        return "batchDot requires the rank of x to be >= 2, but got " + e.shape.length;
      }), _tfjsCore.util.assert(e.shape.length >= 2, function () {
        return "batchDot requires the rank of y to be >= 2, but got " + t.shape.length;
      }), "number" == typeof n && (n = [n, n]), "complex64" === e.dtype || "complex64" === t.dtype) throw new NotImplementedError("batchDot is not implemented for complex64-type Tensors yet.");
      var r = e.shape.length,
        i = t.shape.length;
      null == n && (n = [r - 1, i - 2]);
      var a = n;
      return (0, _tfjsCore.tidy)(function () {
        var n, o;

        if (r > i) {
          n = r - i;

          for (var s = [], l = 0; l < n; ++l) s.push(1);

          t = t.reshape(t.shape.concat(s));
        } else if (i > r) {
          n = i - r;

          for (s = [], l = 0; l < n; ++l) s.push(1);

          e = e.reshape(e.shape.concat(s));
        } else n = 0;

        if (2 === e.shape.length && 2 === t.shape.length) o = a[0] === a[1] ? e.mulStrict(t).sum(a[0]) : e.transpose([1, 0]).mulStrict(t).sum(a[1]); else {
          var u = a[0] !== e.shape.length - 1,
            c = a[1] === t.shape.length - 1;
          o = e.matMul(t, u, c);
        }

        if (n > 0) {
          var p = void 0,
            h = [];

          for (l = p = r > i ? r + i - 3 : r - 1; l < p + n; ++l) h.push(l);

          o = o.squeeze(h);
        }

        return 1 === o.shape.length && (o = o.expandDims(1)), o;
      });
    }

    _tfjsCore.serialization.registerClass(Concatenate);

    var Dot = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.axes = t.axes, n.normalize = null != t.normalize && t.normalize, n.supportsMasking = !0, n.reshapeRequired = !1, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        _tfjsCore.util.assert(Array.isArray(e) && 2 === e.length && Array.isArray(e[0]) && Array.isArray(e[1]), function () {
          return "A `Dot` layer should be called on a list of exactly 2 inputs.";
        });

        var t = e[0],
          n = e[1];
        if (t.length > 3 || n.length > 3) throw new NotImplementedError("Dot layer does not support tensors of 4D or higher rank yet.");
        var r = this.interpretAxes(t, n);
        if (t[r[0]] !== n[r[1]]) throw new ValueError("Dimension incompatibility: " + t[r[0]] + " !== " + n[r[1]]);
      }, t.prototype.mergeFunction = function (e) {
        if (2 !== e.length) throw new ValueError("A `Dot` layer must be called on exactly 2 inputs, but received " + e.length + " input(s).");
        var t,
          n = e[0],
          r = e[1];
        return t = Array.isArray(this.axes) ? this.axes.map(function (t, n) {
          return interpretAxis(t, e[n].shape.length);
        }) : [interpretAxis(this.axes, n.shape.length), interpretAxis(this.axes, r.shape.length)], this.normalize && (n = l2Normalize(n, t[0]), r = l2Normalize(r, t[1])), batchDot(n, r, t);
      }, t.prototype.interpretAxes = function (e, t) {
        return Array.isArray(this.axes) ? this.axes : [interpretAxis(this.axes, e.length), interpretAxis(this.axes, t.length)];
      }, t.prototype.computeOutputShape = function (e) {
        _tfjsCore.util.assert(Array.isArray(e) && 2 === e.length && Array.isArray(e[0]) && Array.isArray(e[1]), function () {
          return "A `Dot` layer should be called on a list of exactly 2 inputs.";
        });

        var t = e[0].slice(),
          n = e[1].slice();
        if (t.length > 3 || n.length > 3) throw new NotImplementedError("Dot layer does not support tensors of 4D or higher rank yet.");
        var r = this.interpretAxes(t, n);
        t.splice(r[0], 1), n.splice(r[1], 1), n.splice(0, 1);
        var i = t.concat(n);
        return 1 === i.length && i.push(1), i;
      }, t.prototype.computeMask = function (e, t) {
        return null;
      }, t.prototype.getConfig = function () {
        var t = {
          axes: this.axes,
          normalize: this.normalize
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "Dot", t;
    }(Merge);

    _tfjsCore.serialization.registerClass(Dot);

    var GaussianNoise = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.supportsMasking = !0, n.stddev = t.stddev, n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this),
          n = {
            stddev: this.stddev
          };
        return Object.assign(n, t), n;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e);
          return inTrainPhase(function () {
            return randomNormal$1(r.shape, 0, n.stddev).add(r);
          }, function () {
            return r;
          }, t.training || !1);
        });
      }, t.className = "GaussianNoise", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(GaussianNoise);

    var GaussianDropout = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.supportsMasking = !0, n.rate = t.rate, n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this),
          n = {
            rate: this.rate
          };
        return Object.assign(n, t), n;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t);
          var r = getExactlyOneTensor(e);

          if (n.rate > 0 && n.rate < 1) {
            return inTrainPhase(function () {
              var e = Math.sqrt(n.rate / (1 - n.rate));
              return r.mul(randomNormal$1(r.shape, 1, e));
            }, function () {
              return r;
            }, t.training || !1);
          }

          return r;
        });
      }, t.className = "GaussianDropout", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(GaussianDropout);

    var AlphaDropout = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.supportsMasking = !0, n.rate = t.rate, n.noiseShape = t.noiseShape, n;
      }

      return __extends(t, e), t.prototype._getNoiseShape = function (e) {
        return this.noiseShape || getExactlyOneTensor(e).shape;
      }, t.prototype.computeOutputShape = function (e) {
        return e;
      }, t.prototype.getConfig = function () {
        var t = e.prototype.getConfig.call(this),
          n = {
            rate: this.rate
          };
        return Object.assign(n, t), n;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          if (n.rate < 1 && n.rate > 0) {
            var r = n._getNoiseShape(e);

            return inTrainPhase(function () {
              var t = getExactlyOneTensor(e),
                i = -1.7580993408473766,
                a = (0, _tfjsCore.greaterEqual)((0, _tfjsCore.randomUniform)(r), n.rate);
              a = cast$1(a, "float32");
              var o = Math.pow((1 - n.rate) * (1 + n.rate * Math.pow(i, 2)), -.5),
                s = -o * i * n.rate;
              return t.mul(a).add(a.add(-1).mul(i)).mul(o).add(s);
            }, function () {
              return getExactlyOneTensor(e);
            }, t.training || !1);
          }

          return e;
        });
      }, t.className = "AlphaDropout", t;
    }(Layer);

    function batchNormalization(e, t, n, r, i, a) {
      var o;
      if (void 0 === a && (a = .001), 2 === e.rank) o = (0, _tfjsCore.batchNorm2d)(e, t, n, r, i, a); else if (3 === e.rank) o = (0, _tfjsCore.batchNorm3d)(e, t, n, r, i, a); else {
        if (4 !== e.rank) throw new NotImplementedError("batchNormalization is not implemented for array of rank " + e.rank + " yet");
        o = (0, _tfjsCore.batchNorm4d)(e, t, n, r, i, a);
      }
      return o;
    }

    function regularNormalizeBatchInTraining(e, t, n, r, i) {
      return void 0 === i && (i = .001), (0, _tfjsCore.tidy)(function () {
        var a = (0, _tfjsCore.moments)(e, r),
          o = a.mean,
          s = a.variance;
        return [batchNormalization(e, o, s, n, t, i), o, s];
      });
    }

    function broadcastNormalizeBatchInTraining(e, t, n, r, i) {
      return void 0 === i && (i = .001), (0, _tfjsCore.tidy)(function () {
        for (var a = (0, _tfjsCore.moments)(e, r), o = a.mean, s = a.variance, l = [], u = 0, c = range(0, e.rank); u < c.length; u++) {
          var p = c[u];
          -1 !== r.indexOf(p) ? l.push(1) : l.push(e.shape[p]);
        }

        var h = o.reshape(l),
          d = s.reshape(l),
          f = null == t ? null : t.reshape(l),
          g = null == n ? null : n.reshape(l);
        return [batchNormalization(e, h, d, g, f, i), o, s];
      });
    }

    function normalizeBatchInTraining(e, t, n, r, i) {
      return void 0 === i && (i = .001), _tfjsCore.util.arraysEqual(r.slice().sort(), range(0, e.rank - 1)) ? regularNormalizeBatchInTraining(e, t, n, r, i) : broadcastNormalizeBatchInTraining(e, t, n, r, i);
    }

    _tfjsCore.serialization.registerClass(AlphaDropout);

    var BatchNormalization = function (e) {
      function t(t) {
        var n = this;
        return null == t && (t = {}), (n = e.call(this, t) || this).supportsMasking = !0, n.axis = null == t.axis ? -1 : t.axis, n.momentum = null == t.momentum ? .99 : t.momentum, n.epsilon = null == t.epsilon ? .001 : t.epsilon, n.center = null == t.center || t.center, n.scale = null == t.scale || t.scale, n.betaInitializer = getInitializer(t.betaInitializer || "zeros"), n.gammaInitializer = getInitializer(t.gammaInitializer || "ones"), n.movingMeanInitializer = getInitializer(t.movingMeanInitializer || "zeros"), n.movingVarianceInitializer = getInitializer(t.movingVarianceInitializer || "ones"), n.betaConstraint = getConstraint(t.betaConstraint), n.gammaConstraint = getConstraint(t.gammaConstraint), n.betaRegularizer = getRegularizer(t.betaRegularizer), n.gammaRegularizer = getRegularizer(t.gammaRegularizer), n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t;
        e = getExactlyOneShape(e);
        var n = this.axis >= 0 ? this.axis : this.axis + e.length,
          r = e[n];
        if (null == r) throw new ValueError("Axis " + n + " of input tensor should have a defined dimension but the layer received an input with shape " + JSON.stringify(e) + ".");
        this.inputSpec = [new InputSpec({
          ndim: e.length,
          axes: (t = {}, t[n] = r, t)
        })];
        var i = [r];
        this.scale && (this.gamma = this.addWeight("gamma", i, null, this.gammaInitializer, this.gammaRegularizer, !0, this.gammaConstraint)), this.center && (this.beta = this.addWeight("beta", i, null, this.betaInitializer, this.betaRegularizer, !0, this.betaConstraint)), this.movingMean = this.addWeight("moving_mean", i, null, this.movingMeanInitializer, null, !1), this.movingVariance = this.addWeight("moving_variance", i, null, this.movingVarianceInitializer, null, !1), this.built = !0;
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var r = null != t.training && t.training,
            i = getExactlyOneTensor(e),
            a = i.shape,
            o = a.length,
            s = range(0, o),
            l = n.axis >= 0 ? n.axis : n.axis + o;
          s.splice(l, 1);
          var u = pyListRepeat(1, o);
          u[l] = a[l];
          var c = s.slice();
          c.sort();
          var p = !_tfjsCore.util.arraysEqual(c, range(0, o).slice(0, o - 1));
          if (!r) return function () {
            if (p) {
              var e = n.movingMean.read().reshape(u),
                t = n.movingVariance.read().reshape(u),
                r = n.center ? n.beta.read().reshape(u) : null,
                a = n.scale ? n.gamma.read().reshape(u) : null;
              return batchNormalization(i, e, t, r, a, n.epsilon);
            }

            return batchNormalization(i, n.movingMean.read(), n.movingVariance.read(), null == n.beta ? null : n.beta.read(), null == n.gamma ? null : n.gamma.read(), n.epsilon);
          }();

          var h = normalizeBatchInTraining(i, n.gamma.read(), n.beta.read(), s, n.epsilon),
            d = h[0],
            f = h[1],
            g = h[2],
            m = function (e, t, n) {
              (0, _tfjsCore.tidy)(function () {
                var r = 1 - n,
                  i = e.read(),
                  a = i.sub(t).mul(r);
                e.write(i.sub(a));
              });
            };

          return m(n.movingMean, f, n.momentum), m(n.movingVariance, g, n.momentum), d;
        });
      }, t.prototype.getConfig = function () {
        var t = {
          axis: this.axis,
          momentum: this.momentum,
          epsilon: this.epsilon,
          center: this.center,
          scale: this.scale,
          betaInitializer: serializeInitializer(this.betaInitializer),
          gammaInitializer: serializeInitializer(this.gammaInitializer),
          movingMeanInitializer: serializeInitializer(this.movingMeanInitializer),
          movingVarianceInitializer: serializeInitializer(this.movingVarianceInitializer),
          betaRegularizer: serializeRegularizer(this.betaRegularizer),
          gammaRegularizer: serializeRegularizer(this.gammaRegularizer),
          betaConstraint: serializeConstraint(this.betaConstraint),
          gammaConstraint: serializeConstraint(this.gammaConstraint)
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "BatchNormalization", t;
    }(Layer);

    _tfjsCore.serialization.registerClass(BatchNormalization);

    var LayerNormalization = function (e) {
      function t(t) {
        var n = this;

        if (null == t && (t = {}), (n = e.call(this, t) || this).axis = null == t.axis ? -1 : t.axis, "number" == typeof n.axis) {
          if (!Number.isInteger(n.axis)) throw new Error("Expected axis to be an integer, but received " + n.axis);
        } else {
          if (!Array.isArray(n.axis)) throw new Error("Expected axis to be an integer or an array of integers, but received " + JSON.stringify(n.axis));

          for (var r = 0, i = n.axis; r < i.length; r++) {
            var a = i[r];
            if (!Number.isInteger(a)) throw new Error("Expected axis to be an array of integers, but received " + JSON.stringify(n.axis));
          }
        }

        return n.epsilon = null == t.epsilon ? .001 : t.epsilon, n.center = null == t.center || t.center, n.scale = null == t.scale || t.scale, n.betaInitializer = getInitializer(t.betaInitializer || "zeros"), n.gammaInitializer = getInitializer(t.gammaInitializer || "ones"), n.betaRegularizer = getRegularizer(t.betaRegularizer), n.gammaRegularizer = getRegularizer(t.gammaRegularizer), n.supportsMasking = !0, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t = (e = getExactlyOneShape(e)).length;
        "number" == typeof this.axis && (this.axis = [this.axis]);

        for (var n = 0; n < this.axis.length; ++n) this.axis[n] < 0 && (this.axis[n] += t);

        for (var r = 0, i = this.axis; r < i.length; r++) {
          var a = i[r];
          if (a < 0 || a >= t) throw new Error("Invalid axis: " + a);
        }

        if (this.axis.length !== unique(this.axis).length) throw new Error("Found duplicate axes in: " + this.axis);
        var o = this.axis.map(function (t) {
          return e[t];
        });
        this.scale ? this.gamma = this.addWeight("gamma", o, "float32", this.gammaInitializer, this.gammaRegularizer, !0) : this.gamma = null, this.center ? this.beta = this.addWeight("beta", o, "float32", this.betaInitializer, this.betaRegularizer, !0) : this.beta = null, this.built = !0;
      }, t.prototype.call = function (e, t) {
        var n = this,
          r = getExactlyOneTensor(e),
          i = r.shape,
          a = i.length;
        return (0, _tfjsCore.tidy)(function () {
          for (var e = (0, _tfjsCore.moments)(r, n.axis, !0), t = e.mean, o = e.variance, s = pyListRepeat(1, a), l = 0, u = n.axis; l < u.length; l++) {
            var c = u[l];
            s[c] = i[c];
          }

          for (var p = function (e) {
            return null != e && e.shape.length !== a && n.axis !== [a - 1] ? e.reshape(s) : e;
          }, h = p(n.gamma.read()), d = p(n.beta.read()), f = [], g = [], m = 0; m < a; ++m) -1 !== n.axis.indexOf(m) ? (f.push(i[m]), g.push(1)) : (f.push(1), g.push(i[m]));

          return t = t.tile(f), o = o.tile(f), h = h.tile(g), d = d.tile(g), batchNormalization(r, t, o, d, h, n.epsilon);
        });
      }, t.prototype.getConfig = function () {
        var t = {
          axis: this.axis,
          epsilon: this.epsilon,
          center: this.center,
          scale: this.scale,
          betaInitializer: serializeInitializer(this.betaInitializer),
          gammaInitializer: serializeInitializer(this.gammaInitializer),
          betaRegularizer: serializeRegularizer(this.betaRegularizer),
          gammaRegularizer: serializeRegularizer(this.gammaRegularizer)
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.className = "LayerNormalization", t;
    }(Layer);

    function spatial2dPadding(e, t, n) {
      return (0, _tfjsCore.tidy)(function () {
        if (4 !== e.rank) throw new ValueError("temporalPadding expects input tensor to be 4-D, but received a " + e.rank + "-D tensor.");
        if (null == t && (t = [[1, 1], [1, 1]]), 2 !== t.length || 2 !== t[0].length || 2 !== t[1].length) throw new 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 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]], (0, _tfjsCore.pad)(e, r);
      });
    }

    _tfjsCore.serialization.registerClass(LayerNormalization);

    var ZeroPadding2D = function (e) {
      function t(t) {
        var n = this;
        if (null == t && (t = {}), (n = e.call(this, t) || this).dataFormat = null == t.dataFormat ? 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 ValueError("ZeroPadding2D expects padding to be a length-2 array, but received a length-" + t.padding.length + " array.");
          var r = void 0,
            i = void 0;
          if ("number" == typeof t.padding[0]) r = [t.padding[0], t.padding[0]], i = [t.padding[1], t.padding[1]]; else {
            if (t.padding = t.padding, 2 !== t.padding[0].length) throw new 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 ValueError("ZeroPadding2D expects width padding to be a length-2 array, but received a length-" + t.padding[1].length + " array.");
            i = t.padding[1];
          }
          n.padding = [r, i];
        }
        return n.inputSpec = [new InputSpec({
          ndim: 4
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        var t, n;
        return e = getExactlyOneShape(e), "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) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return spatial2dPadding(getExactlyOneTensor(e), n.padding, n.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.className = "ZeroPadding2D", t;
    }(Layer);

    function pool2d(e, t, n, r, i, a) {
      return (0, _tfjsCore.tidy)(function () {
        var o;
        checkDataFormat(i), checkPoolMode(a), checkPaddingMode(r), null == n && (n = [1, 1]), null == r && (r = "valid"), null == i && (i = imageDataFormat()), null == a && (a = "max"), e = preprocessConv2DInput(e, i);
        var s = "same" === r ? "same" : "valid";
        return o = "max" === a ? (0, _tfjsCore.maxPool)(e, t, n, s) : (0, _tfjsCore.avgPool)(e, t, n, s), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 3, 1, 2])), o;
      });
    }

    function pool3d(e, t, n, r, i, a) {
      return (0, _tfjsCore.tidy)(function () {
        var o;
        checkDataFormat(i), checkPoolMode(a), checkPaddingMode(r), null == n && (n = [1, 1, 1]), null == r && (r = "valid"), null == i && (i = imageDataFormat()), null == a && (a = "max"), e = preprocessConv3DInput(e, i);
        var s = "same" === r ? "same" : "valid";
        return o = "max" === a ? (0, _tfjsCore.maxPool3d)(e, t, n, s) : (0, _tfjsCore.avgPool3d)(e, t, n, s), "channelsFirst" === i && (o = (0, _tfjsCore.transpose)(o, [0, 4, 1, 2, 3])), o;
      });
    }

    _tfjsCore.serialization.registerClass(ZeroPadding2D);

    var Pooling1D = function (e) {
      function t(t) {
        var n = this;
        if (null == t.poolSize && (t.poolSize = 2), n = e.call(this, t) || this, "number" == typeof t.poolSize) n.poolSize = [t.poolSize]; else {
          if (!Array.isArray(t.poolSize) || 1 !== t.poolSize.length || "number" != typeof t.poolSize[0]) throw new ValueError("poolSize for 1D convolutional layer must be a number or an Array of a single number, but received " + JSON.stringify(t.poolSize));
          n.poolSize = t.poolSize;
        }
        if (assertPositiveInteger(n.poolSize, "poolSize"), null == t.strides) n.strides = n.poolSize; else if ("number" == typeof t.strides) n.strides = [t.strides]; else {
          if (!Array.isArray(t.strides) || 1 !== t.strides.length || "number" != typeof t.strides[0]) throw new ValueError("strides for 1D convolutional layer must be a number or an Array of a single number, but received " + JSON.stringify(t.strides));
          n.strides = t.strides;
        }
        return assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
          ndim: 3
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        var t = convOutputLength((e = getExactlyOneShape(e))[1], this.poolSize[0], this.padding, this.strides[0]);
        return [e[0], t, e[2]];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          n.invokeCallHook(e, t), e = expandDims$1(getExactlyOneTensor(e), 2);
          var r = n.poolingFunction(getExactlyOneTensor(e), [n.poolSize[0], 1], [n.strides[0], 1], n.padding, "channelsLast");
          return (0, _tfjsCore.squeeze)(r, [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;
    }(Layer),
      MaxPooling1D = function (e) {
        function t(t) {
          return e.call(this, t) || this;
        }

        return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
          return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "max");
        }, t.className = "MaxPooling1D", t;
      }(Pooling1D);

    _tfjsCore.serialization.registerClass(MaxPooling1D);

    var AveragePooling1D = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
        return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "avg");
      }, t.className = "AveragePooling1D", t;
    }(Pooling1D);

    _tfjsCore.serialization.registerClass(AveragePooling1D);

    var Pooling2D = function (e) {
      function t(t) {
        var n = this;
        if (null == t.poolSize && (t.poolSize = [2, 2]), (n = e.call(this, t) || this).poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize], null == t.strides) n.strides = n.poolSize; else if (Array.isArray(t.strides)) {
          if (2 !== t.strides.length) throw new ValueError("If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length " + t.strides.length + ".");
          n.strides = t.strides;
        } else n.strides = [t.strides, t.strides];
        return assertPositiveInteger(n.poolSize, "poolSize"), assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
          ndim: 4
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        e = getExactlyOneShape(e);
        var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
          n = "channelsFirst" === this.dataFormat ? e[3] : e[2];
        return t = convOutputLength(t, this.poolSize[0], this.padding, this.strides[0]), n = 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) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return n.invokeCallHook(e, t), n.poolingFunction(getExactlyOneTensor(e), n.poolSize, n.strides, n.padding, n.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;
    }(Layer),
      MaxPooling2D = function (e) {
        function t(t) {
          return e.call(this, t) || this;
        }

        return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
          return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "max");
        }, t.className = "MaxPooling2D", t;
      }(Pooling2D);

    _tfjsCore.serialization.registerClass(MaxPooling2D);

    var AveragePooling2D = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
        return checkDataFormat(i), checkPaddingMode(r), pool2d(e, t, n, r, i, "avg");
      }, t.className = "AveragePooling2D", t;
    }(Pooling2D);

    _tfjsCore.serialization.registerClass(AveragePooling2D);

    var Pooling3D = function (e) {
      function t(t) {
        var n = this;
        if (null == t.poolSize && (t.poolSize = [2, 2, 2]), (n = e.call(this, t) || this).poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize, t.poolSize], null == t.strides) n.strides = n.poolSize; else if (Array.isArray(t.strides)) {
          if (3 !== t.strides.length) throw new ValueError("If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length " + t.strides.length + ".");
          n.strides = t.strides;
        } else n.strides = [t.strides, t.strides, t.strides];
        return assertPositiveInteger(n.poolSize, "poolSize"), assertPositiveInteger(n.strides, "strides"), n.padding = null == t.padding ? "valid" : t.padding, n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), checkPaddingMode(n.padding), n.inputSpec = [new InputSpec({
          ndim: 5
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        e = getExactlyOneShape(e);
        var t = "channelsFirst" === this.dataFormat ? e[2] : e[1],
          n = "channelsFirst" === this.dataFormat ? e[3] : e[2],
          r = "channelsFirst" === this.dataFormat ? e[4] : e[3];
        return t = convOutputLength(t, this.poolSize[0], this.padding, this.strides[0]), n = convOutputLength(n, this.poolSize[1], this.padding, this.strides[1]), r = convOutputLength(r, this.poolSize[2], this.padding, this.strides[2]), "channelsFirst" === this.dataFormat ? [e[0], e[1], t, n, r] : [e[0], t, n, r, e[4]];
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          return n.invokeCallHook(e, t), n.poolingFunction(getExactlyOneTensor(e), n.poolSize, n.strides, n.padding, n.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;
    }(Layer),
      MaxPooling3D = function (e) {
        function t(t) {
          return e.call(this, t) || this;
        }

        return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
          return checkDataFormat(i), checkPaddingMode(r), pool3d(e, t, n, r, i, "max");
        }, t.className = "MaxPooling3D", t;
      }(Pooling3D);

    _tfjsCore.serialization.registerClass(MaxPooling3D);

    var AveragePooling3D = function (e) {
      function t(t) {
        return e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.poolingFunction = function (e, t, n, r, i) {
        return checkDataFormat(i), checkPaddingMode(r), pool3d(e, t, n, r, i, "avg");
      }, t.className = "AveragePooling3D", t;
    }(Pooling3D);

    _tfjsCore.serialization.registerClass(AveragePooling3D);

    var GlobalPooling1D = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.inputSpec = [new InputSpec({
          ndim: 3
        })], n;
      }

      return __extends(t, e), t.prototype.computeOutputShape = function (e) {
        return [e[0], e[2]];
      }, t.prototype.call = function (e, t) {
        throw new NotImplementedError();
      }, t;
    }(Layer),
      GlobalAveragePooling1D = function (e) {
        function t(t) {
          return e.call(this, t || {}) || this;
        }

        return __extends(t, e), t.prototype.call = function (e, t) {
          return (0, _tfjsCore.tidy)(function () {
            var t = getExactlyOneTensor(e);
            return (0, _tfjsCore.mean)(t, 1);
          });
        }, t.className = "GlobalAveragePooling1D", t;
      }(GlobalPooling1D);

    _tfjsCore.serialization.registerClass(GlobalAveragePooling1D);

    var GlobalMaxPooling1D = function (e) {
      function t(t) {
        return e.call(this, t || {}) || this;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        return (0, _tfjsCore.tidy)(function () {
          var t = getExactlyOneTensor(e);
          return (0, _tfjsCore.max)(t, 1);
        });
      }, t.className = "GlobalMaxPooling1D", t;
    }(GlobalPooling1D);

    _tfjsCore.serialization.registerClass(GlobalMaxPooling1D);

    var GlobalPooling2D = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.dataFormat = null == t.dataFormat ? "channelsLast" : t.dataFormat, checkDataFormat(n.dataFormat), n.inputSpec = [new InputSpec({
          ndim: 4
        })], n;
      }

      return __extends(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 NotImplementedError();
      }, t.prototype.getConfig = function () {
        var t = {
          dataFormat: this.dataFormat
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t;
    }(Layer),
      GlobalAveragePooling2D = function (e) {
        function t() {
          return null !== e && e.apply(this, arguments) || this;
        }

        return __extends(t, e), t.prototype.call = function (e, t) {
          var n = this;
          return (0, _tfjsCore.tidy)(function () {
            var t = getExactlyOneTensor(e);
            return "channelsLast" === n.dataFormat ? (0, _tfjsCore.mean)(t, [1, 2]) : (0, _tfjsCore.mean)(t, [2, 3]);
          });
        }, t.className = "GlobalAveragePooling2D", t;
      }(GlobalPooling2D);

    _tfjsCore.serialization.registerClass(GlobalAveragePooling2D);

    var GlobalMaxPooling2D = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var t = getExactlyOneTensor(e);
          return "channelsLast" === n.dataFormat ? (0, _tfjsCore.max)(t, [1, 2]) : (0, _tfjsCore.max)(t, [2, 3]);
        });
      }, t.className = "GlobalMaxPooling2D", t;
    }(GlobalPooling2D);

    function standardizeArgs(e, t, n, r) {
      if (Array.isArray(e)) {
        if (null != t || null != n) throw new ValueError("When inputs is an array, neither initialState or constants should be provided");
        null != r && (n = e.slice(e.length - r, e.length), e = e.slice(0, e.length - r)), e.length > 1 && (t = e.slice(1, e.length)), e = e[0];
      }

      function i(e) {
        return null == e || Array.isArray(e) ? e : [e];
      }

      return {
        inputs: e,
        initialState: t = i(t),
        constants: n = i(n)
      };
    }

    function rnn(e, t, n, r, i, a, o, s) {
      return void 0 === r && (r = !1), void 0 === o && (o = !1), void 0 === s && (s = !1), (0, _tfjsCore.tidy)(function () {
        var l = t.shape.length;
        if (l < 3) throw new ValueError("Input should be at least 3D, but is " + l + "D.");
        var u = [1, 0].concat(range(2, l));
        if (t = (0, _tfjsCore.transpose)(t, u), null != a) throw new NotImplementedError("The rnn() functoin of the deeplearn.js backend does not support constants yet.");
        o && console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."), null != i && ((i = i.asType("bool").asType("float32")).rank === l - 1 && (i = (0, _tfjsCore.expandDims)(i, -1)), i = (0, _tfjsCore.transpose)(i, u)), r && (t = (0, _tfjsCore.reverse)(t, 0), null != i && (i = (0, _tfjsCore.reverse)(i, 0)));
        var c,
          p,
          h = [],
          d = n,
          f = t.shape[0],
          g = (0, _tfjsCore.unstack)(t);
        null != i && (p = (0, _tfjsCore.unstack)(i));

        for (var m, y = function (t) {
          var n = g[t],
            r = (0, _tfjsCore.tidy)(function () {
              return e(n, d);
            });
          if (null == i) c = r[0], d = r[1]; else {
            var a = (0, _tfjsCore.tidy)(function () {
              var e = p[t],
                n = (0, _tfjsCore.onesLike)(e).sub(e);
              return {
                output: r[0].mul(e).addStrict(d[0].mul(n)),
                newStates: d.map(function (t, i) {
                  return r[1][i].mul(e).addStrict(t.mul(n));
                })
              };
            });
            c = a.output, d = a.newStates;
          }
          s && h.push(c);
        }, v = 0; v < f; ++v) y(v);

        if (s) {
          m = (0, _tfjsCore.stack)(h, 1);
        }

        return [c, m, d];
      });
    }

    _tfjsCore.serialization.registerClass(GlobalMaxPooling2D);

    var RNN = function (e) {
      function t(t) {
        var n,
          r = e.call(this, t) || this;
        if (null == t.cell) throw new ValueError("cell property is missing for the constructor of RNN.");
        if (null == (n = Array.isArray(t.cell) ? new StackedRNNCells({
          cells: t.cell
        }) : t.cell).stateSize) throw new 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 InputSpec({
          ndim: 3
        })], r.stateSpec = null, r.states_ = null, r.numConstants = null, r.keptStates = [], r;
      }

      return __extends(t, e), t.prototype.getStates = function () {
        return null == this.states_ ? range(0, Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1).map(function (e) {
          return null;
        }) : this.states_;
      }, t.prototype.setStates = function (e) {
        this.states_ = e;
      }, t.prototype.computeOutputShape = function (e) {
        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; a < o.length; a++) {
            var s = o[a];
            i.push([e[0], s]);
          }

          return [n].concat(i);
        }

        return n;
      }, t.prototype.computeMask = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          Array.isArray(t) && (t = t[0]);
          var e = n.returnSequences ? t : null;

          if (n.returnState) {
            var r = n.states.map(function (e) {
              return null;
            });
            return [e].concat(r);
          }

          return e;
        });
      }, Object.defineProperty(t.prototype, "states", {
        get: function () {
          if (null == this.states_) {
            for (var e = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1, t = [], n = 0; n < e; ++n) t.push(null);

            return t;
          }

          return this.states_;
        },
        set: function (e) {
          this.states_ = e;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.build = function (e) {
        if (null != this.numConstants) throw new NotImplementedError("Constants support is not implemented in RNN yet.");
        isArrayOfShapes(e) && (e = e[0]), e = e;
        var t = this.stateful ? e[0] : null,
          n = e[e.length - 1];
        this.inputSpec[0] = new InputSpec({
          shape: [t, null, n]
        });
        var r,
          i = [e[0]].concat(e.slice(2));

        if (this.cell.build(i), r = Array.isArray(this.cell.stateSize) ? this.cell.stateSize : [this.cell.stateSize], null != this.stateSpec) {
          if (!_tfjsCore.util.arraysEqual(this.stateSpec.map(function (e) {
            return e.shape[e.shape.length - 1];
          }), r)) throw new ValueError("An initialState was passed that is not compatible with cell.stateSize. Received stateSpec=" + this.stateSpec + "; However cell.stateSize is " + this.cell.stateSize);
        } else this.stateSpec = r.map(function (e) {
          return new InputSpec({
            shape: [null, e]
          });
        });

        this.stateful && this.resetStates();
      }, t.prototype.resetStates = function (e, t) {
        var n = this;
        void 0 === t && (t = !1), (0, _tfjsCore.tidy)(function () {
          if (!n.stateful) throw new AttributeError("Cannot call resetStates() on an RNN Layer that is not stateful.");
          var r = n.inputSpec[0].shape[0];
          if (null == r) throw new ValueError("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");
          if (null == n.states_) Array.isArray(n.cell.stateSize) ? n.states_ = n.cell.stateSize.map(function (e) {
            return (0, _tfjsCore.zeros)([r, e]);
          }) : n.states_ = [(0, _tfjsCore.zeros)([r, n.cell.stateSize])]; else if (null == e) (0, _tfjsCore.dispose)(n.states_), null != n.keptStates && ((0, _tfjsCore.dispose)(n.keptStates), n.keptStates = []), Array.isArray(n.cell.stateSize) ? n.states_ = n.cell.stateSize.map(function (e) {
            return (0, _tfjsCore.zeros)([r, e]);
          }) : n.states_[0] = (0, _tfjsCore.zeros)([r, n.cell.stateSize]); else {
            if (Array.isArray(e) || (e = [e]), e.length !== n.states_.length) throw new ValueError("Layer " + n.name + " expects " + n.states_.length + " state(s), but it received " + e.length + " state value(s). Input received: " + e);
            !0 === t ? n.keptStates.push(n.states_.slice()) : (0, _tfjsCore.dispose)(n.states_);

            for (var i = 0; i < n.states_.length; ++i) {
              var a = e[i],
                o = Array.isArray(n.cell.stateSize) ? n.cell.stateSize[i] : n.cell.stateSize,
                s = [r, o];
              if (!_tfjsCore.util.arraysEqual(a.shape, s)) throw new ValueError("State " + i + " is incompatible with layer " + n.name + ": expected shape=" + s + ", received shape=" + a.shape);
              n.states_[i] = a;
            }
          }
          n.states_ = n.states_.map(function (e) {
            return (0, _tfjsCore.keep)(e.clone());
          });
        });
      }, t.prototype.apply = function (t, n) {
        var r = null == n ? null : n.initialState,
          i = null == n ? null : n.constants;
        null == n && (n = {});
        var a = standardizeArgs(t, r, i, this.numConstants);
        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 l = 0, u = r; l < u.length; l++) {
            var c = u[l];
            this.stateSpec.push(new InputSpec({
              shape: c.shape
            }));
          }

          s = s.concat(this.stateSpec);
        }

        if (null != i && (n.constants = i, o = o.concat(i), this.numConstants = i.length), o[0] instanceof SymbolicTensor) {
          var p = [t].concat(o),
            h = this.inputSpec.concat(s),
            d = this.inputSpec;
          this.inputSpec = h;
          var f = e.prototype.apply.call(this, p, n);
          return this.inputSpec = d, f;
        }

        return e.prototype.apply.call(this, t, n);
      }, t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var r = null == t ? null : t.mask,
            i = null == t ? null : t.training,
            a = null == t ? null : t.initialState;
          e = getExactlyOneTensor(e), null == a && (a = n.stateful ? n.states_ : n.getInitialState(e));
          var o = Array.isArray(n.cell.stateSize) ? n.cell.stateSize.length : 1;
          if (a.length !== o) throw new ValueError("RNN Layer has " + o + " state(s) but was passed " + a.length + " initial state(s).");
          n.unroll && console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");
          var s = {
            training: i
          },
            l = rnn(function (e, t) {
              var r = n.cell.call([e].concat(t), s);
              return [r[0], r.slice(1)];
            }, e, a, n.goBackwards, r, null, n.unroll, n.returnSequences),
            u = l[0],
            c = l[1],
            p = l[2];
          n.stateful && n.resetStates(p, i);
          var h = n.returnSequences ? c : u;
          return n.returnState ? [h].concat(p) : h;
        });
      }, t.prototype.getInitialState = function (e) {
        var t = this;
        return (0, _tfjsCore.tidy)(function () {
          var n = (0, _tfjsCore.zeros)(e.shape);
          return n = expandDims$1(n = (0, _tfjsCore.sum)(n, [1, 2])), Array.isArray(t.cell.stateSize) ? t.cell.stateSize.map(function (e) {
            return e > 1 ? tile$1(n, [1, e]) : n;
          }) : t.cell.stateSize > 1 ? [tile$1(n, [1, t.cell.stateSize])] : [n];
        });
      }, 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.setFastWeightInitDuringBuild = function (t) {
        e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.cell && this.cell.setFastWeightInitDuringBuild(t);
      }, 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.getClassName(),
          config: n
        };
        var r = e.prototype.getConfig.call(this);
        return Object.assign(t, r), t;
      }, t.fromConfig = function (e, t, n) {
        void 0 === n && (n = {});
        var r = deserialize(t.cell, n);
        return new e(Object.assign(t, {
          cell: r
        }));
      }, t.className = "RNN", t;
    }(Layer);

    exports.RNN = RNN;

    _tfjsCore.serialization.registerClass(RNN);

    var RNNCell = function (e) {
      function t() {
        return null !== e && e.apply(this, arguments) || this;
      }

      return __extends(t, e), t;
    }(Layer),
      SimpleRNNCell = 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, assertPositiveInteger(n.units, "units"), n.activation = getActivation(null == t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.stateSize = n.units, n.dropoutMask = null, n.recurrentDropoutMask = null, n;
        }

        return __extends(t, e), t.prototype.build = function (e) {
          e = 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) {
          var n = this;
          return (0, _tfjsCore.tidy)(function () {
            if (2 !== (e = e).length) throw new ValueError("SimpleRNNCell expects 2 input Tensors, got " + e.length + ".");
            var r = e[1];
            e = e[0];
            var i,
              a = null != t.training && t.training;
            0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
              return (0, _tfjsCore.onesLike)(e);
            }, n.dropout, a)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
              return (0, _tfjsCore.onesLike)(r);
            }, n.recurrentDropout, a));
            var o = n.dropoutMask,
              s = n.recurrentDropoutMask;
            i = dot(null != o ? (0, _tfjsCore.mul)(e, o) : e, n.kernel.read()), null != n.bias && (i = biasAdd(i, n.bias.read())), null != s && (r = (0, _tfjsCore.mul)(r, s));
            var l = (0, _tfjsCore.add)(i, dot(r, n.recurrentKernel.read()));
            return null != n.activation && (l = n.activation.apply(l)), [l, l];
          });
        }, t.prototype.getConfig = function () {
          var t = {
            units: this.units,
            activation: serializeActivation(this.activation),
            useBias: this.useBias,
            kernelInitializer: serializeInitializer(this.kernelInitializer),
            recurrentInitializer: serializeInitializer(this.recurrentInitializer),
            biasInitializer: serializeInitializer(this.biasInitializer),
            kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
            recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
            biasRegularizer: serializeRegularizer(this.biasRegularizer),
            activityRegularizer: serializeRegularizer(this.activityRegularizer),
            kernelConstraint: serializeConstraint(this.kernelConstraint),
            recurrentConstraint: serializeConstraint(this.recurrentConstraint),
            biasConstraint: serializeConstraint(this.biasConstraint),
            dropout: this.dropout,
            recurrentDropout: this.recurrentDropout
          },
            n = e.prototype.getConfig.call(this);
          return Object.assign(t, n), t;
        }, t.className = "SimpleRNNCell", t;
      }(RNNCell);

    _tfjsCore.serialization.registerClass(SimpleRNNCell);

    var SimpleRNN = function (e) {
      function t(t) {
        return t.cell = new SimpleRNNCell(t), e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.call = function (t, n) {
        var r = this;
        return (0, _tfjsCore.tidy)(function () {
          null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
          var i = null == n ? null : n.mask,
            a = null == n ? null : n.training,
            o = null == n ? null : n.initialState;
          return e.prototype.call.call(r, t, {
            mask: i,
            training: a,
            initialState: o
          });
        });
      }, 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: serializeActivation(this.activation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          recurrentInitializer: serializeInitializer(this.recurrentInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          recurrentConstraint: serializeConstraint(this.recurrentConstraint),
          biasConstraint: serializeConstraint(this.biasConstraint),
          dropout: this.dropout,
          recurrentDropout: this.recurrentDropout
        },
          n = e.prototype.getConfig.call(this);
        return delete n.cell, Object.assign(t, n), t;
      }, t.fromConfig = function (e, t) {
        return new e(t);
      }, t.className = "SimpleRNN", t;
    }(RNN);

    _tfjsCore.serialization.registerClass(SimpleRNN);

    var GRUCell = 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, assertPositiveInteger(n.units, "units"), n.activation = getActivation(void 0 === t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.recurrentActivation = getActivation(void 0 === t.recurrentActivation ? n.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.implementation = t.implementation, n.stateSize = n.units, n.dropoutMask = null, n.recurrentDropoutMask = null, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t = (e = 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) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          if (2 !== (e = e).length) throw new ValueError("GRUCell expects 2 input Tensors (inputs, h, c), got " + e.length + ".");
          var r = null != t.training && t.training,
            i = e[1];
          e = e[0], 0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
            return (0, _tfjsCore.onesLike)(e);
          }, n.dropout, r, 3)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
            return (0, _tfjsCore.onesLike)(i);
          }, n.recurrentDropout, r, 3));
          var a,
            o,
            s,
            l = n.dropoutMask,
            u = n.recurrentDropoutMask;
          0 < n.dropout && n.dropout < 1 && (e = (0, _tfjsCore.mul)(e, l[0]));
          var c = dot(e, n.kernel.read());
          n.useBias && (c = biasAdd(c, n.bias.read())), 0 < n.recurrentDropout && n.recurrentDropout < 1 && (i = (0, _tfjsCore.mul)(i, u[0]));
          var p = n.recurrentKernel.read(),
            h = (0, _tfjsCore.split)(p, [2 * n.units, n.units], p.rank - 1),
            d = h[0],
            f = h[1],
            g = dot(i, d),
            m = (0, _tfjsCore.split)(c, 3, c.rank - 1),
            y = m[0],
            v = m[1],
            b = m[2],
            w = (0, _tfjsCore.split)(g, 2, g.rank - 1),
            z = w[0],
            S = w[1];
          a = n.recurrentActivation.apply((0, _tfjsCore.add)(y, z)), o = n.recurrentActivation.apply((0, _tfjsCore.add)(v, S));
          var A = dot((0, _tfjsCore.mul)(o, i), f);
          s = n.activation.apply((0, _tfjsCore.add)(b, A));

          var _ = (0, _tfjsCore.add)((0, _tfjsCore.mul)(a, i), (0, _tfjsCore.mul)((0, _tfjsCore.add)(1, (0, _tfjsCore.neg)(a)), s));

          return [_, _];
        });
      }, t.prototype.getConfig = function () {
        var t = {
          units: this.units,
          activation: serializeActivation(this.activation),
          recurrentActivation: serializeActivation(this.recurrentActivation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          recurrentInitializer: serializeInitializer(this.recurrentInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          recurrentConstraint: serializeConstraint(this.recurrentConstraint),
          biasConstraint: 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.className = "GRUCell", t;
    }(RNNCell);

    _tfjsCore.serialization.registerClass(GRUCell);

    var GRU = 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 GRUCell(t), e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.call = function (t, n) {
        var r = this;
        return (0, _tfjsCore.tidy)(function () {
          null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
          var i = null == n ? null : n.mask,
            a = null == n ? null : n.training,
            o = null == n ? null : n.initialState;
          return e.prototype.call.call(r, t, {
            mask: i,
            training: a,
            initialState: o
          });
        });
      }, 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, "recurrentActivation", {
        get: function () {
          return this.cell.recurrentActivation;
        },
        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: serializeActivation(this.activation),
          recurrentActivation: serializeActivation(this.recurrentActivation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          recurrentInitializer: serializeInitializer(this.recurrentInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          recurrentConstraint: serializeConstraint(this.recurrentConstraint),
          biasConstraint: serializeConstraint(this.biasConstraint),
          dropout: this.dropout,
          recurrentDropout: this.recurrentDropout,
          implementation: this.implementation
        },
          n = e.prototype.getConfig.call(this);
        return delete n.cell, Object.assign(t, n), t;
      }, t.fromConfig = function (e, t) {
        return 0 === t.implmentation && (t.implementation = 1), new e(t);
      }, t.className = "GRU", t;
    }(RNN);

    _tfjsCore.serialization.registerClass(GRU);

    var LSTMCell = 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, assertPositiveInteger(n.units, "units"), n.activation = getActivation(void 0 === t.activation ? n.DEFAULT_ACTIVATION : t.activation), n.recurrentActivation = getActivation(void 0 === t.recurrentActivation ? n.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), n.useBias = null == t.useBias || t.useBias, n.kernelInitializer = getInitializer(t.kernelInitializer || n.DEFAULT_KERNEL_INITIALIZER), n.recurrentInitializer = getInitializer(t.recurrentInitializer || n.DEFAULT_RECURRENT_INITIALIZER), n.biasInitializer = getInitializer(t.biasInitializer || n.DEFAULT_BIAS_INITIALIZER), n.unitForgetBias = t.unitForgetBias, n.kernelRegularizer = getRegularizer(t.kernelRegularizer), n.recurrentRegularizer = getRegularizer(t.recurrentRegularizer), n.biasRegularizer = getRegularizer(t.biasRegularizer), n.kernelConstraint = getConstraint(t.kernelConstraint), n.recurrentConstraint = getConstraint(t.recurrentConstraint), n.biasConstraint = getConstraint(t.biasConstraint), n.dropout = min$1([1, max$1([0, null == t.dropout ? 0 : t.dropout])]), n.recurrentDropout = min$1([1, max$1([0, null == t.recurrentDropout ? 0 : t.recurrentDropout])]), n.implementation = t.implementation, n.stateSize = [n.units, n.units], n.dropoutMask = null, n.recurrentDropoutMask = null, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        var t,
          n,
          r = (e = getExactlyOneShape(e))[e.length - 1];

        if (this.kernel = this.addWeight("kernel", [r, 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), this.useBias) {
          if (this.unitForgetBias) {
            var i = this.biasInitializer,
              a = this.units;
            n = new ((t = function (e) {
              function t() {
                return null !== e && e.apply(this, arguments) || this;
              }

              return __extends(t, e), t.prototype.apply = function (e, t) {
                var n = i.apply([a]),
                  r = new Ones().apply([a]),
                  o = i.apply([2 * a]);
                return concatAlongFirstAxis(concatAlongFirstAxis(n, r), o);
              }, t;
            }(Initializer)).className = "CustomInit", t)();
          } 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) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          var r = null != t.training && t.training;
          if (3 !== (e = e).length) throw new ValueError("LSTMCell expects 3 input Tensors (inputs, h, c), got " + e.length + ".");
          var i = e[1],
            a = e[2];
          e = e[0], 0 < n.dropout && n.dropout < 1 && null == n.dropoutMask && (n.dropoutMask = generateDropoutMask(function () {
            return (0, _tfjsCore.onesLike)(e);
          }, n.dropout, r, 4)), 0 < n.recurrentDropout && n.recurrentDropout < 1 && null == n.recurrentDropoutMask && (n.recurrentDropoutMask = generateDropoutMask(function () {
            return (0, _tfjsCore.onesLike)(i);
          }, n.recurrentDropout, r, 4));
          var o,
            s,
            l,
            u,
            c = n.dropoutMask,
            p = n.recurrentDropoutMask;
          0 < n.dropout && n.dropout < 1 && (e = (0, _tfjsCore.mul)(e, c[0]));
          var h = dot(e, n.kernel.read());
          0 < n.recurrentDropout && n.recurrentDropout < 1 && (i = (0, _tfjsCore.mul)(i, p[0])), h = (0, _tfjsCore.add)(h, dot(i, n.recurrentKernel.read())), n.useBias && (h = biasAdd(h, n.bias.read()));
          var d = (0, _tfjsCore.split)(h, 4, h.rank - 1),
            f = d[0],
            g = d[1],
            m = d[2],
            y = d[3];
          o = n.recurrentActivation.apply(f), s = n.recurrentActivation.apply(g), l = (0, _tfjsCore.add)((0, _tfjsCore.mul)(s, a), (0, _tfjsCore.mul)(o, n.activation.apply(m))), u = n.recurrentActivation.apply(y);
          var v = (0, _tfjsCore.mul)(u, n.activation.apply(l));
          return [v, v, l];
        });
      }, t.prototype.getConfig = function () {
        var t = {
          units: this.units,
          activation: serializeActivation(this.activation),
          recurrentActivation: serializeActivation(this.recurrentActivation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          recurrentInitializer: serializeInitializer(this.recurrentInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          unitForgetBias: this.unitForgetBias,
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          recurrentConstraint: serializeConstraint(this.recurrentConstraint),
          biasConstraint: 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.className = "LSTMCell", t;
    }(RNNCell);

    _tfjsCore.serialization.registerClass(LSTMCell);

    var LSTM = 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 LSTMCell(t), e.call(this, t) || this;
      }

      return __extends(t, e), t.prototype.call = function (t, n) {
        var r = this;
        return (0, _tfjsCore.tidy)(function () {
          null != r.cell.dropoutMask && ((0, _tfjsCore.dispose)(r.cell.dropoutMask), r.cell.dropoutMask = null), null != r.cell.recurrentDropoutMask && ((0, _tfjsCore.dispose)(r.cell.recurrentDropoutMask), r.cell.recurrentDropoutMask = null);
          var i = null == n ? null : n.mask,
            a = null == n ? null : n.training,
            o = null == n ? null : n.initialState;
          return e.prototype.call.call(r, t, {
            mask: i,
            training: a,
            initialState: o
          });
        });
      }, 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, "recurrentActivation", {
        get: function () {
          return this.cell.recurrentActivation;
        },
        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: serializeActivation(this.activation),
          recurrentActivation: serializeActivation(this.recurrentActivation),
          useBias: this.useBias,
          kernelInitializer: serializeInitializer(this.kernelInitializer),
          recurrentInitializer: serializeInitializer(this.recurrentInitializer),
          biasInitializer: serializeInitializer(this.biasInitializer),
          unitForgetBias: this.unitForgetBias,
          kernelRegularizer: serializeRegularizer(this.kernelRegularizer),
          recurrentRegularizer: serializeRegularizer(this.recurrentRegularizer),
          biasRegularizer: serializeRegularizer(this.biasRegularizer),
          activityRegularizer: serializeRegularizer(this.activityRegularizer),
          kernelConstraint: serializeConstraint(this.kernelConstraint),
          recurrentConstraint: serializeConstraint(this.recurrentConstraint),
          biasConstraint: serializeConstraint(this.biasConstraint),
          dropout: this.dropout,
          recurrentDropout: this.recurrentDropout,
          implementation: this.implementation
        },
          n = e.prototype.getConfig.call(this);
        return delete n.cell, Object.assign(t, n), t;
      }, t.fromConfig = function (e, t) {
        return 0 === t.implmentation && (t.implementation = 1), new e(t);
      }, t.className = "LSTM", t;
    }(RNN);

    _tfjsCore.serialization.registerClass(LSTM);

    var StackedRNNCells = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.cells = t.cells, n;
      }

      return __extends(t, e), Object.defineProperty(t.prototype, "stateSize", {
        get: function () {
          for (var e = [], t = 0, n = this.cells.slice().reverse(); t < n.length; t++) {
            var r = n[t];
            Array.isArray(r.stateSize) ? e.push.apply(e, r.stateSize) : e.push(r.stateSize);
          }

          return e;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.call = function (e, t) {
        var n = this;
        return (0, _tfjsCore.tidy)(function () {
          for (var r = (e = e).slice(1), i = [], a = 0, o = n.cells.slice().reverse(); a < o.length; a++) {
            var s = o[a];
            Array.isArray(s.stateSize) ? i.push(r.splice(0, s.stateSize.length)) : i.push(r.splice(0, 1));
          }

          i.reverse();

          for (var l, u = [], c = 0; c < n.cells.length; ++c) {
            s = n.cells[c];
            r = i[c], l = 0 === c ? [e[0]].concat(r) : [l[0]].concat(r), l = s.call(l, t), u.push(l.slice(1));
          }

          r = [];

          for (var p = 0, h = u.slice().reverse(); p < h.length; p++) {
            var d = h[p];
            r.push.apply(r, d);
          }

          return [l[0]].concat(r);
        });
      }, t.prototype.build = function (e) {
        var t;
        isArrayOfShapes(e) && (e = e[0]), e = e, this.cells.forEach(function (n, r) {
          nameScope("RNNCell_" + r, function () {
            n.build(e), t = Array.isArray(n.stateSize) ? n.stateSize[0] : n.stateSize, e = [e[0], t];
          });
        }), this.built = !0;
      }, t.prototype.getConfig = function () {
        for (var t = [], n = 0, r = this.cells; n < r.length; n++) {
          var i = r[n];
          t.push({
            className: i.getClassName(),
            config: i.getConfig()
          });
        }

        var a = {
          cells: t
        },
          o = e.prototype.getConfig.call(this);
        return Object.assign(a, o), a;
      }, t.fromConfig = function (e, t, n) {
        void 0 === n && (n = {});

        for (var r = [], i = 0, a = t.cells; i < a.length; i++) {
          var o = a[i];
          r.push(deserialize(o, n));
        }

        return new e({
          cells: r
        });
      }, Object.defineProperty(t.prototype, "trainableWeights", {
        get: function () {
          if (!this.trainable) return [];

          for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
            var r = n[t];
            e.push.apply(e, r.trainableWeights);
          }

          return e;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
        get: function () {
          for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
            var r = n[t];
            e.push.apply(e, r.nonTrainableWeights);
          }

          if (!this.trainable) {
            for (var i = [], a = 0, o = this.cells; a < o.length; a++) {
              r = o[a];
              i.push.apply(i, r.trainableWeights);
            }

            return i.concat(e);
          }

          return e;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.getWeights = function () {
        for (var e = [], t = 0, n = this.cells; t < n.length; t++) {
          var r = n[t];
          e.push.apply(e, r.weights);
        }

        return batchGetValue(e);
      }, t.prototype.setWeights = function (e) {
        for (var t = [], n = 0, r = this.cells; n < r.length; n++) for (var i = r[n], a = i.weights.length, o = e.splice(a), s = 0; s < i.weights.length; ++s) t.push([i.weights[s], o[s]]);

        batchSetValue(t);
      }, t.className = "StackedRNNCells", t;
    }(RNNCell);

    function generateDropoutMask(e, t, n, r) {
      function i() {
        return dropout$1(e(), t);
      }

      if (void 0 === n && (n = null), void 0 === r && (r = 1), r > 1) {
        for (var a = [], o = 0; o < r; o++) a.push(inTrainPhase(i, e, n));

        return a.map(function (e) {
          return (0, _tfjsCore.keep)(e.clone());
        });
      }

      return (0, _tfjsCore.keep)(inTrainPhase(i, e, n).clone());
    }

    _tfjsCore.serialization.registerClass(StackedRNNCells);

    var Wrapper = function (e) {
      function t(t) {
        var n = e.call(this, t) || this;
        return n.layer = t.layer, n;
      }

      return __extends(t, e), t.prototype.build = function (e) {
        this.built = !0;
      }, Object.defineProperty(t.prototype, "trainable", {
        get: function () {
          return null != this.layer && this.layer.trainable;
        },
        set: function (e) {
          null != this.layer && (this.layer.trainable = e);
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "trainableWeights", {
        get: function () {
          return this.layer.trainableWeights;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "nonTrainableWeights", {
        get: function () {
          return this.layer.nonTrainableWeights;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "updates", {
        get: function () {
          return this.layer._updates;
        },
        enumerable: !0,
        configurable: !0
      }), Object.defineProperty(t.prototype, "losses", {
        get: function () {
          return this.layer.losses;
        },
        enumerable: !0,
        configurable: !0
      }), t.prototype.getWeights = function () {
        return this.layer.getWeights();
      }, t.prototype.setWeights = function (e) {
        this.layer.setWeights(e);
      }, t.prototype.getConfig = function () {
        var t = {
          layer: {
            className: this.layer.getClassName(),
            config: this.layer.getConfig()
          }
        },
          n = e.prototype.getConfig.call(this);
        return Object.assign(t, n), t;
      }, t.prototype.setFastWeightInitDuringBuild = function (t) {
        e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.layer && this.layer.setFastWeightInitDuringBuild(t);
      }, t.fromConfig = function (e, t, n) {
        void 0 === n && (n = {});
        var r = deserialize(t.layer, n);
        delete t.layer;
        var i = {
          layer: r
        };
        return Object.assign(i, t), new e(i);
      }, t;
    }(Layer),
      TimeDistributed = function (e) {
        function t(t) {
          var n = e.call(this, t) || this;
          return n.supportsMasking = !0, n;
        }

        return __extends(t, e), t.prototype.build = function (t) {
          if ((t = getExactlyOneShape(t)).length < 3) throw new ValueError("TimeDistributed layer expects an input shape >= 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 = 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;
          return (0, _tfjsCore.tidy)(function () {
            return rnn(function (e, r) {
              return [getExactlyOneTensor(n.layer.call(e, t)), []];
            }, e = getExactlyOneTensor(e), [], !1, null, null, !1, !0)[1];
          });
        }, t.className = "TimeDistributed", t;
      }(Wrapper);

    function checkBidirectionalMergeMode(e) {
      checkStringTypeUnionValue(VALID_BIDIRECTIONAL_MERGE_MODES, "BidirectionalMergeMode", e);
    }

    _tfjsCore.serialization.registerClass(TimeDistributed);

    var DEFAULT_BIDIRECTIONAL_MERGE_MODE = "concat",
      Bidirectional = function (e) {
        function t(t) {
          var n = e.call(this, t) || this,
            r = t.layer.getConfig(),
            i = {};
          i.className = t.layer.getClassName(), i.config = r, n.forwardLayer = deserialize(i), r.goBackwards = !0 !== r.goBackwards;
          var a = {};
          if (a.className = t.layer.getClassName(), a.config = r, n.backwardLayer = deserialize(a), n.forwardLayer.name = "forward_" + n.forwardLayer.name, n.backwardLayer.name = "backward_" + n.backwardLayer.name, n.mergeMode = void 0 === t.mergeMode ? DEFAULT_BIDIRECTIONAL_MERGE_MODE : t.mergeMode, checkBidirectionalMergeMode(n.mergeMode), t.weights) throw new 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.numConstants = null, n;
        }

        return __extends(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,
            n,
            r,
            i = this.forwardLayer.computeOutputShape(e);
          return Array.isArray(i) && Array.isArray(i[0]) || (i = [i]), i = i, this.returnState ? (r = i.slice(1), t = i[0]) : t = i[0], t = t, "concat" === this.mergeMode ? (t[t.length - 1] *= 2, n = [t]) : n = null == this.mergeMode ? [t, t.slice()] : [t], this.returnState ? null == this.mergeMode ? n.concat(r).concat(r.slice()) : [t].concat(r).concat(r.slice()) : singletonOrArray(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 = standardizeArgs(t, r, i, this.numConstants);
          if (t = a.inputs, r = a.initialState, i = a.constants, Array.isArray(t) && (r = t.slice(1), t = t[0]), (null == r || 0 === r.length) && null == i) return e.prototype.apply.call(this, t, n);
          var o = [],
            s = [];

          if (null != r) {
            var l = r.length;
            if (l % 2 > 0) throw new ValueError("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");
            n.initialState = r, o.push.apply(o, r);
            var u = r.map(function (e) {
              return new InputSpec({
                shape: e.shape
              });
            });
            this.forwardLayer.stateSpec = u.slice(0, l / 2), this.backwardLayer.stateSpec = u.slice(l / 2), s.push.apply(s, u);
          }

          if (null != i) throw new NotImplementedError("Support for constants in Bidirectional layers is not implemented yet.");

          for (var c = o[0] instanceof SymbolicTensor, p = 0, h = o; p < h.length; p++) {
            if (h[p] instanceof SymbolicTensor !== c) throw new ValueError("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors");
          }

          if (c) {
            var d = [t].concat(o),
              f = this.inputSpec.concat(s),
              g = this.inputSpec;
            this.inputSpec = f;
            var m = e.prototype.apply.call(this, d, n);
            return this.inputSpec = g, m;
          }

          return e.prototype.apply.call(this, t, n);
        }, t.prototype.call = function (e, t) {
          var n = this;
          return (0, _tfjsCore.tidy)(function () {
            if (null != t.mask) throw new NotImplementedError("The support for masking is not implemented for Bidirectional layers yet.");
            var r,
              i,
              a,
              o,
              s = t.initialState;
            if (null == s) r = n.forwardLayer.call(e, t), i = n.backwardLayer.call(e, t); else {
              var l = s.slice(0, s.length / 2),
                u = s.slice(s.length / 2);
              r = n.forwardLayer.call(e, Object.assign(t, {
                initialState: l
              })), i = n.backwardLayer.call(e, Object.assign(t, {
                initialState: u
              }));
            }
            return n.returnState && (Array.isArray(r) && (a = r.slice(1).concat(i.slice(1))), r = r[0], i = i[0]), n.returnSequences && (i = (0, _tfjsCore.reverse)(i, 1)), "concat" === n.mergeMode ? o = concatenate([r, i]) : "sum" === n.mergeMode ? o = (0, _tfjsCore.add)(r, i) : "ave" === n.mergeMode ? o = (0, _tfjsCore.mul)(.5, (0, _tfjsCore.add)(r, i)) : "mul" === n.mergeMode ? o = (0, _tfjsCore.mul)(r, i) : null == n.mergeMode && (o = [r, i]), n.returnState ? null == n.mergeMode ? o.concat(a) : [o].concat(a) : o;
          });
        }, t.prototype.resetStates = function (e) {
          this.forwardLayer.resetStates(), this.backwardLayer.resetStates();
        }, t.prototype.build = function (e) {
          var t = this;
          nameScope(this.forwardLayer.name, function () {
            t.forwardLayer.build(e);
          }), 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.prototype.setFastWeightInitDuringBuild = function (t) {
          e.prototype.setFastWeightInitDuringBuild.call(this, t), null != this.forwardLayer && this.forwardLayer.setFastWeightInitDuringBuild(t), null != this.backwardLayer && this.backwardLayer.setFastWeightInitDuringBuild(t);
        }, t.prototype.getConfig = function () {
          var t = {
            mergeMode: this.mergeMode
          },
            n = e.prototype.getConfig.call(this);
          return Object.assign(t, n), t;
        }, t.fromConfig = function (e, t) {
          var n = deserialize(t.layer);
          if (delete t.layer, null != t.numConstants) throw new NotImplementedError("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");
          var r = t;
          return r.layer = n, new e(r);
        }, t.className = "Bidirectional", t;
      }(Wrapper);

    function inputLayer(e) {
      return new InputLayer(e);
    }

    function elu$2(e) {
      return new ELU(e);
    }

    function reLU(e) {
      return new ReLU(e);
    }

    function leakyReLU(e) {
      return new LeakyReLU(e);
    }

    function prelu$1(e) {
      return new PReLU(e);
    }

    function softmax$1(e) {
      return new Softmax$1(e);
    }

    function thresholdedReLU(e) {
      return new ThresholdedReLU(e);
    }

    function conv1d$2(e) {
      return new Conv1D(e);
    }

    function conv2d$1(e) {
      return new Conv2D(e);
    }

    function conv2dTranspose$1(e) {
      return new Conv2DTranspose(e);
    }

    function conv3d$2(e) {
      return new Conv3D(e);
    }

    function separableConv2d$1(e) {
      return new SeparableConv2D(e);
    }

    function cropping2D(e) {
      return new Cropping2D(e);
    }

    function upSampling2d(e) {
      return new UpSampling2D(e);
    }

    function depthwiseConv2d$2(e) {
      return new DepthwiseConv2D(e);
    }

    function activation(e) {
      return new Activation$1(e);
    }

    function dense(e) {
      return new Dense(e);
    }

    function dropout$2(e) {
      return new Dropout(e);
    }

    function flatten$1(e) {
      return new Flatten(e);
    }

    function repeatVector(e) {
      return new RepeatVector(e);
    }

    function reshape(e) {
      return new Reshape(e);
    }

    function permute(e) {
      return new Permute(e);
    }

    function embedding(e) {
      return new Embedding(e);
    }

    function add$2(e) {
      return new Add(e);
    }

    function average$1(e) {
      return new Average(e);
    }

    function concatenate$2(e) {
      return new Concatenate(e);
    }

    function maximum$2(e) {
      return new Maximum(e);
    }

    function minimum$2(e) {
      return new Minimum(e);
    }

    function multiply$1(e) {
      return new Multiply(e);
    }

    function dot$1(e) {
      return new Dot(e);
    }

    function batchNormalization$1(e) {
      return new BatchNormalization(e);
    }

    function layerNormalization(e) {
      return new LayerNormalization(e);
    }

    function zeroPadding2d(e) {
      return new ZeroPadding2D(e);
    }

    function averagePooling1d(e) {
      return new AveragePooling1D(e);
    }

    function avgPool1d(e) {
      return averagePooling1d(e);
    }

    function avgPooling1d(e) {
      return averagePooling1d(e);
    }

    function averagePooling2d(e) {
      return new AveragePooling2D(e);
    }

    function avgPool2d(e) {
      return averagePooling2d(e);
    }

    function avgPooling2d(e) {
      return averagePooling2d(e);
    }

    function averagePooling3d(e) {
      return new AveragePooling3D(e);
    }

    function avgPool3d$1(e) {
      return averagePooling3d(e);
    }

    function avgPooling3d(e) {
      return averagePooling3d(e);
    }

    function globalAveragePooling1d(e) {
      return new GlobalAveragePooling1D(e);
    }

    function globalAveragePooling2d(e) {
      return new GlobalAveragePooling2D(e);
    }

    function globalMaxPooling1d(e) {
      return new GlobalMaxPooling1D(e);
    }

    function globalMaxPooling2d(e) {
      return new GlobalMaxPooling2D(e);
    }

    function maxPooling1d(e) {
      return new MaxPooling1D(e);
    }

    function maxPooling2d(e) {
      return new MaxPooling2D(e);
    }

    function maxPooling3d(e) {
      return new MaxPooling3D(e);
    }

    function gru(e) {
      return new GRU(e);
    }

    function gruCell(e) {
      return new GRUCell(e);
    }

    function lstm(e) {
      return new LSTM(e);
    }

    function lstmCell(e) {
      return new LSTMCell(e);
    }

    function simpleRNN(e) {
      return new SimpleRNN(e);
    }

    function simpleRNNCell(e) {
      return new SimpleRNNCell(e);
    }

    function rnn$1(e) {
      return new RNN(e);
    }

    function stackedRNNCells(e) {
      return new StackedRNNCells(e);
    }

    function bidirectional(e) {
      return new Bidirectional(e);
    }

    function timeDistributed(e) {
      return new TimeDistributed(e);
    }

    _tfjsCore.serialization.registerClass(Bidirectional);

    var globalMaxPool1d = globalMaxPooling1d,
      globalMaxPool2d = globalMaxPooling2d,
      maxPool1d = maxPooling1d,
      maxPool2d = maxPooling2d;

    function gaussianNoise(e) {
      return new GaussianNoise(e);
    }

    function gaussianDropout(e) {
      return new GaussianDropout(e);
    }

    function alphaDropout(e) {
      return new AlphaDropout(e);
    }

    function masking(e) {
      return new Masking(e);
    }

    var exports_layers = Object.freeze({
      inputLayer: inputLayer,
      elu: elu$2,
      reLU: reLU,
      leakyReLU: leakyReLU,
      prelu: prelu$1,
      softmax: softmax$1,
      thresholdedReLU: thresholdedReLU,
      conv1d: conv1d$2,
      conv2d: conv2d$1,
      conv2dTranspose: conv2dTranspose$1,
      conv3d: conv3d$2,
      separableConv2d: separableConv2d$1,
      cropping2D: cropping2D,
      upSampling2d: upSampling2d,
      depthwiseConv2d: depthwiseConv2d$2,
      activation: activation,
      dense: dense,
      dropout: dropout$2,
      flatten: flatten$1,
      repeatVector: repeatVector,
      reshape: reshape,
      permute: permute,
      embedding: embedding,
      add: add$2,
      average: average$1,
      concatenate: concatenate$2,
      maximum: maximum$2,
      minimum: minimum$2,
      multiply: multiply$1,
      dot: dot$1,
      batchNormalization: batchNormalization$1,
      layerNormalization: layerNormalization,
      zeroPadding2d: zeroPadding2d,
      averagePooling1d: averagePooling1d,
      avgPool1d: avgPool1d,
      avgPooling1d: avgPooling1d,
      averagePooling2d: averagePooling2d,
      avgPool2d: avgPool2d,
      avgPooling2d: avgPooling2d,
      averagePooling3d: averagePooling3d,
      avgPool3d: avgPool3d$1,
      avgPooling3d: avgPooling3d,
      globalAveragePooling1d: globalAveragePooling1d,
      globalAveragePooling2d: globalAveragePooling2d,
      globalMaxPooling1d: globalMaxPooling1d,
      globalMaxPooling2d: globalMaxPooling2d,
      maxPooling1d: maxPooling1d,
      maxPooling2d: maxPooling2d,
      maxPooling3d: maxPooling3d,
      gru: gru,
      gruCell: gruCell,
      lstm: lstm,
      lstmCell: lstmCell,
      simpleRNN: simpleRNN,
      simpleRNNCell: simpleRNNCell,
      rnn: rnn$1,
      stackedRNNCells: stackedRNNCells,
      bidirectional: bidirectional,
      timeDistributed: timeDistributed,
      globalMaxPool1d: globalMaxPool1d,
      globalMaxPool2d: globalMaxPool2d,
      maxPool1d: maxPool1d,
      maxPool2d: maxPool2d,
      Layer: Layer,
      RNN: RNN,
      RNNCell: RNNCell,
      input: input,
      gaussianNoise: gaussianNoise,
      gaussianDropout: gaussianDropout,
      alphaDropout: alphaDropout,
      masking: masking
    });
    exports.layers = exports_layers;

    function binaryAccuracy$1(e, t) {
      return binaryAccuracy(e, t);
    }

    function binaryCrossentropy$2(e, t) {
      return binaryCrossentropy$1(e, t);
    }

    function sparseCategoricalAccuracy$1(e, t) {
      return sparseCategoricalAccuracy(e, t);
    }

    function categoricalAccuracy$1(e, t) {
      return categoricalAccuracy(e, t);
    }

    function categoricalCrossentropy$2(e, t) {
      return categoricalCrossentropy$1(e, t);
    }

    function precision$1(e, t) {
      return precision(e, t);
    }

    function recall$1(e, t) {
      return recall(e, t);
    }

    function cosineProximity$1(e, t) {
      return cosineProximity(e, t);
    }

    function meanAbsoluteError$1(e, t) {
      return meanAbsoluteError(e, t);
    }

    function meanAbsolutePercentageError$1(e, t) {
      return meanAbsolutePercentageError(e, t);
    }

    function MAPE$2(e, t) {
      return meanAbsolutePercentageError(e, t);
    }

    function mape$2(e, t) {
      return meanAbsolutePercentageError(e, t);
    }

    function meanSquaredError$1(e, t) {
      return meanSquaredError(e, t);
    }

    function MSE$2(e, t) {
      return meanSquaredError(e, t);
    }

    function mse$2(e, t) {
      return meanSquaredError(e, t);
    }

    var exports_metrics = Object.freeze({
      binaryAccuracy: binaryAccuracy$1,
      binaryCrossentropy: binaryCrossentropy$2,
      sparseCategoricalAccuracy: sparseCategoricalAccuracy$1,
      categoricalAccuracy: categoricalAccuracy$1,
      categoricalCrossentropy: categoricalCrossentropy$2,
      precision: precision$1,
      recall: recall$1,
      cosineProximity: cosineProximity$1,
      meanAbsoluteError: meanAbsoluteError$1,
      meanAbsolutePercentageError: meanAbsolutePercentageError$1,
      MAPE: MAPE$2,
      mape: mape$2,
      meanSquaredError: meanSquaredError$1,
      MSE: MSE$2,
      mse: mse$2
    }),
      exports_models = Object.freeze({
        modelFromJSON: modelFromJSON
      });
    exports.models = exports_models;
    exports.metrics = exports_metrics;

    function l1l2(e) {
      return new L1L2(e);
    }

    function l1$1(e) {
      return l1(e);
    }

    function l2$1(e) {
      return l2(e);
    }

    var exports_regularizers = Object.freeze({
      l1l2: l1l2,
      l1: l1$1,
      l2: l2$1
    }),
      Callback = function (e) {
        function t() {
          var t = null !== e && e.apply(this, arguments) || this;
          return t.model = null, t;
        }

        return __extends(t, e), t.prototype.setModel = function (e) {
          if (!(e instanceof LayersModel)) throw new Error("model must be a LayersModel, not some other Container");
          this.model = e;
        }, t;
      }(BaseCallback);

    exports.Callback = Callback;
    exports.regularizers = exports_regularizers;

    function less(e, t) {
      return e < t;
    }

    function greater$1(e, t) {
      return e > t;
    }

    var EarlyStopping = function (e) {
      function t(t) {
        var n = e.call(this) || this;
        if (null == t && (t = {}), t.restoreBestWeights) throw new NotImplementedError("restoreBestWeights = True is not implemented in EarlyStopping yet.");
        return n.monitor = t.monitor || "val_loss", n.minDelta = Math.abs(t.minDelta || 0), n.patience = t.patience || 0, n.verbose = t.verbose || 0, n.mode = t.mode || "auto", n.baseline = t.baseline, -1 === ["auto", "min", "max"].indexOf(n.mode) && (console.warn("EarlyStopping mode '" + n.mode + "' is invalid. Falling back to mode 'auto'."), n.mode = "auto"), "min" === n.mode ? n.monitorFunc = less : "max" === n.mode ? n.monitorFunc = greater$1 : -1 !== n.monitor.indexOf("acc") ? n.monitorFunc = greater$1 : n.monitorFunc = less, n.monitorFunc === less && (n.minDelta *= -1), n;
      }

      return __extends(t, e), t.prototype.onTrainBegin = function (e) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (e) {
            return this.wait = 0, this.stoppedEpoch = 0, null != this.baseline ? this.best = this.baseline : this.best = this.monitorFunc === less ? 1 / 0 : -1 / 0, [2];
          });
        });
      }, t.prototype.onEpochEnd = function (e, t) {
        return __awaiter(this, void 0, void 0, function () {
          var n;
          return __generator(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, resolveScalarsInLogs(t)];

              case 1:
                return r.sent(), null == (n = this.getMonitorValue(t)) ? [2] : (this.monitorFunc(n - this.minDelta, this.best) ? (this.best = n, this.wait = 0) : (this.wait++, this.wait >= this.patience && (this.stoppedEpoch = e, this.model.stopTraining = !0)), [2]);
            }
          });
        });
      }, t.prototype.onTrainEnd = function (e) {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (e) {
            return this.stoppedEpoch > 0 && this.verbose && console.log("Epoch " + this.stoppedEpoch + ": early stopping."), [2];
          });
        });
      }, t.prototype.getMonitorValue = function (e) {
        null == e && (e = {});
        var t = e[this.monitor];
        return null == t && console.warn("Metric for EarlyStopping " + this.monitor + " is not available. Available metrics are: " + Object.keys(e)), t;
      }, t;
    }(Callback);

    exports.EarlyStopping = EarlyStopping;

    function earlyStopping(e) {
      return new EarlyStopping(e);
    }

    var callbacks = {
      earlyStopping: earlyStopping
    };
    exports.callbacks = callbacks;
  }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js" }], "node_modules/@tensorflow/tfjs-data/dist/tf-data.esm.js": [function (require, module, exports) {
    var global = arguments[3];
    var Buffer = require("buffer").Buffer;
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.array = array;
    exports.zip = zip;
    exports.csv = csv;
    exports.func = func;
    exports.generator = generator;
    exports.microphone = microphone;
    exports.webcam = webcam;
    exports.version_data = exports.URLDataSource = exports.FileDataSource = exports.TextLineDataset = exports.CSVDataset = exports.Dataset = void 0;

    var _tfjsCore = require("@tensorflow/tfjs-core");

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    var extendStatics = function (t, e) {
      return (extendStatics = Object.setPrototypeOf || {
        __proto__: []
      } instanceof Array && function (t, e) {
        t.__proto__ = e;
      } || function (t, e) {
        for (var r in e) e.hasOwnProperty(r) && (t[r] = e[r]);
      })(t, e);
    };

    function __extends(t, e) {
      function r() {
        this.constructor = t;
      }

      extendStatics(t, e), t.prototype = null === e ? Object.create(e) : (r.prototype = e.prototype, new r());
    }

    function __awaiter(t, e, r, n) {
      return new (r || (r = Promise))(function (i, o) {
        function a(t) {
          try {
            u(n.next(t));
          } catch (t) {
            o(t);
          }
        }

        function s(t) {
          try {
            u(n.throw(t));
          } catch (t) {
            o(t);
          }
        }

        function u(t) {
          t.done ? i(t.value) : new r(function (e) {
            e(t.value);
          }).then(a, s);
        }

        u((n = n.apply(t, e || [])).next());
      });
    }

    function __generator(t, e) {
      var r,
        n,
        i,
        o,
        a = {
          label: 0,
          sent: function () {
            if (1 & i[0]) throw i[1];
            return i[1];
          },
          trys: [],
          ops: []
        };
      return o = {
        next: s(0),
        throw: s(1),
        return: s(2)
      }, "function" == typeof Symbol && (o[Symbol.iterator] = function () {
        return this;
      }), o;

      function s(o) {
        return function (s) {
          return function (o) {
            if (r) throw new TypeError("Generator is already executing.");

            for (; a;) try {
              if (r = 1, n && (i = 2 & o[0] ? n.return : o[0] ? n.throw || ((i = n.return) && i.call(n), 0) : n.next) && !(i = i.call(n, o[1])).done) return i;

              switch (n = 0, i && (o = [2 & o[0], i.value]), o[0]) {
                case 0:
                case 1:
                  i = o;
                  break;

                case 4:
                  return a.label++, {
                    value: o[1],
                    done: !1
                  };

                case 5:
                  a.label++, n = o[1], o = [0];
                  continue;

                case 7:
                  o = a.ops.pop(), a.trys.pop();
                  continue;

                default:
                  if (!(i = (i = a.trys).length > 0 && i[i.length - 1]) && (6 === o[0] || 2 === o[0])) {
                    a = 0;
                    continue;
                  }

                  if (3 === o[0] && (!i || o[1] > i[0] && o[1] < i[3])) {
                    a.label = o[1];
                    break;
                  }

                  if (6 === o[0] && a.label < i[1]) {
                    a.label = i[1], i = o;
                    break;
                  }

                  if (i && a.label < i[2]) {
                    a.label = i[2], a.ops.push(o);
                    break;
                  }

                  i[2] && a.ops.pop(), a.trys.pop();
                  continue;
              }

              o = e.call(t, a);
            } catch (t) {
              o = [6, t], n = 0;
            } finally {
                r = i = 0;
              }

            if (5 & o[0]) throw o[1];
            return {
              value: o[0] ? o[1] : void 0,
              done: !0
            };
          }([o, s]);
        };
      }
    }

    var commonjsGlobal = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : {};

    function createCommonjsModule(t, e) {
      return t(e = {
        exports: {}
      }, e.exports), e.exports;
    }

    var alea = createCommonjsModule(function (t) {
      !function (t, e, r) {
        function n(t, e) {
          return e.c = t.c, e.s0 = t.s0, e.s1 = t.s1, e.s2 = t.s2, e;
        }

        function i(t, e) {
          var r = new function (t) {
            var e,
              r = this,
              n = (e = 4022871197, function (t) {
                t = t.toString();

                for (var r = 0; r < t.length; r++) {
                  var n = .02519603282416938 * (e += t.charCodeAt(r));
                  n -= e = n >>> 0, e = (n *= e) >>> 0, e += 4294967296 * (n -= e);
                }

                return 2.3283064365386963e-10 * (e >>> 0);
              });
            r.next = function () {
              var t = 2091639 * r.s0 + 2.3283064365386963e-10 * r.c;
              return r.s0 = r.s1, r.s1 = r.s2, r.s2 = t - (r.c = 0 | t);
            }, r.c = 1, r.s0 = n(" "), r.s1 = n(" "), r.s2 = n(" "), r.s0 -= n(t), r.s0 < 0 && (r.s0 += 1), r.s1 -= n(t), r.s1 < 0 && (r.s1 += 1), r.s2 -= n(t), r.s2 < 0 && (r.s2 += 1), n = null;
          }(t),
            i = e && e.state,
            o = r.next;
          return o.int32 = function () {
            return 4294967296 * r.next() | 0;
          }, o.double = function () {
            return o() + 1.1102230246251565e-16 * (2097152 * o() | 0);
          }, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
            return n(r, {});
          }), o;
        }

        e && e.exports ? e.exports = i : r && r.amd ? r(function () {
          return i;
        }) : this.alea = i;
      }(0, t, !1);
    }),
      xor128 = createCommonjsModule(function (t) {
        !function (t, e, r) {
          function n(t, e) {
            return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e;
          }

          function i(t, e) {
            var r = new function (t) {
              var e = this,
                r = "";
              e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.next = function () {
                var t = e.x ^ e.x << 11;
                return e.x = e.y, e.y = e.z, e.z = e.w, e.w ^= e.w >>> 19 ^ t ^ t >>> 8;
              }, t === (0 | t) ? e.x = t : r += t;

              for (var n = 0; n < r.length + 64; n++) e.x ^= 0 | r.charCodeAt(n), e.next();
            }(t),
              i = e && e.state,
              o = function () {
                return (r.next() >>> 0) / 4294967296;
              };

            return o.double = function () {
              do {
                var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
              return n(r, {});
            }), o;
          }

          e && e.exports ? e.exports = i : r && r.amd ? r(function () {
            return i;
          }) : this.xor128 = i;
        }(0, t, !1);
      }),
      xorwow = createCommonjsModule(function (t) {
        !function (t, e, r) {
          function n(t, e) {
            return e.x = t.x, e.y = t.y, e.z = t.z, e.w = t.w, e.v = t.v, e.d = t.d, e;
          }

          function i(t, e) {
            var r = new function (t) {
              var e = this,
                r = "";
              e.next = function () {
                var t = e.x ^ e.x >>> 2;
                return e.x = e.y, e.y = e.z, e.z = e.w, e.w = e.v, (e.d = e.d + 362437 | 0) + (e.v = e.v ^ e.v << 4 ^ t ^ t << 1) | 0;
              }, e.x = 0, e.y = 0, e.z = 0, e.w = 0, e.v = 0, t === (0 | t) ? e.x = t : r += t;

              for (var n = 0; n < r.length + 64; n++) e.x ^= 0 | r.charCodeAt(n), n == r.length && (e.d = e.x << 10 ^ e.x >>> 4), e.next();
            }(t),
              i = e && e.state,
              o = function () {
                return (r.next() >>> 0) / 4294967296;
              };

            return o.double = function () {
              do {
                var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
              return n(r, {});
            }), o;
          }

          e && e.exports ? e.exports = i : r && r.amd ? r(function () {
            return i;
          }) : this.xorwow = i;
        }(0, t, !1);
      }),
      xorshift7 = createCommonjsModule(function (t) {
        !function (t, e, r) {
          function n(t, e) {
            return e.x = t.x.slice(), e.i = t.i, e;
          }

          function i(t, e) {
            null == t && (t = +new Date());

            var r = new function (t) {
              var e = this;
              e.next = function () {
                var t,
                  r,
                  n = e.x,
                  i = e.i;
                return t = n[i], r = (t ^= t >>> 7) ^ t << 24, r ^= (t = n[i + 1 & 7]) ^ t >>> 10, r ^= (t = n[i + 3 & 7]) ^ t >>> 3, r ^= (t = n[i + 4 & 7]) ^ t << 7, t = n[i + 7 & 7], r ^= (t ^= t << 13) ^ t << 9, n[i] = r, e.i = i + 1 & 7, r;
              }, function (t, e) {
                var r,
                  n = [];
                if (e === (0 | e)) n[0] = e; else for (e = "" + e, r = 0; r < e.length; ++r) n[7 & r] = n[7 & r] << 15 ^ e.charCodeAt(r) + n[r + 1 & 7] << 13;

                for (; n.length < 8;) n.push(0);

                for (r = 0; r < 8 && 0 === n[r]; ++r);

                for (8 == r ? n[7] = -1 : n[r], t.x = n, t.i = 0, r = 256; r > 0; --r) t.next();
              }(e, t);
            }(t),
              i = e && e.state,
              o = function () {
                return (r.next() >>> 0) / 4294967296;
              };

            return o.double = function () {
              do {
                var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, o.int32 = r.next, o.quick = o, i && (i.x && n(i, r), o.state = function () {
              return n(r, {});
            }), o;
          }

          e && e.exports ? e.exports = i : r && r.amd ? r(function () {
            return i;
          }) : this.xorshift7 = i;
        }(0, t, !1);
      }),
      xor4096 = createCommonjsModule(function (t) {
        !function (t, e, r) {
          function n(t, e) {
            return e.i = t.i, e.w = t.w, e.X = t.X.slice(), e;
          }

          function i(t, e) {
            null == t && (t = +new Date());

            var r = new function (t) {
              var e = this;
              e.next = function () {
                var t,
                  r,
                  n = e.w,
                  i = e.X,
                  o = e.i;
                return e.w = n = n + 1640531527 | 0, r = i[o + 34 & 127], t = i[o = o + 1 & 127], r ^= r << 13, t ^= t << 17, r ^= r >>> 15, t ^= t >>> 12, r = i[o] = r ^ t, e.i = o, r + (n ^ n >>> 16) | 0;
              }, function (t, e) {
                var r,
                  n,
                  i,
                  o,
                  a,
                  s = [],
                  u = 128;

                for (e === (0 | e) ? (n = e, e = null) : (e += "\0", n = 0, u = Math.max(u, e.length)), i = 0, o = -32; o < u; ++o) e && (n ^= e.charCodeAt((o + 32) % e.length)), 0 === o && (a = n), n ^= n << 10, n ^= n >>> 15, n ^= n << 4, n ^= n >>> 13, o >= 0 && (a = a + 1640531527 | 0, i = 0 == (r = s[127 & o] ^= n + a) ? i + 1 : 0);

                for (i >= 128 && (s[127 & (e && e.length || 0)] = -1), i = 127, o = 512; o > 0; --o) n = s[i + 34 & 127], r = s[i = i + 1 & 127], n ^= n << 13, r ^= r << 17, n ^= n >>> 15, r ^= r >>> 12, s[i] = n ^ r;

                t.w = a, t.X = s, t.i = i;
              }(e, t);
            }(t),
              i = e && e.state,
              o = function () {
                return (r.next() >>> 0) / 4294967296;
              };

            return o.double = function () {
              do {
                var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, o.int32 = r.next, o.quick = o, i && (i.X && n(i, r), o.state = function () {
              return n(r, {});
            }), o;
          }

          e && e.exports ? e.exports = i : r && r.amd ? r(function () {
            return i;
          }) : this.xor4096 = i;
        }(0, t, !1);
      }),
      tychei = createCommonjsModule(function (t) {
        !function (t, e, r) {
          function n(t, e) {
            return e.a = t.a, e.b = t.b, e.c = t.c, e.d = t.d, e;
          }

          function i(t, e) {
            var r = new function (t) {
              var e = this,
                r = "";
              e.next = function () {
                var t = e.b,
                  r = e.c,
                  n = e.d,
                  i = e.a;
                return t = t << 25 ^ t >>> 7 ^ r, r = r - n | 0, n = n << 24 ^ n >>> 8 ^ i, i = i - t | 0, e.b = t = t << 20 ^ t >>> 12 ^ r, e.c = r = r - n | 0, e.d = n << 16 ^ r >>> 16 ^ i, e.a = i - t | 0;
              }, e.a = 0, e.b = 0, e.c = -1640531527, e.d = 1367130551, t === Math.floor(t) ? (e.a = t / 4294967296 | 0, e.b = 0 | t) : r += t;

              for (var n = 0; n < r.length + 20; n++) e.b ^= 0 | r.charCodeAt(n), e.next();
            }(t),
              i = e && e.state,
              o = function () {
                return (r.next() >>> 0) / 4294967296;
              };

            return o.double = function () {
              do {
                var t = ((r.next() >>> 11) + (r.next() >>> 0) / 4294967296) / (1 << 21);
              } while (0 === t);

              return t;
            }, o.int32 = r.next, o.quick = o, i && ("object" == typeof i && n(i, r), o.state = function () {
              return n(r, {});
            }), o;
          }

          e && e.exports ? e.exports = i : r && r.amd ? r(function () {
            return i;
          }) : this.tychei = i;
        }(0, t, !1);
      }),
      seedrandom = createCommonjsModule(function (t) {
        !function (e, r) {
          var n,
            i = this,
            o = 256,
            a = 6,
            s = "random",
            u = r.pow(o, a),
            c = r.pow(2, 52),
            l = 2 * c,
            h = o - 1;

          function f(t, f, v) {
            var _ = [],
              w = p(function t(e, r) {
                var n,
                  i = [],
                  o = typeof e;
                if (r && "object" == o) for (n in e) try {
                  i.push(t(e[n], r - 1));
                } catch (t) { }
                return i.length ? i : "string" == o ? e : e + "\0";
              }((f = 1 == f ? {
                entropy: !0
              } : f || {}).entropy ? [t, m(e)] : null == t ? function () {
                try {
                  var t;
                  return n && (t = n.randomBytes) ? t = t(o) : (t = new Uint8Array(o), (i.crypto || i.msCrypto).getRandomValues(t)), m(t);
                } catch (t) {
                  var r = i.navigator,
                    a = r && r.plugins;
                  return [+new Date(), i, a, i.screen, m(e)];
                }
              }() : t, 3), _),
              y = new function (t) {
                var e,
                  r = t.length,
                  n = this,
                  i = 0,
                  a = n.i = n.j = 0,
                  s = n.S = [];
                r || (t = [r++]);

                for (; i < o;) s[i] = i++;

                for (i = 0; i < o; i++) s[i] = s[a = h & a + t[i % r] + (e = s[i])], s[a] = e;

                (n.g = function (t) {
                  for (var e, r = 0, i = n.i, a = n.j, s = n.S; t--;) e = s[i = h & i + 1], r = r * o + s[h & (s[i] = s[a = h & a + e]) + (s[a] = e)];

                  return n.i = i, n.j = a, r;
                })(o);
              }(_),
              g = function () {
                for (var t = y.g(a), e = u, r = 0; t < c;) t = (t + r) * o, e *= o, r = y.g(1);

                for (; t >= l;) t /= 2, e /= 2, r >>>= 1;

                return (t + r) / e;
              };

            return g.int32 = function () {
              return 0 | y.g(4);
            }, g.quick = function () {
              return y.g(4) / 4294967296;
            }, g.double = g, p(m(y.S), e), (f.pass || v || function (t, e, n, i) {
              return i && (i.S && d(i, y), t.state = function () {
                return d(y, {});
              }), n ? (r[s] = t, e) : t;
            })(g, w, "global" in f ? f.global : this == r, f.state);
          }

          function d(t, e) {
            return e.i = t.i, e.j = t.j, e.S = t.S.slice(), e;
          }

          function p(t, e) {
            for (var r, n = t + "", i = 0; i < n.length;) e[h & i] = h & (r ^= 19 * e[h & i]) + n.charCodeAt(i++);

            return m(e);
          }

          function m(t) {
            return String.fromCharCode.apply(0, t);
          }

          if (r["seed" + s] = f, p(r.random(), e), t.exports) {
            t.exports = f;

            try {
              n = require("crypto");
            } catch (t) { }
          } else 0;
        }([], Math);
      });
    seedrandom.alea = alea, seedrandom.xor128 = xor128, seedrandom.xorwow = xorwow, seedrandom.xorshift7 = xorshift7, seedrandom.xor4096 = xor4096, seedrandom.tychei = tychei;
    var seedrandom$1 = seedrandom,
      seedrandom_1 = seedrandom$1.alea;

    function deepMap(t, e) {
      return deepMapInternal(t, e);
    }

    function deepMapInternal(t, e, r, n) {
      if (void 0 === r && (r = new Map()), void 0 === n && (n = new Set()), null == t) return null;
      if (n.has(t)) throw new Error("Circular references are not supported.");
      if (r.has(t)) return r.get(t);
      var i = e(t);
      if (i.recurse && null !== i.value) throw new Error("A deep map function may not return both a value and recurse=true.");

      if (i.recurse) {
        if (isIterable(t)) {
          var o = Array.isArray(t) ? [] : {};

          for (var a in n.add(t), t) {
            var s = deepMapInternal(t[a], e, r, n);
            o[a] = s;
          }

          return n.delete(t), o;
        }

        throw new Error("Can't recurse into non-iterable type: " + t);
      }

      return r.set(t, i.value), i.value;
    }

    function deepZip(t, e) {
      return void 0 === e && (e = zipToList), deepZipInternal(t, e);
    }

    function deepZipInternal(t, e, r) {
      void 0 === r && (r = new Set());
      var n = t[0];
      if (r.has(n)) throw new Error("Circular references are not supported.");
      var i = e(t);
      if (i.recurse && null !== i.value) throw new Error("A deep zip function may not return both a value and recurse=true.");

      if (i.recurse) {
        if (isIterable(n)) {
          var o = Array.isArray(n) ? [] : {};
          r.add(n);

          var a = function (n) {
            var i = deepZipInternal(t.map(function (t) {
              return t[n];
            }), e, r);
            o[n] = i;
          };

          for (var s in n) a(s);

          return r.delete(n), o;
        }

        throw new Error("Can't recurse into non-iterable type: " + n);
      }

      return i.value;
    }

    function zipToList(t) {
      return null === t ? null : isIterable(t[0]) ? {
        value: null,
        recurse: !0
      } : {
          value: t,
          recurse: !1
        };
    }

    function deepMapAndAwaitAll(t, e) {
      return __awaiter(this, void 0, void 0, function () {
        var r, n, i, o, a, s;
        return __generator(this, function (u) {
          switch (u.label) {
            case 0:
              r = new Map(), deepMapInternal(t, e, r), n = 0, i = Array.from(r.keys()), u.label = 1;

            case 1:
              return n < i.length ? (o = i[n], (a = r.get(o)) instanceof Promise ? [4, a] : [3, 3]) : [3, 4];

            case 2:
              s = u.sent(), r.set(o, s), u.label = 3;

            case 3:
              return n++, [3, 1];

            case 4:
              return [2, deepMapInternal(t, e, r)];
          }
        });
      });
    }

    function isIterable(t) {
      return null != t && !ArrayBuffer.isView(t) && (Array.isArray(t) || "object" == typeof t && !(t instanceof _tfjsCore.Tensor));
    }

    function canTensorify(t) {
      return null == t || isPrimitive(t) || Array.isArray(t) || "object" == typeof t && t instanceof _tfjsCore.Tensor || _tfjsCore.util.isTypedArray(t);
    }

    function isPrimitive(t) {
      return null === t || "object" != typeof t && "function" != typeof t;
    }

    function deepClone(t) {
      return deepMap(t, cloneIfTensor);
    }

    function cloneIfTensor(t) {
      return t instanceof _tfjsCore.Tensor ? {
        value: t.clone(),
        recurse: !1
      } : isIterable(t) ? {
        value: null,
        recurse: !0
      } : {
            value: t,
            recurse: !1
          };
    }

    var RingBuffer = function () {
      function t(t) {
        if (this.capacity = t, this.begin = 0, this.end = 0, null == t) throw new RangeError("Can't create a ring buffer of unknown capacity.");
        if (t < 1) throw new RangeError("Can't create ring buffer of capacity < 1.");
        this.data = new Array(t), this.doubledCapacity = 2 * t;
      }

      return t.prototype.wrap = function (t) {
        for (; t < 0;) t += this.doubledCapacity;

        return t % this.doubledCapacity;
      }, t.prototype.get = function (t) {
        if (t < 0) throw new RangeError("Can't get item at a negative index.");
        return this.data[t % this.capacity];
      }, t.prototype.set = function (t, e) {
        if (t < 0) throw new RangeError("Can't set item at a negative index.");
        this.data[t % this.capacity] = e;
      }, t.prototype.length = function () {
        var t = this.end - this.begin;
        return t < 0 && (t = this.doubledCapacity + t), t;
      }, t.prototype.isFull = function () {
        return this.length() === this.capacity;
      }, t.prototype.isEmpty = function () {
        return 0 === this.length();
      }, t.prototype.push = function (t) {
        if (this.isFull()) throw new RangeError("Ring buffer is full.");
        this.set(this.end, t), this.end = this.wrap(this.end + 1);
      }, t.prototype.pushAll = function (t) {
        for (var e = 0, r = t; e < r.length; e++) {
          var n = r[e];
          this.push(n);
        }
      }, t.prototype.pop = function () {
        if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
        this.end = this.wrap(this.end - 1);
        var t = this.get(this.end);
        return this.set(this.end, void 0), t;
      }, t.prototype.unshift = function (t) {
        if (this.isFull()) throw new RangeError("Ring buffer is full.");
        this.begin = this.wrap(this.begin - 1), this.set(this.begin, t);
      }, t.prototype.shift = function () {
        if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
        var t = this.get(this.begin);
        return this.set(this.begin, void 0), this.begin = this.wrap(this.begin + 1), t;
      }, t.prototype.shuffleExcise = function (t) {
        if (this.isEmpty()) throw new RangeError("Ring buffer is empty.");
        var e = this.wrap(this.begin + t),
          r = this.get(e);
        return this.set(e, this.pop()), r;
      }, t;
    }(),
      GrowingRingBuffer = function (t) {
        function e() {
          return t.call(this, e.INITIAL_CAPACITY) || this;
        }

        return __extends(e, t), e.prototype.isFull = function () {
          return !1;
        }, e.prototype.push = function (e) {
          t.prototype.isFull.call(this) && this.expand(), t.prototype.push.call(this, e);
        }, e.prototype.unshift = function (e) {
          t.prototype.isFull.call(this) && this.expand(), t.prototype.unshift.call(this, e);
        }, e.prototype.expand = function () {
          for (var t = 2 * this.capacity, e = new Array(t), r = this.length(), n = 0; n < r; n++) e[n] = this.get(this.wrap(this.begin + n));

          this.data = e, this.capacity = t, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = r;
        }, e.INITIAL_CAPACITY = 32, e;
      }(RingBuffer);

    function iteratorFromItems(t) {
      return new ArrayIterator(t);
    }

    function iteratorFromFunction(t) {
      return new FunctionCallIterator(t);
    }

    function iteratorFromConcatenated(t, e) {
      return new ChainedIterator(t, e);
    }

    function iteratorFromZipped(t, e) {
      return void 0 === e && (e = ZipMismatchMode.FAIL), new ZipIterator(t, e);
    }

    var ZipMismatchMode,
      LazyIterator = function () {
        function t() { }

        return t.prototype.toArray = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return t = [], [4, this.next()];

                case 1:
                  e = r.sent(), r.label = 2;

                case 2:
                  return e.done ? [3, 4] : (t.push(e.value), [4, this.next()]);

                case 3:
                  return e = r.sent(), [3, 2];

                case 4:
                  return [2, t];
              }
            });
          });
        }, t.prototype.toArrayForTest = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return t = this.prefetch(100), e = [], [4, t.next()];

                case 1:
                  r = n.sent(), n.label = 2;

                case 2:
                  return r.done ? [3, 4] : (e.push(r.value), [4, t.next()]);

                case 3:
                  return r = n.sent(), [3, 2];

                case 4:
                  return [2, e];
              }
            });
          });
        }, t.prototype.resolveFully = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              switch (e.label) {
                case 0:
                  return [4, this.next()];

                case 1:
                  t = e.sent(), e.label = 2;

                case 2:
                  return t.done ? [3, 4] : [4, this.next()];

                case 3:
                  return t = e.sent(), [3, 2];

                case 4:
                  return [2];
              }
            });
          });
        }, t.prototype.resolveWhile = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            var e, r;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return [4, this.next()];

                case 1:
                  e = n.sent(), r = t(e.value), n.label = 2;

                case 2:
                  return e.done || !r ? [3, 4] : [4, this.next()];

                case 3:
                  return e = n.sent(), r = t(e.value), [3, 2];

                case 4:
                  return [2];
              }
            });
          });
        }, t.prototype.handleErrors = function (t) {
          return new ErrorHandlingLazyIterator(this, t);
        }, t.prototype.filter = function (t) {
          return new FilterIterator(this, t);
        }, t.prototype.map = function (t) {
          return new MapIterator(this, t);
        }, t.prototype.mapAsync = function (t) {
          return new AsyncMapIterator(this, t);
        }, t.prototype.serialMapAsync = function (t) {
          return new AsyncMapIterator(this, t).serial();
        }, t.prototype.flatmap = function (t) {
          return new FlatmapIterator(this, t);
        }, t.prototype.forEachAsync = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2, this.map(t).resolveFully()];
            });
          });
        }, t.prototype.serialForEach = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2, this.serialMapAsync(t).resolveWhile(function (t) {
                return !0 === t;
              })];
            });
          });
        }, t.prototype.rowMajorBatch = function (t, e) {
          return void 0 === e && (e = !0), new RowMajorBatchIterator(this, t, e);
        }, t.prototype.columnMajorBatch = function (t, e, r) {
          return void 0 === e && (e = !0), void 0 === r && (r = zipToList), this.rowMajorBatch(t, e).map(function (t) {
            return deepZip(t, r);
          });
        }, t.prototype.concatenate = function (t, e) {
          return new ChainedIterator(iteratorFromItems([this, t]), e);
        }, t.prototype.take = function (t) {
          return t < 0 || null == t ? this : new TakeIterator(this, t);
        }, t.prototype.skip = function (t) {
          return t < 0 || null == t ? this : new SkipIterator(this, t);
        }, t.prototype.prefetch = function (t) {
          return new PrefetchIterator(this, t);
        }, t.prototype.shuffle = function (t, e) {
          return new ShuffleIterator(this, t, e);
        }, t.prototype.serial = function () {
          return new SerialIterator(this);
        }, t;
      }(),
      ArrayIterator = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          return r.items = e, r.trav = 0, r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "Array of " + this.items.length + " items";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              return this.trav >= this.items.length ? [2, {
                value: null,
                done: !0
              }] : (t = this.items[this.trav], this.trav++, [2, {
                value: deepClone(t),
                done: !1
              }]);
            });
          });
        }, e;
      }(LazyIterator),
      FunctionCallIterator = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          return r.nextFn = e, r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "Function call";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              try {
                return [2, this.nextFn()];
              } catch (t) {
                throw t.message = "Error thrown while iterating through a dataset: " + t.message, t;
              }

              return [2];
            });
          });
        }, e;
      }(LazyIterator),
      SerialIterator = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          return r.upstream = e, r.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Serial";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return [2, this.upstream.next()];
            });
          });
        }, e;
      }(LazyIterator),
      SkipIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.maxCount = r, n.count = 0, n.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Skip";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              switch (e.label) {
                case 0:
                  return this.count++ < this.maxCount ? [4, this.upstream.next()] : [3, 2];

                case 1:
                  return (t = e.sent()).done ? [2, t] : ((0, _tfjsCore.dispose)(t.value), [3, 0]);

                case 2:
                  return [2, this.upstream.next()];
              }
            });
          });
        }, e;
      }(LazyIterator),
      TakeIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.maxCount = r, n.count = 0, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Take";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return this.count++ >= this.maxCount ? [2, {
                value: null,
                done: !0
              }] : [2, this.upstream.next()];
            });
          });
        }, e;
      }(LazyIterator),
      RowMajorBatchIterator = function (t) {
        function e(e, r, n) {
          void 0 === n && (n = !0);
          var i = t.call(this) || this;
          return i.upstream = e, i.batchSize = r, i.enableSmallLastBatch = n, i.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), i;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> RowMajorBatch";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  t = [], r.label = 1;

                case 1:
                  return t.length < this.batchSize ? [4, this.upstream.next()] : [3, 3];

                case 2:
                  return (e = r.sent()).done ? this.enableSmallLastBatch && t.length > 0 ? [2, {
                    value: t,
                    done: !1
                  }] : [2, {
                    value: null,
                    done: !0
                  }] : (t.push(e.value), [3, 1]);

                case 3:
                  return [2, {
                    value: t,
                    done: !1
                  }];
              }
            });
          });
        }, e;
      }(LazyIterator),
      FilterIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.predicate = r, n.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Filter";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              switch (e.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  return (t = e.sent()).done || this.predicate(t.value) ? [2, t] : ((0, _tfjsCore.dispose)(t.value), [3, 0]);

                case 2:
                  return [2];
              }
            });
          });
        }, e;
      }(LazyIterator),
      MapIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.transform = r, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Map";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n, i, o, a;
            return __generator(this, function (s) {
              switch (s.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  if ((t = s.sent()).done) return [2, {
                    value: null,
                    done: !0
                  }];

                  for (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), r = this.transform(t.value), n = _tfjsCore.tensor_util.getTensorsInContainer(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();

                  return [2, {
                    value: r,
                    done: !1
                  }];
              }
            });
          });
        }, e;
      }(LazyIterator),
      ErrorHandlingLazyIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.handler = r, n.count = 0, n.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> handleErrors";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              switch (e.label) {
                case 0:
                  e.label = 1;

                case 1:
                  return e.trys.push([1, 3, , 4]), [4, this.upstream.next()];

                case 2:
                  return [2, e.sent()];

                case 3:
                  return t = e.sent(), this.handler(t) ? [3, 4] : [2, {
                    value: null,
                    done: !0
                  }];

                case 4:
                  return [3, 0];

                case 5:
                  return [2];
              }
            });
          });
        }, e;
      }(LazyIterator),
      AsyncMapIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.transform = r, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> AsyncMap";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n, i, o, a;
            return __generator(this, function (s) {
              switch (s.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  return (t = s.sent()).done ? [2, {
                    value: null,
                    done: !0
                  }] : (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), [4, this.transform(t.value)]);

                case 2:
                  for (r = s.sent(), n = _tfjsCore.tensor_util.getTensorsInContainer(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();

                  return [2, {
                    value: r,
                    done: !1
                  }];
              }
            });
          });
        }, e;
      }(LazyIterator),
      OneToManyIterator = function (t) {
        function e() {
          var e = t.call(this) || this;
          return e.outputQueue = new GrowingRingBuffer(), e.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), e;
        }

        return __extends(e, t), e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return 0 !== this.outputQueue.length() ? [3, 2] : [4, this.pump()];

                case 1:
                  return t.sent() ? [3, 0] : [2, {
                    value: null,
                    done: !0
                  }];

                case 2:
                  return [2, {
                    value: this.outputQueue.shift(),
                    done: !1
                  }];
              }
            });
          });
        }, e;
      }(LazyIterator),
      FlatmapIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.transform = r, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Flatmap";
        }, e.prototype.pump = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n, i, o, a;
            return __generator(this, function (s) {
              switch (s.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  if ((t = s.sent()).done) return [2, !1];

                  for (e = _tfjsCore.tensor_util.getTensorsInContainer(t.value), r = this.transform(t.value), n = _tfjsCore.tensor_util.getTensorsInContainer(r), this.outputQueue.pushAll(r), i = 0, o = e; i < o.length; i++) a = o[i], _tfjsCore.tensor_util.isTensorInList(a, n) || a.dispose();

                  return [2, !0];
              }
            });
          });
        }, e;
      }(OneToManyIterator),
      ChainedIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.baseErrorHandler = r, n.lastRead = null, n.iterator = null, n.moreIterators = e, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "TODO: fill in upstream of chained summaries -> Chained";
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return this.lastRead = this.readFromChain(this.lastRead), [2, this.lastRead];
            });
          });
        }, e.prototype.readFromChain = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            var e, r;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return [4, t];

                case 1:
                  return n.sent(), null != this.iterator ? [3, 3] : [4, this.moreIterators.next()];

                case 2:
                  if ((e = n.sent()).done) return [2, {
                    value: null,
                    done: !0
                  }];
                  this.iterator = e.value, null != this.baseErrorHandler && (this.iterator = this.iterator.handleErrors(this.baseErrorHandler)), n.label = 3;

                case 3:
                  return [4, this.iterator.next()];

                case 4:
                  return (r = n.sent()).done ? (this.iterator = null, [2, this.readFromChain(t)]) : [2, r];
              }
            });
          });
        }, e;
      }(LazyIterator);

    !function (t) {
      t[t.FAIL = 0] = "FAIL", t[t.SHORTEST = 1] = "SHORTEST", t[t.LONGEST = 2] = "LONGEST";
    }(ZipMismatchMode || (ZipMismatchMode = {}));

    var ZipIterator = function (t) {
      function e(e, r) {
        void 0 === r && (r = ZipMismatchMode.FAIL);
        var n = t.call(this) || this;
        return n.iterators = e, n.mismatchMode = r, n.count = 0, n.currentPromise = null, n;
      }

      return __extends(e, t), e.prototype.summary = function () {
        return "{TODO: fill in upstream of zip summaries} -> Zip";
      }, e.prototype.nextState = function (t) {
        return __awaiter(this, void 0, void 0, function () {
          function e(t) {
            return t instanceof LazyIterator ? {
              value: t.next().then(function (t) {
                return r++, t.done && n++, t.value;
              }),
              recurse: !1
            } : {
                value: null,
                recurse: !0
              };
          }

          var r, n, i;
          return __generator(this, function (o) {
            switch (o.label) {
              case 0:
                return [4, t];

              case 1:
                return o.sent(), r = 0, n = 0, [4, deepMapAndAwaitAll(this.iterators, e)];

              case 2:
                if (i = o.sent(), r === n) return [2, {
                  value: null,
                  done: !0
                }];
                if (n > 0) switch (this.mismatchMode) {
                  case ZipMismatchMode.FAIL:
                    throw new Error("Zipped streams should have the same length. Mismatched at element " + this.count + ".");

                  case ZipMismatchMode.SHORTEST:
                    return [2, {
                      value: null,
                      done: !0
                    }];

                  case ZipMismatchMode.LONGEST:
                }
                return this.count++, [2, {
                  value: i,
                  done: !1
                }];
            }
          });
        });
      }, e.prototype.next = function () {
        return __awaiter(this, void 0, void 0, function () {
          return __generator(this, function (t) {
            return this.currentPromise = this.nextState(this.currentPromise), [2, this.currentPromise];
          });
        });
      }, e;
    }(LazyIterator),
      PrefetchIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.bufferSize = r, n.buffer = new RingBuffer(r), n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Prefetch";
        }, e.prototype.refill = function () {
          for (; !this.buffer.isFull();) {
            var t = this.upstream.next();
            this.buffer.push(t);
          }
        }, e.prototype.next = function () {
          return this.refill(), this.buffer.shift();
        }, e;
      }(LazyIterator),
      ShuffleIterator = function (t) {
        function e(e, r, n) {
          var i = t.call(this, e, r) || this;
          return i.upstream = e, i.windowSize = r, i.upstreamExhausted = !1, i.random = seedrandom_1(n || _tfjsCore.util.now().toString()), i.lastRead = Promise.resolve({
            value: null,
            done: !1
          }), i;
        }

        return __extends(e, t), e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t = this;
            return __generator(this, function (e) {
              return this.lastRead = this.lastRead.then(function () {
                return t.serialNext();
              }), [2, this.lastRead];
            });
          });
        }, e.prototype.randomInt = function (t) {
          return Math.floor(this.random() * t);
        }, e.prototype.chooseIndex = function () {
          return this.randomInt(this.buffer.length());
        }, e.prototype.serialNext = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  this.upstreamExhausted || this.refill(), r.label = 1;

                case 1:
                  return this.buffer.isEmpty() ? [3, 3] : (t = this.chooseIndex(), [4, this.buffer.shuffleExcise(t)]);

                case 2:
                  return (e = r.sent()).done ? (this.upstreamExhausted = !0, [3, 1]) : (this.refill(), [2, e]);

                case 3:
                  return [2, {
                    value: null,
                    done: !0
                  }];
              }
            });
          });
        }, e;
      }(PrefetchIterator),
      Dataset = function () {
        function t() {
          this.size = null;
        }

        return t.prototype.batch = function (t, e) {
          var r = this;
          void 0 === e && (e = !0);
          var n = this;
          return _tfjsCore.util.assert(t > 0, function () {
            return "batchSize needs to be positive, but it is\n      " + t;
          }), datasetFromIteratorFn(function () {
            return __awaiter(r, void 0, void 0, function () {
              return __generator(this, function (r) {
                switch (r.label) {
                  case 0:
                    return [4, n.iterator()];

                  case 1:
                    return [2, r.sent().columnMajorBatch(t, e, deepBatchConcat)];
                }
              });
            });
          }, this.size === 1 / 0 || null == this.size ? this.size : e ? Math.ceil(this.size / t) : Math.floor(this.size / t));
        }, t.prototype.concatenate = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              var e, n;
              return __generator(this, function (i) {
                switch (i.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return n = (e = i.sent()).concatenate, [4, t.iterator()];

                  case 2:
                    return [2, n.apply(e, [i.sent()])];
                }
              });
            });
          }, this.size === 1 / 0 || t.size === 1 / 0 ? 1 / 0 : null != this.size && null != t.size ? this.size + t.size : null);
        }, t.prototype.filter = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().filter(function (e) {
                      return (0, _tfjsCore.tidy)(function () {
                        return t(e);
                      });
                    })];
                }
              });
            });
          }, this.size === 1 / 0 ? 1 / 0 : null);
        }, t.prototype.forEachAsync = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              switch (e.label) {
                case 0:
                  return [4, this.iterator()];

                case 1:
                  return [2, e.sent().forEachAsync(t)];
              }
            });
          });
        }, t.prototype.forEach = function (t) {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return (0, _tfjsCore.deprecationWarn)("dataset.forEach() is deprecated and will be removed. Please use dataset.forEachAsync() instead"), [2, this.forEachAsync(t)];
            });
          });
        }, t.prototype.map = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().map(function (e) {
                      return (0, _tfjsCore.tidy)(function () {
                        return t(e);
                      });
                    })];
                }
              });
            });
          }, this.size);
        }, t.prototype.mapAsync = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().mapAsync(t)];
                }
              });
            });
          }, this.size);
        }, t.prototype.prefetch = function (t) {
          var e = this;
          if (null == t) throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
          var r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().prefetch(t)];
                }
              });
            });
          }, this.size);
        }, t.prototype.repeat = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              var e = this;
              return __generator(this, function (n) {
                return [2, iteratorFromConcatenated(iteratorFromFunction(function () {
                  return __awaiter(e, void 0, void 0, function () {
                    var t;
                    return __generator(this, function (e) {
                      switch (e.label) {
                        case 0:
                          return t = {}, [4, r.iterator()];

                        case 1:
                          return [2, (t.value = e.sent(), t.done = !1, t)];
                      }
                    });
                  });
                }).take(t))];
              });
            });
          }, null != this.size && t > 0 ? this.size * t : 0 === t ? 0 : null != this.size && (void 0 === t || t < 0) ? 1 / 0 : null);
        }, t.prototype.skip = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().skip(t)];
                }
              });
            });
          }, null != this.size && t >= 0 && this.size >= t ? this.size - t : null != this.size && (this.size < t || void 0 === t || t < 0) ? 0 : null);
        }, t.prototype.shuffle = function (t, e, r) {
          var n = this;
          if (void 0 === r && (r = !0), null == t || t < 0) throw null == this.size ? new RangeError("`Dataset.shuffle()` requires bufferSize to be specified.") : new RangeError("`Dataset.shuffle()` requires bufferSize to be specified.  If your data fits in main memory (for regular JS objects), and/or GPU memory (for `tf.Tensor`s), consider setting bufferSize to the dataset size (" + this.size + " elements)");
          var i = this,
            o = seedrandom_1(e || _tfjsCore.util.now().toString());
          return datasetFromIteratorFn(function () {
            return __awaiter(n, void 0, void 0, function () {
              var e;
              return __generator(this, function (n) {
                switch (n.label) {
                  case 0:
                    return e = o.int32(), r && (e += o.int32()), [4, i.iterator()];

                  case 1:
                    return [2, n.sent().shuffle(t, e.toString())];
                }
              });
            });
          }, this.size);
        }, t.prototype.take = function (t) {
          var e = this,
            r = this;
          return datasetFromIteratorFn(function () {
            return __awaiter(e, void 0, void 0, function () {
              return __generator(this, function (e) {
                switch (e.label) {
                  case 0:
                    return [4, r.iterator()];

                  case 1:
                    return [2, e.sent().take(t)];
                }
              });
            });
          }, null != this.size && this.size > t ? t : null != this.size && this.size <= t ? this.size : null);
        }, t.prototype.toArray = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  if (this.size === 1 / 0) throw new Error("Can not convert infinite data stream to array.");
                  return [4, this.iterator()];

                case 1:
                  return [2, t.sent().toArray()];
              }
            });
          });
        }, t.prototype.toArrayForTest = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  if (this.size === 1 / 0) throw new Error("Can not convert infinite data stream to array.");
                  return [4, this.iterator()];

                case 1:
                  return [2, t.sent().toArrayForTest()];
              }
            });
          });
        }, t.MAX_BUFFER_SIZE = 1e4, t;
      }();

    exports.Dataset = Dataset;

    function datasetFromIteratorFn(t, e) {
      return void 0 === e && (e = null), new (function (r) {
        function n() {
          var t = null !== r && r.apply(this, arguments) || this;
          return t.size = e, t;
        }

        return __extends(n, r), n.prototype.iterator = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (e) {
              return [2, t()];
            });
          });
        }, n;
      }(Dataset))();
    }

    function array(t) {
      var e = this;
      return datasetFromIteratorFn(function () {
        return __awaiter(e, void 0, void 0, function () {
          return __generator(this, function (e) {
            return [2, iteratorFromItems(t)];
          });
        });
      }, t.length);
    }

    function zip(t) {
      var e,
        r = this;
      if (!isIterable(t)) throw new Error("The argument to zip() must be an object or array.");
      if (Array.isArray(t)) for (var n = 0; n < t.length; n++) e = null == e ? t[n].size : Math.min(e, t[n].size); else if (t instanceof Object) for (var i in t) e = null == e ? t[i].size : Math.min(e, t[i].size);
      return datasetFromIteratorFn(function () {
        return __awaiter(r, void 0, void 0, function () {
          return __generator(this, function (e) {
            switch (e.label) {
              case 0:
                return [4, deepMapAndAwaitAll(t, function (t) {
                  if (t instanceof Dataset) return {
                    value: t.iterator(),
                    recurse: !1
                  };
                  if (isIterable(t)) return {
                    value: null,
                    recurse: !0
                  };
                  throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.");
                })];

              case 1:
                return [2, iteratorFromZipped(e.sent(), ZipMismatchMode.SHORTEST)];
            }
          });
        });
      }, e);
    }

    function deepBatchConcat(t) {
      return null === t ? null : canTensorify(t[0]) ? {
        value: batchConcat(t),
        recurse: !1
      } : {
          value: null,
          recurse: !0
        };
    }

    function batchConcat(t) {
      if (0 === t.length) throw new Error("Can't make a batch of zero elements.");
      return t[0] instanceof _tfjsCore.Tensor ? (0, _tfjsCore.stack)(t) : (0, _tfjsCore.tensor)(t);
    }

    var TextLineDataset = function (t) {
      function e(e) {
        var r = t.call(this) || this;
        return r.input = e, r;
      }

      return __extends(e, t), e.prototype.iterator = function () {
        return __awaiter(this, void 0, void 0, function () {
          var t, e;
          return __generator(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, this.input.iterator()];

              case 1:
                return t = r.sent(), e = t.decodeUTF8(), [2, e.split("\n").map(function (t) {
                  return t.endsWith("\r") && (t = t.slice(0, -1)), t;
                })];
            }
          });
        });
      }, e;
    }(Dataset),
      CODE_QUOTE = '"',
      STATE_OUT = Symbol("out"),
      STATE_FIELD = Symbol("field"),
      STATE_QUOTE = Symbol("quote"),
      STATE_QUOTE_AFTER_QUOTE = Symbol("quoteafterquote"),
      STATE_WITHIN_QUOTE_IN_QUOTE = Symbol("quoteinquote"),
      CSVDataset = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.input = e, n.hasHeader = !0, n.fullColumnNames = null, n.columnNamesValidated = !1, n.columnConfigs = null, n.configuredColumnsOnly = !1, n.delimiter = ",", n.delimWhitespace = !1, n.base = new TextLineDataset(e), r || (r = {}), n.hasHeader = !1 !== r.hasHeader, n.fullColumnNames = r.columnNames, n.columnConfigs = r.columnConfigs, n.configuredColumnsOnly = r.configuredColumnsOnly, r.delimWhitespace ? (_tfjsCore.util.assert(null == r.delimiter, function () {
            return "Delimiter should not be provided when delimWhitespace is true.";
          }), n.delimWhitespace = !0, n.delimiter = " ") : n.delimiter = r.delimiter ? r.delimiter : ",", n;
        }

        return __extends(e, t), e.prototype.columnNames = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];

                case 1:
                  t.sent(), t.label = 2;

                case 2:
                  return [2, this.configuredColumnsOnly ? Object.keys(this.columnConfigs) : this.fullColumnNames];
              }
            });
          });
        }, e.prototype.setColumnNames = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t,
              e,
              r,
              n,
              i,
              o,
              a = this;
            return __generator(this, function (s) {
              switch (s.label) {
                case 0:
                  return [4, this.maybeReadHeaderLine()];

                case 1:
                  if (t = s.sent(), !this.fullColumnNames && !t) throw new Error("Column names must be provided if there is no header line.");
                  if (this.fullColumnNames && t && _tfjsCore.util.assert(t.length === this.fullColumnNames.length, function () {
                    return "The length of provided columnNames (" + a.fullColumnNames.length.toString() + ") does not match the length of the header line read from file (" + t.length.toString() + ").";
                  }), this.fullColumnNames || (this.fullColumnNames = t), e = this.fullColumnNames.reduce(function (t, e) {
                    return t[e] = t[e] + 1 || 1, t;
                  }, {}), r = Object.keys(e).filter(function (t) {
                    return e[t] > 1;
                  }), _tfjsCore.util.assert(0 === r.length, function () {
                    return "Duplicate column names found: " + r.toString();
                  }), this.columnConfigs) for (n = 0, i = Object.keys(this.columnConfigs); n < i.length; n++) if (o = i[n], -1 === this.fullColumnNames.indexOf(o)) throw new Error('The key "' + o + '" provided in columnConfigs does not match any of the column names (' + this.fullColumnNames.toString() + ").");
                  return this.columnNamesValidated = !0, [2];
              }
            });
          });
        }, e.prototype.maybeReadHeaderLine = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return this.hasHeader ? [4, this.base.iterator()] : [3, 3];

                case 1:
                  return [4, r.sent().next()];

                case 2:
                  if ((t = r.sent()).done) throw new Error("No data was found for CSV parsing.");
                  return e = t.value, [2, this.parseRow(e, !1)];

                case 3:
                  return [2, null];
              }
            });
          });
        }, e.prototype.iterator = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t,
              e = this;
            return __generator(this, function (r) {
              switch (r.label) {
                case 0:
                  return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];

                case 1:
                  r.sent(), r.label = 2;

                case 2:
                  return [4, this.base.iterator()];

                case 3:
                  return t = r.sent(), this.hasHeader && (t = t.skip(1)), [2, t.map(function (t) {
                    return e.makeDataElement(t);
                  })];
              }
            });
          });
        }, e.prototype.makeDataElement = function (t) {
          for (var e = this.parseRow(t), r = {}, n = {}, i = 0; i < this.fullColumnNames.length; i++) {
            var o = this.fullColumnNames[i],
              a = this.columnConfigs ? this.columnConfigs[o] : null;

            if (!this.configuredColumnsOnly || a) {
              var s = e[i],
                u = null;
              if ("" === s) {
                if (a && void 0 !== a.default) u = a.default; else {
                  if (a && (a.required || a.isLabel)) throw new Error("Required column " + o + " is empty in this line: " + t);
                  u = void 0;
                }
              } else {
                var c = Number(s);
                if (isNaN(c)) u = a && "bool" === a.dtype ? this.getBoolean(s) : s; else if (a && a.dtype) switch (a.dtype) {
                  case "float32":
                    u = c;
                    break;

                  case "int32":
                    u = Math.floor(c);
                    break;

                  case "bool":
                    u = this.getBoolean(s);
                    break;

                  default:
                    u = c;
                } else u = c;
              }
              a && a.isLabel ? n[o] = u : r[o] = u;
            }
          }

          return 0 === Object.keys(n).length ? r : {
            xs: r,
            ys: n
          };
        }, e.prototype.getBoolean = function (t) {
          return "1" === t || "true" === t.toLowerCase() ? 1 : 0;
        }, e.prototype.parseRow = function (t, e) {
          void 0 === e && (e = !0);

          for (var r = [], n = 0, i = t.length, o = STATE_OUT, a = 0; a < i; a++) switch (o) {
            case STATE_OUT:
              switch (t.charAt(a)) {
                case CODE_QUOTE:
                  n = a + 1, o = STATE_QUOTE;
                  break;

                case this.delimiter:
                  if (n = a + 1, " " === this.delimiter && this.delimWhitespace) break;
                  r.push(""), o = STATE_OUT;
                  break;

                default:
                  o = STATE_FIELD, n = a;
              }

              break;

            case STATE_FIELD:
              switch (t.charAt(a)) {
                case this.delimiter:
                  r.push(t.substring(n, a)), o = STATE_OUT, n = a + 1;
              }

              break;

            case STATE_QUOTE:
              switch (t.charAt(a)) {
                case CODE_QUOTE:
                  o = STATE_QUOTE_AFTER_QUOTE;
              }

              break;

            case STATE_QUOTE_AFTER_QUOTE:
              switch (t.charAt(a)) {
                case this.delimiter:
                  r.push(t.substring(n, a - 1)), o = STATE_OUT, n = a + 1;
                  break;

                case CODE_QUOTE:
                  o = STATE_QUOTE;
                  break;

                default:
                  o = STATE_WITHIN_QUOTE_IN_QUOTE;
              }

              break;

            case STATE_WITHIN_QUOTE_IN_QUOTE:
              switch (t.charAt(a)) {
                case CODE_QUOTE:
                  o = STATE_QUOTE;
              }

          }

          if (o === STATE_QUOTE_AFTER_QUOTE ? r.push(t.substring(n, i - 1)) : r.push(t.substring(n)), e && r.length !== this.fullColumnNames.length) throw new Error("Invalid row in csv file. Should have " + this.fullColumnNames.length + " elements in a row, but got " + r);
          return r;
        }, e;
      }(Dataset),
      MicrophoneIterator = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          r.microphoneConfig = e, r.isClosed = !1, r.fftSize = e.fftSize || 1024;
          var n = Math.log2(r.fftSize);
          if (r.fftSize < 0 || n < 4 || n > 14 || !Number.isInteger(n)) throw new Error("Invalid fftSize: it must be a power of 2 between 2 to 4 and 2 to 14, but got " + r.fftSize);
          if (r.numFrames = e.numFramesPerSpectrogram || 43, r.sampleRateHz = e.sampleRateHz, r.columnTruncateLength = e.columnTruncateLength || r.fftSize, r.audioTrackConstraints = e.audioTrackConstraints, r.smoothingTimeConstant = e.smoothingTimeConstant || 0, r.includeSpectrogram = !1 !== e.includeSpectrogram, r.includeWaveform = !0 === e.includeWaveform, !r.includeSpectrogram && !r.includeWaveform) throw new Error("Both includeSpectrogram and includeWaveform are false. At least one type of data should be returned.");
          return r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "microphone";
        }, e.create = function (t) {
          return void 0 === t && (t = {}), __awaiter(this, void 0, void 0, function () {
            var r;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  if ((0, _tfjsCore.env)().get("IS_NODE")) throw new Error("microphone API is only supported in browser environment.");
                  return [4, (r = new e(t)).start()];

                case 1:
                  return n.sent(), [2, r];
              }
            });
          });
        }, e.prototype.start = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  return i.trys.push([0, 2, , 3]), t = this, [4, navigator.mediaDevices.getUserMedia({
                    audio: null == this.audioTrackConstraints || this.audioTrackConstraints,
                    video: !1
                  })];

                case 1:
                  return t.stream = i.sent(), [3, 3];

                case 2:
                  throw e = i.sent(), new Error("Error thrown while initializing video stream: " + e.message);

                case 3:
                  if (!this.stream) throw new Error("Could not obtain audio from microphone.");

                  if (r = window.AudioContext || window.webkitAudioContext, this.audioContext = new r(), this.sampleRateHz) {
                    if (this.audioContext.sampleRate !== this.sampleRateHz) throw new Error("Mismatch in sampling rate: Expected: " + this.sampleRateHz + "; Actual: " + this.audioContext.sampleRate);
                  } else this.sampleRateHz = this.audioContext.sampleRate;

                  return n = this.audioContext.createMediaStreamSource(this.stream), this.analyser = this.audioContext.createAnalyser(), this.analyser.fftSize = 2 * this.fftSize, this.analyser.smoothingTimeConstant = this.smoothingTimeConstant, n.connect(this.analyser), this.freqData = new Float32Array(this.fftSize), this.timeData = new Float32Array(this.fftSize), [2];
              }
            });
          });
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n, i;
            return __generator(this, function (o) {
              switch (o.label) {
                case 0:
                  return this.isClosed ? [2, {
                    value: null,
                    done: !0
                  }] : [4, this.getAudioData()];

                case 1:
                  return r = o.sent(), this.includeSpectrogram && (n = this.flattenQueue(r.freqDataQueue), t = this.getTensorFromAudioDataArray(n, [this.numFrames, this.columnTruncateLength, 1])), this.includeWaveform && (i = this.flattenQueue(r.timeDataQueue), e = this.getTensorFromAudioDataArray(i, [this.numFrames * this.fftSize, 1])), [2, {
                    value: {
                      spectrogram: t,
                      waveform: e
                    },
                    done: !1
                  }];
              }
            });
          });
        }, e.prototype.capture = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return [4, this.next()];

                case 1:
                  return [2, t.sent().value];
              }
            });
          });
        }, e.prototype.getAudioData = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t,
              e,
              r,
              n = this;
            return __generator(this, function (i) {
              return t = [], e = [], r = 0, [2, new Promise(function (i) {
                var o = setInterval(function () {
                  n.includeSpectrogram && (n.analyser.getFloatFrequencyData(n.freqData), n.freqData[0] === -1 / 0 && i({
                    freqDataQueue: t,
                    timeDataQueue: e
                  }), t.push(n.freqData.slice(0, n.columnTruncateLength))), n.includeWaveform && (n.analyser.getFloatTimeDomainData(n.timeData), e.push(n.timeData.slice())), ++r === n.numFrames && (clearInterval(o), i({
                    freqDataQueue: t,
                    timeDataQueue: e
                  }));
                }, n.fftSize / n.sampleRateHz * 1e3);
              })];
            });
          });
        }, e.prototype.stop = function () {
          this.isClosed || (this.isClosed = !0, this.analyser.disconnect(), this.audioContext.close(), null != this.stream && this.stream.getTracks().length > 0 && this.stream.getTracks()[0].stop());
        }, e.prototype.toArray = function () {
          throw new Error("Can not convert infinite audio stream to array.");
        }, e.prototype.getSampleRate = function () {
          return this.sampleRateHz;
        }, e.prototype.flattenQueue = function (t) {
          var e = t[0].length,
            r = new Float32Array(t.length * e);
          return t.forEach(function (t, n) {
            return r.set(t, n * e);
          }), r;
        }, e.prototype.getTensorFromAudioDataArray = function (t, e) {
          var r = new Float32Array(_tfjsCore.util.sizeFromShape(e));
          return r.set(t, r.length - t.length), (0, _tfjsCore.tensor)(r, e);
        }, e;
      }(LazyIterator),
      WebcamIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          if (n.webcamVideoElement = e, n.webcamConfig = r, n.isClosed = !0, n.resize = !1, n.needToResize()) if (n.resize = !0, n.cropSize = [n.webcamConfig.resizeHeight, n.webcamConfig.resizeWidth], n.cropBoxInd = (0, _tfjsCore.tensor1d)([0], "int32"), n.webcamConfig.centerCrop) {
            var i = 1 * n.webcamConfig.resizeWidth / n.webcamVideoElement.width,
              o = 1 * n.webcamConfig.resizeHeight / n.webcamVideoElement.height,
              a = (1 - i) / 2,
              s = (1 - o) / 2,
              u = a + i,
              c = o + s;
            n.cropBox = (0, _tfjsCore.tensor2d)([s, a, c, u], [1, 4]);
          } else n.cropBox = (0, _tfjsCore.tensor2d)([0, 0, 1, 1], [1, 4]);
          return n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "webcam";
        }, e.create = function (t, r) {
          return void 0 === r && (r = {}), __awaiter(this, void 0, void 0, function () {
            var n;
            return __generator(this, function (i) {
              switch (i.label) {
                case 0:
                  if ((0, _tfjsCore.env)().get("IS_NODE")) throw new Error("tf.data.webcam is only supported in browser environment.");

                  if (!t) {
                    if (t = document.createElement("video"), !r.resizeWidth || !r.resizeHeight) throw new Error("Please provide webcam video element, or resizeWidth and resizeHeight to create a hidden video element.");
                    t.width = r.resizeWidth, t.height = r.resizeHeight;
                  }

                  return [4, (n = new e(t, r)).start()];

                case 1:
                  return i.sent(), [2, n];
              }
            });
          });
        }, e.prototype.start = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t,
              e,
              r = this;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  this.webcamConfig.facingMode && _tfjsCore.util.assert("user" === this.webcamConfig.facingMode || "environment" === this.webcamConfig.facingMode, function () {
                    return "Invalid webcam facing mode: " + r.webcamConfig.facingMode + ". Please provide 'user' or 'environment'";
                  }), n.label = 1;

                case 1:
                  return n.trys.push([1, 3, , 4]), t = this, [4, navigator.mediaDevices.getUserMedia({
                    video: {
                      deviceId: this.webcamConfig.deviceId,
                      facingMode: this.webcamConfig.facingMode ? this.webcamConfig.facingMode : "user",
                      width: this.webcamVideoElement.width,
                      height: this.webcamVideoElement.height
                    }
                  })];

                case 2:
                  return t.stream = n.sent(), [3, 4];

                case 3:
                  throw (e = n.sent()).message = "Error thrown while initializing video stream: " + e.message, e;

                case 4:
                  if (!this.stream) throw new Error("Could not obtain video from webcam.");

                  try {
                    this.webcamVideoElement.srcObject = this.stream;
                  } catch (t) {
                    console.log(t), this.webcamVideoElement.src = window.URL.createObjectURL(this.stream);
                  }

                  return this.webcamVideoElement.play(), this.isClosed = !1, [2, new Promise(function (t) {
                    r.webcamVideoElement.onloadedmetadata = function () {
                      t();
                    };
                  })];
              }
            });
          });
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t;
            return __generator(this, function (e) {
              if (this.isClosed) return [2, {
                value: null,
                done: !0
              }];

              try {
                t = _tfjsCore.browser.fromPixels(this.webcamVideoElement);
              } catch (t) {
                throw new Error("Error thrown converting video to pixels: " + JSON.stringify(t));
              }

              if (!this.resize) return [2, {
                value: t,
                done: !1
              }];

              try {
                return [2, {
                  value: this.cropAndResizeFrame(t),
                  done: !1
                }];
              } catch (t) {
                throw new Error("Error thrown cropping the video: " + t.message);
              } finally {
                t.dispose();
              }

              return [2];
            });
          });
        }, e.prototype.needToResize = function () {
          return !(!this.webcamConfig.resizeWidth || !this.webcamConfig.resizeHeight || this.webcamVideoElement.width === this.webcamConfig.resizeWidth && this.webcamVideoElement.height === this.webcamConfig.resizeHeight);
        }, e.prototype.cropAndResizeFrame = function (t) {
          var e = this;
          return (0, _tfjsCore.tidy)(function () {
            var r,
              n = t.toFloat().expandDims(0),
              i = (r = _tfjsCore.image.cropAndResize(n, e.cropBox, e.cropBoxInd, e.cropSize, "bilinear")).shape;

            return r.reshape(i.slice(1));
          });
        }, e.prototype.capture = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              switch (t.label) {
                case 0:
                  return [4, this.next()];

                case 1:
                  return [2, t.sent().value];
              }
            });
          });
        }, e.prototype.stop = function () {
          this.stream.getTracks().forEach(function (t) {
            return t.stop();
          });

          try {
            this.webcamVideoElement.srcObject = null;
          } catch (t) {
            console.log(t), this.webcamVideoElement.src = null;
          }

          this.isClosed = !0;
        }, e.prototype.toArray = function () {
          throw new Error("Can not convert infinite video stream to array.");
        }, e;
      }(LazyIterator),
      DataSource = function () {
        return function () { };
      }(),
      StringIterator = function (t) {
        function e() {
          return null !== t && t.apply(this, arguments) || this;
        }

        return __extends(e, t), e.prototype.split = function (t) {
          return new SplitIterator(this, t);
        }, e;
      }(LazyIterator),
      SplitIterator = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.impl = new SplitIteratorImpl(e, r), n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.impl.summary();
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return [2, this.impl.next()];
            });
          });
        }, e;
      }(StringIterator),
      SplitIteratorImpl = function (t) {
        function e(e, r) {
          var n = t.call(this) || this;
          return n.upstream = e, n.separator = r, n.carryover = "", n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Split('" + this.separator + "')";
        }, e.prototype.pump = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r, n, i;
            return __generator(this, function (o) {
              switch (o.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  if ((t = o.sent()).done) return "" === this.carryover ? [2, !1] : (this.outputQueue.push(this.carryover), this.carryover = "", [2, !0]);

                  for ((e = t.value.split(this.separator))[0] = this.carryover + e[0], r = 0, n = e.slice(0, -1); r < n.length; r++) i = n[r], this.outputQueue.push(i);

                  return this.carryover = e[e.length - 1], [2, !0];
              }
            });
          });
        }, e;
      }(OneToManyIterator),
      ByteChunkIterator = function (t) {
        function e() {
          return null !== t && t.apply(this, arguments) || this;
        }

        return __extends(e, t), e.prototype.decodeUTF8 = function () {
          return new Utf8Iterator(this);
        }, e;
      }(LazyIterator),
      Utf8Iterator = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          return r.upstream = e, r.impl = new Utf8IteratorImpl(e), r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.impl.summary();
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return [2, this.impl.next()];
            });
          });
        }, e;
      }(StringIterator),
      Utf8IteratorImpl = function (t) {
        function e(e) {
          var r = t.call(this) || this;
          if (r.upstream = e, (0, _tfjsCore.env)().get("IS_BROWSER")) r.decoder = new TextDecoder("utf-8"); else {
            var n = require("string_decoder").StringDecoder;

            r.decoder = new n("utf8");
          }
          return r;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return this.upstream.summary() + " -> Utf8";
        }, e.prototype.pump = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t, e, r;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return [4, this.upstream.next()];

                case 1:
                  return (t = n.sent()).done ? [2, !1] : (e = t.value, r = (0, _tfjsCore.env)().get("IS_BROWSER") ? this.decoder.decode(e, {
                    stream: !0
                  }) : this.decoder.write(Buffer.from(e.buffer)), this.outputQueue.push(r), [2, !0]);
              }
            });
          });
        }, e;
      }(OneToManyIterator),
      FileChunkIterator = function (t) {
        function e(e, r) {
          void 0 === r && (r = {});
          var n = t.call(this) || this;
          return n.file = e, n.options = r, _tfjsCore.util.assert(e instanceof Uint8Array || !!(0, _tfjsCore.env)().get("IS_BROWSER") && (e instanceof File || e instanceof Blob), function () {
            return "FileChunkIterator only supports File, Blob and Uint8Array right now.";
          }), n.offset = r.offset || 0, n.chunkSize = r.chunkSize || 1048576, n;
        }

        return __extends(e, t), e.prototype.summary = function () {
          return "FileChunks " + this.file;
        }, e.prototype.next = function () {
          return __awaiter(this, void 0, void 0, function () {
            var t,
              e,
              r = this;
            return __generator(this, function (n) {
              switch (n.label) {
                case 0:
                  return this.offset >= (this.file instanceof Uint8Array ? this.file.byteLength : this.file.size) ? [2, {
                    value: null,
                    done: !0
                  }] : (t = new Promise(function (t, e) {
                    var n = r.offset + r.chunkSize;
                    if (r.file instanceof Uint8Array) t(new Uint8Array(r.file.slice(r.offset, n))); else {
                      var i = new FileReader();
                      i.onload = function (r) {
                        var n = i.result;
                        if (n instanceof ArrayBuffer && (n = new Uint8Array(n)), !(n instanceof Uint8Array)) return e(new TypeError("FileReader returned unknown type."));
                        t(n);
                      }, i.onabort = function (t) {
                        return e(new Error("Aborted"));
                      }, i.onerror = function (t) {
                        return e(new Error(t.type));
                      };
                      var o = r.file.slice(r.offset, n);
                      i.readAsArrayBuffer(o);
                    }
                    r.offset = n;
                  }), e = {}, [4, t]);

                case 1:
                  return [2, (e.value = n.sent(), e.done = !1, e)];
              }
            });
          });
        }, e;
      }(ByteChunkIterator);

    exports.CSVDataset = CSVDataset;
    exports.TextLineDataset = TextLineDataset;

    function urlChunkIterator(t, e) {
      return void 0 === e && (e = {}), __awaiter(this, void 0, void 0, function () {
        var r, n, i, o, a;
        return __generator(this, function (s) {
          switch (s.label) {
            case 0:
              return "string" == typeof t ? r = t : (r = t.url, n = getRequestInitFromRequest(t)), [4, _tfjsCore.util.fetch(r, n)];

            case 1:
              return (i = s.sent()).ok ? (a = Uint8Array.bind, [4, i.arrayBuffer()]) : [3, 3];

            case 2:
              return o = new (a.apply(Uint8Array, [void 0, s.sent()]))(), [2, new FileChunkIterator(o, e)];

            case 3:
              throw new Error(i.statusText);
          }
        });
      });
    }

    var getRequestInitFromRequest = function (t) {
      return {
        method: t.method,
        headers: t.headers,
        body: t.body,
        mode: t.mode,
        credentials: t.credentials,
        cache: t.cache,
        redirect: t.redirect,
        referrer: t.referrer,
        integrity: t.integrity
      };
    };

    function isLocalPath(t) {
      return "string" == typeof t && "file://" === t.substr(0, 7);
    }

    var FileDataSource = function (t) {
      function e(e, r) {
        void 0 === r && (r = {});
        var n = t.call(this) || this;
        return n.input = e, n.options = r, n;
      }

      return __extends(e, t), e.prototype.iterator = function () {
        return __awaiter(this, void 0, void 0, function () {
          var t;
          return __generator(this, function (e) {
            return isLocalPath(this.input) && (0, _tfjsCore.env)().get("IS_NODE") && (t = require("fs"), this.input = t.readFileSync(this.input.substr(7))), [2, new FileChunkIterator(this.input, this.options)];
          });
        });
      }, e;
    }(DataSource),
      URLDataSource = function (t) {
        function e(e, r) {
          void 0 === r && (r = {});
          var n = t.call(this) || this;
          return n.url = e, n.fileOptions = r, n;
        }

        return __extends(e, t), e.prototype.iterator = function () {
          return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (t) {
              return isLocalPath(this.url) ? [2, new FileDataSource(this.url, this.fileOptions).iterator()] : [2, urlChunkIterator(this.url, this.fileOptions)];
            });
          });
        }, e;
      }(DataSource);

    exports.URLDataSource = URLDataSource;
    exports.FileDataSource = FileDataSource;

    function csv(t, e) {
      return void 0 === e && (e = {}), new CSVDataset(new URLDataSource(t), e);
    }

    function func(t) {
      var e = this,
        r = iteratorFromFunction(t);
      return datasetFromIteratorFn(function () {
        return __awaiter(e, void 0, void 0, function () {
          return __generator(this, function (t) {
            return [2, r];
          });
        });
      });
    }

    function generator(t) {
      var e = this;
      return datasetFromIteratorFn(function () {
        return __awaiter(e, void 0, void 0, function () {
          var e;
          return __generator(this, function (r) {
            switch (r.label) {
              case 0:
                return [4, t()];

              case 1:
                return e = r.sent(), [2, iteratorFromFunction(function () {
                  return e.next();
                })];
            }
          });
        });
      });
    }

    function webcam(t, e) {
      return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (r) {
          return [2, WebcamIterator.create(t, e)];
        });
      });
    }

    function microphone(t) {
      return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (e) {
          return [2, MicrophoneIterator.create(t)];
        });
      });
    }

    var version = "1.3.1";
    exports.version_data = version;
  }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "crypto": "node_modules/parcel-bundler/src/builtins/_empty.js", "string_decoder": "node_modules/parcel-bundler/src/builtins/_empty.js", "fs": "node_modules/parcel-bundler/src/builtins/_empty.js", "buffer": "node_modules/buffer/index.js" }], "node_modules/@tensorflow/tfjs/dist/tf.esm.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    var _exportNames = {
      version: true,
      data: true
    };
    exports.data = exports.version = void 0;

    var _tfjsCore = require("@tensorflow/tfjs-core");

    Object.keys(_tfjsCore).forEach(function (key) {
      if (key === "default" || key === "__esModule") return;
      if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
      Object.defineProperty(exports, key, {
        enumerable: true,
        get: function () {
          return _tfjsCore[key];
        }
      });
    });

    var _tfjsLayers = require("@tensorflow/tfjs-layers");

    Object.keys(_tfjsLayers).forEach(function (key) {
      if (key === "default" || key === "__esModule") return;
      if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
      Object.defineProperty(exports, key, {
        enumerable: true,
        get: function () {
          return _tfjsLayers[key];
        }
      });
    });

    var _tfjsConverter = require("@tensorflow/tfjs-converter");

    Object.keys(_tfjsConverter).forEach(function (key) {
      if (key === "default" || key === "__esModule") return;
      if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
      Object.defineProperty(exports, key, {
        enumerable: true,
        get: function () {
          return _tfjsConverter[key];
        }
      });
    });

    var tfjsData = _interopRequireWildcard(require("@tensorflow/tfjs-data"));

    exports.data = tfjsData;

    function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

    function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

    // @tensorflow/tfjs Copyright 2019 Google
    var version = "1.3.1",
      version$1 = {
        "tfjs-core": _tfjsCore.version_core,
        "tfjs-data": tfjsData.version_data,
        "tfjs-layers": _tfjsLayers.version_layers,
        "tfjs-converter": _tfjsConverter.version_converter,
        tfjs: version
      };
    exports.version = version$1;
  }, { "@tensorflow/tfjs-core": "node_modules/@tensorflow/tfjs-core/dist/tf-core.esm.js", "@tensorflow/tfjs-layers": "node_modules/@tensorflow/tfjs-layers/dist/tf-layers.esm.js", "@tensorflow/tfjs-converter": "node_modules/@tensorflow/tfjs-converter/dist/tf-converter.esm.js", "@tensorflow/tfjs-data": "node_modules/@tensorflow/tfjs-data/dist/tf-data.esm.js" }], "demo_util.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.isMobile = isMobile;
    exports.updateTryResNetButtonDatGuiCss = updateTryResNetButtonDatGuiCss;
    exports.toggleLoadingUI = toggleLoadingUI;
    exports.drawPoint = drawPoint;
    exports.drawSegment = drawSegment;
    exports.drawSkeleton = drawSkeleton;
    exports.drawKeypoints = drawKeypoints;
    exports.drawBoundingBox = drawBoundingBox;
    exports.renderToCanvas = renderToCanvas;
    exports.renderImageToCanvas = renderImageToCanvas;
    exports.drawHeatMapValues = drawHeatMapValues;
    exports.drawOffsetVectors = drawOffsetVectors;
    exports.tryResNetButtonText = exports.tryResNetButtonName = void 0;

    var posenet = _interopRequireWildcard(require("@tensorflow-models/posenet"));

    var tf = _interopRequireWildcard(require("@tensorflow/tfjs"));

    function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

    function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * https://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    const color = 'aqua';
    const boundingBoxColor = 'red';
    const lineWidth = 2;
    const tryResNetButtonName = 'tryResNetButton';
    exports.tryResNetButtonName = tryResNetButtonName;
    const tryResNetButtonText = '[New] Try ResNet50';
    exports.tryResNetButtonText = tryResNetButtonText;
    const tryResNetButtonTextCss = 'width:100%;text-decoration:underline;';
    const tryResNetButtonBackgroundCss = 'background:#e61d5f;';

    function isAndroid() {
      return /Android/i.test(navigator.userAgent);
    }

    function isiOS() {
      return /iPhone|iPad|iPod/i.test(navigator.userAgent);
    }

    function isMobile() {
      return isAndroid() || isiOS();
    }

    function setDatGuiPropertyCss(propertyText, liCssString, spanCssString = '') {
      var spans = document.getElementsByClassName('property-name');

      for (var i = 0; i < spans.length; i++) {
        var text = spans[i].textContent || spans[i].innerText;

        if (text == propertyText) {
          spans[i].parentNode.parentNode.style = liCssString;

          if (spanCssString !== '') {
            spans[i].style = spanCssString;
          }
        }
      }
    }

    function updateTryResNetButtonDatGuiCss() {
      setDatGuiPropertyCss(tryResNetButtonText, tryResNetButtonBackgroundCss, tryResNetButtonTextCss);
    }
    /**
     * Toggles between the loading UI and the main canvas UI.
     */


    function toggleLoadingUI(showLoadingUI, loadingDivId = 'loading', mainDivId = 'main') {
      //   if (showLoadingUI) {
      //     document.getElementById(loadingDivId).style.display = 'block';
      //     document.getElementById(mainDivId).style.display = 'none'; // document.getElementById('selectEvent').style.display = "none";
      //   } else {
      //     document.getElementById(loadingDivId).style.display = 'none';
      //     document.getElementById(mainDivId).style.display = 'block';
      //     document.getElementById('selectEvent').style.display = "block";
      //   }
    }

    function toTuple({
      y,
      x
    }) {
      return [y, x];
    }

    function drawPoint(ctx, y, x, r, color, name, num) {
      ctx.beginPath();
      ctx.arc(x, y, r, 0, 2 * Math.PI);
      

      if (name === 'nose') {
        // ctx.fillRect(0,0,100,100)
        // ctx.strokeRect(x - 15, y - 135, 50, 50); // ctx.clearRect(x, y, 100, 100)

        //ctx.font = '30px Verdana';
        // ctx.fillText(num, x, y - 100);
      } // canvas 显示文字


      ctx.font = '12px Verdana';
      // ctx.fillText(name, x, y);
      ctx.fillStyle = color;
      ctx.fill();
    }
    /**
     * Draws a line on a canvas, i.e. a joint
     */


    function drawSegment([ay, ax], [by, bx], color, scale, ctx, left, right) {
      ctx.beginPath();

      if (ay != 0 && ax != 0 && by != 0 && bx != 0) {
        ctx.moveTo(ax * scale, ay * scale);
        ctx.lineTo(bx * scale, by * scale);
      }

      ctx.lineWidth = lineWidth;
      ctx.strokeStyle = color; // canvas 写文字 坐标点相连

      // ctx.fillText(left, ax * scale, ay * scale, bx * scale, by * scale);
      // ctx.fillText(right, bx * scale, by * scale, ax * scale, ay * scale);
      ctx.stroke();
    }
    /**
     * Draws a pose skeleton by looking up all adjacent keypoints/joints
     * 通过查找所有相邻的关键点/关节来绘制姿态骨架
     */


    function drawSkeleton(keypoints, minConfidence, ctx, scale = 1) {
      const adjacentKeyPoints = posenet.getAdjacentKeyPoints(keypoints, minConfidence);
      adjacentKeyPoints.forEach(keypoints => {
        drawSegment(toTuple(keypoints[0].position), toTuple(keypoints[1].position), color, scale, ctx, keypoints[0].part, keypoints[1].part);
      });
    }
    /**
     * Draw pose keypoints onto a canvas
     * 在画布上绘制姿态关键点
     */


    function drawKeypoints(keypoints, minConfidence, ctx, num, scale = 1) {
      for (let i = 0; i < keypoints.length; i++) {
        const keypoint = keypoints[i];

        if (keypoint.score < minConfidence) {
          continue;
        }

        const {
          y,
          x
        } = keypoint.position;
        drawPoint(ctx, y * scale, x * scale, 3, color, keypoint.part, num);
      }
    }
    /**
     * Draw the bounding box of a pose. For example, for a whole person standing
     * in an image, the bounding box will begin at the nose and extend to one of
     * ankles
     * 画一个姿势的边界框。例如，一个完整的人站着
     * 在一个图像中，边界框将从鼻子开始并延伸到其中一个
     * 脚踝
     */


    function drawBoundingBox(keypoints, ctx) {
      const boundingBox = posenet.getBoundingBox(keypoints);
      ctx.rect(boundingBox.minX, boundingBox.minY, boundingBox.maxX - boundingBox.minX, boundingBox.maxY - boundingBox.minY);
      ctx.fillText("Hello Canvas", ax * scale, ay * scale, bx * scale, by * scale);
      ctx.strokeStyle = boundingBoxColor;
      ctx.stroke();
    }
    /**
     * Converts an arary of pixel data into an ImageData object
     */


    async function renderToCanvas(a, ctx) {
      const [height, width] = a.shape;
      const imageData = new ImageData(width, height);
      const data = await a.data();

      for (let i = 0; i < height * width; ++i) {
        const j = i * 4;
        const k = i * 3;
        imageData.data[j + 0] = data[k + 0];
        imageData.data[j + 1] = data[k + 1];
        imageData.data[j + 2] = data[k + 2];
        imageData.data[j + 3] = 255;
      }

      ctx.putImageData(imageData, 0, 0);
    }
    /**
     * Draw an image on a canvas
     */


    function renderImageToCanvas(image, size, canvas) {
      canvas.width = size[0];
      canvas.height = size[1];
      const ctx = canvas.getContext('2d');
      ctx.drawImage(image, 0, 0);
    }
    /**
     * Draw heatmap values, one of the model outputs, on to the canvas
     * Read our blog post for a description of PoseNet's heatmap outputs
     * https://medium.com/tensorflow/real-time-human-pose-estimation-in-the-browser-with-tensorflow-js-7dd0bc881cd5
     */


    function drawHeatMapValues(heatMapValues, outputStride, canvas) {
      const ctx = canvas.getContext('2d');
      const radius = 5;
      const scaledValues = heatMapValues.mul(tf.scalar(outputStride, 'int32'));
      drawPoints(ctx, scaledValues, radius, color);
    }
    /**
     * Used by the drawHeatMapValues method to draw heatmap points on to
     * the canvas
     */


    function drawPoints(ctx, points, radius, color) {
      const data = points.buffer().values;

      for (let i = 0; i < data.length; i += 2) {
        const pointY = data[i];
        const pointX = data[i + 1];

        if (pointX !== 0 && pointY !== 0) {
          ctx.beginPath();
          ctx.arc(pointX, pointY, radius, 0, 2 * Math.PI);
          ctx.fillStyle = color;
          ctx.fill();
        }
      }
    }
    /**
     * Draw offset vector values, one of the model outputs, on to the canvas
     * Read our blog post for a description of PoseNet's offset vector outputs
     * https://medium.com/tensorflow/real-time-human-pose-estimation-in-the-browser-with-tensorflow-js-7dd0bc881cd5
     */


    function drawOffsetVectors(heatMapValues, offsets, outputStride, scale = 1, ctx) {
      const offsetPoints = posenet.singlePose.getOffsetPoints(heatMapValues, outputStride, offsets);
      const heatmapData = heatMapValues.buffer().values;
      const offsetPointsData = offsetPoints.buffer().values;

      for (let i = 0; i < heatmapData.length; i += 2) {
        const heatmapY = heatmapData[i] * outputStride;
        const heatmapX = heatmapData[i + 1] * outputStride;
        const offsetPointY = offsetPointsData[i];
        const offsetPointX = offsetPointsData[i + 1];
        drawSegment([heatmapY, heatmapX], [offsetPointY, offsetPointX], color, scale, ctx);
      }
    }
  }, { "@tensorflow-models/posenet": "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js", "@tensorflow/tfjs": "node_modules/@tensorflow/tfjs/dist/tf.esm.js" }], "camera.js": [function (require, module, exports) {
    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.bindPage = bindPage;

    var posenet = _interopRequireWildcard(require("@tensorflow-models/posenet"));

    var _dat = _interopRequireDefault(require("dat.gui"));

    var _stats = _interopRequireDefault(require("stats.js"));

    var _demo_util = require("./demo_util");

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

    function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

    function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

    /**
     * @license
     * Copyright 2019 Google LLC. All Rights Reserved.
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * https://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     * =============================================================================
     */
    const videoWidth = 400;
    const videoHeight = 436;
    let data = ""; //  识别姿势

    let events = ""; //  用户的所有事件

    let event = ""; //  用户选取事件的apikey

    let users = new Object();
    const stats = new _stats.default();

    let recognition_posenet = "识别姿势"; // 识别姿势

    let recognition_first = "识别第"; // 识别第几人

    let people = "人";

    // var lang = GLOBALS.lang
    // let recognition_posenet = lang == 'en' ? 'Recognizing Posture' : lang == 'hant' ? "識別姿勢" : "识别姿势"; // 识别姿势

    // let recognition_first = lang == 'en' ? 'Recognizing The' : lang == 'hant' ? "識別第" : "识别第"; // 识别第几人

    // let people = lang == 'en' ? 'people' : lang == 'hant' ? "人" : "人";
    let getEvent = false; // cloud 发送数据


    function getEvents() {
      let XHR = new XMLHttpRequest();
      XHR.open('get', "https://api.cocorobo.cn/iot/data/apikey/".concat(window.user.data.apiKey, "/event/"));
      XHR.send();

      XHR.onreadystatechange = function () {
        if (XHR.readyState == 4 && XHR.status == 200) {
          events = JSON.parse(XHR.responseText);
          getEvent = true;
          event = JSON.parse(XHR.responseText)[0].eventAPIKey;
          let str = "";
          events.map(x => {
            str = str + "<option value=".concat(x.eventAPIKey, ">").concat(x.name, "</option>");
          });
          document.getElementById('selectEvent').innerHTML = str;
        }
      };
    }
    /**
     * Loads a the camera to be used in the demo
     *
     */


    async function setupCamera() {
      if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
        throw new Error('Browser API navigator.mediaDevices.getUserMedia not available');
      }

      const video = document.getElementById('video');
      video.width = videoWidth;
      video.height = videoHeight;
      const mobile = (0, _demo_util.isMobile)();
      const stream = await navigator.mediaDevices.getUserMedia({
        'audio': false,
        'video': {
          facingMode: 'user',
          width: mobile ? undefined : videoWidth,
          height: mobile ? undefined : videoHeight
        }
      });
      video.srcObject = stream;
      return new Promise(resolve => {
        video.onloadedmetadata = () => {
          resolve(video);
        };
      });
    }

    async function loadVideo() {
      const video = await setupCamera();
      video.play();
      return video;
    }

    const defaultQuantBytes = 2;
    const defaultMobileNetMultiplier = (0, _demo_util.isMobile)() ? 0.50 : 0.75;
    const defaultMobileNetStride = 16;
    const defaultMobileNetInputResolution = 500;
    const defaultResNetMultiplier = 1.0;
    const defaultResNetStride = 32;
    const defaultResNetInputResolution = 250;
    const guiState = {
      algorithm: 'multi-pose',
      input: {
        architecture: 'MobileNetV1',
        outputStride: defaultMobileNetStride,
        inputResolution: defaultMobileNetInputResolution,
        multiplier: defaultMobileNetMultiplier,
        quantBytes: defaultQuantBytes
      },
      singlePoseDetection: {
        minPoseConfidence: 0.1,
        minPartConfidence: 0.5
      },
      multiPoseDetection: {
        maxPoseDetections: 5,
        minPoseConfidence: 0.15,
        minPartConfidence: 0.1,
        nmsRadius: 30.0
      },
      output: {
        showVideo: true,
        showSkeleton: true,
        showPoints: true,
        showBoundingBox: false
      },
      net: null
    };
    /**
     * Sets up dat.gui controller on the top-right of the window
     */

    function setupGui(cameras, net) {
      guiState.net = net;

      if (cameras.length > 0) {
        guiState.camera = cameras[0].deviceId;
      }

      const gui = new _dat.default.GUI({
        width: 300
      });
      let architectureController = null;

      guiState[_demo_util.tryResNetButtonName] = function () {
        architectureController.setValue('ResNet50');
      };

      gui.add(guiState, _demo_util.tryResNetButtonName).name(_demo_util.tryResNetButtonText);
      (0, _demo_util.updateTryResNetButtonDatGuiCss)(); // The single-pose algorithm is faster and simpler but requires only one
      // person to be in the frame or results will be innaccurate. Multi-pose works
      // for more than 1 person

      const algorithmController = gui.add(guiState, 'algorithm', ['single-pose', 'multi-pose']); // The input parameters have the most effect on accuracy and speed of the
      // network

      let input = gui.addFolder('Input'); // Architecture: there are a few PoseNet models varying in size and
      // accuracy. 1.01 is the largest, but will be the slowest. 0.50 is the
      // fastest, but least accurate.

      architectureController = input.add(guiState.input, 'architecture', ['MobileNetV1', 'ResNet50']);
      guiState.architecture = guiState.input.architecture; // Input resolution:  Internally, this parameter affects the height and width
      // of the layers in the neural network. The higher the value of the input
      // resolution the better the accuracy but slower the speed.

      let inputResolutionController = null;

      function updateGuiInputResolution(inputResolution, inputResolutionArray) {
        if (inputResolutionController) {
          inputResolutionController.remove();
        }

        guiState.inputResolution = inputResolution;
        guiState.input.inputResolution = inputResolution;
        inputResolutionController = input.add(guiState.input, 'inputResolution', inputResolutionArray);
        inputResolutionController.onChange(function (inputResolution) {
          guiState.changeToInputResolution = inputResolution;
        });
      } // Output stride:  Internally, this parameter affects the height and width of
      // the layers in the neural network. The lower the value of the output stride
      // the higher the accuracy but slower the speed, the higher the value the
      // faster the speed but lower the accuracy.


      let outputStrideController = null;

      function updateGuiOutputStride(outputStride, outputStrideArray) {
        if (outputStrideController) {
          outputStrideController.remove();
        }

        guiState.outputStride = outputStride;
        guiState.input.outputStride = outputStride;
        outputStrideController = input.add(guiState.input, 'outputStride', outputStrideArray);
        outputStrideController.onChange(function (outputStride) {
          guiState.changeToOutputStride = outputStride;
        });
      } // Multiplier: this parameter affects the number of feature map channels in
      // the MobileNet. The higher the value, the higher the accuracy but slower the
      // speed, the lower the value the faster the speed but lower the accuracy.


      let multiplierController = null;

      function updateGuiMultiplier(multiplier, multiplierArray) {
        if (multiplierController) {
          multiplierController.remove();
        }

        guiState.multiplier = multiplier;
        guiState.input.multiplier = multiplier;
        multiplierController = input.add(guiState.input, 'multiplier', multiplierArray);
        multiplierController.onChange(function (multiplier) {
          guiState.changeToMultiplier = multiplier;
        });
      } // QuantBytes: this parameter affects weight quantization in the ResNet50
      // model. The available options are 1 byte, 2 bytes, and 4 bytes. The higher
      // the value, the larger the model size and thus the longer the loading time,
      // the lower the value, the shorter the loading time but lower the accuracy.


      let quantBytesController = null;

      function updateGuiQuantBytes(quantBytes, quantBytesArray) {
        if (quantBytesController) {
          quantBytesController.remove();
        }

        guiState.quantBytes = +quantBytes;
        guiState.input.quantBytes = +quantBytes;
        quantBytesController = input.add(guiState.input, 'quantBytes', quantBytesArray);
        quantBytesController.onChange(function (quantBytes) {
          guiState.changeToQuantBytes = +quantBytes;
        });
      }

      function updateGui() {
        if (guiState.input.architecture === 'MobileNetV1') {
          updateGuiInputResolution(defaultMobileNetInputResolution, [200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]);
          updateGuiOutputStride(defaultMobileNetStride, [8, 16]);
          updateGuiMultiplier(defaultMobileNetMultiplier, [0.50, 0.75, 1.0]);
        } else {
          // guiState.input.architecture === "ResNet50"
          updateGuiInputResolution(defaultResNetInputResolution, [200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800]);
          updateGuiOutputStride(defaultResNetStride, [32, 16]);
          updateGuiMultiplier(defaultResNetMultiplier, [1.0]);
        }

        updateGuiQuantBytes(defaultQuantBytes, [1, 2, 4]);
      }

      updateGui();
      input.open(); // Pose confidence: the overall confidence in the estimation of a person's
      // pose (i.e. a person detected in a frame)
      // Min part confidence: the confidence that a particular estimated keypoint
      // position is accurate (i.e. the elbow's position)

      let single = gui.addFolder('Single Pose Detection');
      single.add(guiState.singlePoseDetection, 'minPoseConfidence', 0.0, 1.0);
      single.add(guiState.singlePoseDetection, 'minPartConfidence', 0.0, 1.0);
      let multi = gui.addFolder('Multi Pose Detection');
      multi.add(guiState.multiPoseDetection, 'maxPoseDetections').min(1).max(20).step(1);
      multi.add(guiState.multiPoseDetection, 'minPoseConfidence', 0.0, 1.0);
      multi.add(guiState.multiPoseDetection, 'minPartConfidence', 0.0, 1.0); // nms Radius: controls the minimum distance between poses that are returned
      // defaults to 20, which is probably fine for most use cases

      multi.add(guiState.multiPoseDetection, 'nmsRadius').min(0.0).max(40.0);
      multi.open();
      let output = gui.addFolder('Output');
      output.add(guiState.output, 'showVideo');
      output.add(guiState.output, 'showSkeleton');
      output.add(guiState.output, 'showPoints');
      output.add(guiState.output, 'showBoundingBox');
      output.open();
      architectureController.onChange(function (architecture) {
        // if architecture is ResNet50, then show ResNet50 options
        updateGui();
        guiState.changeToArchitecture = architecture;
      });
      algorithmController.onChange(function (value) {
        switch (guiState.algorithm) {
          case 'single-pose':
            multi.close();
            single.open();
            break;

          case 'multi-pose':
            single.close();
            multi.open();
            break;
        }
      });
    }
    /**
     * Sets up a frames per second panel on the top-left of the window
     */


    function setupFPS() {
      stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
      // document.getElementById('main').appendChild(stats.dom);
    }
    /**
     * Feeds an image to posenet to estimate poses - this is where the magic
     * happens. This function loops with a requestAnimationFrame method.
     * 实时监测姿态
     */


    function detectPoseInRealTime(video, net) {
      const canvas = document.getElementById('output');
      const ctx = canvas.getContext('2d'); // since images are being fed from a webcam, we want to feed in the
      // original image and then just flip the keypoints' x coordinates. If instead
      // we flip the image, then correcting left-right keypoint pairs requires a
      // permutation on all the keypoints.

      const flipPoseHorizontal = true;
      canvas.width = videoWidth;
      canvas.height = videoHeight;

      async function poseDetectionFrame() {
        if (guiState.changeToArchitecture) {
          // Important to purge variables and free up GPU memory
          guiState.net.dispose();
          (0, _demo_util.toggleLoadingUI)(true);
          guiState.net = await posenet.load({
            architecture: guiState.changeToArchitecture,
            outputStride: guiState.outputStride,
            inputResolution: guiState.inputResolution,
            multiplier: guiState.multiplier
          });
          (0, _demo_util.toggleLoadingUI)(false);
          guiState.architecture = guiState.changeToArchitecture;
          guiState.changeToArchitecture = null;
        }

        if (guiState.changeToMultiplier) {
          guiState.net.dispose();
          (0, _demo_util.toggleLoadingUI)(true);
          guiState.net = await posenet.load({
            architecture: guiState.architecture,
            outputStride: guiState.outputStride,
            inputResolution: guiState.inputResolution,
            multiplier: +guiState.changeToMultiplier,
            quantBytes: guiState.quantBytes
          });
          (0, _demo_util.toggleLoadingUI)(false);
          guiState.multiplier = +guiState.changeToMultiplier;
          guiState.changeToMultiplier = null;
        }

        if (guiState.changeToOutputStride) {
          // Important to purge variables and free up GPU memory
          guiState.net.dispose();
          (0, _demo_util.toggleLoadingUI)(true);
          guiState.net = await posenet.load({
            architecture: guiState.architecture,
            outputStride: +guiState.changeToOutputStride,
            inputResolution: guiState.inputResolution,
            multiplier: guiState.multiplier,
            quantBytes: guiState.quantBytes
          });
          (0, _demo_util.toggleLoadingUI)(false);
          guiState.outputStride = +guiState.changeToOutputStride;
          guiState.changeToOutputStride = null;
        }

        if (guiState.changeToInputResolution) {
          // Important to purge variables and free up GPU memory
          guiState.net.dispose();
          (0, _demo_util.toggleLoadingUI)(true);
          guiState.net = await posenet.load({
            architecture: guiState.architecture,
            outputStride: guiState.outputStride,
            inputResolution: +guiState.changeToInputResolution,
            multiplier: guiState.multiplier,
            quantBytes: guiState.quantBytes
          });
          (0, _demo_util.toggleLoadingUI)(false);
          guiState.inputResolution = +guiState.changeToInputResolution;
          guiState.changeToInputResolution = null;
        }

        if (guiState.changeToQuantBytes) {
          // Important to purge variables and free up GPU memory
          guiState.net.dispose();
          (0, _demo_util.toggleLoadingUI)(true);
          guiState.net = await posenet.load({
            architecture: guiState.architecture,
            outputStride: guiState.outputStride,
            inputResolution: guiState.inputResolution,
            multiplier: guiState.multiplier,
            quantBytes: guiState.changeToQuantBytes
          });
          (0, _demo_util.toggleLoadingUI)(false);
          guiState.quantBytes = guiState.changeToQuantBytes;
          guiState.changeToQuantBytes = null;
        } // Begin monitoring code for frames per second


        stats.begin();
        let poses = [];
        let minPoseConfidence;
        let minPartConfidence;

        switch (guiState.algorithm) {
          case 'single-pose':
            const pose = await guiState.net.estimatePoses(video, {
              flipHorizontal: flipPoseHorizontal,
              decodingMethod: 'single-person'
            });
            poses = poses.concat(pose);
            minPoseConfidence = +guiState.singlePoseDetection.minPoseConfidence;
            minPartConfidence = +guiState.singlePoseDetection.minPartConfidence;
            break;

          case 'multi-pose':
            let all_poses = await guiState.net.estimatePoses(video, {
              flipHorizontal: flipPoseHorizontal,
              decodingMethod: 'multi-person',
              maxDetections: guiState.multiPoseDetection.maxPoseDetections,
              scoreThreshold: guiState.multiPoseDetection.minPartConfidence,
              nmsRadius: guiState.multiPoseDetection.nmsRadius
            });
            poses = poses.concat(all_poses);
            minPoseConfidence = +guiState.multiPoseDetection.minPoseConfidence;
            minPartConfidence = +guiState.multiPoseDetection.minPartConfidence;
            break;
        }

        ctx.clearRect(0, 0, videoWidth, videoHeight);

        if (guiState.output.showVideo) {
          ctx.save();
          ctx.scale(-1, 1);
          ctx.translate(-videoWidth, 0);
          ctx.drawImage(video, 0, 0, videoWidth, videoHeight);
          ctx.restore();
        } // For each pose (i.e. person) detected in an image, loop through the poses
        // and draw the resulting skeleton and keypoints if over certain confidence
        // scores

        /** 姿态 判断
         * 当左手腕和右手腕的高度 大于 左眼或者右眼时 -----手举高状态
         * 右肘和右肩大致处于同一水平面且右手腕 大于 右肩 小于    ----- 敬礼
         * 臀部距脚踝的距离略 约等于 膝盖到脚踝的距离 ---- 坐着
         * 臀部距脚踝的距离略 约等于 膝盖到脚踝的距离 且  手腕与肘、肩在同一水平面  ---- 深蹲
         * 双手腕 超过左右眼时                    ------- 挥手
         * 鼻子的垂直坐标小于双肩时               ------- 鞠躬
         * 鼻子的平行坐标与脚踝的平行坐标相差较大时       -------- 摔倒
        */


        let count = 0; // 识别的人数

        let Arr = []; // 获取所有的坐标点

        let strs = ""; // 坐标点字符串

        let status = ""; // 识别的姿势

        poses.forEach(({
          score,
          keypoints
        }) => {
          if (score >= minPoseConfidence) {
            keypoints.map(x => {
              if (x.position.y > 436) {
                x.position.y = 0;
                x.position.x = 0;
              }

              if (x.position.x > 400) {
                x.position.y = 0;
                x.position.x = 0;
              }

              return x;
            });
            let nose = keypoints[0].position.y,
              leftEye = keypoints[1].position.y,
              rightEye = keypoints[2].position.y,
              leftEar = keypoints[3].position.y,
              rightEar = keypoints[4].position.y,
              leftShoulder = keypoints[5].position.y,
              rightShoulder = keypoints[6].position.y,
              leftElbow = keypoints[7].position.y,
              rightElbow = keypoints[8].position.y,
              leftWrist = keypoints[9].position.y,
              rightWrist = keypoints[10].position.y,
              leftHip = keypoints[11].position.y,
              rightHip = keypoints[12].position.y,
              leftKnee = keypoints[13].position.y,
              rightknee = keypoints[14].position.y,
              leftAnkle = keypoints[15].position.y,
              rightAnkle = keypoints[16].position.y;
            let left_hip_knee = leftHip - leftAnkle; // 左臀距左脚踝的垂直距离

            let left_right_hip_knee = leftHip - rightAnkle; // 左臀距右脚踝的垂直距离

            let right_hip_knee = rightHip - rightAnkle; // 右臀距右脚踝的垂直距离

            let right_left_hip_knee = rightHip - leftAnkle; // 右臀距左脚踝的垂直距离

            let left_knee_ankle = leftKnee - leftAnkle; // 左膝盖距左脚踝的垂直距离

            let left_right_knee_ankle = leftKnee - rightAnkle; // 左膝盖距右脚踝的垂直距离

            let right_Knee_ankle = rightknee - rightAnkle; // 右膝盖距右脚踝的垂直距离

            let right_left_knee_ankle = rightknee - leftAnkle; // 右膝盖距左脚踝的垂直距离
            // 挥手

            if ((leftEye > leftWrist || rightEye > leftWrist) && (leftShoulder > leftElbow || rightShoulder > leftElbow) && leftWrist != 0 && (leftEye > rightWrist || rightEye > rightWrist) && (leftShoulder > rightElbow || rightShoulder > rightElbow) && rightWrist != 0) {
              // console.log('挥手wave');
              status = "wave";
            } else if ((leftEye > leftWrist || rightEye > leftWrist) && (leftShoulder > leftElbow || rightShoulder > leftElbow) && leftWrist != 0) {
              // console.log('左手举高liftleft')
              status = "liftleft";
            } else if ((leftEye > rightWrist || rightEye > rightWrist) && (leftShoulder > rightElbow || rightShoulder > rightElbow) && rightWrist != 0) {
              // console.log('右手举高liftright')
              status = "liftright";
            } else if (rightWrist != 0 && rightEye < rightWrist && rightWrist < rightShoulder && Math.abs(rightElbow - rightShoulder) < 10) {
              // 敬礼
              // console.log('敬礼salute')
              status = "salute";
            } else if ((nose > leftShoulder || nose > rightShoulder) && rightShoulder != 0 && leftShoulder != 0) {
              // console.log('鞠躬bow');
              status = "bow";
            } else if (leftHip != 0 && leftAnkle != 0 && leftKnee != 0) {
              if (Math.abs(left_hip_knee - left_knee_ankle) > 40 && Math.abs(right_hip_knee - right_Knee_ankle) > 40 && Math.abs(left_right_hip_knee - left_right_knee_ankle) > 40 && Math.abs(right_left_hip_knee - right_left_knee_ankle) > 40) {
                // console.log('站立 stand')
                status = "stand";
              }
            } // }
            // 深蹲（squat）&& 坐着 sit


            if (leftHip != 0 && leftAnkle != 0 && leftKnee != 0) {
              if (Math.abs(left_hip_knee - left_knee_ankle) < 40 && Math.abs(right_hip_knee - right_Knee_ankle) < 40 && Math.abs(left_right_hip_knee - left_right_knee_ankle) < 40 && Math.abs(right_left_hip_knee - right_left_knee_ankle) < 40) {
                if (Math.abs(leftHip - leftKnee) < 20 || Math.abs(rightHip - rightknee) < 20) {
                  // console.log('深蹲squat');
                  status = "squat";
                } else {
                  // console.log('坐着状态sit')
                  status = "sit";
                }
              }
            } // 摔倒（falldown）


            if (keypoints[15].position.x !== 0 && keypoints[16].position.x) {
              if (keypoints[15].position.x - keypoints[0].position.x > 80 || keypoints[16].position.x - keypoints[0].position.x > 80) {
                // console.log('摔倒falldown');
                status = "falldown";
              }
            }



            data = {
              posture: status
            };
            // 传送到cloud 的姿势
            window.dataPosenet = data.posture

            count++;
            Arr = Arr.concat(keypoints.map(x => x.position));
            users;
            let str = "<div style=\"margin-bottom:10px;\"><span>".concat(recognition_first, "<i style=\"color:#2c4fcd;padding:0 5px;font-style:normal;\"> ").concat(count, " </i>").concat(people, "</span><span style=\"margin-left:20px\">").concat(recognition_posenet, "\uFF1A<i style=").concat(status ? "color:#2c4fcd;font-style:normal" : "color:#ccc;font-style:normal", ">").concat(status ? status : 'no result', "</i></span></div>"); // keypoints.map(x => {
            //   str = str + `<li>${x.part}：{${x.position.x.toFixed(2)}，${x.position.y.toFixed(2)}}</li>`;
            //   return x;
            // })
            // str = str + '</ul></div>';

            strs = strs + str;

            if (guiState.output.showPoints) {
              (0, _demo_util.drawKeypoints)(keypoints, minPartConfidence, ctx, count);
            }

            if (guiState.output.showSkeleton) {
              (0, _demo_util.drawSkeleton)(keypoints, minPartConfidence, ctx);
            }

            if (guiState.output.showBoundingBox) {
              (0, _demo_util.drawBoundingBox)(keypoints, ctx);
            }
          }
        }); // 识别的人数

        // document.getElementById('posenet_num').innerText = count; // 坐标点

        document.getElementById('coordinate_points').innerHTML = strs; // End monitoring code for frames per second

        stats.end();
        requestAnimationFrame(poseDetectionFrame);
      }

      poseDetectionFrame();
    }
    /**
     * Kicks off the demo by loading the posenet model, finding and loading
     * available camera devices, and setting off the detectPoseInRealTime function.
     */


    async function bindPage() {
      (0, _demo_util.toggleLoadingUI)(true);
      const net = await posenet.load({
        architecture: guiState.input.architecture,
        outputStride: guiState.input.outputStride,
        inputResolution: guiState.input.inputResolution,
        multiplier: guiState.input.multiplier,
        quantBytes: guiState.input.quantBytes
      });
      (0, _demo_util.toggleLoadingUI)(false);
      let video;

      try {
        video = await loadVideo();
      } catch (e) {
        let info = document.getElementById('info');
        info.textContent = 'this browser does not support video capture,' + 'or this device does not have a camera';
        info.style.display = 'block';
        throw e;
      }

      setupGui([], net);
      setupFPS();
      detectPoseInRealTime(video, net);
    }

    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; // kick off the demo

    bindPage();
  }, { "@tensorflow-models/posenet": "node_modules/@tensorflow-models/posenet/dist/posenet.esm.js", "dat.gui": "node_modules/dat.gui/build/dat.gui.module.js", "stats.js": "node_modules/stats.js/build/stats.min.js", "./demo_util": "demo_util.js" }]
}, {}, ["camera.js"], null)
//# sourceMappingURL=/camera.283d5d54.js.map