mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
rename src/ to Eigen/ so that we're able to #include<Eigen/Core.h>
in the examples instead of ugly things like #include"../../src/Core.h"
This commit is contained in:
14
Eigen/CMakeLists.txt
Normal file
14
Eigen/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
FILE(GLOB Eigen_SRCS "*.h")
|
||||
|
||||
SET(INCLUDE_INSTALL_DIR
|
||||
"${CMAKE_INSTALL_PREFIX}/include/eigen2"
|
||||
CACHE PATH
|
||||
"The directory where we install the header files"
|
||||
FORCE)
|
||||
|
||||
INSTALL(FILES
|
||||
${Eigen_SRCS}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}
|
||||
)
|
||||
|
||||
add_subdirectory(Core)
|
||||
42
Eigen/Core.h
Normal file
42
Eigen/Core.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <complex>
|
||||
#include <cassert>
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
#include "Core/Util.h"
|
||||
#include "Core/NumTraits.h"
|
||||
#include "Core/MathFunctions.h"
|
||||
#include "Core/MatrixBase.h"
|
||||
#include "Core/Coeffs.h"
|
||||
#include "Core/OperatorEquals.h"
|
||||
#include "Core/MatrixRef.h"
|
||||
#include "Core/MatrixStorage.h"
|
||||
#include "Core/Matrix.h"
|
||||
#include "Core/Cast.h"
|
||||
#include "Core/Eval.h"
|
||||
#include "Core/ScalarMultiple.h"
|
||||
#include "Core/Sum.h"
|
||||
#include "Core/Difference.h"
|
||||
#include "Core/Product.h"
|
||||
#include "Core/Opposite.h"
|
||||
#include "Core/Row.h"
|
||||
#include "Core/Column.h"
|
||||
#include "Core/DynBlock.h"
|
||||
#include "Core/Block.h"
|
||||
#include "Core/Minor.h"
|
||||
#include "Core/Transpose.h"
|
||||
#include "Core/Conjugate.h"
|
||||
#include "Core/Trace.h"
|
||||
#include "Core/Dot.h"
|
||||
#include "Core/Random.h"
|
||||
#include "Core/Zero.h"
|
||||
#include "Core/Ones.h"
|
||||
#include "Core/DiagonalMatrix.h"
|
||||
#include "Core/DiagonalCoeffs.h"
|
||||
#include "Core/Identity.h"
|
||||
#include "Core/Fuzzy.h"
|
||||
#include "Core/Map.h"
|
||||
#include "Core/IO.h"
|
||||
|
||||
} // namespace Eigen
|
||||
83
Eigen/Core/Block.h
Normal file
83
Eigen/Core/Block.h
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<int BlockRows, int BlockCols>
|
||||
Block<Derived, BlockRows, BlockCols> MatrixBase<Scalar, Derived>
|
||||
::block(int startRow, int startCol) const
|
||||
{
|
||||
return Block<Derived, BlockRows, BlockCols>
|
||||
(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), startRow, startCol);
|
||||
}
|
||||
|
||||
#endif // EIGEN_BLOCK_H
|
||||
6
Eigen/Core/CMakeLists.txt
Normal file
6
Eigen/Core/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
FILE(GLOB Eigen_Core_SRCS "*.h")
|
||||
|
||||
INSTALL(FILES
|
||||
${Eigen_Core_SRCS}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/Core
|
||||
)
|
||||
68
Eigen/Core/Cast.h
Normal file
68
Eigen/Core/Cast.h
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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
|
||||
|
||||
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. */
|
||||
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
|
||||
130
Eigen/Core/Coeffs.h
Normal file
130
Eigen/Core/Coeffs.h
Normal file
@@ -0,0 +1,130 @@
|
||||
// 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
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::coeff(int row, int col, AssertLevel assertLevel = InternalDebugging) const
|
||||
{
|
||||
eigen_assert(assertLevel, row >= 0 && row < rows()
|
||||
&& col >= 0 && col < cols());
|
||||
return static_cast<const Derived *>(this)->_coeff(row, col);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::operator()(int row, int col) const { return coeff(row, col, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::coeffRef(int row, int col, AssertLevel assertLevel = InternalDebugging)
|
||||
{
|
||||
eigen_assert(assertLevel, row >= 0 && row < rows()
|
||||
&& col >= 0 && col < cols());
|
||||
return static_cast<Derived *>(this)->_coeffRef(row, col);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::operator()(int row, int col) { return coeffRef(row, col, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::coeff(int index, AssertLevel assertLevel = InternalDebugging) const
|
||||
{
|
||||
eigen_assert(assertLevel, IsVector);
|
||||
if(RowsAtCompileTime == 1)
|
||||
{
|
||||
eigen_assert(assertLevel, index >= 0 && index < cols());
|
||||
return coeff(0, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
eigen_assert(assertLevel, index >= 0 && index < rows());
|
||||
return coeff(index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::operator[](int index) const { return coeff(index, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::coeffRef(int index, AssertLevel assertLevel = InternalDebugging)
|
||||
{
|
||||
eigen_assert(assertLevel, IsVector);
|
||||
if(RowsAtCompileTime == 1)
|
||||
{
|
||||
eigen_assert(assertLevel, index >= 0 && index < cols());
|
||||
return coeffRef(0, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
eigen_assert(assertLevel, index >= 0 && index < rows());
|
||||
return coeffRef(index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::operator[](int index) { return coeffRef(index, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::x() const { return coeff(0, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::y() const { return coeff(1, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::z() const { return coeff(2, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar MatrixBase<Scalar, Derived>
|
||||
::w() const { return coeff(3, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::x() { return coeffRef(0, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::y() { return coeffRef(1, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::z() { return coeffRef(2, UserDebugging); }
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Scalar& MatrixBase<Scalar, Derived>
|
||||
::w() { return coeffRef(3, UserDebugging); }
|
||||
|
||||
|
||||
#endif // EIGEN_COEFFS_H
|
||||
79
Eigen/Core/Column.h
Normal file
79
Eigen/Core/Column.h
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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
|
||||
|
||||
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.
|
||||
* \sa row(int) */
|
||||
template<typename Scalar, typename Derived>
|
||||
Column<Derived>
|
||||
MatrixBase<Scalar, Derived>::col(int i) const
|
||||
{
|
||||
return Column<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_COLUMN_H
|
||||
73
Eigen/Core/Conjugate.h
Normal file
73
Eigen/Core/Conjugate.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
const Conjugate<Derived>
|
||||
MatrixBase<Scalar, Derived>::conjugate() const
|
||||
{
|
||||
return Conjugate<Derived>(static_cast<const Derived*>(this)->ref());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
const Transpose<Conjugate<Derived> >
|
||||
MatrixBase<Scalar, Derived>::adjoint() const
|
||||
{
|
||||
return conjugate().transpose();
|
||||
}
|
||||
|
||||
#endif // EIGEN_CONJUGATE_H
|
||||
73
Eigen/Core/DiagonalCoeffs.h
Normal file
73
Eigen/Core/DiagonalCoeffs.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
DiagonalCoeffs<Derived>
|
||||
MatrixBase<Scalar, Derived>::diagonal() const
|
||||
{
|
||||
return DiagonalCoeffs<Derived>
|
||||
(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref());
|
||||
}
|
||||
|
||||
#endif // EIGEN_DIAGONALCOEFFS_H
|
||||
72
Eigen/Core/DiagonalMatrix.h
Normal file
72
Eigen/Core/DiagonalMatrix.h
Normal 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::IsVector
|
||||
&& _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
|
||||
80
Eigen/Core/Difference.h
Normal file
80
Eigen/Core/Difference.h
Normal 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_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;
|
||||
};
|
||||
|
||||
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
|
||||
97
Eigen/Core/Dot.h
Normal file
97
Eigen/Core/Dot.h
Normal file
@@ -0,0 +1,97 @@
|
||||
// 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&) {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
Scalar MatrixBase<Scalar, Derived>::dot(const OtherDerived& other) const
|
||||
{
|
||||
assert(IsVector && OtherDerived::IsVector && 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;
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
typename NumTraits<Scalar>::Real MatrixBase<Scalar, Derived>::norm2() const
|
||||
{
|
||||
return real(dot(*this));
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
typename NumTraits<Scalar>::Real MatrixBase<Scalar, Derived>::norm() const
|
||||
{
|
||||
return sqrt(norm2());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
ScalarMultiple<Derived> MatrixBase<Scalar, Derived>::normalized() const
|
||||
{
|
||||
return (*this) / norm();
|
||||
}
|
||||
|
||||
#endif // EIGEN_DOT_H
|
||||
96
Eigen/Core/DynBlock.h
Normal file
96
Eigen/Core/DynBlock.h
Normal 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_DYNBLOCK_H
|
||||
#define EIGEN_DYNBLOCK_H
|
||||
|
||||
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
|
||||
*/
|
||||
template<typename Scalar, typename Derived>
|
||||
DynBlock<Derived> MatrixBase<Scalar, Derived>
|
||||
::dynBlock(int startRow, int startCol, int blockRows, int blockCols) const
|
||||
{
|
||||
return DynBlock<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(),
|
||||
startRow, startCol, blockRows, blockCols);
|
||||
}
|
||||
|
||||
#endif // EIGEN_DYNBLOCK_H
|
||||
49
Eigen/Core/Eval.h
Normal file
49
Eigen/Core/Eval.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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
|
||||
|
||||
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) {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Eval<Derived> MatrixBase<Scalar, Derived>::eval() const
|
||||
{
|
||||
return Eval<Derived>(*static_cast<const Derived*>(this));
|
||||
}
|
||||
|
||||
#endif // EIGEN_EVAL_H
|
||||
91
Eigen/Core/Fuzzy.h
Normal file
91
Eigen/Core/Fuzzy.h
Normal 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(IsVector)
|
||||
{
|
||||
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(IsVector)
|
||||
{
|
||||
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(IsVector)
|
||||
{
|
||||
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/Core/IO.h
Normal file
45
Eigen/Core/IO.h
Normal 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/Core/Identity.h
Normal file
64
Eigen/Core/Identity.h
Normal 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
|
||||
134
Eigen/Core/Map.h
Normal file
134
Eigen/Core/Map.h
Normal file
@@ -0,0 +1,134 @@
|
||||
// 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;
|
||||
|
||||
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
|
||||
{
|
||||
return m_data[row + col * m_rows];
|
||||
}
|
||||
|
||||
Scalar& _coeffRef(int row, int col)
|
||||
{
|
||||
return const_cast<Scalar*>(m_data)[row + col * m_rows];
|
||||
}
|
||||
|
||||
protected:
|
||||
const Scalar* m_data;
|
||||
int m_rows, m_cols;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int rows, int cols)
|
||||
{
|
||||
return Map<Derived>(const_cast<Scalar*>(data), rows, cols);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data, int size)
|
||||
{
|
||||
assert(IsVector);
|
||||
if(ColsAtCompileTime == 1)
|
||||
return Map<Derived>(const_cast<Scalar*>(data), size, 1);
|
||||
else
|
||||
return Map<Derived>(const_cast<Scalar*>(data), 1, size);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
const Map<Derived> MatrixBase<Scalar, Derived>::map(const Scalar* data)
|
||||
{
|
||||
return Map<Derived>(const_cast<Scalar*>(data), RowsAtCompileTime, ColsAtCompileTime);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int rows, int cols)
|
||||
{
|
||||
return Map<Derived>(data, rows, cols);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data, int size)
|
||||
{
|
||||
assert(IsVector);
|
||||
if(ColsAtCompileTime == 1)
|
||||
return Map<Derived>(data, size, 1);
|
||||
else
|
||||
return Map<Derived>(data, 1, size);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Map<Derived> MatrixBase<Scalar, Derived>::map(Scalar* data)
|
||||
{
|
||||
return Map<Derived>(data, RowsAtCompileTime, ColsAtCompileTime);
|
||||
}
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
Matrix<_Scalar, _Rows, _Cols>
|
||||
::Matrix(const Scalar *data, int rows, int cols)
|
||||
: Storage(rows, cols)
|
||||
{
|
||||
*this = map(data, rows, cols);
|
||||
}
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
Matrix<_Scalar, _Rows, _Cols>
|
||||
::Matrix(const Scalar *data, int size)
|
||||
: Storage(size)
|
||||
{
|
||||
*this = map(data, size);
|
||||
}
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
Matrix<_Scalar, _Rows, _Cols>
|
||||
::Matrix(const Scalar *data)
|
||||
: Storage()
|
||||
{
|
||||
*this = map(data);
|
||||
}
|
||||
|
||||
#endif // EIGEN_MAP_H
|
||||
175
Eigen/Core/MathFunctions.h
Normal file
175
Eigen/Core/MathFunctions.h
Normal file
@@ -0,0 +1,175 @@
|
||||
// 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
|
||||
|
||||
#endif // EIGEN_MATHFUNCTIONS_H
|
||||
202
Eigen/Core/Matrix.h
Normal file
202
Eigen/Core/Matrix.h
Normal file
@@ -0,0 +1,202 @@
|
||||
// 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>
|
||||
class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
|
||||
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; }
|
||||
|
||||
private:
|
||||
static const int _RowsAtCompileTime = _Rows, _ColsAtCompileTime = _Cols;
|
||||
|
||||
Ref _ref() const { return Ref(*this); }
|
||||
|
||||
const Scalar& _coeff(int row, int col) const
|
||||
{
|
||||
return data()[row + col * Storage::_rows()];
|
||||
}
|
||||
|
||||
Scalar& _coeffRef(int row, int col)
|
||||
{
|
||||
return data()[row + col * Storage::_rows()];
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename OtherDerived>
|
||||
Matrix& operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
|
||||
Matrix& operator=(const Matrix& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, -=)
|
||||
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, *=)
|
||||
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, /=)
|
||||
|
||||
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
|
||||
222
Eigen/Core/MatrixBase.h
Normal file
222
Eigen/Core/MatrixBase.h
Normal file
@@ -0,0 +1,222 @@
|
||||
// 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:
|
||||
* \param Scalar the type of the coefficients, e.g. float, double, etc.
|
||||
* \param Derived 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 and of columns at compile-time. These are just
|
||||
* copies of the values 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(), SizeAtCompileTime */
|
||||
static const int RowsAtCompileTime = Derived::_RowsAtCompileTime,
|
||||
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 IsVector = 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 supposed to be clever enough to optimize that. If, on the
|
||||
* other hand, this MatrixBase type is an actual matrix or vector, then \a Ref is
|
||||
* a typedef MatrixRef, which is like 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
|
||||
* \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(). */
|
||||
int size() const { return rows() * cols(); }
|
||||
|
||||
/** \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;
|
||||
Column<Derived> col(int i) const;
|
||||
Minor<Derived> minor(int row, int col) 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) 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;
|
||||
ScalarMultiple<Derived> normalized() const;
|
||||
|
||||
static Eval<Random<Derived> > random(int rows, int cols);
|
||||
static Eval<Random<Derived> > random(int size);
|
||||
static 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;
|
||||
|
||||
static const Map<Derived> map(const Scalar* array, int rows, int cols);
|
||||
static const Map<Derived> map(const Scalar* array, int size);
|
||||
static const Map<Derived> map(const Scalar* array);
|
||||
static Map<Derived> map(Scalar* array, int rows, int cols);
|
||||
static Map<Derived> map(Scalar* array, int size);
|
||||
static Map<Derived> map(Scalar* array);
|
||||
|
||||
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, AssertLevel assertLevel) const;
|
||||
Scalar operator()(int row, int col) const;
|
||||
|
||||
Scalar& coeffRef(int row, int col, AssertLevel assertLevel);
|
||||
Scalar& operator()(int row, int col);
|
||||
|
||||
Scalar coeff(int index, AssertLevel assertLevel) const;
|
||||
Scalar operator[](int index) const;
|
||||
|
||||
Scalar& coeffRef(int index, AssertLevel assertLevel);
|
||||
Scalar& operator[](int index);
|
||||
|
||||
Scalar x() const;
|
||||
Scalar y() const;
|
||||
Scalar z() const;
|
||||
Scalar w() const;
|
||||
Scalar& x();
|
||||
Scalar& y();
|
||||
Scalar& z();
|
||||
Scalar& w();
|
||||
|
||||
Eval<Derived> eval() const EIGEN_ALWAYS_INLINE;
|
||||
};
|
||||
|
||||
#endif // EIGEN_MATRIXBASE_H
|
||||
63
Eigen/Core/MatrixRef.h
Normal file
63
Eigen/Core/MatrixRef.h
Normal 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(*const_cast<MatrixType*>(&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 m_matrix.coeffRef(row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatrixType& m_matrix;
|
||||
};
|
||||
|
||||
#endif // EIGEN_MATRIXREF_H
|
||||
183
Eigen/Core/MatrixStorage.h
Normal file
183
Eigen/Core/MatrixStorage.h
Normal 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
|
||||
86
Eigen/Core/Minor.h
Normal file
86
Eigen/Core/Minor.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// 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
|
||||
|
||||
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. */
|
||||
template<typename Scalar, typename Derived>
|
||||
Minor<Derived>
|
||||
MatrixBase<Scalar, Derived>::minor(int row, int col) const
|
||||
{
|
||||
return Minor<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), row, col);
|
||||
}
|
||||
|
||||
#endif // EIGEN_MINOR_H
|
||||
59
Eigen/Core/NumTraits.h
Normal file
59
Eigen/Core/NumTraits.h
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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;
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = false;
|
||||
};
|
||||
|
||||
template<> struct NumTraits<float>
|
||||
{
|
||||
typedef float Real;
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = true;
|
||||
};
|
||||
|
||||
template<> struct NumTraits<double>
|
||||
{
|
||||
typedef double Real;
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = true;
|
||||
};
|
||||
|
||||
template<typename _Real> struct NumTraits<std::complex<_Real> >
|
||||
{
|
||||
typedef _Real Real;
|
||||
static const bool IsComplex = true;
|
||||
static const bool HasFloatingPoint = NumTraits<Real>::HasFloatingPoint;
|
||||
};
|
||||
|
||||
#endif // EIGEN_NUMTRAITS_H
|
||||
78
Eigen/Core/Ones.h
Normal file
78
Eigen/Core/Ones.h
Normal 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(IsVector);
|
||||
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
|
||||
82
Eigen/Core/OperatorEquals.h
Normal file
82
Eigen/Core/OperatorEquals.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// 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 OperatorEqualsUnroller
|
||||
{
|
||||
static const int col = (UnrollCount-1) / Rows;
|
||||
static const int row = (UnrollCount-1) % Rows;
|
||||
|
||||
static void run(Derived1 &dst, const Derived2 &src)
|
||||
{
|
||||
OperatorEqualsUnroller<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 OperatorEqualsUnroller<Derived1, Derived2, UnrollCount, 0>
|
||||
{
|
||||
static void run(Derived1 &, const Derived2 &) {}
|
||||
};
|
||||
|
||||
template<typename Derived1, typename Derived2, int Rows>
|
||||
struct OperatorEqualsUnroller<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 OperatorEqualsUnroller<Derived1, Derived2, Dynamic, Rows>
|
||||
{
|
||||
static void run(Derived1 &, const Derived2 &) {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
Derived& MatrixBase<Scalar, Derived>
|
||||
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
||||
{
|
||||
assert(rows() == other.rows() && cols() == other.cols());
|
||||
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
|
||||
OperatorEqualsUnroller
|
||||
<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/Core/Opposite.h
Normal file
66
Eigen/Core/Opposite.h
Normal 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
|
||||
133
Eigen/Core/Product.h
Normal file
133
Eigen/Core/Product.h
Normal file
@@ -0,0 +1,133 @@
|
||||
// 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());
|
||||
}
|
||||
|
||||
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/Core/Random.h
Normal file
78
Eigen/Core/Random.h
Normal 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>
|
||||
Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int rows, int cols)
|
||||
{
|
||||
return Random<Derived>(rows, cols).eval();
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random(int size)
|
||||
{
|
||||
assert(IsVector);
|
||||
if(RowsAtCompileTime == 1) return Random<Derived>(1, size).eval();
|
||||
else return Random<Derived>(size, 1).eval();
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Eval<Random<Derived> > MatrixBase<Scalar, Derived>::random()
|
||||
{
|
||||
return Random<Derived>(RowsAtCompileTime, ColsAtCompileTime).eval();
|
||||
}
|
||||
|
||||
#endif // EIGEN_RANDOM_H
|
||||
87
Eigen/Core/Row.h
Normal file
87
Eigen/Core/Row.h
Normal file
@@ -0,0 +1,87 @@
|
||||
// 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
|
||||
|
||||
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.
|
||||
* \sa col(int)*/
|
||||
template<typename Scalar, typename Derived>
|
||||
Row<Derived>
|
||||
MatrixBase<Scalar, Derived>::row(int i) const
|
||||
{
|
||||
return Row<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_ROW_H
|
||||
109
Eigen/Core/ScalarMultiple.h
Normal file
109
Eigen/Core/ScalarMultiple.h
Normal file
@@ -0,0 +1,109 @@
|
||||
// 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 MatrixType> class ScalarMultiple : NoOperatorEquals,
|
||||
public MatrixBase<typename MatrixType::Scalar, ScalarMultiple<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class MatrixBase<typename MatrixType::Scalar, ScalarMultiple<MatrixType> >;
|
||||
|
||||
ScalarMultiple(const MatRef& matrix, Scalar scalar)
|
||||
: m_matrix(matrix), m_scalar(scalar) {}
|
||||
|
||||
ScalarMultiple(const ScalarMultiple& other)
|
||||
: m_matrix(other.m_matrix), m_scalar(other.m_scalar) {}
|
||||
|
||||
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_matrix.coeff(row, col) * m_scalar;
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatRef m_matrix;
|
||||
const Scalar m_scalar;
|
||||
};
|
||||
|
||||
#define EIGEN_MAKE_SCALAR_OPS(OtherScalar) \
|
||||
template<typename Scalar, typename Derived> \
|
||||
const ScalarMultiple<Derived> \
|
||||
operator*(const MatrixBase<Scalar, Derived>& matrix, \
|
||||
OtherScalar scalar) \
|
||||
{ \
|
||||
return ScalarMultiple<Derived>(matrix.ref(), scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
const ScalarMultiple<Derived> \
|
||||
operator*(OtherScalar scalar, \
|
||||
const MatrixBase<Scalar, Derived>& matrix) \
|
||||
{ \
|
||||
return ScalarMultiple<Derived>(matrix.ref(), scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
const ScalarMultiple<Derived> \
|
||||
operator/(const MatrixBase<Scalar, Derived>& matrix, \
|
||||
OtherScalar scalar) \
|
||||
{ \
|
||||
assert(NumTraits<Scalar>::HasFloatingPoint); \
|
||||
return matrix * (static_cast<Scalar>(1) / scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
MatrixBase<Scalar, Derived>::operator*=(const OtherScalar &other) \
|
||||
{ \
|
||||
return *this = *this * other; \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
MatrixBase<Scalar, Derived>::operator/=(const OtherScalar &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
|
||||
79
Eigen/Core/Sum.h
Normal file
79
Eigen/Core/Sum.h
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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;
|
||||
};
|
||||
|
||||
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
|
||||
74
Eigen/Core/Trace.h
Normal file
74
Eigen/Core/Trace.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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&) {}
|
||||
};
|
||||
|
||||
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
|
||||
73
Eigen/Core/Transpose.h
Normal file
73
Eigen/Core/Transpose.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Transpose<Derived>
|
||||
MatrixBase<Scalar, Derived>::transpose() const
|
||||
{
|
||||
return Transpose<Derived>(static_cast<Derived*>(const_cast<MatrixBase*>(this))->ref());
|
||||
}
|
||||
|
||||
#endif // EIGEN_TRANSPOSE_H
|
||||
137
Eigen/Core/Util.h
Normal file
137
Eigen/Core/Util.h
Normal file
@@ -0,0 +1,137 @@
|
||||
// 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
|
||||
|
||||
#undef minor
|
||||
|
||||
#define USING_EIGEN_DATA_TYPES \
|
||||
EIGEN_USING_MATRIX_TYPEDEFS \
|
||||
using Eigen::Matrix;
|
||||
|
||||
#ifdef EIGEN_INTERNAL_DEBUGGING
|
||||
#define EIGEN_ASSERT_LEVEL 2
|
||||
#else
|
||||
#define EIGEN_ASSERT_LEVEL 1
|
||||
#endif
|
||||
|
||||
#define eigen_assert(assertLevel, x) if(assertLevel <= EIGEN_ASSERT_LEVEL) assert(x);
|
||||
|
||||
#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, /=)
|
||||
|
||||
//forward declarations
|
||||
template<typename _Scalar, int _Rows, int _Cols> 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 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>
|
||||
struct ForwardDecl<Matrix<_Scalar, _Rows, _Cols> >
|
||||
{
|
||||
typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols> > Ref;
|
||||
};
|
||||
|
||||
const int Dynamic = -1;
|
||||
|
||||
enum AssertLevel
|
||||
{
|
||||
UserDebugging = 1,
|
||||
InternalDebugging = 2
|
||||
};
|
||||
|
||||
//classes inheriting NoOperatorEquals don't generate a default operator=.
|
||||
class NoOperatorEquals
|
||||
{
|
||||
private:
|
||||
NoOperatorEquals& operator=(const NoOperatorEquals&);
|
||||
};
|
||||
|
||||
#endif // EIGEN_UTIL_H
|
||||
78
Eigen/Core/Zero.h
Normal file
78
Eigen/Core/Zero.h
Normal 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(IsVector);
|
||||
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
|
||||
Reference in New Issue
Block a user