move Core/ to a src/ subdir, in preparation for following changes

This commit is contained in:
Benoit Jacob
2007-12-28 16:00:55 +00:00
parent e7bdbe2e6a
commit dfdad129a3
35 changed files with 0 additions and 0 deletions

126
Eigen/src/Core/Block.h Normal file
View File

@@ -0,0 +1,126 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_BLOCK_H
#define EIGEN_BLOCK_H
/** \class Block
*
* \brief Expression of a fixed-size block
*
* \param MatrixType the type of the object in which we are taking a block
* \param BlockRows the number of rows of the block we are taking
* \param BlockCols the number of columns of the block we are taking
*
* This class represents an expression of a fixed-size block. It is the return
* type of MatrixBase::block() and most of the time this is the only way it
* is used.
*
* However, if you want to directly maniputate fixed-size block expressions,
* for instance 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_Block.cpp
* Output: \verbinclude class_Block.out
*
* \sa MatrixBase::block(), class DynBlock
*/
template<typename MatrixType, int BlockRows, int BlockCols> class Block
: public MatrixBase<typename MatrixType::Scalar,
Block<MatrixType, BlockRows, BlockCols> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Block<MatrixType, BlockRows, BlockCols> >;
Block(const MatRef& matrix, int startRow, int startCol)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol)
{
assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows()
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols());
}
Block(const Block& other)
: m_matrix(other.m_matrix),
m_startRow(other.m_startRow), m_startCol(other.m_startCol) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
private:
static const int _RowsAtCompileTime = BlockRows,
_ColsAtCompileTime = BlockCols;
const Block& _ref() const { return *this; }
int _rows() const { return BlockRows; }
int _cols() const { return BlockCols; }
Scalar& _coeffRef(int row, int col)
{
return m_matrix.coeffRef(row + m_startRow, col + m_startCol);
}
Scalar _coeff(int row, int col) const
{
return m_matrix.coeff(row + m_startRow, col + m_startCol);
}
protected:
MatRef m_matrix;
const int m_startRow, m_startCol;
};
/** \returns a fixed-size expression of a block in *this.
*
* The template parameters \a blockRows and \a blockCols are the number of
* rows and columns in the block
*
* \param startRow the first row in the block
* \param startCol the first column in the block
*
* Example: \include MatrixBase_block.cpp
* Output: \verbinclude MatrixBase_block.out
*
* \sa class Block, dynBlock()
*/
template<typename Scalar, typename Derived>
template<int BlockRows, int BlockCols>
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol)
{
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
}
/** This is the const version of block(). */
template<typename Scalar, typename Derived>
template<int BlockRows, int BlockCols>
const Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
::block(int startRow, int startCol) const
{
return Block<Derived, BlockRows, BlockCols>(ref(), startRow, startCol);
}
#endif // EIGEN_BLOCK_H

View File

@@ -0,0 +1,6 @@
FILE(GLOB Eigen_Core_SRCS "*.h")
INSTALL(FILES
${Eigen_Core_SRCS}
DESTINATION ${INCLUDE_INSTALL_DIR}/Core
)

96
Eigen/src/Core/Cast.h Normal file
View File

@@ -0,0 +1,96 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_CAST_H
#define EIGEN_CAST_H
/** \class Cast
*
* \brief Expression with casted scalar type
*
* \param NewScalar the new scalar type
* \param MatrixType the type of the object in which we are casting the scalar type
*
* This class represents an expression where we are casting the scalar type to a new
* type. It is the return type of MatrixBase::cast() 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_Cast.cpp
* Output: \verbinclude class_Cast.out
*
* \sa MatrixBase::cast()
*/
template<typename NewScalar, typename MatrixType> class Cast : NoOperatorEquals,
public MatrixBase<NewScalar, Cast<NewScalar, MatrixType> >
{
public:
typedef NewScalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Cast<Scalar, MatrixType> >;
Cast(const MatRef& matrix) : m_matrix(matrix) {}
Cast(const Cast& other)
: m_matrix(other.m_matrix) {}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Cast& _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 static_cast<Scalar>(m_matrix.coeff(row, col));
}
protected:
MatRef m_matrix;
};
/** \returns an expression of *this with the \a Scalar type casted to
* \a NewScalar.
*
* \param NewScalar the type we are casting the scalars to
*
* Example: \include MatrixBase_cast.cpp
* Output: \verbinclude MatrixBase_cast.out
*
* \sa class Cast
*/
template<typename Scalar, typename Derived>
template<typename NewScalar>
const Cast<NewScalar, Derived>
MatrixBase<Scalar, Derived>::cast() const
{
return Cast<NewScalar, Derived>(static_cast<const Derived*>(this)->ref());
}
#endif // EIGEN_CAST_H

250
Eigen/src/Core/Coeffs.h Normal file
View File

@@ -0,0 +1,250 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_COEFFS_H
#define EIGEN_COEFFS_H
/** Short version: don't use this function, use
* \link operator()(int,int) const \endlink instead.
*
* Long version: this function is similar to
* \link operator()(int,int) const \endlink, but without the assertion.
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access. Only use this when it is guaranteed that the
* parameters \a row and \a col are in range.
*
* If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
* function equivalent to \link operator()(int,int) const \endlink.
*
* \sa operator()(int,int) const, coeffRef(int,int), coeff(int) const
*/
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::coeff(int row, int col) const
{
eigen_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols());
return static_cast<const Derived *>(this)->_coeff(row, col);
}
/** \returns the coefficient at given the given row and column.
*
* \sa operator()(int,int), operator[](int) const
*/
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::operator()(int row, int col) const
{
assert(row >= 0 && row < rows()
&& col >= 0 && col < cols());
return static_cast<const Derived *>(this)->_coeff(row, col);
}
/** Short version: don't use this function, use
* \link operator()(int,int) \endlink instead.
*
* Long version: this function is similar to
* \link operator()(int,int) \endlink, but without the assertion.
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access. Only use this when it is guaranteed that the
* parameters \a row and \a col are in range.
*
* If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
* function equivalent to \link operator()(int,int) \endlink.
*
* \sa operator()(int,int), coeff(int, int) const, coeffRef(int)
*/
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::coeffRef(int row, int col)
{
eigen_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols());
return static_cast<Derived *>(this)->_coeffRef(row, col);
}
/** \returns a reference to the coefficient at given the given row and column.
*
* \sa operator()(int,int) const, operator[](int)
*/
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::operator()(int row, int col)
{
assert(row >= 0 && row < rows()
&& col >= 0 && col < cols());
return static_cast<Derived *>(this)->_coeffRef(row, col);
}
/** Short version: don't use this function, use
* \link operator[](int) const \endlink instead.
*
* Long version: this function is similar to
* \link operator[](int) const \endlink, but without the assertion.
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access. Only use this when it is guaranteed that the
* parameters \a row and \a col are in range.
*
* If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
* function equivalent to \link operator[](int) const \endlink.
*
* \sa operator[](int) const, coeffRef(int), coeff(int,int) const
*/
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::coeff(int index) const
{
eigen_internal_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1)
{
eigen_internal_assert(index >= 0 && index < cols());
return coeff(0, index);
}
else
{
eigen_internal_assert(index >= 0 && index < rows());
return coeff(index, 0);
}
}
/** \returns the coefficient at given index.
*
* \only_for_vectors
*
* \sa operator[](int), operator()(int,int) const, x() const, y() const,
* z() const, w() const
*/
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::operator[](int index) const
{
assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1)
{
assert(index >= 0 && index < cols());
return coeff(0, index);
}
else
{
assert(index >= 0 && index < rows());
return coeff(index, 0);
}
}
/** Short version: don't use this function, use
* \link operator[](int) \endlink instead.
*
* Long version: this function is similar to
* \link operator[](int) \endlink, but without the assertion.
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access. Only use this when it is guaranteed that the
* parameters \a row and \a col are in range.
*
* If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
* function equivalent to \link operator[](int) \endlink.
*
* \sa operator[](int), coeff(int) const, coeffRef(int,int)
*/
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::coeffRef(int index)
{
eigen_internal_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1)
{
eigen_internal_assert(index >= 0 && index < cols());
return coeffRef(0, index);
}
else
{
eigen_internal_assert(index >= 0 && index < rows());
return coeffRef(index, 0);
}
}
/** \returns a reference to the coefficient at given index.
*
* \only_for_vectors
*
* \sa operator[](int) const, operator()(int,int), x(), y(), z(), w()
*/
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::operator[](int index)
{
assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1)
{
assert(index >= 0 && index < cols());
return coeffRef(0, index);
}
else
{
assert(index >= 0 && index < rows());
return coeffRef(index, 0);
}
}
/** equivalent to operator[](0). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::x() const { return (*this)[0]; }
/** equivalent to operator[](1). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::y() const { return (*this)[1]; }
/** equivalent to operator[](2). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::z() const { return (*this)[2]; }
/** equivalent to operator[](3). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>
::w() const { return (*this)[3]; }
/** equivalent to operator[](0). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::x() { return (*this)[0]; }
/** equivalent to operator[](1). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::y() { return (*this)[1]; }
/** equivalent to operator[](2). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::z() { return (*this)[2]; }
/** equivalent to operator[](3). \only_for_vectors */
template<typename Scalar, typename Derived>
Scalar& MatrixBase<Scalar, Derived>
::w() { return (*this)[3]; }
#endif // EIGEN_COEFFS_H

111
Eigen/src/Core/Column.h Normal file
View File

