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

86.41% Statements 159/184
25% Branches 3/12
100% Functions 1/1
86.41% Lines 159/184

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 1851x 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 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x         2x 2x 2x 2x       2x           2x                       2x 2x 2x 2x     2x 2x 4x 4x 2x 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 floor = require( '@stdlib/math/base/special/floor' );
var radf2 = require( './radf2.js' );
var radf3 = require( './radf3.js' );
var radf4 = require( './radf4.js' );
var radf5 = require( './radf5.js' );
var radfg = require( './radfg.js' );
 
var printWorkspace = require( './print_real_workspace.js' ); // FIXME
 
 
// MAIN //
 
/**
* Performs the forward real-valued Fourier transform.
*
* @private
* @param {NonNegativeInteger} N - length of the sequence to transform
* @param {Float64Array} c - input array containing the sequence to be transformed
* @param {NonNegativeInteger} cOffset - starting index for `c`
* @param {Float64Array} ch - working array for intermediate results
* @param {NonNegativeInteger} chOffset - starting index for `ch`
* @param {Float64Array} wa - workspace array for storing twiddle factors
* @param {NonNegativeInteger} waOffset - starting index for `wa`
* @param {Int32Array} ifac - workspace array for storing factorization results
* @param {NonNegativeInteger} ifacOffset - starting index for `ifac`
* @returns {void}
*/
function rfftf1( N, c, cOffset, ch, chOffset, wa, waOffset, ifac, ifacOffset ) {
	var factor;
	var idl1;
	var FLG;
	var ido;
	var ix4;
	var ix3;
	var ix2;
	var nf;
	var l2;
	var l1;
	var kh;
	var iw;
	var k1;
	var i;
 
	// Resolve the number of factors:
	nf = ifac[ ifacOffset+1 ];
 
	FLG = 1; // FIXME: describe the point of this flag
	l2 = N;
 
	// FIXME
	printWorkspace( N, ch, 1, chOffset );
 
	// Initialize an index offset to the last element in each workspace:
	iw = N - 1;
 
	for ( k1 = 1; k1 <= nf; k1++ ) {
		kh = nf - k1;
 
		// Resolve the next factor:
		factor = ifac[ ifacOffset+kh+2 ];
 
		// Compute a sub-transform length:
		l1 = floor( l2 / factor );
 
		ido = floor( N / l2 );
		idl1 = ido * l1;
 
		// Adjust the index offset
		iw -= ( (factor-1) * ido );
 
		// Toggle the flag: // FIXME: better description?
		FLG = 1 - FLG;
 
		switch ( factor ) {
		case 4:
			ix2 = iw + ido;
			ix3 = ix2 + ido;
			radf4( ido, l1, ( FLG ) ? ch : c, ( FLG ) ? chOffset : cOffset, ( FLG ) ? c : ch, ( FLG ) ? cOffset : chOffset, wa, iw+waOffset, wa, ix2+waOffset, wa, ix3+waOffset );
			break;
		case 2:
			radf2( ido, l1, ( FLG ) ? ch : c, 1, ( FLG ) ? chOffset : cOffset, ( FLG ) ? c : ch, 1, ( FLG ) ? cOffset : chOffset, wa, 1, iw+waOffset );
			break;
		case 3:
			ix2 = iw + ido;
			radf3( ido, l1, ( FLG ) ? ch : c, ( FLG ) ? chOffset : cOffset, ( FLG ) ? c : ch, ( FLG ) ? cOffset : chOffset, wa, iw+waOffset, wa, ix2+waOffset );
			break;
		case 5:
			ix2 = iw + ido;
			ix3 = ix2 + ido;
			ix4 = ix3 + ido;
			radf5( ido, l1, ( FLG ) ? ch : c, ( FLG ) ? chOffset : cOffset, ( FLG ) ? c : ch, ( FLG ) ? cOffset : chOffset, wa, iw+waOffset, wa, ix2+waOffset, wa, ix3+waOffset, wa, ix4+waOffset );
			break;
		default:
			if ( ido === 1 ) {
				FLG = 1 - FLG;
			}
			if ( FLG === 0 ) {
				radfg( ido, factor, l1, idl1, c, cOffset, c, cOffset, c, cOffset, ch, chOffset, ch, chOffset, wa, iw+waOffset );
				FLG = 1;
			} else {
				radfg( ido, factor, l1, idl1, ch, chOffset, ch, chOffset, ch, chOffset, c, cOffset, c, cOffset, wa, iw+waOffset );
				FLG = 0;
			}
			break;
		}
		l2 = l1;
	}
	if ( FLG === 1 ) {
		return;
	}
	// Now that we've finished computing the transforms, copy over the final results to the input array...
	for ( i = 0; i < N; i++ ) {
		c[ cOffset+i ] = ch[ chOffset+i ]; // FIXME: use `blas/base/dcopy`
	}
}
 
 
// EXPORTS //
 
module.exports = rfftf1;