本文整理匯總了Java中java.util.function.DoubleBinaryOperator.applyAsDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java DoubleBinaryOperator.applyAsDouble方法的具體用法?Java DoubleBinaryOperator.applyAsDouble怎麽用?Java DoubleBinaryOperator.applyAsDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.function.DoubleBinaryOperator
的用法示例。
在下文中一共展示了DoubleBinaryOperator.applyAsDouble方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: linearlyMergedUsing
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
/**
* Form a new polynomial by operating on each like term of self and another polynomial.
* This and the other is not changed.
*
* @param operator how to combine each term of this with each term of the `another` polynomial.
* @param another the other polynomial involved in the computation.
* @return the resulting polynomial.
*/
protected Polynomial linearlyMergedUsing(DoubleBinaryOperator operator, /*with*/ Polynomial another) {
// Validate
int thisDegree = getDegree();
int thatDegree = another.getDegree();
while (another.getCoefficientForExponent(thatDegree) == 0) thatDegree--;
// Allocate according to the highest degree
int maxDegree = Math.max(thisDegree, thatDegree);
double[] resultCoefficientsInNaturalOrder = new double[maxDegree + 1];
// Apply operator on each term
for (int exponent = maxDegree, i = 0; exponent >= 0; exponent--, i++) {
if (exponent <= thisDegree)
resultCoefficientsInNaturalOrder[i] += getCoefficientForExponent(exponent);
if (exponent <= thatDegree)
resultCoefficientsInNaturalOrder[i] = operator.applyAsDouble(
resultCoefficientsInNaturalOrder[i],
another.getCoefficientForExponent(exponent)
);
}
return new ArrayBasedPoly(resultCoefficientsInNaturalOrder);
}
示例2: compute
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
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;
}
}
}
}
示例3: getBinaryOperator
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
private static BinaryOperator<Vec3D> getBinaryOperator(DoubleBinaryOperator op) {
return (a, b) -> {
double x = op.applyAsDouble(a.x, b.x);
double y = op.applyAsDouble(a.y, b.y);
double z = op.applyAsDouble(a.z, b.z);
return new Vec3D(x, y, z);
};
}
示例4: map
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector4d map(@NonNull final Vector4d that, @NonNull final DoubleBinaryOperator operator) {
this.x = operator.applyAsDouble(this.x, that.x());
this.y = operator.applyAsDouble(this.y, that.y());
this.z = operator.applyAsDouble(this.z, that.z());
this.w = operator.applyAsDouble(this.w, that.w());
return this;
}
示例5: map
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector4f map(@NonNull final Vector4f that, @NonNull final DoubleBinaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x, that.x());
this.y = (float) operator.applyAsDouble(this.y, that.y());
this.z = (float) operator.applyAsDouble(this.z, that.z());
this.w = (float) operator.applyAsDouble(this.w, that.w());
return this;
}
示例6: map
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector3f map(@NonNull final Vector3f that, @NonNull final DoubleBinaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x, that.x());
this.y = (float) operator.applyAsDouble(this.y, that.y());
this.z = (float) operator.applyAsDouble(this.z, that.z());
return this;
}
示例7: map
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector2f map(@NonNull final Vector2f that, @NonNull final DoubleBinaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x, that.x());
this.y = (float) operator.applyAsDouble(this.y, that.y());
return this;
}
示例8: linearlyMergedUsing
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
/**
* Form a new polynomial by operating on each like term of self and another polynomial.
* A non-existing term is treated as a term with coefficient of 0.
* This and the other is not changed.
*
* @param operator how to combine each pair of like terms of this and `another` polynomial.
* @param another the other polynomial involved in the computation.
* @return the resulting polynomial.
* @implSpec Complexity: O(n)
*/
protected Polynomial linearlyMergedUsing(DoubleBinaryOperator operator, /*with*/ Polynomial another) {
// Validate
int thisDegree = getDegree();
int thatDegree = another.getDegree();
while (another.getCoefficientForExponent(thatDegree) == 0) thatDegree--;
// Allocate according to the highest degree
int maxDegree = Math.max(thisDegree, thatDegree);
TermListNode newHead = null, curTail = null, i = terms,
/*for efficiency*/ tmp, copy;
double coefficient;
// Apply operator on each term
for (int exponent = maxDegree; exponent >= 0; exponent--) {
coefficient = 0;
if (exponent <= thisDegree)
if ((tmp = getTermForExponent(exponent, i)) != null)
coefficient = (i = tmp).getCoefficient();
if (exponent <= thatDegree)
coefficient = operator.applyAsDouble(coefficient,
another.getCoefficientForExponent(exponent));
if (coefficient == 0) continue; // Skip null
copy = new TermListNode(exponent, coefficient, null);
if (newHead == null) newHead = curTail = copy;
else curTail.setNext(curTail = copy);
}
SinglyBasedPolynomial result = new SinglyBasedPolynomial();
if (newHead != null) result.terms = newHead;
return result;
}
示例9: compute
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
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;
}
}
}
}
示例10: testParallelPrefixForDouble
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
@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));
}
示例11: makeDouble
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
/**
* 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();
}
};
}
示例12: meetBounds
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
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);
}
}
示例13: makeDouble
import java.util.function.DoubleBinaryOperator; //導入方法依賴的package包/類
/**
* Constructs a {@code TerminalOp} that implements a functional reduce on
* {@code double} values, producing an optional double result.
*
* @param operator the combining function
* @return a {@code TerminalOp} implementing the reduction
*/
public static TerminalOp<Double, OptionalDouble>
makeDouble(DoubleBinaryOperator operator) {
Objects.requireNonNull(operator);
class ReducingSink
implements AccumulatingSink<Double, OptionalDouble, ReducingSink>, Sink.OfDouble {
private boolean empty;
private double state;
public void begin(long size) {
empty = true;
state = 0;
}
@Override
public void accept(double t) {
if (empty) {
empty = false;
state = t;
}
else {
state = operator.applyAsDouble(state, t);
}
}
@Override
public OptionalDouble get() {
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public void combine(ReducingSink other) {
if (!other.empty)
accept(other.state);
}
}
return new ReduceOp<Double, OptionalDouble, ReducingSink>(StreamShape.DOUBLE_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}