@@ -0,0 +1,111 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_COLUMN_H
#define EIGEN_COLUMN_H
/** \class Column
*
* \brief Expression of a column
*
* \param MatrixType the type of the object in which we are taking a column
*
* This class represents an expression of a column. It is the return
* type of MatrixBase::col() and most of the time this is the only way it
* is used.
*
* However, if you want to directly maniputate column expressions,
* for instance 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_Column.cpp
* Output: \verbinclude class_Column.out
*
* \sa MatrixBase::col()
*/
template<typename MatrixType> class Column
: public MatrixBase<typename MatrixType::Scalar, Column<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Column<MatrixType> >;
Column(const MatRef& matrix, int col)
: m_matrix(matrix), m_col(col)
{
assert(col >= 0 && col < matrix.cols());
}
Column(const Column& other)
: m_matrix(other.m_matrix), m_col(other.m_col) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Column)
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = 1;
const Column& _ref() const { return *this; }
int _rows() const { return m_matrix.rows(); }
int _cols() const { return 1; }
Scalar& _coeffRef(int row, int)
{
return m_matrix.coeffRef(row, m_col);
}
Scalar _coeff(int row, int) const
{
return m_matrix.coeff(row, m_col);
}
protected:
MatRef m_matrix;
const int m_col;
};
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
*
* Example: \include MatrixBase_column.cpp
* Output: \verbinclude MatrixBase_column.out
*
* \sa row(), class Column */
template<typename Scalar, typename Derived>
Column<Derived>
MatrixBase<Scalar, Derived>::col(int i)
{
return Column<Derived>(ref(), i);
}
/** This is the const version of col(). */
template<typename Scalar, typename Derived>
const Column<Derived>
MatrixBase<Scalar, Derived>::col(int i) const
{
return Column<Derived>(ref(), i);
}
#endif // EIGEN_COLUMN_H

View File

@@ -0,0 +1,94 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#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<MatrixType> >;
Conjugate(const MatRef& matrix) : m_matrix(matrix) {}
Conjugate(const Conjugate& other)
: m_matrix(other.m_matrix) {}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
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 conj(m_matrix.coeff(row, col));
}
protected:
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>(static_cast<const Derived*>(this)->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

View File

@@ -0,0 +1,98 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_DIAGONALCOEFFS_H
#define EIGEN_DIAGONALCOEFFS_H
/** \class DiagonalCoeffs
*
* \brief Expression of the main diagonal of a square matrix
*
* \param MatrixType the type of the object in which we are taking the main diagonal
*
* This class represents an expression of the main diagonal of a square matrix.
* It is the return type of MatrixBase::diagonal() and most of the time this is
* the only way it is used.
*
* \sa MatrixBase::diagonal()
*/
template<typename MatrixType> class DiagonalCoeffs
: public MatrixBase<typename MatrixType::Scalar, DiagonalCoeffs<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, DiagonalCoeffs<MatrixType> >;
DiagonalCoeffs(const MatRef& matrix) : m_matrix(matrix) {}
DiagonalCoeffs(const DiagonalCoeffs& other) : m_matrix(other.m_matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs)
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = 1;
const DiagonalCoeffs& _ref() const { return *this; }
int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); }
int _cols() const { return 1; }
Scalar& _coeffRef(int row, int)
{
return m_matrix.coeffRef(row, row);
}
Scalar _coeff(int row, int) const
{
return m_matrix.coeff(row, row);
}
protected:
MatRef m_matrix;
};
/** \returns an expression of the main diagonal of *this, which must be a square matrix.
*
* Example: \include MatrixBase_diagonal.cpp
* Output: \verbinclude MatrixBase_diagonal.out
*
* \sa class DiagonalCoeffs */
template<typename Scalar, typename Derived>
DiagonalCoeffs<Derived>
MatrixBase<Scalar, Derived>::diagonal()
{
return DiagonalCoeffs<Derived>(ref());
}
/** This is the const version of diagonal(). */
template<typename Scalar, typename Derived>
const DiagonalCoeffs<Derived>
MatrixBase<Scalar, Derived>::diagonal() const
{
return DiagonalCoeffs<Derived>(ref());
}
#endif // EIGEN_DIAGONALCOEFFS_H

View File

@@ -0,0 +1,72 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_DIAGONALMATRIX_H
#define EIGEN_DIAGONALMATRIX_H
template<typename MatrixType, typename CoeffsVectorType>
class DiagonalMatrix : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar,
DiagonalMatrix<MatrixType, CoeffsVectorType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename CoeffsVectorType::Ref CoeffsVecRef;
friend class MatrixBase<Scalar, DiagonalMatrix<MatrixType, CoeffsVectorType> >;
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)
{
assert(CoeffsVectorType::IsVectorAtCompileTime
&& _RowsAtCompileTime == _ColsAtCompileTime
&& _RowsAtCompileTime == CoeffsVectorType::SizeAtCompileTime
&& coeffs.size() > 0);
}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const DiagonalMatrix& _ref() const { return *this; }
int _rows() const { return m_coeffs.size(); }
int _cols() const { return m_coeffs.size(); }
Scalar _coeff(int row, int col) const
{
return row == col ? m_coeffs.coeff(row) : static_cast<Scalar>(0);
}
protected:
CoeffsVecRef m_coeffs;
};
template<typename Scalar, typename Derived>
template<typename OtherDerived>
const DiagonalMatrix<Derived, OtherDerived>
MatrixBase<Scalar, Derived>::diagonal(const OtherDerived& coeffs)
{
return DiagonalMatrix<Derived, OtherDerived>(coeffs);
}
#endif // EIGEN_DIAGONALMATRIX_H

View File

@@ -0,0 +1,81 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_DIFFERENCE_H
#define EIGEN_DIFFERENCE_H
template<typename Lhs, typename Rhs> class Difference : NoOperatorEquals,
public MatrixBase<typename Lhs::Scalar, Difference<Lhs, Rhs> >
{
public:
typedef typename Lhs::Scalar Scalar;
typedef typename Lhs::Ref LhsRef;
typedef typename Rhs::Ref RhsRef;
friend class MatrixBase<Scalar, Difference>;
Difference(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
}
Difference(const Difference& other)
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
private:
static const int _RowsAtCompileTime = Lhs::RowsAtCompileTime,
_ColsAtCompileTime = Rhs::ColsAtCompileTime;
const Difference& _ref() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_lhs.cols(); }
Scalar _coeff(int row, int col) const
{
return m_lhs.coeff(row, col) - m_rhs.coeff(row, col);
}
protected:
const LhsRef m_lhs;
const RhsRef m_rhs;
};
/** \relates MatrixBase */
template<typename Scalar, typename Derived1, typename Derived2>
const Difference<Derived1, Derived2>
operator-(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2)
{
return Difference<Derived1, Derived2>(mat1.ref(), mat2.ref());
}
template<typename Scalar, typename Derived>
template<typename OtherDerived>
Derived &
MatrixBase<Scalar, Derived>::operator-=(const MatrixBase<Scalar, OtherDerived> &other)
{
return *this = *this - other;
}
#endif // EIGEN_DIFFERENCE_H

126
Eigen/src/Core/Dot.h Normal file
View File

@@ -0,0 +1,126 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_DOT_H
#define EIGEN_DOT_H
template<int Index, int Size, typename Derived1, typename Derived2>
struct DotUnroller
{
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
{
DotUnroller<Index-1, Size, Derived1, Derived2>::run(v1, v2, dot);
dot += v1.coeff(Index) * conj(v2.coeff(Index));
}
};
template<int Size, typename Derived1, typename Derived2>
struct DotUnroller<0, Size, Derived1, Derived2>
{
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
{
dot = v1.coeff(0) * conj(v2.coeff(0));
}
};
template<int Index, typename Derived1, typename Derived2>
struct DotUnroller<Index, Dynamic, Derived1, Derived2>
{
static void run(const Derived1&, const Derived2&, typename Derived1::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Derived1, typename Derived2>
struct DotUnroller<Index, 0, Derived1, Derived2>
{
static void run(const Derived1&, const Derived2&, typename Derived1::Scalar&) {}
};
/** \returns the dot product of *this with other.
*
* \only_for_vectors
*
* \note If the scalar type is complex numbers, then this function returns the hermitian
* (sesquilinear) dot product, linear in the first variable and anti-linear in the
* second variable.
*
* \sa norm2(), norm()
*/
template<typename Scalar, typename Derived>
template<typename OtherDerived>
Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
{
assert(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime && size() == other.size());
Scalar res;
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 16)
DotUnroller<SizeAtCompileTime-1, SizeAtCompileTime, Derived, OtherDerived>
::run(*static_cast<const Derived*>(this), other, res);
else
{
res = (*this).coeff(0) * conj(other.coeff(0));
for(int i = 1; i < size(); i++)
res += (*this).coeff(i)* conj(other.coeff(i));
}
return res;
}
/** \returns the squared norm of *this, i.e. the dot product of *this with itself.
*
* \only_for_vectors
*
* \sa dot(), norm()
*/
template<typename Scalar, typename Derived>
typename NumTraits<Scalar>::Real MatrixBase<Scalar, Derived>::norm2() const
{
return real(dot(*this));
}
/** \returns the norm of *this, i.e. the square root of the dot product of *this with itself.
*
* \only_for_vectors
*
* \sa dot(), norm2()
*/
template<typename Scalar, typename Derived>
typename NumTraits<Scalar>::Real MatrixBase<Scalar, Derived>::norm() const
{
return sqrt(norm2());
}
/** \returns an expression of the quotient of *this by its own norm.
*
* \only_for_vectors
*
* \sa norm()
*/
template<typename Scalar, typename Derived>
const ScalarMultiple<typename NumTraits<Scalar>::Real, Derived>
MatrixBase<Scalar, Derived>::normalized() const
{
return (*this) / norm();
}
#endif // EIGEN_DOT_H

126
Eigen/src/Core/DynBlock.h Normal file
View File

@@ -0,0 +1,126 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_DYNBLOCK_H
#define EIGEN_DYNBLOCK_H
/** \class DynBlock
*
* \brief Expression of a dynamic-size block
*
* \param MatrixType the type of the object in which we are taking a block
*
* This class represents an expression of a dynamic-size block. It is the return
* type of MatrixBase::dynBlock() and most of the time this is the only way it
* is used.
*
* However, if you want to directly maniputate dynamic-size block expressions,
* for instance 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_DynBlock.cpp
* Output: \verbinclude class_DynBlock.out
*
* \sa MatrixBase::dynBlock()
*/
template<typename MatrixType> class DynBlock
: public MatrixBase<typename MatrixType::Scalar, DynBlock<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, DynBlock<MatrixType> >;
DynBlock(const MatRef& matrix,
int startRow, int startCol,
int blockRows, int blockCols)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
m_blockRows(blockRows), m_blockCols(blockCols)
{
assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows()
&& startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols());
}
DynBlock(const DynBlock& other)
: m_matrix(other.m_matrix),
m_startRow(other.m_startRow), m_startCol(other.m_startCol),
m_blockRows(other.m_blockRows), m_blockCols(other.m_blockCols) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DynBlock)
private:
static const int
_RowsAtCompileTime = MatrixType::RowsAtCompileTime == 1 ? 1 : Dynamic,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime == 1 ? 1 : Dynamic;
const DynBlock& _ref() const { return *this; }
int _rows() const { return m_blockRows; }
int _cols() const { return m_blockCols; }
Scalar& _coeffRef(int row, int col)
{
return m_matrix.coeffRef(row + m_startRow, col + m_startCol);
}
Scalar _coeff(int row, int col) const
{
return m_matrix.coeff(row + m_startRow, col + m_startCol);
}
protected:
MatRef m_matrix;
const int m_startRow, m_startCol, m_blockRows, m_blockCols;
};
/** \returns a dynamic-size expression of a block in *this.
*
* \param startRow the first row in the block
* \param startCol the first column in the block
* \param blockRows the number of rows in the block
* \param blockCols the number of columns in the block
*
* Example: \include MatrixBase_dynBlock.cpp
* Output: \verbinclude MatrixBase_dynBlock.out
*
* \sa class DynBlock, block()
*/
template<typename Scalar, typename Derived>
DynBlock<Derived> MatrixBase<Scalar, Derived>
::dynBlock(int startRow, int startCol, int blockRows, int blockCols)
{
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
}
/** This is the const version of dynBlock(). */
template<typename Scalar, typename Derived>
const DynBlock<Derived> MatrixBase<Scalar, Derived>
::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const
{
return DynBlock<Derived>(ref(), startRow, startCol, blockRows, blockCols);
}
#endif // EIGEN_DYNBLOCK_H

