stefanvodita commented on PR #12966:
URL: https://github.com/apache/lucene/pull/12966#issuecomment-1890420916

   I found a fun HeisenBug in one of the tests. When we iterate cursors from 
`IntFloatHashMap`, the order is not deterministic. Float summation is not 
commutative, so the result we get by aggregating the floats in the map can be 
different depending on the order in which we perform the iteration. For a 
particular seed, running the test was producing an ordering that was not 
favorable, while running the debugger produced an ordering that was. The test 
is fixed in the latest commit and I've opened an [issue to do Kahan 
summation](https://github.com/apache/lucene/issues/13011) over the floats 
instead, to reduce the error we're seeing.
   
   For those who want to follow along, here are the exact numbers we are adding 
in the test in two orderings which produce different results:
   ```
   class FloatSunIsNotCommutative {
       public static void main(String[] args) {
           float x = 177182.61f;
           float y = 238089.27f;
           float z = 255214.66f;
           float acc;
           
           acc = 0;
           acc += x;
           acc += y;
           acc += z;
           System.out.println(acc);
           
           acc = 0;
           acc += z;
           acc += y;
           acc += x;
           System.out.println(acc);
       }
   }
   ```


-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to