Evaluate dimensions and omit unused dimensions.
@param dimensions {array}
@param usedDimensions {object}
@param usedValues {object}
@returns {array}
@private
347489
function(dimensions, usedDimensions, usedValues) {
        var activeDimensions = new Array(dimensions.length);
        var valueCounter = 1;
        for(var i=0; i<dimensions.length; i++) {
            var dimensionName;
            for(dimensionName in dimensions[i]){break}
            if(usedDimensions[dimensionName] === undefined) {
                activeDimensions[i] = 0;
                continue;
            }
            activeDimensions[i] = 1;
            this.dimensionsList.push(dimensionName);
            var labelCollector = {};
            valueCounter = this._dimensionWalk(dimensions[i][dimensionName], usedValues[dimensionName],
                valueCounter, [0], this.precedenceMap, labelCollector, this.numberToValue);
            this.valueToNumber[dimensionName] = labelCollector;
        }
        return activeDimensions;
    }
490092
private Value[] compactValues( Value[] inputValues ) {
        if (inputValues == null) {
            return null;
        }
        List<Value> compactedList = new ArrayList<Value>();
        for (Value inputValue : inputValues) {
            if (inputValue != null) {
                compactedList.add(inputValue);
            }
        }
        return compactedList.toArray(new Value[0]);
    }
402780
private int chooseMaximalExtendedSplitAxis(List<? extends SpatialComparable> objects) {
    // maximum and minimum value for the extension
    int dimension = objects.get(0).getDimensionality();
    double[] maxExtension = new double[dimension];
    double[] minExtension = new double[dimension];
    Arrays.fill(minExtension, Double.MAX_VALUE);

    // compute min and max value in each dimension
    for (SpatialComparable object : objects) {
      for (int d = 0; d < dimension; d++) {
        double min, max;
        min = object.getMin(d);
        max = object.getMax(d);

        if (maxExtension[d] < max) {
          maxExtension[d] = max;
        }

        if (minExtension[d] > min) {
          minExtension[d] = min;
        }
      }
    }

    // set split axis to dim with maximal extension
    int splitAxis = -1;
    double max = 0;
    for (int d = 0; d < dimension; d++) {
      double currentExtension = maxExtension[d] - minExtension[d];
      if (max < currentExtension) {
        max = currentExtension;
        splitAxis = d;
      }
    }
    return splitAxis;
  }
837783
function _unsqueeze (array, dims, dim) {
  let i, ii

  if (Array.isArray(array)) {
    const next = dim + 1
    for (i = 0, ii = array.length; i < ii; i++) {
      array[i] = _unsqueeze(array[i], dims, next)
    }
  } else {
    for (let d = dim; d < dims; d++) {
      array = [array]
    }
  }

  return array
}
1054675
function(coords) {
        var i, j, area = 0;
        for (i = 0; i < coords.length; i++) {
            j = (i + 1) % coords.length;
            area += coords[i][0] * coords[j][1];
            area -= coords[j][0] * coords[i][1];
        }
        return (area < 0);
    }
395626
function getRows (items) {
  const data = {}
  const rows = [[]]

  data.stacks = true

  for (var i = 0; i < items.length; i++) {
    const el = items[i]
    const dim = el.getBoundingClientRect()

    if (!dim.height) {
      continue
    }

    for (var j = rows.length - 1; j >= 0; j--) {
      const row = rows[j]

      if (!row[0]) {
        row.push(el)
        break
      }

      var leftDim = row[0].getBoundingClientRect()

      if (dim.top >= Math.floor(leftDim.bottom)) {
        rows.push([el])
        break
      }

      if (Math.floor(dim.bottom) > leftDim.top) {
        data.stacks = false

        if (dim.left < leftDim.left && !isRtl) {
          row.unshift(el)
          break
        }

        row.push(el)
        break
      }

      if (j === 0) {
        rows.unshift([el])
        break
      }
    }
  }

  data.rows = rows

  return data
}
119949
def _evaluate_usecols(usecols, names):
    
    if callable(usecols):
        return {i for i, name in enumerate(names) if usecols(name)}
    return usecols