81
Eigen/src/Core/Eval.h Normal file
View File

@@ -0,0 +1,81 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_EVAL_H
#define EIGEN_EVAL_H
/** \class Eval
*
* \brief Evaluation of an expression
*
* The template parameter Expression is the type of the expression that we are evaluating.
*
* This class is the return
* type of MatrixBase::eval() and most of the time this is the only way it
* is used.
*
* However, if you want to write a function returning an evaluation of an expression, you
* will need to use this class.
*
* Here is an example illustrating this:
* \include class_Eval.cpp
* Output: \verbinclude class_Eval.out
*
* \sa MatrixBase::eval()
*/
template<typename Expression> class Eval : NoOperatorEquals,
public Matrix< typename Expression::Scalar,
Expression::RowsAtCompileTime,
Expression::ColsAtCompileTime >
{
public:
typedef typename Expression::Scalar Scalar;
typedef Matrix<Scalar, Expression::RowsAtCompileTime, Expression::ColsAtCompileTime> MatrixType;
typedef Expression Base;
friend class MatrixBase<Scalar, Expression>;
Eval(const Expression& expression) : MatrixType(expression) {}
};
/** Evaluates *this, which can be any expression, and returns the obtained matrix.
*
* A common use case for this is the following. In an expression-templates library
* like Eigen, the coefficients of an expression are only computed as they are
* accessed, they are not computed when the expression itself is constructed. This is
* usually a good thing, as this "lazy evaluation" improves performance, but can also
* in certain cases lead to wrong results and/or to redundant computations. In such
* cases, one can restore the classical immediate-evaluation behavior by calling eval().
*
* Example: \include MatrixBase_eval.cpp
* Output: \verbinclude MatrixBase_eval.out
*
* \sa class Eval */
template<typename Scalar, typename Derived>
const Eval<Derived> MatrixBase<Scalar, Derived>::eval() const
{
return Eval<Derived>(*static_cast<const Derived*>(this));
}
#endif // EIGEN_EVAL_H

91
Eigen/src/Core/Fuzzy.h Normal file
View File

@@ -0,0 +1,91 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_FUZZY_H
#define EIGEN_FUZZY_H
template<typename Scalar, typename Derived>
template<typename OtherDerived>
bool MatrixBase<Scalar, Derived>::isApprox(
const OtherDerived& other,
const typename NumTraits<Scalar>::Real& prec
) const
{
assert(rows() == other.rows() && cols() == other.cols());
if(IsVectorAtCompileTime)
{
return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec);
}
else
{
for(int i = 0; i < cols(); i++)
if((col(i) - other.col(i)).norm2()
> std::min(col(i).norm2(), other.col(i).norm2()) * prec * prec)
return false;
return true;
}
}
template<typename Scalar, typename Derived>
bool MatrixBase<Scalar, Derived>::isMuchSmallerThan(
const typename NumTraits<Scalar>::Real& other,
const typename NumTraits<Scalar>::Real& prec
) const
{
if(IsVectorAtCompileTime)
{
return(norm2() <= abs2(other * prec));
}
else
{
for(int i = 0; i < cols(); i++)
if(col(i).norm2() > abs2(other * prec))
return false;
return true;
}
}
template<typename Scalar, typename Derived>
template<typename OtherDerived>
bool MatrixBase<Scalar, Derived>::isMuchSmallerThan(
const MatrixBase<Scalar, OtherDerived>& other,
const typename NumTraits<Scalar>::Real& prec
) const
{
assert(rows() == other.rows() && cols() == other.cols());
if(IsVectorAtCompileTime)
{
return(norm2() <= other.norm2() * prec * prec);
}
else
{
for(int i = 0; i < cols(); i++)
if(col(i).norm2() > other.col(i).norm2() * prec * prec)
return false;
return true;
}
}
#endif // EIGEN_FUZZY_H

45
Eigen/src/Core/IO.h Normal file
View File

@@ -0,0 +1,45 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_IO_H
#define EIGEN_IO_H
template<typename Scalar, typename Derived>
std::ostream & operator <<
( std::ostream & s,
const MatrixBase<Scalar, Derived> & m )
{
for( int i = 0; i < m.rows(); i++ )
{
s << m( i, 0 );
for (int j = 1; j < m.cols(); j++ )
s << " " << m( i, j );
if( i < m.rows() - 1)
s << std::endl;
}
return s;
}
#endif // EIGEN_IO_H

64
Eigen/src/Core/Identity.h Normal file
View File

@@ -0,0 +1,64 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_IDENTITY_H
#define EIGEN_IDENTITY_H
template<typename MatrixType> class Identity : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar, Identity<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Identity<MatrixType> >;
Identity(int rows) : m_rows(rows)
{
assert(rows > 0 && _RowsAtCompileTime == _ColsAtCompileTime);
}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Identity& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_rows; }
Scalar _coeff(int row, int col) const
{
return row == col ? static_cast<Scalar>(1) : static_cast<Scalar>(0);
}
protected:
int m_rows;
};
template<typename Scalar, typename Derived>
const Identity<Derived> MatrixBase<Scalar, Derived>::identity(int rows)
{
return Identity<Derived>(rows);
}
#endif // EIGEN_IDENTITY_H

148
Eigen/src/Core/Map.h Normal file
View File

