@Override public void setConcurrency(int concurrency) { // The setting of the concurrency can only reduce the number // of threads available in the context. int nbThreads = MathLib.min(parent.threads.length, concurrency); threads = new ConcurrentThreadImpl[nbThreads]; for (int i = 0; i < nbThreads; i++) { // Reused from parent threads. threads[i] = parent.threads[i]; } }
private double getMin(double[] fftd, int lowerCutoff, int upperCutoffHz) { double min = Double.MAX_VALUE; for (int i = lowerCutoff; i <= upperCutoffHz; i++) { min = MathLib.min(min, fftd[i]); } return min; }
@Override protected Integer initialized(Integer value) { return MathLib.min(value, 65536); // Hard-limiting }
/** * Performs the logical AND operation on this bit set and the * given bit set. This means it builds the intersection * of the two sets. The result is stored into this bit set. * * @param that the second bit set. */ public void and(FastBitSet that) { final int n = MathLib.min(this._length, that._length); for (int i = 0; i < n; ++i) { this.bits[i] &= that.bits[i]; } this._length = n; }
@Override protected Integer initialized(Integer value) { return MathLib.min(value, 65536); // Hard-limiting }
public final void clear() { for (int i = 0; i < _size; i += C1) { final int count = MathLib.min(_size - i, C1); final E [] low = _high[i >> B1]; System.arraycopy(NULL_BLOCK, 0, low, 0, count); } _size = 0; // No need for volatile, removal are not thread-safe. }
/** * Prints out this text builder to the specified writer. * * @param writer the destination writer. */ public void print(Writer writer) throws IOException { for (int i = 0; i < _length; i += C1) { char[] chars = _high[i >> B1]; writer.write(chars, 0, MathLib.min(C1, _length - i)); } }
private static void reset(Object[] entries) { for (int i = 0; i < entries.length;) { int count = MathLib.min(entries.length - i, C1); System.arraycopy(NULL_ENTRIES, 0, entries, i, count); i += count; } } private static final Entry[] NULL_ENTRIES = new Entry[C1];
private void copyTo(FractalTableImpl that) { int n = MathLib.min(this.data.length, that.data.length); offset &= (data.length << shift) - 1; // Makes it positive. int o = offset >> shift; if ((o + n) > data.length) { // Wrapping. int w = (o + n) - data.length; n -= w; System.arraycopy(data, 0, that.data, n, w); } System.arraycopy(data, o, that.data, 0, n); that.offset = offset - (o << shift); }
private void copyTo(FractalTableImpl that) { int n = MathLib.min(this.data.length, that.data.length); offset &= (data.length << shift) - 1; // Makes it positive. int o = offset >> shift; if ((o + n) > data.length) { // Wrapping. int w = (o + n) - data.length; n -= w; System.arraycopy(data, 0, that.data, n, w); } System.arraycopy(data, o, that.data, 0, n); that.offset = offset - (o << shift); }
private void copyTo(FractalTableImpl that) { int n = MathLib.min(this.data.length, that.data.length); offset &= (data.length << shift) - 1; // Makes it positive. int o = offset >> shift; if ((o + n) > data.length) { // Wrapping. int w = (o + n) - data.length; n -= w; System.arraycopy(data, 0, that.data, n, w); } System.arraycopy(data, o, that.data, 0, n); that.offset = offset - (o << shift); }
@Override public boolean intersects(BitSetService that) { long[] thatBits = that.toLongArray(); int i = MathLib.min(this.bits.length, thatBits.length); while (--i >= 0) { if ((bits[i] & thatBits[i]) != 0) return true; } return false; }
/** * Set the {@link LocalContext local} concurrency. Concurrency is * hard limited by {@link #MAXIMUM_CONCURRENCY}. * * @param concurrency the new concurrency (<code>0</code> or negative * number to disable concurrency). */ public static void setConcurrency(int concurrency) { concurrency = MathLib.max(0, concurrency); concurrency = MathLib.min(((Integer) MAXIMUM_CONCURRENCY.get()).intValue(), concurrency); CONCURRENCY.set(new Integer(concurrency)); }
@Override public BitSetServiceImpl get(int fromIndex, int toIndex) { if (fromIndex < 0 || fromIndex > toIndex) throw new IndexOutOfBoundsException(); BitSetServiceImpl bitSet = new BitSetServiceImpl(); int length = MathLib.min(bits.length, (toIndex >>> 6) + 1); bitSet.bits = new long[length]; System.arraycopy(bits, 0, bitSet.bits, 0, length); bitSet.clear(0, fromIndex); bitSet.clear(toIndex, length << 6); return bitSet; }
@Override public void and(BitSetService that) { long[] thatBits = that.toLongArray(); int n = MathLib.min(this.bits.length, thatBits.length); for (int i = 0; i < n; i++) { this.bits[i] &= thatBits[i]; } for (int i = n; i < bits.length; i++) { this.bits[i] = 0L; } trim(); }
@Override public void andNot(BitSetService that) { long[] thatBits = that.toLongArray(); int n = MathLib.min(this.bits.length, thatBits.length); for (int i = 0; i < n; i++) { this.bits[i] &= ~thatBits[i]; } trim(); }
/** * Returns the trace of this matrix. * * @return the sum of the diagonal elements. */ public F trace() { F sum = this.get(0, 0); for (int i = MathLib.min(getNumberOfColumns(), getNumberOfRows()); --i > 0;) { sum = sum.plus(get(i, i)); } return sum; }
@Override public DenseVector<F> getDiagonal() { int m = this.getNumberOfRows(); int n = this.getNumberOfColumns(); int dimension = MathLib.min(m, n); DenseVector<F> V = DenseVector.newInstance(); for (int i = 0; i < dimension; i++) { V._elements.add(this.get(i, i)); } return V; }
@Override public ComplexVector getDiagonal() { int m = this.getNumberOfRows(); int n = this.getNumberOfColumns(); int dimension = MathLib.min(m, n); ComplexVector V = ComplexVector.newInstance(dimension); for (int i = 0; i < dimension; i++) { V.set(i, this.get(i, i)); } return V; }
@Override public Float64Vector getDiagonal() { int m = this.getNumberOfRows(); int n = this.getNumberOfColumns(); int dimension = MathLib.min(m, n); Float64Vector V = Float64Vector.newInstance(dimension); for (int i = 0; i < dimension; i++) { V.set(i, this.get(i, i).doubleValue()); } return V; }