Skip to content

Commit c323438

Browse files
committed
chore: add tests, docs, examples, benchmark for rffti
--- 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: na - task: lint_repl_help status: na - 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 ---
1 parent 66a24b7 commit c323438

File tree

9 files changed

+682
-6
lines changed

9 files changed

+682
-6
lines changed

lib/node_modules/@stdlib/fft/base/fftpack/decompose/examples/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ var initial = [ 3, 4, 2, 5 ];
2525
var nf;
2626
var j;
2727

28-
for ( j = 0; j < factors.length; j++ ) {
29-
factors[ j ] = 0;
30-
}
31-
3228
nf = decompose( 12, initial, factors, 1, 0 );
3329

3430
console.log( 'Sequence length: %d', 12 );
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
# rffti
22+
23+
> Initialize a workspace array for performing a real-valued Fourier transform.
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 rffti = require( '@stdlib/fft/base/fftpack/rffti' );
41+
```
42+
43+
#### rffti( N, workspace, strideW, offsetW )
44+
45+
Initializes a workspace array for performing a real-valued Fourier transform.
46+
47+
```javascript
48+
var Float64Array = require( '@stdlib/array/float64' );
49+
var workspace;
50+
var N = 8;
51+
52+
workspace = new Float64Array( (2*N) + 34 );
53+
rffti( N, workspace, 1, 0 );
54+
```
55+
56+
The function accepts the following arguments:
57+
58+
- **N**: length of the sequence to transform.
59+
- **workspace**: workspace array.
60+
- **strideW**: stride length for `workspace`.
61+
- **offsetW**: starting index for `workspace`.
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
68+
69+
<section class="notes">
70+
71+
## Notes
72+
73+
- The workspace array should have a length of at least `(2*N) + 34` elements.
74+
- For single-point sequences ( N=1 ), the function returns immediately as the FFT is the identity operation.
75+
76+
</section>
77+
78+
<!-- /.notes -->
79+
80+
<section class="examples">
81+
82+
## Examples
83+
84+
<!-- eslint no-undef: "error" -->
85+
86+
```javascript
87+
var Float64Array = require( '@stdlib/array/float64' );
88+
var rffti = require( '@stdlib/fft/base/fftpack/rffti' );
89+
90+
var workspace;
91+
var N = 8;
92+
var i;
93+
94+
workspace = new Float64Array( (2*N) + 34 );
95+
96+
rffti( N, workspace, 1, 0 );
97+
98+
console.log( 'Sequence length: %d', N );
99+
console.log( 'Workspace array:' );
100+
for ( i = 0; i < workspace.length; i++ ) {
101+
console.log( ' %d: %d', i, workspace[ i ] );
102+
}
103+
```
104+
105+
</section>
106+
107+
<!-- /.examples -->
108+
109+
<!-- 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. -->
110+
111+
<section class="references">
112+
113+
</section>
114+
115+
<!-- /.references -->
116+
117+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
118+
119+
<section class="related">
120+
121+
</section>
122+
123+
<!-- /.related -->
124+
125+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="links">
128+
129+
</section>
130+
131+
<!-- /.links -->
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var pkg = require( './../package.json' ).name;
26+
var rffti = require( './../lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Creates a benchmark function.
33+
*
34+
* @private
35+
* @param {PositiveInteger} N - sequence length to transform
36+
* @returns {Function} benchmark function
37+
*/
38+
function createBenchmark( N ) {
39+
return benchmark;
40+
41+
/**
42+
* Benchmark function.
43+
*
44+
* @private
45+
* @param {Benchmark} b - benchmark instance
46+
*/
47+
function benchmark( b ) {
48+
var workspace;
49+
var i;
50+
51+
workspace = new Float64Array( (2*N) + 34 );
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
rffti( N, workspace, 1, 0 );
56+
if ( workspace[ 2*N ] !== N ) {
57+
b.fail( 'unexpected result' );
58+
}
59+
}
60+
b.toc();
61+
62+
if ( workspace[ 2*N ] !== N ) {
63+
b.fail( 'unexpected result' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var lengths;
80+
var N;
81+
var f;
82+
var i;
83+
84+
lengths = [
85+
8,
86+
16,
87+
32,
88+
64,
89+
128
90+
];
91+
92+
for ( i = 0; i < lengths.length; i++ ) {
93+
N = lengths[ i ];
94+
f = createBenchmark( N );
95+
bench( pkg+':N='+N, f );
96+
}
97+
}
98+
99+
main();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* Initializes a workspace array for performing a real-valued Fourier transform.
25+
*
26+
* ## Notes
27+
*
28+
* - The workspace array should have a length of at least `(2*N) + 34` elements.
29+
* - For single-point sequences (N=1), the function returns immediately as the FFT is the identity operation.
30+
*
31+
* @param N - length of the sequence to transform
32+
* @param workspace - workspace array
33+
* @param strideW - stride length for `workspace`
34+
* @param offsetW - starting index for `workspace`
35+
*
36+
* @example
37+
* // Define a sequence length:
38+
* var N = 8;
39+
*
40+
* // Initialize a workspace array:
41+
* var workspace = new Float64Array( (2*N) + 34 );
42+
*
43+
* rffti( N, workspace, 1, 0 );
44+
*
45+
* var f = workspace.slice();
46+
* // returns <Float64Array>[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.7071067811865476, 0.7071067811865475, 0, 0, 0, 0, 8, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
47+
*/
48+
declare function rffti( N: number, workspace: Float64Array, strideW: number, offsetW: number ): void;
49+
50+
51+
// EXPORTS //
52+
53+
export = rffti;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import rffti = require( './index' );
20+
21+
// TESTS //
22+
23+
// The function returns void...
24+
{
25+
const workspace = new Float64Array( 50 );
26+
rffti( 8, workspace, 1, 0 ); // $ExpectType void
27+
}
28+
29+
// The compiler throws an error if the function is provided a sequence length which is not a number...
30+
{
31+
const workspace = new Float64Array( 50 );
32+
33+
rffti( '12', workspace, 1, 0 ); // $ExpectError
34+
rffti( true, workspace, 1, 0 ); // $ExpectError
35+
rffti( false, workspace, 1, 0 ); // $ExpectError
36+
rffti( null, workspace, 1, 0 ); // $ExpectError
37+
rffti( undefined, workspace, 1, 0 ); // $ExpectError
38+
rffti( [], workspace, 1, 0 ); // $ExpectError
39+
rffti( {}, workspace, 1, 0 ); // $ExpectError
40+
rffti( ( x: number ): number => x, workspace, 1, 0 ); // $ExpectError
41+
}
42+
43+
// The compiler throws an error if the function is provided a workspace which is not a Float64Array...
44+
{
45+
rffti( 8, '4,2,3,5', 1, 0 ); // $ExpectError
46+
rffti( 8, 5, 1, 0 ); // $ExpectError
47+
rffti( 8, true, 1, 0 ); // $ExpectError
48+
rffti( 8, false, 1, 0 ); // $ExpectError
49+
rffti( 8, null, 1, 0 ); // $ExpectError
50+
rffti( 8, undefined, 1, 0 ); // $ExpectError
51+
rffti( 8, [], 1, 0 ); // $ExpectError
52+
rffti( 8, {}, 1, 0 ); // $ExpectError
53+
rffti( 8, ( x: number ): number => x, 1, 0 ); // $ExpectError
54+
}
55+
56+
// The compiler throws an error if the function is provided a stride which is not a number...
57+
{
58+
const workspace = new Float64Array( 50 );
59+
60+
rffti( 8, workspace, '1', 0 ); // $ExpectError
61+
rffti( 8, workspace, true, 0 ); // $ExpectError
62+
rffti( 8, workspace, false, 0 ); // $ExpectError
63+
rffti( 8, workspace, null, 0 ); // $ExpectError
64+
rffti( 8, workspace, undefined, 0 ); // $ExpectError
65+
rffti( 8, workspace, [], 0 ); // $ExpectError
66+
rffti( 8, workspace, {}, 0 ); // $ExpectError
67+
rffti( 8, workspace, ( x: number ): number => x, 0 ); // $ExpectError
68+
}
69+
70+
// The compiler throws an error if the function is provided an offset which is not a number...
71+
{
72+
const workspace = new Float64Array( 50 );
73+
74+
rffti( 8, workspace, 1, '0' ); // $ExpectError
75+
rffti( 8, workspace, 1, true ); // $ExpectError
76+
rffti( 8, workspace, 1, false ); // $ExpectError
77+
rffti( 8, workspace, 1, null ); // $ExpectError
78+
rffti( 8, workspace, 1, undefined ); // $ExpectError
79+
rffti( 8, workspace, 1, [] ); // $ExpectError
80+
rffti( 8, workspace, 1, {} ); // $ExpectError
81+
rffti( 8, workspace, 1, ( x: number ): number => x ); // $ExpectError
82+
}
83+
84+
// The compiler throws an error if the function is provided an unsupported number of arguments...
85+
{
86+
const workspace = new Float64Array( 50 );
87+
88+
rffti(); // $ExpectError
89+
rffti( 8 ); // $ExpectError
90+
rffti( 8, workspace ); // $ExpectError
91+
rffti( 8, workspace, 1 ); // $ExpectError
92+
rffti( 8, workspace, 1, 0, 123 ); // $ExpectError
93+
}

0 commit comments

Comments
 (0)