Skip to content

Commit

Permalink
Added cholesky to torch frontend (#7694)
Browse files Browse the repository at this point in the history
* add cholesky to torch frontend

* add blank line

* formatting
  • Loading branch information
theRealBird committed Dec 15, 2022
1 parent 9d1aff5 commit 5c20f70
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ivy/functional/frontends/torch/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def matrix_rank(input, *, atol=None, rtol=None, hermitian=False, out=None):
return ivy.astype(ivy.matrix_rank(input, atol=atol, rtol=rtol, out=out), ivy.int64)


@to_ivy_arrays_and_back
def cholesky(input, *, upper=False, out=None):
return ivy.cholesky(input, upper=upper, out=out)


@to_ivy_arrays_and_back
def svd(input, /, *, full_matrices=True):
return ivy.svd(input, compute_uv=True, full_matrices=full_matrices)
Expand Down
38 changes: 37 additions & 1 deletion ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,44 @@ def test_matrix_rank(
rtol=rtol,
atol=atol,
)


@handle_frontend_test(
fn_tree="torch.linalg.cholesky",
dtype_and_x=_get_dtype_and_square_matrix(),
upper=st.booleans(),
)
def test_torch_cholesky(
*,
dtype_and_x,
upper,
as_variable,
with_out,
num_positional_args,
native_array,
on_device,
fn_tree,
frontend,
):
dtype, x = dtype_and_x
x = np.matmul(x.T, x) + np.identity(x.shape[0]) # make symmetric positive-definite


helpers.test_frontend_function(
input_dtypes=dtype,
as_variable_flags=as_variable,
with_out=with_out,
all_aliases=["cholesky"],
num_positional_args=num_positional_args,
native_array_flags=native_array,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-01,
input=x,
upper=upper,
)


# svd
@handle_frontend_test(
fn_tree="torch.linalg.svd",
Expand Down

0 comments on commit 5c20f70

Please sign in to comment.