refactor(inner,krylov): reduce cyclomatic complexity to grade A (#52) - #53
Merged
Conversation
Contributor
There was a problem hiding this comment.
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; movesbnorm == 0early 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.
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Resolved the merge conflict in |
…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
force-pushed
the
fix/reduce-inner-complexity
branch
from
July 10, 2026 09:15
4f67526 to
91619fb
Compare
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.
Summary
Closes #52. Extracts the three cyclomatic-complexity B blocks flagged by the quality scorecard into small named helpers, so
radon ccreports 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. Thebnorm == 0early-out now precedes the initial-iterate build (identical result, one fewer redundant vector op on a zero RHS).inner.Exact.solve(CC 6 → 3) /Exactclass (7 → 4): move the free-set memo predicate into_same_free_blockand thercondsingularity guard into_raise_if_singular.Verification
uvx radon cc src -a -s: no block above grade A; average 2.61 → 2.38make fmt,make typecheck(ty + mypy strict),make test: all passDone when (issue acceptance):
uvx radon cc src -sreports no block above grade A with tests green at 100% — ✅ met.🤖 Generated with Claude Code