Registered Member
|
Hi all,
I am working with some code which uses Eigen heavily. For the most part it makes sense however there are a couple complex lines which I am having trouble with. 1) The first is working with a 2 dimensional matrix of reals:
My question is: what is the underlying algo? is it?:
or something else? 2) The Second is working with the same matrix but uses the block funtion... this one I understand even less and have spent a fair amount of time staring at (along with http://eigen.tuxfamily.org/api/classEigen_1_1Block.html) I still dont get it.
Again what is the underlying psuedo-algo to this? Any help is much appreciated. Thanks in advance. -Chad |
Moderator
|
Yes this is it. Here the ".cwise()" mean that the following operation have to be performed coefficient wise. This concerns all operations for which the behavior could be confusing. For instance the following: M = M + 2; will most likely be interpreted as "add 2 to each coefficients" by a computer scientist, and as "A = M + 2 * Indentity" for a mathematician. So, even though "M = M.cwise() + 2" might look cumbersome, at least it is very explicit. Note that in practice the generated loops are different: the two expressions are evaluated one after the other, and for each such an expression we detect that the coefficients are sequentially stored in memory and so we generate only a single for loop which is also explicitly vectorized when possible, etc. Of course, the evaluation of "1/log(10)" is moved out of the loop. Also note that these two expressions can be written as a single one. That should be more efficient.
Oh here it seems that _anotherTwoDimRealMat is actually a vector of matrices. So "_anotherTwoDimRealMat[i].col(0)" represents the first column of the i-th matrix stored in _anotherTwoDimRealMat. The left hand side of the dot product is indeed a bit more tricky to understand because it would have been simpler to write it like this:
Here you take the j-th row of _oneDimRealMat, and then pick the _anotherTwoDimRealMat[i].rows() coefficients starting from the position given by _anotherOneDimRealMat(i,0). In the original code, the .block() function returns exactly the same part of the _oneDimRealMat matrix, but since .block() returns a matrix, they had to add .row(0) to tell Eigen that's actually a vector expression. This is because the dot product function expect vectors, not matrices. If your still unsure, here is the equivalent algo for the compuation of _realMat(j, i):
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]