From 7f0a546a817e97e0fc55ae21b7db811315dd94fe Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 8 Oct 2007 10:19:49 +0000 Subject: [PATCH] add norm() and norm2(); some polishing --- src/Core/Object.h | 14 +++++++++----- src/Core/ScalarOps.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Core/Object.h b/src/Core/Object.h index 14b1647fca..89c62b7b57 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -29,16 +29,17 @@ template 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 void _copy_helper(const EiObject& other); public: + static const int SizeAtCompileTime + = RowsAtCompileTime == EiDynamic || ColsAtCompileTime == EiDynamic + ? EiDynamic : RowsAtCompileTime * ColsAtCompileTime; + static const bool IsVector = RowsAtCompileTime == 1 || ColsAtCompileTime == 1; + typedef typename EiForwardDecl::Ref Ref; typedef typename EiForwardDecl::ConstRef ConstRef; @@ -91,6 +92,9 @@ template class EiObject template Scalar dot(const OtherDerived& other) const; + Scalar norm2() const { assert(IsVector); return dot(*this); } + Scalar norm() const { assert(IsVector); return EiSqrt(dot(*this)); } + template EiMatrixProduct lazyMul(const EiObject& other) const EI_ALWAYS_INLINE; diff --git a/src/Core/ScalarOps.h b/src/Core/ScalarOps.h index 903f2751bd..2f56ff3b48 100644 --- a/src/Core/ScalarOps.h +++ b/src/Core/ScalarOps.h @@ -83,7 +83,8 @@ EiScalarProduct \ operator/(const EiObject& matrix, \ OtherScalar scalar) \ { \ - return matrix * (static_cast(1) / scalar); \ + assert(EiTraits::HasFloatingPoint); \ + return matrix * (static_cast(1) / scalar); \ } \ \ template \