Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:41:23

0001 /*
0002  *  Copyright Nick Thompson, 2019
0003  *  Use, modification and distribution are subject to the
0004  *  Boost Software License, Version 1.0. (See accompanying file
0005  *  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006  *
0007  *  Exactly the same as barycentric_rational.hpp, but delivers values in $\mathbb{R}^n$.
0008  *  In some sense this is trivial, since each component of the vector is computed in exactly the same
0009  *  as would be computed by barycentric_rational.hpp. But this is a bit more efficient and convenient.
0010  */
0011 
0012 #ifndef BOOST_MATH_INTERPOLATORS_VECTOR_BARYCENTRIC_RATIONAL_HPP
0013 #define BOOST_MATH_INTERPOLATORS_VECTOR_BARYCENTRIC_RATIONAL_HPP
0014 
0015 #include <memory>
0016 #include <boost/math/interpolators/detail/vector_barycentric_rational_detail.hpp>
0017 
0018 namespace boost{ namespace math{ namespace interpolators{
0019 
0020 template<class TimeContainer, class SpaceContainer>
0021 class vector_barycentric_rational
0022 {
0023 public:
0024     using Real = typename TimeContainer::value_type;
0025     using Point = typename SpaceContainer::value_type;
0026     vector_barycentric_rational(TimeContainer&& times, SpaceContainer&& points, size_t approximation_order = 3);
0027 
0028     void operator()(Point& x, Real t) const;
0029 
0030     // I have validated using google benchmark that returning a value is no more expensive populating it,
0031     // at least for Eigen vectors with known size at compile-time.
0032     // This is kinda a weird thing to discover since it goes against the advice of basically every high-performance computing book.
0033     Point operator()(Real t) const {
0034         Point p;
0035         this->operator()(p, t);
0036         return p;
0037     }
0038 
0039     void prime(Point& dxdt, Real t) const {
0040         Point x;
0041         m_imp->eval_with_prime(x, dxdt, t);
0042     }
0043 
0044     Point prime(Real t) const {
0045         Point p;
0046         this->prime(p, t);
0047         return p;
0048     }
0049 
0050     void eval_with_prime(Point& x, Point& dxdt, Real t) const {
0051         m_imp->eval_with_prime(x, dxdt, t);
0052         return;
0053     }
0054 
0055     std::pair<Point, Point> eval_with_prime(Real t) const {
0056         Point x;
0057         Point dxdt;
0058         m_imp->eval_with_prime(x, dxdt, t);
0059         return {x, dxdt};
0060     }
0061 
0062 private:
0063     std::shared_ptr<detail::vector_barycentric_rational_imp<TimeContainer, SpaceContainer>> m_imp;
0064 };
0065 
0066 
0067 template <class TimeContainer, class SpaceContainer>
0068 vector_barycentric_rational<TimeContainer, SpaceContainer>::vector_barycentric_rational(TimeContainer&& times, SpaceContainer&& points, size_t approximation_order):
0069  m_imp(std::make_shared<detail::vector_barycentric_rational_imp<TimeContainer, SpaceContainer>>(std::move(times), std::move(points), approximation_order))
0070 {
0071     return;
0072 }
0073 
0074 template <class TimeContainer, class SpaceContainer>
0075 void vector_barycentric_rational<TimeContainer, SpaceContainer>::operator()(typename SpaceContainer::value_type& p, typename TimeContainer::value_type t) const
0076 {
0077     m_imp->operator()(p, t);
0078     return;
0079 }
0080 
0081 }}}
0082 #endif