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

33.77% Statements 102/302
100% Branches 1/1
0% Functions 0/1
33.77% Lines 102/302

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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 3031x 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 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, max-statements */
 
'use strict';
 
// MODULES //
 
var sincos = require( '@stdlib/math/base/special/sincos' );
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
var chRef = require( './ch_ref.js' );
var ccRef = require( './cc_ref.js' );
var c1Ref = require( './c1_ref.js' );
var c2Ref = require( './c2_ref.js' );
var ch2Ref = require( './ch2_ref.js' );
 
 
// MAIN //
 
/**
* Performs the backward FFT for real-valued sequences.
*
* @private
* @param {integer} ido - number of real values for each transform
* @param {integer} ip - radix of the transform
* @param {integer} l1 - length of the input sequences
* @param {integer} idl1 - stride for the transform
* @param {Float64Array} cc - input array containing sequences to be transformed
* @param {number} ccOffset - offset for the input array
* @param {Float64Array} c1 - first work array
* @param {number} c1Offset - offset for the first work array
* @param {Float64Array} c2 - second work array
* @param {number} c2Offset - offset for the second work array
* @param {Float64Array} ch - output array containing transformed sequences
* @param {number} chOffset - offset for the output array
* @param {Float64Array} ch2 - work array for transformed sequences
* @param {number} ch2Offset - offset for the work array
* @param {Float64Array} wa - array of twiddle factors
* @param {number} waOffset - offset for the twiddle factors array
* @returns {void}
*/
function radbg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch, chOffset, ch2, ch2Offset, wa, waOffset ) { // eslint-disable-line max-params
	var ar1h;
	var ar2h;
	var idp2;
	var ipp2;
	var idij;
	var ipph;
	var dc2;
	var ai1;
	var ai2;
	var ar1;
	var ar2;
	var ds2;
	var nbd;
	var dcp;
	var arg;
	var dsp;
	var j2;
	var ic;
	var jc;
	var lc;
	var ik;
	var is;
	var sc;
	var i;
	var j;
	var k;
	var l;

	// Parameter adjustments...
	chOffset -= 1 + ( ido * ( 1 + l1 ) );
	c1Offset -= 1 + ( ido * ( 1 + l1 ) );
	ccOffset -= 1 + ( ido * ( 1 + ip ) );
	ch2Offset -= 1 + idl1;
	c2Offset -= 1 + idl1;
	waOffset -= 1;

	// Function body:
	arg = TWO_PI / ip;
	sc = sincos( arg );
	dcp = sc[ 1 ];
	dsp = sc[ 0 ];
	idp2 = ido + 2;
	nbd = ( ido - 1 ) / 2;
	ipp2 = ip + 2;
	ipph = ( ip + 1 ) / 2;
	if ( ido >= l1 ) {
		for ( k = 1; k <= l1; k++ ) {
			for ( i = 1; i <= ido; i++ ) {
				ch[ chRef( i, k, 1, l1, ido ) + chOffset ] = cc[ ccRef( i, 1, k, ip, ido ) + ccOffset ];
			}
		}
	} else {
		for ( i = 1; i <= ido; i++ ) {
			for ( k = 1; k <= l1; k++ ) {
				ch[ chRef( i, k, 1, l1, ido ) + chOffset ] = cc[ ccRef( i, 1, k, ip, ido ) + ccOffset ];
			}
		}
	}
	for ( j = 2; j <= ipph; j++ ) {
		jc = ipp2 - j;
		j2 = j + j;
		for ( k = 1; k <= l1; k++ ) {
			ch[ chRef( 1, k, j, l1, ido ) + chOffset ] = cc[ ccRef( ido, j2 - 2, k, ip, ido ) + ccOffset ] + cc[ ccRef( ido, j2 - 2, k, ip, ido ) + ccOffset ];
			ch[ chRef( 1, k, jc, l1, ido ) + chOffset ] = cc[ ccRef( 1, j2 - 1, k, ip, ido ) + ccOffset ] + cc[ ccRef( 1, j2 - 1, k, ip, ido ) + ccOffset ];
		}
	}
	if ( ido !== 1 ) {
		if ( nbd >= l1 ) {
			for ( j = 2; j <= ipph; j++ ) {
				jc = ipp2 - j;
				for ( k = 1; k <= l1; k++ ) {
					for ( i = 3; i <= ido; i += 2 ) {
						ic = idp2 - i;
						ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = cc[ ccRef( i - 1, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] + cc[ ccRef( ic - 1, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i - 1, k, jc, l1, ido ) + chOffset ] = cc[ ccRef( i - 1, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] - cc[ ccRef( ic - 1, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i, k, j, l1, ido ) + chOffset ] = cc[ ccRef( i, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] - cc[ ccRef( ic, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i, k, jc, l1, ido ) + chOffset ] = cc[ ccRef( i, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] + cc[ ccRef( ic, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
					}
				}
			}
		} else {
			for ( j = 2; j <= ipph; j++ ) {
				jc = ipp2 - j;
				for ( i = 3; i <= ido; i += 2 ) {
					ic = idp2 - i;
					for ( k = 1; k <= l1; k++ ) {
						ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = cc[ ccRef( i - 1, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] + cc[ ccRef( ic - 1, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i - 1, k, jc, l1, ido ) + chOffset ] = cc[ ccRef( i - 1, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] - cc[ ccRef( ic - 1, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i, k, j, l1, ido ) + chOffset ] = cc[ ccRef( i, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] - cc[ ccRef( ic, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
						ch[ chRef( i, k, jc, l1, ido ) + chOffset ] = cc[ ccRef( i, ( j << 1 ) - 1, k, ip, ido ) + ccOffset ] + cc[ ccRef( ic, ( j << 1 ) - 2, k, ip, ido ) + ccOffset ];
					}
				}
			}
		}
	}
	ar1 = 1.0;
	ai1 = 0.0;
	for ( l = 2; l <= ipph; l++ ) {
		lc = ipp2 - l;
		ar1h = ( dcp * ar1 ) - ( dsp * ai1 );
		ai1 = ( dcp * ai1 ) + ( dsp * ar1 );
		ar1 = ar1h;
		for ( ik = 1; ik <= idl1; ik++ ) {
			c2[ c2Ref( ik, l, idl1 ) + c2Offset ] = ch2[ ch2Ref( ik, 1, idl1 ) + ch2Offset ] + ( ar1 * ch2[ ch2Ref( ik, 2, idl1 ) + ch2Offset ] );
			c2[ c2Ref( ik, lc, idl1 ) + c2Offset ] = ai1 * ch2[ ch2Ref( ik, ip, idl1 ) + ch2Offset ];
		}
		dc2 = ar1;
		ds2 = ai1;
		ar2 = ar1;
		ai2 = ai1;
		for ( j = 3; j <= ipph; j++ ) {
			jc = ipp2 - j;
			ar2h = ( dc2 * ar2 ) - ( ds2 * ai2 );
			ai2 = ( dc2 * ai2 ) + ( ds2 * ar2 );
			ar2 = ar2h;
			for ( ik = 1; ik <= idl1; ik++ ) {
				c2[ c2Ref( ik, l, idl1 ) + c2Offset ] += ( ar2 * ch2[ ch2Ref( ik, j, idl1 ) + ch2Offset ] );
				c2[ c2Ref( ik, lc, idl1 ) + c2Offset ] += ( ai2 * ch2[ ch2Ref( ik, jc, idl1 ) + ch2Offset ] );
			}
		}
	}
	for ( j = 2; j <= ipph; j++ ) {
		for ( ik = 1; ik <= idl1; ik++ ) {
			ch2[ ch2Ref( ik, 1, idl1 ) + ch2Offset ] += ch2[ ch2Ref( ik, j, idl1 ) + ch2Offset ];
		}
	}
	for ( j = 2; j <= ipph; j++ ) {
		jc = ipp2 - j;
		for ( k = 1; k <= l1; k++ ) {
			ch[ chRef( 1, k, j, l1, ido ) + chOffset ] = c1[ c1Ref( 1, k, j, l1, ido ) + c1Offset ] - c1[ c1Ref( 1, k, jc, l1, ido ) + c1Offset ];
			ch[ chRef( 1, k, jc, l1, ido ) + chOffset ] = c1[ c1Ref( 1, k, j, l1, ido ) + c1Offset ] + c1[ c1Ref( 1, k, jc, l1, ido ) + c1Offset ];
		}
	}
	if ( ido !== 1 ) {
		if ( nbd >= l1 ) {
			for ( j = 2; j <= ipph; j++ ) {
				jc = ipp2 - j;
				for ( k = 1; k <= l1; k++ ) {
					for ( i = 3; i <= ido; i += 2 ) {
						ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] - c1[ c1Ref( i, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i - 1, k, jc, l1, ido ) + chOffset ] = c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] + c1[ c1Ref( i, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i, k, j, l1, ido ) + chOffset ] = c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] + c1[ c1Ref( i - 1, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i, k, jc, l1, ido ) + chOffset ] = c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] - c1[ c1Ref( i - 1, k, jc, l1, ido ) + c1Offset ];
					}
				}
			}
		} else {
			for ( j = 2; j <= ipph; j++ ) {
				jc = ipp2 - j;
				for ( i = 3; i <= ido; i += 2 ) {
					for ( k = 1; k <= l1; k++ ) {
						ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] - c1[ c1Ref( i, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i - 1, k, jc, l1, ido ) + chOffset ] = c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] + c1[ c1Ref( i, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i, k, j, l1, ido ) + chOffset ] = c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] + c1[ c1Ref( i - 1, k, jc, l1, ido ) + c1Offset ];
						ch[ chRef( i, k, jc, l1, ido ) + chOffset ] = c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] - c1[ c1Ref( i - 1, k, jc, l1, ido ) + c1Offset ];
					}
				}
			}
		}
	}
	if ( ido === 1 ) {
		return;
	}
	for ( ik = 1; ik <= idl1; ik++ ) {
		c2[ c2Ref( ik, 1, idl1 ) + c2Offset ] = ch2[ ch2Ref( ik, 1, idl1 ) + ch2Offset ];
	}
	for ( j = 2; j <= ip; j++ ) {
		for ( k = 1; k <= l1; k++ ) {
			c1[ c1Ref( 1, k, j, l1, ido ) + c1Offset ] = ch[ chRef( 1, k, j, l1, ido ) + chOffset ];
		}
	}
	if ( nbd <= l1 ) {
		is = -ido;
		for ( j = 2; j <= ip; j++ ) {
			is += ido;
			idij = is;
			for ( i = 3; i <= ido; i += 2 ) {
				idij += 2;
				for ( k = 1; k <= l1; k++ ) {
					c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] = ( wa[ idij - 1 + waOffset ] * ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] ) - ( wa[ idij + waOffset ] * ch[ chRef( i, k, j, l1, ido ) + chOffset ] );
					c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] = ( wa[ idij - 1 + waOffset ] * ch[ chRef( i, k, j, l1, ido ) + chOffset ] ) + ( wa[ idij + waOffset ] * ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] );
				}
			}
		}
	} else {
		is = -ido;
		for ( j = 2; j <= ip; j++ ) {
			is += ido;
			for ( k = 1; k <= l1; k++ ) {
				idij = is;
				for ( i = 3; i <= ido; i += 2 ) {
					idij += 2;
					c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] = ( wa[ idij - 1 + waOffset ] * ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] ) - ( wa[ idij + waOffset ] * ch[ chRef( i, k, j, l1, ido ) + chOffset ] );
					c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] = ( wa[ idij - 1 + waOffset ] * ch[ chRef( i, k, j, l1, ido ) + chOffset ] ) + ( wa[ idij + waOffset ] * ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] );
				}
			}
		}
	}
}
 
 
// EXPORTS //
 
module.exports = radbg;