Skip to content

Commit

Permalink
feat: use policy-based error handling in interpolators
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Feb 13, 2025
1 parent a5c0625 commit 48aafd1
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 48 deletions.
43 changes: 35 additions & 8 deletions include/boost/math/interpolators/cubic_hermite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
#define BOOST_MATH_INTERPOLATORS_CUBIC_HERMITE_HPP
#include <memory>
#include <boost/math/interpolators/detail/cubic_hermite_detail.hpp>
#include <boost/math/policies/error_handling.hpp>

namespace boost {
namespace math {
namespace interpolators {

template<class RandomAccessContainer>
template<class RandomAccessContainer, class Policy = policies::policy<>>
class cubic_hermite {
public:
using Real = typename RandomAccessContainer::value_type;

cubic_hermite(RandomAccessContainer && x, RandomAccessContainer && y, RandomAccessContainer && dydx)
: impl_(std::make_shared<detail::cubic_hermite_detail<RandomAccessContainer>>(std::move(x), std::move(y), std::move(dydx)))
: impl_(std::make_shared<detail::cubic_hermite_detail<RandomAccessContainer, Policy>>(std::move(x), std::move(y), std::move(dydx)))
{}

inline Real operator()(Real x) const {
return impl_->operator()(x);
}
Expand All @@ -43,6 +44,7 @@ class cubic_hermite {

int64_t bytes() const
{
if ( ! valid()) return 0;
return impl_->bytes() + sizeof(impl_);
}

Expand All @@ -51,17 +53,25 @@ class cubic_hermite {
return impl_->domain();
}

bool valid() const {
return impl_->valid();
}

std::string const& error_msg() const {
return impl_->error_msg();
}

private:
std::shared_ptr<detail::cubic_hermite_detail<RandomAccessContainer>> impl_;
};

template<class RandomAccessContainer>
template<class RandomAccessContainer, class Policy = policies::policy<>>
class cardinal_cubic_hermite {
public:
using Real = typename RandomAccessContainer::value_type;

cardinal_cubic_hermite(RandomAccessContainer && y, RandomAccessContainer && dydx, Real x0, Real dx)
: impl_(std::make_shared<detail::cardinal_cubic_hermite_detail<RandomAccessContainer>>(std::move(y), std::move(dydx), x0, dx))
: impl_(std::make_shared<detail::cardinal_cubic_hermite_detail<RandomAccessContainer, Policy>>(std::move(y), std::move(dydx), x0, dx))
{}

inline Real operator()(Real x) const
Expand All @@ -82,6 +92,7 @@ class cardinal_cubic_hermite {

int64_t bytes() const
{
if ( ! valid()) return 0;
return impl_->bytes() + sizeof(impl_);
}

Expand All @@ -90,19 +101,26 @@ class cardinal_cubic_hermite {
return impl_->domain();
}

bool valid() const {
return impl_->valid();
}

std::string const& error_msg() const {
return impl_->error_msg();
}

private:
std::shared_ptr<detail::cardinal_cubic_hermite_detail<RandomAccessContainer>> impl_;
};


template<class RandomAccessContainer>
template<class RandomAccessContainer, class Policy = policies::policy<>>
class cardinal_cubic_hermite_aos {
public:
using Point = typename RandomAccessContainer::value_type;
using Real = typename Point::value_type;

cardinal_cubic_hermite_aos(RandomAccessContainer && data, Real x0, Real dx)
: impl_(std::make_shared<detail::cardinal_cubic_hermite_detail_aos<RandomAccessContainer>>(std::move(data), x0, dx))
: impl_(std::make_shared<detail::cardinal_cubic_hermite_detail_aos<RandomAccessContainer, Policy>>(std::move(data), x0, dx))
{}

inline Real operator()(Real x) const
Expand All @@ -123,6 +141,7 @@ class cardinal_cubic_hermite_aos {

int64_t bytes() const
{
if ( ! valid()) return 0;
return impl_->bytes() + sizeof(impl_);
}

Expand All @@ -131,6 +150,14 @@ class cardinal_cubic_hermite_aos {
return impl_->domain();
}

bool valid() const {
return impl_->valid();
}

std::string const& error_msg() const {
return impl_->error_msg();
}

private:
std::shared_ptr<detail::cardinal_cubic_hermite_detail_aos<RandomAccessContainer>> impl_;
};
Expand Down
Loading

0 comments on commit 48aafd1

Please sign in to comment.