Stan Math Library  2.20.0
reverse mode automatic differentiation
is_unit_vector.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_IS_UNIT_VECTOR_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_IS_UNIT_VECTOR_HPP
3 
8 
9 namespace stan {
10 namespace math {
25 template <typename T_prob>
26 inline bool is_unit_vector(
27  const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>& theta) {
28  if (is_nonzero_size(theta)) {
29  T_prob seq = theta.squaredNorm();
30  return fabs(1.0 - seq) <= CONSTRAINT_TOLERANCE;
31  }
32  return false;
33 }
34 
35 } // namespace math
36 } // namespace stan
37 #endif
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool is_nonzero_size(const T_y &y)
Returns true if the specified matrix/vector is size nonzero.
bool is_unit_vector(const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta)
Return true if the vector is not a unit vector or if any element is NaN.

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