many small fixes and documentation improvements,

this should be alpha5.
This commit is contained in:
Benoit Jacob 2008-05-29 03:12:30 +00:00
parent c1559d3079
commit 486fdb26a1
24 changed files with 165 additions and 169 deletions

View File

@ -497,7 +497,7 @@ inline const Block<Derived, CRows, CCols> MatrixBase<Derived>
* Example: \include MatrixBase_block_int_int.cpp
* Output: \verbinclude MatrixBase_block_int_int.out
*
* \note since block is a templated member, the keyword template as to be used
* \note since block is a templated member, the keyword template has to be used
* if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode
*
* \sa class Block, block(int,int,int,int)

View File

@ -113,6 +113,7 @@ inline typename MatrixBase<Derived>::CommaInitializer MatrixBase<Derived>::opera
return CommaInitializer(*static_cast<Derived*>(this), s);
}
/** \sa operator<<(const Scalar&) */
template<typename Derived>
template<typename OtherDerived>
inline typename MatrixBase<Derived>::CommaInitializer

View File

@ -218,7 +218,7 @@ MatrixBase<Derived>::constant(const Scalar& value)
}
template<typename Derived>
bool MatrixBase<Derived>::isEqualToConstant
bool MatrixBase<Derived>::isApproxToConstant
(const Scalar& value, typename NumTraits<Scalar>::Real prec) const
{
for(int j = 0; j < cols(); j++)
@ -408,7 +408,7 @@ template<typename Derived>
bool MatrixBase<Derived>::isOnes
(typename NumTraits<Scalar>::Real prec) const
{
return isEqualToConstant(Scalar(1), prec);
return isApproxToConstant(Scalar(1), prec);
}
/** Sets all coefficients in this expression to one.

View File

@ -93,7 +93,13 @@ template<typename MatrixType, unsigned int Mode> class Extract
/** \returns an expression of a triangular matrix extracted from the current matrix
*
* \sa part(), marked()
* The parameter \a Mode can have the following values: \c Upper, \c StrictlyUpper, \c UnitUpper,
* \c Lower, \c StrictlyLower, \c UnitLower.
*
* Example: \include MatrixBase_extract.cpp
* Output: \verbinclude MatrixBase_extract.out
*
* \sa class Extract, part(), marked()
*/
template<typename Derived>
template<unsigned int Mode>

View File

@ -101,6 +101,11 @@ template<typename ExpressionType, unsigned int Added, unsigned int Removed> clas
};
/** \returns an expression of *this with added flags
*
* Example: \include MatrixBase_marked.cpp
* Output: \verbinclude MatrixBase_marked.out
*
* \sa class Flagged, extract(), part()
*/
template<typename Derived>
template<unsigned int Added>
@ -112,6 +117,11 @@ MatrixBase<Derived>::marked() const
/** \returns an expression of *this with the following flags removed:
* EvalBeforeNestingBit and EvalBeforeAssigningBit.
*
* Example: \include MatrixBase_lazy.cpp
* Output: \verbinclude MatrixBase_lazy.out
*
* \sa class Flagged, marked()
*/
template<typename Derived>
inline const Flagged<Derived, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>

View File

@ -25,11 +25,19 @@
#ifndef EIGEN_INVERSEPRODUCT_H
#define EIGEN_INVERSEPRODUCT_H
/** \returns the product of the inverse of *this with \a other.
/** \returns the product of the inverse of \c *this with \a other.
*
* This function computes the inverse-matrix matrix product inverse(*this) * \a other
* It works as a forward (resp. backward) substitution if *this is an upper (resp. lower)
* This function computes the inverse-matrix matrix product inverse(\c*this) * \a other
* It works as a forward (resp. backward) substitution if \c *this is an upper (resp. lower)
* triangular matrix.
*
* It is required that \c *this be marked as either an upper or a lower triangular matrix, as
* can be done by marked(), and as is automatically the case with expressions such as those returned
* by extract().
* Example: \include MatrixBase_marked.cpp
* Output: \verbinclude MatrixBase_marked.out
*
* \sa marked(), extract()
*/
template<typename Derived>
template<typename OtherDerived>

