Skip to content

Commit

Permalink
numpy frontend instance nonzero, ravel (#6027)
Browse files Browse the repository at this point in the history
* numpy frontend instance sort, copy

* numpy frontend instance nonzero, ravel
  • Loading branch information
sharique1006 authored Oct 22, 2022
1 parent 6b9fda5 commit b6a6ddb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ivy/functional/frontends/numpy/ndarray/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ def sort(self, *, axis=-1, kind=None, order=None):

def copy(self, order='C'):
return np_frontend.copy(self.data, order=order)

def nonzero(self,):
return np_frontend.nonzero(self.data)[0]

def ravel(self, order="C"):
return np_frontend.ravel(self.data, order=order)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def where(cond, x1=None, x2=None, /):
raise ivy.exceptions.IvyException("where takes either 1 or 3 arguments")


@to_ivy_arrays_and_back
def nonzero(a):
return ivy.nonzero(a)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,77 @@ def test_numpy_instance_copy(
class_name="ndarray",
method_name="copy",
)


@handle_cmd_line_args
@given(
dtype_and_a=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
),
num_positional_args_method=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.ndarray.nonzero"
),
)
def test_numpy_instance_nonzero(
dtype_and_a,
as_variable,
num_positional_args_method,
native_array,
):
input_dtype, a = dtype_and_a

helpers.test_frontend_method(
input_dtypes_init=input_dtype,
input_dtypes_method=input_dtype,
as_variable_flags_init=as_variable,
num_positional_args_init=1,
num_positional_args_method=num_positional_args_method,
native_array_flags_init=native_array,
as_variable_flags_method=as_variable,
native_array_flags_method=native_array,
all_as_kwargs_np_init={
"data": a[0],
},
all_as_kwargs_np_method={
},
frontend="numpy",
class_name="ndarray",
method_name="nonzero",
)


@handle_cmd_line_args
@given(
dtype_and_a=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
),
num_positional_args_method=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.ndarray.ravel"
),
)
def test_numpy_instance_ravel(
dtype_and_a,
as_variable,
num_positional_args_method,
native_array,
):
input_dtype, a = dtype_and_a

helpers.test_frontend_method(
input_dtypes_init=input_dtype,
input_dtypes_method=input_dtype,
as_variable_flags_init=as_variable,
num_positional_args_init=1,
num_positional_args_method=num_positional_args_method,
native_array_flags_init=native_array,
as_variable_flags_method=as_variable,
native_array_flags_method=native_array,
all_as_kwargs_np_init={
"data": a[0],
},
all_as_kwargs_np_method={
},
frontend="numpy",
class_name="ndarray",
method_name="ravel",
)

0 comments on commit b6a6ddb

Please sign in to comment.