Skip to content

Commit

Permalink
feat: adds stack function to paddle tensor class
Browse files Browse the repository at this point in the history
  • Loading branch information
arshPratap committed Sep 27, 2023
1 parent dfe5ea0 commit 654da0a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ivy/functional/frontends/paddle/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def squeeze(x, axis=None, name=None):
return ivy.squeeze(x, axis=axis)


@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "int32", "int64")}, "paddle"
)
@to_ivy_arrays_and_back
def stack(x, axis=0, name=None):
return ivy.stack(x, axis=axis)
Expand Down
3 changes: 3 additions & 0 deletions ivy/functional/frontends/paddle/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,6 @@ def real(self, name=None):
)
def cast(self, dtype):
return paddle_frontend.cast(self, dtype)

def stack(self, axis=0, name=None):
return paddle_frontend.stack(self._ivy_array, axis=axis)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# local
import ivy_tests.test_ivy.helpers as helpers
from ivy.functional.frontends.paddle import Tensor
from ivy.functional.frontends.paddle import Tensor, to_tensor
from ivy_tests.test_ivy.helpers import assert_all_close
from ivy_tests.test_ivy.helpers import handle_frontend_method, BackendHandler
from ivy_tests.test_ivy.test_functional.test_experimental.test_core.test_manipulation import ( # noqa E501
Expand Down Expand Up @@ -152,6 +152,27 @@ def _get_dtype_and_values_for_lerp(draw):
return input_dtype, x[0], x[1], weight


# stack
@st.composite
def _get_stack_inputs(draw):
num_dims = draw(st.shared(helpers.ints(min_value=2, max_value=5), key="num_dims"))
common_shape = draw(
helpers.list_of_size(
x=helpers.ints(min_value=0, max_value=2),
size=num_dims - 1,
)
)
axis = draw(st.sampled_from(list(range(num_dims))))
dtypes, x = draw(
helpers.dtype_and_values(
available_dtypes=draw(helpers.get_dtypes("numeric")),
shape=common_shape,
)
)
x = to_tensor(x)
return x, dtypes, axis


@st.composite
def _reshape_helper(draw):
# generate a shape s.t len(shape) > 0
Expand Down Expand Up @@ -3809,6 +3830,41 @@ def test_paddle_tensor_squeeze_(
)


# stack
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="paddle.to_tensor",
method_name="stack",
input_values=_get_stack_inputs(),
)
def test_paddle_tensor_stack(
input_values,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
backend_fw,
):
data, input_dtype, axis = input_values
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
backend_to_test=backend_fw,
init_all_as_kwargs_np={
"data": data,
},
method_input_dtypes=input_dtype,
method_all_as_kwargs_np={
"axis": axis,
},
frontend_method_data=frontend_method_data,
init_flags=init_flags,
method_flags=method_flags,
frontend=frontend,
on_device=on_device,
)


# stanh
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit 654da0a

Please sign in to comment.