From 1af61c6ff078e6f9f9cd1298374811cfc73d4488 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 9 Sep 2007 09:41:15 +0000 Subject: [PATCH] reorganize header files, split MatrixBase into smaller files. expose only a few meta-headers to the user, the rest moves to a internal/ subdirectory --- doc/tutorial.cpp | 2 +- src/{All.h => All} | 13 ++-- src/CMakeLists.txt | 8 +- src/Core | 32 ++++++++ src/Manip | 33 ++++++++ src/{ => internal}/Block.h | 0 src/internal/CMakeLists.txt | 6 ++ src/{ => internal}/Matrix.h | 4 - src/internal/MatrixAlias.h | 116 +++++++++++++++++++++++++++ src/{ => internal}/MatrixBase.h | 134 ++------------------------------ src/{ => internal}/MatrixOps.h | 0 src/internal/MatrixRef.h | 76 ++++++++++++++++++ src/{ => internal}/MatrixXpr.h | 0 src/{ => internal}/Minor.h | 0 src/{ => internal}/RowAndCol.h | 0 src/{ => internal}/ScalarOps.h | 0 src/{ => internal}/Util.h | 4 +- src/{ => internal}/Vector.h | 3 - test/main.h | 10 +-- test/matrixmanip.cpp | 2 +- test/matrixops.cpp | 2 +- test/vectorops.cpp | 2 +- 22 files changed, 294 insertions(+), 153 deletions(-) rename src/{All.h => All} (89%) create mode 100644 src/Core create mode 100644 src/Manip rename src/{ => internal}/Block.h (100%) create mode 100644 src/internal/CMakeLists.txt rename src/{ => internal}/Matrix.h (98%) create mode 100644 src/internal/MatrixAlias.h rename src/{ => internal}/MatrixBase.h (63%) rename src/{ => internal}/MatrixOps.h (100%) create mode 100644 src/internal/MatrixRef.h rename src/{ => internal}/MatrixXpr.h (100%) rename src/{ => internal}/Minor.h (100%) rename src/{ => internal}/RowAndCol.h (100%) rename src/{ => internal}/ScalarOps.h (100%) rename src/{ => internal}/Util.h (98%) rename src/{ => internal}/Vector.h (98%) diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index 967f0a544..3b4489522 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -1,4 +1,4 @@ -#include"../src/All.h" +#include "../src/All" using namespace std; using namespace Eigen; diff --git a/src/All.h b/src/All similarity index 89% rename from src/All.h rename to src/All index 03828a4d8..5784a91f4 100644 --- a/src/All.h +++ b/src/All @@ -23,13 +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_EIGEN_H -#define EIGEN_EIGEN_H +#ifndef EIGEN_ALL_H +#define EIGEN_ALL_H -#include"Matrix.h" -#include"Vector.h" -#include"RowAndCol.h" -#include"Minor.h" -#include"Block.h" +#include "Core" +#include "Manip" -#endif // EIGEN_EIGEN_H +#endif // EIGEN_ALL_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5459d7453..d5cdda888 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,8 @@ -FILE(GLOB Eigen_SRCS "*.h") +set(Eigen_SRCS + All + Core + Manip +) SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/eigen2" @@ -10,3 +14,5 @@ INSTALL(FILES ${Eigen_SRCS} DESTINATION ${INCLUDE_INSTALL_DIR} ) + +add_subdirectory(internal) \ No newline at end of file diff --git a/src/Core b/src/Core new file mode 100644 index 000000000..767fb73e0 --- /dev/null +++ b/src/Core @@ -0,0 +1,32 @@ +// 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_CORE_H +#define EIGEN_CORE_H + +#include "internal/Vector.h" +#include "internal/Matrix.h" + +#endif // EIGEN_CORE_H diff --git a/src/Manip b/src/Manip new file mode 100644 index 000000000..0bfc4f14b --- /dev/null +++ b/src/Manip @@ -0,0 +1,33 @@ +// 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_MANIP_H +#define EIGEN_MANIP_H + +#include "internal/RowAndCol.h" +#include "internal/Block.h" +#include "internal/Minor.h" + +#endif // EIGEN_MANIP_H diff --git a/src/Block.h b/src/internal/Block.h similarity index 100% rename from src/Block.h rename to src/internal/Block.h diff --git a/src/internal/CMakeLists.txt b/src/internal/CMakeLists.txt new file mode 100644 index 000000000..c3643b916 --- /dev/null +++ b/src/internal/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB Eigen_internal_SRCS "*.h") + +INSTALL(FILES + ${Eigen_internal_SRCS} + DESTINATION ${INCLUDE_INSTALL_DIR}/internal + ) diff --git a/src/Matrix.h b/src/internal/Matrix.h similarity index 98% rename from src/Matrix.h rename to src/internal/Matrix.h index 8ff819902..be7c22bc3 100644 --- a/src/Matrix.h +++ b/src/internal/Matrix.h @@ -176,8 +176,4 @@ class MatrixX : public MatrixBase< MatrixX > } // namespace Eigen -#include"MatrixOps.h" -#include"ScalarOps.h" -#include"RowAndCol.h" - #endif // EIGEN_MATRIX_H diff --git a/src/internal/MatrixAlias.h b/src/internal/MatrixAlias.h new file mode 100644 index 000000000..868011321 --- /dev/null +++ b/src/internal/MatrixAlias.h @@ -0,0 +1,116 @@ +// 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_MATRIXALIAS_H +#define EIGEN_MATRIXALIAS_H + +namespace Eigen +{ + +template class MatrixAlias +{ + public: + typedef typename Derived::Scalar Scalar; + typedef MatrixRef > Ref; + typedef MatrixXpr Xpr; + + MatrixAlias(Derived& matrix) : m_aliased(matrix), m_tmp(matrix) {} + MatrixAlias(const MatrixAlias& other) : m_aliased(other.m_aliased), m_tmp(other.m_tmp) {} + + ~MatrixAlias() + { + m_aliased.xpr() = m_tmp; + } + + Ref ref() + { + return Ref(*this); + } + + Xpr xpr() + { + return Xpr(ref()); + } + + static bool hasDynamicNumRows() + { + return MatrixBase::hasDynamicNumRows(); + } + + static bool hasDynamicNumCols() + { + return MatrixBase::hasDynamicNumCols(); + } + + int rows() const { return m_tmp.rows(); } + int cols() const { return m_tmp.cols(); } + + Scalar& write(int row, int col) + { + return m_tmp.write(row, col); + } + + MatrixXpr > row(int i) { return xpr().row(i); }; + MatrixXpr > col(int i) { return xpr().col(i); }; + MatrixXpr > minor(int row, int col) { return xpr().minor(row, col); }; + MatrixXpr > + block(int startRow, int endRow, int startCol = 0, int endCol = 0) + { + return xpr().block(startRow, endRow, startCol, endCol); + } + + template + void operator=(const MatrixXpr &other) + { + xpr() = other; + } + + template + void operator+=(const MatrixXpr &other) + { + xpr() += other; + } + + template + void operator-=(const MatrixXpr &other) + { + xpr() -= other; + } + + protected: + MatrixRef > m_aliased; + Derived m_tmp; +}; + +template +typename MatrixBase::Alias +MatrixBase::alias() +{ + return Alias(*static_cast(this)); +} + +} // namespace Eigen + +#endif // EIGEN_MATRIXALIAS_H diff --git a/src/MatrixBase.h b/src/internal/MatrixBase.h similarity index 63% rename from src/MatrixBase.h rename to src/internal/MatrixBase.h index 5859a14cc..910cc4ac0 100644 --- a/src/MatrixBase.h +++ b/src/internal/MatrixBase.h @@ -26,54 +26,13 @@ #ifndef EIGEN_MATRIXBASE_H #define EIGEN_MATRIXBASE_H -#include"Util.h" -#include"MatrixXpr.h" +#include "Util.h" +#include "MatrixXpr.h" +#include "MatrixRef.h" namespace Eigen { -template class MatrixRef -{ - public: - typedef typename ForwardDecl::Scalar Scalar; - typedef MatrixXpr > Xpr; - - MatrixRef(MatrixType& matrix) : m_matrix(matrix) {} - MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {} - ~MatrixRef() {} - - static bool hasDynamicNumRows() - { - return MatrixType::hasDynamicNumRows(); - } - - static bool hasDynamicNumCols() - { - return MatrixType::hasDynamicNumCols(); - } - - 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); - } - - Xpr xpr() - { - return Xpr(*this); - } - - protected: - MatrixType& m_matrix; -}; - template class MatrixBase { @@ -232,88 +191,11 @@ std::ostream & operator << (std::ostream & s, return s; } -template class MatrixAlias -{ - public: - typedef typename Derived::Scalar Scalar; - typedef MatrixRef > Ref; - typedef MatrixXpr Xpr; - - MatrixAlias(Derived& matrix) : m_aliased(matrix), m_tmp(matrix) {} - MatrixAlias(const MatrixAlias& other) : m_aliased(other.m_aliased), m_tmp(other.m_tmp) {} - - ~MatrixAlias() - { - m_aliased.xpr() = m_tmp; - } - - Ref ref() - { - return Ref(*this); - } - - Xpr xpr() - { - return Xpr(ref()); - } - - static bool hasDynamicNumRows() - { - return MatrixBase::hasDynamicNumRows(); - } - - static bool hasDynamicNumCols() - { - return MatrixBase::hasDynamicNumCols(); - } - - int rows() const { return m_tmp.rows(); } - int cols() const { return m_tmp.cols(); } - - Scalar& write(int row, int col) - { - return m_tmp.write(row, col); - } - - MatrixXpr > row(int i) { return xpr().row(i); }; - MatrixXpr > col(int i) { return xpr().col(i); }; - MatrixXpr > minor(int row, int col) { return xpr().minor(row, col); }; - MatrixXpr > - block(int startRow, int endRow, int startCol = 0, int endCol = 0) - { - return xpr().block(startRow, endRow, startCol, endCol); - } - - template - void operator=(const MatrixXpr &other) - { - xpr() = other; - } - - template - void operator+=(const MatrixXpr &other) - { - xpr() += other; - } - - template - void operator-=(const MatrixXpr &other) - { - xpr() -= other; - } - - protected: - MatrixRef > m_aliased; - Derived m_tmp; -}; - -template -typename MatrixBase::Alias -MatrixBase::alias() -{ - return Alias(*static_cast(this)); -} - } // namespace Eigen +#include "MatrixAlias.h" +#include "MatrixOps.h" +#include "ScalarOps.h" +#include "RowAndCol.h" + #endif // EIGEN_MATRIXBASE_H diff --git a/src/MatrixOps.h b/src/internal/MatrixOps.h similarity index 100% rename from src/MatrixOps.h rename to src/internal/MatrixOps.h diff --git a/src/internal/MatrixRef.h b/src/internal/MatrixRef.h new file mode 100644 index 000000000..0123c535c --- /dev/null +++ b/src/internal/MatrixRef.h @@ -0,0 +1,76 @@ +// 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_MATRIXREF_H +#define EIGEN_MATRIXREF_H + +namespace Eigen +{ + +template class MatrixRef +{ + public: + typedef typename ForwardDecl::Scalar Scalar; + typedef MatrixXpr > Xpr; + + MatrixRef(MatrixType& matrix) : m_matrix(matrix) {} + MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {} + ~MatrixRef() {} + + static bool hasDynamicNumRows() + { + return MatrixType::hasDynamicNumRows(); + } + + static bool hasDynamicNumCols() + { + return MatrixType::hasDynamicNumCols(); + } + + 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); + } + + Xpr xpr() + { + return Xpr(*this); + } + + protected: + MatrixType& m_matrix; +}; + +} // namespace Eigen + +#endif // EIGEN_MATRIXREF_H diff --git a/src/MatrixXpr.h b/src/internal/MatrixXpr.h similarity index 100% rename from src/MatrixXpr.h rename to src/internal/MatrixXpr.h diff --git a/src/Minor.h b/src/internal/Minor.h similarity index 100% rename from src/Minor.h rename to src/internal/Minor.h diff --git a/src/RowAndCol.h b/src/internal/RowAndCol.h similarity index 100% rename from src/RowAndCol.h rename to src/internal/RowAndCol.h diff --git a/src/ScalarOps.h b/src/internal/ScalarOps.h similarity index 100% rename from src/ScalarOps.h rename to src/internal/ScalarOps.h diff --git a/src/Util.h b/src/internal/Util.h similarity index 98% rename from src/Util.h rename to src/internal/Util.h index f1b51bbe1..31b94b421 100644 --- a/src/Util.h +++ b/src/internal/Util.h @@ -26,8 +26,8 @@ #ifndef EIGEN_UTIL_H #define EIGEN_UTIL_H -#include -#include +#include +#include #undef minor diff --git a/src/Vector.h b/src/internal/Vector.h similarity index 98% rename from src/Vector.h rename to src/internal/Vector.h index ae43a50c7..0d1c719c5 100644 --- a/src/Vector.h +++ b/src/internal/Vector.h @@ -187,7 +187,4 @@ class VectorX : public MatrixBase > } // namespace Eigen -#include"MatrixOps.h" -#include"ScalarOps.h" - #endif // EIGEN_VECTOR_H diff --git a/test/main.h b/test/main.h index ea7e22f2b..45cabd369 100644 --- a/test/main.h +++ b/test/main.h @@ -26,11 +26,11 @@ #ifndef EIGEN_TEST_MAIN_H #define EIGEN_TEST_MAIN_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace std; using namespace Eigen; diff --git a/test/matrixmanip.cpp b/test/matrixmanip.cpp index b3413212a..90ddcaca9 100644 --- a/test/matrixmanip.cpp +++ b/test/matrixmanip.cpp @@ -23,7 +23,7 @@ // 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. -#include"main.h" +#include "main.h" template void matrixManip(const MatrixType& m) { diff --git a/test/matrixops.cpp b/test/matrixops.cpp index 56b252287..b8fd122c3 100644 --- a/test/matrixops.cpp +++ b/test/matrixops.cpp @@ -23,7 +23,7 @@ // 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. -#include"main.h" +#include "main.h" template void matrixOps(const MatrixType1& m1, const MatrixType2& m2) diff --git a/test/vectorops.cpp b/test/vectorops.cpp index de0f03e6f..33aa72178 100644 --- a/test/vectorops.cpp +++ b/test/vectorops.cpp @@ -23,7 +23,7 @@ // 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. -#include"main.h" +#include "main.h" template void vectorOps(const VectorType& v) {