770495
function (n, d, s) {
		var uses = typeof s !== 'undefined';
		var x = [];
		for (var i = 0; i < n; i++) {
			var xhere = [];
			for (var j = 0; j < d; j++) {
				if (uses) {
					xhere.push(s);
				} else {
					xhere.push(randn(0.0, 1e-4));
				}
			}
			x.push(xhere);
		}
		return x;
	}
63050
def unbound_dimensions(streams, kdims, no_duplicates=True):
    
    params = stream_parameters(streams, no_duplicates)
    return [d for d in kdims if d not in params]
187475
private SparseTensor reduceDimensions(Set<Integer> dimensionsToEliminate,
      boolean useSum, Backpointers backpointers) {
    // TODO(jayantk): This method can be generalized to support a
    // generic reduce
    // operation (as a function), but it's unclear what the effect on
    // performance will be.

    // Rotate all of the dimensions which are being eliminated to the
    // end of the keyNums array.
    int[] newLabels = new int[numDimensions()];
    int[] inversionPermutation = new int[numDimensions()];
    int[] newDimensions = new int[numDimensions()];
    int[] newDimensionSizes = new int[numDimensions()];
    int numEliminated = 0;
    int[] dimensionNums = getDimensionNumbers();
    int[] dimensionSizes = getDimensionSizes();
    for (int i = 0; i < dimensionNums.length; i++) {
      if (dimensionsToEliminate.contains(dimensionNums[i])) {
        // Dimension labels must be unique, hence numEliminated.
        newLabels[i] = Integer.MAX_VALUE - numEliminated;
        inversionPermutation[dimensionNums.length - (numEliminated + 1)] = i;
        numEliminated++;
      } else {
        newLabels[i] = dimensionNums[i];
        inversionPermutation[i - numEliminated] = i;
        newDimensions[i - numEliminated] = dimensionNums[i];
        newDimensionSizes[i - numEliminated] = dimensionSizes[i];
      }
    }

    if (numEliminated == 0) {
      // If none of the dimensions being eliminated are actually part of
      // this tensor, then there's no need to do any more work.
      if (backpointers != null) {
        backpointers.setBackpointers(keyNums, keyNums, keyNums.length, this);
      }
      return this;
    } else if (numEliminated == dimensionNums.length && backpointers == null && useSum) {
      // Faster implementation for summing up all values in the tensor,
      // a common operation.
      return sumOutAllDimensions();
    }

    SparseTensor relabeled = relabelDimensions(newLabels);
    int resultNumDimensions = dimensionNums.length - numEliminated;

    // Get a number which we can divide each key by to map it to a key
    // in the reduced dimensional tensor.
    long keyNumDenominator = (resultNumDimensions > 0) ? relabeled.indexOffsets[resultNumDimensions - 1] :
        relabeled.indexOffsets[0] * relabeled.getDimensionSizes()[0];

    long[] resultKeyInts = new long[relabeled.values.length];
    long[] backpointerKeyInts = new long[relabeled.values.length];
    double[] resultValues = new double[relabeled.values.length];

    int resultInd = 0;
    long[] relabeledKeyNums = relabeled.keyNums;
    double[] relabeledValues = relabeled.values;
    int relabeledValuesLength = relabeled.values.length;
    for (int i = 0; i < relabeledValuesLength; i++) {
      long relabeledKeyNumI = relabeledKeyNums[i];
      if (i != 0 && resultInd > 0 &&
          (relabeledKeyNumI / keyNumDenominator) == resultKeyInts[resultInd - 1]) {
        // This key maps to the same entry as the previous key.
        if (useSum) {
          resultValues[resultInd - 1] += relabeledValues[i];
        } else {
          double resultVal = resultValues[resultInd - 1];
          double relabeledVal = relabeledValues[i];
          if (relabeledVal > resultVal) {
            resultValues[resultInd - 1] = relabeledVal;
            backpointerKeyInts[resultInd - 1] = relabeledKeyNumI;
          }
        }
      } else {
        if (resultInd > 0 && resultValues[resultInd - 1] == 0.0) {
          // Make sure the result tensor contains no zero-valued
          // entries.
          resultInd--;
        }

        resultKeyInts[resultInd] = relabeledKeyNumI / keyNumDenominator;
        backpointerKeyInts[resultInd] = relabeledKeyNumI;
        resultValues[resultInd] = relabeledValues[i];
        resultInd++;
      }

      int prevIndex = resultInd - 1;
      if (!useSum && resultValues[prevIndex] < 0.0) {
        // Ensure that, if values is negative, we include missing keys
        // in the maximization.
        long prevKeyNum = relabeledKeyNumI - 1;
        long nextKeyNum = relabeledKeyNumI + 1;

        if (i > 0 && relabeledKeyNums[i - 1] != prevKeyNum
            && prevKeyNum / keyNumDenominator == resultKeyInts[prevIndex]) {
          // prevKeyNum is not in relabeled, but has a higher value
          // than the current key.
          resultValues[prevIndex] = 0.0;
          backpointerKeyInts[prevIndex] = prevKeyNum;
        } else if (i + 1 < relabeledValuesLength && relabeledKeyNums[i + 1] != nextKeyNum
            && nextKeyNum / keyNumDenominator == resultKeyInts[prevIndex]) {
          // nextKeyNum is not in relabeled, but has a higher value
          // than the current key. Delete the current key from the tensor.
          resultValues[prevIndex] = 0.0;
          backpointerKeyInts[prevIndex] = nextKeyNum;
        }
      }
    }

    if (backpointers != null) {
      // backpointerKeyInts needs to have the inverse dimension
      // relabeling applied to it.
      long[] transformedBackpointers = transformKeyNums(backpointerKeyInts, relabeled.indexOffsets,
          this.indexOffsets, inversionPermutation);
      backpointers.setBackpointers(resultKeyInts, transformedBackpointers, resultInd, this);
    }

    return resizeIntoTable(ArrayUtils.copyOf(newDimensions, resultNumDimensions),
        ArrayUtils.copyOf(newDimensionSizes, resultNumDimensions),
        resultKeyInts, resultValues, resultInd);
  }
