Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index_add #26394

Merged
merged 40 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d8a12e8
added index_add for the issue #26392
imsoumya18 Oct 1, 2023
a33ba59
started writing test, will change it
imsoumya18 Oct 2, 2023
a270432
test
imsoumya18 Oct 3, 2023
f3d2842
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 6, 2023
1d131ac
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 7, 2023
74bc04b
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 7, 2023
5639abf
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 9, 2023
df9020f
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 10, 2023
b29c754
index_add issue #26392
imsoumya18 Oct 10, 2023
a6d9fb6
Merge remote-tracking branch 'origin/index_add#26392' into index_add#…
imsoumya18 Oct 10, 2023
d08826d
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 10, 2023
8530c05
index_add issue #26392
imsoumya18 Oct 11, 2023
590003f
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 12, 2023
73f74b4
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 13, 2023
b8f5f36
small fix
imsoumya18 Oct 13, 2023
956e670
small fix
imsoumya18 Oct 13, 2023
925c8a7
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 14, 2023
63e2728
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 15, 2023
a2096b3
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 16, 2023
a44ed2f
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 18, 2023
620cfed
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 19, 2023
b46638e
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 22, 2023
6ef47c3
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Oct 25, 2023
dd33c4d
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Nov 8, 2023
56e4b76
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Nov 9, 2023
1c0ad88
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Nov 10, 2023
9f26f18
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Nov 19, 2023
d1c5b51
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Nov 21, 2023
78f81a0
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 1, 2023
74860cb
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 4, 2023
d93eded
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 5, 2023
3636d64
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 7, 2023
badfcfb
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 7, 2023
f2b939a
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 9, 2023
95110b3
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Dec 11, 2023
b95a0c5
using scatter_nd
imsoumya18 Dec 12, 2023
43123c5
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Jan 2, 2024
4fbfcac
update
imsoumya18 Jan 2, 2024
c244b68
Merge branch 'unifyai:main' into index_add#26392
imsoumya18 Jan 9, 2024
d370354
all tests passed
imsoumya18 Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ivy/functional/frontends/paddle/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,37 @@ def gather_nd(x, index, name=None):
return ivy.gather_nd(x, index)


@with_supported_dtypes(
{"2.5.1 and below": ("int32", "int64", "float16", "float32", "float64")},
"paddle",
)
@to_ivy_arrays_and_back
def index_add(x, index, axis, value, name=None):
input = ivy.swapaxes(x, axis, 0)
source = ivy.swapaxes(value, axis, 0)
_to_adds = []
index = sorted(zip(ivy.to_list(index), range(len(index))), key=(lambda x: x[0]))
while index:
_curr_idx = index[0][0]
while len(_to_adds) < _curr_idx:
_to_adds.append(ivy.zeros_like(source[0]))
_to_add_cum = ivy.get_item(source, index[0][1])
while (1 < len(index)) and (index[0][0] == index[1][0]):
_to_add_cum = _to_add_cum + ivy.get_item(source, index.pop(1)[1])
index.pop(0)
_to_adds.append(_to_add_cum)
while len(_to_adds) < input.shape[0]:
_to_adds.append(ivy.zeros_like(source[0]))
_to_adds = ivy.stack(_to_adds)
if len(input.shape) < 2:
# Added this line due to the paddle backend treating scalars as 1-d arrays
_to_adds = ivy.flatten(_to_adds)

ret = ivy.add(input, _to_adds, alpha=1)
ret = ivy.swapaxes(ret, 0, axis, out=None)
return ret


@to_ivy_arrays_and_back
def put_along_axis(arr, indices, values, axis, reduce="assign"):
result = ivy.put_along_axis(arr, indices, values, axis)
Expand Down
52 changes: 52 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,58 @@ def test_paddle_gather_nd(
)


@handle_frontend_test(
fn_tree="paddle.index_add",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
min_num_dims=3,
max_num_dims=3,
num_arrays=3,
),
dtype_and_x2=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
min_num_dims=2,
max_num_dims=2,
num_arrays=1,
),
dtype_and_x3=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
min_num_dims=3,
max_num_dims=3,
num_arrays=2,
),
dtype=helpers.get_dtypes("valid", full=False),
)
def test_paddle_index_add(
*,
dtype_and_x,
dtype_and_x2,
dtype_and_x3,
dtype,
on_device,
backend_fw,
fn_tree,
frontend,
test_flags,
):
input_dtype, x = dtype_and_x
index = dtype_and_x2[1]
value = dtype_and_x3[1]
helpers.test_frontend_function(
input_dtypes=input_dtype,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=x[0],
index=index[0],
axis=0,
value=value[0],
dtype=dtype[0],
)


# repeat_interleave
@handle_frontend_test(
fn_tree="paddle.repeat_interleave",
Expand Down
Loading