Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lu_solve to PyTorch Frontend #22922

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ivy/functional/frontends/torch/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def lu_factor(A, *, pivot=True, out=None):
return ivy.lu_factor(A, pivot=pivot, out=out)


@to_ivy_arrays_and_back
@with_supported_dtypes(
{"2.0.1 and below": ("float32", "float64", "complex32", "complex64")}, "torch"
)
def lu_solve(LU, pivots, B, left=True, adjoint=False, out=None):
# TODO: Implement left
# TODO: Implement adjoint
return ivy.solve(LU, ivy.dot(pivots, B), out=out)


@to_ivy_arrays_and_back
@with_supported_dtypes(
{"2.0.1 and below": ("float32", "float64", "complex32", "complex64")}, "torch"
Expand Down
50 changes: 50 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,53 @@ def test_torch_cholesky_ex(
input=x,
upper=upper,
)


@handle_frontend_test(
fn_tree="torch.linalg.lu_solve",
dtype_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
shape=(3, 3),
num_arrays=2,
shared_dtype=True,
min_value=-1e04,
max_value=1e04,
),
dtype_y=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
shape=(3, 1),
num_arrays=1,
shared_dtype=True,
min_value=-1e04,
max_value=1e04,
),
left=st.booleans(),
adjoint=st.booleans(),
)
def test_torch_lu_solve(
dtype_x,
dtype_y,
left,
adjoint,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x = dtype_x
input_dtype, y = dtype_y
test_flags.num_positional_args = 2
helpers.test_frontend_function(
input_dtypes=[input_dtype[0], input_dtype[0]],
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
A=x[0],
pivots=x[1],
B=y[0],
left=left,
adjoint=adjoint,
)
Loading