diff --git a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py index ced88f0746b21..308fbf877eb8d 100644 --- a/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py +++ b/ivy/functional/frontends/torch/indexing_slicing_joining_mutating_ops.py @@ -126,6 +126,19 @@ def transpose(input, dim0, dim1): return ivy.swapaxes(input, dim0, dim1) +@to_ivy_arrays_and_back +def t(input): + if input.ndim > 2: + raise ivy.exceptions.IvyException( + "t(input) expects a tensor with <= 2 dimensions, but self is %dD" + % input.ndim + ) + if input.ndim == 2: + return ivy.swapaxes(input, 0, 1) + else: + return input + + @to_ivy_arrays_and_back def tile(input, dims): try: diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py index d529a1ef10a30..aa5f8fbf6d76a 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_indexing_slicing_joining_mutating_ops.py @@ -445,6 +445,31 @@ def test_torch_transpose( dim1=dim1, ) +# t +@handle_frontend_test( + fn_tree="torch.t", + dtype_and_values=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("float"), + shape=st.shared(helpers.get_shape(max_num_dims=2), key="shape"), + ), +) +def test_torch_t( + *, + dtype_and_values, + on_device, + fn_tree, + frontend, + test_flags, +): + input_dtype, value = dtype_and_values + 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], + ) # squeeze @handle_frontend_test(