/// <summary> /// Constructs a {@code TerminalOp} that implements a functional reduce on /// {@code double} values. /// </summary> /// <param name="identity"> the identity for the combining function </param> /// <param name="operator"> the combining function </param> /// <returns> a {@code TerminalOp} implementing the reduction </returns> public static TerminalOp <Double, Double> MakeDouble(double identity, DoubleBinaryOperator @operator) { Objects.RequireNonNull(@operator); //JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter: // 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 ReduceOpAnonymousInnerClassHelper11()); }
/// <summary> /// Subtask constructor </summary> internal DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int origin, int fence, int threshold, int lo, int hi) : base(parent) { this.Function = function; this.Array = array; this.Origin = origin; this.Fence = fence; this.Threshold = threshold; this.Lo = lo; this.Hi = hi; }
/// <summary> /// Root task constructor </summary> public DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, double[] array, int lo, int hi) : base(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.CommonPoolParallelism << 3)) <= MIN_PARTITION ? MIN_PARTITION : p; }
/// <summary> /// Constructs a {@code TerminalOp} that implements a functional reduce on /// {@code double} values, producing an optional double result. /// </summary> /// <param name="operator"> the combining function </param> /// <returns> a {@code TerminalOp} implementing the reduction </returns> public static TerminalOp <Double, OptionalDouble> MakeDouble(DoubleBinaryOperator @operator) { Objects.RequireNonNull(@operator); //JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter: // class ReducingSink implements AccumulatingSink<Double, java.util.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 ReduceOpAnonymousInnerClassHelper12()); }
public static Object Arith(Object a, Object b, ArithOpEnum op) { LongBinaryOperator integerFunc = integerOps[(int)op]; DoubleBinaryOperator floatFunc = floatOps[(int)op]; if (floatFunc == null) { long?x = LuaValue.ToInteger(a); if (x != null) { long?y = LuaValue.ToInteger(b); if (y != null) { return(integerFunc((long)x, (long)y)); } } } else { if (integerFunc != null) { if (TypeExtension.TypeEqual <long>(a) && TypeExtension.TypeEqual <long>(b)) { return(integerFunc((long)a, (long)b)); } } double?x = LuaValue.ToFloat(a); if (x != null) { double?y = LuaValue.ToFloat(b); if (y != null) { return(floatFunc((double)x, (double)y)); } } } return(null); }
/// <summary>Returns the result of applying the specified /// function of two variables (binary operator) to a double and an object of type T. /// The first argument is passed to the function, the second argument is self.</summary> public abstract T Apply(double firstArg, DoubleBinaryOperator binaryFunc);
/// <summary>Returns the result of applying the specified /// function of two variables (binary operator) to an object of type T and a double. /// The first argument is self, the second (double) is passed to the function.</summary> public abstract T Apply(DoubleBinaryOperator binaryFunc, double secondArg);
public DoubleAccumulator(DoubleBinaryOperator arg0, double arg1) : base(ProxyCtor.I) { Instance.CallConstructor("(Ljava/util/function/DoubleBinaryOperator;D)V", arg0, arg1); }
private readonly long Identity; // use long representation /// <summary> /// Creates a new instance using the given accumulator function /// and identity element. </summary> /// <param name="accumulatorFunction"> a side-effect-free function of two arguments </param> /// <param name="identity"> identity (initial value) for the accumulator function </param> public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, double identity) { this.Function = accumulatorFunction; @base = this.Identity = Double.doubleToRawLongBits(identity); }
internal SerializationProxy(DoubleAccumulator a) { Function = a.Function; Identity = a.Identity; Value = a.Get(); }
/// <summary> /// Same as longAccumulate, but injecting long/double conversions /// in too many places to sensibly merge with long version, given /// the low-overhead requirements of this class. So must instead be /// maintained by copy/paste/adapt. /// </summary> internal void DoubleAccumulate(double x, DoubleBinaryOperator fn, bool wasUncontended) { int h; if ((h = Probe) == 0) { ThreadLocalRandom.Current(); // force initialization h = Probe; wasUncontended = true; } bool collide = false; // True if last slot nonempty for (;;) { Cell[] @as; Cell a; int n; long v; if ((@as = Cells) != null && (n = @as.Length) > 0) { if ((a = @as[(n - 1) & h]) == null) { if (CellsBusy == 0) // Try to attach new Cell { Cell r = new Cell(Double.doubleToRawLongBits(x)); if (CellsBusy == 0 && CasCellsBusy()) { bool created = false; try // Recheck under lock { Cell[] rs; int m, j; if ((rs = Cells) != null && (m = rs.Length) > 0 && rs[j = (m - 1) & h] == null) { rs[j] = r; created = true; } } finally { CellsBusy = 0; } if (created) { break; } continue; // Slot is now non-empty } } collide = false; } else if (!wasUncontended) // CAS already known to fail { wasUncontended = true; // Continue after rehash } else if (a.Cas(v = a.Value, ((fn == null) ? Double.doubleToRawLongBits(Double.longBitsToDouble(v) + x) : Double.doubleToRawLongBits(fn.ApplyAsDouble(Double.longBitsToDouble(v), x))))) { break; } else if (n >= NCPU || Cells != @as) { collide = false; // At max size or stale } else if (!collide) { collide = true; } else if (CellsBusy == 0 && CasCellsBusy()) { try { if (Cells == @as) // Expand table unless stale { Cell[] rs = new Cell[n << 1]; for (int i = 0; i < n; ++i) { rs[i] = @as[i]; } Cells = rs; } } finally { CellsBusy = 0; } collide = false; continue; // Retry with expanded table } h = AdvanceProbe(h); } else if (CellsBusy == 0 && Cells == @as && CasCellsBusy()) { bool init = false; try // Initialize table { if (Cells == @as) { Cell[] rs = new Cell[2]; rs[h & 1] = new Cell(Double.doubleToRawLongBits(x)); Cells = rs; init = true; } } finally { CellsBusy = 0; } if (init) { break; } } else if (CasBase(v = @base, ((fn == null) ? Double.doubleToRawLongBits(Double.longBitsToDouble(v) + x) : Double.doubleToRawLongBits(fn.ApplyAsDouble(Double.longBitsToDouble(v), x))))) { break; // Fall back on using base } } }