List of usage examples for org.apache.commons.math.util MathUtils gcd
public static long gcd(final long p, final long q)
Gets the greatest common divisor of the absolute value of two numbers, using the "binary gcd" method which avoids division and modulo operations.
From source file:org.apache.flink.streaming.api.invokable.operator.co.CoBatchReduceInvokable.java
public CoBatchReduceInvokable(CoReduceFunction<IN1, IN2, OUT> coReducer, long batchSize1, long batchSize2, long slideSize1, long slideSize2) { super(coReducer); this.coReducer = coReducer; this.batchSize1 = batchSize1; this.batchSize2 = batchSize2; this.slideSize1 = slideSize1; this.slideSize2 = slideSize2; this.granularity1 = (int) MathUtils.gcd(batchSize1, slideSize1); this.granularity2 = (int) MathUtils.gcd(batchSize2, slideSize2); this.batchPerSlide1 = slideSize1 / granularity1; this.batchPerSlide2 = slideSize2 / granularity2; this.numberOfBatches1 = batchSize1 / granularity1; this.numberOfBatches2 = batchSize2 / granularity2; }
From source file:org.apache.flink.streaming.api.invokable.operator.WindowReduceInvokable.java
public WindowReduceInvokable(GroupReduceFunction<IN, OUT> reduceFunction, long windowSize, long slideInterval) { super(reduceFunction); this.reducer = reduceFunction; this.windowSize = windowSize; this.slideSize = slideInterval; this.granularity = MathUtils.gcd(windowSize, slideSize); this.listSize = (int) granularity; }
From source file:org.apache.flink.streaming.api.invokable.operator.WindowReduceInvokable.java
public WindowReduceInvokable(ReduceFunction<IN> reduceFunction, long windowSize, long slideInterval) { super(reduceFunction); this.windowSize = windowSize; this.slideSize = slideInterval; this.granularity = MathUtils.gcd(windowSize, slideSize); this.listSize = (int) granularity; }
From source file:org.apache.hadoop.metrics2.impl.MetricsSystemImpl.java
private synchronized void configureSinks() { sinkConfigs = config.getInstanceConfigs(SINK_KEY); int confPeriod = 0; for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) { MetricsConfig conf = entry.getValue(); int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT); confPeriod = confPeriod == 0 ? sinkPeriod : MathUtils.gcd(confPeriod, sinkPeriod); String sinkName = entry.getKey(); LOG.debug("sink " + sinkName + " config:\n" + conf); try {/*from w ww .j a va 2s . co m*/ MetricsSinkAdapter sa = newSink(sinkName, conf.getString(DESC_KEY, sinkName), conf); // we allow config of later registered sinks if (sa != null) { sa.start(); sinks.put(sinkName, sa); } } catch (Exception e) { LOG.warn("Error creating " + sinkName, e); } } period = confPeriod > 0 ? confPeriod : config.getInt(PERIOD_KEY, PERIOD_DEFAULT); }
From source file:org.netxilia.functions.MathFunctions.java
/** * Returns the greatest common divisor of one or more integers. * /*from w w w . j a v a 2 s .c om*/ * @return */ public long GCD(Iterator<Long> values) { if (!values.hasNext()) { return 1; } long result = values.next(); while (values.hasNext()) { result = MathUtils.gcd(result, values.next()); } return result; }