Skip to content

Deduplicate native dispatch and warn on ignored R-compat parameters - #75

Merged
OVVO-Financial merged 1 commit into
mainfrom
native-dispatch-cleanup
Jul 4, 2026
Merged

Deduplicate native dispatch and warn on ignored R-compat parameters#75
OVVO-Financial merged 1 commit into
mainfrom
native-dispatch-cleanup

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

What

  • core.py: one implementation instead of four. lpm/upm/lpm_ratio/upm_ratio shared ~80% of their bodies; they are now thin wrappers over a single moment and a single ratio function. Numerics are unchanged, including the degree-0 equality convention (<= counts toward the lower moment) and the non-finite-input fallback.
  • native_fn(name) replaces 18 per-call hasattr guards. The extension is version-pinned and vendored, so probing it attribute-by-attribute at every call was noise. co_moments now picks its kernel — including the d_lpm_v degree-order swap — in one resolver.
  • Ignored parameters now warn instead of lying. Parameters accepted for R API compatibility but not implemented (ncores everywhere, nowcast/obj_fn in nns_var, location/dist/return_values/plot_regions in nns_m_reg, return_values in nns_reg) emit a UserWarning when a caller sets them to a non-default value. Console-verbosity flags (status, print_trace, messages, elaps) stay silent — NNS Python never prints, so there is nothing to warn about — each now carries a one-line comment saying so.
  • Dead code removed: the _reject_deferred_paths stub in regression.py (validated nothing), and internal ncores=1 forwarding in nns_var/nns_m_reg (always a no-op, and would have tripped the new warning).
  • Invariant tests updated to patch native_fn instead of nnscore; uv.lock refreshed against 1.0.9.

Verification

  • Full suite, cache-only (NNS_R_CACHE_ONLY=1, no cache regeneration): 2202 passed. The 3 test_practical_examples failures in my WSL environment fail identically on clean main (stale local extension build) and are green in CI.
  • Native and pure-Python paths spot-checked byte-identical for all four core partial moments and all four co-moments, scalar and vector targets.
  • Warnings verified to fire on explicit non-default values only; internal library calls never warn.
  • ruff and mypy --strict clean.

- core.py: collapse lpm/upm/lpm_ratio/upm_ratio into one moment and one
  ratio implementation; numerics unchanged, including the degree-0
  equality convention and non-finite fallback behavior.
- _native.py: add native_fn(name) and use it everywhere, replacing 18
  per-call hasattr checks against the pinned extension. co_moments picks
  its kernel (and the d_lpm_v degree swap) in one resolver.
- Warn (UserWarning) when a caller sets an accepted-for-R-compatibility
  parameter that has no effect: ncores, nowcast, obj_fn in nns_var,
  location/dist/return_values/plot_regions in nns_m_reg, return_values
  in nns_reg. Console-verbosity flags (status, print_trace, messages,
  elaps) stay silent with a comment; NNS Python never prints.
- Remove dead code: the no-op _reject_deferred_paths stub and internal
  ncores=1 forwarding in nns_var/nns_m_reg.
- Update invariant tests to patch native_fn instead of nnscore.
- Refresh uv.lock.

Verified: full suite (cache-only) 2202 passed; the 3 practical-example
failures are pre-existing on clean main in this environment and green in
CI. Native and pure-Python paths spot-checked identical for all core and
co-moment functions. ruff and mypy --strict clean.
@OVVO-Financial
OVVO-Financial merged commit 0ab45cc into main Jul 4, 2026
8 checks passed
@OVVO-Financial
OVVO-Financial deleted the native-dispatch-cleanup branch July 5, 2026 15:26
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.

2 participants