Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions python/paddle/tensor/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,10 @@ def cholesky(x: Tensor, upper: bool = False, name: str | None = None) -> Tensor:
[1.30602181, 0.08326444, 0.22790681]])
"""
if in_dynamic_or_pir_mode():
x_shape = x.shape
assert (
len(x_shape) >= 2 and x_shape[-1] == x_shape[-2]
), "Shape must have at least 2 dimensions and last two dimensions must be equal."
return _C_ops.cholesky(x, upper)
else:
check_variable_and_dtype(x, 'dtype', ['float32', 'float64'], 'cholesky')
Expand Down Expand Up @@ -4049,8 +4053,6 @@ def eigh(
[ 0.3826833963394165j , -0.9238795042037964j ]])

"""
if in_dynamic_mode():
return _C_ops.eigh(x, UPLO)

def __check_input(x, UPLO):
x_shape = list(x.shape)
Expand All @@ -4068,7 +4070,7 @@ def __check_input(x, UPLO):
f"UPLO must be L or U. But received UPLO is: {UPLO}"
)

if in_pir_mode():
if in_dynamic_mode() or in_pir_mode():
__check_input(x, UPLO)
return _C_ops.eigh(x, UPLO)

Expand Down
8 changes: 8 additions & 0 deletions test/legacy_test/test_cholesky_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ def test_dygraph(self):
print("The mat is singular")


class TestCholeskyAPIError_ZeroSize(unittest.TestCase):
def _test_case(self):
paddle.linalg.cholesky(paddle.randn([0, 5]))

def test_error(self):
self.assertRaises(AssertionError, self._test_case)


if __name__ == "__main__":
paddle.enable_static()
unittest.main()
8 changes: 8 additions & 0 deletions test/legacy_test/test_eigh_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,13 @@ def init_input_shape(self):
self.x_shape = [5, 0, 0]


class TestEighAPIError_ZeroSize(unittest.TestCase):
def _test_case(self):
paddle.linalg.eigh(paddle.randn([0, 5]))

def test_error(self):
self.assertRaises(ValueError, self._test_case)


if __name__ == "__main__":
unittest.main()
Loading