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

numpy frontend instance sort, copy #6024

Merged
merged 1 commit into from
Oct 22, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def asarray(

@to_ivy_arrays_and_back
def copy(a, order="K", subok=False):
return ivy.copy_array(a, dtype=a.dtype())
return ivy.copy_array(a)
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 @@ -113,3 +113,9 @@ def cumsum(self, *, axis=None, dtype=dtype, out=None):
dtype=dtype,
out=out,
)

def sort(self, *, axis=-1, kind=None, order=None):
return np_frontend.sort(self.data, axis=axis, kind=kind, order=order)

def copy(self, order='C'):
return np_frontend.copy(self.data, order=order)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# local
import ivy_tests.test_ivy.helpers as helpers
from ivy_tests.test_ivy.helpers import handle_cmd_line_args
from ivy_tests.test_ivy.helpers import handle_cmd_line_args, assert_all_close
import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers


Expand Down Expand Up @@ -591,3 +591,92 @@ def test_numpy_instance_cumsum(
class_name="ndarray",
method_name="cumsum",
)


@handle_cmd_line_args
@given(
dtype_x_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("float"),
min_axis=-1,
max_axis=0,
min_num_dims=1,
force_int_axis=True,
),
num_positional_args_method=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.ndarray.sort"
),
)
def test_numpy_instance_sort(
dtype_x_axis,
as_variable,
num_positional_args_method,
native_array,
):
input_dtype, x, axis = dtype_x_axis

ret, frontend_ret = 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": x[0],
},
all_as_kwargs_np_method={
"axis": axis,
},
frontend="numpy",
class_name="ndarray",
method_name="sort",
test_values=False,
)
frontend_ret = np.sort(x[0], axis=axis)
assert_all_close(
ret_np=ret,
ret_from_gt_np=frontend_ret,
rtol=1e-2,
atol=1e-2,
ground_truth_backend="numpy",
)


@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("numeric"),
min_num_dims=1,
),
num_positional_args_method=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.ndarray.copy"
),
)
def test_numpy_instance_copy(
dtype_and_x,
as_variable,
num_positional_args_method,
native_array,
):
input_dtype, x = dtype_and_x

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": x[0],
},
all_as_kwargs_np_method={
},
frontend="numpy",
class_name="ndarray",
method_name="copy",
)