Skip to content

Commit

Permalink
feat: adding np.ndarray.var to the frontends (ivy-llc#22336)
Browse files Browse the repository at this point in the history
Co-authored-by: ivy-branch <[email protected]>
Co-authored-by: Anwaar Khalid <[email protected]>
  • Loading branch information
3 people authored and druvdub committed Oct 14, 2023
1 parent 9cd8a3c commit f3f8b36
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
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 @@ -3699,6 +3702,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(),
keepdims=st.booleans(),
)
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

0 comments on commit f3f8b36

Please sign in to comment.