0
$\begingroup$

I want to compute a symmetric matrix A from a vector b by: A = b * b'.

Does the Eigen library automatically take into account that it does not need to do all calculations to get A (because of the symmetry which repeats most of the matrix entries)?

If not, I could take advantage of the symmetry and write my own function for the computation.

$\endgroup$
  • $\begingroup$ What do you need $A$ for? If $b$ is a slim matrix and you want to use $A$ it in an iterative algorithm, you will be more efficient by writing a function that for a given vector $v$ computes $Av = b*(b'*v)$. $\endgroup$ – Jan Sep 9 '13 at 10:18
  • $\begingroup$ A is needed in a generalized eigenvalue problem - so yes, I do need all the entries. $\endgroup$ – Armin Meisterhirn Sep 9 '13 at 13:09
  • 3
    $\begingroup$ If your generalized eigenvalue problem solver wants a matrix with all of the entries, then I wouldn't worry about the speed of constructing this outer product matrix. I have to imagine that the time required to solve the generalized ev problem will dwarf the time required to make this outer product. $\endgroup$ – k20 Sep 9 '13 at 13:46
  • $\begingroup$ Why not solve the generalized eigenvalue problem with a Krylov or Davidson method that would allow you to exploit the efficient computation of Av? $\endgroup$ – Jeff Sep 11 '13 at 17:15
  • $\begingroup$ Thanks for the input, Jeff. I'll have a look at these methods. $\endgroup$ – Armin Meisterhirn Sep 20 '13 at 19:02
2
$\begingroup$

This is a typical case where it does not make sense to actually store the matrix. Rather, consider the matrix to be an operator where

  • if you need to multiply by it, i.e., form $y=Ax$, you do $y=b (b\cdot x)$ instead

  • if you need to access an element $A_{ij}$, you instead compute it as $b_ib_j$.

In other words, knowing what $A$ is, you should just not store it as a matrix but simply as a single vector. You can't expect libraries to do these things for you, but you should do it yourself.

$\endgroup$
  • $\begingroup$ This matrix is needed in a generalized eigenvalue problem - so yes, I do need all the entries. $\endgroup$ – Armin Meisterhirn Sep 9 '13 at 13:09
  • 1
    $\begingroup$ But what I'm saying is that you need the matrix, but you may not need to store every element of it. You can compute the elements on the fly, and you can multiply with the matrix, without actually storing all $n\times n$ elements. $\endgroup$ – Wolfgang Bangerth Sep 9 '13 at 13:52
  • 1
    $\begingroup$ @WolfgangBangerth In theory this is true, but which software packages will deal with this? If you use something like LAPACK for the generalized eigenvalue solver, then it will not let you represent matrices in such a clever way, right? $\endgroup$ – k20 Sep 9 '13 at 13:58
  • $\begingroup$ Yes, k20. That's exactly what I'm using. Maybe it's useful to store it like WolfgangBangerth describes if you write your own generalized eigenvalue solver (which is a lot of work). $\endgroup$ – Armin Meisterhirn Sep 9 '13 at 15:45
  • 1
    $\begingroup$ PETSc and its eigenvalue solver SLEPc allow you to pass in operators as opposed to matrices. You can represent your outer-product matrix as an operator, and SLEPc will be able to give you eigenvalues for it. It's true that LAPACK doesn't. I don't know about Eigen. $\endgroup$ – Wolfgang Bangerth Sep 10 '13 at 4:02
0
$\begingroup$

The Eigen library cannot "know" a priori if the product b*b' will result in a symmetric matrix, therefore you can write your own method (although it'll be somewhat useless if not working with large matrices)

However, a routine called isSymmetric, is used within some linear solvers to check whether the input matrix is symmetric or not, but of course, that does not fulfill your need.

$\endgroup$
  • 1
    $\begingroup$ But you can tell it do so by using views, for example, the triangularView. $\endgroup$ – Armin Meisterhirn Sep 9 '13 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.