diff options
-rw-r--r-- | src/Core.h | 1 | ||||
-rw-r--r-- | src/Core/Cast.h | 70 | ||||
-rw-r--r-- | src/Core/Conjugate.h | 3 | ||||
-rw-r--r-- | src/Core/Matrix.h | 2 | ||||
-rw-r--r-- | src/Core/Object.h | 3 | ||||
-rw-r--r-- | src/Core/Util.h | 1 |
6 files changed, 77 insertions, 3 deletions
diff --git a/src/Core.h b/src/Core.h index 2b2e5b388..0a10e2a14 100644 --- a/src/Core.h +++ b/src/Core.h @@ -11,6 +11,7 @@ namespace Eigen { #include "Core/MatrixRef.h" #include "Core/MatrixStorage.h" #include "Core/Matrix.h" +#include "Core/Cast.h" #include "Core/Eval.h" #include "Core/ScalarMultiple.h" #include "Core/Sum.h" diff --git a/src/Core/Cast.h b/src/Core/Cast.h new file mode 100644 index 000000000..cc4e19f23 --- /dev/null +++ b/src/Core/Cast.h @@ -0,0 +1,70 @@ +// 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_CAST_H +#define EI_CAST_H + +template<typename NewScalar, typename MatrixType> class Cast + : public Object<NewScalar, Cast<NewScalar, MatrixType> > +{ + public: + typedef NewScalar Scalar; + typedef typename MatrixType::Ref MatRef; + friend class Object<Scalar, Cast<Scalar, MatrixType> >; + + static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime; + + Cast(const MatRef& matrix) : m_matrix(matrix) {} + + Cast(const Cast& other) + : m_matrix(other.m_matrix) {} + + // assignments are illegal but we still want to intercept them and get clean compile errors + EI_INHERIT_ASSIGNMENT_OPERATORS(Cast) + + private: + const Cast& _ref() 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 static_cast<Scalar>(m_matrix.read(row, col)); + } + + protected: + MatRef m_matrix; +}; + +template<typename Scalar, typename Derived> +template<typename NewScalar> +Cast<NewScalar, Derived> +Object<Scalar, Derived>::cast() const +{ + return Cast<NewScalar, Derived>(static_cast<const Derived*>(this)->ref()); +} + +#endif // EI_CAST_H diff --git a/src/Core/Conjugate.h b/src/Core/Conjugate.h index 6061fab03..127b0dee9 100644 --- a/src/Core/Conjugate.h +++ b/src/Core/Conjugate.h @@ -42,7 +42,8 @@ template<typename MatrixType> class Conjugate Conjugate(const Conjugate& other) : m_matrix(other.m_matrix) {} - EI_INHERIT_ASSIGNMENT_OPERATORS(Conjugate) + // assignments are illegal but we still want to intercept them and get clean compile errors + EI_INHERIT_ASSIGNMENT_OPERATORS(Conjugate) private: const Conjugate& _ref() const { return *this; } diff --git a/src/Core/Matrix.h b/src/Core/Matrix.h index 0d714faac..10b3dd1d2 100644 --- a/src/Core/Matrix.h +++ b/src/Core/Matrix.h @@ -28,7 +28,7 @@ template<typename _Scalar, int _Rows, int _Cols> class Matrix : public Object<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, - public MatrixStorage<_Scalar, _Rows, _Cols> + public MatrixStorage<_Scalar, _Rows, _Cols> { public: friend class Object<_Scalar, Matrix>; diff --git a/src/Core/Object.h b/src/Core/Object.h index 93871a1d6..ff412e789 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -91,6 +91,8 @@ template<typename Scalar, typename Derived> class Object return *static_cast<Derived*>(this); } + template<typename NewScalar> Cast<NewScalar, Derived> cast() const; + Row<Derived> row(int i) const; Column<Derived> col(int i) const; Minor<Derived> minor(int row, int col) const; @@ -102,7 +104,6 @@ template<typename Scalar, typename Derived> class Object template<typename OtherDerived> Scalar dot(const OtherDerived& other) const; - RealScalar norm2() const; RealScalar norm() const; ScalarMultiple<Derived> normalized() const; diff --git a/src/Core/Util.h b/src/Core/Util.h index 5dcc5c4a1..7ad38aa21 100644 --- a/src/Core/Util.h +++ b/src/Core/Util.h @@ -43,6 +43,7 @@ using Eigen::Matrix; //forward declarations template<typename _Scalar, int _Rows, int _Cols> class Matrix; template<typename MatrixType> class MatrixRef; +template<typename NewScalar, typename MatrixType> class Cast; template<typename MatrixType> class Row; template<typename MatrixType> class Column; template<typename MatrixType> class Minor; |