add norm() and norm2(); some polishing

This commit is contained in:
Benoit Jacob 2007-10-08 10:19:49 +00:00
parent ac6ff5efd6
commit 7f0a546a81
2 changed files with 11 additions and 6 deletions

View File

@ -29,16 +29,17 @@
template<typename Scalar, typename Derived> class EiObject
{
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
ColsAtCompileTime = Derived::ColsAtCompileTime,
SizeAtCompileTime
= RowsAtCompileTime == EiDynamic || ColsAtCompileTime == EiDynamic
? EiDynamic : RowsAtCompileTime * ColsAtCompileTime;
static const bool IsVector = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
ColsAtCompileTime = Derived::ColsAtCompileTime;
template<typename OtherDerived>
void _copy_helper(const EiObject<Scalar, OtherDerived>& other);
public:
static const int SizeAtCompileTime
= RowsAtCompileTime == EiDynamic || ColsAtCompileTime == EiDynamic
? EiDynamic : RowsAtCompileTime * ColsAtCompileTime;
static const bool IsVector = RowsAtCompileTime == 1 || ColsAtCompileTime == 1;
typedef typename EiForwardDecl<Derived>::Ref Ref;
typedef typename EiForwardDecl<Derived>::ConstRef ConstRef;
@ -91,6 +92,9 @@ template<typename Scalar, typename Derived> class EiObject
template<typename OtherDerived>
Scalar dot(const OtherDerived& other) const;
Scalar norm2() const { assert(IsVector); return dot(*this); }
Scalar norm() const { assert(IsVector); return EiSqrt(dot(*this)); }
template<typename OtherDerived>
EiMatrixProduct<Derived, OtherDerived>
lazyMul(const EiObject<Scalar, OtherDerived>& other) const EI_ALWAYS_INLINE;

View File

@ -83,7 +83,8 @@ EiScalarProduct<Derived> \
operator/(const EiObject<Scalar, Derived>& matrix, \
OtherScalar scalar) \
{ \
return matrix * (static_cast<typename Derived::Scalar>(1) / scalar); \
assert(EiTraits<Scalar>::HasFloatingPoint); \
return matrix * (static_cast<Scalar>(1) / scalar); \
} \
\
template<typename Scalar, typename Derived> \