Skip to content

RFC: Decompose the four grade-D complexity hotspots #886

Description

@mmcky

Problem

Radon rates exactly four functions at cyclomatic-complexity grade D — everything else in the package is C or better, so the complexity is concentrated and tractable:

Function Location CC
_compute_fixed_point_ig _compute_fp.py:159 25
DiscreteDP.__init__ markov/ddp.py:299 24
brent_max optimize/scalar_maximization.py:5 24
polym_lcp_solver game_theory/howson_lcp.py:36 23

DiscreteDP.__init__ alone dispatches dense/sparse × full/state-action-pairs input forms inline; _compute_fixed_point_ig interleaves algorithm and bookkeeping. High-CC plus hand-verified numerics is where regressions hide.

Proposed change

One PR per function; behavior-preserving extraction only:

  • DiscreteDP.__init__ → extract _parse_full_form(...) / _parse_sa_form(...) validators returning a normalized bundle.
  • _compute_fixed_point_ig → separate the iteration loop from error/logging bookkeeping.
  • brent_max is Numba-jitted — some branching is inherent to Brent; treat as best-effort.
  • Guard with before/after output equality on existing tests (coverage in these regions is strong).

Related context: #480 (repeated logic in several modules).

Acceptance criteria

  • Radon grade ≤ C for the three non-jitted functions; no public API change
  • Suite green with unchanged numerical outputs

From the July 2026 technical-debt audit (AI-assisted; claims verified against 28d4b3b on 2026-07-25).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions