Skip to content

Commit

Permalink
feat: add t function, issue 10474 (ivy-llc#10588)
Browse files Browse the repository at this point in the history
Co-authored-by: Fotios Spyridakos <[email protected]>
  • Loading branch information
ChunchangShao and fspyridakos authored Feb 17, 2023
1 parent 667409d commit a4d3624
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a4d3624

Please sign in to comment.