Deduplicate native dispatch and warn on ignored R-compat parameters - #75
Merged
Conversation
- 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.
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.
What
core.py: one implementation instead of four.lpm/upm/lpm_ratio/upm_ratioshared ~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-callhasattrguards. The extension is version-pinned and vendored, so probing it attribute-by-attribute at every call was noise.co_momentsnow picks its kernel — including thed_lpm_vdegree-order swap — in one resolver.ncoreseverywhere,nowcast/obj_fninnns_var,location/dist/return_values/plot_regionsinnns_m_reg,return_valuesinnns_reg) emit aUserWarningwhen 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._reject_deferred_pathsstub inregression.py(validated nothing), and internalncores=1forwarding innns_var/nns_m_reg(always a no-op, and would have tripped the new warning).native_fninstead ofnnscore;uv.lockrefreshed against 1.0.9.Verification
NNS_R_CACHE_ONLY=1, no cache regeneration): 2202 passed. The 3test_practical_examplesfailures in my WSL environment fail identically on clean main (stale local extension build) and are green in CI.ruffandmypy --strictclean.