Suppose we have two real matrices $A$ and $B$ of size $n\times m$ with $m < n$, and suppose we look for a (small) matrix $X$ of size $m \times m$ such that $\left\|AX -B\right\|_F$ is minimized, where $\|\cdot\|_F$ is the Frobenius norm. If $A^\top A$ is invertible, the least-square solution to this problem is $X_{\mathrm{ls}} = (A^\top A)^{-1} A^\top B$.
Let $\mathcal S_m$ be the space of symmetric positive semidefinite matrices of size $m\times m$. I am looking for a way to compute $$ X_{\mathrm{ls}}^{\mathrm{spd}} = \min_{X \in\mathcal S_m} \left\| AX - B \right\|_F, $$ i.e., the least-square solution on $\mathcal S_m$.
EDIT:
An idea could be writing $X = LL^\top$ and then minimizing over $L$. The problem in this case is that the loss function would be quartic in $L$. Of course, in practice we could just compute the gradient of $$\ell(L) = \|ALL^\top - B\|_F$$ with respect to $L$ and then run some gradient descent method. Something more elegant than this?