Skip to content
Merged
159 changes: 159 additions & 0 deletions lib/node_modules/@stdlib/fft/fftpack/rffti/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!--

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

-->

# rffti

> Return an initialized one-dimensional workspace [ndarray][@stdlib/ndarray/ctor] for computing a real-valued discrete Fourier transform.

<section class="usage">

## Usage

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

#### rffti( n\[, options] )

Returns an initialized one-dimensional workspace [ndarray][@stdlib/ndarray/ctor] for computing a real-valued discrete Fourier transform.

```javascript
var getDType = require( '@stdlib/ndarray/dtype' );
var getShape = require( '@stdlib/ndarray/shape' );

var ws = rffti( 4 );
// returns <ndarray>

var dt = String( getDType( ws ) );
// returns 'float64'

var sh = getShape( ws );
// returns [ 42 ]
```

The function has the following parameters:

- **n**: sequence length.
- **options**: function options (_optional_).

The function accepts the following options:

- **dtype**: workspace [data type][@stdlib/ndarray/dtypes]. Must be a real-valued floating-point [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`.

To specify the workspace [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.

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

var ws = rffti( 4, {
'dtype': 'float32'
});
// returns <ndarray>

var dt = String( getDType( ws ) );
// returns 'float32'
```

#### rffti.assign( workspace, n )

Initializes a provided one-dimensional workspace [ndarray][@stdlib/ndarray/ctor] for computing a real-valued discrete Fourier transform.

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

var ws = zeros( [ 42 ], {
'dtype': 'float64'
});
// returns <ndarray>

var out = rffti.assign( ws, 4 );
// returns <ndarray>

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

The function has the following parameters:

- **workspace**: workspace [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued floating-point [data type][@stdlib/ndarray/dtypes].
- **n**: sequence length.

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The returned workspace [ndarray][@stdlib/ndarray/ctor] has a length of `(2*n) + 34`.
- The workspace contains precomputed twiddle factors and factorization data used by the FFTPACK forward and backward real-valued FFT routines.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var getDType = require( '@stdlib/ndarray/dtype' );
var getShape = require( '@stdlib/ndarray/shape' );
var rffti = require( '@stdlib/fft/fftpack/rffti' );

// Initialize a workspace for a sequence of length 8:
var ws = rffti( 8 );
console.log( 'dtype: %s', getDType( ws ) );
console.log( 'shape: [%s]', getShape( ws ).join( ', ' ) );

// Initialize a single-precision workspace:
var ws32 = rffti( 8, {
'dtype': 'float32'
});
console.log( 'dtype: %s', getDType( ws32 ) );
console.log( 'shape: [%s]', getShape( ws32 ).join( ', ' ) );
```

</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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var zeros = require( '@stdlib/ndarray/zeros' );
var pow = require( '@stdlib/math/base/special/pow' );
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 - sequence length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var ws = zeros( [ ( 2*len ) + 34 ], options );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = assign( ws, len );
if ( typeof out !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( out ) ) {
b.fail( 'should return an ndarray' );
}
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();
101 changes: 101 additions & 0 deletions lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var rffti = require( './../lib' );


// VARIABLES //

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


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - sequence length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
ws = rffti( len, options );
if ( typeof ws !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isndarrayLike( ws ) ) {
b.fail( 'should return an ndarray' );
}
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:dtype=%s,len=%d', pkg, options.dtype, len ), f );
}
}

main();
Loading
Loading