Skip to content

feat: add fft/base/fftpack/sinqi#13000

Open
gunjjoshi wants to merge 1 commit into
stdlib-js:developfrom
gunjjoshi:sinqi
Open

feat: add fft/base/fftpack/sinqi#13000
gunjjoshi wants to merge 1 commit into
stdlib-js:developfrom
gunjjoshi:sinqi

Conversation

@gunjjoshi

Copy link
Copy Markdown
Member

type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:

  • task: lint_filenames status: passed
  • task: lint_editorconfig status: passed
  • task: lint_markdown_pkg_readmes status: passed
  • task: lint_markdown_docs status: na
  • task: lint_markdown status: na
  • task: lint_package_json status: passed
  • task: lint_repl_help status: passed
  • task: lint_javascript_src status: passed
  • task: lint_javascript_cli status: na
  • task: lint_javascript_examples status: passed
  • task: lint_javascript_tests status: passed
  • task: lint_javascript_benchmarks status: passed
  • task: lint_python status: na
  • task: lint_r status: na
  • task: lint_c_src status: na
  • task: lint_c_examples status: na
  • task: lint_c_benchmarks status: na
  • task: lint_c_tests_fixtures status: passed
  • task: lint_shell status: na
  • task: lint_typescript_declarations status: passed
  • task: lint_typescript_tests status: passed
  • task: lint_license_headers status: passed ---

Resolves stdlib-js/metr-issue-tracker#868.

Description

What is the purpose of this pull request?

This pull request:

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding
  • Code Review

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

Used Gemini-3.5-Flash for reviewing the code.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: passed
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@gunjjoshi gunjjoshi requested a review from a team June 20, 2026 19:22
@gunjjoshi gunjjoshi added Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. labels Jun 20, 2026
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jun 20, 2026
* var bool = ( out === workspace );
* // returns true
*
* var cosineTable = workspace.slice( 0, N );

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.

Intentionally used the name cosineTable here, same as the one used in fft/base/fftpack/cosqi, since this package simply calls cosqi internally, and initializes the array with cosine values, even for quarter-wave sine transform.

Ref: https://github.com/marton78/pffft/blob/master/src/fftpack.c#L2540

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.

This is the same reason for keeping most of the documentation in this package similar to that in cosqi, since we are calculating cosine values only.

@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
fft/base/fftpack/sinqi $\\color{green}222/222$
$\\color{green}+100.00\\%$
$\\color{green}3/3$
$\\color{green}+100.00\\%$
$\\color{green}1/1$
$\\color{green}+100.00\\%$
$\\color{green}222/222$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

Comment on lines +71 to +128
* ## Notes
*
* The workspace array is divided into four sections:
*
* ```text
* size = N N N 2+ceil(log2(N)/2)
* ↓ ↓ ↓ ↓
* | cosine table | scratch/workspace | twiddle factors | radix factor table |
* ↑ ↑ ↑ ↑
* i = 0 ... N ... 2N ... 3N ...
* ```
*
* where
*
* - **cosine table**: a table of precomputed cosine coefficients used by quarter-wave sine transforms.
* - **scratch/workspace**: used as a scratch space when performing transforms. This section is not updated during initialization.
* - **twiddle factors**: a table of reusable complex-exponential constants stored as cosine/sine pairs.
* - **radix factor table**: a table containing the radix factorization of `N`.
*
* In general, a workspace array should have `3N + 34` indexed elements (as `log2(N)/2 ≤ 32` for all `2^64`). During initialization, only the sections for storing the cosine coefficients, twiddle factors, and the factorization of `N` are updated.
*
* > Note: FFTPACK only requires `3N+15`, but we increase that number here to accommodate larger workspace arrays, where `N` may exceed `2^30` indexed elements.
*
* The factorization section is comprised as follows:
*
* ```text
* | sequence_length | number_of_factors | integer_factors |
* ```
*
* The sequence length and number of factors (`nf`) comprise a single element each. Only the first `nf` elements in the integer factors section are written to, with the rest being unused.
*
* As for twiddle factors, these are small, reusable complex-exponential constants that appear inside each "butterfly" stage of a Cooley–Tukey–style FFT. Every arithmetic step in an FFT multiplies one intermediate value by some
*
* ```tex
* W_N^k
* ```
*
* where `W_N^k` is an N-th root of unity. Formally, in a forward FFT,
*
* ```tex
* W_N^k = e^{-2\pi ik/N}
* ```
*
* In a backward FFT,
*
* ```tex
* W_N^k = e^{+2\pi ik/N}
* ```
*
* As may be observed, `W_N^k` for forward and backward FFTs is the same, except the sign of the exponent is flipped. As a consequence, both forward and backward FFT callers can reuse the same set of twiddle factors, with those performing a forward transform (e.g., `cosqf`) multiplying with `(cos,-sin)` and those performing a backward transform (e.g., `cosqb`) multiplying with `(cos,+sin)`.
*
* Because these constants only depend on the transform length `N` (and **not** on the input data), we can pre-compute and store them once, then "twiddle" them (i.e., reuse them with different indices) as we proceed through the factorization.
*
* > As a quick aside regarding the name "twiddle", early FFT papers (notably Gentleman & Sande, 1966) described how you "twiddle" one branch of each butterfly by a complex rotation before adding/subtracting. The coefficients themselves inherited the nickname "twiddle factors," and the term stuck.
*
* By reusing the workspace array when computing multiple transforms of the same length `N`, every subsequent `*f` (forward) or `*b` (backward) call can simply look up the pre-stored twiddle factors instead of recomputing sine and cosine on-the-fly.
*
* In short, twiddle factors are cached roots of unity that allow each stage of the algorithm to rotate data quickly and predictably.

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.

Even though this file doesn't include any implementation, still I have kept these notes from cosqi. We could exclude them here, but then I thought, that anyone using sinqi would still have to pass an array of size 3N+34, and it would be good to keep this, which explains how different parts of that array are used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add fft/base/fftpack/sinqi

2 participants