Eigen Version: 3.3.4
This semester I am taking a course where all programming assignments are in C++ using the library Eigen1. For some reason I keep looking up methods to extract a certain part from a matrix or a vector. The library calls these block operations and has a dedicated documentation page on the topic2. If you prefer something shorter or just want a list of documentation links, here is a short overview of the ones that got me up and running:
A.row(i)3: Returns the
i-th row as vector.
A.col(i)4: Returns the
i-th column as vector.
A.diagonal()5: Returns the diagonal as a vector.
A.diagonal(k): Given a positive number
kthis returns the
k-th diagonal above the main one, also called the
k-th super diagonal. The same thing works with negative numbers for sub diagonals which are below the main one.
A.block(i,j,m,n)6: Returns a matrix containing the block of
ncolumns whose upper left corner is at
A.bottomRows(n)7: Returns a matrix containing the last
A.topRows(n)8: Returns a matrix containing the first
A.leftCols(n)9: Returns a matrix containing the leftmost
A.rightCols(n)10: Returns a matrix containing the rightmost
v.segment(i,n)11: Returns a vector containing the part of length
nstarting from index
v.head(n)12: Returns a vector containing the first
v.tail(n)13: Returns a vector containing the last
v.asDiagonal()14: Returns a diagonal matrix whose diagonal is set to
As you can see, almost all of these boil down to special cases of
However, the Eigen documentation says that the most specific method available will have the most potential for optimizations.
In addition to that more specific methods also make more readable code.
I hope this either helps someone find a method they need or at least help me finally memorize them!