View File

@ -136,10 +136,10 @@ template<typename Derived> class MatrixBase
CoeffReadCost = ei_traits<Derived>::CoeffReadCost
};
/** Default constructor. Just checks at compile-time for self-consistency of the flags. */
MatrixBase()
{
assert(!( (Flags&UnitDiagBit && Flags&ZeroDiagBit)
|| (Flags&UpperTriangularBit && Flags&LowerTriangularBit) ));
ei_assert(ei_are_flags_consistent<Flags>::ret);
}
/** This is the "real scalar" type; if the \a Scalar type is already real numbers
@ -170,7 +170,7 @@ template<typename Derived> class MatrixBase
inline bool isVector() const { return rows()==1 || cols()==1; }
//@}
/// \name Default return types
/// \internal \name Default return types
//@{
/** Represents a constant matrix */
typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType;
@ -289,7 +289,6 @@ template<typename Derived> class MatrixBase
template<typename OtherDerived>
typename OtherDerived::Eval inverseProduct(const MatrixBase<OtherDerived>& other) const;
//@}
/** \name Dot product and related notions
@ -420,7 +419,7 @@ template<typename Derived> class MatrixBase
bool isMuchSmallerThan(const MatrixBase<OtherDerived>& other,
RealScalar prec = precision<Scalar>()) const;
bool isEqualToConstant(const Scalar& value, RealScalar prec = precision<Scalar>()) const;
bool isApproxToConstant(const Scalar& value, RealScalar prec = precision<Scalar>()) const;
bool isZero(RealScalar prec = precision<Scalar>()) const;
bool isOnes(RealScalar prec = precision<Scalar>()) const;
bool isIdentity(RealScalar prec = precision<Scalar>()) const;

View File

@ -26,33 +26,67 @@
#ifndef EIGEN_PART_H
#define EIGEN_PART_H
/** \class Part
*
* \brief Pseudo-expression allowing to write to a special part of a matrix
*
* This lvalue-only pseudo-expression allows to perform special operations
* on a matrix, such as writing only to the upper (above diagonal) part.
*
* It is the return type of MatrixBase::part() and most of the time this is
* the only way that it is used.
*
* \sa class Extract, MatrixBase::part()
*/
template<typename MatrixType, unsigned int Mode>
class Part
{
public:
Part(MatrixType& matrix) : m_matrix(matrix) {}
Part(MatrixType& matrix);
/** \sa operator=(), MatrixBase::lazyAssign() */
template<typename Other> void lazyAssign(const Other& other);
/** \sa MatrixBase::operator=() */
template<typename Other> void operator=(const Other& other);
/** \sa MatrixBase::operator+=() */
template<typename Other> void operator+=(const Other& other);
/** \sa MatrixBase::operator-=() */
template<typename Other> void operator-=(const Other& other);
/** \sa MatrixBase::operator*=() */
void operator*=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa MatrixBase::operator/=() */
void operator/=(const typename ei_traits<MatrixType>::Scalar& other);
/** \sa MatrixBase::setConstant() */
void setConstant(const typename ei_traits<MatrixType>::Scalar& value);
/** \sa MatrixBase::setZero() */
void setZero();
/** \sa MatrixBase::setOnes() */
void setOnes();
/** \sa MatrixBase::setRandom() */
void setRandom();
/** \sa MatrixBase::setIdentity() */
void setIdentity();
private:
MatrixType& m_matrix;
};
template<typename MatrixType, unsigned int Mode>
inline Part<MatrixType, Mode>::Part(MatrixType& matrix)
: m_matrix(matrix)
{
ei_assert(ei_are_flags_consistent<Mode>::ret);
}
template<typename MatrixType, unsigned int Mode>
template<typename Other>
inline void Part<MatrixType, Mode>::operator=(const Other& other)
{
if(Other::Flags & EvalBeforeAssigningBit)
lazyAssign(other.eval());
{
typename ei_eval<Other>::type other_evaluated(other.rows(), other.cols());
other_evaluated.template part<Mode>().lazyAssign(other);
lazyAssign(other_evaluated);
}
else
lazyAssign(other.derived());
}
@ -210,6 +244,16 @@ inline void Part<MatrixType, Mode>::setRandom()
*this = MatrixType::random(m_matrix.rows(), m_matrix.cols());
}
/** \returns a lvalue pseudo-expression allowing to perform special operations on \c *this.
*
* The \a Mode parameter can have the following values: \c Upper, \c StrictlyUpper, \c Lower,
* \c StrictlyLower, \c SelfAdjoint.
*
* Example: \include MatrixBase_part.cpp
* Output: \verbinclude MatrixBase_part.out
*
* \sa class Part, MatrixBase::extract(), MatrixBase::marked()
*/
template<typename Derived>
template<unsigned int Mode>
inline Part<Derived, Mode> MatrixBase<Derived>::part()

