Various fixes in:

- vector to vector assign
 - PartialRedux
 - Vectorization criteria of Product
 - returned type of normalized
 - SSE integer mul
This commit is contained in:
Gael Guennebaud 2008-04-25 23:10:37 +00:00
parent a451835bce
commit 6f2c72fb53
8 changed files with 39 additions and 32 deletions

View File

@ -123,7 +123,8 @@ Derived& MatrixBase<Derived>
{ {
const bool need_to_transpose = Derived::IsVectorAtCompileTime const bool need_to_transpose = Derived::IsVectorAtCompileTime
&& OtherDerived::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(OtherDerived::Flags & EvalBeforeAssigningBit)
{ {
if(need_to_transpose) if(need_to_transpose)

View File

@ -1,8 +1,8 @@
FILE(GLOB Eigen_Core_SRCS "*.h") FILE(GLOB Eigen_Core_SRCS "*.h")
INSTALL(FILES INSTALL(FILES
${Eigen_Core_SRCS} ${Eigen_Core_SRCS}
DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Core DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Core
) )
ADD_SUBDIRECTORY(util) ADD_SUBDIRECTORY(util)

View File

@ -110,7 +110,7 @@ class CwiseNullaryOp : ei_no_assignment_operator,
template<typename Derived> template<typename Derived>
template<typename CustomNullaryOp> template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived> const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::cwiseCreate(int rows, int cols, const CustomNullaryOp& func) MatrixBase<Derived>::create(int rows, int cols, const CustomNullaryOp& func)
{ {
return CwiseNullaryOp<CustomNullaryOp, Derived>(rows, cols, func); return CwiseNullaryOp<CustomNullaryOp, Derived>(rows, cols, func);
} }
@ -133,7 +133,7 @@ MatrixBase<Derived>::cwiseCreate(int rows, int cols, const CustomNullaryOp& func
template<typename Derived> template<typename Derived>
template<typename CustomNullaryOp> template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived> const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::cwiseCreate(int size, const CustomNullaryOp& func) MatrixBase<Derived>::create(int size, const CustomNullaryOp& func)
{ {
ei_assert(IsVectorAtCompileTime); ei_assert(IsVectorAtCompileTime);
if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, Derived>(1, size, func); if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, Derived>(1, size, func);
@ -152,7 +152,7 @@ MatrixBase<Derived>::cwiseCreate(int size, const CustomNullaryOp& func)
template<typename Derived> template<typename Derived>
template<typename CustomNullaryOp> template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived> const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::cwiseCreate(const CustomNullaryOp& func) MatrixBase<Derived>::create(const CustomNullaryOp& func)
{ {
return CwiseNullaryOp<CustomNullaryOp, Derived>(rows(), cols(), func); return CwiseNullaryOp<CustomNullaryOp, Derived>(rows(), cols(), func);
} }
@ -174,7 +174,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::constant(int rows, int cols, const Scalar& value) MatrixBase<Derived>::constant(int rows, int cols, const Scalar& value)
{ {
return cwiseCreate(rows, cols, ei_scalar_constant_op<Scalar>(value)); return create(rows, cols, ei_scalar_constant_op<Scalar>(value));
} }
/** \returns an expression of a constant matrix of value \a value /** \returns an expression of a constant matrix of value \a value
@ -196,7 +196,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::constant(int size, const Scalar& value) MatrixBase<Derived>::constant(int size, const Scalar& value)
{ {
return cwiseCreate(size, ei_scalar_constant_op<Scalar>(value)); return create(size, ei_scalar_constant_op<Scalar>(value));
} }
/** \returns an expression of a constant matrix of value \a value /** \returns an expression of a constant matrix of value \a value
@ -212,7 +212,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::constant(const Scalar& value) MatrixBase<Derived>::constant(const Scalar& value)
{ {
return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op<Scalar>(value)); return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op<Scalar>(value));
} }
template<typename Derived> template<typename Derived>
@ -442,7 +442,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random(int rows, int cols) MatrixBase<Derived>::random(int rows, int cols)
{ {
return cwiseCreate(rows, cols, ei_scalar_random_op<Scalar>()); return create(rows, cols, ei_scalar_random_op<Scalar>());
} }
/** \returns a random vector (not an expression, the vector is immediately evaluated). /** \returns a random vector (not an expression, the vector is immediately evaluated).
@ -465,7 +465,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random(int size) MatrixBase<Derived>::random(int size)
{ {
return cwiseCreate(size, ei_scalar_random_op<Scalar>()); return create(size, ei_scalar_random_op<Scalar>());
} }
/** \returns a fixed-size random matrix or vector /** \returns a fixed-size random matrix or vector
@ -483,7 +483,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::random() MatrixBase<Derived>::random()
{ {
return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>()); return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>());
} }
/** Sets all coefficients in this expression to random values. /** Sets all coefficients in this expression to random values.
@ -519,7 +519,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::identity(int rows, int cols) MatrixBase<Derived>::identity(int rows, int cols)
{ {
return cwiseCreate(rows, cols, ei_scalar_identity_op<Scalar>()); return create(rows, cols, ei_scalar_identity_op<Scalar>());
} }
/** \returns an expression of the identity matrix (not necessarily square). /** \returns an expression of the identity matrix (not necessarily square).
@ -536,7 +536,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::identity() MatrixBase<Derived>::identity()
{ {
return cwiseCreate(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_identity_op<Scalar>()); return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_identity_op<Scalar>());
} }
/** \returns true if *this is approximately equal to the identity matrix /** \returns true if *this is approximately equal to the identity matrix

View File

@ -135,7 +135,7 @@ template<typename Derived>
const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::normalized() const MatrixBase<Derived>::normalized() const
{ {
return (*this) / norm(); return (*this) * (Scalar(1)/norm());
} }
/** \returns true if *this is approximately orthogonal to \a other, /** \returns true if *this is approximately orthogonal to \a other,

View File

@ -340,15 +340,15 @@ template<typename Derived> class MatrixBase
static const CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> static const CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived>
constant(const Scalar& value); constant(const Scalar& value);
template<typename CustomZeroaryOp> template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived> static const CwiseNullaryOp<CustomNullaryOp, Derived>
cwiseCreate(int rows, int cols, const CustomZeroaryOp& func); create(int rows, int cols, const CustomNullaryOp& func);
template<typename CustomZeroaryOp> template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived> static const CwiseNullaryOp<CustomNullaryOp, Derived>
cwiseCreate(int size, const CustomZeroaryOp& func); create(int size, const CustomNullaryOp& func);
template<typename CustomZeroaryOp> template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived> static const CwiseNullaryOp<CustomNullaryOp, Derived>
cwiseCreate(const CustomZeroaryOp& func); create(const CustomNullaryOp& func);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int rows, int cols); static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int rows, int cols);
static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int size); static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int size);

View File

@ -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) inline __m128i ei_pmul(const __m128i& a, const __m128i& b)
{ {
return _mm_or_si128( 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_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); } inline __m128 ei_pmin(const __m128& a, const __m128& b) { return _mm_min_ps(a,b); }

View File

@ -138,12 +138,14 @@ struct ei_traits<Product<Lhs, Rhs, EvalMode> >
~(RowMajorBit | VectorizableBit | Like1DArrayBit) ~(RowMajorBit | VectorizableBit | Like1DArrayBit)
| ( | (
( (
!(Lhs::Flags & RowMajorBit) && (Lhs::Flags & VectorizableBit) (!(Lhs::Flags & RowMajorBit)) && (Lhs::Flags & VectorizableBit)
&& (Lhs::RowsAtCompileTime % ei_packet_traits<Scalar>::size == 0)
) )
? VectorizableBit ? VectorizableBit
: ( : (
( (
(Rhs::Flags & RowMajorBit) && (Rhs::Flags & VectorizableBit) (Rhs::Flags & RowMajorBit) && (Rhs::Flags & VectorizableBit)
&& (Lhs::ColsAtCompileTime % ei_packet_traits<Scalar>::size == 0)
) )
? RowMajorBit | VectorizableBit ? RowMajorBit | VectorizableBit
: 0 : 0
@ -282,7 +284,7 @@ Derived& MatrixBase<Derived>::lazyAssign(const Product<Lhs,Rhs,CacheOptimalProdu
&& (Lhs::RowsAtCompileTime%ei_packet_traits<Scalar>::size==0) ), && (Lhs::RowsAtCompileTime%ei_packet_traits<Scalar>::size==0) ),
ei_meta_true,ei_meta_false>::ret() ei_meta_true,ei_meta_false>::ret()
#else #else
ei_meta_false ei_meta_false()
#endif #endif
); );
return derived(); return derived();

View File

@ -53,7 +53,7 @@ struct ei_redux_unroller<BinaryOp, Derived, Start, 1>
typedef typename ei_result_of<BinaryOp(typename Derived::Scalar)>::type Scalar; typedef typename ei_result_of<BinaryOp(typename Derived::Scalar)>::type Scalar;
static Scalar run(const Derived &mat, const BinaryOp &func) static Scalar run(const Derived &mat, const BinaryOp &)
{ {
return mat.coeff(row, col); return mat.coeff(row, col);
} }
@ -96,7 +96,7 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
Flags = ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) Flags = ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic)
? (unsigned int)_MatrixTypeNested::Flags ? (unsigned int)_MatrixTypeNested::Flags
: (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & ~VectorizableBit, : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & ~(VectorizableBit | Like1DArrayBit),
TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime,
CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost
+ (TraversalSize - 1) * ei_functor_traits<BinaryOp>::Cost + (TraversalSize - 1) * ei_functor_traits<BinaryOp>::Cost
@ -124,9 +124,9 @@ class PartialRedux : ei_no_assignment_operator,
const Scalar _coeff(int i, int j) const const Scalar _coeff(int i, int j) const
{ {
if (Direction==Vertical) if (Direction==Vertical)
return this->col(j).redux(m_functor); return m_matrix.col(j).redux(m_functor);
else else
return this->row(i).redux(m_functor); return m_matrix.row(i).redux(m_functor);
} }
protected: protected: