docs: 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);
    }