216414
function _squeeze (array, dims, dim) {
  let i, ii

  if (dim < dims) {
    const next = dim + 1
    for (i = 0, ii = array.length; i < ii; i++) {
      array[i] = _squeeze(array[i], dims, next)
    }
  } else {
    while (Array.isArray(array)) {
      array = array[0]
    }
  }

  return array
}
204176
def remove_dimensions(self, dimension_names):
        
        with self._lock:
            for dimension in dimension_names:
                if dimension in self._extra_dimensions:
                    del self._extra_dimensions[dimension]
1020213
function buildValueColumns(
  item,
  loadedDimensions,
  columnCombinations,
  dataSets
) {
  var thisColumnOptions = clone(item._columnOptions);
  thisColumnOptions.tableStructure = item._tableStructure;
  var columns = [];
  var hasNoConcepts = item._concepts.length === 0;
  var regionDimension = getDimensionById(
    loadedDimensions,
    item.regionDimensionId
  );
  var regionDimensionIndex = getDimensionIndexById(
    loadedDimensions,
    item.regionDimensionId
  );
  var timePeriodDimension = getDimensionById(
    loadedDimensions,
    item.timePeriodDimensionId
  );
  var timePeriodDimensionIndex = getDimensionIndexById(
    loadedDimensions,
    item.timePeriodDimensionId
  );

  var regionCount = defined(regionDimension)
    ? regionDimension.values.length
    : 1;
  var timePeriodCount = defined(timePeriodDimension)
    ? timePeriodDimension.values.length
    : 1;

  for (
    var combinationIndex = 0;
    combinationIndex < columnCombinations.ids.length;
    combinationIndex++
  ) {
    var ids = columnCombinations.ids[combinationIndex];
    var dimensionIndices = mapDimensionValueIdsToKeyValues(
      item,
      loadedDimensions,
      ids
    );
    // The name is just the joined names of all the columns involved, or 'value' if no columns still have names.
    var combinationName =
      columnCombinations.names[combinationIndex]
        .filter(function(name) {
          return !!name;
        })
        .join(" ") || "Value";
    var combinationId = ids.join(" ") || "Value";
    var values = [];
    for (
      var timePeriodIndex = 0;
      timePeriodIndex < timePeriodCount;
      timePeriodIndex++
    ) {
      for (var regionIndex = 0; regionIndex < regionCount; regionIndex++) {
        if (defined(regionDimensionIndex)) {
          dimensionIndices[regionDimensionIndex] =
            regionDimension.values[regionIndex].id;
        }
        if (defined(timePeriodDimensionIndex)) {
          dimensionIndices[timePeriodDimensionIndex] =
            timePeriodDimension.values[timePeriodIndex].id;
        }
        values.push(
          getObsValue(item, loadedDimensions, dimensionIndices, dataSets)
        );
      }
    }
    thisColumnOptions.id = combinationId; // So we can refer to the dimension in a template by a sequence of ids or names.
    var column = new TableColumn(combinationName, values, thisColumnOptions);
    if (hasNoConcepts) {
      // If there are no concepts displayed to the user, there is only one value column, and we won't add a "total" column.
      // So make this column active.
      column.isActive = true;
    }
    columns.push(column);
  }
  return columns;
}
926162
def calculate_dimensions(variables):
    
    dims = OrderedDict()
    last_used = {}
    scalar_vars = set(k for k, v in variables.items() if not v.dims)
    for k, var in variables.items():
        for dim, size in zip(var.dims, var.shape):
            if dim in scalar_vars:
                raise ValueError('dimension %r already exists as a scalar '
                                 'variable' % dim)
            if dim not in dims:
                dims[dim] = size
                last_used[dim] = k
            elif dims[dim] != size:
                raise ValueError('conflicting sizes for dimension %r: '
                                 'length %s on %r and length %s on %r' %
                                 (dim, size, k, dims[dim], last_used[dim]))
    return dims
