mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Starting Eigen 2 development. The current plan is to use the last
release of tvmet (inactive for 2 years and developer unreachable) as the basis for eigen2, because it provides seemingly good expression template mechanisms, we want that, and it would take years to reinvent that wheel. We'll see. So this commit imports the last tvmet release.
This commit is contained in:
44
tvmet-1.7.1/examples/aliasing.cc
Normal file
44
tvmet-1.7.1/examples/aliasing.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* $Id: aliasing.cc,v 1.2 2004/03/26 07:58:06 opetzold Exp $
|
||||
*
|
||||
* This example shows the problem with aliasing mentioned at
|
||||
* http://tvmet.sourceforge.net/notes.html#alias
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <tvmet/Matrix.h>
|
||||
#include <tvmet/util/Incrementor.h>
|
||||
|
||||
using std::cout; using std::endl;
|
||||
using namespace tvmet;
|
||||
|
||||
typedef Matrix<double,3,3> matrix_type;
|
||||
|
||||
int main()
|
||||
{
|
||||
matrix_type A, B;
|
||||
matrix_type C;
|
||||
|
||||
std::generate(A.begin(), A.end(),
|
||||
tvmet::util::Incrementor<matrix_type::value_type>());
|
||||
std::generate(B.begin(), B.end(),
|
||||
tvmet::util::Incrementor<matrix_type::value_type>());
|
||||
|
||||
cout << "A = " << A << endl;
|
||||
cout << "B = " << B << endl;
|
||||
|
||||
// matrix prod without aliasing
|
||||
C = A * B;
|
||||
cout << "C = A * B = " << C << endl;
|
||||
|
||||
// work around for aliasing
|
||||
matrix_type temp_A(A);
|
||||
A = temp_A * B;
|
||||
cout << "matrix_type temp_A(A);\n"
|
||||
<< "A = temp_A * B = " << A << endl;
|
||||
|
||||
// this shows the aliasing problem
|
||||
A = A * B;
|
||||
cout << "A = A * B = " << A << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user