-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add fft/base/fftpack/decompose
#10354
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
18 commits
Select commit
Hold shift + click to select a range
a467beb
feat: add fft/base/fftpack/decompose
gunjjoshi c765d85
Merge branch 'decompose' of https://github.com/gunjjoshi/stdlib into …
gunjjoshi bc155d6
refactor: use array instead of collection
gunjjoshi 0cfac28
refactor: use slice method
gunjjoshi 7e5e613
refcator: use Collection instead of Array
gunjjoshi c9037e0
refactor: add M as a parameter
gunjjoshi 93ffa30
docs: update notes
gunjjoshi 4308548
refactor: change stride and offset parameter names
gunjjoshi 83619cf
refactor: replace number with integer
gunjjoshi 6dfe177
refactor: replace primes package by hardcoded array
gunjjoshi 17d1f10
refactor: use collection for initial array
gunjjoshi cf1733b
docs: update comments
kgryte 1060d0f
Apply suggestions from code review
kgryte be4f46c
Apply suggestions from code review
kgryte b861a21
Apply suggestions from code review
kgryte df60db6
Apply suggestions from code review
kgryte 547a516
Apply suggestions from code review
kgryte 269e284
test: update messages and make test more robust
kgryte 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
142 changes: 142 additions & 0 deletions
142
lib/node_modules/@stdlib/fft/base/fftpack/decompose/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,142 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # decompose | ||
|
|
||
| > Factorize a sequence length into a product of integers. | ||
|
|
||
| <!-- 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 decompose = require( '@stdlib/fft/base/fftpack/decompose' ); | ||
| ``` | ||
|
|
||
| #### decompose( N, M, initial, si, oi, out, so, oo ) | ||
|
|
||
| Factorizes a sequence length into a product of integers. | ||
|
|
||
| ```javascript | ||
| var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK | ||
| var N = 630; | ||
| var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; | ||
|
|
||
| var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); | ||
| // returns 5 | ||
|
|
||
| console.log( factors ); | ||
| // => [ 630, 5, 2, 3, 3, 5, 7 ] | ||
| ``` | ||
|
|
||
| The function accepts the following arguments: | ||
|
|
||
| - **N**: length of the sequence. | ||
| - **M**: number of trial divisors. | ||
| - **initial**: array of initial trial divisors. | ||
| - **si**: stride length for `initial`. | ||
| - **oi**: starting index for `initial`. | ||
| - **out**: output array for storing factorization results. | ||
| - **so**: stride length for `out`. | ||
| - **oo**: starting index for `out`. | ||
|
|
||
| The function returns the number of factors into which `N` was decomposed. | ||
|
|
||
| </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 | ||
|
|
||
| - Factorization results are stored in the output array as follows: | ||
|
|
||
| ```text | ||
| [ sequence_length | number_of_factors | integer_factors | unused_storage ] | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); | ||
|
|
||
| var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK | ||
| var factors = [ 0, 0, 0, 0 ]; | ||
|
|
||
| var nf = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); | ||
|
|
||
| console.log( 'Sequence length: %d', 12 ); | ||
| console.log( 'Number of factors: %d', nf ); | ||
|
|
||
| console.log( 'Factors:' ); | ||
| var j; | ||
| for ( j = 0; j < nf; j++ ) { | ||
| console.log( ' %d', factors[ j+2 ] ); | ||
| } | ||
| ``` | ||
|
|
||
| </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 --> | ||
107 changes: 107 additions & 0 deletions
107
lib/node_modules/@stdlib/fft/base/fftpack/decompose/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,107 @@ | ||
| /* | ||
| * @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 floor = require( '@stdlib/math/base/special/floor' ); | ||
| var log2 = require( '@stdlib/math/base/special/log2' ); | ||
| var zeros = require( '@stdlib/array/zeros' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var decompose = require( './../lib' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK | ||
|
|
||
|
|
||
| // FUNCTIONS // | ||
|
|
||
| /** | ||
| * Creates a benchmark function. | ||
| * | ||
| * @private | ||
| * @param {PositiveInteger} N - sequence length | ||
| * @returns {Function} benchmark function | ||
| */ | ||
| function createBenchmark( N ) { | ||
| var factors = zeros( 2 + floor( log2( N ) ) ); | ||
| return benchmark; | ||
|
|
||
| /** | ||
| * Benchmark function. | ||
| * | ||
| * @private | ||
| * @param {Benchmark} b - benchmark instance | ||
| */ | ||
| function benchmark( b ) { | ||
| var d; | ||
| var i; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| d = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); | ||
| if ( isnan( d ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( d ) ) { | ||
| 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 = [ | ||
| 12, | ||
| 24, | ||
| 36, | ||
| 48, | ||
| 60, | ||
| 120 | ||
| ]; | ||
|
|
||
| for ( i = 0; i < lengths.length; i++ ) { | ||
| N = lengths[ i ]; | ||
| f = createBenchmark( N ); | ||
| bench( format( '%s:N=%d', pkg, N ), f ); | ||
| } | ||
| } | ||
|
|
||
| main(); |
55 changes: 55 additions & 0 deletions
55
lib/node_modules/@stdlib/fft/base/fftpack/decompose/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,55 @@ | ||
|
|
||
| {{alias}}( N, M, initial, si, oi, out, so, oo ) | ||
| Factorizes a sequence length into a product of integers. | ||
|
|
||
| Factorization results are stored in the output array sequentially, where | ||
| the first element contains the sequence length N, the second element | ||
| contains the number of factors into which N was decomposed, and subsequent | ||
| elements contain the individual integer factors. | ||
|
|
||
| Any remaining array space remains as unused storage. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| N: integer | ||
| Length of the sequence. | ||
|
|
||
| M: integer | ||
| Number of trial divisors. | ||
|
|
||
| initial: ArrayLikeObject<number> | ||
| Array of initial trial divisors. | ||
|
|
||
| si: integer | ||
| Stride length for `initial`. | ||
|
|
||
| oi: integer | ||
| Starting index for `initial`. | ||
|
|
||
| out: ArrayLikeObject<number> | ||
| Output array for storing factorization results. | ||
|
|
||
| so: integer | ||
| Stride length for `out`. | ||
|
|
||
| oo: integer | ||
| Starting index for `out`. | ||
|
|
||
| Returns | ||
| ------- | ||
| numFactors: integer | ||
| Number of factors into which N was decomposed. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var N = 630; | ||
| > var initial = [ 3, 4, 2, 5 ]; | ||
| > var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; | ||
| > var numFactors = {{alias}}( N, 4, initial, 1, 0, factors, 1, 0 ) | ||
| 5 | ||
| > factors | ||
| [ 630, 5, 2, 3, 3, 5, 7 ] | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
50 changes: 50 additions & 0 deletions
50
lib/node_modules/@stdlib/fft/base/fftpack/decompose/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,50 @@ | ||
| /* | ||
| * @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'; | ||
|
|
||
| /** | ||
| * Factorizes a sequence length into a product of integers. | ||
| * | ||
| * @param N - length of the sequence | ||
| * @param M - number of trial divisors | ||
| * @param initial - array of initial trial divisors | ||
| * @param si - stride length for `initial` | ||
| * @param oi - starting index for `initial` | ||
| * @param out - output array for storing factorization results | ||
| * @param so - stride length for `out` | ||
| * @param oo - starting index for `out` | ||
| * @returns number of factors into which `N` was decomposed | ||
| * | ||
| * @example | ||
| * var initial = new Float64Array( [ 3, 4, 2, 5 ] ); | ||
| * var factors = new Float64Array( 4 ); | ||
| * | ||
| * var numFactors = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); | ||
| * // returns 2 | ||
| */ | ||
| declare function decompose( N: number, M: number, initial: Collection<number>, si: number, oi: number, out: Collection<number>, so: number, oo: number ): number; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = decompose; |
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.
Uh oh!
There was an error while loading. Please reload this page.