mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
* Added generic unary operators (replace Opposite and Conjugate)
* functor templates are not template template parameter anymore (this allows to make templated functors !) * Main page: extented compiler discussion * A small hack to support gcc 3.4 and 4.0 (see the main page) * Fix a cast type issue in Cast * Various doxygen updates (mainly Cwise stuff and added doxygen groups in MatrixBase to split the huge memeber list, still not perfect though) * Updated Gael's email address
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com>
|
||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
@@ -328,6 +328,9 @@ const Block<Derived> MatrixBase<Scalar, 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
|
||||
* 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)
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
|
||||
@@ -67,9 +67,9 @@ template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _coeff(int row, int col) const
|
||||
NewScalar _coeff(int row, int col) const
|
||||
{
|
||||
return static_cast<Scalar>(m_matrix.coeff(row, col));
|
||||
return static_cast<NewScalar>(m_matrix.coeff(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// Alternatively, you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License and a copy of the GNU General Public License along with
|
||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EIGEN_CONJUGATE_H
|
||||
#define EIGEN_CONJUGATE_H
|
||||
|
||||
/** \class Conjugate
|
||||
*
|
||||
* \brief Expression of the complex conjugate of a matrix
|
||||
*
|
||||
* \param MatrixType the type of the object of which we are taking the complex conjugate
|
||||
*
|
||||
* This class represents an expression of the complex conjugate of a matrix.
|
||||
* It is the return type of MatrixBase::conjugate() and is also used by
|
||||
* MatrixBase::adjoint() and most of the time these are the only ways it is used.
|
||||
*
|
||||
* \sa MatrixBase::conjugate(), MatrixBase::adjoint()
|
||||
*/
|
||||
template<typename MatrixType> class Conjugate : NoOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Conjugate<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class MatrixBase<Scalar, Conjugate>;
|
||||
typedef MatrixBase<Scalar, Conjugate> Base;
|
||||
|
||||
Conjugate(const MatRef& matrix) : m_matrix(matrix) {}
|
||||
|
||||
private:
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
|
||||
};
|
||||
|
||||
const Conjugate& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _coeff(int row, int col) const
|
||||
{
|
||||
return ei_conj(m_matrix.coeff(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatRef m_matrix;
|
||||
};
|
||||
|
||||
/** \returns an expression of the complex conjugate of *this.
|
||||
*
|
||||
* \sa adjoint(), class Conjugate */
|
||||
template<typename Scalar, typename Derived>
|
||||
const Conjugate<Derived>
|
||||
MatrixBase<Scalar, Derived>::conjugate() const
|
||||
{
|
||||
return Conjugate<Derived>(ref());
|
||||
}
|
||||
|
||||
/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this.
|
||||
*
|
||||
* Example: \include MatrixBase_adjoint.cpp
|
||||
* Output: \verbinclude MatrixBase_adjoint.out
|
||||
*
|
||||
* \sa transpose(), conjugate(), class Transpose, class Conjugate */
|
||||
template<typename Scalar, typename Derived>
|
||||
const Transpose<Conjugate<Derived> >
|
||||
MatrixBase<Scalar, Derived>::adjoint() const
|
||||
{
|
||||
return conjugate().transpose();
|
||||
}
|
||||
|
||||
#endif // EIGEN_CONJUGATE_H
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com>
|
||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
@@ -35,12 +35,18 @@
|
||||
* \param Rhs the type of the right-hand side
|
||||
*
|
||||
* This class represents an expression of a generic binary operator of two matrices or vectors.
|
||||
* It is the return type of the operator+, operator-, cwiseiseProduct, cwiseQuotient between matrices or vectors, and most
|
||||
* It is the return type of the operator+, operator-, cwiseProduct, cwiseQuotient between matrices or vectors, and most
|
||||
* of the time this is the only way it is used.
|
||||
*
|
||||
* However, if you want to write a function returning such an expression, you
|
||||
* will need to use this class.
|
||||
*
|
||||
* Here is an example illustrating this:
|
||||
* \include class_CwiseBinaryOp.cpp
|
||||
*
|
||||
* \sa class CwiseProductOp, class CwiseQuotientOp
|
||||
*/
|
||||
template<template<typename BinaryOpScalar> class BinaryOp, typename Lhs, typename Rhs>
|
||||
template<typename BinaryOp, typename Lhs, typename Rhs>
|
||||
class CwiseBinaryOp : NoOperatorEquals,
|
||||
public MatrixBase<typename Lhs::Scalar, CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
|
||||
{
|
||||
@@ -71,7 +77,7 @@ class CwiseBinaryOp : NoOperatorEquals,
|
||||
|
||||
Scalar _coeff(int row, int col) const
|
||||
{
|
||||
return BinaryOp<Scalar>::op(m_lhs.coeff(row, col), m_rhs.coeff(row, col));
|
||||
return BinaryOp::template op<Scalar>(m_lhs.coeff(row, col), m_rhs.coeff(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -83,32 +89,32 @@ class CwiseBinaryOp : NoOperatorEquals,
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::operator+
|
||||
*/
|
||||
template<typename Scalar> struct CwiseSumOp {
|
||||
static Scalar op(const Scalar& a, const Scalar& b) { return a + b; }
|
||||
struct CwiseSumOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a + b; }
|
||||
};
|
||||
|
||||
/** \brief Template functor to compute the difference of two scalars
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::operator-
|
||||
*/
|
||||
template<typename Scalar> struct CwiseDifferenceOp {
|
||||
static Scalar op(const Scalar& a, const Scalar& b) { return a - b; }
|
||||
struct CwiseDifferenceOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a - b; }
|
||||
};
|
||||
|
||||
/** \brief Template functor to compute the product of two scalars
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::cwiseProduct()
|
||||
*/
|
||||
template<typename Scalar> struct CwiseProductOp {
|
||||
static Scalar op(const Scalar& a, const Scalar& b) { return a * b; }
|
||||
struct CwiseProductOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a * b; }
|
||||
};
|
||||
|
||||
/** \brief Template functor to compute the quotient of two scalars
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::cwiseQuotient()
|
||||
*/
|
||||
template<typename Scalar> struct CwiseQuotientOp {
|
||||
static Scalar op(const Scalar& a, const Scalar& b) { return a / b; }
|
||||
struct CwiseQuotientOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a, const Scalar& b) { return a / b; }
|
||||
};
|
||||
|
||||
/** \relates MatrixBase
|
||||
@@ -193,11 +199,12 @@ MatrixBase<Scalar, Derived>::cwiseQuotient(const MatrixBase<Scalar, OtherDerived
|
||||
*
|
||||
* \returns an expression of a custom coefficient-wise operator of \a mat1 and \a mat2
|
||||
*
|
||||
* \param CustomBinaryOp template functor of the custom operator
|
||||
* The template parameter \a CustomBinaryOp is the template functor
|
||||
* of the custom operator (see class CwiseBinaryOp for an example)
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct, MatrixBase::cwiseQuotient
|
||||
*/
|
||||
template<template<typename BinaryOpScalar> class CustomBinaryOp, typename Scalar, typename Derived1, typename Derived2>
|
||||
template<typename CustomBinaryOp, typename Scalar, typename Derived1, typename Derived2>
|
||||
const CwiseBinaryOp<CustomBinaryOp, Derived1, Derived2>
|
||||
cwise(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2)
|
||||
{
|
||||
@@ -206,12 +213,21 @@ cwise(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived
|
||||
|
||||
/** \returns an expression of a custom coefficient-wise operator of *this and \a other
|
||||
*
|
||||
* \param CustomBinaryOp template functor of the custom operator
|
||||
* The template parameter \a CustomBinaryOp is the template functor
|
||||
* of the custom operator (see class CwiseBinaryOp for an example)
|
||||
*
|
||||
* \note since cwise is a templated member with a mandatory template parameter,
|
||||
* 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);
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct, MatrixBase::cwiseQuotient
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
template<template<typename BinaryOpScalar> class CustomBinaryOp, typename OtherDerived>
|
||||
template<typename CustomBinaryOp, typename OtherDerived>
|
||||
const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
|
||||
MatrixBase<Scalar, Derived>::cwise(const MatrixBase<Scalar, OtherDerived> &other) const
|
||||
{
|
||||
|
||||
171
Eigen/src/Core/CwiseUnaryOp.h
Normal file
171
Eigen/src/Core/CwiseUnaryOp.h
Normal file
@@ -0,0 +1,171 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// Alternatively, you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License and a copy of the GNU General Public License along with
|
||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EIGEN_CWISE_UNARY_OP_H
|
||||
#define EIGEN_CWISE_UNARY_OP_H
|
||||
|
||||
/** \class CwiseUnaryOp
|
||||
*
|
||||
* \brief Generic expression of a coefficient-wise unary operator of a matrix or a vector
|
||||
*
|
||||
* \param UnaryOp template functor implementing the operator
|
||||
* \param MatrixType the type of the matrix we are applying the unary operator
|
||||
*
|
||||
* This class represents an expression of a generic unary operator of a matrix or a vector.
|
||||
* It is the return type of the unary operator-, of a matrix or a vector, and most
|
||||
* of the time this is the only way it is used.
|
||||
*
|
||||
* \sa class CwiseBinaryOp
|
||||
*/
|
||||
template<typename UnaryOp, typename MatrixType>
|
||||
class CwiseUnaryOp : NoOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, CwiseUnaryOp<UnaryOp, MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class MatrixBase<Scalar, CwiseUnaryOp>;
|
||||
typedef MatrixBase<Scalar, CwiseUnaryOp> Base;
|
||||
|
||||
CwiseUnaryOp(const MatRef& mat) : m_matrix(mat) {}
|
||||
|
||||
private:
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
|
||||
};
|
||||
|
||||
const CwiseUnaryOp& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _coeff(int row, int col) const
|
||||
{
|
||||
return UnaryOp::template op<Scalar>(m_matrix.coeff(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatRef m_matrix;
|
||||
};
|
||||
|
||||
/** \brief Template functor to compute the opposite of a scalar
|
||||
*
|
||||
* \sa class CwiseUnaryOp, MatrixBase::operator-
|
||||
*/
|
||||
struct CwiseOppositeOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a) { return -a; }
|
||||
};
|
||||
|
||||
/** \brief Template functor to compute the absolute value of a scalar
|
||||
*
|
||||
* \sa class CwiseUnaryOp, MatrixBase::cwiseAbs
|
||||
*/
|
||||
struct CwiseAbsOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a) { return ei_abs(a); }
|
||||
};
|
||||
|
||||
|
||||
/** \returns an expression of the opposite of \c *this
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
const CwiseUnaryOp<CwiseOppositeOp,Derived>
|
||||
MatrixBase<Scalar, Derived>::operator-() const
|
||||
{
|
||||
return CwiseUnaryOp<CwiseOppositeOp,Derived>(ref());
|
||||
}
|
||||
|
||||
/** \returns an expression of the opposite of \c *this
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
const CwiseUnaryOp<CwiseAbsOp,Derived>
|
||||
MatrixBase<Scalar, Derived>::cwiseAbs() const
|
||||
{
|
||||
return CwiseUnaryOp<CwiseAbsOp,Derived>(ref());
|
||||
}
|
||||
|
||||
|
||||
/** \relates MatrixBase
|
||||
*
|
||||
* \returns an expression of a custom coefficient-wise unary operator of \a mat
|
||||
*
|
||||
* The template parameter \a CustomUnaryOp is the template functor
|
||||
* of the custom unary operator.
|
||||
*
|
||||
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::cwise, MatrixBase::operator-, MatrixBase::cwiseAbs
|
||||
*/
|
||||
template<typename CustomUnaryOp, typename Scalar, typename Derived>
|
||||
const CwiseUnaryOp<CustomUnaryOp, Derived>
|
||||
cwise(const MatrixBase<Scalar, Derived> &mat)
|
||||
{
|
||||
return CwiseUnaryOp<CustomUnaryOp, Derived>(mat.ref());
|
||||
}
|
||||
|
||||
/** \returns an expression of a custom coefficient-wise unary operator of *this
|
||||
*
|
||||
* The template parameter \a CustomUnaryOp is the template functor
|
||||
* of the custom unary operator.
|
||||
*
|
||||
* \note since cwise is a templated member with a mandatory template parameter,
|
||||
* 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>();
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, MatrixBase::cwiseAbs
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename CustomUnaryOp>
|
||||
const CwiseUnaryOp<CustomUnaryOp, Derived>
|
||||
MatrixBase<Scalar, Derived>::cwise() const
|
||||
{
|
||||
return CwiseUnaryOp<CustomUnaryOp, Derived>(ref());
|
||||
}
|
||||
|
||||
|
||||
/** \brief Template functor to compute the conjugate of a complex value
|
||||
*
|
||||
* \sa class CwiseUnaryOp, MatrixBase::conjugate()
|
||||
*/
|
||||
struct ConjugateOp {
|
||||
template<typename Scalar> static Scalar op(const Scalar& a) { return ei_conj(a); }
|
||||
};
|
||||
|
||||
/** \returns an expression of the complex conjugate of *this.
|
||||
*
|
||||
* \sa adjoint(), class Conjugate */
|
||||
template<typename Scalar, typename Derived>
|
||||
const CwiseUnaryOp<ConjugateOp, Derived>
|
||||
MatrixBase<Scalar, Derived>::conjugate() const
|
||||
{
|
||||
return CwiseUnaryOp<ConjugateOp, Derived>(ref());
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // EIGEN_CWISE_UNARY_OP_H
|
||||
@@ -34,10 +34,13 @@ template<typename MatrixType> class Minor;
|
||||
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block;
|
||||
template<typename MatrixType> class Transpose;
|
||||
template<typename MatrixType> class Conjugate;
|
||||
template<typename MatrixType> class Opposite;
|
||||
template<template<typename BinaryOpScalar> class BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp;
|
||||
template<typename Scalar> struct CwiseProductOp;
|
||||
template<typename Scalar> struct CwiseQuotientOp;
|
||||
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;
|
||||
|
||||
@@ -144,6 +144,8 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
*/
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
|
||||
/// \name a - matrix properties
|
||||
//@{
|
||||
/** \returns the number of rows. \sa cols(), Traits::RowsAtCompileTime */
|
||||
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
|
||||
/** \returns the number of columns. \sa row(), Traits::ColsAtCompileTime*/
|
||||
@@ -156,10 +158,13 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
* \code rows()==1 || cols()==1 \endcode
|
||||
* \sa rows(), cols(), Traits::IsVectorAtCompileTime. */
|
||||
bool isVector() const { return rows()==1 || cols()==1; }
|
||||
//@}
|
||||
|
||||
/** \returns a Ref to *this. \sa Ref */
|
||||
Ref ref() const
|
||||
{ return static_cast<const Derived *>(this)->_ref(); }
|
||||
|
||||
//@{
|
||||
/** Copies \a other into *this. \returns a reference to *this. */
|
||||
template<typename OtherDerived>
|
||||
Derived& operator=(const MatrixBase<Scalar, OtherDerived>& other);
|
||||
@@ -172,8 +177,18 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
return this->operator=<Derived>(other);
|
||||
}
|
||||
|
||||
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
|
||||
/** swaps *this with the expression \a other.
|
||||
*
|
||||
* \note \a other is only marked const because I couln't find another way
|
||||
* to get g++ 4.2 to accept that template parameter resolution. It gets const_cast'd
|
||||
* of course. TODO: get rid of const here.
|
||||
*/
|
||||
template<typename OtherDerived>
|
||||
void swap(const MatrixBase<Scalar, OtherDerived>& other);
|
||||
//@}
|
||||
|
||||
/// \name c - sub-matrices
|
||||
//@{
|
||||
Row<Derived> row(int i);
|
||||
const Row<Derived> row(int i) const;
|
||||
|
||||
@@ -204,22 +219,34 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
template<int BlockRows, int BlockCols>
|
||||
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
|
||||
|
||||
DiagonalCoeffs<Derived> diagonal();
|
||||
const DiagonalCoeffs<Derived> diagonal() const;
|
||||
//@}
|
||||
|
||||
/// \name d - matrix transformation
|
||||
//@{
|
||||
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
|
||||
|
||||
const DiagonalMatrix<Derived> asDiagonal() const;
|
||||
|
||||
Transpose<Derived> transpose();
|
||||
const Transpose<Derived> transpose() const;
|
||||
|
||||
const Conjugate<Derived> conjugate() const;
|
||||
const Transpose<Conjugate<Derived> > adjoint() const;
|
||||
const CwiseUnaryOp<ConjugateOp, Derived> conjugate() const;
|
||||
const Transpose<CwiseUnaryOp<ConjugateOp, Derived> > adjoint() const;
|
||||
|
||||
const ScalarMultiple<Derived> normalized() const;
|
||||
//@}
|
||||
|
||||
/// \name f - metrics (??)
|
||||
//@{
|
||||
Scalar trace() const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
Scalar dot(const MatrixBase<Scalar, OtherDerived>& other) const;
|
||||
RealScalar norm2() const;
|
||||
RealScalar norm() const;
|
||||
const ScalarMultiple<Derived> normalized() const;
|
||||
template<typename OtherDerived>
|
||||
bool isOrtho(const MatrixBase<Scalar, OtherDerived>& other,
|
||||
RealScalar prec = precision<Scalar>()) const;
|
||||
bool isOrtho(RealScalar prec = precision<Scalar>()) const;
|
||||
//@}
|
||||
|
||||
static const Eval<Random<Derived> > random(int rows, int cols);
|
||||
static const Eval<Random<Derived> > random(int size);
|
||||
@@ -233,20 +260,22 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
static const Identity<Derived> identity();
|
||||
static const Identity<Derived> identity(int rows, int cols);
|
||||
|
||||
bool isZero(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isOnes(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isIdentity(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isDiagonal(RealScalar prec = precision<Scalar>()) const;
|
||||
|
||||
Derived& setZero();
|
||||
Derived& setOnes();
|
||||
Derived& setRandom();
|
||||
Derived& setIdentity();
|
||||
|
||||
const DiagonalMatrix<Derived> asDiagonal() const;
|
||||
/// \name g - matrix diagnostic and comparison
|
||||
//@{
|
||||
bool isZero(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isOnes(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isIdentity(RealScalar prec = precision<Scalar>()) const;
|
||||
bool isDiagonal(RealScalar prec = precision<Scalar>()) const;
|
||||
|
||||
DiagonalCoeffs<Derived> diagonal();
|
||||
const DiagonalCoeffs<Derived> diagonal() const;
|
||||
template<typename OtherDerived>
|
||||
bool isOrtho(const MatrixBase<Scalar, OtherDerived>& other,
|
||||
RealScalar prec = precision<Scalar>()) const;
|
||||
bool isOrtho(RealScalar prec = precision<Scalar>()) const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
bool isApprox(const OtherDerived& other,
|
||||
@@ -256,24 +285,11 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
template<typename OtherDerived>
|
||||
bool isMuchSmallerThan(const MatrixBase<Scalar, OtherDerived>& other,
|
||||
RealScalar prec = precision<Scalar>()) const;
|
||||
//@}
|
||||
|
||||
template<typename OtherDerived>
|
||||
const Product<Derived, OtherDerived>
|
||||
lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE;
|
||||
|
||||
const Opposite<Derived> operator-() const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived>
|
||||
cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived>
|
||||
cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
|
||||
template<template<typename BinaryOpScalar> class CustomBinaryOp, typename OtherDerived>
|
||||
const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
|
||||
cwise(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
/// \name e - arithemetic operators
|
||||
//@{
|
||||
const CwiseUnaryOp<CwiseOppositeOp,Derived> operator-() const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
Derived& operator+=(const MatrixBase<Scalar, OtherDerived>& other);
|
||||
@@ -293,6 +309,23 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
const MatrixBase& matrix)
|
||||
{ return matrix*scalar; }
|
||||
|
||||
template<typename OtherDerived>
|
||||
const Product<Derived, OtherDerived>
|
||||
lazyProduct(const MatrixBase<Scalar, OtherDerived>& other) const EIGEN_ALWAYS_INLINE;
|
||||
|
||||
const CwiseUnaryOp<CwiseAbsOp,Derived> cwiseAbs() const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
const CwiseBinaryOp<CwiseProductOp, Derived, OtherDerived>
|
||||
cwiseProduct(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
|
||||
template<typename OtherDerived>
|
||||
const CwiseBinaryOp<CwiseQuotientOp, Derived, OtherDerived>
|
||||
cwiseQuotient(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
//@}
|
||||
|
||||
/// \name b - coefficient accessors
|
||||
//@{
|
||||
Scalar coeff(int row, int col) const;
|
||||
Scalar operator()(int row, int col) const;
|
||||
|
||||
@@ -313,9 +346,20 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
Scalar& y();
|
||||
Scalar& z();
|
||||
Scalar& w();
|
||||
//@}
|
||||
|
||||
/// \name h - special functions
|
||||
//@{
|
||||
const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE;
|
||||
|
||||
template<typename CustomUnaryOp>
|
||||
const CwiseUnaryOp<CustomUnaryOp, Derived> cwise() const;
|
||||
|
||||
template<typename CustomBinaryOp, typename OtherDerived>
|
||||
const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
|
||||
cwise(const MatrixBase<Scalar, OtherDerived> &other) const;
|
||||
//@}
|
||||
|
||||
/** puts in *row and *col the location of the coefficient of *this
|
||||
* which has the biggest absolute value.
|
||||
*/
|
||||
@@ -335,14 +379,6 @@ template<typename Scalar, typename Derived> class MatrixBase
|
||||
}
|
||||
}
|
||||
|
||||
/** swaps *this with the expression \a other.
|
||||
*
|
||||
* \note \a other is only marked const because I couln't find another way
|
||||
* to get g++ 4.2 to accept that template parameter resolution. It gets const_cast'd
|
||||
* of course. TODO: get rid of const here.
|
||||
*/
|
||||
template<typename OtherDerived>
|
||||
void swap(const MatrixBase<Scalar, OtherDerived>& other);
|
||||
};
|
||||
|
||||
#endif // EIGEN_MATRIXBASE_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@gmail.com>
|
||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// Alternatively, you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License and a copy of the GNU General Public License along with
|
||||
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EIGEN_OPPOSITE_H
|
||||
#define EIGEN_OPPOSITE_H
|
||||
|
||||
/** \class Opposite
|
||||
*
|
||||
* \brief Expression of the opposite of a matrix or vector
|
||||
*
|
||||
* \param MatrixType the type of which we are taking the opposite
|
||||
*
|
||||
* This class represents an expression of the opposite of a matrix or vector.
|
||||
* It is the return type of the unary operator- for matrices or vectors, and most
|
||||
* of the time this is the only way it is used.
|
||||
*
|
||||
* \sa class Difference
|
||||
*/
|
||||
template<typename MatrixType> class Opposite : NoOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, Opposite<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class MatrixBase<Scalar, Opposite>;
|
||||
typedef MatrixBase<Scalar, Opposite> Base;
|
||||
|
||||
Opposite(const MatRef& matrix) : m_matrix(matrix) {}
|
||||
|
||||
private:
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime
|
||||
};
|
||||
|
||||
const Opposite& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _coeff(int row, int col) const
|
||||
{
|
||||
return -(m_matrix.coeff(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatRef m_matrix;
|
||||
};
|
||||
|
||||
/** \returns an expression of the opposite of \c *this
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
const Opposite<Derived>
|
||||
MatrixBase<Scalar, Derived>::operator-() const
|
||||
{
|
||||
return Opposite<Derived>(ref());
|
||||
}
|
||||
|
||||
#endif // EIGEN_OPPOSITE_H
|
||||
@@ -97,4 +97,17 @@ MatrixBase<Scalar, Derived>::transpose() const
|
||||
return Transpose<Derived>(ref());
|
||||
}
|
||||
|
||||
/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this.
|
||||
*
|
||||
* Example: \include MatrixBase_adjoint.cpp
|
||||
* Output: \verbinclude MatrixBase_adjoint.out
|
||||
*
|
||||
* \sa transpose(), conjugate(), class Transpose, class ConjugateOp */
|
||||
template<typename Scalar, typename Derived>
|
||||
const Transpose<CwiseUnaryOp<ConjugateOp, Derived> >
|
||||
MatrixBase<Scalar, Derived>::adjoint() const
|
||||
{
|
||||
return conjugate().transpose();
|
||||
}
|
||||
|
||||
#endif // EIGEN_TRANSPOSE_H
|
||||
|
||||
@@ -56,7 +56,11 @@ using Eigen::MatrixBase;
|
||||
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
// FIXME with the always_inline attribute,
|
||||
// gcc 3.4.x reports the following compilation error:
|
||||
// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
|
||||
// : function body not available
|
||||
#if (defined __GNUC__) && (__GNUC__!=3)
|
||||
#define EIGEN_ALWAYS_INLINE __attribute__((always_inline))
|
||||
#else
|
||||
#define EIGEN_ALWAYS_INLINE
|
||||
|
||||
Reference in New Issue
Block a user