Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions lib/node_modules/@stdlib/fft/base/fftpack/decompose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# decompose

> Factorize a sequence length into a product of integers.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var decompose = require( '@stdlib/fft/base/fftpack/decompose' );
```

#### decompose( N, M, initial, si, oi, out, so, oo )

Factorizes a sequence length into a product of integers.

```javascript
var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK
var N = 630;
var factors = [ 0, 0, 0, 0, 0, 0, 0 ];

var numFactors = decompose( N, 4, initial, 1, 0, factors, 1, 0 );
// returns 5

console.log( factors );
// => [ 630, 5, 2, 3, 3, 5, 7 ]
```

The function accepts the following arguments:

- **N**: length of the sequence.
- **M**: number of trial divisors.
- **initial**: array of initial trial divisors.
- **si**: stride length for `initial`.
- **oi**: starting index for `initial`.
- **out**: output array for storing factorization results.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

The function returns the number of factors into which `N` was decomposed.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- Factorization results are stored in the output array as follows:

```text
[ sequence_length | number_of_factors | integer_factors | unused_storage ]
```

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var decompose = require( '@stdlib/fft/base/fftpack/decompose' );

var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK
var factors = [ 0, 0, 0, 0 ];

var nf = decompose( 12, 4, initial, 1, 0, factors, 1, 0 );

console.log( 'Sequence length: %d', 12 );
console.log( 'Number of factors: %d', nf );

console.log( 'Factors:' );
var j;
for ( j = 0; j < nf; j++ ) {
console.log( ' %d', factors[ j+2 ] );
}
Comment thread
kgryte marked this conversation as resolved.
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var floor = require( '@stdlib/math/base/special/floor' );
var log2 = require( '@stdlib/math/base/special/log2' );
var zeros = require( '@stdlib/array/zeros' );
var pkg = require( './../package.json' ).name;
var decompose = require( './../lib' );


// VARIABLES //

var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - sequence length
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var factors = zeros( 2 + floor( log2( N ) ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var d;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = decompose( N, 4, initial, 1, 0, factors, 1, 0 );
if ( isnan( d ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( d ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var lengths;
var N;
var f;
var i;

lengths = [
12,
24,
36,
48,
60,
120
];

for ( i = 0; i < lengths.length; i++ ) {
N = lengths[ i ];
f = createBenchmark( N );
bench( format( '%s:N=%d', pkg, N ), f );
}
}

main();
55 changes: 55 additions & 0 deletions lib/node_modules/@stdlib/fft/base/fftpack/decompose/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

{{alias}}( N, M, initial, si, oi, out, so, oo )
Factorizes a sequence length into a product of integers.

Factorization results are stored in the output array sequentially, where
the first element contains the sequence length N, the second element
contains the number of factors into which N was decomposed, and subsequent
elements contain the individual integer factors.

Any remaining array space remains as unused storage.

Parameters
----------
N: integer
Length of the sequence.

M: integer
Number of trial divisors.

initial: ArrayLikeObject<number>
Array of initial trial divisors.

si: integer
Stride length for `initial`.

oi: integer
Starting index for `initial`.

out: ArrayLikeObject<number>
Output array for storing factorization results.

so: integer
Stride length for `out`.

oo: integer
Starting index for `out`.

Returns
-------
numFactors: integer
Number of factors into which N was decomposed.

Examples
--------
> var N = 630;
> var initial = [ 3, 4, 2, 5 ];
> var factors = [ 0, 0, 0, 0, 0, 0, 0 ];
> var numFactors = {{alias}}( N, 4, initial, 1, 0, factors, 1, 0 )
5
> factors
[ 630, 5, 2, 3, 3, 5, 7 ]

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';

/**
* Factorizes a sequence length into a product of integers.
*
* @param N - length of the sequence
* @param M - number of trial divisors
* @param initial - array of initial trial divisors
* @param si - stride length for `initial`
* @param oi - starting index for `initial`
* @param out - output array for storing factorization results
* @param so - stride length for `out`
* @param oo - starting index for `out`
* @returns number of factors into which `N` was decomposed
*
* @example
* var initial = new Float64Array( [ 3, 4, 2, 5 ] );
* var factors = new Float64Array( 4 );
*
* var numFactors = decompose( 12, 4, initial, 1, 0, factors, 1, 0 );
* // returns 2
*/
declare function decompose( N: number, M: number, initial: Collection<number>, si: number, oi: number, out: Collection<number>, so: number, oo: number ): number;


// EXPORTS //

export = decompose;
Loading