All files / fft/base/fftpack/lib radb4.js

52.51% Statements 94/179
100% Branches 1/1
0% Functions 0/1
52.51% Lines 94/179

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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 1801x 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) 2025 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/master/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.
* ```
*/
 
/* eslint-disable max-len */
 
'use strict';
 
// MODULES //
 
var SQRT2 = require( '@stdlib/constants/float64/sqrt-two' );
var chRef = require( './ch_ref.js' );
var ccRef = require( './cc_ref.js' );
 
 
// MAIN //
 
/**
* Performs the backward FFT of length 4 for real-valued sequences.
*
* @private
* @param {integer} ido - number of real values for each transform
* @param {integer} l1 - length of the input sequences
* @param {Float64Array} cc - input array containing sequences to be transformed
* @param {number} ccOffset - offset for the input array
* @param {Float64Array} ch - output array containing transformed sequences
* @param {number} chOffset - offset for the output array
* @param {Float64Array} wa1 - first array of twiddle factors
* @param {number} wa1Offset - offset for the first twiddle factors array
* @param {Float64Array} wa2 - second array of twiddle factors
* @param {number} wa2Offset - offset for the second twiddle factors array
* @param {Float64Array} wa3 - third array of twiddle factors
* @param {number} wa3Offset - offset for the third twiddle factors array
* @returns {void}
*/
function radb4( ido, l1, cc, ccOffset, ch, chOffset, wa1, wa1Offset, wa2, wa2Offset, wa3, wa3Offset ) { // eslint-disable-line max-params
	var idp2;
	var ti1;
	var ti2;
	var ti3;
	var ti4;
	var tr1;
	var tr2;
	var tr3;
	var tr4;
	var ci2;
	var ci3;
	var ci4;
	var cr2;
	var cr3;
	var cr4;
	var ic;
	var i;
	var k;

	// Parameter adjustments...
	chOffset -= 1 + ( ido * ( 1 + l1 ) );
	ccOffset -= 1 + ( ido * 5 );
	wa1Offset -= 1;
	wa2Offset -= 1;
	wa3Offset -= 1;

	// Function body:
	for ( k = 1; k <= l1; k++ ) {
		tr1 = cc[ ccRef( 1, 1, k, 4, ido ) + ccOffset ] - cc[ ccRef( ido, 4, k, 4, ido ) + ccOffset ];
		tr2 = cc[ ccRef( 1, 1, k, 4, ido ) + ccOffset ] + cc[ ccRef( ido, 4, k, 4, ido ) + ccOffset ];
		tr3 = cc[ ccRef( ido, 2, k, 4, ido ) + ccOffset ] + cc[ ccRef( ido, 2, k, 4, ido ) + ccOffset ];
		tr4 = cc[ ccRef( 1, 3, k, 4, ido ) + ccOffset ] + cc[ ccRef( 1, 3, k, 4, ido ) + ccOffset ];
		ch[ chRef( 1, k, 1, l1, ido ) + chOffset ] = tr2 + tr3;
		ch[ chRef( 1, k, 2, l1, ido ) + chOffset ] = tr1 - tr4;
		ch[ chRef( 1, k, 3, l1, ido ) + chOffset ] = tr2 - tr3;
		ch[ chRef( 1, k, 4, l1, ido ) + chOffset ] = tr1 + tr4;
	}
	if ( ido < 2 ) {
		return;
	}
	if ( ido !== 2 ) {
		idp2 = ido + 2;
		for ( k = 1; k <= l1; k++ ) {
			for ( i = 3; i <= ido; i += 2 ) {
				ic = idp2 - i;
				ti1 = cc[ ccRef( i, 1, k, 4, ido ) + ccOffset ] + cc[ ccRef( ic, 4, k, 4, ido ) + ccOffset ];
				ti2 = cc[ ccRef( i, 1, k, 4, ido ) + ccOffset ] - cc[ ccRef( ic, 4, k, 4, ido ) + ccOffset ];
				ti3 = cc[ ccRef( i, 3, k, 4, ido ) + ccOffset ] - cc[ ccRef( ic, 2, k, 4, ido ) + ccOffset ];
				ti4 = cc[ ccRef( i, 3, k, 4, ido ) + ccOffset ] + cc[ ccRef( ic, 2, k, 4, ido ) + ccOffset ];
				tr1 = cc[ ccRef( i - 1, 1, k, 4, ido ) + ccOffset ] - cc[ ccRef( ic - 1, 4, k, 4, ido ) + ccOffset ];
				tr2 = cc[ ccRef( i - 1, 1, k, 4, ido ) + ccOffset ] + cc[ ccRef( ic - 1, 4, k, 4, ido ) + ccOffset ];
				ti4 = cc[ ccRef( i - 1, 3, k, 4, ido ) + ccOffset ] - cc[ ccRef( ic - 1, 2, k, 4, ido ) + ccOffset ];
				tr3 = cc[ ccRef( i - 1, 3, k, 4, ido ) + ccOffset ] + cc[ ccRef( ic - 1, 2, k, 4, ido ) + ccOffset ];
				ch[ chRef( i - 1, k, 1, l1, ido ) + chOffset ] = tr2 + tr3;
				cr3 = tr2 - tr3;
				ch[ chRef( i, k, 1, l1, ido ) + chOffset ] = ti2 + ti3;
				ci3 = ti2 - ti3;
				cr2 = tr1 - tr4;
				cr4 = tr1 + tr4;
				ci2 = ti1 + ti4;
				ci4 = ti1 - ti4;
				ch[ chRef( i - 1, k, 2, l1, ido ) + chOffset ] = ( wa1[ i - 2 + wa1Offset ] * cr2 ) - ( wa1[ i - 1 + wa1Offset ] * ci2 );
				ch[ chRef( i, k, 2, l1, ido ) + chOffset ] = ( wa1[ i - 2 + wa1Offset ] * ci2 ) + ( wa1[ i - 1 + wa1Offset ] * cr2 );
				ch[ chRef( i - 1, k, 3, l1, ido ) + chOffset ] = ( wa2[ i - 2 + wa2Offset ] * cr3 ) - ( wa2[ i - 1 + wa2Offset ] * ci3 );
				ch[ chRef( i, k, 3, l1, ido ) + chOffset ] = ( wa2[ i - 2 + wa2Offset ] * ci3 ) + ( wa2[ i - 1 + wa2Offset ] * cr3 );
				ch[ chRef( i - 1, k, 4, l1, ido ) + chOffset ] = ( wa3[ i - 2 + wa3Offset ] * cr4 ) - ( wa3[ i - 1 + wa3Offset ] * ci4 );
				ch[ chRef( i, k, 4, l1, ido ) + chOffset ] = ( wa3[ i - 2 + wa3Offset ] * ci4 ) + ( wa3[ i - 1 + wa3Offset ] * cr4 );
			}
		}
		if ( ido % 2 === 1 ) {
			return;
		}
	}
	for ( k = 1; k <= l1; k++ ) {
		ti1 = cc[ ccRef( 1, 2, k, 4, ido ) + ccOffset ] + cc[ ccRef( 1, 4, k, 4, ido ) + ccOffset ];
		ti2 = cc[ ccRef( 1, 4, k, 4, ido ) + ccOffset ] - cc[ ccRef( 1, 2, k, 4, ido ) + ccOffset ];
		tr1 = cc[ ccRef( ido, 1, k, 4, ido ) + ccOffset ] - cc[ ccRef( ido, 3, k, 4, ido ) + ccOffset ];
		tr2 = cc[ ccRef( ido, 1, k, 4, ido ) + ccOffset ] + cc[ ccRef( ido, 3, k, 4, ido ) + ccOffset ];
		ch[ chRef( ido, k, 1, l1, ido ) + chOffset ] = tr2 + tr2;
		ch[ chRef( ido, k, 2, l1, ido ) + chOffset ] = SQRT2 * ( tr1 - ti1 );
		ch[ chRef( ido, k, 3, l1, ido ) + chOffset ] = ti2 + ti2;
		ch[ chRef( ido, k, 4, l1, ido ) + chOffset ] = -SQRT2 * ( tr1 + ti1 );
	}
}
 
 
// EXPORTS //
 
module.exports = radb4;