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


--- 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/backends/paddle/general.py`
Content:
```
1 """Collection of Paddle general functions, wrapped to fit Ivy syntax and signature."""
2 # global
3 from functools import reduce
4 from numbers import Number
5 from operator import mul
6 from typing import Optional, Union, Sequence, Callable, List, Tuple
7 import paddle
8 import numpy as np
9 
10 # local
11 import ivy
12 from ivy.utils.exceptions import IvyNotImplementedException
13 from ivy.func_wrapper import with_unsupported_device_and_dtypes
14 from . import backend_version
15 import multiprocessing as _multiprocessing
16 from .elementwise import _elementwise_helper
17 
18 
19 @with_unsupported_device_and_dtypes(
20     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
21 )
22 def is_native_array(x, /, *, exclusive=False):
23     if isinstance(x, paddle.Tensor):
24         if exclusive and not x.stop_gradient:
25             return False
26         return True
27     return False
28 
29 
30 @with_unsupported_device_and_dtypes(
31     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
32 )
33 def array_equal(x0: paddle.Tensor, x1: paddle.Tensor, /) -> bool:
34     return bool(ivy.all(ivy.equal(x0, x1)))
35 
36 
37 def container_types():
38     return []
39 
40 
41 def current_backend_str() -> str:
42     return "paddle"
43 
44 
45 @with_unsupported_device_and_dtypes(
46     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
47 )
48 def get_item(x: paddle.Tensor, query: Union[paddle.Tensor, Tuple]) -> paddle.Tensor:
49     # regular queries x[idx_1,idx_2,...,idx_i]
50     if isinstance(query, tuple):
51         if x.dtype in [paddle.int8, paddle.int16, paddle.uint8, paddle.float16]:
52             return x.cast("float32").__getitem__(query).cast(x.dtype)
53         return x.__getitem__(query)
54 
55     if not ivy.is_native_array(query):
56         query = paddle.to_tensor(query, dtype="int64")
57 
58     # masked queries x[bool_1,bool_2,...,bool_i]
59     if query.dtype == paddle.bool:
60         if x.dtype in [
61             paddle.int8,
62             paddle.int16,
63             paddle.uint8,
64             paddle.float16,
65             paddle.complex64,
66             paddle.complex128,
67             paddle.bool,
68         ]:
69             if paddle.is_complex(x):
70                 return paddle.complex(
71                     paddle.masked_select(x.real(), query),
72                     paddle.masked_select(x.imag(), query),
73                 )
74             return paddle.masked_select(x.cast("float32"), query).cast(x.dtype)
75         return paddle.masked_select(x, query)
76 
77     query = query.cast("int64")
78     # array queries idx = Tensor(idx_1,idx_2,...,idx_i), x[idx]
79     if x.dtype in [
80         paddle.int8,
81         paddle.int16,
82         paddle.uint8,
83         paddle.float16,
84         paddle.complex64,
85         paddle.complex128,
86         paddle.bool,
87     ]:
88         if paddle.is_complex(x):
89             return paddle.complex(
90                 x.real().__getitem__(query), x.imag().__getitem__(query)
91             )
92         return x.cast("float32").__getitem__(query).cast(x.dtype)
93     return x.__getitem__(query)
94 
95 
96 @with_unsupported_device_and_dtypes(
97     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
98 )
99 def to_numpy(
100     x: Union[paddle.Tensor, List[paddle.Tensor]], /, *, copy: bool = True
101 ) -> Union[np.ndarray, List[np.ndarray]]:
102     if isinstance(x, (float, int, bool)):
103         return x
104     elif isinstance(x, np.ndarray):
105         if copy:
106             return x.copy()
107         else:
108             return x
109     elif paddle.is_tensor(x):
110         if copy:
111             return np.array(x)
112         else:
113             return np.asarray(x)
114     elif isinstance(x, list):
115         return [ivy.to_numpy(u) for u in x]
116     raise ivy.utils.exceptions.IvyException("Expected a Paddle Tensor.")
117 
118 
119 @with_unsupported_device_and_dtypes(
120     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
121 )
122 def to_scalar(x: paddle.Tensor, /) -> Number:
123     if isinstance(x, (Number, complex)):
124         return x
125     return x.item()
126 
127 
128 @with_unsupported_device_and_dtypes(
129     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
130 )
131 def to_list(x: paddle.Tensor, /) -> list:
132     return x.tolist()
133 
134 
135 @with_unsupported_device_and_dtypes(
136     {
137         "2.4.2 and below": {
138             "cpu": (
139                 "uint16",
140                 "bfloat16",
141                 "int8",
142                 "int16",
143                 "int32",
144                 "int64",
145                 "float16",
146                 "complex64",
147                 "complex128",
148                 "bool",
149             )
150         }
151     },
152     backend_version,
153 )
154 def gather(
155     params: paddle.Tensor,
156     indices: paddle.Tensor,
157     /,
158     *,
159     axis: Optional[int] = -1,
160     batch_dims: Optional[int] = 0,
161     out: Optional[paddle.Tensor] = None,
162 ) -> paddle.Tensor:
163     axis = axis % paddle.Tensor.ndimension(params)
164     batch_dims = batch_dims % paddle.Tensor.ndimension(params)
165     ivy.utils.assertions.check_gather_input_valid(params, indices, axis, batch_dims)
166     if batch_dims == 0:
167         result = paddle.gather(params, paddle.reshape(indices, shape=[-1]), axis=axis)
168     else:
169         params_list = [p for p in params]
170         indices_list = [i for i in indices]
171         for b in range(1, batch_dims):
172             params_list = [p1 for p in params_list for p1 in p]
173             indices_list = [i1 for i in indices_list for i1 in i]
174         result = []
175         for p, i in zip(params_list, indices_list):
176             result.append(
177                 paddle.gather(p, paddle.reshape(i, shape=[-1]), axis=axis - batch_dims)
178             )
179         result = paddle.concat(result, axis=0)
180     new_shape = (
181         params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1 :]
182     )
183     return paddle.reshape(result, shape=new_shape)
184 
185 
186 @with_unsupported_device_and_dtypes(
187     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
188 )
189 def gather_nd(
190     params: paddle.Tensor,
191     indices: paddle.Tensor,
192     /,
193     *,
194     batch_dims: Optional[int] = 0,
195     out: Optional[paddle.Tensor] = None,
196 ) -> paddle.Tensor:
197     raise IvyNotImplementedException()
198 
199 
200 @with_unsupported_device_and_dtypes(
201     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
202 )
203 def get_num_dims(
204     x: paddle.Tensor, /, *, as_array: bool = False
205 ) -> Union[paddle.Tensor, int]:
206     return paddle.to_tensor(x.ndim) if as_array else x.ndim
207 
208 
209 def inplace_arrays_supported():
210     # there are some operations that support inplace updates
211     # but it's not supported in all functions
212     return False
213 
214 
215 @with_unsupported_device_and_dtypes(
216     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
217 )
218 def inplace_decrement(
219     x: Union[ivy.Array, paddle.Tensor],
220     val: Union[ivy.Array, paddle.Tensor],
221 ) -> ivy.Array:
222     (x_native, val_native), _ = ivy.args_to_native(x, val)
223     x_native -= val_native
224     if ivy.is_ivy_array(x):
225         x.data = x_native
226     else:
227         x = ivy.Array(x_native)
228     return x
229 
230 
231 @with_unsupported_device_and_dtypes(
232     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
233 )
234 def inplace_increment(
235     x: Union[ivy.Array, paddle.Tensor],
236     val: Union[ivy.Array, paddle.Tensor],
237 ) -> ivy.Array:
238     (x_native, val_native), _ = ivy.args_to_native(x, val)
239     x_native += val_native
240     if ivy.is_ivy_array(x):
241         x.data = x_native
242     else:
243         x = ivy.Array(x_native)
244     return x
245 
246 
247 @with_unsupported_device_and_dtypes(
248     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
249 )
250 def inplace_update(
251     x: Union[ivy.Array, paddle.Tensor],
252     val: Union[ivy.Array, paddle.Tensor],
253     /,
254     *,
255     ensure_in_backend: bool = False,
256     keep_input_dtype: bool = False,
257 ) -> ivy.Array:
258     if ivy.is_array(x) and ivy.is_array(val):
259         (x_native, val_native), _ = ivy.args_to_native(x, val)
260 
261         if val_native.shape == x_native.shape:
262             if x_native.dtype != val_native.dtype:
263                 x_native = x_native.astype(val_native.dtype)
264             paddle.assign(val_native, x_native)
265         else:
266             x_native = val_native
267         if ivy.is_ivy_array(x):
268             x.data = x_native
269         else:
270             x = ivy.Array(x_native)
271         return x
272     else:
273         return val
274 
275 
276 @with_unsupported_device_and_dtypes(
277     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
278 )
279 def inplace_variables_supported():
280     return False
281 
282 
283 def multiprocessing(context=None):
284     return (
285         _multiprocessing if context is None else _multiprocessing.get_context(context)
286     )
287 
288 
289 @with_unsupported_device_and_dtypes(
290     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
291 )
292 def scatter_flat(
293     indices: paddle.Tensor,
294     updates: paddle.Tensor,
295     /,
296     *,
297     size: Optional[int] = None,
298     reduction: str = "sum",
299     out: Optional[paddle.Tensor] = None,
300 ):
301     raise IvyNotImplementedException()
302 
303 
304 @with_unsupported_device_and_dtypes(
305     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
306 )
307 def scatter_nd(
308     indices: paddle.Tensor,
309     updates: paddle.Tensor,
310     /,
311     shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,
312     *,
313     reduction: str = "sum",
314     out: Optional[paddle.Tensor] = None,
315 ) -> paddle.Tensor:
316     raise IvyNotImplementedException()
317 
318 
319 @with_unsupported_device_and_dtypes(
320     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
321 )
322 def shape(
323     x: paddle.Tensor, /, *, as_array: bool = False
324 ) -> Union[ivy.Shape, ivy.Array]:
325     if as_array:
326         return ivy.array(x.shape, dtype=ivy.default_int_dtype())
327     else:
328         return ivy.Shape(x.shape)
329 
330 
331 @with_unsupported_device_and_dtypes(
332     {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
333 )
334 def vmap(
335     func: Callable,
336     in_axes: Union[int, Sequence[int], Sequence[None]] = 0,
337     out_axes: Optional[int] = 0,
338 ) -> Callable:
339     raise IvyNotImplementedException()
340 
341 
342 def isin(
343     elements: paddle.Tensor,
344     test_elements: paddle.Tensor,
345     /,
346     *,
347     assume_unique: Optional[bool] = False,
348     invert: Optional[bool] = False,
349 ) -> paddle.Tensor:
350     raise IvyNotImplementedException()
351
```
--- 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/backends/paddle/general.py b/ivy/functional/backends/paddle/general.py
--- a/ivy/functional/backends/paddle/general.py
+++ b/ivy/functional/backends/paddle/general.py
@@ -133,23 +133,7 @@
 
 
 @with_unsupported_device_and_dtypes(
-    {
-        "2.4.2 and below": {
-            "cpu": (
-                "uint16",
-                "bfloat16",
-                "int8",
-                "int16",
-                "int32",
-                "int64",
-                "float16",
-                "complex64",
-                "complex128",
-                "bool",
-            )
-        }
-    },
-    backend_version,
+    {"2.4.2 and below": {"cpu": ("uint16", "bfloat16")}}, backend_version
 )
 def gather(
     params: paddle.Tensor,
@@ -160,27 +144,50 @@
     batch_dims: Optional[int] = 0,
     out: Optional[paddle.Tensor] = None,
 ) -> paddle.Tensor:
-    axis = axis % paddle.Tensor.ndimension(params)
-    batch_dims = batch_dims % paddle.Tensor.ndimension(params)
+    
+
+    def _gather(params1):
+        with ivy.ArrayMode(False):
+            if batch_dims == 0:
+                result = paddle.gather(params1, ivy.reshape(indices, shape=[-1]), axis=axis)
+            #inputs are unstacked batch_dims times because paddle.gather does not support batch_dims
+            else:
+                params1_list = ivy.unstack(params1, axis=0)
+                indices_list = ivy.unstack(indices, axis=0)
+                for b in range(1, batch_dims):
+                    params1_list = [p2 for p1 in params1_list for p2 in ivy.unstack(p1, axis=0)]
+                    indices_list = [i2 for i1 in indices_list for i2 in ivy.unstack(i1, axis=0)]
+                result = []
+                for p, i in zip(params1_list, indices_list):
+                    result.append(
+                        paddle.gather(p, ivy.reshape(i, shape=[-1]), axis=axis - batch_dims)
+                    )
+                result = ivy.concat(result, axis=0)
+            new_shape = (
+                params1.shape[:axis] + indices.shape[batch_dims:] + params1.shape[axis + 1 :]
+            )
+            return ivy.reshape(result, shape=new_shape)
+        
+    
+    axis = axis % params.ndim
+    batch_dims = batch_dims % params.ndim
     ivy.utils.assertions.check_gather_input_valid(params, indices, axis, batch_dims)
-    if batch_dims == 0:
-        result = paddle.gather(params, paddle.reshape(indices, shape=[-1]), axis=axis)
-    else:
-        params_list = [p for p in params]
-        indices_list = [i for i in indices]
-        for b in range(1, batch_dims):
-            params_list = [p1 for p in params_list for p1 in p]
-            indices_list = [i1 for i in indices_list for i1 in i]
-        result = []
-        for p, i in zip(params_list, indices_list):
-            result.append(
-                paddle.gather(p, paddle.reshape(i, shape=[-1]), axis=axis - batch_dims)
+    if params.dtype in [
+        paddle.int8,
+        paddle.int16,
+        paddle.float16,
+        paddle.complex64,
+        paddle.complex128,
+        paddle.bool,
+    ]:
+        if paddle.is_complex(params):
+            return paddle.complex(
+                _gather(params.real()),
+                _gather(params.imag())
             )
-        result = paddle.concat(result, axis=0)
-    new_shape = (
-        params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1 :]
-    )
-    return paddle.reshape(result, shape=new_shape)
+        return _gather(params.cast("float32")).cast(params.dtype)
+    return _gather(params)
+    
 
 
 @with_unsupported_device_and_dtypes(

{"golden_diff": "diff --git a/ivy/functional/backends/paddle/general.py b/ivy/functional/backends/paddle/general.py\n--- a/ivy/functional/backends/paddle/general.py\n+++ b/ivy/functional/backends/paddle/general.py\n@@ -133,23 +133,7 @@\n \n \n @with_unsupported_device_and_dtypes(\n-    {\n-        \"2.4.2 and below\": {\n-            \"cpu\": (\n-                \"uint16\",\n-                \"bfloat16\",\n-                \"int8\",\n-                \"int16\",\n-                \"int32\",\n-                \"int64\",\n-                \"float16\",\n-                \"complex64\",\n-                \"complex128\",\n-                \"bool\",\n-            )\n-        }\n-    },\n-    backend_version,\n+    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n )\n def gather(\n     params: paddle.Tensor,\n@@ -160,27 +144,50 @@\n     batch_dims: Optional[int] = 0,\n     out: Optional[paddle.Tensor] = None,\n ) -> paddle.Tensor:\n-    axis = axis % paddle.Tensor.ndimension(params)\n-    batch_dims = batch_dims % paddle.Tensor.ndimension(params)\n+    \n+\n+    def _gather(params1):\n+        with ivy.ArrayMode(False):\n+            if batch_dims == 0:\n+                result = paddle.gather(params1, ivy.reshape(indices, shape=[-1]), axis=axis)\n+            #inputs are unstacked batch_dims times because paddle.gather does not support batch_dims\n+            else:\n+                params1_list = ivy.unstack(params1, axis=0)\n+                indices_list = ivy.unstack(indices, axis=0)\n+                for b in range(1, batch_dims):\n+                    params1_list = [p2 for p1 in params1_list for p2 in ivy.unstack(p1, axis=0)]\n+                    indices_list = [i2 for i1 in indices_list for i2 in ivy.unstack(i1, axis=0)]\n+                result = []\n+                for p, i in zip(params1_list, indices_list):\n+                    result.append(\n+                        paddle.gather(p, ivy.reshape(i, shape=[-1]), axis=axis - batch_dims)\n+                    )\n+                result = ivy.concat(result, axis=0)\n+            new_shape = (\n+                params1.shape[:axis] + indices.shape[batch_dims:] + params1.shape[axis + 1 :]\n+            )\n+            return ivy.reshape(result, shape=new_shape)\n+        \n+    \n+    axis = axis % params.ndim\n+    batch_dims = batch_dims % params.ndim\n     ivy.utils.assertions.check_gather_input_valid(params, indices, axis, batch_dims)\n-    if batch_dims == 0:\n-        result = paddle.gather(params, paddle.reshape(indices, shape=[-1]), axis=axis)\n-    else:\n-        params_list = [p for p in params]\n-        indices_list = [i for i in indices]\n-        for b in range(1, batch_dims):\n-            params_list = [p1 for p in params_list for p1 in p]\n-            indices_list = [i1 for i in indices_list for i1 in i]\n-        result = []\n-        for p, i in zip(params_list, indices_list):\n-            result.append(\n-                paddle.gather(p, paddle.reshape(i, shape=[-1]), axis=axis - batch_dims)\n+    if params.dtype in [\n+        paddle.int8,\n+        paddle.int16,\n+        paddle.float16,\n+        paddle.complex64,\n+        paddle.complex128,\n+        paddle.bool,\n+    ]:\n+        if paddle.is_complex(params):\n+            return paddle.complex(\n+                _gather(params.real()),\n+                _gather(params.imag())\n             )\n-        result = paddle.concat(result, axis=0)\n-    new_shape = (\n-        params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1 :]\n-    )\n-    return paddle.reshape(result, shape=new_shape)\n+        return _gather(params.cast(\"float32\")).cast(params.dtype)\n+    return _gather(params)\n+    \n \n \n @with_unsupported_device_and_dtypes(\n", "issue": "gather\n\n", "before_files": [{"content": "\"\"\"Collection of Paddle general functions, wrapped to fit Ivy syntax and signature.\"\"\"\n# global\nfrom functools import reduce\nfrom numbers import Number\nfrom operator import mul\nfrom typing import Optional, Union, Sequence, Callable, List, Tuple\nimport paddle\nimport numpy as np\n\n# local\nimport ivy\nfrom ivy.utils.exceptions import IvyNotImplementedException\nfrom ivy.func_wrapper import with_unsupported_device_and_dtypes\nfrom . import backend_version\nimport multiprocessing as _multiprocessing\nfrom .elementwise import _elementwise_helper\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef is_native_array(x, /, *, exclusive=False):\n    if isinstance(x, paddle.Tensor):\n        if exclusive and not x.stop_gradient:\n            return False\n        return True\n    return False\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef array_equal(x0: paddle.Tensor, x1: paddle.Tensor, /) -> bool:\n    return bool(ivy.all(ivy.equal(x0, x1)))\n\n\ndef container_types():\n    return []\n\n\ndef current_backend_str() -> str:\n    return \"paddle\"\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef get_item(x: paddle.Tensor, query: Union[paddle.Tensor, Tuple]) -> paddle.Tensor:\n    # regular queries x[idx_1,idx_2,...,idx_i]\n    if isinstance(query, tuple):\n        if x.dtype in [paddle.int8, paddle.int16, paddle.uint8, paddle.float16]:\n            return x.cast(\"float32\").__getitem__(query).cast(x.dtype)\n        return x.__getitem__(query)\n\n    if not ivy.is_native_array(query):\n        query = paddle.to_tensor(query, dtype=\"int64\")\n\n    # masked queries x[bool_1,bool_2,...,bool_i]\n    if query.dtype == paddle.bool:\n        if x.dtype in [\n            paddle.int8,\n            paddle.int16,\n            paddle.uint8,\n            paddle.float16,\n            paddle.complex64,\n            paddle.complex128,\n            paddle.bool,\n        ]:\n            if paddle.is_complex(x):\n                return paddle.complex(\n                    paddle.masked_select(x.real(), query),\n                    paddle.masked_select(x.imag(), query),\n                )\n            return paddle.masked_select(x.cast(\"float32\"), query).cast(x.dtype)\n        return paddle.masked_select(x, query)\n\n    query = query.cast(\"int64\")\n    # array queries idx = Tensor(idx_1,idx_2,...,idx_i), x[idx]\n    if x.dtype in [\n        paddle.int8,\n        paddle.int16,\n        paddle.uint8,\n        paddle.float16,\n        paddle.complex64,\n        paddle.complex128,\n        paddle.bool,\n    ]:\n        if paddle.is_complex(x):\n            return paddle.complex(\n                x.real().__getitem__(query), x.imag().__getitem__(query)\n            )\n        return x.cast(\"float32\").__getitem__(query).cast(x.dtype)\n    return x.__getitem__(query)\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_numpy(\n    x: Union[paddle.Tensor, List[paddle.Tensor]], /, *, copy: bool = True\n) -> Union[np.ndarray, List[np.ndarray]]:\n    if isinstance(x, (float, int, bool)):\n        return x\n    elif isinstance(x, np.ndarray):\n        if copy:\n            return x.copy()\n        else:\n            return x\n    elif paddle.is_tensor(x):\n        if copy:\n            return np.array(x)\n        else:\n            return np.asarray(x)\n    elif isinstance(x, list):\n        return [ivy.to_numpy(u) for u in x]\n    raise ivy.utils.exceptions.IvyException(\"Expected a Paddle Tensor.\")\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_scalar(x: paddle.Tensor, /) -> Number:\n    if isinstance(x, (Number, complex)):\n        return x\n    return x.item()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_list(x: paddle.Tensor, /) -> list:\n    return x.tolist()\n\n\n@with_unsupported_device_and_dtypes(\n    {\n        \"2.4.2 and below\": {\n            \"cpu\": (\n                \"uint16\",\n                \"bfloat16\",\n                \"int8\",\n                \"int16\",\n                \"int32\",\n                \"int64\",\n                \"float16\",\n                \"complex64\",\n                \"complex128\",\n                \"bool\",\n            )\n        }\n    },\n    backend_version,\n)\ndef gather(\n    params: paddle.Tensor,\n    indices: paddle.Tensor,\n    /,\n    *,\n    axis: Optional[int] = -1,\n    batch_dims: Optional[int] = 0,\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    axis = axis % paddle.Tensor.ndimension(params)\n    batch_dims = batch_dims % paddle.Tensor.ndimension(params)\n    ivy.utils.assertions.check_gather_input_valid(params, indices, axis, batch_dims)\n    if batch_dims == 0:\n        result = paddle.gather(params, paddle.reshape(indices, shape=[-1]), axis=axis)\n    else:\n        params_list = [p for p in params]\n        indices_list = [i for i in indices]\n        for b in range(1, batch_dims):\n            params_list = [p1 for p in params_list for p1 in p]\n            indices_list = [i1 for i in indices_list for i1 in i]\n        result = []\n        for p, i in zip(params_list, indices_list):\n            result.append(\n                paddle.gather(p, paddle.reshape(i, shape=[-1]), axis=axis - batch_dims)\n            )\n        result = paddle.concat(result, axis=0)\n    new_shape = (\n        params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1 :]\n    )\n    return paddle.reshape(result, shape=new_shape)\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef gather_nd(\n    params: paddle.Tensor,\n    indices: paddle.Tensor,\n    /,\n    *,\n    batch_dims: Optional[int] = 0,\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef get_num_dims(\n    x: paddle.Tensor, /, *, as_array: bool = False\n) -> Union[paddle.Tensor, int]:\n    return paddle.to_tensor(x.ndim) if as_array else x.ndim\n\n\ndef inplace_arrays_supported():\n    # there are some operations that support inplace updates\n    # but it's not supported in all functions\n    return False\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_decrement(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n) -> ivy.Array:\n    (x_native, val_native), _ = ivy.args_to_native(x, val)\n    x_native -= val_native\n    if ivy.is_ivy_array(x):\n        x.data = x_native\n    else:\n        x = ivy.Array(x_native)\n    return x\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_increment(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n) -> ivy.Array:\n    (x_native, val_native), _ = ivy.args_to_native(x, val)\n    x_native += val_native\n    if ivy.is_ivy_array(x):\n        x.data = x_native\n    else:\n        x = ivy.Array(x_native)\n    return x\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_update(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n    /,\n    *,\n    ensure_in_backend: bool = False,\n    keep_input_dtype: bool = False,\n) -> ivy.Array:\n    if ivy.is_array(x) and ivy.is_array(val):\n        (x_native, val_native), _ = ivy.args_to_native(x, val)\n\n        if val_native.shape == x_native.shape:\n            if x_native.dtype != val_native.dtype:\n                x_native = x_native.astype(val_native.dtype)\n            paddle.assign(val_native, x_native)\n        else:\n            x_native = val_native\n        if ivy.is_ivy_array(x):\n            x.data = x_native\n        else:\n            x = ivy.Array(x_native)\n        return x\n    else:\n        return val\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_variables_supported():\n    return False\n\n\ndef multiprocessing(context=None):\n    return (\n        _multiprocessing if context is None else _multiprocessing.get_context(context)\n    )\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef scatter_flat(\n    indices: paddle.Tensor,\n    updates: paddle.Tensor,\n    /,\n    *,\n    size: Optional[int] = None,\n    reduction: str = \"sum\",\n    out: Optional[paddle.Tensor] = None,\n):\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef scatter_nd(\n    indices: paddle.Tensor,\n    updates: paddle.Tensor,\n    /,\n    shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,\n    *,\n    reduction: str = \"sum\",\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef shape(\n    x: paddle.Tensor, /, *, as_array: bool = False\n) -> Union[ivy.Shape, ivy.Array]:\n    if as_array:\n        return ivy.array(x.shape, dtype=ivy.default_int_dtype())\n    else:\n        return ivy.Shape(x.shape)\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef vmap(\n    func: Callable,\n    in_axes: Union[int, Sequence[int], Sequence[None]] = 0,\n    out_axes: Optional[int] = 0,\n) -> Callable:\n    raise IvyNotImplementedException()\n\n\ndef isin(\n    elements: paddle.Tensor,\n    test_elements: paddle.Tensor,\n    /,\n    *,\n    assume_unique: Optional[bool] = False,\n    invert: Optional[bool] = False,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n", "path": "ivy/functional/backends/paddle/general.py"}], "after_files": [{"content": "\"\"\"Collection of Paddle general functions, wrapped to fit Ivy syntax and signature.\"\"\"\n# global\nfrom functools import reduce\nfrom numbers import Number\nfrom operator import mul\nfrom typing import Optional, Union, Sequence, Callable, List, Tuple\nimport paddle\nimport numpy as np\n\n# local\nimport ivy\nfrom ivy.utils.exceptions import IvyNotImplementedException\nfrom ivy.func_wrapper import with_unsupported_device_and_dtypes\nfrom . import backend_version\nimport multiprocessing as _multiprocessing\nfrom .elementwise import _elementwise_helper\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef is_native_array(x, /, *, exclusive=False):\n    if isinstance(x, paddle.Tensor):\n        if exclusive and not x.stop_gradient:\n            return False\n        return True\n    return False\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef array_equal(x0: paddle.Tensor, x1: paddle.Tensor, /) -> bool:\n    return bool(ivy.all(ivy.equal(x0, x1)))\n\n\ndef container_types():\n    return []\n\n\ndef current_backend_str() -> str:\n    return \"paddle\"\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef get_item(x: paddle.Tensor, query: Union[paddle.Tensor, Tuple]) -> paddle.Tensor:\n    # regular queries x[idx_1,idx_2,...,idx_i]\n    if isinstance(query, tuple):\n        if x.dtype in [paddle.int8, paddle.int16, paddle.uint8, paddle.float16]:\n            return x.cast(\"float32\").__getitem__(query).cast(x.dtype)\n        return x.__getitem__(query)\n\n    if not ivy.is_native_array(query):\n        query = paddle.to_tensor(query, dtype=\"int64\")\n\n    # masked queries x[bool_1,bool_2,...,bool_i]\n    if query.dtype == paddle.bool:\n        if x.dtype in [\n            paddle.int8,\n            paddle.int16,\n            paddle.uint8,\n            paddle.float16,\n            paddle.complex64,\n            paddle.complex128,\n            paddle.bool,\n        ]:\n            if paddle.is_complex(x):\n                return paddle.complex(\n                    paddle.masked_select(x.real(), query),\n                    paddle.masked_select(x.imag(), query),\n                )\n            return paddle.masked_select(x.cast(\"float32\"), query).cast(x.dtype)\n        return paddle.masked_select(x, query)\n\n    query = query.cast(\"int64\")\n    # array queries idx = Tensor(idx_1,idx_2,...,idx_i), x[idx]\n    if x.dtype in [\n        paddle.int8,\n        paddle.int16,\n        paddle.uint8,\n        paddle.float16,\n        paddle.complex64,\n        paddle.complex128,\n        paddle.bool,\n    ]:\n        if paddle.is_complex(x):\n            return paddle.complex(\n                x.real().__getitem__(query), x.imag().__getitem__(query)\n            )\n        return x.cast(\"float32\").__getitem__(query).cast(x.dtype)\n    return x.__getitem__(query)\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_numpy(\n    x: Union[paddle.Tensor, List[paddle.Tensor]], /, *, copy: bool = True\n) -> Union[np.ndarray, List[np.ndarray]]:\n    if isinstance(x, (float, int, bool)):\n        return x\n    elif isinstance(x, np.ndarray):\n        if copy:\n            return x.copy()\n        else:\n            return x\n    elif paddle.is_tensor(x):\n        if copy:\n            return np.array(x)\n        else:\n            return np.asarray(x)\n    elif isinstance(x, list):\n        return [ivy.to_numpy(u) for u in x]\n    raise ivy.utils.exceptions.IvyException(\"Expected a Paddle Tensor.\")\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_scalar(x: paddle.Tensor, /) -> Number:\n    if isinstance(x, (Number, complex)):\n        return x\n    return x.item()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef to_list(x: paddle.Tensor, /) -> list:\n    return x.tolist()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef gather(\n    params: paddle.Tensor,\n    indices: paddle.Tensor,\n    /,\n    *,\n    axis: Optional[int] = -1,\n    batch_dims: Optional[int] = 0,\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    \n\n    def _gather(params1):\n        with ivy.ArrayMode(False):\n            if batch_dims == 0:\n                result = paddle.gather(params1, ivy.reshape(indices, shape=[-1]), axis=axis)\n            #inputs are unstacked batch_dims times because paddle.gather does not support batch_dims\n            else:\n                params1_list = ivy.unstack(params1, axis=0)\n                indices_list = ivy.unstack(indices, axis=0)\n                for b in range(1, batch_dims):\n                    params1_list = [p2 for p1 in params1_list for p2 in ivy.unstack(p1, axis=0)]\n                    indices_list = [i2 for i1 in indices_list for i2 in ivy.unstack(i1, axis=0)]\n                result = []\n                for p, i in zip(params1_list, indices_list):\n                    result.append(\n                        paddle.gather(p, ivy.reshape(i, shape=[-1]), axis=axis - batch_dims)\n                    )\n                result = ivy.concat(result, axis=0)\n            new_shape = (\n                params1.shape[:axis] + indices.shape[batch_dims:] + params1.shape[axis + 1 :]\n            )\n            return ivy.reshape(result, shape=new_shape)\n        \n    \n    axis = axis % params.ndim\n    batch_dims = batch_dims % params.ndim\n    ivy.utils.assertions.check_gather_input_valid(params, indices, axis, batch_dims)\n    if params.dtype in [\n        paddle.int8,\n        paddle.int16,\n        paddle.float16,\n        paddle.complex64,\n        paddle.complex128,\n        paddle.bool,\n    ]:\n        if paddle.is_complex(params):\n            return paddle.complex(\n                _gather(params.real()),\n                _gather(params.imag())\n            )\n        return _gather(params.cast(\"float32\")).cast(params.dtype)\n    return _gather(params)\n    \n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef gather_nd(\n    params: paddle.Tensor,\n    indices: paddle.Tensor,\n    /,\n    *,\n    batch_dims: Optional[int] = 0,\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef get_num_dims(\n    x: paddle.Tensor, /, *, as_array: bool = False\n) -> Union[paddle.Tensor, int]:\n    return paddle.to_tensor(x.ndim) if as_array else x.ndim\n\n\ndef inplace_arrays_supported():\n    # there are some operations that support inplace updates\n    # but it's not supported in all functions\n    return False\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_decrement(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n) -> ivy.Array:\n    (x_native, val_native), _ = ivy.args_to_native(x, val)\n    x_native -= val_native\n    if ivy.is_ivy_array(x):\n        x.data = x_native\n    else:\n        x = ivy.Array(x_native)\n    return x\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_increment(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n) -> ivy.Array:\n    (x_native, val_native), _ = ivy.args_to_native(x, val)\n    x_native += val_native\n    if ivy.is_ivy_array(x):\n        x.data = x_native\n    else:\n        x = ivy.Array(x_native)\n    return x\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_update(\n    x: Union[ivy.Array, paddle.Tensor],\n    val: Union[ivy.Array, paddle.Tensor],\n    /,\n    *,\n    ensure_in_backend: bool = False,\n    keep_input_dtype: bool = False,\n) -> ivy.Array:\n    if ivy.is_array(x) and ivy.is_array(val):\n        (x_native, val_native), _ = ivy.args_to_native(x, val)\n\n        if val_native.shape == x_native.shape:\n            if x_native.dtype != val_native.dtype:\n                x_native = x_native.astype(val_native.dtype)\n            paddle.assign(val_native, x_native)\n        else:\n            x_native = val_native\n        if ivy.is_ivy_array(x):\n            x.data = x_native\n        else:\n            x = ivy.Array(x_native)\n        return x\n    else:\n        return val\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef inplace_variables_supported():\n    return False\n\n\ndef multiprocessing(context=None):\n    return (\n        _multiprocessing if context is None else _multiprocessing.get_context(context)\n    )\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef scatter_flat(\n    indices: paddle.Tensor,\n    updates: paddle.Tensor,\n    /,\n    *,\n    size: Optional[int] = None,\n    reduction: str = \"sum\",\n    out: Optional[paddle.Tensor] = None,\n):\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef scatter_nd(\n    indices: paddle.Tensor,\n    updates: paddle.Tensor,\n    /,\n    shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,\n    *,\n    reduction: str = \"sum\",\n    out: Optional[paddle.Tensor] = None,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef shape(\n    x: paddle.Tensor, /, *, as_array: bool = False\n) -> Union[ivy.Shape, ivy.Array]:\n    if as_array:\n        return ivy.array(x.shape, dtype=ivy.default_int_dtype())\n    else:\n        return ivy.Shape(x.shape)\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.4.2 and below\": {\"cpu\": (\"uint16\", \"bfloat16\")}}, backend_version\n)\ndef vmap(\n    func: Callable,\n    in_axes: Union[int, Sequence[int], Sequence[None]] = 0,\n    out_axes: Optional[int] = 0,\n) -> Callable:\n    raise IvyNotImplementedException()\n\n\ndef isin(\n    elements: paddle.Tensor,\n    test_elements: paddle.Tensor,\n    /,\n    *,\n    assume_unique: Optional[bool] = False,\n    invert: Optional[bool] = False,\n) -> paddle.Tensor:\n    raise IvyNotImplementedException()\n", "path": "ivy/functional/backends/paddle/general.py"}]}