Sorry in advances for my lack of knowledge on this topic.
Given a $p$ by $p$ positive semidefinite matrix $S$ from which, I want to compute this algorithm
for (i in 1:p){
for (j in 1:p){
Target[i,j] = S[i,j]*S[j,i]+S[i,i]*S[j,j]
}
}
is there a better efficient way using matrix algebra?
In terms of the Hadamard product, we could write $$ T = S \circ S^T + \operatorname{diag}(S)\operatorname{diag}(S)^T, $$ where $\operatorname{diag}(S)$ is the column-vector $(S_{1,1},\dots,S_{p,p})$.