From 6f2c72fb537c18e5b3a2ddc1f1ba2ff2f4a38785 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 25 Apr 2008 23:10:37 +0000 Subject: [PATCH] Various fixes in: - vector to vector assign - PartialRedux - Vectorization criteria of Product - returned type of normalized - SSE integer mul --- Eigen/src/Core/Assign.h | 3 ++- Eigen/src/Core/CMakeLists.txt | 4 ++-- Eigen/src/Core/CwiseNullaryOp.h | 22 +++++++++++----------- Eigen/src/Core/Dot.h | 2 +- Eigen/src/Core/MatrixBase.h | 18 +++++++++--------- Eigen/src/Core/PacketMath.h | 8 ++++++-- Eigen/src/Core/Product.h | 6 ++++-- Eigen/src/Core/Redux.h | 8 ++++---- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index c9e2b6b4b..1590fef81 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -123,7 +123,8 @@ Derived& MatrixBase { const bool need_to_transpose = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime - && (int)Derived::RowsAtCompileTime != (int)OtherDerived::RowsAtCompileTime; + && (int)Derived::RowsAtCompileTime != (int)OtherDerived::RowsAtCompileTime + && (int)Derived::ColsAtCompileTime != (int)OtherDerived::ColsAtCompileTime; if(OtherDerived::Flags & EvalBeforeAssigningBit) { if(need_to_transpose) diff --git a/Eigen/src/Core/CMakeLists.txt b/Eigen/src/Core/CMakeLists.txt index a59a0fd67..9af605dd4 100644 --- a/Eigen/src/Core/CMakeLists.txt +++ b/Eigen/src/Core/CMakeLists.txt @@ -1,8 +1,8 @@ FILE(GLOB Eigen_Core_SRCS "*.h") -INSTALL(FILES +INSTALL(FILES ${Eigen_Core_SRCS} DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Core ) -ADD_SUBDIRECTORY(util) +ADD_SUBDIRECTORY(util) \ No newline at end of file diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 4f09bd8a9..6a0b6bc0c 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -110,7 +110,7 @@ class CwiseNullaryOp : ei_no_assignment_operator, template template const CwiseNullaryOp -MatrixBase::cwiseCreate(int rows, int cols, const CustomNullaryOp& func) +MatrixBase::create(int rows, int cols, const CustomNullaryOp& func) { return CwiseNullaryOp(rows, cols, func); } @@ -133,7 +133,7 @@ MatrixBase::cwiseCreate(int rows, int cols, const CustomNullaryOp& func template template const CwiseNullaryOp -MatrixBase::cwiseCreate(int size, const CustomNullaryOp& func) +MatrixBase::create(int size, const CustomNullaryOp& func) { ei_assert(IsVectorAtCompileTime); if(RowsAtCompileTime == 1) return CwiseNullaryOp(1, size, func); @@ -152,7 +152,7 @@ MatrixBase::cwiseCreate(int size, const CustomNullaryOp& func) template template const CwiseNullaryOp -MatrixBase::cwiseCreate(const CustomNullaryOp& func) +MatrixBase::create(const CustomNullaryOp& func) { return CwiseNullaryOp(rows(), cols(), func); } @@ -174,7 +174,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::constant(int rows, int cols, const Scalar& value) { - return cwiseCreate(rows, cols, ei_scalar_constant_op(value)); + return create(rows, cols, ei_scalar_constant_op(value)); } /** \returns an expression of a constant matrix of value \a value @@ -196,7 +196,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::constant(int size, const Scalar& value) { - return cwiseCreate(size, ei_scalar_constant_op(value)); + return create(size, ei_scalar_constant_op(value)); } /** \returns an expression of a constant matrix of value \a value @@ -212,7 +212,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::constant(const Scalar& value) { - return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op(value)); + return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op(value)); } template @@ -442,7 +442,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::random(int rows, int cols) { - return cwiseCreate(rows, cols, ei_scalar_random_op()); + return create(rows, cols, ei_scalar_random_op()); } /** \returns a random vector (not an expression, the vector is immediately evaluated). @@ -465,7 +465,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::random(int size) { - return cwiseCreate(size, ei_scalar_random_op()); + return create(size, ei_scalar_random_op()); } /** \returns a fixed-size random matrix or vector @@ -483,7 +483,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::random() { - return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op()); + return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op()); } /** Sets all coefficients in this expression to random values. @@ -519,7 +519,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::identity(int rows, int cols) { - return cwiseCreate(rows, cols, ei_scalar_identity_op()); + return create(rows, cols, ei_scalar_identity_op()); } /** \returns an expression of the identity matrix (not necessarily square). @@ -536,7 +536,7 @@ template const CwiseNullaryOp::Scalar>, Derived> MatrixBase::identity() { - return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_identity_op()); + return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_identity_op()); } /** \returns true if *this is approximately equal to the identity matrix diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index ae42bfa1b..c1c607639 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -135,7 +135,7 @@ template const CwiseUnaryOp::Scalar>, Derived> MatrixBase::normalized() const { - return (*this) / norm(); + return (*this) * (Scalar(1)/norm()); } /** \returns true if *this is approximately orthogonal to \a other, diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index b6a161bdd..bed6b2f93 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -340,15 +340,15 @@ template class MatrixBase static const CwiseNullaryOp,Derived> constant(const Scalar& value); - template - static const CwiseNullaryOp - cwiseCreate(int rows, int cols, const CustomZeroaryOp& func); - template - static const CwiseNullaryOp - cwiseCreate(int size, const CustomZeroaryOp& func); - template - static const CwiseNullaryOp - cwiseCreate(const CustomZeroaryOp& func); + template + static const CwiseNullaryOp + create(int rows, int cols, const CustomNullaryOp& func); + template + static const CwiseNullaryOp + create(int size, const CustomNullaryOp& func); + template + static const CwiseNullaryOp + create(const CustomNullaryOp& func); static const CwiseNullaryOp,Derived> random(int rows, int cols); static const CwiseNullaryOp,Derived> random(int size); diff --git a/Eigen/src/Core/PacketMath.h b/Eigen/src/Core/PacketMath.h index 8956c27b0..0f3a132a9 100644 --- a/Eigen/src/Core/PacketMath.h +++ b/Eigen/src/Core/PacketMath.h @@ -59,9 +59,13 @@ inline __m128d ei_pmul(const __m128d& a, const __m128d& b) { return _mm_mul_pd(a inline __m128i ei_pmul(const __m128i& a, const __m128i& b) { return _mm_or_si128( - _mm_mul_epu32(a,b), + _mm_and_si128( + _mm_mul_epu32(a,b), + _mm_setr_epi32(0xffffffff,0,0xffffffff,0)), _mm_slli_si128( - _mm_mul_epu32(_mm_srli_si128(a,32),_mm_srli_si128(b,32)), 32)); + _mm_and_si128( + _mm_mul_epu32(_mm_srli_si128(a,4),_mm_srli_si128(b,4)), + _mm_setr_epi32(0xffffffff,0,0xffffffff,0)), 4)); } inline __m128 ei_pmin(const __m128& a, const __m128& b) { return _mm_min_ps(a,b); } diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 895e19e0e..b77fd3eae 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -138,12 +138,14 @@ struct ei_traits > ~(RowMajorBit | VectorizableBit | Like1DArrayBit) | ( ( - !(Lhs::Flags & RowMajorBit) && (Lhs::Flags & VectorizableBit) + (!(Lhs::Flags & RowMajorBit)) && (Lhs::Flags & VectorizableBit) + && (Lhs::RowsAtCompileTime % ei_packet_traits::size == 0) ) ? VectorizableBit : ( ( (Rhs::Flags & RowMajorBit) && (Rhs::Flags & VectorizableBit) + && (Lhs::ColsAtCompileTime % ei_packet_traits::size == 0) ) ? RowMajorBit | VectorizableBit : 0 @@ -282,7 +284,7 @@ Derived& MatrixBase::lazyAssign(const Product::size==0) ), ei_meta_true,ei_meta_false>::ret() #else - ei_meta_false + ei_meta_false() #endif ); return derived(); diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 6e740fc7d..c9332c847 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -53,7 +53,7 @@ struct ei_redux_unroller typedef typename ei_result_of::type Scalar; - static Scalar run(const Derived &mat, const BinaryOp &func) + static Scalar run(const Derived &mat, const BinaryOp &) { return mat.coeff(row, col); } @@ -96,7 +96,7 @@ struct ei_traits > MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, Flags = ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) ? (unsigned int)_MatrixTypeNested::Flags - : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & ~VectorizableBit, + : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & ~(VectorizableBit | Like1DArrayBit), TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost + (TraversalSize - 1) * ei_functor_traits::Cost @@ -124,9 +124,9 @@ class PartialRedux : ei_no_assignment_operator, const Scalar _coeff(int i, int j) const { if (Direction==Vertical) - return this->col(j).redux(m_functor); + return m_matrix.col(j).redux(m_functor); else - return this->row(i).redux(m_functor); + return m_matrix.row(i).redux(m_functor); } protected: