Skip to content

Commit

Permalink
index_add issue ivy-llc#26392
Browse files Browse the repository at this point in the history
  • Loading branch information
imsoumya18 committed Oct 10, 2023
1 parent 74bc04b commit b29c754
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ivy/functional/frontends/paddle/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ def gather_nd(x, index, name=None):
"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)
def index_add(input, dim, index, source, *, alpha=1, out=None):
input = ivy.swapaxes(input, dim, 0)
source = ivy.swapaxes(source, dim, 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]):
while (len(index)) > 1 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)
Expand All @@ -112,8 +112,8 @@ def index_add(x, index, axis, value, name=None):
# 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)
ret = ivy.add(input, _to_adds, alpha=alpha)
ret = ivy.swapaxes(ret, 0, dim, out=out)
return ret


Expand Down

0 comments on commit b29c754

Please sign in to comment.