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

@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

> Return a new [ndarray][@stdlib/ndarray/ctor] containing the one-dimensional discrete Fourier transform of a real-valued input [ndarray][@stdlib/ndarray/ctor].

<section class="usage">

## Usage

```javascript
var rfftf = require( '@stdlib/fft/rfftf' );
```

#### rfftf( x\[, options] )

Returns a new [ndarray][@stdlib/ndarray/ctor] containing the one-dimensional discrete Fourier transform of a real-valued input [ndarray][@stdlib/ndarray/ctor].

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );

var out = rfftf( x );
// returns <ndarray>
```

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes].
- **options**: function options (_optional_).

The function accepts the following options:

- **n**: number of points over which to compute the transform. If not provided, defaults to the length of the input [ndarray][@stdlib/ndarray/ctor]. If `n` is greater than the input length, the input is zero-padded. If `n` is less than the input length, the input is truncated.
- **normalize**: normalization mode. Must be one of the following: `'backward'` (default), `'ortho'`, or `'forward'`.

The returned [ndarray][@stdlib/ndarray/ctor] has a complex-valued floating-point [data type][@stdlib/ndarray/dtypes] determined by the input [data type][@stdlib/ndarray/dtypes]. For example, `float64` maps to `complex128`. The returned [ndarray][@stdlib/ndarray/ctor] has a length of `floor(N/2) + 1`, where `N` is the length of the sequence to transform.

By default, the number of transform points equals the length of the input [ndarray][@stdlib/ndarray/ctor]. To specify a different number of transform points, provide an `n` option.

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );

var out = rfftf( x, {
'n': 8
});
// returns <ndarray>
```

By default, no normalization is applied to the transform result. To specify a normalization mode, provide a `normalize` option.

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );

// Scale by 1/sqrt(N):
var out = rfftf( x, {
'normalize': 'ortho'
});
// returns <ndarray>
```

The normalization modes are as follows:

- **backward**: no normalization (default).
- **ortho**: scale by `1/sqrt(N)`, making the transform orthonormal.
- **forward**: scale by `1/N`.

#### rfftf.assign( x, out\[, options] )

Computes the one-dimensional discrete Fourier transform of a real-valued input [ndarray][@stdlib/ndarray/ctor] and assigns the results to a provided output [ndarray][@stdlib/ndarray/ctor].

```javascript
var zeros = require( '@stdlib/ndarray/zeros' );
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = zeros( [ 3 ], {
'dtype': 'complex128'
});

var v = rfftf.assign( x, out );
// returns <ndarray>

var bool = ( v === out );
// returns true
```

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes].
- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a complex-valued floating-point [data type][@stdlib/ndarray/dtypes].
- **options**: function options (_optional_).

The function accepts the following options:

- **n**: number of points over which to compute the transform. If not provided, defaults to the length of the input [ndarray][@stdlib/ndarray/ctor]. If `n` is greater than the input length, the input is zero-padded. If `n` is less than the input length, the input is truncated.
- **normalize**: normalization mode. Must be one of the following: `'backward'` (default), `'ortho'`, or `'forward'`.

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The function does **not** mutate the input [ndarray][@stdlib/ndarray/ctor].
- The output [ndarray][@stdlib/ndarray/ctor] contains only the non-negative frequency terms of the full DFT, exploiting the Hermitian symmetry of real-valued input. For an input of length `N`, the output has length `floor(N/2) + 1`.
- The output [ndarray][@stdlib/ndarray/ctor] has a complex-valued floating-point [data type][@stdlib/ndarray/dtypes] determined by the input [data type][@stdlib/ndarray/dtypes]. For example, `float64` input maps to `complex128` output.
- The DC component (index `0`) and, for even-length transforms, the Nyquist component (last index) are always purely real (i.e., have zero imaginary parts).
- This transform is unnormalized by default. A call to this function followed by a call performing a backward transform will multiply the input by `N`. To obtain an orthonormal transform, set the `normalize` option to `'ortho'`.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var uniform = require( '@stdlib/random/uniform' );
var rfftf = require( '@stdlib/fft/rfftf' );

// Generate an ndarray of random numbers:
var x = uniform( [ 8 ], -10.0, 10.0, {
'dtype': 'float64'
});
console.log( ndarray2array( x ) );

// Perform operation:
var out = rfftf( x );

// Print the results:
console.log( ndarray2array( out ) );
```

</section>

<!-- /.examples -->

<!-- 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/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

</section>

<!-- /.links -->
118 changes: 118 additions & 0 deletions lib/node_modules/@stdlib/fft/rfftf/benchmark/benchmark.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var uniform = require( '@stdlib/random/uniform' );
var zeros = require( '@stdlib/ndarray/zeros' );
var getData = require( '@stdlib/ndarray/base/data-buffer' );
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var assign = require( './../lib/assign.js' );


// VARIABLES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out;
var M;
var x;

M = floor( len/2 ) + 1;
x = uniform( [ len ], -50.0, 50.0, options );
out = zeros( [ M ], {
'dtype': 'complex128'
});

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
o = assign( x, out );
if ( typeof o !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
view = reinterpret128( getData( o ), 0 );
if ( isnan( view[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f );
}
}

main();
Loading
Loading