docs: @Override
    public SparseTensor slice(int[] dimensionNumbers, int[] key) {
      if (dimensionNumbers.length == 0) {
        return this;
      }
      // Check for an efficient case, where the dimensions are the first
      // elements of this.
      if (ArrayUtils.subarrayEquals(getDimensionNumbers(), dimensionNumbers, 0)) {
        long minKeyInt = 0;
        int numDimensions = dimensionNumbers.length;
        for (int i = 0; i < numDimensions; i++) {
          minKeyInt += indexOffsets[i] * key[i];
        }
        long maxKeyInt = minKeyInt + indexOffsets[numDimensions - 1];
  
        int startIndex = getNearestIndex(minKeyInt);
        int endIndex = getNearestIndex(maxKeyInt);
  
        long[] newKeyInts = ArrayUtils.copyOfRange(keyNums, startIndex, endIndex);
        int numKeyInts = newKeyInts.length;
        for (int i = 0; i < numKeyInts; i++) {
          newKeyInts[i] -= minKeyInt;
        }
  
        int[] newDimensionNumbers = ArrayUtils.copyOfRange(getDimensionNumbers(), dimensionNumbers.length, getDimensionNumbers().length);
        int[] newDimensionSizes = ArrayUtils.copyOfRange(getDimensionSizes(), dimensionNumbers.length, getDimensionSizes().length);
        double[] newValues = ArrayUtils.copyOfRange(values, startIndex, endIndex);
        return new SparseTensor(newDimensionNumbers, newDimensionSizes, newKeyInts, newValues);
      }
  
      // TODO(jayantk): This is an extremely naive implementation of
      // slice.
      // Figure out the appropriate sizes for the subset of dimensions.
      int[] dimensionSizes = new int[dimensionNumbers.length];
      for (int i = 0; i < dimensionNumbers.length; i++) {
        int dimIndex = getDimensionIndex(dimensionNumbers[i]);
        Preconditions.checkArgument(dimIndex >= 0);
        dimensionSizes[i] = getDimensionSizes()[dimIndex];
      }
      SparseTensorBuilder builder = new SparseTensorBuilder(dimensionNumbers, dimensionSizes);
      builder.put(key, 1.0);
      return elementwiseProduct(builder.build()).sumOutDimensions(Ints.asList(dimensionNumbers));
    }