Skip to content

Commit

Permalink
Add torch.from_dlpack (ivy-llc#13647)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansuwala committed Apr 4, 2023
1 parent 3d26cc7 commit fa69493
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ivy/functional/frontends/torch/creation_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ def eye(
return ret


@to_ivy_arrays_and_back
def from_dlpack(ext_tensor):
return ivy.from_dlpack(ext_tensor)


@to_ivy_arrays_and_back
def empty_like(
input,
Expand Down
26 changes: 26 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_creation_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,29 @@ def test_torch_asarray(
dtype=dtype[0],
device=on_device,
)


# from_dlpack
@handle_frontend_test(
fn_tree="torch.from_dlpack",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("numeric")
),
)
def test_from_dlpack(
*,
dtype_and_x,
on_device,
fn_tree,
frontend,
test_flags,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
ext_tensor=x[0],
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
)

0 comments on commit fa69493

Please sign in to comment.