diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/README.md b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/README.md new file mode 100644 index 000000000000..4efcc013f12a --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/README.md @@ -0,0 +1,175 @@ + + +# hc2c + +> Convert a real-valued single-precision floating-point array in [FFTPACK][fftpack] half-complex format to a single-precision complex floating-point array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var hc2c = require( '@stdlib/fft/base/fftpack/float32/hc2c' ); +``` + +#### hc2c( N, hc, strideHc, offsetHc, out, strideOut, offsetOut ) + +Converts a real-valued single-precision floating-point array in [FFTPACK][fftpack] half-complex format to a single-precision complex floating-point array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); + +var N = 4; +var w = new Float32Array( ( 2*N ) + 34 ); + +rffti( N, w, 1, 0 ); + +var r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + +rfftf( N, r, 1, 0, w, 1, 0 ); +// r => [ 10.0, -2.0, 2.0, -2.0 ] + +var out = new Complex64Array( floor( N/2 ) + 1 ); + +hc2c( N, r, 1, 0, out, 1, 0 ); +// out => [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] +``` + +The function accepts the following arguments: + +- **N**: length of the original real sequence. +- **hc**: input array in [FFTPACK][fftpack] half-complex format. +- **strideHc**: stride length for `hc`. +- **offsetHc**: starting index for `hc`. +- **out**: output complex array. +- **strideOut**: stride length for `out`. +- **offsetOut**: starting index for `out`. + +
+ + + + + +
+ +## Notes + +- [FFTPACK][fftpack]'s [`rfftf`][@stdlib/fft/base/fftpack/float32/rfftf] stores the forward DFT of a length `N` real sequence in `N` real values using the following layout: + + ```text + Even N: [ DC, Re(1), Im(1), Re(2), Im(2), ..., Re(N/2-1), Im(N/2-1), Nyquist ] + Odd N: [ DC, Re(1), Im(1), Re(2), Im(2), ..., Re((N-1)/2), Im((N-1)/2) ] + ``` + + where `DC` is the zero-frequency component and `Nyquist` is the component at frequency `N/2` (even `N` only). Both are always purely real. + +- The output is a complex-valued array of length `floor(N/2) + 1`. The `DC` and `Nyquist` components are stored with an explicit zero imaginary part. + +- This half-complex format differs from other conventions (e.g., [FFTW][fftw-halfcomplex]). In FFTW's half-complex format, all real components are stored first, followed by imaginary components in reverse order. + +
+ + + +
+ +## Examples + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +var hc2c = require( '@stdlib/fft/base/fftpack/float32/hc2c' ); + +var N = 8; +var opts = { + 'dtype': 'float32' +}; +var r = discreteUniform( N, -10, 10, opts ); +var w = new Float32Array( ( 2*N ) + 34 ); + +console.log( r ); + +rffti( N, w, 1, 0 ); +rfftf( N, r, 1, 0, w, 1, 0 ); + +console.log( r ); + +var out = new Complex64Array( floor( N/2 ) + 1 ); + +hc2c( N, r, 1, 0, out, 1, 0 ); + +console.log( out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/benchmark/benchmark.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/benchmark/benchmark.js new file mode 100644 index 000000000000..2b3b940f56c9 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/benchmark/benchmark.js @@ -0,0 +1,137 @@ +/** +* @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/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var hc2c = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - sequence length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var out; + var w; + var r; + var M; + + M = floor( N/2 ) + 1; + r = uniform( N, -100.0, 100.0, options ); + w = new Float32Array( ( 2*N ) + 34 ); + rffti( N, w, 1, 0 ); + rfftf( N, r, 1, 0, w, 1, 0 ); + out = new Complex64Array( M ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var view; + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = hc2c( N, r, 1, 0, out, 1, 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + view = reinterpret( v, 0 ); + if ( isnanf( view[ 0 ] ) ) { + 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( 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/float32/hc2c/docs/repl.txt b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/repl.txt new file mode 100644 index 000000000000..71ab3bd6b14f --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/repl.txt @@ -0,0 +1,50 @@ + +{{alias}}( N, hc, strideHc, offsetHc, out, strideOut, offsetOut ) + Converts a real-valued single-precision floating-point array in FFTPACK + half-complex format to a single-precision complex floating-point array. + + The output complex array must have a length of at least `floor(N/2) + 1`. + + Parameters + ---------- + N: integer + Length of the original real sequence. + + hc: Float32Array + Input array in FFTPACK half-complex format. + + strideHc: integer + Stride length for `hc`. + + offsetHc: integer + Starting index for `hc`. + + out: Complex64Array + Output complex array. + + strideOut: integer + Stride length for `out`. + + offsetOut: integer + Starting index for `out`. + + Returns + ------- + out: Complex64Array + Output complex array. + + Examples + -------- + > var N = 4; + > var w = new {{alias:@stdlib/array/float32}}( ( 2*N ) + 34 ); + > {{alias:@stdlib/fft/base/fftpack/float32/rffti}}( N, w, 1, 0 ) + + > var r = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias:@stdlib/fft/base/fftpack/float32/rfftf}}( N, r, 1, 0, w, 1, 0 ) + [ 10.0, -2.0, 2.0, -2.0 ] + > var out = new {{alias:@stdlib/array/complex64}}( ( N/2 ) + 1 ); + > {{alias}}( N, r, 1, 0, out, 1, 0 ) + [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/index.d.ts b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/index.d.ts new file mode 100644 index 000000000000..ab2eac9bcc54 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/index.d.ts @@ -0,0 +1,61 @@ +/* +* @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 { Complex64Array } from '@stdlib/types/array'; + +/** +* Converts a real-valued single-precision floating-point array in FFTPACK half-complex format to a single-precision complex floating-point array. +* +* @param N - length of the original real sequence +* @param hc - input array in FFTPACK half-complex format +* @param strideHc - stride length for `hc` +* @param offsetHc - starting index for `hc` +* @param out - output complex array +* @param strideOut - stride length for `out` +* @param offsetOut - starting index for `out` +* @returns output complex array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var floor = require( '@stdlib/math/base/special/floor' ); +* var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +* var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +* +* var N = 4; +* var w = new Float32Array( ( 2*N ) + 34 ); +* rffti( N, w, 1, 0 ); +* +* var r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* rfftf( N, r, 1, 0, w, 1, 0 ); +* // r => [ 10.0, -2.0, 2.0, -2.0 ] +* +* var out = new Complex64Array( floor( N/2 ) + 1 ); +* hc2c( N, r, 1, 0, out, 1, 0 ); +* // out => [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] +*/ +declare function hc2c( N: number, hc: Float32Array, strideHc: number, offsetHc: number, out: Complex64Array, strideOut: number, offsetOut: number ): Complex64Array; + + +// EXPORTS // + +export = hc2c; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/test.ts b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/test.ts new file mode 100644 index 000000000000..f55e463e2284 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/docs/types/test.ts @@ -0,0 +1,151 @@ +/* +* @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. +*/ + +import Complex64Array = require( '@stdlib/array/complex64' ); +import hc2c = require( './index' ); + + +// TESTS // + +// The function returns a Complex64Array... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( 4, hc, 1, 0, out, 1, 0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( '4', hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( true, hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( false, hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( null, hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( void 0, hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( [], hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( {}, hc, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( ( x: number ): number => x, hc, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float32Array... +{ + const out = new Complex64Array( 3 ); + + hc2c( 4, '4', 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, 4, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, true, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, false, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, null, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, void 0, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, [], 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, {}, 1, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( 4, hc, '1', 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, true, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, false, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, null, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, void 0, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, [], 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, {}, 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( 4, hc, 1, '0', out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, true, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, false, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, null, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, void 0, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, [], out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, {}, out, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Complex64Array... +{ + const hc = new Float32Array( 4 ); + + hc2c( 4, hc, 1, 0, '42', 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, 42, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, true, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, false, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, null, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, void 0, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, [], 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, {}, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( 4, hc, 1, 0, out, '1', 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, true, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, false, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, null, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, void 0, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, [], 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, {}, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c( 4, hc, 1, 0, out, 1, '0' ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, true ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, false ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, null ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, void 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, [] ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, {} ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const hc = new Float32Array( 4 ); + const out = new Complex64Array( 3 ); + + hc2c(); // $ExpectError + hc2c( 4 ); // $ExpectError + hc2c( 4, hc ); // $ExpectError + hc2c( 4, hc, 1 ); // $ExpectError + hc2c( 4, hc, 1, 0 ); // $ExpectError + hc2c( 4, hc, 1, 0, out ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1 ); // $ExpectError + hc2c( 4, hc, 1, 0, out, 1, 0, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/examples/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/examples/index.js new file mode 100644 index 000000000000..225b817b0db7 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/examples/index.js @@ -0,0 +1,47 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +var hc2c = require( './../lib' ); + +var N = 8; +var opts = { + 'dtype': 'float32' +}; +var r = discreteUniform( N, -10, 10, opts ); +var w = new Float32Array( ( 2*N ) + 34 ); + +console.log( r ); + +rffti( N, w, 1, 0 ); +rfftf( N, r, 1, 0, w, 1, 0 ); + +console.log( r ); + +var out = new Complex64Array( floor( N/2 ) + 1 ); + +hc2c( N, r, 1, 0, out, 1, 0 ); + +console.log( out ); diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/index.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/index.js new file mode 100644 index 000000000000..69fd760f1530 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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'; + +/** +* Convert a real-valued single-precision floating-point array in FFTPACK half-complex format to a single-precision complex floating-point array. +* +* @module @stdlib/fft/base/fftpack/float32/hc2c +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var floor = require( '@stdlib/math/base/special/floor' ); +* var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +* var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +* var hc2c = require( '@stdlib/fft/base/fftpack/float32/hc2c' ); +* +* var N = 4; +* var w = new Float32Array( ( 2*N ) + 34 ); +* rffti( N, w, 1, 0 ); +* +* var r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* rfftf( N, r, 1, 0, w, 1, 0 ); +* // r => [ 10.0, -2.0, 2.0, -2.0 ] +* +* var out = new Complex64Array( floor( N/2 ) + 1 ); +* hc2c( N, r, 1, 0, out, 1, 0 ); +* // out => [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/main.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/main.js new file mode 100644 index 000000000000..4db80b938e73 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/lib/main.js @@ -0,0 +1,106 @@ +/** +* @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 isEven = require( '@stdlib/math/base/assert/is-even' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + + +// MAIN // + +/** +* Converts a real-valued single-precision floating-point array in FFTPACK half-complex format to a single-precision complex floating-point array. +* +* @param {NonNegativeInteger} N - length of the original real sequence +* @param {Float32Array} hc - input array in FFTPACK half-complex format +* @param {integer} strideHc - stride length for `hc` +* @param {NonNegativeInteger} offsetHc - starting index for `hc` +* @param {Complex64Array} out - output complex array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Complex64Array} output complex array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var floor = require( '@stdlib/math/base/special/floor' ); +* var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +* var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +* +* var N = 4; +* var w = new Float32Array( ( 2*N ) + 34 ); +* rffti( N, w, 1, 0 ); +* +* var r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* rfftf( N, r, 1, 0, w, 1, 0 ); +* // r => [ 10.0, -2.0, 2.0, -2.0 ] +* +* var out = new Complex64Array( floor( N/2 ) + 1 ); +* hc2c( N, r, 1, 0, out, 1, 0 ); +* // out => [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] +*/ +function hc2c( N, hc, strideHc, offsetHc, out, strideOut, offsetOut ) { + var view; + var so; + var io; + var M; + var k; + + if ( N <= 0 ) { + return out; + } + // Reinterpret the complex output array as a real-valued array of interleaved real and imaginary components: + view = reinterpret( out, 0 ); + + // Adjust the stride and offset for the real-valued view: + so = strideOut * 2; + io = offsetOut * 2; + + // Resolve the number of interior complex coefficients: + M = floor( ( N - 1 ) / 2 ); + + // DC component: + view[ io ] = hc[ offsetHc ]; + view[ io + 1 ] = 0.0; // Always purely real + offsetHc += strideHc; + io += so; + + // Complex coefficients for frequencies k = 1, ..., M: + for ( k = 0; k < M; k++ ) { + view[ io ] = hc[ offsetHc ]; // real part + view[ io + 1 ] = hc[ offsetHc + strideHc ]; // imaginary part + offsetHc += 2 * strideHc; + io += so; + } + + // Nyquist component (only when N is even): + if ( isEven( N ) ) { + view[ io ] = hc[ offsetHc ]; + view[ io + 1 ] = 0.0; // Always purely real + } + return out; +} + + +// EXPORTS // + +module.exports = hc2c; diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/package.json b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/package.json new file mode 100644 index 000000000000..e4350572b422 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/fft/base/fftpack/float32/hc2c", + "version": "0.0.0", + "description": "Convert a real-valued single-precision floating-point array in FFTPACK half-complex format to a single-precision complex floating-point array.", + "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", + "strided", + "base", + "fft", + "fftpack", + "fourier", + "transform", + "half-complex", + "complex", + "conversion", + "float32", + "single" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/test/test.js b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/test/test.js new file mode 100644 index 000000000000..2201601eab58 --- /dev/null +++ b/lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' ); +var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' ); +var hc2c = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof hc2c, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( hc2c.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var hc; + var N; + var v; + + N = 4; + hc = new Float32Array( [ 10.0, -2.0, 2.0, -2.0 ] ); + out = new Complex64Array( floor( N/2 ) + 1 ); + + v = hc2c( N, hc, 1, 0, out, 1, 0 ); + + t.strictEqual( v, out, 'same reference' ); + t.end(); +}); + +tape( 'the function returns the output array unchanged when N is 0', function test( t ) { + var view; + var out; + var hc; + + hc = new Float32Array( 0 ); + out = new Complex64Array( 0 ); + + hc2c( 0, hc, 1, 0, out, 1, 0 ); + + view = reinterpret( out, 0 ); + t.strictEqual( view.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function converts a sequence of length 1 (DC only)', function test( t ) { + var expected; + var view; + var out; + var hc; + var N; + + N = 1; + hc = new Float32Array( [ 5.0 ] ); + out = new Complex64Array( floor( N/2 ) + 1 ); + + hc2c( N, hc, 1, 0, out, 1, 0 ); + + view = reinterpret( out, 0 ); + expected = new Float32Array( [ 5.0, 0.0 ] ); + t.deepEqual( view, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function converts an even length sequence', function test( t ) { + var expected; + var view; + var out; + var N; + var w; + var r; + + N = 4; + r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + w = new Float32Array( ( 2*N ) + 34 ); + + rffti( N, w, 1, 0 ); + rfftf( N, r, 1, 0, w, 1, 0 ); + + out = new Complex64Array( floor( N/2 ) + 1 ); + hc2c( N, r, 1, 0, out, 1, 0 ); + view = reinterpret( out, 0 ); + + expected = new Float32Array( [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] ); + t.deepEqual( view, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function converts an odd length sequence', function test( t ) { + var view; + var out; + var N; + var w; + var r; + + N = 5; + r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + w = new Float32Array( ( 2*N ) + 34 ); + + rffti( N, w, 1, 0 ); + rfftf( N, r, 1, 0, w, 1, 0 ); + + out = new Complex64Array( floor( N/2 ) + 1 ); + hc2c( N, r, 1, 0, out, 1, 0 ); + view = reinterpret( out, 0 ); + + // DC: + t.strictEqual( view[ 0 ], r[ 0 ], 'returns expected value' ); + t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); + + // Freq 1: + t.strictEqual( view[ 2 ], r[ 1 ], 'returns expected value' ); + t.strictEqual( view[ 3 ], r[ 2 ], 'returns expected value' ); + + // Freq 2: + t.strictEqual( view[ 4 ], r[ 3 ], 'returns expected value' ); + t.strictEqual( view[ 5 ], r[ 4 ], 'returns expected value' ); + + // Should not have a Nyquist component since N is odd: + t.strictEqual( out.length, floor( N/2 ) + 1, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride for the input array', function test( t ) { + var expected; + var view; + var out; + var hc; + var N; + + N = 4; + hc = new Float32Array([ + 10.0, // 0: DC + -999.0, + -2.0, // 2: Re(1) + -999.0, + 2.0, // 4: Im(1) + -999.0, + -2.0, // 6: Nyquist + -999.0 + ]); + + out = new Complex64Array( floor( N/2 ) + 1 ); + hc2c( N, hc, 2, 0, out, 1, 0 ); + view = reinterpret( out, 0 ); + + expected = new Float32Array( [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] ); + t.deepEqual( view, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset for the input array', function test( t ) { + var expected; + var view; + var out; + var hc; + var N; + + N = 4; + hc = new Float32Array([ + -999.0, + -999.0, + 10.0, // 2: DC + -2.0, // 3: Re(1) + 2.0, // 4: Im(1) + -2.0 // 5: Nyquist + ]); + + out = new Complex64Array( floor( N/2 ) + 1 ); + hc2c( N, hc, 1, 2, out, 1, 0 ); + view = reinterpret( out, 0 ); + + expected = new Float32Array( [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] ); + t.deepEqual( view, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride for the output array', function test( t ) { + var view; + var out; + var hc; + var N; + + N = 4; + hc = new Float32Array( [ 10.0, -2.0, 2.0, -2.0 ] ); + out = new Complex64Array( 5 ); + + hc2c( N, hc, 1, 0, out, 2, 0 ); + view = reinterpret( out, 0 ); + + // DC: + t.strictEqual( view[ 0 ], 10.0, 'returns expected value' ); + t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); + + // Freq 1: + t.strictEqual( view[ 4 ], -2.0, 'returns expected value' ); + t.strictEqual( view[ 5 ], 2.0, 'returns expected value' ); + + // Freq 2: + t.strictEqual( view[ 8 ], -2.0, 'returns expected value' ); + t.strictEqual( view[ 9 ], 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset for the output array', function test( t ) { + var view; + var out; + var hc; + var N; + + N = 4; + hc = new Float32Array( [ 10.0, -2.0, 2.0, -2.0 ] ); + out = new Complex64Array( floor( N/2 ) + 2 ); + + hc2c( N, hc, 1, 0, out, 1, 1 ); + view = reinterpret( out, 0 ); + + // DC: + t.strictEqual( view[ 2 ], 10.0, 'returns expected value' ); + t.strictEqual( view[ 3 ], 0.0, 'returns expected value' ); + + // Freq 1: + t.strictEqual( view[ 4 ], -2.0, 'returns expected value' ); + t.strictEqual( view[ 5 ], 2.0, 'returns expected value' ); + + // Freq 2: + t.strictEqual( view[ 6 ], -2.0, 'returns expected value' ); + t.strictEqual( view[ 7 ], 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the input array', function test( t ) { + var expected; + var view; + var out; + var hc; + var N; + + N = 4; + hc = new Float32Array([ + -2.0, // 0: Nyquist + 2.0, // 1: Im(1) + -2.0, // 2: Re(1) + 10.0 // 3: DC + ]); + + out = new Complex64Array( floor( N/2 ) + 1 ); + hc2c( N, hc, -1, 3, out, 1, 0 ); + view = reinterpret( out, 0 ); + + expected = new Float32Array( [ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ] ); + t.deepEqual( view, expected, 'returns expected value' ); + t.end(); +});