Eliminates {@code dimensionsToEliminate}, either by summing or
maximizing.

@param dimensionsToEliminate
@param useSum
@return
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);
  }
732861
@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize;
        int heightSize;

        final int mPaddingLeft = getPaddingLeft();
        final int mPaddingTop = getPaddingTop();
        final int mPaddingRight = getPaddingRight();
        final int mPaddingBottom = getPaddingBottom();

        mSpinnerPadding.left = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft
                : mSelectionLeftPadding;
        mSpinnerPadding.top = mPaddingTop > mSelectionTopPadding ? mPaddingTop
                : mSelectionTopPadding;
        mSpinnerPadding.right = mPaddingRight > mSelectionRightPadding ? mPaddingRight
                : mSelectionRightPadding;
        mSpinnerPadding.bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom
                : mSelectionBottomPadding;

        if (mDataChanged) {
            handleDataChanged();
        }

        int preferredHeight = 0;
        int preferredWidth = 0;
        boolean needsMeasuring = true;

        int selectedPosition = getSelectedItemPosition();
        if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount()) {
            // Try looking in the recycler. (Maybe we were measured once already)
            View view = mRecycler.get(selectedPosition);
            if (view == null) {
                // Make a new one
                view = mAdapter.getView(selectedPosition, null, this);
            }

            if (view != null) {
                // Put in recycler for re-measuring and/or layout
                mRecycler.put(selectedPosition, view);
            }

            if (view != null) {
                if (view.getLayoutParams() == null) {
                    mBlockLayoutRequests = true;
                    view.setLayoutParams(generateDefaultLayoutParams());
                    mBlockLayoutRequests = false;
                }
                measureChild(view, widthMeasureSpec, heightMeasureSpec);

                preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
                preferredWidth = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;

                needsMeasuring = false;
            }
        }

        if (needsMeasuring) {
            // No views -- just use padding
            preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
            if (widthMode == MeasureSpec.UNSPECIFIED) {
                preferredWidth = mSpinnerPadding.left + mSpinnerPadding.right;
            }
        }

        preferredHeight = Math.max(preferredHeight, getSuggestedMinimumHeight());
        preferredWidth = Math.max(preferredWidth, getSuggestedMinimumWidth());

        if (IS_HONEYCOMB) {
            heightSize = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0);
            widthSize = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0);
        } else {
            heightSize = resolveSize(preferredHeight, heightMeasureSpec);
            widthSize = resolveSize(preferredWidth, widthMeasureSpec);
        }

        setMeasuredDimension(widthSize, heightSize);
        mHeightMeasureSpec = heightMeasureSpec;
        mWidthMeasureSpec = widthMeasureSpec;
    }
23015
private void removeFromUseIfLocal(String name, ReachingUses use) {
    Var var = allVarsInFn.get(name);
    if (var == null) {
      return;
    }
    if (!escaped.contains(var)) {
      use.mayUseMap.removeAll(var);
    }
  }
