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
&& 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)

View File

@ -110,7 +110,7 @@ class CwiseNullaryOp : ei_no_assignment_operator,
template<typename Derived>
template<typename CustomNullaryOp>
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);
}
@ -133,7 +133,7 @@ MatrixBase<Derived>::cwiseCreate(int rows, int cols, const CustomNullaryOp& func
template<typename Derived>
template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::cwiseCreate(int size, const CustomNullaryOp& func)
MatrixBase<Derived>::create(int size, const CustomNullaryOp& func)
{
ei_assert(IsVectorAtCompileTime);
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 CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::cwiseCreate(const CustomNullaryOp& func)
MatrixBase<Derived>::create(const CustomNullaryOp& 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>
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
@ -196,7 +196,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived>
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
@ -212,7 +212,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_constant_op<typename ei_traits<Derived>::Scalar>, Derived>
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>
@ -442,7 +442,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
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).
@ -465,7 +465,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
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
@ -483,7 +483,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
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.
@ -519,7 +519,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived>
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).
@ -536,7 +536,7 @@ template<typename Derived>
const CwiseNullaryOp<ei_scalar_identity_op<typename ei_traits<Derived>::Scalar>, Derived>
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

View File

@ -135,7 +135,7 @@ template<typename Derived>
const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::normalized() const
{
return (*this) / norm();
return (*this) * (Scalar(1)/norm());
}
/** \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>
constant(const Scalar& value);
template<typename CustomZeroaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived>
cwiseCreate(int rows, int cols, const CustomZeroaryOp& func);
template<typename CustomZeroaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived>
cwiseCreate(int size, const CustomZeroaryOp& func);
template<typename CustomZeroaryOp>
static const CwiseNullaryOp<CustomZeroaryOp, Derived>
cwiseCreate(const CustomZeroaryOp& func);
template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomNullaryOp, Derived>
create(int rows, int cols, const CustomNullaryOp& func);
template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomNullaryOp, Derived>
create(int size, const CustomNullaryOp& func);
template<typename CustomNullaryOp>
static const CwiseNullaryOp<CustomNullaryOp, Derived>
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 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)
{
return _mm_or_si128(
_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); }

View File

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