We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ihfft2


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ivy/functional/frontends/paddle/fft.py`
Content:
```
1 # global
2 import ivy
3 from ivy.func_wrapper import with_supported_dtypes
4 from ivy.functional.frontends.paddle.func_wrapper import (
5     to_ivy_arrays_and_back,
6 )
7 
8 
9 @with_supported_dtypes(
10     {"2.5.1 and below": ("complex64", "complex128")},
11     "paddle",
12 )
13 @to_ivy_arrays_and_back
14 def fft(x, n=None, axis=-1.0, norm="backward", name=None):
15     ret = ivy.fft(ivy.astype(x, "complex128"), axis, norm=norm, n=n)
16     return ivy.astype(ret, x.dtype)
17 
18 
19 @with_supported_dtypes(
20     {
21         "2.5.1 and below": (
22             "int32",
23             "int64",
24             "float32",
25             "float64",
26         )
27     },
28     "paddle",
29 )
30 @to_ivy_arrays_and_back
31 def fftfreq(n, d=1.0, dtype=None, name=None):
32     if d * n == 0:
33         raise ValueError("d or n should not be 0.")
34 
35     if dtype is None:
36         dtype = ivy.default_dtype()
37     val = 1.0 / (n * d)
38     pos_max = (n + 1) // 2
39     neg_max = n // 2
40     indices = ivy.arange(-neg_max, pos_max, dtype=dtype)
41     indices = ivy.roll(indices, -neg_max)
42     return ivy.multiply(indices, val)
43 
44 
45 @with_supported_dtypes(
46     {
47         "2.5.1 and below": (
48             "int32",
49             "int64",
50             "float32",
51             "float64",
52             "complex64",
53             "complex128",
54         )
55     },
56     "paddle",
57 )
58 @to_ivy_arrays_and_back
59 def fftshift(x, axes=None, name=None):
60     shape = x.shape
61 
62     if axes is None:
63         axes = tuple(range(x.ndim))
64         shifts = [(dim // 2) for dim in shape]
65     elif isinstance(axes, int):
66         shifts = shape[axes] // 2
67     else:
68         shifts = ivy.concat([shape[ax] // 2 for ax in axes])
69 
70     roll = ivy.roll(x, shifts, axis=axes)
71 
72     return roll
73 
74 
75 @with_supported_dtypes(
76     {"2.5.1 and below": ("complex64", "complex128")},
77     "paddle",
78 )
79 @to_ivy_arrays_and_back
80 def hfft(x, n=None, axes=-1, norm="backward", name=None):
81     """Compute the FFT of a signal that has Hermitian symmetry, resulting in a real
82     spectrum."""
83     # Determine the input shape and axis length
84     input_shape = x.shape
85     input_len = input_shape[axes]
86 
87     # Calculate n if not provided
88     if n is None:
89         n = 2 * (input_len - 1)
90 
91     # Perform the FFT along the specified axis
92     result = ivy.fft(x, axes, n=n, norm=norm)
93 
94     return ivy.real(result)
95 
96 
97 @with_supported_dtypes(
98     {"2.5.1 and below": "complex64"},
99     "paddle",
100 )
101 @to_ivy_arrays_and_back
102 def hfft2(x, s=None, axis=(-2, -1), norm="backward"):
103     # check if the input tensor x is a hermitian complex
104     if not ivy.allclose(ivy.conj(ivy.matrix_transpose(x)), x):
105         raise ValueError("Input tensor x must be Hermitian complex.")
106 
107     fft_result = ivy.fft2(x, s=s, dim=axis, norm=norm)
108 
109     # Depending on the norm, apply scaling and normalization
110     if norm == "forward":
111         fft_result /= ivy.sqrt(ivy.prod(ivy.shape(fft_result)))
112     elif norm == "ortho":
113         fft_result /= ivy.sqrt(ivy.prod(ivy.shape(x)))
114 
115     return ivy.real(fft_result)  # Return the real part of the result
116 
117 
118 @with_supported_dtypes(
119     {"2.5.1 and below": ("complex64", "complex128")},
120     "paddle",
121 )
122 @to_ivy_arrays_and_back
123 def ifft(x, n=None, axis=-1.0, norm="backward", name=None):
124     ret = ivy.ifft(ivy.astype(x, "complex128"), axis, norm=norm, n=n)
125     return ivy.astype(ret, x.dtype)
126 
127 
128 @with_supported_dtypes(
129     {
130         "2.5.1 and below": (
131             "int32",
132             "int64",
133             "float32",
134             "float64",
135         )
136     },
137     "paddle",
138 )
139 @to_ivy_arrays_and_back
140 def ifftshift(x, axes=None, name=None):
141     shape = x.shape
142 
143     if axes is None:
144         axes = tuple(range(x.ndim))
145         shifts = [-(dim // 2) for dim in shape]
146     elif isinstance(axes, int):
147         shifts = -(shape[axes] // 2)
148     else:
149         shifts = ivy.concat([-shape[ax] // 2 for ax in axes])
150 
151     roll = ivy.roll(x, shifts, axis=axes)
152 
153     return roll
154 
155 
156 @with_supported_dtypes(
157     {"2.5.1 and below": ("complex64", "complex128")},
158     "paddle",
159 )
160 @to_ivy_arrays_and_back
161 def irfft(x, n=None, axis=-1.0, norm="backward", name=None):
162     if n is None:
163         n = 2 * (x.shape[axis] - 1)
164 
165     pos_freq_terms = ivy.take_along_axis(x, range(n // 2 + 1), axis)
166     neg_freq_terms = ivy.conj(pos_freq_terms[1:-1][::-1])
167     combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=axis)
168     time_domain = ivy.ifft(combined_freq_terms, axis, norm=norm, n=n)
169     if ivy.isreal(x):
170         time_domain = ivy.real(time_domain)
171     return time_domain
172 
173 
174 @with_supported_dtypes(
175     {
176         "2.5.1 and below": (
177             "int32",
178             "int64",
179             "float16",
180             "float32",
181             "float64",
182             "complex64",
183             "complex128",
184         )
185     },
186     "paddle",
187 )
188 @to_ivy_arrays_and_back
189 def irfft2(x, s=None, axes=(-2, -1), norm="backward"):
190     # Handle values if None
191     if s is None:
192         s = x.shape
193     if axes is None:
194         axes = (-2, -1)
195 
196     # Calculate the normalization factor 'n' based on the shape 's'
197     n = ivy.prod(ivy.array(s))
198 
199     result = ivy.ifftn(x, dim=axes[0], norm=norm)
200 
201     # Normalize the result based on the 'norm' parameter
202     if norm == "backward":
203         result /= n
204     elif norm == "forward":
205         result *= n
206     elif norm == "ortho":
207         result /= ivy.sqrt(n)
208     return result
209 
210 
211 @with_supported_dtypes(
212     {"2.5.1 and below": ("complex64", "complex128")},
213     "paddle",
214 )
215 @to_ivy_arrays_and_back
216 def irfftn(x, s=None, axes=None, norm="backward", name=None):
217     x = ivy.array(x)
218 
219     if axes is None:
220         axes = list(range(len(x.shape)))
221 
222     include_last_axis = len(x.shape) - 1 in axes
223 
224     if s is None:
225         s = [
226             x.shape[axis] if axis != (len(x.shape) - 1) else 2 * (x.shape[axis] - 1)
227             for axis in axes
228         ]
229 
230     real_result = x
231     remaining_axes = [axis for axis in axes if axis != (len(x.shape) - 1)]
232 
233     if remaining_axes:
234         real_result = ivy.ifftn(
235             x,
236             s=[s[axes.index(axis)] for axis in remaining_axes],
237             axes=remaining_axes,
238             norm=norm,
239         )
240 
241     if include_last_axis:
242         axis = len(x.shape) - 1
243         size = s[axes.index(axis)]
244         freq_domain = ivy.moveaxis(real_result, axis, -1)
245         slices = [slice(None)] * ivy.get_num_dims(freq_domain)
246         slices[-1] = slice(0, size // 2 + 1)
247         pos_freq_terms = freq_domain[tuple(slices)]
248         slices[-1] = slice(1, -1)
249         neg_freq_terms = ivy.conj(pos_freq_terms[tuple(slices)][..., ::-1])
250         combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=-1)
251         real_result = ivy.ifftn(combined_freq_terms, s=[size], axes=[-1], norm=norm)
252         real_result = ivy.moveaxis(real_result, -1, axis)
253 
254     if ivy.is_complex_dtype(x.dtype):
255         output_dtype = "float32" if x.dtype == "complex64" else "float64"
256     else:
257         output_dtype = "float32"
258 
259     result_t = ivy.astype(real_result, output_dtype)
260     return result_t
261 
262 
263 @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
264 @to_ivy_arrays_and_back
265 def rfft(x, n=None, axis=-1, norm="backward", name=None):
266     return ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm)
267 
268 
269 @to_ivy_arrays_and_back
270 def rfftfreq(n, d=1.0, dtype=None, name=None):
271     dtype = ivy.default_dtype()
272     val = 1.0 / (n * d)
273     pos_max = n // 2 + 1
274     indices = ivy.arange(0, pos_max, dtype=dtype)
275     return indices * val
276
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py
--- a/ivy/functional/frontends/paddle/fft.py
+++ b/ivy/functional/frontends/paddle/fft.py
@@ -153,6 +153,41 @@
     return roll
 
 
+@with_supported_dtypes(
+    {
+        "2.5.1 and below": (
+            "int32",
+            "int64",
+            "float32",
+            "float64",
+        )
+    },
+    "paddle",
+)
+@to_ivy_arrays_and_back
+def ihfft2(x, s=None, axes=(-2, -1), norm="backward", name=None):
+    # check if the input array is two-dimensional and real
+    if len(ivy.array(x).shape) != 2 or ivy.is_complex_dtype(x):
+        raise ValueError("input must be a two-dimensional real array")
+
+    # cast the input to the same float64 type so that there are no backend issues
+    x_ = ivy.astype(x, ivy.float64)
+
+    ihfft2_result = 0
+    # Compute the complex conjugate of the 2-dimensional discrete Fourier Transform
+    if norm == "backward":
+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm="forward"))
+    if norm == "forward":
+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm="backward"))
+    if norm == "ortho":
+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm="ortho"))
+
+    if x.dtype == ivy.float32 or x.dtype == ivy.int32 or x.dtype == ivy.int64:
+        return ivy.astype(ihfft2_result, ivy.complex64)
+    if x.dtype == ivy.float64:
+        return ivy.astype(ihfft2_result, ivy.complex128)
+
+
 @with_supported_dtypes(
     {"2.5.1 and below": ("complex64", "complex128")},
     "paddle",

{"golden_diff": "diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py\n--- a/ivy/functional/frontends/paddle/fft.py\n+++ b/ivy/functional/frontends/paddle/fft.py\n@@ -153,6 +153,41 @@\n     return roll\n \n \n+@with_supported_dtypes(\n+    {\n+        \"2.5.1 and below\": (\n+            \"int32\",\n+            \"int64\",\n+            \"float32\",\n+            \"float64\",\n+        )\n+    },\n+    \"paddle\",\n+)\n+@to_ivy_arrays_and_back\n+def ihfft2(x, s=None, axes=(-2, -1), norm=\"backward\", name=None):\n+    # check if the input array is two-dimensional and real\n+    if len(ivy.array(x).shape) != 2 or ivy.is_complex_dtype(x):\n+        raise ValueError(\"input must be a two-dimensional real array\")\n+\n+    # cast the input to the same float64 type so that there are no backend issues\n+    x_ = ivy.astype(x, ivy.float64)\n+\n+    ihfft2_result = 0\n+    # Compute the complex conjugate of the 2-dimensional discrete Fourier Transform\n+    if norm == \"backward\":\n+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"forward\"))\n+    if norm == \"forward\":\n+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"backward\"))\n+    if norm == \"ortho\":\n+        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"ortho\"))\n+\n+    if x.dtype == ivy.float32 or x.dtype == ivy.int32 or x.dtype == ivy.int64:\n+        return ivy.astype(ihfft2_result, ivy.complex64)\n+    if x.dtype == ivy.float64:\n+        return ivy.astype(ihfft2_result, ivy.complex128)\n+\n+\n @with_supported_dtypes(\n     {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n     \"paddle\",\n", "issue": "ihfft2\n\n", "before_files": [{"content": "# global\nimport ivy\nfrom ivy.func_wrapper import with_supported_dtypes\nfrom ivy.functional.frontends.paddle.func_wrapper import (\n    to_ivy_arrays_and_back,\n)\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    ret = ivy.fft(ivy.astype(x, \"complex128\"), axis, norm=norm, n=n)\n    return ivy.astype(ret, x.dtype)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fftfreq(n, d=1.0, dtype=None, name=None):\n    if d * n == 0:\n        raise ValueError(\"d or n should not be 0.\")\n\n    if dtype is None:\n        dtype = ivy.default_dtype()\n    val = 1.0 / (n * d)\n    pos_max = (n + 1) // 2\n    neg_max = n // 2\n    indices = ivy.arange(-neg_max, pos_max, dtype=dtype)\n    indices = ivy.roll(indices, -neg_max)\n    return ivy.multiply(indices, val)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n            \"complex64\",\n            \"complex128\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fftshift(x, axes=None, name=None):\n    shape = x.shape\n\n    if axes is None:\n        axes = tuple(range(x.ndim))\n        shifts = [(dim // 2) for dim in shape]\n    elif isinstance(axes, int):\n        shifts = shape[axes] // 2\n    else:\n        shifts = ivy.concat([shape[ax] // 2 for ax in axes])\n\n    roll = ivy.roll(x, shifts, axis=axes)\n\n    return roll\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef hfft(x, n=None, axes=-1, norm=\"backward\", name=None):\n    \"\"\"Compute the FFT of a signal that has Hermitian symmetry, resulting in a real\n    spectrum.\"\"\"\n    # Determine the input shape and axis length\n    input_shape = x.shape\n    input_len = input_shape[axes]\n\n    # Calculate n if not provided\n    if n is None:\n        n = 2 * (input_len - 1)\n\n    # Perform the FFT along the specified axis\n    result = ivy.fft(x, axes, n=n, norm=norm)\n\n    return ivy.real(result)\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": \"complex64\"},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef hfft2(x, s=None, axis=(-2, -1), norm=\"backward\"):\n    # check if the input tensor x is a hermitian complex\n    if not ivy.allclose(ivy.conj(ivy.matrix_transpose(x)), x):\n        raise ValueError(\"Input tensor x must be Hermitian complex.\")\n\n    fft_result = ivy.fft2(x, s=s, dim=axis, norm=norm)\n\n    # Depending on the norm, apply scaling and normalization\n    if norm == \"forward\":\n        fft_result /= ivy.sqrt(ivy.prod(ivy.shape(fft_result)))\n    elif norm == \"ortho\":\n        fft_result /= ivy.sqrt(ivy.prod(ivy.shape(x)))\n\n    return ivy.real(fft_result)  # Return the real part of the result\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef ifft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    ret = ivy.ifft(ivy.astype(x, \"complex128\"), axis, norm=norm, n=n)\n    return ivy.astype(ret, x.dtype)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef ifftshift(x, axes=None, name=None):\n    shape = x.shape\n\n    if axes is None:\n        axes = tuple(range(x.ndim))\n        shifts = [-(dim // 2) for dim in shape]\n    elif isinstance(axes, int):\n        shifts = -(shape[axes] // 2)\n    else:\n        shifts = ivy.concat([-shape[ax] // 2 for ax in axes])\n\n    roll = ivy.roll(x, shifts, axis=axes)\n\n    return roll\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    if n is None:\n        n = 2 * (x.shape[axis] - 1)\n\n    pos_freq_terms = ivy.take_along_axis(x, range(n // 2 + 1), axis)\n    neg_freq_terms = ivy.conj(pos_freq_terms[1:-1][::-1])\n    combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=axis)\n    time_domain = ivy.ifft(combined_freq_terms, axis, norm=norm, n=n)\n    if ivy.isreal(x):\n        time_domain = ivy.real(time_domain)\n    return time_domain\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float16\",\n            \"float32\",\n            \"float64\",\n            \"complex64\",\n            \"complex128\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfft2(x, s=None, axes=(-2, -1), norm=\"backward\"):\n    # Handle values if None\n    if s is None:\n        s = x.shape\n    if axes is None:\n        axes = (-2, -1)\n\n    # Calculate the normalization factor 'n' based on the shape 's'\n    n = ivy.prod(ivy.array(s))\n\n    result = ivy.ifftn(x, dim=axes[0], norm=norm)\n\n    # Normalize the result based on the 'norm' parameter\n    if norm == \"backward\":\n        result /= n\n    elif norm == \"forward\":\n        result *= n\n    elif norm == \"ortho\":\n        result /= ivy.sqrt(n)\n    return result\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfftn(x, s=None, axes=None, norm=\"backward\", name=None):\n    x = ivy.array(x)\n\n    if axes is None:\n        axes = list(range(len(x.shape)))\n\n    include_last_axis = len(x.shape) - 1 in axes\n\n    if s is None:\n        s = [\n            x.shape[axis] if axis != (len(x.shape) - 1) else 2 * (x.shape[axis] - 1)\n            for axis in axes\n        ]\n\n    real_result = x\n    remaining_axes = [axis for axis in axes if axis != (len(x.shape) - 1)]\n\n    if remaining_axes:\n        real_result = ivy.ifftn(\n            x,\n            s=[s[axes.index(axis)] for axis in remaining_axes],\n            axes=remaining_axes,\n            norm=norm,\n        )\n\n    if include_last_axis:\n        axis = len(x.shape) - 1\n        size = s[axes.index(axis)]\n        freq_domain = ivy.moveaxis(real_result, axis, -1)\n        slices = [slice(None)] * ivy.get_num_dims(freq_domain)\n        slices[-1] = slice(0, size // 2 + 1)\n        pos_freq_terms = freq_domain[tuple(slices)]\n        slices[-1] = slice(1, -1)\n        neg_freq_terms = ivy.conj(pos_freq_terms[tuple(slices)][..., ::-1])\n        combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=-1)\n        real_result = ivy.ifftn(combined_freq_terms, s=[size], axes=[-1], norm=norm)\n        real_result = ivy.moveaxis(real_result, -1, axis)\n\n    if ivy.is_complex_dtype(x.dtype):\n        output_dtype = \"float32\" if x.dtype == \"complex64\" else \"float64\"\n    else:\n        output_dtype = \"float32\"\n\n    result_t = ivy.astype(real_result, output_dtype)\n    return result_t\n\n\n@with_supported_dtypes({\"2.5.1 and below\": (\"float32\", \"float64\")}, \"paddle\")\n@to_ivy_arrays_and_back\ndef rfft(x, n=None, axis=-1, norm=\"backward\", name=None):\n    return ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm)\n\n\n@to_ivy_arrays_and_back\ndef rfftfreq(n, d=1.0, dtype=None, name=None):\n    dtype = ivy.default_dtype()\n    val = 1.0 / (n * d)\n    pos_max = n // 2 + 1\n    indices = ivy.arange(0, pos_max, dtype=dtype)\n    return indices * val\n", "path": "ivy/functional/frontends/paddle/fft.py"}], "after_files": [{"content": "# global\nimport ivy\nfrom ivy.func_wrapper import with_supported_dtypes\nfrom ivy.functional.frontends.paddle.func_wrapper import (\n    to_ivy_arrays_and_back,\n)\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    ret = ivy.fft(ivy.astype(x, \"complex128\"), axis, norm=norm, n=n)\n    return ivy.astype(ret, x.dtype)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fftfreq(n, d=1.0, dtype=None, name=None):\n    if d * n == 0:\n        raise ValueError(\"d or n should not be 0.\")\n\n    if dtype is None:\n        dtype = ivy.default_dtype()\n    val = 1.0 / (n * d)\n    pos_max = (n + 1) // 2\n    neg_max = n // 2\n    indices = ivy.arange(-neg_max, pos_max, dtype=dtype)\n    indices = ivy.roll(indices, -neg_max)\n    return ivy.multiply(indices, val)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n            \"complex64\",\n            \"complex128\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef fftshift(x, axes=None, name=None):\n    shape = x.shape\n\n    if axes is None:\n        axes = tuple(range(x.ndim))\n        shifts = [(dim // 2) for dim in shape]\n    elif isinstance(axes, int):\n        shifts = shape[axes] // 2\n    else:\n        shifts = ivy.concat([shape[ax] // 2 for ax in axes])\n\n    roll = ivy.roll(x, shifts, axis=axes)\n\n    return roll\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef hfft(x, n=None, axes=-1, norm=\"backward\", name=None):\n    \"\"\"Compute the FFT of a signal that has Hermitian symmetry, resulting in a real\n    spectrum.\"\"\"\n    # Determine the input shape and axis length\n    input_shape = x.shape\n    input_len = input_shape[axes]\n\n    # Calculate n if not provided\n    if n is None:\n        n = 2 * (input_len - 1)\n\n    # Perform the FFT along the specified axis\n    result = ivy.fft(x, axes, n=n, norm=norm)\n\n    return ivy.real(result)\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": \"complex64\"},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef hfft2(x, s=None, axis=(-2, -1), norm=\"backward\"):\n    # check if the input tensor x is a hermitian complex\n    if not ivy.allclose(ivy.conj(ivy.matrix_transpose(x)), x):\n        raise ValueError(\"Input tensor x must be Hermitian complex.\")\n\n    fft_result = ivy.fft2(x, s=s, dim=axis, norm=norm)\n\n    # Depending on the norm, apply scaling and normalization\n    if norm == \"forward\":\n        fft_result /= ivy.sqrt(ivy.prod(ivy.shape(fft_result)))\n    elif norm == \"ortho\":\n        fft_result /= ivy.sqrt(ivy.prod(ivy.shape(x)))\n\n    return ivy.real(fft_result)  # Return the real part of the result\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef ifft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    ret = ivy.ifft(ivy.astype(x, \"complex128\"), axis, norm=norm, n=n)\n    return ivy.astype(ret, x.dtype)\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef ifftshift(x, axes=None, name=None):\n    shape = x.shape\n\n    if axes is None:\n        axes = tuple(range(x.ndim))\n        shifts = [-(dim // 2) for dim in shape]\n    elif isinstance(axes, int):\n        shifts = -(shape[axes] // 2)\n    else:\n        shifts = ivy.concat([-shape[ax] // 2 for ax in axes])\n\n    roll = ivy.roll(x, shifts, axis=axes)\n\n    return roll\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float32\",\n            \"float64\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef ihfft2(x, s=None, axes=(-2, -1), norm=\"backward\", name=None):\n    # check if the input array is two-dimensional and real\n    if len(ivy.array(x).shape) != 2 or ivy.is_complex_dtype(x):\n        raise ValueError(\"input must be a two-dimensional real array\")\n\n    # cast the input to the same float64 type so that there are no backend issues\n    x_ = ivy.astype(x, ivy.float64)\n\n    ihfft2_result = 0\n    # Compute the complex conjugate of the 2-dimensional discrete Fourier Transform\n    if norm == \"backward\":\n        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"forward\"))\n    if norm == \"forward\":\n        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"backward\"))\n    if norm == \"ortho\":\n        ihfft2_result = ivy.conj(ivy.rfftn(x_, s=s, axes=axes, norm=\"ortho\"))\n\n    if x.dtype == ivy.float32 or x.dtype == ivy.int32 or x.dtype == ivy.int64:\n        return ivy.astype(ihfft2_result, ivy.complex64)\n    if x.dtype == ivy.float64:\n        return ivy.astype(ihfft2_result, ivy.complex128)\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfft(x, n=None, axis=-1.0, norm=\"backward\", name=None):\n    if n is None:\n        n = 2 * (x.shape[axis] - 1)\n\n    pos_freq_terms = ivy.take_along_axis(x, range(n // 2 + 1), axis)\n    neg_freq_terms = ivy.conj(pos_freq_terms[1:-1][::-1])\n    combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=axis)\n    time_domain = ivy.ifft(combined_freq_terms, axis, norm=norm, n=n)\n    if ivy.isreal(x):\n        time_domain = ivy.real(time_domain)\n    return time_domain\n\n\n@with_supported_dtypes(\n    {\n        \"2.5.1 and below\": (\n            \"int32\",\n            \"int64\",\n            \"float16\",\n            \"float32\",\n            \"float64\",\n            \"complex64\",\n            \"complex128\",\n        )\n    },\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfft2(x, s=None, axes=(-2, -1), norm=\"backward\"):\n    # Handle values if None\n    if s is None:\n        s = x.shape\n    if axes is None:\n        axes = (-2, -1)\n\n    # Calculate the normalization factor 'n' based on the shape 's'\n    n = ivy.prod(ivy.array(s))\n\n    result = ivy.ifftn(x, dim=axes[0], norm=norm)\n\n    # Normalize the result based on the 'norm' parameter\n    if norm == \"backward\":\n        result /= n\n    elif norm == \"forward\":\n        result *= n\n    elif norm == \"ortho\":\n        result /= ivy.sqrt(n)\n    return result\n\n\n@with_supported_dtypes(\n    {\"2.5.1 and below\": (\"complex64\", \"complex128\")},\n    \"paddle\",\n)\n@to_ivy_arrays_and_back\ndef irfftn(x, s=None, axes=None, norm=\"backward\", name=None):\n    x = ivy.array(x)\n\n    if axes is None:\n        axes = list(range(len(x.shape)))\n\n    include_last_axis = len(x.shape) - 1 in axes\n\n    if s is None:\n        s = [\n            x.shape[axis] if axis != (len(x.shape) - 1) else 2 * (x.shape[axis] - 1)\n            for axis in axes\n        ]\n\n    real_result = x\n    remaining_axes = [axis for axis in axes if axis != (len(x.shape) - 1)]\n\n    if remaining_axes:\n        real_result = ivy.ifftn(\n            x,\n            s=[s[axes.index(axis)] for axis in remaining_axes],\n            axes=remaining_axes,\n            norm=norm,\n        )\n\n    if include_last_axis:\n        axis = len(x.shape) - 1\n        size = s[axes.index(axis)]\n        freq_domain = ivy.moveaxis(real_result, axis, -1)\n        slices = [slice(None)] * ivy.get_num_dims(freq_domain)\n        slices[-1] = slice(0, size // 2 + 1)\n        pos_freq_terms = freq_domain[tuple(slices)]\n        slices[-1] = slice(1, -1)\n        neg_freq_terms = ivy.conj(pos_freq_terms[tuple(slices)][..., ::-1])\n        combined_freq_terms = ivy.concat((pos_freq_terms, neg_freq_terms), axis=-1)\n        real_result = ivy.ifftn(combined_freq_terms, s=[size], axes=[-1], norm=norm)\n        real_result = ivy.moveaxis(real_result, -1, axis)\n\n    if ivy.is_complex_dtype(x.dtype):\n        output_dtype = \"float32\" if x.dtype == \"complex64\" else \"float64\"\n    else:\n        output_dtype = \"float32\"\n\n    result_t = ivy.astype(real_result, output_dtype)\n    return result_t\n\n\n@with_supported_dtypes({\"2.5.1 and below\": (\"float32\", \"float64\")}, \"paddle\")\n@to_ivy_arrays_and_back\ndef rfft(x, n=None, axis=-1, norm=\"backward\", name=None):\n    return ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm)\n\n\n@to_ivy_arrays_and_back\ndef rfftfreq(n, d=1.0, dtype=None, name=None):\n    dtype = ivy.default_dtype()\n    val = 1.0 / (n * d)\n    pos_max = n // 2 + 1\n    indices = ivy.arange(0, pos_max, dtype=dtype)\n    return indices * val\n", "path": "ivy/functional/frontends/paddle/fft.py"}]}