check_unit_vector.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP
#include <stan/math/prim/arr/err/check_nonzero_size.hpp>
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/mat/err/constraint_tolerance.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <sstream>
#include <string>
namespace stan {
namespace math {
template <typename T_prob>
void check_unit_vector(const char* function,
const char* name,
const Eigen::Matrix<T_prob,
Eigen::Dynamic, 1>& theta) {
check_nonzero_size(function, name, theta);
T_prob ssq = theta.squaredNorm();
if (!(fabs(1.0 - ssq) <= CONSTRAINT_TOLERANCE)) {
std::stringstream msg;
msg << "is not a valid unit vector."
<< " The sum of the squares of the elements should be 1, but is ";
std::string msg_str(msg.str());
domain_error(function, name, ssq, msg_str.c_str());
}
}
}
}
#endif
stan::math::check_nonzero_size
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:27
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
stan
Definition: log_sum_exp.hpp:8
stan::math::check_unit_vector
void check_unit_vector(const char *function, const char *name, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta)
Check if the specified vector is unit vector.
Definition: check_unit_vector.hpp:34
constraint_tolerance.hpp
stan::math::CONSTRAINT_TOLERANCE
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Definition: constraint_tolerance.hpp:11
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:30
Eigen.hpp
domain_error.hpp
check_nonzero_size.hpp

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