/** * Returns a new IntColumn containing a value for each value in this column, truncating if necessary. * * A narrowing primitive conversion such as this one may lose information about the overall magnitude of a * numeric value and may also lose precision and range. Specifically, if the value is too small (a negative value * of large magnitude or negative infinity), the result is the smallest representable value of type int. * * Similarly, if the value is too large (a positive value of large magnitude or positive infinity), the result is the * largest representable value of type int. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public IntColumn asIntColumn() { IntArrayList values = new IntArrayList(); for (double d : data) { values.add((int) d); } values.trim(); return IntColumn.create(this.name(), values.elements()); }
/** * Returns a new IntColumn containing a value for each value in this column, truncating if necessary. * * A narrowing primitive conversion such as this one may lose information about the overall magnitude of a * numeric value and may also lose precision and range. Specifically, if the value is too small (a negative value * of large magnitude or negative infinity), the result is the smallest representable value of type int. * * Similarly, if the value is too large (a positive value of large magnitude or positive infinity), the result is the * largest representable value of type int. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public IntColumn asIntColumn() { IntArrayList values = new IntArrayList(); for (float d : data) { values.add((int) d); } values.trim(); return IntColumn.create(this.name(), values.elements()); }
/** * Returns a new IntColumn containing a value for each value in this column * * A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, * where n is the number of bits used to represent type T. In addition to a possible loss of information about * the magnitude of the numeric value, this may cause the sign of the resulting value to differ from the sign of * the input value. * * In other words, if the element being converted is larger (or smaller) than Integer.MAX_VALUE * (or Integer.MIN_VALUE) you will not get a conventionally good conversion. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public IntColumn asIntColumn() { IntArrayList values = new IntArrayList(); for (long f : data) { values.add((int) f); } values.trim(); return IntColumn.create(this.name(), values.elements()); }
@Override public PackIndex build() { Map<Object, IntList> map = index.entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> { e.getValue().trim(); return e.getValue(); })); index.clear(); return new PackIndex(map); } }
@Override @Nonnull public List<Collection<RatingMatrixEntry>> get() { int nusers = data.getUserIndex().size(); ArrayList<IntArrayList> userLists = new ArrayList<>(nusers); for (int i = 0; i < nusers; i++) { userLists.add(new IntArrayList()); } for (RatingMatrixEntry pref : getRatings()) { final int uidx = pref.getUserIndex(); final int idx = pref.getIndex(); userLists.get(uidx).add(idx); } ArrayList<Collection<RatingMatrixEntry>> users = new ArrayList<>(nusers); for (IntArrayList list: userLists) { list.trim(); users.add(new PackedRatingCollection(data, list)); } return users; } }
@Override public PackIndex build() { Long2ObjectMap<IntList> map = new Long2ObjectOpenHashMap<>(); for (Long2ObjectMap.Entry<IntArrayList> e: index.long2ObjectEntrySet()) { e.getValue().trim(); map.put(e.getLongKey(), e.getValue()); } index.clear(); return new PackIndex(map); } }
/** * Trims this array list so that the capacity is equal to the size. * * @see java.util.ArrayList#trimToSize() */ public void trim() { trim(0); } /**
@Override public void trim() { neighbors.trim(); } }
public void trim() { if (fullImpl != null) { boolean compactable = true; for (LongIterator iter = fullImpl.iterator(); compactable && iter.hasNext();) { final long value = iter.nextLong(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { compactable = false; } } if (compactable) { compactImpl = new IntArrayList(fullImpl.size()); for (LongIterator iter = fullImpl.iterator(); iter.hasNext();) { final long value = iter.nextLong(); compactImpl.add((int) value); } fullImpl = null; } else { fullImpl.trim(); } } else { assert compactImpl != null; compactImpl.trim(); } }
@Override public PackIndex build() { Map<Object, IntList> map = index.entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> { e.getValue().trim(); return e.getValue(); })); index.clear(); return new PackIndex(map); } }
@Override public void seal() { ((IntArrayList) _innerList).trim(); _elements = ((IntArrayList) _innerList).elements(); int negativeIndexCheck = withDummy ? 1 : 0; // reverse negative elements, because string order and numeric orders are completely opposite if (_elements.length > negativeIndexCheck && _elements[negativeIndexCheck] < 0) { int endPosition = indexOfWithType(0); if (endPosition < 0) { endPosition = -1 * endPosition - 1; } int tmp; for (int i = 0; i < (endPosition - negativeIndexCheck) / 2; i++) { tmp = _elements[i + negativeIndexCheck]; _elements[i + negativeIndexCheck] = _elements[endPosition - i - 1]; _elements[endPosition - i - 1] = tmp; } } }
/** * Pours an iterator, returning a type-specific list, with a limit on the number * of elements. * * <p> * This method iterates over the given type-specific iterator and returns a * type-specific list containing the returned elements (up to {@code max}). * Iteration on the returned list is guaranteed to produce the elements in the * same order in which they appeared in the iterator. * * * @param i * a type-specific iterator. * @param max * the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to * {@code max}. */ public static IntList pour(final IntIterator i, int max) { final IntArrayList l = new IntArrayList(); pour(i, l, max); l.trim(); return l; } /**
@Override @Nonnull public List<Collection<RatingMatrixEntry>> get() { int nusers = data.getUserIndex().size(); ArrayList<IntArrayList> userLists = new ArrayList<>(nusers); for (int i = 0; i < nusers; i++) { userLists.add(new IntArrayList()); } for (RatingMatrixEntry pref : getRatings()) { final int uidx = pref.getUserIndex(); final int idx = pref.getIndex(); userLists.get(uidx).add(idx); } ArrayList<Collection<RatingMatrixEntry>> users = new ArrayList<>(nusers); for (IntArrayList list: userLists) { list.trim(); users.add(new PackedRatingCollection(data, list)); } return users; } }
/** * Returns a new IntColumn containing a value for each value in this column, truncating if necessary. * * A narrowing primitive conversion such as this one may lose information about the overall magnitude of a * numeric value and may also lose precision and range. Specifically, if the value is too small (a negative value * of large magnitude or negative infinity), the result is the smallest representable value of type int. * * Similarly, if the value is too large (a positive value of large magnitude or positive infinity), the result is the * largest representable value of type int. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public IntColumn asIntColumn() { IntArrayList values = new IntArrayList(); for (double d : data) { values.add((int) d); } values.trim(); return IntColumn.create(this.name(), values.elements()); }
/** * Returns a new IntColumn containing a value for each value in this column, truncating if necessary. * * A narrowing primitive conversion such as this one may lose information about the overall magnitude of a * numeric value and may also lose precision and range. Specifically, if the value is too small (a negative value * of large magnitude or negative infinity), the result is the smallest representable value of type int. * * Similarly, if the value is too large (a positive value of large magnitude or positive infinity), the result is the * largest representable value of type int. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public IntColumn asIntColumn() { IntArrayList values = new IntArrayList(); for (float d : data) { values.add((int) d); } values.trim(); return IntColumn.create(this.name(), values.elements()); }
@Override public PackIndex build() { Long2ObjectMap<IntList> map = new Long2ObjectOpenHashMap<>(); for (Long2ObjectMap.Entry<IntArrayList> e: index.long2ObjectEntrySet()) { e.getValue().trim(); map.put(e.getLongKey(), e.getValue()); } index.clear(); return new PackIndex(map); } }
public void trim() { if (fullImpl != null) { boolean compactable = true; for (LongIterator iter = fullImpl.iterator(); compactable && iter.hasNext();) { final long value = iter.nextLong(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { compactable = false; } } if (compactable) { compactImpl = new IntArrayList(fullImpl.size()); for (LongIterator iter = fullImpl.iterator(); iter.hasNext();) { final long value = iter.nextLong(); compactImpl.add((int) value); } fullImpl = null; } else { fullImpl.trim(); } } else { assert compactImpl != null; compactImpl.trim(); } }
public ScorerContext context( List<String> words ) { Multiset<String> counter = TreeMultiset.create(); counter.addAll( words ); int word_dim = word_model.dimensions(); float[] word_vecs = new float[ counter.size() * word_dim ]; IntArrayList word_counts = new IntArrayList(); int n_words = 0; for( Multiset.Entry<String> entry : counter.entrySet() ) { if( word_model.get( entry.getElement(), word_vecs, n_words * word_dim ) ) { word_counts.add( entry.getCount() ); n_words += 1; } } word_counts.trim(); return create_context( word_vecs, word_counts.elements() ); }
public void trim() { if (fullImpl != null) { boolean compactable = true; for (LongIterator iter = fullImpl.iterator(); compactable && iter.hasNext();) { final long value = iter.nextLong(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { compactable = false; } } if (compactable) { compactImpl = new IntArrayList(fullImpl.size()); for (LongIterator iter = fullImpl.iterator(); iter.hasNext();) { final long value = iter.nextLong(); compactImpl.add((int) value); } fullImpl = null; } else { fullImpl.trim(); } } else { assert compactImpl != null; compactImpl.trim(); } }
public ScorerContext context(List<String> words) { Multiset<String> counter = TreeMultiset.create(); counter.addAll(words); int word_dim = kb.getEmbeddingsSize(); // word_vecs is the concatenation of all word vectors of the word list float[] word_vecs = new float[counter.size() * word_dim]; IntArrayList word_counts = new IntArrayList(); int n_words = 0; for(Multiset.Entry<String> entry : counter.entrySet()) { short[] vector = kb.getWordEmbeddings(entry.getElement()); if (vector != null) { word_counts.add(entry.getCount()); for (int i=0; i<kb.getEmbeddingsSize(); i++) { word_vecs[n_words * word_dim + i] = vector[i]; } n_words += 1; } } word_counts.trim(); return create_context(word_vecs, word_counts.elements()); }