Repository navigation
[eeg_lat2point] Scale the out-of-range tolerance as EEGLAB does - #879
Conversation
Use 16*eps(max(max_valid, max(abs(timewin_sec))*srate)) capped at 0.5, clamp points within the tolerance to max_valid without flagging, and match MATLAB max/min NaN handling, as merged in sccn/eeglab#1002. Fixes #867.
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
Claude finished @arnodelorme's task in 38s —— View job Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. The new tests in
EEGLAB parity notesNone. What I checked against
The vendored Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. |
Code reviewIndependent review by Codex (OpenAI What was done with the findings
Codex's reviewBlockingNone. ImportantMATLAB reference evidence remains unverified. This numerical change requires a run against the pinned EEGLAB and NitsNone. Test gapsThe new tests cover the reported regression at all three sampling rates, strict and default out-of-range handling, a large time origin, overflow, and a NaN latency. They do not directly test the exact tolerance boundary, the half-sample cap, negative or zero scales, or NaN and Inf in epochs and time limits. Add targeted cases for those behaviors and for empty and 2D inputs. The two empty-array guards prevent empty reductions. Local checks preserved the expected shapes and float dtype for the scalar, empty, single-element, and 2D cases checked. An infinite time limit still emits a NumPy invalid-multiply warning in the pre-existing calculation. The changed tolerance logic matches the specified MATLAB reference for the cases inspected. The changed files are within the requested scope. A local comparison confirmed that the long-recording regression tests distinguish this commit from Merge recommendation: Needs changes until the required parity evidence is verified. — orchestrator |
|
Arno confirmed by email on November 29, 2026 ("So Python and EEGLAB agree, right? That's the case just merge.") after merging sccn/eeglab pull request 1002: sccn/eeglab#1002 Merged develop (commit 967a429) into agent/issue-867 (commit d679adf) to resolve the changelog entry conflict with pull request 797, verified that Documentation Build and Pre-commit checks pass on d679adf alongside the full test and EEGLAB reference runs on commit 5edd0e1, and merged this pull request into develop. — orchestrator |
Fixes #867.
Approval (Arno Delorme by email on November 29, 2026, after merging EEGLAB pull request 1002,
eeg_lat2point: round-off tolerance, so pop_select no longer keeps the last sample at 250, 500 and 1000 Hz, commit579a27d0d: sccn/eeglab#1002):On recordings longer than 8,192 samples at 250, 500, and 1000 Hz,
eeg_lat2point.pyused a fixed tolerance of1e-12point, which is smaller than one floating-pointepsof the sample count. It flagged the last sample as out of range,pop_select.pydropped the final rejection region, and the last sample was kept although it was not requested. This pull request ports the exact scaled tolerance, in-tolerance clamping, andNaNhandling of the merged EEGLABeeg_lat2point.m.Example (100,000 samples at 250 Hz,
EEG.data = 0:99999)pop_select(EEG, point=[2, 99999])eeg_lat2pointflag579a27d0d, MATLAB R2025b)2to99999, as requested)100000.00000000001clamped to1000000e435f436)2to100000, last sample kept)100000.00000000001(1.46e-11 > 1e-12)15edd0e1a)2to99999, as requested)100000.00000000001clamped to1000000Comparison with EEGLAB develop (
579a27d0d, MATLAB R2025b)e435f436)[a, b]on 10 and 37 samples across 13 rates, 100 to 30,000 Hz)xmin= -10, 123.45, 1000 s)eeg_lat2pointcalls (random, boundary, out-of-range,outrange1 and 0,NaN/Inf, overflow)max_ulp_diff = 0)pop_select, unchanged)Histogram: samples kept by EEGLAB develop (
579a27d0d) minus samples kept by EEGPrepEEGLAB - EEGPrep)-1(EEGPrep kept one extra trailing sample)0(exact match)+1EEGLAB reference run (rule of pull request #860)
5edd0e1a: all seven jobs passed. Workflow run https://github.com/sccn/eegprep/actions/runs/46289988718 (EEGLAB reference, MATLAB backend, started by hand on this branch), EEGLABd0963be9and eeglab_testsfec88f9f. 4,610 tests passed, 0 failed, 58 skipped, in 35 minutes. Per job: core 3,180 passed and 17 skipped, misc 676 and 8, study 341 and 27, stats 257, hybrid 143 and 4, parity 10 and 2, heavy 3.d0963be9) is 35 commits older than the merged fix579a27d0d, so this run shows that nothing else moved. The agreement with fixed EEGLAB is the comparison above, run locally in MATLAB R2025b ondevelop579a27d0d.Cause, tolerance, and non-finite handling
eeg_lat2pointcomputesnewlat = (lat_array * timeunit - timewin_sec[0]) * srate + 1 + (epoch_array - 1) * pntsand compares it againstmax_valid = max(epoch_array * pnts). Because1 / srateis not exact in binary floating point at rates such as 250, 500, and 1000 Hz, a latency at the last sample can evaluate 1 to 3epsabovemax_valid. Above 8,192 samples, oneepsexceeds1e-12.This pull request mirrors lines 107 to 123 of EEGLAB
functions/popfunc/eeg_lat2point.m(579a27d0d):min(16 * eps(max(max_valid, max(abs(timewin_sec)) * srate)), 0.5), implemented withnp.spacing(abs(scale))andnp.fmax/np.fmin. On 100,000 samples at 250 Hz the tolerance is2.33e-10point, on 1 hour at 1000 Hz (3,600,000samples) it is7.45e-9point, and on 10,000,000 samples it is2.98e-8point. A point one millionth of a sample past the end (1e-6) is still flagged at every tested length.(max_valid, max_valid + tol]are set tomax_validwithout settingflag = 1, without logging a warning, and without raising whenoutrange=0, matching EEGLAB (developleft those values slightly abovemax_valid, causing 44 bit-level differences on direct calls).maxandminomitNaNby default, somin(16 * eps(Inf), 0.5)evaluates to0.5whentimewin_sec * srateoverflows, and aNaNlatency or epoch no longer suppresses detection of another out-of-range point in the same call. Usingnp.fmax.reduceandnp.fmininsidenp.errstate(over='ignore', invalid='ignore')reproduces MATLAB's results across allNaN,Inf, and overflow inputs with zeroRuntimeWarnings.Verification and regression tests
sccn/eeglaborigin/develop(579a27d0d) confirmed byte-for-byte agreement withafter2_1.tsvthroughafter2_7.tsvandafter2_multi.tsvfrom the EEGLAB parity run.tests/test_eeg_lat2point.pymatchingsccn/eeglab_testspull request 17 (pass_roundoff.m, Tests for the last sample in eeg_lat2point and pop_select eeglab_tests#17) and the long-recording failure of eeg_lat2point: the fixed tolerance of 1e-12 point is too small above 8,192 samples (last sample kept at 250, 500 and 1000 Hz) #867:eeg_lat2pointon 10 and 100,000 samples at 250, 500, and 1000 Hz (flag == 0, exactfloat(n)returned, no warning,outrange=0accepted, and mixed near/out-of-range call flagged).eeg_lat2pointon 100,000 samples at 250 Hz with points1e-6sample and1full sample past the end (flag == 1,ValueErrorwithoutrange=0).eeg_lat2pointwith huge time origin[1e12, 1e12 + 1], overflowingtimewin * srate([1e306, 1e306 + 1e291]), and[NaN, 0.05].pop_select(EEG, point=[2, 99999])on 100,000 samples at 250 Hz returning 99,998 samples (1through99998of0:99999).pytest -Werror tests/test_eeg_lat2point.py(10 passed),pytest tests/test_eeg_lat2point.py --eeglab-backend=python(16 passed),tests/test_pop_select.pyandtests/test_eeg_eegrej.py(53 passed, 2 MATLAB-engine skipped),ruff check,ruff format --check,ty check, and./pre-commit.py --changed-from origin/developall pass.— orchestrator