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

@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 discrete Fourier transform (DFT) of a real-valued double-precision floating-point sequence.

<!-- 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/float64/rfftf' );
```

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

Computes the forward discrete Fourier transform (DFT) of a real-valued double-precision floating-point sequence.

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

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

rffti( N, w, 1, 0 );

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

rfftf( N, r, 1, 0, w, 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. The function is most efficient when this value is a product of small prime numbers.
- **r**: input array.
- **strideR**: stride length for `r`.
- **offsetR**: starting index for `r`.
- **w**: workspace array containing pre-computed values.
- **strideW**: stride length for `w`.
- **offsetW**: starting index for `w`.

</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/float64/rffti] with the same sequence length and workspace layout.

- The function performs the transform in-place (i.e., the input array is **mutated**).

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

- This transform is unnormalized as a call to this function followed by a call performing a [backward transform][@stdlib/fft/base/fftpack/float64/rfftb] will multiply the input array by `N`.

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

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

console.log( r );

rffti( N, w, 1, 0 );
rfftf( N, r, 1, 0, w, 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/float64/rffti]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fft/base/fftpack/float64/rffti

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

</section>

<!-- /.links -->
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/float64/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 w;
var x;
var i;

x = [];
for ( i = 0; i < iter; i++ ) {
x.push( uniform( N, -100.0, 100.0, options ) );
}
w = new Float64Array( ( 2*N ) + 34 );
rffti( N, w, 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, w, 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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

{{alias}}( N, r, strideR, offsetR, w, strideW, offsetW )
Computes the forward discrete Fourier transform (DFT) of a real-valued
double-precision floating-point sequence.

Before calling this function, one must first initialize the workspace array
using the corresponding initialization function with the same sequence
length and workspace layout.

This transform is unnormalized as a call to this function followed by a call
performing a backward transform will multiply the input array by `N`.

Parameters
----------
N: integer
Length of the sequence to transform. The function is most efficient when
this value is a product of small prime numbers.

r: Float64Array
Input array.

strideR: integer
Stride length for `r`.

offsetR: integer
Starting index for `r`.

w: Float64Array
Workspace array containing pre-computed values.

strideW: integer
Stride length for `w`.

offsetW: integer
Starting index for `w`.

Returns
-------
r: Float64Array
Input array.

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

See Also
--------

Loading
Loading