14#include "./InternalHeaderCheck.h"
20template <typename Derived, typename Scalar = typename traits<Derived>::Scalar>
21struct squared_norm_impl {
22 using Real =
typename NumTraits<Scalar>::Real;
23 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Real run(
const Derived& a) {
24 Scalar result = a.unaryExpr(squared_norm_functor<Scalar>()).sum();
25 return numext::real(result) + numext::imag(result);
29template <
typename Derived>
30struct squared_norm_impl<Derived, bool> {
31 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool run(
const Derived& a) {
return a.any(); }
47template <
typename Derived>
48template <
typename OtherDerived>
49EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
51 typename internal::traits<OtherDerived>::Scalar>::ReturnType
53 return internal::dot_impl<Derived, OtherDerived>::run(derived(), other.derived());
64template <
typename Derived>
67 return internal::squared_norm_impl<Derived>::run(derived());
76template <
typename Derived>
91template <
typename Derived>
94 typedef typename internal::nested_eval<Derived, 2>::type Nested_;
96 RealScalar z = n.squaredNorm();
98 if (z > RealScalar(0))
99 return n / numext::sqrt(z);
112template <
typename Derived>
116 if (z > RealScalar(0)) derived() /= numext::sqrt(z);
131template <
typename Derived>
132EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename MatrixBase<Derived>::PlainObject
134 typedef typename internal::nested_eval<Derived, 3>::type Nested_;
135 Nested_ n(derived());
136 RealScalar w = n.cwiseAbs().maxCoeff();
138 if (z > RealScalar(0))
139 return n / (numext::sqrt(z) * w);
155template <
typename Derived>
157 RealScalar w =
cwiseAbs().maxCoeff();
159 if (z > RealScalar(0)) derived() /= numext::sqrt(z) * w;
166template <
typename Derived,
int p>
167struct lpNorm_selector {
171 return pow(m.
cwiseAbs().array().pow(p).sum(), RealScalar(1) / p);
175template <
typename Derived>
176struct lpNorm_selector<Derived, 1> {
177 EIGEN_DEVICE_FUNC
static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(
178 const MatrixBase<Derived>& m) {
179 return m.cwiseAbs().sum();
183template <
typename Derived>
184struct lpNorm_selector<Derived, 2> {
186 const MatrixBase<Derived>& m) {
191template <
typename Derived>
194 EIGEN_DEVICE_FUNC
static inline RealScalar run(
const MatrixBase<Derived>& m) {
195 if (Derived::SizeAtCompileTime == 0 || (Derived::SizeAtCompileTime ==
Dynamic && m.size() == 0))
196 return RealScalar(0);
217template <
typename Derived>
219#ifndef EIGEN_PARSED_BY_DOXYGEN
222EIGEN_DEVICE_FUNC MatrixBase<Derived>::RealScalar
225 return internal::lpNorm_selector<Derived, p>::run(*
this);
236template <
typename Derived>
237template <
typename OtherDerived>
239 typename internal::nested_eval<Derived, 2>::type nested(derived());
240 typename internal::nested_eval<OtherDerived, 2>::type otherNested(other.derived());
241 return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm();
255template <
typename Derived>
257 typename internal::nested_eval<Derived, 1>::type self(derived());
258 for (
Index i = 0; i < cols(); ++i) {
259 if (!internal::isApprox(self.col(i).squaredNorm(),
static_cast<RealScalar
>(1), prec))
return false;
260 for (
Index j = 0; j < i; ++j)
261 if (!internal::isMuchSmallerThan(self.col(i).dot(self.col(j)),
static_cast<Scalar>(1), prec))
return false;
const GlobalUnaryPowReturnType< Derived, ScalarExponent > pow(const Eigen::ArrayBase< Derived > &x, const ScalarExponent &exponent)
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
void stableNormalize()
Definition Dot.h:156
const PlainObject stableNormalized() const
Definition Dot.h:133
const PlainObject normalized() const
Definition Dot.h:92
RealScalar lpNorm() const
Definition Dot.h:224
ScalarBinaryOpTraits< typenameinternal::traits< Derived >::Scalar, typenameinternal::traits< OtherDerived >::Scalar >::ReturnType dot(const MatrixBase< OtherDerived > &other) const
Definition Dot.h:52
bool isUnitary(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Dot.h:256
RealScalar squaredNorm() const
Definition Dot.h:66
void normalize()
Definition Dot.h:113
RealScalar norm() const
Definition Dot.h:78
const CwiseAbsReturnType cwiseAbs() const
Definition MatrixBase.h:34
bool isOrthogonal(const MatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Dot.h:238
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Infinity
Definition Constants.h:39
const int Dynamic
Definition Constants.h:25
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:232
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:1047