[eigen] Eigen2 initial commit |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: [eigen] Eigen2 initial commit*From*: Benoît Jacob <jacob@xxxxxxxxxxxxxxx>*Date*: Wed, 5 Sep 2007 13:58:37 +0200

Hi List, I've made committed Eigen2 at /branches/work/eigen2. Here is the anonymous SVN command to check it out: svn co svn://anonsvn.kde.org/home/kde/branches/work/eigen2 (Hope I got it right, can't check right now because I'm behind a firewall). You can use the headers from the src directory without installing if you want to. I attach to this e-mail a tutorial that I wrote (tutorial.cpp). If you use headers from src/ without installing them, then you'll have to edit the #include line. As I said, I've restared Eigen2 from scratch on Sunday, and there's no TVMET code remaining. But of course the expression templates are largely inspired from TVMET, which itself was inspired by articles by Todd, the Blitz++ guy and (co-)inventor of expression templates. In the test/ directory, there a basic unit-tests which only check compilation and asserts. There is currently no check done on the actual results. This is because I haven't yet ported the fuzzy comparison functions from Eigen1. Many things are missing. The only operators defined are + - *. Another thing: don't benchmark it now. The loops are not yet unrolled, and (as a result of that) many functions are not inlined. So performance is bad. Don't worry about that. Enjoy, Benoit

#include<eigen2/All.h> using namespace std; using namespace Eigen; int main(int argc, char **argv) { Matrix<double,2,2> m; // 2x2 fixed-size matrix with uninitialized entries m(0,0) = 1; m(0,1) = 2; m(1,0) = 3; m(1,1) = 4; cout << "Here is a 2x2 matrix m:" << endl << m << endl; cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl; MatrixX<double> m2(4, 4); // dynamic matrix with initial size 4x4 and uninitialized entries // notice how we are mixing fixed-size and dynamic-size types. cout << "In the top-left block, we put the matrix m shown above." << endl; // here we need to use .xpr() to allow write access to the block. m2.xpr().block(0,1,0,1) = m; cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl; m2.xpr().block(2,3,0,1) = m * m; cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl; m2.xpr().block(0,1,2,3) = m + m; cout << "In the bottom-right block, we put the matrix m-m, which is:" << endl << m-m << endl; m2.xpr().block(2,3,2,3) = m - m; cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl; // here we don't need to use .xpr() because we only need read access. cout << "The central 2x2 block of m2 is:" << endl << m2.block(1,2,1,2) << endl; cout << "Row 0 of m2, written as a column vector, is:" << endl << m2.row(0) << endl; cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl; cout << "The matrix m2 with row 0 and column 1 removed is:" << endl << m2.minor(0,1) << endl; cout << endl << "Now let us study a tricky issue." << endl; cout << "Recall that the matrix product m*m is:" << endl << m*m << endl; cout << "We want to store that into m, i.e. do \"m = m * m;\"" << endl; cout << "Here we must be very careful. For if we do \"m = m * m;\"," << endl << "the matrix m becomes" << endl; Matrix<double,2,2> m_save = m; m = m * m; // the bogus operation cout << m << "," << endl; cout << "which is not what was wanted!" << endl << "Explanation: because of the way expression templates work, the matrix m gets" << endl << "overwritten _while_ the matrix product m * m is being computed." << endl << "This is the counterpart of eliminating temporary objects!" << endl << "Anyway, if you want to store m * m into m, you can do this:" << endl << " m << m * m;" << endl; m = m_save; m << m * m; cout << "And m is now:" << endl << m << endl << "as was expected." << endl; return 0; }

**Attachment:
signature.asc**

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] two decisions to take** - Next by Date:
**[eigen]** - Previous by thread:
**Re: [eigen] two decisions to take** - Next by thread:
**[eigen]**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |