Skip to content

Commit 474def9

Browse files
committed
test: use correct implementation of tests, improve implementation
1 parent 02eabb0 commit 474def9

File tree

10 files changed

+207
-243
lines changed

10 files changed

+207
-243
lines changed

lib/node_modules/@stdlib/fft/base/fftpack/lib/decompose.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ function decompose( n, ifac, ifptr, ntryh ) {
112112
}
113113
ifac[ ifptr + 3 ] = 2;
114114
}
115-
if ( nl === 1 ) {
116-
break;
115+
if ( nl !== 1 ) {
116+
continue;
117117
}
118+
break;
118119
}
119120
} while ( nl !== 1 );
120121
ifac[ ifptr + 1 ] = n;

lib/node_modules/@stdlib/fft/base/fftpack/lib/radf2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function radf2( ido, l1, cc, ccOffset, ch, chOffset, wa1, wa1Offset ) {
122122
}
123123
for ( k = 1; k <= l1; k++ ) {
124124
ch[ chRef( 1, 2, k, l1, ido ) + chOffset ] = -cc[ ccRef( ido, k, 2, l1, ido ) + ccOffset ];
125-
ch[ chRef( ido, 1, k, l1, ido ) + chOffset ] = -cc[ ccRef( ido, k, 1, l1, ido ) + ccOffset ];
125+
ch[ chRef( ido, 1, k, l1, ido ) + chOffset ] = cc[ ccRef( ido, k, 1, l1, ido ) + ccOffset ];
126126
}
127127
}
128128

