Skip to content

feat: add fft/base/fftpack/float32/rffti - #14591

Merged
kgryte merged 2 commits into
stdlib-js:developfrom
gunjjoshi:float32-rffti
Aug 25, 2026
Merged

kgryte merged 2 commits into
stdlib-js:developfrom
gunjjoshi:float32-rffti

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#1215.

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 Claude Code to review my implementation and to do some R&D.


@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 August 24, 2026 14:09
@gunjjoshi gunjjoshi added the METR Pull request associated with the METR project. label Aug 24, 2026
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 24, 2026
@stdlib-bot

stdlib-bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
fft/base/fftpack/float32/rffti $\\color{green}414/414$
$\\color{green}+0.00\\%$
$\\color{green}12/12$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}414/414$
$\\color{green}+0.00\\%$

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

# @param {(string|void)} fPIC - flag indicating whether to generate position independent code
#/
$(c_targets): %.out: %.c
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $(FFTPACK_SRC) $< -lm

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for flagging.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. and removed Needs Review A pull request which needs code review. labels Aug 25, 2026
In FFTPACK, they reinterpret the workspace memory as an `int` array. As a consequence, we should emulate integer ops, not float ops. In this case, this just means floor division.

Signed-off-by: Athan <kgryte@gmail.com>

@kgryte kgryte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Removed some of the float32 emulation after looking at the reference implementation. In particular, FFTPACK reinterprets real memory as int and then performs integer ops, not float ops. So, in order to avoid accuracy issues once exceeding the maximum safe float32 integer, I removed various f32 wrapper calls and already updated float32/decompose, as well.

We could, in principle, exactly mimic their logic. Nothing is stopping us from creating a new, say, Int32Array view over the underlying buffer, but I am fine keeping as is, for now.

It is possible that users will want to compute an FFT having more than 16.7M elements

In [42]: FLOAT32_MAX_SAFE_INTEGER
Out[42]: 16777215

but we will cross that bridge when we get there, as things get a bit messy if you need to support int64 arrays (which I don't think we do (!), as surely even the largest practical sequence length will have less than 2^31-1 factors). And given that factors would be written as int32 and not float, it would make fixture and example logic more complicated. But this is also doable, as would require creating an int32 array view to reinterpret raw memory.

We should discuss more during our next sync.

@kgryte
kgryte merged commit 91248c1 into stdlib-js:develop Aug 25, 2026
13 checks passed
@kgryte
kgryte deleted the float32-rffti branch August 25, 2026 08:59
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add fft/base/fftpack/float32/rffti

3 participants