Skip to content

Mark per-kernel numba copies as deliberate duplication - #44

Merged
soodoku merged 2 commits into
mainfrom
mark-kernel-copies
Oct 23, 2026
Merged

soodoku merged 2 commits into
mainfrom
mark-kernel-copies

Conversation

@soodoku

@soodoku soodoku commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Why

preen's duplicate-code check is moving to jscpd (gojiplus/preen#110, not yet released). On main it 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-end region 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: from lscv_numba_epan through lscv_score_numba_cosine (Epanechnikov, uniform, biweight, triweight, cosine). lscv_mv_numba_gauss and warmup stay outside.
  • hbw/_numba_nw.py: from loocv_numba_epan through loocv_score_mv_numba_gauss (Epanechnikov, uniform, biweight, triweight, cosine, multivariate Gaussian). warmup stays outside.

Only comment lines are added (13 lines); no code changes.

Check output

preen DuplicateCodeCheck from the duplicate-code-jscpd branch:

Before:

False ['18 duplicated lines of code: hbw/_numba_kde.py lines 246-272, hbw/_numba_kde.py lines 320-346, hbw/_numba_kde.py lines 394-420, hbw/_numba_kde.py lines 467-493, hbw/_numba_kde.py lines 550-576, hbw/_numba_kde.py lines 635-661', '17 duplicated lines of code: hbw/_numba_nw.py lines 62-89, hbw/_numba_nw.py lines 168-195, hbw/_numba_nw.py lines 270-297, hbw/_numba_nw.py lines 379-406, hbw/_numba_nw.py lines 496-523, hbw/_numba_nw.py lines 611-638, hbw/_numba_nw.py lines 727-754']

After:

True []

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) and pydoclint hbw/ are clean; pytest: 103 passed.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T20:43:33.376736Z f46b8c5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@soodoku
soodoku merged commit 7f54252 into main Oct 23, 2026
12 checks passed
@soodoku
soodoku deleted the mark-kernel-copies branch October 23, 2026 20:55
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