Skip to content

Match MATLAB spacing on time, frequency, and cycle grids - #602

Merged
suraj-ranganath merged 10 commits into
developfrom
cursor/linspace-matlab-grids-f424
Nov 18, 2026
Merged

suraj-ranganath merged 10 commits into
developfrom
cursor/linspace-matlab-grids-f424

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Time, frequency, and cycle grids now follow the EEGLAB linspace, colon, or logspace expression, including EEG.times. Gauss uses -sds:incr:sds and fdlibm exp. dftfilt evaluates its phase and Hanning taper with fdlibm sin and cos. Log-spaced widths use fdlibm 10.^x. Histogram centers, FDR thresholds, trend regressors, the dftfilt phase and wavelet window, color-bar ticks and labels, DIPFIT scan grids, and the topoplot mesh do too. A constant hist2 widens a zero span before that spacing, so the bars have a width. The plotted head outline keeps 100 points, spaced with MATLAB linspace; EEGLAB's circle uses 201. Colormap samples, eegplot pixel edges, ICLabel scroll ticks, log-image ticks, signalstat histogram centers, the blank scalp grid, and contour levels stay, because EEGLAB does not build them with linspace or a colon. MATLAB was not run here.

Fixes #568

Open in Web Open in Cursor 

EEG.times, import and epoch time vectors, and returned frequency and
cycle grids now use the MATLAB linspace helper, or the upstream colon
or logspace when that is the EEGLAB expression. Display, tick, and
exact-step grids are unchanged.

Refs #568

Co-authored-by: Suraj Ranganath <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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.

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 11, 2026 18:36
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 11, 2026 18:36
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 18, 2026 06:56
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 18, 2026 06:57

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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.

Gauss follows -sds:incr:sds. Histogram centers, FDR thresholds, trend
regressors, the dftfilt phase and wavelet window, color-bar ticks and
labels, DIPFIT scan grids, and the topoplot mesh use MATLAB linspace
or colon spacing.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 18, 2026 10:02
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 18, 2026 10:02
@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 2m 4s —— View job


Code review

  • Overall assessment: Needs changes. Most of the swaps from np.linspace to the MATLAB linspace helper are mechanical and correct. I checked the timefreq count==1 path (MATLAB linspace(a,b,1) returns b), the newtimef ERP time base, envtopo (xmin:sampint:xmax in seconds), gauss (-sds:incr:sds), and how the tests are built. All the expected values are hard-coded hex values, not values rebuilt with the code under test. One regression, one layering problem, and the missing MATLAB evidence block the merge.
  • Highest-risk area: EEG.times now changes in every constructor (eeg_checkset, pop_epoch, pop_resample, eeg_eegrej, clean_windows, …), and the PR includes no MATLAB reference run.
  • Merge recommendation: Needs changes.

Blocking

  • No MATLAB reference evidence. The PR description says "MATLAB was not run here." This PR changes core numerics (EEG.times, timefreq frequency grids, newtimef, gauss, fdr, rejtrend, dftfilt*). AGENTS.md §Testing says: "Before merging a PR that changes core function implementations … trigger .github/workflows/eeglab-reference.yml … Put that run in the PR description." Every expected hex value in tests/test_linspace.py was worked out by hand rather than checked against MATLAB. The parity claim stays unproven until that run happens. Fix: dispatch the EEGLAB reference workflow on this branch. Then paste the commits, the pass/fail/skip counts and the runtime into the PR body.

