diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/README.md b/lib/node_modules/@stdlib/fft/fftpack/rffti/README.md new file mode 100644 index 000000000000..4e1fbaa0c2ba --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/README.md @@ -0,0 +1,159 @@ + + +# rffti + +> Return an initialized one-dimensional workspace [ndarray][@stdlib/ndarray/ctor] for computing a real-valued discrete Fourier transform. + +
+ +## 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 + +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 + +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 + +var out = rffti.assign( ws, 4 ); +// returns + +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. + +
+ + + +
+ +## 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. + +
+ + + +
+ +## Examples + + + +```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( ', ' ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..14cc61d1578f --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.assign.js @@ -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(); diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.js new file mode 100644 index 000000000000..16f0268abe95 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/benchmark/benchmark.js @@ -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(); diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/repl.txt b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/repl.txt new file mode 100644 index 000000000000..3c065fe41b1e --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/repl.txt @@ -0,0 +1,58 @@ + +{{alias}}( n[, options] ) + Returns an initialized one-dimensional workspace ndarray for computing a + real-valued discrete Fourier transform. + + Parameters + ---------- + n: integer + Sequence length. + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output workspace ndarray data type. Must be a real-valued floating-point + data type. Default: 'float64'. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var out = {{alias}}( 4 ) + + + +{{alias}}.assign( workspace, n ) + Initializes a provided one-dimensional workspace ndarray for computing a + real-valued discrete Fourier transform. + + The function modifies the workspace ndarray in-place and thus mutates the + input ndarray. + + Parameters + ---------- + workspace: ndarray + Workspace ndarray. Must have a real-valued floating-point data type. + + n: integer + Sequence length. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var ws = {{alias:@stdlib/ndarray/zeros}}( [ 42 ], { 'dtype': 'float64' } ); + > var out = {{alias}}.assign( ws, 4 ) + + > var bool = ( out === ws ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/index.d.ts new file mode 100644 index 000000000000..18770cf3d46e --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/index.d.ts @@ -0,0 +1,115 @@ +/* +* @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 { RealFloatingPointDataType, floatndarray } from '@stdlib/types/ndarray'; + +/** +* Output array. +*/ +type OutputArray = floatndarray; + +/** +* Interface defining options. +*/ +interface Options { + /** + * Workspace data type. + */ + dtype?: RealFloatingPointDataType; +} + +/** +* Interface for initializing a workspace ndarray. +*/ +interface Rffti { + /** + * Returns an initialized one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. + * + * @param n - sequence length + * @param options - function options + * @returns output ndarray + * + * @example + * var getDType = require( '@stdlib/ndarray/dtype' ); + * + * var ws = rffti( 4 ); + * // returns + * + * var dt = String( getDType( ws ) ); + * // returns 'float64' + */ + ( n: number, options?: Options ): OutputArray; + + /** + * Initializes a provided one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. + * + * @param workspace - workspace ndarray + * @param n - sequence length + * @returns input ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var ws = zeros( [ 42 ], { 'dtype': 'float64' } ); + * + * var out = rffti.assign( ws, 4 ); + * // returns + * + * var bool = ( out === ws ); + * // returns true + */ + assign( workspace: T, n: number ): T; +} + +/** +* Returns an initialized one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. +* +* @param n - sequence length +* @param options - function options +* @returns output ndarray +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var ws = rffti( 4 ); +* // returns +* +* var dt = String( getDType( ws ) ); +* // returns 'float64' +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var ws = zeros( [ 42 ], { 'dtype': 'float64' } ); +* +* var out = rffti.assign( ws, 4 ); +* // returns +* +* var bool = ( out === ws ); +* // returns true +*/ +declare const rffti: Rffti; + + +// EXPORTS // + +export = rffti; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/test.ts b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/test.ts new file mode 100644 index 000000000000..5ccdd865d035 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/docs/types/test.ts @@ -0,0 +1,133 @@ +/* +* @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 rffti = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + rffti( 4 ); // $ExpectType floatndarray + rffti( 4, {} ); // $ExpectType floatndarray + rffti( 4, { 'dtype': 'float64' } ); // $ExpectType floatndarray + rffti( 4, { 'dtype': 'float32' } ); // $ExpectType floatndarray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + rffti( '5' ); // $ExpectError + rffti( true ); // $ExpectError + rffti( false ); // $ExpectError + rffti( null ); // $ExpectError + rffti( void 0 ); // $ExpectError + rffti( [] ); // $ExpectError + rffti( {} ); // $ExpectError + rffti( ( x: number ): number => x ); // $ExpectError + + rffti( '5', {} ); // $ExpectError + rffti( true, {} ); // $ExpectError + rffti( false, {} ); // $ExpectError + rffti( null, {} ); // $ExpectError + rffti( void 0, {} ); // $ExpectError + rffti( [], {} ); // $ExpectError + rffti( {}, {} ); // $ExpectError + rffti( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + rffti( 4, '5' ); // $ExpectError + rffti( 4, 5 ); // $ExpectError + rffti( 4, true ); // $ExpectError + rffti( 4, false ); // $ExpectError + rffti( 4, null ); // $ExpectError + rffti( 4, [] ); // $ExpectError + rffti( 4, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + rffti( 4, { 'dtype': '5' } ); // $ExpectError + rffti( 4, { 'dtype': 5 } ); // $ExpectError + rffti( 4, { 'dtype': true } ); // $ExpectError + rffti( 4, { 'dtype': false } ); // $ExpectError + rffti( 4, { 'dtype': null } ); // $ExpectError + rffti( 4, { 'dtype': [] } ); // $ExpectError + rffti( 4, { 'dtype': {} } ); // $ExpectError + rffti( 4, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + rffti(); // $ExpectError + rffti( 4, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const ws = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + rffti.assign( ws, 4 ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + rffti.assign( '5', 4 ); // $ExpectError + rffti.assign( 5, 4 ); // $ExpectError + rffti.assign( true, 4 ); // $ExpectError + rffti.assign( false, 4 ); // $ExpectError + rffti.assign( null, 4 ); // $ExpectError + rffti.assign( void 0, 4 ); // $ExpectError + rffti.assign( {}, 4 ); // $ExpectError + rffti.assign( ( x: number ): number => x, 4 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const ws = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + rffti.assign( ws, '5' ); // $ExpectError + rffti.assign( ws, true ); // $ExpectError + rffti.assign( ws, false ); // $ExpectError + rffti.assign( ws, null ); // $ExpectError + rffti.assign( ws, void 0 ); // $ExpectError + rffti.assign( ws, [] ); // $ExpectError + rffti.assign( ws, {} ); // $ExpectError + rffti.assign( ws, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const ws = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + rffti.assign(); // $ExpectError + rffti.assign( ws ); // $ExpectError + rffti.assign( ws, 4, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/examples/index.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/examples/index.js new file mode 100644 index 000000000000..7858dece30d8 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var rffti = require( './../lib' ); + +// 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( ', ' ) ); diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/assign.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/assign.js new file mode 100644 index 000000000000..e095a0c5b166 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/assign.js @@ -0,0 +1,83 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isvectorLike = require( '@stdlib/assert/is-vector-like' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var contains = require( '@stdlib/array/base/assert/contains' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var DTYPES = require( './dtypes.js' ).odtypes; +var base = require( './base.js' ); + + +// MAIN // + +/** +* Initializes a one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. +* +* @param {ndarrayLike} workspace - workspace ndarray +* @param {PositiveInteger} n - sequence length +* @throws {TypeError} first argument must be a one-dimensional ndarray-like object +* @throws {TypeError} first argument must have a supported data type +* @throws {TypeError} second argument must be a positive integer +* @returns {ndarray} input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var ws = zeros( [ 42 ], { 'dtype': 'float64' } ); +* +* var out = assign( ws, 4 ); +* // returns +* +* var bool = ( out === ws ); +* // returns true +*/ +function assign( workspace, n ) { + var dt; + + if ( !isvectorLike( workspace ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a one-dimensional ndarray. Value: `%s`.', workspace ) ); + } + dt = resolveStr( getDType( workspace ) ); + if ( !contains( DTYPES, dt ) ) { + throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( DTYPES, '", "' ), dt ) ); + } + if ( !isPositiveInteger( n ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) ); + } + + // Initialize the workspace: + base( workspace, scalar2ndarray( n, { + 'dtype': 'int32' + })); + + return workspace; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/base.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/base.js new file mode 100644 index 000000000000..9e6cf6acb19f --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/base.js @@ -0,0 +1,80 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); +var drffti = require( '@stdlib/fft/base/fftpack/ndarray/float64/rffti' ); +var srffti = require( '@stdlib/fft/base/fftpack/ndarray/float32/rffti' ); +var grffti = require( '@stdlib/fft/base/fftpack/ndarray/generic/rffti' ); +var DTYPES = require( './dtypes.js' ).odtypes; + + +// VARIABLES // + +var idtypes0 = dtypes( 'integer_and_generic' ); +var table = { + 'types': [ + 'float64', // workspace + 'float32' // workspace + ], + 'fcns': [ + drffti, + srffti + ], + 'default': grffti +}; + + +// MAIN // + +/** +* Initializes a one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. +* +* @private +* @name rffti +* @type {Function} +* @param {ndarray} workspace - workspace ndarray +* @param {ndarray} N - zero-dimensional ndarray containing the sequence length +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} first argument must have a supported data type +* @throws {TypeError} second argument must be an ndarray-like object +* @returns {ndarray} workspace ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var ws = zeros( [ 42 ], { +* 'dtype': 'float64' +* }); +* +* var out = rffti( ws, scalar2ndarray( 4, { +* 'dtype': 'int32' +* })); +* // returns +*/ +var rffti = factory( table, [ idtypes0 ], DTYPES ); + + +// EXPORTS // + +module.exports = rffti; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/defaults.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/defaults.js new file mode 100644 index 000000000000..e45486496685 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/defaults.js @@ -0,0 +1,38 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns default options. +* +* @private +* @returns {Object} default options +*/ +function defaults() { + return { + 'dtype': 'float64' + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/dtypes.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/dtypes.js new file mode 100644 index 000000000000..7833cdab61cc --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/dtypes.js @@ -0,0 +1,36 @@ +/** +* @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 dtypes2strings = require( '@stdlib/ndarray/base/dtypes2strings' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); + + +// MAIN // + +var dt = { + 'odtypes': dtypes2strings( dtypes( 'real_floating_point_and_generic' ) ) +}; + + +// EXPORTS // + +module.exports = dt; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/index.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/index.js new file mode 100644 index 000000000000..1820f27a9f2f --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/index.js @@ -0,0 +1,75 @@ +/** +* @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'; + +/** +* Return an initialized one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. +* +* @module @stdlib/fft/fftpack/rffti +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var rffti = require( '@stdlib/fft/fftpack/rffti' ); +* +* var ws = rffti( 4 ); +* // returns +* +* var dt = String( getDType( ws ) ); +* // returns 'float64' +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var rffti = require( '@stdlib/fft/fftpack/rffti' ); +* +* var ws = rffti( 4, { 'dtype': 'float32' } ); +* // returns +* +* var dt = String( getDType( ws ) ); +* // returns 'float32' +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var rffti = require( '@stdlib/fft/fftpack/rffti' ); +* +* var ws = zeros( [ 42 ], { 'dtype': 'float64' } ); +* +* var out = rffti.assign( ws, 4 ); +* // returns +* +* var bool = ( out === ws ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/main.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/main.js new file mode 100644 index 000000000000..64141d16ec64 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/lib/main.js @@ -0,0 +1,109 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var contains = require( '@stdlib/array/base/assert/contains' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var join = require( '@stdlib/array/base/join' ); +var format = require( '@stdlib/string/format' ); +var DTYPES = require( './dtypes.js' ).odtypes; +var defaults = require( './defaults.js' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns an initialized one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform. +* +* @param {PositiveInteger} n - sequence length +* @param {Options} [options] - function options +* @param {string} [options.dtype="float64"] - workspace data type +* @throws {TypeError} first argument must be a positive integer +* @throws {TypeError} options argument must be an object +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var ws = rffti( 4 ); +* // returns +* +* var dt = String( getDType( ws ) ); +* // returns 'float64' +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var ws = rffti( 4, { 'dtype': 'float32' } ); +* // returns +* +* var dt = String( getDType( ws ) ); +* // returns 'float32' +*/ +function rffti( n ) { + var options; + var opts; + var dt; + var ws; + + if ( !isPositiveInteger( n ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a positive integer. Value: `%s`.', n ) ); + } + options = defaults(); + + if ( arguments.length > 1 ) { + opts = arguments[ 1 ]; + if ( !isPlainObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'dtype' ) ) { + dt = resolveStr( opts.dtype ); + if ( !isDataType( opts.dtype ) || !contains( DTYPES, dt ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( DTYPES, '", "' ), opts.dtype ) ); + } + options.dtype = dt; + } + } + // Create the workspace ndarray: + ws = zeros( [ ( 2*n ) + 34 ], { + 'dtype': options.dtype + }); + + // Initialize the workspace: + base( ws, scalar2ndarray( n, { + 'dtype': 'int32' + })); + + return ws; +} + + +// EXPORTS // + +module.exports = rffti; diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/package.json b/lib/node_modules/@stdlib/fft/fftpack/rffti/package.json new file mode 100644 index 000000000000..a9525c73265d --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/fft/fftpack/rffti", + "version": "0.0.0", + "description": "Return an initialized one-dimensional workspace ndarray for computing a real-valued discrete Fourier transform.", + "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", + "stdmath", + "mathematics", + "math", + "fft", + "fourier", + "transform", + "workspace", + "initialize", + "rffti", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.assign.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.assign.js new file mode 100644 index 000000000000..ef2989eb0600 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.assign.js @@ -0,0 +1,251 @@ +/** +* @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 isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 4 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var i; + + values = [ + zeros( [ 42 ], { + 'dtype': 'int32' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, 4 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { + var values; + var ws; + var i; + + ws = zeros( [ 42 ], { + 'dtype': 'float64' + }); + + values = [ + '5', + -1, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( ws, value ); + }; + } +}); + +tape( 'the function initializes a provided float64 workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var ulps; + var out; + var buf; + var ws; + var N; + var y; + var e; + var i; + + N = 8; + ws = zeros( [ ( 2*N ) + 34 ], { + 'dtype': 'float64' + }); + out = assign( ws, N ); + + t.strictEqual( out, ws, 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float64', 'returns expected value' ); + + buf = getData( ws ); + + expectedTwiddles = new Float64Array( [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expectedFactors = new Float64Array( [ 8.0, 2.0, 2.0, 4.0 ] ); + + ulps = 1; + for ( i = 0; i < expectedTwiddles.length; i++ ) { + y = buf[ N+i ]; + e = expectedTwiddles[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < expectedFactors.length; i++ ) { + y = buf[ ( 2*N ) + i ]; + e = expectedFactors[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < N; i++ ) { + y = buf[ i ]; + e = 0.0; + t.strictEqual( y, e, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function initializes a provided float32 workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var fview; + var ulps; + var out; + var buf; + var ws; + var N; + var y; + var e; + var i; + + N = 8; + ws = zeros( [ ( 2*N ) + 34 ], { + 'dtype': 'float32' + }); + out = assign( ws, N ); + + t.strictEqual( out, ws, 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'float32', 'returns expected value' ); + + buf = getData( ws ); + + expectedTwiddles = new Float32Array( [ 0.7071067690849304, 0.7071067690849304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expectedFactors = new Uint32Array( [ 8, 2, 2, 4 ] ); + + ulps = 1; + for ( i = 0; i < expectedTwiddles.length; i++ ) { + y = buf[ N+i ]; + e = expectedTwiddles[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + fview = new Uint32Array( buf.buffer, buf.byteOffset, buf.length ); + for ( i = 0; i < expectedFactors.length; i++ ) { + y = fview[ ( 2*N ) + i ]; + e = expectedFactors[ i ]; + t.strictEqual( y, e, 'returns expected integer factor. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < N; i++ ) { + y = buf[ i ]; + e = 0.0; + t.strictEqual( y, e, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function initializes a provided generic workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var out; + var buf; + var ws; + var N; + var i; + + N = 8; + ws = zeros( [ ( 2*N ) + 34 ], { + 'dtype': 'generic' + }); + out = assign( ws, N ); + + t.strictEqual( out, ws, 'returns expected value' ); + t.strictEqual( String( getDType( out ) ), 'generic', 'returns expected value' ); + + buf = getData( ws ); + + expectedTwiddles = [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expectedFactors = [ 8, 2, 2, 4 ]; + + for ( i = 0; i < N; i++ ) { + t.strictEqual( buf[ N+i ], expectedTwiddles[ i ], 'returns expected twiddle factor at index ' + i ); + } + for ( i = 0; i < expectedFactors.length; i++ ) { + t.strictEqual( buf[ (2*N)+i ], expectedFactors[ i ], 'returns expected integer factor at index ' + i ); + } + for ( i = 0; i < N; i++ ) { + t.strictEqual( buf[ i ], 0, 'returns expected scratch space value at index ' + i ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.js new file mode 100644 index 000000000000..e4d642f9d7e3 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.js @@ -0,0 +1,39 @@ +/** +* @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 isMethod = require( '@stdlib/assert/is-method' ); +var rffti = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rffti, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( rffti, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.main.js b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.main.js new file mode 100644 index 000000000000..d7951a10fa17 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/fftpack/rffti/test/test.main.js @@ -0,0 +1,289 @@ +/** +* @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 isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var rffti = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rffti, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rffti( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not a positive integer (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + -1, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rffti( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rffti( 4, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bool', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rffti( 4, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function supports specifying an output data type', function test( t ) { + var ws = rffti( 4, { + 'dtype': 'float32' + }); + + t.strictEqual( String( getDType( ws ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( ws ), [ 42 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a workspace of correct size', function test( t ) { + var ws; + + ws = rffti( 1 ); + t.deepEqual( getShape( ws ), [ 36 ], 'returns expected value' ); // 2*n + 34 + + ws = rffti( 8 ); + t.deepEqual( getShape( ws ), [ 50 ], 'returns expected value' ); // 2*n + 34 + + ws = rffti( 16 ); + t.deepEqual( getShape( ws ), [ 66 ], 'returns expected value' ); // 2*n + 34 + + t.end(); +}); + +tape( 'the function returns a float64 workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var ulps; + var buf; + var ws; + var N; + var y; + var e; + var i; + + N = 8; + ws = rffti( N ); + buf = getData( ws ); + + expectedTwiddles = new Float64Array( [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expectedFactors = new Float64Array( [ 8.0, 2.0, 2.0, 4.0 ] ); + + ulps = 1; + for ( i = 0; i < expectedTwiddles.length; i++ ) { + y = buf[ N+i ]; + e = expectedTwiddles[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < expectedFactors.length; i++ ) { + y = buf[ ( 2*N ) + i ]; + e = expectedFactors[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < N; i++ ) { + y = buf[ i ]; + e = 0.0; + t.strictEqual( y, e, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns a float32 workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var fview; + var ulps; + var buf; + var ws; + var N; + var y; + var e; + var i; + + N = 8; + ws = rffti( N, { + 'dtype': 'float32' + }); + buf = getData( ws ); + + expectedTwiddles = new Float32Array( [ 0.7071067690849304, 0.7071067690849304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + expectedFactors = new Uint32Array( [ 8, 2, 2, 4 ] ); + + ulps = 1; + for ( i = 0; i < expectedTwiddles.length; i++ ) { + y = buf[ N+i ]; + e = expectedTwiddles[ i ]; + t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within ' + ulps + ' ULPs. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + fview = new Uint32Array( buf.buffer, buf.byteOffset, buf.length ); + for ( i = 0; i < expectedFactors.length; i++ ) { + y = fview[ ( 2*N ) + i ]; + e = expectedFactors[ i ]; + t.strictEqual( y, e, 'returns expected integer factor. N: ' + N + '. y: ' + y + '. E: ' + e ); + } + for ( i = 0; i < N; i++ ) { + y = buf[ i ]; + e = 0.0; + t.strictEqual( y, e, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns a generic workspace ndarray', function test( t ) { + var expectedTwiddles; + var expectedFactors; + var buf; + var ws; + var N; + var i; + + N = 8; + ws = rffti( N, { + 'dtype': 'generic' + }); + buf = getData( ws ); + + expectedTwiddles = [ 0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expectedFactors = [ 8, 2, 2, 4 ]; + + for ( i = 0; i < N; i++ ) { + t.strictEqual( buf[ N+i ], expectedTwiddles[ i ], 'returns expected twiddle factor at index ' + i ); + } + for ( i = 0; i < expectedFactors.length; i++ ) { + t.strictEqual( buf[ (2*N)+i ], expectedFactors[ i ], 'returns expected integer factor at index ' + i ); + } + for ( i = 0; i < N; i++ ) { + t.strictEqual( buf[ i ], 0, 'returns expected scratch space value at index ' + i ); + } + t.end(); +});