mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Revert "simplify squaredNorm"
This causes some subtle alignment-related bugs, which @chuckyschluz is currently investigating. See merge request libeigen/eigen!2055
This commit is contained in:
@@ -20,7 +20,10 @@ namespace internal {
|
||||
template <typename Derived, typename Scalar = typename traits<Derived>::Scalar>
|
||||
struct squared_norm_impl {
|
||||
using Real = typename NumTraits<Scalar>::Real;
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Real run(const Derived& a) { return a.realView().cwiseAbs2().sum(); }
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Real run(const Derived& a) {
|
||||
Scalar result = a.unaryExpr(squared_norm_functor<Scalar>()).sum();
|
||||
return numext::real(result) + numext::imag(result);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Derived>
|
||||
|
||||
@@ -106,6 +106,26 @@ struct functor_traits<scalar_abs2_op<Scalar>> {
|
||||
};
|
||||
};
|
||||
|
||||
template <typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
|
||||
struct squared_norm_functor {
|
||||
typedef Scalar result_type;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& a) const {
|
||||
return Scalar(numext::real(a) * numext::real(a), numext::imag(a) * numext::imag(a));
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const {
|
||||
return Packet(pmul(a.v, a.v));
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct squared_norm_functor<Scalar, false> : scalar_abs2_op<Scalar> {};
|
||||
|
||||
template <typename Scalar>
|
||||
struct functor_traits<squared_norm_functor<Scalar>> {
|
||||
using Real = typename NumTraits<Scalar>::Real;
|
||||
enum { Cost = NumTraits<Real>::MulCost, PacketAccess = packet_traits<Real>::HasMul };
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the conjugate of a complex value
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user