Repository navigation
feat: add fft/base/fftpack/ndarray/generic/cffti
#13663
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f52267
feat: add fft/base/fftpack/ndarray/cffti
gunjjoshi 687ed41
Merge branch 'develop' into ndarray/cffti
gunjjoshi 11673ea
docs: rename workspace to w
gunjjoshi 157b946
Merge branch 'develop' into ndarray/cffti
gunjjoshi 1ad5515
test: use integers
gunjjoshi f9fcca2
test: use Float64Array
gunjjoshi ac4c5d8
bench: update benchmark
gunjjoshi 9d6cad7
docs: update docs
gunjjoshi dfcba7f
Merge branch 'develop' into ndarray/cffti
gunjjoshi 77f271d
chore: migrate to fft/base/fftpack/ndarray/generic namespace
gunjjoshi a4d30f6
Merge branch 'develop' into ndarray/cffti
gunjjoshi d38be0c
Merge branch 'develop' into ndarray/cffti
gunjjoshi 1ba5b0a
Merge branch 'develop' into ndarray/cffti
gunjjoshi 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
133 changes: 133 additions & 0 deletions
133
lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/cffti/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,133 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # cffti | ||
|
|
||
| > Initialize a workspace array for performing a complex-valued Fourier transform on a one-dimensional ndarray. | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var cffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/cffti' ); | ||
| ``` | ||
|
|
||
| #### cffti( arrays ) | ||
|
|
||
| Initializes a workspace array for performing a complex-valued Fourier transform on a one-dimensional ndarray. | ||
|
|
||
| ```javascript | ||
| var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); | ||
| var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); | ||
| var Slice = require( '@stdlib/slice/ctor' ); | ||
| var slice = require( '@stdlib/ndarray/slice' ); | ||
|
|
||
| var N = 8; | ||
| var len = scalar2ndarray( N, { | ||
| 'dtype': 'int32' | ||
| }); | ||
|
|
||
| var w = new Float64Vector( ( 4*N ) + 34 ); | ||
|
|
||
| var out = cffti( [ w, len ] ); | ||
| // returns <ndarray> | ||
|
|
||
| var bool = ( out === w ); | ||
| // returns true | ||
|
|
||
| var twiddleFactors = slice( w, new Slice( 2*N, 4*N ) ); | ||
| // returns <ndarray>[ 1, 0, ~0.707, ~0.707, ~0, 1, ~-0.707, ~0.707, 1, 0, 1, 0, 1, 0, ~0, -1 ] | ||
|
|
||
| var factors = slice( w, new Slice( 4*N, ( 4*N ) + 4 ) ); | ||
| // returns <ndarray>[ 8, 2, 2, 4 ] | ||
| ``` | ||
|
|
||
| The function has the following parameters: | ||
|
|
||
| - **arrays**: array-like object containing the following ndarrays: | ||
|
|
||
| - a one-dimensional input ndarray. | ||
| - a zero-dimensional ndarray containing the length of the sequence to transform. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - If provided an empty one-dimensional input ndarray, the function returns the input ndarray unchanged. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); | ||
| var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); | ||
| var ndarray2array = require( '@stdlib/ndarray/to-array' ); | ||
| var cffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/cffti' ); | ||
|
|
||
| var N = 8; | ||
|
|
||
| var w = new Float64Vector( ( 4*N ) + 34 ); | ||
| console.log( ndarray2array( w ) ); | ||
|
|
||
| var len = scalar2ndarray( N, { | ||
| 'dtype': 'int32' | ||
| }); | ||
|
|
||
| var out = cffti( [ w, len ] ); | ||
| console.log( ndarray2array( out ) ); | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- 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 --> | ||
118 changes: 118 additions & 0 deletions
118
lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/cffti/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,118 @@ | ||
| /** | ||
| * @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 zeros = require( '@stdlib/ndarray/zeros' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var cffti = require( './../lib' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var options = { | ||
| 'dtype': 'generic' | ||
| }; | ||
| var nopts = { | ||
| 'dtype': 'int32' | ||
| }; | ||
|
|
||
|
|
||
| // FUNCTIONS // | ||
|
|
||
| /** | ||
| * Creates a benchmark function. | ||
| * | ||
| * @private | ||
| * @param {PositiveInteger} N - sequence length | ||
| * @returns {Function} benchmark function | ||
| */ | ||
| function createBenchmark( N ) { | ||
| var len; | ||
| var w; | ||
|
|
||
| len = scalar2ndarray( N, nopts ); | ||
| w = zeros( [ ( 4*N ) + 34 ], options ); | ||
|
|
||
| return benchmark; | ||
|
|
||
| /** | ||
| * Benchmark function. | ||
| * | ||
| * @private | ||
| * @param {Benchmark} b - benchmark instance | ||
| */ | ||
| function benchmark( b ) { | ||
| var v; | ||
| var i; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| v = cffti( [ w, len ] ); | ||
| if ( typeof v !== 'object' ) { | ||
| b.fail( 'should return an ndarray' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( v.get( 2*N ) ) ) { | ||
| 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(); |
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/cffti/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,42 @@ | ||
|
|
||
| {{alias}}( arrays ) | ||
| Initializes a workspace array for performing a complex-valued Fourier | ||
| transform on a one-dimensional ndarray. | ||
|
|
||
| If provided an empty input ndarray, the function returns the input ndarray | ||
| unchanged. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| arrays: ArrayLikeObject<ndarray> | ||
| Array-like object containing the following ndarrays: | ||
|
|
||
| - a one-dimensional input ndarray. | ||
| - a zero-dimensional ndarray containing the length of the sequence to | ||
| transform. | ||
|
|
||
| Returns | ||
| ------- | ||
| out: ndarray | ||
| Input ndarray. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var N = 8; | ||
| > var w = new {{alias:@stdlib/ndarray/vector/float64}}( ( 4*N ) + 34 ); | ||
| > var opts = { 'dtype': 'int32' }; | ||
| > var len = {{alias:@stdlib/ndarray/from-scalar}}( N, opts ); | ||
| > var out = {{alias}}( [ w, len ] ) | ||
| <ndarray> | ||
| > var bool = ( out === w ) | ||
| true | ||
| > var s = new {{alias:@stdlib/slice/ctor}}( 2*N, 4*N ); | ||
| > var twiddleFactors = {{alias:@stdlib/ndarray/slice}}( w, s ) | ||
| <ndarray> | ||
| > s = new {{alias:@stdlib/slice/ctor}}( 4*N, ( 4*N ) + 4 ); | ||
| > var factors = {{alias:@stdlib/ndarray/slice}}( w, s ) | ||
| <ndarray>[ 8, 2, 2, 4 ] | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
73 changes: 73 additions & 0 deletions
73
lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/cffti/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,73 @@ | ||
| /* | ||
| * @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 { typedndarray, floatndarray, genericndarray } from '@stdlib/types/ndarray'; | ||
|
|
||
| /** | ||
| * Input array. | ||
| */ | ||
| type InputArray = floatndarray | genericndarray<number>; | ||
|
|
||
| /** | ||
| * Initializes a workspace array for performing a complex-valued Fourier transform on a one-dimensional ndarray. | ||
| * | ||
| * ## Notes | ||
| * | ||
| * - The function expects the following ndarrays: | ||
| * | ||
| * - a one-dimensional input ndarray. | ||
| * - a zero-dimensional ndarray containing the length of the sequence to transform. | ||
| * | ||
| * @param arrays - array-like object containing ndarrays | ||
| * @returns input ndarray | ||
| * | ||
| * @example | ||
| * var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); | ||
| * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); | ||
| * var Slice = require( '@stdlib/slice/ctor' ); | ||
| * var slice = require( '@stdlib/ndarray/slice' ); | ||
| * | ||
| * var N = 8; | ||
| * var len = scalar2ndarray( N, { | ||
| * 'dtype': 'int32' | ||
| * }); | ||
| * | ||
| * var w = new Float64Vector( ( 4*N ) + 34 ); | ||
| * | ||
| * var out = cffti( [ w, len ] ); | ||
| * // returns <ndarray> | ||
| * | ||
| * var bool = ( out === w ); | ||
| * // returns true | ||
| * | ||
| * var twiddleFactors = slice( w, new Slice( 2*N, 4*N ) ); | ||
| * // returns <ndarray>[ 1, 0, ~0.707, ~0.707, ~0, 1, ~-0.707, ~0.707, 1, 0, 1, 0, 1, 0, ~0, -1 ] | ||
| * | ||
| * var factors = slice( w, new Slice( 4*N, ( 4*N ) + 4 ) ); | ||
| * // returns <ndarray>[ 8, 2, 2, 4 ] | ||
| */ | ||
| declare function cffti<T extends InputArray = InputArray>( arrays: [ T, typedndarray<number> ] ): T; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = cffti; |
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.
@gunjjoshi I think we want to include the extended notes from the strided implementations in the ndarray wrappers: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fft/base/fftpack/generic/cffti#notes.
Mind submitting a follow-up PR in which you add those to
ndarray/(c|r)ffti? Otherwise, the example above is somewhat cryptic, as a user needs to know to look at the strided docs to understand the workspace regions.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.
Sure, I'll add them up in a follow-up PR.