text: "use strict";
  /**
   * @license
   * Copyright 2018 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.
   * =============================================================================
   */
  Object.defineProperty(exports, "__esModule", { value: true });
  function getParamValue(paramName, node, tensorMap, context) {
      var inputParam = node.inputParams[paramName];
      if (inputParam && inputParam.inputIndexStart !== undefined) {
          var start = inputParam.inputIndexStart;
          var end = inputParam.inputIndexEnd === 0 ?
              undefined :
              (inputParam.inputIndexEnd === undefined ? start + 1 :
                  inputParam.inputIndexEnd);
          if (inputParam.type === 'tensor') {
              return getTensor(node.inputNames[inputParam.inputIndexStart], tensorMap, context);
          }
          if (inputParam.type === 'tensors') {
              var inputs = node.inputNames.slice(start, end);
              return inputs.map(function (name) { return getTensor(name, tensorMap, context); });
          }
          var data = Array.prototype.slice.call(getTensor(node.inputNames.slice(start)[0], tensorMap, context)
              .dataSync());
          return inputParam.type === 'number' ? data[0] : data;
      }
      var attrParam = node.attrParams[paramName];
      return attrParam && attrParam.value;
  }
  exports.getParamValue = getParamValue;
  /**
   * Retrieve the tensor based on input name by extracting the node name and
   * output index information.
   * @param name Node input name
   * @param tensorsMap Tensors map keyed by the node
   */
  function getTensor(name, tensorsMap, context) {
      var _a = parseNodeName(name), nodeName = _a[0], index = _a[1];
      var contextId = context.currentContextIds.find(function (contextId) {
          return !!tensorsMap[getNodeNameWithContextId(nodeName, contextId)];
      });
      return contextId !== undefined ?
          tensorsMap[getNodeNameWithContextId(nodeName, contextId)][index] :
          undefined;
  }
  exports.getTensor = getTensor;
  /**
   * Retrieve the tensors based on input name for current context.
   * @param name Node input name
   * @param tensorsMap Tensors map keyed by the node
   */
  function getTensorsForCurrentContenxt(name, tensorsMap, context) {
      return tensorsMap[getNodeNameWithContextId(name, context.currentContextId)];
  }
  exports.getTensorsForCurrentContenxt = getTensorsForCurrentContenxt;
  /**
   * Returns the node name and index from the Node input name.
   * @param inputName The input name of the node, in format of
   * node_name:output_index, i.e. MatMul:0, if the output_index is not set, it is
   * default to 0.
   */
  function getNodeNameAndIndex(inputName, context) {
      var _a = parseNodeName(inputName), nodeName = _a[0], index = _a[1];
      return [
          getNodeNameWithContextId(nodeName, context && context.currentContextId),
          index
      ];
  }
  exports.getNodeNameAndIndex = getNodeNameAndIndex;
  function getNodeNameWithContextId(name, contextId) {
      return !!contextId ? name + "-" + contextId : name;
  }
  function parseNodeName(name) {
      var index = name.lastIndexOf(':');
      if (index === -1) {
          return [name, 0];
      }
      var nodeName = name.substring(0, index);
      return [nodeName, Number(name.substring(index + 1))];
  }
  exports.parseNodeName = parseNodeName;
  function split(arr, size) {
      var res = [];
      for (var i = 0; i < arr.length; i += size) {
          res.push(arr.slice(i, i + size));
      }
      return res;
  }
  exports.split = split;
  //# sourceMappingURL=utils.js.map