@Override public boolean isEmpty() { synchronized (sync) { return collection.isEmpty(); } } @Override
@Override public boolean isEmpty() { return collection.isEmpty(); } @Override
static public int argmax(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax(scores); float maxValue = -Float.MAX_VALUE; int maxIndex = -1; for (int i : labels) { if (maxValue < scores[i]) { maxIndex = i; maxValue = scores[i]; } } return maxIndex; }
static public int argmax(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax(scores); float maxValue = -Float.MAX_VALUE; int maxIndex = -1; for (int i : labels) { if (maxValue < scores[i]) { maxIndex = i; maxValue = scores[i]; } } return maxIndex; }
public void remove(T key, int value) { IntCollection collection = map.get(key); if (collection != null) { collection.rem(value); if (collection.isEmpty()) { map.remove(key); } } }
/** * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in * this range. */ public boolean containsAll(IntCollection values) { if (values.isEmpty()) { return true; } // this optimizes testing equality of two range-backed sets if (values instanceof IntSortedSet) { IntSortedSet set = (IntSortedSet) values; return contains(set.first()) && contains(set.last()); } for (int value : values) { if (!contains(value)) { return false; } } return true; }
static public int[] argmax2(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax2(scores); IntIterator it = labels.iterator(); if (labels.size() < 2) return new int[]{it.nextInt(),-1}; int[] max = {it.nextInt(), it.nextInt()}; if (scores[max[0]] < scores[max[1]]) DSUtils.swap(max, 0, 1); while (it.hasNext()) { int i = it.nextInt(); if (scores[max[0]] < scores[i]) { max[1] = max[0]; max[0] = i; } else if (scores[max[1]] < scores[i]) max[1] = i; } return max; } }
static public int[] argmax2(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax2(scores); IntIterator it = labels.iterator(); if (labels.size() < 2) return new int[]{it.nextInt(),-1}; int[] max = {it.nextInt(), it.nextInt()}; if (scores[max[0]] < scores[max[1]]) DSUtils.swap(max, 0, 1); while (it.hasNext()) { int i = it.nextInt(); if (scores[max[0]] < scores[i]) { max[1] = max[0]; max[0] = i; } else if (scores[max[1]] < scores[i]) max[1] = i; } return max; } }