13
13
get_all_dtypes ,
14
14
get_complex_dtypes ,
15
15
get_float_dtypes ,
16
- is_cpu_device ,
17
16
)
18
17
19
- # aspects of default device:
20
- _def_device = dpctl .SyclQueue ().sycl_device
21
- _def_dev_has_fp64 = _def_device .has_aspect_fp64
22
- is_gpu_with_fp64 = not is_cpu_device () and _def_dev_has_fp64
18
+
19
+ def _make_array_Hermitian (a , n ):
20
+ """
21
+ This function makes necessary changes of the input array of
22
+ `dpnp.fft.irfft` and `dpnp.fft.hfft` functions to make sure the
23
+ given array is Hermitian.
24
+
25
+ """
26
+
27
+ a [0 ].imag = 0
28
+ if n in [None , 18 ]:
29
+ # f_ny is Nyquist mode (n//2+1 mode) which is n//2 element
30
+ f_ny = - 1 if n is None else n // 2
31
+ a [f_ny ].imag = 0
32
+ a [f_ny :] = 0 # no data needed after Nyquist mode
33
+
34
+ return a
23
35
24
36
25
37
# TODO: `assert_dtype_allclose` calls in this file have `check_only_type_kind=True`
@@ -391,11 +403,12 @@ def test_hfft_1D(self, dtype, n, norm):
391
403
assert_dtype_allclose (result , expected , check_only_type_kind = True )
392
404
393
405
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
394
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
406
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
395
407
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
396
408
def test_hfft_1D_complex (self , dtype , n , norm ):
397
409
x = dpnp .linspace (- 1 , 1 , 11 )
398
410
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
411
+ a = _make_array_Hermitian (a , n )
399
412
a = dpnp .asarray (a , dtype = dtype )
400
413
a_np = dpnp .asnumpy (a )
401
414
@@ -446,13 +459,13 @@ def test_fft_1D(self, dtype, n, norm):
446
459
# but dpnp return float32 if input is float32
447
460
assert_dtype_allclose (result , expected , check_only_type_kind = True )
448
461
449
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
450
462
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
451
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
463
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
452
464
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
453
465
def test_fft_1D_complex (self , dtype , n , norm ):
454
466
x = dpnp .linspace (- 1 , 1 , 11 )
455
467
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
468
+ a = _make_array_Hermitian (a , n )
456
469
a = dpnp .asarray (a , dtype = dtype )
457
470
a_np = dpnp .asnumpy (a )
458
471
@@ -473,29 +486,50 @@ def test_fft_1D_on_2D_array(self, dtype, n, axis, norm, order):
473
486
expected = numpy .fft .irfft (a_np , n = n , axis = axis , norm = norm )
474
487
assert_dtype_allclose (result , expected , check_only_type_kind = True )
475
488
476
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
477
489
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
478
490
@pytest .mark .parametrize ("n" , [None , 5 , 8 ])
479
491
@pytest .mark .parametrize ("axis" , [0 , 1 , 2 ])
480
492
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
481
493
@pytest .mark .parametrize ("order" , ["C" , "F" ])
482
494
def test_fft_1D_on_3D_array (self , dtype , n , axis , norm , order ):
483
- x1 = numpy .random .uniform (- 10 , 10 , 24 )
484
- x2 = numpy .random .uniform (- 10 , 10 , 24 )
495
+ x1 = numpy .random .uniform (- 10 , 10 , 120 )
496
+ x2 = numpy .random .uniform (- 10 , 10 , 120 )
485
497
a_np = numpy .array (x1 + 1j * x2 , dtype = dtype ).reshape (
486
- 2 , 3 , 4 , order = order
498
+ 4 , 5 , 6 , order = order
487
499
)
500
+ # each 1-D array of input should be Hermitian
501
+ if axis == 0 :
502
+ a_np [0 ].imag = 0
503
+ if n is None :
504
+ # for axis=0 and n=8, Nyquist mode is not present
505
+ f_ny = - 1 # Nyquist mode
506
+ a_np [- 1 ].imag = 0
507
+ elif axis == 1 :
508
+ a_np [:, 0 , :].imag = 0
509
+ if n in [None , 8 ]:
510
+ f_ny = - 1 # Nyquist mode
511
+ a_np [:, f_ny , :].imag = 0
512
+ a_np [:, f_ny :, :] = 0 # no data needed after Nyquist mode
513
+ elif axis == 2 :
514
+ a_np [..., 0 ].imag = 0
515
+ if n in [None , 8 ]:
516
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
517
+ a_np [..., f_ny ].imag = 0
518
+ a_np [..., f_ny :] = 0 # no data needed after Nyquist mode
519
+
488
520
a = dpnp .asarray (a_np )
489
521
490
522
result = dpnp .fft .irfft (a , n = n , axis = axis , norm = norm )
491
523
expected = numpy .fft .irfft (a_np , n = n , axis = axis , norm = norm )
492
- assert_dtype_allclose (result , expected , check_only_type_kind = True )
524
+ assert_dtype_allclose (
525
+ result , expected , check_only_type_kind = True , factor = 16
526
+ )
493
527
494
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
495
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
528
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
496
529
def test_fft_usm_ndarray (self , n ):
497
- x = dpt .linspace (- 1 , 1 , 11 )
498
- a = dpt .sin (x ) + 1j * dpt .cos (x )
530
+ x = dpnp .linspace (- 1 , 1 , 11 )
531
+ a = dpnp .sin (x ) + 1j * dpnp .cos (x )
532
+ a = _make_array_Hermitian (a , n )
499
533
a_usm = dpt .asarray (a , dtype = dpt .complex64 )
500
534
a_np = dpt .asnumpy (a_usm )
501
535
out_shape = n if n is not None else 2 * (a_usm .shape [0 ] - 1 )
@@ -506,13 +540,13 @@ def test_fft_usm_ndarray(self, n):
506
540
expected = numpy .fft .irfft (a_np , n = n )
507
541
assert_dtype_allclose (result , expected , check_only_type_kind = True )
508
542
509
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
510
543
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
511
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
544
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
512
545
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
513
546
def test_fft_1D_out (self , dtype , n , norm ):
514
547
x = dpnp .linspace (- 1 , 1 , 11 )
515
548
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
549
+ a = _make_array_Hermitian (a , n )
516
550
a = dpnp .asarray (a , dtype = dtype )
517
551
a_np = dpnp .asnumpy (a )
518
552
0 commit comments