From 976efe0e08824f71108e7f2f0e62d473851d7dde Mon Sep 17 00:00:00 2001 From: Paul Koch Date: Wed, 15 Jan 2025 01:50:48 -0800 Subject: [PATCH] disable non-IEEE 754 math --- build.sh | 2 +- python/interpret-core/tests/glassbox/ebm/test_ebm.py | 5 +---- shared/libebm/interpretable_numerics.cpp | 6 +++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index dc43b8646..36989946f 100644 --- a/build.sh +++ b/build.sh @@ -413,7 +413,7 @@ all_args="$all_args -Wformat=2" all_args="$all_args -Wno-format-nonliteral" all_args="$all_args -Wno-parentheses" all_args="$all_args -fvisibility=hidden -fvisibility-inlines-hidden" -all_args="$all_args -fno-math-errno -fno-trapping-math" +all_args="$all_args -fno-math-errno -fno-trapping-math -fno-fast-math -ffp-contract=off" # TODO: once we have highly efficient tightly looped code, try no -fpic and see if that makes better code. The compiler can save a register in this case. See https://akkadia.org/drepper/dsohowto.pdf # TODO: check no-plt compiler option all_args="$all_args -fpic" diff --git a/python/interpret-core/tests/glassbox/ebm/test_ebm.py b/python/interpret-core/tests/glassbox/ebm/test_ebm.py index f746563a0..af9f77f82 100644 --- a/python/interpret-core/tests/glassbox/ebm/test_ebm.py +++ b/python/interpret-core/tests/glassbox/ebm/test_ebm.py @@ -1245,9 +1245,6 @@ def test_replicatability_classification(): break -@pytest.mark.skip( - reason="Fails on mac. Need to work on getting cross platform identical results." -) def test_identical_classification(): from interpret.develop import get_option, set_option @@ -1271,7 +1268,7 @@ def test_identical_classification(): pred = ebm.eval_terms(X) total += np.sum(pred) - expected = 2.220446049250313e-15 + expected = -3.941291737419306e-15 if total != expected: assert total == expected break diff --git a/shared/libebm/interpretable_numerics.cpp b/shared/libebm/interpretable_numerics.cpp index 947a0ad5e..29383a480 100644 --- a/shared/libebm/interpretable_numerics.cpp +++ b/shared/libebm/interpretable_numerics.cpp @@ -1379,6 +1379,9 @@ static double Mean(const size_t cSamples, // https://stackoverflow.com/questions/895929/how-do-i-determine-the-standard-deviation-stddev-of-a-set-of-values // https://www.johndcook.com/blog/standard_deviation/ + // do not put multiple floating point operations in the same statement since that can be optimized + // https://clang.llvm.org/docs/UsersManual.html + double factor = 1.0; double mean; size_t cNaN; @@ -1440,7 +1443,8 @@ static double Mean(const size_t cSamples, // if all the weights are zero, then weigh them all equally ratio = double{1} / static_cast(cNormal); } - mean += numerator * ratio; + const double multiple = numerator * ratio; + mean += multiple; } if(nullptr != pWeight) { ++pWeight;