Repository navigation
Mark per-kernel numba copies as deliberate duplication - #44
Merged
Merged
Conversation
Each kernel is its own @numba.njit function so numba can specialize it, so the Epanechnikov..cosine (and, in NW, multivariate Gaussian) functions repeat the Gaussian ones on purpose. Wrap them in jscpd ignore markers so preen's jscpd-based duplicate-code check stops flagging them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Why
preen's
duplicate-codecheck is moving to jscpd (gojiplus/preen#110, not yet released). Onmainit flags two groups in hbw:hbw/_numba_kde.py: 6 copies (LSCV score/derivative loop, one per kernel)hbw/_numba_nw.py: 7 copies (LOOCV loop, one per kernel plus the multivariate Gaussian)These copies are deliberate. Each kernel is a separate
@numba.njit(fastmath=True, parallel=True)function so numba compiles a specialized loop for it; folding them into one function that takes the kernel as an argument would give that up. So rather than refactor, this PR marks them for jscpd.What is marked
One
# jscpd:ignore-start/# jscpd:ignore-endregion per file, with a comment above it saying why. The Gaussian versions stay outside the region, so jscpd would still catch a new copy of them elsewhere.hbw/_numba_kde.py: fromlscv_numba_epanthroughlscv_score_numba_cosine(Epanechnikov, uniform, biweight, triweight, cosine).lscv_mv_numba_gaussandwarmupstay outside.hbw/_numba_nw.py: fromloocv_numba_epanthroughloocv_score_mv_numba_gauss(Epanechnikov, uniform, biweight, triweight, cosine, multivariate Gaussian).warmupstays outside.Only comment lines are added (13 lines); no code changes.
Check output
preen
DuplicateCodeCheckfrom theduplicate-code-jscpdbranch:Before:
After:
Plain
uvx jscpd==5.4.2 hbw --format python --ignore-identifiers=consistent --min-lines 12 --min-tokens 1 --reporters console: 17 clones before, 1 after. The one left is the shared 13-line module header (the numba/pyright comment plus imports, lines 3-15 of both files). Plain jscpd counts comments and imports; preen's check skips them, which is why preen passes.Other checks
ruff check,ruff format --check,pyright(0 errors) andpydoclint hbw/are clean;pytest: 103 passed.🤖 Generated with Claude Code