public void testMinMax() { TestUtils.assertEquals(Math.min(2, -78), FunctionUtils.min(2, -78)); TestUtils.assertEquals(Math.max(2, -78), FunctionUtils.max(2, -78)); TestUtils.assertEquals(67, FunctionUtils.max(new int[] {67})); TestUtils.assertEquals(67, FunctionUtils.min(new int[] {67})); TestUtils.assertEquals(FunctionUtils.max(67, -76), FunctionUtils.max(new int[] {67, -76})); TestUtils.assertEquals(FunctionUtils.min(67, -76), FunctionUtils.min(new int[] {67, -76})); TestUtils.assertEquals( FunctionUtils.max(0, 67, -76), FunctionUtils.max(new int[] {0, 67, -76})); TestUtils.assertEquals( FunctionUtils.min(0, 67, -76), FunctionUtils.min(new int[] {0, 67, -76})); TestUtils.assertEquals( FunctionUtils.max(0, 67, -76, 80), FunctionUtils.max(new int[] {0, 67, -76, 80})); TestUtils.assertEquals( FunctionUtils.min(0, 67, -76, -80), FunctionUtils.min(new int[] {0, 67, -76, -80})); TestUtils.assertEquals( FunctionUtils.max(80, 0, 67, -76), FunctionUtils.max(new int[] {80, 0, 67, -76})); TestUtils.assertEquals( FunctionUtils.min(-80, 0, 67, -76), FunctionUtils.min(new int[] {-80, 0, 67, -76})); TestUtils.assertEquals(80, FunctionUtils.max(new int[] {0, 67, -76, 80})); TestUtils.assertEquals(-80, FunctionUtils.min(new int[] {0, 67, -76, -80})); TestUtils.assertEquals(80, FunctionUtils.max(new int[] {80, 0, 67, -76})); TestUtils.assertEquals(-80, FunctionUtils.min(new int[] {-80, 0, 67, -76})); }
private QuadraticSolver buildIterationSolver(final boolean addSmallDiagonal) { MatrixStore<Double> tmpQ = this.getQ(); final MatrixStore<Double> tmpC = this.getC(); if (addSmallDiagonal) { final PhysicalStore<Double> tmpCopyQ = tmpQ.copy(); final double tmpLargest = tmpCopyQ.aggregateAll(Aggregator.LARGEST); final double tmpRelativelySmall = MACHINE_DOUBLE_ERROR * tmpLargest; final double tmpPracticalLimit = MACHINE_DOUBLE_ERROR + IS_ZERO; final double tmpSmallToAdd = Math.max(tmpRelativelySmall, tmpPracticalLimit); final UnaryFunction<Double> tmpFunc = ADD.second(tmpSmallToAdd); tmpCopyQ.modifyDiagonal(0, 0, tmpFunc); tmpQ = tmpCopyQ; } if (this.hasEqualityConstraints()) { final MatrixStore<Double> tmpAE = this.getAE(); final MatrixStore<Double> tmpBE = this.getBE(); final int tmpZeroSize = tmpAE.getRowDim(); final MatrixStore<Double> tmpUpperLeftAE = tmpQ; final MatrixStore<Double> tmpUpperRightAE = tmpAE.builder().transpose().build(); final MatrixStore<Double> tmpLowerLefAE = tmpAE; final MatrixStore<Double> tmpLowerRightAE = ZeroStore.makePrimitive(tmpZeroSize, tmpZeroSize); final MatrixStore<Double> tmpSubAE = new AboveBelowStore<Double>( new LeftRightStore<Double>(tmpUpperLeftAE, tmpUpperRightAE), new LeftRightStore<Double>(tmpLowerLefAE, tmpLowerRightAE)); final MatrixStore<Double> tmpUpperBE = tmpC; final MatrixStore<Double> tmpLowerBE = tmpBE; final MatrixStore<Double> tmpSubBE = new AboveBelowStore<Double>(tmpUpperBE, tmpLowerBE); return new Builder().equalities(tmpSubAE, tmpSubBE).build(options); } else { return new Builder().equalities(tmpQ, tmpC).build(options); } }