aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Product.h
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-12-03 21:01:55 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-12-03 21:01:55 +0000
commitc1e2156d8a45e28a07474c483af7580e055feb70 (patch)
tree9898a7e039393908fd99b68f13d433ec02567794 /Eigen/src/Core/Product.h
parent84cc69f0f3fb0e232435d2318006500f47277e4d (diff)
* Much better, consistent error msgs when mixing different scalar types:
- in matrix-matrix product, static assert on the two scalar types to be the same. - Similarly in CwiseBinaryOp. POTENTIALLY CONTROVERSIAL: we don't allow anymore binary ops to take two different scalar types. The functors that we defined take two args of the same type anyway; also we still allow the return type to be different. Again the reason is that different scalar types are incompatible with vectorization. Better have the user realize explicitly what mixing different numeric types costs him in terms of performance. See comment in CwiseBinaryOp constructor. - This allowed to fix a little mistake in test/regression.cpp, mixing float and double - Remove redundant semicolon (;) after static asserts
Diffstat (limited to 'Eigen/src/Core/Product.h')
-rw-r--r--Eigen/src/Core/Product.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h
index ea9d739fa..c5b06c450 100644
--- a/Eigen/src/Core/Product.h
+++ b/Eigen/src/Core/Product.h
@@ -116,8 +116,8 @@ template<typename LhsNested, typename RhsNested, int ProductMode>
struct ei_traits<Product<LhsNested, RhsNested, ProductMode> >
{
// clean the nested types:
- typedef typename ei_unconst<typename ei_unref<LhsNested>::type>::type _LhsNested;
- typedef typename ei_unconst<typename ei_unref<RhsNested>::type>::type _RhsNested;
+ typedef typename ei_cleantype<LhsNested>::type _LhsNested;
+ typedef typename ei_cleantype<RhsNested>::type _RhsNested;
typedef typename _LhsNested::Scalar Scalar;
enum {
@@ -194,6 +194,10 @@ template<typename LhsNested, typename RhsNested, int ProductMode> class Product
inline Product(const Lhs& lhs, const Rhs& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
+ // we don't allow taking products of matrices of different real types, as that wouldn't be vectorizable.
+ // We still allow to mix T and complex<T>.
+ EIGEN_STATIC_ASSERT((ei_is_same_type<typename Lhs::RealScalar, typename Rhs::RealScalar>::ret),
+ you_mixed_different_numeric_types__you_need_to_use_the_cast_method_of_MatrixBase_to_cast_numeric_types_explicitly)
ei_assert(lhs.cols() == rhs.rows()
&& "invalid matrix product"
&& "if you wanted a coeff-wise or a dot product use the respective explicit functions");
@@ -278,10 +282,10 @@ MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
// * for a dot product use: v1.dot(v2)
// * for a coeff-wise product use: v1.cwise()*v2
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
- invalid_vector_vector_product__if_you_wanted_a_dot_or_coeff_wise_product_you_must_use_the_explicit_functions);
+ invalid_vector_vector_product__if_you_wanted_a_dot_or_coeff_wise_product_you_must_use_the_explicit_functions)
EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
- invalid_matrix_product__if_you_wanted_a_coeff_wise_product_you_must_use_the_explicit_function);
- EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, invalid_matrix_product);
+ invalid_matrix_product__if_you_wanted_a_coeff_wise_product_you_must_use_the_explicit_function)
+ EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, invalid_matrix_product)
return typename ProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
}