20
20
from .third_party .cupy import testing
21
21
22
22
23
- def _make_array_Hermitian (a , n ):
24
- """
25
- For `dpnp.fft.irfft` and `dpnp.fft.hfft`, the input array should be Hermitian.
26
- If it is not, the behavior is undefined. This function makes necessary changes
27
- to make sure the given array is Hermitian.
28
- """
29
-
30
- a [0 ] = a [0 ].real
31
- if n is None :
32
- # last element is Nyquist mode
33
- a [- 1 ] = a [- 1 ].real
34
- elif n % 2 == 0 :
35
- # Nyquist mode (n//2+1 mode) is n//2-th element
36
- f_ny = n // 2
37
- if a .shape [0 ] > f_ny :
38
- a [f_ny ] = a [f_ny ].real
39
- a [f_ny + 1 :] = 0 # no data needed after Nyquist mode
40
- else :
41
- # No Nyquist mode
42
- f_ny = n // 2
43
- if a .shape [0 ] > f_ny :
44
- a [f_ny + 1 :] = 0 # no data needed for the second half
45
-
46
- return a
47
-
48
-
49
23
class TestFft :
50
24
@pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
51
25
@pytest .mark .parametrize ("n" , [None , 5 , 20 ])
@@ -577,13 +551,14 @@ def test_basic(self, func, dtype, axes):
577
551
578
552
579
553
class TestHfft :
580
- @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
554
+ # TODO: include boolean dtype when mkl_fft-gh-180 is merged
555
+ @pytest .mark .parametrize (
556
+ "dtype" , get_all_dtypes (no_none = True , no_bool = True )
557
+ )
581
558
@pytest .mark .parametrize ("n" , [None , 5 , 18 ])
582
559
@pytest .mark .parametrize ("norm" , [None , "backward" , "forward" , "ortho" ])
583
560
def test_basic (self , dtype , n , norm ):
584
561
a = generate_random_numpy_array (11 , dtype )
585
- if numpy .issubdtype (dtype , numpy .complexfloating ):
586
- a = _make_array_Hermitian (a , n )
587
562
ia = dpnp .array (a )
588
563
589
564
result = dpnp .fft .hfft (ia , n = n , norm = norm )
@@ -626,8 +601,6 @@ class TestIrfft:
626
601
@pytest .mark .parametrize ("norm" , [None , "backward" , "forward" , "ortho" ])
627
602
def test_basic (self , dtype , n , norm ):
628
603
a = generate_random_numpy_array (11 )
629
- if numpy .issubdtype (dtype , numpy .complexfloating ):
630
- a = _make_array_Hermitian (a , n )
631
604
ia = dpnp .array (a )
632
605
633
606
result = dpnp .fft .irfft (ia , n = n , norm = norm )
@@ -644,10 +617,6 @@ def test_basic(self, dtype, n, norm):
644
617
def test_2d_array (self , dtype , n , axis , norm , order ):
645
618
a = generate_random_numpy_array ((3 , 4 ), dtype = dtype , order = order )
646
619
ia = dpnp .array (a )
647
- # For dpnp, each 1-D array of input should be Hermitian
648
- ia = dpnp .moveaxis (ia , axis , 0 )
649
- ia = _make_array_Hermitian (ia , n )
650
- ia = dpnp .moveaxis (ia , 0 , axis )
651
620
652
621
result = dpnp .fft .irfft (ia , n = n , axis = axis , norm = norm )
653
622
expected = numpy .fft .irfft (a , n = n , axis = axis , norm = norm )
@@ -661,10 +630,6 @@ def test_2d_array(self, dtype, n, axis, norm, order):
661
630
def test_3d_array (self , dtype , n , axis , norm , order ):
662
631
a = generate_random_numpy_array ((4 , 5 , 6 ), dtype , order )
663
632
ia = dpnp .array (a )
664
- # For dpnp, each 1-D array of input should be Hermitian
665
- ia = dpnp .moveaxis (ia , axis , 0 )
666
- ia = _make_array_Hermitian (ia , n )
667
- ia = dpnp .moveaxis (ia , 0 , axis )
668
633
669
634
result = dpnp .fft .irfft (ia , n = n , axis = axis , norm = norm )
670
635
expected = numpy .fft .irfft (a , n = n , axis = axis , norm = norm )
@@ -674,7 +639,6 @@ def test_3d_array(self, dtype, n, axis, norm, order):
674
639
def test_usm_ndarray (self , n ):
675
640
a = generate_random_numpy_array (11 , dtype = numpy .complex64 )
676
641
a_usm = dpt .asarray (a )
677
- a_usm = _make_array_Hermitian (a_usm , n )
678
642
679
643
expected = numpy .fft .irfft (a , n = n )
680
644
out = dpt .empty (expected .shape , dtype = a_usm .real .dtype )
@@ -688,7 +652,6 @@ def test_usm_ndarray(self, n):
688
652
def test_out (self , dtype , n , norm ):
689
653
a = generate_random_numpy_array (11 , dtype = dtype )
690
654
ia = dpnp .array (a )
691
- ia = _make_array_Hermitian (ia , n )
692
655
693
656
expected = numpy .fft .irfft (a , n = n , norm = norm )
694
657
out = dpnp .empty (expected .shape , dtype = a .real .dtype )
@@ -704,9 +667,6 @@ def test_out(self, dtype, n, norm):
704
667
def test_2d_array_out (self , dtype , n , axis , norm , order ):
705
668
a = generate_random_numpy_array ((3 , 4 ), dtype = dtype , order = order )
706
669
ia = dpnp .array (a )
707
- ia = dpnp .moveaxis (ia , axis , 0 )
708
- ia = _make_array_Hermitian (ia , n )
709
- ia = dpnp .moveaxis (ia , 0 , axis )
710
670
711
671
expected = numpy .fft .irfft (a , n = n , axis = axis , norm = norm )
712
672
out = dpnp .empty (expected .shape , dtype = expected .dtype )
@@ -994,5 +954,7 @@ def test_1d_array(self):
994
954
995
955
result = dpnp .fft .irfftn (ia )
996
956
expected = numpy .fft .irfftn (a )
997
- flag = True if numpy_version () < "2.0.0" else False
957
+ # TODO: change to the commented line when mkl_fft-gh-180 is merged
958
+ flag = True
959
+ # flag = True if numpy_version() < "2.0.0" else False
998
960
assert_dtype_allclose (result , expected , check_only_type_kind = flag )
0 commit comments