Automatic Differentiation
 
Loading...
Searching...
No Matches
is_unit_vector.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_IS_UNIT_VECTOR_HPP
2#define STAN_MATH_PRIM_ERR_IS_UNIT_VECTOR_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
27template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
28inline bool is_unit_vector(const EigVec& theta) {
29 using std::fabs;
30 if (is_nonzero_size(theta)) {
31 value_type_t<EigVec> seq = theta.squaredNorm();
32 return fabs(1.0 - seq) <= CONSTRAINT_TOLERANCE;
33 }
34 return false;
35}
36
37} // namespace math
38} // namespace stan
39#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
bool is_nonzero_size(const T_y &y)
Returns true if the specified matrix/vector is size nonzero.
bool is_unit_vector(const EigVec &theta)
Return true if the vector is not a unit vector or if any element is NaN.
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds in rank and in simplexes.
fvar< T > fabs(const fvar< T > &x)
Definition fabs.hpp:16
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...