## Computing symmetric matrices

kde-blabla
Registered Member
Posts
4
Karma
0

### Computing symmetric matrices

Sun Sep 08, 2013 10:30 pm
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)?
jitseniesen
Registered Member
Posts
204
Karma
2

### Re: Computing symmetric matrices

Mon Sep 09, 2013 7:06 am
No, not automatically. You need to specify this yourself. The .rankUpdate() member function performs the computation A = A + b * b' on the upper or lower triangular part of A (here, b' is the transpose of b, which is I assume the notation you use). So you can do:
Code: Select all
`A.triangularView<Lower>().setZero(); // set lower triangular part of A to zeroA.selfadjointView<Lower>().rankUpdate(b); // compute b * b' and put in lower triangular partA.triangularView<StrictlyUpper>() = A.triangularView<StrictlyLower>().transpose(); // reflect lower triangular part in upper triangular part`
Depending on your application, the last line might not be necessary
kde-blabla
Registered Member
Posts
4
Karma
0

### Re: Computing symmetric matrices

Mon Sep 09, 2013 3:48 pm
jitseniesen wrote:No, not automatically. You need to specify this yourself. The .rankUpdate() member function performs the computation A = A + b * b' on the upper or lower triangular part of A (here, b' is the transpose of b, which is I assume the notation you use). So you can do:
Code: Select all
`A.triangularView<Lower>().setZero(); // set lower triangular part of A to zeroA.selfadjointView<Lower>().rankUpdate(b); // compute b * b' and put in lower triangular partA.triangularView<StrictlyUpper>() = A.triangularView<StrictlyLower>().transpose(); // reflect lower triangular part in upper triangular part`
Depending on your application, the last line might not be necessary

Thanks, that's exactly what I was looking for.

Do you have any indication of the speed differences between this method and the ordinary A = b * b' ?
ggael
Moderator
Posts
2689
Karma
16
OS

### Re: Computing symmetric matrices

Tue Sep 10, 2013 8:11 am
You can expect a x2 for large matrices (>1000^2) and no speed up for small ones (around 30^2). Also, the rankUpdate version is not multi-threaded, so even for large matrices it can be slower if you enabled OpenMP.

## Who is online

Registered users: ABravo, Baidu [Spider], Bing [Bot], davidemme, Exabot [Bot], Fabian L., Google [Bot], google01103, jdh8, jmacleod, joaob, koriun, Majestic-12 [Bot], Mamarok, metzman, mmolch, nylnook, pedrorodriguez, rv8ter, smankowski, TheraHedwig, weaktransform, wolfi323, Xiceph, Yahoo [Bot]