Java Code Examples for com.google.common.base.Preconditions#checkPositionIndex()
The following examples show how to use
com.google.common.base.Preconditions#checkPositionIndex() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: fastText4j File: Matrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public float dotRow(final Vector vec, int i) { Preconditions.checkPositionIndex(i, m); Preconditions.checkArgument(vec.size() == n); float d = 0.0f; for (int j = 0; j < n; j++) { d += data[i * n + j] * vec.at(j); } if (Float.isNaN(d)) { throw new IllegalStateException("Encountered NaN."); } return d; }
Example 2
Source Project: fastText4j File: Matrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addRow(final Vector vec, int i, float a) { Preconditions.checkPositionIndex(i, m); Preconditions.checkArgument(vec.size() == n); for (int j = 0; j < n; j++) { data[i * n + j] += a * vec.at(j); } }
Example 3
Source Project: fastText4j File: Matrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void multiplyRow(final Vector nums, int ib, int ie) { if (ie == -1) { ie = m; } Preconditions.checkPositionIndex(ie, nums.size()); for (int i = ib; i < ie; i++) { float num = nums.at(i - ib); if (n != 0) { for (int j = 0; j < this.n; j++) { data[i * n + j] *= num; } } } }
Example 4
Source Project: fastText4j File: Matrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void divideRow(final Vector denoms, int ib, int ie) { if (ie == -1) { ie = m; } Preconditions.checkPositionIndex(ie, denoms.size()); for (int i = ib; i < ie; i++) { float denom = denoms.at(i - ib); if (denom != 0) { for (int j = 0; j < this.n; j++) { data[i * n + j] /= denom; } } } }
Example 5
Source Project: fastText4j File: Vector.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addRow(ReadableMatrix A, int i, float a) { Preconditions.checkPositionIndex(i, A.m()); Preconditions.checkArgument(m == A.n()); for (int j = 0; j < A.n(); j++) { data[j] += a * A.at(i, j); } }
Example 6
Source Project: fastText4j File: QMatrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public float dotRow(Vector vec, int i) { Preconditions.checkPositionIndex(i, m); Preconditions.checkArgument(vec.size() == n); float norm = 1f; if (qnorm) { int cPosition = npq.getCentroidsPosition(0, normCodes.get(i)); norm = npq.getCentroid(cPosition); } return pq.mulCode(vec, codes, i, norm); }
Example 7
Source Project: fastText4j File: MMapMatrix.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public float dotRow(final Vector vec, int i) { Preconditions.checkPositionIndex(i, m); Preconditions.checkArgument(vec.size() == n); float d = 0.0f; float[] r = atRow(i); for (int j = 0; j < n; j++) { d += r[j] * vec.at(j); } return d; }
Example 8
Source Project: Bats File: ImmutableIntList.java License: Apache License 2.0 | 4 votes |
protected AbstractIndexedListIterator(int size, int position) { Preconditions.checkPositionIndex(position, size); this.size = size; this.position = position; }
Example 9
Source Project: fastText4j File: Dictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public EntryType getType(int id) { Preconditions.checkPositionIndex(id, size); return words[id].type; }
Example 10
Source Project: fastText4j File: Dictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public long getCount(int id) { Preconditions.checkPositionIndex(id, size); return words[id].count; }
Example 11
Source Project: Cleanstone File: PropertyInteger.java License: MIT License | 4 votes |
@Override public Integer deserialize(int serializedValue) { Preconditions.checkPositionIndex(0, totalValuesAmount - 1); return serializedValue + minValue; }
Example 12
Source Project: fastText4j File: Vector.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public void addAt(int i, float v) { Preconditions.checkPositionIndex(i, m); data[i] += v; }
Example 13
Source Project: Cleanstone File: PropertyInteger.java License: MIT License | 4 votes |
@Override public int serialize(Integer value) { Preconditions.checkPositionIndex(minValue, maxValue); return value - minValue; }
Example 14
Source Project: fastText4j File: QCodeArray.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public int get(int i) { Preconditions.checkPositionIndex(i, codes.length); return codes[i]; }
Example 15
Source Project: fastText4j File: MMapDictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public long getCount(int id) { Preconditions.checkPositionIndex(id, size); position(entryFieldPosition(id, countOffset())); return readCount(); }
Example 16
Source Project: fastText4j File: Dictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Entry getEntry(int id) { Preconditions.checkPositionIndex(id, size); return words[id]; }
Example 17
Source Project: fastText4j File: MMapDictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public EntryType getType(int id) { Preconditions.checkPositionIndex(id, size); position(entryFieldPosition(id, typeOffset())); return readType(); }
Example 18
Source Project: fastText4j File: MMapDictionary.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public String getWord(int id) { Preconditions.checkPositionIndex(id, nWords); position(entryPosition(id)); return readWord(); }
Example 19
Source Project: javaide File: ReadOnlyDocument.java License: GNU General Public License v3.0 | 2 votes |
/** * Finds the given text in the document, starting from the given offset. * * @param needle the text to find. * @param offset the starting point of the search. * @return the offset of the found result, or -1 if no match was found. */ int findText(@NonNull String needle, int offset) { Preconditions.checkPositionIndex(offset, mFileContents.length()); return mFileContents.indexOf(needle, offset); }
Example 20
Source Project: hadoop File: AclFeature.java License: Apache License 2.0 | 2 votes |
/** * Get the entry at the specified position * @param pos Position of the entry to be obtained * @return integer representation of AclEntry * @throws IndexOutOfBoundsException if pos out of bound */ int getEntryAt(int pos) { Preconditions.checkPositionIndex(pos, entries.length, "Invalid position for AclEntry"); return entries[pos]; }