@@ -0,0 +1,148 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MAP_H
#define EIGEN_MAP_H
template<typename MatrixType> class Map
: public MatrixBase<typename MatrixType::Scalar, Map<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Map<MatrixType> >;
Map(const Scalar* data, int rows, int cols) : m_data(data), m_rows(rows), m_cols(cols)
{
assert(rows > 0 && cols > 0);
}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
static const MatrixStorageOrder _StorageOrder = MatrixType::StorageOrder;
const Map& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
const Scalar& _coeff(int row, int col) const
{
if(_StorageOrder == ColumnDominant)
return m_data[row + col * m_rows];
else // RowDominant
return m_data[col + row * m_cols];
}
Scalar& _coeffRef(int row, int col)
{
if(_StorageOrder == ColumnDominant)
return const_cast<Scalar*>(m_data)[row + col * m_rows];
else // RowDominant
return const_cast<Scalar*>(m_data)[col + row * m_cols];
}
protected:
const Scalar* m_data;
int m_rows, m_cols;
};
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int rows, int cols)
{
return Map<Matrix>(data, rows, cols);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data, int size)
{
assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1)
return Map<Matrix>(data, size, 1);
else
return Map<Matrix>(data, 1, size);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(const Scalar* data)
{
return Map<Matrix>(data, _Rows, _Cols);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int rows, int cols)
{
return Map<Matrix>(data, rows, cols);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data, int size)
{
assert(_Cols == 1 || _Rows ==1);
if(_Cols == 1)
return Map<Matrix>(data, size, 1);
else
return Map<Matrix>(data, 1, size);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>::map(Scalar* data)
{
return Map<Matrix>(data, _Rows, _Cols);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data, int rows, int cols)
: Storage(rows, cols)
{
*this = map(data, rows, cols);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data, int size)
: Storage(size)
{
*this = map(data, size);
}
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
Matrix<_Scalar, _Rows, _Cols, _StorageOrder>
::Matrix(const Scalar *data)
: Storage()
{
*this = map(data);
}
#endif // EIGEN_MAP_H

View File

@@ -0,0 +1,192 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATHFUNCTIONS_H
#define EIGEN_MATHFUNCTIONS_H
template<typename T> inline typename NumTraits<T>::Real precision();
template<typename T> inline T random(T a, T b);
template<typename T> inline T random();
template<> inline int precision<int>() { return 0; }
inline int real(int x) { return x; }
inline int imag(int) { return 0; }
inline int conj(int x) { return x; }
inline int abs(int x) { return std::abs(x); }
inline int abs2(int x) { return x*x; }
inline int sqrt(int)
{
// Taking the square root of integers is not allowed
// (the square root does not always exist within the integers).
// Please cast to a floating-point type.
assert(false);
return 0;
}
template<> inline int random(int a, int b)
{
// We can't just do rand()%n as only the high-order bits are really random
return a + static_cast<int>((b-a+1) * (rand() / (RAND_MAX + 1.0)));
}
template<> inline int random()
{
return random<int>(-10, 10);
}
inline bool isMuchSmallerThan(int a, int, int = precision<int>())
{
return a == 0;
}
inline bool isApprox(int a, int b, int = precision<int>())
{
return a == b;
}
inline bool isApproxOrLessThan(int a, int b, int = precision<int>())
{
return a <= b;
}
template<> inline float precision<float>() { return 1e-5f; }
inline float real(float x) { return x; }
inline float imag(float) { return 0.f; }
inline float conj(float x) { return x; }
inline float abs(float x) { return std::abs(x); }
inline float abs2(float x) { return x*x; }
inline float sqrt(float x) { return std::sqrt(x); }
template<> inline float random(float a, float b)
{
return a + (b-a) * std::rand() / RAND_MAX;
}
template<> inline float random()
{
return random<float>(-10.0f, 10.0f);
}
inline bool isMuchSmallerThan(float a, float b, float prec = precision<float>())
{
return std::abs(a) <= std::abs(b) * prec;
}
inline bool isApprox(float a, float b, float prec = precision<float>())
{
return std::abs(a - b) <= std::min(std::abs(a), std::abs(b)) * prec;
}
inline bool isApproxOrLessThan(float a, float b, float prec = precision<float>())
{
return a <= b || isApprox(a, b, prec);
}
template<> inline double precision<double>() { return 1e-11; }
inline double real(double x) { return x; }
inline double imag(double) { return 0.; }
inline double conj(double x) { return x; }
inline double abs(double x) { return std::abs(x); }
inline double abs2(double x) { return x*x; }
inline double sqrt(double x) { return std::sqrt(x); }
template<> inline double random(double a, double b)
{
return a + (b-a) * std::rand() / RAND_MAX;
}
template<> inline double random()
{
return random<double>(-10.0, 10.0);
}
inline bool isMuchSmallerThan(double a, double b, double prec = precision<double>())
{
return std::abs(a) <= std::abs(b) * prec;
}
inline bool isApprox(double a, double b, double prec = precision<double>())
{
return std::abs(a - b) <= std::min(std::abs(a), std::abs(b)) * prec;
}
inline bool isApproxOrLessThan(double a, double b, double prec = precision<double>())
{
return a <= b || isApprox(a, b, prec);
}
template<> inline float precision<std::complex<float> >() { return precision<float>(); }
inline float real(const std::complex<float>& x) { return std::real(x); }
inline float imag(const std::complex<float>& x) { return std::imag(x); }
inline std::complex<float> conj(const std::complex<float>& x) { return std::conj(x); }
inline float abs(const std::complex<float>& x) { return std::abs(x); }
inline float abs2(const std::complex<float>& x) { return std::norm(x); }
inline std::complex<float> sqrt(const std::complex<float>&)
{
// Taking the square roots of complex numbers is not allowed,
// as this is ambiguous (there are two square roots).
// What were you trying to do?
assert(false);
return 0;
}
template<> inline std::complex<float> random()
{
return std::complex<float>(random<float>(), random<float>());
}
inline bool isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b, float prec = precision<float>())
{
return abs2(a) <= abs2(b) * prec * prec;
}
inline bool isApprox(const std::complex<float>& a, const std::complex<float>& b, float prec = precision<float>())
{
return isApprox(std::real(a), std::real(b), prec)
&& isApprox(std::imag(a), std::imag(b), prec);
}
// isApproxOrLessThan wouldn't make sense for complex numbers
template<> inline double precision<std::complex<double> >() { return precision<double>(); }
inline double real(const std::complex<double>& x) { return std::real(x); }
inline double imag(const std::complex<double>& x) { return std::imag(x); }
inline std::complex<double> conj(const std::complex<double>& x) { return std::conj(x); }
inline double abs(const std::complex<double>& x) { return std::abs(x); }
inline double abs2(const std::complex<double>& x) { return std::norm(x); }
template<> inline std::complex<double> random()
{
return std::complex<double>(random<double>(), random<double>());
}
inline bool isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b, double prec = precision<double>())
{
return abs2(a) <= abs2(b) * prec * prec;
}
inline bool isApprox(const std::complex<double>& a, const std::complex<double>& b, double prec = precision<double>())
{
return isApprox(std::real(a), std::real(b), prec)
&& isApprox(std::imag(a), std::imag(b), prec);
}
// isApproxOrLessThan wouldn't make sense for complex numbers
#define EIGEN_MAKE_MORE_OVERLOADED_COMPLEX_OPERATOR_STAR(T,U) \
inline std::complex<T> operator*(U a, const std::complex<T>& b) \
{ \
return std::complex<T>(static_cast<T>(a)*b.real(), \
static_cast<T>(a)*b.imag()); \
} \
inline std::complex<T> operator*(const std::complex<T>& b, U a) \
{ \
return std::complex<T>(static_cast<T>(a)*b.real(), \
static_cast<T>(a)*b.imag()); \
}
EIGEN_MAKE_MORE_OVERLOADED_COMPLEX_OPERATOR_STAR(int, float)
EIGEN_MAKE_MORE_OVERLOADED_COMPLEX_OPERATOR_STAR(int, double)
EIGEN_MAKE_MORE_OVERLOADED_COMPLEX_OPERATOR_STAR(float, double)
EIGEN_MAKE_MORE_OVERLOADED_COMPLEX_OPERATOR_STAR(double, float)
#endif // EIGEN_MATHFUNCTIONS_H

227
Eigen/src/Core/Matrix.h Normal file
View File

@@ -0,0 +1,227 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATRIX_H
#define EIGEN_MATRIX_H
template<typename _Scalar, int _Rows, int _Cols,
MatrixStorageOrder _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER>
class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >,
public MatrixStorage<_Scalar, _Rows, _Cols>
{
public:
friend class MatrixBase<_Scalar, Matrix>;
typedef MatrixBase<_Scalar, Matrix> Base;
typedef MatrixStorage<_Scalar, _Rows, _Cols> Storage;
typedef _Scalar Scalar;
typedef MatrixRef<Matrix> Ref;
friend class MatrixRef<Matrix>;
const Scalar* data() const
{ return Storage::m_data; }
Scalar* data()
{ return Storage::m_data; }
static const MatrixStorageOrder StorageOrder = _StorageOrder;
private:
static const int _RowsAtCompileTime = _Rows, _ColsAtCompileTime = _Cols;
Ref _ref() const { return Ref(*this); }
const Scalar& _coeff(int row, int col) const
{
if(_StorageOrder == ColumnDominant)
return (Storage::m_data)[row + col * Storage::_rows()];
else // RowDominant
return (Storage::m_data)[col + row * Storage::_cols()];
}
Scalar& _coeffRef(int row, int col)
{
if(_StorageOrder == ColumnDominant)
return (Storage::m_data)[row + col * Storage::_rows()];
else // RowDominant
return (Storage::m_data)[col + row * Storage::_cols()];
}
public:
template<typename OtherDerived>
Matrix& operator=(const MatrixBase<Scalar, OtherDerived>& other)
{
if(_RowsAtCompileTime == 1)
{
assert(other.isVector());
resize(1, other.size());
}
else if(_ColsAtCompileTime == 1)
{
assert(other.isVector());
resize(other.size(), 1);
}
else resize(other.rows(), other.cols());
return Base::operator=(other);
}
Matrix& operator=(const Matrix& other)
{
return operator=<Matrix>(other);
}
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, -=)
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, *=)
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, /=)
static const Map<Matrix> map(const Scalar* array, int rows, int cols);
static const Map<Matrix> map(const Scalar* array, int size);
static const Map<Matrix> map(const Scalar* array);
static Map<Matrix> map(Scalar* array, int rows, int cols);
static Map<Matrix> map(Scalar* array, int size);
static Map<Matrix> map(Scalar* array);
explicit Matrix() : Storage()
{
assert(_RowsAtCompileTime > 0 && _ColsAtCompileTime > 0);
}
explicit Matrix(int dim) : Storage(dim)
{
assert(dim > 0);
assert((_RowsAtCompileTime == 1
&& (_ColsAtCompileTime == Dynamic || _ColsAtCompileTime == dim))
|| (_ColsAtCompileTime == 1
&& (_RowsAtCompileTime == Dynamic || _RowsAtCompileTime == dim)));
}
// this constructor is very tricky.
// When Matrix is a fixed-size vector type of size 2,
// Matrix(x,y) should mean "construct vector with coefficients x,y".
// Otherwise, Matrix(x,y) should mean "construct matrix with x rows and y cols".
// Note that in the case of fixed-size, Storage::Storage(int,int) does nothing,
// so it is harmless to call it and afterwards we just fill the m_data array
// with the two coefficients. In the case of dynamic size, Storage::Storage(int,int)
// does what we want to, so it only remains to add some asserts.
Matrix(int x, int y) : Storage(x, y)
{
if((_RowsAtCompileTime == 1 && _ColsAtCompileTime == 2)
|| (_RowsAtCompileTime == 2 && _ColsAtCompileTime == 1))
{
(Storage::m_data)[0] = x;
(Storage::m_data)[1] = y;
}
else
{
assert(x > 0 && (_RowsAtCompileTime == Dynamic || _RowsAtCompileTime == x)
&& y > 0 && (_ColsAtCompileTime == Dynamic || _ColsAtCompileTime == y));
}
}
Matrix(const float& x, const float& y)
{
assert((_RowsAtCompileTime == 1 && _ColsAtCompileTime == 2)
|| (_RowsAtCompileTime == 2 && _ColsAtCompileTime == 1));
(Storage::m_data)[0] = x;
(Storage::m_data)[1] = y;
}
Matrix(const double& x, const double& y)
{
assert((_RowsAtCompileTime == 1 && _ColsAtCompileTime == 2)
|| (_RowsAtCompileTime == 2 && _ColsAtCompileTime == 1));
(Storage::m_data)[0] = x;
(Storage::m_data)[1] = y;
}
Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
{
assert((_RowsAtCompileTime == 1 && _ColsAtCompileTime == 3)
|| (_RowsAtCompileTime == 3 && _ColsAtCompileTime == 1));
(Storage::m_data)[0] = x;
(Storage::m_data)[1] = y;
(Storage::m_data)[2] = z;
}
Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
{
assert((_RowsAtCompileTime == 1 && _ColsAtCompileTime == 4)
|| (_RowsAtCompileTime == 4 && _ColsAtCompileTime == 1));
(Storage::m_data)[0] = x;
(Storage::m_data)[1] = y;
(Storage::m_data)[2] = z;
(Storage::m_data)[3] = w;
}
Matrix(const Scalar *data, int rows, int cols);
Matrix(const Scalar *data, int size);
explicit Matrix(const Scalar *data);
template<typename OtherDerived>
Matrix(const MatrixBase<Scalar, OtherDerived>& other)
: Storage(other.rows(), other.cols())
{
*this = other;
}
Matrix(const Matrix& other) : Storage(other.rows(), other.cols())
{
*this = other;
}
~Matrix() {}
};
#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
#undef EIGEN_MAKE_TYPEDEFS
#define EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
using Eigen::Matrix##SizeSuffix##TypeSuffix; \
using Eigen::Vector##SizeSuffix##TypeSuffix; \
using Eigen::RowVector##SizeSuffix##TypeSuffix;
#define EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(TypeSuffix) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X)
#define EIGEN_USING_MATRIX_TYPEDEFS \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(i) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(f) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(d) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(cf) \
EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(cd)
#endif // EIGEN_MATRIX_H

