diff options
-rw-r--r-- | Eigen/Sparse | 1 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseMatrix.h | 5 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseMatrixBase.h | 10 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseNestByValue.h | 84 | ||||
-rw-r--r-- | Eigen/src/Sparse/SparseUtil.h | 1 | ||||
-rw-r--r-- | test/main.h | 1 | ||||
-rw-r--r-- | test/sparse_basic.cpp | 2 |
7 files changed, 97 insertions, 7 deletions
diff --git a/Eigen/Sparse b/Eigen/Sparse index 364fd50c9..a8888daa3 100644 --- a/Eigen/Sparse +++ b/Eigen/Sparse @@ -84,6 +84,7 @@ namespace Eigen { #include "src/Sparse/SparseUtil.h" #include "src/Sparse/SparseMatrixBase.h" +#include "src/Sparse/SparseNestByValue.h" #include "src/Sparse/CompressedStorage.h" #include "src/Sparse/AmbiVector.h" #include "src/Sparse/RandomSetter.h" diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h index b751b5cb9..af3b5e5eb 100644 --- a/Eigen/src/Sparse/SparseMatrix.h +++ b/Eigen/src/Sparse/SparseMatrix.h @@ -443,9 +443,8 @@ class SparseMatrix // two passes algorithm: // 1 - compute the number of coeffs per dest inner vector // 2 - do the actual copy/eval - // Since each coeff of the rhs has to be evaluated twice, let's evauluate it if needed - //typedef typename ei_nested<OtherDerived,2>::type OtherCopy; - typedef typename ei_eval<OtherDerived>::type OtherCopy; + // Since each coeff of the rhs has to be evaluated twice, let's evaluate it if needed + typedef typename ei_nested<OtherDerived,2>::type OtherCopy; typedef typename ei_cleantype<OtherCopy>::type _OtherCopy; OtherCopy otherCopy(other.derived()); diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index 8d9406cfb..6cf4d5e96 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -99,8 +99,10 @@ template<typename Derived> class SparseMatrixBase /** \internal the return type of MatrixBase::imag() */ typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType; /** \internal the return type of MatrixBase::adjoint() */ - typedef SparseTranspose</*NestByValue<*/typename ei_cleantype<ConjugateReturnType>::type> /*>*/ - AdjointReturnType; + typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, + SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::SparseTranspose<Derived> > >, + SparseTranspose<Derived> + >::ret AdjointReturnType; #ifndef EIGEN_PARSED_BY_DOXYGEN /** This is the "real scalar" type; if the \a Scalar type is already real numbers @@ -342,7 +344,7 @@ template<typename Derived> class SparseMatrixBase SparseTranspose<Derived> transpose() { return derived(); } const SparseTranspose<Derived> transpose() const { return derived(); } // void transposeInPlace(); - const AdjointReturnType adjoint() const { return conjugate()/*.nestByValue()*/; } + const AdjointReturnType adjoint() const { return transpose().nestByValue(); } // sub-vector SparseInnerVectorSet<Derived,1> row(int i); @@ -520,7 +522,7 @@ template<typename Derived> class SparseMatrixBase */ // inline int stride(void) const { return derived().stride(); } -// inline const NestByValue<Derived> nestByValue() const; + inline const SparseNestByValue<Derived> nestByValue() const; ConjugateReturnType conjugate() const; diff --git a/Eigen/src/Sparse/SparseNestByValue.h b/Eigen/src/Sparse/SparseNestByValue.h new file mode 100644 index 000000000..72fd056c4 --- /dev/null +++ b/Eigen/src/Sparse/SparseNestByValue.h @@ -0,0 +1,84 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> +// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, 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 of +// the License, 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 Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see <http://www.gnu.org/licenses/>. + +#ifndef EIGEN_SPARSENESTBYVALUE_H +#define EIGEN_SPARSENESTBYVALUE_H + +/** \class SparseNestByValue + * + * \brief Expression which must be nested by value + * + * \param ExpressionType the type of the object of which we are requiring nesting-by-value + * + * This class is the return type of MatrixBase::nestByValue() + * and most of the time this is the only way it is used. + * + * \sa SparseMatrixBase::nestByValue(), class NestByValue + */ +template<typename ExpressionType> +struct ei_traits<SparseNestByValue<ExpressionType> > : public ei_traits<ExpressionType> +{}; + +template<typename ExpressionType> class SparseNestByValue + : public SparseMatrixBase<NestByValue<ExpressionType> > +{ + public: + + class InnerIterator; + + EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseNestByValue) + + inline SparseNestByValue(const ExpressionType& matrix) : m_expression(matrix) {} + + EIGEN_STRONG_INLINE int rows() const { return m_expression.rows(); } + EIGEN_STRONG_INLINE int cols() const { return m_expression.cols(); } + + operator const ExpressionType&() const { return m_expression; } + + protected: + const ExpressionType m_expression; +}; + +/** \returns an expression of the temporary version of *this. + */ +template<typename Derived> +inline const SparseNestByValue<Derived> +SparseMatrixBase<Derived>::nestByValue() const +{ + return SparseNestByValue<Derived>(derived()); +} + +template<typename MatrixType> +class SparseNestByValue<MatrixType>::InnerIterator : public MatrixType::InnerIterator +{ + typedef typename MatrixType::InnerIterator Base; + public: + + EIGEN_STRONG_INLINE InnerIterator(const SparseNestByValue& expr, int outer) + : Base(expr.m_expression, outer) + {} +}; + +#endif // EIGEN_SPARSENESTBYVALUE_H diff --git a/Eigen/src/Sparse/SparseUtil.h b/Eigen/src/Sparse/SparseUtil.h index 52781aa46..a3b1d7ae9 100644 --- a/Eigen/src/Sparse/SparseUtil.h +++ b/Eigen/src/Sparse/SparseUtil.h @@ -106,6 +106,7 @@ template<typename _Scalar, int _Flags = 0> class DynamicSparseMatrix; template<typename _Scalar, int _Flags = 0> class SparseVector; template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix; +template<typename MatrixType> class SparseNestByValue; template<typename MatrixType> class SparseTranspose; template<typename MatrixType, int Size> class SparseInnerVectorSet; template<typename Derived> class SparseCwise; diff --git a/test/main.h b/test/main.h index 53c8245c6..3947451cc 100644 --- a/test/main.h +++ b/test/main.h @@ -28,6 +28,7 @@ #include <iostream> #include <string> #include <vector> +#include <typeinfo> #ifndef EIGEN_TEST_FUNC #error EIGEN_TEST_FUNC must be defined diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 9b7d7c4e6..666eea872 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -299,6 +299,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re initSparse<Scalar>(density, refMat2, m2); VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval()); VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose()); + + VERIFY_IS_APPROX(SparseMatrixType(m2.adjoint()), refMat2.adjoint()); } // test prune |