724134
private MutableBigInteger divideMagnitude(MutableBigInteger div,
                                              MutableBigInteger quotient,
                                              boolean needRemainder ) {
        // assert div.intLen > 1
        // D1 normalize the divisor
        int shift = Integer.numberOfLeadingZeros(div.value[div.offset]);
        // Copy divisor value to protect divisor
        final int dlen = div.intLen;
        int[] divisor;
        MutableBigInteger rem; // Remainder starts as dividend with space for a leading zero
        if (shift > 0) {
            divisor = new int[dlen];
            copyAndShift(div.value,div.offset,dlen,divisor,0,shift);
            if (Integer.numberOfLeadingZeros(value[offset]) >= shift) {
                int[] remarr = new int[intLen + 1];
                rem = new MutableBigInteger(remarr);
                rem.intLen = intLen;
                rem.offset = 1;
                copyAndShift(value,offset,intLen,remarr,1,shift);
            } else {
                int[] remarr = new int[intLen + 2];
                rem = new MutableBigInteger(remarr);
                rem.intLen = intLen+1;
                rem.offset = 1;
                int rFrom = offset;
                int c=0;
                int n2 = 32 - shift;
                for (int i=1; i < intLen+1; i++,rFrom++) {
                    int b = c;
                    c = value[rFrom];
                    remarr[i] = (b << shift) | (c >>> n2);
                }
                remarr[intLen+1] = c << shift;
            }
        } else {
            divisor = Arrays.copyOfRange(div.value, div.offset, div.offset + div.intLen);
            rem = new MutableBigInteger(new int[intLen + 1]);
            System.arraycopy(value, offset, rem.value, 1, intLen);
            rem.intLen = intLen;
            rem.offset = 1;
        }

        int nlen = rem.intLen;

        // Set the quotient size
        final int limit = nlen - dlen + 1;
        if (quotient.value.length < limit) {
            quotient.value = new int[limit];
            quotient.offset = 0;
        }
        quotient.intLen = limit;
        int[] q = quotient.value;


        // Must insert leading 0 in rem if its length did not change
        if (rem.intLen == nlen) {
            rem.offset = 0;
            rem.value[0] = 0;
            rem.intLen++;
        }

        int dh = divisor[0];
        long dhLong = dh & LONG_MASK;
        int dl = divisor[1];

        // D2 Initialize j
        for (int j=0; j < limit-1; j++) {
            // D3 Calculate qhat
            // estimate qhat
            int qhat = 0;
            int qrem = 0;
            boolean skipCorrection = false;
            int nh = rem.value[j+rem.offset];
            int nh2 = nh + 0x80000000;
            int nm = rem.value[j+1+rem.offset];

            if (nh == dh) {
                qhat = ~0;
                qrem = nh + nm;
                skipCorrection = qrem + 0x80000000 < nh2;
            } else {
                long nChunk = (((long)nh) << 32) | (nm & LONG_MASK);
                if (nChunk >= 0) {
                    qhat = (int) (nChunk / dhLong);
                    qrem = (int) (nChunk - (qhat * dhLong));
                } else {
                    long tmp = divWord(nChunk, dh);
                    qhat = (int) (tmp & LONG_MASK);
                    qrem = (int) (tmp >>> 32);
                }
            }

            if (qhat == 0)
                continue;

            if (!skipCorrection) { // Correct qhat
                long nl = rem.value[j+2+rem.offset] & LONG_MASK;
                long rs = ((qrem & LONG_MASK) << 32) | nl;
                long estProduct = (dl & LONG_MASK) * (qhat & LONG_MASK);

                if (unsignedLongCompare(estProduct, rs)) {
                    qhat--;
                    qrem = (int)((qrem & LONG_MASK) + dhLong);
                    if ((qrem & LONG_MASK) >=  dhLong) {
                        estProduct -= (dl & LONG_MASK);
                        rs = ((qrem & LONG_MASK) << 32) | nl;
                        if (unsignedLongCompare(estProduct, rs))
                            qhat--;
                    }
                }
            }

            // D4 Multiply and subtract
            rem.value[j+rem.offset] = 0;
            int borrow = mulsub(rem.value, divisor, qhat, dlen, j+rem.offset);

            // D5 Test remainder
            if (borrow + 0x80000000 > nh2) {
                // D6 Add back
                divadd(divisor, rem.value, j+1+rem.offset);
                qhat--;
            }

            // Store the quotient digit
            q[j] = qhat;
        } // D7 loop on j
        // D3 Calculate qhat
        // estimate qhat
        int qhat = 0;
        int qrem = 0;
        boolean skipCorrection = false;
        int nh = rem.value[limit - 1 + rem.offset];
        int nh2 = nh + 0x80000000;
        int nm = rem.value[limit + rem.offset];

        if (nh == dh) {
            qhat = ~0;
            qrem = nh + nm;
            skipCorrection = qrem + 0x80000000 < nh2;
        } else {
            long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
            if (nChunk >= 0) {
                qhat = (int) (nChunk / dhLong);
                qrem = (int) (nChunk - (qhat * dhLong));
            } else {
                long tmp = divWord(nChunk, dh);
                qhat = (int) (tmp & LONG_MASK);
                qrem = (int) (tmp >>> 32);
            }
        }
        if (qhat != 0) {
            if (!skipCorrection) { // Correct qhat
                long nl = rem.value[limit + 1 + rem.offset] & LONG_MASK;
                long rs = ((qrem & LONG_MASK) << 32) | nl;
                long estProduct = (dl & LONG_MASK) * (qhat & LONG_MASK);

                if (unsignedLongCompare(estProduct, rs)) {
                    qhat--;
                    qrem = (int) ((qrem & LONG_MASK) + dhLong);
                    if ((qrem & LONG_MASK) >= dhLong) {
                        estProduct -= (dl & LONG_MASK);
                        rs = ((qrem & LONG_MASK) << 32) | nl;
                        if (unsignedLongCompare(estProduct, rs))
                            qhat--;
                    }
                }
            }


            // D4 Multiply and subtract
            int borrow;
            rem.value[limit - 1 + rem.offset] = 0;
            if(needRemainder)
                borrow = mulsub(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);
            else
                borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);

            // D5 Test remainder
            if (borrow + 0x80000000 > nh2) {
                // D6 Add back
                if(needRemainder)
                    divadd(divisor, rem.value, limit - 1 + 1 + rem.offset);
                qhat--;
            }

            // Store the quotient digit
            q[(limit - 1)] = qhat;
        }


        if (needRemainder) {
            // D8 Unnormalize
            if (shift > 0)
                rem.rightShift(shift);
            rem.normalize();
        }
        quotient.normalize();
        return needRemainder ? rem : null;
    }