View File

@ -135,6 +135,7 @@ typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
typedef typename Base::PacketScalar PacketScalar; \
typedef typename Eigen::ei_nested<Derived>::type Nested; \
typedef typename Eigen::ei_eval<Derived>::type Eval; \
typedef typename Eigen::Inverse<Eval> InverseType; \
enum { RowsAtCompileTime = Base::RowsAtCompileTime, \
ColsAtCompileTime = Base::ColsAtCompileTime, \
MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime, \

View File

@ -210,4 +210,11 @@ template<typename T, int n=1> struct ei_nested
>::ret type;
};
template<unsigned int Flags> struct ei_are_flags_consistent
{
enum { ret = !( (Flags&UnitDiagBit && Flags&ZeroDiagBit)
|| (Flags&UpperTriangularBit && Flags&LowerTriangularBit) )
};
};
#endif // EIGEN_META_H

View File

@ -1,4 +1,4 @@
o /** @mainpage Eigen
o /** \mainpage Eigen
<h3>If you see this page, then you have not properly generated the documentation. Namely, you have run doxygen from the source directory, which is not appropriate for generating the documentation of Eigen.</h3>
@ -14,6 +14,6 @@ In order to generate the documentation of Eigen, please follow these steps:
After doing that, you will find the HTML documentation in the doc/html/ subdirectory of the build directory.
<h2>Note however that the documentation is available online here:
<a href="http://eigen.tuxfamily.org/2">http://eigen.tuxfamily.org/2</a>
<a href="http://eigen.tuxfamily.org/wiki">http://eigen.tuxfamily.org/wiki</a>
*/

View File

@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = Eigen
PROJECT_NUMBER = 2.0-alpha4
PROJECT_NUMBER = 2.0-alpha5
OUTPUT_DIRECTORY = ${CMAKE_BINARY_DIR}/doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
@ -33,7 +33,7 @@ QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
SEPARATE_MEMBER_PAGES = YES
TAB_SIZE = 8
ALIASES = \
"only_for_vectors=This is only for vectors (either row-vectors or column-vectors), \

View File

