Skip to content

refactor(inner,krylov): reduce cyclomatic complexity to grade A (#52) - #53

Merged
tschm merged 1 commit into
mainfrom
fix/reduce-inner-complexity
Jul 10, 2026
Merged

refactor(inner,krylov): reduce cyclomatic complexity to grade A (#52)#53
tschm merged 1 commit into
mainfrom
fix/reduce-inner-complexity

Conversation

@tschm

@tschm tschm commented Jul 10, 2026

Copy link
Copy Markdown
Member

Summary

Closes #52. Extracts the three cyclomatic-complexity B blocks flagged by the quality scorecard into small named helpers, so radon cc reports no block above grade A — without disturbing the in-house CG/PCG numerical core (CLAUDE.md's flagged core contribution).

Changes

  • krylov.pcg (CC 7 → 5): hoist the identity-preconditioner default into _resolve_precond, and the warm-start iterate/residual setup into _pcg_start. The bnorm == 0 early-out now precedes the initial-iterate build (identical result, one fewer redundant vector op on a zero RHS).
  • inner.Exact.solve (CC 6 → 3) / Exact class (7 → 4): move the free-set memo predicate into _same_free_block and the rcond singularity guard into _raise_if_singular.

Verification

  • uvx radon cc src -a -s: no block above grade A; average 2.61 → 2.38
  • make fmt, make typecheck (ty + mypy strict), make test: all pass
  • 102 tests pass, 100% coverage (unchanged)

Done when (issue acceptance): uvx radon cc src -s reports no block above grade A with tests green at 100% — ✅ met.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 10, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors two core numerical modules (krylov.pcg and inner.Exact.solve) to reduce cyclomatic complexity by extracting small helper functions, while preserving existing CG/PCG and conditioning-guard behavior.

Changes:

  • pcg: factors out default identity-preconditioner resolution and warm-start initialization; moves bnorm == 0 early return ahead of initial iterate/residual setup.
  • Exact.solve: factors out the “same free block” memo predicate and the conditioning/singularity guard into helpers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/nncg/krylov.py Extracts _resolve_precond and _pcg_start to simplify pcg setup flow and reduce CC.
src/nncg/inner.py Extracts _same_free_block and _raise_if_singular to simplify Exact.solve conditioning guard and reduce CC.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tschm

tschm commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in src/nncg/inner.py and merged origin/main into this branch in commit 4f67526.

Copilot finished work on behalf of tschm July 10, 2026 09:09
…ade A (#52)

Splits the three cyclomatic-complexity B blocks flagged by the quality
scorecard into small named helpers, without touching the numerical core:

- krylov.pcg (7->5): hoist the identity-preconditioner default into
  _resolve_precond and the warm-start iterate/residual setup into _pcg_start.
- inner.Exact.solve (6->3) / Exact class (7->4): move the free-set memo
  predicate into _same_free_block and the rcond guard into _raise_if_singular.

radon cc now reports no block above grade A (avg 2.61 -> 2.38); all 102
tests pass at 100% coverage.

Closes #52

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tschm
tschm force-pushed the fix/reduce-inner-complexity branch from 4f67526 to 91619fb Compare July 10, 2026 09:15
@tschm
tschm merged commit de24ca5 into main Jul 10, 2026
62 checks passed
@tschm
tschm deleted the fix/reduce-inner-complexity branch July 10, 2026 09:47
@tschm
tschm restored the fix/reduce-inner-complexity branch July 13, 2026 20:34
@tschm
tschm deleted the fix/reduce-inner-complexity branch July 14, 2026 09:45
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.

Reduce cyclomatic complexity of B-ranked numerical blocks in inner.py and krylov.py

3 participants