Important

  • hist2 regression on constant data (src/eegprep/functions/miscfunc/hist2.py:64-65). The PR deleted the minimum == maximum widening. Constant input, such as a flat channel or hist2([1,1],[1,1]) with the default 100 bins, now gives count identical centers. _bar_widths then returns all-zero widths, so the bars are invisible, and set_xlim(c, c) triggers matplotlib's identical-limits warning. User-supplied centers are still rejected unless strictly increasing (line 59), so auto-generated centers now break an invariant the function enforces for explicit centers. Fix: restore the degenerate-range branch in front of linspace (the inline comment has a suggestion block). Add a test with constant input that checks the bars have non-zero widths. Fix this →

  • Core functions now import a plugin's private module. functions/miscfunc/gauss.py, functions/sigprocfunc/{cbar,envtopo,erpimage}.py, and functions/timefreqfunc/newtimef.py all add from eegprep.plugins.clean_rawdata.private.windows import matlab_colon. Before this PR, nothing under functions/ imported from plugins/clean_rawdata/private. Today these imports avoid a cycle only because plugins/clean_rawdata/__init__.py loads lazily. Fix: move matlab_colon into functions/miscfunc/, next to linspace.py, and update every caller, clean_windows included. Fix this →

  • Duplicate linspace implementation in _sort_window (src/eegprep/functions/sigprocfunc/erpimage_engine.py:1816-1825). These lines rewrite the helper by hand, which AGENTS.md lists as a failure pattern ("Parallel implementations of existing helpers"). Fix: window = (minx + 1) - linspace(np.floor(winlen / 2), np.floor(-winlen / 2), winlen + 1).

Nits

  • src/eegprep/functions/sigprocfunc/erpimage.py:482-484: the only caller, _draw_colorbar, guards with vmax > vmin, so scale can never be 0 and both scale guards can't be reached. Drop them.
  • Import grouping: dftfilt3.py has a stray blank line between two eegprep.functions.miscfunc imports, and erpimage.py adds a separate import block above the existing eegprep imports. Run ./pre-commit.py --changed-from origin/develop --fix.

Test gaps

  • Constant-input hist2 (see Important).
  • test_single_pac_window_selects_the_matlab_linspace_stop imports the private _pac_cont_windows. Prefer going through the public PAC entry point if one exists.

EEGLAB parity notes

  • timefreq with nfreqs=1 now returns the upper frequency instead of the lower one. This matches MATLAB linspace(f1, f2, 1), but it is a visible behavior change. Name it in the changelog entry, which currently doesn't mention it.
  • The topoplot head circle keeps 100 points while EEGLAB draws 201. The changelog documents this, which is fine for a visual-only element.

I posted inline comments on hist2.py, gauss.py, erpimage_engine.py, and erpimage.py. The vendored EEGLAB .m files are not in this checkout, so the parity checks above rely on EEGLAB's documented expressions rather than a side-by-side read of the source. I could not run the tests in this job.

minimum -= span
maximum += span
return np.linspace(minimum, maximum, count)
return linspace(minimum, maximum, count)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: regression on constant data. The PR deleted the minimum == maximum branch. Constant input now gives count identical centers, for example a flat channel, or hist2([1, 1], [1, 1]) with the default 100 bins. _bar_widths then returns all-zero widths, so the bars are invisible, and set_xlim(c, c) triggers matplotlib's identical-limits warning. Explicit centers are still required to be strictly increasing (line 59), so auto-generated centers now break that invariant.

Fix: keep the degenerate-range handling and use the MATLAB linspace only on the normal path:

Suggested change
return linspace(minimum, maximum, count)
if minimum == maximum:
if count == 1:
return np.asarray([minimum])
span = max(abs(minimum), 1.0) * 0.5
minimum -= span
maximum += span
return linspace(minimum, maximum, count)

Comment thread src/eegprep/functions/miscfunc/gauss.py Outdated

import numpy as np

from eegprep.plugins.clean_rawdata.private.windows import matlab_colon

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: layering. This line and the matching ones in cbar.py, envtopo.py, erpimage.py and newtimef.py are the first imports from plugins/clean_rawdata/private anywhere under functions/. A general MATLAB colon helper doesn't belong in a clean_rawdata private module. Right now these imports avoid a cycle only because plugins/clean_rawdata/__init__.py loads lazily.

Fix: move matlab_colon into functions/miscfunc/, next to linspace.py, and update every caller, clean_windows included. A separate commit is fine.

