Skip to content

partial moments: co-moments reject empty input and recycled targets - #189

Closed
gitRasheed wants to merge 1 commit into
rasheed/py-meboot-zero-residualsfrom
rasheed/py-co-moment-lengths
Closed

gitRasheed wants to merge 1 commit into
rasheed/py-meboot-zero-residualsfrom
rasheed/py-co-moment-lengths

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

R's Co.LPM, Co.UPM, D.LPM and D.UPM crashed the session on unequal lengths with a vector target, and raised SIGFPE on an empty target. OVVO-Financial/NNS#132 (merged) checks the lengths up front: x and y equal and non-empty, targets non-empty, and target lengths equal or one of them 1. Unequal target lengths used to recycle and now raise. This slice mirrors that half. The other half, D.UPM with one integer and one fractional degree, is in NNS-core and comes with the re-vendor.

Stacked on #188; merge with a merge commit.

Changes

  • _co_moment (co_moments.py) runs one check before the native/pure dispatch, so both backends raise the same ValueError. Unequal x and y already raised. Empty x and y raise "x and y must be non-empty." (the repo's wording, not R's backticked one). Empty targets raise, and so do target lengths that are neither equal nor 1. The native branch's size > 0 guard is gone, since the check covers it.
  • Before and after, with after equal to R main (native / NNS_DISABLE_NATIVE=1): co_lpm(1, x, x, [0, 1, 2], [0, 1]) recycled in both and now raises. An empty target raised ZeroDivisionError in both. Two empty targets returned []. co_lpm(1, [], [], 0, 0) raised natively and returned nan without native. All of these now raise ValueError.
  • The internal callers (var.py and arma.py, through the VAR and ARMA optimiser objectives) pass scalar targets, so nothing depended on recycling.
  • docs/conventions.md: the "Co-Moment Length Mismatch Divergence From R" section described R's old truncate-and-warn behaviour. It is now "Co-Moment Lengths" and states the rule, which R now shares. The docs/api_status.md row and the co_lpm docstring change to match.

Tests

  • New invariants mirroring the length block of R's test-co-moments.R for all four functions: unequal x and y with scalar, None and 200-point targets, empty x and y with 0 and None targets, an empty target_x, target_y or both, [0, 1, 2] against [0, 1], and a vector target against a scalar one equal to the elementwise calls. They pass with and without the native kernel and fail on the parent commit in both. I left out R's mixed-degree block, since native D.UPM gives 2.5 instead of 6.5 until the re-vendor.
  • No cache entry moves.
  • Gates on the top of this stack (rasheed/co-moment-lengths), cache only: native 2958 passed, 4 skipped, 3 xfailed, 2 xpassed. With NNS_DISABLE_NATIVE=1: 2936 passed, 29 skipped, 2 xpassed. The 3 xfails are mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178's strict ones and the 2 xpasses the existing non-strict live-R VAR xfails. tests/parity/test_practical_examples.py against the usual R library: 9 passed, 2 xfailed, as on mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178. ruff check is clean on every changed file.

Mirrors the length checks of OVVO-Financial/NNS#132

Review

GPT-6.1 Sol reviewed the #149 and #132 mirrors together: SHIP, no findings. It checked 198 nonzero-residual meboot cases per backend for bit-identical outputs and RNG state.

…R co-moment-fixes)

Mirrors the length checks of R Co.LPM/Co.UPM/D.LPM/D.UPM
(OVVO-Financial/NNS co-moment-fixes). co_lpm, co_upm, d_lpm and d_upm
already raised on unequal x and y. Now one check before the native/pure
dispatch also rejects empty x and y, empty targets, and target lengths
that are neither equal nor 1, so both backends raise the same ValueError.

Before -> after (= R main), native / NNS_DISABLE_NATIVE=1:
  co_lpm(1, x, x, [0, 1, 2], [0, 1])  recycled / recycled -> ValueError
  co_lpm(1, x, x, [], 0)              ZeroDivisionError / same -> ValueError
  co_lpm(1, x, x, [], [])             [] / [] -> ValueError
  co_lpm(1, [], [], 0, 0)             ValueError / nan -> ValueError

The internal callers (var.py, arma.py) pass scalar targets. R's
mixed-degree D.UPM fix comes with the NNS-core re-vendor. No cache entry
moves.
OVVO-Financial added a commit that referenced this pull request Nov 6, 2026
This audit retains exactly the previously green workflow files from #189, including pandas test dependencies and pure-Python fallback parity, instead of the older main defaults restored by workflow protection. Workflow change approved for draft audit; do not merge until all R 14.0 gates pass.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Incorporated through NNS R 14.0 integration #192, merged as bd19c3303222af46da79d8c97f258248eb5674d2. Verified exact head 25c98d5cbdd090d22fc0c5a3816d4ae076c14a5e is an ancestor of main; original commits and authorship are preserved. The integration includes the subsequent R14 compatibility corrections and passed the complete GitHub Python 3.11-3.14 matrix. This supersedes the separate landing, not the work or review history.

@github-actions github-actions Bot closed this Nov 7, 2026
@github-actions
github-actions Bot deleted the rasheed/py-co-moment-lengths branch November 7, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant