Skip to content

Commit

Permalink
feat : added nansum function for Pytorch frontend (ivy-llc#23206)
Browse files Browse the repository at this point in the history
Co-authored-by: juliagsy <[email protected]>
  • Loading branch information
2 people authored and druvdub committed Oct 14, 2023
1 parent d0d42b6 commit b37f766
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/ivy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/_template__of_py_test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ivy/functional/frontends/torch/reduction_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def moveaxis(input, source, destination):
def nanmean(input, dim=None, keepdim=False, *, dtype=None, out=None):
return ivy.nanmean(input, axis=dim, keepdims=keepdim, dtype=dtype, out=out)

@numpy_to_torch_style_args
@to_ivy_arrays_and_back
def nansum(input, dim=None, keepdim=False, dtype=None, out=None):
return ivy.nansum(input, axis=dim, keepdims=keepdim, dtype=dtype, out=out)


@to_ivy_arrays_and_back
@with_supported_dtypes(
Expand Down
33 changes: 33 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_reduction_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,39 @@ def test_torch_nanmean(
keepdim=keepdims,
)

@handle_frontend_test(
fn_tree="torch.nansum",
dtype_and_x=_statistical_dtype_values(
function="nansum",
min_value=-1e04,
max_value=1e04,
),
keepdims=st.booleans(),
)
def test_torch_nansum(
*,
dtype_and_x,
keepdims,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x, axis = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
input=x[0],
dim=axis,
keepdim=keepdims,
rtol=1e-02,
atol=1e-02,
)

@handle_frontend_test(
fn_tree="torch.nansum",
Expand Down

0 comments on commit b37f766

Please sign in to comment.