buildMapOfGraph = function buildMapOfGraph(tensor, finishedNodes, nodesInProgress, layer, nodeIndex, tensorIndex) {
	      if (layer == null || nodeIndex == null || tensorIndex == null) {
	        layer = tensor.sourceLayer;
	        nodeIndex = tensor.nodeIndex;
	        tensorIndex = tensor.tensorIndex;
	      }

	      var node = layer.inboundNodes[nodeIndex]; // Prevent cycles.

	      if (nodesInProgress.indexOf(node) !== -1) {
	        throw new RuntimeError("The tensor " + tensor.name + " at layer \"" + layer.name + "\" " + 'is part of a cycle.');
	      } // Don't repeat work for shared subgraphs


	      if (finishedNodes.indexOf(node) !== -1) {
	        return;
	      } // Update containerNodes.


	      _this.containerNodes.add(Container.nodeKey(layer, nodeIndex)); // Store the traversal order for layer sorting.


	      if (!(layer.id in layerIndices)) {
	        layerIndices[layer.id] = Object.keys(layerIndices).length;
	      }

	      if (nodesInProgress.indexOf(node) === -1) {
	        nodesInProgress.push(node);
	      } // Propagate to all previous tensors connected to this node.


	      var numInboundLayers = node.inboundLayers.length;

	      for (var _i = 0; _i < numInboundLayers; _i++) {
	        var x = node.inputTensors[_i];
	        var _layer = node.inboundLayers[_i];
	        var _nodeIndex = node.nodeIndices[_i];
	        var _tensorIndex = node.tensorIndices[_i];
	        buildMapOfGraph(x, finishedNodes, nodesInProgress, _layer, _nodeIndex, _tensorIndex);
	      }

	      finishedNodes.push(node);

	      while (nodesInProgress.indexOf(node) >= 0) {
	        nodesInProgress.splice(nodesInProgress.indexOf(node), 1);
	      }

	      nodesInDecreasingDepth.push(node);
	    }
Builds a map of the graph of layers.

This recursively updates the map `layerIndices`,
the list `nodesInDecreasingDepth` and the set `containerNodes`.

@param tensor Some tensor in a graph.
@param finishedNodes Set of nodes whose subgraphs have been traversed
        completely. Useful to prevent duplicated work.
@param nodesInProgress Set of nodes that are currently active on the
        recursion stack. Useful to detect cycles.
@param layer Layer from which `tensor` comes from. If not provided,
  will be obtained from tensor.sourceLayer.
@param nodeIndex Node index from which `tensor` comes from.
@param tensorIndex TensorIndex from which `tensor` comes from.

@exception RuntimeError if a cycle is detected.