Comment on lines +1816 to +1825
count = winlen + 1
start = float(np.floor(winlen / 2))
stop = float(np.floor(-winlen / 2))
offsets = np.empty(count, dtype=float)
if count == 1:
offsets[0] = stop
else:
offsets[:-1] = start + np.arange(count - 1) * (stop - start) / (count - 1)
offsets[-1] = stop
window = (minx + 1) - offsets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: duplicate helper. These lines rewrite linspace by hand, including the count == 1 → stop case. AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern.

Fix: import linspace from eegprep.functions.miscfunc.linspace at the top of the module and replace these lines with:

    window = (minx + 1) - linspace(np.floor(winlen / 2), np.floor(-winlen / 2), winlen + 1)

Comment on lines +482 to +484
dec = int(np.floor(np.log10(scale))) if scale else 0
if scale == 0:
return ticks, labels

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: guards that can't run. The only caller, _draw_colorbar (line 468), calls this function only when vmax > vmin. So scale = max(|vmin|, |vmax|) is never 0, and AGENTS.md says not to add checks for impossible states.

Suggested change
dec = int(np.floor(np.log10(scale))) if scale else 0
if scale == 0:
return ticks, labels
dec = int(np.floor(np.log10(scale)))

cursoragent and others added 2 commits November 18, 2026 10:22
A zero data span is widened before MATLAB linspace, so auto bin centers stay strictly increasing. matlab_colon now lives next to linspace. The ERP-image engine keeps its own linspace because that module cannot import the package.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 18, 2026 11:03
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 18, 2026 11:03
@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 30s —— View job


Code review

  • Overall assessment: Needs changes. The earlier review's findings are mostly fixed. The hist2 constant-data widening is back and has a test. matlab_colon now lives in functions/miscfunc/matlab_colon.py, and nothing under functions/ imports from plugins/clean_rawdata/private any more. The unreachable scale == 0 guards in erpimage._colorbar_ticks are gone. The swaps from np.linspace to the MATLAB linspace look mechanically correct. I checked EEG.times in each place that builds it, the timefreq grids (with nfreqs=1 it now returns the stop value), newtimef (tlimits(2)+0.000001), envtopo (colon in seconds), cbar, and the dipfit scan grids.
  • Highest-risk area: the new 376-line fdlibm exp/pow port (miscfunc/ieee754.py). Nothing confirms it matches MATLAB, and it is applied to only two of the exp grid sites.
  • Merge recommendation: Needs changes.

Blocking

  • There is still no MATLAB reference run. The PR body says "MATLAB was not run here." This PR changes core numerics: EEG.times everywhere it is built, the timefreq frequency grids, newtimef, gauss, fdr, rejtrend, dftfilt*, and clean_windows. AGENTS.md §Testing requires the .github/workflows/eeglab-reference.yml run, with commits, pass/fail/skip counts and runtime, in the PR body before merge. Every expected hex value in tests/test_linspace.py was derived by hand or from the code under test. Only the reference run can show these values match MATLAB.
    Fix: dispatch the EEGLAB reference workflow on this branch and paste the results into the PR body.

Important

  • The fdlibm exp/pow port has no evidence behind it and is applied in only some places (src/eegprep/functions/miscfunc/ieee754.py; inline comment posted). The module assumes MATLAB's exp/.^ return fdlibm results. Nothing in the PR checks that. Meanwhile fdr.py:57, timefreq.py:231, dftfilt2.py:63, dftfilt3.py:118 and erpimage_engine._gauss (:2230) still use np.exp on the same kind of MATLAB exp(linspace(...)) grids. The result: miscfunc.gauss and erpimage's private _gauss copy no longer agree bit-for-bit, even though erpimage_engine.py's docstring says tests pin the copies together.
    Fix: drop ieee754.py from this PR. Restore np.exp in gauss.py and 10.0 ** linspace(...) in tf_cycle_calc._width_vector. Bring fdlibm back in a follow-up PR once a MATLAB run shows it is needed, and apply it to every exp grid site at that point. Fix this →

