public void testModByZero() { for (long a : TEST_LONGS) { try { UnsignedLong.fromLongBits(a).mod(UnsignedLong.ZERO); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } } }
public void testMod() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { if (b != 0) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned.bigIntegerValue().remainder(bUnsigned.bigIntegerValue()).longValue(); UnsignedLong unsignedRem = aUnsigned.mod(bUnsigned); assertEquals(expected, unsignedRem.longValue()); } } } }
/** * Returns the remainder of dividing this by {@code val}. * * @deprecated Use {@link #mod(UnsignedLong)}. This method is scheduled to be removed in Guava * release 15.0. */ @Deprecated @Beta public UnsignedLong remainder(UnsignedLong val) { return mod(val); }
static <E> List<E> selectValues(List<E> values, java.util.function.Predicate<E> valueFilter, Double split, boolean left){ UnsignedLong bits = toUnsignedLong(split.doubleValue()); List<E> result = new ArrayList<>(); for(int i = 0; i < values.size(); i++){ E value = values.get(i); boolean append; // Send "true" categories to the left if(left){ // Test if the least significant bit (LSB) is 1 append = (bits.mod(RandomForestConverter.TWO)).equals(UnsignedLong.ONE); } else // Send all other categories to the right { // Test if the LSB is 0 append = (bits.mod(RandomForestConverter.TWO)).equals(UnsignedLong.ZERO); } // End if if(append && valueFilter.test(value)){ result.add(value); } bits = bits.dividedBy(RandomForestConverter.TWO); } return result; }
protected void computeSubwords(String word, List<Integer> ngrams, List<String> substrings) { for(int i = 0; i < word.length(); i++) { StringBuilder ngram = new StringBuilder(); if (!charMatches(word.charAt(i))) { for (int j = i, n = 1; j < word.length() && n <= args.getMaxn(); n++) { ngram.append(word.charAt(j++)); while (j < word.length() && charMatches(word.charAt(j))) { ngram.append(word.charAt(j++)); } if (n >= args.getMinn() && !(n == 1 && (i == 0 || j == word.length()))) { UnsignedLong h = UnsignedLong.valueOf(hash(ngram.toString())); h = h.mod(UnsignedLong.valueOf(args.getBucketNumber())); ngrams.add(nWords + h.intValue()); substrings.add(ngram.toString()); } } } } }
protected void computeSubwords(String word, List<Integer> ngrams) { for(int i = 0; i < word.length(); i++) { StringBuilder ngram = new StringBuilder(); if (!charMatches(word.charAt(i))) { for (int j = i, n = 1; j < word.length() && n <= args.getMaxn(); n++) { ngram.append(word.charAt(j++)); while (j < word.length() && charMatches(word.charAt(j))) { ngram.append(word.charAt(j++)); } if (n >= args.getMinn() && !(n == 1 && (i == 0 || j == word.length()))) { UnsignedLong h = UnsignedLong.valueOf(hash(ngram.toString())); h = h.mod(UnsignedLong.valueOf(args.getBucketNumber())); pushHash(ngrams, h.intValue()); } } } } }
public void testModByZero() { for (long a : TEST_LONGS) { try { UnsignedLong.fromLongBits(a).mod(UnsignedLong.ZERO); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) {} } }
protected void addWordNGrams(List<Integer> line, List<Long> hashes, int n) { if (pruneIdxSize == 0) { return; } for (int i = 0; i < hashes.size(); i++) { UnsignedLong h = toUnsignedLong64(hashes.get(i)); for (int j = i + 1; j < hashes.size() && j < i + n; j++) { long h2 = (long) hashes.get(j).intValue(); long coeff = 116049371L; if (h2 >= 0) { h = h.times(UnsignedLong.valueOf(coeff)).plus(UnsignedLong.valueOf(h2)); } else { h = h.times(UnsignedLong.valueOf(coeff)).minus(UnsignedLong.valueOf(-h2)); } int id = h.mod(UnsignedLong.valueOf(args.getBucketNumber())).intValue(); if (pruneIdxSize > 0) { int pruneId = getPruning(id); if (pruneId >= 0) { id = pruneId; } else { continue; } } line.add(nWords + id); } } }
public void testMod() { for (long a : TEST_LONGS) { for (long b : TEST_LONGS) { if (b != 0) { UnsignedLong aUnsigned = UnsignedLong.fromLongBits(a); UnsignedLong bUnsigned = UnsignedLong.fromLongBits(b); long expected = aUnsigned .bigIntegerValue() .remainder(bUnsigned.bigIntegerValue()) .longValue(); UnsignedLong unsignedRem = aUnsigned.mod(bUnsigned); assertEquals(expected, unsignedRem.longValue()); } } } }