internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ivy-llc/ivy

Issue:
prod



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/ndarray/ndarray.py b/ivy/functional/frontends/numpy/ndarray/ndarray.py
--- a/ivy/functional/frontends/numpy/ndarray/ndarray.py
+++ b/ivy/functional/frontends/numpy/ndarray/ndarray.py
@@ -229,7 +229,6 @@ def diagonal(self, *, offset=0, axis1=0, axis2=1):
             axis1=axis1,
             axis2=axis2,
         )
-
     def sort(self, *, axis=-1, kind=None, order=None):
         return np_frontend.sort(self._ivy_array, axis=axis, kind=kind, order=order)
 
@@ -291,6 +290,17 @@ def std(
     def tobytes(self, order="C") -> bytes:
         return np_frontend.tobytes(self.data, order=order)
 
+    def prod(self, *, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True):
+        return np_frontend.prod(
+            self._ivy_array,
+            axis=axis,
+            dtype=dtype,
+            keepdims=keepdims,
+            initial=initial,
+            where=where,
+            out=out,
+        )
+
     def view(self):
         return np_frontend.reshape(self._ivy_array, tuple(self.shape))
 


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py
@@ -571,6 +571,55 @@ def test_numpy_instance_min(
         on_device=on_device,
     )
 
+#prod
+@handle_frontend_method(
+    class_tree=CLASS_TREE,
+    init_tree="numpy.array",
+    method_name="prod",
+    dtype_x_axis_dtype=_get_castable_dtypes_values(use_where=True),
+    keep_dims=st.booleans(),
+    initial=st.one_of(st.floats(min_value=-100, max_value=100)),
+)
+def test_numpy_ndarray_prod(
+    dtype_x_axis_dtype,
+    keep_dims,
+    initial,
+    frontend_method_data,
+    init_flags,
+    method_flags,
+    frontend,
+    on_device,
+):
+    input_dtypes, x, axis, dtype, where = dtype_x_axis_dtype
+    if ivy.current_backend_str() == "torch":
+        assume(not method_flags.as_variable[0])
+
+    where, input_dtypes, method_flags = np_frontend_helpers.handle_where_and_array_bools(
+        where=where,
+        input_dtype=input_dtypes,
+        test_flags=method_flags,
+    )
+    where = ivy.array(where, dtype='bool')
+    helpers.test_frontend_method(
+        init_input_dtypes=input_dtypes,
+        init_all_as_kwargs_np={
+            "object": x[0],
+        },
+        method_input_dtypes=input_dtypes,
+        method_all_as_kwargs_np={
+            "axis": axis,
+            "dtype":dtype,
+            "keepdims": keep_dims,
+            "initial": initial,
+            "where": where,
+        },
+        frontend=frontend,
+        frontend_method_data=frontend_method_data,
+        init_flags=init_flags,
+        method_flags=method_flags,
+        on_device=on_device,
+    )
+
 
 @handle_frontend_method(
     class_tree=CLASS_TREE,
Repository: ivy-llc/ivy

Issue:
indices



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/indexing_routines/indexing_like_operations.py b/ivy/functional/frontends/numpy/indexing_routines/indexing_like_operations.py
--- a/ivy/functional/frontends/numpy/indexing_routines/indexing_like_operations.py
+++ b/ivy/functional/frontends/numpy/indexing_routines/indexing_like_operations.py
@@ -29,3 +29,23 @@ def take_along_axis(arr, indices, axis):
 @to_ivy_arrays_and_back
 def tril_indices(n, k=0, m=None):
     return ivy.tril_indices(n, m, k)
+
+
+@to_ivy_arrays_and_back
+def indices(dimensions, dtype=int, sparse=False):
+    dimensions = tuple(dimensions)
+    N = len(dimensions)
+    shape = (1,) * N
+    if sparse:
+        res = tuple()
+    else:
+        res = ivy.empty((N,) + dimensions, dtype=dtype)
+    for i, dim in enumerate(dimensions):
+        idx = ivy.arange(dim, dtype=dtype).reshape(
+            shape[:i] + (dim,) + shape[i + 1:]
+        )
+        if sparse:
+            res = res + (idx,)
+        else:
+            res[i] = idx
+    return res


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_indexing_routines/test_indexing_like_operations.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_indexing_routines/test_indexing_like_operations.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_indexing_routines/test_indexing_like_operations.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_indexing_routines/test_indexing_like_operations.py
@@ -161,3 +161,32 @@ def test_tril_indices(
         k=k,
         m=m,
     )
+
+
+@handle_frontend_test(
+    fn_tree="numpy.indices",
+    dimensions=helpers.get_shape(),
+    dtype=helpers.get_dtypes(kind="float", full=False),
+    sparse=helpers.get_dtypes(kind="bool"),
+    test_with_out=st.just(False),
+)
+def test_indices(
+    *,
+    dimensions,
+    dtype,
+    sparse,
+    test_flags,
+    frontend,
+    fn_tree,
+    on_device,
+):
+    helpers.test_frontend_function(
+        input_dtypes=dtype,
+        test_flags=test_flags,
+        frontend=frontend,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        dimensions=dimensions,
+        dtype=dtype[0],
+        sparse=sparse,
+    )
Repository: ivy-llc/ivy

Issue:
einops_repeat



Discussion:

Resolving patch:
diff --git a/ivy/data_classes/array/general.py b/ivy/data_classes/array/general.py
--- a/ivy/data_classes/array/general.py
+++ b/ivy/data_classes/array/general.py
@@ -509,16 +509,23 @@ def einops_repeat(
 
         Examples
         --------
+        With :class:`ivy.Array` inputs:
+
         >>> x = ivy.array([5,4])
         >>> y = x.einops_repeat('a -> a c', c=3)
         >>> print(y)
-        ivy.array([[5,5,5],[4,4,4]])
+        ivy.array([[5, 5, 5],
+                   [4, 4, 4]])
+
+        With :class:`ivy.Array` inputs:
 
         >>> x = ivy.array([[5,4],
         ...                [2, 3]])
         >>> y = x.einops_repeat('a b ->  a b c', c=3)
         >>> print(y)
-        ivy.array([[5,5,5],[4,4,4]])
+        ivy.array([[[5, 5, 5], [4, 4, 4]], [[2, 2, 2], [3, 3, 3]]])
+        >>> print(y.shape)
+        (2, 2, 3)
 
         """
         return ivy.einops_repeat(self._data, pattern, out=out, **axes_lengths)
diff --git a/ivy/functional/ivy/general.py b/ivy/functional/ivy/general.py
--- a/ivy/functional/ivy/general.py
+++ b/ivy/functional/ivy/general.py
@@ -1972,8 +1972,7 @@ def einops_repeat(
     out: Optional[ivy.Array] = None,
     **axes_lengths: Dict[str, int],
 ) -> ivy.Array:
-    """
-    Perform einops repeat operation on input array x.
+    """Perform einops repeat operation on input array x.
 
     Parameters
     ----------
@@ -1992,6 +1991,9 @@ def einops_repeat(
     ret
         New array with einops.repeat having been applied.
 
+    This function is *nestable*, and therefore also accepts :code:'ivy.Container'
+    instance in place of the argument.
+
     Examples
     --------
     With :class:`ivy.Array` input:


Test patch:
Repository: ivy-llc/ivy

Issue:
adjoint



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/linalg.py b/ivy/functional/frontends/tensorflow/linalg.py
--- a/ivy/functional/frontends/tensorflow/linalg.py
+++ b/ivy/functional/frontends/tensorflow/linalg.py
@@ -243,3 +243,8 @@ def lu_matrix_inverse(lower_upper, perm, validate_args=False, name=None):
 @to_ivy_arrays_and_back
 def einsum(equation, *inputs, **kwargs):
     return tf_frontend.einsum(equation, *inputs, **kwargs)
+
+
+@to_ivy_arrays_and_back
+def adjoint(matrix, name=None):
+    return ivy.adjoint(matrix)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_linalg.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_linalg.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_linalg.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_linalg.py
@@ -809,3 +809,28 @@ def test_tensorflow_linalg_einsum(
         equation=eq,
         **kw,
     )
+
+
+# adjoint
+@handle_frontend_test(
+    fn_tree="tensorflow.linalg.adjoint",
+    dtype_and_x=_get_dtype_and_matrix(),
+    test_with_out=st.just(False),
+)
+def test_tensorflow_adjoint(
+    *,
+    dtype_and_x,
+    frontend,
+    test_flags,
+    fn_tree,
+    on_device,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        matrix=x[0],
+    )
Repository: ivy-llc/ivy

Issue:
asarray



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/torch/creation_ops.py b/ivy/functional/frontends/torch/creation_ops.py
--- a/ivy/functional/frontends/torch/creation_ops.py
+++ b/ivy/functional/frontends/torch/creation_ops.py
@@ -272,3 +272,14 @@ def tensor(
     pin_memory=False,
 ):
     return ivy.array(data, dtype=dtype, device=device)
+
+
+@to_ivy_arrays_and_back
+def asarray(
+    obj, 
+    *,
+    dtype=None,
+    device=None,
+    copy=None, 
+):
+    return ivy.asarray(obj, copy=copy, dtype=dtype, device=device)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py
--- a/ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py
+++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py
@@ -602,3 +602,33 @@ def test_torch_heaviside(
         values=values[0],
         on_device=on_device,
     )
+
+
+# asarray
+@handle_frontend_test(
+    fn_tree="torch.asarray",
+    dtype_and_x=helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("numeric")
+    ),
+    dtype=helpers.get_dtypes("numeric", full=False),
+)
+def test_torch_asarray(
+    *,
+    dtype_and_x,
+    dtype,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        obj=x[0],
+        dtype=dtype[0],
+        device=on_device,
+    )
Repository: ivy-llc/ivy

Issue:
real



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/torch/pointwise_ops.py b/ivy/functional/frontends/torch/pointwise_ops.py
--- a/ivy/functional/frontends/torch/pointwise_ops.py
+++ b/ivy/functional/frontends/torch/pointwise_ops.py
@@ -206,6 +206,11 @@ def sqrt(input, *, out=None):
     return ivy.sqrt(input, out=out)
 
 
+@to_ivy_arrays_and_back
+def real(input):
+    return ivy.real(input)
+
+
 @to_ivy_arrays_and_back
 def sign(input, *, out=None):
     return ivy.sign(input, out=out)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py
--- a/ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py
+++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py
@@ -937,6 +937,32 @@ def test_torch_sqrt(
     )
 
 
+# real
+@handle_frontend_test(
+    fn_tree="torch.real",
+    dtype_and_x=helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("valid"),
+    ),
+)
+def test_torch_real(
+    *,
+    dtype_and_x,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, input = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        input=input[0],
+    )
+
+
 # sign
 @handle_frontend_test(
     fn_tree="torch.sign",
Repository: ivy-llc/ivy

Issue:
sin



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/math.py b/ivy/functional/frontends/tensorflow/math.py
--- a/ivy/functional/frontends/tensorflow/math.py
+++ b/ivy/functional/frontends/tensorflow/math.py
@@ -325,6 +325,24 @@ def squared_difference(x, y, name=None):
     return ivy.square(ivy.subtract(x, y))
 
 
+@with_supported_dtypes(
+    {
+        "2.9.0 and below": (
+            "bfloat16",
+            "float16",
+            "float32",
+            "float64",
+            "complex64",
+            "complex128",
+        )
+    },
+    "tensorflow",
+)
+@to_ivy_arrays_and_back
+def sin(x, name=None):
+    return ivy.sin(x)
+
+
 @to_ivy_arrays_and_back
 def tan(x, name=None):
     return ivy.tan(x)
diff --git a/ivy/functional/frontends/tensorflow/raw_ops.py b/ivy/functional/frontends/tensorflow/raw_ops.py
--- a/ivy/functional/frontends/tensorflow/raw_ops.py
+++ b/ivy/functional/frontends/tensorflow/raw_ops.py
@@ -419,9 +419,7 @@ def Shape(*, input, output_type=ivy.int32, name="Shape"):
 )
 
 
-@to_ivy_arrays_and_back
-def Sin(*, x, name="Sin"):
-    return ivy.sin(x)
+Sin = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.sin))
 
 
 @to_ivy_arrays_and_back


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
@@ -70,6 +70,32 @@ def test_tensorflow_add(
     )
 
 
+# sin
+@handle_frontend_test(
+    fn_tree="tensorflow.math.sin",
+    dtype_and_x=helpers.dtype_and_values(available_dtypes=helpers.get_dtypes("float")),
+    test_with_out=st.just(False),
+
+)
+def test_tensorflow_sin(
+    *,
+    dtype_and_x,
+    frontend,
+    test_flags,
+    fn_tree,
+    on_device,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=x[0],
+    )
+
+
 # tan
 @handle_frontend_test(
     fn_tree="tensorflow.math.tan",
@@ -1823,10 +1849,10 @@ def test_tensorflow_floormod(
         fn_tree=fn_tree,
         on_device=on_device,
         x=x[0],
-        y=x[1], 
+        y=x[1],
     )
 
-    
+
 # greater
 @handle_frontend_test(
     fn_tree="tensorflow.math.greater",
Repository: ivy-llc/ivy

Issue:
cos



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/math.py b/ivy/functional/frontends/tensorflow/math.py
--- a/ivy/functional/frontends/tensorflow/math.py
+++ b/ivy/functional/frontends/tensorflow/math.py
@@ -512,3 +512,8 @@ def floormod(x, y, name=None):
 def greater(x, y, name=None):
     x, y = check_tensorflow_casting(x, y)
     return ivy.greater(x, y)
+
+
+@to_ivy_arrays_and_back
+def cos(x, name=None):
+    return ivy.cos(x)
diff --git a/ivy/functional/frontends/tensorflow/raw_ops.py b/ivy/functional/frontends/tensorflow/raw_ops.py
--- a/ivy/functional/frontends/tensorflow/raw_ops.py
+++ b/ivy/functional/frontends/tensorflow/raw_ops.py
@@ -132,9 +132,7 @@ def Concat(*, concat_dim, values, name="Concat"):
     return ivy.concat(values, axis=concat_dim)
 
 
-@to_ivy_arrays_and_back
-def Cos(*, x, name="Cos"):
-    return ivy.cos(x)
+Cos = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.cos))
 
 
 @to_ivy_arrays_and_back


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
@@ -1855,3 +1855,29 @@ def test_tensorflow_greater(
         x=x[0],
         y=x[1],
     )
+
+
+@handle_frontend_test(
+    fn_tree="tensorflow.math.cos",
+    dtype_and_x=helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("float"),
+    ),
+    test_with_out=st.just(False),
+)
+def test_tensorflow_cos(
+    *,
+    dtype_and_x,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=x[0],
+    )
Repository: ivy-llc/ivy

Issue:
acosh



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/math.py b/ivy/functional/frontends/tensorflow/math.py
--- a/ivy/functional/frontends/tensorflow/math.py
+++ b/ivy/functional/frontends/tensorflow/math.py
@@ -468,6 +468,11 @@ def acos(x, name="acos"):
     return ivy.acos(x)
 
 
+@to_ivy_arrays_and_back
+def acosh(x, name="acosh"):
+    return ivy.acosh(x)
+
+
 @to_ivy_arrays_and_back
 def square(x, name=None):
     return ivy.square(x)
diff --git a/ivy/functional/frontends/tensorflow/raw_ops.py b/ivy/functional/frontends/tensorflow/raw_ops.py
--- a/ivy/functional/frontends/tensorflow/raw_ops.py
+++ b/ivy/functional/frontends/tensorflow/raw_ops.py
@@ -24,6 +24,9 @@ def Acosh(*, x, name="Acosh"):
     return ivy.acosh(x)
 
 
+Acosh = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.acosh))
+
+
 Add = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.add))
 
 


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py
@@ -1635,7 +1635,34 @@ def test_tensorflow_acos(
         on_device=on_device,
         x=x[0],
     )
-
+    
+    
+# acosh
+@handle_frontend_test(
+    fn_tree="tensorflow.math.acosh",
+    dtype_and_x=helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("numeric")
+    ),
+    test_with_out=st.just(False),
+)
+def test_tensorflow_acosh(
+    *,
+    dtype_and_x,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=x[0],
+    )
+    
 
 # square
 @handle_frontend_test(
Repository: ivy-llc/ivy

Issue:
__str__



Discussion:
Is anybody working on this issue? or may I give it a try?
> Is anybody working on this issue? or may I give it a try?

Hello, I am.

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/ndarray/ndarray.py b/ivy/functional/frontends/numpy/ndarray/ndarray.py
--- a/ivy/functional/frontends/numpy/ndarray/ndarray.py
+++ b/ivy/functional/frontends/numpy/ndarray/ndarray.py
@@ -33,6 +33,9 @@ def __repr__(self):
             "ivy.array", "ivy.frontends.numpy.ndarray"
         )
 
+    def __str__(self):
+        return str(self._ivy_array)
+
     # Properties #
     # ---------- #
 
@@ -447,4 +450,4 @@ def __setitem__(self, key, value):
         self._ivy_array[key] = value
     
     def __mod__(self, value, /):
-        return np_frontend.mod(self._ivy_array, value, out=self)
+        return np_frontend.mod(self._ivy_array, value, out=self)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            


Test patch:
Repository: ivy-llc/ivy

Issue:
native_array



Discussion:

Resolving patch:
diff --git a/ivy/functional/ivy/creation.py b/ivy/functional/ivy/creation.py
--- a/ivy/functional/ivy/creation.py
+++ b/ivy/functional/ivy/creation.py
@@ -2,7 +2,17 @@
 from __future__ import annotations
 import functools
 from numbers import Number
-from typing import Union, Tuple, Optional, List, Sequence, Callable, Protocol, TypeVar
+from typing import (
+    Union,
+    Tuple,
+    Optional,
+    List,
+    Sequence,
+    Callable,
+    Protocol,
+    TypeVar,
+    Iterable
+)
 import numpy as np
 
 # local
@@ -1687,11 +1697,33 @@ def native_array(
     ret
         A native array interpretation of x.
 
+    Examples
+    -------
+    With :class:`List[Number]` input:
+
+    >>> x = [1, 2, 3]
+    >>> x_native = native_array(x)
+    >>> print(x_native)
+    [1. 2. 3.]
+
+    With :class:`np.ndarray` input:
+    >>> y = np.array([4, 5, 6])
+    >>> y_native = native_array(y)
+    >>> print(y_native)
+    [4. 5. 6.]
+
+    With :class:`ivy.Array` input:
+    >>> z = ivy.array([7, 8, 9])
+    >>> z_native = native_array(z)
+    >>> print(z_native)
+    [7. 8. 9.]
     """
     # ToDo: Make this more efficient,
     # ideally without first converting to ivy.Array with ivy.asarray and then
     # converting back to native with ivy.to_native
 
+    if isinstance(x, (ivy.Array, ivy.NativeArray, Iterable)):
+        return ivy.to_native(x, dtype=dtype, device=device)
     return ivy.to_native(ivy.asarray(x, dtype=dtype, device=device))
 
 


Test patch:
Repository: ivy-llc/ivy

Issue:
nonzero



Discussion:

Resolving patch:
diff --git a/ivy/functional/backends/jax/searching.py b/ivy/functional/backends/jax/searching.py
--- a/ivy/functional/backends/jax/searching.py
+++ b/ivy/functional/backends/jax/searching.py
@@ -96,5 +96,9 @@ def where(
 # ----- #
 
 
-def argwhere(x: JaxArray, /, *, out: Optional[JaxArray] = None) -> JaxArray:
+def argwhere(x: JaxArray,
+             /,
+             *,
+             out: Optional[JaxArray] = None,
+) -> JaxArray:
     return jnp.argwhere(x)
diff --git a/ivy/functional/backends/numpy/searching.py b/ivy/functional/backends/numpy/searching.py
--- a/ivy/functional/backends/numpy/searching.py
+++ b/ivy/functional/backends/numpy/searching.py
@@ -101,5 +101,9 @@ def where(
 # ----- #
 
 
-def argwhere(x: np.ndarray, /, *, out: Optional[np.ndarray] = None) -> np.ndarray:
+def argwhere(x: np.ndarray,
+             /,
+             *,
+             out: Optional[np.ndarray] = None,
+) -> np.ndarray:
     return np.argwhere(x)
diff --git a/ivy/functional/backends/torch/searching.py b/ivy/functional/backends/torch/searching.py
--- a/ivy/functional/backends/torch/searching.py
+++ b/ivy/functional/backends/torch/searching.py
@@ -111,5 +111,9 @@ def where(
 # ----- #
 
 
-def argwhere(x: torch.Tensor, /, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
+def argwhere(x: torch.Tensor,
+             /,
+             *,
+             out: Optional[torch.Tensor] = None,
+) -> torch.Tensor:
     return torch.argwhere(x)


Test patch: