14 #include "./InternalHeaderCheck.h" 20 template <typename Derived, typename Scalar = typename traits<Derived>::Scalar>
21 struct 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);
29 template <
typename Derived>
30 struct squared_norm_impl<Derived, bool> {
31 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool run(
const Derived& a) {
return a.any(); }
47 template <
typename Derived>
48 template <
typename OtherDerived>
49 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
50 typename ScalarBinaryOpTraits<typename internal::traits<Derived>::Scalar,
51 typename internal::traits<OtherDerived>::Scalar>::ReturnType
53 return internal::dot_impl<Derived, OtherDerived>::run(derived(), other.
derived());
64 template <
typename Derived>
67 return internal::squared_norm_impl<Derived>::run(derived());
76 template <
typename Derived>
79 return numext::sqrt(squaredNorm());
91 template <
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);
112 template <
typename Derived>
114 RealScalar z = squaredNorm();
116 if (z > RealScalar(0)) derived() /= numext::sqrt(z);
131 template <
typename Derived>
132 EIGEN_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();
137 RealScalar z = (n / w).squaredNorm();
138 if (z > RealScalar(0))
139 return n / (numext::sqrt(z) * w);
155 template <
typename Derived>
157 RealScalar w = cwiseAbs().maxCoeff();
158 RealScalar z = (derived() / w).squaredNorm();
159 if (z > RealScalar(0)) derived() /= numext::sqrt(z) * w;
166 template <
typename Derived,
int p>
167 struct lpNorm_selector {
171 return pow(m.
cwiseAbs().array().pow(p).sum(), RealScalar(1) / p);
175 template <
typename Derived>
176 struct 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();
183 template <
typename Derived>
184 struct lpNorm_selector<Derived, 2> {
185 EIGEN_DEVICE_FUNC
static inline typename NumTraits<typename traits<Derived>::Scalar>::Real run(
186 const MatrixBase<Derived>& m) {
191 template <
typename Derived>
192 struct lpNorm_selector<Derived,
Infinity> {
193 typedef typename NumTraits<typename traits<Derived>::Scalar>::Real RealScalar;
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);
197 return m.cwiseAbs().maxCoeff();
217 template <
typename Derived>
219 #ifndef EIGEN_PARSED_BY_DOXYGEN 220 EIGEN_DEVICE_FUNC
inline typename NumTraits<typename internal::traits<Derived>::Scalar>::Real
222 EIGEN_DEVICE_FUNC MatrixBase<Derived>::RealScalar
225 return internal::lpNorm_selector<Derived, p>::run(*
this);
236 template <
typename Derived>
237 template <
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();
255 template <
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;
268 #endif // EIGEN_DOT_H constexpr Derived & derived()
Definition: EigenBase.h:49
bool isUnitary(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Dot.h:256
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
const PlainObject normalized() const
Definition: Dot.h:92
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
void normalize()
Definition: Dot.h:113
RealScalar norm() const
Definition: Dot.h:78
void stableNormalize()
Definition: Dot.h:156
RealScalar squaredNorm() const
Definition: Dot.h:66
const PlainObject stableNormalized() const
Definition: Dot.h:133
ScalarBinaryOpTraits< typename internal::traits< Derived >::Scalar, typename internal::traits< OtherDerived >::Scalar >::ReturnType dot(const MatrixBase< OtherDerived > &other) const
Definition: Dot.h:52
RealScalar lpNorm() const
Definition: Dot.h:224
bool isOrthogonal(const MatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Dot.h:238
const int Dynamic
Definition: Constants.h:25
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const CwiseAbsReturnType cwiseAbs() const
Definition: MatrixBase.h:34
const int Infinity
Definition: Constants.h:39