Skip to content
Open
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
156 changes: 156 additions & 0 deletions lib/node_modules/@stdlib/fft/base/fftpack/rfftf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!--

@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.

-->

# rfftf

> Compute the forward real-valued fast Fourier transform (FFT).

<!-- 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 rfftf = require( '@stdlib/fft/base/fftpack/rfftf' );
```

#### rfftf( N, r, strideR, offsetR, workspace, strideW, offsetW )

Computes the forward real-valued fast Fourier transform (FFT).

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var rffti = require( '@stdlib/fft/base/fftpack/rffti' );

var N = 4;
var workspace = new Float64Array( ( 2*N ) + 34 );

rffti( N, workspace, 1, 0 );

var r = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );

rfftf( N, r, 1, 0, workspace, 1, 0 );

// r => <Float64Array>[ 10.0, -2.0, 2.0, -2.0 ]
```

The function accepts the following arguments:

- **N**: length of the sequence to transform.
- **r**: input array.
- **strideR**: stride length for `r`.
- **offsetR**: starting index for `r`.
- **workspace**: workspace array containing pre-computed values.
- **strideW**: stride length for `workspace`.
- **offsetW**: starting index for `workspace`.

</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

- Before calling this function, initialize the workspace by calling [`rffti`][@stdlib/fft/base/fftpack/rffti] with the same sequence length and workspace layout.

- The function performs the transform in-place and returns the same input array reference.

- For `N = 4`, the output

```text
[ 10.0, -2.0, 2.0, -2.0 ]
```

corresponds to a zero-frequency term `10.0`, a complex coefficient `-2.0 + 2.0i` at frequency `1`, and a Nyquist term `-2.0`.

- If `N` equals `1`, the function returns early without modifying the input, as a single data point is its own Fourier transform. In that case, the function still returns the same input array reference.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var zeros = require( '@stdlib/array/zeros' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var rffti = require( '@stdlib/fft/base/fftpack/rffti' );
var rfftf = require( '@stdlib/fft/base/fftpack/rfftf' );

var N = 4;
var opts = {
'dtype': 'float64'
};
var r = discreteUniform( N, -10, 10, opts );
var workspace = zeros( ( 2*N ) + 34 );

console.log( r );

rffti( N, workspace, 1, 0 );
rfftf( N, r, 1, 0, workspace, 1, 0 );

console.log( r );
```

</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">

[@stdlib/fft/base/fftpack/rffti]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fft/base/fftpack/rffti

</section>

<!-- /.links -->
138 changes: 138 additions & 0 deletions lib/node_modules/@stdlib/fft/base/fftpack/rfftf/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* @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 slice = require( '@stdlib/array/slice' );
var uniform = require( '@stdlib/random/array/uniform' );
var floor = require( '@stdlib/math/base/special/floor' );
var pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var dcopy = require( '@stdlib/blas/base/dcopy' );
var rffti = require( '@stdlib/fft/base/fftpack/rffti' );
var pkg = require( './../package.json' ).name;
var rfftf = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} iter - number of iterations
* @param {PositiveInteger} N - sequence length
* @returns {Function} benchmark function
*/
function createBenchmark( iter, N ) {
var workspace = new Float64Array( ( 2*N ) + 34 );
var x;
var i;

x = [];
for ( i = 0; i < iter; i++ ) {
x.push( uniform( N, -100.0, 100.0, options ) );
}

rffti( N, workspace, 1, 0 );
return benchmark;

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

xc = slice( x );
for ( i = 0; i < iter; i++ ) {
xc[ i ] = dcopy( N, x[ i ], 1, new Float64Array( N ), 1 );
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = rfftf( N, xc[ i ], 1, 0, workspace, 1, 0 );
if ( isnan( y[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y[ i%N ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

lengths = [
8,
16,
32,
64,
128,
256,
512,
1024
];

iter = 1e6;

for ( i = 0; i < lengths.length; i++ ) {
N = lengths[ i ];
f = createBenchmark( iter, N );
opts = {
'iterations': iter
};
bench( format( '%s:N=%d', pkg, N ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}

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

{{alias}}( N, r, strideR, offsetR, workspace, strideW, offsetW )
Computes the forward real-valued fast Fourier transform (FFT).

Before calling this function, initialize the workspace by calling
`@stdlib/fft/base/fftpack/rffti` with the same sequence length and workspace
layout.

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

r: ArrayLikeObject<number>
Input array.

strideR: integer
Stride length for `r`.

offsetR: integer
Starting index for `r`.

workspace: ArrayLikeObject<number>
Workspace array containing pre-computed values.

strideW: integer
Stride length for `workspace`.

offsetW: integer
Starting index for `workspace`.

Returns
-------
r: ArrayLikeObject<number>
Input array.

Examples
--------
> var rffti = require( '@stdlib/fft/base/fftpack/rffti' );
> var N = 4;
> var r = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var workspace = new {{alias:@stdlib/array/float64}}( ( 2*N ) + 34 );
> rffti( N, workspace, 1, 0 )
<Float64Array>
> var out = {{alias}}( N, r, 1, 0, workspace, 1, 0 )
<Float64Array>
> var bool = ( out === r )
true
> r
<Float64Array>[ 10.0, -2.0, 2.0, -2.0 ]

See Also
--------

Loading
Loading