Even more NestByValue cleanup...

This commit is contained in:
Hauke Heibel 2009-12-01 13:16:51 +01:00
parent 2bf354da80
commit b08d5b2d2c
15 changed files with 30 additions and 147 deletions

View File

@ -84,7 +84,6 @@ 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"

View File

@ -37,12 +37,6 @@ template<typename XprType> struct ei_shape_of
// matrix. Unless we change the overall design, here is a workaround.
// There is an example in unsuported/Eigen/src/AutoDiff/AutoDiffScalar.
template<typename XprType, int Shape = ei_shape_of<XprType>::ret>
struct MakeNestByValue
{
typedef NestByValue<XprType> Type;
};
template<typename Func, typename XprType, int Shape = ei_shape_of<XprType>::ret>
struct MakeCwiseUnaryOp
{

View File

@ -214,20 +214,6 @@ struct ei_blas_traits<CwiseUnaryOp<ei_scalar_opposite_op<Scalar>, NestedXpr> >
{ return - Base::extractScalarFactor(x._expression()); }
};
// pop NestByValue
template<typename NestedXpr>
struct ei_blas_traits<NestByValue<NestedXpr> >
: ei_blas_traits<NestedXpr>
{
typedef typename NestedXpr::Scalar Scalar;
typedef ei_blas_traits<NestedXpr> Base;
typedef NestByValue<NestedXpr> XprType;
typedef typename Base::ExtractType ExtractType;
static inline ExtractType extract(const XprType& x) { return Base::extract(static_cast<const NestedXpr&>(x)); }
static inline Scalar extractScalarFactor(const XprType& x)
{ return Base::extractScalarFactor(static_cast<const NestedXpr&>(x)); }
};
// pop/push transpose
template<typename NestedXpr>
struct ei_blas_traits<Transpose<NestedXpr> >

View File

@ -356,7 +356,7 @@ template<typename _MatrixType> class FullPivLU
ei_assert(m_isInitialized && "LU is not initialized.");
ei_assert(m_lu.rows() == m_lu.cols() && "You can't take the inverse of a non-square matrix!");
return ei_solve_retval<FullPivLU,typename MatrixType::IdentityReturnType>
(*this, MatrixType::Identity(m_lu.rows(), m_lu.cols()).nestByValue());
(*this, MatrixType::Identity(m_lu.rows(), m_lu.cols()));
}
inline int rows() const { return m_lu.rows(); }

View File

