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

Feature/add frontend function pytorch eigh #22637

Merged
Merged
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
6 changes: 6 additions & 0 deletions ivy/functional/frontends/torch/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,9 @@ def vector_norm(input, ord=2, dim=None, keepdim=False, *, dtype=None, out=None):
return ivy.vector_norm(
input, axis=dim, keepdims=keepdim, ord=ord, out=out, dtype=dtype
)

@with_supported_dtypes(
{"2.0.1 and below": ("float32", "float64", "complex32", "complex64", "complex128")}, "torch",
)
def eigh(A, UPLO="L", *, out=None):
return ivy.eigh(A, UPLO=UPLO, out=out)
45 changes: 45 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,48 @@ def test_torch_cholesky_ex(
input=x,
upper=upper,
)


@handle_frontend_test(
fn_tree="torch.linalg.eigh",
dtype_and_x=_get_dtype_and_matrix(dtype="valid", square=True, invertible=True),
UPLO=st.sampled_from(("L", "U")),
)
def test_torch_eigh(
*,
dtype_and_x,
UPLO,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
dtype, x = dtype_and_x
x = np.array(x[0], dtype=dtype[0])
# make symmetric positive-definite beforehand
x = np.matmul(x.T, x) + np.identity(x.shape[0]) * 1e-3

ret, frontend_ret = helpers.test_frontend_function(
input_dtypes=dtype,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
test_values=False,
a=x,
UPLO=UPLO,
)
ret = [ivy.to_numpy(x) for x in ret]
frontend_ret = [np.asarray(x) for x in frontend_ret]

L, Q = ret
frontend_L, frontend_Q = frontend_ret

assert_all_close(
ret_np=Q @ np.diag(L) @ Q.T,
ret_from_gt_np=frontend_Q @ np.diag(frontend_L) @ frontend_Q.T,
atol=1e-02,

)
Loading