Projection onto a positive semidefinite trace ball (source code)

= Projection onto a positive semidefinite trace ball

If $M\succeq0$ has eigenpairs $(\mu_i,v_i)$ and $\operatorname{tr}M>s$, then its Frobenius projection onto $\mathcal S_s$ is
$$
\Pi_{\mathcal S_s}(M)
=\sum_i(\mu_i-\rho)_+v_iv_i^T,
$$
where $\rho>0$ is uniquely determined by $\sum_i(\mu_i-\rho)_+=s$.