From a467beb05b10fec043d200d8afef11fb38f755b4 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 18 Feb 2026 22:47:53 +0530 Subject: [PATCH 01/17] feat: add fft/base/fftpack/decompose --- 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 status: passed - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../fft/base/fftpack/decompose/README.md | 141 +++++++++ .../fftpack/decompose/benchmark/benchmark.js | 107 +++++++ .../fft/base/fftpack/decompose/docs/repl.txt | 46 +++ .../fftpack/decompose/docs/types/index.d.ts | 49 ++++ .../base/fftpack/decompose/docs/types/test.ts | 114 ++++++++ .../base/fftpack/decompose/examples/index.js | 35 +++ .../fft/base/fftpack/decompose/lib/index.js | 60 ++++ .../fft/base/fftpack/decompose/lib/main.js | 206 ++++++++++++++ .../fft/base/fftpack/decompose/package.json | 64 +++++ .../fft/base/fftpack/decompose/test/test.js | 269 ++++++++++++++++++ 10 files changed, 1091 insertions(+) create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/package.json create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md new file mode 100644 index 000000000000..648ad3c34927 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md @@ -0,0 +1,141 @@ + + +# decompose + +> Factorize a sequence length into a product of integers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); +``` + +#### decompose( N, initial, out, stride, offset ) + +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, initial, 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. +- **initial**: array of initial trial divisors. +- **out**: output array for storing factorization results. +- **stride**: stride length for `out`. +- **offset**: starting index for `out`. + +The function returns the number of factors into which `N` was decomposed. + +
+ + + + + +
+ +## Notes + +- Factorization results are stored in the output array as follows: + + ```text + [ sequence_length | number_of_factors | integer_factors | unused_storage ] + ``` + +- The function mutates the input array. + +
+ + + +
+ +## Examples + + + +```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; +var j; + +nf = decompose( 12, initial, factors, 1, 0 ); + +console.log( 'Sequence length: %d', 12 ); +console.log( 'Number of factors: %d', nf ); +console.log( 'Factors:' ); +for ( j = 0; j < nf; j++ ) { + console.log( ' %d', factors[ j+2 ] ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js new file mode 100644 index 000000000000..fec48dff9462 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js @@ -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, initial, 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(); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt new file mode 100644 index 000000000000..42a1641b35e1 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( N, initial, out, stride, offset ) + 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: number + Length of the sequence. + + initial: Array + Array of initial trial divisors. + + out: Collection + Output array for storing factorization results. + + stride: number + Stride length for `out`. + + offset: number + Starting index for `out`. + + Returns + ------- + numFactors: number + 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, initial, factors, 1, 0 ) + 5 + > factors.slice() + [ 630, 5, 2, 3, 3, 5, 7 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts new file mode 100644 index 000000000000..3ab145c3f649 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts @@ -0,0 +1,49 @@ +/* +* @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 + +/// + +/** +* Factorizes a sequence length into a product of integers. +* +* @param N - length of the sequence +* @param initial - array of initial trial divisors +* @param out - output array for storing factorization results +* @param stride - stride length for `out` +* @param offset - starting index for `out` +* @returns number of factors into which `N` was decomposed +* +* @example +* var N = 630; +* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +* var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; +* +* var numFactors = decompose( N, initial, factors, 1, 0 ); +* // returns 5 +* +* var f = factors.slice(); +* // returns [ 630, 5, 2, 3, 3, 5, 7 ] +*/ +declare function decompose( N: number, initial: Array, out: Array, stride: number, offset: number ): number; + + +// EXPORTS // + +export = decompose; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts new file mode 100644 index 000000000000..56f96c79e97c --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts @@ -0,0 +1,114 @@ +/* +* @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. +*/ + +import decompose = require( './index' ); + +// TESTS // + +// The function returns a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, initial, out, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a sequence length which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( '12', initial, out, 1, 0 ); // $ExpectError + decompose( true, initial, out, 1, 0 ); // $ExpectError + decompose( false, initial, out, 1, 0 ); // $ExpectError + decompose( null, initial, out, 1, 0 ); // $ExpectError + decompose( void 0, initial, out, 1, 0 ); // $ExpectError + decompose( [], initial, out, 1, 0 ); // $ExpectError + decompose( {}, initial, out, 1, 0 ); // $ExpectError + decompose( ( x: number ): number => x, initial, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided initial trial divisors which is not an array of numbers... +{ + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, '4,2,3,5', out, 1, 0 ); // $ExpectError + decompose( 12, 5, out, 1, 0 ); // $ExpectError + decompose( 12, true, out, 1, 0 ); // $ExpectError + decompose( 12, false, out, 1, 0 ); // $ExpectError + decompose( 12, null, out, 1, 0 ); // $ExpectError + decompose( 12, void 0, out, 1, 0 ); // $ExpectError + decompose( 12, {}, out, 1, 0 ); // $ExpectError + decompose( 12, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an output array which is not an array-like object... +{ + const initial = [ 3, 4, 2, 5 ]; + + decompose( 12, initial, 123, 1, 0 ); // $ExpectError + decompose( 12, initial, true, 1, 0 ); // $ExpectError + decompose( 12, initial, false, 1, 0 ); // $ExpectError + decompose( 12, initial, null, 1, 0 ); // $ExpectError + decompose( 12, initial, void 0, 1, 0 ); // $ExpectError + decompose( 12, initial, {}, 1, 0 ); // $ExpectError + decompose( 12, initial, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a stride which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, initial, out, '1', 0 ); // $ExpectError + decompose( 12, initial, out, true, 0 ); // $ExpectError + decompose( 12, initial, out, false, 0 ); // $ExpectError + decompose( 12, initial, out, null, 0 ); // $ExpectError + decompose( 12, initial, out, void 0, 0 ); // $ExpectError + decompose( 12, initial, out, [], 0 ); // $ExpectError + decompose( 12, initial, out, {}, 0 ); // $ExpectError + decompose( 12, initial, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an offset which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, initial, out, 1, '0' ); // $ExpectError + decompose( 12, initial, out, 1, true ); // $ExpectError + decompose( 12, initial, out, 1, false ); // $ExpectError + decompose( 12, initial, out, 1, null ); // $ExpectError + decompose( 12, initial, out, 1, void 0 ); // $ExpectError + decompose( 12, initial, out, 1, [] ); // $ExpectError + decompose( 12, initial, out, 1, {} ); // $ExpectError + decompose( 12, initial, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose(); // $ExpectError + decompose( 12 ); // $ExpectError + decompose( 12, initial ); // $ExpectError + decompose( 12, initial, out ); // $ExpectError + decompose( 12, initial, out, 1 ); // $ExpectError + decompose( 12, initial, out, 1, 0, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js new file mode 100644 index 000000000000..052a73cbcf79 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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'; + +var decompose = require( './../lib' ); + +var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +var factors = [ 0, 0, 0, 0 ]; +var nf; +var j; + +nf = decompose( 12, initial, factors, 1, 0 ); + +console.log( 'Sequence length: %d', 12 ); +console.log( 'Number of factors: %d', nf ); +console.log( 'Factors:' ); +for ( j = 0; j < nf; j++ ) { + console.log( ' %d', factors[ j+2 ] ); +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js new file mode 100644 index 000000000000..06fae87ca7a8 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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'; + +/** +* Factorize a sequence length into a product of integers. +* +* @module @stdlib/fft/base/fftpack/decompose +* +* @example +* var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); +* +* var N = 630; +* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +* var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; +* +* var numFactors = decompose( N, initial, factors, 1, 0 ); +* // returns 5 +* +* var f = factors.slice(); +* // returns [ 630, 5, 2, 3, 3, 5, 7 ] +* +* @example +* var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); +* +* var N = 8; +* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +* var factors = [ 0, 0, 0, 0 ]; +* +* var numFactors = decompose( N, initial, factors, 1, 0 ); +* // returns 2 +* +* var f = factors.slice(); +* // returns [ 8, 2, 2, 4 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js new file mode 100644 index 000000000000..dad82708319b --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -0,0 +1,206 @@ +/** +* @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. +* +* +* ## Notice +* +* The original C code and copyright notice are from the [PFFFT library]{@link https://github.com/marton78/pffft/blob/master/fftpack.c}. The implementation follows the original, but has been modified for JavaScript. +* +* ```text +* Copyright (c) 2004 the University Corporation for Atmospheric +* Research ("UCAR"). All rights reserved. Developed by NCAR's +* Computational and Information Systems Laboratory, UCAR, +* www.cisl.ucar.edu. +* +* Redistribution and use of the Software in source and binary forms, +* with or without modification, is permitted provided that the +* following conditions are met: +* +* - Neither the names of NCAR's Computational and Information Systems +* Laboratory, the University Corporation for Atmospheric Research, +* nor the names of its sponsors or contributors may be used to +* endorse or promote products derived from this Software without +* specific prior written permission. +* +* - Redistributions of source code must retain the above copyright +* notices, this list of conditions, and the disclaimer below. +* +* - Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions, and the disclaimer below in the +* documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +* SOFTWARE. +* ``` +*/ + +'use strict'; + +// MODULES // + +var floor = require( '@stdlib/math/base/special/floor' ); +var isInteger = require( '@stdlib/math/base/assert/is-integer' ); +var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var isCollection = require( '@stdlib/assert/is-collection' ); + + +// MAIN // + +/** +* Factorizes a sequence length into a product of integers. +* +* ## Notes +* +* - Factorization results are stored in the input array as follows: +* +* ```text +* [ sequence_length | number_of_factors | integer_factors | unused_storage ] +* ``` +* +* - The function mutates the input array. +* +* @private +* @param {NonNegativeInteger} N - length of the sequence +* @param {NonNegativeIntegerArray} initial - array of initial trial divisors +* @param {Collection} out - output array for storing factorization results +* @param {integer} stride - stride length for `out` +* @param {NonNegativeInteger} offset - starting index for `out` +* @returns {NonNegativeInteger} number of factors into which `N` was decomposed +* +* @example +* var N = 630; +* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +* var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; +* +* var numFactors = decompose( N, initial, factors, 1, 0 ); +* // returns 5 +* +* var f = factors.slice(); +* // returns [ 630, 5, 2, 3, 3, 5, 7 ] +* +* @example +* var N = 8; +* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK +* var factors = [ 0, 0, 0, 0 ]; +* +* var numFactors = decompose( N, initial, factors, 1, 0 ); +* // returns 2 +* +* var f = factors.slice(); +* // returns [ 8, 2, 2, 4 ] +*/ +function decompose( N, initial, out, stride, offset ) { + var divisor; + var ntrials; + var nl; + var nf; + var nq; + var nr; + var ib; + var i; + var j; + + if ( !isNonNegativeInteger( N ) || !isNonNegativeIntegerArray( initial ) || + !isCollection( out ) || !isInteger( stride ) || + !isNonNegativeInteger( offset ) ) { + return NaN; + } + + if ( N === 0 ) { + out[ offset ] = N; + out[ offset+stride ] = 0; + return 0; + } + + // Resolve the number of trial divisors: + ntrials = initial.length; + + // Initialize a variable for storing a trial divisor: + divisor = 0; + + // Initialize a variable for storing a sub-sequence length: + nl = N; + + // Initialize a variable for keeping track of the number of factors into which `N` decomposes: + nf = 0; + + j = 0; + do { + if ( j < ntrials ) { + divisor = initial[ j ]; + } else { + divisor += 2; + } + j += 1; + while ( true ) { + // Compute the integer quotient: + nq = floor( nl / divisor ); + + // Compute the remainder: + nr = nl - ( divisor * nq ); + + // If the divisor did not evenly divide the current sub-sequence length, try a new divisor... + if ( nr !== 0 ) { + break; + } + // We found a new factor: + nf += 1; + + // Update the sub-sequence length: + nl = nq; + + // Store the factor in the output array: + out[ offset+((nf+1)*stride) ] = divisor; + + // When the divisor is `2` and we've already found other factors, shift the other factors right to make room for the most recent `2` factor... + if ( divisor === 2 && nf !== 1 ) { + for ( i = 2; i <= nf; i++ ) { + ib = nf - i + 2; + out[ offset+((ib+1)*stride) ] = out[ offset+(ib*stride) ]; + } + out[ offset+(2*stride) ] = 2; + } + // If we cannot further divide the sequence length into smaller sub-sequences, we're done... + if ( nl === 1 ) { + break; + } + } + } while ( nl !== 1 ); + + // Store the sequence length: + out[ offset ] = N; + + // Store the number of factors: + out[ offset+stride ] = nf; + + // Return the number of factors: + return nf; +} + + +// EXPORTS // + +module.exports = decompose; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/package.json b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/package.json new file mode 100644 index 000000000000..b56ddcebca1c --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/fft/base/fftpack/decompose", + "version": "0.0.0", + "description": "Factorize a sequence length into a product of integers.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "fft", + "fftpack", + "decompose", + "factorization", + "factorize", + "factor", + "prime", + "sequence", + "product" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js new file mode 100644 index 000000000000..24db694d6e17 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -0,0 +1,269 @@ +/** +* @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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var primes = require( '@stdlib/datasets/primes-100k' ); +var decompose = require( './../lib' ); + + +// VARIABLES // + +var INITIAL = [ 3, 4, 2, 5 ]; // as found in FFTPACK + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof decompose, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( decompose.length, 5, 'arity of 5' ); + t.end(); +}); + +tape( 'if provided a sequence length which is not a nonnegative integer, the function returns NaN', function test( t ) { + var factors; + var result; + var values; + var i; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function foo() {} + ]; + + factors = [ 0, 0, 0, 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + result = decompose( values[ i ], INITIAL, factors, 1, 0 ); + t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'if provided an array of initial trial divisors which is not an array of nonnegative integers, the function returns NaN', function test( t ) { + var factors; + var result; + var values; + var i; + + values = [ + '5', + 5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [ '1', '2' ], + [ -1, 2, 3 ], + [ 1.1, 2, 3 ], + function foo() {} + ]; + + factors = [ 0, 0, 0, 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + result = decompose( 10, values[ i ], factors, 1, 0 ); + t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'if provided an output array which is not a collection, the function returns NaN', function test( t ) { + var result; + var values; + var i; + + values = [ + '5', + 5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + function foo() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + result = decompose( 10, INITIAL, values[ i ], 1, 0 ); + t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'if provided a stride which is not an integer, the function returns NaN', function test( t ) { + var factors; + var result; + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function foo() {} + ]; + + factors = [ 0, 0, 0, 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + result = decompose( 10, INITIAL, factors, values[ i ], 0 ); + t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'if provided an offset which is not a nonnegative integer, the function returns NaN', function test( t ) { + var factors; + var result; + var values; + var i; + + values = [ + '5', + -5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function foo() {} + ]; + + factors = [ 0, 0, 0, 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + result = decompose( 10, INITIAL, factors, 1, values[ i ] ); + t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function correctly factorizes a sequence length into a product of integers', function test( t ) { + var factors; + var nf; + + factors = [ 0, 0, 0, 0, 0, 0, 0 ]; + nf = decompose( 630, INITIAL, factors, 1, 0 ); + + t.strictEqual( nf, 5, 'returns expected number of factors' ); + t.strictEqual( factors[ 0 ], 630, 'stores sequence length' ); + t.strictEqual( factors[ 1 ], 5, 'stores number of factors' ); + t.strictEqual( factors[ 2 ], 2, 'stores first factor' ); + t.strictEqual( factors[ 3 ], 3, 'stores second factor' ); + t.strictEqual( factors[ 4 ], 3, 'stores third factor' ); + t.strictEqual( factors[ 5 ], 5, 'stores fourth factor' ); + t.strictEqual( factors[ 6 ], 7, 'stores fifth factor' ); + + factors = [ 0, 0, 0, 0 ]; + nf = decompose( 8, INITIAL, factors, 1, 0 ); + + t.strictEqual( nf, 2, 'returns expected number of factors' ); + t.strictEqual( factors[ 0 ], 8, 'stores sequence length' ); + t.strictEqual( factors[ 1 ], 2, 'stores number of factors' ); + t.strictEqual( factors[ 2 ], 2, 'stores first factor' ); + t.strictEqual( factors[ 3 ], 4, 'stores second factor' ); + + t.end(); +}); + +tape( 'the function correctly factorizes prime numbers', function test( t ) { + var primesList; + var factors; + var nf; + var i; + + // First 10 prime numbers: [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ]... + primesList = primes().slice( 0, 10 ); + + for ( i = 0; i < primesList.length; i++ ) { + factors = [ 0, 0, 0 ]; + nf = decompose( primesList[ i ], INITIAL, factors, 1, 0 ); + + t.strictEqual( nf, 1, 'returns expected number of factors for prime ' + primesList[ i ] ); + t.strictEqual( factors[ 0 ], primesList[ i ], 'stores sequence length' ); + t.strictEqual( factors[ 1 ], 1, 'stores number of factors' ); + t.strictEqual( factors[ 2 ], primesList[ i ], 'stores the prime as its own factor' ); + } + + t.end(); +}); + +tape( 'the function returns expected results when provided a sequence length of 0', function test( t ) { + var factors; + var nf; + + factors = [ 0, 0 ]; + nf = decompose( 0, INITIAL, factors, 1, 0 ); + + t.strictEqual( nf, 0, 'returns expected number of factors' ); + t.strictEqual( factors[ 0 ], 0, 'stores sequence length' ); + t.strictEqual( factors[ 1 ], 0, 'stores number of factors' ); + + t.end(); +}); + +tape( 'the function correctly handles stride and offset parameters', function test( t ) { + var factors; + var stride = 2; + var offset = 1; + var nf; + + factors = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; + nf = decompose( 12, INITIAL, factors, stride, offset ); + + t.strictEqual( nf, 2, 'returns expected number of factors' ); + t.strictEqual( factors[ offset ], 12, 'stores sequence length at offset' ); + t.strictEqual( factors[ offset+stride ], 2, 'stores number of factors at offset + stride' ); + t.strictEqual( factors[ offset+(2*stride) ], 3, 'stores first factor at offset + 2*stride' ); + t.strictEqual( factors[ offset+(3*stride) ], 4, 'stores second factor at offset + 3*stride' ); + + t.end(); +}); From bc155d6e635712ca323c272b9f3e68cf5e745ed5 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 18 Feb 2026 22:58:16 +0530 Subject: [PATCH 02/17] refactor: use array instead of collection --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/fft/base/fftpack/decompose/docs/repl.txt | 2 +- .../@stdlib/fft/base/fftpack/decompose/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js | 2 +- .../@stdlib/fft/base/fftpack/decompose/test/test.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index 42a1641b35e1..e11ac62ac368 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -17,7 +17,7 @@ initial: Array Array of initial trial divisors. - out: Collection + out: Array Output array for storing factorization results. stride: number diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts index 56f96c79e97c..ef79eaa29aab 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts @@ -57,7 +57,7 @@ import decompose = require( './index' ); decompose( 12, ( x: number ): number => x, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided an output array which is not an array-like object... +// The compiler throws an error if the function is provided an output array which is not an array... { const initial = [ 3, 4, 2, 5 ]; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index dad82708319b..768e2e819b6e 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -85,7 +85,7 @@ var isCollection = require( '@stdlib/assert/is-collection' ); * @private * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeIntegerArray} initial - array of initial trial divisors -* @param {Collection} out - output array for storing factorization results +* @param {Array} out - output array for storing factorization results * @param {integer} stride - stride length for `out` * @param {NonNegativeInteger} offset - starting index for `out` * @returns {NonNegativeInteger} number of factors into which `N` was decomposed diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index 24db694d6e17..b01508a2884e 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -104,7 +104,7 @@ tape( 'if provided an array of initial trial divisors which is not an array of n t.end(); }); -tape( 'if provided an output array which is not a collection, the function returns NaN', function test( t ) { +tape( 'if provided an output array which is not an array, the function returns NaN', function test( t ) { var result; var values; var i; From 0cfac281eb6a979f4c0343103d789b8986c4b93d Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 18 Feb 2026 23:35:16 +0530 Subject: [PATCH 03/17] refactor: use slice method --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/fft/base/fftpack/decompose/test/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index b01508a2884e..f3d64ace6d0d 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var primes = require( '@stdlib/datasets/primes-100k' ); +var slice = require( '@stdlib/array/slice' ); var decompose = require( './../lib' ); @@ -221,7 +222,7 @@ tape( 'the function correctly factorizes prime numbers', function test( t ) { var i; // First 10 prime numbers: [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ]... - primesList = primes().slice( 0, 10 ); + primesList = slice( primes(), 0, 10 ); for ( i = 0; i < primesList.length; i++ ) { factors = [ 0, 0, 0 ]; From 7e5e61305cf295e95b721fe2a5f35f720c6d0d9d Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 25 Feb 2026 01:07:53 +0530 Subject: [PATCH 04/17] refcator: use Collection instead of Array --- .../@stdlib/fft/base/fftpack/decompose/docs/repl.txt | 4 ++-- .../@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts | 4 +++- .../@stdlib/fft/base/fftpack/decompose/lib/main.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index e11ac62ac368..d1a2f7f6d710 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -14,10 +14,10 @@ N: number Length of the sequence. - initial: Array + initial: Collection Array of initial trial divisors. - out: Array + out: Collection Output array for storing factorization results. stride: number diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts index 3ab145c3f649..1d8b32c47513 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts @@ -20,6 +20,8 @@ /// +import { Collection } from '@stdlib/types/array'; + /** * Factorizes a sequence length into a product of integers. * @@ -41,7 +43,7 @@ * var f = factors.slice(); * // returns [ 630, 5, 2, 3, 3, 5, 7 ] */ -declare function decompose( N: number, initial: Array, out: Array, stride: number, offset: number ): number; +declare function decompose( N: number, initial: Collection, out: Collection, stride: number, offset: number ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index 768e2e819b6e..dad82708319b 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -85,7 +85,7 @@ var isCollection = require( '@stdlib/assert/is-collection' ); * @private * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeIntegerArray} initial - array of initial trial divisors -* @param {Array} out - output array for storing factorization results +* @param {Collection} out - output array for storing factorization results * @param {integer} stride - stride length for `out` * @param {NonNegativeInteger} offset - starting index for `out` * @returns {NonNegativeInteger} number of factors into which `N` was decomposed From c9037e083df21caf96e5591cab3bf05df37bcbd7 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 25 Feb 2026 21:21:27 +0530 Subject: [PATCH 05/17] refactor: add M as a parameter --- .../fft/base/fftpack/decompose/README.md | 15 +- .../fftpack/decompose/benchmark/benchmark.js | 2 +- .../fft/base/fftpack/decompose/docs/repl.txt | 17 +- .../fftpack/decompose/docs/types/index.d.ts | 21 ++- .../base/fftpack/decompose/docs/types/test.ts | 140 ++++++++++----- .../base/fftpack/decompose/examples/index.js | 2 +- .../fft/base/fftpack/decompose/lib/index.js | 12 +- .../fft/base/fftpack/decompose/lib/main.js | 43 ++--- .../fft/base/fftpack/decompose/test/test.js | 169 ++---------------- 9 files changed, 161 insertions(+), 260 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md index 648ad3c34927..1f25f2c1b8d2 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md @@ -40,7 +40,7 @@ limitations under the License. var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); ``` -#### decompose( N, initial, out, stride, offset ) +#### decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) Factorizes a sequence length into a product of integers. @@ -49,7 +49,7 @@ 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, initial, factors, 1, 0 ); +var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); // returns 5 console.log( factors ); @@ -59,10 +59,13 @@ console.log( factors ); The function accepts the following arguments: - **N**: length of the sequence. +- **M**: number of trial divisors. - **initial**: array of initial trial divisors. +- **strideInitial**: stride length for `initial`. +- **offsetInitial**: starting index for `initial`. - **out**: output array for storing factorization results. -- **stride**: stride length for `out`. -- **offset**: starting index for `out`. +- **strideOut**: stride length for `out`. +- **offsetOut**: starting index for `out`. The function returns the number of factors into which `N` was decomposed. @@ -82,8 +85,6 @@ The function returns the number of factors into which `N` was decomposed. [ sequence_length | number_of_factors | integer_factors | unused_storage ] ``` -- The function mutates the input array. - @@ -102,7 +103,7 @@ var factors = [ 0, 0, 0, 0 ]; var nf; var j; -nf = decompose( 12, initial, factors, 1, 0 ); +nf = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); console.log( 'Sequence length: %d', 12 ); console.log( 'Number of factors: %d', nf ); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js index fec48dff9462..604afa551b4e 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/benchmark/benchmark.js @@ -60,7 +60,7 @@ function createBenchmark( N ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - d = decompose( N, initial, factors, 1, 0 ); + d = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); if ( isnan( d ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index d1a2f7f6d710..ff9aa224929e 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, initial, out, stride, offset ) +{{alias}}( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) Factorizes a sequence length into a product of integers. Factorization results are stored in the output array sequentially, where @@ -14,16 +14,25 @@ N: number Length of the sequence. + M: number + Number of trial divisors. + initial: Collection Array of initial trial divisors. + strideInitial: number + Stride length for `initial`. + + offsetInitial: number + Starting index for `initial`. + out: Collection Output array for storing factorization results. - stride: number + strideOut: number Stride length for `out`. - offset: number + offsetOut: number Starting index for `out`. Returns @@ -36,7 +45,7 @@ > var N = 630; > var initial = [ 3, 4, 2, 5 ]; > var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; - > var numFactors = {{alias}}( N, initial, factors, 1, 0 ) + > var numFactors = {{alias}}( N, 4, initial, 1, 0, factors, 1, 0 ) 5 > factors.slice() [ 630, 5, 2, 3, 3, 5, 7 ] diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts index 1d8b32c47513..33e3860091e5 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts @@ -26,24 +26,23 @@ 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 strideInitial - stride length for `initial` +* @param offsetInitial - starting index for `initial` * @param out - output array for storing factorization results -* @param stride - stride length for `out` -* @param offset - starting index for `out` +* @param strideOut - stride length for `out` +* @param offsetOut - starting index for `out` * @returns number of factors into which `N` was decomposed * * @example -* var N = 630; -* var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK -* var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; +* var initial = new Float64Array( [ 3, 4, 2, 5 ] ); +* var factors = new Float64Array( 4 ); * -* var numFactors = decompose( N, initial, factors, 1, 0 ); -* // returns 5 -* -* var f = factors.slice(); -* // returns [ 630, 5, 2, 3, 3, 5, 7 ] +* var numFactors = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); +* // returns 2 */ -declare function decompose( N: number, initial: Collection, out: Collection, stride: number, offset: number ): number; +declare function decompose( N: number, M: number, initial: Collection, strideInitial: number, offsetInitial: number, out: Collection, strideOut: number, offsetOut: number ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts index ef79eaa29aab..eb11e18c782c 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts @@ -25,7 +25,7 @@ import decompose = require( './index' ); const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; - decompose( 12, initial, out, 1, 0 ); // $ExpectType number + decompose( 12, 4, initial, 1, 0, out, 1, 0 ); // $ExpectType number } // The compiler throws an error if the function is provided a sequence length which is not a number... @@ -33,71 +33,116 @@ import decompose = require( './index' ); const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; - decompose( '12', initial, out, 1, 0 ); // $ExpectError - decompose( true, initial, out, 1, 0 ); // $ExpectError - decompose( false, initial, out, 1, 0 ); // $ExpectError - decompose( null, initial, out, 1, 0 ); // $ExpectError - decompose( void 0, initial, out, 1, 0 ); // $ExpectError - decompose( [], initial, out, 1, 0 ); // $ExpectError - decompose( {}, initial, out, 1, 0 ); // $ExpectError - decompose( ( x: number ): number => x, initial, out, 1, 0 ); // $ExpectError + decompose( '12', 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( true, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( false, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( null, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( void 0, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( [], 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( {}, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( ( x: number ): number => x, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a number of trial divisors which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, '4', initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, true, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, false, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, null, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, void 0, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, [], initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, {}, initial, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, ( x: number ): number => x, initial, 1, 0, out, 1, 0 ); // $ExpectError } // The compiler throws an error if the function is provided initial trial divisors which is not an array of numbers... { const out = [ 0, 0, 0, 0, 0, 0, 0 ]; - decompose( 12, '4,2,3,5', out, 1, 0 ); // $ExpectError - decompose( 12, 5, out, 1, 0 ); // $ExpectError - decompose( 12, true, out, 1, 0 ); // $ExpectError - decompose( 12, false, out, 1, 0 ); // $ExpectError - decompose( 12, null, out, 1, 0 ); // $ExpectError - decompose( 12, void 0, out, 1, 0 ); // $ExpectError - decompose( 12, {}, out, 1, 0 ); // $ExpectError - decompose( 12, ( x: number ): number => x, out, 1, 0 ); // $ExpectError + decompose( 12, 4, '4,2,3,5', 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, 5, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, true, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, false, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, null, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, void 0, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, {}, 1, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a stride for initial which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, 4, initial, '1', 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, true, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, false, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, null, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, void 0, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, [], 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, {}, 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an offset for initial which is not a number... +{ + const initial = [ 3, 4, 2, 5 ]; + const out = [ 0, 0, 0, 0, 0, 0, 0 ]; + + decompose( 12, 4, initial, 1, '0', out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, true, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, false, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, null, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, void 0, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, [], out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, {}, out, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError } // The compiler throws an error if the function is provided an output array which is not an array... { const initial = [ 3, 4, 2, 5 ]; - decompose( 12, initial, 123, 1, 0 ); // $ExpectError - decompose( 12, initial, true, 1, 0 ); // $ExpectError - decompose( 12, initial, false, 1, 0 ); // $ExpectError - decompose( 12, initial, null, 1, 0 ); // $ExpectError - decompose( 12, initial, void 0, 1, 0 ); // $ExpectError - decompose( 12, initial, {}, 1, 0 ); // $ExpectError - decompose( 12, initial, ( x: number ): number => x, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, 123, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, true, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, false, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, null, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, void 0, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, {}, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided a stride which is not a number... +// The compiler throws an error if the function is provided a stride for out which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; - decompose( 12, initial, out, '1', 0 ); // $ExpectError - decompose( 12, initial, out, true, 0 ); // $ExpectError - decompose( 12, initial, out, false, 0 ); // $ExpectError - decompose( 12, initial, out, null, 0 ); // $ExpectError - decompose( 12, initial, out, void 0, 0 ); // $ExpectError - decompose( 12, initial, out, [], 0 ); // $ExpectError - decompose( 12, initial, out, {}, 0 ); // $ExpectError - decompose( 12, initial, out, ( x: number ): number => x, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, '1', 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, true, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, false, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, null, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, void 0, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, [], 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, {}, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided an offset which is not a number... +// The compiler throws an error if the function is provided an offset for out which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; - decompose( 12, initial, out, 1, '0' ); // $ExpectError - decompose( 12, initial, out, 1, true ); // $ExpectError - decompose( 12, initial, out, 1, false ); // $ExpectError - decompose( 12, initial, out, 1, null ); // $ExpectError - decompose( 12, initial, out, 1, void 0 ); // $ExpectError - decompose( 12, initial, out, 1, [] ); // $ExpectError - decompose( 12, initial, out, 1, {} ); // $ExpectError - decompose( 12, initial, out, 1, ( x: number ): number => x ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, '0' ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, true ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, false ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, null ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, void 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, [] ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, {} ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -107,8 +152,11 @@ import decompose = require( './index' ); decompose(); // $ExpectError decompose( 12 ); // $ExpectError - decompose( 12, initial ); // $ExpectError - decompose( 12, initial, out ); // $ExpectError - decompose( 12, initial, out, 1 ); // $ExpectError - decompose( 12, initial, out, 1, 0, 123 ); // $ExpectError + decompose( 12, 4 ); // $ExpectError + decompose( 12, 4, initial ); // $ExpectError + decompose( 12, 4, initial, 1 ); // $ExpectError + decompose( 12, 4, initial, 1, 0 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1 ); // $ExpectError + decompose( 12, 4, initial, 1, 0, out, 1, 0, 123 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js index 052a73cbcf79..c6216a7416f4 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js @@ -25,7 +25,7 @@ var factors = [ 0, 0, 0, 0 ]; var nf; var j; -nf = decompose( 12, initial, factors, 1, 0 ); +nf = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); console.log( 'Sequence length: %d', 12 ); console.log( 'Number of factors: %d', nf ); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js index 06fae87ca7a8..5e7183ef5062 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/index.js @@ -30,24 +30,18 @@ * var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK * var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; * -* var numFactors = decompose( N, initial, factors, 1, 0 ); +* var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); * // returns 5 * -* var f = factors.slice(); -* // returns [ 630, 5, 2, 3, 3, 5, 7 ] -* * @example * var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); * -* var N = 8; +* var N = 12; * var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK * var factors = [ 0, 0, 0, 0 ]; * -* var numFactors = decompose( N, initial, factors, 1, 0 ); +* var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); * // returns 2 -* -* var f = factors.slice(); -* // returns [ 8, 2, 2, 4 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index dad82708319b..08c38bc3bac7 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -61,10 +61,6 @@ // MODULES // var floor = require( '@stdlib/math/base/special/floor' ); -var isInteger = require( '@stdlib/math/base/assert/is-integer' ); -var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; -var isCollection = require( '@stdlib/assert/is-collection' ); // MAIN // @@ -84,10 +80,13 @@ var isCollection = require( '@stdlib/assert/is-collection' ); * * @private * @param {NonNegativeInteger} N - length of the sequence -* @param {NonNegativeIntegerArray} initial - array of initial trial divisors +* @param {NonNegativeInteger} M - number of trial divisors +* @param {NonNegativeIntegerArray} initial - strided array of initial trial divisors +* @param {integer} strideInitial - stride length for `initial` +* @param {NonNegativeInteger} offsetInitial - starting index for `initial` * @param {Collection} out - output array for storing factorization results -* @param {integer} stride - stride length for `out` -* @param {NonNegativeInteger} offset - starting index for `out` +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` * @returns {NonNegativeInteger} number of factors into which `N` was decomposed * * @example @@ -95,7 +94,7 @@ var isCollection = require( '@stdlib/assert/is-collection' ); * var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK * var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; * -* var numFactors = decompose( N, initial, factors, 1, 0 ); +* var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); * // returns 5 * * var f = factors.slice(); @@ -106,13 +105,13 @@ var isCollection = require( '@stdlib/assert/is-collection' ); * var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK * var factors = [ 0, 0, 0, 0 ]; * -* var numFactors = decompose( N, initial, factors, 1, 0 ); +* var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 ); * // returns 2 * * var f = factors.slice(); * // returns [ 8, 2, 2, 4 ] */ -function decompose( N, initial, out, stride, offset ) { +function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) { // eslint-disable-line max-len var divisor; var ntrials; var nl; @@ -123,20 +122,14 @@ function decompose( N, initial, out, stride, offset ) { var i; var j; - if ( !isNonNegativeInteger( N ) || !isNonNegativeIntegerArray( initial ) || - !isCollection( out ) || !isInteger( stride ) || - !isNonNegativeInteger( offset ) ) { - return NaN; - } - if ( N === 0 ) { - out[ offset ] = N; - out[ offset+stride ] = 0; + out[ offsetOut ] = N; + out[ offsetOut+strideOut ] = 0; return 0; } // Resolve the number of trial divisors: - ntrials = initial.length; + ntrials = M; // Initialize a variable for storing a trial divisor: divisor = 0; @@ -150,7 +143,7 @@ function decompose( N, initial, out, stride, offset ) { j = 0; do { if ( j < ntrials ) { - divisor = initial[ j ]; + divisor = initial[ offsetInitial + (j * strideInitial) ]; } else { divisor += 2; } @@ -173,15 +166,15 @@ function decompose( N, initial, out, stride, offset ) { nl = nq; // Store the factor in the output array: - out[ offset+((nf+1)*stride) ] = divisor; + out[ offsetOut+((nf+1)*strideOut) ] = divisor; // When the divisor is `2` and we've already found other factors, shift the other factors right to make room for the most recent `2` factor... if ( divisor === 2 && nf !== 1 ) { for ( i = 2; i <= nf; i++ ) { ib = nf - i + 2; - out[ offset+((ib+1)*stride) ] = out[ offset+(ib*stride) ]; + out[ offsetOut+((ib+1)*strideOut) ] = out[ offsetOut + (ib*strideOut) ]; // eslint-disable-line max-len } - out[ offset+(2*stride) ] = 2; + out[ offsetOut+(2*strideOut) ] = 2; } // If we cannot further divide the sequence length into smaller sub-sequences, we're done... if ( nl === 1 ) { @@ -191,10 +184,10 @@ function decompose( N, initial, out, stride, offset ) { } while ( nl !== 1 ); // Store the sequence length: - out[ offset ] = N; + out[ offsetOut ] = N; // Store the number of factors: - out[ offset+stride ] = nf; + out[ offsetOut+strideOut ] = nf; // Return the number of factors: return nf; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index f3d64ace6d0d..b446fcfae675 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var primes = require( '@stdlib/datasets/primes-100k' ); var slice = require( '@stdlib/array/slice' ); var decompose = require( './../lib' ); @@ -40,150 +39,8 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( decompose.length, 5, 'arity of 5' ); - t.end(); -}); - -tape( 'if provided a sequence length which is not a nonnegative integer, the function returns NaN', function test( t ) { - var factors; - var result; - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [], - function foo() {} - ]; - - factors = [ 0, 0, 0, 0, 0 ]; - - for ( i = 0; i < values.length; i++ ) { - result = decompose( values[ i ], INITIAL, factors, 1, 0 ); - t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); - } - t.end(); -}); - -tape( 'if provided an array of initial trial divisors which is not an array of nonnegative integers, the function returns NaN', function test( t ) { - var factors; - var result; - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [ '1', '2' ], - [ -1, 2, 3 ], - [ 1.1, 2, 3 ], - function foo() {} - ]; - - factors = [ 0, 0, 0, 0, 0 ]; - - for ( i = 0; i < values.length; i++ ) { - result = decompose( 10, values[ i ], factors, 1, 0 ); - t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); - } - t.end(); -}); - -tape( 'if provided an output array which is not an array, the function returns NaN', function test( t ) { - var result; - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function foo() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - result = decompose( 10, INITIAL, values[ i ], 1, 0 ); - t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); - } - t.end(); -}); - -tape( 'if provided a stride which is not an integer, the function returns NaN', function test( t ) { - var factors; - var result; - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [], - function foo() {} - ]; - - factors = [ 0, 0, 0, 0, 0 ]; - - for ( i = 0; i < values.length; i++ ) { - result = decompose( 10, INITIAL, factors, values[ i ], 0 ); - t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); - } - t.end(); -}); - -tape( 'if provided an offset which is not a nonnegative integer, the function returns NaN', function test( t ) { - var factors; - var result; - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - [], - function foo() {} - ]; - - factors = [ 0, 0, 0, 0, 0 ]; - - for ( i = 0; i < values.length; i++ ) { - result = decompose( 10, INITIAL, factors, 1, values[ i ] ); - t.strictEqual( isnan( result ), true, 'returns NaN when provided ' + values[ i ] ); - } +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( decompose.length, 8, 'arity of 8' ); t.end(); }); @@ -192,7 +49,7 @@ tape( 'the function correctly factorizes a sequence length into a product of int var nf; factors = [ 0, 0, 0, 0, 0, 0, 0 ]; - nf = decompose( 630, INITIAL, factors, 1, 0 ); + nf = decompose( 630, 4, INITIAL, 1, 0, factors, 1, 0 ); t.strictEqual( nf, 5, 'returns expected number of factors' ); t.strictEqual( factors[ 0 ], 630, 'stores sequence length' ); @@ -204,7 +61,7 @@ tape( 'the function correctly factorizes a sequence length into a product of int t.strictEqual( factors[ 6 ], 7, 'stores fifth factor' ); factors = [ 0, 0, 0, 0 ]; - nf = decompose( 8, INITIAL, factors, 1, 0 ); + nf = decompose( 8, 4, INITIAL, 1, 0, factors, 1, 0 ); t.strictEqual( nf, 2, 'returns expected number of factors' ); t.strictEqual( factors[ 0 ], 8, 'stores sequence length' ); @@ -226,7 +83,7 @@ tape( 'the function correctly factorizes prime numbers', function test( t ) { for ( i = 0; i < primesList.length; i++ ) { factors = [ 0, 0, 0 ]; - nf = decompose( primesList[ i ], INITIAL, factors, 1, 0 ); + nf = decompose( primesList[ i ], 4, INITIAL, 1, 0, factors, 1, 0 ); t.strictEqual( nf, 1, 'returns expected number of factors for prime ' + primesList[ i ] ); t.strictEqual( factors[ 0 ], primesList[ i ], 'stores sequence length' ); @@ -242,7 +99,7 @@ tape( 'the function returns expected results when provided a sequence length of var nf; factors = [ 0, 0 ]; - nf = decompose( 0, INITIAL, factors, 1, 0 ); + nf = decompose( 0, 4, INITIAL, 1, 0, factors, 1, 0 ); t.strictEqual( nf, 0, 'returns expected number of factors' ); t.strictEqual( factors[ 0 ], 0, 'stores sequence length' ); @@ -252,19 +109,19 @@ tape( 'the function returns expected results when provided a sequence length of }); tape( 'the function correctly handles stride and offset parameters', function test( t ) { + var strideOut = 2; + var offsetOut = 1; var factors; - var stride = 2; - var offset = 1; var nf; factors = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; - nf = decompose( 12, INITIAL, factors, stride, offset ); + nf = decompose( 12, 4, INITIAL, 1, 0, factors, strideOut, offsetOut ); t.strictEqual( nf, 2, 'returns expected number of factors' ); - t.strictEqual( factors[ offset ], 12, 'stores sequence length at offset' ); - t.strictEqual( factors[ offset+stride ], 2, 'stores number of factors at offset + stride' ); - t.strictEqual( factors[ offset+(2*stride) ], 3, 'stores first factor at offset + 2*stride' ); - t.strictEqual( factors[ offset+(3*stride) ], 4, 'stores second factor at offset + 3*stride' ); + t.strictEqual( factors[ offsetOut ], 12, 'stores sequence length at offset' ); + t.strictEqual( factors[ offsetOut+strideOut ], 2, 'stores number of factors at offset + stride' ); + t.strictEqual( factors[ offsetOut+(2*strideOut) ], 3, 'stores first factor at offset + 2*stride' ); + t.strictEqual( factors[ offsetOut+(3*strideOut) ], 4, 'stores second factor at offset + 3*stride' ); t.end(); }); From 93ffa30b63695725ccc6a6740dfaa935ea32dde1 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 25 Feb 2026 21:26:48 +0530 Subject: [PATCH 06/17] docs: update notes --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/fft/base/fftpack/decompose/lib/main.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index 08c38bc3bac7..72eac509eeae 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -70,14 +70,12 @@ var floor = require( '@stdlib/math/base/special/floor' ); * * ## Notes * -* - Factorization results are stored in the input array as follows: +* - Factorization results are stored in the output array as follows: * * ```text * [ sequence_length | number_of_factors | integer_factors | unused_storage ] * ``` * -* - The function mutates the input array. -* * @private * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeInteger} M - number of trial divisors From 4308548d1e22508dfa97b756f8e41a4e03511706 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 25 Feb 2026 23:35:34 +0530 Subject: [PATCH 07/17] refactor: change stride and offset parameter names --- .../fft/base/fftpack/decompose/README.md | 10 +++---- .../fft/base/fftpack/decompose/docs/repl.txt | 10 +++---- .../fftpack/decompose/docs/types/index.d.ts | 10 +++---- .../fft/base/fftpack/decompose/lib/main.js | 26 +++++++++---------- .../fft/base/fftpack/decompose/test/test.js | 14 +++++----- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md index 1f25f2c1b8d2..532929ab004c 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md @@ -40,7 +40,7 @@ limitations under the License. var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); ``` -#### decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) +#### decompose( N, M, initial, si, oi, out, so, oo ) Factorizes a sequence length into a product of integers. @@ -61,11 +61,11 @@ The function accepts the following arguments: - **N**: length of the sequence. - **M**: number of trial divisors. - **initial**: array of initial trial divisors. -- **strideInitial**: stride length for `initial`. -- **offsetInitial**: starting index for `initial`. +- **si**: stride length for `initial`. +- **oi**: starting index for `initial`. - **out**: output array for storing factorization results. -- **strideOut**: stride length for `out`. -- **offsetOut**: starting index for `out`. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. The function returns the number of factors into which `N` was decomposed. diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index ff9aa224929e..4c76102e882e 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) +{{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 @@ -20,19 +20,19 @@ initial: Collection Array of initial trial divisors. - strideInitial: number + si: number Stride length for `initial`. - offsetInitial: number + oi: number Starting index for `initial`. out: Collection Output array for storing factorization results. - strideOut: number + so: number Stride length for `out`. - offsetOut: number + oo: number Starting index for `out`. Returns diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts index 33e3860091e5..686266a120ed 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/index.d.ts @@ -28,11 +28,11 @@ import { Collection } from '@stdlib/types/array'; * @param N - length of the sequence * @param M - number of trial divisors * @param initial - array of initial trial divisors -* @param strideInitial - stride length for `initial` -* @param offsetInitial - starting index for `initial` +* @param si - stride length for `initial` +* @param oi - starting index for `initial` * @param out - output array for storing factorization results -* @param strideOut - stride length for `out` -* @param offsetOut - starting index for `out` +* @param so - stride length for `out` +* @param oo - starting index for `out` * @returns number of factors into which `N` was decomposed * * @example @@ -42,7 +42,7 @@ import { Collection } from '@stdlib/types/array'; * var numFactors = decompose( 12, 4, initial, 1, 0, factors, 1, 0 ); * // returns 2 */ -declare function decompose( N: number, M: number, initial: Collection, strideInitial: number, offsetInitial: number, out: Collection, strideOut: number, offsetOut: number ): number; +declare function decompose( N: number, M: number, initial: Collection, si: number, oi: number, out: Collection, so: number, oo: number ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index 72eac509eeae..10f20d7a272a 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -80,11 +80,11 @@ var floor = require( '@stdlib/math/base/special/floor' ); * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeInteger} M - number of trial divisors * @param {NonNegativeIntegerArray} initial - strided array of initial trial divisors -* @param {integer} strideInitial - stride length for `initial` -* @param {NonNegativeInteger} offsetInitial - starting index for `initial` +* @param {integer} si - stride length for `initial` +* @param {NonNegativeInteger} oi - starting index for `initial` * @param {Collection} out - output array for storing factorization results -* @param {integer} strideOut - stride length for `out` -* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @param {integer} so - stride length for `out` +* @param {NonNegativeInteger} oo - starting index for `out` * @returns {NonNegativeInteger} number of factors into which `N` was decomposed * * @example @@ -109,7 +109,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * var f = factors.slice(); * // returns [ 8, 2, 2, 4 ] */ -function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, offsetOut ) { // eslint-disable-line max-len +function decompose( N, M, initial, si, oi, out, so, oo ) { // eslint-disable-line max-len var divisor; var ntrials; var nl; @@ -121,8 +121,8 @@ function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, var j; if ( N === 0 ) { - out[ offsetOut ] = N; - out[ offsetOut+strideOut ] = 0; + out[ oo ] = N; + out[ oo+so ] = 0; return 0; } @@ -141,7 +141,7 @@ function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, j = 0; do { if ( j < ntrials ) { - divisor = initial[ offsetInitial + (j * strideInitial) ]; + divisor = initial[ oi + (j * si) ]; } else { divisor += 2; } @@ -164,15 +164,15 @@ function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, nl = nq; // Store the factor in the output array: - out[ offsetOut+((nf+1)*strideOut) ] = divisor; + out[ oo+((nf+1)*so) ] = divisor; // When the divisor is `2` and we've already found other factors, shift the other factors right to make room for the most recent `2` factor... if ( divisor === 2 && nf !== 1 ) { for ( i = 2; i <= nf; i++ ) { ib = nf - i + 2; - out[ offsetOut+((ib+1)*strideOut) ] = out[ offsetOut + (ib*strideOut) ]; // eslint-disable-line max-len + out[ oo+((ib+1)*so) ] = out[ oo + (ib*so) ]; // eslint-disable-line max-len } - out[ offsetOut+(2*strideOut) ] = 2; + out[ oo+(2*so) ] = 2; } // If we cannot further divide the sequence length into smaller sub-sequences, we're done... if ( nl === 1 ) { @@ -182,10 +182,10 @@ function decompose( N, M, initial, strideInitial, offsetInitial, out, strideOut, } while ( nl !== 1 ); // Store the sequence length: - out[ offsetOut ] = N; + out[ oo ] = N; // Store the number of factors: - out[ offsetOut+strideOut ] = nf; + out[ oo+so ] = nf; // Return the number of factors: return nf; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index b446fcfae675..fdf3d87c7717 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -109,19 +109,19 @@ tape( 'the function returns expected results when provided a sequence length of }); tape( 'the function correctly handles stride and offset parameters', function test( t ) { - var strideOut = 2; - var offsetOut = 1; var factors; + var so = 2; + var oo = 1; var nf; factors = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; - nf = decompose( 12, 4, INITIAL, 1, 0, factors, strideOut, offsetOut ); + nf = decompose( 12, 4, INITIAL, 1, 0, factors, so, oo ); t.strictEqual( nf, 2, 'returns expected number of factors' ); - t.strictEqual( factors[ offsetOut ], 12, 'stores sequence length at offset' ); - t.strictEqual( factors[ offsetOut+strideOut ], 2, 'stores number of factors at offset + stride' ); - t.strictEqual( factors[ offsetOut+(2*strideOut) ], 3, 'stores first factor at offset + 2*stride' ); - t.strictEqual( factors[ offsetOut+(3*strideOut) ], 4, 'stores second factor at offset + 3*stride' ); + t.strictEqual( factors[ oo ], 12, 'stores sequence length at offset' ); + t.strictEqual( factors[ oo+so ], 2, 'stores number of factors at offset + stride' ); + t.strictEqual( factors[ oo+(2*so) ], 3, 'stores first factor at offset + 2*stride' ); + t.strictEqual( factors[ oo+(3*so) ], 4, 'stores second factor at offset + 3*stride' ); t.end(); }); From 83619cf5ab3f1bf0037295ee627bc801be8d8e0c Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Wed, 25 Feb 2026 23:40:54 +0530 Subject: [PATCH 08/17] refactor: replace number with integer --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../fft/base/fftpack/decompose/docs/repl.txt | 14 +++++++------- .../@stdlib/fft/base/fftpack/decompose/lib/main.js | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index 4c76102e882e..03ddeb405f31 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -11,33 +11,33 @@ Parameters ---------- - N: number + N: integer Length of the sequence. - M: number + M: integer Number of trial divisors. initial: Collection Array of initial trial divisors. - si: number + si: integer Stride length for `initial`. - oi: number + oi: integer Starting index for `initial`. out: Collection Output array for storing factorization results. - so: number + so: integer Stride length for `out`. - oo: number + oo: integer Starting index for `out`. Returns ------- - numFactors: number + numFactors: integer Number of factors into which N was decomposed. Examples diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index 10f20d7a272a..c601579b8d3b 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -76,7 +76,6 @@ var floor = require( '@stdlib/math/base/special/floor' ); * [ sequence_length | number_of_factors | integer_factors | unused_storage ] * ``` * -* @private * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeInteger} M - number of trial divisors * @param {NonNegativeIntegerArray} initial - strided array of initial trial divisors @@ -109,7 +108,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * var f = factors.slice(); * // returns [ 8, 2, 2, 4 ] */ -function decompose( N, M, initial, si, oi, out, so, oo ) { // eslint-disable-line max-len +function decompose( N, M, initial, si, oi, out, so, oo ) { var divisor; var ntrials; var nl; @@ -170,7 +169,7 @@ function decompose( N, M, initial, si, oi, out, so, oo ) { // eslint-disable-lin if ( divisor === 2 && nf !== 1 ) { for ( i = 2; i <= nf; i++ ) { ib = nf - i + 2; - out[ oo+((ib+1)*so) ] = out[ oo + (ib*so) ]; // eslint-disable-line max-len + out[ oo+((ib+1)*so) ] = out[ oo + (ib*so) ]; } out[ oo+(2*so) ] = 2; } From 6dfe1774d2b3dcd4bb1d717327efe8a26b9c677a Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Fri, 27 Feb 2026 22:19:34 +0530 Subject: [PATCH 09/17] refactor: replace primes package by hardcoded array --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/fft/base/fftpack/decompose/test/test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index fdf3d87c7717..17bc2366d529 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -21,8 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var primes = require( '@stdlib/datasets/primes-100k' ); -var slice = require( '@stdlib/array/slice' ); var decompose = require( './../lib' ); @@ -78,8 +76,8 @@ tape( 'the function correctly factorizes prime numbers', function test( t ) { var nf; var i; - // First 10 prime numbers: [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ]... - primesList = slice( primes(), 0, 10 ); + // First 10 prime numbers: + primesList = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ]; for ( i = 0; i < primesList.length; i++ ) { factors = [ 0, 0, 0 ]; From 17d1f10db22a259007239702016cb0ebdfb2ea12 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Tue, 3 Mar 2026 22:53:57 +0530 Subject: [PATCH 10/17] refactor: use collection for initial array Signed-off-by: Gunj Joshi --- lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index c601579b8d3b..cb13b0a8a5a6 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -78,7 +78,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * * @param {NonNegativeInteger} N - length of the sequence * @param {NonNegativeInteger} M - number of trial divisors -* @param {NonNegativeIntegerArray} initial - strided array of initial trial divisors +* @param {Collection} initial - strided array of initial trial divisors * @param {integer} si - stride length for `initial` * @param {NonNegativeInteger} oi - starting index for `initial` * @param {Collection} out - output array for storing factorization results From cf1733b00a4c2b076a73946fd93bf998c7e5ad1e Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:10:04 -0700 Subject: [PATCH 11/17] docs: update comments Signed-off-by: Athan --- .../base/fftpack/decompose/docs/types/test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts index eb11e18c782c..011b915a8882 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/types/test.ts @@ -28,7 +28,7 @@ import decompose = require( './index' ); decompose( 12, 4, initial, 1, 0, out, 1, 0 ); // $ExpectType number } -// The compiler throws an error if the function is provided a sequence length which is not a number... +// The compiler throws an error if the function is provided a first argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -43,7 +43,7 @@ import decompose = require( './index' ); decompose( ( x: number ): number => x, 4, initial, 1, 0, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided a number of trial divisors which is not a number... +// The compiler throws an error if the function is provided a second argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -58,7 +58,7 @@ import decompose = require( './index' ); decompose( 12, ( x: number ): number => x, initial, 1, 0, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided initial trial divisors which is not an array of numbers... +// The compiler throws an error if the function is provided a third argument which is not an array of numbers... { const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -72,7 +72,7 @@ import decompose = require( './index' ); decompose( 12, 4, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided a stride for initial which is not a number... +// The compiler throws an error if the function is provided a fourth argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -87,7 +87,7 @@ import decompose = require( './index' ); decompose( 12, 4, initial, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided an offset for initial which is not a number... +// The compiler throws an error if the function is provided a fifth argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -102,7 +102,7 @@ import decompose = require( './index' ); decompose( 12, 4, initial, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided an output array which is not an array... +// The compiler throws an error if the function is provided a sixth argument which is not an array... { const initial = [ 3, 4, 2, 5 ]; @@ -115,7 +115,7 @@ import decompose = require( './index' ); decompose( 12, 4, initial, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided a stride for out which is not a number... +// The compiler throws an error if the function is provided a seventh argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; @@ -130,7 +130,7 @@ import decompose = require( './index' ); decompose( 12, 4, initial, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError } -// The compiler throws an error if the function is provided an offset for out which is not a number... +// The compiler throws an error if the function is provided an eighth argument which is not a number... { const initial = [ 3, 4, 2, 5 ]; const out = [ 0, 0, 0, 0, 0, 0, 0 ]; From 1060d0fc1e191e47637f5e18b90076baf42d347a Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:11:56 -0700 Subject: [PATCH 12/17] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/fft/base/fftpack/decompose/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index 03ddeb405f31..34c07c44abda 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -4,7 +4,7 @@ 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 + 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. @@ -47,7 +47,7 @@ > var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; > var numFactors = {{alias}}( N, 4, initial, 1, 0, factors, 1, 0 ) 5 - > factors.slice() + > factors [ 630, 5, 2, 3, 3, 5, 7 ] See Also From be4f46c387fc9e165d1ee845865bd3026f88cc03 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:12:54 -0700 Subject: [PATCH 13/17] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/fft/base/fftpack/decompose/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt index 34c07c44abda..964ed8270c71 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt @@ -17,7 +17,7 @@ M: integer Number of trial divisors. - initial: Collection + initial: ArrayLikeObject Array of initial trial divisors. si: integer @@ -26,7 +26,7 @@ oi: integer Starting index for `initial`. - out: Collection + out: ArrayLikeObject Output array for storing factorization results. so: integer From b861a21def6e2b0d3c7546b3330cd69ce1646ef3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:15:08 -0700 Subject: [PATCH 14/17] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/fft/base/fftpack/decompose/examples/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js index c6216a7416f4..11005ed1d37f 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js @@ -22,14 +22,14 @@ var decompose = require( './../lib' ); var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK var factors = [ 0, 0, 0, 0 ]; -var nf; -var j; -nf = decompose( 12, 4, initial, 1, 0, factors, 1, 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 ] ); } From df60db6b3f60f5d199b93070746bd05bebb7a526 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:18:25 -0700 Subject: [PATCH 15/17] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js index cb13b0a8a5a6..921f8db5ecaa 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/lib/main.js @@ -18,7 +18,7 @@ * * ## Notice * -* The original C code and copyright notice are from the [PFFFT library]{@link https://github.com/marton78/pffft/blob/master/fftpack.c}. The implementation follows the original, but has been modified for JavaScript. +* The original C code and copyright notice are from the [PFFFT library]{@link https://github.com/marton78/pffft/blob/0b4ee12c4ba45a4a8e567550c16d96d1679f50ce/src/fftpack.c}. The implementation follows the original, but has been modified for JavaScript. * * ```text * Copyright (c) 2004 the University Corporation for Atmospheric From 547a5165f3485f5a508580940f09694e429b0d22 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:21:16 -0700 Subject: [PATCH 16/17] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/fft/base/fftpack/decompose/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md index 532929ab004c..af5c32205bfc 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md @@ -100,14 +100,14 @@ 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; -var j; -nf = decompose( 12, 4, initial, 1, 0, factors, 1, 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 ] ); } From 269e284f16c330d77e8f0a6f4748e45da47e3f45 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 26 Mar 2026 00:26:01 -0700 Subject: [PATCH 17/17] test: update messages and make test more robust Signed-off-by: Athan --- .../fft/base/fftpack/decompose/test/test.js | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js index 17bc2366d529..d5088dbe227b 100644 --- a/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js +++ b/lib/node_modules/@stdlib/fft/base/fftpack/decompose/test/test.js @@ -38,7 +38,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 8', function test( t ) { - t.strictEqual( decompose.length, 8, 'arity of 8' ); + t.strictEqual( decompose.length, 8, 'returns expected value' ); t.end(); }); @@ -49,23 +49,23 @@ tape( 'the function correctly factorizes a sequence length into a product of int factors = [ 0, 0, 0, 0, 0, 0, 0 ]; nf = decompose( 630, 4, INITIAL, 1, 0, factors, 1, 0 ); - t.strictEqual( nf, 5, 'returns expected number of factors' ); - t.strictEqual( factors[ 0 ], 630, 'stores sequence length' ); - t.strictEqual( factors[ 1 ], 5, 'stores number of factors' ); - t.strictEqual( factors[ 2 ], 2, 'stores first factor' ); - t.strictEqual( factors[ 3 ], 3, 'stores second factor' ); - t.strictEqual( factors[ 4 ], 3, 'stores third factor' ); - t.strictEqual( factors[ 5 ], 5, 'stores fourth factor' ); - t.strictEqual( factors[ 6 ], 7, 'stores fifth factor' ); + t.strictEqual( nf, 5, 'returns expected value' ); + t.strictEqual( factors[ 0 ], 630, 'returns expected value' ); + t.strictEqual( factors[ 1 ], 5, 'returns expected value' ); + t.strictEqual( factors[ 2 ], 2, 'returns expected value' ); + t.strictEqual( factors[ 3 ], 3, 'returns expected value' ); + t.strictEqual( factors[ 4 ], 3, 'returns expected value' ); + t.strictEqual( factors[ 5 ], 5, 'returns expected value' ); + t.strictEqual( factors[ 6 ], 7, 'returns expected value' ); factors = [ 0, 0, 0, 0 ]; nf = decompose( 8, 4, INITIAL, 1, 0, factors, 1, 0 ); - t.strictEqual( nf, 2, 'returns expected number of factors' ); - t.strictEqual( factors[ 0 ], 8, 'stores sequence length' ); - t.strictEqual( factors[ 1 ], 2, 'stores number of factors' ); - t.strictEqual( factors[ 2 ], 2, 'stores first factor' ); - t.strictEqual( factors[ 3 ], 4, 'stores second factor' ); + t.strictEqual( nf, 2, 'returns expected value' ); + t.strictEqual( factors[ 0 ], 8, 'returns expected value' ); + t.strictEqual( factors[ 1 ], 2, 'returns expected value' ); + t.strictEqual( factors[ 2 ], 2, 'returns expected value' ); + t.strictEqual( factors[ 3 ], 4, 'returns expected value' ); t.end(); }); @@ -83,10 +83,10 @@ tape( 'the function correctly factorizes prime numbers', function test( t ) { factors = [ 0, 0, 0 ]; nf = decompose( primesList[ i ], 4, INITIAL, 1, 0, factors, 1, 0 ); - t.strictEqual( nf, 1, 'returns expected number of factors for prime ' + primesList[ i ] ); - t.strictEqual( factors[ 0 ], primesList[ i ], 'stores sequence length' ); - t.strictEqual( factors[ 1 ], 1, 'stores number of factors' ); - t.strictEqual( factors[ 2 ], primesList[ i ], 'stores the prime as its own factor' ); + t.strictEqual( nf, 1, 'returns expected value for ' + primesList[ i ] ); + t.strictEqual( factors[ 0 ], primesList[ i ], 'returns expected value' ); + t.strictEqual( factors[ 1 ], 1, 'returns expected value' ); + t.strictEqual( factors[ 2 ], primesList[ i ], 'returns expected value' ); } t.end(); @@ -99,27 +99,30 @@ tape( 'the function returns expected results when provided a sequence length of factors = [ 0, 0 ]; nf = decompose( 0, 4, INITIAL, 1, 0, factors, 1, 0 ); - t.strictEqual( nf, 0, 'returns expected number of factors' ); - t.strictEqual( factors[ 0 ], 0, 'stores sequence length' ); - t.strictEqual( factors[ 1 ], 0, 'stores number of factors' ); + t.strictEqual( nf, 0, 'returns expected value' ); + t.strictEqual( factors[ 0 ], 0, 'returns expected value' ); + t.strictEqual( factors[ 1 ], 0, 'returns expected value' ); t.end(); }); tape( 'the function correctly handles stride and offset parameters', function test( t ) { + var expected; var factors; - var so = 2; - var oo = 1; + var so; + var oo; var nf; factors = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; + + so = 2; + oo = 1; nf = decompose( 12, 4, INITIAL, 1, 0, factors, so, oo ); - t.strictEqual( nf, 2, 'returns expected number of factors' ); - t.strictEqual( factors[ oo ], 12, 'stores sequence length at offset' ); - t.strictEqual( factors[ oo+so ], 2, 'stores number of factors at offset + stride' ); - t.strictEqual( factors[ oo+(2*so) ], 3, 'stores first factor at offset + 2*stride' ); - t.strictEqual( factors[ oo+(3*so) ], 4, 'stores second factor at offset + 3*stride' ); + expected = [ 0, 12, 0, 2, 0, 3, 0, 4, 0, 0, 0 ]; + + t.strictEqual( nf, 2, 'returns expected value' ); + t.deepEqual( factors, expected, 'returns expected value' ); t.end(); });