lib/node_modules/@stdlib/fft/base/fftpack/lib/radfg.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
var sincos = require( '@stdlib/math/base/special/sincos' );
6666
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
67+
var floor = require( '@stdlib/math/base/special/floor' );
6768
var chRef = require( './ch_ref.js' );
6869
var ccRef = require( './cc_ref.js' );
6970
var c1Ref = require( './c1_ref.js' );
@@ -137,10 +138,10 @@ function radfg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch,
137138
sc = sincos( arg );
138139
dcp = sc[ 1 ];
139140
dsp = sc[ 0 ];
140-
ipph = ( ip + 1 ) / 2;
141+
ipph = floor( ( ip + 1 ) / 2 );
141142
ipp2 = ip + 2;
142143
idp2 = ido + 2;
143-
nbd = ( ido - 1 ) / 2;
144+
nbd = floor( ( ido - 1 ) / 2 );
144145
if ( ido === 1 ) {
145146
for ( ik = 1; ik <= idl1; ik++ ) {
146147
c2[ c2Ref( ik, 1, idl1 ) + c2Offset ] = ch2[ ch2Ref( ik, 1, idl1 ) + ch2Offset ];
@@ -162,8 +163,8 @@ function radfg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch,
162163
for ( i = 3; i <= ido; i += 2 ) {
163164
idij += 2;
164165
for ( k = 1; k <= l1; k++ ) {
165-
ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = ( wa[ idij - 2 + waOffset ] * c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] ) + ( wa[ idij - 2 + waOffset ] * c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] );
166-
ch[ chRef( i, k, j, l1, ido ) + chOffset ] = ( wa[ idij - 2 + waOffset ] * c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] ) - ( wa[ idij - 2 + waOffset ] * c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] );
166+
ch[ chRef( i - 1, k, j, l1, ido ) + chOffset ] = ( wa[ idij - 1 + waOffset ] * c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] ) + ( wa[ idij + waOffset ] * c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] );
167+
ch[ chRef( i, k, j, l1, ido ) + chOffset ] = ( wa[ idij - 1 + waOffset ] * c1[ c1Ref( i, k, j, l1, ido ) + c1Offset ] ) - ( wa[ idij + waOffset ] * c1[ c1Ref( i - 1, k, j, l1, ido ) + c1Offset ] );
167168
}
168169
}
169170
}
@@ -260,7 +261,7 @@ function radfg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch,
260261
}
261262
for ( j = 2; j <= ipph; j++ ) {
262263
jc = ipp2 - j;
263-
j2 = j + j;
264+
j2 = j * 2;
264265
for ( k = 1; k <= l1; k++ ) {
265266
cc[ ccRef( ido, j2 - 2, k, ip, ido ) + ccOffset ] = ch[ chRef( 1, k, j, l1, ido ) + chOffset ];
266267
cc[ ccRef( 1, j2 - 1, k, ip, ido ) + ccOffset ] = ch[ chRef( 1, k, jc, l1, ido ) + chOffset ];
@@ -272,7 +273,7 @@ function radfg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch,
272273
if ( nbd >= l1 ) {
273274
for ( j = 2; j <= ipph; j++ ) {
274275
jc = ipp2 - j;
275-
j2 = j + j;
276+
j2 = j * 2;
276277
for ( k = 1; k <= l1; k++ ) {
277278
for ( i = 3; i <= ido; i += 2 ) {
278279
ic = idp2 - i;
@@ -286,7 +287,7 @@ function radfg( ido, ip, l1, idl1, cc, ccOffset, c1, c1Offset, c2, c2Offset, ch,
286287
} else {
287288
for ( j = 2; j <= ipph; j++ ) {
288289
jc = ipp2 - j;
289-
j2 = j + j;
290+
j2 = j * 2;
290291
for ( i = 3; i <= ido; i += 2 ) {
291292
ic = idp2 - i;
292293
for ( k = 1; k <= l1; k++ ) {

lib/node_modules/@stdlib/fft/base/fftpack/lib/rfftf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ var rfftf1 = require( './rfftf1.js' );
7676
* @returns {void}
7777
*/
7878
function rfftf( n, r, rOffset, wsave, wsaveOffset ) {
79-
wsaveOffset -= 1;
8079
rOffset -= 1;
81-
80+
wsaveOffset -= 1;
8281
if ( n === 1 ) {
8382
return;
8483
}
85-
rfftf1( n, r, 1 + rOffset, wsave, 1 + wsaveOffset, wsave, n + 1 + wsaveOffset, wsave, ( n << 1 ) + 1 + wsaveOffset ); // eslint-disable-line max-len
84+
rfftf1( n, r, rOffset + 1, wsave, wsaveOffset + 1, wsave, n + wsaveOffset + 1, wsave, ( n << 1 ) + 1 + wsaveOffset ); // eslint-disable-line max-len
8685
}
8786

8887

lib/node_modules/@stdlib/fft/base/fftpack/lib/rfftf1.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
// MODULES //
6464

65+
var floor = require( '@stdlib/math/base/special/floor' );
6566
var radf2 = require( './radf2.js' );
6667
var radf3 = require( './radf3.js' );
6768
var radf4 = require( './radf4.js' );
@@ -110,10 +111,10 @@ function rfftf1( n, c, cOffset, ch, chOffset, wa, waOffset, ifac, ifacOffset ) {
110111
for ( k1 = 1; k1 <= nf; k1++ ) {
111112
kh = nf - k1;
112113
ip = ifac[ ifacOffset + kh + 2 ];
113-
l1 = l2 / ip;
114-
ido = n / l2;
114+
l1 = floor( l2 / ip );
115+
ido = floor( n / l2 );
115116
idl1 = ido * l1;
116-
iw -= ( ip - 1 ) * ido;
117+
iw -= ( ( ip - 1 ) * ido );
117118
na = 1 - na;
118119
switch ( ip ) {
119120
case 4:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ var rffti1 = require( './rffti1.js' );
7474
* @returns {void}
7575
*/
7676
function rffti( n, wsave, wptr ) {
77+
wptr -= 1;
7778
if ( n === 1 ) {
7879
return;
7980
}
80-
wptr -= 1;
81-
rffti1( n, wsave, n + wptr, wsave, ( n << 1 ) + wptr );
81+
rffti1( n, wsave, n + 1 + wptr, wsave, 1 + ( n << 1 ) + wptr );
8282
}
8383

8484

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
var sincos = require( '@stdlib/math/base/special/sincos' );
6464
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
65+
var floor = require( '@stdlib/math/base/special/floor' );
6566
var decompose = require( './decompose.js' );
6667

6768

@@ -118,7 +119,7 @@ function rffti1( n, wa, wptr, ifac, ifptr ) {
118119
ip = ifac[ ifptr + k1 + 2 ];
119120
ld = 0;
120121
l2 = ip * l1;
121-
ido = n / l2;
122+
ido = floor( n / l2 );
122123
ipm = ip - 1;
123124
for ( j = 1; j <= ipm; j++ ) {
124125
ld += l1;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var SQRT2 = require( '@stdlib/constants/float64/sqrt-two' );
26+
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
27+
var sin = require( '@stdlib/math/base/special/sin' );
28+
var cos = require( '@stdlib/math/base/special/cos' );
29+
var abs = require( '@stdlib/math/base/special/abs' );
30+
var max = require( '@stdlib/math/base/special/max' );
31+
var pow = require( '@stdlib/math/base/special/pow' );
32+
var floor = require( '@stdlib/math/base/special/floor' );
33+
var rffti = require( './../lib/rffti.js' );
34+
var rfftf = require( './../lib/rfftf.js' );
35+
var rfftb = require( './../lib/rfftb.js' );
36+
37+
38+
// FIXTURES //
39+
40+
var nd = [ 120, 91, 54, 49, 32, 28, 24, 8, 4, 3, 2 ];
41+
42+
43+
// TESTS //
44+
45+
tape( 'main export is a function', function test( t ) {
46+
t.ok( true, __filename );
47+
t.strictEqual( typeof rffti, 'function', 'main export is a function' );
48+
t.end();
49+
});
50+
51+
tape( 'the function initializes FFT working arrays', function test( t ) { // eslint-disable-line max-statements
52+
var rftfb;
53+
var modn;
54+
var rftf;
55+
var rftb;
56+
var sum1;
57+
var sum2;
58+
var arg1;
59+
var sum;
60+
var arg;
61+
var np1;
62+
var nm1;
63+
var ns2;
64+
var tol;
65+
var r2;
66+
var r3;
67+
var r1;
68+
var nz;
69+
var xh;
70+
var dt;
71+
var cf;
72+
var n;
73+
var j;
74+
var x;
75+
var y;
76+
var w;
77+
var k;
78+
var i;
79+
80+
x = new Float64Array( 200 );
81+
y = new Float64Array( 200 );
82+
xh = new Float64Array( 200 );
83+
w = new Float64Array( 2000 );
84+
for ( nz = 1; nz <= nd.length; nz++ ) {
85+
n = nd[ nz - 1 ];
86+
modn = n % 2;
87+
np1 = n + 1;
88+
nm1 = n - 1;
89+
90+
for ( j = 1; j <= np1; j++ ) {
91+
x[ j - 1 ] = sin( j * SQRT2 );
92+
y[ j - 1 ] = x[ j - 1 ];
93+
xh[ j - 1 ] = x[ j - 1 ];
94+
}
95+
96+
// TEST SUBROUTINES RFFTI,RFFTF AND RFFTB:
97+
rffti( n, w, 0 );
98+
dt = TWO_PI / n;
99+
ns2 = floor( ( n + 1 ) / 2 );
100+
if ( ns2 >= 1 ) {
101+
for ( k = 2; k <= ns2; k++ ) {
102+
sum1 = 0.0;
103+
sum2 = 0.0;
104+
arg = ( k - 1 ) * dt;
105+
for ( i = 1; i <= n; i++ ) {
106+
arg1 = ( i - 1 ) * arg;
107+
sum1 += x[ i - 1 ] * cos( arg1 );
108+
sum2 += x[ i - 1 ] * sin( arg1 );
109+
}
110+
y[ ( k << 1 ) - 3 ] = sum1;
111+
y[ ( k << 1 ) - 2 ] = -sum2;
112+
}
113+
}
114+
sum1 = 0.0;
115+
sum2 = 0.0;
116+
for ( i = 1; i <= nm1; i += 2 ) {
117+
sum1 += x[ i - 1 ];
118+
sum2 += x[ i ];
119+
}
120+
if ( modn === 1 ) {
121+
sum1 += x[ n - 1 ];
122+
}
123+
y[ 0 ] = sum1 + sum2;
124+
if ( modn === 0 ) {
125+
y[ n - 1 ] = sum1 - sum2;
126+
}
127+
rfftf( n, x, 0, w, 0 );
128+
rftf = 0.0;
129+
for ( i = 1; i <= n; i++ ) {
130+
// Computing MAX:
131+
r2 = rftf;
132+
r1 = x[ i - 1 ] - y[ i - 1 ];
133+
r3 = abs( r1 );
134+
rftf = max( r2, r3 );
135+
x[ i - 1 ] = xh[ i - 1 ];
136+
}
137+
rftf /= n;
138+
139+
for ( i = 0; i < n; i++ ) {
140+
sum = x[ 0 ] * 0.5;
141+
arg = i * dt;
142+
if ( ns2 >= 1 ) {
143+
for ( k = 1; k < ns2; k++ ) {
144+
arg1 = k * arg;
145+
sum += ( x[ ( ( k + 1 ) << 1 ) - 3 ] * cos( arg1 ) ) - ( x[ ( ( k + 1 ) << 1 ) - 2 ] * sin( arg1 ) ); // eslint-disable-line max-len
146+
}
147+
}
148+
if ( modn === 0 ) {
149+
sum += pow( -1, i - 1 ) * 0.5 * x[ n ];
150+
}
151+
y[ i ] = 2 * sum;
152+
}
153+
154+
rfftb( n, x, 0, w, 0 );
155+
rftb = 0.0;
156+
for ( i = 0; i < n; i++ ) {
157+
// Computing MAX:
158+
r2 = rftb;
159+
r1 = x[ i ] - y[ i ];
160+
r3 = abs( r1 );
161+
rftb = max( r2, r3 );
162+
x[ i ] = xh[ i ];
163+
y[ i ] = xh[ i ];
164+
}
165+
166+
rfftb( n, y, 0, w, 0 );
167+
rfftf( n, y, 0, w, 0 );
168+
cf = 1.0 / n;
169+
rftfb = 0.0;
170+
for ( i = 0; i < n; i++ ) {
171+
// Computing MAX:
172+
r2 = rftfb;
173+
r1 = cf * ( y[ i ] - x[ i ] );
174+
r3 = abs( r1 );
175+
rftfb = max( r2, r3 );
176+
}
177+
178+
tol = 1e-3;
179+
t.ok( rftf <= tol, 'forward transform error: ' + rftf + ' (expected <= ' + tol + ')' );
180+
t.ok( rftb <= tol, 'backward transform error: ' + rftb + ' (expected <= ' + tol + ')' );
181+
t.ok( rftfb <= tol, 'forward-backward transform error: ' + rftfb + ' (expected <= ' + tol + ')' );
182+
}
183+
184+
t.end();
185+
});

0 commit comments

Comments
 (0)