From a575f0b8cdb3bb817a9e26126d51579963730828 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Mon, 21 Sep 2026 19:30:19 +0530 Subject: [PATCH] feat: add fft/base/fftpack/ndarray/generic/rfftf --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - 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 --- --- .../fftpack/ndarray/generic/rfftf/README.md | 155 ++++++++++ .../generic/rfftf/benchmark/benchmark.js | 144 +++++++++ .../ndarray/generic/rfftf/docs/repl.txt | 42 +++ .../generic/rfftf/docs/types/index.d.ts | 69 +++++ .../ndarray/generic/rfftf/docs/types/test.ts | 63 ++++ .../ndarray/generic/rfftf/examples/index.js | 44 +++ .../ndarray/generic/rfftf/lib/index.js | 56 ++++ .../fftpack/ndarray/generic/rfftf/lib/main.js | 79 +++++ .../ndarray/generic/rfftf/package.json | 63 ++++ .../ndarray/generic/rfftf/test/test.js | 285 ++++++++++++++++++ 10 files changed, 1000 insertions(+) create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/README.md create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/examples/index.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/index.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/main.js create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/package.json create mode 100644 lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/test/test.js diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/README.md new file mode 100644 index 000000000000..2475084b277a --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/README.md @@ -0,0 +1,155 @@ + + +# rfftf + +> Compute the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var rfftf = require( '@stdlib/fft/base/fftpack/ndarray/generic/rfftf' ); +``` + +#### rfftf( arrays ) + +Computes the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); + +var N = 4; +var len = scalar2ndarray( N, { + 'dtype': 'int32' +}); + +var w = new Float64Vector( ( 2*N ) + 34 ); +rffti( [ w, len ] ); + +var r = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); + +var out = rfftf( [ r, w ] ); +// returns [ 10.0, -2.0, 2.0, -2.0 ] + +var bool = ( out === r ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional workspace ndarray containing pre-computed values. + +
+ + + +
+ +## Notes + +- Before calling this function, initialize the workspace ndarray by calling [`rffti`][@stdlib/fft/base/fftpack/ndarray/generic/rffti] with the same sequence length and workspace layout. + +- The function performs the transform in-place (i.e., the input ndarray 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/ndarray/generic/rfftb] will multiply the input ndarray by `N`. + +
+ + + +
+ +## Examples + + + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/ndarray/generic/rfftf' ); + +var N = 4; +var r = discreteUniform( [ N ], -10, 10, { + 'dtype': 'generic' +}); +var w = zeros( [ ( 2*N ) + 34 ], { + 'dtype': 'generic' +}); +var len = scalar2ndarray( N, { + 'dtype': 'int32' +}); + +console.log( ndarray2array( r ) ); + +rffti( [ w, len ] ); +var out = rfftf( [ r, w ] ); + +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/benchmark/benchmark.js b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/benchmark/benchmark.js new file mode 100644 index 000000000000..28f134fb3d23 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/benchmark/benchmark.js @@ -0,0 +1,144 @@ +/** +* @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 uniform = require( '@stdlib/random/uniform' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var copy = require( '@stdlib/ndarray/copy' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +var pkg = require( './../package.json' ).name; +var rfftf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; +var nopts = { + 'dtype': 'int32' +}; + + +// 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 len; + var x; + var w; + var i; + + x = []; + for ( i = 0; i < iter; i++ ) { + x.push( uniform( [ N ], -100.0, 100.0, options ) ); + } + len = scalar2ndarray( N, nopts ); + w = zeros( [ ( 2*N ) + 34 ], options ); + rffti( [ w, len ] ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xc; + var v; + var i; + + xc = []; + for ( i = 0; i < iter; i++ ) { + xc.push( copy( x[ i ] ) ); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rfftf( [ xc[ i ], w ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( v.get( 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(); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/repl.txt new file mode 100644 index 000000000000..eb76321f5f95 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( arrays ) + Computes the forward discrete Fourier transform (DFT) of a real-valued + one-dimensional ndarray. + + Before calling this function, one must first initialize the workspace + ndarray 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 ndarray by the + sequence length. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional workspace ndarray containing pre-computed values. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var N = 4; + > var opts = { 'dtype': 'int32' }; + > var len = {{alias:@stdlib/ndarray/from-scalar}}( N, opts ); + > var w = new {{alias:@stdlib/ndarray/vector/float64}}( ( 2*N ) + 34 ); + > {{alias:@stdlib/fft/base/fftpack/ndarray/generic/rffti}}( [ w, len ] ); + > var r = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var out = {{alias}}( [ r, w ] ) + [ 10.0, -2.0, 2.0, -2.0 ] + > var bool = ( out === r ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/index.d.ts new file mode 100644 index 000000000000..57a622d57e65 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/index.d.ts @@ -0,0 +1,69 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { floatndarray, genericndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = floatndarray | genericndarray; + +/** +* Computes the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional workspace ndarray containing pre-computed values. +* +* @param arrays - array-like object containing ndarrays +* @returns input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +* +* var N = 4; +* var len = scalar2ndarray( N, { +* 'dtype': 'int32' +* }); +* +* var w = new Float64Vector( ( 2*N ) + 34 ); +* rffti( [ w, len ] ); +* +* var r = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = rfftf( [ r, w ] ); +* // returns [ 10.0, -2.0, 2.0, -2.0 ] +* +* var bool = ( out === r ); +* // returns true +*/ +declare function rfftf( arrays: [ T, InputArray ] ): T; + + +// EXPORTS // + +export = rfftf; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/test.ts new file mode 100644 index 000000000000..93755172ed77 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/docs/types/test.ts @@ -0,0 +1,63 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import rfftf = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const r = zeros( [ 4 ], { + 'dtype': 'float64' + }); + const w = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + rfftf( [ r, w ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + rfftf( '10' ); // $ExpectError + rfftf( 10 ); // $ExpectError + rfftf( true ); // $ExpectError + rfftf( false ); // $ExpectError + rfftf( null ); // $ExpectError + rfftf( undefined ); // $ExpectError + rfftf( [] ); // $ExpectError + rfftf( {} ); // $ExpectError + rfftf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const r = zeros( [ 4 ], { + 'dtype': 'float64' + }); + const w = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + rfftf(); // $ExpectError + rfftf( [ r, w ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/examples/index.js new file mode 100644 index 000000000000..14a695b25852 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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'; + +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +var rfftf = require( './../lib' ); + +var N = 4; +var r = discreteUniform( [ N ], -10, 10, { + 'dtype': 'generic' +}); +var w = zeros( [ ( 2*N ) + 34 ], { + 'dtype': 'generic' +}); +var len = scalar2ndarray( N, { + 'dtype': 'int32' +}); + +console.log( ndarray2array( r ) ); + +rffti( [ w, len ] ); +var out = rfftf( [ r, w ] ); + +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/index.js new file mode 100644 index 000000000000..817efe988e81 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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'; + +/** +* Compute the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray. +* +* @module @stdlib/fft/base/fftpack/ndarray/generic/rfftf +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +* var rfftf = require( '@stdlib/fft/base/fftpack/ndarray/generic/rfftf' ); +* +* var N = 4; +* var len = scalar2ndarray( N, { +* 'dtype': 'int32' +* }); +* +* var w = new Float64Vector( ( 2*N ) + 34 ); +* rffti( [ w, len ] ); +* +* var r = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = rfftf( [ r, w ] ); +* // returns [ 10.0, -2.0, 2.0, -2.0 ] +* +* var bool = ( out === r ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/main.js new file mode 100644 index 000000000000..88e01e41a025 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/lib/main.js @@ -0,0 +1,79 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/fft/base/fftpack/generic/rfftf' ); + + +// MAIN // + +/** +* Computes the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional workspace ndarray containing pre-computed values. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarrayLike} input ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +* +* var N = 4; +* var len = scalar2ndarray( N, { +* 'dtype': 'int32' +* }); +* +* var w = new Float64Vector( ( 2*N ) + 34 ); +* rffti( [ w, len ] ); +* +* var r = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* +* var out = rfftf( [ r, w ] ); +* // returns [ 10.0, -2.0, 2.0, -2.0 ] +* +* var bool = ( out === r ); +* // returns true +*/ +function rfftf( arrays ) { + var r; + var w; + + r = arrays[ 0 ]; + w = arrays[ 1 ]; + strided( numelDimension( r, 0 ), getData( r ), getStride( r, 0 ), getOffset( r ), getData( w ), getStride( w, 0 ), getOffset( w ) ); // eslint-disable-line max-len + return r; +} + + +// EXPORTS // + +module.exports = rfftf; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/package.json b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/package.json new file mode 100644 index 000000000000..260d52ebbc9f --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/fft/base/fftpack/ndarray/generic/rfftf", + "version": "0.0.0", + "description": "Compute the forward discrete Fourier transform (DFT) of a real-valued one-dimensional ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "fft", + "fftpack", + "rfftf", + "fourier", + "transform", + "forward", + "real", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/test/test.js new file mode 100644 index 000000000000..c59e23d0666e --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/ndarray/generic/rfftf/test/test.js @@ -0,0 +1,285 @@ +/** +* @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 tape = require( 'tape' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var rffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +var rfftf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rfftf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( rfftf.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the forward discrete Fourier transform of a real-valued one-dimensional ndarray', function test( t ) { + var expected; + var wBuf; + var rBuf; + var len; + var N; + var w; + var r; + var v; + + N = 4; + len = scalar2ndarray( N, { + 'dtype': 'int32' + }); + rBuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + r = vector( rBuf, N, 1, 0 ); + + wBuf = new Float64Array( ( 2*N ) + 34 ); + w = vector( wBuf, ( 2*N ) + 34, 1, 0 ); + + rffti( [ w, len ] ); + v = rfftf( [ r, w ] ); + + expected = new Float64Array( [ 10.0, -2.0, 2.0, -2.0 ] ); + + t.strictEqual( v, r, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns the input ndarray unchanged', function test( t ) { + var expected; + var wBuf; + var rBuf; + var len; + var N; + var w; + var r; + var v; + + N = 4; + len = scalar2ndarray( N, { + 'dtype': 'int32' + }); + rBuf = new Float64Array( [] ); + r = vector( rBuf, 0, 1, 0 ); + + wBuf = new Float64Array( ( 2*N ) + 34 ); + w = vector( wBuf, ( 2*N ) + 34, 1, 0 ); + + rffti( [ w, len ] ); + v = rfftf( [ r, w ] ); + + expected = new Float64Array( [] ); + t.strictEqual( v, r, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a one-dimensional ndarray having a non-unit stride', function test( t ) { + var expected; + var wBuf; + var rBuf; + var ulps; + var len; + var N; + var w; + var r; + var v; + var i; + + N = 4; + len = scalar2ndarray( N, { + 'dtype': 'int32' + }); + rBuf = new Float64Array([ + 1.0, // 0 + -999.0, + 2.0, // 1 + -999.0, + 3.0, // 2 + -999.0, + 4.0, // 3 + -999.0 + ]); + r = vector( rBuf, N, 2, 0 ); + + wBuf = new Float64Array( ( ( 2*N ) + 34 ) * 2 ); + w = vector( wBuf, ( 2*N ) + 34, 2, 0 ); + + rffti( [ w, len ] ); + rfftf( [ r, w ] ); + + expected = new Float64Array([ + 10.0, // 0 + -999.0, + -2.0, // 1 + -999.0, + 2.0, // 2 + -999.0, + -2.0, // 3 + -999.0 + ]); + + ulps = 1; + for ( i = 0; i < rBuf.length; i++ ) { + v = rBuf[ i ]; + t.strictEqual( isAlmostSameValue( v, expected[ i ], ulps ), true, 'within ' + ulps + ' ULPs. index: ' + i + '. y: ' + v + '. E: ' + expected[ i ] ); + } + + t.end(); +}); + +tape( 'the function supports a one-dimensional ndarray having a negative stride', function test( t ) { + var expected; + var wBuf; + var rBuf; + var ulps; + var len; + var N; + var w; + var r; + var v; + var i; + + N = 4; + len = scalar2ndarray( N, { + 'dtype': 'int32' + }); + rBuf = new Float64Array([ + 4.0, // 3 + -999.0, + 3.0, // 2 + -999.0, + 2.0, // 1 + -999.0, + 1.0 // 0 + ]); + r = vector( rBuf, N, -2, rBuf.length-1 ); + + wBuf = new Float64Array( ( 2*N ) + 34 ); + w = vector( wBuf, ( 2*N ) + 34, -1, wBuf.length-1 ); + + rffti( [ w, len ] ); + rfftf( [ r, w ] ); + + expected = new Float64Array([ + -2.0, // 3 + -999.0, + 2.0, // 2 + -999.0, + -2.0, // 1 + -999.0, + 10.0 // 0 + ]); + + ulps = 1; + for ( i = 0; i < rBuf.length; i++ ) { + v = rBuf[ i ]; + t.strictEqual( isAlmostSameValue( v, expected[ i ], ulps ), true, 'within ' + ulps + ' ULPs. index: ' + i + '. y: ' + v + '. E: ' + expected[ i ] ); + } + + t.end(); +}); + +tape( 'the function supports a one-dimensional ndarray having a non-zero offset', function test( t ) { + var expected; + var wBuf; + var rBuf; + var ulps; + var len; + var N; + var w; + var r; + var v; + var i; + + N = 4; + len = scalar2ndarray( N, { + 'dtype': 'int32' + }); + rBuf = new Float64Array([ + -999.0, + 1.0, // 0 + -999.0, + 2.0, // 1 + -999.0, + 3.0, // 2 + -999.0, + 4.0, // 3 + -999.0 + ]); + r = vector( rBuf, N, 2, 1 ); + + wBuf = new Float64Array( 3 + ( ( ( 2*N ) + 34 ) * 2 ) ); + w = vector( wBuf, ( 2*N ) + 34, 2, 3 ); + + rffti( [ w, len ] ); + rfftf( [ r, w ] ); + + expected = new Float64Array([ + -999.0, + 10.0, // 0 + -999.0, + -2.0, // 1 + -999.0, + 2.0, // 2 + -999.0, + -2.0, // 3 + -999.0 + ]); + + ulps = 1; + for ( i = 0; i < rBuf.length; i++ ) { + v = rBuf[ i ]; + t.strictEqual( isAlmostSameValue( v, expected[ i ], ulps ), true, 'within ' + ulps + ' ULPs. index: ' + i + '. y: ' + v + '. E: ' + expected[ i ] ); + } + + t.end(); +});