@ -1,156 +1,13 @@
o /** @mainpage Eigen
o /** \mainpage Eigen
<h2>Table of contents</h2>
<a href="#overview">Overview</a><br/>
<a href="#license">License</a><br/>
<a href="#features">Features</a><br/>
<a href="#todo">To-do wiki</a><br/>
<a href="#compiler_support">Compiler Support</a><br/>
<a href="#news">News</a><br/>
<a href="#download">Download</a><br/>
<a href="#kde">Relation to KDE</a><br/>
<a href="#examples">Examples</a><br/>
<a href="#applications">Applications using Eigen</a><br/>
<a href="#credits">Credits</a><br/>
<a href="#contact">Contact us</a><br/>
<a href="#mailinglist">Mailing list</a><br/>
This is the API documentation for Eigen.
<a name="overview"></a>
<h2>Overview</h2>
Most of the API is available as methods in <a href="classEigen_1_1MatrixBase.html">MatrixBase</a>, so this is a good starting point for browsing. Also have a look at <a href="classEigen_1_1Matrix.html">Matrix</a>, as a few methods and the matrix constructors are there.
Eigen is a C++ template library for vector and matrix math, a.k.a. linear algebra. It aims to concile speed, ease of use, and completeness.
For a first contact with Eigen, it is enough to look at Matrix and MatrixBase. In fact, except for advanced use, the only class that you'll have to explicitly name in your program, i.e. of which you'll explicitly contruct objects, is Matrix. For instance, vectors are handled as a special case of Matrix with one column.
<a name="license"></a>
<h2>License</h2>
The many other classes are typically return types for MatrixBase methods.
Eigen is dual-licensed: it can be redistributed and/or modified, at your choice,
<ul>
<li> either under the <a href="http://www.gnu.org/copyleft/lgpl.html">LGPL</a>, version 3 or later,</li>
<li> or under the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>, version 2 or later.</li>
</ul>
Note that this is an OR, not an AND. You do not need to conform to both licenses, you just pick the one that you prefer. Typically, GPL projects will regard Eigen as GPL-licensed while non-GPL projects will regard Eigen as LGPL-licensed.
Short licensing FAQ:
<b>Question:</b> Why not just license under the LGPL, since anyway it is more liberal than the GPL?<br>
<b>Answer:</b> A library licensed under the LGPL3 cannot be used by a program licensed under the GPL2 (<a href="http://www.fsf.org/licensing/licenses/gpl-faq.html#AllCompatibility">see here for details</a>). Therefore, we offer the GPL2 as an alternative license choice for Eigen, in order to allow GPL2 programs to use it.
<b>Question:</b> Why require the LGPL version to be at least 3?<br>
<b>Answer:</b> Because up to version 2.1, the LGPL does not handle the case of C++ template libraries, where all the code is in headers. This problem was solved in version 3 of the LGPL.
<a name="features"></a>
<h2>Features</h2>
WARNING: this alpha release is NOT feature complete -- far from it! It contains only the Core module, while several other modules are planned.
Here are general features of Eigen and more specific features of the Core module:
<ul>
<li><a href="http://ubiety.uwaterloo.ca/~tveldhui/papers/Expression-Templates/exprtmpl.html">Expression templates</a> everywhere. This is an optimization (elimination of temporaries, lazy evaluation), but more importantly this allows for a much nicer API, especially as Eigen supports lvalue expressions. For example, the following is valid with Eigen and compiles to optimized code:
\code matrix.row(i) += factor * matrix.row(j); \endcode</li>
<li>Both fixed-size and dynamic-size objects are supported, with uniform API,
in a way that allows Eigen to make
all usual optimizations in the case of fixed size, such as loop unrolling. Moreover
special care is used to ensure that the fixed-size types never cause dynamic memory
allocations. Even when the dimensions of an expression at not known at compile-time,
if a fixed bound is known (e.g. when taking a block in a fixed-size matrix) then
Eigen uses it to allocate a static array instead of a dynamic one.</li>
<li>Both column-vectors and row-vectors are supported, as special cases of matrices.</li>
<li>The following scalar types are supported and well tested: \c int, \c float, \c double,
\c std::complex<float>, \c std::complex<double>. </li>
</ul>
<a name="todo"></a>
<h2>To-do wiki</h2>
The To-do wiki for Eigen is here: <a href="http://techbase.kde.org/index.php?title=Projects/Eigen/TODO">http://techbase.kde.org/index.php?title=Projects/Eigen/TODO</a>.
<a name="compiler_support"></a>
<h2>Compiler Support</h2>
Eigen is standard C++98 and so should theoretically be compatible with any compliant compiler. Of course, in practice, things might be slightly different. At least, Eigen is known to compile with any version of GCC from 3.3 to 4.3 as well as with recent versions of ICC.
Eigen is well tested with recent versions of GCC and ICC. Both GCC 4.2 and ICC give very good performance. ICC might provide even better performance when the auto-vectorization makes sense. For some reason the performance is not so great with GCC 4.1.
For best performance, we recommend the following compilation flags:
<ul>
<li>\b GCC: \c -O3 \c -DNDEBUG \c -finline-limit=1000 </li>
<li>\b ICC: \c -O3 \c -DNDEBUG \c -xT \c -ipo \c -no-prec-div \c -no-inline-max-size </li>
</ul>
<a name="news"></a>
<h2>News</h2>
If you want to stay informed of Eigen news and releases, please subscribe to our <a href="#mailinglist">mailing list</a>. You can also browse the <a href="http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/">archive</a>.
<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-alpha4.tar.gz">eigen-2.0-alpha4.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>
or view it online at this address:
<a href="http://websvn.kde.org/branches/work/eigen2">http://websvn.kde.org/branches/work/eigen2</a>
<a name="kde"></a>
<h2>Relation to KDE</h2>
First of all: Eigen doesn't have any dependency. In particular, it doesn't depend on any part of KDE or on Qt.<br/>
Eigen is part of the KDE project, in the sense that:
<ul>
<li>Its <a href="http://websvn.kde.org/trunk/kdesupport/eigen/">development tree</a> is hosted in the <a href="http://websvn.kde.org">KDE repository</a>.</li>
<li>It has been founded by, and is developed by KDE people.</li>
<li>It has originally been designed for the needs of KDE applications, especially <a href="http://edu.kde.org/kalzium">Kalzium</a>.</li>
</ul>
However, we quickly realized that Eigen could be useful for non-KDE projects, whence our decision to make sure that it has no dependency on KDE or Qt.
Although Eigen itself doesn't have any dependency, the unit-tests require Qt.
<a name="examples"></a>
<h2>Examples</h2>
There are a lot of small examples throughout the documentation. TODO: write more interesting,
standalone "demos".
<a name="applications"></a>
<h2>Applications using Eigen</h2>
TODO: update this section; make web links
Currently: Kalzium, Avogadro, KSpread(a bit), Krita(a bit), KGLLib<br>
Planned: much more use in KOffice 2.1, Step (if we make Eigen good enough!), OpenBabel (maybe)
Please tell us if you know of other interesting projects using Eigen!
<a name="credits"></a>
<h2>Credits</h2>
<ul>
<li>Benoit Jacob (jacob at math jussieu fr) : Main developer</li>
<li>Gael Guennebaud (gael guennebaud at gmail com) : Large contributions</li>
<li>Christian Mayer (mail at christianmayer de) : reviewed the source code, made many useful suggestions</li>
<li>Michael Olbrich (michael olbrich at gmx net) : initial loop-unrolling metaprogram</li>
<li>and thanks to everyone on the <a href="#mailinglist">mailing list</a> for your input!
</ul>
<a name="contact"></a>
<h2>Contact us</h2>
The best way to contact us is by means of our <a href="#mailinglist">mailing list</a>.<br/>
IRC Channel: \#eigen on Freenode.<br/>
Website (you're here): <a href="http://eigen.tuxfamily.org">http://eigen.tuxfamily.org</a><br/>
<a name="mailinglist"></a>
<h2>Mailing list</h2>
The Mailing list for Eigen is: eigen at lists tuxfamily org.<br/>
To subscribe, send a mail with subject "subscribe" to eigen-request at lists tuxfamily org.<br/>
To unsubscribe, send a mail with subject "unsubscribe" to eigen-request at lists tuxfamily org.<br/>
You can also browse the <a href="http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/">archive</a>.
This API documentation contains many short examples. For bigger examples, tutorials, and general explanations on Eigen, see the <a href="http://eigen.tuxfamily.org/wiki">wiki</a>.
*/

