Repository: ivy-llc/ivy

Issue:
index_copy



Discussion:
Hey I would like to know about this issue can you tell me some details, please 
This issue has been labelled as stale. If you would like to continue working on this issue, then please add another comment or create a PR . If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. For more information please refer to this page in our documentation: https://lets-unify.ai/ivy/contributing/1_the_basics.html#todo-list-issues
I would like to work on this issue so wanted to know more about this 
This issue has been labelled as stale. If you would like to continue working on this issue, then please add another comment or create a PR . If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. For more information please refer to this page in our documentation: https://lets-unify.ai/ivy/contributing/1_the_basics.html#todo-list-issues
This issue is being closed. As this issue has been stalled with no activity for more than 7 days.

Resolving patch:
diff --git a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py
--- a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py
+++ b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py
@@ -322,3 +322,26 @@ def index_add(input, dim, index, source, *, alpha=1, out=None):
     ret = ivy.add(input, _to_adds, alpha=alpha)
     ret = ivy.swapaxes(ret, 0, dim, out=out)
     return ret
+
+
+@to_ivy_arrays_and_back
+def index_copy(input, dim, index, source, *, out=None):
+    input = ivy.swapaxes(input, dim, 0)
+    source = ivy.swapaxes(source, dim, 0)
+    index = sorted(zip(ivy.to_list(index), range(len(index))), key=(lambda x: x[0]))
+    res = []
+    while index:
+        _curr_idx = index[0][0]
+        for i in range(len(res), _curr_idx):
+            res.append(ivy.get_item(input, i))
+        while (1 < len(index)) and (index[0][0] == index[1][0]):
+            index.pop(0)
+        res.append(ivy.get_item(source, index[0][1]))
+        index.pop(0)
+    for i in range(len(res), input.shape[0]):
+        res.append(ivy.get_item(input, i))
+    res = ivy.stack(res)
+    if len(input.shape) < 2:
+        res = ivy.flatten(res)
+
+    return ivy.swapaxes(res, 0, dim, out=out)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py
--- a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py
+++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py
@@ -1308,3 +1308,34 @@ def test_torch_index_add(
         source=source,
         alpha=alpha,
     )
+
+
+# index_copy
+@handle_frontend_test(
+    fn_tree="torch.index_copy",
+    xs_dtypes_dim_idx=_arrays_dim_idx_n_dtypes(),
+)
+def test_torch_index_copy(
+    *,
+    xs_dtypes_dim_idx,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    xs, input_dtypes, axis, indices = xs_dtypes_dim_idx
+    if xs[0].shape[axis] < xs[1].shape[axis]:
+        source, input = xs
+    else:
+        input, source = xs
+    helpers.test_frontend_function(
+        input_dtypes=[input_dtypes[0], "int64", input_dtypes[1]],
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        input=input,
+        dim=axis,
+        index=indices,
+        source=source,
+    )