All files / generic/rfftf/lib main.js

85.21% Statements 98/115
100% Branches 1/1
0% Functions 0/1
85.21% Lines 98/115

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 1161x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                   1x 1x 1x 1x 1x  
/**
* @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.
*
*
* ## Notice
*
* The original C code and copyright notice are from the [PFFFT library]{@link https://github.com/marton78/pffft/blob/0b4ee12c4ba45a4a8e567550c16d96d1679f50ce/src/fftpack.c}. The implementation follows the original, but has been modified for JavaScript.
*
* ```text
* Copyright (c) 2004 the University Corporation for Atmospheric
* Research ("UCAR"). All rights reserved. Developed by NCAR's
* Computational and Information Systems Laboratory, UCAR,
* www.cisl.ucar.edu.
*
* Redistribution and use of the Software in source and binary forms,
* with or without modification, is permitted provided that the
* following conditions are met:
*
*     - Neither the names of NCAR's Computational and Information Systems
*       Laboratory, the University Corporation for Atmospheric Research,
*       nor the names of its sponsors or contributors may be used to
*       endorse or promote products derived from this Software without
*       specific prior written permission.
*
*     - Redistributions of source code must retain the above copyright
*       notices, this list of conditions, and the disclaimer below.
*
*     - Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions, and the disclaimer below in the
*       documentation and/or other materials provided with the
*       distribution.
*
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
* SOFTWARE.
* ```
*/
 
'use strict';
 
// MODULES //
 
var rfftf1 = require( './rfftf1.js' );
 
 
// MAIN //
 
/**
* Computes the forward discrete Fourier transform (DFT) of a real-valued sequence.
*
* @param {NonNegativeInteger} N - length of the sequence to transform
* @param {Collection} r - input array
* @param {integer} strideR - stride length for `r`
* @param {NonNegativeInteger} offsetR - starting index for `r`
* @param {Collection} w - workspace array containing pre-computed values
* @param {integer} strideW - stride length for `w`
* @param {NonNegativeInteger} offsetW - starting index for `w`
* @returns {Collection} input array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var rffti = require( '@stdlib/fft/base/fftpack/generic/rffti' );
*
* var N = 4;
*
* var w = new Float64Array( ( 2*N ) + 34 );
* rffti( N, w, 1, 0 );
*
* var r = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
*
* rfftf( N, r, 1, 0, w, 1, 0 );
* // r => <Float64Array>[ 10.0, -2.0, 2.0, -2.0 ]
*/
function rfftf( N, r, strideR, offsetR, w, strideW, offsetW ) {
	var offsetT;
	var offsetF;

	// When a sub-sequence is a single data point, the FFT is the identity, so no transformation necessary...
	if ( N === 1 ) {
		return r;
	}

	// Resolve the starting indices for storing twiddle factors and factorization results:
	offsetT = offsetW + ( N * strideW ); // index offset for twiddle factors
	offsetF = offsetT + ( N * strideW ); // index offset for factors describing the sub-transforms

	rfftf1( N, r, strideR, offsetR, w, strideW, offsetW, w, strideW, offsetT, w, strideW, offsetF ); // eslint-disable-line max-len

	return r;
}
 
 
// EXPORTS //
 
module.exports = rfftf;