Skip to content

Commit

Permalink
Add default implementation for unravel_index
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosferreira committed Jul 27, 2020
1 parent 0981d47 commit bda0ab9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion unumpy/_multimethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,21 @@ def ravel_multi_index(multi_index, dims, mode="raise", order="C"):
return (multi_index,)


@create_numpy(_self_argreplacer)
def _unravel_index_default(indices, shape, order="C"):
if order == "F":
return NotImplemented

unraveled_coords = []
stride = 1
for i, dim in enumerate(shape[::-1]):
index = (indices // stride) % dim
unraveled_coords.append(index)
stride *= dim

return tuple(unraveled_coords[::-1])


@create_numpy(_self_argreplacer, default=_unravel_index_default)
@all_of_type(ndarray)
def unravel_index(indices, shape, order="C"):
return (indices,)
Expand Down

0 comments on commit bda0ab9

Please sign in to comment.