Skip to content

Commit 2eb785a

Browse files
committed
refactor: revert to old implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5c8446b commit 2eb785a

1 file changed

Lines changed: 59 additions & 61 deletions

File tree

  • lib/node_modules/@stdlib/fft/base/fftpack/rffti/lib

lib/node_modules/@stdlib/fft/base/fftpack/rffti/lib/rffti1.js

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@
6060

6161
// MODULES //
6262

63+
var sincos = require( '@stdlib/math/base/special/sincos' ).assign;
6364
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
6465
var floor = require( '@stdlib/math/base/special/floor' );
65-
var sin = require( '@stdlib/math/base/special/sin' );
66-
var cos = require( '@stdlib/math/base/special/cos' );
6766
var decompose = require( '@stdlib/fft/base/fftpack/decompose' );
6867

6968

7069
// VARIABLES //
7170

71+
// Define a list of initial trial factors for FFT factorization:
7272
var TRIAL_FACTORS = [ 4, 2, 3, 5 ];
7373

7474

@@ -78,104 +78,102 @@ var TRIAL_FACTORS = [ 4, 2, 3, 5 ];
7878
* Initializes the working arrays for applying a Fourier transform to a real-valued sequence.
7979
*
8080
* @private
81-
* @param {NonNegativeInteger} n - length of the sequence
82-
* @param {Collection} wa - array of twiddle factors
83-
* @param {integer} strideW - stride length for `wa`
84-
* @param {NonNegativeInteger} offsetW - starting index for `wa`
85-
* @param {Collection} ifac - array containing a radix factorization
86-
* @param {integer} strideF - stride length for `ifac`
87-
* @param {NonNegativeInteger} offsetF - starting index for `ifac`
81+
* @param {NonNegativeInteger} N - length of the sequence
82+
* @param {Collection} twiddles - array of twiddle factors
83+
* @param {integer} strideT - stride length for `twiddles`
84+
* @param {NonNegativeInteger} offsetT - starting index for `twiddles`
85+
* @param {Collection} factors - array containing a radix factorization
86+
* @param {integer} strideF - stride length for `factors`
87+
* @param {NonNegativeInteger} offsetF - starting index for `factors`
8888
* @returns {void}
8989
*/
90-
function rffti1( n, wa, strideW, offsetW, ifac, strideF, offsetF ) {
90+
function rffti1( N, twiddles, strideT, offsetT, factors, strideF, offsetF ) {
91+
var factor;
9192
var argld;
9293
var argh;
93-
var nfm1;
94-
var arg;
95-
var ipm;
96-
var ido;
94+
var fidx;
9795
var nf;
9896
var fi;
99-
var ip;
10097
var l2;
10198
var l1;
10299
var ld;
103-
var ii;
104-
var is;
105-
var k1;
106-
var i;
100+
var st;
101+
var it;
102+
var im;
103+
var M;
104+
var m;
105+
var k;
107106
var j;
108107

109108
// Decompose the sequence length into its radix factors:
110-
nf = decompose( n, 4, TRIAL_FACTORS, 1, 0, ifac, strideF, offsetF );
109+
nf = decompose( N, 4, TRIAL_FACTORS, 1, 0, factors, strideF, offsetF );
111110

111+
// If the number of radix factors is `1`, the only twiddle factor we need is `W_N^0 = 1`, which the main transform kernels already hard-code, so nothing to pre-compute...
112+
if ( nf-1 === 0 ) {
113+
return;
114+
}
112115
// Compute the master angular step (i.e., the basic angle that generates all twiddles):
113-
argh = TWO_PI / n;
114-
115-
// Initialize the index into the twiddle factor array:
116-
is = 0;
116+
argh = TWO_PI / N;
117117

118-
// Compute the number of factors minus one:
119-
nfm1 = nf - 1;
118+
// Define the location of the first sine term we want to compute:
119+
im = 1;
120120

121121
// Initialize a running product of factors already processed:
122122
l1 = 1;
123123

124-
// If the number of radix factors is `1`, the only twiddle factor we need is `W_N^0 = 1`, which the main transform kernels already hard-code, so nothing to pre-compute...
125-
if ( nfm1 === 0 ) {
126-
return;
127-
}
128-
// Generate twiddle factors for each radix factor...
129-
for ( k1 = 0; k1 < nfm1; k1++ ) {
130-
// Resolve the next radix factor (C code: ifac[k1+2] with 1-based, JS: ifac[k1+2] with 0-based):
131-
ip = ifac[ offsetF + ((k1+2)*strideF) ];
124+
// Compute the index of the first radix factor:
125+
fidx = offsetF + ( 2*strideF );
132126

133-
// Initialize a running offset used to step the angle:
134-
ld = 0;
127+
// Compute the stride length for each cosine/sine pair:
128+
st = 2 * strideT;
129+
130+
// Generate twiddle factors...
131+
for ( k = 0; k < nf-1; k++ ) {
132+
// Resolve the next radix factor:
133+
factor = factors[ fidx ];
135134

136135
// Compute the length of the transform after including the current radix:
137-
l2 = l1 * ip;
136+
l2 = factor * l1;
138137

139-
// Compute the number of data points in each sub-transform:
140-
ido = floor( n / l2 );
138+
// Compute the number of the "butterfly wings" (at this stage, the data is viewed as a `factor`-point transform of sub-vectors of length `l1`; `M` describes how many such vectors fit in the full array of length `N`):
139+
M = floor( N / l2 );
141140

142-
// Compute the number of iterations for the inner loop:
143-
ipm = ip - 1;
141+
// Initialize a running offset used to step the angle:
142+
ld = 0;
144143

145144
// Iterate over each butterfly column within the current radix...
146-
for ( j = 0; j < ipm; j++ ) {
145+
for ( j = 1; j < factor; j++ ) {
147146
// Advance to the next column:
148147
ld += l1;
149148

150-
// Initialize the index into the twiddle factor array:
151-
i = is;
152-
153149
// Compute the angle step for this column:
154-
argld = ld * argh;
150+
argld = ld * argh; // 2π ⋅ j ⋅ li / N, which is the j-th column's base angle
155151

156-
// Initialize the harmonic counter:
157-
fi = 0.0;
152+
// Initialize a counter which counts from `1` to `(M/2)-1` (i.e., all non-trivial harmonics):
153+
fi = 1.0;
158154

159-
// Iterate over each non-trivial harmonic in the column...
160-
for ( ii = 2; ii < ido; ii += 2 ) {
161-
// Advance the index by 2 (for cosine and sine):
162-
i += 2;
155+
// Compute the index of the sine term:
156+
it = offsetT + ( (im+1)*strideT );
163157

164-
// Update the harmonic counter:
165-
fi += 1.0;
158+
// Iterate over each non-trivial harmonic in the column (note: we skip the `m=0` and `m=1` (i.e., the first cosine/sine pair, the first harmonic `W_N^0 = cos(0) + j sin(0) = 1 + j⋅0` is trivial and hard-coded by transform kernels)...
159+
for ( m = 2; m < M; m += 2 ) {
160+
// Compute `(cos(fi*argld), sin(fi*argld))`:
161+
sincos( fi*argld, twiddles, -strideT, it ); // note: `sincos` returns the sine and cosine, in that order, so we need to use a negative stride when assigning the values to `twiddles` to ensure that cosine comes before sine in the twiddles table
166162

167-
// Compute the angle for this harmonic:
168-
arg = fi * argld;
163+
// Update for the next harmonic:
164+
fi += 1.0;
169165

170-
// Store the cosine and sine values:
171-
wa[ offsetW + ( ( i-1 ) * strideW ) ] = cos( arg );
172-
wa[ offsetW + ( i*strideW ) ] = sin( arg );
166+
// Resolve the index of the next sine term:
167+
it += st;
173168
}
174-
// Advance the index by the number of data points in each sub-transform:
175-
is += ido;
169+
// Advance `im` by the size of the current block, skipping the cosine/sine pairs we have just written:
170+
im += M;
176171
}
177172
// Update the running product of factors already processed:
178173
l1 = l2;
174+
175+
// Resolve the index of the next radix factor:
176+
fidx += strideF;
179177
}
180178
}
181179

0 commit comments

Comments
 (0)