From 4336cf3833d87bc1c8b4c9ef6f884547c80e31f0 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 22 Dec 2008 19:17:44 +0000 Subject: * add unit-tests to check allowed and forbiddent mixing of different scalar types * fix issues in Product revealed by this test * in Dot.h forbid mixing of different types (at least for now, might allow real.dot(complex) in the future). --- Eigen/src/Core/Assign.h | 2 ++ Eigen/src/Core/Dot.h | 3 +++ Eigen/src/Core/Product.h | 45 +++++++++++++++++++++++---------------------- 3 files changed, 28 insertions(+), 22 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 7e8102997..42b411e6f 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -437,6 +437,8 @@ template EIGEN_STRONG_INLINE Derived& MatrixBase ::operator=(const MatrixBase& other) { + EIGEN_STATIC_ASSERT((ei_is_same_type::ret), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) return ei_assign_selector::run(derived(), other.derived()); } diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 86bebe246..18e81ac1c 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -266,6 +266,9 @@ MatrixBase::dot(const MatrixBase& other) const EIGEN_STATIC_ASSERT_VECTOR_ONLY(_Nested) EIGEN_STATIC_ASSERT_VECTOR_ONLY(_OtherNested) EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(_Nested,_OtherNested) + EIGEN_STATIC_ASSERT((ei_is_same_type::ret), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + ei_assert(size() == other.size()); return ei_dot_impl<_Nested, _OtherNested>::run(derived(), other.derived()); diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 7df7ac67b..6587ad3e0 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -30,7 +30,7 @@ *** Forward declarations *** ***************************/ -template +template struct ei_product_coeff_impl; template @@ -94,6 +94,7 @@ template struct ei_product_mode || Rhs::MaxColsAtCompileTime >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ) && (!(Rhs::IsVectorAtCompileTime && (Lhs::Flags&RowMajorBit) && (!(Lhs::Flags&DirectAccessBit)))) && (!(Lhs::IsVectorAtCompileTime && (!(Rhs::Flags&RowMajorBit)) && (!(Rhs::Flags&DirectAccessBit)))) + && (ei_is_same_type::ret) ? CacheFriendlyProduct : NormalProduct }; }; @@ -120,7 +121,7 @@ struct ei_traits > // clean the nested types: typedef typename ei_cleantype::type _LhsNested; typedef typename ei_cleantype::type _RhsNested; - typedef typename _LhsNested::Scalar Scalar; + typedef typename ei_scalar_product_traits::ReturnType Scalar; enum { LhsCoeffReadCost = _LhsNested::CoeffReadCost, @@ -189,7 +190,7 @@ template class Product typedef ei_product_coeff_impl ScalarCoeffImpl; + _LhsNested, _RhsNested, Scalar> ScalarCoeffImpl; public: @@ -312,29 +313,29 @@ MatrixBase::operator*=(const MatrixBase &other) *** Scalar path - no vectorization *** **************************************/ -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { - EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) + EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, RetScalar &res) { - ei_product_coeff_impl::run(row, col, lhs, rhs, res); + ei_product_coeff_impl::run(row, col, lhs, rhs, res); res += lhs.coeff(row, Index) * rhs.coeff(Index, col); } }; -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { - EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) + EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, RetScalar &res) { res = lhs.coeff(row, 0) * rhs.coeff(0, col); } }; -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { - EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar& res) + EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, RetScalar& res) { ei_assert(lhs.cols()>0 && "you are using a non initialized matrix"); res = lhs.coeff(row, 0) * rhs.coeff(0, col); @@ -344,10 +345,10 @@ struct ei_product_coeff_impl }; // prevent buggy user code from causing an infinite recursion -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { - EIGEN_STRONG_INLINE static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {} + EIGEN_STRONG_INLINE static void run(int, int, const Lhs&, const Rhs&, RetScalar&) {} }; /******************************************* @@ -374,16 +375,16 @@ struct ei_product_coeff_vectorized_unroller<0, Lhs, Rhs, PacketScalar> } }; -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { typedef typename Lhs::PacketScalar PacketScalar; enum { PacketSize = ei_packet_traits::size }; - EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) + EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, RetScalar &res) { PacketScalar pres; ei_product_coeff_vectorized_unroller::run(row, col, lhs, rhs, pres); - ei_product_coeff_impl::run(row, col, lhs, rhs, res); + ei_product_coeff_impl::run(row, col, lhs, rhs, res); res = ei_predux(pres); } }; @@ -438,8 +439,8 @@ struct ei_product_coeff_vectorized_dyn_selector } }; -template -struct ei_product_coeff_impl +template +struct ei_product_coeff_impl { EIGEN_STRONG_INLINE static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) { -- cgit v1.2.3