240
Eigen/src/Core/MatrixBase.h Normal file
View File

@@ -0,0 +1,240 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATRIXBASE_H
#define EIGEN_MATRIXBASE_H
/** \class MatrixBase
*
* \brief Base class for all matrices, vectors, and expressions
*
* This class is the base that is inherited by all matrix, vector, and expression
* types. Most of the Eigen API is contained in this class.
*
* This class takes two template parameters:
*
* \a Scalar is the type of the coefficients, e.g. float, double, etc.
*
* \a Derived is the derived type, e.g. a matrix type, or an expression, etc.
* Indeed, a separate MatrixBase type is generated for each derived type
* so one knows from inside MatrixBase, at compile-time, what the derived type is.
*
* When writing a function taking Eigen objects as argument, if you want your function
* to take as argument any matrix, vector, or expression, just let it take a
* MatrixBase argument. As an example, here is a function printFirstRow which, given
* a matrix, vector, or expression \a x, prints the first row of \a x.
*
* \code
template<typename Scalar, typename Derived>
void printFirstRow(const Eigen::MatrixBase<Scalar, Derived>& x)
{
cout << x.row(0) << endl;
}
* \endcode
*/
template<typename Scalar, typename Derived> class MatrixBase
{
public:
/** The number of rows at compile-time. This is just a copy of the value provided
* by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant.
* \sa rows(), cols(), ColsAtCompileTime, SizeAtCompileTime */
static const int RowsAtCompileTime = Derived::_RowsAtCompileTime;
/** The number of columns at compile-time. This is just a copy of the value provided
* by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant.
* \sa rows(), cols(), RowsAtCompileTime, SizeAtCompileTime */
static const int ColsAtCompileTime = Derived::_ColsAtCompileTime;
/** This is equal to the number of coefficients, i.e. the number of
* rows times the number of columns, or to \a Dynamic if this is not
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
static const int SizeAtCompileTime
= RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic
? Dynamic : RowsAtCompileTime * ColsAtCompileTime;
/** This is set to true if either the number of rows or the number of
* columns is known at compile-time to be equal to 1. Indeed, in that case,
* we are dealing with a column-vector (if there is only one column) or with
* a row-vector (if there is only one row). */
static const bool IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
/** This is the "reference type" used to pass objects of type MatrixBase as arguments
* to functions. If this MatrixBase type represents an expression, then \a Ref
* is just this MatrixBase type itself, i.e. expressions are just passed by value
* and the compiler is usually clever enough to optimize that. If, on the
* other hand, this MatrixBase type is an actual matrix or vector type, then \a Ref is
* a typedef to MatrixRef, which works as a reference, so that matrices and vectors
* are passed by reference, not by value. \sa ref()*/
typedef typename ForwardDecl<Derived>::Ref Ref;
/** This is the "real scalar" type; if the \a Scalar type is already real numbers
* (e.g. int, float or double) then RealScalar is just the same as \a Scalar. If
* \a Scalar is \a std::complex<T> then RealScalar is \a T. */
typedef typename NumTraits<Scalar>::Real RealScalar;
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
/** \returns the number of columns. \sa row(), ColsAtCompileTime*/
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
/** \returns the number of coefficients, which is \a rows()*cols().
* \sa rows(), cols(), SizeAtCompileTime. */
int size() const { return rows() * cols(); }
/** \returns true if either the number of rows or the number of columns is equal to 1.
* In other words, this function returns
* \code rows()==1 || cols()==1 \endcode
* \sa rows(), cols(), 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);
// Special case of the above template operator=, in order to prevent the compiler
//from generating a default operator= (issue hit with g++ 4.1)
Derived& operator=(const MatrixBase& other)
{
return this->operator=<Derived>(other);
}
template<typename NewScalar> const Cast<NewScalar, Derived> cast() const;
Row<Derived> row(int i);
const Row<Derived> row(int i) const;
Column<Derived> col(int i);
const Column<Derived> col(int i) const;
Minor<Derived> minor(int row, int col);
const Minor<Derived> minor(int row, int col) const;
DynBlock<Derived> dynBlock(int startRow, int startCol, int blockRows, int blockCols);
const DynBlock<Derived>
dynBlock(int startRow, int startCol, int blockRows, int blockCols) const;
template<int BlockRows, int BlockCols>
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol);
template<int BlockRows, int BlockCols>
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const;
Transpose<Derived> transpose();
const Transpose<Derived> transpose() const;
const Conjugate<Derived> conjugate() const;
const Transpose<Conjugate<Derived> > adjoint() const;
Scalar trace() const;
template<typename OtherDerived>
Scalar dot(const OtherDerived& other) const;
RealScalar norm2() const;
RealScalar norm() const;
const ScalarMultiple<RealScalar, Derived> normalized() const;
static const Eval<Random<Derived> > random(int rows, int cols);
static const Eval<Random<Derived> > random(int size);
static const Eval<Random<Derived> > random();
static const Zero<Derived> zero(int rows, int cols);
static const Zero<Derived> zero(int size);
static const Zero<Derived> zero();
static const Ones<Derived> ones(int rows, int cols);
static const Ones<Derived> ones(int size);
static const Ones<Derived> ones();
static const Identity<Derived> identity(int rows = RowsAtCompileTime);
template<typename OtherDerived>
static const DiagonalMatrix<Derived, OtherDerived>
diagonal(const OtherDerived& coeffs);
DiagonalCoeffs<Derived> diagonal();
const DiagonalCoeffs<Derived> diagonal() const;
template<typename OtherDerived>
bool isApprox(
const OtherDerived& other,
const typename NumTraits<Scalar>::Real& prec = precision<Scalar>()
) const;
bool isMuchSmallerThan(
const typename NumTraits<Scalar>::Real& other,
const typename NumTraits<Scalar>::Real& prec = precision<Scalar>()
) const;
template<typename OtherDerived>
bool isMuchSmallerThan(
const MatrixBase<Scalar, OtherDerived>& other,
const typename NumTraits<Scalar>::Real& 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>
Derived& operator+=(const MatrixBase<Scalar, OtherDerived>& other);
template<typename OtherDerived>
Derived& operator-=(const MatrixBase<Scalar, OtherDerived>& other);
template<typename OtherDerived>
Derived& operator*=(const MatrixBase<Scalar, OtherDerived>& other);
Derived& operator*=(const int& other);
Derived& operator*=(const float& other);
Derived& operator*=(const double& other);
Derived& operator*=(const std::complex<float>& other);
Derived& operator*=(const std::complex<double>& other);
Derived& operator/=(const int& other);
Derived& operator/=(const float& other);
Derived& operator/=(const double& other);
Derived& operator/=(const std::complex<float>& other);
Derived& operator/=(const std::complex<double>& other);
Scalar coeff(int row, int col) const;
Scalar operator()(int row, int col) const;
Scalar& coeffRef(int row, int col);
Scalar& operator()(int row, int col);
Scalar coeff(int index) const;
Scalar operator[](int index) const;
Scalar& coeffRef(int index);
Scalar& operator[](int index);
Scalar x() const;
Scalar y() const;
Scalar z() const;
Scalar w() const;
Scalar& x();
Scalar& y();
Scalar& z();
Scalar& w();
const Eval<Derived> eval() const EIGEN_ALWAYS_INLINE;
};
#endif // EIGEN_MATRIXBASE_H

View File

@@ -0,0 +1,63 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATRIXREF_H
#define EIGEN_MATRIXREF_H
template<typename MatrixType> class MatrixRef
: public MatrixBase<typename MatrixType::Scalar, MatrixRef<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, MatrixRef>;
MatrixRef(const MatrixType& matrix) : m_matrix(matrix) {}
MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {}
~MatrixRef() {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRef)
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }
const Scalar& _coeff(int row, int col) const
{
return m_matrix._coeff(row, col);
}
Scalar& _coeffRef(int row, int col)
{
return const_cast<MatrixType*>(&m_matrix)->_coeffRef(row, col);
}
protected:
const MatrixType& m_matrix;
};
#endif // EIGEN_MATRIXREF_H

View File

@@ -0,0 +1,183 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATRIXSTORAGE_H
#define EIGEN_MATRIXSTORAGE_H
template<typename Scalar,
int RowsAtCompileTime,
int ColsAtCompileTime>
class MatrixStorage
{
protected:
Scalar m_data[RowsAtCompileTime * ColsAtCompileTime];
void resize(int rows, int cols)
{
EIGEN_ONLY_USED_FOR_DEBUG(rows);
EIGEN_ONLY_USED_FOR_DEBUG(cols);
assert(rows == RowsAtCompileTime && cols == ColsAtCompileTime);
}
int _rows() const
{ return RowsAtCompileTime; }
int _cols() const
{ return ColsAtCompileTime; }
public:
MatrixStorage() {}
MatrixStorage(int) {}
MatrixStorage(int, int) {}
~MatrixStorage() {};
};
template<typename Scalar, int ColsAtCompileTime>
class MatrixStorage<Scalar, Dynamic, ColsAtCompileTime>
{
protected:
int m_rows;
Scalar* m_data;
void resize(int rows, int cols)
{
EIGEN_ONLY_USED_FOR_DEBUG(cols);
assert(rows > 0 && cols == ColsAtCompileTime);
if(rows > m_rows)
{
delete[] m_data;
m_data = new Scalar[rows * ColsAtCompileTime];
}
m_rows = rows;
}
int _rows() const
{ return m_rows; }
int _cols() const
{ return ColsAtCompileTime; }
public:
MatrixStorage(int dim) : m_rows(dim)
{
m_data = new Scalar[m_rows * ColsAtCompileTime];
}
MatrixStorage(int rows, int) : m_rows(rows)
{
m_data = new Scalar[m_rows * ColsAtCompileTime];
}
~MatrixStorage()
{ delete[] m_data; }
private:
MatrixStorage();
};
template<typename Scalar, int RowsAtCompileTime>
class MatrixStorage<Scalar, RowsAtCompileTime, Dynamic>
{
protected:
int m_cols;
Scalar* m_data;
void resize(int rows, int cols)
{
EIGEN_ONLY_USED_FOR_DEBUG(rows);
assert(rows == RowsAtCompileTime && cols > 0);
if(cols > m_cols)
{
delete[] m_data;
m_data = new Scalar[cols * RowsAtCompileTime];
}
m_cols = cols;
}
int _rows() const
{ return RowsAtCompileTime; }
int _cols() const
{ return m_cols; }
public:
MatrixStorage(int dim) : m_cols(dim)
{
m_data = new Scalar[m_cols * RowsAtCompileTime];
}
MatrixStorage(int, int cols) : m_cols(cols)
{
m_data = new Scalar[m_cols * RowsAtCompileTime];
}
~MatrixStorage()
{ delete[] m_data; }
private:
MatrixStorage();
};
template<typename Scalar>
class MatrixStorage<Scalar, Dynamic, Dynamic>
{
protected:
int m_rows, m_cols;
Scalar* m_data;
void resize(int rows, int cols)
{
assert(rows > 0 && cols > 0);
if(rows * cols > m_rows * m_cols)
{
delete[] m_data;
m_data = new Scalar[rows * cols];
}
m_rows = rows;
m_cols = cols;
}
int _rows() const
{ return m_rows; }
int _cols() const
{ return m_cols; }
public:
MatrixStorage(int rows, int cols) : m_rows(rows), m_cols(cols)
{
m_data = new Scalar[m_rows * m_cols];
}
~MatrixStorage()
{ delete[] m_data; }
private:
MatrixStorage();
MatrixStorage(int dim);
};
#endif // EIGEN_MATRIXSTORAGE_H

112
Eigen/src/Core/Minor.h Normal file
View File

@@ -0,0 +1,112 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MINOR_H
#define EIGEN_MINOR_H
/** \class Minor
*
* \brief Expression of a minor
*
* \param MatrixType the type of the object in which we are taking a minor
*
* This class represents an expression of a minor. It is the return
* type of MatrixBase::minor() and most of the time this is the only way it
* is used.
*
* \sa MatrixBase::minor()
*/
template<typename MatrixType> class Minor
: public MatrixBase<typename MatrixType::Scalar, Minor<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Minor<MatrixType> >;
Minor(const MatRef& matrix,
int row, int col)
: m_matrix(matrix), m_row(row), m_col(col)
{
assert(row >= 0 && row < matrix.rows()
&& col >= 0 && col < matrix.cols());
}
Minor(const Minor& other)
: m_matrix(other.m_matrix), m_row(other.m_row), m_col(other.m_col) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Minor)
private:
static const int
_RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ?
MatrixType::RowsAtCompileTime - 1 : Dynamic,
_ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ?
MatrixType::ColsAtCompileTime - 1 : Dynamic;
const Minor& _ref() const { return *this; }
int _rows() const { return m_matrix.rows() - 1; }
int _cols() const { return m_matrix.cols() - 1; }
Scalar& _coeffRef(int row, int col)
{
return m_matrix.coeffRef(row + (row >= m_row), col + (col >= m_col));
}
Scalar _coeff(int row, int col) const
{
return m_matrix.coeff(row + (row >= m_row), col + (col >= m_col));
}
protected:
MatRef m_matrix;
const int m_row, m_col;
};
/** \return an expression of the (\a row, \a col)-minor of *this,
* i.e. an expression constructed from *this by removing the specified
* row and column.
*
* Example: \include MatrixBase_minor.cpp
* Output: \verbinclude MatrixBase_minor.out
*
* \sa class Minor
*/
template<typename Scalar, typename Derived>
Minor<Derived>
MatrixBase<Scalar, Derived>::minor(int row, int col)
{
return Minor<Derived>(ref(), row, col);
}
/** This is the const version of minor(). */
template<typename Scalar, typename Derived>
const Minor<Derived>
MatrixBase<Scalar, Derived>::minor(int row, int col) const
{
return Minor<Derived>(ref(), row, col);
}
#endif // EIGEN_MINOR_H