864610
private void removeLowerDimension(Geometry geometry, List<Geometry> result, int dimension) {
        for (int i = 0; i < geometry.getNumGeometries(); i++) {
            Geometry g = geometry.getGeometryN(i);
            if (g instanceof GeometryCollection) {
                removeLowerDimension(g, result, dimension);
            } else if (g.getDimension() >= dimension) {
                result.add(g);
            }
        }
    }
929180
@Fix(io.sarl.lang.validation.IssueCodes.REDUNDANT_CAPACITY_USE)
	public void fixRedundantAgentCapacityUse(final Issue issue, IssueResolutionAcceptor acceptor) {
		CapacityReferenceRemoveModification.accept(this, issue, acceptor);
	}
751741
long toCompactValue(int sign) {
        if (intLen == 0 || sign == 0)
            return 0L;
        int[] mag = getMagnitudeArray();
        int len = mag.length;
        int d = mag[0];
        // If this MutableBigInteger can not be fitted into long, we need to
        // make a BigInteger object for the resultant BigDecimal object.
        if (len > 2 || (d < 0 && len == 2))
            return INFLATED;
        long v = (len == 2) ?
            ((mag[1] & LONG_MASK) | (d & LONG_MASK) << 32) :
            d & LONG_MASK;
        return sign == -1 ? -v : v;
    }
1047021
public static SparseTensor empty(List<Integer> dimensionNumbers, List<Integer> dimensionSizes) {
    return empty(Ints.toArray(dimensionNumbers), Ints.toArray(dimensionSizes));
  }
587344
@SuppressWarnings("unchecked")
	protected void removeCurrentTypeConversion() {
		final IStructuredSelection selection = this.list.getStructuredSelection();
		final String[] types = new String[selection.size()];
		final Iterator<ConversionMapping> iter = selection.iterator();
		int i = 0;
		while (iter.hasNext()) {
			types[i] = iter.next().getSource();
			i++;
		}
		removeTypeConversions(types);
	}
459781
public static VectorAccumulator asSumAccumulator(final double neutral) {
        return new VectorAccumulator() {
            private BigDecimal result = BigDecimal.valueOf(neutral);

            @Override
            public void update(int i, double value) {
                result = result.add(BigDecimal.valueOf(value));
            }

            @Override
            public double accumulate() {
                double value = result.setScale(Vectors.ROUND_FACTOR, RoundingMode.CEILING).doubleValue();
                result = BigDecimal.valueOf(neutral);
                return value;
            }
        };
    }
