runoff: reuse IRV Numba tally helpers for head-to-head round#46
runoff: reuse IRV Numba tally helpers for head-to-head round#46endolith wants to merge 6 commits into
Conversation
PR Summary
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 96.37% 96.39% +0.02%
==========================================
Files 17 17
Lines 496 499 +3
==========================================
+ Hits 478 481 +3
Misses 18 18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.14 to 0.15.15. - [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases) - [Commits](astral-sh/ruff-pre-commit@v0.15.14...v0.15.15) --- updated-dependencies: - dependency-name: https://github.com/astral-sh/ruff-pre-commit dependency-version: 0.15.15 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
…hub.com/astral-sh/ruff-pre-commit-0.15.15 Bump https://github.com/astral-sh/ruff-pre-commit from v0.15.14 to 0.15.15
Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.15 to 0.15.16. - [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases) - [Commits](astral-sh/ruff-pre-commit@v0.15.15...v0.15.16) --- updated-dependencies: - dependency-name: https://github.com/astral-sh/ruff-pre-commit dependency-version: 0.15.16 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
…hub.com/astral-sh/ruff-pre-commit-0.15.16 Bump https://github.com/astral-sh/ruff-pre-commit from v0.15.15 to 0.15.16
Second-round contingent vote compares two finalists by whoever appears first on each ballot. That matches advancing each voter's rank index past all non-finalists then tallying at that rank—the same _inc_rank_idx and _tally_at_rank_idx path IRV uses. Co-authored-by: endolith <endolith@gmail.com>
Master replaced reflected-set elimination with a boolean mask in _inc_rank_idx. Update the head-to-head round to match IRV/Coombs and add tests for the docstring example and direct tally-helper behavior. Co-authored-by: endolith <endolith@gmail.com>
f66b32a to
4b7478a
Compare
Closes #3.
Summary
The contingent-vote / top-two runoff second round used a Python loop with
list.indexper ballot. That round is equivalent to instant runoff among only the two finalists: skip every other candidate on each ballot, then count first preference among{finalist_0, finalist_1}. That is exactly what_inc_rank_idx+_tally_at_rank_idxdo—the same Numba path IRV and Coombs use.Changes
elsim/methods/runoff.pylist.indexhead-to-head tally with_inc_rank_idx/_tally_at_rank_idx.eliminated_mask(all candidates except the two finalists) and advance each voter's rank cursor past eliminated candidates before tallying.setin Numba helpers.tests/test_runoff.pytest_docstring_example: exercises the contingent-vote example from therunoff()docstring.test_head_to_head_tally_via_irv_helpers: asserts the shared helpers produce the expected 3–2 split when only finalists A and B remain.Rebase notes
Rebased onto current
master. The original PR passed a Pythonsetinto_inc_rank_idx; master now requires a booleaneliminated_maskndarray, so the second commit updates runoff accordingly.Testing
pytest: 217 passed locally (with[fast]/ Numba).