Skip to content

Commit a206503

Browse files
committed
Add special handling for empty matrices
1 parent 71d3c23 commit a206503

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

dpnp/linalg/dpnp_utils_linalg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,13 @@ def dpnp_matrix_rank(A, tol=None, hermitian=False, rtol=None):
22772277

22782278
S = dpnp_svd(A, compute_uv=False, hermitian=hermitian)
22792279

2280+
# Handle empty matrices: if either dimension is 0, there are no singular
2281+
# values and the rank is 0. For stacked matrices, return array of zeros
2282+
# with proper shape.
2283+
if S.shape[-1] == 0:
2284+
# S has shape (..., 0), so result should have shape (...)
2285+
return dpnp.count_nonzero(S, axis=-1)
2286+
22802287
if tol is None:
22812288
if rtol is None:
22822289
rtol = max(A.shape[-2:]) * dpnp.finfo(S.dtype).eps

0 commit comments

Comments
 (0)