@ -147,7 +147,7 @@ template<typename _MatrixType> class PartialPivLU
{
ei_assert(m_isInitialized && "PartialPivLU is not initialized.");
return ei_solve_retval<PartialPivLU,typename MatrixType::IdentityReturnType>
(*this, MatrixType::Identity(m_lu.rows(), m_lu.cols()).nestByValue());
(*this, MatrixType::Identity(m_lu.rows(), m_lu.cols()));
}
/** \returns the determinant of the matrix of which

View File

@ -219,7 +219,7 @@ template<typename _MatrixType> class ColPivHouseholderQR
{
ei_assert(m_isInitialized && "ColPivHouseholderQR is not initialized.");
return ei_solve_retval<ColPivHouseholderQR,typename MatrixType::IdentityReturnType>
(*this, MatrixType::Identity(m_qr.rows(), m_qr.cols()).nestByValue());
(*this, MatrixType::Identity(m_qr.rows(), m_qr.cols()));
}
inline int rows() const { return m_qr.rows(); }

View File

@ -221,7 +221,7 @@ template<typename _MatrixType> class FullPivHouseholderQR
{
ei_assert(m_isInitialized && "FullPivHouseholderQR is not initialized.");
return ei_solve_retval<FullPivHouseholderQR,typename MatrixType::IdentityReturnType>
(*this, MatrixType::Identity(m_qr.rows(), m_qr.cols()).nestByValue());
(*this, MatrixType::Identity(m_qr.rows(), m_qr.cols()));
}
inline int rows() const { return m_qr.rows(); }

View File

@ -154,16 +154,16 @@ class ei_sparse_diagonal_product_inner_iterator_selector
: public SparseCwiseBinaryOp<
ei_scalar_product_op<typename Rhs::Scalar>,
SparseInnerVectorSet<Lhs,1>,
NestByValue<Transpose<typename Rhs::DiagonalVectorType> > >::InnerIterator
Transpose<typename Rhs::DiagonalVectorType> >::InnerIterator
{
typedef typename SparseCwiseBinaryOp<
ei_scalar_product_op<typename Rhs::Scalar>,
SparseInnerVectorSet<Lhs,1>,
NestByValue<Transpose<typename Rhs::DiagonalVectorType> > >::InnerIterator Base;
Transpose<typename Rhs::DiagonalVectorType> >::InnerIterator Base;
public:
inline ei_sparse_diagonal_product_inner_iterator_selector(
const SparseDiagonalProductType& expr, int outer)
: Base(expr.lhs().innerVector(outer) .cwise()* expr.rhs().diagonal().transpose().nestByValue(), 0)
: Base(expr.lhs().innerVector(outer) .cwise()* expr.rhs().diagonal().transpose(), 0)
{}
};

View File

@ -25,12 +25,6 @@
#ifndef EIGEN_SPARSE_EXPRESSIONMAKER_H
#define EIGEN_SPARSE_EXPRESSIONMAKER_H
template<typename XprType>
struct MakeNestByValue<XprType,IsSparse>
{
typedef SparseNestByValue<XprType> Type;
};
template<typename Func, typename XprType>
struct MakeCwiseUnaryOp<Func,XprType,IsSparse>
{

View File

@ -100,7 +100,7 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
typedef SparseCwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
/** \internal the return type of MatrixBase::adjoint() */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, SparseNestByValue<Eigen::SparseTranspose<Derived> > >,
SparseCwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Eigen::SparseTranspose<Derived> >,
SparseTranspose<Derived>
>::ret AdjointReturnType;
@ -356,7 +356,7 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
SparseTranspose<Derived> transpose() { return derived(); }
const SparseTranspose<Derived> transpose() const { return derived(); }
// void transposeInPlace();
const AdjointReturnType adjoint() const { return transpose().nestByValue(); }
const AdjointReturnType adjoint() const { return transpose(); }
// sub-vector
SparseInnerVectorSet<Derived,1> row(int i);
@ -528,9 +528,6 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
*/
// inline int stride(void) const { return derived().stride(); }
inline const SparseNestByValue<Derived> nestByValue() const;
ConjugateReturnType conjugate() const;
const RealReturnType real() const;
const ImagReturnType imag() const;
@ -583,11 +580,11 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
const MatrixBase<ElseDerived>& elseMatrix) const;
template<typename ThenDerived>
inline const Select<Derived,ThenDerived, NestByValue<typename ThenDerived::ConstantReturnType> >
inline const Select<Derived,ThenDerived, typename ThenDerived::ConstantReturnType>
select(const MatrixBase<ThenDerived>& thenMatrix, typename ThenDerived::Scalar elseScalar) const;
template<typename ElseDerived>
inline const Select<Derived, NestByValue<typename ElseDerived::ConstantReturnType>, ElseDerived >
inline const Select<Derived, typename ElseDerived::ConstantReturnType, ElseDerived >
select(typename ElseDerived::Scalar thenScalar, const MatrixBase<ElseDerived>& elseMatrix) const;
template<int p> RealScalar lpNorm() const;

View File

@ -1,84 +0,0 @@
// 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<SparseNestByValue<ExpressionType> >
{
public:
typedef typename ExpressionType::InnerIterator 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

View File

@ -106,7 +106,6 @@ 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;
@ -147,6 +146,4 @@ template<typename T> class ei_eval<T,IsSparse>
typedef SparseMatrix<_Scalar, _Flags> type;
};
template<typename T> struct ei_must_nest_by_value<SparseNestByValue<T> > { enum { ret = true }; };
#endif // EIGEN_SPARSEUTIL_H

View File

