All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_ordered.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/scal/meta/error_index.hpp>
#include <sstream>
#include <string>
#include <vector>
namespace stan {
namespace math {
template <typename T_y>
bool check_ordered(const char* function,
const char* name,
const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
using Eigen::Dynamic;
using Eigen::Matrix;
using stan::math::index_type;
typedef typename index_type<Matrix<T_y, Dynamic, 1> >::type size_t;
if (y.size() == 0)
return true;
for (size_t n = 1; n < y.size(); n++) {
if (!(y[n] > y[n-1])) {
std::ostringstream msg1;
msg1 << "is not a valid ordered vector."
<< " The element at " << stan::error_index::value + n
<< " is ";
std::string msg1_str(msg1.str());
std::ostringstream msg2;
msg2 << ", but should be greater than the previous element, "
<< y[n-1];
std::string msg2_str(msg2.str());
domain_error(function, name, y[n],
msg1_str.c_str(), msg2_str.c_str());
return false;
}
}
return true;
}
template <typename T_y>
bool check_ordered(const char* function,
const char* name,
const std::vector<T_y>& y) {
if (y.size() == 0)
return true;
for (size_t n = 1; n < y.size(); n++) {
if (!(y[n] > y[n-1])) {
std::ostringstream msg1;
msg1 << "is not a valid ordered vector."
<< " The element at " << stan::error_index::value + n
<< " is ";
std::string msg1_str(msg1.str());
std::ostringstream msg2;
msg2 << ", but should be greater than the previous element, "
<< y[n-1];
std::string msg2_str(msg2.str());
domain_error(function, name, y[n],
msg1_str.c_str(), msg2_str.c_str());
return false;
}
}
return true;
}
}
}
#endif
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
index_type.hpp
stan::math::check_ordered
bool check_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
Return true if the specified vector is sorted into strictly increasing order.
Definition: check_ordered.hpp:31
stan::error_index::value
Definition: error_index.hpp:7
stan::math::domain_error
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error.hpp:32
Eigen.hpp
domain_error.hpp
error_index.hpp

[ Stan Home Page ] © 2011–2015, Stan Development Team.