Support Product::coeff(0,0) even for dynamic matrices

This commit is contained in:
Gael Guennebaud 2014-02-18 13:32:30 +01:00
parent 8cfb138e73
commit 7002aa858f
2 changed files with 23 additions and 25 deletions

View File

@ -109,16 +109,6 @@ public:
{ {
return typename internal::evaluator<ProductXpr>::type(derived()).coeff(0,0); return typename internal::evaluator<ProductXpr>::type(derived()).coeff(0,0);
} }
Scalar coeff(Index row, Index col) const
{
return typename internal::evaluator<ProductXpr>::type(derived()).coeff(row,col);
}
Scalar coeff(Index i) const
{
return typename internal::evaluator<ProductXpr>::type(derived()).coeff(i);
}
}; };
} // namespace internal } // namespace internal
@ -132,6 +122,22 @@ class ProductImpl<Lhs,Rhs,Option,Dense>
typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base; typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
EIGEN_DENSE_PUBLIC_INTERFACE(Derived) EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Scalar coeff(Index row, Index col) const
{
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
eigen_assert(this->rows() == 1 && this->cols() == 1);
return typename internal::evaluator<Derived>::type(derived()).coeff(row,col);
}
Scalar coeff(Index i) const
{
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
eigen_assert(this->rows() == 1 && this->cols() == 1);
return typename internal::evaluator<Derived>::type(derived()).coeff(i);
}
}; };
/*************************************************************************** /***************************************************************************

View File

@ -270,7 +270,7 @@ struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct>
template<typename Dest> template<typename Dest>
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
{ {TRACK;
// TODO bypass GeneralProduct class // TODO bypass GeneralProduct class
GeneralProduct<Lhs, Rhs, GemmProduct>(lhs,rhs).scaleAndAddTo(dst, alpha); GeneralProduct<Lhs, Rhs, GemmProduct>(lhs,rhs).scaleAndAddTo(dst, alpha);
} }
@ -705,7 +705,7 @@ struct generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag>
template<typename Dest> template<typename Dest>
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
{// SelfadjointProductMatrix<MatrixType,Mode,false,OtherDerived,0,OtherDerived::IsVectorAtCompileTime> {
// TODO bypass SelfadjointProductMatrix class // TODO bypass SelfadjointProductMatrix class
SelfadjointProductMatrix<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>(lhs.nestedExpression(),rhs).scaleAndAddTo(dst, alpha); SelfadjointProductMatrix<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>(lhs.nestedExpression(),rhs).scaleAndAddTo(dst, alpha);
} }
@ -739,7 +739,7 @@ struct generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag>
template<typename Dest> template<typename Dest>
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
{//SelfadjointProductMatrix<OtherDerived,0,OtherDerived::IsVectorAtCompileTime,MatrixType,Mode,false> {
// TODO bypass SelfadjointProductMatrix class // TODO bypass SelfadjointProductMatrix class
SelfadjointProductMatrix<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>(lhs,rhs.nestedExpression()).scaleAndAddTo(dst, alpha); SelfadjointProductMatrix<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>(lhs,rhs.nestedExpression()).scaleAndAddTo(dst, alpha);
} }
@ -826,6 +826,8 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalSha
typedef Product<Lhs, Rhs, ProductKind> XprType; typedef Product<Lhs, Rhs, ProductKind> XprType;
typedef typename XprType::PlainObject PlainObject; typedef typename XprType::PlainObject PlainObject;
enum { StorageOrder = int(Rhs::Flags) & RowMajorBit ? RowMajor : ColMajor };
product_evaluator(const XprType& xpr) product_evaluator(const XprType& xpr)
: Base(xpr.rhs(), xpr.lhs().diagonal()) : Base(xpr.rhs(), xpr.lhs().diagonal())
{ {
@ -839,9 +841,6 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalSha
template<int LoadMode> template<int LoadMode>
EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
{ {
enum {
StorageOrder = Rhs::Flags & RowMajorBit ? RowMajor : ColMajor
};
return this->template packet_impl<LoadMode>(row,col, row, return this->template packet_impl<LoadMode>(row,col, row,
typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type()); typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type());
} }
@ -849,9 +848,6 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalSha
template<int LoadMode> template<int LoadMode>
EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const
{ {
enum {
StorageOrder = int(Rhs::Flags) & RowMajorBit ? RowMajor : ColMajor
};
return packet<LoadMode>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); return packet<LoadMode>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
} }
@ -874,6 +870,8 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape,
typedef Product<Lhs, Rhs, ProductKind> XprType; typedef Product<Lhs, Rhs, ProductKind> XprType;
typedef typename XprType::PlainObject PlainObject; typedef typename XprType::PlainObject PlainObject;
enum { StorageOrder = int(Rhs::Flags) & RowMajorBit ? RowMajor : ColMajor };
product_evaluator(const XprType& xpr) product_evaluator(const XprType& xpr)
: Base(xpr.lhs(), xpr.rhs().diagonal()) : Base(xpr.lhs(), xpr.rhs().diagonal())
{ {
@ -887,9 +885,6 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape,
template<int LoadMode> template<int LoadMode>
EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
{ {
enum {
StorageOrder = Rhs::Flags & RowMajorBit ? RowMajor : ColMajor
};
return this->template packet_impl<LoadMode>(row,col, col, return this->template packet_impl<LoadMode>(row,col, col,
typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type()); typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type());
} }
@ -897,9 +892,6 @@ struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape,
template<int LoadMode> template<int LoadMode>
EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const
{ {
enum {
StorageOrder = int(Rhs::Flags) & RowMajorBit ? RowMajor : ColMajor
};
return packet<LoadMode>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); return packet<LoadMode>(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx);
} }