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
23
-
24
18
25
19
# TODO: `assert_dtype_allclose` calls in this file have `check_only_type_kind=True`
26
20
# since stock NumPy is currently used in public CI for code coverege which
@@ -391,11 +385,17 @@ def test_hfft_1D(self, dtype, n, norm):
391
385
assert_dtype_allclose (result , expected , check_only_type_kind = True )
392
386
393
387
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
394
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
388
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
395
389
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
396
390
def test_hfft_1D_complex (self , dtype , n , norm ):
397
391
x = dpnp .linspace (- 1 , 1 , 11 )
398
392
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
393
+ # input should be Hermitian
394
+ a [0 ].imag = 0
395
+ if n in [None , 18 ]:
396
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
397
+ a [f_ny ].imag = 0
398
+ a [f_ny :] = 0 # no data needed after Nyquist mode
399
399
a = dpnp .asarray (a , dtype = dtype )
400
400
a_np = dpnp .asnumpy (a )
401
401
@@ -446,13 +446,18 @@ def test_fft_1D(self, dtype, n, norm):
446
446
# but dpnp return float32 if input is float32
447
447
assert_dtype_allclose (result , expected , check_only_type_kind = True )
448
448
449
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
450
449
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
451
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
450
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
452
451
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
453
452
def test_fft_1D_complex (self , dtype , n , norm ):
454
453
x = dpnp .linspace (- 1 , 1 , 11 )
455
454
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
455
+ # input should be Hermitian
456
+ a [0 ].imag = 0
457
+ if n in [None , 18 ]:
458
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
459
+ a [f_ny ].imag = 0
460
+ a [f_ny :] = 0 # no data needed after Nyquist mode
456
461
a = dpnp .asarray (a , dtype = dtype )
457
462
a_np = dpnp .asnumpy (a )
458
463
@@ -473,29 +478,55 @@ def test_fft_1D_on_2D_array(self, dtype, n, axis, norm, order):
473
478
expected = numpy .fft .irfft (a_np , n = n , axis = axis , norm = norm )
474
479
assert_dtype_allclose (result , expected , check_only_type_kind = True )
475
480
476
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
477
481
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
478
482
@pytest .mark .parametrize ("n" , [None , 5 , 8 ])
479
483
@pytest .mark .parametrize ("axis" , [0 , 1 , 2 ])
480
484
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
481
485
@pytest .mark .parametrize ("order" , ["C" , "F" ])
482
486
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 )
487
+ x1 = numpy .random .uniform (- 10 , 10 , 120 )
488
+ x2 = numpy .random .uniform (- 10 , 10 , 120 )
485
489
a_np = numpy .array (x1 + 1j * x2 , dtype = dtype ).reshape (
486
- 2 , 3 , 4 , order = order
490
+ 4 , 5 , 6 , order = order
487
491
)
492
+ # each 1-D array of input should be Hermitian
493
+ if axis == 0 :
494
+ a_np [0 ].imag = 0
495
+ if n is None :
496
+ # for axis=0 and n=8, Nyquist mode is not present
497
+ f_ny = - 1 # Nyquist mode
498
+ a_np [- 1 ].imag = 0
499
+ elif axis == 1 :
500
+ a_np [:, 0 , :].imag = 0
501
+ if n in [None , 8 ]:
502
+ f_ny = - 1 # Nyquist mode
503
+ a_np [:, f_ny , :].imag = 0
504
+ a_np [:, f_ny :, :] = 0 # no data needed after Nyquist mode
505
+ elif axis == 2 :
506
+ a_np [..., 0 ].imag = 0
507
+ if n in [None , 8 ]:
508
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
509
+ a_np [..., f_ny ].imag = 0
510
+ a_np [..., f_ny :] = 0 # no data needed after Nyquist mode
511
+
488
512
a = dpnp .asarray (a_np )
489
513
490
514
result = dpnp .fft .irfft (a , n = n , axis = axis , norm = norm )
491
515
expected = numpy .fft .irfft (a_np , n = n , axis = axis , norm = norm )
492
- assert_dtype_allclose (result , expected , check_only_type_kind = True )
516
+ assert_dtype_allclose (
517
+ result , expected , check_only_type_kind = True , factor = 16
518
+ )
493
519
494
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
495
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
520
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
496
521
def test_fft_usm_ndarray (self , n ):
497
522
x = dpt .linspace (- 1 , 1 , 11 )
498
523
a = dpt .sin (x ) + 1j * dpt .cos (x )
524
+ # input should be Hermitian
525
+ a [0 ] = dpt .sin (x [0 ])
526
+ if n in [None , 18 ]:
527
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
528
+ a [f_ny ] = dpt .sin (x [f_ny ])
529
+ a [f_ny :] = 0 # no data needed after Nyquist mode
499
530
a_usm = dpt .asarray (a , dtype = dpt .complex64 )
500
531
a_np = dpt .asnumpy (a_usm )
501
532
out_shape = n if n is not None else 2 * (a_usm .shape [0 ] - 1 )
@@ -506,13 +537,18 @@ def test_fft_usm_ndarray(self, n):
506
537
expected = numpy .fft .irfft (a_np , n = n )
507
538
assert_dtype_allclose (result , expected , check_only_type_kind = True )
508
539
509
- @pytest .mark .skipif (is_gpu_with_fp64 , reason = "MKLD17702" )
510
540
@pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
511
- @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
541
+ @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
512
542
@pytest .mark .parametrize ("norm" , ["forward" , "backward" , "ortho" ])
513
543
def test_fft_1D_out (self , dtype , n , norm ):
514
544
x = dpnp .linspace (- 1 , 1 , 11 )
515
545
a = dpnp .sin (x ) + 1j * dpnp .cos (x )
546
+ # input should be Hermitian
547
+ a [0 ].imag = 0
548
+ if n in [None , 18 ]:
549
+ f_ny = - 1 if n is None else n // 2 # Nyquist mode
550
+ a [f_ny ].imag = 0
551
+ a [f_ny :] = 0 # no data needed after Nyquist mode
516
552
a = dpnp .asarray (a , dtype = dtype )
517
553
a_np = dpnp .asnumpy (a )
518
554
@@ -624,7 +660,7 @@ def test_fft_usm_ndarray(self, n):
624
660
x = dpt .linspace (- 1 , 1 , 11 )
625
661
a_usm = dpt .asarray (dpt .sin (x ))
626
662
a_np = dpt .asnumpy (a_usm )
627
- out_shape = a_usm .shape [0 ] // 2 + 1 if n is None else n // 2 + 1
663
+ out_shape = a_usm .shape [0 ] // 2 + 1 if n is None else n // 2
628
664
out_dtype = map_dtype_to_device (dpnp .complex128 , a_usm .sycl_device )
629
665
out = dpt .empty (out_shape , dtype = out_dtype )
630
666
@@ -642,7 +678,7 @@ def test_fft_1D_out(self, dtype, n, norm):
642
678
a = dpnp .asarray (a , dtype = dtype )
643
679
a_np = dpnp .asnumpy (a )
644
680
645
- out_shape = a .shape [0 ] // 2 + 1 if n is None else n // 2 + 1
681
+ out_shape = a .shape [0 ] // 2 + 1 if n is None else n // 2
646
682
out_dtype = dpnp .complex64 if dtype == dpnp .float32 else dpnp .complex128
647
683
out = dpnp .empty (out_shape , dtype = out_dtype )
648
684
@@ -661,7 +697,7 @@ def test_fft_1D_on_2D_array_out(self, dtype, n, axis, norm, order):
661
697
a = dpnp .asarray (a_np )
662
698
663
699
out_shape = list (a .shape )
664
- out_shape [axis ] = a .shape [axis ] // 2 + 1 if n is None else n // 2 + 1
700
+ out_shape [axis ] = a .shape [axis ] // 2 + 1 if n is None else n // 2
665
701
out_shape = tuple (out_shape )
666
702
out_dtype = dpnp .complex64 if dtype == dpnp .float32 else dpnp .complex128
667
703
out = dpnp .empty (out_shape , dtype = out_dtype )
0 commit comments