View File

@@ -0,0 +1,63 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_NUMTRAITS_H
#define EIGEN_NUMTRAITS_H
template<typename T> struct NumTraits;
template<> struct NumTraits<int>
{
typedef int Real;
typedef double FloatingPoint;
static const bool IsComplex = false;
static const bool HasFloatingPoint = false;
};
template<> struct NumTraits<float>
{
typedef float Real;
typedef float FloatingPoint;
static const bool IsComplex = false;
static const bool HasFloatingPoint = true;
};
template<> struct NumTraits<double>
{
typedef double Real;
typedef double FloatingPoint;
static const bool IsComplex = false;
static const bool HasFloatingPoint = true;
};
template<typename _Real> struct NumTraits<std::complex<_Real> >
{
typedef _Real Real;
typedef std::complex<_Real> FloatingPoint;
static const bool IsComplex = true;
static const bool HasFloatingPoint = NumTraits<Real>::HasFloatingPoint;
};
#endif // EIGEN_NUMTRAITS_H

78
Eigen/src/Core/Ones.h Normal file
View File

@@ -0,0 +1,78 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_ONES_H
#define EIGEN_ONES_H
template<typename MatrixType> class Ones : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar, Ones<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Ones<MatrixType> >;
Ones(int rows, int cols) : m_rows(rows), m_cols(cols)
{
assert(rows > 0 && cols > 0);
}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Ones& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
Scalar _coeff(int, int) const
{
return static_cast<Scalar>(1);
}
protected:
int m_rows, m_cols;
};
template<typename Scalar, typename Derived>
const Ones<Derived> MatrixBase<Scalar, Derived>::ones(int rows, int cols)
{
return Ones<Derived>(rows, cols);
}
template<typename Scalar, typename Derived>
const Ones<Derived> MatrixBase<Scalar, Derived>::ones(int size)
{
assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Ones<Derived>(1, size);
else return Ones<Derived>(size, 1);
}
template<typename Scalar, typename Derived>
const Ones<Derived> MatrixBase<Scalar, Derived>::ones()
{
return Ones<Derived>(RowsAtCompileTime, ColsAtCompileTime);
}
#endif // EIGEN_ONES_H

View File

