aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-10-25 11:52:13 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-10-25 11:52:13 +0000
commit568a7e8eba0cac0555c286aa44a594c109b73276 (patch)
tree5dacae316af1316e7abb6e26f9acb22c7d036ec0 /Eigen
parent72f2c7eed5b7ca85c95ead287b92509229e32e89 (diff)
improve assertion checking in product
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Core/Product.h19
-rw-r--r--Eigen/src/Core/util/StaticAssert.h18
2 files changed, 30 insertions, 7 deletions
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h
index de356c6db..e370cd4fb 100644
--- a/Eigen/src/Core/Product.h
+++ b/Eigen/src/Core/Product.h
@@ -194,7 +194,9 @@ template<typename LhsNested, typename RhsNested, int ProductMode> class Product
inline Product(const Lhs& lhs, const Rhs& rhs)
: m_lhs(lhs), m_rhs(rhs)
{
- ei_assert(lhs.cols() == rhs.rows());
+ ei_assert(lhs.cols() == rhs.rows()
+ && "invalid matrix product"
+ && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
}
/** \internal
@@ -265,6 +267,21 @@ template<typename OtherDerived>
inline const typename ProductReturnType<Derived,OtherDerived>::Type
MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
{
+ enum {
+ ProductIsValid = Derived::ColsAtCompileTime==Dynamic
+ || OtherDerived::RowsAtCompileTime==Dynamic
+ || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
+ AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
+ SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived,OtherDerived)
+ };
+ // note to the lost user:
+ // * 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);
+ 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);
return typename ProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
}
diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h
index ad46bde46..fbaf676de 100644
--- a/Eigen/src/Core/util/StaticAssert.h
+++ b/Eigen/src/Core/util/StaticAssert.h
@@ -66,7 +66,10 @@
scalar_type_must_be_floating_point,
default_writting_to_selfadjoint_not_supported,
writting_to_triangular_part_with_unit_diag_is_not_supported,
- this_method_is_only_for_fixed_size
+ this_method_is_only_for_fixed_size,
+ invalid_matrix_product,
+ invalid_vector_vector_product__if_you_wanted_a_dot_or_coeff_wise_product_you_must_use_the_explicit_functions,
+ invalid_matrix_product__if_you_wanted_a_coeff_wise_product_you_must_use_the_explicit_function
};
};
@@ -110,15 +113,18 @@
|| int(TYPE0::SizeAtCompileTime)==int(TYPE1::SizeAtCompileTime)),\
you_mixed_vectors_of_different_sizes)
-// static assertion failing if the two matrix expression types are not compatible (same fixed-size or dynamic size)
-#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
- EIGEN_STATIC_ASSERT( \
- ((int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
+#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
+ ((int(TYPE0::RowsAtCompileTime)==Eigen::Dynamic \
|| int(TYPE1::RowsAtCompileTime)==Eigen::Dynamic \
|| int(TYPE0::RowsAtCompileTime)==int(TYPE1::RowsAtCompileTime)) \
&& (int(TYPE0::ColsAtCompileTime)==Eigen::Dynamic \
|| int(TYPE1::ColsAtCompileTime)==Eigen::Dynamic \
- || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime))),\
+ || int(TYPE0::ColsAtCompileTime)==int(TYPE1::ColsAtCompileTime)))
+
+// static assertion failing if the two matrix expression types are not compatible (same fixed-size or dynamic size)
+#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0,TYPE1) \
+ EIGEN_STATIC_ASSERT( \
+ EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0,TYPE1),\
you_mixed_matrices_of_different_sizes)
#endif // EIGEN_STATIC_ASSERT_H