function _getSubmatrix(data, index, dims, dim) {
    var last = dim === dims - 1;
    var range = index.dimension(dim);

    if (last) {
      return range.map(function (i) {
        validateIndex(i, data.length);
        return data[i];
      }).valueOf();
    } else {
      return range.map(function (i) {
        validateIndex(i, data.length);
        var child = data[i];
        return _getSubmatrix(child, index, dims, dim + 1);
      }).valueOf();
    }
  }
Recursively get a submatrix of a multi dimensional matrix.
Index is not checked for correct number or length of dimensions.
@memberof DenseMatrix
@param {Array} data
@param {Index} index
@param {number} dims   Total number of dimensions
@param {number} dim    Current dimension
@return {Array} submatrix
@private