View File

@ -0,0 +1,8 @@
Matrix3i m = Matrix3i::random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the upper-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::Upper>() << endl;
cout << "Here is the strictly-upper-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::StrictlyUpper>() << endl;
cout << "Here is the unit-lower-triangular matrix extracted from m:" << endl
<< m.extract<Eigen::UnitLower>() << endl;

View File

@ -0,0 +1,7 @@
Matrix2d m = Matrix2d::random();
cout << "Here is the matrix m:" << endl << m << endl;
Matrix2d::InverseType m_inv = m.inverse();
if(m_inv.exists())
cout << "m is invertible, and its inverse is:" << endl << m_inv << endl;
else
cout << "m is not invertible." << endl;

View File

@ -0,0 +1,10 @@
Matrix2d m; m << 1,2,3,4;
Matrix2d n;
n = (m*m).lazy(); // if we did "n = m*m;" then m*m would first be evaluated into
// a temporary, because the Product expression has the EvalBeforeAssigningBit.
// This temporary would then be copied into n. Introducing this temporary is
// useless here and wastes time. Doing "n = (m*m).lazy();" evaluates m*m directly
// into n, which is faster. But, beware! This is only correct because m and n
// are two distinct matrices. Doing "m = (m*m).lazy();" would not produce the
// expected result.
cout << n << endl;

