Skip to content

Fix coefficients with one-shot iterators - #42690

Open
OutisNemosseus wants to merge 2 commits into
sagemath:developfrom
OutisNemosseus:modform-iterator-fix
Open

Fix coefficients with one-shot iterators#42690
OutisNemosseus wants to merge 2 commits into
sagemath:developfrom
OutisNemosseus:modform-iterator-fix

Conversation

@OutisNemosseus

Copy link
Copy Markdown

Description

ModularForm_abstract.coefficients() traversed its index iterable while computing missing coefficients and then traversed it again when constructing the return value. A one-shot iterator was therefore exhausted before the result was assembled, causing calls with generators to return an empty list.

This change materializes non-integer iterables once before coefficient computation. It preserves the requested index order and duplicate indices.

A doctest using a genuine generator with indices [3, 1, 3, 2] verifies the expected result [252, 1, 252, -24].

Testing

  • git diff --check
  • Functional smoke test using the modified worktree source
  • Verified list, tuple, range, range iterator, and generator inputs
  • Verified preservation of order and duplicate indices

The full source-tree doctest runner was not available in the local conda Sage installation, so the focused Sage doctest was not collected locally.

@github-actions

Copy link
Copy Markdown

Documentation preview for this PR (built with commit 7b1673b; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@OutisNemosseus
OutisNemosseus marked this pull request as ready for review August 23, 2026 03:29
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.

2 participants