Line data Source code
1 : #pragma once 2 : 3 : #include <Eigen/Core> 4 : 5 : namespace pa { 6 : 7 : /// Default floating point type 8 : using real_t = double; // TODO: make template? 9 : /// Default type for floating point vectors. 10 : using realvec = Eigen::Matrix<real_t, Eigen::Dynamic, 1>; 11 : /// Default type for floating point matrices. 12 : using realmat = Eigen::Matrix<real_t, Eigen::Dynamic, Eigen::Dynamic>; 13 : /// Default type for vectors. 14 : using vec = realvec; 15 : /// Default type for mutable references to vectors. 16 : using rvec = Eigen::Ref<vec>; 17 : /// Default type for immutable references to vectors. 18 : using crvec = Eigen::Ref<const vec>; 19 : /// Default type for matrices. 20 : using mat = realmat; 21 : /// Default type for mutable references to matrices. 22 : using rmat = Eigen::Ref<mat>; 23 : /// Default type for immutable references to matrices. 24 : using crmat = Eigen::Ref<const mat>; 25 : /// @f$ \infty @f$ 26 : constexpr real_t inf = std::numeric_limits<real_t>::infinity(); 27 : /// Not a number. 28 : constexpr real_t NaN = std::numeric_limits<real_t>::quiet_NaN(); 29 : 30 : namespace vec_util { 31 : 32 : /// Get the Σ norm squared of a given vector, with Σ a diagonal matrix. 33 : /// @returns @f$ \langle v, \Sigma v \rangle @f$ 34 : template <class V, class M> 35 : auto norm_squared_weighted(V &&v, M &&Σ) { 36 : return v.dot(Σ.asDiagonal() * v); 37 : } 38 : 39 : /// Get the maximum or infinity-norm of the given vector. 40 : /// @returns @f$ \left\|v\right\|_\infty @f$ 41 : template <class Vec> 42 200640 : real_t norm_inf(const Vec &v) { 43 200640 : return v.template lpNorm<Eigen::Infinity>(); 44 : } 45 : 46 : /// Get the 1-norm of the given vector. 47 : /// @returns @f$ \left\|v\right\|_1 @f$ 48 : template <class Vec> 49 0 : real_t norm_1(const Vec &v) { 50 0 : return v.template lpNorm<1>(); 51 : } 52 : 53 : } // namespace vec_util 54 : 55 : } // namespace pa