-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathode_rhs_ostream_adatpor.hpp
84 lines (70 loc) · 2.99 KB
/
ode_rhs_ostream_adatpor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef STAN_MATH_TORSTEN_ODE_RHS_OSTREAM_ADATPOR_HPP
#define STAN_MATH_TORSTEN_ODE_RHS_OSTREAM_ADATPOR_HPP
namespace torsten {
template <typename F>
struct pmx_ode_ostream_adapted {
using yes = double;
using no = bool;
template <typename Functor>
static double test(decltype(std::declval<Functor&>()(0.0, Eigen::VectorXd(), nullptr,
std::vector<double>(),
std::vector<double>(),
std::vector<int>()))*);
template <typename Functor>
static no test(...);
static constexpr bool value = sizeof(test<F>(nullptr)) == sizeof(yes);
};
template <typename F>
struct pmx_ode_ostream_not_adapted {
using yes = double;
using no = bool;
template <typename Functor>
static double test(decltype(std::declval<Functor&>()(0.0, Eigen::VectorXd(),
std::vector<double>(),
std::vector<double>(),
std::vector<int>(), nullptr))*);
template <typename Functor>
static no test(...);
static constexpr bool value = sizeof(test<F>(nullptr)) == sizeof(yes);
};
/**
* This adaptor changes the location of ostream arg in functor call so
* we don't need to make change in stanc compiler for variadic solver
* backend.
*
*/
template<typename F>
struct ode_rhs_ostream_adaptor {
F const& f;
ode_rhs_ostream_adaptor(F const& f_) : f(f_) {}
template <typename F0, typename T0, typename T1, typename T2,
std::enable_if_t<pmx_ode_ostream_not_adapted<F0>::value>* = nullptr>
Eigen::Matrix<stan::return_type_t<T0, T1, T2>, -1, 1>
impl_(F0 const& f0,
const T0& t, const Eigen::Matrix<T1, -1, 1> &x,
std::ostream* pstream,
const std::vector<T2>& parms,
const std::vector<double>& x_r, const std::vector<int>& x_i) const {
return f0(t, x, parms, x_r, x_i, pstream);
}
template <typename F0, typename T0, typename T1, typename T2,
std::enable_if_t<pmx_ode_ostream_adapted<F0>::value>* = nullptr>
Eigen::Matrix<stan::return_type_t<T0, T1, T2>, -1, 1>
impl_(F0 const& f0,
const T0& t, const Eigen::Matrix<T1, -1, 1> &x,
std::ostream* pstream,
const std::vector<T2>& parms,
const std::vector<double>& x_r, const std::vector<int>& x_i) const {
return f0(t, x, pstream, parms, x_r, x_i);
}
template <typename T0, typename T1, typename T2>
Eigen::Matrix<stan::return_type_t<T0, T1, T2>, -1, 1>
operator()(const T0& t, const Eigen::Matrix<T1, -1, 1> &x,
std::ostream* pstream,
const std::vector<T2>& parms,
const std::vector<double>& x_r, const std::vector<int>& x_i) const {
return impl_(f, t, x, pstream, parms, x_r, x_i);
}
};
}
#endif