@ -79,14 +79,14 @@ template<typename T>
Block<Map<Matrix<T,Dynamic,Dynamic> >, Dynamic, Dynamic>
matrix(T* data, int rows, int cols, int stride)
{
return Map<Matrix<T,Dynamic,Dynamic> >(data, stride, cols).nestByValue().block(0,0,rows,cols);
return Map<Matrix<T,Dynamic,Dynamic> >(data, stride, cols).block(0,0,rows,cols);
}
template<typename T>
Block<Map<Matrix<T,Dynamic,Dynamic,RowMajor> >, Dynamic, 1>
vector(T* data, int size, int incr)
{
return Map<Matrix<T,Dynamic,Dynamic,RowMajor> >(data, size, incr).nestByValue().col(0);
return Map<Matrix<T,Dynamic,Dynamic,RowMajor> >(data, size, incr).col(0);
}
template<typename T>

View File

@ -212,33 +212,33 @@ class AutoDiffScalar
template<typename OtherDerType>
inline const AutoDiffScalar<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseBinaryOp<ei_scalar_difference_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type>::Type,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >::Type >::Type >
typename MakeCwiseBinaryOp<ei_scalar_difference_op<Scalar>,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >
operator/(const AutoDiffScalar<OtherDerType>& other) const
{
ei_make_coherent(m_derivatives, other.derivatives());
return AutoDiffScalar<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseBinaryOp<ei_scalar_difference_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type>::Type,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >::Type >::Type >(
typename MakeCwiseBinaryOp<ei_scalar_difference_op<Scalar>,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >(
m_value / other.value(),
((m_derivatives * other.value()).nestByValue() - (m_value * other.derivatives()).nestByValue()).nestByValue()
((m_derivatives * other.value()) - (m_value * other.derivatives()))
* (Scalar(1)/(other.value()*other.value())));
}
template<typename OtherDerType>
inline const AutoDiffScalar<typename MakeCwiseBinaryOp<ei_scalar_sum_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type>::Type,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >
operator*(const AutoDiffScalar<OtherDerType>& other) const
{
ei_make_coherent(m_derivatives, other.derivatives());
return AutoDiffScalar<typename MakeCwiseBinaryOp<ei_scalar_sum_op<Scalar>,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type>::Type,
typename MakeNestByValue<typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >::Type >(
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, DerType>::Type,
typename MakeCwiseUnaryOp<ei_scalar_multiple_op<Scalar>, typename ei_cleantype<OtherDerType>::type>::Type>::Type >(
m_value * other.value(),
(m_derivatives * other.value()).nestByValue() + (m_value * other.derivatives()).nestByValue());
(m_derivatives * other.value()) + (m_value * other.derivatives()));
}
inline AutoDiffScalar& operator*=(const Scalar& other)

View File

@ -196,17 +196,17 @@ class AutoDiffVector
// inline const AutoDiffVector<
// CwiseBinaryOp<ei_scalar_multiple_op<Scalar>, ValueType, OtherValueType>
// CwiseBinaryOp<ei_scalar_sum_op<Scalar>,
// NestByValue<CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, JacobianType> >,
// NestByValue<CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, OtherJacobianType> > > >
// CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, JacobianType>,
// CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, OtherJacobianType> > >
// operator*(const AutoDiffVector<OtherValueType,OtherJacobianType>& other) const
// {
// return AutoDiffVector<
// CwiseBinaryOp<ei_scalar_multiple_op<Scalar>, ValueType, OtherValueType>
// CwiseBinaryOp<ei_scalar_sum_op<Scalar>,
// NestByValue<CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, JacobianType> >,
// NestByValue<CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, OtherJacobianType> > > >(
// CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, JacobianType>,
// CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, OtherJacobianType> > >(
// m_values.cwise() * other.values(),
// (m_jacobian * other.values()).nestByValue() + (m_values * other.jacobian()).nestByValue());
// (m_jacobian * other.values()) + (m_values * other.jacobian()));
// }
inline AutoDiffVector& operator*=(const Scalar& other)