View File

@ -0,0 +1,9 @@
Matrix3d m = Matrix3d::zero();
m.part<Eigen::Upper>().setOnes();
cout << "Here is the matrix m:" << endl << m << endl;
Matrix3d n = Matrix3d::ones();
n.part<Eigen::Lower>() *= 2;
cout << "Here is the matrix n:" << endl << n << endl;
cout << "And now here is m.inverse()*n, taking advantage of the fact that"
" m is upper-triangular:" << endl
<< m.marked<Eigen::Upper>().inverseProduct(n);

View File

@ -0,0 +1,8 @@
Matrix3d m = Matrix3i::zero();
m.part<Eigen::StrictlyUpper>().setOnes();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "And let us now compute m*m.adjoint() in a very optimized way" << endl
<< "taking advantage of the symmetry." << endl;
Matrix3d n;
n.part<Eigen::SelfAdjoint>() = (m*m.adjoint()).lazy();
cout << "The result is:" << endl << n << endl;

View File

@ -0,0 +1,5 @@
Matrix4d m = Matrix4d::zero();
m.part<Eigen::Upper>().setOnes();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "We know for sure that it is invertible." << endl;
cout << "Here is its inverse:" << m.quickInverse() << endl;

View File

@ -0,0 +1,5 @@
RowVector4i v = RowVector4i::random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.end(2):" << endl << v.end<2>() << endl;
v.end<2>().setZero();
cout << "Now the vector v is:" << endl << v << endl;

View File

@ -0,0 +1,6 @@
Matrix4i m = Matrix4i::random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the bottom-right 2x3 corner in m:" << endl
<< m.corner<2,3>(Eigen::BottomRight) << endl;
m.corner<2,3>(Eigen::BottomRight).setZero();
cout << "Now the matrix m is:" << endl << m << endl;

View File

@ -0,0 +1,5 @@
RowVector4i v = RowVector4i::random();
cout << "Here is the vector v:" << endl << v << endl;
cout << "Here is v.start(2):" << endl << v.start<2>() << endl;
v.start<2>().setZero();
cout << "Now the vector v is:" << endl << v << endl;

View File

@ -1,4 +1,5 @@
#include <Eigen/Core>
#include <Eigen/LU>
USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
int main(int, char**)

View File

@ -50,8 +50,7 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
v2 = VectorType::random(rows),
vzero = VectorType::zero(rows);
Scalar s1 = ei_random<Scalar>(),
s2 = ei_random<Scalar>();
Scalar s1 = ei_random<Scalar>();
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);