Skip to content

Commit

Permalink
paddle frontend cholesky_solve added (ivy-llc#21291)
Browse files Browse the repository at this point in the history
Co-authored-by: @AnnaTz
  • Loading branch information
dhanush-2501 authored and sushmanthreddy committed Aug 17, 2023
1 parent 3a8c7b6 commit 70685b5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ivy/functional/frontends/paddle/tensor/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ def solve(x1, x2, name=None):
return ivy.solve(x1, x2)


# cholesky_solve
@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
def cholesky_solve(x, y, /, *, upper=False, name=None):
if upper:
y = ivy.matrix_transpose(y)
Y = ivy.solve(y, x)
return ivy.solve(ivy.matrix_transpose(y), Y)


# cholesky
@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import ivy_tests.test_ivy.helpers as helpers
from ivy_tests.test_ivy.helpers import assert_all_close
from ivy_tests.test_ivy.helpers import handle_frontend_test, matrix_is_stable

from ivy_tests.test_ivy.test_frontends.test_tensorflow.test_linalg import (
_get_second_matrix,
_get_cholesky_matrix,
)

# Helpers #
# ------ #
Expand Down Expand Up @@ -528,6 +531,49 @@ def test_paddle_solve(
)


# cholesky_solve
@st.composite
def _get_paddle_cholesky_matrix(draw):
input_dtype, spd_chol = draw(_get_cholesky_matrix())
probability = draw(st.floats(min_value=0, max_value=1))
if probability > 0.5:
spd_chol = spd_chol.T # randomly transpose the matrix
return input_dtype, spd_chol


@handle_frontend_test(
fn_tree="paddle.tensor.linalg.cholesky_solve",
x=_get_second_matrix(),
y=_get_paddle_cholesky_matrix(),
test_with_out=st.just(False),
)
def test_paddle_cholesky_solve(
*,
x,
y,
frontend,
backend_fw,
test_flags,
fn_tree,
on_device,
):
input_dtype1, x1 = x
input_dtype2, x2 = y
helpers.test_frontend_function(
input_dtypes=[input_dtype1, input_dtype2],
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-3,
atol=1e-3,
x=x1,
y=x2,
upper=np.array_equal(x2, np.triu(x2)), # check whether the matrix is upper
)


# cholesky
@handle_frontend_test(
fn_tree="paddle.tensor.linalg.cholesky",
Expand Down

0 comments on commit 70685b5

Please sign in to comment.