You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2019/12/01 11:08:10 UTC

[GitHub] [lucene-solr] rmuir commented on a change in pull request #1043: LUCENE-9071: Speed up BM25 scores.

rmuir commented on a change in pull request #1043: LUCENE-9071: Speed up BM25 scores.
URL: https://github.com/apache/lucene-solr/pull/1043#discussion_r352336609
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/util/MathUtil.java
 ##########
 @@ -165,4 +165,32 @@ public static double sumRelativeErrorBound(int numValues) {
     return (numValues - 1) * u;
   }
 
+  /**
+   * If this returns {@code true} then it means that the sum {@code x + y}
+   * doesn't need rounding to fit in a float. This method assumes two positive
+   * floats. No assumptions can be made if this method returns {@code false}.
+   */
+  public static boolean isSumAccurate(float x, float y) {
+    assert x >= 0;
+    assert y >= 0;
+    int xBits = Float.floatToRawIntBits(x);
+    int yBits = Float.floatToRawIntBits(y);
+    int minBits = Math.min(xBits, yBits);
+    int maxBits = Math.max(xBits, yBits);
+    int maxBiasedExp = maxBits >>> 23;
+    int minBiasedExp = minBits >>> 23;
+    // The result of the sum will have an exponent that is equal to the
+    // exponent of the maximum value, or the exponent of the maximum value plus
+    // one. So if we can do a lossless conversion of both numbers to a float
+    // that has the maximum exponent plus one as an exponent, then the sum is
+    // accurate.
+    int expDelta = maxBiasedExp - minBiasedExp;
+    final boolean accurate = (maxBits & 0x01) == 0 &&
+        // beware of overflows, a biased exponent of 254 is the greatest exponent that is not Infinity or NaN
+        maxBiasedExp < 254 &&
+        expDelta <= 22 &&
+        Integer.numberOfTrailingZeros(minBits) > expDelta;
+    return accurate;
+  }
 
 Review comment:
   i have a tough time believing its worth it to do all this stuff to save a cast to float. Are you sure benchmarks are working correctly? I think we should also consider complexity as well...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org