From 28c44a95c21bb18ec265faba69e750c430045f9c Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 27 Sep 2007 19:54:04 +0000 Subject: Finish prefixing everything with "Ei" --- doc/tutorial.cpp | 4 +- src/All | 6 +- src/Core | 6 +- src/Manip | 6 +- src/internal/Block.h | 8 +-- src/internal/EiObject.h | 130 ------------------------------------------- src/internal/Matrix.h | 88 ++++++++++++++--------------- src/internal/MatrixOps.h | 48 ++++++++-------- src/internal/MatrixRef.h | 18 +++--- src/internal/MatrixStorage.h | 26 ++++----- src/internal/Minor.h | 22 ++++---- src/internal/Object.h | 130 +++++++++++++++++++++++++++++++++++++++++++ src/internal/RowAndCol.h | 62 ++++++++++----------- src/internal/ScalarOps.h | 48 ++++++++-------- src/internal/Util.h | 32 +++++------ test/main.h | 6 +- test/matrixmanip.cpp | 6 +- test/matrixops.cpp | 10 ++-- test/vectorops.cpp | 14 ++--- 19 files changed, 334 insertions(+), 336 deletions(-) delete mode 100644 src/internal/EiObject.h create mode 100644 src/internal/Object.h diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index 38943ec50..b0e13687b 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -4,7 +4,7 @@ using namespace std; int main(int, char **) { - Matrix m; // 2x2 fixed-size matrix with uninitialized entries + EiMatrix m; // 2x2 fixed-size matrix with uninitialized entries m(0,0) = 1; m(0,1) = 2; m(1,0) = 3; @@ -35,7 +35,7 @@ int main(int, char **) cout << "We want to store that into m, i.e. do \"m = m * m;\"" << endl; cout << "Here we must be very careful. For if we do \"m = m * m;\"," << endl << "the matrix m becomes" << endl; - Matrix m_save = m; + EiMatrix m_save = m; m = m * m; // the bogus operation cout << m << "," << endl; cout << "which is not what was wanted!" << endl diff --git a/src/All b/src/All index 5784a91f4..62c2abf35 100644 --- a/src/All +++ b/src/All @@ -23,10 +23,10 @@ // 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_ALL_H -#define EIGEN_ALL_H +#ifndef EI_ALL_H +#define EI_ALL_H #include "Core" #include "Manip" -#endif // EIGEN_ALL_H +#endif // EI_ALL_H diff --git a/src/Core b/src/Core index b4d56a044..581893ace 100644 --- a/src/Core +++ b/src/Core @@ -23,10 +23,10 @@ // 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_CORE_H -#define EIGEN_CORE_H +#ifndef EI_CORE_H +#define EI_CORE_H //#include "internal/Vector.h" #include "internal/Matrix.h" -#endif // EIGEN_CORE_H +#endif // EI_CORE_H diff --git a/src/Manip b/src/Manip index 0bfc4f14b..ca450ddf7 100644 --- a/src/Manip +++ b/src/Manip @@ -23,11 +23,11 @@ // 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_MANIP_H -#define EIGEN_MANIP_H +#ifndef EI_MANIP_H +#define EI_MANIP_H #include "internal/RowAndCol.h" #include "internal/Block.h" #include "internal/Minor.h" -#endif // EIGEN_MANIP_H +#endif // EI_MANIP_H diff --git a/src/internal/Block.h b/src/internal/Block.h index 93ddddcb7..ca2c67465 100644 --- a/src/internal/Block.h +++ b/src/internal/Block.h @@ -23,8 +23,8 @@ // 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 +#ifndef EI_BLOCK_H +#define EI_BLOCK_H template class EiBlock : public EiObject > @@ -52,7 +52,7 @@ template class EiBlock : 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) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(EiBlock) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiBlock) private: const Ref& _ref() const { return *this; } @@ -81,4 +81,4 @@ EiObject::block(int startRow, int endRow, int startCol, int end return EiBlock(ref(), startRow, endRow, startCol, endCol); } -#endif // EIGEN_BLOCK_H +#endif // EI_BLOCK_H diff --git a/src/internal/EiObject.h b/src/internal/EiObject.h deleted file mode 100644 index 290d60b15..000000000 --- a/src/internal/EiObject.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2007 Benoit Jacob -// -// 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_EIGENBASE_H -#define EIGEN_EIGENBASE_H - -#include "Util.h" - -template class EiObject -{ - static const int RowsAtCompileTime = Derived::RowsAtCompileTime, - ColsAtCompileTime = Derived::ColsAtCompileTime; - public: - typedef typename ForwardDecl::Ref Ref; - typedef _Scalar Scalar; - - int rows() const { return static_cast(this)->_rows(); } - int cols() const { return static_cast(this)->_cols(); } - int size() const { return rows() * cols(); } - - Ref ref() - { return static_cast(this)->_ref(); } - - Ref ref() const - { return static_cast(this)->_ref(); } - - Scalar& write(int row, int col) - { - return static_cast(this)->_write(row, col); - } - - Scalar read(int row, int col) const - { - return static_cast(this)->_read(row, col); - } - - template - Derived& operator=(const EiObject& other) - { - assert(rows() == other.rows() && cols() == other.cols()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); - return *static_cast(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()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); - return *static_cast(this); - } - - MatrixRow row(int i); - MatrixCol col(int i); - MatrixMinor minor(int row, int col); - EiBlock - block(int startRow, int endRow, int startCol= 0, int endCol = 0); - - template - Derived& operator+=(const EiObject& other); - template - Derived& operator-=(const EiObject& other); - template - Derived& operator*=(const EiObject& other); - - Derived& operator*=(const int& other); - Derived& operator*=(const float& other); - Derived& operator*=(const double& other); - Derived& operator*=(const std::complex& other); - Derived& operator*=(const std::complex& other); - Derived& operator*=(const std::complex& other); - - Derived& operator/=(const int& other); - Derived& operator/=(const float& other); - Derived& operator/=(const double& other); - Derived& operator/=(const std::complex& other); - Derived& operator/=(const std::complex& other); - Derived& operator/=(const std::complex& other); - - Scalar operator()(int row, int col = 0) const - { return read(row, col); } - - Scalar& operator()(int row, int col = 0) - { return write(row, col); } -}; - -template -std::ostream & operator << -( std::ostream & s, - const EiObject & 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_EIGENBASE_H diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h index 00780ae43..d56ac455a 100644 --- a/src/internal/Matrix.h +++ b/src/internal/Matrix.h @@ -23,30 +23,27 @@ // 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 +#ifndef EI_MATRIX_H +#define EI_MATRIX_H #include "Util.h" -#include "EiObject.h" +#include "Object.h" #include "MatrixRef.h" #include "MatrixStorage.h" template -class EiMatrix : public EiObject<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, - public MatrixStorage<_Scalar, _Rows, _Cols> +class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >, + public EiMatrixStorage<_Scalar, _Rows, _Cols> { public: - friend class EiObject<_Scalar, Matrix>; - typedef EiObject<_Scalar, Matrix> Base; - typedef MatrixStorage<_Scalar, _Rows, _Cols> Storage; - typedef _Scalar Scalar; - typedef MatrixRef Ref; - typedef MatrixAlias Alias; + friend class EiObject<_Scalar, EiMatrix>; + typedef EiObject<_Scalar, EiMatrix> Base; + typedef EiMatrixStorage<_Scalar, _Rows, _Cols> Storage; + typedef _Scalar Scalar; + typedef EiMatrixRef Ref; static const int RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols; - Alias alias(); - const Scalar* array() const { return Storage::m_array; } @@ -54,80 +51,81 @@ class EiMatrix : public EiObject<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, { return Storage::m_array; } private: - Ref _ref() const { return Ref(*const_cast(this)); } + Ref _ref() const { return Ref(*const_cast(this)); } const Scalar& _read(int row, int col = 0) const { - EIGEN_CHECK_RANGES(*this, row, col); + EI_CHECK_RANGES(*this, row, col); return array()[row + col * Storage::_rows()]; } Scalar& _write(int row, int col = 0) { - EIGEN_CHECK_RANGES(*this, row, col); + EI_CHECK_RANGES(*this, row, col); return array()[row + col * Storage::_rows()]; } public: template - Matrix& operator=(const EiObject& other) + EiMatrix& operator=(const EiObject& other) { resize(other.rows(), other.cols()); return Base::operator=(other); } - Matrix& operator=(const Matrix& other) + + EiMatrix& operator=(const EiMatrix& 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, /=) + EI_INHERIT_ASSIGNMENT_OPERATOR(EiMatrix, +=) + EI_INHERIT_ASSIGNMENT_OPERATOR(EiMatrix, -=) + EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(EiMatrix, *=) + EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(EiMatrix, /=) - explicit Matrix(int rows = 1, int cols = 1) : Storage(rows, cols) {} + explicit EiMatrix(int rows = 1, int cols = 1) : Storage(rows, cols) {} template - Matrix(const EiObject& other) : Storage(other.rows(), other.cols()) + EiMatrix(const EiObject& other) : Storage(other.rows(), other.cols()) { *this = other; } - Matrix(const Matrix& other) : Storage(other.rows(), other.cols()) + EiMatrix(const EiMatrix& other) : Storage(other.rows(), other.cols()) { *this = other; } - ~Matrix() {} + ~EiMatrix() {} }; template -Matrix +EiMatrix eval(const EiObject& expression) { - return Matrix(expression); + return EiMatrix(expression); } -#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ -typedef Matrix Matrix##SizeSuffix##TypeSuffix; \ -typedef Matrix Vector##SizeSuffix##TypeSuffix; +#define EI_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ +typedef EiMatrix EiMatrix##SizeSuffix##TypeSuffix; \ +typedef EiMatrix EiVector##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, EiDynamic, X) +#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) -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, ci) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cf) -EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cd) +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, ci) +EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cf) +EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cd) -#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES -#undef EIGEN_MAKE_TYPEDEFS +#undef EI_MAKE_TYPEDEFS_ALL_SIZES +#undef EI_MAKE_TYPEDEFS #include "MatrixOps.h" #include "ScalarOps.h" #include "RowAndCol.h" -#endif // EIGEN_MATRIX_H +#endif // EI_MATRIX_H diff --git a/src/internal/MatrixOps.h b/src/internal/MatrixOps.h index 4f28c179a..f5120277b 100644 --- a/src/internal/MatrixOps.h +++ b/src/internal/MatrixOps.h @@ -23,32 +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 EIGEN_MATRIXOPS_H -#define EIGEN_MATRIXOPS_H +#ifndef EI_MATRIXOPS_H +#define EI_MATRIXOPS_H template class EiSum - : public EiObject > + : public EiObject > { public: typedef typename Lhs::Scalar Scalar; typedef typename Lhs::Ref LhsRef; typedef typename Rhs::Ref RhsRef; - friend class EiObject; + friend class EiObject; typedef EiSum Ref; static const int RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Rhs::ColsAtCompileTime; - MatrixSum(const LhsRef& lhs, const RhsRef& rhs) + EiSum(const LhsRef& lhs, const RhsRef& rhs) : m_lhs(lhs), m_rhs(rhs) { assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); } - MatrixSum(const MatrixSum& other) + EiSum(const EiSum& other) : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixSum) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiSum) private: @@ -67,28 +67,28 @@ template class EiSum }; template class EiDifference - : public EiObject > + : public EiObject > { public: typedef typename Lhs::Scalar Scalar; typedef typename Lhs::Ref LhsRef; typedef typename Rhs::Ref RhsRef; - friend class EiObject; + friend class EiObject; typedef EiDifference Ref; static const int RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Rhs::ColsAtCompileTime; - MatrixDifference(const LhsRef& lhs, const RhsRef& rhs) + EiDifference(const LhsRef& lhs, const RhsRef& rhs) : m_lhs(lhs), m_rhs(rhs) { assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); } - MatrixDifference(const MatrixDifference& other) + EiDifference(const EiDifference& other) : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixDifference) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiDifference) private: const Ref& _ref() const { return *this; } @@ -106,28 +106,28 @@ template class EiDifference }; template class EiMatrixProduct - : public EiObject > + : public EiObject > { public: typedef typename Lhs::Scalar Scalar; typedef typename Lhs::Ref LhsRef; typedef typename Rhs::Ref RhsRef; - friend class EiObject; + friend class EiObject; typedef EiMatrixProduct Ref; static const int RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Rhs::ColsAtCompileTime; - MatrixProduct(const LhsRef& lhs, const RhsRef& rhs) + EiMatrixProduct(const LhsRef& lhs, const RhsRef& rhs) : m_lhs(lhs), m_rhs(rhs) { assert(lhs.cols() == rhs.rows()); } - MatrixProduct(const MatrixProduct& other) + EiMatrixProduct(const EiMatrixProduct& other) : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixProduct) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiMatrixProduct) private: const Ref& _ref() const { return *this; } @@ -148,24 +148,24 @@ template class EiMatrixProduct }; template -MatrixSum +EiSum operator+(const EiObject &mat1, const EiObject &mat2) { - return MatrixSum(mat1.ref(), mat2.ref()); + return EiSum(mat1.ref(), mat2.ref()); } template -MatrixDifference +EiDifference operator-(const EiObject &mat1, const EiObject &mat2) { - return MatrixDifference(mat1.ref(), mat2.ref()); + return EiDifference(mat1.ref(), mat2.ref()); } template -MatrixProduct +EiMatrixProduct operator*(const EiObject &mat1, const EiObject &mat2) { - return MatrixProduct(mat1.ref(), mat2.ref()); + return EiMatrixProduct(mat1.ref(), mat2.ref()); } template @@ -195,4 +195,4 @@ EiObject::operator*=(const EiObject &othe return *static_cast(this); } -#endif // EIGEN_MATRIXOPS_H +#endif // EI_MATRIXOPS_H diff --git a/src/internal/MatrixRef.h b/src/internal/MatrixRef.h index 2e999d6d3..57e44e69c 100644 --- a/src/internal/MatrixRef.h +++ b/src/internal/MatrixRef.h @@ -23,21 +23,21 @@ // 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 +#ifndef EI_MATRIXREF_H +#define EI_MATRIXREF_H template class EiMatrixRef - : public EiObject > + : public EiObject > { public: typedef typename MatrixType::Scalar Scalar; - friend class EiObject; + friend class EiObject; - MatrixRef(MatrixType& matrix) : m_matrix(matrix) {} - MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {} - ~MatrixRef() {} + EiMatrixRef(MatrixType& matrix) : m_matrix(matrix) {} + EiMatrixRef(const EiMatrixRef& other) : m_matrix(other.m_matrix) {} + ~EiMatrixRef() {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRef) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiMatrixRef) private: int _rows() const { return m_matrix.rows(); } @@ -57,4 +57,4 @@ template class EiMatrixRef MatrixType& m_matrix; }; -#endif // EIGEN_MATRIXREF_H +#endif // EI_MATRIXREF_H diff --git a/src/internal/MatrixStorage.h b/src/internal/MatrixStorage.h index 9554bf961..822903b14 100644 --- a/src/internal/MatrixStorage.h +++ b/src/internal/MatrixStorage.h @@ -23,8 +23,8 @@ // 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 +#ifndef EI_MATRIXSTORAGE_H +#define EI_MATRIXSTORAGE_H template 0 && ColsAtCompileTime > 0); } - ~MatrixStorage() {}; + ~EiMatrixStorage() {}; }; template -class MatrixStorage +class EiMatrixStorage { protected: int m_rows; @@ -77,18 +77,18 @@ class MatrixStorage { return 1; } public: - MatrixStorage(int rows, int cols) : m_rows(rows) + EiMatrixStorage(int rows, int cols) : m_rows(rows) { assert(m_rows > 0 && cols == 1); m_array = new Scalar[m_rows]; } - ~MatrixStorage() + ~EiMatrixStorage() { delete[] m_array; } }; template -class MatrixStorage +class EiMatrixStorage { protected: int m_rows, m_cols; @@ -113,14 +113,14 @@ class MatrixStorage { return m_cols; } public: - MatrixStorage(int rows, int cols) : m_rows(rows), m_cols(cols) + 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]; } - ~MatrixStorage() + ~EiMatrixStorage() { delete[] m_array; } }; -#endif // EIGEN_MATRIXSTORAGE_H +#endif // EI_MATRIXSTORAGE_H diff --git a/src/internal/Minor.h b/src/internal/Minor.h index cc6fa0b18..77fa4b9c8 100644 --- a/src/internal/Minor.h +++ b/src/internal/Minor.h @@ -23,32 +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 EIGEN_MINOR_H -#define EIGEN_MINOR_H +#ifndef EI_MINOR_H +#define EI_MINOR_H template class EiMinor - : public EiObject > + : public EiObject > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class EiObject >; + friend class EiObject >; typedef EiMinor Ref; static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime - 1, ColsAtCompileTime = MatrixType::ColsAtCompileTime - 1; - MatrixMinor(const MatRef& matrix, + EiMinor(const MatRef& matrix, int row, int col = 0) : m_matrix(matrix), m_row(row), m_col(col) { - EIGEN_CHECK_RANGES(matrix, row, col); + EI_CHECK_RANGES(matrix, row, col); } - MatrixMinor(const MatrixMinor& other) + EiMinor(const EiMinor& other) : m_matrix(other.m_matrix), m_row(other.m_row), m_col(other.m_col) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixMinor) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiMinor) private: const Ref& _ref() const { return *this; } @@ -71,10 +71,10 @@ template class EiMinor }; template -MatrixMinor > +EiMinor > EiObject::minor(int row, int col) { - return MatrixMinor(ref(), row, col); + return EiMinor(ref(), row, col); } -#endif // EIGEN_MINOR_H +#endif // EI_MINOR_H diff --git a/src/internal/Object.h b/src/internal/Object.h new file mode 100644 index 000000000..6bf86f87a --- /dev/null +++ b/src/internal/Object.h @@ -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 +// +// 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_EIGENBASE_H +#define EI_EIGENBASE_H + +#include "Util.h" + +template class EiObject +{ + static const int RowsAtCompileTime = Derived::RowsAtCompileTime, + ColsAtCompileTime = Derived::ColsAtCompileTime; + public: + typedef typename EiForwardDecl::Ref Ref; + typedef _Scalar Scalar; + + int rows() const { return static_cast(this)->_rows(); } + int cols() const { return static_cast(this)->_cols(); } + int size() const { return rows() * cols(); } + + Ref ref() + { return static_cast(this)->_ref(); } + + Ref ref() const + { return static_cast(this)->_ref(); } + + Scalar& write(int row, int col) + { + return static_cast(this)->_write(row, col); + } + + Scalar read(int row, int col) const + { + return static_cast(this)->_read(row, col); + } + + template + Derived& operator=(const EiObject& other) + { + assert(rows() == other.rows() && cols() == other.cols()); + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + write(i, j) = other.read(i, j); + return *static_cast(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()); + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + write(i, j) = other.read(i, j); + return *static_cast(this); + } + + EiRow row(int i); + EiColumn col(int i); + EiMinor minor(int row, int col); + EiBlock + block(int startRow, int endRow, int startCol= 0, int endCol = 0); + + template + Derived& operator+=(const EiObject& other); + template + Derived& operator-=(const EiObject& other); + template + Derived& operator*=(const EiObject& other); + + Derived& operator*=(const int& other); + Derived& operator*=(const float& other); + Derived& operator*=(const double& other); + Derived& operator*=(const std::complex& other); + Derived& operator*=(const std::complex& other); + Derived& operator*=(const std::complex& other); + + Derived& operator/=(const int& other); + Derived& operator/=(const float& other); + Derived& operator/=(const double& other); + Derived& operator/=(const std::complex& other); + Derived& operator/=(const std::complex& other); + Derived& operator/=(const std::complex& other); + + Scalar operator()(int row, int col = 0) const + { return read(row, col); } + + Scalar& operator()(int row, int col = 0) + { return write(row, col); } +}; + +template +std::ostream & operator << +( std::ostream & s, + const EiObject & 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_EIGENBASE_H diff --git a/src/internal/RowAndCol.h b/src/internal/RowAndCol.h index 03e25651f..0bfc361b0 100644 --- a/src/internal/RowAndCol.h +++ b/src/internal/RowAndCol.h @@ -23,37 +23,37 @@ // 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_ROWANDCOL_H -#define EIGEN_ROWANDCOL_H +#ifndef EI_ROWANDCOL_H +#define EI_ROWANDCOL_H template class EiRow - : public EiObject > + : public EiObject > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class EiObject >; + friend class EiObject >; typedef EiRow Ref; static const int RowsAtCompileTime = MatrixType::ColsAtCompileTime, ColsAtCompileTime = 1; - MatrixRow(const MatRef& matrix, int row) + EiRow(const MatRef& matrix, int row) : m_matrix(matrix), m_row(row) { - EIGEN_CHECK_ROW_RANGE(matrix, row); + EI_CHECK_ROW_RANGE(matrix, row); } - MatrixRow(const MatrixRow& other) + EiRow(const EiRow& other) : m_matrix(other.m_matrix), m_row(other.m_row) {} template - MatrixRow& operator=(const EiObject& other) + EiRow& operator=(const EiObject& other) { - return EiObject >::operator=(other); + return EiObject >::operator=(other); } - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRow) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiRow) private: const Ref& _ref() const { return *this; } @@ -63,15 +63,15 @@ template class EiRow Scalar& _write(int row, int col=0) { - EIGEN_UNUSED(col); - EIGEN_CHECK_ROW_RANGE(*this, row); + EI_UNUSED(col); + EI_CHECK_ROW_RANGE(*this, row); return m_matrix.write(m_row, row); } Scalar _read(int row, int col=0) const { - EIGEN_UNUSED(col); - EIGEN_CHECK_ROW_RANGE(*this, row); + EI_UNUSED(col); + EI_CHECK_ROW_RANGE(*this, row); return m_matrix.read(m_row, row); } @@ -80,28 +80,28 @@ template class EiRow const int m_row; }; -template class MatrixCol - : public EiObject > +template class EiColumn + : public EiObject > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; - friend class EiObject >; - typedef MatrixCol Ref; + friend class EiObject >; + typedef EiColumn Ref; static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = 1; - MatrixCol(const MatRef& matrix, int col) + EiColumn(const MatRef& matrix, int col) : m_matrix(matrix), m_col(col) { - EIGEN_CHECK_COL_RANGE(matrix, col); + EI_CHECK_COL_RANGE(matrix, col); } - MatrixCol(const MatrixCol& other) + EiColumn(const EiColumn& other) : m_matrix(other.m_matrix), m_col(other.m_col) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixCol) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiColumn) private: const Ref& _ref() const { return *this; } @@ -110,15 +110,15 @@ template class MatrixCol Scalar& _write(int row, int col=0) { - EIGEN_UNUSED(col); - EIGEN_CHECK_ROW_RANGE(*this, row); + EI_UNUSED(col); + EI_CHECK_ROW_RANGE(*this, row); return m_matrix.write(row, m_col); } Scalar _read(int row, int col=0) const { - EIGEN_UNUSED(col); - EIGEN_CHECK_ROW_RANGE(*this, row); + EI_UNUSED(col); + EI_CHECK_ROW_RANGE(*this, row); return m_matrix.read(row, m_col); } @@ -128,17 +128,17 @@ template class MatrixCol }; template -MatrixRow > +EiRow > EiObject::row(int i) { - return MatrixRow(ref(), i); + return EiRow(ref(), i); } template -MatrixCol > +EiColumn > EiObject::col(int i) { - return MatrixCol(ref(), i); + return EiColumn(ref(), i); } -#endif // EIGEN_ROWANDCOL_H +#endif // EI_ROWANDCOL_H diff --git a/src/internal/ScalarOps.h b/src/internal/ScalarOps.h index 1dd072cb2..6d7de3bed 100644 --- a/src/internal/ScalarOps.h +++ b/src/internal/ScalarOps.h @@ -23,28 +23,28 @@ // 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_SCALAROPS_H -#define EIGEN_SCALAROPS_H +#ifndef EI_SCALAROPS_H +#define EI_SCALAROPS_H template class EiScalarProduct - : public EiObject > + : public EiObject > { public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Ref MatRef; typedef EiScalarProduct Ref; - friend class EiObject >; + friend class EiObject >; static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime; - ScalarProduct(const MatRef& matrix, Scalar scalar) + EiScalarProduct(const MatRef& matrix, Scalar scalar) : m_matrix(matrix), m_scalar(scalar) {} - ScalarProduct(const ScalarProduct& other) + EiScalarProduct(const EiScalarProduct& other) : m_matrix(other.m_matrix), m_scalar(other.m_scalar) {} - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ScalarProduct) + EI_INHERIT_ASSIGNMENT_OPERATORS(EiScalarProduct) private: const Ref& _ref() const { return *this; } @@ -61,26 +61,26 @@ template class EiScalarProduct const Scalar m_scalar; }; -#define EIGEN_MAKE_SCALAR_OPS(OtherScalar) \ +#define EI_MAKE_SCALAR_OPS(OtherScalar) \ template \ -ScalarProduct \ -operator*(const EiObject& matrix, \ +EiScalarProduct \ +operator*(const EiObject& matrix, \ OtherScalar scalar) \ { \ - return ScalarProduct(matrix.ref(), scalar); \ + return EiScalarProduct(matrix.ref(), scalar); \ } \ \ template \ -ScalarProduct \ +EiScalarProduct \ operator*(OtherScalar scalar, \ - const EiObject& matrix) \ + const EiObject& matrix) \ { \ - return ScalarProduct(matrix.ref(), scalar); \ + return EiScalarProduct(matrix.ref(), scalar); \ } \ \ template \ -ScalarProduct \ -operator/(const EiObject& matrix, \ +EiScalarProduct \ +operator/(const EiObject& matrix, \ OtherScalar scalar) \ { \ return matrix * (static_cast(1) / scalar); \ @@ -102,13 +102,13 @@ EiObject::operator/=(const OtherScalar &other) \ return *static_cast(this); \ } -EIGEN_MAKE_SCALAR_OPS(int) -EIGEN_MAKE_SCALAR_OPS(float) -EIGEN_MAKE_SCALAR_OPS(double) -EIGEN_MAKE_SCALAR_OPS(std::complex) -EIGEN_MAKE_SCALAR_OPS(std::complex) -EIGEN_MAKE_SCALAR_OPS(std::complex) +EI_MAKE_SCALAR_OPS(int) +EI_MAKE_SCALAR_OPS(float) +EI_MAKE_SCALAR_OPS(double) +EI_MAKE_SCALAR_OPS(std::complex) +EI_MAKE_SCALAR_OPS(std::complex) +EI_MAKE_SCALAR_OPS(std::complex) -#undef EIGEN_MAKE_SCALAR_OPS +#undef EI_MAKE_SCALAR_OPS -#endif // EIGEN_SCALAROPS_H +#endif // EI_SCALAROPS_H diff --git a/src/internal/Util.h b/src/internal/Util.h index d4362383e..05ebbe163 100644 --- a/src/internal/Util.h +++ b/src/internal/Util.h @@ -23,8 +23,8 @@ // 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 +#ifndef EI_UTIL_H +#define EI_UTIL_H #include #include @@ -32,12 +32,12 @@ #undef minor -#define EIGEN_UNUSED(x) (void)x -#define EIGEN_CHECK_RANGES(matrix, row, col) \ +#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 EIGEN_CHECK_ROW_RANGE(matrix, row) \ +#define EI_CHECK_ROW_RANGE(matrix, row) \ assert(row >= 0 && row < (matrix).rows()) -#define EIGEN_CHECK_COL_RANGE(matrix, col) \ +#define EI_CHECK_COL_RANGE(matrix, col) \ assert(col >= 0 && col < (matrix).cols()) //forward declarations @@ -65,9 +65,9 @@ struct EiForwardDecl > const int EiDynamic = -1; -#define EIGEN_UNUSED(x) (void)x +#define EI_UNUSED(x) (void)x -#define EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ +#define EI_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ template \ Derived& operator Op(const EiObject& other) \ { \ @@ -78,18 +78,18 @@ Derived& operator Op(const Derived& other) \ return EiObject::operator Op(other); \ } -#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ +#define EI_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ template \ Derived& operator Op(const Other& scalar) \ { \ return EiObject::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, /=) +#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 // EIGEN_UTIL_H +#endif // EI_UTIL_H diff --git a/test/main.h b/test/main.h index 0ae9967b5..1cdc781d7 100644 --- a/test/main.h +++ b/test/main.h @@ -23,8 +23,8 @@ // 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_TEST_MAIN_H -#define EIGEN_TEST_MAIN_H +#ifndef EI_TEST_MAIN_H +#define EI_TEST_MAIN_H #include #include @@ -47,4 +47,4 @@ class EigenTest : public QObject void testMatrixManip(); }; -#endif // EIGEN_TEST_MAIN_H +#endif // EI_TEST_MAIN_H diff --git a/test/matrixmanip.cpp b/test/matrixmanip.cpp index 608dc1dad..4851a9178 100644 --- a/test/matrixmanip.cpp +++ b/test/matrixmanip.cpp @@ -44,9 +44,9 @@ template void matrixManip(const MatrixType& m) void EigenTest::testMatrixManip() { - matrixManip(Matrix()); - matrixManip(Matrix()); - matrixManip(Matrix, 4,3>()); + matrixManip(EiMatrix()); + matrixManip(EiMatrix()); + matrixManip(EiMatrix, 4,3>()); matrixManip(EiMatrixXi(2, 2)); matrixManip(EiMatrixXd(3, 5)); matrixManip(EiMatrixXcf(4, 4)); diff --git a/test/matrixops.cpp b/test/matrixops.cpp index 059cb6126..e5f01759e 100644 --- a/test/matrixops.cpp +++ b/test/matrixops.cpp @@ -58,14 +58,14 @@ template(), Matrix()); - matrixOps(Matrix(), Matrix()); - matrixOps(Matrix(), Matrix()); - matrixOps(Matrix, 4,3>(), Matrix, 3,4>()); + matrixOps(EiMatrix(), EiMatrix()); + matrixOps(EiMatrix(), EiMatrix()); + matrixOps(EiMatrix(), EiMatrix()); + matrixOps(EiMatrix, 4,3>(), EiMatrix, 3,4>()); matrixOps(EiMatrixXf(1, 1), EiMatrixXf(1, 3)); matrixOps(EiMatrixXi(2, 2), EiMatrixXi(2, 2)); matrixOps(EiMatrixXd(3, 5), EiMatrixXd(5, 1)); matrixOps(EiMatrixXcf(4, 4), EiMatrixXcf(4, 4)); - matrixOps(EiMatrixXd(3, 5), Matrix()); + matrixOps(EiMatrixXd(3, 5), EiMatrix()); matrixOps(EiMatrix4cf(), EiMatrixXcf(4, 4)); } diff --git a/test/vectorops.cpp b/test/vectorops.cpp index 1ac9c45df..b061206c2 100644 --- a/test/vectorops.cpp +++ b/test/vectorops.cpp @@ -53,11 +53,11 @@ template void vectorOps(const VectorType& v) void EigenTest::testVectorOps() { - vectorOps(Vector2i()); - vectorOps(Vector3d()); - vectorOps(Vector4cf()); - vectorOps(VectorXf(1)); - vectorOps(VectorXi(2)); - vectorOps(VectorXd(3)); - vectorOps(VectorXcf(4)); + vectorOps(EiVector2i()); + vectorOps(EiVector3d()); + vectorOps(EiVector4cf()); + vectorOps(EiVectorXf(1)); + vectorOps(EiVectorXi(2)); + vectorOps(EiVectorXd(3)); + vectorOps(EiVectorXcf(4)); } -- cgit v1.2.3