refactor(phase2-3): numerical precision, C++20 idioms, static-analysis cleanup#17
Merged
refactor(phase2-3): numerical precision, C++20 idioms, static-analysis cleanup#17
Conversation
Phase 2.1 — student_t.cpp: - Replace std::log(1.0 + x²/ν) with std::log1p(x²/ν) in all 9 batch probability sites (6 parallel/GPU lambdas + 3 scalar fallback paths); avoids catastrophic cancellation when x²/ν ≈ 0 Phase 3.1 — stream operator prefix checks: - Replace find(...) != 0 / == 0 with std::string::starts_with() in operator>> for beta, chi_squared, discrete, exponential, gamma (×2), gaussian, poisson, student_t, uniform — C++20 idiomatic and intent-clearer Phase 3.2 — static-analysis sweep: - simd_policy.cpp: remove redundant = SIMDPolicy::Level::None initializer (every branch including the final unconditional else assigns it) - gaussian.cpp: remove redundant double l1 = ZERO_DOUBLE initializer (immediately overwritten by std::accumulate on the next line) - math_utils.cpp: rename local empirical_cdf → ecdf_i to avoid shadowing the free function empirical_cdf declared at line 400 - work_stealing_pool.cpp: const auto& in destructor and resetStatistics range-for loops (pointer not rebound, atomic stores through const& are fine) - system_capabilities.cpp: add volatile bench_sink read after benchmark loop to prevent dead-code elimination of results[] writes Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phases 2, 3.1, and 3.2 of the quality improvement plan. All changes are mechanical and low-risk; no API or ABI changes.
Changes
Phase 2.1 — Numerical precision (
src/student_t.cpp)Replace
std::log(1.0 + x²/ν)withstd::log1p(x²/ν)at all 9 batch probability sites (6 parallel/GPU lambdas + 3 scalar fallback paths). Avoids catastrophic cancellation whenx²/ν ≈ 0. Added explanatory comment at the first site.Phase 3.1 — C++20 idiom:
starts_with()(10 files)Replace
find(...) != 0/find(...) == 0prefix checks inoperator>>stream parsers withstd::string::starts_with()/!starts_with()acrossbeta,chi_squared,discrete,exponential,gamma(×2),gaussian,poisson,student_t,uniform. Intent is now explicit.Phase 3.2 — Static-analysis sweep (5 fixes)
simd_policy.cpp: remove redundant= SIMDPolicy::Level::Noneinitialiser (every branch including the final unconditionalelseassigns it)gaussian.cpp: remove redundantdouble l1 = ZERO_DOUBLE(immediately overwritten bystd::accumulate)math_utils.cpp: rename localempirical_cdf→ecdf_ito stop shadowing the free function of the same namework_stealing_pool.cpp:const auto&in destructor andresetStatisticsrange-for loops (unique_ptr not rebound; atomic stores through const-ref are fine)system_capabilities.cpp: addvolatile double bench_sinkread after benchmark loop to prevent dead-code elimination ofresults[]writesTesting
Conversation: https://app.warp.dev/conversation/aed97ef4-35cf-4a9d-ab39-264b97f3c2f4
Co-Authored-By: Oz oz-agent@warp.dev