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

feat: adding np.ndarray.var to the frontends #22336

Merged
merged 11 commits into from
Oct 4, 2023
13 changes: 13 additions & 0 deletions ivy/functional/frontends/numpy/ndarray/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,19 @@ def __lshift__(self, value, /):
def round(self, decimals=0, out=None):
return np_frontend.round(self, decimals=decimals, out=out)

def var(
self, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True
):
return np_frontend.var(
self,
axis=axis,
dtype=dtype,
out=out,
ddof=ddof,
keepdims=keepdims,
where=where,
)


# --- Helpers --- #
# --------------- #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
assert_all_close,
BackendHandler,
)
from ivy_tests.test_ivy.test_functional.test_core.test_statistical import (
_statistical_dtype_values,
)
import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers
from ivy_tests.test_ivy.test_functional.test_core.test_linalg import (
_get_first_matrix_and_dtype,
Expand Down Expand Up @@ -3638,6 +3641,52 @@ def test_numpy_ndarray_transpose(
)


# var
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="numpy.array",
method_name="var",
dtype_x_axis=_statistical_dtype_values(function="var"),
dtype=helpers.get_dtypes("valid", full=False, none=True),
where=np_frontend_helpers.where(),
keep_dims=st.booleans(),
PushpamJha14 marked this conversation as resolved.
Show resolved Hide resolved
)
def test_numpy_ndarray_var(
dtype_x_axis,
frontend_method_data,
init_flags,
method_flags,
frontend,
backend_fw,
on_device,
keepdims,
where,
dtype,
):
input_dtypes, x, axis = dtype_x_axis
helpers.test_frontend_method(
init_input_dtypes=input_dtypes,
method_input_dtypes=input_dtypes,
init_all_as_kwargs_np={
"object": x[0],
},
method_all_as_kwargs_np={
"axis": axis,
"dtype": dtype,
"keepdims": keepdims,
"where": where,
},
frontend=frontend,
backend_to_test=backend_fw,
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
rtol_=1e-2,
atol_=1e-2,
on_device=on_device,
)


# view
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down
Loading