mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
reorganisation of headers, commit47b935fc42cbf2ca992d8a270bc1b0fc97d1f6bc
/2....
This commit is contained in:
84
src/Core/Block.h
Normal file
84
src/Core/Block.h
Normal file
@@ -0,0 +1,84 @@
|
||||
// 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 EI_BLOCK_H
|
||||
#define EI_BLOCK_H
|
||||
|
||||
template<typename MatrixType> class EiBlock
|
||||
: public EiObject<typename MatrixType::Scalar, EiBlock<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiBlock<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = EiDynamic,
|
||||
ColsAtCompileTime = EiDynamic;
|
||||
|
||||
EiBlock(const MatRef& matrix,
|
||||
int startRow, int endRow,
|
||||
int startCol = 0, int endCol = 0)
|
||||
: m_matrix(matrix), m_startRow(startRow), m_endRow(endRow),
|
||||
m_startCol(startCol), m_endCol(endCol)
|
||||
{
|
||||
assert(startRow >= 0 && startRow <= endRow && endRow < matrix.rows()
|
||||
&& startCol >= 0 && startCol <= endCol && endCol < matrix.cols());
|
||||
}
|
||||
|
||||
EiBlock(const EiBlock& other)
|
||||
: m_matrix(other.m_matrix), m_startRow(other.m_startRow), m_endRow(other.m_endRow),
|
||||
m_startCol(other.m_startCol), m_endCol(other.m_endCol) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiBlock)
|
||||
|
||||
private:
|
||||
EiBlock& _ref() { return *this; }
|
||||
const EiBlock& _constRef() const { return *this; }
|
||||
int _rows() const { return m_endRow - m_startRow + 1; }
|
||||
int _cols() const { return m_endCol - m_startCol + 1; }
|
||||
|
||||
Scalar& _write(int row, int col=0)
|
||||
{
|
||||
return m_matrix.write(row + m_startRow, col + m_startCol);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col=0) const
|
||||
{
|
||||
return m_matrix.read(row + m_startRow, col + m_startCol);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_startRow, m_endRow, m_startCol, m_endCol;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiBlock<Derived>
|
||||
EiObject<Scalar, Derived>::block(int startRow, int endRow, int startCol, int endCol)
|
||||
{
|
||||
return EiBlock<Derived>(static_cast<Derived*>(this)->ref(), startRow, endRow, startCol, endCol);
|
||||
}
|
||||
|
||||
#endif // EI_BLOCK_H
|
||||
6
src/Core/CMakeLists.txt
Normal file
6
src/Core/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
FILE(GLOB Eigen_internal_SRCS "*.h")
|
||||
|
||||
INSTALL(FILES
|
||||
${Eigen_internal_SRCS}
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/internal
|
||||
)
|
||||
83
src/Core/Column.h
Normal file
83
src/Core/Column.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 EI_COLUMN_H
|
||||
#define EI_COLUMN_H
|
||||
|
||||
template<typename MatrixType> class EiColumn
|
||||
: public EiObject<typename MatrixType::Scalar, EiColumn<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiColumn<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = 1;
|
||||
|
||||
EiColumn(const MatRef& matrix, int col)
|
||||
: m_matrix(matrix), m_col(col)
|
||||
{
|
||||
EI_CHECK_COL_RANGE(matrix, col);
|
||||
}
|
||||
|
||||
EiColumn(const EiColumn& other)
|
||||
: m_matrix(other.m_matrix), m_col(other.m_col) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiColumn)
|
||||
|
||||
private:
|
||||
EiColumn& _ref() { return *this; }
|
||||
const EiColumn& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return 1; }
|
||||
|
||||
Scalar& _write(int row, int col=0)
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.write(row, m_col);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col=0) const
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.read(row, m_col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_col;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiColumn<Derived>
|
||||
EiObject<Scalar, Derived>::col(int i)
|
||||
{
|
||||
return EiColumn<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_COLUMN_H
|
||||
69
src/Core/Conjugate.h
Normal file
69
src/Core/Conjugate.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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 EI_CONJUGATE_H
|
||||
#define EI_CONJUGATE_H
|
||||
|
||||
template<typename MatrixType> class EiConjugate
|
||||
: public EiObject<typename MatrixType::Scalar, EiConjugate<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiConjugate<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
||||
|
||||
EiConjugate(const MatRef& matrix) : m_matrix(matrix) {}
|
||||
|
||||
EiConjugate(const EiConjugate& other)
|
||||
: m_matrix(other.m_matrix) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiConjugate)
|
||||
|
||||
private:
|
||||
EiConjugate& _ref() { return *this; }
|
||||
const EiConjugate& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return EiConj(m_matrix.read(row, col));
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiConjugate<Derived>
|
||||
EiObject<Scalar, Derived>::conjugate()
|
||||
{
|
||||
return EiConjugate<Derived>(static_cast<Derived*>(this)->ref());
|
||||
}
|
||||
|
||||
#endif // EI_CONJUGATE_H
|
||||
51
src/Core/Eval.h
Normal file
51
src/Core/Eval.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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 EI_EVAL_H
|
||||
#define EI_EVAL_H
|
||||
|
||||
template<typename Expression> class EiEval
|
||||
: public EiMatrix< typename Expression::Scalar,
|
||||
Expression::RowsAtCompileTime,
|
||||
Expression::ColsAtCompileTime >
|
||||
{
|
||||
public:
|
||||
typedef typename Expression::Scalar Scalar;
|
||||
typedef EiMatrix<Scalar, Expression::RowsAtCompileTime, Expression::ColsAtCompileTime> MatrixType;
|
||||
typedef Expression Base;
|
||||
friend class EiObject<Scalar, Expression>;
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval)
|
||||
|
||||
EiEval(const Expression& expression) : MatrixType(expression) {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiEval<Derived> EiObject<Scalar, Derived>::eval() const
|
||||
{
|
||||
return EiEval<Derived>(*static_cast<const Derived*>(this));
|
||||
}
|
||||
|
||||
#endif // EI_EVAL_H
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
|
||||
//
|
||||
// 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
|
||||
@@ -23,10 +23,32 @@
|
||||
// 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 EI_CORE_H
|
||||
#define EI_CORE_H
|
||||
#ifndef EI_LOOP_H
|
||||
#define EI_LOOP_H
|
||||
|
||||
//#include "internal/Vector.h"
|
||||
#include "internal/Matrix.h"
|
||||
template<int UnrollCount, int Rows> class EiLoop
|
||||
{
|
||||
static const int col = (UnrollCount-1) / Rows;
|
||||
static const int row = (UnrollCount-1) % Rows;
|
||||
|
||||
#endif // EI_CORE_H
|
||||
public:
|
||||
template <typename Derived1, typename Derived2>
|
||||
static void copy(Derived1 &dst, const Derived2 &src)
|
||||
{
|
||||
EiLoop<UnrollCount-1, Rows>::copy(dst, src);
|
||||
dst.write(row, col) = src.read(row, col);
|
||||
}
|
||||
};
|
||||
|
||||
template<int Rows> class EiLoop<0, Rows>
|
||||
{
|
||||
public:
|
||||
template <typename Derived1, typename Derived2>
|
||||
static void copy(Derived1 &dst, const Derived2 &src)
|
||||
{
|
||||
EI_UNUSED(dst);
|
||||
EI_UNUSED(src);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // EI_LOOP_H
|
||||
131
src/Core/Matrix.h
Normal file
131
src/Core/Matrix.h
Normal file
@@ -0,0 +1,131 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 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 EI_MATRIX_H
|
||||
#define EI_MATRIX_H
|
||||
|
||||
#include "Util.h"
|
||||
#include "Numeric.h"
|
||||
#include "Object.h"
|
||||
#include "MatrixRef.h"
|
||||
#include "MatrixStorage.h"
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >,
|
||||
public EiMatrixStorage<_Scalar, _Rows, _Cols>
|
||||
{
|
||||
public:
|
||||
friend class EiObject<_Scalar, EiMatrix>;
|
||||
typedef EiObject<_Scalar, EiMatrix> Base;
|
||||
typedef EiMatrixStorage<_Scalar, _Rows, _Cols> Storage;
|
||||
typedef _Scalar Scalar;
|
||||
typedef EiMatrixRef<EiMatrix> Ref;
|
||||
typedef EiMatrixConstRef<EiMatrix> ConstRef;
|
||||
friend class EiMatrixRef<EiMatrix>;
|
||||
friend class EiMatrixConstRef<EiMatrix>;
|
||||
|
||||
static const int RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols;
|
||||
|
||||
const Scalar* array() const
|
||||
{ return Storage::m_array; }
|
||||
|
||||
Scalar* array()
|
||||
{ return Storage::m_array; }
|
||||
|
||||
private:
|
||||
Ref _ref() { return Ref(*this); }
|
||||
ConstRef _constRef() const { return ConstRef(*this); }
|
||||
|
||||
const Scalar& _read(int row, int col) const
|
||||
{
|
||||
EI_CHECK_RANGES(*this, row, col);
|
||||
return array()[row + col * Storage::_rows()];
|
||||
}
|
||||
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
EI_CHECK_RANGES(*this, row, col);
|
||||
return array()[row + col * Storage::_rows()];
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename OtherDerived>
|
||||
EiMatrix& operator=(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
|
||||
EiMatrix& operator=(const EiMatrix& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATOR(EiMatrix, +=)
|
||||
EI_INHERIT_ASSIGNMENT_OPERATOR(EiMatrix, -=)
|
||||
EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(EiMatrix, *=)
|
||||
EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(EiMatrix, /=)
|
||||
|
||||
explicit EiMatrix(int rows = 1, int cols = 1) : Storage(rows, cols) {}
|
||||
template<typename OtherDerived>
|
||||
EiMatrix(const EiObject<Scalar, OtherDerived>& other) : Storage(other.rows(), other.cols())
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
EiMatrix(const EiMatrix& other) : Storage(other.rows(), other.cols())
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
~EiMatrix() {}
|
||||
};
|
||||
|
||||
#define EI_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
|
||||
typedef EiMatrix<Type, Size, Size> EiMatrix##SizeSuffix##TypeSuffix; \
|
||||
typedef EiMatrix<Type, Size, 1> EiVector##SizeSuffix##TypeSuffix; \
|
||||
typedef EiMatrix<Type, 1, Size> EiRowVector##SizeSuffix##TypeSuffix;
|
||||
|
||||
#define EI_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
|
||||
EI_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
|
||||
EI_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
|
||||
EI_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
|
||||
EI_MAKE_TYPEDEFS(Type, TypeSuffix, EiDynamic, X)
|
||||
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(int, i)
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(float, f)
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(double, d)
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<int>, ci)
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
|
||||
EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
|
||||
|
||||
#undef EI_MAKE_TYPEDEFS_ALL_SIZES
|
||||
#undef EI_MAKE_TYPEDEFS
|
||||
|
||||
#include "Eval.h"
|
||||
#include "MatrixOps.h"
|
||||
#include "ScalarOps.h"
|
||||
|
||||
|
||||
#endif // EI_MATRIX_H
|
||||
210
src/Core/MatrixOps.h
Normal file
210
src/Core/MatrixOps.h
Normal file
@@ -0,0 +1,210 @@
|
||||
// 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 EI_MATRIXOPS_H
|
||||
#define EI_MATRIXOPS_H
|
||||
|
||||
template<typename Lhs, typename Rhs> class EiSum
|
||||
: public EiObject<typename Lhs::Scalar, EiSum<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
typedef typename Lhs::ConstRef LhsRef;
|
||||
typedef typename Rhs::ConstRef RhsRef;
|
||||
friend class EiObject<Scalar, EiSum>;
|
||||
|
||||
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Rhs::ColsAtCompileTime;
|
||||
|
||||
EiSum(const LhsRef& lhs, const RhsRef& rhs)
|
||||
: m_lhs(lhs), m_rhs(rhs)
|
||||
{
|
||||
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
|
||||
}
|
||||
|
||||
EiSum(const EiSum& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiSum)
|
||||
|
||||
private:
|
||||
|
||||
const EiSum& _ref() const { return *this; }
|
||||
const EiSum& _constRef() const { return *this; }
|
||||
int _rows() const { return m_lhs.rows(); }
|
||||
int _cols() const { return m_lhs.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return m_lhs.read(row, col) + m_rhs.read(row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
const LhsRef m_lhs;
|
||||
const RhsRef m_rhs;
|
||||
};
|
||||
|
||||
template<typename Lhs, typename Rhs> class EiDifference
|
||||
: public EiObject<typename Lhs::Scalar, EiDifference<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
typedef typename Lhs::ConstRef LhsRef;
|
||||
typedef typename Rhs::ConstRef RhsRef;
|
||||
friend class EiObject<Scalar, EiDifference>;
|
||||
|
||||
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Rhs::ColsAtCompileTime;
|
||||
|
||||
EiDifference(const LhsRef& lhs, const RhsRef& rhs)
|
||||
: m_lhs(lhs), m_rhs(rhs)
|
||||
{
|
||||
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
|
||||
}
|
||||
|
||||
EiDifference(const EiDifference& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiDifference)
|
||||
|
||||
private:
|
||||
const EiDifference& _ref() const { return *this; }
|
||||
const EiDifference& _constRef() const { return *this; }
|
||||
int _rows() const { return m_lhs.rows(); }
|
||||
int _cols() const { return m_lhs.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return m_lhs.read(row, col) - m_rhs.read(row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
const LhsRef m_lhs;
|
||||
const RhsRef m_rhs;
|
||||
};
|
||||
|
||||
template<typename Lhs, typename Rhs> class EiMatrixProduct
|
||||
: public EiObject<typename Lhs::Scalar, EiMatrixProduct<Lhs, Rhs> >
|
||||
{
|
||||
public:
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
typedef typename Lhs::ConstRef LhsRef;
|
||||
typedef typename Rhs::ConstRef RhsRef;
|
||||
friend class EiObject<Scalar, EiMatrixProduct>;
|
||||
|
||||
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Rhs::ColsAtCompileTime;
|
||||
|
||||
EiMatrixProduct(const LhsRef& lhs, const RhsRef& rhs)
|
||||
: m_lhs(lhs), m_rhs(rhs)
|
||||
{
|
||||
assert(lhs.cols() == rhs.rows());
|
||||
}
|
||||
|
||||
EiMatrixProduct(const EiMatrixProduct& other)
|
||||
: m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiMatrixProduct)
|
||||
|
||||
private:
|
||||
const EiMatrixProduct& _ref() const { return *this; }
|
||||
const EiMatrixProduct& _constRef() const { return *this; }
|
||||
int _rows() const { return m_lhs.rows(); }
|
||||
int _cols() const { return m_rhs.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
if(Lhs::ColsAtCompileTime == 3)
|
||||
{
|
||||
return m_lhs(row,0) * m_rhs(0,col) + m_lhs(row,1) * m_rhs(1,col) + m_lhs(row,2) * m_rhs(2,col);
|
||||
}
|
||||
else
|
||||
{
|
||||
Scalar x = static_cast<Scalar>(0);
|
||||
for(int i = 0; i < m_lhs.cols(); i++)
|
||||
x += m_lhs.read(row, i) * m_rhs.read(i, col);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
const LhsRef m_lhs;
|
||||
const RhsRef m_rhs;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived1, typename Derived2>
|
||||
EiSum<Derived1, Derived2>
|
||||
operator+(const EiObject<Scalar, Derived1> &mat1, const EiObject<Scalar, Derived2> &mat2)
|
||||
{
|
||||
return EiSum<Derived1, Derived2>(mat1.constRef(), mat2.constRef());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived1, typename Derived2>
|
||||
EiDifference<Derived1, Derived2>
|
||||
operator-(const EiObject<Scalar, Derived1> &mat1, const EiObject<Scalar, Derived2> &mat2)
|
||||
{
|
||||
return EiDifference<Derived1, Derived2>(mat1.constRef(), mat2.constRef());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
EiMatrixProduct<Derived, OtherDerived>
|
||||
EiObject<Scalar, Derived>::lazyMul(const EiObject<Scalar, OtherDerived> &other) const
|
||||
{
|
||||
return EiMatrixProduct<Derived, OtherDerived>(constRef(), other.constRef());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived1, typename Derived2>
|
||||
EiEval<EiMatrixProduct<Derived1, Derived2> >
|
||||
operator*(const EiObject<Scalar, Derived1> &mat1, const EiObject<Scalar, Derived2> &mat2)
|
||||
{
|
||||
return mat1.lazyMul(mat2).eval();
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
Derived &
|
||||
EiObject<Scalar, Derived>::operator+=(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
return *this = *this + other;
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
Derived &
|
||||
EiObject<Scalar, Derived>::operator-=(const EiObject<Scalar, OtherDerived> &other)
|
||||
{
|
||||
return *this = *this - other;
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
template<typename OtherDerived>
|
||||
Derived &
|
||||
EiObject<Scalar, Derived>::operator*=(const EiObject<Scalar, OtherDerived> &other)
|
||||
{
|
||||
return *this = *this * other;
|
||||
}
|
||||
|
||||
#endif // EI_MATRIXOPS_H
|
||||
85
src/Core/MatrixRef.h
Normal file
85
src/Core/MatrixRef.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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 EI_MATRIXREF_H
|
||||
#define EI_MATRIXREF_H
|
||||
|
||||
template<typename MatrixType> class EiMatrixConstRef
|
||||
: public EiObject<typename MatrixType::Scalar, EiMatrixConstRef<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
friend class EiObject<Scalar, EiMatrixConstRef>;
|
||||
|
||||
EiMatrixConstRef(const MatrixType& matrix) : m_matrix(matrix) {}
|
||||
EiMatrixConstRef(const EiMatrixConstRef& other) : m_matrix(other.m_matrix) {}
|
||||
~EiMatrixConstRef() {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiMatrixConstRef)
|
||||
|
||||
private:
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
const Scalar& _read(int row, int col) const
|
||||
{
|
||||
return m_matrix._read(row, col);
|
||||
}
|
||||
|
||||
const MatrixType& m_matrix;
|
||||
};
|
||||
|
||||
template<typename MatrixType> class EiMatrixRef
|
||||
: public EiObject<typename MatrixType::Scalar, EiMatrixRef<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
friend class EiObject<Scalar, EiMatrixRef>;
|
||||
|
||||
EiMatrixRef(MatrixType& matrix) : m_matrix(matrix) {}
|
||||
EiMatrixRef(const EiMatrixRef& other) : m_matrix(other.m_matrix) {}
|
||||
~EiMatrixRef() {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiMatrixRef)
|
||||
|
||||
private:
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
const Scalar& _read(int row, int col) const
|
||||
{
|
||||
return m_matrix._read(row, col);
|
||||
}
|
||||
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
return m_matrix.write(row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatrixType& m_matrix;
|
||||
};
|
||||
|
||||
#endif // EI_MATRIXREF_H
|
||||
163
src/Core/MatrixStorage.h
Normal file
163
src/Core/MatrixStorage.h
Normal file
@@ -0,0 +1,163 @@
|
||||
// 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 EI_MATRIXSTORAGE_H
|
||||
#define EI_MATRIXSTORAGE_H
|
||||
|
||||
template<typename Scalar,
|
||||
int RowsAtCompileTime,
|
||||
int ColsAtCompileTime>
|
||||
class EiMatrixStorage
|
||||
{
|
||||
protected:
|
||||
Scalar m_array[RowsAtCompileTime * ColsAtCompileTime];
|
||||
|
||||
void resize(int rows, int cols)
|
||||
{ assert(rows == RowsAtCompileTime && cols == ColsAtCompileTime); }
|
||||
|
||||
int _rows() const
|
||||
{ return RowsAtCompileTime; }
|
||||
|
||||
int _cols() const
|
||||
{ return ColsAtCompileTime; }
|
||||
|
||||
public:
|
||||
EiMatrixStorage(int rows, int cols)
|
||||
{
|
||||
EI_UNUSED(rows);
|
||||
EI_UNUSED(cols);
|
||||
assert(RowsAtCompileTime > 0 && ColsAtCompileTime > 0);
|
||||
}
|
||||
|
||||
~EiMatrixStorage() {};
|
||||
};
|
||||
|
||||
template<typename Scalar, int ColsAtCompileTime>
|
||||
class EiMatrixStorage<Scalar, EiDynamic, ColsAtCompileTime>
|
||||
{
|
||||
protected:
|
||||
int m_rows;
|
||||
Scalar* m_array;
|
||||
|
||||
void resize(int rows, int cols)
|
||||
{
|
||||
assert(rows > 0 && cols == ColsAtCompileTime);
|
||||
if(rows > m_rows)
|
||||
{
|
||||
delete[] m_array;
|
||||
m_array = new Scalar[rows * ColsAtCompileTime];
|
||||
}
|
||||
m_rows = rows;
|
||||
}
|
||||
|
||||
int _rows() const
|
||||
{ return m_rows; }
|
||||
|
||||
int _cols() const
|
||||
{ return ColsAtCompileTime; }
|
||||
|
||||
public:
|
||||
EiMatrixStorage(int rows, int cols) : m_rows(rows)
|
||||
{
|
||||
assert(m_rows > 0 && cols == ColsAtCompileTime);
|
||||
m_array = new Scalar[m_rows * ColsAtCompileTime];
|
||||
}
|
||||
|
||||
~EiMatrixStorage()
|
||||
{ delete[] m_array; }
|
||||
};
|
||||
|
||||
template<typename Scalar, int RowsAtCompileTime>
|
||||
class EiMatrixStorage<Scalar, RowsAtCompileTime, EiDynamic>
|
||||
{
|
||||
protected:
|
||||
int m_cols;
|
||||
Scalar* m_array;
|
||||
|
||||
void resize(int rows, int cols)
|
||||
{
|
||||
assert(rows == RowsAtCompileTime && cols > 0);
|
||||
if(cols > m_cols)
|
||||
{
|
||||
delete[] m_array;
|
||||
m_array = new Scalar[cols * RowsAtCompileTime];
|
||||
}
|
||||
m_cols = cols;
|
||||
}
|
||||
|
||||
int _rows() const
|
||||
{ return RowsAtCompileTime; }
|
||||
|
||||
int _cols() const
|
||||
{ return m_cols; }
|
||||
|
||||
public:
|
||||
EiMatrixStorage(int rows, int cols) : m_cols(cols)
|
||||
{
|
||||
assert(rows == RowsAtCompileTime && cols > 0);
|
||||
m_array = new Scalar[m_cols * RowsAtCompileTime];
|
||||
}
|
||||
|
||||
~EiMatrixStorage()
|
||||
{ delete[] m_array; }
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
class EiMatrixStorage<Scalar, EiDynamic, EiDynamic>
|
||||
{
|
||||
protected:
|
||||
int m_rows, m_cols;
|
||||
Scalar* m_array;
|
||||
|
||||
void resize(int rows, int cols)
|
||||
{
|
||||
assert(rows > 0 && cols > 0);
|
||||
if(rows * cols > m_rows * m_cols)
|
||||
{
|
||||
delete[] m_array;
|
||||
m_array = new Scalar[rows * cols];
|
||||
}
|
||||
m_rows = rows;
|
||||
m_cols = cols;
|
||||
}
|
||||
|
||||
int _rows() const
|
||||
{ return m_rows; }
|
||||
|
||||
int _cols() const
|
||||
{ return m_cols; }
|
||||
|
||||
public:
|
||||
EiMatrixStorage(int rows, int cols) : m_rows(rows), m_cols(cols)
|
||||
{
|
||||
assert(m_rows > 0 && m_cols > 0);
|
||||
m_array = new Scalar[m_rows * m_cols];
|
||||
}
|
||||
|
||||
~EiMatrixStorage()
|
||||
{ delete[] m_array; }
|
||||
};
|
||||
|
||||
#endif // EI_MATRIXSTORAGE_H
|
||||
83
src/Core/Minor.h
Normal file
83
src/Core/Minor.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 EI_MINOR_H
|
||||
#define EI_MINOR_H
|
||||
|
||||
template<typename MatrixType> class EiMinor
|
||||
: public EiObject<typename MatrixType::Scalar, EiMinor<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiMinor<MatrixType> >;
|
||||
|
||||
static const int
|
||||
RowsAtCompileTime = (MatrixType::RowsAtCompileTime != EiDynamic) ?
|
||||
MatrixType::RowsAtCompileTime - 1 : EiDynamic,
|
||||
ColsAtCompileTime = (MatrixType::ColsAtCompileTime != EiDynamic) ?
|
||||
MatrixType::ColsAtCompileTime - 1 : EiDynamic;
|
||||
|
||||
EiMinor(const MatRef& matrix,
|
||||
int row, int col = 0)
|
||||
: m_matrix(matrix), m_row(row), m_col(col)
|
||||
{
|
||||
EI_CHECK_RANGES(matrix, row, col);
|
||||
}
|
||||
|
||||
EiMinor(const EiMinor& other)
|
||||
: m_matrix(other.m_matrix), m_row(other.m_row), m_col(other.m_col) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiMinor)
|
||||
|
||||
private:
|
||||
EiMinor& _ref() { return *this; }
|
||||
const EiMinor& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows() - 1; }
|
||||
int _cols() const { return m_matrix.cols() - 1; }
|
||||
|
||||
Scalar& _write(int row, int col=0)
|
||||
{
|
||||
return m_matrix.write(row + (row >= m_row), col + (col >= m_col));
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col=0) const
|
||||
{
|
||||
return m_matrix.read(row + (row >= m_row), col + (col >= m_col));
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_row, m_col;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiMinor<Derived>
|
||||
EiObject<Scalar, Derived>::minor(int row, int col)
|
||||
{
|
||||
return EiMinor<Derived>(static_cast<Derived*>(this)->ref(), row, col);
|
||||
}
|
||||
|
||||
#endif // EI_MINOR_H
|
||||
169
src/Core/Numeric.h
Normal file
169
src/Core/Numeric.h
Normal file
@@ -0,0 +1,169 @@
|
||||
|
||||
// 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 EI_NUMERIC_H
|
||||
#define EI_NUMERIC_H
|
||||
|
||||
template<typename T> struct EiTraits;
|
||||
|
||||
template<> struct EiTraits<int>
|
||||
{
|
||||
typedef int Real;
|
||||
typedef double FloatingPoint;
|
||||
typedef double RealFloatingPoint;
|
||||
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = false;
|
||||
|
||||
static int epsilon() { return 0; }
|
||||
static int real(const int& x) { return x; }
|
||||
static int imag(const int& x) { EI_UNUSED(x); return 0; }
|
||||
static int conj(const int& x) { return x; }
|
||||
static double sqrt(const int& x) { return std::sqrt(static_cast<double>(x)); }
|
||||
static int abs(const int& x) { return std::abs(x); }
|
||||
static int abs2(const int& x) { return x*x; }
|
||||
static int random()
|
||||
{
|
||||
// "rand()%21" would be bad. always use the high-order bits, not the low-order bits.
|
||||
// note: here (gcc 4.1) static_cast<int> seems to round the nearest int.
|
||||
// I don't know if that's part of the standard.
|
||||
return -10 + static_cast<int>(rand() / ((RAND_MAX + 1.0)/20.0));
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct EiTraits<float>
|
||||
{
|
||||
typedef float Real;
|
||||
typedef float FloatingPoint;
|
||||
typedef float RealFloatingPoint;
|
||||
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = true;
|
||||
|
||||
static float epsilon() { return 1e-5f; }
|
||||
static float real(const float& x) { return x; }
|
||||
static float imag(const float& x) { EI_UNUSED(x); return 0; }
|
||||
static float conj(const float& x) { return x; }
|
||||
static float sqrt(const float& x) { return std::sqrt(x); }
|
||||
static float abs(const float& x) { return std::abs(x); }
|
||||
static float abs2(const float& x) { return x*x; }
|
||||
static float random()
|
||||
{
|
||||
return rand() / (RAND_MAX/20.0f) - 10.0f;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct EiTraits<double>
|
||||
{
|
||||
typedef double Real;
|
||||
typedef double FloatingPoint;
|
||||
typedef double RealFloatingPoint;
|
||||
|
||||
static const bool IsComplex = false;
|
||||
static const bool HasFloatingPoint = true;
|
||||
|
||||
static double epsilon() { return 1e-11; }
|
||||
static double real(const double& x) { return x; }
|
||||
static double imag(const double& x) { EI_UNUSED(x); return 0; }
|
||||
static double conj(const double& x) { return x; }
|
||||
static double sqrt(const double& x) { return std::sqrt(x); }
|
||||
static double abs(const double& x) { return std::abs(x); }
|
||||
static double abs2(const double& x) { return x*x; }
|
||||
static double random()
|
||||
{
|
||||
return rand() / (RAND_MAX/20.0) - 10.0;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename _Real> struct EiTraits<std::complex<_Real> >
|
||||
{
|
||||
typedef _Real Real;
|
||||
typedef std::complex<Real> Complex;
|
||||
typedef std::complex<double> FloatingPoint;
|
||||
typedef typename EiTraits<Real>::FloatingPoint RealFloatingPoint;
|
||||
|
||||
static const bool IsComplex = true;
|
||||
static const bool HasFloatingPoint = EiTraits<Real>::HasFloatingPoint;
|
||||
|
||||
static Real epsilon() { return EiTraits<Real>::epsilon(); }
|
||||
static Real real(const Complex& x) { return std::real(x); }
|
||||
static Real imag(const Complex& x) { return std::imag(x); }
|
||||
static Complex conj(const Complex& x) { return std::conj(x); }
|
||||
static FloatingPoint sqrt(const Complex& x)
|
||||
{ return std::sqrt(static_cast<FloatingPoint>(x)); }
|
||||
static RealFloatingPoint abs(const Complex& x)
|
||||
{ return std::abs(static_cast<FloatingPoint>(x)); }
|
||||
static Real abs2(const Complex& x)
|
||||
{ return std::real(x) * std::real(x) + std::imag(x) * std::imag(x); }
|
||||
static Complex random()
|
||||
{
|
||||
return Complex(EiTraits<Real>::random(), EiTraits<Real>::random());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> typename EiTraits<T>::Real EiReal(const T& x)
|
||||
{ return EiTraits<T>::real(x); }
|
||||
|
||||
template<typename T> typename EiTraits<T>::Real EiImag(const T& x)
|
||||
{ return EiTraits<T>::imag(x); }
|
||||
|
||||
template<typename T> T EiConj(const T& x)
|
||||
{ return EiTraits<T>::conj(x); }
|
||||
|
||||
template<typename T> typename EiTraits<T>::FloatingPoint EiSqrt(const T& x)
|
||||
{ return EiTraits<T>::sqrt(x); }
|
||||
|
||||
template<typename T> typename EiTraits<T>::RealFloatingPoint EiAbs(const T& x)
|
||||
{ return EiTraits<T>::abs(x); }
|
||||
|
||||
template<typename T> typename EiTraits<T>::Real EiAbs2(const T& x)
|
||||
{ return EiTraits<T>::abs2(x); }
|
||||
|
||||
template<typename T> T EiRandom()
|
||||
{ return EiTraits<T>::random(); }
|
||||
|
||||
template<typename T> bool EiNegligible(const T& a, const T& b)
|
||||
{
|
||||
return(EiAbs(a) <= EiAbs(b) * EiTraits<T>::epsilon());
|
||||
}
|
||||
|
||||
template<typename T> bool EiApprox(const T& a, const T& b)
|
||||
{
|
||||
if(EiTraits<T>::IsFloat)
|
||||
return(EiAbs(a - b) <= std::min(EiAbs(a), EiAbs(b)) * EiTraits<T>::epsilon());
|
||||
else
|
||||
return(a == b);
|
||||
}
|
||||
|
||||
template<typename T> bool EiLessThanOrApprox(const T& a, const T& b)
|
||||
{
|
||||
if(EiTraits<T>::IsFloat)
|
||||
return(a < b || EiApprox(a, b));
|
||||
else
|
||||
return(a <= b);
|
||||
}
|
||||
|
||||
#endif // EI_NUMERIC_H
|
||||
165
src/Core/Object.h
Normal file
165
src/Core/Object.h
Normal file
@@ -0,0 +1,165 @@
|
||||
// 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 EI_OBJECT_H
|
||||
#define EI_OBJECT_H
|
||||
|
||||
#include "Util.h"
|
||||
#include "Loop.h"
|
||||
|
||||
template<typename Scalar, typename Derived> class EiObject
|
||||
{
|
||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||
static const bool HasDynamicSize = RowsAtCompileTime != EiDynamic
|
||||
&& ColsAtCompileTime != EiDynamic;
|
||||
static const int UnrollCount = HasDynamicSize ?
|
||||
RowsAtCompileTime * ColsAtCompileTime : 0;
|
||||
|
||||
template<typename OtherDerived>
|
||||
void _copy_helper(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
if(UnrollCount > 0 && UnrollCount <= EI_LOOP_UNROLLING_LIMIT)
|
||||
EiLoop<UnrollCount, RowsAtCompileTime>::copy(*this, other);
|
||||
else
|
||||
for(int i = 0; i < rows(); i++)
|
||||
for(int j = 0; j < cols(); j++)
|
||||
write(i, j) = other.read(i, j);
|
||||
}
|
||||
|
||||
public:
|
||||
typedef typename EiForwardDecl<Derived>::Ref Ref;
|
||||
typedef typename EiForwardDecl<Derived>::ConstRef ConstRef;
|
||||
|
||||
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
|
||||
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
||||
int size() const { return rows() * cols(); }
|
||||
|
||||
Ref ref()
|
||||
{ return static_cast<Derived *>(this)->_ref(); }
|
||||
|
||||
ConstRef constRef() const
|
||||
{ return static_cast<const Derived *>(this)->_constRef(); }
|
||||
|
||||
Scalar& write(int row, int col)
|
||||
{
|
||||
return static_cast<Derived *>(this)->_write(row, col);
|
||||
}
|
||||
|
||||
Scalar read(int row, int col) const
|
||||
{
|
||||
return static_cast<const Derived *>(this)->_read(row, col);
|
||||
}
|
||||
|
||||
template<typename OtherDerived>
|
||||
Derived& operator=(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
assert(rows() == other.rows() && cols() == other.cols());
|
||||
_copy_helper(other);
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
//special case of the above template operator=. Strangely, g++ 4.1 failed to use
|
||||
//that template when OtherDerived == Derived
|
||||
Derived& operator=(const EiObject& other)
|
||||
{
|
||||
assert(rows() == other.rows() && cols() == other.cols());
|
||||
_copy_helper(other);
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
EiRow<Derived> row(int i);
|
||||
EiColumn<Derived> col(int i);
|
||||
EiMinor<Derived> minor(int row, int col);
|
||||
EiBlock<Derived> block(int startRow, int endRow, int startCol, int endCol);
|
||||
EiTranspose<Derived> transpose();
|
||||
EiConjugate<Derived> conjugate();
|
||||
EiTranspose<EiConjugate<Derived> > adjoint() { return conjugate().transpose(); }
|
||||
|
||||
template<typename OtherDerived>
|
||||
EiMatrixProduct<Derived, OtherDerived>
|
||||
lazyMul(const EiObject<Scalar, OtherDerived>& other) const EI_ALWAYS_INLINE;
|
||||
|
||||
template<typename OtherDerived>
|
||||
Derived& operator+=(const EiObject<Scalar, OtherDerived>& other);
|
||||
template<typename OtherDerived>
|
||||
Derived& operator-=(const EiObject<Scalar, OtherDerived>& other);
|
||||
template<typename OtherDerived>
|
||||
Derived& operator*=(const EiObject<Scalar, OtherDerived>& other);
|
||||
|
||||
Derived& operator*=(const int& other);
|
||||
Derived& operator*=(const float& other);
|
||||
Derived& operator*=(const double& other);
|
||||
Derived& operator*=(const std::complex<int>& 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<int>& other);
|
||||
Derived& operator/=(const std::complex<float>& other);
|
||||
Derived& operator/=(const std::complex<double>& other);
|
||||
|
||||
Scalar operator()(int row, int col) const
|
||||
{ return read(row, col); }
|
||||
|
||||
Scalar& operator()(int row, int col)
|
||||
{ return write(row, col); }
|
||||
|
||||
Scalar operator[](int index) const
|
||||
{
|
||||
assert(RowsAtCompileTime == 1 || ColsAtCompileTime == 1);
|
||||
if(RowsAtCompileTime == 1) return read(0, index);
|
||||
else return read(index, 0);
|
||||
}
|
||||
|
||||
Scalar& operator[](int index)
|
||||
{
|
||||
assert(RowsAtCompileTime == 1 || ColsAtCompileTime == 1);
|
||||
if(RowsAtCompileTime == 1) return write(0, index);
|
||||
else return write(index, 0);
|
||||
}
|
||||
|
||||
EiEval<Derived> eval() const EI_ALWAYS_INLINE;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
std::ostream & operator <<
|
||||
( std::ostream & s,
|
||||
const EiObject<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 // EI_OBJECT_H
|
||||
88
src/Core/Row.h
Normal file
88
src/Core/Row.h
Normal file
@@ -0,0 +1,88 @@
|
||||
// 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 EI_ROW_H
|
||||
#define EI_ROW_H
|
||||
|
||||
template<typename MatrixType> class EiRow
|
||||
: public EiObject<typename MatrixType::Scalar, EiRow<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiRow<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = 1,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
||||
|
||||
EiRow(const MatRef& matrix, int row)
|
||||
: m_matrix(matrix), m_row(row)
|
||||
{
|
||||
EI_CHECK_ROW_RANGE(matrix, row);
|
||||
}
|
||||
|
||||
EiRow(const EiRow& other)
|
||||
: m_matrix(other.m_matrix), m_row(other.m_row) {}
|
||||
|
||||
template<typename OtherDerived>
|
||||
EiRow& operator=(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
return EiObject<Scalar, EiRow<MatrixType> >::operator=(other);
|
||||
}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiRow)
|
||||
|
||||
private:
|
||||
EiRow& _ref() { return *this; }
|
||||
const EiRow& _constRef() const { return *this; }
|
||||
|
||||
int _rows() const { return 1; }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
EI_UNUSED(row);
|
||||
return m_matrix.write(m_row, col);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
EI_UNUSED(row);
|
||||
return m_matrix.read(m_row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_row;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiRow<Derived>
|
||||
EiObject<Scalar, Derived>::row(int i)
|
||||
{
|
||||
return EiRow<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_ROW_H
|
||||
112
src/Core/ScalarOps.h
Normal file
112
src/Core/ScalarOps.h
Normal file
@@ -0,0 +1,112 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#ifndef EI_SCALAROPS_H
|
||||
#define EI_SCALAROPS_H
|
||||
|
||||
template<typename MatrixType> class EiScalarProduct
|
||||
: public EiObject<typename MatrixType::Scalar, EiScalarProduct<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::ConstRef MatRef;
|
||||
friend class EiObject<typename MatrixType::Scalar, EiScalarProduct<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
||||
|
||||
EiScalarProduct(const MatRef& matrix, Scalar scalar)
|
||||
: m_matrix(matrix), m_scalar(scalar) {}
|
||||
|
||||
EiScalarProduct(const EiScalarProduct& other)
|
||||
: m_matrix(other.m_matrix), m_scalar(other.m_scalar) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiScalarProduct)
|
||||
|
||||
private:
|
||||
const EiScalarProduct& _ref() const { return *this; }
|
||||
const EiScalarProduct& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return m_matrix.read(row, col) * m_scalar;
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatRef m_matrix;
|
||||
const Scalar m_scalar;
|
||||
};
|
||||
|
||||
#define EI_MAKE_SCALAR_OPS(OtherScalar) \
|
||||
template<typename Scalar, typename Derived> \
|
||||
EiScalarProduct<Derived> \
|
||||
operator*(const EiObject<Scalar, Derived>& matrix, \
|
||||
OtherScalar scalar) \
|
||||
{ \
|
||||
return EiScalarProduct<Derived>(matrix.constRef(), scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
EiScalarProduct<Derived> \
|
||||
operator*(OtherScalar scalar, \
|
||||
const EiObject<Scalar, Derived>& matrix) \
|
||||
{ \
|
||||
return EiScalarProduct<Derived>(matrix.constRef(), scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
EiScalarProduct<Derived> \
|
||||
operator/(const EiObject<Scalar, Derived>& matrix, \
|
||||
OtherScalar scalar) \
|
||||
{ \
|
||||
return matrix * (static_cast<typename Derived::Scalar>(1) / scalar); \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
EiObject<Scalar, Derived>::operator*=(const OtherScalar &other) \
|
||||
{ \
|
||||
return *this = *this * other; \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
EiObject<Scalar, Derived>::operator/=(const OtherScalar &other) \
|
||||
{ \
|
||||
return *this = *this / other; \
|
||||
}
|
||||
|
||||
EI_MAKE_SCALAR_OPS(int)
|
||||
EI_MAKE_SCALAR_OPS(float)
|
||||
EI_MAKE_SCALAR_OPS(double)
|
||||
EI_MAKE_SCALAR_OPS(std::complex<int>)
|
||||
EI_MAKE_SCALAR_OPS(std::complex<float>)
|
||||
EI_MAKE_SCALAR_OPS(std::complex<double>)
|
||||
|
||||
#undef EI_MAKE_SCALAR_OPS
|
||||
|
||||
#endif // EI_SCALAROPS_H
|
||||
74
src/Core/Transpose.h
Normal file
74
src/Core/Transpose.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 EI_TRANSPOSE_H
|
||||
#define EI_TRANSPOSE_H
|
||||
|
||||
template<typename MatrixType> class EiTranspose
|
||||
: public EiObject<typename MatrixType::Scalar, EiTranspose<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiTranspose<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::ColsAtCompileTime,
|
||||
ColsAtCompileTime = MatrixType::RowsAtCompileTime;
|
||||
|
||||
EiTranspose(const MatRef& matrix) : m_matrix(matrix) {}
|
||||
|
||||
EiTranspose(const EiTranspose& other)
|
||||
: m_matrix(other.m_matrix) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiTranspose)
|
||||
|
||||
private:
|
||||
EiTranspose& _ref() { return *this; }
|
||||
const EiTranspose& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.cols(); }
|
||||
int _cols() const { return m_matrix.rows(); }
|
||||
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
return m_matrix.write(col, row);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return m_matrix.read(col, row);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiTranspose<Derived>
|
||||
EiObject<Scalar, Derived>::transpose()
|
||||
{
|
||||
return EiTranspose<Derived>(static_cast<Derived*>(this)->ref());
|
||||
}
|
||||
|
||||
#endif // EI_TRANSPOSE_H
|
||||
111
src/Core/Util.h
Normal file
111
src/Core/Util.h
Normal file
@@ -0,0 +1,111 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#ifndef EI_UTIL_H
|
||||
#define EI_UTIL_H
|
||||
|
||||
#include <iostream>
|
||||
#include <complex>
|
||||
#include <cassert>
|
||||
|
||||
#undef minor
|
||||
|
||||
#define EI_UNUSED(x) (void)x
|
||||
#define EI_CHECK_RANGES(matrix, row, col) \
|
||||
assert(row >= 0 && row < (matrix).rows() && col >= 0 && col < (matrix).cols())
|
||||
#define EI_CHECK_ROW_RANGE(matrix, row) \
|
||||
assert(row >= 0 && row < (matrix).rows())
|
||||
#define EI_CHECK_COL_RANGE(matrix, col) \
|
||||
assert(col >= 0 && col < (matrix).cols())
|
||||
|
||||
//forward declarations
|
||||
template<typename _Scalar, int _Rows, int _Cols> class EiMatrix;
|
||||
template<typename MatrixType> class EiMatrixRef;
|
||||
template<typename MatrixType> class EiMatrixConstRef;
|
||||
template<typename MatrixType> class EiRow;
|
||||
template<typename MatrixType> class EiColumn;
|
||||
template<typename MatrixType> class EiMinor;
|
||||
template<typename MatrixType> class EiBlock;
|
||||
template<typename MatrixType> class EiTranspose;
|
||||
template<typename MatrixType> class EiConjugate;
|
||||
template<typename Lhs, typename Rhs> class EiSum;
|
||||
template<typename Lhs, typename Rhs> class EiDifference;
|
||||
template<typename Lhs, typename Rhs> class EiMatrixProduct;
|
||||
template<typename MatrixType> class EiScalarProduct;
|
||||
template<typename ExpressionType> class EiEval;
|
||||
|
||||
template<typename T> struct EiForwardDecl
|
||||
{
|
||||
typedef T Ref;
|
||||
typedef T ConstRef;
|
||||
};
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
struct EiForwardDecl<EiMatrix<_Scalar, _Rows, _Cols> >
|
||||
{
|
||||
typedef EiMatrixRef<EiMatrix<_Scalar, _Rows, _Cols> > Ref;
|
||||
typedef EiMatrixConstRef<EiMatrix<_Scalar, _Rows, _Cols> > ConstRef;
|
||||
};
|
||||
|
||||
const int EiDynamic = -1;
|
||||
|
||||
#define EI_LOOP_UNROLLING_LIMIT 25
|
||||
|
||||
#define EI_UNUSED(x) (void)x
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define EI_ALWAYS_INLINE __attribute__((always_inline))
|
||||
# define EI_RESTRICT /*__restrict__*/
|
||||
#else
|
||||
# define EI_ALWAYS_INLINE
|
||||
# define EI_RESTRICT
|
||||
#endif
|
||||
|
||||
#define EI_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
|
||||
template<typename OtherScalar, typename OtherDerived> \
|
||||
Derived& operator Op(const EiObject<OtherScalar, OtherDerived>& other) \
|
||||
{ \
|
||||
return EiObject<Scalar, Derived>::operator Op(other); \
|
||||
} \
|
||||
Derived& operator Op(const Derived& other) \
|
||||
{ \
|
||||
return EiObject<Scalar, Derived>::operator Op(other); \
|
||||
}
|
||||
|
||||
#define EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
|
||||
template<typename Other> \
|
||||
Derived& operator Op(const Other& scalar) \
|
||||
{ \
|
||||
return EiObject<Scalar, Derived>::operator Op(scalar); \
|
||||
}
|
||||
|
||||
#define EI_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
|
||||
EI_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
|
||||
EI_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
|
||||
EI_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
|
||||
EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
|
||||
EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
|
||||
|
||||
#endif // EI_UTIL_H
|
||||
Reference in New Issue
Block a user