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 @@ -723,3 +723,16 @@ def _unsigned_int_bytes_repr(item_val, /, *, dtype=None):
return b"".join(bytes_reprs)
else:
raise ValueError("Unsupported data type for the array.")

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,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the tests are failing because they are unable to locate this function (https://github.com/unifyai/ivy/actions/runs/6200453935/job/16835349713?pr=22336#step:3:10495). Could you move this function at bit higher up in the file where other numpy nd.array instance methods are implemented?

Original file line number Diff line number Diff line change
Expand Up @@ -3671,3 +3671,54 @@ def test_numpy_ndarray_view(
frontend_method_data=frontend_method_data,
on_device=on_device,
)


#var
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="numpy.array",
method_name="var",
dtype_x_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("valid"),
valid_axis=True,
),
keepdims=st.booleans(),
where=np_frontend_helpers.where(),
dtype=helpers.get_dtypes(kind="valid"),
ddof=0,
)
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,
"ddof": 0,
"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,
)
Loading