Skip to content

refactor(phase2-3): numerical precision, C++20 idioms, static-analysis cleanup#17

Merged
OldCrow merged 1 commit intomainfrom
refactor/phase2-3-6-cleanup
May 6, 2026
Merged

refactor(phase2-3): numerical precision, C++20 idioms, static-analysis cleanup#17
OldCrow merged 1 commit intomainfrom
refactor/phase2-3-6-cleanup

Conversation

@OldCrow
Copy link
Copy Markdown
Owner

@OldCrow OldCrow commented May 6, 2026

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²/ν) with std::log1p(x²/ν) at all 9 batch probability sites (6 parallel/GPU lambdas + 3 scalar fallback paths). Avoids catastrophic cancellation when x²/ν ≈ 0. Added explanatory comment at the first site.

Phase 3.1 — C++20 idiom: starts_with() (10 files)

Replace find(...) != 0 / find(...) == 0 prefix checks in operator>> stream parsers with std::string::starts_with() / !starts_with() across beta, 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::None initialiser (every branch including the final unconditional else assigns it)
  • gaussian.cpp: remove redundant double l1 = ZERO_DOUBLE (immediately overwritten by std::accumulate)
  • math_utils.cpp: rename local empirical_cdfecdf_i to stop shadowing the free function of the same name
  • work_stealing_pool.cpp: const auto& in destructor and resetStatistics range-for loops (unique_ptr not rebound; atomic stores through const-ref are fine)
  • system_capabilities.cpp: add volatile double bench_sink read after benchmark loop to prevent dead-code elimination of results[] writes

Testing

  • 31/31 libstats correctness tests pass
  • All pre-commit hooks (clang-format, copyright headers, include order, secrets) pass

Conversation: https://app.warp.dev/conversation/aed97ef4-35cf-4a9d-ab39-264b97f3c2f4

Co-Authored-By: Oz oz-agent@warp.dev

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>
@OldCrow OldCrow merged commit 3d68552 into main May 6, 2026
26 checks passed
@OldCrow OldCrow deleted the refactor/phase2-3-6-cleanup branch May 6, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant