aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Dot.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-06-19 23:36:38 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-06-19 23:36:38 +0200
commit7fd8418b199cda8b7facb37fccbe871375c5b6d2 (patch)
tree215d97917637683c78efb23dfa604687fb037f5e /Eigen/src/Core/Dot.h
parent575ac5409c6f6a9af219cdff3374c40e8a2a120d (diff)
finish to merge Array into Core:
- mv Array/* into Core/ - merge Functors.h files, and move Norms.h into Dot.h
Diffstat (limited to 'Eigen/src/Core/Dot.h')
-rw-r--r--Eigen/src/Core/Dot.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h
index dfa313e89..8eaa62185 100644
--- a/Eigen/src/Core/Dot.h
+++ b/Eigen/src/Core/Dot.h
@@ -80,6 +80,8 @@ MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
return ei_dot_nocheck<Derived,OtherDerived>::run(*this, other);
}
+//---------- implementation of L2 norm and related functions ----------
+
/** \returns the squared \em l2 norm of *this, i.e., for vectors, the dot product of *this with itself.
*
* \sa dot(), norm()
@@ -128,6 +130,61 @@ inline void MatrixBase<Derived>::normalize()
*this /= norm();
}
+//---------- implementation of other norms ----------
+
+template<typename Derived, int p>
+struct ei_lpNorm_selector
+{
+ typedef typename NumTraits<typename ei_traits<Derived>::Scalar>::Real RealScalar;
+ inline static RealScalar run(const MatrixBase<Derived>& m)
+ {
+ return ei_pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p);
+ }
+};
+
+template<typename Derived>
+struct ei_lpNorm_selector<Derived, 1>
+{
+ inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
+ {
+ return m.cwiseAbs().sum();
+ }
+};
+
+template<typename Derived>
+struct ei_lpNorm_selector<Derived, 2>
+{
+ inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
+ {
+ return m.norm();
+ }
+};
+
+template<typename Derived>
+struct ei_lpNorm_selector<Derived, Infinity>
+{
+ inline static typename NumTraits<typename ei_traits<Derived>::Scalar>::Real run(const MatrixBase<Derived>& m)
+ {
+ return m.cwiseAbs().maxCoeff();
+ }
+};
+
+/** \returns the \f$ \ell^p \f$ norm of *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values
+ * of the coefficients of *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^p\infty \f$
+ * norm, that is the maximum of the absolute values of the coefficients of *this.
+ *
+ * \sa norm()
+ */
+template<typename Derived>
+template<int p>
+inline typename NumTraits<typename ei_traits<Derived>::Scalar>::Real
+MatrixBase<Derived>::lpNorm() const
+{
+ return ei_lpNorm_selector<Derived, p>::run(*this);
+}
+
+//---------- implementation of isOrthogonal / isUnitary ----------
+
/** \returns true if *this is approximately orthogonal to \a other,
* within the precision given by \a prec.
*
@@ -169,4 +226,5 @@ bool MatrixBase<Derived>::isUnitary(RealScalar prec) const
}
return true;
}
+
#endif // EIGEN_DOT_H