* Eigen compiles with any GCC versions from, at least, 3.3 without the previous ugly hack :)

* Renamed the scalar functors with the "Scalar" prefix (instead of "Cwise")
This commit is contained in:
Gael Guennebaud 2008-03-04 12:34:58 +00:00
parent 46885d33bf
commit f65cca5d1d
23 changed files with 248 additions and 240 deletions

View File

@ -4,14 +4,6 @@
#include <cassert>
#include <iostream>
#if ((defined __GNUC__) && ( (__GNUC__==3) || (__GNUC__==4) && __GNUC_MINOR__==0))
/* This very ugly hack to fix a bug of gcc <4.1 with the Curiously recurring template pattern and friend class.
Note that gcc-4.0.1 is still the default compiler on MACOSX Leopard.
*/
#define private public
#warning "Your compiler (gcc<4.1) has issue with friend and CRT, all private members of Eigen's classes are made public"
#endif
namespace Eigen {
#include "src/Core/Util.h"
@ -50,6 +42,3 @@ namespace Eigen {
} // namespace Eigen
#if ((defined __GNUC__) && (__GNUC_MINOR__==0))
#undef private
#endif

View File

@ -65,6 +65,7 @@ template<typename MatrixType,
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Block>;
friend class MatrixBase<Scalar, Block>::Traits;
typedef MatrixBase<Scalar, Block> Base;
/** Fixed-size constructor

View File

@ -52,6 +52,7 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
typedef NewScalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Cast>;
friend class MatrixBase<Scalar, Cast>::Traits;
typedef MatrixBase<Scalar, Cast> Base;
Cast(const MatRef& matrix) : m_matrix(matrix) {}

View File

@ -52,6 +52,7 @@ template<typename MatrixType> class Column
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Column>;
friend class MatrixBase<Scalar, Column>::Traits;
typedef MatrixBase<Scalar, Column> Base;
Column(const MatRef& matrix, int col)

View File

@ -44,7 +44,7 @@
* Here is an example illustrating this:
* \include class_CwiseBinaryOp.cpp
*
* \sa class CwiseProductOp, class CwiseQuotientOp
* \sa class ScalarProductOp, class ScalarQuotientOp
*/
template<typename BinaryOp, typename Lhs, typename Rhs>
class CwiseBinaryOp : NoOperatorEquals,
@ -55,6 +55,7 @@ class CwiseBinaryOp : NoOperatorEquals,
typedef typename Lhs::Ref LhsRef;
typedef typename Rhs::Ref RhsRef;
friend class MatrixBase<Scalar, CwiseBinaryOp>;
friend class MatrixBase<Scalar, CwiseBinaryOp>::Traits;
typedef MatrixBase<Scalar, CwiseBinaryOp> Base;
CwiseBinaryOp(const LhsRef& lhs, const RhsRef& rhs)
@ -105,7 +106,7 @@ struct CwiseDifferenceOp {
*
* \sa class CwiseBinaryOp, MatrixBase::cwiseProduct()
*/
struct CwiseProductOp {
struct ScalarProductOp {
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a * b; }
};
@ -113,7 +114,7 @@ struct CwiseProductOp {
*
* \sa class CwiseBinaryOp, MatrixBase::cwiseQuotient()
*/
struct CwiseQuotientOp {
struct ScalarQuotientOp {
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a / b; }
};
@ -175,10 +176,10 @@ MatrixBase<Scalar, Derived>::operator+=(const MatrixBase<Scalar, OtherDerived>&
*/
template<typename Scalar, typename Derived>
template<typename OtherDerived>
const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived>
const CwiseBinaryOp<ScalarProductOp, Derived, OtherDerived>
MatrixBase<Scalar, Derived>::cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const
{
return CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived>(ref(), other.ref());
return CwiseBinaryOp<ScalarProductOp, Derived, OtherDerived>(ref(), other.ref());
}
@ -188,10 +189,10 @@ MatrixBase<Scalar, Derived>::cwiseProduct(const MatrixBase<Scalar, OtherDerived>
*/
template<typename Scalar, typename Derived>
template<typename OtherDerived>
const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived>
const CwiseBinaryOp<ScalarQuotientOp, Derived, OtherDerived>
MatrixBase<Scalar, Derived>::cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const
{
return CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived>(ref(), other.ref());
return CwiseBinaryOp<ScalarQuotientOp, Derived, OtherDerived>(ref(), other.ref());
}
@ -220,7 +221,7 @@ cwise(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived
* the keyword template as to be used if the matrix type is also a template parameter:
* \code
* template <typename MatrixType> void foo(const MatrixType& m1, const MatrixType& m2) {
* m1.template cwise<CwiseProductOp>(m2);
* m1.template cwise<ScalarProductOp>(m2);
* }
* \endcode
*

View File

@ -47,6 +47,7 @@ class CwiseUnaryOp : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, CwiseUnaryOp>;
friend class MatrixBase<Scalar, CwiseUnaryOp>::Traits;
typedef MatrixBase<Scalar, CwiseUnaryOp> Base;
CwiseUnaryOp(const MatRef& mat) : m_matrix(mat) {}
@ -76,7 +77,7 @@ class CwiseUnaryOp : NoOperatorEquals,
*
* \sa class CwiseUnaryOp, MatrixBase::operator-
*/
struct CwiseOppositeOp {
struct ScalarOppositeOp {
template<typename Scalar> static Scalar op(const Scalar& a) { return -a; }
};
@ -84,7 +85,7 @@ struct CwiseOppositeOp {
*
* \sa class CwiseUnaryOp, MatrixBase::cwiseAbs
*/
struct CwiseAbsOp {
struct ScalarAbsOp {
template<typename Scalar> static Scalar op(const Scalar& a) { return ei_abs(a); }
};
@ -92,19 +93,19 @@ struct CwiseAbsOp {
/** \returns an expression of the opposite of \c *this
*/
template<typename Scalar, typename Derived>
const CwiseUnaryOp<CwiseOppositeOp,Derived>
const CwiseUnaryOp<ScalarOppositeOp,Derived>
MatrixBase<Scalar, Derived>::operator-() const
{
return CwiseUnaryOp<CwiseOppositeOp,Derived>(ref());
return CwiseUnaryOp<ScalarOppositeOp,Derived>(ref());
}
/** \returns an expression of the opposite of \c *this
*/
template<typename Scalar, typename Derived>
const CwiseUnaryOp<CwiseAbsOp,Derived>
const CwiseUnaryOp<ScalarAbsOp,Derived>
MatrixBase<Scalar, Derived>::cwiseAbs() const
{
return CwiseUnaryOp<CwiseAbsOp,Derived>(ref());
return CwiseUnaryOp<ScalarAbsOp,Derived>(ref());
}
@ -133,7 +134,7 @@ cwise(const MatrixBase<Scalar, Derived> &mat)
* the keyword template as to be used if the matrix type is also a template parameter:
* \code
* template <typename MatrixType> void foo(const MatrixType& m) {
* m.template cwise<CwiseAbsOp>();
* m.template cwise<ScalarAbsOp>();
* }
* \endcode
*
@ -152,7 +153,7 @@ MatrixBase<Scalar, Derived>::cwise() const
*
* \sa class CwiseUnaryOp, MatrixBase::conjugate()
*/
struct ConjugateOp {
struct ScalarConjugateOp {
template<typename Scalar> static Scalar op(const Scalar& a) { return ei_conj(a); }
};
@ -160,10 +161,10 @@ struct ConjugateOp {
*
* \sa adjoint(), class Conjugate */
template<typename Scalar, typename Derived>
const CwiseUnaryOp<ConjugateOp, Derived>
const CwiseUnaryOp<ScalarConjugateOp, Derived>
MatrixBase<Scalar, Derived>::conjugate() const
{
return CwiseUnaryOp<ConjugateOp, Derived>(ref());
return CwiseUnaryOp<ScalarConjugateOp, Derived>(ref());
}

View File

@ -44,6 +44,7 @@ template<typename MatrixType> class DiagonalCoeffs
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, DiagonalCoeffs>;
friend class MatrixBase<Scalar, DiagonalCoeffs>::Traits;
typedef MatrixBase<Scalar, DiagonalCoeffs> Base;
DiagonalCoeffs(const MatRef& matrix) : m_matrix(matrix) {}

View File

@ -47,6 +47,7 @@ class DiagonalMatrix : NoOperatorEquals,
typedef typename CoeffsVectorType::Scalar Scalar;
typedef typename CoeffsVectorType::Ref CoeffsVecRef;
friend class MatrixBase<Scalar, DiagonalMatrix>;
friend class MatrixBase<Scalar, DiagonalMatrix>::Traits;
typedef MatrixBase<Scalar, DiagonalMatrix> Base;
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)

View File

@ -35,12 +35,7 @@ template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> clas
template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate;
template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp;
struct CwiseProductOp;
struct CwiseQuotientOp;
template<typename UnaryOp, typename MatrixType> class CwiseUnaryOp;
struct CwiseOppositeOp;
struct ConjugateOp;
struct CwiseAbsOp;
template<typename Lhs, typename Rhs> class Product;
template<typename MatrixType> class ScalarMultiple;
template<typename MatrixType> class Random;
@ -52,6 +47,12 @@ template<typename MatrixType> class Identity;
template<typename MatrixType> class Map;
template<typename Derived> class Eval;
struct ScalarProductOp;
struct ScalarQuotientOp;
struct ScalarOppositeOp;
struct ScalarConjugateOp;
struct ScalarAbsOp;
template<typename T> struct Reference
{
typedef T Type;

View File

@ -37,6 +37,7 @@ template<typename MatrixType> class Identity : NoOperatorEquals,
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Identity>;
friend class MatrixBase<Scalar, Identity>::Traits;
typedef MatrixBase<Scalar, Identity> Base;
Identity(int rows, int cols) : m_rows(rows), m_cols(cols)

View File

@ -44,6 +44,7 @@ template<typename MatrixType> class Map
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Map>;
friend class MatrixBase<Scalar, Map>::Traits;
typedef MatrixBase<Scalar, Map> Base;
private:

View File

@ -79,6 +79,7 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols,
{
public:
friend class MatrixBase<_Scalar, Matrix>;
friend class MatrixBase<_Scalar, Matrix>::Traits;
friend class Map<Matrix>;
typedef MatrixBase<_Scalar, Matrix> Base;

View File

@ -144,7 +144,7 @@ template<typename Scalar, typename Derived> class MatrixBase
*/
typedef typename NumTraits<Scalar>::Real RealScalar;
/// \name a - matrix properties
/// \name matrix properties
//@{
/** \returns the number of rows. \sa cols(), Traits::RowsAtCompileTime */
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
@ -187,7 +187,7 @@ template<typename Scalar, typename Derived> class MatrixBase
void swap(const MatrixBase<Scalar, OtherDerived>& other);
//@}
/// \name c - sub-matrices
/// \name sub-matrices
//@{
Row<Derived> row(int i);
const Row<Derived> row(int i) const;
@ -223,7 +223,7 @@ template<typename Scalar, typename Derived> class MatrixBase
const DiagonalCoeffs<Derived> diagonal() const;
//@}
/// \name d - matrix transformation
/// \name matrix transformation
//@{
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
@ -232,13 +232,14 @@ template<typename Scalar, typename Derived> class MatrixBase
Transpose<Derived> transpose();
const Transpose<Derived> transpose() const;
const CwiseUnaryOp<ConjugateOp, Derived> conjugate() const;
const Transpose<CwiseUnaryOp<ConjugateOp, Derived> > adjoint() const;
const CwiseUnaryOp<ScalarConjugateOp, Derived> conjugate() const;
const Transpose<CwiseUnaryOp<ScalarConjugateOp, Derived> > adjoint() const;
const ScalarMultiple<Derived> normalized() const;
//@}
/// \name f - metrics (??)
// FIXME not sure about the following name
/// \name metrics
//@{
Scalar trace() const;
@ -265,7 +266,7 @@ template<typename Scalar, typename Derived> class MatrixBase
Derived& setRandom();
Derived& setIdentity();
/// \name g - matrix diagnostic and comparison
/// \name matrix diagnostic and comparison
//@{
bool isZero(RealScalar prec = precision<Scalar>()) const;
bool isOnes(RealScalar prec = precision<Scalar>()) const;
@ -287,9 +288,9 @@ template<typename Scalar, typename Derived> class MatrixBase
RealScalar prec = precision<Scalar>()) const;
//@}
/// \name e - arithemetic operators
/// \name arithemetic operators
//@{
const CwiseUnaryOp<CwiseOppositeOp,Derived> operator-() const;
const CwiseUnaryOp<ScalarOppositeOp,Derived> operator-() const;
template<typename OtherDerived>
Derived& operator+=(const MatrixBase<Scalar, OtherDerived>& other);
@ -313,18 +314,18 @@ template<typename Scalar, typename Derived> class MatrixBase
const Product<Derived, OtherDerived>
lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE;
const CwiseUnaryOp<CwiseAbsOp,Derived> cwiseAbs() const;
const CwiseUnaryOp<ScalarAbsOp,Derived> cwiseAbs() const;
template<typename OtherDerived>
const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived>
const CwiseBinaryOp<ScalarProductOp, Derived, OtherDerived>
cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const;
template<typename OtherDerived>
const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived>
const CwiseBinaryOp<ScalarQuotientOp, Derived, OtherDerived>
cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const;
//@}
/// \name b - coefficient accessors
/// \name coefficient accessors
//@{
Scalar coeff(int row, int col) const;
Scalar operator()(int row, int col) const;
@ -348,7 +349,7 @@ template<typename Scalar, typename Derived> class MatrixBase
Scalar& w();
//@}
/// \name h - special functions
/// \name special functions
//@{
const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE;

View File

@ -31,6 +31,7 @@ template<typename MatrixType> class MatrixRef
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, MatrixRef>;
friend class MatrixBase<Scalar, MatrixRef>::Traits;
typedef MatrixBase<Scalar, MatrixRef> Base;
MatrixRef(const MatrixType& matrix) : m_matrix(matrix) {}

View File

@ -44,6 +44,7 @@ template<typename MatrixType> class Minor
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Minor>;
friend class MatrixBase<Scalar, Minor>::Traits;
typedef MatrixBase<Scalar, Minor> Base;
Minor(const MatRef& matrix,

View File

@ -38,6 +38,7 @@ template<typename MatrixType> class Ones : NoOperatorEquals,
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Ones>;
friend class MatrixBase<Scalar, Ones>::Traits;
typedef MatrixBase<Scalar, Ones> Base;
private:

View File

@ -80,6 +80,7 @@ template<typename Lhs, typename Rhs> class Product : NoOperatorEquals,
typedef typename Lhs::Ref LhsRef;
typedef typename Rhs::Ref RhsRef;
friend class MatrixBase<Scalar, Product>;
friend class MatrixBase<Scalar, Product>::Traits;
typedef MatrixBase<Scalar, Product> Base;
Product(const LhsRef& lhs, const RhsRef& rhs)

View File

@ -38,6 +38,7 @@ template<typename MatrixType> class Random : NoOperatorEquals,
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Random>;
friend class MatrixBase<Scalar, Random>::Traits;
typedef MatrixBase<Scalar, Random> Base;
private:

View File

@ -52,6 +52,7 @@ template<typename MatrixType> class Row
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Row>;
friend class MatrixBase<Scalar, Row>::Traits;
typedef MatrixBase<Scalar, Row> Base;
Row(const MatRef& matrix, int row)

View File

@ -43,6 +43,7 @@ template<typename MatrixType> class ScalarMultiple : NoOperatorEquals,
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, ScalarMultiple>;
friend class MatrixBase<Scalar, ScalarMultiple>::Traits;
typedef MatrixBase<Scalar, ScalarMultiple> Base;
ScalarMultiple(const MatRef& matrix, Scalar factor)

View File

@ -44,6 +44,7 @@ template<typename MatrixType> class Transpose
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Transpose>;
friend class MatrixBase<Scalar, Transpose>::Traits;
typedef MatrixBase<Scalar, Transpose> Base;
Transpose(const MatRef& matrix) : m_matrix(matrix) {}
@ -102,9 +103,9 @@ MatrixBase<Scalar, Derived>::transpose() const
* Example: \include MatrixBase_adjoint.cpp
* Output: \verbinclude MatrixBase_adjoint.out
*
* \sa transpose(), conjugate(), class Transpose, class ConjugateOp */
* \sa transpose(), conjugate(), class Transpose, class ScalarConjugateOp */
template<typename Scalar, typename Derived>
const Transpose<CwiseUnaryOp<ConjugateOp, Derived> >
const Transpose<CwiseUnaryOp<ScalarConjugateOp, Derived> >
MatrixBase<Scalar, Derived>::adjoint() const
{
return conjugate().transpose();

View File

@ -38,6 +38,7 @@ template<typename MatrixType> class Zero : NoOperatorEquals,
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Zero>;
friend class MatrixBase<Scalar, Zero>::Traits;
typedef MatrixBase<Scalar, Zero> Base;
private:

View File

@ -69,12 +69,10 @@ The To-do wiki for Eigen is here: <a href="http://techbase.kde.org/index.php?tit
<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 are slightly different.
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 gives 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.
Eigen is also known to compile with GCC 3.4 and 4.0. However, these later ones seems to not correctly handle friend class with the CRT design pattern. Therefore, at the moment, for any GCC versions earlier than 4.1, all private members of Eigen's classes are made public. It is up to the user to take care to access public members only.
For best performance, we recommend the following compilation flags:
<ul>
<li>\b GCC: \c -O3 \c -DNDEBUG \c -finline-limit=10000 \c -falign-functions=64 </li>