jnp.linalg.svd(hermitian=True) returns an all-zero row in vh when a singular value is 0
Description
Using jnp.linalg.svd(a, hermitian=True), I get an all-zero row in vh when a singular value is exactly 0. That row should still be a unit vector, so the returned singular vectors aren’t orthonormal. This happens with float32 and float64, with or without jit; NumPy and JAX without hermitian=True both handle the same input correctly. Looks like sign(0) in the hermitian path is wiping out the vector.
import jax.numpy as jnp
a = jnp.array([[1., 0.], [0., 0.]])
u, s, vh = jnp.linalg.svd(a, hermitian=True)
print(s) # [1. 0.]
print(vh) # [[1. 0.] [0. 0.]]
print(vh @ vh.T) # [[1. 0.] [0. 0.]]
System info (python version, jaxlib version, accelerator, etc.)
python: 3.12.3
jax: 0.12.0.dev20261013+8fabfbc551 (main at 8fabfbc5)
jaxlib: 0.11.2
numpy: 2.5.4
platform: Linux x86_64, CPU
Looks like this comes from sign = lax.sign(v) in the hermitian branch of jnp.linalg.svd in jax/_src/numpy/linalg.py.
Since lax.sign(0.0) == 0.0, the zero eigenvalue sets sign to 0, which zeroes out the corresponding row when computing vh = _H(u * sign[..., None, :].astype(u.dtype)).
Mapping non-negative eigenvalues to 1 (e.g. lax.select(v < 0, lax.full_like(v, -1), lax.full_like(v, 1)) or jnp.where(v < 0, -1, 1)) preserves the unit eigenvector from eigh and keeps vh orthonormal.