We would like to have a function similar to torch.matmul() in order to compute the product of a symmetric n x n matrix and a 1 dimensional vector of size n. This function should exploit the symmetry of the input matrix and we need it fast because we are calling it many times.
Hi Filippo!
A normal (that is, non-symmetric) n x n matrix, A_nn, contains n^2 distinct elements
and multiplying it against a length-n vector, A_nn @ v_n requires n^2 distinct scalar
multiplications.
A symmetric n x n matrix, S_nn, contains only n * (n + 1) / 2 distinct elements.
Nonetheless, computing S_nn @ v_n still requires n^2 distinct multiplications. For
this reason, you can’t exploit the symmetry of S_nn to speed up the computation of
the matrix-vector product.
This is hinted at in the comments to your stackoverflow cross-posting.
(You can save on storage by storing just the distinct elements of S_nn rather than
storing the full matrix in the form of A_nn where A_ij = A_ji. Depending on how
you store S_nn you may want a specialized routine that knows your storage scheme
or endure the cost of converting S_nn to its full A_nn form.)
Best.
K. Frank
Thank you very much!