@Override public boolean test(double t) { if (!initialized) { result = t; initialized = true; } else { result = accumulator.applyAsDouble(result, t); } return true; } }
/** * Reduction with binary operator * * @param op the operator * @return Optional with the result of reducing all rows with operator */ default Optional<Double> reduce(DoubleBinaryOperator op) { boolean first = true; double acc = 0.0; for (int i = 0; i < size(); i++) { double d = getDouble(i); if (first) { acc = d; first = false; } else { acc = op.applyAsDouble(acc, d); } } return (first ? Optional.<Double>empty() : Optional.<Double>of(acc)); }
/** * Reduction with binary operator and initial value * * @param initial initial value * @param op the operator * @return the result of reducing initial value and all rows with operator */ default double reduce(double initial, DoubleBinaryOperator op) { double acc = initial; for (int i = 0; i < size(); i++) { acc = op.applyAsDouble(acc, getDouble(i)); } return acc; }
/** * Atomically update the current value using the given {@link DoubleBinaryOperator accumulator function}. The new * value is calculated by applying the accumulator function to the current value and the given {@code updateValue}. * * @param updateValue the value which will be passed into the accumulator function. * @param accumulatorFunction the function which calculates the value to set. Should be a pure function (no side * effects), because it will be applied several times if update attempts fail due to concurrent calls. Must * not be {@literal null}. * @return the updated value. * @since 2.2 */ public double accumulateAndGet(double updateValue, DoubleBinaryOperator accumulatorFunction) { Assert.notNull(accumulatorFunction, "Accumulator function must not be null!"); double previousValue, newValue; do { previousValue = get(); newValue = accumulatorFunction.applyAsDouble(previousValue, updateValue); } while (!compareAndSet(previousValue, newValue)); return newValue; }
/** * Atomically update the current value using the given {@link DoubleBinaryOperator accumulator function}. The new * value is calculated by applying the accumulator function to the current value and the given {@code updateValue}. * * @param updateValue the value which will be passed into the accumulator function. * @param accumulatorFunction the function which calculates the value to set. Should be a pure function (no side * effects), because it will be applied several times if update attempts fail due to concurrent calls. Must * not be {@literal null}. * @return the previous value. * @since 2.2 */ public double getAndAccumulate(double updateValue, DoubleBinaryOperator accumulatorFunction) { Assert.notNull(accumulatorFunction, "Accumulator function must not be null!"); double previousValue, newValue; do { previousValue = get(); newValue = accumulatorFunction.applyAsDouble(previousValue, updateValue); } while (!compareAndSet(previousValue, newValue)); return previousValue; }
public final void compute() { final ToDoubleFunction<Map.Entry<K,V>> transformer; final DoubleBinaryOperator reducer; if ((transformer = this.transformer) != null && (reducer = this.reducer) != null) { double r = this.basis; for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) { addToPendingCount(1); (rights = new MapReduceEntriesToDoubleTask<K,V> (this, batch >>>= 1, baseLimit = h, f, tab, rights, transformer, r, reducer)).fork(); } for (Node<K,V> p; (p = advance()) != null; ) r = reducer.applyAsDouble(r, transformer.applyAsDouble(p)); result = r; CountedCompleter<?> c; for (c = firstComplete(); c != null; c = c.nextComplete()) { @SuppressWarnings("unchecked") MapReduceEntriesToDoubleTask<K,V> t = (MapReduceEntriesToDoubleTask<K,V>)c, s = t.rights; while (s != null) { t.result = reducer.applyAsDouble(t.result, s.result); s = t.rights = s.nextRight; } } } } }
public final void compute() { final ToDoubleFunction<? super K> transformer; final DoubleBinaryOperator reducer; if ((transformer = this.transformer) != null && (reducer = this.reducer) != null) { double r = this.basis; for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) { addToPendingCount(1); (rights = new MapReduceKeysToDoubleTask<K,V> (this, batch >>>= 1, baseLimit = h, f, tab, rights, transformer, r, reducer)).fork(); } for (Node<K,V> p; (p = advance()) != null; ) r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.key)); result = r; CountedCompleter<?> c; for (c = firstComplete(); c != null; c = c.nextComplete()) { @SuppressWarnings("unchecked") MapReduceKeysToDoubleTask<K,V> t = (MapReduceKeysToDoubleTask<K,V>)c, s = t.rights; while (s != null) { t.result = reducer.applyAsDouble(t.result, s.result); s = t.rights = s.nextRight; } } } } }
public final void compute() { final ToDoubleFunction<? super V> transformer; final DoubleBinaryOperator reducer; if ((transformer = this.transformer) != null && (reducer = this.reducer) != null) { double r = this.basis; for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) { addToPendingCount(1); (rights = new MapReduceValuesToDoubleTask<K,V> (this, batch >>>= 1, baseLimit = h, f, tab, rights, transformer, r, reducer)).fork(); } for (Node<K,V> p; (p = advance()) != null; ) r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.val)); result = r; CountedCompleter<?> c; for (c = firstComplete(); c != null; c = c.nextComplete()) { @SuppressWarnings("unchecked") MapReduceValuesToDoubleTask<K,V> t = (MapReduceValuesToDoubleTask<K,V>)c, s = t.rights; while (s != null) { t.result = reducer.applyAsDouble(t.result, s.result); s = t.rights = s.nextRight; } } } } }
public final void compute() { final ToDoubleBiFunction<? super K, ? super V> transformer; final DoubleBinaryOperator reducer; if ((transformer = this.transformer) != null && (reducer = this.reducer) != null) { double r = this.basis; for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) { addToPendingCount(1); (rights = new MapReduceMappingsToDoubleTask<K,V> (this, batch >>>= 1, baseLimit = h, f, tab, rights, transformer, r, reducer)).fork(); } for (Node<K,V> p; (p = advance()) != null; ) r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.key, p.val)); result = r; CountedCompleter<?> c; for (c = firstComplete(); c != null; c = c.nextComplete()) { @SuppressWarnings("unchecked") MapReduceMappingsToDoubleTask<K,V> t = (MapReduceMappingsToDoubleTask<K,V>)c, s = t.rights; while (s != null) { t.result = reducer.applyAsDouble(t.result, s.result); s = t.rights = s.nextRight; } } } } }
@Property public void works(DoubleBinaryOperator f, double first, double second) { double result = f.applyAsDouble(first, second); } }
public static void fillMatching(final double[][] target, final double[][] left, final DoubleBinaryOperator function, final double[][] right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left[i][j], right[i][j]); } } }
@Override public void accept(double next) { if(started) { acc = op.applyAsDouble(acc, next); } else { started = true; acc = next; } } }
public static void fillMatching(final double[][] target, final double[][] left, final DoubleBinaryOperator function, final double right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left[i][j], right); } } }
public static void fillMatching(final double[][] target, final double left, final DoubleBinaryOperator function, final double[][] right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left, right[i][j]); } } }
public static void fillMatching(final double[][] target, final double[][] left, final DoubleBinaryOperator function, final double right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left[i][j], right); } } }
public static void fillMatching(final double[][] target, final double[][] left, final DoubleBinaryOperator function, final double[][] right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left[i][j], right[i][j]); } } }
public static void fillMatching(final double[][] target, final double left, final DoubleBinaryOperator function, final double[][] right) { final int tmpLength = target.length; for (int i = 0; i < tmpLength; i++) { final int tmpInnerLength = target[i].length; for (int j = 0; j < tmpInnerLength; j++) { target[i][j] = function.applyAsDouble(left, right[i][j]); } } }
public void ThreeDimensionalGraph(Location loc, double startX, double startZ, double endX, double endZ, double smoothness, DoubleBinaryOperator f) { for (double x = startX; x < endX; x += smoothness) { for (double z = startZ; z < endZ; z += smoothness) { double y = f.applyAsDouble(x, z); //drawing } } }
private static long apply(DoubleBinaryOperator fn, long v, double x) { double d = Double.longBitsToDouble(v); d = (fn == null) ? d + x : fn.applyAsDouble(d, x); return Double.doubleToRawLongBits(d); }
private static long apply(DoubleBinaryOperator fn, long v, double x) { double d = Double.longBitsToDouble(v); d = (fn == null) ? d + x : fn.applyAsDouble(d, x); return Double.doubleToRawLongBits(d); }