@@ -0,0 +1,131 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_OPERATOREQUALS_H
#define EIGEN_OPERATOREQUALS_H
template<typename Derived1, typename Derived2, int UnrollCount, int Rows>
struct MatrixOperatorEqualsUnroller
{
static const int col = (UnrollCount-1) / Rows;
static const int row = (UnrollCount-1) % Rows;
static void run(Derived1 &dst, const Derived2 &src)
{
MatrixOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1, Rows>::run(dst, src);
dst.coeffRef(row, col) = src.coeff(row, col);
}
};
// prevent buggy user code from causing an infinite recursion
template<typename Derived1, typename Derived2, int UnrollCount>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, UnrollCount, 0>
{
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2, int Rows>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 1, Rows>
{
static void run(Derived1 &dst, const Derived2 &src)
{
dst.coeffRef(0, 0) = src.coeff(0, 0);
}
};
template<typename Derived1, typename Derived2, int Rows>
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, Dynamic, Rows>
{
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2, int UnrollCount>
struct VectorOperatorEqualsUnroller
{
static const int index = UnrollCount - 1;
static void run(Derived1 &dst, const Derived2 &src)
{
VectorOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1>::run(dst, src);
dst.coeffRef(index) = src.coeff(index);
}
};
// prevent buggy user code from causing an infinite recursion
template<typename Derived1, typename Derived2>
struct VectorOperatorEqualsUnroller<Derived1, Derived2, 0>
{
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2>
struct VectorOperatorEqualsUnroller<Derived1, Derived2, 1>
{
static void run(Derived1 &dst, const Derived2 &src)
{
dst.coeffRef(0) = src.coeff(0);
}
};
template<typename Derived1, typename Derived2>
struct VectorOperatorEqualsUnroller<Derived1, Derived2, Dynamic>
{
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Scalar, typename Derived>
template<typename OtherDerived>
Derived& MatrixBase<Scalar, Derived>
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
{
if(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) // copying a vector expression into a vector
{
assert(size() == other.size());
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
VectorOperatorEqualsUnroller
<Derived, OtherDerived, SizeAtCompileTime>::run
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
else
for(int i = 0; i < size(); i++)
coeffRef(i) = other.coeff(i);
return *static_cast<Derived*>(this);
}
else // all other cases (typically, but not necessarily, copying a matrix)
{
assert(rows() == other.rows() && cols() == other.cols());
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
MatrixOperatorEqualsUnroller
<Derived, OtherDerived, SizeAtCompileTime, RowsAtCompileTime>::run
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
else
for(int j = 0; j < cols(); j++) //traverse in column-dominant order
for(int i = 0; i < rows(); i++)
coeffRef(i, j) = other.coeff(i, j);
return *static_cast<Derived*>(this);
}
}
#endif // EIGEN_OPERATOREQUALS_H

66
Eigen/src/Core/Opposite.h Normal file
View File

@@ -0,0 +1,66 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_OPPOSITE_H
#define EIGEN_OPPOSITE_H
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<MatrixType> >;
Opposite(const MatRef& matrix) : m_matrix(matrix) {}
Opposite(const Opposite& other)
: m_matrix(other.m_matrix) {}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
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:
MatRef m_matrix;
};
template<typename Scalar, typename Derived>
const Opposite<Derived>
MatrixBase<Scalar, Derived>::operator-() const
{
return Opposite<Derived>(static_cast<const Derived*>(this)->ref());
}
#endif // EIGEN_OPPOSITE_H

142
Eigen/src/Core/Product.h Normal file
View File

@@ -0,0 +1,142 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_PRODUCT_H
#define EIGEN_PRODUCT_H
template<int Index, int Size, typename Lhs, typename Rhs>
struct ProductUnroller
{
static void run(int row, int col, const Lhs& lhs, const Rhs& rhs,
typename Lhs::Scalar &res)
{
ProductUnroller<Index-1, Size, Lhs, Rhs>::run(row, col, lhs, rhs, res);
res += lhs.coeff(row, Index) * rhs.coeff(Index, col);
}
};
template<int Size, typename Lhs, typename Rhs>
struct ProductUnroller<0, Size, Lhs, Rhs>
{
static void run(int row, int col, const Lhs& lhs, const Rhs& rhs,
typename Lhs::Scalar &res)
{
res = lhs.coeff(row, 0) * rhs.coeff(0, col);
}
};
template<int Index, typename Lhs, typename Rhs>
struct ProductUnroller<Index, Dynamic, Lhs, Rhs>
{
static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Lhs, typename Rhs>
struct ProductUnroller<Index, 0, Lhs, Rhs>
{
static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {}
};
template<typename Lhs, typename Rhs> class Product : NoOperatorEquals,
public MatrixBase<typename Lhs::Scalar, Product<Lhs, Rhs> >
{
public:
typedef typename Lhs::Scalar Scalar;
typedef typename Lhs::Ref LhsRef;
typedef typename Rhs::Ref RhsRef;
friend class MatrixBase<Scalar, Product>;
Product(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
assert(lhs.cols() == rhs.rows());
}
Product(const Product& other)
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
private:
static const int _RowsAtCompileTime = Lhs::RowsAtCompileTime,
_ColsAtCompileTime = Rhs::ColsAtCompileTime;
const Product& _ref() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_rhs.cols(); }
Scalar _coeff(int row, int col) const
{
Scalar res;
if(EIGEN_UNROLLED_LOOPS
&& Lhs::ColsAtCompileTime != Dynamic && Lhs::ColsAtCompileTime <= 16)
ProductUnroller<Lhs::ColsAtCompileTime-1, Lhs::ColsAtCompileTime, LhsRef, RhsRef>
::run(row, col, m_lhs, m_rhs, res);
else
{
res = m_lhs.coeff(row, 0) * m_rhs.coeff(0, col);
for(int i = 1; i < m_lhs.cols(); i++)
res += m_lhs.coeff(row, i) * m_rhs.coeff(i, col);
}
return res;
}
protected:
const LhsRef m_lhs;
const RhsRef m_rhs;
};
template<typename Scalar, typename Derived>
template<typename OtherDerived>
const Product<Derived, OtherDerived>
MatrixBase<Scalar, Derived>::lazyProduct(const MatrixBase<Scalar, OtherDerived> &other) const
{
return Product<Derived, OtherDerived>(ref(), other.ref());
}
/** \relates MatrixBase
*
* \returns the matrix product of \a mat1 and \a mat2.
*
* \note This function causes an immediate evaluation. If you want to perform a matrix product
* without immediate evaluation, use MatrixBase::lazyProduct() instead.
*
* \sa MatrixBase::lazyProduct(), MatrixBase::operator*=(const MatrixBase&)
*/
template<typename Scalar, typename Derived1, typename Derived2>
Eval<Product<Derived1, Derived2> >
operator*(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2)
{
return mat1.lazyProduct(mat2).eval();
}
template<typename Scalar, typename Derived>
template<typename OtherDerived>
Derived &
MatrixBase<Scalar, Derived>::operator*=(const MatrixBase<Scalar, OtherDerived> &other)
{
return *this = *this * other;
}
#endif // EIGEN_PRODUCT_H

78
Eigen/src/Core/Random.h Normal file
View File

@@ -0,0 +1,78 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_RANDOM_H
#define EIGEN_RANDOM_H
template<typename MatrixType> class Random : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar, Random<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Random<MatrixType> >;
Random(int rows, int cols) : m_rows(rows), m_cols(cols)
{
assert(rows > 0 && cols > 0);
}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Random& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
Scalar _coeff(int, int) const
{
return random<Scalar>();
}
protected:
int m_rows, m_cols;
};
template<typename Scalar, typename Derived>
const Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int rows, int cols)
{
return Random<Derived>(rows, cols).eval();
}
template<typename Scalar, typename Derived>
const Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int size)
{
assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Random<Derived>(1, size).eval();
else return Random<Derived>(size, 1).eval();
}
template<typename Scalar, typename Derived>
const Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random()
{
return Random<Derived>(RowsAtCompileTime, ColsAtCompileTime).eval();
}
#endif // EIGEN_RANDOM_H

119
Eigen/src/Core/Row.h Normal file
View File

@@ -0,0 +1,119 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_ROW_H
#define EIGEN_ROW_H
/** \class Row
*
* \brief Expression of a row
*
* \param MatrixType the type of the object in which we are taking a row
*
* This class represents an expression of a row. It is the return
* type of MatrixBase::row() and most of the time this is the only way it
* is used.
*
* However, if you want to directly maniputate row expressions,
* for instance 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_Row.cpp
* Output: \verbinclude class_Row.out
*
* \sa MatrixBase::row()
*/
template<typename MatrixType> class Row
: public MatrixBase<typename MatrixType::Scalar, Row<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Row<MatrixType> >;
Row(const MatRef& matrix, int row)
: m_matrix(matrix), m_row(row)
{
assert(row >= 0 && row < matrix.rows());
}
Row(const Row& other)
: m_matrix(other.m_matrix), m_row(other.m_row) {}
template<typename OtherDerived>
Row& operator=(const MatrixBase<Scalar, OtherDerived>& other)
{
return MatrixBase<Scalar, Row<MatrixType> >::operator=(other);
}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Row)
private:
static const int _RowsAtCompileTime = 1,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Row& _ref() const { return *this; }
int _rows() const { return 1; }
int _cols() const { return m_matrix.cols(); }
Scalar& _coeffRef(int, int col)
{
return m_matrix.coeffRef(m_row, col);
}
Scalar _coeff(int, int col) const
{
return m_matrix.coeff(m_row, col);
}
protected:
MatRef m_matrix;
const int m_row;
};
/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
*
* Example: \include MatrixBase_row.cpp
* Output: \verbinclude MatrixBase_row.out
*
* \sa col(), class Row */
template<typename Scalar, typename Derived>
Row<Derived>
MatrixBase<Scalar, Derived>::row(int i)
{
return Row<Derived>(ref(), i);
}
/** This is the const version of row(). */
template<typename Scalar, typename Derived>
const Row<Derived>
MatrixBase<Scalar, Derived>::row(int i) const
{
return Row<Derived>(ref(), i);
}
#endif // EIGEN_ROW_H

View File

@@ -0,0 +1,114 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_SCALARMULTIPLE_H
#define EIGEN_SCALARMULTIPLE_H
template<typename FactorType, typename MatrixType> class ScalarMultiple : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar, ScalarMultiple<FactorType, MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, ScalarMultiple<FactorType, MatrixType> >;
ScalarMultiple(const MatRef& matrix, FactorType factor)
: m_matrix(matrix), m_factor(factor) {}
ScalarMultiple(const ScalarMultiple& other)
: m_matrix(other.m_matrix), m_factor(other.m_factor) {}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const ScalarMultiple& _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_factor * m_matrix.coeff(row, col);
}
protected:
const MatRef m_matrix;
const FactorType m_factor;
};
#define EIGEN_MAKE_SCALAR_OPS(FactorType) \
/** \relates MatrixBase */ \
template<typename Scalar, typename Derived> \
const ScalarMultiple<FactorType, Derived> \
operator*(const MatrixBase<Scalar, Derived>& matrix, \
FactorType scalar) \
{ \
return ScalarMultiple<FactorType, Derived>(matrix.ref(), scalar); \
} \
\
/** \relates MatrixBase */ \
template<typename Scalar, typename Derived> \
const ScalarMultiple<FactorType, Derived> \
operator*(FactorType scalar, \
const MatrixBase<Scalar, Derived>& matrix) \
{ \
return ScalarMultiple<FactorType, Derived>(matrix.ref(), scalar); \
} \
\
/** \relates MatrixBase */ \
template<typename Scalar, typename Derived> \
const ScalarMultiple<typename NumTraits<FactorType>::FloatingPoint, Derived> \
operator/(const MatrixBase<Scalar, Derived>& matrix, \
FactorType scalar) \
{ \
assert(NumTraits<Scalar>::HasFloatingPoint); \
return matrix * (static_cast< \
typename NumTraits<FactorType>::FloatingPoint \
>(1) / scalar); \
} \
\
template<typename Scalar, typename Derived> \
Derived & \
MatrixBase<Scalar, Derived>::operator*=(const FactorType &other) \
{ \
return *this = *this * other; \
} \
\
template<typename Scalar, typename Derived> \
Derived & \
MatrixBase<Scalar, Derived>::operator/=(const FactorType &other) \
{ \
return *this = *this / other; \
}
EIGEN_MAKE_SCALAR_OPS(int)
EIGEN_MAKE_SCALAR_OPS(float)
EIGEN_MAKE_SCALAR_OPS(double)
EIGEN_MAKE_SCALAR_OPS(std::complex<float>)
EIGEN_MAKE_SCALAR_OPS(std::complex<double>)
#undef EIGEN_MAKE_SCALAR_OPS
#endif // EIGEN_SCALARMULTIPLE_H

