#pragma once #include #include #include #include namespace alpaqa { template struct is_config : std::false_type {}; template inline constexpr bool is_config_v = is_config::value; template concept Config = is_config_v; struct DefaultConfig; template <> struct is_config : std::true_type {}; #define USING_ALPAQA_CONFIG_NO_TYPENAME(Conf) \ using real_t [[maybe_unused]] = Conf::real_t; \ using vec [[maybe_unused]] = Conf::vec; \ using mvec [[maybe_unused]] = Conf::mvec; \ using cmvec [[maybe_unused]] = Conf::cmvec; \ using rvec [[maybe_unused]] = Conf::rvec; \ using crvec [[maybe_unused]] = Conf::crvec; \ using mat [[maybe_unused]] = Conf::mat; \ using mmat [[maybe_unused]] = Conf::mmat; \ using cmmat [[maybe_unused]] = Conf::cmmat; \ using rmat [[maybe_unused]] = Conf::rmat; \ using crmat [[maybe_unused]] = Conf::crmat; \ using length_t [[maybe_unused]] = Conf::length_t; \ using index_t [[maybe_unused]] = Conf::index_t; \ using indexvec [[maybe_unused]] = Conf::indexvec; \ using rindexvec [[maybe_unused]] = Conf::rindexvec; \ using crindexvec [[maybe_unused]] = Conf::crindexvec #define USING_ALPAQA_CONFIG(Conf) /** @cond CONFIG_TYPES */ \ using config_t [[maybe_unused]] = Conf; \ USING_ALPAQA_CONFIG_NO_TYPENAME(typename Conf) /** @endcond */ #define USING_ALPAQA_CONFIG_TEMPLATE(Conf) /** @cond CONFIG_TYPES */ \ using config_t [[maybe_unused]] = typename Conf; \ USING_ALPAQA_CONFIG_NO_TYPENAME(typename Conf) /** @endcond */ // clang-format off template using real_t = typename Conf::real_t; template using vec = typename Conf::vec; template using mvec = typename Conf::mvec; template using cmvec = typename Conf::cmvec; template using rvec = typename Conf::rvec; template using crvec = typename Conf::crvec; template using mat = typename Conf::mat; template using mmat = typename Conf::mmat; template using cmmat = typename Conf::cmmat; template using rmat = typename Conf::rmat; template using crmat = typename Conf::crmat; template using length_t = typename Conf::length_t; template using index_t = typename Conf::index_t; template using indexvec = typename Conf::indexvec; template using rindexvec = typename Conf::rindexvec; template using crindexvec = typename Conf::crindexvec; template constexpr const auto inf = std::numeric_limits>::infinity(); template constexpr const auto NaN = std::numeric_limits>::quiet_NaN(); // clang-format on template struct EigenConfig { /// Real scalar element type. using real_t = RealT; /// Dynamic vector type. using vec = Eigen::VectorX; /// Map of vector type. using mvec = Eigen::Map; /// Immutable map of vector type. using cmvec = Eigen::Map; /// Reference to mutable vector. using rvec = Eigen::Ref; /// Reference to immutable vector. using crvec = Eigen::Ref; /// Dynamic matrix type. using mat = Eigen::MatrixX; /// Map of matrix type. using mmat = Eigen::Map; /// Immutable map of matrix type. using cmmat = Eigen::Map; /// Reference to mutable matrix. using rmat = Eigen::Ref; /// Reference to immutable matrix. using crmat = Eigen::Ref; /// Type for lengths and sizes. using length_t = Eigen::Index; /// Type for vector and matrix indices. using index_t = Eigen::Index; /// Dynamic vector of indices. using indexvec = Eigen::VectorX; /// Reference to mutable index vector. using rindexvec = Eigen::Ref; /// Reference to immutable index vector. using crindexvec = Eigen::Ref; }; /// Single-precision `float` configuration. struct EigenConfigf : EigenConfig { static constexpr const char *get_name() { return "EigenConfigf"; } }; /// Double-precision `double` configuration. struct EigenConfigd : EigenConfig { static constexpr const char *get_name() { return "EigenConfigd"; } }; /// `long double` configuration. (Quad precision on ARM64, 80-bit x87 floats /// on Intel/AMD x86) struct EigenConfigl : EigenConfig { static constexpr const char *get_name() { return "EigenConfigl"; } }; #ifdef ALPAQA_WITH_QUAD_PRECISION /// Quad-precision `__float128` configuration. struct EigenConfigq : EigenConfig<__float128> { static constexpr const char *get_name() { return "EigenConfigq"; } }; template <> struct is_config : std::true_type {}; #endif struct DefaultConfig : EigenConfigd {}; template <> struct is_config : std::true_type {}; template <> struct is_config : std::true_type {}; template <> struct is_config : std::true_type {}; /// Global empty vector for convenience. template inline const rvec null_vec = mvec{nullptr, 0}; namespace vec_util { /// Get the maximum or infinity-norm of the given vector. /// @returns @f$ \left\|v\right\|_\infty @f$ template requires(Derived::ColsAtCompileTime == 1) auto norm_inf(const Eigen::MatrixBase &v) { return v.template lpNorm(); } /// Get the 1-norm of the given vector. /// @returns @f$ \left\|v\right\|_1 @f$ template requires(Derived::ColsAtCompileTime == 1) auto norm_1(const Eigen::MatrixBase &v) { return v.template lpNorm<1>(); } } // namespace vec_util } // namespace alpaqa