Sylvester's law of inertia states that for any symmetric matrix $A$ there exist an invertible matrix S such that, $S^T A S = D$, where $D$ is a diagonal matrix which has only entries 0, +1 and −1 along the diagonal.
How can the matrix $S$ be computed such that for symmetric positive diagonal matrix $A$, the diagonal matrix $D$ will be in the following form, $\begin{pmatrix} I_r \\ & 0\\ & & \ddots & \\ & & & & 0 \\ \end{pmatrix}$.
Where $r = \text{rank} (A)$