80
Eigen/src/Core/Sum.h Normal file
View File

@@ -0,0 +1,80 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_SUM_H
#define EIGEN_SUM_H
template<typename Lhs, typename Rhs> class Sum : NoOperatorEquals,
public MatrixBase<typename Lhs::Scalar, Sum<Lhs, Rhs> >
{
public:
typedef typename Lhs::Scalar Scalar;
typedef typename Lhs::Ref LhsRef;
typedef typename Rhs::Ref RhsRef;
friend class MatrixBase<Scalar, Sum>;
Sum(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
}
Sum(const Sum& other) : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
private:
static const int _RowsAtCompileTime = Lhs::RowsAtCompileTime,
_ColsAtCompileTime = Rhs::ColsAtCompileTime;
const Sum& _ref() const { return *this; }
int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_lhs.cols(); }
Scalar _coeff(int row, int col) const
{
return m_lhs.coeff(row, col) + m_rhs.coeff(row, col);
}
protected:
const LhsRef m_lhs;
const RhsRef m_rhs;
};
/** \relates MatrixBase */
template<typename Scalar, typename Derived1, typename Derived2>
const Sum<Derived1, Derived2>
operator+(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2)
{
return Sum<Derived1, Derived2>(mat1.ref(), mat2.ref());
}
template<typename Scalar, typename Derived>
template<typename OtherDerived>
Derived &
MatrixBase<Scalar, Derived>::operator+=(const MatrixBase<Scalar, OtherDerived>& other)
{
return *this = *this + other;
}
#endif // EIGEN_SUM_H

77
Eigen/src/Core/Trace.h Normal file
View File

@@ -0,0 +1,77 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_TRACE_H
#define EIGEN_TRACE_H
template<int Index, int Rows, typename Derived> struct TraceUnroller
{
static void run(const Derived &mat, typename Derived::Scalar &trace)
{
TraceUnroller<Index-1, Rows, Derived>::run(mat, trace);
trace += mat.coeff(Index, Index);
}
};
template<int Rows, typename Derived> struct TraceUnroller<0, Rows, Derived>
{
static void run(const Derived &mat, typename Derived::Scalar &trace)
{
trace = mat.coeff(0, 0);
}
};
template<int Index, typename Derived> struct TraceUnroller<Index, Dynamic, Derived>
{
static void run(const Derived&, typename Derived::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Derived> struct TraceUnroller<Index, 0, Derived>
{
static void run(const Derived&, typename Derived::Scalar&) {}
};
/** \returns the trace of *this, which must be a square matrix.
*
* \sa diagonal() */
template<typename Scalar, typename Derived>
Scalar MatrixBase<Scalar, Derived>::trace() const
{
assert(rows() == cols());
Scalar res;
if(EIGEN_UNROLLED_LOOPS && RowsAtCompileTime != Dynamic && RowsAtCompileTime <= 16)
TraceUnroller<RowsAtCompileTime-1, RowsAtCompileTime, Derived>
::run(*static_cast<const Derived*>(this), res);
else
{
res = coeff(0, 0);
for(int i = 1; i < rows(); i++)
res += coeff(i, i);
}
return res;
}
#endif // EIGEN_TRACE_H

View File

@@ -0,0 +1,99 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_TRANSPOSE_H
#define EIGEN_TRANSPOSE_H
/** \class Transpose
*
* \brief Expression of the transpose of a matrix
*
* \param MatrixType the type of the object of which we are taking the transpose
*
* This class represents an expression of the transpose of a matrix.
* It is the return type of MatrixBase::transpose() and MatrixBase::adjoint()
* and most of the time this is the only way it is used.
*
* \sa MatrixBase::transpose(), MatrixBase::adjoint()
*/
template<typename MatrixType> class Transpose
: public MatrixBase<typename MatrixType::Scalar, Transpose<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::Ref MatRef;
friend class MatrixBase<Scalar, Transpose<MatrixType> >;
Transpose(const MatRef& matrix) : m_matrix(matrix) {}
Transpose(const Transpose& other)
: m_matrix(other.m_matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
private:
static const int _RowsAtCompileTime = MatrixType::ColsAtCompileTime,
_ColsAtCompileTime = MatrixType::RowsAtCompileTime;
const Transpose& _ref() const { return *this; }
int _rows() const { return m_matrix.cols(); }
int _cols() const { return m_matrix.rows(); }
Scalar& _coeffRef(int row, int col)
{
return m_matrix.coeffRef(col, row);
}
Scalar _coeff(int row, int col) const
{
return m_matrix.coeff(col, row);
}
protected:
MatRef m_matrix;
};
/** \returns an expression of the transpose of *this.
*
* Example: \include MatrixBase_transpose.cpp
* Output: \verbinclude MatrixBase_transpose.out
*
* \sa adjoint(), class DiagonalCoeffs */
template<typename Scalar, typename Derived>
Transpose<Derived>
MatrixBase<Scalar, Derived>::transpose()
{
return Transpose<Derived>(ref());
}
/** This is the const version of transpose(). \sa adjoint() */
template<typename Scalar, typename Derived>
const Transpose<Derived>
MatrixBase<Scalar, Derived>::transpose() const
{
return Transpose<Derived>(ref());
}
#endif // EIGEN_TRANSPOSE_H

141
Eigen/src/Core/Util.h Normal file
View File

@@ -0,0 +1,141 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_UTIL_H
#define EIGEN_UTIL_H
#ifdef EIGEN_DONT_USE_UNROLLED_LOOPS
#define EIGEN_UNROLLED_LOOPS (false)
#else
#define EIGEN_UNROLLED_LOOPS (true)
#endif
#ifndef EIGEN_DEFAULT_MATRIX_STORAGE_ORDER
#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER ColumnDominant
#endif
#undef minor
#define USING_PART_OF_NAMESPACE_EIGEN \
EIGEN_USING_MATRIX_TYPEDEFS \
using Eigen::Matrix; \
using Eigen::MatrixBase;
#ifdef EIGEN_INTERNAL_DEBUGGING
#define eigen_internal_assert(x) assert(x);
#else
#define eigen_internal_assert(x)
#endif
#ifdef NDEBUG
#define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
#else
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
#endif
#ifdef __GNUC__
# define EIGEN_ALWAYS_INLINE __attribute__((always_inline))
#else
# define EIGEN_ALWAYS_INLINE
#endif
#define EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
template<typename OtherScalar, typename OtherDerived> \
Derived& operator Op(const MatrixBase<OtherScalar, OtherDerived>& other) \
{ \
return MatrixBase<Scalar, Derived>::operator Op(other); \
} \
Derived& operator Op(const Derived& other) \
{ \
return MatrixBase<Scalar, Derived>::operator Op(other); \
}
#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
template<typename Other> \
Derived& operator Op(const Other& scalar) \
{ \
return MatrixBase<Scalar, Derived>::operator Op(scalar); \
}
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
const int Dynamic = -1;
enum MatrixStorageOrder
{
ColumnDominant,
RowDominant
};
//forward declarations
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
class Matrix;
template<typename MatrixType> class MatrixRef;
template<typename NewScalar, typename MatrixType> class Cast;
template<typename MatrixType> class Row;
template<typename MatrixType> class Column;
template<typename MatrixType> class Minor;
template<typename MatrixType> class DynBlock;
template<typename MatrixType, int BlockRows, int BlockCols> class Block;
template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate;
template<typename MatrixType> class Opposite;
template<typename Lhs, typename Rhs> class Sum;
template<typename Lhs, typename Rhs> class Difference;
template<typename Lhs, typename Rhs> class Product;
template<typename FactorType, typename MatrixType> class ScalarMultiple;
template<typename MatrixType> class Random;
template<typename MatrixType> class Zero;
template<typename MatrixType> class Ones;
template<typename MatrixType, typename CoeffsVectorType> class DiagonalMatrix;
template<typename MatrixType> class DiagonalCoeffs;
template<typename MatrixType> class Identity;
template<typename ExpressionType> class Eval;
template<typename MatrixType> class Map;
template<typename T> struct ForwardDecl
{
typedef T Ref;
};
template<typename _Scalar, int _Rows, int _Cols, MatrixStorageOrder _StorageOrder>
struct ForwardDecl<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> >
{
typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder> > Ref;
};
//classes inheriting NoOperatorEquals don't generate a default operator=.
class NoOperatorEquals
{
private:
NoOperatorEquals& operator=(const NoOperatorEquals&);
};
#endif // EIGEN_UTIL_H

78
Eigen/src/Core/Zero.h Normal file
View File

@@ -0,0 +1,78 @@
// 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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_ZERO_H
#define EIGEN_ZERO_H
template<typename MatrixType> class Zero : NoOperatorEquals,
public MatrixBase<typename MatrixType::Scalar, Zero<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
friend class MatrixBase<Scalar, Zero<MatrixType> >;
Zero(int rows, int cols) : m_rows(rows), m_cols(cols)
{
assert(rows > 0 && cols > 0);
}
private:
static const int _RowsAtCompileTime = MatrixType::RowsAtCompileTime,
_ColsAtCompileTime = MatrixType::ColsAtCompileTime;
const Zero& _ref() const { return *this; }
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
Scalar _coeff(int, int) const
{
return static_cast<Scalar>(0);
}
protected:
int m_rows, m_cols;
};
template<typename Scalar, typename Derived>
const Zero<Derived> MatrixBase<Scalar, Derived>::zero(int rows, int cols)
{
return Zero<Derived>(rows, cols);
}
template<typename Scalar, typename Derived>
const Zero<Derived> MatrixBase<Scalar, Derived>::zero(int size)
{
assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return Zero<Derived>(1, size);
else return Zero<Derived>(size, 1);
}
template<typename Scalar, typename Derived>
const Zero<Derived> MatrixBase<Scalar, Derived>::zero()
{
return Zero<Derived>(RowsAtCompileTime, ColsAtCompileTime);
}
#endif // EIGEN_ZERO_H