I understand that the rank of a positive semi-definite matrix is equal to the number of non-zero singular values of the matrix.
$$\operatorname{rank}(M) = \{ \sigma \mid \sigma \ne 0 \}$$
This is somehow related to the spectral decomposition (or singular value decomposition, as some call it), but I cannot figure out how.
This question touches on that, but I cannot figure out the relationship:
How does the rank of a PSD matrix being equal to number of nonzero eigenvalues, follow from the spectral decomposition?
For any matrix, PSD or not, the rank of the matrix equals the number of nonzero singular values, and hence equals the number of nonzero eigenvalues.