-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add fft/base/fftpack/rffti
#11467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gunjjoshi
wants to merge
2
commits into
stdlib-js:develop
Choose a base branch
from
gunjjoshi:rffti-v2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
lib/node_modules/@stdlib/fft/base/fftpack/rffti/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| <!-- | ||
|
|
||
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2026 The Stdlib Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| --> | ||
|
|
||
| # rffti | ||
|
|
||
| > Initialize a workspace array for performing a real-valued Fourier transform. | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- Package usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var rffti = require( '@stdlib/fft/base/fftpack/rffti' ); | ||
| ``` | ||
|
|
||
| #### rffti( N, workspace, strideW, offsetW ) | ||
|
|
||
| Initializes a workspace array for performing a real-valued Fourier transform. | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
|
|
||
| var N = 8; | ||
| var workspace = new Float64Array( ( 2*N ) + 34 ); | ||
|
|
||
| rffti( N, workspace, 1, 0 ); | ||
|
|
||
| var twiddleFactors = workspace.slice( N, 2*N ); | ||
| // returns <Float64Array>[ 0, ~0.707, ~0.707, 0, 0, 0, 0, 0 ] | ||
|
|
||
| var factors = workspace.slice( 2*N, ( 2*N ) + 4 ); | ||
| // returns <Float64Array>[ 8, 2, 2, 4 ] | ||
| ``` | ||
|
|
||
| The function accepts the following arguments: | ||
|
|
||
| - **N**: length of the sequence to transform. | ||
| - **workspace**: workspace array. | ||
| - **strideW**: stride length for `workspace`. | ||
| - **offsetW**: starting index for `workspace`. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - The workspace array is divided into three sections: | ||
|
|
||
| ```text | ||
| size = N N 2+ceil(log2(N)/2) | ||
| ↓ ↓ ↓ | ||
| | scratch / workspace | twiddle factors | radix factor table | | ||
| ↑ ↑ ↑ | ||
| i = 0 ... N ... 2N ... | ||
| ``` | ||
|
|
||
| - **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 sequence length `N`, the number of factors into which `N` was decomposed, and the individual integer radix factors. | ||
|
|
||
| - In general, a workspace array should have `2N + 34` indexed elements (as `log2(N)/2 ≤ 32` for all `2^64`). During initialization, only the sections for storing twiddle factors and the factorization of `N` are updated. | ||
|
|
||
| - The radix factor table is comprised as follows: | ||
|
|
||
| ```text | ||
| | sequence_length | number_of_factors | integer_factors | | ||
| ``` | ||
|
|
||
| - If `N` equals `1`, the function returns early without modifying the workspace, as a single data point is its own Fourier transform. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var rffti = require( '@stdlib/fft/base/fftpack/rffti' ); | ||
|
|
||
| var workspace; | ||
| var N; | ||
| var nf; | ||
| var i; | ||
| var j; | ||
|
|
||
| N = 8; | ||
| workspace = new Float64Array( ( 2*N ) + 34 ); | ||
|
|
||
| rffti( N, workspace, 1, 0 ); | ||
|
|
||
| console.log( 'Sequence length: %d', N ); | ||
| console.log( 'Twiddle factors:' ); | ||
| for ( i = N; i < 2*N; i++ ) { | ||
| console.log( ' workspace[%d] = %d', i, workspace[ i ] ); | ||
| } | ||
|
|
||
| console.log( 'Factorization:' ); | ||
| nf = workspace[ ( 2*N ) + 1 ]; | ||
| console.log( ' number of factors: %d', nf ); | ||
| for ( j = 0; j < nf; j++ ) { | ||
| console.log( ' factor[%d]: %d', j, workspace[ ( 2*N ) + 2 + j ] ); | ||
| } | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="references"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.references --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
101 changes: 101 additions & 0 deletions
101
lib/node_modules/@stdlib/fft/base/fftpack/rffti/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var rffti = require( './../lib' ); | ||
|
|
||
|
|
||
| // FUNCTIONS // | ||
|
|
||
| /** | ||
| * Creates a benchmark function. | ||
| * | ||
| * @private | ||
| * @param {PositiveInteger} N - sequence length | ||
| * @returns {Function} benchmark function | ||
| */ | ||
| function createBenchmark( N ) { | ||
| var workspace = new Float64Array( ( 2*N ) + 34 ); | ||
| return benchmark; | ||
|
|
||
| /** | ||
| * Benchmark function. | ||
| * | ||
| * @private | ||
| * @param {Benchmark} b - benchmark instance | ||
| */ | ||
| function benchmark( b ) { | ||
| var i; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| rffti( N, workspace, 1, 0 ); | ||
| if ( isnan( workspace[ N+1 ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( workspace[ N+1 ] ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Main execution sequence. | ||
| * | ||
| * @private | ||
| */ | ||
| function main() { | ||
| var lengths; | ||
| var N; | ||
| var f; | ||
| var i; | ||
|
|
||
| lengths = [ | ||
| 8, | ||
| 16, | ||
| 32, | ||
| 64, | ||
| 128, | ||
| 256, | ||
| 512, | ||
| 1024 | ||
| ]; | ||
|
|
||
| for ( i = 0; i < lengths.length; i++ ) { | ||
| N = lengths[ i ]; | ||
| f = createBenchmark( N ); | ||
| bench( format( '%s:N=%d', pkg, N ), f ); | ||
| } | ||
| } | ||
|
|
||
| main(); |
45 changes: 45 additions & 0 deletions
45
lib/node_modules/@stdlib/fft/base/fftpack/rffti/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| {{alias}}( N, workspace, strideW, offsetW ) | ||||||||||||||||||||||
| Initializes a workspace array for performing a real-valued Fourier | ||||||||||||||||||||||
| transform. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The workspace array is divided into three sections: scratch/workspace | ||||||||||||||||||||||
| (indices 0 to N-1), twiddle factors (indices N to 2N-1), and radix factor | ||||||||||||||||||||||
| table (indices 2N onwards). | ||||||||||||||||||||||
|
Comment on lines
+6
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The scratch/workspace section is used while performing transforms and is | ||||||||||||||||||||||
| not updated during initialization. The twiddle factors section stores a | ||||||||||||||||||||||
| table of reusable complex exponential constants as cosine/sine pairs. The | ||||||||||||||||||||||
| radix factor table stores the sequence length N, the number of factors into | ||||||||||||||||||||||
| which N was decomposed, and the individual integer radix factors. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Any remaining array space remains as unused storage. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||
| N: integer | ||||||||||||||||||||||
| Length of the sequence. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| workspace: ArrayLikeObject<number> | ||||||||||||||||||||||
| Workspace array. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| strideW: integer | ||||||||||||||||||||||
| Stride length for `workspace`. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| offsetW: integer | ||||||||||||||||||||||
| Starting index for `workspace`. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Examples | ||||||||||||||||||||||
| -------- | ||||||||||||||||||||||
| > var {{alias:@stdlib/array/float64}} = require( '@stdlib/array/float64' ); | ||||||||||||||||||||||
| > var N = 8; | ||||||||||||||||||||||
| > var workspace = new {{alias:@stdlib/array/float64}}( ( 2*N ) + 34 ); | ||||||||||||||||||||||
| > {{alias}}( N, workspace, 1, 0 ); | ||||||||||||||||||||||
| > var twiddleFactors = workspace.slice( N, 2*N ) | ||||||||||||||||||||||
| <Float64Array>[ 0, ~0.707, ~0.707, 0, 0, 0, 0, 0 ] | ||||||||||||||||||||||
| > var factors = workspace.slice( 2*N, ( 2*N ) + 4 ) | ||||||||||||||||||||||
| <Float64Array>[ 8, 2, 2, 4 ] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| See Also | ||||||||||||||||||||||
| -------- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
51 changes: 51 additions & 0 deletions
51
lib/node_modules/@stdlib/fft/base/fftpack/rffti/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| import { Collection } from '@stdlib/types/array'; | ||
|
|
||
| /** | ||
| * Initializes a workspace array for performing a real-valued Fourier transform. | ||
| * | ||
| * @param N - length of the sequence | ||
| * @param workspace - workspace array | ||
| * @param strideW - stride length for `workspace` | ||
| * @param offsetW - starting index for `workspace` | ||
| * | ||
| * @example | ||
| * var Float64Array = require( '@stdlib/array/float64' ); | ||
| * var N = 8; | ||
| * var workspace = new Float64Array( ( 2*N ) + 34 ); | ||
| * | ||
| * rffti( N, workspace, 1, 0 ); | ||
| * | ||
| * var twiddleFactors = workspace.slice( N, 2*N ); | ||
| * // returns <Float64Array>[ 0, ~0.707, ~0.707, 0, 0, 0, 0, 0 ] | ||
| * | ||
| * var factors = workspace.slice( 2*N, ( 2*N ) + 4 ); | ||
| * // returns <Float64Array>[ 8, 2, 2, 4 ] | ||
| */ | ||
| declare function rffti( N: number, workspace: Collection<number>, strideW: number, offsetW: number ): void; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = rffti; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may also apply to your example file.