|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# decompose |
| 22 | + |
| 23 | +> Factorize a sequence length into a product of integers. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### decompose( N, initial, out, stride, offset ) |
| 44 | + |
| 45 | +Factorizes a sequence length into a product of integers. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var initial = [ 3, 4, 2, 5 ]; // as found in FFTPACK |
| 49 | +var N = 630; |
| 50 | +var factors = [ 0, 0, 0, 0, 0, 0, 0 ]; |
| 51 | + |
| 52 | +var numFactors = decompose( N, initial, factors, 1, 0 ); |
| 53 | +// returns 5 |
| 54 | + |
| 55 | +console.log( factors ); |
| 56 | +// => [ 630, 5, 2, 3, 3, 5, 7 ] |
| 57 | +``` |
| 58 | + |
| 59 | +The function accepts the following arguments: |
| 60 | + |
| 61 | +- **N**: length of the sequence. |
| 62 | +- **initial**: array of initial trial divisors. |
| 63 | +- **out**: output array for storing factorization results. |
| 64 | +- **stride**: stride length for `out`. |
| 65 | +- **offset**: starting index for `out`. |
| 66 | + |
| 67 | +The function returns the number of factors into which `N` was decomposed. |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.usage --> |
| 72 | + |
| 73 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 74 | + |
| 75 | +<section class="notes"> |
| 76 | + |
| 77 | +## Notes |
| 78 | + |
| 79 | +- Factorization results are stored in the output array as follows: |
| 80 | + |
| 81 | + ```text |
| 82 | + [ sequence_length | number_of_factors | integer_factors | unused_storage ] |
| 83 | + ``` |
| 84 | +
|
| 85 | +- The function mutates the input array. |
| 86 | +
|
| 87 | +</section> |
| 88 | +
|
| 89 | +<!-- /.notes --> |
| 90 | +
|
| 91 | +<section class="examples"> |
| 92 | +
|
| 93 | +## Examples |
| 94 | +
|
| 95 | +<!-- eslint no-undef: "error" --> |
| 96 | +
|
| 97 | +```javascript |
| 98 | +var decompose = require( '@stdlib/fft/base/fftpack/decompose' ); |
| 99 | +
|
| 100 | +var factors = [ 0, 0, 0, 0 ]; |
| 101 | +var initial = [ 3, 4, 2, 5 ]; |
| 102 | +var nf; |
| 103 | +var j; |
| 104 | +
|
| 105 | +for ( j = 0; j < factors.length; j++ ) { |
| 106 | + factors[ j ] = 0; |
| 107 | +} |
| 108 | +
|
| 109 | +nf = decompose( 12, initial, factors, 1, 0 ); |
| 110 | +
|
| 111 | +console.log( 'Sequence length: %d', 12 ); |
| 112 | +console.log( 'Number of factors: %d', nf ); |
| 113 | +console.log( 'Factors:' ); |
| 114 | +for ( j = 0; j < nf; j++ ) { |
| 115 | + console.log( ' %d', factors[ j+2 ] ); |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.examples --> |
| 122 | + |
| 123 | +<!-- 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. --> |
| 124 | + |
| 125 | +<section class="references"> |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.references --> |
| 130 | + |
| 131 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 132 | + |
| 133 | +<section class="related"> |
| 134 | + |
| 135 | +</section> |
| 136 | + |
| 137 | +<!-- /.related --> |
| 138 | + |
| 139 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 140 | + |
| 141 | +<section class="links"> |
| 142 | + |
| 143 | +</section> |
| 144 | + |
| 145 | +<!-- /.links --> |
0 commit comments