@@ -214,8 +214,93 @@ describeWithFlags('2D RFFT', WEBGL_ENVS, () => {
214
214
} ) ;
215
215
216
216
it ( 'should return the same value with TensorFlow (2x2x2 elements)' , ( ) => {
217
- const t1Real = tf . tensor3d ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , [ 2 , 2 , 2 ] ) ;
218
- expectArraysClose ( tf . spectral . rfft ( t1Real ) ,
219
- [ 3 , 0 , - 1 , 0 , 7 , 0 , - 1 , 0 , 11 , 0 , - 1 , 0 , 15 , 0 , - 1 , 0 ] ) ;
217
+ const t1Real = tf . tensor3d ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] , [ 2 , 2 , 2 ] ) ;
218
+ expectArraysClose (
219
+ tf . spectral . rfft ( t1Real ) ,
220
+ [ 3 , 0 , - 1 , 0 , 7 , 0 , - 1 , 0 , 11 , 0 , - 1 , 0 , 15 , 0 , - 1 , 0 ] ) ;
221
+ } ) ;
222
+ } ) ;
223
+
224
+ describeWithFlags ( '1D IRFFT' , ALL_ENVS , ( ) => {
225
+ it ( 'should return the same value with TensorFlow (2 elements)' , ( ) => {
226
+ const t1Real = tf . tensor1d ( [ 1 , 2 ] ) ;
227
+ const t1Imag = tf . tensor1d ( [ 0 , 0 ] ) ;
228
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
229
+ expectArraysClose ( tf . spectral . irfft ( t1 ) , [ 1.5 , - 0.5 ] ) ;
230
+ } ) ;
231
+
232
+ it ( 'should return the same value with TensorFlow (5 elements)' , ( ) => {
233
+ const t1Real = tf . tensor1d ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
234
+ const t1Imag = tf . tensor1d ( [ 0 , 0 , 0 , 0 , 0 ] ) ;
235
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
236
+ expectArraysClose (
237
+ tf . spectral . irfft ( t1 ) ,
238
+ [ 3 , - 0.8535534 , 0 , - 0.14644662 , 0 , - 0.14644662 , 0 , - 0.8535534 ] ) ;
220
239
} ) ;
240
+
241
+ it ( 'should return the same value with TensorFlow (5 elements) with imag' ,
242
+ ( ) => {
243
+ const t1Real = tf . tensor1d ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
244
+ const t1Imag = tf . tensor1d ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
245
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
246
+ expectArraysClose (
247
+ tf . spectral . irfft ( t1 ) ,
248
+ [ 3 , - 2.6642137 , 0.5 , - 0.45710677 , 0 , 0.16421354 , - 0.5 , 0.95710677 ] ) ;
249
+ } ) ;
250
+ } ) ;
251
+
252
+ describeWithFlags ( '2D IRFFT' , ALL_ENVS , ( ) => {
253
+ it ( 'should return the same value with TensorFlow (2x2 elements)' , ( ) => {
254
+ const t1Real = tf . tensor2d ( [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] ) ;
255
+ const t1Imag = tf . tensor2d ( [ 0 , 0 , 0 , 0 ] , [ 2 , 2 ] ) ;
256
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
257
+ expectArraysClose ( tf . spectral . irfft ( t1 ) , [ 1.5 , - 0.5 , 3.5 , - 0.5 ] ) ;
258
+ } ) ;
259
+
260
+ it ( 'should return the same value with TensorFlow (2x3 elements)' , ( ) => {
261
+ const t1Real = tf . tensor2d ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 3 ] ) ;
262
+ const t1Imag = tf . tensor2d ( [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 2 , 3 ] ) ;
263
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
264
+ expectArraysClose (
265
+ tf . spectral . irfft ( t1 ) , [ 2 , - 0.5 , 0 , - 0.5 , 5 , - 0.5 , 0 , - 0.5 ] ) ;
266
+ } ) ;
267
+
268
+ it ( 'should return the same value with TensorFlow (2x3 elements) with imag' ,
269
+ ( ) => {
270
+ const t1Real = tf . tensor2d ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 3 ] ) ;
271
+ const t1Imag = tf . tensor2d ( [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 3 ] ) ;
272
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
273
+ expectArraysClose ( tf . spectral . irfft ( t1 ) , [ 2 , - 1.5 , 0 , 0.5 , 5 , - 3 , 0 , 2 ] ) ;
274
+ } ) ;
275
+ } ) ;
276
+
277
+ describeWithFlags ( '3D IRFFT' , ALL_ENVS , ( ) => {
278
+ it ( 'should return the same value with TensorFlow (2x2x2 elements)' , ( ) => {
279
+ const t1Real = tf . tensor3d ( [ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ] , [ 2 , 2 , 2 ] ) ;
280
+ const t1Imag = tf . tensor3d ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 2 , 2 , 2 ] ) ;
281
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
282
+ expectArraysClose (
283
+ tf . spectral . irfft ( t1 ) , [ 1.5 , - 0.5 , 3.5 , - 0.5 , 1.5 , - 0.5 , 3.5 , - 0.5 ] ) ;
284
+ } ) ;
285
+
286
+ it ( 'should return the same value with TensorFlow (2x2x3 elements)' , ( ) => {
287
+ const t1Real = tf . tensor3d ( [ 1 , 2 , 3 , 4 , 5 , 6 , 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 2 , 3 ] ) ;
288
+ const t1Imag = tf . tensor3d ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 2 , 2 , 3 ] ) ;
289
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
290
+ expectArraysClose ( tf . spectral . irfft ( t1 ) , [
291
+ 2 , - 0.5 , 0 , - 0.5 , 5 , - 0.5 , 0 , - 0.5 , 2 , - 0.5 , 0 , - 0.5 , 5 , - 0.5 , 0 , - 0.5
292
+ ] ) ;
293
+ } ) ;
294
+
295
+ it ( 'should return the same value with TensorFlow (2x2x3 elements) with imag' ,
296
+ ( ) => {
297
+ const t1Real =
298
+ tf . tensor3d ( [ 1 , 2 , 3 , 4 , 5 , 6 , 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 2 , 3 ] ) ;
299
+ const t1Imag =
300
+ tf . tensor3d ( [ 1 , 2 , 3 , 4 , 5 , 6 , 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 2 , 3 ] ) ;
301
+ const t1 = tf . complex ( t1Real , t1Imag ) ;
302
+ expectArraysClose (
303
+ tf . spectral . irfft ( t1 ) ,
304
+ [ 2 , - 1.5 , 0 , 0.5 , 5 , - 3 , 0 , 2 , 2 , - 1.5 , 0 , 0.5 , 5 , - 3 , 0 , 2 ] ) ;
305
+ } ) ;
221
306
} ) ;
0 commit comments