Skip to content

Commit

Permalink
fix(torch-frontend, ivy): Updated test_torch_result_type to cover sca…
Browse files Browse the repository at this point in the history
…lar cases and fixed the paddle backend of ivy.result_type for these
  • Loading branch information
AnnaTz committed Sep 27, 2023
1 parent 3333dbc commit 789da6d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ivy/functional/backends/paddle/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def iinfo(type: Union[paddle.dtype, str, paddle.Tensor], /) -> Iinfo:


def result_type(*arrays_and_dtypes: Union[paddle.Tensor, paddle.dtype]) -> ivy.Dtype:
return ivy.promote_types(arrays_and_dtypes[0].dtype, arrays_and_dtypes[1].dtype)
return ivy.promote_types_of_inputs(*arrays_and_dtypes)[0].dtype


# Extra #
Expand Down
53 changes: 44 additions & 9 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,65 @@ def test_torch_bincount(
)


@st.composite
def _elemwise_helper(draw):
value_strategy = st.one_of(
helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
),
st.integers(min_value=-10000, max_value=10000),
st.floats(min_value=-10000, max_value=10000),
)

dtype_and_x1 = draw(value_strategy)
if isinstance(dtype_and_x1, tuple):
dtype1 = dtype_and_x1[0]
x1 = dtype_and_x1[1][0]
else:
dtype1 = []
x1 = dtype_and_x1

dtype_and_x2 = draw(value_strategy)
if isinstance(dtype_and_x2, tuple):
dtype2 = dtype_and_x2[0]
x2 = dtype_and_x2[1][0]
else:
dtype2 = []
x2 = dtype_and_x2

num_pos_args = None
if not dtype1 and not dtype2:
num_pos_args = 2
elif not dtype1:
x1, x2 = x2, x1
input_dtypes = dtype1 + dtype2

return x1, x2, input_dtypes, num_pos_args


@handle_frontend_test(
fn_tree="torch.result_type",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
num_arrays=2,
),
dtypes_and_xs=_elemwise_helper(),
test_with_out=st.just(False),
)
def test_torch_result_type(
dtype_and_x,
dtypes_and_xs,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x = dtype_and_x
x1, x2, input_dtypes, num_pos_args = dtypes_and_xs
if num_pos_args is not None:
test_flags.num_positional_args = num_pos_args
helpers.test_frontend_function(
input_dtypes=input_dtype,
input_dtypes=input_dtypes,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
tensor=x[0],
other=x[1],
tensor=x1,
other=x2,
)

0 comments on commit 789da6d

Please sign in to comment.