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

added unravel_index #12876

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 0 additions & 48 deletions .idea/runConfigurations/pytest_for_stateful.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# local
import ivy
from ivy.functional.frontends.numpy.func_wrapper import (
to_ivy_arrays_and_back,
Expand Down Expand Up @@ -31,6 +32,13 @@ def tril_indices(n, k=0, m=None):
return ivy.tril_indices(n, m, k)


# unravel_index
@to_ivy_arrays_and_back
def unravel_index(indices, shape, order='C'):
ret = [x.astype("int64") for x in ivy.unravel_index(indices, shape)]
return tuple(ret)


@to_ivy_arrays_and_back
def indices(dimensions, dtype=int, sparse=False):
dimensions = tuple(dimensions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Testing Function
# global
import numpy as np
from hypothesis import strategies as st

# local
Expand Down Expand Up @@ -190,3 +191,50 @@ def test_indices(
dtype=dtype[0],
sparse=sparse,
)


# unravel_index
@st.composite
def max_value_as_shape_prod(draw):
shape = draw(
helpers.get_shape(
min_num_dims=1,
max_num_dims=5,
min_dim_size=1,
max_dim_size=5,
)
)
dtype_and_x = draw(
helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("valid"),
min_value=0,
max_value=np.prod(shape) - 1,
)
)
return dtype_and_x, shape


@handle_frontend_test(
fn_tree="numpy.unravel_index",
dtype_x_shape=max_value_as_shape_prod(),
test_with_out=st.just(False),
)
def test_numpy_unravel_index(
*,
dtype_x_shape,
test_flags,
frontend,
fn_tree,
on_device,
):
dtype_and_x, shape = dtype_x_shape
input_dtype, x = dtype_and_x[0], dtype_and_x[1]
helpers.test_frontend_function(
input_dtypes=input_dtype,
test_flags=test_flags,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
indices=x[0],
shape=shape,
)