Search code examples
c++eigen

eigen: how to only compute the lower/upper part in the matrix inner product


I need to compute formula like "A'*A" using Eigen where A is an m by n matrix. The intuitive way to do this is,

result = A.transpose()*A;

But since the result is symmetric, is it possible to only compute the lower or upper part of result?


Solution

  • Yes, using selfadjointView and rankUpdate:

    result.setZero();
    result.selfadjointView<Lower>().rankUpdate(A.transpose());
    

    This will only update the lower part of result.