45537
private DenseTensor reduceDimensions(Collection<Integer> dimensionsToEliminate,
      boolean useSum, Backpointers backpointers) {
    SortedSet<Integer> dimensionsToKeep = Sets.newTreeSet(Ints.asList(getDimensionNumbers()));
    dimensionsToKeep.removeAll(dimensionsToEliminate);

    int[] myDimensionNumbers = getDimensionNumbers();
    int[] myDimensionSizes = getDimensionSizes();
    List<Integer> dimensionNumsToKeep = Lists.newArrayList();
    List<Integer> dimensionSizesToKeep = Lists.newArrayList();
    List<Integer> dimensionNumsToEliminate = Lists.newArrayList();
    List<Integer> dimensionSizesToEliminate = Lists.newArrayList();
    for (int i = 0; i < myDimensionNumbers.length; i++) {
      if (!dimensionsToEliminate.contains(myDimensionNumbers[i])) {
        dimensionNumsToKeep.add(myDimensionNumbers[i]);
        dimensionSizesToKeep.add(myDimensionSizes[i]);
      } else {
        dimensionNumsToEliminate.add(myDimensionNumbers[i]);
        dimensionSizesToEliminate.add(myDimensionSizes[i]);
      }
    }

    DenseTensorBuilder outputBuilder = new DenseTensorBuilder(Ints.toArray(dimensionNumsToKeep),
        Ints.toArray(dimensionSizesToKeep));
    // Optionally return the list of keynums which determined the values
    // in the returned tensor.
    long[] newBackpointerNums = null;
    long[] oldBackpointerNums = null;
    if (backpointers != null) {
      newBackpointerNums = new long[outputBuilder.values.length];
      oldBackpointerNums = new long[outputBuilder.values.length];
    }

    // Maps a key of the reduced tensor into a partial key of this.
    int[] dimensionMapping = getDimensionMapping(outputBuilder.getDimensionNumbers());
    int[] partialKey = new int[getDimensionNumbers().length];
    Arrays.fill(partialKey, -1);
    Iterator<KeyValue> otherKeyValues = outputBuilder.keyValueIterator();

    int backpointerIndex = 0;
    while (otherKeyValues.hasNext()) {
      KeyValue otherKeyValue = otherKeyValues.next();
      for (int i = 0; i < otherKeyValue.getKey().length; i++) {
        partialKey[dimensionMapping[i]] = otherKeyValue.getKey()[i];
      }

      Iterator<int[]> myKeyIterator = new SliceIndexIterator(getDimensionSizes(), partialKey);
      double resultVal = (useSum) ? 0.0 : Double.NEGATIVE_INFINITY;
      long backpointerKeyNum = -1;
      while (myKeyIterator.hasNext()) {
        if (useSum) {
          resultVal += getByDimKey(myKeyIterator.next());
        } else {
          int[] nextKey = myKeyIterator.next();
          double keyVal = getByDimKey(nextKey);
          if (keyVal > resultVal) {
            resultVal = keyVal;
            backpointerKeyNum = dimKeyToKeyNum(nextKey);
          }
        }
      }
      outputBuilder.put(otherKeyValue.getKey(), resultVal);

      if (backpointers != null) {
        newBackpointerNums[backpointerIndex] = outputBuilder.dimKeyToKeyNum(otherKeyValue.getKey());
        oldBackpointerNums[backpointerIndex] = backpointerKeyNum;
        backpointerIndex++;
      }
    }

    if (backpointers != null) {
      backpointers.setBackpointers(newBackpointerNums, oldBackpointerNums, backpointerIndex, this);
    }

    return outputBuilder.buildNoCopy();
  }
