alpha 3.1. in this commit:

- finally get the Eval stuff right. get back to having Eval as
  a subclass of Matrix with limited functionality, and then,
  add a typedef MatrixType to get the actual matrix type.
- add swap(), findBiggestCoeff()
- bugfix by Ramon in Transpose
- new demo: doc/echelon.cpp
This commit is contained in:
Benoit Jacob
2008-01-15 13:55:47 +00:00
parent 9c9a42cc49
commit c67e717404
32 changed files with 262 additions and 94 deletions

View File

@@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = Eigen
PROJECT_NUMBER = 2.0-alpha3
PROJECT_NUMBER = 2.0-alpha3.1
OUTPUT_DIRECTORY = ${CMAKE_BINARY_DIR}/doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English

View File

@@ -73,7 +73,7 @@ If you want to stay informed of Eigen news and releases, please subscribe to our
<a name="download"></a>
<h2>Download</h2>
The source code of the latest release is here: <a href="http://download.tuxfamily.org/eigen/eigen-2.0-alpha3.tar.gz">eigen-2.0-alpha3.tar.gz</a><br/>
The source code of the latest release is here: <a href="http://download.tuxfamily.org/eigen/eigen-2.0-alpha3.1.tar.gz">eigen-2.0-alpha3.1.tar.gz</a><br/>
Alternatively, you can checkout the development tree by anonymous svn, by doing:
<pre>svn co svn://anonsvn.kde.org/home/kde/branches/work/eigen2</pre>

71
doc/echelon.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include <Eigen/Core>
USING_PART_OF_NAMESPACE_EIGEN
namespace Eigen {
template<typename Scalar, typename Derived>
void echelon(MatrixBase<Scalar, Derived>& m)
{
const int N = std::min(m.rows(), m.cols());
for(int k = 0; k < N; k++)
{
int rowOfBiggest, colOfBiggest;
int cornerRows = m.rows()-k;
int cornerCols = m.cols()-k;
m.corner(BottomRight, cornerRows, cornerCols)
.findBiggestCoeff(&rowOfBiggest, &colOfBiggest);
m.row(k).swap(m.row(k+rowOfBiggest));
m.col(k).swap(m.col(k+colOfBiggest));
for(int r = k+1; r < m.rows(); r++)
m.row(r).end(cornerCols) -= m.row(k).end(cornerCols) * m(r,k) / m(k,k);
}
}
template<typename Scalar, typename Derived>
void doSomeRankPreservingOperations(MatrixBase<Scalar, Derived>& m)
{
for(int a = 0; a < 3*(m.rows()+m.cols()); a++)
{
double d = Eigen::random<double>(-1,1);
int i = Eigen::random<int>(0,m.rows()-1); // i is a random row number
int j;
do {
j = Eigen::random<int>(0,m.rows()-1);
} while (i==j); // j is another one (must be different)
m.row(i) += d * m.row(j);
i = Eigen::random<int>(0,m.cols()-1); // i is a random column number
do {
j = Eigen::random<int>(0,m.cols()-1);
} while (i==j); // j is another one (must be different)
m.col(i) += d * m.col(j);
}
}
} // namespace Eigen
using namespace std;
int main(int, char **)
{
srand((unsigned int)time(0));
const int Rows = 6, Cols = 4;
typedef Matrix<double, Rows, Cols> Mat;
const int N = Rows < Cols ? Rows : Cols;
// start with a matrix m that's obviously of rank N-1
Mat m = Mat::identity(Rows, Cols); // args just in case of dyn. size
m.row(0) = m.row(1) = m.row(0) + m.row(1);
doSomeRankPreservingOperations(m);
// now m is still a matrix of rank N-1
cout << "Here's the matrix m:" << endl << m << endl;
cout << "Now let's echelon m:" << endl;
echelon(m);
cout << "Now m is:" << endl << m << endl;
}

View File

@@ -0,0 +1,13 @@
typedef Matrix3i MyMatrixType;
MyMatrixType m = MyMatrixType::random(3, 3);
cout << "Here's the matrix m:" << endl << m << endl;
typedef Eigen::Eval<Eigen::Row<MyMatrixType> >::MatrixType MyRowType;
// now MyRowType is just the same typedef as RowVector3i
MyRowType r = m.row(0);
cout << "Here's r:" << endl << r << endl;
typedef Eigen::Eval<Eigen::Block<MyMatrixType> >::MatrixType MyBlockType;
MyBlockType c = m.corner(Eigen::TopRight, 2, 2);
// now MyBlockType is a a matrix type where the number of rows and columns
// are dynamic, but know at compile-time to be <= 2. Therefore no dynamic memory
// allocation occurs.
cout << "Here's c:" << endl << c << endl;