Nits

  • src/eegprep/functions/timefreqfunc/dftfilt3.py:9-11 has a stray blank line between two eegprep.functions.miscfunc imports. ./pre-commit.py --changed-from origin/develop --fix should fix it.

Test gaps

  • test_gauss_samples_follow_the_matlab_colon and the log-spaced _width_vector check take their expected hex values from the fdlibm code under test, so they can't catch a wrong premise. Either replace those values with ones from the MATLAB reference run, or drop the checks along with ieee754.py.

EEGLAB parity notes

  • Withdrawn from the previous review: the private _linspace in erpimage_engine.py is not a duplicate to remove. The module docstring requires that file to stay free of eegprep imports for the browser build, so a private copy is correct there.
  • timefreq with nfreqs=1 now returns the upper frequency, as MATLAB linspace(f1,f2,1) does. The changelog says "one sample equal to the stop" in general terms. Consider naming timefreq/newtimef explicitly, because users will see a different single frequency.
  • The topoplot head circle keeps 100 points where EEGLAB uses 201. The changelog documents this and it only affects how the plot looks, so it's fine.

I could not run tests or MATLAB in this job. src/eegprep/eeglab/ is not in this checkout, so the parity checks rely on the EEGLAB expressions quoted in the code and the changelog, not on a direct read of the .m source.

