We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix reduction_ops.test_torch_unique
|   |   |
|---|---|
|paddle|<a href="https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252"><img src=https://img.shields.io/badge/-failure-red></a>
|numpy|<a href="https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252"><img src=https://img.shields.io/badge/-failure-red></a>
|jax|<a href="https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252"><img src=https://img.shields.io/badge/-failure-red></a>
|tensorflow|<a href="https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252"><img src=https://img.shields.io/badge/-failure-red></a>
|torch|<a href="https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252"><img src=https://img.shields.io/badge/-failure-red></a>


--- 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/torch/reduction_ops.py`
Content:
```
1 import ivy
2 from ivy.func_wrapper import with_unsupported_dtypes
3 from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
4 from collections import namedtuple
5 
6 
7 @to_ivy_arrays_and_back
8 def dist(input, other, p=2):
9     return ivy.vector_norm(ivy.subtract(input, other), ord=p)
10 
11 
12 @to_ivy_arrays_and_back
13 def argmax(input, dim=None, keepdim=False):
14     return ivy.argmax(input, axis=dim, keepdims=keepdim)
15 
16 
17 @to_ivy_arrays_and_back
18 def argmin(input, dim=None, keepdim=False):
19     return ivy.argmin(input, axis=dim, keepdims=keepdim).astype(ivy.int64)
20 
21 
22 @to_ivy_arrays_and_back
23 def amax(input, dim=None, keepdim=False, *, out=None):
24     return ivy.max(input, axis=dim, keepdims=keepdim, out=out)
25 
26 
27 @to_ivy_arrays_and_back
28 def amin(input, dim=None, keepdim=False, *, out=None):
29     return ivy.min(input, axis=dim, keepdims=keepdim, out=out)
30 
31 
32 @to_ivy_arrays_and_back
33 def all(input, dim=None, keepdim=False, *, out=None):
34     input_dtype = ivy.as_ivy_dtype(input.dtype)
35     ret = ivy.all(input, axis=dim, keepdims=keepdim, out=out)
36     if ivy.is_uint_dtype(input_dtype):
37         ret = ivy.astype(ret, input_dtype, out=out)
38     return ret
39 
40 
41 @to_ivy_arrays_and_back
42 def any(input, dim=None, keepdim=False, *, out=None):
43     input_dtype = ivy.as_ivy_dtype(input.dtype)
44     ret = ivy.any(input, axis=dim, keepdims=keepdim, out=out)
45     if ivy.is_uint_dtype(input_dtype):
46         ret = ivy.astype(ret, input_dtype, out=out)
47     return ret
48 
49 
50 @to_ivy_arrays_and_back
51 def sum(input, dim=None, keepdim=False, *, dtype=None, out=None):
52     return ivy.sum(input, axis=dim, dtype=dtype, keepdims=keepdim, out=out)
53 
54 
55 @to_ivy_arrays_and_back
56 def mean(input, dim=None, axis=None, keepdim=False, *, out=None):
57     if dim is None:
58         dim = axis
59     return ivy.mean(input, axis=dim, keepdims=keepdim, out=out)
60 
61 
62 @to_ivy_arrays_and_back
63 def nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None):
64     return ivy.nanmean(input, axis=dim, keepdims=keepdim, dtype=dtype, out=out)
65 
66 
67 @to_ivy_arrays_and_back
68 def median(input, dim=None, keepdim=False, *, out=None):
69     if dim is None:
70         input = ivy.reshape(input, (-1,))
71         sorted_input = ivy.sort(input)
72         return sorted_input[(sorted_input.shape[0] - 1) // 2]
73 
74     median_tuple = namedtuple("median", ["values", "indices"])
75 
76     if input.ndim == 0:
77         result = median_tuple(input, ivy.array(0))
78     else:
79         sorted_indices = ivy.argsort(input, axis=dim)
80         median_indices = ivy.gather(
81             sorted_indices, (sorted_indices.shape[dim] - 1) // 2, axis=dim
82         )
83         median_values = ivy.take_along_axis(
84             input, ivy.expand_dims(median_indices, axis=dim), dim
85         ).squeeze(dim)
86 
87         if keepdim:
88             median_values = ivy.expand_dims(median_values, axis=dim)
89             median_indices = ivy.expand_dims(median_indices, axis=dim)
90 
91         result = median_tuple(median_values, median_indices)
92     if out is not None:
93         ivy.inplace_update(out[0], result.values)
94         ivy.inplace_update(out[1], result.indices)
95         return out
96     return result
97 
98 
99 @to_ivy_arrays_and_back
100 @with_unsupported_dtypes({"2.0.1 and below": ("float16",)}, "torch")
101 def std(input, dim=None, unbiased=True, keepdim=False, *, out=None):
102     return ivy.std(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)
103 
104 
105 @to_ivy_arrays_and_back
106 @with_unsupported_dtypes(
107     {
108         "2.0.1 and below": (
109             "float16",
110             "bfloat16",
111         )
112     },
113     "torch",
114 )
115 def prod(input, dim=None, keepdim=False, *, dtype=None):
116     if not dtype:
117         if "int" in input.dtype:
118             dtype = ivy.int64
119     return ivy.prod(input, axis=dim, dtype=dtype, keepdims=keepdim)
120 
121 
122 @to_ivy_arrays_and_back
123 def var(input, dim, unbiased, keepdim=False, *, out=None):
124     return ivy.var(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)
125 
126 
127 @to_ivy_arrays_and_back
128 def min(input, dim=None, keepdim=False, *, out=None):
129     if dim is None:
130         return ivy.min(input, axis=dim, keepdims=keepdim, out=out)
131     elif out is not None:
132         ivy.min(input, axis=dim, keepdims=keepdim, out=out[0])
133         ivy.argmin(input, axis=dim, keepdims=keepdim, out=out[1])
134         return out
135     else:
136         min_tuple = namedtuple("min", ["values", "indices"])
137         return min_tuple(
138             ivy.min(input, axis=dim, keepdims=keepdim),
139             ivy.argmin(input, axis=dim, keepdims=keepdim),
140         )
141 
142 
143 @to_ivy_arrays_and_back
144 def max(input, dim=None, keepdim=False, *, out=None):
145     if dim is None:
146         return ivy.max(input, axis=dim, keepdims=keepdim, out=out)
147     elif out is not None:
148         ivy.max(input, axis=dim, keepdims=keepdim, out=out[0])
149         ivy.argmax(input, axis=dim, keepdims=keepdim, out=out[1])
150         return out
151     else:
152         max_tuple = namedtuple("max", ["values", "indices"])
153         return max_tuple(
154             ivy.max(input, axis=dim, keepdims=keepdim),
155             ivy.argmax(input, axis=dim, keepdims=keepdim),
156         )
157 
158 
159 @to_ivy_arrays_and_back
160 def moveaxis(input, source, destination):
161     return ivy.moveaxis(input, source, destination)
162 
163 
164 @to_ivy_arrays_and_back
165 @with_unsupported_dtypes({"2.12.0 and below": ("bfloat16",)}, "tensorflow")
166 def std_mean(input, dim, unbiased, keepdim=False, *, out=None):
167     temp_std = ivy.std(
168         input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out
169     )
170     temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)
171     return temp_std, temp_mean
172 
173 
174 @to_ivy_arrays_and_back
175 def var_mean(input, dim, unbiased, keepdim=False, *, out=None):
176     temp_var = ivy.var(
177         input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out
178     )
179     temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)
180     return (temp_var, temp_mean)
181 
182 
183 @to_ivy_arrays_and_back
184 def aminmax(input, *, dim=None, keepdim=False, out=None):
185     minmax_tuple = namedtuple("minmax", ["min", "max"])
186     return minmax_tuple(
187         ivy.min(input, axis=dim, keepdims=keepdim, out=out),
188         ivy.max(input, axis=dim, keepdims=keepdim, out=out),
189     )
190 
191 
192 aminmax.unsupported_dtypes = {
193     "torch": ("float16", "bfloat16"),
194     "numpy": ("float16", "bfloat16"),
195     "jax": ("float16", "bfloat16"),
196     "tensorflow": ("float16", "bfloat16"),
197 }
198 
199 
200 @to_ivy_arrays_and_back
201 def quantile(input, q, dim=None, keepdim=False, *, interpolation="linear", out=None):
202     return ivy.quantile(
203         input, q, axis=dim, keepdims=keepdim, interpolation=interpolation, out=out
204     )
205 
206 
207 quantile.unsupported_dtypes = {
208     "torch": ("float16", "bfloat16"),
209     "numpy": ("float16", "bfloat16"),
210     "jax": ("float16", "bfloat16"),
211     "tensorflow": ("float16", "bfloat16"),
212 }
213 
214 
215 @to_ivy_arrays_and_back
216 def count_nonzero(input, dim=None):
217     return ivy.count_nonzero(input, axis=dim).astype(ivy.int64)
218 
219 
220 @to_ivy_arrays_and_back
221 def logsumexp(input, dim, keepdim=False, *, out=None):
222     c = ivy.max(input, axis=dim, keepdims=True)
223     if ivy.get_num_dims(c) > 0:
224         c = ivy.where(ivy.isinf(c), ivy.zeros_like(c), c)
225     elif not ivy.isinf(c):
226         c = 0
227     exponential = ivy.exp(input - c)
228     sum = ivy.sum(exponential, axis=dim, keepdims=keepdim)
229     ret = ivy.log(sum)
230     if not keepdim:
231         c = ivy.squeeze(c, axis=dim)
232     ret = ivy.add(ret, c, out=out)
233     return ret
234 
235 
236 @to_ivy_arrays_and_back
237 def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):
238     results = ivy.unique_all(input, axis=dim)
239 
240     fields = ["values"]
241     if return_inverse:
242         fields.append("inverse_indices")
243     if return_counts:
244         fields.append("counts")
245 
246     Results = namedtuple("Results", fields)
247 
248     values = [results.values]
249     if return_inverse:
250         values.append(results.inverse_indices)
251     if return_counts:
252         values.append(results.counts)
253 
254     return Results(*values)
255 
256 
257 @to_ivy_arrays_and_back
258 @with_unsupported_dtypes(
259     {"2.0.1 and below": ("bfloat16",)},
260     "torch",
261 )
262 def norm(input, p="fro", dim=None, keepdim=False, out=None, dtype=None):
263     if (
264         p == "fro" and (dim is None or isinstance(dim, int) or len(dim) <= 2)
265     ) or p is None:
266         p = 2
267     if isinstance(p, str):
268         if dim is None:
269             dim = tuple(range(input.dim()))
270         return ivy.matrix_norm(input, ord=p, axis=dim, keepdims=keepdim, out=out)
271     else:
272         return ivy.vector_norm(
273             input, ord=p, axis=dim, keepdims=keepdim, dtype=dtype, out=out
274         )
275 
276 
277 @with_unsupported_dtypes(
278     {
279         "2.0.1 and below": (
280             "float16",
281             "complex",
282         )
283     },
284     "torch",
285 )
286 @to_ivy_arrays_and_back
287 def unique_consecutive(input, return_inverse, return_counts, dim):
288     output, inverse_indices, counts = ivy.unique_consecutive(input, axis=dim)
289     ret = (output,)
290     if return_inverse:
291         ret += (inverse_indices,)
292     if return_counts:
293         ret += (counts,)
294     return ret
295
```
--- 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/torch/reduction_ops.py b/ivy/functional/frontends/torch/reduction_ops.py
--- a/ivy/functional/frontends/torch/reduction_ops.py
+++ b/ivy/functional/frontends/torch/reduction_ops.py
@@ -235,9 +235,11 @@
 
 @to_ivy_arrays_and_back
 def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):
-    results = ivy.unique_all(input, axis=dim)
+    if dim is not None:
+        sorted = True
+    results = ivy.unique_all(input, by_value=sorted, axis=dim)
 
-    fields = ["values"]
+    fields = ["output"]
     if return_inverse:
         fields.append("inverse_indices")
     if return_counts:
@@ -247,7 +249,12 @@
 
     values = [results.values]
     if return_inverse:
-        values.append(results.inverse_indices)
+        inverse_indices = results.inverse_indices
+
+        if dim is None:
+            inverse_indices = inverse_indices.reshape(input.shape)
+
+        values.append(inverse_indices)
     if return_counts:
         values.append(results.counts)

{"golden_diff": "diff --git a/ivy/functional/frontends/torch/reduction_ops.py b/ivy/functional/frontends/torch/reduction_ops.py\n--- a/ivy/functional/frontends/torch/reduction_ops.py\n+++ b/ivy/functional/frontends/torch/reduction_ops.py\n@@ -235,9 +235,11 @@\n \r\n @to_ivy_arrays_and_back\r\n def unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):\r\n-    results = ivy.unique_all(input, axis=dim)\r\n+    if dim is not None:\r\n+        sorted = True\r\n+    results = ivy.unique_all(input, by_value=sorted, axis=dim)\r\n \r\n-    fields = [\"values\"]\r\n+    fields = [\"output\"]\r\n     if return_inverse:\r\n         fields.append(\"inverse_indices\")\r\n     if return_counts:\r\n@@ -247,7 +249,12 @@\n \r\n     values = [results.values]\r\n     if return_inverse:\r\n-        values.append(results.inverse_indices)\r\n+        inverse_indices = results.inverse_indices\r\n+\r\n+        if dim is None:\r\n+            inverse_indices = inverse_indices.reshape(input.shape)\r\n+\r\n+        values.append(inverse_indices)\r\n     if return_counts:\r\n         values.append(results.counts)\n", "issue": "Fix reduction_ops.test_torch_unique\n|   |   |\r\n|---|---|\r\n|paddle|<a href=\"https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252\"><img src=https://img.shields.io/badge/-failure-red></a>\r\n|numpy|<a href=\"https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252\"><img src=https://img.shields.io/badge/-failure-red></a>\r\n|jax|<a href=\"https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252\"><img src=https://img.shields.io/badge/-failure-red></a>\r\n|tensorflow|<a href=\"https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252\"><img src=https://img.shields.io/badge/-failure-red></a>\r\n|torch|<a href=\"https://github.com/unifyai/ivy/actions/runs/6289534329/job/17076112252\"><img src=https://img.shields.io/badge/-failure-red></a>\r\n\n", "before_files": [{"content": "import ivy\r\nfrom ivy.func_wrapper import with_unsupported_dtypes\r\nfrom ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back\r\nfrom collections import namedtuple\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef dist(input, other, p=2):\r\n    return ivy.vector_norm(ivy.subtract(input, other), ord=p)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef argmax(input, dim=None, keepdim=False):\r\n    return ivy.argmax(input, axis=dim, keepdims=keepdim)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef argmin(input, dim=None, keepdim=False):\r\n    return ivy.argmin(input, axis=dim, keepdims=keepdim).astype(ivy.int64)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef amax(input, dim=None, keepdim=False, *, out=None):\r\n    return ivy.max(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef amin(input, dim=None, keepdim=False, *, out=None):\r\n    return ivy.min(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef all(input, dim=None, keepdim=False, *, out=None):\r\n    input_dtype = ivy.as_ivy_dtype(input.dtype)\r\n    ret = ivy.all(input, axis=dim, keepdims=keepdim, out=out)\r\n    if ivy.is_uint_dtype(input_dtype):\r\n        ret = ivy.astype(ret, input_dtype, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef any(input, dim=None, keepdim=False, *, out=None):\r\n    input_dtype = ivy.as_ivy_dtype(input.dtype)\r\n    ret = ivy.any(input, axis=dim, keepdims=keepdim, out=out)\r\n    if ivy.is_uint_dtype(input_dtype):\r\n        ret = ivy.astype(ret, input_dtype, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef sum(input, dim=None, keepdim=False, *, dtype=None, out=None):\r\n    return ivy.sum(input, axis=dim, dtype=dtype, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef mean(input, dim=None, axis=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        dim = axis\r\n    return ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None):\r\n    return ivy.nanmean(input, axis=dim, keepdims=keepdim, dtype=dtype, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef median(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        input = ivy.reshape(input, (-1,))\r\n        sorted_input = ivy.sort(input)\r\n        return sorted_input[(sorted_input.shape[0] - 1) // 2]\r\n\r\n    median_tuple = namedtuple(\"median\", [\"values\", \"indices\"])\r\n\r\n    if input.ndim == 0:\r\n        result = median_tuple(input, ivy.array(0))\r\n    else:\r\n        sorted_indices = ivy.argsort(input, axis=dim)\r\n        median_indices = ivy.gather(\r\n            sorted_indices, (sorted_indices.shape[dim] - 1) // 2, axis=dim\r\n        )\r\n        median_values = ivy.take_along_axis(\r\n            input, ivy.expand_dims(median_indices, axis=dim), dim\r\n        ).squeeze(dim)\r\n\r\n        if keepdim:\r\n            median_values = ivy.expand_dims(median_values, axis=dim)\r\n            median_indices = ivy.expand_dims(median_indices, axis=dim)\r\n\r\n        result = median_tuple(median_values, median_indices)\r\n    if out is not None:\r\n        ivy.inplace_update(out[0], result.values)\r\n        ivy.inplace_update(out[1], result.indices)\r\n        return out\r\n    return result\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes({\"2.0.1 and below\": (\"float16\",)}, \"torch\")\r\ndef std(input, dim=None, unbiased=True, keepdim=False, *, out=None):\r\n    return ivy.std(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes(\r\n    {\r\n        \"2.0.1 and below\": (\r\n            \"float16\",\r\n            \"bfloat16\",\r\n        )\r\n    },\r\n    \"torch\",\r\n)\r\ndef prod(input, dim=None, keepdim=False, *, dtype=None):\r\n    if not dtype:\r\n        if \"int\" in input.dtype:\r\n            dtype = ivy.int64\r\n    return ivy.prod(input, axis=dim, dtype=dtype, keepdims=keepdim)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef var(input, dim, unbiased, keepdim=False, *, out=None):\r\n    return ivy.var(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef min(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        return ivy.min(input, axis=dim, keepdims=keepdim, out=out)\r\n    elif out is not None:\r\n        ivy.min(input, axis=dim, keepdims=keepdim, out=out[0])\r\n        ivy.argmin(input, axis=dim, keepdims=keepdim, out=out[1])\r\n        return out\r\n    else:\r\n        min_tuple = namedtuple(\"min\", [\"values\", \"indices\"])\r\n        return min_tuple(\r\n            ivy.min(input, axis=dim, keepdims=keepdim),\r\n            ivy.argmin(input, axis=dim, keepdims=keepdim),\r\n        )\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef max(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        return ivy.max(input, axis=dim, keepdims=keepdim, out=out)\r\n    elif out is not None:\r\n        ivy.max(input, axis=dim, keepdims=keepdim, out=out[0])\r\n        ivy.argmax(input, axis=dim, keepdims=keepdim, out=out[1])\r\n        return out\r\n    else:\r\n        max_tuple = namedtuple(\"max\", [\"values\", \"indices\"])\r\n        return max_tuple(\r\n            ivy.max(input, axis=dim, keepdims=keepdim),\r\n            ivy.argmax(input, axis=dim, keepdims=keepdim),\r\n        )\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef moveaxis(input, source, destination):\r\n    return ivy.moveaxis(input, source, destination)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes({\"2.12.0 and below\": (\"bfloat16\",)}, \"tensorflow\")\r\ndef std_mean(input, dim, unbiased, keepdim=False, *, out=None):\r\n    temp_std = ivy.std(\r\n        input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out\r\n    )\r\n    temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n    return temp_std, temp_mean\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef var_mean(input, dim, unbiased, keepdim=False, *, out=None):\r\n    temp_var = ivy.var(\r\n        input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out\r\n    )\r\n    temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n    return (temp_var, temp_mean)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef aminmax(input, *, dim=None, keepdim=False, out=None):\r\n    minmax_tuple = namedtuple(\"minmax\", [\"min\", \"max\"])\r\n    return minmax_tuple(\r\n        ivy.min(input, axis=dim, keepdims=keepdim, out=out),\r\n        ivy.max(input, axis=dim, keepdims=keepdim, out=out),\r\n    )\r\n\r\n\r\naminmax.unsupported_dtypes = {\r\n    \"torch\": (\"float16\", \"bfloat16\"),\r\n    \"numpy\": (\"float16\", \"bfloat16\"),\r\n    \"jax\": (\"float16\", \"bfloat16\"),\r\n    \"tensorflow\": (\"float16\", \"bfloat16\"),\r\n}\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef quantile(input, q, dim=None, keepdim=False, *, interpolation=\"linear\", out=None):\r\n    return ivy.quantile(\r\n        input, q, axis=dim, keepdims=keepdim, interpolation=interpolation, out=out\r\n    )\r\n\r\n\r\nquantile.unsupported_dtypes = {\r\n    \"torch\": (\"float16\", \"bfloat16\"),\r\n    \"numpy\": (\"float16\", \"bfloat16\"),\r\n    \"jax\": (\"float16\", \"bfloat16\"),\r\n    \"tensorflow\": (\"float16\", \"bfloat16\"),\r\n}\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef count_nonzero(input, dim=None):\r\n    return ivy.count_nonzero(input, axis=dim).astype(ivy.int64)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef logsumexp(input, dim, keepdim=False, *, out=None):\r\n    c = ivy.max(input, axis=dim, keepdims=True)\r\n    if ivy.get_num_dims(c) > 0:\r\n        c = ivy.where(ivy.isinf(c), ivy.zeros_like(c), c)\r\n    elif not ivy.isinf(c):\r\n        c = 0\r\n    exponential = ivy.exp(input - c)\r\n    sum = ivy.sum(exponential, axis=dim, keepdims=keepdim)\r\n    ret = ivy.log(sum)\r\n    if not keepdim:\r\n        c = ivy.squeeze(c, axis=dim)\r\n    ret = ivy.add(ret, c, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):\r\n    results = ivy.unique_all(input, axis=dim)\r\n\r\n    fields = [\"values\"]\r\n    if return_inverse:\r\n        fields.append(\"inverse_indices\")\r\n    if return_counts:\r\n        fields.append(\"counts\")\r\n\r\n    Results = namedtuple(\"Results\", fields)\r\n\r\n    values = [results.values]\r\n    if return_inverse:\r\n        values.append(results.inverse_indices)\r\n    if return_counts:\r\n        values.append(results.counts)\r\n\r\n    return Results(*values)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes(\r\n    {\"2.0.1 and below\": (\"bfloat16\",)},\r\n    \"torch\",\r\n)\r\ndef norm(input, p=\"fro\", dim=None, keepdim=False, out=None, dtype=None):\r\n    if (\r\n        p == \"fro\" and (dim is None or isinstance(dim, int) or len(dim) <= 2)\r\n    ) or p is None:\r\n        p = 2\r\n    if isinstance(p, str):\r\n        if dim is None:\r\n            dim = tuple(range(input.dim()))\r\n        return ivy.matrix_norm(input, ord=p, axis=dim, keepdims=keepdim, out=out)\r\n    else:\r\n        return ivy.vector_norm(\r\n            input, ord=p, axis=dim, keepdims=keepdim, dtype=dtype, out=out\r\n        )\r\n\r\n\r\n@with_unsupported_dtypes(\r\n    {\r\n        \"2.0.1 and below\": (\r\n            \"float16\",\r\n            \"complex\",\r\n        )\r\n    },\r\n    \"torch\",\r\n)\r\n@to_ivy_arrays_and_back\r\ndef unique_consecutive(input, return_inverse, return_counts, dim):\r\n    output, inverse_indices, counts = ivy.unique_consecutive(input, axis=dim)\r\n    ret = (output,)\r\n    if return_inverse:\r\n        ret += (inverse_indices,)\r\n    if return_counts:\r\n        ret += (counts,)\r\n    return ret\r\n", "path": "ivy/functional/frontends/torch/reduction_ops.py"}], "after_files": [{"content": "import ivy\r\nfrom ivy.func_wrapper import with_unsupported_dtypes\r\nfrom ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back\r\nfrom collections import namedtuple\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef dist(input, other, p=2):\r\n    return ivy.vector_norm(ivy.subtract(input, other), ord=p)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef argmax(input, dim=None, keepdim=False):\r\n    return ivy.argmax(input, axis=dim, keepdims=keepdim)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef argmin(input, dim=None, keepdim=False):\r\n    return ivy.argmin(input, axis=dim, keepdims=keepdim).astype(ivy.int64)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef amax(input, dim=None, keepdim=False, *, out=None):\r\n    return ivy.max(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef amin(input, dim=None, keepdim=False, *, out=None):\r\n    return ivy.min(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef all(input, dim=None, keepdim=False, *, out=None):\r\n    input_dtype = ivy.as_ivy_dtype(input.dtype)\r\n    ret = ivy.all(input, axis=dim, keepdims=keepdim, out=out)\r\n    if ivy.is_uint_dtype(input_dtype):\r\n        ret = ivy.astype(ret, input_dtype, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef any(input, dim=None, keepdim=False, *, out=None):\r\n    input_dtype = ivy.as_ivy_dtype(input.dtype)\r\n    ret = ivy.any(input, axis=dim, keepdims=keepdim, out=out)\r\n    if ivy.is_uint_dtype(input_dtype):\r\n        ret = ivy.astype(ret, input_dtype, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef sum(input, dim=None, keepdim=False, *, dtype=None, out=None):\r\n    return ivy.sum(input, axis=dim, dtype=dtype, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef mean(input, dim=None, axis=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        dim = axis\r\n    return ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None):\r\n    return ivy.nanmean(input, axis=dim, keepdims=keepdim, dtype=dtype, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef median(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        input = ivy.reshape(input, (-1,))\r\n        sorted_input = ivy.sort(input)\r\n        return sorted_input[(sorted_input.shape[0] - 1) // 2]\r\n\r\n    median_tuple = namedtuple(\"median\", [\"values\", \"indices\"])\r\n\r\n    if input.ndim == 0:\r\n        result = median_tuple(input, ivy.array(0))\r\n    else:\r\n        sorted_indices = ivy.argsort(input, axis=dim)\r\n        median_indices = ivy.gather(\r\n            sorted_indices, (sorted_indices.shape[dim] - 1) // 2, axis=dim\r\n        )\r\n        median_values = ivy.take_along_axis(\r\n            input, ivy.expand_dims(median_indices, axis=dim), dim\r\n        ).squeeze(dim)\r\n\r\n        if keepdim:\r\n            median_values = ivy.expand_dims(median_values, axis=dim)\r\n            median_indices = ivy.expand_dims(median_indices, axis=dim)\r\n\r\n        result = median_tuple(median_values, median_indices)\r\n    if out is not None:\r\n        ivy.inplace_update(out[0], result.values)\r\n        ivy.inplace_update(out[1], result.indices)\r\n        return out\r\n    return result\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes({\"2.0.1 and below\": (\"float16\",)}, \"torch\")\r\ndef std(input, dim=None, unbiased=True, keepdim=False, *, out=None):\r\n    return ivy.std(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes(\r\n    {\r\n        \"2.0.1 and below\": (\r\n            \"float16\",\r\n            \"bfloat16\",\r\n        )\r\n    },\r\n    \"torch\",\r\n)\r\ndef prod(input, dim=None, keepdim=False, *, dtype=None):\r\n    if not dtype:\r\n        if \"int\" in input.dtype:\r\n            dtype = ivy.int64\r\n    return ivy.prod(input, axis=dim, dtype=dtype, keepdims=keepdim)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef var(input, dim, unbiased, keepdim=False, *, out=None):\r\n    return ivy.var(input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef min(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        return ivy.min(input, axis=dim, keepdims=keepdim, out=out)\r\n    elif out is not None:\r\n        ivy.min(input, axis=dim, keepdims=keepdim, out=out[0])\r\n        ivy.argmin(input, axis=dim, keepdims=keepdim, out=out[1])\r\n        return out\r\n    else:\r\n        min_tuple = namedtuple(\"min\", [\"values\", \"indices\"])\r\n        return min_tuple(\r\n            ivy.min(input, axis=dim, keepdims=keepdim),\r\n            ivy.argmin(input, axis=dim, keepdims=keepdim),\r\n        )\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef max(input, dim=None, keepdim=False, *, out=None):\r\n    if dim is None:\r\n        return ivy.max(input, axis=dim, keepdims=keepdim, out=out)\r\n    elif out is not None:\r\n        ivy.max(input, axis=dim, keepdims=keepdim, out=out[0])\r\n        ivy.argmax(input, axis=dim, keepdims=keepdim, out=out[1])\r\n        return out\r\n    else:\r\n        max_tuple = namedtuple(\"max\", [\"values\", \"indices\"])\r\n        return max_tuple(\r\n            ivy.max(input, axis=dim, keepdims=keepdim),\r\n            ivy.argmax(input, axis=dim, keepdims=keepdim),\r\n        )\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef moveaxis(input, source, destination):\r\n    return ivy.moveaxis(input, source, destination)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes({\"2.12.0 and below\": (\"bfloat16\",)}, \"tensorflow\")\r\ndef std_mean(input, dim, unbiased, keepdim=False, *, out=None):\r\n    temp_std = ivy.std(\r\n        input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out\r\n    )\r\n    temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n    return temp_std, temp_mean\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef var_mean(input, dim, unbiased, keepdim=False, *, out=None):\r\n    temp_var = ivy.var(\r\n        input, axis=dim, correction=int(unbiased), keepdims=keepdim, out=out\r\n    )\r\n    temp_mean = ivy.mean(input, axis=dim, keepdims=keepdim, out=out)\r\n    return (temp_var, temp_mean)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef aminmax(input, *, dim=None, keepdim=False, out=None):\r\n    minmax_tuple = namedtuple(\"minmax\", [\"min\", \"max\"])\r\n    return minmax_tuple(\r\n        ivy.min(input, axis=dim, keepdims=keepdim, out=out),\r\n        ivy.max(input, axis=dim, keepdims=keepdim, out=out),\r\n    )\r\n\r\n\r\naminmax.unsupported_dtypes = {\r\n    \"torch\": (\"float16\", \"bfloat16\"),\r\n    \"numpy\": (\"float16\", \"bfloat16\"),\r\n    \"jax\": (\"float16\", \"bfloat16\"),\r\n    \"tensorflow\": (\"float16\", \"bfloat16\"),\r\n}\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef quantile(input, q, dim=None, keepdim=False, *, interpolation=\"linear\", out=None):\r\n    return ivy.quantile(\r\n        input, q, axis=dim, keepdims=keepdim, interpolation=interpolation, out=out\r\n    )\r\n\r\n\r\nquantile.unsupported_dtypes = {\r\n    \"torch\": (\"float16\", \"bfloat16\"),\r\n    \"numpy\": (\"float16\", \"bfloat16\"),\r\n    \"jax\": (\"float16\", \"bfloat16\"),\r\n    \"tensorflow\": (\"float16\", \"bfloat16\"),\r\n}\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef count_nonzero(input, dim=None):\r\n    return ivy.count_nonzero(input, axis=dim).astype(ivy.int64)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef logsumexp(input, dim, keepdim=False, *, out=None):\r\n    c = ivy.max(input, axis=dim, keepdims=True)\r\n    if ivy.get_num_dims(c) > 0:\r\n        c = ivy.where(ivy.isinf(c), ivy.zeros_like(c), c)\r\n    elif not ivy.isinf(c):\r\n        c = 0\r\n    exponential = ivy.exp(input - c)\r\n    sum = ivy.sum(exponential, axis=dim, keepdims=keepdim)\r\n    ret = ivy.log(sum)\r\n    if not keepdim:\r\n        c = ivy.squeeze(c, axis=dim)\r\n    ret = ivy.add(ret, c, out=out)\r\n    return ret\r\n\r\n\r\n@to_ivy_arrays_and_back\r\ndef unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None):\r\n    if dim is not None:\r\n        sorted = True\r\n    results = ivy.unique_all(input, by_value=sorted, axis=dim)\r\n\r\n    fields = [\"output\"]\r\n    if return_inverse:\r\n        fields.append(\"inverse_indices\")\r\n    if return_counts:\r\n        fields.append(\"counts\")\r\n\r\n    Results = namedtuple(\"Results\", fields)\r\n\r\n    values = [results.values]\r\n    if return_inverse:\r\n        inverse_indices = results.inverse_indices\r\n\r\n        if dim is None:\r\n            inverse_indices = inverse_indices.reshape(input.shape)\r\n\r\n        values.append(inverse_indices)\r\n    if return_counts:\r\n        values.append(results.counts)\r\n\r\n    return Results(*values)\r\n\r\n\r\n@to_ivy_arrays_and_back\r\n@with_unsupported_dtypes(\r\n    {\"2.0.1 and below\": (\"bfloat16\",)},\r\n    \"torch\",\r\n)\r\ndef norm(input, p=\"fro\", dim=None, keepdim=False, out=None, dtype=None):\r\n    if (\r\n        p == \"fro\" and (dim is None or isinstance(dim, int) or len(dim) <= 2)\r\n    ) or p is None:\r\n        p = 2\r\n    if isinstance(p, str):\r\n        if dim is None:\r\n            dim = tuple(range(input.dim()))\r\n        return ivy.matrix_norm(input, ord=p, axis=dim, keepdims=keepdim, out=out)\r\n    else:\r\n        return ivy.vector_norm(\r\n            input, ord=p, axis=dim, keepdims=keepdim, dtype=dtype, out=out\r\n        )\r\n\r\n\r\n@with_unsupported_dtypes(\r\n    {\r\n        \"2.0.1 and below\": (\r\n            \"float16\",\r\n            \"complex\",\r\n        )\r\n    },\r\n    \"torch\",\r\n)\r\n@to_ivy_arrays_and_back\r\ndef unique_consecutive(input, return_inverse, return_counts, dim):\r\n    output, inverse_indices, counts = ivy.unique_consecutive(input, axis=dim)\r\n    ret = (output,)\r\n    if return_inverse:\r\n        ret += (inverse_indices,)\r\n    if return_counts:\r\n        ret += (counts,)\r\n    return ret\r\n", "path": "ivy/functional/frontends/torch/reduction_ops.py"}]}