mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-20 20:04:26 +08:00
add a SparseNestByValue expression and fix issue in sparse adjoint evaluation
This commit is contained in:
parent
ab17f92728
commit
1e7b1a8a85
@ -84,6 +84,7 @@ namespace Eigen {
|
|||||||
|
|
||||||
#include "src/Sparse/SparseUtil.h"
|
#include "src/Sparse/SparseUtil.h"
|
||||||
#include "src/Sparse/SparseMatrixBase.h"
|
#include "src/Sparse/SparseMatrixBase.h"
|
||||||
|
#include "src/Sparse/SparseNestByValue.h"
|
||||||
#include "src/Sparse/CompressedStorage.h"
|
#include "src/Sparse/CompressedStorage.h"
|
||||||
#include "src/Sparse/AmbiVector.h"
|
#include "src/Sparse/AmbiVector.h"
|
||||||
#include "src/Sparse/RandomSetter.h"
|
#include "src/Sparse/RandomSetter.h"
|
||||||
|
@ -443,9 +443,8 @@ class SparseMatrix
|
|||||||
// two passes algorithm:
|
// two passes algorithm:
|
||||||
// 1 - compute the number of coeffs per dest inner vector
|
// 1 - compute the number of coeffs per dest inner vector
|
||||||
// 2 - do the actual copy/eval
|
// 2 - do the actual copy/eval
|
||||||
// Since each coeff of the rhs has to be evaluated twice, let's evauluate it if needed
|
// 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_nested<OtherDerived,2>::type OtherCopy;
|
||||||
typedef typename ei_eval<OtherDerived>::type OtherCopy;
|
|
||||||
typedef typename ei_cleantype<OtherCopy>::type _OtherCopy;
|
typedef typename ei_cleantype<OtherCopy>::type _OtherCopy;
|
||||||
OtherCopy otherCopy(other.derived());
|
OtherCopy otherCopy(other.derived());
|
||||||
|
|
||||||
|
@ -99,8 +99,10 @@ template<typename Derived> class SparseMatrixBase
|
|||||||
/** \internal the return type of MatrixBase::imag() */
|
/** \internal the return type of MatrixBase::imag() */
|
||||||
typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
|
typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
|
||||||
/** \internal the return type of MatrixBase::adjoint() */
|
/** \internal the return type of MatrixBase::adjoint() */
|
||||||
typedef SparseTranspose</*NestByValue<*/typename ei_cleantype<ConjugateReturnType>::type> /*>*/
|
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
|
||||||
AdjointReturnType;
|
SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::SparseTranspose<Derived> > >,
|
||||||
|
SparseTranspose<Derived>
|
||||||
|
>::ret AdjointReturnType;
|
||||||
|
|
||||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||||
/** This is the "real scalar" type; if the \a Scalar type is already real numbers
|
/** 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(); }
|
SparseTranspose<Derived> transpose() { return derived(); }
|
||||||
const SparseTranspose<Derived> transpose() const { return derived(); }
|
const SparseTranspose<Derived> transpose() const { return derived(); }
|
||||||
// void transposeInPlace();
|
// void transposeInPlace();
|
||||||
const AdjointReturnType adjoint() const { return conjugate()/*.nestByValue()*/; }
|
const AdjointReturnType adjoint() const { return transpose().nestByValue(); }
|
||||||
|
|
||||||
// sub-vector
|
// sub-vector
|
||||||
SparseInnerVectorSet<Derived,1> row(int i);
|
SparseInnerVectorSet<Derived,1> row(int i);
|
||||||
@ -520,7 +522,7 @@ template<typename Derived> class SparseMatrixBase
|
|||||||
*/
|
*/
|
||||||
// inline int stride(void) const { return derived().stride(); }
|
// inline int stride(void) const { return derived().stride(); }
|
||||||
|
|
||||||
// inline const NestByValue<Derived> nestByValue() const;
|
inline const SparseNestByValue<Derived> nestByValue() const;
|
||||||
|
|
||||||
|
|
||||||
ConjugateReturnType conjugate() const;
|
ConjugateReturnType conjugate() const;
|
||||||
|
84
Eigen/src/Sparse/SparseNestByValue.h
Normal file
84
Eigen/src/Sparse/SparseNestByValue.h
Normal file
@ -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
|
@ -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 SparseVector;
|
||||||
template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix;
|
template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix;
|
||||||
|
|
||||||
|
template<typename MatrixType> class SparseNestByValue;
|
||||||
template<typename MatrixType> class SparseTranspose;
|
template<typename MatrixType> class SparseTranspose;
|
||||||
template<typename MatrixType, int Size> class SparseInnerVectorSet;
|
template<typename MatrixType, int Size> class SparseInnerVectorSet;
|
||||||
template<typename Derived> class SparseCwise;
|
template<typename Derived> class SparseCwise;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#ifndef EIGEN_TEST_FUNC
|
#ifndef EIGEN_TEST_FUNC
|
||||||
#error EIGEN_TEST_FUNC must be defined
|
#error EIGEN_TEST_FUNC must be defined
|
||||||
|
@ -299,6 +299,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
initSparse<Scalar>(density, refMat2, m2);
|
initSparse<Scalar>(density, refMat2, m2);
|
||||||
VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval());
|
VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval());
|
||||||
VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose());
|
VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose());
|
||||||
|
|
||||||
|
VERIFY_IS_APPROX(SparseMatrixType(m2.adjoint()), refMat2.adjoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
// test prune
|
// test prune
|
||||||
|
Loading…
x
Reference in New Issue
Block a user