398127
function unflatten(valuesInOneDimension, size) {
  const {height, width} = size;
  const valuesInTwoDimensions = [];
  for (let y = 0; y < height; y++) {
    const start = y * width;
    const end = start + width;
    valuesInTwoDimensions.push(valuesInOneDimension.slice(start, end));
  }
  return valuesInTwoDimensions;
}
1278877
private final SparseTensor doElementwise(Tensor other, boolean useSum) {
    // TODO(jayantk): This method could be generalized by taking a
    // Function
    // instead of a boolean flag. However, it's unclear how this
    // change
    // affects performance.
    Preconditions.checkArgument(Arrays.equals(getDimensionNumbers(), other.getDimensionNumbers()));
    long[] resultKeyInts = new long[size() + other.size()];
    double[] resultValues = new double[size() + other.size()];

    int resultInd = 0;
    int myInd = 0;
    int otherInd = 0;

    int mySize = size();
    int otherSize = other.size();
    long otherKeyNum = 1;
    while (myInd < mySize && otherInd < otherSize) {
      otherKeyNum = other.indexToKeyNum(otherInd);
      if (keyNums[myInd] < otherKeyNum) {
        resultKeyInts[resultInd] = keyNums[myInd];
        resultValues[resultInd] = values[myInd];
        resultInd++;
        myInd++;
      } else if (keyNums[myInd] > otherKeyNum) {
        resultKeyInts[resultInd] = otherKeyNum;
        resultValues[resultInd] = other.getByIndex(otherInd);
        resultInd++;
        otherInd++;
      } else {
        // Keys are equal.
        if (useSum) {
          resultValues[resultInd] = values[myInd] + other.getByIndex(otherInd);
        } else {
          resultValues[resultInd] = Math.max(values[myInd], other.getByIndex(otherInd));
        }

        if (resultValues[resultInd] != 0.0) {
          // Ignore the resulting value if it is zero.
          resultKeyInts[resultInd] = keyNums[myInd];
          resultInd++;
        }
        myInd++;
        otherInd++;
      }
    }

    // One of the two lists might not be done yet. Finish it off.
    for (; myInd < size(); myInd++) {
      resultKeyInts[resultInd] = keyNums[myInd];
      resultValues[resultInd] = values[myInd];
      resultInd++;
    }

    for (; otherInd < other.size(); otherInd++) {
      resultKeyInts[resultInd] = other.indexToKeyNum(otherInd);
      resultValues[resultInd] = other.getByIndex(otherInd);
      resultInd++;
    }

    return resizeIntoTable(getDimensionNumbers(), getDimensionSizes(), resultKeyInts, resultValues, resultInd);
  }