List of usage examples for java.util Arrays fill
public static void fill(Object[] a, int fromIndex, int toIndex, Object val)
From source file:hivemall.io.DenseModel.java
private void ensureCapacity(final int index) { if (index >= size) { int bits = MathUtils.bitsRequired(index); int newSize = (1 << bits) + 1; int oldSize = size; logger.info("Expands internal array size from " + oldSize + " to " + newSize + " (" + bits + " bits)"); this.size = newSize; this.weights = Arrays.copyOf(weights, newSize); if (covars != null) { this.covars = Arrays.copyOf(covars, newSize); Arrays.fill(covars, oldSize, newSize, 1.f); }/*from w w w . j av a 2 s . co m*/ if (sum_of_squared_gradients != null) { this.sum_of_squared_gradients = Arrays.copyOf(sum_of_squared_gradients, newSize); } if (sum_of_squared_delta_x != null) { this.sum_of_squared_delta_x = Arrays.copyOf(sum_of_squared_delta_x, newSize); } if (sum_of_gradients != null) { this.sum_of_gradients = Arrays.copyOf(sum_of_gradients, newSize); } if (clocks != null) { this.clocks = Arrays.copyOf(clocks, newSize); this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize); } } }
From source file:com.cate.javatransmitter.FileHandler.java
public int[] nextIntChunk() { // Read the bytes with the proper encoding for this platform. If // you skip this step, you might see something that looks like // Chinese characters when you expect Latin-style characters. //String encoding = System.getProperty("file.encoding"); byte[] nByteC = this.nextChunk(); Arrays.fill(nIntC, nByteC.length, 256, 0); for (int i = 0; i < nByteC.length; i++) nIntC[i] = (int) nByteC[i] & 0xFF; return (nIntC); }
From source file:edu.harvard.med.screensaver.ui.arch.util.converter.EmptyWellsConverter.java
private Set<Integer> getFullRows(Set<WellName> wellNames) { int[] rowCounts = new int[ScreensaverConstants.DEFAULT_PLATE_SIZE.getRows()]; Arrays.fill(rowCounts, 0, rowCounts.length, 0); for (WellName wellName : wellNames) { rowCounts[wellName.getRowIndex()]++; }/* w w w. j a v a 2 s. c o m*/ SortedSet<Integer> fullRowIndexes = Sets.newTreeSet(); for (int rowIndex = 0; rowIndex < rowCounts.length; ++rowIndex) { if (rowCounts[rowIndex] == ScreensaverConstants.DEFAULT_PLATE_SIZE.getColumns()) { fullRowIndexes.add(rowIndex); } } return fullRowIndexes; }
From source file:cc.recommenders.mining.calls.NetworkMathUtils.java
public static double[] createPriorProbabilitiesForContextNodeAssumingDummyStateAtFirstIndex(final int length) { final double[] res = new double[length]; Arrays.fill(res, 1, res.length, P_MIN); final double sum = StatUtils.sum(res); res[0] = 1 - sum;/*from w ww. j a va 2 s. c o m*/ return res; }
From source file:com.google.uzaygezen.core.LongArrayBitVector.java
@Override public void set(int fromIndex, int toIndex) { checkRange(0, size, fromIndex, toIndex); int fromBucket = fromIndex / WORD; int toBucket = toIndex / WORD; if (fromBucket == toBucket) { if (fromBucket != data.length) { data[fromBucket] |= (1L << toIndex) - (1L << fromIndex); } else {//w w w . j a v a 2s .com assert fromIndex == toIndex; assert toIndex == size; } } else { data[fromBucket] |= -(1L << fromIndex); if (toBucket != data.length) { data[toBucket] |= (1L << toIndex) - 1L; } else { assert toIndex == size; } Arrays.fill(data, fromBucket + 1, toBucket, -1L); } assert checkSanity(); }
From source file:Main.java
/** * Ensures the given array has a given size. * @param array the array.//from w ww . j av a2 s . co m * @param size the target size of the array. * @param initialValue the initial value of the elements. * @return the original array, or a copy if it had to be * extended. */ public static Object[] ensureArraySize(Object[] array, int size, Object initialValue) { // Is the existing array large enough? if (array.length >= size) { // Reinitialize the existing array. Arrays.fill(array, 0, size, initialValue); } else { // Otherwise create and initialize a new array. array = (Object[]) Array.newInstance(array.getClass().getComponentType(), size); if (initialValue != null) { Arrays.fill(array, 0, size, initialValue); } } return array; }
From source file:hivemall.io.SpaceEfficientDenseModel.java
private void ensureCapacity(final int index) { if (index >= size) { int bits = MathUtils.bitsRequired(index); int newSize = (1 << bits) + 1; int oldSize = size; logger.info("Expands internal array size from " + oldSize + " to " + newSize + " (" + bits + " bits)"); this.size = newSize; this.weights = Arrays.copyOf(weights, newSize); if (covars != null) { this.covars = Arrays.copyOf(covars, newSize); Arrays.fill(covars, oldSize, newSize, HalfFloat.ONE); }/*from ww w . j ava 2 s.c o m*/ if (sum_of_squared_gradients != null) { this.sum_of_squared_gradients = Arrays.copyOf(sum_of_squared_gradients, newSize); } if (sum_of_squared_delta_x != null) { this.sum_of_squared_delta_x = Arrays.copyOf(sum_of_squared_delta_x, newSize); } if (sum_of_gradients != null) { this.sum_of_gradients = Arrays.copyOf(sum_of_gradients, newSize); } if (clocks != null) { this.clocks = Arrays.copyOf(clocks, newSize); this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize); } } }
From source file:com.graphhopper.apache.commons.collections.IntDoubleBinaryHeap.java
void trimTo(int toSize) { this.size = toSize; toSize++;/* ww w .ja v a 2s . co m*/ // necessary as we currently do not init arrays when inserting Arrays.fill(elements, toSize, size + 1, 0); }
From source file:edu.harvard.med.screensaver.ui.arch.util.converter.EmptyWellsConverter.java
private SortedSet<Integer> getFullColumns(Set<WellName> wellNames) { int[] columnCounts = new int[ScreensaverConstants.DEFAULT_PLATE_SIZE.getColumns()]; Arrays.fill(columnCounts, 0, columnCounts.length, 0); for (WellName wellName : wellNames) { columnCounts[wellName.getColumnIndex()]++; }/* w w w . j av a 2s . c o m*/ SortedSet<Integer> fullColumnIndexes = Sets.newTreeSet(); for (int colIndex = 0; colIndex < columnCounts.length; ++colIndex) { if (columnCounts[colIndex] == ScreensaverConstants.DEFAULT_PLATE_SIZE.getRows()) { fullColumnIndexes.add(colIndex); } } return fullColumnIndexes; }
From source file:edu.uci.ics.hivesterix.serde.lazy.LazyMap.java
/** * Parse the byte[] and fill keyStart, keyLength, keyIsNull valueStart, * valueLength and valueIsNull.// ww w .ja v a 2 s. c o m */ private void parse() { // get the VInt that represents the map size LazyUtils.readVInt(bytes, start, vInt); mapSize = vInt.value; if (0 == mapSize) { parsed = true; return; } // adjust arrays adjustArraySize(mapSize); // find out the null-bytes int mapByteStart = start + vInt.length; int nullByteCur = mapByteStart; int nullByteEnd = mapByteStart + (mapSize * 2 + 7) / 8; int lastElementByteEnd = nullByteEnd; // parsing the keys and values one by one for (int i = 0; i < mapSize; i++) { // parse a key keyIsNull[i] = true; if ((bytes[nullByteCur] & (1 << ((i * 2) % 8))) != 0) { keyIsNull[i] = false; LazyUtils.checkObjectByteInfo(((MapObjectInspector) oi).getMapKeyObjectInspector(), bytes, lastElementByteEnd, recordInfo); keyStart[i] = lastElementByteEnd + recordInfo.elementOffset; keyLength[i] = recordInfo.elementSize; lastElementByteEnd = keyStart[i] + keyLength[i]; } else if (!nullMapKey) { nullMapKey = true; LOG.warn("Null map key encountered! Ignoring similar problems."); } // parse a value valueIsNull[i] = true; if ((bytes[nullByteCur] & (1 << ((i * 2 + 1) % 8))) != 0) { valueIsNull[i] = false; LazyUtils.checkObjectByteInfo(((MapObjectInspector) oi).getMapValueObjectInspector(), bytes, lastElementByteEnd, recordInfo); valueStart[i] = lastElementByteEnd + recordInfo.elementOffset; valueLength[i] = recordInfo.elementSize; lastElementByteEnd = valueStart[i] + valueLength[i]; } // move onto the next null byte if (3 == (i % 4)) { nullByteCur++; } } Arrays.fill(keyInited, 0, mapSize, false); Arrays.fill(valueInited, 0, mapSize, false); parsed = true; }