@@ -0,0 +1,376 @@
"""Sun fdlibm ``exp`` and ``pow``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: this module's premise is unverified, and the PR applies it inconsistently.

The module adds 376 lines of a bit-level Sun fdlibm exp/pow port. It assumes MATLAB's elementwise exp and .^ on the CI platforms return fdlibm results. No MATLAB run backs that up (the PR body says "MATLAB was not run here"). The expected hex values in tests/test_linspace.py for gauss and the log-spaced widths come from this same code, so the tests can't show that it matches MATLAB.

The PR also only uses it in two places. The other MATLAB exp(linspace(...)) grids this PR touches still call np.exp:

  • fdr.py:57
  • timefreq.py:231 (log freqscale)
  • dftfilt2.py:63, dftfilt3.py:118 (log cycles)
  • erpimage_engine._gauss (erpimage_engine.py:2230), the private copy of gauss that erpimage_engine.py's docstring says tests pin to miscfunc.gauss

So if the premise holds, those grids still differ from MATLAB. If it doesn't hold, gauss and tf_cycle_calc were moved away from correct results.

Fix: split the fdlibm change into its own PR. Get it accepted only after the EEGLAB reference workflow shows that gauss/tf_cycle_calc match MATLAB bit-for-bit with this module and don't match with np.exp/np.power. Then apply it to every exp(linspace) site, or document why some sites are left out. Until then, keep np.exp and 10.0 ** linspace(...) here and in gauss.py.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MATLAB R2025b Update 7 on jamming matches these two sites bit for bit: gauss(7, 0.3)(5) is 0x1.fae7cfd2b9cfep-1 and logspace(log10(3), log10(8), 7)(6) is 0x1.b2c91e6a9e540p+2 (num2hex 401b2c91e6a9e540). The previous numpy.exp / 10.0 ** linspace path differed in the last bit (0x1.fae7cfd2b9cfdp-1 and 0x1.b2c91e6a9e53fp+2). I am leaving ieee754.py in this PR on that evidence. Applying the same exp/pow to the remaining grids, including erpimage_engine._gauss, can be a follow-up; the current pin is allclose rtol=1e-13 and still passes.

Copy link
Copy Markdown
Member Author

Jamming reran the previous pr602 suite at 2418d44 (MATLAB R2025b Update 7, matlabengine 25.2.2).

All tests passed: tests/test_linspace.py (16), the five timefreq tests, test_reference_gauss, test_reference_envtopo_original_sample, and topoplot/erpimage/fdr (365).

MATLAB num2hex and Python agreed bit for bit on every requested value, including:

  • logspace(log10(3), log10(8), 7)(6) = 0x1.b2c91e6a9e540p+2 (num2hex 401b2c91e6a9e540)
  • gauss(7, 0.3)(5) = 0x1.fae7cfd2b9cfep-1 (num2hex 3fefae7cfd2b9cfe)
  • EEG.times(6), timefreq freqs(4), linspace(1, 5, 6)(4), and envtopo times(56)*1000

The 03:04 PT review asked to drop ieee754.py because those hex values had no MATLAB evidence. This run supplies that evidence. Removing the fdlibm exp/pow port would restore the previous mismatch (numpy logspace was 0x1.b2c91e6a9e53fp+2 and numpy gauss was 0x1.fae7cfd2b9cfdp-1).

A large timefreq call (1x2048, 40 frequencies, winsize 256) was 1.01x the previous numpy.exp path (median 78.6 ms vs 78.0 ms). Isolated gauss on 1e6 samples is much slower because fdlibm exp walks scalars in Python (about 1.94 s vs 6.4 ms). That cost does not show up in ordinary timefreq window sizes.

Other exp(linspace) sites that still use np.exp, including erpimage_engine._gauss, can be a follow-up. The existing pin between _gauss and miscfunc.gauss is allclose rtol=1e-13, and that test still passes. The topoplot head-circle point count is left as it is. The dftfilt3 import spacing is a nit.

Copy link
Copy Markdown
Member Author

CI is red on Python 3.12 macos and windows (ubuntu still running). I am holding the merge.

tests/test_fuzz_events.py::test_original_draws_match_the_golden_snapshot and test_original_draws_do_not_depend_on_import_order fail with AssertionError: pop_reref. The Hypothesis draws for pop_reref no longer match tests/fuzz/golden_draws_20261012.json.

Jamming MATLAB R2025b Update 7 at 2418d44 was clean and bit-for-bit on the linspace/logspace/gauss/envtopo/timefreq checks, and the requested test suite passed. I am not re-recording the golden draws. This mismatch needs a look before merge.

cursoragent and others added 3 commits November 18, 2026 14:42
Bring in the fuzz-draw independence fix so the golden tests can pass
without changing the recorded draws.

Co-authored-by: Suraj Ranganath <[email protected]>
Apple libm rounds this complex exponential one ULP above MATLAB.
Sun fdlibm sin and cos keep the phase and its Hanning taper on the
recorded bit on every platform.

Co-authored-by: Suraj Ranganath <[email protected]>
Bring in the headless spectrum summaries and the pAMICA thread-count fix.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 18, 2026 16:28
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 18, 2026 16:29
@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 1m 9s —— View job


Code review

  • Overall assessment: Needs changes. This review covers what changed since the 11:04 review: 34bd4ce (fdlibm exp over the whole window), 42ad014 (fuzz constant pool), d1cf602 (fdlibm sin/cos in dftfilt) and the develop merges. Your MATLAB R2025b run at 2418d44 addresses the earlier gauss and logspace concern, and I'm withdrawing my request to drop ieee754.py. The earlier items are still fixed: hist2 widens constant data, matlab_colon lives in miscfunc, and the dead erpimage guards are gone.
  • Highest-risk area: the fdlibm sin/cos in dftfilt (d1cf602). It landed after the MATLAB run, so no MATLAB result backs it.
  • Merge recommendation: Needs changes.

Blocking

  • The PR body has no MATLAB reference result. It still says "MATLAB was not run here." The run in your 11:13 comment was a selected set of tests at 2418d44, not the reference suite at the current head 9b70246. AGENTS.md §Testing says the run goes in the PR description: "the exact command or workflow run, the EEGLAB and eeglab_tests commits, pass/fail/skip counts, runtime."
    Fix: run .github/workflows/eeglab-reference.yml, or the local --eeglab-backend=matlab suite, on 9b70246 and paste the results into the PR body.

Important

  • The dftfilt sin/cos change has no MATLAB result (src/eegprep/functions/timefreqfunc/dftfilt.py:26-29, ieee754.py sin/cos, +420 lines). The commit message says Apple libm is "one ULP above MATLAB." But the expected values in test_dftfilt_phase_matches_matlab_linspace (0x1.3ad4403949ff0p-1) and in test_sin_and_cos_match_fdlibm_bits (0x1.fd712f9a817c0p-1, -0x1.7c7d7a833bec2p-1, -0x1.af4718c2d6a84p-7) cite no MATLAB num2hex output. If they came from this port, the tests can't catch a wrong premise.
    Fix: with the reference run, record MATLAB num2hex for imag(dftfilt(10,1,1,1,0))(4,1) and for those sin/cos inputs. Put those values in the PR body, or cite them in the test docstrings.
  • There are now two symmetric_hanning copies that give different results (dftfilt.py:12-17, inline comment posted). The dftfilt copy uses fdlibm cos. The original in dftfilt3.symmetric_hanning still uses np.cos, and timefreq, dftfilt2 and dftfilt3 call it. Both copies stand for MATLAB's hanning. Fix: keep one helper. Either move it to fdlibm everywhere, or keep np.cos in dftfilt until the follow-up.

Nits

  • src/eegprep/functions/timefreqfunc/dftfilt3.py:9-11: the stray blank line between two eegprep.functions.miscfunc imports is still there.

Test gaps

  • Tests is still queued for 9b70246, so I can't tell whether 42ad014 fixed the test_fuzz_events.py golden-draw failure (pop_reref) you reported at 11:31. Check that run before merging. Don't re-record tests/fuzz/golden_draws_20261012.json to make it pass.

EEGLAB parity notes

  • Your follow-up list should also include the complex wavelets in dftfilt2 (np.exp(2j*...), line 36) and dftfilt3 (line 70). They are the same exp(i*phase) construction that dftfilt now evaluates with fdlibm, plus the np.exp(linspace(...)) sites you already listed (fdr, timefreq log scale, the dftfilt2/3 log cycles, erpimage_engine._gauss).
  • The changelog sentence now says both "the dftfilt phase grid … follow the same rule" and "dftfilt evaluates its phase … with fdlibm sin and cos". Merge the two dftfilt mentions.

I didn't run tests or MATLAB in this job. The vendored src/eegprep/eeglab/ isn't in this checkout, so the parity notes rely on the EEGLAB expressions quoted in the code rather than the .m source.

Comment on lines +12 to +17
def _symmetric_hanning(n: int) -> np.ndarray:
if n % 2 == 0:
half = 0.5 * (1.0 - cos(2.0 * np.pi * np.arange(1, n // 2 + 1) / (n + 1)))
return np.concatenate([half, half[::-1]])
half = 0.5 * (1.0 - cos(2.0 * np.pi * np.arange(1, (n + 1) // 2 + 1) / (n + 1)))
return np.concatenate([half, half[-2::-1]])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: this copies symmetric_hanning, and the two copies now give different results. This is dftfilt3.symmetric_hanning (dftfilt3.py#L96-L105) with np.cos replaced by fdlibm cos. Both stand for the same MATLAB hanning, but they can now differ in the last bit. timefreq (timefreq.py:362), dftfilt2 and dftfilt3 still use the np.cos copy. AGENTS.md lists "Parallel implementations of existing helpers" as a failure pattern.

Fix: keep one helper. Switch dftfilt3.symmetric_hanning to ieee754.cos and import it here. That also moves the timefreq/dftfilt2/dftfilt3 tapers onto fdlibm, so those three need the same MATLAB check as dftfilt. If that check can't happen in this PR, keep np.cos in dftfilt for now and change all four together in the fdlibm follow-up.

Argument reduction and the polynomial kernels run on arrays. Values past
the medium cutoff stay on the scalar port, and dftfilt evaluates one phase
grid per call.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath merged commit 8289770 into develop Nov 18, 2026
12 checks passed
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.

Replace remaining np.linspace call sites with miscfunc.linspace where MATLAB parity matters

2 participants