|
Go to the documentation of this file.
31template < typename Derived>
35 typename Derived::PlainObject tmp;
36 tmp.setConstant(mass);
38 (v - tmp).abs().minCoeff(&pos);
43template < class BinaryOp, class Derived>
45 const Eigen::DenseBase<Derived>& a, const Eigen::DenseBase<Derived>& b, BinaryOp op)
47 typename Derived::PlainObject result(a.rows(), b.cols());
49 assert(a.rows() == b.rows());
50 assert(a.cols() == b.cols());
52 for ( int k = 0; k < a.cols(); k++)
53 for ( int i = 0; i < a.rows(); i++)
54 result(i,k) = op(a(i,k), b(i,k));
66template < class Derived>
68 const Eigen::DenseBase<Derived>& a, const Eigen::DenseBase<Derived>& b)
70 using Scalar = typename Derived::Scalar;
72 return binary_map(a, b, [](Scalar x, Scalar y){
73 const Scalar q = x / y;
74 return std::isfinite(q) ? q : Scalar{};
88template < class Derived>
90 const Eigen::PlainObjectBase<Derived>& b, double eps)
92 if (a.rows() != b.rows() || a.cols() != b.cols()) {
96 for ( decltype(a.size()) i = 0; i < a.size(); i++) {
97 const auto ai = a.data()[i];
98 const auto bi = b.data()[i];
99 const auto max = std::max(std::abs(ai), std::abs(bi));
100 if (std::abs(ai - bi) >= eps*(1 + max)) {
117template < typename DerivedArray, typename DerivedMatrix>
119 Eigen::MatrixBase<DerivedMatrix>& z)
125 const int sign = (idx - pos) < 0 ? -1 : 1;
126 int steps = std::abs(idx - pos);
130 const int new_pos = pos + sign;
131 v.row(new_pos).swap(v.row(pos));
132 z.row(new_pos).swap(z.row(pos));
146template < int M, int N>
149 auto data = m.data();
150 const auto size = m.size();
152 for ( int i = 0; i < size; i++) {
155 else if ( data[i] > max)
169template < int M, int N>
172 auto data = m.data();
173 const auto size = m.size();
175 for ( int i = 0; i < size; i++) {
176 if (std::abs( data[i]) > max_mag)
177 data[i] = std::polar(max_mag, std::arg( data[i]));
184 bool operator()(T x) const noexcept { return !std::isfinite(x); }
197template< class Real, int Nsrc, int Ncmp>
199 const Eigen::Array<Real,Nsrc,1>& src,
200 const Eigen::Array<Real,Ncmp,1>& cmp)
202 Eigen::Array<Real,Nsrc,1> non_equal(src);
203 Eigen::Array< Real,Nsrc - Ncmp,1> dst;
205 for ( int i = 0; i < Ncmp; i++) {
207 non_equal(idx) = std::numeric_limits<double>::infinity();
210 std::remove_copy_if(non_equal.data(), non_equal.data() + Nsrc,
211 dst.data(), Is_not_finite<Real>());
221template< class Real, int N>
223 Eigen::Array<Real,N,1>& v,
224 const Eigen::Array<Real,N,1>& v2)
226 Eigen::PermutationMatrix<N> p;
228 std::sort(p.indices().data(), p.indices().data() + p.indices().size(),
229 [&v2] ( int i, int j) { return v2[i] < v2[j]; });
231#if EIGEN_VERSION_AT_LEAST(3,1,4)
232 v.matrix().transpose() *= p.inverse();
234 Eigen::Map<Eigen::Matrix<Real,N,1> >(v.data()).transpose() *= p.inverse();
245template< class Derived>
247 Eigen::Array< double,Eigen::MatrixBase<Derived>::RowsAtCompileTime,1>& v,
248 const Eigen::MatrixBase<Derived>& matrix)
255void sort(Eigen::Array<double, N, 1>& v)
257 std::sort(v.data(), v.data() + v.size(),
258 [] ( double a, double b) { return std::abs(a) < std::abs(b); });
void move_goldstone_to(int idx, double mass, Eigen::ArrayBase< DerivedArray > &v, Eigen::MatrixBase< DerivedMatrix > &z)
void normalize_to_interval(Eigen::Matrix< double, M, N > &m, double min=-1., double max=1.)
Derived binary_map(const Eigen::DenseBase< Derived > &a, const Eigen::DenseBase< Derived > &b, BinaryOp op)
void reorder_vector(Eigen::Array< Real, N, 1 > &v, const Eigen::Array< Real, N, 1 > &v2) reorders vector v according to ordering in vector v2
int closest_index(double mass, const Eigen::ArrayBase< Derived > &v)
bool is_equal_rel(const Eigen::PlainObjectBase< Derived > &a, const Eigen::PlainObjectBase< Derived > &b, double eps)
Derived div_safe(const Eigen::DenseBase< Derived > &a, const Eigen::DenseBase< Derived > &b)
Eigen::Array< Real, Nsrc - Ncmp, 1 > remove_if_equal(const Eigen::Array< Real, Nsrc, 1 > &src, const Eigen::Array< Real, Ncmp, 1 > &cmp)
void sort(Eigen::Array< double, N, 1 > &v) sorts an Eigen array
bool operator()(T x) const noexcept
|