208532
public void setUsed(long value){
		used.setValueAsLong(value);
		minUsed.setValueIfLesserThanCurrentAsLong(value);
		maxUsed.setValueIfGreaterThanCurrentAsLong(value);
	}
29526
@Deprecated
    public boolean greaterMinor(Version other) {
        return other.major < this.major || other.major == this.major && other.minor < this.minor;
    }
443538
public static boolean movedStrictlyOutsideThresholdPercentage(final BigDecimal startValue, final BigDecimal newValue,
            final BigDecimal thresholdPercent) {
        final BigDecimal s = BigDecimalUtil.setScale(startValue, 10);
        final BigDecimal n = BigDecimalUtil.setScale(newValue, 10);
        final BigDecimal diff = BigDecimalUtil.divide(BigDecimalUtil.doSubtract(s, n), s, BigDecimal.ROUND_HALF_UP);

        return BigDecimalUtil.absCompareTo(diff, thresholdPercent) > 0;
    }
100681
public static <S> AreaSizeD toAreaSizeD(final PAreaSizeD<S> a)
  {
    Objects.requireNonNull(a, "area size");
    return AreaSizeD.of(a.sizeX(), a.sizeY());
  }
753708
public ArgumentOptions withMaxUsageWidth(int maxWidth) {
        if (tty.isInteractive()) {
            this.usageWidth = Math.min(maxWidth, tty.getTerminalSize().cols);
        } else {
            this.usageWidth = maxWidth;
        }
        return this;
    }
315117
private Dimension layoutSize(Container target, boolean preferred)
	{
	synchronized (target.getTreeLock())
	{
		//  Each row must fit with the width allocated to the containter.
		//  When the container width = 0, the preferred width of the container
		//  has not yet been calculated so lets ask for the maximum.

		int targetWidth = target.getSize().width;
		Container container = target;

		while (container.getSize().width == 0 && container.getParent() != null)
		{
			container = container.getParent();
		}

		targetWidth = container.getSize().width;

		if (targetWidth == 0)
			targetWidth = Integer.MAX_VALUE;

		int hgap = getHgap();
		int vgap = getVgap();
		Insets insets = target.getInsets();
		int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
		int maxWidth = targetWidth - horizontalInsetsAndGap;

		//  Fit components into the allowed width

		Dimension dim = new Dimension(0, 0);
		int rowWidth = 0;
		int rowHeight = 0;

		int nmembers = target.getComponentCount();

		for (int i = 0; i < nmembers; i++)
		{
			Component m = target.getComponent(i);

			if (m.isVisible())
			{
				Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

				//  Can't add the component to current row. Start a new row.

				if (rowWidth + d.width > maxWidth)
				{
					addRow(dim, rowWidth, rowHeight);
					rowWidth = 0;
					rowHeight = 0;
				}

				//  Add a horizontal gap for all components after the first

				if (rowWidth != 0)
				{
					rowWidth += hgap;
				}

				rowWidth += d.width;
				rowHeight = Math.max(rowHeight, d.height);
			}
		}

		addRow(dim, rowWidth, rowHeight);

		dim.width += horizontalInsetsAndGap;
		dim.height += insets.top + insets.bottom + vgap * 2;

		//	When using a scroll pane or the DecoratedLookAndFeel we need to
		//  make sure the preferred size is less than the size of the
		//  target containter so shrinking the container size works
		//  correctly. Removing the horizontal gap is an easy way to do this.

		Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

		if (scrollPane != null && target.isValid())
		{
			dim.width -= (hgap + 1);
		}

		return dim;
	}
	}
1288272
private static DSAKeyValidationParameters.Usage getUsage(int usage)
    {
        if (usage == DSAParameterGenerationParameters.DIGITAL_SIGNATURE_USAGE) {
            return DSAKeyValidationParameters.Usage.DIGITAL_SIGNATURE;
        } else if (usage == DSAParameterGenerationParameters.KEY_ESTABLISHMENT_USAGE) {
            return DSAKeyValidationParameters.Usage.KEY_ESTABLISHMENT;
        }
        return DSAKeyValidationParameters.Usage.ANY;
    }