aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Product.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2013-12-04 22:58:19 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2013-12-04 22:58:19 +0100
commit8d8acc3ab4f0b3f45f2a8bc25c0b7f5f66a22024 (patch)
tree5e7e2fa19e21075efa8ce3e2a7da4a53053b35bb /Eigen/src/Core/Product.h
parent6c5e915e9a6c79550e7e2db2b53648f163a1411d (diff)
Move inner product special functions to a base class to avoid ambiguous calls
Diffstat (limited to 'Eigen/src/Core/Product.h')
-rw-r--r--Eigen/src/Core/Product.h50
1 files changed, 41 insertions, 9 deletions
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h
index b37fd2ff7..79d09fbb6 100644
--- a/Eigen/src/Core/Product.h
+++ b/Eigen/src/Core/Product.h
@@ -79,12 +79,6 @@ class Product : public ProductImpl<_Lhs,_Rhs,Option,
const LhsNestedCleaned& lhs() const { return m_lhs; }
const RhsNestedCleaned& rhs() const { return m_rhs; }
-
- /** Convertion to scalar for inner-products */
- operator const Scalar() const {
- EIGEN_STATIC_ASSERT(SizeAtCompileTime==1, IMPLICIT_CONVERSION_TO_SCALAR_IS_FOR_INNER_PRODUCT_ONLY);
- return typename internal::evaluator<Product>::type(*this).coeff(0,0);
- }
protected:
@@ -92,13 +86,51 @@ class Product : public ProductImpl<_Lhs,_Rhs,Option,
RhsNested m_rhs;
};
+namespace internal {
+
+template<typename Lhs, typename Rhs, int Option, int ProductTab = internal::product_tag<Lhs,Rhs>::ret>
+class dense_product_base
+ : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
+{};
+
+/** Convertion to scalar for inner-products */
template<typename Lhs, typename Rhs, int Option>
-class ProductImpl<Lhs,Rhs,Option,Dense> : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
+class dense_product_base<Lhs, Rhs, Option, InnerProduct>
+ : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
+{
+ typedef Product<Lhs,Rhs,Option> ProductXpr;
+ typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
+public:
+ using Base::derived;
+ typedef typename Base::Scalar Scalar;
+ typedef typename Base::Index Index;
+
+ operator const Scalar() const
+ {
+ 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
+
+template<typename Lhs, typename Rhs, int Option>
+class ProductImpl<Lhs,Rhs,Option,Dense>
+ : public internal::dense_product_base<Lhs,Rhs,Option>
{
typedef Product<Lhs, Rhs> Derived;
public:
-
- typedef typename internal::dense_xpr_base<Product<Lhs, Rhs, Option> >::type Base;
+
+ typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
};