1 #ifndef ISCONSTANTCHAIN_HPP
2 #define ISCONSTANTCHAIN_HPP
14 typename std::enable_if<!std::numeric_limits<T>::is_integer,
bool>::type
19 return std::fabs(x-y) <= std::numeric_limits<T>::epsilon() * std::fabs(x+y) * ulp
21 || std::fabs(x-y) < std::numeric_limits<T>::min();
24 template<
typename StateType>
25 bool isConstantChain (
const std::vector<
const std::vector<StateType>*>& chains,
long dimension) {
26 using Scalar =
typename StateType::Scalar;
29 unsigned long numberOfChains = chains.size();
30 unsigned long numberOfDraws = chains[0]->size();
32 std::vector<Scalar> initDraw(numberOfChains, 0);
34 bool chainsAllConst =
true;
35 for (
unsigned long m = 0; m < numberOfChains; ++m) {
36 initDraw[m] = (*chains[m])[0](d);
38 if (!std::isfinite(initDraw[m])) {
39 return std::numeric_limits<double>::quiet_NaN();
44 bool drawsAllConst =
true;
45 for (
unsigned long n = 1; n < numberOfDraws; ++n) {
46 if (!std::isfinite((*chains[m])[n](d))) {
51 drawsAllConst =
false;
58 chainsAllConst =
false;
64 bool chainsAllSameConst =
true;
67 for (
unsigned long m = 1; m < numberOfChains; ++m) {
69 chainsAllSameConst =
false;
74 if (chainsAllSameConst) {
82 template<
typename StateType>
83 bool isConstantChain (
const std::vector<std::vector<StateType>>& chains,
long dimension) {
84 std::vector<const std::vector<StateType>*> chainsPtrArray;
85 for (
auto& chain : chains) {
86 chainsPtrArray.push_back(&chain);
91 template<
typename StateType>
93 for (
long dimension = 0; dimension < (*chains[0])[0].size(); ++dimension) {
102 template<
typename StateType>
104 std::vector<const std::vector<StateType>*> chainsPtrArray;
105 for (
auto& chain : chains) {
106 chainsPtrArray.push_back(&chain);
112 #endif // ISCONSTANTCHAIN_HPP