Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use policy-based error handling in interpolators #1245

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions include/boost/math/interpolators/cubic_hermite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
#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 {
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
Loading