Skip to content

Commit

Permalink
feat(frontends): Added erfinv and erfinv_ to torch frontend along wit…
Browse files Browse the repository at this point in the history
…h tests
  • Loading branch information
hmahmood24 committed Feb 3, 2024
1 parent 323b33d commit ba08c56
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ivy/functional/frontends/torch/miscellaneous_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ def einsum(equation, *operands):
return ivy.einsum(equation, *operands)


@to_ivy_arrays_and_back
def erfinv(input, *, out=None):
return ivy.erfinv(input, out=out)


@to_ivy_arrays_and_back
def finfo(dtype):
return ivy.finfo(dtype)
Expand Down
12 changes: 12 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,18 @@ def _set(index):

return self

@with_unsupported_dtypes({"2.1.2 and below": ("float16", "complex")}, "torch")
def erfinv(self, *, out=None):
return torch_frontend.erfinv(self, out=out)

@with_unsupported_dtypes({"2.1.2 and below": ("float16", "complex")}, "torch")
def erfinv_(self, *, out=None):
ret = self.erfinv(out=out)
self._ivy_array = ivy.inplace_update(
self._ivy_array, ivy.astype(ret.ivy_array, self._ivy_array.dtype)
)
return self

# Method aliases
absolute, absolute_ = abs, abs_
clip, clip_ = clamp, clamp_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,37 @@ def test_torch_einsum(
)


# erfinv
@handle_frontend_test(
fn_tree="torch.erfinv",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_value=-1,
max_value=1,
abs_smallest_val=1e-05,
),
)
def test_torch_erfinv(
*,
dtype_and_x,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x = 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],
)


@handle_frontend_test(
fn_tree="torch.flatten",
dtype_input_axes=helpers.dtype_values_axis(
Expand Down
77 changes: 77 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6374,6 +6374,83 @@ def test_torch_erf_(
)


# erfinv_ tests
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="erfinv_",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_value=-1,
max_value=1,
abs_smallest_val=1e-05,
),
)
def test_torch_erfinv(
dtype_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
backend_fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
backend_to_test=backend_fw,
init_all_as_kwargs_np={
"data": x[0],
},
method_input_dtypes=input_dtype,
method_all_as_kwargs_np={},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)


# erfinv_ tests
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="erfinv_",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
min_value=-1,
max_value=1,
abs_smallest_val=1e-05,
),
test_inplace=st.just(True),
)
def test_torch_erfinv_(
dtype_and_x,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
backend_fw,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
backend_to_test=backend_fw,
init_all_as_kwargs_np={
"data": x[0],
},
method_input_dtypes=input_dtype,
method_all_as_kwargs_np={},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)


# exp
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit ba08c56

Please sign in to comment.