Skip to content

Commit

Permalink
feat: add unflatten as torch frontend Tensor method and the test
Browse files Browse the repository at this point in the history
tests pass.
  • Loading branch information
Ishticode committed Feb 13, 2024
1 parent 90eb299 commit d15467d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ def positive(self):
def pow(self, exponent):
return torch_frontend.pow(self, exponent)

def unflatten(self, dim, sizes):
return torch_frontend.unflatten(self, dim, sizes)

@with_unsupported_dtypes({"2.2 and below": ("bfloat16",)}, "torch")
def pow_(self, exponent):
self.ivy_array = self.pow(exponent).ivy_array
Expand Down
49 changes: 49 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 @@ -21,6 +21,7 @@

# local
import ivy_tests.test_ivy.helpers as helpers
from ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers import sizes_
from ivy_tests.test_ivy.test_frontends.test_torch.test_blas_and_lapack_ops import (
_get_dtype_and_3dbatch_matrices,
_get_dtype_input_and_matrices,
Expand Down Expand Up @@ -13800,6 +13801,54 @@ def test_torch_unbind(
)


@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="unflatten",
shape=st.shared(helpers.get_shape(min_num_dims=1), key="shape"),
dtype_and_values=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
min_num_dims=1,
shape_key="shape",
),
axis=helpers.get_axis(
shape=st.shared(helpers.get_shape(min_num_dims=1), key="shape"),
force_int=True,
),
)
def test_torch_unflatten(
*,
dtype_and_values,
on_device,
frontend,
backend_fw,
shape,
axis,
frontend_method_data,
init_flags,
method_flags,
):
dtype, x = dtype_and_values
sizes = sizes_(shape, axis)
helpers.test_frontend_method(
init_input_dtypes=dtype,
backend_to_test=backend_fw,
init_all_as_kwargs_np={
"data": x[0],
},
method_input_dtypes=dtype,
method_all_as_kwargs_np={
"dim": axis,
"sizes": sizes,
},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)


# unfold
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit d15467d

Please sign in to comment.