speedup: vectorise Monte Carlo permutation test in fisher_test_cci#12
Merged
Conversation
Agent-Logs-Url: https://github.com/CostaLab/pyCrossTalkeR/sessions/276a8fba-104c-4eb6-88c4-8c314a2cbaf7 Co-authored-by: jsnagai <8943000+jsnagai@users.noreply.github.com>
Agent-Logs-Url: https://github.com/CostaLab/pyCrossTalkeR/sessions/276a8fba-104c-4eb6-88c4-8c314a2cbaf7 Co-authored-by: jsnagai <8943000+jsnagai@users.noreply.github.com>
Agent-Logs-Url: https://github.com/CostaLab/pyCrossTalkeR/sessions/276a8fba-104c-4eb6-88c4-8c314a2cbaf7 Co-authored-by: jsnagai <8943000+jsnagai@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
jsnagai
April 1, 2026 14:48
View session
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.
The Monte Carlo permutation loop inside
fisher_test_ccicalledfisher_exact1 000 times per cell pair via a plain Pythonforloop, withnp.random.seed(42)reset on every iteration (making all permutations across rows identical).perm_p_valuewas computed but never stored.Changes
np.random.seed(42)inside the inner loop with a singlenp.random.default_rng(42)created once per function call.fisher_exactcalls: 4 values yield at most 4! = 24 unique 2×2 arrangements;np.unique(..., return_inverse=True)reduces ~1 000 calls per row to ≤ 24.count += 1loop with(perm_pvals <= p_value + _PVAL_TOL).sum().perm_p_valuenow stored: added as aperm_p_valuecolumn in the output stats DataFrame._pairwise_statshelper shared by both branches offisher_test_cci.