2020from .third_party .cupy import testing
2121
2222
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-
4923class TestFft :
5024 @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
5125 @pytest .mark .parametrize ("n" , [None , 5 , 20 ])
@@ -577,13 +551,14 @@ def test_basic(self, func, dtype, axes):
577551
578552
579553class 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+ )
581558 @pytest .mark .parametrize ("n" , [None , 5 , 18 ])
582559 @pytest .mark .parametrize ("norm" , [None , "backward" , "forward" , "ortho" ])
583560 def test_basic (self , dtype , n , norm ):
584561 a = generate_random_numpy_array (11 , dtype )
585- if numpy .issubdtype (dtype , numpy .complexfloating ):
586- a = _make_array_Hermitian (a , n )
587562 ia = dpnp .array (a )
588563
589564 result = dpnp .fft .hfft (ia , n = n , norm = norm )
@@ -626,8 +601,6 @@ class TestIrfft:
626601 @pytest .mark .parametrize ("norm" , [None , "backward" , "forward" , "ortho" ])
627602 def test_basic (self , dtype , n , norm ):
628603 a = generate_random_numpy_array (11 )
629- if numpy .issubdtype (dtype , numpy .complexfloating ):
630- a = _make_array_Hermitian (a , n )
631604 ia = dpnp .array (a )
632605
633606 result = dpnp .fft .irfft (ia , n = n , norm = norm )
@@ -644,10 +617,6 @@ def test_basic(self, dtype, n, norm):
644617 def test_2d_array (self , dtype , n , axis , norm , order ):
645618 a = generate_random_numpy_array ((3 , 4 ), dtype = dtype , order = order )
646619 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 )
651620
652621 result = dpnp .fft .irfft (ia , n = n , axis = axis , norm = norm )
653622 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):
661630 def test_3d_array (self , dtype , n , axis , norm , order ):
662631 a = generate_random_numpy_array ((4 , 5 , 6 ), dtype , order )
663632 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 )
668633
669634 result = dpnp .fft .irfft (ia , n = n , axis = axis , norm = norm )
670635 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):
674639 def test_usm_ndarray (self , n ):
675640 a = generate_random_numpy_array (11 , dtype = numpy .complex64 )
676641 a_usm = dpt .asarray (a )
677- a_usm = _make_array_Hermitian (a_usm , n )
678642
679643 expected = numpy .fft .irfft (a , n = n )
680644 out = dpt .empty (expected .shape , dtype = a_usm .real .dtype )
@@ -688,7 +652,6 @@ def test_usm_ndarray(self, n):
688652 def test_out (self , dtype , n , norm ):
689653 a = generate_random_numpy_array (11 , dtype = dtype )
690654 ia = dpnp .array (a )
691- ia = _make_array_Hermitian (ia , n )
692655
693656 expected = numpy .fft .irfft (a , n = n , norm = norm )
694657 out = dpnp .empty (expected .shape , dtype = a .real .dtype )
@@ -704,9 +667,6 @@ def test_out(self, dtype, n, norm):
704667 def test_2d_array_out (self , dtype , n , axis , norm , order ):
705668 a = generate_random_numpy_array ((3 , 4 ), dtype = dtype , order = order )
706669 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 )
710670
711671 expected = numpy .fft .irfft (a , n = n , axis = axis , norm = norm )
712672 out = dpnp .empty (expected .shape , dtype = expected .dtype )
@@ -994,5 +954,7 @@ def test_1d_array(self):
994954
995955 result = dpnp .fft .irfftn (ia )
996956 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
998960 assert_dtype_allclose (result , expected , check_only_type_kind = flag )
0 commit comments