java.util.function.DoubleBinaryOperator Java Examples
The following examples show how to use
java.util.function.DoubleBinaryOperator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrimitiveSumMinMaxTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void testDoubleMethods() { BinaryOperator<Double> sum1 = Double::sum; DoubleBinaryOperator sum2 = Double::sum; BinaryOperator<Double> max1 = Double::max; DoubleBinaryOperator max2 = Double::max; BinaryOperator<Double> min1 = Double::min; DoubleBinaryOperator min2 = Double::min; Comparator<Double> cmp = Double::compare; double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE }; for (double i : numbers) { for (double j : numbers) { assertEquals(i+j, (double) sum1.apply(i, j)); assertEquals(i+j, sum2.applyAsDouble(i, j)); assertEquals(Math.max(i,j), (double) max1.apply(i, j)); assertEquals(Math.max(i,j), max2.applyAsDouble(i, j)); assertEquals(Math.min(i,j), (double) min1.apply(i, j)); assertEquals(Math.min(i,j), min2.applyAsDouble(i, j)); assertEquals(((Double) i).compareTo(j), cmp.compare(i, j)); } } }
Example #2
Source File: PrimitiveSumMinMaxTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void testDoubleMethods() { BinaryOperator<Double> sum1 = Double::sum; DoubleBinaryOperator sum2 = Double::sum; BinaryOperator<Double> max1 = Double::max; DoubleBinaryOperator max2 = Double::max; BinaryOperator<Double> min1 = Double::min; DoubleBinaryOperator min2 = Double::min; Comparator<Double> cmp = Double::compare; double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE }; for (double i : numbers) { for (double j : numbers) { assertEquals(i+j, (double) sum1.apply(i, j)); assertEquals(i+j, sum2.applyAsDouble(i, j)); assertEquals(Math.max(i,j), (double) max1.apply(i, j)); assertEquals(Math.max(i,j), max2.applyAsDouble(i, j)); assertEquals(Math.min(i,j), (double) min1.apply(i, j)); assertEquals(Math.min(i,j), min2.applyAsDouble(i, j)); assertEquals(((Double) i).compareTo(j), cmp.compare(i, j)); } } }
Example #3
Source File: Matrix.java From symbol-sdk-java with Apache License 2.0 | 6 votes |
private Matrix join(final Matrix matrix, final boolean isTwoWay, final DoubleBinaryOperator op) { if (!this.isSameSize(matrix)) { throw new IllegalArgumentException("matrix sizes must be equal"); } final Matrix result = this.create(this.getRowCount(), this.getColumnCount()); this.forEach( (r, c, v) -> result .setAtUnchecked(r, c, op.applyAsDouble(v, matrix.getAtUnchecked(r, c)))); if (isTwoWay) { matrix.forEach( (r, c, v) -> result .setAtUnchecked(r, c, op.applyAsDouble(v, this.getAtUnchecked(r, c)))); } return result; }
Example #4
Source File: PrimitiveSumMinMaxTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void testDoubleMethods() { BinaryOperator<Double> sum1 = Double::sum; DoubleBinaryOperator sum2 = Double::sum; BinaryOperator<Double> max1 = Double::max; DoubleBinaryOperator max2 = Double::max; BinaryOperator<Double> min1 = Double::min; DoubleBinaryOperator min2 = Double::min; Comparator<Double> cmp = Double::compare; double[] numbers = { -1, 0, 1, 100, Double.MAX_VALUE, Double.MIN_VALUE }; for (double i : numbers) { for (double j : numbers) { assertEquals(i+j, (double) sum1.apply(i, j)); assertEquals(i+j, sum2.applyAsDouble(i, j)); assertEquals(Math.max(i,j), (double) max1.apply(i, j)); assertEquals(Math.max(i,j), max2.applyAsDouble(i, j)); assertEquals(Math.min(i,j), (double) min1.apply(i, j)); assertEquals(Math.min(i,j), min2.applyAsDouble(i, j)); assertEquals(((Double) i).compareTo(j), cmp.compare(i, j)); } } }
Example #5
Source File: ParallelPrefix.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "doubleSet") public static Object[][] doubleSet(){ return genericData(size -> IntStream.range(0, size).mapToDouble(i -> (double)i).toArray(), new DoubleBinaryOperator[]{ Double::sum, Double::min}); }
Example #6
Source File: ArrayPrefixHelpers.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** Subtask constructor */ DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) { super(parent); this.function = function; this.array = array; this.origin = origin; this.fence = fence; this.threshold = threshold; this.lo = lo; this.hi = hi; }
Example #7
Source File: ReduceOps.java From desugar_jdk_libs with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #8
Source File: Serial.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
static void testDoubleAccumulator() { DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y; DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d); a.accumulate(17.5d); DoubleAccumulator result = echo(a); if (result.get() != a.get()) throw new RuntimeException("Unexpected value"); a.reset(); result.reset(); if (result.get() != a.get()) throw new RuntimeException("Unexpected value after reset"); checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy"); }
Example #9
Source File: ReduceOps.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #10
Source File: Serial.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static void testDoubleAccumulator() { DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y; DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d); a.accumulate(17.5d); DoubleAccumulator result = echo(a); if (result.get() != a.get()) throw new RuntimeException("Unexpected value"); a.reset(); result.reset(); if (result.get() != a.get()) throw new RuntimeException("Unexpected value after reset"); checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy"); }
Example #11
Source File: ReduceOps.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #12
Source File: ReduceOps.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #13
Source File: ParallelPrefix.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="doubleSet") public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) { double[] sequentialResult = data.clone(); for (int index = fromIndex + 1; index < toIndex; index++) { sequentialResult[index ] = op.applyAsDouble(sequentialResult[index - 1], sequentialResult[index]); } double[] parallelResult = data.clone(); Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op); assertEquals(parallelResult, sequentialResult); double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex); Arrays.parallelPrefix(parallelRangeResult, op); assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex)); }
Example #14
Source File: ArrayPrefixHelpers.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** Subtask constructor */ DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) { super(parent); this.function = function; this.array = array; this.origin = origin; this.fence = fence; this.threshold = threshold; this.lo = lo; this.hi = hi; }
Example #15
Source File: ArrayPrefixHelpers.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** Root task constructor */ public DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int lo, int hi) { super(parent); this.function = function; this.array = array; this.lo = this.origin = lo; this.hi = this.fence = hi; int p; this.threshold = (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) <= MIN_PARTITION ? MIN_PARTITION : p; }
Example #16
Source File: ParallelPrefix.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@DataProvider public static Object[][] doubleSet(){ return genericData(size -> IntStream.range(0, size).mapToDouble(i -> (double)i).toArray(), new DoubleBinaryOperator[]{ Double::sum, Double::min}); }
Example #17
Source File: ParallelPrefix.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="doubleSet") public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) { double[] sequentialResult = data.clone(); for (int index = fromIndex + 1; index < toIndex; index++) { sequentialResult[index ] = op.applyAsDouble(sequentialResult[index - 1], sequentialResult[index]); } double[] parallelResult = data.clone(); Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op); assertArraysEqual(parallelResult, sequentialResult); double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex); Arrays.parallelPrefix(parallelRangeResult, op); assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex)); }
Example #18
Source File: ArrayPrefixHelpers.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** Subtask constructor */ DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) { super(parent); this.function = function; this.array = array; this.origin = origin; this.fence = fence; this.threshold = threshold; this.lo = lo; this.hi = hi; }
Example #19
Source File: ReduceOps.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #20
Source File: ArrayPrefixHelpers.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** Subtask constructor */ DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) { super(parent); this.function = function; this.array = array; this.origin = origin; this.fence = fence; this.threshold = threshold; this.lo = lo; this.hi = hi; }
Example #21
Source File: ParallelPrefix.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider public static Object[][] doubleSet(){ return genericData(size -> IntStream.range(0, size).mapToDouble(i -> (double)i).toArray(), new DoubleBinaryOperator[]{ Double::sum, Double::min}); }
Example #22
Source File: ReduceOps.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #23
Source File: Serial.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static void testDoubleAccumulator() { DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y; DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d); a.accumulate(17.5d); DoubleAccumulator result = echo(a); if (result.get() != a.get()) throw new RuntimeException("Unexpected value"); a.reset(); result.reset(); if (result.get() != a.get()) throw new RuntimeException("Unexpected value after reset"); checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy"); }
Example #24
Source File: ArrayPrefixHelpers.java From Bytecoder with Apache License 2.0 | 5 votes |
/** Root task constructor */ public DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int lo, int hi) { super(parent); this.function = function; this.array = array; this.lo = this.origin = lo; this.hi = this.fence = hi; int p; this.threshold = (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) <= MIN_PARTITION ? MIN_PARTITION : p; }
Example #25
Source File: DoubleAccumulator.java From Bytecoder with Apache License 2.0 | 5 votes |
SerializationProxy(double value, DoubleBinaryOperator function, long identity) { this.value = value; this.function = function; this.identity = identity; }
Example #26
Source File: ArrayPrefixHelpers.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** Subtask constructor */ DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) { super(parent); this.function = function; this.array = array; this.origin = origin; this.fence = fence; this.threshold = threshold; this.lo = lo; this.hi = hi; }
Example #27
Source File: ReduceOps.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #28
Source File: ReduceOps.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Constructs a {@code TerminalOp} that implements a functional reduce on * {@code double} values. * * @param identity the identity for the combining function * @param operator the combining function * @return a {@code TerminalOp} implementing the reduction */ public static TerminalOp<Double, Double> makeDouble(double identity, DoubleBinaryOperator operator) { Objects.requireNonNull(operator); class ReducingSink implements AccumulatingSink<Double, Double, ReducingSink>, Sink.OfDouble { private double state; @Override public void begin(long size) { state = identity; } @Override public void accept(double t) { state = operator.applyAsDouble(state, t); } @Override public Double get() { return state; } @Override public void combine(ReducingSink other) { accept(other.state); } } return new ReduceOp<Double, Double, ReducingSink>(StreamShape.DOUBLE_VALUE) { @Override public ReducingSink makeSink() { return new ReducingSink(); } }; }
Example #29
Source File: ParallelPrefix.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="doubleSet") public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) { double[] sequentialResult = data.clone(); for (int index = fromIndex + 1; index < toIndex; index++) { sequentialResult[index ] = op.applyAsDouble(sequentialResult[index - 1], sequentialResult[index]); } double[] parallelResult = data.clone(); Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op); assertEquals(parallelResult, sequentialResult); double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex); Arrays.parallelPrefix(parallelRangeResult, op); assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex)); }
Example #30
Source File: FloatStamp.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static double meetBounds(double a, double b, DoubleBinaryOperator op) { if (Double.isNaN(a)) { return b; } else if (Double.isNaN(b)) { return a; } else { return op.applyAsDouble(a, b); } }