Skip to content

Commit

Permalink
tensorflow.roll (ivy-llc#10354)
Browse files Browse the repository at this point in the history
* tensorflow.roll implementation

* code formating

* added required changes
  • Loading branch information
ebyau authored Feb 14, 2023
1 parent 5e40b56 commit fc48a90
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ivy/functional/frontends/tensorflow/general_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,7 @@ def where(condition: ivy.array, x=None, y=None, name=None):
return ivy.argwhere(condition)
else:
return ivy.where(condition, x, y)


def roll(input, shift, axis, name=None):
return ivy.roll(input, shift, axis=axis)
Original file line number Diff line number Diff line change
Expand Up @@ -1445,3 +1445,49 @@ def test_tensorflow_where_with_xy(
x=x,
y=y,
)


# roll
@handle_frontend_test(
fn_tree="tensorflow.roll",
dtype_and_values=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
shape=st.shared(helpers.get_shape(min_num_dims=1), key="shape"),
),
shift=helpers.get_axis(
shape=st.shared(helpers.get_shape(min_num_dims=1), key="shape"),
force_tuple=True,
),
axis=helpers.get_axis(
shape=st.shared(helpers.get_shape(min_num_dims=1), key="shape"),
force_tuple=True,
),
)
def test_tensorflow_roll(
*,
dtype_and_values,
shift,
axis,
on_device,
fn_tree,
frontend,
test_flags,
):
input_dtype, value = dtype_and_values
if isinstance(shift, int) and isinstance(axis, tuple):
axis = axis[0]
if isinstance(shift, tuple) and isinstance(axis, tuple):
if len(shift) != len(axis):
mn = min(len(shift), len(axis))
shift = shift[:mn]
axis = axis[:mn]
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
input=value[0],
shift=shift,
axis=axis,
)

0 comments on commit fc48a90

Please sign in to comment.