List of usage examples for java.util Arrays fill
public static void fill(Object[] a, int fromIndex, int toIndex, Object val)
From source file:com.eryansky.common.utils.SysUtils.java
public static String rightPad(String text, int length, byte c) { if (null == text) text = ""; byte[] array = new byte[length]; byte[] reference = text.getBytes(); Arrays.fill(array, reference.length, length, c); System.arraycopy(reference, 0, array, 0, reference.length); return new String(array); }
From source file:Main.java
/** * Ensures the given array has a given size. * @param array the array./*from ww w .j a v 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 int[] ensureArraySize(int[] array, int size, int 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 = new int[size]; if (initialValue != 0) { Arrays.fill(array, 0, size, initialValue); } } return array; }
From source file:hivemall.common.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); }// www. java 2s. c om } }
From source file:hivemall.model.NewDenseModel.java
private void ensureCapacity(final int index) { if (index >= size) { int bits = MathUtils.bitsRequired(index); int newSize = (1 << bits) + 1; int oldSize = size; if (logger.isInfoEnabled()) { logger.info(/* w w w. j a va2s. co m*/ "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); } if (clocks != null) { this.clocks = Arrays.copyOf(clocks, newSize); this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize); } } }
From source file:com.eryansky.common.utils.SysUtils.java
/** * /*from ww w .j a va2 s . com*/ * * @param o * @param length * @return * @throws Exception */ public static String decimalPad(Integer o, int length) { if (null == o) return rightPad("", length, (byte) ' '); byte[] array = new byte[length]; Arrays.fill(array, 0, length, (byte) '0'); return new DecimalFormat(new String(array)).format(o); }
From source file:edu.oregonstate.eecs.mcplan.ml.KulisLowRankKernelLearner.java
public KulisLowRankKernelLearner(final ArrayList<RealVector> X, final ArrayList<int[]> S, final ArrayList<int[]> D, final double u, final double ell, final RealMatrix A0, final double gamma, final RandomGenerator rng) { X_ = X;/*from w w w . java 2 s . com*/ S_ = S; D_ = D; u_ = u; ell_ = ell; A0_ = A0; // FIXME: For testing only! r_ = 2; G0_ = MatrixUtils.createRealIdentityMatrix(X.size()); gamma_ = gamma; rng_ = rng; Nc_ = S_.size() + D_.size(); xi_ = new double[Nc_]; Arrays.fill(xi_, 0, S_.size(), u_); Arrays.fill(xi_, S_.size(), Nc_, ell_); lambda_ = new double[Nc_]; }
From source file:edu.oregonstate.eecs.mcplan.ml.InformationTheoreticMetricLearner.java
/** * @param S A list of differences between Similar pairs of points. * @param D A list of differences between Disimilar pairs of points. * @param u The Upper bound on separation of similar instances. * @param ell The Lower bound on separation of disimilar instances. * @param A0 Initial metric//from ww w . j a v a 2 s . co m * @param gamma Relative weight of similarity constraints over log-det regularization * @param rng */ public InformationTheoreticMetricLearner(final ArrayList<double[]> S, final ArrayList<double[]> D, final double u, final double ell, final RealMatrix A0, final double gamma, final RandomGenerator rng) { // X_ = X; S_ = S; D_ = D; this.u = u; this.ell = ell; A0_ = A0; gamma_ = gamma; rng_ = rng; Nc_ = S_.size() + D_.size(); xi_ = new double[Nc_]; Arrays.fill(xi_, 0, S_.size(), u); Arrays.fill(xi_, S_.size(), Nc_, ell); lambda_ = new double[Nc_]; }
From source file:Main.java
/** * Ensures the given array has a given size. * @param array the array.// w ww. j a v a 2 s. c om * @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 long[] ensureArraySize(long[] array, int size, long 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 = new long[size]; if (initialValue != 0L) { Arrays.fill(array, 0, size, initialValue); } } return array; }
From source file:hivemall.model.NewSpaceEfficientDenseModel.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); }/* www . j a v a 2s. co m*/ if (clocks != null) { this.clocks = Arrays.copyOf(clocks, newSize); this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize); } } }
From source file:com.eryansky.common.utils.SysUtils.java
/** * ?//w ww . j av a 2 s . c om * * @param o * @param length * @param scale * @return * @throws Exception */ public static String decimalPad(Double o, int length, int scale) throws Exception { if (length < (2 + scale)) throw new Exception("?4!"); if (null == o) return rightPad("", length, (byte) ' '); byte[] array = new byte[length]; Arrays.fill(array, 0, length, (byte) '0'); array[length - (1 + scale)] = (byte) '.'; return new DecimalFormat(new String(array)).format(o); }