Skip to content

Commit

Permalink
Implemented tensor.reshape_as
Browse files Browse the repository at this point in the history
  • Loading branch information
fspyridakos committed Jan 27, 2023
1 parent cd1a4ea commit bf4b3d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ivy/functional/frontends/torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def reshape(self, *args, shape=None):
return torch_frontend.reshape(self._ivy_array, args)
return torch_frontend.reshape(self._ivy_array)

@with_unsupported_dtypes({"1.11.0 and below": ("bfloat16",)}, "torch")
def reshape_as(self, other):
return torch_frontend.reshape(self, other.shape)

@with_unsupported_dtypes({"1.11.0 and below": ("bfloat16",)}, "torch")
def add(self, other, *, alpha=1):
return torch_frontend.add(self._ivy_array, other, alpha=alpha)
Expand Down
39 changes: 39 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 @@ -442,6 +442,45 @@ def test_torch_instance_reshape(
)


# reshape_as
@handle_frontend_method(
class_tree=CLASS_TREE,
init_tree="torch.tensor",
method_name="reshape_as",
dtype_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid", full=True), num_arrays=2
),
)
def test_torch_instance_reshape_as(
dtype_x,
init_num_positional_args: pf.NumPositionalArgFn,
method_num_positional_args: pf.NumPositionalArgMethod,
as_variable: pf.AsVariableFlags,
native_array: pf.NativeArrayFlags,
frontend_method_data,
frontend,
):
input_dtype, x = dtype_x
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
init_as_variable_flags=as_variable,
init_num_positional_args=init_num_positional_args,
init_native_array_flags=native_array,
init_all_as_kwargs_np={
"data": x[0],
},
method_input_dtypes=input_dtype,
method_as_variable_flags=as_variable,
method_num_positional_args=method_num_positional_args,
method_native_array_flags=native_array,
method_all_as_kwargs_np={
"other": x[1],
},
frontend_method_data=frontend_method_data,
frontend=frontend,
)


# sin
@handle_frontend_method(
class_tree=CLASS_TREE,
Expand Down

0 comments on commit bf4b3d1

Please sign in to comment.