| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
check_unit_vector.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/scal/err/domain_error.hpp>
6 #include <stan/math/prim/mat/err/constraint_tolerance.hpp>
7 #include <stan/math/prim/scal/err/check_nonzero_size.hpp>
8 #include <sstream>
9 #include <string>
10
11 namespace stan {
12
13 namespace math {
14 using Eigen::Dynamic;
15
37 template <typename T_prob>
38 bool check_unit_vector(const char* function,
39 const char* name,
40 const Eigen::Matrix<T_prob, Dynamic, 1>& theta) {
41 check_nonzero_size(function, name, theta);
42 T_prob ssq = theta.squaredNorm();
43 if (!(fabs(1.0 - ssq) <= CONSTRAINT_TOLERANCE)) {
44 std::stringstream msg;
45 msg << "is not a valid unit vector."
46 << " The sum of the squares of the elements should be 1, but is ";
47 std::string msg_str(msg.str());
48 domain_error(function, name, ssq, msg_str.c_str());
49 }
50 return true;
51 }
52
53 }
54 }
55 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
constraint_tolerance.hpp
stan::math::check_unit_vector
bool check_unit_vector(const char *function, const char *name, const Eigen::Matrix< T_prob, Dynamic, 1 > &theta)
Return true if the specified vector is unit vector.
Definition: check_unit_vector.hpp:38
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::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:31
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
check_nonzero_size.hpp

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